Merge "Add ActivityOption to remove keyguard when an activity is launched." into tm-d1-dev

This commit is contained in:
Issei Suzuki
2022-05-20 07:29:31 +00:00
committed by Android (Google) Code Review
5 changed files with 37 additions and 24 deletions

View File

@@ -16,6 +16,7 @@
package android.app; package android.app;
import static android.Manifest.permission.CONTROL_KEYGUARD;
import static android.Manifest.permission.CONTROL_REMOTE_APP_TRANSITION_ANIMATIONS; import static android.Manifest.permission.CONTROL_REMOTE_APP_TRANSITION_ANIMATIONS;
import static android.Manifest.permission.START_TASKS_FROM_RECENTS; import static android.Manifest.permission.START_TASKS_FROM_RECENTS;
import static android.app.WindowConfiguration.ACTIVITY_TYPE_UNDEFINED; import static android.app.WindowConfiguration.ACTIVITY_TYPE_UNDEFINED;
@@ -362,9 +363,8 @@ public class ActivityOptions extends ComponentOptions {
private static final String KEY_LAUNCH_INTO_PIP_PARAMS = private static final String KEY_LAUNCH_INTO_PIP_PARAMS =
"android.activity.launchIntoPipParams"; "android.activity.launchIntoPipParams";
/** See {@link #setDismissKeyguardIfInsecure()}. */ /** See {@link #setDismissKeyguard()}. */
private static final String KEY_DISMISS_KEYGUARD_IF_INSECURE = private static final String KEY_DISMISS_KEYGUARD = "android.activity.dismissKeyguard";
"android.activity.dismissKeyguardIfInsecure";
private static final String KEY_IGNORE_PENDING_INTENT_CREATOR_FOREGROUND_STATE = private static final String KEY_IGNORE_PENDING_INTENT_CREATOR_FOREGROUND_STATE =
"android.activity.ignorePendingIntentCreatorForegroundState"; "android.activity.ignorePendingIntentCreatorForegroundState";
@@ -465,7 +465,7 @@ public class ActivityOptions extends ComponentOptions {
private boolean mLaunchedFromBubble; private boolean mLaunchedFromBubble;
private boolean mTransientLaunch; private boolean mTransientLaunch;
private PictureInPictureParams mLaunchIntoPipParams; private PictureInPictureParams mLaunchIntoPipParams;
private boolean mDismissKeyguardIfInsecure; private boolean mDismissKeyguard;
private boolean mIgnorePendingIntentCreatorForegroundState; private boolean mIgnorePendingIntentCreatorForegroundState;
/** /**
@@ -1270,7 +1270,7 @@ public class ActivityOptions extends ComponentOptions {
mLaunchIntoPipParams = opts.getParcelable(KEY_LAUNCH_INTO_PIP_PARAMS); mLaunchIntoPipParams = opts.getParcelable(KEY_LAUNCH_INTO_PIP_PARAMS);
mIsEligibleForLegacyPermissionPrompt = mIsEligibleForLegacyPermissionPrompt =
opts.getBoolean(KEY_LEGACY_PERMISSION_PROMPT_ELIGIBLE); opts.getBoolean(KEY_LEGACY_PERMISSION_PROMPT_ELIGIBLE);
mDismissKeyguardIfInsecure = opts.getBoolean(KEY_DISMISS_KEYGUARD_IF_INSECURE); mDismissKeyguard = opts.getBoolean(KEY_DISMISS_KEYGUARD);
mIgnorePendingIntentCreatorForegroundState = opts.getBoolean( mIgnorePendingIntentCreatorForegroundState = opts.getBoolean(
KEY_IGNORE_PENDING_INTENT_CREATOR_FOREGROUND_STATE); KEY_IGNORE_PENDING_INTENT_CREATOR_FOREGROUND_STATE);
} }
@@ -1869,24 +1869,24 @@ public class ActivityOptions extends ComponentOptions {
} }
/** /**
* Sets whether the insecure keyguard should go away when this activity launches. In case the * Sets whether the keyguard should go away when this activity launches.
* keyguard is secure, this option will be ignored.
* *
* @see Activity#setShowWhenLocked(boolean) * @see Activity#setShowWhenLocked(boolean)
* @see android.R.attr#showWhenLocked * @see android.R.attr#showWhenLocked
* @hide * @hide
*/ */
public void setDismissKeyguardIfInsecure() { @RequiresPermission(CONTROL_KEYGUARD)
mDismissKeyguardIfInsecure = true; public void setDismissKeyguard() {
mDismissKeyguard = true;
} }
/** /**
* @see #setDismissKeyguardIfInsecure() * @see #setDismissKeyguard()
* @return whether the insecure keyguard should go away when the activity launches. * @return whether the insecure keyguard should go away when the activity launches.
* @hide * @hide
*/ */
public boolean getDismissKeyguardIfInsecure() { public boolean getDismissKeyguard() {
return mDismissKeyguardIfInsecure; return mDismissKeyguard;
} }
/** /**
@@ -2167,8 +2167,8 @@ public class ActivityOptions extends ComponentOptions {
b.putBoolean(KEY_LEGACY_PERMISSION_PROMPT_ELIGIBLE, b.putBoolean(KEY_LEGACY_PERMISSION_PROMPT_ELIGIBLE,
mIsEligibleForLegacyPermissionPrompt); mIsEligibleForLegacyPermissionPrompt);
} }
if (mDismissKeyguardIfInsecure) { if (mDismissKeyguard) {
b.putBoolean(KEY_DISMISS_KEYGUARD_IF_INSECURE, mDismissKeyguardIfInsecure); b.putBoolean(KEY_DISMISS_KEYGUARD, mDismissKeyguard);
} }
if (mIgnorePendingIntentCreatorForegroundState) { if (mIgnorePendingIntentCreatorForegroundState) {
b.putBoolean(KEY_IGNORE_PENDING_INTENT_CREATOR_FOREGROUND_STATE, b.putBoolean(KEY_IGNORE_PENDING_INTENT_CREATOR_FOREGROUND_STATE,

View File

@@ -183,7 +183,7 @@ final class ActivityManagerShellCommand extends ShellCommand {
private boolean mAsync; private boolean mAsync;
private BroadcastOptions mBroadcastOptions; private BroadcastOptions mBroadcastOptions;
private boolean mShowSplashScreen; private boolean mShowSplashScreen;
private boolean mDismissKeyguardIfInsecure; private boolean mDismissKeyguard;
final boolean mDumping; final boolean mDumping;
@@ -442,8 +442,8 @@ final class ActivityManagerShellCommand extends ShellCommand {
mAsync = true; mAsync = true;
} else if (opt.equals("--splashscreen-show-icon")) { } else if (opt.equals("--splashscreen-show-icon")) {
mShowSplashScreen = true; mShowSplashScreen = true;
} else if (opt.equals("--dismiss-keyguard-if-insecure")) { } else if (opt.equals("--dismiss-keyguard")) {
mDismissKeyguardIfInsecure = true; mDismissKeyguard = true;
} else { } else {
return false; return false;
} }
@@ -588,11 +588,11 @@ final class ActivityManagerShellCommand extends ShellCommand {
} }
options.setSplashScreenStyle(SplashScreen.SPLASH_SCREEN_STYLE_ICON); options.setSplashScreenStyle(SplashScreen.SPLASH_SCREEN_STYLE_ICON);
} }
if (mDismissKeyguardIfInsecure) { if (mDismissKeyguard) {
if (options == null) { if (options == null) {
options = ActivityOptions.makeBasic(); options = ActivityOptions.makeBasic();
} }
options.setDismissKeyguardIfInsecure(); options.setDismissKeyguard();
} }
if (mWaitOption) { if (mWaitOption) {
result = mInternal.startActivityAndWait(null, SHELL_PACKAGE_NAME, null, intent, result = mInternal.startActivityAndWait(null, SHELL_PACKAGE_NAME, null, intent,

View File

@@ -873,7 +873,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
boolean mEnteringAnimation; boolean mEnteringAnimation;
boolean mOverrideTaskTransition; boolean mOverrideTaskTransition;
boolean mDismissKeyguardIfInsecure; boolean mDismissKeyguard;
boolean mAppStopped; boolean mAppStopped;
// A hint to override the window specified rotation animation, or -1 to use the window specified // A hint to override the window specified rotation animation, or -1 to use the window specified
@@ -1992,7 +1992,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
} }
mOverrideTaskTransition = options.getOverrideTaskTransition(); mOverrideTaskTransition = options.getOverrideTaskTransition();
mDismissKeyguardIfInsecure = options.getDismissKeyguardIfInsecure(); mDismissKeyguard = options.getDismissKeyguard();
} }
ColorDisplayService.ColorDisplayServiceInternal cds = LocalServices.getService( ColorDisplayService.ColorDisplayServiceInternal cds = LocalServices.getService(

View File

@@ -589,9 +589,7 @@ class KeyguardController {
mTopTurnScreenOnActivity = top; mTopTurnScreenOnActivity = top;
} }
final boolean isKeyguardSecure = controller.mWindowManager.isKeyguardSecure( if (top.mDismissKeyguard && mKeyguardShowing) {
controller.mService.getCurrentUserId());
if (top.mDismissKeyguardIfInsecure && mKeyguardShowing && !isKeyguardSecure) {
mKeyguardGoingAway = true; mKeyguardGoingAway = true;
} else if (top.canShowWhenLocked()) { } else if (top.canShowWhenLocked()) {
mTopOccludesActivity = top; mTopOccludesActivity = top;

View File

@@ -16,6 +16,7 @@
package com.android.server.wm; package com.android.server.wm;
import static android.Manifest.permission.CONTROL_KEYGUARD;
import static android.Manifest.permission.CONTROL_REMOTE_APP_TRANSITION_ANIMATIONS; import static android.Manifest.permission.CONTROL_REMOTE_APP_TRANSITION_ANIMATIONS;
import static android.Manifest.permission.START_TASKS_FROM_RECENTS; import static android.Manifest.permission.START_TASKS_FROM_RECENTS;
import static android.Manifest.permission.STATUS_BAR_SERVICE; import static android.Manifest.permission.STATUS_BAR_SERVICE;
@@ -297,6 +298,20 @@ public class SafeActivityOptions {
} }
} }
// Check if the caller is allowed to dismiss keyguard.
final boolean dismissKeyguard = options.getDismissKeyguard();
if (aInfo != null && dismissKeyguard) {
final int controlKeyguardPerm = ActivityTaskManagerService.checkPermission(
CONTROL_KEYGUARD, callingPid, callingUid);
if (controlKeyguardPerm != PERMISSION_GRANTED) {
final String msg = "Permission Denial: starting " + getIntentString(intent)
+ " from " + callerApp + " (pid=" + callingPid
+ ", uid=" + callingUid + ") with dismissKeyguard=true";
Slog.w(TAG, msg);
throw new SecurityException(msg);
}
}
// Check permission for remote animations // Check permission for remote animations
final RemoteAnimationAdapter adapter = options.getRemoteAnimationAdapter(); final RemoteAnimationAdapter adapter = options.getRemoteAnimationAdapter();
if (adapter != null && supervisor.mService.checkPermission( if (adapter != null && supervisor.mService.checkPermission(