blob: a6838f8bbf0acac8bcb081c83a4a10934c47be04 [file] [log] [blame]
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001/*
2 * Copyright (C) 2010 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 android.app;
18
Tor Norbye7b9c9122013-05-30 16:48:33 -070019import android.annotation.DrawableRes;
Alan Viveretteecd585a2015-04-13 10:32:51 -070020import android.annotation.NonNull;
21import android.annotation.Nullable;
Tor Norbye7b9c9122013-05-30 16:48:33 -070022import android.annotation.StringRes;
23import android.annotation.XmlRes;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080024import android.content.ComponentName;
25import android.content.ContentResolver;
Yao Chen022b8ea2016-12-16 11:03:28 -080026import android.content.Context;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080027import android.content.Intent;
28import android.content.IntentFilter;
29import android.content.IntentSender;
30import android.content.pm.ActivityInfo;
31import android.content.pm.ApplicationInfo;
Todd Kennedy9106c642017-02-08 14:16:53 -080032import android.content.pm.ChangedPackages;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080033import android.content.pm.ComponentInfo;
Svetoslav Ganov096d3042017-01-30 16:34:13 -080034import android.content.pm.InstantAppInfo;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080035import android.content.pm.FeatureInfo;
Svetoslavf7c06eb2015-06-10 18:43:22 -070036import android.content.pm.IOnPermissionsChangeListener;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080037import android.content.pm.IPackageDataObserver;
38import android.content.pm.IPackageDeleteObserver;
39import android.content.pm.IPackageInstallObserver;
40import android.content.pm.IPackageManager;
41import android.content.pm.IPackageMoveObserver;
42import android.content.pm.IPackageStatsObserver;
43import android.content.pm.InstrumentationInfo;
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -080044import android.content.pm.IntentFilterVerificationInfo;
dcashman9d2f4412014-06-09 09:27:54 -070045import android.content.pm.KeySet;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080046import android.content.pm.PackageInfo;
Jeff Sharkey3a44f3f2014-04-28 17:36:31 -070047import android.content.pm.PackageInstaller;
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +010048import android.content.pm.PackageItemInfo;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080049import android.content.pm.PackageManager;
Kenny Roote6cd0c72011-05-19 12:48:14 -070050import android.content.pm.ParceledListSlice;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080051import android.content.pm.PermissionGroupInfo;
52import android.content.pm.PermissionInfo;
53import android.content.pm.ProviderInfo;
54import android.content.pm.ResolveInfo;
55import android.content.pm.ServiceInfo;
Svet Ganov67882122016-12-11 16:36:34 -080056import android.content.pm.SharedLibraryInfo;
Kenny Root0aaa0d92011-09-12 16:42:55 -070057import android.content.pm.VerifierDeviceIdentity;
Svet Ganov67882122016-12-11 16:36:34 -080058import android.content.pm.VersionedPackage;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080059import android.content.res.Resources;
60import android.content.res.XmlResourceParser;
Svetoslavc7d62f02014-09-04 15:39:54 -070061import android.graphics.Bitmap;
62import android.graphics.Canvas;
63import android.graphics.Rect;
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +010064import android.graphics.drawable.BitmapDrawable;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080065import android.graphics.drawable.Drawable;
Kenny Guy02c89902016-11-15 19:36:38 +000066import android.graphics.drawable.LayerDrawable;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080067import android.net.Uri;
Jeff Sharkeye6306c42017-03-07 21:03:18 -070068import android.os.Build;
Jeff Sharkey50a05452015-04-29 11:24:52 -070069import android.os.Bundle;
Jeff Sharkey620b32b2015-04-23 19:36:02 -070070import android.os.Handler;
71import android.os.Looper;
72import android.os.Message;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080073import android.os.Process;
74import android.os.RemoteException;
Jeff Sharkeyb2b9ab82015-04-05 21:10:42 -070075import android.os.SystemProperties;
Amith Yamasani67df64b2012-12-14 12:09:36 -080076import android.os.UserHandle;
Nicolas Prevot88cc3462014-05-14 14:51:48 +010077import android.os.UserManager;
Jeff Sharkeye2d45be2015-04-15 17:14:12 -070078import android.os.storage.StorageManager;
79import android.os.storage.VolumeInfo;
Todd Kennedyf39ca8f2015-08-07 14:15:07 -070080import android.provider.Settings;
Dianne Hackbornadd005c2013-07-17 18:43:12 -070081import android.util.ArrayMap;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080082import android.util.Log;
Jeff Browna492c3a2012-08-23 19:48:44 -070083import android.view.Display;
Jeff Sharkeyb2b9ab82015-04-05 21:10:42 -070084
85import dalvik.system.VMRuntime;
Jeff Sharkey16c8e3f2014-07-24 17:08:17 -070086
87import com.android.internal.annotations.GuardedBy;
Kenny Guy02c89902016-11-15 19:36:38 +000088import com.android.internal.annotations.VisibleForTesting;
Jeff Sharkeyb36586a2015-04-27 08:42:28 -070089import com.android.internal.os.SomeArgs;
dcashman9d2f4412014-06-09 09:27:54 -070090import com.android.internal.util.Preconditions;
Alexandra Gherghina64d4dca2014-08-28 18:26:56 +010091import com.android.internal.util.UserIcons;
Svet Ganov2acf0632015-11-24 19:10:59 -080092import libcore.util.EmptyArray;
Jeff Sharkey16c8e3f2014-07-24 17:08:17 -070093
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080094import java.lang.ref.WeakReference;
95import java.util.ArrayList;
Svet Ganov2acf0632015-11-24 19:10:59 -080096import java.util.Collections;
Jeff Sharkey620b32b2015-04-23 19:36:02 -070097import java.util.Iterator;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080098import java.util.List;
Svetoslavf7c06eb2015-06-10 18:43:22 -070099import java.util.Map;
Jeff Sharkey620b32b2015-04-23 19:36:02 -0700100import java.util.Objects;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800101
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700102/** @hide */
103public class ApplicationPackageManager extends PackageManager {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800104 private static final String TAG = "ApplicationPackageManager";
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800105 private final static boolean DEBUG_ICONS = false;
106
Svet Ganov2acf0632015-11-24 19:10:59 -0800107 private static final int DEFAULT_EPHEMERAL_COOKIE_MAX_SIZE_BYTES = 16384; // 16KB
108
Adam Lesinskid00bb5e2014-10-07 12:14:45 -0700109 // Default flags to use with PackageManager when no flags are given.
110 private final static int sDefaultFlags = PackageManager.GET_SHARED_LIBRARY_FILES;
111
Jeff Sharkey16c8e3f2014-07-24 17:08:17 -0700112 private final Object mLock = new Object();
113
114 @GuardedBy("mLock")
115 private UserManager mUserManager;
116 @GuardedBy("mLock")
117 private PackageInstaller mInstaller;
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +0100118
Jeff Sharkey620b32b2015-04-23 19:36:02 -0700119 @GuardedBy("mDelegates")
120 private final ArrayList<MoveCallbackDelegate> mDelegates = new ArrayList<>();
121
Svet Ganovf1b7f202015-07-29 08:33:42 -0700122 @GuardedBy("mLock")
123 private String mPermissionsControllerPackageName;
124
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +0100125 UserManager getUserManager() {
Jeff Sharkey16c8e3f2014-07-24 17:08:17 -0700126 synchronized (mLock) {
127 if (mUserManager == null) {
128 mUserManager = UserManager.get(mContext);
129 }
130 return mUserManager;
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +0100131 }
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +0100132 }
133
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800134 @Override
135 public PackageInfo getPackageInfo(String packageName, int flags)
136 throws NameNotFoundException {
Nicolas Prevot9a80e532015-09-23 15:49:28 +0100137 return getPackageInfoAsUser(packageName, flags, mContext.getUserId());
138 }
139
140 @Override
Svet Ganov67882122016-12-11 16:36:34 -0800141 public PackageInfo getPackageInfo(VersionedPackage versionedPackage, int flags)
142 throws NameNotFoundException {
143 try {
144 PackageInfo pi = mPM.getPackageInfoVersioned(versionedPackage, flags,
145 mContext.getUserId());
146 if (pi != null) {
147 return pi;
148 }
149 } catch (RemoteException e) {
150 throw e.rethrowFromSystemServer();
151 }
152 throw new NameNotFoundException(versionedPackage.toString());
153 }
154
155 @Override
Nicolas Prevot9a80e532015-09-23 15:49:28 +0100156 public PackageInfo getPackageInfoAsUser(String packageName, int flags, int userId)
157 throws NameNotFoundException {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800158 try {
Nicolas Prevot9a80e532015-09-23 15:49:28 +0100159 PackageInfo pi = mPM.getPackageInfo(packageName, flags, userId);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800160 if (pi != null) {
161 return pi;
162 }
163 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700164 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800165 }
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800166 throw new NameNotFoundException(packageName);
167 }
168
169 @Override
170 public String[] currentToCanonicalPackageNames(String[] names) {
171 try {
172 return mPM.currentToCanonicalPackageNames(names);
173 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700174 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800175 }
176 }
177
178 @Override
179 public String[] canonicalToCurrentPackageNames(String[] names) {
180 try {
181 return mPM.canonicalToCurrentPackageNames(names);
182 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700183 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800184 }
185 }
186
187 @Override
188 public Intent getLaunchIntentForPackage(String packageName) {
189 // First see if the package has an INFO activity; the existence of
190 // such an activity is implied to be the desired front-door for the
191 // overall package (such as if it has multiple launcher entries).
192 Intent intentToResolve = new Intent(Intent.ACTION_MAIN);
193 intentToResolve.addCategory(Intent.CATEGORY_INFO);
194 intentToResolve.setPackage(packageName);
Dianne Hackborn19415762010-12-15 00:20:27 -0800195 List<ResolveInfo> ris = queryIntentActivities(intentToResolve, 0);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800196
197 // Otherwise, try to find a main launcher activity.
Dianne Hackborn19415762010-12-15 00:20:27 -0800198 if (ris == null || ris.size() <= 0) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800199 // reuse the intent instance
200 intentToResolve.removeCategory(Intent.CATEGORY_INFO);
201 intentToResolve.addCategory(Intent.CATEGORY_LAUNCHER);
202 intentToResolve.setPackage(packageName);
Dianne Hackborn19415762010-12-15 00:20:27 -0800203 ris = queryIntentActivities(intentToResolve, 0);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800204 }
Dianne Hackborn19415762010-12-15 00:20:27 -0800205 if (ris == null || ris.size() <= 0) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800206 return null;
207 }
208 Intent intent = new Intent(intentToResolve);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800209 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Dianne Hackborn19415762010-12-15 00:20:27 -0800210 intent.setClassName(ris.get(0).activityInfo.packageName,
211 ris.get(0).activityInfo.name);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800212 return intent;
213 }
214
215 @Override
Jose Lima970417c2014-04-10 10:42:19 -0700216 public Intent getLeanbackLaunchIntentForPackage(String packageName) {
217 // Try to find a main leanback_launcher activity.
218 Intent intentToResolve = new Intent(Intent.ACTION_MAIN);
219 intentToResolve.addCategory(Intent.CATEGORY_LEANBACK_LAUNCHER);
220 intentToResolve.setPackage(packageName);
221 List<ResolveInfo> ris = queryIntentActivities(intentToResolve, 0);
222
223 if (ris == null || ris.size() <= 0) {
224 return null;
225 }
226 Intent intent = new Intent(intentToResolve);
227 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
228 intent.setClassName(ris.get(0).activityInfo.packageName,
229 ris.get(0).activityInfo.name);
230 return intent;
231 }
232
233 @Override
Jeff Sharkey8588bc12016-01-06 16:47:42 -0700234 public int[] getPackageGids(String packageName) throws NameNotFoundException {
235 return getPackageGids(packageName, 0);
236 }
237
238 @Override
239 public int[] getPackageGids(String packageName, int flags)
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800240 throws NameNotFoundException {
241 try {
Jeff Sharkeycd654482016-01-08 17:42:11 -0700242 int[] gids = mPM.getPackageGids(packageName, flags, mContext.getUserId());
Svetoslavc6d1c342015-02-26 14:44:43 -0800243 if (gids != null) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800244 return gids;
245 }
246 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700247 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800248 }
249
250 throw new NameNotFoundException(packageName);
251 }
252
253 @Override
Jeff Sharkey8588bc12016-01-06 16:47:42 -0700254 public int getPackageUid(String packageName, int flags) throws NameNotFoundException {
255 return getPackageUidAsUser(packageName, flags, mContext.getUserId());
256 }
257
258 @Override
259 public int getPackageUidAsUser(String packageName, int userId) throws NameNotFoundException {
260 return getPackageUidAsUser(packageName, 0, userId);
261 }
262
263 @Override
264 public int getPackageUidAsUser(String packageName, int flags, int userId)
Dianne Hackborna06de0f2012-12-11 16:34:47 -0800265 throws NameNotFoundException {
266 try {
Jeff Sharkeycd654482016-01-08 17:42:11 -0700267 int uid = mPM.getPackageUid(packageName, flags, userId);
Dianne Hackborna06de0f2012-12-11 16:34:47 -0800268 if (uid >= 0) {
269 return uid;
270 }
271 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700272 throw e.rethrowFromSystemServer();
Dianne Hackborna06de0f2012-12-11 16:34:47 -0800273 }
274
275 throw new NameNotFoundException(packageName);
276 }
277
278 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800279 public PermissionInfo getPermissionInfo(String name, int flags)
280 throws NameNotFoundException {
281 try {
282 PermissionInfo pi = mPM.getPermissionInfo(name, flags);
283 if (pi != null) {
284 return pi;
285 }
286 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700287 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800288 }
289
290 throw new NameNotFoundException(name);
291 }
292
293 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700294 @SuppressWarnings("unchecked")
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800295 public List<PermissionInfo> queryPermissionsByGroup(String group, int flags)
296 throws NameNotFoundException {
297 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700298 ParceledListSlice<PermissionInfo> parceledList =
299 mPM.queryPermissionsByGroup(group, flags);
300 if (parceledList != null) {
301 List<PermissionInfo> pi = parceledList.getList();
302 if (pi != null) {
303 return pi;
304 }
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800305 }
306 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700307 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800308 }
309
310 throw new NameNotFoundException(group);
311 }
312
313 @Override
Paul Navin7b89a7b2017-01-26 23:56:08 +0000314 public boolean isPermissionReviewModeEnabled() {
315 return mContext.getResources().getBoolean(
316 com.android.internal.R.bool.config_permissionReviewRequired);
317 }
318
319 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800320 public PermissionGroupInfo getPermissionGroupInfo(String name,
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700321 int flags) throws NameNotFoundException {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800322 try {
323 PermissionGroupInfo pgi = mPM.getPermissionGroupInfo(name, flags);
324 if (pgi != null) {
325 return pgi;
326 }
327 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700328 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800329 }
330
331 throw new NameNotFoundException(name);
332 }
333
334 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700335 @SuppressWarnings("unchecked")
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800336 public List<PermissionGroupInfo> getAllPermissionGroups(int flags) {
337 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700338 ParceledListSlice<PermissionGroupInfo> parceledList =
339 mPM.getAllPermissionGroups(flags);
340 if (parceledList == null) {
341 return Collections.emptyList();
342 }
343 return parceledList.getList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800344 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700345 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800346 }
347 }
348
349 @Override
350 public ApplicationInfo getApplicationInfo(String packageName, int flags)
351 throws NameNotFoundException {
Jeff Sharkeycd654482016-01-08 17:42:11 -0700352 return getApplicationInfoAsUser(packageName, flags, mContext.getUserId());
353 }
354
355 @Override
356 public ApplicationInfo getApplicationInfoAsUser(String packageName, int flags, int userId)
357 throws NameNotFoundException {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800358 try {
Jeff Sharkeycd654482016-01-08 17:42:11 -0700359 ApplicationInfo ai = mPM.getApplicationInfo(packageName, flags, userId);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800360 if (ai != null) {
Narayan Kamathcaa71192014-07-16 11:06:43 +0100361 // This is a temporary hack. Callers must use
362 // createPackageContext(packageName).getApplicationInfo() to
363 // get the right paths.
Tao Baic9a02372016-01-12 15:02:24 -0800364 return maybeAdjustApplicationInfo(ai);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800365 }
366 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700367 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800368 }
369
370 throw new NameNotFoundException(packageName);
371 }
372
Tao Baic9a02372016-01-12 15:02:24 -0800373 private static ApplicationInfo maybeAdjustApplicationInfo(ApplicationInfo info) {
Narayan Kamathcaa71192014-07-16 11:06:43 +0100374 // If we're dealing with a multi-arch application that has both
375 // 32 and 64 bit shared libraries, we might need to choose the secondary
376 // depending on what the current runtime's instruction set is.
377 if (info.primaryCpuAbi != null && info.secondaryCpuAbi != null) {
378 final String runtimeIsa = VMRuntime.getRuntime().vmInstructionSet();
jgu214741cd92014-12-17 17:23:29 -0500379
380 // Get the instruction set that the libraries of secondary Abi is supported.
381 // In presence of a native bridge this might be different than the one secondary Abi used.
382 String secondaryIsa = VMRuntime.getInstructionSet(info.secondaryCpuAbi);
383 final String secondaryDexCodeIsa = SystemProperties.get("ro.dalvik.vm.isa." + secondaryIsa);
384 secondaryIsa = secondaryDexCodeIsa.isEmpty() ? secondaryIsa : secondaryDexCodeIsa;
Narayan Kamathcaa71192014-07-16 11:06:43 +0100385
386 // If the runtimeIsa is the same as the primary isa, then we do nothing.
387 // Everything will be set up correctly because info.nativeLibraryDir will
388 // correspond to the right ISA.
389 if (runtimeIsa.equals(secondaryIsa)) {
Tao Baic9a02372016-01-12 15:02:24 -0800390 ApplicationInfo modified = new ApplicationInfo(info);
391 modified.nativeLibraryDir = info.secondaryNativeLibraryDir;
392 return modified;
Narayan Kamathcaa71192014-07-16 11:06:43 +0100393 }
394 }
Tao Baic9a02372016-01-12 15:02:24 -0800395 return info;
Narayan Kamathcaa71192014-07-16 11:06:43 +0100396 }
397
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800398 @Override
399 public ActivityInfo getActivityInfo(ComponentName className, int flags)
400 throws NameNotFoundException {
401 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700402 ActivityInfo ai = mPM.getActivityInfo(className, flags, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800403 if (ai != null) {
404 return ai;
405 }
406 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700407 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800408 }
409
410 throw new NameNotFoundException(className.toString());
411 }
412
413 @Override
414 public ActivityInfo getReceiverInfo(ComponentName className, int flags)
415 throws NameNotFoundException {
416 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700417 ActivityInfo ai = mPM.getReceiverInfo(className, flags, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800418 if (ai != null) {
419 return ai;
420 }
421 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700422 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800423 }
424
425 throw new NameNotFoundException(className.toString());
426 }
427
428 @Override
429 public ServiceInfo getServiceInfo(ComponentName className, int flags)
430 throws NameNotFoundException {
431 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700432 ServiceInfo si = mPM.getServiceInfo(className, flags, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800433 if (si != null) {
434 return si;
435 }
436 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700437 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800438 }
439
440 throw new NameNotFoundException(className.toString());
441 }
442
443 @Override
444 public ProviderInfo getProviderInfo(ComponentName className, int flags)
445 throws NameNotFoundException {
446 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700447 ProviderInfo pi = mPM.getProviderInfo(className, flags, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800448 if (pi != null) {
449 return pi;
450 }
451 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700452 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800453 }
454
455 throw new NameNotFoundException(className.toString());
456 }
457
458 @Override
459 public String[] getSystemSharedLibraryNames() {
460 try {
461 return mPM.getSystemSharedLibraryNames();
462 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700463 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800464 }
465 }
466
Svet Ganovd7b1f4112016-02-09 18:49:23 -0800467 /** @hide */
468 @Override
Svet Ganov67882122016-12-11 16:36:34 -0800469 public @NonNull List<SharedLibraryInfo> getSharedLibraries(int flags) {
470 return getSharedLibrariesAsUser(flags, mContext.getUserId());
471 }
472
473 /** @hide */
474 @Override
475 @SuppressWarnings("unchecked")
476 public @NonNull List<SharedLibraryInfo> getSharedLibrariesAsUser(int flags, int userId) {
477 try {
478 ParceledListSlice<SharedLibraryInfo> sharedLibs = mPM.getSharedLibraries(
479 flags, userId);
480 if (sharedLibs == null) {
481 return Collections.emptyList();
482 }
483 return sharedLibs.getList();
484 } catch (RemoteException e) {
485 throw e.rethrowFromSystemServer();
486 }
487 }
488
489 /** @hide */
490 @Override
Svetoslav Ganova9c25002016-04-13 19:25:56 -0700491 public @NonNull String getServicesSystemSharedLibraryPackageName() {
Svet Ganovd7b1f4112016-02-09 18:49:23 -0800492 try {
493 return mPM.getServicesSystemSharedLibraryPackageName();
494 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700495 throw e.rethrowFromSystemServer();
Svet Ganovd7b1f4112016-02-09 18:49:23 -0800496 }
497 }
498
Svetoslav Ganova9c25002016-04-13 19:25:56 -0700499 /**
500 * @hide
501 */
502 public @NonNull String getSharedSystemSharedLibraryPackageName() {
503 try {
504 return mPM.getSharedSystemSharedLibraryPackageName();
505 } catch (RemoteException e) {
506 throw e.rethrowFromSystemServer();
507 }
508 }
509
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800510 @Override
Todd Kennedy9106c642017-02-08 14:16:53 -0800511 public ChangedPackages getChangedPackages(int sequenceNumber) {
512 try {
513 return mPM.getChangedPackages(sequenceNumber, mContext.getUserId());
514 } catch (RemoteException e) {
515 throw e.rethrowFromSystemServer();
516 }
517 }
518
519 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700520 @SuppressWarnings("unchecked")
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800521 public FeatureInfo[] getSystemAvailableFeatures() {
522 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700523 ParceledListSlice<FeatureInfo> parceledList =
524 mPM.getSystemAvailableFeatures();
525 if (parceledList == null) {
526 return new FeatureInfo[0];
527 }
528 final List<FeatureInfo> list = parceledList.getList();
Jeff Sharkeyd5896632016-03-04 16:16:00 -0700529 final FeatureInfo[] res = new FeatureInfo[list.size()];
530 for (int i = 0; i < res.length; i++) {
531 res[i] = list.get(i);
532 }
533 return res;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800534 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700535 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800536 }
537 }
538
539 @Override
540 public boolean hasSystemFeature(String name) {
Jeff Sharkey115d2c12016-02-15 17:25:57 -0700541 return hasSystemFeature(name, 0);
542 }
543
544 @Override
545 public boolean hasSystemFeature(String name, int version) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800546 try {
Jeff Sharkey115d2c12016-02-15 17:25:57 -0700547 return mPM.hasSystemFeature(name, version);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800548 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700549 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800550 }
551 }
552
553 @Override
554 public int checkPermission(String permName, String pkgName) {
555 try {
Svetoslavc6d1c342015-02-26 14:44:43 -0800556 return mPM.checkPermission(permName, pkgName, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800557 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700558 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800559 }
560 }
561
562 @Override
Svet Ganovad3b2972015-07-07 22:49:17 -0700563 public boolean isPermissionRevokedByPolicy(String permName, String pkgName) {
564 try {
565 return mPM.isPermissionRevokedByPolicy(permName, pkgName, mContext.getUserId());
566 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700567 throw e.rethrowFromSystemServer();
Svet Ganovad3b2972015-07-07 22:49:17 -0700568 }
569 }
570
Svet Ganovf1b7f202015-07-29 08:33:42 -0700571 /**
572 * @hide
573 */
574 @Override
575 public String getPermissionControllerPackageName() {
576 synchronized (mLock) {
577 if (mPermissionsControllerPackageName == null) {
578 try {
579 mPermissionsControllerPackageName = mPM.getPermissionControllerPackageName();
580 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700581 throw e.rethrowFromSystemServer();
Svet Ganovf1b7f202015-07-29 08:33:42 -0700582 }
583 }
584 return mPermissionsControllerPackageName;
585 }
586 }
587
Svet Ganovad3b2972015-07-07 22:49:17 -0700588 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800589 public boolean addPermission(PermissionInfo info) {
590 try {
591 return mPM.addPermission(info);
592 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700593 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800594 }
595 }
596
597 @Override
598 public boolean addPermissionAsync(PermissionInfo info) {
599 try {
600 return mPM.addPermissionAsync(info);
601 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700602 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800603 }
604 }
605
606 @Override
607 public void removePermission(String name) {
608 try {
609 mPM.removePermission(name);
610 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700611 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800612 }
613 }
614
615 @Override
Svet Ganov8c7f7002015-05-07 10:48:44 -0700616 public void grantRuntimePermission(String packageName, String permissionName,
617 UserHandle user) {
Dianne Hackborne639da72012-02-21 15:11:13 -0800618 try {
Svet Ganov8c7f7002015-05-07 10:48:44 -0700619 mPM.grantRuntimePermission(packageName, permissionName, user.getIdentifier());
Dianne Hackborne639da72012-02-21 15:11:13 -0800620 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700621 throw e.rethrowFromSystemServer();
Dianne Hackborne639da72012-02-21 15:11:13 -0800622 }
623 }
624
625 @Override
Svet Ganov8c7f7002015-05-07 10:48:44 -0700626 public void revokeRuntimePermission(String packageName, String permissionName,
627 UserHandle user) {
Dianne Hackborne639da72012-02-21 15:11:13 -0800628 try {
Svet Ganov8c7f7002015-05-07 10:48:44 -0700629 mPM.revokeRuntimePermission(packageName, permissionName, user.getIdentifier());
630 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700631 throw e.rethrowFromSystemServer();
Svet Ganov8c7f7002015-05-07 10:48:44 -0700632 }
633 }
634
635 @Override
636 public int getPermissionFlags(String permissionName, String packageName, UserHandle user) {
637 try {
638 return mPM.getPermissionFlags(permissionName, packageName, user.getIdentifier());
639 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700640 throw e.rethrowFromSystemServer();
Svet Ganov8c7f7002015-05-07 10:48:44 -0700641 }
642 }
643
644 @Override
645 public void updatePermissionFlags(String permissionName, String packageName,
646 int flagMask, int flagValues, UserHandle user) {
647 try {
648 mPM.updatePermissionFlags(permissionName, packageName, flagMask,
649 flagValues, user.getIdentifier());
Dianne Hackborne639da72012-02-21 15:11:13 -0800650 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700651 throw e.rethrowFromSystemServer();
Dianne Hackborne639da72012-02-21 15:11:13 -0800652 }
653 }
654
655 @Override
Svetoslav20770dd2015-05-29 15:43:04 -0700656 public boolean shouldShowRequestPermissionRationale(String permission) {
657 try {
658 return mPM.shouldShowRequestPermissionRationale(permission,
659 mContext.getPackageName(), mContext.getUserId());
660 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700661 throw e.rethrowFromSystemServer();
Svetoslav20770dd2015-05-29 15:43:04 -0700662 }
663 }
664
665 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800666 public int checkSignatures(String pkg1, String pkg2) {
667 try {
668 return mPM.checkSignatures(pkg1, pkg2);
669 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700670 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800671 }
672 }
673
674 @Override
675 public int checkSignatures(int uid1, int uid2) {
676 try {
677 return mPM.checkUidSignatures(uid1, uid2);
678 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700679 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800680 }
681 }
682
683 @Override
684 public String[] getPackagesForUid(int uid) {
685 try {
686 return mPM.getPackagesForUid(uid);
687 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700688 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800689 }
690 }
691
692 @Override
693 public String getNameForUid(int uid) {
694 try {
695 return mPM.getNameForUid(uid);
696 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700697 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800698 }
699 }
700
701 @Override
702 public int getUidForSharedUser(String sharedUserName)
703 throws NameNotFoundException {
704 try {
705 int uid = mPM.getUidForSharedUser(sharedUserName);
706 if(uid != -1) {
707 return uid;
708 }
709 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700710 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800711 }
712 throw new NameNotFoundException("No shared userid for user:"+sharedUserName);
713 }
714
Kenny Roote6cd0c72011-05-19 12:48:14 -0700715 @SuppressWarnings("unchecked")
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800716 @Override
717 public List<PackageInfo> getInstalledPackages(int flags) {
Jeff Sharkeye06b4d12016-01-06 14:51:50 -0700718 return getInstalledPackagesAsUser(flags, mContext.getUserId());
Amith Yamasani151ec4c2012-09-07 19:25:16 -0700719 }
720
721 /** @hide */
722 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700723 @SuppressWarnings("unchecked")
Jeff Sharkeye06b4d12016-01-06 14:51:50 -0700724 public List<PackageInfo> getInstalledPackagesAsUser(int flags, int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800725 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700726 ParceledListSlice<PackageInfo> parceledList =
727 mPM.getInstalledPackages(flags, userId);
728 if (parceledList == null) {
729 return Collections.emptyList();
730 }
731 return parceledList.getList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800732 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700733 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800734 }
735 }
736
Kenny Roote6cd0c72011-05-19 12:48:14 -0700737 @SuppressWarnings("unchecked")
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800738 @Override
Dianne Hackborne7991752013-01-16 17:56:46 -0800739 public List<PackageInfo> getPackagesHoldingPermissions(
740 String[] permissions, int flags) {
741 final int userId = mContext.getUserId();
742 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700743 ParceledListSlice<PackageInfo> parceledList =
744 mPM.getPackagesHoldingPermissions(permissions, flags, userId);
745 if (parceledList == null) {
746 return Collections.emptyList();
747 }
748 return parceledList.getList();
Dianne Hackborne7991752013-01-16 17:56:46 -0800749 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700750 throw e.rethrowFromSystemServer();
Dianne Hackborne7991752013-01-16 17:56:46 -0800751 }
752 }
753
754 @SuppressWarnings("unchecked")
755 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800756 public List<ApplicationInfo> getInstalledApplications(int flags) {
Bartosz Fabianowski11334242016-11-17 20:49:16 +0100757 return getInstalledApplicationsAsUser(flags, mContext.getUserId());
758 }
759
760 /** @hide */
761 @SuppressWarnings("unchecked")
762 @Override
763 public List<ApplicationInfo> getInstalledApplicationsAsUser(int flags, int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800764 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700765 ParceledListSlice<ApplicationInfo> parceledList =
766 mPM.getInstalledApplications(flags, userId);
767 if (parceledList == null) {
768 return Collections.emptyList();
769 }
770 return parceledList.getList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800771 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700772 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800773 }
774 }
775
Svet Ganov2acf0632015-11-24 19:10:59 -0800776 /** @hide */
777 @SuppressWarnings("unchecked")
778 @Override
Svetoslav Ganov096d3042017-01-30 16:34:13 -0800779 public List<InstantAppInfo> getInstantApps() {
Svet Ganov2acf0632015-11-24 19:10:59 -0800780 try {
Svetoslav Ganov096d3042017-01-30 16:34:13 -0800781 ParceledListSlice<InstantAppInfo> slice =
782 mPM.getInstantApps(mContext.getUserId());
Svet Ganov2acf0632015-11-24 19:10:59 -0800783 if (slice != null) {
784 return slice.getList();
785 }
786 return Collections.emptyList();
787 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700788 throw e.rethrowFromSystemServer();
Svet Ganov2acf0632015-11-24 19:10:59 -0800789 }
790 }
791
792 /** @hide */
793 @Override
Svetoslav Ganov096d3042017-01-30 16:34:13 -0800794 public Drawable getInstantAppIcon(String packageName) {
Svet Ganov2acf0632015-11-24 19:10:59 -0800795 try {
Svetoslav Ganov096d3042017-01-30 16:34:13 -0800796 Bitmap bitmap = mPM.getInstantAppIcon(
Svet Ganov2acf0632015-11-24 19:10:59 -0800797 packageName, mContext.getUserId());
798 if (bitmap != null) {
799 return new BitmapDrawable(null, bitmap);
800 }
801 return null;
802 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700803 throw e.rethrowFromSystemServer();
Svet Ganov2acf0632015-11-24 19:10:59 -0800804 }
805 }
806
807 @Override
Svetoslav Ganov096d3042017-01-30 16:34:13 -0800808 public boolean isInstantApp() {
David Christie31a16552017-03-01 15:08:45 -0800809 return isInstantApp(mContext.getPackageName());
810 }
811
812 @Override
813 public boolean isInstantApp(String packageName) {
Svet Ganov2acf0632015-11-24 19:10:59 -0800814 try {
David Christie31a16552017-03-01 15:08:45 -0800815 return mPM.isInstantApp(packageName, mContext.getUserId());
Svet Ganov2acf0632015-11-24 19:10:59 -0800816 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700817 throw e.rethrowFromSystemServer();
Svet Ganov2acf0632015-11-24 19:10:59 -0800818 }
Svet Ganov2acf0632015-11-24 19:10:59 -0800819 }
820
821 @Override
Svetoslav Ganov096d3042017-01-30 16:34:13 -0800822 public int getInstantAppCookieMaxSize() {
Svet Ganov2acf0632015-11-24 19:10:59 -0800823 return Settings.Global.getInt(mContext.getContentResolver(),
824 Settings.Global.EPHEMERAL_COOKIE_MAX_SIZE_BYTES,
825 DEFAULT_EPHEMERAL_COOKIE_MAX_SIZE_BYTES);
826 }
827
828 @Override
Svetoslav Ganov096d3042017-01-30 16:34:13 -0800829 public @NonNull byte[] getInstantAppCookie() {
Svet Ganov2acf0632015-11-24 19:10:59 -0800830 try {
Svetoslav Ganov096d3042017-01-30 16:34:13 -0800831 final byte[] cookie = mPM.getInstantAppCookie(
Svet Ganov2acf0632015-11-24 19:10:59 -0800832 mContext.getPackageName(), mContext.getUserId());
833 if (cookie != null) {
834 return cookie;
Jeff Sharkey27b2e692016-02-25 17:40:12 -0700835 } else {
836 return EmptyArray.BYTE;
Svet Ganov2acf0632015-11-24 19:10:59 -0800837 }
838 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700839 throw e.rethrowFromSystemServer();
Svet Ganov2acf0632015-11-24 19:10:59 -0800840 }
Svet Ganov2acf0632015-11-24 19:10:59 -0800841 }
842
843 @Override
Svetoslav Ganov096d3042017-01-30 16:34:13 -0800844 public boolean setInstantAppCookie(@NonNull byte[] cookie) {
Svet Ganov2acf0632015-11-24 19:10:59 -0800845 try {
Svetoslav Ganov096d3042017-01-30 16:34:13 -0800846 return mPM.setInstantAppCookie(mContext.getPackageName(),
847 cookie, mContext.getUserId());
Svet Ganov2acf0632015-11-24 19:10:59 -0800848 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700849 throw e.rethrowFromSystemServer();
Svet Ganov2acf0632015-11-24 19:10:59 -0800850 }
Svet Ganov2acf0632015-11-24 19:10:59 -0800851 }
852
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800853 @Override
854 public ResolveInfo resolveActivity(Intent intent, int flags) {
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700855 return resolveActivityAsUser(intent, flags, mContext.getUserId());
Svetoslav Ganov58d37b52012-09-18 12:04:19 -0700856 }
857
858 @Override
859 public ResolveInfo resolveActivityAsUser(Intent intent, int flags, int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800860 try {
861 return mPM.resolveIntent(
862 intent,
863 intent.resolveTypeIfNeeded(mContext.getContentResolver()),
Svetoslav Ganov58d37b52012-09-18 12:04:19 -0700864 flags,
865 userId);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800866 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700867 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800868 }
869 }
870
871 @Override
872 public List<ResolveInfo> queryIntentActivities(Intent intent,
873 int flags) {
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700874 return queryIntentActivitiesAsUser(intent, flags, mContext.getUserId());
Amith Yamasani151ec4c2012-09-07 19:25:16 -0700875 }
876
877 /** @hide Same as above but for a specific user */
878 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700879 @SuppressWarnings("unchecked")
Svetoslav Ganov58d37b52012-09-18 12:04:19 -0700880 public List<ResolveInfo> queryIntentActivitiesAsUser(Intent intent,
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700881 int flags, int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800882 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700883 ParceledListSlice<ResolveInfo> parceledList =
884 mPM.queryIntentActivities(intent,
885 intent.resolveTypeIfNeeded(mContext.getContentResolver()),
886 flags, userId);
887 if (parceledList == null) {
888 return Collections.emptyList();
889 }
890 return parceledList.getList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800891 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700892 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800893 }
894 }
895
896 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700897 @SuppressWarnings("unchecked")
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800898 public List<ResolveInfo> queryIntentActivityOptions(
899 ComponentName caller, Intent[] specifics, Intent intent,
900 int flags) {
901 final ContentResolver resolver = mContext.getContentResolver();
902
903 String[] specificTypes = null;
904 if (specifics != null) {
905 final int N = specifics.length;
906 for (int i=0; i<N; i++) {
907 Intent sp = specifics[i];
908 if (sp != null) {
909 String t = sp.resolveTypeIfNeeded(resolver);
910 if (t != null) {
911 if (specificTypes == null) {
912 specificTypes = new String[N];
913 }
914 specificTypes[i] = t;
915 }
916 }
917 }
918 }
919
920 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700921 ParceledListSlice<ResolveInfo> parceledList =
922 mPM.queryIntentActivityOptions(caller, specifics, specificTypes, intent,
923 intent.resolveTypeIfNeeded(resolver), flags, mContext.getUserId());
924 if (parceledList == null) {
925 return Collections.emptyList();
926 }
927 return parceledList.getList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800928 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700929 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800930 }
931 }
932
Amith Yamasanif203aee2012-08-29 18:41:53 -0700933 /**
934 * @hide
935 */
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800936 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700937 @SuppressWarnings("unchecked")
Jeff Sharkeye06b4d12016-01-06 14:51:50 -0700938 public List<ResolveInfo> queryBroadcastReceiversAsUser(Intent intent, int flags, int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800939 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700940 ParceledListSlice<ResolveInfo> parceledList =
941 mPM.queryIntentReceivers(intent,
942 intent.resolveTypeIfNeeded(mContext.getContentResolver()),
943 flags, userId);
944 if (parceledList == null) {
945 return Collections.emptyList();
946 }
947 return parceledList.getList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800948 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700949 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800950 }
951 }
952
953 @Override
Amith Yamasanif203aee2012-08-29 18:41:53 -0700954 public List<ResolveInfo> queryBroadcastReceivers(Intent intent, int flags) {
Jeff Sharkeye06b4d12016-01-06 14:51:50 -0700955 return queryBroadcastReceiversAsUser(intent, flags, mContext.getUserId());
Amith Yamasanif203aee2012-08-29 18:41:53 -0700956 }
957
958 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800959 public ResolveInfo resolveService(Intent intent, int flags) {
960 try {
961 return mPM.resolveService(
962 intent,
963 intent.resolveTypeIfNeeded(mContext.getContentResolver()),
Amith Yamasani483f3b02012-03-13 16:08:00 -0700964 flags,
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700965 mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800966 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700967 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800968 }
969 }
970
971 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700972 @SuppressWarnings("unchecked")
Svetoslav Ganov58d37b52012-09-18 12:04:19 -0700973 public List<ResolveInfo> queryIntentServicesAsUser(Intent intent, int flags, int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800974 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700975 ParceledListSlice<ResolveInfo> parceledList =
976 mPM.queryIntentServices(intent,
977 intent.resolveTypeIfNeeded(mContext.getContentResolver()),
978 flags, userId);
979 if (parceledList == null) {
980 return Collections.emptyList();
981 }
982 return parceledList.getList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800983 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700984 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800985 }
986 }
987
988 @Override
Svetoslav Ganov58d37b52012-09-18 12:04:19 -0700989 public List<ResolveInfo> queryIntentServices(Intent intent, int flags) {
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700990 return queryIntentServicesAsUser(intent, flags, mContext.getUserId());
Svetoslav Ganov58d37b52012-09-18 12:04:19 -0700991 }
992
993 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700994 @SuppressWarnings("unchecked")
Jeff Sharkey85f5f812013-10-07 10:16:12 -0700995 public List<ResolveInfo> queryIntentContentProvidersAsUser(
996 Intent intent, int flags, int userId) {
997 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700998 ParceledListSlice<ResolveInfo> parceledList =
999 mPM.queryIntentContentProviders(intent,
1000 intent.resolveTypeIfNeeded(mContext.getContentResolver()),
1001 flags, userId);
1002 if (parceledList == null) {
1003 return Collections.emptyList();
1004 }
1005 return parceledList.getList();
Jeff Sharkey85f5f812013-10-07 10:16:12 -07001006 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001007 throw e.rethrowFromSystemServer();
Jeff Sharkey85f5f812013-10-07 10:16:12 -07001008 }
1009 }
1010
1011 @Override
1012 public List<ResolveInfo> queryIntentContentProviders(Intent intent, int flags) {
1013 return queryIntentContentProvidersAsUser(intent, flags, mContext.getUserId());
1014 }
1015
1016 @Override
Alexandra Gherghina0363c3e2014-06-23 13:34:59 +01001017 public ProviderInfo resolveContentProvider(String name, int flags) {
1018 return resolveContentProviderAsUser(name, flags, mContext.getUserId());
1019 }
1020
1021 /** @hide **/
1022 @Override
1023 public ProviderInfo resolveContentProviderAsUser(String name, int flags, int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001024 try {
Alexandra Gherghina0363c3e2014-06-23 13:34:59 +01001025 return mPM.resolveContentProvider(name, flags, userId);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001026 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001027 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001028 }
1029 }
1030
1031 @Override
1032 public List<ProviderInfo> queryContentProviders(String processName,
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001033 int uid, int flags) {
Makoto Onuki32757292017-02-22 14:36:59 -08001034 return queryContentProviders(processName, uid, flags, null);
1035 }
1036
1037 @Override
1038 @SuppressWarnings("unchecked")
1039 public List<ProviderInfo> queryContentProviders(String processName,
1040 int uid, int flags, String metaDataKey) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001041 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001042 ParceledListSlice<ProviderInfo> slice =
Makoto Onuki32757292017-02-22 14:36:59 -08001043 mPM.queryContentProviders(processName, uid, flags, metaDataKey);
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001044 return slice != null ? slice.getList() : Collections.<ProviderInfo>emptyList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001045 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001046 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001047 }
1048 }
1049
1050 @Override
1051 public InstrumentationInfo getInstrumentationInfo(
1052 ComponentName className, int flags)
1053 throws NameNotFoundException {
1054 try {
1055 InstrumentationInfo ii = mPM.getInstrumentationInfo(
1056 className, flags);
1057 if (ii != null) {
1058 return ii;
1059 }
1060 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001061 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001062 }
1063
1064 throw new NameNotFoundException(className.toString());
1065 }
1066
1067 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001068 @SuppressWarnings("unchecked")
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001069 public List<InstrumentationInfo> queryInstrumentation(
1070 String targetPackage, int flags) {
1071 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001072 ParceledListSlice<InstrumentationInfo> parceledList =
1073 mPM.queryInstrumentation(targetPackage, flags);
1074 if (parceledList == null) {
1075 return Collections.emptyList();
1076 }
1077 return parceledList.getList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001078 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001079 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001080 }
1081 }
1082
Alan Viveretteecd585a2015-04-13 10:32:51 -07001083 @Nullable
1084 @Override
1085 public Drawable getDrawable(String packageName, @DrawableRes int resId,
1086 @Nullable ApplicationInfo appInfo) {
1087 final ResourceName name = new ResourceName(packageName, resId);
1088 final Drawable cachedIcon = getCachedIcon(name);
1089 if (cachedIcon != null) {
1090 return cachedIcon;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001091 }
Alan Viveretteecd585a2015-04-13 10:32:51 -07001092
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001093 if (appInfo == null) {
1094 try {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001095 appInfo = getApplicationInfo(packageName, sDefaultFlags);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001096 } catch (NameNotFoundException e) {
1097 return null;
1098 }
1099 }
Alan Viveretteecd585a2015-04-13 10:32:51 -07001100
1101 if (resId != 0) {
1102 try {
1103 final Resources r = getResourcesForApplication(appInfo);
1104 final Drawable dr = r.getDrawable(resId, null);
1105 if (dr != null) {
1106 putCachedIcon(name, dr);
1107 }
1108
1109 if (false) {
1110 RuntimeException e = new RuntimeException("here");
1111 e.fillInStackTrace();
1112 Log.w(TAG, "Getting drawable 0x" + Integer.toHexString(resId)
1113 + " from package " + packageName
1114 + ": app scale=" + r.getCompatibilityInfo().applicationScale
1115 + ", caller scale=" + mContext.getResources()
1116 .getCompatibilityInfo().applicationScale,
1117 e);
1118 }
Ricky Wai3ce46252015-04-15 16:12:22 +01001119 if (DEBUG_ICONS) {
Alan Viveretteecd585a2015-04-13 10:32:51 -07001120 Log.v(TAG, "Getting drawable 0x"
1121 + Integer.toHexString(resId) + " from " + r
1122 + ": " + dr);
Ricky Wai3ce46252015-04-15 16:12:22 +01001123 }
1124 return dr;
Alan Viveretteecd585a2015-04-13 10:32:51 -07001125 } catch (NameNotFoundException e) {
1126 Log.w("PackageManager", "Failure retrieving resources for "
1127 + appInfo.packageName);
1128 } catch (Resources.NotFoundException e) {
1129 Log.w("PackageManager", "Failure retrieving resources for "
1130 + appInfo.packageName + ": " + e.getMessage());
1131 } catch (Exception e) {
1132 // If an exception was thrown, fall through to return
1133 // default icon.
1134 Log.w("PackageManager", "Failure retrieving icon 0x"
1135 + Integer.toHexString(resId) + " in package "
1136 + packageName, e);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001137 }
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001138 }
Alan Viveretteecd585a2015-04-13 10:32:51 -07001139
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001140 return null;
1141 }
1142
1143 @Override public Drawable getActivityIcon(ComponentName activityName)
1144 throws NameNotFoundException {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001145 return getActivityInfo(activityName, sDefaultFlags).loadIcon(this);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001146 }
1147
1148 @Override public Drawable getActivityIcon(Intent intent)
1149 throws NameNotFoundException {
1150 if (intent.getComponent() != null) {
1151 return getActivityIcon(intent.getComponent());
1152 }
1153
1154 ResolveInfo info = resolveActivity(
1155 intent, PackageManager.MATCH_DEFAULT_ONLY);
1156 if (info != null) {
1157 return info.activityInfo.loadIcon(this);
1158 }
1159
Romain Guy39fe17c2011-11-30 10:34:07 -08001160 throw new NameNotFoundException(intent.toUri(0));
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001161 }
1162
1163 @Override public Drawable getDefaultActivityIcon() {
1164 return Resources.getSystem().getDrawable(
1165 com.android.internal.R.drawable.sym_def_app_icon);
1166 }
1167
1168 @Override public Drawable getApplicationIcon(ApplicationInfo info) {
1169 return info.loadIcon(this);
1170 }
1171
1172 @Override public Drawable getApplicationIcon(String packageName)
1173 throws NameNotFoundException {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001174 return getApplicationIcon(getApplicationInfo(packageName, sDefaultFlags));
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001175 }
1176
1177 @Override
Jose Limaf78e3122014-03-06 12:13:15 -08001178 public Drawable getActivityBanner(ComponentName activityName)
1179 throws NameNotFoundException {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001180 return getActivityInfo(activityName, sDefaultFlags).loadBanner(this);
Jose Limaf78e3122014-03-06 12:13:15 -08001181 }
1182
1183 @Override
1184 public Drawable getActivityBanner(Intent intent)
1185 throws NameNotFoundException {
1186 if (intent.getComponent() != null) {
1187 return getActivityBanner(intent.getComponent());
1188 }
1189
1190 ResolveInfo info = resolveActivity(
1191 intent, PackageManager.MATCH_DEFAULT_ONLY);
1192 if (info != null) {
1193 return info.activityInfo.loadBanner(this);
1194 }
1195
1196 throw new NameNotFoundException(intent.toUri(0));
1197 }
1198
1199 @Override
1200 public Drawable getApplicationBanner(ApplicationInfo info) {
1201 return info.loadBanner(this);
1202 }
1203
1204 @Override
1205 public Drawable getApplicationBanner(String packageName)
1206 throws NameNotFoundException {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001207 return getApplicationBanner(getApplicationInfo(packageName, sDefaultFlags));
Jose Limaf78e3122014-03-06 12:13:15 -08001208 }
1209
1210 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001211 public Drawable getActivityLogo(ComponentName activityName)
1212 throws NameNotFoundException {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001213 return getActivityInfo(activityName, sDefaultFlags).loadLogo(this);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001214 }
1215
1216 @Override
1217 public Drawable getActivityLogo(Intent intent)
1218 throws NameNotFoundException {
1219 if (intent.getComponent() != null) {
1220 return getActivityLogo(intent.getComponent());
1221 }
1222
1223 ResolveInfo info = resolveActivity(
1224 intent, PackageManager.MATCH_DEFAULT_ONLY);
1225 if (info != null) {
1226 return info.activityInfo.loadLogo(this);
1227 }
1228
1229 throw new NameNotFoundException(intent.toUri(0));
1230 }
1231
1232 @Override
1233 public Drawable getApplicationLogo(ApplicationInfo info) {
1234 return info.loadLogo(this);
1235 }
1236
1237 @Override
1238 public Drawable getApplicationLogo(String packageName)
1239 throws NameNotFoundException {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001240 return getApplicationLogo(getApplicationInfo(packageName, sDefaultFlags));
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001241 }
1242
Svetoslavc7d62f02014-09-04 15:39:54 -07001243 @Override
1244 public Drawable getUserBadgedIcon(Drawable icon, UserHandle user) {
Kenny Guy02c89902016-11-15 19:36:38 +00001245 if (!isManagedProfile(user.getIdentifier())) {
Svetoslavc7d62f02014-09-04 15:39:54 -07001246 return icon;
1247 }
Kenny Guy02c89902016-11-15 19:36:38 +00001248 Drawable badgeShadow = getDrawable("system",
1249 com.android.internal.R.drawable.ic_corp_icon_badge_shadow, null);
1250 Drawable badgeColor = getDrawable("system",
1251 com.android.internal.R.drawable.ic_corp_icon_badge_color, null);
1252 badgeColor.setTint(getUserBadgeColor(user));
1253 Drawable badgeForeground = getDrawable("system",
1254 com.android.internal.R.drawable.ic_corp_icon_badge_case, null);
1255
1256 Drawable badge = new LayerDrawable(
1257 new Drawable[] {badgeShadow, badgeColor, badgeForeground });
1258 return getBadgedDrawable(icon, badge, null, true);
Svetoslavc7d62f02014-09-04 15:39:54 -07001259 }
1260
1261 @Override
1262 public Drawable getUserBadgedDrawableForDensity(Drawable drawable, UserHandle user,
1263 Rect badgeLocation, int badgeDensity) {
1264 Drawable badgeDrawable = getUserBadgeForDensity(user, badgeDensity);
1265 if (badgeDrawable == null) {
1266 return drawable;
1267 }
1268 return getBadgedDrawable(drawable, badgeDrawable, badgeLocation, true);
1269 }
1270
Kenny Guy02c89902016-11-15 19:36:38 +00001271 // Should have enough colors to cope with UserManagerService.getMaxManagedProfiles()
1272 @VisibleForTesting
1273 public static final int[] CORP_BADGE_COLORS = new int[] {
1274 com.android.internal.R.color.profile_badge_1,
1275 com.android.internal.R.color.profile_badge_2,
1276 com.android.internal.R.color.profile_badge_3
1277 };
1278
1279 @VisibleForTesting
1280 public static final int[] CORP_BADGE_LABEL_RES_ID = new int[] {
1281 com.android.internal.R.string.managed_profile_label_badge,
1282 com.android.internal.R.string.managed_profile_label_badge_2,
1283 com.android.internal.R.string.managed_profile_label_badge_3
1284 };
1285
1286 private int getUserBadgeColor(UserHandle user) {
1287 int badge = getUserManager().getManagedProfileBadge(user.getIdentifier());
1288 if (badge < 0) {
1289 badge = 0;
1290 }
1291 int resourceId = CORP_BADGE_COLORS[badge % CORP_BADGE_COLORS.length];
1292 return Resources.getSystem().getColor(resourceId, null);
1293 }
1294
Svetoslavc7d62f02014-09-04 15:39:54 -07001295 @Override
1296 public Drawable getUserBadgeForDensity(UserHandle user, int density) {
Kenny Guy02c89902016-11-15 19:36:38 +00001297 Drawable badgeColor = getManagedProfileIconForDensity(user,
1298 com.android.internal.R.drawable.ic_corp_badge_color, density);
1299 if (badgeColor == null) {
1300 return null;
1301 }
1302 badgeColor.setTint(getUserBadgeColor(user));
1303 Drawable badgeForeground = getDrawableForDensity(
1304 com.android.internal.R.drawable.ic_corp_badge_case, density);
1305 Drawable badge = new LayerDrawable(
1306 new Drawable[] {badgeColor, badgeForeground });
1307 return badge;
Selim Cineke6ff9462016-01-15 15:07:06 -08001308 }
1309
1310 @Override
1311 public Drawable getUserBadgeForDensityNoBackground(UserHandle user, int density) {
Kenny Guy02c89902016-11-15 19:36:38 +00001312 Drawable badge = getManagedProfileIconForDensity(user,
Vadim Tryshev66ae66a2016-02-18 15:41:21 -08001313 com.android.internal.R.drawable.ic_corp_badge_no_background, density);
Kenny Guy02c89902016-11-15 19:36:38 +00001314 if (badge != null) {
1315 badge.setTint(getUserBadgeColor(user));
1316 }
1317 return badge;
Selim Cineke6ff9462016-01-15 15:07:06 -08001318 }
1319
Vadim Tryshev66ae66a2016-02-18 15:41:21 -08001320 private Drawable getDrawableForDensity(int drawableId, int density) {
1321 if (density <= 0) {
1322 density = mContext.getResources().getDisplayMetrics().densityDpi;
1323 }
1324 return Resources.getSystem().getDrawableForDensity(drawableId, density);
1325 }
1326
1327 private Drawable getManagedProfileIconForDensity(UserHandle user, int drawableId, int density) {
Tony Mak8673b282016-03-21 21:10:59 +00001328 if (isManagedProfile(user.getIdentifier())) {
Vadim Tryshev66ae66a2016-02-18 15:41:21 -08001329 return getDrawableForDensity(drawableId, density);
Svetoslavc7d62f02014-09-04 15:39:54 -07001330 }
1331 return null;
1332 }
1333
1334 @Override
1335 public CharSequence getUserBadgedLabel(CharSequence label, UserHandle user) {
Tony Mak8673b282016-03-21 21:10:59 +00001336 if (isManagedProfile(user.getIdentifier())) {
Kenny Guy02c89902016-11-15 19:36:38 +00001337 int badge = getUserManager().getManagedProfileBadge(user.getIdentifier());
1338 int resourceId = CORP_BADGE_LABEL_RES_ID[badge % CORP_BADGE_LABEL_RES_ID.length];
1339 return Resources.getSystem().getString(resourceId, label);
Svetoslavc7d62f02014-09-04 15:39:54 -07001340 }
1341 return label;
1342 }
1343
Alan Viveretteecd585a2015-04-13 10:32:51 -07001344 @Override
1345 public Resources getResourcesForActivity(ComponentName activityName)
1346 throws NameNotFoundException {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001347 return getResourcesForApplication(
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001348 getActivityInfo(activityName, sDefaultFlags).applicationInfo);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001349 }
1350
Alan Viveretteecd585a2015-04-13 10:32:51 -07001351 @Override
1352 public Resources getResourcesForApplication(@NonNull ApplicationInfo app)
1353 throws NameNotFoundException {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001354 if (app.packageName.equals("system")) {
Adam Lesinskia82b6262017-03-21 16:56:17 -07001355 return mContext.mMainThread.getSystemUiContext().getResources();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001356 }
Jeff Sharkey8a4c9722014-06-16 13:48:42 -07001357 final boolean sameUid = (app.uid == Process.myUid());
Adam Lesinski53fafdf2016-08-03 13:36:39 -07001358 final Resources r = mContext.mMainThread.getTopLevelResources(
Adam Lesinskic82f28a2016-06-08 17:19:09 -07001359 sameUid ? app.sourceDir : app.publicSourceDir,
1360 sameUid ? app.splitSourceDirs : app.splitPublicSourceDirs,
1361 app.resourceDirs, app.sharedLibraryFiles, Display.DEFAULT_DISPLAY,
1362 mContext.mPackageInfo);
Adam Lesinski53fafdf2016-08-03 13:36:39 -07001363 if (r != null) {
1364 return r;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001365 }
Adam Lesinski53fafdf2016-08-03 13:36:39 -07001366 throw new NameNotFoundException("Unable to open " + app.publicSourceDir);
1367
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001368 }
1369
Alan Viveretteecd585a2015-04-13 10:32:51 -07001370 @Override
1371 public Resources getResourcesForApplication(String appPackageName)
1372 throws NameNotFoundException {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001373 return getResourcesForApplication(
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001374 getApplicationInfo(appPackageName, sDefaultFlags));
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001375 }
1376
Amith Yamasani98edc952012-09-25 14:09:27 -07001377 /** @hide */
1378 @Override
1379 public Resources getResourcesForApplicationAsUser(String appPackageName, int userId)
1380 throws NameNotFoundException {
Jeff Sharkeyded653b2012-09-27 19:09:24 -07001381 if (userId < 0) {
1382 throw new IllegalArgumentException(
1383 "Call does not support special user #" + userId);
1384 }
1385 if ("system".equals(appPackageName)) {
Adam Lesinskia82b6262017-03-21 16:56:17 -07001386 return mContext.mMainThread.getSystemUiContext().getResources();
Jeff Sharkeyded653b2012-09-27 19:09:24 -07001387 }
Amith Yamasani98edc952012-09-25 14:09:27 -07001388 try {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001389 ApplicationInfo ai = mPM.getApplicationInfo(appPackageName, sDefaultFlags, userId);
Amith Yamasani98edc952012-09-25 14:09:27 -07001390 if (ai != null) {
1391 return getResourcesForApplication(ai);
1392 }
1393 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001394 throw e.rethrowFromSystemServer();
Amith Yamasani98edc952012-09-25 14:09:27 -07001395 }
1396 throw new NameNotFoundException("Package " + appPackageName + " doesn't exist");
1397 }
1398
Jeff Sharkeycd654482016-01-08 17:42:11 -07001399 volatile int mCachedSafeMode = -1;
1400
1401 @Override
1402 public boolean isSafeMode() {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001403 try {
1404 if (mCachedSafeMode < 0) {
1405 mCachedSafeMode = mPM.isSafeMode() ? 1 : 0;
1406 }
1407 return mCachedSafeMode != 0;
1408 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001409 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001410 }
1411 }
1412
Svetoslavf7c06eb2015-06-10 18:43:22 -07001413 @Override
1414 public void addOnPermissionsChangeListener(OnPermissionsChangedListener listener) {
1415 synchronized (mPermissionListeners) {
1416 if (mPermissionListeners.get(listener) != null) {
1417 return;
1418 }
1419 OnPermissionsChangeListenerDelegate delegate =
1420 new OnPermissionsChangeListenerDelegate(listener, Looper.getMainLooper());
1421 try {
1422 mPM.addOnPermissionsChangeListener(delegate);
1423 mPermissionListeners.put(listener, delegate);
1424 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001425 throw e.rethrowFromSystemServer();
Svetoslavf7c06eb2015-06-10 18:43:22 -07001426 }
1427 }
1428 }
1429
1430 @Override
1431 public void removeOnPermissionsChangeListener(OnPermissionsChangedListener listener) {
1432 synchronized (mPermissionListeners) {
1433 IOnPermissionsChangeListener delegate = mPermissionListeners.get(listener);
1434 if (delegate != null) {
1435 try {
1436 mPM.removeOnPermissionsChangeListener(delegate);
1437 mPermissionListeners.remove(listener);
1438 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001439 throw e.rethrowFromSystemServer();
Svetoslavf7c06eb2015-06-10 18:43:22 -07001440 }
1441 }
1442 }
1443 }
1444
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001445 static void configurationChanged() {
1446 synchronized (sSync) {
1447 sIconCache.clear();
1448 sStringCache.clear();
1449 }
1450 }
1451
Yao Chen022b8ea2016-12-16 11:03:28 -08001452 protected ApplicationPackageManager(ContextImpl context,
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001453 IPackageManager pm) {
1454 mContext = context;
1455 mPM = pm;
1456 }
1457
Alan Viveretteecd585a2015-04-13 10:32:51 -07001458 @Nullable
1459 private Drawable getCachedIcon(@NonNull ResourceName name) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001460 synchronized (sSync) {
Alan Viveretteecd585a2015-04-13 10:32:51 -07001461 final WeakReference<Drawable.ConstantState> wr = sIconCache.get(name);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001462 if (DEBUG_ICONS) Log.v(TAG, "Get cached weak drawable ref for "
1463 + name + ": " + wr);
1464 if (wr != null) { // we have the activity
Alan Viveretteecd585a2015-04-13 10:32:51 -07001465 final Drawable.ConstantState state = wr.get();
Romain Guy39fe17c2011-11-30 10:34:07 -08001466 if (state != null) {
1467 if (DEBUG_ICONS) {
1468 Log.v(TAG, "Get cached drawable state for " + name + ": " + state);
1469 }
1470 // Note: It's okay here to not use the newDrawable(Resources) variant
1471 // of the API. The ConstantState comes from a drawable that was
1472 // originally created by passing the proper app Resources instance
1473 // which means the state should already contain the proper
1474 // resources specific information (like density.) See
1475 // BitmapDrawable.BitmapState for instance.
1476 return state.newDrawable();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001477 }
1478 // our entry has been purged
1479 sIconCache.remove(name);
1480 }
1481 }
1482 return null;
1483 }
1484
Alan Viveretteecd585a2015-04-13 10:32:51 -07001485 private void putCachedIcon(@NonNull ResourceName name, @NonNull Drawable dr) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001486 synchronized (sSync) {
Alan Viveretteecd585a2015-04-13 10:32:51 -07001487 sIconCache.put(name, new WeakReference<>(dr.getConstantState()));
Romain Guy39fe17c2011-11-30 10:34:07 -08001488 if (DEBUG_ICONS) Log.v(TAG, "Added cached drawable state for " + name + ": " + dr);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001489 }
1490 }
1491
Romain Guy39fe17c2011-11-30 10:34:07 -08001492 static void handlePackageBroadcast(int cmd, String[] pkgList, boolean hasPkgInfo) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001493 boolean immediateGc = false;
Sudheer Shankacc6418f2016-10-13 12:03:44 -07001494 if (cmd == ApplicationThreadConstants.EXTERNAL_STORAGE_UNAVAILABLE) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001495 immediateGc = true;
1496 }
1497 if (pkgList != null && (pkgList.length > 0)) {
1498 boolean needCleanup = false;
1499 for (String ssp : pkgList) {
1500 synchronized (sSync) {
Dianne Hackbornadd005c2013-07-17 18:43:12 -07001501 for (int i=sIconCache.size()-1; i>=0; i--) {
1502 ResourceName nm = sIconCache.keyAt(i);
1503 if (nm.packageName.equals(ssp)) {
1504 //Log.i(TAG, "Removing cached drawable for " + nm);
1505 sIconCache.removeAt(i);
1506 needCleanup = true;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001507 }
1508 }
Dianne Hackbornadd005c2013-07-17 18:43:12 -07001509 for (int i=sStringCache.size()-1; i>=0; i--) {
1510 ResourceName nm = sStringCache.keyAt(i);
1511 if (nm.packageName.equals(ssp)) {
1512 //Log.i(TAG, "Removing cached string for " + nm);
1513 sStringCache.removeAt(i);
1514 needCleanup = true;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001515 }
1516 }
1517 }
1518 }
1519 if (needCleanup || hasPkgInfo) {
1520 if (immediateGc) {
1521 // Schedule an immediate gc.
1522 Runtime.getRuntime().gc();
1523 } else {
1524 ActivityThread.currentActivityThread().scheduleGcIdler();
1525 }
1526 }
1527 }
1528 }
1529
1530 private static final class ResourceName {
1531 final String packageName;
1532 final int iconId;
1533
1534 ResourceName(String _packageName, int _iconId) {
1535 packageName = _packageName;
1536 iconId = _iconId;
1537 }
1538
1539 ResourceName(ApplicationInfo aInfo, int _iconId) {
1540 this(aInfo.packageName, _iconId);
1541 }
1542
1543 ResourceName(ComponentInfo cInfo, int _iconId) {
1544 this(cInfo.applicationInfo.packageName, _iconId);
1545 }
1546
1547 ResourceName(ResolveInfo rInfo, int _iconId) {
1548 this(rInfo.activityInfo.applicationInfo.packageName, _iconId);
1549 }
1550
1551 @Override
1552 public boolean equals(Object o) {
1553 if (this == o) return true;
1554 if (o == null || getClass() != o.getClass()) return false;
1555
1556 ResourceName that = (ResourceName) o;
1557
1558 if (iconId != that.iconId) return false;
1559 return !(packageName != null ?
1560 !packageName.equals(that.packageName) : that.packageName != null);
1561
1562 }
1563
1564 @Override
1565 public int hashCode() {
1566 int result;
1567 result = packageName.hashCode();
1568 result = 31 * result + iconId;
1569 return result;
1570 }
1571
1572 @Override
1573 public String toString() {
1574 return "{ResourceName " + packageName + " / " + iconId + "}";
1575 }
1576 }
1577
1578 private CharSequence getCachedString(ResourceName name) {
1579 synchronized (sSync) {
1580 WeakReference<CharSequence> wr = sStringCache.get(name);
1581 if (wr != null) { // we have the activity
1582 CharSequence cs = wr.get();
1583 if (cs != null) {
1584 return cs;
1585 }
1586 // our entry has been purged
1587 sStringCache.remove(name);
1588 }
1589 }
1590 return null;
1591 }
1592
1593 private void putCachedString(ResourceName name, CharSequence cs) {
1594 synchronized (sSync) {
1595 sStringCache.put(name, new WeakReference<CharSequence>(cs));
1596 }
1597 }
1598
1599 @Override
Tor Norbye7b9c9122013-05-30 16:48:33 -07001600 public CharSequence getText(String packageName, @StringRes int resid,
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001601 ApplicationInfo appInfo) {
1602 ResourceName name = new ResourceName(packageName, resid);
1603 CharSequence text = getCachedString(name);
1604 if (text != null) {
1605 return text;
1606 }
1607 if (appInfo == null) {
1608 try {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001609 appInfo = getApplicationInfo(packageName, sDefaultFlags);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001610 } catch (NameNotFoundException e) {
1611 return null;
1612 }
1613 }
1614 try {
1615 Resources r = getResourcesForApplication(appInfo);
1616 text = r.getText(resid);
1617 putCachedString(name, text);
1618 return text;
1619 } catch (NameNotFoundException e) {
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07001620 Log.w("PackageManager", "Failure retrieving resources for "
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001621 + appInfo.packageName);
1622 } catch (RuntimeException e) {
1623 // If an exception was thrown, fall through to return
1624 // default icon.
1625 Log.w("PackageManager", "Failure retrieving text 0x"
1626 + Integer.toHexString(resid) + " in package "
1627 + packageName, e);
1628 }
1629 return null;
1630 }
1631
1632 @Override
Tor Norbye7b9c9122013-05-30 16:48:33 -07001633 public XmlResourceParser getXml(String packageName, @XmlRes int resid,
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001634 ApplicationInfo appInfo) {
1635 if (appInfo == null) {
1636 try {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001637 appInfo = getApplicationInfo(packageName, sDefaultFlags);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001638 } catch (NameNotFoundException e) {
1639 return null;
1640 }
1641 }
1642 try {
1643 Resources r = getResourcesForApplication(appInfo);
1644 return r.getXml(resid);
1645 } catch (RuntimeException e) {
1646 // If an exception was thrown, fall through to return
1647 // default icon.
1648 Log.w("PackageManager", "Failure retrieving xml 0x"
1649 + Integer.toHexString(resid) + " in package "
1650 + packageName, e);
1651 } catch (NameNotFoundException e) {
Alon Albert3fa51e32010-11-11 09:24:04 -08001652 Log.w("PackageManager", "Failure retrieving resources for "
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001653 + appInfo.packageName);
1654 }
1655 return null;
1656 }
1657
1658 @Override
1659 public CharSequence getApplicationLabel(ApplicationInfo info) {
1660 return info.loadLabel(this);
1661 }
1662
1663 @Override
1664 public void installPackage(Uri packageURI, IPackageInstallObserver observer, int flags,
1665 String installerPackageName) {
Jeff Sharkey513a0742014-07-08 17:10:32 -07001666 installCommon(packageURI, new LegacyPackageInstallObserver(observer), flags,
Todd Kennedya6793232016-02-24 22:46:00 +00001667 installerPackageName, mContext.getUserId());
Christopher Tatef1977b42014-03-24 16:25:51 -07001668 }
1669
Christopher Tatef1977b42014-03-24 16:25:51 -07001670 @Override
1671 public void installPackage(Uri packageURI, PackageInstallObserver observer,
1672 int flags, String installerPackageName) {
Todd Kennedya6793232016-02-24 22:46:00 +00001673 installCommon(packageURI, observer, flags, installerPackageName, mContext.getUserId());
Jeff Sharkey513a0742014-07-08 17:10:32 -07001674 }
1675
1676 private void installCommon(Uri packageURI,
1677 PackageInstallObserver observer, int flags, String installerPackageName,
Nicolas Prevot9a80e532015-09-23 15:49:28 +01001678 int userId) {
Jeff Sharkey513a0742014-07-08 17:10:32 -07001679 if (!"file".equals(packageURI.getScheme())) {
1680 throw new UnsupportedOperationException("Only file:// URIs are supported");
1681 }
Jeff Sharkey513a0742014-07-08 17:10:32 -07001682
1683 final String originPath = packageURI.getPath();
Christopher Tatef1977b42014-03-24 16:25:51 -07001684 try {
Nicolas Prevot9a80e532015-09-23 15:49:28 +01001685 mPM.installPackageAsUser(originPath, observer.getBinder(), flags, installerPackageName,
Todd Kennedya6793232016-02-24 22:46:00 +00001686 userId);
Jeff Sharkey27b2e692016-02-25 17:40:12 -07001687 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001688 throw e.rethrowFromSystemServer();
rich cannings706e8ba2012-08-20 13:20:14 -07001689 }
1690 }
1691
1692 @Override
Nicolas Prevot9a80e532015-09-23 15:49:28 +01001693 public int installExistingPackage(String packageName) throws NameNotFoundException {
Robin Lee0e27c872015-09-28 14:37:40 +01001694 return installExistingPackageAsUser(packageName, mContext.getUserId());
Nicolas Prevot9a80e532015-09-23 15:49:28 +01001695 }
1696
1697 @Override
1698 public int installExistingPackageAsUser(String packageName, int userId)
Dianne Hackborn7767eac2012-08-23 18:25:40 -07001699 throws NameNotFoundException {
1700 try {
Todd Kennedybe0b8892017-02-15 14:13:52 -08001701 int res = mPM.installExistingPackageAsUser(packageName, userId, 0 /*installFlags*/,
Bartosz Fabianowskia34f53f2017-01-11 18:08:47 +01001702 PackageManager.INSTALL_REASON_UNKNOWN);
Dianne Hackborn7767eac2012-08-23 18:25:40 -07001703 if (res == INSTALL_FAILED_INVALID_URI) {
1704 throw new NameNotFoundException("Package " + packageName + " doesn't exist");
1705 }
1706 return res;
1707 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001708 throw e.rethrowFromSystemServer();
Dianne Hackborn7767eac2012-08-23 18:25:40 -07001709 }
1710 }
1711
1712 @Override
Kenny Root3a9b5fb2011-09-20 14:15:38 -07001713 public void verifyPendingInstall(int id, int response) {
Kenny Root5ab21572011-07-27 11:11:19 -07001714 try {
Kenny Root3a9b5fb2011-09-20 14:15:38 -07001715 mPM.verifyPendingInstall(id, response);
Kenny Root5ab21572011-07-27 11:11:19 -07001716 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001717 throw e.rethrowFromSystemServer();
Kenny Root5ab21572011-07-27 11:11:19 -07001718 }
1719 }
1720
1721 @Override
rich canningsd9ef3e52012-08-22 14:28:05 -07001722 public void extendVerificationTimeout(int id, int verificationCodeAtTimeout,
1723 long millisecondsToDelay) {
1724 try {
1725 mPM.extendVerificationTimeout(id, verificationCodeAtTimeout, millisecondsToDelay);
1726 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001727 throw e.rethrowFromSystemServer();
rich canningsd9ef3e52012-08-22 14:28:05 -07001728 }
1729 }
1730
1731 @Override
Todd Kennedydfa93ab2016-03-03 15:24:33 -08001732 public void verifyIntentFilter(int id, int verificationCode, List<String> failedDomains) {
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001733 try {
Todd Kennedydfa93ab2016-03-03 15:24:33 -08001734 mPM.verifyIntentFilter(id, verificationCode, failedDomains);
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001735 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001736 throw e.rethrowFromSystemServer();
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001737 }
1738 }
1739
1740 @Override
Jeff Sharkeye06b4d12016-01-06 14:51:50 -07001741 public int getIntentVerificationStatusAsUser(String packageName, int userId) {
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001742 try {
1743 return mPM.getIntentVerificationStatus(packageName, userId);
1744 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001745 throw e.rethrowFromSystemServer();
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001746 }
1747 }
1748
1749 @Override
Jeff Sharkeye06b4d12016-01-06 14:51:50 -07001750 public boolean updateIntentVerificationStatusAsUser(String packageName, int status, int userId) {
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001751 try {
1752 return mPM.updateIntentVerificationStatus(packageName, status, userId);
1753 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001754 throw e.rethrowFromSystemServer();
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001755 }
1756 }
1757
1758 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001759 @SuppressWarnings("unchecked")
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001760 public List<IntentFilterVerificationInfo> getIntentFilterVerifications(String packageName) {
1761 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001762 ParceledListSlice<IntentFilterVerificationInfo> parceledList =
1763 mPM.getIntentFilterVerifications(packageName);
1764 if (parceledList == null) {
1765 return Collections.emptyList();
1766 }
1767 return parceledList.getList();
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001768 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001769 throw e.rethrowFromSystemServer();
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001770 }
1771 }
1772
1773 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001774 @SuppressWarnings("unchecked")
Fabrice Di Meglio07885952015-04-06 19:41:28 -07001775 public List<IntentFilter> getAllIntentFilters(String packageName) {
1776 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001777 ParceledListSlice<IntentFilter> parceledList =
1778 mPM.getAllIntentFilters(packageName);
1779 if (parceledList == null) {
1780 return Collections.emptyList();
1781 }
1782 return parceledList.getList();
Fabrice Di Meglio07885952015-04-06 19:41:28 -07001783 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001784 throw e.rethrowFromSystemServer();
Fabrice Di Meglio07885952015-04-06 19:41:28 -07001785 }
1786 }
1787
1788 @Override
Jeff Sharkeye06b4d12016-01-06 14:51:50 -07001789 public String getDefaultBrowserPackageNameAsUser(int userId) {
Fabrice Di Meglio62271722015-04-10 17:24:02 -07001790 try {
1791 return mPM.getDefaultBrowserPackageName(userId);
1792 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001793 throw e.rethrowFromSystemServer();
Fabrice Di Meglio62271722015-04-10 17:24:02 -07001794 }
1795 }
1796
1797 @Override
Jeff Sharkeye06b4d12016-01-06 14:51:50 -07001798 public boolean setDefaultBrowserPackageNameAsUser(String packageName, int userId) {
Fabrice Di Meglio62271722015-04-10 17:24:02 -07001799 try {
1800 return mPM.setDefaultBrowserPackageName(packageName, userId);
1801 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001802 throw e.rethrowFromSystemServer();
Fabrice Di Meglio62271722015-04-10 17:24:02 -07001803 }
1804 }
1805
1806 @Override
Dianne Hackborn880119b2010-11-18 22:26:40 -08001807 public void setInstallerPackageName(String targetPackage,
1808 String installerPackageName) {
1809 try {
1810 mPM.setInstallerPackageName(targetPackage, installerPackageName);
1811 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001812 throw e.rethrowFromSystemServer();
Dianne Hackborn880119b2010-11-18 22:26:40 -08001813 }
1814 }
1815
1816 @Override
Todd Kennedyab532892017-03-08 14:19:49 -08001817 public void setUpdateAvailable(String packageName, boolean updateAvailable) {
1818 try {
1819 mPM.setUpdateAvailable(packageName, updateAvailable);
1820 } catch (RemoteException e) {
1821 throw e.rethrowFromSystemServer();
1822 }
1823 }
1824
1825 @Override
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001826 public String getInstallerPackageName(String packageName) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001827 try {
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001828 return mPM.getInstallerPackageName(packageName);
1829 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001830 throw e.rethrowFromSystemServer();
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001831 }
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001832 }
1833
1834 @Override
1835 public int getMoveStatus(int moveId) {
1836 try {
1837 return mPM.getMoveStatus(moveId);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001838 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001839 throw e.rethrowFromSystemServer();
Jeff Sharkeyb2b9ab82015-04-05 21:10:42 -07001840 }
1841 }
1842
1843 @Override
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001844 public void registerMoveCallback(MoveCallback callback, Handler handler) {
1845 synchronized (mDelegates) {
1846 final MoveCallbackDelegate delegate = new MoveCallbackDelegate(callback,
1847 handler.getLooper());
1848 try {
1849 mPM.registerMoveCallback(delegate);
1850 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001851 throw e.rethrowFromSystemServer();
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001852 }
1853 mDelegates.add(delegate);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001854 }
1855 }
1856
1857 @Override
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001858 public void unregisterMoveCallback(MoveCallback callback) {
1859 synchronized (mDelegates) {
1860 for (Iterator<MoveCallbackDelegate> i = mDelegates.iterator(); i.hasNext();) {
1861 final MoveCallbackDelegate delegate = i.next();
1862 if (delegate.mCallback == callback) {
1863 try {
1864 mPM.unregisterMoveCallback(delegate);
1865 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001866 throw e.rethrowFromSystemServer();
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001867 }
1868 i.remove();
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001869 }
1870 }
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001871 }
1872 }
1873
1874 @Override
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001875 public int movePackage(String packageName, VolumeInfo vol) {
1876 try {
1877 final String volumeUuid;
1878 if (VolumeInfo.ID_PRIVATE_INTERNAL.equals(vol.id)) {
1879 volumeUuid = StorageManager.UUID_PRIVATE_INTERNAL;
1880 } else if (vol.isPrimaryPhysical()) {
1881 volumeUuid = StorageManager.UUID_PRIMARY_PHYSICAL;
1882 } else {
1883 volumeUuid = Preconditions.checkNotNull(vol.fsUuid);
1884 }
1885
1886 return mPM.movePackage(packageName, volumeUuid);
1887 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001888 throw e.rethrowFromSystemServer();
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001889 }
1890 }
1891
1892 @Override
1893 public @Nullable VolumeInfo getPackageCurrentVolume(ApplicationInfo app) {
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001894 final StorageManager storage = mContext.getSystemService(StorageManager.class);
Yao Chen022b8ea2016-12-16 11:03:28 -08001895 return getPackageCurrentVolume(app, storage);
1896 }
1897
1898 @VisibleForTesting
1899 protected @Nullable VolumeInfo getPackageCurrentVolume(ApplicationInfo app,
1900 StorageManager storage) {
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001901 if (app.isInternal()) {
1902 return storage.findVolumeById(VolumeInfo.ID_PRIVATE_INTERNAL);
1903 } else if (app.isExternalAsec()) {
1904 return storage.getPrimaryPhysicalVolume();
1905 } else {
1906 return storage.findVolumeByUuid(app.volumeUuid);
1907 }
1908 }
1909
1910 @Override
1911 public @NonNull List<VolumeInfo> getPackageCandidateVolumes(ApplicationInfo app) {
Yao Chen022b8ea2016-12-16 11:03:28 -08001912 final StorageManager storageManager = mContext.getSystemService(StorageManager.class);
1913 return getPackageCandidateVolumes(app, storageManager, mPM);
1914 }
1915
1916 @VisibleForTesting
1917 protected @NonNull List<VolumeInfo> getPackageCandidateVolumes(ApplicationInfo app,
1918 StorageManager storageManager, IPackageManager pm) {
1919 final VolumeInfo currentVol = getPackageCurrentVolume(app, storageManager);
1920 final List<VolumeInfo> vols = storageManager.getVolumes();
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001921 final List<VolumeInfo> candidates = new ArrayList<>();
1922 for (VolumeInfo vol : vols) {
Yao Chen022b8ea2016-12-16 11:03:28 -08001923 if (Objects.equals(vol, currentVol)
1924 || isPackageCandidateVolume(mContext, app, vol, pm)) {
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001925 candidates.add(vol);
1926 }
1927 }
1928 return candidates;
1929 }
1930
Yao Chen022b8ea2016-12-16 11:03:28 -08001931 @VisibleForTesting
1932 protected boolean isForceAllowOnExternal(Context context) {
1933 return Settings.Global.getInt(
Todd Kennedyf39ca8f2015-08-07 14:15:07 -07001934 context.getContentResolver(), Settings.Global.FORCE_ALLOW_ON_EXTERNAL, 0) != 0;
Yao Chen022b8ea2016-12-16 11:03:28 -08001935 }
1936
1937 @VisibleForTesting
1938 protected boolean isAllow3rdPartyOnInternal(Context context) {
1939 return context.getResources().getBoolean(
1940 com.android.internal.R.bool.config_allow3rdPartyAppOnInternal);
1941 }
1942
1943 private boolean isPackageCandidateVolume(
1944 ContextImpl context, ApplicationInfo app, VolumeInfo vol, IPackageManager pm) {
1945 final boolean forceAllowOnExternal = isForceAllowOnExternal(context);
1946
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001947 if (VolumeInfo.ID_PRIVATE_INTERNAL.equals(vol.getId())) {
Yao Chen022b8ea2016-12-16 11:03:28 -08001948 return app.isSystemApp() || isAllow3rdPartyOnInternal(context);
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001949 }
1950
1951 // System apps and apps demanding internal storage can't be moved
1952 // anywhere else
Todd Kennedyf39ca8f2015-08-07 14:15:07 -07001953 if (app.isSystemApp()) {
1954 return false;
1955 }
1956 if (!forceAllowOnExternal
Dianne Hackborn30a4e6d2015-10-12 17:14:56 -07001957 && (app.installLocation == PackageInfo.INSTALL_LOCATION_INTERNAL_ONLY
1958 || app.installLocation == PackageInfo.INSTALL_LOCATION_UNSPECIFIED)) {
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001959 return false;
1960 }
1961
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001962 // Gotta be able to write there
1963 if (!vol.isMountedWritable()) {
1964 return false;
1965 }
1966
1967 // Moving into an ASEC on public primary is only option internal
1968 if (vol.isPrimaryPhysical()) {
1969 return app.isInternal();
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001970 }
1971
Makoto Onukif34db0a2016-02-17 11:17:15 -08001972 // Some apps can't be moved. (e.g. device admins)
1973 try {
Yao Chen022b8ea2016-12-16 11:03:28 -08001974 if (pm.isPackageDeviceAdminOnAnyUser(app.packageName)) {
Makoto Onukif34db0a2016-02-17 11:17:15 -08001975 return false;
1976 }
1977 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001978 throw e.rethrowFromSystemServer();
Makoto Onukif34db0a2016-02-17 11:17:15 -08001979 }
1980
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001981 // Otherwise we can move to any private volume
1982 return (vol.getType() == VolumeInfo.TYPE_PRIVATE);
1983 }
1984
1985 @Override
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001986 public int movePrimaryStorage(VolumeInfo vol) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001987 try {
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001988 final String volumeUuid;
1989 if (VolumeInfo.ID_PRIVATE_INTERNAL.equals(vol.id)) {
1990 volumeUuid = StorageManager.UUID_PRIVATE_INTERNAL;
1991 } else if (vol.isPrimaryPhysical()) {
1992 volumeUuid = StorageManager.UUID_PRIMARY_PHYSICAL;
1993 } else {
1994 volumeUuid = Preconditions.checkNotNull(vol.fsUuid);
1995 }
1996
1997 return mPM.movePrimaryStorage(volumeUuid);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001998 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001999 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002000 }
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002001 }
2002
Jeff Sharkey275e3e42015-04-24 16:10:32 -07002003 @Override
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002004 public @Nullable VolumeInfo getPrimaryStorageCurrentVolume() {
2005 final StorageManager storage = mContext.getSystemService(StorageManager.class);
2006 final String volumeUuid = storage.getPrimaryStorageUuid();
Jeff Sharkey50a05452015-04-29 11:24:52 -07002007 return storage.findVolumeByQualifiedUuid(volumeUuid);
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002008 }
2009
Jeff Sharkey275e3e42015-04-24 16:10:32 -07002010 @Override
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002011 public @NonNull List<VolumeInfo> getPrimaryStorageCandidateVolumes() {
2012 final StorageManager storage = mContext.getSystemService(StorageManager.class);
2013 final VolumeInfo currentVol = getPrimaryStorageCurrentVolume();
2014 final List<VolumeInfo> vols = storage.getVolumes();
2015 final List<VolumeInfo> candidates = new ArrayList<>();
Jeff Sharkeyfced5342015-05-10 14:53:34 -07002016 if (Objects.equals(StorageManager.UUID_PRIMARY_PHYSICAL,
2017 storage.getPrimaryStorageUuid()) && currentVol != null) {
2018 // TODO: support moving primary physical to emulated volume
2019 candidates.add(currentVol);
2020 } else {
2021 for (VolumeInfo vol : vols) {
2022 if (Objects.equals(vol, currentVol) || isPrimaryStorageCandidateVolume(vol)) {
2023 candidates.add(vol);
2024 }
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002025 }
2026 }
2027 return candidates;
2028 }
2029
2030 private static boolean isPrimaryStorageCandidateVolume(VolumeInfo vol) {
2031 // Private internal is always an option
2032 if (VolumeInfo.ID_PRIVATE_INTERNAL.equals(vol.getId())) {
2033 return true;
2034 }
2035
2036 // Gotta be able to write there
2037 if (!vol.isMountedWritable()) {
2038 return false;
2039 }
2040
Jeff Sharkeyfced5342015-05-10 14:53:34 -07002041 // We can move to any private volume
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002042 return (vol.getType() == VolumeInfo.TYPE_PRIVATE);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002043 }
2044
2045 @Override
2046 public void deletePackage(String packageName, IPackageDeleteObserver observer, int flags) {
Robin Lee0e27c872015-09-28 14:37:40 +01002047 deletePackageAsUser(packageName, observer, flags, mContext.getUserId());
Nicolas Prevot9a80e532015-09-23 15:49:28 +01002048 }
2049
2050 @Override
Svet Ganov67882122016-12-11 16:36:34 -08002051 public void deletePackageAsUser(String packageName, IPackageDeleteObserver observer,
2052 int flags, int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002053 try {
Svet Ganov67882122016-12-11 16:36:34 -08002054 mPM.deletePackageAsUser(packageName, PackageManager.VERSION_CODE_HIGHEST,
2055 observer, userId, flags);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002056 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002057 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002058 }
2059 }
Jeff Sharkeyfbd0e9f2014-08-06 16:34:34 -07002060
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002061 @Override
2062 public void clearApplicationUserData(String packageName,
2063 IPackageDataObserver observer) {
2064 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -07002065 mPM.clearApplicationUserData(packageName, observer, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002066 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002067 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002068 }
2069 }
2070 @Override
2071 public void deleteApplicationCacheFiles(String packageName,
2072 IPackageDataObserver observer) {
2073 try {
2074 mPM.deleteApplicationCacheFiles(packageName, observer);
2075 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002076 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002077 }
2078 }
Jeff Sharkey529f91f2015-04-18 20:23:13 -07002079
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002080 @Override
Suprabh Shukla78c9eb82016-04-12 15:51:35 -07002081 public void deleteApplicationCacheFilesAsUser(String packageName, int userId,
2082 IPackageDataObserver observer) {
2083 try {
2084 mPM.deleteApplicationCacheFilesAsUser(packageName, userId, observer);
2085 } catch (RemoteException e) {
2086 throw e.rethrowFromSystemServer();
2087 }
2088 }
2089
2090 @Override
Jeff Sharkey529f91f2015-04-18 20:23:13 -07002091 public void freeStorageAndNotify(String volumeUuid, long idealStorageSize,
2092 IPackageDataObserver observer) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002093 try {
Jeff Sharkey529f91f2015-04-18 20:23:13 -07002094 mPM.freeStorageAndNotify(volumeUuid, idealStorageSize, observer);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002095 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002096 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002097 }
2098 }
2099
2100 @Override
Jeff Sharkey529f91f2015-04-18 20:23:13 -07002101 public void freeStorage(String volumeUuid, long freeStorageSize, IntentSender pi) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002102 try {
Jeff Sharkey529f91f2015-04-18 20:23:13 -07002103 mPM.freeStorage(volumeUuid, freeStorageSize, pi);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002104 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002105 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002106 }
2107 }
2108
2109 @Override
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00002110 public String[] setPackagesSuspendedAsUser(String[] packageNames, boolean suspended,
2111 int userId) {
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00002112 try {
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00002113 return mPM.setPackagesSuspendedAsUser(packageNames, suspended, userId);
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00002114 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002115 throw e.rethrowFromSystemServer();
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00002116 }
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00002117 }
2118
2119 @Override
Andrei Stingaceanu355b2322016-02-12 16:43:51 +00002120 public boolean isPackageSuspendedForUser(String packageName, int userId) {
2121 try {
2122 return mPM.isPackageSuspendedForUser(packageName, userId);
2123 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002124 throw e.rethrowFromSystemServer();
Andrei Stingaceanu355b2322016-02-12 16:43:51 +00002125 }
Andrei Stingaceanu355b2322016-02-12 16:43:51 +00002126 }
2127
Jeff Sharkey9bc89af2017-01-11 11:25:50 -07002128 /** @hide */
2129 @Override
2130 public void setApplicationCategoryHint(String packageName, int categoryHint) {
2131 try {
2132 mPM.setApplicationCategoryHint(packageName, categoryHint,
2133 mContext.getOpPackageName());
2134 } catch (RemoteException e) {
2135 throw e.rethrowFromSystemServer();
2136 }
2137 }
2138
Andrei Stingaceanu355b2322016-02-12 16:43:51 +00002139 @Override
Jeff Sharkeye06b4d12016-01-06 14:51:50 -07002140 public void getPackageSizeInfoAsUser(String packageName, int userHandle,
Dianne Hackborn0c380492012-08-20 17:23:30 -07002141 IPackageStatsObserver observer) {
Jeff Sharkey6f4b2a32017-03-21 14:13:41 -06002142 final String msg = "Shame on you for calling the hidden API "
2143 + "getPackageSizeInfoAsUser(). Shame!";
Jeff Sharkeye6306c42017-03-07 21:03:18 -07002144 if (mContext.getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.O) {
Jeff Sharkey6f4b2a32017-03-21 14:13:41 -06002145 throw new UnsupportedOperationException(msg);
Jeff Sharkeye6306c42017-03-07 21:03:18 -07002146 } else if (observer != null) {
Jeff Sharkey6f4b2a32017-03-21 14:13:41 -06002147 Log.d(TAG, msg);
Jeff Sharkeye6306c42017-03-07 21:03:18 -07002148 try {
2149 observer.onGetStatsCompleted(null, false);
2150 } catch (RemoteException ignored) {
2151 }
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002152 }
2153 }
Jeff Sharkeyd5896632016-03-04 16:16:00 -07002154
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002155 @Override
2156 public void addPackageToPreferred(String packageName) {
Jeff Sharkeyd5896632016-03-04 16:16:00 -07002157 Log.w(TAG, "addPackageToPreferred() is a no-op");
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002158 }
2159
2160 @Override
2161 public void removePackageFromPreferred(String packageName) {
Jeff Sharkeyd5896632016-03-04 16:16:00 -07002162 Log.w(TAG, "removePackageFromPreferred() is a no-op");
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002163 }
2164
2165 @Override
2166 public List<PackageInfo> getPreferredPackages(int flags) {
Jeff Sharkeyd5896632016-03-04 16:16:00 -07002167 Log.w(TAG, "getPreferredPackages() is a no-op");
2168 return Collections.emptyList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002169 }
2170
2171 @Override
2172 public void addPreferredActivity(IntentFilter filter,
2173 int match, ComponentName[] set, ComponentName activity) {
2174 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -07002175 mPM.addPreferredActivity(filter, match, set, activity, mContext.getUserId());
Amith Yamasania3f133a2012-08-09 17:11:28 -07002176 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002177 throw e.rethrowFromSystemServer();
Amith Yamasania3f133a2012-08-09 17:11:28 -07002178 }
2179 }
2180
2181 @Override
Jeff Sharkeye06b4d12016-01-06 14:51:50 -07002182 public void addPreferredActivityAsUser(IntentFilter filter, int match,
Amith Yamasania3f133a2012-08-09 17:11:28 -07002183 ComponentName[] set, ComponentName activity, int userId) {
2184 try {
2185 mPM.addPreferredActivity(filter, match, set, activity, userId);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002186 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002187 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002188 }
2189 }
2190
2191 @Override
2192 public void replacePreferredActivity(IntentFilter filter,
2193 int match, ComponentName[] set, ComponentName activity) {
2194 try {
Robin Lee0e27c872015-09-28 14:37:40 +01002195 mPM.replacePreferredActivity(filter, match, set, activity, mContext.getUserId());
Amith Yamasani41c1ded2014-08-05 11:15:05 -07002196 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002197 throw e.rethrowFromSystemServer();
Amith Yamasani41c1ded2014-08-05 11:15:05 -07002198 }
2199 }
2200
2201 @Override
2202 public void replacePreferredActivityAsUser(IntentFilter filter,
2203 int match, ComponentName[] set, ComponentName activity,
2204 int userId) {
2205 try {
2206 mPM.replacePreferredActivity(filter, match, set, activity, userId);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002207 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002208 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002209 }
2210 }
2211
2212 @Override
2213 public void clearPackagePreferredActivities(String packageName) {
2214 try {
2215 mPM.clearPackagePreferredActivities(packageName);
2216 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002217 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002218 }
2219 }
2220
2221 @Override
2222 public int getPreferredActivities(List<IntentFilter> outFilters,
2223 List<ComponentName> outActivities, String packageName) {
2224 try {
2225 return mPM.getPreferredActivities(outFilters, outActivities, packageName);
2226 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002227 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002228 }
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002229 }
2230
2231 @Override
Christopher Tatea2a0850d2013-09-05 16:38:58 -07002232 public ComponentName getHomeActivities(List<ResolveInfo> outActivities) {
2233 try {
2234 return mPM.getHomeActivities(outActivities);
2235 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002236 throw e.rethrowFromSystemServer();
Christopher Tatea2a0850d2013-09-05 16:38:58 -07002237 }
Christopher Tatea2a0850d2013-09-05 16:38:58 -07002238 }
2239
2240 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002241 public void setComponentEnabledSetting(ComponentName componentName,
2242 int newState, int flags) {
2243 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -07002244 mPM.setComponentEnabledSetting(componentName, newState, flags, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002245 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002246 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002247 }
2248 }
2249
2250 @Override
2251 public int getComponentEnabledSetting(ComponentName componentName) {
2252 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -07002253 return mPM.getComponentEnabledSetting(componentName, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002254 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002255 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002256 }
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002257 }
2258
2259 @Override
2260 public void setApplicationEnabledSetting(String packageName,
2261 int newState, int flags) {
2262 try {
Dianne Hackborn3fa3c28a2013-03-26 16:15:41 -07002263 mPM.setApplicationEnabledSetting(packageName, newState, flags,
Dianne Hackborn95d78532013-09-11 09:51:14 -07002264 mContext.getUserId(), mContext.getOpPackageName());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002265 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002266 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002267 }
2268 }
2269
2270 @Override
2271 public int getApplicationEnabledSetting(String packageName) {
2272 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -07002273 return mPM.getApplicationEnabledSetting(packageName, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002274 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002275 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002276 }
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002277 }
2278
Amith Yamasani655d0e22013-06-12 14:19:10 -07002279 @Override
Sudheer Shankabbb3ff22015-07-09 15:39:23 +01002280 public void flushPackageRestrictionsAsUser(int userId) {
2281 try {
2282 mPM.flushPackageRestrictionsAsUser(userId);
2283 } catch (RemoteException e) {
2284 throw e.rethrowFromSystemServer();
2285 }
2286 }
2287
2288 @Override
Amith Yamasanie5bcff62014-07-19 15:44:09 -07002289 public boolean setApplicationHiddenSettingAsUser(String packageName, boolean hidden,
Amith Yamasani655d0e22013-06-12 14:19:10 -07002290 UserHandle user) {
2291 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07002292 return mPM.setApplicationHiddenSettingAsUser(packageName, hidden,
Amith Yamasani655d0e22013-06-12 14:19:10 -07002293 user.getIdentifier());
Jeff Sharkey27b2e692016-02-25 17:40:12 -07002294 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002295 throw e.rethrowFromSystemServer();
Amith Yamasani655d0e22013-06-12 14:19:10 -07002296 }
Amith Yamasani655d0e22013-06-12 14:19:10 -07002297 }
2298
2299 @Override
Amith Yamasanie5bcff62014-07-19 15:44:09 -07002300 public boolean getApplicationHiddenSettingAsUser(String packageName, UserHandle user) {
Amith Yamasani655d0e22013-06-12 14:19:10 -07002301 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07002302 return mPM.getApplicationHiddenSettingAsUser(packageName, user.getIdentifier());
Jeff Sharkey27b2e692016-02-25 17:40:12 -07002303 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002304 throw e.rethrowFromSystemServer();
Amith Yamasani655d0e22013-06-12 14:19:10 -07002305 }
Amith Yamasani655d0e22013-06-12 14:19:10 -07002306 }
2307
dcashmanc6f22492014-08-14 09:54:51 -07002308 /** @hide */
dcashman9d2f4412014-06-09 09:27:54 -07002309 @Override
2310 public KeySet getKeySetByAlias(String packageName, String alias) {
2311 Preconditions.checkNotNull(packageName);
2312 Preconditions.checkNotNull(alias);
dcashman9d2f4412014-06-09 09:27:54 -07002313 try {
Jeff Sharkey27b2e692016-02-25 17:40:12 -07002314 return mPM.getKeySetByAlias(packageName, alias);
dcashman9d2f4412014-06-09 09:27:54 -07002315 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002316 throw e.rethrowFromSystemServer();
dcashman9d2f4412014-06-09 09:27:54 -07002317 }
dcashman9d2f4412014-06-09 09:27:54 -07002318 }
2319
dcashmanc6f22492014-08-14 09:54:51 -07002320 /** @hide */
dcashman9d2f4412014-06-09 09:27:54 -07002321 @Override
2322 public KeySet getSigningKeySet(String packageName) {
2323 Preconditions.checkNotNull(packageName);
dcashman9d2f4412014-06-09 09:27:54 -07002324 try {
Jeff Sharkey27b2e692016-02-25 17:40:12 -07002325 return mPM.getSigningKeySet(packageName);
dcashman9d2f4412014-06-09 09:27:54 -07002326 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002327 throw e.rethrowFromSystemServer();
dcashman9d2f4412014-06-09 09:27:54 -07002328 }
dcashman9d2f4412014-06-09 09:27:54 -07002329 }
2330
dcashmanc6f22492014-08-14 09:54:51 -07002331 /** @hide */
dcashman9d2f4412014-06-09 09:27:54 -07002332 @Override
2333 public boolean isSignedBy(String packageName, KeySet ks) {
2334 Preconditions.checkNotNull(packageName);
2335 Preconditions.checkNotNull(ks);
dcashman9d2f4412014-06-09 09:27:54 -07002336 try {
dcashmanc6f22492014-08-14 09:54:51 -07002337 return mPM.isPackageSignedByKeySet(packageName, ks);
dcashman9d2f4412014-06-09 09:27:54 -07002338 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002339 throw e.rethrowFromSystemServer();
dcashman9d2f4412014-06-09 09:27:54 -07002340 }
2341 }
2342
dcashmanc6f22492014-08-14 09:54:51 -07002343 /** @hide */
dcashman9d2f4412014-06-09 09:27:54 -07002344 @Override
2345 public boolean isSignedByExactly(String packageName, KeySet ks) {
2346 Preconditions.checkNotNull(packageName);
2347 Preconditions.checkNotNull(ks);
dcashman9d2f4412014-06-09 09:27:54 -07002348 try {
dcashmanc6f22492014-08-14 09:54:51 -07002349 return mPM.isPackageSignedByKeySetExactly(packageName, ks);
dcashman9d2f4412014-06-09 09:27:54 -07002350 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002351 throw e.rethrowFromSystemServer();
dcashman9d2f4412014-06-09 09:27:54 -07002352 }
2353 }
2354
Kenny Root0aaa0d92011-09-12 16:42:55 -07002355 /**
2356 * @hide
2357 */
2358 @Override
2359 public VerifierDeviceIdentity getVerifierDeviceIdentity() {
2360 try {
2361 return mPM.getVerifierDeviceIdentity();
2362 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002363 throw e.rethrowFromSystemServer();
Kenny Root0aaa0d92011-09-12 16:42:55 -07002364 }
Kenny Root0aaa0d92011-09-12 16:42:55 -07002365 }
2366
Jeff Hao9f60c082014-10-28 18:51:07 -07002367 /**
2368 * @hide
2369 */
2370 @Override
2371 public boolean isUpgrade() {
2372 try {
2373 return mPM.isUpgrade();
2374 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002375 throw e.rethrowFromSystemServer();
Jeff Hao9f60c082014-10-28 18:51:07 -07002376 }
2377 }
2378
Jeff Sharkey3a44f3f2014-04-28 17:36:31 -07002379 @Override
Jeff Sharkey16c8e3f2014-07-24 17:08:17 -07002380 public PackageInstaller getPackageInstaller() {
2381 synchronized (mLock) {
2382 if (mInstaller == null) {
2383 try {
Svet Ganov67882122016-12-11 16:36:34 -08002384 mInstaller = new PackageInstaller(mPM.getPackageInstaller(),
Jeff Sharkey16c8e3f2014-07-24 17:08:17 -07002385 mContext.getPackageName(), mContext.getUserId());
2386 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002387 throw e.rethrowFromSystemServer();
Jeff Sharkey16c8e3f2014-07-24 17:08:17 -07002388 }
2389 }
2390 return mInstaller;
Jeff Sharkey3a44f3f2014-04-28 17:36:31 -07002391 }
2392 }
2393
Jeff Sharkey6c833e02014-07-14 22:44:30 -07002394 @Override
2395 public boolean isPackageAvailable(String packageName) {
2396 try {
2397 return mPM.isPackageAvailable(packageName, mContext.getUserId());
2398 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002399 throw e.rethrowFromSystemServer();
Jeff Sharkey6c833e02014-07-14 22:44:30 -07002400 }
2401 }
2402
Nicolas Prevotc79586e2014-05-06 12:47:57 +01002403 /**
2404 * @hide
2405 */
2406 @Override
Nicolas Prevot63798c52014-05-27 13:22:38 +01002407 public void addCrossProfileIntentFilter(IntentFilter filter, int sourceUserId, int targetUserId,
2408 int flags) {
Nicolas Prevotc79586e2014-05-06 12:47:57 +01002409 try {
Nicolas Prevot3f7777f2014-07-24 15:58:39 +01002410 mPM.addCrossProfileIntentFilter(filter, mContext.getOpPackageName(),
Nicolas Prevot4b8d5822015-03-05 15:20:49 +00002411 sourceUserId, targetUserId, flags);
Nicolas Prevotc79586e2014-05-06 12:47:57 +01002412 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002413 throw e.rethrowFromSystemServer();
Nicolas Prevotc79586e2014-05-06 12:47:57 +01002414 }
2415 }
2416
2417 /**
2418 * @hide
2419 */
2420 @Override
Nicolas Prevot81948992014-05-16 18:25:26 +01002421 public void clearCrossProfileIntentFilters(int sourceUserId) {
Nicolas Prevotc79586e2014-05-06 12:47:57 +01002422 try {
Nicolas Prevot4b8d5822015-03-05 15:20:49 +00002423 mPM.clearCrossProfileIntentFilters(sourceUserId, mContext.getOpPackageName());
Nicolas Prevotc79586e2014-05-06 12:47:57 +01002424 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002425 throw e.rethrowFromSystemServer();
Nicolas Prevotc79586e2014-05-06 12:47:57 +01002426 }
2427 }
2428
Nicolas Prevot88cc3462014-05-14 14:51:48 +01002429 /**
2430 * @hide
2431 */
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +01002432 public Drawable loadItemIcon(PackageItemInfo itemInfo, ApplicationInfo appInfo) {
Benjamin Franzec2d48b2014-10-01 15:38:43 +01002433 Drawable dr = loadUnbadgedItemIcon(itemInfo, appInfo);
2434 if (itemInfo.showUserIcon != UserHandle.USER_NULL) {
2435 return dr;
2436 }
2437 return getUserBadgedIcon(dr, new UserHandle(mContext.getUserId()));
2438 }
2439
2440 /**
2441 * @hide
2442 */
2443 public Drawable loadUnbadgedItemIcon(PackageItemInfo itemInfo, ApplicationInfo appInfo) {
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +01002444 if (itemInfo.showUserIcon != UserHandle.USER_NULL) {
Alexandra Gherghina64d4dca2014-08-28 18:26:56 +01002445 Bitmap bitmap = getUserManager().getUserIcon(itemInfo.showUserIcon);
2446 if (bitmap == null) {
2447 return UserIcons.getDefaultUserIcon(itemInfo.showUserIcon, /* light= */ false);
2448 }
2449 return new BitmapDrawable(bitmap);
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +01002450 }
Alexandra Gherghinadb811db2014-08-29 13:43:59 +01002451 Drawable dr = null;
2452 if (itemInfo.packageName != null) {
2453 dr = getDrawable(itemInfo.packageName, itemInfo.icon, appInfo);
2454 }
Alexandra Gherghinaa71e3902014-07-25 20:03:47 +01002455 if (dr == null) {
Alexandra Gherghinaa7093142014-07-30 13:43:39 +01002456 dr = itemInfo.loadDefaultIcon(this);
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +01002457 }
Benjamin Franzec2d48b2014-10-01 15:38:43 +01002458 return dr;
Svetoslavc7d62f02014-09-04 15:39:54 -07002459 }
2460
2461 private Drawable getBadgedDrawable(Drawable drawable, Drawable badgeDrawable,
2462 Rect badgeLocation, boolean tryBadgeInPlace) {
2463 final int badgedWidth = drawable.getIntrinsicWidth();
2464 final int badgedHeight = drawable.getIntrinsicHeight();
2465 final boolean canBadgeInPlace = tryBadgeInPlace
2466 && (drawable instanceof BitmapDrawable)
2467 && ((BitmapDrawable) drawable).getBitmap().isMutable();
2468
2469 final Bitmap bitmap;
2470 if (canBadgeInPlace) {
2471 bitmap = ((BitmapDrawable) drawable).getBitmap();
2472 } else {
2473 bitmap = Bitmap.createBitmap(badgedWidth, badgedHeight, Bitmap.Config.ARGB_8888);
2474 }
2475 Canvas canvas = new Canvas(bitmap);
2476
2477 if (!canBadgeInPlace) {
2478 drawable.setBounds(0, 0, badgedWidth, badgedHeight);
2479 drawable.draw(canvas);
2480 }
2481
2482 if (badgeLocation != null) {
2483 if (badgeLocation.left < 0 || badgeLocation.top < 0
2484 || badgeLocation.width() > badgedWidth || badgeLocation.height() > badgedHeight) {
2485 throw new IllegalArgumentException("Badge location " + badgeLocation
2486 + " not in badged drawable bounds "
2487 + new Rect(0, 0, badgedWidth, badgedHeight));
2488 }
2489 badgeDrawable.setBounds(0, 0, badgeLocation.width(), badgeLocation.height());
2490
2491 canvas.save();
2492 canvas.translate(badgeLocation.left, badgeLocation.top);
2493 badgeDrawable.draw(canvas);
2494 canvas.restore();
2495 } else {
2496 badgeDrawable.setBounds(0, 0, badgedWidth, badgedHeight);
2497 badgeDrawable.draw(canvas);
2498 }
2499
2500 if (!canBadgeInPlace) {
2501 BitmapDrawable mergedDrawable = new BitmapDrawable(mContext.getResources(), bitmap);
2502
2503 if (drawable instanceof BitmapDrawable) {
2504 BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
2505 mergedDrawable.setTargetDensity(bitmapDrawable.getBitmap().getDensity());
2506 }
2507
2508 return mergedDrawable;
2509 }
2510
2511 return drawable;
2512 }
2513
Tony Mak8673b282016-03-21 21:10:59 +00002514 private boolean isManagedProfile(int userId) {
2515 return getUserManager().isManagedProfile(userId);
Nicolas Prevot88cc3462014-05-14 14:51:48 +01002516 }
2517
Bartosz Fabianowskia34f53f2017-01-11 18:08:47 +01002518 /**
2519 * @hide
2520 */
2521 @Override
2522 public int getInstallReason(String packageName, UserHandle user) {
2523 try {
2524 return mPM.getInstallReason(packageName, user.getIdentifier());
2525 } catch (RemoteException e) {
2526 throw e.rethrowFromSystemServer();
2527 }
2528 }
2529
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002530 /** {@hide} */
2531 private static class MoveCallbackDelegate extends IPackageMoveObserver.Stub implements
2532 Handler.Callback {
Jeff Sharkey50a05452015-04-29 11:24:52 -07002533 private static final int MSG_CREATED = 1;
2534 private static final int MSG_STATUS_CHANGED = 2;
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002535
2536 final MoveCallback mCallback;
2537 final Handler mHandler;
2538
2539 public MoveCallbackDelegate(MoveCallback callback, Looper looper) {
2540 mCallback = callback;
2541 mHandler = new Handler(looper, this);
2542 }
2543
2544 @Override
2545 public boolean handleMessage(Message msg) {
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002546 switch (msg.what) {
Jeff Sharkey50a05452015-04-29 11:24:52 -07002547 case MSG_CREATED: {
Jeff Sharkeyb36586a2015-04-27 08:42:28 -07002548 final SomeArgs args = (SomeArgs) msg.obj;
Jeff Sharkey50a05452015-04-29 11:24:52 -07002549 mCallback.onCreated(args.argi1, (Bundle) args.arg2);
Jeff Sharkeyb36586a2015-04-27 08:42:28 -07002550 args.recycle();
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002551 return true;
Jeff Sharkey50a05452015-04-29 11:24:52 -07002552 }
2553 case MSG_STATUS_CHANGED: {
2554 final SomeArgs args = (SomeArgs) msg.obj;
2555 mCallback.onStatusChanged(args.argi1, args.argi2, (long) args.arg3);
2556 args.recycle();
2557 return true;
2558 }
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002559 }
2560 return false;
2561 }
2562
2563 @Override
Jeff Sharkey50a05452015-04-29 11:24:52 -07002564 public void onCreated(int moveId, Bundle extras) {
Jeff Sharkeyb36586a2015-04-27 08:42:28 -07002565 final SomeArgs args = SomeArgs.obtain();
2566 args.argi1 = moveId;
Jeff Sharkey50a05452015-04-29 11:24:52 -07002567 args.arg2 = extras;
2568 mHandler.obtainMessage(MSG_CREATED, args).sendToTarget();
2569 }
2570
2571 @Override
2572 public void onStatusChanged(int moveId, int status, long estMillis) {
2573 final SomeArgs args = SomeArgs.obtain();
2574 args.argi1 = moveId;
2575 args.argi2 = status;
2576 args.arg3 = estMillis;
Jeff Sharkeyb36586a2015-04-27 08:42:28 -07002577 mHandler.obtainMessage(MSG_STATUS_CHANGED, args).sendToTarget();
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002578 }
2579 }
2580
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002581 private final ContextImpl mContext;
2582 private final IPackageManager mPM;
2583
2584 private static final Object sSync = new Object();
Dianne Hackbornadd005c2013-07-17 18:43:12 -07002585 private static ArrayMap<ResourceName, WeakReference<Drawable.ConstantState>> sIconCache
2586 = new ArrayMap<ResourceName, WeakReference<Drawable.ConstantState>>();
2587 private static ArrayMap<ResourceName, WeakReference<CharSequence>> sStringCache
2588 = new ArrayMap<ResourceName, WeakReference<CharSequence>>();
Svetoslavf7c06eb2015-06-10 18:43:22 -07002589
2590 private final Map<OnPermissionsChangedListener, IOnPermissionsChangeListener>
2591 mPermissionListeners = new ArrayMap<>();
2592
2593 public class OnPermissionsChangeListenerDelegate extends IOnPermissionsChangeListener.Stub
2594 implements Handler.Callback{
2595 private static final int MSG_PERMISSIONS_CHANGED = 1;
2596
2597 private final OnPermissionsChangedListener mListener;
2598 private final Handler mHandler;
2599
2600
2601 public OnPermissionsChangeListenerDelegate(OnPermissionsChangedListener listener,
2602 Looper looper) {
2603 mListener = listener;
2604 mHandler = new Handler(looper, this);
2605 }
2606
2607 @Override
2608 public void onPermissionsChanged(int uid) {
2609 mHandler.obtainMessage(MSG_PERMISSIONS_CHANGED, uid, 0).sendToTarget();
2610 }
2611
2612 @Override
2613 public boolean handleMessage(Message msg) {
2614 switch (msg.what) {
2615 case MSG_PERMISSIONS_CHANGED: {
2616 final int uid = msg.arg1;
2617 mListener.onPermissionsChanged(uid);
2618 return true;
2619 }
2620 }
2621 return false;
2622 }
2623 }
Suprabh Shuklaaef25132017-01-23 18:09:03 -08002624
2625 @Override
2626 public boolean canRequestPackageInstalls() {
2627 try {
2628 return mPM.canRequestPackageInstalls(mContext.getPackageName(), mContext.getUserId());
2629 } catch (RemoteException e) {
2630 throw e.rethrowAsRuntimeException();
2631 }
2632 }
Chad Brubaker336ae5b2017-03-24 15:53:09 -07002633
2634 @Override
2635 public ComponentName getInstantAppResolverSettingsComponent() {
2636 try {
2637 return mPM.getInstantAppResolverSettingsComponent();
2638 } catch (RemoteException e) {
2639 throw e.rethrowAsRuntimeException();
2640 }
2641 }
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002642}