2 * Copyright (C) 2007 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package android.test.mock;
19 import android.annotation.SystemApi;
20 import android.app.IApplicationThread;
21 import android.app.IServiceConnection;
22 import android.app.Notification;
23 import android.content.ComponentName;
24 import android.content.ContentResolver;
25 import android.content.Context;
26 import android.content.Intent;
27 import android.content.IntentFilter;
28 import android.content.BroadcastReceiver;
29 import android.content.IntentSender;
30 import android.content.ServiceConnection;
31 import android.content.SharedPreferences;
32 import android.content.pm.ApplicationInfo;
33 import android.content.pm.PackageManager;
34 import android.content.res.AssetManager;
35 import android.content.res.Configuration;
36 import android.content.res.Resources;
37 import android.database.DatabaseErrorHandler;
38 import android.database.sqlite.SQLiteDatabase;
39 import android.graphics.Bitmap;
40 import android.graphics.drawable.Drawable;
41 import android.net.Uri;
42 import android.os.Bundle;
43 import android.os.Handler;
44 import android.os.IBinder;
45 import android.os.Looper;
46 import android.os.UserHandle;
47 import android.view.DisplayAdjustments;
48 import android.view.Display;
51 import java.io.FileInputStream;
52 import java.io.FileNotFoundException;
53 import java.io.FileOutputStream;
54 import java.io.IOException;
55 import java.io.InputStream;
58 * A mock {@link android.content.Context} class. All methods are non-functional and throw
59 * {@link java.lang.UnsupportedOperationException}. You can use this to inject other dependencies,
60 * mocks, or monitors into the classes you are testing.
62 public class MockContext extends Context {
65 public AssetManager getAssets() {
66 throw new UnsupportedOperationException();
70 public Resources getResources() {
71 throw new UnsupportedOperationException();
75 public PackageManager getPackageManager() {
76 throw new UnsupportedOperationException();
80 public ContentResolver getContentResolver() {
81 throw new UnsupportedOperationException();
85 public Looper getMainLooper() {
86 throw new UnsupportedOperationException();
90 public Context getApplicationContext() {
91 throw new UnsupportedOperationException();
95 public void setTheme(int resid) {
96 throw new UnsupportedOperationException();
100 public Resources.Theme getTheme() {
101 throw new UnsupportedOperationException();
105 public ClassLoader getClassLoader() {
106 throw new UnsupportedOperationException();
110 public String getPackageName() {
111 throw new UnsupportedOperationException();
116 public String getBasePackageName() {
117 throw new UnsupportedOperationException();
122 public String getOpPackageName() {
123 throw new UnsupportedOperationException();
127 public ApplicationInfo getApplicationInfo() {
128 throw new UnsupportedOperationException();
132 public String getPackageResourcePath() {
133 throw new UnsupportedOperationException();
137 public String getPackageCodePath() {
138 throw new UnsupportedOperationException();
142 public SharedPreferences getSharedPreferences(String name, int mode) {
143 throw new UnsupportedOperationException();
148 public SharedPreferences getSharedPreferences(File file, int mode) {
149 throw new UnsupportedOperationException();
154 public void reloadSharedPreferences() {
155 throw new UnsupportedOperationException();
159 public boolean moveSharedPreferencesFrom(Context sourceContext, String name) {
160 throw new UnsupportedOperationException();
164 public boolean deleteSharedPreferences(String name) {
165 throw new UnsupportedOperationException();
169 public FileInputStream openFileInput(String name) throws FileNotFoundException {
170 throw new UnsupportedOperationException();
174 public FileOutputStream openFileOutput(String name, int mode) throws FileNotFoundException {
175 throw new UnsupportedOperationException();
179 public boolean deleteFile(String name) {
180 throw new UnsupportedOperationException();
184 public File getFileStreamPath(String name) {
185 throw new UnsupportedOperationException();
190 public File getSharedPreferencesPath(String name) {
191 throw new UnsupportedOperationException();
195 public String[] fileList() {
196 throw new UnsupportedOperationException();
200 public File getDataDir() {
201 throw new UnsupportedOperationException();
205 public File getFilesDir() {
206 throw new UnsupportedOperationException();
210 public File getNoBackupFilesDir() {
211 throw new UnsupportedOperationException();
215 public File getExternalFilesDir(String type) {
216 throw new UnsupportedOperationException();
220 public File getObbDir() {
221 throw new UnsupportedOperationException();
225 public File getCacheDir() {
226 throw new UnsupportedOperationException();
230 public File getCodeCacheDir() {
231 throw new UnsupportedOperationException();
235 public File getExternalCacheDir() {
236 throw new UnsupportedOperationException();
240 public File getDir(String name, int mode) {
241 throw new UnsupportedOperationException();
245 public SQLiteDatabase openOrCreateDatabase(String file, int mode,
246 SQLiteDatabase.CursorFactory factory) {
247 throw new UnsupportedOperationException();
251 public SQLiteDatabase openOrCreateDatabase(String file, int mode,
252 SQLiteDatabase.CursorFactory factory, DatabaseErrorHandler errorHandler) {
253 throw new UnsupportedOperationException();
257 public File getDatabasePath(String name) {
258 throw new UnsupportedOperationException();
262 public String[] databaseList() {
263 throw new UnsupportedOperationException();
267 public boolean moveDatabaseFrom(Context sourceContext, String name) {
268 throw new UnsupportedOperationException();
272 public boolean deleteDatabase(String name) {
273 throw new UnsupportedOperationException();
277 public Drawable getWallpaper() {
278 throw new UnsupportedOperationException();
282 public Drawable peekWallpaper() {
283 throw new UnsupportedOperationException();
287 public int getWallpaperDesiredMinimumWidth() {
288 throw new UnsupportedOperationException();
292 public int getWallpaperDesiredMinimumHeight() {
293 throw new UnsupportedOperationException();
297 public void setWallpaper(Bitmap bitmap) throws IOException {
298 throw new UnsupportedOperationException();
302 public void setWallpaper(InputStream data) throws IOException {
303 throw new UnsupportedOperationException();
307 public void clearWallpaper() {
308 throw new UnsupportedOperationException();
312 public void startActivity(Intent intent) {
313 throw new UnsupportedOperationException();
317 public void startActivity(Intent intent, Bundle options) {
318 startActivity(intent);
322 public void startActivities(Intent[] intents) {
323 throw new UnsupportedOperationException();
327 public void startActivities(Intent[] intents, Bundle options) {
328 startActivities(intents);
332 public void startIntentSender(IntentSender intent,
333 Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags)
334 throws IntentSender.SendIntentException {
335 throw new UnsupportedOperationException();
339 public void startIntentSender(IntentSender intent,
340 Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags,
341 Bundle options) throws IntentSender.SendIntentException {
342 startIntentSender(intent, fillInIntent, flagsMask, flagsValues, extraFlags);
346 public void sendBroadcast(Intent intent) {
347 throw new UnsupportedOperationException();
351 public void sendBroadcast(Intent intent, String receiverPermission) {
352 throw new UnsupportedOperationException();
357 public void sendBroadcastMultiplePermissions(Intent intent, String[] receiverPermissions) {
358 throw new UnsupportedOperationException();
364 public void sendBroadcast(Intent intent, String receiverPermission, Bundle options) {
365 throw new UnsupportedOperationException();
370 public void sendBroadcast(Intent intent, String receiverPermission, int appOp) {
371 throw new UnsupportedOperationException();
375 public void sendOrderedBroadcast(Intent intent,
376 String receiverPermission) {
377 throw new UnsupportedOperationException();
381 public void sendOrderedBroadcast(Intent intent, String receiverPermission,
382 BroadcastReceiver resultReceiver, Handler scheduler, int initialCode, String initialData,
383 Bundle initialExtras) {
384 throw new UnsupportedOperationException();
390 public void sendOrderedBroadcast(Intent intent, String receiverPermission,
391 Bundle options, BroadcastReceiver resultReceiver, Handler scheduler, int initialCode, String initialData,
392 Bundle initialExtras) {
393 throw new UnsupportedOperationException();
398 public void sendOrderedBroadcast(Intent intent, String receiverPermission, int appOp,
399 BroadcastReceiver resultReceiver, Handler scheduler, int initialCode, String initialData,
400 Bundle initialExtras) {
401 throw new UnsupportedOperationException();
405 public void sendBroadcastAsUser(Intent intent, UserHandle user) {
406 throw new UnsupportedOperationException();
410 public void sendBroadcastAsUser(Intent intent, UserHandle user,
411 String receiverPermission) {
412 throw new UnsupportedOperationException();
418 public void sendBroadcastAsUser(Intent intent, UserHandle user,
419 String receiverPermission, Bundle options) {
420 throw new UnsupportedOperationException();
425 public void sendBroadcastAsUser(Intent intent, UserHandle user,
426 String receiverPermission, int appOp) {
427 throw new UnsupportedOperationException();
431 public void sendOrderedBroadcastAsUser(Intent intent, UserHandle user,
432 String receiverPermission, BroadcastReceiver resultReceiver, Handler scheduler,
433 int initialCode, String initialData, Bundle initialExtras) {
434 throw new UnsupportedOperationException();
439 public void sendOrderedBroadcastAsUser(Intent intent, UserHandle user,
440 String receiverPermission, int appOp, BroadcastReceiver resultReceiver,
441 Handler scheduler, int initialCode, String initialData, Bundle initialExtras) {
442 throw new UnsupportedOperationException();
447 public void sendOrderedBroadcastAsUser(Intent intent, UserHandle user,
448 String receiverPermission, int appOp, Bundle options, BroadcastReceiver resultReceiver,
449 Handler scheduler, int initialCode, String initialData, Bundle initialExtras) {
450 throw new UnsupportedOperationException();
454 public void sendStickyBroadcast(Intent intent) {
455 throw new UnsupportedOperationException();
459 public void sendStickyOrderedBroadcast(Intent intent,
460 BroadcastReceiver resultReceiver, Handler scheduler, int initialCode, String initialData,
461 Bundle initialExtras) {
462 throw new UnsupportedOperationException();
466 public void removeStickyBroadcast(Intent intent) {
467 throw new UnsupportedOperationException();
471 public void sendStickyBroadcastAsUser(Intent intent, UserHandle user) {
472 throw new UnsupportedOperationException();
477 public void sendStickyBroadcastAsUser(Intent intent, UserHandle user, Bundle options) {
478 throw new UnsupportedOperationException();
482 public void sendStickyOrderedBroadcastAsUser(Intent intent,
483 UserHandle user, BroadcastReceiver resultReceiver,
484 Handler scheduler, int initialCode, String initialData,
485 Bundle initialExtras) {
486 throw new UnsupportedOperationException();
490 public void removeStickyBroadcastAsUser(Intent intent, UserHandle user) {
491 throw new UnsupportedOperationException();
495 public Intent registerReceiver(BroadcastReceiver receiver, IntentFilter filter) {
496 throw new UnsupportedOperationException();
500 public Intent registerReceiver(BroadcastReceiver receiver, IntentFilter filter,
502 throw new UnsupportedOperationException();
506 public Intent registerReceiver(BroadcastReceiver receiver, IntentFilter filter,
507 String broadcastPermission, Handler scheduler) {
508 throw new UnsupportedOperationException();
512 public Intent registerReceiver(BroadcastReceiver receiver, IntentFilter filter,
513 String broadcastPermission, Handler scheduler, int flags) {
514 throw new UnsupportedOperationException();
519 public Intent registerReceiverAsUser(BroadcastReceiver receiver, UserHandle user,
520 IntentFilter filter, String broadcastPermission, Handler scheduler) {
521 throw new UnsupportedOperationException();
525 public void unregisterReceiver(BroadcastReceiver receiver) {
526 throw new UnsupportedOperationException();
530 public ComponentName startService(Intent service) {
531 throw new UnsupportedOperationException();
535 public ComponentName startForegroundService(Intent service) {
536 throw new UnsupportedOperationException();
540 public boolean stopService(Intent service) {
541 throw new UnsupportedOperationException();
546 public ComponentName startServiceAsUser(Intent service, UserHandle user) {
547 throw new UnsupportedOperationException();
552 public ComponentName startForegroundServiceAsUser(Intent service, UserHandle user) {
553 throw new UnsupportedOperationException();
558 public boolean stopServiceAsUser(Intent service, UserHandle user) {
559 throw new UnsupportedOperationException();
563 public boolean bindService(Intent service, ServiceConnection conn, int flags) {
564 throw new UnsupportedOperationException();
569 public boolean bindServiceAsUser(Intent service, ServiceConnection conn, int flags,
571 throw new UnsupportedOperationException();
575 public void unbindService(ServiceConnection conn) {
576 throw new UnsupportedOperationException();
580 public boolean startInstrumentation(ComponentName className,
581 String profileFile, Bundle arguments) {
582 throw new UnsupportedOperationException();
586 public Object getSystemService(String name) {
587 throw new UnsupportedOperationException();
591 public String getSystemServiceName(Class<?> serviceClass) {
592 throw new UnsupportedOperationException();
596 public int checkPermission(String permission, int pid, int uid) {
597 throw new UnsupportedOperationException();
602 public int checkPermission(String permission, int pid, int uid, IBinder callerToken) {
603 return checkPermission(permission, pid, uid);
607 public int checkCallingPermission(String permission) {
608 throw new UnsupportedOperationException();
612 public int checkCallingOrSelfPermission(String permission) {
613 throw new UnsupportedOperationException();
617 public int checkSelfPermission(String permission) {
618 throw new UnsupportedOperationException();
622 public void enforcePermission(
623 String permission, int pid, int uid, String message) {
624 throw new UnsupportedOperationException();
628 public void enforceCallingPermission(String permission, String message) {
629 throw new UnsupportedOperationException();
633 public void enforceCallingOrSelfPermission(String permission, String message) {
634 throw new UnsupportedOperationException();
638 public void grantUriPermission(String toPackage, Uri uri, int modeFlags) {
639 throw new UnsupportedOperationException();
643 public void revokeUriPermission(Uri uri, int modeFlags) {
644 throw new UnsupportedOperationException();
648 public void revokeUriPermission(String targetPackage, Uri uri, int modeFlags) {
649 throw new UnsupportedOperationException();
653 public int checkUriPermission(Uri uri, int pid, int uid, int modeFlags) {
654 throw new UnsupportedOperationException();
659 public int checkUriPermission(Uri uri, int pid, int uid, int modeFlags, IBinder callerToken) {
660 return checkUriPermission(uri, pid, uid, modeFlags);
664 public int checkCallingUriPermission(Uri uri, int modeFlags) {
665 throw new UnsupportedOperationException();
669 public int checkCallingOrSelfUriPermission(Uri uri, int modeFlags) {
670 throw new UnsupportedOperationException();
674 public int checkUriPermission(Uri uri, String readPermission,
675 String writePermission, int pid, int uid, int modeFlags) {
676 throw new UnsupportedOperationException();
680 public void enforceUriPermission(
681 Uri uri, int pid, int uid, int modeFlags, String message) {
682 throw new UnsupportedOperationException();
686 public void enforceCallingUriPermission(
687 Uri uri, int modeFlags, String message) {
688 throw new UnsupportedOperationException();
692 public void enforceCallingOrSelfUriPermission(
693 Uri uri, int modeFlags, String message) {
694 throw new UnsupportedOperationException();
697 public void enforceUriPermission(
698 Uri uri, String readPermission, String writePermission,
699 int pid, int uid, int modeFlags, String message) {
700 throw new UnsupportedOperationException();
704 public Context createPackageContext(String packageName, int flags)
705 throws PackageManager.NameNotFoundException {
706 throw new UnsupportedOperationException();
711 public Context createApplicationContext(ApplicationInfo application, int flags)
712 throws PackageManager.NameNotFoundException {
718 public Context createContextForSplit(String splitName)
719 throws PackageManager.NameNotFoundException {
720 throw new UnsupportedOperationException();
725 public Context createPackageContextAsUser(String packageName, int flags, UserHandle user)
726 throws PackageManager.NameNotFoundException {
727 throw new UnsupportedOperationException();
732 public int getUserId() {
733 throw new UnsupportedOperationException();
737 public Context createConfigurationContext(Configuration overrideConfiguration) {
738 throw new UnsupportedOperationException();
742 public Context createDisplayContext(Display display) {
743 throw new UnsupportedOperationException();
747 public boolean isRestricted() {
748 throw new UnsupportedOperationException();
753 public DisplayAdjustments getDisplayAdjustments(int displayId) {
754 throw new UnsupportedOperationException();
759 public Display getDisplay() {
760 throw new UnsupportedOperationException();
765 public void updateDisplay(int displayId) {
766 throw new UnsupportedOperationException();
770 public File[] getExternalFilesDirs(String type) {
771 throw new UnsupportedOperationException();
775 public File[] getObbDirs() {
776 throw new UnsupportedOperationException();
780 public File[] getExternalCacheDirs() {
781 throw new UnsupportedOperationException();
785 public File[] getExternalMediaDirs() {
786 throw new UnsupportedOperationException();
791 public File getPreloadsFileCache() { throw new UnsupportedOperationException(); }
794 public Context createDeviceProtectedStorageContext() {
795 throw new UnsupportedOperationException();
801 public Context createCredentialProtectedStorageContext() {
802 throw new UnsupportedOperationException();
806 public boolean isDeviceProtectedStorage() {
807 throw new UnsupportedOperationException();
813 public boolean isCredentialProtectedStorage() {
814 throw new UnsupportedOperationException();
819 public IBinder getActivityToken() {
820 throw new UnsupportedOperationException();
825 public IServiceConnection getServiceDispatcher(ServiceConnection conn, Handler handler,
827 throw new UnsupportedOperationException();
832 public IApplicationThread getIApplicationThread() {
833 throw new UnsupportedOperationException();
838 public Handler getMainThreadHandler() {
839 throw new UnsupportedOperationException();