Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 83249ec4 authored by Dianne Hackborn's avatar Dianne Hackborn
Browse files

Add API to get a uid's current importance.

This is kind-of useful to go along with monitoring
uid importance changes.

Test: none yet

Change-Id: Ic0f8418955d17ea21d06f49dcd9641bc5f32387b
parent 4a306894
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -3980,6 +3980,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();
+1 −0
Original line number Diff line number Diff line
@@ -3848,6 +3848,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();
+20 −0
Original line number Diff line number Diff line
@@ -3346,6 +3346,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}.
+1 −0
Original line number Diff line number Diff line
@@ -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);
+13 −0
Original line number Diff line number Diff line
@@ -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) {