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

Commit bef6e7a3 authored by Bernardo Rufino's avatar Bernardo Rufino Committed by Automerger Merge Worker
Browse files

Merge "Require proper permission for togglePanel()/handleSystemKey()" into sc-dev am: 6b1896db

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

Change-Id: Ibba7df55a23bffb6ff0a28322f242278c9a0d8cf
parents 5a03acb8 6b1896db
Loading
Loading
Loading
Loading
+2 −0
Original line number Original line Diff line number Diff line
@@ -333,8 +333,10 @@ package android.app {
    method public void clickNotification(@Nullable String, int, int, boolean);
    method public void clickNotification(@Nullable String, int, int, boolean);
    method @RequiresPermission(android.Manifest.permission.STATUS_BAR) public void collapsePanels();
    method @RequiresPermission(android.Manifest.permission.STATUS_BAR) public void collapsePanels();
    method public void expandNotificationsPanel();
    method public void expandNotificationsPanel();
    method @RequiresPermission(android.Manifest.permission.STATUS_BAR) public void handleSystemKey(int);
    method public void sendNotificationFeedback(@Nullable String, @Nullable android.os.Bundle);
    method public void sendNotificationFeedback(@Nullable String, @Nullable android.os.Bundle);
    method @RequiresPermission(android.Manifest.permission.STATUS_BAR) public void setExpansionDisabledForSimNetworkLock(boolean);
    method @RequiresPermission(android.Manifest.permission.STATUS_BAR) public void setExpansionDisabledForSimNetworkLock(boolean);
    method @RequiresPermission(android.Manifest.permission.STATUS_BAR) public void togglePanel();
  }
  }


  public final class SyncNotedAppOp implements android.os.Parcelable {
  public final class SyncNotedAppOp implements android.os.Parcelable {
+36 −0
Original line number Original line Diff line number Diff line
@@ -351,6 +351,42 @@ public class StatusBarManager {
        }
        }
    }
    }


    /**
     * Toggles the notification panel.
     *
     * @hide
     */
    @RequiresPermission(android.Manifest.permission.STATUS_BAR)
    @TestApi
    public void togglePanel() {
        try {
            final IStatusBarService svc = getService();
            if (svc != null) {
                svc.togglePanel();
            }
        } catch (RemoteException ex) {
            throw ex.rethrowFromSystemServer();
        }
    }

    /**
     * Sends system keys to the status bar.
     *
     * @hide
     */
    @RequiresPermission(android.Manifest.permission.STATUS_BAR)
    @TestApi
    public void handleSystemKey(int key) {
        try {
            final IStatusBarService svc = getService();
            if (svc != null) {
                svc.handleSystemKey(key);
            }
        } catch (RemoteException ex) {
            throw ex.rethrowFromSystemServer();
        }
    }

    /**
    /**
     * Expand the settings panel.
     * Expand the settings panel.
     *
     *
+31 −16
Original line number Original line Diff line number Diff line
@@ -671,21 +671,9 @@ public class StatusBarManagerService extends IStatusBarService.Stub implements D


    @Override
    @Override
    public void collapsePanels() {
    public void collapsePanels() {
        int uid = Binder.getCallingUid();
        if (!checkCanCollapseStatusBar("collapsePanels")) {
        int pid = Binder.getCallingPid();
        if (CompatChanges.isChangeEnabled(LOCK_DOWN_COLLAPSE_STATUS_BAR, uid)) {
            enforceStatusBar();
        } else {
            if (mContext.checkPermission(Manifest.permission.STATUS_BAR, pid, uid)
                    != PackageManager.PERMISSION_GRANTED) {
                enforceExpandStatusBar();
                if (!mActivityTaskManager.canCloseSystemDialogs(pid, uid)) {
                    Slog.e(TAG, "Permission Denial: Method collapsePanels() requires permission "
                            + Manifest.permission.STATUS_BAR + ", ignoring call.");
            return;
            return;
        }
        }
            }
        }


        if (mBar != null) {
        if (mBar != null) {
            try {
            try {
@@ -697,7 +685,9 @@ public class StatusBarManagerService extends IStatusBarService.Stub implements D


    @Override
    @Override
    public void togglePanel() {
    public void togglePanel() {
        enforceExpandStatusBar();
        if (!checkCanCollapseStatusBar("togglePanel")) {
            return;
        }


        if (isDisable2FlagSet(DISABLE2_NOTIFICATION_SHADE)) {
        if (isDisable2FlagSet(DISABLE2_NOTIFICATION_SHADE)) {
            return;
            return;
@@ -758,7 +748,9 @@ public class StatusBarManagerService extends IStatusBarService.Stub implements D


    @Override
    @Override
    public void handleSystemKey(int key) throws RemoteException {
    public void handleSystemKey(int key) throws RemoteException {
        enforceExpandStatusBar();
        if (!checkCanCollapseStatusBar("handleSystemKey")) {
            return;
        }


        if (mBar != null) {
        if (mBar != null) {
            try {
            try {
@@ -1201,6 +1193,29 @@ public class StatusBarManagerService extends IStatusBarService.Stub implements D
                "StatusBarManagerService");
                "StatusBarManagerService");
    }
    }


    /**
     *  For targetSdk S+ we require STATUS_BAR. For targetSdk < S, we only require EXPAND_STATUS_BAR
     *  but also require that it falls into one of the allowed use-cases to lock down abuse vector.
     */
    private boolean checkCanCollapseStatusBar(String method) {
        int uid = Binder.getCallingUid();
        int pid = Binder.getCallingUid();
        if (CompatChanges.isChangeEnabled(LOCK_DOWN_COLLAPSE_STATUS_BAR, uid)) {
            enforceStatusBar();
        } else {
            if (mContext.checkPermission(Manifest.permission.STATUS_BAR, pid, uid)
                    != PackageManager.PERMISSION_GRANTED) {
                enforceExpandStatusBar();
                if (!mActivityTaskManager.canCloseSystemDialogs(pid, uid)) {
                    Slog.e(TAG, "Permission Denial: Method " + method + "() requires permission "
                            + Manifest.permission.STATUS_BAR + ", ignoring call.");
                    return false;
                }
            }
        }
        return true;
    }

    // ================================================================================
    // ================================================================================
    // Callbacks from the status bar service.
    // Callbacks from the status bar service.
    // ================================================================================
    // ================================================================================