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

Commit a1434293 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

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

parents a807683a f31443e2
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;
@@ -409,6 +410,7 @@ public class CompanionDeviceManagerService extends SystemService implements Bind
            checkCallerIsSystemOr(callingPackage);
            int userId = getCallingUserId();
            checkUsesFeature(callingPackage, userId);
            checkProfilePermissions(request);

            mFindDeviceCallback = callback;
            mRequest = request;
@@ -519,6 +521,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 {