1/*
2 * Copyright (C) 2007 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.test.mock;
18
19import android.content.ComponentName;
20import android.content.ContentResolver;
21import android.content.Context;
22import android.content.Intent;
23import android.content.IntentFilter;
24import android.content.BroadcastReceiver;
25import android.content.IntentSender;
26import android.content.ServiceConnection;
27import android.content.SharedPreferences;
28import android.content.pm.ApplicationInfo;
29import android.content.pm.PackageManager;
30import android.content.res.AssetManager;
31import android.content.res.Configuration;
32import android.content.res.Resources;
33import android.database.DatabaseErrorHandler;
34import android.database.sqlite.SQLiteDatabase;
35import android.graphics.Bitmap;
36import android.graphics.drawable.Drawable;
37import android.net.Uri;
38import android.os.Bundle;
39import android.os.Handler;
40import android.os.Looper;
41import android.os.UserHandle;
42import android.view.DisplayAdjustments;
43import android.view.Display;
44
45import java.io.File;
46import java.io.FileInputStream;
47import java.io.FileNotFoundException;
48import java.io.FileOutputStream;
49import java.io.IOException;
50import java.io.InputStream;
51
52/**
53 * A mock {@link android.content.Context} class.  All methods are non-functional and throw
54 * {@link java.lang.UnsupportedOperationException}.  You can use this to inject other dependencies,
55 * mocks, or monitors into the classes you are testing.
56 */
57public class MockContext extends Context {
58
59    @Override
60    public AssetManager getAssets() {
61        throw new UnsupportedOperationException();
62    }
63
64    @Override
65    public Resources getResources() {
66        throw new UnsupportedOperationException();
67    }
68
69    @Override
70    public PackageManager getPackageManager() {
71        throw new UnsupportedOperationException();
72    }
73
74    @Override
75    public ContentResolver getContentResolver() {
76        throw new UnsupportedOperationException();
77    }
78
79    @Override
80    public Looper getMainLooper() {
81        throw new UnsupportedOperationException();
82    }
83
84    @Override
85    public Context getApplicationContext() {
86        throw new UnsupportedOperationException();
87    }
88
89    @Override
90    public void setTheme(int resid) {
91        throw new UnsupportedOperationException();
92    }
93
94    @Override
95    public Resources.Theme getTheme() {
96        throw new UnsupportedOperationException();
97    }
98
99    @Override
100    public ClassLoader getClassLoader() {
101        throw new UnsupportedOperationException();
102    }
103
104    @Override
105    public String getPackageName() {
106        throw new UnsupportedOperationException();
107    }
108
109    /** @hide */
110    @Override
111    public String getBasePackageName() {
112        throw new UnsupportedOperationException();
113    }
114
115    /** @hide */
116    @Override
117    public String getOpPackageName() {
118        throw new UnsupportedOperationException();
119    }
120
121    @Override
122    public ApplicationInfo getApplicationInfo() {
123        throw new UnsupportedOperationException();
124    }
125
126    @Override
127    public String getPackageResourcePath() {
128        throw new UnsupportedOperationException();
129    }
130
131    /** @hide */
132    @Override
133    public File getSharedPrefsFile(String name) {
134        throw new UnsupportedOperationException();
135    }
136
137    @Override
138    public String getPackageCodePath() {
139        throw new UnsupportedOperationException();
140    }
141
142    @Override
143    public SharedPreferences getSharedPreferences(String name, int mode) {
144        throw new UnsupportedOperationException();
145    }
146
147    @Override
148    public FileInputStream openFileInput(String name) throws FileNotFoundException {
149        throw new UnsupportedOperationException();
150    }
151
152    @Override
153    public FileOutputStream openFileOutput(String name, int mode) throws FileNotFoundException {
154        throw new UnsupportedOperationException();
155    }
156
157    @Override
158    public boolean deleteFile(String name) {
159        throw new UnsupportedOperationException();
160    }
161
162    @Override
163    public File getFileStreamPath(String name) {
164        throw new UnsupportedOperationException();
165    }
166
167    @Override
168    public String[] fileList() {
169        throw new UnsupportedOperationException();
170    }
171
172    @Override
173    public File getFilesDir() {
174        throw new UnsupportedOperationException();
175    }
176
177    @Override
178    public File getExternalFilesDir(String type) {
179        throw new UnsupportedOperationException();
180    }
181
182    @Override
183    public File getObbDir() {
184        throw new UnsupportedOperationException();
185    }
186
187    @Override
188    public File getCacheDir() {
189        throw new UnsupportedOperationException();
190    }
191
192    @Override
193    public File getExternalCacheDir() {
194        throw new UnsupportedOperationException();
195    }
196
197    @Override
198    public File getDir(String name, int mode) {
199        throw new UnsupportedOperationException();
200    }
201
202    @Override
203    public SQLiteDatabase openOrCreateDatabase(String file, int mode,
204            SQLiteDatabase.CursorFactory factory) {
205        throw new UnsupportedOperationException();
206    }
207
208    @Override
209    public SQLiteDatabase openOrCreateDatabase(String file, int mode,
210            SQLiteDatabase.CursorFactory factory, DatabaseErrorHandler errorHandler) {
211        throw new UnsupportedOperationException();
212    }
213
214    @Override
215    public File getDatabasePath(String name) {
216        throw new UnsupportedOperationException();
217    }
218
219    @Override
220    public String[] databaseList() {
221        throw new UnsupportedOperationException();
222    }
223
224    @Override
225    public boolean deleteDatabase(String name) {
226        throw new UnsupportedOperationException();
227    }
228
229    @Override
230    public Drawable getWallpaper() {
231        throw new UnsupportedOperationException();
232    }
233
234    @Override
235    public Drawable peekWallpaper() {
236        throw new UnsupportedOperationException();
237    }
238
239    @Override
240    public int getWallpaperDesiredMinimumWidth() {
241        throw new UnsupportedOperationException();
242    }
243
244    @Override
245    public int getWallpaperDesiredMinimumHeight() {
246        throw new UnsupportedOperationException();
247    }
248
249    @Override
250    public void setWallpaper(Bitmap bitmap) throws IOException {
251        throw new UnsupportedOperationException();
252    }
253
254    @Override
255    public void setWallpaper(InputStream data) throws IOException {
256        throw new UnsupportedOperationException();
257    }
258
259    @Override
260    public void clearWallpaper() {
261        throw new UnsupportedOperationException();
262    }
263
264    @Override
265    public void startActivity(Intent intent) {
266        throw new UnsupportedOperationException();
267    }
268
269    @Override
270    public void startActivity(Intent intent, Bundle options) {
271        startActivity(intent);
272    }
273
274    @Override
275    public void startActivities(Intent[] intents) {
276        throw new UnsupportedOperationException();
277    }
278
279    @Override
280    public void startActivities(Intent[] intents, Bundle options) {
281        startActivities(intents);
282    }
283
284    @Override
285    public void startIntentSender(IntentSender intent,
286            Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags)
287            throws IntentSender.SendIntentException {
288        throw new UnsupportedOperationException();
289    }
290
291    @Override
292    public void startIntentSender(IntentSender intent,
293            Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags,
294            Bundle options) throws IntentSender.SendIntentException {
295        startIntentSender(intent, fillInIntent, flagsMask, flagsValues, extraFlags);
296    }
297
298    @Override
299    public void sendBroadcast(Intent intent) {
300        throw new UnsupportedOperationException();
301    }
302
303    @Override
304    public void sendBroadcast(Intent intent, String receiverPermission) {
305        throw new UnsupportedOperationException();
306    }
307
308    /** @hide */
309    @Override
310    public void sendBroadcast(Intent intent, String receiverPermission, int appOp) {
311        throw new UnsupportedOperationException();
312    }
313
314    @Override
315    public void sendOrderedBroadcast(Intent intent,
316            String receiverPermission) {
317        throw new UnsupportedOperationException();
318    }
319
320    @Override
321    public void sendOrderedBroadcast(Intent intent, String receiverPermission,
322            BroadcastReceiver resultReceiver, Handler scheduler, int initialCode, String initialData,
323           Bundle initialExtras) {
324        throw new UnsupportedOperationException();
325    }
326
327    /** @hide */
328    @Override
329    public void sendOrderedBroadcast(Intent intent, String receiverPermission, int appOp,
330            BroadcastReceiver resultReceiver, Handler scheduler, int initialCode, String initialData,
331           Bundle initialExtras) {
332        throw new UnsupportedOperationException();
333    }
334
335    @Override
336    public void sendBroadcastAsUser(Intent intent, UserHandle user) {
337        throw new UnsupportedOperationException();
338    }
339
340    @Override
341    public void sendBroadcastAsUser(Intent intent, UserHandle user,
342            String receiverPermission) {
343        throw new UnsupportedOperationException();
344    }
345
346    @Override
347    public void sendOrderedBroadcastAsUser(Intent intent, UserHandle user,
348            String receiverPermission, BroadcastReceiver resultReceiver, Handler scheduler,
349            int initialCode, String initialData, Bundle initialExtras) {
350        throw new UnsupportedOperationException();
351    }
352
353    @Override
354    public void sendStickyBroadcast(Intent intent) {
355        throw new UnsupportedOperationException();
356    }
357
358    @Override
359    public void sendStickyOrderedBroadcast(Intent intent,
360            BroadcastReceiver resultReceiver, Handler scheduler, int initialCode, String initialData,
361           Bundle initialExtras) {
362        throw new UnsupportedOperationException();
363    }
364
365    @Override
366    public void removeStickyBroadcast(Intent intent) {
367        throw new UnsupportedOperationException();
368    }
369
370    @Override
371    public void sendStickyBroadcastAsUser(Intent intent, UserHandle user) {
372        throw new UnsupportedOperationException();
373    }
374
375    @Override
376    public void sendStickyOrderedBroadcastAsUser(Intent intent,
377            UserHandle user, BroadcastReceiver resultReceiver,
378            Handler scheduler, int initialCode, String initialData,
379            Bundle initialExtras) {
380        throw new UnsupportedOperationException();
381    }
382
383    @Override
384    public void removeStickyBroadcastAsUser(Intent intent, UserHandle user) {
385        throw new UnsupportedOperationException();
386    }
387
388    @Override
389    public Intent registerReceiver(BroadcastReceiver receiver, IntentFilter filter) {
390        throw new UnsupportedOperationException();
391    }
392
393    @Override
394    public Intent registerReceiver(BroadcastReceiver receiver, IntentFilter filter,
395            String broadcastPermission, Handler scheduler) {
396        throw new UnsupportedOperationException();
397    }
398
399    /** @hide */
400    @Override
401    public Intent registerReceiverAsUser(BroadcastReceiver receiver, UserHandle user,
402            IntentFilter filter, String broadcastPermission, Handler scheduler) {
403        throw new UnsupportedOperationException();
404    }
405
406    @Override
407    public void unregisterReceiver(BroadcastReceiver receiver) {
408        throw new UnsupportedOperationException();
409    }
410
411    @Override
412    public ComponentName startService(Intent service) {
413        throw new UnsupportedOperationException();
414    }
415
416    @Override
417    public boolean stopService(Intent service) {
418        throw new UnsupportedOperationException();
419    }
420
421    /** @hide */
422    @Override
423    public ComponentName startServiceAsUser(Intent service, UserHandle user) {
424        throw new UnsupportedOperationException();
425    }
426
427    /** @hide */
428    @Override
429    public boolean stopServiceAsUser(Intent service, UserHandle user) {
430        throw new UnsupportedOperationException();
431    }
432
433    @Override
434    public boolean bindService(Intent service, ServiceConnection conn, int flags) {
435        throw new UnsupportedOperationException();
436    }
437
438    /** @hide */
439    @Override
440    public boolean bindServiceAsUser(Intent service, ServiceConnection conn, int flags,
441            UserHandle user) {
442        throw new UnsupportedOperationException();
443    }
444
445    @Override
446    public void unbindService(ServiceConnection conn) {
447        throw new UnsupportedOperationException();
448    }
449
450    @Override
451    public boolean startInstrumentation(ComponentName className,
452            String profileFile, Bundle arguments) {
453        throw new UnsupportedOperationException();
454    }
455
456    @Override
457    public Object getSystemService(String name) {
458        throw new UnsupportedOperationException();
459    }
460
461    @Override
462    public int checkPermission(String permission, int pid, int uid) {
463        throw new UnsupportedOperationException();
464    }
465
466    @Override
467    public int checkCallingPermission(String permission) {
468        throw new UnsupportedOperationException();
469    }
470
471    @Override
472    public int checkCallingOrSelfPermission(String permission) {
473        throw new UnsupportedOperationException();
474    }
475
476    @Override
477    public void enforcePermission(
478            String permission, int pid, int uid, String message) {
479        throw new UnsupportedOperationException();
480    }
481
482    @Override
483    public void enforceCallingPermission(String permission, String message) {
484        throw new UnsupportedOperationException();
485    }
486
487    @Override
488    public void enforceCallingOrSelfPermission(String permission, String message) {
489        throw new UnsupportedOperationException();
490    }
491
492    @Override
493    public void grantUriPermission(String toPackage, Uri uri, int modeFlags) {
494        throw new UnsupportedOperationException();
495    }
496
497    @Override
498    public void revokeUriPermission(Uri uri, int modeFlags) {
499        throw new UnsupportedOperationException();
500    }
501
502    @Override
503    public int checkUriPermission(Uri uri, int pid, int uid, int modeFlags) {
504        throw new UnsupportedOperationException();
505    }
506
507    @Override
508    public int checkCallingUriPermission(Uri uri, int modeFlags) {
509        throw new UnsupportedOperationException();
510    }
511
512    @Override
513    public int checkCallingOrSelfUriPermission(Uri uri, int modeFlags) {
514        throw new UnsupportedOperationException();
515    }
516
517    @Override
518    public int checkUriPermission(Uri uri, String readPermission,
519            String writePermission, int pid, int uid, int modeFlags) {
520        throw new UnsupportedOperationException();
521    }
522
523    @Override
524    public void enforceUriPermission(
525            Uri uri, int pid, int uid, int modeFlags, String message) {
526        throw new UnsupportedOperationException();
527    }
528
529    @Override
530    public void enforceCallingUriPermission(
531            Uri uri, int modeFlags, String message) {
532        throw new UnsupportedOperationException();
533    }
534
535    @Override
536    public void enforceCallingOrSelfUriPermission(
537            Uri uri, int modeFlags, String message) {
538        throw new UnsupportedOperationException();
539    }
540
541    public void enforceUriPermission(
542            Uri uri, String readPermission, String writePermission,
543            int pid, int uid, int modeFlags, String message) {
544        throw new UnsupportedOperationException();
545    }
546
547    @Override
548    public Context createPackageContext(String packageName, int flags)
549            throws PackageManager.NameNotFoundException {
550        throw new UnsupportedOperationException();
551    }
552
553    /** {@hide} */
554    @Override
555    public Context createPackageContextAsUser(String packageName, int flags, UserHandle user)
556            throws PackageManager.NameNotFoundException {
557        throw new UnsupportedOperationException();
558    }
559
560    /** {@hide} */
561    @Override
562    public int getUserId() {
563        throw new UnsupportedOperationException();
564    }
565
566    @Override
567    public Context createConfigurationContext(Configuration overrideConfiguration) {
568        throw new UnsupportedOperationException();
569    }
570
571    @Override
572    public Context createDisplayContext(Display display) {
573        throw new UnsupportedOperationException();
574    }
575
576    @Override
577    public boolean isRestricted() {
578        throw new UnsupportedOperationException();
579    }
580
581    /** @hide */
582    @Override
583    public DisplayAdjustments getDisplayAdjustments(int displayId) {
584        throw new UnsupportedOperationException();
585    }
586
587    @Override
588    public File[] getExternalFilesDirs(String type) {
589        throw new UnsupportedOperationException();
590    }
591
592    @Override
593    public File[] getObbDirs() {
594        throw new UnsupportedOperationException();
595    }
596
597    @Override
598    public File[] getExternalCacheDirs() {
599        throw new UnsupportedOperationException();
600    }
601}
602