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