blob: 04f643074592ebd8b9478c49199d6afe965fdc4d [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 Sharkey50a05452015-04-29 11:24:52 -070065import android.os.Bundle;
Jeff Sharkey620b32b2015-04-23 19:36:02 -070066import android.os.Handler;
67import android.os.Looper;
68import android.os.Message;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080069import android.os.Process;
70import android.os.RemoteException;
Jeff Sharkeyb2b9ab82015-04-05 21:10:42 -070071import android.os.SystemProperties;
Amith Yamasani67df64b2012-12-14 12:09:36 -080072import android.os.UserHandle;
Nicolas Prevot88cc3462014-05-14 14:51:48 +010073import android.os.UserManager;
Jeff Sharkeye2d45be2015-04-15 17:14:12 -070074import android.os.storage.StorageManager;
75import android.os.storage.VolumeInfo;
Dianne Hackbornadd005c2013-07-17 18:43:12 -070076import android.util.ArrayMap;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080077import android.util.Log;
Jeff Browna492c3a2012-08-23 19:48:44 -070078import android.view.Display;
Jeff Sharkeyb2b9ab82015-04-05 21:10:42 -070079
80import dalvik.system.VMRuntime;
Jeff Sharkey16c8e3f2014-07-24 17:08:17 -070081
82import com.android.internal.annotations.GuardedBy;
Jeff Sharkeyb36586a2015-04-27 08:42:28 -070083import com.android.internal.os.SomeArgs;
dcashman9d2f4412014-06-09 09:27:54 -070084import com.android.internal.util.Preconditions;
Alexandra Gherghina64d4dca2014-08-28 18:26:56 +010085import com.android.internal.util.UserIcons;
Jeff Sharkey16c8e3f2014-07-24 17:08:17 -070086
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080087import java.lang.ref.WeakReference;
88import java.util.ArrayList;
Jeff Sharkey620b32b2015-04-23 19:36:02 -070089import java.util.Iterator;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080090import java.util.List;
Jeff Sharkey620b32b2015-04-23 19:36:02 -070091import java.util.Objects;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080092
93/*package*/
94final class ApplicationPackageManager extends PackageManager {
95 private static final String TAG = "ApplicationPackageManager";
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080096 private final static boolean DEBUG_ICONS = false;
97
Adam Lesinskid00bb5e2014-10-07 12:14:45 -070098 // Default flags to use with PackageManager when no flags are given.
99 private final static int sDefaultFlags = PackageManager.GET_SHARED_LIBRARY_FILES;
100
Jeff Sharkey16c8e3f2014-07-24 17:08:17 -0700101 private final Object mLock = new Object();
102
103 @GuardedBy("mLock")
104 private UserManager mUserManager;
105 @GuardedBy("mLock")
106 private PackageInstaller mInstaller;
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +0100107
Jeff Sharkey620b32b2015-04-23 19:36:02 -0700108 @GuardedBy("mDelegates")
109 private final ArrayList<MoveCallbackDelegate> mDelegates = new ArrayList<>();
110
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +0100111 UserManager getUserManager() {
Jeff Sharkey16c8e3f2014-07-24 17:08:17 -0700112 synchronized (mLock) {
113 if (mUserManager == null) {
114 mUserManager = UserManager.get(mContext);
115 }
116 return mUserManager;
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +0100117 }
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +0100118 }
119
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800120 @Override
121 public PackageInfo getPackageInfo(String packageName, int flags)
122 throws NameNotFoundException {
123 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700124 PackageInfo pi = mPM.getPackageInfo(packageName, flags, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800125 if (pi != null) {
126 return pi;
127 }
128 } catch (RemoteException e) {
129 throw new RuntimeException("Package manager has died", e);
130 }
131
132 throw new NameNotFoundException(packageName);
133 }
134
135 @Override
136 public String[] currentToCanonicalPackageNames(String[] names) {
137 try {
138 return mPM.currentToCanonicalPackageNames(names);
139 } catch (RemoteException e) {
140 throw new RuntimeException("Package manager has died", e);
141 }
142 }
143
144 @Override
145 public String[] canonicalToCurrentPackageNames(String[] names) {
146 try {
147 return mPM.canonicalToCurrentPackageNames(names);
148 } catch (RemoteException e) {
149 throw new RuntimeException("Package manager has died", e);
150 }
151 }
152
153 @Override
154 public Intent getLaunchIntentForPackage(String packageName) {
155 // First see if the package has an INFO activity; the existence of
156 // such an activity is implied to be the desired front-door for the
157 // overall package (such as if it has multiple launcher entries).
158 Intent intentToResolve = new Intent(Intent.ACTION_MAIN);
159 intentToResolve.addCategory(Intent.CATEGORY_INFO);
160 intentToResolve.setPackage(packageName);
Dianne Hackborn19415762010-12-15 00:20:27 -0800161 List<ResolveInfo> ris = queryIntentActivities(intentToResolve, 0);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800162
163 // Otherwise, try to find a main launcher activity.
Dianne Hackborn19415762010-12-15 00:20:27 -0800164 if (ris == null || ris.size() <= 0) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800165 // reuse the intent instance
166 intentToResolve.removeCategory(Intent.CATEGORY_INFO);
167 intentToResolve.addCategory(Intent.CATEGORY_LAUNCHER);
168 intentToResolve.setPackage(packageName);
Dianne Hackborn19415762010-12-15 00:20:27 -0800169 ris = queryIntentActivities(intentToResolve, 0);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800170 }
Dianne Hackborn19415762010-12-15 00:20:27 -0800171 if (ris == null || ris.size() <= 0) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800172 return null;
173 }
174 Intent intent = new Intent(intentToResolve);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800175 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Dianne Hackborn19415762010-12-15 00:20:27 -0800176 intent.setClassName(ris.get(0).activityInfo.packageName,
177 ris.get(0).activityInfo.name);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800178 return intent;
179 }
180
181 @Override
Jose Lima970417c2014-04-10 10:42:19 -0700182 public Intent getLeanbackLaunchIntentForPackage(String packageName) {
183 // Try to find a main leanback_launcher activity.
184 Intent intentToResolve = new Intent(Intent.ACTION_MAIN);
185 intentToResolve.addCategory(Intent.CATEGORY_LEANBACK_LAUNCHER);
186 intentToResolve.setPackage(packageName);
187 List<ResolveInfo> ris = queryIntentActivities(intentToResolve, 0);
188
189 if (ris == null || ris.size() <= 0) {
190 return null;
191 }
192 Intent intent = new Intent(intentToResolve);
193 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
194 intent.setClassName(ris.get(0).activityInfo.packageName,
195 ris.get(0).activityInfo.name);
196 return intent;
197 }
198
199 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800200 public int[] getPackageGids(String packageName)
201 throws NameNotFoundException {
202 try {
Svetoslavc6d1c342015-02-26 14:44:43 -0800203 int[] gids = mPM.getPackageGids(packageName, mContext.getUserId());
204 if (gids != null) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800205 return gids;
206 }
207 } catch (RemoteException e) {
208 throw new RuntimeException("Package manager has died", e);
209 }
210
211 throw new NameNotFoundException(packageName);
212 }
213
214 @Override
Dianne Hackborna06de0f2012-12-11 16:34:47 -0800215 public int getPackageUid(String packageName, int userHandle)
216 throws NameNotFoundException {
217 try {
218 int uid = mPM.getPackageUid(packageName, userHandle);
219 if (uid >= 0) {
220 return uid;
221 }
222 } catch (RemoteException e) {
223 throw new RuntimeException("Package manager has died", e);
224 }
225
226 throw new NameNotFoundException(packageName);
227 }
228
229 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800230 public PermissionInfo getPermissionInfo(String name, int flags)
231 throws NameNotFoundException {
232 try {
233 PermissionInfo pi = mPM.getPermissionInfo(name, flags);
234 if (pi != null) {
235 return pi;
236 }
237 } catch (RemoteException e) {
238 throw new RuntimeException("Package manager has died", e);
239 }
240
241 throw new NameNotFoundException(name);
242 }
243
244 @Override
245 public List<PermissionInfo> queryPermissionsByGroup(String group, int flags)
246 throws NameNotFoundException {
247 try {
248 List<PermissionInfo> pi = mPM.queryPermissionsByGroup(group, flags);
249 if (pi != null) {
250 return pi;
251 }
252 } catch (RemoteException e) {
253 throw new RuntimeException("Package manager has died", e);
254 }
255
256 throw new NameNotFoundException(group);
257 }
258
259 @Override
260 public PermissionGroupInfo getPermissionGroupInfo(String name,
261 int flags) throws NameNotFoundException {
262 try {
263 PermissionGroupInfo pgi = mPM.getPermissionGroupInfo(name, flags);
264 if (pgi != null) {
265 return pgi;
266 }
267 } catch (RemoteException e) {
268 throw new RuntimeException("Package manager has died", e);
269 }
270
271 throw new NameNotFoundException(name);
272 }
273
274 @Override
275 public List<PermissionGroupInfo> getAllPermissionGroups(int flags) {
276 try {
277 return mPM.getAllPermissionGroups(flags);
278 } catch (RemoteException e) {
279 throw new RuntimeException("Package manager has died", e);
280 }
281 }
282
283 @Override
284 public ApplicationInfo getApplicationInfo(String packageName, int flags)
285 throws NameNotFoundException {
286 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700287 ApplicationInfo ai = mPM.getApplicationInfo(packageName, flags, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800288 if (ai != null) {
Narayan Kamathcaa71192014-07-16 11:06:43 +0100289 // This is a temporary hack. Callers must use
290 // createPackageContext(packageName).getApplicationInfo() to
291 // get the right paths.
292 maybeAdjustApplicationInfo(ai);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800293 return ai;
294 }
295 } catch (RemoteException e) {
296 throw new RuntimeException("Package manager has died", e);
297 }
298
299 throw new NameNotFoundException(packageName);
300 }
301
Narayan Kamathcaa71192014-07-16 11:06:43 +0100302 private static void maybeAdjustApplicationInfo(ApplicationInfo info) {
303 // If we're dealing with a multi-arch application that has both
304 // 32 and 64 bit shared libraries, we might need to choose the secondary
305 // depending on what the current runtime's instruction set is.
306 if (info.primaryCpuAbi != null && info.secondaryCpuAbi != null) {
307 final String runtimeIsa = VMRuntime.getRuntime().vmInstructionSet();
jgu214741cd92014-12-17 17:23:29 -0500308
309 // Get the instruction set that the libraries of secondary Abi is supported.
310 // In presence of a native bridge this might be different than the one secondary Abi used.
311 String secondaryIsa = VMRuntime.getInstructionSet(info.secondaryCpuAbi);
312 final String secondaryDexCodeIsa = SystemProperties.get("ro.dalvik.vm.isa." + secondaryIsa);
313 secondaryIsa = secondaryDexCodeIsa.isEmpty() ? secondaryIsa : secondaryDexCodeIsa;
Narayan Kamathcaa71192014-07-16 11:06:43 +0100314
315 // If the runtimeIsa is the same as the primary isa, then we do nothing.
316 // Everything will be set up correctly because info.nativeLibraryDir will
317 // correspond to the right ISA.
318 if (runtimeIsa.equals(secondaryIsa)) {
319 info.nativeLibraryDir = info.secondaryNativeLibraryDir;
320 }
321 }
322 }
323
324
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800325 @Override
326 public ActivityInfo getActivityInfo(ComponentName className, int flags)
327 throws NameNotFoundException {
328 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700329 ActivityInfo ai = mPM.getActivityInfo(className, flags, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800330 if (ai != null) {
331 return ai;
332 }
333 } catch (RemoteException e) {
334 throw new RuntimeException("Package manager has died", e);
335 }
336
337 throw new NameNotFoundException(className.toString());
338 }
339
340 @Override
341 public ActivityInfo getReceiverInfo(ComponentName className, int flags)
342 throws NameNotFoundException {
343 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700344 ActivityInfo ai = mPM.getReceiverInfo(className, flags, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800345 if (ai != null) {
346 return ai;
347 }
348 } catch (RemoteException e) {
349 throw new RuntimeException("Package manager has died", e);
350 }
351
352 throw new NameNotFoundException(className.toString());
353 }
354
355 @Override
356 public ServiceInfo getServiceInfo(ComponentName className, int flags)
357 throws NameNotFoundException {
358 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700359 ServiceInfo si = mPM.getServiceInfo(className, flags, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800360 if (si != null) {
361 return si;
362 }
363 } catch (RemoteException e) {
364 throw new RuntimeException("Package manager has died", e);
365 }
366
367 throw new NameNotFoundException(className.toString());
368 }
369
370 @Override
371 public ProviderInfo getProviderInfo(ComponentName className, int flags)
372 throws NameNotFoundException {
373 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700374 ProviderInfo pi = mPM.getProviderInfo(className, flags, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800375 if (pi != null) {
376 return pi;
377 }
378 } catch (RemoteException e) {
379 throw new RuntimeException("Package manager has died", e);
380 }
381
382 throw new NameNotFoundException(className.toString());
383 }
384
385 @Override
386 public String[] getSystemSharedLibraryNames() {
387 try {
388 return mPM.getSystemSharedLibraryNames();
389 } catch (RemoteException e) {
390 throw new RuntimeException("Package manager has died", e);
391 }
392 }
393
394 @Override
395 public FeatureInfo[] getSystemAvailableFeatures() {
396 try {
397 return mPM.getSystemAvailableFeatures();
398 } catch (RemoteException e) {
399 throw new RuntimeException("Package manager has died", e);
400 }
401 }
402
403 @Override
404 public boolean hasSystemFeature(String name) {
405 try {
406 return mPM.hasSystemFeature(name);
407 } catch (RemoteException e) {
408 throw new RuntimeException("Package manager has died", e);
409 }
410 }
411
412 @Override
413 public int checkPermission(String permName, String pkgName) {
414 try {
Svetoslavc6d1c342015-02-26 14:44:43 -0800415 return mPM.checkPermission(permName, pkgName, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800416 } catch (RemoteException e) {
417 throw new RuntimeException("Package manager has died", e);
418 }
419 }
420
421 @Override
422 public boolean addPermission(PermissionInfo info) {
423 try {
424 return mPM.addPermission(info);
425 } catch (RemoteException e) {
426 throw new RuntimeException("Package manager has died", e);
427 }
428 }
429
430 @Override
431 public boolean addPermissionAsync(PermissionInfo info) {
432 try {
433 return mPM.addPermissionAsync(info);
434 } catch (RemoteException e) {
435 throw new RuntimeException("Package manager has died", e);
436 }
437 }
438
439 @Override
440 public void removePermission(String name) {
441 try {
442 mPM.removePermission(name);
443 } catch (RemoteException e) {
444 throw new RuntimeException("Package manager has died", e);
445 }
446 }
447
448 @Override
Svet Ganov8c7f7002015-05-07 10:48:44 -0700449 public void grantRuntimePermission(String packageName, String permissionName,
450 UserHandle user) {
Dianne Hackborne639da72012-02-21 15:11:13 -0800451 try {
Svet Ganov8c7f7002015-05-07 10:48:44 -0700452 mPM.grantRuntimePermission(packageName, permissionName, user.getIdentifier());
Dianne Hackborne639da72012-02-21 15:11:13 -0800453 } catch (RemoteException e) {
454 throw new RuntimeException("Package manager has died", e);
455 }
456 }
457
458 @Override
Svet Ganov8c7f7002015-05-07 10:48:44 -0700459 public void revokeRuntimePermission(String packageName, String permissionName,
460 UserHandle user) {
Dianne Hackborne639da72012-02-21 15:11:13 -0800461 try {
Svet Ganov8c7f7002015-05-07 10:48:44 -0700462 mPM.revokeRuntimePermission(packageName, permissionName, user.getIdentifier());
463 } catch (RemoteException e) {
464 throw new RuntimeException("Package manager has died", e);
465 }
466 }
467
468 @Override
469 public int getPermissionFlags(String permissionName, String packageName, UserHandle user) {
470 try {
471 return mPM.getPermissionFlags(permissionName, packageName, user.getIdentifier());
472 } catch (RemoteException e) {
473 throw new RuntimeException("Package manager has died", e);
474 }
475 }
476
477 @Override
478 public void updatePermissionFlags(String permissionName, String packageName,
479 int flagMask, int flagValues, UserHandle user) {
480 try {
481 mPM.updatePermissionFlags(permissionName, packageName, flagMask,
482 flagValues, user.getIdentifier());
Dianne Hackborne639da72012-02-21 15:11:13 -0800483 } catch (RemoteException e) {
484 throw new RuntimeException("Package manager has died", e);
485 }
486 }
487
488 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800489 public int checkSignatures(String pkg1, String pkg2) {
490 try {
491 return mPM.checkSignatures(pkg1, pkg2);
492 } catch (RemoteException e) {
493 throw new RuntimeException("Package manager has died", e);
494 }
495 }
496
497 @Override
498 public int checkSignatures(int uid1, int uid2) {
499 try {
500 return mPM.checkUidSignatures(uid1, uid2);
501 } catch (RemoteException e) {
502 throw new RuntimeException("Package manager has died", e);
503 }
504 }
505
506 @Override
507 public String[] getPackagesForUid(int uid) {
508 try {
509 return mPM.getPackagesForUid(uid);
510 } catch (RemoteException e) {
511 throw new RuntimeException("Package manager has died", e);
512 }
513 }
514
515 @Override
516 public String getNameForUid(int uid) {
517 try {
518 return mPM.getNameForUid(uid);
519 } catch (RemoteException e) {
520 throw new RuntimeException("Package manager has died", e);
521 }
522 }
523
524 @Override
525 public int getUidForSharedUser(String sharedUserName)
526 throws NameNotFoundException {
527 try {
528 int uid = mPM.getUidForSharedUser(sharedUserName);
529 if(uid != -1) {
530 return uid;
531 }
532 } catch (RemoteException e) {
533 throw new RuntimeException("Package manager has died", e);
534 }
535 throw new NameNotFoundException("No shared userid for user:"+sharedUserName);
536 }
537
Kenny Roote6cd0c72011-05-19 12:48:14 -0700538 @SuppressWarnings("unchecked")
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800539 @Override
540 public List<PackageInfo> getInstalledPackages(int flags) {
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700541 return getInstalledPackages(flags, mContext.getUserId());
Amith Yamasani151ec4c2012-09-07 19:25:16 -0700542 }
543
544 /** @hide */
545 @Override
546 public List<PackageInfo> getInstalledPackages(int flags, int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800547 try {
Dianne Hackbornd8e1dbb2013-01-17 17:47:37 -0800548 ParceledListSlice<PackageInfo> slice = mPM.getInstalledPackages(flags, userId);
549 return slice.getList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800550 } catch (RemoteException e) {
551 throw new RuntimeException("Package manager has died", e);
552 }
553 }
554
Kenny Roote6cd0c72011-05-19 12:48:14 -0700555 @SuppressWarnings("unchecked")
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800556 @Override
Dianne Hackborne7991752013-01-16 17:56:46 -0800557 public List<PackageInfo> getPackagesHoldingPermissions(
558 String[] permissions, int flags) {
559 final int userId = mContext.getUserId();
560 try {
Dianne Hackbornd8e1dbb2013-01-17 17:47:37 -0800561 ParceledListSlice<PackageInfo> slice = mPM.getPackagesHoldingPermissions(
562 permissions, flags, userId);
563 return slice.getList();
Dianne Hackborne7991752013-01-16 17:56:46 -0800564 } catch (RemoteException e) {
565 throw new RuntimeException("Package manager has died", e);
566 }
567 }
568
569 @SuppressWarnings("unchecked")
570 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800571 public List<ApplicationInfo> getInstalledApplications(int flags) {
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700572 final int userId = mContext.getUserId();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800573 try {
Dianne Hackbornd8e1dbb2013-01-17 17:47:37 -0800574 ParceledListSlice<ApplicationInfo> slice = mPM.getInstalledApplications(flags, userId);
575 return slice.getList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800576 } catch (RemoteException e) {
577 throw new RuntimeException("Package manager has died", e);
578 }
579 }
580
581 @Override
582 public ResolveInfo resolveActivity(Intent intent, int flags) {
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700583 return resolveActivityAsUser(intent, flags, mContext.getUserId());
Svetoslav Ganov58d37b52012-09-18 12:04:19 -0700584 }
585
586 @Override
587 public ResolveInfo resolveActivityAsUser(Intent intent, int flags, int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800588 try {
589 return mPM.resolveIntent(
590 intent,
591 intent.resolveTypeIfNeeded(mContext.getContentResolver()),
Svetoslav Ganov58d37b52012-09-18 12:04:19 -0700592 flags,
593 userId);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800594 } catch (RemoteException e) {
595 throw new RuntimeException("Package manager has died", e);
596 }
597 }
598
599 @Override
600 public List<ResolveInfo> queryIntentActivities(Intent intent,
601 int flags) {
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700602 return queryIntentActivitiesAsUser(intent, flags, mContext.getUserId());
Amith Yamasani151ec4c2012-09-07 19:25:16 -0700603 }
604
605 /** @hide Same as above but for a specific user */
606 @Override
Svetoslav Ganov58d37b52012-09-18 12:04:19 -0700607 public List<ResolveInfo> queryIntentActivitiesAsUser(Intent intent,
Amith Yamasani151ec4c2012-09-07 19:25:16 -0700608 int flags, int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800609 try {
610 return mPM.queryIntentActivities(
611 intent,
612 intent.resolveTypeIfNeeded(mContext.getContentResolver()),
Amith Yamasani483f3b02012-03-13 16:08:00 -0700613 flags,
Amith Yamasani151ec4c2012-09-07 19:25:16 -0700614 userId);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800615 } catch (RemoteException e) {
616 throw new RuntimeException("Package manager has died", e);
617 }
618 }
619
620 @Override
621 public List<ResolveInfo> queryIntentActivityOptions(
622 ComponentName caller, Intent[] specifics, Intent intent,
623 int flags) {
624 final ContentResolver resolver = mContext.getContentResolver();
625
626 String[] specificTypes = null;
627 if (specifics != null) {
628 final int N = specifics.length;
629 for (int i=0; i<N; i++) {
630 Intent sp = specifics[i];
631 if (sp != null) {
632 String t = sp.resolveTypeIfNeeded(resolver);
633 if (t != null) {
634 if (specificTypes == null) {
635 specificTypes = new String[N];
636 }
637 specificTypes[i] = t;
638 }
639 }
640 }
641 }
642
643 try {
644 return mPM.queryIntentActivityOptions(caller, specifics,
645 specificTypes, intent, intent.resolveTypeIfNeeded(resolver),
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700646 flags, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800647 } catch (RemoteException e) {
648 throw new RuntimeException("Package manager has died", e);
649 }
650 }
651
Amith Yamasanif203aee2012-08-29 18:41:53 -0700652 /**
653 * @hide
654 */
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800655 @Override
Amith Yamasanif203aee2012-08-29 18:41:53 -0700656 public List<ResolveInfo> queryBroadcastReceivers(Intent intent, int flags, int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800657 try {
658 return mPM.queryIntentReceivers(
659 intent,
660 intent.resolveTypeIfNeeded(mContext.getContentResolver()),
Amith Yamasani483f3b02012-03-13 16:08:00 -0700661 flags,
Amith Yamasanif203aee2012-08-29 18:41:53 -0700662 userId);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800663 } catch (RemoteException e) {
664 throw new RuntimeException("Package manager has died", e);
665 }
666 }
667
668 @Override
Amith Yamasanif203aee2012-08-29 18:41:53 -0700669 public List<ResolveInfo> queryBroadcastReceivers(Intent intent, int flags) {
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700670 return queryBroadcastReceivers(intent, flags, mContext.getUserId());
Amith Yamasanif203aee2012-08-29 18:41:53 -0700671 }
672
673 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800674 public ResolveInfo resolveService(Intent intent, int flags) {
675 try {
676 return mPM.resolveService(
677 intent,
678 intent.resolveTypeIfNeeded(mContext.getContentResolver()),
Amith Yamasani483f3b02012-03-13 16:08:00 -0700679 flags,
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700680 mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800681 } catch (RemoteException e) {
682 throw new RuntimeException("Package manager has died", e);
683 }
684 }
685
686 @Override
Svetoslav Ganov58d37b52012-09-18 12:04:19 -0700687 public List<ResolveInfo> queryIntentServicesAsUser(Intent intent, int flags, int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800688 try {
689 return mPM.queryIntentServices(
690 intent,
691 intent.resolveTypeIfNeeded(mContext.getContentResolver()),
Amith Yamasani483f3b02012-03-13 16:08:00 -0700692 flags,
Svetoslav Ganov58d37b52012-09-18 12:04:19 -0700693 userId);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800694 } catch (RemoteException e) {
695 throw new RuntimeException("Package manager has died", e);
696 }
697 }
698
699 @Override
Svetoslav Ganov58d37b52012-09-18 12:04:19 -0700700 public List<ResolveInfo> queryIntentServices(Intent intent, int flags) {
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700701 return queryIntentServicesAsUser(intent, flags, mContext.getUserId());
Svetoslav Ganov58d37b52012-09-18 12:04:19 -0700702 }
703
704 @Override
Jeff Sharkey85f5f812013-10-07 10:16:12 -0700705 public List<ResolveInfo> queryIntentContentProvidersAsUser(
706 Intent intent, int flags, int userId) {
707 try {
708 return mPM.queryIntentContentProviders(intent,
709 intent.resolveTypeIfNeeded(mContext.getContentResolver()), flags, userId);
710 } catch (RemoteException e) {
711 throw new RuntimeException("Package manager has died", e);
712 }
713 }
714
715 @Override
716 public List<ResolveInfo> queryIntentContentProviders(Intent intent, int flags) {
717 return queryIntentContentProvidersAsUser(intent, flags, mContext.getUserId());
718 }
719
720 @Override
Alexandra Gherghina0363c3e2014-06-23 13:34:59 +0100721 public ProviderInfo resolveContentProvider(String name, int flags) {
722 return resolveContentProviderAsUser(name, flags, mContext.getUserId());
723 }
724
725 /** @hide **/
726 @Override
727 public ProviderInfo resolveContentProviderAsUser(String name, int flags, int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800728 try {
Alexandra Gherghina0363c3e2014-06-23 13:34:59 +0100729 return mPM.resolveContentProvider(name, flags, userId);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800730 } catch (RemoteException e) {
731 throw new RuntimeException("Package manager has died", e);
732 }
733 }
734
735 @Override
736 public List<ProviderInfo> queryContentProviders(String processName,
737 int uid, int flags) {
738 try {
739 return mPM.queryContentProviders(processName, uid, flags);
740 } catch (RemoteException e) {
741 throw new RuntimeException("Package manager has died", e);
742 }
743 }
744
745 @Override
746 public InstrumentationInfo getInstrumentationInfo(
747 ComponentName className, int flags)
748 throws NameNotFoundException {
749 try {
750 InstrumentationInfo ii = mPM.getInstrumentationInfo(
751 className, flags);
752 if (ii != null) {
753 return ii;
754 }
755 } catch (RemoteException e) {
756 throw new RuntimeException("Package manager has died", e);
757 }
758
759 throw new NameNotFoundException(className.toString());
760 }
761
762 @Override
763 public List<InstrumentationInfo> queryInstrumentation(
764 String targetPackage, int flags) {
765 try {
766 return mPM.queryInstrumentation(targetPackage, flags);
767 } catch (RemoteException e) {
768 throw new RuntimeException("Package manager has died", e);
769 }
770 }
771
Alan Viveretteecd585a2015-04-13 10:32:51 -0700772 @Nullable
773 @Override
774 public Drawable getDrawable(String packageName, @DrawableRes int resId,
775 @Nullable ApplicationInfo appInfo) {
776 final ResourceName name = new ResourceName(packageName, resId);
777 final Drawable cachedIcon = getCachedIcon(name);
778 if (cachedIcon != null) {
779 return cachedIcon;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800780 }
Alan Viveretteecd585a2015-04-13 10:32:51 -0700781
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800782 if (appInfo == null) {
783 try {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -0700784 appInfo = getApplicationInfo(packageName, sDefaultFlags);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800785 } catch (NameNotFoundException e) {
786 return null;
787 }
788 }
Alan Viveretteecd585a2015-04-13 10:32:51 -0700789
790 if (resId != 0) {
791 try {
792 final Resources r = getResourcesForApplication(appInfo);
793 final Drawable dr = r.getDrawable(resId, null);
794 if (dr != null) {
795 putCachedIcon(name, dr);
796 }
797
798 if (false) {
799 RuntimeException e = new RuntimeException("here");
800 e.fillInStackTrace();
801 Log.w(TAG, "Getting drawable 0x" + Integer.toHexString(resId)
802 + " from package " + packageName
803 + ": app scale=" + r.getCompatibilityInfo().applicationScale
804 + ", caller scale=" + mContext.getResources()
805 .getCompatibilityInfo().applicationScale,
806 e);
807 }
Ricky Wai3ce46252015-04-15 16:12:22 +0100808 if (DEBUG_ICONS) {
Alan Viveretteecd585a2015-04-13 10:32:51 -0700809 Log.v(TAG, "Getting drawable 0x"
810 + Integer.toHexString(resId) + " from " + r
811 + ": " + dr);
Ricky Wai3ce46252015-04-15 16:12:22 +0100812 }
813 return dr;
Alan Viveretteecd585a2015-04-13 10:32:51 -0700814 } catch (NameNotFoundException e) {
815 Log.w("PackageManager", "Failure retrieving resources for "
816 + appInfo.packageName);
817 } catch (Resources.NotFoundException e) {
818 Log.w("PackageManager", "Failure retrieving resources for "
819 + appInfo.packageName + ": " + e.getMessage());
820 } catch (Exception e) {
821 // If an exception was thrown, fall through to return
822 // default icon.
823 Log.w("PackageManager", "Failure retrieving icon 0x"
824 + Integer.toHexString(resId) + " in package "
825 + packageName, e);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800826 }
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800827 }
Alan Viveretteecd585a2015-04-13 10:32:51 -0700828
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800829 return null;
830 }
831
832 @Override public Drawable getActivityIcon(ComponentName activityName)
833 throws NameNotFoundException {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -0700834 return getActivityInfo(activityName, sDefaultFlags).loadIcon(this);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800835 }
836
837 @Override public Drawable getActivityIcon(Intent intent)
838 throws NameNotFoundException {
839 if (intent.getComponent() != null) {
840 return getActivityIcon(intent.getComponent());
841 }
842
843 ResolveInfo info = resolveActivity(
844 intent, PackageManager.MATCH_DEFAULT_ONLY);
845 if (info != null) {
846 return info.activityInfo.loadIcon(this);
847 }
848
Romain Guy39fe17c2011-11-30 10:34:07 -0800849 throw new NameNotFoundException(intent.toUri(0));
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800850 }
851
852 @Override public Drawable getDefaultActivityIcon() {
853 return Resources.getSystem().getDrawable(
854 com.android.internal.R.drawable.sym_def_app_icon);
855 }
856
857 @Override public Drawable getApplicationIcon(ApplicationInfo info) {
858 return info.loadIcon(this);
859 }
860
861 @Override public Drawable getApplicationIcon(String packageName)
862 throws NameNotFoundException {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -0700863 return getApplicationIcon(getApplicationInfo(packageName, sDefaultFlags));
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800864 }
865
866 @Override
Jose Limaf78e3122014-03-06 12:13:15 -0800867 public Drawable getActivityBanner(ComponentName activityName)
868 throws NameNotFoundException {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -0700869 return getActivityInfo(activityName, sDefaultFlags).loadBanner(this);
Jose Limaf78e3122014-03-06 12:13:15 -0800870 }
871
872 @Override
873 public Drawable getActivityBanner(Intent intent)
874 throws NameNotFoundException {
875 if (intent.getComponent() != null) {
876 return getActivityBanner(intent.getComponent());
877 }
878
879 ResolveInfo info = resolveActivity(
880 intent, PackageManager.MATCH_DEFAULT_ONLY);
881 if (info != null) {
882 return info.activityInfo.loadBanner(this);
883 }
884
885 throw new NameNotFoundException(intent.toUri(0));
886 }
887
888 @Override
889 public Drawable getApplicationBanner(ApplicationInfo info) {
890 return info.loadBanner(this);
891 }
892
893 @Override
894 public Drawable getApplicationBanner(String packageName)
895 throws NameNotFoundException {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -0700896 return getApplicationBanner(getApplicationInfo(packageName, sDefaultFlags));
Jose Limaf78e3122014-03-06 12:13:15 -0800897 }
898
899 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800900 public Drawable getActivityLogo(ComponentName activityName)
901 throws NameNotFoundException {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -0700902 return getActivityInfo(activityName, sDefaultFlags).loadLogo(this);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800903 }
904
905 @Override
906 public Drawable getActivityLogo(Intent intent)
907 throws NameNotFoundException {
908 if (intent.getComponent() != null) {
909 return getActivityLogo(intent.getComponent());
910 }
911
912 ResolveInfo info = resolveActivity(
913 intent, PackageManager.MATCH_DEFAULT_ONLY);
914 if (info != null) {
915 return info.activityInfo.loadLogo(this);
916 }
917
918 throw new NameNotFoundException(intent.toUri(0));
919 }
920
921 @Override
922 public Drawable getApplicationLogo(ApplicationInfo info) {
923 return info.loadLogo(this);
924 }
925
926 @Override
927 public Drawable getApplicationLogo(String packageName)
928 throws NameNotFoundException {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -0700929 return getApplicationLogo(getApplicationInfo(packageName, sDefaultFlags));
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800930 }
931
Svetoslavc7d62f02014-09-04 15:39:54 -0700932 @Override
933 public Drawable getUserBadgedIcon(Drawable icon, UserHandle user) {
934 final int badgeResId = getBadgeResIdForUser(user.getIdentifier());
935 if (badgeResId == 0) {
936 return icon;
937 }
938 Drawable badgeIcon = getDrawable("system", badgeResId, null);
939 return getBadgedDrawable(icon, badgeIcon, null, true);
940 }
941
942 @Override
943 public Drawable getUserBadgedDrawableForDensity(Drawable drawable, UserHandle user,
944 Rect badgeLocation, int badgeDensity) {
945 Drawable badgeDrawable = getUserBadgeForDensity(user, badgeDensity);
946 if (badgeDrawable == null) {
947 return drawable;
948 }
949 return getBadgedDrawable(drawable, badgeDrawable, badgeLocation, true);
950 }
951
952 @Override
953 public Drawable getUserBadgeForDensity(UserHandle user, int density) {
954 UserInfo userInfo = getUserIfProfile(user.getIdentifier());
955 if (userInfo != null && userInfo.isManagedProfile()) {
956 if (density <= 0) {
957 density = mContext.getResources().getDisplayMetrics().densityDpi;
958 }
959 return Resources.getSystem().getDrawableForDensity(
960 com.android.internal.R.drawable.ic_corp_badge, density);
961 }
962 return null;
963 }
964
965 @Override
966 public CharSequence getUserBadgedLabel(CharSequence label, UserHandle user) {
967 UserInfo userInfo = getUserIfProfile(user.getIdentifier());
968 if (userInfo != null && userInfo.isManagedProfile()) {
969 return Resources.getSystem().getString(
970 com.android.internal.R.string.managed_profile_label_badge, label);
971 }
972 return label;
973 }
974
Alan Viveretteecd585a2015-04-13 10:32:51 -0700975 @Override
976 public Resources getResourcesForActivity(ComponentName activityName)
977 throws NameNotFoundException {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800978 return getResourcesForApplication(
Adam Lesinskid00bb5e2014-10-07 12:14:45 -0700979 getActivityInfo(activityName, sDefaultFlags).applicationInfo);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800980 }
981
Alan Viveretteecd585a2015-04-13 10:32:51 -0700982 @Override
983 public Resources getResourcesForApplication(@NonNull ApplicationInfo app)
984 throws NameNotFoundException {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800985 if (app.packageName.equals("system")) {
986 return mContext.mMainThread.getSystemContext().getResources();
987 }
Jeff Sharkey8a4c9722014-06-16 13:48:42 -0700988 final boolean sameUid = (app.uid == Process.myUid());
Alan Viveretteecd585a2015-04-13 10:32:51 -0700989 final Resources r = mContext.mMainThread.getTopLevelResources(
Jeff Sharkey8a4c9722014-06-16 13:48:42 -0700990 sameUid ? app.sourceDir : app.publicSourceDir,
991 sameUid ? app.splitSourceDirs : app.splitPublicSourceDirs,
Adam Lesinskid00bb5e2014-10-07 12:14:45 -0700992 app.resourceDirs, app.sharedLibraryFiles, Display.DEFAULT_DISPLAY,
993 null, mContext.mPackageInfo);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800994 if (r != null) {
995 return r;
996 }
997 throw new NameNotFoundException("Unable to open " + app.publicSourceDir);
998 }
999
Alan Viveretteecd585a2015-04-13 10:32:51 -07001000 @Override
1001 public Resources getResourcesForApplication(String appPackageName)
1002 throws NameNotFoundException {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001003 return getResourcesForApplication(
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001004 getApplicationInfo(appPackageName, sDefaultFlags));
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001005 }
1006
Amith Yamasani98edc952012-09-25 14:09:27 -07001007 /** @hide */
1008 @Override
1009 public Resources getResourcesForApplicationAsUser(String appPackageName, int userId)
1010 throws NameNotFoundException {
Jeff Sharkeyded653b2012-09-27 19:09:24 -07001011 if (userId < 0) {
1012 throw new IllegalArgumentException(
1013 "Call does not support special user #" + userId);
1014 }
1015 if ("system".equals(appPackageName)) {
1016 return mContext.mMainThread.getSystemContext().getResources();
1017 }
Amith Yamasani98edc952012-09-25 14:09:27 -07001018 try {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001019 ApplicationInfo ai = mPM.getApplicationInfo(appPackageName, sDefaultFlags, userId);
Amith Yamasani98edc952012-09-25 14:09:27 -07001020 if (ai != null) {
1021 return getResourcesForApplication(ai);
1022 }
1023 } catch (RemoteException e) {
1024 throw new RuntimeException("Package manager has died", e);
1025 }
1026 throw new NameNotFoundException("Package " + appPackageName + " doesn't exist");
1027 }
1028
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001029 int mCachedSafeMode = -1;
1030 @Override public boolean isSafeMode() {
1031 try {
1032 if (mCachedSafeMode < 0) {
1033 mCachedSafeMode = mPM.isSafeMode() ? 1 : 0;
1034 }
1035 return mCachedSafeMode != 0;
1036 } catch (RemoteException e) {
1037 throw new RuntimeException("Package manager has died", e);
1038 }
1039 }
1040
1041 static void configurationChanged() {
1042 synchronized (sSync) {
1043 sIconCache.clear();
1044 sStringCache.clear();
1045 }
1046 }
1047
1048 ApplicationPackageManager(ContextImpl context,
1049 IPackageManager pm) {
1050 mContext = context;
1051 mPM = pm;
1052 }
1053
Alan Viveretteecd585a2015-04-13 10:32:51 -07001054 @Nullable
1055 private Drawable getCachedIcon(@NonNull ResourceName name) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001056 synchronized (sSync) {
Alan Viveretteecd585a2015-04-13 10:32:51 -07001057 final WeakReference<Drawable.ConstantState> wr = sIconCache.get(name);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001058 if (DEBUG_ICONS) Log.v(TAG, "Get cached weak drawable ref for "
1059 + name + ": " + wr);
1060 if (wr != null) { // we have the activity
Alan Viveretteecd585a2015-04-13 10:32:51 -07001061 final Drawable.ConstantState state = wr.get();
Romain Guy39fe17c2011-11-30 10:34:07 -08001062 if (state != null) {
1063 if (DEBUG_ICONS) {
1064 Log.v(TAG, "Get cached drawable state for " + name + ": " + state);
1065 }
1066 // Note: It's okay here to not use the newDrawable(Resources) variant
1067 // of the API. The ConstantState comes from a drawable that was
1068 // originally created by passing the proper app Resources instance
1069 // which means the state should already contain the proper
1070 // resources specific information (like density.) See
1071 // BitmapDrawable.BitmapState for instance.
1072 return state.newDrawable();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001073 }
1074 // our entry has been purged
1075 sIconCache.remove(name);
1076 }
1077 }
1078 return null;
1079 }
1080
Alan Viveretteecd585a2015-04-13 10:32:51 -07001081 private void putCachedIcon(@NonNull ResourceName name, @NonNull Drawable dr) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001082 synchronized (sSync) {
Alan Viveretteecd585a2015-04-13 10:32:51 -07001083 sIconCache.put(name, new WeakReference<>(dr.getConstantState()));
Romain Guy39fe17c2011-11-30 10:34:07 -08001084 if (DEBUG_ICONS) Log.v(TAG, "Added cached drawable state for " + name + ": " + dr);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001085 }
1086 }
1087
Romain Guy39fe17c2011-11-30 10:34:07 -08001088 static void handlePackageBroadcast(int cmd, String[] pkgList, boolean hasPkgInfo) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001089 boolean immediateGc = false;
1090 if (cmd == IApplicationThread.EXTERNAL_STORAGE_UNAVAILABLE) {
1091 immediateGc = true;
1092 }
1093 if (pkgList != null && (pkgList.length > 0)) {
1094 boolean needCleanup = false;
1095 for (String ssp : pkgList) {
1096 synchronized (sSync) {
Dianne Hackbornadd005c2013-07-17 18:43:12 -07001097 for (int i=sIconCache.size()-1; i>=0; i--) {
1098 ResourceName nm = sIconCache.keyAt(i);
1099 if (nm.packageName.equals(ssp)) {
1100 //Log.i(TAG, "Removing cached drawable for " + nm);
1101 sIconCache.removeAt(i);
1102 needCleanup = true;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001103 }
1104 }
Dianne Hackbornadd005c2013-07-17 18:43:12 -07001105 for (int i=sStringCache.size()-1; i>=0; i--) {
1106 ResourceName nm = sStringCache.keyAt(i);
1107 if (nm.packageName.equals(ssp)) {
1108 //Log.i(TAG, "Removing cached string for " + nm);
1109 sStringCache.removeAt(i);
1110 needCleanup = true;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001111 }
1112 }
1113 }
1114 }
1115 if (needCleanup || hasPkgInfo) {
1116 if (immediateGc) {
1117 // Schedule an immediate gc.
1118 Runtime.getRuntime().gc();
1119 } else {
1120 ActivityThread.currentActivityThread().scheduleGcIdler();
1121 }
1122 }
1123 }
1124 }
1125
1126 private static final class ResourceName {
1127 final String packageName;
1128 final int iconId;
1129
1130 ResourceName(String _packageName, int _iconId) {
1131 packageName = _packageName;
1132 iconId = _iconId;
1133 }
1134
1135 ResourceName(ApplicationInfo aInfo, int _iconId) {
1136 this(aInfo.packageName, _iconId);
1137 }
1138
1139 ResourceName(ComponentInfo cInfo, int _iconId) {
1140 this(cInfo.applicationInfo.packageName, _iconId);
1141 }
1142
1143 ResourceName(ResolveInfo rInfo, int _iconId) {
1144 this(rInfo.activityInfo.applicationInfo.packageName, _iconId);
1145 }
1146
1147 @Override
1148 public boolean equals(Object o) {
1149 if (this == o) return true;
1150 if (o == null || getClass() != o.getClass()) return false;
1151
1152 ResourceName that = (ResourceName) o;
1153
1154 if (iconId != that.iconId) return false;
1155 return !(packageName != null ?
1156 !packageName.equals(that.packageName) : that.packageName != null);
1157
1158 }
1159
1160 @Override
1161 public int hashCode() {
1162 int result;
1163 result = packageName.hashCode();
1164 result = 31 * result + iconId;
1165 return result;
1166 }
1167
1168 @Override
1169 public String toString() {
1170 return "{ResourceName " + packageName + " / " + iconId + "}";
1171 }
1172 }
1173
1174 private CharSequence getCachedString(ResourceName name) {
1175 synchronized (sSync) {
1176 WeakReference<CharSequence> wr = sStringCache.get(name);
1177 if (wr != null) { // we have the activity
1178 CharSequence cs = wr.get();
1179 if (cs != null) {
1180 return cs;
1181 }
1182 // our entry has been purged
1183 sStringCache.remove(name);
1184 }
1185 }
1186 return null;
1187 }
1188
1189 private void putCachedString(ResourceName name, CharSequence cs) {
1190 synchronized (sSync) {
1191 sStringCache.put(name, new WeakReference<CharSequence>(cs));
1192 }
1193 }
1194
1195 @Override
Tor Norbye7b9c9122013-05-30 16:48:33 -07001196 public CharSequence getText(String packageName, @StringRes int resid,
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001197 ApplicationInfo appInfo) {
1198 ResourceName name = new ResourceName(packageName, resid);
1199 CharSequence text = getCachedString(name);
1200 if (text != null) {
1201 return text;
1202 }
1203 if (appInfo == null) {
1204 try {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001205 appInfo = getApplicationInfo(packageName, sDefaultFlags);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001206 } catch (NameNotFoundException e) {
1207 return null;
1208 }
1209 }
1210 try {
1211 Resources r = getResourcesForApplication(appInfo);
1212 text = r.getText(resid);
1213 putCachedString(name, text);
1214 return text;
1215 } catch (NameNotFoundException e) {
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07001216 Log.w("PackageManager", "Failure retrieving resources for "
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001217 + appInfo.packageName);
1218 } catch (RuntimeException e) {
1219 // If an exception was thrown, fall through to return
1220 // default icon.
1221 Log.w("PackageManager", "Failure retrieving text 0x"
1222 + Integer.toHexString(resid) + " in package "
1223 + packageName, e);
1224 }
1225 return null;
1226 }
1227
1228 @Override
Tor Norbye7b9c9122013-05-30 16:48:33 -07001229 public XmlResourceParser getXml(String packageName, @XmlRes int resid,
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001230 ApplicationInfo appInfo) {
1231 if (appInfo == null) {
1232 try {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001233 appInfo = getApplicationInfo(packageName, sDefaultFlags);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001234 } catch (NameNotFoundException e) {
1235 return null;
1236 }
1237 }
1238 try {
1239 Resources r = getResourcesForApplication(appInfo);
1240 return r.getXml(resid);
1241 } catch (RuntimeException e) {
1242 // If an exception was thrown, fall through to return
1243 // default icon.
1244 Log.w("PackageManager", "Failure retrieving xml 0x"
1245 + Integer.toHexString(resid) + " in package "
1246 + packageName, e);
1247 } catch (NameNotFoundException e) {
Alon Albert3fa51e32010-11-11 09:24:04 -08001248 Log.w("PackageManager", "Failure retrieving resources for "
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001249 + appInfo.packageName);
1250 }
1251 return null;
1252 }
1253
1254 @Override
1255 public CharSequence getApplicationLabel(ApplicationInfo info) {
1256 return info.loadLabel(this);
1257 }
1258
1259 @Override
1260 public void installPackage(Uri packageURI, IPackageInstallObserver observer, int flags,
1261 String installerPackageName) {
Jeff Sharkey513a0742014-07-08 17:10:32 -07001262 final VerificationParams verificationParams = new VerificationParams(null, null,
1263 null, VerificationParams.NO_UID, null);
1264 installCommon(packageURI, new LegacyPackageInstallObserver(observer), flags,
1265 installerPackageName, verificationParams, null);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001266 }
1267
1268 @Override
Kenny Root5ab21572011-07-27 11:11:19 -07001269 public void installPackageWithVerification(Uri packageURI, IPackageInstallObserver observer,
1270 int flags, String installerPackageName, Uri verificationURI,
Rich Canningse1d7c712012-08-08 12:46:06 -07001271 ManifestDigest manifestDigest, ContainerEncryptionParams encryptionParams) {
Jeff Sharkey513a0742014-07-08 17:10:32 -07001272 final VerificationParams verificationParams = new VerificationParams(verificationURI, null,
1273 null, VerificationParams.NO_UID, manifestDigest);
1274 installCommon(packageURI, new LegacyPackageInstallObserver(observer), flags,
1275 installerPackageName, verificationParams, encryptionParams);
Kenny Root5ab21572011-07-27 11:11:19 -07001276 }
1277
1278 @Override
John Spurlock8a985d22014-02-25 09:40:05 -05001279 public void installPackageWithVerificationAndEncryption(Uri packageURI,
rich cannings706e8ba2012-08-20 13:20:14 -07001280 IPackageInstallObserver observer, int flags, String installerPackageName,
1281 VerificationParams verificationParams, ContainerEncryptionParams encryptionParams) {
Jeff Sharkey513a0742014-07-08 17:10:32 -07001282 installCommon(packageURI, new LegacyPackageInstallObserver(observer), flags,
1283 installerPackageName, verificationParams, encryptionParams);
Christopher Tatef1977b42014-03-24 16:25:51 -07001284 }
1285
Christopher Tatef1977b42014-03-24 16:25:51 -07001286 @Override
1287 public void installPackage(Uri packageURI, PackageInstallObserver observer,
1288 int flags, String installerPackageName) {
Jeff Sharkey513a0742014-07-08 17:10:32 -07001289 final VerificationParams verificationParams = new VerificationParams(null, null,
1290 null, VerificationParams.NO_UID, null);
1291 installCommon(packageURI, observer, flags, installerPackageName, verificationParams, null);
Christopher Tatef1977b42014-03-24 16:25:51 -07001292 }
1293
1294 @Override
1295 public void installPackageWithVerification(Uri packageURI,
1296 PackageInstallObserver observer, int flags, String installerPackageName,
1297 Uri verificationURI, ManifestDigest manifestDigest,
1298 ContainerEncryptionParams encryptionParams) {
Jeff Sharkey513a0742014-07-08 17:10:32 -07001299 final VerificationParams verificationParams = new VerificationParams(verificationURI, null,
1300 null, VerificationParams.NO_UID, manifestDigest);
1301 installCommon(packageURI, observer, flags, installerPackageName, verificationParams,
1302 encryptionParams);
Christopher Tatef1977b42014-03-24 16:25:51 -07001303 }
1304
1305 @Override
1306 public void installPackageWithVerificationAndEncryption(Uri packageURI,
1307 PackageInstallObserver observer, int flags, String installerPackageName,
1308 VerificationParams verificationParams, ContainerEncryptionParams encryptionParams) {
Jeff Sharkey513a0742014-07-08 17:10:32 -07001309 installCommon(packageURI, observer, flags, installerPackageName, verificationParams,
1310 encryptionParams);
1311 }
1312
1313 private void installCommon(Uri packageURI,
1314 PackageInstallObserver observer, int flags, String installerPackageName,
1315 VerificationParams verificationParams, ContainerEncryptionParams encryptionParams) {
1316 if (!"file".equals(packageURI.getScheme())) {
1317 throw new UnsupportedOperationException("Only file:// URIs are supported");
1318 }
1319 if (encryptionParams != null) {
1320 throw new UnsupportedOperationException("ContainerEncryptionParams not supported");
1321 }
1322
1323 final String originPath = packageURI.getPath();
Christopher Tatef1977b42014-03-24 16:25:51 -07001324 try {
Jeff Sharkey513a0742014-07-08 17:10:32 -07001325 mPM.installPackage(originPath, observer.getBinder(), flags, installerPackageName,
1326 verificationParams, null);
1327 } catch (RemoteException ignored) {
rich cannings706e8ba2012-08-20 13:20:14 -07001328 }
1329 }
1330
1331 @Override
Dianne Hackborn7767eac2012-08-23 18:25:40 -07001332 public int installExistingPackage(String packageName)
1333 throws NameNotFoundException {
1334 try {
Amith Yamasani67df64b2012-12-14 12:09:36 -08001335 int res = mPM.installExistingPackageAsUser(packageName, UserHandle.myUserId());
Dianne Hackborn7767eac2012-08-23 18:25:40 -07001336 if (res == INSTALL_FAILED_INVALID_URI) {
1337 throw new NameNotFoundException("Package " + packageName + " doesn't exist");
1338 }
1339 return res;
1340 } catch (RemoteException e) {
1341 // Should never happen!
1342 throw new NameNotFoundException("Package " + packageName + " doesn't exist");
1343 }
1344 }
1345
1346 @Override
Kenny Root3a9b5fb2011-09-20 14:15:38 -07001347 public void verifyPendingInstall(int id, int response) {
Kenny Root5ab21572011-07-27 11:11:19 -07001348 try {
Kenny Root3a9b5fb2011-09-20 14:15:38 -07001349 mPM.verifyPendingInstall(id, response);
Kenny Root5ab21572011-07-27 11:11:19 -07001350 } catch (RemoteException e) {
1351 // Should never happen!
1352 }
1353 }
1354
1355 @Override
rich canningsd9ef3e52012-08-22 14:28:05 -07001356 public void extendVerificationTimeout(int id, int verificationCodeAtTimeout,
1357 long millisecondsToDelay) {
1358 try {
1359 mPM.extendVerificationTimeout(id, verificationCodeAtTimeout, millisecondsToDelay);
1360 } catch (RemoteException e) {
1361 // Should never happen!
1362 }
1363 }
1364
1365 @Override
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001366 public void verifyIntentFilter(int id, int verificationCode, List<String> outFailedDomains) {
1367 try {
1368 mPM.verifyIntentFilter(id, verificationCode, outFailedDomains);
1369 } catch (RemoteException e) {
1370 // Should never happen!
1371 }
1372 }
1373
1374 @Override
1375 public int getIntentVerificationStatus(String packageName, int userId) {
1376 try {
1377 return mPM.getIntentVerificationStatus(packageName, userId);
1378 } catch (RemoteException e) {
1379 // Should never happen!
1380 return PackageManager.INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_UNDEFINED;
1381 }
1382 }
1383
1384 @Override
1385 public boolean updateIntentVerificationStatus(String packageName, int status, int userId) {
1386 try {
1387 return mPM.updateIntentVerificationStatus(packageName, status, userId);
1388 } catch (RemoteException e) {
1389 // Should never happen!
1390 return false;
1391 }
1392 }
1393
1394 @Override
1395 public List<IntentFilterVerificationInfo> getIntentFilterVerifications(String packageName) {
1396 try {
1397 return mPM.getIntentFilterVerifications(packageName);
1398 } catch (RemoteException e) {
1399 // Should never happen!
1400 return null;
1401 }
1402 }
1403
1404 @Override
Fabrice Di Meglio07885952015-04-06 19:41:28 -07001405 public List<IntentFilter> getAllIntentFilters(String packageName) {
1406 try {
1407 return mPM.getAllIntentFilters(packageName);
1408 } catch (RemoteException e) {
1409 // Should never happen!
1410 return null;
1411 }
1412 }
1413
1414 @Override
Fabrice Di Meglio62271722015-04-10 17:24:02 -07001415 public String getDefaultBrowserPackageName(int userId) {
1416 try {
1417 return mPM.getDefaultBrowserPackageName(userId);
1418 } catch (RemoteException e) {
1419 // Should never happen!
1420 return null;
1421 }
1422 }
1423
1424 @Override
1425 public boolean setDefaultBrowserPackageName(String packageName, int userId) {
1426 try {
1427 return mPM.setDefaultBrowserPackageName(packageName, userId);
1428 } catch (RemoteException e) {
1429 // Should never happen!
1430 return false;
1431 }
1432 }
1433
1434 @Override
Dianne Hackborn880119b2010-11-18 22:26:40 -08001435 public void setInstallerPackageName(String targetPackage,
1436 String installerPackageName) {
1437 try {
1438 mPM.setInstallerPackageName(targetPackage, installerPackageName);
1439 } catch (RemoteException e) {
1440 // Should never happen!
1441 }
1442 }
1443
1444 @Override
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001445 public String getInstallerPackageName(String packageName) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001446 try {
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001447 return mPM.getInstallerPackageName(packageName);
1448 } catch (RemoteException e) {
1449 // Should never happen!
1450 }
1451 return null;
1452 }
1453
1454 @Override
1455 public int getMoveStatus(int moveId) {
1456 try {
1457 return mPM.getMoveStatus(moveId);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001458 } catch (RemoteException e) {
Jeff Sharkeyb2b9ab82015-04-05 21:10:42 -07001459 throw e.rethrowAsRuntimeException();
1460 }
1461 }
1462
1463 @Override
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001464 public void registerMoveCallback(MoveCallback callback, Handler handler) {
1465 synchronized (mDelegates) {
1466 final MoveCallbackDelegate delegate = new MoveCallbackDelegate(callback,
1467 handler.getLooper());
1468 try {
1469 mPM.registerMoveCallback(delegate);
1470 } catch (RemoteException e) {
1471 throw e.rethrowAsRuntimeException();
1472 }
1473 mDelegates.add(delegate);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001474 }
1475 }
1476
1477 @Override
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001478 public void unregisterMoveCallback(MoveCallback callback) {
1479 synchronized (mDelegates) {
1480 for (Iterator<MoveCallbackDelegate> i = mDelegates.iterator(); i.hasNext();) {
1481 final MoveCallbackDelegate delegate = i.next();
1482 if (delegate.mCallback == callback) {
1483 try {
1484 mPM.unregisterMoveCallback(delegate);
1485 } catch (RemoteException e) {
1486 throw e.rethrowAsRuntimeException();
1487 }
1488 i.remove();
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001489 }
1490 }
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001491 }
1492 }
1493
1494 @Override
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001495 public int movePackage(String packageName, VolumeInfo vol) {
1496 try {
1497 final String volumeUuid;
1498 if (VolumeInfo.ID_PRIVATE_INTERNAL.equals(vol.id)) {
1499 volumeUuid = StorageManager.UUID_PRIVATE_INTERNAL;
1500 } else if (vol.isPrimaryPhysical()) {
1501 volumeUuid = StorageManager.UUID_PRIMARY_PHYSICAL;
1502 } else {
1503 volumeUuid = Preconditions.checkNotNull(vol.fsUuid);
1504 }
1505
1506 return mPM.movePackage(packageName, volumeUuid);
1507 } catch (RemoteException e) {
1508 throw e.rethrowAsRuntimeException();
1509 }
1510 }
1511
1512 @Override
1513 public @Nullable VolumeInfo getPackageCurrentVolume(ApplicationInfo app) {
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001514 final StorageManager storage = mContext.getSystemService(StorageManager.class);
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001515 if (app.isInternal()) {
1516 return storage.findVolumeById(VolumeInfo.ID_PRIVATE_INTERNAL);
1517 } else if (app.isExternalAsec()) {
1518 return storage.getPrimaryPhysicalVolume();
1519 } else {
1520 return storage.findVolumeByUuid(app.volumeUuid);
1521 }
1522 }
1523
1524 @Override
1525 public @NonNull List<VolumeInfo> getPackageCandidateVolumes(ApplicationInfo app) {
1526 final StorageManager storage = mContext.getSystemService(StorageManager.class);
1527 final VolumeInfo currentVol = getPackageCurrentVolume(app);
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001528 final List<VolumeInfo> vols = storage.getVolumes();
1529 final List<VolumeInfo> candidates = new ArrayList<>();
1530 for (VolumeInfo vol : vols) {
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001531 if (Objects.equals(vol, currentVol) || isPackageCandidateVolume(app, vol)) {
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001532 candidates.add(vol);
1533 }
1534 }
1535 return candidates;
1536 }
1537
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001538 private static boolean isPackageCandidateVolume(ApplicationInfo app, VolumeInfo vol) {
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001539 // Private internal is always an option
1540 if (VolumeInfo.ID_PRIVATE_INTERNAL.equals(vol.getId())) {
1541 return true;
1542 }
1543
1544 // System apps and apps demanding internal storage can't be moved
1545 // anywhere else
1546 if (app.isSystemApp()
1547 || app.installLocation == PackageInfo.INSTALL_LOCATION_INTERNAL_ONLY) {
1548 return false;
1549 }
1550
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001551 // Gotta be able to write there
1552 if (!vol.isMountedWritable()) {
1553 return false;
1554 }
1555
1556 // Moving into an ASEC on public primary is only option internal
1557 if (vol.isPrimaryPhysical()) {
1558 return app.isInternal();
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001559 }
1560
1561 // Otherwise we can move to any private volume
1562 return (vol.getType() == VolumeInfo.TYPE_PRIVATE);
1563 }
1564
1565 @Override
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001566 public int movePrimaryStorage(VolumeInfo vol) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001567 try {
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001568 final String volumeUuid;
1569 if (VolumeInfo.ID_PRIVATE_INTERNAL.equals(vol.id)) {
1570 volumeUuid = StorageManager.UUID_PRIVATE_INTERNAL;
1571 } else if (vol.isPrimaryPhysical()) {
1572 volumeUuid = StorageManager.UUID_PRIMARY_PHYSICAL;
1573 } else {
1574 volumeUuid = Preconditions.checkNotNull(vol.fsUuid);
1575 }
1576
1577 return mPM.movePrimaryStorage(volumeUuid);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001578 } catch (RemoteException e) {
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001579 throw e.rethrowAsRuntimeException();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001580 }
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001581 }
1582
Jeff Sharkey275e3e42015-04-24 16:10:32 -07001583 @Override
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001584 public @Nullable VolumeInfo getPrimaryStorageCurrentVolume() {
1585 final StorageManager storage = mContext.getSystemService(StorageManager.class);
1586 final String volumeUuid = storage.getPrimaryStorageUuid();
Jeff Sharkey50a05452015-04-29 11:24:52 -07001587 return storage.findVolumeByQualifiedUuid(volumeUuid);
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001588 }
1589
Jeff Sharkey275e3e42015-04-24 16:10:32 -07001590 @Override
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001591 public @NonNull List<VolumeInfo> getPrimaryStorageCandidateVolumes() {
1592 final StorageManager storage = mContext.getSystemService(StorageManager.class);
1593 final VolumeInfo currentVol = getPrimaryStorageCurrentVolume();
1594 final List<VolumeInfo> vols = storage.getVolumes();
1595 final List<VolumeInfo> candidates = new ArrayList<>();
Jeff Sharkeyfced5342015-05-10 14:53:34 -07001596 if (Objects.equals(StorageManager.UUID_PRIMARY_PHYSICAL,
1597 storage.getPrimaryStorageUuid()) && currentVol != null) {
1598 // TODO: support moving primary physical to emulated volume
1599 candidates.add(currentVol);
1600 } else {
1601 for (VolumeInfo vol : vols) {
1602 if (Objects.equals(vol, currentVol) || isPrimaryStorageCandidateVolume(vol)) {
1603 candidates.add(vol);
1604 }
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001605 }
1606 }
1607 return candidates;
1608 }
1609
1610 private static boolean isPrimaryStorageCandidateVolume(VolumeInfo vol) {
1611 // Private internal is always an option
1612 if (VolumeInfo.ID_PRIVATE_INTERNAL.equals(vol.getId())) {
1613 return true;
1614 }
1615
1616 // Gotta be able to write there
1617 if (!vol.isMountedWritable()) {
1618 return false;
1619 }
1620
Jeff Sharkeyfced5342015-05-10 14:53:34 -07001621 // We can move to any private volume
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001622 return (vol.getType() == VolumeInfo.TYPE_PRIVATE);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001623 }
1624
1625 @Override
1626 public void deletePackage(String packageName, IPackageDeleteObserver observer, int flags) {
1627 try {
Amith Yamasani67df64b2012-12-14 12:09:36 -08001628 mPM.deletePackageAsUser(packageName, observer, UserHandle.myUserId(), flags);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001629 } catch (RemoteException e) {
1630 // Should never happen!
1631 }
1632 }
Jeff Sharkeyfbd0e9f2014-08-06 16:34:34 -07001633
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001634 @Override
1635 public void clearApplicationUserData(String packageName,
1636 IPackageDataObserver observer) {
1637 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -07001638 mPM.clearApplicationUserData(packageName, observer, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001639 } catch (RemoteException e) {
1640 // Should never happen!
1641 }
1642 }
1643 @Override
1644 public void deleteApplicationCacheFiles(String packageName,
1645 IPackageDataObserver observer) {
1646 try {
1647 mPM.deleteApplicationCacheFiles(packageName, observer);
1648 } catch (RemoteException e) {
1649 // Should never happen!
1650 }
1651 }
Jeff Sharkey529f91f2015-04-18 20:23:13 -07001652
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001653 @Override
Jeff Sharkey529f91f2015-04-18 20:23:13 -07001654 public void freeStorageAndNotify(String volumeUuid, long idealStorageSize,
1655 IPackageDataObserver observer) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001656 try {
Jeff Sharkey529f91f2015-04-18 20:23:13 -07001657 mPM.freeStorageAndNotify(volumeUuid, idealStorageSize, observer);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001658 } catch (RemoteException e) {
1659 // Should never happen!
1660 }
1661 }
1662
1663 @Override
Jeff Sharkey529f91f2015-04-18 20:23:13 -07001664 public void freeStorage(String volumeUuid, long freeStorageSize, IntentSender pi) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001665 try {
Jeff Sharkey529f91f2015-04-18 20:23:13 -07001666 mPM.freeStorage(volumeUuid, freeStorageSize, pi);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001667 } catch (RemoteException e) {
1668 // Should never happen!
1669 }
1670 }
1671
1672 @Override
Dianne Hackborn0c380492012-08-20 17:23:30 -07001673 public void getPackageSizeInfo(String packageName, int userHandle,
1674 IPackageStatsObserver observer) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001675 try {
Dianne Hackborn0c380492012-08-20 17:23:30 -07001676 mPM.getPackageSizeInfo(packageName, userHandle, observer);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001677 } catch (RemoteException e) {
1678 // Should never happen!
1679 }
1680 }
1681 @Override
1682 public void addPackageToPreferred(String packageName) {
1683 try {
1684 mPM.addPackageToPreferred(packageName);
1685 } catch (RemoteException e) {
1686 // Should never happen!
1687 }
1688 }
1689
1690 @Override
1691 public void removePackageFromPreferred(String packageName) {
1692 try {
1693 mPM.removePackageFromPreferred(packageName);
1694 } catch (RemoteException e) {
1695 // Should never happen!
1696 }
1697 }
1698
1699 @Override
1700 public List<PackageInfo> getPreferredPackages(int flags) {
1701 try {
1702 return mPM.getPreferredPackages(flags);
1703 } catch (RemoteException e) {
1704 // Should never happen!
1705 }
1706 return new ArrayList<PackageInfo>();
1707 }
1708
1709 @Override
1710 public void addPreferredActivity(IntentFilter filter,
1711 int match, ComponentName[] set, ComponentName activity) {
1712 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -07001713 mPM.addPreferredActivity(filter, match, set, activity, mContext.getUserId());
Amith Yamasania3f133a2012-08-09 17:11:28 -07001714 } catch (RemoteException e) {
1715 // Should never happen!
1716 }
1717 }
1718
1719 @Override
1720 public void addPreferredActivity(IntentFilter filter, int match,
1721 ComponentName[] set, ComponentName activity, int userId) {
1722 try {
1723 mPM.addPreferredActivity(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 replacePreferredActivity(IntentFilter filter,
1731 int match, ComponentName[] set, ComponentName activity) {
1732 try {
Amith Yamasani41c1ded2014-08-05 11:15:05 -07001733 mPM.replacePreferredActivity(filter, match, set, activity, UserHandle.myUserId());
1734 } catch (RemoteException e) {
1735 // Should never happen!
1736 }
1737 }
1738
1739 @Override
1740 public void replacePreferredActivityAsUser(IntentFilter filter,
1741 int match, ComponentName[] set, ComponentName activity,
1742 int userId) {
1743 try {
1744 mPM.replacePreferredActivity(filter, match, set, activity, userId);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001745 } catch (RemoteException e) {
1746 // Should never happen!
1747 }
1748 }
1749
1750 @Override
1751 public void clearPackagePreferredActivities(String packageName) {
1752 try {
1753 mPM.clearPackagePreferredActivities(packageName);
1754 } catch (RemoteException e) {
1755 // Should never happen!
1756 }
1757 }
1758
1759 @Override
1760 public int getPreferredActivities(List<IntentFilter> outFilters,
1761 List<ComponentName> outActivities, String packageName) {
1762 try {
1763 return mPM.getPreferredActivities(outFilters, outActivities, packageName);
1764 } catch (RemoteException e) {
1765 // Should never happen!
1766 }
1767 return 0;
1768 }
1769
1770 @Override
Christopher Tatea2a0850d2013-09-05 16:38:58 -07001771 public ComponentName getHomeActivities(List<ResolveInfo> outActivities) {
1772 try {
1773 return mPM.getHomeActivities(outActivities);
1774 } catch (RemoteException e) {
1775 // Should never happen!
1776 }
1777 return null;
1778 }
1779
1780 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001781 public void setComponentEnabledSetting(ComponentName componentName,
1782 int newState, int flags) {
1783 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -07001784 mPM.setComponentEnabledSetting(componentName, newState, flags, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001785 } catch (RemoteException e) {
1786 // Should never happen!
1787 }
1788 }
1789
1790 @Override
1791 public int getComponentEnabledSetting(ComponentName componentName) {
1792 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -07001793 return mPM.getComponentEnabledSetting(componentName, 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
1800 @Override
1801 public void setApplicationEnabledSetting(String packageName,
1802 int newState, int flags) {
1803 try {
Dianne Hackborn3fa3c28a2013-03-26 16:15:41 -07001804 mPM.setApplicationEnabledSetting(packageName, newState, flags,
Dianne Hackborn95d78532013-09-11 09:51:14 -07001805 mContext.getUserId(), mContext.getOpPackageName());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001806 } catch (RemoteException e) {
1807 // Should never happen!
1808 }
1809 }
1810
1811 @Override
1812 public int getApplicationEnabledSetting(String packageName) {
1813 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -07001814 return mPM.getApplicationEnabledSetting(packageName, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001815 } catch (RemoteException e) {
1816 // Should never happen!
1817 }
1818 return PackageManager.COMPONENT_ENABLED_STATE_DEFAULT;
1819 }
1820
Amith Yamasani655d0e22013-06-12 14:19:10 -07001821 @Override
Amith Yamasanie5bcff62014-07-19 15:44:09 -07001822 public boolean setApplicationHiddenSettingAsUser(String packageName, boolean hidden,
Amith Yamasani655d0e22013-06-12 14:19:10 -07001823 UserHandle user) {
1824 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07001825 return mPM.setApplicationHiddenSettingAsUser(packageName, hidden,
Amith Yamasani655d0e22013-06-12 14:19:10 -07001826 user.getIdentifier());
1827 } catch (RemoteException re) {
1828 // Should never happen!
1829 }
1830 return false;
1831 }
1832
1833 @Override
Amith Yamasanie5bcff62014-07-19 15:44:09 -07001834 public boolean getApplicationHiddenSettingAsUser(String packageName, UserHandle user) {
Amith Yamasani655d0e22013-06-12 14:19:10 -07001835 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07001836 return mPM.getApplicationHiddenSettingAsUser(packageName, user.getIdentifier());
Amith Yamasani655d0e22013-06-12 14:19:10 -07001837 } catch (RemoteException re) {
1838 // Should never happen!
1839 }
1840 return false;
1841 }
1842
dcashmanc6f22492014-08-14 09:54:51 -07001843 /** @hide */
dcashman9d2f4412014-06-09 09:27:54 -07001844 @Override
1845 public KeySet getKeySetByAlias(String packageName, String alias) {
1846 Preconditions.checkNotNull(packageName);
1847 Preconditions.checkNotNull(alias);
dcashmanc6f22492014-08-14 09:54:51 -07001848 KeySet ks;
dcashman9d2f4412014-06-09 09:27:54 -07001849 try {
dcashmanc6f22492014-08-14 09:54:51 -07001850 ks = mPM.getKeySetByAlias(packageName, alias);
dcashman9d2f4412014-06-09 09:27:54 -07001851 } catch (RemoteException e) {
1852 return null;
1853 }
dcashmanc6f22492014-08-14 09:54:51 -07001854 return ks;
dcashman9d2f4412014-06-09 09:27:54 -07001855 }
1856
dcashmanc6f22492014-08-14 09:54:51 -07001857 /** @hide */
dcashman9d2f4412014-06-09 09:27:54 -07001858 @Override
1859 public KeySet getSigningKeySet(String packageName) {
1860 Preconditions.checkNotNull(packageName);
dcashmanc6f22492014-08-14 09:54:51 -07001861 KeySet ks;
dcashman9d2f4412014-06-09 09:27:54 -07001862 try {
dcashmanc6f22492014-08-14 09:54:51 -07001863 ks = mPM.getSigningKeySet(packageName);
dcashman9d2f4412014-06-09 09:27:54 -07001864 } catch (RemoteException e) {
1865 return null;
1866 }
dcashmanc6f22492014-08-14 09:54:51 -07001867 return ks;
dcashman9d2f4412014-06-09 09:27:54 -07001868 }
1869
dcashmanc6f22492014-08-14 09:54:51 -07001870 /** @hide */
dcashman9d2f4412014-06-09 09:27:54 -07001871 @Override
1872 public boolean isSignedBy(String packageName, KeySet ks) {
1873 Preconditions.checkNotNull(packageName);
1874 Preconditions.checkNotNull(ks);
dcashman9d2f4412014-06-09 09:27:54 -07001875 try {
dcashmanc6f22492014-08-14 09:54:51 -07001876 return mPM.isPackageSignedByKeySet(packageName, ks);
dcashman9d2f4412014-06-09 09:27:54 -07001877 } catch (RemoteException e) {
1878 return false;
1879 }
1880 }
1881
dcashmanc6f22492014-08-14 09:54:51 -07001882 /** @hide */
dcashman9d2f4412014-06-09 09:27:54 -07001883 @Override
1884 public boolean isSignedByExactly(String packageName, KeySet ks) {
1885 Preconditions.checkNotNull(packageName);
1886 Preconditions.checkNotNull(ks);
dcashman9d2f4412014-06-09 09:27:54 -07001887 try {
dcashmanc6f22492014-08-14 09:54:51 -07001888 return mPM.isPackageSignedByKeySetExactly(packageName, ks);
dcashman9d2f4412014-06-09 09:27:54 -07001889 } catch (RemoteException e) {
1890 return false;
1891 }
1892 }
1893
Kenny Root0aaa0d92011-09-12 16:42:55 -07001894 /**
1895 * @hide
1896 */
1897 @Override
1898 public VerifierDeviceIdentity getVerifierDeviceIdentity() {
1899 try {
1900 return mPM.getVerifierDeviceIdentity();
1901 } catch (RemoteException e) {
1902 // Should never happen!
1903 }
1904 return null;
1905 }
1906
Jeff Hao9f60c082014-10-28 18:51:07 -07001907 /**
1908 * @hide
1909 */
1910 @Override
1911 public boolean isUpgrade() {
1912 try {
1913 return mPM.isUpgrade();
1914 } catch (RemoteException e) {
1915 return false;
1916 }
1917 }
1918
Jeff Sharkey3a44f3f2014-04-28 17:36:31 -07001919 @Override
Jeff Sharkey16c8e3f2014-07-24 17:08:17 -07001920 public PackageInstaller getPackageInstaller() {
1921 synchronized (mLock) {
1922 if (mInstaller == null) {
1923 try {
Jeff Sharkeya0907432014-08-15 10:23:11 -07001924 mInstaller = new PackageInstaller(mContext, this, mPM.getPackageInstaller(),
Jeff Sharkey16c8e3f2014-07-24 17:08:17 -07001925 mContext.getPackageName(), mContext.getUserId());
1926 } catch (RemoteException e) {
1927 throw e.rethrowAsRuntimeException();
1928 }
1929 }
1930 return mInstaller;
Jeff Sharkey3a44f3f2014-04-28 17:36:31 -07001931 }
1932 }
1933
Jeff Sharkey6c833e02014-07-14 22:44:30 -07001934 @Override
1935 public boolean isPackageAvailable(String packageName) {
1936 try {
1937 return mPM.isPackageAvailable(packageName, mContext.getUserId());
1938 } catch (RemoteException e) {
1939 throw e.rethrowAsRuntimeException();
1940 }
1941 }
1942
Nicolas Prevotc79586e2014-05-06 12:47:57 +01001943 /**
1944 * @hide
1945 */
1946 @Override
Nicolas Prevot63798c52014-05-27 13:22:38 +01001947 public void addCrossProfileIntentFilter(IntentFilter filter, int sourceUserId, int targetUserId,
1948 int flags) {
Nicolas Prevotc79586e2014-05-06 12:47:57 +01001949 try {
Nicolas Prevot3f7777f2014-07-24 15:58:39 +01001950 mPM.addCrossProfileIntentFilter(filter, mContext.getOpPackageName(),
Nicolas Prevot4b8d5822015-03-05 15:20:49 +00001951 sourceUserId, targetUserId, flags);
Nicolas Prevotc79586e2014-05-06 12:47:57 +01001952 } catch (RemoteException e) {
1953 // Should never happen!
1954 }
1955 }
1956
1957 /**
1958 * @hide
1959 */
1960 @Override
Nicolas Prevot81948992014-05-16 18:25:26 +01001961 public void clearCrossProfileIntentFilters(int sourceUserId) {
Nicolas Prevotc79586e2014-05-06 12:47:57 +01001962 try {
Nicolas Prevot4b8d5822015-03-05 15:20:49 +00001963 mPM.clearCrossProfileIntentFilters(sourceUserId, mContext.getOpPackageName());
Nicolas Prevotc79586e2014-05-06 12:47:57 +01001964 } catch (RemoteException e) {
1965 // Should never happen!
1966 }
1967 }
1968
Nicolas Prevot88cc3462014-05-14 14:51:48 +01001969 /**
1970 * @hide
1971 */
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +01001972 public Drawable loadItemIcon(PackageItemInfo itemInfo, ApplicationInfo appInfo) {
Benjamin Franzec2d48b2014-10-01 15:38:43 +01001973 Drawable dr = loadUnbadgedItemIcon(itemInfo, appInfo);
1974 if (itemInfo.showUserIcon != UserHandle.USER_NULL) {
1975 return dr;
1976 }
1977 return getUserBadgedIcon(dr, new UserHandle(mContext.getUserId()));
1978 }
1979
1980 /**
1981 * @hide
1982 */
1983 public Drawable loadUnbadgedItemIcon(PackageItemInfo itemInfo, ApplicationInfo appInfo) {
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +01001984 if (itemInfo.showUserIcon != UserHandle.USER_NULL) {
Alexandra Gherghina64d4dca2014-08-28 18:26:56 +01001985 Bitmap bitmap = getUserManager().getUserIcon(itemInfo.showUserIcon);
1986 if (bitmap == null) {
1987 return UserIcons.getDefaultUserIcon(itemInfo.showUserIcon, /* light= */ false);
1988 }
1989 return new BitmapDrawable(bitmap);
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +01001990 }
Alexandra Gherghinadb811db2014-08-29 13:43:59 +01001991 Drawable dr = null;
1992 if (itemInfo.packageName != null) {
1993 dr = getDrawable(itemInfo.packageName, itemInfo.icon, appInfo);
1994 }
Alexandra Gherghinaa71e3902014-07-25 20:03:47 +01001995 if (dr == null) {
Alexandra Gherghinaa7093142014-07-30 13:43:39 +01001996 dr = itemInfo.loadDefaultIcon(this);
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +01001997 }
Benjamin Franzec2d48b2014-10-01 15:38:43 +01001998 return dr;
Svetoslavc7d62f02014-09-04 15:39:54 -07001999 }
2000
2001 private Drawable getBadgedDrawable(Drawable drawable, Drawable badgeDrawable,
2002 Rect badgeLocation, boolean tryBadgeInPlace) {
2003 final int badgedWidth = drawable.getIntrinsicWidth();
2004 final int badgedHeight = drawable.getIntrinsicHeight();
2005 final boolean canBadgeInPlace = tryBadgeInPlace
2006 && (drawable instanceof BitmapDrawable)
2007 && ((BitmapDrawable) drawable).getBitmap().isMutable();
2008
2009 final Bitmap bitmap;
2010 if (canBadgeInPlace) {
2011 bitmap = ((BitmapDrawable) drawable).getBitmap();
2012 } else {
2013 bitmap = Bitmap.createBitmap(badgedWidth, badgedHeight, Bitmap.Config.ARGB_8888);
2014 }
2015 Canvas canvas = new Canvas(bitmap);
2016
2017 if (!canBadgeInPlace) {
2018 drawable.setBounds(0, 0, badgedWidth, badgedHeight);
2019 drawable.draw(canvas);
2020 }
2021
2022 if (badgeLocation != null) {
2023 if (badgeLocation.left < 0 || badgeLocation.top < 0
2024 || badgeLocation.width() > badgedWidth || badgeLocation.height() > badgedHeight) {
2025 throw new IllegalArgumentException("Badge location " + badgeLocation
2026 + " not in badged drawable bounds "
2027 + new Rect(0, 0, badgedWidth, badgedHeight));
2028 }
2029 badgeDrawable.setBounds(0, 0, badgeLocation.width(), badgeLocation.height());
2030
2031 canvas.save();
2032 canvas.translate(badgeLocation.left, badgeLocation.top);
2033 badgeDrawable.draw(canvas);
2034 canvas.restore();
2035 } else {
2036 badgeDrawable.setBounds(0, 0, badgedWidth, badgedHeight);
2037 badgeDrawable.draw(canvas);
2038 }
2039
2040 if (!canBadgeInPlace) {
2041 BitmapDrawable mergedDrawable = new BitmapDrawable(mContext.getResources(), bitmap);
2042
2043 if (drawable instanceof BitmapDrawable) {
2044 BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
2045 mergedDrawable.setTargetDensity(bitmapDrawable.getBitmap().getDensity());
2046 }
2047
2048 return mergedDrawable;
2049 }
2050
2051 return drawable;
2052 }
2053
2054 private int getBadgeResIdForUser(int userHandle) {
2055 // Return the framework-provided badge.
2056 UserInfo userInfo = getUserIfProfile(userHandle);
2057 if (userInfo != null && userInfo.isManagedProfile()) {
2058 return com.android.internal.R.drawable.ic_corp_icon_badge;
2059 }
2060 return 0;
2061 }
2062
2063 private UserInfo getUserIfProfile(int userHandle) {
Svetoslav7de2abb2014-09-05 11:28:00 -07002064 List<UserInfo> userProfiles = getUserManager().getProfiles(UserHandle.myUserId());
Svetoslavc7d62f02014-09-04 15:39:54 -07002065 for (UserInfo user : userProfiles) {
2066 if (user.id == userHandle) {
2067 return user;
2068 }
2069 }
2070 return null;
Nicolas Prevot88cc3462014-05-14 14:51:48 +01002071 }
2072
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002073 /** {@hide} */
2074 private static class MoveCallbackDelegate extends IPackageMoveObserver.Stub implements
2075 Handler.Callback {
Jeff Sharkey50a05452015-04-29 11:24:52 -07002076 private static final int MSG_CREATED = 1;
2077 private static final int MSG_STATUS_CHANGED = 2;
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002078
2079 final MoveCallback mCallback;
2080 final Handler mHandler;
2081
2082 public MoveCallbackDelegate(MoveCallback callback, Looper looper) {
2083 mCallback = callback;
2084 mHandler = new Handler(looper, this);
2085 }
2086
2087 @Override
2088 public boolean handleMessage(Message msg) {
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002089 switch (msg.what) {
Jeff Sharkey50a05452015-04-29 11:24:52 -07002090 case MSG_CREATED: {
Jeff Sharkeyb36586a2015-04-27 08:42:28 -07002091 final SomeArgs args = (SomeArgs) msg.obj;
Jeff Sharkey50a05452015-04-29 11:24:52 -07002092 mCallback.onCreated(args.argi1, (Bundle) args.arg2);
Jeff Sharkeyb36586a2015-04-27 08:42:28 -07002093 args.recycle();
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002094 return true;
Jeff Sharkey50a05452015-04-29 11:24:52 -07002095 }
2096 case MSG_STATUS_CHANGED: {
2097 final SomeArgs args = (SomeArgs) msg.obj;
2098 mCallback.onStatusChanged(args.argi1, args.argi2, (long) args.arg3);
2099 args.recycle();
2100 return true;
2101 }
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002102 }
2103 return false;
2104 }
2105
2106 @Override
Jeff Sharkey50a05452015-04-29 11:24:52 -07002107 public void onCreated(int moveId, Bundle extras) {
Jeff Sharkeyb36586a2015-04-27 08:42:28 -07002108 final SomeArgs args = SomeArgs.obtain();
2109 args.argi1 = moveId;
Jeff Sharkey50a05452015-04-29 11:24:52 -07002110 args.arg2 = extras;
2111 mHandler.obtainMessage(MSG_CREATED, args).sendToTarget();
2112 }
2113
2114 @Override
2115 public void onStatusChanged(int moveId, int status, long estMillis) {
2116 final SomeArgs args = SomeArgs.obtain();
2117 args.argi1 = moveId;
2118 args.argi2 = status;
2119 args.arg3 = estMillis;
Jeff Sharkeyb36586a2015-04-27 08:42:28 -07002120 mHandler.obtainMessage(MSG_STATUS_CHANGED, args).sendToTarget();
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002121 }
2122 }
2123
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002124 private final ContextImpl mContext;
2125 private final IPackageManager mPM;
2126
2127 private static final Object sSync = new Object();
Dianne Hackbornadd005c2013-07-17 18:43:12 -07002128 private static ArrayMap<ResourceName, WeakReference<Drawable.ConstantState>> sIconCache
2129 = new ArrayMap<ResourceName, WeakReference<Drawable.ConstantState>>();
2130 private static ArrayMap<ResourceName, WeakReference<CharSequence>> sStringCache
2131 = new ArrayMap<ResourceName, WeakReference<CharSequence>>();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002132}