Merge "Restrict StatusBarManager.collapsePanels() for targetSdk < S"

This commit is contained in:
Bernardo Rufino
2021-01-13 14:15:44 +00:00
committed by Android (Google) Code Review
3 changed files with 33 additions and 2 deletions

View File

@@ -19,6 +19,7 @@ package com.android.server.statusbar;
import static android.app.StatusBarManager.DISABLE2_GLOBAL_ACTIONS;
import static android.view.Display.DEFAULT_DISPLAY;
import android.Manifest;
import android.annotation.Nullable;
import android.app.ActivityThread;
import android.app.ITransientNotificationCallback;
@@ -29,6 +30,7 @@ import android.compat.annotation.ChangeId;
import android.compat.annotation.EnabledSince;
import android.content.ComponentName;
import android.content.Context;
import android.content.pm.PackageManager;
import android.hardware.biometrics.IBiometricSysuiReceiver;
import android.hardware.biometrics.PromptInfo;
import android.hardware.display.DisplayManager;
@@ -74,6 +76,7 @@ import com.android.server.notification.NotificationDelegate;
import com.android.server.policy.GlobalActionsProvider;
import com.android.server.power.ShutdownCheckPoints;
import com.android.server.power.ShutdownThread;
import com.android.server.wm.ActivityTaskManagerInternal;
import java.io.FileDescriptor;
import java.io.PrintWriter;
@@ -113,6 +116,7 @@ public class StatusBarManagerService extends IStatusBarService.Stub implements D
private final Object mLock = new Object();
private final DeathRecipient mDeathRecipient = new DeathRecipient();
private final ActivityTaskManagerInternal mActivityTaskManager;
private int mCurrentUserId;
private boolean mTracingEnabled;
@@ -213,6 +217,7 @@ public class StatusBarManagerService extends IStatusBarService.Stub implements D
final DisplayManager displayManager =
(DisplayManager) context.getSystemService(Context.DISPLAY_SERVICE);
displayManager.registerDisplayListener(this, mHandler);
mActivityTaskManager = LocalServices.getService(ActivityTaskManagerInternal.class);
}
@Override
@@ -620,10 +625,20 @@ public class StatusBarManagerService extends IStatusBarService.Stub implements D
@Override
public void collapsePanels() {
if (CompatChanges.isChangeEnabled(LOCK_DOWN_COLLAPSE_STATUS_BAR, Binder.getCallingUid())) {
int uid = Binder.getCallingUid();
int pid = Binder.getCallingPid();
if (CompatChanges.isChangeEnabled(LOCK_DOWN_COLLAPSE_STATUS_BAR, uid)) {
enforceStatusBar();
} else {
enforceExpandStatusBar();
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;
}
}
}
if (mBar != null) {

View File

@@ -292,6 +292,11 @@ public abstract class ActivityTaskManagerInternal {
public abstract boolean checkCanCloseSystemDialogs(int pid, int uid,
@Nullable String packageName);
/**
* Returns whether the app can close system dialogs or not.
*/
public abstract boolean canCloseSystemDialogs(int pid, int uid);
/**
* Called after the voice interaction service has changed.
*/

View File

@@ -2958,6 +2958,11 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
== PERMISSION_GRANTED) {
return true;
}
if (process == null) {
synchronized (mGlobalLock) {
process = mProcessMap.getProcess(pid);
}
}
if (process != null) {
// Check if the instrumentation of the process has the permission. This covers the
// usual test started from the shell (which has the permission) case. This is needed
@@ -5236,6 +5241,12 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
packageName);
}
@Override
public boolean canCloseSystemDialogs(int pid, int uid) {
return ActivityTaskManagerService.this.canCloseSystemDialogs(pid, uid,
null /* process */);
}
@Override
public void notifyActiveVoiceInteractionServiceChanged(ComponentName component) {
synchronized (mGlobalLock) {