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

Commit 420d58d7 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Guard CDM watch profile behind its permission" into sc-dev am: a1434293

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/13775536

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: Ic10224c147b7731e4b0ec7bec72394d7c61204fa
parents 8f8c8d6b a1434293
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -64,10 +64,12 @@ public final class AssociationRequest implements Parcelable {
     * set up is a specific kind of device, and some extra permissions may be granted to the app
     * as a result.
     *
     * Using it requires declaring uses-permission
     * {@link android.Manifest.permission#REQUEST_COMPANION_PROFILE_WATCH} in the manifest.
     *
     * @see AssociationRequest.Builder#setDeviceProfile
     */
    public static final String DEVICE_PROFILE_WATCH =
            "android.app.role.COMPANION_DEVICE_WATCH";
    public static final String DEVICE_PROFILE_WATCH = "android.app.role.COMPANION_DEVICE_WATCH";

    /** @hide */
    @StringDef(value = { DEVICE_PROFILE_WATCH })
+17 −0
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@ import static com.android.internal.util.function.pooled.PooledLambda.obtainRunna
import static java.util.Objects.requireNonNull;
import static java.util.concurrent.TimeUnit.MINUTES;

import android.Manifest;
import android.annotation.CheckResult;
import android.annotation.NonNull;
import android.annotation.Nullable;
@@ -417,6 +418,7 @@ public class CompanionDeviceManagerService extends SystemService implements Bind
            checkCallerIsSystemOr(callingPackage);
            int userId = getCallingUserId();
            checkUsesFeature(callingPackage, userId);
            checkProfilePermissions(request);

            mFindDeviceCallback = callback;
            mRequest = request;
@@ -527,6 +529,21 @@ public class CompanionDeviceManagerService extends SystemService implements Bind
            }
        }

        private void checkProfilePermissions(AssociationRequest request) {
            checkProfilePermission(request,
                    AssociationRequest.DEVICE_PROFILE_WATCH,
                    Manifest.permission.REQUEST_COMPANION_PROFILE_WATCH);
        }

        private void checkProfilePermission(
                AssociationRequest request, String profile, String permission) {
            if (profile.equals(request.getDeviceProfile())
                    && getContext().checkCallingOrSelfPermission(permission)
                            != PackageManager.PERMISSION_GRANTED) {
                throw new SecurityException("Using " + profile + " requires " + permission);
            }
        }

        @Override
        public PendingIntent requestNotificationAccess(ComponentName component)
                throws RemoteException {