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