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

Commit 6a34e567 authored by Jeff Sharkey's avatar Jeff Sharkey
Browse files

Relax protected broadcast checks for shell.

On userdebug/eng devices, the shell can run as non-shell UIDs, so
define a flag to identify broadcasts coming from the shell, and
don't yell if they're non-protected.

Test: builds, boots, root shell can send broadcasts
Bug: 32369665
Change-Id: I5f55930ee434cb8318c86aaf05eba3c59a326694
parent d0abcbeb
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -8701,6 +8701,7 @@ package android.content {
    method public void readFromParcel(android.os.Parcel);
    method public void removeCategory(java.lang.String);
    method public void removeExtra(java.lang.String);
    method public void removeFlags(int);
    method public android.content.Intent replaceExtras(android.content.Intent);
    method public android.content.Intent replaceExtras(android.os.Bundle);
    method public android.content.ComponentName resolveActivity(android.content.pm.PackageManager);
+1 −0
Original line number Diff line number Diff line
@@ -9058,6 +9058,7 @@ package android.content {
    method public void readFromParcel(android.os.Parcel);
    method public void removeCategory(java.lang.String);
    method public void removeExtra(java.lang.String);
    method public void removeFlags(int);
    method public android.content.Intent replaceExtras(android.content.Intent);
    method public android.content.Intent replaceExtras(android.os.Bundle);
    method public android.content.ComponentName resolveActivity(android.content.pm.PackageManager);
+1 −0
Original line number Diff line number Diff line
@@ -8726,6 +8726,7 @@ package android.content {
    method public void readFromParcel(android.os.Parcel);
    method public void removeCategory(java.lang.String);
    method public void removeExtra(java.lang.String);
    method public void removeFlags(int);
    method public android.content.Intent replaceExtras(android.content.Intent);
    method public android.content.Intent replaceExtras(android.os.Bundle);
    method public android.content.ComponentName resolveActivity(android.content.pm.PackageManager);
+22 −7
Original line number Diff line number Diff line
@@ -4785,6 +4785,11 @@ public class Intent implements Parcelable, Cloneable {
     * @hide
     */
    public static final int FLAG_RECEIVER_EXCLUDE_BACKGROUND = 0x00800000;
    /**
     * If set, this broadcast is being sent from the shell.
     * @hide
     */
    public static final int FLAG_RECEIVER_FROM_SHELL = 0x00400000;

    /**
     * @hide Flags that can't be changed with PendingIntent.
@@ -7969,6 +7974,7 @@ public class Intent implements Parcelable, Cloneable {
     *
     * @see #getFlags
     * @see #addFlags
     * @see #removeFlags
     *
     * @see #FLAG_GRANT_READ_URI_PERMISSION
     * @see #FLAG_GRANT_WRITE_URI_PERMISSION
@@ -8002,21 +8008,30 @@ public class Intent implements Parcelable, Cloneable {
    }

    /**
     * Add additional flags to the intent (or with existing flags
     * value).
     * Add additional flags to the intent (or with existing flags value).
     *
     * @param flags The new flags to set.
     *
     * @return Returns the same Intent object, for chaining multiple calls
     * into a single statement.
     *
     * @see #setFlags
     * @return Returns the same Intent object, for chaining multiple calls into
     *         a single statement.
     * @see #setFlags(int)
     * @see #removeFlags(int)
     */
    public Intent addFlags(int flags) {
        mFlags |= flags;
        return this;
    }

    /**
     * Remove these flags from the intent.
     *
     * @param flags The flags to remove.
     * @see #setFlags(int)
     * @see #addFlags(int)
     */
    public void removeFlags(int flags) {
        mFlags &= ~flags;
    }

    /**
     * (Usually optional) Set an explicit application package name that limits
     * the components this Intent will resolve to.  If left to the default
+18 −1
Original line number Diff line number Diff line
@@ -17947,7 +17947,11 @@ public class ActivityManagerService extends IActivityManager.Stub
            case Process.PHONE_UID:
            case Process.BLUETOOTH_UID:
            case Process.NFC_UID:
                if ((intent.getFlags() & Intent.FLAG_RECEIVER_FROM_SHELL) != 0) {
                    isCallerSystem = false;
                } else {
                    isCallerSystem = true;
                }
                break;
            default:
                isCallerSystem = (callerApp != null) && callerApp.persistent;
@@ -18520,6 +18524,19 @@ public class ActivityManagerService extends IActivityManager.Stub
                    "Can't use FLAG_RECEIVER_BOOT_UPGRADE here");
        }
        if ((flags & Intent.FLAG_RECEIVER_FROM_SHELL) != 0) {
            switch (Binder.getCallingUid()) {
                case Process.ROOT_UID:
                case Process.SHELL_UID:
                    break;
                default:
                    Slog.w(TAG, "Removing FLAG_RECEIVER_FROM_SHELL because caller is UID "
                            + Binder.getCallingUid());
                    intent.removeFlags(Intent.FLAG_RECEIVER_FROM_SHELL);
                    break;
            }
        }
        return intent;
    }
Loading