blob: 5936c2d391e00556ff48058ede61c8498b2bbd6d [file] [log] [blame]
Nicolas Prevot5f22bf52014-07-24 19:30:55 +01001/*
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 */
16package com.android.managedprovisioning;
17
18import static android.speech.RecognizerIntent.ACTION_RECOGNIZE_SPEECH;
19
Nicolas Prevot5f22bf52014-07-24 19:30:55 +010020import android.content.Context;
21import android.content.Intent;
22import android.content.IntentFilter;
Nicolas Prevot5f22bf52014-07-24 19:30:55 +010023import android.content.pm.PackageManager;
Sudheer Shanka2fd51c52015-01-20 19:02:49 +000024import android.provider.AlarmClock;
Nicolas Prevot5f22bf52014-07-24 19:30:55 +010025import android.provider.MediaStore;
Nicolas Prevot5f22bf52014-07-24 19:30:55 +010026
27import com.android.managedprovisioning.ProvisionLogger;
28
29import java.util.List;
30/**
31 * Class to set CrossProfileIntentFilters during managed profile creation, and reset them after an
32 * ota.
33 */
34public class CrossProfileIntentFiltersHelper {
35
Nicolas Prevot5f22bf52014-07-24 19:30:55 +010036 public static void setFilters(PackageManager pm, int parentUserId, int managedProfileUserId) {
37 ProvisionLogger.logd("Setting cross-profile intent filters");
38
Esteban Talavera67732ef2014-08-13 11:07:24 +010039 // Voicemail scheme, phone/call related MIME types and emergency/priviledged calls are sent
40 // directly to the parent user.
Nicolas Prevot5f22bf52014-07-24 19:30:55 +010041 IntentFilter mimeTypeTelephony = new IntentFilter();
42 mimeTypeTelephony.addAction(Intent.ACTION_DIAL);
Esteban Talavera67732ef2014-08-13 11:07:24 +010043 mimeTypeTelephony.addAction(Intent.ACTION_VIEW);
44 mimeTypeTelephony.addAction(Intent.ACTION_CALL_EMERGENCY);
45 mimeTypeTelephony.addAction(Intent.ACTION_CALL_PRIVILEGED);
Nicolas Prevot5f22bf52014-07-24 19:30:55 +010046 mimeTypeTelephony.addCategory(Intent.CATEGORY_DEFAULT);
47 mimeTypeTelephony.addCategory(Intent.CATEGORY_BROWSABLE);
48 try {
49 mimeTypeTelephony.addDataType("vnd.android.cursor.item/phone");
Esteban Talavera67732ef2014-08-13 11:07:24 +010050 mimeTypeTelephony.addDataType("vnd.android.cursor.item/phone_v2");
Nicolas Prevot5f22bf52014-07-24 19:30:55 +010051 mimeTypeTelephony.addDataType("vnd.android.cursor.item/person");
52 mimeTypeTelephony.addDataType("vnd.android.cursor.dir/calls");
Esteban Talavera67732ef2014-08-13 11:07:24 +010053 mimeTypeTelephony.addDataType("vnd.android.cursor.item/calls");
Nicolas Prevot5f22bf52014-07-24 19:30:55 +010054 } catch (IntentFilter.MalformedMimeTypeException e) {
55 //will not happen
56 }
57 pm.addCrossProfileIntentFilter(mimeTypeTelephony, managedProfileUserId, parentUserId,
58 PackageManager.SKIP_CURRENT_PROFILE);
59
Esteban Talavera67732ef2014-08-13 11:07:24 +010060 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);
Nicolas Prevot47f7fd02014-08-06 11:00:10 +010070
Esteban Talavera67732ef2014-08-13 11:07:24 +010071 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.
Nicolas Prevot5f22bf52014-07-24 19:30:55 +010083 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");
Nicolas Prevot5f22bf52014-07-24 19:30:55 +010090 callDial.addDataScheme("sip");
Esteban Talavera67732ef2014-08-13 11:07:24 +010091 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);
Nicolas Prevot5f22bf52014-07-24 19:30:55 +010097
98 IntentFilter callDialNoData = new IntentFilter();
99 callDialNoData.addAction(Intent.ACTION_DIAL);
100 callDialNoData.addAction(Intent.ACTION_CALL);
Nicolas Prevot5f22bf52014-07-24 19:30:55 +0100101 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
Nicolas Prevot47f7fd02014-08-06 11:00:10 +0100118 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
Nicolas Prevotdeca0612014-08-11 12:03:15 +0100125 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
Nicolas Prevot5f22bf52014-07-24 19:30:55 +0100132 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 }
Esteban Talavera67732ef2014-08-13 11:07:24 +0100141 // This is the only filter set on the opposite direction (from parent to managed profile).
Nicolas Prevot5f22bf52014-07-24 19:30:55 +0100142 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.INTENT_ACTION_STILL_IMAGE_CAMERA);
192 capture.addAction(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA_SECURE);
193 capture.addAction(MediaStore.INTENT_ACTION_VIDEO_CAMERA);
194 capture.addCategory(Intent.CATEGORY_DEFAULT);
195 pm.addCrossProfileIntentFilter(capture, managedProfileUserId, parentUserId, 0);
Sudheer Shanka2fd51c52015-01-20 19:02:49 +0000196
197 IntentFilter setClock = new IntentFilter();
198 setClock.addAction(AlarmClock.ACTION_SET_ALARM);
199 setClock.addAction(AlarmClock.ACTION_SHOW_ALARMS);
200 setClock.addAction(AlarmClock.ACTION_SET_TIMER);
201 setClock.addCategory(Intent.CATEGORY_DEFAULT);
202 pm.addCrossProfileIntentFilter(setClock, managedProfileUserId, parentUserId, 0);
Nicolas Prevot5f22bf52014-07-24 19:30:55 +0100203 }
204}