Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 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 | |
| 19 | import android.content.ComponentName; |
| 20 | import android.content.ContentResolver; |
| 21 | import android.content.Intent; |
| 22 | import android.content.IntentFilter; |
| 23 | import android.content.IntentSender; |
| 24 | import android.content.pm.ActivityInfo; |
| 25 | import android.content.pm.ApplicationInfo; |
| 26 | import android.content.pm.ComponentInfo; |
Anonymous Coward | ceb1b0b | 2012-04-24 10:35:16 -0700 | [diff] [blame] | 27 | import android.content.pm.ContainerEncryptionParams; |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 28 | import android.content.pm.FeatureInfo; |
| 29 | import android.content.pm.IPackageDataObserver; |
| 30 | import android.content.pm.IPackageDeleteObserver; |
| 31 | import android.content.pm.IPackageInstallObserver; |
| 32 | import android.content.pm.IPackageManager; |
| 33 | import android.content.pm.IPackageMoveObserver; |
| 34 | import android.content.pm.IPackageStatsObserver; |
| 35 | import android.content.pm.InstrumentationInfo; |
dcashman | 9d2f441 | 2014-06-09 09:27:54 -0700 | [diff] [blame] | 36 | import android.content.pm.KeySet; |
Jeff Sharkey | 513a074 | 2014-07-08 17:10:32 -0700 | [diff] [blame] | 37 | import android.content.pm.ManifestDigest; |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 38 | import android.content.pm.PackageInfo; |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 39 | import android.content.pm.PackageInstaller; |
Nicolas Prevot | 7f7b0c7 | 2014-06-23 15:59:38 +0100 | [diff] [blame] | 40 | import android.content.pm.PackageItemInfo; |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 41 | import android.content.pm.PackageManager; |
Kenny Root | e6cd0c7 | 2011-05-19 12:48:14 -0700 | [diff] [blame] | 42 | import android.content.pm.ParceledListSlice; |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 43 | import android.content.pm.PermissionGroupInfo; |
| 44 | import android.content.pm.PermissionInfo; |
| 45 | import android.content.pm.ProviderInfo; |
| 46 | import android.content.pm.ResolveInfo; |
| 47 | import android.content.pm.ServiceInfo; |
rich cannings | 706e8ba | 2012-08-20 13:20:14 -0700 | [diff] [blame] | 48 | import android.content.pm.VerificationParams; |
Kenny Root | 0aaa0d9 | 2011-09-12 16:42:55 -0700 | [diff] [blame] | 49 | import android.content.pm.VerifierDeviceIdentity; |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 50 | import android.content.res.Resources; |
| 51 | import android.content.res.XmlResourceParser; |
Nicolas Prevot | 7f7b0c7 | 2014-06-23 15:59:38 +0100 | [diff] [blame] | 52 | import android.graphics.drawable.BitmapDrawable; |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 53 | import android.graphics.drawable.Drawable; |
| 54 | import android.net.Uri; |
Jeff Sharkey | 513a074 | 2014-07-08 17:10:32 -0700 | [diff] [blame] | 55 | import android.os.Bundle; |
dcashman | 9d2f441 | 2014-06-09 09:27:54 -0700 | [diff] [blame] | 56 | import android.os.IBinder; |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 57 | import android.os.Process; |
| 58 | import android.os.RemoteException; |
Amith Yamasani | 67df64b | 2012-12-14 12:09:36 -0800 | [diff] [blame] | 59 | import android.os.UserHandle; |
Nicolas Prevot | 88cc346 | 2014-05-14 14:51:48 +0100 | [diff] [blame] | 60 | import android.os.UserManager; |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 61 | import android.util.ArrayMap; |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 62 | import android.util.Log; |
Jeff Brown | a492c3a | 2012-08-23 19:48:44 -0700 | [diff] [blame] | 63 | import android.view.Display; |
Jeff Sharkey | 16c8e3f | 2014-07-24 17:08:17 -0700 | [diff] [blame] | 64 | |
| 65 | import com.android.internal.annotations.GuardedBy; |
dcashman | 9d2f441 | 2014-06-09 09:27:54 -0700 | [diff] [blame] | 66 | import com.android.internal.util.Preconditions; |
Jeff Sharkey | 16c8e3f | 2014-07-24 17:08:17 -0700 | [diff] [blame] | 67 | |
Narayan Kamath | caa7119 | 2014-07-16 11:06:43 +0100 | [diff] [blame] | 68 | import dalvik.system.VMRuntime; |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 69 | |
| 70 | import java.lang.ref.WeakReference; |
| 71 | import java.util.ArrayList; |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 72 | import java.util.List; |
| 73 | |
| 74 | /*package*/ |
| 75 | final class ApplicationPackageManager extends PackageManager { |
| 76 | private static final String TAG = "ApplicationPackageManager"; |
| 77 | private final static boolean DEBUG = false; |
| 78 | private final static boolean DEBUG_ICONS = false; |
| 79 | |
Jeff Sharkey | 16c8e3f | 2014-07-24 17:08:17 -0700 | [diff] [blame] | 80 | private final Object mLock = new Object(); |
| 81 | |
| 82 | @GuardedBy("mLock") |
| 83 | private UserManager mUserManager; |
| 84 | @GuardedBy("mLock") |
| 85 | private PackageInstaller mInstaller; |
Nicolas Prevot | 7f7b0c7 | 2014-06-23 15:59:38 +0100 | [diff] [blame] | 86 | |
| 87 | UserManager getUserManager() { |
Jeff Sharkey | 16c8e3f | 2014-07-24 17:08:17 -0700 | [diff] [blame] | 88 | synchronized (mLock) { |
| 89 | if (mUserManager == null) { |
| 90 | mUserManager = UserManager.get(mContext); |
| 91 | } |
| 92 | return mUserManager; |
Nicolas Prevot | 7f7b0c7 | 2014-06-23 15:59:38 +0100 | [diff] [blame] | 93 | } |
Nicolas Prevot | 7f7b0c7 | 2014-06-23 15:59:38 +0100 | [diff] [blame] | 94 | } |
| 95 | |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 96 | @Override |
| 97 | public PackageInfo getPackageInfo(String packageName, int flags) |
| 98 | throws NameNotFoundException { |
| 99 | try { |
Jeff Sharkey | ded653b | 2012-09-27 19:09:24 -0700 | [diff] [blame] | 100 | PackageInfo pi = mPM.getPackageInfo(packageName, flags, mContext.getUserId()); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 101 | if (pi != null) { |
| 102 | return pi; |
| 103 | } |
| 104 | } catch (RemoteException e) { |
| 105 | throw new RuntimeException("Package manager has died", e); |
| 106 | } |
| 107 | |
| 108 | throw new NameNotFoundException(packageName); |
| 109 | } |
| 110 | |
| 111 | @Override |
| 112 | public String[] currentToCanonicalPackageNames(String[] names) { |
| 113 | try { |
| 114 | return mPM.currentToCanonicalPackageNames(names); |
| 115 | } catch (RemoteException e) { |
| 116 | throw new RuntimeException("Package manager has died", e); |
| 117 | } |
| 118 | } |
| 119 | |
| 120 | @Override |
| 121 | public String[] canonicalToCurrentPackageNames(String[] names) { |
| 122 | try { |
| 123 | return mPM.canonicalToCurrentPackageNames(names); |
| 124 | } catch (RemoteException e) { |
| 125 | throw new RuntimeException("Package manager has died", e); |
| 126 | } |
| 127 | } |
| 128 | |
| 129 | @Override |
| 130 | public Intent getLaunchIntentForPackage(String packageName) { |
| 131 | // First see if the package has an INFO activity; the existence of |
| 132 | // such an activity is implied to be the desired front-door for the |
| 133 | // overall package (such as if it has multiple launcher entries). |
| 134 | Intent intentToResolve = new Intent(Intent.ACTION_MAIN); |
| 135 | intentToResolve.addCategory(Intent.CATEGORY_INFO); |
| 136 | intentToResolve.setPackage(packageName); |
Dianne Hackborn | 1941576 | 2010-12-15 00:20:27 -0800 | [diff] [blame] | 137 | List<ResolveInfo> ris = queryIntentActivities(intentToResolve, 0); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 138 | |
| 139 | // Otherwise, try to find a main launcher activity. |
Dianne Hackborn | 1941576 | 2010-12-15 00:20:27 -0800 | [diff] [blame] | 140 | if (ris == null || ris.size() <= 0) { |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 141 | // reuse the intent instance |
| 142 | intentToResolve.removeCategory(Intent.CATEGORY_INFO); |
| 143 | intentToResolve.addCategory(Intent.CATEGORY_LAUNCHER); |
| 144 | intentToResolve.setPackage(packageName); |
Dianne Hackborn | 1941576 | 2010-12-15 00:20:27 -0800 | [diff] [blame] | 145 | ris = queryIntentActivities(intentToResolve, 0); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 146 | } |
Dianne Hackborn | 1941576 | 2010-12-15 00:20:27 -0800 | [diff] [blame] | 147 | if (ris == null || ris.size() <= 0) { |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 148 | return null; |
| 149 | } |
| 150 | Intent intent = new Intent(intentToResolve); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 151 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
Dianne Hackborn | 1941576 | 2010-12-15 00:20:27 -0800 | [diff] [blame] | 152 | intent.setClassName(ris.get(0).activityInfo.packageName, |
| 153 | ris.get(0).activityInfo.name); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 154 | return intent; |
| 155 | } |
| 156 | |
| 157 | @Override |
Jose Lima | 970417c | 2014-04-10 10:42:19 -0700 | [diff] [blame] | 158 | public Intent getLeanbackLaunchIntentForPackage(String packageName) { |
| 159 | // Try to find a main leanback_launcher activity. |
| 160 | Intent intentToResolve = new Intent(Intent.ACTION_MAIN); |
| 161 | intentToResolve.addCategory(Intent.CATEGORY_LEANBACK_LAUNCHER); |
| 162 | intentToResolve.setPackage(packageName); |
| 163 | List<ResolveInfo> ris = queryIntentActivities(intentToResolve, 0); |
| 164 | |
| 165 | if (ris == null || ris.size() <= 0) { |
| 166 | return null; |
| 167 | } |
| 168 | Intent intent = new Intent(intentToResolve); |
| 169 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 170 | intent.setClassName(ris.get(0).activityInfo.packageName, |
| 171 | ris.get(0).activityInfo.name); |
| 172 | return intent; |
| 173 | } |
| 174 | |
| 175 | @Override |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 176 | public int[] getPackageGids(String packageName) |
| 177 | throws NameNotFoundException { |
| 178 | try { |
| 179 | int[] gids = mPM.getPackageGids(packageName); |
| 180 | if (gids == null || gids.length > 0) { |
| 181 | return gids; |
| 182 | } |
| 183 | } catch (RemoteException e) { |
| 184 | throw new RuntimeException("Package manager has died", e); |
| 185 | } |
| 186 | |
| 187 | throw new NameNotFoundException(packageName); |
| 188 | } |
| 189 | |
| 190 | @Override |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 191 | public int getPackageUid(String packageName, int userHandle) |
| 192 | throws NameNotFoundException { |
| 193 | try { |
| 194 | int uid = mPM.getPackageUid(packageName, userHandle); |
| 195 | if (uid >= 0) { |
| 196 | return uid; |
| 197 | } |
| 198 | } catch (RemoteException e) { |
| 199 | throw new RuntimeException("Package manager has died", e); |
| 200 | } |
| 201 | |
| 202 | throw new NameNotFoundException(packageName); |
| 203 | } |
| 204 | |
| 205 | @Override |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 206 | public PermissionInfo getPermissionInfo(String name, int flags) |
| 207 | throws NameNotFoundException { |
| 208 | try { |
| 209 | PermissionInfo pi = mPM.getPermissionInfo(name, flags); |
| 210 | if (pi != null) { |
| 211 | return pi; |
| 212 | } |
| 213 | } catch (RemoteException e) { |
| 214 | throw new RuntimeException("Package manager has died", e); |
| 215 | } |
| 216 | |
| 217 | throw new NameNotFoundException(name); |
| 218 | } |
| 219 | |
| 220 | @Override |
| 221 | public List<PermissionInfo> queryPermissionsByGroup(String group, int flags) |
| 222 | throws NameNotFoundException { |
| 223 | try { |
| 224 | List<PermissionInfo> pi = mPM.queryPermissionsByGroup(group, flags); |
| 225 | if (pi != null) { |
| 226 | return pi; |
| 227 | } |
| 228 | } catch (RemoteException e) { |
| 229 | throw new RuntimeException("Package manager has died", e); |
| 230 | } |
| 231 | |
| 232 | throw new NameNotFoundException(group); |
| 233 | } |
| 234 | |
| 235 | @Override |
| 236 | public PermissionGroupInfo getPermissionGroupInfo(String name, |
| 237 | int flags) throws NameNotFoundException { |
| 238 | try { |
| 239 | PermissionGroupInfo pgi = mPM.getPermissionGroupInfo(name, flags); |
| 240 | if (pgi != null) { |
| 241 | return pgi; |
| 242 | } |
| 243 | } catch (RemoteException e) { |
| 244 | throw new RuntimeException("Package manager has died", e); |
| 245 | } |
| 246 | |
| 247 | throw new NameNotFoundException(name); |
| 248 | } |
| 249 | |
| 250 | @Override |
| 251 | public List<PermissionGroupInfo> getAllPermissionGroups(int flags) { |
| 252 | try { |
| 253 | return mPM.getAllPermissionGroups(flags); |
| 254 | } catch (RemoteException e) { |
| 255 | throw new RuntimeException("Package manager has died", e); |
| 256 | } |
| 257 | } |
| 258 | |
| 259 | @Override |
| 260 | public ApplicationInfo getApplicationInfo(String packageName, int flags) |
| 261 | throws NameNotFoundException { |
| 262 | try { |
Jeff Sharkey | ded653b | 2012-09-27 19:09:24 -0700 | [diff] [blame] | 263 | ApplicationInfo ai = mPM.getApplicationInfo(packageName, flags, mContext.getUserId()); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 264 | if (ai != null) { |
Narayan Kamath | caa7119 | 2014-07-16 11:06:43 +0100 | [diff] [blame] | 265 | // This is a temporary hack. Callers must use |
| 266 | // createPackageContext(packageName).getApplicationInfo() to |
| 267 | // get the right paths. |
| 268 | maybeAdjustApplicationInfo(ai); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 269 | return ai; |
| 270 | } |
| 271 | } catch (RemoteException e) { |
| 272 | throw new RuntimeException("Package manager has died", e); |
| 273 | } |
| 274 | |
| 275 | throw new NameNotFoundException(packageName); |
| 276 | } |
| 277 | |
Narayan Kamath | caa7119 | 2014-07-16 11:06:43 +0100 | [diff] [blame] | 278 | private static void maybeAdjustApplicationInfo(ApplicationInfo info) { |
| 279 | // If we're dealing with a multi-arch application that has both |
| 280 | // 32 and 64 bit shared libraries, we might need to choose the secondary |
| 281 | // depending on what the current runtime's instruction set is. |
| 282 | if (info.primaryCpuAbi != null && info.secondaryCpuAbi != null) { |
| 283 | final String runtimeIsa = VMRuntime.getRuntime().vmInstructionSet(); |
| 284 | final String secondaryIsa = VMRuntime.getInstructionSet(info.secondaryCpuAbi); |
| 285 | |
| 286 | // If the runtimeIsa is the same as the primary isa, then we do nothing. |
| 287 | // Everything will be set up correctly because info.nativeLibraryDir will |
| 288 | // correspond to the right ISA. |
| 289 | if (runtimeIsa.equals(secondaryIsa)) { |
| 290 | info.nativeLibraryDir = info.secondaryNativeLibraryDir; |
| 291 | } |
| 292 | } |
| 293 | } |
| 294 | |
| 295 | |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 296 | @Override |
| 297 | public ActivityInfo getActivityInfo(ComponentName className, int flags) |
| 298 | throws NameNotFoundException { |
| 299 | try { |
Jeff Sharkey | ded653b | 2012-09-27 19:09:24 -0700 | [diff] [blame] | 300 | ActivityInfo ai = mPM.getActivityInfo(className, flags, mContext.getUserId()); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 301 | if (ai != null) { |
| 302 | return ai; |
| 303 | } |
| 304 | } catch (RemoteException e) { |
| 305 | throw new RuntimeException("Package manager has died", e); |
| 306 | } |
| 307 | |
| 308 | throw new NameNotFoundException(className.toString()); |
| 309 | } |
| 310 | |
| 311 | @Override |
| 312 | public ActivityInfo getReceiverInfo(ComponentName className, int flags) |
| 313 | throws NameNotFoundException { |
| 314 | try { |
Jeff Sharkey | ded653b | 2012-09-27 19:09:24 -0700 | [diff] [blame] | 315 | ActivityInfo ai = mPM.getReceiverInfo(className, flags, mContext.getUserId()); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 316 | if (ai != null) { |
| 317 | return ai; |
| 318 | } |
| 319 | } catch (RemoteException e) { |
| 320 | throw new RuntimeException("Package manager has died", e); |
| 321 | } |
| 322 | |
| 323 | throw new NameNotFoundException(className.toString()); |
| 324 | } |
| 325 | |
| 326 | @Override |
| 327 | public ServiceInfo getServiceInfo(ComponentName className, int flags) |
| 328 | throws NameNotFoundException { |
| 329 | try { |
Jeff Sharkey | ded653b | 2012-09-27 19:09:24 -0700 | [diff] [blame] | 330 | ServiceInfo si = mPM.getServiceInfo(className, flags, mContext.getUserId()); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 331 | if (si != null) { |
| 332 | return si; |
| 333 | } |
| 334 | } catch (RemoteException e) { |
| 335 | throw new RuntimeException("Package manager has died", e); |
| 336 | } |
| 337 | |
| 338 | throw new NameNotFoundException(className.toString()); |
| 339 | } |
| 340 | |
| 341 | @Override |
| 342 | public ProviderInfo getProviderInfo(ComponentName className, int flags) |
| 343 | throws NameNotFoundException { |
| 344 | try { |
Jeff Sharkey | ded653b | 2012-09-27 19:09:24 -0700 | [diff] [blame] | 345 | ProviderInfo pi = mPM.getProviderInfo(className, flags, mContext.getUserId()); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 346 | if (pi != null) { |
| 347 | return pi; |
| 348 | } |
| 349 | } catch (RemoteException e) { |
| 350 | throw new RuntimeException("Package manager has died", e); |
| 351 | } |
| 352 | |
| 353 | throw new NameNotFoundException(className.toString()); |
| 354 | } |
| 355 | |
| 356 | @Override |
| 357 | public String[] getSystemSharedLibraryNames() { |
| 358 | try { |
| 359 | return mPM.getSystemSharedLibraryNames(); |
| 360 | } catch (RemoteException e) { |
| 361 | throw new RuntimeException("Package manager has died", e); |
| 362 | } |
| 363 | } |
| 364 | |
| 365 | @Override |
| 366 | public FeatureInfo[] getSystemAvailableFeatures() { |
| 367 | try { |
| 368 | return mPM.getSystemAvailableFeatures(); |
| 369 | } catch (RemoteException e) { |
| 370 | throw new RuntimeException("Package manager has died", e); |
| 371 | } |
| 372 | } |
| 373 | |
| 374 | @Override |
| 375 | public boolean hasSystemFeature(String name) { |
| 376 | try { |
| 377 | return mPM.hasSystemFeature(name); |
| 378 | } catch (RemoteException e) { |
| 379 | throw new RuntimeException("Package manager has died", e); |
| 380 | } |
| 381 | } |
| 382 | |
| 383 | @Override |
| 384 | public int checkPermission(String permName, String pkgName) { |
| 385 | try { |
| 386 | return mPM.checkPermission(permName, pkgName); |
| 387 | } catch (RemoteException e) { |
| 388 | throw new RuntimeException("Package manager has died", e); |
| 389 | } |
| 390 | } |
| 391 | |
| 392 | @Override |
| 393 | public boolean addPermission(PermissionInfo info) { |
| 394 | try { |
| 395 | return mPM.addPermission(info); |
| 396 | } catch (RemoteException e) { |
| 397 | throw new RuntimeException("Package manager has died", e); |
| 398 | } |
| 399 | } |
| 400 | |
| 401 | @Override |
| 402 | public boolean addPermissionAsync(PermissionInfo info) { |
| 403 | try { |
| 404 | return mPM.addPermissionAsync(info); |
| 405 | } catch (RemoteException e) { |
| 406 | throw new RuntimeException("Package manager has died", e); |
| 407 | } |
| 408 | } |
| 409 | |
| 410 | @Override |
| 411 | public void removePermission(String name) { |
| 412 | try { |
| 413 | mPM.removePermission(name); |
| 414 | } catch (RemoteException e) { |
| 415 | throw new RuntimeException("Package manager has died", e); |
| 416 | } |
| 417 | } |
| 418 | |
| 419 | @Override |
Dianne Hackborn | e639da7 | 2012-02-21 15:11:13 -0800 | [diff] [blame] | 420 | public void grantPermission(String packageName, String permissionName) { |
| 421 | try { |
| 422 | mPM.grantPermission(packageName, permissionName); |
| 423 | } catch (RemoteException e) { |
| 424 | throw new RuntimeException("Package manager has died", e); |
| 425 | } |
| 426 | } |
| 427 | |
| 428 | @Override |
| 429 | public void revokePermission(String packageName, String permissionName) { |
| 430 | try { |
| 431 | mPM.revokePermission(packageName, permissionName); |
| 432 | } catch (RemoteException e) { |
| 433 | throw new RuntimeException("Package manager has died", e); |
| 434 | } |
| 435 | } |
| 436 | |
| 437 | @Override |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 438 | public int checkSignatures(String pkg1, String pkg2) { |
| 439 | try { |
| 440 | return mPM.checkSignatures(pkg1, pkg2); |
| 441 | } catch (RemoteException e) { |
| 442 | throw new RuntimeException("Package manager has died", e); |
| 443 | } |
| 444 | } |
| 445 | |
| 446 | @Override |
| 447 | public int checkSignatures(int uid1, int uid2) { |
| 448 | try { |
| 449 | return mPM.checkUidSignatures(uid1, uid2); |
| 450 | } catch (RemoteException e) { |
| 451 | throw new RuntimeException("Package manager has died", e); |
| 452 | } |
| 453 | } |
| 454 | |
| 455 | @Override |
| 456 | public String[] getPackagesForUid(int uid) { |
| 457 | try { |
| 458 | return mPM.getPackagesForUid(uid); |
| 459 | } catch (RemoteException e) { |
| 460 | throw new RuntimeException("Package manager has died", e); |
| 461 | } |
| 462 | } |
| 463 | |
| 464 | @Override |
| 465 | public String getNameForUid(int uid) { |
| 466 | try { |
| 467 | return mPM.getNameForUid(uid); |
| 468 | } catch (RemoteException e) { |
| 469 | throw new RuntimeException("Package manager has died", e); |
| 470 | } |
| 471 | } |
| 472 | |
| 473 | @Override |
| 474 | public int getUidForSharedUser(String sharedUserName) |
| 475 | throws NameNotFoundException { |
| 476 | try { |
| 477 | int uid = mPM.getUidForSharedUser(sharedUserName); |
| 478 | if(uid != -1) { |
| 479 | return uid; |
| 480 | } |
| 481 | } catch (RemoteException e) { |
| 482 | throw new RuntimeException("Package manager has died", e); |
| 483 | } |
| 484 | throw new NameNotFoundException("No shared userid for user:"+sharedUserName); |
| 485 | } |
| 486 | |
Kenny Root | e6cd0c7 | 2011-05-19 12:48:14 -0700 | [diff] [blame] | 487 | @SuppressWarnings("unchecked") |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 488 | @Override |
| 489 | public List<PackageInfo> getInstalledPackages(int flags) { |
Jeff Sharkey | ded653b | 2012-09-27 19:09:24 -0700 | [diff] [blame] | 490 | return getInstalledPackages(flags, mContext.getUserId()); |
Amith Yamasani | 151ec4c | 2012-09-07 19:25:16 -0700 | [diff] [blame] | 491 | } |
| 492 | |
| 493 | /** @hide */ |
| 494 | @Override |
| 495 | public List<PackageInfo> getInstalledPackages(int flags, int userId) { |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 496 | try { |
Dianne Hackborn | d8e1dbb | 2013-01-17 17:47:37 -0800 | [diff] [blame] | 497 | ParceledListSlice<PackageInfo> slice = mPM.getInstalledPackages(flags, userId); |
| 498 | return slice.getList(); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 499 | } catch (RemoteException e) { |
| 500 | throw new RuntimeException("Package manager has died", e); |
| 501 | } |
| 502 | } |
| 503 | |
Kenny Root | e6cd0c7 | 2011-05-19 12:48:14 -0700 | [diff] [blame] | 504 | @SuppressWarnings("unchecked") |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 505 | @Override |
Dianne Hackborn | e799175 | 2013-01-16 17:56:46 -0800 | [diff] [blame] | 506 | public List<PackageInfo> getPackagesHoldingPermissions( |
| 507 | String[] permissions, int flags) { |
| 508 | final int userId = mContext.getUserId(); |
| 509 | try { |
Dianne Hackborn | d8e1dbb | 2013-01-17 17:47:37 -0800 | [diff] [blame] | 510 | ParceledListSlice<PackageInfo> slice = mPM.getPackagesHoldingPermissions( |
| 511 | permissions, flags, userId); |
| 512 | return slice.getList(); |
Dianne Hackborn | e799175 | 2013-01-16 17:56:46 -0800 | [diff] [blame] | 513 | } catch (RemoteException e) { |
| 514 | throw new RuntimeException("Package manager has died", e); |
| 515 | } |
| 516 | } |
| 517 | |
| 518 | @SuppressWarnings("unchecked") |
| 519 | @Override |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 520 | public List<ApplicationInfo> getInstalledApplications(int flags) { |
Jeff Sharkey | ded653b | 2012-09-27 19:09:24 -0700 | [diff] [blame] | 521 | final int userId = mContext.getUserId(); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 522 | try { |
Dianne Hackborn | d8e1dbb | 2013-01-17 17:47:37 -0800 | [diff] [blame] | 523 | ParceledListSlice<ApplicationInfo> slice = mPM.getInstalledApplications(flags, userId); |
| 524 | return slice.getList(); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 525 | } catch (RemoteException e) { |
| 526 | throw new RuntimeException("Package manager has died", e); |
| 527 | } |
| 528 | } |
| 529 | |
| 530 | @Override |
| 531 | public ResolveInfo resolveActivity(Intent intent, int flags) { |
Jeff Sharkey | ded653b | 2012-09-27 19:09:24 -0700 | [diff] [blame] | 532 | return resolveActivityAsUser(intent, flags, mContext.getUserId()); |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 533 | } |
| 534 | |
| 535 | @Override |
| 536 | public ResolveInfo resolveActivityAsUser(Intent intent, int flags, int userId) { |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 537 | try { |
| 538 | return mPM.resolveIntent( |
| 539 | intent, |
| 540 | intent.resolveTypeIfNeeded(mContext.getContentResolver()), |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 541 | flags, |
| 542 | userId); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 543 | } catch (RemoteException e) { |
| 544 | throw new RuntimeException("Package manager has died", e); |
| 545 | } |
| 546 | } |
| 547 | |
| 548 | @Override |
| 549 | public List<ResolveInfo> queryIntentActivities(Intent intent, |
| 550 | int flags) { |
Jeff Sharkey | ded653b | 2012-09-27 19:09:24 -0700 | [diff] [blame] | 551 | return queryIntentActivitiesAsUser(intent, flags, mContext.getUserId()); |
Amith Yamasani | 151ec4c | 2012-09-07 19:25:16 -0700 | [diff] [blame] | 552 | } |
| 553 | |
| 554 | /** @hide Same as above but for a specific user */ |
| 555 | @Override |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 556 | public List<ResolveInfo> queryIntentActivitiesAsUser(Intent intent, |
Amith Yamasani | 151ec4c | 2012-09-07 19:25:16 -0700 | [diff] [blame] | 557 | int flags, int userId) { |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 558 | try { |
| 559 | return mPM.queryIntentActivities( |
| 560 | intent, |
| 561 | intent.resolveTypeIfNeeded(mContext.getContentResolver()), |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 562 | flags, |
Amith Yamasani | 151ec4c | 2012-09-07 19:25:16 -0700 | [diff] [blame] | 563 | userId); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 564 | } catch (RemoteException e) { |
| 565 | throw new RuntimeException("Package manager has died", e); |
| 566 | } |
| 567 | } |
| 568 | |
| 569 | @Override |
| 570 | public List<ResolveInfo> queryIntentActivityOptions( |
| 571 | ComponentName caller, Intent[] specifics, Intent intent, |
| 572 | int flags) { |
| 573 | final ContentResolver resolver = mContext.getContentResolver(); |
| 574 | |
| 575 | String[] specificTypes = null; |
| 576 | if (specifics != null) { |
| 577 | final int N = specifics.length; |
| 578 | for (int i=0; i<N; i++) { |
| 579 | Intent sp = specifics[i]; |
| 580 | if (sp != null) { |
| 581 | String t = sp.resolveTypeIfNeeded(resolver); |
| 582 | if (t != null) { |
| 583 | if (specificTypes == null) { |
| 584 | specificTypes = new String[N]; |
| 585 | } |
| 586 | specificTypes[i] = t; |
| 587 | } |
| 588 | } |
| 589 | } |
| 590 | } |
| 591 | |
| 592 | try { |
| 593 | return mPM.queryIntentActivityOptions(caller, specifics, |
| 594 | specificTypes, intent, intent.resolveTypeIfNeeded(resolver), |
Jeff Sharkey | ded653b | 2012-09-27 19:09:24 -0700 | [diff] [blame] | 595 | flags, mContext.getUserId()); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 596 | } catch (RemoteException e) { |
| 597 | throw new RuntimeException("Package manager has died", e); |
| 598 | } |
| 599 | } |
| 600 | |
Amith Yamasani | f203aee | 2012-08-29 18:41:53 -0700 | [diff] [blame] | 601 | /** |
| 602 | * @hide |
| 603 | */ |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 604 | @Override |
Amith Yamasani | f203aee | 2012-08-29 18:41:53 -0700 | [diff] [blame] | 605 | public List<ResolveInfo> queryBroadcastReceivers(Intent intent, int flags, int userId) { |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 606 | try { |
| 607 | return mPM.queryIntentReceivers( |
| 608 | intent, |
| 609 | intent.resolveTypeIfNeeded(mContext.getContentResolver()), |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 610 | flags, |
Amith Yamasani | f203aee | 2012-08-29 18:41:53 -0700 | [diff] [blame] | 611 | userId); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 612 | } catch (RemoteException e) { |
| 613 | throw new RuntimeException("Package manager has died", e); |
| 614 | } |
| 615 | } |
| 616 | |
| 617 | @Override |
Amith Yamasani | f203aee | 2012-08-29 18:41:53 -0700 | [diff] [blame] | 618 | public List<ResolveInfo> queryBroadcastReceivers(Intent intent, int flags) { |
Jeff Sharkey | ded653b | 2012-09-27 19:09:24 -0700 | [diff] [blame] | 619 | return queryBroadcastReceivers(intent, flags, mContext.getUserId()); |
Amith Yamasani | f203aee | 2012-08-29 18:41:53 -0700 | [diff] [blame] | 620 | } |
| 621 | |
| 622 | @Override |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 623 | public ResolveInfo resolveService(Intent intent, int flags) { |
| 624 | try { |
| 625 | return mPM.resolveService( |
| 626 | intent, |
| 627 | intent.resolveTypeIfNeeded(mContext.getContentResolver()), |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 628 | flags, |
Jeff Sharkey | ded653b | 2012-09-27 19:09:24 -0700 | [diff] [blame] | 629 | mContext.getUserId()); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 630 | } catch (RemoteException e) { |
| 631 | throw new RuntimeException("Package manager has died", e); |
| 632 | } |
| 633 | } |
| 634 | |
| 635 | @Override |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 636 | public List<ResolveInfo> queryIntentServicesAsUser(Intent intent, int flags, int userId) { |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 637 | try { |
| 638 | return mPM.queryIntentServices( |
| 639 | intent, |
| 640 | intent.resolveTypeIfNeeded(mContext.getContentResolver()), |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 641 | flags, |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 642 | userId); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 643 | } catch (RemoteException e) { |
| 644 | throw new RuntimeException("Package manager has died", e); |
| 645 | } |
| 646 | } |
| 647 | |
| 648 | @Override |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 649 | public List<ResolveInfo> queryIntentServices(Intent intent, int flags) { |
Jeff Sharkey | ded653b | 2012-09-27 19:09:24 -0700 | [diff] [blame] | 650 | return queryIntentServicesAsUser(intent, flags, mContext.getUserId()); |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 651 | } |
| 652 | |
| 653 | @Override |
Jeff Sharkey | 85f5f81 | 2013-10-07 10:16:12 -0700 | [diff] [blame] | 654 | public List<ResolveInfo> queryIntentContentProvidersAsUser( |
| 655 | Intent intent, int flags, int userId) { |
| 656 | try { |
| 657 | return mPM.queryIntentContentProviders(intent, |
| 658 | intent.resolveTypeIfNeeded(mContext.getContentResolver()), flags, userId); |
| 659 | } catch (RemoteException e) { |
| 660 | throw new RuntimeException("Package manager has died", e); |
| 661 | } |
| 662 | } |
| 663 | |
| 664 | @Override |
| 665 | public List<ResolveInfo> queryIntentContentProviders(Intent intent, int flags) { |
| 666 | return queryIntentContentProvidersAsUser(intent, flags, mContext.getUserId()); |
| 667 | } |
| 668 | |
| 669 | @Override |
Alexandra Gherghina | 0363c3e | 2014-06-23 13:34:59 +0100 | [diff] [blame] | 670 | public ProviderInfo resolveContentProvider(String name, int flags) { |
| 671 | return resolveContentProviderAsUser(name, flags, mContext.getUserId()); |
| 672 | } |
| 673 | |
| 674 | /** @hide **/ |
| 675 | @Override |
| 676 | public ProviderInfo resolveContentProviderAsUser(String name, int flags, int userId) { |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 677 | try { |
Alexandra Gherghina | 0363c3e | 2014-06-23 13:34:59 +0100 | [diff] [blame] | 678 | return mPM.resolveContentProvider(name, flags, userId); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 679 | } catch (RemoteException e) { |
| 680 | throw new RuntimeException("Package manager has died", e); |
| 681 | } |
| 682 | } |
| 683 | |
| 684 | @Override |
| 685 | public List<ProviderInfo> queryContentProviders(String processName, |
| 686 | int uid, int flags) { |
| 687 | try { |
| 688 | return mPM.queryContentProviders(processName, uid, flags); |
| 689 | } catch (RemoteException e) { |
| 690 | throw new RuntimeException("Package manager has died", e); |
| 691 | } |
| 692 | } |
| 693 | |
| 694 | @Override |
| 695 | public InstrumentationInfo getInstrumentationInfo( |
| 696 | ComponentName className, int flags) |
| 697 | throws NameNotFoundException { |
| 698 | try { |
| 699 | InstrumentationInfo ii = mPM.getInstrumentationInfo( |
| 700 | className, flags); |
| 701 | if (ii != null) { |
| 702 | return ii; |
| 703 | } |
| 704 | } catch (RemoteException e) { |
| 705 | throw new RuntimeException("Package manager has died", e); |
| 706 | } |
| 707 | |
| 708 | throw new NameNotFoundException(className.toString()); |
| 709 | } |
| 710 | |
| 711 | @Override |
| 712 | public List<InstrumentationInfo> queryInstrumentation( |
| 713 | String targetPackage, int flags) { |
| 714 | try { |
| 715 | return mPM.queryInstrumentation(targetPackage, flags); |
| 716 | } catch (RemoteException e) { |
| 717 | throw new RuntimeException("Package manager has died", e); |
| 718 | } |
| 719 | } |
| 720 | |
| 721 | @Override public Drawable getDrawable(String packageName, int resid, |
| 722 | ApplicationInfo appInfo) { |
| 723 | ResourceName name = new ResourceName(packageName, resid); |
| 724 | Drawable dr = getCachedIcon(name); |
| 725 | if (dr != null) { |
| 726 | return dr; |
| 727 | } |
| 728 | if (appInfo == null) { |
| 729 | try { |
| 730 | appInfo = getApplicationInfo(packageName, 0); |
| 731 | } catch (NameNotFoundException e) { |
| 732 | return null; |
| 733 | } |
| 734 | } |
| 735 | try { |
| 736 | Resources r = getResourcesForApplication(appInfo); |
| 737 | dr = r.getDrawable(resid); |
| 738 | if (false) { |
| 739 | RuntimeException e = new RuntimeException("here"); |
| 740 | e.fillInStackTrace(); |
| 741 | Log.w(TAG, "Getting drawable 0x" + Integer.toHexString(resid) |
| 742 | + " from package " + packageName |
| 743 | + ": app scale=" + r.getCompatibilityInfo().applicationScale |
| 744 | + ", caller scale=" + mContext.getResources().getCompatibilityInfo().applicationScale, |
| 745 | e); |
| 746 | } |
| 747 | if (DEBUG_ICONS) Log.v(TAG, "Getting drawable 0x" |
| 748 | + Integer.toHexString(resid) + " from " + r |
| 749 | + ": " + dr); |
| 750 | putCachedIcon(name, dr); |
| 751 | return dr; |
| 752 | } catch (NameNotFoundException e) { |
| 753 | Log.w("PackageManager", "Failure retrieving resources for" |
| 754 | + appInfo.packageName); |
Joe Onorato | 08f1654 | 2011-01-20 11:49:56 -0800 | [diff] [blame] | 755 | } catch (Resources.NotFoundException e) { |
| 756 | Log.w("PackageManager", "Failure retrieving resources for" |
| 757 | + appInfo.packageName + ": " + e.getMessage()); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 758 | } catch (RuntimeException e) { |
| 759 | // If an exception was thrown, fall through to return |
| 760 | // default icon. |
| 761 | Log.w("PackageManager", "Failure retrieving icon 0x" |
| 762 | + Integer.toHexString(resid) + " in package " |
| 763 | + packageName, e); |
| 764 | } |
| 765 | return null; |
| 766 | } |
| 767 | |
| 768 | @Override public Drawable getActivityIcon(ComponentName activityName) |
| 769 | throws NameNotFoundException { |
| 770 | return getActivityInfo(activityName, 0).loadIcon(this); |
| 771 | } |
| 772 | |
| 773 | @Override public Drawable getActivityIcon(Intent intent) |
| 774 | throws NameNotFoundException { |
| 775 | if (intent.getComponent() != null) { |
| 776 | return getActivityIcon(intent.getComponent()); |
| 777 | } |
| 778 | |
| 779 | ResolveInfo info = resolveActivity( |
| 780 | intent, PackageManager.MATCH_DEFAULT_ONLY); |
| 781 | if (info != null) { |
| 782 | return info.activityInfo.loadIcon(this); |
| 783 | } |
| 784 | |
Romain Guy | 39fe17c | 2011-11-30 10:34:07 -0800 | [diff] [blame] | 785 | throw new NameNotFoundException(intent.toUri(0)); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 786 | } |
| 787 | |
| 788 | @Override public Drawable getDefaultActivityIcon() { |
| 789 | return Resources.getSystem().getDrawable( |
| 790 | com.android.internal.R.drawable.sym_def_app_icon); |
| 791 | } |
| 792 | |
| 793 | @Override public Drawable getApplicationIcon(ApplicationInfo info) { |
| 794 | return info.loadIcon(this); |
| 795 | } |
| 796 | |
| 797 | @Override public Drawable getApplicationIcon(String packageName) |
| 798 | throws NameNotFoundException { |
| 799 | return getApplicationIcon(getApplicationInfo(packageName, 0)); |
| 800 | } |
| 801 | |
| 802 | @Override |
Jose Lima | f78e312 | 2014-03-06 12:13:15 -0800 | [diff] [blame] | 803 | public Drawable getActivityBanner(ComponentName activityName) |
| 804 | throws NameNotFoundException { |
| 805 | return getActivityInfo(activityName, 0).loadBanner(this); |
| 806 | } |
| 807 | |
| 808 | @Override |
| 809 | public Drawable getActivityBanner(Intent intent) |
| 810 | throws NameNotFoundException { |
| 811 | if (intent.getComponent() != null) { |
| 812 | return getActivityBanner(intent.getComponent()); |
| 813 | } |
| 814 | |
| 815 | ResolveInfo info = resolveActivity( |
| 816 | intent, PackageManager.MATCH_DEFAULT_ONLY); |
| 817 | if (info != null) { |
| 818 | return info.activityInfo.loadBanner(this); |
| 819 | } |
| 820 | |
| 821 | throw new NameNotFoundException(intent.toUri(0)); |
| 822 | } |
| 823 | |
| 824 | @Override |
| 825 | public Drawable getApplicationBanner(ApplicationInfo info) { |
| 826 | return info.loadBanner(this); |
| 827 | } |
| 828 | |
| 829 | @Override |
| 830 | public Drawable getApplicationBanner(String packageName) |
| 831 | throws NameNotFoundException { |
| 832 | return getApplicationBanner(getApplicationInfo(packageName, 0)); |
| 833 | } |
| 834 | |
| 835 | @Override |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 836 | public Drawable getActivityLogo(ComponentName activityName) |
| 837 | throws NameNotFoundException { |
| 838 | return getActivityInfo(activityName, 0).loadLogo(this); |
| 839 | } |
| 840 | |
| 841 | @Override |
| 842 | public Drawable getActivityLogo(Intent intent) |
| 843 | throws NameNotFoundException { |
| 844 | if (intent.getComponent() != null) { |
| 845 | return getActivityLogo(intent.getComponent()); |
| 846 | } |
| 847 | |
| 848 | ResolveInfo info = resolveActivity( |
| 849 | intent, PackageManager.MATCH_DEFAULT_ONLY); |
| 850 | if (info != null) { |
| 851 | return info.activityInfo.loadLogo(this); |
| 852 | } |
| 853 | |
| 854 | throw new NameNotFoundException(intent.toUri(0)); |
| 855 | } |
| 856 | |
| 857 | @Override |
| 858 | public Drawable getApplicationLogo(ApplicationInfo info) { |
| 859 | return info.loadLogo(this); |
| 860 | } |
| 861 | |
| 862 | @Override |
| 863 | public Drawable getApplicationLogo(String packageName) |
| 864 | throws NameNotFoundException { |
| 865 | return getApplicationLogo(getApplicationInfo(packageName, 0)); |
| 866 | } |
| 867 | |
| 868 | @Override public Resources getResourcesForActivity( |
| 869 | ComponentName activityName) throws NameNotFoundException { |
| 870 | return getResourcesForApplication( |
| 871 | getActivityInfo(activityName, 0).applicationInfo); |
| 872 | } |
| 873 | |
| 874 | @Override public Resources getResourcesForApplication( |
| 875 | ApplicationInfo app) throws NameNotFoundException { |
| 876 | if (app.packageName.equals("system")) { |
| 877 | return mContext.mMainThread.getSystemContext().getResources(); |
| 878 | } |
Jeff Sharkey | 8a4c972 | 2014-06-16 13:48:42 -0700 | [diff] [blame] | 879 | final boolean sameUid = (app.uid == Process.myUid()); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 880 | Resources r = mContext.mMainThread.getTopLevelResources( |
Jeff Sharkey | 8a4c972 | 2014-06-16 13:48:42 -0700 | [diff] [blame] | 881 | sameUid ? app.sourceDir : app.publicSourceDir, |
| 882 | sameUid ? app.splitSourceDirs : app.splitPublicSourceDirs, |
Adam Lesinski | de898ff | 2014-01-29 18:20:45 -0800 | [diff] [blame] | 883 | app.resourceDirs, null, Display.DEFAULT_DISPLAY, null, mContext.mPackageInfo); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 884 | if (r != null) { |
| 885 | return r; |
| 886 | } |
| 887 | throw new NameNotFoundException("Unable to open " + app.publicSourceDir); |
| 888 | } |
| 889 | |
| 890 | @Override public Resources getResourcesForApplication( |
| 891 | String appPackageName) throws NameNotFoundException { |
| 892 | return getResourcesForApplication( |
| 893 | getApplicationInfo(appPackageName, 0)); |
| 894 | } |
| 895 | |
Amith Yamasani | 98edc95 | 2012-09-25 14:09:27 -0700 | [diff] [blame] | 896 | /** @hide */ |
| 897 | @Override |
| 898 | public Resources getResourcesForApplicationAsUser(String appPackageName, int userId) |
| 899 | throws NameNotFoundException { |
Jeff Sharkey | ded653b | 2012-09-27 19:09:24 -0700 | [diff] [blame] | 900 | if (userId < 0) { |
| 901 | throw new IllegalArgumentException( |
| 902 | "Call does not support special user #" + userId); |
| 903 | } |
| 904 | if ("system".equals(appPackageName)) { |
| 905 | return mContext.mMainThread.getSystemContext().getResources(); |
| 906 | } |
Amith Yamasani | 98edc95 | 2012-09-25 14:09:27 -0700 | [diff] [blame] | 907 | try { |
| 908 | ApplicationInfo ai = mPM.getApplicationInfo(appPackageName, 0, userId); |
| 909 | if (ai != null) { |
| 910 | return getResourcesForApplication(ai); |
| 911 | } |
| 912 | } catch (RemoteException e) { |
| 913 | throw new RuntimeException("Package manager has died", e); |
| 914 | } |
| 915 | throw new NameNotFoundException("Package " + appPackageName + " doesn't exist"); |
| 916 | } |
| 917 | |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 918 | int mCachedSafeMode = -1; |
| 919 | @Override public boolean isSafeMode() { |
| 920 | try { |
| 921 | if (mCachedSafeMode < 0) { |
| 922 | mCachedSafeMode = mPM.isSafeMode() ? 1 : 0; |
| 923 | } |
| 924 | return mCachedSafeMode != 0; |
| 925 | } catch (RemoteException e) { |
| 926 | throw new RuntimeException("Package manager has died", e); |
| 927 | } |
| 928 | } |
| 929 | |
| 930 | static void configurationChanged() { |
| 931 | synchronized (sSync) { |
| 932 | sIconCache.clear(); |
| 933 | sStringCache.clear(); |
| 934 | } |
| 935 | } |
| 936 | |
| 937 | ApplicationPackageManager(ContextImpl context, |
| 938 | IPackageManager pm) { |
| 939 | mContext = context; |
| 940 | mPM = pm; |
| 941 | } |
| 942 | |
| 943 | private Drawable getCachedIcon(ResourceName name) { |
| 944 | synchronized (sSync) { |
Romain Guy | 39fe17c | 2011-11-30 10:34:07 -0800 | [diff] [blame] | 945 | WeakReference<Drawable.ConstantState> wr = sIconCache.get(name); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 946 | if (DEBUG_ICONS) Log.v(TAG, "Get cached weak drawable ref for " |
| 947 | + name + ": " + wr); |
| 948 | if (wr != null) { // we have the activity |
Romain Guy | 39fe17c | 2011-11-30 10:34:07 -0800 | [diff] [blame] | 949 | Drawable.ConstantState state = wr.get(); |
| 950 | if (state != null) { |
| 951 | if (DEBUG_ICONS) { |
| 952 | Log.v(TAG, "Get cached drawable state for " + name + ": " + state); |
| 953 | } |
| 954 | // Note: It's okay here to not use the newDrawable(Resources) variant |
| 955 | // of the API. The ConstantState comes from a drawable that was |
| 956 | // originally created by passing the proper app Resources instance |
| 957 | // which means the state should already contain the proper |
| 958 | // resources specific information (like density.) See |
| 959 | // BitmapDrawable.BitmapState for instance. |
| 960 | return state.newDrawable(); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 961 | } |
| 962 | // our entry has been purged |
| 963 | sIconCache.remove(name); |
| 964 | } |
| 965 | } |
| 966 | return null; |
| 967 | } |
| 968 | |
| 969 | private void putCachedIcon(ResourceName name, Drawable dr) { |
| 970 | synchronized (sSync) { |
Romain Guy | 39fe17c | 2011-11-30 10:34:07 -0800 | [diff] [blame] | 971 | sIconCache.put(name, new WeakReference<Drawable.ConstantState>(dr.getConstantState())); |
| 972 | if (DEBUG_ICONS) Log.v(TAG, "Added cached drawable state for " + name + ": " + dr); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 973 | } |
| 974 | } |
| 975 | |
Romain Guy | 39fe17c | 2011-11-30 10:34:07 -0800 | [diff] [blame] | 976 | static void handlePackageBroadcast(int cmd, String[] pkgList, boolean hasPkgInfo) { |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 977 | boolean immediateGc = false; |
| 978 | if (cmd == IApplicationThread.EXTERNAL_STORAGE_UNAVAILABLE) { |
| 979 | immediateGc = true; |
| 980 | } |
| 981 | if (pkgList != null && (pkgList.length > 0)) { |
| 982 | boolean needCleanup = false; |
| 983 | for (String ssp : pkgList) { |
| 984 | synchronized (sSync) { |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 985 | for (int i=sIconCache.size()-1; i>=0; i--) { |
| 986 | ResourceName nm = sIconCache.keyAt(i); |
| 987 | if (nm.packageName.equals(ssp)) { |
| 988 | //Log.i(TAG, "Removing cached drawable for " + nm); |
| 989 | sIconCache.removeAt(i); |
| 990 | needCleanup = true; |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 991 | } |
| 992 | } |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 993 | for (int i=sStringCache.size()-1; i>=0; i--) { |
| 994 | ResourceName nm = sStringCache.keyAt(i); |
| 995 | if (nm.packageName.equals(ssp)) { |
| 996 | //Log.i(TAG, "Removing cached string for " + nm); |
| 997 | sStringCache.removeAt(i); |
| 998 | needCleanup = true; |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 999 | } |
| 1000 | } |
| 1001 | } |
| 1002 | } |
| 1003 | if (needCleanup || hasPkgInfo) { |
| 1004 | if (immediateGc) { |
| 1005 | // Schedule an immediate gc. |
| 1006 | Runtime.getRuntime().gc(); |
| 1007 | } else { |
| 1008 | ActivityThread.currentActivityThread().scheduleGcIdler(); |
| 1009 | } |
| 1010 | } |
| 1011 | } |
| 1012 | } |
| 1013 | |
| 1014 | private static final class ResourceName { |
| 1015 | final String packageName; |
| 1016 | final int iconId; |
| 1017 | |
| 1018 | ResourceName(String _packageName, int _iconId) { |
| 1019 | packageName = _packageName; |
| 1020 | iconId = _iconId; |
| 1021 | } |
| 1022 | |
| 1023 | ResourceName(ApplicationInfo aInfo, int _iconId) { |
| 1024 | this(aInfo.packageName, _iconId); |
| 1025 | } |
| 1026 | |
| 1027 | ResourceName(ComponentInfo cInfo, int _iconId) { |
| 1028 | this(cInfo.applicationInfo.packageName, _iconId); |
| 1029 | } |
| 1030 | |
| 1031 | ResourceName(ResolveInfo rInfo, int _iconId) { |
| 1032 | this(rInfo.activityInfo.applicationInfo.packageName, _iconId); |
| 1033 | } |
| 1034 | |
| 1035 | @Override |
| 1036 | public boolean equals(Object o) { |
| 1037 | if (this == o) return true; |
| 1038 | if (o == null || getClass() != o.getClass()) return false; |
| 1039 | |
| 1040 | ResourceName that = (ResourceName) o; |
| 1041 | |
| 1042 | if (iconId != that.iconId) return false; |
| 1043 | return !(packageName != null ? |
| 1044 | !packageName.equals(that.packageName) : that.packageName != null); |
| 1045 | |
| 1046 | } |
| 1047 | |
| 1048 | @Override |
| 1049 | public int hashCode() { |
| 1050 | int result; |
| 1051 | result = packageName.hashCode(); |
| 1052 | result = 31 * result + iconId; |
| 1053 | return result; |
| 1054 | } |
| 1055 | |
| 1056 | @Override |
| 1057 | public String toString() { |
| 1058 | return "{ResourceName " + packageName + " / " + iconId + "}"; |
| 1059 | } |
| 1060 | } |
| 1061 | |
| 1062 | private CharSequence getCachedString(ResourceName name) { |
| 1063 | synchronized (sSync) { |
| 1064 | WeakReference<CharSequence> wr = sStringCache.get(name); |
| 1065 | if (wr != null) { // we have the activity |
| 1066 | CharSequence cs = wr.get(); |
| 1067 | if (cs != null) { |
| 1068 | return cs; |
| 1069 | } |
| 1070 | // our entry has been purged |
| 1071 | sStringCache.remove(name); |
| 1072 | } |
| 1073 | } |
| 1074 | return null; |
| 1075 | } |
| 1076 | |
| 1077 | private void putCachedString(ResourceName name, CharSequence cs) { |
| 1078 | synchronized (sSync) { |
| 1079 | sStringCache.put(name, new WeakReference<CharSequence>(cs)); |
| 1080 | } |
| 1081 | } |
| 1082 | |
| 1083 | @Override |
| 1084 | public CharSequence getText(String packageName, int resid, |
| 1085 | ApplicationInfo appInfo) { |
| 1086 | ResourceName name = new ResourceName(packageName, resid); |
| 1087 | CharSequence text = getCachedString(name); |
| 1088 | if (text != null) { |
| 1089 | return text; |
| 1090 | } |
| 1091 | if (appInfo == null) { |
| 1092 | try { |
| 1093 | appInfo = getApplicationInfo(packageName, 0); |
| 1094 | } catch (NameNotFoundException e) { |
| 1095 | return null; |
| 1096 | } |
| 1097 | } |
| 1098 | try { |
| 1099 | Resources r = getResourcesForApplication(appInfo); |
| 1100 | text = r.getText(resid); |
| 1101 | putCachedString(name, text); |
| 1102 | return text; |
| 1103 | } catch (NameNotFoundException e) { |
| 1104 | Log.w("PackageManager", "Failure retrieving resources for" |
| 1105 | + appInfo.packageName); |
| 1106 | } catch (RuntimeException e) { |
| 1107 | // If an exception was thrown, fall through to return |
| 1108 | // default icon. |
| 1109 | Log.w("PackageManager", "Failure retrieving text 0x" |
| 1110 | + Integer.toHexString(resid) + " in package " |
| 1111 | + packageName, e); |
| 1112 | } |
| 1113 | return null; |
| 1114 | } |
| 1115 | |
| 1116 | @Override |
| 1117 | public XmlResourceParser getXml(String packageName, int resid, |
| 1118 | ApplicationInfo appInfo) { |
| 1119 | if (appInfo == null) { |
| 1120 | try { |
| 1121 | appInfo = getApplicationInfo(packageName, 0); |
| 1122 | } catch (NameNotFoundException e) { |
| 1123 | return null; |
| 1124 | } |
| 1125 | } |
| 1126 | try { |
| 1127 | Resources r = getResourcesForApplication(appInfo); |
| 1128 | return r.getXml(resid); |
| 1129 | } catch (RuntimeException e) { |
| 1130 | // If an exception was thrown, fall through to return |
| 1131 | // default icon. |
| 1132 | Log.w("PackageManager", "Failure retrieving xml 0x" |
| 1133 | + Integer.toHexString(resid) + " in package " |
| 1134 | + packageName, e); |
| 1135 | } catch (NameNotFoundException e) { |
Alon Albert | 3fa51e3 | 2010-11-11 09:24:04 -0800 | [diff] [blame] | 1136 | Log.w("PackageManager", "Failure retrieving resources for " |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 1137 | + appInfo.packageName); |
| 1138 | } |
| 1139 | return null; |
| 1140 | } |
| 1141 | |
| 1142 | @Override |
| 1143 | public CharSequence getApplicationLabel(ApplicationInfo info) { |
| 1144 | return info.loadLabel(this); |
| 1145 | } |
| 1146 | |
| 1147 | @Override |
| 1148 | public void installPackage(Uri packageURI, IPackageInstallObserver observer, int flags, |
| 1149 | String installerPackageName) { |
Jeff Sharkey | 513a074 | 2014-07-08 17:10:32 -0700 | [diff] [blame] | 1150 | final VerificationParams verificationParams = new VerificationParams(null, null, |
| 1151 | null, VerificationParams.NO_UID, null); |
| 1152 | installCommon(packageURI, new LegacyPackageInstallObserver(observer), flags, |
| 1153 | installerPackageName, verificationParams, null); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 1154 | } |
| 1155 | |
| 1156 | @Override |
Kenny Root | 5ab2157 | 2011-07-27 11:11:19 -0700 | [diff] [blame] | 1157 | public void installPackageWithVerification(Uri packageURI, IPackageInstallObserver observer, |
| 1158 | int flags, String installerPackageName, Uri verificationURI, |
Rich Cannings | e1d7c71 | 2012-08-08 12:46:06 -0700 | [diff] [blame] | 1159 | ManifestDigest manifestDigest, ContainerEncryptionParams encryptionParams) { |
Jeff Sharkey | 513a074 | 2014-07-08 17:10:32 -0700 | [diff] [blame] | 1160 | final VerificationParams verificationParams = new VerificationParams(verificationURI, null, |
| 1161 | null, VerificationParams.NO_UID, manifestDigest); |
| 1162 | installCommon(packageURI, new LegacyPackageInstallObserver(observer), flags, |
| 1163 | installerPackageName, verificationParams, encryptionParams); |
Kenny Root | 5ab2157 | 2011-07-27 11:11:19 -0700 | [diff] [blame] | 1164 | } |
| 1165 | |
| 1166 | @Override |
John Spurlock | 8a985d2 | 2014-02-25 09:40:05 -0500 | [diff] [blame] | 1167 | public void installPackageWithVerificationAndEncryption(Uri packageURI, |
rich cannings | 706e8ba | 2012-08-20 13:20:14 -0700 | [diff] [blame] | 1168 | IPackageInstallObserver observer, int flags, String installerPackageName, |
| 1169 | VerificationParams verificationParams, ContainerEncryptionParams encryptionParams) { |
Jeff Sharkey | 513a074 | 2014-07-08 17:10:32 -0700 | [diff] [blame] | 1170 | installCommon(packageURI, new LegacyPackageInstallObserver(observer), flags, |
| 1171 | installerPackageName, verificationParams, encryptionParams); |
Christopher Tate | f1977b4 | 2014-03-24 16:25:51 -0700 | [diff] [blame] | 1172 | } |
| 1173 | |
Christopher Tate | f1977b4 | 2014-03-24 16:25:51 -0700 | [diff] [blame] | 1174 | @Override |
| 1175 | public void installPackage(Uri packageURI, PackageInstallObserver observer, |
| 1176 | int flags, String installerPackageName) { |
Jeff Sharkey | 513a074 | 2014-07-08 17:10:32 -0700 | [diff] [blame] | 1177 | final VerificationParams verificationParams = new VerificationParams(null, null, |
| 1178 | null, VerificationParams.NO_UID, null); |
| 1179 | installCommon(packageURI, observer, flags, installerPackageName, verificationParams, null); |
Christopher Tate | f1977b4 | 2014-03-24 16:25:51 -0700 | [diff] [blame] | 1180 | } |
| 1181 | |
| 1182 | @Override |
| 1183 | public void installPackageWithVerification(Uri packageURI, |
| 1184 | PackageInstallObserver observer, int flags, String installerPackageName, |
| 1185 | Uri verificationURI, ManifestDigest manifestDigest, |
| 1186 | ContainerEncryptionParams encryptionParams) { |
Jeff Sharkey | 513a074 | 2014-07-08 17:10:32 -0700 | [diff] [blame] | 1187 | final VerificationParams verificationParams = new VerificationParams(verificationURI, null, |
| 1188 | null, VerificationParams.NO_UID, manifestDigest); |
| 1189 | installCommon(packageURI, observer, flags, installerPackageName, verificationParams, |
| 1190 | encryptionParams); |
Christopher Tate | f1977b4 | 2014-03-24 16:25:51 -0700 | [diff] [blame] | 1191 | } |
| 1192 | |
| 1193 | @Override |
| 1194 | public void installPackageWithVerificationAndEncryption(Uri packageURI, |
| 1195 | PackageInstallObserver observer, int flags, String installerPackageName, |
| 1196 | VerificationParams verificationParams, ContainerEncryptionParams encryptionParams) { |
Jeff Sharkey | 513a074 | 2014-07-08 17:10:32 -0700 | [diff] [blame] | 1197 | installCommon(packageURI, observer, flags, installerPackageName, verificationParams, |
| 1198 | encryptionParams); |
| 1199 | } |
| 1200 | |
| 1201 | private void installCommon(Uri packageURI, |
| 1202 | PackageInstallObserver observer, int flags, String installerPackageName, |
| 1203 | VerificationParams verificationParams, ContainerEncryptionParams encryptionParams) { |
| 1204 | if (!"file".equals(packageURI.getScheme())) { |
| 1205 | throw new UnsupportedOperationException("Only file:// URIs are supported"); |
| 1206 | } |
| 1207 | if (encryptionParams != null) { |
| 1208 | throw new UnsupportedOperationException("ContainerEncryptionParams not supported"); |
| 1209 | } |
| 1210 | |
| 1211 | final String originPath = packageURI.getPath(); |
Christopher Tate | f1977b4 | 2014-03-24 16:25:51 -0700 | [diff] [blame] | 1212 | try { |
Jeff Sharkey | 513a074 | 2014-07-08 17:10:32 -0700 | [diff] [blame] | 1213 | mPM.installPackage(originPath, observer.getBinder(), flags, installerPackageName, |
| 1214 | verificationParams, null); |
| 1215 | } catch (RemoteException ignored) { |
rich cannings | 706e8ba | 2012-08-20 13:20:14 -0700 | [diff] [blame] | 1216 | } |
| 1217 | } |
| 1218 | |
| 1219 | @Override |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 1220 | public int installExistingPackage(String packageName) |
| 1221 | throws NameNotFoundException { |
| 1222 | try { |
Amith Yamasani | 67df64b | 2012-12-14 12:09:36 -0800 | [diff] [blame] | 1223 | int res = mPM.installExistingPackageAsUser(packageName, UserHandle.myUserId()); |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 1224 | if (res == INSTALL_FAILED_INVALID_URI) { |
| 1225 | throw new NameNotFoundException("Package " + packageName + " doesn't exist"); |
| 1226 | } |
| 1227 | return res; |
| 1228 | } catch (RemoteException e) { |
| 1229 | // Should never happen! |
| 1230 | throw new NameNotFoundException("Package " + packageName + " doesn't exist"); |
| 1231 | } |
| 1232 | } |
| 1233 | |
| 1234 | @Override |
Kenny Root | 3a9b5fb | 2011-09-20 14:15:38 -0700 | [diff] [blame] | 1235 | public void verifyPendingInstall(int id, int response) { |
Kenny Root | 5ab2157 | 2011-07-27 11:11:19 -0700 | [diff] [blame] | 1236 | try { |
Kenny Root | 3a9b5fb | 2011-09-20 14:15:38 -0700 | [diff] [blame] | 1237 | mPM.verifyPendingInstall(id, response); |
Kenny Root | 5ab2157 | 2011-07-27 11:11:19 -0700 | [diff] [blame] | 1238 | } catch (RemoteException e) { |
| 1239 | // Should never happen! |
| 1240 | } |
| 1241 | } |
| 1242 | |
| 1243 | @Override |
rich cannings | d9ef3e5 | 2012-08-22 14:28:05 -0700 | [diff] [blame] | 1244 | public void extendVerificationTimeout(int id, int verificationCodeAtTimeout, |
| 1245 | long millisecondsToDelay) { |
| 1246 | try { |
| 1247 | mPM.extendVerificationTimeout(id, verificationCodeAtTimeout, millisecondsToDelay); |
| 1248 | } catch (RemoteException e) { |
| 1249 | // Should never happen! |
| 1250 | } |
| 1251 | } |
| 1252 | |
| 1253 | @Override |
Dianne Hackborn | 880119b | 2010-11-18 22:26:40 -0800 | [diff] [blame] | 1254 | public void setInstallerPackageName(String targetPackage, |
| 1255 | String installerPackageName) { |
| 1256 | try { |
| 1257 | mPM.setInstallerPackageName(targetPackage, installerPackageName); |
| 1258 | } catch (RemoteException e) { |
| 1259 | // Should never happen! |
| 1260 | } |
| 1261 | } |
| 1262 | |
| 1263 | @Override |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 1264 | public void movePackage(String packageName, IPackageMoveObserver observer, int flags) { |
| 1265 | try { |
| 1266 | mPM.movePackage(packageName, observer, flags); |
| 1267 | } catch (RemoteException e) { |
| 1268 | // Should never happen! |
| 1269 | } |
| 1270 | } |
| 1271 | |
| 1272 | @Override |
| 1273 | public String getInstallerPackageName(String packageName) { |
| 1274 | try { |
| 1275 | return mPM.getInstallerPackageName(packageName); |
| 1276 | } catch (RemoteException e) { |
| 1277 | // Should never happen! |
| 1278 | } |
| 1279 | return null; |
| 1280 | } |
| 1281 | |
| 1282 | @Override |
| 1283 | public void deletePackage(String packageName, IPackageDeleteObserver observer, int flags) { |
| 1284 | try { |
Amith Yamasani | 67df64b | 2012-12-14 12:09:36 -0800 | [diff] [blame] | 1285 | mPM.deletePackageAsUser(packageName, observer, UserHandle.myUserId(), flags); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 1286 | } catch (RemoteException e) { |
| 1287 | // Should never happen! |
| 1288 | } |
| 1289 | } |
| 1290 | @Override |
| 1291 | public void clearApplicationUserData(String packageName, |
| 1292 | IPackageDataObserver observer) { |
| 1293 | try { |
Jeff Sharkey | ded653b | 2012-09-27 19:09:24 -0700 | [diff] [blame] | 1294 | mPM.clearApplicationUserData(packageName, observer, mContext.getUserId()); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 1295 | } catch (RemoteException e) { |
| 1296 | // Should never happen! |
| 1297 | } |
| 1298 | } |
| 1299 | @Override |
| 1300 | public void deleteApplicationCacheFiles(String packageName, |
| 1301 | IPackageDataObserver observer) { |
| 1302 | try { |
| 1303 | mPM.deleteApplicationCacheFiles(packageName, observer); |
| 1304 | } catch (RemoteException e) { |
| 1305 | // Should never happen! |
| 1306 | } |
| 1307 | } |
| 1308 | @Override |
| 1309 | public void freeStorageAndNotify(long idealStorageSize, IPackageDataObserver observer) { |
| 1310 | try { |
| 1311 | mPM.freeStorageAndNotify(idealStorageSize, observer); |
| 1312 | } catch (RemoteException e) { |
| 1313 | // Should never happen! |
| 1314 | } |
| 1315 | } |
| 1316 | |
| 1317 | @Override |
| 1318 | public void freeStorage(long freeStorageSize, IntentSender pi) { |
| 1319 | try { |
| 1320 | mPM.freeStorage(freeStorageSize, pi); |
| 1321 | } catch (RemoteException e) { |
| 1322 | // Should never happen! |
| 1323 | } |
| 1324 | } |
| 1325 | |
| 1326 | @Override |
Dianne Hackborn | 0c38049 | 2012-08-20 17:23:30 -0700 | [diff] [blame] | 1327 | public void getPackageSizeInfo(String packageName, int userHandle, |
| 1328 | IPackageStatsObserver observer) { |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 1329 | try { |
Dianne Hackborn | 0c38049 | 2012-08-20 17:23:30 -0700 | [diff] [blame] | 1330 | mPM.getPackageSizeInfo(packageName, userHandle, observer); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 1331 | } catch (RemoteException e) { |
| 1332 | // Should never happen! |
| 1333 | } |
| 1334 | } |
| 1335 | @Override |
| 1336 | public void addPackageToPreferred(String packageName) { |
| 1337 | try { |
| 1338 | mPM.addPackageToPreferred(packageName); |
| 1339 | } catch (RemoteException e) { |
| 1340 | // Should never happen! |
| 1341 | } |
| 1342 | } |
| 1343 | |
| 1344 | @Override |
| 1345 | public void removePackageFromPreferred(String packageName) { |
| 1346 | try { |
| 1347 | mPM.removePackageFromPreferred(packageName); |
| 1348 | } catch (RemoteException e) { |
| 1349 | // Should never happen! |
| 1350 | } |
| 1351 | } |
| 1352 | |
| 1353 | @Override |
| 1354 | public List<PackageInfo> getPreferredPackages(int flags) { |
| 1355 | try { |
| 1356 | return mPM.getPreferredPackages(flags); |
| 1357 | } catch (RemoteException e) { |
| 1358 | // Should never happen! |
| 1359 | } |
| 1360 | return new ArrayList<PackageInfo>(); |
| 1361 | } |
| 1362 | |
| 1363 | @Override |
| 1364 | public void addPreferredActivity(IntentFilter filter, |
| 1365 | int match, ComponentName[] set, ComponentName activity) { |
| 1366 | try { |
Jeff Sharkey | ded653b | 2012-09-27 19:09:24 -0700 | [diff] [blame] | 1367 | mPM.addPreferredActivity(filter, match, set, activity, mContext.getUserId()); |
Amith Yamasani | a3f133a | 2012-08-09 17:11:28 -0700 | [diff] [blame] | 1368 | } catch (RemoteException e) { |
| 1369 | // Should never happen! |
| 1370 | } |
| 1371 | } |
| 1372 | |
| 1373 | @Override |
| 1374 | public void addPreferredActivity(IntentFilter filter, int match, |
| 1375 | ComponentName[] set, ComponentName activity, int userId) { |
| 1376 | try { |
| 1377 | mPM.addPreferredActivity(filter, match, set, activity, userId); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 1378 | } catch (RemoteException e) { |
| 1379 | // Should never happen! |
| 1380 | } |
| 1381 | } |
| 1382 | |
| 1383 | @Override |
| 1384 | public void replacePreferredActivity(IntentFilter filter, |
| 1385 | int match, ComponentName[] set, ComponentName activity) { |
| 1386 | try { |
| 1387 | mPM.replacePreferredActivity(filter, match, set, activity); |
| 1388 | } catch (RemoteException e) { |
| 1389 | // Should never happen! |
| 1390 | } |
| 1391 | } |
| 1392 | |
| 1393 | @Override |
| 1394 | public void clearPackagePreferredActivities(String packageName) { |
| 1395 | try { |
| 1396 | mPM.clearPackagePreferredActivities(packageName); |
| 1397 | } catch (RemoteException e) { |
| 1398 | // Should never happen! |
| 1399 | } |
| 1400 | } |
| 1401 | |
| 1402 | @Override |
| 1403 | public int getPreferredActivities(List<IntentFilter> outFilters, |
| 1404 | List<ComponentName> outActivities, String packageName) { |
| 1405 | try { |
| 1406 | return mPM.getPreferredActivities(outFilters, outActivities, packageName); |
| 1407 | } catch (RemoteException e) { |
| 1408 | // Should never happen! |
| 1409 | } |
| 1410 | return 0; |
| 1411 | } |
| 1412 | |
| 1413 | @Override |
Christopher Tate | a2a0850d | 2013-09-05 16:38:58 -0700 | [diff] [blame] | 1414 | public ComponentName getHomeActivities(List<ResolveInfo> outActivities) { |
| 1415 | try { |
| 1416 | return mPM.getHomeActivities(outActivities); |
| 1417 | } catch (RemoteException e) { |
| 1418 | // Should never happen! |
| 1419 | } |
| 1420 | return null; |
| 1421 | } |
| 1422 | |
| 1423 | @Override |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 1424 | public void setComponentEnabledSetting(ComponentName componentName, |
| 1425 | int newState, int flags) { |
| 1426 | try { |
Jeff Sharkey | ded653b | 2012-09-27 19:09:24 -0700 | [diff] [blame] | 1427 | mPM.setComponentEnabledSetting(componentName, newState, flags, mContext.getUserId()); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 1428 | } catch (RemoteException e) { |
| 1429 | // Should never happen! |
| 1430 | } |
| 1431 | } |
| 1432 | |
| 1433 | @Override |
| 1434 | public int getComponentEnabledSetting(ComponentName componentName) { |
| 1435 | try { |
Jeff Sharkey | ded653b | 2012-09-27 19:09:24 -0700 | [diff] [blame] | 1436 | return mPM.getComponentEnabledSetting(componentName, mContext.getUserId()); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 1437 | } catch (RemoteException e) { |
| 1438 | // Should never happen! |
| 1439 | } |
| 1440 | return PackageManager.COMPONENT_ENABLED_STATE_DEFAULT; |
| 1441 | } |
| 1442 | |
| 1443 | @Override |
| 1444 | public void setApplicationEnabledSetting(String packageName, |
| 1445 | int newState, int flags) { |
| 1446 | try { |
Dianne Hackborn | 3fa3c28a | 2013-03-26 16:15:41 -0700 | [diff] [blame] | 1447 | mPM.setApplicationEnabledSetting(packageName, newState, flags, |
Dianne Hackborn | 95d7853 | 2013-09-11 09:51:14 -0700 | [diff] [blame] | 1448 | mContext.getUserId(), mContext.getOpPackageName()); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 1449 | } catch (RemoteException e) { |
| 1450 | // Should never happen! |
| 1451 | } |
| 1452 | } |
| 1453 | |
| 1454 | @Override |
| 1455 | public int getApplicationEnabledSetting(String packageName) { |
| 1456 | try { |
Jeff Sharkey | ded653b | 2012-09-27 19:09:24 -0700 | [diff] [blame] | 1457 | return mPM.getApplicationEnabledSetting(packageName, mContext.getUserId()); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 1458 | } catch (RemoteException e) { |
| 1459 | // Should never happen! |
| 1460 | } |
| 1461 | return PackageManager.COMPONENT_ENABLED_STATE_DEFAULT; |
| 1462 | } |
| 1463 | |
Amith Yamasani | 655d0e2 | 2013-06-12 14:19:10 -0700 | [diff] [blame] | 1464 | @Override |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 1465 | public boolean setApplicationHiddenSettingAsUser(String packageName, boolean hidden, |
Amith Yamasani | 655d0e2 | 2013-06-12 14:19:10 -0700 | [diff] [blame] | 1466 | UserHandle user) { |
| 1467 | try { |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 1468 | return mPM.setApplicationHiddenSettingAsUser(packageName, hidden, |
Amith Yamasani | 655d0e2 | 2013-06-12 14:19:10 -0700 | [diff] [blame] | 1469 | user.getIdentifier()); |
| 1470 | } catch (RemoteException re) { |
| 1471 | // Should never happen! |
| 1472 | } |
| 1473 | return false; |
| 1474 | } |
| 1475 | |
| 1476 | @Override |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 1477 | public boolean getApplicationHiddenSettingAsUser(String packageName, UserHandle user) { |
Amith Yamasani | 655d0e2 | 2013-06-12 14:19:10 -0700 | [diff] [blame] | 1478 | try { |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 1479 | return mPM.getApplicationHiddenSettingAsUser(packageName, user.getIdentifier()); |
Amith Yamasani | 655d0e2 | 2013-06-12 14:19:10 -0700 | [diff] [blame] | 1480 | } catch (RemoteException re) { |
| 1481 | // Should never happen! |
| 1482 | } |
| 1483 | return false; |
| 1484 | } |
| 1485 | |
dcashman | 9d2f441 | 2014-06-09 09:27:54 -0700 | [diff] [blame] | 1486 | @Override |
| 1487 | public KeySet getKeySetByAlias(String packageName, String alias) { |
| 1488 | Preconditions.checkNotNull(packageName); |
| 1489 | Preconditions.checkNotNull(alias); |
| 1490 | IBinder keySetToken; |
| 1491 | try { |
| 1492 | keySetToken = mPM.getKeySetByAlias(packageName, alias); |
| 1493 | } catch (RemoteException e) { |
| 1494 | return null; |
| 1495 | } |
| 1496 | if (keySetToken == null) { |
| 1497 | return null; |
| 1498 | } |
| 1499 | return new KeySet(keySetToken); |
| 1500 | } |
| 1501 | |
| 1502 | @Override |
| 1503 | public KeySet getSigningKeySet(String packageName) { |
| 1504 | Preconditions.checkNotNull(packageName); |
| 1505 | IBinder keySetToken; |
| 1506 | try { |
| 1507 | keySetToken = mPM.getSigningKeySet(packageName); |
| 1508 | } catch (RemoteException e) { |
| 1509 | return null; |
| 1510 | } |
| 1511 | if (keySetToken == null) { |
| 1512 | return null; |
| 1513 | } |
| 1514 | return new KeySet(keySetToken); |
| 1515 | } |
| 1516 | |
| 1517 | |
| 1518 | @Override |
| 1519 | public boolean isSignedBy(String packageName, KeySet ks) { |
| 1520 | Preconditions.checkNotNull(packageName); |
| 1521 | Preconditions.checkNotNull(ks); |
| 1522 | IBinder keySetToken = ks.getToken(); |
| 1523 | try { |
| 1524 | return mPM.isPackageSignedByKeySet(packageName, keySetToken); |
| 1525 | } catch (RemoteException e) { |
| 1526 | return false; |
| 1527 | } |
| 1528 | } |
| 1529 | |
| 1530 | @Override |
| 1531 | public boolean isSignedByExactly(String packageName, KeySet ks) { |
| 1532 | Preconditions.checkNotNull(packageName); |
| 1533 | Preconditions.checkNotNull(ks); |
| 1534 | IBinder keySetToken = ks.getToken(); |
| 1535 | try { |
| 1536 | return mPM.isPackageSignedByKeySetExactly(packageName, keySetToken); |
| 1537 | } catch (RemoteException e) { |
| 1538 | return false; |
| 1539 | } |
| 1540 | } |
| 1541 | |
Kenny Root | 0aaa0d9 | 2011-09-12 16:42:55 -0700 | [diff] [blame] | 1542 | /** |
| 1543 | * @hide |
| 1544 | */ |
| 1545 | @Override |
| 1546 | public VerifierDeviceIdentity getVerifierDeviceIdentity() { |
| 1547 | try { |
| 1548 | return mPM.getVerifierDeviceIdentity(); |
| 1549 | } catch (RemoteException e) { |
| 1550 | // Should never happen! |
| 1551 | } |
| 1552 | return null; |
| 1553 | } |
| 1554 | |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 1555 | @Override |
Jeff Sharkey | 16c8e3f | 2014-07-24 17:08:17 -0700 | [diff] [blame] | 1556 | public PackageInstaller getPackageInstaller() { |
| 1557 | synchronized (mLock) { |
| 1558 | if (mInstaller == null) { |
| 1559 | try { |
| 1560 | mInstaller = new PackageInstaller(this, mPM.getPackageInstaller(), |
| 1561 | mContext.getPackageName(), mContext.getUserId()); |
| 1562 | } catch (RemoteException e) { |
| 1563 | throw e.rethrowAsRuntimeException(); |
| 1564 | } |
| 1565 | } |
| 1566 | return mInstaller; |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 1567 | } |
| 1568 | } |
| 1569 | |
Jeff Sharkey | 6c833e0 | 2014-07-14 22:44:30 -0700 | [diff] [blame] | 1570 | @Override |
| 1571 | public boolean isPackageAvailable(String packageName) { |
| 1572 | try { |
| 1573 | return mPM.isPackageAvailable(packageName, mContext.getUserId()); |
| 1574 | } catch (RemoteException e) { |
| 1575 | throw e.rethrowAsRuntimeException(); |
| 1576 | } |
| 1577 | } |
| 1578 | |
Nicolas Prevot | c79586e | 2014-05-06 12:47:57 +0100 | [diff] [blame] | 1579 | /** |
| 1580 | * @hide |
| 1581 | */ |
| 1582 | @Override |
Nicolas Prevot | 63798c5 | 2014-05-27 13:22:38 +0100 | [diff] [blame] | 1583 | public void addCrossProfileIntentFilter(IntentFilter filter, int sourceUserId, int targetUserId, |
| 1584 | int flags) { |
Nicolas Prevot | c79586e | 2014-05-06 12:47:57 +0100 | [diff] [blame] | 1585 | try { |
Nicolas Prevot | 3f7777f | 2014-07-24 15:58:39 +0100 | [diff] [blame] | 1586 | mPM.addCrossProfileIntentFilter(filter, mContext.getOpPackageName(), |
| 1587 | mContext.getUserId(), sourceUserId, targetUserId, flags); |
Nicolas Prevot | c79586e | 2014-05-06 12:47:57 +0100 | [diff] [blame] | 1588 | } catch (RemoteException e) { |
| 1589 | // Should never happen! |
| 1590 | } |
| 1591 | } |
| 1592 | |
| 1593 | /** |
| 1594 | * @hide |
| 1595 | */ |
Alexandra Gherghina | 6e2ae25 | 2014-06-12 16:03:58 +0100 | [diff] [blame] | 1596 | public void addCrossProfileIntentsForPackage(String packageName, |
| 1597 | int sourceUserId, int targetUserId) { |
| 1598 | try { |
| 1599 | mPM.addCrossProfileIntentsForPackage(packageName, sourceUserId, targetUserId); |
| 1600 | } catch (RemoteException e) { |
| 1601 | // Should never happen! |
| 1602 | } |
| 1603 | } |
| 1604 | |
| 1605 | /** |
| 1606 | * @hide |
| 1607 | */ |
Nicolas Prevot | c79586e | 2014-05-06 12:47:57 +0100 | [diff] [blame] | 1608 | @Override |
Nicolas Prevot | 8194899 | 2014-05-16 18:25:26 +0100 | [diff] [blame] | 1609 | public void clearCrossProfileIntentFilters(int sourceUserId) { |
Nicolas Prevot | c79586e | 2014-05-06 12:47:57 +0100 | [diff] [blame] | 1610 | try { |
Nicolas Prevot | 3f7777f | 2014-07-24 15:58:39 +0100 | [diff] [blame] | 1611 | mPM.clearCrossProfileIntentFilters(sourceUserId, mContext.getOpPackageName(), |
| 1612 | mContext.getUserId()); |
Nicolas Prevot | c79586e | 2014-05-06 12:47:57 +0100 | [diff] [blame] | 1613 | } catch (RemoteException e) { |
| 1614 | // Should never happen! |
| 1615 | } |
| 1616 | } |
| 1617 | |
Nicolas Prevot | 88cc346 | 2014-05-14 14:51:48 +0100 | [diff] [blame] | 1618 | /** |
| 1619 | * @hide |
| 1620 | */ |
Nicolas Prevot | 7f7b0c7 | 2014-06-23 15:59:38 +0100 | [diff] [blame] | 1621 | public Drawable loadItemIcon(PackageItemInfo itemInfo, ApplicationInfo appInfo) { |
| 1622 | if (itemInfo.showUserIcon != UserHandle.USER_NULL) { |
| 1623 | return new BitmapDrawable(getUserManager().getUserIcon(itemInfo.showUserIcon)); |
| 1624 | } |
| 1625 | Drawable dr = getDrawable(itemInfo.packageName, itemInfo.icon, appInfo); |
Alexandra Gherghina | a71e390 | 2014-07-25 20:03:47 +0100 | [diff] [blame^] | 1626 | if (dr == null) { |
| 1627 | dr = getDefaultActivityIcon(); |
Nicolas Prevot | 7f7b0c7 | 2014-06-23 15:59:38 +0100 | [diff] [blame] | 1628 | } |
Alexandra Gherghina | a71e390 | 2014-07-25 20:03:47 +0100 | [diff] [blame^] | 1629 | return getUserManager().getBadgedDrawableForUser(dr, |
| 1630 | new UserHandle(mContext.getUserId())); |
Nicolas Prevot | 88cc346 | 2014-05-14 14:51:48 +0100 | [diff] [blame] | 1631 | } |
| 1632 | |
Jeff Sharkey | 513a074 | 2014-07-08 17:10:32 -0700 | [diff] [blame] | 1633 | private static class LegacyPackageInstallObserver extends PackageInstallObserver { |
| 1634 | private final IPackageInstallObserver mLegacy; |
| 1635 | |
| 1636 | public LegacyPackageInstallObserver(IPackageInstallObserver legacy) { |
| 1637 | mLegacy = legacy; |
| 1638 | } |
| 1639 | |
| 1640 | @Override |
| 1641 | public void packageInstalled(String basePackageName, Bundle extras, int returnCode) { |
| 1642 | try { |
| 1643 | mLegacy.packageInstalled(basePackageName, returnCode); |
| 1644 | } catch (RemoteException ignored) { |
| 1645 | } |
| 1646 | } |
| 1647 | } |
| 1648 | |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 1649 | private final ContextImpl mContext; |
| 1650 | private final IPackageManager mPM; |
| 1651 | |
| 1652 | private static final Object sSync = new Object(); |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 1653 | private static ArrayMap<ResourceName, WeakReference<Drawable.ConstantState>> sIconCache |
| 1654 | = new ArrayMap<ResourceName, WeakReference<Drawable.ConstantState>>(); |
| 1655 | private static ArrayMap<ResourceName, WeakReference<CharSequence>> sStringCache |
| 1656 | = new ArrayMap<ResourceName, WeakReference<CharSequence>>(); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 1657 | } |