Nicolas Prevot | 5f22bf5 | 2014-07-24 19:30:55 +0100 | [diff] [blame] | 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 | |
Nicolas Prevot | 5f22bf5 | 2014-07-24 19:30:55 +0100 | [diff] [blame] | 20 | import android.content.Context; |
| 21 | import android.content.Intent; |
| 22 | import android.content.IntentFilter; |
Nicolas Prevot | 5f22bf5 | 2014-07-24 19:30:55 +0100 | [diff] [blame] | 23 | import android.content.pm.PackageManager; |
Sudheer Shanka | 2fd51c5 | 2015-01-20 19:02:49 +0000 | [diff] [blame] | 24 | import android.provider.AlarmClock; |
Nicolas Prevot | 5f22bf5 | 2014-07-24 19:30:55 +0100 | [diff] [blame] | 25 | import android.provider.MediaStore; |
Nicolas Prevot | 5f22bf5 | 2014-07-24 19:30:55 +0100 | [diff] [blame] | 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 | |
Nicolas Prevot | 5f22bf5 | 2014-07-24 19:30:55 +0100 | [diff] [blame] | 36 | public static void setFilters(PackageManager pm, int parentUserId, int managedProfileUserId) { |
| 37 | ProvisionLogger.logd("Setting cross-profile intent filters"); |
| 38 | |
Esteban Talavera | 67732ef | 2014-08-13 11:07:24 +0100 | [diff] [blame] | 39 | // Voicemail scheme, phone/call related MIME types and emergency/priviledged calls are sent |
| 40 | // directly to the parent user. |
Nicolas Prevot | 5f22bf5 | 2014-07-24 19:30:55 +0100 | [diff] [blame] | 41 | IntentFilter mimeTypeTelephony = new IntentFilter(); |
| 42 | mimeTypeTelephony.addAction(Intent.ACTION_DIAL); |
Esteban Talavera | 67732ef | 2014-08-13 11:07:24 +0100 | [diff] [blame] | 43 | mimeTypeTelephony.addAction(Intent.ACTION_VIEW); |
| 44 | mimeTypeTelephony.addAction(Intent.ACTION_CALL_EMERGENCY); |
| 45 | mimeTypeTelephony.addAction(Intent.ACTION_CALL_PRIVILEGED); |
Nicolas Prevot | 5f22bf5 | 2014-07-24 19:30:55 +0100 | [diff] [blame] | 46 | mimeTypeTelephony.addCategory(Intent.CATEGORY_DEFAULT); |
| 47 | mimeTypeTelephony.addCategory(Intent.CATEGORY_BROWSABLE); |
| 48 | try { |
| 49 | mimeTypeTelephony.addDataType("vnd.android.cursor.item/phone"); |
Esteban Talavera | 67732ef | 2014-08-13 11:07:24 +0100 | [diff] [blame] | 50 | mimeTypeTelephony.addDataType("vnd.android.cursor.item/phone_v2"); |
Nicolas Prevot | 5f22bf5 | 2014-07-24 19:30:55 +0100 | [diff] [blame] | 51 | mimeTypeTelephony.addDataType("vnd.android.cursor.item/person"); |
| 52 | mimeTypeTelephony.addDataType("vnd.android.cursor.dir/calls"); |
Esteban Talavera | 67732ef | 2014-08-13 11:07:24 +0100 | [diff] [blame] | 53 | mimeTypeTelephony.addDataType("vnd.android.cursor.item/calls"); |
Nicolas Prevot | 5f22bf5 | 2014-07-24 19:30:55 +0100 | [diff] [blame] | 54 | } catch (IntentFilter.MalformedMimeTypeException e) { |
| 55 | //will not happen |
| 56 | } |
| 57 | pm.addCrossProfileIntentFilter(mimeTypeTelephony, managedProfileUserId, parentUserId, |
| 58 | PackageManager.SKIP_CURRENT_PROFILE); |
| 59 | |
Esteban Talavera | 67732ef | 2014-08-13 11:07:24 +0100 | [diff] [blame] | 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); |
Nicolas Prevot | 47f7fd0 | 2014-08-06 11:00:10 +0100 | [diff] [blame] | 70 | |
Esteban Talavera | 67732ef | 2014-08-13 11:07:24 +0100 | [diff] [blame] | 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. |
Nicolas Prevot | 5f22bf5 | 2014-07-24 19:30:55 +0100 | [diff] [blame] | 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"); |
Nicolas Prevot | 5f22bf5 | 2014-07-24 19:30:55 +0100 | [diff] [blame] | 90 | callDial.addDataScheme("sip"); |
Esteban Talavera | 67732ef | 2014-08-13 11:07:24 +0100 | [diff] [blame] | 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); |
Nicolas Prevot | 5f22bf5 | 2014-07-24 19:30:55 +0100 | [diff] [blame] | 97 | |
| 98 | IntentFilter callDialNoData = new IntentFilter(); |
| 99 | callDialNoData.addAction(Intent.ACTION_DIAL); |
| 100 | callDialNoData.addAction(Intent.ACTION_CALL); |
Nicolas Prevot | 5f22bf5 | 2014-07-24 19:30:55 +0100 | [diff] [blame] | 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 | |
Nicolas Prevot | 47f7fd0 | 2014-08-06 11:00:10 +0100 | [diff] [blame] | 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 | |
Nicolas Prevot | deca061 | 2014-08-11 12:03:15 +0100 | [diff] [blame] | 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 | |
Nicolas Prevot | 5f22bf5 | 2014-07-24 19:30:55 +0100 | [diff] [blame] | 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 | } |
Esteban Talavera | 67732ef | 2014-08-13 11:07:24 +0100 | [diff] [blame] | 141 | // This is the only filter set on the opposite direction (from parent to managed profile). |
Nicolas Prevot | 5f22bf5 | 2014-07-24 19:30:55 +0100 | [diff] [blame] | 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.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 Shanka | 2fd51c5 | 2015-01-20 19:02:49 +0000 | [diff] [blame] | 196 | |
| 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 Prevot | 5f22bf5 | 2014-07-24 19:30:55 +0100 | [diff] [blame] | 203 | } |
| 204 | } |