| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package android.test.mock; |
| 18 | |
| 19 | import android.content.ComponentName; |
| 20 | import android.content.ContentResolver; |
| 21 | import android.content.Context; |
| 22 | import android.content.Intent; |
| 23 | import android.content.IntentFilter; |
| 24 | import android.content.BroadcastReceiver; |
| Dianne Hackborn | fa82f22 | 2009-09-17 15:14:12 -0700 | [diff] [blame] | 25 | import android.content.IntentSender; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 26 | import android.content.ServiceConnection; |
| 27 | import android.content.SharedPreferences; |
| Dianne Hackborn | 5c1e00b | 2009-06-18 17:10:57 -0700 | [diff] [blame] | 28 | import android.content.pm.ApplicationInfo; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 29 | import android.content.pm.PackageManager; |
| 30 | import android.content.res.AssetManager; |
| Dianne Hackborn | 756220b | 2012-08-14 16:45:30 -0700 | [diff] [blame] | 31 | import android.content.res.Configuration; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 32 | import android.content.res.Resources; |
| Vasu Nori | 74f170f | 2010-06-01 18:06:18 -0700 | [diff] [blame] | 33 | import android.database.DatabaseErrorHandler; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 34 | import android.database.sqlite.SQLiteDatabase; |
| 35 | import android.graphics.Bitmap; |
| 36 | import android.graphics.drawable.Drawable; |
| 37 | import android.net.Uri; |
| 38 | import android.os.Bundle; |
| 39 | import android.os.Handler; |
| 40 | import android.os.Looper; |
| Dianne Hackborn | 79af1dd | 2012-08-16 16:42:52 -0700 | [diff] [blame] | 41 | import android.os.UserHandle; |
| Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 42 | import android.view.CompatibilityInfoHolder; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 43 | |
| 44 | import java.io.File; |
| 45 | import java.io.FileInputStream; |
| 46 | import java.io.FileNotFoundException; |
| 47 | import java.io.FileOutputStream; |
| 48 | import java.io.IOException; |
| 49 | import 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 | */ |
| 56 | public 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 Hackborn | 5c1e00b | 2009-06-18 17:10:57 -0700 | [diff] [blame] | 109 | public ApplicationInfo getApplicationInfo() { |
| 110 | throw new UnsupportedOperationException(); |
| 111 | } |
| 112 | |
| 113 | @Override |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 114 | public String getPackageResourcePath() { |
| 115 | throw new UnsupportedOperationException(); |
| 116 | } |
| 117 | |
| Dianne Hackborn | 7f20543 | 2009-07-28 00:13:47 -0700 | [diff] [blame] | 118 | /** @hide */ |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 119 | @Override |
| Joe Onorato | 23ecae3 | 2009-06-10 17:07:15 -0700 | [diff] [blame] | 120 | public File getSharedPrefsFile(String name) { |
| 121 | throw new UnsupportedOperationException(); |
| 122 | } |
| 123 | |
| 124 | @Override |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 125 | 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 Hackborn | e83cefce | 2010-02-04 17:38:14 -0800 | [diff] [blame] | 165 | public File getExternalFilesDir(String type) { |
| 166 | throw new UnsupportedOperationException(); |
| 167 | } |
| 168 | |
| 169 | @Override |
| Dianne Hackborn | 805fd7e | 2011-01-16 18:30:29 -0800 | [diff] [blame] | 170 | public File getObbDir() { |
| 171 | throw new UnsupportedOperationException(); |
| 172 | } |
| 173 | |
| 174 | @Override |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 175 | public File getCacheDir() { |
| 176 | throw new UnsupportedOperationException(); |
| 177 | } |
| 178 | |
| 179 | @Override |
| Dianne Hackborn | e83cefce | 2010-02-04 17:38:14 -0800 | [diff] [blame] | 180 | public File getExternalCacheDir() { |
| 181 | throw new UnsupportedOperationException(); |
| 182 | } |
| 183 | |
| 184 | @Override |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 185 | 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 Nori | 74f170f | 2010-06-01 18:06:18 -0700 | [diff] [blame] | 196 | 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 Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 202 | 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 Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 257 | public void startActivity(Intent intent, Bundle options) { |
| 258 | startActivity(intent); |
| 259 | } |
| 260 | |
| 261 | @Override |
| Dianne Hackborn | 621e17d | 2010-11-22 15:59:56 -0800 | [diff] [blame] | 262 | public void startActivities(Intent[] intents) { |
| 263 | throw new UnsupportedOperationException(); |
| 264 | } |
| 265 | |
| 266 | @Override |
| Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 267 | public void startActivities(Intent[] intents, Bundle options) { |
| 268 | startActivities(intents); |
| 269 | } |
| 270 | |
| 271 | @Override |
| Dianne Hackborn | fa82f22 | 2009-09-17 15:14:12 -0700 | [diff] [blame] | 272 | public void startIntentSender(IntentSender intent, |
| 273 | Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags) |
| 274 | throws IntentSender.SendIntentException { |
| 275 | throw new UnsupportedOperationException(); |
| 276 | } |
| Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 277 | |
| 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 Hackborn | fa82f22 | 2009-09-17 15:14:12 -0700 | [diff] [blame] | 284 | |
| 285 | @Override |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 286 | public void sendBroadcast(Intent intent) { |
| 287 | throw new UnsupportedOperationException(); |
| 288 | } |
| 289 | |
| Amith Yamasani | 67cf7d3 | 2012-02-16 14:31:23 -0800 | [diff] [blame] | 290 | @Override |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 291 | 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 Hackborn | 79af1dd | 2012-08-16 16:42:52 -0700 | [diff] [blame] | 309 | public void sendBroadcastAsUser(Intent intent, UserHandle user) { |
| Dianne Hackborn | 7d19e02 | 2012-08-07 19:12:33 -0700 | [diff] [blame] | 310 | throw new UnsupportedOperationException(); |
| 311 | } |
| 312 | |
| 313 | @Override |
| Dianne Hackborn | 79af1dd | 2012-08-16 16:42:52 -0700 | [diff] [blame] | 314 | public void sendOrderedBroadcastAsUser(Intent intent, UserHandle user, |
| Dianne Hackborn | 7d19e02 | 2012-08-07 19:12:33 -0700 | [diff] [blame] | 315 | BroadcastReceiver resultReceiver, Handler scheduler, |
| 316 | int initialCode, String initialData, Bundle initialExtras) { |
| 317 | throw new UnsupportedOperationException(); |
| 318 | } |
| 319 | |
| 320 | @Override |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 321 | public void sendStickyBroadcast(Intent intent) { |
| 322 | throw new UnsupportedOperationException(); |
| 323 | } |
| 324 | |
| 325 | @Override |
| Dianne Hackborn | efa199f | 2009-09-19 12:03:15 -0700 | [diff] [blame] | 326 | 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 Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 333 | 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 | |
| Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame^] | 363 | /** @hide */ |
| 364 | @Override |
| 365 | public ComponentName startServiceAsUser(Intent service, UserHandle user) { |
| 366 | throw new UnsupportedOperationException(); |
| 367 | } |
| 368 | |
| 369 | /** @hide */ |
| 370 | @Override |
| 371 | public boolean stopServiceAsUser(Intent service, UserHandle user) { |
| 372 | throw new UnsupportedOperationException(); |
| 373 | } |
| 374 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 375 | @Override |
| 376 | public boolean bindService(Intent service, ServiceConnection conn, int flags) { |
| 377 | throw new UnsupportedOperationException(); |
| 378 | } |
| 379 | |
| Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 380 | /** @hide */ |
| 381 | @Override |
| 382 | public boolean bindService(Intent service, ServiceConnection conn, int flags, int userId) { |
| 383 | throw new UnsupportedOperationException(); |
| 384 | } |
| 385 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 386 | @Override |
| 387 | public void unbindService(ServiceConnection conn) { |
| 388 | throw new UnsupportedOperationException(); |
| 389 | } |
| 390 | |
| 391 | @Override |
| 392 | public boolean startInstrumentation(ComponentName className, |
| 393 | String profileFile, Bundle arguments) { |
| 394 | throw new UnsupportedOperationException(); |
| 395 | } |
| 396 | |
| 397 | @Override |
| 398 | public Object getSystemService(String name) { |
| 399 | throw new UnsupportedOperationException(); |
| 400 | } |
| 401 | |
| 402 | @Override |
| 403 | public int checkPermission(String permission, int pid, int uid) { |
| 404 | throw new UnsupportedOperationException(); |
| 405 | } |
| 406 | |
| 407 | @Override |
| 408 | public int checkCallingPermission(String permission) { |
| 409 | throw new UnsupportedOperationException(); |
| 410 | } |
| 411 | |
| 412 | @Override |
| 413 | public int checkCallingOrSelfPermission(String permission) { |
| 414 | throw new UnsupportedOperationException(); |
| 415 | } |
| 416 | |
| 417 | @Override |
| 418 | public void enforcePermission( |
| 419 | String permission, int pid, int uid, String message) { |
| 420 | throw new UnsupportedOperationException(); |
| 421 | } |
| 422 | |
| 423 | @Override |
| 424 | public void enforceCallingPermission(String permission, String message) { |
| 425 | throw new UnsupportedOperationException(); |
| 426 | } |
| 427 | |
| 428 | @Override |
| 429 | public void enforceCallingOrSelfPermission(String permission, String message) { |
| 430 | throw new UnsupportedOperationException(); |
| 431 | } |
| 432 | |
| 433 | @Override |
| 434 | public void grantUriPermission(String toPackage, Uri uri, int modeFlags) { |
| 435 | throw new UnsupportedOperationException(); |
| 436 | } |
| 437 | |
| 438 | @Override |
| 439 | public void revokeUriPermission(Uri uri, int modeFlags) { |
| 440 | throw new UnsupportedOperationException(); |
| 441 | } |
| 442 | |
| 443 | @Override |
| 444 | public int checkUriPermission(Uri uri, int pid, int uid, int modeFlags) { |
| 445 | throw new UnsupportedOperationException(); |
| 446 | } |
| 447 | |
| 448 | @Override |
| 449 | public int checkCallingUriPermission(Uri uri, int modeFlags) { |
| 450 | throw new UnsupportedOperationException(); |
| 451 | } |
| 452 | |
| 453 | @Override |
| 454 | public int checkCallingOrSelfUriPermission(Uri uri, int modeFlags) { |
| 455 | throw new UnsupportedOperationException(); |
| 456 | } |
| 457 | |
| 458 | @Override |
| 459 | public int checkUriPermission(Uri uri, String readPermission, |
| 460 | String writePermission, int pid, int uid, int modeFlags) { |
| 461 | throw new UnsupportedOperationException(); |
| 462 | } |
| 463 | |
| 464 | @Override |
| 465 | public void enforceUriPermission( |
| 466 | Uri uri, int pid, int uid, int modeFlags, String message) { |
| 467 | throw new UnsupportedOperationException(); |
| 468 | } |
| 469 | |
| 470 | @Override |
| 471 | public void enforceCallingUriPermission( |
| 472 | Uri uri, int modeFlags, String message) { |
| 473 | throw new UnsupportedOperationException(); |
| 474 | } |
| 475 | |
| 476 | @Override |
| 477 | public void enforceCallingOrSelfUriPermission( |
| 478 | Uri uri, int modeFlags, String message) { |
| 479 | throw new UnsupportedOperationException(); |
| 480 | } |
| 481 | |
| 482 | public void enforceUriPermission( |
| 483 | Uri uri, String readPermission, String writePermission, |
| 484 | int pid, int uid, int modeFlags, String message) { |
| 485 | throw new UnsupportedOperationException(); |
| 486 | } |
| 487 | |
| 488 | @Override |
| 489 | public Context createPackageContext(String packageName, int flags) |
| 490 | throws PackageManager.NameNotFoundException { |
| 491 | throw new UnsupportedOperationException(); |
| 492 | } |
| Romain Guy | 870e09f | 2009-07-06 16:35:25 -0700 | [diff] [blame] | 493 | |
| 494 | @Override |
| Dianne Hackborn | 756220b | 2012-08-14 16:45:30 -0700 | [diff] [blame] | 495 | public Context createConfigurationContext(Configuration overrideConfiguration) { |
| 496 | throw new UnsupportedOperationException(); |
| 497 | } |
| 498 | |
| 499 | @Override |
| Romain Guy | 870e09f | 2009-07-06 16:35:25 -0700 | [diff] [blame] | 500 | public boolean isRestricted() { |
| 501 | throw new UnsupportedOperationException(); |
| 502 | } |
| Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 503 | |
| 504 | /** @hide */ |
| 505 | @Override |
| 506 | public CompatibilityInfoHolder getCompatibilityInfo() { |
| 507 | throw new UnsupportedOperationException(); |
| 508 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 509 | } |