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.app; |
| 18 | |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 19 | import com.android.internal.policy.PolicyManager; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 20 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 21 | import android.content.BroadcastReceiver; |
| 22 | import android.content.ComponentName; |
| 23 | import android.content.ContentResolver; |
| 24 | import android.content.Context; |
| 25 | import android.content.ContextWrapper; |
| 26 | import android.content.IContentProvider; |
| 27 | import android.content.Intent; |
| 28 | import android.content.IntentFilter; |
Suchi Amalapurapu | 1ccac75 | 2009-06-12 10:09:58 -0700 | [diff] [blame] | 29 | import android.content.IIntentReceiver; |
| 30 | import android.content.IntentSender; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 31 | import android.content.ReceiverCallNotAllowedException; |
| 32 | import android.content.ServiceConnection; |
| 33 | import android.content.SharedPreferences; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 34 | import android.content.pm.ApplicationInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 35 | import android.content.pm.IPackageManager; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 36 | import android.content.pm.PackageManager; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 37 | import android.content.res.AssetManager; |
Dianne Hackborn | 5be8de3 | 2011-05-24 18:11:57 -0700 | [diff] [blame] | 38 | import android.content.res.CompatibilityInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 39 | import android.content.res.Resources; |
Vasu Nori | 74f170f | 2010-06-01 18:06:18 -0700 | [diff] [blame] | 40 | import android.database.DatabaseErrorHandler; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 41 | import android.database.sqlite.SQLiteDatabase; |
| 42 | import android.database.sqlite.SQLiteDatabase.CursorFactory; |
| 43 | import android.graphics.Bitmap; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 44 | import android.graphics.drawable.Drawable; |
| 45 | import android.hardware.SensorManager; |
Mike Lockwood | c4308f0 | 2011-03-01 08:04:54 -0800 | [diff] [blame] | 46 | import android.hardware.usb.IUsbManager; |
| 47 | import android.hardware.usb.UsbManager; |
Bai Tao | a58a875 | 2010-07-13 15:32:16 +0800 | [diff] [blame] | 48 | import android.location.CountryDetector; |
| 49 | import android.location.ICountryDetector; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 50 | import android.location.ILocationManager; |
| 51 | import android.location.LocationManager; |
| 52 | import android.media.AudioManager; |
| 53 | import android.net.ConnectivityManager; |
| 54 | import android.net.IConnectivityManager; |
Jeff Sharkey | 1a30395 | 2011-06-16 13:04:20 -0700 | [diff] [blame] | 55 | import android.net.INetworkPolicyManager; |
| 56 | import android.net.NetworkPolicyManager; |
Irfan Sheriff | c9b6851 | 2010-04-08 14:12:33 -0700 | [diff] [blame] | 57 | import android.net.ThrottleManager; |
| 58 | import android.net.IThrottleManager; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 59 | import android.net.Uri; |
| 60 | import android.net.wifi.IWifiManager; |
| 61 | import android.net.wifi.WifiManager; |
repo sync | 55bc5f3 | 2011-06-24 14:23:07 -0700 | [diff] [blame] | 62 | import android.net.wifi.p2p.IWifiP2pManager; |
| 63 | import android.net.wifi.p2p.WifiP2pManager; |
Nick Pelly | 50b4d8f | 2010-12-07 22:40:28 -0800 | [diff] [blame] | 64 | import android.nfc.NfcManager; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 65 | import android.os.Binder; |
| 66 | import android.os.Bundle; |
Dan Egnor | f18a01c | 2009-11-12 11:32:50 -0800 | [diff] [blame] | 67 | import android.os.DropBoxManager; |
Oscar Montemayor | 539d3c4 | 2010-01-29 15:27:00 -0800 | [diff] [blame] | 68 | import android.os.Environment; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 69 | import android.os.FileUtils; |
| 70 | import android.os.Handler; |
| 71 | import android.os.IBinder; |
| 72 | import android.os.IPowerManager; |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 73 | import android.os.Looper; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 74 | import android.os.PowerManager; |
| 75 | import android.os.Process; |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 76 | import android.os.RemoteException; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 77 | import android.os.ServiceManager; |
| 78 | import android.os.Vibrator; |
San Mehat | b104340 | 2010-02-05 08:26:50 -0800 | [diff] [blame] | 79 | import android.os.storage.StorageManager; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 80 | import android.telephony.TelephonyManager; |
Dianne Hackborn | 9f53119 | 2010-08-04 17:48:03 -0700 | [diff] [blame] | 81 | import android.content.ClipboardManager; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 82 | import android.util.AndroidRuntimeException; |
| 83 | import android.util.Log; |
| 84 | import android.view.ContextThemeWrapper; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 85 | import android.view.WindowManagerImpl; |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 86 | import android.view.accessibility.AccessibilityManager; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 87 | import android.view.inputmethod.InputMethodManager; |
satok | 988323c | 2011-06-22 16:38:13 +0900 | [diff] [blame] | 88 | import android.view.textservice.TextServicesManager; |
Fred Quintana | 6030734 | 2009-03-24 22:48:12 -0700 | [diff] [blame] | 89 | import android.accounts.AccountManager; |
| 90 | import android.accounts.IAccountManager; |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 91 | import android.app.admin.DevicePolicyManager; |
Dan Egnor | f18a01c | 2009-11-12 11:32:50 -0800 | [diff] [blame] | 92 | import com.android.internal.os.IDropBoxManagerService; |
Dan Egnor | 9524027 | 2009-10-27 18:23:39 -0700 | [diff] [blame] | 93 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 94 | import java.io.File; |
| 95 | import java.io.FileInputStream; |
| 96 | import java.io.FileNotFoundException; |
| 97 | import java.io.FileOutputStream; |
| 98 | import java.io.IOException; |
| 99 | import java.io.InputStream; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 100 | import java.util.ArrayList; |
| 101 | import java.util.HashMap; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 102 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 103 | class ReceiverRestrictedContext extends ContextWrapper { |
| 104 | ReceiverRestrictedContext(Context base) { |
| 105 | super(base); |
| 106 | } |
| 107 | |
| 108 | @Override |
| 109 | public Intent registerReceiver(BroadcastReceiver receiver, IntentFilter filter) { |
| 110 | return registerReceiver(receiver, filter, null, null); |
| 111 | } |
| 112 | |
| 113 | @Override |
| 114 | public Intent registerReceiver(BroadcastReceiver receiver, IntentFilter filter, |
| 115 | String broadcastPermission, Handler scheduler) { |
| 116 | throw new ReceiverCallNotAllowedException( |
| 117 | "IntentReceiver components are not allowed to register to receive intents"); |
| 118 | //ex.fillInStackTrace(); |
| 119 | //Log.e("IntentReceiver", ex.getMessage(), ex); |
| 120 | //return mContext.registerReceiver(receiver, filter, broadcastPermission, |
| 121 | // scheduler); |
| 122 | } |
| 123 | |
| 124 | @Override |
| 125 | public boolean bindService(Intent service, ServiceConnection conn, int flags) { |
| 126 | throw new ReceiverCallNotAllowedException( |
| 127 | "IntentReceiver components are not allowed to bind to services"); |
| 128 | //ex.fillInStackTrace(); |
| 129 | //Log.e("IntentReceiver", ex.getMessage(), ex); |
| 130 | //return mContext.bindService(service, interfaceName, conn, flags); |
| 131 | } |
| 132 | } |
| 133 | |
| 134 | /** |
Dianne Hackborn | 2155637 | 2010-02-04 16:34:40 -0800 | [diff] [blame] | 135 | * Common implementation of Context API, which provides the base |
| 136 | * context object for Activity and other application components. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 137 | */ |
Dianne Hackborn | 2155637 | 2010-02-04 16:34:40 -0800 | [diff] [blame] | 138 | class ContextImpl extends Context { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 139 | private final static String TAG = "ApplicationContext"; |
Mitsuru Oshima | 569076c | 2009-07-02 20:06:08 -0700 | [diff] [blame] | 140 | private final static boolean DEBUG = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 141 | |
Brad Fitzpatrick | 333b8cb | 2010-08-26 12:04:57 -0700 | [diff] [blame] | 142 | private static final HashMap<String, SharedPreferencesImpl> sSharedPrefs = |
| 143 | new HashMap<String, SharedPreferencesImpl>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 144 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 145 | /*package*/ LoadedApk mPackageInfo; |
Dianne Hackborn | 6c418d5 | 2011-06-29 14:05:33 -0700 | [diff] [blame] | 146 | private String mBasePackageName; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 147 | private Resources mResources; |
| 148 | /*package*/ ActivityThread mMainThread; |
| 149 | private Context mOuterContext; |
| 150 | private IBinder mActivityToken = null; |
| 151 | private ApplicationContentResolver mContentResolver; |
| 152 | private int mThemeResource = 0; |
| 153 | private Resources.Theme mTheme = null; |
| 154 | private PackageManager mPackageManager; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 155 | private Context mReceiverRestrictedContext = null; |
Romain Guy | 870e09f | 2009-07-06 16:35:25 -0700 | [diff] [blame] | 156 | private boolean mRestricted; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 157 | |
| 158 | private final Object mSync = new Object(); |
| 159 | |
| 160 | private File mDatabasesDir; |
| 161 | private File mPreferencesDir; |
| 162 | private File mFilesDir; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 163 | private File mCacheDir; |
Dianne Hackborn | 805fd7e | 2011-01-16 18:30:29 -0800 | [diff] [blame] | 164 | private File mObbDir; |
Dianne Hackborn | e83cefce | 2010-02-04 17:38:14 -0800 | [diff] [blame] | 165 | private File mExternalFilesDir; |
| 166 | private File mExternalCacheDir; |
Christian Mehlmauer | 5f5acca | 2010-06-25 19:06:18 +0200 | [diff] [blame] | 167 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 168 | private static final String[] EMPTY_FILE_LIST = {}; |
| 169 | |
Brad Fitzpatrick | 224ba0c | 2010-11-12 12:22:15 -0800 | [diff] [blame] | 170 | /** |
| 171 | * Override this class when the system service constructor needs a |
| 172 | * ContextImpl. Else, use StaticServiceFetcher below. |
| 173 | */ |
| 174 | /*package*/ static class ServiceFetcher { |
| 175 | int mContextCacheIndex = -1; |
| 176 | |
| 177 | /** |
| 178 | * Main entrypoint; only override if you don't need caching. |
| 179 | */ |
| 180 | public Object getService(ContextImpl ctx) { |
| 181 | ArrayList<Object> cache = ctx.mServiceCache; |
| 182 | Object service; |
| 183 | synchronized (cache) { |
| 184 | if (cache.size() == 0) { |
| 185 | // Initialize the cache vector on first access. |
| 186 | // At this point sNextPerContextServiceCacheIndex |
| 187 | // is the number of potential services that are |
| 188 | // cached per-Context. |
| 189 | for (int i = 0; i < sNextPerContextServiceCacheIndex; i++) { |
| 190 | cache.add(null); |
| 191 | } |
| 192 | } else { |
| 193 | service = cache.get(mContextCacheIndex); |
| 194 | if (service != null) { |
| 195 | return service; |
| 196 | } |
| 197 | } |
| 198 | service = createService(ctx); |
| 199 | cache.set(mContextCacheIndex, service); |
| 200 | return service; |
| 201 | } |
| 202 | } |
| 203 | |
| 204 | /** |
| 205 | * Override this to create a new per-Context instance of the |
| 206 | * service. getService() will handle locking and caching. |
| 207 | */ |
| 208 | public Object createService(ContextImpl ctx) { |
| 209 | throw new RuntimeException("Not implemented"); |
| 210 | } |
| 211 | } |
| 212 | |
| 213 | /** |
| 214 | * Override this class for services to be cached process-wide. |
| 215 | */ |
| 216 | abstract static class StaticServiceFetcher extends ServiceFetcher { |
| 217 | private Object mCachedInstance; |
| 218 | |
| 219 | @Override |
| 220 | public final Object getService(ContextImpl unused) { |
| 221 | synchronized (StaticServiceFetcher.this) { |
| 222 | Object service = mCachedInstance; |
| 223 | if (service != null) { |
| 224 | return service; |
| 225 | } |
| 226 | return mCachedInstance = createStaticService(); |
| 227 | } |
| 228 | } |
| 229 | |
| 230 | public abstract Object createStaticService(); |
| 231 | } |
| 232 | |
| 233 | private static final HashMap<String, ServiceFetcher> SYSTEM_SERVICE_MAP = |
| 234 | new HashMap<String, ServiceFetcher>(); |
| 235 | |
| 236 | private static int sNextPerContextServiceCacheIndex = 0; |
| 237 | private static void registerService(String serviceName, ServiceFetcher fetcher) { |
| 238 | if (!(fetcher instanceof StaticServiceFetcher)) { |
| 239 | fetcher.mContextCacheIndex = sNextPerContextServiceCacheIndex++; |
| 240 | } |
| 241 | SYSTEM_SERVICE_MAP.put(serviceName, fetcher); |
| 242 | } |
| 243 | |
| 244 | // This one's defined separately and given a variable name so it |
| 245 | // can be re-used by getWallpaperManager(), avoiding a HashMap |
| 246 | // lookup. |
| 247 | private static ServiceFetcher WALLPAPER_FETCHER = new ServiceFetcher() { |
| 248 | public Object createService(ContextImpl ctx) { |
| 249 | return new WallpaperManager(ctx.getOuterContext(), |
| 250 | ctx.mMainThread.getHandler()); |
| 251 | }}; |
| 252 | |
| 253 | static { |
| 254 | registerService(ACCESSIBILITY_SERVICE, new ServiceFetcher() { |
| 255 | public Object getService(ContextImpl ctx) { |
| 256 | return AccessibilityManager.getInstance(ctx); |
| 257 | }}); |
| 258 | |
| 259 | registerService(ACCOUNT_SERVICE, new ServiceFetcher() { |
| 260 | public Object createService(ContextImpl ctx) { |
| 261 | IBinder b = ServiceManager.getService(ACCOUNT_SERVICE); |
| 262 | IAccountManager service = IAccountManager.Stub.asInterface(b); |
| 263 | return new AccountManager(ctx, service); |
| 264 | }}); |
| 265 | |
| 266 | registerService(ACTIVITY_SERVICE, new ServiceFetcher() { |
| 267 | public Object createService(ContextImpl ctx) { |
| 268 | return new ActivityManager(ctx.getOuterContext(), ctx.mMainThread.getHandler()); |
| 269 | }}); |
| 270 | |
| 271 | registerService(ALARM_SERVICE, new StaticServiceFetcher() { |
| 272 | public Object createStaticService() { |
| 273 | IBinder b = ServiceManager.getService(ALARM_SERVICE); |
| 274 | IAlarmManager service = IAlarmManager.Stub.asInterface(b); |
| 275 | return new AlarmManager(service); |
| 276 | }}); |
| 277 | |
| 278 | registerService(AUDIO_SERVICE, new ServiceFetcher() { |
| 279 | public Object createService(ContextImpl ctx) { |
| 280 | return new AudioManager(ctx); |
| 281 | }}); |
| 282 | |
| 283 | registerService(CLIPBOARD_SERVICE, new ServiceFetcher() { |
| 284 | public Object createService(ContextImpl ctx) { |
| 285 | return new ClipboardManager(ctx.getOuterContext(), |
| 286 | ctx.mMainThread.getHandler()); |
| 287 | }}); |
| 288 | |
| 289 | registerService(CONNECTIVITY_SERVICE, new StaticServiceFetcher() { |
| 290 | public Object createStaticService() { |
| 291 | IBinder b = ServiceManager.getService(CONNECTIVITY_SERVICE); |
| 292 | return new ConnectivityManager(IConnectivityManager.Stub.asInterface(b)); |
| 293 | }}); |
| 294 | |
| 295 | registerService(COUNTRY_DETECTOR, new StaticServiceFetcher() { |
| 296 | public Object createStaticService() { |
| 297 | IBinder b = ServiceManager.getService(COUNTRY_DETECTOR); |
| 298 | return new CountryDetector(ICountryDetector.Stub.asInterface(b)); |
| 299 | }}); |
| 300 | |
| 301 | registerService(DEVICE_POLICY_SERVICE, new ServiceFetcher() { |
| 302 | public Object createService(ContextImpl ctx) { |
| 303 | return DevicePolicyManager.create(ctx, ctx.mMainThread.getHandler()); |
| 304 | }}); |
| 305 | |
| 306 | registerService(DOWNLOAD_SERVICE, new ServiceFetcher() { |
| 307 | public Object createService(ContextImpl ctx) { |
| 308 | return new DownloadManager(ctx.getContentResolver(), ctx.getPackageName()); |
| 309 | }}); |
| 310 | |
Nick Pelly | d250746 | 2010-12-13 12:22:34 -0800 | [diff] [blame] | 311 | registerService(NFC_SERVICE, new ServiceFetcher() { |
| 312 | public Object createService(ContextImpl ctx) { |
| 313 | return new NfcManager(ctx); |
| 314 | }}); |
| 315 | |
Brad Fitzpatrick | 224ba0c | 2010-11-12 12:22:15 -0800 | [diff] [blame] | 316 | registerService(DROPBOX_SERVICE, new StaticServiceFetcher() { |
| 317 | public Object createStaticService() { |
| 318 | return createDropBoxManager(); |
| 319 | }}); |
| 320 | |
| 321 | registerService(INPUT_METHOD_SERVICE, new ServiceFetcher() { |
| 322 | public Object createService(ContextImpl ctx) { |
| 323 | return InputMethodManager.getInstance(ctx); |
| 324 | }}); |
| 325 | |
satok | 988323c | 2011-06-22 16:38:13 +0900 | [diff] [blame] | 326 | registerService(TEXT_SERVICES_MANAGER_SERVICE, new ServiceFetcher() { |
| 327 | public Object createService(ContextImpl ctx) { |
| 328 | return TextServicesManager.getInstance(); |
| 329 | }}); |
| 330 | |
Brad Fitzpatrick | 224ba0c | 2010-11-12 12:22:15 -0800 | [diff] [blame] | 331 | registerService(KEYGUARD_SERVICE, new ServiceFetcher() { |
| 332 | public Object getService(ContextImpl ctx) { |
| 333 | // TODO: why isn't this caching it? It wasn't |
| 334 | // before, so I'm preserving the old behavior and |
| 335 | // using getService(), instead of createService() |
| 336 | // which would do the caching. |
| 337 | return new KeyguardManager(); |
| 338 | }}); |
| 339 | |
| 340 | registerService(LAYOUT_INFLATER_SERVICE, new ServiceFetcher() { |
| 341 | public Object createService(ContextImpl ctx) { |
| 342 | return PolicyManager.makeNewLayoutInflater(ctx.getOuterContext()); |
| 343 | }}); |
| 344 | |
| 345 | registerService(LOCATION_SERVICE, new StaticServiceFetcher() { |
| 346 | public Object createStaticService() { |
| 347 | IBinder b = ServiceManager.getService(LOCATION_SERVICE); |
| 348 | return new LocationManager(ILocationManager.Stub.asInterface(b)); |
| 349 | }}); |
| 350 | |
Jeff Sharkey | 1a30395 | 2011-06-16 13:04:20 -0700 | [diff] [blame] | 351 | registerService(NETWORK_POLICY_SERVICE, new ServiceFetcher() { |
| 352 | @Override |
| 353 | public Object createService(ContextImpl ctx) { |
| 354 | return new NetworkPolicyManager(INetworkPolicyManager.Stub.asInterface( |
| 355 | ServiceManager.getService(NETWORK_POLICY_SERVICE))); |
| 356 | } |
| 357 | }); |
| 358 | |
Brad Fitzpatrick | 224ba0c | 2010-11-12 12:22:15 -0800 | [diff] [blame] | 359 | registerService(NOTIFICATION_SERVICE, new ServiceFetcher() { |
| 360 | public Object createService(ContextImpl ctx) { |
| 361 | final Context outerContext = ctx.getOuterContext(); |
| 362 | return new NotificationManager( |
| 363 | new ContextThemeWrapper(outerContext, |
Dianne Hackborn | d922ae0 | 2011-01-14 11:43:24 -0800 | [diff] [blame] | 364 | Resources.selectSystemTheme(0, |
| 365 | outerContext.getApplicationInfo().targetSdkVersion, |
| 366 | com.android.internal.R.style.Theme_Dialog, |
Adam Powell | 6e90a36 | 2011-08-14 16:48:32 -0700 | [diff] [blame^] | 367 | com.android.internal.R.style.Theme_Holo_Dialog, |
| 368 | com.android.internal.R.style.Theme_DeviceDefault_Dialog)), |
Brad Fitzpatrick | 224ba0c | 2010-11-12 12:22:15 -0800 | [diff] [blame] | 369 | ctx.mMainThread.getHandler()); |
| 370 | }}); |
| 371 | |
| 372 | // Note: this was previously cached in a static variable, but |
| 373 | // constructed using mMainThread.getHandler(), so converting |
| 374 | // it to be a regular Context-cached service... |
| 375 | registerService(POWER_SERVICE, new ServiceFetcher() { |
| 376 | public Object createService(ContextImpl ctx) { |
| 377 | IBinder b = ServiceManager.getService(POWER_SERVICE); |
| 378 | IPowerManager service = IPowerManager.Stub.asInterface(b); |
| 379 | return new PowerManager(service, ctx.mMainThread.getHandler()); |
| 380 | }}); |
| 381 | |
| 382 | registerService(SEARCH_SERVICE, new ServiceFetcher() { |
| 383 | public Object createService(ContextImpl ctx) { |
| 384 | return new SearchManager(ctx.getOuterContext(), |
| 385 | ctx.mMainThread.getHandler()); |
| 386 | }}); |
| 387 | |
| 388 | registerService(SENSOR_SERVICE, new ServiceFetcher() { |
| 389 | public Object createService(ContextImpl ctx) { |
| 390 | return new SensorManager(ctx.mMainThread.getHandler().getLooper()); |
| 391 | }}); |
| 392 | |
| 393 | registerService(STATUS_BAR_SERVICE, new ServiceFetcher() { |
| 394 | public Object createService(ContextImpl ctx) { |
| 395 | return new StatusBarManager(ctx.getOuterContext()); |
| 396 | }}); |
| 397 | |
| 398 | registerService(STORAGE_SERVICE, new ServiceFetcher() { |
| 399 | public Object createService(ContextImpl ctx) { |
| 400 | try { |
| 401 | return new StorageManager(ctx.mMainThread.getHandler().getLooper()); |
| 402 | } catch (RemoteException rex) { |
| 403 | Log.e(TAG, "Failed to create StorageManager", rex); |
| 404 | return null; |
| 405 | } |
| 406 | }}); |
| 407 | |
| 408 | registerService(TELEPHONY_SERVICE, new ServiceFetcher() { |
| 409 | public Object createService(ContextImpl ctx) { |
| 410 | return new TelephonyManager(ctx.getOuterContext()); |
| 411 | }}); |
| 412 | |
| 413 | registerService(THROTTLE_SERVICE, new StaticServiceFetcher() { |
| 414 | public Object createStaticService() { |
| 415 | IBinder b = ServiceManager.getService(THROTTLE_SERVICE); |
| 416 | return new ThrottleManager(IThrottleManager.Stub.asInterface(b)); |
| 417 | }}); |
| 418 | |
| 419 | registerService(UI_MODE_SERVICE, new ServiceFetcher() { |
| 420 | public Object createService(ContextImpl ctx) { |
| 421 | return new UiModeManager(); |
| 422 | }}); |
| 423 | |
Mike Lockwood | 3a68b83 | 2011-03-08 10:08:59 -0500 | [diff] [blame] | 424 | registerService(USB_SERVICE, new ServiceFetcher() { |
| 425 | public Object createService(ContextImpl ctx) { |
Mike Lockwood | e7d511e | 2010-12-30 13:39:37 -0500 | [diff] [blame] | 426 | IBinder b = ServiceManager.getService(USB_SERVICE); |
Mike Lockwood | 3a68b83 | 2011-03-08 10:08:59 -0500 | [diff] [blame] | 427 | return new UsbManager(ctx, IUsbManager.Stub.asInterface(b)); |
Mike Lockwood | e7d511e | 2010-12-30 13:39:37 -0500 | [diff] [blame] | 428 | }}); |
| 429 | |
Brad Fitzpatrick | 224ba0c | 2010-11-12 12:22:15 -0800 | [diff] [blame] | 430 | registerService(VIBRATOR_SERVICE, new ServiceFetcher() { |
| 431 | public Object createService(ContextImpl ctx) { |
| 432 | return new Vibrator(); |
| 433 | }}); |
| 434 | |
| 435 | registerService(WALLPAPER_SERVICE, WALLPAPER_FETCHER); |
| 436 | |
| 437 | registerService(WIFI_SERVICE, new ServiceFetcher() { |
| 438 | public Object createService(ContextImpl ctx) { |
| 439 | IBinder b = ServiceManager.getService(WIFI_SERVICE); |
| 440 | IWifiManager service = IWifiManager.Stub.asInterface(b); |
| 441 | return new WifiManager(service, ctx.mMainThread.getHandler()); |
| 442 | }}); |
| 443 | |
repo sync | 55bc5f3 | 2011-06-24 14:23:07 -0700 | [diff] [blame] | 444 | registerService(WIFI_P2P_SERVICE, new ServiceFetcher() { |
| 445 | public Object createService(ContextImpl ctx) { |
| 446 | IBinder b = ServiceManager.getService(WIFI_P2P_SERVICE); |
| 447 | IWifiP2pManager service = IWifiP2pManager.Stub.asInterface(b); |
| 448 | return new WifiP2pManager(service); |
| 449 | }}); |
| 450 | |
Brad Fitzpatrick | 224ba0c | 2010-11-12 12:22:15 -0800 | [diff] [blame] | 451 | registerService(WINDOW_SERVICE, new ServiceFetcher() { |
| 452 | public Object getService(ContextImpl ctx) { |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 453 | return WindowManagerImpl.getDefault(ctx.mPackageInfo.mCompatibilityInfo); |
Brad Fitzpatrick | 224ba0c | 2010-11-12 12:22:15 -0800 | [diff] [blame] | 454 | }}); |
| 455 | } |
| 456 | |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 457 | static ContextImpl getImpl(Context context) { |
| 458 | Context nextContext; |
| 459 | while ((context instanceof ContextWrapper) && |
| 460 | (nextContext=((ContextWrapper)context).getBaseContext()) != null) { |
| 461 | context = nextContext; |
| 462 | } |
| 463 | return (ContextImpl)context; |
| 464 | } |
| 465 | |
Brad Fitzpatrick | 224ba0c | 2010-11-12 12:22:15 -0800 | [diff] [blame] | 466 | // The system service cache for the system services that are |
| 467 | // cached per-ContextImpl. Package-scoped to avoid accessor |
| 468 | // methods. |
| 469 | final ArrayList<Object> mServiceCache = new ArrayList<Object>(); |
| 470 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 471 | @Override |
| 472 | public AssetManager getAssets() { |
| 473 | return mResources.getAssets(); |
| 474 | } |
| 475 | |
| 476 | @Override |
| 477 | public Resources getResources() { |
| 478 | return mResources; |
| 479 | } |
| 480 | |
| 481 | @Override |
| 482 | public PackageManager getPackageManager() { |
| 483 | if (mPackageManager != null) { |
| 484 | return mPackageManager; |
| 485 | } |
| 486 | |
| 487 | IPackageManager pm = ActivityThread.getPackageManager(); |
| 488 | if (pm != null) { |
| 489 | // Doesn't matter if we make more than one instance. |
| 490 | return (mPackageManager = new ApplicationPackageManager(this, pm)); |
| 491 | } |
| 492 | |
| 493 | return null; |
| 494 | } |
| 495 | |
| 496 | @Override |
| 497 | public ContentResolver getContentResolver() { |
| 498 | return mContentResolver; |
| 499 | } |
| 500 | |
| 501 | @Override |
| 502 | public Looper getMainLooper() { |
| 503 | return mMainThread.getLooper(); |
| 504 | } |
Christian Mehlmauer | 5f5acca | 2010-06-25 19:06:18 +0200 | [diff] [blame] | 505 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 506 | @Override |
| 507 | public Context getApplicationContext() { |
Christopher Tate | eb9e9ec | 2010-03-23 17:14:36 -0700 | [diff] [blame] | 508 | return (mPackageInfo != null) ? |
| 509 | mPackageInfo.getApplication() : mMainThread.getApplication(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 510 | } |
Christian Mehlmauer | 5f5acca | 2010-06-25 19:06:18 +0200 | [diff] [blame] | 511 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 512 | @Override |
| 513 | public void setTheme(int resid) { |
| 514 | mThemeResource = resid; |
| 515 | } |
Christian Mehlmauer | 5f5acca | 2010-06-25 19:06:18 +0200 | [diff] [blame] | 516 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 517 | @Override |
Dianne Hackborn | 247fe74 | 2011-01-08 17:25:57 -0800 | [diff] [blame] | 518 | public int getThemeResId() { |
| 519 | return mThemeResource; |
| 520 | } |
| 521 | |
| 522 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 523 | public Resources.Theme getTheme() { |
| 524 | if (mTheme == null) { |
Dianne Hackborn | d922ae0 | 2011-01-14 11:43:24 -0800 | [diff] [blame] | 525 | mThemeResource = Resources.selectDefaultTheme(mThemeResource, |
| 526 | getOuterContext().getApplicationInfo().targetSdkVersion); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 527 | mTheme = mResources.newTheme(); |
| 528 | mTheme.applyStyle(mThemeResource, true); |
| 529 | } |
| 530 | return mTheme; |
| 531 | } |
| 532 | |
| 533 | @Override |
| 534 | public ClassLoader getClassLoader() { |
| 535 | return mPackageInfo != null ? |
| 536 | mPackageInfo.getClassLoader() : ClassLoader.getSystemClassLoader(); |
| 537 | } |
| 538 | |
| 539 | @Override |
| 540 | public String getPackageName() { |
| 541 | if (mPackageInfo != null) { |
| 542 | return mPackageInfo.getPackageName(); |
| 543 | } |
| 544 | throw new RuntimeException("Not supported in system context"); |
| 545 | } |
| 546 | |
| 547 | @Override |
Dianne Hackborn | 5c1e00b | 2009-06-18 17:10:57 -0700 | [diff] [blame] | 548 | public ApplicationInfo getApplicationInfo() { |
| 549 | if (mPackageInfo != null) { |
| 550 | return mPackageInfo.getApplicationInfo(); |
| 551 | } |
| 552 | throw new RuntimeException("Not supported in system context"); |
| 553 | } |
| 554 | |
| 555 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 556 | public String getPackageResourcePath() { |
| 557 | if (mPackageInfo != null) { |
| 558 | return mPackageInfo.getResDir(); |
| 559 | } |
| 560 | throw new RuntimeException("Not supported in system context"); |
| 561 | } |
| 562 | |
| 563 | @Override |
| 564 | public String getPackageCodePath() { |
| 565 | if (mPackageInfo != null) { |
| 566 | return mPackageInfo.getAppDir(); |
| 567 | } |
| 568 | throw new RuntimeException("Not supported in system context"); |
| 569 | } |
Christian Mehlmauer | 5f5acca | 2010-06-25 19:06:18 +0200 | [diff] [blame] | 570 | |
Joe Onorato | 23ecae3 | 2009-06-10 17:07:15 -0700 | [diff] [blame] | 571 | public File getSharedPrefsFile(String name) { |
| 572 | return makeFilename(getPreferencesDir(), name + ".xml"); |
| 573 | } |
| 574 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 575 | @Override |
| 576 | public SharedPreferences getSharedPreferences(String name, int mode) { |
| 577 | SharedPreferencesImpl sp; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 578 | synchronized (sSharedPrefs) { |
Brad Fitzpatrick | 333b8cb | 2010-08-26 12:04:57 -0700 | [diff] [blame] | 579 | sp = sSharedPrefs.get(name); |
Brad Fitzpatrick | 6194c53 | 2010-09-07 18:00:33 -0700 | [diff] [blame] | 580 | if (sp == null) { |
Brad Fitzpatrick | 4cd50b8 | 2010-12-01 17:31:45 -0800 | [diff] [blame] | 581 | File prefsFile = getSharedPrefsFile(name); |
| 582 | sp = new SharedPreferencesImpl(prefsFile, mode); |
Brad Fitzpatrick | 6194c53 | 2010-09-07 18:00:33 -0700 | [diff] [blame] | 583 | sSharedPrefs.put(name, sp); |
Brad Fitzpatrick | 6194c53 | 2010-09-07 18:00:33 -0700 | [diff] [blame] | 584 | return sp; |
| 585 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 586 | } |
Brad Fitzpatrick | 4e920f7 | 2010-12-14 11:52:13 -0800 | [diff] [blame] | 587 | if ((mode & Context.MODE_MULTI_PROCESS) != 0 || |
| 588 | getApplicationInfo().targetSdkVersion < android.os.Build.VERSION_CODES.HONEYCOMB) { |
| 589 | // If somebody else (some other process) changed the prefs |
| 590 | // file behind our back, we reload it. This has been the |
| 591 | // historical (if undocumented) behavior. |
| 592 | sp.startReloadIfChangedUnexpectedly(); |
| 593 | } |
Brad Fitzpatrick | 6194c53 | 2010-09-07 18:00:33 -0700 | [diff] [blame] | 594 | return sp; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 595 | } |
| 596 | |
| 597 | private File getPreferencesDir() { |
| 598 | synchronized (mSync) { |
| 599 | if (mPreferencesDir == null) { |
| 600 | mPreferencesDir = new File(getDataDirFile(), "shared_prefs"); |
| 601 | } |
| 602 | return mPreferencesDir; |
| 603 | } |
| 604 | } |
| 605 | |
| 606 | @Override |
| 607 | public FileInputStream openFileInput(String name) |
| 608 | throws FileNotFoundException { |
| 609 | File f = makeFilename(getFilesDir(), name); |
| 610 | return new FileInputStream(f); |
| 611 | } |
| 612 | |
| 613 | @Override |
| 614 | public FileOutputStream openFileOutput(String name, int mode) |
| 615 | throws FileNotFoundException { |
| 616 | final boolean append = (mode&MODE_APPEND) != 0; |
| 617 | File f = makeFilename(getFilesDir(), name); |
| 618 | try { |
| 619 | FileOutputStream fos = new FileOutputStream(f, append); |
| 620 | setFilePermissionsFromMode(f.getPath(), mode, 0); |
| 621 | return fos; |
| 622 | } catch (FileNotFoundException e) { |
| 623 | } |
| 624 | |
| 625 | File parent = f.getParentFile(); |
| 626 | parent.mkdir(); |
| 627 | FileUtils.setPermissions( |
| 628 | parent.getPath(), |
| 629 | FileUtils.S_IRWXU|FileUtils.S_IRWXG|FileUtils.S_IXOTH, |
| 630 | -1, -1); |
| 631 | FileOutputStream fos = new FileOutputStream(f, append); |
| 632 | setFilePermissionsFromMode(f.getPath(), mode, 0); |
| 633 | return fos; |
| 634 | } |
| 635 | |
| 636 | @Override |
| 637 | public boolean deleteFile(String name) { |
| 638 | File f = makeFilename(getFilesDir(), name); |
| 639 | return f.delete(); |
| 640 | } |
| 641 | |
| 642 | @Override |
| 643 | public File getFilesDir() { |
| 644 | synchronized (mSync) { |
| 645 | if (mFilesDir == null) { |
| 646 | mFilesDir = new File(getDataDirFile(), "files"); |
| 647 | } |
| 648 | if (!mFilesDir.exists()) { |
| 649 | if(!mFilesDir.mkdirs()) { |
Christian Mehlmauer | 5f5acca | 2010-06-25 19:06:18 +0200 | [diff] [blame] | 650 | Log.w(TAG, "Unable to create files directory " + mFilesDir.getPath()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 651 | return null; |
| 652 | } |
| 653 | FileUtils.setPermissions( |
| 654 | mFilesDir.getPath(), |
| 655 | FileUtils.S_IRWXU|FileUtils.S_IRWXG|FileUtils.S_IXOTH, |
| 656 | -1, -1); |
| 657 | } |
| 658 | return mFilesDir; |
| 659 | } |
| 660 | } |
Christian Mehlmauer | 5f5acca | 2010-06-25 19:06:18 +0200 | [diff] [blame] | 661 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 662 | @Override |
Dianne Hackborn | e83cefce | 2010-02-04 17:38:14 -0800 | [diff] [blame] | 663 | public File getExternalFilesDir(String type) { |
| 664 | synchronized (mSync) { |
| 665 | if (mExternalFilesDir == null) { |
| 666 | mExternalFilesDir = Environment.getExternalStorageAppFilesDirectory( |
| 667 | getPackageName()); |
| 668 | } |
| 669 | if (!mExternalFilesDir.exists()) { |
| 670 | try { |
| 671 | (new File(Environment.getExternalStorageAndroidDataDir(), |
| 672 | ".nomedia")).createNewFile(); |
| 673 | } catch (IOException e) { |
| 674 | } |
| 675 | if (!mExternalFilesDir.mkdirs()) { |
| 676 | Log.w(TAG, "Unable to create external files directory"); |
| 677 | return null; |
| 678 | } |
| 679 | } |
| 680 | if (type == null) { |
| 681 | return mExternalFilesDir; |
| 682 | } |
| 683 | File dir = new File(mExternalFilesDir, type); |
| 684 | if (!dir.exists()) { |
| 685 | if (!dir.mkdirs()) { |
| 686 | Log.w(TAG, "Unable to create external media directory " + dir); |
| 687 | return null; |
| 688 | } |
| 689 | } |
| 690 | return dir; |
| 691 | } |
| 692 | } |
Christian Mehlmauer | 5f5acca | 2010-06-25 19:06:18 +0200 | [diff] [blame] | 693 | |
Dianne Hackborn | e83cefce | 2010-02-04 17:38:14 -0800 | [diff] [blame] | 694 | @Override |
Dianne Hackborn | 805fd7e | 2011-01-16 18:30:29 -0800 | [diff] [blame] | 695 | public File getObbDir() { |
| 696 | synchronized (mSync) { |
| 697 | if (mObbDir == null) { |
| 698 | mObbDir = Environment.getExternalStorageAppObbDirectory( |
| 699 | getPackageName()); |
| 700 | } |
| 701 | return mObbDir; |
| 702 | } |
| 703 | } |
| 704 | |
| 705 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 706 | public File getCacheDir() { |
| 707 | synchronized (mSync) { |
| 708 | if (mCacheDir == null) { |
| 709 | mCacheDir = new File(getDataDirFile(), "cache"); |
| 710 | } |
| 711 | if (!mCacheDir.exists()) { |
| 712 | if(!mCacheDir.mkdirs()) { |
| 713 | Log.w(TAG, "Unable to create cache directory"); |
| 714 | return null; |
| 715 | } |
| 716 | FileUtils.setPermissions( |
| 717 | mCacheDir.getPath(), |
| 718 | FileUtils.S_IRWXU|FileUtils.S_IRWXG|FileUtils.S_IXOTH, |
| 719 | -1, -1); |
| 720 | } |
| 721 | } |
| 722 | return mCacheDir; |
| 723 | } |
Christian Mehlmauer | 5f5acca | 2010-06-25 19:06:18 +0200 | [diff] [blame] | 724 | |
Dianne Hackborn | e83cefce | 2010-02-04 17:38:14 -0800 | [diff] [blame] | 725 | @Override |
| 726 | public File getExternalCacheDir() { |
| 727 | synchronized (mSync) { |
| 728 | if (mExternalCacheDir == null) { |
| 729 | mExternalCacheDir = Environment.getExternalStorageAppCacheDirectory( |
| 730 | getPackageName()); |
| 731 | } |
| 732 | if (!mExternalCacheDir.exists()) { |
| 733 | try { |
| 734 | (new File(Environment.getExternalStorageAndroidDataDir(), |
| 735 | ".nomedia")).createNewFile(); |
| 736 | } catch (IOException e) { |
| 737 | } |
| 738 | if (!mExternalCacheDir.mkdirs()) { |
| 739 | Log.w(TAG, "Unable to create external cache directory"); |
| 740 | return null; |
| 741 | } |
| 742 | } |
| 743 | return mExternalCacheDir; |
| 744 | } |
| 745 | } |
Christian Mehlmauer | 5f5acca | 2010-06-25 19:06:18 +0200 | [diff] [blame] | 746 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 747 | @Override |
| 748 | public File getFileStreamPath(String name) { |
| 749 | return makeFilename(getFilesDir(), name); |
| 750 | } |
| 751 | |
| 752 | @Override |
| 753 | public String[] fileList() { |
| 754 | final String[] list = getFilesDir().list(); |
| 755 | return (list != null) ? list : EMPTY_FILE_LIST; |
| 756 | } |
| 757 | |
| 758 | @Override |
| 759 | public SQLiteDatabase openOrCreateDatabase(String name, int mode, CursorFactory factory) { |
Oscar Montemayor | a8529f6 | 2009-11-18 10:14:20 -0800 | [diff] [blame] | 760 | File f = validateFilePath(name, true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 761 | SQLiteDatabase db = SQLiteDatabase.openOrCreateDatabase(f, factory); |
| 762 | setFilePermissionsFromMode(f.getPath(), mode, 0); |
| 763 | return db; |
| 764 | } |
| 765 | |
| 766 | @Override |
Vasu Nori | 74f170f | 2010-06-01 18:06:18 -0700 | [diff] [blame] | 767 | public SQLiteDatabase openOrCreateDatabase(String name, int mode, CursorFactory factory, |
| 768 | DatabaseErrorHandler errorHandler) { |
| 769 | File f = validateFilePath(name, true); |
| 770 | SQLiteDatabase db = SQLiteDatabase.openOrCreateDatabase(f.getPath(), factory, errorHandler); |
| 771 | setFilePermissionsFromMode(f.getPath(), mode, 0); |
| 772 | return db; |
| 773 | } |
| 774 | |
| 775 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 776 | public boolean deleteDatabase(String name) { |
| 777 | try { |
Oscar Montemayor | a8529f6 | 2009-11-18 10:14:20 -0800 | [diff] [blame] | 778 | File f = validateFilePath(name, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 779 | return f.delete(); |
| 780 | } catch (Exception e) { |
| 781 | } |
| 782 | return false; |
| 783 | } |
| 784 | |
| 785 | @Override |
| 786 | public File getDatabasePath(String name) { |
Oscar Montemayor | a8529f6 | 2009-11-18 10:14:20 -0800 | [diff] [blame] | 787 | return validateFilePath(name, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 788 | } |
| 789 | |
| 790 | @Override |
| 791 | public String[] databaseList() { |
| 792 | final String[] list = getDatabasesDir().list(); |
| 793 | return (list != null) ? list : EMPTY_FILE_LIST; |
| 794 | } |
| 795 | |
Christian Mehlmauer | 5f5acca | 2010-06-25 19:06:18 +0200 | [diff] [blame] | 796 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 797 | private File getDatabasesDir() { |
| 798 | synchronized (mSync) { |
| 799 | if (mDatabasesDir == null) { |
| 800 | mDatabasesDir = new File(getDataDirFile(), "databases"); |
| 801 | } |
| 802 | if (mDatabasesDir.getPath().equals("databases")) { |
| 803 | mDatabasesDir = new File("/data/system"); |
| 804 | } |
| 805 | return mDatabasesDir; |
| 806 | } |
| 807 | } |
Christian Mehlmauer | 5f5acca | 2010-06-25 19:06:18 +0200 | [diff] [blame] | 808 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 809 | @Override |
| 810 | public Drawable getWallpaper() { |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 811 | return getWallpaperManager().getDrawable(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 812 | } |
| 813 | |
| 814 | @Override |
Dianne Hackborn | 8cc6a50 | 2009-08-05 21:29:42 -0700 | [diff] [blame] | 815 | public Drawable peekWallpaper() { |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 816 | return getWallpaperManager().peekDrawable(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 817 | } |
| 818 | |
| 819 | @Override |
| 820 | public int getWallpaperDesiredMinimumWidth() { |
Dianne Hackborn | 8cc6a50 | 2009-08-05 21:29:42 -0700 | [diff] [blame] | 821 | return getWallpaperManager().getDesiredMinimumWidth(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 822 | } |
| 823 | |
| 824 | @Override |
| 825 | public int getWallpaperDesiredMinimumHeight() { |
Dianne Hackborn | 8cc6a50 | 2009-08-05 21:29:42 -0700 | [diff] [blame] | 826 | return getWallpaperManager().getDesiredMinimumHeight(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 827 | } |
| 828 | |
| 829 | @Override |
| 830 | public void setWallpaper(Bitmap bitmap) throws IOException { |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 831 | getWallpaperManager().setBitmap(bitmap); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 832 | } |
| 833 | |
| 834 | @Override |
| 835 | public void setWallpaper(InputStream data) throws IOException { |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 836 | getWallpaperManager().setStream(data); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 837 | } |
| 838 | |
| 839 | @Override |
| 840 | public void clearWallpaper() throws IOException { |
Dianne Hackborn | 8cc6a50 | 2009-08-05 21:29:42 -0700 | [diff] [blame] | 841 | getWallpaperManager().clear(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 842 | } |
| 843 | |
| 844 | @Override |
| 845 | public void startActivity(Intent intent) { |
| 846 | if ((intent.getFlags()&Intent.FLAG_ACTIVITY_NEW_TASK) == 0) { |
| 847 | throw new AndroidRuntimeException( |
| 848 | "Calling startActivity() from outside of an Activity " |
| 849 | + " context requires the FLAG_ACTIVITY_NEW_TASK flag." |
| 850 | + " Is this really what you want?"); |
| 851 | } |
| 852 | mMainThread.getInstrumentation().execStartActivity( |
Dianne Hackborn | 6e8304e | 2010-05-14 00:42:53 -0700 | [diff] [blame] | 853 | getOuterContext(), mMainThread.getApplicationThread(), null, |
| 854 | (Activity)null, intent, -1); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 855 | } |
| 856 | |
| 857 | @Override |
Dianne Hackborn | 621e17d | 2010-11-22 15:59:56 -0800 | [diff] [blame] | 858 | public void startActivities(Intent[] intents) { |
| 859 | if ((intents[0].getFlags()&Intent.FLAG_ACTIVITY_NEW_TASK) == 0) { |
| 860 | throw new AndroidRuntimeException( |
| 861 | "Calling startActivities() from outside of an Activity " |
| 862 | + " context requires the FLAG_ACTIVITY_NEW_TASK flag on first Intent." |
| 863 | + " Is this really what you want?"); |
| 864 | } |
| 865 | mMainThread.getInstrumentation().execStartActivities( |
| 866 | getOuterContext(), mMainThread.getApplicationThread(), null, |
| 867 | (Activity)null, intents); |
| 868 | } |
| 869 | |
| 870 | @Override |
Dianne Hackborn | fa82f22 | 2009-09-17 15:14:12 -0700 | [diff] [blame] | 871 | public void startIntentSender(IntentSender intent, |
| 872 | Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags) |
| 873 | throws IntentSender.SendIntentException { |
| 874 | try { |
| 875 | String resolvedType = null; |
| 876 | if (fillInIntent != null) { |
| 877 | resolvedType = fillInIntent.resolveTypeIfNeeded(getContentResolver()); |
| 878 | } |
| 879 | int result = ActivityManagerNative.getDefault() |
| 880 | .startActivityIntentSender(mMainThread.getApplicationThread(), intent, |
| 881 | fillInIntent, resolvedType, null, null, |
| 882 | 0, flagsMask, flagsValues); |
| 883 | if (result == IActivityManager.START_CANCELED) { |
| 884 | throw new IntentSender.SendIntentException(); |
| 885 | } |
| 886 | Instrumentation.checkStartActivityResult(result, null); |
| 887 | } catch (RemoteException e) { |
| 888 | } |
| 889 | } |
Christian Mehlmauer | 5f5acca | 2010-06-25 19:06:18 +0200 | [diff] [blame] | 890 | |
Dianne Hackborn | fa82f22 | 2009-09-17 15:14:12 -0700 | [diff] [blame] | 891 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 892 | public void sendBroadcast(Intent intent) { |
| 893 | String resolvedType = intent.resolveTypeIfNeeded(getContentResolver()); |
| 894 | try { |
| 895 | ActivityManagerNative.getDefault().broadcastIntent( |
| 896 | mMainThread.getApplicationThread(), intent, resolvedType, null, |
| 897 | Activity.RESULT_OK, null, null, null, false, false); |
| 898 | } catch (RemoteException e) { |
| 899 | } |
| 900 | } |
| 901 | |
| 902 | @Override |
| 903 | public void sendBroadcast(Intent intent, String receiverPermission) { |
| 904 | String resolvedType = intent.resolveTypeIfNeeded(getContentResolver()); |
| 905 | try { |
| 906 | ActivityManagerNative.getDefault().broadcastIntent( |
| 907 | mMainThread.getApplicationThread(), intent, resolvedType, null, |
| 908 | Activity.RESULT_OK, null, null, receiverPermission, false, false); |
| 909 | } catch (RemoteException e) { |
| 910 | } |
| 911 | } |
| 912 | |
| 913 | @Override |
| 914 | public void sendOrderedBroadcast(Intent intent, |
| 915 | String receiverPermission) { |
| 916 | String resolvedType = intent.resolveTypeIfNeeded(getContentResolver()); |
| 917 | try { |
| 918 | ActivityManagerNative.getDefault().broadcastIntent( |
| 919 | mMainThread.getApplicationThread(), intent, resolvedType, null, |
| 920 | Activity.RESULT_OK, null, null, receiverPermission, true, false); |
| 921 | } catch (RemoteException e) { |
| 922 | } |
| 923 | } |
| 924 | |
| 925 | @Override |
| 926 | public void sendOrderedBroadcast(Intent intent, |
| 927 | String receiverPermission, BroadcastReceiver resultReceiver, |
| 928 | Handler scheduler, int initialCode, String initialData, |
| 929 | Bundle initialExtras) { |
| 930 | IIntentReceiver rd = null; |
| 931 | if (resultReceiver != null) { |
| 932 | if (mPackageInfo != null) { |
| 933 | if (scheduler == null) { |
| 934 | scheduler = mMainThread.getHandler(); |
| 935 | } |
| 936 | rd = mPackageInfo.getReceiverDispatcher( |
| 937 | resultReceiver, getOuterContext(), scheduler, |
| 938 | mMainThread.getInstrumentation(), false); |
| 939 | } else { |
| 940 | if (scheduler == null) { |
| 941 | scheduler = mMainThread.getHandler(); |
| 942 | } |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 943 | rd = new LoadedApk.ReceiverDispatcher( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 944 | resultReceiver, getOuterContext(), scheduler, null, false).getIIntentReceiver(); |
| 945 | } |
| 946 | } |
| 947 | String resolvedType = intent.resolveTypeIfNeeded(getContentResolver()); |
| 948 | try { |
| 949 | ActivityManagerNative.getDefault().broadcastIntent( |
| 950 | mMainThread.getApplicationThread(), intent, resolvedType, rd, |
| 951 | initialCode, initialData, initialExtras, receiverPermission, |
| 952 | true, false); |
| 953 | } catch (RemoteException e) { |
| 954 | } |
| 955 | } |
| 956 | |
| 957 | @Override |
| 958 | public void sendStickyBroadcast(Intent intent) { |
| 959 | String resolvedType = intent.resolveTypeIfNeeded(getContentResolver()); |
| 960 | try { |
| 961 | ActivityManagerNative.getDefault().broadcastIntent( |
| 962 | mMainThread.getApplicationThread(), intent, resolvedType, null, |
| 963 | Activity.RESULT_OK, null, null, null, false, true); |
| 964 | } catch (RemoteException e) { |
| 965 | } |
| 966 | } |
| 967 | |
| 968 | @Override |
Dianne Hackborn | efa199f | 2009-09-19 12:03:15 -0700 | [diff] [blame] | 969 | public void sendStickyOrderedBroadcast(Intent intent, |
| 970 | BroadcastReceiver resultReceiver, |
| 971 | Handler scheduler, int initialCode, String initialData, |
| 972 | Bundle initialExtras) { |
| 973 | IIntentReceiver rd = null; |
| 974 | if (resultReceiver != null) { |
| 975 | if (mPackageInfo != null) { |
| 976 | if (scheduler == null) { |
| 977 | scheduler = mMainThread.getHandler(); |
| 978 | } |
| 979 | rd = mPackageInfo.getReceiverDispatcher( |
| 980 | resultReceiver, getOuterContext(), scheduler, |
| 981 | mMainThread.getInstrumentation(), false); |
| 982 | } else { |
| 983 | if (scheduler == null) { |
| 984 | scheduler = mMainThread.getHandler(); |
| 985 | } |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 986 | rd = new LoadedApk.ReceiverDispatcher( |
Dianne Hackborn | efa199f | 2009-09-19 12:03:15 -0700 | [diff] [blame] | 987 | resultReceiver, getOuterContext(), scheduler, null, false).getIIntentReceiver(); |
| 988 | } |
| 989 | } |
| 990 | String resolvedType = intent.resolveTypeIfNeeded(getContentResolver()); |
| 991 | try { |
| 992 | ActivityManagerNative.getDefault().broadcastIntent( |
| 993 | mMainThread.getApplicationThread(), intent, resolvedType, rd, |
| 994 | initialCode, initialData, initialExtras, null, |
| 995 | true, true); |
| 996 | } catch (RemoteException e) { |
| 997 | } |
| 998 | } |
| 999 | |
| 1000 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1001 | public void removeStickyBroadcast(Intent intent) { |
| 1002 | String resolvedType = intent.resolveTypeIfNeeded(getContentResolver()); |
| 1003 | if (resolvedType != null) { |
| 1004 | intent = new Intent(intent); |
| 1005 | intent.setDataAndType(intent.getData(), resolvedType); |
| 1006 | } |
| 1007 | try { |
| 1008 | ActivityManagerNative.getDefault().unbroadcastIntent( |
| 1009 | mMainThread.getApplicationThread(), intent); |
| 1010 | } catch (RemoteException e) { |
| 1011 | } |
| 1012 | } |
| 1013 | |
| 1014 | @Override |
| 1015 | public Intent registerReceiver(BroadcastReceiver receiver, IntentFilter filter) { |
| 1016 | return registerReceiver(receiver, filter, null, null); |
| 1017 | } |
| 1018 | |
| 1019 | @Override |
| 1020 | public Intent registerReceiver(BroadcastReceiver receiver, IntentFilter filter, |
| 1021 | String broadcastPermission, Handler scheduler) { |
| 1022 | return registerReceiverInternal(receiver, filter, broadcastPermission, |
| 1023 | scheduler, getOuterContext()); |
| 1024 | } |
| 1025 | |
| 1026 | private Intent registerReceiverInternal(BroadcastReceiver receiver, |
| 1027 | IntentFilter filter, String broadcastPermission, |
| 1028 | Handler scheduler, Context context) { |
| 1029 | IIntentReceiver rd = null; |
| 1030 | if (receiver != null) { |
| 1031 | if (mPackageInfo != null && context != null) { |
| 1032 | if (scheduler == null) { |
| 1033 | scheduler = mMainThread.getHandler(); |
| 1034 | } |
| 1035 | rd = mPackageInfo.getReceiverDispatcher( |
| 1036 | receiver, context, scheduler, |
| 1037 | mMainThread.getInstrumentation(), true); |
| 1038 | } else { |
| 1039 | if (scheduler == null) { |
| 1040 | scheduler = mMainThread.getHandler(); |
| 1041 | } |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1042 | rd = new LoadedApk.ReceiverDispatcher( |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 1043 | receiver, context, scheduler, null, true).getIIntentReceiver(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1044 | } |
| 1045 | } |
| 1046 | try { |
| 1047 | return ActivityManagerNative.getDefault().registerReceiver( |
Dianne Hackborn | 6c418d5 | 2011-06-29 14:05:33 -0700 | [diff] [blame] | 1048 | mMainThread.getApplicationThread(), mBasePackageName, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1049 | rd, filter, broadcastPermission); |
| 1050 | } catch (RemoteException e) { |
| 1051 | return null; |
| 1052 | } |
| 1053 | } |
| 1054 | |
| 1055 | @Override |
| 1056 | public void unregisterReceiver(BroadcastReceiver receiver) { |
| 1057 | if (mPackageInfo != null) { |
| 1058 | IIntentReceiver rd = mPackageInfo.forgetReceiverDispatcher( |
| 1059 | getOuterContext(), receiver); |
| 1060 | try { |
| 1061 | ActivityManagerNative.getDefault().unregisterReceiver(rd); |
| 1062 | } catch (RemoteException e) { |
| 1063 | } |
| 1064 | } else { |
| 1065 | throw new RuntimeException("Not supported in system context"); |
| 1066 | } |
| 1067 | } |
| 1068 | |
| 1069 | @Override |
| 1070 | public ComponentName startService(Intent service) { |
| 1071 | try { |
| 1072 | ComponentName cn = ActivityManagerNative.getDefault().startService( |
| 1073 | mMainThread.getApplicationThread(), service, |
| 1074 | service.resolveTypeIfNeeded(getContentResolver())); |
| 1075 | if (cn != null && cn.getPackageName().equals("!")) { |
| 1076 | throw new SecurityException( |
| 1077 | "Not allowed to start service " + service |
| 1078 | + " without permission " + cn.getClassName()); |
| 1079 | } |
| 1080 | return cn; |
| 1081 | } catch (RemoteException e) { |
| 1082 | return null; |
| 1083 | } |
| 1084 | } |
| 1085 | |
| 1086 | @Override |
| 1087 | public boolean stopService(Intent service) { |
| 1088 | try { |
| 1089 | int res = ActivityManagerNative.getDefault().stopService( |
| 1090 | mMainThread.getApplicationThread(), service, |
| 1091 | service.resolveTypeIfNeeded(getContentResolver())); |
| 1092 | if (res < 0) { |
| 1093 | throw new SecurityException( |
| 1094 | "Not allowed to stop service " + service); |
| 1095 | } |
| 1096 | return res != 0; |
| 1097 | } catch (RemoteException e) { |
| 1098 | return false; |
| 1099 | } |
| 1100 | } |
| 1101 | |
| 1102 | @Override |
| 1103 | public boolean bindService(Intent service, ServiceConnection conn, |
| 1104 | int flags) { |
| 1105 | IServiceConnection sd; |
| 1106 | if (mPackageInfo != null) { |
| 1107 | sd = mPackageInfo.getServiceDispatcher(conn, getOuterContext(), |
| 1108 | mMainThread.getHandler(), flags); |
| 1109 | } else { |
| 1110 | throw new RuntimeException("Not supported in system context"); |
| 1111 | } |
| 1112 | try { |
Dianne Hackborn | c68c913 | 2011-07-29 01:25:18 -0700 | [diff] [blame] | 1113 | IBinder token = getActivityToken(); |
| 1114 | if (token == null && (flags&BIND_AUTO_CREATE) == 0 && mPackageInfo != null |
| 1115 | && mPackageInfo.getApplicationInfo().targetSdkVersion |
| 1116 | < android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH) { |
| 1117 | flags |= BIND_WAIVE_PRIORITY; |
| 1118 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1119 | int res = ActivityManagerNative.getDefault().bindService( |
| 1120 | mMainThread.getApplicationThread(), getActivityToken(), |
| 1121 | service, service.resolveTypeIfNeeded(getContentResolver()), |
| 1122 | sd, flags); |
| 1123 | if (res < 0) { |
| 1124 | throw new SecurityException( |
| 1125 | "Not allowed to bind to service " + service); |
| 1126 | } |
| 1127 | return res != 0; |
| 1128 | } catch (RemoteException e) { |
| 1129 | return false; |
| 1130 | } |
| 1131 | } |
| 1132 | |
| 1133 | @Override |
| 1134 | public void unbindService(ServiceConnection conn) { |
| 1135 | if (mPackageInfo != null) { |
| 1136 | IServiceConnection sd = mPackageInfo.forgetServiceDispatcher( |
| 1137 | getOuterContext(), conn); |
| 1138 | try { |
| 1139 | ActivityManagerNative.getDefault().unbindService(sd); |
| 1140 | } catch (RemoteException e) { |
| 1141 | } |
| 1142 | } else { |
| 1143 | throw new RuntimeException("Not supported in system context"); |
| 1144 | } |
| 1145 | } |
| 1146 | |
| 1147 | @Override |
| 1148 | public boolean startInstrumentation(ComponentName className, |
| 1149 | String profileFile, Bundle arguments) { |
| 1150 | try { |
| 1151 | return ActivityManagerNative.getDefault().startInstrumentation( |
| 1152 | className, profileFile, 0, arguments, null); |
| 1153 | } catch (RemoteException e) { |
| 1154 | // System has crashed, nothing we can do. |
| 1155 | } |
| 1156 | return false; |
| 1157 | } |
| 1158 | |
| 1159 | @Override |
| 1160 | public Object getSystemService(String name) { |
Brad Fitzpatrick | 224ba0c | 2010-11-12 12:22:15 -0800 | [diff] [blame] | 1161 | ServiceFetcher fetcher = SYSTEM_SERVICE_MAP.get(name); |
| 1162 | return fetcher == null ? null : fetcher.getService(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1163 | } |
| 1164 | |
Dianne Hackborn | 8cc6a50 | 2009-08-05 21:29:42 -0700 | [diff] [blame] | 1165 | private WallpaperManager getWallpaperManager() { |
Brad Fitzpatrick | 224ba0c | 2010-11-12 12:22:15 -0800 | [diff] [blame] | 1166 | return (WallpaperManager) WALLPAPER_FETCHER.getService(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1167 | } |
| 1168 | |
Brad Fitzpatrick | 438d059 | 2010-06-10 12:19:19 -0700 | [diff] [blame] | 1169 | /* package */ static DropBoxManager createDropBoxManager() { |
| 1170 | IBinder b = ServiceManager.getService(DROPBOX_SERVICE); |
| 1171 | IDropBoxManagerService service = IDropBoxManagerService.Stub.asInterface(b); |
Brad Fitzpatrick | ec062f6 | 2010-11-03 09:56:54 -0700 | [diff] [blame] | 1172 | if (service == null) { |
| 1173 | // Don't return a DropBoxManager that will NPE upon use. |
| 1174 | // This also avoids caching a broken DropBoxManager in |
| 1175 | // getDropBoxManager during early boot, before the |
| 1176 | // DROPBOX_SERVICE is registered. |
| 1177 | return null; |
| 1178 | } |
Brad Fitzpatrick | 438d059 | 2010-06-10 12:19:19 -0700 | [diff] [blame] | 1179 | return new DropBoxManager(service); |
| 1180 | } |
| 1181 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1182 | @Override |
| 1183 | public int checkPermission(String permission, int pid, int uid) { |
| 1184 | if (permission == null) { |
| 1185 | throw new IllegalArgumentException("permission is null"); |
| 1186 | } |
| 1187 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1188 | try { |
| 1189 | return ActivityManagerNative.getDefault().checkPermission( |
| 1190 | permission, pid, uid); |
| 1191 | } catch (RemoteException e) { |
| 1192 | return PackageManager.PERMISSION_DENIED; |
| 1193 | } |
| 1194 | } |
| 1195 | |
| 1196 | @Override |
| 1197 | public int checkCallingPermission(String permission) { |
| 1198 | if (permission == null) { |
| 1199 | throw new IllegalArgumentException("permission is null"); |
| 1200 | } |
| 1201 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1202 | int pid = Binder.getCallingPid(); |
| 1203 | if (pid != Process.myPid()) { |
| 1204 | return checkPermission(permission, pid, |
| 1205 | Binder.getCallingUid()); |
| 1206 | } |
| 1207 | return PackageManager.PERMISSION_DENIED; |
| 1208 | } |
| 1209 | |
| 1210 | @Override |
| 1211 | public int checkCallingOrSelfPermission(String permission) { |
| 1212 | if (permission == null) { |
| 1213 | throw new IllegalArgumentException("permission is null"); |
| 1214 | } |
| 1215 | |
| 1216 | return checkPermission(permission, Binder.getCallingPid(), |
| 1217 | Binder.getCallingUid()); |
| 1218 | } |
| 1219 | |
| 1220 | private void enforce( |
| 1221 | String permission, int resultOfCheck, |
| 1222 | boolean selfToo, int uid, String message) { |
| 1223 | if (resultOfCheck != PackageManager.PERMISSION_GRANTED) { |
| 1224 | throw new SecurityException( |
| 1225 | (message != null ? (message + ": ") : "") + |
| 1226 | (selfToo |
| 1227 | ? "Neither user " + uid + " nor current process has " |
| 1228 | : "User " + uid + " does not have ") + |
| 1229 | permission + |
| 1230 | "."); |
| 1231 | } |
| 1232 | } |
| 1233 | |
| 1234 | public void enforcePermission( |
| 1235 | String permission, int pid, int uid, String message) { |
| 1236 | enforce(permission, |
| 1237 | checkPermission(permission, pid, uid), |
| 1238 | false, |
| 1239 | uid, |
| 1240 | message); |
| 1241 | } |
| 1242 | |
| 1243 | public void enforceCallingPermission(String permission, String message) { |
| 1244 | enforce(permission, |
| 1245 | checkCallingPermission(permission), |
| 1246 | false, |
| 1247 | Binder.getCallingUid(), |
| 1248 | message); |
| 1249 | } |
| 1250 | |
| 1251 | public void enforceCallingOrSelfPermission( |
| 1252 | String permission, String message) { |
| 1253 | enforce(permission, |
| 1254 | checkCallingOrSelfPermission(permission), |
| 1255 | true, |
| 1256 | Binder.getCallingUid(), |
| 1257 | message); |
| 1258 | } |
| 1259 | |
| 1260 | @Override |
| 1261 | public void grantUriPermission(String toPackage, Uri uri, int modeFlags) { |
| 1262 | try { |
| 1263 | ActivityManagerNative.getDefault().grantUriPermission( |
| 1264 | mMainThread.getApplicationThread(), toPackage, uri, |
| 1265 | modeFlags); |
| 1266 | } catch (RemoteException e) { |
| 1267 | } |
| 1268 | } |
| 1269 | |
| 1270 | @Override |
| 1271 | public void revokeUriPermission(Uri uri, int modeFlags) { |
| 1272 | try { |
| 1273 | ActivityManagerNative.getDefault().revokeUriPermission( |
| 1274 | mMainThread.getApplicationThread(), uri, |
| 1275 | modeFlags); |
| 1276 | } catch (RemoteException e) { |
| 1277 | } |
| 1278 | } |
| 1279 | |
| 1280 | @Override |
| 1281 | public int checkUriPermission(Uri uri, int pid, int uid, int modeFlags) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1282 | try { |
| 1283 | return ActivityManagerNative.getDefault().checkUriPermission( |
| 1284 | uri, pid, uid, modeFlags); |
| 1285 | } catch (RemoteException e) { |
| 1286 | return PackageManager.PERMISSION_DENIED; |
| 1287 | } |
| 1288 | } |
| 1289 | |
| 1290 | @Override |
| 1291 | public int checkCallingUriPermission(Uri uri, int modeFlags) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1292 | int pid = Binder.getCallingPid(); |
| 1293 | if (pid != Process.myPid()) { |
| 1294 | return checkUriPermission(uri, pid, |
| 1295 | Binder.getCallingUid(), modeFlags); |
| 1296 | } |
| 1297 | return PackageManager.PERMISSION_DENIED; |
| 1298 | } |
| 1299 | |
| 1300 | @Override |
| 1301 | public int checkCallingOrSelfUriPermission(Uri uri, int modeFlags) { |
| 1302 | return checkUriPermission(uri, Binder.getCallingPid(), |
| 1303 | Binder.getCallingUid(), modeFlags); |
| 1304 | } |
| 1305 | |
| 1306 | @Override |
| 1307 | public int checkUriPermission(Uri uri, String readPermission, |
| 1308 | String writePermission, int pid, int uid, int modeFlags) { |
Mitsuru Oshima | 569076c | 2009-07-02 20:06:08 -0700 | [diff] [blame] | 1309 | if (DEBUG) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1310 | Log.i("foo", "checkUriPermission: uri=" + uri + "readPermission=" |
| 1311 | + readPermission + " writePermission=" + writePermission |
| 1312 | + " pid=" + pid + " uid=" + uid + " mode" + modeFlags); |
| 1313 | } |
| 1314 | if ((modeFlags&Intent.FLAG_GRANT_READ_URI_PERMISSION) != 0) { |
| 1315 | if (readPermission == null |
| 1316 | || checkPermission(readPermission, pid, uid) |
| 1317 | == PackageManager.PERMISSION_GRANTED) { |
| 1318 | return PackageManager.PERMISSION_GRANTED; |
| 1319 | } |
| 1320 | } |
| 1321 | if ((modeFlags&Intent.FLAG_GRANT_WRITE_URI_PERMISSION) != 0) { |
| 1322 | if (writePermission == null |
| 1323 | || checkPermission(writePermission, pid, uid) |
| 1324 | == PackageManager.PERMISSION_GRANTED) { |
| 1325 | return PackageManager.PERMISSION_GRANTED; |
| 1326 | } |
| 1327 | } |
| 1328 | return uri != null ? checkUriPermission(uri, pid, uid, modeFlags) |
| 1329 | : PackageManager.PERMISSION_DENIED; |
| 1330 | } |
| 1331 | |
| 1332 | private String uriModeFlagToString(int uriModeFlags) { |
| 1333 | switch (uriModeFlags) { |
| 1334 | case Intent.FLAG_GRANT_READ_URI_PERMISSION | |
| 1335 | Intent.FLAG_GRANT_WRITE_URI_PERMISSION: |
| 1336 | return "read and write"; |
| 1337 | case Intent.FLAG_GRANT_READ_URI_PERMISSION: |
| 1338 | return "read"; |
| 1339 | case Intent.FLAG_GRANT_WRITE_URI_PERMISSION: |
| 1340 | return "write"; |
| 1341 | } |
| 1342 | throw new IllegalArgumentException( |
| 1343 | "Unknown permission mode flags: " + uriModeFlags); |
| 1344 | } |
| 1345 | |
| 1346 | private void enforceForUri( |
| 1347 | int modeFlags, int resultOfCheck, boolean selfToo, |
| 1348 | int uid, Uri uri, String message) { |
| 1349 | if (resultOfCheck != PackageManager.PERMISSION_GRANTED) { |
| 1350 | throw new SecurityException( |
| 1351 | (message != null ? (message + ": ") : "") + |
| 1352 | (selfToo |
| 1353 | ? "Neither user " + uid + " nor current process has " |
| 1354 | : "User " + uid + " does not have ") + |
| 1355 | uriModeFlagToString(modeFlags) + |
| 1356 | " permission on " + |
| 1357 | uri + |
| 1358 | "."); |
| 1359 | } |
| 1360 | } |
| 1361 | |
| 1362 | public void enforceUriPermission( |
| 1363 | Uri uri, int pid, int uid, int modeFlags, String message) { |
| 1364 | enforceForUri( |
| 1365 | modeFlags, checkUriPermission(uri, pid, uid, modeFlags), |
| 1366 | false, uid, uri, message); |
| 1367 | } |
| 1368 | |
| 1369 | public void enforceCallingUriPermission( |
| 1370 | Uri uri, int modeFlags, String message) { |
| 1371 | enforceForUri( |
| 1372 | modeFlags, checkCallingUriPermission(uri, modeFlags), |
| 1373 | false, Binder.getCallingUid(), uri, message); |
| 1374 | } |
| 1375 | |
| 1376 | public void enforceCallingOrSelfUriPermission( |
| 1377 | Uri uri, int modeFlags, String message) { |
| 1378 | enforceForUri( |
| 1379 | modeFlags, |
| 1380 | checkCallingOrSelfUriPermission(uri, modeFlags), true, |
| 1381 | Binder.getCallingUid(), uri, message); |
| 1382 | } |
| 1383 | |
| 1384 | public void enforceUriPermission( |
| 1385 | Uri uri, String readPermission, String writePermission, |
| 1386 | int pid, int uid, int modeFlags, String message) { |
| 1387 | enforceForUri(modeFlags, |
| 1388 | checkUriPermission( |
| 1389 | uri, readPermission, writePermission, pid, uid, |
| 1390 | modeFlags), |
| 1391 | false, |
| 1392 | uid, |
| 1393 | uri, |
| 1394 | message); |
| 1395 | } |
| 1396 | |
| 1397 | @Override |
| 1398 | public Context createPackageContext(String packageName, int flags) |
| 1399 | throws PackageManager.NameNotFoundException { |
| 1400 | if (packageName.equals("system") || packageName.equals("android")) { |
Dianne Hackborn | 2155637 | 2010-02-04 16:34:40 -0800 | [diff] [blame] | 1401 | return new ContextImpl(mMainThread.getSystemContext()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1402 | } |
| 1403 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1404 | LoadedApk pi = |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1405 | mMainThread.getPackageInfo(packageName, mResources.getCompatibilityInfo(), flags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1406 | if (pi != null) { |
Dianne Hackborn | 2155637 | 2010-02-04 16:34:40 -0800 | [diff] [blame] | 1407 | ContextImpl c = new ContextImpl(); |
Romain Guy | 870e09f | 2009-07-06 16:35:25 -0700 | [diff] [blame] | 1408 | c.mRestricted = (flags & CONTEXT_RESTRICTED) == CONTEXT_RESTRICTED; |
Dianne Hackborn | 6c418d5 | 2011-06-29 14:05:33 -0700 | [diff] [blame] | 1409 | c.init(pi, null, mMainThread, mResources, mBasePackageName); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1410 | if (c.mResources != null) { |
| 1411 | return c; |
| 1412 | } |
| 1413 | } |
| 1414 | |
| 1415 | // Should be a better exception. |
| 1416 | throw new PackageManager.NameNotFoundException( |
| 1417 | "Application package " + packageName + " not found"); |
| 1418 | } |
| 1419 | |
Romain Guy | 870e09f | 2009-07-06 16:35:25 -0700 | [diff] [blame] | 1420 | @Override |
| 1421 | public boolean isRestricted() { |
| 1422 | return mRestricted; |
| 1423 | } |
| 1424 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1425 | private File getDataDirFile() { |
| 1426 | if (mPackageInfo != null) { |
| 1427 | return mPackageInfo.getDataDirFile(); |
| 1428 | } |
| 1429 | throw new RuntimeException("Not supported in system context"); |
| 1430 | } |
| 1431 | |
| 1432 | @Override |
| 1433 | public File getDir(String name, int mode) { |
| 1434 | name = "app_" + name; |
| 1435 | File file = makeFilename(getDataDirFile(), name); |
| 1436 | if (!file.exists()) { |
| 1437 | file.mkdir(); |
| 1438 | setFilePermissionsFromMode(file.getPath(), mode, |
| 1439 | FileUtils.S_IRWXU|FileUtils.S_IRWXG|FileUtils.S_IXOTH); |
| 1440 | } |
| 1441 | return file; |
| 1442 | } |
| 1443 | |
Dianne Hackborn | 2155637 | 2010-02-04 16:34:40 -0800 | [diff] [blame] | 1444 | static ContextImpl createSystemContext(ActivityThread mainThread) { |
| 1445 | ContextImpl context = new ContextImpl(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1446 | context.init(Resources.getSystem(), mainThread); |
| 1447 | return context; |
| 1448 | } |
| 1449 | |
Dianne Hackborn | 2155637 | 2010-02-04 16:34:40 -0800 | [diff] [blame] | 1450 | ContextImpl() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1451 | mOuterContext = this; |
| 1452 | } |
| 1453 | |
| 1454 | /** |
| 1455 | * Create a new ApplicationContext from an existing one. The new one |
| 1456 | * works and operates the same as the one it is copying. |
| 1457 | * |
| 1458 | * @param context Existing application context. |
| 1459 | */ |
Dianne Hackborn | 2155637 | 2010-02-04 16:34:40 -0800 | [diff] [blame] | 1460 | public ContextImpl(ContextImpl context) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1461 | mPackageInfo = context.mPackageInfo; |
Dianne Hackborn | 6c418d5 | 2011-06-29 14:05:33 -0700 | [diff] [blame] | 1462 | mBasePackageName = context.mBasePackageName; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1463 | mResources = context.mResources; |
| 1464 | mMainThread = context.mMainThread; |
| 1465 | mContentResolver = context.mContentResolver; |
| 1466 | mOuterContext = this; |
| 1467 | } |
| 1468 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1469 | final void init(LoadedApk packageInfo, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1470 | IBinder activityToken, ActivityThread mainThread) { |
Dianne Hackborn | 6c418d5 | 2011-06-29 14:05:33 -0700 | [diff] [blame] | 1471 | init(packageInfo, activityToken, mainThread, null, null); |
Mitsuru Oshima | ba3ba57 | 2009-07-08 18:49:26 -0700 | [diff] [blame] | 1472 | } |
| 1473 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1474 | final void init(LoadedApk packageInfo, |
Mitsuru Oshima | ba3ba57 | 2009-07-08 18:49:26 -0700 | [diff] [blame] | 1475 | IBinder activityToken, ActivityThread mainThread, |
Dianne Hackborn | 6c418d5 | 2011-06-29 14:05:33 -0700 | [diff] [blame] | 1476 | Resources container, String basePackageName) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1477 | mPackageInfo = packageInfo; |
Dianne Hackborn | 6c418d5 | 2011-06-29 14:05:33 -0700 | [diff] [blame] | 1478 | mBasePackageName = basePackageName != null ? basePackageName : packageInfo.mPackageName; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1479 | mResources = mPackageInfo.getResources(mainThread); |
Mitsuru Oshima | ba3ba57 | 2009-07-08 18:49:26 -0700 | [diff] [blame] | 1480 | |
Dianne Hackborn | 559a787 | 2010-04-07 18:19:41 -0700 | [diff] [blame] | 1481 | if (mResources != null && container != null |
| 1482 | && container.getCompatibilityInfo().applicationScale != |
| 1483 | mResources.getCompatibilityInfo().applicationScale) { |
Mitsuru Oshima | ba3ba57 | 2009-07-08 18:49:26 -0700 | [diff] [blame] | 1484 | if (DEBUG) { |
| 1485 | Log.d(TAG, "loaded context has different scaling. Using container's" + |
| 1486 | " compatiblity info:" + container.getDisplayMetrics()); |
| 1487 | } |
| 1488 | mResources = mainThread.getTopLevelResources( |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1489 | mPackageInfo.getResDir(), container.getCompatibilityInfo()); |
Mitsuru Oshima | ba3ba57 | 2009-07-08 18:49:26 -0700 | [diff] [blame] | 1490 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1491 | mMainThread = mainThread; |
| 1492 | mContentResolver = new ApplicationContentResolver(this, mainThread); |
| 1493 | |
| 1494 | setActivityToken(activityToken); |
| 1495 | } |
| 1496 | |
| 1497 | final void init(Resources resources, ActivityThread mainThread) { |
| 1498 | mPackageInfo = null; |
Dianne Hackborn | 6c418d5 | 2011-06-29 14:05:33 -0700 | [diff] [blame] | 1499 | mBasePackageName = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1500 | mResources = resources; |
| 1501 | mMainThread = mainThread; |
| 1502 | mContentResolver = new ApplicationContentResolver(this, mainThread); |
| 1503 | } |
| 1504 | |
| 1505 | final void scheduleFinalCleanup(String who, String what) { |
| 1506 | mMainThread.scheduleContextCleanup(this, who, what); |
| 1507 | } |
| 1508 | |
| 1509 | final void performFinalCleanup(String who, String what) { |
| 1510 | //Log.i(TAG, "Cleanup up context: " + this); |
| 1511 | mPackageInfo.removeContextRegistrations(getOuterContext(), who, what); |
| 1512 | } |
| 1513 | |
| 1514 | final Context getReceiverRestrictedContext() { |
| 1515 | if (mReceiverRestrictedContext != null) { |
| 1516 | return mReceiverRestrictedContext; |
| 1517 | } |
| 1518 | return mReceiverRestrictedContext = new ReceiverRestrictedContext(getOuterContext()); |
| 1519 | } |
| 1520 | |
| 1521 | final void setActivityToken(IBinder token) { |
| 1522 | mActivityToken = token; |
| 1523 | } |
Christian Mehlmauer | 5f5acca | 2010-06-25 19:06:18 +0200 | [diff] [blame] | 1524 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1525 | final void setOuterContext(Context context) { |
| 1526 | mOuterContext = context; |
| 1527 | } |
Christian Mehlmauer | 5f5acca | 2010-06-25 19:06:18 +0200 | [diff] [blame] | 1528 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1529 | final Context getOuterContext() { |
| 1530 | return mOuterContext; |
| 1531 | } |
Christian Mehlmauer | 5f5acca | 2010-06-25 19:06:18 +0200 | [diff] [blame] | 1532 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1533 | final IBinder getActivityToken() { |
| 1534 | return mActivityToken; |
| 1535 | } |
| 1536 | |
Brad Fitzpatrick | d3da440 | 2010-11-10 08:27:11 -0800 | [diff] [blame] | 1537 | static void setFilePermissionsFromMode(String name, int mode, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1538 | int extraPermissions) { |
| 1539 | int perms = FileUtils.S_IRUSR|FileUtils.S_IWUSR |
| 1540 | |FileUtils.S_IRGRP|FileUtils.S_IWGRP |
| 1541 | |extraPermissions; |
| 1542 | if ((mode&MODE_WORLD_READABLE) != 0) { |
| 1543 | perms |= FileUtils.S_IROTH; |
| 1544 | } |
| 1545 | if ((mode&MODE_WORLD_WRITEABLE) != 0) { |
| 1546 | perms |= FileUtils.S_IWOTH; |
| 1547 | } |
Mitsuru Oshima | 569076c | 2009-07-02 20:06:08 -0700 | [diff] [blame] | 1548 | if (DEBUG) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1549 | Log.i(TAG, "File " + name + ": mode=0x" + Integer.toHexString(mode) |
| 1550 | + ", perms=0x" + Integer.toHexString(perms)); |
| 1551 | } |
| 1552 | FileUtils.setPermissions(name, perms, -1, -1); |
| 1553 | } |
| 1554 | |
Oscar Montemayor | a8529f6 | 2009-11-18 10:14:20 -0800 | [diff] [blame] | 1555 | private File validateFilePath(String name, boolean createDirectory) { |
| 1556 | File dir; |
| 1557 | File f; |
| 1558 | |
| 1559 | if (name.charAt(0) == File.separatorChar) { |
| 1560 | String dirPath = name.substring(0, name.lastIndexOf(File.separatorChar)); |
| 1561 | dir = new File(dirPath); |
| 1562 | name = name.substring(name.lastIndexOf(File.separatorChar)); |
| 1563 | f = new File(dir, name); |
| 1564 | } else { |
| 1565 | dir = getDatabasesDir(); |
| 1566 | f = makeFilename(dir, name); |
| 1567 | } |
| 1568 | |
| 1569 | if (createDirectory && !dir.isDirectory() && dir.mkdir()) { |
| 1570 | FileUtils.setPermissions(dir.getPath(), |
| 1571 | FileUtils.S_IRWXU|FileUtils.S_IRWXG|FileUtils.S_IXOTH, |
| 1572 | -1, -1); |
| 1573 | } |
| 1574 | |
| 1575 | return f; |
| 1576 | } |
| 1577 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1578 | private File makeFilename(File base, String name) { |
| 1579 | if (name.indexOf(File.separatorChar) < 0) { |
| 1580 | return new File(base, name); |
| 1581 | } |
| 1582 | throw new IllegalArgumentException( |
Oscar Montemayor | a8529f6 | 2009-11-18 10:14:20 -0800 | [diff] [blame] | 1583 | "File " + name + " contains a path separator"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1584 | } |
| 1585 | |
| 1586 | // ---------------------------------------------------------------------- |
| 1587 | // ---------------------------------------------------------------------- |
| 1588 | // ---------------------------------------------------------------------- |
| 1589 | |
| 1590 | private static final class ApplicationContentResolver extends ContentResolver { |
Dianne Hackborn | cca1f0e | 2010-09-26 18:34:53 -0700 | [diff] [blame] | 1591 | public ApplicationContentResolver(Context context, ActivityThread mainThread) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1592 | super(context); |
| 1593 | mMainThread = mainThread; |
| 1594 | } |
| 1595 | |
| 1596 | @Override |
Dianne Hackborn | cca1f0e | 2010-09-26 18:34:53 -0700 | [diff] [blame] | 1597 | protected IContentProvider acquireProvider(Context context, String name) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1598 | return mMainThread.acquireProvider(context, name); |
| 1599 | } |
| 1600 | |
| 1601 | @Override |
Dianne Hackborn | cca1f0e | 2010-09-26 18:34:53 -0700 | [diff] [blame] | 1602 | protected IContentProvider acquireExistingProvider(Context context, String name) { |
| 1603 | return mMainThread.acquireExistingProvider(context, name); |
| 1604 | } |
| 1605 | |
| 1606 | @Override |
| 1607 | public boolean releaseProvider(IContentProvider provider) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1608 | return mMainThread.releaseProvider(provider); |
| 1609 | } |
Christian Mehlmauer | 5f5acca | 2010-06-25 19:06:18 +0200 | [diff] [blame] | 1610 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1611 | private final ActivityThread mMainThread; |
| 1612 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1613 | } |