blob: 27bbc4bca268627d6b492599ddbae11041416e08 [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;
Philip P. Moltmann18e3eb82018-03-09 16:55:55 -080023import android.annotation.UserIdInt;
Tor Norbye7b9c9122013-05-30 16:48:33 -070024import android.annotation.XmlRes;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080025import android.content.ComponentName;
26import android.content.ContentResolver;
Yao Chen022b8ea2016-12-16 11:03:28 -080027import android.content.Context;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080028import android.content.Intent;
29import android.content.IntentFilter;
30import android.content.IntentSender;
31import android.content.pm.ActivityInfo;
32import android.content.pm.ApplicationInfo;
Todd Kennedy9106c642017-02-08 14:16:53 -080033import android.content.pm.ChangedPackages;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080034import android.content.pm.ComponentInfo;
35import 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;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080039import android.content.pm.IPackageManager;
40import android.content.pm.IPackageMoveObserver;
41import android.content.pm.IPackageStatsObserver;
Todd Kennedy9da8b8a72017-07-25 15:38:39 -070042import android.content.pm.InstantAppInfo;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080043import 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;
Calin Juravle45f8b292017-11-07 18:49:43 -080059import android.content.pm.dex.ArtManager;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080060import android.content.res.Resources;
61import android.content.res.XmlResourceParser;
Svetoslavc7d62f02014-09-04 15:39:54 -070062import android.graphics.Bitmap;
63import android.graphics.Canvas;
64import android.graphics.Rect;
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +010065import android.graphics.drawable.BitmapDrawable;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080066import android.graphics.drawable.Drawable;
Kenny Guy02c89902016-11-15 19:36:38 +000067import android.graphics.drawable.LayerDrawable;
Jeff Sharkeye6306c42017-03-07 21:03:18 -070068import android.os.Build;
Jeff Sharkey50a05452015-04-29 11:24:52 -070069import android.os.Bundle;
Jeff Sharkey620b32b2015-04-23 19:36:02 -070070import android.os.Handler;
71import android.os.Looper;
72import android.os.Message;
Suprabh Shukla021b57a2018-03-08 18:21:50 -080073import android.os.PersistableBundle;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080074import android.os.Process;
75import android.os.RemoteException;
Jeff Sharkeyb2b9ab82015-04-05 21:10:42 -070076import android.os.SystemProperties;
Amith Yamasani67df64b2012-12-14 12:09:36 -080077import android.os.UserHandle;
Nicolas Prevot88cc3462014-05-14 14:51:48 +010078import android.os.UserManager;
Jeff Sharkeye2d45be2015-04-15 17:14:12 -070079import android.os.storage.StorageManager;
80import android.os.storage.VolumeInfo;
Todd Kennedyf39ca8f2015-08-07 14:15:07 -070081import android.provider.Settings;
Calin Juravle3d2af7f2017-04-19 19:56:21 -070082import android.system.ErrnoException;
83import android.system.Os;
84import android.system.OsConstants;
85import android.system.StructStat;
Dianne Hackbornadd005c2013-07-17 18:43:12 -070086import android.util.ArrayMap;
Sunny Goyalbab30752017-04-12 15:36:42 -070087import android.util.IconDrawableFactory;
88import android.util.LauncherIcons;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080089import android.util.Log;
Jeff Browna492c3a2012-08-23 19:48:44 -070090import android.view.Display;
Jeff Sharkeyb2b9ab82015-04-05 21:10:42 -070091
Jeff Sharkey16c8e3f2014-07-24 17:08:17 -070092import com.android.internal.annotations.GuardedBy;
Kenny Guy02c89902016-11-15 19:36:38 +000093import com.android.internal.annotations.VisibleForTesting;
Jeff Sharkeyb36586a2015-04-27 08:42:28 -070094import com.android.internal.os.SomeArgs;
dcashman9d2f4412014-06-09 09:27:54 -070095import com.android.internal.util.Preconditions;
Alexandra Gherghina64d4dca2014-08-28 18:26:56 +010096import com.android.internal.util.UserIcons;
Todd Kennedy9da8b8a72017-07-25 15:38:39 -070097
98import dalvik.system.VMRuntime;
99
Svet Ganov2acf0632015-11-24 19:10:59 -0800100import libcore.util.EmptyArray;
Jeff Sharkey16c8e3f2014-07-24 17:08:17 -0700101
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800102import java.lang.ref.WeakReference;
103import java.util.ArrayList;
Svet Ganov2acf0632015-11-24 19:10:59 -0800104import java.util.Collections;
Jeff Sharkey620b32b2015-04-23 19:36:02 -0700105import java.util.Iterator;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800106import java.util.List;
Svetoslavf7c06eb2015-06-10 18:43:22 -0700107import java.util.Map;
Jeff Sharkey620b32b2015-04-23 19:36:02 -0700108import java.util.Objects;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800109
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700110/** @hide */
111public class ApplicationPackageManager extends PackageManager {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800112 private static final String TAG = "ApplicationPackageManager";
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800113 private final static boolean DEBUG_ICONS = false;
114
Svet Ganov2acf0632015-11-24 19:10:59 -0800115 private static final int DEFAULT_EPHEMERAL_COOKIE_MAX_SIZE_BYTES = 16384; // 16KB
116
Adam Lesinskid00bb5e2014-10-07 12:14:45 -0700117 // Default flags to use with PackageManager when no flags are given.
118 private final static int sDefaultFlags = PackageManager.GET_SHARED_LIBRARY_FILES;
119
Jeff Sharkey16c8e3f2014-07-24 17:08:17 -0700120 private final Object mLock = new Object();
121
122 @GuardedBy("mLock")
123 private UserManager mUserManager;
124 @GuardedBy("mLock")
125 private PackageInstaller mInstaller;
Calin Juravle45f8b292017-11-07 18:49:43 -0800126 @GuardedBy("mLock")
127 private ArtManager mArtManager;
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +0100128
Jeff Sharkey620b32b2015-04-23 19:36:02 -0700129 @GuardedBy("mDelegates")
130 private final ArrayList<MoveCallbackDelegate> mDelegates = new ArrayList<>();
131
Svet Ganovf1b7f202015-07-29 08:33:42 -0700132 @GuardedBy("mLock")
133 private String mPermissionsControllerPackageName;
134
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +0100135 UserManager getUserManager() {
Jeff Sharkey16c8e3f2014-07-24 17:08:17 -0700136 synchronized (mLock) {
137 if (mUserManager == null) {
138 mUserManager = UserManager.get(mContext);
139 }
140 return mUserManager;
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +0100141 }
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +0100142 }
143
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800144 @Override
Jeff Sharkeyad357d12018-02-02 13:25:31 -0700145 public int getUserId() {
146 return mContext.getUserId();
147 }
148
149 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800150 public PackageInfo getPackageInfo(String packageName, int flags)
151 throws NameNotFoundException {
Nicolas Prevot9a80e532015-09-23 15:49:28 +0100152 return getPackageInfoAsUser(packageName, flags, mContext.getUserId());
153 }
154
155 @Override
Svet Ganov67882122016-12-11 16:36:34 -0800156 public PackageInfo getPackageInfo(VersionedPackage versionedPackage, int flags)
157 throws NameNotFoundException {
158 try {
159 PackageInfo pi = mPM.getPackageInfoVersioned(versionedPackage, flags,
160 mContext.getUserId());
161 if (pi != null) {
162 return pi;
163 }
164 } catch (RemoteException e) {
165 throw e.rethrowFromSystemServer();
166 }
167 throw new NameNotFoundException(versionedPackage.toString());
168 }
169
170 @Override
Nicolas Prevot9a80e532015-09-23 15:49:28 +0100171 public PackageInfo getPackageInfoAsUser(String packageName, int flags, int userId)
172 throws NameNotFoundException {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800173 try {
Nicolas Prevot9a80e532015-09-23 15:49:28 +0100174 PackageInfo pi = mPM.getPackageInfo(packageName, flags, userId);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800175 if (pi != null) {
176 return pi;
177 }
178 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700179 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800180 }
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800181 throw new NameNotFoundException(packageName);
182 }
183
184 @Override
185 public String[] currentToCanonicalPackageNames(String[] names) {
186 try {
187 return mPM.currentToCanonicalPackageNames(names);
188 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700189 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800190 }
191 }
192
193 @Override
194 public String[] canonicalToCurrentPackageNames(String[] names) {
195 try {
196 return mPM.canonicalToCurrentPackageNames(names);
197 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700198 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800199 }
200 }
201
202 @Override
203 public Intent getLaunchIntentForPackage(String packageName) {
204 // First see if the package has an INFO activity; the existence of
205 // such an activity is implied to be the desired front-door for the
206 // overall package (such as if it has multiple launcher entries).
207 Intent intentToResolve = new Intent(Intent.ACTION_MAIN);
208 intentToResolve.addCategory(Intent.CATEGORY_INFO);
209 intentToResolve.setPackage(packageName);
Dianne Hackborn19415762010-12-15 00:20:27 -0800210 List<ResolveInfo> ris = queryIntentActivities(intentToResolve, 0);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800211
212 // Otherwise, try to find a main launcher activity.
Dianne Hackborn19415762010-12-15 00:20:27 -0800213 if (ris == null || ris.size() <= 0) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800214 // reuse the intent instance
215 intentToResolve.removeCategory(Intent.CATEGORY_INFO);
216 intentToResolve.addCategory(Intent.CATEGORY_LAUNCHER);
217 intentToResolve.setPackage(packageName);
Dianne Hackborn19415762010-12-15 00:20:27 -0800218 ris = queryIntentActivities(intentToResolve, 0);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800219 }
Dianne Hackborn19415762010-12-15 00:20:27 -0800220 if (ris == null || ris.size() <= 0) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800221 return null;
222 }
223 Intent intent = new Intent(intentToResolve);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800224 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Dianne Hackborn19415762010-12-15 00:20:27 -0800225 intent.setClassName(ris.get(0).activityInfo.packageName,
226 ris.get(0).activityInfo.name);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800227 return intent;
228 }
229
230 @Override
Jose Lima970417c2014-04-10 10:42:19 -0700231 public Intent getLeanbackLaunchIntentForPackage(String packageName) {
Roberto Perez7ee1a7a2017-12-04 17:14:33 -0800232 return getLaunchIntentForPackageAndCategory(packageName, Intent.CATEGORY_LEANBACK_LAUNCHER);
233 }
234
235 @Override
236 public Intent getCarLaunchIntentForPackage(String packageName) {
237 return getLaunchIntentForPackageAndCategory(packageName, Intent.CATEGORY_CAR_LAUNCHER);
238 }
239
240 private Intent getLaunchIntentForPackageAndCategory(String packageName, String category) {
241 // Try to find a main launcher activity for the given categories.
Jose Lima970417c2014-04-10 10:42:19 -0700242 Intent intentToResolve = new Intent(Intent.ACTION_MAIN);
Roberto Perez7ee1a7a2017-12-04 17:14:33 -0800243 intentToResolve.addCategory(category);
Jose Lima970417c2014-04-10 10:42:19 -0700244 intentToResolve.setPackage(packageName);
245 List<ResolveInfo> ris = queryIntentActivities(intentToResolve, 0);
246
247 if (ris == null || ris.size() <= 0) {
248 return null;
249 }
250 Intent intent = new Intent(intentToResolve);
251 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
252 intent.setClassName(ris.get(0).activityInfo.packageName,
253 ris.get(0).activityInfo.name);
254 return intent;
255 }
256
257 @Override
Jeff Sharkey8588bc12016-01-06 16:47:42 -0700258 public int[] getPackageGids(String packageName) throws NameNotFoundException {
259 return getPackageGids(packageName, 0);
260 }
261
262 @Override
263 public int[] getPackageGids(String packageName, int flags)
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800264 throws NameNotFoundException {
265 try {
Jeff Sharkeycd654482016-01-08 17:42:11 -0700266 int[] gids = mPM.getPackageGids(packageName, flags, mContext.getUserId());
Svetoslavc6d1c342015-02-26 14:44:43 -0800267 if (gids != null) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800268 return gids;
269 }
270 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700271 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800272 }
273
274 throw new NameNotFoundException(packageName);
275 }
276
277 @Override
Jeff Sharkey8588bc12016-01-06 16:47:42 -0700278 public int getPackageUid(String packageName, int flags) throws NameNotFoundException {
279 return getPackageUidAsUser(packageName, flags, mContext.getUserId());
280 }
281
282 @Override
283 public int getPackageUidAsUser(String packageName, int userId) throws NameNotFoundException {
284 return getPackageUidAsUser(packageName, 0, userId);
285 }
286
287 @Override
288 public int getPackageUidAsUser(String packageName, int flags, int userId)
Dianne Hackborna06de0f2012-12-11 16:34:47 -0800289 throws NameNotFoundException {
290 try {
Jeff Sharkeycd654482016-01-08 17:42:11 -0700291 int uid = mPM.getPackageUid(packageName, flags, userId);
Dianne Hackborna06de0f2012-12-11 16:34:47 -0800292 if (uid >= 0) {
293 return uid;
294 }
295 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700296 throw e.rethrowFromSystemServer();
Dianne Hackborna06de0f2012-12-11 16:34:47 -0800297 }
298
299 throw new NameNotFoundException(packageName);
300 }
301
302 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800303 public PermissionInfo getPermissionInfo(String name, int flags)
304 throws NameNotFoundException {
305 try {
Svetoslav Ganovadb8c522017-07-28 05:46:53 +0000306 PermissionInfo pi = mPM.getPermissionInfo(name,
307 mContext.getOpPackageName(), flags);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800308 if (pi != null) {
309 return pi;
310 }
311 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700312 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800313 }
314
315 throw new NameNotFoundException(name);
316 }
317
318 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700319 @SuppressWarnings("unchecked")
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800320 public List<PermissionInfo> queryPermissionsByGroup(String group, int flags)
321 throws NameNotFoundException {
322 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700323 ParceledListSlice<PermissionInfo> parceledList =
324 mPM.queryPermissionsByGroup(group, flags);
325 if (parceledList != null) {
326 List<PermissionInfo> pi = parceledList.getList();
327 if (pi != null) {
328 return pi;
329 }
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800330 }
331 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700332 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800333 }
334
335 throw new NameNotFoundException(group);
336 }
337
338 @Override
Paul Navin7b89a7b2017-01-26 23:56:08 +0000339 public boolean isPermissionReviewModeEnabled() {
340 return mContext.getResources().getBoolean(
341 com.android.internal.R.bool.config_permissionReviewRequired);
342 }
343
344 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800345 public PermissionGroupInfo getPermissionGroupInfo(String name,
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700346 int flags) throws NameNotFoundException {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800347 try {
348 PermissionGroupInfo pgi = mPM.getPermissionGroupInfo(name, flags);
349 if (pgi != null) {
350 return pgi;
351 }
352 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700353 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800354 }
355
356 throw new NameNotFoundException(name);
357 }
358
359 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700360 @SuppressWarnings("unchecked")
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800361 public List<PermissionGroupInfo> getAllPermissionGroups(int flags) {
362 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700363 ParceledListSlice<PermissionGroupInfo> parceledList =
364 mPM.getAllPermissionGroups(flags);
365 if (parceledList == null) {
366 return Collections.emptyList();
367 }
368 return parceledList.getList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800369 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700370 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800371 }
372 }
373
374 @Override
375 public ApplicationInfo getApplicationInfo(String packageName, int flags)
376 throws NameNotFoundException {
Jeff Sharkeycd654482016-01-08 17:42:11 -0700377 return getApplicationInfoAsUser(packageName, flags, mContext.getUserId());
378 }
379
380 @Override
381 public ApplicationInfo getApplicationInfoAsUser(String packageName, int flags, int userId)
382 throws NameNotFoundException {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800383 try {
Jeff Sharkeycd654482016-01-08 17:42:11 -0700384 ApplicationInfo ai = mPM.getApplicationInfo(packageName, flags, userId);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800385 if (ai != null) {
Narayan Kamathcaa71192014-07-16 11:06:43 +0100386 // This is a temporary hack. Callers must use
387 // createPackageContext(packageName).getApplicationInfo() to
388 // get the right paths.
Tao Baic9a02372016-01-12 15:02:24 -0800389 return maybeAdjustApplicationInfo(ai);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800390 }
391 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700392 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800393 }
394
395 throw new NameNotFoundException(packageName);
396 }
397
Tao Baic9a02372016-01-12 15:02:24 -0800398 private static ApplicationInfo maybeAdjustApplicationInfo(ApplicationInfo info) {
Narayan Kamathcaa71192014-07-16 11:06:43 +0100399 // If we're dealing with a multi-arch application that has both
400 // 32 and 64 bit shared libraries, we might need to choose the secondary
401 // depending on what the current runtime's instruction set is.
402 if (info.primaryCpuAbi != null && info.secondaryCpuAbi != null) {
403 final String runtimeIsa = VMRuntime.getRuntime().vmInstructionSet();
jgu214741cd92014-12-17 17:23:29 -0500404
405 // Get the instruction set that the libraries of secondary Abi is supported.
406 // In presence of a native bridge this might be different than the one secondary Abi used.
407 String secondaryIsa = VMRuntime.getInstructionSet(info.secondaryCpuAbi);
408 final String secondaryDexCodeIsa = SystemProperties.get("ro.dalvik.vm.isa." + secondaryIsa);
409 secondaryIsa = secondaryDexCodeIsa.isEmpty() ? secondaryIsa : secondaryDexCodeIsa;
Narayan Kamathcaa71192014-07-16 11:06:43 +0100410
411 // If the runtimeIsa is the same as the primary isa, then we do nothing.
412 // Everything will be set up correctly because info.nativeLibraryDir will
413 // correspond to the right ISA.
414 if (runtimeIsa.equals(secondaryIsa)) {
Tao Baic9a02372016-01-12 15:02:24 -0800415 ApplicationInfo modified = new ApplicationInfo(info);
416 modified.nativeLibraryDir = info.secondaryNativeLibraryDir;
417 return modified;
Narayan Kamathcaa71192014-07-16 11:06:43 +0100418 }
419 }
Tao Baic9a02372016-01-12 15:02:24 -0800420 return info;
Narayan Kamathcaa71192014-07-16 11:06:43 +0100421 }
422
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800423 @Override
424 public ActivityInfo getActivityInfo(ComponentName className, int flags)
425 throws NameNotFoundException {
426 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700427 ActivityInfo ai = mPM.getActivityInfo(className, flags, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800428 if (ai != null) {
429 return ai;
430 }
431 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700432 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800433 }
434
435 throw new NameNotFoundException(className.toString());
436 }
437
438 @Override
439 public ActivityInfo getReceiverInfo(ComponentName className, int flags)
440 throws NameNotFoundException {
441 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700442 ActivityInfo ai = mPM.getReceiverInfo(className, flags, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800443 if (ai != null) {
444 return ai;
445 }
446 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700447 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800448 }
449
450 throw new NameNotFoundException(className.toString());
451 }
452
453 @Override
454 public ServiceInfo getServiceInfo(ComponentName className, int flags)
455 throws NameNotFoundException {
456 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700457 ServiceInfo si = mPM.getServiceInfo(className, flags, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800458 if (si != null) {
459 return si;
460 }
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 throw new NameNotFoundException(className.toString());
466 }
467
468 @Override
469 public ProviderInfo getProviderInfo(ComponentName className, int flags)
470 throws NameNotFoundException {
471 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700472 ProviderInfo pi = mPM.getProviderInfo(className, flags, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800473 if (pi != null) {
474 return pi;
475 }
476 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700477 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800478 }
479
480 throw new NameNotFoundException(className.toString());
481 }
482
483 @Override
484 public String[] getSystemSharedLibraryNames() {
485 try {
486 return mPM.getSystemSharedLibraryNames();
487 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700488 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800489 }
490 }
491
Svet Ganovd7b1f4112016-02-09 18:49:23 -0800492 /** @hide */
493 @Override
Svet Ganov67882122016-12-11 16:36:34 -0800494 public @NonNull List<SharedLibraryInfo> getSharedLibraries(int flags) {
495 return getSharedLibrariesAsUser(flags, mContext.getUserId());
496 }
497
498 /** @hide */
499 @Override
500 @SuppressWarnings("unchecked")
501 public @NonNull List<SharedLibraryInfo> getSharedLibrariesAsUser(int flags, int userId) {
502 try {
503 ParceledListSlice<SharedLibraryInfo> sharedLibs = mPM.getSharedLibraries(
Svet Ganov58c99f02017-05-15 14:07:17 -0700504 mContext.getOpPackageName(), flags, userId);
Svet Ganov67882122016-12-11 16:36:34 -0800505 if (sharedLibs == null) {
506 return Collections.emptyList();
507 }
508 return sharedLibs.getList();
509 } catch (RemoteException e) {
510 throw e.rethrowFromSystemServer();
511 }
512 }
513
514 /** @hide */
515 @Override
Svetoslav Ganova9c25002016-04-13 19:25:56 -0700516 public @NonNull String getServicesSystemSharedLibraryPackageName() {
Svet Ganovd7b1f4112016-02-09 18:49:23 -0800517 try {
518 return mPM.getServicesSystemSharedLibraryPackageName();
519 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700520 throw e.rethrowFromSystemServer();
Svet Ganovd7b1f4112016-02-09 18:49:23 -0800521 }
522 }
523
Svetoslav Ganova9c25002016-04-13 19:25:56 -0700524 /**
525 * @hide
526 */
527 public @NonNull String getSharedSystemSharedLibraryPackageName() {
528 try {
529 return mPM.getSharedSystemSharedLibraryPackageName();
530 } catch (RemoteException e) {
531 throw e.rethrowFromSystemServer();
532 }
533 }
534
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800535 @Override
Todd Kennedy9106c642017-02-08 14:16:53 -0800536 public ChangedPackages getChangedPackages(int sequenceNumber) {
537 try {
538 return mPM.getChangedPackages(sequenceNumber, mContext.getUserId());
539 } catch (RemoteException e) {
540 throw e.rethrowFromSystemServer();
541 }
542 }
543
544 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700545 @SuppressWarnings("unchecked")
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800546 public FeatureInfo[] getSystemAvailableFeatures() {
547 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700548 ParceledListSlice<FeatureInfo> parceledList =
549 mPM.getSystemAvailableFeatures();
550 if (parceledList == null) {
551 return new FeatureInfo[0];
552 }
553 final List<FeatureInfo> list = parceledList.getList();
Jeff Sharkeyd5896632016-03-04 16:16:00 -0700554 final FeatureInfo[] res = new FeatureInfo[list.size()];
555 for (int i = 0; i < res.length; i++) {
556 res[i] = list.get(i);
557 }
558 return res;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800559 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700560 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800561 }
562 }
563
564 @Override
565 public boolean hasSystemFeature(String name) {
Jeff Sharkey115d2c12016-02-15 17:25:57 -0700566 return hasSystemFeature(name, 0);
567 }
568
569 @Override
570 public boolean hasSystemFeature(String name, int version) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800571 try {
Jeff Sharkey115d2c12016-02-15 17:25:57 -0700572 return mPM.hasSystemFeature(name, version);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800573 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700574 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800575 }
576 }
577
578 @Override
579 public int checkPermission(String permName, String pkgName) {
580 try {
Svetoslavc6d1c342015-02-26 14:44:43 -0800581 return mPM.checkPermission(permName, pkgName, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800582 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700583 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800584 }
585 }
586
587 @Override
Svet Ganovad3b2972015-07-07 22:49:17 -0700588 public boolean isPermissionRevokedByPolicy(String permName, String pkgName) {
589 try {
590 return mPM.isPermissionRevokedByPolicy(permName, pkgName, mContext.getUserId());
591 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700592 throw e.rethrowFromSystemServer();
Svet Ganovad3b2972015-07-07 22:49:17 -0700593 }
594 }
595
Svet Ganovf1b7f202015-07-29 08:33:42 -0700596 /**
597 * @hide
598 */
599 @Override
600 public String getPermissionControllerPackageName() {
601 synchronized (mLock) {
602 if (mPermissionsControllerPackageName == null) {
603 try {
604 mPermissionsControllerPackageName = mPM.getPermissionControllerPackageName();
605 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700606 throw e.rethrowFromSystemServer();
Svet Ganovf1b7f202015-07-29 08:33:42 -0700607 }
608 }
609 return mPermissionsControllerPackageName;
610 }
611 }
612
Svet Ganovad3b2972015-07-07 22:49:17 -0700613 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800614 public boolean addPermission(PermissionInfo info) {
615 try {
616 return mPM.addPermission(info);
617 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700618 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800619 }
620 }
621
622 @Override
623 public boolean addPermissionAsync(PermissionInfo info) {
624 try {
625 return mPM.addPermissionAsync(info);
626 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700627 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800628 }
629 }
630
631 @Override
632 public void removePermission(String name) {
633 try {
634 mPM.removePermission(name);
635 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700636 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800637 }
638 }
639
640 @Override
Svet Ganov8c7f7002015-05-07 10:48:44 -0700641 public void grantRuntimePermission(String packageName, String permissionName,
642 UserHandle user) {
Dianne Hackborne639da72012-02-21 15:11:13 -0800643 try {
Svet Ganov8c7f7002015-05-07 10:48:44 -0700644 mPM.grantRuntimePermission(packageName, permissionName, user.getIdentifier());
Dianne Hackborne639da72012-02-21 15:11:13 -0800645 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700646 throw e.rethrowFromSystemServer();
Dianne Hackborne639da72012-02-21 15:11:13 -0800647 }
648 }
649
650 @Override
Svet Ganov8c7f7002015-05-07 10:48:44 -0700651 public void revokeRuntimePermission(String packageName, String permissionName,
652 UserHandle user) {
Dianne Hackborne639da72012-02-21 15:11:13 -0800653 try {
Svet Ganov8c7f7002015-05-07 10:48:44 -0700654 mPM.revokeRuntimePermission(packageName, permissionName, user.getIdentifier());
655 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700656 throw e.rethrowFromSystemServer();
Svet Ganov8c7f7002015-05-07 10:48:44 -0700657 }
658 }
659
660 @Override
661 public int getPermissionFlags(String permissionName, String packageName, UserHandle user) {
662 try {
663 return mPM.getPermissionFlags(permissionName, packageName, user.getIdentifier());
664 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700665 throw e.rethrowFromSystemServer();
Svet Ganov8c7f7002015-05-07 10:48:44 -0700666 }
667 }
668
669 @Override
670 public void updatePermissionFlags(String permissionName, String packageName,
671 int flagMask, int flagValues, UserHandle user) {
672 try {
673 mPM.updatePermissionFlags(permissionName, packageName, flagMask,
674 flagValues, user.getIdentifier());
Dianne Hackborne639da72012-02-21 15:11:13 -0800675 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700676 throw e.rethrowFromSystemServer();
Dianne Hackborne639da72012-02-21 15:11:13 -0800677 }
678 }
679
680 @Override
Svetoslav20770dd2015-05-29 15:43:04 -0700681 public boolean shouldShowRequestPermissionRationale(String permission) {
682 try {
683 return mPM.shouldShowRequestPermissionRationale(permission,
684 mContext.getPackageName(), mContext.getUserId());
685 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700686 throw e.rethrowFromSystemServer();
Svetoslav20770dd2015-05-29 15:43:04 -0700687 }
688 }
689
690 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800691 public int checkSignatures(String pkg1, String pkg2) {
692 try {
693 return mPM.checkSignatures(pkg1, pkg2);
694 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700695 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800696 }
697 }
698
699 @Override
700 public int checkSignatures(int uid1, int uid2) {
701 try {
702 return mPM.checkUidSignatures(uid1, uid2);
703 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700704 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800705 }
706 }
707
708 @Override
Daniel Cashman5cdda342018-01-19 07:22:52 -0800709 public boolean hasSigningCertificate(
710 String packageName, byte[] certificate, @PackageManager.CertificateInputType int type) {
711 try {
712 return mPM.hasSigningCertificate(packageName, certificate, type);
713 } catch (RemoteException e) {
714 throw e.rethrowFromSystemServer();
715 }
716 }
717
718 @Override
719 public boolean hasSigningCertificate(
720 int uid, byte[] certificate, @PackageManager.CertificateInputType int type) {
721 try {
722 return mPM.hasUidSigningCertificate(uid, certificate, type);
723 } catch (RemoteException e) {
724 throw e.rethrowFromSystemServer();
725 }
726 }
727
728 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800729 public String[] getPackagesForUid(int uid) {
730 try {
731 return mPM.getPackagesForUid(uid);
732 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700733 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800734 }
735 }
736
737 @Override
738 public String getNameForUid(int uid) {
739 try {
740 return mPM.getNameForUid(uid);
741 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700742 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800743 }
744 }
745
746 @Override
Todd Kennedy9da8b8a72017-07-25 15:38:39 -0700747 public String[] getNamesForUids(int[] uids) {
748 try {
749 return mPM.getNamesForUids(uids);
750 } catch (RemoteException e) {
751 throw e.rethrowFromSystemServer();
752 }
753 }
754
755 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800756 public int getUidForSharedUser(String sharedUserName)
757 throws NameNotFoundException {
758 try {
759 int uid = mPM.getUidForSharedUser(sharedUserName);
760 if(uid != -1) {
761 return uid;
762 }
763 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700764 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800765 }
766 throw new NameNotFoundException("No shared userid for user:"+sharedUserName);
767 }
768
Kenny Roote6cd0c72011-05-19 12:48:14 -0700769 @SuppressWarnings("unchecked")
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800770 @Override
771 public List<PackageInfo> getInstalledPackages(int flags) {
Jeff Sharkeye06b4d12016-01-06 14:51:50 -0700772 return getInstalledPackagesAsUser(flags, mContext.getUserId());
Amith Yamasani151ec4c2012-09-07 19:25:16 -0700773 }
774
775 /** @hide */
776 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700777 @SuppressWarnings("unchecked")
Jeff Sharkeye06b4d12016-01-06 14:51:50 -0700778 public List<PackageInfo> getInstalledPackagesAsUser(int flags, int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800779 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700780 ParceledListSlice<PackageInfo> parceledList =
781 mPM.getInstalledPackages(flags, userId);
782 if (parceledList == null) {
783 return Collections.emptyList();
784 }
785 return parceledList.getList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800786 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700787 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800788 }
789 }
790
Kenny Roote6cd0c72011-05-19 12:48:14 -0700791 @SuppressWarnings("unchecked")
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800792 @Override
Dianne Hackborne7991752013-01-16 17:56:46 -0800793 public List<PackageInfo> getPackagesHoldingPermissions(
794 String[] permissions, int flags) {
795 final int userId = mContext.getUserId();
796 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700797 ParceledListSlice<PackageInfo> parceledList =
798 mPM.getPackagesHoldingPermissions(permissions, flags, userId);
799 if (parceledList == null) {
800 return Collections.emptyList();
801 }
802 return parceledList.getList();
Dianne Hackborne7991752013-01-16 17:56:46 -0800803 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700804 throw e.rethrowFromSystemServer();
Dianne Hackborne7991752013-01-16 17:56:46 -0800805 }
806 }
807
808 @SuppressWarnings("unchecked")
809 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800810 public List<ApplicationInfo> getInstalledApplications(int flags) {
Bartosz Fabianowski11334242016-11-17 20:49:16 +0100811 return getInstalledApplicationsAsUser(flags, mContext.getUserId());
812 }
813
814 /** @hide */
815 @SuppressWarnings("unchecked")
816 @Override
817 public List<ApplicationInfo> getInstalledApplicationsAsUser(int flags, int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800818 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700819 ParceledListSlice<ApplicationInfo> parceledList =
820 mPM.getInstalledApplications(flags, userId);
821 if (parceledList == null) {
822 return Collections.emptyList();
823 }
824 return parceledList.getList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800825 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700826 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800827 }
828 }
829
Svet Ganov2acf0632015-11-24 19:10:59 -0800830 /** @hide */
831 @SuppressWarnings("unchecked")
832 @Override
Svetoslav Ganov096d3042017-01-30 16:34:13 -0800833 public List<InstantAppInfo> getInstantApps() {
Svet Ganov2acf0632015-11-24 19:10:59 -0800834 try {
Svetoslav Ganov096d3042017-01-30 16:34:13 -0800835 ParceledListSlice<InstantAppInfo> slice =
836 mPM.getInstantApps(mContext.getUserId());
Svet Ganov2acf0632015-11-24 19:10:59 -0800837 if (slice != null) {
838 return slice.getList();
839 }
840 return Collections.emptyList();
841 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700842 throw e.rethrowFromSystemServer();
Svet Ganov2acf0632015-11-24 19:10:59 -0800843 }
844 }
845
846 /** @hide */
847 @Override
Svetoslav Ganov096d3042017-01-30 16:34:13 -0800848 public Drawable getInstantAppIcon(String packageName) {
Svet Ganov2acf0632015-11-24 19:10:59 -0800849 try {
Svetoslav Ganov096d3042017-01-30 16:34:13 -0800850 Bitmap bitmap = mPM.getInstantAppIcon(
Svet Ganov2acf0632015-11-24 19:10:59 -0800851 packageName, mContext.getUserId());
852 if (bitmap != null) {
853 return new BitmapDrawable(null, bitmap);
854 }
855 return null;
856 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700857 throw e.rethrowFromSystemServer();
Svet Ganov2acf0632015-11-24 19:10:59 -0800858 }
859 }
860
861 @Override
Svetoslav Ganov096d3042017-01-30 16:34:13 -0800862 public boolean isInstantApp() {
David Christie31a16552017-03-01 15:08:45 -0800863 return isInstantApp(mContext.getPackageName());
864 }
865
866 @Override
867 public boolean isInstantApp(String packageName) {
Svet Ganov2acf0632015-11-24 19:10:59 -0800868 try {
David Christie31a16552017-03-01 15:08:45 -0800869 return mPM.isInstantApp(packageName, mContext.getUserId());
Svet Ganov2acf0632015-11-24 19:10:59 -0800870 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700871 throw e.rethrowFromSystemServer();
Svet Ganov2acf0632015-11-24 19:10:59 -0800872 }
Svet Ganov2acf0632015-11-24 19:10:59 -0800873 }
874
Svetoslav Ganov345ffa52017-04-18 16:08:41 -0700875 public int getInstantAppCookieMaxBytes() {
Svet Ganov2acf0632015-11-24 19:10:59 -0800876 return Settings.Global.getInt(mContext.getContentResolver(),
877 Settings.Global.EPHEMERAL_COOKIE_MAX_SIZE_BYTES,
878 DEFAULT_EPHEMERAL_COOKIE_MAX_SIZE_BYTES);
879 }
880
881 @Override
Svetoslav Ganov345ffa52017-04-18 16:08:41 -0700882 public int getInstantAppCookieMaxSize() {
883 return getInstantAppCookieMaxBytes();
884 }
885
886 @Override
Svetoslav Ganov096d3042017-01-30 16:34:13 -0800887 public @NonNull byte[] getInstantAppCookie() {
Svet Ganov2acf0632015-11-24 19:10:59 -0800888 try {
Svetoslav Ganov096d3042017-01-30 16:34:13 -0800889 final byte[] cookie = mPM.getInstantAppCookie(
Svet Ganov2acf0632015-11-24 19:10:59 -0800890 mContext.getPackageName(), mContext.getUserId());
891 if (cookie != null) {
892 return cookie;
Jeff Sharkey27b2e692016-02-25 17:40:12 -0700893 } else {
894 return EmptyArray.BYTE;
Svet Ganov2acf0632015-11-24 19:10:59 -0800895 }
896 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700897 throw e.rethrowFromSystemServer();
Svet Ganov2acf0632015-11-24 19:10:59 -0800898 }
Svet Ganov2acf0632015-11-24 19:10:59 -0800899 }
900
901 @Override
Svetoslav Ganov345ffa52017-04-18 16:08:41 -0700902 public void clearInstantAppCookie() {
903 updateInstantAppCookie(null);
904 }
905
906 @Override
907 public void updateInstantAppCookie(@NonNull byte[] cookie) {
908 if (cookie != null && cookie.length > getInstantAppCookieMaxBytes()) {
909 throw new IllegalArgumentException("instant cookie longer than "
910 + getInstantAppCookieMaxBytes());
911 }
912 try {
913 mPM.setInstantAppCookie(mContext.getPackageName(),
914 cookie, mContext.getUserId());
915 } catch (RemoteException e) {
916 throw e.rethrowFromSystemServer();
917 }
918 }
919
920 @Override
Svetoslav Ganov096d3042017-01-30 16:34:13 -0800921 public boolean setInstantAppCookie(@NonNull byte[] cookie) {
Svet Ganov2acf0632015-11-24 19:10:59 -0800922 try {
Svetoslav Ganov096d3042017-01-30 16:34:13 -0800923 return mPM.setInstantAppCookie(mContext.getPackageName(),
924 cookie, mContext.getUserId());
Svet Ganov2acf0632015-11-24 19:10:59 -0800925 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700926 throw e.rethrowFromSystemServer();
Svet Ganov2acf0632015-11-24 19:10:59 -0800927 }
Svet Ganov2acf0632015-11-24 19:10:59 -0800928 }
929
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800930 @Override
931 public ResolveInfo resolveActivity(Intent intent, int flags) {
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700932 return resolveActivityAsUser(intent, flags, mContext.getUserId());
Svetoslav Ganov58d37b52012-09-18 12:04:19 -0700933 }
934
935 @Override
936 public ResolveInfo resolveActivityAsUser(Intent intent, int flags, int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800937 try {
938 return mPM.resolveIntent(
939 intent,
940 intent.resolveTypeIfNeeded(mContext.getContentResolver()),
Svetoslav Ganov58d37b52012-09-18 12:04:19 -0700941 flags,
942 userId);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800943 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700944 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800945 }
946 }
947
948 @Override
949 public List<ResolveInfo> queryIntentActivities(Intent intent,
950 int flags) {
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700951 return queryIntentActivitiesAsUser(intent, flags, mContext.getUserId());
Amith Yamasani151ec4c2012-09-07 19:25:16 -0700952 }
953
954 /** @hide Same as above but for a specific user */
955 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700956 @SuppressWarnings("unchecked")
Svetoslav Ganov58d37b52012-09-18 12:04:19 -0700957 public List<ResolveInfo> queryIntentActivitiesAsUser(Intent intent,
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700958 int flags, int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800959 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700960 ParceledListSlice<ResolveInfo> parceledList =
961 mPM.queryIntentActivities(intent,
962 intent.resolveTypeIfNeeded(mContext.getContentResolver()),
963 flags, userId);
964 if (parceledList == null) {
965 return Collections.emptyList();
966 }
967 return parceledList.getList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800968 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700969 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800970 }
971 }
972
973 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700974 @SuppressWarnings("unchecked")
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800975 public List<ResolveInfo> queryIntentActivityOptions(
976 ComponentName caller, Intent[] specifics, Intent intent,
977 int flags) {
978 final ContentResolver resolver = mContext.getContentResolver();
979
980 String[] specificTypes = null;
981 if (specifics != null) {
982 final int N = specifics.length;
983 for (int i=0; i<N; i++) {
984 Intent sp = specifics[i];
985 if (sp != null) {
986 String t = sp.resolveTypeIfNeeded(resolver);
987 if (t != null) {
988 if (specificTypes == null) {
989 specificTypes = new String[N];
990 }
991 specificTypes[i] = t;
992 }
993 }
994 }
995 }
996
997 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700998 ParceledListSlice<ResolveInfo> parceledList =
999 mPM.queryIntentActivityOptions(caller, specifics, specificTypes, intent,
1000 intent.resolveTypeIfNeeded(resolver), flags, mContext.getUserId());
1001 if (parceledList == null) {
1002 return Collections.emptyList();
1003 }
1004 return parceledList.getList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001005 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001006 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001007 }
1008 }
1009
Amith Yamasanif203aee2012-08-29 18:41:53 -07001010 /**
1011 * @hide
1012 */
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001013 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001014 @SuppressWarnings("unchecked")
Jeff Sharkeye06b4d12016-01-06 14:51:50 -07001015 public List<ResolveInfo> queryBroadcastReceiversAsUser(Intent intent, int flags, int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001016 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001017 ParceledListSlice<ResolveInfo> parceledList =
1018 mPM.queryIntentReceivers(intent,
1019 intent.resolveTypeIfNeeded(mContext.getContentResolver()),
1020 flags, userId);
1021 if (parceledList == null) {
1022 return Collections.emptyList();
1023 }
1024 return parceledList.getList();
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
Amith Yamasanif203aee2012-08-29 18:41:53 -07001031 public List<ResolveInfo> queryBroadcastReceivers(Intent intent, int flags) {
Jeff Sharkeye06b4d12016-01-06 14:51:50 -07001032 return queryBroadcastReceiversAsUser(intent, flags, mContext.getUserId());
Amith Yamasanif203aee2012-08-29 18:41:53 -07001033 }
1034
1035 @Override
Philip P. Moltmann18e3eb82018-03-09 16:55:55 -08001036 public ResolveInfo resolveServiceAsUser(Intent intent, @ResolveInfoFlags int flags,
1037 @UserIdInt int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001038 try {
1039 return mPM.resolveService(
1040 intent,
1041 intent.resolveTypeIfNeeded(mContext.getContentResolver()),
Amith Yamasani483f3b02012-03-13 16:08:00 -07001042 flags,
Philip P. Moltmann18e3eb82018-03-09 16:55:55 -08001043 userId);
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
Philip P. Moltmann18e3eb82018-03-09 16:55:55 -08001050 public ResolveInfo resolveService(Intent intent, int flags) {
1051 return resolveServiceAsUser(intent, flags, mContext.getUserId());
1052 }
1053
1054 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001055 @SuppressWarnings("unchecked")
Svetoslav Ganov58d37b52012-09-18 12:04:19 -07001056 public List<ResolveInfo> queryIntentServicesAsUser(Intent intent, int flags, int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001057 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001058 ParceledListSlice<ResolveInfo> parceledList =
1059 mPM.queryIntentServices(intent,
1060 intent.resolveTypeIfNeeded(mContext.getContentResolver()),
1061 flags, userId);
1062 if (parceledList == null) {
1063 return Collections.emptyList();
1064 }
1065 return parceledList.getList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001066 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001067 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001068 }
1069 }
1070
1071 @Override
Svetoslav Ganov58d37b52012-09-18 12:04:19 -07001072 public List<ResolveInfo> queryIntentServices(Intent intent, int flags) {
Jeff Sharkeyded653b2012-09-27 19:09:24 -07001073 return queryIntentServicesAsUser(intent, flags, mContext.getUserId());
Svetoslav Ganov58d37b52012-09-18 12:04:19 -07001074 }
1075
1076 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001077 @SuppressWarnings("unchecked")
Jeff Sharkey85f5f812013-10-07 10:16:12 -07001078 public List<ResolveInfo> queryIntentContentProvidersAsUser(
1079 Intent intent, int flags, int userId) {
1080 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001081 ParceledListSlice<ResolveInfo> parceledList =
1082 mPM.queryIntentContentProviders(intent,
1083 intent.resolveTypeIfNeeded(mContext.getContentResolver()),
1084 flags, userId);
1085 if (parceledList == null) {
1086 return Collections.emptyList();
1087 }
1088 return parceledList.getList();
Jeff Sharkey85f5f812013-10-07 10:16:12 -07001089 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001090 throw e.rethrowFromSystemServer();
Jeff Sharkey85f5f812013-10-07 10:16:12 -07001091 }
1092 }
1093
1094 @Override
1095 public List<ResolveInfo> queryIntentContentProviders(Intent intent, int flags) {
1096 return queryIntentContentProvidersAsUser(intent, flags, mContext.getUserId());
1097 }
1098
1099 @Override
Alexandra Gherghina0363c3e2014-06-23 13:34:59 +01001100 public ProviderInfo resolveContentProvider(String name, int flags) {
1101 return resolveContentProviderAsUser(name, flags, mContext.getUserId());
1102 }
1103
1104 /** @hide **/
1105 @Override
1106 public ProviderInfo resolveContentProviderAsUser(String name, int flags, int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001107 try {
Alexandra Gherghina0363c3e2014-06-23 13:34:59 +01001108 return mPM.resolveContentProvider(name, flags, userId);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001109 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001110 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001111 }
1112 }
1113
1114 @Override
1115 public List<ProviderInfo> queryContentProviders(String processName,
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001116 int uid, int flags) {
Makoto Onuki32757292017-02-22 14:36:59 -08001117 return queryContentProviders(processName, uid, flags, null);
1118 }
1119
1120 @Override
1121 @SuppressWarnings("unchecked")
1122 public List<ProviderInfo> queryContentProviders(String processName,
1123 int uid, int flags, String metaDataKey) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001124 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001125 ParceledListSlice<ProviderInfo> slice =
Makoto Onuki32757292017-02-22 14:36:59 -08001126 mPM.queryContentProviders(processName, uid, flags, metaDataKey);
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001127 return slice != null ? slice.getList() : Collections.<ProviderInfo>emptyList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001128 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001129 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001130 }
1131 }
1132
1133 @Override
1134 public InstrumentationInfo getInstrumentationInfo(
1135 ComponentName className, int flags)
1136 throws NameNotFoundException {
1137 try {
1138 InstrumentationInfo ii = mPM.getInstrumentationInfo(
1139 className, flags);
1140 if (ii != null) {
1141 return ii;
1142 }
1143 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001144 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001145 }
1146
1147 throw new NameNotFoundException(className.toString());
1148 }
1149
1150 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001151 @SuppressWarnings("unchecked")
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001152 public List<InstrumentationInfo> queryInstrumentation(
1153 String targetPackage, int flags) {
1154 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001155 ParceledListSlice<InstrumentationInfo> parceledList =
1156 mPM.queryInstrumentation(targetPackage, flags);
1157 if (parceledList == null) {
1158 return Collections.emptyList();
1159 }
1160 return parceledList.getList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001161 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001162 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001163 }
1164 }
1165
Alan Viveretteecd585a2015-04-13 10:32:51 -07001166 @Nullable
1167 @Override
1168 public Drawable getDrawable(String packageName, @DrawableRes int resId,
1169 @Nullable ApplicationInfo appInfo) {
1170 final ResourceName name = new ResourceName(packageName, resId);
1171 final Drawable cachedIcon = getCachedIcon(name);
1172 if (cachedIcon != null) {
1173 return cachedIcon;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001174 }
Alan Viveretteecd585a2015-04-13 10:32:51 -07001175
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001176 if (appInfo == null) {
1177 try {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001178 appInfo = getApplicationInfo(packageName, sDefaultFlags);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001179 } catch (NameNotFoundException e) {
1180 return null;
1181 }
1182 }
Alan Viveretteecd585a2015-04-13 10:32:51 -07001183
1184 if (resId != 0) {
1185 try {
1186 final Resources r = getResourcesForApplication(appInfo);
1187 final Drawable dr = r.getDrawable(resId, null);
1188 if (dr != null) {
1189 putCachedIcon(name, dr);
1190 }
1191
1192 if (false) {
1193 RuntimeException e = new RuntimeException("here");
1194 e.fillInStackTrace();
1195 Log.w(TAG, "Getting drawable 0x" + Integer.toHexString(resId)
1196 + " from package " + packageName
1197 + ": app scale=" + r.getCompatibilityInfo().applicationScale
1198 + ", caller scale=" + mContext.getResources()
1199 .getCompatibilityInfo().applicationScale,
1200 e);
1201 }
Ricky Wai3ce46252015-04-15 16:12:22 +01001202 if (DEBUG_ICONS) {
Alan Viveretteecd585a2015-04-13 10:32:51 -07001203 Log.v(TAG, "Getting drawable 0x"
1204 + Integer.toHexString(resId) + " from " + r
1205 + ": " + dr);
Ricky Wai3ce46252015-04-15 16:12:22 +01001206 }
1207 return dr;
Alan Viveretteecd585a2015-04-13 10:32:51 -07001208 } catch (NameNotFoundException e) {
1209 Log.w("PackageManager", "Failure retrieving resources for "
1210 + appInfo.packageName);
1211 } catch (Resources.NotFoundException e) {
1212 Log.w("PackageManager", "Failure retrieving resources for "
1213 + appInfo.packageName + ": " + e.getMessage());
1214 } catch (Exception e) {
1215 // If an exception was thrown, fall through to return
1216 // default icon.
1217 Log.w("PackageManager", "Failure retrieving icon 0x"
1218 + Integer.toHexString(resId) + " in package "
1219 + packageName, e);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001220 }
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001221 }
Alan Viveretteecd585a2015-04-13 10:32:51 -07001222
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001223 return null;
1224 }
1225
1226 @Override public Drawable getActivityIcon(ComponentName activityName)
1227 throws NameNotFoundException {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001228 return getActivityInfo(activityName, sDefaultFlags).loadIcon(this);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001229 }
1230
1231 @Override public Drawable getActivityIcon(Intent intent)
1232 throws NameNotFoundException {
1233 if (intent.getComponent() != null) {
1234 return getActivityIcon(intent.getComponent());
1235 }
1236
1237 ResolveInfo info = resolveActivity(
1238 intent, PackageManager.MATCH_DEFAULT_ONLY);
1239 if (info != null) {
1240 return info.activityInfo.loadIcon(this);
1241 }
1242
Romain Guy39fe17c2011-11-30 10:34:07 -08001243 throw new NameNotFoundException(intent.toUri(0));
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001244 }
1245
1246 @Override public Drawable getDefaultActivityIcon() {
1247 return Resources.getSystem().getDrawable(
1248 com.android.internal.R.drawable.sym_def_app_icon);
1249 }
1250
1251 @Override public Drawable getApplicationIcon(ApplicationInfo info) {
1252 return info.loadIcon(this);
1253 }
1254
1255 @Override public Drawable getApplicationIcon(String packageName)
1256 throws NameNotFoundException {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001257 return getApplicationIcon(getApplicationInfo(packageName, sDefaultFlags));
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001258 }
1259
1260 @Override
Jose Limaf78e3122014-03-06 12:13:15 -08001261 public Drawable getActivityBanner(ComponentName activityName)
1262 throws NameNotFoundException {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001263 return getActivityInfo(activityName, sDefaultFlags).loadBanner(this);
Jose Limaf78e3122014-03-06 12:13:15 -08001264 }
1265
1266 @Override
1267 public Drawable getActivityBanner(Intent intent)
1268 throws NameNotFoundException {
1269 if (intent.getComponent() != null) {
1270 return getActivityBanner(intent.getComponent());
1271 }
1272
1273 ResolveInfo info = resolveActivity(
1274 intent, PackageManager.MATCH_DEFAULT_ONLY);
1275 if (info != null) {
1276 return info.activityInfo.loadBanner(this);
1277 }
1278
1279 throw new NameNotFoundException(intent.toUri(0));
1280 }
1281
1282 @Override
1283 public Drawable getApplicationBanner(ApplicationInfo info) {
1284 return info.loadBanner(this);
1285 }
1286
1287 @Override
1288 public Drawable getApplicationBanner(String packageName)
1289 throws NameNotFoundException {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001290 return getApplicationBanner(getApplicationInfo(packageName, sDefaultFlags));
Jose Limaf78e3122014-03-06 12:13:15 -08001291 }
1292
1293 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001294 public Drawable getActivityLogo(ComponentName activityName)
1295 throws NameNotFoundException {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001296 return getActivityInfo(activityName, sDefaultFlags).loadLogo(this);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001297 }
1298
1299 @Override
1300 public Drawable getActivityLogo(Intent intent)
1301 throws NameNotFoundException {
1302 if (intent.getComponent() != null) {
1303 return getActivityLogo(intent.getComponent());
1304 }
1305
1306 ResolveInfo info = resolveActivity(
1307 intent, PackageManager.MATCH_DEFAULT_ONLY);
1308 if (info != null) {
1309 return info.activityInfo.loadLogo(this);
1310 }
1311
1312 throw new NameNotFoundException(intent.toUri(0));
1313 }
1314
1315 @Override
1316 public Drawable getApplicationLogo(ApplicationInfo info) {
1317 return info.loadLogo(this);
1318 }
1319
1320 @Override
1321 public Drawable getApplicationLogo(String packageName)
1322 throws NameNotFoundException {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001323 return getApplicationLogo(getApplicationInfo(packageName, sDefaultFlags));
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001324 }
1325
Svetoslavc7d62f02014-09-04 15:39:54 -07001326 @Override
1327 public Drawable getUserBadgedIcon(Drawable icon, UserHandle user) {
Kenny Guy02c89902016-11-15 19:36:38 +00001328 if (!isManagedProfile(user.getIdentifier())) {
Svetoslavc7d62f02014-09-04 15:39:54 -07001329 return icon;
1330 }
Sunny Goyalbab30752017-04-12 15:36:42 -07001331 Drawable badge = new LauncherIcons(mContext).getBadgeDrawable(
1332 com.android.internal.R.drawable.ic_corp_icon_badge_case,
1333 getUserBadgeColor(user));
Kenny Guy02c89902016-11-15 19:36:38 +00001334 return getBadgedDrawable(icon, badge, null, true);
Svetoslavc7d62f02014-09-04 15:39:54 -07001335 }
1336
1337 @Override
1338 public Drawable getUserBadgedDrawableForDensity(Drawable drawable, UserHandle user,
1339 Rect badgeLocation, int badgeDensity) {
1340 Drawable badgeDrawable = getUserBadgeForDensity(user, badgeDensity);
1341 if (badgeDrawable == null) {
1342 return drawable;
1343 }
1344 return getBadgedDrawable(drawable, badgeDrawable, badgeLocation, true);
1345 }
1346
Kenny Guy02c89902016-11-15 19:36:38 +00001347 @VisibleForTesting
1348 public static final int[] CORP_BADGE_LABEL_RES_ID = new int[] {
1349 com.android.internal.R.string.managed_profile_label_badge,
1350 com.android.internal.R.string.managed_profile_label_badge_2,
1351 com.android.internal.R.string.managed_profile_label_badge_3
1352 };
1353
1354 private int getUserBadgeColor(UserHandle user) {
Sunny Goyalbab30752017-04-12 15:36:42 -07001355 return IconDrawableFactory.getUserBadgeColor(getUserManager(), user.getIdentifier());
Kenny Guy02c89902016-11-15 19:36:38 +00001356 }
1357
Svetoslavc7d62f02014-09-04 15:39:54 -07001358 @Override
1359 public Drawable getUserBadgeForDensity(UserHandle user, int density) {
Kenny Guy02c89902016-11-15 19:36:38 +00001360 Drawable badgeColor = getManagedProfileIconForDensity(user,
1361 com.android.internal.R.drawable.ic_corp_badge_color, density);
1362 if (badgeColor == null) {
1363 return null;
1364 }
Kenny Guy02c89902016-11-15 19:36:38 +00001365 Drawable badgeForeground = getDrawableForDensity(
1366 com.android.internal.R.drawable.ic_corp_badge_case, density);
Tony Make21a1d02018-02-16 11:46:58 +00001367 badgeForeground.setTint(getUserBadgeColor(user));
1368 Drawable badge = new LayerDrawable(new Drawable[] {badgeColor, badgeForeground });
Kenny Guy02c89902016-11-15 19:36:38 +00001369 return badge;
Selim Cineke6ff9462016-01-15 15:07:06 -08001370 }
1371
1372 @Override
1373 public Drawable getUserBadgeForDensityNoBackground(UserHandle user, int density) {
Kenny Guy02c89902016-11-15 19:36:38 +00001374 Drawable badge = getManagedProfileIconForDensity(user,
Vadim Tryshev66ae66a2016-02-18 15:41:21 -08001375 com.android.internal.R.drawable.ic_corp_badge_no_background, density);
Kenny Guy02c89902016-11-15 19:36:38 +00001376 if (badge != null) {
1377 badge.setTint(getUserBadgeColor(user));
1378 }
1379 return badge;
Selim Cineke6ff9462016-01-15 15:07:06 -08001380 }
1381
Vadim Tryshev66ae66a2016-02-18 15:41:21 -08001382 private Drawable getDrawableForDensity(int drawableId, int density) {
1383 if (density <= 0) {
1384 density = mContext.getResources().getDisplayMetrics().densityDpi;
1385 }
1386 return Resources.getSystem().getDrawableForDensity(drawableId, density);
1387 }
1388
1389 private Drawable getManagedProfileIconForDensity(UserHandle user, int drawableId, int density) {
Tony Mak8673b282016-03-21 21:10:59 +00001390 if (isManagedProfile(user.getIdentifier())) {
Vadim Tryshev66ae66a2016-02-18 15:41:21 -08001391 return getDrawableForDensity(drawableId, density);
Svetoslavc7d62f02014-09-04 15:39:54 -07001392 }
1393 return null;
1394 }
1395
1396 @Override
1397 public CharSequence getUserBadgedLabel(CharSequence label, UserHandle user) {
Tony Mak8673b282016-03-21 21:10:59 +00001398 if (isManagedProfile(user.getIdentifier())) {
Kenny Guy02c89902016-11-15 19:36:38 +00001399 int badge = getUserManager().getManagedProfileBadge(user.getIdentifier());
1400 int resourceId = CORP_BADGE_LABEL_RES_ID[badge % CORP_BADGE_LABEL_RES_ID.length];
1401 return Resources.getSystem().getString(resourceId, label);
Svetoslavc7d62f02014-09-04 15:39:54 -07001402 }
1403 return label;
1404 }
1405
Alan Viveretteecd585a2015-04-13 10:32:51 -07001406 @Override
1407 public Resources getResourcesForActivity(ComponentName activityName)
1408 throws NameNotFoundException {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001409 return getResourcesForApplication(
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001410 getActivityInfo(activityName, sDefaultFlags).applicationInfo);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001411 }
1412
Alan Viveretteecd585a2015-04-13 10:32:51 -07001413 @Override
1414 public Resources getResourcesForApplication(@NonNull ApplicationInfo app)
1415 throws NameNotFoundException {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001416 if (app.packageName.equals("system")) {
Adam Lesinskia82b6262017-03-21 16:56:17 -07001417 return mContext.mMainThread.getSystemUiContext().getResources();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001418 }
Jeff Sharkey8a4c9722014-06-16 13:48:42 -07001419 final boolean sameUid = (app.uid == Process.myUid());
Adam Lesinski53fafdf2016-08-03 13:36:39 -07001420 final Resources r = mContext.mMainThread.getTopLevelResources(
Adam Lesinskic82f28a2016-06-08 17:19:09 -07001421 sameUid ? app.sourceDir : app.publicSourceDir,
1422 sameUid ? app.splitSourceDirs : app.splitPublicSourceDirs,
1423 app.resourceDirs, app.sharedLibraryFiles, Display.DEFAULT_DISPLAY,
Todd Kennedy233a0b12018-01-29 20:30:24 +00001424 mContext.mPackageInfo);
Adam Lesinski53fafdf2016-08-03 13:36:39 -07001425 if (r != null) {
1426 return r;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001427 }
Adam Lesinski53fafdf2016-08-03 13:36:39 -07001428 throw new NameNotFoundException("Unable to open " + app.publicSourceDir);
1429
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001430 }
1431
Alan Viveretteecd585a2015-04-13 10:32:51 -07001432 @Override
1433 public Resources getResourcesForApplication(String appPackageName)
1434 throws NameNotFoundException {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001435 return getResourcesForApplication(
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001436 getApplicationInfo(appPackageName, sDefaultFlags));
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001437 }
1438
Amith Yamasani98edc952012-09-25 14:09:27 -07001439 /** @hide */
1440 @Override
1441 public Resources getResourcesForApplicationAsUser(String appPackageName, int userId)
1442 throws NameNotFoundException {
Jeff Sharkeyded653b2012-09-27 19:09:24 -07001443 if (userId < 0) {
1444 throw new IllegalArgumentException(
1445 "Call does not support special user #" + userId);
1446 }
1447 if ("system".equals(appPackageName)) {
Adam Lesinskia82b6262017-03-21 16:56:17 -07001448 return mContext.mMainThread.getSystemUiContext().getResources();
Jeff Sharkeyded653b2012-09-27 19:09:24 -07001449 }
Amith Yamasani98edc952012-09-25 14:09:27 -07001450 try {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001451 ApplicationInfo ai = mPM.getApplicationInfo(appPackageName, sDefaultFlags, userId);
Amith Yamasani98edc952012-09-25 14:09:27 -07001452 if (ai != null) {
1453 return getResourcesForApplication(ai);
1454 }
1455 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001456 throw e.rethrowFromSystemServer();
Amith Yamasani98edc952012-09-25 14:09:27 -07001457 }
1458 throw new NameNotFoundException("Package " + appPackageName + " doesn't exist");
1459 }
1460
Jeff Sharkeycd654482016-01-08 17:42:11 -07001461 volatile int mCachedSafeMode = -1;
1462
1463 @Override
1464 public boolean isSafeMode() {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001465 try {
1466 if (mCachedSafeMode < 0) {
1467 mCachedSafeMode = mPM.isSafeMode() ? 1 : 0;
1468 }
1469 return mCachedSafeMode != 0;
1470 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001471 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001472 }
1473 }
1474
Svetoslavf7c06eb2015-06-10 18:43:22 -07001475 @Override
1476 public void addOnPermissionsChangeListener(OnPermissionsChangedListener listener) {
1477 synchronized (mPermissionListeners) {
1478 if (mPermissionListeners.get(listener) != null) {
1479 return;
1480 }
1481 OnPermissionsChangeListenerDelegate delegate =
1482 new OnPermissionsChangeListenerDelegate(listener, Looper.getMainLooper());
1483 try {
1484 mPM.addOnPermissionsChangeListener(delegate);
1485 mPermissionListeners.put(listener, delegate);
1486 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001487 throw e.rethrowFromSystemServer();
Svetoslavf7c06eb2015-06-10 18:43:22 -07001488 }
1489 }
1490 }
1491
1492 @Override
1493 public void removeOnPermissionsChangeListener(OnPermissionsChangedListener listener) {
1494 synchronized (mPermissionListeners) {
1495 IOnPermissionsChangeListener delegate = mPermissionListeners.get(listener);
1496 if (delegate != null) {
1497 try {
1498 mPM.removeOnPermissionsChangeListener(delegate);
1499 mPermissionListeners.remove(listener);
1500 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001501 throw e.rethrowFromSystemServer();
Svetoslavf7c06eb2015-06-10 18:43:22 -07001502 }
1503 }
1504 }
1505 }
1506
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001507 static void configurationChanged() {
1508 synchronized (sSync) {
1509 sIconCache.clear();
1510 sStringCache.clear();
1511 }
1512 }
1513
Yao Chen022b8ea2016-12-16 11:03:28 -08001514 protected ApplicationPackageManager(ContextImpl context,
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001515 IPackageManager pm) {
1516 mContext = context;
1517 mPM = pm;
1518 }
1519
Alan Viveretteecd585a2015-04-13 10:32:51 -07001520 @Nullable
1521 private Drawable getCachedIcon(@NonNull ResourceName name) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001522 synchronized (sSync) {
Alan Viveretteecd585a2015-04-13 10:32:51 -07001523 final WeakReference<Drawable.ConstantState> wr = sIconCache.get(name);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001524 if (DEBUG_ICONS) Log.v(TAG, "Get cached weak drawable ref for "
1525 + name + ": " + wr);
1526 if (wr != null) { // we have the activity
Alan Viveretteecd585a2015-04-13 10:32:51 -07001527 final Drawable.ConstantState state = wr.get();
Romain Guy39fe17c2011-11-30 10:34:07 -08001528 if (state != null) {
1529 if (DEBUG_ICONS) {
1530 Log.v(TAG, "Get cached drawable state for " + name + ": " + state);
1531 }
1532 // Note: It's okay here to not use the newDrawable(Resources) variant
1533 // of the API. The ConstantState comes from a drawable that was
1534 // originally created by passing the proper app Resources instance
1535 // which means the state should already contain the proper
1536 // resources specific information (like density.) See
1537 // BitmapDrawable.BitmapState for instance.
1538 return state.newDrawable();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001539 }
1540 // our entry has been purged
1541 sIconCache.remove(name);
1542 }
1543 }
1544 return null;
1545 }
1546
Alan Viveretteecd585a2015-04-13 10:32:51 -07001547 private void putCachedIcon(@NonNull ResourceName name, @NonNull Drawable dr) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001548 synchronized (sSync) {
Alan Viveretteecd585a2015-04-13 10:32:51 -07001549 sIconCache.put(name, new WeakReference<>(dr.getConstantState()));
Romain Guy39fe17c2011-11-30 10:34:07 -08001550 if (DEBUG_ICONS) Log.v(TAG, "Added cached drawable state for " + name + ": " + dr);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001551 }
1552 }
1553
Romain Guy39fe17c2011-11-30 10:34:07 -08001554 static void handlePackageBroadcast(int cmd, String[] pkgList, boolean hasPkgInfo) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001555 boolean immediateGc = false;
Sudheer Shankacc6418f2016-10-13 12:03:44 -07001556 if (cmd == ApplicationThreadConstants.EXTERNAL_STORAGE_UNAVAILABLE) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001557 immediateGc = true;
1558 }
1559 if (pkgList != null && (pkgList.length > 0)) {
1560 boolean needCleanup = false;
1561 for (String ssp : pkgList) {
1562 synchronized (sSync) {
Dianne Hackbornadd005c2013-07-17 18:43:12 -07001563 for (int i=sIconCache.size()-1; i>=0; i--) {
1564 ResourceName nm = sIconCache.keyAt(i);
1565 if (nm.packageName.equals(ssp)) {
1566 //Log.i(TAG, "Removing cached drawable for " + nm);
1567 sIconCache.removeAt(i);
1568 needCleanup = true;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001569 }
1570 }
Dianne Hackbornadd005c2013-07-17 18:43:12 -07001571 for (int i=sStringCache.size()-1; i>=0; i--) {
1572 ResourceName nm = sStringCache.keyAt(i);
1573 if (nm.packageName.equals(ssp)) {
1574 //Log.i(TAG, "Removing cached string for " + nm);
1575 sStringCache.removeAt(i);
1576 needCleanup = true;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001577 }
1578 }
1579 }
1580 }
1581 if (needCleanup || hasPkgInfo) {
1582 if (immediateGc) {
1583 // Schedule an immediate gc.
1584 Runtime.getRuntime().gc();
1585 } else {
1586 ActivityThread.currentActivityThread().scheduleGcIdler();
1587 }
1588 }
1589 }
1590 }
1591
1592 private static final class ResourceName {
1593 final String packageName;
1594 final int iconId;
1595
1596 ResourceName(String _packageName, int _iconId) {
1597 packageName = _packageName;
1598 iconId = _iconId;
1599 }
1600
1601 ResourceName(ApplicationInfo aInfo, int _iconId) {
1602 this(aInfo.packageName, _iconId);
1603 }
1604
1605 ResourceName(ComponentInfo cInfo, int _iconId) {
1606 this(cInfo.applicationInfo.packageName, _iconId);
1607 }
1608
1609 ResourceName(ResolveInfo rInfo, int _iconId) {
1610 this(rInfo.activityInfo.applicationInfo.packageName, _iconId);
1611 }
1612
1613 @Override
1614 public boolean equals(Object o) {
1615 if (this == o) return true;
1616 if (o == null || getClass() != o.getClass()) return false;
1617
1618 ResourceName that = (ResourceName) o;
1619
1620 if (iconId != that.iconId) return false;
1621 return !(packageName != null ?
1622 !packageName.equals(that.packageName) : that.packageName != null);
1623
1624 }
1625
1626 @Override
1627 public int hashCode() {
1628 int result;
1629 result = packageName.hashCode();
1630 result = 31 * result + iconId;
1631 return result;
1632 }
1633
1634 @Override
1635 public String toString() {
1636 return "{ResourceName " + packageName + " / " + iconId + "}";
1637 }
1638 }
1639
1640 private CharSequence getCachedString(ResourceName name) {
1641 synchronized (sSync) {
1642 WeakReference<CharSequence> wr = sStringCache.get(name);
1643 if (wr != null) { // we have the activity
1644 CharSequence cs = wr.get();
1645 if (cs != null) {
1646 return cs;
1647 }
1648 // our entry has been purged
1649 sStringCache.remove(name);
1650 }
1651 }
1652 return null;
1653 }
1654
1655 private void putCachedString(ResourceName name, CharSequence cs) {
1656 synchronized (sSync) {
1657 sStringCache.put(name, new WeakReference<CharSequence>(cs));
1658 }
1659 }
1660
1661 @Override
Tor Norbye7b9c9122013-05-30 16:48:33 -07001662 public CharSequence getText(String packageName, @StringRes int resid,
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001663 ApplicationInfo appInfo) {
1664 ResourceName name = new ResourceName(packageName, resid);
1665 CharSequence text = getCachedString(name);
1666 if (text != null) {
1667 return text;
1668 }
1669 if (appInfo == null) {
1670 try {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001671 appInfo = getApplicationInfo(packageName, sDefaultFlags);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001672 } catch (NameNotFoundException e) {
1673 return null;
1674 }
1675 }
1676 try {
1677 Resources r = getResourcesForApplication(appInfo);
1678 text = r.getText(resid);
1679 putCachedString(name, text);
1680 return text;
1681 } catch (NameNotFoundException e) {
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07001682 Log.w("PackageManager", "Failure retrieving resources for "
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001683 + appInfo.packageName);
1684 } catch (RuntimeException e) {
1685 // If an exception was thrown, fall through to return
1686 // default icon.
1687 Log.w("PackageManager", "Failure retrieving text 0x"
1688 + Integer.toHexString(resid) + " in package "
1689 + packageName, e);
1690 }
1691 return null;
1692 }
1693
1694 @Override
Tor Norbye7b9c9122013-05-30 16:48:33 -07001695 public XmlResourceParser getXml(String packageName, @XmlRes int resid,
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001696 ApplicationInfo appInfo) {
1697 if (appInfo == null) {
1698 try {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001699 appInfo = getApplicationInfo(packageName, sDefaultFlags);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001700 } catch (NameNotFoundException e) {
1701 return null;
1702 }
1703 }
1704 try {
1705 Resources r = getResourcesForApplication(appInfo);
1706 return r.getXml(resid);
1707 } catch (RuntimeException e) {
1708 // If an exception was thrown, fall through to return
1709 // default icon.
1710 Log.w("PackageManager", "Failure retrieving xml 0x"
1711 + Integer.toHexString(resid) + " in package "
1712 + packageName, e);
1713 } catch (NameNotFoundException e) {
Alon Albert3fa51e32010-11-11 09:24:04 -08001714 Log.w("PackageManager", "Failure retrieving resources for "
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001715 + appInfo.packageName);
1716 }
1717 return null;
1718 }
1719
1720 @Override
1721 public CharSequence getApplicationLabel(ApplicationInfo info) {
1722 return info.loadLabel(this);
1723 }
1724
1725 @Override
Nicolas Prevot9a80e532015-09-23 15:49:28 +01001726 public int installExistingPackage(String packageName) throws NameNotFoundException {
Sunny Goyala31a74b2017-05-11 15:59:19 -07001727 return installExistingPackage(packageName, PackageManager.INSTALL_REASON_UNKNOWN);
1728 }
1729
1730 @Override
1731 public int installExistingPackage(String packageName, int installReason)
1732 throws NameNotFoundException {
1733 return installExistingPackageAsUser(packageName, installReason, mContext.getUserId());
Nicolas Prevot9a80e532015-09-23 15:49:28 +01001734 }
1735
1736 @Override
1737 public int installExistingPackageAsUser(String packageName, int userId)
Dianne Hackborn7767eac2012-08-23 18:25:40 -07001738 throws NameNotFoundException {
Sunny Goyala31a74b2017-05-11 15:59:19 -07001739 return installExistingPackageAsUser(packageName, PackageManager.INSTALL_REASON_UNKNOWN,
1740 userId);
1741 }
1742
1743 private int installExistingPackageAsUser(String packageName, int installReason, int userId)
1744 throws NameNotFoundException {
Dianne Hackborn7767eac2012-08-23 18:25:40 -07001745 try {
Todd Kennedybe0b8892017-02-15 14:13:52 -08001746 int res = mPM.installExistingPackageAsUser(packageName, userId, 0 /*installFlags*/,
Sunny Goyala31a74b2017-05-11 15:59:19 -07001747 installReason);
Dianne Hackborn7767eac2012-08-23 18:25:40 -07001748 if (res == INSTALL_FAILED_INVALID_URI) {
1749 throw new NameNotFoundException("Package " + packageName + " doesn't exist");
1750 }
1751 return res;
1752 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001753 throw e.rethrowFromSystemServer();
Dianne Hackborn7767eac2012-08-23 18:25:40 -07001754 }
1755 }
1756
1757 @Override
Kenny Root3a9b5fb2011-09-20 14:15:38 -07001758 public void verifyPendingInstall(int id, int response) {
Kenny Root5ab21572011-07-27 11:11:19 -07001759 try {
Kenny Root3a9b5fb2011-09-20 14:15:38 -07001760 mPM.verifyPendingInstall(id, response);
Kenny Root5ab21572011-07-27 11:11:19 -07001761 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001762 throw e.rethrowFromSystemServer();
Kenny Root5ab21572011-07-27 11:11:19 -07001763 }
1764 }
1765
1766 @Override
rich canningsd9ef3e52012-08-22 14:28:05 -07001767 public void extendVerificationTimeout(int id, int verificationCodeAtTimeout,
1768 long millisecondsToDelay) {
1769 try {
1770 mPM.extendVerificationTimeout(id, verificationCodeAtTimeout, millisecondsToDelay);
1771 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001772 throw e.rethrowFromSystemServer();
rich canningsd9ef3e52012-08-22 14:28:05 -07001773 }
1774 }
1775
1776 @Override
Todd Kennedydfa93ab2016-03-03 15:24:33 -08001777 public void verifyIntentFilter(int id, int verificationCode, List<String> failedDomains) {
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001778 try {
Todd Kennedydfa93ab2016-03-03 15:24:33 -08001779 mPM.verifyIntentFilter(id, verificationCode, failedDomains);
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001780 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001781 throw e.rethrowFromSystemServer();
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001782 }
1783 }
1784
1785 @Override
Jeff Sharkeye06b4d12016-01-06 14:51:50 -07001786 public int getIntentVerificationStatusAsUser(String packageName, int userId) {
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001787 try {
1788 return mPM.getIntentVerificationStatus(packageName, userId);
1789 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001790 throw e.rethrowFromSystemServer();
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001791 }
1792 }
1793
1794 @Override
Jeff Sharkeye06b4d12016-01-06 14:51:50 -07001795 public boolean updateIntentVerificationStatusAsUser(String packageName, int status, int userId) {
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001796 try {
1797 return mPM.updateIntentVerificationStatus(packageName, status, userId);
1798 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001799 throw e.rethrowFromSystemServer();
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001800 }
1801 }
1802
1803 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001804 @SuppressWarnings("unchecked")
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001805 public List<IntentFilterVerificationInfo> getIntentFilterVerifications(String packageName) {
1806 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001807 ParceledListSlice<IntentFilterVerificationInfo> parceledList =
1808 mPM.getIntentFilterVerifications(packageName);
1809 if (parceledList == null) {
1810 return Collections.emptyList();
1811 }
1812 return parceledList.getList();
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001813 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001814 throw e.rethrowFromSystemServer();
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001815 }
1816 }
1817
1818 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001819 @SuppressWarnings("unchecked")
Fabrice Di Meglio07885952015-04-06 19:41:28 -07001820 public List<IntentFilter> getAllIntentFilters(String packageName) {
1821 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001822 ParceledListSlice<IntentFilter> parceledList =
1823 mPM.getAllIntentFilters(packageName);
1824 if (parceledList == null) {
1825 return Collections.emptyList();
1826 }
1827 return parceledList.getList();
Fabrice Di Meglio07885952015-04-06 19:41:28 -07001828 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001829 throw e.rethrowFromSystemServer();
Fabrice Di Meglio07885952015-04-06 19:41:28 -07001830 }
1831 }
1832
1833 @Override
Jeff Sharkeye06b4d12016-01-06 14:51:50 -07001834 public String getDefaultBrowserPackageNameAsUser(int userId) {
Fabrice Di Meglio62271722015-04-10 17:24:02 -07001835 try {
1836 return mPM.getDefaultBrowserPackageName(userId);
1837 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001838 throw e.rethrowFromSystemServer();
Fabrice Di Meglio62271722015-04-10 17:24:02 -07001839 }
1840 }
1841
1842 @Override
Jeff Sharkeye06b4d12016-01-06 14:51:50 -07001843 public boolean setDefaultBrowserPackageNameAsUser(String packageName, int userId) {
Fabrice Di Meglio62271722015-04-10 17:24:02 -07001844 try {
1845 return mPM.setDefaultBrowserPackageName(packageName, userId);
1846 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001847 throw e.rethrowFromSystemServer();
Fabrice Di Meglio62271722015-04-10 17:24:02 -07001848 }
1849 }
1850
1851 @Override
Dianne Hackborn880119b2010-11-18 22:26:40 -08001852 public void setInstallerPackageName(String targetPackage,
1853 String installerPackageName) {
1854 try {
1855 mPM.setInstallerPackageName(targetPackage, installerPackageName);
1856 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001857 throw e.rethrowFromSystemServer();
Dianne Hackborn880119b2010-11-18 22:26:40 -08001858 }
1859 }
1860
1861 @Override
Todd Kennedyab532892017-03-08 14:19:49 -08001862 public void setUpdateAvailable(String packageName, boolean updateAvailable) {
1863 try {
1864 mPM.setUpdateAvailable(packageName, updateAvailable);
1865 } catch (RemoteException e) {
1866 throw e.rethrowFromSystemServer();
1867 }
1868 }
1869
1870 @Override
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001871 public String getInstallerPackageName(String packageName) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001872 try {
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001873 return mPM.getInstallerPackageName(packageName);
1874 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001875 throw e.rethrowFromSystemServer();
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001876 }
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001877 }
1878
1879 @Override
1880 public int getMoveStatus(int moveId) {
1881 try {
1882 return mPM.getMoveStatus(moveId);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001883 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001884 throw e.rethrowFromSystemServer();
Jeff Sharkeyb2b9ab82015-04-05 21:10:42 -07001885 }
1886 }
1887
1888 @Override
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001889 public void registerMoveCallback(MoveCallback callback, Handler handler) {
1890 synchronized (mDelegates) {
1891 final MoveCallbackDelegate delegate = new MoveCallbackDelegate(callback,
1892 handler.getLooper());
1893 try {
1894 mPM.registerMoveCallback(delegate);
1895 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001896 throw e.rethrowFromSystemServer();
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001897 }
1898 mDelegates.add(delegate);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001899 }
1900 }
1901
1902 @Override
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001903 public void unregisterMoveCallback(MoveCallback callback) {
1904 synchronized (mDelegates) {
1905 for (Iterator<MoveCallbackDelegate> i = mDelegates.iterator(); i.hasNext();) {
1906 final MoveCallbackDelegate delegate = i.next();
1907 if (delegate.mCallback == callback) {
1908 try {
1909 mPM.unregisterMoveCallback(delegate);
1910 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001911 throw e.rethrowFromSystemServer();
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001912 }
1913 i.remove();
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001914 }
1915 }
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001916 }
1917 }
1918
1919 @Override
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001920 public int movePackage(String packageName, VolumeInfo vol) {
1921 try {
1922 final String volumeUuid;
1923 if (VolumeInfo.ID_PRIVATE_INTERNAL.equals(vol.id)) {
1924 volumeUuid = StorageManager.UUID_PRIVATE_INTERNAL;
1925 } else if (vol.isPrimaryPhysical()) {
1926 volumeUuid = StorageManager.UUID_PRIMARY_PHYSICAL;
1927 } else {
1928 volumeUuid = Preconditions.checkNotNull(vol.fsUuid);
1929 }
1930
1931 return mPM.movePackage(packageName, volumeUuid);
1932 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001933 throw e.rethrowFromSystemServer();
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001934 }
1935 }
1936
1937 @Override
1938 public @Nullable VolumeInfo getPackageCurrentVolume(ApplicationInfo app) {
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001939 final StorageManager storage = mContext.getSystemService(StorageManager.class);
Yao Chen022b8ea2016-12-16 11:03:28 -08001940 return getPackageCurrentVolume(app, storage);
1941 }
1942
1943 @VisibleForTesting
1944 protected @Nullable VolumeInfo getPackageCurrentVolume(ApplicationInfo app,
1945 StorageManager storage) {
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001946 if (app.isInternal()) {
1947 return storage.findVolumeById(VolumeInfo.ID_PRIVATE_INTERNAL);
1948 } else if (app.isExternalAsec()) {
1949 return storage.getPrimaryPhysicalVolume();
1950 } else {
1951 return storage.findVolumeByUuid(app.volumeUuid);
1952 }
1953 }
1954
1955 @Override
1956 public @NonNull List<VolumeInfo> getPackageCandidateVolumes(ApplicationInfo app) {
Yao Chen022b8ea2016-12-16 11:03:28 -08001957 final StorageManager storageManager = mContext.getSystemService(StorageManager.class);
1958 return getPackageCandidateVolumes(app, storageManager, mPM);
1959 }
1960
1961 @VisibleForTesting
1962 protected @NonNull List<VolumeInfo> getPackageCandidateVolumes(ApplicationInfo app,
1963 StorageManager storageManager, IPackageManager pm) {
1964 final VolumeInfo currentVol = getPackageCurrentVolume(app, storageManager);
1965 final List<VolumeInfo> vols = storageManager.getVolumes();
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001966 final List<VolumeInfo> candidates = new ArrayList<>();
1967 for (VolumeInfo vol : vols) {
Yao Chen022b8ea2016-12-16 11:03:28 -08001968 if (Objects.equals(vol, currentVol)
1969 || isPackageCandidateVolume(mContext, app, vol, pm)) {
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001970 candidates.add(vol);
1971 }
1972 }
1973 return candidates;
1974 }
1975
Yao Chen022b8ea2016-12-16 11:03:28 -08001976 @VisibleForTesting
1977 protected boolean isForceAllowOnExternal(Context context) {
1978 return Settings.Global.getInt(
Todd Kennedyf39ca8f2015-08-07 14:15:07 -07001979 context.getContentResolver(), Settings.Global.FORCE_ALLOW_ON_EXTERNAL, 0) != 0;
Yao Chen022b8ea2016-12-16 11:03:28 -08001980 }
1981
1982 @VisibleForTesting
1983 protected boolean isAllow3rdPartyOnInternal(Context context) {
1984 return context.getResources().getBoolean(
1985 com.android.internal.R.bool.config_allow3rdPartyAppOnInternal);
1986 }
1987
1988 private boolean isPackageCandidateVolume(
1989 ContextImpl context, ApplicationInfo app, VolumeInfo vol, IPackageManager pm) {
1990 final boolean forceAllowOnExternal = isForceAllowOnExternal(context);
1991
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001992 if (VolumeInfo.ID_PRIVATE_INTERNAL.equals(vol.getId())) {
Yao Chen022b8ea2016-12-16 11:03:28 -08001993 return app.isSystemApp() || isAllow3rdPartyOnInternal(context);
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001994 }
1995
1996 // System apps and apps demanding internal storage can't be moved
1997 // anywhere else
Todd Kennedyf39ca8f2015-08-07 14:15:07 -07001998 if (app.isSystemApp()) {
1999 return false;
2000 }
2001 if (!forceAllowOnExternal
Dianne Hackborn30a4e6d2015-10-12 17:14:56 -07002002 && (app.installLocation == PackageInfo.INSTALL_LOCATION_INTERNAL_ONLY
2003 || app.installLocation == PackageInfo.INSTALL_LOCATION_UNSPECIFIED)) {
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07002004 return false;
2005 }
2006
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002007 // Gotta be able to write there
2008 if (!vol.isMountedWritable()) {
2009 return false;
2010 }
2011
2012 // Moving into an ASEC on public primary is only option internal
2013 if (vol.isPrimaryPhysical()) {
2014 return app.isInternal();
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07002015 }
2016
Makoto Onukif34db0a2016-02-17 11:17:15 -08002017 // Some apps can't be moved. (e.g. device admins)
2018 try {
Yao Chen022b8ea2016-12-16 11:03:28 -08002019 if (pm.isPackageDeviceAdminOnAnyUser(app.packageName)) {
Makoto Onukif34db0a2016-02-17 11:17:15 -08002020 return false;
2021 }
2022 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002023 throw e.rethrowFromSystemServer();
Makoto Onukif34db0a2016-02-17 11:17:15 -08002024 }
2025
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07002026 // Otherwise we can move to any private volume
2027 return (vol.getType() == VolumeInfo.TYPE_PRIVATE);
2028 }
2029
2030 @Override
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002031 public int movePrimaryStorage(VolumeInfo vol) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002032 try {
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002033 final String volumeUuid;
2034 if (VolumeInfo.ID_PRIVATE_INTERNAL.equals(vol.id)) {
2035 volumeUuid = StorageManager.UUID_PRIVATE_INTERNAL;
2036 } else if (vol.isPrimaryPhysical()) {
2037 volumeUuid = StorageManager.UUID_PRIMARY_PHYSICAL;
2038 } else {
2039 volumeUuid = Preconditions.checkNotNull(vol.fsUuid);
2040 }
2041
2042 return mPM.movePrimaryStorage(volumeUuid);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002043 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002044 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002045 }
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002046 }
2047
Jeff Sharkey275e3e42015-04-24 16:10:32 -07002048 @Override
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002049 public @Nullable VolumeInfo getPrimaryStorageCurrentVolume() {
2050 final StorageManager storage = mContext.getSystemService(StorageManager.class);
2051 final String volumeUuid = storage.getPrimaryStorageUuid();
Jeff Sharkey50a05452015-04-29 11:24:52 -07002052 return storage.findVolumeByQualifiedUuid(volumeUuid);
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002053 }
2054
Jeff Sharkey275e3e42015-04-24 16:10:32 -07002055 @Override
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002056 public @NonNull List<VolumeInfo> getPrimaryStorageCandidateVolumes() {
2057 final StorageManager storage = mContext.getSystemService(StorageManager.class);
2058 final VolumeInfo currentVol = getPrimaryStorageCurrentVolume();
2059 final List<VolumeInfo> vols = storage.getVolumes();
2060 final List<VolumeInfo> candidates = new ArrayList<>();
Jeff Sharkeyfced5342015-05-10 14:53:34 -07002061 if (Objects.equals(StorageManager.UUID_PRIMARY_PHYSICAL,
2062 storage.getPrimaryStorageUuid()) && currentVol != null) {
2063 // TODO: support moving primary physical to emulated volume
2064 candidates.add(currentVol);
2065 } else {
2066 for (VolumeInfo vol : vols) {
2067 if (Objects.equals(vol, currentVol) || isPrimaryStorageCandidateVolume(vol)) {
2068 candidates.add(vol);
2069 }
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002070 }
2071 }
2072 return candidates;
2073 }
2074
2075 private static boolean isPrimaryStorageCandidateVolume(VolumeInfo vol) {
2076 // Private internal is always an option
2077 if (VolumeInfo.ID_PRIVATE_INTERNAL.equals(vol.getId())) {
2078 return true;
2079 }
2080
2081 // Gotta be able to write there
2082 if (!vol.isMountedWritable()) {
2083 return false;
2084 }
2085
Jeff Sharkeyfced5342015-05-10 14:53:34 -07002086 // We can move to any private volume
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002087 return (vol.getType() == VolumeInfo.TYPE_PRIVATE);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002088 }
2089
2090 @Override
2091 public void deletePackage(String packageName, IPackageDeleteObserver observer, int flags) {
Robin Lee0e27c872015-09-28 14:37:40 +01002092 deletePackageAsUser(packageName, observer, flags, mContext.getUserId());
Nicolas Prevot9a80e532015-09-23 15:49:28 +01002093 }
2094
2095 @Override
Svet Ganov67882122016-12-11 16:36:34 -08002096 public void deletePackageAsUser(String packageName, IPackageDeleteObserver observer,
2097 int flags, int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002098 try {
Svet Ganov67882122016-12-11 16:36:34 -08002099 mPM.deletePackageAsUser(packageName, PackageManager.VERSION_CODE_HIGHEST,
2100 observer, userId, flags);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002101 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002102 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002103 }
2104 }
Jeff Sharkeyfbd0e9f2014-08-06 16:34:34 -07002105
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002106 @Override
2107 public void clearApplicationUserData(String packageName,
2108 IPackageDataObserver observer) {
2109 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -07002110 mPM.clearApplicationUserData(packageName, observer, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002111 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002112 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002113 }
2114 }
2115 @Override
2116 public void deleteApplicationCacheFiles(String packageName,
2117 IPackageDataObserver observer) {
2118 try {
2119 mPM.deleteApplicationCacheFiles(packageName, observer);
2120 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002121 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002122 }
2123 }
Jeff Sharkey529f91f2015-04-18 20:23:13 -07002124
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002125 @Override
Suprabh Shukla78c9eb82016-04-12 15:51:35 -07002126 public void deleteApplicationCacheFilesAsUser(String packageName, int userId,
2127 IPackageDataObserver observer) {
2128 try {
2129 mPM.deleteApplicationCacheFilesAsUser(packageName, userId, observer);
2130 } catch (RemoteException e) {
2131 throw e.rethrowFromSystemServer();
2132 }
2133 }
2134
2135 @Override
Jeff Sharkey529f91f2015-04-18 20:23:13 -07002136 public void freeStorageAndNotify(String volumeUuid, long idealStorageSize,
2137 IPackageDataObserver observer) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002138 try {
Jeff Sharkeyddff8072017-05-26 13:10:46 -06002139 mPM.freeStorageAndNotify(volumeUuid, idealStorageSize, 0, observer);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002140 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002141 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002142 }
2143 }
2144
2145 @Override
Jeff Sharkey529f91f2015-04-18 20:23:13 -07002146 public void freeStorage(String volumeUuid, long freeStorageSize, IntentSender pi) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002147 try {
Jeff Sharkeyddff8072017-05-26 13:10:46 -06002148 mPM.freeStorage(volumeUuid, freeStorageSize, 0, pi);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002149 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002150 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002151 }
2152 }
2153
2154 @Override
Suprabh Shukla021b57a2018-03-08 18:21:50 -08002155 public String[] setPackagesSuspended(String[] packageNames, boolean suspended,
2156 PersistableBundle appExtras, PersistableBundle launcherExtras,
2157 String dialogMessage) {
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00002158 try {
Suprabh Shukla021b57a2018-03-08 18:21:50 -08002159 return mPM.setPackagesSuspendedAsUser(packageNames, suspended, appExtras,
Suprabh Shukla3c3af142018-03-30 00:28:37 -07002160 launcherExtras, dialogMessage, mContext.getOpPackageName(),
2161 mContext.getUserId());
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00002162 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002163 throw e.rethrowFromSystemServer();
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00002164 }
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00002165 }
2166
2167 @Override
Suprabh Shukla021b57a2018-03-08 18:21:50 -08002168 public PersistableBundle getSuspendedPackageAppExtras(String packageName) {
2169 try {
Suprabh Shukla2fd43ba2018-03-22 16:57:49 -07002170 return mPM.getSuspendedPackageAppExtras(packageName, mContext.getUserId());
Suprabh Shukla021b57a2018-03-08 18:21:50 -08002171 } catch (RemoteException e) {
2172 throw e.rethrowFromSystemServer();
2173 }
2174 }
2175
2176 @Override
Suprabh Shukla2fd43ba2018-03-22 16:57:49 -07002177 public Bundle getSuspendedPackageAppExtras() {
2178 final PersistableBundle extras = getSuspendedPackageAppExtras(mContext.getOpPackageName());
2179 return extras != null ? new Bundle(extras.deepCopy()) : null;
Suprabh Shukla021b57a2018-03-08 18:21:50 -08002180 }
2181
2182 @Override
2183 public void setSuspendedPackageAppExtras(String packageName, PersistableBundle appExtras) {
2184 try {
2185 mPM.setSuspendedPackageAppExtras(packageName, appExtras, mContext.getUserId());
2186 } catch (RemoteException e) {
2187 e.rethrowFromSystemServer();
2188 }
2189 }
2190
2191 @Override
Andrei Stingaceanu355b2322016-02-12 16:43:51 +00002192 public boolean isPackageSuspendedForUser(String packageName, int userId) {
2193 try {
2194 return mPM.isPackageSuspendedForUser(packageName, userId);
2195 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002196 throw e.rethrowFromSystemServer();
Andrei Stingaceanu355b2322016-02-12 16:43:51 +00002197 }
Andrei Stingaceanu355b2322016-02-12 16:43:51 +00002198 }
2199
Jeff Sharkey9bc89af2017-01-11 11:25:50 -07002200 /** @hide */
2201 @Override
Suprabh Shukla021b57a2018-03-08 18:21:50 -08002202 public boolean isPackageSuspended(String packageName) {
2203 return isPackageSuspendedForUser(packageName, mContext.getUserId());
2204 }
2205
2206 @Override
2207 public boolean isPackageSuspended() {
2208 return isPackageSuspendedForUser(mContext.getOpPackageName(), mContext.getUserId());
2209 }
2210
2211 /** @hide */
2212 @Override
Jeff Sharkey9bc89af2017-01-11 11:25:50 -07002213 public void setApplicationCategoryHint(String packageName, int categoryHint) {
2214 try {
2215 mPM.setApplicationCategoryHint(packageName, categoryHint,
2216 mContext.getOpPackageName());
2217 } catch (RemoteException e) {
2218 throw e.rethrowFromSystemServer();
2219 }
2220 }
2221
Andrei Stingaceanu355b2322016-02-12 16:43:51 +00002222 @Override
Jeff Sharkeye06b4d12016-01-06 14:51:50 -07002223 public void getPackageSizeInfoAsUser(String packageName, int userHandle,
Dianne Hackborn0c380492012-08-20 17:23:30 -07002224 IPackageStatsObserver observer) {
Jeff Sharkey6f4b2a32017-03-21 14:13:41 -06002225 final String msg = "Shame on you for calling the hidden API "
2226 + "getPackageSizeInfoAsUser(). Shame!";
Jeff Sharkeye6306c42017-03-07 21:03:18 -07002227 if (mContext.getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.O) {
Jeff Sharkey6f4b2a32017-03-21 14:13:41 -06002228 throw new UnsupportedOperationException(msg);
Jeff Sharkeye6306c42017-03-07 21:03:18 -07002229 } else if (observer != null) {
Jeff Sharkey6f4b2a32017-03-21 14:13:41 -06002230 Log.d(TAG, msg);
Jeff Sharkeye6306c42017-03-07 21:03:18 -07002231 try {
2232 observer.onGetStatsCompleted(null, false);
2233 } catch (RemoteException ignored) {
2234 }
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002235 }
2236 }
Jeff Sharkeyd5896632016-03-04 16:16:00 -07002237
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002238 @Override
2239 public void addPackageToPreferred(String packageName) {
Jeff Sharkeyd5896632016-03-04 16:16:00 -07002240 Log.w(TAG, "addPackageToPreferred() is a no-op");
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002241 }
2242
2243 @Override
2244 public void removePackageFromPreferred(String packageName) {
Jeff Sharkeyd5896632016-03-04 16:16:00 -07002245 Log.w(TAG, "removePackageFromPreferred() is a no-op");
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002246 }
2247
2248 @Override
2249 public List<PackageInfo> getPreferredPackages(int flags) {
Jeff Sharkeyd5896632016-03-04 16:16:00 -07002250 Log.w(TAG, "getPreferredPackages() is a no-op");
2251 return Collections.emptyList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002252 }
2253
2254 @Override
2255 public void addPreferredActivity(IntentFilter filter,
2256 int match, ComponentName[] set, ComponentName activity) {
2257 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -07002258 mPM.addPreferredActivity(filter, match, set, activity, mContext.getUserId());
Amith Yamasania3f133a2012-08-09 17:11:28 -07002259 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002260 throw e.rethrowFromSystemServer();
Amith Yamasania3f133a2012-08-09 17:11:28 -07002261 }
2262 }
2263
2264 @Override
Jeff Sharkeye06b4d12016-01-06 14:51:50 -07002265 public void addPreferredActivityAsUser(IntentFilter filter, int match,
Amith Yamasania3f133a2012-08-09 17:11:28 -07002266 ComponentName[] set, ComponentName activity, int userId) {
2267 try {
2268 mPM.addPreferredActivity(filter, match, set, activity, userId);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002269 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002270 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002271 }
2272 }
2273
2274 @Override
2275 public void replacePreferredActivity(IntentFilter filter,
2276 int match, ComponentName[] set, ComponentName activity) {
2277 try {
Robin Lee0e27c872015-09-28 14:37:40 +01002278 mPM.replacePreferredActivity(filter, match, set, activity, mContext.getUserId());
Amith Yamasani41c1ded2014-08-05 11:15:05 -07002279 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002280 throw e.rethrowFromSystemServer();
Amith Yamasani41c1ded2014-08-05 11:15:05 -07002281 }
2282 }
2283
2284 @Override
2285 public void replacePreferredActivityAsUser(IntentFilter filter,
2286 int match, ComponentName[] set, ComponentName activity,
2287 int userId) {
2288 try {
2289 mPM.replacePreferredActivity(filter, match, set, activity, userId);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002290 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002291 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002292 }
2293 }
2294
2295 @Override
2296 public void clearPackagePreferredActivities(String packageName) {
2297 try {
2298 mPM.clearPackagePreferredActivities(packageName);
2299 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002300 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002301 }
2302 }
2303
2304 @Override
2305 public int getPreferredActivities(List<IntentFilter> outFilters,
2306 List<ComponentName> outActivities, String packageName) {
2307 try {
2308 return mPM.getPreferredActivities(outFilters, outActivities, packageName);
2309 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002310 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002311 }
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002312 }
2313
2314 @Override
Christopher Tatea2a0850d2013-09-05 16:38:58 -07002315 public ComponentName getHomeActivities(List<ResolveInfo> outActivities) {
2316 try {
2317 return mPM.getHomeActivities(outActivities);
2318 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002319 throw e.rethrowFromSystemServer();
Christopher Tatea2a0850d2013-09-05 16:38:58 -07002320 }
Christopher Tatea2a0850d2013-09-05 16:38:58 -07002321 }
2322
2323 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002324 public void setComponentEnabledSetting(ComponentName componentName,
2325 int newState, int flags) {
2326 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -07002327 mPM.setComponentEnabledSetting(componentName, newState, flags, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002328 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002329 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002330 }
2331 }
2332
2333 @Override
2334 public int getComponentEnabledSetting(ComponentName componentName) {
2335 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -07002336 return mPM.getComponentEnabledSetting(componentName, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002337 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002338 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002339 }
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002340 }
2341
2342 @Override
2343 public void setApplicationEnabledSetting(String packageName,
2344 int newState, int flags) {
2345 try {
Dianne Hackborn3fa3c28a2013-03-26 16:15:41 -07002346 mPM.setApplicationEnabledSetting(packageName, newState, flags,
Dianne Hackborn95d78532013-09-11 09:51:14 -07002347 mContext.getUserId(), mContext.getOpPackageName());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002348 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002349 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002350 }
2351 }
2352
2353 @Override
2354 public int getApplicationEnabledSetting(String packageName) {
2355 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -07002356 return mPM.getApplicationEnabledSetting(packageName, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002357 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002358 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002359 }
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002360 }
2361
Amith Yamasani655d0e22013-06-12 14:19:10 -07002362 @Override
Sudheer Shankabbb3ff22015-07-09 15:39:23 +01002363 public void flushPackageRestrictionsAsUser(int userId) {
2364 try {
2365 mPM.flushPackageRestrictionsAsUser(userId);
2366 } catch (RemoteException e) {
2367 throw e.rethrowFromSystemServer();
2368 }
2369 }
2370
2371 @Override
Amith Yamasanie5bcff62014-07-19 15:44:09 -07002372 public boolean setApplicationHiddenSettingAsUser(String packageName, boolean hidden,
Amith Yamasani655d0e22013-06-12 14:19:10 -07002373 UserHandle user) {
2374 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07002375 return mPM.setApplicationHiddenSettingAsUser(packageName, hidden,
Amith Yamasani655d0e22013-06-12 14:19:10 -07002376 user.getIdentifier());
Jeff Sharkey27b2e692016-02-25 17:40:12 -07002377 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002378 throw e.rethrowFromSystemServer();
Amith Yamasani655d0e22013-06-12 14:19:10 -07002379 }
Amith Yamasani655d0e22013-06-12 14:19:10 -07002380 }
2381
2382 @Override
Amith Yamasanie5bcff62014-07-19 15:44:09 -07002383 public boolean getApplicationHiddenSettingAsUser(String packageName, UserHandle user) {
Amith Yamasani655d0e22013-06-12 14:19:10 -07002384 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07002385 return mPM.getApplicationHiddenSettingAsUser(packageName, user.getIdentifier());
Jeff Sharkey27b2e692016-02-25 17:40:12 -07002386 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002387 throw e.rethrowFromSystemServer();
Amith Yamasani655d0e22013-06-12 14:19:10 -07002388 }
Amith Yamasani655d0e22013-06-12 14:19:10 -07002389 }
2390
dcashmanc6f22492014-08-14 09:54:51 -07002391 /** @hide */
dcashman9d2f4412014-06-09 09:27:54 -07002392 @Override
2393 public KeySet getKeySetByAlias(String packageName, String alias) {
2394 Preconditions.checkNotNull(packageName);
2395 Preconditions.checkNotNull(alias);
dcashman9d2f4412014-06-09 09:27:54 -07002396 try {
Jeff Sharkey27b2e692016-02-25 17:40:12 -07002397 return mPM.getKeySetByAlias(packageName, alias);
dcashman9d2f4412014-06-09 09:27:54 -07002398 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002399 throw e.rethrowFromSystemServer();
dcashman9d2f4412014-06-09 09:27:54 -07002400 }
dcashman9d2f4412014-06-09 09:27:54 -07002401 }
2402
dcashmanc6f22492014-08-14 09:54:51 -07002403 /** @hide */
dcashman9d2f4412014-06-09 09:27:54 -07002404 @Override
2405 public KeySet getSigningKeySet(String packageName) {
2406 Preconditions.checkNotNull(packageName);
dcashman9d2f4412014-06-09 09:27:54 -07002407 try {
Jeff Sharkey27b2e692016-02-25 17:40:12 -07002408 return mPM.getSigningKeySet(packageName);
dcashman9d2f4412014-06-09 09:27:54 -07002409 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002410 throw e.rethrowFromSystemServer();
dcashman9d2f4412014-06-09 09:27:54 -07002411 }
dcashman9d2f4412014-06-09 09:27:54 -07002412 }
2413
dcashmanc6f22492014-08-14 09:54:51 -07002414 /** @hide */
dcashman9d2f4412014-06-09 09:27:54 -07002415 @Override
2416 public boolean isSignedBy(String packageName, KeySet ks) {
2417 Preconditions.checkNotNull(packageName);
2418 Preconditions.checkNotNull(ks);
dcashman9d2f4412014-06-09 09:27:54 -07002419 try {
dcashmanc6f22492014-08-14 09:54:51 -07002420 return mPM.isPackageSignedByKeySet(packageName, ks);
dcashman9d2f4412014-06-09 09:27:54 -07002421 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002422 throw e.rethrowFromSystemServer();
dcashman9d2f4412014-06-09 09:27:54 -07002423 }
2424 }
2425
dcashmanc6f22492014-08-14 09:54:51 -07002426 /** @hide */
dcashman9d2f4412014-06-09 09:27:54 -07002427 @Override
2428 public boolean isSignedByExactly(String packageName, KeySet ks) {
2429 Preconditions.checkNotNull(packageName);
2430 Preconditions.checkNotNull(ks);
dcashman9d2f4412014-06-09 09:27:54 -07002431 try {
dcashmanc6f22492014-08-14 09:54:51 -07002432 return mPM.isPackageSignedByKeySetExactly(packageName, ks);
dcashman9d2f4412014-06-09 09:27:54 -07002433 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002434 throw e.rethrowFromSystemServer();
dcashman9d2f4412014-06-09 09:27:54 -07002435 }
2436 }
2437
Kenny Root0aaa0d92011-09-12 16:42:55 -07002438 /**
2439 * @hide
2440 */
2441 @Override
2442 public VerifierDeviceIdentity getVerifierDeviceIdentity() {
2443 try {
2444 return mPM.getVerifierDeviceIdentity();
2445 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002446 throw e.rethrowFromSystemServer();
Kenny Root0aaa0d92011-09-12 16:42:55 -07002447 }
Kenny Root0aaa0d92011-09-12 16:42:55 -07002448 }
2449
Jeff Hao9f60c082014-10-28 18:51:07 -07002450 /**
2451 * @hide
2452 */
2453 @Override
2454 public boolean isUpgrade() {
2455 try {
2456 return mPM.isUpgrade();
2457 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002458 throw e.rethrowFromSystemServer();
Jeff Hao9f60c082014-10-28 18:51:07 -07002459 }
2460 }
2461
Jeff Sharkey3a44f3f2014-04-28 17:36:31 -07002462 @Override
Jeff Sharkey16c8e3f2014-07-24 17:08:17 -07002463 public PackageInstaller getPackageInstaller() {
2464 synchronized (mLock) {
2465 if (mInstaller == null) {
2466 try {
Svet Ganov67882122016-12-11 16:36:34 -08002467 mInstaller = new PackageInstaller(mPM.getPackageInstaller(),
Jeff Sharkey16c8e3f2014-07-24 17:08:17 -07002468 mContext.getPackageName(), mContext.getUserId());
2469 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002470 throw e.rethrowFromSystemServer();
Jeff Sharkey16c8e3f2014-07-24 17:08:17 -07002471 }
2472 }
2473 return mInstaller;
Jeff Sharkey3a44f3f2014-04-28 17:36:31 -07002474 }
2475 }
2476
Jeff Sharkey6c833e02014-07-14 22:44:30 -07002477 @Override
2478 public boolean isPackageAvailable(String packageName) {
2479 try {
2480 return mPM.isPackageAvailable(packageName, mContext.getUserId());
2481 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002482 throw e.rethrowFromSystemServer();
Jeff Sharkey6c833e02014-07-14 22:44:30 -07002483 }
2484 }
2485
Nicolas Prevotc79586e2014-05-06 12:47:57 +01002486 /**
2487 * @hide
2488 */
2489 @Override
Nicolas Prevot63798c52014-05-27 13:22:38 +01002490 public void addCrossProfileIntentFilter(IntentFilter filter, int sourceUserId, int targetUserId,
2491 int flags) {
Nicolas Prevotc79586e2014-05-06 12:47:57 +01002492 try {
Nicolas Prevot3f7777f2014-07-24 15:58:39 +01002493 mPM.addCrossProfileIntentFilter(filter, mContext.getOpPackageName(),
Nicolas Prevot4b8d5822015-03-05 15:20:49 +00002494 sourceUserId, targetUserId, flags);
Nicolas Prevotc79586e2014-05-06 12:47:57 +01002495 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002496 throw e.rethrowFromSystemServer();
Nicolas Prevotc79586e2014-05-06 12:47:57 +01002497 }
2498 }
2499
2500 /**
2501 * @hide
2502 */
2503 @Override
Nicolas Prevot81948992014-05-16 18:25:26 +01002504 public void clearCrossProfileIntentFilters(int sourceUserId) {
Nicolas Prevotc79586e2014-05-06 12:47:57 +01002505 try {
Nicolas Prevot4b8d5822015-03-05 15:20:49 +00002506 mPM.clearCrossProfileIntentFilters(sourceUserId, mContext.getOpPackageName());
Nicolas Prevotc79586e2014-05-06 12:47:57 +01002507 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002508 throw e.rethrowFromSystemServer();
Nicolas Prevotc79586e2014-05-06 12:47:57 +01002509 }
2510 }
2511
Nicolas Prevot88cc3462014-05-14 14:51:48 +01002512 /**
2513 * @hide
2514 */
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +01002515 public Drawable loadItemIcon(PackageItemInfo itemInfo, ApplicationInfo appInfo) {
Benjamin Franzec2d48b2014-10-01 15:38:43 +01002516 Drawable dr = loadUnbadgedItemIcon(itemInfo, appInfo);
2517 if (itemInfo.showUserIcon != UserHandle.USER_NULL) {
2518 return dr;
2519 }
2520 return getUserBadgedIcon(dr, new UserHandle(mContext.getUserId()));
2521 }
2522
2523 /**
2524 * @hide
2525 */
2526 public Drawable loadUnbadgedItemIcon(PackageItemInfo itemInfo, ApplicationInfo appInfo) {
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +01002527 if (itemInfo.showUserIcon != UserHandle.USER_NULL) {
Alexandra Gherghina64d4dca2014-08-28 18:26:56 +01002528 Bitmap bitmap = getUserManager().getUserIcon(itemInfo.showUserIcon);
2529 if (bitmap == null) {
Tony Mak213955e2017-11-23 16:57:08 +08002530 return UserIcons.getDefaultUserIcon(
2531 mContext.getResources(), itemInfo.showUserIcon, /* light= */ false);
Alexandra Gherghina64d4dca2014-08-28 18:26:56 +01002532 }
2533 return new BitmapDrawable(bitmap);
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +01002534 }
Alexandra Gherghinadb811db2014-08-29 13:43:59 +01002535 Drawable dr = null;
2536 if (itemInfo.packageName != null) {
2537 dr = getDrawable(itemInfo.packageName, itemInfo.icon, appInfo);
2538 }
Alexandra Gherghinaa71e3902014-07-25 20:03:47 +01002539 if (dr == null) {
Alexandra Gherghinaa7093142014-07-30 13:43:39 +01002540 dr = itemInfo.loadDefaultIcon(this);
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +01002541 }
Benjamin Franzec2d48b2014-10-01 15:38:43 +01002542 return dr;
Svetoslavc7d62f02014-09-04 15:39:54 -07002543 }
2544
2545 private Drawable getBadgedDrawable(Drawable drawable, Drawable badgeDrawable,
2546 Rect badgeLocation, boolean tryBadgeInPlace) {
2547 final int badgedWidth = drawable.getIntrinsicWidth();
2548 final int badgedHeight = drawable.getIntrinsicHeight();
2549 final boolean canBadgeInPlace = tryBadgeInPlace
2550 && (drawable instanceof BitmapDrawable)
2551 && ((BitmapDrawable) drawable).getBitmap().isMutable();
2552
2553 final Bitmap bitmap;
2554 if (canBadgeInPlace) {
2555 bitmap = ((BitmapDrawable) drawable).getBitmap();
2556 } else {
2557 bitmap = Bitmap.createBitmap(badgedWidth, badgedHeight, Bitmap.Config.ARGB_8888);
2558 }
2559 Canvas canvas = new Canvas(bitmap);
2560
2561 if (!canBadgeInPlace) {
2562 drawable.setBounds(0, 0, badgedWidth, badgedHeight);
2563 drawable.draw(canvas);
2564 }
2565
2566 if (badgeLocation != null) {
2567 if (badgeLocation.left < 0 || badgeLocation.top < 0
2568 || badgeLocation.width() > badgedWidth || badgeLocation.height() > badgedHeight) {
2569 throw new IllegalArgumentException("Badge location " + badgeLocation
2570 + " not in badged drawable bounds "
2571 + new Rect(0, 0, badgedWidth, badgedHeight));
2572 }
2573 badgeDrawable.setBounds(0, 0, badgeLocation.width(), badgeLocation.height());
2574
2575 canvas.save();
2576 canvas.translate(badgeLocation.left, badgeLocation.top);
2577 badgeDrawable.draw(canvas);
2578 canvas.restore();
2579 } else {
2580 badgeDrawable.setBounds(0, 0, badgedWidth, badgedHeight);
2581 badgeDrawable.draw(canvas);
2582 }
2583
2584 if (!canBadgeInPlace) {
2585 BitmapDrawable mergedDrawable = new BitmapDrawable(mContext.getResources(), bitmap);
2586
2587 if (drawable instanceof BitmapDrawable) {
2588 BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
2589 mergedDrawable.setTargetDensity(bitmapDrawable.getBitmap().getDensity());
2590 }
2591
2592 return mergedDrawable;
2593 }
2594
2595 return drawable;
2596 }
2597
Tony Mak8673b282016-03-21 21:10:59 +00002598 private boolean isManagedProfile(int userId) {
2599 return getUserManager().isManagedProfile(userId);
Nicolas Prevot88cc3462014-05-14 14:51:48 +01002600 }
2601
Bartosz Fabianowskia34f53f2017-01-11 18:08:47 +01002602 /**
2603 * @hide
2604 */
2605 @Override
2606 public int getInstallReason(String packageName, UserHandle user) {
2607 try {
2608 return mPM.getInstallReason(packageName, user.getIdentifier());
2609 } catch (RemoteException e) {
2610 throw e.rethrowFromSystemServer();
2611 }
2612 }
2613
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002614 /** {@hide} */
2615 private static class MoveCallbackDelegate extends IPackageMoveObserver.Stub implements
2616 Handler.Callback {
Jeff Sharkey50a05452015-04-29 11:24:52 -07002617 private static final int MSG_CREATED = 1;
2618 private static final int MSG_STATUS_CHANGED = 2;
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002619
2620 final MoveCallback mCallback;
2621 final Handler mHandler;
2622
2623 public MoveCallbackDelegate(MoveCallback callback, Looper looper) {
2624 mCallback = callback;
2625 mHandler = new Handler(looper, this);
2626 }
2627
2628 @Override
2629 public boolean handleMessage(Message msg) {
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002630 switch (msg.what) {
Jeff Sharkey50a05452015-04-29 11:24:52 -07002631 case MSG_CREATED: {
Jeff Sharkeyb36586a2015-04-27 08:42:28 -07002632 final SomeArgs args = (SomeArgs) msg.obj;
Jeff Sharkey50a05452015-04-29 11:24:52 -07002633 mCallback.onCreated(args.argi1, (Bundle) args.arg2);
Jeff Sharkeyb36586a2015-04-27 08:42:28 -07002634 args.recycle();
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002635 return true;
Jeff Sharkey50a05452015-04-29 11:24:52 -07002636 }
2637 case MSG_STATUS_CHANGED: {
2638 final SomeArgs args = (SomeArgs) msg.obj;
2639 mCallback.onStatusChanged(args.argi1, args.argi2, (long) args.arg3);
2640 args.recycle();
2641 return true;
2642 }
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002643 }
2644 return false;
2645 }
2646
2647 @Override
Jeff Sharkey50a05452015-04-29 11:24:52 -07002648 public void onCreated(int moveId, Bundle extras) {
Jeff Sharkeyb36586a2015-04-27 08:42:28 -07002649 final SomeArgs args = SomeArgs.obtain();
2650 args.argi1 = moveId;
Jeff Sharkey50a05452015-04-29 11:24:52 -07002651 args.arg2 = extras;
2652 mHandler.obtainMessage(MSG_CREATED, args).sendToTarget();
2653 }
2654
2655 @Override
2656 public void onStatusChanged(int moveId, int status, long estMillis) {
2657 final SomeArgs args = SomeArgs.obtain();
2658 args.argi1 = moveId;
2659 args.argi2 = status;
2660 args.arg3 = estMillis;
Jeff Sharkeyb36586a2015-04-27 08:42:28 -07002661 mHandler.obtainMessage(MSG_STATUS_CHANGED, args).sendToTarget();
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002662 }
2663 }
2664
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002665 private final ContextImpl mContext;
2666 private final IPackageManager mPM;
2667
2668 private static final Object sSync = new Object();
Dianne Hackbornadd005c2013-07-17 18:43:12 -07002669 private static ArrayMap<ResourceName, WeakReference<Drawable.ConstantState>> sIconCache
2670 = new ArrayMap<ResourceName, WeakReference<Drawable.ConstantState>>();
2671 private static ArrayMap<ResourceName, WeakReference<CharSequence>> sStringCache
2672 = new ArrayMap<ResourceName, WeakReference<CharSequence>>();
Svetoslavf7c06eb2015-06-10 18:43:22 -07002673
2674 private final Map<OnPermissionsChangedListener, IOnPermissionsChangeListener>
2675 mPermissionListeners = new ArrayMap<>();
2676
2677 public class OnPermissionsChangeListenerDelegate extends IOnPermissionsChangeListener.Stub
2678 implements Handler.Callback{
2679 private static final int MSG_PERMISSIONS_CHANGED = 1;
2680
2681 private final OnPermissionsChangedListener mListener;
2682 private final Handler mHandler;
2683
2684
2685 public OnPermissionsChangeListenerDelegate(OnPermissionsChangedListener listener,
2686 Looper looper) {
2687 mListener = listener;
2688 mHandler = new Handler(looper, this);
2689 }
2690
2691 @Override
2692 public void onPermissionsChanged(int uid) {
2693 mHandler.obtainMessage(MSG_PERMISSIONS_CHANGED, uid, 0).sendToTarget();
2694 }
2695
2696 @Override
2697 public boolean handleMessage(Message msg) {
2698 switch (msg.what) {
2699 case MSG_PERMISSIONS_CHANGED: {
2700 final int uid = msg.arg1;
2701 mListener.onPermissionsChanged(uid);
2702 return true;
2703 }
2704 }
2705 return false;
2706 }
2707 }
Suprabh Shuklaaef25132017-01-23 18:09:03 -08002708
2709 @Override
2710 public boolean canRequestPackageInstalls() {
2711 try {
2712 return mPM.canRequestPackageInstalls(mContext.getPackageName(), mContext.getUserId());
2713 } catch (RemoteException e) {
2714 throw e.rethrowAsRuntimeException();
2715 }
2716 }
Chad Brubaker336ae5b2017-03-24 15:53:09 -07002717
2718 @Override
2719 public ComponentName getInstantAppResolverSettingsComponent() {
2720 try {
2721 return mPM.getInstantAppResolverSettingsComponent();
2722 } catch (RemoteException e) {
2723 throw e.rethrowAsRuntimeException();
2724 }
2725 }
Todd Kennedy801e6592017-04-12 14:10:12 -07002726
2727 @Override
2728 public ComponentName getInstantAppInstallerComponent() {
2729 try {
2730 return mPM.getInstantAppInstallerComponent();
2731 } catch (RemoteException e) {
2732 throw e.rethrowAsRuntimeException();
2733 }
2734 }
Chad Brubaker0d277a72017-04-12 16:56:53 -07002735
2736 @Override
2737 public String getInstantAppAndroidId(String packageName, UserHandle user) {
2738 try {
2739 return mPM.getInstantAppAndroidId(packageName, user.getIdentifier());
2740 } catch (RemoteException e) {
2741 throw e.rethrowAsRuntimeException();
2742 }
2743 }
Calin Juravle3d2af7f2017-04-19 19:56:21 -07002744
2745 private static class DexModuleRegisterResult {
2746 final String dexModulePath;
2747 final boolean success;
2748 final String message;
2749
2750 private DexModuleRegisterResult(String dexModulePath, boolean success, String message) {
2751 this.dexModulePath = dexModulePath;
2752 this.success = success;
2753 this.message = message;
2754 }
2755 }
2756
2757 private static class DexModuleRegisterCallbackDelegate
2758 extends android.content.pm.IDexModuleRegisterCallback.Stub
2759 implements Handler.Callback {
2760 private static final int MSG_DEX_MODULE_REGISTERED = 1;
2761 private final DexModuleRegisterCallback callback;
2762 private final Handler mHandler;
2763
2764 DexModuleRegisterCallbackDelegate(@NonNull DexModuleRegisterCallback callback) {
2765 this.callback = callback;
2766 mHandler = new Handler(Looper.getMainLooper(), this);
2767 }
2768
2769 @Override
2770 public void onDexModuleRegistered(@NonNull String dexModulePath, boolean success,
2771 @Nullable String message)throws RemoteException {
2772 mHandler.obtainMessage(MSG_DEX_MODULE_REGISTERED,
2773 new DexModuleRegisterResult(dexModulePath, success, message)).sendToTarget();
2774 }
2775
2776 @Override
2777 public boolean handleMessage(Message msg) {
2778 if (msg.what != MSG_DEX_MODULE_REGISTERED) {
2779 return false;
2780 }
2781 DexModuleRegisterResult result = (DexModuleRegisterResult)msg.obj;
2782 callback.onDexModuleRegistered(result.dexModulePath, result.success, result.message);
2783 return true;
2784 }
2785 }
2786
2787 @Override
2788 public void registerDexModule(@NonNull String dexModule,
2789 @Nullable DexModuleRegisterCallback callback) {
2790 // Check if this is a shared module by looking if the others can read it.
2791 boolean isSharedModule = false;
2792 try {
2793 StructStat stat = Os.stat(dexModule);
2794 if ((OsConstants.S_IROTH & stat.st_mode) != 0) {
2795 isSharedModule = true;
2796 }
2797 } catch (ErrnoException e) {
2798 callback.onDexModuleRegistered(dexModule, false,
2799 "Could not get stat the module file: " + e.getMessage());
2800 return;
2801 }
2802
2803 // Module path is ok.
2804 // Create the callback delegate to be passed to package manager service.
2805 DexModuleRegisterCallbackDelegate callbackDelegate = null;
2806 if (callback != null) {
2807 callbackDelegate = new DexModuleRegisterCallbackDelegate(callback);
2808 }
2809
2810 // Invoke the package manager service.
2811 try {
2812 mPM.registerDexModule(mContext.getPackageName(), dexModule,
2813 isSharedModule, callbackDelegate);
2814 } catch (RemoteException e) {
2815 throw e.rethrowAsRuntimeException();
2816 }
2817 }
Calin Juravle45f8b292017-11-07 18:49:43 -08002818
2819 @Override
Ben Gruver1ab3d6e2017-12-07 13:45:08 -08002820 public CharSequence getHarmfulAppWarning(String packageName) {
2821 try {
2822 return mPM.getHarmfulAppWarning(packageName, mContext.getUserId());
2823 } catch (RemoteException e) {
2824 throw e.rethrowAsRuntimeException();
2825 }
2826 }
2827
2828 @Override
2829 public void setHarmfulAppWarning(String packageName, CharSequence warning) {
2830 try {
2831 mPM.setHarmfulAppWarning(packageName, warning, mContext.getUserId());
2832 } catch (RemoteException e) {
2833 throw e.rethrowAsRuntimeException();
2834 }
2835 }
2836
2837 @Override
Calin Juravle45f8b292017-11-07 18:49:43 -08002838 public ArtManager getArtManager() {
2839 synchronized (mLock) {
2840 if (mArtManager == null) {
2841 try {
2842 mArtManager = new ArtManager(mPM.getArtManager());
2843 } catch (RemoteException e) {
2844 throw e.rethrowFromSystemServer();
2845 }
2846 }
2847 return mArtManager;
2848 }
2849 }
Makoto Onuki700feef2018-02-15 10:59:41 -08002850
2851 @Override
2852 public String getSystemTextClassifierPackageName() {
2853 try {
2854 return mPM.getSystemTextClassifierPackageName();
2855 } catch (RemoteException e) {
2856 throw e.rethrowAsRuntimeException();
2857 }
2858 }
Benjamin Franz7cc9a812018-03-22 10:11:29 +00002859
2860 @Override
2861 public boolean isPackageStateProtected(String packageName, int userId) {
2862 try {
2863 return mPM.isPackageStateProtected(packageName, userId);
2864 } catch (RemoteException e) {
2865 throw e.rethrowAsRuntimeException();
2866 }
2867 }
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002868}