ShadowApplicationPackageManager.java revision 88fbaf29896f691addb303eaaf4b5ece4698e39b
1package org.robolectric.shadows; 2 3import static android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_DISABLED; 4import static android.content.pm.PackageManager.GET_META_DATA; 5import static android.content.pm.PackageManager.GET_SIGNATURES; 6import static android.content.pm.PackageManager.MATCH_UNINSTALLED_PACKAGES; 7import static android.content.pm.PackageManager.SIGNATURE_UNKNOWN_PACKAGE; 8import static android.os.Build.VERSION_CODES.JELLY_BEAN; 9import static android.os.Build.VERSION_CODES.JELLY_BEAN_MR1; 10import static android.os.Build.VERSION_CODES.M; 11import static android.os.Build.VERSION_CODES.N; 12import static org.robolectric.shadow.api.Shadow.directlyOn; 13 14import android.annotation.DrawableRes; 15import android.annotation.NonNull; 16import android.annotation.Nullable; 17import android.annotation.StringRes; 18import android.annotation.UserIdInt; 19import android.app.ApplicationPackageManager; 20import android.content.ComponentName; 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.FeatureInfo; 27import android.content.pm.IPackageDataObserver; 28import android.content.pm.IPackageDeleteObserver; 29import android.content.pm.IPackageInstallObserver; 30import android.content.pm.IPackageStatsObserver; 31import android.content.pm.InstrumentationInfo; 32import android.content.pm.IntentFilterVerificationInfo; 33import android.content.pm.PackageInfo; 34import android.content.pm.PackageItemInfo; 35import android.content.pm.PackageManager; 36import android.content.pm.PackageManager.NameNotFoundException; 37import android.content.pm.PackageStats; 38import android.content.pm.PermissionGroupInfo; 39import android.content.pm.PermissionInfo; 40import android.content.pm.ProviderInfo; 41import android.content.pm.ResolveInfo; 42import android.content.pm.ServiceInfo; 43import android.content.pm.VerifierDeviceIdentity; 44import android.content.res.Resources; 45import android.graphics.Rect; 46import android.graphics.drawable.Drawable; 47import android.net.Uri; 48import android.os.Handler; 49import android.os.Looper; 50import android.os.RemoteException; 51import android.os.UserHandle; 52import android.os.storage.VolumeInfo; 53import android.util.Pair; 54import java.util.ArrayList; 55import java.util.Collections; 56import java.util.HashSet; 57import java.util.Iterator; 58import java.util.LinkedList; 59import java.util.List; 60 61import java.util.Map; 62import java.util.Objects; 63import java.util.Set; 64import org.robolectric.RuntimeEnvironment; 65import org.robolectric.annotation.Implementation; 66import org.robolectric.annotation.Implements; 67import org.robolectric.manifest.ActivityData; 68import org.robolectric.manifest.AndroidManifest; 69import org.robolectric.manifest.ContentProviderData; 70import org.robolectric.manifest.PackageItemData; 71import org.robolectric.manifest.PermissionItemData; 72import org.robolectric.manifest.ServiceData; 73 74@Implements(value = ApplicationPackageManager.class, isInAndroidSdk = false, looseSignatures = true) 75public class ShadowApplicationPackageManager extends ShadowPackageManager { 76 77 @Implementation 78 public List<PackageInfo> getInstalledPackages(int flags) { 79 List<PackageInfo> result = new ArrayList<>(); 80 for (PackageInfo packageInfo : packageInfos.values()) { 81 if (applicationEnabledSettingMap.get(packageInfo.packageName) 82 != COMPONENT_ENABLED_STATE_DISABLED 83 || (flags & MATCH_UNINSTALLED_PACKAGES) == MATCH_UNINSTALLED_PACKAGES) { 84 result.add(packageInfo); 85 } 86 } 87 88 return result; 89 } 90 91 @Implementation 92 public ActivityInfo getActivityInfo(ComponentName component, int flags) throws NameNotFoundException { 93 ActivityInfo activityInfo = new ActivityInfo(); 94 String packageName = component.getPackageName(); 95 String activityName = component.getClassName(); 96 activityInfo.name = activityName; 97 activityInfo.packageName = packageName; 98 99 AndroidManifest androidManifest = androidManifests.get(packageName); 100 101 // In the cases where there is no manifest entry for the activity, e.g: a test that creates 102 // simply an android.app.Activity just return what we have. 103 if (androidManifest == null) { 104 return activityInfo; 105 } 106 107 ActivityData activityData = androidManifest.getActivityData(activityName); 108 if (activityData != null) { 109 activityInfo.configChanges = getConfigChanges(activityData); 110 activityInfo.parentActivityName = activityData.getParentActivityName(); 111 activityInfo.metaData = metaDataToBundle(activityData.getMetaData().getValueMap()); 112 String themeRef; 113 114 // Based on ShadowActivity 115 if (activityData.getThemeRef() != null) { 116 themeRef = activityData.getThemeRef(); 117 } else { 118 themeRef = androidManifest.getThemeRef(); 119 } 120 if (themeRef != null) { 121 activityInfo.theme = RuntimeEnvironment.application.getResources().getIdentifier(themeRef.replace("@", ""), "style", packageName); 122 } 123 } 124 activityInfo.applicationInfo = getApplicationInfo(packageName, flags); 125 return activityInfo; 126 } 127 128 @Implementation 129 public boolean hasSystemFeature(String name) { 130 return systemFeatureList.containsKey(name) ? systemFeatureList.get(name) : false; 131 } 132 133 @Implementation 134 public int getComponentEnabledSetting(ComponentName componentName) { 135 ComponentState state = componentList.get(componentName); 136 return state != null ? state.newState : PackageManager.COMPONENT_ENABLED_STATE_DEFAULT; 137 } 138 139 @Implementation 140 public @Nullable String getNameForUid(int uid) { 141 return namesForUid.get(uid); 142 } 143 144 @Implementation 145 public @Nullable String[] getPackagesForUid(int uid) { 146 String[] packageNames = packagesForUid.get(uid); 147 if (packageNames != null) { 148 return packageNames; 149 } 150 151 Set<String> results = new HashSet<>(); 152 for (PackageInfo packageInfo : packageInfos.values()) { 153 if (packageInfo.applicationInfo != null && packageInfo.applicationInfo.uid == uid) { 154 results.add(packageInfo.packageName); 155 } 156 } 157 158 return results.isEmpty() 159 ? null 160 :results.toArray(new String[results.size()]); 161 } 162 163 @Implementation 164 public int getApplicationEnabledSetting(String packageName) { 165 try { 166 getPackageInfo(packageName, -1); 167 } catch (NameNotFoundException e) { 168 throw new IllegalArgumentException(e); 169 } 170 171 return applicationEnabledSettingMap.get(packageName); 172 } 173 174 @Implementation 175 public ProviderInfo getProviderInfo(ComponentName component, int flags) throws NameNotFoundException { 176 String packageName = component.getPackageName(); 177 AndroidManifest androidManifest = androidManifests.get(packageName); 178 String classString = resolvePackageName(packageName, component); 179 180 if (androidManifest != null) { 181 for (ContentProviderData contentProviderData : androidManifest.getContentProviders()) { 182 if (contentProviderData.getClassName().equals(classString)) { 183 ProviderInfo providerInfo = new ProviderInfo(); 184 providerInfo.packageName = packageName; 185 providerInfo.name = contentProviderData.getClassName(); 186 providerInfo.authority = contentProviderData.getAuthorities(); // todo: support multiple authorities 187 providerInfo.readPermission = contentProviderData.getReadPermission(); 188 providerInfo.writePermission = contentProviderData.getWritePermission(); 189 providerInfo.pathPermissions = createPathPermissions(contentProviderData.getPathPermissionDatas()); 190 providerInfo.metaData = metaDataToBundle(contentProviderData.getMetaData().getValueMap()); 191 if ((flags & GET_META_DATA) != 0) { 192 providerInfo.metaData = metaDataToBundle(contentProviderData.getMetaData().getValueMap()); 193 } 194 return providerInfo; 195 } 196 } 197 } 198 199 throw new NameNotFoundException("Package not found: " + packageName); 200 } 201 202 @Implementation 203 public void setComponentEnabledSetting(ComponentName componentName, int newState, int flags) { 204 componentList.put(componentName, new ComponentState(newState, flags)); 205 } 206 207 @Override @Implementation 208 public void setApplicationEnabledSetting(String packageName, int newState, int flags) { 209 applicationEnabledSettingMap.put(packageName, newState); 210 } 211 212 @Implementation 213 public ResolveInfo resolveActivity(Intent intent, int flags) { 214 List<ResolveInfo> candidates = queryIntentActivities(intent, flags); 215 return candidates.isEmpty() ? null : candidates.get(0); 216 } 217 218 @Implementation 219 public ProviderInfo resolveContentProvider(String name, int flags) { 220 for (PackageInfo packageInfo : packageInfos.values()) { 221 if (packageInfo.providers == null) continue; 222 223 for (ProviderInfo providerInfo : packageInfo.providers) { 224 if (name.equals(providerInfo.authority)) { // todo: support multiple authorities 225 return providerInfo; 226 } 227 } 228 } 229 230 return null; 231 } 232 233 @Implementation 234 public ProviderInfo resolveContentProviderAsUser(String name, int flags, @UserIdInt int userId) { 235 return null; 236 } 237 238 @Implementation 239 public PackageInfo getPackageInfo(String packageName, int flags) throws NameNotFoundException { 240 PackageInfo info = packageInfos.get(packageName); 241 if (info != null) { 242 if (applicationEnabledSettingMap.get(packageName) == COMPONENT_ENABLED_STATE_DISABLED 243 && (flags & MATCH_UNINSTALLED_PACKAGES) != MATCH_UNINSTALLED_PACKAGES) { 244 throw new NameNotFoundException("Package is disabled, can't find"); 245 } 246 return info; 247 } else { 248 throw new NameNotFoundException(packageName); 249 } 250 } 251 252 @Implementation 253 public List<ResolveInfo> queryIntentServices(Intent intent, int flags) { 254 // Check the manually added resolve infos first. 255 List<ResolveInfo> resolveInfos = queryIntent(intent, flags); 256 if (!resolveInfos.isEmpty()) { 257 return resolveInfos; 258 } 259 260 // Check matches from the manifest. 261 resolveInfos = new ArrayList<>(); 262 AndroidManifest applicationManifest = RuntimeEnvironment.getAppManifest(); 263 if (resolveInfos.isEmpty() && applicationManifest != null) { 264 for (ServiceData service : applicationManifest.getServices()) { 265 IntentFilter intentFilter = matchIntentFilter(intent, service.getIntentFilters()); 266 if (intentFilter != null) { 267 resolveInfos.add(getResolveInfo(service, intentFilter, applicationManifest.getPackageName())); 268 } 269 } 270 } 271 272 return resolveInfos; 273 } 274 275 @Implementation 276 public List<ResolveInfo> queryIntentActivities(Intent intent, int flags) { 277 List<ResolveInfo> resolveInfoList = queryIntent(intent, flags); 278 279 if (resolveInfoList.isEmpty() && queryIntentImplicitly) { 280 resolveInfoList = queryImplicitIntent(intent, flags); 281 } 282 283 return resolveInfoList; 284 } 285 286 private List<ResolveInfo> queryImplicitIntent(Intent intent, int flags) { 287 List<ResolveInfo> resolveInfoList = new ArrayList<>(); 288 289 for (Map.Entry<String, AndroidManifest> androidManifest : androidManifests.entrySet()) { 290 String packageName = androidManifest.getKey(); 291 AndroidManifest appManifest = androidManifest.getValue(); 292 293 for (Map.Entry<String, ActivityData> activity : appManifest.getActivityDatas().entrySet()) { 294 String activityName = activity.getKey(); 295 ActivityData activityData = activity.getValue(); 296 if (activityData.getTargetActivity() != null) { 297 activityName = activityData.getTargetActivityName(); 298 } 299 300 IntentFilter intentFilter = matchIntentFilter(intent, activityData.getIntentFilters()); 301 if (intentFilter != null) { 302 ResolveInfo resolveInfo = new ResolveInfo(); 303 resolveInfo.resolvePackageName = packageName; 304 resolveInfo.activityInfo = new ActivityInfo(); 305 resolveInfo.activityInfo.targetActivity = activityName; 306 resolveInfo.activityInfo.name = activityData.getName(); 307 resolveInfoList.add(resolveInfo); 308 } 309 } 310 } 311 312 return resolveInfoList; 313 } 314 315 @Implementation 316 public int checkPermission(String permName, String pkgName) { 317 PackageInfo permissionsInfo = packageInfos.get(pkgName); 318 if (permissionsInfo == null || permissionsInfo.requestedPermissions == null) { 319 return PackageManager.PERMISSION_DENIED; 320 } 321 for (String permission : permissionsInfo.requestedPermissions) { 322 if (permission != null && permission.equals(permName)) { 323 return PackageManager.PERMISSION_GRANTED; 324 } 325 } 326 return PackageManager.PERMISSION_DENIED; 327 } 328 329 @Implementation 330 public ActivityInfo getReceiverInfo(ComponentName className, int flags) throws NameNotFoundException { 331 String packageName = className.getPackageName(); 332 AndroidManifest androidManifest = androidManifests.get(packageName); 333 String classString = resolvePackageName(packageName, className); 334 335 for (PackageItemData receiver : androidManifest.getBroadcastReceivers()) { 336 if (receiver.getClassName().equals(classString)) { 337 ActivityInfo activityInfo = new ActivityInfo(); 338 activityInfo.packageName = packageName; 339 activityInfo.name = classString; 340 if ((flags & GET_META_DATA) != 0) { 341 activityInfo.metaData = metaDataToBundle(receiver.getMetaData().getValueMap()); 342 } 343 return activityInfo; 344 } 345 } 346 return null; 347 } 348 349 @Implementation 350 public List<ResolveInfo> queryBroadcastReceivers(Intent intent, int flags) { 351 return queryIntent(intent, flags); 352 } 353 354 @Implementation 355 public ResolveInfo resolveService(Intent intent, int flags) { 356 List<ResolveInfo> candidates = queryIntentActivities(intent, flags); 357 return candidates.isEmpty() ? null : candidates.get(0); 358 } 359 360 @Implementation 361 public ServiceInfo getServiceInfo(ComponentName className, int flags) throws NameNotFoundException { 362 String packageName = className.getPackageName(); 363 AndroidManifest androidManifest = androidManifests.get(packageName); 364 if (androidManifest != null) { 365 String serviceName = className.getClassName(); 366 ServiceData serviceData = androidManifest.getServiceData(serviceName); 367 if (serviceData == null) { 368 throw new NameNotFoundException(serviceName); 369 } 370 371 ServiceInfo serviceInfo = new ServiceInfo(); 372 serviceInfo.packageName = packageName; 373 serviceInfo.name = serviceName; 374 serviceInfo.applicationInfo = getApplicationInfo(packageName, flags); 375 serviceInfo.permission = serviceData.getPermission(); 376 if ((flags & GET_META_DATA) != 0) { 377 serviceInfo.metaData = metaDataToBundle(serviceData.getMetaData().getValueMap()); 378 } 379 return serviceInfo; 380 } 381 return null; 382 } 383 384 @Implementation 385 public Resources getResourcesForApplication(@NonNull ApplicationInfo applicationInfo) throws PackageManager.NameNotFoundException { 386 if (RuntimeEnvironment.application.getPackageName().equals(applicationInfo.packageName)) { 387 return RuntimeEnvironment.application.getResources(); 388 } else if (resources.containsKey(applicationInfo.packageName)) { 389 return resources.get(applicationInfo.packageName); 390 } 391 throw new NameNotFoundException(applicationInfo.packageName); 392 } 393 394 @Implementation 395 public List<ApplicationInfo> getInstalledApplications(int flags) { 396 List<ApplicationInfo> result = new LinkedList<>(); 397 398 for (PackageInfo packageInfo : packageInfos.values()) { 399 result.add(packageInfo.applicationInfo); 400 } 401 return result; 402 } 403 404 @Implementation 405 public String getInstallerPackageName(String packageName) { 406 return packageInstallerMap.get(packageName); 407 } 408 409 @Implementation 410 public PermissionInfo getPermissionInfo(String name, int flags) throws NameNotFoundException { 411 PermissionInfo permissionInfo = extraPermissions.get(name); 412 if (permissionInfo != null) { 413 return permissionInfo; 414 } 415 416 PermissionItemData permissionItemData = RuntimeEnvironment.getAppManifest().getPermissions().get( 417 name); 418 if (permissionItemData == null) { 419 throw new NameNotFoundException(name); 420 } 421 422 permissionInfo = createPermissionInfo(flags, permissionItemData); 423 424 return permissionInfo; 425 } 426 427 @Implementation(minSdk = M) 428 public boolean shouldShowRequestPermissionRationale(String permission) { 429 return permissionRationaleMap.containsKey(permission) ? permissionRationaleMap.get(permission) : false; 430 } 431 432 @Implementation 433 public FeatureInfo[] getSystemAvailableFeatures() { 434 return systemAvailableFeatures.isEmpty() ? null : systemAvailableFeatures.toArray(new FeatureInfo[systemAvailableFeatures.size()]); 435 } 436 437 @Implementation 438 public void verifyPendingInstall(int id, int verificationCode) { 439 if (verificationResults.containsKey(id)) { 440 throw new IllegalStateException("Multiple verifications for id=" + id); 441 } 442 verificationResults.put(id, verificationCode); 443 } 444 445 @Implementation 446 public void extendVerificationTimeout(int id, int verificationCodeAtTimeout, long millisecondsToDelay) { 447 verificationTimeoutExtension.put(id, millisecondsToDelay); 448 } 449 450 @Implementation 451 public void freeStorageAndNotify(long freeStorageSize, IPackageDataObserver observer) { 452 } 453 454 @Implementation 455 public void freeStorageAndNotify(String volumeUuid, long freeStorageSize, IPackageDataObserver observer) { 456 } 457 458 @Implementation 459 public void setInstallerPackageName(String targetPackage, String installerPackageName) { 460 packageInstallerMap.put(targetPackage, installerPackageName); 461 } 462 463 @Implementation 464 public List<ResolveInfo> queryIntentContentProviders(Intent intent, int flags) { 465 return Collections.emptyList(); 466 } 467 468 @Implementation 469 public List<ResolveInfo> queryIntentContentProvidersAsUser(Intent intent, int flags, int userId) { 470 return Collections.emptyList(); 471 } 472 473 @Implementation 474 public String getPermissionControllerPackageName() { 475 return null; 476 } 477 478 @Implementation(maxSdk = JELLY_BEAN) 479 public void getPackageSizeInfo(String packageName, final IPackageStatsObserver observer) { 480 final PackageStats packageStats = packageStatsMap.get(packageName); 481 new Handler(Looper.getMainLooper()).post(new Runnable() { 482 483 public void run() { 484 try { 485 observer.onGetStatsCompleted(packageStats, packageStats != null); 486 } catch (RemoteException remoteException) { 487 remoteException.rethrowFromSystemServer(); 488 } 489 } 490 }); 491 } 492 493 @Implementation(minSdk = JELLY_BEAN_MR1, maxSdk = M) 494 public void getPackageSizeInfo(String pkgName, int uid, final IPackageStatsObserver callback) { 495 final PackageStats packageStats = packageStatsMap.get(pkgName); 496 new Handler(Looper.getMainLooper()).post(new Runnable() { 497 498 public void run() { 499 try { 500 callback.onGetStatsCompleted(packageStats, packageStats != null); 501 } catch (RemoteException remoteException) { 502 remoteException.rethrowFromSystemServer(); 503 } 504 } 505 }); 506 } 507 508 @Implementation(minSdk = N) 509 public void getPackageSizeInfoAsUser(String pkgName, int uid, final IPackageStatsObserver callback) { 510 final PackageStats packageStats = packageStatsMap.get(pkgName); 511 new Handler(Looper.getMainLooper()).post(new Runnable() { 512 513 public void run() { 514 try { 515 callback.onGetStatsCompleted(packageStats, packageStats != null); 516 } catch (RemoteException remoteException) { 517 remoteException.rethrowFromSystemServer(); 518 } 519 } 520 }); 521 } 522 523 @Implementation 524 public void deletePackage(String packageName, IPackageDeleteObserver observer, int flags) { 525 pendingDeleteCallbacks.put(packageName, observer); 526 } 527 528 @Implementation 529 public String[] currentToCanonicalPackageNames(String[] names) { 530 String[] out = new String[names.length]; 531 for (int i = names.length - 1; i >= 0; i--) { 532 if (currentToCanonicalNames.containsKey(names[i])) { 533 out[i] = currentToCanonicalNames.get(names[i]); 534 } else { 535 out[i] = names[i]; 536 } 537 } 538 return out; 539 } 540 541 @Implementation 542 public boolean isSafeMode() { 543 return false; 544 } 545 546 @Implementation 547 public Drawable getApplicationIcon(String packageName) throws NameNotFoundException { 548 return applicationIcons.get(packageName); 549 } 550 551 @Implementation 552 public Drawable getApplicationIcon(ApplicationInfo info) { 553 return null; 554 } 555 556 @Implementation 557 public Drawable getUserBadgeForDensity(UserHandle userHandle, int i) { 558 return null; 559 } 560 561 @Implementation 562 public int checkSignatures(String pkg1, String pkg2) { 563 try { 564 PackageInfo packageInfo1 = getPackageInfo(pkg1, GET_SIGNATURES); 565 PackageInfo packageInfo2 = getPackageInfo(pkg2, GET_SIGNATURES); 566 return compareSignature(packageInfo1.signatures, packageInfo2.signatures); 567 } catch (NameNotFoundException e) { 568 return SIGNATURE_UNKNOWN_PACKAGE; 569 } 570 } 571 572 @Implementation 573 public int checkSignatures(int uid1, int uid2) { 574 return 0; 575 } 576 577 @Implementation 578 public List<PermissionInfo> queryPermissionsByGroup(String group, int flags) throws NameNotFoundException { 579 List<PermissionInfo> result = new LinkedList<>(); 580 for (PermissionInfo permissionInfo : extraPermissions.values()) { 581 if (Objects.equals(permissionInfo.group, group)) { 582 result.add(permissionInfo); 583 } 584 } 585 586 for (PermissionItemData permissionItemData : RuntimeEnvironment.getAppManifest().getPermissions().values()) { 587 if (Objects.equals(permissionItemData.getPermissionGroup(), group)) { 588 result.add(createPermissionInfo(flags, permissionItemData)); 589 } 590 } 591 592 return result; 593 } 594 595 public CharSequence getApplicationLabel(ApplicationInfo info) { 596 return info.name; 597 } 598 599 @Implementation 600 public Intent getLaunchIntentForPackage(String packageName) { 601 Intent intentToResolve = new Intent(Intent.ACTION_MAIN); 602 intentToResolve.addCategory(Intent.CATEGORY_INFO); 603 intentToResolve.setPackage(packageName); 604 List<ResolveInfo> ris = queryIntentActivities(intentToResolve, 0); 605 606 if (ris == null || ris.isEmpty()) { 607 intentToResolve.removeCategory(Intent.CATEGORY_INFO); 608 intentToResolve.addCategory(Intent.CATEGORY_LAUNCHER); 609 intentToResolve.setPackage(packageName); 610 ris = queryIntentActivities(intentToResolve, 0); 611 } 612 if (ris == null || ris.isEmpty()) { 613 return null; 614 } 615 Intent intent = new Intent(intentToResolve); 616 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 617 intent.setClassName(ris.get(0).activityInfo.packageName, ris.get(0).activityInfo.name); 618 return intent; 619 } 620 621 //////////////////////////// 622 623 @Implementation 624 public PackageInfo getPackageInfoAsUser(String packageName, int flags, int userId) 625 throws NameNotFoundException { 626 return null; 627 } 628 629 @Implementation 630 public String[] canonicalToCurrentPackageNames(String[] names) { 631 return new String[0]; 632 } 633 634 @Implementation 635 public Intent getLeanbackLaunchIntentForPackage(String packageName) { 636 return null; 637 } 638 639 @Implementation 640 public int[] getPackageGids(String packageName) throws NameNotFoundException { 641 return new int[0]; 642 } 643 644 @Implementation 645 public int[] getPackageGids(String packageName, int flags) throws NameNotFoundException { 646 return null; 647 } 648 649 @Implementation 650 public int getPackageUid(String packageName, int flags) throws NameNotFoundException { 651 return 0; 652 } 653 654 @Implementation 655 public int getPackageUidAsUser(String packageName, int userId) throws NameNotFoundException { 656 return 0; 657 } 658 659 @Implementation 660 public int getPackageUidAsUser(String packageName, int flags, int userId) 661 throws NameNotFoundException { 662 return 0; 663 } 664 665 @Implementation 666 public PermissionGroupInfo getPermissionGroupInfo(String name, int flags) 667 throws NameNotFoundException { 668 return null; 669 } 670 671 @Implementation 672 public List<PermissionGroupInfo> getAllPermissionGroups(int flags) { 673 return null; 674 } 675 676 @Implementation 677 public ApplicationInfo getApplicationInfo(String packageName, int flags) throws NameNotFoundException { 678 PackageInfo info = packageInfos.get(packageName); 679 if (info != null) { 680 try { 681 PackageInfo packageInfo = getPackageInfo(packageName, -1); 682 } catch (NameNotFoundException e) { 683 throw new IllegalArgumentException(e); 684 } 685 686 if (applicationEnabledSettingMap.get(packageName) == COMPONENT_ENABLED_STATE_DISABLED 687 && (flags & MATCH_UNINSTALLED_PACKAGES) != MATCH_UNINSTALLED_PACKAGES) { 688 throw new NameNotFoundException("Package is disabled, can't find"); 689 } 690 return info.applicationInfo; 691 } else { 692 throw new NameNotFoundException(packageName); 693 } 694 } 695 696 @Implementation 697 public String[] getSystemSharedLibraryNames() { 698 return new String[0]; 699 } 700 701 @Implementation 702 public 703 @NonNull 704 String getServicesSystemSharedLibraryPackageName() { 705 return null; 706 } 707 708 @Implementation 709 public 710 @NonNull 711 String getSharedSystemSharedLibraryPackageName() { 712 return ""; 713 } 714 715 @Implementation 716 public boolean hasSystemFeature(String name, int version) { 717 return false; 718 } 719 720 @Implementation 721 public boolean isPermissionRevokedByPolicy(String permName, String pkgName) { 722 return false; 723 } 724 725 @Implementation 726 public boolean addPermission(PermissionInfo info) { 727 return false; 728 } 729 730 @Implementation 731 public boolean addPermissionAsync(PermissionInfo info) { 732 return false; 733 } 734 735 @Implementation 736 public void removePermission(String name) { 737 } 738 739 @Implementation 740 public void grantRuntimePermission(String packageName, String permissionName, UserHandle user) { 741 } 742 743 @Implementation 744 public void revokeRuntimePermission(String packageName, String permissionName, UserHandle user) { 745 } 746 747 @Implementation 748 public int getPermissionFlags(String permissionName, String packageName, UserHandle user) { 749 return 0; 750 } 751 752 @Implementation 753 public void updatePermissionFlags(String permissionName, String packageName, int flagMask, 754 int flagValues, UserHandle user) { 755 } 756 757 @Implementation 758 public int getUidForSharedUser(String sharedUserName) throws NameNotFoundException { 759 return 0; 760 } 761 762 @Implementation 763 public List<PackageInfo> getInstalledPackagesAsUser(int flags, int userId) { 764 return null; 765 } 766 767 @Implementation 768 public List<PackageInfo> getPackagesHoldingPermissions(String[] permissions, int flags) { 769 return null; 770 } 771 772 @Implementation 773 public ResolveInfo resolveActivityAsUser(Intent intent, int flags, int userId) { 774 return null; 775 } 776 777 @Implementation 778 public List<ResolveInfo> queryIntentActivitiesAsUser(Intent intent, int flags, int userId) { 779 return null; 780 } 781 782 @Implementation 783 public List<ResolveInfo> queryIntentActivityOptions(ComponentName caller, Intent[] specifics, Intent intent, int flags) { 784 return null; 785 } 786 787 @Implementation 788 public List<ResolveInfo> queryBroadcastReceiversAsUser(Intent intent, int flags, int userId) { 789 return null; 790 } 791 792 @Implementation 793 public List<ResolveInfo> queryIntentServicesAsUser(Intent intent, int flags, int userId) { 794 return null; 795 } 796 797 @Implementation 798 public List<ProviderInfo> queryContentProviders(String processName, int uid, int flags) { 799 return null; 800 } 801 802 @Implementation 803 public InstrumentationInfo getInstrumentationInfo(ComponentName className, int flags) throws NameNotFoundException { 804 return null; 805 } 806 807 @Implementation 808 public List<InstrumentationInfo> queryInstrumentation(String targetPackage, int flags) { 809 return null; 810 } 811 812 @Override @Nullable 813 @Implementation 814 public Drawable getDrawable(String packageName, @DrawableRes int resId, @Nullable ApplicationInfo appInfo) { 815 return drawables.get(new Pair(packageName, resId)); 816 } 817 818 @Override @Implementation 819 public Drawable getActivityIcon(ComponentName activityName) throws NameNotFoundException { 820 return drawableList.get(activityName); 821 } 822 823 @Override public Drawable getActivityIcon(Intent intent) throws NameNotFoundException { 824 return drawableList.get(intent.getComponent()); 825 } 826 827 @Implementation 828 public Drawable getDefaultActivityIcon() { 829 return Resources.getSystem().getDrawable(com.android.internal.R.drawable.sym_def_app_icon); 830 } 831 832 @Implementation 833 public Drawable getActivityBanner(ComponentName activityName) throws NameNotFoundException { 834 return null; 835 } 836 837 @Implementation 838 public Drawable getActivityBanner(Intent intent) throws NameNotFoundException { 839 return null; 840 } 841 842 @Implementation 843 public Drawable getApplicationBanner(ApplicationInfo info) { 844 return null; 845 } 846 847 @Implementation 848 public Drawable getApplicationBanner(String packageName) throws NameNotFoundException { 849 return null; 850 } 851 852 @Implementation 853 public Drawable getActivityLogo(ComponentName activityName) throws NameNotFoundException { 854 return null; 855 } 856 857 @Implementation 858 public Drawable getActivityLogo(Intent intent) throws NameNotFoundException { 859 return null; 860 } 861 862 @Implementation 863 public Drawable getApplicationLogo(ApplicationInfo info) { 864 return null; 865 } 866 867 @Implementation 868 public Drawable getApplicationLogo(String packageName) throws NameNotFoundException { 869 return null; 870 } 871 872 @Implementation 873 public Drawable getUserBadgedIcon(Drawable icon, UserHandle user) { 874 return null; 875 } 876 877 @Implementation 878 public Drawable getUserBadgedDrawableForDensity(Drawable drawable, UserHandle user, Rect badgeLocation, int badgeDensity) { 879 return null; 880 } 881 882 @Implementation 883 public Drawable getUserBadgeForDensityNoBackground(UserHandle user, int density) { 884 return null; 885 } 886 887 @Implementation 888 public CharSequence getUserBadgedLabel(CharSequence label, UserHandle user) { 889 return null; 890 } 891 892 @Implementation 893 public Resources getResourcesForActivity(ComponentName activityName) throws NameNotFoundException { 894 return null; 895 } 896 897 @Implementation 898 public Resources getResourcesForApplication(String appPackageName) throws NameNotFoundException { 899 if (RuntimeEnvironment.application.getPackageName().equals(appPackageName)) { 900 return RuntimeEnvironment.application.getResources(); 901 } else if (resources.containsKey(appPackageName)) { 902 return resources.get(appPackageName); 903 } 904 throw new NameNotFoundException(appPackageName); 905 } 906 907 @Implementation 908 public Resources getResourcesForApplicationAsUser(String appPackageName, int userId) throws NameNotFoundException { 909 return null; 910 } 911 912 @Implementation 913 public void addOnPermissionsChangeListener(Object listener) { 914 } 915 916 @Implementation 917 public void removeOnPermissionsChangeListener(Object listener) { 918 } 919 920 @Implementation 921 public CharSequence getText(String packageName, @StringRes int resid, ApplicationInfo appInfo) { 922 return null; 923 } 924 925 @Implementation 926 public void installPackage(Uri packageURI, IPackageInstallObserver observer, int flags, String installerPackageName) { 927 } 928 929 @Implementation 930 public void installPackage(Object packageURI, Object observer, Object flags, Object installerPackageName) { 931 } 932 933 @Implementation 934 public int installExistingPackage(String packageName) throws NameNotFoundException { 935 return 0; 936 } 937 938 @Implementation 939 public int installExistingPackageAsUser(String packageName, int userId) throws NameNotFoundException { 940 return 0; 941 } 942 943 @Implementation 944 public void verifyIntentFilter(int id, int verificationCode, List<String> failedDomains) { 945 } 946 947 @Implementation 948 public int getIntentVerificationStatusAsUser(String packageName, int userId) { 949 return 0; 950 } 951 952 @Implementation 953 public boolean updateIntentVerificationStatusAsUser(String packageName, int status, int userId) { 954 return false; 955 } 956 957 @Implementation 958 public List<IntentFilterVerificationInfo> getIntentFilterVerifications(String packageName) { 959 return null; 960 } 961 962 @Implementation 963 public List<IntentFilter> getAllIntentFilters(String packageName) { 964 return null; 965 } 966 967 @Implementation 968 public String getDefaultBrowserPackageNameAsUser(int userId) { 969 return null; 970 } 971 972 @Implementation 973 public boolean setDefaultBrowserPackageNameAsUser(String packageName, int userId) { 974 return false; 975 } 976 977 @Implementation 978 public int getMoveStatus(int moveId) { 979 return 0; 980 } 981 982 @Implementation 983 public void registerMoveCallback(Object callback, Object handler) { 984 } 985 986 @Implementation 987 public void unregisterMoveCallback(Object callback) { 988 } 989 990 @Implementation 991 public Object movePackage(Object packageName, Object vol) { 992 return 0; 993 } 994 995 @Implementation 996 public Object getPackageCurrentVolume(Object app) { 997 return null; 998 } 999 1000 @Implementation 1001 public List<VolumeInfo> getPackageCandidateVolumes(ApplicationInfo app) { 1002 return null; 1003 } 1004 1005 @Implementation 1006 public Object movePrimaryStorage(Object vol) { 1007 return 0; 1008 } 1009 1010 @Implementation 1011 public @Nullable Object getPrimaryStorageCurrentVolume() { 1012 return null; 1013 } 1014 1015 @Implementation 1016 public @NonNull List<VolumeInfo> getPrimaryStorageCandidateVolumes() { 1017 return null; 1018 } 1019 1020 @Implementation 1021 public void deletePackageAsUser(String packageName, IPackageDeleteObserver observer, int flags, int userId) { 1022 } 1023 1024 @Implementation 1025 public void clearApplicationUserData(String packageName, IPackageDataObserver observer) { 1026 } 1027 1028 @Implementation 1029 public void deleteApplicationCacheFiles(String packageName, IPackageDataObserver observer) { 1030 } 1031 1032 @Implementation 1033 public void deleteApplicationCacheFilesAsUser(String packageName, int userId, IPackageDataObserver observer) { 1034 } 1035 1036 @Implementation 1037 public void freeStorage(String volumeUuid, long freeStorageSize, IntentSender pi) { 1038 } 1039 1040 @Implementation 1041 public String[] setPackagesSuspendedAsUser(String[] packageNames, boolean suspended, int userId) { 1042 return null; 1043 } 1044 1045 @Implementation 1046 public boolean isPackageSuspendedForUser(String packageName, int userId) { 1047 return false; 1048 } 1049 1050 @Implementation 1051 public void addPackageToPreferred(String packageName) { 1052 } 1053 1054 @Implementation 1055 public void removePackageFromPreferred(String packageName) { 1056 } 1057 1058 @Implementation 1059 public List<PackageInfo> getPreferredPackages(int flags) { 1060 return null; 1061 } 1062 1063 @Override public void addPreferredActivity(IntentFilter filter, int match, ComponentName[] set, ComponentName activity) { 1064 preferredActivities.put(filter, activity); 1065 } 1066 1067 @Implementation 1068 public void replacePreferredActivity(IntentFilter filter, int match, ComponentName[] set, ComponentName activity) { 1069 } 1070 1071 @Implementation 1072 public void clearPackagePreferredActivities(String packageName) { 1073 } 1074 1075 @Override public int getPreferredActivities(List<IntentFilter> outFilters, 1076 List<ComponentName> outActivities, String packageName) { 1077 if (outFilters == null) { 1078 return 0; 1079 } 1080 1081 Set<IntentFilter> filters = preferredActivities.keySet(); 1082 for (IntentFilter filter : outFilters) { 1083 step: 1084 for (IntentFilter testFilter : filters) { 1085 ComponentName name = preferredActivities.get(testFilter); 1086 // filter out based on the given packageName; 1087 if (packageName != null && !name.getPackageName().equals(packageName)) { 1088 continue step; 1089 } 1090 1091 // Check actions 1092 Iterator<String> iterator = filter.actionsIterator(); 1093 while (iterator.hasNext()) { 1094 if (!testFilter.matchAction(iterator.next())) { 1095 continue step; 1096 } 1097 } 1098 1099 iterator = filter.categoriesIterator(); 1100 while (iterator.hasNext()) { 1101 if (!filter.hasCategory(iterator.next())) { 1102 continue step; 1103 } 1104 } 1105 1106 if (outActivities == null) { 1107 outActivities = new ArrayList<>(); 1108 } 1109 1110 outActivities.add(name); 1111 } 1112 } 1113 1114 return 0; 1115 } 1116 1117 @Implementation 1118 public ComponentName getHomeActivities(List<ResolveInfo> outActivities) { 1119 return null; 1120 } 1121 1122 @Implementation 1123 public void flushPackageRestrictionsAsUser(int userId) { 1124 } 1125 1126 @Implementation 1127 public boolean setApplicationHiddenSettingAsUser(String packageName, boolean hidden, UserHandle user) { 1128 return false; 1129 } 1130 1131 @Implementation 1132 public boolean getApplicationHiddenSettingAsUser(String packageName, UserHandle user) { 1133 return false; 1134 } 1135 1136 @Implementation 1137 public Object getKeySetByAlias(String packageName, String alias) { 1138 return null; 1139 } 1140 1141 @Implementation 1142 public Object getSigningKeySet(String packageName) { 1143 return null; 1144 } 1145 1146 @Implementation 1147 public boolean isSignedBy(String packageName, Object ks) { 1148 return false; 1149 } 1150 1151 @Implementation 1152 public boolean isSignedByExactly(String packageName, Object ks) { 1153 return false; 1154 } 1155 1156 @Implementation 1157 public VerifierDeviceIdentity getVerifierDeviceIdentity() { 1158 return null; 1159 } 1160 1161 @Implementation 1162 public boolean isUpgrade() { 1163 return false; 1164 } 1165 1166 @Implementation 1167 public boolean isPackageAvailable(String packageName) { 1168 return false; 1169 } 1170 1171 @Implementation 1172 public void addCrossProfileIntentFilter(IntentFilter filter, int sourceUserId, int targetUserId, int flags) { 1173 } 1174 1175 @Implementation 1176 public void clearCrossProfileIntentFilters(int sourceUserId) { 1177 } 1178 1179 @Implementation 1180 public Drawable loadItemIcon(PackageItemInfo itemInfo, ApplicationInfo appInfo) { 1181 return null; 1182 } 1183 1184 @Implementation 1185 public Drawable loadUnbadgedItemIcon(PackageItemInfo itemInfo, ApplicationInfo appInfo) { 1186 return null; 1187 } 1188} 1189