1/* 2 * Copyright (C) 2017 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 17package com.android.settings.applications; 18 19import android.content.Intent; 20import android.content.pm.PackageInfo; 21import android.content.pm.ParceledListSlice; 22import android.content.pm.ResolveInfo; 23import android.os.RemoteException; 24 25/** 26 * This interface replicates a subset of the android.content.pm.IPackageManager (PMS). The interface 27 * exists so that we can use a thin wrapper around the PMS in production code and a mock in tests. 28 * We cannot directly mock or shadow the PMS, because some of the methods we rely on are newer than 29 * the API version supported by Robolectric. 30 */ 31public interface IPackageManagerWrapper { 32 33 /** 34 * Calls {@code IPackageManager.checkUidPermission()}. 35 * 36 * @see android.content.pm.IPackageManager#checkUidPermission 37 */ 38 int checkUidPermission(String permName, int uid) throws RemoteException; 39 40 /** 41 * Calls {@code IPackageManager.findPersistentPreferredActivity()}. 42 * 43 * @see android.content.pm.IPackageManager#findPersistentPreferredActivity 44 */ 45 ResolveInfo findPersistentPreferredActivity(Intent intent, int userId) throws RemoteException; 46 47 /** 48 * Calls {@code IPackageManager.getPackageInfo()}. 49 * 50 * @see android.content.pm.IPackageManager#getPackageInfo 51 */ 52 PackageInfo getPackageInfo(String packageName, int flags, int userId) throws RemoteException; 53 54 /** 55 * Calls {@code IPackageManager.getAppOpPermissionPackages()}. 56 * 57 * @see android.content.pm.IPackageManager#getAppOpPermissionPackages 58 */ 59 String[] getAppOpPermissionPackages(String permissionName) throws RemoteException; 60 61 /** 62 * Calls {@code IPackageManager.isPackageAvailable()}. 63 * 64 * @see android.content.pm.IPackageManager#isPackageAvailable 65 */ 66 boolean isPackageAvailable(String packageName, int userId) throws RemoteException; 67 68 /** 69 * Calls {@code IPackageManager.getPackagesHoldingPermissions()}. 70 * 71 * @see android.content.pm.IPackageManager#getPackagesHoldingPermissions 72 */ 73 ParceledListSlice<PackageInfo> getPackagesHoldingPermissions( 74 String[] permissions, int flags, int userId) throws RemoteException; 75} 76