blob: b265d470dbe94b1929fcfd076063c3ff29e87f84 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
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;
Dianne Hackbornfa82f222009-09-17 15:14:12 -070025import android.content.IntentSender;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080026import android.content.ServiceConnection;
27import android.content.SharedPreferences;
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -070028import android.content.pm.ApplicationInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080029import android.content.pm.PackageManager;
30import android.content.res.AssetManager;
Dianne Hackborn756220b2012-08-14 16:45:30 -070031import android.content.res.Configuration;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080032import android.content.res.Resources;
Vasu Nori74f170f2010-06-01 18:06:18 -070033import android.database.DatabaseErrorHandler;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080034import 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;
Dianne Hackbornff170242014-11-19 10:59:01 -080040import android.os.IBinder;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080041import android.os.Looper;
Dianne Hackborn79af1dd2012-08-16 16:42:52 -070042import android.os.UserHandle;
Craig Mautner48d0d182013-06-11 07:53:06 -070043import android.view.DisplayAdjustments;
Jeff Browna492c3a2012-08-23 19:48:44 -070044import android.view.Display;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080045
46import java.io.File;
47import java.io.FileInputStream;
48import java.io.FileNotFoundException;
49import java.io.FileOutputStream;
50import java.io.IOException;
51import java.io.InputStream;
52
53/**
54 * A mock {@link android.content.Context} class. All methods are non-functional and throw
55 * {@link java.lang.UnsupportedOperationException}. You can use this to inject other dependencies,
56 * mocks, or monitors into the classes you are testing.
57 */
58public class MockContext extends Context {
59
60 @Override
61 public AssetManager getAssets() {
62 throw new UnsupportedOperationException();
63 }
64
65 @Override
66 public Resources getResources() {
67 throw new UnsupportedOperationException();
68 }
69
70 @Override
71 public PackageManager getPackageManager() {
72 throw new UnsupportedOperationException();
73 }
74
75 @Override
76 public ContentResolver getContentResolver() {
77 throw new UnsupportedOperationException();
78 }
79
80 @Override
81 public Looper getMainLooper() {
82 throw new UnsupportedOperationException();
83 }
84
85 @Override
86 public Context getApplicationContext() {
87 throw new UnsupportedOperationException();
88 }
89
90 @Override
91 public void setTheme(int resid) {
92 throw new UnsupportedOperationException();
93 }
94
95 @Override
96 public Resources.Theme getTheme() {
97 throw new UnsupportedOperationException();
98 }
99
100 @Override
101 public ClassLoader getClassLoader() {
102 throw new UnsupportedOperationException();
103 }
104
105 @Override
106 public String getPackageName() {
107 throw new UnsupportedOperationException();
108 }
109
Dianne Hackbornd8e1dbb2013-01-17 17:47:37 -0800110 /** @hide */
111 @Override
112 public String getBasePackageName() {
113 throw new UnsupportedOperationException();
114 }
115
Dianne Hackborn95d78532013-09-11 09:51:14 -0700116 /** @hide */
117 @Override
118 public String getOpPackageName() {
119 throw new UnsupportedOperationException();
120 }
121
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800122 @Override
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -0700123 public ApplicationInfo getApplicationInfo() {
124 throw new UnsupportedOperationException();
125 }
126
127 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800128 public String getPackageResourcePath() {
129 throw new UnsupportedOperationException();
130 }
131
Dianne Hackborn7f205432009-07-28 00:13:47 -0700132 /** @hide */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800133 @Override
Joe Onorato23ecae32009-06-10 17:07:15 -0700134 public File getSharedPrefsFile(String name) {
135 throw new UnsupportedOperationException();
136 }
137
138 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800139 public String getPackageCodePath() {
140 throw new UnsupportedOperationException();
141 }
142
143 @Override
144 public SharedPreferences getSharedPreferences(String name, int mode) {
145 throw new UnsupportedOperationException();
146 }
147
148 @Override
149 public FileInputStream openFileInput(String name) throws FileNotFoundException {
150 throw new UnsupportedOperationException();
151 }
152
153 @Override
154 public FileOutputStream openFileOutput(String name, int mode) throws FileNotFoundException {
155 throw new UnsupportedOperationException();
156 }
157
158 @Override
159 public boolean deleteFile(String name) {
160 throw new UnsupportedOperationException();
161 }
162
163 @Override
164 public File getFileStreamPath(String name) {
165 throw new UnsupportedOperationException();
166 }
167
168 @Override
169 public String[] fileList() {
170 throw new UnsupportedOperationException();
171 }
172
173 @Override
174 public File getFilesDir() {
175 throw new UnsupportedOperationException();
176 }
177
178 @Override
Christopher Tatea7835b62014-07-11 17:25:57 -0700179 public File getNoBackupFilesDir() {
180 throw new UnsupportedOperationException();
181 }
182
183 @Override
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800184 public File getExternalFilesDir(String type) {
185 throw new UnsupportedOperationException();
186 }
187
188 @Override
Dianne Hackborn805fd7e2011-01-16 18:30:29 -0800189 public File getObbDir() {
190 throw new UnsupportedOperationException();
191 }
192
193 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800194 public File getCacheDir() {
195 throw new UnsupportedOperationException();
196 }
197
198 @Override
Jeff Sharkey4ed745d2014-07-15 20:39:15 -0700199 public File getCodeCacheDir() {
200 throw new UnsupportedOperationException();
201 }
202
203 @Override
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800204 public File getExternalCacheDir() {
205 throw new UnsupportedOperationException();
206 }
207
208 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800209 public File getDir(String name, int mode) {
210 throw new UnsupportedOperationException();
211 }
212
213 @Override
214 public SQLiteDatabase openOrCreateDatabase(String file, int mode,
215 SQLiteDatabase.CursorFactory factory) {
216 throw new UnsupportedOperationException();
217 }
218
219 @Override
Vasu Nori74f170f2010-06-01 18:06:18 -0700220 public SQLiteDatabase openOrCreateDatabase(String file, int mode,
221 SQLiteDatabase.CursorFactory factory, DatabaseErrorHandler errorHandler) {
222 throw new UnsupportedOperationException();
223 }
224
225 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800226 public File getDatabasePath(String name) {
227 throw new UnsupportedOperationException();
228 }
229
230 @Override
231 public String[] databaseList() {
232 throw new UnsupportedOperationException();
233 }
234
235 @Override
236 public boolean deleteDatabase(String name) {
237 throw new UnsupportedOperationException();
238 }
239
240 @Override
241 public Drawable getWallpaper() {
242 throw new UnsupportedOperationException();
243 }
244
245 @Override
246 public Drawable peekWallpaper() {
247 throw new UnsupportedOperationException();
248 }
249
250 @Override
251 public int getWallpaperDesiredMinimumWidth() {
252 throw new UnsupportedOperationException();
253 }
254
255 @Override
256 public int getWallpaperDesiredMinimumHeight() {
257 throw new UnsupportedOperationException();
258 }
259
260 @Override
261 public void setWallpaper(Bitmap bitmap) throws IOException {
262 throw new UnsupportedOperationException();
263 }
264
265 @Override
266 public void setWallpaper(InputStream data) throws IOException {
267 throw new UnsupportedOperationException();
268 }
269
270 @Override
271 public void clearWallpaper() {
272 throw new UnsupportedOperationException();
273 }
274
275 @Override
276 public void startActivity(Intent intent) {
277 throw new UnsupportedOperationException();
278 }
279
280 @Override
Dianne Hackborna4972e92012-03-14 10:38:05 -0700281 public void startActivity(Intent intent, Bundle options) {
282 startActivity(intent);
283 }
284
285 @Override
Dianne Hackborn621e17d2010-11-22 15:59:56 -0800286 public void startActivities(Intent[] intents) {
287 throw new UnsupportedOperationException();
288 }
289
290 @Override
Dianne Hackborna4972e92012-03-14 10:38:05 -0700291 public void startActivities(Intent[] intents, Bundle options) {
292 startActivities(intents);
293 }
294
295 @Override
Dianne Hackbornfa82f222009-09-17 15:14:12 -0700296 public void startIntentSender(IntentSender intent,
297 Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags)
298 throws IntentSender.SendIntentException {
299 throw new UnsupportedOperationException();
300 }
Dianne Hackborna4972e92012-03-14 10:38:05 -0700301
302 @Override
303 public void startIntentSender(IntentSender intent,
304 Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags,
305 Bundle options) throws IntentSender.SendIntentException {
306 startIntentSender(intent, fillInIntent, flagsMask, flagsValues, extraFlags);
307 }
Dianne Hackbornfa82f222009-09-17 15:14:12 -0700308
309 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800310 public void sendBroadcast(Intent intent) {
311 throw new UnsupportedOperationException();
312 }
313
Amith Yamasani67cf7d32012-02-16 14:31:23 -0800314 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800315 public void sendBroadcast(Intent intent, String receiverPermission) {
316 throw new UnsupportedOperationException();
317 }
318
Dianne Hackbornf51f6122013-02-04 18:23:34 -0800319 /** @hide */
320 @Override
321 public void sendBroadcast(Intent intent, String receiverPermission, int appOp) {
322 throw new UnsupportedOperationException();
323 }
324
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800325 @Override
326 public void sendOrderedBroadcast(Intent intent,
327 String receiverPermission) {
328 throw new UnsupportedOperationException();
329 }
330
331 @Override
332 public void sendOrderedBroadcast(Intent intent, String receiverPermission,
333 BroadcastReceiver resultReceiver, Handler scheduler, int initialCode, String initialData,
334 Bundle initialExtras) {
335 throw new UnsupportedOperationException();
336 }
337
Dianne Hackbornf51f6122013-02-04 18:23:34 -0800338 /** @hide */
339 @Override
340 public void sendOrderedBroadcast(Intent intent, String receiverPermission, int appOp,
341 BroadcastReceiver resultReceiver, Handler scheduler, int initialCode, String initialData,
342 Bundle initialExtras) {
343 throw new UnsupportedOperationException();
344 }
345
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800346 @Override
Dianne Hackborn79af1dd2012-08-16 16:42:52 -0700347 public void sendBroadcastAsUser(Intent intent, UserHandle user) {
Dianne Hackborn7d19e022012-08-07 19:12:33 -0700348 throw new UnsupportedOperationException();
349 }
350
351 @Override
Dianne Hackborn5ac72a22012-08-29 18:32:08 -0700352 public void sendBroadcastAsUser(Intent intent, UserHandle user,
353 String receiverPermission) {
354 throw new UnsupportedOperationException();
355 }
356
357 @Override
Dianne Hackborn79af1dd2012-08-16 16:42:52 -0700358 public void sendOrderedBroadcastAsUser(Intent intent, UserHandle user,
Dianne Hackborn5ac72a22012-08-29 18:32:08 -0700359 String receiverPermission, BroadcastReceiver resultReceiver, Handler scheduler,
Dianne Hackborn7d19e022012-08-07 19:12:33 -0700360 int initialCode, String initialData, Bundle initialExtras) {
361 throw new UnsupportedOperationException();
362 }
363
Amith Yamasani3cf75722014-05-16 12:37:29 -0700364 /** @hide */
Dianne Hackborn7d19e022012-08-07 19:12:33 -0700365 @Override
Amith Yamasani3cf75722014-05-16 12:37:29 -0700366 public void sendOrderedBroadcastAsUser(Intent intent, UserHandle user,
367 String receiverPermission, int appOp, BroadcastReceiver resultReceiver,
368 Handler scheduler,
369 int initialCode, String initialData, Bundle initialExtras) {
370 throw new UnsupportedOperationException();
371 }
372
373 @Override
374
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800375 public void sendStickyBroadcast(Intent intent) {
376 throw new UnsupportedOperationException();
377 }
378
379 @Override
Dianne Hackbornefa199f2009-09-19 12:03:15 -0700380 public void sendStickyOrderedBroadcast(Intent intent,
381 BroadcastReceiver resultReceiver, Handler scheduler, int initialCode, String initialData,
382 Bundle initialExtras) {
383 throw new UnsupportedOperationException();
384 }
385
386 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800387 public void removeStickyBroadcast(Intent intent) {
388 throw new UnsupportedOperationException();
389 }
390
391 @Override
Dianne Hackborn5ac72a22012-08-29 18:32:08 -0700392 public void sendStickyBroadcastAsUser(Intent intent, UserHandle user) {
393 throw new UnsupportedOperationException();
394 }
395
396 @Override
397 public void sendStickyOrderedBroadcastAsUser(Intent intent,
398 UserHandle user, BroadcastReceiver resultReceiver,
399 Handler scheduler, int initialCode, String initialData,
400 Bundle initialExtras) {
401 throw new UnsupportedOperationException();
402 }
403
404 @Override
405 public void removeStickyBroadcastAsUser(Intent intent, UserHandle user) {
406 throw new UnsupportedOperationException();
407 }
408
409 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800410 public Intent registerReceiver(BroadcastReceiver receiver, IntentFilter filter) {
411 throw new UnsupportedOperationException();
412 }
413
414 @Override
415 public Intent registerReceiver(BroadcastReceiver receiver, IntentFilter filter,
416 String broadcastPermission, Handler scheduler) {
417 throw new UnsupportedOperationException();
418 }
419
Dianne Hackborn20e80982012-08-31 19:00:44 -0700420 /** @hide */
421 @Override
422 public Intent registerReceiverAsUser(BroadcastReceiver receiver, UserHandle user,
423 IntentFilter filter, String broadcastPermission, Handler scheduler) {
424 throw new UnsupportedOperationException();
425 }
426
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800427 @Override
428 public void unregisterReceiver(BroadcastReceiver receiver) {
429 throw new UnsupportedOperationException();
430 }
431
432 @Override
433 public ComponentName startService(Intent service) {
434 throw new UnsupportedOperationException();
435 }
436
437 @Override
438 public boolean stopService(Intent service) {
439 throw new UnsupportedOperationException();
440 }
441
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700442 /** @hide */
443 @Override
444 public ComponentName startServiceAsUser(Intent service, UserHandle user) {
445 throw new UnsupportedOperationException();
446 }
447
448 /** @hide */
449 @Override
450 public boolean stopServiceAsUser(Intent service, UserHandle user) {
451 throw new UnsupportedOperationException();
452 }
453
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800454 @Override
455 public boolean bindService(Intent service, ServiceConnection conn, int flags) {
456 throw new UnsupportedOperationException();
457 }
458
Amith Yamasani37ce3a82012-02-06 12:04:42 -0800459 /** @hide */
460 @Override
Amith Yamasani27b89e62013-01-16 12:30:11 -0800461 public boolean bindServiceAsUser(Intent service, ServiceConnection conn, int flags,
462 UserHandle user) {
Amith Yamasani37ce3a82012-02-06 12:04:42 -0800463 throw new UnsupportedOperationException();
464 }
465
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800466 @Override
467 public void unbindService(ServiceConnection conn) {
468 throw new UnsupportedOperationException();
469 }
470
471 @Override
472 public boolean startInstrumentation(ComponentName className,
473 String profileFile, Bundle arguments) {
474 throw new UnsupportedOperationException();
475 }
476
477 @Override
478 public Object getSystemService(String name) {
479 throw new UnsupportedOperationException();
480 }
481
482 @Override
Jeff Brown6e539312015-02-24 18:53:21 -0800483 public String getSystemServiceName(Class<?> serviceClass) {
484 throw new UnsupportedOperationException();
485 }
486
487 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800488 public int checkPermission(String permission, int pid, int uid) {
489 throw new UnsupportedOperationException();
490 }
491
Dianne Hackbornff170242014-11-19 10:59:01 -0800492 /** @hide */
493 @Override
494 public int checkPermission(String permission, int pid, int uid, IBinder callerToken) {
495 return checkPermission(permission, pid, uid);
496 }
497
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800498 @Override
499 public int checkCallingPermission(String permission) {
500 throw new UnsupportedOperationException();
501 }
502
503 @Override
504 public int checkCallingOrSelfPermission(String permission) {
505 throw new UnsupportedOperationException();
506 }
507
508 @Override
Svetoslavc6d1c342015-02-26 14:44:43 -0800509 public int checkSelfPermission(String permission) {
510 throw new UnsupportedOperationException();
511 }
512
513 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800514 public void enforcePermission(
515 String permission, int pid, int uid, String message) {
516 throw new UnsupportedOperationException();
517 }
518
519 @Override
520 public void enforceCallingPermission(String permission, String message) {
521 throw new UnsupportedOperationException();
522 }
523
524 @Override
525 public void enforceCallingOrSelfPermission(String permission, String message) {
526 throw new UnsupportedOperationException();
527 }
528
529 @Override
530 public void grantUriPermission(String toPackage, Uri uri, int modeFlags) {
531 throw new UnsupportedOperationException();
532 }
533
534 @Override
535 public void revokeUriPermission(Uri uri, int modeFlags) {
536 throw new UnsupportedOperationException();
537 }
538
539 @Override
540 public int checkUriPermission(Uri uri, int pid, int uid, int modeFlags) {
541 throw new UnsupportedOperationException();
542 }
543
Dianne Hackbornff170242014-11-19 10:59:01 -0800544 /** @hide */
545 @Override
546 public int checkUriPermission(Uri uri, int pid, int uid, int modeFlags, IBinder callerToken) {
547 return checkUriPermission(uri, pid, uid, modeFlags);
548 }
549
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800550 @Override
551 public int checkCallingUriPermission(Uri uri, int modeFlags) {
552 throw new UnsupportedOperationException();
553 }
554
555 @Override
556 public int checkCallingOrSelfUriPermission(Uri uri, int modeFlags) {
557 throw new UnsupportedOperationException();
558 }
559
560 @Override
561 public int checkUriPermission(Uri uri, String readPermission,
562 String writePermission, int pid, int uid, int modeFlags) {
563 throw new UnsupportedOperationException();
564 }
565
566 @Override
567 public void enforceUriPermission(
568 Uri uri, int pid, int uid, int modeFlags, String message) {
569 throw new UnsupportedOperationException();
570 }
571
572 @Override
573 public void enforceCallingUriPermission(
574 Uri uri, int modeFlags, String message) {
575 throw new UnsupportedOperationException();
576 }
577
578 @Override
579 public void enforceCallingOrSelfUriPermission(
580 Uri uri, int modeFlags, String message) {
581 throw new UnsupportedOperationException();
582 }
583
584 public void enforceUriPermission(
585 Uri uri, String readPermission, String writePermission,
586 int pid, int uid, int modeFlags, String message) {
587 throw new UnsupportedOperationException();
588 }
589
590 @Override
591 public Context createPackageContext(String packageName, int flags)
592 throws PackageManager.NameNotFoundException {
593 throw new UnsupportedOperationException();
594 }
Romain Guy870e09f2009-07-06 16:35:25 -0700595
Jeff Sharkey6d515712012-09-20 16:06:08 -0700596 /** {@hide} */
597 @Override
Svetoslav976e8bd2014-07-16 15:12:03 -0700598 public Context createApplicationContext(ApplicationInfo application, int flags)
599 throws PackageManager.NameNotFoundException {
600 return null;
601 }
602
603 /** {@hide} */
604 @Override
Jeff Sharkey6d515712012-09-20 16:06:08 -0700605 public Context createPackageContextAsUser(String packageName, int flags, UserHandle user)
606 throws PackageManager.NameNotFoundException {
607 throw new UnsupportedOperationException();
608 }
609
Jim Millera75a8832013-02-07 16:53:32 -0800610 /** {@hide} */
611 @Override
612 public int getUserId() {
613 throw new UnsupportedOperationException();
614 }
615
Romain Guy870e09f2009-07-06 16:35:25 -0700616 @Override
Dianne Hackborn756220b2012-08-14 16:45:30 -0700617 public Context createConfigurationContext(Configuration overrideConfiguration) {
618 throw new UnsupportedOperationException();
619 }
620
621 @Override
Jeff Browna492c3a2012-08-23 19:48:44 -0700622 public Context createDisplayContext(Display display) {
623 throw new UnsupportedOperationException();
624 }
625
626 @Override
Romain Guy870e09f2009-07-06 16:35:25 -0700627 public boolean isRestricted() {
Svetoslav976e8bd2014-07-16 15:12:03 -0700628 throw new UnsupportedOperationException();
Romain Guy870e09f2009-07-06 16:35:25 -0700629 }
Jeff Brown98365d72012-08-19 20:30:52 -0700630
631 /** @hide */
632 @Override
Craig Mautner48d0d182013-06-11 07:53:06 -0700633 public DisplayAdjustments getDisplayAdjustments(int displayId) {
Jeff Brown98365d72012-08-19 20:30:52 -0700634 throw new UnsupportedOperationException();
635 }
Jeff Sharkey7f392de2013-08-11 17:42:17 -0700636
637 @Override
638 public File[] getExternalFilesDirs(String type) {
639 throw new UnsupportedOperationException();
640 }
641
642 @Override
643 public File[] getObbDirs() {
644 throw new UnsupportedOperationException();
645 }
646
647 @Override
648 public File[] getExternalCacheDirs() {
649 throw new UnsupportedOperationException();
650 }
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -0700651
652 @Override
653 public File[] getExternalMediaDirs() {
654 throw new UnsupportedOperationException();
655 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800656}