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

Commit da3ae494 authored by kholoud mohamed's avatar kholoud mohamed Committed by Kholoud Mohamed
Browse files

Change bindServiceAsUser from system to public API

Also, add RequiresPermission annotation for INTERACT_ACROSS_PROFILES
INTERACT_ACROSS_PROFILES should work as a replacement for INTERACT_ACROSS_USERS
for this API when binding to the caller package in some user of the same user
group as the caller, so we don't have to give privileged system components a
permission that is more powerful than is necessary.

BUG: 136249261
BUG: 138645036
Test: Build succeeds
Change-Id: I53c59ecc78a67ea9d324d60787d3b647b7251ea9
parent 2ddb0eb5
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -9823,6 +9823,7 @@ package android.content {
    method public boolean bindIsolatedService(@NonNull @RequiresPermission android.content.Intent, int, @NonNull String, @NonNull java.util.concurrent.Executor, @NonNull android.content.ServiceConnection);
    method public abstract boolean bindService(@RequiresPermission android.content.Intent, @NonNull android.content.ServiceConnection, int);
    method public boolean bindService(@NonNull @RequiresPermission android.content.Intent, int, @NonNull java.util.concurrent.Executor, @NonNull android.content.ServiceConnection);
    method @RequiresPermission(anyOf={"android.permission.INTERACT_ACROSS_USERS", android.Manifest.permission.INTERACT_ACROSS_PROFILES}) public boolean bindServiceAsUser(@NonNull @RequiresPermission android.content.Intent, @NonNull android.content.ServiceConnection, int, @NonNull android.os.UserHandle);
    method @CheckResult(suggest="#enforceCallingOrSelfPermission(String,String)") public abstract int checkCallingOrSelfPermission(@NonNull String);
    method @CheckResult(suggest="#enforceCallingOrSelfUriPermission(Uri,int,String)") public abstract int checkCallingOrSelfUriPermission(android.net.Uri, int);
    method @CheckResult(suggest="#enforceCallingPermission(String,String)") public abstract int checkCallingPermission(@NonNull String);
+0 −1
Original line number Diff line number Diff line
@@ -1671,7 +1671,6 @@ package android.content {
  }
  public abstract class Context {
    method @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS) public boolean bindServiceAsUser(@RequiresPermission android.content.Intent, android.content.ServiceConnection, int, android.os.UserHandle);
    method @NonNull public android.content.Context createContextAsUser(@NonNull android.os.UserHandle, int);
    method public abstract android.content.Context createCredentialProtectedStorageContext();
    method @NonNull public android.content.Context createPackageContextAsUser(@NonNull String, int, @NonNull android.os.UserHandle) throws android.content.pm.PackageManager.NameNotFoundException;
+32 −7
Original line number Diff line number Diff line
@@ -3240,15 +3240,40 @@ public abstract class Context {
    }

    /**
     * Same as {@link #bindService(Intent, ServiceConnection, int)}, but with an explicit userHandle
     * argument for use by system server and other multi-user aware code.
     * @hide
     * Binds to a service in the given {@code user} in the same manner as
     * {@link #bindService(Intent, ServiceConnection, int)}.
     *
     * <p>If the given {@code user} is in the same profile group and the target package is the
     * same as the caller, {@code android.Manifest.permission.INTERACT_ACROSS_PROFILES} is
     * sufficient. Otherwise, requires {@code android.Manifest.permission.INTERACT_ACROSS_USERS}
     * for interacting with other users.
     *
     * @param service Identifies the service to connect to.  The Intent must
     *      specify an explicit component name.
     * @param conn Receives information as the service is started and stopped.
     *      This must be a valid ServiceConnection object; it must not be null.
     * @param flags Operation options for the binding.  May be 0,
     *          {@link #BIND_AUTO_CREATE}, {@link #BIND_DEBUG_UNBIND},
     *          {@link #BIND_NOT_FOREGROUND}, {@link #BIND_ABOVE_CLIENT},
     *          {@link #BIND_ALLOW_OOM_MANAGEMENT}, {@link #BIND_WAIVE_PRIORITY}.
     *          {@link #BIND_IMPORTANT}, or
     *          {@link #BIND_ADJUST_WITH_ACTIVITY}.
     * @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. If this value is {@code true}, you
     *         should later call {@link #unbindService} to release the
     *         connection.
     *
     * @throws SecurityException if the client does not have the required permission to bind.
     */
    @SystemApi
    @SuppressWarnings("unused")
    @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
    public boolean bindServiceAsUser(@RequiresPermission Intent service, ServiceConnection conn,
            int flags, UserHandle user) {
    @RequiresPermission(anyOf = {
            android.Manifest.permission.INTERACT_ACROSS_USERS,
            android.Manifest.permission.INTERACT_ACROSS_PROFILES
    })
    public boolean bindServiceAsUser(
            @NonNull @RequiresPermission Intent service, @NonNull ServiceConnection conn, int flags,
            @NonNull UserHandle user) {
        throw new RuntimeException("Not implemented. Must override in a subclass.");
    }