1 /* 2 * Copyright (C) 2016 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.settings.applications; 18 19 import android.content.ComponentName; 20 import android.content.Intent; 21 import android.content.IntentFilter; 22 import android.content.pm.ApplicationInfo; 23 import android.content.pm.IPackageDeleteObserver; 24 import android.content.pm.PackageInfo; 25 import android.content.pm.PackageManager; 26 import android.content.pm.ResolveInfo; 27 import android.os.UserHandle; 28 import android.os.storage.VolumeInfo; 29 30 import java.util.List; 31 32 /** 33 * This interface replicates a subset of the android.content.pm.PackageManager (PM). The interface 34 * exists so that we can use a thin wrapper around the PM in production code and a mock in tests. 35 * We cannot directly mock or shadow the PM, because some of the methods we rely on are newer than 36 * the API version supported by Robolectric. 37 */ 38 public interface PackageManagerWrapper { 39 40 /** 41 * Returns the real {@code PackageManager} object. 42 */ getPackageManager()43 PackageManager getPackageManager(); 44 45 /** 46 * Calls {@code PackageManager.getInstalledApplicationsAsUser()}. 47 * 48 * @see android.content.pm.PackageManager#getInstalledApplicationsAsUser 49 */ getInstalledApplicationsAsUser(int flags, int userId)50 List<ApplicationInfo> getInstalledApplicationsAsUser(int flags, int userId); 51 52 /** 53 * Calls {@code PackageManager.getInstalledPackagesAsUser} 54 */ getInstalledPackagesAsUser(int flags, int userId)55 List<PackageInfo> getInstalledPackagesAsUser(int flags, int userId); 56 57 /** 58 * Calls {@code PackageManager.hasSystemFeature()}. 59 * 60 * @see android.content.pm.PackageManager#hasSystemFeature 61 */ hasSystemFeature(String name)62 boolean hasSystemFeature(String name); 63 64 /** 65 * Calls {@code PackageManager.queryIntentActivitiesAsUser()}. 66 * 67 * @see android.content.pm.PackageManager#queryIntentActivitiesAsUser 68 */ queryIntentActivitiesAsUser(Intent intent, int flags, int userId)69 List<ResolveInfo> queryIntentActivitiesAsUser(Intent intent, int flags, int userId); 70 71 /** 72 * Calls {@code PackageManager.getInstallReason()}. 73 * 74 * @see android.content.pm.PackageManager#getInstallReason 75 */ getInstallReason(String packageName, UserHandle user)76 int getInstallReason(String packageName, UserHandle user); 77 78 /** 79 * Calls {@code PackageManager.getApplicationInfoAsUser} 80 */ getApplicationInfoAsUser(String packageName, int i, int userId)81 ApplicationInfo getApplicationInfoAsUser(String packageName, int i, int userId) 82 throws PackageManager.NameNotFoundException; 83 84 /** 85 * Calls {@code PackageManager.setDefaultBrowserPackageNameAsUser} 86 */ setDefaultBrowserPackageNameAsUser(String packageName, int userId)87 boolean setDefaultBrowserPackageNameAsUser(String packageName, int userId); 88 89 /** 90 * Calls {@code PackageManager.getDefaultBrowserPackageNameAsUser} 91 */ getDefaultBrowserPackageNameAsUser(int userId)92 String getDefaultBrowserPackageNameAsUser(int userId); 93 94 /** 95 * Calls {@code PackageManager.getHomeActivities} 96 */ getHomeActivities(List<ResolveInfo> homeActivities)97 ComponentName getHomeActivities(List<ResolveInfo> homeActivities); 98 99 /** 100 * Calls {@code PackageManager.queryIntentServicesAsUser} 101 */ queryIntentServicesAsUser(Intent intent, int i, int user)102 List<ResolveInfo> queryIntentServicesAsUser(Intent intent, int i, int user); 103 104 /** 105 * Calls {@code PackageManager.replacePreferredActivity} 106 */ replacePreferredActivity(IntentFilter homeFilter, int matchCategoryEmpty, ComponentName[] componentNames, ComponentName component)107 void replacePreferredActivity(IntentFilter homeFilter, int matchCategoryEmpty, 108 ComponentName[] componentNames, ComponentName component); 109 110 /** 111 * Calls {@code PackageManager.getPrimaryStorageCurrentVolume} 112 */ getPrimaryStorageCurrentVolume()113 VolumeInfo getPrimaryStorageCurrentVolume(); 114 115 /** 116 * Calls {@code PackageManager.deletePackageAsUser} 117 */ deletePackageAsUser(String packageName, IPackageDeleteObserver observer, int flags, int userId)118 void deletePackageAsUser(String packageName, IPackageDeleteObserver observer, int flags, 119 int userId); 120 getPackageUidAsUser(String pkg, int userId)121 int getPackageUidAsUser(String pkg, int userId) throws PackageManager.NameNotFoundException; 122 } 123