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