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