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