blob: 027ddf51a069c24db243c828617d135647f06c08 [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 Sharkeye6306c42017-03-07 21:03:18 -070068import android.os.Build;
Jeff Sharkey50a05452015-04-29 11:24:52 -070069import android.os.Bundle;
Jeff Sharkey620b32b2015-04-23 19:36:02 -070070import android.os.Handler;
71import android.os.Looper;
72import android.os.Message;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080073import android.os.Process;
74import android.os.RemoteException;
Jeff Sharkeyb2b9ab82015-04-05 21:10:42 -070075import android.os.SystemProperties;
Amith Yamasani67df64b2012-12-14 12:09:36 -080076import android.os.UserHandle;
Nicolas Prevot88cc3462014-05-14 14:51:48 +010077import android.os.UserManager;
Jeff Sharkeye2d45be2015-04-15 17:14:12 -070078import android.os.storage.StorageManager;
79import android.os.storage.VolumeInfo;
Todd Kennedyf39ca8f2015-08-07 14:15:07 -070080import android.provider.Settings;
Dianne Hackbornadd005c2013-07-17 18:43:12 -070081import android.util.ArrayMap;
Sunny Goyalbab30752017-04-12 15:36:42 -070082import android.util.IconDrawableFactory;
83import android.util.LauncherIcons;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080084import android.util.Log;
Jeff Browna492c3a2012-08-23 19:48:44 -070085import android.view.Display;
Jeff Sharkeyb2b9ab82015-04-05 21:10:42 -070086
87import dalvik.system.VMRuntime;
Jeff Sharkey16c8e3f2014-07-24 17:08:17 -070088
89import com.android.internal.annotations.GuardedBy;
Kenny Guy02c89902016-11-15 19:36:38 +000090import com.android.internal.annotations.VisibleForTesting;
Jeff Sharkeyb36586a2015-04-27 08:42:28 -070091import com.android.internal.os.SomeArgs;
dcashman9d2f4412014-06-09 09:27:54 -070092import com.android.internal.util.Preconditions;
Alexandra Gherghina64d4dca2014-08-28 18:26:56 +010093import com.android.internal.util.UserIcons;
Svet Ganov2acf0632015-11-24 19:10:59 -080094import libcore.util.EmptyArray;
Jeff Sharkey16c8e3f2014-07-24 17:08:17 -070095
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080096import java.lang.ref.WeakReference;
97import java.util.ArrayList;
Svet Ganov2acf0632015-11-24 19:10:59 -080098import java.util.Collections;
Jeff Sharkey620b32b2015-04-23 19:36:02 -070099import java.util.Iterator;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800100import java.util.List;
Svetoslavf7c06eb2015-06-10 18:43:22 -0700101import java.util.Map;
Jeff Sharkey620b32b2015-04-23 19:36:02 -0700102import java.util.Objects;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800103
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700104/** @hide */
105public class ApplicationPackageManager extends PackageManager {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800106 private static final String TAG = "ApplicationPackageManager";
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800107 private final static boolean DEBUG_ICONS = false;
108
Svet Ganov2acf0632015-11-24 19:10:59 -0800109 private static final int DEFAULT_EPHEMERAL_COOKIE_MAX_SIZE_BYTES = 16384; // 16KB
110
Adam Lesinskid00bb5e2014-10-07 12:14:45 -0700111 // Default flags to use with PackageManager when no flags are given.
112 private final static int sDefaultFlags = PackageManager.GET_SHARED_LIBRARY_FILES;
113
Jeff Sharkey16c8e3f2014-07-24 17:08:17 -0700114 private final Object mLock = new Object();
115
116 @GuardedBy("mLock")
117 private UserManager mUserManager;
118 @GuardedBy("mLock")
119 private PackageInstaller mInstaller;
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +0100120
Jeff Sharkey620b32b2015-04-23 19:36:02 -0700121 @GuardedBy("mDelegates")
122 private final ArrayList<MoveCallbackDelegate> mDelegates = new ArrayList<>();
123
Svet Ganovf1b7f202015-07-29 08:33:42 -0700124 @GuardedBy("mLock")
125 private String mPermissionsControllerPackageName;
126
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +0100127 UserManager getUserManager() {
Jeff Sharkey16c8e3f2014-07-24 17:08:17 -0700128 synchronized (mLock) {
129 if (mUserManager == null) {
130 mUserManager = UserManager.get(mContext);
131 }
132 return mUserManager;
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +0100133 }
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +0100134 }
135
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800136 @Override
137 public PackageInfo getPackageInfo(String packageName, int flags)
138 throws NameNotFoundException {
Nicolas Prevot9a80e532015-09-23 15:49:28 +0100139 return getPackageInfoAsUser(packageName, flags, mContext.getUserId());
140 }
141
142 @Override
Svet Ganov67882122016-12-11 16:36:34 -0800143 public PackageInfo getPackageInfo(VersionedPackage versionedPackage, int flags)
144 throws NameNotFoundException {
145 try {
146 PackageInfo pi = mPM.getPackageInfoVersioned(versionedPackage, flags,
147 mContext.getUserId());
148 if (pi != null) {
149 return pi;
150 }
151 } catch (RemoteException e) {
152 throw e.rethrowFromSystemServer();
153 }
154 throw new NameNotFoundException(versionedPackage.toString());
155 }
156
157 @Override
Nicolas Prevot9a80e532015-09-23 15:49:28 +0100158 public PackageInfo getPackageInfoAsUser(String packageName, int flags, int userId)
159 throws NameNotFoundException {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800160 try {
Nicolas Prevot9a80e532015-09-23 15:49:28 +0100161 PackageInfo pi = mPM.getPackageInfo(packageName, flags, userId);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800162 if (pi != null) {
163 return pi;
164 }
165 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700166 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800167 }
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800168 throw new NameNotFoundException(packageName);
169 }
170
171 @Override
172 public String[] currentToCanonicalPackageNames(String[] names) {
173 try {
174 return mPM.currentToCanonicalPackageNames(names);
175 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700176 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800177 }
178 }
179
180 @Override
181 public String[] canonicalToCurrentPackageNames(String[] names) {
182 try {
183 return mPM.canonicalToCurrentPackageNames(names);
184 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700185 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800186 }
187 }
188
189 @Override
190 public Intent getLaunchIntentForPackage(String packageName) {
191 // First see if the package has an INFO activity; the existence of
192 // such an activity is implied to be the desired front-door for the
193 // overall package (such as if it has multiple launcher entries).
194 Intent intentToResolve = new Intent(Intent.ACTION_MAIN);
195 intentToResolve.addCategory(Intent.CATEGORY_INFO);
196 intentToResolve.setPackage(packageName);
Dianne Hackborn19415762010-12-15 00:20:27 -0800197 List<ResolveInfo> ris = queryIntentActivities(intentToResolve, 0);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800198
199 // Otherwise, try to find a main launcher activity.
Dianne Hackborn19415762010-12-15 00:20:27 -0800200 if (ris == null || ris.size() <= 0) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800201 // reuse the intent instance
202 intentToResolve.removeCategory(Intent.CATEGORY_INFO);
203 intentToResolve.addCategory(Intent.CATEGORY_LAUNCHER);
204 intentToResolve.setPackage(packageName);
Dianne Hackborn19415762010-12-15 00:20:27 -0800205 ris = queryIntentActivities(intentToResolve, 0);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800206 }
Dianne Hackborn19415762010-12-15 00:20:27 -0800207 if (ris == null || ris.size() <= 0) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800208 return null;
209 }
210 Intent intent = new Intent(intentToResolve);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800211 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Dianne Hackborn19415762010-12-15 00:20:27 -0800212 intent.setClassName(ris.get(0).activityInfo.packageName,
213 ris.get(0).activityInfo.name);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800214 return intent;
215 }
216
217 @Override
Jose Lima970417c2014-04-10 10:42:19 -0700218 public Intent getLeanbackLaunchIntentForPackage(String packageName) {
219 // Try to find a main leanback_launcher activity.
220 Intent intentToResolve = new Intent(Intent.ACTION_MAIN);
221 intentToResolve.addCategory(Intent.CATEGORY_LEANBACK_LAUNCHER);
222 intentToResolve.setPackage(packageName);
223 List<ResolveInfo> ris = queryIntentActivities(intentToResolve, 0);
224
225 if (ris == null || ris.size() <= 0) {
226 return null;
227 }
228 Intent intent = new Intent(intentToResolve);
229 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
230 intent.setClassName(ris.get(0).activityInfo.packageName,
231 ris.get(0).activityInfo.name);
232 return intent;
233 }
234
235 @Override
Jeff Sharkey8588bc12016-01-06 16:47:42 -0700236 public int[] getPackageGids(String packageName) throws NameNotFoundException {
237 return getPackageGids(packageName, 0);
238 }
239
240 @Override
241 public int[] getPackageGids(String packageName, int flags)
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800242 throws NameNotFoundException {
243 try {
Jeff Sharkeycd654482016-01-08 17:42:11 -0700244 int[] gids = mPM.getPackageGids(packageName, flags, mContext.getUserId());
Svetoslavc6d1c342015-02-26 14:44:43 -0800245 if (gids != null) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800246 return gids;
247 }
248 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700249 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800250 }
251
252 throw new NameNotFoundException(packageName);
253 }
254
255 @Override
Jeff Sharkey8588bc12016-01-06 16:47:42 -0700256 public int getPackageUid(String packageName, int flags) throws NameNotFoundException {
257 return getPackageUidAsUser(packageName, flags, mContext.getUserId());
258 }
259
260 @Override
261 public int getPackageUidAsUser(String packageName, int userId) throws NameNotFoundException {
262 return getPackageUidAsUser(packageName, 0, userId);
263 }
264
265 @Override
266 public int getPackageUidAsUser(String packageName, int flags, int userId)
Dianne Hackborna06de0f2012-12-11 16:34:47 -0800267 throws NameNotFoundException {
268 try {
Jeff Sharkeycd654482016-01-08 17:42:11 -0700269 int uid = mPM.getPackageUid(packageName, flags, userId);
Dianne Hackborna06de0f2012-12-11 16:34:47 -0800270 if (uid >= 0) {
271 return uid;
272 }
273 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700274 throw e.rethrowFromSystemServer();
Dianne Hackborna06de0f2012-12-11 16:34:47 -0800275 }
276
277 throw new NameNotFoundException(packageName);
278 }
279
280 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800281 public PermissionInfo getPermissionInfo(String name, int flags)
282 throws NameNotFoundException {
283 try {
284 PermissionInfo pi = mPM.getPermissionInfo(name, flags);
285 if (pi != null) {
286 return pi;
287 }
288 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700289 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800290 }
291
292 throw new NameNotFoundException(name);
293 }
294
295 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700296 @SuppressWarnings("unchecked")
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800297 public List<PermissionInfo> queryPermissionsByGroup(String group, int flags)
298 throws NameNotFoundException {
299 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700300 ParceledListSlice<PermissionInfo> parceledList =
301 mPM.queryPermissionsByGroup(group, flags);
302 if (parceledList != null) {
303 List<PermissionInfo> pi = parceledList.getList();
304 if (pi != null) {
305 return pi;
306 }
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800307 }
308 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700309 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800310 }
311
312 throw new NameNotFoundException(group);
313 }
314
315 @Override
Paul Navin7b89a7b2017-01-26 23:56:08 +0000316 public boolean isPermissionReviewModeEnabled() {
317 return mContext.getResources().getBoolean(
318 com.android.internal.R.bool.config_permissionReviewRequired);
319 }
320
321 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800322 public PermissionGroupInfo getPermissionGroupInfo(String name,
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700323 int flags) throws NameNotFoundException {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800324 try {
325 PermissionGroupInfo pgi = mPM.getPermissionGroupInfo(name, flags);
326 if (pgi != null) {
327 return pgi;
328 }
329 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700330 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800331 }
332
333 throw new NameNotFoundException(name);
334 }
335
336 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700337 @SuppressWarnings("unchecked")
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800338 public List<PermissionGroupInfo> getAllPermissionGroups(int flags) {
339 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700340 ParceledListSlice<PermissionGroupInfo> parceledList =
341 mPM.getAllPermissionGroups(flags);
342 if (parceledList == null) {
343 return Collections.emptyList();
344 }
345 return parceledList.getList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800346 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700347 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800348 }
349 }
350
351 @Override
352 public ApplicationInfo getApplicationInfo(String packageName, int flags)
353 throws NameNotFoundException {
Jeff Sharkeycd654482016-01-08 17:42:11 -0700354 return getApplicationInfoAsUser(packageName, flags, mContext.getUserId());
355 }
356
357 @Override
358 public ApplicationInfo getApplicationInfoAsUser(String packageName, int flags, int userId)
359 throws NameNotFoundException {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800360 try {
Jeff Sharkeycd654482016-01-08 17:42:11 -0700361 ApplicationInfo ai = mPM.getApplicationInfo(packageName, flags, userId);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800362 if (ai != null) {
Narayan Kamathcaa71192014-07-16 11:06:43 +0100363 // This is a temporary hack. Callers must use
364 // createPackageContext(packageName).getApplicationInfo() to
365 // get the right paths.
Tao Baic9a02372016-01-12 15:02:24 -0800366 return maybeAdjustApplicationInfo(ai);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800367 }
368 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700369 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800370 }
371
372 throw new NameNotFoundException(packageName);
373 }
374
Tao Baic9a02372016-01-12 15:02:24 -0800375 private static ApplicationInfo maybeAdjustApplicationInfo(ApplicationInfo info) {
Narayan Kamathcaa71192014-07-16 11:06:43 +0100376 // If we're dealing with a multi-arch application that has both
377 // 32 and 64 bit shared libraries, we might need to choose the secondary
378 // depending on what the current runtime's instruction set is.
379 if (info.primaryCpuAbi != null && info.secondaryCpuAbi != null) {
380 final String runtimeIsa = VMRuntime.getRuntime().vmInstructionSet();
jgu214741cd92014-12-17 17:23:29 -0500381
382 // Get the instruction set that the libraries of secondary Abi is supported.
383 // In presence of a native bridge this might be different than the one secondary Abi used.
384 String secondaryIsa = VMRuntime.getInstructionSet(info.secondaryCpuAbi);
385 final String secondaryDexCodeIsa = SystemProperties.get("ro.dalvik.vm.isa." + secondaryIsa);
386 secondaryIsa = secondaryDexCodeIsa.isEmpty() ? secondaryIsa : secondaryDexCodeIsa;
Narayan Kamathcaa71192014-07-16 11:06:43 +0100387
388 // If the runtimeIsa is the same as the primary isa, then we do nothing.
389 // Everything will be set up correctly because info.nativeLibraryDir will
390 // correspond to the right ISA.
391 if (runtimeIsa.equals(secondaryIsa)) {
Tao Baic9a02372016-01-12 15:02:24 -0800392 ApplicationInfo modified = new ApplicationInfo(info);
393 modified.nativeLibraryDir = info.secondaryNativeLibraryDir;
394 return modified;
Narayan Kamathcaa71192014-07-16 11:06:43 +0100395 }
396 }
Tao Baic9a02372016-01-12 15:02:24 -0800397 return info;
Narayan Kamathcaa71192014-07-16 11:06:43 +0100398 }
399
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800400 @Override
401 public ActivityInfo getActivityInfo(ComponentName className, int flags)
402 throws NameNotFoundException {
403 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700404 ActivityInfo ai = mPM.getActivityInfo(className, flags, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800405 if (ai != null) {
406 return ai;
407 }
408 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700409 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800410 }
411
412 throw new NameNotFoundException(className.toString());
413 }
414
415 @Override
416 public ActivityInfo getReceiverInfo(ComponentName className, int flags)
417 throws NameNotFoundException {
418 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700419 ActivityInfo ai = mPM.getReceiverInfo(className, flags, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800420 if (ai != null) {
421 return ai;
422 }
423 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700424 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800425 }
426
427 throw new NameNotFoundException(className.toString());
428 }
429
430 @Override
431 public ServiceInfo getServiceInfo(ComponentName className, int flags)
432 throws NameNotFoundException {
433 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700434 ServiceInfo si = mPM.getServiceInfo(className, flags, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800435 if (si != null) {
436 return si;
437 }
438 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700439 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800440 }
441
442 throw new NameNotFoundException(className.toString());
443 }
444
445 @Override
446 public ProviderInfo getProviderInfo(ComponentName className, int flags)
447 throws NameNotFoundException {
448 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700449 ProviderInfo pi = mPM.getProviderInfo(className, flags, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800450 if (pi != null) {
451 return pi;
452 }
453 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700454 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800455 }
456
457 throw new NameNotFoundException(className.toString());
458 }
459
460 @Override
461 public String[] getSystemSharedLibraryNames() {
462 try {
463 return mPM.getSystemSharedLibraryNames();
464 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700465 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800466 }
467 }
468
Svet Ganovd7b1f4112016-02-09 18:49:23 -0800469 /** @hide */
470 @Override
Svet Ganov67882122016-12-11 16:36:34 -0800471 public @NonNull List<SharedLibraryInfo> getSharedLibraries(int flags) {
472 return getSharedLibrariesAsUser(flags, mContext.getUserId());
473 }
474
475 /** @hide */
476 @Override
477 @SuppressWarnings("unchecked")
478 public @NonNull List<SharedLibraryInfo> getSharedLibrariesAsUser(int flags, int userId) {
479 try {
480 ParceledListSlice<SharedLibraryInfo> sharedLibs = mPM.getSharedLibraries(
481 flags, userId);
482 if (sharedLibs == null) {
483 return Collections.emptyList();
484 }
485 return sharedLibs.getList();
486 } catch (RemoteException e) {
487 throw e.rethrowFromSystemServer();
488 }
489 }
490
491 /** @hide */
492 @Override
Svetoslav Ganova9c25002016-04-13 19:25:56 -0700493 public @NonNull String getServicesSystemSharedLibraryPackageName() {
Svet Ganovd7b1f4112016-02-09 18:49:23 -0800494 try {
495 return mPM.getServicesSystemSharedLibraryPackageName();
496 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700497 throw e.rethrowFromSystemServer();
Svet Ganovd7b1f4112016-02-09 18:49:23 -0800498 }
499 }
500
Svetoslav Ganova9c25002016-04-13 19:25:56 -0700501 /**
502 * @hide
503 */
504 public @NonNull String getSharedSystemSharedLibraryPackageName() {
505 try {
506 return mPM.getSharedSystemSharedLibraryPackageName();
507 } catch (RemoteException e) {
508 throw e.rethrowFromSystemServer();
509 }
510 }
511
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800512 @Override
Todd Kennedy9106c642017-02-08 14:16:53 -0800513 public ChangedPackages getChangedPackages(int sequenceNumber) {
514 try {
515 return mPM.getChangedPackages(sequenceNumber, mContext.getUserId());
516 } catch (RemoteException e) {
517 throw e.rethrowFromSystemServer();
518 }
519 }
520
521 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700522 @SuppressWarnings("unchecked")
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800523 public FeatureInfo[] getSystemAvailableFeatures() {
524 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700525 ParceledListSlice<FeatureInfo> parceledList =
526 mPM.getSystemAvailableFeatures();
527 if (parceledList == null) {
528 return new FeatureInfo[0];
529 }
530 final List<FeatureInfo> list = parceledList.getList();
Jeff Sharkeyd5896632016-03-04 16:16:00 -0700531 final FeatureInfo[] res = new FeatureInfo[list.size()];
532 for (int i = 0; i < res.length; i++) {
533 res[i] = list.get(i);
534 }
535 return res;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800536 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700537 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800538 }
539 }
540
541 @Override
542 public boolean hasSystemFeature(String name) {
Jeff Sharkey115d2c12016-02-15 17:25:57 -0700543 return hasSystemFeature(name, 0);
544 }
545
546 @Override
547 public boolean hasSystemFeature(String name, int version) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800548 try {
Jeff Sharkey115d2c12016-02-15 17:25:57 -0700549 return mPM.hasSystemFeature(name, version);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800550 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700551 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800552 }
553 }
554
555 @Override
556 public int checkPermission(String permName, String pkgName) {
557 try {
Svetoslavc6d1c342015-02-26 14:44:43 -0800558 return mPM.checkPermission(permName, pkgName, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800559 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700560 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800561 }
562 }
563
564 @Override
Svet Ganovad3b2972015-07-07 22:49:17 -0700565 public boolean isPermissionRevokedByPolicy(String permName, String pkgName) {
566 try {
567 return mPM.isPermissionRevokedByPolicy(permName, pkgName, mContext.getUserId());
568 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700569 throw e.rethrowFromSystemServer();
Svet Ganovad3b2972015-07-07 22:49:17 -0700570 }
571 }
572
Svet Ganovf1b7f202015-07-29 08:33:42 -0700573 /**
574 * @hide
575 */
576 @Override
577 public String getPermissionControllerPackageName() {
578 synchronized (mLock) {
579 if (mPermissionsControllerPackageName == null) {
580 try {
581 mPermissionsControllerPackageName = mPM.getPermissionControllerPackageName();
582 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700583 throw e.rethrowFromSystemServer();
Svet Ganovf1b7f202015-07-29 08:33:42 -0700584 }
585 }
586 return mPermissionsControllerPackageName;
587 }
588 }
589
Svet Ganovad3b2972015-07-07 22:49:17 -0700590 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800591 public boolean addPermission(PermissionInfo info) {
592 try {
593 return mPM.addPermission(info);
594 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700595 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800596 }
597 }
598
599 @Override
600 public boolean addPermissionAsync(PermissionInfo info) {
601 try {
602 return mPM.addPermissionAsync(info);
603 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700604 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800605 }
606 }
607
608 @Override
609 public void removePermission(String name) {
610 try {
611 mPM.removePermission(name);
612 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700613 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800614 }
615 }
616
617 @Override
Svet Ganov8c7f7002015-05-07 10:48:44 -0700618 public void grantRuntimePermission(String packageName, String permissionName,
619 UserHandle user) {
Dianne Hackborne639da72012-02-21 15:11:13 -0800620 try {
Svet Ganov8c7f7002015-05-07 10:48:44 -0700621 mPM.grantRuntimePermission(packageName, permissionName, user.getIdentifier());
Dianne Hackborne639da72012-02-21 15:11:13 -0800622 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700623 throw e.rethrowFromSystemServer();
Dianne Hackborne639da72012-02-21 15:11:13 -0800624 }
625 }
626
627 @Override
Svet Ganov8c7f7002015-05-07 10:48:44 -0700628 public void revokeRuntimePermission(String packageName, String permissionName,
629 UserHandle user) {
Dianne Hackborne639da72012-02-21 15:11:13 -0800630 try {
Svet Ganov8c7f7002015-05-07 10:48:44 -0700631 mPM.revokeRuntimePermission(packageName, permissionName, user.getIdentifier());
632 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700633 throw e.rethrowFromSystemServer();
Svet Ganov8c7f7002015-05-07 10:48:44 -0700634 }
635 }
636
637 @Override
638 public int getPermissionFlags(String permissionName, String packageName, UserHandle user) {
639 try {
640 return mPM.getPermissionFlags(permissionName, packageName, user.getIdentifier());
641 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700642 throw e.rethrowFromSystemServer();
Svet Ganov8c7f7002015-05-07 10:48:44 -0700643 }
644 }
645
646 @Override
647 public void updatePermissionFlags(String permissionName, String packageName,
648 int flagMask, int flagValues, UserHandle user) {
649 try {
650 mPM.updatePermissionFlags(permissionName, packageName, flagMask,
651 flagValues, user.getIdentifier());
Dianne Hackborne639da72012-02-21 15:11:13 -0800652 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700653 throw e.rethrowFromSystemServer();
Dianne Hackborne639da72012-02-21 15:11:13 -0800654 }
655 }
656
657 @Override
Svetoslav20770dd2015-05-29 15:43:04 -0700658 public boolean shouldShowRequestPermissionRationale(String permission) {
659 try {
660 return mPM.shouldShowRequestPermissionRationale(permission,
661 mContext.getPackageName(), mContext.getUserId());
662 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700663 throw e.rethrowFromSystemServer();
Svetoslav20770dd2015-05-29 15:43:04 -0700664 }
665 }
666
667 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800668 public int checkSignatures(String pkg1, String pkg2) {
669 try {
670 return mPM.checkSignatures(pkg1, pkg2);
671 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700672 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800673 }
674 }
675
676 @Override
677 public int checkSignatures(int uid1, int uid2) {
678 try {
679 return mPM.checkUidSignatures(uid1, uid2);
680 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700681 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800682 }
683 }
684
685 @Override
686 public String[] getPackagesForUid(int uid) {
687 try {
688 return mPM.getPackagesForUid(uid);
689 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700690 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800691 }
692 }
693
694 @Override
695 public String getNameForUid(int uid) {
696 try {
697 return mPM.getNameForUid(uid);
698 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700699 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800700 }
701 }
702
703 @Override
704 public int getUidForSharedUser(String sharedUserName)
705 throws NameNotFoundException {
706 try {
707 int uid = mPM.getUidForSharedUser(sharedUserName);
708 if(uid != -1) {
709 return uid;
710 }
711 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700712 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800713 }
714 throw new NameNotFoundException("No shared userid for user:"+sharedUserName);
715 }
716
Kenny Roote6cd0c72011-05-19 12:48:14 -0700717 @SuppressWarnings("unchecked")
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800718 @Override
719 public List<PackageInfo> getInstalledPackages(int flags) {
Jeff Sharkeye06b4d12016-01-06 14:51:50 -0700720 return getInstalledPackagesAsUser(flags, mContext.getUserId());
Amith Yamasani151ec4c2012-09-07 19:25:16 -0700721 }
722
723 /** @hide */
724 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700725 @SuppressWarnings("unchecked")
Jeff Sharkeye06b4d12016-01-06 14:51:50 -0700726 public List<PackageInfo> getInstalledPackagesAsUser(int flags, int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800727 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700728 ParceledListSlice<PackageInfo> parceledList =
729 mPM.getInstalledPackages(flags, userId);
730 if (parceledList == null) {
731 return Collections.emptyList();
732 }
733 return parceledList.getList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800734 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700735 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800736 }
737 }
738
Kenny Roote6cd0c72011-05-19 12:48:14 -0700739 @SuppressWarnings("unchecked")
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800740 @Override
Dianne Hackborne7991752013-01-16 17:56:46 -0800741 public List<PackageInfo> getPackagesHoldingPermissions(
742 String[] permissions, int flags) {
743 final int userId = mContext.getUserId();
744 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700745 ParceledListSlice<PackageInfo> parceledList =
746 mPM.getPackagesHoldingPermissions(permissions, flags, userId);
747 if (parceledList == null) {
748 return Collections.emptyList();
749 }
750 return parceledList.getList();
Dianne Hackborne7991752013-01-16 17:56:46 -0800751 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700752 throw e.rethrowFromSystemServer();
Dianne Hackborne7991752013-01-16 17:56:46 -0800753 }
754 }
755
756 @SuppressWarnings("unchecked")
757 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800758 public List<ApplicationInfo> getInstalledApplications(int flags) {
Bartosz Fabianowski11334242016-11-17 20:49:16 +0100759 return getInstalledApplicationsAsUser(flags, mContext.getUserId());
760 }
761
762 /** @hide */
763 @SuppressWarnings("unchecked")
764 @Override
765 public List<ApplicationInfo> getInstalledApplicationsAsUser(int flags, int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800766 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700767 ParceledListSlice<ApplicationInfo> parceledList =
768 mPM.getInstalledApplications(flags, userId);
769 if (parceledList == null) {
770 return Collections.emptyList();
771 }
772 return parceledList.getList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800773 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700774 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800775 }
776 }
777
Svet Ganov2acf0632015-11-24 19:10:59 -0800778 /** @hide */
779 @SuppressWarnings("unchecked")
780 @Override
Svetoslav Ganov096d3042017-01-30 16:34:13 -0800781 public List<InstantAppInfo> getInstantApps() {
Svet Ganov2acf0632015-11-24 19:10:59 -0800782 try {
Svetoslav Ganov096d3042017-01-30 16:34:13 -0800783 ParceledListSlice<InstantAppInfo> slice =
784 mPM.getInstantApps(mContext.getUserId());
Svet Ganov2acf0632015-11-24 19:10:59 -0800785 if (slice != null) {
786 return slice.getList();
787 }
788 return Collections.emptyList();
789 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700790 throw e.rethrowFromSystemServer();
Svet Ganov2acf0632015-11-24 19:10:59 -0800791 }
792 }
793
794 /** @hide */
795 @Override
Svetoslav Ganov096d3042017-01-30 16:34:13 -0800796 public Drawable getInstantAppIcon(String packageName) {
Svet Ganov2acf0632015-11-24 19:10:59 -0800797 try {
Svetoslav Ganov096d3042017-01-30 16:34:13 -0800798 Bitmap bitmap = mPM.getInstantAppIcon(
Svet Ganov2acf0632015-11-24 19:10:59 -0800799 packageName, mContext.getUserId());
800 if (bitmap != null) {
801 return new BitmapDrawable(null, bitmap);
802 }
803 return null;
804 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700805 throw e.rethrowFromSystemServer();
Svet Ganov2acf0632015-11-24 19:10:59 -0800806 }
807 }
808
809 @Override
Svetoslav Ganov096d3042017-01-30 16:34:13 -0800810 public boolean isInstantApp() {
David Christie31a16552017-03-01 15:08:45 -0800811 return isInstantApp(mContext.getPackageName());
812 }
813
814 @Override
815 public boolean isInstantApp(String packageName) {
Svet Ganov2acf0632015-11-24 19:10:59 -0800816 try {
David Christie31a16552017-03-01 15:08:45 -0800817 return mPM.isInstantApp(packageName, mContext.getUserId());
Svet Ganov2acf0632015-11-24 19:10:59 -0800818 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700819 throw e.rethrowFromSystemServer();
Svet Ganov2acf0632015-11-24 19:10:59 -0800820 }
Svet Ganov2acf0632015-11-24 19:10:59 -0800821 }
822
823 @Override
Svetoslav Ganov096d3042017-01-30 16:34:13 -0800824 public int getInstantAppCookieMaxSize() {
Svet Ganov2acf0632015-11-24 19:10:59 -0800825 return Settings.Global.getInt(mContext.getContentResolver(),
826 Settings.Global.EPHEMERAL_COOKIE_MAX_SIZE_BYTES,
827 DEFAULT_EPHEMERAL_COOKIE_MAX_SIZE_BYTES);
828 }
829
830 @Override
Svetoslav Ganov096d3042017-01-30 16:34:13 -0800831 public @NonNull byte[] getInstantAppCookie() {
Svet Ganov2acf0632015-11-24 19:10:59 -0800832 try {
Svetoslav Ganov096d3042017-01-30 16:34:13 -0800833 final byte[] cookie = mPM.getInstantAppCookie(
Svet Ganov2acf0632015-11-24 19:10:59 -0800834 mContext.getPackageName(), mContext.getUserId());
835 if (cookie != null) {
836 return cookie;
Jeff Sharkey27b2e692016-02-25 17:40:12 -0700837 } else {
838 return EmptyArray.BYTE;
Svet Ganov2acf0632015-11-24 19:10:59 -0800839 }
840 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700841 throw e.rethrowFromSystemServer();
Svet Ganov2acf0632015-11-24 19:10:59 -0800842 }
Svet Ganov2acf0632015-11-24 19:10:59 -0800843 }
844
845 @Override
Svetoslav Ganov096d3042017-01-30 16:34:13 -0800846 public boolean setInstantAppCookie(@NonNull byte[] cookie) {
Svet Ganov2acf0632015-11-24 19:10:59 -0800847 try {
Svetoslav Ganov096d3042017-01-30 16:34:13 -0800848 return mPM.setInstantAppCookie(mContext.getPackageName(),
849 cookie, mContext.getUserId());
Svet Ganov2acf0632015-11-24 19:10:59 -0800850 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700851 throw e.rethrowFromSystemServer();
Svet Ganov2acf0632015-11-24 19:10:59 -0800852 }
Svet Ganov2acf0632015-11-24 19:10:59 -0800853 }
854
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800855 @Override
856 public ResolveInfo resolveActivity(Intent intent, int flags) {
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700857 return resolveActivityAsUser(intent, flags, mContext.getUserId());
Svetoslav Ganov58d37b52012-09-18 12:04:19 -0700858 }
859
860 @Override
861 public ResolveInfo resolveActivityAsUser(Intent intent, int flags, int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800862 try {
863 return mPM.resolveIntent(
864 intent,
865 intent.resolveTypeIfNeeded(mContext.getContentResolver()),
Svetoslav Ganov58d37b52012-09-18 12:04:19 -0700866 flags,
867 userId);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800868 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700869 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800870 }
871 }
872
873 @Override
874 public List<ResolveInfo> queryIntentActivities(Intent intent,
875 int flags) {
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700876 return queryIntentActivitiesAsUser(intent, flags, mContext.getUserId());
Amith Yamasani151ec4c2012-09-07 19:25:16 -0700877 }
878
879 /** @hide Same as above but for a specific user */
880 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700881 @SuppressWarnings("unchecked")
Svetoslav Ganov58d37b52012-09-18 12:04:19 -0700882 public List<ResolveInfo> queryIntentActivitiesAsUser(Intent intent,
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700883 int flags, int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800884 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700885 ParceledListSlice<ResolveInfo> parceledList =
886 mPM.queryIntentActivities(intent,
887 intent.resolveTypeIfNeeded(mContext.getContentResolver()),
888 flags, userId);
889 if (parceledList == null) {
890 return Collections.emptyList();
891 }
892 return parceledList.getList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800893 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700894 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800895 }
896 }
897
898 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700899 @SuppressWarnings("unchecked")
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800900 public List<ResolveInfo> queryIntentActivityOptions(
901 ComponentName caller, Intent[] specifics, Intent intent,
902 int flags) {
903 final ContentResolver resolver = mContext.getContentResolver();
904
905 String[] specificTypes = null;
906 if (specifics != null) {
907 final int N = specifics.length;
908 for (int i=0; i<N; i++) {
909 Intent sp = specifics[i];
910 if (sp != null) {
911 String t = sp.resolveTypeIfNeeded(resolver);
912 if (t != null) {
913 if (specificTypes == null) {
914 specificTypes = new String[N];
915 }
916 specificTypes[i] = t;
917 }
918 }
919 }
920 }
921
922 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700923 ParceledListSlice<ResolveInfo> parceledList =
924 mPM.queryIntentActivityOptions(caller, specifics, specificTypes, intent,
925 intent.resolveTypeIfNeeded(resolver), flags, mContext.getUserId());
926 if (parceledList == null) {
927 return Collections.emptyList();
928 }
929 return parceledList.getList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800930 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700931 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800932 }
933 }
934
Amith Yamasanif203aee2012-08-29 18:41:53 -0700935 /**
936 * @hide
937 */
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800938 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700939 @SuppressWarnings("unchecked")
Jeff Sharkeye06b4d12016-01-06 14:51:50 -0700940 public List<ResolveInfo> queryBroadcastReceiversAsUser(Intent intent, int flags, int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800941 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700942 ParceledListSlice<ResolveInfo> parceledList =
943 mPM.queryIntentReceivers(intent,
944 intent.resolveTypeIfNeeded(mContext.getContentResolver()),
945 flags, userId);
946 if (parceledList == null) {
947 return Collections.emptyList();
948 }
949 return parceledList.getList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800950 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700951 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800952 }
953 }
954
955 @Override
Amith Yamasanif203aee2012-08-29 18:41:53 -0700956 public List<ResolveInfo> queryBroadcastReceivers(Intent intent, int flags) {
Jeff Sharkeye06b4d12016-01-06 14:51:50 -0700957 return queryBroadcastReceiversAsUser(intent, flags, mContext.getUserId());
Amith Yamasanif203aee2012-08-29 18:41:53 -0700958 }
959
960 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800961 public ResolveInfo resolveService(Intent intent, int flags) {
962 try {
963 return mPM.resolveService(
964 intent,
965 intent.resolveTypeIfNeeded(mContext.getContentResolver()),
Amith Yamasani483f3b02012-03-13 16:08:00 -0700966 flags,
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700967 mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800968 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700969 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800970 }
971 }
972
973 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700974 @SuppressWarnings("unchecked")
Svetoslav Ganov58d37b52012-09-18 12:04:19 -0700975 public List<ResolveInfo> queryIntentServicesAsUser(Intent intent, int flags, int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800976 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700977 ParceledListSlice<ResolveInfo> parceledList =
978 mPM.queryIntentServices(intent,
979 intent.resolveTypeIfNeeded(mContext.getContentResolver()),
980 flags, userId);
981 if (parceledList == null) {
982 return Collections.emptyList();
983 }
984 return parceledList.getList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800985 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700986 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800987 }
988 }
989
990 @Override
Svetoslav Ganov58d37b52012-09-18 12:04:19 -0700991 public List<ResolveInfo> queryIntentServices(Intent intent, int flags) {
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700992 return queryIntentServicesAsUser(intent, flags, mContext.getUserId());
Svetoslav Ganov58d37b52012-09-18 12:04:19 -0700993 }
994
995 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700996 @SuppressWarnings("unchecked")
Jeff Sharkey85f5f812013-10-07 10:16:12 -0700997 public List<ResolveInfo> queryIntentContentProvidersAsUser(
998 Intent intent, int flags, int userId) {
999 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001000 ParceledListSlice<ResolveInfo> parceledList =
1001 mPM.queryIntentContentProviders(intent,
1002 intent.resolveTypeIfNeeded(mContext.getContentResolver()),
1003 flags, userId);
1004 if (parceledList == null) {
1005 return Collections.emptyList();
1006 }
1007 return parceledList.getList();
Jeff Sharkey85f5f812013-10-07 10:16:12 -07001008 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001009 throw e.rethrowFromSystemServer();
Jeff Sharkey85f5f812013-10-07 10:16:12 -07001010 }
1011 }
1012
1013 @Override
1014 public List<ResolveInfo> queryIntentContentProviders(Intent intent, int flags) {
1015 return queryIntentContentProvidersAsUser(intent, flags, mContext.getUserId());
1016 }
1017
1018 @Override
Alexandra Gherghina0363c3e2014-06-23 13:34:59 +01001019 public ProviderInfo resolveContentProvider(String name, int flags) {
1020 return resolveContentProviderAsUser(name, flags, mContext.getUserId());
1021 }
1022
1023 /** @hide **/
1024 @Override
1025 public ProviderInfo resolveContentProviderAsUser(String name, int flags, int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001026 try {
Alexandra Gherghina0363c3e2014-06-23 13:34:59 +01001027 return mPM.resolveContentProvider(name, flags, userId);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001028 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001029 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001030 }
1031 }
1032
1033 @Override
1034 public List<ProviderInfo> queryContentProviders(String processName,
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001035 int uid, int flags) {
Makoto Onuki32757292017-02-22 14:36:59 -08001036 return queryContentProviders(processName, uid, flags, null);
1037 }
1038
1039 @Override
1040 @SuppressWarnings("unchecked")
1041 public List<ProviderInfo> queryContentProviders(String processName,
1042 int uid, int flags, String metaDataKey) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001043 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001044 ParceledListSlice<ProviderInfo> slice =
Makoto Onuki32757292017-02-22 14:36:59 -08001045 mPM.queryContentProviders(processName, uid, flags, metaDataKey);
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001046 return slice != null ? slice.getList() : Collections.<ProviderInfo>emptyList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001047 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001048 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001049 }
1050 }
1051
1052 @Override
1053 public InstrumentationInfo getInstrumentationInfo(
1054 ComponentName className, int flags)
1055 throws NameNotFoundException {
1056 try {
1057 InstrumentationInfo ii = mPM.getInstrumentationInfo(
1058 className, flags);
1059 if (ii != null) {
1060 return ii;
1061 }
1062 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001063 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001064 }
1065
1066 throw new NameNotFoundException(className.toString());
1067 }
1068
1069 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001070 @SuppressWarnings("unchecked")
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001071 public List<InstrumentationInfo> queryInstrumentation(
1072 String targetPackage, int flags) {
1073 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001074 ParceledListSlice<InstrumentationInfo> parceledList =
1075 mPM.queryInstrumentation(targetPackage, flags);
1076 if (parceledList == null) {
1077 return Collections.emptyList();
1078 }
1079 return parceledList.getList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001080 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001081 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001082 }
1083 }
1084
Alan Viveretteecd585a2015-04-13 10:32:51 -07001085 @Nullable
1086 @Override
1087 public Drawable getDrawable(String packageName, @DrawableRes int resId,
1088 @Nullable ApplicationInfo appInfo) {
1089 final ResourceName name = new ResourceName(packageName, resId);
1090 final Drawable cachedIcon = getCachedIcon(name);
1091 if (cachedIcon != null) {
1092 return cachedIcon;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001093 }
Alan Viveretteecd585a2015-04-13 10:32:51 -07001094
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001095 if (appInfo == null) {
1096 try {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001097 appInfo = getApplicationInfo(packageName, sDefaultFlags);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001098 } catch (NameNotFoundException e) {
1099 return null;
1100 }
1101 }
Alan Viveretteecd585a2015-04-13 10:32:51 -07001102
1103 if (resId != 0) {
1104 try {
1105 final Resources r = getResourcesForApplication(appInfo);
1106 final Drawable dr = r.getDrawable(resId, null);
1107 if (dr != null) {
1108 putCachedIcon(name, dr);
1109 }
1110
1111 if (false) {
1112 RuntimeException e = new RuntimeException("here");
1113 e.fillInStackTrace();
1114 Log.w(TAG, "Getting drawable 0x" + Integer.toHexString(resId)
1115 + " from package " + packageName
1116 + ": app scale=" + r.getCompatibilityInfo().applicationScale
1117 + ", caller scale=" + mContext.getResources()
1118 .getCompatibilityInfo().applicationScale,
1119 e);
1120 }
Ricky Wai3ce46252015-04-15 16:12:22 +01001121 if (DEBUG_ICONS) {
Alan Viveretteecd585a2015-04-13 10:32:51 -07001122 Log.v(TAG, "Getting drawable 0x"
1123 + Integer.toHexString(resId) + " from " + r
1124 + ": " + dr);
Ricky Wai3ce46252015-04-15 16:12:22 +01001125 }
1126 return dr;
Alan Viveretteecd585a2015-04-13 10:32:51 -07001127 } catch (NameNotFoundException e) {
1128 Log.w("PackageManager", "Failure retrieving resources for "
1129 + appInfo.packageName);
1130 } catch (Resources.NotFoundException e) {
1131 Log.w("PackageManager", "Failure retrieving resources for "
1132 + appInfo.packageName + ": " + e.getMessage());
1133 } catch (Exception e) {
1134 // If an exception was thrown, fall through to return
1135 // default icon.
1136 Log.w("PackageManager", "Failure retrieving icon 0x"
1137 + Integer.toHexString(resId) + " in package "
1138 + packageName, e);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001139 }
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001140 }
Alan Viveretteecd585a2015-04-13 10:32:51 -07001141
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001142 return null;
1143 }
1144
1145 @Override public Drawable getActivityIcon(ComponentName activityName)
1146 throws NameNotFoundException {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001147 return getActivityInfo(activityName, sDefaultFlags).loadIcon(this);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001148 }
1149
1150 @Override public Drawable getActivityIcon(Intent intent)
1151 throws NameNotFoundException {
1152 if (intent.getComponent() != null) {
1153 return getActivityIcon(intent.getComponent());
1154 }
1155
1156 ResolveInfo info = resolveActivity(
1157 intent, PackageManager.MATCH_DEFAULT_ONLY);
1158 if (info != null) {
1159 return info.activityInfo.loadIcon(this);
1160 }
1161
Romain Guy39fe17c2011-11-30 10:34:07 -08001162 throw new NameNotFoundException(intent.toUri(0));
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001163 }
1164
1165 @Override public Drawable getDefaultActivityIcon() {
1166 return Resources.getSystem().getDrawable(
1167 com.android.internal.R.drawable.sym_def_app_icon);
1168 }
1169
1170 @Override public Drawable getApplicationIcon(ApplicationInfo info) {
1171 return info.loadIcon(this);
1172 }
1173
1174 @Override public Drawable getApplicationIcon(String packageName)
1175 throws NameNotFoundException {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001176 return getApplicationIcon(getApplicationInfo(packageName, sDefaultFlags));
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001177 }
1178
1179 @Override
Jose Limaf78e3122014-03-06 12:13:15 -08001180 public Drawable getActivityBanner(ComponentName activityName)
1181 throws NameNotFoundException {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001182 return getActivityInfo(activityName, sDefaultFlags).loadBanner(this);
Jose Limaf78e3122014-03-06 12:13:15 -08001183 }
1184
1185 @Override
1186 public Drawable getActivityBanner(Intent intent)
1187 throws NameNotFoundException {
1188 if (intent.getComponent() != null) {
1189 return getActivityBanner(intent.getComponent());
1190 }
1191
1192 ResolveInfo info = resolveActivity(
1193 intent, PackageManager.MATCH_DEFAULT_ONLY);
1194 if (info != null) {
1195 return info.activityInfo.loadBanner(this);
1196 }
1197
1198 throw new NameNotFoundException(intent.toUri(0));
1199 }
1200
1201 @Override
1202 public Drawable getApplicationBanner(ApplicationInfo info) {
1203 return info.loadBanner(this);
1204 }
1205
1206 @Override
1207 public Drawable getApplicationBanner(String packageName)
1208 throws NameNotFoundException {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001209 return getApplicationBanner(getApplicationInfo(packageName, sDefaultFlags));
Jose Limaf78e3122014-03-06 12:13:15 -08001210 }
1211
1212 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001213 public Drawable getActivityLogo(ComponentName activityName)
1214 throws NameNotFoundException {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001215 return getActivityInfo(activityName, sDefaultFlags).loadLogo(this);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001216 }
1217
1218 @Override
1219 public Drawable getActivityLogo(Intent intent)
1220 throws NameNotFoundException {
1221 if (intent.getComponent() != null) {
1222 return getActivityLogo(intent.getComponent());
1223 }
1224
1225 ResolveInfo info = resolveActivity(
1226 intent, PackageManager.MATCH_DEFAULT_ONLY);
1227 if (info != null) {
1228 return info.activityInfo.loadLogo(this);
1229 }
1230
1231 throw new NameNotFoundException(intent.toUri(0));
1232 }
1233
1234 @Override
1235 public Drawable getApplicationLogo(ApplicationInfo info) {
1236 return info.loadLogo(this);
1237 }
1238
1239 @Override
1240 public Drawable getApplicationLogo(String packageName)
1241 throws NameNotFoundException {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001242 return getApplicationLogo(getApplicationInfo(packageName, sDefaultFlags));
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001243 }
1244
Svetoslavc7d62f02014-09-04 15:39:54 -07001245 @Override
1246 public Drawable getUserBadgedIcon(Drawable icon, UserHandle user) {
Kenny Guy02c89902016-11-15 19:36:38 +00001247 if (!isManagedProfile(user.getIdentifier())) {
Svetoslavc7d62f02014-09-04 15:39:54 -07001248 return icon;
1249 }
Sunny Goyalbab30752017-04-12 15:36:42 -07001250 Drawable badge = new LauncherIcons(mContext).getBadgeDrawable(
1251 com.android.internal.R.drawable.ic_corp_icon_badge_case,
1252 getUserBadgeColor(user));
Kenny Guy02c89902016-11-15 19:36:38 +00001253 return getBadgedDrawable(icon, badge, null, true);
Svetoslavc7d62f02014-09-04 15:39:54 -07001254 }
1255
1256 @Override
1257 public Drawable getUserBadgedDrawableForDensity(Drawable drawable, UserHandle user,
1258 Rect badgeLocation, int badgeDensity) {
1259 Drawable badgeDrawable = getUserBadgeForDensity(user, badgeDensity);
1260 if (badgeDrawable == null) {
1261 return drawable;
1262 }
1263 return getBadgedDrawable(drawable, badgeDrawable, badgeLocation, true);
1264 }
1265
Kenny Guy02c89902016-11-15 19:36:38 +00001266 @VisibleForTesting
1267 public static final int[] CORP_BADGE_LABEL_RES_ID = new int[] {
1268 com.android.internal.R.string.managed_profile_label_badge,
1269 com.android.internal.R.string.managed_profile_label_badge_2,
1270 com.android.internal.R.string.managed_profile_label_badge_3
1271 };
1272
1273 private int getUserBadgeColor(UserHandle user) {
Sunny Goyalbab30752017-04-12 15:36:42 -07001274 return IconDrawableFactory.getUserBadgeColor(getUserManager(), user.getIdentifier());
Kenny Guy02c89902016-11-15 19:36:38 +00001275 }
1276
Svetoslavc7d62f02014-09-04 15:39:54 -07001277 @Override
1278 public Drawable getUserBadgeForDensity(UserHandle user, int density) {
Kenny Guy02c89902016-11-15 19:36:38 +00001279 Drawable badgeColor = getManagedProfileIconForDensity(user,
1280 com.android.internal.R.drawable.ic_corp_badge_color, density);
1281 if (badgeColor == null) {
1282 return null;
1283 }
1284 badgeColor.setTint(getUserBadgeColor(user));
1285 Drawable badgeForeground = getDrawableForDensity(
1286 com.android.internal.R.drawable.ic_corp_badge_case, density);
1287 Drawable badge = new LayerDrawable(
1288 new Drawable[] {badgeColor, badgeForeground });
1289 return badge;
Selim Cineke6ff9462016-01-15 15:07:06 -08001290 }
1291
1292 @Override
1293 public Drawable getUserBadgeForDensityNoBackground(UserHandle user, int density) {
Kenny Guy02c89902016-11-15 19:36:38 +00001294 Drawable badge = getManagedProfileIconForDensity(user,
Vadim Tryshev66ae66a2016-02-18 15:41:21 -08001295 com.android.internal.R.drawable.ic_corp_badge_no_background, density);
Kenny Guy02c89902016-11-15 19:36:38 +00001296 if (badge != null) {
1297 badge.setTint(getUserBadgeColor(user));
1298 }
1299 return badge;
Selim Cineke6ff9462016-01-15 15:07:06 -08001300 }
1301
Vadim Tryshev66ae66a2016-02-18 15:41:21 -08001302 private Drawable getDrawableForDensity(int drawableId, int density) {
1303 if (density <= 0) {
1304 density = mContext.getResources().getDisplayMetrics().densityDpi;
1305 }
1306 return Resources.getSystem().getDrawableForDensity(drawableId, density);
1307 }
1308
1309 private Drawable getManagedProfileIconForDensity(UserHandle user, int drawableId, int density) {
Tony Mak8673b282016-03-21 21:10:59 +00001310 if (isManagedProfile(user.getIdentifier())) {
Vadim Tryshev66ae66a2016-02-18 15:41:21 -08001311 return getDrawableForDensity(drawableId, density);
Svetoslavc7d62f02014-09-04 15:39:54 -07001312 }
1313 return null;
1314 }
1315
1316 @Override
1317 public CharSequence getUserBadgedLabel(CharSequence label, UserHandle user) {
Tony Mak8673b282016-03-21 21:10:59 +00001318 if (isManagedProfile(user.getIdentifier())) {
Kenny Guy02c89902016-11-15 19:36:38 +00001319 int badge = getUserManager().getManagedProfileBadge(user.getIdentifier());
1320 int resourceId = CORP_BADGE_LABEL_RES_ID[badge % CORP_BADGE_LABEL_RES_ID.length];
1321 return Resources.getSystem().getString(resourceId, label);
Svetoslavc7d62f02014-09-04 15:39:54 -07001322 }
1323 return label;
1324 }
1325
Alan Viveretteecd585a2015-04-13 10:32:51 -07001326 @Override
1327 public Resources getResourcesForActivity(ComponentName activityName)
1328 throws NameNotFoundException {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001329 return getResourcesForApplication(
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001330 getActivityInfo(activityName, sDefaultFlags).applicationInfo);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001331 }
1332
Alan Viveretteecd585a2015-04-13 10:32:51 -07001333 @Override
1334 public Resources getResourcesForApplication(@NonNull ApplicationInfo app)
1335 throws NameNotFoundException {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001336 if (app.packageName.equals("system")) {
Adam Lesinskia82b6262017-03-21 16:56:17 -07001337 return mContext.mMainThread.getSystemUiContext().getResources();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001338 }
Jeff Sharkey8a4c9722014-06-16 13:48:42 -07001339 final boolean sameUid = (app.uid == Process.myUid());
Adam Lesinski53fafdf2016-08-03 13:36:39 -07001340 final Resources r = mContext.mMainThread.getTopLevelResources(
Adam Lesinskic82f28a2016-06-08 17:19:09 -07001341 sameUid ? app.sourceDir : app.publicSourceDir,
1342 sameUid ? app.splitSourceDirs : app.splitPublicSourceDirs,
1343 app.resourceDirs, app.sharedLibraryFiles, Display.DEFAULT_DISPLAY,
1344 mContext.mPackageInfo);
Adam Lesinski53fafdf2016-08-03 13:36:39 -07001345 if (r != null) {
1346 return r;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001347 }
Adam Lesinski53fafdf2016-08-03 13:36:39 -07001348 throw new NameNotFoundException("Unable to open " + app.publicSourceDir);
1349
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001350 }
1351
Alan Viveretteecd585a2015-04-13 10:32:51 -07001352 @Override
1353 public Resources getResourcesForApplication(String appPackageName)
1354 throws NameNotFoundException {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001355 return getResourcesForApplication(
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001356 getApplicationInfo(appPackageName, sDefaultFlags));
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001357 }
1358
Amith Yamasani98edc952012-09-25 14:09:27 -07001359 /** @hide */
1360 @Override
1361 public Resources getResourcesForApplicationAsUser(String appPackageName, int userId)
1362 throws NameNotFoundException {
Jeff Sharkeyded653b2012-09-27 19:09:24 -07001363 if (userId < 0) {
1364 throw new IllegalArgumentException(
1365 "Call does not support special user #" + userId);
1366 }
1367 if ("system".equals(appPackageName)) {
Adam Lesinskia82b6262017-03-21 16:56:17 -07001368 return mContext.mMainThread.getSystemUiContext().getResources();
Jeff Sharkeyded653b2012-09-27 19:09:24 -07001369 }
Amith Yamasani98edc952012-09-25 14:09:27 -07001370 try {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001371 ApplicationInfo ai = mPM.getApplicationInfo(appPackageName, sDefaultFlags, userId);
Amith Yamasani98edc952012-09-25 14:09:27 -07001372 if (ai != null) {
1373 return getResourcesForApplication(ai);
1374 }
1375 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001376 throw e.rethrowFromSystemServer();
Amith Yamasani98edc952012-09-25 14:09:27 -07001377 }
1378 throw new NameNotFoundException("Package " + appPackageName + " doesn't exist");
1379 }
1380
Jeff Sharkeycd654482016-01-08 17:42:11 -07001381 volatile int mCachedSafeMode = -1;
1382
1383 @Override
1384 public boolean isSafeMode() {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001385 try {
1386 if (mCachedSafeMode < 0) {
1387 mCachedSafeMode = mPM.isSafeMode() ? 1 : 0;
1388 }
1389 return mCachedSafeMode != 0;
1390 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001391 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001392 }
1393 }
1394
Svetoslavf7c06eb2015-06-10 18:43:22 -07001395 @Override
1396 public void addOnPermissionsChangeListener(OnPermissionsChangedListener listener) {
1397 synchronized (mPermissionListeners) {
1398 if (mPermissionListeners.get(listener) != null) {
1399 return;
1400 }
1401 OnPermissionsChangeListenerDelegate delegate =
1402 new OnPermissionsChangeListenerDelegate(listener, Looper.getMainLooper());
1403 try {
1404 mPM.addOnPermissionsChangeListener(delegate);
1405 mPermissionListeners.put(listener, delegate);
1406 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001407 throw e.rethrowFromSystemServer();
Svetoslavf7c06eb2015-06-10 18:43:22 -07001408 }
1409 }
1410 }
1411
1412 @Override
1413 public void removeOnPermissionsChangeListener(OnPermissionsChangedListener listener) {
1414 synchronized (mPermissionListeners) {
1415 IOnPermissionsChangeListener delegate = mPermissionListeners.get(listener);
1416 if (delegate != null) {
1417 try {
1418 mPM.removeOnPermissionsChangeListener(delegate);
1419 mPermissionListeners.remove(listener);
1420 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001421 throw e.rethrowFromSystemServer();
Svetoslavf7c06eb2015-06-10 18:43:22 -07001422 }
1423 }
1424 }
1425 }
1426
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001427 static void configurationChanged() {
1428 synchronized (sSync) {
1429 sIconCache.clear();
1430 sStringCache.clear();
1431 }
1432 }
1433
Yao Chen022b8ea2016-12-16 11:03:28 -08001434 protected ApplicationPackageManager(ContextImpl context,
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001435 IPackageManager pm) {
1436 mContext = context;
1437 mPM = pm;
1438 }
1439
Alan Viveretteecd585a2015-04-13 10:32:51 -07001440 @Nullable
1441 private Drawable getCachedIcon(@NonNull ResourceName name) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001442 synchronized (sSync) {
Alan Viveretteecd585a2015-04-13 10:32:51 -07001443 final WeakReference<Drawable.ConstantState> wr = sIconCache.get(name);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001444 if (DEBUG_ICONS) Log.v(TAG, "Get cached weak drawable ref for "
1445 + name + ": " + wr);
1446 if (wr != null) { // we have the activity
Alan Viveretteecd585a2015-04-13 10:32:51 -07001447 final Drawable.ConstantState state = wr.get();
Romain Guy39fe17c2011-11-30 10:34:07 -08001448 if (state != null) {
1449 if (DEBUG_ICONS) {
1450 Log.v(TAG, "Get cached drawable state for " + name + ": " + state);
1451 }
1452 // Note: It's okay here to not use the newDrawable(Resources) variant
1453 // of the API. The ConstantState comes from a drawable that was
1454 // originally created by passing the proper app Resources instance
1455 // which means the state should already contain the proper
1456 // resources specific information (like density.) See
1457 // BitmapDrawable.BitmapState for instance.
1458 return state.newDrawable();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001459 }
1460 // our entry has been purged
1461 sIconCache.remove(name);
1462 }
1463 }
1464 return null;
1465 }
1466
Alan Viveretteecd585a2015-04-13 10:32:51 -07001467 private void putCachedIcon(@NonNull ResourceName name, @NonNull Drawable dr) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001468 synchronized (sSync) {
Alan Viveretteecd585a2015-04-13 10:32:51 -07001469 sIconCache.put(name, new WeakReference<>(dr.getConstantState()));
Romain Guy39fe17c2011-11-30 10:34:07 -08001470 if (DEBUG_ICONS) Log.v(TAG, "Added cached drawable state for " + name + ": " + dr);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001471 }
1472 }
1473
Romain Guy39fe17c2011-11-30 10:34:07 -08001474 static void handlePackageBroadcast(int cmd, String[] pkgList, boolean hasPkgInfo) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001475 boolean immediateGc = false;
Sudheer Shankacc6418f2016-10-13 12:03:44 -07001476 if (cmd == ApplicationThreadConstants.EXTERNAL_STORAGE_UNAVAILABLE) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001477 immediateGc = true;
1478 }
1479 if (pkgList != null && (pkgList.length > 0)) {
1480 boolean needCleanup = false;
1481 for (String ssp : pkgList) {
1482 synchronized (sSync) {
Dianne Hackbornadd005c2013-07-17 18:43:12 -07001483 for (int i=sIconCache.size()-1; i>=0; i--) {
1484 ResourceName nm = sIconCache.keyAt(i);
1485 if (nm.packageName.equals(ssp)) {
1486 //Log.i(TAG, "Removing cached drawable for " + nm);
1487 sIconCache.removeAt(i);
1488 needCleanup = true;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001489 }
1490 }
Dianne Hackbornadd005c2013-07-17 18:43:12 -07001491 for (int i=sStringCache.size()-1; i>=0; i--) {
1492 ResourceName nm = sStringCache.keyAt(i);
1493 if (nm.packageName.equals(ssp)) {
1494 //Log.i(TAG, "Removing cached string for " + nm);
1495 sStringCache.removeAt(i);
1496 needCleanup = true;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001497 }
1498 }
1499 }
1500 }
1501 if (needCleanup || hasPkgInfo) {
1502 if (immediateGc) {
1503 // Schedule an immediate gc.
1504 Runtime.getRuntime().gc();
1505 } else {
1506 ActivityThread.currentActivityThread().scheduleGcIdler();
1507 }
1508 }
1509 }
1510 }
1511
1512 private static final class ResourceName {
1513 final String packageName;
1514 final int iconId;
1515
1516 ResourceName(String _packageName, int _iconId) {
1517 packageName = _packageName;
1518 iconId = _iconId;
1519 }
1520
1521 ResourceName(ApplicationInfo aInfo, int _iconId) {
1522 this(aInfo.packageName, _iconId);
1523 }
1524
1525 ResourceName(ComponentInfo cInfo, int _iconId) {
1526 this(cInfo.applicationInfo.packageName, _iconId);
1527 }
1528
1529 ResourceName(ResolveInfo rInfo, int _iconId) {
1530 this(rInfo.activityInfo.applicationInfo.packageName, _iconId);
1531 }
1532
1533 @Override
1534 public boolean equals(Object o) {
1535 if (this == o) return true;
1536 if (o == null || getClass() != o.getClass()) return false;
1537
1538 ResourceName that = (ResourceName) o;
1539
1540 if (iconId != that.iconId) return false;
1541 return !(packageName != null ?
1542 !packageName.equals(that.packageName) : that.packageName != null);
1543
1544 }
1545
1546 @Override
1547 public int hashCode() {
1548 int result;
1549 result = packageName.hashCode();
1550 result = 31 * result + iconId;
1551 return result;
1552 }
1553
1554 @Override
1555 public String toString() {
1556 return "{ResourceName " + packageName + " / " + iconId + "}";
1557 }
1558 }
1559
1560 private CharSequence getCachedString(ResourceName name) {
1561 synchronized (sSync) {
1562 WeakReference<CharSequence> wr = sStringCache.get(name);
1563 if (wr != null) { // we have the activity
1564 CharSequence cs = wr.get();
1565 if (cs != null) {
1566 return cs;
1567 }
1568 // our entry has been purged
1569 sStringCache.remove(name);
1570 }
1571 }
1572 return null;
1573 }
1574
1575 private void putCachedString(ResourceName name, CharSequence cs) {
1576 synchronized (sSync) {
1577 sStringCache.put(name, new WeakReference<CharSequence>(cs));
1578 }
1579 }
1580
1581 @Override
Tor Norbye7b9c9122013-05-30 16:48:33 -07001582 public CharSequence getText(String packageName, @StringRes int resid,
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001583 ApplicationInfo appInfo) {
1584 ResourceName name = new ResourceName(packageName, resid);
1585 CharSequence text = getCachedString(name);
1586 if (text != null) {
1587 return text;
1588 }
1589 if (appInfo == null) {
1590 try {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001591 appInfo = getApplicationInfo(packageName, sDefaultFlags);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001592 } catch (NameNotFoundException e) {
1593 return null;
1594 }
1595 }
1596 try {
1597 Resources r = getResourcesForApplication(appInfo);
1598 text = r.getText(resid);
1599 putCachedString(name, text);
1600 return text;
1601 } catch (NameNotFoundException e) {
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07001602 Log.w("PackageManager", "Failure retrieving resources for "
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001603 + appInfo.packageName);
1604 } catch (RuntimeException e) {
1605 // If an exception was thrown, fall through to return
1606 // default icon.
1607 Log.w("PackageManager", "Failure retrieving text 0x"
1608 + Integer.toHexString(resid) + " in package "
1609 + packageName, e);
1610 }
1611 return null;
1612 }
1613
1614 @Override
Tor Norbye7b9c9122013-05-30 16:48:33 -07001615 public XmlResourceParser getXml(String packageName, @XmlRes int resid,
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001616 ApplicationInfo appInfo) {
1617 if (appInfo == null) {
1618 try {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001619 appInfo = getApplicationInfo(packageName, sDefaultFlags);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001620 } catch (NameNotFoundException e) {
1621 return null;
1622 }
1623 }
1624 try {
1625 Resources r = getResourcesForApplication(appInfo);
1626 return r.getXml(resid);
1627 } catch (RuntimeException e) {
1628 // If an exception was thrown, fall through to return
1629 // default icon.
1630 Log.w("PackageManager", "Failure retrieving xml 0x"
1631 + Integer.toHexString(resid) + " in package "
1632 + packageName, e);
1633 } catch (NameNotFoundException e) {
Alon Albert3fa51e32010-11-11 09:24:04 -08001634 Log.w("PackageManager", "Failure retrieving resources for "
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001635 + appInfo.packageName);
1636 }
1637 return null;
1638 }
1639
1640 @Override
1641 public CharSequence getApplicationLabel(ApplicationInfo info) {
1642 return info.loadLabel(this);
1643 }
1644
1645 @Override
1646 public void installPackage(Uri packageURI, IPackageInstallObserver observer, int flags,
1647 String installerPackageName) {
Jeff Sharkey513a0742014-07-08 17:10:32 -07001648 installCommon(packageURI, new LegacyPackageInstallObserver(observer), flags,
Todd Kennedya6793232016-02-24 22:46:00 +00001649 installerPackageName, mContext.getUserId());
Christopher Tatef1977b42014-03-24 16:25:51 -07001650 }
1651
Christopher Tatef1977b42014-03-24 16:25:51 -07001652 @Override
1653 public void installPackage(Uri packageURI, PackageInstallObserver observer,
1654 int flags, String installerPackageName) {
Todd Kennedya6793232016-02-24 22:46:00 +00001655 installCommon(packageURI, observer, flags, installerPackageName, mContext.getUserId());
Jeff Sharkey513a0742014-07-08 17:10:32 -07001656 }
1657
1658 private void installCommon(Uri packageURI,
1659 PackageInstallObserver observer, int flags, String installerPackageName,
Nicolas Prevot9a80e532015-09-23 15:49:28 +01001660 int userId) {
Jeff Sharkey513a0742014-07-08 17:10:32 -07001661 if (!"file".equals(packageURI.getScheme())) {
1662 throw new UnsupportedOperationException("Only file:// URIs are supported");
1663 }
Jeff Sharkey513a0742014-07-08 17:10:32 -07001664
1665 final String originPath = packageURI.getPath();
Christopher Tatef1977b42014-03-24 16:25:51 -07001666 try {
Nicolas Prevot9a80e532015-09-23 15:49:28 +01001667 mPM.installPackageAsUser(originPath, observer.getBinder(), flags, installerPackageName,
Todd Kennedya6793232016-02-24 22:46:00 +00001668 userId);
Jeff Sharkey27b2e692016-02-25 17:40:12 -07001669 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001670 throw e.rethrowFromSystemServer();
rich cannings706e8ba2012-08-20 13:20:14 -07001671 }
1672 }
1673
1674 @Override
Nicolas Prevot9a80e532015-09-23 15:49:28 +01001675 public int installExistingPackage(String packageName) throws NameNotFoundException {
Robin Lee0e27c872015-09-28 14:37:40 +01001676 return installExistingPackageAsUser(packageName, mContext.getUserId());
Nicolas Prevot9a80e532015-09-23 15:49:28 +01001677 }
1678
1679 @Override
1680 public int installExistingPackageAsUser(String packageName, int userId)
Dianne Hackborn7767eac2012-08-23 18:25:40 -07001681 throws NameNotFoundException {
1682 try {
Todd Kennedybe0b8892017-02-15 14:13:52 -08001683 int res = mPM.installExistingPackageAsUser(packageName, userId, 0 /*installFlags*/,
Bartosz Fabianowskia34f53f2017-01-11 18:08:47 +01001684 PackageManager.INSTALL_REASON_UNKNOWN);
Dianne Hackborn7767eac2012-08-23 18:25:40 -07001685 if (res == INSTALL_FAILED_INVALID_URI) {
1686 throw new NameNotFoundException("Package " + packageName + " doesn't exist");
1687 }
1688 return res;
1689 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001690 throw e.rethrowFromSystemServer();
Dianne Hackborn7767eac2012-08-23 18:25:40 -07001691 }
1692 }
1693
1694 @Override
Kenny Root3a9b5fb2011-09-20 14:15:38 -07001695 public void verifyPendingInstall(int id, int response) {
Kenny Root5ab21572011-07-27 11:11:19 -07001696 try {
Kenny Root3a9b5fb2011-09-20 14:15:38 -07001697 mPM.verifyPendingInstall(id, response);
Kenny Root5ab21572011-07-27 11:11:19 -07001698 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001699 throw e.rethrowFromSystemServer();
Kenny Root5ab21572011-07-27 11:11:19 -07001700 }
1701 }
1702
1703 @Override
rich canningsd9ef3e52012-08-22 14:28:05 -07001704 public void extendVerificationTimeout(int id, int verificationCodeAtTimeout,
1705 long millisecondsToDelay) {
1706 try {
1707 mPM.extendVerificationTimeout(id, verificationCodeAtTimeout, millisecondsToDelay);
1708 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001709 throw e.rethrowFromSystemServer();
rich canningsd9ef3e52012-08-22 14:28:05 -07001710 }
1711 }
1712
1713 @Override
Todd Kennedydfa93ab2016-03-03 15:24:33 -08001714 public void verifyIntentFilter(int id, int verificationCode, List<String> failedDomains) {
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001715 try {
Todd Kennedydfa93ab2016-03-03 15:24:33 -08001716 mPM.verifyIntentFilter(id, verificationCode, failedDomains);
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001717 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001718 throw e.rethrowFromSystemServer();
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001719 }
1720 }
1721
1722 @Override
Jeff Sharkeye06b4d12016-01-06 14:51:50 -07001723 public int getIntentVerificationStatusAsUser(String packageName, int userId) {
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001724 try {
1725 return mPM.getIntentVerificationStatus(packageName, userId);
1726 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001727 throw e.rethrowFromSystemServer();
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001728 }
1729 }
1730
1731 @Override
Jeff Sharkeye06b4d12016-01-06 14:51:50 -07001732 public boolean updateIntentVerificationStatusAsUser(String packageName, int status, int userId) {
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001733 try {
1734 return mPM.updateIntentVerificationStatus(packageName, status, userId);
1735 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001736 throw e.rethrowFromSystemServer();
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001737 }
1738 }
1739
1740 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001741 @SuppressWarnings("unchecked")
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001742 public List<IntentFilterVerificationInfo> getIntentFilterVerifications(String packageName) {
1743 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001744 ParceledListSlice<IntentFilterVerificationInfo> parceledList =
1745 mPM.getIntentFilterVerifications(packageName);
1746 if (parceledList == null) {
1747 return Collections.emptyList();
1748 }
1749 return parceledList.getList();
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001750 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001751 throw e.rethrowFromSystemServer();
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001752 }
1753 }
1754
1755 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001756 @SuppressWarnings("unchecked")
Fabrice Di Meglio07885952015-04-06 19:41:28 -07001757 public List<IntentFilter> getAllIntentFilters(String packageName) {
1758 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001759 ParceledListSlice<IntentFilter> parceledList =
1760 mPM.getAllIntentFilters(packageName);
1761 if (parceledList == null) {
1762 return Collections.emptyList();
1763 }
1764 return parceledList.getList();
Fabrice Di Meglio07885952015-04-06 19:41:28 -07001765 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001766 throw e.rethrowFromSystemServer();
Fabrice Di Meglio07885952015-04-06 19:41:28 -07001767 }
1768 }
1769
1770 @Override
Jeff Sharkeye06b4d12016-01-06 14:51:50 -07001771 public String getDefaultBrowserPackageNameAsUser(int userId) {
Fabrice Di Meglio62271722015-04-10 17:24:02 -07001772 try {
1773 return mPM.getDefaultBrowserPackageName(userId);
1774 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001775 throw e.rethrowFromSystemServer();
Fabrice Di Meglio62271722015-04-10 17:24:02 -07001776 }
1777 }
1778
1779 @Override
Jeff Sharkeye06b4d12016-01-06 14:51:50 -07001780 public boolean setDefaultBrowserPackageNameAsUser(String packageName, int userId) {
Fabrice Di Meglio62271722015-04-10 17:24:02 -07001781 try {
1782 return mPM.setDefaultBrowserPackageName(packageName, userId);
1783 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001784 throw e.rethrowFromSystemServer();
Fabrice Di Meglio62271722015-04-10 17:24:02 -07001785 }
1786 }
1787
1788 @Override
Dianne Hackborn880119b2010-11-18 22:26:40 -08001789 public void setInstallerPackageName(String targetPackage,
1790 String installerPackageName) {
1791 try {
1792 mPM.setInstallerPackageName(targetPackage, installerPackageName);
1793 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001794 throw e.rethrowFromSystemServer();
Dianne Hackborn880119b2010-11-18 22:26:40 -08001795 }
1796 }
1797
1798 @Override
Todd Kennedyab532892017-03-08 14:19:49 -08001799 public void setUpdateAvailable(String packageName, boolean updateAvailable) {
1800 try {
1801 mPM.setUpdateAvailable(packageName, updateAvailable);
1802 } catch (RemoteException e) {
1803 throw e.rethrowFromSystemServer();
1804 }
1805 }
1806
1807 @Override
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001808 public String getInstallerPackageName(String packageName) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001809 try {
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001810 return mPM.getInstallerPackageName(packageName);
1811 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001812 throw e.rethrowFromSystemServer();
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001813 }
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001814 }
1815
1816 @Override
1817 public int getMoveStatus(int moveId) {
1818 try {
1819 return mPM.getMoveStatus(moveId);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001820 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001821 throw e.rethrowFromSystemServer();
Jeff Sharkeyb2b9ab82015-04-05 21:10:42 -07001822 }
1823 }
1824
1825 @Override
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001826 public void registerMoveCallback(MoveCallback callback, Handler handler) {
1827 synchronized (mDelegates) {
1828 final MoveCallbackDelegate delegate = new MoveCallbackDelegate(callback,
1829 handler.getLooper());
1830 try {
1831 mPM.registerMoveCallback(delegate);
1832 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001833 throw e.rethrowFromSystemServer();
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001834 }
1835 mDelegates.add(delegate);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001836 }
1837 }
1838
1839 @Override
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001840 public void unregisterMoveCallback(MoveCallback callback) {
1841 synchronized (mDelegates) {
1842 for (Iterator<MoveCallbackDelegate> i = mDelegates.iterator(); i.hasNext();) {
1843 final MoveCallbackDelegate delegate = i.next();
1844 if (delegate.mCallback == callback) {
1845 try {
1846 mPM.unregisterMoveCallback(delegate);
1847 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001848 throw e.rethrowFromSystemServer();
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001849 }
1850 i.remove();
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001851 }
1852 }
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001853 }
1854 }
1855
1856 @Override
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001857 public int movePackage(String packageName, VolumeInfo vol) {
1858 try {
1859 final String volumeUuid;
1860 if (VolumeInfo.ID_PRIVATE_INTERNAL.equals(vol.id)) {
1861 volumeUuid = StorageManager.UUID_PRIVATE_INTERNAL;
1862 } else if (vol.isPrimaryPhysical()) {
1863 volumeUuid = StorageManager.UUID_PRIMARY_PHYSICAL;
1864 } else {
1865 volumeUuid = Preconditions.checkNotNull(vol.fsUuid);
1866 }
1867
1868 return mPM.movePackage(packageName, volumeUuid);
1869 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001870 throw e.rethrowFromSystemServer();
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001871 }
1872 }
1873
1874 @Override
1875 public @Nullable VolumeInfo getPackageCurrentVolume(ApplicationInfo app) {
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001876 final StorageManager storage = mContext.getSystemService(StorageManager.class);
Yao Chen022b8ea2016-12-16 11:03:28 -08001877 return getPackageCurrentVolume(app, storage);
1878 }
1879
1880 @VisibleForTesting
1881 protected @Nullable VolumeInfo getPackageCurrentVolume(ApplicationInfo app,
1882 StorageManager storage) {
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001883 if (app.isInternal()) {
1884 return storage.findVolumeById(VolumeInfo.ID_PRIVATE_INTERNAL);
1885 } else if (app.isExternalAsec()) {
1886 return storage.getPrimaryPhysicalVolume();
1887 } else {
1888 return storage.findVolumeByUuid(app.volumeUuid);
1889 }
1890 }
1891
1892 @Override
1893 public @NonNull List<VolumeInfo> getPackageCandidateVolumes(ApplicationInfo app) {
Yao Chen022b8ea2016-12-16 11:03:28 -08001894 final StorageManager storageManager = mContext.getSystemService(StorageManager.class);
1895 return getPackageCandidateVolumes(app, storageManager, mPM);
1896 }
1897
1898 @VisibleForTesting
1899 protected @NonNull List<VolumeInfo> getPackageCandidateVolumes(ApplicationInfo app,
1900 StorageManager storageManager, IPackageManager pm) {
1901 final VolumeInfo currentVol = getPackageCurrentVolume(app, storageManager);
1902 final List<VolumeInfo> vols = storageManager.getVolumes();
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001903 final List<VolumeInfo> candidates = new ArrayList<>();
1904 for (VolumeInfo vol : vols) {
Yao Chen022b8ea2016-12-16 11:03:28 -08001905 if (Objects.equals(vol, currentVol)
1906 || isPackageCandidateVolume(mContext, app, vol, pm)) {
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001907 candidates.add(vol);
1908 }
1909 }
1910 return candidates;
1911 }
1912
Yao Chen022b8ea2016-12-16 11:03:28 -08001913 @VisibleForTesting
1914 protected boolean isForceAllowOnExternal(Context context) {
1915 return Settings.Global.getInt(
Todd Kennedyf39ca8f2015-08-07 14:15:07 -07001916 context.getContentResolver(), Settings.Global.FORCE_ALLOW_ON_EXTERNAL, 0) != 0;
Yao Chen022b8ea2016-12-16 11:03:28 -08001917 }
1918
1919 @VisibleForTesting
1920 protected boolean isAllow3rdPartyOnInternal(Context context) {
1921 return context.getResources().getBoolean(
1922 com.android.internal.R.bool.config_allow3rdPartyAppOnInternal);
1923 }
1924
1925 private boolean isPackageCandidateVolume(
1926 ContextImpl context, ApplicationInfo app, VolumeInfo vol, IPackageManager pm) {
1927 final boolean forceAllowOnExternal = isForceAllowOnExternal(context);
1928
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001929 if (VolumeInfo.ID_PRIVATE_INTERNAL.equals(vol.getId())) {
Yao Chen022b8ea2016-12-16 11:03:28 -08001930 return app.isSystemApp() || isAllow3rdPartyOnInternal(context);
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001931 }
1932
1933 // System apps and apps demanding internal storage can't be moved
1934 // anywhere else
Todd Kennedyf39ca8f2015-08-07 14:15:07 -07001935 if (app.isSystemApp()) {
1936 return false;
1937 }
1938 if (!forceAllowOnExternal
Dianne Hackborn30a4e6d2015-10-12 17:14:56 -07001939 && (app.installLocation == PackageInfo.INSTALL_LOCATION_INTERNAL_ONLY
1940 || app.installLocation == PackageInfo.INSTALL_LOCATION_UNSPECIFIED)) {
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001941 return false;
1942 }
1943
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001944 // Gotta be able to write there
1945 if (!vol.isMountedWritable()) {
1946 return false;
1947 }
1948
1949 // Moving into an ASEC on public primary is only option internal
1950 if (vol.isPrimaryPhysical()) {
1951 return app.isInternal();
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001952 }
1953
Makoto Onukif34db0a2016-02-17 11:17:15 -08001954 // Some apps can't be moved. (e.g. device admins)
1955 try {
Yao Chen022b8ea2016-12-16 11:03:28 -08001956 if (pm.isPackageDeviceAdminOnAnyUser(app.packageName)) {
Makoto Onukif34db0a2016-02-17 11:17:15 -08001957 return false;
1958 }
1959 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001960 throw e.rethrowFromSystemServer();
Makoto Onukif34db0a2016-02-17 11:17:15 -08001961 }
1962
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001963 // Otherwise we can move to any private volume
1964 return (vol.getType() == VolumeInfo.TYPE_PRIVATE);
1965 }
1966
1967 @Override
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001968 public int movePrimaryStorage(VolumeInfo vol) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001969 try {
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001970 final String volumeUuid;
1971 if (VolumeInfo.ID_PRIVATE_INTERNAL.equals(vol.id)) {
1972 volumeUuid = StorageManager.UUID_PRIVATE_INTERNAL;
1973 } else if (vol.isPrimaryPhysical()) {
1974 volumeUuid = StorageManager.UUID_PRIMARY_PHYSICAL;
1975 } else {
1976 volumeUuid = Preconditions.checkNotNull(vol.fsUuid);
1977 }
1978
1979 return mPM.movePrimaryStorage(volumeUuid);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001980 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001981 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001982 }
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001983 }
1984
Jeff Sharkey275e3e42015-04-24 16:10:32 -07001985 @Override
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001986 public @Nullable VolumeInfo getPrimaryStorageCurrentVolume() {
1987 final StorageManager storage = mContext.getSystemService(StorageManager.class);
1988 final String volumeUuid = storage.getPrimaryStorageUuid();
Jeff Sharkey50a05452015-04-29 11:24:52 -07001989 return storage.findVolumeByQualifiedUuid(volumeUuid);
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001990 }
1991
Jeff Sharkey275e3e42015-04-24 16:10:32 -07001992 @Override
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001993 public @NonNull List<VolumeInfo> getPrimaryStorageCandidateVolumes() {
1994 final StorageManager storage = mContext.getSystemService(StorageManager.class);
1995 final VolumeInfo currentVol = getPrimaryStorageCurrentVolume();
1996 final List<VolumeInfo> vols = storage.getVolumes();
1997 final List<VolumeInfo> candidates = new ArrayList<>();
Jeff Sharkeyfced5342015-05-10 14:53:34 -07001998 if (Objects.equals(StorageManager.UUID_PRIMARY_PHYSICAL,
1999 storage.getPrimaryStorageUuid()) && currentVol != null) {
2000 // TODO: support moving primary physical to emulated volume
2001 candidates.add(currentVol);
2002 } else {
2003 for (VolumeInfo vol : vols) {
2004 if (Objects.equals(vol, currentVol) || isPrimaryStorageCandidateVolume(vol)) {
2005 candidates.add(vol);
2006 }
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002007 }
2008 }
2009 return candidates;
2010 }
2011
2012 private static boolean isPrimaryStorageCandidateVolume(VolumeInfo vol) {
2013 // Private internal is always an option
2014 if (VolumeInfo.ID_PRIVATE_INTERNAL.equals(vol.getId())) {
2015 return true;
2016 }
2017
2018 // Gotta be able to write there
2019 if (!vol.isMountedWritable()) {
2020 return false;
2021 }
2022
Jeff Sharkeyfced5342015-05-10 14:53:34 -07002023 // We can move to any private volume
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002024 return (vol.getType() == VolumeInfo.TYPE_PRIVATE);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002025 }
2026
2027 @Override
2028 public void deletePackage(String packageName, IPackageDeleteObserver observer, int flags) {
Robin Lee0e27c872015-09-28 14:37:40 +01002029 deletePackageAsUser(packageName, observer, flags, mContext.getUserId());
Nicolas Prevot9a80e532015-09-23 15:49:28 +01002030 }
2031
2032 @Override
Svet Ganov67882122016-12-11 16:36:34 -08002033 public void deletePackageAsUser(String packageName, IPackageDeleteObserver observer,
2034 int flags, int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002035 try {
Svet Ganov67882122016-12-11 16:36:34 -08002036 mPM.deletePackageAsUser(packageName, PackageManager.VERSION_CODE_HIGHEST,
2037 observer, userId, flags);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002038 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002039 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002040 }
2041 }
Jeff Sharkeyfbd0e9f2014-08-06 16:34:34 -07002042
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002043 @Override
2044 public void clearApplicationUserData(String packageName,
2045 IPackageDataObserver observer) {
2046 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -07002047 mPM.clearApplicationUserData(packageName, observer, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002048 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002049 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002050 }
2051 }
2052 @Override
2053 public void deleteApplicationCacheFiles(String packageName,
2054 IPackageDataObserver observer) {
2055 try {
2056 mPM.deleteApplicationCacheFiles(packageName, observer);
2057 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002058 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002059 }
2060 }
Jeff Sharkey529f91f2015-04-18 20:23:13 -07002061
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002062 @Override
Suprabh Shukla78c9eb82016-04-12 15:51:35 -07002063 public void deleteApplicationCacheFilesAsUser(String packageName, int userId,
2064 IPackageDataObserver observer) {
2065 try {
2066 mPM.deleteApplicationCacheFilesAsUser(packageName, userId, observer);
2067 } catch (RemoteException e) {
2068 throw e.rethrowFromSystemServer();
2069 }
2070 }
2071
2072 @Override
Jeff Sharkey529f91f2015-04-18 20:23:13 -07002073 public void freeStorageAndNotify(String volumeUuid, long idealStorageSize,
2074 IPackageDataObserver observer) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002075 try {
Jeff Sharkey529f91f2015-04-18 20:23:13 -07002076 mPM.freeStorageAndNotify(volumeUuid, idealStorageSize, observer);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002077 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002078 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002079 }
2080 }
2081
2082 @Override
Jeff Sharkey529f91f2015-04-18 20:23:13 -07002083 public void freeStorage(String volumeUuid, long freeStorageSize, IntentSender pi) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002084 try {
Jeff Sharkey529f91f2015-04-18 20:23:13 -07002085 mPM.freeStorage(volumeUuid, freeStorageSize, pi);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002086 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002087 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002088 }
2089 }
2090
2091 @Override
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00002092 public String[] setPackagesSuspendedAsUser(String[] packageNames, boolean suspended,
2093 int userId) {
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00002094 try {
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00002095 return mPM.setPackagesSuspendedAsUser(packageNames, suspended, userId);
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00002096 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002097 throw e.rethrowFromSystemServer();
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00002098 }
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00002099 }
2100
2101 @Override
Andrei Stingaceanu355b2322016-02-12 16:43:51 +00002102 public boolean isPackageSuspendedForUser(String packageName, int userId) {
2103 try {
2104 return mPM.isPackageSuspendedForUser(packageName, userId);
2105 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002106 throw e.rethrowFromSystemServer();
Andrei Stingaceanu355b2322016-02-12 16:43:51 +00002107 }
Andrei Stingaceanu355b2322016-02-12 16:43:51 +00002108 }
2109
Jeff Sharkey9bc89af2017-01-11 11:25:50 -07002110 /** @hide */
2111 @Override
2112 public void setApplicationCategoryHint(String packageName, int categoryHint) {
2113 try {
2114 mPM.setApplicationCategoryHint(packageName, categoryHint,
2115 mContext.getOpPackageName());
2116 } catch (RemoteException e) {
2117 throw e.rethrowFromSystemServer();
2118 }
2119 }
2120
Andrei Stingaceanu355b2322016-02-12 16:43:51 +00002121 @Override
Jeff Sharkeye06b4d12016-01-06 14:51:50 -07002122 public void getPackageSizeInfoAsUser(String packageName, int userHandle,
Dianne Hackborn0c380492012-08-20 17:23:30 -07002123 IPackageStatsObserver observer) {
Jeff Sharkey6f4b2a32017-03-21 14:13:41 -06002124 final String msg = "Shame on you for calling the hidden API "
2125 + "getPackageSizeInfoAsUser(). Shame!";
Jeff Sharkeye6306c42017-03-07 21:03:18 -07002126 if (mContext.getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.O) {
Jeff Sharkey6f4b2a32017-03-21 14:13:41 -06002127 throw new UnsupportedOperationException(msg);
Jeff Sharkeye6306c42017-03-07 21:03:18 -07002128 } else if (observer != null) {
Jeff Sharkey6f4b2a32017-03-21 14:13:41 -06002129 Log.d(TAG, msg);
Jeff Sharkeye6306c42017-03-07 21:03:18 -07002130 try {
2131 observer.onGetStatsCompleted(null, false);
2132 } catch (RemoteException ignored) {
2133 }
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002134 }
2135 }
Jeff Sharkeyd5896632016-03-04 16:16:00 -07002136
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002137 @Override
2138 public void addPackageToPreferred(String packageName) {
Jeff Sharkeyd5896632016-03-04 16:16:00 -07002139 Log.w(TAG, "addPackageToPreferred() is a no-op");
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002140 }
2141
2142 @Override
2143 public void removePackageFromPreferred(String packageName) {
Jeff Sharkeyd5896632016-03-04 16:16:00 -07002144 Log.w(TAG, "removePackageFromPreferred() is a no-op");
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002145 }
2146
2147 @Override
2148 public List<PackageInfo> getPreferredPackages(int flags) {
Jeff Sharkeyd5896632016-03-04 16:16:00 -07002149 Log.w(TAG, "getPreferredPackages() is a no-op");
2150 return Collections.emptyList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002151 }
2152
2153 @Override
2154 public void addPreferredActivity(IntentFilter filter,
2155 int match, ComponentName[] set, ComponentName activity) {
2156 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -07002157 mPM.addPreferredActivity(filter, match, set, activity, mContext.getUserId());
Amith Yamasania3f133a2012-08-09 17:11:28 -07002158 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002159 throw e.rethrowFromSystemServer();
Amith Yamasania3f133a2012-08-09 17:11:28 -07002160 }
2161 }
2162
2163 @Override
Jeff Sharkeye06b4d12016-01-06 14:51:50 -07002164 public void addPreferredActivityAsUser(IntentFilter filter, int match,
Amith Yamasania3f133a2012-08-09 17:11:28 -07002165 ComponentName[] set, ComponentName activity, int userId) {
2166 try {
2167 mPM.addPreferredActivity(filter, match, set, activity, userId);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002168 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002169 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002170 }
2171 }
2172
2173 @Override
2174 public void replacePreferredActivity(IntentFilter filter,
2175 int match, ComponentName[] set, ComponentName activity) {
2176 try {
Robin Lee0e27c872015-09-28 14:37:40 +01002177 mPM.replacePreferredActivity(filter, match, set, activity, mContext.getUserId());
Amith Yamasani41c1ded2014-08-05 11:15:05 -07002178 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002179 throw e.rethrowFromSystemServer();
Amith Yamasani41c1ded2014-08-05 11:15:05 -07002180 }
2181 }
2182
2183 @Override
2184 public void replacePreferredActivityAsUser(IntentFilter filter,
2185 int match, ComponentName[] set, ComponentName activity,
2186 int userId) {
2187 try {
2188 mPM.replacePreferredActivity(filter, match, set, activity, userId);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002189 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002190 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002191 }
2192 }
2193
2194 @Override
2195 public void clearPackagePreferredActivities(String packageName) {
2196 try {
2197 mPM.clearPackagePreferredActivities(packageName);
2198 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002199 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002200 }
2201 }
2202
2203 @Override
2204 public int getPreferredActivities(List<IntentFilter> outFilters,
2205 List<ComponentName> outActivities, String packageName) {
2206 try {
2207 return mPM.getPreferredActivities(outFilters, outActivities, packageName);
2208 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002209 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002210 }
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002211 }
2212
2213 @Override
Christopher Tatea2a0850d2013-09-05 16:38:58 -07002214 public ComponentName getHomeActivities(List<ResolveInfo> outActivities) {
2215 try {
2216 return mPM.getHomeActivities(outActivities);
2217 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002218 throw e.rethrowFromSystemServer();
Christopher Tatea2a0850d2013-09-05 16:38:58 -07002219 }
Christopher Tatea2a0850d2013-09-05 16:38:58 -07002220 }
2221
2222 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002223 public void setComponentEnabledSetting(ComponentName componentName,
2224 int newState, int flags) {
2225 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -07002226 mPM.setComponentEnabledSetting(componentName, newState, flags, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002227 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002228 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002229 }
2230 }
2231
2232 @Override
2233 public int getComponentEnabledSetting(ComponentName componentName) {
2234 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -07002235 return mPM.getComponentEnabledSetting(componentName, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002236 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002237 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002238 }
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002239 }
2240
2241 @Override
2242 public void setApplicationEnabledSetting(String packageName,
2243 int newState, int flags) {
2244 try {
Dianne Hackborn3fa3c28a2013-03-26 16:15:41 -07002245 mPM.setApplicationEnabledSetting(packageName, newState, flags,
Dianne Hackborn95d78532013-09-11 09:51:14 -07002246 mContext.getUserId(), mContext.getOpPackageName());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002247 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002248 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002249 }
2250 }
2251
2252 @Override
2253 public int getApplicationEnabledSetting(String packageName) {
2254 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -07002255 return mPM.getApplicationEnabledSetting(packageName, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002256 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002257 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002258 }
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002259 }
2260
Amith Yamasani655d0e22013-06-12 14:19:10 -07002261 @Override
Sudheer Shankabbb3ff22015-07-09 15:39:23 +01002262 public void flushPackageRestrictionsAsUser(int userId) {
2263 try {
2264 mPM.flushPackageRestrictionsAsUser(userId);
2265 } catch (RemoteException e) {
2266 throw e.rethrowFromSystemServer();
2267 }
2268 }
2269
2270 @Override
Amith Yamasanie5bcff62014-07-19 15:44:09 -07002271 public boolean setApplicationHiddenSettingAsUser(String packageName, boolean hidden,
Amith Yamasani655d0e22013-06-12 14:19:10 -07002272 UserHandle user) {
2273 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07002274 return mPM.setApplicationHiddenSettingAsUser(packageName, hidden,
Amith Yamasani655d0e22013-06-12 14:19:10 -07002275 user.getIdentifier());
Jeff Sharkey27b2e692016-02-25 17:40:12 -07002276 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002277 throw e.rethrowFromSystemServer();
Amith Yamasani655d0e22013-06-12 14:19:10 -07002278 }
Amith Yamasani655d0e22013-06-12 14:19:10 -07002279 }
2280
2281 @Override
Amith Yamasanie5bcff62014-07-19 15:44:09 -07002282 public boolean getApplicationHiddenSettingAsUser(String packageName, UserHandle user) {
Amith Yamasani655d0e22013-06-12 14:19:10 -07002283 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07002284 return mPM.getApplicationHiddenSettingAsUser(packageName, user.getIdentifier());
Jeff Sharkey27b2e692016-02-25 17:40:12 -07002285 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002286 throw e.rethrowFromSystemServer();
Amith Yamasani655d0e22013-06-12 14:19:10 -07002287 }
Amith Yamasani655d0e22013-06-12 14:19:10 -07002288 }
2289
dcashmanc6f22492014-08-14 09:54:51 -07002290 /** @hide */
dcashman9d2f4412014-06-09 09:27:54 -07002291 @Override
2292 public KeySet getKeySetByAlias(String packageName, String alias) {
2293 Preconditions.checkNotNull(packageName);
2294 Preconditions.checkNotNull(alias);
dcashman9d2f4412014-06-09 09:27:54 -07002295 try {
Jeff Sharkey27b2e692016-02-25 17:40:12 -07002296 return mPM.getKeySetByAlias(packageName, alias);
dcashman9d2f4412014-06-09 09:27:54 -07002297 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002298 throw e.rethrowFromSystemServer();
dcashman9d2f4412014-06-09 09:27:54 -07002299 }
dcashman9d2f4412014-06-09 09:27:54 -07002300 }
2301
dcashmanc6f22492014-08-14 09:54:51 -07002302 /** @hide */
dcashman9d2f4412014-06-09 09:27:54 -07002303 @Override
2304 public KeySet getSigningKeySet(String packageName) {
2305 Preconditions.checkNotNull(packageName);
dcashman9d2f4412014-06-09 09:27:54 -07002306 try {
Jeff Sharkey27b2e692016-02-25 17:40:12 -07002307 return mPM.getSigningKeySet(packageName);
dcashman9d2f4412014-06-09 09:27:54 -07002308 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002309 throw e.rethrowFromSystemServer();
dcashman9d2f4412014-06-09 09:27:54 -07002310 }
dcashman9d2f4412014-06-09 09:27:54 -07002311 }
2312
dcashmanc6f22492014-08-14 09:54:51 -07002313 /** @hide */
dcashman9d2f4412014-06-09 09:27:54 -07002314 @Override
2315 public boolean isSignedBy(String packageName, KeySet ks) {
2316 Preconditions.checkNotNull(packageName);
2317 Preconditions.checkNotNull(ks);
dcashman9d2f4412014-06-09 09:27:54 -07002318 try {
dcashmanc6f22492014-08-14 09:54:51 -07002319 return mPM.isPackageSignedByKeySet(packageName, ks);
dcashman9d2f4412014-06-09 09:27:54 -07002320 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002321 throw e.rethrowFromSystemServer();
dcashman9d2f4412014-06-09 09:27:54 -07002322 }
2323 }
2324
dcashmanc6f22492014-08-14 09:54:51 -07002325 /** @hide */
dcashman9d2f4412014-06-09 09:27:54 -07002326 @Override
2327 public boolean isSignedByExactly(String packageName, KeySet ks) {
2328 Preconditions.checkNotNull(packageName);
2329 Preconditions.checkNotNull(ks);
dcashman9d2f4412014-06-09 09:27:54 -07002330 try {
dcashmanc6f22492014-08-14 09:54:51 -07002331 return mPM.isPackageSignedByKeySetExactly(packageName, ks);
dcashman9d2f4412014-06-09 09:27:54 -07002332 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002333 throw e.rethrowFromSystemServer();
dcashman9d2f4412014-06-09 09:27:54 -07002334 }
2335 }
2336
Kenny Root0aaa0d92011-09-12 16:42:55 -07002337 /**
2338 * @hide
2339 */
2340 @Override
2341 public VerifierDeviceIdentity getVerifierDeviceIdentity() {
2342 try {
2343 return mPM.getVerifierDeviceIdentity();
2344 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002345 throw e.rethrowFromSystemServer();
Kenny Root0aaa0d92011-09-12 16:42:55 -07002346 }
Kenny Root0aaa0d92011-09-12 16:42:55 -07002347 }
2348
Jeff Hao9f60c082014-10-28 18:51:07 -07002349 /**
2350 * @hide
2351 */
2352 @Override
2353 public boolean isUpgrade() {
2354 try {
2355 return mPM.isUpgrade();
2356 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002357 throw e.rethrowFromSystemServer();
Jeff Hao9f60c082014-10-28 18:51:07 -07002358 }
2359 }
2360
Jeff Sharkey3a44f3f2014-04-28 17:36:31 -07002361 @Override
Jeff Sharkey16c8e3f2014-07-24 17:08:17 -07002362 public PackageInstaller getPackageInstaller() {
2363 synchronized (mLock) {
2364 if (mInstaller == null) {
2365 try {
Svet Ganov67882122016-12-11 16:36:34 -08002366 mInstaller = new PackageInstaller(mPM.getPackageInstaller(),
Jeff Sharkey16c8e3f2014-07-24 17:08:17 -07002367 mContext.getPackageName(), mContext.getUserId());
2368 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002369 throw e.rethrowFromSystemServer();
Jeff Sharkey16c8e3f2014-07-24 17:08:17 -07002370 }
2371 }
2372 return mInstaller;
Jeff Sharkey3a44f3f2014-04-28 17:36:31 -07002373 }
2374 }
2375
Jeff Sharkey6c833e02014-07-14 22:44:30 -07002376 @Override
2377 public boolean isPackageAvailable(String packageName) {
2378 try {
2379 return mPM.isPackageAvailable(packageName, mContext.getUserId());
2380 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002381 throw e.rethrowFromSystemServer();
Jeff Sharkey6c833e02014-07-14 22:44:30 -07002382 }
2383 }
2384
Nicolas Prevotc79586e2014-05-06 12:47:57 +01002385 /**
2386 * @hide
2387 */
2388 @Override
Nicolas Prevot63798c52014-05-27 13:22:38 +01002389 public void addCrossProfileIntentFilter(IntentFilter filter, int sourceUserId, int targetUserId,
2390 int flags) {
Nicolas Prevotc79586e2014-05-06 12:47:57 +01002391 try {
Nicolas Prevot3f7777f2014-07-24 15:58:39 +01002392 mPM.addCrossProfileIntentFilter(filter, mContext.getOpPackageName(),
Nicolas Prevot4b8d5822015-03-05 15:20:49 +00002393 sourceUserId, targetUserId, flags);
Nicolas Prevotc79586e2014-05-06 12:47:57 +01002394 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002395 throw e.rethrowFromSystemServer();
Nicolas Prevotc79586e2014-05-06 12:47:57 +01002396 }
2397 }
2398
2399 /**
2400 * @hide
2401 */
2402 @Override
Nicolas Prevot81948992014-05-16 18:25:26 +01002403 public void clearCrossProfileIntentFilters(int sourceUserId) {
Nicolas Prevotc79586e2014-05-06 12:47:57 +01002404 try {
Nicolas Prevot4b8d5822015-03-05 15:20:49 +00002405 mPM.clearCrossProfileIntentFilters(sourceUserId, mContext.getOpPackageName());
Nicolas Prevotc79586e2014-05-06 12:47:57 +01002406 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002407 throw e.rethrowFromSystemServer();
Nicolas Prevotc79586e2014-05-06 12:47:57 +01002408 }
2409 }
2410
Nicolas Prevot88cc3462014-05-14 14:51:48 +01002411 /**
2412 * @hide
2413 */
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +01002414 public Drawable loadItemIcon(PackageItemInfo itemInfo, ApplicationInfo appInfo) {
Benjamin Franzec2d48b2014-10-01 15:38:43 +01002415 Drawable dr = loadUnbadgedItemIcon(itemInfo, appInfo);
2416 if (itemInfo.showUserIcon != UserHandle.USER_NULL) {
2417 return dr;
2418 }
2419 return getUserBadgedIcon(dr, new UserHandle(mContext.getUserId()));
2420 }
2421
2422 /**
2423 * @hide
2424 */
2425 public Drawable loadUnbadgedItemIcon(PackageItemInfo itemInfo, ApplicationInfo appInfo) {
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +01002426 if (itemInfo.showUserIcon != UserHandle.USER_NULL) {
Alexandra Gherghina64d4dca2014-08-28 18:26:56 +01002427 Bitmap bitmap = getUserManager().getUserIcon(itemInfo.showUserIcon);
2428 if (bitmap == null) {
2429 return UserIcons.getDefaultUserIcon(itemInfo.showUserIcon, /* light= */ false);
2430 }
2431 return new BitmapDrawable(bitmap);
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +01002432 }
Alexandra Gherghinadb811db2014-08-29 13:43:59 +01002433 Drawable dr = null;
2434 if (itemInfo.packageName != null) {
2435 dr = getDrawable(itemInfo.packageName, itemInfo.icon, appInfo);
2436 }
Alexandra Gherghinaa71e3902014-07-25 20:03:47 +01002437 if (dr == null) {
Alexandra Gherghinaa7093142014-07-30 13:43:39 +01002438 dr = itemInfo.loadDefaultIcon(this);
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +01002439 }
Benjamin Franzec2d48b2014-10-01 15:38:43 +01002440 return dr;
Svetoslavc7d62f02014-09-04 15:39:54 -07002441 }
2442
2443 private Drawable getBadgedDrawable(Drawable drawable, Drawable badgeDrawable,
2444 Rect badgeLocation, boolean tryBadgeInPlace) {
2445 final int badgedWidth = drawable.getIntrinsicWidth();
2446 final int badgedHeight = drawable.getIntrinsicHeight();
2447 final boolean canBadgeInPlace = tryBadgeInPlace
2448 && (drawable instanceof BitmapDrawable)
2449 && ((BitmapDrawable) drawable).getBitmap().isMutable();
2450
2451 final Bitmap bitmap;
2452 if (canBadgeInPlace) {
2453 bitmap = ((BitmapDrawable) drawable).getBitmap();
2454 } else {
2455 bitmap = Bitmap.createBitmap(badgedWidth, badgedHeight, Bitmap.Config.ARGB_8888);
2456 }
2457 Canvas canvas = new Canvas(bitmap);
2458
2459 if (!canBadgeInPlace) {
2460 drawable.setBounds(0, 0, badgedWidth, badgedHeight);
2461 drawable.draw(canvas);
2462 }
2463
2464 if (badgeLocation != null) {
2465 if (badgeLocation.left < 0 || badgeLocation.top < 0
2466 || badgeLocation.width() > badgedWidth || badgeLocation.height() > badgedHeight) {
2467 throw new IllegalArgumentException("Badge location " + badgeLocation
2468 + " not in badged drawable bounds "
2469 + new Rect(0, 0, badgedWidth, badgedHeight));
2470 }
2471 badgeDrawable.setBounds(0, 0, badgeLocation.width(), badgeLocation.height());
2472
2473 canvas.save();
2474 canvas.translate(badgeLocation.left, badgeLocation.top);
2475 badgeDrawable.draw(canvas);
2476 canvas.restore();
2477 } else {
2478 badgeDrawable.setBounds(0, 0, badgedWidth, badgedHeight);
2479 badgeDrawable.draw(canvas);
2480 }
2481
2482 if (!canBadgeInPlace) {
2483 BitmapDrawable mergedDrawable = new BitmapDrawable(mContext.getResources(), bitmap);
2484
2485 if (drawable instanceof BitmapDrawable) {
2486 BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
2487 mergedDrawable.setTargetDensity(bitmapDrawable.getBitmap().getDensity());
2488 }
2489
2490 return mergedDrawable;
2491 }
2492
2493 return drawable;
2494 }
2495
Tony Mak8673b282016-03-21 21:10:59 +00002496 private boolean isManagedProfile(int userId) {
2497 return getUserManager().isManagedProfile(userId);
Nicolas Prevot88cc3462014-05-14 14:51:48 +01002498 }
2499
Bartosz Fabianowskia34f53f2017-01-11 18:08:47 +01002500 /**
2501 * @hide
2502 */
2503 @Override
2504 public int getInstallReason(String packageName, UserHandle user) {
2505 try {
2506 return mPM.getInstallReason(packageName, user.getIdentifier());
2507 } catch (RemoteException e) {
2508 throw e.rethrowFromSystemServer();
2509 }
2510 }
2511
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002512 /** {@hide} */
2513 private static class MoveCallbackDelegate extends IPackageMoveObserver.Stub implements
2514 Handler.Callback {
Jeff Sharkey50a05452015-04-29 11:24:52 -07002515 private static final int MSG_CREATED = 1;
2516 private static final int MSG_STATUS_CHANGED = 2;
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002517
2518 final MoveCallback mCallback;
2519 final Handler mHandler;
2520
2521 public MoveCallbackDelegate(MoveCallback callback, Looper looper) {
2522 mCallback = callback;
2523 mHandler = new Handler(looper, this);
2524 }
2525
2526 @Override
2527 public boolean handleMessage(Message msg) {
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002528 switch (msg.what) {
Jeff Sharkey50a05452015-04-29 11:24:52 -07002529 case MSG_CREATED: {
Jeff Sharkeyb36586a2015-04-27 08:42:28 -07002530 final SomeArgs args = (SomeArgs) msg.obj;
Jeff Sharkey50a05452015-04-29 11:24:52 -07002531 mCallback.onCreated(args.argi1, (Bundle) args.arg2);
Jeff Sharkeyb36586a2015-04-27 08:42:28 -07002532 args.recycle();
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002533 return true;
Jeff Sharkey50a05452015-04-29 11:24:52 -07002534 }
2535 case MSG_STATUS_CHANGED: {
2536 final SomeArgs args = (SomeArgs) msg.obj;
2537 mCallback.onStatusChanged(args.argi1, args.argi2, (long) args.arg3);
2538 args.recycle();
2539 return true;
2540 }
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002541 }
2542 return false;
2543 }
2544
2545 @Override
Jeff Sharkey50a05452015-04-29 11:24:52 -07002546 public void onCreated(int moveId, Bundle extras) {
Jeff Sharkeyb36586a2015-04-27 08:42:28 -07002547 final SomeArgs args = SomeArgs.obtain();
2548 args.argi1 = moveId;
Jeff Sharkey50a05452015-04-29 11:24:52 -07002549 args.arg2 = extras;
2550 mHandler.obtainMessage(MSG_CREATED, args).sendToTarget();
2551 }
2552
2553 @Override
2554 public void onStatusChanged(int moveId, int status, long estMillis) {
2555 final SomeArgs args = SomeArgs.obtain();
2556 args.argi1 = moveId;
2557 args.argi2 = status;
2558 args.arg3 = estMillis;
Jeff Sharkeyb36586a2015-04-27 08:42:28 -07002559 mHandler.obtainMessage(MSG_STATUS_CHANGED, args).sendToTarget();
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002560 }
2561 }
2562
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002563 private final ContextImpl mContext;
2564 private final IPackageManager mPM;
2565
2566 private static final Object sSync = new Object();
Dianne Hackbornadd005c2013-07-17 18:43:12 -07002567 private static ArrayMap<ResourceName, WeakReference<Drawable.ConstantState>> sIconCache
2568 = new ArrayMap<ResourceName, WeakReference<Drawable.ConstantState>>();
2569 private static ArrayMap<ResourceName, WeakReference<CharSequence>> sStringCache
2570 = new ArrayMap<ResourceName, WeakReference<CharSequence>>();
Svetoslavf7c06eb2015-06-10 18:43:22 -07002571
2572 private final Map<OnPermissionsChangedListener, IOnPermissionsChangeListener>
2573 mPermissionListeners = new ArrayMap<>();
2574
2575 public class OnPermissionsChangeListenerDelegate extends IOnPermissionsChangeListener.Stub
2576 implements Handler.Callback{
2577 private static final int MSG_PERMISSIONS_CHANGED = 1;
2578
2579 private final OnPermissionsChangedListener mListener;
2580 private final Handler mHandler;
2581
2582
2583 public OnPermissionsChangeListenerDelegate(OnPermissionsChangedListener listener,
2584 Looper looper) {
2585 mListener = listener;
2586 mHandler = new Handler(looper, this);
2587 }
2588
2589 @Override
2590 public void onPermissionsChanged(int uid) {
2591 mHandler.obtainMessage(MSG_PERMISSIONS_CHANGED, uid, 0).sendToTarget();
2592 }
2593
2594 @Override
2595 public boolean handleMessage(Message msg) {
2596 switch (msg.what) {
2597 case MSG_PERMISSIONS_CHANGED: {
2598 final int uid = msg.arg1;
2599 mListener.onPermissionsChanged(uid);
2600 return true;
2601 }
2602 }
2603 return false;
2604 }
2605 }
Suprabh Shuklaaef25132017-01-23 18:09:03 -08002606
2607 @Override
2608 public boolean canRequestPackageInstalls() {
2609 try {
2610 return mPM.canRequestPackageInstalls(mContext.getPackageName(), mContext.getUserId());
2611 } catch (RemoteException e) {
2612 throw e.rethrowAsRuntimeException();
2613 }
2614 }
Chad Brubaker336ae5b2017-03-24 15:53:09 -07002615
2616 @Override
2617 public ComponentName getInstantAppResolverSettingsComponent() {
2618 try {
2619 return mPM.getInstantAppResolverSettingsComponent();
2620 } catch (RemoteException e) {
2621 throw e.rethrowAsRuntimeException();
2622 }
2623 }
Todd Kennedy801e6592017-04-12 14:10:12 -07002624
2625 @Override
2626 public ComponentName getInstantAppInstallerComponent() {
2627 try {
2628 return mPM.getInstantAppInstallerComponent();
2629 } catch (RemoteException e) {
2630 throw e.rethrowAsRuntimeException();
2631 }
2632 }
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002633}