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

Commit 5016a789 authored by Amith Yamasani's avatar Amith Yamasani
Browse files

Expose BIND_NOT_PERCEPTIBLE service flag

Using this flag when binding to a service will
allow the bound process to be held at a low
oom_adj of 250, so that it can be expunged to
reclaim memory if a more user-visible app needs
it.

Use for bindings such as job services and other
connections that the caller can easily recover
from and restart if necessary.

Adjust the lmk thresholds to use this oom_adj
as one of the levels, so they're killed before
perceptible apps (such as foreground services).

Bug: 135219821
Test: CtsAppTestCases
      Manually check notification listener oom_adj
      and dumpsys activity services output

Change-Id: I9f6d0891d842e4d12f7995b9b1a8f57b0903a16d
parent 1ed4ce01
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -9808,6 +9808,7 @@ package android.content {
    field public static final int BIND_IMPORTANT = 64; // 0x40
    field public static final int BIND_INCLUDE_CAPABILITIES = 4096; // 0x1000
    field public static final int BIND_NOT_FOREGROUND = 4; // 0x4
    field public static final int BIND_NOT_PERCEPTIBLE = 256; // 0x100
    field public static final int BIND_WAIVE_PRIORITY = 32; // 0x20
    field public static final String BIOMETRIC_SERVICE = "biometric";
    field public static final String BLUETOOTH_SERVICE = "bluetooth";
+13 −12
Original line number Diff line number Diff line
@@ -234,7 +234,9 @@ public abstract class Context {
            BIND_ALLOW_OOM_MANAGEMENT,
            BIND_WAIVE_PRIORITY,
            BIND_IMPORTANT,
            BIND_ADJUST_WITH_ACTIVITY
            BIND_ADJUST_WITH_ACTIVITY,
            BIND_NOT_PERCEPTIBLE,
            BIND_INCLUDE_CAPABILITIES
    })
    @Retention(RetentionPolicy.SOURCE)
    public @interface BindServiceFlags {}
@@ -328,26 +330,25 @@ public abstract class Context {
     */
    public static final int BIND_ADJUST_WITH_ACTIVITY = 0x0080;

    /**
     * Flag for {@link #bindService}: If binding from an app that is visible or user-perceptible,
     * lower the target service's importance to below the perceptible level. This allows
     * the system to (temporarily) expunge the bound process from memory to make room for more
     * important user-perceptible processes.
     */
    public static final int BIND_NOT_PERCEPTIBLE = 0x00000100;

    /**
     * Flag for {@link #bindService}: If binding from an app that has specific capabilities
     * due to its foreground state such as an activity or foreground service, then this flag will
     * allow the bound app to get the same capabilities, as long as it has the required permissions
     * as well.
     */
    public static final int BIND_INCLUDE_CAPABILITIES = 0x00001000;
    public static final int BIND_INCLUDE_CAPABILITIES = 0x000001000;

    /***********    Public flags above this line ***********/
    /***********    Hidden flags below this line ***********/

    /**
     * Flag for {@link #bindService}: If binding from something better than perceptible,
     * still set the adjust below perceptible. This would be used for bound services that can
     * afford to be evicted when under extreme memory pressure, but should be restarted as soon
     * as possible.
     * @hide
     */
    public static final int BIND_ADJUST_BELOW_PERCEPTIBLE = 0x00040000;

    /**
     * Flag for {@link #bindService}: This flag is intended to be used only by the system to adjust
     * the scheduling policy for IMEs (and any other out-of-process user-visible components that
@@ -473,7 +474,7 @@ public abstract class Context {
     */
    public static final int BIND_REDUCTION_FLAGS =
            Context.BIND_ALLOW_OOM_MANAGEMENT | Context.BIND_WAIVE_PRIORITY
                    | Context.BIND_ADJUST_BELOW_PERCEPTIBLE | Context.BIND_NOT_VISIBLE;
                    | Context.BIND_NOT_PERCEPTIBLE | Context.BIND_NOT_VISIBLE;

    /** @hide */
    @IntDef(flag = true, prefix = { "RECEIVER_VISIBLE_" }, value = {
+2 −0
Original line number Diff line number Diff line
@@ -591,6 +591,8 @@ message ConnectionRecordProto {
        SHOWING_UI = 13;
        NOT_VISIBLE = 14;
        DEAD = 15;
        NOT_PERCEPTIBLE = 16;
        INCLUDE_CAPABILITIES = 17;
    }
    repeated Flag flags = 3;
    optional string service_name = 4;
+10 −0
Original line number Diff line number Diff line
@@ -65,6 +65,8 @@ final class ConnectionRecord {
            Context.BIND_VISIBLE,
            Context.BIND_SHOWING_UI,
            Context.BIND_NOT_VISIBLE,
            Context.BIND_NOT_PERCEPTIBLE,
            Context.BIND_INCLUDE_CAPABILITIES,
    };
    private static final int[] BIND_PROTO_ENUMS = new int[] {
            ConnectionRecordProto.AUTO_CREATE,
@@ -82,6 +84,8 @@ final class ConnectionRecord {
            ConnectionRecordProto.VISIBLE,
            ConnectionRecordProto.SHOWING_UI,
            ConnectionRecordProto.NOT_VISIBLE,
            ConnectionRecordProto.NOT_PERCEPTIBLE,
            ConnectionRecordProto.INCLUDE_CAPABILITIES,
    };

    void dump(PrintWriter pw, String prefix) {
@@ -212,6 +216,12 @@ final class ConnectionRecord {
        if ((flags&Context.BIND_NOT_VISIBLE) != 0) {
            sb.append("!VIS ");
        }
        if ((flags & Context.BIND_NOT_PERCEPTIBLE) != 0) {
            sb.append("!PRCP ");
        }
        if ((flags & Context.BIND_INCLUDE_CAPABILITIES) != 0) {
            sb.append("CAPS ");
        }
        if (serviceDead) {
            sb.append("DEAD ");
        }
+1 −1
Original line number Diff line number Diff line
@@ -1264,7 +1264,7 @@ public final class OomAdjuster {
                                        cr.trackProcState(procState, mAdjSeq, now);
                                        trackedProcState = true;
                                    }
                                } else if ((cr.flags & Context.BIND_ADJUST_BELOW_PERCEPTIBLE) != 0
                                } else if ((cr.flags & Context.BIND_NOT_PERCEPTIBLE) != 0
                                        && clientAdj < ProcessList.PERCEPTIBLE_APP_ADJ
                                        && adj > ProcessList.PERCEPTIBLE_LOW_APP_ADJ) {
                                    newAdj = ProcessList.PERCEPTIBLE_LOW_APP_ADJ;
Loading