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

Commit 5e711d69 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Add a SIMULATE_ALLOW_FREEZE bind flag" into main

parents 438fb544 5531557c
Loading
Loading
Loading
Loading
+18 −0
Original line number Diff line number Diff line
@@ -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;
@@ -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.
+8 −7
Original line number Diff line number Diff line
@@ -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,
+4 −0
Original line number Diff line number Diff line
@@ -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;
+3 −0
Original line number Diff line number Diff line
@@ -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 ");
        }
+2 −3
Original line number Diff line number Diff line
@@ -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