blob: 333e412e1c33720a411f788a2d83be993bece433 [file] [log] [blame]
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001/*
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
17package android.app;
18
Tor Norbye7b9c9122013-05-30 16:48:33 -070019import android.annotation.DrawableRes;
Alan Viveretteecd585a2015-04-13 10:32:51 -070020import android.annotation.NonNull;
21import android.annotation.Nullable;
Tor Norbye7b9c9122013-05-30 16:48:33 -070022import android.annotation.StringRes;
23import android.annotation.XmlRes;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080024import android.content.ComponentName;
25import android.content.ContentResolver;
Yao Chen022b8ea2016-12-16 11:03:28 -080026import android.content.Context;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080027import android.content.Intent;
28import android.content.IntentFilter;
29import android.content.IntentSender;
30import android.content.pm.ActivityInfo;
31import android.content.pm.ApplicationInfo;
Todd Kennedy9106c642017-02-08 14:16:53 -080032import android.content.pm.ChangedPackages;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080033import android.content.pm.ComponentInfo;
Svetoslav Ganov096d3042017-01-30 16:34:13 -080034import android.content.pm.InstantAppInfo;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080035import android.content.pm.FeatureInfo;
Svetoslavf7c06eb2015-06-10 18:43:22 -070036import android.content.pm.IOnPermissionsChangeListener;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080037import android.content.pm.IPackageDataObserver;
38import android.content.pm.IPackageDeleteObserver;
39import android.content.pm.IPackageInstallObserver;
40import android.content.pm.IPackageManager;
41import android.content.pm.IPackageMoveObserver;
42import android.content.pm.IPackageStatsObserver;
43import android.content.pm.InstrumentationInfo;
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -080044import android.content.pm.IntentFilterVerificationInfo;
dcashman9d2f4412014-06-09 09:27:54 -070045import android.content.pm.KeySet;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080046import android.content.pm.PackageInfo;
Jeff Sharkey3a44f3f2014-04-28 17:36:31 -070047import android.content.pm.PackageInstaller;
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +010048import android.content.pm.PackageItemInfo;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080049import android.content.pm.PackageManager;
Kenny Roote6cd0c72011-05-19 12:48:14 -070050import android.content.pm.ParceledListSlice;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080051import android.content.pm.PermissionGroupInfo;
52import android.content.pm.PermissionInfo;
53import android.content.pm.ProviderInfo;
54import android.content.pm.ResolveInfo;
55import android.content.pm.ServiceInfo;
Svet Ganov67882122016-12-11 16:36:34 -080056import android.content.pm.SharedLibraryInfo;
Kenny Root0aaa0d92011-09-12 16:42:55 -070057import android.content.pm.VerifierDeviceIdentity;
Svet Ganov67882122016-12-11 16:36:34 -080058import android.content.pm.VersionedPackage;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080059import android.content.res.Resources;
60import android.content.res.XmlResourceParser;
Svetoslavc7d62f02014-09-04 15:39:54 -070061import android.graphics.Bitmap;
62import android.graphics.Canvas;
63import android.graphics.Rect;
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +010064import android.graphics.drawable.BitmapDrawable;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080065import android.graphics.drawable.Drawable;
Kenny Guy02c89902016-11-15 19:36:38 +000066import android.graphics.drawable.LayerDrawable;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080067import android.net.Uri;
Jeff Sharkey50a05452015-04-29 11:24:52 -070068import android.os.Bundle;
Jeff Sharkey620b32b2015-04-23 19:36:02 -070069import android.os.Handler;
70import android.os.Looper;
71import android.os.Message;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080072import android.os.Process;
73import android.os.RemoteException;
Jeff Sharkeyb2b9ab82015-04-05 21:10:42 -070074import android.os.SystemProperties;
Amith Yamasani67df64b2012-12-14 12:09:36 -080075import android.os.UserHandle;
Nicolas Prevot88cc3462014-05-14 14:51:48 +010076import android.os.UserManager;
Jeff Sharkeye2d45be2015-04-15 17:14:12 -070077import android.os.storage.StorageManager;
78import android.os.storage.VolumeInfo;
Todd Kennedyf39ca8f2015-08-07 14:15:07 -070079import android.provider.Settings;
Dianne Hackbornadd005c2013-07-17 18:43:12 -070080import android.util.ArrayMap;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080081import android.util.Log;
Jeff Browna492c3a2012-08-23 19:48:44 -070082import android.view.Display;
Jeff Sharkeyb2b9ab82015-04-05 21:10:42 -070083
84import dalvik.system.VMRuntime;
Jeff Sharkey16c8e3f2014-07-24 17:08:17 -070085
86import com.android.internal.annotations.GuardedBy;
Kenny Guy02c89902016-11-15 19:36:38 +000087import com.android.internal.annotations.VisibleForTesting;
Jeff Sharkeyb36586a2015-04-27 08:42:28 -070088import com.android.internal.os.SomeArgs;
dcashman9d2f4412014-06-09 09:27:54 -070089import com.android.internal.util.Preconditions;
Alexandra Gherghina64d4dca2014-08-28 18:26:56 +010090import com.android.internal.util.UserIcons;
Svet Ganov2acf0632015-11-24 19:10:59 -080091import libcore.util.EmptyArray;
Jeff Sharkey16c8e3f2014-07-24 17:08:17 -070092
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080093import java.lang.ref.WeakReference;
94import java.util.ArrayList;
Svet Ganov2acf0632015-11-24 19:10:59 -080095import java.util.Collections;
Jeff Sharkey620b32b2015-04-23 19:36:02 -070096import java.util.Iterator;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080097import java.util.List;
Svetoslavf7c06eb2015-06-10 18:43:22 -070098import java.util.Map;
Jeff Sharkey620b32b2015-04-23 19:36:02 -070099import java.util.Objects;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800100
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700101/** @hide */
102public class ApplicationPackageManager extends PackageManager {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800103 private static final String TAG = "ApplicationPackageManager";
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800104 private final static boolean DEBUG_ICONS = false;
105
Svet Ganov2acf0632015-11-24 19:10:59 -0800106 private static final int DEFAULT_EPHEMERAL_COOKIE_MAX_SIZE_BYTES = 16384; // 16KB
107
Adam Lesinskid00bb5e2014-10-07 12:14:45 -0700108 // Default flags to use with PackageManager when no flags are given.
109 private final static int sDefaultFlags = PackageManager.GET_SHARED_LIBRARY_FILES;
110
Jeff Sharkey16c8e3f2014-07-24 17:08:17 -0700111 private final Object mLock = new Object();
112
113 @GuardedBy("mLock")
114 private UserManager mUserManager;
115 @GuardedBy("mLock")
116 private PackageInstaller mInstaller;
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +0100117
Jeff Sharkey620b32b2015-04-23 19:36:02 -0700118 @GuardedBy("mDelegates")
119 private final ArrayList<MoveCallbackDelegate> mDelegates = new ArrayList<>();
120
Svet Ganovf1b7f202015-07-29 08:33:42 -0700121 @GuardedBy("mLock")
122 private String mPermissionsControllerPackageName;
123
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +0100124 UserManager getUserManager() {
Jeff Sharkey16c8e3f2014-07-24 17:08:17 -0700125 synchronized (mLock) {
126 if (mUserManager == null) {
127 mUserManager = UserManager.get(mContext);
128 }
129 return mUserManager;
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +0100130 }
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +0100131 }
132
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800133 @Override
134 public PackageInfo getPackageInfo(String packageName, int flags)
135 throws NameNotFoundException {
Nicolas Prevot9a80e532015-09-23 15:49:28 +0100136 return getPackageInfoAsUser(packageName, flags, mContext.getUserId());
137 }
138
139 @Override
Svet Ganov67882122016-12-11 16:36:34 -0800140 public PackageInfo getPackageInfo(VersionedPackage versionedPackage, int flags)
141 throws NameNotFoundException {
142 try {
143 PackageInfo pi = mPM.getPackageInfoVersioned(versionedPackage, flags,
144 mContext.getUserId());
145 if (pi != null) {
146 return pi;
147 }
148 } catch (RemoteException e) {
149 throw e.rethrowFromSystemServer();
150 }
151 throw new NameNotFoundException(versionedPackage.toString());
152 }
153
154 @Override
Nicolas Prevot9a80e532015-09-23 15:49:28 +0100155 public PackageInfo getPackageInfoAsUser(String packageName, int flags, int userId)
156 throws NameNotFoundException {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800157 try {
Nicolas Prevot9a80e532015-09-23 15:49:28 +0100158 PackageInfo pi = mPM.getPackageInfo(packageName, flags, userId);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800159 if (pi != null) {
160 return pi;
161 }
162 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700163 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800164 }
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800165 throw new NameNotFoundException(packageName);
166 }
167
168 @Override
169 public String[] currentToCanonicalPackageNames(String[] names) {
170 try {
171 return mPM.currentToCanonicalPackageNames(names);
172 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700173 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800174 }
175 }
176
177 @Override
178 public String[] canonicalToCurrentPackageNames(String[] names) {
179 try {
180 return mPM.canonicalToCurrentPackageNames(names);
181 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700182 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800183 }
184 }
185
186 @Override
187 public Intent getLaunchIntentForPackage(String packageName) {
188 // First see if the package has an INFO activity; the existence of
189 // such an activity is implied to be the desired front-door for the
190 // overall package (such as if it has multiple launcher entries).
191 Intent intentToResolve = new Intent(Intent.ACTION_MAIN);
192 intentToResolve.addCategory(Intent.CATEGORY_INFO);
193 intentToResolve.setPackage(packageName);
Dianne Hackborn19415762010-12-15 00:20:27 -0800194 List<ResolveInfo> ris = queryIntentActivities(intentToResolve, 0);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800195
196 // Otherwise, try to find a main launcher activity.
Dianne Hackborn19415762010-12-15 00:20:27 -0800197 if (ris == null || ris.size() <= 0) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800198 // reuse the intent instance
199 intentToResolve.removeCategory(Intent.CATEGORY_INFO);
200 intentToResolve.addCategory(Intent.CATEGORY_LAUNCHER);
201 intentToResolve.setPackage(packageName);
Dianne Hackborn19415762010-12-15 00:20:27 -0800202 ris = queryIntentActivities(intentToResolve, 0);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800203 }
Dianne Hackborn19415762010-12-15 00:20:27 -0800204 if (ris == null || ris.size() <= 0) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800205 return null;
206 }
207 Intent intent = new Intent(intentToResolve);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800208 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Dianne Hackborn19415762010-12-15 00:20:27 -0800209 intent.setClassName(ris.get(0).activityInfo.packageName,
210 ris.get(0).activityInfo.name);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800211 return intent;
212 }
213
214 @Override
Jose Lima970417c2014-04-10 10:42:19 -0700215 public Intent getLeanbackLaunchIntentForPackage(String packageName) {
216 // Try to find a main leanback_launcher activity.
217 Intent intentToResolve = new Intent(Intent.ACTION_MAIN);
218 intentToResolve.addCategory(Intent.CATEGORY_LEANBACK_LAUNCHER);
219 intentToResolve.setPackage(packageName);
220 List<ResolveInfo> ris = queryIntentActivities(intentToResolve, 0);
221
222 if (ris == null || ris.size() <= 0) {
223 return null;
224 }
225 Intent intent = new Intent(intentToResolve);
226 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
227 intent.setClassName(ris.get(0).activityInfo.packageName,
228 ris.get(0).activityInfo.name);
229 return intent;
230 }
231
232 @Override
Jeff Sharkey8588bc12016-01-06 16:47:42 -0700233 public int[] getPackageGids(String packageName) throws NameNotFoundException {
234 return getPackageGids(packageName, 0);
235 }
236
237 @Override
238 public int[] getPackageGids(String packageName, int flags)
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800239 throws NameNotFoundException {
240 try {
Jeff Sharkeycd654482016-01-08 17:42:11 -0700241 int[] gids = mPM.getPackageGids(packageName, flags, mContext.getUserId());
Svetoslavc6d1c342015-02-26 14:44:43 -0800242 if (gids != null) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800243 return gids;
244 }
245 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700246 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800247 }
248
249 throw new NameNotFoundException(packageName);
250 }
251
252 @Override
Jeff Sharkey8588bc12016-01-06 16:47:42 -0700253 public int getPackageUid(String packageName, int flags) throws NameNotFoundException {
254 return getPackageUidAsUser(packageName, flags, mContext.getUserId());
255 }
256
257 @Override
258 public int getPackageUidAsUser(String packageName, int userId) throws NameNotFoundException {
259 return getPackageUidAsUser(packageName, 0, userId);
260 }
261
262 @Override
263 public int getPackageUidAsUser(String packageName, int flags, int userId)
Dianne Hackborna06de0f2012-12-11 16:34:47 -0800264 throws NameNotFoundException {
265 try {
Jeff Sharkeycd654482016-01-08 17:42:11 -0700266 int uid = mPM.getPackageUid(packageName, flags, userId);
Dianne Hackborna06de0f2012-12-11 16:34:47 -0800267 if (uid >= 0) {
268 return uid;
269 }
270 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700271 throw e.rethrowFromSystemServer();
Dianne Hackborna06de0f2012-12-11 16:34:47 -0800272 }
273
274 throw new NameNotFoundException(packageName);
275 }
276
277 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800278 public PermissionInfo getPermissionInfo(String name, int flags)
279 throws NameNotFoundException {
280 try {
281 PermissionInfo pi = mPM.getPermissionInfo(name, flags);
282 if (pi != null) {
283 return pi;
284 }
285 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700286 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800287 }
288
289 throw new NameNotFoundException(name);
290 }
291
292 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700293 @SuppressWarnings("unchecked")
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800294 public List<PermissionInfo> queryPermissionsByGroup(String group, int flags)
295 throws NameNotFoundException {
296 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700297 ParceledListSlice<PermissionInfo> parceledList =
298 mPM.queryPermissionsByGroup(group, flags);
299 if (parceledList != null) {
300 List<PermissionInfo> pi = parceledList.getList();
301 if (pi != null) {
302 return pi;
303 }
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800304 }
305 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700306 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800307 }
308
309 throw new NameNotFoundException(group);
310 }
311
312 @Override
Paul Navin7b89a7b2017-01-26 23:56:08 +0000313 public boolean isPermissionReviewModeEnabled() {
314 return mContext.getResources().getBoolean(
315 com.android.internal.R.bool.config_permissionReviewRequired);
316 }
317
318 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800319 public PermissionGroupInfo getPermissionGroupInfo(String name,
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700320 int flags) throws NameNotFoundException {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800321 try {
322 PermissionGroupInfo pgi = mPM.getPermissionGroupInfo(name, flags);
323 if (pgi != null) {
324 return pgi;
325 }
326 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700327 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800328 }
329
330 throw new NameNotFoundException(name);
331 }
332
333 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700334 @SuppressWarnings("unchecked")
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800335 public List<PermissionGroupInfo> getAllPermissionGroups(int flags) {
336 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700337 ParceledListSlice<PermissionGroupInfo> parceledList =
338 mPM.getAllPermissionGroups(flags);
339 if (parceledList == null) {
340 return Collections.emptyList();
341 }
342 return parceledList.getList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800343 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700344 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800345 }
346 }
347
348 @Override
349 public ApplicationInfo getApplicationInfo(String packageName, int flags)
350 throws NameNotFoundException {
Jeff Sharkeycd654482016-01-08 17:42:11 -0700351 return getApplicationInfoAsUser(packageName, flags, mContext.getUserId());
352 }
353
354 @Override
355 public ApplicationInfo getApplicationInfoAsUser(String packageName, int flags, int userId)
356 throws NameNotFoundException {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800357 try {
Jeff Sharkeycd654482016-01-08 17:42:11 -0700358 ApplicationInfo ai = mPM.getApplicationInfo(packageName, flags, userId);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800359 if (ai != null) {
Narayan Kamathcaa71192014-07-16 11:06:43 +0100360 // This is a temporary hack. Callers must use
361 // createPackageContext(packageName).getApplicationInfo() to
362 // get the right paths.
Tao Baic9a02372016-01-12 15:02:24 -0800363 return maybeAdjustApplicationInfo(ai);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800364 }
365 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700366 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800367 }
368
369 throw new NameNotFoundException(packageName);
370 }
371
Tao Baic9a02372016-01-12 15:02:24 -0800372 private static ApplicationInfo maybeAdjustApplicationInfo(ApplicationInfo info) {
Narayan Kamathcaa71192014-07-16 11:06:43 +0100373 // If we're dealing with a multi-arch application that has both
374 // 32 and 64 bit shared libraries, we might need to choose the secondary
375 // depending on what the current runtime's instruction set is.
376 if (info.primaryCpuAbi != null && info.secondaryCpuAbi != null) {
377 final String runtimeIsa = VMRuntime.getRuntime().vmInstructionSet();
jgu214741cd92014-12-17 17:23:29 -0500378
379 // Get the instruction set that the libraries of secondary Abi is supported.
380 // In presence of a native bridge this might be different than the one secondary Abi used.
381 String secondaryIsa = VMRuntime.getInstructionSet(info.secondaryCpuAbi);
382 final String secondaryDexCodeIsa = SystemProperties.get("ro.dalvik.vm.isa." + secondaryIsa);
383 secondaryIsa = secondaryDexCodeIsa.isEmpty() ? secondaryIsa : secondaryDexCodeIsa;
Narayan Kamathcaa71192014-07-16 11:06:43 +0100384
385 // If the runtimeIsa is the same as the primary isa, then we do nothing.
386 // Everything will be set up correctly because info.nativeLibraryDir will
387 // correspond to the right ISA.
388 if (runtimeIsa.equals(secondaryIsa)) {
Tao Baic9a02372016-01-12 15:02:24 -0800389 ApplicationInfo modified = new ApplicationInfo(info);
390 modified.nativeLibraryDir = info.secondaryNativeLibraryDir;
391 return modified;
Narayan Kamathcaa71192014-07-16 11:06:43 +0100392 }
393 }
Tao Baic9a02372016-01-12 15:02:24 -0800394 return info;
Narayan Kamathcaa71192014-07-16 11:06:43 +0100395 }
396
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800397 @Override
398 public ActivityInfo getActivityInfo(ComponentName className, int flags)
399 throws NameNotFoundException {
400 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700401 ActivityInfo ai = mPM.getActivityInfo(className, flags, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800402 if (ai != null) {
403 return ai;
404 }
405 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700406 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800407 }
408
409 throw new NameNotFoundException(className.toString());
410 }
411
412 @Override
413 public ActivityInfo getReceiverInfo(ComponentName className, int flags)
414 throws NameNotFoundException {
415 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700416 ActivityInfo ai = mPM.getReceiverInfo(className, flags, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800417 if (ai != null) {
418 return ai;
419 }
420 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700421 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800422 }
423
424 throw new NameNotFoundException(className.toString());
425 }
426
427 @Override
428 public ServiceInfo getServiceInfo(ComponentName className, int flags)
429 throws NameNotFoundException {
430 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700431 ServiceInfo si = mPM.getServiceInfo(className, flags, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800432 if (si != null) {
433 return si;
434 }
435 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700436 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800437 }
438
439 throw new NameNotFoundException(className.toString());
440 }
441
442 @Override
443 public ProviderInfo getProviderInfo(ComponentName className, int flags)
444 throws NameNotFoundException {
445 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700446 ProviderInfo pi = mPM.getProviderInfo(className, flags, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800447 if (pi != null) {
448 return pi;
449 }
450 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700451 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800452 }
453
454 throw new NameNotFoundException(className.toString());
455 }
456
457 @Override
458 public String[] getSystemSharedLibraryNames() {
459 try {
460 return mPM.getSystemSharedLibraryNames();
461 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700462 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800463 }
464 }
465
Svet Ganovd7b1f4112016-02-09 18:49:23 -0800466 /** @hide */
467 @Override
Svet Ganov67882122016-12-11 16:36:34 -0800468 public @NonNull List<SharedLibraryInfo> getSharedLibraries(int flags) {
469 return getSharedLibrariesAsUser(flags, mContext.getUserId());
470 }
471
472 /** @hide */
473 @Override
474 @SuppressWarnings("unchecked")
475 public @NonNull List<SharedLibraryInfo> getSharedLibrariesAsUser(int flags, int userId) {
476 try {
477 ParceledListSlice<SharedLibraryInfo> sharedLibs = mPM.getSharedLibraries(
478 flags, userId);
479 if (sharedLibs == null) {
480 return Collections.emptyList();
481 }
482 return sharedLibs.getList();
483 } catch (RemoteException e) {
484 throw e.rethrowFromSystemServer();
485 }
486 }
487
488 /** @hide */
489 @Override
Svetoslav Ganova9c25002016-04-13 19:25:56 -0700490 public @NonNull String getServicesSystemSharedLibraryPackageName() {
Svet Ganovd7b1f4112016-02-09 18:49:23 -0800491 try {
492 return mPM.getServicesSystemSharedLibraryPackageName();
493 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700494 throw e.rethrowFromSystemServer();
Svet Ganovd7b1f4112016-02-09 18:49:23 -0800495 }
496 }
497
Svetoslav Ganova9c25002016-04-13 19:25:56 -0700498 /**
499 * @hide
500 */
501 public @NonNull String getSharedSystemSharedLibraryPackageName() {
502 try {
503 return mPM.getSharedSystemSharedLibraryPackageName();
504 } catch (RemoteException e) {
505 throw e.rethrowFromSystemServer();
506 }
507 }
508
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800509 @Override
Todd Kennedy9106c642017-02-08 14:16:53 -0800510 public ChangedPackages getChangedPackages(int sequenceNumber) {
511 try {
512 return mPM.getChangedPackages(sequenceNumber, mContext.getUserId());
513 } catch (RemoteException e) {
514 throw e.rethrowFromSystemServer();
515 }
516 }
517
518 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700519 @SuppressWarnings("unchecked")
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800520 public FeatureInfo[] getSystemAvailableFeatures() {
521 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700522 ParceledListSlice<FeatureInfo> parceledList =
523 mPM.getSystemAvailableFeatures();
524 if (parceledList == null) {
525 return new FeatureInfo[0];
526 }
527 final List<FeatureInfo> list = parceledList.getList();
Jeff Sharkeyd5896632016-03-04 16:16:00 -0700528 final FeatureInfo[] res = new FeatureInfo[list.size()];
529 for (int i = 0; i < res.length; i++) {
530 res[i] = list.get(i);
531 }
532 return res;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800533 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700534 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800535 }
536 }
537
538 @Override
539 public boolean hasSystemFeature(String name) {
Jeff Sharkey115d2c12016-02-15 17:25:57 -0700540 return hasSystemFeature(name, 0);
541 }
542
543 @Override
544 public boolean hasSystemFeature(String name, int version) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800545 try {
Jeff Sharkey115d2c12016-02-15 17:25:57 -0700546 return mPM.hasSystemFeature(name, version);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800547 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700548 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800549 }
550 }
551
552 @Override
553 public int checkPermission(String permName, String pkgName) {
554 try {
Svetoslavc6d1c342015-02-26 14:44:43 -0800555 return mPM.checkPermission(permName, pkgName, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800556 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700557 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800558 }
559 }
560
561 @Override
Svet Ganovad3b2972015-07-07 22:49:17 -0700562 public boolean isPermissionRevokedByPolicy(String permName, String pkgName) {
563 try {
564 return mPM.isPermissionRevokedByPolicy(permName, pkgName, mContext.getUserId());
565 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700566 throw e.rethrowFromSystemServer();
Svet Ganovad3b2972015-07-07 22:49:17 -0700567 }
568 }
569
Svet Ganovf1b7f202015-07-29 08:33:42 -0700570 /**
571 * @hide
572 */
573 @Override
574 public String getPermissionControllerPackageName() {
575 synchronized (mLock) {
576 if (mPermissionsControllerPackageName == null) {
577 try {
578 mPermissionsControllerPackageName = mPM.getPermissionControllerPackageName();
579 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700580 throw e.rethrowFromSystemServer();
Svet Ganovf1b7f202015-07-29 08:33:42 -0700581 }
582 }
583 return mPermissionsControllerPackageName;
584 }
585 }
586
Svet Ganovad3b2972015-07-07 22:49:17 -0700587 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800588 public boolean addPermission(PermissionInfo info) {
589 try {
590 return mPM.addPermission(info);
591 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700592 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800593 }
594 }
595
596 @Override
597 public boolean addPermissionAsync(PermissionInfo info) {
598 try {
599 return mPM.addPermissionAsync(info);
600 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700601 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800602 }
603 }
604
605 @Override
606 public void removePermission(String name) {
607 try {
608 mPM.removePermission(name);
609 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700610 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800611 }
612 }
613
614 @Override
Svet Ganov8c7f7002015-05-07 10:48:44 -0700615 public void grantRuntimePermission(String packageName, String permissionName,
616 UserHandle user) {
Dianne Hackborne639da72012-02-21 15:11:13 -0800617 try {
Svet Ganov8c7f7002015-05-07 10:48:44 -0700618 mPM.grantRuntimePermission(packageName, permissionName, user.getIdentifier());
Dianne Hackborne639da72012-02-21 15:11:13 -0800619 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700620 throw e.rethrowFromSystemServer();
Dianne Hackborne639da72012-02-21 15:11:13 -0800621 }
622 }
623
624 @Override
Svet Ganov8c7f7002015-05-07 10:48:44 -0700625 public void revokeRuntimePermission(String packageName, String permissionName,
626 UserHandle user) {
Dianne Hackborne639da72012-02-21 15:11:13 -0800627 try {
Svet Ganov8c7f7002015-05-07 10:48:44 -0700628 mPM.revokeRuntimePermission(packageName, permissionName, user.getIdentifier());
629 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700630 throw e.rethrowFromSystemServer();
Svet Ganov8c7f7002015-05-07 10:48:44 -0700631 }
632 }
633
634 @Override
635 public int getPermissionFlags(String permissionName, String packageName, UserHandle user) {
636 try {
637 return mPM.getPermissionFlags(permissionName, packageName, user.getIdentifier());
638 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700639 throw e.rethrowFromSystemServer();
Svet Ganov8c7f7002015-05-07 10:48:44 -0700640 }
641 }
642
643 @Override
644 public void updatePermissionFlags(String permissionName, String packageName,
645 int flagMask, int flagValues, UserHandle user) {
646 try {
647 mPM.updatePermissionFlags(permissionName, packageName, flagMask,
648 flagValues, user.getIdentifier());
Dianne Hackborne639da72012-02-21 15:11:13 -0800649 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700650 throw e.rethrowFromSystemServer();
Dianne Hackborne639da72012-02-21 15:11:13 -0800651 }
652 }
653
654 @Override
Svetoslav20770dd2015-05-29 15:43:04 -0700655 public boolean shouldShowRequestPermissionRationale(String permission) {
656 try {
657 return mPM.shouldShowRequestPermissionRationale(permission,
658 mContext.getPackageName(), mContext.getUserId());
659 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700660 throw e.rethrowFromSystemServer();
Svetoslav20770dd2015-05-29 15:43:04 -0700661 }
662 }
663
664 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800665 public int checkSignatures(String pkg1, String pkg2) {
666 try {
667 return mPM.checkSignatures(pkg1, pkg2);
668 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700669 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800670 }
671 }
672
673 @Override
674 public int checkSignatures(int uid1, int uid2) {
675 try {
676 return mPM.checkUidSignatures(uid1, uid2);
677 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700678 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800679 }
680 }
681
682 @Override
683 public String[] getPackagesForUid(int uid) {
684 try {
685 return mPM.getPackagesForUid(uid);
686 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700687 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800688 }
689 }
690
691 @Override
692 public String getNameForUid(int uid) {
693 try {
694 return mPM.getNameForUid(uid);
695 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700696 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800697 }
698 }
699
700 @Override
701 public int getUidForSharedUser(String sharedUserName)
702 throws NameNotFoundException {
703 try {
704 int uid = mPM.getUidForSharedUser(sharedUserName);
705 if(uid != -1) {
706 return uid;
707 }
708 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700709 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800710 }
711 throw new NameNotFoundException("No shared userid for user:"+sharedUserName);
712 }
713
Kenny Roote6cd0c72011-05-19 12:48:14 -0700714 @SuppressWarnings("unchecked")
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800715 @Override
716 public List<PackageInfo> getInstalledPackages(int flags) {
Jeff Sharkeye06b4d12016-01-06 14:51:50 -0700717 return getInstalledPackagesAsUser(flags, mContext.getUserId());
Amith Yamasani151ec4c2012-09-07 19:25:16 -0700718 }
719
720 /** @hide */
721 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700722 @SuppressWarnings("unchecked")
Jeff Sharkeye06b4d12016-01-06 14:51:50 -0700723 public List<PackageInfo> getInstalledPackagesAsUser(int flags, int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800724 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700725 ParceledListSlice<PackageInfo> parceledList =
726 mPM.getInstalledPackages(flags, userId);
727 if (parceledList == null) {
728 return Collections.emptyList();
729 }
730 return parceledList.getList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800731 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700732 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800733 }
734 }
735
Kenny Roote6cd0c72011-05-19 12:48:14 -0700736 @SuppressWarnings("unchecked")
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800737 @Override
Dianne Hackborne7991752013-01-16 17:56:46 -0800738 public List<PackageInfo> getPackagesHoldingPermissions(
739 String[] permissions, int flags) {
740 final int userId = mContext.getUserId();
741 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700742 ParceledListSlice<PackageInfo> parceledList =
743 mPM.getPackagesHoldingPermissions(permissions, flags, userId);
744 if (parceledList == null) {
745 return Collections.emptyList();
746 }
747 return parceledList.getList();
Dianne Hackborne7991752013-01-16 17:56:46 -0800748 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700749 throw e.rethrowFromSystemServer();
Dianne Hackborne7991752013-01-16 17:56:46 -0800750 }
751 }
752
753 @SuppressWarnings("unchecked")
754 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800755 public List<ApplicationInfo> getInstalledApplications(int flags) {
Bartosz Fabianowski11334242016-11-17 20:49:16 +0100756 return getInstalledApplicationsAsUser(flags, mContext.getUserId());
757 }
758
759 /** @hide */
760 @SuppressWarnings("unchecked")
761 @Override
762 public List<ApplicationInfo> getInstalledApplicationsAsUser(int flags, int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800763 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700764 ParceledListSlice<ApplicationInfo> parceledList =
765 mPM.getInstalledApplications(flags, userId);
766 if (parceledList == null) {
767 return Collections.emptyList();
768 }
769 return parceledList.getList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800770 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700771 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800772 }
773 }
774
Svet Ganov2acf0632015-11-24 19:10:59 -0800775 /** @hide */
776 @SuppressWarnings("unchecked")
777 @Override
Svetoslav Ganov096d3042017-01-30 16:34:13 -0800778 public List<InstantAppInfo> getInstantApps() {
Svet Ganov2acf0632015-11-24 19:10:59 -0800779 try {
Svetoslav Ganov096d3042017-01-30 16:34:13 -0800780 ParceledListSlice<InstantAppInfo> slice =
781 mPM.getInstantApps(mContext.getUserId());
Svet Ganov2acf0632015-11-24 19:10:59 -0800782 if (slice != null) {
783 return slice.getList();
784 }
785 return Collections.emptyList();
786 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700787 throw e.rethrowFromSystemServer();
Svet Ganov2acf0632015-11-24 19:10:59 -0800788 }
789 }
790
791 /** @hide */
792 @Override
Svetoslav Ganov096d3042017-01-30 16:34:13 -0800793 public Drawable getInstantAppIcon(String packageName) {
Svet Ganov2acf0632015-11-24 19:10:59 -0800794 try {
Svetoslav Ganov096d3042017-01-30 16:34:13 -0800795 Bitmap bitmap = mPM.getInstantAppIcon(
Svet Ganov2acf0632015-11-24 19:10:59 -0800796 packageName, mContext.getUserId());
797 if (bitmap != null) {
798 return new BitmapDrawable(null, bitmap);
799 }
800 return null;
801 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700802 throw e.rethrowFromSystemServer();
Svet Ganov2acf0632015-11-24 19:10:59 -0800803 }
804 }
805
806 @Override
Svetoslav Ganov096d3042017-01-30 16:34:13 -0800807 public boolean isInstantApp() {
Svet Ganov2acf0632015-11-24 19:10:59 -0800808 try {
Svetoslav Ganov096d3042017-01-30 16:34:13 -0800809 return mPM.isInstantApp(mContext.getPackageName(),
810 mContext.getUserId());
Svet Ganov2acf0632015-11-24 19:10:59 -0800811 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700812 throw e.rethrowFromSystemServer();
Svet Ganov2acf0632015-11-24 19:10:59 -0800813 }
Svet Ganov2acf0632015-11-24 19:10:59 -0800814 }
815
816 @Override
Svetoslav Ganov096d3042017-01-30 16:34:13 -0800817 public int getInstantAppCookieMaxSize() {
Svet Ganov2acf0632015-11-24 19:10:59 -0800818 return Settings.Global.getInt(mContext.getContentResolver(),
819 Settings.Global.EPHEMERAL_COOKIE_MAX_SIZE_BYTES,
820 DEFAULT_EPHEMERAL_COOKIE_MAX_SIZE_BYTES);
821 }
822
823 @Override
Svetoslav Ganov096d3042017-01-30 16:34:13 -0800824 public @NonNull byte[] getInstantAppCookie() {
Svet Ganov2acf0632015-11-24 19:10:59 -0800825 try {
Svetoslav Ganov096d3042017-01-30 16:34:13 -0800826 final byte[] cookie = mPM.getInstantAppCookie(
Svet Ganov2acf0632015-11-24 19:10:59 -0800827 mContext.getPackageName(), mContext.getUserId());
828 if (cookie != null) {
829 return cookie;
Jeff Sharkey27b2e692016-02-25 17:40:12 -0700830 } else {
831 return EmptyArray.BYTE;
Svet Ganov2acf0632015-11-24 19:10:59 -0800832 }
833 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700834 throw e.rethrowFromSystemServer();
Svet Ganov2acf0632015-11-24 19:10:59 -0800835 }
Svet Ganov2acf0632015-11-24 19:10:59 -0800836 }
837
838 @Override
Svetoslav Ganov096d3042017-01-30 16:34:13 -0800839 public boolean setInstantAppCookie(@NonNull byte[] cookie) {
Svet Ganov2acf0632015-11-24 19:10:59 -0800840 try {
Svetoslav Ganov096d3042017-01-30 16:34:13 -0800841 return mPM.setInstantAppCookie(mContext.getPackageName(),
842 cookie, mContext.getUserId());
Svet Ganov2acf0632015-11-24 19:10:59 -0800843 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700844 throw e.rethrowFromSystemServer();
Svet Ganov2acf0632015-11-24 19:10:59 -0800845 }
Svet Ganov2acf0632015-11-24 19:10:59 -0800846 }
847
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800848 @Override
849 public ResolveInfo resolveActivity(Intent intent, int flags) {
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700850 return resolveActivityAsUser(intent, flags, mContext.getUserId());
Svetoslav Ganov58d37b52012-09-18 12:04:19 -0700851 }
852
853 @Override
854 public ResolveInfo resolveActivityAsUser(Intent intent, int flags, int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800855 try {
856 return mPM.resolveIntent(
857 intent,
858 intent.resolveTypeIfNeeded(mContext.getContentResolver()),
Svetoslav Ganov58d37b52012-09-18 12:04:19 -0700859 flags,
860 userId);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800861 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700862 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800863 }
864 }
865
866 @Override
867 public List<ResolveInfo> queryIntentActivities(Intent intent,
868 int flags) {
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700869 return queryIntentActivitiesAsUser(intent, flags, mContext.getUserId());
Amith Yamasani151ec4c2012-09-07 19:25:16 -0700870 }
871
872 /** @hide Same as above but for a specific user */
873 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700874 @SuppressWarnings("unchecked")
Svetoslav Ganov58d37b52012-09-18 12:04:19 -0700875 public List<ResolveInfo> queryIntentActivitiesAsUser(Intent intent,
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700876 int flags, int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800877 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700878 ParceledListSlice<ResolveInfo> parceledList =
879 mPM.queryIntentActivities(intent,
880 intent.resolveTypeIfNeeded(mContext.getContentResolver()),
881 flags, userId);
882 if (parceledList == null) {
883 return Collections.emptyList();
884 }
885 return parceledList.getList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800886 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700887 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800888 }
889 }
890
891 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700892 @SuppressWarnings("unchecked")
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800893 public List<ResolveInfo> queryIntentActivityOptions(
894 ComponentName caller, Intent[] specifics, Intent intent,
895 int flags) {
896 final ContentResolver resolver = mContext.getContentResolver();
897
898 String[] specificTypes = null;
899 if (specifics != null) {
900 final int N = specifics.length;
901 for (int i=0; i<N; i++) {
902 Intent sp = specifics[i];
903 if (sp != null) {
904 String t = sp.resolveTypeIfNeeded(resolver);
905 if (t != null) {
906 if (specificTypes == null) {
907 specificTypes = new String[N];
908 }
909 specificTypes[i] = t;
910 }
911 }
912 }
913 }
914
915 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700916 ParceledListSlice<ResolveInfo> parceledList =
917 mPM.queryIntentActivityOptions(caller, specifics, specificTypes, intent,
918 intent.resolveTypeIfNeeded(resolver), flags, mContext.getUserId());
919 if (parceledList == null) {
920 return Collections.emptyList();
921 }
922 return parceledList.getList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800923 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700924 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800925 }
926 }
927
Amith Yamasanif203aee2012-08-29 18:41:53 -0700928 /**
929 * @hide
930 */
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800931 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700932 @SuppressWarnings("unchecked")
Jeff Sharkeye06b4d12016-01-06 14:51:50 -0700933 public List<ResolveInfo> queryBroadcastReceiversAsUser(Intent intent, int flags, int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800934 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700935 ParceledListSlice<ResolveInfo> parceledList =
936 mPM.queryIntentReceivers(intent,
937 intent.resolveTypeIfNeeded(mContext.getContentResolver()),
938 flags, userId);
939 if (parceledList == null) {
940 return Collections.emptyList();
941 }
942 return parceledList.getList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800943 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700944 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800945 }
946 }
947
948 @Override
Amith Yamasanif203aee2012-08-29 18:41:53 -0700949 public List<ResolveInfo> queryBroadcastReceivers(Intent intent, int flags) {
Jeff Sharkeye06b4d12016-01-06 14:51:50 -0700950 return queryBroadcastReceiversAsUser(intent, flags, mContext.getUserId());
Amith Yamasanif203aee2012-08-29 18:41:53 -0700951 }
952
953 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800954 public ResolveInfo resolveService(Intent intent, int flags) {
955 try {
956 return mPM.resolveService(
957 intent,
958 intent.resolveTypeIfNeeded(mContext.getContentResolver()),
Amith Yamasani483f3b02012-03-13 16:08:00 -0700959 flags,
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700960 mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800961 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700962 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800963 }
964 }
965
966 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700967 @SuppressWarnings("unchecked")
Svetoslav Ganov58d37b52012-09-18 12:04:19 -0700968 public List<ResolveInfo> queryIntentServicesAsUser(Intent intent, int flags, int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800969 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700970 ParceledListSlice<ResolveInfo> parceledList =
971 mPM.queryIntentServices(intent,
972 intent.resolveTypeIfNeeded(mContext.getContentResolver()),
973 flags, userId);
974 if (parceledList == null) {
975 return Collections.emptyList();
976 }
977 return parceledList.getList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800978 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700979 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800980 }
981 }
982
983 @Override
Svetoslav Ganov58d37b52012-09-18 12:04:19 -0700984 public List<ResolveInfo> queryIntentServices(Intent intent, int flags) {
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700985 return queryIntentServicesAsUser(intent, flags, mContext.getUserId());
Svetoslav Ganov58d37b52012-09-18 12:04:19 -0700986 }
987
988 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700989 @SuppressWarnings("unchecked")
Jeff Sharkey85f5f812013-10-07 10:16:12 -0700990 public List<ResolveInfo> queryIntentContentProvidersAsUser(
991 Intent intent, int flags, int userId) {
992 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700993 ParceledListSlice<ResolveInfo> parceledList =
994 mPM.queryIntentContentProviders(intent,
995 intent.resolveTypeIfNeeded(mContext.getContentResolver()),
996 flags, userId);
997 if (parceledList == null) {
998 return Collections.emptyList();
999 }
1000 return parceledList.getList();
Jeff Sharkey85f5f812013-10-07 10:16:12 -07001001 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001002 throw e.rethrowFromSystemServer();
Jeff Sharkey85f5f812013-10-07 10:16:12 -07001003 }
1004 }
1005
1006 @Override
1007 public List<ResolveInfo> queryIntentContentProviders(Intent intent, int flags) {
1008 return queryIntentContentProvidersAsUser(intent, flags, mContext.getUserId());
1009 }
1010
1011 @Override
Alexandra Gherghina0363c3e2014-06-23 13:34:59 +01001012 public ProviderInfo resolveContentProvider(String name, int flags) {
1013 return resolveContentProviderAsUser(name, flags, mContext.getUserId());
1014 }
1015
1016 /** @hide **/
1017 @Override
1018 public ProviderInfo resolveContentProviderAsUser(String name, int flags, int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001019 try {
Alexandra Gherghina0363c3e2014-06-23 13:34:59 +01001020 return mPM.resolveContentProvider(name, flags, userId);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001021 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001022 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001023 }
1024 }
1025
1026 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001027 @SuppressWarnings("unchecked")
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001028 public List<ProviderInfo> queryContentProviders(String processName,
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001029 int uid, int flags) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001030 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001031 ParceledListSlice<ProviderInfo> slice =
1032 mPM.queryContentProviders(processName, uid, flags);
1033 return slice != null ? slice.getList() : Collections.<ProviderInfo>emptyList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001034 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001035 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001036 }
1037 }
1038
1039 @Override
1040 public InstrumentationInfo getInstrumentationInfo(
1041 ComponentName className, int flags)
1042 throws NameNotFoundException {
1043 try {
1044 InstrumentationInfo ii = mPM.getInstrumentationInfo(
1045 className, flags);
1046 if (ii != null) {
1047 return ii;
1048 }
1049 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001050 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001051 }
1052
1053 throw new NameNotFoundException(className.toString());
1054 }
1055
1056 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001057 @SuppressWarnings("unchecked")
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001058 public List<InstrumentationInfo> queryInstrumentation(
1059 String targetPackage, int flags) {
1060 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001061 ParceledListSlice<InstrumentationInfo> parceledList =
1062 mPM.queryInstrumentation(targetPackage, flags);
1063 if (parceledList == null) {
1064 return Collections.emptyList();
1065 }
1066 return parceledList.getList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001067 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001068 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001069 }
1070 }
1071
Alan Viveretteecd585a2015-04-13 10:32:51 -07001072 @Nullable
1073 @Override
1074 public Drawable getDrawable(String packageName, @DrawableRes int resId,
1075 @Nullable ApplicationInfo appInfo) {
1076 final ResourceName name = new ResourceName(packageName, resId);
1077 final Drawable cachedIcon = getCachedIcon(name);
1078 if (cachedIcon != null) {
1079 return cachedIcon;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001080 }
Alan Viveretteecd585a2015-04-13 10:32:51 -07001081
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001082 if (appInfo == null) {
1083 try {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001084 appInfo = getApplicationInfo(packageName, sDefaultFlags);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001085 } catch (NameNotFoundException e) {
1086 return null;
1087 }
1088 }
Alan Viveretteecd585a2015-04-13 10:32:51 -07001089
1090 if (resId != 0) {
1091 try {
1092 final Resources r = getResourcesForApplication(appInfo);
1093 final Drawable dr = r.getDrawable(resId, null);
1094 if (dr != null) {
1095 putCachedIcon(name, dr);
1096 }
1097
1098 if (false) {
1099 RuntimeException e = new RuntimeException("here");
1100 e.fillInStackTrace();
1101 Log.w(TAG, "Getting drawable 0x" + Integer.toHexString(resId)
1102 + " from package " + packageName
1103 + ": app scale=" + r.getCompatibilityInfo().applicationScale
1104 + ", caller scale=" + mContext.getResources()
1105 .getCompatibilityInfo().applicationScale,
1106 e);
1107 }
Ricky Wai3ce46252015-04-15 16:12:22 +01001108 if (DEBUG_ICONS) {
Alan Viveretteecd585a2015-04-13 10:32:51 -07001109 Log.v(TAG, "Getting drawable 0x"
1110 + Integer.toHexString(resId) + " from " + r
1111 + ": " + dr);
Ricky Wai3ce46252015-04-15 16:12:22 +01001112 }
1113 return dr;
Alan Viveretteecd585a2015-04-13 10:32:51 -07001114 } catch (NameNotFoundException e) {
1115 Log.w("PackageManager", "Failure retrieving resources for "
1116 + appInfo.packageName);
1117 } catch (Resources.NotFoundException e) {
1118 Log.w("PackageManager", "Failure retrieving resources for "
1119 + appInfo.packageName + ": " + e.getMessage());
1120 } catch (Exception e) {
1121 // If an exception was thrown, fall through to return
1122 // default icon.
1123 Log.w("PackageManager", "Failure retrieving icon 0x"
1124 + Integer.toHexString(resId) + " in package "
1125 + packageName, e);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001126 }
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001127 }
Alan Viveretteecd585a2015-04-13 10:32:51 -07001128
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001129 return null;
1130 }
1131
1132 @Override public Drawable getActivityIcon(ComponentName activityName)
1133 throws NameNotFoundException {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001134 return getActivityInfo(activityName, sDefaultFlags).loadIcon(this);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001135 }
1136
1137 @Override public Drawable getActivityIcon(Intent intent)
1138 throws NameNotFoundException {
1139 if (intent.getComponent() != null) {
1140 return getActivityIcon(intent.getComponent());
1141 }
1142
1143 ResolveInfo info = resolveActivity(
1144 intent, PackageManager.MATCH_DEFAULT_ONLY);
1145 if (info != null) {
1146 return info.activityInfo.loadIcon(this);
1147 }
1148
Romain Guy39fe17c2011-11-30 10:34:07 -08001149 throw new NameNotFoundException(intent.toUri(0));
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001150 }
1151
1152 @Override public Drawable getDefaultActivityIcon() {
1153 return Resources.getSystem().getDrawable(
1154 com.android.internal.R.drawable.sym_def_app_icon);
1155 }
1156
1157 @Override public Drawable getApplicationIcon(ApplicationInfo info) {
1158 return info.loadIcon(this);
1159 }
1160
1161 @Override public Drawable getApplicationIcon(String packageName)
1162 throws NameNotFoundException {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001163 return getApplicationIcon(getApplicationInfo(packageName, sDefaultFlags));
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001164 }
1165
1166 @Override
Jose Limaf78e3122014-03-06 12:13:15 -08001167 public Drawable getActivityBanner(ComponentName activityName)
1168 throws NameNotFoundException {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001169 return getActivityInfo(activityName, sDefaultFlags).loadBanner(this);
Jose Limaf78e3122014-03-06 12:13:15 -08001170 }
1171
1172 @Override
1173 public Drawable getActivityBanner(Intent intent)
1174 throws NameNotFoundException {
1175 if (intent.getComponent() != null) {
1176 return getActivityBanner(intent.getComponent());
1177 }
1178
1179 ResolveInfo info = resolveActivity(
1180 intent, PackageManager.MATCH_DEFAULT_ONLY);
1181 if (info != null) {
1182 return info.activityInfo.loadBanner(this);
1183 }
1184
1185 throw new NameNotFoundException(intent.toUri(0));
1186 }
1187
1188 @Override
1189 public Drawable getApplicationBanner(ApplicationInfo info) {
1190 return info.loadBanner(this);
1191 }
1192
1193 @Override
1194 public Drawable getApplicationBanner(String packageName)
1195 throws NameNotFoundException {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001196 return getApplicationBanner(getApplicationInfo(packageName, sDefaultFlags));
Jose Limaf78e3122014-03-06 12:13:15 -08001197 }
1198
1199 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001200 public Drawable getActivityLogo(ComponentName activityName)
1201 throws NameNotFoundException {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001202 return getActivityInfo(activityName, sDefaultFlags).loadLogo(this);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001203 }
1204
1205 @Override
1206 public Drawable getActivityLogo(Intent intent)
1207 throws NameNotFoundException {
1208 if (intent.getComponent() != null) {
1209 return getActivityLogo(intent.getComponent());
1210 }
1211
1212 ResolveInfo info = resolveActivity(
1213 intent, PackageManager.MATCH_DEFAULT_ONLY);
1214 if (info != null) {
1215 return info.activityInfo.loadLogo(this);
1216 }
1217
1218 throw new NameNotFoundException(intent.toUri(0));
1219 }
1220
1221 @Override
1222 public Drawable getApplicationLogo(ApplicationInfo info) {
1223 return info.loadLogo(this);
1224 }
1225
1226 @Override
1227 public Drawable getApplicationLogo(String packageName)
1228 throws NameNotFoundException {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001229 return getApplicationLogo(getApplicationInfo(packageName, sDefaultFlags));
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001230 }
1231
Svetoslavc7d62f02014-09-04 15:39:54 -07001232 @Override
1233 public Drawable getUserBadgedIcon(Drawable icon, UserHandle user) {
Kenny Guy02c89902016-11-15 19:36:38 +00001234 if (!isManagedProfile(user.getIdentifier())) {
Svetoslavc7d62f02014-09-04 15:39:54 -07001235 return icon;
1236 }
Kenny Guy02c89902016-11-15 19:36:38 +00001237 Drawable badgeShadow = getDrawable("system",
1238 com.android.internal.R.drawable.ic_corp_icon_badge_shadow, null);
1239 Drawable badgeColor = getDrawable("system",
1240 com.android.internal.R.drawable.ic_corp_icon_badge_color, null);
1241 badgeColor.setTint(getUserBadgeColor(user));
1242 Drawable badgeForeground = getDrawable("system",
1243 com.android.internal.R.drawable.ic_corp_icon_badge_case, null);
1244
1245 Drawable badge = new LayerDrawable(
1246 new Drawable[] {badgeShadow, badgeColor, badgeForeground });
1247 return getBadgedDrawable(icon, badge, null, true);
Svetoslavc7d62f02014-09-04 15:39:54 -07001248 }
1249
1250 @Override
1251 public Drawable getUserBadgedDrawableForDensity(Drawable drawable, UserHandle user,
1252 Rect badgeLocation, int badgeDensity) {
1253 Drawable badgeDrawable = getUserBadgeForDensity(user, badgeDensity);
1254 if (badgeDrawable == null) {
1255 return drawable;
1256 }
1257 return getBadgedDrawable(drawable, badgeDrawable, badgeLocation, true);
1258 }
1259
Kenny Guy02c89902016-11-15 19:36:38 +00001260 // Should have enough colors to cope with UserManagerService.getMaxManagedProfiles()
1261 @VisibleForTesting
1262 public static final int[] CORP_BADGE_COLORS = new int[] {
1263 com.android.internal.R.color.profile_badge_1,
1264 com.android.internal.R.color.profile_badge_2,
1265 com.android.internal.R.color.profile_badge_3
1266 };
1267
1268 @VisibleForTesting
1269 public static final int[] CORP_BADGE_LABEL_RES_ID = new int[] {
1270 com.android.internal.R.string.managed_profile_label_badge,
1271 com.android.internal.R.string.managed_profile_label_badge_2,
1272 com.android.internal.R.string.managed_profile_label_badge_3
1273 };
1274
1275 private int getUserBadgeColor(UserHandle user) {
1276 int badge = getUserManager().getManagedProfileBadge(user.getIdentifier());
1277 if (badge < 0) {
1278 badge = 0;
1279 }
1280 int resourceId = CORP_BADGE_COLORS[badge % CORP_BADGE_COLORS.length];
1281 return Resources.getSystem().getColor(resourceId, null);
1282 }
1283
Svetoslavc7d62f02014-09-04 15:39:54 -07001284 @Override
1285 public Drawable getUserBadgeForDensity(UserHandle user, int density) {
Kenny Guy02c89902016-11-15 19:36:38 +00001286 Drawable badgeColor = getManagedProfileIconForDensity(user,
1287 com.android.internal.R.drawable.ic_corp_badge_color, density);
1288 if (badgeColor == null) {
1289 return null;
1290 }
1291 badgeColor.setTint(getUserBadgeColor(user));
1292 Drawable badgeForeground = getDrawableForDensity(
1293 com.android.internal.R.drawable.ic_corp_badge_case, density);
1294 Drawable badge = new LayerDrawable(
1295 new Drawable[] {badgeColor, badgeForeground });
1296 return badge;
Selim Cineke6ff9462016-01-15 15:07:06 -08001297 }
1298
1299 @Override
1300 public Drawable getUserBadgeForDensityNoBackground(UserHandle user, int density) {
Kenny Guy02c89902016-11-15 19:36:38 +00001301 Drawable badge = getManagedProfileIconForDensity(user,
Vadim Tryshev66ae66a2016-02-18 15:41:21 -08001302 com.android.internal.R.drawable.ic_corp_badge_no_background, density);
Kenny Guy02c89902016-11-15 19:36:38 +00001303 if (badge != null) {
1304 badge.setTint(getUserBadgeColor(user));
1305 }
1306 return badge;
Selim Cineke6ff9462016-01-15 15:07:06 -08001307 }
1308
Vadim Tryshev66ae66a2016-02-18 15:41:21 -08001309 private Drawable getDrawableForDensity(int drawableId, int density) {
1310 if (density <= 0) {
1311 density = mContext.getResources().getDisplayMetrics().densityDpi;
1312 }
1313 return Resources.getSystem().getDrawableForDensity(drawableId, density);
1314 }
1315
1316 private Drawable getManagedProfileIconForDensity(UserHandle user, int drawableId, int density) {
Tony Mak8673b282016-03-21 21:10:59 +00001317 if (isManagedProfile(user.getIdentifier())) {
Vadim Tryshev66ae66a2016-02-18 15:41:21 -08001318 return getDrawableForDensity(drawableId, density);
Svetoslavc7d62f02014-09-04 15:39:54 -07001319 }
1320 return null;
1321 }
1322
1323 @Override
1324 public CharSequence getUserBadgedLabel(CharSequence label, UserHandle user) {
Tony Mak8673b282016-03-21 21:10:59 +00001325 if (isManagedProfile(user.getIdentifier())) {
Kenny Guy02c89902016-11-15 19:36:38 +00001326 int badge = getUserManager().getManagedProfileBadge(user.getIdentifier());
1327 int resourceId = CORP_BADGE_LABEL_RES_ID[badge % CORP_BADGE_LABEL_RES_ID.length];
1328 return Resources.getSystem().getString(resourceId, label);
Svetoslavc7d62f02014-09-04 15:39:54 -07001329 }
1330 return label;
1331 }
1332
Alan Viveretteecd585a2015-04-13 10:32:51 -07001333 @Override
1334 public Resources getResourcesForActivity(ComponentName activityName)
1335 throws NameNotFoundException {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001336 return getResourcesForApplication(
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001337 getActivityInfo(activityName, sDefaultFlags).applicationInfo);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001338 }
1339
Alan Viveretteecd585a2015-04-13 10:32:51 -07001340 @Override
1341 public Resources getResourcesForApplication(@NonNull ApplicationInfo app)
1342 throws NameNotFoundException {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001343 if (app.packageName.equals("system")) {
1344 return mContext.mMainThread.getSystemContext().getResources();
1345 }
Jeff Sharkey8a4c9722014-06-16 13:48:42 -07001346 final boolean sameUid = (app.uid == Process.myUid());
Adam Lesinski53fafdf2016-08-03 13:36:39 -07001347 final Resources r = mContext.mMainThread.getTopLevelResources(
Adam Lesinskic82f28a2016-06-08 17:19:09 -07001348 sameUid ? app.sourceDir : app.publicSourceDir,
1349 sameUid ? app.splitSourceDirs : app.splitPublicSourceDirs,
1350 app.resourceDirs, app.sharedLibraryFiles, Display.DEFAULT_DISPLAY,
1351 mContext.mPackageInfo);
Adam Lesinski53fafdf2016-08-03 13:36:39 -07001352 if (r != null) {
1353 return r;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001354 }
Adam Lesinski53fafdf2016-08-03 13:36:39 -07001355 throw new NameNotFoundException("Unable to open " + app.publicSourceDir);
1356
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001357 }
1358
Alan Viveretteecd585a2015-04-13 10:32:51 -07001359 @Override
1360 public Resources getResourcesForApplication(String appPackageName)
1361 throws NameNotFoundException {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001362 return getResourcesForApplication(
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001363 getApplicationInfo(appPackageName, sDefaultFlags));
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001364 }
1365
Amith Yamasani98edc952012-09-25 14:09:27 -07001366 /** @hide */
1367 @Override
1368 public Resources getResourcesForApplicationAsUser(String appPackageName, int userId)
1369 throws NameNotFoundException {
Jeff Sharkeyded653b2012-09-27 19:09:24 -07001370 if (userId < 0) {
1371 throw new IllegalArgumentException(
1372 "Call does not support special user #" + userId);
1373 }
1374 if ("system".equals(appPackageName)) {
1375 return mContext.mMainThread.getSystemContext().getResources();
1376 }
Amith Yamasani98edc952012-09-25 14:09:27 -07001377 try {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001378 ApplicationInfo ai = mPM.getApplicationInfo(appPackageName, sDefaultFlags, userId);
Amith Yamasani98edc952012-09-25 14:09:27 -07001379 if (ai != null) {
1380 return getResourcesForApplication(ai);
1381 }
1382 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001383 throw e.rethrowFromSystemServer();
Amith Yamasani98edc952012-09-25 14:09:27 -07001384 }
1385 throw new NameNotFoundException("Package " + appPackageName + " doesn't exist");
1386 }
1387
Jeff Sharkeycd654482016-01-08 17:42:11 -07001388 volatile int mCachedSafeMode = -1;
1389
1390 @Override
1391 public boolean isSafeMode() {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001392 try {
1393 if (mCachedSafeMode < 0) {
1394 mCachedSafeMode = mPM.isSafeMode() ? 1 : 0;
1395 }
1396 return mCachedSafeMode != 0;
1397 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001398 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001399 }
1400 }
1401
Svetoslavf7c06eb2015-06-10 18:43:22 -07001402 @Override
1403 public void addOnPermissionsChangeListener(OnPermissionsChangedListener listener) {
1404 synchronized (mPermissionListeners) {
1405 if (mPermissionListeners.get(listener) != null) {
1406 return;
1407 }
1408 OnPermissionsChangeListenerDelegate delegate =
1409 new OnPermissionsChangeListenerDelegate(listener, Looper.getMainLooper());
1410 try {
1411 mPM.addOnPermissionsChangeListener(delegate);
1412 mPermissionListeners.put(listener, delegate);
1413 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001414 throw e.rethrowFromSystemServer();
Svetoslavf7c06eb2015-06-10 18:43:22 -07001415 }
1416 }
1417 }
1418
1419 @Override
1420 public void removeOnPermissionsChangeListener(OnPermissionsChangedListener listener) {
1421 synchronized (mPermissionListeners) {
1422 IOnPermissionsChangeListener delegate = mPermissionListeners.get(listener);
1423 if (delegate != null) {
1424 try {
1425 mPM.removeOnPermissionsChangeListener(delegate);
1426 mPermissionListeners.remove(listener);
1427 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001428 throw e.rethrowFromSystemServer();
Svetoslavf7c06eb2015-06-10 18:43:22 -07001429 }
1430 }
1431 }
1432 }
1433
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001434 static void configurationChanged() {
1435 synchronized (sSync) {
1436 sIconCache.clear();
1437 sStringCache.clear();
1438 }
1439 }
1440
Yao Chen022b8ea2016-12-16 11:03:28 -08001441 protected ApplicationPackageManager(ContextImpl context,
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001442 IPackageManager pm) {
1443 mContext = context;
1444 mPM = pm;
1445 }
1446
Alan Viveretteecd585a2015-04-13 10:32:51 -07001447 @Nullable
1448 private Drawable getCachedIcon(@NonNull ResourceName name) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001449 synchronized (sSync) {
Alan Viveretteecd585a2015-04-13 10:32:51 -07001450 final WeakReference<Drawable.ConstantState> wr = sIconCache.get(name);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001451 if (DEBUG_ICONS) Log.v(TAG, "Get cached weak drawable ref for "
1452 + name + ": " + wr);
1453 if (wr != null) { // we have the activity
Alan Viveretteecd585a2015-04-13 10:32:51 -07001454 final Drawable.ConstantState state = wr.get();
Romain Guy39fe17c2011-11-30 10:34:07 -08001455 if (state != null) {
1456 if (DEBUG_ICONS) {
1457 Log.v(TAG, "Get cached drawable state for " + name + ": " + state);
1458 }
1459 // Note: It's okay here to not use the newDrawable(Resources) variant
1460 // of the API. The ConstantState comes from a drawable that was
1461 // originally created by passing the proper app Resources instance
1462 // which means the state should already contain the proper
1463 // resources specific information (like density.) See
1464 // BitmapDrawable.BitmapState for instance.
1465 return state.newDrawable();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001466 }
1467 // our entry has been purged
1468 sIconCache.remove(name);
1469 }
1470 }
1471 return null;
1472 }
1473
Alan Viveretteecd585a2015-04-13 10:32:51 -07001474 private void putCachedIcon(@NonNull ResourceName name, @NonNull Drawable dr) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001475 synchronized (sSync) {
Alan Viveretteecd585a2015-04-13 10:32:51 -07001476 sIconCache.put(name, new WeakReference<>(dr.getConstantState()));
Romain Guy39fe17c2011-11-30 10:34:07 -08001477 if (DEBUG_ICONS) Log.v(TAG, "Added cached drawable state for " + name + ": " + dr);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001478 }
1479 }
1480
Romain Guy39fe17c2011-11-30 10:34:07 -08001481 static void handlePackageBroadcast(int cmd, String[] pkgList, boolean hasPkgInfo) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001482 boolean immediateGc = false;
Sudheer Shankacc6418f2016-10-13 12:03:44 -07001483 if (cmd == ApplicationThreadConstants.EXTERNAL_STORAGE_UNAVAILABLE) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001484 immediateGc = true;
1485 }
1486 if (pkgList != null && (pkgList.length > 0)) {
1487 boolean needCleanup = false;
1488 for (String ssp : pkgList) {
1489 synchronized (sSync) {
Dianne Hackbornadd005c2013-07-17 18:43:12 -07001490 for (int i=sIconCache.size()-1; i>=0; i--) {
1491 ResourceName nm = sIconCache.keyAt(i);
1492 if (nm.packageName.equals(ssp)) {
1493 //Log.i(TAG, "Removing cached drawable for " + nm);
1494 sIconCache.removeAt(i);
1495 needCleanup = true;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001496 }
1497 }
Dianne Hackbornadd005c2013-07-17 18:43:12 -07001498 for (int i=sStringCache.size()-1; i>=0; i--) {
1499 ResourceName nm = sStringCache.keyAt(i);
1500 if (nm.packageName.equals(ssp)) {
1501 //Log.i(TAG, "Removing cached string for " + nm);
1502 sStringCache.removeAt(i);
1503 needCleanup = true;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001504 }
1505 }
1506 }
1507 }
1508 if (needCleanup || hasPkgInfo) {
1509 if (immediateGc) {
1510 // Schedule an immediate gc.
1511 Runtime.getRuntime().gc();
1512 } else {
1513 ActivityThread.currentActivityThread().scheduleGcIdler();
1514 }
1515 }
1516 }
1517 }
1518
1519 private static final class ResourceName {
1520 final String packageName;
1521 final int iconId;
1522
1523 ResourceName(String _packageName, int _iconId) {
1524 packageName = _packageName;
1525 iconId = _iconId;
1526 }
1527
1528 ResourceName(ApplicationInfo aInfo, int _iconId) {
1529 this(aInfo.packageName, _iconId);
1530 }
1531
1532 ResourceName(ComponentInfo cInfo, int _iconId) {
1533 this(cInfo.applicationInfo.packageName, _iconId);
1534 }
1535
1536 ResourceName(ResolveInfo rInfo, int _iconId) {
1537 this(rInfo.activityInfo.applicationInfo.packageName, _iconId);
1538 }
1539
1540 @Override
1541 public boolean equals(Object o) {
1542 if (this == o) return true;
1543 if (o == null || getClass() != o.getClass()) return false;
1544
1545 ResourceName that = (ResourceName) o;
1546
1547 if (iconId != that.iconId) return false;
1548 return !(packageName != null ?
1549 !packageName.equals(that.packageName) : that.packageName != null);
1550
1551 }
1552
1553 @Override
1554 public int hashCode() {
1555 int result;
1556 result = packageName.hashCode();
1557 result = 31 * result + iconId;
1558 return result;
1559 }
1560
1561 @Override
1562 public String toString() {
1563 return "{ResourceName " + packageName + " / " + iconId + "}";
1564 }
1565 }
1566
1567 private CharSequence getCachedString(ResourceName name) {
1568 synchronized (sSync) {
1569 WeakReference<CharSequence> wr = sStringCache.get(name);
1570 if (wr != null) { // we have the activity
1571 CharSequence cs = wr.get();
1572 if (cs != null) {
1573 return cs;
1574 }
1575 // our entry has been purged
1576 sStringCache.remove(name);
1577 }
1578 }
1579 return null;
1580 }
1581
1582 private void putCachedString(ResourceName name, CharSequence cs) {
1583 synchronized (sSync) {
1584 sStringCache.put(name, new WeakReference<CharSequence>(cs));
1585 }
1586 }
1587
1588 @Override
Tor Norbye7b9c9122013-05-30 16:48:33 -07001589 public CharSequence getText(String packageName, @StringRes int resid,
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001590 ApplicationInfo appInfo) {
1591 ResourceName name = new ResourceName(packageName, resid);
1592 CharSequence text = getCachedString(name);
1593 if (text != null) {
1594 return text;
1595 }
1596 if (appInfo == null) {
1597 try {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001598 appInfo = getApplicationInfo(packageName, sDefaultFlags);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001599 } catch (NameNotFoundException e) {
1600 return null;
1601 }
1602 }
1603 try {
1604 Resources r = getResourcesForApplication(appInfo);
1605 text = r.getText(resid);
1606 putCachedString(name, text);
1607 return text;
1608 } catch (NameNotFoundException e) {
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07001609 Log.w("PackageManager", "Failure retrieving resources for "
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001610 + appInfo.packageName);
1611 } catch (RuntimeException e) {
1612 // If an exception was thrown, fall through to return
1613 // default icon.
1614 Log.w("PackageManager", "Failure retrieving text 0x"
1615 + Integer.toHexString(resid) + " in package "
1616 + packageName, e);
1617 }
1618 return null;
1619 }
1620
1621 @Override
Tor Norbye7b9c9122013-05-30 16:48:33 -07001622 public XmlResourceParser getXml(String packageName, @XmlRes int resid,
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001623 ApplicationInfo appInfo) {
1624 if (appInfo == null) {
1625 try {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001626 appInfo = getApplicationInfo(packageName, sDefaultFlags);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001627 } catch (NameNotFoundException e) {
1628 return null;
1629 }
1630 }
1631 try {
1632 Resources r = getResourcesForApplication(appInfo);
1633 return r.getXml(resid);
1634 } catch (RuntimeException e) {
1635 // If an exception was thrown, fall through to return
1636 // default icon.
1637 Log.w("PackageManager", "Failure retrieving xml 0x"
1638 + Integer.toHexString(resid) + " in package "
1639 + packageName, e);
1640 } catch (NameNotFoundException e) {
Alon Albert3fa51e32010-11-11 09:24:04 -08001641 Log.w("PackageManager", "Failure retrieving resources for "
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001642 + appInfo.packageName);
1643 }
1644 return null;
1645 }
1646
1647 @Override
1648 public CharSequence getApplicationLabel(ApplicationInfo info) {
1649 return info.loadLabel(this);
1650 }
1651
1652 @Override
1653 public void installPackage(Uri packageURI, IPackageInstallObserver observer, int flags,
1654 String installerPackageName) {
Jeff Sharkey513a0742014-07-08 17:10:32 -07001655 installCommon(packageURI, new LegacyPackageInstallObserver(observer), flags,
Todd Kennedya6793232016-02-24 22:46:00 +00001656 installerPackageName, mContext.getUserId());
Christopher Tatef1977b42014-03-24 16:25:51 -07001657 }
1658
Christopher Tatef1977b42014-03-24 16:25:51 -07001659 @Override
1660 public void installPackage(Uri packageURI, PackageInstallObserver observer,
1661 int flags, String installerPackageName) {
Todd Kennedya6793232016-02-24 22:46:00 +00001662 installCommon(packageURI, observer, flags, installerPackageName, mContext.getUserId());
Jeff Sharkey513a0742014-07-08 17:10:32 -07001663 }
1664
1665 private void installCommon(Uri packageURI,
1666 PackageInstallObserver observer, int flags, String installerPackageName,
Nicolas Prevot9a80e532015-09-23 15:49:28 +01001667 int userId) {
Jeff Sharkey513a0742014-07-08 17:10:32 -07001668 if (!"file".equals(packageURI.getScheme())) {
1669 throw new UnsupportedOperationException("Only file:// URIs are supported");
1670 }
Jeff Sharkey513a0742014-07-08 17:10:32 -07001671
1672 final String originPath = packageURI.getPath();
Christopher Tatef1977b42014-03-24 16:25:51 -07001673 try {
Nicolas Prevot9a80e532015-09-23 15:49:28 +01001674 mPM.installPackageAsUser(originPath, observer.getBinder(), flags, installerPackageName,
Todd Kennedya6793232016-02-24 22:46:00 +00001675 userId);
Jeff Sharkey27b2e692016-02-25 17:40:12 -07001676 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001677 throw e.rethrowFromSystemServer();
rich cannings706e8ba2012-08-20 13:20:14 -07001678 }
1679 }
1680
1681 @Override
Nicolas Prevot9a80e532015-09-23 15:49:28 +01001682 public int installExistingPackage(String packageName) throws NameNotFoundException {
Robin Lee0e27c872015-09-28 14:37:40 +01001683 return installExistingPackageAsUser(packageName, mContext.getUserId());
Nicolas Prevot9a80e532015-09-23 15:49:28 +01001684 }
1685
1686 @Override
1687 public int installExistingPackageAsUser(String packageName, int userId)
Dianne Hackborn7767eac2012-08-23 18:25:40 -07001688 throws NameNotFoundException {
1689 try {
Bartosz Fabianowskia34f53f2017-01-11 18:08:47 +01001690 int res = mPM.installExistingPackageAsUser(packageName, userId,
1691 PackageManager.INSTALL_REASON_UNKNOWN);
Dianne Hackborn7767eac2012-08-23 18:25:40 -07001692 if (res == INSTALL_FAILED_INVALID_URI) {
1693 throw new NameNotFoundException("Package " + packageName + " doesn't exist");
1694 }
1695 return res;
1696 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001697 throw e.rethrowFromSystemServer();
Dianne Hackborn7767eac2012-08-23 18:25:40 -07001698 }
1699 }
1700
1701 @Override
Kenny Root3a9b5fb2011-09-20 14:15:38 -07001702 public void verifyPendingInstall(int id, int response) {
Kenny Root5ab21572011-07-27 11:11:19 -07001703 try {
Kenny Root3a9b5fb2011-09-20 14:15:38 -07001704 mPM.verifyPendingInstall(id, response);
Kenny Root5ab21572011-07-27 11:11:19 -07001705 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001706 throw e.rethrowFromSystemServer();
Kenny Root5ab21572011-07-27 11:11:19 -07001707 }
1708 }
1709
1710 @Override
rich canningsd9ef3e52012-08-22 14:28:05 -07001711 public void extendVerificationTimeout(int id, int verificationCodeAtTimeout,
1712 long millisecondsToDelay) {
1713 try {
1714 mPM.extendVerificationTimeout(id, verificationCodeAtTimeout, millisecondsToDelay);
1715 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001716 throw e.rethrowFromSystemServer();
rich canningsd9ef3e52012-08-22 14:28:05 -07001717 }
1718 }
1719
1720 @Override
Todd Kennedydfa93ab2016-03-03 15:24:33 -08001721 public void verifyIntentFilter(int id, int verificationCode, List<String> failedDomains) {
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001722 try {
Todd Kennedydfa93ab2016-03-03 15:24:33 -08001723 mPM.verifyIntentFilter(id, verificationCode, failedDomains);
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001724 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001725 throw e.rethrowFromSystemServer();
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001726 }
1727 }
1728
1729 @Override
Jeff Sharkeye06b4d12016-01-06 14:51:50 -07001730 public int getIntentVerificationStatusAsUser(String packageName, int userId) {
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001731 try {
1732 return mPM.getIntentVerificationStatus(packageName, userId);
1733 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001734 throw e.rethrowFromSystemServer();
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001735 }
1736 }
1737
1738 @Override
Jeff Sharkeye06b4d12016-01-06 14:51:50 -07001739 public boolean updateIntentVerificationStatusAsUser(String packageName, int status, int userId) {
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001740 try {
1741 return mPM.updateIntentVerificationStatus(packageName, status, userId);
1742 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001743 throw e.rethrowFromSystemServer();
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001744 }
1745 }
1746
1747 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001748 @SuppressWarnings("unchecked")
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001749 public List<IntentFilterVerificationInfo> getIntentFilterVerifications(String packageName) {
1750 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001751 ParceledListSlice<IntentFilterVerificationInfo> parceledList =
1752 mPM.getIntentFilterVerifications(packageName);
1753 if (parceledList == null) {
1754 return Collections.emptyList();
1755 }
1756 return parceledList.getList();
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001757 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001758 throw e.rethrowFromSystemServer();
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001759 }
1760 }
1761
1762 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001763 @SuppressWarnings("unchecked")
Fabrice Di Meglio07885952015-04-06 19:41:28 -07001764 public List<IntentFilter> getAllIntentFilters(String packageName) {
1765 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001766 ParceledListSlice<IntentFilter> parceledList =
1767 mPM.getAllIntentFilters(packageName);
1768 if (parceledList == null) {
1769 return Collections.emptyList();
1770 }
1771 return parceledList.getList();
Fabrice Di Meglio07885952015-04-06 19:41:28 -07001772 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001773 throw e.rethrowFromSystemServer();
Fabrice Di Meglio07885952015-04-06 19:41:28 -07001774 }
1775 }
1776
1777 @Override
Jeff Sharkeye06b4d12016-01-06 14:51:50 -07001778 public String getDefaultBrowserPackageNameAsUser(int userId) {
Fabrice Di Meglio62271722015-04-10 17:24:02 -07001779 try {
1780 return mPM.getDefaultBrowserPackageName(userId);
1781 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001782 throw e.rethrowFromSystemServer();
Fabrice Di Meglio62271722015-04-10 17:24:02 -07001783 }
1784 }
1785
1786 @Override
Jeff Sharkeye06b4d12016-01-06 14:51:50 -07001787 public boolean setDefaultBrowserPackageNameAsUser(String packageName, int userId) {
Fabrice Di Meglio62271722015-04-10 17:24:02 -07001788 try {
1789 return mPM.setDefaultBrowserPackageName(packageName, userId);
1790 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001791 throw e.rethrowFromSystemServer();
Fabrice Di Meglio62271722015-04-10 17:24:02 -07001792 }
1793 }
1794
1795 @Override
Dianne Hackborn880119b2010-11-18 22:26:40 -08001796 public void setInstallerPackageName(String targetPackage,
1797 String installerPackageName) {
1798 try {
1799 mPM.setInstallerPackageName(targetPackage, installerPackageName);
1800 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001801 throw e.rethrowFromSystemServer();
Dianne Hackborn880119b2010-11-18 22:26:40 -08001802 }
1803 }
1804
1805 @Override
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001806 public String getInstallerPackageName(String packageName) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001807 try {
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001808 return mPM.getInstallerPackageName(packageName);
1809 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001810 throw e.rethrowFromSystemServer();
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001811 }
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001812 }
1813
1814 @Override
1815 public int getMoveStatus(int moveId) {
1816 try {
1817 return mPM.getMoveStatus(moveId);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001818 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001819 throw e.rethrowFromSystemServer();
Jeff Sharkeyb2b9ab82015-04-05 21:10:42 -07001820 }
1821 }
1822
1823 @Override
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001824 public void registerMoveCallback(MoveCallback callback, Handler handler) {
1825 synchronized (mDelegates) {
1826 final MoveCallbackDelegate delegate = new MoveCallbackDelegate(callback,
1827 handler.getLooper());
1828 try {
1829 mPM.registerMoveCallback(delegate);
1830 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001831 throw e.rethrowFromSystemServer();
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001832 }
1833 mDelegates.add(delegate);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001834 }
1835 }
1836
1837 @Override
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001838 public void unregisterMoveCallback(MoveCallback callback) {
1839 synchronized (mDelegates) {
1840 for (Iterator<MoveCallbackDelegate> i = mDelegates.iterator(); i.hasNext();) {
1841 final MoveCallbackDelegate delegate = i.next();
1842 if (delegate.mCallback == callback) {
1843 try {
1844 mPM.unregisterMoveCallback(delegate);
1845 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001846 throw e.rethrowFromSystemServer();
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001847 }
1848 i.remove();
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001849 }
1850 }
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001851 }
1852 }
1853
1854 @Override
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001855 public int movePackage(String packageName, VolumeInfo vol) {
1856 try {
1857 final String volumeUuid;
1858 if (VolumeInfo.ID_PRIVATE_INTERNAL.equals(vol.id)) {
1859 volumeUuid = StorageManager.UUID_PRIVATE_INTERNAL;
1860 } else if (vol.isPrimaryPhysical()) {
1861 volumeUuid = StorageManager.UUID_PRIMARY_PHYSICAL;
1862 } else {
1863 volumeUuid = Preconditions.checkNotNull(vol.fsUuid);
1864 }
1865
1866 return mPM.movePackage(packageName, volumeUuid);
1867 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001868 throw e.rethrowFromSystemServer();
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001869 }
1870 }
1871
1872 @Override
1873 public @Nullable VolumeInfo getPackageCurrentVolume(ApplicationInfo app) {
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001874 final StorageManager storage = mContext.getSystemService(StorageManager.class);
Yao Chen022b8ea2016-12-16 11:03:28 -08001875 return getPackageCurrentVolume(app, storage);
1876 }
1877
1878 @VisibleForTesting
1879 protected @Nullable VolumeInfo getPackageCurrentVolume(ApplicationInfo app,
1880 StorageManager storage) {
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001881 if (app.isInternal()) {
1882 return storage.findVolumeById(VolumeInfo.ID_PRIVATE_INTERNAL);
1883 } else if (app.isExternalAsec()) {
1884 return storage.getPrimaryPhysicalVolume();
1885 } else {
1886 return storage.findVolumeByUuid(app.volumeUuid);
1887 }
1888 }
1889
1890 @Override
1891 public @NonNull List<VolumeInfo> getPackageCandidateVolumes(ApplicationInfo app) {
Yao Chen022b8ea2016-12-16 11:03:28 -08001892 final StorageManager storageManager = mContext.getSystemService(StorageManager.class);
1893 return getPackageCandidateVolumes(app, storageManager, mPM);
1894 }
1895
1896 @VisibleForTesting
1897 protected @NonNull List<VolumeInfo> getPackageCandidateVolumes(ApplicationInfo app,
1898 StorageManager storageManager, IPackageManager pm) {
1899 final VolumeInfo currentVol = getPackageCurrentVolume(app, storageManager);
1900 final List<VolumeInfo> vols = storageManager.getVolumes();
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001901 final List<VolumeInfo> candidates = new ArrayList<>();
1902 for (VolumeInfo vol : vols) {
Yao Chen022b8ea2016-12-16 11:03:28 -08001903 if (Objects.equals(vol, currentVol)
1904 || isPackageCandidateVolume(mContext, app, vol, pm)) {
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001905 candidates.add(vol);
1906 }
1907 }
1908 return candidates;
1909 }
1910
Yao Chen022b8ea2016-12-16 11:03:28 -08001911 @VisibleForTesting
1912 protected boolean isForceAllowOnExternal(Context context) {
1913 return Settings.Global.getInt(
Todd Kennedyf39ca8f2015-08-07 14:15:07 -07001914 context.getContentResolver(), Settings.Global.FORCE_ALLOW_ON_EXTERNAL, 0) != 0;
Yao Chen022b8ea2016-12-16 11:03:28 -08001915 }
1916
1917 @VisibleForTesting
1918 protected boolean isAllow3rdPartyOnInternal(Context context) {
1919 return context.getResources().getBoolean(
1920 com.android.internal.R.bool.config_allow3rdPartyAppOnInternal);
1921 }
1922
1923 private boolean isPackageCandidateVolume(
1924 ContextImpl context, ApplicationInfo app, VolumeInfo vol, IPackageManager pm) {
1925 final boolean forceAllowOnExternal = isForceAllowOnExternal(context);
1926
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001927 if (VolumeInfo.ID_PRIVATE_INTERNAL.equals(vol.getId())) {
Yao Chen022b8ea2016-12-16 11:03:28 -08001928 return app.isSystemApp() || isAllow3rdPartyOnInternal(context);
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001929 }
1930
1931 // System apps and apps demanding internal storage can't be moved
1932 // anywhere else
Todd Kennedyf39ca8f2015-08-07 14:15:07 -07001933 if (app.isSystemApp()) {
1934 return false;
1935 }
1936 if (!forceAllowOnExternal
Dianne Hackborn30a4e6d2015-10-12 17:14:56 -07001937 && (app.installLocation == PackageInfo.INSTALL_LOCATION_INTERNAL_ONLY
1938 || app.installLocation == PackageInfo.INSTALL_LOCATION_UNSPECIFIED)) {
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001939 return false;
1940 }
1941
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001942 // Gotta be able to write there
1943 if (!vol.isMountedWritable()) {
1944 return false;
1945 }
1946
1947 // Moving into an ASEC on public primary is only option internal
1948 if (vol.isPrimaryPhysical()) {
1949 return app.isInternal();
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001950 }
1951
Makoto Onukif34db0a2016-02-17 11:17:15 -08001952 // Some apps can't be moved. (e.g. device admins)
1953 try {
Yao Chen022b8ea2016-12-16 11:03:28 -08001954 if (pm.isPackageDeviceAdminOnAnyUser(app.packageName)) {
Makoto Onukif34db0a2016-02-17 11:17:15 -08001955 return false;
1956 }
1957 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001958 throw e.rethrowFromSystemServer();
Makoto Onukif34db0a2016-02-17 11:17:15 -08001959 }
1960
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001961 // Otherwise we can move to any private volume
1962 return (vol.getType() == VolumeInfo.TYPE_PRIVATE);
1963 }
1964
1965 @Override
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001966 public int movePrimaryStorage(VolumeInfo vol) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001967 try {
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001968 final String volumeUuid;
1969 if (VolumeInfo.ID_PRIVATE_INTERNAL.equals(vol.id)) {
1970 volumeUuid = StorageManager.UUID_PRIVATE_INTERNAL;
1971 } else if (vol.isPrimaryPhysical()) {
1972 volumeUuid = StorageManager.UUID_PRIMARY_PHYSICAL;
1973 } else {
1974 volumeUuid = Preconditions.checkNotNull(vol.fsUuid);
1975 }
1976
1977 return mPM.movePrimaryStorage(volumeUuid);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001978 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001979 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001980 }
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001981 }
1982
Jeff Sharkey275e3e42015-04-24 16:10:32 -07001983 @Override
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001984 public @Nullable VolumeInfo getPrimaryStorageCurrentVolume() {
1985 final StorageManager storage = mContext.getSystemService(StorageManager.class);
1986 final String volumeUuid = storage.getPrimaryStorageUuid();
Jeff Sharkey50a05452015-04-29 11:24:52 -07001987 return storage.findVolumeByQualifiedUuid(volumeUuid);
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001988 }
1989
Jeff Sharkey275e3e42015-04-24 16:10:32 -07001990 @Override
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001991 public @NonNull List<VolumeInfo> getPrimaryStorageCandidateVolumes() {
1992 final StorageManager storage = mContext.getSystemService(StorageManager.class);
1993 final VolumeInfo currentVol = getPrimaryStorageCurrentVolume();
1994 final List<VolumeInfo> vols = storage.getVolumes();
1995 final List<VolumeInfo> candidates = new ArrayList<>();
Jeff Sharkeyfced5342015-05-10 14:53:34 -07001996 if (Objects.equals(StorageManager.UUID_PRIMARY_PHYSICAL,
1997 storage.getPrimaryStorageUuid()) && currentVol != null) {
1998 // TODO: support moving primary physical to emulated volume
1999 candidates.add(currentVol);
2000 } else {
2001 for (VolumeInfo vol : vols) {
2002 if (Objects.equals(vol, currentVol) || isPrimaryStorageCandidateVolume(vol)) {
2003 candidates.add(vol);
2004 }
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002005 }
2006 }
2007 return candidates;
2008 }
2009
2010 private static boolean isPrimaryStorageCandidateVolume(VolumeInfo vol) {
2011 // Private internal is always an option
2012 if (VolumeInfo.ID_PRIVATE_INTERNAL.equals(vol.getId())) {
2013 return true;
2014 }
2015
2016 // Gotta be able to write there
2017 if (!vol.isMountedWritable()) {
2018 return false;
2019 }
2020
Jeff Sharkeyfced5342015-05-10 14:53:34 -07002021 // We can move to any private volume
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002022 return (vol.getType() == VolumeInfo.TYPE_PRIVATE);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002023 }
2024
2025 @Override
2026 public void deletePackage(String packageName, IPackageDeleteObserver observer, int flags) {
Robin Lee0e27c872015-09-28 14:37:40 +01002027 deletePackageAsUser(packageName, observer, flags, mContext.getUserId());
Nicolas Prevot9a80e532015-09-23 15:49:28 +01002028 }
2029
2030 @Override
Svet Ganov67882122016-12-11 16:36:34 -08002031 public void deletePackageAsUser(String packageName, IPackageDeleteObserver observer,
2032 int flags, int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002033 try {
Svet Ganov67882122016-12-11 16:36:34 -08002034 mPM.deletePackageAsUser(packageName, PackageManager.VERSION_CODE_HIGHEST,
2035 observer, userId, flags);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002036 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002037 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002038 }
2039 }
Jeff Sharkeyfbd0e9f2014-08-06 16:34:34 -07002040
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002041 @Override
2042 public void clearApplicationUserData(String packageName,
2043 IPackageDataObserver observer) {
2044 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -07002045 mPM.clearApplicationUserData(packageName, observer, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002046 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002047 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002048 }
2049 }
2050 @Override
2051 public void deleteApplicationCacheFiles(String packageName,
2052 IPackageDataObserver observer) {
2053 try {
2054 mPM.deleteApplicationCacheFiles(packageName, observer);
2055 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002056 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002057 }
2058 }
Jeff Sharkey529f91f2015-04-18 20:23:13 -07002059
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002060 @Override
Suprabh Shukla78c9eb82016-04-12 15:51:35 -07002061 public void deleteApplicationCacheFilesAsUser(String packageName, int userId,
2062 IPackageDataObserver observer) {
2063 try {
2064 mPM.deleteApplicationCacheFilesAsUser(packageName, userId, observer);
2065 } catch (RemoteException e) {
2066 throw e.rethrowFromSystemServer();
2067 }
2068 }
2069
2070 @Override
Jeff Sharkey529f91f2015-04-18 20:23:13 -07002071 public void freeStorageAndNotify(String volumeUuid, long idealStorageSize,
2072 IPackageDataObserver observer) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002073 try {
Jeff Sharkey529f91f2015-04-18 20:23:13 -07002074 mPM.freeStorageAndNotify(volumeUuid, idealStorageSize, observer);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002075 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002076 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002077 }
2078 }
2079
2080 @Override
Jeff Sharkey529f91f2015-04-18 20:23:13 -07002081 public void freeStorage(String volumeUuid, long freeStorageSize, IntentSender pi) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002082 try {
Jeff Sharkey529f91f2015-04-18 20:23:13 -07002083 mPM.freeStorage(volumeUuid, freeStorageSize, pi);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002084 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002085 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002086 }
2087 }
2088
2089 @Override
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00002090 public String[] setPackagesSuspendedAsUser(String[] packageNames, boolean suspended,
2091 int userId) {
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00002092 try {
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00002093 return mPM.setPackagesSuspendedAsUser(packageNames, suspended, userId);
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00002094 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002095 throw e.rethrowFromSystemServer();
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00002096 }
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00002097 }
2098
2099 @Override
Andrei Stingaceanu355b2322016-02-12 16:43:51 +00002100 public boolean isPackageSuspendedForUser(String packageName, int userId) {
2101 try {
2102 return mPM.isPackageSuspendedForUser(packageName, userId);
2103 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002104 throw e.rethrowFromSystemServer();
Andrei Stingaceanu355b2322016-02-12 16:43:51 +00002105 }
Andrei Stingaceanu355b2322016-02-12 16:43:51 +00002106 }
2107
Jeff Sharkey9bc89af2017-01-11 11:25:50 -07002108 /** @hide */
2109 @Override
2110 public void setApplicationCategoryHint(String packageName, int categoryHint) {
2111 try {
2112 mPM.setApplicationCategoryHint(packageName, categoryHint,
2113 mContext.getOpPackageName());
2114 } catch (RemoteException e) {
2115 throw e.rethrowFromSystemServer();
2116 }
2117 }
2118
Andrei Stingaceanu355b2322016-02-12 16:43:51 +00002119 @Override
Jeff Sharkeye06b4d12016-01-06 14:51:50 -07002120 public void getPackageSizeInfoAsUser(String packageName, int userHandle,
Dianne Hackborn0c380492012-08-20 17:23:30 -07002121 IPackageStatsObserver observer) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002122 try {
Dianne Hackborn0c380492012-08-20 17:23:30 -07002123 mPM.getPackageSizeInfo(packageName, userHandle, observer);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002124 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002125 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002126 }
2127 }
Jeff Sharkeyd5896632016-03-04 16:16:00 -07002128
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002129 @Override
2130 public void addPackageToPreferred(String packageName) {
Jeff Sharkeyd5896632016-03-04 16:16:00 -07002131 Log.w(TAG, "addPackageToPreferred() is a no-op");
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002132 }
2133
2134 @Override
2135 public void removePackageFromPreferred(String packageName) {
Jeff Sharkeyd5896632016-03-04 16:16:00 -07002136 Log.w(TAG, "removePackageFromPreferred() is a no-op");
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002137 }
2138
2139 @Override
2140 public List<PackageInfo> getPreferredPackages(int flags) {
Jeff Sharkeyd5896632016-03-04 16:16:00 -07002141 Log.w(TAG, "getPreferredPackages() is a no-op");
2142 return Collections.emptyList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002143 }
2144
2145 @Override
2146 public void addPreferredActivity(IntentFilter filter,
2147 int match, ComponentName[] set, ComponentName activity) {
2148 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -07002149 mPM.addPreferredActivity(filter, match, set, activity, mContext.getUserId());
Amith Yamasania3f133a2012-08-09 17:11:28 -07002150 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002151 throw e.rethrowFromSystemServer();
Amith Yamasania3f133a2012-08-09 17:11:28 -07002152 }
2153 }
2154
2155 @Override
Jeff Sharkeye06b4d12016-01-06 14:51:50 -07002156 public void addPreferredActivityAsUser(IntentFilter filter, int match,
Amith Yamasania3f133a2012-08-09 17:11:28 -07002157 ComponentName[] set, ComponentName activity, int userId) {
2158 try {
2159 mPM.addPreferredActivity(filter, match, set, activity, userId);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002160 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002161 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002162 }
2163 }
2164
2165 @Override
2166 public void replacePreferredActivity(IntentFilter filter,
2167 int match, ComponentName[] set, ComponentName activity) {
2168 try {
Robin Lee0e27c872015-09-28 14:37:40 +01002169 mPM.replacePreferredActivity(filter, match, set, activity, mContext.getUserId());
Amith Yamasani41c1ded2014-08-05 11:15:05 -07002170 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002171 throw e.rethrowFromSystemServer();
Amith Yamasani41c1ded2014-08-05 11:15:05 -07002172 }
2173 }
2174
2175 @Override
2176 public void replacePreferredActivityAsUser(IntentFilter filter,
2177 int match, ComponentName[] set, ComponentName activity,
2178 int userId) {
2179 try {
2180 mPM.replacePreferredActivity(filter, match, set, activity, userId);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002181 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002182 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002183 }
2184 }
2185
2186 @Override
2187 public void clearPackagePreferredActivities(String packageName) {
2188 try {
2189 mPM.clearPackagePreferredActivities(packageName);
2190 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002191 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002192 }
2193 }
2194
2195 @Override
2196 public int getPreferredActivities(List<IntentFilter> outFilters,
2197 List<ComponentName> outActivities, String packageName) {
2198 try {
2199 return mPM.getPreferredActivities(outFilters, outActivities, packageName);
2200 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002201 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002202 }
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002203 }
2204
2205 @Override
Christopher Tatea2a0850d2013-09-05 16:38:58 -07002206 public ComponentName getHomeActivities(List<ResolveInfo> outActivities) {
2207 try {
2208 return mPM.getHomeActivities(outActivities);
2209 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002210 throw e.rethrowFromSystemServer();
Christopher Tatea2a0850d2013-09-05 16:38:58 -07002211 }
Christopher Tatea2a0850d2013-09-05 16:38:58 -07002212 }
2213
2214 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002215 public void setComponentEnabledSetting(ComponentName componentName,
2216 int newState, int flags) {
2217 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -07002218 mPM.setComponentEnabledSetting(componentName, newState, flags, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002219 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002220 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002221 }
2222 }
2223
2224 @Override
2225 public int getComponentEnabledSetting(ComponentName componentName) {
2226 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -07002227 return mPM.getComponentEnabledSetting(componentName, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002228 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002229 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002230 }
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002231 }
2232
2233 @Override
2234 public void setApplicationEnabledSetting(String packageName,
2235 int newState, int flags) {
2236 try {
Dianne Hackborn3fa3c28a2013-03-26 16:15:41 -07002237 mPM.setApplicationEnabledSetting(packageName, newState, flags,
Dianne Hackborn95d78532013-09-11 09:51:14 -07002238 mContext.getUserId(), mContext.getOpPackageName());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002239 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002240 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002241 }
2242 }
2243
2244 @Override
2245 public int getApplicationEnabledSetting(String packageName) {
2246 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -07002247 return mPM.getApplicationEnabledSetting(packageName, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002248 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002249 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002250 }
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002251 }
2252
Amith Yamasani655d0e22013-06-12 14:19:10 -07002253 @Override
Sudheer Shankabbb3ff22015-07-09 15:39:23 +01002254 public void flushPackageRestrictionsAsUser(int userId) {
2255 try {
2256 mPM.flushPackageRestrictionsAsUser(userId);
2257 } catch (RemoteException e) {
2258 throw e.rethrowFromSystemServer();
2259 }
2260 }
2261
2262 @Override
Amith Yamasanie5bcff62014-07-19 15:44:09 -07002263 public boolean setApplicationHiddenSettingAsUser(String packageName, boolean hidden,
Amith Yamasani655d0e22013-06-12 14:19:10 -07002264 UserHandle user) {
2265 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07002266 return mPM.setApplicationHiddenSettingAsUser(packageName, hidden,
Amith Yamasani655d0e22013-06-12 14:19:10 -07002267 user.getIdentifier());
Jeff Sharkey27b2e692016-02-25 17:40:12 -07002268 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002269 throw e.rethrowFromSystemServer();
Amith Yamasani655d0e22013-06-12 14:19:10 -07002270 }
Amith Yamasani655d0e22013-06-12 14:19:10 -07002271 }
2272
2273 @Override
Amith Yamasanie5bcff62014-07-19 15:44:09 -07002274 public boolean getApplicationHiddenSettingAsUser(String packageName, UserHandle user) {
Amith Yamasani655d0e22013-06-12 14:19:10 -07002275 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07002276 return mPM.getApplicationHiddenSettingAsUser(packageName, user.getIdentifier());
Jeff Sharkey27b2e692016-02-25 17:40:12 -07002277 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002278 throw e.rethrowFromSystemServer();
Amith Yamasani655d0e22013-06-12 14:19:10 -07002279 }
Amith Yamasani655d0e22013-06-12 14:19:10 -07002280 }
2281
dcashmanc6f22492014-08-14 09:54:51 -07002282 /** @hide */
dcashman9d2f4412014-06-09 09:27:54 -07002283 @Override
2284 public KeySet getKeySetByAlias(String packageName, String alias) {
2285 Preconditions.checkNotNull(packageName);
2286 Preconditions.checkNotNull(alias);
dcashman9d2f4412014-06-09 09:27:54 -07002287 try {
Jeff Sharkey27b2e692016-02-25 17:40:12 -07002288 return mPM.getKeySetByAlias(packageName, alias);
dcashman9d2f4412014-06-09 09:27:54 -07002289 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002290 throw e.rethrowFromSystemServer();
dcashman9d2f4412014-06-09 09:27:54 -07002291 }
dcashman9d2f4412014-06-09 09:27:54 -07002292 }
2293
dcashmanc6f22492014-08-14 09:54:51 -07002294 /** @hide */
dcashman9d2f4412014-06-09 09:27:54 -07002295 @Override
2296 public KeySet getSigningKeySet(String packageName) {
2297 Preconditions.checkNotNull(packageName);
dcashman9d2f4412014-06-09 09:27:54 -07002298 try {
Jeff Sharkey27b2e692016-02-25 17:40:12 -07002299 return mPM.getSigningKeySet(packageName);
dcashman9d2f4412014-06-09 09:27:54 -07002300 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002301 throw e.rethrowFromSystemServer();
dcashman9d2f4412014-06-09 09:27:54 -07002302 }
dcashman9d2f4412014-06-09 09:27:54 -07002303 }
2304
dcashmanc6f22492014-08-14 09:54:51 -07002305 /** @hide */
dcashman9d2f4412014-06-09 09:27:54 -07002306 @Override
2307 public boolean isSignedBy(String packageName, KeySet ks) {
2308 Preconditions.checkNotNull(packageName);
2309 Preconditions.checkNotNull(ks);
dcashman9d2f4412014-06-09 09:27:54 -07002310 try {
dcashmanc6f22492014-08-14 09:54:51 -07002311 return mPM.isPackageSignedByKeySet(packageName, ks);
dcashman9d2f4412014-06-09 09:27:54 -07002312 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002313 throw e.rethrowFromSystemServer();
dcashman9d2f4412014-06-09 09:27:54 -07002314 }
2315 }
2316
dcashmanc6f22492014-08-14 09:54:51 -07002317 /** @hide */
dcashman9d2f4412014-06-09 09:27:54 -07002318 @Override
2319 public boolean isSignedByExactly(String packageName, KeySet ks) {
2320 Preconditions.checkNotNull(packageName);
2321 Preconditions.checkNotNull(ks);
dcashman9d2f4412014-06-09 09:27:54 -07002322 try {
dcashmanc6f22492014-08-14 09:54:51 -07002323 return mPM.isPackageSignedByKeySetExactly(packageName, ks);
dcashman9d2f4412014-06-09 09:27:54 -07002324 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002325 throw e.rethrowFromSystemServer();
dcashman9d2f4412014-06-09 09:27:54 -07002326 }
2327 }
2328
Kenny Root0aaa0d92011-09-12 16:42:55 -07002329 /**
2330 * @hide
2331 */
2332 @Override
2333 public VerifierDeviceIdentity getVerifierDeviceIdentity() {
2334 try {
2335 return mPM.getVerifierDeviceIdentity();
2336 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002337 throw e.rethrowFromSystemServer();
Kenny Root0aaa0d92011-09-12 16:42:55 -07002338 }
Kenny Root0aaa0d92011-09-12 16:42:55 -07002339 }
2340
Jeff Hao9f60c082014-10-28 18:51:07 -07002341 /**
2342 * @hide
2343 */
2344 @Override
2345 public boolean isUpgrade() {
2346 try {
2347 return mPM.isUpgrade();
2348 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002349 throw e.rethrowFromSystemServer();
Jeff Hao9f60c082014-10-28 18:51:07 -07002350 }
2351 }
2352
Jeff Sharkey3a44f3f2014-04-28 17:36:31 -07002353 @Override
Jeff Sharkey16c8e3f2014-07-24 17:08:17 -07002354 public PackageInstaller getPackageInstaller() {
2355 synchronized (mLock) {
2356 if (mInstaller == null) {
2357 try {
Svet Ganov67882122016-12-11 16:36:34 -08002358 mInstaller = new PackageInstaller(mPM.getPackageInstaller(),
Jeff Sharkey16c8e3f2014-07-24 17:08:17 -07002359 mContext.getPackageName(), mContext.getUserId());
2360 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002361 throw e.rethrowFromSystemServer();
Jeff Sharkey16c8e3f2014-07-24 17:08:17 -07002362 }
2363 }
2364 return mInstaller;
Jeff Sharkey3a44f3f2014-04-28 17:36:31 -07002365 }
2366 }
2367
Jeff Sharkey6c833e02014-07-14 22:44:30 -07002368 @Override
2369 public boolean isPackageAvailable(String packageName) {
2370 try {
2371 return mPM.isPackageAvailable(packageName, mContext.getUserId());
2372 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002373 throw e.rethrowFromSystemServer();
Jeff Sharkey6c833e02014-07-14 22:44:30 -07002374 }
2375 }
2376
Nicolas Prevotc79586e2014-05-06 12:47:57 +01002377 /**
2378 * @hide
2379 */
2380 @Override
Nicolas Prevot63798c52014-05-27 13:22:38 +01002381 public void addCrossProfileIntentFilter(IntentFilter filter, int sourceUserId, int targetUserId,
2382 int flags) {
Nicolas Prevotc79586e2014-05-06 12:47:57 +01002383 try {
Nicolas Prevot3f7777f2014-07-24 15:58:39 +01002384 mPM.addCrossProfileIntentFilter(filter, mContext.getOpPackageName(),
Nicolas Prevot4b8d5822015-03-05 15:20:49 +00002385 sourceUserId, targetUserId, flags);
Nicolas Prevotc79586e2014-05-06 12:47:57 +01002386 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002387 throw e.rethrowFromSystemServer();
Nicolas Prevotc79586e2014-05-06 12:47:57 +01002388 }
2389 }
2390
2391 /**
2392 * @hide
2393 */
2394 @Override
Nicolas Prevot81948992014-05-16 18:25:26 +01002395 public void clearCrossProfileIntentFilters(int sourceUserId) {
Nicolas Prevotc79586e2014-05-06 12:47:57 +01002396 try {
Nicolas Prevot4b8d5822015-03-05 15:20:49 +00002397 mPM.clearCrossProfileIntentFilters(sourceUserId, mContext.getOpPackageName());
Nicolas Prevotc79586e2014-05-06 12:47:57 +01002398 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002399 throw e.rethrowFromSystemServer();
Nicolas Prevotc79586e2014-05-06 12:47:57 +01002400 }
2401 }
2402
Nicolas Prevot88cc3462014-05-14 14:51:48 +01002403 /**
2404 * @hide
2405 */
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +01002406 public Drawable loadItemIcon(PackageItemInfo itemInfo, ApplicationInfo appInfo) {
Benjamin Franzec2d48b2014-10-01 15:38:43 +01002407 Drawable dr = loadUnbadgedItemIcon(itemInfo, appInfo);
2408 if (itemInfo.showUserIcon != UserHandle.USER_NULL) {
2409 return dr;
2410 }
2411 return getUserBadgedIcon(dr, new UserHandle(mContext.getUserId()));
2412 }
2413
2414 /**
2415 * @hide
2416 */
2417 public Drawable loadUnbadgedItemIcon(PackageItemInfo itemInfo, ApplicationInfo appInfo) {
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +01002418 if (itemInfo.showUserIcon != UserHandle.USER_NULL) {
Alexandra Gherghina64d4dca2014-08-28 18:26:56 +01002419 Bitmap bitmap = getUserManager().getUserIcon(itemInfo.showUserIcon);
2420 if (bitmap == null) {
2421 return UserIcons.getDefaultUserIcon(itemInfo.showUserIcon, /* light= */ false);
2422 }
2423 return new BitmapDrawable(bitmap);
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +01002424 }
Alexandra Gherghinadb811db2014-08-29 13:43:59 +01002425 Drawable dr = null;
2426 if (itemInfo.packageName != null) {
2427 dr = getDrawable(itemInfo.packageName, itemInfo.icon, appInfo);
2428 }
Alexandra Gherghinaa71e3902014-07-25 20:03:47 +01002429 if (dr == null) {
Alexandra Gherghinaa7093142014-07-30 13:43:39 +01002430 dr = itemInfo.loadDefaultIcon(this);
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +01002431 }
Benjamin Franzec2d48b2014-10-01 15:38:43 +01002432 return dr;
Svetoslavc7d62f02014-09-04 15:39:54 -07002433 }
2434
2435 private Drawable getBadgedDrawable(Drawable drawable, Drawable badgeDrawable,
2436 Rect badgeLocation, boolean tryBadgeInPlace) {
2437 final int badgedWidth = drawable.getIntrinsicWidth();
2438 final int badgedHeight = drawable.getIntrinsicHeight();
2439 final boolean canBadgeInPlace = tryBadgeInPlace
2440 && (drawable instanceof BitmapDrawable)
2441 && ((BitmapDrawable) drawable).getBitmap().isMutable();
2442
2443 final Bitmap bitmap;
2444 if (canBadgeInPlace) {
2445 bitmap = ((BitmapDrawable) drawable).getBitmap();
2446 } else {
2447 bitmap = Bitmap.createBitmap(badgedWidth, badgedHeight, Bitmap.Config.ARGB_8888);
2448 }
2449 Canvas canvas = new Canvas(bitmap);
2450
2451 if (!canBadgeInPlace) {
2452 drawable.setBounds(0, 0, badgedWidth, badgedHeight);
2453 drawable.draw(canvas);
2454 }
2455
2456 if (badgeLocation != null) {
2457 if (badgeLocation.left < 0 || badgeLocation.top < 0
2458 || badgeLocation.width() > badgedWidth || badgeLocation.height() > badgedHeight) {
2459 throw new IllegalArgumentException("Badge location " + badgeLocation
2460 + " not in badged drawable bounds "
2461 + new Rect(0, 0, badgedWidth, badgedHeight));
2462 }
2463 badgeDrawable.setBounds(0, 0, badgeLocation.width(), badgeLocation.height());
2464
2465 canvas.save();
2466 canvas.translate(badgeLocation.left, badgeLocation.top);
2467 badgeDrawable.draw(canvas);
2468 canvas.restore();
2469 } else {
2470 badgeDrawable.setBounds(0, 0, badgedWidth, badgedHeight);
2471 badgeDrawable.draw(canvas);
2472 }
2473
2474 if (!canBadgeInPlace) {
2475 BitmapDrawable mergedDrawable = new BitmapDrawable(mContext.getResources(), bitmap);
2476
2477 if (drawable instanceof BitmapDrawable) {
2478 BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
2479 mergedDrawable.setTargetDensity(bitmapDrawable.getBitmap().getDensity());
2480 }
2481
2482 return mergedDrawable;
2483 }
2484
2485 return drawable;
2486 }
2487
Tony Mak8673b282016-03-21 21:10:59 +00002488 private boolean isManagedProfile(int userId) {
2489 return getUserManager().isManagedProfile(userId);
Nicolas Prevot88cc3462014-05-14 14:51:48 +01002490 }
2491
Bartosz Fabianowskia34f53f2017-01-11 18:08:47 +01002492 /**
2493 * @hide
2494 */
2495 @Override
2496 public int getInstallReason(String packageName, UserHandle user) {
2497 try {
2498 return mPM.getInstallReason(packageName, user.getIdentifier());
2499 } catch (RemoteException e) {
2500 throw e.rethrowFromSystemServer();
2501 }
2502 }
2503
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002504 /** {@hide} */
2505 private static class MoveCallbackDelegate extends IPackageMoveObserver.Stub implements
2506 Handler.Callback {
Jeff Sharkey50a05452015-04-29 11:24:52 -07002507 private static final int MSG_CREATED = 1;
2508 private static final int MSG_STATUS_CHANGED = 2;
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002509
2510 final MoveCallback mCallback;
2511 final Handler mHandler;
2512
2513 public MoveCallbackDelegate(MoveCallback callback, Looper looper) {
2514 mCallback = callback;
2515 mHandler = new Handler(looper, this);
2516 }
2517
2518 @Override
2519 public boolean handleMessage(Message msg) {
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002520 switch (msg.what) {
Jeff Sharkey50a05452015-04-29 11:24:52 -07002521 case MSG_CREATED: {
Jeff Sharkeyb36586a2015-04-27 08:42:28 -07002522 final SomeArgs args = (SomeArgs) msg.obj;
Jeff Sharkey50a05452015-04-29 11:24:52 -07002523 mCallback.onCreated(args.argi1, (Bundle) args.arg2);
Jeff Sharkeyb36586a2015-04-27 08:42:28 -07002524 args.recycle();
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002525 return true;
Jeff Sharkey50a05452015-04-29 11:24:52 -07002526 }
2527 case MSG_STATUS_CHANGED: {
2528 final SomeArgs args = (SomeArgs) msg.obj;
2529 mCallback.onStatusChanged(args.argi1, args.argi2, (long) args.arg3);
2530 args.recycle();
2531 return true;
2532 }
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002533 }
2534 return false;
2535 }
2536
2537 @Override
Jeff Sharkey50a05452015-04-29 11:24:52 -07002538 public void onCreated(int moveId, Bundle extras) {
Jeff Sharkeyb36586a2015-04-27 08:42:28 -07002539 final SomeArgs args = SomeArgs.obtain();
2540 args.argi1 = moveId;
Jeff Sharkey50a05452015-04-29 11:24:52 -07002541 args.arg2 = extras;
2542 mHandler.obtainMessage(MSG_CREATED, args).sendToTarget();
2543 }
2544
2545 @Override
2546 public void onStatusChanged(int moveId, int status, long estMillis) {
2547 final SomeArgs args = SomeArgs.obtain();
2548 args.argi1 = moveId;
2549 args.argi2 = status;
2550 args.arg3 = estMillis;
Jeff Sharkeyb36586a2015-04-27 08:42:28 -07002551 mHandler.obtainMessage(MSG_STATUS_CHANGED, args).sendToTarget();
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002552 }
2553 }
2554
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002555 private final ContextImpl mContext;
2556 private final IPackageManager mPM;
2557
2558 private static final Object sSync = new Object();
Dianne Hackbornadd005c2013-07-17 18:43:12 -07002559 private static ArrayMap<ResourceName, WeakReference<Drawable.ConstantState>> sIconCache
2560 = new ArrayMap<ResourceName, WeakReference<Drawable.ConstantState>>();
2561 private static ArrayMap<ResourceName, WeakReference<CharSequence>> sStringCache
2562 = new ArrayMap<ResourceName, WeakReference<CharSequence>>();
Svetoslavf7c06eb2015-06-10 18:43:22 -07002563
2564 private final Map<OnPermissionsChangedListener, IOnPermissionsChangeListener>
2565 mPermissionListeners = new ArrayMap<>();
2566
2567 public class OnPermissionsChangeListenerDelegate extends IOnPermissionsChangeListener.Stub
2568 implements Handler.Callback{
2569 private static final int MSG_PERMISSIONS_CHANGED = 1;
2570
2571 private final OnPermissionsChangedListener mListener;
2572 private final Handler mHandler;
2573
2574
2575 public OnPermissionsChangeListenerDelegate(OnPermissionsChangedListener listener,
2576 Looper looper) {
2577 mListener = listener;
2578 mHandler = new Handler(looper, this);
2579 }
2580
2581 @Override
2582 public void onPermissionsChanged(int uid) {
2583 mHandler.obtainMessage(MSG_PERMISSIONS_CHANGED, uid, 0).sendToTarget();
2584 }
2585
2586 @Override
2587 public boolean handleMessage(Message msg) {
2588 switch (msg.what) {
2589 case MSG_PERMISSIONS_CHANGED: {
2590 final int uid = msg.arg1;
2591 mListener.onPermissionsChanged(uid);
2592 return true;
2593 }
2594 }
2595 return false;
2596 }
2597 }
Suprabh Shuklaaef25132017-01-23 18:09:03 -08002598
2599 @Override
2600 public boolean canRequestPackageInstalls() {
2601 try {
2602 return mPM.canRequestPackageInstalls(mContext.getPackageName(), mContext.getUserId());
2603 } catch (RemoteException e) {
2604 throw e.rethrowAsRuntimeException();
2605 }
2606 }
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002607}