blob: 10f59602b93f4edafd3d89c1d7103b7bf96156a3 [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;
26import android.content.Intent;
27import android.content.IntentFilter;
28import android.content.IntentSender;
29import android.content.pm.ActivityInfo;
30import android.content.pm.ApplicationInfo;
31import android.content.pm.ComponentInfo;
Anonymous Cowardceb1b0b2012-04-24 10:35:16 -070032import android.content.pm.ContainerEncryptionParams;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080033import android.content.pm.FeatureInfo;
34import android.content.pm.IPackageDataObserver;
35import android.content.pm.IPackageDeleteObserver;
36import android.content.pm.IPackageInstallObserver;
37import android.content.pm.IPackageManager;
38import android.content.pm.IPackageMoveObserver;
39import android.content.pm.IPackageStatsObserver;
40import android.content.pm.InstrumentationInfo;
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -080041import android.content.pm.IntentFilterVerificationInfo;
dcashman9d2f4412014-06-09 09:27:54 -070042import android.content.pm.KeySet;
Jeff Sharkey513a0742014-07-08 17:10:32 -070043import android.content.pm.ManifestDigest;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080044import android.content.pm.PackageInfo;
Jeff Sharkey3a44f3f2014-04-28 17:36:31 -070045import android.content.pm.PackageInstaller;
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +010046import android.content.pm.PackageItemInfo;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080047import android.content.pm.PackageManager;
Kenny Roote6cd0c72011-05-19 12:48:14 -070048import android.content.pm.ParceledListSlice;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080049import android.content.pm.PermissionGroupInfo;
50import android.content.pm.PermissionInfo;
51import android.content.pm.ProviderInfo;
52import android.content.pm.ResolveInfo;
53import android.content.pm.ServiceInfo;
Svetoslavc7d62f02014-09-04 15:39:54 -070054import android.content.pm.UserInfo;
rich cannings706e8ba2012-08-20 13:20:14 -070055import android.content.pm.VerificationParams;
Kenny Root0aaa0d92011-09-12 16:42:55 -070056import android.content.pm.VerifierDeviceIdentity;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080057import android.content.res.Resources;
58import android.content.res.XmlResourceParser;
Svetoslavc7d62f02014-09-04 15:39:54 -070059import android.graphics.Bitmap;
60import android.graphics.Canvas;
61import android.graphics.Rect;
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +010062import android.graphics.drawable.BitmapDrawable;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080063import android.graphics.drawable.Drawable;
64import android.net.Uri;
Jeff Sharkey620b32b2015-04-23 19:36:02 -070065import android.os.Handler;
66import android.os.Looper;
67import android.os.Message;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080068import android.os.Process;
69import android.os.RemoteException;
Jeff Sharkeyb2b9ab82015-04-05 21:10:42 -070070import android.os.SystemProperties;
Amith Yamasani67df64b2012-12-14 12:09:36 -080071import android.os.UserHandle;
Nicolas Prevot88cc3462014-05-14 14:51:48 +010072import android.os.UserManager;
Jeff Sharkeye2d45be2015-04-15 17:14:12 -070073import android.os.storage.StorageManager;
74import android.os.storage.VolumeInfo;
Dianne Hackbornadd005c2013-07-17 18:43:12 -070075import android.util.ArrayMap;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080076import android.util.Log;
Jeff Browna492c3a2012-08-23 19:48:44 -070077import android.view.Display;
Jeff Sharkeyb2b9ab82015-04-05 21:10:42 -070078
79import dalvik.system.VMRuntime;
Jeff Sharkey16c8e3f2014-07-24 17:08:17 -070080
81import com.android.internal.annotations.GuardedBy;
dcashman9d2f4412014-06-09 09:27:54 -070082import com.android.internal.util.Preconditions;
Alexandra Gherghina64d4dca2014-08-28 18:26:56 +010083import com.android.internal.util.UserIcons;
Jeff Sharkey16c8e3f2014-07-24 17:08:17 -070084
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080085import java.lang.ref.WeakReference;
86import java.util.ArrayList;
Jeff Sharkey620b32b2015-04-23 19:36:02 -070087import java.util.Iterator;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080088import java.util.List;
Jeff Sharkey620b32b2015-04-23 19:36:02 -070089import java.util.Objects;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080090
91/*package*/
92final class ApplicationPackageManager extends PackageManager {
93 private static final String TAG = "ApplicationPackageManager";
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080094 private final static boolean DEBUG_ICONS = false;
95
Adam Lesinskid00bb5e2014-10-07 12:14:45 -070096 // Default flags to use with PackageManager when no flags are given.
97 private final static int sDefaultFlags = PackageManager.GET_SHARED_LIBRARY_FILES;
98
Jeff Sharkey16c8e3f2014-07-24 17:08:17 -070099 private final Object mLock = new Object();
100
101 @GuardedBy("mLock")
102 private UserManager mUserManager;
103 @GuardedBy("mLock")
104 private PackageInstaller mInstaller;
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +0100105
Jeff Sharkey620b32b2015-04-23 19:36:02 -0700106 @GuardedBy("mDelegates")
107 private final ArrayList<MoveCallbackDelegate> mDelegates = new ArrayList<>();
108
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +0100109 UserManager getUserManager() {
Jeff Sharkey16c8e3f2014-07-24 17:08:17 -0700110 synchronized (mLock) {
111 if (mUserManager == null) {
112 mUserManager = UserManager.get(mContext);
113 }
114 return mUserManager;
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +0100115 }
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +0100116 }
117
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800118 @Override
119 public PackageInfo getPackageInfo(String packageName, int flags)
120 throws NameNotFoundException {
121 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700122 PackageInfo pi = mPM.getPackageInfo(packageName, flags, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800123 if (pi != null) {
124 return pi;
125 }
126 } catch (RemoteException e) {
127 throw new RuntimeException("Package manager has died", e);
128 }
129
130 throw new NameNotFoundException(packageName);
131 }
132
133 @Override
134 public String[] currentToCanonicalPackageNames(String[] names) {
135 try {
136 return mPM.currentToCanonicalPackageNames(names);
137 } catch (RemoteException e) {
138 throw new RuntimeException("Package manager has died", e);
139 }
140 }
141
142 @Override
143 public String[] canonicalToCurrentPackageNames(String[] names) {
144 try {
145 return mPM.canonicalToCurrentPackageNames(names);
146 } catch (RemoteException e) {
147 throw new RuntimeException("Package manager has died", e);
148 }
149 }
150
151 @Override
152 public Intent getLaunchIntentForPackage(String packageName) {
153 // First see if the package has an INFO activity; the existence of
154 // such an activity is implied to be the desired front-door for the
155 // overall package (such as if it has multiple launcher entries).
156 Intent intentToResolve = new Intent(Intent.ACTION_MAIN);
157 intentToResolve.addCategory(Intent.CATEGORY_INFO);
158 intentToResolve.setPackage(packageName);
Dianne Hackborn19415762010-12-15 00:20:27 -0800159 List<ResolveInfo> ris = queryIntentActivities(intentToResolve, 0);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800160
161 // Otherwise, try to find a main launcher activity.
Dianne Hackborn19415762010-12-15 00:20:27 -0800162 if (ris == null || ris.size() <= 0) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800163 // reuse the intent instance
164 intentToResolve.removeCategory(Intent.CATEGORY_INFO);
165 intentToResolve.addCategory(Intent.CATEGORY_LAUNCHER);
166 intentToResolve.setPackage(packageName);
Dianne Hackborn19415762010-12-15 00:20:27 -0800167 ris = queryIntentActivities(intentToResolve, 0);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800168 }
Dianne Hackborn19415762010-12-15 00:20:27 -0800169 if (ris == null || ris.size() <= 0) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800170 return null;
171 }
172 Intent intent = new Intent(intentToResolve);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800173 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Dianne Hackborn19415762010-12-15 00:20:27 -0800174 intent.setClassName(ris.get(0).activityInfo.packageName,
175 ris.get(0).activityInfo.name);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800176 return intent;
177 }
178
179 @Override
Jose Lima970417c2014-04-10 10:42:19 -0700180 public Intent getLeanbackLaunchIntentForPackage(String packageName) {
181 // Try to find a main leanback_launcher activity.
182 Intent intentToResolve = new Intent(Intent.ACTION_MAIN);
183 intentToResolve.addCategory(Intent.CATEGORY_LEANBACK_LAUNCHER);
184 intentToResolve.setPackage(packageName);
185 List<ResolveInfo> ris = queryIntentActivities(intentToResolve, 0);
186
187 if (ris == null || ris.size() <= 0) {
188 return null;
189 }
190 Intent intent = new Intent(intentToResolve);
191 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
192 intent.setClassName(ris.get(0).activityInfo.packageName,
193 ris.get(0).activityInfo.name);
194 return intent;
195 }
196
197 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800198 public int[] getPackageGids(String packageName)
199 throws NameNotFoundException {
200 try {
Svetoslavc6d1c342015-02-26 14:44:43 -0800201 int[] gids = mPM.getPackageGids(packageName, mContext.getUserId());
202 if (gids != null) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800203 return gids;
204 }
205 } catch (RemoteException e) {
206 throw new RuntimeException("Package manager has died", e);
207 }
208
209 throw new NameNotFoundException(packageName);
210 }
211
212 @Override
Dianne Hackborna06de0f2012-12-11 16:34:47 -0800213 public int getPackageUid(String packageName, int userHandle)
214 throws NameNotFoundException {
215 try {
216 int uid = mPM.getPackageUid(packageName, userHandle);
217 if (uid >= 0) {
218 return uid;
219 }
220 } catch (RemoteException e) {
221 throw new RuntimeException("Package manager has died", e);
222 }
223
224 throw new NameNotFoundException(packageName);
225 }
226
227 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800228 public PermissionInfo getPermissionInfo(String name, int flags)
229 throws NameNotFoundException {
230 try {
231 PermissionInfo pi = mPM.getPermissionInfo(name, flags);
232 if (pi != null) {
233 return pi;
234 }
235 } catch (RemoteException e) {
236 throw new RuntimeException("Package manager has died", e);
237 }
238
239 throw new NameNotFoundException(name);
240 }
241
242 @Override
243 public List<PermissionInfo> queryPermissionsByGroup(String group, int flags)
244 throws NameNotFoundException {
245 try {
246 List<PermissionInfo> pi = mPM.queryPermissionsByGroup(group, flags);
247 if (pi != null) {
248 return pi;
249 }
250 } catch (RemoteException e) {
251 throw new RuntimeException("Package manager has died", e);
252 }
253
254 throw new NameNotFoundException(group);
255 }
256
257 @Override
258 public PermissionGroupInfo getPermissionGroupInfo(String name,
259 int flags) throws NameNotFoundException {
260 try {
261 PermissionGroupInfo pgi = mPM.getPermissionGroupInfo(name, flags);
262 if (pgi != null) {
263 return pgi;
264 }
265 } catch (RemoteException e) {
266 throw new RuntimeException("Package manager has died", e);
267 }
268
269 throw new NameNotFoundException(name);
270 }
271
272 @Override
273 public List<PermissionGroupInfo> getAllPermissionGroups(int flags) {
274 try {
275 return mPM.getAllPermissionGroups(flags);
276 } catch (RemoteException e) {
277 throw new RuntimeException("Package manager has died", e);
278 }
279 }
280
281 @Override
282 public ApplicationInfo getApplicationInfo(String packageName, int flags)
283 throws NameNotFoundException {
284 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700285 ApplicationInfo ai = mPM.getApplicationInfo(packageName, flags, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800286 if (ai != null) {
Narayan Kamathcaa71192014-07-16 11:06:43 +0100287 // This is a temporary hack. Callers must use
288 // createPackageContext(packageName).getApplicationInfo() to
289 // get the right paths.
290 maybeAdjustApplicationInfo(ai);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800291 return ai;
292 }
293 } catch (RemoteException e) {
294 throw new RuntimeException("Package manager has died", e);
295 }
296
297 throw new NameNotFoundException(packageName);
298 }
299
Narayan Kamathcaa71192014-07-16 11:06:43 +0100300 private static void maybeAdjustApplicationInfo(ApplicationInfo info) {
301 // If we're dealing with a multi-arch application that has both
302 // 32 and 64 bit shared libraries, we might need to choose the secondary
303 // depending on what the current runtime's instruction set is.
304 if (info.primaryCpuAbi != null && info.secondaryCpuAbi != null) {
305 final String runtimeIsa = VMRuntime.getRuntime().vmInstructionSet();
jgu214741cd92014-12-17 17:23:29 -0500306
307 // Get the instruction set that the libraries of secondary Abi is supported.
308 // In presence of a native bridge this might be different than the one secondary Abi used.
309 String secondaryIsa = VMRuntime.getInstructionSet(info.secondaryCpuAbi);
310 final String secondaryDexCodeIsa = SystemProperties.get("ro.dalvik.vm.isa." + secondaryIsa);
311 secondaryIsa = secondaryDexCodeIsa.isEmpty() ? secondaryIsa : secondaryDexCodeIsa;
Narayan Kamathcaa71192014-07-16 11:06:43 +0100312
313 // If the runtimeIsa is the same as the primary isa, then we do nothing.
314 // Everything will be set up correctly because info.nativeLibraryDir will
315 // correspond to the right ISA.
316 if (runtimeIsa.equals(secondaryIsa)) {
317 info.nativeLibraryDir = info.secondaryNativeLibraryDir;
318 }
319 }
320 }
321
322
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800323 @Override
324 public ActivityInfo getActivityInfo(ComponentName className, int flags)
325 throws NameNotFoundException {
326 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700327 ActivityInfo ai = mPM.getActivityInfo(className, flags, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800328 if (ai != null) {
329 return ai;
330 }
331 } catch (RemoteException e) {
332 throw new RuntimeException("Package manager has died", e);
333 }
334
335 throw new NameNotFoundException(className.toString());
336 }
337
338 @Override
339 public ActivityInfo getReceiverInfo(ComponentName className, int flags)
340 throws NameNotFoundException {
341 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700342 ActivityInfo ai = mPM.getReceiverInfo(className, flags, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800343 if (ai != null) {
344 return ai;
345 }
346 } catch (RemoteException e) {
347 throw new RuntimeException("Package manager has died", e);
348 }
349
350 throw new NameNotFoundException(className.toString());
351 }
352
353 @Override
354 public ServiceInfo getServiceInfo(ComponentName className, int flags)
355 throws NameNotFoundException {
356 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700357 ServiceInfo si = mPM.getServiceInfo(className, flags, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800358 if (si != null) {
359 return si;
360 }
361 } catch (RemoteException e) {
362 throw new RuntimeException("Package manager has died", e);
363 }
364
365 throw new NameNotFoundException(className.toString());
366 }
367
368 @Override
369 public ProviderInfo getProviderInfo(ComponentName className, int flags)
370 throws NameNotFoundException {
371 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700372 ProviderInfo pi = mPM.getProviderInfo(className, flags, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800373 if (pi != null) {
374 return pi;
375 }
376 } catch (RemoteException e) {
377 throw new RuntimeException("Package manager has died", e);
378 }
379
380 throw new NameNotFoundException(className.toString());
381 }
382
383 @Override
384 public String[] getSystemSharedLibraryNames() {
385 try {
386 return mPM.getSystemSharedLibraryNames();
387 } catch (RemoteException e) {
388 throw new RuntimeException("Package manager has died", e);
389 }
390 }
391
392 @Override
393 public FeatureInfo[] getSystemAvailableFeatures() {
394 try {
395 return mPM.getSystemAvailableFeatures();
396 } catch (RemoteException e) {
397 throw new RuntimeException("Package manager has died", e);
398 }
399 }
400
401 @Override
402 public boolean hasSystemFeature(String name) {
403 try {
404 return mPM.hasSystemFeature(name);
405 } catch (RemoteException e) {
406 throw new RuntimeException("Package manager has died", e);
407 }
408 }
409
410 @Override
411 public int checkPermission(String permName, String pkgName) {
412 try {
Svetoslavc6d1c342015-02-26 14:44:43 -0800413 return mPM.checkPermission(permName, pkgName, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800414 } catch (RemoteException e) {
415 throw new RuntimeException("Package manager has died", e);
416 }
417 }
418
419 @Override
420 public boolean addPermission(PermissionInfo info) {
421 try {
422 return mPM.addPermission(info);
423 } catch (RemoteException e) {
424 throw new RuntimeException("Package manager has died", e);
425 }
426 }
427
428 @Override
429 public boolean addPermissionAsync(PermissionInfo info) {
430 try {
431 return mPM.addPermissionAsync(info);
432 } catch (RemoteException e) {
433 throw new RuntimeException("Package manager has died", e);
434 }
435 }
436
437 @Override
438 public void removePermission(String name) {
439 try {
440 mPM.removePermission(name);
441 } catch (RemoteException e) {
442 throw new RuntimeException("Package manager has died", e);
443 }
444 }
445
446 @Override
Svetoslavc6d1c342015-02-26 14:44:43 -0800447 public void grantPermission(String packageName, String permissionName, UserHandle user) {
Dianne Hackborne639da72012-02-21 15:11:13 -0800448 try {
Svetoslavc6d1c342015-02-26 14:44:43 -0800449 mPM.grantPermission(packageName, permissionName, user.getIdentifier());
Dianne Hackborne639da72012-02-21 15:11:13 -0800450 } catch (RemoteException e) {
451 throw new RuntimeException("Package manager has died", e);
452 }
453 }
454
455 @Override
Svetoslavc6d1c342015-02-26 14:44:43 -0800456 public void revokePermission(String packageName, String permissionName, UserHandle user) {
Dianne Hackborne639da72012-02-21 15:11:13 -0800457 try {
Svetoslavc6d1c342015-02-26 14:44:43 -0800458 mPM.revokePermission(packageName, permissionName, user.getIdentifier());
Dianne Hackborne639da72012-02-21 15:11:13 -0800459 } catch (RemoteException e) {
460 throw new RuntimeException("Package manager has died", e);
461 }
462 }
463
464 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800465 public int checkSignatures(String pkg1, String pkg2) {
466 try {
467 return mPM.checkSignatures(pkg1, pkg2);
468 } catch (RemoteException e) {
469 throw new RuntimeException("Package manager has died", e);
470 }
471 }
472
473 @Override
474 public int checkSignatures(int uid1, int uid2) {
475 try {
476 return mPM.checkUidSignatures(uid1, uid2);
477 } catch (RemoteException e) {
478 throw new RuntimeException("Package manager has died", e);
479 }
480 }
481
482 @Override
483 public String[] getPackagesForUid(int uid) {
484 try {
485 return mPM.getPackagesForUid(uid);
486 } catch (RemoteException e) {
487 throw new RuntimeException("Package manager has died", e);
488 }
489 }
490
491 @Override
492 public String getNameForUid(int uid) {
493 try {
494 return mPM.getNameForUid(uid);
495 } catch (RemoteException e) {
496 throw new RuntimeException("Package manager has died", e);
497 }
498 }
499
500 @Override
501 public int getUidForSharedUser(String sharedUserName)
502 throws NameNotFoundException {
503 try {
504 int uid = mPM.getUidForSharedUser(sharedUserName);
505 if(uid != -1) {
506 return uid;
507 }
508 } catch (RemoteException e) {
509 throw new RuntimeException("Package manager has died", e);
510 }
511 throw new NameNotFoundException("No shared userid for user:"+sharedUserName);
512 }
513
Kenny Roote6cd0c72011-05-19 12:48:14 -0700514 @SuppressWarnings("unchecked")
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800515 @Override
516 public List<PackageInfo> getInstalledPackages(int flags) {
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700517 return getInstalledPackages(flags, mContext.getUserId());
Amith Yamasani151ec4c2012-09-07 19:25:16 -0700518 }
519
520 /** @hide */
521 @Override
522 public List<PackageInfo> getInstalledPackages(int flags, int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800523 try {
Dianne Hackbornd8e1dbb2013-01-17 17:47:37 -0800524 ParceledListSlice<PackageInfo> slice = mPM.getInstalledPackages(flags, userId);
525 return slice.getList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800526 } catch (RemoteException e) {
527 throw new RuntimeException("Package manager has died", e);
528 }
529 }
530
Kenny Roote6cd0c72011-05-19 12:48:14 -0700531 @SuppressWarnings("unchecked")
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800532 @Override
Dianne Hackborne7991752013-01-16 17:56:46 -0800533 public List<PackageInfo> getPackagesHoldingPermissions(
534 String[] permissions, int flags) {
535 final int userId = mContext.getUserId();
536 try {
Dianne Hackbornd8e1dbb2013-01-17 17:47:37 -0800537 ParceledListSlice<PackageInfo> slice = mPM.getPackagesHoldingPermissions(
538 permissions, flags, userId);
539 return slice.getList();
Dianne Hackborne7991752013-01-16 17:56:46 -0800540 } catch (RemoteException e) {
541 throw new RuntimeException("Package manager has died", e);
542 }
543 }
544
545 @SuppressWarnings("unchecked")
546 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800547 public List<ApplicationInfo> getInstalledApplications(int flags) {
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700548 final int userId = mContext.getUserId();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800549 try {
Dianne Hackbornd8e1dbb2013-01-17 17:47:37 -0800550 ParceledListSlice<ApplicationInfo> slice = mPM.getInstalledApplications(flags, userId);
551 return slice.getList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800552 } catch (RemoteException e) {
553 throw new RuntimeException("Package manager has died", e);
554 }
555 }
556
557 @Override
558 public ResolveInfo resolveActivity(Intent intent, int flags) {
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700559 return resolveActivityAsUser(intent, flags, mContext.getUserId());
Svetoslav Ganov58d37b52012-09-18 12:04:19 -0700560 }
561
562 @Override
563 public ResolveInfo resolveActivityAsUser(Intent intent, int flags, int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800564 try {
565 return mPM.resolveIntent(
566 intent,
567 intent.resolveTypeIfNeeded(mContext.getContentResolver()),
Svetoslav Ganov58d37b52012-09-18 12:04:19 -0700568 flags,
569 userId);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800570 } catch (RemoteException e) {
571 throw new RuntimeException("Package manager has died", e);
572 }
573 }
574
575 @Override
576 public List<ResolveInfo> queryIntentActivities(Intent intent,
577 int flags) {
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700578 return queryIntentActivitiesAsUser(intent, flags, mContext.getUserId());
Amith Yamasani151ec4c2012-09-07 19:25:16 -0700579 }
580
581 /** @hide Same as above but for a specific user */
582 @Override
Svetoslav Ganov58d37b52012-09-18 12:04:19 -0700583 public List<ResolveInfo> queryIntentActivitiesAsUser(Intent intent,
Amith Yamasani151ec4c2012-09-07 19:25:16 -0700584 int flags, int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800585 try {
586 return mPM.queryIntentActivities(
587 intent,
588 intent.resolveTypeIfNeeded(mContext.getContentResolver()),
Amith Yamasani483f3b02012-03-13 16:08:00 -0700589 flags,
Amith Yamasani151ec4c2012-09-07 19:25:16 -0700590 userId);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800591 } catch (RemoteException e) {
592 throw new RuntimeException("Package manager has died", e);
593 }
594 }
595
596 @Override
597 public List<ResolveInfo> queryIntentActivityOptions(
598 ComponentName caller, Intent[] specifics, Intent intent,
599 int flags) {
600 final ContentResolver resolver = mContext.getContentResolver();
601
602 String[] specificTypes = null;
603 if (specifics != null) {
604 final int N = specifics.length;
605 for (int i=0; i<N; i++) {
606 Intent sp = specifics[i];
607 if (sp != null) {
608 String t = sp.resolveTypeIfNeeded(resolver);
609 if (t != null) {
610 if (specificTypes == null) {
611 specificTypes = new String[N];
612 }
613 specificTypes[i] = t;
614 }
615 }
616 }
617 }
618
619 try {
620 return mPM.queryIntentActivityOptions(caller, specifics,
621 specificTypes, intent, intent.resolveTypeIfNeeded(resolver),
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700622 flags, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800623 } catch (RemoteException e) {
624 throw new RuntimeException("Package manager has died", e);
625 }
626 }
627
Amith Yamasanif203aee2012-08-29 18:41:53 -0700628 /**
629 * @hide
630 */
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800631 @Override
Amith Yamasanif203aee2012-08-29 18:41:53 -0700632 public List<ResolveInfo> queryBroadcastReceivers(Intent intent, int flags, int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800633 try {
634 return mPM.queryIntentReceivers(
635 intent,
636 intent.resolveTypeIfNeeded(mContext.getContentResolver()),
Amith Yamasani483f3b02012-03-13 16:08:00 -0700637 flags,
Amith Yamasanif203aee2012-08-29 18:41:53 -0700638 userId);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800639 } catch (RemoteException e) {
640 throw new RuntimeException("Package manager has died", e);
641 }
642 }
643
644 @Override
Amith Yamasanif203aee2012-08-29 18:41:53 -0700645 public List<ResolveInfo> queryBroadcastReceivers(Intent intent, int flags) {
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700646 return queryBroadcastReceivers(intent, flags, mContext.getUserId());
Amith Yamasanif203aee2012-08-29 18:41:53 -0700647 }
648
649 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800650 public ResolveInfo resolveService(Intent intent, int flags) {
651 try {
652 return mPM.resolveService(
653 intent,
654 intent.resolveTypeIfNeeded(mContext.getContentResolver()),
Amith Yamasani483f3b02012-03-13 16:08:00 -0700655 flags,
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700656 mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800657 } catch (RemoteException e) {
658 throw new RuntimeException("Package manager has died", e);
659 }
660 }
661
662 @Override
Svetoslav Ganov58d37b52012-09-18 12:04:19 -0700663 public List<ResolveInfo> queryIntentServicesAsUser(Intent intent, int flags, int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800664 try {
665 return mPM.queryIntentServices(
666 intent,
667 intent.resolveTypeIfNeeded(mContext.getContentResolver()),
Amith Yamasani483f3b02012-03-13 16:08:00 -0700668 flags,
Svetoslav Ganov58d37b52012-09-18 12:04:19 -0700669 userId);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800670 } catch (RemoteException e) {
671 throw new RuntimeException("Package manager has died", e);
672 }
673 }
674
675 @Override
Svetoslav Ganov58d37b52012-09-18 12:04:19 -0700676 public List<ResolveInfo> queryIntentServices(Intent intent, int flags) {
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700677 return queryIntentServicesAsUser(intent, flags, mContext.getUserId());
Svetoslav Ganov58d37b52012-09-18 12:04:19 -0700678 }
679
680 @Override
Jeff Sharkey85f5f812013-10-07 10:16:12 -0700681 public List<ResolveInfo> queryIntentContentProvidersAsUser(
682 Intent intent, int flags, int userId) {
683 try {
684 return mPM.queryIntentContentProviders(intent,
685 intent.resolveTypeIfNeeded(mContext.getContentResolver()), flags, userId);
686 } catch (RemoteException e) {
687 throw new RuntimeException("Package manager has died", e);
688 }
689 }
690
691 @Override
692 public List<ResolveInfo> queryIntentContentProviders(Intent intent, int flags) {
693 return queryIntentContentProvidersAsUser(intent, flags, mContext.getUserId());
694 }
695
696 @Override
Alexandra Gherghina0363c3e2014-06-23 13:34:59 +0100697 public ProviderInfo resolveContentProvider(String name, int flags) {
698 return resolveContentProviderAsUser(name, flags, mContext.getUserId());
699 }
700
701 /** @hide **/
702 @Override
703 public ProviderInfo resolveContentProviderAsUser(String name, int flags, int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800704 try {
Alexandra Gherghina0363c3e2014-06-23 13:34:59 +0100705 return mPM.resolveContentProvider(name, flags, userId);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800706 } catch (RemoteException e) {
707 throw new RuntimeException("Package manager has died", e);
708 }
709 }
710
711 @Override
712 public List<ProviderInfo> queryContentProviders(String processName,
713 int uid, int flags) {
714 try {
715 return mPM.queryContentProviders(processName, uid, flags);
716 } catch (RemoteException e) {
717 throw new RuntimeException("Package manager has died", e);
718 }
719 }
720
721 @Override
722 public InstrumentationInfo getInstrumentationInfo(
723 ComponentName className, int flags)
724 throws NameNotFoundException {
725 try {
726 InstrumentationInfo ii = mPM.getInstrumentationInfo(
727 className, flags);
728 if (ii != null) {
729 return ii;
730 }
731 } catch (RemoteException e) {
732 throw new RuntimeException("Package manager has died", e);
733 }
734
735 throw new NameNotFoundException(className.toString());
736 }
737
738 @Override
739 public List<InstrumentationInfo> queryInstrumentation(
740 String targetPackage, int flags) {
741 try {
742 return mPM.queryInstrumentation(targetPackage, flags);
743 } catch (RemoteException e) {
744 throw new RuntimeException("Package manager has died", e);
745 }
746 }
747
Alan Viveretteecd585a2015-04-13 10:32:51 -0700748 @Nullable
749 @Override
750 public Drawable getDrawable(String packageName, @DrawableRes int resId,
751 @Nullable ApplicationInfo appInfo) {
752 final ResourceName name = new ResourceName(packageName, resId);
753 final Drawable cachedIcon = getCachedIcon(name);
754 if (cachedIcon != null) {
755 return cachedIcon;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800756 }
Alan Viveretteecd585a2015-04-13 10:32:51 -0700757
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800758 if (appInfo == null) {
759 try {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -0700760 appInfo = getApplicationInfo(packageName, sDefaultFlags);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800761 } catch (NameNotFoundException e) {
762 return null;
763 }
764 }
Alan Viveretteecd585a2015-04-13 10:32:51 -0700765
766 if (resId != 0) {
767 try {
768 final Resources r = getResourcesForApplication(appInfo);
769 final Drawable dr = r.getDrawable(resId, null);
770 if (dr != null) {
771 putCachedIcon(name, dr);
772 }
773
774 if (false) {
775 RuntimeException e = new RuntimeException("here");
776 e.fillInStackTrace();
777 Log.w(TAG, "Getting drawable 0x" + Integer.toHexString(resId)
778 + " from package " + packageName
779 + ": app scale=" + r.getCompatibilityInfo().applicationScale
780 + ", caller scale=" + mContext.getResources()
781 .getCompatibilityInfo().applicationScale,
782 e);
783 }
Ricky Wai3ce46252015-04-15 16:12:22 +0100784 if (DEBUG_ICONS) {
Alan Viveretteecd585a2015-04-13 10:32:51 -0700785 Log.v(TAG, "Getting drawable 0x"
786 + Integer.toHexString(resId) + " from " + r
787 + ": " + dr);
Ricky Wai3ce46252015-04-15 16:12:22 +0100788 }
789 return dr;
Alan Viveretteecd585a2015-04-13 10:32:51 -0700790 } catch (NameNotFoundException e) {
791 Log.w("PackageManager", "Failure retrieving resources for "
792 + appInfo.packageName);
793 } catch (Resources.NotFoundException e) {
794 Log.w("PackageManager", "Failure retrieving resources for "
795 + appInfo.packageName + ": " + e.getMessage());
796 } catch (Exception e) {
797 // If an exception was thrown, fall through to return
798 // default icon.
799 Log.w("PackageManager", "Failure retrieving icon 0x"
800 + Integer.toHexString(resId) + " in package "
801 + packageName, e);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800802 }
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800803 }
Alan Viveretteecd585a2015-04-13 10:32:51 -0700804
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800805 return null;
806 }
807
808 @Override public Drawable getActivityIcon(ComponentName activityName)
809 throws NameNotFoundException {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -0700810 return getActivityInfo(activityName, sDefaultFlags).loadIcon(this);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800811 }
812
813 @Override public Drawable getActivityIcon(Intent intent)
814 throws NameNotFoundException {
815 if (intent.getComponent() != null) {
816 return getActivityIcon(intent.getComponent());
817 }
818
819 ResolveInfo info = resolveActivity(
820 intent, PackageManager.MATCH_DEFAULT_ONLY);
821 if (info != null) {
822 return info.activityInfo.loadIcon(this);
823 }
824
Romain Guy39fe17c2011-11-30 10:34:07 -0800825 throw new NameNotFoundException(intent.toUri(0));
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800826 }
827
828 @Override public Drawable getDefaultActivityIcon() {
829 return Resources.getSystem().getDrawable(
830 com.android.internal.R.drawable.sym_def_app_icon);
831 }
832
833 @Override public Drawable getApplicationIcon(ApplicationInfo info) {
834 return info.loadIcon(this);
835 }
836
837 @Override public Drawable getApplicationIcon(String packageName)
838 throws NameNotFoundException {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -0700839 return getApplicationIcon(getApplicationInfo(packageName, sDefaultFlags));
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800840 }
841
842 @Override
Jose Limaf78e3122014-03-06 12:13:15 -0800843 public Drawable getActivityBanner(ComponentName activityName)
844 throws NameNotFoundException {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -0700845 return getActivityInfo(activityName, sDefaultFlags).loadBanner(this);
Jose Limaf78e3122014-03-06 12:13:15 -0800846 }
847
848 @Override
849 public Drawable getActivityBanner(Intent intent)
850 throws NameNotFoundException {
851 if (intent.getComponent() != null) {
852 return getActivityBanner(intent.getComponent());
853 }
854
855 ResolveInfo info = resolveActivity(
856 intent, PackageManager.MATCH_DEFAULT_ONLY);
857 if (info != null) {
858 return info.activityInfo.loadBanner(this);
859 }
860
861 throw new NameNotFoundException(intent.toUri(0));
862 }
863
864 @Override
865 public Drawable getApplicationBanner(ApplicationInfo info) {
866 return info.loadBanner(this);
867 }
868
869 @Override
870 public Drawable getApplicationBanner(String packageName)
871 throws NameNotFoundException {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -0700872 return getApplicationBanner(getApplicationInfo(packageName, sDefaultFlags));
Jose Limaf78e3122014-03-06 12:13:15 -0800873 }
874
875 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800876 public Drawable getActivityLogo(ComponentName activityName)
877 throws NameNotFoundException {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -0700878 return getActivityInfo(activityName, sDefaultFlags).loadLogo(this);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800879 }
880
881 @Override
882 public Drawable getActivityLogo(Intent intent)
883 throws NameNotFoundException {
884 if (intent.getComponent() != null) {
885 return getActivityLogo(intent.getComponent());
886 }
887
888 ResolveInfo info = resolveActivity(
889 intent, PackageManager.MATCH_DEFAULT_ONLY);
890 if (info != null) {
891 return info.activityInfo.loadLogo(this);
892 }
893
894 throw new NameNotFoundException(intent.toUri(0));
895 }
896
897 @Override
898 public Drawable getApplicationLogo(ApplicationInfo info) {
899 return info.loadLogo(this);
900 }
901
902 @Override
903 public Drawable getApplicationLogo(String packageName)
904 throws NameNotFoundException {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -0700905 return getApplicationLogo(getApplicationInfo(packageName, sDefaultFlags));
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800906 }
907
Svetoslavc7d62f02014-09-04 15:39:54 -0700908 @Override
909 public Drawable getUserBadgedIcon(Drawable icon, UserHandle user) {
910 final int badgeResId = getBadgeResIdForUser(user.getIdentifier());
911 if (badgeResId == 0) {
912 return icon;
913 }
914 Drawable badgeIcon = getDrawable("system", badgeResId, null);
915 return getBadgedDrawable(icon, badgeIcon, null, true);
916 }
917
918 @Override
919 public Drawable getUserBadgedDrawableForDensity(Drawable drawable, UserHandle user,
920 Rect badgeLocation, int badgeDensity) {
921 Drawable badgeDrawable = getUserBadgeForDensity(user, badgeDensity);
922 if (badgeDrawable == null) {
923 return drawable;
924 }
925 return getBadgedDrawable(drawable, badgeDrawable, badgeLocation, true);
926 }
927
928 @Override
929 public Drawable getUserBadgeForDensity(UserHandle user, int density) {
930 UserInfo userInfo = getUserIfProfile(user.getIdentifier());
931 if (userInfo != null && userInfo.isManagedProfile()) {
932 if (density <= 0) {
933 density = mContext.getResources().getDisplayMetrics().densityDpi;
934 }
935 return Resources.getSystem().getDrawableForDensity(
936 com.android.internal.R.drawable.ic_corp_badge, density);
937 }
938 return null;
939 }
940
941 @Override
942 public CharSequence getUserBadgedLabel(CharSequence label, UserHandle user) {
943 UserInfo userInfo = getUserIfProfile(user.getIdentifier());
944 if (userInfo != null && userInfo.isManagedProfile()) {
945 return Resources.getSystem().getString(
946 com.android.internal.R.string.managed_profile_label_badge, label);
947 }
948 return label;
949 }
950
Alan Viveretteecd585a2015-04-13 10:32:51 -0700951 @Override
952 public Resources getResourcesForActivity(ComponentName activityName)
953 throws NameNotFoundException {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800954 return getResourcesForApplication(
Adam Lesinskid00bb5e2014-10-07 12:14:45 -0700955 getActivityInfo(activityName, sDefaultFlags).applicationInfo);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800956 }
957
Alan Viveretteecd585a2015-04-13 10:32:51 -0700958 @Override
959 public Resources getResourcesForApplication(@NonNull ApplicationInfo app)
960 throws NameNotFoundException {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800961 if (app.packageName.equals("system")) {
962 return mContext.mMainThread.getSystemContext().getResources();
963 }
Jeff Sharkey8a4c9722014-06-16 13:48:42 -0700964 final boolean sameUid = (app.uid == Process.myUid());
Alan Viveretteecd585a2015-04-13 10:32:51 -0700965 final Resources r = mContext.mMainThread.getTopLevelResources(
Jeff Sharkey8a4c9722014-06-16 13:48:42 -0700966 sameUid ? app.sourceDir : app.publicSourceDir,
967 sameUid ? app.splitSourceDirs : app.splitPublicSourceDirs,
Adam Lesinskid00bb5e2014-10-07 12:14:45 -0700968 app.resourceDirs, app.sharedLibraryFiles, Display.DEFAULT_DISPLAY,
969 null, mContext.mPackageInfo);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800970 if (r != null) {
971 return r;
972 }
973 throw new NameNotFoundException("Unable to open " + app.publicSourceDir);
974 }
975
Alan Viveretteecd585a2015-04-13 10:32:51 -0700976 @Override
977 public Resources getResourcesForApplication(String appPackageName)
978 throws NameNotFoundException {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800979 return getResourcesForApplication(
Adam Lesinskid00bb5e2014-10-07 12:14:45 -0700980 getApplicationInfo(appPackageName, sDefaultFlags));
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800981 }
982
Amith Yamasani98edc952012-09-25 14:09:27 -0700983 /** @hide */
984 @Override
985 public Resources getResourcesForApplicationAsUser(String appPackageName, int userId)
986 throws NameNotFoundException {
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700987 if (userId < 0) {
988 throw new IllegalArgumentException(
989 "Call does not support special user #" + userId);
990 }
991 if ("system".equals(appPackageName)) {
992 return mContext.mMainThread.getSystemContext().getResources();
993 }
Amith Yamasani98edc952012-09-25 14:09:27 -0700994 try {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -0700995 ApplicationInfo ai = mPM.getApplicationInfo(appPackageName, sDefaultFlags, userId);
Amith Yamasani98edc952012-09-25 14:09:27 -0700996 if (ai != null) {
997 return getResourcesForApplication(ai);
998 }
999 } catch (RemoteException e) {
1000 throw new RuntimeException("Package manager has died", e);
1001 }
1002 throw new NameNotFoundException("Package " + appPackageName + " doesn't exist");
1003 }
1004
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001005 int mCachedSafeMode = -1;
1006 @Override public boolean isSafeMode() {
1007 try {
1008 if (mCachedSafeMode < 0) {
1009 mCachedSafeMode = mPM.isSafeMode() ? 1 : 0;
1010 }
1011 return mCachedSafeMode != 0;
1012 } catch (RemoteException e) {
1013 throw new RuntimeException("Package manager has died", e);
1014 }
1015 }
1016
1017 static void configurationChanged() {
1018 synchronized (sSync) {
1019 sIconCache.clear();
1020 sStringCache.clear();
1021 }
1022 }
1023
1024 ApplicationPackageManager(ContextImpl context,
1025 IPackageManager pm) {
1026 mContext = context;
1027 mPM = pm;
1028 }
1029
Alan Viveretteecd585a2015-04-13 10:32:51 -07001030 @Nullable
1031 private Drawable getCachedIcon(@NonNull ResourceName name) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001032 synchronized (sSync) {
Alan Viveretteecd585a2015-04-13 10:32:51 -07001033 final WeakReference<Drawable.ConstantState> wr = sIconCache.get(name);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001034 if (DEBUG_ICONS) Log.v(TAG, "Get cached weak drawable ref for "
1035 + name + ": " + wr);
1036 if (wr != null) { // we have the activity
Alan Viveretteecd585a2015-04-13 10:32:51 -07001037 final Drawable.ConstantState state = wr.get();
Romain Guy39fe17c2011-11-30 10:34:07 -08001038 if (state != null) {
1039 if (DEBUG_ICONS) {
1040 Log.v(TAG, "Get cached drawable state for " + name + ": " + state);
1041 }
1042 // Note: It's okay here to not use the newDrawable(Resources) variant
1043 // of the API. The ConstantState comes from a drawable that was
1044 // originally created by passing the proper app Resources instance
1045 // which means the state should already contain the proper
1046 // resources specific information (like density.) See
1047 // BitmapDrawable.BitmapState for instance.
1048 return state.newDrawable();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001049 }
1050 // our entry has been purged
1051 sIconCache.remove(name);
1052 }
1053 }
1054 return null;
1055 }
1056
Alan Viveretteecd585a2015-04-13 10:32:51 -07001057 private void putCachedIcon(@NonNull ResourceName name, @NonNull Drawable dr) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001058 synchronized (sSync) {
Alan Viveretteecd585a2015-04-13 10:32:51 -07001059 sIconCache.put(name, new WeakReference<>(dr.getConstantState()));
Romain Guy39fe17c2011-11-30 10:34:07 -08001060 if (DEBUG_ICONS) Log.v(TAG, "Added cached drawable state for " + name + ": " + dr);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001061 }
1062 }
1063
Romain Guy39fe17c2011-11-30 10:34:07 -08001064 static void handlePackageBroadcast(int cmd, String[] pkgList, boolean hasPkgInfo) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001065 boolean immediateGc = false;
1066 if (cmd == IApplicationThread.EXTERNAL_STORAGE_UNAVAILABLE) {
1067 immediateGc = true;
1068 }
1069 if (pkgList != null && (pkgList.length > 0)) {
1070 boolean needCleanup = false;
1071 for (String ssp : pkgList) {
1072 synchronized (sSync) {
Dianne Hackbornadd005c2013-07-17 18:43:12 -07001073 for (int i=sIconCache.size()-1; i>=0; i--) {
1074 ResourceName nm = sIconCache.keyAt(i);
1075 if (nm.packageName.equals(ssp)) {
1076 //Log.i(TAG, "Removing cached drawable for " + nm);
1077 sIconCache.removeAt(i);
1078 needCleanup = true;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001079 }
1080 }
Dianne Hackbornadd005c2013-07-17 18:43:12 -07001081 for (int i=sStringCache.size()-1; i>=0; i--) {
1082 ResourceName nm = sStringCache.keyAt(i);
1083 if (nm.packageName.equals(ssp)) {
1084 //Log.i(TAG, "Removing cached string for " + nm);
1085 sStringCache.removeAt(i);
1086 needCleanup = true;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001087 }
1088 }
1089 }
1090 }
1091 if (needCleanup || hasPkgInfo) {
1092 if (immediateGc) {
1093 // Schedule an immediate gc.
1094 Runtime.getRuntime().gc();
1095 } else {
1096 ActivityThread.currentActivityThread().scheduleGcIdler();
1097 }
1098 }
1099 }
1100 }
1101
1102 private static final class ResourceName {
1103 final String packageName;
1104 final int iconId;
1105
1106 ResourceName(String _packageName, int _iconId) {
1107 packageName = _packageName;
1108 iconId = _iconId;
1109 }
1110
1111 ResourceName(ApplicationInfo aInfo, int _iconId) {
1112 this(aInfo.packageName, _iconId);
1113 }
1114
1115 ResourceName(ComponentInfo cInfo, int _iconId) {
1116 this(cInfo.applicationInfo.packageName, _iconId);
1117 }
1118
1119 ResourceName(ResolveInfo rInfo, int _iconId) {
1120 this(rInfo.activityInfo.applicationInfo.packageName, _iconId);
1121 }
1122
1123 @Override
1124 public boolean equals(Object o) {
1125 if (this == o) return true;
1126 if (o == null || getClass() != o.getClass()) return false;
1127
1128 ResourceName that = (ResourceName) o;
1129
1130 if (iconId != that.iconId) return false;
1131 return !(packageName != null ?
1132 !packageName.equals(that.packageName) : that.packageName != null);
1133
1134 }
1135
1136 @Override
1137 public int hashCode() {
1138 int result;
1139 result = packageName.hashCode();
1140 result = 31 * result + iconId;
1141 return result;
1142 }
1143
1144 @Override
1145 public String toString() {
1146 return "{ResourceName " + packageName + " / " + iconId + "}";
1147 }
1148 }
1149
1150 private CharSequence getCachedString(ResourceName name) {
1151 synchronized (sSync) {
1152 WeakReference<CharSequence> wr = sStringCache.get(name);
1153 if (wr != null) { // we have the activity
1154 CharSequence cs = wr.get();
1155 if (cs != null) {
1156 return cs;
1157 }
1158 // our entry has been purged
1159 sStringCache.remove(name);
1160 }
1161 }
1162 return null;
1163 }
1164
1165 private void putCachedString(ResourceName name, CharSequence cs) {
1166 synchronized (sSync) {
1167 sStringCache.put(name, new WeakReference<CharSequence>(cs));
1168 }
1169 }
1170
1171 @Override
Tor Norbye7b9c9122013-05-30 16:48:33 -07001172 public CharSequence getText(String packageName, @StringRes int resid,
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001173 ApplicationInfo appInfo) {
1174 ResourceName name = new ResourceName(packageName, resid);
1175 CharSequence text = getCachedString(name);
1176 if (text != null) {
1177 return text;
1178 }
1179 if (appInfo == null) {
1180 try {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001181 appInfo = getApplicationInfo(packageName, sDefaultFlags);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001182 } catch (NameNotFoundException e) {
1183 return null;
1184 }
1185 }
1186 try {
1187 Resources r = getResourcesForApplication(appInfo);
1188 text = r.getText(resid);
1189 putCachedString(name, text);
1190 return text;
1191 } catch (NameNotFoundException e) {
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07001192 Log.w("PackageManager", "Failure retrieving resources for "
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001193 + appInfo.packageName);
1194 } catch (RuntimeException e) {
1195 // If an exception was thrown, fall through to return
1196 // default icon.
1197 Log.w("PackageManager", "Failure retrieving text 0x"
1198 + Integer.toHexString(resid) + " in package "
1199 + packageName, e);
1200 }
1201 return null;
1202 }
1203
1204 @Override
Tor Norbye7b9c9122013-05-30 16:48:33 -07001205 public XmlResourceParser getXml(String packageName, @XmlRes int resid,
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001206 ApplicationInfo appInfo) {
1207 if (appInfo == null) {
1208 try {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001209 appInfo = getApplicationInfo(packageName, sDefaultFlags);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001210 } catch (NameNotFoundException e) {
1211 return null;
1212 }
1213 }
1214 try {
1215 Resources r = getResourcesForApplication(appInfo);
1216 return r.getXml(resid);
1217 } catch (RuntimeException e) {
1218 // If an exception was thrown, fall through to return
1219 // default icon.
1220 Log.w("PackageManager", "Failure retrieving xml 0x"
1221 + Integer.toHexString(resid) + " in package "
1222 + packageName, e);
1223 } catch (NameNotFoundException e) {
Alon Albert3fa51e32010-11-11 09:24:04 -08001224 Log.w("PackageManager", "Failure retrieving resources for "
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001225 + appInfo.packageName);
1226 }
1227 return null;
1228 }
1229
1230 @Override
1231 public CharSequence getApplicationLabel(ApplicationInfo info) {
1232 return info.loadLabel(this);
1233 }
1234
1235 @Override
1236 public void installPackage(Uri packageURI, IPackageInstallObserver observer, int flags,
1237 String installerPackageName) {
Jeff Sharkey513a0742014-07-08 17:10:32 -07001238 final VerificationParams verificationParams = new VerificationParams(null, null,
1239 null, VerificationParams.NO_UID, null);
1240 installCommon(packageURI, new LegacyPackageInstallObserver(observer), flags,
1241 installerPackageName, verificationParams, null);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001242 }
1243
1244 @Override
Kenny Root5ab21572011-07-27 11:11:19 -07001245 public void installPackageWithVerification(Uri packageURI, IPackageInstallObserver observer,
1246 int flags, String installerPackageName, Uri verificationURI,
Rich Canningse1d7c712012-08-08 12:46:06 -07001247 ManifestDigest manifestDigest, ContainerEncryptionParams encryptionParams) {
Jeff Sharkey513a0742014-07-08 17:10:32 -07001248 final VerificationParams verificationParams = new VerificationParams(verificationURI, null,
1249 null, VerificationParams.NO_UID, manifestDigest);
1250 installCommon(packageURI, new LegacyPackageInstallObserver(observer), flags,
1251 installerPackageName, verificationParams, encryptionParams);
Kenny Root5ab21572011-07-27 11:11:19 -07001252 }
1253
1254 @Override
John Spurlock8a985d22014-02-25 09:40:05 -05001255 public void installPackageWithVerificationAndEncryption(Uri packageURI,
rich cannings706e8ba2012-08-20 13:20:14 -07001256 IPackageInstallObserver observer, int flags, String installerPackageName,
1257 VerificationParams verificationParams, ContainerEncryptionParams encryptionParams) {
Jeff Sharkey513a0742014-07-08 17:10:32 -07001258 installCommon(packageURI, new LegacyPackageInstallObserver(observer), flags,
1259 installerPackageName, verificationParams, encryptionParams);
Christopher Tatef1977b42014-03-24 16:25:51 -07001260 }
1261
Christopher Tatef1977b42014-03-24 16:25:51 -07001262 @Override
1263 public void installPackage(Uri packageURI, PackageInstallObserver observer,
1264 int flags, String installerPackageName) {
Jeff Sharkey513a0742014-07-08 17:10:32 -07001265 final VerificationParams verificationParams = new VerificationParams(null, null,
1266 null, VerificationParams.NO_UID, null);
1267 installCommon(packageURI, observer, flags, installerPackageName, verificationParams, null);
Christopher Tatef1977b42014-03-24 16:25:51 -07001268 }
1269
1270 @Override
1271 public void installPackageWithVerification(Uri packageURI,
1272 PackageInstallObserver observer, int flags, String installerPackageName,
1273 Uri verificationURI, ManifestDigest manifestDigest,
1274 ContainerEncryptionParams encryptionParams) {
Jeff Sharkey513a0742014-07-08 17:10:32 -07001275 final VerificationParams verificationParams = new VerificationParams(verificationURI, null,
1276 null, VerificationParams.NO_UID, manifestDigest);
1277 installCommon(packageURI, observer, flags, installerPackageName, verificationParams,
1278 encryptionParams);
Christopher Tatef1977b42014-03-24 16:25:51 -07001279 }
1280
1281 @Override
1282 public void installPackageWithVerificationAndEncryption(Uri packageURI,
1283 PackageInstallObserver observer, int flags, String installerPackageName,
1284 VerificationParams verificationParams, ContainerEncryptionParams encryptionParams) {
Jeff Sharkey513a0742014-07-08 17:10:32 -07001285 installCommon(packageURI, observer, flags, installerPackageName, verificationParams,
1286 encryptionParams);
1287 }
1288
1289 private void installCommon(Uri packageURI,
1290 PackageInstallObserver observer, int flags, String installerPackageName,
1291 VerificationParams verificationParams, ContainerEncryptionParams encryptionParams) {
1292 if (!"file".equals(packageURI.getScheme())) {
1293 throw new UnsupportedOperationException("Only file:// URIs are supported");
1294 }
1295 if (encryptionParams != null) {
1296 throw new UnsupportedOperationException("ContainerEncryptionParams not supported");
1297 }
1298
1299 final String originPath = packageURI.getPath();
Christopher Tatef1977b42014-03-24 16:25:51 -07001300 try {
Jeff Sharkey513a0742014-07-08 17:10:32 -07001301 mPM.installPackage(originPath, observer.getBinder(), flags, installerPackageName,
1302 verificationParams, null);
1303 } catch (RemoteException ignored) {
rich cannings706e8ba2012-08-20 13:20:14 -07001304 }
1305 }
1306
1307 @Override
Dianne Hackborn7767eac2012-08-23 18:25:40 -07001308 public int installExistingPackage(String packageName)
1309 throws NameNotFoundException {
1310 try {
Amith Yamasani67df64b2012-12-14 12:09:36 -08001311 int res = mPM.installExistingPackageAsUser(packageName, UserHandle.myUserId());
Dianne Hackborn7767eac2012-08-23 18:25:40 -07001312 if (res == INSTALL_FAILED_INVALID_URI) {
1313 throw new NameNotFoundException("Package " + packageName + " doesn't exist");
1314 }
1315 return res;
1316 } catch (RemoteException e) {
1317 // Should never happen!
1318 throw new NameNotFoundException("Package " + packageName + " doesn't exist");
1319 }
1320 }
1321
1322 @Override
Kenny Root3a9b5fb2011-09-20 14:15:38 -07001323 public void verifyPendingInstall(int id, int response) {
Kenny Root5ab21572011-07-27 11:11:19 -07001324 try {
Kenny Root3a9b5fb2011-09-20 14:15:38 -07001325 mPM.verifyPendingInstall(id, response);
Kenny Root5ab21572011-07-27 11:11:19 -07001326 } catch (RemoteException e) {
1327 // Should never happen!
1328 }
1329 }
1330
1331 @Override
rich canningsd9ef3e52012-08-22 14:28:05 -07001332 public void extendVerificationTimeout(int id, int verificationCodeAtTimeout,
1333 long millisecondsToDelay) {
1334 try {
1335 mPM.extendVerificationTimeout(id, verificationCodeAtTimeout, millisecondsToDelay);
1336 } catch (RemoteException e) {
1337 // Should never happen!
1338 }
1339 }
1340
1341 @Override
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001342 public void verifyIntentFilter(int id, int verificationCode, List<String> outFailedDomains) {
1343 try {
1344 mPM.verifyIntentFilter(id, verificationCode, outFailedDomains);
1345 } catch (RemoteException e) {
1346 // Should never happen!
1347 }
1348 }
1349
1350 @Override
1351 public int getIntentVerificationStatus(String packageName, int userId) {
1352 try {
1353 return mPM.getIntentVerificationStatus(packageName, userId);
1354 } catch (RemoteException e) {
1355 // Should never happen!
1356 return PackageManager.INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_UNDEFINED;
1357 }
1358 }
1359
1360 @Override
1361 public boolean updateIntentVerificationStatus(String packageName, int status, int userId) {
1362 try {
1363 return mPM.updateIntentVerificationStatus(packageName, status, userId);
1364 } catch (RemoteException e) {
1365 // Should never happen!
1366 return false;
1367 }
1368 }
1369
1370 @Override
1371 public List<IntentFilterVerificationInfo> getIntentFilterVerifications(String packageName) {
1372 try {
1373 return mPM.getIntentFilterVerifications(packageName);
1374 } catch (RemoteException e) {
1375 // Should never happen!
1376 return null;
1377 }
1378 }
1379
1380 @Override
Fabrice Di Meglio07885952015-04-06 19:41:28 -07001381 public List<IntentFilter> getAllIntentFilters(String packageName) {
1382 try {
1383 return mPM.getAllIntentFilters(packageName);
1384 } catch (RemoteException e) {
1385 // Should never happen!
1386 return null;
1387 }
1388 }
1389
1390 @Override
Fabrice Di Meglio62271722015-04-10 17:24:02 -07001391 public String getDefaultBrowserPackageName(int userId) {
1392 try {
1393 return mPM.getDefaultBrowserPackageName(userId);
1394 } catch (RemoteException e) {
1395 // Should never happen!
1396 return null;
1397 }
1398 }
1399
1400 @Override
1401 public boolean setDefaultBrowserPackageName(String packageName, int userId) {
1402 try {
1403 return mPM.setDefaultBrowserPackageName(packageName, userId);
1404 } catch (RemoteException e) {
1405 // Should never happen!
1406 return false;
1407 }
1408 }
1409
1410 @Override
Dianne Hackborn880119b2010-11-18 22:26:40 -08001411 public void setInstallerPackageName(String targetPackage,
1412 String installerPackageName) {
1413 try {
1414 mPM.setInstallerPackageName(targetPackage, installerPackageName);
1415 } catch (RemoteException e) {
1416 // Should never happen!
1417 }
1418 }
1419
1420 @Override
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001421 public String getInstallerPackageName(String packageName) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001422 try {
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001423 return mPM.getInstallerPackageName(packageName);
1424 } catch (RemoteException e) {
1425 // Should never happen!
1426 }
1427 return null;
1428 }
1429
1430 @Override
1431 public int getMoveStatus(int moveId) {
1432 try {
1433 return mPM.getMoveStatus(moveId);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001434 } catch (RemoteException e) {
Jeff Sharkeyb2b9ab82015-04-05 21:10:42 -07001435 throw e.rethrowAsRuntimeException();
1436 }
1437 }
1438
1439 @Override
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001440 public void registerMoveCallback(MoveCallback callback, Handler handler) {
1441 synchronized (mDelegates) {
1442 final MoveCallbackDelegate delegate = new MoveCallbackDelegate(callback,
1443 handler.getLooper());
1444 try {
1445 mPM.registerMoveCallback(delegate);
1446 } catch (RemoteException e) {
1447 throw e.rethrowAsRuntimeException();
1448 }
1449 mDelegates.add(delegate);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001450 }
1451 }
1452
1453 @Override
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001454 public void unregisterMoveCallback(MoveCallback callback) {
1455 synchronized (mDelegates) {
1456 for (Iterator<MoveCallbackDelegate> i = mDelegates.iterator(); i.hasNext();) {
1457 final MoveCallbackDelegate delegate = i.next();
1458 if (delegate.mCallback == callback) {
1459 try {
1460 mPM.unregisterMoveCallback(delegate);
1461 } catch (RemoteException e) {
1462 throw e.rethrowAsRuntimeException();
1463 }
1464 i.remove();
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001465 }
1466 }
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001467 }
1468 }
1469
1470 @Override
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001471 public int movePackage(String packageName, VolumeInfo vol) {
1472 try {
1473 final String volumeUuid;
1474 if (VolumeInfo.ID_PRIVATE_INTERNAL.equals(vol.id)) {
1475 volumeUuid = StorageManager.UUID_PRIVATE_INTERNAL;
1476 } else if (vol.isPrimaryPhysical()) {
1477 volumeUuid = StorageManager.UUID_PRIMARY_PHYSICAL;
1478 } else {
1479 volumeUuid = Preconditions.checkNotNull(vol.fsUuid);
1480 }
1481
1482 return mPM.movePackage(packageName, volumeUuid);
1483 } catch (RemoteException e) {
1484 throw e.rethrowAsRuntimeException();
1485 }
1486 }
1487
1488 @Override
1489 public @Nullable VolumeInfo getPackageCurrentVolume(ApplicationInfo app) {
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001490 final StorageManager storage = mContext.getSystemService(StorageManager.class);
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001491 if (app.isInternal()) {
1492 return storage.findVolumeById(VolumeInfo.ID_PRIVATE_INTERNAL);
1493 } else if (app.isExternalAsec()) {
1494 return storage.getPrimaryPhysicalVolume();
1495 } else {
1496 return storage.findVolumeByUuid(app.volumeUuid);
1497 }
1498 }
1499
1500 @Override
1501 public @NonNull List<VolumeInfo> getPackageCandidateVolumes(ApplicationInfo app) {
1502 final StorageManager storage = mContext.getSystemService(StorageManager.class);
1503 final VolumeInfo currentVol = getPackageCurrentVolume(app);
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001504 final List<VolumeInfo> vols = storage.getVolumes();
1505 final List<VolumeInfo> candidates = new ArrayList<>();
1506 for (VolumeInfo vol : vols) {
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001507 if (Objects.equals(vol, currentVol) || isPackageCandidateVolume(app, vol)) {
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001508 candidates.add(vol);
1509 }
1510 }
1511 return candidates;
1512 }
1513
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001514 private static boolean isPackageCandidateVolume(ApplicationInfo app, VolumeInfo vol) {
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001515 // Private internal is always an option
1516 if (VolumeInfo.ID_PRIVATE_INTERNAL.equals(vol.getId())) {
1517 return true;
1518 }
1519
1520 // System apps and apps demanding internal storage can't be moved
1521 // anywhere else
1522 if (app.isSystemApp()
1523 || app.installLocation == PackageInfo.INSTALL_LOCATION_INTERNAL_ONLY) {
1524 return false;
1525 }
1526
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001527 // Gotta be able to write there
1528 if (!vol.isMountedWritable()) {
1529 return false;
1530 }
1531
1532 // Moving into an ASEC on public primary is only option internal
1533 if (vol.isPrimaryPhysical()) {
1534 return app.isInternal();
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001535 }
1536
1537 // Otherwise we can move to any private volume
1538 return (vol.getType() == VolumeInfo.TYPE_PRIVATE);
1539 }
1540
1541 @Override
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001542 public int movePrimaryStorage(VolumeInfo vol) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001543 try {
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001544 final String volumeUuid;
1545 if (VolumeInfo.ID_PRIVATE_INTERNAL.equals(vol.id)) {
1546 volumeUuid = StorageManager.UUID_PRIVATE_INTERNAL;
1547 } else if (vol.isPrimaryPhysical()) {
1548 volumeUuid = StorageManager.UUID_PRIMARY_PHYSICAL;
1549 } else {
1550 volumeUuid = Preconditions.checkNotNull(vol.fsUuid);
1551 }
1552
1553 return mPM.movePrimaryStorage(volumeUuid);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001554 } catch (RemoteException e) {
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001555 throw e.rethrowAsRuntimeException();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001556 }
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001557 }
1558
1559 public @Nullable VolumeInfo getPrimaryStorageCurrentVolume() {
1560 final StorageManager storage = mContext.getSystemService(StorageManager.class);
1561 final String volumeUuid = storage.getPrimaryStorageUuid();
1562 if (Objects.equals(StorageManager.UUID_PRIVATE_INTERNAL, volumeUuid)) {
1563 return storage.findVolumeById(VolumeInfo.ID_PRIVATE_INTERNAL);
1564 } else if (Objects.equals(StorageManager.UUID_PRIMARY_PHYSICAL, volumeUuid)) {
1565 return storage.getPrimaryPhysicalVolume();
1566 } else {
1567 return storage.findVolumeByUuid(volumeUuid);
1568 }
1569 }
1570
1571 public @NonNull List<VolumeInfo> getPrimaryStorageCandidateVolumes() {
1572 final StorageManager storage = mContext.getSystemService(StorageManager.class);
1573 final VolumeInfo currentVol = getPrimaryStorageCurrentVolume();
1574 final List<VolumeInfo> vols = storage.getVolumes();
1575 final List<VolumeInfo> candidates = new ArrayList<>();
1576 for (VolumeInfo vol : vols) {
1577 if (Objects.equals(vol, currentVol) || isPrimaryStorageCandidateVolume(vol)) {
1578 candidates.add(vol);
1579 }
1580 }
1581 return candidates;
1582 }
1583
1584 private static boolean isPrimaryStorageCandidateVolume(VolumeInfo vol) {
1585 // Private internal is always an option
1586 if (VolumeInfo.ID_PRIVATE_INTERNAL.equals(vol.getId())) {
1587 return true;
1588 }
1589
1590 // Gotta be able to write there
1591 if (!vol.isMountedWritable()) {
1592 return false;
1593 }
1594
1595 // We can move to public volumes on legacy devices
1596 if ((vol.getType() == VolumeInfo.TYPE_PUBLIC) && vol.getDisk().isDefaultPrimary()) {
1597 return true;
1598 }
1599
1600 // Otherwise we can move to any private volume
1601 return (vol.getType() == VolumeInfo.TYPE_PRIVATE);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001602 }
1603
1604 @Override
1605 public void deletePackage(String packageName, IPackageDeleteObserver observer, int flags) {
1606 try {
Amith Yamasani67df64b2012-12-14 12:09:36 -08001607 mPM.deletePackageAsUser(packageName, observer, UserHandle.myUserId(), flags);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001608 } catch (RemoteException e) {
1609 // Should never happen!
1610 }
1611 }
Jeff Sharkeyfbd0e9f2014-08-06 16:34:34 -07001612
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001613 @Override
1614 public void clearApplicationUserData(String packageName,
1615 IPackageDataObserver observer) {
1616 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -07001617 mPM.clearApplicationUserData(packageName, observer, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001618 } catch (RemoteException e) {
1619 // Should never happen!
1620 }
1621 }
1622 @Override
1623 public void deleteApplicationCacheFiles(String packageName,
1624 IPackageDataObserver observer) {
1625 try {
1626 mPM.deleteApplicationCacheFiles(packageName, observer);
1627 } catch (RemoteException e) {
1628 // Should never happen!
1629 }
1630 }
Jeff Sharkey529f91f2015-04-18 20:23:13 -07001631
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001632 @Override
Jeff Sharkey529f91f2015-04-18 20:23:13 -07001633 public void freeStorageAndNotify(String volumeUuid, long idealStorageSize,
1634 IPackageDataObserver observer) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001635 try {
Jeff Sharkey529f91f2015-04-18 20:23:13 -07001636 mPM.freeStorageAndNotify(volumeUuid, idealStorageSize, observer);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001637 } catch (RemoteException e) {
1638 // Should never happen!
1639 }
1640 }
1641
1642 @Override
Jeff Sharkey529f91f2015-04-18 20:23:13 -07001643 public void freeStorage(String volumeUuid, long freeStorageSize, IntentSender pi) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001644 try {
Jeff Sharkey529f91f2015-04-18 20:23:13 -07001645 mPM.freeStorage(volumeUuid, freeStorageSize, pi);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001646 } catch (RemoteException e) {
1647 // Should never happen!
1648 }
1649 }
1650
1651 @Override
Dianne Hackborn0c380492012-08-20 17:23:30 -07001652 public void getPackageSizeInfo(String packageName, int userHandle,
1653 IPackageStatsObserver observer) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001654 try {
Dianne Hackborn0c380492012-08-20 17:23:30 -07001655 mPM.getPackageSizeInfo(packageName, userHandle, observer);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001656 } catch (RemoteException e) {
1657 // Should never happen!
1658 }
1659 }
1660 @Override
1661 public void addPackageToPreferred(String packageName) {
1662 try {
1663 mPM.addPackageToPreferred(packageName);
1664 } catch (RemoteException e) {
1665 // Should never happen!
1666 }
1667 }
1668
1669 @Override
1670 public void removePackageFromPreferred(String packageName) {
1671 try {
1672 mPM.removePackageFromPreferred(packageName);
1673 } catch (RemoteException e) {
1674 // Should never happen!
1675 }
1676 }
1677
1678 @Override
1679 public List<PackageInfo> getPreferredPackages(int flags) {
1680 try {
1681 return mPM.getPreferredPackages(flags);
1682 } catch (RemoteException e) {
1683 // Should never happen!
1684 }
1685 return new ArrayList<PackageInfo>();
1686 }
1687
1688 @Override
1689 public void addPreferredActivity(IntentFilter filter,
1690 int match, ComponentName[] set, ComponentName activity) {
1691 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -07001692 mPM.addPreferredActivity(filter, match, set, activity, mContext.getUserId());
Amith Yamasania3f133a2012-08-09 17:11:28 -07001693 } catch (RemoteException e) {
1694 // Should never happen!
1695 }
1696 }
1697
1698 @Override
1699 public void addPreferredActivity(IntentFilter filter, int match,
1700 ComponentName[] set, ComponentName activity, int userId) {
1701 try {
1702 mPM.addPreferredActivity(filter, match, set, activity, userId);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001703 } catch (RemoteException e) {
1704 // Should never happen!
1705 }
1706 }
1707
1708 @Override
1709 public void replacePreferredActivity(IntentFilter filter,
1710 int match, ComponentName[] set, ComponentName activity) {
1711 try {
Amith Yamasani41c1ded2014-08-05 11:15:05 -07001712 mPM.replacePreferredActivity(filter, match, set, activity, UserHandle.myUserId());
1713 } catch (RemoteException e) {
1714 // Should never happen!
1715 }
1716 }
1717
1718 @Override
1719 public void replacePreferredActivityAsUser(IntentFilter filter,
1720 int match, ComponentName[] set, ComponentName activity,
1721 int userId) {
1722 try {
1723 mPM.replacePreferredActivity(filter, match, set, activity, userId);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001724 } catch (RemoteException e) {
1725 // Should never happen!
1726 }
1727 }
1728
1729 @Override
1730 public void clearPackagePreferredActivities(String packageName) {
1731 try {
1732 mPM.clearPackagePreferredActivities(packageName);
1733 } catch (RemoteException e) {
1734 // Should never happen!
1735 }
1736 }
1737
1738 @Override
1739 public int getPreferredActivities(List<IntentFilter> outFilters,
1740 List<ComponentName> outActivities, String packageName) {
1741 try {
1742 return mPM.getPreferredActivities(outFilters, outActivities, packageName);
1743 } catch (RemoteException e) {
1744 // Should never happen!
1745 }
1746 return 0;
1747 }
1748
1749 @Override
Christopher Tatea2a0850d2013-09-05 16:38:58 -07001750 public ComponentName getHomeActivities(List<ResolveInfo> outActivities) {
1751 try {
1752 return mPM.getHomeActivities(outActivities);
1753 } catch (RemoteException e) {
1754 // Should never happen!
1755 }
1756 return null;
1757 }
1758
1759 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001760 public void setComponentEnabledSetting(ComponentName componentName,
1761 int newState, int flags) {
1762 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -07001763 mPM.setComponentEnabledSetting(componentName, newState, flags, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001764 } catch (RemoteException e) {
1765 // Should never happen!
1766 }
1767 }
1768
1769 @Override
1770 public int getComponentEnabledSetting(ComponentName componentName) {
1771 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -07001772 return mPM.getComponentEnabledSetting(componentName, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001773 } catch (RemoteException e) {
1774 // Should never happen!
1775 }
1776 return PackageManager.COMPONENT_ENABLED_STATE_DEFAULT;
1777 }
1778
1779 @Override
1780 public void setApplicationEnabledSetting(String packageName,
1781 int newState, int flags) {
1782 try {
Dianne Hackborn3fa3c28a2013-03-26 16:15:41 -07001783 mPM.setApplicationEnabledSetting(packageName, newState, flags,
Dianne Hackborn95d78532013-09-11 09:51:14 -07001784 mContext.getUserId(), mContext.getOpPackageName());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001785 } catch (RemoteException e) {
1786 // Should never happen!
1787 }
1788 }
1789
1790 @Override
1791 public int getApplicationEnabledSetting(String packageName) {
1792 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -07001793 return mPM.getApplicationEnabledSetting(packageName, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001794 } catch (RemoteException e) {
1795 // Should never happen!
1796 }
1797 return PackageManager.COMPONENT_ENABLED_STATE_DEFAULT;
1798 }
1799
Amith Yamasani655d0e22013-06-12 14:19:10 -07001800 @Override
Amith Yamasanie5bcff62014-07-19 15:44:09 -07001801 public boolean setApplicationHiddenSettingAsUser(String packageName, boolean hidden,
Amith Yamasani655d0e22013-06-12 14:19:10 -07001802 UserHandle user) {
1803 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07001804 return mPM.setApplicationHiddenSettingAsUser(packageName, hidden,
Amith Yamasani655d0e22013-06-12 14:19:10 -07001805 user.getIdentifier());
1806 } catch (RemoteException re) {
1807 // Should never happen!
1808 }
1809 return false;
1810 }
1811
1812 @Override
Amith Yamasanie5bcff62014-07-19 15:44:09 -07001813 public boolean getApplicationHiddenSettingAsUser(String packageName, UserHandle user) {
Amith Yamasani655d0e22013-06-12 14:19:10 -07001814 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07001815 return mPM.getApplicationHiddenSettingAsUser(packageName, user.getIdentifier());
Amith Yamasani655d0e22013-06-12 14:19:10 -07001816 } catch (RemoteException re) {
1817 // Should never happen!
1818 }
1819 return false;
1820 }
1821
dcashmanc6f22492014-08-14 09:54:51 -07001822 /** @hide */
dcashman9d2f4412014-06-09 09:27:54 -07001823 @Override
1824 public KeySet getKeySetByAlias(String packageName, String alias) {
1825 Preconditions.checkNotNull(packageName);
1826 Preconditions.checkNotNull(alias);
dcashmanc6f22492014-08-14 09:54:51 -07001827 KeySet ks;
dcashman9d2f4412014-06-09 09:27:54 -07001828 try {
dcashmanc6f22492014-08-14 09:54:51 -07001829 ks = mPM.getKeySetByAlias(packageName, alias);
dcashman9d2f4412014-06-09 09:27:54 -07001830 } catch (RemoteException e) {
1831 return null;
1832 }
dcashmanc6f22492014-08-14 09:54:51 -07001833 return ks;
dcashman9d2f4412014-06-09 09:27:54 -07001834 }
1835
dcashmanc6f22492014-08-14 09:54:51 -07001836 /** @hide */
dcashman9d2f4412014-06-09 09:27:54 -07001837 @Override
1838 public KeySet getSigningKeySet(String packageName) {
1839 Preconditions.checkNotNull(packageName);
dcashmanc6f22492014-08-14 09:54:51 -07001840 KeySet ks;
dcashman9d2f4412014-06-09 09:27:54 -07001841 try {
dcashmanc6f22492014-08-14 09:54:51 -07001842 ks = mPM.getSigningKeySet(packageName);
dcashman9d2f4412014-06-09 09:27:54 -07001843 } catch (RemoteException e) {
1844 return null;
1845 }
dcashmanc6f22492014-08-14 09:54:51 -07001846 return ks;
dcashman9d2f4412014-06-09 09:27:54 -07001847 }
1848
dcashmanc6f22492014-08-14 09:54:51 -07001849 /** @hide */
dcashman9d2f4412014-06-09 09:27:54 -07001850 @Override
1851 public boolean isSignedBy(String packageName, KeySet ks) {
1852 Preconditions.checkNotNull(packageName);
1853 Preconditions.checkNotNull(ks);
dcashman9d2f4412014-06-09 09:27:54 -07001854 try {
dcashmanc6f22492014-08-14 09:54:51 -07001855 return mPM.isPackageSignedByKeySet(packageName, ks);
dcashman9d2f4412014-06-09 09:27:54 -07001856 } catch (RemoteException e) {
1857 return false;
1858 }
1859 }
1860
dcashmanc6f22492014-08-14 09:54:51 -07001861 /** @hide */
dcashman9d2f4412014-06-09 09:27:54 -07001862 @Override
1863 public boolean isSignedByExactly(String packageName, KeySet ks) {
1864 Preconditions.checkNotNull(packageName);
1865 Preconditions.checkNotNull(ks);
dcashman9d2f4412014-06-09 09:27:54 -07001866 try {
dcashmanc6f22492014-08-14 09:54:51 -07001867 return mPM.isPackageSignedByKeySetExactly(packageName, ks);
dcashman9d2f4412014-06-09 09:27:54 -07001868 } catch (RemoteException e) {
1869 return false;
1870 }
1871 }
1872
Kenny Root0aaa0d92011-09-12 16:42:55 -07001873 /**
1874 * @hide
1875 */
1876 @Override
1877 public VerifierDeviceIdentity getVerifierDeviceIdentity() {
1878 try {
1879 return mPM.getVerifierDeviceIdentity();
1880 } catch (RemoteException e) {
1881 // Should never happen!
1882 }
1883 return null;
1884 }
1885
Jeff Hao9f60c082014-10-28 18:51:07 -07001886 /**
1887 * @hide
1888 */
1889 @Override
1890 public boolean isUpgrade() {
1891 try {
1892 return mPM.isUpgrade();
1893 } catch (RemoteException e) {
1894 return false;
1895 }
1896 }
1897
Jeff Sharkey3a44f3f2014-04-28 17:36:31 -07001898 @Override
Jeff Sharkey16c8e3f2014-07-24 17:08:17 -07001899 public PackageInstaller getPackageInstaller() {
1900 synchronized (mLock) {
1901 if (mInstaller == null) {
1902 try {
Jeff Sharkeya0907432014-08-15 10:23:11 -07001903 mInstaller = new PackageInstaller(mContext, this, mPM.getPackageInstaller(),
Jeff Sharkey16c8e3f2014-07-24 17:08:17 -07001904 mContext.getPackageName(), mContext.getUserId());
1905 } catch (RemoteException e) {
1906 throw e.rethrowAsRuntimeException();
1907 }
1908 }
1909 return mInstaller;
Jeff Sharkey3a44f3f2014-04-28 17:36:31 -07001910 }
1911 }
1912
Jeff Sharkey6c833e02014-07-14 22:44:30 -07001913 @Override
1914 public boolean isPackageAvailable(String packageName) {
1915 try {
1916 return mPM.isPackageAvailable(packageName, mContext.getUserId());
1917 } catch (RemoteException e) {
1918 throw e.rethrowAsRuntimeException();
1919 }
1920 }
1921
Nicolas Prevotc79586e2014-05-06 12:47:57 +01001922 /**
1923 * @hide
1924 */
1925 @Override
Nicolas Prevot63798c52014-05-27 13:22:38 +01001926 public void addCrossProfileIntentFilter(IntentFilter filter, int sourceUserId, int targetUserId,
1927 int flags) {
Nicolas Prevotc79586e2014-05-06 12:47:57 +01001928 try {
Nicolas Prevot3f7777f2014-07-24 15:58:39 +01001929 mPM.addCrossProfileIntentFilter(filter, mContext.getOpPackageName(),
Nicolas Prevot4b8d5822015-03-05 15:20:49 +00001930 sourceUserId, targetUserId, flags);
Nicolas Prevotc79586e2014-05-06 12:47:57 +01001931 } catch (RemoteException e) {
1932 // Should never happen!
1933 }
1934 }
1935
1936 /**
1937 * @hide
1938 */
1939 @Override
Nicolas Prevot81948992014-05-16 18:25:26 +01001940 public void clearCrossProfileIntentFilters(int sourceUserId) {
Nicolas Prevotc79586e2014-05-06 12:47:57 +01001941 try {
Nicolas Prevot4b8d5822015-03-05 15:20:49 +00001942 mPM.clearCrossProfileIntentFilters(sourceUserId, mContext.getOpPackageName());
Nicolas Prevotc79586e2014-05-06 12:47:57 +01001943 } catch (RemoteException e) {
1944 // Should never happen!
1945 }
1946 }
1947
Nicolas Prevot88cc3462014-05-14 14:51:48 +01001948 /**
1949 * @hide
1950 */
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +01001951 public Drawable loadItemIcon(PackageItemInfo itemInfo, ApplicationInfo appInfo) {
Benjamin Franzec2d48b2014-10-01 15:38:43 +01001952 Drawable dr = loadUnbadgedItemIcon(itemInfo, appInfo);
1953 if (itemInfo.showUserIcon != UserHandle.USER_NULL) {
1954 return dr;
1955 }
1956 return getUserBadgedIcon(dr, new UserHandle(mContext.getUserId()));
1957 }
1958
1959 /**
1960 * @hide
1961 */
1962 public Drawable loadUnbadgedItemIcon(PackageItemInfo itemInfo, ApplicationInfo appInfo) {
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +01001963 if (itemInfo.showUserIcon != UserHandle.USER_NULL) {
Alexandra Gherghina64d4dca2014-08-28 18:26:56 +01001964 Bitmap bitmap = getUserManager().getUserIcon(itemInfo.showUserIcon);
1965 if (bitmap == null) {
1966 return UserIcons.getDefaultUserIcon(itemInfo.showUserIcon, /* light= */ false);
1967 }
1968 return new BitmapDrawable(bitmap);
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +01001969 }
Alexandra Gherghinadb811db2014-08-29 13:43:59 +01001970 Drawable dr = null;
1971 if (itemInfo.packageName != null) {
1972 dr = getDrawable(itemInfo.packageName, itemInfo.icon, appInfo);
1973 }
Alexandra Gherghinaa71e3902014-07-25 20:03:47 +01001974 if (dr == null) {
Alexandra Gherghinaa7093142014-07-30 13:43:39 +01001975 dr = itemInfo.loadDefaultIcon(this);
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +01001976 }
Benjamin Franzec2d48b2014-10-01 15:38:43 +01001977 return dr;
Svetoslavc7d62f02014-09-04 15:39:54 -07001978 }
1979
1980 private Drawable getBadgedDrawable(Drawable drawable, Drawable badgeDrawable,
1981 Rect badgeLocation, boolean tryBadgeInPlace) {
1982 final int badgedWidth = drawable.getIntrinsicWidth();
1983 final int badgedHeight = drawable.getIntrinsicHeight();
1984 final boolean canBadgeInPlace = tryBadgeInPlace
1985 && (drawable instanceof BitmapDrawable)
1986 && ((BitmapDrawable) drawable).getBitmap().isMutable();
1987
1988 final Bitmap bitmap;
1989 if (canBadgeInPlace) {
1990 bitmap = ((BitmapDrawable) drawable).getBitmap();
1991 } else {
1992 bitmap = Bitmap.createBitmap(badgedWidth, badgedHeight, Bitmap.Config.ARGB_8888);
1993 }
1994 Canvas canvas = new Canvas(bitmap);
1995
1996 if (!canBadgeInPlace) {
1997 drawable.setBounds(0, 0, badgedWidth, badgedHeight);
1998 drawable.draw(canvas);
1999 }
2000
2001 if (badgeLocation != null) {
2002 if (badgeLocation.left < 0 || badgeLocation.top < 0
2003 || badgeLocation.width() > badgedWidth || badgeLocation.height() > badgedHeight) {
2004 throw new IllegalArgumentException("Badge location " + badgeLocation
2005 + " not in badged drawable bounds "
2006 + new Rect(0, 0, badgedWidth, badgedHeight));
2007 }
2008 badgeDrawable.setBounds(0, 0, badgeLocation.width(), badgeLocation.height());
2009
2010 canvas.save();
2011 canvas.translate(badgeLocation.left, badgeLocation.top);
2012 badgeDrawable.draw(canvas);
2013 canvas.restore();
2014 } else {
2015 badgeDrawable.setBounds(0, 0, badgedWidth, badgedHeight);
2016 badgeDrawable.draw(canvas);
2017 }
2018
2019 if (!canBadgeInPlace) {
2020 BitmapDrawable mergedDrawable = new BitmapDrawable(mContext.getResources(), bitmap);
2021
2022 if (drawable instanceof BitmapDrawable) {
2023 BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
2024 mergedDrawable.setTargetDensity(bitmapDrawable.getBitmap().getDensity());
2025 }
2026
2027 return mergedDrawable;
2028 }
2029
2030 return drawable;
2031 }
2032
2033 private int getBadgeResIdForUser(int userHandle) {
2034 // Return the framework-provided badge.
2035 UserInfo userInfo = getUserIfProfile(userHandle);
2036 if (userInfo != null && userInfo.isManagedProfile()) {
2037 return com.android.internal.R.drawable.ic_corp_icon_badge;
2038 }
2039 return 0;
2040 }
2041
2042 private UserInfo getUserIfProfile(int userHandle) {
Svetoslav7de2abb2014-09-05 11:28:00 -07002043 List<UserInfo> userProfiles = getUserManager().getProfiles(UserHandle.myUserId());
Svetoslavc7d62f02014-09-04 15:39:54 -07002044 for (UserInfo user : userProfiles) {
2045 if (user.id == userHandle) {
2046 return user;
2047 }
2048 }
2049 return null;
Nicolas Prevot88cc3462014-05-14 14:51:48 +01002050 }
2051
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002052 /** {@hide} */
2053 private static class MoveCallbackDelegate extends IPackageMoveObserver.Stub implements
2054 Handler.Callback {
2055 private static final int MSG_STARTED = 1;
2056 private static final int MSG_STATUS_CHANGED = 2;
2057
2058 final MoveCallback mCallback;
2059 final Handler mHandler;
2060
2061 public MoveCallbackDelegate(MoveCallback callback, Looper looper) {
2062 mCallback = callback;
2063 mHandler = new Handler(looper, this);
2064 }
2065
2066 @Override
2067 public boolean handleMessage(Message msg) {
2068 final int moveId = msg.arg1;
2069 switch (msg.what) {
2070 case MSG_STARTED:
2071 mCallback.onStarted(moveId, (String) msg.obj);
2072 return true;
2073 case MSG_STATUS_CHANGED:
2074 mCallback.onStatusChanged(moveId, msg.arg2, (long) msg.obj);
2075 return true;
2076 }
2077 return false;
2078 }
2079
2080 @Override
2081 public void onStarted(int moveId, String title) {
2082 mHandler.obtainMessage(MSG_STARTED, moveId, 0, title).sendToTarget();
2083 }
2084
2085 @Override
2086 public void onStatusChanged(int moveId, int status, long estMillis) {
2087 mHandler.obtainMessage(MSG_STATUS_CHANGED, moveId, status, estMillis).sendToTarget();
2088 }
2089 }
2090
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002091 private final ContextImpl mContext;
2092 private final IPackageManager mPM;
2093
2094 private static final Object sSync = new Object();
Dianne Hackbornadd005c2013-07-17 18:43:12 -07002095 private static ArrayMap<ResourceName, WeakReference<Drawable.ConstantState>> sIconCache
2096 = new ArrayMap<ResourceName, WeakReference<Drawable.ConstantState>>();
2097 private static ArrayMap<ResourceName, WeakReference<CharSequence>> sStringCache
2098 = new ArrayMap<ResourceName, WeakReference<CharSequence>>();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002099}