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