diff options
| author | 2017-04-13 14:54:56 -0700 | |
|---|---|---|
| committer | 2017-04-14 09:47:54 -0700 | |
| commit | d7e405851f23805fb484f861b5a2ba2de87a31d5 (patch) | |
| tree | 5313bbca3e1ba261e4ac2f105afe9e4079cea0c0 | |
| parent | d2b368a68dfd1447e6590606cf8231dcf00a5bdc (diff) | |
Fix the wrong IMPORTANCE_ values.
Bug: 36697597
Test: cts-tradefed run cts-dev --skip-device-info --skip-preconditions --skip-system-status-check com.android.compatibility.common.tradefed.targetprep.NetworkConnectivityChecker -a armeabi-v7a -l INFO -m CtsAppTestCases -t android.app.cts.AlertWindowsTests
Change-Id: I3327d4668470400e8b30faeebb77534eeb2583ed
| -rw-r--r-- | api/current.txt | 3 | ||||
| -rw-r--r-- | api/system-current.txt | 3 | ||||
| -rw-r--r-- | api/test-current.txt | 3 | ||||
| -rw-r--r-- | core/java/android/app/ActivityManager.java | 71 |
4 files changed, 68 insertions, 12 deletions
diff --git a/api/current.txt b/api/current.txt index 6e30fd876ca2..9552d9307043 100644 --- a/api/current.txt +++ b/api/current.txt @@ -3939,7 +3939,8 @@ package android.app { field public static final int IMPORTANCE_FOREGROUND = 100; // 0x64 field public static final int IMPORTANCE_FOREGROUND_SERVICE = 125; // 0x7d field public static final int IMPORTANCE_GONE = 1000; // 0x3e8 - field public static final int IMPORTANCE_PERCEPTIBLE = 130; // 0x82 + field public static final int IMPORTANCE_PERCEPTIBLE = 230; // 0xe6 + field public static final deprecated int IMPORTANCE_PERCEPTIBLE_DEPRECATED = 130; // 0x82 field public static final int IMPORTANCE_SERVICE = 300; // 0x12c field public static final int IMPORTANCE_TOP_SLEEPING = 150; // 0x96 field public static final int IMPORTANCE_VISIBLE = 200; // 0xc8 diff --git a/api/system-current.txt b/api/system-current.txt index b0eb10db5d8a..e87775f68ca3 100644 --- a/api/system-current.txt +++ b/api/system-current.txt @@ -4083,7 +4083,8 @@ package android.app { field public static final int IMPORTANCE_FOREGROUND = 100; // 0x64 field public static final int IMPORTANCE_FOREGROUND_SERVICE = 125; // 0x7d field public static final int IMPORTANCE_GONE = 1000; // 0x3e8 - field public static final int IMPORTANCE_PERCEPTIBLE = 130; // 0x82 + field public static final int IMPORTANCE_PERCEPTIBLE = 230; // 0xe6 + field public static final deprecated int IMPORTANCE_PERCEPTIBLE_DEPRECATED = 130; // 0x82 field public static final int IMPORTANCE_SERVICE = 300; // 0x12c field public static final int IMPORTANCE_TOP_SLEEPING = 150; // 0x96 field public static final int IMPORTANCE_VISIBLE = 200; // 0xc8 diff --git a/api/test-current.txt b/api/test-current.txt index 52a07faabeed..3690f4b1a333 100644 --- a/api/test-current.txt +++ b/api/test-current.txt @@ -3949,7 +3949,8 @@ package android.app { field public static final int IMPORTANCE_FOREGROUND = 100; // 0x64 field public static final int IMPORTANCE_FOREGROUND_SERVICE = 125; // 0x7d field public static final int IMPORTANCE_GONE = 1000; // 0x3e8 - field public static final int IMPORTANCE_PERCEPTIBLE = 130; // 0x82 + field public static final int IMPORTANCE_PERCEPTIBLE = 230; // 0xe6 + field public static final deprecated int IMPORTANCE_PERCEPTIBLE_DEPRECATED = 130; // 0x82 field public static final int IMPORTANCE_SERVICE = 300; // 0x12c field public static final int IMPORTANCE_TOP_SLEEPING = 150; // 0x96 field public static final int IMPORTANCE_VISIBLE = 200; // 0xc8 diff --git a/core/java/android/app/ActivityManager.java b/core/java/android/app/ActivityManager.java index 80482ca6e026..0f6671b55ae4 100644 --- a/core/java/android/app/ActivityManager.java +++ b/core/java/android/app/ActivityManager.java @@ -30,6 +30,8 @@ import android.graphics.GraphicBuffer; import android.graphics.Matrix; import android.graphics.Point; import android.os.BatteryStats; +import android.os.Build; +import android.os.Build.VERSION_CODES; import android.os.IBinder; import android.os.ParcelFileDescriptor; @@ -138,14 +140,17 @@ public class ActivityManager { static final class UidObserver extends IUidObserver.Stub { final OnUidImportanceListener mListener; + final Context mContext; - UidObserver(OnUidImportanceListener listener) { + UidObserver(OnUidImportanceListener listener, Context clientContext) { mListener = listener; + mContext = clientContext; } @Override public void onUidStateChanged(int uid, int procState, long procStateSeq) { - mListener.onUidImportance(uid, RunningAppProcessInfo.procStateToImportance(procState)); + mListener.onUidImportance(uid, RunningAppProcessInfo.procStateToImportanceForClient( + procState, mContext)); } @Override @@ -3081,10 +3086,32 @@ public class ActivityManager { public static final int IMPORTANCE_VISIBLE = 200; /** + * Constant for {@link #importance}: {@link #IMPORTANCE_PERCEPTIBLE} had this wrong value + * before {@link Build.VERSION_CODES#O}. Since the {@link Build.VERSION_CODES#O} SDK, + * the value of {@link #IMPORTANCE_PERCEPTIBLE} has been fixed. + * + * @deprecated Use {@link #IMPORTANCE_PERCEPTIBLE} instead. + */ + @Deprecated + public static final int IMPORTANCE_PERCEPTIBLE_DEPRECATED = 130; + + /** * Constant for {@link #importance}: This process is not something the user - * is directly aware of, but is otherwise perceptable to them to some degree. + * is directly aware of, but is otherwise perceptible to them to some degree. + */ + public static final int IMPORTANCE_PERCEPTIBLE = 230; + + /** + * Constant for {@link #importance}: {@link #IMPORTANCE_CANT_SAVE_STATE} had + * this wrong value + * before {@link Build.VERSION_CODES#O}. Since the {@link Build.VERSION_CODES#O} SDK, + * the value of {@link #IMPORTANCE_CANT_SAVE_STATE} has been fixed. + * + * @deprecated Use {@link #IMPORTANCE_CANT_SAVE_STATE} instead. + * @hide */ - public static final int IMPORTANCE_PERCEPTIBLE = 130; + @Deprecated + public static final int IMPORTANCE_CANT_SAVE_STATE_DEPRECATED = 170; /** * Constant for {@link #importance}: This process is running an @@ -3092,7 +3119,7 @@ public class ActivityManager { * while in the background. * @hide */ - public static final int IMPORTANCE_CANT_SAVE_STATE = 170; + public static final int IMPORTANCE_CANT_SAVE_STATE= 270; /** * Constant for {@link #importance}: This process is contains services @@ -3128,7 +3155,11 @@ public class ActivityManager { */ public static final int IMPORTANCE_GONE = 1000; - /** @hide */ + /** + * Convert a proc state to the correspondent IMPORTANCE_* constant. If the return value + * will be passed to a client, use {@link #procStateToImportanceForClient}. + * @hide + */ public static int procStateToImportance(int procState) { if (procState == PROCESS_STATE_NONEXISTENT) { return IMPORTANCE_GONE; @@ -3151,6 +3182,28 @@ public class ActivityManager { } } + /** + * Convert a proc state to the correspondent IMPORTANCE_* constant for a client represented + * by a given {@link Context}, with converting {@link #IMPORTANCE_PERCEPTIBLE} + * and {@link #IMPORTANCE_CANT_SAVE_STATE} to the corresponding "wrong" value if the + * client's target SDK < {@link VERSION_CODES#O}. + * @hide + */ + public static int procStateToImportanceForClient(int procState, Context clientContext) { + final int importance = procStateToImportance(procState); + + // For pre O apps, convert to the old, wrong values. + if (clientContext.getApplicationInfo().targetSdkVersion < VERSION_CODES.O) { + switch (importance) { + case IMPORTANCE_PERCEPTIBLE: + return IMPORTANCE_PERCEPTIBLE_DEPRECATED; + case IMPORTANCE_CANT_SAVE_STATE: + return IMPORTANCE_CANT_SAVE_STATE_DEPRECATED; + } + } + return importance; + } + /** @hide */ public static int importanceToProcState(int importance) { if (importance == IMPORTANCE_GONE) { @@ -3380,7 +3433,7 @@ public class ActivityManager { try { int procState = getService().getPackageProcessState(packageName, mContext.getOpPackageName()); - return RunningAppProcessInfo.procStateToImportance(procState); + return RunningAppProcessInfo.procStateToImportanceForClient(procState, mContext); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } @@ -3400,7 +3453,7 @@ public class ActivityManager { try { int procState = getService().getUidProcessState(uid, mContext.getOpPackageName()); - return RunningAppProcessInfo.procStateToImportance(procState); + return RunningAppProcessInfo.procStateToImportanceForClient(procState, mContext); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } @@ -3450,7 +3503,7 @@ public class ActivityManager { throw new IllegalArgumentException("Listener already registered: " + listener); } // TODO: implement the cut point in the system process to avoid IPCs. - UidObserver observer = new UidObserver(listener); + UidObserver observer = new UidObserver(listener, mContext); try { getService().registerUidObserver(observer, UID_OBSERVER_PROCSTATE | UID_OBSERVER_GONE, |