• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package android.app;
18 
19 import android.os.Bundle;
20 
21 /**
22  * @hide
23  */
24 public class ComponentOptions {
25 
26     /**
27      * Default value for KEY_PENDING_INTENT_BACKGROUND_ACTIVITY_ALLOWED.
28      * @hide
29      **/
30     public static final boolean PENDING_INTENT_BAL_ALLOWED_DEFAULT = true;
31 
32     /**
33      * PendingIntent caller allows activity start even if PendingIntent creator is in background.
34      * This only works if the PendingIntent caller is allowed to start background activities,
35      * for example if it's in the foreground, or has BAL permission.
36      * @hide
37      */
38     public static final String KEY_PENDING_INTENT_BACKGROUND_ACTIVITY_ALLOWED =
39             "android.pendingIntent.backgroundActivityAllowed";
40 
41     /**
42      * PendingIntent caller allows activity to be started if caller has BAL permission.
43      * @hide
44      */
45     public static final String KEY_PENDING_INTENT_BACKGROUND_ACTIVITY_ALLOWED_BY_PERMISSION =
46             "android.pendingIntent.backgroundActivityAllowedByPermission";
47 
48     private boolean mPendingIntentBalAllowed = PENDING_INTENT_BAL_ALLOWED_DEFAULT;
49     private boolean mPendingIntentBalAllowedByPermission = false;
50 
ComponentOptions()51     ComponentOptions() {
52     }
53 
ComponentOptions(Bundle opts)54     ComponentOptions(Bundle opts) {
55         // If the remote side sent us bad parcelables, they won't get the
56         // results they want, which is their loss.
57         opts.setDefusable(true);
58         setPendingIntentBackgroundActivityLaunchAllowed(
59                 opts.getBoolean(KEY_PENDING_INTENT_BACKGROUND_ACTIVITY_ALLOWED,
60                         PENDING_INTENT_BAL_ALLOWED_DEFAULT));
61         setPendingIntentBackgroundActivityLaunchAllowedByPermission(
62                 opts.getBoolean(KEY_PENDING_INTENT_BACKGROUND_ACTIVITY_ALLOWED_BY_PERMISSION,
63                         false));
64     }
65 
66     /**
67      * Set PendingIntent activity is allowed to be started in the background if the caller
68      * can start background activities.
69      */
setPendingIntentBackgroundActivityLaunchAllowed(boolean allowed)70     public void setPendingIntentBackgroundActivityLaunchAllowed(boolean allowed) {
71         mPendingIntentBalAllowed = allowed;
72     }
73 
74     /**
75      * Get PendingIntent activity is allowed to be started in the background if the caller
76      * can start background activities.
77      */
isPendingIntentBackgroundActivityLaunchAllowed()78     public boolean isPendingIntentBackgroundActivityLaunchAllowed() {
79         return mPendingIntentBalAllowed;
80     }
81 
82     /**
83      * Set PendingIntent activity can be launched from background if caller has BAL permission.
84      * @hide
85      */
setPendingIntentBackgroundActivityLaunchAllowedByPermission(boolean allowed)86     public void setPendingIntentBackgroundActivityLaunchAllowedByPermission(boolean allowed) {
87         mPendingIntentBalAllowedByPermission = allowed;
88     }
89 
90     /**
91      * Get PendingIntent activity is allowed to be started in the background if the caller
92      * has BAL permission.
93      * @hide
94      */
isPendingIntentBackgroundActivityLaunchAllowedByPermission()95     public boolean isPendingIntentBackgroundActivityLaunchAllowedByPermission() {
96         return mPendingIntentBalAllowedByPermission;
97     }
98 
toBundle()99     public Bundle toBundle() {
100         Bundle b = new Bundle();
101         b.putBoolean(KEY_PENDING_INTENT_BACKGROUND_ACTIVITY_ALLOWED, mPendingIntentBalAllowed);
102         if (mPendingIntentBalAllowedByPermission) {
103             b.putBoolean(KEY_PENDING_INTENT_BACKGROUND_ACTIVITY_ALLOWED_BY_PERMISSION,
104                     mPendingIntentBalAllowedByPermission);
105         }
106         return b;
107     }
108 }
109