Merge "Add API to get a uid's current importance." into oc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
ad6ab44e15
@@ -3982,6 +3982,7 @@ package android.app {
|
||||
method public android.app.PendingIntent getRunningServiceControlPanel(android.content.ComponentName) throws java.lang.SecurityException;
|
||||
method public java.util.List<android.app.ActivityManager.RunningServiceInfo> getRunningServices(int) throws java.lang.SecurityException;
|
||||
method public deprecated java.util.List<android.app.ActivityManager.RunningTaskInfo> getRunningTasks(int) throws java.lang.SecurityException;
|
||||
method public int getUidImportance(int);
|
||||
method public deprecated boolean isInLockTaskMode();
|
||||
method public boolean isLowRamDevice();
|
||||
method public static boolean isRunningInTestHarness();
|
||||
|
||||
@@ -3849,6 +3849,7 @@ package android.app {
|
||||
method public android.app.PendingIntent getRunningServiceControlPanel(android.content.ComponentName) throws java.lang.SecurityException;
|
||||
method public java.util.List<android.app.ActivityManager.RunningServiceInfo> getRunningServices(int) throws java.lang.SecurityException;
|
||||
method public deprecated java.util.List<android.app.ActivityManager.RunningTaskInfo> getRunningTasks(int) throws java.lang.SecurityException;
|
||||
method public int getUidImportance(int);
|
||||
method public deprecated boolean isInLockTaskMode();
|
||||
method public boolean isLowRamDevice();
|
||||
method public static boolean isRunningInTestHarness();
|
||||
|
||||
@@ -3386,6 +3386,26 @@ public class ActivityManager {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the importance of a given uid, based on the processes that are
|
||||
* currently running. The return value is one of the importance constants defined
|
||||
* in {@link RunningAppProcessInfo}, giving you the highest importance of all the
|
||||
* processes that this uid has running. If there are no processes
|
||||
* running its code, {@link RunningAppProcessInfo#IMPORTANCE_GONE} is returned.
|
||||
* @hide
|
||||
*/
|
||||
@SystemApi @TestApi
|
||||
@RequiresPermission(Manifest.permission.PACKAGE_USAGE_STATS)
|
||||
public int getUidImportance(int uid) {
|
||||
try {
|
||||
int procState = getService().getUidProcessState(uid,
|
||||
mContext.getOpPackageName());
|
||||
return RunningAppProcessInfo.procStateToImportance(procState);
|
||||
} catch (RemoteException e) {
|
||||
throw e.rethrowFromSystemServer();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback to get reports about changes to the importance of a uid. Use with
|
||||
* {@link #addOnUidImportanceListener}.
|
||||
|
||||
@@ -463,6 +463,7 @@ interface IActivityManager {
|
||||
* etc.
|
||||
*/
|
||||
void keyguardGoingAway(int flags);
|
||||
int getUidProcessState(int uid, in String callingPackage);
|
||||
void registerUidObserver(in IUidObserver observer, int which, int cutpoint,
|
||||
String callingPackage);
|
||||
void unregisterUidObserver(in IUidObserver observer);
|
||||
|
||||
@@ -13024,6 +13024,19 @@ public class ActivityManagerService extends IActivityManager.Stub
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getUidProcessState(int uid, String callingPackage) {
|
||||
if (!hasUsageStatsPermission(callingPackage)) {
|
||||
enforceCallingPermission(android.Manifest.permission.PACKAGE_USAGE_STATS,
|
||||
"getUidProcessState");
|
||||
}
|
||||
|
||||
synchronized (this) {
|
||||
UidRecord uidRec = mActiveUids.get(uid);
|
||||
return uidRec != null ? uidRec.curProcState : ActivityManager.PROCESS_STATE_NONEXISTENT;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerUidObserver(IUidObserver observer, int which, int cutpoint,
|
||||
String callingPackage) {
|
||||
|
||||
Reference in New Issue
Block a user