blob: dcb40b20365edb042bdede889b3b967fcc320804 [file] [log] [blame]
Salvador Martinez3965e022017-02-01 17:17:49 -08001/*
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 */
16package com.android.settingslib.applications;
17
18import android.content.ComponentName;
19import android.content.Intent;
20import android.content.IntentFilter;
21import android.content.pm.ApplicationInfo;
22import android.content.pm.PackageInfo;
23import android.content.pm.PackageManager;
24import android.content.pm.PackageManager.NameNotFoundException;
25import android.content.pm.ResolveInfo;
26import android.graphics.drawable.Drawable;
27import android.os.UserHandle;
28
29import 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 */
36public class PackageManagerWrapperImpl implements PackageManagerWrapper {
37
38 private final PackageManager mPm;
39
40 public PackageManagerWrapperImpl(PackageManager pm) {
41 mPm = pm;
42 }
43
44 @Override
45 public PackageManager getPackageManager() {
46 return mPm;
47 }
48
49 @Override
50 public List<ApplicationInfo> getInstalledApplicationsAsUser(int flags, int userId) {
51 return mPm.getInstalledApplicationsAsUser(flags, userId);
52 }
53
54 @Override
55 public boolean hasSystemFeature(String name) {
56 return mPm.hasSystemFeature(name);
57 }
58
59 @Override
60 public List<ResolveInfo> queryIntentActivitiesAsUser(Intent intent, int flags, int userId) {
61 return mPm.queryIntentActivitiesAsUser(intent, flags, userId);
62 }
63
64 @Override
65 public int getInstallReason(String packageName, UserHandle user) {
66 return mPm.getInstallReason(packageName, user);
67 }
68
69 @Override
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
76 public boolean setDefaultBrowserPackageNameAsUser(String packageName, int userId) {
77 return mPm.setDefaultBrowserPackageNameAsUser(packageName, userId);
78 }
79
80 @Override
81 public String getDefaultBrowserPackageNameAsUser(int userId) {
82 return mPm.getDefaultBrowserPackageNameAsUser(userId);
83 }
84
85 @Override
86 public ComponentName getHomeActivities(List<ResolveInfo> homeActivities) {
87 return mPm.getHomeActivities(homeActivities);
88 }
89
90 @Override
91 public List<ResolveInfo> queryIntentServicesAsUser(Intent intent, int i, int user) {
92 return mPm.queryIntentServicesAsUser(intent, i, user);
93 }
94
95 @Override
96 public void replacePreferredActivity(IntentFilter homeFilter, int matchCategoryEmpty,
97 ComponentName[] componentNames, ComponentName component) {
98 mPm.replacePreferredActivity(homeFilter, matchCategoryEmpty, componentNames, component);
99 }
100
101 @Override
102 public PackageInfo getPackageInfo(String packageName, int i) throws NameNotFoundException {
103 return mPm.getPackageInfo(packageName, i);
104 }
105
106 @Override
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
113 public CharSequence loadLabel(ApplicationInfo app) {
114 return app.loadLabel(mPm);
115 }
Daniel Nishibf8eb3d2017-07-12 10:24:25 -0700116
117 @Override
118 public List<ResolveInfo> queryIntentActivities(Intent intent, int flags) {
119 return mPm.queryIntentActivities(intent, flags);
120 }
Salvador Martinez3965e022017-02-01 17:17:49 -0800121}