blob: 12fab2ade0c6da06143117ceef3199ed82621685 [file] [log] [blame]
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001/*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.app;
18
Tor Norbye7b9c9122013-05-30 16:48:33 -070019import android.annotation.DrawableRes;
Alan Viveretteecd585a2015-04-13 10:32:51 -070020import android.annotation.NonNull;
21import android.annotation.Nullable;
Tor Norbye7b9c9122013-05-30 16:48:33 -070022import android.annotation.StringRes;
23import android.annotation.XmlRes;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080024import android.content.ComponentName;
25import android.content.ContentResolver;
Yao Chen022b8ea2016-12-16 11:03:28 -080026import android.content.Context;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080027import android.content.Intent;
28import android.content.IntentFilter;
29import android.content.IntentSender;
30import android.content.pm.ActivityInfo;
31import android.content.pm.ApplicationInfo;
Todd Kennedy9106c642017-02-08 14:16:53 -080032import android.content.pm.ChangedPackages;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080033import android.content.pm.ComponentInfo;
34import android.content.pm.FeatureInfo;
Svetoslavf7c06eb2015-06-10 18:43:22 -070035import android.content.pm.IOnPermissionsChangeListener;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080036import android.content.pm.IPackageDataObserver;
37import android.content.pm.IPackageDeleteObserver;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080038import android.content.pm.IPackageManager;
39import android.content.pm.IPackageMoveObserver;
40import android.content.pm.IPackageStatsObserver;
Todd Kennedy9da8b8a72017-07-25 15:38:39 -070041import android.content.pm.InstantAppInfo;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080042import android.content.pm.InstrumentationInfo;
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -080043import android.content.pm.IntentFilterVerificationInfo;
dcashman9d2f4412014-06-09 09:27:54 -070044import android.content.pm.KeySet;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080045import android.content.pm.PackageInfo;
Jeff Sharkey3a44f3f2014-04-28 17:36:31 -070046import android.content.pm.PackageInstaller;
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +010047import android.content.pm.PackageItemInfo;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080048import android.content.pm.PackageManager;
Kenny Roote6cd0c72011-05-19 12:48:14 -070049import android.content.pm.ParceledListSlice;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080050import android.content.pm.PermissionGroupInfo;
51import android.content.pm.PermissionInfo;
52import android.content.pm.ProviderInfo;
53import android.content.pm.ResolveInfo;
54import android.content.pm.ServiceInfo;
Svet Ganov67882122016-12-11 16:36:34 -080055import android.content.pm.SharedLibraryInfo;
Kenny Root0aaa0d92011-09-12 16:42:55 -070056import android.content.pm.VerifierDeviceIdentity;
Svet Ganov67882122016-12-11 16:36:34 -080057import android.content.pm.VersionedPackage;
Calin Juravle45f8b292017-11-07 18:49:43 -080058import android.content.pm.dex.ArtManager;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080059import android.content.res.Resources;
60import android.content.res.XmlResourceParser;
Svetoslavc7d62f02014-09-04 15:39:54 -070061import android.graphics.Bitmap;
62import android.graphics.Canvas;
63import android.graphics.Rect;
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +010064import android.graphics.drawable.BitmapDrawable;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080065import android.graphics.drawable.Drawable;
Kenny Guy02c89902016-11-15 19:36:38 +000066import android.graphics.drawable.LayerDrawable;
Jeff Sharkeye6306c42017-03-07 21:03:18 -070067import android.os.Build;
Jeff Sharkey50a05452015-04-29 11:24:52 -070068import android.os.Bundle;
Jeff Sharkey620b32b2015-04-23 19:36:02 -070069import android.os.Handler;
70import android.os.Looper;
71import android.os.Message;
Suprabh Shukla021b57a2018-03-08 18:21:50 -080072import android.os.PersistableBundle;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080073import android.os.Process;
74import android.os.RemoteException;
Jeff Sharkeyb2b9ab82015-04-05 21:10:42 -070075import android.os.SystemProperties;
Amith Yamasani67df64b2012-12-14 12:09:36 -080076import android.os.UserHandle;
Nicolas Prevot88cc3462014-05-14 14:51:48 +010077import android.os.UserManager;
Jeff Sharkeye2d45be2015-04-15 17:14:12 -070078import android.os.storage.StorageManager;
79import android.os.storage.VolumeInfo;
Todd Kennedyf39ca8f2015-08-07 14:15:07 -070080import android.provider.Settings;
Calin Juravle3d2af7f2017-04-19 19:56:21 -070081import android.system.ErrnoException;
82import android.system.Os;
83import android.system.OsConstants;
84import android.system.StructStat;
Dianne Hackbornadd005c2013-07-17 18:43:12 -070085import android.util.ArrayMap;
Sunny Goyalbab30752017-04-12 15:36:42 -070086import android.util.IconDrawableFactory;
87import android.util.LauncherIcons;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080088import android.util.Log;
Jeff Browna492c3a2012-08-23 19:48:44 -070089import android.view.Display;
Jeff Sharkeyb2b9ab82015-04-05 21:10:42 -070090
Jeff Sharkey16c8e3f2014-07-24 17:08:17 -070091import com.android.internal.annotations.GuardedBy;
Kenny Guy02c89902016-11-15 19:36:38 +000092import com.android.internal.annotations.VisibleForTesting;
Jeff Sharkeyb36586a2015-04-27 08:42:28 -070093import com.android.internal.os.SomeArgs;
dcashman9d2f4412014-06-09 09:27:54 -070094import com.android.internal.util.Preconditions;
Alexandra Gherghina64d4dca2014-08-28 18:26:56 +010095import com.android.internal.util.UserIcons;
Todd Kennedy9da8b8a72017-07-25 15:38:39 -070096
97import dalvik.system.VMRuntime;
98
Svet Ganov2acf0632015-11-24 19:10:59 -080099import libcore.util.EmptyArray;
Jeff Sharkey16c8e3f2014-07-24 17:08:17 -0700100
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800101import java.lang.ref.WeakReference;
102import java.util.ArrayList;
Svet Ganov2acf0632015-11-24 19:10:59 -0800103import java.util.Collections;
Jeff Sharkey620b32b2015-04-23 19:36:02 -0700104import java.util.Iterator;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800105import java.util.List;
Svetoslavf7c06eb2015-06-10 18:43:22 -0700106import java.util.Map;
Jeff Sharkey620b32b2015-04-23 19:36:02 -0700107import java.util.Objects;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800108
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700109/** @hide */
110public class ApplicationPackageManager extends PackageManager {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800111 private static final String TAG = "ApplicationPackageManager";
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800112 private final static boolean DEBUG_ICONS = false;
113
Svet Ganov2acf0632015-11-24 19:10:59 -0800114 private static final int DEFAULT_EPHEMERAL_COOKIE_MAX_SIZE_BYTES = 16384; // 16KB
115
Adam Lesinskid00bb5e2014-10-07 12:14:45 -0700116 // Default flags to use with PackageManager when no flags are given.
117 private final static int sDefaultFlags = PackageManager.GET_SHARED_LIBRARY_FILES;
118
Jeff Sharkey16c8e3f2014-07-24 17:08:17 -0700119 private final Object mLock = new Object();
120
121 @GuardedBy("mLock")
122 private UserManager mUserManager;
123 @GuardedBy("mLock")
124 private PackageInstaller mInstaller;
Calin Juravle45f8b292017-11-07 18:49:43 -0800125 @GuardedBy("mLock")
126 private ArtManager mArtManager;
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +0100127
Jeff Sharkey620b32b2015-04-23 19:36:02 -0700128 @GuardedBy("mDelegates")
129 private final ArrayList<MoveCallbackDelegate> mDelegates = new ArrayList<>();
130
Svet Ganovf1b7f202015-07-29 08:33:42 -0700131 @GuardedBy("mLock")
132 private String mPermissionsControllerPackageName;
133
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +0100134 UserManager getUserManager() {
Jeff Sharkey16c8e3f2014-07-24 17:08:17 -0700135 synchronized (mLock) {
136 if (mUserManager == null) {
137 mUserManager = UserManager.get(mContext);
138 }
139 return mUserManager;
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +0100140 }
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +0100141 }
142
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800143 @Override
Jeff Sharkeyad357d12018-02-02 13:25:31 -0700144 public int getUserId() {
145 return mContext.getUserId();
146 }
147
148 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800149 public PackageInfo getPackageInfo(String packageName, int flags)
150 throws NameNotFoundException {
Nicolas Prevot9a80e532015-09-23 15:49:28 +0100151 return getPackageInfoAsUser(packageName, flags, mContext.getUserId());
152 }
153
154 @Override
Svet Ganov67882122016-12-11 16:36:34 -0800155 public PackageInfo getPackageInfo(VersionedPackage versionedPackage, int flags)
156 throws NameNotFoundException {
157 try {
158 PackageInfo pi = mPM.getPackageInfoVersioned(versionedPackage, flags,
159 mContext.getUserId());
160 if (pi != null) {
161 return pi;
162 }
163 } catch (RemoteException e) {
164 throw e.rethrowFromSystemServer();
165 }
166 throw new NameNotFoundException(versionedPackage.toString());
167 }
168
169 @Override
Nicolas Prevot9a80e532015-09-23 15:49:28 +0100170 public PackageInfo getPackageInfoAsUser(String packageName, int flags, int userId)
171 throws NameNotFoundException {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800172 try {
Nicolas Prevot9a80e532015-09-23 15:49:28 +0100173 PackageInfo pi = mPM.getPackageInfo(packageName, flags, userId);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800174 if (pi != null) {
175 return pi;
176 }
177 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700178 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800179 }
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800180 throw new NameNotFoundException(packageName);
181 }
182
183 @Override
184 public String[] currentToCanonicalPackageNames(String[] names) {
185 try {
186 return mPM.currentToCanonicalPackageNames(names);
187 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700188 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800189 }
190 }
191
192 @Override
193 public String[] canonicalToCurrentPackageNames(String[] names) {
194 try {
195 return mPM.canonicalToCurrentPackageNames(names);
196 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700197 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800198 }
199 }
200
201 @Override
202 public Intent getLaunchIntentForPackage(String packageName) {
203 // First see if the package has an INFO activity; the existence of
204 // such an activity is implied to be the desired front-door for the
205 // overall package (such as if it has multiple launcher entries).
206 Intent intentToResolve = new Intent(Intent.ACTION_MAIN);
207 intentToResolve.addCategory(Intent.CATEGORY_INFO);
208 intentToResolve.setPackage(packageName);
Dianne Hackborn19415762010-12-15 00:20:27 -0800209 List<ResolveInfo> ris = queryIntentActivities(intentToResolve, 0);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800210
211 // Otherwise, try to find a main launcher activity.
Dianne Hackborn19415762010-12-15 00:20:27 -0800212 if (ris == null || ris.size() <= 0) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800213 // reuse the intent instance
214 intentToResolve.removeCategory(Intent.CATEGORY_INFO);
215 intentToResolve.addCategory(Intent.CATEGORY_LAUNCHER);
216 intentToResolve.setPackage(packageName);
Dianne Hackborn19415762010-12-15 00:20:27 -0800217 ris = queryIntentActivities(intentToResolve, 0);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800218 }
Dianne Hackborn19415762010-12-15 00:20:27 -0800219 if (ris == null || ris.size() <= 0) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800220 return null;
221 }
222 Intent intent = new Intent(intentToResolve);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800223 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Dianne Hackborn19415762010-12-15 00:20:27 -0800224 intent.setClassName(ris.get(0).activityInfo.packageName,
225 ris.get(0).activityInfo.name);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800226 return intent;
227 }
228
229 @Override
Jose Lima970417c2014-04-10 10:42:19 -0700230 public Intent getLeanbackLaunchIntentForPackage(String packageName) {
Roberto Perez7ee1a7a2017-12-04 17:14:33 -0800231 return getLaunchIntentForPackageAndCategory(packageName, Intent.CATEGORY_LEANBACK_LAUNCHER);
232 }
233
234 @Override
235 public Intent getCarLaunchIntentForPackage(String packageName) {
236 return getLaunchIntentForPackageAndCategory(packageName, Intent.CATEGORY_CAR_LAUNCHER);
237 }
238
239 private Intent getLaunchIntentForPackageAndCategory(String packageName, String category) {
240 // Try to find a main launcher activity for the given categories.
Jose Lima970417c2014-04-10 10:42:19 -0700241 Intent intentToResolve = new Intent(Intent.ACTION_MAIN);
Roberto Perez7ee1a7a2017-12-04 17:14:33 -0800242 intentToResolve.addCategory(category);
Jose Lima970417c2014-04-10 10:42:19 -0700243 intentToResolve.setPackage(packageName);
244 List<ResolveInfo> ris = queryIntentActivities(intentToResolve, 0);
245
246 if (ris == null || ris.size() <= 0) {
247 return null;
248 }
249 Intent intent = new Intent(intentToResolve);
250 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
251 intent.setClassName(ris.get(0).activityInfo.packageName,
252 ris.get(0).activityInfo.name);
253 return intent;
254 }
255
256 @Override
Jeff Sharkey8588bc12016-01-06 16:47:42 -0700257 public int[] getPackageGids(String packageName) throws NameNotFoundException {
258 return getPackageGids(packageName, 0);
259 }
260
261 @Override
262 public int[] getPackageGids(String packageName, int flags)
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800263 throws NameNotFoundException {
264 try {
Jeff Sharkeycd654482016-01-08 17:42:11 -0700265 int[] gids = mPM.getPackageGids(packageName, flags, mContext.getUserId());
Svetoslavc6d1c342015-02-26 14:44:43 -0800266 if (gids != null) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800267 return gids;
268 }
269 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700270 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800271 }
272
273 throw new NameNotFoundException(packageName);
274 }
275
276 @Override
Jeff Sharkey8588bc12016-01-06 16:47:42 -0700277 public int getPackageUid(String packageName, int flags) throws NameNotFoundException {
278 return getPackageUidAsUser(packageName, flags, mContext.getUserId());
279 }
280
281 @Override
282 public int getPackageUidAsUser(String packageName, int userId) throws NameNotFoundException {
283 return getPackageUidAsUser(packageName, 0, userId);
284 }
285
286 @Override
287 public int getPackageUidAsUser(String packageName, int flags, int userId)
Dianne Hackborna06de0f2012-12-11 16:34:47 -0800288 throws NameNotFoundException {
289 try {
Jeff Sharkeycd654482016-01-08 17:42:11 -0700290 int uid = mPM.getPackageUid(packageName, flags, userId);
Dianne Hackborna06de0f2012-12-11 16:34:47 -0800291 if (uid >= 0) {
292 return uid;
293 }
294 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700295 throw e.rethrowFromSystemServer();
Dianne Hackborna06de0f2012-12-11 16:34:47 -0800296 }
297
298 throw new NameNotFoundException(packageName);
299 }
300
301 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800302 public PermissionInfo getPermissionInfo(String name, int flags)
303 throws NameNotFoundException {
304 try {
Svetoslav Ganovadb8c522017-07-28 05:46:53 +0000305 PermissionInfo pi = mPM.getPermissionInfo(name,
306 mContext.getOpPackageName(), flags);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800307 if (pi != null) {
308 return pi;
309 }
310 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700311 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800312 }
313
314 throw new NameNotFoundException(name);
315 }
316
317 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700318 @SuppressWarnings("unchecked")
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800319 public List<PermissionInfo> queryPermissionsByGroup(String group, int flags)
320 throws NameNotFoundException {
321 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700322 ParceledListSlice<PermissionInfo> parceledList =
323 mPM.queryPermissionsByGroup(group, flags);
324 if (parceledList != null) {
325 List<PermissionInfo> pi = parceledList.getList();
326 if (pi != null) {
327 return pi;
328 }
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800329 }
330 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700331 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800332 }
333
334 throw new NameNotFoundException(group);
335 }
336
337 @Override
Paul Navin7b89a7b2017-01-26 23:56:08 +0000338 public boolean isPermissionReviewModeEnabled() {
339 return mContext.getResources().getBoolean(
340 com.android.internal.R.bool.config_permissionReviewRequired);
341 }
342
343 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800344 public PermissionGroupInfo getPermissionGroupInfo(String name,
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700345 int flags) throws NameNotFoundException {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800346 try {
347 PermissionGroupInfo pgi = mPM.getPermissionGroupInfo(name, flags);
348 if (pgi != null) {
349 return pgi;
350 }
351 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700352 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800353 }
354
355 throw new NameNotFoundException(name);
356 }
357
358 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700359 @SuppressWarnings("unchecked")
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800360 public List<PermissionGroupInfo> getAllPermissionGroups(int flags) {
361 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700362 ParceledListSlice<PermissionGroupInfo> parceledList =
363 mPM.getAllPermissionGroups(flags);
364 if (parceledList == null) {
365 return Collections.emptyList();
366 }
367 return parceledList.getList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800368 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700369 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800370 }
371 }
372
373 @Override
374 public ApplicationInfo getApplicationInfo(String packageName, int flags)
375 throws NameNotFoundException {
Jeff Sharkeycd654482016-01-08 17:42:11 -0700376 return getApplicationInfoAsUser(packageName, flags, mContext.getUserId());
377 }
378
379 @Override
380 public ApplicationInfo getApplicationInfoAsUser(String packageName, int flags, int userId)
381 throws NameNotFoundException {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800382 try {
Jeff Sharkeycd654482016-01-08 17:42:11 -0700383 ApplicationInfo ai = mPM.getApplicationInfo(packageName, flags, userId);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800384 if (ai != null) {
Narayan Kamathcaa71192014-07-16 11:06:43 +0100385 // This is a temporary hack. Callers must use
386 // createPackageContext(packageName).getApplicationInfo() to
387 // get the right paths.
Tao Baic9a02372016-01-12 15:02:24 -0800388 return maybeAdjustApplicationInfo(ai);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800389 }
390 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700391 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800392 }
393
394 throw new NameNotFoundException(packageName);
395 }
396
Tao Baic9a02372016-01-12 15:02:24 -0800397 private static ApplicationInfo maybeAdjustApplicationInfo(ApplicationInfo info) {
Narayan Kamathcaa71192014-07-16 11:06:43 +0100398 // If we're dealing with a multi-arch application that has both
399 // 32 and 64 bit shared libraries, we might need to choose the secondary
400 // depending on what the current runtime's instruction set is.
401 if (info.primaryCpuAbi != null && info.secondaryCpuAbi != null) {
402 final String runtimeIsa = VMRuntime.getRuntime().vmInstructionSet();
jgu214741cd92014-12-17 17:23:29 -0500403
404 // Get the instruction set that the libraries of secondary Abi is supported.
405 // In presence of a native bridge this might be different than the one secondary Abi used.
406 String secondaryIsa = VMRuntime.getInstructionSet(info.secondaryCpuAbi);
407 final String secondaryDexCodeIsa = SystemProperties.get("ro.dalvik.vm.isa." + secondaryIsa);
408 secondaryIsa = secondaryDexCodeIsa.isEmpty() ? secondaryIsa : secondaryDexCodeIsa;
Narayan Kamathcaa71192014-07-16 11:06:43 +0100409
410 // If the runtimeIsa is the same as the primary isa, then we do nothing.
411 // Everything will be set up correctly because info.nativeLibraryDir will
412 // correspond to the right ISA.
413 if (runtimeIsa.equals(secondaryIsa)) {
Tao Baic9a02372016-01-12 15:02:24 -0800414 ApplicationInfo modified = new ApplicationInfo(info);
415 modified.nativeLibraryDir = info.secondaryNativeLibraryDir;
416 return modified;
Narayan Kamathcaa71192014-07-16 11:06:43 +0100417 }
418 }
Tao Baic9a02372016-01-12 15:02:24 -0800419 return info;
Narayan Kamathcaa71192014-07-16 11:06:43 +0100420 }
421
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800422 @Override
423 public ActivityInfo getActivityInfo(ComponentName className, int flags)
424 throws NameNotFoundException {
425 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700426 ActivityInfo ai = mPM.getActivityInfo(className, flags, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800427 if (ai != null) {
428 return ai;
429 }
430 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700431 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800432 }
433
434 throw new NameNotFoundException(className.toString());
435 }
436
437 @Override
438 public ActivityInfo getReceiverInfo(ComponentName className, int flags)
439 throws NameNotFoundException {
440 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700441 ActivityInfo ai = mPM.getReceiverInfo(className, flags, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800442 if (ai != null) {
443 return ai;
444 }
445 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700446 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800447 }
448
449 throw new NameNotFoundException(className.toString());
450 }
451
452 @Override
453 public ServiceInfo getServiceInfo(ComponentName className, int flags)
454 throws NameNotFoundException {
455 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700456 ServiceInfo si = mPM.getServiceInfo(className, flags, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800457 if (si != null) {
458 return si;
459 }
460 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700461 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800462 }
463
464 throw new NameNotFoundException(className.toString());
465 }
466
467 @Override
468 public ProviderInfo getProviderInfo(ComponentName className, int flags)
469 throws NameNotFoundException {
470 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700471 ProviderInfo pi = mPM.getProviderInfo(className, flags, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800472 if (pi != null) {
473 return pi;
474 }
475 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700476 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800477 }
478
479 throw new NameNotFoundException(className.toString());
480 }
481
482 @Override
483 public String[] getSystemSharedLibraryNames() {
484 try {
485 return mPM.getSystemSharedLibraryNames();
486 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700487 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800488 }
489 }
490
Svet Ganovd7b1f4112016-02-09 18:49:23 -0800491 /** @hide */
492 @Override
Svet Ganov67882122016-12-11 16:36:34 -0800493 public @NonNull List<SharedLibraryInfo> getSharedLibraries(int flags) {
494 return getSharedLibrariesAsUser(flags, mContext.getUserId());
495 }
496
497 /** @hide */
498 @Override
499 @SuppressWarnings("unchecked")
500 public @NonNull List<SharedLibraryInfo> getSharedLibrariesAsUser(int flags, int userId) {
501 try {
502 ParceledListSlice<SharedLibraryInfo> sharedLibs = mPM.getSharedLibraries(
Svet Ganov58c99f02017-05-15 14:07:17 -0700503 mContext.getOpPackageName(), flags, userId);
Svet Ganov67882122016-12-11 16:36:34 -0800504 if (sharedLibs == null) {
505 return Collections.emptyList();
506 }
507 return sharedLibs.getList();
508 } catch (RemoteException e) {
509 throw e.rethrowFromSystemServer();
510 }
511 }
512
513 /** @hide */
514 @Override
Svetoslav Ganova9c25002016-04-13 19:25:56 -0700515 public @NonNull String getServicesSystemSharedLibraryPackageName() {
Svet Ganovd7b1f4112016-02-09 18:49:23 -0800516 try {
517 return mPM.getServicesSystemSharedLibraryPackageName();
518 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700519 throw e.rethrowFromSystemServer();
Svet Ganovd7b1f4112016-02-09 18:49:23 -0800520 }
521 }
522
Svetoslav Ganova9c25002016-04-13 19:25:56 -0700523 /**
524 * @hide
525 */
526 public @NonNull String getSharedSystemSharedLibraryPackageName() {
527 try {
528 return mPM.getSharedSystemSharedLibraryPackageName();
529 } catch (RemoteException e) {
530 throw e.rethrowFromSystemServer();
531 }
532 }
533
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800534 @Override
Todd Kennedy9106c642017-02-08 14:16:53 -0800535 public ChangedPackages getChangedPackages(int sequenceNumber) {
536 try {
537 return mPM.getChangedPackages(sequenceNumber, mContext.getUserId());
538 } catch (RemoteException e) {
539 throw e.rethrowFromSystemServer();
540 }
541 }
542
543 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700544 @SuppressWarnings("unchecked")
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800545 public FeatureInfo[] getSystemAvailableFeatures() {
546 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700547 ParceledListSlice<FeatureInfo> parceledList =
548 mPM.getSystemAvailableFeatures();
549 if (parceledList == null) {
550 return new FeatureInfo[0];
551 }
552 final List<FeatureInfo> list = parceledList.getList();
Jeff Sharkeyd5896632016-03-04 16:16:00 -0700553 final FeatureInfo[] res = new FeatureInfo[list.size()];
554 for (int i = 0; i < res.length; i++) {
555 res[i] = list.get(i);
556 }
557 return res;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800558 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700559 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800560 }
561 }
562
563 @Override
564 public boolean hasSystemFeature(String name) {
Jeff Sharkey115d2c12016-02-15 17:25:57 -0700565 return hasSystemFeature(name, 0);
566 }
567
568 @Override
569 public boolean hasSystemFeature(String name, int version) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800570 try {
Jeff Sharkey115d2c12016-02-15 17:25:57 -0700571 return mPM.hasSystemFeature(name, version);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800572 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700573 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800574 }
575 }
576
577 @Override
578 public int checkPermission(String permName, String pkgName) {
579 try {
Svetoslavc6d1c342015-02-26 14:44:43 -0800580 return mPM.checkPermission(permName, pkgName, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800581 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700582 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800583 }
584 }
585
586 @Override
Svet Ganovad3b2972015-07-07 22:49:17 -0700587 public boolean isPermissionRevokedByPolicy(String permName, String pkgName) {
588 try {
589 return mPM.isPermissionRevokedByPolicy(permName, pkgName, mContext.getUserId());
590 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700591 throw e.rethrowFromSystemServer();
Svet Ganovad3b2972015-07-07 22:49:17 -0700592 }
593 }
594
Svet Ganovf1b7f202015-07-29 08:33:42 -0700595 /**
596 * @hide
597 */
598 @Override
599 public String getPermissionControllerPackageName() {
600 synchronized (mLock) {
601 if (mPermissionsControllerPackageName == null) {
602 try {
603 mPermissionsControllerPackageName = mPM.getPermissionControllerPackageName();
604 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700605 throw e.rethrowFromSystemServer();
Svet Ganovf1b7f202015-07-29 08:33:42 -0700606 }
607 }
608 return mPermissionsControllerPackageName;
609 }
610 }
611
Svet Ganovad3b2972015-07-07 22:49:17 -0700612 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800613 public boolean addPermission(PermissionInfo info) {
614 try {
615 return mPM.addPermission(info);
616 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700617 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800618 }
619 }
620
621 @Override
622 public boolean addPermissionAsync(PermissionInfo info) {
623 try {
624 return mPM.addPermissionAsync(info);
625 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700626 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800627 }
628 }
629
630 @Override
631 public void removePermission(String name) {
632 try {
633 mPM.removePermission(name);
634 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700635 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800636 }
637 }
638
639 @Override
Svet Ganov8c7f7002015-05-07 10:48:44 -0700640 public void grantRuntimePermission(String packageName, String permissionName,
641 UserHandle user) {
Dianne Hackborne639da72012-02-21 15:11:13 -0800642 try {
Svet Ganov8c7f7002015-05-07 10:48:44 -0700643 mPM.grantRuntimePermission(packageName, permissionName, user.getIdentifier());
Dianne Hackborne639da72012-02-21 15:11:13 -0800644 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700645 throw e.rethrowFromSystemServer();
Dianne Hackborne639da72012-02-21 15:11:13 -0800646 }
647 }
648
649 @Override
Svet Ganov8c7f7002015-05-07 10:48:44 -0700650 public void revokeRuntimePermission(String packageName, String permissionName,
651 UserHandle user) {
Dianne Hackborne639da72012-02-21 15:11:13 -0800652 try {
Svet Ganov8c7f7002015-05-07 10:48:44 -0700653 mPM.revokeRuntimePermission(packageName, permissionName, user.getIdentifier());
654 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700655 throw e.rethrowFromSystemServer();
Svet Ganov8c7f7002015-05-07 10:48:44 -0700656 }
657 }
658
659 @Override
660 public int getPermissionFlags(String permissionName, String packageName, UserHandle user) {
661 try {
662 return mPM.getPermissionFlags(permissionName, packageName, user.getIdentifier());
663 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700664 throw e.rethrowFromSystemServer();
Svet Ganov8c7f7002015-05-07 10:48:44 -0700665 }
666 }
667
668 @Override
669 public void updatePermissionFlags(String permissionName, String packageName,
670 int flagMask, int flagValues, UserHandle user) {
671 try {
672 mPM.updatePermissionFlags(permissionName, packageName, flagMask,
673 flagValues, user.getIdentifier());
Dianne Hackborne639da72012-02-21 15:11:13 -0800674 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700675 throw e.rethrowFromSystemServer();
Dianne Hackborne639da72012-02-21 15:11:13 -0800676 }
677 }
678
679 @Override
Svetoslav20770dd2015-05-29 15:43:04 -0700680 public boolean shouldShowRequestPermissionRationale(String permission) {
681 try {
682 return mPM.shouldShowRequestPermissionRationale(permission,
683 mContext.getPackageName(), mContext.getUserId());
684 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700685 throw e.rethrowFromSystemServer();
Svetoslav20770dd2015-05-29 15:43:04 -0700686 }
687 }
688
689 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800690 public int checkSignatures(String pkg1, String pkg2) {
691 try {
692 return mPM.checkSignatures(pkg1, pkg2);
693 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700694 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800695 }
696 }
697
698 @Override
699 public int checkSignatures(int uid1, int uid2) {
700 try {
701 return mPM.checkUidSignatures(uid1, uid2);
702 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700703 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800704 }
705 }
706
707 @Override
Daniel Cashman5cdda342018-01-19 07:22:52 -0800708 public boolean hasSigningCertificate(
709 String packageName, byte[] certificate, @PackageManager.CertificateInputType int type) {
710 try {
711 return mPM.hasSigningCertificate(packageName, certificate, type);
712 } catch (RemoteException e) {
713 throw e.rethrowFromSystemServer();
714 }
715 }
716
717 @Override
718 public boolean hasSigningCertificate(
719 int uid, byte[] certificate, @PackageManager.CertificateInputType int type) {
720 try {
721 return mPM.hasUidSigningCertificate(uid, certificate, type);
722 } catch (RemoteException e) {
723 throw e.rethrowFromSystemServer();
724 }
725 }
726
727 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800728 public String[] getPackagesForUid(int uid) {
729 try {
730 return mPM.getPackagesForUid(uid);
731 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700732 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800733 }
734 }
735
736 @Override
737 public String getNameForUid(int uid) {
738 try {
739 return mPM.getNameForUid(uid);
740 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700741 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800742 }
743 }
744
745 @Override
Todd Kennedy9da8b8a72017-07-25 15:38:39 -0700746 public String[] getNamesForUids(int[] uids) {
747 try {
748 return mPM.getNamesForUids(uids);
749 } catch (RemoteException e) {
750 throw e.rethrowFromSystemServer();
751 }
752 }
753
754 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800755 public int getUidForSharedUser(String sharedUserName)
756 throws NameNotFoundException {
757 try {
758 int uid = mPM.getUidForSharedUser(sharedUserName);
759 if(uid != -1) {
760 return uid;
761 }
762 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700763 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800764 }
765 throw new NameNotFoundException("No shared userid for user:"+sharedUserName);
766 }
767
Kenny Roote6cd0c72011-05-19 12:48:14 -0700768 @SuppressWarnings("unchecked")
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800769 @Override
770 public List<PackageInfo> getInstalledPackages(int flags) {
Jeff Sharkeye06b4d12016-01-06 14:51:50 -0700771 return getInstalledPackagesAsUser(flags, mContext.getUserId());
Amith Yamasani151ec4c2012-09-07 19:25:16 -0700772 }
773
774 /** @hide */
775 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700776 @SuppressWarnings("unchecked")
Jeff Sharkeye06b4d12016-01-06 14:51:50 -0700777 public List<PackageInfo> getInstalledPackagesAsUser(int flags, int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800778 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700779 ParceledListSlice<PackageInfo> parceledList =
780 mPM.getInstalledPackages(flags, userId);
781 if (parceledList == null) {
782 return Collections.emptyList();
783 }
784 return parceledList.getList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800785 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700786 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800787 }
788 }
789
Kenny Roote6cd0c72011-05-19 12:48:14 -0700790 @SuppressWarnings("unchecked")
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800791 @Override
Dianne Hackborne7991752013-01-16 17:56:46 -0800792 public List<PackageInfo> getPackagesHoldingPermissions(
793 String[] permissions, int flags) {
794 final int userId = mContext.getUserId();
795 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700796 ParceledListSlice<PackageInfo> parceledList =
797 mPM.getPackagesHoldingPermissions(permissions, flags, userId);
798 if (parceledList == null) {
799 return Collections.emptyList();
800 }
801 return parceledList.getList();
Dianne Hackborne7991752013-01-16 17:56:46 -0800802 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700803 throw e.rethrowFromSystemServer();
Dianne Hackborne7991752013-01-16 17:56:46 -0800804 }
805 }
806
807 @SuppressWarnings("unchecked")
808 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800809 public List<ApplicationInfo> getInstalledApplications(int flags) {
Bartosz Fabianowski11334242016-11-17 20:49:16 +0100810 return getInstalledApplicationsAsUser(flags, mContext.getUserId());
811 }
812
813 /** @hide */
814 @SuppressWarnings("unchecked")
815 @Override
816 public List<ApplicationInfo> getInstalledApplicationsAsUser(int flags, int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800817 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700818 ParceledListSlice<ApplicationInfo> parceledList =
819 mPM.getInstalledApplications(flags, userId);
820 if (parceledList == null) {
821 return Collections.emptyList();
822 }
823 return parceledList.getList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800824 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700825 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800826 }
827 }
828
Svet Ganov2acf0632015-11-24 19:10:59 -0800829 /** @hide */
830 @SuppressWarnings("unchecked")
831 @Override
Svetoslav Ganov096d3042017-01-30 16:34:13 -0800832 public List<InstantAppInfo> getInstantApps() {
Svet Ganov2acf0632015-11-24 19:10:59 -0800833 try {
Svetoslav Ganov096d3042017-01-30 16:34:13 -0800834 ParceledListSlice<InstantAppInfo> slice =
835 mPM.getInstantApps(mContext.getUserId());
Svet Ganov2acf0632015-11-24 19:10:59 -0800836 if (slice != null) {
837 return slice.getList();
838 }
839 return Collections.emptyList();
840 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700841 throw e.rethrowFromSystemServer();
Svet Ganov2acf0632015-11-24 19:10:59 -0800842 }
843 }
844
845 /** @hide */
846 @Override
Svetoslav Ganov096d3042017-01-30 16:34:13 -0800847 public Drawable getInstantAppIcon(String packageName) {
Svet Ganov2acf0632015-11-24 19:10:59 -0800848 try {
Svetoslav Ganov096d3042017-01-30 16:34:13 -0800849 Bitmap bitmap = mPM.getInstantAppIcon(
Svet Ganov2acf0632015-11-24 19:10:59 -0800850 packageName, mContext.getUserId());
851 if (bitmap != null) {
852 return new BitmapDrawable(null, bitmap);
853 }
854 return null;
855 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700856 throw e.rethrowFromSystemServer();
Svet Ganov2acf0632015-11-24 19:10:59 -0800857 }
858 }
859
860 @Override
Svetoslav Ganov096d3042017-01-30 16:34:13 -0800861 public boolean isInstantApp() {
David Christie31a16552017-03-01 15:08:45 -0800862 return isInstantApp(mContext.getPackageName());
863 }
864
865 @Override
866 public boolean isInstantApp(String packageName) {
Svet Ganov2acf0632015-11-24 19:10:59 -0800867 try {
David Christie31a16552017-03-01 15:08:45 -0800868 return mPM.isInstantApp(packageName, mContext.getUserId());
Svet Ganov2acf0632015-11-24 19:10:59 -0800869 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700870 throw e.rethrowFromSystemServer();
Svet Ganov2acf0632015-11-24 19:10:59 -0800871 }
Svet Ganov2acf0632015-11-24 19:10:59 -0800872 }
873
Svetoslav Ganov345ffa52017-04-18 16:08:41 -0700874 public int getInstantAppCookieMaxBytes() {
Svet Ganov2acf0632015-11-24 19:10:59 -0800875 return Settings.Global.getInt(mContext.getContentResolver(),
876 Settings.Global.EPHEMERAL_COOKIE_MAX_SIZE_BYTES,
877 DEFAULT_EPHEMERAL_COOKIE_MAX_SIZE_BYTES);
878 }
879
880 @Override
Svetoslav Ganov345ffa52017-04-18 16:08:41 -0700881 public int getInstantAppCookieMaxSize() {
882 return getInstantAppCookieMaxBytes();
883 }
884
885 @Override
Svetoslav Ganov096d3042017-01-30 16:34:13 -0800886 public @NonNull byte[] getInstantAppCookie() {
Svet Ganov2acf0632015-11-24 19:10:59 -0800887 try {
Svetoslav Ganov096d3042017-01-30 16:34:13 -0800888 final byte[] cookie = mPM.getInstantAppCookie(
Svet Ganov2acf0632015-11-24 19:10:59 -0800889 mContext.getPackageName(), mContext.getUserId());
890 if (cookie != null) {
891 return cookie;
Jeff Sharkey27b2e692016-02-25 17:40:12 -0700892 } else {
893 return EmptyArray.BYTE;
Svet Ganov2acf0632015-11-24 19:10:59 -0800894 }
895 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700896 throw e.rethrowFromSystemServer();
Svet Ganov2acf0632015-11-24 19:10:59 -0800897 }
Svet Ganov2acf0632015-11-24 19:10:59 -0800898 }
899
900 @Override
Svetoslav Ganov345ffa52017-04-18 16:08:41 -0700901 public void clearInstantAppCookie() {
902 updateInstantAppCookie(null);
903 }
904
905 @Override
906 public void updateInstantAppCookie(@NonNull byte[] cookie) {
907 if (cookie != null && cookie.length > getInstantAppCookieMaxBytes()) {
908 throw new IllegalArgumentException("instant cookie longer than "
909 + getInstantAppCookieMaxBytes());
910 }
911 try {
912 mPM.setInstantAppCookie(mContext.getPackageName(),
913 cookie, mContext.getUserId());
914 } catch (RemoteException e) {
915 throw e.rethrowFromSystemServer();
916 }
917 }
918
919 @Override
Svetoslav Ganov096d3042017-01-30 16:34:13 -0800920 public boolean setInstantAppCookie(@NonNull byte[] cookie) {
Svet Ganov2acf0632015-11-24 19:10:59 -0800921 try {
Svetoslav Ganov096d3042017-01-30 16:34:13 -0800922 return mPM.setInstantAppCookie(mContext.getPackageName(),
923 cookie, mContext.getUserId());
Svet Ganov2acf0632015-11-24 19:10:59 -0800924 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700925 throw e.rethrowFromSystemServer();
Svet Ganov2acf0632015-11-24 19:10:59 -0800926 }
Svet Ganov2acf0632015-11-24 19:10:59 -0800927 }
928
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800929 @Override
930 public ResolveInfo resolveActivity(Intent intent, int flags) {
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700931 return resolveActivityAsUser(intent, flags, mContext.getUserId());
Svetoslav Ganov58d37b52012-09-18 12:04:19 -0700932 }
933
934 @Override
935 public ResolveInfo resolveActivityAsUser(Intent intent, int flags, int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800936 try {
937 return mPM.resolveIntent(
938 intent,
939 intent.resolveTypeIfNeeded(mContext.getContentResolver()),
Svetoslav Ganov58d37b52012-09-18 12:04:19 -0700940 flags,
941 userId);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800942 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700943 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800944 }
945 }
946
947 @Override
948 public List<ResolveInfo> queryIntentActivities(Intent intent,
949 int flags) {
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700950 return queryIntentActivitiesAsUser(intent, flags, mContext.getUserId());
Amith Yamasani151ec4c2012-09-07 19:25:16 -0700951 }
952
953 /** @hide Same as above but for a specific user */
954 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700955 @SuppressWarnings("unchecked")
Svetoslav Ganov58d37b52012-09-18 12:04:19 -0700956 public List<ResolveInfo> queryIntentActivitiesAsUser(Intent intent,
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700957 int flags, int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800958 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700959 ParceledListSlice<ResolveInfo> parceledList =
960 mPM.queryIntentActivities(intent,
961 intent.resolveTypeIfNeeded(mContext.getContentResolver()),
962 flags, userId);
963 if (parceledList == null) {
964 return Collections.emptyList();
965 }
966 return parceledList.getList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800967 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700968 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800969 }
970 }
971
972 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700973 @SuppressWarnings("unchecked")
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800974 public List<ResolveInfo> queryIntentActivityOptions(
975 ComponentName caller, Intent[] specifics, Intent intent,
976 int flags) {
977 final ContentResolver resolver = mContext.getContentResolver();
978
979 String[] specificTypes = null;
980 if (specifics != null) {
981 final int N = specifics.length;
982 for (int i=0; i<N; i++) {
983 Intent sp = specifics[i];
984 if (sp != null) {
985 String t = sp.resolveTypeIfNeeded(resolver);
986 if (t != null) {
987 if (specificTypes == null) {
988 specificTypes = new String[N];
989 }
990 specificTypes[i] = t;
991 }
992 }
993 }
994 }
995
996 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700997 ParceledListSlice<ResolveInfo> parceledList =
998 mPM.queryIntentActivityOptions(caller, specifics, specificTypes, intent,
999 intent.resolveTypeIfNeeded(resolver), flags, mContext.getUserId());
1000 if (parceledList == null) {
1001 return Collections.emptyList();
1002 }
1003 return parceledList.getList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001004 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001005 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001006 }
1007 }
1008
Amith Yamasanif203aee2012-08-29 18:41:53 -07001009 /**
1010 * @hide
1011 */
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001012 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001013 @SuppressWarnings("unchecked")
Jeff Sharkeye06b4d12016-01-06 14:51:50 -07001014 public List<ResolveInfo> queryBroadcastReceiversAsUser(Intent intent, int flags, int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001015 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001016 ParceledListSlice<ResolveInfo> parceledList =
1017 mPM.queryIntentReceivers(intent,
1018 intent.resolveTypeIfNeeded(mContext.getContentResolver()),
1019 flags, userId);
1020 if (parceledList == null) {
1021 return Collections.emptyList();
1022 }
1023 return parceledList.getList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001024 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001025 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001026 }
1027 }
1028
1029 @Override
Amith Yamasanif203aee2012-08-29 18:41:53 -07001030 public List<ResolveInfo> queryBroadcastReceivers(Intent intent, int flags) {
Jeff Sharkeye06b4d12016-01-06 14:51:50 -07001031 return queryBroadcastReceiversAsUser(intent, flags, mContext.getUserId());
Amith Yamasanif203aee2012-08-29 18:41:53 -07001032 }
1033
1034 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001035 public ResolveInfo resolveService(Intent intent, int flags) {
1036 try {
1037 return mPM.resolveService(
1038 intent,
1039 intent.resolveTypeIfNeeded(mContext.getContentResolver()),
Amith Yamasani483f3b02012-03-13 16:08:00 -07001040 flags,
Jeff Sharkeyded653b2012-09-27 19:09:24 -07001041 mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001042 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001043 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001044 }
1045 }
1046
1047 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001048 @SuppressWarnings("unchecked")
Svetoslav Ganov58d37b52012-09-18 12:04:19 -07001049 public List<ResolveInfo> queryIntentServicesAsUser(Intent intent, int flags, int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001050 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001051 ParceledListSlice<ResolveInfo> parceledList =
1052 mPM.queryIntentServices(intent,
1053 intent.resolveTypeIfNeeded(mContext.getContentResolver()),
1054 flags, userId);
1055 if (parceledList == null) {
1056 return Collections.emptyList();
1057 }
1058 return parceledList.getList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001059 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001060 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001061 }
1062 }
1063
1064 @Override
Svetoslav Ganov58d37b52012-09-18 12:04:19 -07001065 public List<ResolveInfo> queryIntentServices(Intent intent, int flags) {
Jeff Sharkeyded653b2012-09-27 19:09:24 -07001066 return queryIntentServicesAsUser(intent, flags, mContext.getUserId());
Svetoslav Ganov58d37b52012-09-18 12:04:19 -07001067 }
1068
1069 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001070 @SuppressWarnings("unchecked")
Jeff Sharkey85f5f812013-10-07 10:16:12 -07001071 public List<ResolveInfo> queryIntentContentProvidersAsUser(
1072 Intent intent, int flags, int userId) {
1073 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001074 ParceledListSlice<ResolveInfo> parceledList =
1075 mPM.queryIntentContentProviders(intent,
1076 intent.resolveTypeIfNeeded(mContext.getContentResolver()),
1077 flags, userId);
1078 if (parceledList == null) {
1079 return Collections.emptyList();
1080 }
1081 return parceledList.getList();
Jeff Sharkey85f5f812013-10-07 10:16:12 -07001082 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001083 throw e.rethrowFromSystemServer();
Jeff Sharkey85f5f812013-10-07 10:16:12 -07001084 }
1085 }
1086
1087 @Override
1088 public List<ResolveInfo> queryIntentContentProviders(Intent intent, int flags) {
1089 return queryIntentContentProvidersAsUser(intent, flags, mContext.getUserId());
1090 }
1091
1092 @Override
Alexandra Gherghina0363c3e2014-06-23 13:34:59 +01001093 public ProviderInfo resolveContentProvider(String name, int flags) {
1094 return resolveContentProviderAsUser(name, flags, mContext.getUserId());
1095 }
1096
1097 /** @hide **/
1098 @Override
1099 public ProviderInfo resolveContentProviderAsUser(String name, int flags, int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001100 try {
Alexandra Gherghina0363c3e2014-06-23 13:34:59 +01001101 return mPM.resolveContentProvider(name, flags, userId);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001102 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001103 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001104 }
1105 }
1106
1107 @Override
1108 public List<ProviderInfo> queryContentProviders(String processName,
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001109 int uid, int flags) {
Makoto Onuki32757292017-02-22 14:36:59 -08001110 return queryContentProviders(processName, uid, flags, null);
1111 }
1112
1113 @Override
1114 @SuppressWarnings("unchecked")
1115 public List<ProviderInfo> queryContentProviders(String processName,
1116 int uid, int flags, String metaDataKey) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001117 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001118 ParceledListSlice<ProviderInfo> slice =
Makoto Onuki32757292017-02-22 14:36:59 -08001119 mPM.queryContentProviders(processName, uid, flags, metaDataKey);
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001120 return slice != null ? slice.getList() : Collections.<ProviderInfo>emptyList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001121 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001122 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001123 }
1124 }
1125
1126 @Override
1127 public InstrumentationInfo getInstrumentationInfo(
1128 ComponentName className, int flags)
1129 throws NameNotFoundException {
1130 try {
1131 InstrumentationInfo ii = mPM.getInstrumentationInfo(
1132 className, flags);
1133 if (ii != null) {
1134 return ii;
1135 }
1136 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001137 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001138 }
1139
1140 throw new NameNotFoundException(className.toString());
1141 }
1142
1143 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001144 @SuppressWarnings("unchecked")
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001145 public List<InstrumentationInfo> queryInstrumentation(
1146 String targetPackage, int flags) {
1147 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001148 ParceledListSlice<InstrumentationInfo> parceledList =
1149 mPM.queryInstrumentation(targetPackage, flags);
1150 if (parceledList == null) {
1151 return Collections.emptyList();
1152 }
1153 return parceledList.getList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001154 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001155 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001156 }
1157 }
1158
Alan Viveretteecd585a2015-04-13 10:32:51 -07001159 @Nullable
1160 @Override
1161 public Drawable getDrawable(String packageName, @DrawableRes int resId,
1162 @Nullable ApplicationInfo appInfo) {
1163 final ResourceName name = new ResourceName(packageName, resId);
1164 final Drawable cachedIcon = getCachedIcon(name);
1165 if (cachedIcon != null) {
1166 return cachedIcon;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001167 }
Alan Viveretteecd585a2015-04-13 10:32:51 -07001168
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001169 if (appInfo == null) {
1170 try {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001171 appInfo = getApplicationInfo(packageName, sDefaultFlags);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001172 } catch (NameNotFoundException e) {
1173 return null;
1174 }
1175 }
Alan Viveretteecd585a2015-04-13 10:32:51 -07001176
1177 if (resId != 0) {
1178 try {
1179 final Resources r = getResourcesForApplication(appInfo);
1180 final Drawable dr = r.getDrawable(resId, null);
1181 if (dr != null) {
1182 putCachedIcon(name, dr);
1183 }
1184
1185 if (false) {
1186 RuntimeException e = new RuntimeException("here");
1187 e.fillInStackTrace();
1188 Log.w(TAG, "Getting drawable 0x" + Integer.toHexString(resId)
1189 + " from package " + packageName
1190 + ": app scale=" + r.getCompatibilityInfo().applicationScale
1191 + ", caller scale=" + mContext.getResources()
1192 .getCompatibilityInfo().applicationScale,
1193 e);
1194 }
Ricky Wai3ce46252015-04-15 16:12:22 +01001195 if (DEBUG_ICONS) {
Alan Viveretteecd585a2015-04-13 10:32:51 -07001196 Log.v(TAG, "Getting drawable 0x"
1197 + Integer.toHexString(resId) + " from " + r
1198 + ": " + dr);
Ricky Wai3ce46252015-04-15 16:12:22 +01001199 }
1200 return dr;
Alan Viveretteecd585a2015-04-13 10:32:51 -07001201 } catch (NameNotFoundException e) {
1202 Log.w("PackageManager", "Failure retrieving resources for "
1203 + appInfo.packageName);
1204 } catch (Resources.NotFoundException e) {
1205 Log.w("PackageManager", "Failure retrieving resources for "
1206 + appInfo.packageName + ": " + e.getMessage());
1207 } catch (Exception e) {
1208 // If an exception was thrown, fall through to return
1209 // default icon.
1210 Log.w("PackageManager", "Failure retrieving icon 0x"
1211 + Integer.toHexString(resId) + " in package "
1212 + packageName, e);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001213 }
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001214 }
Alan Viveretteecd585a2015-04-13 10:32:51 -07001215
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001216 return null;
1217 }
1218
1219 @Override public Drawable getActivityIcon(ComponentName activityName)
1220 throws NameNotFoundException {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001221 return getActivityInfo(activityName, sDefaultFlags).loadIcon(this);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001222 }
1223
1224 @Override public Drawable getActivityIcon(Intent intent)
1225 throws NameNotFoundException {
1226 if (intent.getComponent() != null) {
1227 return getActivityIcon(intent.getComponent());
1228 }
1229
1230 ResolveInfo info = resolveActivity(
1231 intent, PackageManager.MATCH_DEFAULT_ONLY);
1232 if (info != null) {
1233 return info.activityInfo.loadIcon(this);
1234 }
1235
Romain Guy39fe17c2011-11-30 10:34:07 -08001236 throw new NameNotFoundException(intent.toUri(0));
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001237 }
1238
1239 @Override public Drawable getDefaultActivityIcon() {
1240 return Resources.getSystem().getDrawable(
1241 com.android.internal.R.drawable.sym_def_app_icon);
1242 }
1243
1244 @Override public Drawable getApplicationIcon(ApplicationInfo info) {
1245 return info.loadIcon(this);
1246 }
1247
1248 @Override public Drawable getApplicationIcon(String packageName)
1249 throws NameNotFoundException {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001250 return getApplicationIcon(getApplicationInfo(packageName, sDefaultFlags));
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001251 }
1252
1253 @Override
Jose Limaf78e3122014-03-06 12:13:15 -08001254 public Drawable getActivityBanner(ComponentName activityName)
1255 throws NameNotFoundException {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001256 return getActivityInfo(activityName, sDefaultFlags).loadBanner(this);
Jose Limaf78e3122014-03-06 12:13:15 -08001257 }
1258
1259 @Override
1260 public Drawable getActivityBanner(Intent intent)
1261 throws NameNotFoundException {
1262 if (intent.getComponent() != null) {
1263 return getActivityBanner(intent.getComponent());
1264 }
1265
1266 ResolveInfo info = resolveActivity(
1267 intent, PackageManager.MATCH_DEFAULT_ONLY);
1268 if (info != null) {
1269 return info.activityInfo.loadBanner(this);
1270 }
1271
1272 throw new NameNotFoundException(intent.toUri(0));
1273 }
1274
1275 @Override
1276 public Drawable getApplicationBanner(ApplicationInfo info) {
1277 return info.loadBanner(this);
1278 }
1279
1280 @Override
1281 public Drawable getApplicationBanner(String packageName)
1282 throws NameNotFoundException {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001283 return getApplicationBanner(getApplicationInfo(packageName, sDefaultFlags));
Jose Limaf78e3122014-03-06 12:13:15 -08001284 }
1285
1286 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001287 public Drawable getActivityLogo(ComponentName activityName)
1288 throws NameNotFoundException {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001289 return getActivityInfo(activityName, sDefaultFlags).loadLogo(this);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001290 }
1291
1292 @Override
1293 public Drawable getActivityLogo(Intent intent)
1294 throws NameNotFoundException {
1295 if (intent.getComponent() != null) {
1296 return getActivityLogo(intent.getComponent());
1297 }
1298
1299 ResolveInfo info = resolveActivity(
1300 intent, PackageManager.MATCH_DEFAULT_ONLY);
1301 if (info != null) {
1302 return info.activityInfo.loadLogo(this);
1303 }
1304
1305 throw new NameNotFoundException(intent.toUri(0));
1306 }
1307
1308 @Override
1309 public Drawable getApplicationLogo(ApplicationInfo info) {
1310 return info.loadLogo(this);
1311 }
1312
1313 @Override
1314 public Drawable getApplicationLogo(String packageName)
1315 throws NameNotFoundException {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001316 return getApplicationLogo(getApplicationInfo(packageName, sDefaultFlags));
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001317 }
1318
Svetoslavc7d62f02014-09-04 15:39:54 -07001319 @Override
1320 public Drawable getUserBadgedIcon(Drawable icon, UserHandle user) {
Kenny Guy02c89902016-11-15 19:36:38 +00001321 if (!isManagedProfile(user.getIdentifier())) {
Svetoslavc7d62f02014-09-04 15:39:54 -07001322 return icon;
1323 }
Sunny Goyalbab30752017-04-12 15:36:42 -07001324 Drawable badge = new LauncherIcons(mContext).getBadgeDrawable(
1325 com.android.internal.R.drawable.ic_corp_icon_badge_case,
1326 getUserBadgeColor(user));
Kenny Guy02c89902016-11-15 19:36:38 +00001327 return getBadgedDrawable(icon, badge, null, true);
Svetoslavc7d62f02014-09-04 15:39:54 -07001328 }
1329
1330 @Override
1331 public Drawable getUserBadgedDrawableForDensity(Drawable drawable, UserHandle user,
1332 Rect badgeLocation, int badgeDensity) {
1333 Drawable badgeDrawable = getUserBadgeForDensity(user, badgeDensity);
1334 if (badgeDrawable == null) {
1335 return drawable;
1336 }
1337 return getBadgedDrawable(drawable, badgeDrawable, badgeLocation, true);
1338 }
1339
Kenny Guy02c89902016-11-15 19:36:38 +00001340 @VisibleForTesting
1341 public static final int[] CORP_BADGE_LABEL_RES_ID = new int[] {
1342 com.android.internal.R.string.managed_profile_label_badge,
1343 com.android.internal.R.string.managed_profile_label_badge_2,
1344 com.android.internal.R.string.managed_profile_label_badge_3
1345 };
1346
1347 private int getUserBadgeColor(UserHandle user) {
Sunny Goyalbab30752017-04-12 15:36:42 -07001348 return IconDrawableFactory.getUserBadgeColor(getUserManager(), user.getIdentifier());
Kenny Guy02c89902016-11-15 19:36:38 +00001349 }
1350
Svetoslavc7d62f02014-09-04 15:39:54 -07001351 @Override
1352 public Drawable getUserBadgeForDensity(UserHandle user, int density) {
Kenny Guy02c89902016-11-15 19:36:38 +00001353 Drawable badgeColor = getManagedProfileIconForDensity(user,
1354 com.android.internal.R.drawable.ic_corp_badge_color, density);
1355 if (badgeColor == null) {
1356 return null;
1357 }
Kenny Guy02c89902016-11-15 19:36:38 +00001358 Drawable badgeForeground = getDrawableForDensity(
1359 com.android.internal.R.drawable.ic_corp_badge_case, density);
Tony Make21a1d02018-02-16 11:46:58 +00001360 badgeForeground.setTint(getUserBadgeColor(user));
1361 Drawable badge = new LayerDrawable(new Drawable[] {badgeColor, badgeForeground });
Kenny Guy02c89902016-11-15 19:36:38 +00001362 return badge;
Selim Cineke6ff9462016-01-15 15:07:06 -08001363 }
1364
1365 @Override
1366 public Drawable getUserBadgeForDensityNoBackground(UserHandle user, int density) {
Kenny Guy02c89902016-11-15 19:36:38 +00001367 Drawable badge = getManagedProfileIconForDensity(user,
Vadim Tryshev66ae66a2016-02-18 15:41:21 -08001368 com.android.internal.R.drawable.ic_corp_badge_no_background, density);
Kenny Guy02c89902016-11-15 19:36:38 +00001369 if (badge != null) {
1370 badge.setTint(getUserBadgeColor(user));
1371 }
1372 return badge;
Selim Cineke6ff9462016-01-15 15:07:06 -08001373 }
1374
Vadim Tryshev66ae66a2016-02-18 15:41:21 -08001375 private Drawable getDrawableForDensity(int drawableId, int density) {
1376 if (density <= 0) {
1377 density = mContext.getResources().getDisplayMetrics().densityDpi;
1378 }
1379 return Resources.getSystem().getDrawableForDensity(drawableId, density);
1380 }
1381
1382 private Drawable getManagedProfileIconForDensity(UserHandle user, int drawableId, int density) {
Tony Mak8673b282016-03-21 21:10:59 +00001383 if (isManagedProfile(user.getIdentifier())) {
Vadim Tryshev66ae66a2016-02-18 15:41:21 -08001384 return getDrawableForDensity(drawableId, density);
Svetoslavc7d62f02014-09-04 15:39:54 -07001385 }
1386 return null;
1387 }
1388
1389 @Override
1390 public CharSequence getUserBadgedLabel(CharSequence label, UserHandle user) {
Tony Mak8673b282016-03-21 21:10:59 +00001391 if (isManagedProfile(user.getIdentifier())) {
Kenny Guy02c89902016-11-15 19:36:38 +00001392 int badge = getUserManager().getManagedProfileBadge(user.getIdentifier());
1393 int resourceId = CORP_BADGE_LABEL_RES_ID[badge % CORP_BADGE_LABEL_RES_ID.length];
1394 return Resources.getSystem().getString(resourceId, label);
Svetoslavc7d62f02014-09-04 15:39:54 -07001395 }
1396 return label;
1397 }
1398
Alan Viveretteecd585a2015-04-13 10:32:51 -07001399 @Override
1400 public Resources getResourcesForActivity(ComponentName activityName)
1401 throws NameNotFoundException {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001402 return getResourcesForApplication(
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001403 getActivityInfo(activityName, sDefaultFlags).applicationInfo);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001404 }
1405
Alan Viveretteecd585a2015-04-13 10:32:51 -07001406 @Override
1407 public Resources getResourcesForApplication(@NonNull ApplicationInfo app)
1408 throws NameNotFoundException {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001409 if (app.packageName.equals("system")) {
Adam Lesinskia82b6262017-03-21 16:56:17 -07001410 return mContext.mMainThread.getSystemUiContext().getResources();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001411 }
Jeff Sharkey8a4c9722014-06-16 13:48:42 -07001412 final boolean sameUid = (app.uid == Process.myUid());
Adam Lesinski53fafdf2016-08-03 13:36:39 -07001413 final Resources r = mContext.mMainThread.getTopLevelResources(
Adam Lesinskic82f28a2016-06-08 17:19:09 -07001414 sameUid ? app.sourceDir : app.publicSourceDir,
1415 sameUid ? app.splitSourceDirs : app.splitPublicSourceDirs,
1416 app.resourceDirs, app.sharedLibraryFiles, Display.DEFAULT_DISPLAY,
Todd Kennedy233a0b12018-01-29 20:30:24 +00001417 mContext.mPackageInfo);
Adam Lesinski53fafdf2016-08-03 13:36:39 -07001418 if (r != null) {
1419 return r;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001420 }
Adam Lesinski53fafdf2016-08-03 13:36:39 -07001421 throw new NameNotFoundException("Unable to open " + app.publicSourceDir);
1422
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001423 }
1424
Alan Viveretteecd585a2015-04-13 10:32:51 -07001425 @Override
1426 public Resources getResourcesForApplication(String appPackageName)
1427 throws NameNotFoundException {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001428 return getResourcesForApplication(
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001429 getApplicationInfo(appPackageName, sDefaultFlags));
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001430 }
1431
Amith Yamasani98edc952012-09-25 14:09:27 -07001432 /** @hide */
1433 @Override
1434 public Resources getResourcesForApplicationAsUser(String appPackageName, int userId)
1435 throws NameNotFoundException {
Jeff Sharkeyded653b2012-09-27 19:09:24 -07001436 if (userId < 0) {
1437 throw new IllegalArgumentException(
1438 "Call does not support special user #" + userId);
1439 }
1440 if ("system".equals(appPackageName)) {
Adam Lesinskia82b6262017-03-21 16:56:17 -07001441 return mContext.mMainThread.getSystemUiContext().getResources();
Jeff Sharkeyded653b2012-09-27 19:09:24 -07001442 }
Amith Yamasani98edc952012-09-25 14:09:27 -07001443 try {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001444 ApplicationInfo ai = mPM.getApplicationInfo(appPackageName, sDefaultFlags, userId);
Amith Yamasani98edc952012-09-25 14:09:27 -07001445 if (ai != null) {
1446 return getResourcesForApplication(ai);
1447 }
1448 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001449 throw e.rethrowFromSystemServer();
Amith Yamasani98edc952012-09-25 14:09:27 -07001450 }
1451 throw new NameNotFoundException("Package " + appPackageName + " doesn't exist");
1452 }
1453
Jeff Sharkeycd654482016-01-08 17:42:11 -07001454 volatile int mCachedSafeMode = -1;
1455
1456 @Override
1457 public boolean isSafeMode() {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001458 try {
1459 if (mCachedSafeMode < 0) {
1460 mCachedSafeMode = mPM.isSafeMode() ? 1 : 0;
1461 }
1462 return mCachedSafeMode != 0;
1463 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001464 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001465 }
1466 }
1467
Svetoslavf7c06eb2015-06-10 18:43:22 -07001468 @Override
1469 public void addOnPermissionsChangeListener(OnPermissionsChangedListener listener) {
1470 synchronized (mPermissionListeners) {
1471 if (mPermissionListeners.get(listener) != null) {
1472 return;
1473 }
1474 OnPermissionsChangeListenerDelegate delegate =
1475 new OnPermissionsChangeListenerDelegate(listener, Looper.getMainLooper());
1476 try {
1477 mPM.addOnPermissionsChangeListener(delegate);
1478 mPermissionListeners.put(listener, delegate);
1479 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001480 throw e.rethrowFromSystemServer();
Svetoslavf7c06eb2015-06-10 18:43:22 -07001481 }
1482 }
1483 }
1484
1485 @Override
1486 public void removeOnPermissionsChangeListener(OnPermissionsChangedListener listener) {
1487 synchronized (mPermissionListeners) {
1488 IOnPermissionsChangeListener delegate = mPermissionListeners.get(listener);
1489 if (delegate != null) {
1490 try {
1491 mPM.removeOnPermissionsChangeListener(delegate);
1492 mPermissionListeners.remove(listener);
1493 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001494 throw e.rethrowFromSystemServer();
Svetoslavf7c06eb2015-06-10 18:43:22 -07001495 }
1496 }
1497 }
1498 }
1499
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001500 static void configurationChanged() {
1501 synchronized (sSync) {
1502 sIconCache.clear();
1503 sStringCache.clear();
1504 }
1505 }
1506
Yao Chen022b8ea2016-12-16 11:03:28 -08001507 protected ApplicationPackageManager(ContextImpl context,
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001508 IPackageManager pm) {
1509 mContext = context;
1510 mPM = pm;
1511 }
1512
Alan Viveretteecd585a2015-04-13 10:32:51 -07001513 @Nullable
1514 private Drawable getCachedIcon(@NonNull ResourceName name) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001515 synchronized (sSync) {
Alan Viveretteecd585a2015-04-13 10:32:51 -07001516 final WeakReference<Drawable.ConstantState> wr = sIconCache.get(name);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001517 if (DEBUG_ICONS) Log.v(TAG, "Get cached weak drawable ref for "
1518 + name + ": " + wr);
1519 if (wr != null) { // we have the activity
Alan Viveretteecd585a2015-04-13 10:32:51 -07001520 final Drawable.ConstantState state = wr.get();
Romain Guy39fe17c2011-11-30 10:34:07 -08001521 if (state != null) {
1522 if (DEBUG_ICONS) {
1523 Log.v(TAG, "Get cached drawable state for " + name + ": " + state);
1524 }
1525 // Note: It's okay here to not use the newDrawable(Resources) variant
1526 // of the API. The ConstantState comes from a drawable that was
1527 // originally created by passing the proper app Resources instance
1528 // which means the state should already contain the proper
1529 // resources specific information (like density.) See
1530 // BitmapDrawable.BitmapState for instance.
1531 return state.newDrawable();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001532 }
1533 // our entry has been purged
1534 sIconCache.remove(name);
1535 }
1536 }
1537 return null;
1538 }
1539
Alan Viveretteecd585a2015-04-13 10:32:51 -07001540 private void putCachedIcon(@NonNull ResourceName name, @NonNull Drawable dr) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001541 synchronized (sSync) {
Alan Viveretteecd585a2015-04-13 10:32:51 -07001542 sIconCache.put(name, new WeakReference<>(dr.getConstantState()));
Romain Guy39fe17c2011-11-30 10:34:07 -08001543 if (DEBUG_ICONS) Log.v(TAG, "Added cached drawable state for " + name + ": " + dr);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001544 }
1545 }
1546
Romain Guy39fe17c2011-11-30 10:34:07 -08001547 static void handlePackageBroadcast(int cmd, String[] pkgList, boolean hasPkgInfo) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001548 boolean immediateGc = false;
Sudheer Shankacc6418f2016-10-13 12:03:44 -07001549 if (cmd == ApplicationThreadConstants.EXTERNAL_STORAGE_UNAVAILABLE) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001550 immediateGc = true;
1551 }
1552 if (pkgList != null && (pkgList.length > 0)) {
1553 boolean needCleanup = false;
1554 for (String ssp : pkgList) {
1555 synchronized (sSync) {
Dianne Hackbornadd005c2013-07-17 18:43:12 -07001556 for (int i=sIconCache.size()-1; i>=0; i--) {
1557 ResourceName nm = sIconCache.keyAt(i);
1558 if (nm.packageName.equals(ssp)) {
1559 //Log.i(TAG, "Removing cached drawable for " + nm);
1560 sIconCache.removeAt(i);
1561 needCleanup = true;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001562 }
1563 }
Dianne Hackbornadd005c2013-07-17 18:43:12 -07001564 for (int i=sStringCache.size()-1; i>=0; i--) {
1565 ResourceName nm = sStringCache.keyAt(i);
1566 if (nm.packageName.equals(ssp)) {
1567 //Log.i(TAG, "Removing cached string for " + nm);
1568 sStringCache.removeAt(i);
1569 needCleanup = true;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001570 }
1571 }
1572 }
1573 }
1574 if (needCleanup || hasPkgInfo) {
1575 if (immediateGc) {
1576 // Schedule an immediate gc.
1577 Runtime.getRuntime().gc();
1578 } else {
1579 ActivityThread.currentActivityThread().scheduleGcIdler();
1580 }
1581 }
1582 }
1583 }
1584
1585 private static final class ResourceName {
1586 final String packageName;
1587 final int iconId;
1588
1589 ResourceName(String _packageName, int _iconId) {
1590 packageName = _packageName;
1591 iconId = _iconId;
1592 }
1593
1594 ResourceName(ApplicationInfo aInfo, int _iconId) {
1595 this(aInfo.packageName, _iconId);
1596 }
1597
1598 ResourceName(ComponentInfo cInfo, int _iconId) {
1599 this(cInfo.applicationInfo.packageName, _iconId);
1600 }
1601
1602 ResourceName(ResolveInfo rInfo, int _iconId) {
1603 this(rInfo.activityInfo.applicationInfo.packageName, _iconId);
1604 }
1605
1606 @Override
1607 public boolean equals(Object o) {
1608 if (this == o) return true;
1609 if (o == null || getClass() != o.getClass()) return false;
1610
1611 ResourceName that = (ResourceName) o;
1612
1613 if (iconId != that.iconId) return false;
1614 return !(packageName != null ?
1615 !packageName.equals(that.packageName) : that.packageName != null);
1616
1617 }
1618
1619 @Override
1620 public int hashCode() {
1621 int result;
1622 result = packageName.hashCode();
1623 result = 31 * result + iconId;
1624 return result;
1625 }
1626
1627 @Override
1628 public String toString() {
1629 return "{ResourceName " + packageName + " / " + iconId + "}";
1630 }
1631 }
1632
1633 private CharSequence getCachedString(ResourceName name) {
1634 synchronized (sSync) {
1635 WeakReference<CharSequence> wr = sStringCache.get(name);
1636 if (wr != null) { // we have the activity
1637 CharSequence cs = wr.get();
1638 if (cs != null) {
1639 return cs;
1640 }
1641 // our entry has been purged
1642 sStringCache.remove(name);
1643 }
1644 }
1645 return null;
1646 }
1647
1648 private void putCachedString(ResourceName name, CharSequence cs) {
1649 synchronized (sSync) {
1650 sStringCache.put(name, new WeakReference<CharSequence>(cs));
1651 }
1652 }
1653
1654 @Override
Tor Norbye7b9c9122013-05-30 16:48:33 -07001655 public CharSequence getText(String packageName, @StringRes int resid,
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001656 ApplicationInfo appInfo) {
1657 ResourceName name = new ResourceName(packageName, resid);
1658 CharSequence text = getCachedString(name);
1659 if (text != null) {
1660 return text;
1661 }
1662 if (appInfo == null) {
1663 try {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001664 appInfo = getApplicationInfo(packageName, sDefaultFlags);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001665 } catch (NameNotFoundException e) {
1666 return null;
1667 }
1668 }
1669 try {
1670 Resources r = getResourcesForApplication(appInfo);
1671 text = r.getText(resid);
1672 putCachedString(name, text);
1673 return text;
1674 } catch (NameNotFoundException e) {
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07001675 Log.w("PackageManager", "Failure retrieving resources for "
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001676 + appInfo.packageName);
1677 } catch (RuntimeException e) {
1678 // If an exception was thrown, fall through to return
1679 // default icon.
1680 Log.w("PackageManager", "Failure retrieving text 0x"
1681 + Integer.toHexString(resid) + " in package "
1682 + packageName, e);
1683 }
1684 return null;
1685 }
1686
1687 @Override
Tor Norbye7b9c9122013-05-30 16:48:33 -07001688 public XmlResourceParser getXml(String packageName, @XmlRes int resid,
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001689 ApplicationInfo appInfo) {
1690 if (appInfo == null) {
1691 try {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001692 appInfo = getApplicationInfo(packageName, sDefaultFlags);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001693 } catch (NameNotFoundException e) {
1694 return null;
1695 }
1696 }
1697 try {
1698 Resources r = getResourcesForApplication(appInfo);
1699 return r.getXml(resid);
1700 } catch (RuntimeException e) {
1701 // If an exception was thrown, fall through to return
1702 // default icon.
1703 Log.w("PackageManager", "Failure retrieving xml 0x"
1704 + Integer.toHexString(resid) + " in package "
1705 + packageName, e);
1706 } catch (NameNotFoundException e) {
Alon Albert3fa51e32010-11-11 09:24:04 -08001707 Log.w("PackageManager", "Failure retrieving resources for "
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001708 + appInfo.packageName);
1709 }
1710 return null;
1711 }
1712
1713 @Override
1714 public CharSequence getApplicationLabel(ApplicationInfo info) {
1715 return info.loadLabel(this);
1716 }
1717
1718 @Override
Nicolas Prevot9a80e532015-09-23 15:49:28 +01001719 public int installExistingPackage(String packageName) throws NameNotFoundException {
Sunny Goyala31a74b2017-05-11 15:59:19 -07001720 return installExistingPackage(packageName, PackageManager.INSTALL_REASON_UNKNOWN);
1721 }
1722
1723 @Override
1724 public int installExistingPackage(String packageName, int installReason)
1725 throws NameNotFoundException {
1726 return installExistingPackageAsUser(packageName, installReason, mContext.getUserId());
Nicolas Prevot9a80e532015-09-23 15:49:28 +01001727 }
1728
1729 @Override
1730 public int installExistingPackageAsUser(String packageName, int userId)
Dianne Hackborn7767eac2012-08-23 18:25:40 -07001731 throws NameNotFoundException {
Sunny Goyala31a74b2017-05-11 15:59:19 -07001732 return installExistingPackageAsUser(packageName, PackageManager.INSTALL_REASON_UNKNOWN,
1733 userId);
1734 }
1735
1736 private int installExistingPackageAsUser(String packageName, int installReason, int userId)
1737 throws NameNotFoundException {
Dianne Hackborn7767eac2012-08-23 18:25:40 -07001738 try {
Todd Kennedybe0b8892017-02-15 14:13:52 -08001739 int res = mPM.installExistingPackageAsUser(packageName, userId, 0 /*installFlags*/,
Sunny Goyala31a74b2017-05-11 15:59:19 -07001740 installReason);
Dianne Hackborn7767eac2012-08-23 18:25:40 -07001741 if (res == INSTALL_FAILED_INVALID_URI) {
1742 throw new NameNotFoundException("Package " + packageName + " doesn't exist");
1743 }
1744 return res;
1745 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001746 throw e.rethrowFromSystemServer();
Dianne Hackborn7767eac2012-08-23 18:25:40 -07001747 }
1748 }
1749
1750 @Override
Kenny Root3a9b5fb2011-09-20 14:15:38 -07001751 public void verifyPendingInstall(int id, int response) {
Kenny Root5ab21572011-07-27 11:11:19 -07001752 try {
Kenny Root3a9b5fb2011-09-20 14:15:38 -07001753 mPM.verifyPendingInstall(id, response);
Kenny Root5ab21572011-07-27 11:11:19 -07001754 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001755 throw e.rethrowFromSystemServer();
Kenny Root5ab21572011-07-27 11:11:19 -07001756 }
1757 }
1758
1759 @Override
rich canningsd9ef3e52012-08-22 14:28:05 -07001760 public void extendVerificationTimeout(int id, int verificationCodeAtTimeout,
1761 long millisecondsToDelay) {
1762 try {
1763 mPM.extendVerificationTimeout(id, verificationCodeAtTimeout, millisecondsToDelay);
1764 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001765 throw e.rethrowFromSystemServer();
rich canningsd9ef3e52012-08-22 14:28:05 -07001766 }
1767 }
1768
1769 @Override
Todd Kennedydfa93ab2016-03-03 15:24:33 -08001770 public void verifyIntentFilter(int id, int verificationCode, List<String> failedDomains) {
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001771 try {
Todd Kennedydfa93ab2016-03-03 15:24:33 -08001772 mPM.verifyIntentFilter(id, verificationCode, failedDomains);
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001773 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001774 throw e.rethrowFromSystemServer();
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001775 }
1776 }
1777
1778 @Override
Jeff Sharkeye06b4d12016-01-06 14:51:50 -07001779 public int getIntentVerificationStatusAsUser(String packageName, int userId) {
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001780 try {
1781 return mPM.getIntentVerificationStatus(packageName, userId);
1782 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001783 throw e.rethrowFromSystemServer();
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001784 }
1785 }
1786
1787 @Override
Jeff Sharkeye06b4d12016-01-06 14:51:50 -07001788 public boolean updateIntentVerificationStatusAsUser(String packageName, int status, int userId) {
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001789 try {
1790 return mPM.updateIntentVerificationStatus(packageName, status, userId);
1791 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001792 throw e.rethrowFromSystemServer();
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001793 }
1794 }
1795
1796 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001797 @SuppressWarnings("unchecked")
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001798 public List<IntentFilterVerificationInfo> getIntentFilterVerifications(String packageName) {
1799 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001800 ParceledListSlice<IntentFilterVerificationInfo> parceledList =
1801 mPM.getIntentFilterVerifications(packageName);
1802 if (parceledList == null) {
1803 return Collections.emptyList();
1804 }
1805 return parceledList.getList();
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001806 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001807 throw e.rethrowFromSystemServer();
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001808 }
1809 }
1810
1811 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001812 @SuppressWarnings("unchecked")
Fabrice Di Meglio07885952015-04-06 19:41:28 -07001813 public List<IntentFilter> getAllIntentFilters(String packageName) {
1814 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001815 ParceledListSlice<IntentFilter> parceledList =
1816 mPM.getAllIntentFilters(packageName);
1817 if (parceledList == null) {
1818 return Collections.emptyList();
1819 }
1820 return parceledList.getList();
Fabrice Di Meglio07885952015-04-06 19:41:28 -07001821 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001822 throw e.rethrowFromSystemServer();
Fabrice Di Meglio07885952015-04-06 19:41:28 -07001823 }
1824 }
1825
1826 @Override
Jeff Sharkeye06b4d12016-01-06 14:51:50 -07001827 public String getDefaultBrowserPackageNameAsUser(int userId) {
Fabrice Di Meglio62271722015-04-10 17:24:02 -07001828 try {
1829 return mPM.getDefaultBrowserPackageName(userId);
1830 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001831 throw e.rethrowFromSystemServer();
Fabrice Di Meglio62271722015-04-10 17:24:02 -07001832 }
1833 }
1834
1835 @Override
Jeff Sharkeye06b4d12016-01-06 14:51:50 -07001836 public boolean setDefaultBrowserPackageNameAsUser(String packageName, int userId) {
Fabrice Di Meglio62271722015-04-10 17:24:02 -07001837 try {
1838 return mPM.setDefaultBrowserPackageName(packageName, userId);
1839 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001840 throw e.rethrowFromSystemServer();
Fabrice Di Meglio62271722015-04-10 17:24:02 -07001841 }
1842 }
1843
1844 @Override
Dianne Hackborn880119b2010-11-18 22:26:40 -08001845 public void setInstallerPackageName(String targetPackage,
1846 String installerPackageName) {
1847 try {
1848 mPM.setInstallerPackageName(targetPackage, installerPackageName);
1849 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001850 throw e.rethrowFromSystemServer();
Dianne Hackborn880119b2010-11-18 22:26:40 -08001851 }
1852 }
1853
1854 @Override
Todd Kennedyab532892017-03-08 14:19:49 -08001855 public void setUpdateAvailable(String packageName, boolean updateAvailable) {
1856 try {
1857 mPM.setUpdateAvailable(packageName, updateAvailable);
1858 } catch (RemoteException e) {
1859 throw e.rethrowFromSystemServer();
1860 }
1861 }
1862
1863 @Override
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001864 public String getInstallerPackageName(String packageName) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001865 try {
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001866 return mPM.getInstallerPackageName(packageName);
1867 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001868 throw e.rethrowFromSystemServer();
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001869 }
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001870 }
1871
1872 @Override
1873 public int getMoveStatus(int moveId) {
1874 try {
1875 return mPM.getMoveStatus(moveId);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001876 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001877 throw e.rethrowFromSystemServer();
Jeff Sharkeyb2b9ab82015-04-05 21:10:42 -07001878 }
1879 }
1880
1881 @Override
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001882 public void registerMoveCallback(MoveCallback callback, Handler handler) {
1883 synchronized (mDelegates) {
1884 final MoveCallbackDelegate delegate = new MoveCallbackDelegate(callback,
1885 handler.getLooper());
1886 try {
1887 mPM.registerMoveCallback(delegate);
1888 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001889 throw e.rethrowFromSystemServer();
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001890 }
1891 mDelegates.add(delegate);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001892 }
1893 }
1894
1895 @Override
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001896 public void unregisterMoveCallback(MoveCallback callback) {
1897 synchronized (mDelegates) {
1898 for (Iterator<MoveCallbackDelegate> i = mDelegates.iterator(); i.hasNext();) {
1899 final MoveCallbackDelegate delegate = i.next();
1900 if (delegate.mCallback == callback) {
1901 try {
1902 mPM.unregisterMoveCallback(delegate);
1903 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001904 throw e.rethrowFromSystemServer();
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001905 }
1906 i.remove();
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001907 }
1908 }
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001909 }
1910 }
1911
1912 @Override
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001913 public int movePackage(String packageName, VolumeInfo vol) {
1914 try {
1915 final String volumeUuid;
1916 if (VolumeInfo.ID_PRIVATE_INTERNAL.equals(vol.id)) {
1917 volumeUuid = StorageManager.UUID_PRIVATE_INTERNAL;
1918 } else if (vol.isPrimaryPhysical()) {
1919 volumeUuid = StorageManager.UUID_PRIMARY_PHYSICAL;
1920 } else {
1921 volumeUuid = Preconditions.checkNotNull(vol.fsUuid);
1922 }
1923
1924 return mPM.movePackage(packageName, volumeUuid);
1925 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001926 throw e.rethrowFromSystemServer();
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001927 }
1928 }
1929
1930 @Override
1931 public @Nullable VolumeInfo getPackageCurrentVolume(ApplicationInfo app) {
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001932 final StorageManager storage = mContext.getSystemService(StorageManager.class);
Yao Chen022b8ea2016-12-16 11:03:28 -08001933 return getPackageCurrentVolume(app, storage);
1934 }
1935
1936 @VisibleForTesting
1937 protected @Nullable VolumeInfo getPackageCurrentVolume(ApplicationInfo app,
1938 StorageManager storage) {
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001939 if (app.isInternal()) {
1940 return storage.findVolumeById(VolumeInfo.ID_PRIVATE_INTERNAL);
1941 } else if (app.isExternalAsec()) {
1942 return storage.getPrimaryPhysicalVolume();
1943 } else {
1944 return storage.findVolumeByUuid(app.volumeUuid);
1945 }
1946 }
1947
1948 @Override
1949 public @NonNull List<VolumeInfo> getPackageCandidateVolumes(ApplicationInfo app) {
Yao Chen022b8ea2016-12-16 11:03:28 -08001950 final StorageManager storageManager = mContext.getSystemService(StorageManager.class);
1951 return getPackageCandidateVolumes(app, storageManager, mPM);
1952 }
1953
1954 @VisibleForTesting
1955 protected @NonNull List<VolumeInfo> getPackageCandidateVolumes(ApplicationInfo app,
1956 StorageManager storageManager, IPackageManager pm) {
1957 final VolumeInfo currentVol = getPackageCurrentVolume(app, storageManager);
1958 final List<VolumeInfo> vols = storageManager.getVolumes();
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001959 final List<VolumeInfo> candidates = new ArrayList<>();
1960 for (VolumeInfo vol : vols) {
Yao Chen022b8ea2016-12-16 11:03:28 -08001961 if (Objects.equals(vol, currentVol)
1962 || isPackageCandidateVolume(mContext, app, vol, pm)) {
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001963 candidates.add(vol);
1964 }
1965 }
1966 return candidates;
1967 }
1968
Yao Chen022b8ea2016-12-16 11:03:28 -08001969 @VisibleForTesting
1970 protected boolean isForceAllowOnExternal(Context context) {
1971 return Settings.Global.getInt(
Todd Kennedyf39ca8f2015-08-07 14:15:07 -07001972 context.getContentResolver(), Settings.Global.FORCE_ALLOW_ON_EXTERNAL, 0) != 0;
Yao Chen022b8ea2016-12-16 11:03:28 -08001973 }
1974
1975 @VisibleForTesting
1976 protected boolean isAllow3rdPartyOnInternal(Context context) {
1977 return context.getResources().getBoolean(
1978 com.android.internal.R.bool.config_allow3rdPartyAppOnInternal);
1979 }
1980
1981 private boolean isPackageCandidateVolume(
1982 ContextImpl context, ApplicationInfo app, VolumeInfo vol, IPackageManager pm) {
1983 final boolean forceAllowOnExternal = isForceAllowOnExternal(context);
1984
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001985 if (VolumeInfo.ID_PRIVATE_INTERNAL.equals(vol.getId())) {
Yao Chen022b8ea2016-12-16 11:03:28 -08001986 return app.isSystemApp() || isAllow3rdPartyOnInternal(context);
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001987 }
1988
1989 // System apps and apps demanding internal storage can't be moved
1990 // anywhere else
Todd Kennedyf39ca8f2015-08-07 14:15:07 -07001991 if (app.isSystemApp()) {
1992 return false;
1993 }
1994 if (!forceAllowOnExternal
Dianne Hackborn30a4e6d2015-10-12 17:14:56 -07001995 && (app.installLocation == PackageInfo.INSTALL_LOCATION_INTERNAL_ONLY
1996 || app.installLocation == PackageInfo.INSTALL_LOCATION_UNSPECIFIED)) {
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001997 return false;
1998 }
1999
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002000 // Gotta be able to write there
2001 if (!vol.isMountedWritable()) {
2002 return false;
2003 }
2004
2005 // Moving into an ASEC on public primary is only option internal
2006 if (vol.isPrimaryPhysical()) {
2007 return app.isInternal();
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07002008 }
2009
Makoto Onukif34db0a2016-02-17 11:17:15 -08002010 // Some apps can't be moved. (e.g. device admins)
2011 try {
Yao Chen022b8ea2016-12-16 11:03:28 -08002012 if (pm.isPackageDeviceAdminOnAnyUser(app.packageName)) {
Makoto Onukif34db0a2016-02-17 11:17:15 -08002013 return false;
2014 }
2015 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002016 throw e.rethrowFromSystemServer();
Makoto Onukif34db0a2016-02-17 11:17:15 -08002017 }
2018
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07002019 // Otherwise we can move to any private volume
2020 return (vol.getType() == VolumeInfo.TYPE_PRIVATE);
2021 }
2022
2023 @Override
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002024 public int movePrimaryStorage(VolumeInfo vol) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002025 try {
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002026 final String volumeUuid;
2027 if (VolumeInfo.ID_PRIVATE_INTERNAL.equals(vol.id)) {
2028 volumeUuid = StorageManager.UUID_PRIVATE_INTERNAL;
2029 } else if (vol.isPrimaryPhysical()) {
2030 volumeUuid = StorageManager.UUID_PRIMARY_PHYSICAL;
2031 } else {
2032 volumeUuid = Preconditions.checkNotNull(vol.fsUuid);
2033 }
2034
2035 return mPM.movePrimaryStorage(volumeUuid);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002036 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002037 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002038 }
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002039 }
2040
Jeff Sharkey275e3e42015-04-24 16:10:32 -07002041 @Override
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002042 public @Nullable VolumeInfo getPrimaryStorageCurrentVolume() {
2043 final StorageManager storage = mContext.getSystemService(StorageManager.class);
2044 final String volumeUuid = storage.getPrimaryStorageUuid();
Jeff Sharkey50a05452015-04-29 11:24:52 -07002045 return storage.findVolumeByQualifiedUuid(volumeUuid);
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 @NonNull List<VolumeInfo> getPrimaryStorageCandidateVolumes() {
2050 final StorageManager storage = mContext.getSystemService(StorageManager.class);
2051 final VolumeInfo currentVol = getPrimaryStorageCurrentVolume();
2052 final List<VolumeInfo> vols = storage.getVolumes();
2053 final List<VolumeInfo> candidates = new ArrayList<>();
Jeff Sharkeyfced5342015-05-10 14:53:34 -07002054 if (Objects.equals(StorageManager.UUID_PRIMARY_PHYSICAL,
2055 storage.getPrimaryStorageUuid()) && currentVol != null) {
2056 // TODO: support moving primary physical to emulated volume
2057 candidates.add(currentVol);
2058 } else {
2059 for (VolumeInfo vol : vols) {
2060 if (Objects.equals(vol, currentVol) || isPrimaryStorageCandidateVolume(vol)) {
2061 candidates.add(vol);
2062 }
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002063 }
2064 }
2065 return candidates;
2066 }
2067
2068 private static boolean isPrimaryStorageCandidateVolume(VolumeInfo vol) {
2069 // Private internal is always an option
2070 if (VolumeInfo.ID_PRIVATE_INTERNAL.equals(vol.getId())) {
2071 return true;
2072 }
2073
2074 // Gotta be able to write there
2075 if (!vol.isMountedWritable()) {
2076 return false;
2077 }
2078
Jeff Sharkeyfced5342015-05-10 14:53:34 -07002079 // We can move to any private volume
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002080 return (vol.getType() == VolumeInfo.TYPE_PRIVATE);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002081 }
2082
2083 @Override
2084 public void deletePackage(String packageName, IPackageDeleteObserver observer, int flags) {
Robin Lee0e27c872015-09-28 14:37:40 +01002085 deletePackageAsUser(packageName, observer, flags, mContext.getUserId());
Nicolas Prevot9a80e532015-09-23 15:49:28 +01002086 }
2087
2088 @Override
Svet Ganov67882122016-12-11 16:36:34 -08002089 public void deletePackageAsUser(String packageName, IPackageDeleteObserver observer,
2090 int flags, int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002091 try {
Svet Ganov67882122016-12-11 16:36:34 -08002092 mPM.deletePackageAsUser(packageName, PackageManager.VERSION_CODE_HIGHEST,
2093 observer, userId, flags);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002094 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002095 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002096 }
2097 }
Jeff Sharkeyfbd0e9f2014-08-06 16:34:34 -07002098
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002099 @Override
2100 public void clearApplicationUserData(String packageName,
2101 IPackageDataObserver observer) {
2102 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -07002103 mPM.clearApplicationUserData(packageName, observer, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002104 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002105 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002106 }
2107 }
2108 @Override
2109 public void deleteApplicationCacheFiles(String packageName,
2110 IPackageDataObserver observer) {
2111 try {
2112 mPM.deleteApplicationCacheFiles(packageName, observer);
2113 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002114 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002115 }
2116 }
Jeff Sharkey529f91f2015-04-18 20:23:13 -07002117
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002118 @Override
Suprabh Shukla78c9eb82016-04-12 15:51:35 -07002119 public void deleteApplicationCacheFilesAsUser(String packageName, int userId,
2120 IPackageDataObserver observer) {
2121 try {
2122 mPM.deleteApplicationCacheFilesAsUser(packageName, userId, observer);
2123 } catch (RemoteException e) {
2124 throw e.rethrowFromSystemServer();
2125 }
2126 }
2127
2128 @Override
Jeff Sharkey529f91f2015-04-18 20:23:13 -07002129 public void freeStorageAndNotify(String volumeUuid, long idealStorageSize,
2130 IPackageDataObserver observer) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002131 try {
Jeff Sharkeyddff8072017-05-26 13:10:46 -06002132 mPM.freeStorageAndNotify(volumeUuid, idealStorageSize, 0, observer);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002133 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002134 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002135 }
2136 }
2137
2138 @Override
Jeff Sharkey529f91f2015-04-18 20:23:13 -07002139 public void freeStorage(String volumeUuid, long freeStorageSize, IntentSender pi) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002140 try {
Jeff Sharkeyddff8072017-05-26 13:10:46 -06002141 mPM.freeStorage(volumeUuid, freeStorageSize, 0, pi);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002142 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002143 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002144 }
2145 }
2146
2147 @Override
Suprabh Shukla021b57a2018-03-08 18:21:50 -08002148 public String[] setPackagesSuspended(String[] packageNames, boolean suspended,
2149 PersistableBundle appExtras, PersistableBundle launcherExtras,
2150 String dialogMessage) {
2151 // TODO (b/75332201): Pass in the dialogMessage and use it in the interceptor dialog
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00002152 try {
Suprabh Shukla021b57a2018-03-08 18:21:50 -08002153 return mPM.setPackagesSuspendedAsUser(packageNames, suspended, appExtras,
2154 launcherExtras, mContext.getOpPackageName(), mContext.getUserId());
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00002155 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002156 throw e.rethrowFromSystemServer();
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00002157 }
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00002158 }
2159
2160 @Override
Suprabh Shukla021b57a2018-03-08 18:21:50 -08002161 public PersistableBundle getSuspendedPackageAppExtras(String packageName) {
2162 try {
2163 return mPM.getPackageSuspendedAppExtras(packageName, mContext.getUserId());
2164 } catch (RemoteException e) {
2165 throw e.rethrowFromSystemServer();
2166 }
2167 }
2168
2169 @Override
2170 public PersistableBundle getSuspendedPackageAppExtras() {
2171 return getSuspendedPackageAppExtras(mContext.getOpPackageName());
2172 }
2173
2174 @Override
2175 public void setSuspendedPackageAppExtras(String packageName, PersistableBundle appExtras) {
2176 try {
2177 mPM.setSuspendedPackageAppExtras(packageName, appExtras, mContext.getUserId());
2178 } catch (RemoteException e) {
2179 e.rethrowFromSystemServer();
2180 }
2181 }
2182
2183 @Override
Andrei Stingaceanu355b2322016-02-12 16:43:51 +00002184 public boolean isPackageSuspendedForUser(String packageName, int userId) {
2185 try {
2186 return mPM.isPackageSuspendedForUser(packageName, userId);
2187 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002188 throw e.rethrowFromSystemServer();
Andrei Stingaceanu355b2322016-02-12 16:43:51 +00002189 }
Andrei Stingaceanu355b2322016-02-12 16:43:51 +00002190 }
2191
Jeff Sharkey9bc89af2017-01-11 11:25:50 -07002192 /** @hide */
2193 @Override
Suprabh Shukla021b57a2018-03-08 18:21:50 -08002194 public boolean isPackageSuspended(String packageName) {
2195 return isPackageSuspendedForUser(packageName, mContext.getUserId());
2196 }
2197
2198 @Override
2199 public boolean isPackageSuspended() {
2200 return isPackageSuspendedForUser(mContext.getOpPackageName(), mContext.getUserId());
2201 }
2202
2203 /** @hide */
2204 @Override
Jeff Sharkey9bc89af2017-01-11 11:25:50 -07002205 public void setApplicationCategoryHint(String packageName, int categoryHint) {
2206 try {
2207 mPM.setApplicationCategoryHint(packageName, categoryHint,
2208 mContext.getOpPackageName());
2209 } catch (RemoteException e) {
2210 throw e.rethrowFromSystemServer();
2211 }
2212 }
2213
Andrei Stingaceanu355b2322016-02-12 16:43:51 +00002214 @Override
Jeff Sharkeye06b4d12016-01-06 14:51:50 -07002215 public void getPackageSizeInfoAsUser(String packageName, int userHandle,
Dianne Hackborn0c380492012-08-20 17:23:30 -07002216 IPackageStatsObserver observer) {
Jeff Sharkey6f4b2a32017-03-21 14:13:41 -06002217 final String msg = "Shame on you for calling the hidden API "
2218 + "getPackageSizeInfoAsUser(). Shame!";
Jeff Sharkeye6306c42017-03-07 21:03:18 -07002219 if (mContext.getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.O) {
Jeff Sharkey6f4b2a32017-03-21 14:13:41 -06002220 throw new UnsupportedOperationException(msg);
Jeff Sharkeye6306c42017-03-07 21:03:18 -07002221 } else if (observer != null) {
Jeff Sharkey6f4b2a32017-03-21 14:13:41 -06002222 Log.d(TAG, msg);
Jeff Sharkeye6306c42017-03-07 21:03:18 -07002223 try {
2224 observer.onGetStatsCompleted(null, false);
2225 } catch (RemoteException ignored) {
2226 }
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002227 }
2228 }
Jeff Sharkeyd5896632016-03-04 16:16:00 -07002229
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002230 @Override
2231 public void addPackageToPreferred(String packageName) {
Jeff Sharkeyd5896632016-03-04 16:16:00 -07002232 Log.w(TAG, "addPackageToPreferred() is a no-op");
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002233 }
2234
2235 @Override
2236 public void removePackageFromPreferred(String packageName) {
Jeff Sharkeyd5896632016-03-04 16:16:00 -07002237 Log.w(TAG, "removePackageFromPreferred() is a no-op");
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002238 }
2239
2240 @Override
2241 public List<PackageInfo> getPreferredPackages(int flags) {
Jeff Sharkeyd5896632016-03-04 16:16:00 -07002242 Log.w(TAG, "getPreferredPackages() is a no-op");
2243 return Collections.emptyList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002244 }
2245
2246 @Override
2247 public void addPreferredActivity(IntentFilter filter,
2248 int match, ComponentName[] set, ComponentName activity) {
2249 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -07002250 mPM.addPreferredActivity(filter, match, set, activity, mContext.getUserId());
Amith Yamasania3f133a2012-08-09 17:11:28 -07002251 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002252 throw e.rethrowFromSystemServer();
Amith Yamasania3f133a2012-08-09 17:11:28 -07002253 }
2254 }
2255
2256 @Override
Jeff Sharkeye06b4d12016-01-06 14:51:50 -07002257 public void addPreferredActivityAsUser(IntentFilter filter, int match,
Amith Yamasania3f133a2012-08-09 17:11:28 -07002258 ComponentName[] set, ComponentName activity, int userId) {
2259 try {
2260 mPM.addPreferredActivity(filter, match, set, activity, userId);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002261 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002262 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002263 }
2264 }
2265
2266 @Override
2267 public void replacePreferredActivity(IntentFilter filter,
2268 int match, ComponentName[] set, ComponentName activity) {
2269 try {
Robin Lee0e27c872015-09-28 14:37:40 +01002270 mPM.replacePreferredActivity(filter, match, set, activity, mContext.getUserId());
Amith Yamasani41c1ded2014-08-05 11:15:05 -07002271 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002272 throw e.rethrowFromSystemServer();
Amith Yamasani41c1ded2014-08-05 11:15:05 -07002273 }
2274 }
2275
2276 @Override
2277 public void replacePreferredActivityAsUser(IntentFilter filter,
2278 int match, ComponentName[] set, ComponentName activity,
2279 int userId) {
2280 try {
2281 mPM.replacePreferredActivity(filter, match, set, activity, userId);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002282 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002283 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002284 }
2285 }
2286
2287 @Override
2288 public void clearPackagePreferredActivities(String packageName) {
2289 try {
2290 mPM.clearPackagePreferredActivities(packageName);
2291 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002292 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002293 }
2294 }
2295
2296 @Override
2297 public int getPreferredActivities(List<IntentFilter> outFilters,
2298 List<ComponentName> outActivities, String packageName) {
2299 try {
2300 return mPM.getPreferredActivities(outFilters, outActivities, packageName);
2301 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002302 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002303 }
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002304 }
2305
2306 @Override
Christopher Tatea2a0850d2013-09-05 16:38:58 -07002307 public ComponentName getHomeActivities(List<ResolveInfo> outActivities) {
2308 try {
2309 return mPM.getHomeActivities(outActivities);
2310 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002311 throw e.rethrowFromSystemServer();
Christopher Tatea2a0850d2013-09-05 16:38:58 -07002312 }
Christopher Tatea2a0850d2013-09-05 16:38:58 -07002313 }
2314
2315 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002316 public void setComponentEnabledSetting(ComponentName componentName,
2317 int newState, int flags) {
2318 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -07002319 mPM.setComponentEnabledSetting(componentName, newState, flags, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002320 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002321 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002322 }
2323 }
2324
2325 @Override
2326 public int getComponentEnabledSetting(ComponentName componentName) {
2327 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -07002328 return mPM.getComponentEnabledSetting(componentName, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002329 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002330 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002331 }
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002332 }
2333
2334 @Override
2335 public void setApplicationEnabledSetting(String packageName,
2336 int newState, int flags) {
2337 try {
Dianne Hackborn3fa3c28a2013-03-26 16:15:41 -07002338 mPM.setApplicationEnabledSetting(packageName, newState, flags,
Dianne Hackborn95d78532013-09-11 09:51:14 -07002339 mContext.getUserId(), mContext.getOpPackageName());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002340 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002341 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002342 }
2343 }
2344
2345 @Override
2346 public int getApplicationEnabledSetting(String packageName) {
2347 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -07002348 return mPM.getApplicationEnabledSetting(packageName, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002349 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002350 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002351 }
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002352 }
2353
Amith Yamasani655d0e22013-06-12 14:19:10 -07002354 @Override
Sudheer Shankabbb3ff22015-07-09 15:39:23 +01002355 public void flushPackageRestrictionsAsUser(int userId) {
2356 try {
2357 mPM.flushPackageRestrictionsAsUser(userId);
2358 } catch (RemoteException e) {
2359 throw e.rethrowFromSystemServer();
2360 }
2361 }
2362
2363 @Override
Amith Yamasanie5bcff62014-07-19 15:44:09 -07002364 public boolean setApplicationHiddenSettingAsUser(String packageName, boolean hidden,
Amith Yamasani655d0e22013-06-12 14:19:10 -07002365 UserHandle user) {
2366 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07002367 return mPM.setApplicationHiddenSettingAsUser(packageName, hidden,
Amith Yamasani655d0e22013-06-12 14:19:10 -07002368 user.getIdentifier());
Jeff Sharkey27b2e692016-02-25 17:40:12 -07002369 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002370 throw e.rethrowFromSystemServer();
Amith Yamasani655d0e22013-06-12 14:19:10 -07002371 }
Amith Yamasani655d0e22013-06-12 14:19:10 -07002372 }
2373
2374 @Override
Amith Yamasanie5bcff62014-07-19 15:44:09 -07002375 public boolean getApplicationHiddenSettingAsUser(String packageName, UserHandle user) {
Amith Yamasani655d0e22013-06-12 14:19:10 -07002376 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07002377 return mPM.getApplicationHiddenSettingAsUser(packageName, user.getIdentifier());
Jeff Sharkey27b2e692016-02-25 17:40:12 -07002378 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002379 throw e.rethrowFromSystemServer();
Amith Yamasani655d0e22013-06-12 14:19:10 -07002380 }
Amith Yamasani655d0e22013-06-12 14:19:10 -07002381 }
2382
dcashmanc6f22492014-08-14 09:54:51 -07002383 /** @hide */
dcashman9d2f4412014-06-09 09:27:54 -07002384 @Override
2385 public KeySet getKeySetByAlias(String packageName, String alias) {
2386 Preconditions.checkNotNull(packageName);
2387 Preconditions.checkNotNull(alias);
dcashman9d2f4412014-06-09 09:27:54 -07002388 try {
Jeff Sharkey27b2e692016-02-25 17:40:12 -07002389 return mPM.getKeySetByAlias(packageName, alias);
dcashman9d2f4412014-06-09 09:27:54 -07002390 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002391 throw e.rethrowFromSystemServer();
dcashman9d2f4412014-06-09 09:27:54 -07002392 }
dcashman9d2f4412014-06-09 09:27:54 -07002393 }
2394
dcashmanc6f22492014-08-14 09:54:51 -07002395 /** @hide */
dcashman9d2f4412014-06-09 09:27:54 -07002396 @Override
2397 public KeySet getSigningKeySet(String packageName) {
2398 Preconditions.checkNotNull(packageName);
dcashman9d2f4412014-06-09 09:27:54 -07002399 try {
Jeff Sharkey27b2e692016-02-25 17:40:12 -07002400 return mPM.getSigningKeySet(packageName);
dcashman9d2f4412014-06-09 09:27:54 -07002401 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002402 throw e.rethrowFromSystemServer();
dcashman9d2f4412014-06-09 09:27:54 -07002403 }
dcashman9d2f4412014-06-09 09:27:54 -07002404 }
2405
dcashmanc6f22492014-08-14 09:54:51 -07002406 /** @hide */
dcashman9d2f4412014-06-09 09:27:54 -07002407 @Override
2408 public boolean isSignedBy(String packageName, KeySet ks) {
2409 Preconditions.checkNotNull(packageName);
2410 Preconditions.checkNotNull(ks);
dcashman9d2f4412014-06-09 09:27:54 -07002411 try {
dcashmanc6f22492014-08-14 09:54:51 -07002412 return mPM.isPackageSignedByKeySet(packageName, ks);
dcashman9d2f4412014-06-09 09:27:54 -07002413 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002414 throw e.rethrowFromSystemServer();
dcashman9d2f4412014-06-09 09:27:54 -07002415 }
2416 }
2417
dcashmanc6f22492014-08-14 09:54:51 -07002418 /** @hide */
dcashman9d2f4412014-06-09 09:27:54 -07002419 @Override
2420 public boolean isSignedByExactly(String packageName, KeySet ks) {
2421 Preconditions.checkNotNull(packageName);
2422 Preconditions.checkNotNull(ks);
dcashman9d2f4412014-06-09 09:27:54 -07002423 try {
dcashmanc6f22492014-08-14 09:54:51 -07002424 return mPM.isPackageSignedByKeySetExactly(packageName, ks);
dcashman9d2f4412014-06-09 09:27:54 -07002425 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002426 throw e.rethrowFromSystemServer();
dcashman9d2f4412014-06-09 09:27:54 -07002427 }
2428 }
2429
Kenny Root0aaa0d92011-09-12 16:42:55 -07002430 /**
2431 * @hide
2432 */
2433 @Override
2434 public VerifierDeviceIdentity getVerifierDeviceIdentity() {
2435 try {
2436 return mPM.getVerifierDeviceIdentity();
2437 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002438 throw e.rethrowFromSystemServer();
Kenny Root0aaa0d92011-09-12 16:42:55 -07002439 }
Kenny Root0aaa0d92011-09-12 16:42:55 -07002440 }
2441
Jeff Hao9f60c082014-10-28 18:51:07 -07002442 /**
2443 * @hide
2444 */
2445 @Override
2446 public boolean isUpgrade() {
2447 try {
2448 return mPM.isUpgrade();
2449 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002450 throw e.rethrowFromSystemServer();
Jeff Hao9f60c082014-10-28 18:51:07 -07002451 }
2452 }
2453
Jeff Sharkey3a44f3f2014-04-28 17:36:31 -07002454 @Override
Jeff Sharkey16c8e3f2014-07-24 17:08:17 -07002455 public PackageInstaller getPackageInstaller() {
2456 synchronized (mLock) {
2457 if (mInstaller == null) {
2458 try {
Svet Ganov67882122016-12-11 16:36:34 -08002459 mInstaller = new PackageInstaller(mPM.getPackageInstaller(),
Jeff Sharkey16c8e3f2014-07-24 17:08:17 -07002460 mContext.getPackageName(), mContext.getUserId());
2461 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002462 throw e.rethrowFromSystemServer();
Jeff Sharkey16c8e3f2014-07-24 17:08:17 -07002463 }
2464 }
2465 return mInstaller;
Jeff Sharkey3a44f3f2014-04-28 17:36:31 -07002466 }
2467 }
2468
Jeff Sharkey6c833e02014-07-14 22:44:30 -07002469 @Override
2470 public boolean isPackageAvailable(String packageName) {
2471 try {
2472 return mPM.isPackageAvailable(packageName, mContext.getUserId());
2473 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002474 throw e.rethrowFromSystemServer();
Jeff Sharkey6c833e02014-07-14 22:44:30 -07002475 }
2476 }
2477
Nicolas Prevotc79586e2014-05-06 12:47:57 +01002478 /**
2479 * @hide
2480 */
2481 @Override
Nicolas Prevot63798c52014-05-27 13:22:38 +01002482 public void addCrossProfileIntentFilter(IntentFilter filter, int sourceUserId, int targetUserId,
2483 int flags) {
Nicolas Prevotc79586e2014-05-06 12:47:57 +01002484 try {
Nicolas Prevot3f7777f2014-07-24 15:58:39 +01002485 mPM.addCrossProfileIntentFilter(filter, mContext.getOpPackageName(),
Nicolas Prevot4b8d5822015-03-05 15:20:49 +00002486 sourceUserId, targetUserId, flags);
Nicolas Prevotc79586e2014-05-06 12:47:57 +01002487 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002488 throw e.rethrowFromSystemServer();
Nicolas Prevotc79586e2014-05-06 12:47:57 +01002489 }
2490 }
2491
2492 /**
2493 * @hide
2494 */
2495 @Override
Nicolas Prevot81948992014-05-16 18:25:26 +01002496 public void clearCrossProfileIntentFilters(int sourceUserId) {
Nicolas Prevotc79586e2014-05-06 12:47:57 +01002497 try {
Nicolas Prevot4b8d5822015-03-05 15:20:49 +00002498 mPM.clearCrossProfileIntentFilters(sourceUserId, mContext.getOpPackageName());
Nicolas Prevotc79586e2014-05-06 12:47:57 +01002499 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002500 throw e.rethrowFromSystemServer();
Nicolas Prevotc79586e2014-05-06 12:47:57 +01002501 }
2502 }
2503
Nicolas Prevot88cc3462014-05-14 14:51:48 +01002504 /**
2505 * @hide
2506 */
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +01002507 public Drawable loadItemIcon(PackageItemInfo itemInfo, ApplicationInfo appInfo) {
Benjamin Franzec2d48b2014-10-01 15:38:43 +01002508 Drawable dr = loadUnbadgedItemIcon(itemInfo, appInfo);
2509 if (itemInfo.showUserIcon != UserHandle.USER_NULL) {
2510 return dr;
2511 }
2512 return getUserBadgedIcon(dr, new UserHandle(mContext.getUserId()));
2513 }
2514
2515 /**
2516 * @hide
2517 */
2518 public Drawable loadUnbadgedItemIcon(PackageItemInfo itemInfo, ApplicationInfo appInfo) {
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +01002519 if (itemInfo.showUserIcon != UserHandle.USER_NULL) {
Alexandra Gherghina64d4dca2014-08-28 18:26:56 +01002520 Bitmap bitmap = getUserManager().getUserIcon(itemInfo.showUserIcon);
2521 if (bitmap == null) {
Tony Mak213955e2017-11-23 16:57:08 +08002522 return UserIcons.getDefaultUserIcon(
2523 mContext.getResources(), itemInfo.showUserIcon, /* light= */ false);
Alexandra Gherghina64d4dca2014-08-28 18:26:56 +01002524 }
2525 return new BitmapDrawable(bitmap);
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +01002526 }
Alexandra Gherghinadb811db2014-08-29 13:43:59 +01002527 Drawable dr = null;
2528 if (itemInfo.packageName != null) {
2529 dr = getDrawable(itemInfo.packageName, itemInfo.icon, appInfo);
2530 }
Alexandra Gherghinaa71e3902014-07-25 20:03:47 +01002531 if (dr == null) {
Alexandra Gherghinaa7093142014-07-30 13:43:39 +01002532 dr = itemInfo.loadDefaultIcon(this);
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +01002533 }
Benjamin Franzec2d48b2014-10-01 15:38:43 +01002534 return dr;
Svetoslavc7d62f02014-09-04 15:39:54 -07002535 }
2536
2537 private Drawable getBadgedDrawable(Drawable drawable, Drawable badgeDrawable,
2538 Rect badgeLocation, boolean tryBadgeInPlace) {
2539 final int badgedWidth = drawable.getIntrinsicWidth();
2540 final int badgedHeight = drawable.getIntrinsicHeight();
2541 final boolean canBadgeInPlace = tryBadgeInPlace
2542 && (drawable instanceof BitmapDrawable)
2543 && ((BitmapDrawable) drawable).getBitmap().isMutable();
2544
2545 final Bitmap bitmap;
2546 if (canBadgeInPlace) {
2547 bitmap = ((BitmapDrawable) drawable).getBitmap();
2548 } else {
2549 bitmap = Bitmap.createBitmap(badgedWidth, badgedHeight, Bitmap.Config.ARGB_8888);
2550 }
2551 Canvas canvas = new Canvas(bitmap);
2552
2553 if (!canBadgeInPlace) {
2554 drawable.setBounds(0, 0, badgedWidth, badgedHeight);
2555 drawable.draw(canvas);
2556 }
2557
2558 if (badgeLocation != null) {
2559 if (badgeLocation.left < 0 || badgeLocation.top < 0
2560 || badgeLocation.width() > badgedWidth || badgeLocation.height() > badgedHeight) {
2561 throw new IllegalArgumentException("Badge location " + badgeLocation
2562 + " not in badged drawable bounds "
2563 + new Rect(0, 0, badgedWidth, badgedHeight));
2564 }
2565 badgeDrawable.setBounds(0, 0, badgeLocation.width(), badgeLocation.height());
2566
2567 canvas.save();
2568 canvas.translate(badgeLocation.left, badgeLocation.top);
2569 badgeDrawable.draw(canvas);
2570 canvas.restore();
2571 } else {
2572 badgeDrawable.setBounds(0, 0, badgedWidth, badgedHeight);
2573 badgeDrawable.draw(canvas);
2574 }
2575
2576 if (!canBadgeInPlace) {
2577 BitmapDrawable mergedDrawable = new BitmapDrawable(mContext.getResources(), bitmap);
2578
2579 if (drawable instanceof BitmapDrawable) {
2580 BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
2581 mergedDrawable.setTargetDensity(bitmapDrawable.getBitmap().getDensity());
2582 }
2583
2584 return mergedDrawable;
2585 }
2586
2587 return drawable;
2588 }
2589
Tony Mak8673b282016-03-21 21:10:59 +00002590 private boolean isManagedProfile(int userId) {
2591 return getUserManager().isManagedProfile(userId);
Nicolas Prevot88cc3462014-05-14 14:51:48 +01002592 }
2593
Bartosz Fabianowskia34f53f2017-01-11 18:08:47 +01002594 /**
2595 * @hide
2596 */
2597 @Override
2598 public int getInstallReason(String packageName, UserHandle user) {
2599 try {
2600 return mPM.getInstallReason(packageName, user.getIdentifier());
2601 } catch (RemoteException e) {
2602 throw e.rethrowFromSystemServer();
2603 }
2604 }
2605
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002606 /** {@hide} */
2607 private static class MoveCallbackDelegate extends IPackageMoveObserver.Stub implements
2608 Handler.Callback {
Jeff Sharkey50a05452015-04-29 11:24:52 -07002609 private static final int MSG_CREATED = 1;
2610 private static final int MSG_STATUS_CHANGED = 2;
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002611
2612 final MoveCallback mCallback;
2613 final Handler mHandler;
2614
2615 public MoveCallbackDelegate(MoveCallback callback, Looper looper) {
2616 mCallback = callback;
2617 mHandler = new Handler(looper, this);
2618 }
2619
2620 @Override
2621 public boolean handleMessage(Message msg) {
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002622 switch (msg.what) {
Jeff Sharkey50a05452015-04-29 11:24:52 -07002623 case MSG_CREATED: {
Jeff Sharkeyb36586a2015-04-27 08:42:28 -07002624 final SomeArgs args = (SomeArgs) msg.obj;
Jeff Sharkey50a05452015-04-29 11:24:52 -07002625 mCallback.onCreated(args.argi1, (Bundle) args.arg2);
Jeff Sharkeyb36586a2015-04-27 08:42:28 -07002626 args.recycle();
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002627 return true;
Jeff Sharkey50a05452015-04-29 11:24:52 -07002628 }
2629 case MSG_STATUS_CHANGED: {
2630 final SomeArgs args = (SomeArgs) msg.obj;
2631 mCallback.onStatusChanged(args.argi1, args.argi2, (long) args.arg3);
2632 args.recycle();
2633 return true;
2634 }
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002635 }
2636 return false;
2637 }
2638
2639 @Override
Jeff Sharkey50a05452015-04-29 11:24:52 -07002640 public void onCreated(int moveId, Bundle extras) {
Jeff Sharkeyb36586a2015-04-27 08:42:28 -07002641 final SomeArgs args = SomeArgs.obtain();
2642 args.argi1 = moveId;
Jeff Sharkey50a05452015-04-29 11:24:52 -07002643 args.arg2 = extras;
2644 mHandler.obtainMessage(MSG_CREATED, args).sendToTarget();
2645 }
2646
2647 @Override
2648 public void onStatusChanged(int moveId, int status, long estMillis) {
2649 final SomeArgs args = SomeArgs.obtain();
2650 args.argi1 = moveId;
2651 args.argi2 = status;
2652 args.arg3 = estMillis;
Jeff Sharkeyb36586a2015-04-27 08:42:28 -07002653 mHandler.obtainMessage(MSG_STATUS_CHANGED, args).sendToTarget();
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002654 }
2655 }
2656
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002657 private final ContextImpl mContext;
2658 private final IPackageManager mPM;
2659
2660 private static final Object sSync = new Object();
Dianne Hackbornadd005c2013-07-17 18:43:12 -07002661 private static ArrayMap<ResourceName, WeakReference<Drawable.ConstantState>> sIconCache
2662 = new ArrayMap<ResourceName, WeakReference<Drawable.ConstantState>>();
2663 private static ArrayMap<ResourceName, WeakReference<CharSequence>> sStringCache
2664 = new ArrayMap<ResourceName, WeakReference<CharSequence>>();
Svetoslavf7c06eb2015-06-10 18:43:22 -07002665
2666 private final Map<OnPermissionsChangedListener, IOnPermissionsChangeListener>
2667 mPermissionListeners = new ArrayMap<>();
2668
2669 public class OnPermissionsChangeListenerDelegate extends IOnPermissionsChangeListener.Stub
2670 implements Handler.Callback{
2671 private static final int MSG_PERMISSIONS_CHANGED = 1;
2672
2673 private final OnPermissionsChangedListener mListener;
2674 private final Handler mHandler;
2675
2676
2677 public OnPermissionsChangeListenerDelegate(OnPermissionsChangedListener listener,
2678 Looper looper) {
2679 mListener = listener;
2680 mHandler = new Handler(looper, this);
2681 }
2682
2683 @Override
2684 public void onPermissionsChanged(int uid) {
2685 mHandler.obtainMessage(MSG_PERMISSIONS_CHANGED, uid, 0).sendToTarget();
2686 }
2687
2688 @Override
2689 public boolean handleMessage(Message msg) {
2690 switch (msg.what) {
2691 case MSG_PERMISSIONS_CHANGED: {
2692 final int uid = msg.arg1;
2693 mListener.onPermissionsChanged(uid);
2694 return true;
2695 }
2696 }
2697 return false;
2698 }
2699 }
Suprabh Shuklaaef25132017-01-23 18:09:03 -08002700
2701 @Override
2702 public boolean canRequestPackageInstalls() {
2703 try {
2704 return mPM.canRequestPackageInstalls(mContext.getPackageName(), mContext.getUserId());
2705 } catch (RemoteException e) {
2706 throw e.rethrowAsRuntimeException();
2707 }
2708 }
Chad Brubaker336ae5b2017-03-24 15:53:09 -07002709
2710 @Override
2711 public ComponentName getInstantAppResolverSettingsComponent() {
2712 try {
2713 return mPM.getInstantAppResolverSettingsComponent();
2714 } catch (RemoteException e) {
2715 throw e.rethrowAsRuntimeException();
2716 }
2717 }
Todd Kennedy801e6592017-04-12 14:10:12 -07002718
2719 @Override
2720 public ComponentName getInstantAppInstallerComponent() {
2721 try {
2722 return mPM.getInstantAppInstallerComponent();
2723 } catch (RemoteException e) {
2724 throw e.rethrowAsRuntimeException();
2725 }
2726 }
Chad Brubaker0d277a72017-04-12 16:56:53 -07002727
2728 @Override
2729 public String getInstantAppAndroidId(String packageName, UserHandle user) {
2730 try {
2731 return mPM.getInstantAppAndroidId(packageName, user.getIdentifier());
2732 } catch (RemoteException e) {
2733 throw e.rethrowAsRuntimeException();
2734 }
2735 }
Calin Juravle3d2af7f2017-04-19 19:56:21 -07002736
2737 private static class DexModuleRegisterResult {
2738 final String dexModulePath;
2739 final boolean success;
2740 final String message;
2741
2742 private DexModuleRegisterResult(String dexModulePath, boolean success, String message) {
2743 this.dexModulePath = dexModulePath;
2744 this.success = success;
2745 this.message = message;
2746 }
2747 }
2748
2749 private static class DexModuleRegisterCallbackDelegate
2750 extends android.content.pm.IDexModuleRegisterCallback.Stub
2751 implements Handler.Callback {
2752 private static final int MSG_DEX_MODULE_REGISTERED = 1;
2753 private final DexModuleRegisterCallback callback;
2754 private final Handler mHandler;
2755
2756 DexModuleRegisterCallbackDelegate(@NonNull DexModuleRegisterCallback callback) {
2757 this.callback = callback;
2758 mHandler = new Handler(Looper.getMainLooper(), this);
2759 }
2760
2761 @Override
2762 public void onDexModuleRegistered(@NonNull String dexModulePath, boolean success,
2763 @Nullable String message)throws RemoteException {
2764 mHandler.obtainMessage(MSG_DEX_MODULE_REGISTERED,
2765 new DexModuleRegisterResult(dexModulePath, success, message)).sendToTarget();
2766 }
2767
2768 @Override
2769 public boolean handleMessage(Message msg) {
2770 if (msg.what != MSG_DEX_MODULE_REGISTERED) {
2771 return false;
2772 }
2773 DexModuleRegisterResult result = (DexModuleRegisterResult)msg.obj;
2774 callback.onDexModuleRegistered(result.dexModulePath, result.success, result.message);
2775 return true;
2776 }
2777 }
2778
2779 @Override
2780 public void registerDexModule(@NonNull String dexModule,
2781 @Nullable DexModuleRegisterCallback callback) {
2782 // Check if this is a shared module by looking if the others can read it.
2783 boolean isSharedModule = false;
2784 try {
2785 StructStat stat = Os.stat(dexModule);
2786 if ((OsConstants.S_IROTH & stat.st_mode) != 0) {
2787 isSharedModule = true;
2788 }
2789 } catch (ErrnoException e) {
2790 callback.onDexModuleRegistered(dexModule, false,
2791 "Could not get stat the module file: " + e.getMessage());
2792 return;
2793 }
2794
2795 // Module path is ok.
2796 // Create the callback delegate to be passed to package manager service.
2797 DexModuleRegisterCallbackDelegate callbackDelegate = null;
2798 if (callback != null) {
2799 callbackDelegate = new DexModuleRegisterCallbackDelegate(callback);
2800 }
2801
2802 // Invoke the package manager service.
2803 try {
2804 mPM.registerDexModule(mContext.getPackageName(), dexModule,
2805 isSharedModule, callbackDelegate);
2806 } catch (RemoteException e) {
2807 throw e.rethrowAsRuntimeException();
2808 }
2809 }
Calin Juravle45f8b292017-11-07 18:49:43 -08002810
2811 @Override
Ben Gruver1ab3d6e2017-12-07 13:45:08 -08002812 public CharSequence getHarmfulAppWarning(String packageName) {
2813 try {
2814 return mPM.getHarmfulAppWarning(packageName, mContext.getUserId());
2815 } catch (RemoteException e) {
2816 throw e.rethrowAsRuntimeException();
2817 }
2818 }
2819
2820 @Override
2821 public void setHarmfulAppWarning(String packageName, CharSequence warning) {
2822 try {
2823 mPM.setHarmfulAppWarning(packageName, warning, mContext.getUserId());
2824 } catch (RemoteException e) {
2825 throw e.rethrowAsRuntimeException();
2826 }
2827 }
2828
2829 @Override
Calin Juravle45f8b292017-11-07 18:49:43 -08002830 public ArtManager getArtManager() {
2831 synchronized (mLock) {
2832 if (mArtManager == null) {
2833 try {
2834 mArtManager = new ArtManager(mPM.getArtManager());
2835 } catch (RemoteException e) {
2836 throw e.rethrowFromSystemServer();
2837 }
2838 }
2839 return mArtManager;
2840 }
2841 }
Makoto Onuki700feef2018-02-15 10:59:41 -08002842
2843 @Override
2844 public String getSystemTextClassifierPackageName() {
2845 try {
2846 return mPM.getSystemTextClassifierPackageName();
2847 } catch (RemoteException e) {
2848 throw e.rethrowAsRuntimeException();
2849 }
2850 }
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002851}