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