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

Commit 6831749c authored by Sudheer Shanka's avatar Sudheer Shanka
Browse files

Allow EJs to obtain new network capability.

- Introduce new oom_adj score to be used for EJs so that they won't
  be killed before normal jobs but before any FGS. Also, add a new
  bind flag to instruct the OomAdjuster about when to use this
  new oom_adj score.
- Unlike other capabilities, any app (regardless of it's proc_state)
  with network capability will be able to transfer it's capability
  to other app by binding to it.

Bug: 177641226
Test: atest ./tests/app/src/android/app/cts/ActivityManagerProcessStateTest.java
Test: atest ./tests/cts/hostside/src/com/android/cts/net/HostsideRestrictBackgroundNetworkTests.java
Test: atest ./services/tests/mockingservicestests/src/com/android/server/am/MockingOomAdjusterTests.java
Test: atest CtsJobSchedulerTestCases

Change-Id: I888764ff22fba92fe2cccf3d8442ed318a19ad2a
parent 3ea9673b
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -271,7 +271,9 @@ public final class JobServiceContext implements ServiceConnection {
                if (job.shouldTreatAsExpeditedJob()) {
                    // TODO(171305774): The job should run on the little cores. We'll probably need
                    // another binding flag for that.
                    bindFlags = Context.BIND_AUTO_CREATE;
                    bindFlags = Context.BIND_AUTO_CREATE | Context.BIND_NOT_FOREGROUND
                            | Context.BIND_ALMOST_PERCEPTIBLE
                            | Context.BIND_ALLOW_NETWORK_ACCESS;
                } else {
                    bindFlags = Context.BIND_AUTO_CREATE | Context.BIND_NOT_FOREGROUND
                            | Context.BIND_NOT_PERCEPTIBLE;
+5 −0
Original line number Diff line number Diff line
@@ -91,6 +91,8 @@ package android.app {
    method @RequiresPermission(android.Manifest.permission.SET_ACTIVITY_WATCHER) public void addHomeVisibilityListener(@NonNull java.util.concurrent.Executor, @NonNull android.app.HomeVisibilityListener);
    method public void alwaysShowUnsupportedCompileSdkWarning(android.content.ComponentName);
    method public long getTotalRam();
    method @RequiresPermission(android.Manifest.permission.PACKAGE_USAGE_STATS) public int getUidProcessCapabilities(int);
    method @RequiresPermission(android.Manifest.permission.PACKAGE_USAGE_STATS) public int getUidProcessState(int);
    method public void holdLock(android.os.IBinder, int);
    method public static boolean isHighEndGfx();
    method @RequiresPermission(android.Manifest.permission.SET_ACTIVITY_WATCHER) public void removeHomeVisibilityListener(@NonNull android.app.HomeVisibilityListener);
@@ -106,7 +108,10 @@ package android.app {
    field public static final int PROCESS_CAPABILITY_FOREGROUND_CAMERA = 2; // 0x2
    field public static final int PROCESS_CAPABILITY_FOREGROUND_LOCATION = 1; // 0x1
    field public static final int PROCESS_CAPABILITY_FOREGROUND_MICROPHONE = 4; // 0x4
    field public static final int PROCESS_CAPABILITY_NETWORK = 8; // 0x8
    field public static final int PROCESS_CAPABILITY_NONE = 0; // 0x0
    field public static final int PROCESS_STATE_FOREGROUND_SERVICE = 4; // 0x4
    field public static final int PROCESS_STATE_TOP = 2; // 0x2
  }

  public static class ActivityManager.RunningAppProcessInfo implements android.os.Parcelable {
+33 −0
Original line number Diff line number Diff line
@@ -511,6 +511,7 @@ public class ActivityManager {
    /** @hide Process is hosting the current top activities.  Note that this covers
     * all activities that are visible to the user. */
    @UnsupportedAppUsage
    @TestApi
    public static final int PROCESS_STATE_TOP = ProcessStateEnum.TOP;

    /** @hide Process is bound to a TOP app. */
@@ -518,6 +519,7 @@ public class ActivityManager {

    /** @hide Process is hosting a foreground service. */
    @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
    @TestApi
    public static final int PROCESS_STATE_FOREGROUND_SERVICE = ProcessStateEnum.FOREGROUND_SERVICE;

    /** @hide Process is hosting a foreground service due to a system binding. */
@@ -617,6 +619,7 @@ public class ActivityManager {
    public static final int PROCESS_CAPABILITY_FOREGROUND_MICROPHONE = 1 << 2;

    /** @hide Process can access network despite any power saving resrictions */
    @TestApi
    public static final int PROCESS_CAPABILITY_NETWORK = 1 << 3;

    /** @hide all capabilities, the ORing of all flags in {@link ProcessCapability}*/
@@ -3431,6 +3434,36 @@ public class ActivityManager {
        return SystemProperties.getBoolean("persist.sys.lmk.reportkills", false);
    }

    /**
     * Returns the process state of this uid.
     *
     * @hide
     */
    @TestApi
    @RequiresPermission(Manifest.permission.PACKAGE_USAGE_STATS)
    public int getUidProcessState(int uid) {
        try {
            return getService().getUidProcessState(uid, mContext.getOpPackageName());
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

    /**
     * Returns the process capability of this uid.
     *
     * @hide
     */
    @TestApi
    @RequiresPermission(Manifest.permission.PACKAGE_USAGE_STATS)
    public @ProcessCapability int getUidProcessCapabilities(int uid) {
        try {
            return getService().getUidProcessCapabilities(uid, mContext.getOpPackageName());
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

    /**
     * Return the importance of a given package name, based on the processes that are
     * currently running.  The return value is one of the importance constants defined
+2 −0
Original line number Diff line number Diff line
@@ -707,4 +707,6 @@ interface IActivityManager {

    /** Called by PendingIntent.queryIntentComponents() */
    List<ResolveInfo> queryIntentComponentsForIntentSender(in IIntentSender sender, int matchFlags);

    int getUidProcessCapabilities(int uid, in String callingPackage);
}
+19 −0
Original line number Diff line number Diff line
@@ -369,6 +369,25 @@ public abstract class Context {
    /***********    Public flags above this line ***********/
    /***********    Hidden flags below this line ***********/

    /**
     * Flag for {@link #bindService}: allow the process hosting the target service to be treated
     * as if it's as important as a perceptible app to the user and avoid the oom killer killing
     * this process in low memory situations until there aren't any other processes left but the
     * ones which are user-perceptible.
     *
     * @hide
     */
    public static final int BIND_ALMOST_PERCEPTIBLE = 0x000010000;

    /**
     * Flag for {@link #bindService}: allow the process hosting the target service to gain
     * {@link ActivityManager#PROCESS_CAPABILITY_NETWORK}, which allows it be able
     * to access network regardless of any power saving restrictions.
     *
     * @hide
     */
    public static final int BIND_ALLOW_NETWORK_ACCESS = 0x00020000;

    /**
     * Flag for {@link #bindService}: allow background foreground service starts from the bound
     * service's process.
Loading