Loading core/java/android/content/Context.java +18 −0 Original line number Diff line number Diff line Loading @@ -54,6 +54,7 @@ import android.app.BroadcastOptions; import android.app.GameManager; import android.app.GrammaticalInflectionManager; import android.app.IApplicationThread; import android.app.IBinderSession; import android.app.IServiceConnection; import android.app.VrManager; import android.app.ambientcontext.AmbientContextManager; Loading Loading @@ -748,11 +749,28 @@ public abstract class Context { /** * Flag for {@link #bindService} that allows the bound app to be frozen if it is eligible. * When used, this provides the caller an {@link android.app.IBinderSession} via * {@link ServiceConnection#onServiceConnected(ComponentName, IBinder, IBinderSession)}. This * object can be used to unfreeze the remote process to allow it to process any binder calls * made on the bound service. * * <p> Currently, this is only meant for outgoing bindings from the system process. * * @hide */ public static final long BIND_ALLOW_FREEZE = 0x4_0000_0000L; /** * Flag for {@link #bindService} that enables receiving an {@link android.app.IBinderSession} * via {@link ServiceConnection#onServiceConnected(ComponentName, IBinder, IBinderSession)}. * * This acts as a dry run of {@link #BIND_ALLOW_FREEZE}, where the system will not actually * freeze the remote process even if it is not processing any binder call on the bound service. * * @hide */ public static final long BIND_SIMULATE_ALLOW_FREEZE = 0x8_0000_0000L; /** * These bind flags reduce the strength of the binding such that we shouldn't * consider it as pulling the process up to the level of the one that is bound to it. Loading core/java/android/content/ServiceConnection.java +8 −7 Original line number Diff line number Diff line Loading @@ -50,19 +50,20 @@ public interface ServiceConnection { /** * Same as {@link #onServiceConnected(ComponentName, IBinder)} but provides a * {@link IBinderSession} to account for binder calls to a frozen remote process whenever the * {@link Context#BIND_ALLOW_FREEZE} was used with the bindService call. * {@link Context#BIND_ALLOW_FREEZE} or {@link Context#BIND_SIMULATE_ALLOW_FREEZE} was used with * the bindService call. Other clients can continue overriding and using * {@link #onServiceConnected(ComponentName, IBinder)} normally. * * <p>Clients who do not use the {@link Context#BIND_ALLOW_FREEZE} flag can continue using * {@link #onServiceConnected(ComponentName, IBinder)} normally. Note that clients that use * {@link Context#BIND_ALLOW_FREEZE} but do not override this will have to deal with the remote * process's frozen state on their own. * <p> Note that clients that use {@link Context#BIND_ALLOW_FREEZE} but do not override this * will have to deal with the remote process's frozen state on their own. * * @param name The concrete component name of the service that has been connected. * @param service The IBinder of the Service's communication channel, which you can now make * calls on. * @param binderSession An IBinderSession used to keep the remote service unfrozen to process * any binder calls. Will be {@code null} when * {@link Context#BIND_ALLOW_FREEZE} was not used. * any binder calls. Will be {@code null} when neither * {@link Context#BIND_ALLOW_FREEZE} nor * {@link Context#BIND_SIMULATE_ALLOW_FREEZE} was used. * @hide */ default void onServiceConnected(ComponentName name, IBinder service, Loading services/core/java/com/android/server/am/ActiveServices.java +4 −0 Original line number Diff line number Diff line Loading @@ -4166,6 +4166,10 @@ public final class ActiveServices { throw new SecurityException("Non-system caller (pid=" + callingPid + ") set BIND_ALLOW_FREEZE when binding service " + service); } if ((flags & Context.BIND_SIMULATE_ALLOW_FREEZE) != 0 && !isCallerSystem) { throw new SecurityException("Non-system caller (pid=" + callingPid + ") set BIND_SIMULATE_ALLOW_FREEZE when binding service " + service); } final boolean callerFg = callerApp.mState.getSetSchedGroup() != ProcessList.SCHED_GROUP_BACKGROUND; Loading services/core/java/com/android/server/am/ConnectionRecord.java +3 −0 Original line number Diff line number Diff line Loading @@ -309,6 +309,9 @@ final class ConnectionRecord implements OomAdjusterImpl.Connection{ if (hasFlag(Context.BIND_ALLOW_FREEZE)) { sb.append("!CPU "); } if (hasFlag(Context.BIND_SIMULATE_ALLOW_FREEZE)) { sb.append("S!CPU "); } if (serviceDead) { sb.append("DEAD "); } Loading services/core/java/com/android/server/am/ProcessStateController.java +2 −3 Original line number Diff line number Diff line Loading @@ -124,11 +124,10 @@ public class ProcessStateController { * associates a new one if required. */ public BoundServiceSession getBoundServiceSessionFor(ConnectionRecord connectionRecord) { if (connectionRecord.notHasFlag(Context.BIND_ALLOW_FREEZE)) { if (connectionRecord.notHasFlag(Context.BIND_ALLOW_FREEZE) && connectionRecord.notHasFlag( Context.BIND_SIMULATE_ALLOW_FREEZE)) { // Don't incur the memory and compute overhead for process state adjustments for all // bindings by default. This should be opted into as needed. // TODO: b/415379524 - Add a debug flag to allow clients to opt-in to binder call // accounting without having to use BIND_ALLOW_FREEZE. return null; } if (connectionRecord.mBoundServiceSession != null) { Loading Loading
core/java/android/content/Context.java +18 −0 Original line number Diff line number Diff line Loading @@ -54,6 +54,7 @@ import android.app.BroadcastOptions; import android.app.GameManager; import android.app.GrammaticalInflectionManager; import android.app.IApplicationThread; import android.app.IBinderSession; import android.app.IServiceConnection; import android.app.VrManager; import android.app.ambientcontext.AmbientContextManager; Loading Loading @@ -748,11 +749,28 @@ public abstract class Context { /** * Flag for {@link #bindService} that allows the bound app to be frozen if it is eligible. * When used, this provides the caller an {@link android.app.IBinderSession} via * {@link ServiceConnection#onServiceConnected(ComponentName, IBinder, IBinderSession)}. This * object can be used to unfreeze the remote process to allow it to process any binder calls * made on the bound service. * * <p> Currently, this is only meant for outgoing bindings from the system process. * * @hide */ public static final long BIND_ALLOW_FREEZE = 0x4_0000_0000L; /** * Flag for {@link #bindService} that enables receiving an {@link android.app.IBinderSession} * via {@link ServiceConnection#onServiceConnected(ComponentName, IBinder, IBinderSession)}. * * This acts as a dry run of {@link #BIND_ALLOW_FREEZE}, where the system will not actually * freeze the remote process even if it is not processing any binder call on the bound service. * * @hide */ public static final long BIND_SIMULATE_ALLOW_FREEZE = 0x8_0000_0000L; /** * These bind flags reduce the strength of the binding such that we shouldn't * consider it as pulling the process up to the level of the one that is bound to it. Loading
core/java/android/content/ServiceConnection.java +8 −7 Original line number Diff line number Diff line Loading @@ -50,19 +50,20 @@ public interface ServiceConnection { /** * Same as {@link #onServiceConnected(ComponentName, IBinder)} but provides a * {@link IBinderSession} to account for binder calls to a frozen remote process whenever the * {@link Context#BIND_ALLOW_FREEZE} was used with the bindService call. * {@link Context#BIND_ALLOW_FREEZE} or {@link Context#BIND_SIMULATE_ALLOW_FREEZE} was used with * the bindService call. Other clients can continue overriding and using * {@link #onServiceConnected(ComponentName, IBinder)} normally. * * <p>Clients who do not use the {@link Context#BIND_ALLOW_FREEZE} flag can continue using * {@link #onServiceConnected(ComponentName, IBinder)} normally. Note that clients that use * {@link Context#BIND_ALLOW_FREEZE} but do not override this will have to deal with the remote * process's frozen state on their own. * <p> Note that clients that use {@link Context#BIND_ALLOW_FREEZE} but do not override this * will have to deal with the remote process's frozen state on their own. * * @param name The concrete component name of the service that has been connected. * @param service The IBinder of the Service's communication channel, which you can now make * calls on. * @param binderSession An IBinderSession used to keep the remote service unfrozen to process * any binder calls. Will be {@code null} when * {@link Context#BIND_ALLOW_FREEZE} was not used. * any binder calls. Will be {@code null} when neither * {@link Context#BIND_ALLOW_FREEZE} nor * {@link Context#BIND_SIMULATE_ALLOW_FREEZE} was used. * @hide */ default void onServiceConnected(ComponentName name, IBinder service, Loading
services/core/java/com/android/server/am/ActiveServices.java +4 −0 Original line number Diff line number Diff line Loading @@ -4166,6 +4166,10 @@ public final class ActiveServices { throw new SecurityException("Non-system caller (pid=" + callingPid + ") set BIND_ALLOW_FREEZE when binding service " + service); } if ((flags & Context.BIND_SIMULATE_ALLOW_FREEZE) != 0 && !isCallerSystem) { throw new SecurityException("Non-system caller (pid=" + callingPid + ") set BIND_SIMULATE_ALLOW_FREEZE when binding service " + service); } final boolean callerFg = callerApp.mState.getSetSchedGroup() != ProcessList.SCHED_GROUP_BACKGROUND; Loading
services/core/java/com/android/server/am/ConnectionRecord.java +3 −0 Original line number Diff line number Diff line Loading @@ -309,6 +309,9 @@ final class ConnectionRecord implements OomAdjusterImpl.Connection{ if (hasFlag(Context.BIND_ALLOW_FREEZE)) { sb.append("!CPU "); } if (hasFlag(Context.BIND_SIMULATE_ALLOW_FREEZE)) { sb.append("S!CPU "); } if (serviceDead) { sb.append("DEAD "); } Loading
services/core/java/com/android/server/am/ProcessStateController.java +2 −3 Original line number Diff line number Diff line Loading @@ -124,11 +124,10 @@ public class ProcessStateController { * associates a new one if required. */ public BoundServiceSession getBoundServiceSessionFor(ConnectionRecord connectionRecord) { if (connectionRecord.notHasFlag(Context.BIND_ALLOW_FREEZE)) { if (connectionRecord.notHasFlag(Context.BIND_ALLOW_FREEZE) && connectionRecord.notHasFlag( Context.BIND_SIMULATE_ALLOW_FREEZE)) { // Don't incur the memory and compute overhead for process state adjustments for all // bindings by default. This should be opted into as needed. // TODO: b/415379524 - Add a debug flag to allow clients to opt-in to binder call // accounting without having to use BIND_ALLOW_FREEZE. return null; } if (connectionRecord.mBoundServiceSession != null) { Loading