1 /* 2 * Copyright (C) 2008 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 17 package android.test.mock; 18 19 import android.content.ComponentName; 20 import android.content.Intent; 21 import android.content.IntentFilter; 22 import android.content.IntentSender; 23 import android.content.pm.ActivityInfo; 24 import android.content.pm.ApplicationInfo; 25 import android.content.pm.ContainerEncryptionParams; 26 import android.content.pm.FeatureInfo; 27 import android.content.pm.IPackageDataObserver; 28 import android.content.pm.IPackageDeleteObserver; 29 import android.content.pm.IPackageInstallObserver; 30 import android.content.pm.IPackageMoveObserver; 31 import android.content.pm.IPackageStatsObserver; 32 import android.content.pm.InstrumentationInfo; 33 import android.content.pm.ManifestDigest; 34 import android.content.pm.PackageInfo; 35 import android.content.pm.PackageManager; 36 import android.content.pm.PermissionGroupInfo; 37 import android.content.pm.PermissionInfo; 38 import android.content.pm.ProviderInfo; 39 import android.content.pm.ResolveInfo; 40 import android.content.pm.ServiceInfo; 41 import android.content.pm.VerificationParams; 42 import android.content.pm.VerifierDeviceIdentity; 43 import android.content.pm.PackageManager.NameNotFoundException; 44 import android.content.res.Resources; 45 import android.content.res.XmlResourceParser; 46 import android.graphics.drawable.Drawable; 47 import android.net.Uri; 48 import android.os.Binder; 49 import android.os.RemoteException; 50 import android.os.UserHandle; 51 52 import java.util.List; 53 54 /** 55 * A mock {@link android.content.pm.PackageManager} class. All methods are non-functional and throw 56 * {@link java.lang.UnsupportedOperationException}. Override it to provide the operations that you 57 * need. 58 */ 59 public class MockPackageManager extends PackageManager { 60 61 @Override 62 public PackageInfo getPackageInfo(String packageName, int flags) 63 throws NameNotFoundException { 64 throw new UnsupportedOperationException(); 65 } 66 67 @Override 68 public String[] currentToCanonicalPackageNames(String[] names) { 69 throw new UnsupportedOperationException(); 70 } 71 72 @Override 73 public String[] canonicalToCurrentPackageNames(String[] names) { 74 throw new UnsupportedOperationException(); 75 } 76 77 @Override 78 public Intent getLaunchIntentForPackage(String packageName) { 79 throw new UnsupportedOperationException(); 80 } 81 82 @Override 83 public int[] getPackageGids(String packageName) throws NameNotFoundException { 84 throw new UnsupportedOperationException(); 85 } 86 87 /** @hide */ 88 @Override 89 public int getPackageUid(String packageName, int userHandle) 90 throws NameNotFoundException { 91 throw new UnsupportedOperationException(); 92 } 93 94 @Override 95 public PermissionInfo getPermissionInfo(String name, int flags) 96 throws NameNotFoundException { 97 throw new UnsupportedOperationException(); 98 } 99 100 @Override 101 public List<PermissionInfo> queryPermissionsByGroup(String group, int flags) 102 throws NameNotFoundException { 103 throw new UnsupportedOperationException(); 104 } 105 106 @Override 107 public PermissionGroupInfo getPermissionGroupInfo(String name, 108 int flags) throws NameNotFoundException { 109 throw new UnsupportedOperationException(); 110 } 111 112 @Override 113 public List<PermissionGroupInfo> getAllPermissionGroups(int flags) { 114 throw new UnsupportedOperationException(); 115 } 116 117 @Override 118 public ApplicationInfo getApplicationInfo(String packageName, int flags) 119 throws NameNotFoundException { 120 throw new UnsupportedOperationException(); 121 } 122 123 @Override 124 public ActivityInfo getActivityInfo(ComponentName className, int flags) 125 throws NameNotFoundException { 126 throw new UnsupportedOperationException(); 127 } 128 129 @Override 130 public ActivityInfo getReceiverInfo(ComponentName className, int flags) 131 throws NameNotFoundException { 132 throw new UnsupportedOperationException(); 133 } 134 135 @Override 136 public ServiceInfo getServiceInfo(ComponentName className, int flags) 137 throws NameNotFoundException { 138 throw new UnsupportedOperationException(); 139 } 140 141 @Override 142 public ProviderInfo getProviderInfo(ComponentName className, int flags) 143 throws NameNotFoundException { 144 throw new UnsupportedOperationException(); 145 } 146 147 @Override 148 public List<PackageInfo> getInstalledPackages(int flags) { 149 throw new UnsupportedOperationException(); 150 } 151 152 @Override 153 public List<PackageInfo> getPackagesHoldingPermissions(String[] permissions, 154 int flags) { 155 throw new UnsupportedOperationException(); 156 } 157 158 /** @hide */ 159 @Override 160 public List<PackageInfo> getInstalledPackages(int flags, int userId) { 161 throw new UnsupportedOperationException(); 162 } 163 164 @Override 165 public int checkPermission(String permName, String pkgName) { 166 throw new UnsupportedOperationException(); 167 } 168 169 @Override 170 public boolean addPermission(PermissionInfo info) { 171 throw new UnsupportedOperationException(); 172 } 173 174 @Override 175 public boolean addPermissionAsync(PermissionInfo info) { 176 throw new UnsupportedOperationException(); 177 } 178 179 @Override 180 public void removePermission(String name) { 181 throw new UnsupportedOperationException(); 182 } 183 184 /** @hide */ 185 @Override 186 public void grantPermission(String packageName, String permissionName) { 187 throw new UnsupportedOperationException(); 188 } 189 190 /** @hide */ 191 @Override 192 public void revokePermission(String packageName, String permissionName) { 193 throw new UnsupportedOperationException(); 194 } 195 196 @Override 197 public int checkSignatures(String pkg1, String pkg2) { 198 throw new UnsupportedOperationException(); 199 } 200 201 @Override 202 public int checkSignatures(int uid1, int uid2) { 203 throw new UnsupportedOperationException(); 204 } 205 206 @Override 207 public String[] getPackagesForUid(int uid) { 208 throw new UnsupportedOperationException(); 209 } 210 211 @Override 212 public String getNameForUid(int uid) { 213 throw new UnsupportedOperationException(); 214 } 215 216 /** 217 * @hide - to match hiding in superclass 218 */ 219 @Override 220 public int getUidForSharedUser(String sharedUserName) { 221 throw new UnsupportedOperationException(); 222 } 223 224 @Override 225 public List<ApplicationInfo> getInstalledApplications(int flags) { 226 throw new UnsupportedOperationException(); 227 } 228 229 @Override 230 public ResolveInfo resolveActivity(Intent intent, int flags) { 231 throw new UnsupportedOperationException(); 232 } 233 234 /** @hide */ 235 @Override 236 public ResolveInfo resolveActivityAsUser(Intent intent, int flags, int userId) { 237 throw new UnsupportedOperationException(); 238 } 239 240 @Override 241 public List<ResolveInfo> queryIntentActivities(Intent intent, int flags) { 242 throw new UnsupportedOperationException(); 243 } 244 245 /** @hide */ 246 @Override 247 public List<ResolveInfo> queryIntentActivitiesAsUser(Intent intent, 248 int flags, int userId) { 249 throw new UnsupportedOperationException(); 250 } 251 252 @Override 253 public List<ResolveInfo> queryIntentActivityOptions(ComponentName caller, 254 Intent[] specifics, Intent intent, int flags) { 255 throw new UnsupportedOperationException(); 256 } 257 258 @Override 259 public List<ResolveInfo> queryBroadcastReceivers(Intent intent, int flags) { 260 throw new UnsupportedOperationException(); 261 } 262 263 /** @hide */ 264 @Override 265 public List<ResolveInfo> queryBroadcastReceivers(Intent intent, int flags, int userId) { 266 throw new UnsupportedOperationException(); 267 } 268 269 @Override 270 public ResolveInfo resolveService(Intent intent, int flags) { 271 throw new UnsupportedOperationException(); 272 } 273 274 @Override 275 public List<ResolveInfo> queryIntentServices(Intent intent, int flags) { 276 throw new UnsupportedOperationException(); 277 } 278 279 /** @hide */ 280 @Override 281 public List<ResolveInfo> queryIntentServicesAsUser(Intent intent, int flags, int userId) { 282 throw new UnsupportedOperationException(); 283 } 284 285 /** @hide */ 286 @Override 287 public List<ResolveInfo> queryIntentContentProvidersAsUser( 288 Intent intent, int flags, int userId) { 289 throw new UnsupportedOperationException(); 290 } 291 292 @Override 293 public List<ResolveInfo> queryIntentContentProviders(Intent intent, int flags) { 294 throw new UnsupportedOperationException(); 295 } 296 297 @Override 298 public ProviderInfo resolveContentProvider(String name, int flags) { 299 throw new UnsupportedOperationException(); 300 } 301 302 @Override 303 public List<ProviderInfo> queryContentProviders(String processName, int uid, int flags) { 304 throw new UnsupportedOperationException(); 305 } 306 307 @Override 308 public InstrumentationInfo getInstrumentationInfo(ComponentName className, int flags) 309 throws NameNotFoundException { 310 throw new UnsupportedOperationException(); 311 } 312 313 @Override 314 public List<InstrumentationInfo> queryInstrumentation( 315 String targetPackage, int flags) { 316 throw new UnsupportedOperationException(); 317 } 318 319 @Override 320 public Drawable getDrawable(String packageName, int resid, ApplicationInfo appInfo) { 321 throw new UnsupportedOperationException(); 322 } 323 324 @Override 325 public Drawable getActivityIcon(ComponentName activityName) 326 throws NameNotFoundException { 327 throw new UnsupportedOperationException(); 328 } 329 330 @Override 331 public Drawable getActivityIcon(Intent intent) throws NameNotFoundException { 332 throw new UnsupportedOperationException(); 333 } 334 335 @Override 336 public Drawable getDefaultActivityIcon() { 337 throw new UnsupportedOperationException(); 338 } 339 340 @Override 341 public Drawable getApplicationIcon(ApplicationInfo info) { 342 throw new UnsupportedOperationException(); 343 } 344 345 @Override 346 public Drawable getApplicationIcon(String packageName) throws NameNotFoundException { 347 throw new UnsupportedOperationException(); 348 } 349 350 @Override 351 public Drawable getActivityLogo(ComponentName activityName) throws NameNotFoundException { 352 throw new UnsupportedOperationException(); 353 } 354 355 @Override 356 public Drawable getActivityLogo(Intent intent) throws NameNotFoundException { 357 throw new UnsupportedOperationException(); 358 } 359 360 @Override 361 public Drawable getApplicationLogo(ApplicationInfo info) { 362 throw new UnsupportedOperationException(); 363 } 364 365 @Override 366 public Drawable getApplicationLogo(String packageName) throws NameNotFoundException { 367 throw new UnsupportedOperationException(); 368 } 369 370 @Override 371 public CharSequence getText(String packageName, int resid, ApplicationInfo appInfo) { 372 throw new UnsupportedOperationException(); 373 } 374 375 @Override 376 public XmlResourceParser getXml(String packageName, int resid, 377 ApplicationInfo appInfo) { 378 throw new UnsupportedOperationException(); 379 } 380 381 @Override 382 public CharSequence getApplicationLabel(ApplicationInfo info) { 383 throw new UnsupportedOperationException(); 384 } 385 386 @Override 387 public Resources getResourcesForActivity(ComponentName activityName) 388 throws NameNotFoundException { 389 throw new UnsupportedOperationException(); 390 } 391 392 @Override 393 public Resources getResourcesForApplication(ApplicationInfo app) { 394 throw new UnsupportedOperationException(); 395 } 396 397 @Override 398 public Resources getResourcesForApplication(String appPackageName) 399 throws NameNotFoundException { 400 throw new UnsupportedOperationException(); 401 } 402 403 /** @hide */ 404 @Override 405 public Resources getResourcesForApplicationAsUser(String appPackageName, int userId) { 406 throw new UnsupportedOperationException(); 407 } 408 409 @Override 410 public PackageInfo getPackageArchiveInfo(String archiveFilePath, int flags) { 411 throw new UnsupportedOperationException(); 412 } 413 414 /** 415 * @hide - to match hiding in superclass 416 */ 417 @Override 418 public void installPackage(Uri packageURI, IPackageInstallObserver observer, 419 int flags, String installerPackageName) { 420 throw new UnsupportedOperationException(); 421 } 422 423 @Override 424 public void setInstallerPackageName(String targetPackage, 425 String installerPackageName) { 426 throw new UnsupportedOperationException(); 427 } 428 429 /** 430 * @hide - to match hiding in superclass 431 */ 432 @Override 433 public void movePackage(String packageName, IPackageMoveObserver observer, int flags) { 434 throw new UnsupportedOperationException(); 435 } 436 437 @Override 438 public String getInstallerPackageName(String packageName) { 439 throw new UnsupportedOperationException(); 440 } 441 442 /** 443 * @hide - to match hiding in superclass 444 */ 445 @Override 446 public void clearApplicationUserData( 447 String packageName, IPackageDataObserver observer) { 448 throw new UnsupportedOperationException(); 449 } 450 451 /** 452 * @hide - to match hiding in superclass 453 */ 454 @Override 455 public void deleteApplicationCacheFiles( 456 String packageName, IPackageDataObserver observer) { 457 throw new UnsupportedOperationException(); 458 } 459 460 /** 461 * @hide - to match hiding in superclass 462 */ 463 @Override 464 public void freeStorageAndNotify( 465 long idealStorageSize, IPackageDataObserver observer) { 466 throw new UnsupportedOperationException(); 467 } 468 469 /** 470 * @hide - to match hiding in superclass 471 */ 472 @Override 473 public void freeStorage( 474 long idealStorageSize, IntentSender pi) { 475 throw new UnsupportedOperationException(); 476 } 477 478 /** 479 * @hide - to match hiding in superclass 480 */ 481 @Override 482 public void deletePackage( 483 String packageName, IPackageDeleteObserver observer, int flags) { 484 throw new UnsupportedOperationException(); 485 } 486 487 @Override 488 public void addPackageToPreferred(String packageName) { 489 throw new UnsupportedOperationException(); 490 } 491 492 @Override 493 public void removePackageFromPreferred(String packageName) { 494 throw new UnsupportedOperationException(); 495 } 496 497 @Override 498 public List<PackageInfo> getPreferredPackages(int flags) { 499 throw new UnsupportedOperationException(); 500 } 501 502 @Override 503 public void setComponentEnabledSetting(ComponentName componentName, 504 int newState, int flags) { 505 throw new UnsupportedOperationException(); 506 } 507 508 @Override 509 public int getComponentEnabledSetting(ComponentName componentName) { 510 throw new UnsupportedOperationException(); 511 } 512 513 @Override 514 public void setApplicationEnabledSetting(String packageName, int newState, int flags) { 515 throw new UnsupportedOperationException(); 516 } 517 518 @Override 519 public int getApplicationEnabledSetting(String packageName) { 520 throw new UnsupportedOperationException(); 521 } 522 523 @Override 524 public void addPreferredActivity(IntentFilter filter, 525 int match, ComponentName[] set, ComponentName activity) { 526 throw new UnsupportedOperationException(); 527 } 528 529 /** 530 * @hide - to match hiding in superclass 531 */ 532 @Override 533 public void replacePreferredActivity(IntentFilter filter, 534 int match, ComponentName[] set, ComponentName activity) { 535 throw new UnsupportedOperationException(); 536 } 537 538 539 @Override 540 public void clearPackagePreferredActivities(String packageName) { 541 throw new UnsupportedOperationException(); 542 } 543 544 /** 545 * @hide - to match hiding in superclass 546 */ 547 @Override 548 public void getPackageSizeInfo(String packageName, int userHandle, 549 IPackageStatsObserver observer) { 550 throw new UnsupportedOperationException(); 551 } 552 553 @Override 554 public int getPreferredActivities(List<IntentFilter> outFilters, 555 List<ComponentName> outActivities, String packageName) { 556 throw new UnsupportedOperationException(); 557 } 558 559 /** @hide - hidden in superclass */ 560 @Override 561 public ComponentName getHomeActivities(List<ResolveInfo> outActivities) { 562 throw new UnsupportedOperationException(); 563 } 564 565 @Override 566 public String[] getSystemSharedLibraryNames() { 567 throw new UnsupportedOperationException(); 568 } 569 570 @Override 571 public FeatureInfo[] getSystemAvailableFeatures() { 572 throw new UnsupportedOperationException(); 573 } 574 575 @Override 576 public boolean hasSystemFeature(String name) { 577 throw new UnsupportedOperationException(); 578 } 579 580 @Override 581 public boolean isSafeMode() { 582 throw new UnsupportedOperationException(); 583 } 584 585 /** 586 * @hide 587 */ 588 @Override 589 public void installPackageWithVerification(Uri packageURI, IPackageInstallObserver observer, 590 int flags, String installerPackageName, Uri verificationURI, 591 ManifestDigest manifestDigest, ContainerEncryptionParams encryptionParams) { 592 throw new UnsupportedOperationException(); 593 } 594 595 /** 596 * @hide 597 */ 598 @Override 599 public void installPackageWithVerificationAndEncryption(Uri packageURI, 600 IPackageInstallObserver observer, int flags, String installerPackageName, 601 VerificationParams verificationParams, ContainerEncryptionParams encryptionParams) { 602 throw new UnsupportedOperationException(); 603 } 604 605 /** 606 * @hide 607 */ 608 @Override 609 public boolean setApplicationBlockedSettingAsUser(String packageName, boolean blocked, 610 UserHandle user) { 611 return false; 612 } 613 614 /** 615 * @hide 616 */ 617 @Override 618 public boolean getApplicationBlockedSettingAsUser(String packageName, UserHandle user) { 619 return false; 620 } 621 622 /** 623 * @hide 624 */ 625 @Override 626 public int installExistingPackage(String packageName) 627 throws NameNotFoundException { 628 throw new UnsupportedOperationException(); 629 } 630 631 @Override 632 public void verifyPendingInstall(int id, int verificationCode) { 633 throw new UnsupportedOperationException(); 634 } 635 636 @Override 637 public void extendVerificationTimeout(int id, int verificationCodeAtTimeout, 638 long millisecondsToDelay) { 639 throw new UnsupportedOperationException(); 640 } 641 642 /** 643 * @hide 644 */ 645 @Override 646 public VerifierDeviceIdentity getVerifierDeviceIdentity() { 647 throw new UnsupportedOperationException(); 648 } 649 } 650