1 /*
2  * Copyright 2014, 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 package com.android.managedprovisioning;
17 
18 import android.content.Intent;
19 import android.content.IntentFilter;
20 import android.content.pm.PackageManager;
21 import android.provider.AlarmClock;
22 import android.provider.MediaStore;
23 
24 import static android.speech.RecognizerIntent.ACTION_RECOGNIZE_SPEECH;
25 /**
26  * Class to set CrossProfileIntentFilters during managed profile creation, and reset them after an
27  * ota.
28  */
29 public class CrossProfileIntentFiltersHelper {
30 
setFilters(PackageManager pm, int parentUserId, int managedProfileUserId)31     public static void setFilters(PackageManager pm, int parentUserId, int managedProfileUserId) {
32         ProvisionLogger.logd("Setting cross-profile intent filters");
33 
34         // All Emergency/privileged calls are sent directly to the parent user.
35         IntentFilter mimeTypeCallEmergency = new IntentFilter();
36         mimeTypeCallEmergency.addAction(Intent.ACTION_CALL_EMERGENCY);
37         mimeTypeCallEmergency.addAction(Intent.ACTION_CALL_PRIVILEGED);
38         mimeTypeCallEmergency.addCategory(Intent.CATEGORY_DEFAULT);
39         mimeTypeCallEmergency.addCategory(Intent.CATEGORY_BROWSABLE);
40         try {
41             mimeTypeCallEmergency.addDataType("vnd.android.cursor.item/phone");
42             mimeTypeCallEmergency.addDataType("vnd.android.cursor.item/phone_v2");
43             mimeTypeCallEmergency.addDataType("vnd.android.cursor.item/person");
44             mimeTypeCallEmergency.addDataType("vnd.android.cursor.dir/calls");
45             mimeTypeCallEmergency.addDataType("vnd.android.cursor.item/calls");
46         } catch (IntentFilter.MalformedMimeTypeException e) {
47             //will not happen
48         }
49         pm.addCrossProfileIntentFilter(mimeTypeCallEmergency, managedProfileUserId, parentUserId,
50                 PackageManager.SKIP_CURRENT_PROFILE);
51 
52         IntentFilter callWithDataEmergency = new IntentFilter();
53         callWithDataEmergency.addAction(Intent.ACTION_CALL_EMERGENCY);
54         callWithDataEmergency.addAction(Intent.ACTION_CALL_PRIVILEGED);
55         callWithDataEmergency.addCategory(Intent.CATEGORY_DEFAULT);
56         callWithDataEmergency.addCategory(Intent.CATEGORY_BROWSABLE);
57         callWithDataEmergency.addDataScheme("tel");
58         callWithDataEmergency.addDataScheme("sip");
59         callWithDataEmergency.addDataScheme("voicemail");
60         pm.addCrossProfileIntentFilter(callWithDataEmergency, managedProfileUserId, parentUserId,
61                 PackageManager.SKIP_CURRENT_PROFILE);
62 
63         // Dial intent with mime type can be handled by either managed profile or its parent user.
64         IntentFilter mimeTypeDial = new IntentFilter();
65         mimeTypeDial.addAction(Intent.ACTION_DIAL);
66         mimeTypeDial.addAction(Intent.ACTION_VIEW);
67         mimeTypeDial.addCategory(Intent.CATEGORY_DEFAULT);
68         mimeTypeDial.addCategory(Intent.CATEGORY_BROWSABLE);
69         try {
70             mimeTypeDial.addDataType("vnd.android.cursor.item/phone");
71             mimeTypeDial.addDataType("vnd.android.cursor.item/phone_v2");
72             mimeTypeDial.addDataType("vnd.android.cursor.item/person");
73             mimeTypeDial.addDataType("vnd.android.cursor.dir/calls");
74             mimeTypeDial.addDataType("vnd.android.cursor.item/calls");
75         } catch (IntentFilter.MalformedMimeTypeException e) {
76             //will not happen
77             ProvisionLogger.loge(e);
78         }
79         pm.addCrossProfileIntentFilter(mimeTypeDial, managedProfileUserId, parentUserId,
80                 PackageManager.ONLY_IF_NO_MATCH_FOUND);
81 
82         // Dial intent with tel, sip and voicemail scheme can be handled by either managed profile
83         // or its parent user.
84         IntentFilter dialWithData = new IntentFilter();
85         dialWithData.addAction(Intent.ACTION_DIAL);
86         dialWithData.addAction(Intent.ACTION_VIEW);
87         dialWithData.addCategory(Intent.CATEGORY_DEFAULT);
88         dialWithData.addCategory(Intent.CATEGORY_BROWSABLE);
89         dialWithData.addDataScheme("tel");
90         dialWithData.addDataScheme("sip");
91         dialWithData.addDataScheme("voicemail");
92         pm.addCrossProfileIntentFilter(dialWithData, managedProfileUserId, parentUserId,
93                 PackageManager.ONLY_IF_NO_MATCH_FOUND);
94 
95         // Dial intent with no data can be handled by either managed profile or its parent user.
96         IntentFilter dialNoData = new IntentFilter();
97         dialNoData.addAction(Intent.ACTION_DIAL);
98         dialNoData.addCategory(Intent.CATEGORY_DEFAULT);
99         dialNoData.addCategory(Intent.CATEGORY_BROWSABLE);
100         pm.addCrossProfileIntentFilter(dialNoData, managedProfileUserId, parentUserId,
101                 PackageManager.ONLY_IF_NO_MATCH_FOUND);
102 
103         // Call button intent can be handled by either managed profile or its parent user.
104         IntentFilter callButton = new IntentFilter();
105         callButton.addAction(Intent.ACTION_CALL_BUTTON);
106         callButton.addCategory(Intent.CATEGORY_DEFAULT);
107         pm.addCrossProfileIntentFilter(callButton, managedProfileUserId, parentUserId,
108                 PackageManager.ONLY_IF_NO_MATCH_FOUND);
109 
110         IntentFilter smsMms = new IntentFilter();
111         smsMms.addAction(Intent.ACTION_VIEW);
112         smsMms.addAction(Intent.ACTION_SENDTO);
113         smsMms.addCategory(Intent.CATEGORY_DEFAULT);
114         smsMms.addCategory(Intent.CATEGORY_BROWSABLE);
115         smsMms.addDataScheme("sms");
116         smsMms.addDataScheme("smsto");
117         smsMms.addDataScheme("mms");
118         smsMms.addDataScheme("mmsto");
119         pm.addCrossProfileIntentFilter(smsMms, managedProfileUserId, parentUserId,
120                 PackageManager.SKIP_CURRENT_PROFILE);
121 
122         IntentFilter mobileNetworkSettings = new IntentFilter();
123         mobileNetworkSettings.addAction(android.provider.Settings.ACTION_DATA_ROAMING_SETTINGS);
124         mobileNetworkSettings.addAction(android.provider.Settings.ACTION_NETWORK_OPERATOR_SETTINGS);
125         mobileNetworkSettings.addCategory(Intent.CATEGORY_DEFAULT);
126         pm.addCrossProfileIntentFilter(mobileNetworkSettings, managedProfileUserId,
127                 parentUserId, PackageManager.SKIP_CURRENT_PROFILE);
128 
129         IntentFilter home = new IntentFilter();
130         home.addAction(Intent.ACTION_MAIN);
131         home.addCategory(Intent.CATEGORY_DEFAULT);
132         home.addCategory(Intent.CATEGORY_HOME);
133         pm.addCrossProfileIntentFilter(home, managedProfileUserId, parentUserId,
134                 PackageManager.SKIP_CURRENT_PROFILE);
135 
136         IntentFilter send = new IntentFilter();
137         send.addAction(Intent.ACTION_SEND);
138         send.addAction(Intent.ACTION_SEND_MULTIPLE);
139         send.addCategory(Intent.CATEGORY_DEFAULT);
140         try {
141             send.addDataType("*/*");
142         } catch (IntentFilter.MalformedMimeTypeException e) {
143             //will not happen
144             ProvisionLogger.loge(e);
145         }
146         // This is the only filter set on the opposite direction (from parent to managed profile).
147         pm.addCrossProfileIntentFilter(send, parentUserId, managedProfileUserId, 0);
148 
149         IntentFilter getContent = new IntentFilter();
150         getContent.addAction(Intent.ACTION_GET_CONTENT);
151         getContent.addCategory(Intent.CATEGORY_DEFAULT);
152         getContent.addCategory(Intent.CATEGORY_OPENABLE);
153         try {
154             getContent.addDataType("*/*");
155         } catch (IntentFilter.MalformedMimeTypeException e) {
156             //will not happen
157             ProvisionLogger.loge(e);
158         }
159         pm.addCrossProfileIntentFilter(getContent, managedProfileUserId, parentUserId, 0);
160 
161         IntentFilter openDocument = new IntentFilter();
162         openDocument.addAction(Intent.ACTION_OPEN_DOCUMENT);
163         openDocument.addCategory(Intent.CATEGORY_DEFAULT);
164         openDocument.addCategory(Intent.CATEGORY_OPENABLE);
165         try {
166             openDocument.addDataType("*/*");
167         } catch (IntentFilter.MalformedMimeTypeException e) {
168             //will not happen
169             ProvisionLogger.loge(e);
170         }
171         pm.addCrossProfileIntentFilter(openDocument, managedProfileUserId, parentUserId, 0);
172 
173         IntentFilter pick = new IntentFilter();
174         pick.addAction(Intent.ACTION_PICK);
175         pick.addCategory(Intent.CATEGORY_DEFAULT);
176         try {
177             pick.addDataType("*/*");
178         } catch (IntentFilter.MalformedMimeTypeException e) {
179             //will not happen
180             ProvisionLogger.loge(e);
181         }
182         pm.addCrossProfileIntentFilter(pick, managedProfileUserId, parentUserId, 0);
183 
184         IntentFilter pickNoData = new IntentFilter();
185         pickNoData.addAction(Intent.ACTION_PICK);
186         pickNoData.addCategory(Intent.CATEGORY_DEFAULT);
187         pm.addCrossProfileIntentFilter(pickNoData, managedProfileUserId,
188                 parentUserId, 0);
189 
190         IntentFilter recognizeSpeech = new IntentFilter();
191         recognizeSpeech.addAction(ACTION_RECOGNIZE_SPEECH);
192         recognizeSpeech.addCategory(Intent.CATEGORY_DEFAULT);
193         pm.addCrossProfileIntentFilter(recognizeSpeech, managedProfileUserId, parentUserId, 0);
194 
195         IntentFilter capture = new IntentFilter();
196         capture.addAction(MediaStore.ACTION_IMAGE_CAPTURE);
197         capture.addAction(MediaStore.ACTION_IMAGE_CAPTURE_SECURE);
198         capture.addAction(MediaStore.ACTION_VIDEO_CAPTURE);
199         capture.addAction(MediaStore.Audio.Media.RECORD_SOUND_ACTION);
200         capture.addAction(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA);
201         capture.addAction(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA_SECURE);
202         capture.addAction(MediaStore.INTENT_ACTION_VIDEO_CAMERA);
203         capture.addCategory(Intent.CATEGORY_DEFAULT);
204         pm.addCrossProfileIntentFilter(capture, managedProfileUserId, parentUserId, 0);
205 
206         IntentFilter setClock = new IntentFilter();
207         setClock.addAction(AlarmClock.ACTION_SET_ALARM);
208         setClock.addAction(AlarmClock.ACTION_SHOW_ALARMS);
209         setClock.addAction(AlarmClock.ACTION_SET_TIMER);
210         setClock.addCategory(Intent.CATEGORY_DEFAULT);
211         pm.addCrossProfileIntentFilter(setClock, managedProfileUserId, parentUserId, 0);
212     }
213 }
214