blob: 0d9cd18999f21658071ae36ba2e1439fa8ef7dcc [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;
40import android.os.Looper;
Dianne Hackborn79af1dd2012-08-16 16:42:52 -070041import android.os.UserHandle;
Craig Mautner48d0d182013-06-11 07:53:06 -070042import android.view.DisplayAdjustments;
Jeff Browna492c3a2012-08-23 19:48:44 -070043import android.view.Display;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080044
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
Dianne Hackbornd8e1dbb2013-01-17 17:47:37 -0800109 /** @hide */
110 @Override
111 public String getBasePackageName() {
112 throw new UnsupportedOperationException();
113 }
114
Dianne Hackborn95d78532013-09-11 09:51:14 -0700115 /** @hide */
116 @Override
117 public String getOpPackageName() {
118 throw new UnsupportedOperationException();
119 }
120
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800121 @Override
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -0700122 public ApplicationInfo getApplicationInfo() {
123 throw new UnsupportedOperationException();
124 }
125
126 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800127 public String getPackageResourcePath() {
128 throw new UnsupportedOperationException();
129 }
130
Dianne Hackborn7f205432009-07-28 00:13:47 -0700131 /** @hide */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800132 @Override
Joe Onorato23ecae32009-06-10 17:07:15 -0700133 public File getSharedPrefsFile(String name) {
134 throw new UnsupportedOperationException();
135 }
136
137 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800138 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
Dianne Hackborne83cefc2010-02-04 17:38:14 -0800178 public File getExternalFilesDir(String type) {
179 throw new UnsupportedOperationException();
180 }
181
182 @Override
Dianne Hackborn805fd7e2011-01-16 18:30:29 -0800183 public File getObbDir() {
184 throw new UnsupportedOperationException();
185 }
186
187 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800188 public File getCacheDir() {
189 throw new UnsupportedOperationException();
190 }
191
192 @Override
Dianne Hackborne83cefc2010-02-04 17:38:14 -0800193 public File getExternalCacheDir() {
194 throw new UnsupportedOperationException();
195 }
196
197 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800198 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
Vasu Nori74f170f2010-06-01 18:06:18 -0700209 public SQLiteDatabase openOrCreateDatabase(String file, int mode,
210 SQLiteDatabase.CursorFactory factory, DatabaseErrorHandler errorHandler) {
211 throw new UnsupportedOperationException();
212 }
213
214 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800215 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
Dianne Hackborna4972e92012-03-14 10:38:05 -0700270 public void startActivity(Intent intent, Bundle options) {
271 startActivity(intent);
272 }
273
274 @Override
Dianne Hackborn621e17d2010-11-22 15:59:56 -0800275 public void startActivities(Intent[] intents) {
276 throw new UnsupportedOperationException();
277 }
278
279 @Override
Dianne Hackborna4972e92012-03-14 10:38:05 -0700280 public void startActivities(Intent[] intents, Bundle options) {
281 startActivities(intents);
282 }
283
284 @Override
Dianne Hackbornfa82f222009-09-17 15:14:12 -0700285 public void startIntentSender(IntentSender intent,
286 Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags)
287 throws IntentSender.SendIntentException {
288 throw new UnsupportedOperationException();
289 }
Dianne Hackborna4972e92012-03-14 10:38:05 -0700290
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 }
Dianne Hackbornfa82f222009-09-17 15:14:12 -0700297
298 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800299 public void sendBroadcast(Intent intent) {
300 throw new UnsupportedOperationException();
301 }
302
Amith Yamasani67cf7d32012-02-16 14:31:23 -0800303 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800304 public void sendBroadcast(Intent intent, String receiverPermission) {
305 throw new UnsupportedOperationException();
306 }
307
Dianne Hackbornf51f6122013-02-04 18:23:34 -0800308 /** @hide */
309 @Override
310 public void sendBroadcast(Intent intent, String receiverPermission, int appOp) {
311 throw new UnsupportedOperationException();
312 }
313
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800314 @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
Dianne Hackbornf51f6122013-02-04 18:23:34 -0800327 /** @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
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800335 @Override
Dianne Hackborn79af1dd2012-08-16 16:42:52 -0700336 public void sendBroadcastAsUser(Intent intent, UserHandle user) {
Dianne Hackborn7d19e022012-08-07 19:12:33 -0700337 throw new UnsupportedOperationException();
338 }
339
340 @Override
Dianne Hackborn5ac72a22012-08-29 18:32:08 -0700341 public void sendBroadcastAsUser(Intent intent, UserHandle user,
342 String receiverPermission) {
343 throw new UnsupportedOperationException();
344 }
345
346 @Override
Dianne Hackborn79af1dd2012-08-16 16:42:52 -0700347 public void sendOrderedBroadcastAsUser(Intent intent, UserHandle user,
Dianne Hackborn5ac72a22012-08-29 18:32:08 -0700348 String receiverPermission, BroadcastReceiver resultReceiver, Handler scheduler,
Dianne Hackborn7d19e022012-08-07 19:12:33 -0700349 int initialCode, String initialData, Bundle initialExtras) {
350 throw new UnsupportedOperationException();
351 }
352
353 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800354 public void sendStickyBroadcast(Intent intent) {
355 throw new UnsupportedOperationException();
356 }
357
358 @Override
Dianne Hackbornefa199f2009-09-19 12:03:15 -0700359 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
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800366 public void removeStickyBroadcast(Intent intent) {
367 throw new UnsupportedOperationException();
368 }
369
370 @Override
Dianne Hackborn5ac72a22012-08-29 18:32:08 -0700371 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
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800389 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
Dianne Hackborn20e80982012-08-31 19:00:44 -0700399 /** @hide */
400 @Override
401 public Intent registerReceiverAsUser(BroadcastReceiver receiver, UserHandle user,
402 IntentFilter filter, String broadcastPermission, Handler scheduler) {
403 throw new UnsupportedOperationException();
404 }
405
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800406 @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
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700421 /** @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
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800433 @Override
434 public boolean bindService(Intent service, ServiceConnection conn, int flags) {
435 throw new UnsupportedOperationException();
436 }
437
Amith Yamasani37ce3a82012-02-06 12:04:42 -0800438 /** @hide */
439 @Override
Amith Yamasani27b89e62013-01-16 12:30:11 -0800440 public boolean bindServiceAsUser(Intent service, ServiceConnection conn, int flags,
441 UserHandle user) {
Amith Yamasani37ce3a82012-02-06 12:04:42 -0800442 throw new UnsupportedOperationException();
443 }
444
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800445 @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 }
Romain Guy870e09f2009-07-06 16:35:25 -0700552
Jeff Sharkey6d515712012-09-20 16:06:08 -0700553 /** {@hide} */
554 @Override
555 public Context createPackageContextAsUser(String packageName, int flags, UserHandle user)
556 throws PackageManager.NameNotFoundException {
557 throw new UnsupportedOperationException();
558 }
559
Jim Millera75a8832013-02-07 16:53:32 -0800560 /** {@hide} */
561 @Override
562 public int getUserId() {
563 throw new UnsupportedOperationException();
564 }
565
Romain Guy870e09f2009-07-06 16:35:25 -0700566 @Override
Dianne Hackborn756220b2012-08-14 16:45:30 -0700567 public Context createConfigurationContext(Configuration overrideConfiguration) {
568 throw new UnsupportedOperationException();
569 }
570
571 @Override
Jeff Browna492c3a2012-08-23 19:48:44 -0700572 public Context createDisplayContext(Display display) {
573 throw new UnsupportedOperationException();
574 }
575
576 @Override
Romain Guy870e09f2009-07-06 16:35:25 -0700577 public boolean isRestricted() {
578 throw new UnsupportedOperationException();
579 }
Jeff Brown98365d72012-08-19 20:30:52 -0700580
581 /** @hide */
582 @Override
Craig Mautner48d0d182013-06-11 07:53:06 -0700583 public DisplayAdjustments getDisplayAdjustments(int displayId) {
Jeff Brown98365d72012-08-19 20:30:52 -0700584 throw new UnsupportedOperationException();
585 }
Jeff Sharkey7f392de2013-08-11 17:42:17 -0700586
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 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800601}