• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 package com.android.settingslib.applications;
17 
18 import android.content.ComponentName;
19 import android.content.Intent;
20 import android.content.IntentFilter;
21 import android.content.pm.ApplicationInfo;
22 import android.content.pm.PackageInfo;
23 import android.content.pm.PackageManager;
24 import android.content.pm.PackageManager.NameNotFoundException;
25 import android.content.pm.ResolveInfo;
26 import android.graphics.drawable.Drawable;
27 import android.os.UserHandle;
28 
29 import java.util.List;
30 
31 /**
32  * A thin wrapper class that simplifies testing by putting a mockable layer between the application
33  * and the PackageManager. This class only provides access to the minimum number of functions from
34  * the PackageManager needed for DeletionHelper to work.
35  */
36 public class PackageManagerWrapperImpl implements PackageManagerWrapper {
37 
38     private final PackageManager mPm;
39 
PackageManagerWrapperImpl(PackageManager pm)40     public PackageManagerWrapperImpl(PackageManager pm) {
41         mPm = pm;
42     }
43 
44     @Override
getPackageManager()45     public PackageManager getPackageManager() {
46         return mPm;
47     }
48 
49     @Override
getInstalledApplicationsAsUser(int flags, int userId)50     public List<ApplicationInfo> getInstalledApplicationsAsUser(int flags, int userId) {
51         return mPm.getInstalledApplicationsAsUser(flags, userId);
52     }
53 
54     @Override
hasSystemFeature(String name)55     public boolean hasSystemFeature(String name) {
56         return mPm.hasSystemFeature(name);
57     }
58 
59     @Override
queryIntentActivitiesAsUser(Intent intent, int flags, int userId)60     public List<ResolveInfo> queryIntentActivitiesAsUser(Intent intent, int flags, int userId) {
61         return mPm.queryIntentActivitiesAsUser(intent, flags, userId);
62     }
63 
64     @Override
getInstallReason(String packageName, UserHandle user)65     public int getInstallReason(String packageName, UserHandle user) {
66         return mPm.getInstallReason(packageName, user);
67     }
68 
69     @Override
getApplicationInfoAsUser(String packageName, int i, int userId)70     public ApplicationInfo getApplicationInfoAsUser(String packageName, int i, int userId)
71             throws PackageManager.NameNotFoundException {
72         return mPm.getApplicationInfoAsUser(packageName, i, userId);
73     }
74 
75     @Override
setDefaultBrowserPackageNameAsUser(String packageName, int userId)76     public boolean setDefaultBrowserPackageNameAsUser(String packageName, int userId) {
77         return mPm.setDefaultBrowserPackageNameAsUser(packageName, userId);
78     }
79 
80     @Override
getDefaultBrowserPackageNameAsUser(int userId)81     public String getDefaultBrowserPackageNameAsUser(int userId) {
82         return mPm.getDefaultBrowserPackageNameAsUser(userId);
83     }
84 
85     @Override
getHomeActivities(List<ResolveInfo> homeActivities)86     public ComponentName getHomeActivities(List<ResolveInfo> homeActivities) {
87         return mPm.getHomeActivities(homeActivities);
88     }
89 
90     @Override
queryIntentServicesAsUser(Intent intent, int i, int user)91     public List<ResolveInfo> queryIntentServicesAsUser(Intent intent, int i, int user) {
92         return mPm.queryIntentServicesAsUser(intent, i, user);
93     }
94 
95     @Override
replacePreferredActivity(IntentFilter homeFilter, int matchCategoryEmpty, ComponentName[] componentNames, ComponentName component)96     public void replacePreferredActivity(IntentFilter homeFilter, int matchCategoryEmpty,
97             ComponentName[] componentNames, ComponentName component) {
98         mPm.replacePreferredActivity(homeFilter, matchCategoryEmpty, componentNames, component);
99     }
100 
101     @Override
getPackageInfo(String packageName, int i)102     public PackageInfo getPackageInfo(String packageName, int i) throws NameNotFoundException {
103         return mPm.getPackageInfo(packageName, i);
104     }
105 
106     @Override
getUserBadgedIcon(ApplicationInfo info)107     public Drawable getUserBadgedIcon(ApplicationInfo info) {
108         return mPm.getUserBadgedIcon(mPm.loadUnbadgedItemIcon(info, info),
109                 new UserHandle(UserHandle.getUserId(info.uid)));
110     }
111 
112     @Override
loadLabel(ApplicationInfo app)113     public CharSequence loadLabel(ApplicationInfo app) {
114         return app.loadLabel(mPm);
115     }
116 }
117