blob: 248fbf1985e884abc38198ae629053d433b6b295 [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;
Jeff Brown98365d72012-08-19 20:30:52 -070042import android.view.CompatibilityInfoHolder;
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
302 @Override
303 public void sendOrderedBroadcast(Intent intent,
304 String receiverPermission) {
305 throw new UnsupportedOperationException();
306 }
307
308 @Override
309 public void sendOrderedBroadcast(Intent intent, String receiverPermission,
310 BroadcastReceiver resultReceiver, Handler scheduler, int initialCode, String initialData,
311 Bundle initialExtras) {
312 throw new UnsupportedOperationException();
313 }
314
315 @Override
Dianne Hackborn79af1dd2012-08-16 16:42:52 -0700316 public void sendBroadcastAsUser(Intent intent, UserHandle user) {
Dianne Hackborn7d19e022012-08-07 19:12:33 -0700317 throw new UnsupportedOperationException();
318 }
319
320 @Override
Dianne Hackborn5ac72a22012-08-29 18:32:08 -0700321 public void sendBroadcastAsUser(Intent intent, UserHandle user,
322 String receiverPermission) {
323 throw new UnsupportedOperationException();
324 }
325
326 @Override
Dianne Hackborn79af1dd2012-08-16 16:42:52 -0700327 public void sendOrderedBroadcastAsUser(Intent intent, UserHandle user,
Dianne Hackborn5ac72a22012-08-29 18:32:08 -0700328 String receiverPermission, BroadcastReceiver resultReceiver, Handler scheduler,
Dianne Hackborn7d19e022012-08-07 19:12:33 -0700329 int initialCode, String initialData, Bundle initialExtras) {
330 throw new UnsupportedOperationException();
331 }
332
333 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800334 public void sendStickyBroadcast(Intent intent) {
335 throw new UnsupportedOperationException();
336 }
337
338 @Override
Dianne Hackbornefa199f2009-09-19 12:03:15 -0700339 public void sendStickyOrderedBroadcast(Intent intent,
340 BroadcastReceiver resultReceiver, Handler scheduler, int initialCode, String initialData,
341 Bundle initialExtras) {
342 throw new UnsupportedOperationException();
343 }
344
345 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800346 public void removeStickyBroadcast(Intent intent) {
347 throw new UnsupportedOperationException();
348 }
349
350 @Override
Dianne Hackborn5ac72a22012-08-29 18:32:08 -0700351 public void sendStickyBroadcastAsUser(Intent intent, UserHandle user) {
352 throw new UnsupportedOperationException();
353 }
354
355 @Override
356 public void sendStickyOrderedBroadcastAsUser(Intent intent,
357 UserHandle user, BroadcastReceiver resultReceiver,
358 Handler scheduler, int initialCode, String initialData,
359 Bundle initialExtras) {
360 throw new UnsupportedOperationException();
361 }
362
363 @Override
364 public void removeStickyBroadcastAsUser(Intent intent, UserHandle user) {
365 throw new UnsupportedOperationException();
366 }
367
368 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800369 public Intent registerReceiver(BroadcastReceiver receiver, IntentFilter filter) {
370 throw new UnsupportedOperationException();
371 }
372
373 @Override
374 public Intent registerReceiver(BroadcastReceiver receiver, IntentFilter filter,
375 String broadcastPermission, Handler scheduler) {
376 throw new UnsupportedOperationException();
377 }
378
Dianne Hackborn20e80982012-08-31 19:00:44 -0700379 /** @hide */
380 @Override
381 public Intent registerReceiverAsUser(BroadcastReceiver receiver, UserHandle user,
382 IntentFilter filter, String broadcastPermission, Handler scheduler) {
383 throw new UnsupportedOperationException();
384 }
385
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800386 @Override
387 public void unregisterReceiver(BroadcastReceiver receiver) {
388 throw new UnsupportedOperationException();
389 }
390
391 @Override
392 public ComponentName startService(Intent service) {
393 throw new UnsupportedOperationException();
394 }
395
396 @Override
397 public boolean stopService(Intent service) {
398 throw new UnsupportedOperationException();
399 }
400
Dianne Hackborn7767eac2012-08-23 18:25:40 -0700401 /** @hide */
402 @Override
403 public ComponentName startServiceAsUser(Intent service, UserHandle user) {
404 throw new UnsupportedOperationException();
405 }
406
407 /** @hide */
408 @Override
409 public boolean stopServiceAsUser(Intent service, UserHandle user) {
410 throw new UnsupportedOperationException();
411 }
412
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800413 @Override
414 public boolean bindService(Intent service, ServiceConnection conn, int flags) {
415 throw new UnsupportedOperationException();
416 }
417
Amith Yamasani37ce3a82012-02-06 12:04:42 -0800418 /** @hide */
419 @Override
Amith Yamasani27b89e62013-01-16 12:30:11 -0800420 public boolean bindServiceAsUser(Intent service, ServiceConnection conn, int flags,
421 UserHandle user) {
Amith Yamasani37ce3a82012-02-06 12:04:42 -0800422 throw new UnsupportedOperationException();
423 }
424
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800425 @Override
426 public void unbindService(ServiceConnection conn) {
427 throw new UnsupportedOperationException();
428 }
429
430 @Override
431 public boolean startInstrumentation(ComponentName className,
432 String profileFile, Bundle arguments) {
433 throw new UnsupportedOperationException();
434 }
435
436 @Override
437 public Object getSystemService(String name) {
438 throw new UnsupportedOperationException();
439 }
440
441 @Override
442 public int checkPermission(String permission, int pid, int uid) {
443 throw new UnsupportedOperationException();
444 }
445
446 @Override
447 public int checkCallingPermission(String permission) {
448 throw new UnsupportedOperationException();
449 }
450
451 @Override
452 public int checkCallingOrSelfPermission(String permission) {
453 throw new UnsupportedOperationException();
454 }
455
456 @Override
457 public void enforcePermission(
458 String permission, int pid, int uid, String message) {
459 throw new UnsupportedOperationException();
460 }
461
462 @Override
463 public void enforceCallingPermission(String permission, String message) {
464 throw new UnsupportedOperationException();
465 }
466
467 @Override
468 public void enforceCallingOrSelfPermission(String permission, String message) {
469 throw new UnsupportedOperationException();
470 }
471
472 @Override
473 public void grantUriPermission(String toPackage, Uri uri, int modeFlags) {
474 throw new UnsupportedOperationException();
475 }
476
477 @Override
478 public void revokeUriPermission(Uri uri, int modeFlags) {
479 throw new UnsupportedOperationException();
480 }
481
482 @Override
483 public int checkUriPermission(Uri uri, int pid, int uid, int modeFlags) {
484 throw new UnsupportedOperationException();
485 }
486
487 @Override
488 public int checkCallingUriPermission(Uri uri, int modeFlags) {
489 throw new UnsupportedOperationException();
490 }
491
492 @Override
493 public int checkCallingOrSelfUriPermission(Uri uri, int modeFlags) {
494 throw new UnsupportedOperationException();
495 }
496
497 @Override
498 public int checkUriPermission(Uri uri, String readPermission,
499 String writePermission, int pid, int uid, int modeFlags) {
500 throw new UnsupportedOperationException();
501 }
502
503 @Override
504 public void enforceUriPermission(
505 Uri uri, int pid, int uid, int modeFlags, String message) {
506 throw new UnsupportedOperationException();
507 }
508
509 @Override
510 public void enforceCallingUriPermission(
511 Uri uri, int modeFlags, String message) {
512 throw new UnsupportedOperationException();
513 }
514
515 @Override
516 public void enforceCallingOrSelfUriPermission(
517 Uri uri, int modeFlags, String message) {
518 throw new UnsupportedOperationException();
519 }
520
521 public void enforceUriPermission(
522 Uri uri, String readPermission, String writePermission,
523 int pid, int uid, int modeFlags, String message) {
524 throw new UnsupportedOperationException();
525 }
526
527 @Override
528 public Context createPackageContext(String packageName, int flags)
529 throws PackageManager.NameNotFoundException {
530 throw new UnsupportedOperationException();
531 }
Romain Guy870e09f2009-07-06 16:35:25 -0700532
Jeff Sharkey6d515712012-09-20 16:06:08 -0700533 /** {@hide} */
534 @Override
535 public Context createPackageContextAsUser(String packageName, int flags, UserHandle user)
536 throws PackageManager.NameNotFoundException {
537 throw new UnsupportedOperationException();
538 }
539
Romain Guy870e09f2009-07-06 16:35:25 -0700540 @Override
Dianne Hackborn756220b2012-08-14 16:45:30 -0700541 public Context createConfigurationContext(Configuration overrideConfiguration) {
542 throw new UnsupportedOperationException();
543 }
544
545 @Override
Jeff Browna492c3a2012-08-23 19:48:44 -0700546 public Context createDisplayContext(Display display) {
547 throw new UnsupportedOperationException();
548 }
549
550 @Override
Romain Guy870e09f2009-07-06 16:35:25 -0700551 public boolean isRestricted() {
552 throw new UnsupportedOperationException();
553 }
Jeff Brown98365d72012-08-19 20:30:52 -0700554
555 /** @hide */
556 @Override
Jeff Browna492c3a2012-08-23 19:48:44 -0700557 public CompatibilityInfoHolder getCompatibilityInfo(int displayId) {
Jeff Brown98365d72012-08-19 20:30:52 -0700558 throw new UnsupportedOperationException();
559 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800560}