• 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 com.android.server.pm;
18 
19 import static android.content.pm.PackageManager.ONLY_IF_NO_MATCH_FOUND;
20 import static android.content.pm.PackageManager.SKIP_CURRENT_PROFILE;
21 import static android.speech.RecognizerIntent.ACTION_RECOGNIZE_SPEECH;
22 
23 import android.content.Intent;
24 import android.hardware.usb.UsbManager;
25 import android.provider.AlarmClock;
26 import android.provider.MediaStore;
27 
28 import java.util.Arrays;
29 import java.util.List;
30 
31 /**
32  * Utility Class for {@link DefaultCrossProfileIntentFilter}.
33  */
34 public class DefaultCrossProfileIntentFiltersUtils {
35 
DefaultCrossProfileIntentFiltersUtils()36     private DefaultCrossProfileIntentFiltersUtils() {
37     }
38 
39     // Intents from profile to parent user
40     /** Emergency call intent with mime type is always resolved by primary user. */
41     private static final DefaultCrossProfileIntentFilter
42             EMERGENCY_CALL_MIME =
43             new DefaultCrossProfileIntentFilter.Builder(
44                     DefaultCrossProfileIntentFilter.Direction.TO_PARENT,
45                     SKIP_CURRENT_PROFILE,
46                     /* letsPersonalDataIntoProfile= */ false)
47                     .addAction(Intent.ACTION_CALL_EMERGENCY)
48                     .addAction(Intent.ACTION_CALL_PRIVILEGED)
49                     .addCategory(Intent.CATEGORY_DEFAULT)
50                     .addCategory(Intent.CATEGORY_BROWSABLE)
51                     .addDataType("vnd.android.cursor.item/phone")
52                     .addDataType("vnd.android.cursor.item/phone_v2")
53                     .addDataType("vnd.android.cursor.item/person")
54                     .addDataType("vnd.android.cursor.dir/calls")
55                     .addDataType("vnd.android.cursor.item/calls")
56                     .build();
57 
58     /** Emergency call intent with data schemes is always resolved by primary user. */
59     private static final DefaultCrossProfileIntentFilter
60             EMERGENCY_CALL_DATA =
61             new DefaultCrossProfileIntentFilter.Builder(
62                     DefaultCrossProfileIntentFilter.Direction.TO_PARENT,
63                     SKIP_CURRENT_PROFILE,
64                     /* letsPersonalDataIntoProfile= */ false)
65                     .addAction(Intent.ACTION_CALL_EMERGENCY)
66                     .addAction(Intent.ACTION_CALL_PRIVILEGED)
67                     .addCategory(Intent.CATEGORY_DEFAULT)
68                     .addCategory(Intent.CATEGORY_BROWSABLE)
69                     .addDataScheme("tel")
70                     .addDataScheme("sip")
71                     .addDataScheme("voicemail")
72                     .build();
73 
74     /** Dial intent with mime type can be handled by either managed profile or its parent user. */
75     private static final DefaultCrossProfileIntentFilter DIAL_MIME =
76             new DefaultCrossProfileIntentFilter.Builder(
77                     DefaultCrossProfileIntentFilter.Direction.TO_PARENT,
78                     ONLY_IF_NO_MATCH_FOUND,
79                     /* letsPersonalDataIntoProfile= */ false)
80                     .addAction(Intent.ACTION_DIAL)
81                     .addAction(Intent.ACTION_VIEW)
82                     .addCategory(Intent.CATEGORY_DEFAULT)
83                     .addCategory(Intent.CATEGORY_BROWSABLE)
84                     .addDataType("vnd.android.cursor.item/phone")
85                     .addDataType("vnd.android.cursor.item/phone_v2")
86                     .addDataType("vnd.android.cursor.item/person")
87                     .addDataType("vnd.android.cursor.dir/calls")
88                     .addDataType("vnd.android.cursor.item/calls")
89                     .build();
90 
91     /** Dial intent with data scheme can be handled by either managed profile or its parent user. */
92     private static final DefaultCrossProfileIntentFilter DIAL_DATA =
93             new DefaultCrossProfileIntentFilter.Builder(
94                     DefaultCrossProfileIntentFilter.Direction.TO_PARENT,
95                     ONLY_IF_NO_MATCH_FOUND,
96                     /* letsPersonalDataIntoProfile= */ false)
97                     .addAction(Intent.ACTION_DIAL)
98                     .addAction(Intent.ACTION_VIEW)
99                     .addCategory(Intent.CATEGORY_DEFAULT)
100                     .addCategory(Intent.CATEGORY_BROWSABLE)
101                     .addDataScheme("tel")
102                     .addDataScheme("sip")
103                     .addDataScheme("voicemail")
104                     .build();
105 
106     /**
107      * Dial intent with no data scheme or type can be handled by either managed profile or its
108      * parent user.
109      */
110     private static final DefaultCrossProfileIntentFilter DIAL_RAW =
111             new DefaultCrossProfileIntentFilter.Builder(
112                     DefaultCrossProfileIntentFilter.Direction.TO_PARENT,
113                     ONLY_IF_NO_MATCH_FOUND,
114                     /* letsPersonalDataIntoProfile= */ false)
115                     .addAction(Intent.ACTION_DIAL)
116                     .addCategory(Intent.CATEGORY_DEFAULT)
117                     .addCategory(Intent.CATEGORY_BROWSABLE)
118                     .build();
119 
120     /** Pressing the call button can be handled by either managed profile or its parent user. */
121     private static final DefaultCrossProfileIntentFilter CALL_BUTTON =
122             new DefaultCrossProfileIntentFilter.Builder(
123                     DefaultCrossProfileIntentFilter.Direction.TO_PARENT,
124                     ONLY_IF_NO_MATCH_FOUND,
125                     /* letsPersonalDataIntoProfile= */ false)
126                     .addAction(Intent.ACTION_CALL_BUTTON)
127                     .addCategory(Intent.CATEGORY_DEFAULT)
128                     .build();
129 
130     /** SMS and MMS are exclusively handled by the primary user. */
131     private static final DefaultCrossProfileIntentFilter SMS_MMS =
132             new DefaultCrossProfileIntentFilter.Builder(
133                     DefaultCrossProfileIntentFilter.Direction.TO_PARENT,
134                     SKIP_CURRENT_PROFILE,
135                     /* letsPersonalDataIntoProfile= */ false)
136                     .addAction(Intent.ACTION_VIEW)
137                     .addAction(Intent.ACTION_SENDTO)
138                     .addCategory(Intent.CATEGORY_DEFAULT)
139                     .addCategory(Intent.CATEGORY_BROWSABLE)
140                     .addDataScheme("sms")
141                     .addDataScheme("smsto")
142                     .addDataScheme("mms")
143                     .addDataScheme("mmsto")
144                     .build();
145 
146     /** Mobile network settings is always shown in the primary user. */
147     private static final DefaultCrossProfileIntentFilter
148             MOBILE_NETWORK_SETTINGS =
149             new DefaultCrossProfileIntentFilter.Builder(
150                     DefaultCrossProfileIntentFilter.Direction.TO_PARENT,
151                     SKIP_CURRENT_PROFILE,
152                     /* letsPersonalDataIntoProfile= */ false)
153                     .addAction(android.provider.Settings.ACTION_DATA_ROAMING_SETTINGS)
154                     .addAction(android.provider.Settings.ACTION_NETWORK_OPERATOR_SETTINGS)
155                     .addCategory(Intent.CATEGORY_DEFAULT)
156                     .build();
157 
158     /** HOME intent is always resolved by the primary user. */
159     static final DefaultCrossProfileIntentFilter HOME =
160             new DefaultCrossProfileIntentFilter.Builder(
161                     DefaultCrossProfileIntentFilter.Direction.TO_PARENT,
162                     SKIP_CURRENT_PROFILE,
163                     /* letsPersonalDataIntoProfile= */ false)
164                     .addAction(Intent.ACTION_MAIN)
165                     .addCategory(Intent.CATEGORY_DEFAULT)
166                     .addCategory(Intent.CATEGORY_HOME)
167                     .build();
168 
169     /** Get content can be forwarded to parent user. */
170     private static final DefaultCrossProfileIntentFilter GET_CONTENT =
171             new DefaultCrossProfileIntentFilter.Builder(
172                     DefaultCrossProfileIntentFilter.Direction.TO_PARENT,
173                     /* flags= */0,
174                     /* letsPersonalDataIntoProfile= */ true)
175                     .addAction(Intent.ACTION_GET_CONTENT)
176                     .addCategory(Intent.CATEGORY_DEFAULT)
177                     .addCategory(Intent.CATEGORY_OPENABLE)
178                     .addDataType("*/*")
179                     .build();
180 
181     /** Pick images can be forwarded to parent user. */
182     private static final DefaultCrossProfileIntentFilter ACTION_PICK_IMAGES =
183             new DefaultCrossProfileIntentFilter.Builder(
184                     DefaultCrossProfileIntentFilter.Direction.TO_PARENT,
185                     /* flags= */ 0,
186                     /* letsPersonalDataIntoProfile= */ true)
187                     .addAction(MediaStore.ACTION_PICK_IMAGES)
188                     .addCategory(Intent.CATEGORY_DEFAULT)
189                     .build();
190     /** Pick images can be forwarded to parent user. */
191     private static final DefaultCrossProfileIntentFilter ACTION_PICK_IMAGES_WITH_DATA_TYPES =
192             new DefaultCrossProfileIntentFilter.Builder(
193                     DefaultCrossProfileIntentFilter.Direction.TO_PARENT,
194                     /* flags= */ 0,
195                     /* letsPersonalDataIntoProfile= */ true)
196                     .addAction(MediaStore.ACTION_PICK_IMAGES)
197                     .addCategory(Intent.CATEGORY_DEFAULT)
198                     .addDataType("image/*")
199                     .addDataType("video/*")
200                     .build();
201 
202     /** Open document intent can be forwarded to parent user. */
203     private static final DefaultCrossProfileIntentFilter OPEN_DOCUMENT =
204             new DefaultCrossProfileIntentFilter.Builder(
205                     DefaultCrossProfileIntentFilter.Direction.TO_PARENT,
206                     /* flags= */0,
207                     /* letsPersonalDataIntoProfile= */ true)
208                     .addAction(Intent.ACTION_OPEN_DOCUMENT)
209                     .addCategory(Intent.CATEGORY_DEFAULT)
210                     .addCategory(Intent.CATEGORY_OPENABLE)
211                     .addDataType("*/*")
212                     .build();
213 
214     /** Pick for any data type can be forwarded to parent user. */
215     private static final DefaultCrossProfileIntentFilter ACTION_PICK_DATA =
216             new DefaultCrossProfileIntentFilter.Builder(
217                     DefaultCrossProfileIntentFilter.Direction.TO_PARENT,
218                     /* flags= */0,
219                     /* letsPersonalDataIntoProfile= */ true)
220                     .addAction(Intent.ACTION_PICK)
221                     .addCategory(Intent.CATEGORY_DEFAULT)
222                     .addDataType("*/*")
223                     .build();
224 
225     /** Pick without data type can be forwarded to parent user. */
226     private static final DefaultCrossProfileIntentFilter ACTION_PICK_RAW =
227             new DefaultCrossProfileIntentFilter.Builder(
228                     DefaultCrossProfileIntentFilter.Direction.TO_PARENT,
229                     /* flags= */0,
230                     /* letsPersonalDataIntoProfile= */ true)
231                     .addAction(Intent.ACTION_PICK)
232                     .addCategory(Intent.CATEGORY_DEFAULT)
233                     .build();
234 
235     /** Speech recognition can be performed by primary user. */
236     private static final DefaultCrossProfileIntentFilter RECOGNIZE_SPEECH =
237             new DefaultCrossProfileIntentFilter.Builder(
238                     DefaultCrossProfileIntentFilter.Direction.TO_PARENT,
239                     /* flags= */ ONLY_IF_NO_MATCH_FOUND,
240                     /* letsPersonalDataIntoProfile= */ false)
241                     .addAction(ACTION_RECOGNIZE_SPEECH)
242                     .addCategory(Intent.CATEGORY_DEFAULT)
243                     .build();
244 
245     /** Media capture can be performed by primary user. */
246     private static final DefaultCrossProfileIntentFilter MEDIA_CAPTURE =
247             new DefaultCrossProfileIntentFilter.Builder(
248                     DefaultCrossProfileIntentFilter.Direction.TO_PARENT,
249                     /* flags= */ ONLY_IF_NO_MATCH_FOUND,
250                     /* letsPersonalDataIntoProfile= */ true)
251                     .addAction(MediaStore.ACTION_IMAGE_CAPTURE)
252                     .addAction(MediaStore.ACTION_IMAGE_CAPTURE_SECURE)
253                     .addAction(MediaStore.ACTION_VIDEO_CAPTURE)
254                     .addAction(MediaStore.Audio.Media.RECORD_SOUND_ACTION)
255                     .addAction(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA)
256                     .addAction(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA_SECURE)
257                     .addAction(MediaStore.INTENT_ACTION_VIDEO_CAMERA)
258                     .addCategory(Intent.CATEGORY_DEFAULT)
259                     .build();
260 
261     /** Alarm setting can be performed by primary user. */
262     private static final DefaultCrossProfileIntentFilter SET_ALARM =
263             new DefaultCrossProfileIntentFilter.Builder(
264                     DefaultCrossProfileIntentFilter.Direction.TO_PARENT,
265                     /* flags= */0,
266                     /* letsPersonalDataIntoProfile= */ false)
267                     .addAction(AlarmClock.ACTION_SET_ALARM)
268                     .addAction(AlarmClock.ACTION_SHOW_ALARMS)
269                     .addAction(AlarmClock.ACTION_SET_TIMER)
270                     .addCategory(Intent.CATEGORY_DEFAULT)
271                     .build();
272 
273     // Intents from parent to profile user
274 
275     /** ACTION_SEND can be forwarded to the managed profile on user's choice. */
276     private static final DefaultCrossProfileIntentFilter ACTION_SEND =
277             new DefaultCrossProfileIntentFilter.Builder(
278                     DefaultCrossProfileIntentFilter.Direction.TO_PROFILE,
279                     /* flags= */0,
280                     /* letsPersonalDataIntoProfile= */ true)
281                     .addAction(Intent.ACTION_SEND)
282                     .addAction(Intent.ACTION_SEND_MULTIPLE)
283                     .addCategory(Intent.CATEGORY_DEFAULT)
284                     .addDataType("*/*")
285                     .build();
286 
287     /** USB devices attached can get forwarded to the profile. */
288     private static final DefaultCrossProfileIntentFilter
289             USB_DEVICE_ATTACHED =
290             new DefaultCrossProfileIntentFilter.Builder(
291                     DefaultCrossProfileIntentFilter.Direction.TO_PROFILE,
292                     /* flags= */0,
293                     /* letsPersonalDataIntoProfile= */ false)
294                     .addAction(UsbManager.ACTION_USB_DEVICE_ATTACHED)
295                     .addAction(UsbManager.ACTION_USB_ACCESSORY_ATTACHED)
296                     .addCategory(Intent.CATEGORY_DEFAULT)
297                     .build();
298 
getDefaultManagedProfileFilters()299     public static List<DefaultCrossProfileIntentFilter> getDefaultManagedProfileFilters() {
300         return Arrays.asList(
301                 EMERGENCY_CALL_MIME,
302                 EMERGENCY_CALL_DATA,
303                 DIAL_MIME,
304                 DIAL_DATA,
305                 DIAL_RAW,
306                 CALL_BUTTON,
307                 SMS_MMS,
308                 SET_ALARM,
309                 MEDIA_CAPTURE,
310                 RECOGNIZE_SPEECH,
311                 ACTION_PICK_RAW,
312                 ACTION_PICK_DATA,
313                 ACTION_PICK_IMAGES,
314                 ACTION_PICK_IMAGES_WITH_DATA_TYPES,
315                 OPEN_DOCUMENT,
316                 GET_CONTENT,
317                 USB_DEVICE_ATTACHED,
318                 ACTION_SEND,
319                 HOME,
320                 MOBILE_NETWORK_SETTINGS);
321     }
322 }
323