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

Commit 77069b95 authored by Amith Yamasani's avatar Amith Yamasani Committed by android-build-merger
Browse files

Merge "Allow Shell to change component enabled state" into nyc-dev am: 19b34ecc

am: 0250ae2c

* commit '0250ae2c':
  Allow Shell to change component enabled state

Change-Id: I2a29c8e15ba81a9aa5c3950c8aeccd3d4ff662cc
parents cde1df92 0250ae2c
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -111,6 +111,7 @@
    <uses-permission android:name="android.permission.VIBRATE" />
    <uses-permission android:name="android.permission.MANAGE_ACTIVITY_STACKS" />
    <uses-permission android:name="android.permission.CONNECTIVITY_INTERNAL" />
    <uses-permission android:name="android.permission.CHANGE_COMPONENT_ENABLED_STATE" />
    <!-- Permission needed to rename bugreport notifications (so they're not shown as Shell) -->
    <uses-permission android:name="android.permission.SUBSTITUTE_NOTIFICATION_APP_NAME" />

+27 −0
Original line number Diff line number Diff line
@@ -17509,6 +17509,14 @@ Slog.v(TAG, ":: stepped forward, applying functor at tag " + parser.getName());
                throw new IllegalArgumentException(
                        "Unknown component: " + packageName + "/" + className);
            }
            // Don't allow other apps to disable an active profile owner
            if (!UserHandle.isSameApp(uid, pkgSetting.appId)) {
                final DevicePolicyManagerInternal dpmi = LocalServices
                        .getService(DevicePolicyManagerInternal.class);
                if (dpmi != null && dpmi.hasDeviceOwnerOrProfileOwner(packageName, userId)) {
                    throw new SecurityException("Cannot disable a device owner or a profile owner");
                }
            }
            // Allow root and verify that userId is not being specified by a different user
            if (!allowedByPermission && !UserHandle.isSameApp(uid, pkgSetting.appId)) {
                throw new SecurityException(
@@ -17516,6 +17524,25 @@ Slog.v(TAG, ":: stepped forward, applying functor at tag " + parser.getName());
                        + Binder.getCallingPid()
                        + ", uid=" + uid + ", package uid=" + pkgSetting.appId);
            }
            if (uid == Process.SHELL_UID) {
                // Shell can only change whole packages between ENABLED and DISABLED_USER states
                int oldState = pkgSetting.getEnabled(userId);
                if (className == null
                    &&
                    (oldState == COMPONENT_ENABLED_STATE_DISABLED_USER
                     || oldState == COMPONENT_ENABLED_STATE_DEFAULT
                     || oldState == COMPONENT_ENABLED_STATE_ENABLED)
                    &&
                    (newState == COMPONENT_ENABLED_STATE_DISABLED_USER
                     || newState == COMPONENT_ENABLED_STATE_DEFAULT
                     || newState == COMPONENT_ENABLED_STATE_ENABLED)) {
                    // ok
                } else {
                    throw new SecurityException(
                            "Shell cannot change component state for " + packageName + "/"
                            + className + " to " + newState);
                }
            }
            if (className == null) {
                // We're dealing with an application/package level state change
                if (pkgSetting.getEnabled(userId) == newState) {