blob: 7c30ecd19cd3805310fc67a585c93734f7c75bf6 [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
19import android.content.ComponentName;
20import android.content.ContentResolver;
21import android.content.Intent;
22import android.content.IntentFilter;
23import android.content.IntentSender;
24import android.content.pm.ActivityInfo;
25import android.content.pm.ApplicationInfo;
26import android.content.pm.ComponentInfo;
Anonymous Cowardceb1b0b2012-04-24 10:35:16 -070027import android.content.pm.ContainerEncryptionParams;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080028import android.content.pm.FeatureInfo;
29import android.content.pm.IPackageDataObserver;
30import android.content.pm.IPackageDeleteObserver;
31import android.content.pm.IPackageInstallObserver;
32import android.content.pm.IPackageManager;
33import android.content.pm.IPackageMoveObserver;
34import android.content.pm.IPackageStatsObserver;
35import android.content.pm.InstrumentationInfo;
36import android.content.pm.PackageInfo;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080037import android.content.pm.PackageManager;
Kenny Roote6cd0c72011-05-19 12:48:14 -070038import android.content.pm.ParceledListSlice;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080039import android.content.pm.PermissionGroupInfo;
40import android.content.pm.PermissionInfo;
41import android.content.pm.ProviderInfo;
42import android.content.pm.ResolveInfo;
43import android.content.pm.ServiceInfo;
Kenny Root5ab21572011-07-27 11:11:19 -070044import android.content.pm.ManifestDigest;
rich cannings706e8ba2012-08-20 13:20:14 -070045import android.content.pm.VerificationParams;
Kenny Root0aaa0d92011-09-12 16:42:55 -070046import android.content.pm.VerifierDeviceIdentity;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080047import android.content.res.Resources;
48import android.content.res.XmlResourceParser;
49import android.graphics.drawable.Drawable;
50import android.net.Uri;
51import android.os.Process;
52import android.os.RemoteException;
Amith Yamasani67df64b2012-12-14 12:09:36 -080053import android.os.UserHandle;
Dianne Hackbornadd005c2013-07-17 18:43:12 -070054import android.util.ArrayMap;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080055import android.util.Log;
Jeff Browna492c3a2012-08-23 19:48:44 -070056import android.view.Display;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080057
58import java.lang.ref.WeakReference;
59import java.util.ArrayList;
60import java.util.HashMap;
61import java.util.Iterator;
62import java.util.List;
63
64/*package*/
65final class ApplicationPackageManager extends PackageManager {
66 private static final String TAG = "ApplicationPackageManager";
67 private final static boolean DEBUG = false;
68 private final static boolean DEBUG_ICONS = false;
69
70 @Override
71 public PackageInfo getPackageInfo(String packageName, int flags)
72 throws NameNotFoundException {
73 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -070074 PackageInfo pi = mPM.getPackageInfo(packageName, flags, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080075 if (pi != null) {
76 return pi;
77 }
78 } catch (RemoteException e) {
79 throw new RuntimeException("Package manager has died", e);
80 }
81
82 throw new NameNotFoundException(packageName);
83 }
84
85 @Override
86 public String[] currentToCanonicalPackageNames(String[] names) {
87 try {
88 return mPM.currentToCanonicalPackageNames(names);
89 } catch (RemoteException e) {
90 throw new RuntimeException("Package manager has died", e);
91 }
92 }
93
94 @Override
95 public String[] canonicalToCurrentPackageNames(String[] names) {
96 try {
97 return mPM.canonicalToCurrentPackageNames(names);
98 } catch (RemoteException e) {
99 throw new RuntimeException("Package manager has died", e);
100 }
101 }
102
103 @Override
104 public Intent getLaunchIntentForPackage(String packageName) {
105 // First see if the package has an INFO activity; the existence of
106 // such an activity is implied to be the desired front-door for the
107 // overall package (such as if it has multiple launcher entries).
108 Intent intentToResolve = new Intent(Intent.ACTION_MAIN);
109 intentToResolve.addCategory(Intent.CATEGORY_INFO);
110 intentToResolve.setPackage(packageName);
Dianne Hackborn19415762010-12-15 00:20:27 -0800111 List<ResolveInfo> ris = queryIntentActivities(intentToResolve, 0);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800112
113 // Otherwise, try to find a main launcher activity.
Dianne Hackborn19415762010-12-15 00:20:27 -0800114 if (ris == null || ris.size() <= 0) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800115 // reuse the intent instance
116 intentToResolve.removeCategory(Intent.CATEGORY_INFO);
117 intentToResolve.addCategory(Intent.CATEGORY_LAUNCHER);
118 intentToResolve.setPackage(packageName);
Dianne Hackborn19415762010-12-15 00:20:27 -0800119 ris = queryIntentActivities(intentToResolve, 0);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800120 }
Dianne Hackborn19415762010-12-15 00:20:27 -0800121 if (ris == null || ris.size() <= 0) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800122 return null;
123 }
124 Intent intent = new Intent(intentToResolve);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800125 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Dianne Hackborn19415762010-12-15 00:20:27 -0800126 intent.setClassName(ris.get(0).activityInfo.packageName,
127 ris.get(0).activityInfo.name);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800128 return intent;
129 }
130
Tim Kilbourneeeacab2014-05-06 14:33:02 -0700131 /** @hide */
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800132 @Override
Jose Lima970417c2014-04-10 10:42:19 -0700133 public Intent getLeanbackLaunchIntentForPackage(String packageName) {
134 // Try to find a main leanback_launcher activity.
135 Intent intentToResolve = new Intent(Intent.ACTION_MAIN);
136 intentToResolve.addCategory(Intent.CATEGORY_LEANBACK_LAUNCHER);
137 intentToResolve.setPackage(packageName);
138 List<ResolveInfo> ris = queryIntentActivities(intentToResolve, 0);
139
140 if (ris == null || ris.size() <= 0) {
141 return null;
142 }
143 Intent intent = new Intent(intentToResolve);
144 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
145 intent.setClassName(ris.get(0).activityInfo.packageName,
146 ris.get(0).activityInfo.name);
147 return intent;
148 }
149
150 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800151 public int[] getPackageGids(String packageName)
152 throws NameNotFoundException {
153 try {
154 int[] gids = mPM.getPackageGids(packageName);
155 if (gids == null || gids.length > 0) {
156 return gids;
157 }
158 } catch (RemoteException e) {
159 throw new RuntimeException("Package manager has died", e);
160 }
161
162 throw new NameNotFoundException(packageName);
163 }
164
165 @Override
Dianne Hackborna06de0f2012-12-11 16:34:47 -0800166 public int getPackageUid(String packageName, int userHandle)
167 throws NameNotFoundException {
168 try {
169 int uid = mPM.getPackageUid(packageName, userHandle);
170 if (uid >= 0) {
171 return uid;
172 }
173 } catch (RemoteException e) {
174 throw new RuntimeException("Package manager has died", e);
175 }
176
177 throw new NameNotFoundException(packageName);
178 }
179
180 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800181 public PermissionInfo getPermissionInfo(String name, int flags)
182 throws NameNotFoundException {
183 try {
184 PermissionInfo pi = mPM.getPermissionInfo(name, flags);
185 if (pi != null) {
186 return pi;
187 }
188 } catch (RemoteException e) {
189 throw new RuntimeException("Package manager has died", e);
190 }
191
192 throw new NameNotFoundException(name);
193 }
194
195 @Override
196 public List<PermissionInfo> queryPermissionsByGroup(String group, int flags)
197 throws NameNotFoundException {
198 try {
199 List<PermissionInfo> pi = mPM.queryPermissionsByGroup(group, flags);
200 if (pi != null) {
201 return pi;
202 }
203 } catch (RemoteException e) {
204 throw new RuntimeException("Package manager has died", e);
205 }
206
207 throw new NameNotFoundException(group);
208 }
209
210 @Override
211 public PermissionGroupInfo getPermissionGroupInfo(String name,
212 int flags) throws NameNotFoundException {
213 try {
214 PermissionGroupInfo pgi = mPM.getPermissionGroupInfo(name, flags);
215 if (pgi != null) {
216 return pgi;
217 }
218 } catch (RemoteException e) {
219 throw new RuntimeException("Package manager has died", e);
220 }
221
222 throw new NameNotFoundException(name);
223 }
224
225 @Override
226 public List<PermissionGroupInfo> getAllPermissionGroups(int flags) {
227 try {
228 return mPM.getAllPermissionGroups(flags);
229 } catch (RemoteException e) {
230 throw new RuntimeException("Package manager has died", e);
231 }
232 }
233
234 @Override
235 public ApplicationInfo getApplicationInfo(String packageName, int flags)
236 throws NameNotFoundException {
237 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700238 ApplicationInfo ai = mPM.getApplicationInfo(packageName, flags, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800239 if (ai != null) {
240 return ai;
241 }
242 } catch (RemoteException e) {
243 throw new RuntimeException("Package manager has died", e);
244 }
245
246 throw new NameNotFoundException(packageName);
247 }
248
249 @Override
250 public ActivityInfo getActivityInfo(ComponentName className, int flags)
251 throws NameNotFoundException {
252 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700253 ActivityInfo ai = mPM.getActivityInfo(className, flags, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800254 if (ai != null) {
255 return ai;
256 }
257 } catch (RemoteException e) {
258 throw new RuntimeException("Package manager has died", e);
259 }
260
261 throw new NameNotFoundException(className.toString());
262 }
263
264 @Override
265 public ActivityInfo getReceiverInfo(ComponentName className, int flags)
266 throws NameNotFoundException {
267 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700268 ActivityInfo ai = mPM.getReceiverInfo(className, flags, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800269 if (ai != null) {
270 return ai;
271 }
272 } catch (RemoteException e) {
273 throw new RuntimeException("Package manager has died", e);
274 }
275
276 throw new NameNotFoundException(className.toString());
277 }
278
279 @Override
280 public ServiceInfo getServiceInfo(ComponentName className, int flags)
281 throws NameNotFoundException {
282 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700283 ServiceInfo si = mPM.getServiceInfo(className, flags, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800284 if (si != null) {
285 return si;
286 }
287 } catch (RemoteException e) {
288 throw new RuntimeException("Package manager has died", e);
289 }
290
291 throw new NameNotFoundException(className.toString());
292 }
293
294 @Override
295 public ProviderInfo getProviderInfo(ComponentName className, int flags)
296 throws NameNotFoundException {
297 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700298 ProviderInfo pi = mPM.getProviderInfo(className, flags, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800299 if (pi != null) {
300 return pi;
301 }
302 } catch (RemoteException e) {
303 throw new RuntimeException("Package manager has died", e);
304 }
305
306 throw new NameNotFoundException(className.toString());
307 }
308
309 @Override
310 public String[] getSystemSharedLibraryNames() {
311 try {
312 return mPM.getSystemSharedLibraryNames();
313 } catch (RemoteException e) {
314 throw new RuntimeException("Package manager has died", e);
315 }
316 }
317
318 @Override
319 public FeatureInfo[] getSystemAvailableFeatures() {
320 try {
321 return mPM.getSystemAvailableFeatures();
322 } catch (RemoteException e) {
323 throw new RuntimeException("Package manager has died", e);
324 }
325 }
326
327 @Override
328 public boolean hasSystemFeature(String name) {
329 try {
330 return mPM.hasSystemFeature(name);
331 } catch (RemoteException e) {
332 throw new RuntimeException("Package manager has died", e);
333 }
334 }
335
336 @Override
337 public int checkPermission(String permName, String pkgName) {
338 try {
339 return mPM.checkPermission(permName, pkgName);
340 } catch (RemoteException e) {
341 throw new RuntimeException("Package manager has died", e);
342 }
343 }
344
345 @Override
346 public boolean addPermission(PermissionInfo info) {
347 try {
348 return mPM.addPermission(info);
349 } catch (RemoteException e) {
350 throw new RuntimeException("Package manager has died", e);
351 }
352 }
353
354 @Override
355 public boolean addPermissionAsync(PermissionInfo info) {
356 try {
357 return mPM.addPermissionAsync(info);
358 } catch (RemoteException e) {
359 throw new RuntimeException("Package manager has died", e);
360 }
361 }
362
363 @Override
364 public void removePermission(String name) {
365 try {
366 mPM.removePermission(name);
367 } catch (RemoteException e) {
368 throw new RuntimeException("Package manager has died", e);
369 }
370 }
371
372 @Override
Dianne Hackborne639da72012-02-21 15:11:13 -0800373 public void grantPermission(String packageName, String permissionName) {
374 try {
375 mPM.grantPermission(packageName, permissionName);
376 } catch (RemoteException e) {
377 throw new RuntimeException("Package manager has died", e);
378 }
379 }
380
381 @Override
382 public void revokePermission(String packageName, String permissionName) {
383 try {
384 mPM.revokePermission(packageName, permissionName);
385 } catch (RemoteException e) {
386 throw new RuntimeException("Package manager has died", e);
387 }
388 }
389
390 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800391 public int checkSignatures(String pkg1, String pkg2) {
392 try {
393 return mPM.checkSignatures(pkg1, pkg2);
394 } catch (RemoteException e) {
395 throw new RuntimeException("Package manager has died", e);
396 }
397 }
398
399 @Override
400 public int checkSignatures(int uid1, int uid2) {
401 try {
402 return mPM.checkUidSignatures(uid1, uid2);
403 } catch (RemoteException e) {
404 throw new RuntimeException("Package manager has died", e);
405 }
406 }
407
408 @Override
409 public String[] getPackagesForUid(int uid) {
410 try {
411 return mPM.getPackagesForUid(uid);
412 } catch (RemoteException e) {
413 throw new RuntimeException("Package manager has died", e);
414 }
415 }
416
417 @Override
418 public String getNameForUid(int uid) {
419 try {
420 return mPM.getNameForUid(uid);
421 } catch (RemoteException e) {
422 throw new RuntimeException("Package manager has died", e);
423 }
424 }
425
426 @Override
427 public int getUidForSharedUser(String sharedUserName)
428 throws NameNotFoundException {
429 try {
430 int uid = mPM.getUidForSharedUser(sharedUserName);
431 if(uid != -1) {
432 return uid;
433 }
434 } catch (RemoteException e) {
435 throw new RuntimeException("Package manager has died", e);
436 }
437 throw new NameNotFoundException("No shared userid for user:"+sharedUserName);
438 }
439
Kenny Roote6cd0c72011-05-19 12:48:14 -0700440 @SuppressWarnings("unchecked")
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800441 @Override
442 public List<PackageInfo> getInstalledPackages(int flags) {
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700443 return getInstalledPackages(flags, mContext.getUserId());
Amith Yamasani151ec4c2012-09-07 19:25:16 -0700444 }
445
446 /** @hide */
447 @Override
448 public List<PackageInfo> getInstalledPackages(int flags, int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800449 try {
Dianne Hackbornd8e1dbb2013-01-17 17:47:37 -0800450 ParceledListSlice<PackageInfo> slice = mPM.getInstalledPackages(flags, userId);
451 return slice.getList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800452 } catch (RemoteException e) {
453 throw new RuntimeException("Package manager has died", e);
454 }
455 }
456
Kenny Roote6cd0c72011-05-19 12:48:14 -0700457 @SuppressWarnings("unchecked")
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800458 @Override
Dianne Hackborne7991752013-01-16 17:56:46 -0800459 public List<PackageInfo> getPackagesHoldingPermissions(
460 String[] permissions, int flags) {
461 final int userId = mContext.getUserId();
462 try {
Dianne Hackbornd8e1dbb2013-01-17 17:47:37 -0800463 ParceledListSlice<PackageInfo> slice = mPM.getPackagesHoldingPermissions(
464 permissions, flags, userId);
465 return slice.getList();
Dianne Hackborne7991752013-01-16 17:56:46 -0800466 } catch (RemoteException e) {
467 throw new RuntimeException("Package manager has died", e);
468 }
469 }
470
471 @SuppressWarnings("unchecked")
472 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800473 public List<ApplicationInfo> getInstalledApplications(int flags) {
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700474 final int userId = mContext.getUserId();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800475 try {
Dianne Hackbornd8e1dbb2013-01-17 17:47:37 -0800476 ParceledListSlice<ApplicationInfo> slice = mPM.getInstalledApplications(flags, userId);
477 return slice.getList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800478 } catch (RemoteException e) {
479 throw new RuntimeException("Package manager has died", e);
480 }
481 }
482
483 @Override
484 public ResolveInfo resolveActivity(Intent intent, int flags) {
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700485 return resolveActivityAsUser(intent, flags, mContext.getUserId());
Svetoslav Ganov58d37b52012-09-18 12:04:19 -0700486 }
487
488 @Override
489 public ResolveInfo resolveActivityAsUser(Intent intent, int flags, int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800490 try {
491 return mPM.resolveIntent(
492 intent,
493 intent.resolveTypeIfNeeded(mContext.getContentResolver()),
Svetoslav Ganov58d37b52012-09-18 12:04:19 -0700494 flags,
495 userId);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800496 } catch (RemoteException e) {
497 throw new RuntimeException("Package manager has died", e);
498 }
499 }
500
501 @Override
502 public List<ResolveInfo> queryIntentActivities(Intent intent,
503 int flags) {
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700504 return queryIntentActivitiesAsUser(intent, flags, mContext.getUserId());
Amith Yamasani151ec4c2012-09-07 19:25:16 -0700505 }
506
507 /** @hide Same as above but for a specific user */
508 @Override
Svetoslav Ganov58d37b52012-09-18 12:04:19 -0700509 public List<ResolveInfo> queryIntentActivitiesAsUser(Intent intent,
Amith Yamasani151ec4c2012-09-07 19:25:16 -0700510 int flags, int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800511 try {
512 return mPM.queryIntentActivities(
513 intent,
514 intent.resolveTypeIfNeeded(mContext.getContentResolver()),
Amith Yamasani483f3b02012-03-13 16:08:00 -0700515 flags,
Amith Yamasani151ec4c2012-09-07 19:25:16 -0700516 userId);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800517 } catch (RemoteException e) {
518 throw new RuntimeException("Package manager has died", e);
519 }
520 }
521
522 @Override
523 public List<ResolveInfo> queryIntentActivityOptions(
524 ComponentName caller, Intent[] specifics, Intent intent,
525 int flags) {
526 final ContentResolver resolver = mContext.getContentResolver();
527
528 String[] specificTypes = null;
529 if (specifics != null) {
530 final int N = specifics.length;
531 for (int i=0; i<N; i++) {
532 Intent sp = specifics[i];
533 if (sp != null) {
534 String t = sp.resolveTypeIfNeeded(resolver);
535 if (t != null) {
536 if (specificTypes == null) {
537 specificTypes = new String[N];
538 }
539 specificTypes[i] = t;
540 }
541 }
542 }
543 }
544
545 try {
546 return mPM.queryIntentActivityOptions(caller, specifics,
547 specificTypes, intent, intent.resolveTypeIfNeeded(resolver),
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700548 flags, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800549 } catch (RemoteException e) {
550 throw new RuntimeException("Package manager has died", e);
551 }
552 }
553
Amith Yamasanif203aee2012-08-29 18:41:53 -0700554 /**
555 * @hide
556 */
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800557 @Override
Amith Yamasanif203aee2012-08-29 18:41:53 -0700558 public List<ResolveInfo> queryBroadcastReceivers(Intent intent, int flags, int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800559 try {
560 return mPM.queryIntentReceivers(
561 intent,
562 intent.resolveTypeIfNeeded(mContext.getContentResolver()),
Amith Yamasani483f3b02012-03-13 16:08:00 -0700563 flags,
Amith Yamasanif203aee2012-08-29 18:41:53 -0700564 userId);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800565 } catch (RemoteException e) {
566 throw new RuntimeException("Package manager has died", e);
567 }
568 }
569
570 @Override
Amith Yamasanif203aee2012-08-29 18:41:53 -0700571 public List<ResolveInfo> queryBroadcastReceivers(Intent intent, int flags) {
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700572 return queryBroadcastReceivers(intent, flags, mContext.getUserId());
Amith Yamasanif203aee2012-08-29 18:41:53 -0700573 }
574
575 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800576 public ResolveInfo resolveService(Intent intent, int flags) {
577 try {
578 return mPM.resolveService(
579 intent,
580 intent.resolveTypeIfNeeded(mContext.getContentResolver()),
Amith Yamasani483f3b02012-03-13 16:08:00 -0700581 flags,
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700582 mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800583 } catch (RemoteException e) {
584 throw new RuntimeException("Package manager has died", e);
585 }
586 }
587
588 @Override
Svetoslav Ganov58d37b52012-09-18 12:04:19 -0700589 public List<ResolveInfo> queryIntentServicesAsUser(Intent intent, int flags, int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800590 try {
591 return mPM.queryIntentServices(
592 intent,
593 intent.resolveTypeIfNeeded(mContext.getContentResolver()),
Amith Yamasani483f3b02012-03-13 16:08:00 -0700594 flags,
Svetoslav Ganov58d37b52012-09-18 12:04:19 -0700595 userId);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800596 } catch (RemoteException e) {
597 throw new RuntimeException("Package manager has died", e);
598 }
599 }
600
601 @Override
Svetoslav Ganov58d37b52012-09-18 12:04:19 -0700602 public List<ResolveInfo> queryIntentServices(Intent intent, int flags) {
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700603 return queryIntentServicesAsUser(intent, flags, mContext.getUserId());
Svetoslav Ganov58d37b52012-09-18 12:04:19 -0700604 }
605
606 @Override
Jeff Sharkey85f5f812013-10-07 10:16:12 -0700607 public List<ResolveInfo> queryIntentContentProvidersAsUser(
608 Intent intent, int flags, int userId) {
609 try {
610 return mPM.queryIntentContentProviders(intent,
611 intent.resolveTypeIfNeeded(mContext.getContentResolver()), flags, userId);
612 } catch (RemoteException e) {
613 throw new RuntimeException("Package manager has died", e);
614 }
615 }
616
617 @Override
618 public List<ResolveInfo> queryIntentContentProviders(Intent intent, int flags) {
619 return queryIntentContentProvidersAsUser(intent, flags, mContext.getUserId());
620 }
621
622 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800623 public ProviderInfo resolveContentProvider(String name,
624 int flags) {
625 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700626 return mPM.resolveContentProvider(name, flags, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800627 } catch (RemoteException e) {
628 throw new RuntimeException("Package manager has died", e);
629 }
630 }
631
632 @Override
633 public List<ProviderInfo> queryContentProviders(String processName,
634 int uid, int flags) {
635 try {
636 return mPM.queryContentProviders(processName, uid, flags);
637 } catch (RemoteException e) {
638 throw new RuntimeException("Package manager has died", e);
639 }
640 }
641
642 @Override
643 public InstrumentationInfo getInstrumentationInfo(
644 ComponentName className, int flags)
645 throws NameNotFoundException {
646 try {
647 InstrumentationInfo ii = mPM.getInstrumentationInfo(
648 className, flags);
649 if (ii != null) {
650 return ii;
651 }
652 } catch (RemoteException e) {
653 throw new RuntimeException("Package manager has died", e);
654 }
655
656 throw new NameNotFoundException(className.toString());
657 }
658
659 @Override
660 public List<InstrumentationInfo> queryInstrumentation(
661 String targetPackage, int flags) {
662 try {
663 return mPM.queryInstrumentation(targetPackage, flags);
664 } catch (RemoteException e) {
665 throw new RuntimeException("Package manager has died", e);
666 }
667 }
668
669 @Override public Drawable getDrawable(String packageName, int resid,
670 ApplicationInfo appInfo) {
671 ResourceName name = new ResourceName(packageName, resid);
672 Drawable dr = getCachedIcon(name);
673 if (dr != null) {
674 return dr;
675 }
676 if (appInfo == null) {
677 try {
678 appInfo = getApplicationInfo(packageName, 0);
679 } catch (NameNotFoundException e) {
680 return null;
681 }
682 }
683 try {
684 Resources r = getResourcesForApplication(appInfo);
685 dr = r.getDrawable(resid);
686 if (false) {
687 RuntimeException e = new RuntimeException("here");
688 e.fillInStackTrace();
689 Log.w(TAG, "Getting drawable 0x" + Integer.toHexString(resid)
690 + " from package " + packageName
691 + ": app scale=" + r.getCompatibilityInfo().applicationScale
692 + ", caller scale=" + mContext.getResources().getCompatibilityInfo().applicationScale,
693 e);
694 }
695 if (DEBUG_ICONS) Log.v(TAG, "Getting drawable 0x"
696 + Integer.toHexString(resid) + " from " + r
697 + ": " + dr);
698 putCachedIcon(name, dr);
699 return dr;
700 } catch (NameNotFoundException e) {
701 Log.w("PackageManager", "Failure retrieving resources for"
702 + appInfo.packageName);
Joe Onorato08f16542011-01-20 11:49:56 -0800703 } catch (Resources.NotFoundException e) {
704 Log.w("PackageManager", "Failure retrieving resources for"
705 + appInfo.packageName + ": " + e.getMessage());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800706 } catch (RuntimeException e) {
707 // If an exception was thrown, fall through to return
708 // default icon.
709 Log.w("PackageManager", "Failure retrieving icon 0x"
710 + Integer.toHexString(resid) + " in package "
711 + packageName, e);
712 }
713 return null;
714 }
715
716 @Override public Drawable getActivityIcon(ComponentName activityName)
717 throws NameNotFoundException {
718 return getActivityInfo(activityName, 0).loadIcon(this);
719 }
720
721 @Override public Drawable getActivityIcon(Intent intent)
722 throws NameNotFoundException {
723 if (intent.getComponent() != null) {
724 return getActivityIcon(intent.getComponent());
725 }
726
727 ResolveInfo info = resolveActivity(
728 intent, PackageManager.MATCH_DEFAULT_ONLY);
729 if (info != null) {
730 return info.activityInfo.loadIcon(this);
731 }
732
Romain Guy39fe17c2011-11-30 10:34:07 -0800733 throw new NameNotFoundException(intent.toUri(0));
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800734 }
735
736 @Override public Drawable getDefaultActivityIcon() {
737 return Resources.getSystem().getDrawable(
738 com.android.internal.R.drawable.sym_def_app_icon);
739 }
740
741 @Override public Drawable getApplicationIcon(ApplicationInfo info) {
742 return info.loadIcon(this);
743 }
744
745 @Override public Drawable getApplicationIcon(String packageName)
746 throws NameNotFoundException {
747 return getApplicationIcon(getApplicationInfo(packageName, 0));
748 }
749
750 @Override
Jose Limaf78e3122014-03-06 12:13:15 -0800751 public Drawable getActivityBanner(ComponentName activityName)
752 throws NameNotFoundException {
753 return getActivityInfo(activityName, 0).loadBanner(this);
754 }
755
756 @Override
757 public Drawable getActivityBanner(Intent intent)
758 throws NameNotFoundException {
759 if (intent.getComponent() != null) {
760 return getActivityBanner(intent.getComponent());
761 }
762
763 ResolveInfo info = resolveActivity(
764 intent, PackageManager.MATCH_DEFAULT_ONLY);
765 if (info != null) {
766 return info.activityInfo.loadBanner(this);
767 }
768
769 throw new NameNotFoundException(intent.toUri(0));
770 }
771
772 @Override
773 public Drawable getApplicationBanner(ApplicationInfo info) {
774 return info.loadBanner(this);
775 }
776
777 @Override
778 public Drawable getApplicationBanner(String packageName)
779 throws NameNotFoundException {
780 return getApplicationBanner(getApplicationInfo(packageName, 0));
781 }
782
783 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800784 public Drawable getActivityLogo(ComponentName activityName)
785 throws NameNotFoundException {
786 return getActivityInfo(activityName, 0).loadLogo(this);
787 }
788
789 @Override
790 public Drawable getActivityLogo(Intent intent)
791 throws NameNotFoundException {
792 if (intent.getComponent() != null) {
793 return getActivityLogo(intent.getComponent());
794 }
795
796 ResolveInfo info = resolveActivity(
797 intent, PackageManager.MATCH_DEFAULT_ONLY);
798 if (info != null) {
799 return info.activityInfo.loadLogo(this);
800 }
801
802 throw new NameNotFoundException(intent.toUri(0));
803 }
804
805 @Override
806 public Drawable getApplicationLogo(ApplicationInfo info) {
807 return info.loadLogo(this);
808 }
809
810 @Override
811 public Drawable getApplicationLogo(String packageName)
812 throws NameNotFoundException {
813 return getApplicationLogo(getApplicationInfo(packageName, 0));
814 }
815
816 @Override public Resources getResourcesForActivity(
817 ComponentName activityName) throws NameNotFoundException {
818 return getResourcesForApplication(
819 getActivityInfo(activityName, 0).applicationInfo);
820 }
821
822 @Override public Resources getResourcesForApplication(
823 ApplicationInfo app) throws NameNotFoundException {
824 if (app.packageName.equals("system")) {
825 return mContext.mMainThread.getSystemContext().getResources();
826 }
827 Resources r = mContext.mMainThread.getTopLevelResources(
Jeff Browna492c3a2012-08-23 19:48:44 -0700828 app.uid == Process.myUid() ? app.sourceDir : app.publicSourceDir,
829 Display.DEFAULT_DISPLAY, null, mContext.mPackageInfo);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800830 if (r != null) {
831 return r;
832 }
833 throw new NameNotFoundException("Unable to open " + app.publicSourceDir);
834 }
835
836 @Override public Resources getResourcesForApplication(
837 String appPackageName) throws NameNotFoundException {
838 return getResourcesForApplication(
839 getApplicationInfo(appPackageName, 0));
840 }
841
Amith Yamasani98edc952012-09-25 14:09:27 -0700842 /** @hide */
843 @Override
844 public Resources getResourcesForApplicationAsUser(String appPackageName, int userId)
845 throws NameNotFoundException {
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700846 if (userId < 0) {
847 throw new IllegalArgumentException(
848 "Call does not support special user #" + userId);
849 }
850 if ("system".equals(appPackageName)) {
851 return mContext.mMainThread.getSystemContext().getResources();
852 }
Amith Yamasani98edc952012-09-25 14:09:27 -0700853 try {
854 ApplicationInfo ai = mPM.getApplicationInfo(appPackageName, 0, userId);
855 if (ai != null) {
856 return getResourcesForApplication(ai);
857 }
858 } catch (RemoteException e) {
859 throw new RuntimeException("Package manager has died", e);
860 }
861 throw new NameNotFoundException("Package " + appPackageName + " doesn't exist");
862 }
863
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800864 int mCachedSafeMode = -1;
865 @Override public boolean isSafeMode() {
866 try {
867 if (mCachedSafeMode < 0) {
868 mCachedSafeMode = mPM.isSafeMode() ? 1 : 0;
869 }
870 return mCachedSafeMode != 0;
871 } catch (RemoteException e) {
872 throw new RuntimeException("Package manager has died", e);
873 }
874 }
875
876 static void configurationChanged() {
877 synchronized (sSync) {
878 sIconCache.clear();
879 sStringCache.clear();
880 }
881 }
882
883 ApplicationPackageManager(ContextImpl context,
884 IPackageManager pm) {
885 mContext = context;
886 mPM = pm;
887 }
888
889 private Drawable getCachedIcon(ResourceName name) {
890 synchronized (sSync) {
Romain Guy39fe17c2011-11-30 10:34:07 -0800891 WeakReference<Drawable.ConstantState> wr = sIconCache.get(name);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800892 if (DEBUG_ICONS) Log.v(TAG, "Get cached weak drawable ref for "
893 + name + ": " + wr);
894 if (wr != null) { // we have the activity
Romain Guy39fe17c2011-11-30 10:34:07 -0800895 Drawable.ConstantState state = wr.get();
896 if (state != null) {
897 if (DEBUG_ICONS) {
898 Log.v(TAG, "Get cached drawable state for " + name + ": " + state);
899 }
900 // Note: It's okay here to not use the newDrawable(Resources) variant
901 // of the API. The ConstantState comes from a drawable that was
902 // originally created by passing the proper app Resources instance
903 // which means the state should already contain the proper
904 // resources specific information (like density.) See
905 // BitmapDrawable.BitmapState for instance.
906 return state.newDrawable();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800907 }
908 // our entry has been purged
909 sIconCache.remove(name);
910 }
911 }
912 return null;
913 }
914
915 private void putCachedIcon(ResourceName name, Drawable dr) {
916 synchronized (sSync) {
Romain Guy39fe17c2011-11-30 10:34:07 -0800917 sIconCache.put(name, new WeakReference<Drawable.ConstantState>(dr.getConstantState()));
918 if (DEBUG_ICONS) Log.v(TAG, "Added cached drawable state for " + name + ": " + dr);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800919 }
920 }
921
Romain Guy39fe17c2011-11-30 10:34:07 -0800922 static void handlePackageBroadcast(int cmd, String[] pkgList, boolean hasPkgInfo) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800923 boolean immediateGc = false;
924 if (cmd == IApplicationThread.EXTERNAL_STORAGE_UNAVAILABLE) {
925 immediateGc = true;
926 }
927 if (pkgList != null && (pkgList.length > 0)) {
928 boolean needCleanup = false;
929 for (String ssp : pkgList) {
930 synchronized (sSync) {
Dianne Hackbornadd005c2013-07-17 18:43:12 -0700931 for (int i=sIconCache.size()-1; i>=0; i--) {
932 ResourceName nm = sIconCache.keyAt(i);
933 if (nm.packageName.equals(ssp)) {
934 //Log.i(TAG, "Removing cached drawable for " + nm);
935 sIconCache.removeAt(i);
936 needCleanup = true;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800937 }
938 }
Dianne Hackbornadd005c2013-07-17 18:43:12 -0700939 for (int i=sStringCache.size()-1; i>=0; i--) {
940 ResourceName nm = sStringCache.keyAt(i);
941 if (nm.packageName.equals(ssp)) {
942 //Log.i(TAG, "Removing cached string for " + nm);
943 sStringCache.removeAt(i);
944 needCleanup = true;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800945 }
946 }
947 }
948 }
949 if (needCleanup || hasPkgInfo) {
950 if (immediateGc) {
951 // Schedule an immediate gc.
952 Runtime.getRuntime().gc();
953 } else {
954 ActivityThread.currentActivityThread().scheduleGcIdler();
955 }
956 }
957 }
958 }
959
960 private static final class ResourceName {
961 final String packageName;
962 final int iconId;
963
964 ResourceName(String _packageName, int _iconId) {
965 packageName = _packageName;
966 iconId = _iconId;
967 }
968
969 ResourceName(ApplicationInfo aInfo, int _iconId) {
970 this(aInfo.packageName, _iconId);
971 }
972
973 ResourceName(ComponentInfo cInfo, int _iconId) {
974 this(cInfo.applicationInfo.packageName, _iconId);
975 }
976
977 ResourceName(ResolveInfo rInfo, int _iconId) {
978 this(rInfo.activityInfo.applicationInfo.packageName, _iconId);
979 }
980
981 @Override
982 public boolean equals(Object o) {
983 if (this == o) return true;
984 if (o == null || getClass() != o.getClass()) return false;
985
986 ResourceName that = (ResourceName) o;
987
988 if (iconId != that.iconId) return false;
989 return !(packageName != null ?
990 !packageName.equals(that.packageName) : that.packageName != null);
991
992 }
993
994 @Override
995 public int hashCode() {
996 int result;
997 result = packageName.hashCode();
998 result = 31 * result + iconId;
999 return result;
1000 }
1001
1002 @Override
1003 public String toString() {
1004 return "{ResourceName " + packageName + " / " + iconId + "}";
1005 }
1006 }
1007
1008 private CharSequence getCachedString(ResourceName name) {
1009 synchronized (sSync) {
1010 WeakReference<CharSequence> wr = sStringCache.get(name);
1011 if (wr != null) { // we have the activity
1012 CharSequence cs = wr.get();
1013 if (cs != null) {
1014 return cs;
1015 }
1016 // our entry has been purged
1017 sStringCache.remove(name);
1018 }
1019 }
1020 return null;
1021 }
1022
1023 private void putCachedString(ResourceName name, CharSequence cs) {
1024 synchronized (sSync) {
1025 sStringCache.put(name, new WeakReference<CharSequence>(cs));
1026 }
1027 }
1028
1029 @Override
1030 public CharSequence getText(String packageName, int resid,
1031 ApplicationInfo appInfo) {
1032 ResourceName name = new ResourceName(packageName, resid);
1033 CharSequence text = getCachedString(name);
1034 if (text != null) {
1035 return text;
1036 }
1037 if (appInfo == null) {
1038 try {
1039 appInfo = getApplicationInfo(packageName, 0);
1040 } catch (NameNotFoundException e) {
1041 return null;
1042 }
1043 }
1044 try {
1045 Resources r = getResourcesForApplication(appInfo);
1046 text = r.getText(resid);
1047 putCachedString(name, text);
1048 return text;
1049 } catch (NameNotFoundException e) {
1050 Log.w("PackageManager", "Failure retrieving resources for"
1051 + appInfo.packageName);
1052 } catch (RuntimeException e) {
1053 // If an exception was thrown, fall through to return
1054 // default icon.
1055 Log.w("PackageManager", "Failure retrieving text 0x"
1056 + Integer.toHexString(resid) + " in package "
1057 + packageName, e);
1058 }
1059 return null;
1060 }
1061
1062 @Override
1063 public XmlResourceParser getXml(String packageName, int resid,
1064 ApplicationInfo appInfo) {
1065 if (appInfo == null) {
1066 try {
1067 appInfo = getApplicationInfo(packageName, 0);
1068 } catch (NameNotFoundException e) {
1069 return null;
1070 }
1071 }
1072 try {
1073 Resources r = getResourcesForApplication(appInfo);
1074 return r.getXml(resid);
1075 } catch (RuntimeException e) {
1076 // If an exception was thrown, fall through to return
1077 // default icon.
1078 Log.w("PackageManager", "Failure retrieving xml 0x"
1079 + Integer.toHexString(resid) + " in package "
1080 + packageName, e);
1081 } catch (NameNotFoundException e) {
Alon Albert3fa51e32010-11-11 09:24:04 -08001082 Log.w("PackageManager", "Failure retrieving resources for "
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001083 + appInfo.packageName);
1084 }
1085 return null;
1086 }
1087
1088 @Override
1089 public CharSequence getApplicationLabel(ApplicationInfo info) {
1090 return info.loadLabel(this);
1091 }
1092
1093 @Override
1094 public void installPackage(Uri packageURI, IPackageInstallObserver observer, int flags,
1095 String installerPackageName) {
1096 try {
1097 mPM.installPackage(packageURI, observer, flags, installerPackageName);
1098 } catch (RemoteException e) {
1099 // Should never happen!
1100 }
1101 }
1102
1103 @Override
Kenny Root5ab21572011-07-27 11:11:19 -07001104 public void installPackageWithVerification(Uri packageURI, IPackageInstallObserver observer,
1105 int flags, String installerPackageName, Uri verificationURI,
Rich Canningse1d7c712012-08-08 12:46:06 -07001106 ManifestDigest manifestDigest, ContainerEncryptionParams encryptionParams) {
Kenny Root5ab21572011-07-27 11:11:19 -07001107 try {
1108 mPM.installPackageWithVerification(packageURI, observer, flags, installerPackageName,
Rich Canningse1d7c712012-08-08 12:46:06 -07001109 verificationURI, manifestDigest, encryptionParams);
Kenny Root5ab21572011-07-27 11:11:19 -07001110 } catch (RemoteException e) {
1111 // Should never happen!
1112 }
1113 }
1114
1115 @Override
rich cannings706e8ba2012-08-20 13:20:14 -07001116 public void installPackageWithVerificationAndEncryption(Uri packageURI,
1117 IPackageInstallObserver observer, int flags, String installerPackageName,
1118 VerificationParams verificationParams, ContainerEncryptionParams encryptionParams) {
1119 try {
1120 mPM.installPackageWithVerificationAndEncryption(packageURI, observer, flags,
1121 installerPackageName, verificationParams, encryptionParams);
1122 } catch (RemoteException e) {
1123 // Should never happen!
1124 }
1125 }
1126
1127 @Override
Dianne Hackborn7767eac2012-08-23 18:25:40 -07001128 public int installExistingPackage(String packageName)
1129 throws NameNotFoundException {
1130 try {
Amith Yamasani67df64b2012-12-14 12:09:36 -08001131 int res = mPM.installExistingPackageAsUser(packageName, UserHandle.myUserId());
Dianne Hackborn7767eac2012-08-23 18:25:40 -07001132 if (res == INSTALL_FAILED_INVALID_URI) {
1133 throw new NameNotFoundException("Package " + packageName + " doesn't exist");
1134 }
1135 return res;
1136 } catch (RemoteException e) {
1137 // Should never happen!
1138 throw new NameNotFoundException("Package " + packageName + " doesn't exist");
1139 }
1140 }
1141
1142 @Override
Kenny Root3a9b5fb2011-09-20 14:15:38 -07001143 public void verifyPendingInstall(int id, int response) {
Kenny Root5ab21572011-07-27 11:11:19 -07001144 try {
Kenny Root3a9b5fb2011-09-20 14:15:38 -07001145 mPM.verifyPendingInstall(id, response);
Kenny Root5ab21572011-07-27 11:11:19 -07001146 } catch (RemoteException e) {
1147 // Should never happen!
1148 }
1149 }
1150
1151 @Override
rich canningsd9ef3e52012-08-22 14:28:05 -07001152 public void extendVerificationTimeout(int id, int verificationCodeAtTimeout,
1153 long millisecondsToDelay) {
1154 try {
1155 mPM.extendVerificationTimeout(id, verificationCodeAtTimeout, millisecondsToDelay);
1156 } catch (RemoteException e) {
1157 // Should never happen!
1158 }
1159 }
1160
1161 @Override
Dianne Hackborn880119b2010-11-18 22:26:40 -08001162 public void setInstallerPackageName(String targetPackage,
1163 String installerPackageName) {
1164 try {
1165 mPM.setInstallerPackageName(targetPackage, installerPackageName);
1166 } catch (RemoteException e) {
1167 // Should never happen!
1168 }
1169 }
1170
1171 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001172 public void movePackage(String packageName, IPackageMoveObserver observer, int flags) {
1173 try {
1174 mPM.movePackage(packageName, observer, flags);
1175 } catch (RemoteException e) {
1176 // Should never happen!
1177 }
1178 }
1179
1180 @Override
1181 public String getInstallerPackageName(String packageName) {
1182 try {
1183 return mPM.getInstallerPackageName(packageName);
1184 } catch (RemoteException e) {
1185 // Should never happen!
1186 }
1187 return null;
1188 }
1189
1190 @Override
1191 public void deletePackage(String packageName, IPackageDeleteObserver observer, int flags) {
1192 try {
Amith Yamasani67df64b2012-12-14 12:09:36 -08001193 mPM.deletePackageAsUser(packageName, observer, UserHandle.myUserId(), flags);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001194 } catch (RemoteException e) {
1195 // Should never happen!
1196 }
1197 }
1198 @Override
1199 public void clearApplicationUserData(String packageName,
1200 IPackageDataObserver observer) {
1201 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -07001202 mPM.clearApplicationUserData(packageName, observer, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001203 } catch (RemoteException e) {
1204 // Should never happen!
1205 }
1206 }
1207 @Override
1208 public void deleteApplicationCacheFiles(String packageName,
1209 IPackageDataObserver observer) {
1210 try {
1211 mPM.deleteApplicationCacheFiles(packageName, observer);
1212 } catch (RemoteException e) {
1213 // Should never happen!
1214 }
1215 }
1216 @Override
1217 public void freeStorageAndNotify(long idealStorageSize, IPackageDataObserver observer) {
1218 try {
1219 mPM.freeStorageAndNotify(idealStorageSize, observer);
1220 } catch (RemoteException e) {
1221 // Should never happen!
1222 }
1223 }
1224
1225 @Override
1226 public void freeStorage(long freeStorageSize, IntentSender pi) {
1227 try {
1228 mPM.freeStorage(freeStorageSize, pi);
1229 } catch (RemoteException e) {
1230 // Should never happen!
1231 }
1232 }
1233
1234 @Override
Dianne Hackborn0c380492012-08-20 17:23:30 -07001235 public void getPackageSizeInfo(String packageName, int userHandle,
1236 IPackageStatsObserver observer) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001237 try {
Dianne Hackborn0c380492012-08-20 17:23:30 -07001238 mPM.getPackageSizeInfo(packageName, userHandle, observer);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001239 } catch (RemoteException e) {
1240 // Should never happen!
1241 }
1242 }
1243 @Override
1244 public void addPackageToPreferred(String packageName) {
1245 try {
1246 mPM.addPackageToPreferred(packageName);
1247 } catch (RemoteException e) {
1248 // Should never happen!
1249 }
1250 }
1251
1252 @Override
1253 public void removePackageFromPreferred(String packageName) {
1254 try {
1255 mPM.removePackageFromPreferred(packageName);
1256 } catch (RemoteException e) {
1257 // Should never happen!
1258 }
1259 }
1260
1261 @Override
1262 public List<PackageInfo> getPreferredPackages(int flags) {
1263 try {
1264 return mPM.getPreferredPackages(flags);
1265 } catch (RemoteException e) {
1266 // Should never happen!
1267 }
1268 return new ArrayList<PackageInfo>();
1269 }
1270
1271 @Override
1272 public void addPreferredActivity(IntentFilter filter,
1273 int match, ComponentName[] set, ComponentName activity) {
1274 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -07001275 mPM.addPreferredActivity(filter, match, set, activity, mContext.getUserId());
Amith Yamasania3f133a2012-08-09 17:11:28 -07001276 } catch (RemoteException e) {
1277 // Should never happen!
1278 }
1279 }
1280
1281 @Override
1282 public void addPreferredActivity(IntentFilter filter, int match,
1283 ComponentName[] set, ComponentName activity, int userId) {
1284 try {
1285 mPM.addPreferredActivity(filter, match, set, activity, userId);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001286 } catch (RemoteException e) {
1287 // Should never happen!
1288 }
1289 }
1290
1291 @Override
1292 public void replacePreferredActivity(IntentFilter filter,
1293 int match, ComponentName[] set, ComponentName activity) {
1294 try {
1295 mPM.replacePreferredActivity(filter, match, set, activity);
1296 } catch (RemoteException e) {
1297 // Should never happen!
1298 }
1299 }
1300
1301 @Override
1302 public void clearPackagePreferredActivities(String packageName) {
1303 try {
1304 mPM.clearPackagePreferredActivities(packageName);
1305 } catch (RemoteException e) {
1306 // Should never happen!
1307 }
1308 }
1309
1310 @Override
1311 public int getPreferredActivities(List<IntentFilter> outFilters,
1312 List<ComponentName> outActivities, String packageName) {
1313 try {
1314 return mPM.getPreferredActivities(outFilters, outActivities, packageName);
1315 } catch (RemoteException e) {
1316 // Should never happen!
1317 }
1318 return 0;
1319 }
1320
1321 @Override
Christopher Tatea2a08502013-09-05 16:38:58 -07001322 public ComponentName getHomeActivities(List<ResolveInfo> outActivities) {
1323 try {
1324 return mPM.getHomeActivities(outActivities);
1325 } catch (RemoteException e) {
1326 // Should never happen!
1327 }
1328 return null;
1329 }
1330
1331 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001332 public void setComponentEnabledSetting(ComponentName componentName,
1333 int newState, int flags) {
1334 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -07001335 mPM.setComponentEnabledSetting(componentName, newState, flags, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001336 } catch (RemoteException e) {
1337 // Should never happen!
1338 }
1339 }
1340
1341 @Override
1342 public int getComponentEnabledSetting(ComponentName componentName) {
1343 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -07001344 return mPM.getComponentEnabledSetting(componentName, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001345 } catch (RemoteException e) {
1346 // Should never happen!
1347 }
1348 return PackageManager.COMPONENT_ENABLED_STATE_DEFAULT;
1349 }
1350
1351 @Override
1352 public void setApplicationEnabledSetting(String packageName,
1353 int newState, int flags) {
1354 try {
Dianne Hackborn3fa3c28a2013-03-26 16:15:41 -07001355 mPM.setApplicationEnabledSetting(packageName, newState, flags,
Dianne Hackborn95d78532013-09-11 09:51:14 -07001356 mContext.getUserId(), mContext.getOpPackageName());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001357 } catch (RemoteException e) {
1358 // Should never happen!
1359 }
1360 }
1361
1362 @Override
1363 public int getApplicationEnabledSetting(String packageName) {
1364 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -07001365 return mPM.getApplicationEnabledSetting(packageName, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001366 } catch (RemoteException e) {
1367 // Should never happen!
1368 }
1369 return PackageManager.COMPONENT_ENABLED_STATE_DEFAULT;
1370 }
1371
Amith Yamasani655d0e22013-06-12 14:19:10 -07001372 @Override
1373 public boolean setApplicationBlockedSettingAsUser(String packageName, boolean blocked,
1374 UserHandle user) {
1375 try {
1376 return mPM.setApplicationBlockedSettingAsUser(packageName, blocked,
1377 user.getIdentifier());
1378 } catch (RemoteException re) {
1379 // Should never happen!
1380 }
1381 return false;
1382 }
1383
1384 @Override
1385 public boolean getApplicationBlockedSettingAsUser(String packageName, UserHandle user) {
1386 try {
1387 return mPM.getApplicationBlockedSettingAsUser(packageName, user.getIdentifier());
1388 } catch (RemoteException re) {
1389 // Should never happen!
1390 }
1391 return false;
1392 }
1393
Kenny Root0aaa0d92011-09-12 16:42:55 -07001394 /**
1395 * @hide
1396 */
1397 @Override
1398 public VerifierDeviceIdentity getVerifierDeviceIdentity() {
1399 try {
1400 return mPM.getVerifierDeviceIdentity();
1401 } catch (RemoteException e) {
1402 // Should never happen!
1403 }
1404 return null;
1405 }
1406
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001407 private final ContextImpl mContext;
1408 private final IPackageManager mPM;
1409
1410 private static final Object sSync = new Object();
Dianne Hackbornadd005c2013-07-17 18:43:12 -07001411 private static ArrayMap<ResourceName, WeakReference<Drawable.ConstantState>> sIconCache
1412 = new ArrayMap<ResourceName, WeakReference<Drawable.ConstantState>>();
1413 private static ArrayMap<ResourceName, WeakReference<CharSequence>> sStringCache
1414 = new ArrayMap<ResourceName, WeakReference<CharSequence>>();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001415}