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