blob: 51c2246e3ccd0c68a9f8eb8d6be17d5f5e29878c [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
Svetoslav Ganov345ffa52017-04-18 16:08:41 -0700823 public int getInstantAppCookieMaxBytes() {
Svet Ganov2acf0632015-11-24 19:10:59 -0800824 return Settings.Global.getInt(mContext.getContentResolver(),
825 Settings.Global.EPHEMERAL_COOKIE_MAX_SIZE_BYTES,
826 DEFAULT_EPHEMERAL_COOKIE_MAX_SIZE_BYTES);
827 }
828
829 @Override
Svetoslav Ganov345ffa52017-04-18 16:08:41 -0700830 public int getInstantAppCookieMaxSize() {
831 return getInstantAppCookieMaxBytes();
832 }
833
834 @Override
Svetoslav Ganov096d3042017-01-30 16:34:13 -0800835 public @NonNull byte[] getInstantAppCookie() {
Svet Ganov2acf0632015-11-24 19:10:59 -0800836 try {
Svetoslav Ganov096d3042017-01-30 16:34:13 -0800837 final byte[] cookie = mPM.getInstantAppCookie(
Svet Ganov2acf0632015-11-24 19:10:59 -0800838 mContext.getPackageName(), mContext.getUserId());
839 if (cookie != null) {
840 return cookie;
Jeff Sharkey27b2e692016-02-25 17:40:12 -0700841 } else {
842 return EmptyArray.BYTE;
Svet Ganov2acf0632015-11-24 19:10:59 -0800843 }
844 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700845 throw e.rethrowFromSystemServer();
Svet Ganov2acf0632015-11-24 19:10:59 -0800846 }
Svet Ganov2acf0632015-11-24 19:10:59 -0800847 }
848
849 @Override
Svetoslav Ganov345ffa52017-04-18 16:08:41 -0700850 public void clearInstantAppCookie() {
851 updateInstantAppCookie(null);
852 }
853
854 @Override
855 public void updateInstantAppCookie(@NonNull byte[] cookie) {
856 if (cookie != null && cookie.length > getInstantAppCookieMaxBytes()) {
857 throw new IllegalArgumentException("instant cookie longer than "
858 + getInstantAppCookieMaxBytes());
859 }
860 try {
861 mPM.setInstantAppCookie(mContext.getPackageName(),
862 cookie, mContext.getUserId());
863 } catch (RemoteException e) {
864 throw e.rethrowFromSystemServer();
865 }
866 }
867
868 @Override
Svetoslav Ganov096d3042017-01-30 16:34:13 -0800869 public boolean setInstantAppCookie(@NonNull byte[] cookie) {
Svet Ganov2acf0632015-11-24 19:10:59 -0800870 try {
Svetoslav Ganov096d3042017-01-30 16:34:13 -0800871 return mPM.setInstantAppCookie(mContext.getPackageName(),
872 cookie, mContext.getUserId());
Svet Ganov2acf0632015-11-24 19:10:59 -0800873 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700874 throw e.rethrowFromSystemServer();
Svet Ganov2acf0632015-11-24 19:10:59 -0800875 }
Svet Ganov2acf0632015-11-24 19:10:59 -0800876 }
877
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800878 @Override
879 public ResolveInfo resolveActivity(Intent intent, int flags) {
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700880 return resolveActivityAsUser(intent, flags, mContext.getUserId());
Svetoslav Ganov58d37b52012-09-18 12:04:19 -0700881 }
882
883 @Override
884 public ResolveInfo resolveActivityAsUser(Intent intent, int flags, int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800885 try {
886 return mPM.resolveIntent(
887 intent,
888 intent.resolveTypeIfNeeded(mContext.getContentResolver()),
Svetoslav Ganov58d37b52012-09-18 12:04:19 -0700889 flags,
890 userId);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800891 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700892 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800893 }
894 }
895
896 @Override
897 public List<ResolveInfo> queryIntentActivities(Intent intent,
898 int flags) {
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700899 return queryIntentActivitiesAsUser(intent, flags, mContext.getUserId());
Amith Yamasani151ec4c2012-09-07 19:25:16 -0700900 }
901
902 /** @hide Same as above but for a specific user */
903 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700904 @SuppressWarnings("unchecked")
Svetoslav Ganov58d37b52012-09-18 12:04:19 -0700905 public List<ResolveInfo> queryIntentActivitiesAsUser(Intent intent,
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700906 int flags, int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800907 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700908 ParceledListSlice<ResolveInfo> parceledList =
909 mPM.queryIntentActivities(intent,
910 intent.resolveTypeIfNeeded(mContext.getContentResolver()),
911 flags, userId);
912 if (parceledList == null) {
913 return Collections.emptyList();
914 }
915 return parceledList.getList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800916 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700917 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800918 }
919 }
920
921 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700922 @SuppressWarnings("unchecked")
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800923 public List<ResolveInfo> queryIntentActivityOptions(
924 ComponentName caller, Intent[] specifics, Intent intent,
925 int flags) {
926 final ContentResolver resolver = mContext.getContentResolver();
927
928 String[] specificTypes = null;
929 if (specifics != null) {
930 final int N = specifics.length;
931 for (int i=0; i<N; i++) {
932 Intent sp = specifics[i];
933 if (sp != null) {
934 String t = sp.resolveTypeIfNeeded(resolver);
935 if (t != null) {
936 if (specificTypes == null) {
937 specificTypes = new String[N];
938 }
939 specificTypes[i] = t;
940 }
941 }
942 }
943 }
944
945 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700946 ParceledListSlice<ResolveInfo> parceledList =
947 mPM.queryIntentActivityOptions(caller, specifics, specificTypes, intent,
948 intent.resolveTypeIfNeeded(resolver), flags, mContext.getUserId());
949 if (parceledList == null) {
950 return Collections.emptyList();
951 }
952 return parceledList.getList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800953 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700954 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800955 }
956 }
957
Amith Yamasanif203aee2012-08-29 18:41:53 -0700958 /**
959 * @hide
960 */
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800961 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700962 @SuppressWarnings("unchecked")
Jeff Sharkeye06b4d12016-01-06 14:51:50 -0700963 public List<ResolveInfo> queryBroadcastReceiversAsUser(Intent intent, int flags, int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800964 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700965 ParceledListSlice<ResolveInfo> parceledList =
966 mPM.queryIntentReceivers(intent,
967 intent.resolveTypeIfNeeded(mContext.getContentResolver()),
968 flags, userId);
969 if (parceledList == null) {
970 return Collections.emptyList();
971 }
972 return parceledList.getList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800973 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700974 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800975 }
976 }
977
978 @Override
Amith Yamasanif203aee2012-08-29 18:41:53 -0700979 public List<ResolveInfo> queryBroadcastReceivers(Intent intent, int flags) {
Jeff Sharkeye06b4d12016-01-06 14:51:50 -0700980 return queryBroadcastReceiversAsUser(intent, flags, mContext.getUserId());
Amith Yamasanif203aee2012-08-29 18:41:53 -0700981 }
982
983 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800984 public ResolveInfo resolveService(Intent intent, int flags) {
985 try {
986 return mPM.resolveService(
987 intent,
988 intent.resolveTypeIfNeeded(mContext.getContentResolver()),
Amith Yamasani483f3b02012-03-13 16:08:00 -0700989 flags,
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700990 mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800991 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700992 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800993 }
994 }
995
996 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700997 @SuppressWarnings("unchecked")
Svetoslav Ganov58d37b52012-09-18 12:04:19 -0700998 public List<ResolveInfo> queryIntentServicesAsUser(Intent intent, int flags, int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800999 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001000 ParceledListSlice<ResolveInfo> parceledList =
1001 mPM.queryIntentServices(intent,
1002 intent.resolveTypeIfNeeded(mContext.getContentResolver()),
1003 flags, userId);
1004 if (parceledList == null) {
1005 return Collections.emptyList();
1006 }
1007 return parceledList.getList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001008 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001009 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001010 }
1011 }
1012
1013 @Override
Svetoslav Ganov58d37b52012-09-18 12:04:19 -07001014 public List<ResolveInfo> queryIntentServices(Intent intent, int flags) {
Jeff Sharkeyded653b2012-09-27 19:09:24 -07001015 return queryIntentServicesAsUser(intent, flags, mContext.getUserId());
Svetoslav Ganov58d37b52012-09-18 12:04:19 -07001016 }
1017
1018 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001019 @SuppressWarnings("unchecked")
Jeff Sharkey85f5f812013-10-07 10:16:12 -07001020 public List<ResolveInfo> queryIntentContentProvidersAsUser(
1021 Intent intent, int flags, int userId) {
1022 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001023 ParceledListSlice<ResolveInfo> parceledList =
1024 mPM.queryIntentContentProviders(intent,
1025 intent.resolveTypeIfNeeded(mContext.getContentResolver()),
1026 flags, userId);
1027 if (parceledList == null) {
1028 return Collections.emptyList();
1029 }
1030 return parceledList.getList();
Jeff Sharkey85f5f812013-10-07 10:16:12 -07001031 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001032 throw e.rethrowFromSystemServer();
Jeff Sharkey85f5f812013-10-07 10:16:12 -07001033 }
1034 }
1035
1036 @Override
1037 public List<ResolveInfo> queryIntentContentProviders(Intent intent, int flags) {
1038 return queryIntentContentProvidersAsUser(intent, flags, mContext.getUserId());
1039 }
1040
1041 @Override
Alexandra Gherghina0363c3e2014-06-23 13:34:59 +01001042 public ProviderInfo resolveContentProvider(String name, int flags) {
1043 return resolveContentProviderAsUser(name, flags, mContext.getUserId());
1044 }
1045
1046 /** @hide **/
1047 @Override
1048 public ProviderInfo resolveContentProviderAsUser(String name, int flags, int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001049 try {
Alexandra Gherghina0363c3e2014-06-23 13:34:59 +01001050 return mPM.resolveContentProvider(name, flags, userId);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001051 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001052 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001053 }
1054 }
1055
1056 @Override
1057 public List<ProviderInfo> queryContentProviders(String processName,
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001058 int uid, int flags) {
Makoto Onuki32757292017-02-22 14:36:59 -08001059 return queryContentProviders(processName, uid, flags, null);
1060 }
1061
1062 @Override
1063 @SuppressWarnings("unchecked")
1064 public List<ProviderInfo> queryContentProviders(String processName,
1065 int uid, int flags, String metaDataKey) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001066 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001067 ParceledListSlice<ProviderInfo> slice =
Makoto Onuki32757292017-02-22 14:36:59 -08001068 mPM.queryContentProviders(processName, uid, flags, metaDataKey);
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001069 return slice != null ? slice.getList() : Collections.<ProviderInfo>emptyList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001070 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001071 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001072 }
1073 }
1074
1075 @Override
1076 public InstrumentationInfo getInstrumentationInfo(
1077 ComponentName className, int flags)
1078 throws NameNotFoundException {
1079 try {
1080 InstrumentationInfo ii = mPM.getInstrumentationInfo(
1081 className, flags);
1082 if (ii != null) {
1083 return ii;
1084 }
1085 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001086 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001087 }
1088
1089 throw new NameNotFoundException(className.toString());
1090 }
1091
1092 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001093 @SuppressWarnings("unchecked")
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001094 public List<InstrumentationInfo> queryInstrumentation(
1095 String targetPackage, int flags) {
1096 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001097 ParceledListSlice<InstrumentationInfo> parceledList =
1098 mPM.queryInstrumentation(targetPackage, flags);
1099 if (parceledList == null) {
1100 return Collections.emptyList();
1101 }
1102 return parceledList.getList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001103 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001104 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001105 }
1106 }
1107
Alan Viveretteecd585a2015-04-13 10:32:51 -07001108 @Nullable
1109 @Override
1110 public Drawable getDrawable(String packageName, @DrawableRes int resId,
1111 @Nullable ApplicationInfo appInfo) {
1112 final ResourceName name = new ResourceName(packageName, resId);
1113 final Drawable cachedIcon = getCachedIcon(name);
1114 if (cachedIcon != null) {
1115 return cachedIcon;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001116 }
Alan Viveretteecd585a2015-04-13 10:32:51 -07001117
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001118 if (appInfo == null) {
1119 try {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001120 appInfo = getApplicationInfo(packageName, sDefaultFlags);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001121 } catch (NameNotFoundException e) {
1122 return null;
1123 }
1124 }
Alan Viveretteecd585a2015-04-13 10:32:51 -07001125
1126 if (resId != 0) {
1127 try {
1128 final Resources r = getResourcesForApplication(appInfo);
1129 final Drawable dr = r.getDrawable(resId, null);
1130 if (dr != null) {
1131 putCachedIcon(name, dr);
1132 }
1133
1134 if (false) {
1135 RuntimeException e = new RuntimeException("here");
1136 e.fillInStackTrace();
1137 Log.w(TAG, "Getting drawable 0x" + Integer.toHexString(resId)
1138 + " from package " + packageName
1139 + ": app scale=" + r.getCompatibilityInfo().applicationScale
1140 + ", caller scale=" + mContext.getResources()
1141 .getCompatibilityInfo().applicationScale,
1142 e);
1143 }
Ricky Wai3ce46252015-04-15 16:12:22 +01001144 if (DEBUG_ICONS) {
Alan Viveretteecd585a2015-04-13 10:32:51 -07001145 Log.v(TAG, "Getting drawable 0x"
1146 + Integer.toHexString(resId) + " from " + r
1147 + ": " + dr);
Ricky Wai3ce46252015-04-15 16:12:22 +01001148 }
1149 return dr;
Alan Viveretteecd585a2015-04-13 10:32:51 -07001150 } catch (NameNotFoundException e) {
1151 Log.w("PackageManager", "Failure retrieving resources for "
1152 + appInfo.packageName);
1153 } catch (Resources.NotFoundException e) {
1154 Log.w("PackageManager", "Failure retrieving resources for "
1155 + appInfo.packageName + ": " + e.getMessage());
1156 } catch (Exception e) {
1157 // If an exception was thrown, fall through to return
1158 // default icon.
1159 Log.w("PackageManager", "Failure retrieving icon 0x"
1160 + Integer.toHexString(resId) + " in package "
1161 + packageName, e);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001162 }
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001163 }
Alan Viveretteecd585a2015-04-13 10:32:51 -07001164
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001165 return null;
1166 }
1167
1168 @Override public Drawable getActivityIcon(ComponentName activityName)
1169 throws NameNotFoundException {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001170 return getActivityInfo(activityName, sDefaultFlags).loadIcon(this);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001171 }
1172
1173 @Override public Drawable getActivityIcon(Intent intent)
1174 throws NameNotFoundException {
1175 if (intent.getComponent() != null) {
1176 return getActivityIcon(intent.getComponent());
1177 }
1178
1179 ResolveInfo info = resolveActivity(
1180 intent, PackageManager.MATCH_DEFAULT_ONLY);
1181 if (info != null) {
1182 return info.activityInfo.loadIcon(this);
1183 }
1184
Romain Guy39fe17c2011-11-30 10:34:07 -08001185 throw new NameNotFoundException(intent.toUri(0));
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001186 }
1187
1188 @Override public Drawable getDefaultActivityIcon() {
1189 return Resources.getSystem().getDrawable(
1190 com.android.internal.R.drawable.sym_def_app_icon);
1191 }
1192
1193 @Override public Drawable getApplicationIcon(ApplicationInfo info) {
1194 return info.loadIcon(this);
1195 }
1196
1197 @Override public Drawable getApplicationIcon(String packageName)
1198 throws NameNotFoundException {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001199 return getApplicationIcon(getApplicationInfo(packageName, sDefaultFlags));
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001200 }
1201
1202 @Override
Jose Limaf78e3122014-03-06 12:13:15 -08001203 public Drawable getActivityBanner(ComponentName activityName)
1204 throws NameNotFoundException {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001205 return getActivityInfo(activityName, sDefaultFlags).loadBanner(this);
Jose Limaf78e3122014-03-06 12:13:15 -08001206 }
1207
1208 @Override
1209 public Drawable getActivityBanner(Intent intent)
1210 throws NameNotFoundException {
1211 if (intent.getComponent() != null) {
1212 return getActivityBanner(intent.getComponent());
1213 }
1214
1215 ResolveInfo info = resolveActivity(
1216 intent, PackageManager.MATCH_DEFAULT_ONLY);
1217 if (info != null) {
1218 return info.activityInfo.loadBanner(this);
1219 }
1220
1221 throw new NameNotFoundException(intent.toUri(0));
1222 }
1223
1224 @Override
1225 public Drawable getApplicationBanner(ApplicationInfo info) {
1226 return info.loadBanner(this);
1227 }
1228
1229 @Override
1230 public Drawable getApplicationBanner(String packageName)
1231 throws NameNotFoundException {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001232 return getApplicationBanner(getApplicationInfo(packageName, sDefaultFlags));
Jose Limaf78e3122014-03-06 12:13:15 -08001233 }
1234
1235 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001236 public Drawable getActivityLogo(ComponentName activityName)
1237 throws NameNotFoundException {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001238 return getActivityInfo(activityName, sDefaultFlags).loadLogo(this);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001239 }
1240
1241 @Override
1242 public Drawable getActivityLogo(Intent intent)
1243 throws NameNotFoundException {
1244 if (intent.getComponent() != null) {
1245 return getActivityLogo(intent.getComponent());
1246 }
1247
1248 ResolveInfo info = resolveActivity(
1249 intent, PackageManager.MATCH_DEFAULT_ONLY);
1250 if (info != null) {
1251 return info.activityInfo.loadLogo(this);
1252 }
1253
1254 throw new NameNotFoundException(intent.toUri(0));
1255 }
1256
1257 @Override
1258 public Drawable getApplicationLogo(ApplicationInfo info) {
1259 return info.loadLogo(this);
1260 }
1261
1262 @Override
1263 public Drawable getApplicationLogo(String packageName)
1264 throws NameNotFoundException {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001265 return getApplicationLogo(getApplicationInfo(packageName, sDefaultFlags));
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001266 }
1267
Svetoslavc7d62f02014-09-04 15:39:54 -07001268 @Override
1269 public Drawable getUserBadgedIcon(Drawable icon, UserHandle user) {
Kenny Guy02c89902016-11-15 19:36:38 +00001270 if (!isManagedProfile(user.getIdentifier())) {
Svetoslavc7d62f02014-09-04 15:39:54 -07001271 return icon;
1272 }
Sunny Goyalbab30752017-04-12 15:36:42 -07001273 Drawable badge = new LauncherIcons(mContext).getBadgeDrawable(
1274 com.android.internal.R.drawable.ic_corp_icon_badge_case,
1275 getUserBadgeColor(user));
Kenny Guy02c89902016-11-15 19:36:38 +00001276 return getBadgedDrawable(icon, badge, null, true);
Svetoslavc7d62f02014-09-04 15:39:54 -07001277 }
1278
1279 @Override
1280 public Drawable getUserBadgedDrawableForDensity(Drawable drawable, UserHandle user,
1281 Rect badgeLocation, int badgeDensity) {
1282 Drawable badgeDrawable = getUserBadgeForDensity(user, badgeDensity);
1283 if (badgeDrawable == null) {
1284 return drawable;
1285 }
1286 return getBadgedDrawable(drawable, badgeDrawable, badgeLocation, true);
1287 }
1288
Kenny Guy02c89902016-11-15 19:36:38 +00001289 @VisibleForTesting
1290 public static final int[] CORP_BADGE_LABEL_RES_ID = new int[] {
1291 com.android.internal.R.string.managed_profile_label_badge,
1292 com.android.internal.R.string.managed_profile_label_badge_2,
1293 com.android.internal.R.string.managed_profile_label_badge_3
1294 };
1295
1296 private int getUserBadgeColor(UserHandle user) {
Sunny Goyalbab30752017-04-12 15:36:42 -07001297 return IconDrawableFactory.getUserBadgeColor(getUserManager(), user.getIdentifier());
Kenny Guy02c89902016-11-15 19:36:38 +00001298 }
1299
Svetoslavc7d62f02014-09-04 15:39:54 -07001300 @Override
1301 public Drawable getUserBadgeForDensity(UserHandle user, int density) {
Kenny Guy02c89902016-11-15 19:36:38 +00001302 Drawable badgeColor = getManagedProfileIconForDensity(user,
1303 com.android.internal.R.drawable.ic_corp_badge_color, density);
1304 if (badgeColor == null) {
1305 return null;
1306 }
1307 badgeColor.setTint(getUserBadgeColor(user));
1308 Drawable badgeForeground = getDrawableForDensity(
1309 com.android.internal.R.drawable.ic_corp_badge_case, density);
1310 Drawable badge = new LayerDrawable(
1311 new Drawable[] {badgeColor, badgeForeground });
1312 return badge;
Selim Cineke6ff9462016-01-15 15:07:06 -08001313 }
1314
1315 @Override
1316 public Drawable getUserBadgeForDensityNoBackground(UserHandle user, int density) {
Kenny Guy02c89902016-11-15 19:36:38 +00001317 Drawable badge = getManagedProfileIconForDensity(user,
Vadim Tryshev66ae66a2016-02-18 15:41:21 -08001318 com.android.internal.R.drawable.ic_corp_badge_no_background, density);
Kenny Guy02c89902016-11-15 19:36:38 +00001319 if (badge != null) {
1320 badge.setTint(getUserBadgeColor(user));
1321 }
1322 return badge;
Selim Cineke6ff9462016-01-15 15:07:06 -08001323 }
1324
Vadim Tryshev66ae66a2016-02-18 15:41:21 -08001325 private Drawable getDrawableForDensity(int drawableId, int density) {
1326 if (density <= 0) {
1327 density = mContext.getResources().getDisplayMetrics().densityDpi;
1328 }
1329 return Resources.getSystem().getDrawableForDensity(drawableId, density);
1330 }
1331
1332 private Drawable getManagedProfileIconForDensity(UserHandle user, int drawableId, int density) {
Tony Mak8673b282016-03-21 21:10:59 +00001333 if (isManagedProfile(user.getIdentifier())) {
Vadim Tryshev66ae66a2016-02-18 15:41:21 -08001334 return getDrawableForDensity(drawableId, density);
Svetoslavc7d62f02014-09-04 15:39:54 -07001335 }
1336 return null;
1337 }
1338
1339 @Override
1340 public CharSequence getUserBadgedLabel(CharSequence label, UserHandle user) {
Tony Mak8673b282016-03-21 21:10:59 +00001341 if (isManagedProfile(user.getIdentifier())) {
Kenny Guy02c89902016-11-15 19:36:38 +00001342 int badge = getUserManager().getManagedProfileBadge(user.getIdentifier());
1343 int resourceId = CORP_BADGE_LABEL_RES_ID[badge % CORP_BADGE_LABEL_RES_ID.length];
1344 return Resources.getSystem().getString(resourceId, label);
Svetoslavc7d62f02014-09-04 15:39:54 -07001345 }
1346 return label;
1347 }
1348
Alan Viveretteecd585a2015-04-13 10:32:51 -07001349 @Override
1350 public Resources getResourcesForActivity(ComponentName activityName)
1351 throws NameNotFoundException {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001352 return getResourcesForApplication(
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001353 getActivityInfo(activityName, sDefaultFlags).applicationInfo);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001354 }
1355
Alan Viveretteecd585a2015-04-13 10:32:51 -07001356 @Override
1357 public Resources getResourcesForApplication(@NonNull ApplicationInfo app)
1358 throws NameNotFoundException {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001359 if (app.packageName.equals("system")) {
Adam Lesinskia82b6262017-03-21 16:56:17 -07001360 return mContext.mMainThread.getSystemUiContext().getResources();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001361 }
Jeff Sharkey8a4c9722014-06-16 13:48:42 -07001362 final boolean sameUid = (app.uid == Process.myUid());
Adam Lesinski53fafdf2016-08-03 13:36:39 -07001363 final Resources r = mContext.mMainThread.getTopLevelResources(
Adam Lesinskic82f28a2016-06-08 17:19:09 -07001364 sameUid ? app.sourceDir : app.publicSourceDir,
1365 sameUid ? app.splitSourceDirs : app.splitPublicSourceDirs,
1366 app.resourceDirs, app.sharedLibraryFiles, Display.DEFAULT_DISPLAY,
1367 mContext.mPackageInfo);
Adam Lesinski53fafdf2016-08-03 13:36:39 -07001368 if (r != null) {
1369 return r;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001370 }
Adam Lesinski53fafdf2016-08-03 13:36:39 -07001371 throw new NameNotFoundException("Unable to open " + app.publicSourceDir);
1372
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001373 }
1374
Alan Viveretteecd585a2015-04-13 10:32:51 -07001375 @Override
1376 public Resources getResourcesForApplication(String appPackageName)
1377 throws NameNotFoundException {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001378 return getResourcesForApplication(
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001379 getApplicationInfo(appPackageName, sDefaultFlags));
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001380 }
1381
Amith Yamasani98edc952012-09-25 14:09:27 -07001382 /** @hide */
1383 @Override
1384 public Resources getResourcesForApplicationAsUser(String appPackageName, int userId)
1385 throws NameNotFoundException {
Jeff Sharkeyded653b2012-09-27 19:09:24 -07001386 if (userId < 0) {
1387 throw new IllegalArgumentException(
1388 "Call does not support special user #" + userId);
1389 }
1390 if ("system".equals(appPackageName)) {
Adam Lesinskia82b6262017-03-21 16:56:17 -07001391 return mContext.mMainThread.getSystemUiContext().getResources();
Jeff Sharkeyded653b2012-09-27 19:09:24 -07001392 }
Amith Yamasani98edc952012-09-25 14:09:27 -07001393 try {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001394 ApplicationInfo ai = mPM.getApplicationInfo(appPackageName, sDefaultFlags, userId);
Amith Yamasani98edc952012-09-25 14:09:27 -07001395 if (ai != null) {
1396 return getResourcesForApplication(ai);
1397 }
1398 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001399 throw e.rethrowFromSystemServer();
Amith Yamasani98edc952012-09-25 14:09:27 -07001400 }
1401 throw new NameNotFoundException("Package " + appPackageName + " doesn't exist");
1402 }
1403
Jeff Sharkeycd654482016-01-08 17:42:11 -07001404 volatile int mCachedSafeMode = -1;
1405
1406 @Override
1407 public boolean isSafeMode() {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001408 try {
1409 if (mCachedSafeMode < 0) {
1410 mCachedSafeMode = mPM.isSafeMode() ? 1 : 0;
1411 }
1412 return mCachedSafeMode != 0;
1413 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001414 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001415 }
1416 }
1417
Svetoslavf7c06eb2015-06-10 18:43:22 -07001418 @Override
1419 public void addOnPermissionsChangeListener(OnPermissionsChangedListener listener) {
1420 synchronized (mPermissionListeners) {
1421 if (mPermissionListeners.get(listener) != null) {
1422 return;
1423 }
1424 OnPermissionsChangeListenerDelegate delegate =
1425 new OnPermissionsChangeListenerDelegate(listener, Looper.getMainLooper());
1426 try {
1427 mPM.addOnPermissionsChangeListener(delegate);
1428 mPermissionListeners.put(listener, delegate);
1429 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001430 throw e.rethrowFromSystemServer();
Svetoslavf7c06eb2015-06-10 18:43:22 -07001431 }
1432 }
1433 }
1434
1435 @Override
1436 public void removeOnPermissionsChangeListener(OnPermissionsChangedListener listener) {
1437 synchronized (mPermissionListeners) {
1438 IOnPermissionsChangeListener delegate = mPermissionListeners.get(listener);
1439 if (delegate != null) {
1440 try {
1441 mPM.removeOnPermissionsChangeListener(delegate);
1442 mPermissionListeners.remove(listener);
1443 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001444 throw e.rethrowFromSystemServer();
Svetoslavf7c06eb2015-06-10 18:43:22 -07001445 }
1446 }
1447 }
1448 }
1449
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001450 static void configurationChanged() {
1451 synchronized (sSync) {
1452 sIconCache.clear();
1453 sStringCache.clear();
1454 }
1455 }
1456
Yao Chen022b8ea2016-12-16 11:03:28 -08001457 protected ApplicationPackageManager(ContextImpl context,
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001458 IPackageManager pm) {
1459 mContext = context;
1460 mPM = pm;
1461 }
1462
Alan Viveretteecd585a2015-04-13 10:32:51 -07001463 @Nullable
1464 private Drawable getCachedIcon(@NonNull ResourceName name) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001465 synchronized (sSync) {
Alan Viveretteecd585a2015-04-13 10:32:51 -07001466 final WeakReference<Drawable.ConstantState> wr = sIconCache.get(name);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001467 if (DEBUG_ICONS) Log.v(TAG, "Get cached weak drawable ref for "
1468 + name + ": " + wr);
1469 if (wr != null) { // we have the activity
Alan Viveretteecd585a2015-04-13 10:32:51 -07001470 final Drawable.ConstantState state = wr.get();
Romain Guy39fe17c2011-11-30 10:34:07 -08001471 if (state != null) {
1472 if (DEBUG_ICONS) {
1473 Log.v(TAG, "Get cached drawable state for " + name + ": " + state);
1474 }
1475 // Note: It's okay here to not use the newDrawable(Resources) variant
1476 // of the API. The ConstantState comes from a drawable that was
1477 // originally created by passing the proper app Resources instance
1478 // which means the state should already contain the proper
1479 // resources specific information (like density.) See
1480 // BitmapDrawable.BitmapState for instance.
1481 return state.newDrawable();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001482 }
1483 // our entry has been purged
1484 sIconCache.remove(name);
1485 }
1486 }
1487 return null;
1488 }
1489
Alan Viveretteecd585a2015-04-13 10:32:51 -07001490 private void putCachedIcon(@NonNull ResourceName name, @NonNull Drawable dr) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001491 synchronized (sSync) {
Alan Viveretteecd585a2015-04-13 10:32:51 -07001492 sIconCache.put(name, new WeakReference<>(dr.getConstantState()));
Romain Guy39fe17c2011-11-30 10:34:07 -08001493 if (DEBUG_ICONS) Log.v(TAG, "Added cached drawable state for " + name + ": " + dr);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001494 }
1495 }
1496
Romain Guy39fe17c2011-11-30 10:34:07 -08001497 static void handlePackageBroadcast(int cmd, String[] pkgList, boolean hasPkgInfo) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001498 boolean immediateGc = false;
Sudheer Shankacc6418f2016-10-13 12:03:44 -07001499 if (cmd == ApplicationThreadConstants.EXTERNAL_STORAGE_UNAVAILABLE) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001500 immediateGc = true;
1501 }
1502 if (pkgList != null && (pkgList.length > 0)) {
1503 boolean needCleanup = false;
1504 for (String ssp : pkgList) {
1505 synchronized (sSync) {
Dianne Hackbornadd005c2013-07-17 18:43:12 -07001506 for (int i=sIconCache.size()-1; i>=0; i--) {
1507 ResourceName nm = sIconCache.keyAt(i);
1508 if (nm.packageName.equals(ssp)) {
1509 //Log.i(TAG, "Removing cached drawable for " + nm);
1510 sIconCache.removeAt(i);
1511 needCleanup = true;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001512 }
1513 }
Dianne Hackbornadd005c2013-07-17 18:43:12 -07001514 for (int i=sStringCache.size()-1; i>=0; i--) {
1515 ResourceName nm = sStringCache.keyAt(i);
1516 if (nm.packageName.equals(ssp)) {
1517 //Log.i(TAG, "Removing cached string for " + nm);
1518 sStringCache.removeAt(i);
1519 needCleanup = true;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001520 }
1521 }
1522 }
1523 }
1524 if (needCleanup || hasPkgInfo) {
1525 if (immediateGc) {
1526 // Schedule an immediate gc.
1527 Runtime.getRuntime().gc();
1528 } else {
1529 ActivityThread.currentActivityThread().scheduleGcIdler();
1530 }
1531 }
1532 }
1533 }
1534
1535 private static final class ResourceName {
1536 final String packageName;
1537 final int iconId;
1538
1539 ResourceName(String _packageName, int _iconId) {
1540 packageName = _packageName;
1541 iconId = _iconId;
1542 }
1543
1544 ResourceName(ApplicationInfo aInfo, int _iconId) {
1545 this(aInfo.packageName, _iconId);
1546 }
1547
1548 ResourceName(ComponentInfo cInfo, int _iconId) {
1549 this(cInfo.applicationInfo.packageName, _iconId);
1550 }
1551
1552 ResourceName(ResolveInfo rInfo, int _iconId) {
1553 this(rInfo.activityInfo.applicationInfo.packageName, _iconId);
1554 }
1555
1556 @Override
1557 public boolean equals(Object o) {
1558 if (this == o) return true;
1559 if (o == null || getClass() != o.getClass()) return false;
1560
1561 ResourceName that = (ResourceName) o;
1562
1563 if (iconId != that.iconId) return false;
1564 return !(packageName != null ?
1565 !packageName.equals(that.packageName) : that.packageName != null);
1566
1567 }
1568
1569 @Override
1570 public int hashCode() {
1571 int result;
1572 result = packageName.hashCode();
1573 result = 31 * result + iconId;
1574 return result;
1575 }
1576
1577 @Override
1578 public String toString() {
1579 return "{ResourceName " + packageName + " / " + iconId + "}";
1580 }
1581 }
1582
1583 private CharSequence getCachedString(ResourceName name) {
1584 synchronized (sSync) {
1585 WeakReference<CharSequence> wr = sStringCache.get(name);
1586 if (wr != null) { // we have the activity
1587 CharSequence cs = wr.get();
1588 if (cs != null) {
1589 return cs;
1590 }
1591 // our entry has been purged
1592 sStringCache.remove(name);
1593 }
1594 }
1595 return null;
1596 }
1597
1598 private void putCachedString(ResourceName name, CharSequence cs) {
1599 synchronized (sSync) {
1600 sStringCache.put(name, new WeakReference<CharSequence>(cs));
1601 }
1602 }
1603
1604 @Override
Tor Norbye7b9c9122013-05-30 16:48:33 -07001605 public CharSequence getText(String packageName, @StringRes int resid,
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001606 ApplicationInfo appInfo) {
1607 ResourceName name = new ResourceName(packageName, resid);
1608 CharSequence text = getCachedString(name);
1609 if (text != null) {
1610 return text;
1611 }
1612 if (appInfo == null) {
1613 try {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001614 appInfo = getApplicationInfo(packageName, sDefaultFlags);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001615 } catch (NameNotFoundException e) {
1616 return null;
1617 }
1618 }
1619 try {
1620 Resources r = getResourcesForApplication(appInfo);
1621 text = r.getText(resid);
1622 putCachedString(name, text);
1623 return text;
1624 } catch (NameNotFoundException e) {
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07001625 Log.w("PackageManager", "Failure retrieving resources for "
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001626 + appInfo.packageName);
1627 } catch (RuntimeException e) {
1628 // If an exception was thrown, fall through to return
1629 // default icon.
1630 Log.w("PackageManager", "Failure retrieving text 0x"
1631 + Integer.toHexString(resid) + " in package "
1632 + packageName, e);
1633 }
1634 return null;
1635 }
1636
1637 @Override
Tor Norbye7b9c9122013-05-30 16:48:33 -07001638 public XmlResourceParser getXml(String packageName, @XmlRes int resid,
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001639 ApplicationInfo appInfo) {
1640 if (appInfo == null) {
1641 try {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001642 appInfo = getApplicationInfo(packageName, sDefaultFlags);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001643 } catch (NameNotFoundException e) {
1644 return null;
1645 }
1646 }
1647 try {
1648 Resources r = getResourcesForApplication(appInfo);
1649 return r.getXml(resid);
1650 } catch (RuntimeException e) {
1651 // If an exception was thrown, fall through to return
1652 // default icon.
1653 Log.w("PackageManager", "Failure retrieving xml 0x"
1654 + Integer.toHexString(resid) + " in package "
1655 + packageName, e);
1656 } catch (NameNotFoundException e) {
Alon Albert3fa51e32010-11-11 09:24:04 -08001657 Log.w("PackageManager", "Failure retrieving resources for "
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001658 + appInfo.packageName);
1659 }
1660 return null;
1661 }
1662
1663 @Override
1664 public CharSequence getApplicationLabel(ApplicationInfo info) {
1665 return info.loadLabel(this);
1666 }
1667
1668 @Override
1669 public void installPackage(Uri packageURI, IPackageInstallObserver observer, int flags,
1670 String installerPackageName) {
Jeff Sharkey513a0742014-07-08 17:10:32 -07001671 installCommon(packageURI, new LegacyPackageInstallObserver(observer), flags,
Todd Kennedya6793232016-02-24 22:46:00 +00001672 installerPackageName, mContext.getUserId());
Christopher Tatef1977b42014-03-24 16:25:51 -07001673 }
1674
Christopher Tatef1977b42014-03-24 16:25:51 -07001675 @Override
1676 public void installPackage(Uri packageURI, PackageInstallObserver observer,
1677 int flags, String installerPackageName) {
Todd Kennedya6793232016-02-24 22:46:00 +00001678 installCommon(packageURI, observer, flags, installerPackageName, mContext.getUserId());
Jeff Sharkey513a0742014-07-08 17:10:32 -07001679 }
1680
1681 private void installCommon(Uri packageURI,
1682 PackageInstallObserver observer, int flags, String installerPackageName,
Nicolas Prevot9a80e532015-09-23 15:49:28 +01001683 int userId) {
Jeff Sharkey513a0742014-07-08 17:10:32 -07001684 if (!"file".equals(packageURI.getScheme())) {
1685 throw new UnsupportedOperationException("Only file:// URIs are supported");
1686 }
Jeff Sharkey513a0742014-07-08 17:10:32 -07001687
1688 final String originPath = packageURI.getPath();
Christopher Tatef1977b42014-03-24 16:25:51 -07001689 try {
Nicolas Prevot9a80e532015-09-23 15:49:28 +01001690 mPM.installPackageAsUser(originPath, observer.getBinder(), flags, installerPackageName,
Todd Kennedya6793232016-02-24 22:46:00 +00001691 userId);
Jeff Sharkey27b2e692016-02-25 17:40:12 -07001692 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001693 throw e.rethrowFromSystemServer();
rich cannings706e8ba2012-08-20 13:20:14 -07001694 }
1695 }
1696
1697 @Override
Nicolas Prevot9a80e532015-09-23 15:49:28 +01001698 public int installExistingPackage(String packageName) throws NameNotFoundException {
Sunny Goyala31a74b2017-05-11 15:59:19 -07001699 return installExistingPackage(packageName, PackageManager.INSTALL_REASON_UNKNOWN);
1700 }
1701
1702 @Override
1703 public int installExistingPackage(String packageName, int installReason)
1704 throws NameNotFoundException {
1705 return installExistingPackageAsUser(packageName, installReason, mContext.getUserId());
Nicolas Prevot9a80e532015-09-23 15:49:28 +01001706 }
1707
1708 @Override
1709 public int installExistingPackageAsUser(String packageName, int userId)
Dianne Hackborn7767eac2012-08-23 18:25:40 -07001710 throws NameNotFoundException {
Sunny Goyala31a74b2017-05-11 15:59:19 -07001711 return installExistingPackageAsUser(packageName, PackageManager.INSTALL_REASON_UNKNOWN,
1712 userId);
1713 }
1714
1715 private int installExistingPackageAsUser(String packageName, int installReason, int userId)
1716 throws NameNotFoundException {
Dianne Hackborn7767eac2012-08-23 18:25:40 -07001717 try {
Todd Kennedybe0b8892017-02-15 14:13:52 -08001718 int res = mPM.installExistingPackageAsUser(packageName, userId, 0 /*installFlags*/,
Sunny Goyala31a74b2017-05-11 15:59:19 -07001719 installReason);
Dianne Hackborn7767eac2012-08-23 18:25:40 -07001720 if (res == INSTALL_FAILED_INVALID_URI) {
1721 throw new NameNotFoundException("Package " + packageName + " doesn't exist");
1722 }
1723 return res;
1724 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001725 throw e.rethrowFromSystemServer();
Dianne Hackborn7767eac2012-08-23 18:25:40 -07001726 }
1727 }
1728
1729 @Override
Kenny Root3a9b5fb2011-09-20 14:15:38 -07001730 public void verifyPendingInstall(int id, int response) {
Kenny Root5ab21572011-07-27 11:11:19 -07001731 try {
Kenny Root3a9b5fb2011-09-20 14:15:38 -07001732 mPM.verifyPendingInstall(id, response);
Kenny Root5ab21572011-07-27 11:11:19 -07001733 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001734 throw e.rethrowFromSystemServer();
Kenny Root5ab21572011-07-27 11:11:19 -07001735 }
1736 }
1737
1738 @Override
rich canningsd9ef3e52012-08-22 14:28:05 -07001739 public void extendVerificationTimeout(int id, int verificationCodeAtTimeout,
1740 long millisecondsToDelay) {
1741 try {
1742 mPM.extendVerificationTimeout(id, verificationCodeAtTimeout, millisecondsToDelay);
1743 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001744 throw e.rethrowFromSystemServer();
rich canningsd9ef3e52012-08-22 14:28:05 -07001745 }
1746 }
1747
1748 @Override
Todd Kennedydfa93ab2016-03-03 15:24:33 -08001749 public void verifyIntentFilter(int id, int verificationCode, List<String> failedDomains) {
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001750 try {
Todd Kennedydfa93ab2016-03-03 15:24:33 -08001751 mPM.verifyIntentFilter(id, verificationCode, failedDomains);
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001752 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001753 throw e.rethrowFromSystemServer();
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001754 }
1755 }
1756
1757 @Override
Jeff Sharkeye06b4d12016-01-06 14:51:50 -07001758 public int getIntentVerificationStatusAsUser(String packageName, int userId) {
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001759 try {
1760 return mPM.getIntentVerificationStatus(packageName, userId);
1761 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001762 throw e.rethrowFromSystemServer();
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001763 }
1764 }
1765
1766 @Override
Jeff Sharkeye06b4d12016-01-06 14:51:50 -07001767 public boolean updateIntentVerificationStatusAsUser(String packageName, int status, int userId) {
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001768 try {
1769 return mPM.updateIntentVerificationStatus(packageName, status, userId);
1770 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001771 throw e.rethrowFromSystemServer();
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001772 }
1773 }
1774
1775 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001776 @SuppressWarnings("unchecked")
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001777 public List<IntentFilterVerificationInfo> getIntentFilterVerifications(String packageName) {
1778 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001779 ParceledListSlice<IntentFilterVerificationInfo> parceledList =
1780 mPM.getIntentFilterVerifications(packageName);
1781 if (parceledList == null) {
1782 return Collections.emptyList();
1783 }
1784 return parceledList.getList();
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001785 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001786 throw e.rethrowFromSystemServer();
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001787 }
1788 }
1789
1790 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001791 @SuppressWarnings("unchecked")
Fabrice Di Meglio07885952015-04-06 19:41:28 -07001792 public List<IntentFilter> getAllIntentFilters(String packageName) {
1793 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001794 ParceledListSlice<IntentFilter> parceledList =
1795 mPM.getAllIntentFilters(packageName);
1796 if (parceledList == null) {
1797 return Collections.emptyList();
1798 }
1799 return parceledList.getList();
Fabrice Di Meglio07885952015-04-06 19:41:28 -07001800 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001801 throw e.rethrowFromSystemServer();
Fabrice Di Meglio07885952015-04-06 19:41:28 -07001802 }
1803 }
1804
1805 @Override
Jeff Sharkeye06b4d12016-01-06 14:51:50 -07001806 public String getDefaultBrowserPackageNameAsUser(int userId) {
Fabrice Di Meglio62271722015-04-10 17:24:02 -07001807 try {
1808 return mPM.getDefaultBrowserPackageName(userId);
1809 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001810 throw e.rethrowFromSystemServer();
Fabrice Di Meglio62271722015-04-10 17:24:02 -07001811 }
1812 }
1813
1814 @Override
Jeff Sharkeye06b4d12016-01-06 14:51:50 -07001815 public boolean setDefaultBrowserPackageNameAsUser(String packageName, int userId) {
Fabrice Di Meglio62271722015-04-10 17:24:02 -07001816 try {
1817 return mPM.setDefaultBrowserPackageName(packageName, userId);
1818 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001819 throw e.rethrowFromSystemServer();
Fabrice Di Meglio62271722015-04-10 17:24:02 -07001820 }
1821 }
1822
1823 @Override
Dianne Hackborn880119b2010-11-18 22:26:40 -08001824 public void setInstallerPackageName(String targetPackage,
1825 String installerPackageName) {
1826 try {
1827 mPM.setInstallerPackageName(targetPackage, installerPackageName);
1828 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001829 throw e.rethrowFromSystemServer();
Dianne Hackborn880119b2010-11-18 22:26:40 -08001830 }
1831 }
1832
1833 @Override
Todd Kennedyab532892017-03-08 14:19:49 -08001834 public void setUpdateAvailable(String packageName, boolean updateAvailable) {
1835 try {
1836 mPM.setUpdateAvailable(packageName, updateAvailable);
1837 } catch (RemoteException e) {
1838 throw e.rethrowFromSystemServer();
1839 }
1840 }
1841
1842 @Override
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001843 public String getInstallerPackageName(String packageName) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001844 try {
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001845 return mPM.getInstallerPackageName(packageName);
1846 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001847 throw e.rethrowFromSystemServer();
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001848 }
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001849 }
1850
1851 @Override
1852 public int getMoveStatus(int moveId) {
1853 try {
1854 return mPM.getMoveStatus(moveId);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001855 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001856 throw e.rethrowFromSystemServer();
Jeff Sharkeyb2b9ab82015-04-05 21:10:42 -07001857 }
1858 }
1859
1860 @Override
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001861 public void registerMoveCallback(MoveCallback callback, Handler handler) {
1862 synchronized (mDelegates) {
1863 final MoveCallbackDelegate delegate = new MoveCallbackDelegate(callback,
1864 handler.getLooper());
1865 try {
1866 mPM.registerMoveCallback(delegate);
1867 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001868 throw e.rethrowFromSystemServer();
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001869 }
1870 mDelegates.add(delegate);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001871 }
1872 }
1873
1874 @Override
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001875 public void unregisterMoveCallback(MoveCallback callback) {
1876 synchronized (mDelegates) {
1877 for (Iterator<MoveCallbackDelegate> i = mDelegates.iterator(); i.hasNext();) {
1878 final MoveCallbackDelegate delegate = i.next();
1879 if (delegate.mCallback == callback) {
1880 try {
1881 mPM.unregisterMoveCallback(delegate);
1882 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001883 throw e.rethrowFromSystemServer();
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001884 }
1885 i.remove();
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001886 }
1887 }
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001888 }
1889 }
1890
1891 @Override
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001892 public int movePackage(String packageName, VolumeInfo vol) {
1893 try {
1894 final String volumeUuid;
1895 if (VolumeInfo.ID_PRIVATE_INTERNAL.equals(vol.id)) {
1896 volumeUuid = StorageManager.UUID_PRIVATE_INTERNAL;
1897 } else if (vol.isPrimaryPhysical()) {
1898 volumeUuid = StorageManager.UUID_PRIMARY_PHYSICAL;
1899 } else {
1900 volumeUuid = Preconditions.checkNotNull(vol.fsUuid);
1901 }
1902
1903 return mPM.movePackage(packageName, volumeUuid);
1904 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001905 throw e.rethrowFromSystemServer();
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001906 }
1907 }
1908
1909 @Override
1910 public @Nullable VolumeInfo getPackageCurrentVolume(ApplicationInfo app) {
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001911 final StorageManager storage = mContext.getSystemService(StorageManager.class);
Yao Chen022b8ea2016-12-16 11:03:28 -08001912 return getPackageCurrentVolume(app, storage);
1913 }
1914
1915 @VisibleForTesting
1916 protected @Nullable VolumeInfo getPackageCurrentVolume(ApplicationInfo app,
1917 StorageManager storage) {
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001918 if (app.isInternal()) {
1919 return storage.findVolumeById(VolumeInfo.ID_PRIVATE_INTERNAL);
1920 } else if (app.isExternalAsec()) {
1921 return storage.getPrimaryPhysicalVolume();
1922 } else {
1923 return storage.findVolumeByUuid(app.volumeUuid);
1924 }
1925 }
1926
1927 @Override
1928 public @NonNull List<VolumeInfo> getPackageCandidateVolumes(ApplicationInfo app) {
Yao Chen022b8ea2016-12-16 11:03:28 -08001929 final StorageManager storageManager = mContext.getSystemService(StorageManager.class);
1930 return getPackageCandidateVolumes(app, storageManager, mPM);
1931 }
1932
1933 @VisibleForTesting
1934 protected @NonNull List<VolumeInfo> getPackageCandidateVolumes(ApplicationInfo app,
1935 StorageManager storageManager, IPackageManager pm) {
1936 final VolumeInfo currentVol = getPackageCurrentVolume(app, storageManager);
1937 final List<VolumeInfo> vols = storageManager.getVolumes();
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001938 final List<VolumeInfo> candidates = new ArrayList<>();
1939 for (VolumeInfo vol : vols) {
Yao Chen022b8ea2016-12-16 11:03:28 -08001940 if (Objects.equals(vol, currentVol)
1941 || isPackageCandidateVolume(mContext, app, vol, pm)) {
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001942 candidates.add(vol);
1943 }
1944 }
1945 return candidates;
1946 }
1947
Yao Chen022b8ea2016-12-16 11:03:28 -08001948 @VisibleForTesting
1949 protected boolean isForceAllowOnExternal(Context context) {
1950 return Settings.Global.getInt(
Todd Kennedyf39ca8f2015-08-07 14:15:07 -07001951 context.getContentResolver(), Settings.Global.FORCE_ALLOW_ON_EXTERNAL, 0) != 0;
Yao Chen022b8ea2016-12-16 11:03:28 -08001952 }
1953
1954 @VisibleForTesting
1955 protected boolean isAllow3rdPartyOnInternal(Context context) {
1956 return context.getResources().getBoolean(
1957 com.android.internal.R.bool.config_allow3rdPartyAppOnInternal);
1958 }
1959
1960 private boolean isPackageCandidateVolume(
1961 ContextImpl context, ApplicationInfo app, VolumeInfo vol, IPackageManager pm) {
1962 final boolean forceAllowOnExternal = isForceAllowOnExternal(context);
1963
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001964 if (VolumeInfo.ID_PRIVATE_INTERNAL.equals(vol.getId())) {
Yao Chen022b8ea2016-12-16 11:03:28 -08001965 return app.isSystemApp() || isAllow3rdPartyOnInternal(context);
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001966 }
1967
1968 // System apps and apps demanding internal storage can't be moved
1969 // anywhere else
Todd Kennedyf39ca8f2015-08-07 14:15:07 -07001970 if (app.isSystemApp()) {
1971 return false;
1972 }
1973 if (!forceAllowOnExternal
Dianne Hackborn30a4e6d2015-10-12 17:14:56 -07001974 && (app.installLocation == PackageInfo.INSTALL_LOCATION_INTERNAL_ONLY
1975 || app.installLocation == PackageInfo.INSTALL_LOCATION_UNSPECIFIED)) {
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001976 return false;
1977 }
1978
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001979 // Gotta be able to write there
1980 if (!vol.isMountedWritable()) {
1981 return false;
1982 }
1983
1984 // Moving into an ASEC on public primary is only option internal
1985 if (vol.isPrimaryPhysical()) {
1986 return app.isInternal();
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001987 }
1988
Makoto Onukif34db0a2016-02-17 11:17:15 -08001989 // Some apps can't be moved. (e.g. device admins)
1990 try {
Yao Chen022b8ea2016-12-16 11:03:28 -08001991 if (pm.isPackageDeviceAdminOnAnyUser(app.packageName)) {
Makoto Onukif34db0a2016-02-17 11:17:15 -08001992 return false;
1993 }
1994 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001995 throw e.rethrowFromSystemServer();
Makoto Onukif34db0a2016-02-17 11:17:15 -08001996 }
1997
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001998 // Otherwise we can move to any private volume
1999 return (vol.getType() == VolumeInfo.TYPE_PRIVATE);
2000 }
2001
2002 @Override
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002003 public int movePrimaryStorage(VolumeInfo vol) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002004 try {
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002005 final String volumeUuid;
2006 if (VolumeInfo.ID_PRIVATE_INTERNAL.equals(vol.id)) {
2007 volumeUuid = StorageManager.UUID_PRIVATE_INTERNAL;
2008 } else if (vol.isPrimaryPhysical()) {
2009 volumeUuid = StorageManager.UUID_PRIMARY_PHYSICAL;
2010 } else {
2011 volumeUuid = Preconditions.checkNotNull(vol.fsUuid);
2012 }
2013
2014 return mPM.movePrimaryStorage(volumeUuid);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002015 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002016 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002017 }
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002018 }
2019
Jeff Sharkey275e3e42015-04-24 16:10:32 -07002020 @Override
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002021 public @Nullable VolumeInfo getPrimaryStorageCurrentVolume() {
2022 final StorageManager storage = mContext.getSystemService(StorageManager.class);
2023 final String volumeUuid = storage.getPrimaryStorageUuid();
Jeff Sharkey50a05452015-04-29 11:24:52 -07002024 return storage.findVolumeByQualifiedUuid(volumeUuid);
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002025 }
2026
Jeff Sharkey275e3e42015-04-24 16:10:32 -07002027 @Override
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002028 public @NonNull List<VolumeInfo> getPrimaryStorageCandidateVolumes() {
2029 final StorageManager storage = mContext.getSystemService(StorageManager.class);
2030 final VolumeInfo currentVol = getPrimaryStorageCurrentVolume();
2031 final List<VolumeInfo> vols = storage.getVolumes();
2032 final List<VolumeInfo> candidates = new ArrayList<>();
Jeff Sharkeyfced5342015-05-10 14:53:34 -07002033 if (Objects.equals(StorageManager.UUID_PRIMARY_PHYSICAL,
2034 storage.getPrimaryStorageUuid()) && currentVol != null) {
2035 // TODO: support moving primary physical to emulated volume
2036 candidates.add(currentVol);
2037 } else {
2038 for (VolumeInfo vol : vols) {
2039 if (Objects.equals(vol, currentVol) || isPrimaryStorageCandidateVolume(vol)) {
2040 candidates.add(vol);
2041 }
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002042 }
2043 }
2044 return candidates;
2045 }
2046
2047 private static boolean isPrimaryStorageCandidateVolume(VolumeInfo vol) {
2048 // Private internal is always an option
2049 if (VolumeInfo.ID_PRIVATE_INTERNAL.equals(vol.getId())) {
2050 return true;
2051 }
2052
2053 // Gotta be able to write there
2054 if (!vol.isMountedWritable()) {
2055 return false;
2056 }
2057
Jeff Sharkeyfced5342015-05-10 14:53:34 -07002058 // We can move to any private volume
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002059 return (vol.getType() == VolumeInfo.TYPE_PRIVATE);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002060 }
2061
2062 @Override
2063 public void deletePackage(String packageName, IPackageDeleteObserver observer, int flags) {
Robin Lee0e27c872015-09-28 14:37:40 +01002064 deletePackageAsUser(packageName, observer, flags, mContext.getUserId());
Nicolas Prevot9a80e532015-09-23 15:49:28 +01002065 }
2066
2067 @Override
Svet Ganov67882122016-12-11 16:36:34 -08002068 public void deletePackageAsUser(String packageName, IPackageDeleteObserver observer,
2069 int flags, int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002070 try {
Svet Ganov67882122016-12-11 16:36:34 -08002071 mPM.deletePackageAsUser(packageName, PackageManager.VERSION_CODE_HIGHEST,
2072 observer, userId, flags);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002073 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002074 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002075 }
2076 }
Jeff Sharkeyfbd0e9f2014-08-06 16:34:34 -07002077
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002078 @Override
2079 public void clearApplicationUserData(String packageName,
2080 IPackageDataObserver observer) {
2081 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -07002082 mPM.clearApplicationUserData(packageName, observer, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002083 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002084 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002085 }
2086 }
2087 @Override
2088 public void deleteApplicationCacheFiles(String packageName,
2089 IPackageDataObserver observer) {
2090 try {
2091 mPM.deleteApplicationCacheFiles(packageName, observer);
2092 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002093 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002094 }
2095 }
Jeff Sharkey529f91f2015-04-18 20:23:13 -07002096
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002097 @Override
Suprabh Shukla78c9eb82016-04-12 15:51:35 -07002098 public void deleteApplicationCacheFilesAsUser(String packageName, int userId,
2099 IPackageDataObserver observer) {
2100 try {
2101 mPM.deleteApplicationCacheFilesAsUser(packageName, userId, observer);
2102 } catch (RemoteException e) {
2103 throw e.rethrowFromSystemServer();
2104 }
2105 }
2106
2107 @Override
Jeff Sharkey529f91f2015-04-18 20:23:13 -07002108 public void freeStorageAndNotify(String volumeUuid, long idealStorageSize,
2109 IPackageDataObserver observer) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002110 try {
Jeff Sharkey529f91f2015-04-18 20:23:13 -07002111 mPM.freeStorageAndNotify(volumeUuid, idealStorageSize, observer);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002112 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002113 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002114 }
2115 }
2116
2117 @Override
Jeff Sharkey529f91f2015-04-18 20:23:13 -07002118 public void freeStorage(String volumeUuid, long freeStorageSize, IntentSender pi) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002119 try {
Jeff Sharkey529f91f2015-04-18 20:23:13 -07002120 mPM.freeStorage(volumeUuid, freeStorageSize, pi);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002121 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002122 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002123 }
2124 }
2125
2126 @Override
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00002127 public String[] setPackagesSuspendedAsUser(String[] packageNames, boolean suspended,
2128 int userId) {
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00002129 try {
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00002130 return mPM.setPackagesSuspendedAsUser(packageNames, suspended, userId);
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00002131 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002132 throw e.rethrowFromSystemServer();
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00002133 }
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00002134 }
2135
2136 @Override
Andrei Stingaceanu355b2322016-02-12 16:43:51 +00002137 public boolean isPackageSuspendedForUser(String packageName, int userId) {
2138 try {
2139 return mPM.isPackageSuspendedForUser(packageName, userId);
2140 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002141 throw e.rethrowFromSystemServer();
Andrei Stingaceanu355b2322016-02-12 16:43:51 +00002142 }
Andrei Stingaceanu355b2322016-02-12 16:43:51 +00002143 }
2144
Jeff Sharkey9bc89af2017-01-11 11:25:50 -07002145 /** @hide */
2146 @Override
2147 public void setApplicationCategoryHint(String packageName, int categoryHint) {
2148 try {
2149 mPM.setApplicationCategoryHint(packageName, categoryHint,
2150 mContext.getOpPackageName());
2151 } catch (RemoteException e) {
2152 throw e.rethrowFromSystemServer();
2153 }
2154 }
2155
Andrei Stingaceanu355b2322016-02-12 16:43:51 +00002156 @Override
Jeff Sharkeye06b4d12016-01-06 14:51:50 -07002157 public void getPackageSizeInfoAsUser(String packageName, int userHandle,
Dianne Hackborn0c380492012-08-20 17:23:30 -07002158 IPackageStatsObserver observer) {
Jeff Sharkey6f4b2a32017-03-21 14:13:41 -06002159 final String msg = "Shame on you for calling the hidden API "
2160 + "getPackageSizeInfoAsUser(). Shame!";
Jeff Sharkeye6306c42017-03-07 21:03:18 -07002161 if (mContext.getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.O) {
Jeff Sharkey6f4b2a32017-03-21 14:13:41 -06002162 throw new UnsupportedOperationException(msg);
Jeff Sharkeye6306c42017-03-07 21:03:18 -07002163 } else if (observer != null) {
Jeff Sharkey6f4b2a32017-03-21 14:13:41 -06002164 Log.d(TAG, msg);
Jeff Sharkeye6306c42017-03-07 21:03:18 -07002165 try {
2166 observer.onGetStatsCompleted(null, false);
2167 } catch (RemoteException ignored) {
2168 }
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002169 }
2170 }
Jeff Sharkeyd5896632016-03-04 16:16:00 -07002171
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002172 @Override
2173 public void addPackageToPreferred(String packageName) {
Jeff Sharkeyd5896632016-03-04 16:16:00 -07002174 Log.w(TAG, "addPackageToPreferred() is a no-op");
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002175 }
2176
2177 @Override
2178 public void removePackageFromPreferred(String packageName) {
Jeff Sharkeyd5896632016-03-04 16:16:00 -07002179 Log.w(TAG, "removePackageFromPreferred() is a no-op");
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002180 }
2181
2182 @Override
2183 public List<PackageInfo> getPreferredPackages(int flags) {
Jeff Sharkeyd5896632016-03-04 16:16:00 -07002184 Log.w(TAG, "getPreferredPackages() is a no-op");
2185 return Collections.emptyList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002186 }
2187
2188 @Override
2189 public void addPreferredActivity(IntentFilter filter,
2190 int match, ComponentName[] set, ComponentName activity) {
2191 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -07002192 mPM.addPreferredActivity(filter, match, set, activity, mContext.getUserId());
Amith Yamasania3f133a2012-08-09 17:11:28 -07002193 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002194 throw e.rethrowFromSystemServer();
Amith Yamasania3f133a2012-08-09 17:11:28 -07002195 }
2196 }
2197
2198 @Override
Jeff Sharkeye06b4d12016-01-06 14:51:50 -07002199 public void addPreferredActivityAsUser(IntentFilter filter, int match,
Amith Yamasania3f133a2012-08-09 17:11:28 -07002200 ComponentName[] set, ComponentName activity, int userId) {
2201 try {
2202 mPM.addPreferredActivity(filter, match, set, activity, userId);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002203 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002204 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002205 }
2206 }
2207
2208 @Override
2209 public void replacePreferredActivity(IntentFilter filter,
2210 int match, ComponentName[] set, ComponentName activity) {
2211 try {
Robin Lee0e27c872015-09-28 14:37:40 +01002212 mPM.replacePreferredActivity(filter, match, set, activity, mContext.getUserId());
Amith Yamasani41c1ded2014-08-05 11:15:05 -07002213 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002214 throw e.rethrowFromSystemServer();
Amith Yamasani41c1ded2014-08-05 11:15:05 -07002215 }
2216 }
2217
2218 @Override
2219 public void replacePreferredActivityAsUser(IntentFilter filter,
2220 int match, ComponentName[] set, ComponentName activity,
2221 int userId) {
2222 try {
2223 mPM.replacePreferredActivity(filter, match, set, activity, userId);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002224 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002225 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002226 }
2227 }
2228
2229 @Override
2230 public void clearPackagePreferredActivities(String packageName) {
2231 try {
2232 mPM.clearPackagePreferredActivities(packageName);
2233 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002234 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002235 }
2236 }
2237
2238 @Override
2239 public int getPreferredActivities(List<IntentFilter> outFilters,
2240 List<ComponentName> outActivities, String packageName) {
2241 try {
2242 return mPM.getPreferredActivities(outFilters, outActivities, packageName);
2243 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002244 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002245 }
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002246 }
2247
2248 @Override
Christopher Tatea2a0850d2013-09-05 16:38:58 -07002249 public ComponentName getHomeActivities(List<ResolveInfo> outActivities) {
2250 try {
2251 return mPM.getHomeActivities(outActivities);
2252 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002253 throw e.rethrowFromSystemServer();
Christopher Tatea2a0850d2013-09-05 16:38:58 -07002254 }
Christopher Tatea2a0850d2013-09-05 16:38:58 -07002255 }
2256
2257 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002258 public void setComponentEnabledSetting(ComponentName componentName,
2259 int newState, int flags) {
2260 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -07002261 mPM.setComponentEnabledSetting(componentName, newState, flags, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002262 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002263 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002264 }
2265 }
2266
2267 @Override
2268 public int getComponentEnabledSetting(ComponentName componentName) {
2269 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -07002270 return mPM.getComponentEnabledSetting(componentName, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002271 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002272 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002273 }
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002274 }
2275
2276 @Override
2277 public void setApplicationEnabledSetting(String packageName,
2278 int newState, int flags) {
2279 try {
Dianne Hackborn3fa3c28a2013-03-26 16:15:41 -07002280 mPM.setApplicationEnabledSetting(packageName, newState, flags,
Dianne Hackborn95d78532013-09-11 09:51:14 -07002281 mContext.getUserId(), mContext.getOpPackageName());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002282 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002283 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002284 }
2285 }
2286
2287 @Override
2288 public int getApplicationEnabledSetting(String packageName) {
2289 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -07002290 return mPM.getApplicationEnabledSetting(packageName, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002291 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002292 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002293 }
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002294 }
2295
Amith Yamasani655d0e22013-06-12 14:19:10 -07002296 @Override
Sudheer Shankabbb3ff22015-07-09 15:39:23 +01002297 public void flushPackageRestrictionsAsUser(int userId) {
2298 try {
2299 mPM.flushPackageRestrictionsAsUser(userId);
2300 } catch (RemoteException e) {
2301 throw e.rethrowFromSystemServer();
2302 }
2303 }
2304
2305 @Override
Amith Yamasanie5bcff62014-07-19 15:44:09 -07002306 public boolean setApplicationHiddenSettingAsUser(String packageName, boolean hidden,
Amith Yamasani655d0e22013-06-12 14:19:10 -07002307 UserHandle user) {
2308 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07002309 return mPM.setApplicationHiddenSettingAsUser(packageName, hidden,
Amith Yamasani655d0e22013-06-12 14:19:10 -07002310 user.getIdentifier());
Jeff Sharkey27b2e692016-02-25 17:40:12 -07002311 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002312 throw e.rethrowFromSystemServer();
Amith Yamasani655d0e22013-06-12 14:19:10 -07002313 }
Amith Yamasani655d0e22013-06-12 14:19:10 -07002314 }
2315
2316 @Override
Amith Yamasanie5bcff62014-07-19 15:44:09 -07002317 public boolean getApplicationHiddenSettingAsUser(String packageName, UserHandle user) {
Amith Yamasani655d0e22013-06-12 14:19:10 -07002318 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07002319 return mPM.getApplicationHiddenSettingAsUser(packageName, user.getIdentifier());
Jeff Sharkey27b2e692016-02-25 17:40:12 -07002320 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002321 throw e.rethrowFromSystemServer();
Amith Yamasani655d0e22013-06-12 14:19:10 -07002322 }
Amith Yamasani655d0e22013-06-12 14:19:10 -07002323 }
2324
dcashmanc6f22492014-08-14 09:54:51 -07002325 /** @hide */
dcashman9d2f4412014-06-09 09:27:54 -07002326 @Override
2327 public KeySet getKeySetByAlias(String packageName, String alias) {
2328 Preconditions.checkNotNull(packageName);
2329 Preconditions.checkNotNull(alias);
dcashman9d2f4412014-06-09 09:27:54 -07002330 try {
Jeff Sharkey27b2e692016-02-25 17:40:12 -07002331 return mPM.getKeySetByAlias(packageName, alias);
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 }
dcashman9d2f4412014-06-09 09:27:54 -07002335 }
2336
dcashmanc6f22492014-08-14 09:54:51 -07002337 /** @hide */
dcashman9d2f4412014-06-09 09:27:54 -07002338 @Override
2339 public KeySet getSigningKeySet(String packageName) {
2340 Preconditions.checkNotNull(packageName);
dcashman9d2f4412014-06-09 09:27:54 -07002341 try {
Jeff Sharkey27b2e692016-02-25 17:40:12 -07002342 return mPM.getSigningKeySet(packageName);
dcashman9d2f4412014-06-09 09:27:54 -07002343 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002344 throw e.rethrowFromSystemServer();
dcashman9d2f4412014-06-09 09:27:54 -07002345 }
dcashman9d2f4412014-06-09 09:27:54 -07002346 }
2347
dcashmanc6f22492014-08-14 09:54:51 -07002348 /** @hide */
dcashman9d2f4412014-06-09 09:27:54 -07002349 @Override
2350 public boolean isSignedBy(String packageName, KeySet ks) {
2351 Preconditions.checkNotNull(packageName);
2352 Preconditions.checkNotNull(ks);
dcashman9d2f4412014-06-09 09:27:54 -07002353 try {
dcashmanc6f22492014-08-14 09:54:51 -07002354 return mPM.isPackageSignedByKeySet(packageName, ks);
dcashman9d2f4412014-06-09 09:27:54 -07002355 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002356 throw e.rethrowFromSystemServer();
dcashman9d2f4412014-06-09 09:27:54 -07002357 }
2358 }
2359
dcashmanc6f22492014-08-14 09:54:51 -07002360 /** @hide */
dcashman9d2f4412014-06-09 09:27:54 -07002361 @Override
2362 public boolean isSignedByExactly(String packageName, KeySet ks) {
2363 Preconditions.checkNotNull(packageName);
2364 Preconditions.checkNotNull(ks);
dcashman9d2f4412014-06-09 09:27:54 -07002365 try {
dcashmanc6f22492014-08-14 09:54:51 -07002366 return mPM.isPackageSignedByKeySetExactly(packageName, ks);
dcashman9d2f4412014-06-09 09:27:54 -07002367 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002368 throw e.rethrowFromSystemServer();
dcashman9d2f4412014-06-09 09:27:54 -07002369 }
2370 }
2371
Kenny Root0aaa0d92011-09-12 16:42:55 -07002372 /**
2373 * @hide
2374 */
2375 @Override
2376 public VerifierDeviceIdentity getVerifierDeviceIdentity() {
2377 try {
2378 return mPM.getVerifierDeviceIdentity();
2379 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002380 throw e.rethrowFromSystemServer();
Kenny Root0aaa0d92011-09-12 16:42:55 -07002381 }
Kenny Root0aaa0d92011-09-12 16:42:55 -07002382 }
2383
Jeff Hao9f60c082014-10-28 18:51:07 -07002384 /**
2385 * @hide
2386 */
2387 @Override
2388 public boolean isUpgrade() {
2389 try {
2390 return mPM.isUpgrade();
2391 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002392 throw e.rethrowFromSystemServer();
Jeff Hao9f60c082014-10-28 18:51:07 -07002393 }
2394 }
2395
Jeff Sharkey3a44f3f2014-04-28 17:36:31 -07002396 @Override
Jeff Sharkey16c8e3f2014-07-24 17:08:17 -07002397 public PackageInstaller getPackageInstaller() {
2398 synchronized (mLock) {
2399 if (mInstaller == null) {
2400 try {
Svet Ganov67882122016-12-11 16:36:34 -08002401 mInstaller = new PackageInstaller(mPM.getPackageInstaller(),
Jeff Sharkey16c8e3f2014-07-24 17:08:17 -07002402 mContext.getPackageName(), mContext.getUserId());
2403 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002404 throw e.rethrowFromSystemServer();
Jeff Sharkey16c8e3f2014-07-24 17:08:17 -07002405 }
2406 }
2407 return mInstaller;
Jeff Sharkey3a44f3f2014-04-28 17:36:31 -07002408 }
2409 }
2410
Jeff Sharkey6c833e02014-07-14 22:44:30 -07002411 @Override
2412 public boolean isPackageAvailable(String packageName) {
2413 try {
2414 return mPM.isPackageAvailable(packageName, mContext.getUserId());
2415 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002416 throw e.rethrowFromSystemServer();
Jeff Sharkey6c833e02014-07-14 22:44:30 -07002417 }
2418 }
2419
Nicolas Prevotc79586e2014-05-06 12:47:57 +01002420 /**
2421 * @hide
2422 */
2423 @Override
Nicolas Prevot63798c52014-05-27 13:22:38 +01002424 public void addCrossProfileIntentFilter(IntentFilter filter, int sourceUserId, int targetUserId,
2425 int flags) {
Nicolas Prevotc79586e2014-05-06 12:47:57 +01002426 try {
Nicolas Prevot3f7777f2014-07-24 15:58:39 +01002427 mPM.addCrossProfileIntentFilter(filter, mContext.getOpPackageName(),
Nicolas Prevot4b8d5822015-03-05 15:20:49 +00002428 sourceUserId, targetUserId, flags);
Nicolas Prevotc79586e2014-05-06 12:47:57 +01002429 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002430 throw e.rethrowFromSystemServer();
Nicolas Prevotc79586e2014-05-06 12:47:57 +01002431 }
2432 }
2433
2434 /**
2435 * @hide
2436 */
2437 @Override
Nicolas Prevot81948992014-05-16 18:25:26 +01002438 public void clearCrossProfileIntentFilters(int sourceUserId) {
Nicolas Prevotc79586e2014-05-06 12:47:57 +01002439 try {
Nicolas Prevot4b8d5822015-03-05 15:20:49 +00002440 mPM.clearCrossProfileIntentFilters(sourceUserId, mContext.getOpPackageName());
Nicolas Prevotc79586e2014-05-06 12:47:57 +01002441 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002442 throw e.rethrowFromSystemServer();
Nicolas Prevotc79586e2014-05-06 12:47:57 +01002443 }
2444 }
2445
Nicolas Prevot88cc3462014-05-14 14:51:48 +01002446 /**
2447 * @hide
2448 */
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +01002449 public Drawable loadItemIcon(PackageItemInfo itemInfo, ApplicationInfo appInfo) {
Benjamin Franzec2d48b2014-10-01 15:38:43 +01002450 Drawable dr = loadUnbadgedItemIcon(itemInfo, appInfo);
2451 if (itemInfo.showUserIcon != UserHandle.USER_NULL) {
2452 return dr;
2453 }
2454 return getUserBadgedIcon(dr, new UserHandle(mContext.getUserId()));
2455 }
2456
2457 /**
2458 * @hide
2459 */
2460 public Drawable loadUnbadgedItemIcon(PackageItemInfo itemInfo, ApplicationInfo appInfo) {
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +01002461 if (itemInfo.showUserIcon != UserHandle.USER_NULL) {
Alexandra Gherghina64d4dca2014-08-28 18:26:56 +01002462 Bitmap bitmap = getUserManager().getUserIcon(itemInfo.showUserIcon);
2463 if (bitmap == null) {
2464 return UserIcons.getDefaultUserIcon(itemInfo.showUserIcon, /* light= */ false);
2465 }
2466 return new BitmapDrawable(bitmap);
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +01002467 }
Alexandra Gherghinadb811db2014-08-29 13:43:59 +01002468 Drawable dr = null;
2469 if (itemInfo.packageName != null) {
2470 dr = getDrawable(itemInfo.packageName, itemInfo.icon, appInfo);
2471 }
Alexandra Gherghinaa71e3902014-07-25 20:03:47 +01002472 if (dr == null) {
Alexandra Gherghinaa7093142014-07-30 13:43:39 +01002473 dr = itemInfo.loadDefaultIcon(this);
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +01002474 }
Benjamin Franzec2d48b2014-10-01 15:38:43 +01002475 return dr;
Svetoslavc7d62f02014-09-04 15:39:54 -07002476 }
2477
2478 private Drawable getBadgedDrawable(Drawable drawable, Drawable badgeDrawable,
2479 Rect badgeLocation, boolean tryBadgeInPlace) {
2480 final int badgedWidth = drawable.getIntrinsicWidth();
2481 final int badgedHeight = drawable.getIntrinsicHeight();
2482 final boolean canBadgeInPlace = tryBadgeInPlace
2483 && (drawable instanceof BitmapDrawable)
2484 && ((BitmapDrawable) drawable).getBitmap().isMutable();
2485
2486 final Bitmap bitmap;
2487 if (canBadgeInPlace) {
2488 bitmap = ((BitmapDrawable) drawable).getBitmap();
2489 } else {
2490 bitmap = Bitmap.createBitmap(badgedWidth, badgedHeight, Bitmap.Config.ARGB_8888);
2491 }
2492 Canvas canvas = new Canvas(bitmap);
2493
2494 if (!canBadgeInPlace) {
2495 drawable.setBounds(0, 0, badgedWidth, badgedHeight);
2496 drawable.draw(canvas);
2497 }
2498
2499 if (badgeLocation != null) {
2500 if (badgeLocation.left < 0 || badgeLocation.top < 0
2501 || badgeLocation.width() > badgedWidth || badgeLocation.height() > badgedHeight) {
2502 throw new IllegalArgumentException("Badge location " + badgeLocation
2503 + " not in badged drawable bounds "
2504 + new Rect(0, 0, badgedWidth, badgedHeight));
2505 }
2506 badgeDrawable.setBounds(0, 0, badgeLocation.width(), badgeLocation.height());
2507
2508 canvas.save();
2509 canvas.translate(badgeLocation.left, badgeLocation.top);
2510 badgeDrawable.draw(canvas);
2511 canvas.restore();
2512 } else {
2513 badgeDrawable.setBounds(0, 0, badgedWidth, badgedHeight);
2514 badgeDrawable.draw(canvas);
2515 }
2516
2517 if (!canBadgeInPlace) {
2518 BitmapDrawable mergedDrawable = new BitmapDrawable(mContext.getResources(), bitmap);
2519
2520 if (drawable instanceof BitmapDrawable) {
2521 BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
2522 mergedDrawable.setTargetDensity(bitmapDrawable.getBitmap().getDensity());
2523 }
2524
2525 return mergedDrawable;
2526 }
2527
2528 return drawable;
2529 }
2530
Tony Mak8673b282016-03-21 21:10:59 +00002531 private boolean isManagedProfile(int userId) {
2532 return getUserManager().isManagedProfile(userId);
Nicolas Prevot88cc3462014-05-14 14:51:48 +01002533 }
2534
Bartosz Fabianowskia34f53f2017-01-11 18:08:47 +01002535 /**
2536 * @hide
2537 */
2538 @Override
2539 public int getInstallReason(String packageName, UserHandle user) {
2540 try {
2541 return mPM.getInstallReason(packageName, user.getIdentifier());
2542 } catch (RemoteException e) {
2543 throw e.rethrowFromSystemServer();
2544 }
2545 }
2546
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002547 /** {@hide} */
2548 private static class MoveCallbackDelegate extends IPackageMoveObserver.Stub implements
2549 Handler.Callback {
Jeff Sharkey50a05452015-04-29 11:24:52 -07002550 private static final int MSG_CREATED = 1;
2551 private static final int MSG_STATUS_CHANGED = 2;
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002552
2553 final MoveCallback mCallback;
2554 final Handler mHandler;
2555
2556 public MoveCallbackDelegate(MoveCallback callback, Looper looper) {
2557 mCallback = callback;
2558 mHandler = new Handler(looper, this);
2559 }
2560
2561 @Override
2562 public boolean handleMessage(Message msg) {
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002563 switch (msg.what) {
Jeff Sharkey50a05452015-04-29 11:24:52 -07002564 case MSG_CREATED: {
Jeff Sharkeyb36586a2015-04-27 08:42:28 -07002565 final SomeArgs args = (SomeArgs) msg.obj;
Jeff Sharkey50a05452015-04-29 11:24:52 -07002566 mCallback.onCreated(args.argi1, (Bundle) args.arg2);
Jeff Sharkeyb36586a2015-04-27 08:42:28 -07002567 args.recycle();
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002568 return true;
Jeff Sharkey50a05452015-04-29 11:24:52 -07002569 }
2570 case MSG_STATUS_CHANGED: {
2571 final SomeArgs args = (SomeArgs) msg.obj;
2572 mCallback.onStatusChanged(args.argi1, args.argi2, (long) args.arg3);
2573 args.recycle();
2574 return true;
2575 }
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002576 }
2577 return false;
2578 }
2579
2580 @Override
Jeff Sharkey50a05452015-04-29 11:24:52 -07002581 public void onCreated(int moveId, Bundle extras) {
Jeff Sharkeyb36586a2015-04-27 08:42:28 -07002582 final SomeArgs args = SomeArgs.obtain();
2583 args.argi1 = moveId;
Jeff Sharkey50a05452015-04-29 11:24:52 -07002584 args.arg2 = extras;
2585 mHandler.obtainMessage(MSG_CREATED, args).sendToTarget();
2586 }
2587
2588 @Override
2589 public void onStatusChanged(int moveId, int status, long estMillis) {
2590 final SomeArgs args = SomeArgs.obtain();
2591 args.argi1 = moveId;
2592 args.argi2 = status;
2593 args.arg3 = estMillis;
Jeff Sharkeyb36586a2015-04-27 08:42:28 -07002594 mHandler.obtainMessage(MSG_STATUS_CHANGED, args).sendToTarget();
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002595 }
2596 }
2597
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002598 private final ContextImpl mContext;
2599 private final IPackageManager mPM;
2600
2601 private static final Object sSync = new Object();
Dianne Hackbornadd005c2013-07-17 18:43:12 -07002602 private static ArrayMap<ResourceName, WeakReference<Drawable.ConstantState>> sIconCache
2603 = new ArrayMap<ResourceName, WeakReference<Drawable.ConstantState>>();
2604 private static ArrayMap<ResourceName, WeakReference<CharSequence>> sStringCache
2605 = new ArrayMap<ResourceName, WeakReference<CharSequence>>();
Svetoslavf7c06eb2015-06-10 18:43:22 -07002606
2607 private final Map<OnPermissionsChangedListener, IOnPermissionsChangeListener>
2608 mPermissionListeners = new ArrayMap<>();
2609
2610 public class OnPermissionsChangeListenerDelegate extends IOnPermissionsChangeListener.Stub
2611 implements Handler.Callback{
2612 private static final int MSG_PERMISSIONS_CHANGED = 1;
2613
2614 private final OnPermissionsChangedListener mListener;
2615 private final Handler mHandler;
2616
2617
2618 public OnPermissionsChangeListenerDelegate(OnPermissionsChangedListener listener,
2619 Looper looper) {
2620 mListener = listener;
2621 mHandler = new Handler(looper, this);
2622 }
2623
2624 @Override
2625 public void onPermissionsChanged(int uid) {
2626 mHandler.obtainMessage(MSG_PERMISSIONS_CHANGED, uid, 0).sendToTarget();
2627 }
2628
2629 @Override
2630 public boolean handleMessage(Message msg) {
2631 switch (msg.what) {
2632 case MSG_PERMISSIONS_CHANGED: {
2633 final int uid = msg.arg1;
2634 mListener.onPermissionsChanged(uid);
2635 return true;
2636 }
2637 }
2638 return false;
2639 }
2640 }
Suprabh Shuklaaef25132017-01-23 18:09:03 -08002641
2642 @Override
2643 public boolean canRequestPackageInstalls() {
2644 try {
2645 return mPM.canRequestPackageInstalls(mContext.getPackageName(), mContext.getUserId());
2646 } catch (RemoteException e) {
2647 throw e.rethrowAsRuntimeException();
2648 }
2649 }
Chad Brubaker336ae5b2017-03-24 15:53:09 -07002650
2651 @Override
2652 public ComponentName getInstantAppResolverSettingsComponent() {
2653 try {
2654 return mPM.getInstantAppResolverSettingsComponent();
2655 } catch (RemoteException e) {
2656 throw e.rethrowAsRuntimeException();
2657 }
2658 }
Todd Kennedy801e6592017-04-12 14:10:12 -07002659
2660 @Override
2661 public ComponentName getInstantAppInstallerComponent() {
2662 try {
2663 return mPM.getInstantAppInstallerComponent();
2664 } catch (RemoteException e) {
2665 throw e.rethrowAsRuntimeException();
2666 }
2667 }
Chad Brubaker0d277a72017-04-12 16:56:53 -07002668
2669 @Override
2670 public String getInstantAppAndroidId(String packageName, UserHandle user) {
2671 try {
2672 return mPM.getInstantAppAndroidId(packageName, user.getIdentifier());
2673 } catch (RemoteException e) {
2674 throw e.rethrowAsRuntimeException();
2675 }
2676 }
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002677}