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 | |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 19 | import com.android.internal.annotations.GuardedBy; |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 20 | import com.android.internal.util.Preconditions; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 21 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 22 | import android.content.BroadcastReceiver; |
| 23 | import android.content.ComponentName; |
Nicolas Prevot | d85fc72 | 2014-04-16 19:52:08 +0100 | [diff] [blame] | 24 | import android.content.ContentProvider; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 25 | import android.content.ContentResolver; |
| 26 | import android.content.Context; |
| 27 | import android.content.ContextWrapper; |
| 28 | import android.content.IContentProvider; |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 29 | import android.content.IIntentReceiver; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 30 | import android.content.Intent; |
| 31 | import android.content.IntentFilter; |
Suchi Amalapurapu | 1ccac75 | 2009-06-12 10:09:58 -0700 | [diff] [blame] | 32 | import android.content.IntentSender; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 33 | import android.content.ReceiverCallNotAllowedException; |
| 34 | import android.content.ServiceConnection; |
| 35 | import android.content.SharedPreferences; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 36 | import android.content.pm.ApplicationInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 37 | import android.content.pm.IPackageManager; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 38 | import android.content.pm.PackageManager; |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 39 | import android.content.pm.PackageManager.NameNotFoundException; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 40 | import android.content.res.AssetManager; |
Dianne Hackborn | 5be8de3 | 2011-05-24 18:11:57 -0700 | [diff] [blame] | 41 | import android.content.res.CompatibilityInfo; |
Dianne Hackborn | 756220b | 2012-08-14 16:45:30 -0700 | [diff] [blame] | 42 | import android.content.res.Configuration; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 43 | import android.content.res.Resources; |
Vasu Nori | 74f170f | 2010-06-01 18:06:18 -0700 | [diff] [blame] | 44 | import android.database.DatabaseErrorHandler; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 45 | import android.database.sqlite.SQLiteDatabase; |
| 46 | import android.database.sqlite.SQLiteDatabase.CursorFactory; |
| 47 | import android.graphics.Bitmap; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 48 | import android.graphics.drawable.Drawable; |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 49 | import android.hardware.display.DisplayManager; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 50 | import android.net.Uri; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 51 | import android.os.Binder; |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 52 | import android.os.Build; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 53 | import android.os.Bundle; |
Amith Yamasani | cd75706 | 2012-10-19 18:23:52 -0700 | [diff] [blame] | 54 | import android.os.Debug; |
Oscar Montemayor | 539d3c4 | 2010-01-29 15:27:00 -0800 | [diff] [blame] | 55 | import android.os.Environment; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 56 | import android.os.FileUtils; |
| 57 | import android.os.Handler; |
| 58 | import android.os.IBinder; |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 59 | import android.os.Looper; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 60 | import android.os.Process; |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 61 | import android.os.RemoteException; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 62 | import android.os.ServiceManager; |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 63 | import android.os.UserHandle; |
Jeff Sharkey | 2d8b4e8 | 2013-09-17 17:30:33 -0700 | [diff] [blame] | 64 | import android.os.storage.IMountService; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 65 | import android.util.AndroidRuntimeException; |
Jeff Sharkey | 8e3ddab | 2013-06-17 18:26:37 -0700 | [diff] [blame] | 66 | import android.util.ArrayMap; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 67 | import android.util.Log; |
Amith Yamasani | cd75706 | 2012-10-19 18:23:52 -0700 | [diff] [blame] | 68 | import android.util.Slog; |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 69 | import android.view.Display; |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 70 | import android.view.DisplayAdjustments; |
Dan Egnor | 9524027 | 2009-10-27 18:23:39 -0700 | [diff] [blame] | 71 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 72 | import java.io.File; |
| 73 | import java.io.FileInputStream; |
| 74 | import java.io.FileNotFoundException; |
| 75 | import java.io.FileOutputStream; |
| 76 | import java.io.IOException; |
| 77 | import java.io.InputStream; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 78 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 79 | class ReceiverRestrictedContext extends ContextWrapper { |
| 80 | ReceiverRestrictedContext(Context base) { |
| 81 | super(base); |
| 82 | } |
| 83 | |
| 84 | @Override |
| 85 | public Intent registerReceiver(BroadcastReceiver receiver, IntentFilter filter) { |
| 86 | return registerReceiver(receiver, filter, null, null); |
| 87 | } |
| 88 | |
| 89 | @Override |
| 90 | public Intent registerReceiver(BroadcastReceiver receiver, IntentFilter filter, |
| 91 | String broadcastPermission, Handler scheduler) { |
Jeff Sharkey | 27bd34d | 2012-09-16 12:49:00 -0700 | [diff] [blame] | 92 | if (receiver == null) { |
| 93 | // Allow retrieving current sticky broadcast; this is safe since we |
| 94 | // aren't actually registering a receiver. |
| 95 | return super.registerReceiver(null, filter, broadcastPermission, scheduler); |
| 96 | } else { |
| 97 | throw new ReceiverCallNotAllowedException( |
| 98 | "BroadcastReceiver components are not allowed to register to receive intents"); |
| 99 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 100 | } |
| 101 | |
| 102 | @Override |
Dianne Hackborn | 20e8098 | 2012-08-31 19:00:44 -0700 | [diff] [blame] | 103 | public Intent registerReceiverAsUser(BroadcastReceiver receiver, UserHandle user, |
| 104 | IntentFilter filter, String broadcastPermission, Handler scheduler) { |
Jeff Sharkey | 27bd34d | 2012-09-16 12:49:00 -0700 | [diff] [blame] | 105 | if (receiver == null) { |
| 106 | // Allow retrieving current sticky broadcast; this is safe since we |
| 107 | // aren't actually registering a receiver. |
| 108 | return super.registerReceiverAsUser(null, user, filter, broadcastPermission, scheduler); |
| 109 | } else { |
| 110 | throw new ReceiverCallNotAllowedException( |
| 111 | "BroadcastReceiver components are not allowed to register to receive intents"); |
| 112 | } |
Dianne Hackborn | 20e8098 | 2012-08-31 19:00:44 -0700 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 116 | public boolean bindService(Intent service, ServiceConnection conn, int flags) { |
| 117 | throw new ReceiverCallNotAllowedException( |
Jeff Sharkey | 27bd34d | 2012-09-16 12:49:00 -0700 | [diff] [blame] | 118 | "BroadcastReceiver components are not allowed to bind to services"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 119 | } |
| 120 | } |
| 121 | |
| 122 | /** |
Dianne Hackborn | 2155637 | 2010-02-04 16:34:40 -0800 | [diff] [blame] | 123 | * Common implementation of Context API, which provides the base |
| 124 | * context object for Activity and other application components. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 125 | */ |
Dianne Hackborn | 2155637 | 2010-02-04 16:34:40 -0800 | [diff] [blame] | 126 | class ContextImpl extends Context { |
Dianne Hackborn | 40e9f29 | 2012-11-27 19:12:23 -0800 | [diff] [blame] | 127 | private final static String TAG = "ContextImpl"; |
Mitsuru Oshima | 569076c | 2009-07-02 20:06:08 -0700 | [diff] [blame] | 128 | private final static boolean DEBUG = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 129 | |
Jeff Sharkey | 8e3ddab | 2013-06-17 18:26:37 -0700 | [diff] [blame] | 130 | /** |
| 131 | * Map from package name, to preference name, to cached preferences. |
| 132 | */ |
| 133 | private static ArrayMap<String, ArrayMap<String, SharedPreferencesImpl>> sSharedPrefs; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 134 | |
Jeff Brown | defd4a6 | 2014-03-10 21:24:37 -0700 | [diff] [blame] | 135 | final ActivityThread mMainThread; |
| 136 | final LoadedApk mPackageInfo; |
| 137 | |
| 138 | private final IBinder mActivityToken; |
| 139 | |
| 140 | private final UserHandle mUser; |
| 141 | |
| 142 | private final ApplicationContentResolver mContentResolver; |
| 143 | |
| 144 | private final String mBasePackageName; |
| 145 | private final String mOpPackageName; |
| 146 | |
| 147 | private final ResourcesManager mResourcesManager; |
| 148 | private final Resources mResources; |
| 149 | private final Display mDisplay; // may be null if default display |
| 150 | private final DisplayAdjustments mDisplayAdjustments = new DisplayAdjustments(); |
Jeff Brown | defd4a6 | 2014-03-10 21:24:37 -0700 | [diff] [blame] | 151 | |
| 152 | private final boolean mRestricted; |
| 153 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 154 | private Context mOuterContext; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 155 | private int mThemeResource = 0; |
| 156 | private Resources.Theme mTheme = null; |
| 157 | private PackageManager mPackageManager; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 158 | private Context mReceiverRestrictedContext = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 159 | |
| 160 | private final Object mSync = new Object(); |
| 161 | |
Jeff Sharkey | 1abdb71 | 2013-08-11 16:28:14 -0700 | [diff] [blame] | 162 | @GuardedBy("mSync") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 163 | private File mDatabasesDir; |
Jeff Sharkey | 1abdb71 | 2013-08-11 16:28:14 -0700 | [diff] [blame] | 164 | @GuardedBy("mSync") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 165 | private File mPreferencesDir; |
Jeff Sharkey | 1abdb71 | 2013-08-11 16:28:14 -0700 | [diff] [blame] | 166 | @GuardedBy("mSync") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 167 | private File mFilesDir; |
Jeff Sharkey | 1abdb71 | 2013-08-11 16:28:14 -0700 | [diff] [blame] | 168 | @GuardedBy("mSync") |
Christopher Tate | a7835b6 | 2014-07-11 17:25:57 -0700 | [diff] [blame] | 169 | private File mNoBackupFilesDir; |
| 170 | @GuardedBy("mSync") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 171 | private File mCacheDir; |
Jeff Sharkey | 4ed745d | 2014-07-15 20:39:15 -0700 | [diff] [blame] | 172 | @GuardedBy("mSync") |
| 173 | private File mCodeCacheDir; |
Jeff Sharkey | 1abdb71 | 2013-08-11 16:28:14 -0700 | [diff] [blame] | 174 | |
| 175 | @GuardedBy("mSync") |
| 176 | private File[] mExternalObbDirs; |
| 177 | @GuardedBy("mSync") |
| 178 | private File[] mExternalFilesDirs; |
| 179 | @GuardedBy("mSync") |
| 180 | private File[] mExternalCacheDirs; |
Jeff Sharkey | 2ee3c1e | 2014-05-30 15:38:35 -0700 | [diff] [blame] | 181 | @GuardedBy("mSync") |
| 182 | private File[] mExternalMediaDirs; |
Christian Mehlmauer | 5f5acca | 2010-06-25 19:06:18 +0200 | [diff] [blame] | 183 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 184 | private static final String[] EMPTY_FILE_LIST = {}; |
| 185 | |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 186 | // The system service cache for the system services that are cached per-ContextImpl. |
| 187 | final Object[] mServiceCache = SystemServiceRegistry.createServiceCache(); |
Brad Fitzpatrick | 224ba0c | 2010-11-12 12:22:15 -0800 | [diff] [blame] | 188 | |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 189 | static ContextImpl getImpl(Context context) { |
| 190 | Context nextContext; |
| 191 | while ((context instanceof ContextWrapper) && |
| 192 | (nextContext=((ContextWrapper)context).getBaseContext()) != null) { |
| 193 | context = nextContext; |
| 194 | } |
| 195 | return (ContextImpl)context; |
| 196 | } |
| 197 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 198 | @Override |
| 199 | public AssetManager getAssets() { |
Dianne Hackborn | 756220b | 2012-08-14 16:45:30 -0700 | [diff] [blame] | 200 | return getResources().getAssets(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 201 | } |
| 202 | |
| 203 | @Override |
| 204 | public Resources getResources() { |
| 205 | return mResources; |
| 206 | } |
| 207 | |
| 208 | @Override |
| 209 | public PackageManager getPackageManager() { |
| 210 | if (mPackageManager != null) { |
| 211 | return mPackageManager; |
| 212 | } |
| 213 | |
| 214 | IPackageManager pm = ActivityThread.getPackageManager(); |
| 215 | if (pm != null) { |
| 216 | // Doesn't matter if we make more than one instance. |
| 217 | return (mPackageManager = new ApplicationPackageManager(this, pm)); |
| 218 | } |
| 219 | |
| 220 | return null; |
| 221 | } |
| 222 | |
| 223 | @Override |
| 224 | public ContentResolver getContentResolver() { |
| 225 | return mContentResolver; |
| 226 | } |
| 227 | |
| 228 | @Override |
| 229 | public Looper getMainLooper() { |
| 230 | return mMainThread.getLooper(); |
| 231 | } |
Christian Mehlmauer | 5f5acca | 2010-06-25 19:06:18 +0200 | [diff] [blame] | 232 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 233 | @Override |
| 234 | public Context getApplicationContext() { |
Christopher Tate | eb9e9ec | 2010-03-23 17:14:36 -0700 | [diff] [blame] | 235 | return (mPackageInfo != null) ? |
| 236 | mPackageInfo.getApplication() : mMainThread.getApplication(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 237 | } |
Christian Mehlmauer | 5f5acca | 2010-06-25 19:06:18 +0200 | [diff] [blame] | 238 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 239 | @Override |
| 240 | public void setTheme(int resid) { |
| 241 | mThemeResource = resid; |
| 242 | } |
Christian Mehlmauer | 5f5acca | 2010-06-25 19:06:18 +0200 | [diff] [blame] | 243 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 244 | @Override |
Dianne Hackborn | 247fe74 | 2011-01-08 17:25:57 -0800 | [diff] [blame] | 245 | public int getThemeResId() { |
| 246 | return mThemeResource; |
| 247 | } |
| 248 | |
| 249 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 250 | public Resources.Theme getTheme() { |
| 251 | if (mTheme == null) { |
Alan Viverette | 5effd7e | 2014-05-05 12:25:33 -0700 | [diff] [blame] | 252 | mThemeResource = Resources.selectDefaultTheme(mThemeResource, |
Dianne Hackborn | d922ae0 | 2011-01-14 11:43:24 -0800 | [diff] [blame] | 253 | getOuterContext().getApplicationInfo().targetSdkVersion); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 254 | mTheme = mResources.newTheme(); |
| 255 | mTheme.applyStyle(mThemeResource, true); |
| 256 | } |
| 257 | return mTheme; |
| 258 | } |
| 259 | |
| 260 | @Override |
| 261 | public ClassLoader getClassLoader() { |
| 262 | return mPackageInfo != null ? |
| 263 | mPackageInfo.getClassLoader() : ClassLoader.getSystemClassLoader(); |
| 264 | } |
| 265 | |
| 266 | @Override |
| 267 | public String getPackageName() { |
| 268 | if (mPackageInfo != null) { |
| 269 | return mPackageInfo.getPackageName(); |
| 270 | } |
Dianne Hackborn | 35654b6 | 2013-01-14 17:38:02 -0800 | [diff] [blame] | 271 | // No mPackageInfo means this is a Context for the system itself, |
| 272 | // and this here is its name. |
| 273 | return "android"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 274 | } |
| 275 | |
Dianne Hackborn | d8e1dbb | 2013-01-17 17:47:37 -0800 | [diff] [blame] | 276 | /** @hide */ |
| 277 | @Override |
| 278 | public String getBasePackageName() { |
| 279 | return mBasePackageName != null ? mBasePackageName : getPackageName(); |
| 280 | } |
| 281 | |
Dianne Hackborn | 95d7853 | 2013-09-11 09:51:14 -0700 | [diff] [blame] | 282 | /** @hide */ |
| 283 | @Override |
| 284 | public String getOpPackageName() { |
| 285 | return mOpPackageName != null ? mOpPackageName : getBasePackageName(); |
| 286 | } |
| 287 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 288 | @Override |
Dianne Hackborn | 5c1e00b | 2009-06-18 17:10:57 -0700 | [diff] [blame] | 289 | public ApplicationInfo getApplicationInfo() { |
| 290 | if (mPackageInfo != null) { |
| 291 | return mPackageInfo.getApplicationInfo(); |
| 292 | } |
| 293 | throw new RuntimeException("Not supported in system context"); |
| 294 | } |
| 295 | |
| 296 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 297 | public String getPackageResourcePath() { |
| 298 | if (mPackageInfo != null) { |
| 299 | return mPackageInfo.getResDir(); |
| 300 | } |
| 301 | throw new RuntimeException("Not supported in system context"); |
| 302 | } |
| 303 | |
| 304 | @Override |
| 305 | public String getPackageCodePath() { |
| 306 | if (mPackageInfo != null) { |
| 307 | return mPackageInfo.getAppDir(); |
| 308 | } |
| 309 | throw new RuntimeException("Not supported in system context"); |
| 310 | } |
Christian Mehlmauer | 5f5acca | 2010-06-25 19:06:18 +0200 | [diff] [blame] | 311 | |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 312 | @Override |
Joe Onorato | 23ecae3 | 2009-06-10 17:07:15 -0700 | [diff] [blame] | 313 | public File getSharedPrefsFile(String name) { |
| 314 | return makeFilename(getPreferencesDir(), name + ".xml"); |
| 315 | } |
| 316 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 317 | @Override |
| 318 | public SharedPreferences getSharedPreferences(String name, int mode) { |
| 319 | SharedPreferencesImpl sp; |
Dianne Hackborn | f691359 | 2013-09-05 13:21:24 -0700 | [diff] [blame] | 320 | synchronized (ContextImpl.class) { |
Jeff Sharkey | 8e3ddab | 2013-06-17 18:26:37 -0700 | [diff] [blame] | 321 | if (sSharedPrefs == null) { |
| 322 | sSharedPrefs = new ArrayMap<String, ArrayMap<String, SharedPreferencesImpl>>(); |
| 323 | } |
| 324 | |
| 325 | final String packageName = getPackageName(); |
| 326 | ArrayMap<String, SharedPreferencesImpl> packagePrefs = sSharedPrefs.get(packageName); |
| 327 | if (packagePrefs == null) { |
| 328 | packagePrefs = new ArrayMap<String, SharedPreferencesImpl>(); |
| 329 | sSharedPrefs.put(packageName, packagePrefs); |
| 330 | } |
| 331 | |
Dianne Hackborn | ff32f35 | 2013-07-18 17:31:13 -0700 | [diff] [blame] | 332 | // At least one application in the world actually passes in a null |
| 333 | // name. This happened to work because when we generated the file name |
| 334 | // we would stringify it to "null.xml". Nice. |
| 335 | if (mPackageInfo.getApplicationInfo().targetSdkVersion < |
Chet Haase | e8222dd | 2013-09-05 07:44:18 -0700 | [diff] [blame] | 336 | Build.VERSION_CODES.KITKAT) { |
Dianne Hackborn | ff32f35 | 2013-07-18 17:31:13 -0700 | [diff] [blame] | 337 | if (name == null) { |
| 338 | name = "null"; |
| 339 | } |
| 340 | } |
| 341 | |
Jeff Sharkey | 8e3ddab | 2013-06-17 18:26:37 -0700 | [diff] [blame] | 342 | sp = packagePrefs.get(name); |
Brad Fitzpatrick | 6194c53 | 2010-09-07 18:00:33 -0700 | [diff] [blame] | 343 | if (sp == null) { |
Brad Fitzpatrick | 4cd50b8 | 2010-12-01 17:31:45 -0800 | [diff] [blame] | 344 | File prefsFile = getSharedPrefsFile(name); |
| 345 | sp = new SharedPreferencesImpl(prefsFile, mode); |
Jeff Sharkey | 8e3ddab | 2013-06-17 18:26:37 -0700 | [diff] [blame] | 346 | packagePrefs.put(name, sp); |
Brad Fitzpatrick | 6194c53 | 2010-09-07 18:00:33 -0700 | [diff] [blame] | 347 | return sp; |
| 348 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 349 | } |
Brad Fitzpatrick | 4e920f7 | 2010-12-14 11:52:13 -0800 | [diff] [blame] | 350 | if ((mode & Context.MODE_MULTI_PROCESS) != 0 || |
| 351 | getApplicationInfo().targetSdkVersion < android.os.Build.VERSION_CODES.HONEYCOMB) { |
| 352 | // If somebody else (some other process) changed the prefs |
| 353 | // file behind our back, we reload it. This has been the |
| 354 | // historical (if undocumented) behavior. |
| 355 | sp.startReloadIfChangedUnexpectedly(); |
| 356 | } |
Brad Fitzpatrick | 6194c53 | 2010-09-07 18:00:33 -0700 | [diff] [blame] | 357 | return sp; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 358 | } |
| 359 | |
| 360 | private File getPreferencesDir() { |
| 361 | synchronized (mSync) { |
| 362 | if (mPreferencesDir == null) { |
| 363 | mPreferencesDir = new File(getDataDirFile(), "shared_prefs"); |
| 364 | } |
| 365 | return mPreferencesDir; |
| 366 | } |
| 367 | } |
| 368 | |
| 369 | @Override |
| 370 | public FileInputStream openFileInput(String name) |
| 371 | throws FileNotFoundException { |
| 372 | File f = makeFilename(getFilesDir(), name); |
| 373 | return new FileInputStream(f); |
| 374 | } |
| 375 | |
| 376 | @Override |
| 377 | public FileOutputStream openFileOutput(String name, int mode) |
| 378 | throws FileNotFoundException { |
| 379 | final boolean append = (mode&MODE_APPEND) != 0; |
| 380 | File f = makeFilename(getFilesDir(), name); |
| 381 | try { |
| 382 | FileOutputStream fos = new FileOutputStream(f, append); |
| 383 | setFilePermissionsFromMode(f.getPath(), mode, 0); |
| 384 | return fos; |
| 385 | } catch (FileNotFoundException e) { |
| 386 | } |
| 387 | |
| 388 | File parent = f.getParentFile(); |
| 389 | parent.mkdir(); |
| 390 | FileUtils.setPermissions( |
| 391 | parent.getPath(), |
| 392 | FileUtils.S_IRWXU|FileUtils.S_IRWXG|FileUtils.S_IXOTH, |
| 393 | -1, -1); |
| 394 | FileOutputStream fos = new FileOutputStream(f, append); |
| 395 | setFilePermissionsFromMode(f.getPath(), mode, 0); |
| 396 | return fos; |
| 397 | } |
| 398 | |
| 399 | @Override |
| 400 | public boolean deleteFile(String name) { |
| 401 | File f = makeFilename(getFilesDir(), name); |
| 402 | return f.delete(); |
| 403 | } |
| 404 | |
Christopher Tate | a7835b6 | 2014-07-11 17:25:57 -0700 | [diff] [blame] | 405 | // Common-path handling of app data dir creation |
| 406 | private static File createFilesDirLocked(File file) { |
| 407 | if (!file.exists()) { |
| 408 | if (!file.mkdirs()) { |
| 409 | if (file.exists()) { |
| 410 | // spurious failure; probably racing with another process for this app |
| 411 | return file; |
| 412 | } |
| 413 | Log.w(TAG, "Unable to create files subdir " + file.getPath()); |
| 414 | return null; |
| 415 | } |
| 416 | FileUtils.setPermissions( |
| 417 | file.getPath(), |
| 418 | FileUtils.S_IRWXU|FileUtils.S_IRWXG|FileUtils.S_IXOTH, |
| 419 | -1, -1); |
| 420 | } |
| 421 | return file; |
| 422 | } |
| 423 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 424 | @Override |
| 425 | public File getFilesDir() { |
| 426 | synchronized (mSync) { |
| 427 | if (mFilesDir == null) { |
| 428 | mFilesDir = new File(getDataDirFile(), "files"); |
| 429 | } |
Christopher Tate | a7835b6 | 2014-07-11 17:25:57 -0700 | [diff] [blame] | 430 | return createFilesDirLocked(mFilesDir); |
| 431 | } |
| 432 | } |
| 433 | |
| 434 | @Override |
| 435 | public File getNoBackupFilesDir() { |
| 436 | synchronized (mSync) { |
| 437 | if (mNoBackupFilesDir == null) { |
| 438 | mNoBackupFilesDir = new File(getDataDirFile(), "no_backup"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 439 | } |
Christopher Tate | a7835b6 | 2014-07-11 17:25:57 -0700 | [diff] [blame] | 440 | return createFilesDirLocked(mNoBackupFilesDir); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 441 | } |
| 442 | } |
Christian Mehlmauer | 5f5acca | 2010-06-25 19:06:18 +0200 | [diff] [blame] | 443 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 444 | @Override |
Dianne Hackborn | e83cefce | 2010-02-04 17:38:14 -0800 | [diff] [blame] | 445 | public File getExternalFilesDir(String type) { |
Jeff Sharkey | 1abdb71 | 2013-08-11 16:28:14 -0700 | [diff] [blame] | 446 | // Operates on primary external storage |
| 447 | return getExternalFilesDirs(type)[0]; |
| 448 | } |
| 449 | |
| 450 | @Override |
| 451 | public File[] getExternalFilesDirs(String type) { |
Dianne Hackborn | e83cefce | 2010-02-04 17:38:14 -0800 | [diff] [blame] | 452 | synchronized (mSync) { |
Jeff Sharkey | 1abdb71 | 2013-08-11 16:28:14 -0700 | [diff] [blame] | 453 | if (mExternalFilesDirs == null) { |
| 454 | mExternalFilesDirs = Environment.buildExternalStorageAppFilesDirs(getPackageName()); |
Dianne Hackborn | e83cefce | 2010-02-04 17:38:14 -0800 | [diff] [blame] | 455 | } |
Jeff Sharkey | 1abdb71 | 2013-08-11 16:28:14 -0700 | [diff] [blame] | 456 | |
| 457 | // Splice in requested type, if any |
| 458 | File[] dirs = mExternalFilesDirs; |
| 459 | if (type != null) { |
| 460 | dirs = Environment.buildPaths(dirs, type); |
Dianne Hackborn | e83cefce | 2010-02-04 17:38:14 -0800 | [diff] [blame] | 461 | } |
Jeff Sharkey | 1abdb71 | 2013-08-11 16:28:14 -0700 | [diff] [blame] | 462 | |
| 463 | // Create dirs if needed |
| 464 | return ensureDirsExistOrFilter(dirs); |
Dianne Hackborn | e83cefce | 2010-02-04 17:38:14 -0800 | [diff] [blame] | 465 | } |
| 466 | } |
Christian Mehlmauer | 5f5acca | 2010-06-25 19:06:18 +0200 | [diff] [blame] | 467 | |
Dianne Hackborn | e83cefce | 2010-02-04 17:38:14 -0800 | [diff] [blame] | 468 | @Override |
Dianne Hackborn | 805fd7e | 2011-01-16 18:30:29 -0800 | [diff] [blame] | 469 | public File getObbDir() { |
Jeff Sharkey | 1abdb71 | 2013-08-11 16:28:14 -0700 | [diff] [blame] | 470 | // Operates on primary external storage |
| 471 | return getObbDirs()[0]; |
| 472 | } |
| 473 | |
| 474 | @Override |
| 475 | public File[] getObbDirs() { |
Dianne Hackborn | 805fd7e | 2011-01-16 18:30:29 -0800 | [diff] [blame] | 476 | synchronized (mSync) { |
Jeff Sharkey | 1abdb71 | 2013-08-11 16:28:14 -0700 | [diff] [blame] | 477 | if (mExternalObbDirs == null) { |
| 478 | mExternalObbDirs = Environment.buildExternalStorageAppObbDirs(getPackageName()); |
Dianne Hackborn | 805fd7e | 2011-01-16 18:30:29 -0800 | [diff] [blame] | 479 | } |
Jeff Sharkey | 2d8b4e8 | 2013-09-17 17:30:33 -0700 | [diff] [blame] | 480 | |
| 481 | // Create dirs if needed |
| 482 | return ensureDirsExistOrFilter(mExternalObbDirs); |
Dianne Hackborn | 805fd7e | 2011-01-16 18:30:29 -0800 | [diff] [blame] | 483 | } |
| 484 | } |
| 485 | |
| 486 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 487 | public File getCacheDir() { |
| 488 | synchronized (mSync) { |
| 489 | if (mCacheDir == null) { |
| 490 | mCacheDir = new File(getDataDirFile(), "cache"); |
| 491 | } |
Christopher Tate | a7835b6 | 2014-07-11 17:25:57 -0700 | [diff] [blame] | 492 | return createFilesDirLocked(mCacheDir); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 493 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 494 | } |
Christian Mehlmauer | 5f5acca | 2010-06-25 19:06:18 +0200 | [diff] [blame] | 495 | |
Dianne Hackborn | e83cefce | 2010-02-04 17:38:14 -0800 | [diff] [blame] | 496 | @Override |
Jeff Sharkey | 4ed745d | 2014-07-15 20:39:15 -0700 | [diff] [blame] | 497 | public File getCodeCacheDir() { |
| 498 | synchronized (mSync) { |
| 499 | if (mCodeCacheDir == null) { |
| 500 | mCodeCacheDir = new File(getDataDirFile(), "code_cache"); |
| 501 | } |
| 502 | return createFilesDirLocked(mCodeCacheDir); |
| 503 | } |
| 504 | } |
| 505 | |
| 506 | @Override |
Dianne Hackborn | e83cefce | 2010-02-04 17:38:14 -0800 | [diff] [blame] | 507 | public File getExternalCacheDir() { |
Jeff Sharkey | 1abdb71 | 2013-08-11 16:28:14 -0700 | [diff] [blame] | 508 | // Operates on primary external storage |
| 509 | return getExternalCacheDirs()[0]; |
| 510 | } |
| 511 | |
| 512 | @Override |
| 513 | public File[] getExternalCacheDirs() { |
Dianne Hackborn | e83cefce | 2010-02-04 17:38:14 -0800 | [diff] [blame] | 514 | synchronized (mSync) { |
Jeff Sharkey | 1abdb71 | 2013-08-11 16:28:14 -0700 | [diff] [blame] | 515 | if (mExternalCacheDirs == null) { |
| 516 | mExternalCacheDirs = Environment.buildExternalStorageAppCacheDirs(getPackageName()); |
Dianne Hackborn | e83cefce | 2010-02-04 17:38:14 -0800 | [diff] [blame] | 517 | } |
Jeff Sharkey | 1abdb71 | 2013-08-11 16:28:14 -0700 | [diff] [blame] | 518 | |
| 519 | // Create dirs if needed |
| 520 | return ensureDirsExistOrFilter(mExternalCacheDirs); |
Dianne Hackborn | e83cefce | 2010-02-04 17:38:14 -0800 | [diff] [blame] | 521 | } |
| 522 | } |
Christian Mehlmauer | 5f5acca | 2010-06-25 19:06:18 +0200 | [diff] [blame] | 523 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 524 | @Override |
Jeff Sharkey | 2ee3c1e | 2014-05-30 15:38:35 -0700 | [diff] [blame] | 525 | public File[] getExternalMediaDirs() { |
| 526 | synchronized (mSync) { |
| 527 | if (mExternalMediaDirs == null) { |
| 528 | mExternalMediaDirs = Environment.buildExternalStorageAppMediaDirs(getPackageName()); |
| 529 | } |
| 530 | |
| 531 | // Create dirs if needed |
| 532 | return ensureDirsExistOrFilter(mExternalMediaDirs); |
| 533 | } |
| 534 | } |
| 535 | |
| 536 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 537 | public File getFileStreamPath(String name) { |
| 538 | return makeFilename(getFilesDir(), name); |
| 539 | } |
| 540 | |
| 541 | @Override |
| 542 | public String[] fileList() { |
| 543 | final String[] list = getFilesDir().list(); |
| 544 | return (list != null) ? list : EMPTY_FILE_LIST; |
| 545 | } |
| 546 | |
| 547 | @Override |
| 548 | public SQLiteDatabase openOrCreateDatabase(String name, int mode, CursorFactory factory) { |
Jeff Brown | 47847f3 | 2012-03-22 19:13:11 -0700 | [diff] [blame] | 549 | return openOrCreateDatabase(name, mode, factory, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 550 | } |
| 551 | |
| 552 | @Override |
Vasu Nori | 74f170f | 2010-06-01 18:06:18 -0700 | [diff] [blame] | 553 | public SQLiteDatabase openOrCreateDatabase(String name, int mode, CursorFactory factory, |
| 554 | DatabaseErrorHandler errorHandler) { |
| 555 | File f = validateFilePath(name, true); |
Jeff Brown | 47847f3 | 2012-03-22 19:13:11 -0700 | [diff] [blame] | 556 | int flags = SQLiteDatabase.CREATE_IF_NECESSARY; |
| 557 | if ((mode & MODE_ENABLE_WRITE_AHEAD_LOGGING) != 0) { |
| 558 | flags |= SQLiteDatabase.ENABLE_WRITE_AHEAD_LOGGING; |
| 559 | } |
| 560 | SQLiteDatabase db = SQLiteDatabase.openDatabase(f.getPath(), factory, flags, errorHandler); |
Vasu Nori | 74f170f | 2010-06-01 18:06:18 -0700 | [diff] [blame] | 561 | setFilePermissionsFromMode(f.getPath(), mode, 0); |
| 562 | return db; |
| 563 | } |
| 564 | |
| 565 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 566 | public boolean deleteDatabase(String name) { |
| 567 | try { |
Oscar Montemayor | a8529f6 | 2009-11-18 10:14:20 -0800 | [diff] [blame] | 568 | File f = validateFilePath(name, false); |
Jeff Brown | 79087e4 | 2012-03-01 19:52:44 -0800 | [diff] [blame] | 569 | return SQLiteDatabase.deleteDatabase(f); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 570 | } catch (Exception e) { |
| 571 | } |
| 572 | return false; |
| 573 | } |
| 574 | |
| 575 | @Override |
| 576 | public File getDatabasePath(String name) { |
Oscar Montemayor | a8529f6 | 2009-11-18 10:14:20 -0800 | [diff] [blame] | 577 | return validateFilePath(name, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 578 | } |
| 579 | |
| 580 | @Override |
| 581 | public String[] databaseList() { |
| 582 | final String[] list = getDatabasesDir().list(); |
| 583 | return (list != null) ? list : EMPTY_FILE_LIST; |
| 584 | } |
| 585 | |
Christian Mehlmauer | 5f5acca | 2010-06-25 19:06:18 +0200 | [diff] [blame] | 586 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 587 | private File getDatabasesDir() { |
| 588 | synchronized (mSync) { |
| 589 | if (mDatabasesDir == null) { |
| 590 | mDatabasesDir = new File(getDataDirFile(), "databases"); |
| 591 | } |
| 592 | if (mDatabasesDir.getPath().equals("databases")) { |
| 593 | mDatabasesDir = new File("/data/system"); |
| 594 | } |
| 595 | return mDatabasesDir; |
| 596 | } |
| 597 | } |
Christian Mehlmauer | 5f5acca | 2010-06-25 19:06:18 +0200 | [diff] [blame] | 598 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 599 | @Override |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 600 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 601 | public Drawable getWallpaper() { |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 602 | return getWallpaperManager().getDrawable(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 603 | } |
| 604 | |
| 605 | @Override |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 606 | @Deprecated |
Dianne Hackborn | 8cc6a50 | 2009-08-05 21:29:42 -0700 | [diff] [blame] | 607 | public Drawable peekWallpaper() { |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 608 | return getWallpaperManager().peekDrawable(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 609 | } |
| 610 | |
| 611 | @Override |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 612 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 613 | public int getWallpaperDesiredMinimumWidth() { |
Dianne Hackborn | 8cc6a50 | 2009-08-05 21:29:42 -0700 | [diff] [blame] | 614 | return getWallpaperManager().getDesiredMinimumWidth(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 615 | } |
| 616 | |
| 617 | @Override |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 618 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 619 | public int getWallpaperDesiredMinimumHeight() { |
Dianne Hackborn | 8cc6a50 | 2009-08-05 21:29:42 -0700 | [diff] [blame] | 620 | return getWallpaperManager().getDesiredMinimumHeight(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 621 | } |
| 622 | |
| 623 | @Override |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 624 | @Deprecated |
| 625 | public void setWallpaper(Bitmap bitmap) throws IOException { |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 626 | getWallpaperManager().setBitmap(bitmap); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 627 | } |
| 628 | |
| 629 | @Override |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 630 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 631 | public void setWallpaper(InputStream data) throws IOException { |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 632 | getWallpaperManager().setStream(data); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 633 | } |
| 634 | |
| 635 | @Override |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 636 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 637 | public void clearWallpaper() throws IOException { |
Dianne Hackborn | 8cc6a50 | 2009-08-05 21:29:42 -0700 | [diff] [blame] | 638 | getWallpaperManager().clear(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 639 | } |
| 640 | |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 641 | private WallpaperManager getWallpaperManager() { |
| 642 | return getSystemService(WallpaperManager.class); |
| 643 | } |
| 644 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 645 | @Override |
| 646 | public void startActivity(Intent intent) { |
Amith Yamasani | cd75706 | 2012-10-19 18:23:52 -0700 | [diff] [blame] | 647 | warnIfCallingFromSystemProcess(); |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 648 | startActivity(intent, null); |
| 649 | } |
| 650 | |
Amith Yamasani | 8264408 | 2012-08-03 13:09:11 -0700 | [diff] [blame] | 651 | /** @hide */ |
| 652 | @Override |
Dianne Hackborn | 79af1dd | 2012-08-16 16:42:52 -0700 | [diff] [blame] | 653 | public void startActivityAsUser(Intent intent, UserHandle user) { |
Dianne Hackborn | f1c26e2 | 2012-08-23 13:54:58 -0700 | [diff] [blame] | 654 | startActivityAsUser(intent, null, user); |
Amith Yamasani | 8264408 | 2012-08-03 13:09:11 -0700 | [diff] [blame] | 655 | } |
| 656 | |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 657 | @Override |
| 658 | public void startActivity(Intent intent, Bundle options) { |
Amith Yamasani | cd75706 | 2012-10-19 18:23:52 -0700 | [diff] [blame] | 659 | warnIfCallingFromSystemProcess(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 660 | if ((intent.getFlags()&Intent.FLAG_ACTIVITY_NEW_TASK) == 0) { |
| 661 | throw new AndroidRuntimeException( |
| 662 | "Calling startActivity() from outside of an Activity " |
| 663 | + " context requires the FLAG_ACTIVITY_NEW_TASK flag." |
| 664 | + " Is this really what you want?"); |
| 665 | } |
| 666 | mMainThread.getInstrumentation().execStartActivity( |
Dianne Hackborn | 6e8304e | 2010-05-14 00:42:53 -0700 | [diff] [blame] | 667 | getOuterContext(), mMainThread.getApplicationThread(), null, |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 668 | (Activity)null, intent, -1, options); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 669 | } |
| 670 | |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 671 | /** @hide */ |
| 672 | @Override |
Dianne Hackborn | 79af1dd | 2012-08-16 16:42:52 -0700 | [diff] [blame] | 673 | public void startActivityAsUser(Intent intent, Bundle options, UserHandle user) { |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 674 | try { |
| 675 | ActivityManagerNative.getDefault().startActivityAsUser( |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 676 | mMainThread.getApplicationThread(), getBasePackageName(), intent, |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 677 | intent.resolveTypeIfNeeded(getContentResolver()), |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 678 | null, null, 0, Intent.FLAG_ACTIVITY_NEW_TASK, null, options, |
Dianne Hackborn | 79af1dd | 2012-08-16 16:42:52 -0700 | [diff] [blame] | 679 | user.getIdentifier()); |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 680 | } catch (RemoteException re) { |
| 681 | } |
| 682 | } |
| 683 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 684 | @Override |
Dianne Hackborn | 621e17d | 2010-11-22 15:59:56 -0800 | [diff] [blame] | 685 | public void startActivities(Intent[] intents) { |
Amith Yamasani | cd75706 | 2012-10-19 18:23:52 -0700 | [diff] [blame] | 686 | warnIfCallingFromSystemProcess(); |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 687 | startActivities(intents, null); |
| 688 | } |
| 689 | |
Amith Yamasani | ea7e915 | 2012-09-24 16:11:18 -0700 | [diff] [blame] | 690 | /** @hide */ |
| 691 | @Override |
| 692 | public void startActivitiesAsUser(Intent[] intents, Bundle options, UserHandle userHandle) { |
| 693 | if ((intents[0].getFlags()&Intent.FLAG_ACTIVITY_NEW_TASK) == 0) { |
| 694 | throw new AndroidRuntimeException( |
| 695 | "Calling startActivities() from outside of an Activity " |
| 696 | + " context requires the FLAG_ACTIVITY_NEW_TASK flag on first Intent." |
| 697 | + " Is this really what you want?"); |
| 698 | } |
| 699 | mMainThread.getInstrumentation().execStartActivitiesAsUser( |
| 700 | getOuterContext(), mMainThread.getApplicationThread(), null, |
| 701 | (Activity)null, intents, options, userHandle.getIdentifier()); |
| 702 | } |
| 703 | |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 704 | @Override |
| 705 | public void startActivities(Intent[] intents, Bundle options) { |
Amith Yamasani | cd75706 | 2012-10-19 18:23:52 -0700 | [diff] [blame] | 706 | warnIfCallingFromSystemProcess(); |
Dianne Hackborn | 621e17d | 2010-11-22 15:59:56 -0800 | [diff] [blame] | 707 | if ((intents[0].getFlags()&Intent.FLAG_ACTIVITY_NEW_TASK) == 0) { |
| 708 | throw new AndroidRuntimeException( |
| 709 | "Calling startActivities() from outside of an Activity " |
| 710 | + " context requires the FLAG_ACTIVITY_NEW_TASK flag on first Intent." |
| 711 | + " Is this really what you want?"); |
| 712 | } |
| 713 | mMainThread.getInstrumentation().execStartActivities( |
| 714 | getOuterContext(), mMainThread.getApplicationThread(), null, |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 715 | (Activity)null, intents, options); |
Dianne Hackborn | 621e17d | 2010-11-22 15:59:56 -0800 | [diff] [blame] | 716 | } |
| 717 | |
| 718 | @Override |
Dianne Hackborn | fa82f22 | 2009-09-17 15:14:12 -0700 | [diff] [blame] | 719 | public void startIntentSender(IntentSender intent, |
| 720 | Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags) |
| 721 | throws IntentSender.SendIntentException { |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 722 | startIntentSender(intent, fillInIntent, flagsMask, flagsValues, extraFlags, null); |
| 723 | } |
| 724 | |
| 725 | @Override |
| 726 | public void startIntentSender(IntentSender intent, Intent fillInIntent, |
| 727 | int flagsMask, int flagsValues, int extraFlags, Bundle options) |
| 728 | throws IntentSender.SendIntentException { |
Dianne Hackborn | fa82f22 | 2009-09-17 15:14:12 -0700 | [diff] [blame] | 729 | try { |
| 730 | String resolvedType = null; |
| 731 | if (fillInIntent != null) { |
Jeff Sharkey | a14acd2 | 2013-04-02 18:27:45 -0700 | [diff] [blame] | 732 | fillInIntent.migrateExtraStreamToClipData(); |
| 733 | fillInIntent.prepareToLeaveProcess(); |
Dianne Hackborn | fa82f22 | 2009-09-17 15:14:12 -0700 | [diff] [blame] | 734 | resolvedType = fillInIntent.resolveTypeIfNeeded(getContentResolver()); |
| 735 | } |
| 736 | int result = ActivityManagerNative.getDefault() |
| 737 | .startActivityIntentSender(mMainThread.getApplicationThread(), intent, |
| 738 | fillInIntent, resolvedType, null, null, |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 739 | 0, flagsMask, flagsValues, options); |
| 740 | if (result == ActivityManager.START_CANCELED) { |
Dianne Hackborn | fa82f22 | 2009-09-17 15:14:12 -0700 | [diff] [blame] | 741 | throw new IntentSender.SendIntentException(); |
| 742 | } |
| 743 | Instrumentation.checkStartActivityResult(result, null); |
| 744 | } catch (RemoteException e) { |
| 745 | } |
| 746 | } |
Christian Mehlmauer | 5f5acca | 2010-06-25 19:06:18 +0200 | [diff] [blame] | 747 | |
Dianne Hackborn | fa82f22 | 2009-09-17 15:14:12 -0700 | [diff] [blame] | 748 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 749 | public void sendBroadcast(Intent intent) { |
Amith Yamasani | cd75706 | 2012-10-19 18:23:52 -0700 | [diff] [blame] | 750 | warnIfCallingFromSystemProcess(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 751 | String resolvedType = intent.resolveTypeIfNeeded(getContentResolver()); |
| 752 | try { |
Jeff Sharkey | a14acd2 | 2013-04-02 18:27:45 -0700 | [diff] [blame] | 753 | intent.prepareToLeaveProcess(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 754 | ActivityManagerNative.getDefault().broadcastIntent( |
| 755 | mMainThread.getApplicationThread(), intent, resolvedType, null, |
Dianne Hackborn | f51f612 | 2013-02-04 18:23:34 -0800 | [diff] [blame] | 756 | Activity.RESULT_OK, null, null, null, AppOpsManager.OP_NONE, false, false, |
Jeff Sharkey | ded653b | 2012-09-27 19:09:24 -0700 | [diff] [blame] | 757 | getUserId()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 758 | } catch (RemoteException e) { |
| 759 | } |
| 760 | } |
| 761 | |
Amith Yamasani | 67cf7d3 | 2012-02-16 14:31:23 -0800 | [diff] [blame] | 762 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 763 | public void sendBroadcast(Intent intent, String receiverPermission) { |
Amith Yamasani | cd75706 | 2012-10-19 18:23:52 -0700 | [diff] [blame] | 764 | warnIfCallingFromSystemProcess(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 765 | String resolvedType = intent.resolveTypeIfNeeded(getContentResolver()); |
| 766 | try { |
Jeff Sharkey | a14acd2 | 2013-04-02 18:27:45 -0700 | [diff] [blame] | 767 | intent.prepareToLeaveProcess(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 768 | ActivityManagerNative.getDefault().broadcastIntent( |
| 769 | mMainThread.getApplicationThread(), intent, resolvedType, null, |
Dianne Hackborn | f51f612 | 2013-02-04 18:23:34 -0800 | [diff] [blame] | 770 | Activity.RESULT_OK, null, null, receiverPermission, AppOpsManager.OP_NONE, |
| 771 | false, false, getUserId()); |
| 772 | } catch (RemoteException e) { |
| 773 | } |
| 774 | } |
| 775 | |
| 776 | @Override |
| 777 | public void sendBroadcast(Intent intent, String receiverPermission, int appOp) { |
| 778 | warnIfCallingFromSystemProcess(); |
| 779 | String resolvedType = intent.resolveTypeIfNeeded(getContentResolver()); |
| 780 | try { |
Jeff Sharkey | a14acd2 | 2013-04-02 18:27:45 -0700 | [diff] [blame] | 781 | intent.prepareToLeaveProcess(); |
Dianne Hackborn | f51f612 | 2013-02-04 18:23:34 -0800 | [diff] [blame] | 782 | ActivityManagerNative.getDefault().broadcastIntent( |
| 783 | mMainThread.getApplicationThread(), intent, resolvedType, null, |
| 784 | Activity.RESULT_OK, null, null, receiverPermission, appOp, false, false, |
Jeff Sharkey | ded653b | 2012-09-27 19:09:24 -0700 | [diff] [blame] | 785 | getUserId()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 786 | } catch (RemoteException e) { |
| 787 | } |
| 788 | } |
| 789 | |
| 790 | @Override |
| 791 | public void sendOrderedBroadcast(Intent intent, |
| 792 | String receiverPermission) { |
Amith Yamasani | cd75706 | 2012-10-19 18:23:52 -0700 | [diff] [blame] | 793 | warnIfCallingFromSystemProcess(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 794 | String resolvedType = intent.resolveTypeIfNeeded(getContentResolver()); |
| 795 | try { |
Jeff Sharkey | a14acd2 | 2013-04-02 18:27:45 -0700 | [diff] [blame] | 796 | intent.prepareToLeaveProcess(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 797 | ActivityManagerNative.getDefault().broadcastIntent( |
| 798 | mMainThread.getApplicationThread(), intent, resolvedType, null, |
Dianne Hackborn | f51f612 | 2013-02-04 18:23:34 -0800 | [diff] [blame] | 799 | Activity.RESULT_OK, null, null, receiverPermission, AppOpsManager.OP_NONE, true, false, |
Jeff Sharkey | ded653b | 2012-09-27 19:09:24 -0700 | [diff] [blame] | 800 | getUserId()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 801 | } catch (RemoteException e) { |
| 802 | } |
| 803 | } |
| 804 | |
| 805 | @Override |
| 806 | public void sendOrderedBroadcast(Intent intent, |
| 807 | String receiverPermission, BroadcastReceiver resultReceiver, |
| 808 | Handler scheduler, int initialCode, String initialData, |
| 809 | Bundle initialExtras) { |
Dianne Hackborn | f51f612 | 2013-02-04 18:23:34 -0800 | [diff] [blame] | 810 | sendOrderedBroadcast(intent, receiverPermission, AppOpsManager.OP_NONE, |
| 811 | resultReceiver, scheduler, initialCode, initialData, initialExtras); |
| 812 | } |
| 813 | |
| 814 | @Override |
| 815 | public void sendOrderedBroadcast(Intent intent, |
| 816 | String receiverPermission, int appOp, BroadcastReceiver resultReceiver, |
| 817 | Handler scheduler, int initialCode, String initialData, |
| 818 | Bundle initialExtras) { |
Amith Yamasani | cd75706 | 2012-10-19 18:23:52 -0700 | [diff] [blame] | 819 | warnIfCallingFromSystemProcess(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 820 | IIntentReceiver rd = null; |
| 821 | if (resultReceiver != null) { |
| 822 | if (mPackageInfo != null) { |
| 823 | if (scheduler == null) { |
| 824 | scheduler = mMainThread.getHandler(); |
| 825 | } |
| 826 | rd = mPackageInfo.getReceiverDispatcher( |
| 827 | resultReceiver, getOuterContext(), scheduler, |
| 828 | mMainThread.getInstrumentation(), false); |
| 829 | } else { |
| 830 | if (scheduler == null) { |
| 831 | scheduler = mMainThread.getHandler(); |
| 832 | } |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 833 | rd = new LoadedApk.ReceiverDispatcher( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 834 | resultReceiver, getOuterContext(), scheduler, null, false).getIIntentReceiver(); |
| 835 | } |
| 836 | } |
| 837 | String resolvedType = intent.resolveTypeIfNeeded(getContentResolver()); |
| 838 | try { |
Jeff Sharkey | a14acd2 | 2013-04-02 18:27:45 -0700 | [diff] [blame] | 839 | intent.prepareToLeaveProcess(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 840 | ActivityManagerNative.getDefault().broadcastIntent( |
| 841 | mMainThread.getApplicationThread(), intent, resolvedType, rd, |
Dianne Hackborn | f51f612 | 2013-02-04 18:23:34 -0800 | [diff] [blame] | 842 | initialCode, initialData, initialExtras, receiverPermission, appOp, |
| 843 | true, false, getUserId()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 844 | } catch (RemoteException e) { |
| 845 | } |
| 846 | } |
| 847 | |
| 848 | @Override |
Dianne Hackborn | 79af1dd | 2012-08-16 16:42:52 -0700 | [diff] [blame] | 849 | public void sendBroadcastAsUser(Intent intent, UserHandle user) { |
Dianne Hackborn | 7d19e02 | 2012-08-07 19:12:33 -0700 | [diff] [blame] | 850 | String resolvedType = intent.resolveTypeIfNeeded(getContentResolver()); |
| 851 | try { |
Jeff Sharkey | a14acd2 | 2013-04-02 18:27:45 -0700 | [diff] [blame] | 852 | intent.prepareToLeaveProcess(); |
Dianne Hackborn | 7d19e02 | 2012-08-07 19:12:33 -0700 | [diff] [blame] | 853 | ActivityManagerNative.getDefault().broadcastIntent(mMainThread.getApplicationThread(), |
Dianne Hackborn | f51f612 | 2013-02-04 18:23:34 -0800 | [diff] [blame] | 854 | intent, resolvedType, null, Activity.RESULT_OK, null, null, null, |
| 855 | AppOpsManager.OP_NONE, false, false, user.getIdentifier()); |
Dianne Hackborn | 7d19e02 | 2012-08-07 19:12:33 -0700 | [diff] [blame] | 856 | } catch (RemoteException e) { |
| 857 | } |
| 858 | } |
| 859 | |
| 860 | @Override |
Dianne Hackborn | 5ac72a2 | 2012-08-29 18:32:08 -0700 | [diff] [blame] | 861 | public void sendBroadcastAsUser(Intent intent, UserHandle user, |
| 862 | String receiverPermission) { |
| 863 | String resolvedType = intent.resolveTypeIfNeeded(getContentResolver()); |
| 864 | try { |
Jeff Sharkey | a14acd2 | 2013-04-02 18:27:45 -0700 | [diff] [blame] | 865 | intent.prepareToLeaveProcess(); |
Dianne Hackborn | 5ac72a2 | 2012-08-29 18:32:08 -0700 | [diff] [blame] | 866 | ActivityManagerNative.getDefault().broadcastIntent( |
| 867 | mMainThread.getApplicationThread(), intent, resolvedType, null, |
Dianne Hackborn | f51f612 | 2013-02-04 18:23:34 -0800 | [diff] [blame] | 868 | Activity.RESULT_OK, null, null, receiverPermission, AppOpsManager.OP_NONE, false, false, |
Dianne Hackborn | 5ac72a2 | 2012-08-29 18:32:08 -0700 | [diff] [blame] | 869 | user.getIdentifier()); |
| 870 | } catch (RemoteException e) { |
| 871 | } |
| 872 | } |
| 873 | |
| 874 | @Override |
Dianne Hackborn | 79af1dd | 2012-08-16 16:42:52 -0700 | [diff] [blame] | 875 | public void sendOrderedBroadcastAsUser(Intent intent, UserHandle user, |
Dianne Hackborn | 5ac72a2 | 2012-08-29 18:32:08 -0700 | [diff] [blame] | 876 | String receiverPermission, BroadcastReceiver resultReceiver, Handler scheduler, |
Dianne Hackborn | 7d19e02 | 2012-08-07 19:12:33 -0700 | [diff] [blame] | 877 | int initialCode, String initialData, Bundle initialExtras) { |
Amith Yamasani | 3cf7572 | 2014-05-16 12:37:29 -0700 | [diff] [blame] | 878 | sendOrderedBroadcastAsUser(intent, user, receiverPermission, AppOpsManager.OP_NONE, |
| 879 | resultReceiver, scheduler, initialCode, initialData, initialExtras); |
| 880 | } |
| 881 | |
| 882 | @Override |
| 883 | public void sendOrderedBroadcastAsUser(Intent intent, UserHandle user, |
| 884 | String receiverPermission, int appOp, BroadcastReceiver resultReceiver, |
| 885 | Handler scheduler, |
| 886 | int initialCode, String initialData, Bundle initialExtras) { |
Dianne Hackborn | 7d19e02 | 2012-08-07 19:12:33 -0700 | [diff] [blame] | 887 | IIntentReceiver rd = null; |
| 888 | if (resultReceiver != null) { |
| 889 | if (mPackageInfo != null) { |
| 890 | if (scheduler == null) { |
| 891 | scheduler = mMainThread.getHandler(); |
| 892 | } |
| 893 | rd = mPackageInfo.getReceiverDispatcher( |
| 894 | resultReceiver, getOuterContext(), scheduler, |
| 895 | mMainThread.getInstrumentation(), false); |
| 896 | } else { |
| 897 | if (scheduler == null) { |
| 898 | scheduler = mMainThread.getHandler(); |
| 899 | } |
| 900 | rd = new LoadedApk.ReceiverDispatcher( |
| 901 | resultReceiver, getOuterContext(), scheduler, null, false).getIIntentReceiver(); |
| 902 | } |
| 903 | } |
| 904 | String resolvedType = intent.resolveTypeIfNeeded(getContentResolver()); |
| 905 | try { |
Jeff Sharkey | a14acd2 | 2013-04-02 18:27:45 -0700 | [diff] [blame] | 906 | intent.prepareToLeaveProcess(); |
Dianne Hackborn | 7d19e02 | 2012-08-07 19:12:33 -0700 | [diff] [blame] | 907 | ActivityManagerNative.getDefault().broadcastIntent( |
| 908 | mMainThread.getApplicationThread(), intent, resolvedType, rd, |
Dianne Hackborn | 5ac72a2 | 2012-08-29 18:32:08 -0700 | [diff] [blame] | 909 | initialCode, initialData, initialExtras, receiverPermission, |
Amith Yamasani | 0261b9b | 2014-05-20 16:57:26 -0700 | [diff] [blame] | 910 | appOp, true, false, user.getIdentifier()); |
Dianne Hackborn | 7d19e02 | 2012-08-07 19:12:33 -0700 | [diff] [blame] | 911 | } catch (RemoteException e) { |
| 912 | } |
| 913 | } |
| 914 | |
| 915 | @Override |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 916 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 917 | public void sendStickyBroadcast(Intent intent) { |
Amith Yamasani | cd75706 | 2012-10-19 18:23:52 -0700 | [diff] [blame] | 918 | warnIfCallingFromSystemProcess(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 919 | String resolvedType = intent.resolveTypeIfNeeded(getContentResolver()); |
| 920 | try { |
Jeff Sharkey | a14acd2 | 2013-04-02 18:27:45 -0700 | [diff] [blame] | 921 | intent.prepareToLeaveProcess(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 922 | ActivityManagerNative.getDefault().broadcastIntent( |
| 923 | mMainThread.getApplicationThread(), intent, resolvedType, null, |
Dianne Hackborn | f51f612 | 2013-02-04 18:23:34 -0800 | [diff] [blame] | 924 | Activity.RESULT_OK, null, null, null, AppOpsManager.OP_NONE, false, true, |
Jeff Sharkey | ded653b | 2012-09-27 19:09:24 -0700 | [diff] [blame] | 925 | getUserId()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 926 | } catch (RemoteException e) { |
| 927 | } |
| 928 | } |
| 929 | |
| 930 | @Override |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 931 | @Deprecated |
Dianne Hackborn | efa199f | 2009-09-19 12:03:15 -0700 | [diff] [blame] | 932 | public void sendStickyOrderedBroadcast(Intent intent, |
| 933 | BroadcastReceiver resultReceiver, |
| 934 | Handler scheduler, int initialCode, String initialData, |
| 935 | Bundle initialExtras) { |
Amith Yamasani | cd75706 | 2012-10-19 18:23:52 -0700 | [diff] [blame] | 936 | warnIfCallingFromSystemProcess(); |
Dianne Hackborn | efa199f | 2009-09-19 12:03:15 -0700 | [diff] [blame] | 937 | IIntentReceiver rd = null; |
| 938 | if (resultReceiver != null) { |
| 939 | if (mPackageInfo != null) { |
| 940 | if (scheduler == null) { |
| 941 | scheduler = mMainThread.getHandler(); |
| 942 | } |
| 943 | rd = mPackageInfo.getReceiverDispatcher( |
| 944 | resultReceiver, getOuterContext(), scheduler, |
| 945 | mMainThread.getInstrumentation(), false); |
| 946 | } else { |
| 947 | if (scheduler == null) { |
| 948 | scheduler = mMainThread.getHandler(); |
| 949 | } |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 950 | rd = new LoadedApk.ReceiverDispatcher( |
Dianne Hackborn | efa199f | 2009-09-19 12:03:15 -0700 | [diff] [blame] | 951 | resultReceiver, getOuterContext(), scheduler, null, false).getIIntentReceiver(); |
| 952 | } |
| 953 | } |
| 954 | String resolvedType = intent.resolveTypeIfNeeded(getContentResolver()); |
| 955 | try { |
Jeff Sharkey | a14acd2 | 2013-04-02 18:27:45 -0700 | [diff] [blame] | 956 | intent.prepareToLeaveProcess(); |
Dianne Hackborn | efa199f | 2009-09-19 12:03:15 -0700 | [diff] [blame] | 957 | ActivityManagerNative.getDefault().broadcastIntent( |
| 958 | mMainThread.getApplicationThread(), intent, resolvedType, rd, |
| 959 | initialCode, initialData, initialExtras, null, |
Dianne Hackborn | f51f612 | 2013-02-04 18:23:34 -0800 | [diff] [blame] | 960 | AppOpsManager.OP_NONE, true, true, getUserId()); |
Dianne Hackborn | efa199f | 2009-09-19 12:03:15 -0700 | [diff] [blame] | 961 | } catch (RemoteException e) { |
| 962 | } |
| 963 | } |
| 964 | |
| 965 | @Override |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 966 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 967 | public void removeStickyBroadcast(Intent intent) { |
| 968 | String resolvedType = intent.resolveTypeIfNeeded(getContentResolver()); |
| 969 | if (resolvedType != null) { |
| 970 | intent = new Intent(intent); |
| 971 | intent.setDataAndType(intent.getData(), resolvedType); |
| 972 | } |
| 973 | try { |
Jeff Sharkey | a14acd2 | 2013-04-02 18:27:45 -0700 | [diff] [blame] | 974 | intent.prepareToLeaveProcess(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 975 | ActivityManagerNative.getDefault().unbroadcastIntent( |
Jeff Sharkey | ded653b | 2012-09-27 19:09:24 -0700 | [diff] [blame] | 976 | mMainThread.getApplicationThread(), intent, getUserId()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 977 | } catch (RemoteException e) { |
| 978 | } |
| 979 | } |
| 980 | |
| 981 | @Override |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 982 | @Deprecated |
Dianne Hackborn | 5ac72a2 | 2012-08-29 18:32:08 -0700 | [diff] [blame] | 983 | public void sendStickyBroadcastAsUser(Intent intent, UserHandle user) { |
| 984 | String resolvedType = intent.resolveTypeIfNeeded(getContentResolver()); |
| 985 | try { |
Jeff Sharkey | a14acd2 | 2013-04-02 18:27:45 -0700 | [diff] [blame] | 986 | intent.prepareToLeaveProcess(); |
Dianne Hackborn | 5ac72a2 | 2012-08-29 18:32:08 -0700 | [diff] [blame] | 987 | ActivityManagerNative.getDefault().broadcastIntent( |
| 988 | mMainThread.getApplicationThread(), intent, resolvedType, null, |
Dianne Hackborn | f51f612 | 2013-02-04 18:23:34 -0800 | [diff] [blame] | 989 | Activity.RESULT_OK, null, null, null, AppOpsManager.OP_NONE, false, true, user.getIdentifier()); |
Dianne Hackborn | 5ac72a2 | 2012-08-29 18:32:08 -0700 | [diff] [blame] | 990 | } catch (RemoteException e) { |
| 991 | } |
| 992 | } |
| 993 | |
| 994 | @Override |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 995 | @Deprecated |
Dianne Hackborn | 5ac72a2 | 2012-08-29 18:32:08 -0700 | [diff] [blame] | 996 | public void sendStickyOrderedBroadcastAsUser(Intent intent, |
| 997 | UserHandle user, BroadcastReceiver resultReceiver, |
| 998 | Handler scheduler, int initialCode, String initialData, |
| 999 | Bundle initialExtras) { |
| 1000 | IIntentReceiver rd = null; |
| 1001 | if (resultReceiver != null) { |
| 1002 | if (mPackageInfo != null) { |
| 1003 | if (scheduler == null) { |
| 1004 | scheduler = mMainThread.getHandler(); |
| 1005 | } |
| 1006 | rd = mPackageInfo.getReceiverDispatcher( |
| 1007 | resultReceiver, getOuterContext(), scheduler, |
| 1008 | mMainThread.getInstrumentation(), false); |
| 1009 | } else { |
| 1010 | if (scheduler == null) { |
| 1011 | scheduler = mMainThread.getHandler(); |
| 1012 | } |
| 1013 | rd = new LoadedApk.ReceiverDispatcher( |
| 1014 | resultReceiver, getOuterContext(), scheduler, null, false).getIIntentReceiver(); |
| 1015 | } |
| 1016 | } |
| 1017 | String resolvedType = intent.resolveTypeIfNeeded(getContentResolver()); |
| 1018 | try { |
Jeff Sharkey | a14acd2 | 2013-04-02 18:27:45 -0700 | [diff] [blame] | 1019 | intent.prepareToLeaveProcess(); |
Dianne Hackborn | 5ac72a2 | 2012-08-29 18:32:08 -0700 | [diff] [blame] | 1020 | ActivityManagerNative.getDefault().broadcastIntent( |
| 1021 | mMainThread.getApplicationThread(), intent, resolvedType, rd, |
| 1022 | initialCode, initialData, initialExtras, null, |
Dianne Hackborn | f51f612 | 2013-02-04 18:23:34 -0800 | [diff] [blame] | 1023 | AppOpsManager.OP_NONE, true, true, user.getIdentifier()); |
Dianne Hackborn | 5ac72a2 | 2012-08-29 18:32:08 -0700 | [diff] [blame] | 1024 | } catch (RemoteException e) { |
| 1025 | } |
| 1026 | } |
| 1027 | |
| 1028 | @Override |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 1029 | @Deprecated |
Dianne Hackborn | 5ac72a2 | 2012-08-29 18:32:08 -0700 | [diff] [blame] | 1030 | public void removeStickyBroadcastAsUser(Intent intent, UserHandle user) { |
| 1031 | String resolvedType = intent.resolveTypeIfNeeded(getContentResolver()); |
| 1032 | if (resolvedType != null) { |
| 1033 | intent = new Intent(intent); |
| 1034 | intent.setDataAndType(intent.getData(), resolvedType); |
| 1035 | } |
| 1036 | try { |
Jeff Sharkey | a14acd2 | 2013-04-02 18:27:45 -0700 | [diff] [blame] | 1037 | intent.prepareToLeaveProcess(); |
Dianne Hackborn | 5ac72a2 | 2012-08-29 18:32:08 -0700 | [diff] [blame] | 1038 | ActivityManagerNative.getDefault().unbroadcastIntent( |
| 1039 | mMainThread.getApplicationThread(), intent, user.getIdentifier()); |
| 1040 | } catch (RemoteException e) { |
| 1041 | } |
| 1042 | } |
| 1043 | |
| 1044 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1045 | public Intent registerReceiver(BroadcastReceiver receiver, IntentFilter filter) { |
| 1046 | return registerReceiver(receiver, filter, null, null); |
| 1047 | } |
| 1048 | |
| 1049 | @Override |
| 1050 | public Intent registerReceiver(BroadcastReceiver receiver, IntentFilter filter, |
| 1051 | String broadcastPermission, Handler scheduler) { |
Jeff Sharkey | ded653b | 2012-09-27 19:09:24 -0700 | [diff] [blame] | 1052 | return registerReceiverInternal(receiver, getUserId(), |
Dianne Hackborn | 20e8098 | 2012-08-31 19:00:44 -0700 | [diff] [blame] | 1053 | filter, broadcastPermission, scheduler, getOuterContext()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1054 | } |
| 1055 | |
Dianne Hackborn | 20e8098 | 2012-08-31 19:00:44 -0700 | [diff] [blame] | 1056 | @Override |
| 1057 | public Intent registerReceiverAsUser(BroadcastReceiver receiver, UserHandle user, |
| 1058 | IntentFilter filter, String broadcastPermission, Handler scheduler) { |
| 1059 | return registerReceiverInternal(receiver, user.getIdentifier(), |
| 1060 | filter, broadcastPermission, scheduler, getOuterContext()); |
| 1061 | } |
| 1062 | |
| 1063 | private Intent registerReceiverInternal(BroadcastReceiver receiver, int userId, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1064 | IntentFilter filter, String broadcastPermission, |
| 1065 | Handler scheduler, Context context) { |
| 1066 | IIntentReceiver rd = null; |
| 1067 | if (receiver != null) { |
| 1068 | if (mPackageInfo != null && context != null) { |
| 1069 | if (scheduler == null) { |
| 1070 | scheduler = mMainThread.getHandler(); |
| 1071 | } |
| 1072 | rd = mPackageInfo.getReceiverDispatcher( |
| 1073 | receiver, context, scheduler, |
| 1074 | mMainThread.getInstrumentation(), true); |
| 1075 | } else { |
| 1076 | if (scheduler == null) { |
| 1077 | scheduler = mMainThread.getHandler(); |
| 1078 | } |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 1079 | rd = new LoadedApk.ReceiverDispatcher( |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 1080 | receiver, context, scheduler, null, true).getIIntentReceiver(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1081 | } |
| 1082 | } |
| 1083 | try { |
| 1084 | return ActivityManagerNative.getDefault().registerReceiver( |
Dianne Hackborn | 6c418d5 | 2011-06-29 14:05:33 -0700 | [diff] [blame] | 1085 | mMainThread.getApplicationThread(), mBasePackageName, |
Dianne Hackborn | 20e8098 | 2012-08-31 19:00:44 -0700 | [diff] [blame] | 1086 | rd, filter, broadcastPermission, userId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1087 | } catch (RemoteException e) { |
| 1088 | return null; |
| 1089 | } |
| 1090 | } |
| 1091 | |
| 1092 | @Override |
| 1093 | public void unregisterReceiver(BroadcastReceiver receiver) { |
| 1094 | if (mPackageInfo != null) { |
| 1095 | IIntentReceiver rd = mPackageInfo.forgetReceiverDispatcher( |
| 1096 | getOuterContext(), receiver); |
| 1097 | try { |
| 1098 | ActivityManagerNative.getDefault().unregisterReceiver(rd); |
| 1099 | } catch (RemoteException e) { |
| 1100 | } |
| 1101 | } else { |
| 1102 | throw new RuntimeException("Not supported in system context"); |
| 1103 | } |
| 1104 | } |
| 1105 | |
Dianne Hackborn | fd6c7b1 | 2013-10-03 10:42:26 -0700 | [diff] [blame] | 1106 | private void validateServiceIntent(Intent service) { |
| 1107 | if (service.getComponent() == null && service.getPackage() == null) { |
Dianne Hackborn | 955d8d6 | 2014-10-07 20:17:19 -0700 | [diff] [blame] | 1108 | if (getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.LOLLIPOP) { |
Dianne Hackborn | 10ad982 | 2014-03-17 11:28:36 -0700 | [diff] [blame] | 1109 | IllegalArgumentException ex = new IllegalArgumentException( |
| 1110 | "Service Intent must be explicit: " + service); |
| 1111 | throw ex; |
| 1112 | } else { |
Dianne Hackborn | fd6c7b1 | 2013-10-03 10:42:26 -0700 | [diff] [blame] | 1113 | Log.w(TAG, "Implicit intents with startService are not safe: " + service |
| 1114 | + " " + Debug.getCallers(2, 3)); |
Dianne Hackborn | fd6c7b1 | 2013-10-03 10:42:26 -0700 | [diff] [blame] | 1115 | } |
| 1116 | } |
| 1117 | } |
| 1118 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1119 | @Override |
| 1120 | public ComponentName startService(Intent service) { |
Amith Yamasani | cd75706 | 2012-10-19 18:23:52 -0700 | [diff] [blame] | 1121 | warnIfCallingFromSystemProcess(); |
Dianne Hackborn | fd6c7b1 | 2013-10-03 10:42:26 -0700 | [diff] [blame] | 1122 | return startServiceCommon(service, mUser); |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 1123 | } |
| 1124 | |
| 1125 | @Override |
| 1126 | public boolean stopService(Intent service) { |
Amith Yamasani | cd75706 | 2012-10-19 18:23:52 -0700 | [diff] [blame] | 1127 | warnIfCallingFromSystemProcess(); |
Dianne Hackborn | fd6c7b1 | 2013-10-03 10:42:26 -0700 | [diff] [blame] | 1128 | return stopServiceCommon(service, mUser); |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 1129 | } |
| 1130 | |
| 1131 | @Override |
| 1132 | public ComponentName startServiceAsUser(Intent service, UserHandle user) { |
Dianne Hackborn | fd6c7b1 | 2013-10-03 10:42:26 -0700 | [diff] [blame] | 1133 | return startServiceCommon(service, user); |
| 1134 | } |
| 1135 | |
| 1136 | private ComponentName startServiceCommon(Intent service, UserHandle user) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1137 | try { |
Dianne Hackborn | fd6c7b1 | 2013-10-03 10:42:26 -0700 | [diff] [blame] | 1138 | validateServiceIntent(service); |
Jeff Sharkey | a14acd2 | 2013-04-02 18:27:45 -0700 | [diff] [blame] | 1139 | service.prepareToLeaveProcess(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1140 | ComponentName cn = ActivityManagerNative.getDefault().startService( |
| 1141 | mMainThread.getApplicationThread(), service, |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 1142 | service.resolveTypeIfNeeded(getContentResolver()), user.getIdentifier()); |
Dianne Hackborn | c0bd747 | 2012-10-09 14:00:30 -0700 | [diff] [blame] | 1143 | if (cn != null) { |
| 1144 | if (cn.getPackageName().equals("!")) { |
| 1145 | throw new SecurityException( |
| 1146 | "Not allowed to start service " + service |
| 1147 | + " without permission " + cn.getClassName()); |
| 1148 | } else if (cn.getPackageName().equals("!!")) { |
| 1149 | throw new SecurityException( |
| 1150 | "Unable to start service " + service |
| 1151 | + ": " + cn.getClassName()); |
| 1152 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1153 | } |
| 1154 | return cn; |
| 1155 | } catch (RemoteException e) { |
| 1156 | return null; |
| 1157 | } |
| 1158 | } |
| 1159 | |
| 1160 | @Override |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 1161 | public boolean stopServiceAsUser(Intent service, UserHandle user) { |
Dianne Hackborn | fd6c7b1 | 2013-10-03 10:42:26 -0700 | [diff] [blame] | 1162 | return stopServiceCommon(service, user); |
| 1163 | } |
| 1164 | |
| 1165 | private boolean stopServiceCommon(Intent service, UserHandle user) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1166 | try { |
Dianne Hackborn | fd6c7b1 | 2013-10-03 10:42:26 -0700 | [diff] [blame] | 1167 | validateServiceIntent(service); |
Jeff Sharkey | a14acd2 | 2013-04-02 18:27:45 -0700 | [diff] [blame] | 1168 | service.prepareToLeaveProcess(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1169 | int res = ActivityManagerNative.getDefault().stopService( |
| 1170 | mMainThread.getApplicationThread(), service, |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 1171 | service.resolveTypeIfNeeded(getContentResolver()), user.getIdentifier()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1172 | if (res < 0) { |
| 1173 | throw new SecurityException( |
| 1174 | "Not allowed to stop service " + service); |
| 1175 | } |
| 1176 | return res != 0; |
| 1177 | } catch (RemoteException e) { |
| 1178 | return false; |
| 1179 | } |
| 1180 | } |
| 1181 | |
| 1182 | @Override |
| 1183 | public boolean bindService(Intent service, ServiceConnection conn, |
| 1184 | int flags) { |
Amith Yamasani | cd75706 | 2012-10-19 18:23:52 -0700 | [diff] [blame] | 1185 | warnIfCallingFromSystemProcess(); |
Dianne Hackborn | fd6c7b1 | 2013-10-03 10:42:26 -0700 | [diff] [blame] | 1186 | return bindServiceCommon(service, conn, flags, Process.myUserHandle()); |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 1187 | } |
| 1188 | |
| 1189 | /** @hide */ |
| 1190 | @Override |
Amith Yamasani | 27b89e6 | 2013-01-16 12:30:11 -0800 | [diff] [blame] | 1191 | public boolean bindServiceAsUser(Intent service, ServiceConnection conn, int flags, |
| 1192 | UserHandle user) { |
Dianne Hackborn | fd6c7b1 | 2013-10-03 10:42:26 -0700 | [diff] [blame] | 1193 | return bindServiceCommon(service, conn, flags, user); |
| 1194 | } |
| 1195 | |
| 1196 | private boolean bindServiceCommon(Intent service, ServiceConnection conn, int flags, |
| 1197 | UserHandle user) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1198 | IServiceConnection sd; |
Christopher Tate | 79b3317 | 2012-06-18 14:54:21 -0700 | [diff] [blame] | 1199 | if (conn == null) { |
| 1200 | throw new IllegalArgumentException("connection is null"); |
| 1201 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1202 | if (mPackageInfo != null) { |
| 1203 | sd = mPackageInfo.getServiceDispatcher(conn, getOuterContext(), |
| 1204 | mMainThread.getHandler(), flags); |
| 1205 | } else { |
| 1206 | throw new RuntimeException("Not supported in system context"); |
| 1207 | } |
Dianne Hackborn | fd6c7b1 | 2013-10-03 10:42:26 -0700 | [diff] [blame] | 1208 | validateServiceIntent(service); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1209 | try { |
Dianne Hackborn | c68c913 | 2011-07-29 01:25:18 -0700 | [diff] [blame] | 1210 | IBinder token = getActivityToken(); |
| 1211 | if (token == null && (flags&BIND_AUTO_CREATE) == 0 && mPackageInfo != null |
| 1212 | && mPackageInfo.getApplicationInfo().targetSdkVersion |
| 1213 | < android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH) { |
| 1214 | flags |= BIND_WAIVE_PRIORITY; |
| 1215 | } |
Jeff Sharkey | a14acd2 | 2013-04-02 18:27:45 -0700 | [diff] [blame] | 1216 | service.prepareToLeaveProcess(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1217 | int res = ActivityManagerNative.getDefault().bindService( |
| 1218 | mMainThread.getApplicationThread(), getActivityToken(), |
| 1219 | service, service.resolveTypeIfNeeded(getContentResolver()), |
Amith Yamasani | 27b89e6 | 2013-01-16 12:30:11 -0800 | [diff] [blame] | 1220 | sd, flags, user.getIdentifier()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1221 | if (res < 0) { |
| 1222 | throw new SecurityException( |
| 1223 | "Not allowed to bind to service " + service); |
| 1224 | } |
| 1225 | return res != 0; |
| 1226 | } catch (RemoteException e) { |
| 1227 | return false; |
| 1228 | } |
| 1229 | } |
| 1230 | |
| 1231 | @Override |
| 1232 | public void unbindService(ServiceConnection conn) { |
Christopher Tate | 79b3317 | 2012-06-18 14:54:21 -0700 | [diff] [blame] | 1233 | if (conn == null) { |
| 1234 | throw new IllegalArgumentException("connection is null"); |
| 1235 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1236 | if (mPackageInfo != null) { |
| 1237 | IServiceConnection sd = mPackageInfo.forgetServiceDispatcher( |
| 1238 | getOuterContext(), conn); |
| 1239 | try { |
| 1240 | ActivityManagerNative.getDefault().unbindService(sd); |
| 1241 | } catch (RemoteException e) { |
| 1242 | } |
| 1243 | } else { |
| 1244 | throw new RuntimeException("Not supported in system context"); |
| 1245 | } |
| 1246 | } |
| 1247 | |
| 1248 | @Override |
| 1249 | public boolean startInstrumentation(ComponentName className, |
| 1250 | String profileFile, Bundle arguments) { |
| 1251 | try { |
Dianne Hackborn | 9ecebbf | 2011-09-28 23:19:47 -0400 | [diff] [blame] | 1252 | if (arguments != null) { |
| 1253 | arguments.setAllowFds(false); |
| 1254 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1255 | return ActivityManagerNative.getDefault().startInstrumentation( |
Narayan Kamath | 8dcfefd | 2014-05-15 18:12:59 +0100 | [diff] [blame] | 1256 | className, profileFile, 0, arguments, null, null, getUserId(), |
| 1257 | null /* ABI override */); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1258 | } catch (RemoteException e) { |
| 1259 | // System has crashed, nothing we can do. |
| 1260 | } |
| 1261 | return false; |
| 1262 | } |
| 1263 | |
| 1264 | @Override |
| 1265 | public Object getSystemService(String name) { |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 1266 | return SystemServiceRegistry.getSystemService(this, name); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1267 | } |
| 1268 | |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 1269 | @Override |
| 1270 | public String getSystemServiceName(Class<?> serviceClass) { |
| 1271 | return SystemServiceRegistry.getSystemServiceName(serviceClass); |
Brad Fitzpatrick | 438d059 | 2010-06-10 12:19:19 -0700 | [diff] [blame] | 1272 | } |
| 1273 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1274 | @Override |
| 1275 | public int checkPermission(String permission, int pid, int uid) { |
| 1276 | if (permission == null) { |
| 1277 | throw new IllegalArgumentException("permission is null"); |
| 1278 | } |
| 1279 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1280 | try { |
| 1281 | return ActivityManagerNative.getDefault().checkPermission( |
| 1282 | permission, pid, uid); |
| 1283 | } catch (RemoteException e) { |
| 1284 | return PackageManager.PERMISSION_DENIED; |
| 1285 | } |
| 1286 | } |
| 1287 | |
Dianne Hackborn | ff17024 | 2014-11-19 10:59:01 -0800 | [diff] [blame] | 1288 | /** @hide */ |
| 1289 | @Override |
| 1290 | public int checkPermission(String permission, int pid, int uid, IBinder callerToken) { |
| 1291 | if (permission == null) { |
| 1292 | throw new IllegalArgumentException("permission is null"); |
| 1293 | } |
| 1294 | |
| 1295 | try { |
| 1296 | return ActivityManagerNative.getDefault().checkPermissionWithToken( |
| 1297 | permission, pid, uid, callerToken); |
| 1298 | } catch (RemoteException e) { |
| 1299 | return PackageManager.PERMISSION_DENIED; |
| 1300 | } |
| 1301 | } |
| 1302 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1303 | @Override |
| 1304 | public int checkCallingPermission(String permission) { |
| 1305 | if (permission == null) { |
| 1306 | throw new IllegalArgumentException("permission is null"); |
| 1307 | } |
| 1308 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1309 | int pid = Binder.getCallingPid(); |
| 1310 | if (pid != Process.myPid()) { |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 1311 | return checkPermission(permission, pid, Binder.getCallingUid()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1312 | } |
| 1313 | return PackageManager.PERMISSION_DENIED; |
| 1314 | } |
| 1315 | |
| 1316 | @Override |
| 1317 | public int checkCallingOrSelfPermission(String permission) { |
| 1318 | if (permission == null) { |
| 1319 | throw new IllegalArgumentException("permission is null"); |
| 1320 | } |
| 1321 | |
| 1322 | return checkPermission(permission, Binder.getCallingPid(), |
| 1323 | Binder.getCallingUid()); |
| 1324 | } |
| 1325 | |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 1326 | @Override |
| 1327 | public int checkSelfPermission(String permission) { |
| 1328 | if (permission == null) { |
| 1329 | throw new IllegalArgumentException("permission is null"); |
| 1330 | } |
| 1331 | |
| 1332 | return checkPermission(permission, Process.myPid(), Process.myUid()); |
| 1333 | } |
| 1334 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1335 | private void enforce( |
| 1336 | String permission, int resultOfCheck, |
| 1337 | boolean selfToo, int uid, String message) { |
| 1338 | if (resultOfCheck != PackageManager.PERMISSION_GRANTED) { |
| 1339 | throw new SecurityException( |
| 1340 | (message != null ? (message + ": ") : "") + |
| 1341 | (selfToo |
| 1342 | ? "Neither user " + uid + " nor current process has " |
Christopher Tate | 4dc7a68 | 2012-09-11 12:15:49 -0700 | [diff] [blame] | 1343 | : "uid " + uid + " does not have ") + |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1344 | permission + |
| 1345 | "."); |
| 1346 | } |
| 1347 | } |
| 1348 | |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 1349 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1350 | public void enforcePermission( |
| 1351 | String permission, int pid, int uid, String message) { |
| 1352 | enforce(permission, |
| 1353 | checkPermission(permission, pid, uid), |
| 1354 | false, |
| 1355 | uid, |
| 1356 | message); |
| 1357 | } |
| 1358 | |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 1359 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1360 | public void enforceCallingPermission(String permission, String message) { |
| 1361 | enforce(permission, |
| 1362 | checkCallingPermission(permission), |
| 1363 | false, |
| 1364 | Binder.getCallingUid(), |
| 1365 | message); |
| 1366 | } |
| 1367 | |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 1368 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1369 | public void enforceCallingOrSelfPermission( |
| 1370 | String permission, String message) { |
| 1371 | enforce(permission, |
| 1372 | checkCallingOrSelfPermission(permission), |
| 1373 | true, |
| 1374 | Binder.getCallingUid(), |
| 1375 | message); |
| 1376 | } |
| 1377 | |
| 1378 | @Override |
| 1379 | public void grantUriPermission(String toPackage, Uri uri, int modeFlags) { |
| 1380 | try { |
| 1381 | ActivityManagerNative.getDefault().grantUriPermission( |
Nicolas Prevot | d85fc72 | 2014-04-16 19:52:08 +0100 | [diff] [blame] | 1382 | mMainThread.getApplicationThread(), toPackage, |
| 1383 | ContentProvider.getUriWithoutUserId(uri), modeFlags, resolveUserId(uri)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1384 | } catch (RemoteException e) { |
| 1385 | } |
| 1386 | } |
| 1387 | |
| 1388 | @Override |
| 1389 | public void revokeUriPermission(Uri uri, int modeFlags) { |
| 1390 | try { |
| 1391 | ActivityManagerNative.getDefault().revokeUriPermission( |
Nicolas Prevot | d85fc72 | 2014-04-16 19:52:08 +0100 | [diff] [blame] | 1392 | mMainThread.getApplicationThread(), |
| 1393 | ContentProvider.getUriWithoutUserId(uri), modeFlags, resolveUserId(uri)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1394 | } catch (RemoteException e) { |
| 1395 | } |
| 1396 | } |
| 1397 | |
| 1398 | @Override |
| 1399 | 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] | 1400 | try { |
| 1401 | return ActivityManagerNative.getDefault().checkUriPermission( |
Nicolas Prevot | d85fc72 | 2014-04-16 19:52:08 +0100 | [diff] [blame] | 1402 | ContentProvider.getUriWithoutUserId(uri), pid, uid, modeFlags, |
Dianne Hackborn | ff17024 | 2014-11-19 10:59:01 -0800 | [diff] [blame] | 1403 | resolveUserId(uri), null); |
| 1404 | } catch (RemoteException e) { |
| 1405 | return PackageManager.PERMISSION_DENIED; |
| 1406 | } |
| 1407 | } |
| 1408 | |
| 1409 | /** @hide */ |
| 1410 | @Override |
| 1411 | public int checkUriPermission(Uri uri, int pid, int uid, int modeFlags, IBinder callerToken) { |
| 1412 | try { |
| 1413 | return ActivityManagerNative.getDefault().checkUriPermission( |
| 1414 | ContentProvider.getUriWithoutUserId(uri), pid, uid, modeFlags, |
| 1415 | resolveUserId(uri), callerToken); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1416 | } catch (RemoteException e) { |
| 1417 | return PackageManager.PERMISSION_DENIED; |
| 1418 | } |
| 1419 | } |
| 1420 | |
Nicolas Prevot | d85fc72 | 2014-04-16 19:52:08 +0100 | [diff] [blame] | 1421 | private int resolveUserId(Uri uri) { |
| 1422 | return ContentProvider.getUserIdFromUri(uri, getUserId()); |
| 1423 | } |
| 1424 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1425 | @Override |
| 1426 | public int checkCallingUriPermission(Uri uri, int modeFlags) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1427 | int pid = Binder.getCallingPid(); |
| 1428 | if (pid != Process.myPid()) { |
| 1429 | return checkUriPermission(uri, pid, |
| 1430 | Binder.getCallingUid(), modeFlags); |
| 1431 | } |
| 1432 | return PackageManager.PERMISSION_DENIED; |
| 1433 | } |
| 1434 | |
| 1435 | @Override |
| 1436 | public int checkCallingOrSelfUriPermission(Uri uri, int modeFlags) { |
| 1437 | return checkUriPermission(uri, Binder.getCallingPid(), |
| 1438 | Binder.getCallingUid(), modeFlags); |
| 1439 | } |
| 1440 | |
| 1441 | @Override |
| 1442 | public int checkUriPermission(Uri uri, String readPermission, |
| 1443 | String writePermission, int pid, int uid, int modeFlags) { |
Mitsuru Oshima | 569076c | 2009-07-02 20:06:08 -0700 | [diff] [blame] | 1444 | if (DEBUG) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1445 | Log.i("foo", "checkUriPermission: uri=" + uri + "readPermission=" |
| 1446 | + readPermission + " writePermission=" + writePermission |
| 1447 | + " pid=" + pid + " uid=" + uid + " mode" + modeFlags); |
| 1448 | } |
| 1449 | if ((modeFlags&Intent.FLAG_GRANT_READ_URI_PERMISSION) != 0) { |
| 1450 | if (readPermission == null |
| 1451 | || checkPermission(readPermission, pid, uid) |
| 1452 | == PackageManager.PERMISSION_GRANTED) { |
| 1453 | return PackageManager.PERMISSION_GRANTED; |
| 1454 | } |
| 1455 | } |
| 1456 | if ((modeFlags&Intent.FLAG_GRANT_WRITE_URI_PERMISSION) != 0) { |
| 1457 | if (writePermission == null |
| 1458 | || checkPermission(writePermission, pid, uid) |
| 1459 | == PackageManager.PERMISSION_GRANTED) { |
| 1460 | return PackageManager.PERMISSION_GRANTED; |
| 1461 | } |
| 1462 | } |
| 1463 | return uri != null ? checkUriPermission(uri, pid, uid, modeFlags) |
| 1464 | : PackageManager.PERMISSION_DENIED; |
| 1465 | } |
| 1466 | |
| 1467 | private String uriModeFlagToString(int uriModeFlags) { |
Jeff Sharkey | 846318a | 2014-04-04 12:12:41 -0700 | [diff] [blame] | 1468 | StringBuilder builder = new StringBuilder(); |
| 1469 | if ((uriModeFlags & Intent.FLAG_GRANT_READ_URI_PERMISSION) != 0) { |
| 1470 | builder.append("read and "); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1471 | } |
Jeff Sharkey | 846318a | 2014-04-04 12:12:41 -0700 | [diff] [blame] | 1472 | if ((uriModeFlags & Intent.FLAG_GRANT_WRITE_URI_PERMISSION) != 0) { |
| 1473 | builder.append("write and "); |
| 1474 | } |
| 1475 | if ((uriModeFlags & Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION) != 0) { |
| 1476 | builder.append("persistable and "); |
| 1477 | } |
| 1478 | if ((uriModeFlags & Intent.FLAG_GRANT_PREFIX_URI_PERMISSION) != 0) { |
| 1479 | builder.append("prefix and "); |
| 1480 | } |
| 1481 | |
| 1482 | if (builder.length() > 5) { |
| 1483 | builder.setLength(builder.length() - 5); |
| 1484 | return builder.toString(); |
| 1485 | } else { |
| 1486 | throw new IllegalArgumentException("Unknown permission mode flags: " + uriModeFlags); |
| 1487 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1488 | } |
| 1489 | |
| 1490 | private void enforceForUri( |
| 1491 | int modeFlags, int resultOfCheck, boolean selfToo, |
| 1492 | int uid, Uri uri, String message) { |
| 1493 | if (resultOfCheck != PackageManager.PERMISSION_GRANTED) { |
| 1494 | throw new SecurityException( |
| 1495 | (message != null ? (message + ": ") : "") + |
| 1496 | (selfToo |
| 1497 | ? "Neither user " + uid + " nor current process has " |
| 1498 | : "User " + uid + " does not have ") + |
| 1499 | uriModeFlagToString(modeFlags) + |
| 1500 | " permission on " + |
| 1501 | uri + |
| 1502 | "."); |
| 1503 | } |
| 1504 | } |
| 1505 | |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 1506 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1507 | public void enforceUriPermission( |
| 1508 | Uri uri, int pid, int uid, int modeFlags, String message) { |
| 1509 | enforceForUri( |
| 1510 | modeFlags, checkUriPermission(uri, pid, uid, modeFlags), |
| 1511 | false, uid, uri, message); |
| 1512 | } |
| 1513 | |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 1514 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1515 | public void enforceCallingUriPermission( |
| 1516 | Uri uri, int modeFlags, String message) { |
| 1517 | enforceForUri( |
| 1518 | modeFlags, checkCallingUriPermission(uri, modeFlags), |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 1519 | false, |
| 1520 | Binder.getCallingUid(), uri, message); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1521 | } |
| 1522 | |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 1523 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1524 | public void enforceCallingOrSelfUriPermission( |
| 1525 | Uri uri, int modeFlags, String message) { |
| 1526 | enforceForUri( |
| 1527 | modeFlags, |
| 1528 | checkCallingOrSelfUriPermission(uri, modeFlags), true, |
| 1529 | Binder.getCallingUid(), uri, message); |
| 1530 | } |
| 1531 | |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 1532 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1533 | public void enforceUriPermission( |
| 1534 | Uri uri, String readPermission, String writePermission, |
| 1535 | int pid, int uid, int modeFlags, String message) { |
| 1536 | enforceForUri(modeFlags, |
| 1537 | checkUriPermission( |
| 1538 | uri, readPermission, writePermission, pid, uid, |
| 1539 | modeFlags), |
| 1540 | false, |
| 1541 | uid, |
| 1542 | uri, |
| 1543 | message); |
| 1544 | } |
| 1545 | |
Tom O'Neill | 365632e | 2013-09-09 09:34:58 -0700 | [diff] [blame] | 1546 | /** |
| 1547 | * Logs a warning if the system process directly called a method such as |
| 1548 | * {@link #startService(Intent)} instead of {@link #startServiceAsUser(Intent, UserHandle)}. |
| 1549 | * The "AsUser" variants allow us to properly enforce the user's restrictions. |
| 1550 | */ |
Amith Yamasani | cd75706 | 2012-10-19 18:23:52 -0700 | [diff] [blame] | 1551 | private void warnIfCallingFromSystemProcess() { |
| 1552 | if (Process.myUid() == Process.SYSTEM_UID) { |
| 1553 | Slog.w(TAG, "Calling a method in the system process without a qualified user: " |
Dianne Hackborn | 40e9f29 | 2012-11-27 19:12:23 -0800 | [diff] [blame] | 1554 | + Debug.getCallers(5)); |
Amith Yamasani | cd75706 | 2012-10-19 18:23:52 -0700 | [diff] [blame] | 1555 | } |
| 1556 | } |
| 1557 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1558 | @Override |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 1559 | public Context createApplicationContext(ApplicationInfo application, int flags) |
| 1560 | throws NameNotFoundException { |
| 1561 | LoadedApk pi = mMainThread.getPackageInfo(application, mResources.getCompatibilityInfo(), |
| 1562 | flags | CONTEXT_REGISTER_PACKAGE); |
| 1563 | if (pi != null) { |
| 1564 | final boolean restricted = (flags & CONTEXT_RESTRICTED) == CONTEXT_RESTRICTED; |
| 1565 | ContextImpl c = new ContextImpl(this, mMainThread, pi, mActivityToken, |
| 1566 | new UserHandle(UserHandle.getUserId(application.uid)), restricted, |
Wale Ogunwale | b740537 | 2015-02-09 16:35:10 -0800 | [diff] [blame] | 1567 | mDisplay, null); |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 1568 | if (c.mResources != null) { |
| 1569 | return c; |
| 1570 | } |
| 1571 | } |
| 1572 | |
| 1573 | throw new PackageManager.NameNotFoundException( |
| 1574 | "Application package " + application.packageName + " not found"); |
| 1575 | } |
| 1576 | |
| 1577 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1578 | public Context createPackageContext(String packageName, int flags) |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 1579 | throws NameNotFoundException { |
Amith Yamasani | 64442c1 | 2012-10-07 08:17:46 -0700 | [diff] [blame] | 1580 | return createPackageContextAsUser(packageName, flags, |
| 1581 | mUser != null ? mUser : Process.myUserHandle()); |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 1582 | } |
| 1583 | |
| 1584 | @Override |
| 1585 | public Context createPackageContextAsUser(String packageName, int flags, UserHandle user) |
| 1586 | throws NameNotFoundException { |
Jeff Brown | defd4a6 | 2014-03-10 21:24:37 -0700 | [diff] [blame] | 1587 | final boolean restricted = (flags & CONTEXT_RESTRICTED) == CONTEXT_RESTRICTED; |
Kenny Guy | c2a4060 | 2014-09-08 18:51:15 +0000 | [diff] [blame] | 1588 | if (packageName.equals("system") || packageName.equals("android")) { |
Jeff Brown | defd4a6 | 2014-03-10 21:24:37 -0700 | [diff] [blame] | 1589 | return new ContextImpl(this, mMainThread, mPackageInfo, mActivityToken, |
Wale Ogunwale | b740537 | 2015-02-09 16:35:10 -0800 | [diff] [blame] | 1590 | user, restricted, mDisplay, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1591 | } |
| 1592 | |
Jeff Brown | defd4a6 | 2014-03-10 21:24:37 -0700 | [diff] [blame] | 1593 | LoadedApk pi = mMainThread.getPackageInfo(packageName, mResources.getCompatibilityInfo(), |
Dianne Hackborn | fee756f | 2014-07-16 17:31:10 -0700 | [diff] [blame] | 1594 | flags | CONTEXT_REGISTER_PACKAGE, user.getIdentifier()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1595 | if (pi != null) { |
Jeff Brown | defd4a6 | 2014-03-10 21:24:37 -0700 | [diff] [blame] | 1596 | ContextImpl c = new ContextImpl(this, mMainThread, pi, mActivityToken, |
Wale Ogunwale | b740537 | 2015-02-09 16:35:10 -0800 | [diff] [blame] | 1597 | user, restricted, mDisplay, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1598 | if (c.mResources != null) { |
| 1599 | return c; |
| 1600 | } |
| 1601 | } |
| 1602 | |
| 1603 | // Should be a better exception. |
| 1604 | throw new PackageManager.NameNotFoundException( |
Jeff Brown | defd4a6 | 2014-03-10 21:24:37 -0700 | [diff] [blame] | 1605 | "Application package " + packageName + " not found"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1606 | } |
| 1607 | |
Romain Guy | 870e09f | 2009-07-06 16:35:25 -0700 | [diff] [blame] | 1608 | @Override |
Dianne Hackborn | 756220b | 2012-08-14 16:45:30 -0700 | [diff] [blame] | 1609 | public Context createConfigurationContext(Configuration overrideConfiguration) { |
Jeff Brown | a492c3a | 2012-08-23 19:48:44 -0700 | [diff] [blame] | 1610 | if (overrideConfiguration == null) { |
| 1611 | throw new IllegalArgumentException("overrideConfiguration must not be null"); |
| 1612 | } |
| 1613 | |
Jeff Brown | defd4a6 | 2014-03-10 21:24:37 -0700 | [diff] [blame] | 1614 | return new ContextImpl(this, mMainThread, mPackageInfo, mActivityToken, |
| 1615 | mUser, mRestricted, mDisplay, overrideConfiguration); |
Dianne Hackborn | 756220b | 2012-08-14 16:45:30 -0700 | [diff] [blame] | 1616 | } |
| 1617 | |
| 1618 | @Override |
Jeff Brown | a492c3a | 2012-08-23 19:48:44 -0700 | [diff] [blame] | 1619 | public Context createDisplayContext(Display display) { |
| 1620 | if (display == null) { |
| 1621 | throw new IllegalArgumentException("display must not be null"); |
| 1622 | } |
| 1623 | |
Jeff Brown | defd4a6 | 2014-03-10 21:24:37 -0700 | [diff] [blame] | 1624 | return new ContextImpl(this, mMainThread, mPackageInfo, mActivityToken, |
Wale Ogunwale | b740537 | 2015-02-09 16:35:10 -0800 | [diff] [blame] | 1625 | mUser, mRestricted, display, null); |
Jeff Brown | a492c3a | 2012-08-23 19:48:44 -0700 | [diff] [blame] | 1626 | } |
| 1627 | |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 1628 | Display getDisplay() { |
| 1629 | if (mDisplay != null) { |
| 1630 | return mDisplay; |
| 1631 | } |
| 1632 | DisplayManager dm = getSystemService(DisplayManager.class); |
| 1633 | return dm.getDisplay(Display.DEFAULT_DISPLAY); |
| 1634 | } |
| 1635 | |
Jeff Brown | a492c3a | 2012-08-23 19:48:44 -0700 | [diff] [blame] | 1636 | private int getDisplayId() { |
| 1637 | return mDisplay != null ? mDisplay.getDisplayId() : Display.DEFAULT_DISPLAY; |
| 1638 | } |
| 1639 | |
| 1640 | @Override |
Romain Guy | 870e09f | 2009-07-06 16:35:25 -0700 | [diff] [blame] | 1641 | public boolean isRestricted() { |
| 1642 | return mRestricted; |
| 1643 | } |
| 1644 | |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 1645 | @Override |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 1646 | public DisplayAdjustments getDisplayAdjustments(int displayId) { |
| 1647 | return mDisplayAdjustments; |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 1648 | } |
| 1649 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1650 | private File getDataDirFile() { |
| 1651 | if (mPackageInfo != null) { |
| 1652 | return mPackageInfo.getDataDirFile(); |
| 1653 | } |
| 1654 | throw new RuntimeException("Not supported in system context"); |
| 1655 | } |
| 1656 | |
| 1657 | @Override |
| 1658 | public File getDir(String name, int mode) { |
| 1659 | name = "app_" + name; |
| 1660 | File file = makeFilename(getDataDirFile(), name); |
| 1661 | if (!file.exists()) { |
| 1662 | file.mkdir(); |
| 1663 | setFilePermissionsFromMode(file.getPath(), mode, |
| 1664 | FileUtils.S_IRWXU|FileUtils.S_IRWXG|FileUtils.S_IXOTH); |
| 1665 | } |
| 1666 | return file; |
| 1667 | } |
| 1668 | |
Jeff Sharkey | ded653b | 2012-09-27 19:09:24 -0700 | [diff] [blame] | 1669 | /** {@hide} */ |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 1670 | @Override |
Jeff Sharkey | ded653b | 2012-09-27 19:09:24 -0700 | [diff] [blame] | 1671 | public int getUserId() { |
| 1672 | return mUser.getIdentifier(); |
| 1673 | } |
| 1674 | |
Dianne Hackborn | 2155637 | 2010-02-04 16:34:40 -0800 | [diff] [blame] | 1675 | static ContextImpl createSystemContext(ActivityThread mainThread) { |
Jeff Brown | defd4a6 | 2014-03-10 21:24:37 -0700 | [diff] [blame] | 1676 | LoadedApk packageInfo = new LoadedApk(mainThread); |
| 1677 | ContextImpl context = new ContextImpl(null, mainThread, |
| 1678 | packageInfo, null, null, false, null, null); |
| 1679 | context.mResources.updateConfiguration(context.mResourcesManager.getConfiguration(), |
Wale Ogunwale | 7c72668 | 2015-02-06 17:34:28 -0800 | [diff] [blame] | 1680 | context.mResourcesManager.getDisplayMetricsLocked()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1681 | return context; |
| 1682 | } |
| 1683 | |
Jeff Brown | defd4a6 | 2014-03-10 21:24:37 -0700 | [diff] [blame] | 1684 | static ContextImpl createAppContext(ActivityThread mainThread, LoadedApk packageInfo) { |
| 1685 | if (packageInfo == null) throw new IllegalArgumentException("packageInfo"); |
| 1686 | return new ContextImpl(null, mainThread, |
| 1687 | packageInfo, null, null, false, null, null); |
| 1688 | } |
| 1689 | |
| 1690 | static ContextImpl createActivityContext(ActivityThread mainThread, |
Wale Ogunwale | 7c72668 | 2015-02-06 17:34:28 -0800 | [diff] [blame] | 1691 | LoadedApk packageInfo, int displayId, Configuration overrideConfiguration) { |
Jeff Brown | defd4a6 | 2014-03-10 21:24:37 -0700 | [diff] [blame] | 1692 | if (packageInfo == null) throw new IllegalArgumentException("packageInfo"); |
Wale Ogunwale | 7c72668 | 2015-02-06 17:34:28 -0800 | [diff] [blame] | 1693 | final Display display = ResourcesManager.getInstance().getAdjustedDisplay( |
| 1694 | displayId, overrideConfiguration); |
| 1695 | return new ContextImpl(null, mainThread, packageInfo, null, null, false, display, |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 1696 | overrideConfiguration); |
Jeff Brown | defd4a6 | 2014-03-10 21:24:37 -0700 | [diff] [blame] | 1697 | } |
| 1698 | |
| 1699 | private ContextImpl(ContextImpl container, ActivityThread mainThread, |
| 1700 | LoadedApk packageInfo, IBinder activityToken, UserHandle user, boolean restricted, |
| 1701 | Display display, Configuration overrideConfiguration) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1702 | mOuterContext = this; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1703 | |
Jeff Brown | defd4a6 | 2014-03-10 21:24:37 -0700 | [diff] [blame] | 1704 | mMainThread = mainThread; |
| 1705 | mActivityToken = activityToken; |
| 1706 | mRestricted = restricted; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1707 | |
Jeff Brown | defd4a6 | 2014-03-10 21:24:37 -0700 | [diff] [blame] | 1708 | if (user == null) { |
| 1709 | user = Process.myUserHandle(); |
| 1710 | } |
| 1711 | mUser = user; |
Mitsuru Oshima | ba3ba57 | 2009-07-08 18:49:26 -0700 | [diff] [blame] | 1712 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1713 | mPackageInfo = packageInfo; |
Jeff Brown | defd4a6 | 2014-03-10 21:24:37 -0700 | [diff] [blame] | 1714 | mResourcesManager = ResourcesManager.getInstance(); |
| 1715 | mDisplay = display; |
Jeff Brown | defd4a6 | 2014-03-10 21:24:37 -0700 | [diff] [blame] | 1716 | |
| 1717 | final int displayId = getDisplayId(); |
| 1718 | CompatibilityInfo compatInfo = null; |
| 1719 | if (container != null) { |
| 1720 | compatInfo = container.getDisplayAdjustments(displayId).getCompatibilityInfo(); |
| 1721 | } |
Wale Ogunwale | 9cf9954 | 2015-02-18 16:31:34 -0800 | [diff] [blame] | 1722 | if (compatInfo == null) { |
| 1723 | compatInfo = (displayId == Display.DEFAULT_DISPLAY) |
| 1724 | ? packageInfo.getCompatibilityInfo() |
| 1725 | : CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO; |
Jeff Brown | defd4a6 | 2014-03-10 21:24:37 -0700 | [diff] [blame] | 1726 | } |
| 1727 | mDisplayAdjustments.setCompatibilityInfo(compatInfo); |
Wale Ogunwale | 7c72668 | 2015-02-06 17:34:28 -0800 | [diff] [blame] | 1728 | mDisplayAdjustments.setConfiguration(overrideConfiguration); |
Jeff Brown | defd4a6 | 2014-03-10 21:24:37 -0700 | [diff] [blame] | 1729 | |
| 1730 | Resources resources = packageInfo.getResources(mainThread); |
| 1731 | if (resources != null) { |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 1732 | if (displayId != Display.DEFAULT_DISPLAY |
Jeff Brown | defd4a6 | 2014-03-10 21:24:37 -0700 | [diff] [blame] | 1733 | || overrideConfiguration != null |
| 1734 | || (compatInfo != null && compatInfo.applicationScale |
| 1735 | != resources.getCompatibilityInfo().applicationScale)) { |
Jeff Sharkey | 8a4c972 | 2014-06-16 13:48:42 -0700 | [diff] [blame] | 1736 | resources = mResourcesManager.getTopLevelResources(packageInfo.getResDir(), |
| 1737 | packageInfo.getSplitResDirs(), packageInfo.getOverlayDirs(), |
| 1738 | packageInfo.getApplicationInfo().sharedLibraryFiles, displayId, |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 1739 | overrideConfiguration, compatInfo); |
Jeff Brown | defd4a6 | 2014-03-10 21:24:37 -0700 | [diff] [blame] | 1740 | } |
| 1741 | } |
| 1742 | mResources = resources; |
| 1743 | |
| 1744 | if (container != null) { |
| 1745 | mBasePackageName = container.mBasePackageName; |
| 1746 | mOpPackageName = container.mOpPackageName; |
Dianne Hackborn | 95d7853 | 2013-09-11 09:51:14 -0700 | [diff] [blame] | 1747 | } else { |
| 1748 | mBasePackageName = packageInfo.mPackageName; |
| 1749 | ApplicationInfo ainfo = packageInfo.getApplicationInfo(); |
| 1750 | if (ainfo.uid == Process.SYSTEM_UID && ainfo.uid != Process.myUid()) { |
| 1751 | // Special case: system components allow themselves to be loaded in to other |
| 1752 | // processes. For purposes of app ops, we must then consider the context as |
| 1753 | // belonging to the package of this process, not the system itself, otherwise |
| 1754 | // the package+uid verifications in app ops will fail. |
| 1755 | mOpPackageName = ActivityThread.currentPackageName(); |
| 1756 | } else { |
| 1757 | mOpPackageName = mBasePackageName; |
| 1758 | } |
| 1759 | } |
Xin Guan | 2bcb97b | 2014-09-10 15:24:30 -0500 | [diff] [blame] | 1760 | |
| 1761 | mContentResolver = new ApplicationContentResolver(this, mainThread, user); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1762 | } |
| 1763 | |
Narayan Kamath | 29564cd | 2014-08-07 10:57:40 +0100 | [diff] [blame] | 1764 | void installSystemApplicationInfo(ApplicationInfo info, ClassLoader classLoader) { |
| 1765 | mPackageInfo.installSystemApplicationInfo(info, classLoader); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1766 | } |
| 1767 | |
| 1768 | final void scheduleFinalCleanup(String who, String what) { |
| 1769 | mMainThread.scheduleContextCleanup(this, who, what); |
| 1770 | } |
| 1771 | |
| 1772 | final void performFinalCleanup(String who, String what) { |
| 1773 | //Log.i(TAG, "Cleanup up context: " + this); |
| 1774 | mPackageInfo.removeContextRegistrations(getOuterContext(), who, what); |
| 1775 | } |
| 1776 | |
| 1777 | final Context getReceiverRestrictedContext() { |
| 1778 | if (mReceiverRestrictedContext != null) { |
| 1779 | return mReceiverRestrictedContext; |
| 1780 | } |
| 1781 | return mReceiverRestrictedContext = new ReceiverRestrictedContext(getOuterContext()); |
| 1782 | } |
| 1783 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1784 | final void setOuterContext(Context context) { |
| 1785 | mOuterContext = context; |
| 1786 | } |
Christian Mehlmauer | 5f5acca | 2010-06-25 19:06:18 +0200 | [diff] [blame] | 1787 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1788 | final Context getOuterContext() { |
| 1789 | return mOuterContext; |
| 1790 | } |
Christian Mehlmauer | 5f5acca | 2010-06-25 19:06:18 +0200 | [diff] [blame] | 1791 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1792 | final IBinder getActivityToken() { |
| 1793 | return mActivityToken; |
| 1794 | } |
| 1795 | |
Jeff Brown | 6e53931 | 2015-02-24 18:53:21 -0800 | [diff] [blame] | 1796 | @SuppressWarnings("deprecation") |
Brad Fitzpatrick | d3da440 | 2010-11-10 08:27:11 -0800 | [diff] [blame] | 1797 | static void setFilePermissionsFromMode(String name, int mode, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1798 | int extraPermissions) { |
| 1799 | int perms = FileUtils.S_IRUSR|FileUtils.S_IWUSR |
| 1800 | |FileUtils.S_IRGRP|FileUtils.S_IWGRP |
| 1801 | |extraPermissions; |
| 1802 | if ((mode&MODE_WORLD_READABLE) != 0) { |
| 1803 | perms |= FileUtils.S_IROTH; |
| 1804 | } |
| 1805 | if ((mode&MODE_WORLD_WRITEABLE) != 0) { |
| 1806 | perms |= FileUtils.S_IWOTH; |
| 1807 | } |
Mitsuru Oshima | 569076c | 2009-07-02 20:06:08 -0700 | [diff] [blame] | 1808 | if (DEBUG) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1809 | Log.i(TAG, "File " + name + ": mode=0x" + Integer.toHexString(mode) |
| 1810 | + ", perms=0x" + Integer.toHexString(perms)); |
| 1811 | } |
| 1812 | FileUtils.setPermissions(name, perms, -1, -1); |
| 1813 | } |
| 1814 | |
Oscar Montemayor | a8529f6 | 2009-11-18 10:14:20 -0800 | [diff] [blame] | 1815 | private File validateFilePath(String name, boolean createDirectory) { |
| 1816 | File dir; |
| 1817 | File f; |
| 1818 | |
| 1819 | if (name.charAt(0) == File.separatorChar) { |
| 1820 | String dirPath = name.substring(0, name.lastIndexOf(File.separatorChar)); |
| 1821 | dir = new File(dirPath); |
| 1822 | name = name.substring(name.lastIndexOf(File.separatorChar)); |
| 1823 | f = new File(dir, name); |
| 1824 | } else { |
| 1825 | dir = getDatabasesDir(); |
| 1826 | f = makeFilename(dir, name); |
| 1827 | } |
| 1828 | |
| 1829 | if (createDirectory && !dir.isDirectory() && dir.mkdir()) { |
| 1830 | FileUtils.setPermissions(dir.getPath(), |
| 1831 | FileUtils.S_IRWXU|FileUtils.S_IRWXG|FileUtils.S_IXOTH, |
| 1832 | -1, -1); |
| 1833 | } |
| 1834 | |
| 1835 | return f; |
| 1836 | } |
| 1837 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1838 | private File makeFilename(File base, String name) { |
| 1839 | if (name.indexOf(File.separatorChar) < 0) { |
| 1840 | return new File(base, name); |
| 1841 | } |
| 1842 | throw new IllegalArgumentException( |
Oscar Montemayor | a8529f6 | 2009-11-18 10:14:20 -0800 | [diff] [blame] | 1843 | "File " + name + " contains a path separator"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1844 | } |
| 1845 | |
Jeff Sharkey | 1abdb71 | 2013-08-11 16:28:14 -0700 | [diff] [blame] | 1846 | /** |
| 1847 | * Ensure that given directories exist, trying to create them if missing. If |
| 1848 | * unable to create, they are filtered by replacing with {@code null}. |
| 1849 | */ |
Jeff Sharkey | 2d8b4e8 | 2013-09-17 17:30:33 -0700 | [diff] [blame] | 1850 | private File[] ensureDirsExistOrFilter(File[] dirs) { |
Jeff Sharkey | 1abdb71 | 2013-08-11 16:28:14 -0700 | [diff] [blame] | 1851 | File[] result = new File[dirs.length]; |
| 1852 | for (int i = 0; i < dirs.length; i++) { |
| 1853 | File dir = dirs[i]; |
| 1854 | if (!dir.exists()) { |
| 1855 | if (!dir.mkdirs()) { |
Christopher Tate | cc866da | 2013-10-02 18:11:01 -0700 | [diff] [blame] | 1856 | // recheck existence in case of cross-process race |
| 1857 | if (!dir.exists()) { |
| 1858 | // Failing to mkdir() may be okay, since we might not have |
| 1859 | // enough permissions; ask vold to create on our behalf. |
| 1860 | final IMountService mount = IMountService.Stub.asInterface( |
| 1861 | ServiceManager.getService("mount")); |
| 1862 | int res = -1; |
| 1863 | try { |
| 1864 | res = mount.mkdirs(getPackageName(), dir.getAbsolutePath()); |
Jeff Sharkey | 9708669 | 2015-01-08 14:00:13 -0800 | [diff] [blame] | 1865 | } catch (Exception ignored) { |
Christopher Tate | cc866da | 2013-10-02 18:11:01 -0700 | [diff] [blame] | 1866 | } |
| 1867 | if (res != 0) { |
| 1868 | Log.w(TAG, "Failed to ensure directory: " + dir); |
| 1869 | dir = null; |
| 1870 | } |
Jeff Sharkey | 2d8b4e8 | 2013-09-17 17:30:33 -0700 | [diff] [blame] | 1871 | } |
Jeff Sharkey | 1abdb71 | 2013-08-11 16:28:14 -0700 | [diff] [blame] | 1872 | } |
| 1873 | } |
| 1874 | result[i] = dir; |
| 1875 | } |
| 1876 | return result; |
| 1877 | } |
| 1878 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1879 | // ---------------------------------------------------------------------- |
| 1880 | // ---------------------------------------------------------------------- |
| 1881 | // ---------------------------------------------------------------------- |
| 1882 | |
| 1883 | private static final class ApplicationContentResolver extends ContentResolver { |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 1884 | private final ActivityThread mMainThread; |
| 1885 | private final UserHandle mUser; |
| 1886 | |
| 1887 | public ApplicationContentResolver( |
| 1888 | Context context, ActivityThread mainThread, UserHandle user) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1889 | super(context); |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 1890 | mMainThread = Preconditions.checkNotNull(mainThread); |
| 1891 | mUser = Preconditions.checkNotNull(user); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1892 | } |
| 1893 | |
| 1894 | @Override |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 1895 | protected IContentProvider acquireProvider(Context context, String auth) { |
Nicolas Prevot | d85fc72 | 2014-04-16 19:52:08 +0100 | [diff] [blame] | 1896 | return mMainThread.acquireProvider(context, |
| 1897 | ContentProvider.getAuthorityWithoutUserId(auth), |
| 1898 | resolveUserIdFromAuthority(auth), true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1899 | } |
| 1900 | |
| 1901 | @Override |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 1902 | protected IContentProvider acquireExistingProvider(Context context, String auth) { |
Nicolas Prevot | d85fc72 | 2014-04-16 19:52:08 +0100 | [diff] [blame] | 1903 | return mMainThread.acquireExistingProvider(context, |
| 1904 | ContentProvider.getAuthorityWithoutUserId(auth), |
| 1905 | resolveUserIdFromAuthority(auth), true); |
Dianne Hackborn | cca1f0e | 2010-09-26 18:34:53 -0700 | [diff] [blame] | 1906 | } |
| 1907 | |
| 1908 | @Override |
| 1909 | public boolean releaseProvider(IContentProvider provider) { |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 1910 | return mMainThread.releaseProvider(provider, true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1911 | } |
Christian Mehlmauer | 5f5acca | 2010-06-25 19:06:18 +0200 | [diff] [blame] | 1912 | |
Dianne Hackborn | 652b6d1 | 2012-05-09 18:18:40 -0700 | [diff] [blame] | 1913 | @Override |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 1914 | protected IContentProvider acquireUnstableProvider(Context c, String auth) { |
Nicolas Prevot | d85fc72 | 2014-04-16 19:52:08 +0100 | [diff] [blame] | 1915 | return mMainThread.acquireProvider(c, |
| 1916 | ContentProvider.getAuthorityWithoutUserId(auth), |
| 1917 | resolveUserIdFromAuthority(auth), false); |
Dianne Hackborn | 652b6d1 | 2012-05-09 18:18:40 -0700 | [diff] [blame] | 1918 | } |
| 1919 | |
| 1920 | @Override |
| 1921 | public boolean releaseUnstableProvider(IContentProvider icp) { |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 1922 | return mMainThread.releaseProvider(icp, false); |
| 1923 | } |
| 1924 | |
| 1925 | @Override |
| 1926 | public void unstableProviderDied(IContentProvider icp) { |
| 1927 | mMainThread.handleUnstableProviderDied(icp.asBinder(), true); |
Dianne Hackborn | 652b6d1 | 2012-05-09 18:18:40 -0700 | [diff] [blame] | 1928 | } |
Jeff Sharkey | 7aa7601 | 2013-09-30 14:26:27 -0700 | [diff] [blame] | 1929 | |
| 1930 | @Override |
| 1931 | public void appNotRespondingViaProvider(IContentProvider icp) { |
| 1932 | mMainThread.appNotRespondingViaProvider(icp.asBinder()); |
| 1933 | } |
Nicolas Prevot | d85fc72 | 2014-04-16 19:52:08 +0100 | [diff] [blame] | 1934 | |
| 1935 | /** @hide */ |
| 1936 | protected int resolveUserIdFromAuthority(String auth) { |
| 1937 | return ContentProvider.getUserIdFromAuthority(auth, mUser.getIdentifier()); |
| 1938 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1939 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1940 | } |