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

Commit 585ce26c authored by Sanjana Sunil's avatar Sanjana Sunil
Browse files

Modify bindSupplementalProcess parameters

Allow to pass different flags to the API as opposed to setting it to
BIND_AUTO_CREATE by default. The API is renamed to
bindSupplementalProcess accordingly. Additionally, the process name is
allowed to be passed from the caller side.

Test: Manual, install suplemental process test apps and see processes
Bug: 218314884
Bug: 209058402
Change-Id: I0809f824c64d2512feff44e131c40f0ea8bc8ed3
parent a04c2370
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -1998,7 +1998,7 @@ class ContextImpl extends Context {
    private boolean bindServiceCommon(Intent service, ServiceConnection conn, int flags,
            String instanceName, Handler handler, Executor executor, UserHandle user) {
        // Keep this in sync with DevicePolicyManager.bindDeviceAdminServiceAsUser and
        // ActivityManagerService.LocalService.startAndBindSupplementalProcessService
        // ActivityManagerLocal.bindSupplementalProcessService
        IServiceConnection sd;
        if (conn == null) {
            throw new IllegalArgumentException("connection is null");
+1 −1
Original line number Diff line number Diff line
@@ -38,8 +38,8 @@ package com.android.server {
package com.android.server.am {

  public interface ActivityManagerLocal {
    method public boolean bindSupplementalProcessService(@NonNull android.content.Intent, @NonNull android.content.ServiceConnection, int, @NonNull String, int) throws android.os.RemoteException;
    method public boolean canStartForegroundService(int, int, @NonNull String);
    method public boolean startAndBindSupplementalProcessService(@NonNull android.content.Intent, @NonNull android.content.ServiceConnection, int) throws android.os.TransactionTooLargeException;
  }

}
+3 −1
Original line number Diff line number Diff line
@@ -3411,9 +3411,11 @@ public final class ActiveServices {
                    final Intent.FilterComparison filter
                            = new Intent.FilterComparison(service.cloneFilter());
                    final ServiceRestarter res = new ServiceRestarter();
                    String supplementalProcessName = isSupplementalProcessService ? instanceName
                                                                                  : null;
                    r = new ServiceRecord(mAm, className, name, definingPackageName,
                            definingUid, filter, sInfo, callingFromFg, res,
                            isSupplementalProcessService);
                            supplementalProcessName);
                    res.setService(r);
                    smap.mServicesByInstanceName.put(name, r);
                    smap.mServicesByIntent.put(filter, r);
+16 −8
Original line number Diff line number Diff line
@@ -17,10 +17,12 @@
package com.android.server.am;

import android.annotation.NonNull;
import android.annotation.SuppressLint;
import android.annotation.SystemApi;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.TransactionTooLargeException;
import android.os.RemoteException;

/**
 * Interface for in-process calls into
@@ -63,22 +65,28 @@ public interface ActivityManagerLocal {
    void tempAllowWhileInUsePermissionInFgs(int uid, long durationMs);

    /**
     * Starts a supplemental process service and binds to it. You can through the arguments here
     * have the system bring up multiple concurrent processes hosting their own instance of that
     * service. The <var>userAppUid</var> you provide here identifies the different instances - each
     * unique uid is attributed to a supplemental process.
     * Binds to a supplemental process service, creating it if needed. You can through the arguments
     * here have the system bring up multiple concurrent processes hosting their own instance of
     * that service. The {@code processName} you provide here identifies the different instances.
     *
     * @param service Identifies the supplemental process service to connect to. The Intent must
     *        specify an explicit component name. This value cannot be null.
     * @param conn Receives information as the service is started and stopped.
     *        This must be a valid ServiceConnection object; it must not be null.
     * @param userAppUid Uid of the app for which the supplemental process needs to be spawned.
     * @param processName Unique identifier for the service instance. Each unique name here will
     *        result in a different service instance being created. Identifiers must only contain
     *        ASCII letters, digits, underscores, and periods.
     * @param flags Operation options provided by Context class for the binding.
     * @return {@code true} if the system is in the process of bringing up a
     *         service that your client has permission to bind to; {@code false}
     *         if the system couldn't find the service or if your client doesn't
     *         have permission to bind to it.
     * @throws RemoteException If the service could not be brought up.
     * @see Context#bindService(Intent, ServiceConnection, int)
     */
    boolean startAndBindSupplementalProcessService(@NonNull Intent service,
            @NonNull ServiceConnection conn, int userAppUid) throws TransactionTooLargeException;

    @SuppressLint("RethrowRemoteException")
    boolean bindSupplementalProcessService(@NonNull Intent service, @NonNull ServiceConnection conn,
            int userAppUid, @NonNull String processName, @Context.BindServiceFlags int flags)
            throws RemoteException;
}
+9 −7
Original line number Diff line number Diff line
@@ -15922,14 +15922,17 @@ public class ActivityManagerService extends IActivityManager.Stub
        }
        @Override
        public boolean startAndBindSupplementalProcessService(Intent service,
                ServiceConnection conn, int userAppUid) throws TransactionTooLargeException {
        public boolean bindSupplementalProcessService(Intent service, ServiceConnection conn,
                int userAppUid, String processName, int flags) throws RemoteException {
            if (service == null) {
                throw new IllegalArgumentException("intent is null");
            }
            if (conn == null) {
                throw new IllegalArgumentException("connection is null");
            }
            if (processName == null) {
                throw new IllegalArgumentException("processName is null");
            }
            if (service.getComponent() == null) {
                throw new IllegalArgumentException("service must specify explicit component");
            }
@@ -15938,15 +15941,14 @@ public class ActivityManagerService extends IActivityManager.Stub
            }
            Handler handler = mContext.getMainThreadHandler();
            int flags = Context.BIND_AUTO_CREATE;
            final IServiceConnection sd = mContext.getServiceDispatcher(conn, handler, flags);
            service.prepareToLeaveProcess(mContext);
            return ActivityManagerService.this.bindServiceInstance(
                    mContext.getIApplicationThread(), mContext.getActivityToken(), service,
                    service.resolveTypeIfNeeded(mContext.getContentResolver()), sd, flags,
                        Integer.toString(userAppUid), /*isSupplementalProcessService*/ true,
                        mContext.getOpPackageName(), UserHandle.getUserId(userAppUid)) != 0;
                    processName, /*isSupplementalProcessService*/ true, mContext.getOpPackageName(),
                    UserHandle.getUserId(userAppUid)) != 0;
        }
        @Override
Loading