diff options
| author | TreeHugger Robot <treehugger-gerrit@google.com> | 2021-10-19 09:40:52 +0000 |
|---|---|---|
| committer | Android (Google) Code Review <android-gerrit@google.com> | 2021-10-19 09:40:52 +0000 |
| commit | 3145f6bb100d75f78ef751f1a91f93e268fd56a7 (patch) | |
| tree | ccbb74a29eb107a2fedc3e047e5d958306a61f0a /core/java | |
| parent | 93ef99202a844f68cdecff77f85c3099d7d3a5e4 (diff) | |
| parent | 2cea1518db25098d9ba29f2ee10720b62d003a2f (diff) | |
Merge "Revert "Merge BroadcastOptions and ActivityOptions PendingIntent...""
Diffstat (limited to 'core/java')
| -rw-r--r-- | core/java/android/app/ActivityOptions.java | 46 | ||||
| -rw-r--r-- | core/java/android/app/BroadcastOptions.java | 42 | ||||
| -rw-r--r-- | core/java/android/app/ComponentOptions.java | 76 |
3 files changed, 78 insertions, 86 deletions
diff --git a/core/java/android/app/ActivityOptions.java b/core/java/android/app/ActivityOptions.java index c1b94787de24..860224cc7256 100644 --- a/core/java/android/app/ActivityOptions.java +++ b/core/java/android/app/ActivityOptions.java @@ -69,7 +69,7 @@ import java.util.ArrayList; * {@link android.content.Context#startActivity(android.content.Intent, android.os.Bundle) * Context.startActivity(Intent, Bundle)} and related methods. */ -public class ActivityOptions extends ComponentOptions { +public class ActivityOptions { private static final String TAG = "ActivityOptions"; /** @@ -168,6 +168,14 @@ public class ActivityOptions extends ComponentOptions { public static final String KEY_SPLASH_SCREEN_THEME = "android.activity.splashScreenTheme"; /** + * PendingIntent caller allows activity start even if PendingIntent creator is in background. + * This only works if the PendingIntent caller is allowed to start background activities, + * for example if it's in the foreground, or has BAL permission. + * @hide + */ + public static final String KEY_PENDING_INTENT_BACKGROUND_ACTIVITY_ALLOWED = + "android.pendingIntent.backgroundActivityAllowed"; + /** * Callback for when the last frame of the animation is played. * @hide */ @@ -381,6 +389,12 @@ public class ActivityOptions extends ComponentOptions { /** @hide */ public static final int ANIM_REMOTE_ANIMATION = 13; + /** + * Default value for KEY_PENDING_INTENT_BACKGROUND_ACTIVITY_ALLOWED. + * @hide + **/ + public static final boolean PENDING_INTENT_BAL_ALLOWED_DEFAULT = true; + private String mPackageName; private Rect mLaunchBounds; private int mAnimationType = ANIM_UNDEFINED; @@ -432,6 +446,7 @@ public class ActivityOptions extends ComponentOptions { private String mSplashScreenThemeResName; @SplashScreen.SplashScreenStyle private int mSplashScreenStyle; + private boolean mPendingIntentBalAllowed = PENDING_INTENT_BAL_ALLOWED_DEFAULT; private boolean mRemoveWithTaskOrganizer; private boolean mLaunchedFromBubble; private boolean mTransientLaunch; @@ -1081,12 +1096,13 @@ public class ActivityOptions extends ComponentOptions { } private ActivityOptions() { - super(); } /** @hide */ public ActivityOptions(Bundle opts) { - super(opts); + // If the remote side sent us bad parcelables, they won't get the + // results they want, which is their loss. + opts.setDefusable(true); mPackageName = opts.getString(KEY_PACKAGE_NAME); try { @@ -1184,6 +1200,8 @@ public class ActivityOptions extends ComponentOptions { mRemoteTransition = opts.getParcelable(KEY_REMOTE_TRANSITION); mOverrideTaskTransition = opts.getBoolean(KEY_OVERRIDE_TASK_TRANSITION); mSplashScreenThemeResName = opts.getString(KEY_SPLASH_SCREEN_THEME); + mPendingIntentBalAllowed = opts.getBoolean(KEY_PENDING_INTENT_BACKGROUND_ACTIVITY_ALLOWED, + PENDING_INTENT_BAL_ALLOWED_DEFAULT); mRemoveWithTaskOrganizer = opts.getBoolean(KEY_REMOVE_WITH_TASK_ORGANIZER); mLaunchedFromBubble = opts.getBoolean(KEY_LAUNCHED_FROM_BUBBLE); mTransientLaunch = opts.getBoolean(KEY_TRANSIENT_LAUNCH); @@ -1408,6 +1426,24 @@ public class ActivityOptions extends ComponentOptions { } /** + * Set PendingIntent activity is allowed to be started in the background if the caller + * can start background activities. + * @hide + */ + public void setPendingIntentBackgroundActivityLaunchAllowed(boolean allowed) { + mPendingIntentBalAllowed = allowed; + } + + /** + * Get PendingIntent activity is allowed to be started in the background if the caller + * can start background activities. + * @hide + */ + public boolean isPendingIntentBackgroundActivityLaunchAllowed() { + return mPendingIntentBalAllowed; + } + + /** * Sets whether the activity is to be launched into LockTask mode. * * Use this option to start an activity in LockTask mode. Note that only apps permitted by @@ -1832,9 +1868,8 @@ public class ActivityOptions extends ComponentOptions { * object; you must not modify it, but can supply it to the startActivity * methods that take an options Bundle. */ - @Override public Bundle toBundle() { - Bundle b = super.toBundle(); + Bundle b = new Bundle(); if (mPackageName != null) { b.putString(KEY_PACKAGE_NAME, mPackageName); } @@ -1981,6 +2016,7 @@ public class ActivityOptions extends ComponentOptions { if (mSplashScreenThemeResName != null && !mSplashScreenThemeResName.isEmpty()) { b.putString(KEY_SPLASH_SCREEN_THEME, mSplashScreenThemeResName); } + b.putBoolean(KEY_PENDING_INTENT_BACKGROUND_ACTIVITY_ALLOWED, mPendingIntentBalAllowed); if (mRemoveWithTaskOrganizer) { b.putBoolean(KEY_REMOVE_WITH_TASK_ORGANIZER, mRemoveWithTaskOrganizer); } diff --git a/core/java/android/app/BroadcastOptions.java b/core/java/android/app/BroadcastOptions.java index 4ca3beb39a46..4e19abfa0d5b 100644 --- a/core/java/android/app/BroadcastOptions.java +++ b/core/java/android/app/BroadcastOptions.java @@ -34,7 +34,7 @@ import android.os.PowerExemptionManager.TempAllowListType; * {@hide} */ @SystemApi -public class BroadcastOptions extends ComponentOptions { +public class BroadcastOptions { private long mTemporaryAppAllowlistDuration; private @TempAllowListType int mTemporaryAppAllowlistType; private @ReasonCode int mTemporaryAppAllowlistReasonCode; @@ -43,6 +43,7 @@ public class BroadcastOptions extends ComponentOptions { private int mMaxManifestReceiverApiLevel = Build.VERSION_CODES.CUR_DEVELOPMENT; private boolean mDontSendToRestrictedApps = false; private boolean mAllowBackgroundActivityStarts; + private boolean mPendingIntentBalAllowed = ActivityOptions.PENDING_INTENT_BAL_ALLOWED_DEFAULT; /** * How long to temporarily put an app on the power allowlist when executing this broadcast @@ -79,6 +80,16 @@ public class BroadcastOptions extends ComponentOptions { "android:broadcast.dontSendToRestrictedApps"; /** + * PendingIntent caller allows activity start even if PendingIntent creator is in background. + * This only works if the PendingIntent caller is allowed to start background activities, + * for example if it's in the foreground, or has BAL permission. + * TODO: Merge it with ActivityOptions. + * @hide + */ + public static final String KEY_PENDING_INTENT_BACKGROUND_ACTIVITY_ALLOWED = + "android.pendingIntent.backgroundActivityAllowed"; + + /** * Corresponds to {@link #setBackgroundActivityStartsAllowed}. */ private static final String KEY_ALLOW_BACKGROUND_ACTIVITY_STARTS = @@ -108,14 +119,12 @@ public class BroadcastOptions extends ComponentOptions { } private BroadcastOptions() { - super(); resetTemporaryAppAllowlist(); } /** @hide */ @TestApi public BroadcastOptions(@NonNull Bundle opts) { - super(opts); // Match the logic in toBundle(). if (opts.containsKey(KEY_TEMPORARY_APP_ALLOWLIST_DURATION)) { mTemporaryAppAllowlistDuration = opts.getLong(KEY_TEMPORARY_APP_ALLOWLIST_DURATION); @@ -132,6 +141,8 @@ public class BroadcastOptions extends ComponentOptions { mDontSendToRestrictedApps = opts.getBoolean(KEY_DONT_SEND_TO_RESTRICTED_APPS, false); mAllowBackgroundActivityStarts = opts.getBoolean(KEY_ALLOW_BACKGROUND_ACTIVITY_STARTS, false); + mPendingIntentBalAllowed = opts.getBoolean(KEY_PENDING_INTENT_BACKGROUND_ACTIVITY_ALLOWED, + ActivityOptions.PENDING_INTENT_BAL_ALLOWED_DEFAULT); } /** @@ -303,6 +314,26 @@ public class BroadcastOptions extends ComponentOptions { } /** + * Set PendingIntent activity is allowed to be started in the background if the caller + * can start background activities. + * TODO: Merge it with ActivityOptions. + * @hide + */ + public void setPendingIntentBackgroundActivityLaunchAllowed(boolean allowed) { + mPendingIntentBalAllowed = allowed; + } + + /** + * Get PendingIntent activity is allowed to be started in the background if the caller + * can start background activities. + * TODO: Merge it with ActivityOptions. + * @hide + */ + public boolean isPendingIntentBackgroundActivityLaunchAllowed() { + return mPendingIntentBalAllowed; + } + + /** * Returns the created options as a Bundle, which can be passed to * {@link android.content.Context#sendBroadcast(android.content.Intent) * Context.sendBroadcast(Intent)} and related methods. @@ -310,9 +341,8 @@ public class BroadcastOptions extends ComponentOptions { * object; you must not modify it, but can supply it to the sendBroadcast * methods that take an options Bundle. */ - @Override public Bundle toBundle() { - Bundle b = super.toBundle(); + Bundle b = new Bundle(); if (isTemporaryAppAllowlistSet()) { b.putLong(KEY_TEMPORARY_APP_ALLOWLIST_DURATION, mTemporaryAppAllowlistDuration); b.putInt(KEY_TEMPORARY_APP_ALLOWLIST_TYPE, mTemporaryAppAllowlistType); @@ -331,6 +361,8 @@ public class BroadcastOptions extends ComponentOptions { if (mAllowBackgroundActivityStarts) { b.putBoolean(KEY_ALLOW_BACKGROUND_ACTIVITY_STARTS, true); } + // TODO: Add API for BroadcastOptions and have a shared base class with ActivityOptions. + b.putBoolean(KEY_PENDING_INTENT_BACKGROUND_ACTIVITY_ALLOWED, mPendingIntentBalAllowed); return b.isEmpty() ? null : b; } } diff --git a/core/java/android/app/ComponentOptions.java b/core/java/android/app/ComponentOptions.java deleted file mode 100644 index d50a73a1f4c2..000000000000 --- a/core/java/android/app/ComponentOptions.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright (C) 2021 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package android.app; - -import android.os.Bundle; - -/** - * @hide - */ -public class ComponentOptions { - - /** - * Default value for KEY_PENDING_INTENT_BACKGROUND_ACTIVITY_ALLOWED. - * @hide - **/ - public static final boolean PENDING_INTENT_BAL_ALLOWED_DEFAULT = true; - - /** - * PendingIntent caller allows activity start even if PendingIntent creator is in background. - * This only works if the PendingIntent caller is allowed to start background activities, - * for example if it's in the foreground, or has BAL permission. - * @hide - */ - public static final String KEY_PENDING_INTENT_BACKGROUND_ACTIVITY_ALLOWED = - "android.pendingIntent.backgroundActivityAllowed"; - - private boolean mPendingIntentBalAllowed = PENDING_INTENT_BAL_ALLOWED_DEFAULT; - - ComponentOptions() { - } - - ComponentOptions(Bundle opts) { - // If the remote side sent us bad parcelables, they won't get the - // results they want, which is their loss. - opts.setDefusable(true); - setPendingIntentBackgroundActivityLaunchAllowed( - opts.getBoolean(KEY_PENDING_INTENT_BACKGROUND_ACTIVITY_ALLOWED, - PENDING_INTENT_BAL_ALLOWED_DEFAULT)); - } - - /** - * Set PendingIntent activity is allowed to be started in the background if the caller - * can start background activities. - */ - public void setPendingIntentBackgroundActivityLaunchAllowed(boolean allowed) { - mPendingIntentBalAllowed = allowed; - } - - /** - * Get PendingIntent activity is allowed to be started in the background if the caller - * can start background activities. - */ - public boolean isPendingIntentBackgroundActivityLaunchAllowed() { - return mPendingIntentBalAllowed; - } - - public Bundle toBundle() { - Bundle b = new Bundle(); - b.putBoolean(KEY_PENDING_INTENT_BACKGROUND_ACTIVITY_ALLOWED, mPendingIntentBalAllowed); - return b; - } -} |
