blob: cb48e5885207f8c6c01de36dae34e40e2233385f [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;
Christopher Tatef1977b42014-03-24 16:25:51 -070032import android.content.pm.IPackageInstallObserver2;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080033import android.content.pm.IPackageManager;
34import android.content.pm.IPackageMoveObserver;
35import android.content.pm.IPackageStatsObserver;
36import android.content.pm.InstrumentationInfo;
37import android.content.pm.PackageInfo;
Jeff Sharkey3a44f3f2014-04-28 17:36:31 -070038import android.content.pm.PackageInstaller;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080039import android.content.pm.PackageManager;
Kenny Roote6cd0c72011-05-19 12:48:14 -070040import android.content.pm.ParceledListSlice;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080041import android.content.pm.PermissionGroupInfo;
42import android.content.pm.PermissionInfo;
43import android.content.pm.ProviderInfo;
44import android.content.pm.ResolveInfo;
45import android.content.pm.ServiceInfo;
Kenny Root5ab21572011-07-27 11:11:19 -070046import android.content.pm.ManifestDigest;
rich cannings706e8ba2012-08-20 13:20:14 -070047import android.content.pm.VerificationParams;
Kenny Root0aaa0d92011-09-12 16:42:55 -070048import android.content.pm.VerifierDeviceIdentity;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080049import android.content.res.Resources;
50import android.content.res.XmlResourceParser;
Nicolas Prevot88cc3462014-05-14 14:51:48 +010051import android.graphics.Bitmap;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080052import android.graphics.drawable.Drawable;
53import android.net.Uri;
54import android.os.Process;
55import android.os.RemoteException;
Amith Yamasani67df64b2012-12-14 12:09:36 -080056import android.os.UserHandle;
Nicolas Prevot88cc3462014-05-14 14:51:48 +010057import android.os.UserManager;
Dianne Hackbornadd005c2013-07-17 18:43:12 -070058import android.util.ArrayMap;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080059import android.util.Log;
Jeff Browna492c3a2012-08-23 19:48:44 -070060import android.view.Display;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080061
62import java.lang.ref.WeakReference;
63import java.util.ArrayList;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080064import java.util.List;
65
66/*package*/
67final class ApplicationPackageManager extends PackageManager {
68 private static final String TAG = "ApplicationPackageManager";
69 private final static boolean DEBUG = false;
70 private final static boolean DEBUG_ICONS = false;
71
72 @Override
73 public PackageInfo getPackageInfo(String packageName, int flags)
74 throws NameNotFoundException {
75 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -070076 PackageInfo pi = mPM.getPackageInfo(packageName, flags, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080077 if (pi != null) {
78 return pi;
79 }
80 } catch (RemoteException e) {
81 throw new RuntimeException("Package manager has died", e);
82 }
83
84 throw new NameNotFoundException(packageName);
85 }
86
87 @Override
88 public String[] currentToCanonicalPackageNames(String[] names) {
89 try {
90 return mPM.currentToCanonicalPackageNames(names);
91 } catch (RemoteException e) {
92 throw new RuntimeException("Package manager has died", e);
93 }
94 }
95
96 @Override
97 public String[] canonicalToCurrentPackageNames(String[] names) {
98 try {
99 return mPM.canonicalToCurrentPackageNames(names);
100 } catch (RemoteException e) {
101 throw new RuntimeException("Package manager has died", e);
102 }
103 }
104
105 @Override
106 public Intent getLaunchIntentForPackage(String packageName) {
107 // First see if the package has an INFO activity; the existence of
108 // such an activity is implied to be the desired front-door for the
109 // overall package (such as if it has multiple launcher entries).
110 Intent intentToResolve = new Intent(Intent.ACTION_MAIN);
111 intentToResolve.addCategory(Intent.CATEGORY_INFO);
112 intentToResolve.setPackage(packageName);
Dianne Hackborn19415762010-12-15 00:20:27 -0800113 List<ResolveInfo> ris = queryIntentActivities(intentToResolve, 0);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800114
115 // Otherwise, try to find a main launcher activity.
Dianne Hackborn19415762010-12-15 00:20:27 -0800116 if (ris == null || ris.size() <= 0) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800117 // reuse the intent instance
118 intentToResolve.removeCategory(Intent.CATEGORY_INFO);
119 intentToResolve.addCategory(Intent.CATEGORY_LAUNCHER);
120 intentToResolve.setPackage(packageName);
Dianne Hackborn19415762010-12-15 00:20:27 -0800121 ris = queryIntentActivities(intentToResolve, 0);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800122 }
Dianne Hackborn19415762010-12-15 00:20:27 -0800123 if (ris == null || ris.size() <= 0) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800124 return null;
125 }
126 Intent intent = new Intent(intentToResolve);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800127 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Dianne Hackborn19415762010-12-15 00:20:27 -0800128 intent.setClassName(ris.get(0).activityInfo.packageName,
129 ris.get(0).activityInfo.name);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800130 return intent;
131 }
132
133 @Override
Jose Lima970417c2014-04-10 10:42:19 -0700134 public Intent getLeanbackLaunchIntentForPackage(String packageName) {
135 // Try to find a main leanback_launcher activity.
136 Intent intentToResolve = new Intent(Intent.ACTION_MAIN);
137 intentToResolve.addCategory(Intent.CATEGORY_LEANBACK_LAUNCHER);
138 intentToResolve.setPackage(packageName);
139 List<ResolveInfo> ris = queryIntentActivities(intentToResolve, 0);
140
141 if (ris == null || ris.size() <= 0) {
142 return null;
143 }
144 Intent intent = new Intent(intentToResolve);
145 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
146 intent.setClassName(ris.get(0).activityInfo.packageName,
147 ris.get(0).activityInfo.name);
148 return intent;
149 }
150
151 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800152 public int[] getPackageGids(String packageName)
153 throws NameNotFoundException {
154 try {
155 int[] gids = mPM.getPackageGids(packageName);
156 if (gids == null || gids.length > 0) {
157 return gids;
158 }
159 } catch (RemoteException e) {
160 throw new RuntimeException("Package manager has died", e);
161 }
162
163 throw new NameNotFoundException(packageName);
164 }
165
166 @Override
Dianne Hackborna06de0f2012-12-11 16:34:47 -0800167 public int getPackageUid(String packageName, int userHandle)
168 throws NameNotFoundException {
169 try {
170 int uid = mPM.getPackageUid(packageName, userHandle);
171 if (uid >= 0) {
172 return uid;
173 }
174 } catch (RemoteException e) {
175 throw new RuntimeException("Package manager has died", e);
176 }
177
178 throw new NameNotFoundException(packageName);
179 }
180
181 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800182 public PermissionInfo getPermissionInfo(String name, int flags)
183 throws NameNotFoundException {
184 try {
185 PermissionInfo pi = mPM.getPermissionInfo(name, flags);
186 if (pi != null) {
187 return pi;
188 }
189 } catch (RemoteException e) {
190 throw new RuntimeException("Package manager has died", e);
191 }
192
193 throw new NameNotFoundException(name);
194 }
195
196 @Override
197 public List<PermissionInfo> queryPermissionsByGroup(String group, int flags)
198 throws NameNotFoundException {
199 try {
200 List<PermissionInfo> pi = mPM.queryPermissionsByGroup(group, flags);
201 if (pi != null) {
202 return pi;
203 }
204 } catch (RemoteException e) {
205 throw new RuntimeException("Package manager has died", e);
206 }
207
208 throw new NameNotFoundException(group);
209 }
210
211 @Override
212 public PermissionGroupInfo getPermissionGroupInfo(String name,
213 int flags) throws NameNotFoundException {
214 try {
215 PermissionGroupInfo pgi = mPM.getPermissionGroupInfo(name, flags);
216 if (pgi != null) {
217 return pgi;
218 }
219 } catch (RemoteException e) {
220 throw new RuntimeException("Package manager has died", e);
221 }
222
223 throw new NameNotFoundException(name);
224 }
225
226 @Override
227 public List<PermissionGroupInfo> getAllPermissionGroups(int flags) {
228 try {
229 return mPM.getAllPermissionGroups(flags);
230 } catch (RemoteException e) {
231 throw new RuntimeException("Package manager has died", e);
232 }
233 }
234
235 @Override
236 public ApplicationInfo getApplicationInfo(String packageName, int flags)
237 throws NameNotFoundException {
238 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700239 ApplicationInfo ai = mPM.getApplicationInfo(packageName, flags, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800240 if (ai != null) {
241 return ai;
242 }
243 } catch (RemoteException e) {
244 throw new RuntimeException("Package manager has died", e);
245 }
246
247 throw new NameNotFoundException(packageName);
248 }
249
250 @Override
251 public ActivityInfo getActivityInfo(ComponentName className, int flags)
252 throws NameNotFoundException {
253 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700254 ActivityInfo ai = mPM.getActivityInfo(className, flags, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800255 if (ai != null) {
256 return ai;
257 }
258 } catch (RemoteException e) {
259 throw new RuntimeException("Package manager has died", e);
260 }
261
262 throw new NameNotFoundException(className.toString());
263 }
264
265 @Override
266 public ActivityInfo getReceiverInfo(ComponentName className, int flags)
267 throws NameNotFoundException {
268 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700269 ActivityInfo ai = mPM.getReceiverInfo(className, flags, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800270 if (ai != null) {
271 return ai;
272 }
273 } catch (RemoteException e) {
274 throw new RuntimeException("Package manager has died", e);
275 }
276
277 throw new NameNotFoundException(className.toString());
278 }
279
280 @Override
281 public ServiceInfo getServiceInfo(ComponentName className, int flags)
282 throws NameNotFoundException {
283 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700284 ServiceInfo si = mPM.getServiceInfo(className, flags, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800285 if (si != null) {
286 return si;
287 }
288 } catch (RemoteException e) {
289 throw new RuntimeException("Package manager has died", e);
290 }
291
292 throw new NameNotFoundException(className.toString());
293 }
294
295 @Override
296 public ProviderInfo getProviderInfo(ComponentName className, int flags)
297 throws NameNotFoundException {
298 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700299 ProviderInfo pi = mPM.getProviderInfo(className, flags, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800300 if (pi != null) {
301 return pi;
302 }
303 } catch (RemoteException e) {
304 throw new RuntimeException("Package manager has died", e);
305 }
306
307 throw new NameNotFoundException(className.toString());
308 }
309
310 @Override
311 public String[] getSystemSharedLibraryNames() {
312 try {
313 return mPM.getSystemSharedLibraryNames();
314 } catch (RemoteException e) {
315 throw new RuntimeException("Package manager has died", e);
316 }
317 }
318
319 @Override
320 public FeatureInfo[] getSystemAvailableFeatures() {
321 try {
322 return mPM.getSystemAvailableFeatures();
323 } catch (RemoteException e) {
324 throw new RuntimeException("Package manager has died", e);
325 }
326 }
327
328 @Override
329 public boolean hasSystemFeature(String name) {
330 try {
331 return mPM.hasSystemFeature(name);
332 } catch (RemoteException e) {
333 throw new RuntimeException("Package manager has died", e);
334 }
335 }
336
337 @Override
338 public int checkPermission(String permName, String pkgName) {
339 try {
340 return mPM.checkPermission(permName, pkgName);
341 } catch (RemoteException e) {
342 throw new RuntimeException("Package manager has died", e);
343 }
344 }
345
346 @Override
347 public boolean addPermission(PermissionInfo info) {
348 try {
349 return mPM.addPermission(info);
350 } catch (RemoteException e) {
351 throw new RuntimeException("Package manager has died", e);
352 }
353 }
354
355 @Override
356 public boolean addPermissionAsync(PermissionInfo info) {
357 try {
358 return mPM.addPermissionAsync(info);
359 } catch (RemoteException e) {
360 throw new RuntimeException("Package manager has died", e);
361 }
362 }
363
364 @Override
365 public void removePermission(String name) {
366 try {
367 mPM.removePermission(name);
368 } catch (RemoteException e) {
369 throw new RuntimeException("Package manager has died", e);
370 }
371 }
372
373 @Override
Dianne Hackborne639da72012-02-21 15:11:13 -0800374 public void grantPermission(String packageName, String permissionName) {
375 try {
376 mPM.grantPermission(packageName, permissionName);
377 } catch (RemoteException e) {
378 throw new RuntimeException("Package manager has died", e);
379 }
380 }
381
382 @Override
383 public void revokePermission(String packageName, String permissionName) {
384 try {
385 mPM.revokePermission(packageName, permissionName);
386 } catch (RemoteException e) {
387 throw new RuntimeException("Package manager has died", e);
388 }
389 }
390
391 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800392 public int checkSignatures(String pkg1, String pkg2) {
393 try {
394 return mPM.checkSignatures(pkg1, pkg2);
395 } catch (RemoteException e) {
396 throw new RuntimeException("Package manager has died", e);
397 }
398 }
399
400 @Override
401 public int checkSignatures(int uid1, int uid2) {
402 try {
403 return mPM.checkUidSignatures(uid1, uid2);
404 } catch (RemoteException e) {
405 throw new RuntimeException("Package manager has died", e);
406 }
407 }
408
409 @Override
410 public String[] getPackagesForUid(int uid) {
411 try {
412 return mPM.getPackagesForUid(uid);
413 } catch (RemoteException e) {
414 throw new RuntimeException("Package manager has died", e);
415 }
416 }
417
418 @Override
419 public String getNameForUid(int uid) {
420 try {
421 return mPM.getNameForUid(uid);
422 } catch (RemoteException e) {
423 throw new RuntimeException("Package manager has died", e);
424 }
425 }
426
427 @Override
428 public int getUidForSharedUser(String sharedUserName)
429 throws NameNotFoundException {
430 try {
431 int uid = mPM.getUidForSharedUser(sharedUserName);
432 if(uid != -1) {
433 return uid;
434 }
435 } catch (RemoteException e) {
436 throw new RuntimeException("Package manager has died", e);
437 }
438 throw new NameNotFoundException("No shared userid for user:"+sharedUserName);
439 }
440
Kenny Roote6cd0c72011-05-19 12:48:14 -0700441 @SuppressWarnings("unchecked")
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800442 @Override
443 public List<PackageInfo> getInstalledPackages(int flags) {
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700444 return getInstalledPackages(flags, mContext.getUserId());
Amith Yamasani151ec4c2012-09-07 19:25:16 -0700445 }
446
447 /** @hide */
448 @Override
449 public List<PackageInfo> getInstalledPackages(int flags, int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800450 try {
Dianne Hackbornd8e1dbb2013-01-17 17:47:37 -0800451 ParceledListSlice<PackageInfo> slice = mPM.getInstalledPackages(flags, userId);
452 return slice.getList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800453 } catch (RemoteException e) {
454 throw new RuntimeException("Package manager has died", e);
455 }
456 }
457
Kenny Roote6cd0c72011-05-19 12:48:14 -0700458 @SuppressWarnings("unchecked")
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800459 @Override
Dianne Hackborne7991752013-01-16 17:56:46 -0800460 public List<PackageInfo> getPackagesHoldingPermissions(
461 String[] permissions, int flags) {
462 final int userId = mContext.getUserId();
463 try {
Dianne Hackbornd8e1dbb2013-01-17 17:47:37 -0800464 ParceledListSlice<PackageInfo> slice = mPM.getPackagesHoldingPermissions(
465 permissions, flags, userId);
466 return slice.getList();
Dianne Hackborne7991752013-01-16 17:56:46 -0800467 } catch (RemoteException e) {
468 throw new RuntimeException("Package manager has died", e);
469 }
470 }
471
472 @SuppressWarnings("unchecked")
473 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800474 public List<ApplicationInfo> getInstalledApplications(int flags) {
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700475 final int userId = mContext.getUserId();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800476 try {
Dianne Hackbornd8e1dbb2013-01-17 17:47:37 -0800477 ParceledListSlice<ApplicationInfo> slice = mPM.getInstalledApplications(flags, userId);
478 return slice.getList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800479 } catch (RemoteException e) {
480 throw new RuntimeException("Package manager has died", e);
481 }
482 }
483
484 @Override
485 public ResolveInfo resolveActivity(Intent intent, int flags) {
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700486 return resolveActivityAsUser(intent, flags, mContext.getUserId());
Svetoslav Ganov58d37b52012-09-18 12:04:19 -0700487 }
488
489 @Override
490 public ResolveInfo resolveActivityAsUser(Intent intent, int flags, int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800491 try {
492 return mPM.resolveIntent(
493 intent,
494 intent.resolveTypeIfNeeded(mContext.getContentResolver()),
Svetoslav Ganov58d37b52012-09-18 12:04:19 -0700495 flags,
496 userId);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800497 } catch (RemoteException e) {
498 throw new RuntimeException("Package manager has died", e);
499 }
500 }
501
502 @Override
503 public List<ResolveInfo> queryIntentActivities(Intent intent,
504 int flags) {
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700505 return queryIntentActivitiesAsUser(intent, flags, mContext.getUserId());
Amith Yamasani151ec4c2012-09-07 19:25:16 -0700506 }
507
508 /** @hide Same as above but for a specific user */
509 @Override
Svetoslav Ganov58d37b52012-09-18 12:04:19 -0700510 public List<ResolveInfo> queryIntentActivitiesAsUser(Intent intent,
Amith Yamasani151ec4c2012-09-07 19:25:16 -0700511 int flags, int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800512 try {
513 return mPM.queryIntentActivities(
514 intent,
515 intent.resolveTypeIfNeeded(mContext.getContentResolver()),
Amith Yamasani483f3b02012-03-13 16:08:00 -0700516 flags,
Amith Yamasani151ec4c2012-09-07 19:25:16 -0700517 userId);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800518 } catch (RemoteException e) {
519 throw new RuntimeException("Package manager has died", e);
520 }
521 }
522
523 @Override
524 public List<ResolveInfo> queryIntentActivityOptions(
525 ComponentName caller, Intent[] specifics, Intent intent,
526 int flags) {
527 final ContentResolver resolver = mContext.getContentResolver();
528
529 String[] specificTypes = null;
530 if (specifics != null) {
531 final int N = specifics.length;
532 for (int i=0; i<N; i++) {
533 Intent sp = specifics[i];
534 if (sp != null) {
535 String t = sp.resolveTypeIfNeeded(resolver);
536 if (t != null) {
537 if (specificTypes == null) {
538 specificTypes = new String[N];
539 }
540 specificTypes[i] = t;
541 }
542 }
543 }
544 }
545
546 try {
547 return mPM.queryIntentActivityOptions(caller, specifics,
548 specificTypes, intent, intent.resolveTypeIfNeeded(resolver),
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700549 flags, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800550 } catch (RemoteException e) {
551 throw new RuntimeException("Package manager has died", e);
552 }
553 }
554
Amith Yamasanif203aee2012-08-29 18:41:53 -0700555 /**
556 * @hide
557 */
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800558 @Override
Amith Yamasanif203aee2012-08-29 18:41:53 -0700559 public List<ResolveInfo> queryBroadcastReceivers(Intent intent, int flags, int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800560 try {
561 return mPM.queryIntentReceivers(
562 intent,
563 intent.resolveTypeIfNeeded(mContext.getContentResolver()),
Amith Yamasani483f3b02012-03-13 16:08:00 -0700564 flags,
Amith Yamasanif203aee2012-08-29 18:41:53 -0700565 userId);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800566 } catch (RemoteException e) {
567 throw new RuntimeException("Package manager has died", e);
568 }
569 }
570
571 @Override
Amith Yamasanif203aee2012-08-29 18:41:53 -0700572 public List<ResolveInfo> queryBroadcastReceivers(Intent intent, int flags) {
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700573 return queryBroadcastReceivers(intent, flags, mContext.getUserId());
Amith Yamasanif203aee2012-08-29 18:41:53 -0700574 }
575
576 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800577 public ResolveInfo resolveService(Intent intent, int flags) {
578 try {
579 return mPM.resolveService(
580 intent,
581 intent.resolveTypeIfNeeded(mContext.getContentResolver()),
Amith Yamasani483f3b02012-03-13 16:08:00 -0700582 flags,
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700583 mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800584 } catch (RemoteException e) {
585 throw new RuntimeException("Package manager has died", e);
586 }
587 }
588
589 @Override
Svetoslav Ganov58d37b52012-09-18 12:04:19 -0700590 public List<ResolveInfo> queryIntentServicesAsUser(Intent intent, int flags, int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800591 try {
592 return mPM.queryIntentServices(
593 intent,
594 intent.resolveTypeIfNeeded(mContext.getContentResolver()),
Amith Yamasani483f3b02012-03-13 16:08:00 -0700595 flags,
Svetoslav Ganov58d37b52012-09-18 12:04:19 -0700596 userId);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800597 } catch (RemoteException e) {
598 throw new RuntimeException("Package manager has died", e);
599 }
600 }
601
602 @Override
Svetoslav Ganov58d37b52012-09-18 12:04:19 -0700603 public List<ResolveInfo> queryIntentServices(Intent intent, int flags) {
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700604 return queryIntentServicesAsUser(intent, flags, mContext.getUserId());
Svetoslav Ganov58d37b52012-09-18 12:04:19 -0700605 }
606
607 @Override
Jeff Sharkey85f5f812013-10-07 10:16:12 -0700608 public List<ResolveInfo> queryIntentContentProvidersAsUser(
609 Intent intent, int flags, int userId) {
610 try {
611 return mPM.queryIntentContentProviders(intent,
612 intent.resolveTypeIfNeeded(mContext.getContentResolver()), flags, userId);
613 } catch (RemoteException e) {
614 throw new RuntimeException("Package manager has died", e);
615 }
616 }
617
618 @Override
619 public List<ResolveInfo> queryIntentContentProviders(Intent intent, int flags) {
620 return queryIntentContentProvidersAsUser(intent, flags, mContext.getUserId());
621 }
622
623 @Override
Alexandra Gherghina0363c3e2014-06-23 13:34:59 +0100624 public ProviderInfo resolveContentProvider(String name, int flags) {
625 return resolveContentProviderAsUser(name, flags, mContext.getUserId());
626 }
627
628 /** @hide **/
629 @Override
630 public ProviderInfo resolveContentProviderAsUser(String name, int flags, int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800631 try {
Alexandra Gherghina0363c3e2014-06-23 13:34:59 +0100632 return mPM.resolveContentProvider(name, flags, userId);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800633 } catch (RemoteException e) {
634 throw new RuntimeException("Package manager has died", e);
635 }
636 }
637
638 @Override
639 public List<ProviderInfo> queryContentProviders(String processName,
640 int uid, int flags) {
641 try {
642 return mPM.queryContentProviders(processName, uid, flags);
643 } catch (RemoteException e) {
644 throw new RuntimeException("Package manager has died", e);
645 }
646 }
647
648 @Override
649 public InstrumentationInfo getInstrumentationInfo(
650 ComponentName className, int flags)
651 throws NameNotFoundException {
652 try {
653 InstrumentationInfo ii = mPM.getInstrumentationInfo(
654 className, flags);
655 if (ii != null) {
656 return ii;
657 }
658 } catch (RemoteException e) {
659 throw new RuntimeException("Package manager has died", e);
660 }
661
662 throw new NameNotFoundException(className.toString());
663 }
664
665 @Override
666 public List<InstrumentationInfo> queryInstrumentation(
667 String targetPackage, int flags) {
668 try {
669 return mPM.queryInstrumentation(targetPackage, flags);
670 } catch (RemoteException e) {
671 throw new RuntimeException("Package manager has died", e);
672 }
673 }
674
675 @Override public Drawable getDrawable(String packageName, int resid,
676 ApplicationInfo appInfo) {
677 ResourceName name = new ResourceName(packageName, resid);
678 Drawable dr = getCachedIcon(name);
679 if (dr != null) {
680 return dr;
681 }
682 if (appInfo == null) {
683 try {
684 appInfo = getApplicationInfo(packageName, 0);
685 } catch (NameNotFoundException e) {
686 return null;
687 }
688 }
689 try {
690 Resources r = getResourcesForApplication(appInfo);
691 dr = r.getDrawable(resid);
692 if (false) {
693 RuntimeException e = new RuntimeException("here");
694 e.fillInStackTrace();
695 Log.w(TAG, "Getting drawable 0x" + Integer.toHexString(resid)
696 + " from package " + packageName
697 + ": app scale=" + r.getCompatibilityInfo().applicationScale
698 + ", caller scale=" + mContext.getResources().getCompatibilityInfo().applicationScale,
699 e);
700 }
701 if (DEBUG_ICONS) Log.v(TAG, "Getting drawable 0x"
702 + Integer.toHexString(resid) + " from " + r
703 + ": " + dr);
704 putCachedIcon(name, dr);
705 return dr;
706 } catch (NameNotFoundException e) {
707 Log.w("PackageManager", "Failure retrieving resources for"
708 + appInfo.packageName);
Joe Onorato08f16542011-01-20 11:49:56 -0800709 } catch (Resources.NotFoundException e) {
710 Log.w("PackageManager", "Failure retrieving resources for"
711 + appInfo.packageName + ": " + e.getMessage());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800712 } catch (RuntimeException e) {
713 // If an exception was thrown, fall through to return
714 // default icon.
715 Log.w("PackageManager", "Failure retrieving icon 0x"
716 + Integer.toHexString(resid) + " in package "
717 + packageName, e);
718 }
719 return null;
720 }
721
722 @Override public Drawable getActivityIcon(ComponentName activityName)
723 throws NameNotFoundException {
724 return getActivityInfo(activityName, 0).loadIcon(this);
725 }
726
727 @Override public Drawable getActivityIcon(Intent intent)
728 throws NameNotFoundException {
729 if (intent.getComponent() != null) {
730 return getActivityIcon(intent.getComponent());
731 }
732
733 ResolveInfo info = resolveActivity(
734 intent, PackageManager.MATCH_DEFAULT_ONLY);
735 if (info != null) {
736 return info.activityInfo.loadIcon(this);
737 }
738
Romain Guy39fe17c2011-11-30 10:34:07 -0800739 throw new NameNotFoundException(intent.toUri(0));
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800740 }
741
742 @Override public Drawable getDefaultActivityIcon() {
743 return Resources.getSystem().getDrawable(
744 com.android.internal.R.drawable.sym_def_app_icon);
745 }
746
747 @Override public Drawable getApplicationIcon(ApplicationInfo info) {
748 return info.loadIcon(this);
749 }
750
751 @Override public Drawable getApplicationIcon(String packageName)
752 throws NameNotFoundException {
753 return getApplicationIcon(getApplicationInfo(packageName, 0));
754 }
755
756 @Override
Jose Limaf78e3122014-03-06 12:13:15 -0800757 public Drawable getActivityBanner(ComponentName activityName)
758 throws NameNotFoundException {
759 return getActivityInfo(activityName, 0).loadBanner(this);
760 }
761
762 @Override
763 public Drawable getActivityBanner(Intent intent)
764 throws NameNotFoundException {
765 if (intent.getComponent() != null) {
766 return getActivityBanner(intent.getComponent());
767 }
768
769 ResolveInfo info = resolveActivity(
770 intent, PackageManager.MATCH_DEFAULT_ONLY);
771 if (info != null) {
772 return info.activityInfo.loadBanner(this);
773 }
774
775 throw new NameNotFoundException(intent.toUri(0));
776 }
777
778 @Override
779 public Drawable getApplicationBanner(ApplicationInfo info) {
780 return info.loadBanner(this);
781 }
782
783 @Override
784 public Drawable getApplicationBanner(String packageName)
785 throws NameNotFoundException {
786 return getApplicationBanner(getApplicationInfo(packageName, 0));
787 }
788
789 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800790 public Drawable getActivityLogo(ComponentName activityName)
791 throws NameNotFoundException {
792 return getActivityInfo(activityName, 0).loadLogo(this);
793 }
794
795 @Override
796 public Drawable getActivityLogo(Intent intent)
797 throws NameNotFoundException {
798 if (intent.getComponent() != null) {
799 return getActivityLogo(intent.getComponent());
800 }
801
802 ResolveInfo info = resolveActivity(
803 intent, PackageManager.MATCH_DEFAULT_ONLY);
804 if (info != null) {
805 return info.activityInfo.loadLogo(this);
806 }
807
808 throw new NameNotFoundException(intent.toUri(0));
809 }
810
811 @Override
812 public Drawable getApplicationLogo(ApplicationInfo info) {
813 return info.loadLogo(this);
814 }
815
816 @Override
817 public Drawable getApplicationLogo(String packageName)
818 throws NameNotFoundException {
819 return getApplicationLogo(getApplicationInfo(packageName, 0));
820 }
821
822 @Override public Resources getResourcesForActivity(
823 ComponentName activityName) throws NameNotFoundException {
824 return getResourcesForApplication(
825 getActivityInfo(activityName, 0).applicationInfo);
826 }
827
828 @Override public Resources getResourcesForApplication(
829 ApplicationInfo app) throws NameNotFoundException {
830 if (app.packageName.equals("system")) {
831 return mContext.mMainThread.getSystemContext().getResources();
832 }
Jeff Sharkey8a4c9722014-06-16 13:48:42 -0700833 final boolean sameUid = (app.uid == Process.myUid());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800834 Resources r = mContext.mMainThread.getTopLevelResources(
Jeff Sharkey8a4c9722014-06-16 13:48:42 -0700835 sameUid ? app.sourceDir : app.publicSourceDir,
836 sameUid ? app.splitSourceDirs : app.splitPublicSourceDirs,
Adam Lesinskide898ff2014-01-29 18:20:45 -0800837 app.resourceDirs, null, Display.DEFAULT_DISPLAY, null, mContext.mPackageInfo);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800838 if (r != null) {
839 return r;
840 }
841 throw new NameNotFoundException("Unable to open " + app.publicSourceDir);
842 }
843
844 @Override public Resources getResourcesForApplication(
845 String appPackageName) throws NameNotFoundException {
846 return getResourcesForApplication(
847 getApplicationInfo(appPackageName, 0));
848 }
849
Amith Yamasani98edc952012-09-25 14:09:27 -0700850 /** @hide */
851 @Override
852 public Resources getResourcesForApplicationAsUser(String appPackageName, int userId)
853 throws NameNotFoundException {
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700854 if (userId < 0) {
855 throw new IllegalArgumentException(
856 "Call does not support special user #" + userId);
857 }
858 if ("system".equals(appPackageName)) {
859 return mContext.mMainThread.getSystemContext().getResources();
860 }
Amith Yamasani98edc952012-09-25 14:09:27 -0700861 try {
862 ApplicationInfo ai = mPM.getApplicationInfo(appPackageName, 0, userId);
863 if (ai != null) {
864 return getResourcesForApplication(ai);
865 }
866 } catch (RemoteException e) {
867 throw new RuntimeException("Package manager has died", e);
868 }
869 throw new NameNotFoundException("Package " + appPackageName + " doesn't exist");
870 }
871
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800872 int mCachedSafeMode = -1;
873 @Override public boolean isSafeMode() {
874 try {
875 if (mCachedSafeMode < 0) {
876 mCachedSafeMode = mPM.isSafeMode() ? 1 : 0;
877 }
878 return mCachedSafeMode != 0;
879 } catch (RemoteException e) {
880 throw new RuntimeException("Package manager has died", e);
881 }
882 }
883
884 static void configurationChanged() {
885 synchronized (sSync) {
886 sIconCache.clear();
887 sStringCache.clear();
888 }
889 }
890
891 ApplicationPackageManager(ContextImpl context,
892 IPackageManager pm) {
893 mContext = context;
894 mPM = pm;
895 }
896
897 private Drawable getCachedIcon(ResourceName name) {
898 synchronized (sSync) {
Romain Guy39fe17c2011-11-30 10:34:07 -0800899 WeakReference<Drawable.ConstantState> wr = sIconCache.get(name);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800900 if (DEBUG_ICONS) Log.v(TAG, "Get cached weak drawable ref for "
901 + name + ": " + wr);
902 if (wr != null) { // we have the activity
Romain Guy39fe17c2011-11-30 10:34:07 -0800903 Drawable.ConstantState state = wr.get();
904 if (state != null) {
905 if (DEBUG_ICONS) {
906 Log.v(TAG, "Get cached drawable state for " + name + ": " + state);
907 }
908 // Note: It's okay here to not use the newDrawable(Resources) variant
909 // of the API. The ConstantState comes from a drawable that was
910 // originally created by passing the proper app Resources instance
911 // which means the state should already contain the proper
912 // resources specific information (like density.) See
913 // BitmapDrawable.BitmapState for instance.
914 return state.newDrawable();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800915 }
916 // our entry has been purged
917 sIconCache.remove(name);
918 }
919 }
920 return null;
921 }
922
923 private void putCachedIcon(ResourceName name, Drawable dr) {
924 synchronized (sSync) {
Romain Guy39fe17c2011-11-30 10:34:07 -0800925 sIconCache.put(name, new WeakReference<Drawable.ConstantState>(dr.getConstantState()));
926 if (DEBUG_ICONS) Log.v(TAG, "Added cached drawable state for " + name + ": " + dr);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800927 }
928 }
929
Romain Guy39fe17c2011-11-30 10:34:07 -0800930 static void handlePackageBroadcast(int cmd, String[] pkgList, boolean hasPkgInfo) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800931 boolean immediateGc = false;
932 if (cmd == IApplicationThread.EXTERNAL_STORAGE_UNAVAILABLE) {
933 immediateGc = true;
934 }
935 if (pkgList != null && (pkgList.length > 0)) {
936 boolean needCleanup = false;
937 for (String ssp : pkgList) {
938 synchronized (sSync) {
Dianne Hackbornadd005c2013-07-17 18:43:12 -0700939 for (int i=sIconCache.size()-1; i>=0; i--) {
940 ResourceName nm = sIconCache.keyAt(i);
941 if (nm.packageName.equals(ssp)) {
942 //Log.i(TAG, "Removing cached drawable for " + nm);
943 sIconCache.removeAt(i);
944 needCleanup = true;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800945 }
946 }
Dianne Hackbornadd005c2013-07-17 18:43:12 -0700947 for (int i=sStringCache.size()-1; i>=0; i--) {
948 ResourceName nm = sStringCache.keyAt(i);
949 if (nm.packageName.equals(ssp)) {
950 //Log.i(TAG, "Removing cached string for " + nm);
951 sStringCache.removeAt(i);
952 needCleanup = true;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800953 }
954 }
955 }
956 }
957 if (needCleanup || hasPkgInfo) {
958 if (immediateGc) {
959 // Schedule an immediate gc.
960 Runtime.getRuntime().gc();
961 } else {
962 ActivityThread.currentActivityThread().scheduleGcIdler();
963 }
964 }
965 }
966 }
967
968 private static final class ResourceName {
969 final String packageName;
970 final int iconId;
971
972 ResourceName(String _packageName, int _iconId) {
973 packageName = _packageName;
974 iconId = _iconId;
975 }
976
977 ResourceName(ApplicationInfo aInfo, int _iconId) {
978 this(aInfo.packageName, _iconId);
979 }
980
981 ResourceName(ComponentInfo cInfo, int _iconId) {
982 this(cInfo.applicationInfo.packageName, _iconId);
983 }
984
985 ResourceName(ResolveInfo rInfo, int _iconId) {
986 this(rInfo.activityInfo.applicationInfo.packageName, _iconId);
987 }
988
989 @Override
990 public boolean equals(Object o) {
991 if (this == o) return true;
992 if (o == null || getClass() != o.getClass()) return false;
993
994 ResourceName that = (ResourceName) o;
995
996 if (iconId != that.iconId) return false;
997 return !(packageName != null ?
998 !packageName.equals(that.packageName) : that.packageName != null);
999
1000 }
1001
1002 @Override
1003 public int hashCode() {
1004 int result;
1005 result = packageName.hashCode();
1006 result = 31 * result + iconId;
1007 return result;
1008 }
1009
1010 @Override
1011 public String toString() {
1012 return "{ResourceName " + packageName + " / " + iconId + "}";
1013 }
1014 }
1015
1016 private CharSequence getCachedString(ResourceName name) {
1017 synchronized (sSync) {
1018 WeakReference<CharSequence> wr = sStringCache.get(name);
1019 if (wr != null) { // we have the activity
1020 CharSequence cs = wr.get();
1021 if (cs != null) {
1022 return cs;
1023 }
1024 // our entry has been purged
1025 sStringCache.remove(name);
1026 }
1027 }
1028 return null;
1029 }
1030
1031 private void putCachedString(ResourceName name, CharSequence cs) {
1032 synchronized (sSync) {
1033 sStringCache.put(name, new WeakReference<CharSequence>(cs));
1034 }
1035 }
1036
1037 @Override
1038 public CharSequence getText(String packageName, int resid,
1039 ApplicationInfo appInfo) {
1040 ResourceName name = new ResourceName(packageName, resid);
1041 CharSequence text = getCachedString(name);
1042 if (text != null) {
1043 return text;
1044 }
1045 if (appInfo == null) {
1046 try {
1047 appInfo = getApplicationInfo(packageName, 0);
1048 } catch (NameNotFoundException e) {
1049 return null;
1050 }
1051 }
1052 try {
1053 Resources r = getResourcesForApplication(appInfo);
1054 text = r.getText(resid);
1055 putCachedString(name, text);
1056 return text;
1057 } catch (NameNotFoundException e) {
1058 Log.w("PackageManager", "Failure retrieving resources for"
1059 + appInfo.packageName);
1060 } catch (RuntimeException e) {
1061 // If an exception was thrown, fall through to return
1062 // default icon.
1063 Log.w("PackageManager", "Failure retrieving text 0x"
1064 + Integer.toHexString(resid) + " in package "
1065 + packageName, e);
1066 }
1067 return null;
1068 }
1069
1070 @Override
1071 public XmlResourceParser getXml(String packageName, int resid,
1072 ApplicationInfo appInfo) {
1073 if (appInfo == null) {
1074 try {
1075 appInfo = getApplicationInfo(packageName, 0);
1076 } catch (NameNotFoundException e) {
1077 return null;
1078 }
1079 }
1080 try {
1081 Resources r = getResourcesForApplication(appInfo);
1082 return r.getXml(resid);
1083 } catch (RuntimeException e) {
1084 // If an exception was thrown, fall through to return
1085 // default icon.
1086 Log.w("PackageManager", "Failure retrieving xml 0x"
1087 + Integer.toHexString(resid) + " in package "
1088 + packageName, e);
1089 } catch (NameNotFoundException e) {
Alon Albert3fa51e32010-11-11 09:24:04 -08001090 Log.w("PackageManager", "Failure retrieving resources for "
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001091 + appInfo.packageName);
1092 }
1093 return null;
1094 }
1095
1096 @Override
1097 public CharSequence getApplicationLabel(ApplicationInfo info) {
1098 return info.loadLabel(this);
1099 }
1100
1101 @Override
1102 public void installPackage(Uri packageURI, IPackageInstallObserver observer, int flags,
1103 String installerPackageName) {
1104 try {
Christopher Tatef1977b42014-03-24 16:25:51 -07001105 mPM.installPackageEtc(packageURI, observer, null, flags, installerPackageName);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001106 } catch (RemoteException e) {
1107 // Should never happen!
1108 }
1109 }
1110
1111 @Override
Kenny Root5ab21572011-07-27 11:11:19 -07001112 public void installPackageWithVerification(Uri packageURI, IPackageInstallObserver observer,
1113 int flags, String installerPackageName, Uri verificationURI,
Rich Canningse1d7c712012-08-08 12:46:06 -07001114 ManifestDigest manifestDigest, ContainerEncryptionParams encryptionParams) {
Kenny Root5ab21572011-07-27 11:11:19 -07001115 try {
Christopher Tatef1977b42014-03-24 16:25:51 -07001116 mPM.installPackageWithVerificationEtc(packageURI, observer, null, flags,
1117 installerPackageName, verificationURI, manifestDigest, encryptionParams);
Kenny Root5ab21572011-07-27 11:11:19 -07001118 } catch (RemoteException e) {
1119 // Should never happen!
1120 }
1121 }
1122
1123 @Override
John Spurlock8a985d22014-02-25 09:40:05 -05001124 public void installPackageWithVerificationAndEncryption(Uri packageURI,
rich cannings706e8ba2012-08-20 13:20:14 -07001125 IPackageInstallObserver observer, int flags, String installerPackageName,
1126 VerificationParams verificationParams, ContainerEncryptionParams encryptionParams) {
1127 try {
Christopher Tatef1977b42014-03-24 16:25:51 -07001128 mPM.installPackageWithVerificationAndEncryptionEtc(packageURI, observer, null,
1129 flags, installerPackageName, verificationParams, encryptionParams);
1130 } catch (RemoteException e) {
1131 // Should never happen!
1132 }
1133 }
1134
1135 // Expanded observer-API versions
1136 @Override
1137 public void installPackage(Uri packageURI, PackageInstallObserver observer,
1138 int flags, String installerPackageName) {
1139 try {
Jeff Sharkey3a44f3f2014-04-28 17:36:31 -07001140 mPM.installPackageEtc(packageURI, null, observer.getBinder(),
Christopher Tatef1977b42014-03-24 16:25:51 -07001141 flags, installerPackageName);
1142 } catch (RemoteException e) {
1143 // Should never happen!
1144 }
1145 }
1146
1147 @Override
1148 public void installPackageWithVerification(Uri packageURI,
1149 PackageInstallObserver observer, int flags, String installerPackageName,
1150 Uri verificationURI, ManifestDigest manifestDigest,
1151 ContainerEncryptionParams encryptionParams) {
1152 try {
Jeff Sharkey3a44f3f2014-04-28 17:36:31 -07001153 mPM.installPackageWithVerificationEtc(packageURI, null, observer.getBinder(), flags,
Christopher Tatef1977b42014-03-24 16:25:51 -07001154 installerPackageName, verificationURI, manifestDigest, encryptionParams);
1155 } catch (RemoteException e) {
1156 // Should never happen!
1157 }
1158 }
1159
1160 @Override
1161 public void installPackageWithVerificationAndEncryption(Uri packageURI,
1162 PackageInstallObserver observer, int flags, String installerPackageName,
1163 VerificationParams verificationParams, ContainerEncryptionParams encryptionParams) {
1164 try {
1165 mPM.installPackageWithVerificationAndEncryptionEtc(packageURI, null,
Jeff Sharkey3a44f3f2014-04-28 17:36:31 -07001166 observer.getBinder(), flags, installerPackageName, verificationParams,
Christopher Tatef1977b42014-03-24 16:25:51 -07001167 encryptionParams);
rich cannings706e8ba2012-08-20 13:20:14 -07001168 } catch (RemoteException e) {
1169 // Should never happen!
1170 }
1171 }
1172
1173 @Override
Dianne Hackborn7767eac2012-08-23 18:25:40 -07001174 public int installExistingPackage(String packageName)
1175 throws NameNotFoundException {
1176 try {
Amith Yamasani67df64b2012-12-14 12:09:36 -08001177 int res = mPM.installExistingPackageAsUser(packageName, UserHandle.myUserId());
Dianne Hackborn7767eac2012-08-23 18:25:40 -07001178 if (res == INSTALL_FAILED_INVALID_URI) {
1179 throw new NameNotFoundException("Package " + packageName + " doesn't exist");
1180 }
1181 return res;
1182 } catch (RemoteException e) {
1183 // Should never happen!
1184 throw new NameNotFoundException("Package " + packageName + " doesn't exist");
1185 }
1186 }
1187
1188 @Override
Kenny Root3a9b5fb2011-09-20 14:15:38 -07001189 public void verifyPendingInstall(int id, int response) {
Kenny Root5ab21572011-07-27 11:11:19 -07001190 try {
Kenny Root3a9b5fb2011-09-20 14:15:38 -07001191 mPM.verifyPendingInstall(id, response);
Kenny Root5ab21572011-07-27 11:11:19 -07001192 } catch (RemoteException e) {
1193 // Should never happen!
1194 }
1195 }
1196
1197 @Override
rich canningsd9ef3e52012-08-22 14:28:05 -07001198 public void extendVerificationTimeout(int id, int verificationCodeAtTimeout,
1199 long millisecondsToDelay) {
1200 try {
1201 mPM.extendVerificationTimeout(id, verificationCodeAtTimeout, millisecondsToDelay);
1202 } catch (RemoteException e) {
1203 // Should never happen!
1204 }
1205 }
1206
1207 @Override
Dianne Hackborn880119b2010-11-18 22:26:40 -08001208 public void setInstallerPackageName(String targetPackage,
1209 String installerPackageName) {
1210 try {
1211 mPM.setInstallerPackageName(targetPackage, installerPackageName);
1212 } catch (RemoteException e) {
1213 // Should never happen!
1214 }
1215 }
1216
1217 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001218 public void movePackage(String packageName, IPackageMoveObserver observer, int flags) {
1219 try {
1220 mPM.movePackage(packageName, observer, flags);
1221 } catch (RemoteException e) {
1222 // Should never happen!
1223 }
1224 }
1225
1226 @Override
1227 public String getInstallerPackageName(String packageName) {
1228 try {
1229 return mPM.getInstallerPackageName(packageName);
1230 } catch (RemoteException e) {
1231 // Should never happen!
1232 }
1233 return null;
1234 }
1235
1236 @Override
1237 public void deletePackage(String packageName, IPackageDeleteObserver observer, int flags) {
1238 try {
Amith Yamasani67df64b2012-12-14 12:09:36 -08001239 mPM.deletePackageAsUser(packageName, observer, UserHandle.myUserId(), flags);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001240 } catch (RemoteException e) {
1241 // Should never happen!
1242 }
1243 }
1244 @Override
1245 public void clearApplicationUserData(String packageName,
1246 IPackageDataObserver observer) {
1247 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -07001248 mPM.clearApplicationUserData(packageName, observer, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001249 } catch (RemoteException e) {
1250 // Should never happen!
1251 }
1252 }
1253 @Override
1254 public void deleteApplicationCacheFiles(String packageName,
1255 IPackageDataObserver observer) {
1256 try {
1257 mPM.deleteApplicationCacheFiles(packageName, observer);
1258 } catch (RemoteException e) {
1259 // Should never happen!
1260 }
1261 }
1262 @Override
1263 public void freeStorageAndNotify(long idealStorageSize, IPackageDataObserver observer) {
1264 try {
1265 mPM.freeStorageAndNotify(idealStorageSize, observer);
1266 } catch (RemoteException e) {
1267 // Should never happen!
1268 }
1269 }
1270
1271 @Override
1272 public void freeStorage(long freeStorageSize, IntentSender pi) {
1273 try {
1274 mPM.freeStorage(freeStorageSize, pi);
1275 } catch (RemoteException e) {
1276 // Should never happen!
1277 }
1278 }
1279
1280 @Override
Dianne Hackborn0c380492012-08-20 17:23:30 -07001281 public void getPackageSizeInfo(String packageName, int userHandle,
1282 IPackageStatsObserver observer) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001283 try {
Dianne Hackborn0c380492012-08-20 17:23:30 -07001284 mPM.getPackageSizeInfo(packageName, userHandle, observer);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001285 } catch (RemoteException e) {
1286 // Should never happen!
1287 }
1288 }
1289 @Override
1290 public void addPackageToPreferred(String packageName) {
1291 try {
1292 mPM.addPackageToPreferred(packageName);
1293 } catch (RemoteException e) {
1294 // Should never happen!
1295 }
1296 }
1297
1298 @Override
1299 public void removePackageFromPreferred(String packageName) {
1300 try {
1301 mPM.removePackageFromPreferred(packageName);
1302 } catch (RemoteException e) {
1303 // Should never happen!
1304 }
1305 }
1306
1307 @Override
1308 public List<PackageInfo> getPreferredPackages(int flags) {
1309 try {
1310 return mPM.getPreferredPackages(flags);
1311 } catch (RemoteException e) {
1312 // Should never happen!
1313 }
1314 return new ArrayList<PackageInfo>();
1315 }
1316
1317 @Override
1318 public void addPreferredActivity(IntentFilter filter,
1319 int match, ComponentName[] set, ComponentName activity) {
1320 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -07001321 mPM.addPreferredActivity(filter, match, set, activity, mContext.getUserId());
Amith Yamasania3f133a2012-08-09 17:11:28 -07001322 } catch (RemoteException e) {
1323 // Should never happen!
1324 }
1325 }
1326
1327 @Override
1328 public void addPreferredActivity(IntentFilter filter, int match,
1329 ComponentName[] set, ComponentName activity, int userId) {
1330 try {
1331 mPM.addPreferredActivity(filter, match, set, activity, userId);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001332 } catch (RemoteException e) {
1333 // Should never happen!
1334 }
1335 }
1336
1337 @Override
1338 public void replacePreferredActivity(IntentFilter filter,
1339 int match, ComponentName[] set, ComponentName activity) {
1340 try {
1341 mPM.replacePreferredActivity(filter, match, set, activity);
1342 } catch (RemoteException e) {
1343 // Should never happen!
1344 }
1345 }
1346
1347 @Override
1348 public void clearPackagePreferredActivities(String packageName) {
1349 try {
1350 mPM.clearPackagePreferredActivities(packageName);
1351 } catch (RemoteException e) {
1352 // Should never happen!
1353 }
1354 }
1355
1356 @Override
1357 public int getPreferredActivities(List<IntentFilter> outFilters,
1358 List<ComponentName> outActivities, String packageName) {
1359 try {
1360 return mPM.getPreferredActivities(outFilters, outActivities, packageName);
1361 } catch (RemoteException e) {
1362 // Should never happen!
1363 }
1364 return 0;
1365 }
1366
1367 @Override
Christopher Tatea2a08502013-09-05 16:38:58 -07001368 public ComponentName getHomeActivities(List<ResolveInfo> outActivities) {
1369 try {
1370 return mPM.getHomeActivities(outActivities);
1371 } catch (RemoteException e) {
1372 // Should never happen!
1373 }
1374 return null;
1375 }
1376
1377 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001378 public void setComponentEnabledSetting(ComponentName componentName,
1379 int newState, int flags) {
1380 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -07001381 mPM.setComponentEnabledSetting(componentName, newState, flags, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001382 } catch (RemoteException e) {
1383 // Should never happen!
1384 }
1385 }
1386
1387 @Override
1388 public int getComponentEnabledSetting(ComponentName componentName) {
1389 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -07001390 return mPM.getComponentEnabledSetting(componentName, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001391 } catch (RemoteException e) {
1392 // Should never happen!
1393 }
1394 return PackageManager.COMPONENT_ENABLED_STATE_DEFAULT;
1395 }
1396
1397 @Override
1398 public void setApplicationEnabledSetting(String packageName,
1399 int newState, int flags) {
1400 try {
Dianne Hackborn3fa3c28a2013-03-26 16:15:41 -07001401 mPM.setApplicationEnabledSetting(packageName, newState, flags,
Dianne Hackborn95d78532013-09-11 09:51:14 -07001402 mContext.getUserId(), mContext.getOpPackageName());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001403 } catch (RemoteException e) {
1404 // Should never happen!
1405 }
1406 }
1407
1408 @Override
1409 public int getApplicationEnabledSetting(String packageName) {
1410 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -07001411 return mPM.getApplicationEnabledSetting(packageName, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001412 } catch (RemoteException e) {
1413 // Should never happen!
1414 }
1415 return PackageManager.COMPONENT_ENABLED_STATE_DEFAULT;
1416 }
1417
Amith Yamasani655d0e22013-06-12 14:19:10 -07001418 @Override
1419 public boolean setApplicationBlockedSettingAsUser(String packageName, boolean blocked,
1420 UserHandle user) {
1421 try {
1422 return mPM.setApplicationBlockedSettingAsUser(packageName, blocked,
1423 user.getIdentifier());
1424 } catch (RemoteException re) {
1425 // Should never happen!
1426 }
1427 return false;
1428 }
1429
1430 @Override
1431 public boolean getApplicationBlockedSettingAsUser(String packageName, UserHandle user) {
1432 try {
1433 return mPM.getApplicationBlockedSettingAsUser(packageName, user.getIdentifier());
1434 } catch (RemoteException re) {
1435 // Should never happen!
1436 }
1437 return false;
1438 }
1439
Kenny Root0aaa0d92011-09-12 16:42:55 -07001440 /**
1441 * @hide
1442 */
1443 @Override
1444 public VerifierDeviceIdentity getVerifierDeviceIdentity() {
1445 try {
1446 return mPM.getVerifierDeviceIdentity();
1447 } catch (RemoteException e) {
1448 // Should never happen!
1449 }
1450 return null;
1451 }
1452
Jeff Sharkey3a44f3f2014-04-28 17:36:31 -07001453 @Override
1454 public PackageInstaller getPackageInstaller() {
1455 try {
1456 return new PackageInstaller(this, mPM.getPackageInstaller(), mContext.getUserId(),
1457 mContext.getPackageName());
1458 } catch (RemoteException e) {
1459 throw e.rethrowAsRuntimeException();
1460 }
1461 }
1462
Nicolas Prevotc79586e2014-05-06 12:47:57 +01001463 /**
1464 * @hide
1465 */
1466 @Override
Nicolas Prevot63798c52014-05-27 13:22:38 +01001467 public void addCrossProfileIntentFilter(IntentFilter filter, int sourceUserId, int targetUserId,
1468 int flags) {
Nicolas Prevotc79586e2014-05-06 12:47:57 +01001469 try {
Nicolas Prevot63798c52014-05-27 13:22:38 +01001470 mPM.addCrossProfileIntentFilter(filter, sourceUserId, targetUserId, flags);
Nicolas Prevotc79586e2014-05-06 12:47:57 +01001471 } catch (RemoteException e) {
1472 // Should never happen!
1473 }
1474 }
1475
1476 /**
1477 * @hide
1478 */
Alexandra Gherghina6e2ae252014-06-12 16:03:58 +01001479 public void addCrossProfileIntentsForPackage(String packageName,
1480 int sourceUserId, int targetUserId) {
1481 try {
1482 mPM.addCrossProfileIntentsForPackage(packageName, sourceUserId, targetUserId);
1483 } catch (RemoteException e) {
1484 // Should never happen!
1485 }
1486 }
1487
1488 /**
1489 * @hide
1490 */
Nicolas Prevotc79586e2014-05-06 12:47:57 +01001491 @Override
Nicolas Prevot81948992014-05-16 18:25:26 +01001492 public void clearCrossProfileIntentFilters(int sourceUserId) {
Nicolas Prevotc79586e2014-05-06 12:47:57 +01001493 try {
Nicolas Prevot81948992014-05-16 18:25:26 +01001494 mPM.clearCrossProfileIntentFilters(sourceUserId);
Nicolas Prevotc79586e2014-05-06 12:47:57 +01001495 } catch (RemoteException e) {
1496 // Should never happen!
1497 }
1498 }
1499
Nicolas Prevot88cc3462014-05-14 14:51:48 +01001500 /**
1501 * @hide
1502 */
1503 @Override
1504 public Bitmap getUserIcon(int userId) {
1505 UserManager um = UserManager.get(mContext);
1506 return um.getUserIcon(userId);
1507 }
1508
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001509 private final ContextImpl mContext;
1510 private final IPackageManager mPM;
1511
1512 private static final Object sSync = new Object();
Dianne Hackbornadd005c2013-07-17 18:43:12 -07001513 private static ArrayMap<ResourceName, WeakReference<Drawable.ConstantState>> sIconCache
1514 = new ArrayMap<ResourceName, WeakReference<Drawable.ConstantState>>();
1515 private static ArrayMap<ResourceName, WeakReference<CharSequence>> sStringCache
1516 = new ArrayMap<ResourceName, WeakReference<CharSequence>>();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001517}