The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2006 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.content; |
| 18 | |
Dianne Hackborn | 5c1e00b | 2009-06-18 17:10:57 -0700 | [diff] [blame] | 19 | import android.content.pm.ApplicationInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 20 | import android.content.pm.PackageManager; |
| 21 | import android.content.res.AssetManager; |
| 22 | import android.content.res.Resources; |
Vasu Nori | 74f170f | 2010-06-01 18:06:18 -0700 | [diff] [blame] | 23 | import android.database.DatabaseErrorHandler; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 24 | import android.database.sqlite.SQLiteDatabase; |
| 25 | import android.database.sqlite.SQLiteDatabase.CursorFactory; |
| 26 | import android.graphics.Bitmap; |
| 27 | import android.graphics.drawable.Drawable; |
| 28 | import android.net.Uri; |
| 29 | import android.os.Bundle; |
| 30 | import android.os.Handler; |
| 31 | import android.os.Looper; |
| 32 | |
| 33 | import java.io.File; |
| 34 | import java.io.FileInputStream; |
| 35 | import java.io.FileNotFoundException; |
| 36 | import java.io.FileOutputStream; |
| 37 | import java.io.IOException; |
| 38 | import java.io.InputStream; |
| 39 | |
| 40 | /** |
| 41 | * Proxying implementation of Context that simply delegates all of its calls to |
| 42 | * another Context. Can be subclassed to modify behavior without changing |
| 43 | * the original Context. |
| 44 | */ |
| 45 | public class ContextWrapper extends Context { |
| 46 | Context mBase; |
| 47 | |
| 48 | public ContextWrapper(Context base) { |
| 49 | mBase = base; |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * Set the base context for this ContextWrapper. All calls will then be |
| 54 | * delegated to the base context. Throws |
| 55 | * IllegalStateException if a base context has already been set. |
| 56 | * |
| 57 | * @param base The new base context for this wrapper. |
| 58 | */ |
| 59 | protected void attachBaseContext(Context base) { |
| 60 | if (mBase != null) { |
| 61 | throw new IllegalStateException("Base context already set"); |
| 62 | } |
| 63 | mBase = base; |
| 64 | } |
| 65 | |
| 66 | /** |
| 67 | * @return the base context as set by the constructor or setBaseContext |
| 68 | */ |
| 69 | public Context getBaseContext() { |
| 70 | return mBase; |
| 71 | } |
| 72 | |
| 73 | @Override |
| 74 | public AssetManager getAssets() { |
| 75 | return mBase.getAssets(); |
| 76 | } |
| 77 | |
| 78 | @Override |
| 79 | public Resources getResources() |
| 80 | { |
| 81 | return mBase.getResources(); |
| 82 | } |
| 83 | |
| 84 | @Override |
| 85 | public PackageManager getPackageManager() { |
| 86 | return mBase.getPackageManager(); |
| 87 | } |
| 88 | |
| 89 | @Override |
| 90 | public ContentResolver getContentResolver() { |
| 91 | return mBase.getContentResolver(); |
| 92 | } |
| 93 | |
| 94 | @Override |
| 95 | public Looper getMainLooper() { |
| 96 | return mBase.getMainLooper(); |
| 97 | } |
| 98 | |
| 99 | @Override |
| 100 | public Context getApplicationContext() { |
| 101 | return mBase.getApplicationContext(); |
| 102 | } |
| 103 | |
| 104 | @Override |
| 105 | public void setTheme(int resid) { |
| 106 | mBase.setTheme(resid); |
| 107 | } |
| 108 | |
| 109 | @Override |
| 110 | public Resources.Theme getTheme() { |
| 111 | return mBase.getTheme(); |
| 112 | } |
| 113 | |
| 114 | @Override |
| 115 | public ClassLoader getClassLoader() { |
| 116 | return mBase.getClassLoader(); |
| 117 | } |
| 118 | |
| 119 | @Override |
| 120 | public String getPackageName() { |
| 121 | return mBase.getPackageName(); |
| 122 | } |
| 123 | |
| 124 | @Override |
Dianne Hackborn | 5c1e00b | 2009-06-18 17:10:57 -0700 | [diff] [blame] | 125 | public ApplicationInfo getApplicationInfo() { |
| 126 | return mBase.getApplicationInfo(); |
| 127 | } |
| 128 | |
| 129 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 130 | public String getPackageResourcePath() { |
| 131 | return mBase.getPackageResourcePath(); |
| 132 | } |
| 133 | |
| 134 | @Override |
| 135 | public String getPackageCodePath() { |
| 136 | return mBase.getPackageCodePath(); |
| 137 | } |
| 138 | |
Dianne Hackborn | 7f20543 | 2009-07-28 00:13:47 -0700 | [diff] [blame] | 139 | /** @hide */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 140 | @Override |
Joe Onorato | 23ecae3 | 2009-06-10 17:07:15 -0700 | [diff] [blame] | 141 | public File getSharedPrefsFile(String name) { |
| 142 | return mBase.getSharedPrefsFile(name); |
| 143 | } |
| 144 | |
| 145 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 146 | public SharedPreferences getSharedPreferences(String name, int mode) { |
| 147 | return mBase.getSharedPreferences(name, mode); |
| 148 | } |
| 149 | |
| 150 | @Override |
| 151 | public FileInputStream openFileInput(String name) |
| 152 | throws FileNotFoundException { |
| 153 | return mBase.openFileInput(name); |
| 154 | } |
| 155 | |
| 156 | @Override |
| 157 | public FileOutputStream openFileOutput(String name, int mode) |
| 158 | throws FileNotFoundException { |
| 159 | return mBase.openFileOutput(name, mode); |
| 160 | } |
| 161 | |
| 162 | @Override |
| 163 | public boolean deleteFile(String name) { |
| 164 | return mBase.deleteFile(name); |
| 165 | } |
| 166 | |
| 167 | @Override |
| 168 | public File getFileStreamPath(String name) { |
| 169 | return mBase.getFileStreamPath(name); |
| 170 | } |
| 171 | |
| 172 | @Override |
| 173 | public String[] fileList() { |
| 174 | return mBase.fileList(); |
| 175 | } |
| 176 | |
| 177 | @Override |
| 178 | public File getFilesDir() { |
| 179 | return mBase.getFilesDir(); |
| 180 | } |
| 181 | |
| 182 | @Override |
Dianne Hackborn | e83cefce | 2010-02-04 17:38:14 -0800 | [diff] [blame] | 183 | public File getExternalFilesDir(String type) { |
| 184 | return mBase.getExternalFilesDir(type); |
| 185 | } |
| 186 | |
| 187 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 188 | public File getCacheDir() { |
| 189 | return mBase.getCacheDir(); |
| 190 | } |
| 191 | |
| 192 | @Override |
Dianne Hackborn | e83cefce | 2010-02-04 17:38:14 -0800 | [diff] [blame] | 193 | public File getExternalCacheDir() { |
| 194 | return mBase.getExternalCacheDir(); |
| 195 | } |
| 196 | |
| 197 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 198 | public File getDir(String name, int mode) { |
| 199 | return mBase.getDir(name, mode); |
| 200 | } |
| 201 | |
| 202 | @Override |
| 203 | public SQLiteDatabase openOrCreateDatabase(String name, int mode, CursorFactory factory) { |
| 204 | return mBase.openOrCreateDatabase(name, mode, factory); |
| 205 | } |
| 206 | |
| 207 | @Override |
Vasu Nori | 74f170f | 2010-06-01 18:06:18 -0700 | [diff] [blame] | 208 | public SQLiteDatabase openOrCreateDatabase(String name, int mode, CursorFactory factory, |
| 209 | DatabaseErrorHandler errorHandler) { |
| 210 | return mBase.openOrCreateDatabase(name, mode, factory, errorHandler); |
| 211 | } |
| 212 | |
| 213 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 214 | public boolean deleteDatabase(String name) { |
| 215 | return mBase.deleteDatabase(name); |
| 216 | } |
| 217 | |
| 218 | @Override |
| 219 | public File getDatabasePath(String name) { |
| 220 | return mBase.getDatabasePath(name); |
| 221 | } |
| 222 | |
| 223 | @Override |
| 224 | public String[] databaseList() { |
| 225 | return mBase.databaseList(); |
| 226 | } |
| 227 | |
| 228 | @Override |
| 229 | public Drawable getWallpaper() { |
| 230 | return mBase.getWallpaper(); |
| 231 | } |
| 232 | |
| 233 | @Override |
| 234 | public Drawable peekWallpaper() { |
| 235 | return mBase.peekWallpaper(); |
| 236 | } |
| 237 | |
| 238 | @Override |
| 239 | public int getWallpaperDesiredMinimumWidth() { |
| 240 | return mBase.getWallpaperDesiredMinimumWidth(); |
| 241 | } |
| 242 | |
| 243 | @Override |
| 244 | public int getWallpaperDesiredMinimumHeight() { |
| 245 | return mBase.getWallpaperDesiredMinimumHeight(); |
| 246 | } |
| 247 | |
| 248 | @Override |
| 249 | public void setWallpaper(Bitmap bitmap) throws IOException { |
| 250 | mBase.setWallpaper(bitmap); |
| 251 | } |
| 252 | |
| 253 | @Override |
| 254 | public void setWallpaper(InputStream data) throws IOException { |
| 255 | mBase.setWallpaper(data); |
| 256 | } |
| 257 | |
| 258 | @Override |
| 259 | public void clearWallpaper() throws IOException { |
| 260 | mBase.clearWallpaper(); |
| 261 | } |
| 262 | |
| 263 | @Override |
| 264 | public void startActivity(Intent intent) { |
| 265 | mBase.startActivity(intent); |
| 266 | } |
| 267 | |
| 268 | @Override |
Dianne Hackborn | fa82f22 | 2009-09-17 15:14:12 -0700 | [diff] [blame] | 269 | public void startIntentSender(IntentSender intent, |
| 270 | Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags) |
| 271 | throws IntentSender.SendIntentException { |
| 272 | mBase.startIntentSender(intent, fillInIntent, flagsMask, |
| 273 | flagsValues, extraFlags); |
| 274 | } |
| 275 | |
| 276 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 277 | public void sendBroadcast(Intent intent) { |
| 278 | mBase.sendBroadcast(intent); |
| 279 | } |
| 280 | |
| 281 | @Override |
| 282 | public void sendBroadcast(Intent intent, String receiverPermission) { |
| 283 | mBase.sendBroadcast(intent, receiverPermission); |
| 284 | } |
| 285 | |
| 286 | @Override |
| 287 | public void sendOrderedBroadcast(Intent intent, |
| 288 | String receiverPermission) { |
| 289 | mBase.sendOrderedBroadcast(intent, receiverPermission); |
| 290 | } |
| 291 | |
| 292 | @Override |
| 293 | public void sendOrderedBroadcast( |
| 294 | Intent intent, String receiverPermission, BroadcastReceiver resultReceiver, |
| 295 | Handler scheduler, int initialCode, String initialData, |
| 296 | Bundle initialExtras) { |
| 297 | mBase.sendOrderedBroadcast(intent, receiverPermission, |
| 298 | resultReceiver, scheduler, initialCode, |
| 299 | initialData, initialExtras); |
| 300 | } |
| 301 | |
| 302 | @Override |
| 303 | public void sendStickyBroadcast(Intent intent) { |
| 304 | mBase.sendStickyBroadcast(intent); |
| 305 | } |
| 306 | |
| 307 | @Override |
Dianne Hackborn | efa199f | 2009-09-19 12:03:15 -0700 | [diff] [blame] | 308 | public void sendStickyOrderedBroadcast( |
| 309 | Intent intent, BroadcastReceiver resultReceiver, |
| 310 | Handler scheduler, int initialCode, String initialData, |
| 311 | Bundle initialExtras) { |
| 312 | mBase.sendStickyOrderedBroadcast(intent, |
| 313 | resultReceiver, scheduler, initialCode, |
| 314 | initialData, initialExtras); |
| 315 | } |
| 316 | |
| 317 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 318 | public void removeStickyBroadcast(Intent intent) { |
| 319 | mBase.removeStickyBroadcast(intent); |
| 320 | } |
| 321 | |
| 322 | @Override |
| 323 | public Intent registerReceiver( |
| 324 | BroadcastReceiver receiver, IntentFilter filter) { |
| 325 | return mBase.registerReceiver(receiver, filter); |
| 326 | } |
| 327 | |
| 328 | @Override |
| 329 | public Intent registerReceiver( |
| 330 | BroadcastReceiver receiver, IntentFilter filter, |
| 331 | String broadcastPermission, Handler scheduler) { |
| 332 | return mBase.registerReceiver(receiver, filter, broadcastPermission, |
| 333 | scheduler); |
| 334 | } |
| 335 | |
| 336 | @Override |
| 337 | public void unregisterReceiver(BroadcastReceiver receiver) { |
| 338 | mBase.unregisterReceiver(receiver); |
| 339 | } |
| 340 | |
| 341 | @Override |
| 342 | public ComponentName startService(Intent service) { |
| 343 | return mBase.startService(service); |
| 344 | } |
| 345 | |
| 346 | @Override |
| 347 | public boolean stopService(Intent name) { |
| 348 | return mBase.stopService(name); |
| 349 | } |
| 350 | |
| 351 | @Override |
| 352 | public boolean bindService(Intent service, ServiceConnection conn, |
| 353 | int flags) { |
| 354 | return mBase.bindService(service, conn, flags); |
| 355 | } |
| 356 | |
| 357 | @Override |
| 358 | public void unbindService(ServiceConnection conn) { |
| 359 | mBase.unbindService(conn); |
| 360 | } |
| 361 | |
| 362 | @Override |
| 363 | public boolean startInstrumentation(ComponentName className, |
| 364 | String profileFile, Bundle arguments) { |
| 365 | return mBase.startInstrumentation(className, profileFile, arguments); |
| 366 | } |
| 367 | |
| 368 | @Override |
| 369 | public Object getSystemService(String name) { |
| 370 | return mBase.getSystemService(name); |
| 371 | } |
| 372 | |
| 373 | @Override |
| 374 | public int checkPermission(String permission, int pid, int uid) { |
| 375 | return mBase.checkPermission(permission, pid, uid); |
| 376 | } |
| 377 | |
| 378 | @Override |
| 379 | public int checkCallingPermission(String permission) { |
| 380 | return mBase.checkCallingPermission(permission); |
| 381 | } |
| 382 | |
| 383 | @Override |
| 384 | public int checkCallingOrSelfPermission(String permission) { |
| 385 | return mBase.checkCallingOrSelfPermission(permission); |
| 386 | } |
| 387 | |
| 388 | @Override |
| 389 | public void enforcePermission( |
| 390 | String permission, int pid, int uid, String message) { |
| 391 | mBase.enforcePermission(permission, pid, uid, message); |
| 392 | } |
| 393 | |
| 394 | @Override |
| 395 | public void enforceCallingPermission(String permission, String message) { |
| 396 | mBase.enforceCallingPermission(permission, message); |
| 397 | } |
| 398 | |
| 399 | @Override |
| 400 | public void enforceCallingOrSelfPermission( |
| 401 | String permission, String message) { |
| 402 | mBase.enforceCallingOrSelfPermission(permission, message); |
| 403 | } |
| 404 | |
| 405 | @Override |
| 406 | public void grantUriPermission(String toPackage, Uri uri, int modeFlags) { |
| 407 | mBase.grantUriPermission(toPackage, uri, modeFlags); |
| 408 | } |
| 409 | |
| 410 | @Override |
| 411 | public void revokeUriPermission(Uri uri, int modeFlags) { |
| 412 | mBase.revokeUriPermission(uri, modeFlags); |
| 413 | } |
| 414 | |
| 415 | @Override |
| 416 | public int checkUriPermission(Uri uri, int pid, int uid, int modeFlags) { |
| 417 | return mBase.checkUriPermission(uri, pid, uid, modeFlags); |
| 418 | } |
| 419 | |
| 420 | @Override |
| 421 | public int checkCallingUriPermission(Uri uri, int modeFlags) { |
| 422 | return mBase.checkCallingUriPermission(uri, modeFlags); |
| 423 | } |
| 424 | |
| 425 | @Override |
| 426 | public int checkCallingOrSelfUriPermission(Uri uri, int modeFlags) { |
| 427 | return mBase.checkCallingOrSelfUriPermission(uri, modeFlags); |
| 428 | } |
| 429 | |
| 430 | @Override |
| 431 | public int checkUriPermission(Uri uri, String readPermission, |
| 432 | String writePermission, int pid, int uid, int modeFlags) { |
| 433 | return mBase.checkUriPermission(uri, readPermission, writePermission, |
| 434 | pid, uid, modeFlags); |
| 435 | } |
| 436 | |
| 437 | @Override |
| 438 | public void enforceUriPermission( |
| 439 | Uri uri, int pid, int uid, int modeFlags, String message) { |
| 440 | mBase.enforceUriPermission(uri, pid, uid, modeFlags, message); |
| 441 | } |
| 442 | |
| 443 | @Override |
| 444 | public void enforceCallingUriPermission( |
| 445 | Uri uri, int modeFlags, String message) { |
| 446 | mBase.enforceCallingUriPermission(uri, modeFlags, message); |
| 447 | } |
| 448 | |
| 449 | @Override |
| 450 | public void enforceCallingOrSelfUriPermission( |
| 451 | Uri uri, int modeFlags, String message) { |
| 452 | mBase.enforceCallingOrSelfUriPermission(uri, modeFlags, message); |
| 453 | } |
| 454 | |
| 455 | @Override |
| 456 | public void enforceUriPermission( |
| 457 | Uri uri, String readPermission, String writePermission, |
| 458 | int pid, int uid, int modeFlags, String message) { |
| 459 | mBase.enforceUriPermission( |
| 460 | uri, readPermission, writePermission, pid, uid, modeFlags, |
| 461 | message); |
| 462 | } |
| 463 | |
| 464 | @Override |
| 465 | public Context createPackageContext(String packageName, int flags) |
| 466 | throws PackageManager.NameNotFoundException { |
| 467 | return mBase.createPackageContext(packageName, flags); |
| 468 | } |
Romain Guy | 870e09f | 2009-07-06 16:35:25 -0700 | [diff] [blame] | 469 | |
| 470 | @Override |
| 471 | public boolean isRestricted() { |
| 472 | return mBase.isRestricted(); |
| 473 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 474 | } |