diff options
| author | Dianne Hackborn <hackbod@google.com> | 2018-04-23 17:38:09 -0700 |
|---|---|---|
| committer | Dianne Hackborn <hackbod@google.com> | 2018-04-24 16:08:25 -0700 |
| commit | cd1f30b4392ed7fdb50befa2f2190e1be4eada43 (patch) | |
| tree | 7db296254f2f52c6473b8e23974f71295bee0cde /core/java/android/app/AppOpsManager.java | |
| parent | 73f83613547594b159f5d50326b7fe829af1c91a (diff) | |
Work on issue #78480444: Start tracking uid state in app ops
We now push uid states down from activity manager in to app
ops, and it uses them to keep track of access/reject times for
each uid/package at the various states.
Bug: 78480444
Test: manual
Change-Id: Ia0bc9174b60b4bf0851834961cc48507a6a60951
Diffstat (limited to 'core/java/android/app/AppOpsManager.java')
| -rw-r--r-- | core/java/android/app/AppOpsManager.java | 99 |
1 files changed, 88 insertions, 11 deletions
diff --git a/core/java/android/app/AppOpsManager.java b/core/java/android/app/AppOpsManager.java index ab0001ca8c3c..13389e35943c 100644 --- a/core/java/android/app/AppOpsManager.java +++ b/core/java/android/app/AppOpsManager.java @@ -109,6 +109,48 @@ public class AppOpsManager { */ public static final int MODE_DEFAULT = 3; + /** + * Metrics about an op when its uid is persistent. + * @hide + */ + public static final int UID_STATE_PERSISTENT = 0; + + /** + * Metrics about an op when its uid is at the top. + * @hide + */ + public static final int UID_STATE_TOP = 1; + + /** + * Metrics about an op when its uid is running a foreground service. + * @hide + */ + public static final int UID_STATE_FOREGROUND_SERVICE = 2; + + /** + * Metrics about an op when its uid is in the foreground for any other reasons. + * @hide + */ + public static final int UID_STATE_FOREGROUND = 3; + + /** + * Metrics about an op when its uid is in the background for any reason. + * @hide + */ + public static final int UID_STATE_BACKGROUND = 4; + + /** + * Metrics about an op when its uid is cached. + * @hide + */ + public static final int UID_STATE_CACHED = 5; + + /** + * Number of uid states we track. + * @hide + */ + public static final int _NUM_UID_STATE = 6; + // when adding one of these: // - increment _NUM_OP // - define an OPSTR_* constant (marked as @SystemApi) @@ -1471,8 +1513,8 @@ public class AppOpsManager { public static class OpEntry implements Parcelable { private final int mOp; private final int mMode; - private final long mTime; - private final long mRejectTime; + private final long[] mTimes; + private final long[] mRejectTimes; private final int mDuration; private final int mProxyUid; private final String mProxyPackageName; @@ -1481,8 +1523,23 @@ public class AppOpsManager { int proxyUid, String proxyPackage) { mOp = op; mMode = mode; - mTime = time; - mRejectTime = rejectTime; + mTimes = new long[_NUM_UID_STATE]; + mRejectTimes = new long[_NUM_UID_STATE]; + mTimes[0] = time; + mRejectTimes[0] = rejectTime; + mDuration = duration; + mProxyUid = proxyUid; + mProxyPackageName = proxyPackage; + } + + public OpEntry(int op, int mode, long[] times, long[] rejectTimes, int duration, + int proxyUid, String proxyPackage) { + mOp = op; + mMode = mode; + mTimes = new long[_NUM_UID_STATE]; + mRejectTimes = new long[_NUM_UID_STATE]; + System.arraycopy(times, 0, mTimes, 0, _NUM_UID_STATE); + System.arraycopy(rejectTimes, 0, mRejectTimes, 0, _NUM_UID_STATE); mDuration = duration; mProxyUid = proxyUid; mProxyPackageName = proxyPackage; @@ -1497,11 +1554,31 @@ public class AppOpsManager { } public long getTime() { - return mTime; + long time = 0; + for (int i = 0; i < _NUM_UID_STATE; i++) { + if (mTimes[i] > time) { + time = mTimes[i]; + } + } + return time; + } + + public long getTimeFor(int uidState) { + return mTimes[uidState]; } public long getRejectTime() { - return mRejectTime; + long time = 0; + for (int i = 0; i < _NUM_UID_STATE; i++) { + if (mRejectTimes[i] > time) { + time = mTimes[i]; + } + } + return time; + } + + public long getRejectTimeFor(int uidState) { + return mRejectTimes[uidState]; } public boolean isRunning() { @@ -1509,7 +1586,7 @@ public class AppOpsManager { } public int getDuration() { - return mDuration == -1 ? (int)(System.currentTimeMillis()-mTime) : mDuration; + return mDuration; } public int getProxyUid() { @@ -1529,8 +1606,8 @@ public class AppOpsManager { public void writeToParcel(Parcel dest, int flags) { dest.writeInt(mOp); dest.writeInt(mMode); - dest.writeLong(mTime); - dest.writeLong(mRejectTime); + dest.writeLongArray(mTimes); + dest.writeLongArray(mRejectTimes); dest.writeInt(mDuration); dest.writeInt(mProxyUid); dest.writeString(mProxyPackageName); @@ -1539,8 +1616,8 @@ public class AppOpsManager { OpEntry(Parcel source) { mOp = source.readInt(); mMode = source.readInt(); - mTime = source.readLong(); - mRejectTime = source.readLong(); + mTimes = source.createLongArray(); + mRejectTimes = source.createLongArray(); mDuration = source.readInt(); mProxyUid = source.readInt(); mProxyPackageName = source.readString(); |
