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 17 package com.android.managedprovisioning.task; 18 19 import android.app.AppGlobals; 20 import android.content.ComponentName; 21 import android.content.Context; 22 import android.content.Intent; 23 import android.content.pm.ComponentInfo; 24 import android.content.pm.PackageManager; 25 import android.content.pm.ResolveInfo; 26 27 import com.android.managedprovisioning.common.ProvisionLogger; 28 import com.android.managedprovisioning.R; 29 import com.android.managedprovisioning.common.Utils; 30 import com.android.managedprovisioning.model.ProvisioningParams; 31 32 import java.util.List; 33 import java.util.Set; 34 35 36 /** 37 * Disables all system app components that listen to ACTION_INSTALL_SHORTCUT. 38 */ 39 public class DisableInstallShortcutListenersTask extends AbstractProvisioningTask { 40 private final PackageManager mPm; 41 private int mUserId; 42 43 private final Utils mUtils = new Utils(); 44 45 public DisableInstallShortcutListenersTask( 46 Context context, 47 ProvisioningParams params, 48 Callback callback) { 49 super(context, params, callback); 50 51 mPm = context.getPackageManager(); 52 } 53 54 @Override 55 public void run(int userId) { 56 mUserId = userId; 57 ProvisionLogger.logd("Disabling install shortcut listeners."); 58 Intent actionShortcut = new Intent("com.android.launcher.action.INSTALL_SHORTCUT"); 59 Set<String> systemApps = mUtils.getCurrentSystemApps(AppGlobals.getPackageManager(), 60 mUserId); 61 for (String systemApp : systemApps) { 62 actionShortcut.setPackage(systemApp); 63 disableReceivers(actionShortcut); 64 } 65 success(); 66 } 67 68 @Override 69 public int getStatusMsgId() { 70 return R.string.progress_finishing_touches; 71 } 72 73 /** 74 * Disable all components that can handle the specified broadcast intent. 75 */ 76 private void disableReceivers(Intent intent) { 77 List<ResolveInfo> receivers = mPm.queryBroadcastReceiversAsUser(intent, 78 PackageManager.MATCH_DIRECT_BOOT_UNAWARE | PackageManager.MATCH_DIRECT_BOOT_AWARE, 79 mUserId); 80 for (ResolveInfo ri : receivers) { 81 // One of ri.activityInfo, ri.serviceInfo, ri.providerInfo is not null. Let's find which 82 // one. 83 ComponentInfo ci; 84 if (ri.activityInfo != null) { 85 ci = ri.activityInfo; 86 } else if (ri.serviceInfo != null) { 87 ci = ri.serviceInfo; 88 } else { 89 ci = ri.providerInfo; 90 } 91 mUtils.disableComponent(new ComponentName(ci.packageName, ci.name), mUserId); 92 } 93 } 94 } 95