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