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; |
Yao Chen | 022b8ea | 2016-12-16 11:03:28 -0800 | [diff] [blame] | 26 | import android.content.Context; |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 27 | import android.content.Intent; |
| 28 | import android.content.IntentFilter; |
| 29 | import android.content.IntentSender; |
| 30 | import android.content.pm.ActivityInfo; |
| 31 | import android.content.pm.ApplicationInfo; |
Todd Kennedy | 9106c64 | 2017-02-08 14:16:53 -0800 | [diff] [blame] | 32 | import android.content.pm.ChangedPackages; |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 33 | import android.content.pm.ComponentInfo; |
Svetoslav Ganov | 096d304 | 2017-01-30 16:34:13 -0800 | [diff] [blame] | 34 | import android.content.pm.InstantAppInfo; |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 35 | import android.content.pm.FeatureInfo; |
Svetoslav | f7c06eb | 2015-06-10 18:43:22 -0700 | [diff] [blame] | 36 | import android.content.pm.IOnPermissionsChangeListener; |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 37 | import android.content.pm.IPackageDataObserver; |
| 38 | import android.content.pm.IPackageDeleteObserver; |
| 39 | import android.content.pm.IPackageInstallObserver; |
| 40 | import android.content.pm.IPackageManager; |
| 41 | import android.content.pm.IPackageMoveObserver; |
| 42 | import android.content.pm.IPackageStatsObserver; |
| 43 | import android.content.pm.InstrumentationInfo; |
Fabrice Di Meglio | 1c1b471 | 2014-11-19 17:12:32 -0800 | [diff] [blame] | 44 | import android.content.pm.IntentFilterVerificationInfo; |
dcashman | 9d2f441 | 2014-06-09 09:27:54 -0700 | [diff] [blame] | 45 | import android.content.pm.KeySet; |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 46 | import android.content.pm.PackageInfo; |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 47 | import android.content.pm.PackageInstaller; |
Nicolas Prevot | 7f7b0c7 | 2014-06-23 15:59:38 +0100 | [diff] [blame] | 48 | import android.content.pm.PackageItemInfo; |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 49 | import android.content.pm.PackageManager; |
Kenny Root | e6cd0c7 | 2011-05-19 12:48:14 -0700 | [diff] [blame] | 50 | import android.content.pm.ParceledListSlice; |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 51 | import android.content.pm.PermissionGroupInfo; |
| 52 | import android.content.pm.PermissionInfo; |
| 53 | import android.content.pm.ProviderInfo; |
| 54 | import android.content.pm.ResolveInfo; |
| 55 | import android.content.pm.ServiceInfo; |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 56 | import android.content.pm.SharedLibraryInfo; |
Kenny Root | 0aaa0d9 | 2011-09-12 16:42:55 -0700 | [diff] [blame] | 57 | import android.content.pm.VerifierDeviceIdentity; |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 58 | import android.content.pm.VersionedPackage; |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 59 | import android.content.res.Resources; |
| 60 | import android.content.res.XmlResourceParser; |
Svetoslav | c7d62f0 | 2014-09-04 15:39:54 -0700 | [diff] [blame] | 61 | import android.graphics.Bitmap; |
| 62 | import android.graphics.Canvas; |
| 63 | import android.graphics.Rect; |
Nicolas Prevot | 7f7b0c7 | 2014-06-23 15:59:38 +0100 | [diff] [blame] | 64 | import android.graphics.drawable.BitmapDrawable; |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 65 | import android.graphics.drawable.Drawable; |
Kenny Guy | 02c8990 | 2016-11-15 19:36:38 +0000 | [diff] [blame] | 66 | import android.graphics.drawable.LayerDrawable; |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 67 | import android.net.Uri; |
Jeff Sharkey | e6306c4 | 2017-03-07 21:03:18 -0700 | [diff] [blame] | 68 | import android.os.Build; |
Jeff Sharkey | 50a0545 | 2015-04-29 11:24:52 -0700 | [diff] [blame] | 69 | import android.os.Bundle; |
Jeff Sharkey | 620b32b | 2015-04-23 19:36:02 -0700 | [diff] [blame] | 70 | import android.os.Handler; |
| 71 | import android.os.Looper; |
| 72 | import android.os.Message; |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 73 | import android.os.Process; |
| 74 | import android.os.RemoteException; |
Jeff Sharkey | b2b9ab8 | 2015-04-05 21:10:42 -0700 | [diff] [blame] | 75 | import android.os.SystemProperties; |
Amith Yamasani | 67df64b | 2012-12-14 12:09:36 -0800 | [diff] [blame] | 76 | import android.os.UserHandle; |
Nicolas Prevot | 88cc346 | 2014-05-14 14:51:48 +0100 | [diff] [blame] | 77 | import android.os.UserManager; |
Jeff Sharkey | e2d45be | 2015-04-15 17:14:12 -0700 | [diff] [blame] | 78 | import android.os.storage.StorageManager; |
| 79 | import android.os.storage.VolumeInfo; |
Todd Kennedy | f39ca8f | 2015-08-07 14:15:07 -0700 | [diff] [blame] | 80 | import android.provider.Settings; |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 81 | import android.util.ArrayMap; |
Sunny Goyal | bab3075 | 2017-04-12 15:36:42 -0700 | [diff] [blame] | 82 | import android.util.IconDrawableFactory; |
| 83 | import android.util.LauncherIcons; |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 84 | import android.util.Log; |
Jeff Brown | a492c3a | 2012-08-23 19:48:44 -0700 | [diff] [blame] | 85 | import android.view.Display; |
Jeff Sharkey | b2b9ab8 | 2015-04-05 21:10:42 -0700 | [diff] [blame] | 86 | |
| 87 | import dalvik.system.VMRuntime; |
Jeff Sharkey | 16c8e3f | 2014-07-24 17:08:17 -0700 | [diff] [blame] | 88 | |
| 89 | import com.android.internal.annotations.GuardedBy; |
Kenny Guy | 02c8990 | 2016-11-15 19:36:38 +0000 | [diff] [blame] | 90 | import com.android.internal.annotations.VisibleForTesting; |
Jeff Sharkey | b36586a | 2015-04-27 08:42:28 -0700 | [diff] [blame] | 91 | import com.android.internal.os.SomeArgs; |
dcashman | 9d2f441 | 2014-06-09 09:27:54 -0700 | [diff] [blame] | 92 | import com.android.internal.util.Preconditions; |
Alexandra Gherghina | 64d4dca | 2014-08-28 18:26:56 +0100 | [diff] [blame] | 93 | import com.android.internal.util.UserIcons; |
Svet Ganov | 2acf063 | 2015-11-24 19:10:59 -0800 | [diff] [blame] | 94 | import libcore.util.EmptyArray; |
Jeff Sharkey | 16c8e3f | 2014-07-24 17:08:17 -0700 | [diff] [blame] | 95 | |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 96 | import java.lang.ref.WeakReference; |
| 97 | import java.util.ArrayList; |
Svet Ganov | 2acf063 | 2015-11-24 19:10:59 -0800 | [diff] [blame] | 98 | import java.util.Collections; |
Jeff Sharkey | 620b32b | 2015-04-23 19:36:02 -0700 | [diff] [blame] | 99 | import java.util.Iterator; |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 100 | import java.util.List; |
Svetoslav | f7c06eb | 2015-06-10 18:43:22 -0700 | [diff] [blame] | 101 | import java.util.Map; |
Jeff Sharkey | 620b32b | 2015-04-23 19:36:02 -0700 | [diff] [blame] | 102 | import java.util.Objects; |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 103 | |
Makoto Onuki | cc4bbeb | 2015-09-17 10:28:24 -0700 | [diff] [blame] | 104 | /** @hide */ |
| 105 | public class ApplicationPackageManager extends PackageManager { |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 106 | private static final String TAG = "ApplicationPackageManager"; |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 107 | private final static boolean DEBUG_ICONS = false; |
| 108 | |
Svet Ganov | 2acf063 | 2015-11-24 19:10:59 -0800 | [diff] [blame] | 109 | private static final int DEFAULT_EPHEMERAL_COOKIE_MAX_SIZE_BYTES = 16384; // 16KB |
| 110 | |
Adam Lesinski | d00bb5e | 2014-10-07 12:14:45 -0700 | [diff] [blame] | 111 | // Default flags to use with PackageManager when no flags are given. |
| 112 | private final static int sDefaultFlags = PackageManager.GET_SHARED_LIBRARY_FILES; |
| 113 | |
Jeff Sharkey | 16c8e3f | 2014-07-24 17:08:17 -0700 | [diff] [blame] | 114 | private final Object mLock = new Object(); |
| 115 | |
| 116 | @GuardedBy("mLock") |
| 117 | private UserManager mUserManager; |
| 118 | @GuardedBy("mLock") |
| 119 | private PackageInstaller mInstaller; |
Nicolas Prevot | 7f7b0c7 | 2014-06-23 15:59:38 +0100 | [diff] [blame] | 120 | |
Jeff Sharkey | 620b32b | 2015-04-23 19:36:02 -0700 | [diff] [blame] | 121 | @GuardedBy("mDelegates") |
| 122 | private final ArrayList<MoveCallbackDelegate> mDelegates = new ArrayList<>(); |
| 123 | |
Svet Ganov | f1b7f20 | 2015-07-29 08:33:42 -0700 | [diff] [blame] | 124 | @GuardedBy("mLock") |
| 125 | private String mPermissionsControllerPackageName; |
| 126 | |
Nicolas Prevot | 7f7b0c7 | 2014-06-23 15:59:38 +0100 | [diff] [blame] | 127 | UserManager getUserManager() { |
Jeff Sharkey | 16c8e3f | 2014-07-24 17:08:17 -0700 | [diff] [blame] | 128 | synchronized (mLock) { |
| 129 | if (mUserManager == null) { |
| 130 | mUserManager = UserManager.get(mContext); |
| 131 | } |
| 132 | return mUserManager; |
Nicolas Prevot | 7f7b0c7 | 2014-06-23 15:59:38 +0100 | [diff] [blame] | 133 | } |
Nicolas Prevot | 7f7b0c7 | 2014-06-23 15:59:38 +0100 | [diff] [blame] | 134 | } |
| 135 | |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 136 | @Override |
| 137 | public PackageInfo getPackageInfo(String packageName, int flags) |
| 138 | throws NameNotFoundException { |
Nicolas Prevot | 9a80e53 | 2015-09-23 15:49:28 +0100 | [diff] [blame] | 139 | return getPackageInfoAsUser(packageName, flags, mContext.getUserId()); |
| 140 | } |
| 141 | |
| 142 | @Override |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 143 | public PackageInfo getPackageInfo(VersionedPackage versionedPackage, int flags) |
| 144 | throws NameNotFoundException { |
| 145 | try { |
| 146 | PackageInfo pi = mPM.getPackageInfoVersioned(versionedPackage, flags, |
| 147 | mContext.getUserId()); |
| 148 | if (pi != null) { |
| 149 | return pi; |
| 150 | } |
| 151 | } catch (RemoteException e) { |
| 152 | throw e.rethrowFromSystemServer(); |
| 153 | } |
| 154 | throw new NameNotFoundException(versionedPackage.toString()); |
| 155 | } |
| 156 | |
| 157 | @Override |
Nicolas Prevot | 9a80e53 | 2015-09-23 15:49:28 +0100 | [diff] [blame] | 158 | public PackageInfo getPackageInfoAsUser(String packageName, int flags, int userId) |
| 159 | throws NameNotFoundException { |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 160 | try { |
Nicolas Prevot | 9a80e53 | 2015-09-23 15:49:28 +0100 | [diff] [blame] | 161 | PackageInfo pi = mPM.getPackageInfo(packageName, flags, userId); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 162 | if (pi != null) { |
| 163 | return pi; |
| 164 | } |
| 165 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 166 | throw e.rethrowFromSystemServer(); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 167 | } |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 168 | throw new NameNotFoundException(packageName); |
| 169 | } |
| 170 | |
| 171 | @Override |
| 172 | public String[] currentToCanonicalPackageNames(String[] names) { |
| 173 | try { |
| 174 | return mPM.currentToCanonicalPackageNames(names); |
| 175 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 176 | throw e.rethrowFromSystemServer(); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 177 | } |
| 178 | } |
| 179 | |
| 180 | @Override |
| 181 | public String[] canonicalToCurrentPackageNames(String[] names) { |
| 182 | try { |
| 183 | return mPM.canonicalToCurrentPackageNames(names); |
| 184 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 185 | throw e.rethrowFromSystemServer(); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 186 | } |
| 187 | } |
| 188 | |
| 189 | @Override |
| 190 | public Intent getLaunchIntentForPackage(String packageName) { |
| 191 | // First see if the package has an INFO activity; the existence of |
| 192 | // such an activity is implied to be the desired front-door for the |
| 193 | // overall package (such as if it has multiple launcher entries). |
| 194 | Intent intentToResolve = new Intent(Intent.ACTION_MAIN); |
| 195 | intentToResolve.addCategory(Intent.CATEGORY_INFO); |
| 196 | intentToResolve.setPackage(packageName); |
Dianne Hackborn | 1941576 | 2010-12-15 00:20:27 -0800 | [diff] [blame] | 197 | List<ResolveInfo> ris = queryIntentActivities(intentToResolve, 0); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 198 | |
| 199 | // Otherwise, try to find a main launcher activity. |
Dianne Hackborn | 1941576 | 2010-12-15 00:20:27 -0800 | [diff] [blame] | 200 | if (ris == null || ris.size() <= 0) { |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 201 | // reuse the intent instance |
| 202 | intentToResolve.removeCategory(Intent.CATEGORY_INFO); |
| 203 | intentToResolve.addCategory(Intent.CATEGORY_LAUNCHER); |
| 204 | intentToResolve.setPackage(packageName); |
Dianne Hackborn | 1941576 | 2010-12-15 00:20:27 -0800 | [diff] [blame] | 205 | ris = queryIntentActivities(intentToResolve, 0); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 206 | } |
Dianne Hackborn | 1941576 | 2010-12-15 00:20:27 -0800 | [diff] [blame] | 207 | if (ris == null || ris.size() <= 0) { |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 208 | return null; |
| 209 | } |
| 210 | Intent intent = new Intent(intentToResolve); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 211 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
Dianne Hackborn | 1941576 | 2010-12-15 00:20:27 -0800 | [diff] [blame] | 212 | intent.setClassName(ris.get(0).activityInfo.packageName, |
| 213 | ris.get(0).activityInfo.name); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 214 | return intent; |
| 215 | } |
| 216 | |
| 217 | @Override |
Jose Lima | 970417c | 2014-04-10 10:42:19 -0700 | [diff] [blame] | 218 | public Intent getLeanbackLaunchIntentForPackage(String packageName) { |
| 219 | // Try to find a main leanback_launcher activity. |
| 220 | Intent intentToResolve = new Intent(Intent.ACTION_MAIN); |
| 221 | intentToResolve.addCategory(Intent.CATEGORY_LEANBACK_LAUNCHER); |
| 222 | intentToResolve.setPackage(packageName); |
| 223 | List<ResolveInfo> ris = queryIntentActivities(intentToResolve, 0); |
| 224 | |
| 225 | if (ris == null || ris.size() <= 0) { |
| 226 | return null; |
| 227 | } |
| 228 | Intent intent = new Intent(intentToResolve); |
| 229 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 230 | intent.setClassName(ris.get(0).activityInfo.packageName, |
| 231 | ris.get(0).activityInfo.name); |
| 232 | return intent; |
| 233 | } |
| 234 | |
| 235 | @Override |
Jeff Sharkey | 8588bc1 | 2016-01-06 16:47:42 -0700 | [diff] [blame] | 236 | public int[] getPackageGids(String packageName) throws NameNotFoundException { |
| 237 | return getPackageGids(packageName, 0); |
| 238 | } |
| 239 | |
| 240 | @Override |
| 241 | public int[] getPackageGids(String packageName, int flags) |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 242 | throws NameNotFoundException { |
| 243 | try { |
Jeff Sharkey | cd65448 | 2016-01-08 17:42:11 -0700 | [diff] [blame] | 244 | int[] gids = mPM.getPackageGids(packageName, flags, mContext.getUserId()); |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 245 | if (gids != null) { |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 246 | return gids; |
| 247 | } |
| 248 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 249 | throw e.rethrowFromSystemServer(); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 250 | } |
| 251 | |
| 252 | throw new NameNotFoundException(packageName); |
| 253 | } |
| 254 | |
| 255 | @Override |
Jeff Sharkey | 8588bc1 | 2016-01-06 16:47:42 -0700 | [diff] [blame] | 256 | public int getPackageUid(String packageName, int flags) throws NameNotFoundException { |
| 257 | return getPackageUidAsUser(packageName, flags, mContext.getUserId()); |
| 258 | } |
| 259 | |
| 260 | @Override |
| 261 | public int getPackageUidAsUser(String packageName, int userId) throws NameNotFoundException { |
| 262 | return getPackageUidAsUser(packageName, 0, userId); |
| 263 | } |
| 264 | |
| 265 | @Override |
| 266 | public int getPackageUidAsUser(String packageName, int flags, int userId) |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 267 | throws NameNotFoundException { |
| 268 | try { |
Jeff Sharkey | cd65448 | 2016-01-08 17:42:11 -0700 | [diff] [blame] | 269 | int uid = mPM.getPackageUid(packageName, flags, userId); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 270 | if (uid >= 0) { |
| 271 | return uid; |
| 272 | } |
| 273 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 274 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 275 | } |
| 276 | |
| 277 | throw new NameNotFoundException(packageName); |
| 278 | } |
| 279 | |
| 280 | @Override |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 281 | public PermissionInfo getPermissionInfo(String name, int flags) |
| 282 | throws NameNotFoundException { |
| 283 | try { |
| 284 | PermissionInfo pi = mPM.getPermissionInfo(name, flags); |
| 285 | if (pi != null) { |
| 286 | return pi; |
| 287 | } |
| 288 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 289 | throw e.rethrowFromSystemServer(); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 290 | } |
| 291 | |
| 292 | throw new NameNotFoundException(name); |
| 293 | } |
| 294 | |
| 295 | @Override |
Svetoslav Ganov | b2c2e45 | 2016-03-24 18:01:17 -0700 | [diff] [blame] | 296 | @SuppressWarnings("unchecked") |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 297 | public List<PermissionInfo> queryPermissionsByGroup(String group, int flags) |
| 298 | throws NameNotFoundException { |
| 299 | try { |
Svetoslav Ganov | b2c2e45 | 2016-03-24 18:01:17 -0700 | [diff] [blame] | 300 | ParceledListSlice<PermissionInfo> parceledList = |
| 301 | mPM.queryPermissionsByGroup(group, flags); |
| 302 | if (parceledList != null) { |
| 303 | List<PermissionInfo> pi = parceledList.getList(); |
| 304 | if (pi != null) { |
| 305 | return pi; |
| 306 | } |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 307 | } |
| 308 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 309 | throw e.rethrowFromSystemServer(); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 310 | } |
| 311 | |
| 312 | throw new NameNotFoundException(group); |
| 313 | } |
| 314 | |
| 315 | @Override |
Paul Navin | 7b89a7b | 2017-01-26 23:56:08 +0000 | [diff] [blame] | 316 | public boolean isPermissionReviewModeEnabled() { |
| 317 | return mContext.getResources().getBoolean( |
| 318 | com.android.internal.R.bool.config_permissionReviewRequired); |
| 319 | } |
| 320 | |
| 321 | @Override |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 322 | public PermissionGroupInfo getPermissionGroupInfo(String name, |
Svetoslav Ganov | b2c2e45 | 2016-03-24 18:01:17 -0700 | [diff] [blame] | 323 | int flags) throws NameNotFoundException { |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 324 | try { |
| 325 | PermissionGroupInfo pgi = mPM.getPermissionGroupInfo(name, flags); |
| 326 | if (pgi != null) { |
| 327 | return pgi; |
| 328 | } |
| 329 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 330 | throw e.rethrowFromSystemServer(); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 331 | } |
| 332 | |
| 333 | throw new NameNotFoundException(name); |
| 334 | } |
| 335 | |
| 336 | @Override |
Svetoslav Ganov | b2c2e45 | 2016-03-24 18:01:17 -0700 | [diff] [blame] | 337 | @SuppressWarnings("unchecked") |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 338 | public List<PermissionGroupInfo> getAllPermissionGroups(int flags) { |
| 339 | try { |
Svetoslav Ganov | b2c2e45 | 2016-03-24 18:01:17 -0700 | [diff] [blame] | 340 | ParceledListSlice<PermissionGroupInfo> parceledList = |
| 341 | mPM.getAllPermissionGroups(flags); |
| 342 | if (parceledList == null) { |
| 343 | return Collections.emptyList(); |
| 344 | } |
| 345 | return parceledList.getList(); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 346 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 347 | throw e.rethrowFromSystemServer(); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 348 | } |
| 349 | } |
| 350 | |
| 351 | @Override |
| 352 | public ApplicationInfo getApplicationInfo(String packageName, int flags) |
| 353 | throws NameNotFoundException { |
Jeff Sharkey | cd65448 | 2016-01-08 17:42:11 -0700 | [diff] [blame] | 354 | return getApplicationInfoAsUser(packageName, flags, mContext.getUserId()); |
| 355 | } |
| 356 | |
| 357 | @Override |
| 358 | public ApplicationInfo getApplicationInfoAsUser(String packageName, int flags, int userId) |
| 359 | throws NameNotFoundException { |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 360 | try { |
Jeff Sharkey | cd65448 | 2016-01-08 17:42:11 -0700 | [diff] [blame] | 361 | ApplicationInfo ai = mPM.getApplicationInfo(packageName, flags, userId); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 362 | if (ai != null) { |
Narayan Kamath | caa7119 | 2014-07-16 11:06:43 +0100 | [diff] [blame] | 363 | // This is a temporary hack. Callers must use |
| 364 | // createPackageContext(packageName).getApplicationInfo() to |
| 365 | // get the right paths. |
Tao Bai | c9a0237 | 2016-01-12 15:02:24 -0800 | [diff] [blame] | 366 | return maybeAdjustApplicationInfo(ai); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 367 | } |
| 368 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 369 | throw e.rethrowFromSystemServer(); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 370 | } |
| 371 | |
| 372 | throw new NameNotFoundException(packageName); |
| 373 | } |
| 374 | |
Tao Bai | c9a0237 | 2016-01-12 15:02:24 -0800 | [diff] [blame] | 375 | private static ApplicationInfo maybeAdjustApplicationInfo(ApplicationInfo info) { |
Narayan Kamath | caa7119 | 2014-07-16 11:06:43 +0100 | [diff] [blame] | 376 | // If we're dealing with a multi-arch application that has both |
| 377 | // 32 and 64 bit shared libraries, we might need to choose the secondary |
| 378 | // depending on what the current runtime's instruction set is. |
| 379 | if (info.primaryCpuAbi != null && info.secondaryCpuAbi != null) { |
| 380 | final String runtimeIsa = VMRuntime.getRuntime().vmInstructionSet(); |
jgu21 | 4741cd9 | 2014-12-17 17:23:29 -0500 | [diff] [blame] | 381 | |
| 382 | // Get the instruction set that the libraries of secondary Abi is supported. |
| 383 | // In presence of a native bridge this might be different than the one secondary Abi used. |
| 384 | String secondaryIsa = VMRuntime.getInstructionSet(info.secondaryCpuAbi); |
| 385 | final String secondaryDexCodeIsa = SystemProperties.get("ro.dalvik.vm.isa." + secondaryIsa); |
| 386 | secondaryIsa = secondaryDexCodeIsa.isEmpty() ? secondaryIsa : secondaryDexCodeIsa; |
Narayan Kamath | caa7119 | 2014-07-16 11:06:43 +0100 | [diff] [blame] | 387 | |
| 388 | // If the runtimeIsa is the same as the primary isa, then we do nothing. |
| 389 | // Everything will be set up correctly because info.nativeLibraryDir will |
| 390 | // correspond to the right ISA. |
| 391 | if (runtimeIsa.equals(secondaryIsa)) { |
Tao Bai | c9a0237 | 2016-01-12 15:02:24 -0800 | [diff] [blame] | 392 | ApplicationInfo modified = new ApplicationInfo(info); |
| 393 | modified.nativeLibraryDir = info.secondaryNativeLibraryDir; |
| 394 | return modified; |
Narayan Kamath | caa7119 | 2014-07-16 11:06:43 +0100 | [diff] [blame] | 395 | } |
| 396 | } |
Tao Bai | c9a0237 | 2016-01-12 15:02:24 -0800 | [diff] [blame] | 397 | return info; |
Narayan Kamath | caa7119 | 2014-07-16 11:06:43 +0100 | [diff] [blame] | 398 | } |
| 399 | |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 400 | @Override |
| 401 | public ActivityInfo getActivityInfo(ComponentName className, int flags) |
| 402 | throws NameNotFoundException { |
| 403 | try { |
Jeff Sharkey | ded653b | 2012-09-27 19:09:24 -0700 | [diff] [blame] | 404 | ActivityInfo ai = mPM.getActivityInfo(className, flags, mContext.getUserId()); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 405 | if (ai != null) { |
| 406 | return ai; |
| 407 | } |
| 408 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 409 | throw e.rethrowFromSystemServer(); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 410 | } |
| 411 | |
| 412 | throw new NameNotFoundException(className.toString()); |
| 413 | } |
| 414 | |
| 415 | @Override |
| 416 | public ActivityInfo getReceiverInfo(ComponentName className, int flags) |
| 417 | throws NameNotFoundException { |
| 418 | try { |
Jeff Sharkey | ded653b | 2012-09-27 19:09:24 -0700 | [diff] [blame] | 419 | ActivityInfo ai = mPM.getReceiverInfo(className, flags, mContext.getUserId()); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 420 | if (ai != null) { |
| 421 | return ai; |
| 422 | } |
| 423 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 424 | throw e.rethrowFromSystemServer(); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 425 | } |
| 426 | |
| 427 | throw new NameNotFoundException(className.toString()); |
| 428 | } |
| 429 | |
| 430 | @Override |
| 431 | public ServiceInfo getServiceInfo(ComponentName className, int flags) |
| 432 | throws NameNotFoundException { |
| 433 | try { |
Jeff Sharkey | ded653b | 2012-09-27 19:09:24 -0700 | [diff] [blame] | 434 | ServiceInfo si = mPM.getServiceInfo(className, flags, mContext.getUserId()); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 435 | if (si != null) { |
| 436 | return si; |
| 437 | } |
| 438 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 439 | throw e.rethrowFromSystemServer(); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 440 | } |
| 441 | |
| 442 | throw new NameNotFoundException(className.toString()); |
| 443 | } |
| 444 | |
| 445 | @Override |
| 446 | public ProviderInfo getProviderInfo(ComponentName className, int flags) |
| 447 | throws NameNotFoundException { |
| 448 | try { |
Jeff Sharkey | ded653b | 2012-09-27 19:09:24 -0700 | [diff] [blame] | 449 | ProviderInfo pi = mPM.getProviderInfo(className, flags, mContext.getUserId()); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 450 | if (pi != null) { |
| 451 | return pi; |
| 452 | } |
| 453 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 454 | throw e.rethrowFromSystemServer(); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 455 | } |
| 456 | |
| 457 | throw new NameNotFoundException(className.toString()); |
| 458 | } |
| 459 | |
| 460 | @Override |
| 461 | public String[] getSystemSharedLibraryNames() { |
| 462 | try { |
| 463 | return mPM.getSystemSharedLibraryNames(); |
| 464 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 465 | throw e.rethrowFromSystemServer(); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 466 | } |
| 467 | } |
| 468 | |
Svet Ganov | d7b1f411 | 2016-02-09 18:49:23 -0800 | [diff] [blame] | 469 | /** @hide */ |
| 470 | @Override |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 471 | public @NonNull List<SharedLibraryInfo> getSharedLibraries(int flags) { |
| 472 | return getSharedLibrariesAsUser(flags, mContext.getUserId()); |
| 473 | } |
| 474 | |
| 475 | /** @hide */ |
| 476 | @Override |
| 477 | @SuppressWarnings("unchecked") |
| 478 | public @NonNull List<SharedLibraryInfo> getSharedLibrariesAsUser(int flags, int userId) { |
| 479 | try { |
| 480 | ParceledListSlice<SharedLibraryInfo> sharedLibs = mPM.getSharedLibraries( |
Svet Ganov | 58c99f0 | 2017-05-15 14:07:17 -0700 | [diff] [blame] | 481 | mContext.getOpPackageName(), flags, userId); |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 482 | if (sharedLibs == null) { |
| 483 | return Collections.emptyList(); |
| 484 | } |
| 485 | return sharedLibs.getList(); |
| 486 | } catch (RemoteException e) { |
| 487 | throw e.rethrowFromSystemServer(); |
| 488 | } |
| 489 | } |
| 490 | |
| 491 | /** @hide */ |
| 492 | @Override |
Svetoslav Ganov | a9c2500 | 2016-04-13 19:25:56 -0700 | [diff] [blame] | 493 | public @NonNull String getServicesSystemSharedLibraryPackageName() { |
Svet Ganov | d7b1f411 | 2016-02-09 18:49:23 -0800 | [diff] [blame] | 494 | try { |
| 495 | return mPM.getServicesSystemSharedLibraryPackageName(); |
| 496 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 497 | throw e.rethrowFromSystemServer(); |
Svet Ganov | d7b1f411 | 2016-02-09 18:49:23 -0800 | [diff] [blame] | 498 | } |
| 499 | } |
| 500 | |
Svetoslav Ganov | a9c2500 | 2016-04-13 19:25:56 -0700 | [diff] [blame] | 501 | /** |
| 502 | * @hide |
| 503 | */ |
| 504 | public @NonNull String getSharedSystemSharedLibraryPackageName() { |
| 505 | try { |
| 506 | return mPM.getSharedSystemSharedLibraryPackageName(); |
| 507 | } catch (RemoteException e) { |
| 508 | throw e.rethrowFromSystemServer(); |
| 509 | } |
| 510 | } |
| 511 | |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 512 | @Override |
Todd Kennedy | 9106c64 | 2017-02-08 14:16:53 -0800 | [diff] [blame] | 513 | public ChangedPackages getChangedPackages(int sequenceNumber) { |
| 514 | try { |
| 515 | return mPM.getChangedPackages(sequenceNumber, mContext.getUserId()); |
| 516 | } catch (RemoteException e) { |
| 517 | throw e.rethrowFromSystemServer(); |
| 518 | } |
| 519 | } |
| 520 | |
| 521 | @Override |
Svetoslav Ganov | b2c2e45 | 2016-03-24 18:01:17 -0700 | [diff] [blame] | 522 | @SuppressWarnings("unchecked") |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 523 | public FeatureInfo[] getSystemAvailableFeatures() { |
| 524 | try { |
Svetoslav Ganov | b2c2e45 | 2016-03-24 18:01:17 -0700 | [diff] [blame] | 525 | ParceledListSlice<FeatureInfo> parceledList = |
| 526 | mPM.getSystemAvailableFeatures(); |
| 527 | if (parceledList == null) { |
| 528 | return new FeatureInfo[0]; |
| 529 | } |
| 530 | final List<FeatureInfo> list = parceledList.getList(); |
Jeff Sharkey | d589663 | 2016-03-04 16:16:00 -0700 | [diff] [blame] | 531 | final FeatureInfo[] res = new FeatureInfo[list.size()]; |
| 532 | for (int i = 0; i < res.length; i++) { |
| 533 | res[i] = list.get(i); |
| 534 | } |
| 535 | return res; |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 536 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 537 | throw e.rethrowFromSystemServer(); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 538 | } |
| 539 | } |
| 540 | |
| 541 | @Override |
| 542 | public boolean hasSystemFeature(String name) { |
Jeff Sharkey | 115d2c1 | 2016-02-15 17:25:57 -0700 | [diff] [blame] | 543 | return hasSystemFeature(name, 0); |
| 544 | } |
| 545 | |
| 546 | @Override |
| 547 | public boolean hasSystemFeature(String name, int version) { |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 548 | try { |
Jeff Sharkey | 115d2c1 | 2016-02-15 17:25:57 -0700 | [diff] [blame] | 549 | return mPM.hasSystemFeature(name, version); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 550 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 551 | throw e.rethrowFromSystemServer(); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 552 | } |
| 553 | } |
| 554 | |
| 555 | @Override |
| 556 | public int checkPermission(String permName, String pkgName) { |
| 557 | try { |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 558 | return mPM.checkPermission(permName, pkgName, mContext.getUserId()); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 559 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 560 | throw e.rethrowFromSystemServer(); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 561 | } |
| 562 | } |
| 563 | |
| 564 | @Override |
Svet Ganov | ad3b297 | 2015-07-07 22:49:17 -0700 | [diff] [blame] | 565 | public boolean isPermissionRevokedByPolicy(String permName, String pkgName) { |
| 566 | try { |
| 567 | return mPM.isPermissionRevokedByPolicy(permName, pkgName, mContext.getUserId()); |
| 568 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 569 | throw e.rethrowFromSystemServer(); |
Svet Ganov | ad3b297 | 2015-07-07 22:49:17 -0700 | [diff] [blame] | 570 | } |
| 571 | } |
| 572 | |
Svet Ganov | f1b7f20 | 2015-07-29 08:33:42 -0700 | [diff] [blame] | 573 | /** |
| 574 | * @hide |
| 575 | */ |
| 576 | @Override |
| 577 | public String getPermissionControllerPackageName() { |
| 578 | synchronized (mLock) { |
| 579 | if (mPermissionsControllerPackageName == null) { |
| 580 | try { |
| 581 | mPermissionsControllerPackageName = mPM.getPermissionControllerPackageName(); |
| 582 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 583 | throw e.rethrowFromSystemServer(); |
Svet Ganov | f1b7f20 | 2015-07-29 08:33:42 -0700 | [diff] [blame] | 584 | } |
| 585 | } |
| 586 | return mPermissionsControllerPackageName; |
| 587 | } |
| 588 | } |
| 589 | |
Svet Ganov | ad3b297 | 2015-07-07 22:49:17 -0700 | [diff] [blame] | 590 | @Override |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 591 | public boolean addPermission(PermissionInfo info) { |
| 592 | try { |
| 593 | return mPM.addPermission(info); |
| 594 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 595 | throw e.rethrowFromSystemServer(); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 596 | } |
| 597 | } |
| 598 | |
| 599 | @Override |
| 600 | public boolean addPermissionAsync(PermissionInfo info) { |
| 601 | try { |
| 602 | return mPM.addPermissionAsync(info); |
| 603 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 604 | throw e.rethrowFromSystemServer(); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 605 | } |
| 606 | } |
| 607 | |
| 608 | @Override |
| 609 | public void removePermission(String name) { |
| 610 | try { |
| 611 | mPM.removePermission(name); |
| 612 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 613 | throw e.rethrowFromSystemServer(); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 614 | } |
| 615 | } |
| 616 | |
| 617 | @Override |
Svet Ganov | 8c7f700 | 2015-05-07 10:48:44 -0700 | [diff] [blame] | 618 | public void grantRuntimePermission(String packageName, String permissionName, |
| 619 | UserHandle user) { |
Dianne Hackborn | e639da7 | 2012-02-21 15:11:13 -0800 | [diff] [blame] | 620 | try { |
Svet Ganov | 8c7f700 | 2015-05-07 10:48:44 -0700 | [diff] [blame] | 621 | mPM.grantRuntimePermission(packageName, permissionName, user.getIdentifier()); |
Dianne Hackborn | e639da7 | 2012-02-21 15:11:13 -0800 | [diff] [blame] | 622 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 623 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | e639da7 | 2012-02-21 15:11:13 -0800 | [diff] [blame] | 624 | } |
| 625 | } |
| 626 | |
| 627 | @Override |
Svet Ganov | 8c7f700 | 2015-05-07 10:48:44 -0700 | [diff] [blame] | 628 | public void revokeRuntimePermission(String packageName, String permissionName, |
| 629 | UserHandle user) { |
Dianne Hackborn | e639da7 | 2012-02-21 15:11:13 -0800 | [diff] [blame] | 630 | try { |
Svet Ganov | 8c7f700 | 2015-05-07 10:48:44 -0700 | [diff] [blame] | 631 | mPM.revokeRuntimePermission(packageName, permissionName, user.getIdentifier()); |
| 632 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 633 | throw e.rethrowFromSystemServer(); |
Svet Ganov | 8c7f700 | 2015-05-07 10:48:44 -0700 | [diff] [blame] | 634 | } |
| 635 | } |
| 636 | |
| 637 | @Override |
| 638 | public int getPermissionFlags(String permissionName, String packageName, UserHandle user) { |
| 639 | try { |
| 640 | return mPM.getPermissionFlags(permissionName, packageName, user.getIdentifier()); |
| 641 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 642 | throw e.rethrowFromSystemServer(); |
Svet Ganov | 8c7f700 | 2015-05-07 10:48:44 -0700 | [diff] [blame] | 643 | } |
| 644 | } |
| 645 | |
| 646 | @Override |
| 647 | public void updatePermissionFlags(String permissionName, String packageName, |
| 648 | int flagMask, int flagValues, UserHandle user) { |
| 649 | try { |
| 650 | mPM.updatePermissionFlags(permissionName, packageName, flagMask, |
| 651 | flagValues, user.getIdentifier()); |
Dianne Hackborn | e639da7 | 2012-02-21 15:11:13 -0800 | [diff] [blame] | 652 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 653 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | e639da7 | 2012-02-21 15:11:13 -0800 | [diff] [blame] | 654 | } |
| 655 | } |
| 656 | |
| 657 | @Override |
Svetoslav | 20770dd | 2015-05-29 15:43:04 -0700 | [diff] [blame] | 658 | public boolean shouldShowRequestPermissionRationale(String permission) { |
| 659 | try { |
| 660 | return mPM.shouldShowRequestPermissionRationale(permission, |
| 661 | mContext.getPackageName(), mContext.getUserId()); |
| 662 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 663 | throw e.rethrowFromSystemServer(); |
Svetoslav | 20770dd | 2015-05-29 15:43:04 -0700 | [diff] [blame] | 664 | } |
| 665 | } |
| 666 | |
| 667 | @Override |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 668 | public int checkSignatures(String pkg1, String pkg2) { |
| 669 | try { |
| 670 | return mPM.checkSignatures(pkg1, pkg2); |
| 671 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 672 | throw e.rethrowFromSystemServer(); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 673 | } |
| 674 | } |
| 675 | |
| 676 | @Override |
| 677 | public int checkSignatures(int uid1, int uid2) { |
| 678 | try { |
| 679 | return mPM.checkUidSignatures(uid1, uid2); |
| 680 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 681 | throw e.rethrowFromSystemServer(); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 682 | } |
| 683 | } |
| 684 | |
| 685 | @Override |
| 686 | public String[] getPackagesForUid(int uid) { |
| 687 | try { |
| 688 | return mPM.getPackagesForUid(uid); |
| 689 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 690 | throw e.rethrowFromSystemServer(); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 691 | } |
| 692 | } |
| 693 | |
| 694 | @Override |
| 695 | public String getNameForUid(int uid) { |
| 696 | try { |
| 697 | return mPM.getNameForUid(uid); |
| 698 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 699 | throw e.rethrowFromSystemServer(); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 700 | } |
| 701 | } |
| 702 | |
| 703 | @Override |
| 704 | public int getUidForSharedUser(String sharedUserName) |
| 705 | throws NameNotFoundException { |
| 706 | try { |
| 707 | int uid = mPM.getUidForSharedUser(sharedUserName); |
| 708 | if(uid != -1) { |
| 709 | return uid; |
| 710 | } |
| 711 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 712 | throw e.rethrowFromSystemServer(); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 713 | } |
| 714 | throw new NameNotFoundException("No shared userid for user:"+sharedUserName); |
| 715 | } |
| 716 | |
Kenny Root | e6cd0c7 | 2011-05-19 12:48:14 -0700 | [diff] [blame] | 717 | @SuppressWarnings("unchecked") |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 718 | @Override |
| 719 | public List<PackageInfo> getInstalledPackages(int flags) { |
Jeff Sharkey | e06b4d1 | 2016-01-06 14:51:50 -0700 | [diff] [blame] | 720 | return getInstalledPackagesAsUser(flags, mContext.getUserId()); |
Amith Yamasani | 151ec4c | 2012-09-07 19:25:16 -0700 | [diff] [blame] | 721 | } |
| 722 | |
| 723 | /** @hide */ |
| 724 | @Override |
Svetoslav Ganov | b2c2e45 | 2016-03-24 18:01:17 -0700 | [diff] [blame] | 725 | @SuppressWarnings("unchecked") |
Jeff Sharkey | e06b4d1 | 2016-01-06 14:51:50 -0700 | [diff] [blame] | 726 | public List<PackageInfo> getInstalledPackagesAsUser(int flags, int userId) { |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 727 | try { |
Svetoslav Ganov | b2c2e45 | 2016-03-24 18:01:17 -0700 | [diff] [blame] | 728 | ParceledListSlice<PackageInfo> parceledList = |
| 729 | mPM.getInstalledPackages(flags, userId); |
| 730 | if (parceledList == null) { |
| 731 | return Collections.emptyList(); |
| 732 | } |
| 733 | return parceledList.getList(); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 734 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 735 | throw e.rethrowFromSystemServer(); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 736 | } |
| 737 | } |
| 738 | |
Kenny Root | e6cd0c7 | 2011-05-19 12:48:14 -0700 | [diff] [blame] | 739 | @SuppressWarnings("unchecked") |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 740 | @Override |
Dianne Hackborn | e799175 | 2013-01-16 17:56:46 -0800 | [diff] [blame] | 741 | public List<PackageInfo> getPackagesHoldingPermissions( |
| 742 | String[] permissions, int flags) { |
| 743 | final int userId = mContext.getUserId(); |
| 744 | try { |
Svetoslav Ganov | b2c2e45 | 2016-03-24 18:01:17 -0700 | [diff] [blame] | 745 | ParceledListSlice<PackageInfo> parceledList = |
| 746 | mPM.getPackagesHoldingPermissions(permissions, flags, userId); |
| 747 | if (parceledList == null) { |
| 748 | return Collections.emptyList(); |
| 749 | } |
| 750 | return parceledList.getList(); |
Dianne Hackborn | e799175 | 2013-01-16 17:56:46 -0800 | [diff] [blame] | 751 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 752 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | e799175 | 2013-01-16 17:56:46 -0800 | [diff] [blame] | 753 | } |
| 754 | } |
| 755 | |
| 756 | @SuppressWarnings("unchecked") |
| 757 | @Override |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 758 | public List<ApplicationInfo> getInstalledApplications(int flags) { |
Bartosz Fabianowski | 1133424 | 2016-11-17 20:49:16 +0100 | [diff] [blame] | 759 | return getInstalledApplicationsAsUser(flags, mContext.getUserId()); |
| 760 | } |
| 761 | |
| 762 | /** @hide */ |
| 763 | @SuppressWarnings("unchecked") |
| 764 | @Override |
| 765 | public List<ApplicationInfo> getInstalledApplicationsAsUser(int flags, int userId) { |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 766 | try { |
Svetoslav Ganov | b2c2e45 | 2016-03-24 18:01:17 -0700 | [diff] [blame] | 767 | ParceledListSlice<ApplicationInfo> parceledList = |
| 768 | mPM.getInstalledApplications(flags, userId); |
| 769 | if (parceledList == null) { |
| 770 | return Collections.emptyList(); |
| 771 | } |
| 772 | return parceledList.getList(); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 773 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 774 | throw e.rethrowFromSystemServer(); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 775 | } |
| 776 | } |
| 777 | |
Svet Ganov | 2acf063 | 2015-11-24 19:10:59 -0800 | [diff] [blame] | 778 | /** @hide */ |
| 779 | @SuppressWarnings("unchecked") |
| 780 | @Override |
Svetoslav Ganov | 096d304 | 2017-01-30 16:34:13 -0800 | [diff] [blame] | 781 | public List<InstantAppInfo> getInstantApps() { |
Svet Ganov | 2acf063 | 2015-11-24 19:10:59 -0800 | [diff] [blame] | 782 | try { |
Svetoslav Ganov | 096d304 | 2017-01-30 16:34:13 -0800 | [diff] [blame] | 783 | ParceledListSlice<InstantAppInfo> slice = |
| 784 | mPM.getInstantApps(mContext.getUserId()); |
Svet Ganov | 2acf063 | 2015-11-24 19:10:59 -0800 | [diff] [blame] | 785 | if (slice != null) { |
| 786 | return slice.getList(); |
| 787 | } |
| 788 | return Collections.emptyList(); |
| 789 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 790 | throw e.rethrowFromSystemServer(); |
Svet Ganov | 2acf063 | 2015-11-24 19:10:59 -0800 | [diff] [blame] | 791 | } |
| 792 | } |
| 793 | |
| 794 | /** @hide */ |
| 795 | @Override |
Svetoslav Ganov | 096d304 | 2017-01-30 16:34:13 -0800 | [diff] [blame] | 796 | public Drawable getInstantAppIcon(String packageName) { |
Svet Ganov | 2acf063 | 2015-11-24 19:10:59 -0800 | [diff] [blame] | 797 | try { |
Svetoslav Ganov | 096d304 | 2017-01-30 16:34:13 -0800 | [diff] [blame] | 798 | Bitmap bitmap = mPM.getInstantAppIcon( |
Svet Ganov | 2acf063 | 2015-11-24 19:10:59 -0800 | [diff] [blame] | 799 | packageName, mContext.getUserId()); |
| 800 | if (bitmap != null) { |
| 801 | return new BitmapDrawable(null, bitmap); |
| 802 | } |
| 803 | return null; |
| 804 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 805 | throw e.rethrowFromSystemServer(); |
Svet Ganov | 2acf063 | 2015-11-24 19:10:59 -0800 | [diff] [blame] | 806 | } |
| 807 | } |
| 808 | |
| 809 | @Override |
Svetoslav Ganov | 096d304 | 2017-01-30 16:34:13 -0800 | [diff] [blame] | 810 | public boolean isInstantApp() { |
David Christie | 31a1655 | 2017-03-01 15:08:45 -0800 | [diff] [blame] | 811 | return isInstantApp(mContext.getPackageName()); |
| 812 | } |
| 813 | |
| 814 | @Override |
| 815 | public boolean isInstantApp(String packageName) { |
Svet Ganov | 2acf063 | 2015-11-24 19:10:59 -0800 | [diff] [blame] | 816 | try { |
David Christie | 31a1655 | 2017-03-01 15:08:45 -0800 | [diff] [blame] | 817 | return mPM.isInstantApp(packageName, mContext.getUserId()); |
Svet Ganov | 2acf063 | 2015-11-24 19:10:59 -0800 | [diff] [blame] | 818 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 819 | throw e.rethrowFromSystemServer(); |
Svet Ganov | 2acf063 | 2015-11-24 19:10:59 -0800 | [diff] [blame] | 820 | } |
Svet Ganov | 2acf063 | 2015-11-24 19:10:59 -0800 | [diff] [blame] | 821 | } |
| 822 | |
Svetoslav Ganov | 345ffa5 | 2017-04-18 16:08:41 -0700 | [diff] [blame] | 823 | public int getInstantAppCookieMaxBytes() { |
Svet Ganov | 2acf063 | 2015-11-24 19:10:59 -0800 | [diff] [blame] | 824 | return Settings.Global.getInt(mContext.getContentResolver(), |
| 825 | Settings.Global.EPHEMERAL_COOKIE_MAX_SIZE_BYTES, |
| 826 | DEFAULT_EPHEMERAL_COOKIE_MAX_SIZE_BYTES); |
| 827 | } |
| 828 | |
| 829 | @Override |
Svetoslav Ganov | 345ffa5 | 2017-04-18 16:08:41 -0700 | [diff] [blame] | 830 | public int getInstantAppCookieMaxSize() { |
| 831 | return getInstantAppCookieMaxBytes(); |
| 832 | } |
| 833 | |
| 834 | @Override |
Svetoslav Ganov | 096d304 | 2017-01-30 16:34:13 -0800 | [diff] [blame] | 835 | public @NonNull byte[] getInstantAppCookie() { |
Svet Ganov | 2acf063 | 2015-11-24 19:10:59 -0800 | [diff] [blame] | 836 | try { |
Svetoslav Ganov | 096d304 | 2017-01-30 16:34:13 -0800 | [diff] [blame] | 837 | final byte[] cookie = mPM.getInstantAppCookie( |
Svet Ganov | 2acf063 | 2015-11-24 19:10:59 -0800 | [diff] [blame] | 838 | mContext.getPackageName(), mContext.getUserId()); |
| 839 | if (cookie != null) { |
| 840 | return cookie; |
Jeff Sharkey | 27b2e69 | 2016-02-25 17:40:12 -0700 | [diff] [blame] | 841 | } else { |
| 842 | return EmptyArray.BYTE; |
Svet Ganov | 2acf063 | 2015-11-24 19:10:59 -0800 | [diff] [blame] | 843 | } |
| 844 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 845 | throw e.rethrowFromSystemServer(); |
Svet Ganov | 2acf063 | 2015-11-24 19:10:59 -0800 | [diff] [blame] | 846 | } |
Svet Ganov | 2acf063 | 2015-11-24 19:10:59 -0800 | [diff] [blame] | 847 | } |
| 848 | |
| 849 | @Override |
Svetoslav Ganov | 345ffa5 | 2017-04-18 16:08:41 -0700 | [diff] [blame] | 850 | public void clearInstantAppCookie() { |
| 851 | updateInstantAppCookie(null); |
| 852 | } |
| 853 | |
| 854 | @Override |
| 855 | public void updateInstantAppCookie(@NonNull byte[] cookie) { |
| 856 | if (cookie != null && cookie.length > getInstantAppCookieMaxBytes()) { |
| 857 | throw new IllegalArgumentException("instant cookie longer than " |
| 858 | + getInstantAppCookieMaxBytes()); |
| 859 | } |
| 860 | try { |
| 861 | mPM.setInstantAppCookie(mContext.getPackageName(), |
| 862 | cookie, mContext.getUserId()); |
| 863 | } catch (RemoteException e) { |
| 864 | throw e.rethrowFromSystemServer(); |
| 865 | } |
| 866 | } |
| 867 | |
| 868 | @Override |
Svetoslav Ganov | 096d304 | 2017-01-30 16:34:13 -0800 | [diff] [blame] | 869 | public boolean setInstantAppCookie(@NonNull byte[] cookie) { |
Svet Ganov | 2acf063 | 2015-11-24 19:10:59 -0800 | [diff] [blame] | 870 | try { |
Svetoslav Ganov | 096d304 | 2017-01-30 16:34:13 -0800 | [diff] [blame] | 871 | return mPM.setInstantAppCookie(mContext.getPackageName(), |
| 872 | cookie, mContext.getUserId()); |
Svet Ganov | 2acf063 | 2015-11-24 19:10:59 -0800 | [diff] [blame] | 873 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 874 | throw e.rethrowFromSystemServer(); |
Svet Ganov | 2acf063 | 2015-11-24 19:10:59 -0800 | [diff] [blame] | 875 | } |
Svet Ganov | 2acf063 | 2015-11-24 19:10:59 -0800 | [diff] [blame] | 876 | } |
| 877 | |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 878 | @Override |
| 879 | public ResolveInfo resolveActivity(Intent intent, int flags) { |
Jeff Sharkey | ded653b | 2012-09-27 19:09:24 -0700 | [diff] [blame] | 880 | return resolveActivityAsUser(intent, flags, mContext.getUserId()); |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 881 | } |
| 882 | |
| 883 | @Override |
| 884 | public ResolveInfo resolveActivityAsUser(Intent intent, int flags, int userId) { |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 885 | try { |
| 886 | return mPM.resolveIntent( |
| 887 | intent, |
| 888 | intent.resolveTypeIfNeeded(mContext.getContentResolver()), |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 889 | flags, |
| 890 | userId); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 891 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 892 | throw e.rethrowFromSystemServer(); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 893 | } |
| 894 | } |
| 895 | |
| 896 | @Override |
| 897 | public List<ResolveInfo> queryIntentActivities(Intent intent, |
| 898 | int flags) { |
Jeff Sharkey | ded653b | 2012-09-27 19:09:24 -0700 | [diff] [blame] | 899 | return queryIntentActivitiesAsUser(intent, flags, mContext.getUserId()); |
Amith Yamasani | 151ec4c | 2012-09-07 19:25:16 -0700 | [diff] [blame] | 900 | } |
| 901 | |
| 902 | /** @hide Same as above but for a specific user */ |
| 903 | @Override |
Svetoslav Ganov | b2c2e45 | 2016-03-24 18:01:17 -0700 | [diff] [blame] | 904 | @SuppressWarnings("unchecked") |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 905 | public List<ResolveInfo> queryIntentActivitiesAsUser(Intent intent, |
Svetoslav Ganov | b2c2e45 | 2016-03-24 18:01:17 -0700 | [diff] [blame] | 906 | int flags, int userId) { |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 907 | try { |
Svetoslav Ganov | b2c2e45 | 2016-03-24 18:01:17 -0700 | [diff] [blame] | 908 | ParceledListSlice<ResolveInfo> parceledList = |
| 909 | mPM.queryIntentActivities(intent, |
| 910 | intent.resolveTypeIfNeeded(mContext.getContentResolver()), |
| 911 | flags, userId); |
| 912 | if (parceledList == null) { |
| 913 | return Collections.emptyList(); |
| 914 | } |
| 915 | return parceledList.getList(); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 916 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 917 | throw e.rethrowFromSystemServer(); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 918 | } |
| 919 | } |
| 920 | |
| 921 | @Override |
Svetoslav Ganov | b2c2e45 | 2016-03-24 18:01:17 -0700 | [diff] [blame] | 922 | @SuppressWarnings("unchecked") |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 923 | public List<ResolveInfo> queryIntentActivityOptions( |
| 924 | ComponentName caller, Intent[] specifics, Intent intent, |
| 925 | int flags) { |
| 926 | final ContentResolver resolver = mContext.getContentResolver(); |
| 927 | |
| 928 | String[] specificTypes = null; |
| 929 | if (specifics != null) { |
| 930 | final int N = specifics.length; |
| 931 | for (int i=0; i<N; i++) { |
| 932 | Intent sp = specifics[i]; |
| 933 | if (sp != null) { |
| 934 | String t = sp.resolveTypeIfNeeded(resolver); |
| 935 | if (t != null) { |
| 936 | if (specificTypes == null) { |
| 937 | specificTypes = new String[N]; |
| 938 | } |
| 939 | specificTypes[i] = t; |
| 940 | } |
| 941 | } |
| 942 | } |
| 943 | } |
| 944 | |
| 945 | try { |
Svetoslav Ganov | b2c2e45 | 2016-03-24 18:01:17 -0700 | [diff] [blame] | 946 | ParceledListSlice<ResolveInfo> parceledList = |
| 947 | mPM.queryIntentActivityOptions(caller, specifics, specificTypes, intent, |
| 948 | intent.resolveTypeIfNeeded(resolver), flags, mContext.getUserId()); |
| 949 | if (parceledList == null) { |
| 950 | return Collections.emptyList(); |
| 951 | } |
| 952 | return parceledList.getList(); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 953 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 954 | throw e.rethrowFromSystemServer(); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 955 | } |
| 956 | } |
| 957 | |
Amith Yamasani | f203aee | 2012-08-29 18:41:53 -0700 | [diff] [blame] | 958 | /** |
| 959 | * @hide |
| 960 | */ |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 961 | @Override |
Svetoslav Ganov | b2c2e45 | 2016-03-24 18:01:17 -0700 | [diff] [blame] | 962 | @SuppressWarnings("unchecked") |
Jeff Sharkey | e06b4d1 | 2016-01-06 14:51:50 -0700 | [diff] [blame] | 963 | public List<ResolveInfo> queryBroadcastReceiversAsUser(Intent intent, int flags, int userId) { |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 964 | try { |
Svetoslav Ganov | b2c2e45 | 2016-03-24 18:01:17 -0700 | [diff] [blame] | 965 | ParceledListSlice<ResolveInfo> parceledList = |
| 966 | mPM.queryIntentReceivers(intent, |
| 967 | intent.resolveTypeIfNeeded(mContext.getContentResolver()), |
| 968 | flags, userId); |
| 969 | if (parceledList == null) { |
| 970 | return Collections.emptyList(); |
| 971 | } |
| 972 | return parceledList.getList(); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 973 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 974 | throw e.rethrowFromSystemServer(); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 975 | } |
| 976 | } |
| 977 | |
| 978 | @Override |
Amith Yamasani | f203aee | 2012-08-29 18:41:53 -0700 | [diff] [blame] | 979 | public List<ResolveInfo> queryBroadcastReceivers(Intent intent, int flags) { |
Jeff Sharkey | e06b4d1 | 2016-01-06 14:51:50 -0700 | [diff] [blame] | 980 | return queryBroadcastReceiversAsUser(intent, flags, mContext.getUserId()); |
Amith Yamasani | f203aee | 2012-08-29 18:41:53 -0700 | [diff] [blame] | 981 | } |
| 982 | |
| 983 | @Override |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 984 | public ResolveInfo resolveService(Intent intent, int flags) { |
| 985 | try { |
| 986 | return mPM.resolveService( |
| 987 | intent, |
| 988 | intent.resolveTypeIfNeeded(mContext.getContentResolver()), |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 989 | flags, |
Jeff Sharkey | ded653b | 2012-09-27 19:09:24 -0700 | [diff] [blame] | 990 | mContext.getUserId()); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 991 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 992 | throw e.rethrowFromSystemServer(); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 993 | } |
| 994 | } |
| 995 | |
| 996 | @Override |
Svetoslav Ganov | b2c2e45 | 2016-03-24 18:01:17 -0700 | [diff] [blame] | 997 | @SuppressWarnings("unchecked") |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 998 | public List<ResolveInfo> queryIntentServicesAsUser(Intent intent, int flags, int userId) { |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 999 | try { |
Svetoslav Ganov | b2c2e45 | 2016-03-24 18:01:17 -0700 | [diff] [blame] | 1000 | ParceledListSlice<ResolveInfo> parceledList = |
| 1001 | mPM.queryIntentServices(intent, |
| 1002 | intent.resolveTypeIfNeeded(mContext.getContentResolver()), |
| 1003 | flags, userId); |
| 1004 | if (parceledList == null) { |
| 1005 | return Collections.emptyList(); |
| 1006 | } |
| 1007 | return parceledList.getList(); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 1008 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1009 | throw e.rethrowFromSystemServer(); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 1010 | } |
| 1011 | } |
| 1012 | |
| 1013 | @Override |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 1014 | public List<ResolveInfo> queryIntentServices(Intent intent, int flags) { |
Jeff Sharkey | ded653b | 2012-09-27 19:09:24 -0700 | [diff] [blame] | 1015 | return queryIntentServicesAsUser(intent, flags, mContext.getUserId()); |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 1016 | } |
| 1017 | |
| 1018 | @Override |
Svetoslav Ganov | b2c2e45 | 2016-03-24 18:01:17 -0700 | [diff] [blame] | 1019 | @SuppressWarnings("unchecked") |
Jeff Sharkey | 85f5f81 | 2013-10-07 10:16:12 -0700 | [diff] [blame] | 1020 | public List<ResolveInfo> queryIntentContentProvidersAsUser( |
| 1021 | Intent intent, int flags, int userId) { |
| 1022 | try { |
Svetoslav Ganov | b2c2e45 | 2016-03-24 18:01:17 -0700 | [diff] [blame] | 1023 | ParceledListSlice<ResolveInfo> parceledList = |
| 1024 | mPM.queryIntentContentProviders(intent, |
| 1025 | intent.resolveTypeIfNeeded(mContext.getContentResolver()), |
| 1026 | flags, userId); |
| 1027 | if (parceledList == null) { |
| 1028 | return Collections.emptyList(); |
| 1029 | } |
| 1030 | return parceledList.getList(); |
Jeff Sharkey | 85f5f81 | 2013-10-07 10:16:12 -0700 | [diff] [blame] | 1031 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1032 | throw e.rethrowFromSystemServer(); |
Jeff Sharkey | 85f5f81 | 2013-10-07 10:16:12 -0700 | [diff] [blame] | 1033 | } |
| 1034 | } |
| 1035 | |
| 1036 | @Override |
| 1037 | public List<ResolveInfo> queryIntentContentProviders(Intent intent, int flags) { |
| 1038 | return queryIntentContentProvidersAsUser(intent, flags, mContext.getUserId()); |
| 1039 | } |
| 1040 | |
| 1041 | @Override |
Alexandra Gherghina | 0363c3e | 2014-06-23 13:34:59 +0100 | [diff] [blame] | 1042 | public ProviderInfo resolveContentProvider(String name, int flags) { |
| 1043 | return resolveContentProviderAsUser(name, flags, mContext.getUserId()); |
| 1044 | } |
| 1045 | |
| 1046 | /** @hide **/ |
| 1047 | @Override |
| 1048 | public ProviderInfo resolveContentProviderAsUser(String name, int flags, int userId) { |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 1049 | try { |
Alexandra Gherghina | 0363c3e | 2014-06-23 13:34:59 +0100 | [diff] [blame] | 1050 | return mPM.resolveContentProvider(name, flags, userId); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 1051 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1052 | throw e.rethrowFromSystemServer(); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 1053 | } |
| 1054 | } |
| 1055 | |
| 1056 | @Override |
| 1057 | public List<ProviderInfo> queryContentProviders(String processName, |
Svetoslav Ganov | b2c2e45 | 2016-03-24 18:01:17 -0700 | [diff] [blame] | 1058 | int uid, int flags) { |
Makoto Onuki | 3275729 | 2017-02-22 14:36:59 -0800 | [diff] [blame] | 1059 | return queryContentProviders(processName, uid, flags, null); |
| 1060 | } |
| 1061 | |
| 1062 | @Override |
| 1063 | @SuppressWarnings("unchecked") |
| 1064 | public List<ProviderInfo> queryContentProviders(String processName, |
| 1065 | int uid, int flags, String metaDataKey) { |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 1066 | try { |
Svetoslav Ganov | b2c2e45 | 2016-03-24 18:01:17 -0700 | [diff] [blame] | 1067 | ParceledListSlice<ProviderInfo> slice = |
Makoto Onuki | 3275729 | 2017-02-22 14:36:59 -0800 | [diff] [blame] | 1068 | mPM.queryContentProviders(processName, uid, flags, metaDataKey); |
Svetoslav Ganov | b2c2e45 | 2016-03-24 18:01:17 -0700 | [diff] [blame] | 1069 | return slice != null ? slice.getList() : Collections.<ProviderInfo>emptyList(); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 1070 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1071 | throw e.rethrowFromSystemServer(); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 1072 | } |
| 1073 | } |
| 1074 | |
| 1075 | @Override |
| 1076 | public InstrumentationInfo getInstrumentationInfo( |
| 1077 | ComponentName className, int flags) |
| 1078 | throws NameNotFoundException { |
| 1079 | try { |
| 1080 | InstrumentationInfo ii = mPM.getInstrumentationInfo( |
| 1081 | className, flags); |
| 1082 | if (ii != null) { |
| 1083 | return ii; |
| 1084 | } |
| 1085 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1086 | throw e.rethrowFromSystemServer(); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 1087 | } |
| 1088 | |
| 1089 | throw new NameNotFoundException(className.toString()); |
| 1090 | } |
| 1091 | |
| 1092 | @Override |
Svetoslav Ganov | b2c2e45 | 2016-03-24 18:01:17 -0700 | [diff] [blame] | 1093 | @SuppressWarnings("unchecked") |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 1094 | public List<InstrumentationInfo> queryInstrumentation( |
| 1095 | String targetPackage, int flags) { |
| 1096 | try { |
Svetoslav Ganov | b2c2e45 | 2016-03-24 18:01:17 -0700 | [diff] [blame] | 1097 | ParceledListSlice<InstrumentationInfo> parceledList = |
| 1098 | mPM.queryInstrumentation(targetPackage, flags); |
| 1099 | if (parceledList == null) { |
| 1100 | return Collections.emptyList(); |
| 1101 | } |
| 1102 | return parceledList.getList(); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 1103 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1104 | throw e.rethrowFromSystemServer(); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 1105 | } |
| 1106 | } |
| 1107 | |
Alan Viverette | ecd585a | 2015-04-13 10:32:51 -0700 | [diff] [blame] | 1108 | @Nullable |
| 1109 | @Override |
| 1110 | public Drawable getDrawable(String packageName, @DrawableRes int resId, |
| 1111 | @Nullable ApplicationInfo appInfo) { |
| 1112 | final ResourceName name = new ResourceName(packageName, resId); |
| 1113 | final Drawable cachedIcon = getCachedIcon(name); |
| 1114 | if (cachedIcon != null) { |
| 1115 | return cachedIcon; |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 1116 | } |
Alan Viverette | ecd585a | 2015-04-13 10:32:51 -0700 | [diff] [blame] | 1117 | |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 1118 | if (appInfo == null) { |
| 1119 | try { |
Adam Lesinski | d00bb5e | 2014-10-07 12:14:45 -0700 | [diff] [blame] | 1120 | appInfo = getApplicationInfo(packageName, sDefaultFlags); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 1121 | } catch (NameNotFoundException e) { |
| 1122 | return null; |
| 1123 | } |
| 1124 | } |
Alan Viverette | ecd585a | 2015-04-13 10:32:51 -0700 | [diff] [blame] | 1125 | |
| 1126 | if (resId != 0) { |
| 1127 | try { |
| 1128 | final Resources r = getResourcesForApplication(appInfo); |
| 1129 | final Drawable dr = r.getDrawable(resId, null); |
| 1130 | if (dr != null) { |
| 1131 | putCachedIcon(name, dr); |
| 1132 | } |
| 1133 | |
| 1134 | if (false) { |
| 1135 | RuntimeException e = new RuntimeException("here"); |
| 1136 | e.fillInStackTrace(); |
| 1137 | Log.w(TAG, "Getting drawable 0x" + Integer.toHexString(resId) |
| 1138 | + " from package " + packageName |
| 1139 | + ": app scale=" + r.getCompatibilityInfo().applicationScale |
| 1140 | + ", caller scale=" + mContext.getResources() |
| 1141 | .getCompatibilityInfo().applicationScale, |
| 1142 | e); |
| 1143 | } |
Ricky Wai | 3ce4625 | 2015-04-15 16:12:22 +0100 | [diff] [blame] | 1144 | if (DEBUG_ICONS) { |
Alan Viverette | ecd585a | 2015-04-13 10:32:51 -0700 | [diff] [blame] | 1145 | Log.v(TAG, "Getting drawable 0x" |
| 1146 | + Integer.toHexString(resId) + " from " + r |
| 1147 | + ": " + dr); |
Ricky Wai | 3ce4625 | 2015-04-15 16:12:22 +0100 | [diff] [blame] | 1148 | } |
| 1149 | return dr; |
Alan Viverette | ecd585a | 2015-04-13 10:32:51 -0700 | [diff] [blame] | 1150 | } catch (NameNotFoundException e) { |
| 1151 | Log.w("PackageManager", "Failure retrieving resources for " |
| 1152 | + appInfo.packageName); |
| 1153 | } catch (Resources.NotFoundException e) { |
| 1154 | Log.w("PackageManager", "Failure retrieving resources for " |
| 1155 | + appInfo.packageName + ": " + e.getMessage()); |
| 1156 | } catch (Exception e) { |
| 1157 | // If an exception was thrown, fall through to return |
| 1158 | // default icon. |
| 1159 | Log.w("PackageManager", "Failure retrieving icon 0x" |
| 1160 | + Integer.toHexString(resId) + " in package " |
| 1161 | + packageName, e); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 1162 | } |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 1163 | } |
Alan Viverette | ecd585a | 2015-04-13 10:32:51 -0700 | [diff] [blame] | 1164 | |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 1165 | return null; |
| 1166 | } |
| 1167 | |
| 1168 | @Override public Drawable getActivityIcon(ComponentName activityName) |
| 1169 | throws NameNotFoundException { |
Adam Lesinski | d00bb5e | 2014-10-07 12:14:45 -0700 | [diff] [blame] | 1170 | return getActivityInfo(activityName, sDefaultFlags).loadIcon(this); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 1171 | } |
| 1172 | |
| 1173 | @Override public Drawable getActivityIcon(Intent intent) |
| 1174 | throws NameNotFoundException { |
| 1175 | if (intent.getComponent() != null) { |
| 1176 | return getActivityIcon(intent.getComponent()); |
| 1177 | } |
| 1178 | |
| 1179 | ResolveInfo info = resolveActivity( |
| 1180 | intent, PackageManager.MATCH_DEFAULT_ONLY); |
| 1181 | if (info != null) { |
| 1182 | return info.activityInfo.loadIcon(this); |
| 1183 | } |
| 1184 | |
Romain Guy | 39fe17c | 2011-11-30 10:34:07 -0800 | [diff] [blame] | 1185 | throw new NameNotFoundException(intent.toUri(0)); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 1186 | } |
| 1187 | |
| 1188 | @Override public Drawable getDefaultActivityIcon() { |
| 1189 | return Resources.getSystem().getDrawable( |
| 1190 | com.android.internal.R.drawable.sym_def_app_icon); |
| 1191 | } |
| 1192 | |
| 1193 | @Override public Drawable getApplicationIcon(ApplicationInfo info) { |
| 1194 | return info.loadIcon(this); |
| 1195 | } |
| 1196 | |
| 1197 | @Override public Drawable getApplicationIcon(String packageName) |
| 1198 | throws NameNotFoundException { |
Adam Lesinski | d00bb5e | 2014-10-07 12:14:45 -0700 | [diff] [blame] | 1199 | return getApplicationIcon(getApplicationInfo(packageName, sDefaultFlags)); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 1200 | } |
| 1201 | |
| 1202 | @Override |
Jose Lima | f78e312 | 2014-03-06 12:13:15 -0800 | [diff] [blame] | 1203 | public Drawable getActivityBanner(ComponentName activityName) |
| 1204 | throws NameNotFoundException { |
Adam Lesinski | d00bb5e | 2014-10-07 12:14:45 -0700 | [diff] [blame] | 1205 | return getActivityInfo(activityName, sDefaultFlags).loadBanner(this); |
Jose Lima | f78e312 | 2014-03-06 12:13:15 -0800 | [diff] [blame] | 1206 | } |
| 1207 | |
| 1208 | @Override |
| 1209 | public Drawable getActivityBanner(Intent intent) |
| 1210 | throws NameNotFoundException { |
| 1211 | if (intent.getComponent() != null) { |
| 1212 | return getActivityBanner(intent.getComponent()); |
| 1213 | } |
| 1214 | |
| 1215 | ResolveInfo info = resolveActivity( |
| 1216 | intent, PackageManager.MATCH_DEFAULT_ONLY); |
| 1217 | if (info != null) { |
| 1218 | return info.activityInfo.loadBanner(this); |
| 1219 | } |
| 1220 | |
| 1221 | throw new NameNotFoundException(intent.toUri(0)); |
| 1222 | } |
| 1223 | |
| 1224 | @Override |
| 1225 | public Drawable getApplicationBanner(ApplicationInfo info) { |
| 1226 | return info.loadBanner(this); |
| 1227 | } |
| 1228 | |
| 1229 | @Override |
| 1230 | public Drawable getApplicationBanner(String packageName) |
| 1231 | throws NameNotFoundException { |
Adam Lesinski | d00bb5e | 2014-10-07 12:14:45 -0700 | [diff] [blame] | 1232 | return getApplicationBanner(getApplicationInfo(packageName, sDefaultFlags)); |
Jose Lima | f78e312 | 2014-03-06 12:13:15 -0800 | [diff] [blame] | 1233 | } |
| 1234 | |
| 1235 | @Override |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 1236 | public Drawable getActivityLogo(ComponentName activityName) |
| 1237 | throws NameNotFoundException { |
Adam Lesinski | d00bb5e | 2014-10-07 12:14:45 -0700 | [diff] [blame] | 1238 | return getActivityInfo(activityName, sDefaultFlags).loadLogo(this); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 1239 | } |
| 1240 | |
| 1241 | @Override |
| 1242 | public Drawable getActivityLogo(Intent intent) |
| 1243 | throws NameNotFoundException { |
| 1244 | if (intent.getComponent() != null) { |
| 1245 | return getActivityLogo(intent.getComponent()); |
| 1246 | } |
| 1247 | |
| 1248 | ResolveInfo info = resolveActivity( |
| 1249 | intent, PackageManager.MATCH_DEFAULT_ONLY); |
| 1250 | if (info != null) { |
| 1251 | return info.activityInfo.loadLogo(this); |
| 1252 | } |
| 1253 | |
| 1254 | throw new NameNotFoundException(intent.toUri(0)); |
| 1255 | } |
| 1256 | |
| 1257 | @Override |
| 1258 | public Drawable getApplicationLogo(ApplicationInfo info) { |
| 1259 | return info.loadLogo(this); |
| 1260 | } |
| 1261 | |
| 1262 | @Override |
| 1263 | public Drawable getApplicationLogo(String packageName) |
| 1264 | throws NameNotFoundException { |
Adam Lesinski | d00bb5e | 2014-10-07 12:14:45 -0700 | [diff] [blame] | 1265 | return getApplicationLogo(getApplicationInfo(packageName, sDefaultFlags)); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 1266 | } |
| 1267 | |
Svetoslav | c7d62f0 | 2014-09-04 15:39:54 -0700 | [diff] [blame] | 1268 | @Override |
| 1269 | public Drawable getUserBadgedIcon(Drawable icon, UserHandle user) { |
Kenny Guy | 02c8990 | 2016-11-15 19:36:38 +0000 | [diff] [blame] | 1270 | if (!isManagedProfile(user.getIdentifier())) { |
Svetoslav | c7d62f0 | 2014-09-04 15:39:54 -0700 | [diff] [blame] | 1271 | return icon; |
| 1272 | } |
Sunny Goyal | bab3075 | 2017-04-12 15:36:42 -0700 | [diff] [blame] | 1273 | Drawable badge = new LauncherIcons(mContext).getBadgeDrawable( |
| 1274 | com.android.internal.R.drawable.ic_corp_icon_badge_case, |
| 1275 | getUserBadgeColor(user)); |
Kenny Guy | 02c8990 | 2016-11-15 19:36:38 +0000 | [diff] [blame] | 1276 | return getBadgedDrawable(icon, badge, null, true); |
Svetoslav | c7d62f0 | 2014-09-04 15:39:54 -0700 | [diff] [blame] | 1277 | } |
| 1278 | |
| 1279 | @Override |
| 1280 | public Drawable getUserBadgedDrawableForDensity(Drawable drawable, UserHandle user, |
| 1281 | Rect badgeLocation, int badgeDensity) { |
| 1282 | Drawable badgeDrawable = getUserBadgeForDensity(user, badgeDensity); |
| 1283 | if (badgeDrawable == null) { |
| 1284 | return drawable; |
| 1285 | } |
| 1286 | return getBadgedDrawable(drawable, badgeDrawable, badgeLocation, true); |
| 1287 | } |
| 1288 | |
Kenny Guy | 02c8990 | 2016-11-15 19:36:38 +0000 | [diff] [blame] | 1289 | @VisibleForTesting |
| 1290 | public static final int[] CORP_BADGE_LABEL_RES_ID = new int[] { |
| 1291 | com.android.internal.R.string.managed_profile_label_badge, |
| 1292 | com.android.internal.R.string.managed_profile_label_badge_2, |
| 1293 | com.android.internal.R.string.managed_profile_label_badge_3 |
| 1294 | }; |
| 1295 | |
| 1296 | private int getUserBadgeColor(UserHandle user) { |
Sunny Goyal | bab3075 | 2017-04-12 15:36:42 -0700 | [diff] [blame] | 1297 | return IconDrawableFactory.getUserBadgeColor(getUserManager(), user.getIdentifier()); |
Kenny Guy | 02c8990 | 2016-11-15 19:36:38 +0000 | [diff] [blame] | 1298 | } |
| 1299 | |
Svetoslav | c7d62f0 | 2014-09-04 15:39:54 -0700 | [diff] [blame] | 1300 | @Override |
| 1301 | public Drawable getUserBadgeForDensity(UserHandle user, int density) { |
Kenny Guy | 02c8990 | 2016-11-15 19:36:38 +0000 | [diff] [blame] | 1302 | Drawable badgeColor = getManagedProfileIconForDensity(user, |
| 1303 | com.android.internal.R.drawable.ic_corp_badge_color, density); |
| 1304 | if (badgeColor == null) { |
| 1305 | return null; |
| 1306 | } |
| 1307 | badgeColor.setTint(getUserBadgeColor(user)); |
| 1308 | Drawable badgeForeground = getDrawableForDensity( |
| 1309 | com.android.internal.R.drawable.ic_corp_badge_case, density); |
| 1310 | Drawable badge = new LayerDrawable( |
| 1311 | new Drawable[] {badgeColor, badgeForeground }); |
| 1312 | return badge; |
Selim Cinek | e6ff946 | 2016-01-15 15:07:06 -0800 | [diff] [blame] | 1313 | } |
| 1314 | |
| 1315 | @Override |
| 1316 | public Drawable getUserBadgeForDensityNoBackground(UserHandle user, int density) { |
Kenny Guy | 02c8990 | 2016-11-15 19:36:38 +0000 | [diff] [blame] | 1317 | Drawable badge = getManagedProfileIconForDensity(user, |
Vadim Tryshev | 66ae66a | 2016-02-18 15:41:21 -0800 | [diff] [blame] | 1318 | com.android.internal.R.drawable.ic_corp_badge_no_background, density); |
Kenny Guy | 02c8990 | 2016-11-15 19:36:38 +0000 | [diff] [blame] | 1319 | if (badge != null) { |
| 1320 | badge.setTint(getUserBadgeColor(user)); |
| 1321 | } |
| 1322 | return badge; |
Selim Cinek | e6ff946 | 2016-01-15 15:07:06 -0800 | [diff] [blame] | 1323 | } |
| 1324 | |
Vadim Tryshev | 66ae66a | 2016-02-18 15:41:21 -0800 | [diff] [blame] | 1325 | private Drawable getDrawableForDensity(int drawableId, int density) { |
| 1326 | if (density <= 0) { |
| 1327 | density = mContext.getResources().getDisplayMetrics().densityDpi; |
| 1328 | } |
| 1329 | return Resources.getSystem().getDrawableForDensity(drawableId, density); |
| 1330 | } |
| 1331 | |
| 1332 | private Drawable getManagedProfileIconForDensity(UserHandle user, int drawableId, int density) { |
Tony Mak | 8673b28 | 2016-03-21 21:10:59 +0000 | [diff] [blame] | 1333 | if (isManagedProfile(user.getIdentifier())) { |
Vadim Tryshev | 66ae66a | 2016-02-18 15:41:21 -0800 | [diff] [blame] | 1334 | return getDrawableForDensity(drawableId, density); |
Svetoslav | c7d62f0 | 2014-09-04 15:39:54 -0700 | [diff] [blame] | 1335 | } |
| 1336 | return null; |
| 1337 | } |
| 1338 | |
| 1339 | @Override |
| 1340 | public CharSequence getUserBadgedLabel(CharSequence label, UserHandle user) { |
Tony Mak | 8673b28 | 2016-03-21 21:10:59 +0000 | [diff] [blame] | 1341 | if (isManagedProfile(user.getIdentifier())) { |
Kenny Guy | 02c8990 | 2016-11-15 19:36:38 +0000 | [diff] [blame] | 1342 | int badge = getUserManager().getManagedProfileBadge(user.getIdentifier()); |
| 1343 | int resourceId = CORP_BADGE_LABEL_RES_ID[badge % CORP_BADGE_LABEL_RES_ID.length]; |
| 1344 | return Resources.getSystem().getString(resourceId, label); |
Svetoslav | c7d62f0 | 2014-09-04 15:39:54 -0700 | [diff] [blame] | 1345 | } |
| 1346 | return label; |
| 1347 | } |
| 1348 | |
Alan Viverette | ecd585a | 2015-04-13 10:32:51 -0700 | [diff] [blame] | 1349 | @Override |
| 1350 | public Resources getResourcesForActivity(ComponentName activityName) |
| 1351 | throws NameNotFoundException { |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 1352 | return getResourcesForApplication( |
Adam Lesinski | d00bb5e | 2014-10-07 12:14:45 -0700 | [diff] [blame] | 1353 | getActivityInfo(activityName, sDefaultFlags).applicationInfo); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 1354 | } |
| 1355 | |
Alan Viverette | ecd585a | 2015-04-13 10:32:51 -0700 | [diff] [blame] | 1356 | @Override |
| 1357 | public Resources getResourcesForApplication(@NonNull ApplicationInfo app) |
| 1358 | throws NameNotFoundException { |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 1359 | if (app.packageName.equals("system")) { |
Adam Lesinski | a82b626 | 2017-03-21 16:56:17 -0700 | [diff] [blame] | 1360 | return mContext.mMainThread.getSystemUiContext().getResources(); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 1361 | } |
Jeff Sharkey | 8a4c972 | 2014-06-16 13:48:42 -0700 | [diff] [blame] | 1362 | final boolean sameUid = (app.uid == Process.myUid()); |
Adam Lesinski | 53fafdf | 2016-08-03 13:36:39 -0700 | [diff] [blame] | 1363 | final Resources r = mContext.mMainThread.getTopLevelResources( |
Adam Lesinski | c82f28a | 2016-06-08 17:19:09 -0700 | [diff] [blame] | 1364 | sameUid ? app.sourceDir : app.publicSourceDir, |
| 1365 | sameUid ? app.splitSourceDirs : app.splitPublicSourceDirs, |
| 1366 | app.resourceDirs, app.sharedLibraryFiles, Display.DEFAULT_DISPLAY, |
| 1367 | mContext.mPackageInfo); |
Adam Lesinski | 53fafdf | 2016-08-03 13:36:39 -0700 | [diff] [blame] | 1368 | if (r != null) { |
| 1369 | return r; |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 1370 | } |
Adam Lesinski | 53fafdf | 2016-08-03 13:36:39 -0700 | [diff] [blame] | 1371 | throw new NameNotFoundException("Unable to open " + app.publicSourceDir); |
| 1372 | |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 1373 | } |
| 1374 | |
Alan Viverette | ecd585a | 2015-04-13 10:32:51 -0700 | [diff] [blame] | 1375 | @Override |
| 1376 | public Resources getResourcesForApplication(String appPackageName) |
| 1377 | throws NameNotFoundException { |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 1378 | return getResourcesForApplication( |
Adam Lesinski | d00bb5e | 2014-10-07 12:14:45 -0700 | [diff] [blame] | 1379 | getApplicationInfo(appPackageName, sDefaultFlags)); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 1380 | } |
| 1381 | |
Amith Yamasani | 98edc95 | 2012-09-25 14:09:27 -0700 | [diff] [blame] | 1382 | /** @hide */ |
| 1383 | @Override |
| 1384 | public Resources getResourcesForApplicationAsUser(String appPackageName, int userId) |
| 1385 | throws NameNotFoundException { |
Jeff Sharkey | ded653b | 2012-09-27 19:09:24 -0700 | [diff] [blame] | 1386 | if (userId < 0) { |
| 1387 | throw new IllegalArgumentException( |
| 1388 | "Call does not support special user #" + userId); |
| 1389 | } |
| 1390 | if ("system".equals(appPackageName)) { |
Adam Lesinski | a82b626 | 2017-03-21 16:56:17 -0700 | [diff] [blame] | 1391 | return mContext.mMainThread.getSystemUiContext().getResources(); |
Jeff Sharkey | ded653b | 2012-09-27 19:09:24 -0700 | [diff] [blame] | 1392 | } |
Amith Yamasani | 98edc95 | 2012-09-25 14:09:27 -0700 | [diff] [blame] | 1393 | try { |
Adam Lesinski | d00bb5e | 2014-10-07 12:14:45 -0700 | [diff] [blame] | 1394 | ApplicationInfo ai = mPM.getApplicationInfo(appPackageName, sDefaultFlags, userId); |
Amith Yamasani | 98edc95 | 2012-09-25 14:09:27 -0700 | [diff] [blame] | 1395 | if (ai != null) { |
| 1396 | return getResourcesForApplication(ai); |
| 1397 | } |
| 1398 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1399 | throw e.rethrowFromSystemServer(); |
Amith Yamasani | 98edc95 | 2012-09-25 14:09:27 -0700 | [diff] [blame] | 1400 | } |
| 1401 | throw new NameNotFoundException("Package " + appPackageName + " doesn't exist"); |
| 1402 | } |
| 1403 | |
Jeff Sharkey | cd65448 | 2016-01-08 17:42:11 -0700 | [diff] [blame] | 1404 | volatile int mCachedSafeMode = -1; |
| 1405 | |
| 1406 | @Override |
| 1407 | public boolean isSafeMode() { |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 1408 | try { |
| 1409 | if (mCachedSafeMode < 0) { |
| 1410 | mCachedSafeMode = mPM.isSafeMode() ? 1 : 0; |
| 1411 | } |
| 1412 | return mCachedSafeMode != 0; |
| 1413 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1414 | throw e.rethrowFromSystemServer(); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 1415 | } |
| 1416 | } |
| 1417 | |
Svetoslav | f7c06eb | 2015-06-10 18:43:22 -0700 | [diff] [blame] | 1418 | @Override |
| 1419 | public void addOnPermissionsChangeListener(OnPermissionsChangedListener listener) { |
| 1420 | synchronized (mPermissionListeners) { |
| 1421 | if (mPermissionListeners.get(listener) != null) { |
| 1422 | return; |
| 1423 | } |
| 1424 | OnPermissionsChangeListenerDelegate delegate = |
| 1425 | new OnPermissionsChangeListenerDelegate(listener, Looper.getMainLooper()); |
| 1426 | try { |
| 1427 | mPM.addOnPermissionsChangeListener(delegate); |
| 1428 | mPermissionListeners.put(listener, delegate); |
| 1429 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1430 | throw e.rethrowFromSystemServer(); |
Svetoslav | f7c06eb | 2015-06-10 18:43:22 -0700 | [diff] [blame] | 1431 | } |
| 1432 | } |
| 1433 | } |
| 1434 | |
| 1435 | @Override |
| 1436 | public void removeOnPermissionsChangeListener(OnPermissionsChangedListener listener) { |
| 1437 | synchronized (mPermissionListeners) { |
| 1438 | IOnPermissionsChangeListener delegate = mPermissionListeners.get(listener); |
| 1439 | if (delegate != null) { |
| 1440 | try { |
| 1441 | mPM.removeOnPermissionsChangeListener(delegate); |
| 1442 | mPermissionListeners.remove(listener); |
| 1443 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1444 | throw e.rethrowFromSystemServer(); |
Svetoslav | f7c06eb | 2015-06-10 18:43:22 -0700 | [diff] [blame] | 1445 | } |
| 1446 | } |
| 1447 | } |
| 1448 | } |
| 1449 | |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 1450 | static void configurationChanged() { |
| 1451 | synchronized (sSync) { |
| 1452 | sIconCache.clear(); |
| 1453 | sStringCache.clear(); |
| 1454 | } |
| 1455 | } |
| 1456 | |
Yao Chen | 022b8ea | 2016-12-16 11:03:28 -0800 | [diff] [blame] | 1457 | protected ApplicationPackageManager(ContextImpl context, |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 1458 | IPackageManager pm) { |
| 1459 | mContext = context; |
| 1460 | mPM = pm; |
| 1461 | } |
| 1462 | |
Alan Viverette | ecd585a | 2015-04-13 10:32:51 -0700 | [diff] [blame] | 1463 | @Nullable |
| 1464 | private Drawable getCachedIcon(@NonNull ResourceName name) { |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 1465 | synchronized (sSync) { |
Alan Viverette | ecd585a | 2015-04-13 10:32:51 -0700 | [diff] [blame] | 1466 | final WeakReference<Drawable.ConstantState> wr = sIconCache.get(name); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 1467 | if (DEBUG_ICONS) Log.v(TAG, "Get cached weak drawable ref for " |
| 1468 | + name + ": " + wr); |
| 1469 | if (wr != null) { // we have the activity |
Alan Viverette | ecd585a | 2015-04-13 10:32:51 -0700 | [diff] [blame] | 1470 | final Drawable.ConstantState state = wr.get(); |
Romain Guy | 39fe17c | 2011-11-30 10:34:07 -0800 | [diff] [blame] | 1471 | if (state != null) { |
| 1472 | if (DEBUG_ICONS) { |
| 1473 | Log.v(TAG, "Get cached drawable state for " + name + ": " + state); |
| 1474 | } |
| 1475 | // Note: It's okay here to not use the newDrawable(Resources) variant |
| 1476 | // of the API. The ConstantState comes from a drawable that was |
| 1477 | // originally created by passing the proper app Resources instance |
| 1478 | // which means the state should already contain the proper |
| 1479 | // resources specific information (like density.) See |
| 1480 | // BitmapDrawable.BitmapState for instance. |
| 1481 | return state.newDrawable(); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 1482 | } |
| 1483 | // our entry has been purged |
| 1484 | sIconCache.remove(name); |
| 1485 | } |
| 1486 | } |
| 1487 | return null; |
| 1488 | } |
| 1489 | |
Alan Viverette | ecd585a | 2015-04-13 10:32:51 -0700 | [diff] [blame] | 1490 | private void putCachedIcon(@NonNull ResourceName name, @NonNull Drawable dr) { |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 1491 | synchronized (sSync) { |
Alan Viverette | ecd585a | 2015-04-13 10:32:51 -0700 | [diff] [blame] | 1492 | sIconCache.put(name, new WeakReference<>(dr.getConstantState())); |
Romain Guy | 39fe17c | 2011-11-30 10:34:07 -0800 | [diff] [blame] | 1493 | 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] | 1494 | } |
| 1495 | } |
| 1496 | |
Romain Guy | 39fe17c | 2011-11-30 10:34:07 -0800 | [diff] [blame] | 1497 | static void handlePackageBroadcast(int cmd, String[] pkgList, boolean hasPkgInfo) { |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 1498 | boolean immediateGc = false; |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 1499 | if (cmd == ApplicationThreadConstants.EXTERNAL_STORAGE_UNAVAILABLE) { |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 1500 | immediateGc = true; |
| 1501 | } |
| 1502 | if (pkgList != null && (pkgList.length > 0)) { |
| 1503 | boolean needCleanup = false; |
| 1504 | for (String ssp : pkgList) { |
| 1505 | synchronized (sSync) { |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 1506 | for (int i=sIconCache.size()-1; i>=0; i--) { |
| 1507 | ResourceName nm = sIconCache.keyAt(i); |
| 1508 | if (nm.packageName.equals(ssp)) { |
| 1509 | //Log.i(TAG, "Removing cached drawable for " + nm); |
| 1510 | sIconCache.removeAt(i); |
| 1511 | needCleanup = true; |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 1512 | } |
| 1513 | } |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 1514 | for (int i=sStringCache.size()-1; i>=0; i--) { |
| 1515 | ResourceName nm = sStringCache.keyAt(i); |
| 1516 | if (nm.packageName.equals(ssp)) { |
| 1517 | //Log.i(TAG, "Removing cached string for " + nm); |
| 1518 | sStringCache.removeAt(i); |
| 1519 | needCleanup = true; |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 1520 | } |
| 1521 | } |
| 1522 | } |
| 1523 | } |
| 1524 | if (needCleanup || hasPkgInfo) { |
| 1525 | if (immediateGc) { |
| 1526 | // Schedule an immediate gc. |
| 1527 | Runtime.getRuntime().gc(); |
| 1528 | } else { |
| 1529 | ActivityThread.currentActivityThread().scheduleGcIdler(); |
| 1530 | } |
| 1531 | } |
| 1532 | } |
| 1533 | } |
| 1534 | |
| 1535 | private static final class ResourceName { |
| 1536 | final String packageName; |
| 1537 | final int iconId; |
| 1538 | |
| 1539 | ResourceName(String _packageName, int _iconId) { |
| 1540 | packageName = _packageName; |
| 1541 | iconId = _iconId; |
| 1542 | } |
| 1543 | |
| 1544 | ResourceName(ApplicationInfo aInfo, int _iconId) { |
| 1545 | this(aInfo.packageName, _iconId); |
| 1546 | } |
| 1547 | |
| 1548 | ResourceName(ComponentInfo cInfo, int _iconId) { |
| 1549 | this(cInfo.applicationInfo.packageName, _iconId); |
| 1550 | } |
| 1551 | |
| 1552 | ResourceName(ResolveInfo rInfo, int _iconId) { |
| 1553 | this(rInfo.activityInfo.applicationInfo.packageName, _iconId); |
| 1554 | } |
| 1555 | |
| 1556 | @Override |
| 1557 | public boolean equals(Object o) { |
| 1558 | if (this == o) return true; |
| 1559 | if (o == null || getClass() != o.getClass()) return false; |
| 1560 | |
| 1561 | ResourceName that = (ResourceName) o; |
| 1562 | |
| 1563 | if (iconId != that.iconId) return false; |
| 1564 | return !(packageName != null ? |
| 1565 | !packageName.equals(that.packageName) : that.packageName != null); |
| 1566 | |
| 1567 | } |
| 1568 | |
| 1569 | @Override |
| 1570 | public int hashCode() { |
| 1571 | int result; |
| 1572 | result = packageName.hashCode(); |
| 1573 | result = 31 * result + iconId; |
| 1574 | return result; |
| 1575 | } |
| 1576 | |
| 1577 | @Override |
| 1578 | public String toString() { |
| 1579 | return "{ResourceName " + packageName + " / " + iconId + "}"; |
| 1580 | } |
| 1581 | } |
| 1582 | |
| 1583 | private CharSequence getCachedString(ResourceName name) { |
| 1584 | synchronized (sSync) { |
| 1585 | WeakReference<CharSequence> wr = sStringCache.get(name); |
| 1586 | if (wr != null) { // we have the activity |
| 1587 | CharSequence cs = wr.get(); |
| 1588 | if (cs != null) { |
| 1589 | return cs; |
| 1590 | } |
| 1591 | // our entry has been purged |
| 1592 | sStringCache.remove(name); |
| 1593 | } |
| 1594 | } |
| 1595 | return null; |
| 1596 | } |
| 1597 | |
| 1598 | private void putCachedString(ResourceName name, CharSequence cs) { |
| 1599 | synchronized (sSync) { |
| 1600 | sStringCache.put(name, new WeakReference<CharSequence>(cs)); |
| 1601 | } |
| 1602 | } |
| 1603 | |
| 1604 | @Override |
Tor Norbye | 7b9c912 | 2013-05-30 16:48:33 -0700 | [diff] [blame] | 1605 | public CharSequence getText(String packageName, @StringRes int resid, |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 1606 | ApplicationInfo appInfo) { |
| 1607 | ResourceName name = new ResourceName(packageName, resid); |
| 1608 | CharSequence text = getCachedString(name); |
| 1609 | if (text != null) { |
| 1610 | return text; |
| 1611 | } |
| 1612 | if (appInfo == null) { |
| 1613 | try { |
Adam Lesinski | d00bb5e | 2014-10-07 12:14:45 -0700 | [diff] [blame] | 1614 | appInfo = getApplicationInfo(packageName, sDefaultFlags); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 1615 | } catch (NameNotFoundException e) { |
| 1616 | return null; |
| 1617 | } |
| 1618 | } |
| 1619 | try { |
| 1620 | Resources r = getResourcesForApplication(appInfo); |
| 1621 | text = r.getText(resid); |
| 1622 | putCachedString(name, text); |
| 1623 | return text; |
| 1624 | } catch (NameNotFoundException e) { |
Dianne Hackborn | aec68bb | 2014-08-20 15:25:13 -0700 | [diff] [blame] | 1625 | Log.w("PackageManager", "Failure retrieving resources for " |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 1626 | + appInfo.packageName); |
| 1627 | } catch (RuntimeException e) { |
| 1628 | // If an exception was thrown, fall through to return |
| 1629 | // default icon. |
| 1630 | Log.w("PackageManager", "Failure retrieving text 0x" |
| 1631 | + Integer.toHexString(resid) + " in package " |
| 1632 | + packageName, e); |
| 1633 | } |
| 1634 | return null; |
| 1635 | } |
| 1636 | |
| 1637 | @Override |
Tor Norbye | 7b9c912 | 2013-05-30 16:48:33 -0700 | [diff] [blame] | 1638 | public XmlResourceParser getXml(String packageName, @XmlRes int resid, |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 1639 | ApplicationInfo appInfo) { |
| 1640 | if (appInfo == null) { |
| 1641 | try { |
Adam Lesinski | d00bb5e | 2014-10-07 12:14:45 -0700 | [diff] [blame] | 1642 | appInfo = getApplicationInfo(packageName, sDefaultFlags); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 1643 | } catch (NameNotFoundException e) { |
| 1644 | return null; |
| 1645 | } |
| 1646 | } |
| 1647 | try { |
| 1648 | Resources r = getResourcesForApplication(appInfo); |
| 1649 | return r.getXml(resid); |
| 1650 | } catch (RuntimeException e) { |
| 1651 | // If an exception was thrown, fall through to return |
| 1652 | // default icon. |
| 1653 | Log.w("PackageManager", "Failure retrieving xml 0x" |
| 1654 | + Integer.toHexString(resid) + " in package " |
| 1655 | + packageName, e); |
| 1656 | } catch (NameNotFoundException e) { |
Alon Albert | 3fa51e3 | 2010-11-11 09:24:04 -0800 | [diff] [blame] | 1657 | Log.w("PackageManager", "Failure retrieving resources for " |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 1658 | + appInfo.packageName); |
| 1659 | } |
| 1660 | return null; |
| 1661 | } |
| 1662 | |
| 1663 | @Override |
| 1664 | public CharSequence getApplicationLabel(ApplicationInfo info) { |
| 1665 | return info.loadLabel(this); |
| 1666 | } |
| 1667 | |
| 1668 | @Override |
| 1669 | public void installPackage(Uri packageURI, IPackageInstallObserver observer, int flags, |
| 1670 | String installerPackageName) { |
Jeff Sharkey | 513a074 | 2014-07-08 17:10:32 -0700 | [diff] [blame] | 1671 | installCommon(packageURI, new LegacyPackageInstallObserver(observer), flags, |
Todd Kennedy | a679323 | 2016-02-24 22:46:00 +0000 | [diff] [blame] | 1672 | installerPackageName, mContext.getUserId()); |
Christopher Tate | f1977b4 | 2014-03-24 16:25:51 -0700 | [diff] [blame] | 1673 | } |
| 1674 | |
Christopher Tate | f1977b4 | 2014-03-24 16:25:51 -0700 | [diff] [blame] | 1675 | @Override |
| 1676 | public void installPackage(Uri packageURI, PackageInstallObserver observer, |
| 1677 | int flags, String installerPackageName) { |
Todd Kennedy | a679323 | 2016-02-24 22:46:00 +0000 | [diff] [blame] | 1678 | installCommon(packageURI, observer, flags, installerPackageName, mContext.getUserId()); |
Jeff Sharkey | 513a074 | 2014-07-08 17:10:32 -0700 | [diff] [blame] | 1679 | } |
| 1680 | |
| 1681 | private void installCommon(Uri packageURI, |
| 1682 | PackageInstallObserver observer, int flags, String installerPackageName, |
Nicolas Prevot | 9a80e53 | 2015-09-23 15:49:28 +0100 | [diff] [blame] | 1683 | int userId) { |
Jeff Sharkey | 513a074 | 2014-07-08 17:10:32 -0700 | [diff] [blame] | 1684 | if (!"file".equals(packageURI.getScheme())) { |
| 1685 | throw new UnsupportedOperationException("Only file:// URIs are supported"); |
| 1686 | } |
Jeff Sharkey | 513a074 | 2014-07-08 17:10:32 -0700 | [diff] [blame] | 1687 | |
| 1688 | final String originPath = packageURI.getPath(); |
Christopher Tate | f1977b4 | 2014-03-24 16:25:51 -0700 | [diff] [blame] | 1689 | try { |
Nicolas Prevot | 9a80e53 | 2015-09-23 15:49:28 +0100 | [diff] [blame] | 1690 | mPM.installPackageAsUser(originPath, observer.getBinder(), flags, installerPackageName, |
Todd Kennedy | a679323 | 2016-02-24 22:46:00 +0000 | [diff] [blame] | 1691 | userId); |
Jeff Sharkey | 27b2e69 | 2016-02-25 17:40:12 -0700 | [diff] [blame] | 1692 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1693 | throw e.rethrowFromSystemServer(); |
rich cannings | 706e8ba | 2012-08-20 13:20:14 -0700 | [diff] [blame] | 1694 | } |
| 1695 | } |
| 1696 | |
| 1697 | @Override |
Nicolas Prevot | 9a80e53 | 2015-09-23 15:49:28 +0100 | [diff] [blame] | 1698 | public int installExistingPackage(String packageName) throws NameNotFoundException { |
Sunny Goyal | a31a74b | 2017-05-11 15:59:19 -0700 | [diff] [blame] | 1699 | return installExistingPackage(packageName, PackageManager.INSTALL_REASON_UNKNOWN); |
| 1700 | } |
| 1701 | |
| 1702 | @Override |
| 1703 | public int installExistingPackage(String packageName, int installReason) |
| 1704 | throws NameNotFoundException { |
| 1705 | return installExistingPackageAsUser(packageName, installReason, mContext.getUserId()); |
Nicolas Prevot | 9a80e53 | 2015-09-23 15:49:28 +0100 | [diff] [blame] | 1706 | } |
| 1707 | |
| 1708 | @Override |
| 1709 | public int installExistingPackageAsUser(String packageName, int userId) |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 1710 | throws NameNotFoundException { |
Sunny Goyal | a31a74b | 2017-05-11 15:59:19 -0700 | [diff] [blame] | 1711 | return installExistingPackageAsUser(packageName, PackageManager.INSTALL_REASON_UNKNOWN, |
| 1712 | userId); |
| 1713 | } |
| 1714 | |
| 1715 | private int installExistingPackageAsUser(String packageName, int installReason, int userId) |
| 1716 | throws NameNotFoundException { |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 1717 | try { |
Todd Kennedy | be0b889 | 2017-02-15 14:13:52 -0800 | [diff] [blame] | 1718 | int res = mPM.installExistingPackageAsUser(packageName, userId, 0 /*installFlags*/, |
Sunny Goyal | a31a74b | 2017-05-11 15:59:19 -0700 | [diff] [blame] | 1719 | installReason); |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 1720 | if (res == INSTALL_FAILED_INVALID_URI) { |
| 1721 | throw new NameNotFoundException("Package " + packageName + " doesn't exist"); |
| 1722 | } |
| 1723 | return res; |
| 1724 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1725 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 7767eac | 2012-08-23 18:25:40 -0700 | [diff] [blame] | 1726 | } |
| 1727 | } |
| 1728 | |
| 1729 | @Override |
Kenny Root | 3a9b5fb | 2011-09-20 14:15:38 -0700 | [diff] [blame] | 1730 | public void verifyPendingInstall(int id, int response) { |
Kenny Root | 5ab2157 | 2011-07-27 11:11:19 -0700 | [diff] [blame] | 1731 | try { |
Kenny Root | 3a9b5fb | 2011-09-20 14:15:38 -0700 | [diff] [blame] | 1732 | mPM.verifyPendingInstall(id, response); |
Kenny Root | 5ab2157 | 2011-07-27 11:11:19 -0700 | [diff] [blame] | 1733 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1734 | throw e.rethrowFromSystemServer(); |
Kenny Root | 5ab2157 | 2011-07-27 11:11:19 -0700 | [diff] [blame] | 1735 | } |
| 1736 | } |
| 1737 | |
| 1738 | @Override |
rich cannings | d9ef3e5 | 2012-08-22 14:28:05 -0700 | [diff] [blame] | 1739 | public void extendVerificationTimeout(int id, int verificationCodeAtTimeout, |
| 1740 | long millisecondsToDelay) { |
| 1741 | try { |
| 1742 | mPM.extendVerificationTimeout(id, verificationCodeAtTimeout, millisecondsToDelay); |
| 1743 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1744 | throw e.rethrowFromSystemServer(); |
rich cannings | d9ef3e5 | 2012-08-22 14:28:05 -0700 | [diff] [blame] | 1745 | } |
| 1746 | } |
| 1747 | |
| 1748 | @Override |
Todd Kennedy | dfa93ab | 2016-03-03 15:24:33 -0800 | [diff] [blame] | 1749 | public void verifyIntentFilter(int id, int verificationCode, List<String> failedDomains) { |
Fabrice Di Meglio | 1c1b471 | 2014-11-19 17:12:32 -0800 | [diff] [blame] | 1750 | try { |
Todd Kennedy | dfa93ab | 2016-03-03 15:24:33 -0800 | [diff] [blame] | 1751 | mPM.verifyIntentFilter(id, verificationCode, failedDomains); |
Fabrice Di Meglio | 1c1b471 | 2014-11-19 17:12:32 -0800 | [diff] [blame] | 1752 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1753 | throw e.rethrowFromSystemServer(); |
Fabrice Di Meglio | 1c1b471 | 2014-11-19 17:12:32 -0800 | [diff] [blame] | 1754 | } |
| 1755 | } |
| 1756 | |
| 1757 | @Override |
Jeff Sharkey | e06b4d1 | 2016-01-06 14:51:50 -0700 | [diff] [blame] | 1758 | public int getIntentVerificationStatusAsUser(String packageName, int userId) { |
Fabrice Di Meglio | 1c1b471 | 2014-11-19 17:12:32 -0800 | [diff] [blame] | 1759 | try { |
| 1760 | return mPM.getIntentVerificationStatus(packageName, userId); |
| 1761 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1762 | throw e.rethrowFromSystemServer(); |
Fabrice Di Meglio | 1c1b471 | 2014-11-19 17:12:32 -0800 | [diff] [blame] | 1763 | } |
| 1764 | } |
| 1765 | |
| 1766 | @Override |
Jeff Sharkey | e06b4d1 | 2016-01-06 14:51:50 -0700 | [diff] [blame] | 1767 | public boolean updateIntentVerificationStatusAsUser(String packageName, int status, int userId) { |
Fabrice Di Meglio | 1c1b471 | 2014-11-19 17:12:32 -0800 | [diff] [blame] | 1768 | try { |
| 1769 | return mPM.updateIntentVerificationStatus(packageName, status, userId); |
| 1770 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1771 | throw e.rethrowFromSystemServer(); |
Fabrice Di Meglio | 1c1b471 | 2014-11-19 17:12:32 -0800 | [diff] [blame] | 1772 | } |
| 1773 | } |
| 1774 | |
| 1775 | @Override |
Svetoslav Ganov | b2c2e45 | 2016-03-24 18:01:17 -0700 | [diff] [blame] | 1776 | @SuppressWarnings("unchecked") |
Fabrice Di Meglio | 1c1b471 | 2014-11-19 17:12:32 -0800 | [diff] [blame] | 1777 | public List<IntentFilterVerificationInfo> getIntentFilterVerifications(String packageName) { |
| 1778 | try { |
Svetoslav Ganov | b2c2e45 | 2016-03-24 18:01:17 -0700 | [diff] [blame] | 1779 | ParceledListSlice<IntentFilterVerificationInfo> parceledList = |
| 1780 | mPM.getIntentFilterVerifications(packageName); |
| 1781 | if (parceledList == null) { |
| 1782 | return Collections.emptyList(); |
| 1783 | } |
| 1784 | return parceledList.getList(); |
Fabrice Di Meglio | 1c1b471 | 2014-11-19 17:12:32 -0800 | [diff] [blame] | 1785 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1786 | throw e.rethrowFromSystemServer(); |
Fabrice Di Meglio | 1c1b471 | 2014-11-19 17:12:32 -0800 | [diff] [blame] | 1787 | } |
| 1788 | } |
| 1789 | |
| 1790 | @Override |
Svetoslav Ganov | b2c2e45 | 2016-03-24 18:01:17 -0700 | [diff] [blame] | 1791 | @SuppressWarnings("unchecked") |
Fabrice Di Meglio | 0788595 | 2015-04-06 19:41:28 -0700 | [diff] [blame] | 1792 | public List<IntentFilter> getAllIntentFilters(String packageName) { |
| 1793 | try { |
Svetoslav Ganov | b2c2e45 | 2016-03-24 18:01:17 -0700 | [diff] [blame] | 1794 | ParceledListSlice<IntentFilter> parceledList = |
| 1795 | mPM.getAllIntentFilters(packageName); |
| 1796 | if (parceledList == null) { |
| 1797 | return Collections.emptyList(); |
| 1798 | } |
| 1799 | return parceledList.getList(); |
Fabrice Di Meglio | 0788595 | 2015-04-06 19:41:28 -0700 | [diff] [blame] | 1800 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1801 | throw e.rethrowFromSystemServer(); |
Fabrice Di Meglio | 0788595 | 2015-04-06 19:41:28 -0700 | [diff] [blame] | 1802 | } |
| 1803 | } |
| 1804 | |
| 1805 | @Override |
Jeff Sharkey | e06b4d1 | 2016-01-06 14:51:50 -0700 | [diff] [blame] | 1806 | public String getDefaultBrowserPackageNameAsUser(int userId) { |
Fabrice Di Meglio | 6227172 | 2015-04-10 17:24:02 -0700 | [diff] [blame] | 1807 | try { |
| 1808 | return mPM.getDefaultBrowserPackageName(userId); |
| 1809 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1810 | throw e.rethrowFromSystemServer(); |
Fabrice Di Meglio | 6227172 | 2015-04-10 17:24:02 -0700 | [diff] [blame] | 1811 | } |
| 1812 | } |
| 1813 | |
| 1814 | @Override |
Jeff Sharkey | e06b4d1 | 2016-01-06 14:51:50 -0700 | [diff] [blame] | 1815 | public boolean setDefaultBrowserPackageNameAsUser(String packageName, int userId) { |
Fabrice Di Meglio | 6227172 | 2015-04-10 17:24:02 -0700 | [diff] [blame] | 1816 | try { |
| 1817 | return mPM.setDefaultBrowserPackageName(packageName, userId); |
| 1818 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1819 | throw e.rethrowFromSystemServer(); |
Fabrice Di Meglio | 6227172 | 2015-04-10 17:24:02 -0700 | [diff] [blame] | 1820 | } |
| 1821 | } |
| 1822 | |
| 1823 | @Override |
Dianne Hackborn | 880119b | 2010-11-18 22:26:40 -0800 | [diff] [blame] | 1824 | public void setInstallerPackageName(String targetPackage, |
| 1825 | String installerPackageName) { |
| 1826 | try { |
| 1827 | mPM.setInstallerPackageName(targetPackage, installerPackageName); |
| 1828 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1829 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 880119b | 2010-11-18 22:26:40 -0800 | [diff] [blame] | 1830 | } |
| 1831 | } |
| 1832 | |
| 1833 | @Override |
Todd Kennedy | ab53289 | 2017-03-08 14:19:49 -0800 | [diff] [blame] | 1834 | public void setUpdateAvailable(String packageName, boolean updateAvailable) { |
| 1835 | try { |
| 1836 | mPM.setUpdateAvailable(packageName, updateAvailable); |
| 1837 | } catch (RemoteException e) { |
| 1838 | throw e.rethrowFromSystemServer(); |
| 1839 | } |
| 1840 | } |
| 1841 | |
| 1842 | @Override |
Jeff Sharkey | 620b32b | 2015-04-23 19:36:02 -0700 | [diff] [blame] | 1843 | public String getInstallerPackageName(String packageName) { |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 1844 | try { |
Jeff Sharkey | 620b32b | 2015-04-23 19:36:02 -0700 | [diff] [blame] | 1845 | return mPM.getInstallerPackageName(packageName); |
| 1846 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1847 | throw e.rethrowFromSystemServer(); |
Jeff Sharkey | 620b32b | 2015-04-23 19:36:02 -0700 | [diff] [blame] | 1848 | } |
Jeff Sharkey | 620b32b | 2015-04-23 19:36:02 -0700 | [diff] [blame] | 1849 | } |
| 1850 | |
| 1851 | @Override |
| 1852 | public int getMoveStatus(int moveId) { |
| 1853 | try { |
| 1854 | return mPM.getMoveStatus(moveId); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 1855 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1856 | throw e.rethrowFromSystemServer(); |
Jeff Sharkey | b2b9ab8 | 2015-04-05 21:10:42 -0700 | [diff] [blame] | 1857 | } |
| 1858 | } |
| 1859 | |
| 1860 | @Override |
Jeff Sharkey | 620b32b | 2015-04-23 19:36:02 -0700 | [diff] [blame] | 1861 | public void registerMoveCallback(MoveCallback callback, Handler handler) { |
| 1862 | synchronized (mDelegates) { |
| 1863 | final MoveCallbackDelegate delegate = new MoveCallbackDelegate(callback, |
| 1864 | handler.getLooper()); |
| 1865 | try { |
| 1866 | mPM.registerMoveCallback(delegate); |
| 1867 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1868 | throw e.rethrowFromSystemServer(); |
Jeff Sharkey | 620b32b | 2015-04-23 19:36:02 -0700 | [diff] [blame] | 1869 | } |
| 1870 | mDelegates.add(delegate); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 1871 | } |
| 1872 | } |
| 1873 | |
| 1874 | @Override |
Jeff Sharkey | 620b32b | 2015-04-23 19:36:02 -0700 | [diff] [blame] | 1875 | public void unregisterMoveCallback(MoveCallback callback) { |
| 1876 | synchronized (mDelegates) { |
| 1877 | for (Iterator<MoveCallbackDelegate> i = mDelegates.iterator(); i.hasNext();) { |
| 1878 | final MoveCallbackDelegate delegate = i.next(); |
| 1879 | if (delegate.mCallback == callback) { |
| 1880 | try { |
| 1881 | mPM.unregisterMoveCallback(delegate); |
| 1882 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1883 | throw e.rethrowFromSystemServer(); |
Jeff Sharkey | 620b32b | 2015-04-23 19:36:02 -0700 | [diff] [blame] | 1884 | } |
| 1885 | i.remove(); |
Jeff Sharkey | e2d45be | 2015-04-15 17:14:12 -0700 | [diff] [blame] | 1886 | } |
| 1887 | } |
Jeff Sharkey | e2d45be | 2015-04-15 17:14:12 -0700 | [diff] [blame] | 1888 | } |
| 1889 | } |
| 1890 | |
| 1891 | @Override |
Jeff Sharkey | 620b32b | 2015-04-23 19:36:02 -0700 | [diff] [blame] | 1892 | public int movePackage(String packageName, VolumeInfo vol) { |
| 1893 | try { |
| 1894 | final String volumeUuid; |
| 1895 | if (VolumeInfo.ID_PRIVATE_INTERNAL.equals(vol.id)) { |
| 1896 | volumeUuid = StorageManager.UUID_PRIVATE_INTERNAL; |
| 1897 | } else if (vol.isPrimaryPhysical()) { |
| 1898 | volumeUuid = StorageManager.UUID_PRIMARY_PHYSICAL; |
| 1899 | } else { |
| 1900 | volumeUuid = Preconditions.checkNotNull(vol.fsUuid); |
| 1901 | } |
| 1902 | |
| 1903 | return mPM.movePackage(packageName, volumeUuid); |
| 1904 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1905 | throw e.rethrowFromSystemServer(); |
Jeff Sharkey | 620b32b | 2015-04-23 19:36:02 -0700 | [diff] [blame] | 1906 | } |
| 1907 | } |
| 1908 | |
| 1909 | @Override |
| 1910 | public @Nullable VolumeInfo getPackageCurrentVolume(ApplicationInfo app) { |
Jeff Sharkey | e2d45be | 2015-04-15 17:14:12 -0700 | [diff] [blame] | 1911 | final StorageManager storage = mContext.getSystemService(StorageManager.class); |
Yao Chen | 022b8ea | 2016-12-16 11:03:28 -0800 | [diff] [blame] | 1912 | return getPackageCurrentVolume(app, storage); |
| 1913 | } |
| 1914 | |
| 1915 | @VisibleForTesting |
| 1916 | protected @Nullable VolumeInfo getPackageCurrentVolume(ApplicationInfo app, |
| 1917 | StorageManager storage) { |
Jeff Sharkey | 620b32b | 2015-04-23 19:36:02 -0700 | [diff] [blame] | 1918 | if (app.isInternal()) { |
| 1919 | return storage.findVolumeById(VolumeInfo.ID_PRIVATE_INTERNAL); |
| 1920 | } else if (app.isExternalAsec()) { |
| 1921 | return storage.getPrimaryPhysicalVolume(); |
| 1922 | } else { |
| 1923 | return storage.findVolumeByUuid(app.volumeUuid); |
| 1924 | } |
| 1925 | } |
| 1926 | |
| 1927 | @Override |
| 1928 | public @NonNull List<VolumeInfo> getPackageCandidateVolumes(ApplicationInfo app) { |
Yao Chen | 022b8ea | 2016-12-16 11:03:28 -0800 | [diff] [blame] | 1929 | final StorageManager storageManager = mContext.getSystemService(StorageManager.class); |
| 1930 | return getPackageCandidateVolumes(app, storageManager, mPM); |
| 1931 | } |
| 1932 | |
| 1933 | @VisibleForTesting |
| 1934 | protected @NonNull List<VolumeInfo> getPackageCandidateVolumes(ApplicationInfo app, |
| 1935 | StorageManager storageManager, IPackageManager pm) { |
| 1936 | final VolumeInfo currentVol = getPackageCurrentVolume(app, storageManager); |
| 1937 | final List<VolumeInfo> vols = storageManager.getVolumes(); |
Jeff Sharkey | e2d45be | 2015-04-15 17:14:12 -0700 | [diff] [blame] | 1938 | final List<VolumeInfo> candidates = new ArrayList<>(); |
| 1939 | for (VolumeInfo vol : vols) { |
Yao Chen | 022b8ea | 2016-12-16 11:03:28 -0800 | [diff] [blame] | 1940 | if (Objects.equals(vol, currentVol) |
| 1941 | || isPackageCandidateVolume(mContext, app, vol, pm)) { |
Jeff Sharkey | e2d45be | 2015-04-15 17:14:12 -0700 | [diff] [blame] | 1942 | candidates.add(vol); |
| 1943 | } |
| 1944 | } |
| 1945 | return candidates; |
| 1946 | } |
| 1947 | |
Yao Chen | 022b8ea | 2016-12-16 11:03:28 -0800 | [diff] [blame] | 1948 | @VisibleForTesting |
| 1949 | protected boolean isForceAllowOnExternal(Context context) { |
| 1950 | return Settings.Global.getInt( |
Todd Kennedy | f39ca8f | 2015-08-07 14:15:07 -0700 | [diff] [blame] | 1951 | context.getContentResolver(), Settings.Global.FORCE_ALLOW_ON_EXTERNAL, 0) != 0; |
Yao Chen | 022b8ea | 2016-12-16 11:03:28 -0800 | [diff] [blame] | 1952 | } |
| 1953 | |
| 1954 | @VisibleForTesting |
| 1955 | protected boolean isAllow3rdPartyOnInternal(Context context) { |
| 1956 | return context.getResources().getBoolean( |
| 1957 | com.android.internal.R.bool.config_allow3rdPartyAppOnInternal); |
| 1958 | } |
| 1959 | |
| 1960 | private boolean isPackageCandidateVolume( |
| 1961 | ContextImpl context, ApplicationInfo app, VolumeInfo vol, IPackageManager pm) { |
| 1962 | final boolean forceAllowOnExternal = isForceAllowOnExternal(context); |
| 1963 | |
Jeff Sharkey | e2d45be | 2015-04-15 17:14:12 -0700 | [diff] [blame] | 1964 | if (VolumeInfo.ID_PRIVATE_INTERNAL.equals(vol.getId())) { |
Yao Chen | 022b8ea | 2016-12-16 11:03:28 -0800 | [diff] [blame] | 1965 | return app.isSystemApp() || isAllow3rdPartyOnInternal(context); |
Jeff Sharkey | e2d45be | 2015-04-15 17:14:12 -0700 | [diff] [blame] | 1966 | } |
| 1967 | |
| 1968 | // System apps and apps demanding internal storage can't be moved |
| 1969 | // anywhere else |
Todd Kennedy | f39ca8f | 2015-08-07 14:15:07 -0700 | [diff] [blame] | 1970 | if (app.isSystemApp()) { |
| 1971 | return false; |
| 1972 | } |
| 1973 | if (!forceAllowOnExternal |
Dianne Hackborn | 30a4e6d | 2015-10-12 17:14:56 -0700 | [diff] [blame] | 1974 | && (app.installLocation == PackageInfo.INSTALL_LOCATION_INTERNAL_ONLY |
| 1975 | || app.installLocation == PackageInfo.INSTALL_LOCATION_UNSPECIFIED)) { |
Jeff Sharkey | e2d45be | 2015-04-15 17:14:12 -0700 | [diff] [blame] | 1976 | return false; |
| 1977 | } |
| 1978 | |
Jeff Sharkey | 620b32b | 2015-04-23 19:36:02 -0700 | [diff] [blame] | 1979 | // Gotta be able to write there |
| 1980 | if (!vol.isMountedWritable()) { |
| 1981 | return false; |
| 1982 | } |
| 1983 | |
| 1984 | // Moving into an ASEC on public primary is only option internal |
| 1985 | if (vol.isPrimaryPhysical()) { |
| 1986 | return app.isInternal(); |
Jeff Sharkey | e2d45be | 2015-04-15 17:14:12 -0700 | [diff] [blame] | 1987 | } |
| 1988 | |
Makoto Onuki | f34db0a | 2016-02-17 11:17:15 -0800 | [diff] [blame] | 1989 | // Some apps can't be moved. (e.g. device admins) |
| 1990 | try { |
Yao Chen | 022b8ea | 2016-12-16 11:03:28 -0800 | [diff] [blame] | 1991 | if (pm.isPackageDeviceAdminOnAnyUser(app.packageName)) { |
Makoto Onuki | f34db0a | 2016-02-17 11:17:15 -0800 | [diff] [blame] | 1992 | return false; |
| 1993 | } |
| 1994 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1995 | throw e.rethrowFromSystemServer(); |
Makoto Onuki | f34db0a | 2016-02-17 11:17:15 -0800 | [diff] [blame] | 1996 | } |
| 1997 | |
Jeff Sharkey | e2d45be | 2015-04-15 17:14:12 -0700 | [diff] [blame] | 1998 | // Otherwise we can move to any private volume |
| 1999 | return (vol.getType() == VolumeInfo.TYPE_PRIVATE); |
| 2000 | } |
| 2001 | |
| 2002 | @Override |
Jeff Sharkey | 620b32b | 2015-04-23 19:36:02 -0700 | [diff] [blame] | 2003 | public int movePrimaryStorage(VolumeInfo vol) { |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 2004 | try { |
Jeff Sharkey | 620b32b | 2015-04-23 19:36:02 -0700 | [diff] [blame] | 2005 | final String volumeUuid; |
| 2006 | if (VolumeInfo.ID_PRIVATE_INTERNAL.equals(vol.id)) { |
| 2007 | volumeUuid = StorageManager.UUID_PRIVATE_INTERNAL; |
| 2008 | } else if (vol.isPrimaryPhysical()) { |
| 2009 | volumeUuid = StorageManager.UUID_PRIMARY_PHYSICAL; |
| 2010 | } else { |
| 2011 | volumeUuid = Preconditions.checkNotNull(vol.fsUuid); |
| 2012 | } |
| 2013 | |
| 2014 | return mPM.movePrimaryStorage(volumeUuid); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 2015 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 2016 | throw e.rethrowFromSystemServer(); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 2017 | } |
Jeff Sharkey | 620b32b | 2015-04-23 19:36:02 -0700 | [diff] [blame] | 2018 | } |
| 2019 | |
Jeff Sharkey | 275e3e4 | 2015-04-24 16:10:32 -0700 | [diff] [blame] | 2020 | @Override |
Jeff Sharkey | 620b32b | 2015-04-23 19:36:02 -0700 | [diff] [blame] | 2021 | public @Nullable VolumeInfo getPrimaryStorageCurrentVolume() { |
| 2022 | final StorageManager storage = mContext.getSystemService(StorageManager.class); |
| 2023 | final String volumeUuid = storage.getPrimaryStorageUuid(); |
Jeff Sharkey | 50a0545 | 2015-04-29 11:24:52 -0700 | [diff] [blame] | 2024 | return storage.findVolumeByQualifiedUuid(volumeUuid); |
Jeff Sharkey | 620b32b | 2015-04-23 19:36:02 -0700 | [diff] [blame] | 2025 | } |
| 2026 | |
Jeff Sharkey | 275e3e4 | 2015-04-24 16:10:32 -0700 | [diff] [blame] | 2027 | @Override |
Jeff Sharkey | 620b32b | 2015-04-23 19:36:02 -0700 | [diff] [blame] | 2028 | public @NonNull List<VolumeInfo> getPrimaryStorageCandidateVolumes() { |
| 2029 | final StorageManager storage = mContext.getSystemService(StorageManager.class); |
| 2030 | final VolumeInfo currentVol = getPrimaryStorageCurrentVolume(); |
| 2031 | final List<VolumeInfo> vols = storage.getVolumes(); |
| 2032 | final List<VolumeInfo> candidates = new ArrayList<>(); |
Jeff Sharkey | fced534 | 2015-05-10 14:53:34 -0700 | [diff] [blame] | 2033 | if (Objects.equals(StorageManager.UUID_PRIMARY_PHYSICAL, |
| 2034 | storage.getPrimaryStorageUuid()) && currentVol != null) { |
| 2035 | // TODO: support moving primary physical to emulated volume |
| 2036 | candidates.add(currentVol); |
| 2037 | } else { |
| 2038 | for (VolumeInfo vol : vols) { |
| 2039 | if (Objects.equals(vol, currentVol) || isPrimaryStorageCandidateVolume(vol)) { |
| 2040 | candidates.add(vol); |
| 2041 | } |
Jeff Sharkey | 620b32b | 2015-04-23 19:36:02 -0700 | [diff] [blame] | 2042 | } |
| 2043 | } |
| 2044 | return candidates; |
| 2045 | } |
| 2046 | |
| 2047 | private static boolean isPrimaryStorageCandidateVolume(VolumeInfo vol) { |
| 2048 | // Private internal is always an option |
| 2049 | if (VolumeInfo.ID_PRIVATE_INTERNAL.equals(vol.getId())) { |
| 2050 | return true; |
| 2051 | } |
| 2052 | |
| 2053 | // Gotta be able to write there |
| 2054 | if (!vol.isMountedWritable()) { |
| 2055 | return false; |
| 2056 | } |
| 2057 | |
Jeff Sharkey | fced534 | 2015-05-10 14:53:34 -0700 | [diff] [blame] | 2058 | // We can move to any private volume |
Jeff Sharkey | 620b32b | 2015-04-23 19:36:02 -0700 | [diff] [blame] | 2059 | return (vol.getType() == VolumeInfo.TYPE_PRIVATE); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 2060 | } |
| 2061 | |
| 2062 | @Override |
| 2063 | public void deletePackage(String packageName, IPackageDeleteObserver observer, int flags) { |
Robin Lee | 0e27c87 | 2015-09-28 14:37:40 +0100 | [diff] [blame] | 2064 | deletePackageAsUser(packageName, observer, flags, mContext.getUserId()); |
Nicolas Prevot | 9a80e53 | 2015-09-23 15:49:28 +0100 | [diff] [blame] | 2065 | } |
| 2066 | |
| 2067 | @Override |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 2068 | public void deletePackageAsUser(String packageName, IPackageDeleteObserver observer, |
| 2069 | int flags, int userId) { |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 2070 | try { |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 2071 | mPM.deletePackageAsUser(packageName, PackageManager.VERSION_CODE_HIGHEST, |
| 2072 | observer, userId, flags); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 2073 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 2074 | throw e.rethrowFromSystemServer(); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 2075 | } |
| 2076 | } |
Jeff Sharkey | fbd0e9f | 2014-08-06 16:34:34 -0700 | [diff] [blame] | 2077 | |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 2078 | @Override |
| 2079 | public void clearApplicationUserData(String packageName, |
| 2080 | IPackageDataObserver observer) { |
| 2081 | try { |
Jeff Sharkey | ded653b | 2012-09-27 19:09:24 -0700 | [diff] [blame] | 2082 | mPM.clearApplicationUserData(packageName, observer, mContext.getUserId()); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 2083 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 2084 | throw e.rethrowFromSystemServer(); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 2085 | } |
| 2086 | } |
| 2087 | @Override |
| 2088 | public void deleteApplicationCacheFiles(String packageName, |
| 2089 | IPackageDataObserver observer) { |
| 2090 | try { |
| 2091 | mPM.deleteApplicationCacheFiles(packageName, observer); |
| 2092 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 2093 | throw e.rethrowFromSystemServer(); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 2094 | } |
| 2095 | } |
Jeff Sharkey | 529f91f | 2015-04-18 20:23:13 -0700 | [diff] [blame] | 2096 | |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 2097 | @Override |
Suprabh Shukla | 78c9eb8 | 2016-04-12 15:51:35 -0700 | [diff] [blame] | 2098 | public void deleteApplicationCacheFilesAsUser(String packageName, int userId, |
| 2099 | IPackageDataObserver observer) { |
| 2100 | try { |
| 2101 | mPM.deleteApplicationCacheFilesAsUser(packageName, userId, observer); |
| 2102 | } catch (RemoteException e) { |
| 2103 | throw e.rethrowFromSystemServer(); |
| 2104 | } |
| 2105 | } |
| 2106 | |
| 2107 | @Override |
Jeff Sharkey | 529f91f | 2015-04-18 20:23:13 -0700 | [diff] [blame] | 2108 | public void freeStorageAndNotify(String volumeUuid, long idealStorageSize, |
| 2109 | IPackageDataObserver observer) { |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 2110 | try { |
Jeff Sharkey | ddff807 | 2017-05-26 13:10:46 -0600 | [diff] [blame] | 2111 | mPM.freeStorageAndNotify(volumeUuid, idealStorageSize, 0, observer); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 2112 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 2113 | throw e.rethrowFromSystemServer(); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 2114 | } |
| 2115 | } |
| 2116 | |
| 2117 | @Override |
Jeff Sharkey | 529f91f | 2015-04-18 20:23:13 -0700 | [diff] [blame] | 2118 | public void freeStorage(String volumeUuid, long freeStorageSize, IntentSender pi) { |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 2119 | try { |
Jeff Sharkey | ddff807 | 2017-05-26 13:10:46 -0600 | [diff] [blame] | 2120 | mPM.freeStorage(volumeUuid, freeStorageSize, 0, pi); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 2121 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 2122 | throw e.rethrowFromSystemServer(); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 2123 | } |
| 2124 | } |
| 2125 | |
| 2126 | @Override |
Andrei Stingaceanu | eb84b18 | 2016-01-26 18:39:55 +0000 | [diff] [blame] | 2127 | public String[] setPackagesSuspendedAsUser(String[] packageNames, boolean suspended, |
| 2128 | int userId) { |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 2129 | try { |
Andrei Stingaceanu | eb84b18 | 2016-01-26 18:39:55 +0000 | [diff] [blame] | 2130 | return mPM.setPackagesSuspendedAsUser(packageNames, suspended, userId); |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 2131 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 2132 | throw e.rethrowFromSystemServer(); |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 2133 | } |
Andrei Stingaceanu | 1e28391 | 2015-11-26 15:26:28 +0000 | [diff] [blame] | 2134 | } |
| 2135 | |
| 2136 | @Override |
Andrei Stingaceanu | 355b232 | 2016-02-12 16:43:51 +0000 | [diff] [blame] | 2137 | public boolean isPackageSuspendedForUser(String packageName, int userId) { |
| 2138 | try { |
| 2139 | return mPM.isPackageSuspendedForUser(packageName, userId); |
| 2140 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 2141 | throw e.rethrowFromSystemServer(); |
Andrei Stingaceanu | 355b232 | 2016-02-12 16:43:51 +0000 | [diff] [blame] | 2142 | } |
Andrei Stingaceanu | 355b232 | 2016-02-12 16:43:51 +0000 | [diff] [blame] | 2143 | } |
| 2144 | |
Jeff Sharkey | 9bc89af | 2017-01-11 11:25:50 -0700 | [diff] [blame] | 2145 | /** @hide */ |
| 2146 | @Override |
| 2147 | public void setApplicationCategoryHint(String packageName, int categoryHint) { |
| 2148 | try { |
| 2149 | mPM.setApplicationCategoryHint(packageName, categoryHint, |
| 2150 | mContext.getOpPackageName()); |
| 2151 | } catch (RemoteException e) { |
| 2152 | throw e.rethrowFromSystemServer(); |
| 2153 | } |
| 2154 | } |
| 2155 | |
Andrei Stingaceanu | 355b232 | 2016-02-12 16:43:51 +0000 | [diff] [blame] | 2156 | @Override |
Jeff Sharkey | e06b4d1 | 2016-01-06 14:51:50 -0700 | [diff] [blame] | 2157 | public void getPackageSizeInfoAsUser(String packageName, int userHandle, |
Dianne Hackborn | 0c38049 | 2012-08-20 17:23:30 -0700 | [diff] [blame] | 2158 | IPackageStatsObserver observer) { |
Jeff Sharkey | 6f4b2a3 | 2017-03-21 14:13:41 -0600 | [diff] [blame] | 2159 | final String msg = "Shame on you for calling the hidden API " |
| 2160 | + "getPackageSizeInfoAsUser(). Shame!"; |
Jeff Sharkey | e6306c4 | 2017-03-07 21:03:18 -0700 | [diff] [blame] | 2161 | if (mContext.getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.O) { |
Jeff Sharkey | 6f4b2a3 | 2017-03-21 14:13:41 -0600 | [diff] [blame] | 2162 | throw new UnsupportedOperationException(msg); |
Jeff Sharkey | e6306c4 | 2017-03-07 21:03:18 -0700 | [diff] [blame] | 2163 | } else if (observer != null) { |
Jeff Sharkey | 6f4b2a3 | 2017-03-21 14:13:41 -0600 | [diff] [blame] | 2164 | Log.d(TAG, msg); |
Jeff Sharkey | e6306c4 | 2017-03-07 21:03:18 -0700 | [diff] [blame] | 2165 | try { |
| 2166 | observer.onGetStatsCompleted(null, false); |
| 2167 | } catch (RemoteException ignored) { |
| 2168 | } |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 2169 | } |
| 2170 | } |
Jeff Sharkey | d589663 | 2016-03-04 16:16:00 -0700 | [diff] [blame] | 2171 | |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 2172 | @Override |
| 2173 | public void addPackageToPreferred(String packageName) { |
Jeff Sharkey | d589663 | 2016-03-04 16:16:00 -0700 | [diff] [blame] | 2174 | Log.w(TAG, "addPackageToPreferred() is a no-op"); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 2175 | } |
| 2176 | |
| 2177 | @Override |
| 2178 | public void removePackageFromPreferred(String packageName) { |
Jeff Sharkey | d589663 | 2016-03-04 16:16:00 -0700 | [diff] [blame] | 2179 | Log.w(TAG, "removePackageFromPreferred() is a no-op"); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 2180 | } |
| 2181 | |
| 2182 | @Override |
| 2183 | public List<PackageInfo> getPreferredPackages(int flags) { |
Jeff Sharkey | d589663 | 2016-03-04 16:16:00 -0700 | [diff] [blame] | 2184 | Log.w(TAG, "getPreferredPackages() is a no-op"); |
| 2185 | return Collections.emptyList(); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 2186 | } |
| 2187 | |
| 2188 | @Override |
| 2189 | public void addPreferredActivity(IntentFilter filter, |
| 2190 | int match, ComponentName[] set, ComponentName activity) { |
| 2191 | try { |
Jeff Sharkey | ded653b | 2012-09-27 19:09:24 -0700 | [diff] [blame] | 2192 | mPM.addPreferredActivity(filter, match, set, activity, mContext.getUserId()); |
Amith Yamasani | a3f133a | 2012-08-09 17:11:28 -0700 | [diff] [blame] | 2193 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 2194 | throw e.rethrowFromSystemServer(); |
Amith Yamasani | a3f133a | 2012-08-09 17:11:28 -0700 | [diff] [blame] | 2195 | } |
| 2196 | } |
| 2197 | |
| 2198 | @Override |
Jeff Sharkey | e06b4d1 | 2016-01-06 14:51:50 -0700 | [diff] [blame] | 2199 | public void addPreferredActivityAsUser(IntentFilter filter, int match, |
Amith Yamasani | a3f133a | 2012-08-09 17:11:28 -0700 | [diff] [blame] | 2200 | ComponentName[] set, ComponentName activity, int userId) { |
| 2201 | try { |
| 2202 | mPM.addPreferredActivity(filter, match, set, activity, userId); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 2203 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 2204 | throw e.rethrowFromSystemServer(); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 2205 | } |
| 2206 | } |
| 2207 | |
| 2208 | @Override |
| 2209 | public void replacePreferredActivity(IntentFilter filter, |
| 2210 | int match, ComponentName[] set, ComponentName activity) { |
| 2211 | try { |
Robin Lee | 0e27c87 | 2015-09-28 14:37:40 +0100 | [diff] [blame] | 2212 | mPM.replacePreferredActivity(filter, match, set, activity, mContext.getUserId()); |
Amith Yamasani | 41c1ded | 2014-08-05 11:15:05 -0700 | [diff] [blame] | 2213 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 2214 | throw e.rethrowFromSystemServer(); |
Amith Yamasani | 41c1ded | 2014-08-05 11:15:05 -0700 | [diff] [blame] | 2215 | } |
| 2216 | } |
| 2217 | |
| 2218 | @Override |
| 2219 | public void replacePreferredActivityAsUser(IntentFilter filter, |
| 2220 | int match, ComponentName[] set, ComponentName activity, |
| 2221 | int userId) { |
| 2222 | try { |
| 2223 | mPM.replacePreferredActivity(filter, match, set, activity, userId); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 2224 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 2225 | throw e.rethrowFromSystemServer(); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 2226 | } |
| 2227 | } |
| 2228 | |
| 2229 | @Override |
| 2230 | public void clearPackagePreferredActivities(String packageName) { |
| 2231 | try { |
| 2232 | mPM.clearPackagePreferredActivities(packageName); |
| 2233 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 2234 | throw e.rethrowFromSystemServer(); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 2235 | } |
| 2236 | } |
| 2237 | |
| 2238 | @Override |
| 2239 | public int getPreferredActivities(List<IntentFilter> outFilters, |
| 2240 | List<ComponentName> outActivities, String packageName) { |
| 2241 | try { |
| 2242 | return mPM.getPreferredActivities(outFilters, outActivities, packageName); |
| 2243 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 2244 | throw e.rethrowFromSystemServer(); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 2245 | } |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 2246 | } |
| 2247 | |
| 2248 | @Override |
Christopher Tate | a2a0850d | 2013-09-05 16:38:58 -0700 | [diff] [blame] | 2249 | public ComponentName getHomeActivities(List<ResolveInfo> outActivities) { |
| 2250 | try { |
| 2251 | return mPM.getHomeActivities(outActivities); |
| 2252 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 2253 | throw e.rethrowFromSystemServer(); |
Christopher Tate | a2a0850d | 2013-09-05 16:38:58 -0700 | [diff] [blame] | 2254 | } |
Christopher Tate | a2a0850d | 2013-09-05 16:38:58 -0700 | [diff] [blame] | 2255 | } |
| 2256 | |
| 2257 | @Override |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 2258 | public void setComponentEnabledSetting(ComponentName componentName, |
| 2259 | int newState, int flags) { |
| 2260 | try { |
Jeff Sharkey | ded653b | 2012-09-27 19:09:24 -0700 | [diff] [blame] | 2261 | mPM.setComponentEnabledSetting(componentName, newState, flags, mContext.getUserId()); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 2262 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 2263 | throw e.rethrowFromSystemServer(); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 2264 | } |
| 2265 | } |
| 2266 | |
| 2267 | @Override |
| 2268 | public int getComponentEnabledSetting(ComponentName componentName) { |
| 2269 | try { |
Jeff Sharkey | ded653b | 2012-09-27 19:09:24 -0700 | [diff] [blame] | 2270 | return mPM.getComponentEnabledSetting(componentName, mContext.getUserId()); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 2271 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 2272 | throw e.rethrowFromSystemServer(); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 2273 | } |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 2274 | } |
| 2275 | |
| 2276 | @Override |
| 2277 | public void setApplicationEnabledSetting(String packageName, |
| 2278 | int newState, int flags) { |
| 2279 | try { |
Dianne Hackborn | 3fa3c28a | 2013-03-26 16:15:41 -0700 | [diff] [blame] | 2280 | mPM.setApplicationEnabledSetting(packageName, newState, flags, |
Dianne Hackborn | 95d7853 | 2013-09-11 09:51:14 -0700 | [diff] [blame] | 2281 | mContext.getUserId(), mContext.getOpPackageName()); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 2282 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 2283 | throw e.rethrowFromSystemServer(); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 2284 | } |
| 2285 | } |
| 2286 | |
| 2287 | @Override |
| 2288 | public int getApplicationEnabledSetting(String packageName) { |
| 2289 | try { |
Jeff Sharkey | ded653b | 2012-09-27 19:09:24 -0700 | [diff] [blame] | 2290 | return mPM.getApplicationEnabledSetting(packageName, mContext.getUserId()); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 2291 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 2292 | throw e.rethrowFromSystemServer(); |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 2293 | } |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 2294 | } |
| 2295 | |
Amith Yamasani | 655d0e2 | 2013-06-12 14:19:10 -0700 | [diff] [blame] | 2296 | @Override |
Sudheer Shanka | bbb3ff2 | 2015-07-09 15:39:23 +0100 | [diff] [blame] | 2297 | public void flushPackageRestrictionsAsUser(int userId) { |
| 2298 | try { |
| 2299 | mPM.flushPackageRestrictionsAsUser(userId); |
| 2300 | } catch (RemoteException e) { |
| 2301 | throw e.rethrowFromSystemServer(); |
| 2302 | } |
| 2303 | } |
| 2304 | |
| 2305 | @Override |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 2306 | public boolean setApplicationHiddenSettingAsUser(String packageName, boolean hidden, |
Amith Yamasani | 655d0e2 | 2013-06-12 14:19:10 -0700 | [diff] [blame] | 2307 | UserHandle user) { |
| 2308 | try { |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 2309 | return mPM.setApplicationHiddenSettingAsUser(packageName, hidden, |
Amith Yamasani | 655d0e2 | 2013-06-12 14:19:10 -0700 | [diff] [blame] | 2310 | user.getIdentifier()); |
Jeff Sharkey | 27b2e69 | 2016-02-25 17:40:12 -0700 | [diff] [blame] | 2311 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 2312 | throw e.rethrowFromSystemServer(); |
Amith Yamasani | 655d0e2 | 2013-06-12 14:19:10 -0700 | [diff] [blame] | 2313 | } |
Amith Yamasani | 655d0e2 | 2013-06-12 14:19:10 -0700 | [diff] [blame] | 2314 | } |
| 2315 | |
| 2316 | @Override |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 2317 | public boolean getApplicationHiddenSettingAsUser(String packageName, UserHandle user) { |
Amith Yamasani | 655d0e2 | 2013-06-12 14:19:10 -0700 | [diff] [blame] | 2318 | try { |
Amith Yamasani | e5bcff6 | 2014-07-19 15:44:09 -0700 | [diff] [blame] | 2319 | return mPM.getApplicationHiddenSettingAsUser(packageName, user.getIdentifier()); |
Jeff Sharkey | 27b2e69 | 2016-02-25 17:40:12 -0700 | [diff] [blame] | 2320 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 2321 | throw e.rethrowFromSystemServer(); |
Amith Yamasani | 655d0e2 | 2013-06-12 14:19:10 -0700 | [diff] [blame] | 2322 | } |
Amith Yamasani | 655d0e2 | 2013-06-12 14:19:10 -0700 | [diff] [blame] | 2323 | } |
| 2324 | |
dcashman | c6f2249 | 2014-08-14 09:54:51 -0700 | [diff] [blame] | 2325 | /** @hide */ |
dcashman | 9d2f441 | 2014-06-09 09:27:54 -0700 | [diff] [blame] | 2326 | @Override |
| 2327 | public KeySet getKeySetByAlias(String packageName, String alias) { |
| 2328 | Preconditions.checkNotNull(packageName); |
| 2329 | Preconditions.checkNotNull(alias); |
dcashman | 9d2f441 | 2014-06-09 09:27:54 -0700 | [diff] [blame] | 2330 | try { |
Jeff Sharkey | 27b2e69 | 2016-02-25 17:40:12 -0700 | [diff] [blame] | 2331 | return mPM.getKeySetByAlias(packageName, alias); |
dcashman | 9d2f441 | 2014-06-09 09:27:54 -0700 | [diff] [blame] | 2332 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 2333 | throw e.rethrowFromSystemServer(); |
dcashman | 9d2f441 | 2014-06-09 09:27:54 -0700 | [diff] [blame] | 2334 | } |
dcashman | 9d2f441 | 2014-06-09 09:27:54 -0700 | [diff] [blame] | 2335 | } |
| 2336 | |
dcashman | c6f2249 | 2014-08-14 09:54:51 -0700 | [diff] [blame] | 2337 | /** @hide */ |
dcashman | 9d2f441 | 2014-06-09 09:27:54 -0700 | [diff] [blame] | 2338 | @Override |
| 2339 | public KeySet getSigningKeySet(String packageName) { |
| 2340 | Preconditions.checkNotNull(packageName); |
dcashman | 9d2f441 | 2014-06-09 09:27:54 -0700 | [diff] [blame] | 2341 | try { |
Jeff Sharkey | 27b2e69 | 2016-02-25 17:40:12 -0700 | [diff] [blame] | 2342 | return mPM.getSigningKeySet(packageName); |
dcashman | 9d2f441 | 2014-06-09 09:27:54 -0700 | [diff] [blame] | 2343 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 2344 | throw e.rethrowFromSystemServer(); |
dcashman | 9d2f441 | 2014-06-09 09:27:54 -0700 | [diff] [blame] | 2345 | } |
dcashman | 9d2f441 | 2014-06-09 09:27:54 -0700 | [diff] [blame] | 2346 | } |
| 2347 | |
dcashman | c6f2249 | 2014-08-14 09:54:51 -0700 | [diff] [blame] | 2348 | /** @hide */ |
dcashman | 9d2f441 | 2014-06-09 09:27:54 -0700 | [diff] [blame] | 2349 | @Override |
| 2350 | public boolean isSignedBy(String packageName, KeySet ks) { |
| 2351 | Preconditions.checkNotNull(packageName); |
| 2352 | Preconditions.checkNotNull(ks); |
dcashman | 9d2f441 | 2014-06-09 09:27:54 -0700 | [diff] [blame] | 2353 | try { |
dcashman | c6f2249 | 2014-08-14 09:54:51 -0700 | [diff] [blame] | 2354 | return mPM.isPackageSignedByKeySet(packageName, ks); |
dcashman | 9d2f441 | 2014-06-09 09:27:54 -0700 | [diff] [blame] | 2355 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 2356 | throw e.rethrowFromSystemServer(); |
dcashman | 9d2f441 | 2014-06-09 09:27:54 -0700 | [diff] [blame] | 2357 | } |
| 2358 | } |
| 2359 | |
dcashman | c6f2249 | 2014-08-14 09:54:51 -0700 | [diff] [blame] | 2360 | /** @hide */ |
dcashman | 9d2f441 | 2014-06-09 09:27:54 -0700 | [diff] [blame] | 2361 | @Override |
| 2362 | public boolean isSignedByExactly(String packageName, KeySet ks) { |
| 2363 | Preconditions.checkNotNull(packageName); |
| 2364 | Preconditions.checkNotNull(ks); |
dcashman | 9d2f441 | 2014-06-09 09:27:54 -0700 | [diff] [blame] | 2365 | try { |
dcashman | c6f2249 | 2014-08-14 09:54:51 -0700 | [diff] [blame] | 2366 | return mPM.isPackageSignedByKeySetExactly(packageName, ks); |
dcashman | 9d2f441 | 2014-06-09 09:27:54 -0700 | [diff] [blame] | 2367 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 2368 | throw e.rethrowFromSystemServer(); |
dcashman | 9d2f441 | 2014-06-09 09:27:54 -0700 | [diff] [blame] | 2369 | } |
| 2370 | } |
| 2371 | |
Kenny Root | 0aaa0d9 | 2011-09-12 16:42:55 -0700 | [diff] [blame] | 2372 | /** |
| 2373 | * @hide |
| 2374 | */ |
| 2375 | @Override |
| 2376 | public VerifierDeviceIdentity getVerifierDeviceIdentity() { |
| 2377 | try { |
| 2378 | return mPM.getVerifierDeviceIdentity(); |
| 2379 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 2380 | throw e.rethrowFromSystemServer(); |
Kenny Root | 0aaa0d9 | 2011-09-12 16:42:55 -0700 | [diff] [blame] | 2381 | } |
Kenny Root | 0aaa0d9 | 2011-09-12 16:42:55 -0700 | [diff] [blame] | 2382 | } |
| 2383 | |
Jeff Hao | 9f60c08 | 2014-10-28 18:51:07 -0700 | [diff] [blame] | 2384 | /** |
| 2385 | * @hide |
| 2386 | */ |
| 2387 | @Override |
| 2388 | public boolean isUpgrade() { |
| 2389 | try { |
| 2390 | return mPM.isUpgrade(); |
| 2391 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 2392 | throw e.rethrowFromSystemServer(); |
Jeff Hao | 9f60c08 | 2014-10-28 18:51:07 -0700 | [diff] [blame] | 2393 | } |
| 2394 | } |
| 2395 | |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 2396 | @Override |
Jeff Sharkey | 16c8e3f | 2014-07-24 17:08:17 -0700 | [diff] [blame] | 2397 | public PackageInstaller getPackageInstaller() { |
| 2398 | synchronized (mLock) { |
| 2399 | if (mInstaller == null) { |
| 2400 | try { |
Svet Ganov | 6788212 | 2016-12-11 16:36:34 -0800 | [diff] [blame] | 2401 | mInstaller = new PackageInstaller(mPM.getPackageInstaller(), |
Jeff Sharkey | 16c8e3f | 2014-07-24 17:08:17 -0700 | [diff] [blame] | 2402 | mContext.getPackageName(), mContext.getUserId()); |
| 2403 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 2404 | throw e.rethrowFromSystemServer(); |
Jeff Sharkey | 16c8e3f | 2014-07-24 17:08:17 -0700 | [diff] [blame] | 2405 | } |
| 2406 | } |
| 2407 | return mInstaller; |
Jeff Sharkey | 3a44f3f | 2014-04-28 17:36:31 -0700 | [diff] [blame] | 2408 | } |
| 2409 | } |
| 2410 | |
Jeff Sharkey | 6c833e0 | 2014-07-14 22:44:30 -0700 | [diff] [blame] | 2411 | @Override |
| 2412 | public boolean isPackageAvailable(String packageName) { |
| 2413 | try { |
| 2414 | return mPM.isPackageAvailable(packageName, mContext.getUserId()); |
| 2415 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 2416 | throw e.rethrowFromSystemServer(); |
Jeff Sharkey | 6c833e0 | 2014-07-14 22:44:30 -0700 | [diff] [blame] | 2417 | } |
| 2418 | } |
| 2419 | |
Nicolas Prevot | c79586e | 2014-05-06 12:47:57 +0100 | [diff] [blame] | 2420 | /** |
| 2421 | * @hide |
| 2422 | */ |
| 2423 | @Override |
Nicolas Prevot | 63798c5 | 2014-05-27 13:22:38 +0100 | [diff] [blame] | 2424 | public void addCrossProfileIntentFilter(IntentFilter filter, int sourceUserId, int targetUserId, |
| 2425 | int flags) { |
Nicolas Prevot | c79586e | 2014-05-06 12:47:57 +0100 | [diff] [blame] | 2426 | try { |
Nicolas Prevot | 3f7777f | 2014-07-24 15:58:39 +0100 | [diff] [blame] | 2427 | mPM.addCrossProfileIntentFilter(filter, mContext.getOpPackageName(), |
Nicolas Prevot | 4b8d582 | 2015-03-05 15:20:49 +0000 | [diff] [blame] | 2428 | sourceUserId, targetUserId, flags); |
Nicolas Prevot | c79586e | 2014-05-06 12:47:57 +0100 | [diff] [blame] | 2429 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 2430 | throw e.rethrowFromSystemServer(); |
Nicolas Prevot | c79586e | 2014-05-06 12:47:57 +0100 | [diff] [blame] | 2431 | } |
| 2432 | } |
| 2433 | |
| 2434 | /** |
| 2435 | * @hide |
| 2436 | */ |
| 2437 | @Override |
Nicolas Prevot | 8194899 | 2014-05-16 18:25:26 +0100 | [diff] [blame] | 2438 | public void clearCrossProfileIntentFilters(int sourceUserId) { |
Nicolas Prevot | c79586e | 2014-05-06 12:47:57 +0100 | [diff] [blame] | 2439 | try { |
Nicolas Prevot | 4b8d582 | 2015-03-05 15:20:49 +0000 | [diff] [blame] | 2440 | mPM.clearCrossProfileIntentFilters(sourceUserId, mContext.getOpPackageName()); |
Nicolas Prevot | c79586e | 2014-05-06 12:47:57 +0100 | [diff] [blame] | 2441 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 2442 | throw e.rethrowFromSystemServer(); |
Nicolas Prevot | c79586e | 2014-05-06 12:47:57 +0100 | [diff] [blame] | 2443 | } |
| 2444 | } |
| 2445 | |
Nicolas Prevot | 88cc346 | 2014-05-14 14:51:48 +0100 | [diff] [blame] | 2446 | /** |
| 2447 | * @hide |
| 2448 | */ |
Nicolas Prevot | 7f7b0c7 | 2014-06-23 15:59:38 +0100 | [diff] [blame] | 2449 | public Drawable loadItemIcon(PackageItemInfo itemInfo, ApplicationInfo appInfo) { |
Benjamin Franz | ec2d48b | 2014-10-01 15:38:43 +0100 | [diff] [blame] | 2450 | Drawable dr = loadUnbadgedItemIcon(itemInfo, appInfo); |
| 2451 | if (itemInfo.showUserIcon != UserHandle.USER_NULL) { |
| 2452 | return dr; |
| 2453 | } |
| 2454 | return getUserBadgedIcon(dr, new UserHandle(mContext.getUserId())); |
| 2455 | } |
| 2456 | |
| 2457 | /** |
| 2458 | * @hide |
| 2459 | */ |
| 2460 | public Drawable loadUnbadgedItemIcon(PackageItemInfo itemInfo, ApplicationInfo appInfo) { |
Nicolas Prevot | 7f7b0c7 | 2014-06-23 15:59:38 +0100 | [diff] [blame] | 2461 | if (itemInfo.showUserIcon != UserHandle.USER_NULL) { |
Alexandra Gherghina | 64d4dca | 2014-08-28 18:26:56 +0100 | [diff] [blame] | 2462 | Bitmap bitmap = getUserManager().getUserIcon(itemInfo.showUserIcon); |
| 2463 | if (bitmap == null) { |
| 2464 | return UserIcons.getDefaultUserIcon(itemInfo.showUserIcon, /* light= */ false); |
| 2465 | } |
| 2466 | return new BitmapDrawable(bitmap); |
Nicolas Prevot | 7f7b0c7 | 2014-06-23 15:59:38 +0100 | [diff] [blame] | 2467 | } |
Alexandra Gherghina | db811db | 2014-08-29 13:43:59 +0100 | [diff] [blame] | 2468 | Drawable dr = null; |
| 2469 | if (itemInfo.packageName != null) { |
| 2470 | dr = getDrawable(itemInfo.packageName, itemInfo.icon, appInfo); |
| 2471 | } |
Alexandra Gherghina | a71e390 | 2014-07-25 20:03:47 +0100 | [diff] [blame] | 2472 | if (dr == null) { |
Alexandra Gherghina | a709314 | 2014-07-30 13:43:39 +0100 | [diff] [blame] | 2473 | dr = itemInfo.loadDefaultIcon(this); |
Nicolas Prevot | 7f7b0c7 | 2014-06-23 15:59:38 +0100 | [diff] [blame] | 2474 | } |
Benjamin Franz | ec2d48b | 2014-10-01 15:38:43 +0100 | [diff] [blame] | 2475 | return dr; |
Svetoslav | c7d62f0 | 2014-09-04 15:39:54 -0700 | [diff] [blame] | 2476 | } |
| 2477 | |
| 2478 | private Drawable getBadgedDrawable(Drawable drawable, Drawable badgeDrawable, |
| 2479 | Rect badgeLocation, boolean tryBadgeInPlace) { |
| 2480 | final int badgedWidth = drawable.getIntrinsicWidth(); |
| 2481 | final int badgedHeight = drawable.getIntrinsicHeight(); |
| 2482 | final boolean canBadgeInPlace = tryBadgeInPlace |
| 2483 | && (drawable instanceof BitmapDrawable) |
| 2484 | && ((BitmapDrawable) drawable).getBitmap().isMutable(); |
| 2485 | |
| 2486 | final Bitmap bitmap; |
| 2487 | if (canBadgeInPlace) { |
| 2488 | bitmap = ((BitmapDrawable) drawable).getBitmap(); |
| 2489 | } else { |
| 2490 | bitmap = Bitmap.createBitmap(badgedWidth, badgedHeight, Bitmap.Config.ARGB_8888); |
| 2491 | } |
| 2492 | Canvas canvas = new Canvas(bitmap); |
| 2493 | |
| 2494 | if (!canBadgeInPlace) { |
| 2495 | drawable.setBounds(0, 0, badgedWidth, badgedHeight); |
| 2496 | drawable.draw(canvas); |
| 2497 | } |
| 2498 | |
| 2499 | if (badgeLocation != null) { |
| 2500 | if (badgeLocation.left < 0 || badgeLocation.top < 0 |
| 2501 | || badgeLocation.width() > badgedWidth || badgeLocation.height() > badgedHeight) { |
| 2502 | throw new IllegalArgumentException("Badge location " + badgeLocation |
| 2503 | + " not in badged drawable bounds " |
| 2504 | + new Rect(0, 0, badgedWidth, badgedHeight)); |
| 2505 | } |
| 2506 | badgeDrawable.setBounds(0, 0, badgeLocation.width(), badgeLocation.height()); |
| 2507 | |
| 2508 | canvas.save(); |
| 2509 | canvas.translate(badgeLocation.left, badgeLocation.top); |
| 2510 | badgeDrawable.draw(canvas); |
| 2511 | canvas.restore(); |
| 2512 | } else { |
| 2513 | badgeDrawable.setBounds(0, 0, badgedWidth, badgedHeight); |
| 2514 | badgeDrawable.draw(canvas); |
| 2515 | } |
| 2516 | |
| 2517 | if (!canBadgeInPlace) { |
| 2518 | BitmapDrawable mergedDrawable = new BitmapDrawable(mContext.getResources(), bitmap); |
| 2519 | |
| 2520 | if (drawable instanceof BitmapDrawable) { |
| 2521 | BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable; |
| 2522 | mergedDrawable.setTargetDensity(bitmapDrawable.getBitmap().getDensity()); |
| 2523 | } |
| 2524 | |
| 2525 | return mergedDrawable; |
| 2526 | } |
| 2527 | |
| 2528 | return drawable; |
| 2529 | } |
| 2530 | |
Tony Mak | 8673b28 | 2016-03-21 21:10:59 +0000 | [diff] [blame] | 2531 | private boolean isManagedProfile(int userId) { |
| 2532 | return getUserManager().isManagedProfile(userId); |
Nicolas Prevot | 88cc346 | 2014-05-14 14:51:48 +0100 | [diff] [blame] | 2533 | } |
| 2534 | |
Bartosz Fabianowski | a34f53f | 2017-01-11 18:08:47 +0100 | [diff] [blame] | 2535 | /** |
| 2536 | * @hide |
| 2537 | */ |
| 2538 | @Override |
| 2539 | public int getInstallReason(String packageName, UserHandle user) { |
| 2540 | try { |
| 2541 | return mPM.getInstallReason(packageName, user.getIdentifier()); |
| 2542 | } catch (RemoteException e) { |
| 2543 | throw e.rethrowFromSystemServer(); |
| 2544 | } |
| 2545 | } |
| 2546 | |
Jeff Sharkey | 620b32b | 2015-04-23 19:36:02 -0700 | [diff] [blame] | 2547 | /** {@hide} */ |
| 2548 | private static class MoveCallbackDelegate extends IPackageMoveObserver.Stub implements |
| 2549 | Handler.Callback { |
Jeff Sharkey | 50a0545 | 2015-04-29 11:24:52 -0700 | [diff] [blame] | 2550 | private static final int MSG_CREATED = 1; |
| 2551 | private static final int MSG_STATUS_CHANGED = 2; |
Jeff Sharkey | 620b32b | 2015-04-23 19:36:02 -0700 | [diff] [blame] | 2552 | |
| 2553 | final MoveCallback mCallback; |
| 2554 | final Handler mHandler; |
| 2555 | |
| 2556 | public MoveCallbackDelegate(MoveCallback callback, Looper looper) { |
| 2557 | mCallback = callback; |
| 2558 | mHandler = new Handler(looper, this); |
| 2559 | } |
| 2560 | |
| 2561 | @Override |
| 2562 | public boolean handleMessage(Message msg) { |
Jeff Sharkey | 620b32b | 2015-04-23 19:36:02 -0700 | [diff] [blame] | 2563 | switch (msg.what) { |
Jeff Sharkey | 50a0545 | 2015-04-29 11:24:52 -0700 | [diff] [blame] | 2564 | case MSG_CREATED: { |
Jeff Sharkey | b36586a | 2015-04-27 08:42:28 -0700 | [diff] [blame] | 2565 | final SomeArgs args = (SomeArgs) msg.obj; |
Jeff Sharkey | 50a0545 | 2015-04-29 11:24:52 -0700 | [diff] [blame] | 2566 | mCallback.onCreated(args.argi1, (Bundle) args.arg2); |
Jeff Sharkey | b36586a | 2015-04-27 08:42:28 -0700 | [diff] [blame] | 2567 | args.recycle(); |
Jeff Sharkey | 620b32b | 2015-04-23 19:36:02 -0700 | [diff] [blame] | 2568 | return true; |
Jeff Sharkey | 50a0545 | 2015-04-29 11:24:52 -0700 | [diff] [blame] | 2569 | } |
| 2570 | case MSG_STATUS_CHANGED: { |
| 2571 | final SomeArgs args = (SomeArgs) msg.obj; |
| 2572 | mCallback.onStatusChanged(args.argi1, args.argi2, (long) args.arg3); |
| 2573 | args.recycle(); |
| 2574 | return true; |
| 2575 | } |
Jeff Sharkey | 620b32b | 2015-04-23 19:36:02 -0700 | [diff] [blame] | 2576 | } |
| 2577 | return false; |
| 2578 | } |
| 2579 | |
| 2580 | @Override |
Jeff Sharkey | 50a0545 | 2015-04-29 11:24:52 -0700 | [diff] [blame] | 2581 | public void onCreated(int moveId, Bundle extras) { |
Jeff Sharkey | b36586a | 2015-04-27 08:42:28 -0700 | [diff] [blame] | 2582 | final SomeArgs args = SomeArgs.obtain(); |
| 2583 | args.argi1 = moveId; |
Jeff Sharkey | 50a0545 | 2015-04-29 11:24:52 -0700 | [diff] [blame] | 2584 | args.arg2 = extras; |
| 2585 | mHandler.obtainMessage(MSG_CREATED, args).sendToTarget(); |
| 2586 | } |
| 2587 | |
| 2588 | @Override |
| 2589 | public void onStatusChanged(int moveId, int status, long estMillis) { |
| 2590 | final SomeArgs args = SomeArgs.obtain(); |
| 2591 | args.argi1 = moveId; |
| 2592 | args.argi2 = status; |
| 2593 | args.arg3 = estMillis; |
Jeff Sharkey | b36586a | 2015-04-27 08:42:28 -0700 | [diff] [blame] | 2594 | mHandler.obtainMessage(MSG_STATUS_CHANGED, args).sendToTarget(); |
Jeff Sharkey | 620b32b | 2015-04-23 19:36:02 -0700 | [diff] [blame] | 2595 | } |
| 2596 | } |
| 2597 | |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 2598 | private final ContextImpl mContext; |
| 2599 | private final IPackageManager mPM; |
| 2600 | |
| 2601 | private static final Object sSync = new Object(); |
Dianne Hackborn | add005c | 2013-07-17 18:43:12 -0700 | [diff] [blame] | 2602 | private static ArrayMap<ResourceName, WeakReference<Drawable.ConstantState>> sIconCache |
| 2603 | = new ArrayMap<ResourceName, WeakReference<Drawable.ConstantState>>(); |
| 2604 | private static ArrayMap<ResourceName, WeakReference<CharSequence>> sStringCache |
| 2605 | = new ArrayMap<ResourceName, WeakReference<CharSequence>>(); |
Svetoslav | f7c06eb | 2015-06-10 18:43:22 -0700 | [diff] [blame] | 2606 | |
| 2607 | private final Map<OnPermissionsChangedListener, IOnPermissionsChangeListener> |
| 2608 | mPermissionListeners = new ArrayMap<>(); |
| 2609 | |
| 2610 | public class OnPermissionsChangeListenerDelegate extends IOnPermissionsChangeListener.Stub |
| 2611 | implements Handler.Callback{ |
| 2612 | private static final int MSG_PERMISSIONS_CHANGED = 1; |
| 2613 | |
| 2614 | private final OnPermissionsChangedListener mListener; |
| 2615 | private final Handler mHandler; |
| 2616 | |
| 2617 | |
| 2618 | public OnPermissionsChangeListenerDelegate(OnPermissionsChangedListener listener, |
| 2619 | Looper looper) { |
| 2620 | mListener = listener; |
| 2621 | mHandler = new Handler(looper, this); |
| 2622 | } |
| 2623 | |
| 2624 | @Override |
| 2625 | public void onPermissionsChanged(int uid) { |
| 2626 | mHandler.obtainMessage(MSG_PERMISSIONS_CHANGED, uid, 0).sendToTarget(); |
| 2627 | } |
| 2628 | |
| 2629 | @Override |
| 2630 | public boolean handleMessage(Message msg) { |
| 2631 | switch (msg.what) { |
| 2632 | case MSG_PERMISSIONS_CHANGED: { |
| 2633 | final int uid = msg.arg1; |
| 2634 | mListener.onPermissionsChanged(uid); |
| 2635 | return true; |
| 2636 | } |
| 2637 | } |
| 2638 | return false; |
| 2639 | } |
| 2640 | } |
Suprabh Shukla | aef2513 | 2017-01-23 18:09:03 -0800 | [diff] [blame] | 2641 | |
| 2642 | @Override |
| 2643 | public boolean canRequestPackageInstalls() { |
| 2644 | try { |
| 2645 | return mPM.canRequestPackageInstalls(mContext.getPackageName(), mContext.getUserId()); |
| 2646 | } catch (RemoteException e) { |
| 2647 | throw e.rethrowAsRuntimeException(); |
| 2648 | } |
| 2649 | } |
Chad Brubaker | 336ae5b | 2017-03-24 15:53:09 -0700 | [diff] [blame] | 2650 | |
| 2651 | @Override |
| 2652 | public ComponentName getInstantAppResolverSettingsComponent() { |
| 2653 | try { |
| 2654 | return mPM.getInstantAppResolverSettingsComponent(); |
| 2655 | } catch (RemoteException e) { |
| 2656 | throw e.rethrowAsRuntimeException(); |
| 2657 | } |
| 2658 | } |
Todd Kennedy | 801e659 | 2017-04-12 14:10:12 -0700 | [diff] [blame] | 2659 | |
| 2660 | @Override |
| 2661 | public ComponentName getInstantAppInstallerComponent() { |
| 2662 | try { |
| 2663 | return mPM.getInstantAppInstallerComponent(); |
| 2664 | } catch (RemoteException e) { |
| 2665 | throw e.rethrowAsRuntimeException(); |
| 2666 | } |
| 2667 | } |
Chad Brubaker | 0d277a7 | 2017-04-12 16:56:53 -0700 | [diff] [blame] | 2668 | |
| 2669 | @Override |
| 2670 | public String getInstantAppAndroidId(String packageName, UserHandle user) { |
| 2671 | try { |
| 2672 | return mPM.getInstantAppAndroidId(packageName, user.getIdentifier()); |
| 2673 | } catch (RemoteException e) { |
| 2674 | throw e.rethrowAsRuntimeException(); |
| 2675 | } |
| 2676 | } |
Brad Fitzpatrick | 390dae1 | 2010-11-10 08:27:28 -0800 | [diff] [blame] | 2677 | } |