summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTreeHugger Robot <treehugger-gerrit@google.com>2020-01-02 23:22:52 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2020-01-02 23:22:52 +0000
commit742715cf838fed0acaaaf56edec496d32722d3b3 (patch)
tree0f40f50de3110b83bd3e17ba44d4475dcf77e021
parentaf56f01556fbf6d70837e066bbd6de8acbf939fd (diff)
parente6ece90a586d6378d099a547451c918db91faebb (diff)
Merge "Use elapsedRealtime to measure in-progress app-ops"
-rw-r--r--services/core/java/com/android/server/appop/AppOpsService.java26
1 files changed, 16 insertions, 10 deletions
diff --git a/services/core/java/com/android/server/appop/AppOpsService.java b/services/core/java/com/android/server/appop/AppOpsService.java
index 9ce266ecbe4c..8c9bff937831 100644
--- a/services/core/java/com/android/server/appop/AppOpsService.java
+++ b/services/core/java/com/android/server/appop/AppOpsService.java
@@ -477,9 +477,12 @@ public class AppOpsService extends IAppOpsService.Stub {
/** A in progress startOp->finishOp event */
private static final class InProgressStartOpEvent implements IBinder.DeathRecipient {
- /** Time of startOp event */
+ /** Wall clock time of startOp event (not monotonic) */
final long startTime;
+ /** Elapsed time since boot of startOp event */
+ final long startElapsedTime;
+
/** Id of the client that started the event */
final @NonNull IBinder clientId;
@@ -492,9 +495,11 @@ public class AppOpsService extends IAppOpsService.Stub {
/** How many times the op was started but not finished yet */
int numUnfinishedStarts;
- private InProgressStartOpEvent(long startTime, @NonNull IBinder clientId,
- @NonNull Runnable onDeath, int uidState) throws RemoteException {
+ private InProgressStartOpEvent(long startTime, long startElapsedTime,
+ @NonNull IBinder clientId, @NonNull Runnable onDeath, int uidState)
+ throws RemoteException {
this.startTime = startTime;
+ this.startElapsedTime = startElapsedTime;
this.clientId = clientId;
this.onDeath = onDeath;
this.uidState = uidState;
@@ -636,7 +641,8 @@ public class AppOpsService extends IAppOpsService.Stub {
InProgressStartOpEvent event = mInProgressEvents.get(clientId);
if (event == null) {
- event = new InProgressStartOpEvent(System.currentTimeMillis(), clientId, () -> {
+ event = new InProgressStartOpEvent(System.currentTimeMillis(),
+ SystemClock.elapsedRealtime(), clientId, () -> {
// In the case the client dies without calling finish first
synchronized (AppOpsService.this) {
if (mInProgressEvents == null) {
@@ -698,7 +704,7 @@ public class AppOpsService extends IAppOpsService.Stub {
// startOp events don't support proxy, hence use flags==SELF
NoteOpEvent finishedEvent = new NoteOpEvent(event.startTime,
- System.currentTimeMillis() - event.startTime, null);
+ SystemClock.elapsedRealtime() - event.startElapsedTime, null);
mAccessEvents.put(makeKey(event.uidState, OP_FLAG_SELF), finishedEvent);
mHistoricalRegistry.increaseOpAccessDuration(parent.op, parent.uid,
@@ -759,7 +765,7 @@ public class AppOpsService extends IAppOpsService.Stub {
// Add in progress events as access events
if (mInProgressEvents != null) {
- long now = System.currentTimeMillis();
+ long now = SystemClock.elapsedRealtime();
int numInProgressEvents = mInProgressEvents.size();
if (accessEvents == null) {
@@ -771,7 +777,7 @@ public class AppOpsService extends IAppOpsService.Stub {
// startOp events don't support proxy
accessEvents.append(makeKey(event.uidState, OP_FLAG_SELF),
- new NoteOpEvent(event.startTime, now - event.startTime, null));
+ new NoteOpEvent(event.startTime, now - event.startElapsedTime, null));
}
}
@@ -4188,18 +4194,18 @@ public class AppOpsService extends IAppOpsService.Stub {
final FeatureOp featureOp = op.mFeatures.get(featureId);
if (featureOp.isRunning()) {
- long earliestStartTime = Long.MAX_VALUE;
+ long earliestElapsedTime = Long.MAX_VALUE;
long maxNumStarts = 0;
int numInProgressEvents = featureOp.mInProgressEvents.size();
for (int i = 0; i < numInProgressEvents; i++) {
InProgressStartOpEvent event = featureOp.mInProgressEvents.valueAt(i);
- earliestStartTime = Math.min(earliestStartTime, event.startTime);
+ earliestElapsedTime = Math.min(earliestElapsedTime, event.startElapsedTime);
maxNumStarts = Math.max(maxNumStarts, event.numUnfinishedStarts);
}
pw.print(prefix + "Running start at: ");
- TimeUtils.formatDuration(nowElapsed - earliestStartTime, pw);
+ TimeUtils.formatDuration(nowElapsed - earliestElapsedTime, pw);
pw.println();
if (maxNumStarts > 1) {