blob: 64e2d49d274bdc9e73a7856a5a9f1c5b15036696 [file] [log] [blame]
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001/*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.app;
18
Tor Norbye7b9c9122013-05-30 16:48:33 -070019import android.annotation.DrawableRes;
Alan Viveretteecd585a2015-04-13 10:32:51 -070020import android.annotation.NonNull;
21import android.annotation.Nullable;
Tor Norbye7b9c9122013-05-30 16:48:33 -070022import android.annotation.StringRes;
23import android.annotation.XmlRes;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080024import android.content.ComponentName;
25import android.content.ContentResolver;
Yao Chen022b8ea2016-12-16 11:03:28 -080026import android.content.Context;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080027import android.content.Intent;
28import android.content.IntentFilter;
29import android.content.IntentSender;
30import android.content.pm.ActivityInfo;
31import android.content.pm.ApplicationInfo;
Todd Kennedy9106c642017-02-08 14:16:53 -080032import android.content.pm.ChangedPackages;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080033import android.content.pm.ComponentInfo;
Svetoslav Ganov096d3042017-01-30 16:34:13 -080034import android.content.pm.InstantAppInfo;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080035import android.content.pm.FeatureInfo;
Svetoslavf7c06eb2015-06-10 18:43:22 -070036import android.content.pm.IOnPermissionsChangeListener;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080037import android.content.pm.IPackageDataObserver;
38import android.content.pm.IPackageDeleteObserver;
39import android.content.pm.IPackageInstallObserver;
40import android.content.pm.IPackageManager;
41import android.content.pm.IPackageMoveObserver;
42import android.content.pm.IPackageStatsObserver;
43import android.content.pm.InstrumentationInfo;
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -080044import android.content.pm.IntentFilterVerificationInfo;
dcashman9d2f4412014-06-09 09:27:54 -070045import android.content.pm.KeySet;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080046import android.content.pm.PackageInfo;
Jeff Sharkey3a44f3f2014-04-28 17:36:31 -070047import android.content.pm.PackageInstaller;
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +010048import android.content.pm.PackageItemInfo;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080049import android.content.pm.PackageManager;
Kenny Roote6cd0c72011-05-19 12:48:14 -070050import android.content.pm.ParceledListSlice;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080051import android.content.pm.PermissionGroupInfo;
52import android.content.pm.PermissionInfo;
53import android.content.pm.ProviderInfo;
54import android.content.pm.ResolveInfo;
55import android.content.pm.ServiceInfo;
Svet Ganov67882122016-12-11 16:36:34 -080056import android.content.pm.SharedLibraryInfo;
Kenny Root0aaa0d92011-09-12 16:42:55 -070057import android.content.pm.VerifierDeviceIdentity;
Svet Ganov67882122016-12-11 16:36:34 -080058import android.content.pm.VersionedPackage;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080059import android.content.res.Resources;
60import android.content.res.XmlResourceParser;
Svetoslavc7d62f02014-09-04 15:39:54 -070061import android.graphics.Bitmap;
62import android.graphics.Canvas;
63import android.graphics.Rect;
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +010064import android.graphics.drawable.BitmapDrawable;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080065import android.graphics.drawable.Drawable;
Kenny Guy02c89902016-11-15 19:36:38 +000066import android.graphics.drawable.LayerDrawable;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080067import android.net.Uri;
Jeff Sharkey50a05452015-04-29 11:24:52 -070068import android.os.Bundle;
Jeff Sharkey620b32b2015-04-23 19:36:02 -070069import android.os.Handler;
70import android.os.Looper;
71import android.os.Message;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080072import android.os.Process;
73import android.os.RemoteException;
Jeff Sharkeyb2b9ab82015-04-05 21:10:42 -070074import android.os.SystemProperties;
Amith Yamasani67df64b2012-12-14 12:09:36 -080075import android.os.UserHandle;
Nicolas Prevot88cc3462014-05-14 14:51:48 +010076import android.os.UserManager;
Jeff Sharkeye2d45be2015-04-15 17:14:12 -070077import android.os.storage.StorageManager;
78import android.os.storage.VolumeInfo;
Todd Kennedyf39ca8f2015-08-07 14:15:07 -070079import android.provider.Settings;
Dianne Hackbornadd005c2013-07-17 18:43:12 -070080import android.util.ArrayMap;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080081import android.util.Log;
Jeff Browna492c3a2012-08-23 19:48:44 -070082import android.view.Display;
Jeff Sharkeyb2b9ab82015-04-05 21:10:42 -070083
84import dalvik.system.VMRuntime;
Jeff Sharkey16c8e3f2014-07-24 17:08:17 -070085
86import com.android.internal.annotations.GuardedBy;
Kenny Guy02c89902016-11-15 19:36:38 +000087import com.android.internal.annotations.VisibleForTesting;
Jeff Sharkeyb36586a2015-04-27 08:42:28 -070088import com.android.internal.os.SomeArgs;
dcashman9d2f4412014-06-09 09:27:54 -070089import com.android.internal.util.Preconditions;
Alexandra Gherghina64d4dca2014-08-28 18:26:56 +010090import com.android.internal.util.UserIcons;
Svet Ganov2acf0632015-11-24 19:10:59 -080091import libcore.util.EmptyArray;
Jeff Sharkey16c8e3f2014-07-24 17:08:17 -070092
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080093import java.lang.ref.WeakReference;
94import java.util.ArrayList;
Svet Ganov2acf0632015-11-24 19:10:59 -080095import java.util.Collections;
Jeff Sharkey620b32b2015-04-23 19:36:02 -070096import java.util.Iterator;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080097import java.util.List;
Svetoslavf7c06eb2015-06-10 18:43:22 -070098import java.util.Map;
Jeff Sharkey620b32b2015-04-23 19:36:02 -070099import java.util.Objects;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800100
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700101/** @hide */
102public class ApplicationPackageManager extends PackageManager {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800103 private static final String TAG = "ApplicationPackageManager";
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800104 private final static boolean DEBUG_ICONS = false;
105
Svet Ganov2acf0632015-11-24 19:10:59 -0800106 private static final int DEFAULT_EPHEMERAL_COOKIE_MAX_SIZE_BYTES = 16384; // 16KB
107
Adam Lesinskid00bb5e2014-10-07 12:14:45 -0700108 // Default flags to use with PackageManager when no flags are given.
109 private final static int sDefaultFlags = PackageManager.GET_SHARED_LIBRARY_FILES;
110
Jeff Sharkey16c8e3f2014-07-24 17:08:17 -0700111 private final Object mLock = new Object();
112
113 @GuardedBy("mLock")
114 private UserManager mUserManager;
115 @GuardedBy("mLock")
116 private PackageInstaller mInstaller;
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +0100117
Jeff Sharkey620b32b2015-04-23 19:36:02 -0700118 @GuardedBy("mDelegates")
119 private final ArrayList<MoveCallbackDelegate> mDelegates = new ArrayList<>();
120
Svet Ganovf1b7f202015-07-29 08:33:42 -0700121 @GuardedBy("mLock")
122 private String mPermissionsControllerPackageName;
123
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +0100124 UserManager getUserManager() {
Jeff Sharkey16c8e3f2014-07-24 17:08:17 -0700125 synchronized (mLock) {
126 if (mUserManager == null) {
127 mUserManager = UserManager.get(mContext);
128 }
129 return mUserManager;
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +0100130 }
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +0100131 }
132
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800133 @Override
134 public PackageInfo getPackageInfo(String packageName, int flags)
135 throws NameNotFoundException {
Nicolas Prevot9a80e532015-09-23 15:49:28 +0100136 return getPackageInfoAsUser(packageName, flags, mContext.getUserId());
137 }
138
139 @Override
Svet Ganov67882122016-12-11 16:36:34 -0800140 public PackageInfo getPackageInfo(VersionedPackage versionedPackage, int flags)
141 throws NameNotFoundException {
142 try {
143 PackageInfo pi = mPM.getPackageInfoVersioned(versionedPackage, flags,
144 mContext.getUserId());
145 if (pi != null) {
146 return pi;
147 }
148 } catch (RemoteException e) {
149 throw e.rethrowFromSystemServer();
150 }
151 throw new NameNotFoundException(versionedPackage.toString());
152 }
153
154 @Override
Nicolas Prevot9a80e532015-09-23 15:49:28 +0100155 public PackageInfo getPackageInfoAsUser(String packageName, int flags, int userId)
156 throws NameNotFoundException {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800157 try {
Nicolas Prevot9a80e532015-09-23 15:49:28 +0100158 PackageInfo pi = mPM.getPackageInfo(packageName, flags, userId);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800159 if (pi != null) {
160 return pi;
161 }
162 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700163 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800164 }
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800165 throw new NameNotFoundException(packageName);
166 }
167
168 @Override
169 public String[] currentToCanonicalPackageNames(String[] names) {
170 try {
171 return mPM.currentToCanonicalPackageNames(names);
172 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700173 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800174 }
175 }
176
177 @Override
178 public String[] canonicalToCurrentPackageNames(String[] names) {
179 try {
180 return mPM.canonicalToCurrentPackageNames(names);
181 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700182 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800183 }
184 }
185
186 @Override
187 public Intent getLaunchIntentForPackage(String packageName) {
188 // First see if the package has an INFO activity; the existence of
189 // such an activity is implied to be the desired front-door for the
190 // overall package (such as if it has multiple launcher entries).
191 Intent intentToResolve = new Intent(Intent.ACTION_MAIN);
192 intentToResolve.addCategory(Intent.CATEGORY_INFO);
193 intentToResolve.setPackage(packageName);
Dianne Hackborn19415762010-12-15 00:20:27 -0800194 List<ResolveInfo> ris = queryIntentActivities(intentToResolve, 0);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800195
196 // Otherwise, try to find a main launcher activity.
Dianne Hackborn19415762010-12-15 00:20:27 -0800197 if (ris == null || ris.size() <= 0) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800198 // reuse the intent instance
199 intentToResolve.removeCategory(Intent.CATEGORY_INFO);
200 intentToResolve.addCategory(Intent.CATEGORY_LAUNCHER);
201 intentToResolve.setPackage(packageName);
Dianne Hackborn19415762010-12-15 00:20:27 -0800202 ris = queryIntentActivities(intentToResolve, 0);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800203 }
Dianne Hackborn19415762010-12-15 00:20:27 -0800204 if (ris == null || ris.size() <= 0) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800205 return null;
206 }
207 Intent intent = new Intent(intentToResolve);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800208 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Dianne Hackborn19415762010-12-15 00:20:27 -0800209 intent.setClassName(ris.get(0).activityInfo.packageName,
210 ris.get(0).activityInfo.name);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800211 return intent;
212 }
213
214 @Override
Jose Lima970417c2014-04-10 10:42:19 -0700215 public Intent getLeanbackLaunchIntentForPackage(String packageName) {
216 // Try to find a main leanback_launcher activity.
217 Intent intentToResolve = new Intent(Intent.ACTION_MAIN);
218 intentToResolve.addCategory(Intent.CATEGORY_LEANBACK_LAUNCHER);
219 intentToResolve.setPackage(packageName);
220 List<ResolveInfo> ris = queryIntentActivities(intentToResolve, 0);
221
222 if (ris == null || ris.size() <= 0) {
223 return null;
224 }
225 Intent intent = new Intent(intentToResolve);
226 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
227 intent.setClassName(ris.get(0).activityInfo.packageName,
228 ris.get(0).activityInfo.name);
229 return intent;
230 }
231
232 @Override
Jeff Sharkey8588bc12016-01-06 16:47:42 -0700233 public int[] getPackageGids(String packageName) throws NameNotFoundException {
234 return getPackageGids(packageName, 0);
235 }
236
237 @Override
238 public int[] getPackageGids(String packageName, int flags)
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800239 throws NameNotFoundException {
240 try {
Jeff Sharkeycd654482016-01-08 17:42:11 -0700241 int[] gids = mPM.getPackageGids(packageName, flags, mContext.getUserId());
Svetoslavc6d1c342015-02-26 14:44:43 -0800242 if (gids != null) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800243 return gids;
244 }
245 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700246 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800247 }
248
249 throw new NameNotFoundException(packageName);
250 }
251
252 @Override
Jeff Sharkey8588bc12016-01-06 16:47:42 -0700253 public int getPackageUid(String packageName, int flags) throws NameNotFoundException {
254 return getPackageUidAsUser(packageName, flags, mContext.getUserId());
255 }
256
257 @Override
258 public int getPackageUidAsUser(String packageName, int userId) throws NameNotFoundException {
259 return getPackageUidAsUser(packageName, 0, userId);
260 }
261
262 @Override
263 public int getPackageUidAsUser(String packageName, int flags, int userId)
Dianne Hackborna06de0f2012-12-11 16:34:47 -0800264 throws NameNotFoundException {
265 try {
Jeff Sharkeycd654482016-01-08 17:42:11 -0700266 int uid = mPM.getPackageUid(packageName, flags, userId);
Dianne Hackborna06de0f2012-12-11 16:34:47 -0800267 if (uid >= 0) {
268 return uid;
269 }
270 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700271 throw e.rethrowFromSystemServer();
Dianne Hackborna06de0f2012-12-11 16:34:47 -0800272 }
273
274 throw new NameNotFoundException(packageName);
275 }
276
277 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800278 public PermissionInfo getPermissionInfo(String name, int flags)
279 throws NameNotFoundException {
280 try {
281 PermissionInfo pi = mPM.getPermissionInfo(name, flags);
282 if (pi != null) {
283 return pi;
284 }
285 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700286 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800287 }
288
289 throw new NameNotFoundException(name);
290 }
291
292 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700293 @SuppressWarnings("unchecked")
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800294 public List<PermissionInfo> queryPermissionsByGroup(String group, int flags)
295 throws NameNotFoundException {
296 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700297 ParceledListSlice<PermissionInfo> parceledList =
298 mPM.queryPermissionsByGroup(group, flags);
299 if (parceledList != null) {
300 List<PermissionInfo> pi = parceledList.getList();
301 if (pi != null) {
302 return pi;
303 }
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800304 }
305 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700306 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800307 }
308
309 throw new NameNotFoundException(group);
310 }
311
312 @Override
Paul Navin7b89a7b2017-01-26 23:56:08 +0000313 public boolean isPermissionReviewModeEnabled() {
314 return mContext.getResources().getBoolean(
315 com.android.internal.R.bool.config_permissionReviewRequired);
316 }
317
318 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800319 public PermissionGroupInfo getPermissionGroupInfo(String name,
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700320 int flags) throws NameNotFoundException {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800321 try {
322 PermissionGroupInfo pgi = mPM.getPermissionGroupInfo(name, flags);
323 if (pgi != null) {
324 return pgi;
325 }
326 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700327 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800328 }
329
330 throw new NameNotFoundException(name);
331 }
332
333 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700334 @SuppressWarnings("unchecked")
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800335 public List<PermissionGroupInfo> getAllPermissionGroups(int flags) {
336 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700337 ParceledListSlice<PermissionGroupInfo> parceledList =
338 mPM.getAllPermissionGroups(flags);
339 if (parceledList == null) {
340 return Collections.emptyList();
341 }
342 return parceledList.getList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800343 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700344 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800345 }
346 }
347
348 @Override
349 public ApplicationInfo getApplicationInfo(String packageName, int flags)
350 throws NameNotFoundException {
Jeff Sharkeycd654482016-01-08 17:42:11 -0700351 return getApplicationInfoAsUser(packageName, flags, mContext.getUserId());
352 }
353
354 @Override
355 public ApplicationInfo getApplicationInfoAsUser(String packageName, int flags, int userId)
356 throws NameNotFoundException {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800357 try {
Jeff Sharkeycd654482016-01-08 17:42:11 -0700358 ApplicationInfo ai = mPM.getApplicationInfo(packageName, flags, userId);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800359 if (ai != null) {
Narayan Kamathcaa71192014-07-16 11:06:43 +0100360 // This is a temporary hack. Callers must use
361 // createPackageContext(packageName).getApplicationInfo() to
362 // get the right paths.
Tao Baic9a02372016-01-12 15:02:24 -0800363 return maybeAdjustApplicationInfo(ai);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800364 }
365 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700366 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800367 }
368
369 throw new NameNotFoundException(packageName);
370 }
371
Tao Baic9a02372016-01-12 15:02:24 -0800372 private static ApplicationInfo maybeAdjustApplicationInfo(ApplicationInfo info) {
Narayan Kamathcaa71192014-07-16 11:06:43 +0100373 // If we're dealing with a multi-arch application that has both
374 // 32 and 64 bit shared libraries, we might need to choose the secondary
375 // depending on what the current runtime's instruction set is.
376 if (info.primaryCpuAbi != null && info.secondaryCpuAbi != null) {
377 final String runtimeIsa = VMRuntime.getRuntime().vmInstructionSet();
jgu214741cd92014-12-17 17:23:29 -0500378
379 // Get the instruction set that the libraries of secondary Abi is supported.
380 // In presence of a native bridge this might be different than the one secondary Abi used.
381 String secondaryIsa = VMRuntime.getInstructionSet(info.secondaryCpuAbi);
382 final String secondaryDexCodeIsa = SystemProperties.get("ro.dalvik.vm.isa." + secondaryIsa);
383 secondaryIsa = secondaryDexCodeIsa.isEmpty() ? secondaryIsa : secondaryDexCodeIsa;
Narayan Kamathcaa71192014-07-16 11:06:43 +0100384
385 // If the runtimeIsa is the same as the primary isa, then we do nothing.
386 // Everything will be set up correctly because info.nativeLibraryDir will
387 // correspond to the right ISA.
388 if (runtimeIsa.equals(secondaryIsa)) {
Tao Baic9a02372016-01-12 15:02:24 -0800389 ApplicationInfo modified = new ApplicationInfo(info);
390 modified.nativeLibraryDir = info.secondaryNativeLibraryDir;
391 return modified;
Narayan Kamathcaa71192014-07-16 11:06:43 +0100392 }
393 }
Tao Baic9a02372016-01-12 15:02:24 -0800394 return info;
Narayan Kamathcaa71192014-07-16 11:06:43 +0100395 }
396
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800397 @Override
398 public ActivityInfo getActivityInfo(ComponentName className, int flags)
399 throws NameNotFoundException {
400 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700401 ActivityInfo ai = mPM.getActivityInfo(className, flags, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800402 if (ai != null) {
403 return ai;
404 }
405 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700406 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800407 }
408
409 throw new NameNotFoundException(className.toString());
410 }
411
412 @Override
413 public ActivityInfo getReceiverInfo(ComponentName className, int flags)
414 throws NameNotFoundException {
415 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700416 ActivityInfo ai = mPM.getReceiverInfo(className, flags, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800417 if (ai != null) {
418 return ai;
419 }
420 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700421 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800422 }
423
424 throw new NameNotFoundException(className.toString());
425 }
426
427 @Override
428 public ServiceInfo getServiceInfo(ComponentName className, int flags)
429 throws NameNotFoundException {
430 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700431 ServiceInfo si = mPM.getServiceInfo(className, flags, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800432 if (si != null) {
433 return si;
434 }
435 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700436 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800437 }
438
439 throw new NameNotFoundException(className.toString());
440 }
441
442 @Override
443 public ProviderInfo getProviderInfo(ComponentName className, int flags)
444 throws NameNotFoundException {
445 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700446 ProviderInfo pi = mPM.getProviderInfo(className, flags, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800447 if (pi != null) {
448 return pi;
449 }
450 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700451 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800452 }
453
454 throw new NameNotFoundException(className.toString());
455 }
456
457 @Override
458 public String[] getSystemSharedLibraryNames() {
459 try {
460 return mPM.getSystemSharedLibraryNames();
461 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700462 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800463 }
464 }
465
Svet Ganovd7b1f4112016-02-09 18:49:23 -0800466 /** @hide */
467 @Override
Svet Ganov67882122016-12-11 16:36:34 -0800468 public @NonNull List<SharedLibraryInfo> getSharedLibraries(int flags) {
469 return getSharedLibrariesAsUser(flags, mContext.getUserId());
470 }
471
472 /** @hide */
473 @Override
474 @SuppressWarnings("unchecked")
475 public @NonNull List<SharedLibraryInfo> getSharedLibrariesAsUser(int flags, int userId) {
476 try {
477 ParceledListSlice<SharedLibraryInfo> sharedLibs = mPM.getSharedLibraries(
478 flags, userId);
479 if (sharedLibs == null) {
480 return Collections.emptyList();
481 }
482 return sharedLibs.getList();
483 } catch (RemoteException e) {
484 throw e.rethrowFromSystemServer();
485 }
486 }
487
488 /** @hide */
489 @Override
Svetoslav Ganova9c25002016-04-13 19:25:56 -0700490 public @NonNull String getServicesSystemSharedLibraryPackageName() {
Svet Ganovd7b1f4112016-02-09 18:49:23 -0800491 try {
492 return mPM.getServicesSystemSharedLibraryPackageName();
493 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700494 throw e.rethrowFromSystemServer();
Svet Ganovd7b1f4112016-02-09 18:49:23 -0800495 }
496 }
497
Svetoslav Ganova9c25002016-04-13 19:25:56 -0700498 /**
499 * @hide
500 */
501 public @NonNull String getSharedSystemSharedLibraryPackageName() {
502 try {
503 return mPM.getSharedSystemSharedLibraryPackageName();
504 } catch (RemoteException e) {
505 throw e.rethrowFromSystemServer();
506 }
507 }
508
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800509 @Override
Todd Kennedy9106c642017-02-08 14:16:53 -0800510 public ChangedPackages getChangedPackages(int sequenceNumber) {
511 try {
512 return mPM.getChangedPackages(sequenceNumber, mContext.getUserId());
513 } catch (RemoteException e) {
514 throw e.rethrowFromSystemServer();
515 }
516 }
517
518 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700519 @SuppressWarnings("unchecked")
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800520 public FeatureInfo[] getSystemAvailableFeatures() {
521 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700522 ParceledListSlice<FeatureInfo> parceledList =
523 mPM.getSystemAvailableFeatures();
524 if (parceledList == null) {
525 return new FeatureInfo[0];
526 }
527 final List<FeatureInfo> list = parceledList.getList();
Jeff Sharkeyd5896632016-03-04 16:16:00 -0700528 final FeatureInfo[] res = new FeatureInfo[list.size()];
529 for (int i = 0; i < res.length; i++) {
530 res[i] = list.get(i);
531 }
532 return res;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800533 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700534 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800535 }
536 }
537
538 @Override
539 public boolean hasSystemFeature(String name) {
Jeff Sharkey115d2c12016-02-15 17:25:57 -0700540 return hasSystemFeature(name, 0);
541 }
542
543 @Override
544 public boolean hasSystemFeature(String name, int version) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800545 try {
Jeff Sharkey115d2c12016-02-15 17:25:57 -0700546 return mPM.hasSystemFeature(name, version);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800547 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700548 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800549 }
550 }
551
552 @Override
553 public int checkPermission(String permName, String pkgName) {
554 try {
Svetoslavc6d1c342015-02-26 14:44:43 -0800555 return mPM.checkPermission(permName, pkgName, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800556 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700557 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800558 }
559 }
560
561 @Override
Svet Ganovad3b2972015-07-07 22:49:17 -0700562 public boolean isPermissionRevokedByPolicy(String permName, String pkgName) {
563 try {
564 return mPM.isPermissionRevokedByPolicy(permName, pkgName, mContext.getUserId());
565 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700566 throw e.rethrowFromSystemServer();
Svet Ganovad3b2972015-07-07 22:49:17 -0700567 }
568 }
569
Svet Ganovf1b7f202015-07-29 08:33:42 -0700570 /**
571 * @hide
572 */
573 @Override
574 public String getPermissionControllerPackageName() {
575 synchronized (mLock) {
576 if (mPermissionsControllerPackageName == null) {
577 try {
578 mPermissionsControllerPackageName = mPM.getPermissionControllerPackageName();
579 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700580 throw e.rethrowFromSystemServer();
Svet Ganovf1b7f202015-07-29 08:33:42 -0700581 }
582 }
583 return mPermissionsControllerPackageName;
584 }
585 }
586
Svet Ganovad3b2972015-07-07 22:49:17 -0700587 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800588 public boolean addPermission(PermissionInfo info) {
589 try {
590 return mPM.addPermission(info);
591 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700592 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800593 }
594 }
595
596 @Override
597 public boolean addPermissionAsync(PermissionInfo info) {
598 try {
599 return mPM.addPermissionAsync(info);
600 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700601 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800602 }
603 }
604
605 @Override
606 public void removePermission(String name) {
607 try {
608 mPM.removePermission(name);
609 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700610 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800611 }
612 }
613
614 @Override
Svet Ganov8c7f7002015-05-07 10:48:44 -0700615 public void grantRuntimePermission(String packageName, String permissionName,
616 UserHandle user) {
Dianne Hackborne639da72012-02-21 15:11:13 -0800617 try {
Svet Ganov8c7f7002015-05-07 10:48:44 -0700618 mPM.grantRuntimePermission(packageName, permissionName, user.getIdentifier());
Dianne Hackborne639da72012-02-21 15:11:13 -0800619 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700620 throw e.rethrowFromSystemServer();
Dianne Hackborne639da72012-02-21 15:11:13 -0800621 }
622 }
623
624 @Override
Svet Ganov8c7f7002015-05-07 10:48:44 -0700625 public void revokeRuntimePermission(String packageName, String permissionName,
626 UserHandle user) {
Dianne Hackborne639da72012-02-21 15:11:13 -0800627 try {
Svet Ganov8c7f7002015-05-07 10:48:44 -0700628 mPM.revokeRuntimePermission(packageName, permissionName, user.getIdentifier());
629 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700630 throw e.rethrowFromSystemServer();
Svet Ganov8c7f7002015-05-07 10:48:44 -0700631 }
632 }
633
634 @Override
635 public int getPermissionFlags(String permissionName, String packageName, UserHandle user) {
636 try {
637 return mPM.getPermissionFlags(permissionName, packageName, user.getIdentifier());
638 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700639 throw e.rethrowFromSystemServer();
Svet Ganov8c7f7002015-05-07 10:48:44 -0700640 }
641 }
642
643 @Override
644 public void updatePermissionFlags(String permissionName, String packageName,
645 int flagMask, int flagValues, UserHandle user) {
646 try {
647 mPM.updatePermissionFlags(permissionName, packageName, flagMask,
648 flagValues, user.getIdentifier());
Dianne Hackborne639da72012-02-21 15:11:13 -0800649 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700650 throw e.rethrowFromSystemServer();
Dianne Hackborne639da72012-02-21 15:11:13 -0800651 }
652 }
653
654 @Override
Svetoslav20770dd2015-05-29 15:43:04 -0700655 public boolean shouldShowRequestPermissionRationale(String permission) {
656 try {
657 return mPM.shouldShowRequestPermissionRationale(permission,
658 mContext.getPackageName(), mContext.getUserId());
659 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700660 throw e.rethrowFromSystemServer();
Svetoslav20770dd2015-05-29 15:43:04 -0700661 }
662 }
663
664 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800665 public int checkSignatures(String pkg1, String pkg2) {
666 try {
667 return mPM.checkSignatures(pkg1, pkg2);
668 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700669 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800670 }
671 }
672
673 @Override
674 public int checkSignatures(int uid1, int uid2) {
675 try {
676 return mPM.checkUidSignatures(uid1, uid2);
677 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700678 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800679 }
680 }
681
682 @Override
683 public String[] getPackagesForUid(int uid) {
684 try {
685 return mPM.getPackagesForUid(uid);
686 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700687 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800688 }
689 }
690
691 @Override
692 public String getNameForUid(int uid) {
693 try {
694 return mPM.getNameForUid(uid);
695 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700696 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800697 }
698 }
699
700 @Override
701 public int getUidForSharedUser(String sharedUserName)
702 throws NameNotFoundException {
703 try {
704 int uid = mPM.getUidForSharedUser(sharedUserName);
705 if(uid != -1) {
706 return uid;
707 }
708 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700709 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800710 }
711 throw new NameNotFoundException("No shared userid for user:"+sharedUserName);
712 }
713
Kenny Roote6cd0c72011-05-19 12:48:14 -0700714 @SuppressWarnings("unchecked")
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800715 @Override
716 public List<PackageInfo> getInstalledPackages(int flags) {
Jeff Sharkeye06b4d12016-01-06 14:51:50 -0700717 return getInstalledPackagesAsUser(flags, mContext.getUserId());
Amith Yamasani151ec4c2012-09-07 19:25:16 -0700718 }
719
720 /** @hide */
721 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700722 @SuppressWarnings("unchecked")
Jeff Sharkeye06b4d12016-01-06 14:51:50 -0700723 public List<PackageInfo> getInstalledPackagesAsUser(int flags, int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800724 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700725 ParceledListSlice<PackageInfo> parceledList =
726 mPM.getInstalledPackages(flags, userId);
727 if (parceledList == null) {
728 return Collections.emptyList();
729 }
730 return parceledList.getList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800731 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700732 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800733 }
734 }
735
Kenny Roote6cd0c72011-05-19 12:48:14 -0700736 @SuppressWarnings("unchecked")
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800737 @Override
Dianne Hackborne7991752013-01-16 17:56:46 -0800738 public List<PackageInfo> getPackagesHoldingPermissions(
739 String[] permissions, int flags) {
740 final int userId = mContext.getUserId();
741 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700742 ParceledListSlice<PackageInfo> parceledList =
743 mPM.getPackagesHoldingPermissions(permissions, flags, userId);
744 if (parceledList == null) {
745 return Collections.emptyList();
746 }
747 return parceledList.getList();
Dianne Hackborne7991752013-01-16 17:56:46 -0800748 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700749 throw e.rethrowFromSystemServer();
Dianne Hackborne7991752013-01-16 17:56:46 -0800750 }
751 }
752
753 @SuppressWarnings("unchecked")
754 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800755 public List<ApplicationInfo> getInstalledApplications(int flags) {
Bartosz Fabianowski11334242016-11-17 20:49:16 +0100756 return getInstalledApplicationsAsUser(flags, mContext.getUserId());
757 }
758
759 /** @hide */
760 @SuppressWarnings("unchecked")
761 @Override
762 public List<ApplicationInfo> getInstalledApplicationsAsUser(int flags, int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800763 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700764 ParceledListSlice<ApplicationInfo> parceledList =
765 mPM.getInstalledApplications(flags, userId);
766 if (parceledList == null) {
767 return Collections.emptyList();
768 }
769 return parceledList.getList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800770 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700771 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800772 }
773 }
774
Svet Ganov2acf0632015-11-24 19:10:59 -0800775 /** @hide */
776 @SuppressWarnings("unchecked")
777 @Override
Svetoslav Ganov096d3042017-01-30 16:34:13 -0800778 public List<InstantAppInfo> getInstantApps() {
Svet Ganov2acf0632015-11-24 19:10:59 -0800779 try {
Svetoslav Ganov096d3042017-01-30 16:34:13 -0800780 ParceledListSlice<InstantAppInfo> slice =
781 mPM.getInstantApps(mContext.getUserId());
Svet Ganov2acf0632015-11-24 19:10:59 -0800782 if (slice != null) {
783 return slice.getList();
784 }
785 return Collections.emptyList();
786 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700787 throw e.rethrowFromSystemServer();
Svet Ganov2acf0632015-11-24 19:10:59 -0800788 }
789 }
790
791 /** @hide */
792 @Override
Svetoslav Ganov096d3042017-01-30 16:34:13 -0800793 public Drawable getInstantAppIcon(String packageName) {
Svet Ganov2acf0632015-11-24 19:10:59 -0800794 try {
Svetoslav Ganov096d3042017-01-30 16:34:13 -0800795 Bitmap bitmap = mPM.getInstantAppIcon(
Svet Ganov2acf0632015-11-24 19:10:59 -0800796 packageName, mContext.getUserId());
797 if (bitmap != null) {
798 return new BitmapDrawable(null, bitmap);
799 }
800 return null;
801 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700802 throw e.rethrowFromSystemServer();
Svet Ganov2acf0632015-11-24 19:10:59 -0800803 }
804 }
805
806 @Override
Svetoslav Ganov096d3042017-01-30 16:34:13 -0800807 public boolean isInstantApp() {
David Christie31a16552017-03-01 15:08:45 -0800808 return isInstantApp(mContext.getPackageName());
809 }
810
811 @Override
812 public boolean isInstantApp(String packageName) {
Svet Ganov2acf0632015-11-24 19:10:59 -0800813 try {
David Christie31a16552017-03-01 15:08:45 -0800814 return mPM.isInstantApp(packageName, mContext.getUserId());
Svet Ganov2acf0632015-11-24 19:10:59 -0800815 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700816 throw e.rethrowFromSystemServer();
Svet Ganov2acf0632015-11-24 19:10:59 -0800817 }
Svet Ganov2acf0632015-11-24 19:10:59 -0800818 }
819
820 @Override
Svetoslav Ganov096d3042017-01-30 16:34:13 -0800821 public int getInstantAppCookieMaxSize() {
Svet Ganov2acf0632015-11-24 19:10:59 -0800822 return Settings.Global.getInt(mContext.getContentResolver(),
823 Settings.Global.EPHEMERAL_COOKIE_MAX_SIZE_BYTES,
824 DEFAULT_EPHEMERAL_COOKIE_MAX_SIZE_BYTES);
825 }
826
827 @Override
Svetoslav Ganov096d3042017-01-30 16:34:13 -0800828 public @NonNull byte[] getInstantAppCookie() {
Svet Ganov2acf0632015-11-24 19:10:59 -0800829 try {
Svetoslav Ganov096d3042017-01-30 16:34:13 -0800830 final byte[] cookie = mPM.getInstantAppCookie(
Svet Ganov2acf0632015-11-24 19:10:59 -0800831 mContext.getPackageName(), mContext.getUserId());
832 if (cookie != null) {
833 return cookie;
Jeff Sharkey27b2e692016-02-25 17:40:12 -0700834 } else {
835 return EmptyArray.BYTE;
Svet Ganov2acf0632015-11-24 19:10:59 -0800836 }
837 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700838 throw e.rethrowFromSystemServer();
Svet Ganov2acf0632015-11-24 19:10:59 -0800839 }
Svet Ganov2acf0632015-11-24 19:10:59 -0800840 }
841
842 @Override
Svetoslav Ganov096d3042017-01-30 16:34:13 -0800843 public boolean setInstantAppCookie(@NonNull byte[] cookie) {
Svet Ganov2acf0632015-11-24 19:10:59 -0800844 try {
Svetoslav Ganov096d3042017-01-30 16:34:13 -0800845 return mPM.setInstantAppCookie(mContext.getPackageName(),
846 cookie, mContext.getUserId());
Svet Ganov2acf0632015-11-24 19:10:59 -0800847 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700848 throw e.rethrowFromSystemServer();
Svet Ganov2acf0632015-11-24 19:10:59 -0800849 }
Svet Ganov2acf0632015-11-24 19:10:59 -0800850 }
851
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800852 @Override
853 public ResolveInfo resolveActivity(Intent intent, int flags) {
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700854 return resolveActivityAsUser(intent, flags, mContext.getUserId());
Svetoslav Ganov58d37b52012-09-18 12:04:19 -0700855 }
856
857 @Override
858 public ResolveInfo resolveActivityAsUser(Intent intent, int flags, int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800859 try {
860 return mPM.resolveIntent(
861 intent,
862 intent.resolveTypeIfNeeded(mContext.getContentResolver()),
Svetoslav Ganov58d37b52012-09-18 12:04:19 -0700863 flags,
864 userId);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800865 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700866 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800867 }
868 }
869
870 @Override
871 public List<ResolveInfo> queryIntentActivities(Intent intent,
872 int flags) {
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700873 return queryIntentActivitiesAsUser(intent, flags, mContext.getUserId());
Amith Yamasani151ec4c2012-09-07 19:25:16 -0700874 }
875
876 /** @hide Same as above but for a specific user */
877 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700878 @SuppressWarnings("unchecked")
Svetoslav Ganov58d37b52012-09-18 12:04:19 -0700879 public List<ResolveInfo> queryIntentActivitiesAsUser(Intent intent,
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700880 int flags, int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800881 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700882 ParceledListSlice<ResolveInfo> parceledList =
883 mPM.queryIntentActivities(intent,
884 intent.resolveTypeIfNeeded(mContext.getContentResolver()),
885 flags, userId);
886 if (parceledList == null) {
887 return Collections.emptyList();
888 }
889 return parceledList.getList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800890 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700891 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800892 }
893 }
894
895 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700896 @SuppressWarnings("unchecked")
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800897 public List<ResolveInfo> queryIntentActivityOptions(
898 ComponentName caller, Intent[] specifics, Intent intent,
899 int flags) {
900 final ContentResolver resolver = mContext.getContentResolver();
901
902 String[] specificTypes = null;
903 if (specifics != null) {
904 final int N = specifics.length;
905 for (int i=0; i<N; i++) {
906 Intent sp = specifics[i];
907 if (sp != null) {
908 String t = sp.resolveTypeIfNeeded(resolver);
909 if (t != null) {
910 if (specificTypes == null) {
911 specificTypes = new String[N];
912 }
913 specificTypes[i] = t;
914 }
915 }
916 }
917 }
918
919 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700920 ParceledListSlice<ResolveInfo> parceledList =
921 mPM.queryIntentActivityOptions(caller, specifics, specificTypes, intent,
922 intent.resolveTypeIfNeeded(resolver), flags, mContext.getUserId());
923 if (parceledList == null) {
924 return Collections.emptyList();
925 }
926 return parceledList.getList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800927 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700928 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800929 }
930 }
931
Amith Yamasanif203aee2012-08-29 18:41:53 -0700932 /**
933 * @hide
934 */
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800935 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700936 @SuppressWarnings("unchecked")
Jeff Sharkeye06b4d12016-01-06 14:51:50 -0700937 public List<ResolveInfo> queryBroadcastReceiversAsUser(Intent intent, int flags, int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800938 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700939 ParceledListSlice<ResolveInfo> parceledList =
940 mPM.queryIntentReceivers(intent,
941 intent.resolveTypeIfNeeded(mContext.getContentResolver()),
942 flags, userId);
943 if (parceledList == null) {
944 return Collections.emptyList();
945 }
946 return parceledList.getList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800947 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700948 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800949 }
950 }
951
952 @Override
Amith Yamasanif203aee2012-08-29 18:41:53 -0700953 public List<ResolveInfo> queryBroadcastReceivers(Intent intent, int flags) {
Jeff Sharkeye06b4d12016-01-06 14:51:50 -0700954 return queryBroadcastReceiversAsUser(intent, flags, mContext.getUserId());
Amith Yamasanif203aee2012-08-29 18:41:53 -0700955 }
956
957 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800958 public ResolveInfo resolveService(Intent intent, int flags) {
959 try {
960 return mPM.resolveService(
961 intent,
962 intent.resolveTypeIfNeeded(mContext.getContentResolver()),
Amith Yamasani483f3b02012-03-13 16:08:00 -0700963 flags,
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700964 mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800965 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700966 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800967 }
968 }
969
970 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700971 @SuppressWarnings("unchecked")
Svetoslav Ganov58d37b52012-09-18 12:04:19 -0700972 public List<ResolveInfo> queryIntentServicesAsUser(Intent intent, int flags, int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800973 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700974 ParceledListSlice<ResolveInfo> parceledList =
975 mPM.queryIntentServices(intent,
976 intent.resolveTypeIfNeeded(mContext.getContentResolver()),
977 flags, userId);
978 if (parceledList == null) {
979 return Collections.emptyList();
980 }
981 return parceledList.getList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800982 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700983 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800984 }
985 }
986
987 @Override
Svetoslav Ganov58d37b52012-09-18 12:04:19 -0700988 public List<ResolveInfo> queryIntentServices(Intent intent, int flags) {
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700989 return queryIntentServicesAsUser(intent, flags, mContext.getUserId());
Svetoslav Ganov58d37b52012-09-18 12:04:19 -0700990 }
991
992 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700993 @SuppressWarnings("unchecked")
Jeff Sharkey85f5f812013-10-07 10:16:12 -0700994 public List<ResolveInfo> queryIntentContentProvidersAsUser(
995 Intent intent, int flags, int userId) {
996 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700997 ParceledListSlice<ResolveInfo> parceledList =
998 mPM.queryIntentContentProviders(intent,
999 intent.resolveTypeIfNeeded(mContext.getContentResolver()),
1000 flags, userId);
1001 if (parceledList == null) {
1002 return Collections.emptyList();
1003 }
1004 return parceledList.getList();
Jeff Sharkey85f5f812013-10-07 10:16:12 -07001005 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001006 throw e.rethrowFromSystemServer();
Jeff Sharkey85f5f812013-10-07 10:16:12 -07001007 }
1008 }
1009
1010 @Override
1011 public List<ResolveInfo> queryIntentContentProviders(Intent intent, int flags) {
1012 return queryIntentContentProvidersAsUser(intent, flags, mContext.getUserId());
1013 }
1014
1015 @Override
Alexandra Gherghina0363c3e2014-06-23 13:34:59 +01001016 public ProviderInfo resolveContentProvider(String name, int flags) {
1017 return resolveContentProviderAsUser(name, flags, mContext.getUserId());
1018 }
1019
1020 /** @hide **/
1021 @Override
1022 public ProviderInfo resolveContentProviderAsUser(String name, int flags, int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001023 try {
Alexandra Gherghina0363c3e2014-06-23 13:34:59 +01001024 return mPM.resolveContentProvider(name, flags, userId);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001025 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001026 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001027 }
1028 }
1029
1030 @Override
1031 public List<ProviderInfo> queryContentProviders(String processName,
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001032 int uid, int flags) {
Makoto Onuki32757292017-02-22 14:36:59 -08001033 return queryContentProviders(processName, uid, flags, null);
1034 }
1035
1036 @Override
1037 @SuppressWarnings("unchecked")
1038 public List<ProviderInfo> queryContentProviders(String processName,
1039 int uid, int flags, String metaDataKey) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001040 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001041 ParceledListSlice<ProviderInfo> slice =
Makoto Onuki32757292017-02-22 14:36:59 -08001042 mPM.queryContentProviders(processName, uid, flags, metaDataKey);
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001043 return slice != null ? slice.getList() : Collections.<ProviderInfo>emptyList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001044 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001045 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001046 }
1047 }
1048
1049 @Override
1050 public InstrumentationInfo getInstrumentationInfo(
1051 ComponentName className, int flags)
1052 throws NameNotFoundException {
1053 try {
1054 InstrumentationInfo ii = mPM.getInstrumentationInfo(
1055 className, flags);
1056 if (ii != null) {
1057 return ii;
1058 }
1059 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001060 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001061 }
1062
1063 throw new NameNotFoundException(className.toString());
1064 }
1065
1066 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001067 @SuppressWarnings("unchecked")
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001068 public List<InstrumentationInfo> queryInstrumentation(
1069 String targetPackage, int flags) {
1070 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001071 ParceledListSlice<InstrumentationInfo> parceledList =
1072 mPM.queryInstrumentation(targetPackage, flags);
1073 if (parceledList == null) {
1074 return Collections.emptyList();
1075 }
1076 return parceledList.getList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001077 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001078 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001079 }
1080 }
1081
Alan Viveretteecd585a2015-04-13 10:32:51 -07001082 @Nullable
1083 @Override
1084 public Drawable getDrawable(String packageName, @DrawableRes int resId,
1085 @Nullable ApplicationInfo appInfo) {
1086 final ResourceName name = new ResourceName(packageName, resId);
1087 final Drawable cachedIcon = getCachedIcon(name);
1088 if (cachedIcon != null) {
1089 return cachedIcon;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001090 }
Alan Viveretteecd585a2015-04-13 10:32:51 -07001091
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001092 if (appInfo == null) {
1093 try {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001094 appInfo = getApplicationInfo(packageName, sDefaultFlags);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001095 } catch (NameNotFoundException e) {
1096 return null;
1097 }
1098 }
Alan Viveretteecd585a2015-04-13 10:32:51 -07001099
1100 if (resId != 0) {
1101 try {
1102 final Resources r = getResourcesForApplication(appInfo);
1103 final Drawable dr = r.getDrawable(resId, null);
1104 if (dr != null) {
1105 putCachedIcon(name, dr);
1106 }
1107
1108 if (false) {
1109 RuntimeException e = new RuntimeException("here");
1110 e.fillInStackTrace();
1111 Log.w(TAG, "Getting drawable 0x" + Integer.toHexString(resId)
1112 + " from package " + packageName
1113 + ": app scale=" + r.getCompatibilityInfo().applicationScale
1114 + ", caller scale=" + mContext.getResources()
1115 .getCompatibilityInfo().applicationScale,
1116 e);
1117 }
Ricky Wai3ce46252015-04-15 16:12:22 +01001118 if (DEBUG_ICONS) {
Alan Viveretteecd585a2015-04-13 10:32:51 -07001119 Log.v(TAG, "Getting drawable 0x"
1120 + Integer.toHexString(resId) + " from " + r
1121 + ": " + dr);
Ricky Wai3ce46252015-04-15 16:12:22 +01001122 }
1123 return dr;
Alan Viveretteecd585a2015-04-13 10:32:51 -07001124 } catch (NameNotFoundException e) {
1125 Log.w("PackageManager", "Failure retrieving resources for "
1126 + appInfo.packageName);
1127 } catch (Resources.NotFoundException e) {
1128 Log.w("PackageManager", "Failure retrieving resources for "
1129 + appInfo.packageName + ": " + e.getMessage());
1130 } catch (Exception e) {
1131 // If an exception was thrown, fall through to return
1132 // default icon.
1133 Log.w("PackageManager", "Failure retrieving icon 0x"
1134 + Integer.toHexString(resId) + " in package "
1135 + packageName, e);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001136 }
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001137 }
Alan Viveretteecd585a2015-04-13 10:32:51 -07001138
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001139 return null;
1140 }
1141
1142 @Override public Drawable getActivityIcon(ComponentName activityName)
1143 throws NameNotFoundException {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001144 return getActivityInfo(activityName, sDefaultFlags).loadIcon(this);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001145 }
1146
1147 @Override public Drawable getActivityIcon(Intent intent)
1148 throws NameNotFoundException {
1149 if (intent.getComponent() != null) {
1150 return getActivityIcon(intent.getComponent());
1151 }
1152
1153 ResolveInfo info = resolveActivity(
1154 intent, PackageManager.MATCH_DEFAULT_ONLY);
1155 if (info != null) {
1156 return info.activityInfo.loadIcon(this);
1157 }
1158
Romain Guy39fe17c2011-11-30 10:34:07 -08001159 throw new NameNotFoundException(intent.toUri(0));
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001160 }
1161
1162 @Override public Drawable getDefaultActivityIcon() {
1163 return Resources.getSystem().getDrawable(
1164 com.android.internal.R.drawable.sym_def_app_icon);
1165 }
1166
1167 @Override public Drawable getApplicationIcon(ApplicationInfo info) {
1168 return info.loadIcon(this);
1169 }
1170
1171 @Override public Drawable getApplicationIcon(String packageName)
1172 throws NameNotFoundException {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001173 return getApplicationIcon(getApplicationInfo(packageName, sDefaultFlags));
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001174 }
1175
1176 @Override
Jose Limaf78e3122014-03-06 12:13:15 -08001177 public Drawable getActivityBanner(ComponentName activityName)
1178 throws NameNotFoundException {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001179 return getActivityInfo(activityName, sDefaultFlags).loadBanner(this);
Jose Limaf78e3122014-03-06 12:13:15 -08001180 }
1181
1182 @Override
1183 public Drawable getActivityBanner(Intent intent)
1184 throws NameNotFoundException {
1185 if (intent.getComponent() != null) {
1186 return getActivityBanner(intent.getComponent());
1187 }
1188
1189 ResolveInfo info = resolveActivity(
1190 intent, PackageManager.MATCH_DEFAULT_ONLY);
1191 if (info != null) {
1192 return info.activityInfo.loadBanner(this);
1193 }
1194
1195 throw new NameNotFoundException(intent.toUri(0));
1196 }
1197
1198 @Override
1199 public Drawable getApplicationBanner(ApplicationInfo info) {
1200 return info.loadBanner(this);
1201 }
1202
1203 @Override
1204 public Drawable getApplicationBanner(String packageName)
1205 throws NameNotFoundException {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001206 return getApplicationBanner(getApplicationInfo(packageName, sDefaultFlags));
Jose Limaf78e3122014-03-06 12:13:15 -08001207 }
1208
1209 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001210 public Drawable getActivityLogo(ComponentName activityName)
1211 throws NameNotFoundException {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001212 return getActivityInfo(activityName, sDefaultFlags).loadLogo(this);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001213 }
1214
1215 @Override
1216 public Drawable getActivityLogo(Intent intent)
1217 throws NameNotFoundException {
1218 if (intent.getComponent() != null) {
1219 return getActivityLogo(intent.getComponent());
1220 }
1221
1222 ResolveInfo info = resolveActivity(
1223 intent, PackageManager.MATCH_DEFAULT_ONLY);
1224 if (info != null) {
1225 return info.activityInfo.loadLogo(this);
1226 }
1227
1228 throw new NameNotFoundException(intent.toUri(0));
1229 }
1230
1231 @Override
1232 public Drawable getApplicationLogo(ApplicationInfo info) {
1233 return info.loadLogo(this);
1234 }
1235
1236 @Override
1237 public Drawable getApplicationLogo(String packageName)
1238 throws NameNotFoundException {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001239 return getApplicationLogo(getApplicationInfo(packageName, sDefaultFlags));
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001240 }
1241
Svetoslavc7d62f02014-09-04 15:39:54 -07001242 @Override
1243 public Drawable getUserBadgedIcon(Drawable icon, UserHandle user) {
Kenny Guy02c89902016-11-15 19:36:38 +00001244 if (!isManagedProfile(user.getIdentifier())) {
Svetoslavc7d62f02014-09-04 15:39:54 -07001245 return icon;
1246 }
Kenny Guy02c89902016-11-15 19:36:38 +00001247 Drawable badgeShadow = getDrawable("system",
1248 com.android.internal.R.drawable.ic_corp_icon_badge_shadow, null);
1249 Drawable badgeColor = getDrawable("system",
1250 com.android.internal.R.drawable.ic_corp_icon_badge_color, null);
1251 badgeColor.setTint(getUserBadgeColor(user));
1252 Drawable badgeForeground = getDrawable("system",
1253 com.android.internal.R.drawable.ic_corp_icon_badge_case, null);
1254
1255 Drawable badge = new LayerDrawable(
1256 new Drawable[] {badgeShadow, badgeColor, badgeForeground });
1257 return getBadgedDrawable(icon, badge, null, true);
Svetoslavc7d62f02014-09-04 15:39:54 -07001258 }
1259
1260 @Override
1261 public Drawable getUserBadgedDrawableForDensity(Drawable drawable, UserHandle user,
1262 Rect badgeLocation, int badgeDensity) {
1263 Drawable badgeDrawable = getUserBadgeForDensity(user, badgeDensity);
1264 if (badgeDrawable == null) {
1265 return drawable;
1266 }
1267 return getBadgedDrawable(drawable, badgeDrawable, badgeLocation, true);
1268 }
1269
Kenny Guy02c89902016-11-15 19:36:38 +00001270 // Should have enough colors to cope with UserManagerService.getMaxManagedProfiles()
1271 @VisibleForTesting
1272 public static final int[] CORP_BADGE_COLORS = new int[] {
1273 com.android.internal.R.color.profile_badge_1,
1274 com.android.internal.R.color.profile_badge_2,
1275 com.android.internal.R.color.profile_badge_3
1276 };
1277
1278 @VisibleForTesting
1279 public static final int[] CORP_BADGE_LABEL_RES_ID = new int[] {
1280 com.android.internal.R.string.managed_profile_label_badge,
1281 com.android.internal.R.string.managed_profile_label_badge_2,
1282 com.android.internal.R.string.managed_profile_label_badge_3
1283 };
1284
1285 private int getUserBadgeColor(UserHandle user) {
1286 int badge = getUserManager().getManagedProfileBadge(user.getIdentifier());
1287 if (badge < 0) {
1288 badge = 0;
1289 }
1290 int resourceId = CORP_BADGE_COLORS[badge % CORP_BADGE_COLORS.length];
1291 return Resources.getSystem().getColor(resourceId, null);
1292 }
1293
Svetoslavc7d62f02014-09-04 15:39:54 -07001294 @Override
1295 public Drawable getUserBadgeForDensity(UserHandle user, int density) {
Kenny Guy02c89902016-11-15 19:36:38 +00001296 Drawable badgeColor = getManagedProfileIconForDensity(user,
1297 com.android.internal.R.drawable.ic_corp_badge_color, density);
1298 if (badgeColor == null) {
1299 return null;
1300 }
1301 badgeColor.setTint(getUserBadgeColor(user));
1302 Drawable badgeForeground = getDrawableForDensity(
1303 com.android.internal.R.drawable.ic_corp_badge_case, density);
1304 Drawable badge = new LayerDrawable(
1305 new Drawable[] {badgeColor, badgeForeground });
1306 return badge;
Selim Cineke6ff9462016-01-15 15:07:06 -08001307 }
1308
1309 @Override
1310 public Drawable getUserBadgeForDensityNoBackground(UserHandle user, int density) {
Kenny Guy02c89902016-11-15 19:36:38 +00001311 Drawable badge = getManagedProfileIconForDensity(user,
Vadim Tryshev66ae66a2016-02-18 15:41:21 -08001312 com.android.internal.R.drawable.ic_corp_badge_no_background, density);
Kenny Guy02c89902016-11-15 19:36:38 +00001313 if (badge != null) {
1314 badge.setTint(getUserBadgeColor(user));
1315 }
1316 return badge;
Selim Cineke6ff9462016-01-15 15:07:06 -08001317 }
1318
Vadim Tryshev66ae66a2016-02-18 15:41:21 -08001319 private Drawable getDrawableForDensity(int drawableId, int density) {
1320 if (density <= 0) {
1321 density = mContext.getResources().getDisplayMetrics().densityDpi;
1322 }
1323 return Resources.getSystem().getDrawableForDensity(drawableId, density);
1324 }
1325
1326 private Drawable getManagedProfileIconForDensity(UserHandle user, int drawableId, int density) {
Tony Mak8673b282016-03-21 21:10:59 +00001327 if (isManagedProfile(user.getIdentifier())) {
Vadim Tryshev66ae66a2016-02-18 15:41:21 -08001328 return getDrawableForDensity(drawableId, density);
Svetoslavc7d62f02014-09-04 15:39:54 -07001329 }
1330 return null;
1331 }
1332
1333 @Override
1334 public CharSequence getUserBadgedLabel(CharSequence label, UserHandle user) {
Tony Mak8673b282016-03-21 21:10:59 +00001335 if (isManagedProfile(user.getIdentifier())) {
Kenny Guy02c89902016-11-15 19:36:38 +00001336 int badge = getUserManager().getManagedProfileBadge(user.getIdentifier());
1337 int resourceId = CORP_BADGE_LABEL_RES_ID[badge % CORP_BADGE_LABEL_RES_ID.length];
1338 return Resources.getSystem().getString(resourceId, label);
Svetoslavc7d62f02014-09-04 15:39:54 -07001339 }
1340 return label;
1341 }
1342
Alan Viveretteecd585a2015-04-13 10:32:51 -07001343 @Override
1344 public Resources getResourcesForActivity(ComponentName activityName)
1345 throws NameNotFoundException {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001346 return getResourcesForApplication(
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001347 getActivityInfo(activityName, sDefaultFlags).applicationInfo);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001348 }
1349
Alan Viveretteecd585a2015-04-13 10:32:51 -07001350 @Override
1351 public Resources getResourcesForApplication(@NonNull ApplicationInfo app)
1352 throws NameNotFoundException {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001353 if (app.packageName.equals("system")) {
1354 return mContext.mMainThread.getSystemContext().getResources();
1355 }
Jeff Sharkey8a4c9722014-06-16 13:48:42 -07001356 final boolean sameUid = (app.uid == Process.myUid());
Adam Lesinski53fafdf2016-08-03 13:36:39 -07001357 final Resources r = mContext.mMainThread.getTopLevelResources(
Adam Lesinskic82f28a2016-06-08 17:19:09 -07001358 sameUid ? app.sourceDir : app.publicSourceDir,
1359 sameUid ? app.splitSourceDirs : app.splitPublicSourceDirs,
1360 app.resourceDirs, app.sharedLibraryFiles, Display.DEFAULT_DISPLAY,
1361 mContext.mPackageInfo);
Adam Lesinski53fafdf2016-08-03 13:36:39 -07001362 if (r != null) {
1363 return r;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001364 }
Adam Lesinski53fafdf2016-08-03 13:36:39 -07001365 throw new NameNotFoundException("Unable to open " + app.publicSourceDir);
1366
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001367 }
1368
Alan Viveretteecd585a2015-04-13 10:32:51 -07001369 @Override
1370 public Resources getResourcesForApplication(String appPackageName)
1371 throws NameNotFoundException {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001372 return getResourcesForApplication(
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001373 getApplicationInfo(appPackageName, sDefaultFlags));
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001374 }
1375
Amith Yamasani98edc952012-09-25 14:09:27 -07001376 /** @hide */
1377 @Override
1378 public Resources getResourcesForApplicationAsUser(String appPackageName, int userId)
1379 throws NameNotFoundException {
Jeff Sharkeyded653b2012-09-27 19:09:24 -07001380 if (userId < 0) {
1381 throw new IllegalArgumentException(
1382 "Call does not support special user #" + userId);
1383 }
1384 if ("system".equals(appPackageName)) {
1385 return mContext.mMainThread.getSystemContext().getResources();
1386 }
Amith Yamasani98edc952012-09-25 14:09:27 -07001387 try {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001388 ApplicationInfo ai = mPM.getApplicationInfo(appPackageName, sDefaultFlags, userId);
Amith Yamasani98edc952012-09-25 14:09:27 -07001389 if (ai != null) {
1390 return getResourcesForApplication(ai);
1391 }
1392 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001393 throw e.rethrowFromSystemServer();
Amith Yamasani98edc952012-09-25 14:09:27 -07001394 }
1395 throw new NameNotFoundException("Package " + appPackageName + " doesn't exist");
1396 }
1397
Jeff Sharkeycd654482016-01-08 17:42:11 -07001398 volatile int mCachedSafeMode = -1;
1399
1400 @Override
1401 public boolean isSafeMode() {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001402 try {
1403 if (mCachedSafeMode < 0) {
1404 mCachedSafeMode = mPM.isSafeMode() ? 1 : 0;
1405 }
1406 return mCachedSafeMode != 0;
1407 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001408 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001409 }
1410 }
1411
Svetoslavf7c06eb2015-06-10 18:43:22 -07001412 @Override
1413 public void addOnPermissionsChangeListener(OnPermissionsChangedListener listener) {
1414 synchronized (mPermissionListeners) {
1415 if (mPermissionListeners.get(listener) != null) {
1416 return;
1417 }
1418 OnPermissionsChangeListenerDelegate delegate =
1419 new OnPermissionsChangeListenerDelegate(listener, Looper.getMainLooper());
1420 try {
1421 mPM.addOnPermissionsChangeListener(delegate);
1422 mPermissionListeners.put(listener, delegate);
1423 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001424 throw e.rethrowFromSystemServer();
Svetoslavf7c06eb2015-06-10 18:43:22 -07001425 }
1426 }
1427 }
1428
1429 @Override
1430 public void removeOnPermissionsChangeListener(OnPermissionsChangedListener listener) {
1431 synchronized (mPermissionListeners) {
1432 IOnPermissionsChangeListener delegate = mPermissionListeners.get(listener);
1433 if (delegate != null) {
1434 try {
1435 mPM.removeOnPermissionsChangeListener(delegate);
1436 mPermissionListeners.remove(listener);
1437 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001438 throw e.rethrowFromSystemServer();
Svetoslavf7c06eb2015-06-10 18:43:22 -07001439 }
1440 }
1441 }
1442 }
1443
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001444 static void configurationChanged() {
1445 synchronized (sSync) {
1446 sIconCache.clear();
1447 sStringCache.clear();
1448 }
1449 }
1450
Yao Chen022b8ea2016-12-16 11:03:28 -08001451 protected ApplicationPackageManager(ContextImpl context,
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001452 IPackageManager pm) {
1453 mContext = context;
1454 mPM = pm;
1455 }
1456
Alan Viveretteecd585a2015-04-13 10:32:51 -07001457 @Nullable
1458 private Drawable getCachedIcon(@NonNull ResourceName name) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001459 synchronized (sSync) {
Alan Viveretteecd585a2015-04-13 10:32:51 -07001460 final WeakReference<Drawable.ConstantState> wr = sIconCache.get(name);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001461 if (DEBUG_ICONS) Log.v(TAG, "Get cached weak drawable ref for "
1462 + name + ": " + wr);
1463 if (wr != null) { // we have the activity
Alan Viveretteecd585a2015-04-13 10:32:51 -07001464 final Drawable.ConstantState state = wr.get();
Romain Guy39fe17c2011-11-30 10:34:07 -08001465 if (state != null) {
1466 if (DEBUG_ICONS) {
1467 Log.v(TAG, "Get cached drawable state for " + name + ": " + state);
1468 }
1469 // Note: It's okay here to not use the newDrawable(Resources) variant
1470 // of the API. The ConstantState comes from a drawable that was
1471 // originally created by passing the proper app Resources instance
1472 // which means the state should already contain the proper
1473 // resources specific information (like density.) See
1474 // BitmapDrawable.BitmapState for instance.
1475 return state.newDrawable();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001476 }
1477 // our entry has been purged
1478 sIconCache.remove(name);
1479 }
1480 }
1481 return null;
1482 }
1483
Alan Viveretteecd585a2015-04-13 10:32:51 -07001484 private void putCachedIcon(@NonNull ResourceName name, @NonNull Drawable dr) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001485 synchronized (sSync) {
Alan Viveretteecd585a2015-04-13 10:32:51 -07001486 sIconCache.put(name, new WeakReference<>(dr.getConstantState()));
Romain Guy39fe17c2011-11-30 10:34:07 -08001487 if (DEBUG_ICONS) Log.v(TAG, "Added cached drawable state for " + name + ": " + dr);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001488 }
1489 }
1490
Romain Guy39fe17c2011-11-30 10:34:07 -08001491 static void handlePackageBroadcast(int cmd, String[] pkgList, boolean hasPkgInfo) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001492 boolean immediateGc = false;
Sudheer Shankacc6418f2016-10-13 12:03:44 -07001493 if (cmd == ApplicationThreadConstants.EXTERNAL_STORAGE_UNAVAILABLE) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001494 immediateGc = true;
1495 }
1496 if (pkgList != null && (pkgList.length > 0)) {
1497 boolean needCleanup = false;
1498 for (String ssp : pkgList) {
1499 synchronized (sSync) {
Dianne Hackbornadd005c2013-07-17 18:43:12 -07001500 for (int i=sIconCache.size()-1; i>=0; i--) {
1501 ResourceName nm = sIconCache.keyAt(i);
1502 if (nm.packageName.equals(ssp)) {
1503 //Log.i(TAG, "Removing cached drawable for " + nm);
1504 sIconCache.removeAt(i);
1505 needCleanup = true;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001506 }
1507 }
Dianne Hackbornadd005c2013-07-17 18:43:12 -07001508 for (int i=sStringCache.size()-1; i>=0; i--) {
1509 ResourceName nm = sStringCache.keyAt(i);
1510 if (nm.packageName.equals(ssp)) {
1511 //Log.i(TAG, "Removing cached string for " + nm);
1512 sStringCache.removeAt(i);
1513 needCleanup = true;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001514 }
1515 }
1516 }
1517 }
1518 if (needCleanup || hasPkgInfo) {
1519 if (immediateGc) {
1520 // Schedule an immediate gc.
1521 Runtime.getRuntime().gc();
1522 } else {
1523 ActivityThread.currentActivityThread().scheduleGcIdler();
1524 }
1525 }
1526 }
1527 }
1528
1529 private static final class ResourceName {
1530 final String packageName;
1531 final int iconId;
1532
1533 ResourceName(String _packageName, int _iconId) {
1534 packageName = _packageName;
1535 iconId = _iconId;
1536 }
1537
1538 ResourceName(ApplicationInfo aInfo, int _iconId) {
1539 this(aInfo.packageName, _iconId);
1540 }
1541
1542 ResourceName(ComponentInfo cInfo, int _iconId) {
1543 this(cInfo.applicationInfo.packageName, _iconId);
1544 }
1545
1546 ResourceName(ResolveInfo rInfo, int _iconId) {
1547 this(rInfo.activityInfo.applicationInfo.packageName, _iconId);
1548 }
1549
1550 @Override
1551 public boolean equals(Object o) {
1552 if (this == o) return true;
1553 if (o == null || getClass() != o.getClass()) return false;
1554
1555 ResourceName that = (ResourceName) o;
1556
1557 if (iconId != that.iconId) return false;
1558 return !(packageName != null ?
1559 !packageName.equals(that.packageName) : that.packageName != null);
1560
1561 }
1562
1563 @Override
1564 public int hashCode() {
1565 int result;
1566 result = packageName.hashCode();
1567 result = 31 * result + iconId;
1568 return result;
1569 }
1570
1571 @Override
1572 public String toString() {
1573 return "{ResourceName " + packageName + " / " + iconId + "}";
1574 }
1575 }
1576
1577 private CharSequence getCachedString(ResourceName name) {
1578 synchronized (sSync) {
1579 WeakReference<CharSequence> wr = sStringCache.get(name);
1580 if (wr != null) { // we have the activity
1581 CharSequence cs = wr.get();
1582 if (cs != null) {
1583 return cs;
1584 }
1585 // our entry has been purged
1586 sStringCache.remove(name);
1587 }
1588 }
1589 return null;
1590 }
1591
1592 private void putCachedString(ResourceName name, CharSequence cs) {
1593 synchronized (sSync) {
1594 sStringCache.put(name, new WeakReference<CharSequence>(cs));
1595 }
1596 }
1597
1598 @Override
Tor Norbye7b9c9122013-05-30 16:48:33 -07001599 public CharSequence getText(String packageName, @StringRes int resid,
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001600 ApplicationInfo appInfo) {
1601 ResourceName name = new ResourceName(packageName, resid);
1602 CharSequence text = getCachedString(name);
1603 if (text != null) {
1604 return text;
1605 }
1606 if (appInfo == null) {
1607 try {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001608 appInfo = getApplicationInfo(packageName, sDefaultFlags);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001609 } catch (NameNotFoundException e) {
1610 return null;
1611 }
1612 }
1613 try {
1614 Resources r = getResourcesForApplication(appInfo);
1615 text = r.getText(resid);
1616 putCachedString(name, text);
1617 return text;
1618 } catch (NameNotFoundException e) {
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07001619 Log.w("PackageManager", "Failure retrieving resources for "
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001620 + appInfo.packageName);
1621 } catch (RuntimeException e) {
1622 // If an exception was thrown, fall through to return
1623 // default icon.
1624 Log.w("PackageManager", "Failure retrieving text 0x"
1625 + Integer.toHexString(resid) + " in package "
1626 + packageName, e);
1627 }
1628 return null;
1629 }
1630
1631 @Override
Tor Norbye7b9c9122013-05-30 16:48:33 -07001632 public XmlResourceParser getXml(String packageName, @XmlRes int resid,
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001633 ApplicationInfo appInfo) {
1634 if (appInfo == null) {
1635 try {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001636 appInfo = getApplicationInfo(packageName, sDefaultFlags);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001637 } catch (NameNotFoundException e) {
1638 return null;
1639 }
1640 }
1641 try {
1642 Resources r = getResourcesForApplication(appInfo);
1643 return r.getXml(resid);
1644 } catch (RuntimeException e) {
1645 // If an exception was thrown, fall through to return
1646 // default icon.
1647 Log.w("PackageManager", "Failure retrieving xml 0x"
1648 + Integer.toHexString(resid) + " in package "
1649 + packageName, e);
1650 } catch (NameNotFoundException e) {
Alon Albert3fa51e32010-11-11 09:24:04 -08001651 Log.w("PackageManager", "Failure retrieving resources for "
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001652 + appInfo.packageName);
1653 }
1654 return null;
1655 }
1656
1657 @Override
1658 public CharSequence getApplicationLabel(ApplicationInfo info) {
1659 return info.loadLabel(this);
1660 }
1661
1662 @Override
1663 public void installPackage(Uri packageURI, IPackageInstallObserver observer, int flags,
1664 String installerPackageName) {
Jeff Sharkey513a0742014-07-08 17:10:32 -07001665 installCommon(packageURI, new LegacyPackageInstallObserver(observer), flags,
Todd Kennedya6793232016-02-24 22:46:00 +00001666 installerPackageName, mContext.getUserId());
Christopher Tatef1977b42014-03-24 16:25:51 -07001667 }
1668
Christopher Tatef1977b42014-03-24 16:25:51 -07001669 @Override
1670 public void installPackage(Uri packageURI, PackageInstallObserver observer,
1671 int flags, String installerPackageName) {
Todd Kennedya6793232016-02-24 22:46:00 +00001672 installCommon(packageURI, observer, flags, installerPackageName, mContext.getUserId());
Jeff Sharkey513a0742014-07-08 17:10:32 -07001673 }
1674
1675 private void installCommon(Uri packageURI,
1676 PackageInstallObserver observer, int flags, String installerPackageName,
Nicolas Prevot9a80e532015-09-23 15:49:28 +01001677 int userId) {
Jeff Sharkey513a0742014-07-08 17:10:32 -07001678 if (!"file".equals(packageURI.getScheme())) {
1679 throw new UnsupportedOperationException("Only file:// URIs are supported");
1680 }
Jeff Sharkey513a0742014-07-08 17:10:32 -07001681
1682 final String originPath = packageURI.getPath();
Christopher Tatef1977b42014-03-24 16:25:51 -07001683 try {
Nicolas Prevot9a80e532015-09-23 15:49:28 +01001684 mPM.installPackageAsUser(originPath, observer.getBinder(), flags, installerPackageName,
Todd Kennedya6793232016-02-24 22:46:00 +00001685 userId);
Jeff Sharkey27b2e692016-02-25 17:40:12 -07001686 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001687 throw e.rethrowFromSystemServer();
rich cannings706e8ba2012-08-20 13:20:14 -07001688 }
1689 }
1690
1691 @Override
Nicolas Prevot9a80e532015-09-23 15:49:28 +01001692 public int installExistingPackage(String packageName) throws NameNotFoundException {
Robin Lee0e27c872015-09-28 14:37:40 +01001693 return installExistingPackageAsUser(packageName, mContext.getUserId());
Nicolas Prevot9a80e532015-09-23 15:49:28 +01001694 }
1695
1696 @Override
1697 public int installExistingPackageAsUser(String packageName, int userId)
Dianne Hackborn7767eac2012-08-23 18:25:40 -07001698 throws NameNotFoundException {
1699 try {
Todd Kennedybe0b8892017-02-15 14:13:52 -08001700 int res = mPM.installExistingPackageAsUser(packageName, userId, 0 /*installFlags*/,
Bartosz Fabianowskia34f53f2017-01-11 18:08:47 +01001701 PackageManager.INSTALL_REASON_UNKNOWN);
Dianne Hackborn7767eac2012-08-23 18:25:40 -07001702 if (res == INSTALL_FAILED_INVALID_URI) {
1703 throw new NameNotFoundException("Package " + packageName + " doesn't exist");
1704 }
1705 return res;
1706 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001707 throw e.rethrowFromSystemServer();
Dianne Hackborn7767eac2012-08-23 18:25:40 -07001708 }
1709 }
1710
1711 @Override
Kenny Root3a9b5fb2011-09-20 14:15:38 -07001712 public void verifyPendingInstall(int id, int response) {
Kenny Root5ab21572011-07-27 11:11:19 -07001713 try {
Kenny Root3a9b5fb2011-09-20 14:15:38 -07001714 mPM.verifyPendingInstall(id, response);
Kenny Root5ab21572011-07-27 11:11:19 -07001715 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001716 throw e.rethrowFromSystemServer();
Kenny Root5ab21572011-07-27 11:11:19 -07001717 }
1718 }
1719
1720 @Override
rich canningsd9ef3e52012-08-22 14:28:05 -07001721 public void extendVerificationTimeout(int id, int verificationCodeAtTimeout,
1722 long millisecondsToDelay) {
1723 try {
1724 mPM.extendVerificationTimeout(id, verificationCodeAtTimeout, millisecondsToDelay);
1725 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001726 throw e.rethrowFromSystemServer();
rich canningsd9ef3e52012-08-22 14:28:05 -07001727 }
1728 }
1729
1730 @Override
Todd Kennedydfa93ab2016-03-03 15:24:33 -08001731 public void verifyIntentFilter(int id, int verificationCode, List<String> failedDomains) {
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001732 try {
Todd Kennedydfa93ab2016-03-03 15:24:33 -08001733 mPM.verifyIntentFilter(id, verificationCode, failedDomains);
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001734 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001735 throw e.rethrowFromSystemServer();
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001736 }
1737 }
1738
1739 @Override
Jeff Sharkeye06b4d12016-01-06 14:51:50 -07001740 public int getIntentVerificationStatusAsUser(String packageName, int userId) {
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001741 try {
1742 return mPM.getIntentVerificationStatus(packageName, userId);
1743 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001744 throw e.rethrowFromSystemServer();
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001745 }
1746 }
1747
1748 @Override
Jeff Sharkeye06b4d12016-01-06 14:51:50 -07001749 public boolean updateIntentVerificationStatusAsUser(String packageName, int status, int userId) {
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001750 try {
1751 return mPM.updateIntentVerificationStatus(packageName, status, userId);
1752 } 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
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001758 @SuppressWarnings("unchecked")
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001759 public List<IntentFilterVerificationInfo> getIntentFilterVerifications(String packageName) {
1760 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001761 ParceledListSlice<IntentFilterVerificationInfo> parceledList =
1762 mPM.getIntentFilterVerifications(packageName);
1763 if (parceledList == null) {
1764 return Collections.emptyList();
1765 }
1766 return parceledList.getList();
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001767 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001768 throw e.rethrowFromSystemServer();
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001769 }
1770 }
1771
1772 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001773 @SuppressWarnings("unchecked")
Fabrice Di Meglio07885952015-04-06 19:41:28 -07001774 public List<IntentFilter> getAllIntentFilters(String packageName) {
1775 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001776 ParceledListSlice<IntentFilter> parceledList =
1777 mPM.getAllIntentFilters(packageName);
1778 if (parceledList == null) {
1779 return Collections.emptyList();
1780 }
1781 return parceledList.getList();
Fabrice Di Meglio07885952015-04-06 19:41:28 -07001782 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001783 throw e.rethrowFromSystemServer();
Fabrice Di Meglio07885952015-04-06 19:41:28 -07001784 }
1785 }
1786
1787 @Override
Jeff Sharkeye06b4d12016-01-06 14:51:50 -07001788 public String getDefaultBrowserPackageNameAsUser(int userId) {
Fabrice Di Meglio62271722015-04-10 17:24:02 -07001789 try {
1790 return mPM.getDefaultBrowserPackageName(userId);
1791 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001792 throw e.rethrowFromSystemServer();
Fabrice Di Meglio62271722015-04-10 17:24:02 -07001793 }
1794 }
1795
1796 @Override
Jeff Sharkeye06b4d12016-01-06 14:51:50 -07001797 public boolean setDefaultBrowserPackageNameAsUser(String packageName, int userId) {
Fabrice Di Meglio62271722015-04-10 17:24:02 -07001798 try {
1799 return mPM.setDefaultBrowserPackageName(packageName, userId);
1800 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001801 throw e.rethrowFromSystemServer();
Fabrice Di Meglio62271722015-04-10 17:24:02 -07001802 }
1803 }
1804
1805 @Override
Dianne Hackborn880119b2010-11-18 22:26:40 -08001806 public void setInstallerPackageName(String targetPackage,
1807 String installerPackageName) {
1808 try {
1809 mPM.setInstallerPackageName(targetPackage, installerPackageName);
1810 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001811 throw e.rethrowFromSystemServer();
Dianne Hackborn880119b2010-11-18 22:26:40 -08001812 }
1813 }
1814
1815 @Override
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001816 public String getInstallerPackageName(String packageName) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001817 try {
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001818 return mPM.getInstallerPackageName(packageName);
1819 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001820 throw e.rethrowFromSystemServer();
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001821 }
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001822 }
1823
1824 @Override
1825 public int getMoveStatus(int moveId) {
1826 try {
1827 return mPM.getMoveStatus(moveId);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001828 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001829 throw e.rethrowFromSystemServer();
Jeff Sharkeyb2b9ab82015-04-05 21:10:42 -07001830 }
1831 }
1832
1833 @Override
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001834 public void registerMoveCallback(MoveCallback callback, Handler handler) {
1835 synchronized (mDelegates) {
1836 final MoveCallbackDelegate delegate = new MoveCallbackDelegate(callback,
1837 handler.getLooper());
1838 try {
1839 mPM.registerMoveCallback(delegate);
1840 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001841 throw e.rethrowFromSystemServer();
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001842 }
1843 mDelegates.add(delegate);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001844 }
1845 }
1846
1847 @Override
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001848 public void unregisterMoveCallback(MoveCallback callback) {
1849 synchronized (mDelegates) {
1850 for (Iterator<MoveCallbackDelegate> i = mDelegates.iterator(); i.hasNext();) {
1851 final MoveCallbackDelegate delegate = i.next();
1852 if (delegate.mCallback == callback) {
1853 try {
1854 mPM.unregisterMoveCallback(delegate);
1855 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001856 throw e.rethrowFromSystemServer();
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001857 }
1858 i.remove();
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001859 }
1860 }
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001861 }
1862 }
1863
1864 @Override
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001865 public int movePackage(String packageName, VolumeInfo vol) {
1866 try {
1867 final String volumeUuid;
1868 if (VolumeInfo.ID_PRIVATE_INTERNAL.equals(vol.id)) {
1869 volumeUuid = StorageManager.UUID_PRIVATE_INTERNAL;
1870 } else if (vol.isPrimaryPhysical()) {
1871 volumeUuid = StorageManager.UUID_PRIMARY_PHYSICAL;
1872 } else {
1873 volumeUuid = Preconditions.checkNotNull(vol.fsUuid);
1874 }
1875
1876 return mPM.movePackage(packageName, volumeUuid);
1877 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001878 throw e.rethrowFromSystemServer();
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001879 }
1880 }
1881
1882 @Override
1883 public @Nullable VolumeInfo getPackageCurrentVolume(ApplicationInfo app) {
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001884 final StorageManager storage = mContext.getSystemService(StorageManager.class);
Yao Chen022b8ea2016-12-16 11:03:28 -08001885 return getPackageCurrentVolume(app, storage);
1886 }
1887
1888 @VisibleForTesting
1889 protected @Nullable VolumeInfo getPackageCurrentVolume(ApplicationInfo app,
1890 StorageManager storage) {
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001891 if (app.isInternal()) {
1892 return storage.findVolumeById(VolumeInfo.ID_PRIVATE_INTERNAL);
1893 } else if (app.isExternalAsec()) {
1894 return storage.getPrimaryPhysicalVolume();
1895 } else {
1896 return storage.findVolumeByUuid(app.volumeUuid);
1897 }
1898 }
1899
1900 @Override
1901 public @NonNull List<VolumeInfo> getPackageCandidateVolumes(ApplicationInfo app) {
Yao Chen022b8ea2016-12-16 11:03:28 -08001902 final StorageManager storageManager = mContext.getSystemService(StorageManager.class);
1903 return getPackageCandidateVolumes(app, storageManager, mPM);
1904 }
1905
1906 @VisibleForTesting
1907 protected @NonNull List<VolumeInfo> getPackageCandidateVolumes(ApplicationInfo app,
1908 StorageManager storageManager, IPackageManager pm) {
1909 final VolumeInfo currentVol = getPackageCurrentVolume(app, storageManager);
1910 final List<VolumeInfo> vols = storageManager.getVolumes();
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001911 final List<VolumeInfo> candidates = new ArrayList<>();
1912 for (VolumeInfo vol : vols) {
Yao Chen022b8ea2016-12-16 11:03:28 -08001913 if (Objects.equals(vol, currentVol)
1914 || isPackageCandidateVolume(mContext, app, vol, pm)) {
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001915 candidates.add(vol);
1916 }
1917 }
1918 return candidates;
1919 }
1920
Yao Chen022b8ea2016-12-16 11:03:28 -08001921 @VisibleForTesting
1922 protected boolean isForceAllowOnExternal(Context context) {
1923 return Settings.Global.getInt(
Todd Kennedyf39ca8f2015-08-07 14:15:07 -07001924 context.getContentResolver(), Settings.Global.FORCE_ALLOW_ON_EXTERNAL, 0) != 0;
Yao Chen022b8ea2016-12-16 11:03:28 -08001925 }
1926
1927 @VisibleForTesting
1928 protected boolean isAllow3rdPartyOnInternal(Context context) {
1929 return context.getResources().getBoolean(
1930 com.android.internal.R.bool.config_allow3rdPartyAppOnInternal);
1931 }
1932
1933 private boolean isPackageCandidateVolume(
1934 ContextImpl context, ApplicationInfo app, VolumeInfo vol, IPackageManager pm) {
1935 final boolean forceAllowOnExternal = isForceAllowOnExternal(context);
1936
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001937 if (VolumeInfo.ID_PRIVATE_INTERNAL.equals(vol.getId())) {
Yao Chen022b8ea2016-12-16 11:03:28 -08001938 return app.isSystemApp() || isAllow3rdPartyOnInternal(context);
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001939 }
1940
1941 // System apps and apps demanding internal storage can't be moved
1942 // anywhere else
Todd Kennedyf39ca8f2015-08-07 14:15:07 -07001943 if (app.isSystemApp()) {
1944 return false;
1945 }
1946 if (!forceAllowOnExternal
Dianne Hackborn30a4e6d2015-10-12 17:14:56 -07001947 && (app.installLocation == PackageInfo.INSTALL_LOCATION_INTERNAL_ONLY
1948 || app.installLocation == PackageInfo.INSTALL_LOCATION_UNSPECIFIED)) {
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001949 return false;
1950 }
1951
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001952 // Gotta be able to write there
1953 if (!vol.isMountedWritable()) {
1954 return false;
1955 }
1956
1957 // Moving into an ASEC on public primary is only option internal
1958 if (vol.isPrimaryPhysical()) {
1959 return app.isInternal();
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001960 }
1961
Makoto Onukif34db0a2016-02-17 11:17:15 -08001962 // Some apps can't be moved. (e.g. device admins)
1963 try {
Yao Chen022b8ea2016-12-16 11:03:28 -08001964 if (pm.isPackageDeviceAdminOnAnyUser(app.packageName)) {
Makoto Onukif34db0a2016-02-17 11:17:15 -08001965 return false;
1966 }
1967 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001968 throw e.rethrowFromSystemServer();
Makoto Onukif34db0a2016-02-17 11:17:15 -08001969 }
1970
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001971 // Otherwise we can move to any private volume
1972 return (vol.getType() == VolumeInfo.TYPE_PRIVATE);
1973 }
1974
1975 @Override
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001976 public int movePrimaryStorage(VolumeInfo vol) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001977 try {
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001978 final String volumeUuid;
1979 if (VolumeInfo.ID_PRIVATE_INTERNAL.equals(vol.id)) {
1980 volumeUuid = StorageManager.UUID_PRIVATE_INTERNAL;
1981 } else if (vol.isPrimaryPhysical()) {
1982 volumeUuid = StorageManager.UUID_PRIMARY_PHYSICAL;
1983 } else {
1984 volumeUuid = Preconditions.checkNotNull(vol.fsUuid);
1985 }
1986
1987 return mPM.movePrimaryStorage(volumeUuid);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001988 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001989 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001990 }
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001991 }
1992
Jeff Sharkey275e3e42015-04-24 16:10:32 -07001993 @Override
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001994 public @Nullable VolumeInfo getPrimaryStorageCurrentVolume() {
1995 final StorageManager storage = mContext.getSystemService(StorageManager.class);
1996 final String volumeUuid = storage.getPrimaryStorageUuid();
Jeff Sharkey50a05452015-04-29 11:24:52 -07001997 return storage.findVolumeByQualifiedUuid(volumeUuid);
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001998 }
1999
Jeff Sharkey275e3e42015-04-24 16:10:32 -07002000 @Override
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002001 public @NonNull List<VolumeInfo> getPrimaryStorageCandidateVolumes() {
2002 final StorageManager storage = mContext.getSystemService(StorageManager.class);
2003 final VolumeInfo currentVol = getPrimaryStorageCurrentVolume();
2004 final List<VolumeInfo> vols = storage.getVolumes();
2005 final List<VolumeInfo> candidates = new ArrayList<>();
Jeff Sharkeyfced5342015-05-10 14:53:34 -07002006 if (Objects.equals(StorageManager.UUID_PRIMARY_PHYSICAL,
2007 storage.getPrimaryStorageUuid()) && currentVol != null) {
2008 // TODO: support moving primary physical to emulated volume
2009 candidates.add(currentVol);
2010 } else {
2011 for (VolumeInfo vol : vols) {
2012 if (Objects.equals(vol, currentVol) || isPrimaryStorageCandidateVolume(vol)) {
2013 candidates.add(vol);
2014 }
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002015 }
2016 }
2017 return candidates;
2018 }
2019
2020 private static boolean isPrimaryStorageCandidateVolume(VolumeInfo vol) {
2021 // Private internal is always an option
2022 if (VolumeInfo.ID_PRIVATE_INTERNAL.equals(vol.getId())) {
2023 return true;
2024 }
2025
2026 // Gotta be able to write there
2027 if (!vol.isMountedWritable()) {
2028 return false;
2029 }
2030
Jeff Sharkeyfced5342015-05-10 14:53:34 -07002031 // We can move to any private volume
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002032 return (vol.getType() == VolumeInfo.TYPE_PRIVATE);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002033 }
2034
2035 @Override
2036 public void deletePackage(String packageName, IPackageDeleteObserver observer, int flags) {
Robin Lee0e27c872015-09-28 14:37:40 +01002037 deletePackageAsUser(packageName, observer, flags, mContext.getUserId());
Nicolas Prevot9a80e532015-09-23 15:49:28 +01002038 }
2039
2040 @Override
Svet Ganov67882122016-12-11 16:36:34 -08002041 public void deletePackageAsUser(String packageName, IPackageDeleteObserver observer,
2042 int flags, int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002043 try {
Svet Ganov67882122016-12-11 16:36:34 -08002044 mPM.deletePackageAsUser(packageName, PackageManager.VERSION_CODE_HIGHEST,
2045 observer, userId, flags);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002046 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002047 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002048 }
2049 }
Jeff Sharkeyfbd0e9f2014-08-06 16:34:34 -07002050
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002051 @Override
2052 public void clearApplicationUserData(String packageName,
2053 IPackageDataObserver observer) {
2054 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -07002055 mPM.clearApplicationUserData(packageName, observer, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002056 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002057 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002058 }
2059 }
2060 @Override
2061 public void deleteApplicationCacheFiles(String packageName,
2062 IPackageDataObserver observer) {
2063 try {
2064 mPM.deleteApplicationCacheFiles(packageName, observer);
2065 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002066 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002067 }
2068 }
Jeff Sharkey529f91f2015-04-18 20:23:13 -07002069
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002070 @Override
Suprabh Shukla78c9eb82016-04-12 15:51:35 -07002071 public void deleteApplicationCacheFilesAsUser(String packageName, int userId,
2072 IPackageDataObserver observer) {
2073 try {
2074 mPM.deleteApplicationCacheFilesAsUser(packageName, userId, observer);
2075 } catch (RemoteException e) {
2076 throw e.rethrowFromSystemServer();
2077 }
2078 }
2079
2080 @Override
Jeff Sharkey529f91f2015-04-18 20:23:13 -07002081 public void freeStorageAndNotify(String volumeUuid, long idealStorageSize,
2082 IPackageDataObserver observer) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002083 try {
Jeff Sharkey529f91f2015-04-18 20:23:13 -07002084 mPM.freeStorageAndNotify(volumeUuid, idealStorageSize, observer);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002085 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002086 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002087 }
2088 }
2089
2090 @Override
Jeff Sharkey529f91f2015-04-18 20:23:13 -07002091 public void freeStorage(String volumeUuid, long freeStorageSize, IntentSender pi) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002092 try {
Jeff Sharkey529f91f2015-04-18 20:23:13 -07002093 mPM.freeStorage(volumeUuid, freeStorageSize, pi);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002094 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002095 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002096 }
2097 }
2098
2099 @Override
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00002100 public String[] setPackagesSuspendedAsUser(String[] packageNames, boolean suspended,
2101 int userId) {
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00002102 try {
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00002103 return mPM.setPackagesSuspendedAsUser(packageNames, suspended, userId);
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00002104 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002105 throw e.rethrowFromSystemServer();
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00002106 }
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00002107 }
2108
2109 @Override
Andrei Stingaceanu355b2322016-02-12 16:43:51 +00002110 public boolean isPackageSuspendedForUser(String packageName, int userId) {
2111 try {
2112 return mPM.isPackageSuspendedForUser(packageName, userId);
2113 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002114 throw e.rethrowFromSystemServer();
Andrei Stingaceanu355b2322016-02-12 16:43:51 +00002115 }
Andrei Stingaceanu355b2322016-02-12 16:43:51 +00002116 }
2117
Jeff Sharkey9bc89af2017-01-11 11:25:50 -07002118 /** @hide */
2119 @Override
2120 public void setApplicationCategoryHint(String packageName, int categoryHint) {
2121 try {
2122 mPM.setApplicationCategoryHint(packageName, categoryHint,
2123 mContext.getOpPackageName());
2124 } catch (RemoteException e) {
2125 throw e.rethrowFromSystemServer();
2126 }
2127 }
2128
Andrei Stingaceanu355b2322016-02-12 16:43:51 +00002129 @Override
Jeff Sharkeye06b4d12016-01-06 14:51:50 -07002130 public void getPackageSizeInfoAsUser(String packageName, int userHandle,
Dianne Hackborn0c380492012-08-20 17:23:30 -07002131 IPackageStatsObserver observer) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002132 try {
Dianne Hackborn0c380492012-08-20 17:23:30 -07002133 mPM.getPackageSizeInfo(packageName, userHandle, observer);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002134 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002135 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002136 }
2137 }
Jeff Sharkeyd5896632016-03-04 16:16:00 -07002138
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002139 @Override
2140 public void addPackageToPreferred(String packageName) {
Jeff Sharkeyd5896632016-03-04 16:16:00 -07002141 Log.w(TAG, "addPackageToPreferred() is a no-op");
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002142 }
2143
2144 @Override
2145 public void removePackageFromPreferred(String packageName) {
Jeff Sharkeyd5896632016-03-04 16:16:00 -07002146 Log.w(TAG, "removePackageFromPreferred() is a no-op");
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002147 }
2148
2149 @Override
2150 public List<PackageInfo> getPreferredPackages(int flags) {
Jeff Sharkeyd5896632016-03-04 16:16:00 -07002151 Log.w(TAG, "getPreferredPackages() is a no-op");
2152 return Collections.emptyList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002153 }
2154
2155 @Override
2156 public void addPreferredActivity(IntentFilter filter,
2157 int match, ComponentName[] set, ComponentName activity) {
2158 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -07002159 mPM.addPreferredActivity(filter, match, set, activity, mContext.getUserId());
Amith Yamasania3f133a2012-08-09 17:11:28 -07002160 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002161 throw e.rethrowFromSystemServer();
Amith Yamasania3f133a2012-08-09 17:11:28 -07002162 }
2163 }
2164
2165 @Override
Jeff Sharkeye06b4d12016-01-06 14:51:50 -07002166 public void addPreferredActivityAsUser(IntentFilter filter, int match,
Amith Yamasania3f133a2012-08-09 17:11:28 -07002167 ComponentName[] set, ComponentName activity, int userId) {
2168 try {
2169 mPM.addPreferredActivity(filter, match, set, activity, userId);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002170 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002171 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002172 }
2173 }
2174
2175 @Override
2176 public void replacePreferredActivity(IntentFilter filter,
2177 int match, ComponentName[] set, ComponentName activity) {
2178 try {
Robin Lee0e27c872015-09-28 14:37:40 +01002179 mPM.replacePreferredActivity(filter, match, set, activity, mContext.getUserId());
Amith Yamasani41c1ded2014-08-05 11:15:05 -07002180 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002181 throw e.rethrowFromSystemServer();
Amith Yamasani41c1ded2014-08-05 11:15:05 -07002182 }
2183 }
2184
2185 @Override
2186 public void replacePreferredActivityAsUser(IntentFilter filter,
2187 int match, ComponentName[] set, ComponentName activity,
2188 int userId) {
2189 try {
2190 mPM.replacePreferredActivity(filter, match, set, activity, userId);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002191 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002192 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002193 }
2194 }
2195
2196 @Override
2197 public void clearPackagePreferredActivities(String packageName) {
2198 try {
2199 mPM.clearPackagePreferredActivities(packageName);
2200 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002201 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002202 }
2203 }
2204
2205 @Override
2206 public int getPreferredActivities(List<IntentFilter> outFilters,
2207 List<ComponentName> outActivities, String packageName) {
2208 try {
2209 return mPM.getPreferredActivities(outFilters, outActivities, packageName);
2210 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002211 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002212 }
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002213 }
2214
2215 @Override
Christopher Tatea2a0850d2013-09-05 16:38:58 -07002216 public ComponentName getHomeActivities(List<ResolveInfo> outActivities) {
2217 try {
2218 return mPM.getHomeActivities(outActivities);
2219 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002220 throw e.rethrowFromSystemServer();
Christopher Tatea2a0850d2013-09-05 16:38:58 -07002221 }
Christopher Tatea2a0850d2013-09-05 16:38:58 -07002222 }
2223
2224 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002225 public void setComponentEnabledSetting(ComponentName componentName,
2226 int newState, int flags) {
2227 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -07002228 mPM.setComponentEnabledSetting(componentName, newState, flags, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002229 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002230 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002231 }
2232 }
2233
2234 @Override
2235 public int getComponentEnabledSetting(ComponentName componentName) {
2236 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -07002237 return mPM.getComponentEnabledSetting(componentName, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002238 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002239 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002240 }
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002241 }
2242
2243 @Override
2244 public void setApplicationEnabledSetting(String packageName,
2245 int newState, int flags) {
2246 try {
Dianne Hackborn3fa3c28a2013-03-26 16:15:41 -07002247 mPM.setApplicationEnabledSetting(packageName, newState, flags,
Dianne Hackborn95d78532013-09-11 09:51:14 -07002248 mContext.getUserId(), mContext.getOpPackageName());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002249 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002250 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002251 }
2252 }
2253
2254 @Override
2255 public int getApplicationEnabledSetting(String packageName) {
2256 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -07002257 return mPM.getApplicationEnabledSetting(packageName, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002258 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002259 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002260 }
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002261 }
2262
Amith Yamasani655d0e22013-06-12 14:19:10 -07002263 @Override
Sudheer Shankabbb3ff22015-07-09 15:39:23 +01002264 public void flushPackageRestrictionsAsUser(int userId) {
2265 try {
2266 mPM.flushPackageRestrictionsAsUser(userId);
2267 } catch (RemoteException e) {
2268 throw e.rethrowFromSystemServer();
2269 }
2270 }
2271
2272 @Override
Amith Yamasanie5bcff62014-07-19 15:44:09 -07002273 public boolean setApplicationHiddenSettingAsUser(String packageName, boolean hidden,
Amith Yamasani655d0e22013-06-12 14:19:10 -07002274 UserHandle user) {
2275 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07002276 return mPM.setApplicationHiddenSettingAsUser(packageName, hidden,
Amith Yamasani655d0e22013-06-12 14:19:10 -07002277 user.getIdentifier());
Jeff Sharkey27b2e692016-02-25 17:40:12 -07002278 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002279 throw e.rethrowFromSystemServer();
Amith Yamasani655d0e22013-06-12 14:19:10 -07002280 }
Amith Yamasani655d0e22013-06-12 14:19:10 -07002281 }
2282
2283 @Override
Amith Yamasanie5bcff62014-07-19 15:44:09 -07002284 public boolean getApplicationHiddenSettingAsUser(String packageName, UserHandle user) {
Amith Yamasani655d0e22013-06-12 14:19:10 -07002285 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07002286 return mPM.getApplicationHiddenSettingAsUser(packageName, user.getIdentifier());
Jeff Sharkey27b2e692016-02-25 17:40:12 -07002287 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002288 throw e.rethrowFromSystemServer();
Amith Yamasani655d0e22013-06-12 14:19:10 -07002289 }
Amith Yamasani655d0e22013-06-12 14:19:10 -07002290 }
2291
dcashmanc6f22492014-08-14 09:54:51 -07002292 /** @hide */
dcashman9d2f4412014-06-09 09:27:54 -07002293 @Override
2294 public KeySet getKeySetByAlias(String packageName, String alias) {
2295 Preconditions.checkNotNull(packageName);
2296 Preconditions.checkNotNull(alias);
dcashman9d2f4412014-06-09 09:27:54 -07002297 try {
Jeff Sharkey27b2e692016-02-25 17:40:12 -07002298 return mPM.getKeySetByAlias(packageName, alias);
dcashman9d2f4412014-06-09 09:27:54 -07002299 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002300 throw e.rethrowFromSystemServer();
dcashman9d2f4412014-06-09 09:27:54 -07002301 }
dcashman9d2f4412014-06-09 09:27:54 -07002302 }
2303
dcashmanc6f22492014-08-14 09:54:51 -07002304 /** @hide */
dcashman9d2f4412014-06-09 09:27:54 -07002305 @Override
2306 public KeySet getSigningKeySet(String packageName) {
2307 Preconditions.checkNotNull(packageName);
dcashman9d2f4412014-06-09 09:27:54 -07002308 try {
Jeff Sharkey27b2e692016-02-25 17:40:12 -07002309 return mPM.getSigningKeySet(packageName);
dcashman9d2f4412014-06-09 09:27:54 -07002310 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002311 throw e.rethrowFromSystemServer();
dcashman9d2f4412014-06-09 09:27:54 -07002312 }
dcashman9d2f4412014-06-09 09:27:54 -07002313 }
2314
dcashmanc6f22492014-08-14 09:54:51 -07002315 /** @hide */
dcashman9d2f4412014-06-09 09:27:54 -07002316 @Override
2317 public boolean isSignedBy(String packageName, KeySet ks) {
2318 Preconditions.checkNotNull(packageName);
2319 Preconditions.checkNotNull(ks);
dcashman9d2f4412014-06-09 09:27:54 -07002320 try {
dcashmanc6f22492014-08-14 09:54:51 -07002321 return mPM.isPackageSignedByKeySet(packageName, ks);
dcashman9d2f4412014-06-09 09:27:54 -07002322 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002323 throw e.rethrowFromSystemServer();
dcashman9d2f4412014-06-09 09:27:54 -07002324 }
2325 }
2326
dcashmanc6f22492014-08-14 09:54:51 -07002327 /** @hide */
dcashman9d2f4412014-06-09 09:27:54 -07002328 @Override
2329 public boolean isSignedByExactly(String packageName, KeySet ks) {
2330 Preconditions.checkNotNull(packageName);
2331 Preconditions.checkNotNull(ks);
dcashman9d2f4412014-06-09 09:27:54 -07002332 try {
dcashmanc6f22492014-08-14 09:54:51 -07002333 return mPM.isPackageSignedByKeySetExactly(packageName, ks);
dcashman9d2f4412014-06-09 09:27:54 -07002334 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002335 throw e.rethrowFromSystemServer();
dcashman9d2f4412014-06-09 09:27:54 -07002336 }
2337 }
2338
Kenny Root0aaa0d92011-09-12 16:42:55 -07002339 /**
2340 * @hide
2341 */
2342 @Override
2343 public VerifierDeviceIdentity getVerifierDeviceIdentity() {
2344 try {
2345 return mPM.getVerifierDeviceIdentity();
2346 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002347 throw e.rethrowFromSystemServer();
Kenny Root0aaa0d92011-09-12 16:42:55 -07002348 }
Kenny Root0aaa0d92011-09-12 16:42:55 -07002349 }
2350
Jeff Hao9f60c082014-10-28 18:51:07 -07002351 /**
2352 * @hide
2353 */
2354 @Override
2355 public boolean isUpgrade() {
2356 try {
2357 return mPM.isUpgrade();
2358 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002359 throw e.rethrowFromSystemServer();
Jeff Hao9f60c082014-10-28 18:51:07 -07002360 }
2361 }
2362
Jeff Sharkey3a44f3f2014-04-28 17:36:31 -07002363 @Override
Jeff Sharkey16c8e3f2014-07-24 17:08:17 -07002364 public PackageInstaller getPackageInstaller() {
2365 synchronized (mLock) {
2366 if (mInstaller == null) {
2367 try {
Svet Ganov67882122016-12-11 16:36:34 -08002368 mInstaller = new PackageInstaller(mPM.getPackageInstaller(),
Jeff Sharkey16c8e3f2014-07-24 17:08:17 -07002369 mContext.getPackageName(), mContext.getUserId());
2370 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002371 throw e.rethrowFromSystemServer();
Jeff Sharkey16c8e3f2014-07-24 17:08:17 -07002372 }
2373 }
2374 return mInstaller;
Jeff Sharkey3a44f3f2014-04-28 17:36:31 -07002375 }
2376 }
2377
Jeff Sharkey6c833e02014-07-14 22:44:30 -07002378 @Override
2379 public boolean isPackageAvailable(String packageName) {
2380 try {
2381 return mPM.isPackageAvailable(packageName, mContext.getUserId());
2382 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002383 throw e.rethrowFromSystemServer();
Jeff Sharkey6c833e02014-07-14 22:44:30 -07002384 }
2385 }
2386
Nicolas Prevotc79586e2014-05-06 12:47:57 +01002387 /**
2388 * @hide
2389 */
2390 @Override
Nicolas Prevot63798c52014-05-27 13:22:38 +01002391 public void addCrossProfileIntentFilter(IntentFilter filter, int sourceUserId, int targetUserId,
2392 int flags) {
Nicolas Prevotc79586e2014-05-06 12:47:57 +01002393 try {
Nicolas Prevot3f7777f2014-07-24 15:58:39 +01002394 mPM.addCrossProfileIntentFilter(filter, mContext.getOpPackageName(),
Nicolas Prevot4b8d5822015-03-05 15:20:49 +00002395 sourceUserId, targetUserId, flags);
Nicolas Prevotc79586e2014-05-06 12:47:57 +01002396 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002397 throw e.rethrowFromSystemServer();
Nicolas Prevotc79586e2014-05-06 12:47:57 +01002398 }
2399 }
2400
2401 /**
2402 * @hide
2403 */
2404 @Override
Nicolas Prevot81948992014-05-16 18:25:26 +01002405 public void clearCrossProfileIntentFilters(int sourceUserId) {
Nicolas Prevotc79586e2014-05-06 12:47:57 +01002406 try {
Nicolas Prevot4b8d5822015-03-05 15:20:49 +00002407 mPM.clearCrossProfileIntentFilters(sourceUserId, mContext.getOpPackageName());
Nicolas Prevotc79586e2014-05-06 12:47:57 +01002408 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002409 throw e.rethrowFromSystemServer();
Nicolas Prevotc79586e2014-05-06 12:47:57 +01002410 }
2411 }
2412
Nicolas Prevot88cc3462014-05-14 14:51:48 +01002413 /**
2414 * @hide
2415 */
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +01002416 public Drawable loadItemIcon(PackageItemInfo itemInfo, ApplicationInfo appInfo) {
Benjamin Franzec2d48b2014-10-01 15:38:43 +01002417 Drawable dr = loadUnbadgedItemIcon(itemInfo, appInfo);
2418 if (itemInfo.showUserIcon != UserHandle.USER_NULL) {
2419 return dr;
2420 }
2421 return getUserBadgedIcon(dr, new UserHandle(mContext.getUserId()));
2422 }
2423
2424 /**
2425 * @hide
2426 */
2427 public Drawable loadUnbadgedItemIcon(PackageItemInfo itemInfo, ApplicationInfo appInfo) {
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +01002428 if (itemInfo.showUserIcon != UserHandle.USER_NULL) {
Alexandra Gherghina64d4dca2014-08-28 18:26:56 +01002429 Bitmap bitmap = getUserManager().getUserIcon(itemInfo.showUserIcon);
2430 if (bitmap == null) {
2431 return UserIcons.getDefaultUserIcon(itemInfo.showUserIcon, /* light= */ false);
2432 }
2433 return new BitmapDrawable(bitmap);
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +01002434 }
Alexandra Gherghinadb811db2014-08-29 13:43:59 +01002435 Drawable dr = null;
2436 if (itemInfo.packageName != null) {
2437 dr = getDrawable(itemInfo.packageName, itemInfo.icon, appInfo);
2438 }
Alexandra Gherghinaa71e3902014-07-25 20:03:47 +01002439 if (dr == null) {
Alexandra Gherghinaa7093142014-07-30 13:43:39 +01002440 dr = itemInfo.loadDefaultIcon(this);
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +01002441 }
Benjamin Franzec2d48b2014-10-01 15:38:43 +01002442 return dr;
Svetoslavc7d62f02014-09-04 15:39:54 -07002443 }
2444
2445 private Drawable getBadgedDrawable(Drawable drawable, Drawable badgeDrawable,
2446 Rect badgeLocation, boolean tryBadgeInPlace) {
2447 final int badgedWidth = drawable.getIntrinsicWidth();
2448 final int badgedHeight = drawable.getIntrinsicHeight();
2449 final boolean canBadgeInPlace = tryBadgeInPlace
2450 && (drawable instanceof BitmapDrawable)
2451 && ((BitmapDrawable) drawable).getBitmap().isMutable();
2452
2453 final Bitmap bitmap;
2454 if (canBadgeInPlace) {
2455 bitmap = ((BitmapDrawable) drawable).getBitmap();
2456 } else {
2457 bitmap = Bitmap.createBitmap(badgedWidth, badgedHeight, Bitmap.Config.ARGB_8888);
2458 }
2459 Canvas canvas = new Canvas(bitmap);
2460
2461 if (!canBadgeInPlace) {
2462 drawable.setBounds(0, 0, badgedWidth, badgedHeight);
2463 drawable.draw(canvas);
2464 }
2465
2466 if (badgeLocation != null) {
2467 if (badgeLocation.left < 0 || badgeLocation.top < 0
2468 || badgeLocation.width() > badgedWidth || badgeLocation.height() > badgedHeight) {
2469 throw new IllegalArgumentException("Badge location " + badgeLocation
2470 + " not in badged drawable bounds "
2471 + new Rect(0, 0, badgedWidth, badgedHeight));
2472 }
2473 badgeDrawable.setBounds(0, 0, badgeLocation.width(), badgeLocation.height());
2474
2475 canvas.save();
2476 canvas.translate(badgeLocation.left, badgeLocation.top);
2477 badgeDrawable.draw(canvas);
2478 canvas.restore();
2479 } else {
2480 badgeDrawable.setBounds(0, 0, badgedWidth, badgedHeight);
2481 badgeDrawable.draw(canvas);
2482 }
2483
2484 if (!canBadgeInPlace) {
2485 BitmapDrawable mergedDrawable = new BitmapDrawable(mContext.getResources(), bitmap);
2486
2487 if (drawable instanceof BitmapDrawable) {
2488 BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
2489 mergedDrawable.setTargetDensity(bitmapDrawable.getBitmap().getDensity());
2490 }
2491
2492 return mergedDrawable;
2493 }
2494
2495 return drawable;
2496 }
2497
Tony Mak8673b282016-03-21 21:10:59 +00002498 private boolean isManagedProfile(int userId) {
2499 return getUserManager().isManagedProfile(userId);
Nicolas Prevot88cc3462014-05-14 14:51:48 +01002500 }
2501
Bartosz Fabianowskia34f53f2017-01-11 18:08:47 +01002502 /**
2503 * @hide
2504 */
2505 @Override
2506 public int getInstallReason(String packageName, UserHandle user) {
2507 try {
2508 return mPM.getInstallReason(packageName, user.getIdentifier());
2509 } catch (RemoteException e) {
2510 throw e.rethrowFromSystemServer();
2511 }
2512 }
2513
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002514 /** {@hide} */
2515 private static class MoveCallbackDelegate extends IPackageMoveObserver.Stub implements
2516 Handler.Callback {
Jeff Sharkey50a05452015-04-29 11:24:52 -07002517 private static final int MSG_CREATED = 1;
2518 private static final int MSG_STATUS_CHANGED = 2;
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002519
2520 final MoveCallback mCallback;
2521 final Handler mHandler;
2522
2523 public MoveCallbackDelegate(MoveCallback callback, Looper looper) {
2524 mCallback = callback;
2525 mHandler = new Handler(looper, this);
2526 }
2527
2528 @Override
2529 public boolean handleMessage(Message msg) {
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002530 switch (msg.what) {
Jeff Sharkey50a05452015-04-29 11:24:52 -07002531 case MSG_CREATED: {
Jeff Sharkeyb36586a2015-04-27 08:42:28 -07002532 final SomeArgs args = (SomeArgs) msg.obj;
Jeff Sharkey50a05452015-04-29 11:24:52 -07002533 mCallback.onCreated(args.argi1, (Bundle) args.arg2);
Jeff Sharkeyb36586a2015-04-27 08:42:28 -07002534 args.recycle();
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002535 return true;
Jeff Sharkey50a05452015-04-29 11:24:52 -07002536 }
2537 case MSG_STATUS_CHANGED: {
2538 final SomeArgs args = (SomeArgs) msg.obj;
2539 mCallback.onStatusChanged(args.argi1, args.argi2, (long) args.arg3);
2540 args.recycle();
2541 return true;
2542 }
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002543 }
2544 return false;
2545 }
2546
2547 @Override
Jeff Sharkey50a05452015-04-29 11:24:52 -07002548 public void onCreated(int moveId, Bundle extras) {
Jeff Sharkeyb36586a2015-04-27 08:42:28 -07002549 final SomeArgs args = SomeArgs.obtain();
2550 args.argi1 = moveId;
Jeff Sharkey50a05452015-04-29 11:24:52 -07002551 args.arg2 = extras;
2552 mHandler.obtainMessage(MSG_CREATED, args).sendToTarget();
2553 }
2554
2555 @Override
2556 public void onStatusChanged(int moveId, int status, long estMillis) {
2557 final SomeArgs args = SomeArgs.obtain();
2558 args.argi1 = moveId;
2559 args.argi2 = status;
2560 args.arg3 = estMillis;
Jeff Sharkeyb36586a2015-04-27 08:42:28 -07002561 mHandler.obtainMessage(MSG_STATUS_CHANGED, args).sendToTarget();
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002562 }
2563 }
2564
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002565 private final ContextImpl mContext;
2566 private final IPackageManager mPM;
2567
2568 private static final Object sSync = new Object();
Dianne Hackbornadd005c2013-07-17 18:43:12 -07002569 private static ArrayMap<ResourceName, WeakReference<Drawable.ConstantState>> sIconCache
2570 = new ArrayMap<ResourceName, WeakReference<Drawable.ConstantState>>();
2571 private static ArrayMap<ResourceName, WeakReference<CharSequence>> sStringCache
2572 = new ArrayMap<ResourceName, WeakReference<CharSequence>>();
Svetoslavf7c06eb2015-06-10 18:43:22 -07002573
2574 private final Map<OnPermissionsChangedListener, IOnPermissionsChangeListener>
2575 mPermissionListeners = new ArrayMap<>();
2576
2577 public class OnPermissionsChangeListenerDelegate extends IOnPermissionsChangeListener.Stub
2578 implements Handler.Callback{
2579 private static final int MSG_PERMISSIONS_CHANGED = 1;
2580
2581 private final OnPermissionsChangedListener mListener;
2582 private final Handler mHandler;
2583
2584
2585 public OnPermissionsChangeListenerDelegate(OnPermissionsChangedListener listener,
2586 Looper looper) {
2587 mListener = listener;
2588 mHandler = new Handler(looper, this);
2589 }
2590
2591 @Override
2592 public void onPermissionsChanged(int uid) {
2593 mHandler.obtainMessage(MSG_PERMISSIONS_CHANGED, uid, 0).sendToTarget();
2594 }
2595
2596 @Override
2597 public boolean handleMessage(Message msg) {
2598 switch (msg.what) {
2599 case MSG_PERMISSIONS_CHANGED: {
2600 final int uid = msg.arg1;
2601 mListener.onPermissionsChanged(uid);
2602 return true;
2603 }
2604 }
2605 return false;
2606 }
2607 }
Suprabh Shuklaaef25132017-01-23 18:09:03 -08002608
2609 @Override
2610 public boolean canRequestPackageInstalls() {
2611 try {
2612 return mPM.canRequestPackageInstalls(mContext.getPackageName(), mContext.getUserId());
2613 } catch (RemoteException e) {
2614 throw e.rethrowAsRuntimeException();
2615 }
2616 }
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002617}