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