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