blob: 12ad4feabd3e9860fc52d2f637f5d293a13557d6 [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;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080043
44import java.io.File;
45import java.io.FileInputStream;
46import java.io.FileNotFoundException;
47import java.io.FileOutputStream;
48import java.io.IOException;
49import java.io.InputStream;
50
51/**
52 * A mock {@link android.content.Context} class. All methods are non-functional and throw
53 * {@link java.lang.UnsupportedOperationException}. You can use this to inject other dependencies,
54 * mocks, or monitors into the classes you are testing.
55 */
56public class MockContext extends Context {
57
58 @Override
59 public AssetManager getAssets() {
60 throw new UnsupportedOperationException();
61 }
62
63 @Override
64 public Resources getResources() {
65 throw new UnsupportedOperationException();
66 }
67
68 @Override
69 public PackageManager getPackageManager() {
70 throw new UnsupportedOperationException();
71 }
72
73 @Override
74 public ContentResolver getContentResolver() {
75 throw new UnsupportedOperationException();
76 }
77
78 @Override
79 public Looper getMainLooper() {
80 throw new UnsupportedOperationException();
81 }
82
83 @Override
84 public Context getApplicationContext() {
85 throw new UnsupportedOperationException();
86 }
87
88 @Override
89 public void setTheme(int resid) {
90 throw new UnsupportedOperationException();
91 }
92
93 @Override
94 public Resources.Theme getTheme() {
95 throw new UnsupportedOperationException();
96 }
97
98 @Override
99 public ClassLoader getClassLoader() {
100 throw new UnsupportedOperationException();
101 }
102
103 @Override
104 public String getPackageName() {
105 throw new UnsupportedOperationException();
106 }
107
108 @Override
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -0700109 public ApplicationInfo getApplicationInfo() {
110 throw new UnsupportedOperationException();
111 }
112
113 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800114 public String getPackageResourcePath() {
115 throw new UnsupportedOperationException();
116 }
117
Dianne Hackborn7f205432009-07-28 00:13:47 -0700118 /** @hide */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800119 @Override
Joe Onorato23ecae32009-06-10 17:07:15 -0700120 public File getSharedPrefsFile(String name) {
121 throw new UnsupportedOperationException();
122 }
123
124 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800125 public String getPackageCodePath() {
126 throw new UnsupportedOperationException();
127 }
128
129 @Override
130 public SharedPreferences getSharedPreferences(String name, int mode) {
131 throw new UnsupportedOperationException();
132 }
133
134 @Override
135 public FileInputStream openFileInput(String name) throws FileNotFoundException {
136 throw new UnsupportedOperationException();
137 }
138
139 @Override
140 public FileOutputStream openFileOutput(String name, int mode) throws FileNotFoundException {
141 throw new UnsupportedOperationException();
142 }
143
144 @Override
145 public boolean deleteFile(String name) {
146 throw new UnsupportedOperationException();
147 }
148
149 @Override
150 public File getFileStreamPath(String name) {
151 throw new UnsupportedOperationException();
152 }
153
154 @Override
155 public String[] fileList() {
156 throw new UnsupportedOperationException();
157 }
158
159 @Override
160 public File getFilesDir() {
161 throw new UnsupportedOperationException();
162 }
163
164 @Override
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800165 public File getExternalFilesDir(String type) {
166 throw new UnsupportedOperationException();
167 }
168
169 @Override
Dianne Hackborn805fd7e2011-01-16 18:30:29 -0800170 public File getObbDir() {
171 throw new UnsupportedOperationException();
172 }
173
174 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800175 public File getCacheDir() {
176 throw new UnsupportedOperationException();
177 }
178
179 @Override
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800180 public File getExternalCacheDir() {
181 throw new UnsupportedOperationException();
182 }
183
184 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800185 public File getDir(String name, int mode) {
186 throw new UnsupportedOperationException();
187 }
188
189 @Override
190 public SQLiteDatabase openOrCreateDatabase(String file, int mode,
191 SQLiteDatabase.CursorFactory factory) {
192 throw new UnsupportedOperationException();
193 }
194
195 @Override
Vasu Nori74f170f2010-06-01 18:06:18 -0700196 public SQLiteDatabase openOrCreateDatabase(String file, int mode,
197 SQLiteDatabase.CursorFactory factory, DatabaseErrorHandler errorHandler) {
198 throw new UnsupportedOperationException();
199 }
200
201 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800202 public File getDatabasePath(String name) {
203 throw new UnsupportedOperationException();
204 }
205
206 @Override
207 public String[] databaseList() {
208 throw new UnsupportedOperationException();
209 }
210
211 @Override
212 public boolean deleteDatabase(String name) {
213 throw new UnsupportedOperationException();
214 }
215
216 @Override
217 public Drawable getWallpaper() {
218 throw new UnsupportedOperationException();
219 }
220
221 @Override
222 public Drawable peekWallpaper() {
223 throw new UnsupportedOperationException();
224 }
225
226 @Override
227 public int getWallpaperDesiredMinimumWidth() {
228 throw new UnsupportedOperationException();
229 }
230
231 @Override
232 public int getWallpaperDesiredMinimumHeight() {
233 throw new UnsupportedOperationException();
234 }
235
236 @Override
237 public void setWallpaper(Bitmap bitmap) throws IOException {
238 throw new UnsupportedOperationException();
239 }
240
241 @Override
242 public void setWallpaper(InputStream data) throws IOException {
243 throw new UnsupportedOperationException();
244 }
245
246 @Override
247 public void clearWallpaper() {
248 throw new UnsupportedOperationException();
249 }
250
251 @Override
252 public void startActivity(Intent intent) {
253 throw new UnsupportedOperationException();
254 }
255
256 @Override
Dianne Hackborna4972e92012-03-14 10:38:05 -0700257 public void startActivity(Intent intent, Bundle options) {
258 startActivity(intent);
259 }
260
261 @Override
Dianne Hackborn621e17d2010-11-22 15:59:56 -0800262 public void startActivities(Intent[] intents) {
263 throw new UnsupportedOperationException();
264 }
265
266 @Override
Dianne Hackborna4972e92012-03-14 10:38:05 -0700267 public void startActivities(Intent[] intents, Bundle options) {
268 startActivities(intents);
269 }
270
271 @Override
Dianne Hackbornfa82f222009-09-17 15:14:12 -0700272 public void startIntentSender(IntentSender intent,
273 Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags)
274 throws IntentSender.SendIntentException {
275 throw new UnsupportedOperationException();
276 }
Dianne Hackborna4972e92012-03-14 10:38:05 -0700277
278 @Override
279 public void startIntentSender(IntentSender intent,
280 Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags,
281 Bundle options) throws IntentSender.SendIntentException {
282 startIntentSender(intent, fillInIntent, flagsMask, flagsValues, extraFlags);
283 }
Dianne Hackbornfa82f222009-09-17 15:14:12 -0700284
285 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800286 public void sendBroadcast(Intent intent) {
287 throw new UnsupportedOperationException();
288 }
289
Amith Yamasani67cf7d32012-02-16 14:31:23 -0800290 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800291 public void sendBroadcast(Intent intent, String receiverPermission) {
292 throw new UnsupportedOperationException();
293 }
294
295 @Override
296 public void sendOrderedBroadcast(Intent intent,
297 String receiverPermission) {
298 throw new UnsupportedOperationException();
299 }
300
301 @Override
302 public void sendOrderedBroadcast(Intent intent, String receiverPermission,
303 BroadcastReceiver resultReceiver, Handler scheduler, int initialCode, String initialData,
304 Bundle initialExtras) {
305 throw new UnsupportedOperationException();
306 }
307
308 @Override
Dianne Hackborn79af1dd2012-08-16 16:42:52 -0700309 public void sendBroadcastAsUser(Intent intent, UserHandle user) {
Dianne Hackborn7d19e022012-08-07 19:12:33 -0700310 throw new UnsupportedOperationException();
311 }
312
313 @Override
Dianne Hackborn79af1dd2012-08-16 16:42:52 -0700314 public void sendOrderedBroadcastAsUser(Intent intent, UserHandle user,
Dianne Hackborn7d19e022012-08-07 19:12:33 -0700315 BroadcastReceiver resultReceiver, Handler scheduler,
316 int initialCode, String initialData, Bundle initialExtras) {
317 throw new UnsupportedOperationException();
318 }
319
320 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800321 public void sendStickyBroadcast(Intent intent) {
322 throw new UnsupportedOperationException();
323 }
324
325 @Override
Dianne Hackbornefa199f2009-09-19 12:03:15 -0700326 public void sendStickyOrderedBroadcast(Intent intent,
327 BroadcastReceiver resultReceiver, Handler scheduler, int initialCode, String initialData,
328 Bundle initialExtras) {
329 throw new UnsupportedOperationException();
330 }
331
332 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800333 public void removeStickyBroadcast(Intent intent) {
334 throw new UnsupportedOperationException();
335 }
336
337 @Override
338 public Intent registerReceiver(BroadcastReceiver receiver, IntentFilter filter) {
339 throw new UnsupportedOperationException();
340 }
341
342 @Override
343 public Intent registerReceiver(BroadcastReceiver receiver, IntentFilter filter,
344 String broadcastPermission, Handler scheduler) {
345 throw new UnsupportedOperationException();
346 }
347
348 @Override
349 public void unregisterReceiver(BroadcastReceiver receiver) {
350 throw new UnsupportedOperationException();
351 }
352
353 @Override
354 public ComponentName startService(Intent service) {
355 throw new UnsupportedOperationException();
356 }
357
358 @Override
359 public boolean stopService(Intent service) {
360 throw new UnsupportedOperationException();
361 }
362
363 @Override
364 public boolean bindService(Intent service, ServiceConnection conn, int flags) {
365 throw new UnsupportedOperationException();
366 }
367
Amith Yamasani37ce3a82012-02-06 12:04:42 -0800368 /** @hide */
369 @Override
370 public boolean bindService(Intent service, ServiceConnection conn, int flags, int userId) {
371 throw new UnsupportedOperationException();
372 }
373
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800374 @Override
375 public void unbindService(ServiceConnection conn) {
376 throw new UnsupportedOperationException();
377 }
378
379 @Override
380 public boolean startInstrumentation(ComponentName className,
381 String profileFile, Bundle arguments) {
382 throw new UnsupportedOperationException();
383 }
384
385 @Override
386 public Object getSystemService(String name) {
387 throw new UnsupportedOperationException();
388 }
389
390 @Override
391 public int checkPermission(String permission, int pid, int uid) {
392 throw new UnsupportedOperationException();
393 }
394
395 @Override
396 public int checkCallingPermission(String permission) {
397 throw new UnsupportedOperationException();
398 }
399
400 @Override
401 public int checkCallingOrSelfPermission(String permission) {
402 throw new UnsupportedOperationException();
403 }
404
405 @Override
406 public void enforcePermission(
407 String permission, int pid, int uid, String message) {
408 throw new UnsupportedOperationException();
409 }
410
411 @Override
412 public void enforceCallingPermission(String permission, String message) {
413 throw new UnsupportedOperationException();
414 }
415
416 @Override
417 public void enforceCallingOrSelfPermission(String permission, String message) {
418 throw new UnsupportedOperationException();
419 }
420
421 @Override
422 public void grantUriPermission(String toPackage, Uri uri, int modeFlags) {
423 throw new UnsupportedOperationException();
424 }
425
426 @Override
427 public void revokeUriPermission(Uri uri, int modeFlags) {
428 throw new UnsupportedOperationException();
429 }
430
431 @Override
432 public int checkUriPermission(Uri uri, int pid, int uid, int modeFlags) {
433 throw new UnsupportedOperationException();
434 }
435
436 @Override
437 public int checkCallingUriPermission(Uri uri, int modeFlags) {
438 throw new UnsupportedOperationException();
439 }
440
441 @Override
442 public int checkCallingOrSelfUriPermission(Uri uri, int modeFlags) {
443 throw new UnsupportedOperationException();
444 }
445
446 @Override
447 public int checkUriPermission(Uri uri, String readPermission,
448 String writePermission, int pid, int uid, int modeFlags) {
449 throw new UnsupportedOperationException();
450 }
451
452 @Override
453 public void enforceUriPermission(
454 Uri uri, int pid, int uid, int modeFlags, String message) {
455 throw new UnsupportedOperationException();
456 }
457
458 @Override
459 public void enforceCallingUriPermission(
460 Uri uri, int modeFlags, String message) {
461 throw new UnsupportedOperationException();
462 }
463
464 @Override
465 public void enforceCallingOrSelfUriPermission(
466 Uri uri, int modeFlags, String message) {
467 throw new UnsupportedOperationException();
468 }
469
470 public void enforceUriPermission(
471 Uri uri, String readPermission, String writePermission,
472 int pid, int uid, int modeFlags, String message) {
473 throw new UnsupportedOperationException();
474 }
475
476 @Override
477 public Context createPackageContext(String packageName, int flags)
478 throws PackageManager.NameNotFoundException {
479 throw new UnsupportedOperationException();
480 }
Romain Guy870e09f2009-07-06 16:35:25 -0700481
482 @Override
Dianne Hackborn756220b2012-08-14 16:45:30 -0700483 public Context createConfigurationContext(Configuration overrideConfiguration) {
484 throw new UnsupportedOperationException();
485 }
486
487 @Override
Romain Guy870e09f2009-07-06 16:35:25 -0700488 public boolean isRestricted() {
489 throw new UnsupportedOperationException();
490 }
Jeff Brown98365d72012-08-19 20:30:52 -0700491
492 /** @hide */
493 @Override
494 public CompatibilityInfoHolder getCompatibilityInfo() {
495 throw new UnsupportedOperationException();
496 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800497}