blob: 44077ae2c86a699189324b65f5cbe72c56bc6c27 [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
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800115 @Override
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -0700116 public ApplicationInfo getApplicationInfo() {
117 throw new UnsupportedOperationException();
118 }
119
120 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800121 public String getPackageResourcePath() {
122 throw new UnsupportedOperationException();
123 }
124
Dianne Hackborn7f205432009-07-28 00:13:47 -0700125 /** @hide */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800126 @Override
Joe Onorato23ecae32009-06-10 17:07:15 -0700127 public File getSharedPrefsFile(String name) {
128 throw new UnsupportedOperationException();
129 }
130
131 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800132 public String getPackageCodePath() {
133 throw new UnsupportedOperationException();
134 }
135
136 @Override
137 public SharedPreferences getSharedPreferences(String name, int mode) {
138 throw new UnsupportedOperationException();
139 }
140
141 @Override
142 public FileInputStream openFileInput(String name) throws FileNotFoundException {
143 throw new UnsupportedOperationException();
144 }
145
146 @Override
147 public FileOutputStream openFileOutput(String name, int mode) throws FileNotFoundException {
148 throw new UnsupportedOperationException();
149 }
150
151 @Override
152 public boolean deleteFile(String name) {
153 throw new UnsupportedOperationException();
154 }
155
156 @Override
157 public File getFileStreamPath(String name) {
158 throw new UnsupportedOperationException();
159 }
160
161 @Override
162 public String[] fileList() {
163 throw new UnsupportedOperationException();
164 }
165
166 @Override
167 public File getFilesDir() {
168 throw new UnsupportedOperationException();
169 }
170
171 @Override
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800172 public File getExternalFilesDir(String type) {
173 throw new UnsupportedOperationException();
174 }
175
176 @Override
Dianne Hackborn805fd7e2011-01-16 18:30:29 -0800177 public File getObbDir() {
178 throw new UnsupportedOperationException();
179 }
180
181 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800182 public File getCacheDir() {
183 throw new UnsupportedOperationException();
184 }
185
186 @Override
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800187 public File getExternalCacheDir() {
188 throw new UnsupportedOperationException();
189 }
190
191 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800192 public File getDir(String name, int mode) {
193 throw new UnsupportedOperationException();
194 }
195
196 @Override
197 public SQLiteDatabase openOrCreateDatabase(String file, int mode,
198 SQLiteDatabase.CursorFactory factory) {
199 throw new UnsupportedOperationException();
200 }
201
202 @Override
Vasu Nori74f170f2010-06-01 18:06:18 -0700203 public SQLiteDatabase openOrCreateDatabase(String file, int mode,
204 SQLiteDatabase.CursorFactory factory, DatabaseErrorHandler errorHandler) {
205 throw new UnsupportedOperationException();
206 }
207
208 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800209 public File getDatabasePath(String name) {
210 throw new UnsupportedOperationException();
211 }
212
213 @Override
214 public String[] databaseList() {
215 throw new UnsupportedOperationException();
216 }
217
218 @Override
219 public boolean deleteDatabase(String name) {
220 throw new UnsupportedOperationException();
221 }
222
223 @Override
224 public Drawable getWallpaper() {
225 throw new UnsupportedOperationException();
226 }
227
228 @Override
229 public Drawable peekWallpaper() {
230 throw new UnsupportedOperationException();
231 }
232
233 @Override
234 public int getWallpaperDesiredMinimumWidth() {
235 throw new UnsupportedOperationException();
236 }
237
238 @Override
239 public int getWallpaperDesiredMinimumHeight() {
240 throw new UnsupportedOperationException();
241 }
242
243 @Override
244 public void setWallpaper(Bitmap bitmap) throws IOException {
245 throw new UnsupportedOperationException();
246 }
247
248 @Override
249 public void setWallpaper(InputStream data) throws IOException {
250 throw new UnsupportedOperationException();
251 }
252
253 @Override
254 public void clearWallpaper() {
255 throw new UnsupportedOperationException();
256 }
257
258 @Override
259 public void startActivity(Intent intent) {
260 throw new UnsupportedOperationException();
261 }
262
263 @Override
Dianne Hackborna4972e92012-03-14 10:38:05 -0700264 public void startActivity(Intent intent, Bundle options) {
265 startActivity(intent);
266 }
267
268 @Override
Dianne Hackborn621e17d2010-11-22 15:59:56 -0800269 public void startActivities(Intent[] intents) {
270 throw new UnsupportedOperationException();
271 }
272
273 @Override
Dianne Hackborna4972e92012-03-14 10:38:05 -0700274 public void startActivities(Intent[] intents, Bundle options) {
275 startActivities(intents);
276 }
277
278 @Override
Dianne Hackbornfa82f222009-09-17 15:14:12 -0700279 public void startIntentSender(IntentSender intent,
280 Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags)
281 throws IntentSender.SendIntentException {
282 throw new UnsupportedOperationException();
283 }
Dianne Hackborna4972e92012-03-14 10:38:05 -0700284
285 @Override
286 public void startIntentSender(IntentSender intent,
287 Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags,
288 Bundle options) throws IntentSender.SendIntentException {
289 startIntentSender(intent, fillInIntent, flagsMask, flagsValues, extraFlags);
290 }
Dianne Hackbornfa82f222009-09-17 15:14:12 -0700291
292 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800293 public void sendBroadcast(Intent intent) {
294 throw new UnsupportedOperationException();
295 }
296
Amith Yamasani67cf7d32012-02-16 14:31:23 -0800297 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800298 public void sendBroadcast(Intent intent, String receiverPermission) {
299 throw new UnsupportedOperationException();
300 }
301
Dianne Hackbornf51f6122013-02-04 18:23:34 -0800302 /** @hide */
303 @Override
304 public void sendBroadcast(Intent intent, String receiverPermission, int appOp) {
305 throw new UnsupportedOperationException();
306 }
307
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800308 @Override
309 public void sendOrderedBroadcast(Intent intent,
310 String receiverPermission) {
311 throw new UnsupportedOperationException();
312 }
313
314 @Override
315 public void sendOrderedBroadcast(Intent intent, String receiverPermission,
316 BroadcastReceiver resultReceiver, Handler scheduler, int initialCode, String initialData,
317 Bundle initialExtras) {
318 throw new UnsupportedOperationException();
319 }
320
Dianne Hackbornf51f6122013-02-04 18:23:34 -0800321 /** @hide */
322 @Override
323 public void sendOrderedBroadcast(Intent intent, String receiverPermission, int appOp,
324 BroadcastReceiver resultReceiver, Handler scheduler, int initialCode, String initialData,
325 Bundle initialExtras) {
326 throw new UnsupportedOperationException();
327 }
328
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800329 @Override
Dianne Hackborn79af1dd2012-08-16 16:42:52 -0700330 public void sendBroadcastAsUser(Intent intent, UserHandle user) {
Dianne Hackborn7d19e022012-08-07 19:12:33 -0700331 throw new UnsupportedOperationException();
332 }
333
334 @Override
Dianne Hackborn5ac72a22012-08-29 18:32:08 -0700335 public void sendBroadcastAsUser(Intent intent, UserHandle user,
336 String receiverPermission) {
337 throw new UnsupportedOperationException();
338 }
339
340 @Override
Dianne Hackborn79af1dd2012-08-16 16:42:52 -0700341 public void sendOrderedBroadcastAsUser(Intent intent, UserHandle user,
Dianne Hackborn5ac72a22012-08-29 18:32:08 -0700342 String receiverPermission, BroadcastReceiver resultReceiver, Handler scheduler,
Dianne Hackborn7d19e022012-08-07 19:12:33 -0700343 int initialCode, String initialData, Bundle initialExtras) {
344 throw new UnsupportedOperationException();
345 }
346
347 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800348 public void sendStickyBroadcast(Intent intent) {
349 throw new UnsupportedOperationException();
350 }
351
352 @Override
Dianne Hackbornefa199f2009-09-19 12:03:15 -0700353 public void sendStickyOrderedBroadcast(Intent intent,
354 BroadcastReceiver resultReceiver, Handler scheduler, int initialCode, String initialData,
355 Bundle initialExtras) {
356 throw new UnsupportedOperationException();
357 }
358
359 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800360 public void removeStickyBroadcast(Intent intent) {
361 throw new UnsupportedOperationException();
362 }
363
364 @Override
Dianne Hackborn5ac72a22012-08-29 18:32:08 -0700365 public void sendStickyBroadcastAsUser(Intent intent, UserHandle user) {
366 throw new UnsupportedOperationException();
367 }
368
369 @Override
370 public void sendStickyOrderedBroadcastAsUser(Intent intent,
371 UserHandle user, BroadcastReceiver resultReceiver,
372 Handler scheduler, int initialCode, String initialData,
373 Bundle initialExtras) {
374 throw new UnsupportedOperationException();
375 }
376
377 @Override
378 public void removeStickyBroadcastAsUser(Intent intent, UserHandle user) {
379 throw new UnsupportedOperationException();
380 }
381
382 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800383 public Intent registerReceiver(BroadcastReceiver receiver, IntentFilter filter) {
384 throw new UnsupportedOperationException();
385 }
386
387 @Override
388 public Intent registerReceiver(BroadcastReceiver receiver, IntentFilter filter,
389 String broadcastPermission, Handler scheduler) {
390 throw new UnsupportedOperationException();
391 }
392
Dianne Hackborn20e80982012-08-31 19:00:44 -0700393 /** @hide */
394 @Override
395 public Intent registerReceiverAsUser(BroadcastReceiver receiver, UserHandle user,
396 IntentFilter filter, String broadcastPermission, Handler scheduler) {
397 throw new UnsupportedOperationException();
398 }
399
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800400 @Override
401 public void unregisterReceiver(BroadcastReceiver receiver) {
402 throw new UnsupportedOperationException();
403 }
404
405 @Override
406 public ComponentName startService(Intent service) {
407 throw new UnsupportedOperationException();
408 }
409
410 @Override
411 public boolean stopService(Intent service) {
412 throw new UnsupportedOperationException();
413 }
414
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700415 /** @hide */
416 @Override
417 public ComponentName startServiceAsUser(Intent service, UserHandle user) {
418 throw new UnsupportedOperationException();
419 }
420
421 /** @hide */
422 @Override
423 public boolean stopServiceAsUser(Intent service, UserHandle user) {
424 throw new UnsupportedOperationException();
425 }
426
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800427 @Override
428 public boolean bindService(Intent service, ServiceConnection conn, int flags) {
429 throw new UnsupportedOperationException();
430 }
431
Amith Yamasani37ce3a82012-02-06 12:04:42 -0800432 /** @hide */
433 @Override
Amith Yamasani27b89e62013-01-16 12:30:11 -0800434 public boolean bindServiceAsUser(Intent service, ServiceConnection conn, int flags,
435 UserHandle user) {
Amith Yamasani37ce3a82012-02-06 12:04:42 -0800436 throw new UnsupportedOperationException();
437 }
438
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800439 @Override
440 public void unbindService(ServiceConnection conn) {
441 throw new UnsupportedOperationException();
442 }
443
444 @Override
445 public boolean startInstrumentation(ComponentName className,
446 String profileFile, Bundle arguments) {
447 throw new UnsupportedOperationException();
448 }
449
450 @Override
451 public Object getSystemService(String name) {
452 throw new UnsupportedOperationException();
453 }
454
455 @Override
456 public int checkPermission(String permission, int pid, int uid) {
457 throw new UnsupportedOperationException();
458 }
459
460 @Override
461 public int checkCallingPermission(String permission) {
462 throw new UnsupportedOperationException();
463 }
464
465 @Override
466 public int checkCallingOrSelfPermission(String permission) {
467 throw new UnsupportedOperationException();
468 }
469
470 @Override
471 public void enforcePermission(
472 String permission, int pid, int uid, String message) {
473 throw new UnsupportedOperationException();
474 }
475
476 @Override
477 public void enforceCallingPermission(String permission, String message) {
478 throw new UnsupportedOperationException();
479 }
480
481 @Override
482 public void enforceCallingOrSelfPermission(String permission, String message) {
483 throw new UnsupportedOperationException();
484 }
485
486 @Override
487 public void grantUriPermission(String toPackage, Uri uri, int modeFlags) {
488 throw new UnsupportedOperationException();
489 }
490
491 @Override
492 public void revokeUriPermission(Uri uri, int modeFlags) {
493 throw new UnsupportedOperationException();
494 }
495
496 @Override
497 public int checkUriPermission(Uri uri, int pid, int uid, int modeFlags) {
498 throw new UnsupportedOperationException();
499 }
500
501 @Override
502 public int checkCallingUriPermission(Uri uri, int modeFlags) {
503 throw new UnsupportedOperationException();
504 }
505
506 @Override
507 public int checkCallingOrSelfUriPermission(Uri uri, int modeFlags) {
508 throw new UnsupportedOperationException();
509 }
510
511 @Override
512 public int checkUriPermission(Uri uri, String readPermission,
513 String writePermission, int pid, int uid, int modeFlags) {
514 throw new UnsupportedOperationException();
515 }
516
517 @Override
518 public void enforceUriPermission(
519 Uri uri, int pid, int uid, int modeFlags, String message) {
520 throw new UnsupportedOperationException();
521 }
522
523 @Override
524 public void enforceCallingUriPermission(
525 Uri uri, int modeFlags, String message) {
526 throw new UnsupportedOperationException();
527 }
528
529 @Override
530 public void enforceCallingOrSelfUriPermission(
531 Uri uri, int modeFlags, String message) {
532 throw new UnsupportedOperationException();
533 }
534
535 public void enforceUriPermission(
536 Uri uri, String readPermission, String writePermission,
537 int pid, int uid, int modeFlags, String message) {
538 throw new UnsupportedOperationException();
539 }
540
541 @Override
542 public Context createPackageContext(String packageName, int flags)
543 throws PackageManager.NameNotFoundException {
544 throw new UnsupportedOperationException();
545 }
Romain Guy870e09f2009-07-06 16:35:25 -0700546
Jeff Sharkey6d515712012-09-20 16:06:08 -0700547 /** {@hide} */
548 @Override
549 public Context createPackageContextAsUser(String packageName, int flags, UserHandle user)
550 throws PackageManager.NameNotFoundException {
551 throw new UnsupportedOperationException();
552 }
553
Jim Millera75a8832013-02-07 16:53:32 -0800554 /** {@hide} */
555 @Override
556 public int getUserId() {
557 throw new UnsupportedOperationException();
558 }
559
Romain Guy870e09f2009-07-06 16:35:25 -0700560 @Override
Dianne Hackborn756220b2012-08-14 16:45:30 -0700561 public Context createConfigurationContext(Configuration overrideConfiguration) {
562 throw new UnsupportedOperationException();
563 }
564
565 @Override
Jeff Browna492c3a2012-08-23 19:48:44 -0700566 public Context createDisplayContext(Display display) {
567 throw new UnsupportedOperationException();
568 }
569
570 @Override
Romain Guy870e09f2009-07-06 16:35:25 -0700571 public boolean isRestricted() {
572 throw new UnsupportedOperationException();
573 }
Jeff Brown98365d72012-08-19 20:30:52 -0700574
575 /** @hide */
576 @Override
Craig Mautner48d0d182013-06-11 07:53:06 -0700577 public DisplayAdjustments getDisplayAdjustments(int displayId) {
Jeff Brown98365d72012-08-19 20:30:52 -0700578 throw new UnsupportedOperationException();
579 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800580}