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

Commit 3f6d9e89 authored by David Riley's avatar David Riley
Browse files

Add rebindService API to update binding flags.

This will allow applications to eliminate multiple bindings to handle
the case of needing to increase or decrease priority of service
processes by allowing them to repurpose a single binding.

Bug: 424003130
Flag: android.content.flags.enable_update_service_bindings
Test: atest android.app.cts.service.ServiceTest
Change-Id: I24b01ccc8bf5f15b5fe12efb243430413f3f79d5
parent 008772e7
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -11199,6 +11199,7 @@ package android.content {
    method public abstract android.database.sqlite.SQLiteDatabase openOrCreateDatabase(String, int, android.database.sqlite.SQLiteDatabase.CursorFactory);
    method public abstract android.database.sqlite.SQLiteDatabase openOrCreateDatabase(String, int, android.database.sqlite.SQLiteDatabase.CursorFactory, @Nullable android.database.DatabaseErrorHandler);
    method @Deprecated public abstract android.graphics.drawable.Drawable peekWallpaper();
    method @FlaggedApi("android.content.flags.enable_update_service_bindings") public void rebindService(@NonNull android.content.ServiceConnection, @NonNull android.content.Context.BindServiceFlags);
    method public void registerComponentCallbacks(android.content.ComponentCallbacks);
    method public void registerDeviceIdChangeListener(@NonNull java.util.concurrent.Executor, @NonNull java.util.function.IntConsumer);
    method @Nullable public abstract android.content.Intent registerReceiver(@Nullable android.content.BroadcastReceiver, android.content.IntentFilter);
+1 −1
Original line number Diff line number Diff line
@@ -522,7 +522,7 @@ public abstract class ActivityManagerInternal {
    public static final int OOM_ADJ_REASON_SERVICE_BINDER_CALL = 25;

    /**
     * Oom Adj Reason: Batched updated request.
     * Oom Adj Reason: Batched service binding update request
     */
    public static final int OOM_ADJ_REASON_BATCH_UPDATE_REQUEST = 26;

+26 −0
Original line number Diff line number Diff line
@@ -2372,6 +2372,32 @@ class ContextImpl extends Context {
        }
    }

    @Override
    public void rebindService(ServiceConnection conn, @NonNull BindServiceFlags flags) {
        if (conn == null) {
            throw new IllegalArgumentException("ServiceConnection is null");
        }
        if (mPackageInfo == null) {
            throw new RuntimeException("Not supported in system context");
        }
        final IServiceConnection sd = mPackageInfo.lookupServiceDispatcher(
                        conn, getOuterContext());
        if (sd == null) {
            throw new IllegalArgumentException("ServiceConnection not currently bound: " + conn);
        }
        final BindUpdateInfo update = new BindUpdateInfo();
        update.connection = sd.asBinder();
        update.unbind = false;
        update.flags = flags.getValue();
        final ArrayList<BindUpdateInfo> updates = new ArrayList<>(1);
        updates.add(update);
        try {
            ActivityManager.getService().updateServiceBindings(updates);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

    @Override
    public boolean startInstrumentation(ComponentName className,
            String profileFile, Bundle arguments) {
+18 −0
Original line number Diff line number Diff line
@@ -4467,6 +4467,24 @@ public abstract class Context {
     */
    public abstract void unbindService(@NonNull ServiceConnection conn);

    /**
     * Rebind an application service with updated bind service flags
     *
     * @param conn The connection interface previously supplied to
     *             bindService().  This parameter must not be null.
     * @param flags Updated flags for the binding as per {@link #bindService}.
     *              Only flags returned from {@link #getUpdateableFlags} may
     *              be added or removed.
     *
     * @see #bindService
     * @see #updateServiceBindings
     */
    @FlaggedApi(FLAG_ENABLE_UPDATE_SERVICE_BINDINGS)
    public void rebindService(@NonNull ServiceConnection conn,
            @NonNull BindServiceFlags flags) {
        throw new RuntimeException("Not implemented. Must override in a subclass.");
    }

    /**
     * Start executing an {@link android.app.Instrumentation} class.  The given
     * Instrumentation component will be run by killing its target application
+7 −0
Original line number Diff line number Diff line
@@ -973,6 +973,13 @@ public class ContextWrapper extends Context {
        mBase.unbindService(conn);
    }


    @Override
    public void rebindService(@NonNull ServiceConnection conn,
            @NonNull BindServiceFlags flags) {
        mBase.rebindService(conn, flags);
    }

    @Override
    public boolean startInstrumentation(ComponentName className,
            @Nullable String profileFile, @Nullable Bundle arguments) {