blob: 1dbdb59ebccea2a97b4c7317b5d0dc9504e1830d [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;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080067import android.net.Uri;
Jeff Sharkeye6306c42017-03-07 21:03:18 -070068import android.os.Build;
Jeff Sharkey50a05452015-04-29 11:24:52 -070069import android.os.Bundle;
Jeff Sharkey620b32b2015-04-23 19:36:02 -070070import android.os.Handler;
71import android.os.Looper;
72import android.os.Message;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080073import android.os.Process;
74import android.os.RemoteException;
Jeff Sharkeyb2b9ab82015-04-05 21:10:42 -070075import android.os.SystemProperties;
Amith Yamasani67df64b2012-12-14 12:09:36 -080076import android.os.UserHandle;
Nicolas Prevot88cc3462014-05-14 14:51:48 +010077import android.os.UserManager;
Jeff Sharkeye2d45be2015-04-15 17:14:12 -070078import android.os.storage.StorageManager;
79import android.os.storage.VolumeInfo;
Todd Kennedyf39ca8f2015-08-07 14:15:07 -070080import android.provider.Settings;
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
144 public PackageInfo getPackageInfo(String packageName, int flags)
145 throws NameNotFoundException {
Nicolas Prevot9a80e532015-09-23 15:49:28 +0100146 return getPackageInfoAsUser(packageName, flags, mContext.getUserId());
147 }
148
149 @Override
Svet Ganov67882122016-12-11 16:36:34 -0800150 public PackageInfo getPackageInfo(VersionedPackage versionedPackage, int flags)
151 throws NameNotFoundException {
152 try {
153 PackageInfo pi = mPM.getPackageInfoVersioned(versionedPackage, flags,
154 mContext.getUserId());
155 if (pi != null) {
156 return pi;
157 }
158 } catch (RemoteException e) {
159 throw e.rethrowFromSystemServer();
160 }
161 throw new NameNotFoundException(versionedPackage.toString());
162 }
163
164 @Override
Nicolas Prevot9a80e532015-09-23 15:49:28 +0100165 public PackageInfo getPackageInfoAsUser(String packageName, int flags, int userId)
166 throws NameNotFoundException {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800167 try {
Nicolas Prevot9a80e532015-09-23 15:49:28 +0100168 PackageInfo pi = mPM.getPackageInfo(packageName, flags, userId);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800169 if (pi != null) {
170 return pi;
171 }
172 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700173 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800174 }
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800175 throw new NameNotFoundException(packageName);
176 }
177
178 @Override
179 public String[] currentToCanonicalPackageNames(String[] names) {
180 try {
181 return mPM.currentToCanonicalPackageNames(names);
182 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700183 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800184 }
185 }
186
187 @Override
188 public String[] canonicalToCurrentPackageNames(String[] names) {
189 try {
190 return mPM.canonicalToCurrentPackageNames(names);
191 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700192 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800193 }
194 }
195
196 @Override
197 public Intent getLaunchIntentForPackage(String packageName) {
198 // First see if the package has an INFO activity; the existence of
199 // such an activity is implied to be the desired front-door for the
200 // overall package (such as if it has multiple launcher entries).
201 Intent intentToResolve = new Intent(Intent.ACTION_MAIN);
202 intentToResolve.addCategory(Intent.CATEGORY_INFO);
203 intentToResolve.setPackage(packageName);
Dianne Hackborn19415762010-12-15 00:20:27 -0800204 List<ResolveInfo> ris = queryIntentActivities(intentToResolve, 0);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800205
206 // Otherwise, try to find a main launcher activity.
Dianne Hackborn19415762010-12-15 00:20:27 -0800207 if (ris == null || ris.size() <= 0) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800208 // reuse the intent instance
209 intentToResolve.removeCategory(Intent.CATEGORY_INFO);
210 intentToResolve.addCategory(Intent.CATEGORY_LAUNCHER);
211 intentToResolve.setPackage(packageName);
Dianne Hackborn19415762010-12-15 00:20:27 -0800212 ris = queryIntentActivities(intentToResolve, 0);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800213 }
Dianne Hackborn19415762010-12-15 00:20:27 -0800214 if (ris == null || ris.size() <= 0) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800215 return null;
216 }
217 Intent intent = new Intent(intentToResolve);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800218 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Dianne Hackborn19415762010-12-15 00:20:27 -0800219 intent.setClassName(ris.get(0).activityInfo.packageName,
220 ris.get(0).activityInfo.name);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800221 return intent;
222 }
223
224 @Override
Jose Lima970417c2014-04-10 10:42:19 -0700225 public Intent getLeanbackLaunchIntentForPackage(String packageName) {
226 // Try to find a main leanback_launcher activity.
227 Intent intentToResolve = new Intent(Intent.ACTION_MAIN);
228 intentToResolve.addCategory(Intent.CATEGORY_LEANBACK_LAUNCHER);
229 intentToResolve.setPackage(packageName);
230 List<ResolveInfo> ris = queryIntentActivities(intentToResolve, 0);
231
232 if (ris == null || ris.size() <= 0) {
233 return null;
234 }
235 Intent intent = new Intent(intentToResolve);
236 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
237 intent.setClassName(ris.get(0).activityInfo.packageName,
238 ris.get(0).activityInfo.name);
239 return intent;
240 }
241
242 @Override
Jeff Sharkey8588bc12016-01-06 16:47:42 -0700243 public int[] getPackageGids(String packageName) throws NameNotFoundException {
244 return getPackageGids(packageName, 0);
245 }
246
247 @Override
248 public int[] getPackageGids(String packageName, int flags)
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800249 throws NameNotFoundException {
250 try {
Jeff Sharkeycd654482016-01-08 17:42:11 -0700251 int[] gids = mPM.getPackageGids(packageName, flags, mContext.getUserId());
Svetoslavc6d1c342015-02-26 14:44:43 -0800252 if (gids != null) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800253 return gids;
254 }
255 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700256 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800257 }
258
259 throw new NameNotFoundException(packageName);
260 }
261
262 @Override
Jeff Sharkey8588bc12016-01-06 16:47:42 -0700263 public int getPackageUid(String packageName, int flags) throws NameNotFoundException {
264 return getPackageUidAsUser(packageName, flags, mContext.getUserId());
265 }
266
267 @Override
268 public int getPackageUidAsUser(String packageName, int userId) throws NameNotFoundException {
269 return getPackageUidAsUser(packageName, 0, userId);
270 }
271
272 @Override
273 public int getPackageUidAsUser(String packageName, int flags, int userId)
Dianne Hackborna06de0f2012-12-11 16:34:47 -0800274 throws NameNotFoundException {
275 try {
Jeff Sharkeycd654482016-01-08 17:42:11 -0700276 int uid = mPM.getPackageUid(packageName, flags, userId);
Dianne Hackborna06de0f2012-12-11 16:34:47 -0800277 if (uid >= 0) {
278 return uid;
279 }
280 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700281 throw e.rethrowFromSystemServer();
Dianne Hackborna06de0f2012-12-11 16:34:47 -0800282 }
283
284 throw new NameNotFoundException(packageName);
285 }
286
287 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800288 public PermissionInfo getPermissionInfo(String name, int flags)
289 throws NameNotFoundException {
290 try {
Svetoslav Ganovadb8c522017-07-28 05:46:53 +0000291 PermissionInfo pi = mPM.getPermissionInfo(name,
292 mContext.getOpPackageName(), flags);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800293 if (pi != null) {
294 return pi;
295 }
296 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700297 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800298 }
299
300 throw new NameNotFoundException(name);
301 }
302
303 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700304 @SuppressWarnings("unchecked")
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800305 public List<PermissionInfo> queryPermissionsByGroup(String group, int flags)
306 throws NameNotFoundException {
307 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700308 ParceledListSlice<PermissionInfo> parceledList =
309 mPM.queryPermissionsByGroup(group, flags);
310 if (parceledList != null) {
311 List<PermissionInfo> pi = parceledList.getList();
312 if (pi != null) {
313 return pi;
314 }
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800315 }
316 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700317 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800318 }
319
320 throw new NameNotFoundException(group);
321 }
322
323 @Override
Paul Navin7b89a7b2017-01-26 23:56:08 +0000324 public boolean isPermissionReviewModeEnabled() {
325 return mContext.getResources().getBoolean(
326 com.android.internal.R.bool.config_permissionReviewRequired);
327 }
328
329 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800330 public PermissionGroupInfo getPermissionGroupInfo(String name,
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700331 int flags) throws NameNotFoundException {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800332 try {
333 PermissionGroupInfo pgi = mPM.getPermissionGroupInfo(name, flags);
334 if (pgi != null) {
335 return pgi;
336 }
337 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700338 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800339 }
340
341 throw new NameNotFoundException(name);
342 }
343
344 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700345 @SuppressWarnings("unchecked")
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800346 public List<PermissionGroupInfo> getAllPermissionGroups(int flags) {
347 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700348 ParceledListSlice<PermissionGroupInfo> parceledList =
349 mPM.getAllPermissionGroups(flags);
350 if (parceledList == null) {
351 return Collections.emptyList();
352 }
353 return parceledList.getList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800354 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700355 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800356 }
357 }
358
359 @Override
360 public ApplicationInfo getApplicationInfo(String packageName, int flags)
361 throws NameNotFoundException {
Jeff Sharkeycd654482016-01-08 17:42:11 -0700362 return getApplicationInfoAsUser(packageName, flags, mContext.getUserId());
363 }
364
365 @Override
366 public ApplicationInfo getApplicationInfoAsUser(String packageName, int flags, int userId)
367 throws NameNotFoundException {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800368 try {
Jeff Sharkeycd654482016-01-08 17:42:11 -0700369 ApplicationInfo ai = mPM.getApplicationInfo(packageName, flags, userId);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800370 if (ai != null) {
Narayan Kamathcaa71192014-07-16 11:06:43 +0100371 // This is a temporary hack. Callers must use
372 // createPackageContext(packageName).getApplicationInfo() to
373 // get the right paths.
Tao Baic9a02372016-01-12 15:02:24 -0800374 return maybeAdjustApplicationInfo(ai);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800375 }
376 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700377 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800378 }
379
380 throw new NameNotFoundException(packageName);
381 }
382
Tao Baic9a02372016-01-12 15:02:24 -0800383 private static ApplicationInfo maybeAdjustApplicationInfo(ApplicationInfo info) {
Narayan Kamathcaa71192014-07-16 11:06:43 +0100384 // If we're dealing with a multi-arch application that has both
385 // 32 and 64 bit shared libraries, we might need to choose the secondary
386 // depending on what the current runtime's instruction set is.
387 if (info.primaryCpuAbi != null && info.secondaryCpuAbi != null) {
388 final String runtimeIsa = VMRuntime.getRuntime().vmInstructionSet();
jgu214741cd92014-12-17 17:23:29 -0500389
390 // Get the instruction set that the libraries of secondary Abi is supported.
391 // In presence of a native bridge this might be different than the one secondary Abi used.
392 String secondaryIsa = VMRuntime.getInstructionSet(info.secondaryCpuAbi);
393 final String secondaryDexCodeIsa = SystemProperties.get("ro.dalvik.vm.isa." + secondaryIsa);
394 secondaryIsa = secondaryDexCodeIsa.isEmpty() ? secondaryIsa : secondaryDexCodeIsa;
Narayan Kamathcaa71192014-07-16 11:06:43 +0100395
396 // If the runtimeIsa is the same as the primary isa, then we do nothing.
397 // Everything will be set up correctly because info.nativeLibraryDir will
398 // correspond to the right ISA.
399 if (runtimeIsa.equals(secondaryIsa)) {
Tao Baic9a02372016-01-12 15:02:24 -0800400 ApplicationInfo modified = new ApplicationInfo(info);
401 modified.nativeLibraryDir = info.secondaryNativeLibraryDir;
402 return modified;
Narayan Kamathcaa71192014-07-16 11:06:43 +0100403 }
404 }
Tao Baic9a02372016-01-12 15:02:24 -0800405 return info;
Narayan Kamathcaa71192014-07-16 11:06:43 +0100406 }
407
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800408 @Override
409 public ActivityInfo getActivityInfo(ComponentName className, int flags)
410 throws NameNotFoundException {
411 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700412 ActivityInfo ai = mPM.getActivityInfo(className, flags, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800413 if (ai != null) {
414 return ai;
415 }
416 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700417 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800418 }
419
420 throw new NameNotFoundException(className.toString());
421 }
422
423 @Override
424 public ActivityInfo getReceiverInfo(ComponentName className, int flags)
425 throws NameNotFoundException {
426 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700427 ActivityInfo ai = mPM.getReceiverInfo(className, flags, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800428 if (ai != null) {
429 return ai;
430 }
431 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700432 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800433 }
434
435 throw new NameNotFoundException(className.toString());
436 }
437
438 @Override
439 public ServiceInfo getServiceInfo(ComponentName className, int flags)
440 throws NameNotFoundException {
441 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700442 ServiceInfo si = mPM.getServiceInfo(className, flags, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800443 if (si != null) {
444 return si;
445 }
446 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700447 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800448 }
449
450 throw new NameNotFoundException(className.toString());
451 }
452
453 @Override
454 public ProviderInfo getProviderInfo(ComponentName className, int flags)
455 throws NameNotFoundException {
456 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700457 ProviderInfo pi = mPM.getProviderInfo(className, flags, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800458 if (pi != null) {
459 return pi;
460 }
461 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700462 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800463 }
464
465 throw new NameNotFoundException(className.toString());
466 }
467
468 @Override
469 public String[] getSystemSharedLibraryNames() {
470 try {
471 return mPM.getSystemSharedLibraryNames();
472 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700473 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800474 }
475 }
476
Svet Ganovd7b1f4112016-02-09 18:49:23 -0800477 /** @hide */
478 @Override
Svet Ganov67882122016-12-11 16:36:34 -0800479 public @NonNull List<SharedLibraryInfo> getSharedLibraries(int flags) {
480 return getSharedLibrariesAsUser(flags, mContext.getUserId());
481 }
482
483 /** @hide */
484 @Override
485 @SuppressWarnings("unchecked")
486 public @NonNull List<SharedLibraryInfo> getSharedLibrariesAsUser(int flags, int userId) {
487 try {
488 ParceledListSlice<SharedLibraryInfo> sharedLibs = mPM.getSharedLibraries(
Svet Ganov58c99f02017-05-15 14:07:17 -0700489 mContext.getOpPackageName(), flags, userId);
Svet Ganov67882122016-12-11 16:36:34 -0800490 if (sharedLibs == null) {
491 return Collections.emptyList();
492 }
493 return sharedLibs.getList();
494 } catch (RemoteException e) {
495 throw e.rethrowFromSystemServer();
496 }
497 }
498
499 /** @hide */
500 @Override
Svetoslav Ganova9c25002016-04-13 19:25:56 -0700501 public @NonNull String getServicesSystemSharedLibraryPackageName() {
Svet Ganovd7b1f4112016-02-09 18:49:23 -0800502 try {
503 return mPM.getServicesSystemSharedLibraryPackageName();
504 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700505 throw e.rethrowFromSystemServer();
Svet Ganovd7b1f4112016-02-09 18:49:23 -0800506 }
507 }
508
Svetoslav Ganova9c25002016-04-13 19:25:56 -0700509 /**
510 * @hide
511 */
512 public @NonNull String getSharedSystemSharedLibraryPackageName() {
513 try {
514 return mPM.getSharedSystemSharedLibraryPackageName();
515 } catch (RemoteException e) {
516 throw e.rethrowFromSystemServer();
517 }
518 }
519
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800520 @Override
Todd Kennedy9106c642017-02-08 14:16:53 -0800521 public ChangedPackages getChangedPackages(int sequenceNumber) {
522 try {
523 return mPM.getChangedPackages(sequenceNumber, mContext.getUserId());
524 } catch (RemoteException e) {
525 throw e.rethrowFromSystemServer();
526 }
527 }
528
529 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700530 @SuppressWarnings("unchecked")
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800531 public FeatureInfo[] getSystemAvailableFeatures() {
532 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700533 ParceledListSlice<FeatureInfo> parceledList =
534 mPM.getSystemAvailableFeatures();
535 if (parceledList == null) {
536 return new FeatureInfo[0];
537 }
538 final List<FeatureInfo> list = parceledList.getList();
Jeff Sharkeyd5896632016-03-04 16:16:00 -0700539 final FeatureInfo[] res = new FeatureInfo[list.size()];
540 for (int i = 0; i < res.length; i++) {
541 res[i] = list.get(i);
542 }
543 return res;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800544 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700545 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800546 }
547 }
548
549 @Override
550 public boolean hasSystemFeature(String name) {
Jeff Sharkey115d2c12016-02-15 17:25:57 -0700551 return hasSystemFeature(name, 0);
552 }
553
554 @Override
555 public boolean hasSystemFeature(String name, int version) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800556 try {
Jeff Sharkey115d2c12016-02-15 17:25:57 -0700557 return mPM.hasSystemFeature(name, version);
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 int checkPermission(String permName, String pkgName) {
565 try {
Svetoslavc6d1c342015-02-26 14:44:43 -0800566 return mPM.checkPermission(permName, pkgName, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800567 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700568 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800569 }
570 }
571
572 @Override
Svet Ganovad3b2972015-07-07 22:49:17 -0700573 public boolean isPermissionRevokedByPolicy(String permName, String pkgName) {
574 try {
575 return mPM.isPermissionRevokedByPolicy(permName, pkgName, mContext.getUserId());
576 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700577 throw e.rethrowFromSystemServer();
Svet Ganovad3b2972015-07-07 22:49:17 -0700578 }
579 }
580
Svet Ganovf1b7f202015-07-29 08:33:42 -0700581 /**
582 * @hide
583 */
584 @Override
585 public String getPermissionControllerPackageName() {
586 synchronized (mLock) {
587 if (mPermissionsControllerPackageName == null) {
588 try {
589 mPermissionsControllerPackageName = mPM.getPermissionControllerPackageName();
590 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700591 throw e.rethrowFromSystemServer();
Svet Ganovf1b7f202015-07-29 08:33:42 -0700592 }
593 }
594 return mPermissionsControllerPackageName;
595 }
596 }
597
Svet Ganovad3b2972015-07-07 22:49:17 -0700598 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800599 public boolean addPermission(PermissionInfo info) {
600 try {
601 return mPM.addPermission(info);
602 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700603 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800604 }
605 }
606
607 @Override
608 public boolean addPermissionAsync(PermissionInfo info) {
609 try {
610 return mPM.addPermissionAsync(info);
611 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700612 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800613 }
614 }
615
616 @Override
617 public void removePermission(String name) {
618 try {
619 mPM.removePermission(name);
620 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700621 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800622 }
623 }
624
625 @Override
Svet Ganov8c7f7002015-05-07 10:48:44 -0700626 public void grantRuntimePermission(String packageName, String permissionName,
627 UserHandle user) {
Dianne Hackborne639da72012-02-21 15:11:13 -0800628 try {
Svet Ganov8c7f7002015-05-07 10:48:44 -0700629 mPM.grantRuntimePermission(packageName, permissionName, user.getIdentifier());
Dianne Hackborne639da72012-02-21 15:11:13 -0800630 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700631 throw e.rethrowFromSystemServer();
Dianne Hackborne639da72012-02-21 15:11:13 -0800632 }
633 }
634
635 @Override
Svet Ganov8c7f7002015-05-07 10:48:44 -0700636 public void revokeRuntimePermission(String packageName, String permissionName,
637 UserHandle user) {
Dianne Hackborne639da72012-02-21 15:11:13 -0800638 try {
Svet Ganov8c7f7002015-05-07 10:48:44 -0700639 mPM.revokeRuntimePermission(packageName, permissionName, user.getIdentifier());
640 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700641 throw e.rethrowFromSystemServer();
Svet Ganov8c7f7002015-05-07 10:48:44 -0700642 }
643 }
644
645 @Override
646 public int getPermissionFlags(String permissionName, String packageName, UserHandle user) {
647 try {
648 return mPM.getPermissionFlags(permissionName, packageName, user.getIdentifier());
649 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700650 throw e.rethrowFromSystemServer();
Svet Ganov8c7f7002015-05-07 10:48:44 -0700651 }
652 }
653
654 @Override
655 public void updatePermissionFlags(String permissionName, String packageName,
656 int flagMask, int flagValues, UserHandle user) {
657 try {
658 mPM.updatePermissionFlags(permissionName, packageName, flagMask,
659 flagValues, user.getIdentifier());
Dianne Hackborne639da72012-02-21 15:11:13 -0800660 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700661 throw e.rethrowFromSystemServer();
Dianne Hackborne639da72012-02-21 15:11:13 -0800662 }
663 }
664
665 @Override
Svetoslav20770dd2015-05-29 15:43:04 -0700666 public boolean shouldShowRequestPermissionRationale(String permission) {
667 try {
668 return mPM.shouldShowRequestPermissionRationale(permission,
669 mContext.getPackageName(), mContext.getUserId());
670 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700671 throw e.rethrowFromSystemServer();
Svetoslav20770dd2015-05-29 15:43:04 -0700672 }
673 }
674
675 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800676 public int checkSignatures(String pkg1, String pkg2) {
677 try {
678 return mPM.checkSignatures(pkg1, pkg2);
679 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700680 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800681 }
682 }
683
684 @Override
685 public int checkSignatures(int uid1, int uid2) {
686 try {
687 return mPM.checkUidSignatures(uid1, uid2);
688 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700689 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800690 }
691 }
692
693 @Override
694 public String[] getPackagesForUid(int uid) {
695 try {
696 return mPM.getPackagesForUid(uid);
697 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700698 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800699 }
700 }
701
702 @Override
703 public String getNameForUid(int uid) {
704 try {
705 return mPM.getNameForUid(uid);
706 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700707 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800708 }
709 }
710
711 @Override
Todd Kennedy9da8b8a72017-07-25 15:38:39 -0700712 public String[] getNamesForUids(int[] uids) {
713 try {
714 return mPM.getNamesForUids(uids);
715 } catch (RemoteException e) {
716 throw e.rethrowFromSystemServer();
717 }
718 }
719
720 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800721 public int getUidForSharedUser(String sharedUserName)
722 throws NameNotFoundException {
723 try {
724 int uid = mPM.getUidForSharedUser(sharedUserName);
725 if(uid != -1) {
726 return uid;
727 }
728 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700729 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800730 }
731 throw new NameNotFoundException("No shared userid for user:"+sharedUserName);
732 }
733
Kenny Roote6cd0c72011-05-19 12:48:14 -0700734 @SuppressWarnings("unchecked")
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800735 @Override
736 public List<PackageInfo> getInstalledPackages(int flags) {
Jeff Sharkeye06b4d12016-01-06 14:51:50 -0700737 return getInstalledPackagesAsUser(flags, mContext.getUserId());
Amith Yamasani151ec4c2012-09-07 19:25:16 -0700738 }
739
740 /** @hide */
741 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700742 @SuppressWarnings("unchecked")
Jeff Sharkeye06b4d12016-01-06 14:51:50 -0700743 public List<PackageInfo> getInstalledPackagesAsUser(int flags, int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800744 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700745 ParceledListSlice<PackageInfo> parceledList =
746 mPM.getInstalledPackages(flags, userId);
747 if (parceledList == null) {
748 return Collections.emptyList();
749 }
750 return parceledList.getList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800751 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700752 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800753 }
754 }
755
Kenny Roote6cd0c72011-05-19 12:48:14 -0700756 @SuppressWarnings("unchecked")
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800757 @Override
Dianne Hackborne7991752013-01-16 17:56:46 -0800758 public List<PackageInfo> getPackagesHoldingPermissions(
759 String[] permissions, int flags) {
760 final int userId = mContext.getUserId();
761 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700762 ParceledListSlice<PackageInfo> parceledList =
763 mPM.getPackagesHoldingPermissions(permissions, flags, userId);
764 if (parceledList == null) {
765 return Collections.emptyList();
766 }
767 return parceledList.getList();
Dianne Hackborne7991752013-01-16 17:56:46 -0800768 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700769 throw e.rethrowFromSystemServer();
Dianne Hackborne7991752013-01-16 17:56:46 -0800770 }
771 }
772
773 @SuppressWarnings("unchecked")
774 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800775 public List<ApplicationInfo> getInstalledApplications(int flags) {
Bartosz Fabianowski11334242016-11-17 20:49:16 +0100776 return getInstalledApplicationsAsUser(flags, mContext.getUserId());
777 }
778
779 /** @hide */
780 @SuppressWarnings("unchecked")
781 @Override
782 public List<ApplicationInfo> getInstalledApplicationsAsUser(int flags, int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800783 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700784 ParceledListSlice<ApplicationInfo> parceledList =
785 mPM.getInstalledApplications(flags, userId);
786 if (parceledList == null) {
787 return Collections.emptyList();
788 }
789 return parceledList.getList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800790 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700791 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800792 }
793 }
794
Svet Ganov2acf0632015-11-24 19:10:59 -0800795 /** @hide */
796 @SuppressWarnings("unchecked")
797 @Override
Svetoslav Ganov096d3042017-01-30 16:34:13 -0800798 public List<InstantAppInfo> getInstantApps() {
Svet Ganov2acf0632015-11-24 19:10:59 -0800799 try {
Svetoslav Ganov096d3042017-01-30 16:34:13 -0800800 ParceledListSlice<InstantAppInfo> slice =
801 mPM.getInstantApps(mContext.getUserId());
Svet Ganov2acf0632015-11-24 19:10:59 -0800802 if (slice != null) {
803 return slice.getList();
804 }
805 return Collections.emptyList();
806 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700807 throw e.rethrowFromSystemServer();
Svet Ganov2acf0632015-11-24 19:10:59 -0800808 }
809 }
810
811 /** @hide */
812 @Override
Svetoslav Ganov096d3042017-01-30 16:34:13 -0800813 public Drawable getInstantAppIcon(String packageName) {
Svet Ganov2acf0632015-11-24 19:10:59 -0800814 try {
Svetoslav Ganov096d3042017-01-30 16:34:13 -0800815 Bitmap bitmap = mPM.getInstantAppIcon(
Svet Ganov2acf0632015-11-24 19:10:59 -0800816 packageName, mContext.getUserId());
817 if (bitmap != null) {
818 return new BitmapDrawable(null, bitmap);
819 }
820 return null;
821 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700822 throw e.rethrowFromSystemServer();
Svet Ganov2acf0632015-11-24 19:10:59 -0800823 }
824 }
825
826 @Override
Svetoslav Ganov096d3042017-01-30 16:34:13 -0800827 public boolean isInstantApp() {
David Christie31a16552017-03-01 15:08:45 -0800828 return isInstantApp(mContext.getPackageName());
829 }
830
831 @Override
832 public boolean isInstantApp(String packageName) {
Svet Ganov2acf0632015-11-24 19:10:59 -0800833 try {
David Christie31a16552017-03-01 15:08:45 -0800834 return mPM.isInstantApp(packageName, mContext.getUserId());
Svet Ganov2acf0632015-11-24 19:10:59 -0800835 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700836 throw e.rethrowFromSystemServer();
Svet Ganov2acf0632015-11-24 19:10:59 -0800837 }
Svet Ganov2acf0632015-11-24 19:10:59 -0800838 }
839
Svetoslav Ganov345ffa52017-04-18 16:08:41 -0700840 public int getInstantAppCookieMaxBytes() {
Svet Ganov2acf0632015-11-24 19:10:59 -0800841 return Settings.Global.getInt(mContext.getContentResolver(),
842 Settings.Global.EPHEMERAL_COOKIE_MAX_SIZE_BYTES,
843 DEFAULT_EPHEMERAL_COOKIE_MAX_SIZE_BYTES);
844 }
845
846 @Override
Svetoslav Ganov345ffa52017-04-18 16:08:41 -0700847 public int getInstantAppCookieMaxSize() {
848 return getInstantAppCookieMaxBytes();
849 }
850
851 @Override
Svetoslav Ganov096d3042017-01-30 16:34:13 -0800852 public @NonNull byte[] getInstantAppCookie() {
Svet Ganov2acf0632015-11-24 19:10:59 -0800853 try {
Svetoslav Ganov096d3042017-01-30 16:34:13 -0800854 final byte[] cookie = mPM.getInstantAppCookie(
Svet Ganov2acf0632015-11-24 19:10:59 -0800855 mContext.getPackageName(), mContext.getUserId());
856 if (cookie != null) {
857 return cookie;
Jeff Sharkey27b2e692016-02-25 17:40:12 -0700858 } else {
859 return EmptyArray.BYTE;
Svet Ganov2acf0632015-11-24 19:10:59 -0800860 }
861 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700862 throw e.rethrowFromSystemServer();
Svet Ganov2acf0632015-11-24 19:10:59 -0800863 }
Svet Ganov2acf0632015-11-24 19:10:59 -0800864 }
865
866 @Override
Svetoslav Ganov345ffa52017-04-18 16:08:41 -0700867 public void clearInstantAppCookie() {
868 updateInstantAppCookie(null);
869 }
870
871 @Override
872 public void updateInstantAppCookie(@NonNull byte[] cookie) {
873 if (cookie != null && cookie.length > getInstantAppCookieMaxBytes()) {
874 throw new IllegalArgumentException("instant cookie longer than "
875 + getInstantAppCookieMaxBytes());
876 }
877 try {
878 mPM.setInstantAppCookie(mContext.getPackageName(),
879 cookie, mContext.getUserId());
880 } catch (RemoteException e) {
881 throw e.rethrowFromSystemServer();
882 }
883 }
884
885 @Override
Svetoslav Ganov096d3042017-01-30 16:34:13 -0800886 public boolean setInstantAppCookie(@NonNull byte[] cookie) {
Svet Ganov2acf0632015-11-24 19:10:59 -0800887 try {
Svetoslav Ganov096d3042017-01-30 16:34:13 -0800888 return mPM.setInstantAppCookie(mContext.getPackageName(),
889 cookie, mContext.getUserId());
Svet Ganov2acf0632015-11-24 19:10:59 -0800890 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700891 throw e.rethrowFromSystemServer();
Svet Ganov2acf0632015-11-24 19:10:59 -0800892 }
Svet Ganov2acf0632015-11-24 19:10:59 -0800893 }
894
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800895 @Override
896 public ResolveInfo resolveActivity(Intent intent, int flags) {
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700897 return resolveActivityAsUser(intent, flags, mContext.getUserId());
Svetoslav Ganov58d37b52012-09-18 12:04:19 -0700898 }
899
900 @Override
901 public ResolveInfo resolveActivityAsUser(Intent intent, int flags, int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800902 try {
903 return mPM.resolveIntent(
904 intent,
905 intent.resolveTypeIfNeeded(mContext.getContentResolver()),
Svetoslav Ganov58d37b52012-09-18 12:04:19 -0700906 flags,
907 userId);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800908 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700909 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800910 }
911 }
912
913 @Override
914 public List<ResolveInfo> queryIntentActivities(Intent intent,
915 int flags) {
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700916 return queryIntentActivitiesAsUser(intent, flags, mContext.getUserId());
Amith Yamasani151ec4c2012-09-07 19:25:16 -0700917 }
918
919 /** @hide Same as above but for a specific user */
920 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700921 @SuppressWarnings("unchecked")
Svetoslav Ganov58d37b52012-09-18 12:04:19 -0700922 public List<ResolveInfo> queryIntentActivitiesAsUser(Intent intent,
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700923 int flags, int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800924 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700925 ParceledListSlice<ResolveInfo> parceledList =
926 mPM.queryIntentActivities(intent,
927 intent.resolveTypeIfNeeded(mContext.getContentResolver()),
928 flags, userId);
929 if (parceledList == null) {
930 return Collections.emptyList();
931 }
932 return parceledList.getList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800933 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700934 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800935 }
936 }
937
938 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700939 @SuppressWarnings("unchecked")
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800940 public List<ResolveInfo> queryIntentActivityOptions(
941 ComponentName caller, Intent[] specifics, Intent intent,
942 int flags) {
943 final ContentResolver resolver = mContext.getContentResolver();
944
945 String[] specificTypes = null;
946 if (specifics != null) {
947 final int N = specifics.length;
948 for (int i=0; i<N; i++) {
949 Intent sp = specifics[i];
950 if (sp != null) {
951 String t = sp.resolveTypeIfNeeded(resolver);
952 if (t != null) {
953 if (specificTypes == null) {
954 specificTypes = new String[N];
955 }
956 specificTypes[i] = t;
957 }
958 }
959 }
960 }
961
962 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700963 ParceledListSlice<ResolveInfo> parceledList =
964 mPM.queryIntentActivityOptions(caller, specifics, specificTypes, intent,
965 intent.resolveTypeIfNeeded(resolver), flags, mContext.getUserId());
966 if (parceledList == null) {
967 return Collections.emptyList();
968 }
969 return parceledList.getList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800970 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700971 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800972 }
973 }
974
Amith Yamasanif203aee2012-08-29 18:41:53 -0700975 /**
976 * @hide
977 */
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800978 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700979 @SuppressWarnings("unchecked")
Jeff Sharkeye06b4d12016-01-06 14:51:50 -0700980 public List<ResolveInfo> queryBroadcastReceiversAsUser(Intent intent, int flags, int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800981 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700982 ParceledListSlice<ResolveInfo> parceledList =
983 mPM.queryIntentReceivers(intent,
984 intent.resolveTypeIfNeeded(mContext.getContentResolver()),
985 flags, userId);
986 if (parceledList == null) {
987 return Collections.emptyList();
988 }
989 return parceledList.getList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800990 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700991 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800992 }
993 }
994
995 @Override
Amith Yamasanif203aee2012-08-29 18:41:53 -0700996 public List<ResolveInfo> queryBroadcastReceivers(Intent intent, int flags) {
Jeff Sharkeye06b4d12016-01-06 14:51:50 -0700997 return queryBroadcastReceiversAsUser(intent, flags, mContext.getUserId());
Amith Yamasanif203aee2012-08-29 18:41:53 -0700998 }
999
1000 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001001 public ResolveInfo resolveService(Intent intent, int flags) {
1002 try {
1003 return mPM.resolveService(
1004 intent,
1005 intent.resolveTypeIfNeeded(mContext.getContentResolver()),
Amith Yamasani483f3b02012-03-13 16:08:00 -07001006 flags,
Jeff Sharkeyded653b2012-09-27 19:09:24 -07001007 mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001008 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001009 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001010 }
1011 }
1012
1013 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001014 @SuppressWarnings("unchecked")
Svetoslav Ganov58d37b52012-09-18 12:04:19 -07001015 public List<ResolveInfo> queryIntentServicesAsUser(Intent intent, int flags, int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001016 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001017 ParceledListSlice<ResolveInfo> parceledList =
1018 mPM.queryIntentServices(intent,
1019 intent.resolveTypeIfNeeded(mContext.getContentResolver()),
1020 flags, userId);
1021 if (parceledList == null) {
1022 return Collections.emptyList();
1023 }
1024 return parceledList.getList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001025 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001026 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001027 }
1028 }
1029
1030 @Override
Svetoslav Ganov58d37b52012-09-18 12:04:19 -07001031 public List<ResolveInfo> queryIntentServices(Intent intent, int flags) {
Jeff Sharkeyded653b2012-09-27 19:09:24 -07001032 return queryIntentServicesAsUser(intent, flags, mContext.getUserId());
Svetoslav Ganov58d37b52012-09-18 12:04:19 -07001033 }
1034
1035 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001036 @SuppressWarnings("unchecked")
Jeff Sharkey85f5f812013-10-07 10:16:12 -07001037 public List<ResolveInfo> queryIntentContentProvidersAsUser(
1038 Intent intent, int flags, int userId) {
1039 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001040 ParceledListSlice<ResolveInfo> parceledList =
1041 mPM.queryIntentContentProviders(intent,
1042 intent.resolveTypeIfNeeded(mContext.getContentResolver()),
1043 flags, userId);
1044 if (parceledList == null) {
1045 return Collections.emptyList();
1046 }
1047 return parceledList.getList();
Jeff Sharkey85f5f812013-10-07 10:16:12 -07001048 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001049 throw e.rethrowFromSystemServer();
Jeff Sharkey85f5f812013-10-07 10:16:12 -07001050 }
1051 }
1052
1053 @Override
1054 public List<ResolveInfo> queryIntentContentProviders(Intent intent, int flags) {
1055 return queryIntentContentProvidersAsUser(intent, flags, mContext.getUserId());
1056 }
1057
1058 @Override
Alexandra Gherghina0363c3e2014-06-23 13:34:59 +01001059 public ProviderInfo resolveContentProvider(String name, int flags) {
1060 return resolveContentProviderAsUser(name, flags, mContext.getUserId());
1061 }
1062
1063 /** @hide **/
1064 @Override
1065 public ProviderInfo resolveContentProviderAsUser(String name, int flags, int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001066 try {
Alexandra Gherghina0363c3e2014-06-23 13:34:59 +01001067 return mPM.resolveContentProvider(name, flags, userId);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001068 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001069 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001070 }
1071 }
1072
1073 @Override
1074 public List<ProviderInfo> queryContentProviders(String processName,
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001075 int uid, int flags) {
Makoto Onuki32757292017-02-22 14:36:59 -08001076 return queryContentProviders(processName, uid, flags, null);
1077 }
1078
1079 @Override
1080 @SuppressWarnings("unchecked")
1081 public List<ProviderInfo> queryContentProviders(String processName,
1082 int uid, int flags, String metaDataKey) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001083 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001084 ParceledListSlice<ProviderInfo> slice =
Makoto Onuki32757292017-02-22 14:36:59 -08001085 mPM.queryContentProviders(processName, uid, flags, metaDataKey);
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001086 return slice != null ? slice.getList() : Collections.<ProviderInfo>emptyList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001087 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001088 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001089 }
1090 }
1091
1092 @Override
1093 public InstrumentationInfo getInstrumentationInfo(
1094 ComponentName className, int flags)
1095 throws NameNotFoundException {
1096 try {
1097 InstrumentationInfo ii = mPM.getInstrumentationInfo(
1098 className, flags);
1099 if (ii != null) {
1100 return ii;
1101 }
1102 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001103 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001104 }
1105
1106 throw new NameNotFoundException(className.toString());
1107 }
1108
1109 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001110 @SuppressWarnings("unchecked")
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001111 public List<InstrumentationInfo> queryInstrumentation(
1112 String targetPackage, int flags) {
1113 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001114 ParceledListSlice<InstrumentationInfo> parceledList =
1115 mPM.queryInstrumentation(targetPackage, flags);
1116 if (parceledList == null) {
1117 return Collections.emptyList();
1118 }
1119 return parceledList.getList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001120 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001121 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001122 }
1123 }
1124
Alan Viveretteecd585a2015-04-13 10:32:51 -07001125 @Nullable
1126 @Override
1127 public Drawable getDrawable(String packageName, @DrawableRes int resId,
1128 @Nullable ApplicationInfo appInfo) {
1129 final ResourceName name = new ResourceName(packageName, resId);
1130 final Drawable cachedIcon = getCachedIcon(name);
1131 if (cachedIcon != null) {
1132 return cachedIcon;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001133 }
Alan Viveretteecd585a2015-04-13 10:32:51 -07001134
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001135 if (appInfo == null) {
1136 try {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001137 appInfo = getApplicationInfo(packageName, sDefaultFlags);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001138 } catch (NameNotFoundException e) {
1139 return null;
1140 }
1141 }
Alan Viveretteecd585a2015-04-13 10:32:51 -07001142
1143 if (resId != 0) {
1144 try {
1145 final Resources r = getResourcesForApplication(appInfo);
1146 final Drawable dr = r.getDrawable(resId, null);
1147 if (dr != null) {
1148 putCachedIcon(name, dr);
1149 }
1150
1151 if (false) {
1152 RuntimeException e = new RuntimeException("here");
1153 e.fillInStackTrace();
1154 Log.w(TAG, "Getting drawable 0x" + Integer.toHexString(resId)
1155 + " from package " + packageName
1156 + ": app scale=" + r.getCompatibilityInfo().applicationScale
1157 + ", caller scale=" + mContext.getResources()
1158 .getCompatibilityInfo().applicationScale,
1159 e);
1160 }
Ricky Wai3ce46252015-04-15 16:12:22 +01001161 if (DEBUG_ICONS) {
Alan Viveretteecd585a2015-04-13 10:32:51 -07001162 Log.v(TAG, "Getting drawable 0x"
1163 + Integer.toHexString(resId) + " from " + r
1164 + ": " + dr);
Ricky Wai3ce46252015-04-15 16:12:22 +01001165 }
1166 return dr;
Alan Viveretteecd585a2015-04-13 10:32:51 -07001167 } catch (NameNotFoundException e) {
1168 Log.w("PackageManager", "Failure retrieving resources for "
1169 + appInfo.packageName);
1170 } catch (Resources.NotFoundException e) {
1171 Log.w("PackageManager", "Failure retrieving resources for "
1172 + appInfo.packageName + ": " + e.getMessage());
1173 } catch (Exception e) {
1174 // If an exception was thrown, fall through to return
1175 // default icon.
1176 Log.w("PackageManager", "Failure retrieving icon 0x"
1177 + Integer.toHexString(resId) + " in package "
1178 + packageName, e);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001179 }
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001180 }
Alan Viveretteecd585a2015-04-13 10:32:51 -07001181
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001182 return null;
1183 }
1184
1185 @Override public Drawable getActivityIcon(ComponentName activityName)
1186 throws NameNotFoundException {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001187 return getActivityInfo(activityName, sDefaultFlags).loadIcon(this);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001188 }
1189
1190 @Override public Drawable getActivityIcon(Intent intent)
1191 throws NameNotFoundException {
1192 if (intent.getComponent() != null) {
1193 return getActivityIcon(intent.getComponent());
1194 }
1195
1196 ResolveInfo info = resolveActivity(
1197 intent, PackageManager.MATCH_DEFAULT_ONLY);
1198 if (info != null) {
1199 return info.activityInfo.loadIcon(this);
1200 }
1201
Romain Guy39fe17c2011-11-30 10:34:07 -08001202 throw new NameNotFoundException(intent.toUri(0));
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001203 }
1204
1205 @Override public Drawable getDefaultActivityIcon() {
1206 return Resources.getSystem().getDrawable(
1207 com.android.internal.R.drawable.sym_def_app_icon);
1208 }
1209
1210 @Override public Drawable getApplicationIcon(ApplicationInfo info) {
1211 return info.loadIcon(this);
1212 }
1213
1214 @Override public Drawable getApplicationIcon(String packageName)
1215 throws NameNotFoundException {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001216 return getApplicationIcon(getApplicationInfo(packageName, sDefaultFlags));
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001217 }
1218
1219 @Override
Jose Limaf78e3122014-03-06 12:13:15 -08001220 public Drawable getActivityBanner(ComponentName activityName)
1221 throws NameNotFoundException {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001222 return getActivityInfo(activityName, sDefaultFlags).loadBanner(this);
Jose Limaf78e3122014-03-06 12:13:15 -08001223 }
1224
1225 @Override
1226 public Drawable getActivityBanner(Intent intent)
1227 throws NameNotFoundException {
1228 if (intent.getComponent() != null) {
1229 return getActivityBanner(intent.getComponent());
1230 }
1231
1232 ResolveInfo info = resolveActivity(
1233 intent, PackageManager.MATCH_DEFAULT_ONLY);
1234 if (info != null) {
1235 return info.activityInfo.loadBanner(this);
1236 }
1237
1238 throw new NameNotFoundException(intent.toUri(0));
1239 }
1240
1241 @Override
1242 public Drawable getApplicationBanner(ApplicationInfo info) {
1243 return info.loadBanner(this);
1244 }
1245
1246 @Override
1247 public Drawable getApplicationBanner(String packageName)
1248 throws NameNotFoundException {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001249 return getApplicationBanner(getApplicationInfo(packageName, sDefaultFlags));
Jose Limaf78e3122014-03-06 12:13:15 -08001250 }
1251
1252 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001253 public Drawable getActivityLogo(ComponentName activityName)
1254 throws NameNotFoundException {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001255 return getActivityInfo(activityName, sDefaultFlags).loadLogo(this);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001256 }
1257
1258 @Override
1259 public Drawable getActivityLogo(Intent intent)
1260 throws NameNotFoundException {
1261 if (intent.getComponent() != null) {
1262 return getActivityLogo(intent.getComponent());
1263 }
1264
1265 ResolveInfo info = resolveActivity(
1266 intent, PackageManager.MATCH_DEFAULT_ONLY);
1267 if (info != null) {
1268 return info.activityInfo.loadLogo(this);
1269 }
1270
1271 throw new NameNotFoundException(intent.toUri(0));
1272 }
1273
1274 @Override
1275 public Drawable getApplicationLogo(ApplicationInfo info) {
1276 return info.loadLogo(this);
1277 }
1278
1279 @Override
1280 public Drawable getApplicationLogo(String packageName)
1281 throws NameNotFoundException {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001282 return getApplicationLogo(getApplicationInfo(packageName, sDefaultFlags));
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001283 }
1284
Svetoslavc7d62f02014-09-04 15:39:54 -07001285 @Override
1286 public Drawable getUserBadgedIcon(Drawable icon, UserHandle user) {
Kenny Guy02c89902016-11-15 19:36:38 +00001287 if (!isManagedProfile(user.getIdentifier())) {
Svetoslavc7d62f02014-09-04 15:39:54 -07001288 return icon;
1289 }
Sunny Goyalbab30752017-04-12 15:36:42 -07001290 Drawable badge = new LauncherIcons(mContext).getBadgeDrawable(
1291 com.android.internal.R.drawable.ic_corp_icon_badge_case,
1292 getUserBadgeColor(user));
Kenny Guy02c89902016-11-15 19:36:38 +00001293 return getBadgedDrawable(icon, badge, null, true);
Svetoslavc7d62f02014-09-04 15:39:54 -07001294 }
1295
1296 @Override
1297 public Drawable getUserBadgedDrawableForDensity(Drawable drawable, UserHandle user,
1298 Rect badgeLocation, int badgeDensity) {
1299 Drawable badgeDrawable = getUserBadgeForDensity(user, badgeDensity);
1300 if (badgeDrawable == null) {
1301 return drawable;
1302 }
1303 return getBadgedDrawable(drawable, badgeDrawable, badgeLocation, true);
1304 }
1305
Kenny Guy02c89902016-11-15 19:36:38 +00001306 @VisibleForTesting
1307 public static final int[] CORP_BADGE_LABEL_RES_ID = new int[] {
1308 com.android.internal.R.string.managed_profile_label_badge,
1309 com.android.internal.R.string.managed_profile_label_badge_2,
1310 com.android.internal.R.string.managed_profile_label_badge_3
1311 };
1312
1313 private int getUserBadgeColor(UserHandle user) {
Sunny Goyalbab30752017-04-12 15:36:42 -07001314 return IconDrawableFactory.getUserBadgeColor(getUserManager(), user.getIdentifier());
Kenny Guy02c89902016-11-15 19:36:38 +00001315 }
1316
Svetoslavc7d62f02014-09-04 15:39:54 -07001317 @Override
1318 public Drawable getUserBadgeForDensity(UserHandle user, int density) {
Kenny Guy02c89902016-11-15 19:36:38 +00001319 Drawable badgeColor = getManagedProfileIconForDensity(user,
1320 com.android.internal.R.drawable.ic_corp_badge_color, density);
1321 if (badgeColor == null) {
1322 return null;
1323 }
1324 badgeColor.setTint(getUserBadgeColor(user));
1325 Drawable badgeForeground = getDrawableForDensity(
1326 com.android.internal.R.drawable.ic_corp_badge_case, density);
1327 Drawable badge = new LayerDrawable(
1328 new Drawable[] {badgeColor, badgeForeground });
1329 return badge;
Selim Cineke6ff9462016-01-15 15:07:06 -08001330 }
1331
1332 @Override
1333 public Drawable getUserBadgeForDensityNoBackground(UserHandle user, int density) {
Kenny Guy02c89902016-11-15 19:36:38 +00001334 Drawable badge = getManagedProfileIconForDensity(user,
Vadim Tryshev66ae66a2016-02-18 15:41:21 -08001335 com.android.internal.R.drawable.ic_corp_badge_no_background, density);
Kenny Guy02c89902016-11-15 19:36:38 +00001336 if (badge != null) {
1337 badge.setTint(getUserBadgeColor(user));
1338 }
1339 return badge;
Selim Cineke6ff9462016-01-15 15:07:06 -08001340 }
1341
Vadim Tryshev66ae66a2016-02-18 15:41:21 -08001342 private Drawable getDrawableForDensity(int drawableId, int density) {
1343 if (density <= 0) {
1344 density = mContext.getResources().getDisplayMetrics().densityDpi;
1345 }
1346 return Resources.getSystem().getDrawableForDensity(drawableId, density);
1347 }
1348
1349 private Drawable getManagedProfileIconForDensity(UserHandle user, int drawableId, int density) {
Tony Mak8673b282016-03-21 21:10:59 +00001350 if (isManagedProfile(user.getIdentifier())) {
Vadim Tryshev66ae66a2016-02-18 15:41:21 -08001351 return getDrawableForDensity(drawableId, density);
Svetoslavc7d62f02014-09-04 15:39:54 -07001352 }
1353 return null;
1354 }
1355
1356 @Override
1357 public CharSequence getUserBadgedLabel(CharSequence label, UserHandle user) {
Tony Mak8673b282016-03-21 21:10:59 +00001358 if (isManagedProfile(user.getIdentifier())) {
Kenny Guy02c89902016-11-15 19:36:38 +00001359 int badge = getUserManager().getManagedProfileBadge(user.getIdentifier());
1360 int resourceId = CORP_BADGE_LABEL_RES_ID[badge % CORP_BADGE_LABEL_RES_ID.length];
1361 return Resources.getSystem().getString(resourceId, label);
Svetoslavc7d62f02014-09-04 15:39:54 -07001362 }
1363 return label;
1364 }
1365
Alan Viveretteecd585a2015-04-13 10:32:51 -07001366 @Override
1367 public Resources getResourcesForActivity(ComponentName activityName)
1368 throws NameNotFoundException {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001369 return getResourcesForApplication(
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001370 getActivityInfo(activityName, sDefaultFlags).applicationInfo);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001371 }
1372
Alan Viveretteecd585a2015-04-13 10:32:51 -07001373 @Override
1374 public Resources getResourcesForApplication(@NonNull ApplicationInfo app)
1375 throws NameNotFoundException {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001376 if (app.packageName.equals("system")) {
Adam Lesinskia82b6262017-03-21 16:56:17 -07001377 return mContext.mMainThread.getSystemUiContext().getResources();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001378 }
Jeff Sharkey8a4c9722014-06-16 13:48:42 -07001379 final boolean sameUid = (app.uid == Process.myUid());
Adam Lesinski53fafdf2016-08-03 13:36:39 -07001380 final Resources r = mContext.mMainThread.getTopLevelResources(
Adam Lesinskic82f28a2016-06-08 17:19:09 -07001381 sameUid ? app.sourceDir : app.publicSourceDir,
1382 sameUid ? app.splitSourceDirs : app.splitPublicSourceDirs,
1383 app.resourceDirs, app.sharedLibraryFiles, Display.DEFAULT_DISPLAY,
1384 mContext.mPackageInfo);
Adam Lesinski53fafdf2016-08-03 13:36:39 -07001385 if (r != null) {
1386 return r;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001387 }
Adam Lesinski53fafdf2016-08-03 13:36:39 -07001388 throw new NameNotFoundException("Unable to open " + app.publicSourceDir);
1389
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001390 }
1391
Alan Viveretteecd585a2015-04-13 10:32:51 -07001392 @Override
1393 public Resources getResourcesForApplication(String appPackageName)
1394 throws NameNotFoundException {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001395 return getResourcesForApplication(
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001396 getApplicationInfo(appPackageName, sDefaultFlags));
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001397 }
1398
Amith Yamasani98edc952012-09-25 14:09:27 -07001399 /** @hide */
1400 @Override
1401 public Resources getResourcesForApplicationAsUser(String appPackageName, int userId)
1402 throws NameNotFoundException {
Jeff Sharkeyded653b2012-09-27 19:09:24 -07001403 if (userId < 0) {
1404 throw new IllegalArgumentException(
1405 "Call does not support special user #" + userId);
1406 }
1407 if ("system".equals(appPackageName)) {
Adam Lesinskia82b6262017-03-21 16:56:17 -07001408 return mContext.mMainThread.getSystemUiContext().getResources();
Jeff Sharkeyded653b2012-09-27 19:09:24 -07001409 }
Amith Yamasani98edc952012-09-25 14:09:27 -07001410 try {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001411 ApplicationInfo ai = mPM.getApplicationInfo(appPackageName, sDefaultFlags, userId);
Amith Yamasani98edc952012-09-25 14:09:27 -07001412 if (ai != null) {
1413 return getResourcesForApplication(ai);
1414 }
1415 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001416 throw e.rethrowFromSystemServer();
Amith Yamasani98edc952012-09-25 14:09:27 -07001417 }
1418 throw new NameNotFoundException("Package " + appPackageName + " doesn't exist");
1419 }
1420
Jeff Sharkeycd654482016-01-08 17:42:11 -07001421 volatile int mCachedSafeMode = -1;
1422
1423 @Override
1424 public boolean isSafeMode() {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001425 try {
1426 if (mCachedSafeMode < 0) {
1427 mCachedSafeMode = mPM.isSafeMode() ? 1 : 0;
1428 }
1429 return mCachedSafeMode != 0;
1430 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001431 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001432 }
1433 }
1434
Svetoslavf7c06eb2015-06-10 18:43:22 -07001435 @Override
1436 public void addOnPermissionsChangeListener(OnPermissionsChangedListener listener) {
1437 synchronized (mPermissionListeners) {
1438 if (mPermissionListeners.get(listener) != null) {
1439 return;
1440 }
1441 OnPermissionsChangeListenerDelegate delegate =
1442 new OnPermissionsChangeListenerDelegate(listener, Looper.getMainLooper());
1443 try {
1444 mPM.addOnPermissionsChangeListener(delegate);
1445 mPermissionListeners.put(listener, delegate);
1446 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001447 throw e.rethrowFromSystemServer();
Svetoslavf7c06eb2015-06-10 18:43:22 -07001448 }
1449 }
1450 }
1451
1452 @Override
1453 public void removeOnPermissionsChangeListener(OnPermissionsChangedListener listener) {
1454 synchronized (mPermissionListeners) {
1455 IOnPermissionsChangeListener delegate = mPermissionListeners.get(listener);
1456 if (delegate != null) {
1457 try {
1458 mPM.removeOnPermissionsChangeListener(delegate);
1459 mPermissionListeners.remove(listener);
1460 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001461 throw e.rethrowFromSystemServer();
Svetoslavf7c06eb2015-06-10 18:43:22 -07001462 }
1463 }
1464 }
1465 }
1466
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001467 static void configurationChanged() {
1468 synchronized (sSync) {
1469 sIconCache.clear();
1470 sStringCache.clear();
1471 }
1472 }
1473
Yao Chen022b8ea2016-12-16 11:03:28 -08001474 protected ApplicationPackageManager(ContextImpl context,
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001475 IPackageManager pm) {
1476 mContext = context;
1477 mPM = pm;
1478 }
1479
Alan Viveretteecd585a2015-04-13 10:32:51 -07001480 @Nullable
1481 private Drawable getCachedIcon(@NonNull ResourceName name) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001482 synchronized (sSync) {
Alan Viveretteecd585a2015-04-13 10:32:51 -07001483 final WeakReference<Drawable.ConstantState> wr = sIconCache.get(name);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001484 if (DEBUG_ICONS) Log.v(TAG, "Get cached weak drawable ref for "
1485 + name + ": " + wr);
1486 if (wr != null) { // we have the activity
Alan Viveretteecd585a2015-04-13 10:32:51 -07001487 final Drawable.ConstantState state = wr.get();
Romain Guy39fe17c2011-11-30 10:34:07 -08001488 if (state != null) {
1489 if (DEBUG_ICONS) {
1490 Log.v(TAG, "Get cached drawable state for " + name + ": " + state);
1491 }
1492 // Note: It's okay here to not use the newDrawable(Resources) variant
1493 // of the API. The ConstantState comes from a drawable that was
1494 // originally created by passing the proper app Resources instance
1495 // which means the state should already contain the proper
1496 // resources specific information (like density.) See
1497 // BitmapDrawable.BitmapState for instance.
1498 return state.newDrawable();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001499 }
1500 // our entry has been purged
1501 sIconCache.remove(name);
1502 }
1503 }
1504 return null;
1505 }
1506
Alan Viveretteecd585a2015-04-13 10:32:51 -07001507 private void putCachedIcon(@NonNull ResourceName name, @NonNull Drawable dr) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001508 synchronized (sSync) {
Alan Viveretteecd585a2015-04-13 10:32:51 -07001509 sIconCache.put(name, new WeakReference<>(dr.getConstantState()));
Romain Guy39fe17c2011-11-30 10:34:07 -08001510 if (DEBUG_ICONS) Log.v(TAG, "Added cached drawable state for " + name + ": " + dr);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001511 }
1512 }
1513
Romain Guy39fe17c2011-11-30 10:34:07 -08001514 static void handlePackageBroadcast(int cmd, String[] pkgList, boolean hasPkgInfo) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001515 boolean immediateGc = false;
Sudheer Shankacc6418f2016-10-13 12:03:44 -07001516 if (cmd == ApplicationThreadConstants.EXTERNAL_STORAGE_UNAVAILABLE) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001517 immediateGc = true;
1518 }
1519 if (pkgList != null && (pkgList.length > 0)) {
1520 boolean needCleanup = false;
1521 for (String ssp : pkgList) {
1522 synchronized (sSync) {
Dianne Hackbornadd005c2013-07-17 18:43:12 -07001523 for (int i=sIconCache.size()-1; i>=0; i--) {
1524 ResourceName nm = sIconCache.keyAt(i);
1525 if (nm.packageName.equals(ssp)) {
1526 //Log.i(TAG, "Removing cached drawable for " + nm);
1527 sIconCache.removeAt(i);
1528 needCleanup = true;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001529 }
1530 }
Dianne Hackbornadd005c2013-07-17 18:43:12 -07001531 for (int i=sStringCache.size()-1; i>=0; i--) {
1532 ResourceName nm = sStringCache.keyAt(i);
1533 if (nm.packageName.equals(ssp)) {
1534 //Log.i(TAG, "Removing cached string for " + nm);
1535 sStringCache.removeAt(i);
1536 needCleanup = true;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001537 }
1538 }
1539 }
1540 }
1541 if (needCleanup || hasPkgInfo) {
1542 if (immediateGc) {
1543 // Schedule an immediate gc.
1544 Runtime.getRuntime().gc();
1545 } else {
1546 ActivityThread.currentActivityThread().scheduleGcIdler();
1547 }
1548 }
1549 }
1550 }
1551
1552 private static final class ResourceName {
1553 final String packageName;
1554 final int iconId;
1555
1556 ResourceName(String _packageName, int _iconId) {
1557 packageName = _packageName;
1558 iconId = _iconId;
1559 }
1560
1561 ResourceName(ApplicationInfo aInfo, int _iconId) {
1562 this(aInfo.packageName, _iconId);
1563 }
1564
1565 ResourceName(ComponentInfo cInfo, int _iconId) {
1566 this(cInfo.applicationInfo.packageName, _iconId);
1567 }
1568
1569 ResourceName(ResolveInfo rInfo, int _iconId) {
1570 this(rInfo.activityInfo.applicationInfo.packageName, _iconId);
1571 }
1572
1573 @Override
1574 public boolean equals(Object o) {
1575 if (this == o) return true;
1576 if (o == null || getClass() != o.getClass()) return false;
1577
1578 ResourceName that = (ResourceName) o;
1579
1580 if (iconId != that.iconId) return false;
1581 return !(packageName != null ?
1582 !packageName.equals(that.packageName) : that.packageName != null);
1583
1584 }
1585
1586 @Override
1587 public int hashCode() {
1588 int result;
1589 result = packageName.hashCode();
1590 result = 31 * result + iconId;
1591 return result;
1592 }
1593
1594 @Override
1595 public String toString() {
1596 return "{ResourceName " + packageName + " / " + iconId + "}";
1597 }
1598 }
1599
1600 private CharSequence getCachedString(ResourceName name) {
1601 synchronized (sSync) {
1602 WeakReference<CharSequence> wr = sStringCache.get(name);
1603 if (wr != null) { // we have the activity
1604 CharSequence cs = wr.get();
1605 if (cs != null) {
1606 return cs;
1607 }
1608 // our entry has been purged
1609 sStringCache.remove(name);
1610 }
1611 }
1612 return null;
1613 }
1614
1615 private void putCachedString(ResourceName name, CharSequence cs) {
1616 synchronized (sSync) {
1617 sStringCache.put(name, new WeakReference<CharSequence>(cs));
1618 }
1619 }
1620
1621 @Override
Tor Norbye7b9c9122013-05-30 16:48:33 -07001622 public CharSequence getText(String packageName, @StringRes int resid,
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001623 ApplicationInfo appInfo) {
1624 ResourceName name = new ResourceName(packageName, resid);
1625 CharSequence text = getCachedString(name);
1626 if (text != null) {
1627 return text;
1628 }
1629 if (appInfo == null) {
1630 try {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001631 appInfo = getApplicationInfo(packageName, sDefaultFlags);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001632 } catch (NameNotFoundException e) {
1633 return null;
1634 }
1635 }
1636 try {
1637 Resources r = getResourcesForApplication(appInfo);
1638 text = r.getText(resid);
1639 putCachedString(name, text);
1640 return text;
1641 } catch (NameNotFoundException e) {
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07001642 Log.w("PackageManager", "Failure retrieving resources for "
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001643 + appInfo.packageName);
1644 } catch (RuntimeException e) {
1645 // If an exception was thrown, fall through to return
1646 // default icon.
1647 Log.w("PackageManager", "Failure retrieving text 0x"
1648 + Integer.toHexString(resid) + " in package "
1649 + packageName, e);
1650 }
1651 return null;
1652 }
1653
1654 @Override
Tor Norbye7b9c9122013-05-30 16:48:33 -07001655 public XmlResourceParser getXml(String packageName, @XmlRes int resid,
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001656 ApplicationInfo appInfo) {
1657 if (appInfo == null) {
1658 try {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001659 appInfo = getApplicationInfo(packageName, sDefaultFlags);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001660 } catch (NameNotFoundException e) {
1661 return null;
1662 }
1663 }
1664 try {
1665 Resources r = getResourcesForApplication(appInfo);
1666 return r.getXml(resid);
1667 } catch (RuntimeException e) {
1668 // If an exception was thrown, fall through to return
1669 // default icon.
1670 Log.w("PackageManager", "Failure retrieving xml 0x"
1671 + Integer.toHexString(resid) + " in package "
1672 + packageName, e);
1673 } catch (NameNotFoundException e) {
Alon Albert3fa51e32010-11-11 09:24:04 -08001674 Log.w("PackageManager", "Failure retrieving resources for "
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001675 + appInfo.packageName);
1676 }
1677 return null;
1678 }
1679
1680 @Override
1681 public CharSequence getApplicationLabel(ApplicationInfo info) {
1682 return info.loadLabel(this);
1683 }
1684
1685 @Override
Philip P. Moltmannb13f1532017-11-14 08:34:06 -08001686 public void installPackage(Uri packageURI,
1687 PackageInstallObserver observer, int flags, String installerPackageName) {
Jeff Sharkey513a0742014-07-08 17:10:32 -07001688 if (!"file".equals(packageURI.getScheme())) {
1689 throw new UnsupportedOperationException("Only file:// URIs are supported");
1690 }
Jeff Sharkey513a0742014-07-08 17:10:32 -07001691
1692 final String originPath = packageURI.getPath();
Christopher Tatef1977b42014-03-24 16:25:51 -07001693 try {
Nicolas Prevot9a80e532015-09-23 15:49:28 +01001694 mPM.installPackageAsUser(originPath, observer.getBinder(), flags, installerPackageName,
Philip P. Moltmannb13f1532017-11-14 08:34:06 -08001695 mContext.getUserId());
Jeff Sharkey27b2e692016-02-25 17:40:12 -07001696 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001697 throw e.rethrowFromSystemServer();
rich cannings706e8ba2012-08-20 13:20:14 -07001698 }
1699 }
1700
1701 @Override
Nicolas Prevot9a80e532015-09-23 15:49:28 +01001702 public int installExistingPackage(String packageName) throws NameNotFoundException {
Sunny Goyala31a74b2017-05-11 15:59:19 -07001703 return installExistingPackage(packageName, PackageManager.INSTALL_REASON_UNKNOWN);
1704 }
1705
1706 @Override
1707 public int installExistingPackage(String packageName, int installReason)
1708 throws NameNotFoundException {
1709 return installExistingPackageAsUser(packageName, installReason, mContext.getUserId());
Nicolas Prevot9a80e532015-09-23 15:49:28 +01001710 }
1711
1712 @Override
1713 public int installExistingPackageAsUser(String packageName, int userId)
Dianne Hackborn7767eac2012-08-23 18:25:40 -07001714 throws NameNotFoundException {
Sunny Goyala31a74b2017-05-11 15:59:19 -07001715 return installExistingPackageAsUser(packageName, PackageManager.INSTALL_REASON_UNKNOWN,
1716 userId);
1717 }
1718
1719 private int installExistingPackageAsUser(String packageName, int installReason, int userId)
1720 throws NameNotFoundException {
Dianne Hackborn7767eac2012-08-23 18:25:40 -07001721 try {
Todd Kennedybe0b8892017-02-15 14:13:52 -08001722 int res = mPM.installExistingPackageAsUser(packageName, userId, 0 /*installFlags*/,
Sunny Goyala31a74b2017-05-11 15:59:19 -07001723 installReason);
Dianne Hackborn7767eac2012-08-23 18:25:40 -07001724 if (res == INSTALL_FAILED_INVALID_URI) {
1725 throw new NameNotFoundException("Package " + packageName + " doesn't exist");
1726 }
1727 return res;
1728 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001729 throw e.rethrowFromSystemServer();
Dianne Hackborn7767eac2012-08-23 18:25:40 -07001730 }
1731 }
1732
1733 @Override
Kenny Root3a9b5fb2011-09-20 14:15:38 -07001734 public void verifyPendingInstall(int id, int response) {
Kenny Root5ab21572011-07-27 11:11:19 -07001735 try {
Kenny Root3a9b5fb2011-09-20 14:15:38 -07001736 mPM.verifyPendingInstall(id, response);
Kenny Root5ab21572011-07-27 11:11:19 -07001737 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001738 throw e.rethrowFromSystemServer();
Kenny Root5ab21572011-07-27 11:11:19 -07001739 }
1740 }
1741
1742 @Override
rich canningsd9ef3e52012-08-22 14:28:05 -07001743 public void extendVerificationTimeout(int id, int verificationCodeAtTimeout,
1744 long millisecondsToDelay) {
1745 try {
1746 mPM.extendVerificationTimeout(id, verificationCodeAtTimeout, millisecondsToDelay);
1747 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001748 throw e.rethrowFromSystemServer();
rich canningsd9ef3e52012-08-22 14:28:05 -07001749 }
1750 }
1751
1752 @Override
Todd Kennedydfa93ab2016-03-03 15:24:33 -08001753 public void verifyIntentFilter(int id, int verificationCode, List<String> failedDomains) {
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001754 try {
Todd Kennedydfa93ab2016-03-03 15:24:33 -08001755 mPM.verifyIntentFilter(id, verificationCode, failedDomains);
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001756 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001757 throw e.rethrowFromSystemServer();
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001758 }
1759 }
1760
1761 @Override
Jeff Sharkeye06b4d12016-01-06 14:51:50 -07001762 public int getIntentVerificationStatusAsUser(String packageName, int userId) {
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001763 try {
1764 return mPM.getIntentVerificationStatus(packageName, userId);
1765 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001766 throw e.rethrowFromSystemServer();
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001767 }
1768 }
1769
1770 @Override
Jeff Sharkeye06b4d12016-01-06 14:51:50 -07001771 public boolean updateIntentVerificationStatusAsUser(String packageName, int status, int userId) {
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001772 try {
1773 return mPM.updateIntentVerificationStatus(packageName, status, userId);
1774 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001775 throw e.rethrowFromSystemServer();
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001776 }
1777 }
1778
1779 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001780 @SuppressWarnings("unchecked")
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001781 public List<IntentFilterVerificationInfo> getIntentFilterVerifications(String packageName) {
1782 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001783 ParceledListSlice<IntentFilterVerificationInfo> parceledList =
1784 mPM.getIntentFilterVerifications(packageName);
1785 if (parceledList == null) {
1786 return Collections.emptyList();
1787 }
1788 return parceledList.getList();
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001789 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001790 throw e.rethrowFromSystemServer();
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001791 }
1792 }
1793
1794 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001795 @SuppressWarnings("unchecked")
Fabrice Di Meglio07885952015-04-06 19:41:28 -07001796 public List<IntentFilter> getAllIntentFilters(String packageName) {
1797 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001798 ParceledListSlice<IntentFilter> parceledList =
1799 mPM.getAllIntentFilters(packageName);
1800 if (parceledList == null) {
1801 return Collections.emptyList();
1802 }
1803 return parceledList.getList();
Fabrice Di Meglio07885952015-04-06 19:41:28 -07001804 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001805 throw e.rethrowFromSystemServer();
Fabrice Di Meglio07885952015-04-06 19:41:28 -07001806 }
1807 }
1808
1809 @Override
Jeff Sharkeye06b4d12016-01-06 14:51:50 -07001810 public String getDefaultBrowserPackageNameAsUser(int userId) {
Fabrice Di Meglio62271722015-04-10 17:24:02 -07001811 try {
1812 return mPM.getDefaultBrowserPackageName(userId);
1813 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001814 throw e.rethrowFromSystemServer();
Fabrice Di Meglio62271722015-04-10 17:24:02 -07001815 }
1816 }
1817
1818 @Override
Jeff Sharkeye06b4d12016-01-06 14:51:50 -07001819 public boolean setDefaultBrowserPackageNameAsUser(String packageName, int userId) {
Fabrice Di Meglio62271722015-04-10 17:24:02 -07001820 try {
1821 return mPM.setDefaultBrowserPackageName(packageName, userId);
1822 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001823 throw e.rethrowFromSystemServer();
Fabrice Di Meglio62271722015-04-10 17:24:02 -07001824 }
1825 }
1826
1827 @Override
Dianne Hackborn880119b2010-11-18 22:26:40 -08001828 public void setInstallerPackageName(String targetPackage,
1829 String installerPackageName) {
1830 try {
1831 mPM.setInstallerPackageName(targetPackage, installerPackageName);
1832 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001833 throw e.rethrowFromSystemServer();
Dianne Hackborn880119b2010-11-18 22:26:40 -08001834 }
1835 }
1836
1837 @Override
Todd Kennedyab532892017-03-08 14:19:49 -08001838 public void setUpdateAvailable(String packageName, boolean updateAvailable) {
1839 try {
1840 mPM.setUpdateAvailable(packageName, updateAvailable);
1841 } catch (RemoteException e) {
1842 throw e.rethrowFromSystemServer();
1843 }
1844 }
1845
1846 @Override
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001847 public String getInstallerPackageName(String packageName) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001848 try {
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001849 return mPM.getInstallerPackageName(packageName);
1850 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001851 throw e.rethrowFromSystemServer();
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001852 }
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001853 }
1854
1855 @Override
1856 public int getMoveStatus(int moveId) {
1857 try {
1858 return mPM.getMoveStatus(moveId);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001859 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001860 throw e.rethrowFromSystemServer();
Jeff Sharkeyb2b9ab82015-04-05 21:10:42 -07001861 }
1862 }
1863
1864 @Override
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001865 public void registerMoveCallback(MoveCallback callback, Handler handler) {
1866 synchronized (mDelegates) {
1867 final MoveCallbackDelegate delegate = new MoveCallbackDelegate(callback,
1868 handler.getLooper());
1869 try {
1870 mPM.registerMoveCallback(delegate);
1871 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001872 throw e.rethrowFromSystemServer();
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001873 }
1874 mDelegates.add(delegate);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001875 }
1876 }
1877
1878 @Override
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001879 public void unregisterMoveCallback(MoveCallback callback) {
1880 synchronized (mDelegates) {
1881 for (Iterator<MoveCallbackDelegate> i = mDelegates.iterator(); i.hasNext();) {
1882 final MoveCallbackDelegate delegate = i.next();
1883 if (delegate.mCallback == callback) {
1884 try {
1885 mPM.unregisterMoveCallback(delegate);
1886 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001887 throw e.rethrowFromSystemServer();
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001888 }
1889 i.remove();
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001890 }
1891 }
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001892 }
1893 }
1894
1895 @Override
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001896 public int movePackage(String packageName, VolumeInfo vol) {
1897 try {
1898 final String volumeUuid;
1899 if (VolumeInfo.ID_PRIVATE_INTERNAL.equals(vol.id)) {
1900 volumeUuid = StorageManager.UUID_PRIVATE_INTERNAL;
1901 } else if (vol.isPrimaryPhysical()) {
1902 volumeUuid = StorageManager.UUID_PRIMARY_PHYSICAL;
1903 } else {
1904 volumeUuid = Preconditions.checkNotNull(vol.fsUuid);
1905 }
1906
1907 return mPM.movePackage(packageName, volumeUuid);
1908 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001909 throw e.rethrowFromSystemServer();
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001910 }
1911 }
1912
1913 @Override
1914 public @Nullable VolumeInfo getPackageCurrentVolume(ApplicationInfo app) {
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001915 final StorageManager storage = mContext.getSystemService(StorageManager.class);
Yao Chen022b8ea2016-12-16 11:03:28 -08001916 return getPackageCurrentVolume(app, storage);
1917 }
1918
1919 @VisibleForTesting
1920 protected @Nullable VolumeInfo getPackageCurrentVolume(ApplicationInfo app,
1921 StorageManager storage) {
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001922 if (app.isInternal()) {
1923 return storage.findVolumeById(VolumeInfo.ID_PRIVATE_INTERNAL);
1924 } else if (app.isExternalAsec()) {
1925 return storage.getPrimaryPhysicalVolume();
1926 } else {
1927 return storage.findVolumeByUuid(app.volumeUuid);
1928 }
1929 }
1930
1931 @Override
1932 public @NonNull List<VolumeInfo> getPackageCandidateVolumes(ApplicationInfo app) {
Yao Chen022b8ea2016-12-16 11:03:28 -08001933 final StorageManager storageManager = mContext.getSystemService(StorageManager.class);
1934 return getPackageCandidateVolumes(app, storageManager, mPM);
1935 }
1936
1937 @VisibleForTesting
1938 protected @NonNull List<VolumeInfo> getPackageCandidateVolumes(ApplicationInfo app,
1939 StorageManager storageManager, IPackageManager pm) {
1940 final VolumeInfo currentVol = getPackageCurrentVolume(app, storageManager);
1941 final List<VolumeInfo> vols = storageManager.getVolumes();
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001942 final List<VolumeInfo> candidates = new ArrayList<>();
1943 for (VolumeInfo vol : vols) {
Yao Chen022b8ea2016-12-16 11:03:28 -08001944 if (Objects.equals(vol, currentVol)
1945 || isPackageCandidateVolume(mContext, app, vol, pm)) {
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001946 candidates.add(vol);
1947 }
1948 }
1949 return candidates;
1950 }
1951
Yao Chen022b8ea2016-12-16 11:03:28 -08001952 @VisibleForTesting
1953 protected boolean isForceAllowOnExternal(Context context) {
1954 return Settings.Global.getInt(
Todd Kennedyf39ca8f2015-08-07 14:15:07 -07001955 context.getContentResolver(), Settings.Global.FORCE_ALLOW_ON_EXTERNAL, 0) != 0;
Yao Chen022b8ea2016-12-16 11:03:28 -08001956 }
1957
1958 @VisibleForTesting
1959 protected boolean isAllow3rdPartyOnInternal(Context context) {
1960 return context.getResources().getBoolean(
1961 com.android.internal.R.bool.config_allow3rdPartyAppOnInternal);
1962 }
1963
1964 private boolean isPackageCandidateVolume(
1965 ContextImpl context, ApplicationInfo app, VolumeInfo vol, IPackageManager pm) {
1966 final boolean forceAllowOnExternal = isForceAllowOnExternal(context);
1967
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001968 if (VolumeInfo.ID_PRIVATE_INTERNAL.equals(vol.getId())) {
Yao Chen022b8ea2016-12-16 11:03:28 -08001969 return app.isSystemApp() || isAllow3rdPartyOnInternal(context);
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001970 }
1971
1972 // System apps and apps demanding internal storage can't be moved
1973 // anywhere else
Todd Kennedyf39ca8f2015-08-07 14:15:07 -07001974 if (app.isSystemApp()) {
1975 return false;
1976 }
1977 if (!forceAllowOnExternal
Dianne Hackborn30a4e6d2015-10-12 17:14:56 -07001978 && (app.installLocation == PackageInfo.INSTALL_LOCATION_INTERNAL_ONLY
1979 || app.installLocation == PackageInfo.INSTALL_LOCATION_UNSPECIFIED)) {
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001980 return false;
1981 }
1982
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001983 // Gotta be able to write there
1984 if (!vol.isMountedWritable()) {
1985 return false;
1986 }
1987
1988 // Moving into an ASEC on public primary is only option internal
1989 if (vol.isPrimaryPhysical()) {
1990 return app.isInternal();
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001991 }
1992
Makoto Onukif34db0a2016-02-17 11:17:15 -08001993 // Some apps can't be moved. (e.g. device admins)
1994 try {
Yao Chen022b8ea2016-12-16 11:03:28 -08001995 if (pm.isPackageDeviceAdminOnAnyUser(app.packageName)) {
Makoto Onukif34db0a2016-02-17 11:17:15 -08001996 return false;
1997 }
1998 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001999 throw e.rethrowFromSystemServer();
Makoto Onukif34db0a2016-02-17 11:17:15 -08002000 }
2001
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07002002 // Otherwise we can move to any private volume
2003 return (vol.getType() == VolumeInfo.TYPE_PRIVATE);
2004 }
2005
2006 @Override
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002007 public int movePrimaryStorage(VolumeInfo vol) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002008 try {
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002009 final String volumeUuid;
2010 if (VolumeInfo.ID_PRIVATE_INTERNAL.equals(vol.id)) {
2011 volumeUuid = StorageManager.UUID_PRIVATE_INTERNAL;
2012 } else if (vol.isPrimaryPhysical()) {
2013 volumeUuid = StorageManager.UUID_PRIMARY_PHYSICAL;
2014 } else {
2015 volumeUuid = Preconditions.checkNotNull(vol.fsUuid);
2016 }
2017
2018 return mPM.movePrimaryStorage(volumeUuid);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002019 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002020 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002021 }
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002022 }
2023
Jeff Sharkey275e3e42015-04-24 16:10:32 -07002024 @Override
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002025 public @Nullable VolumeInfo getPrimaryStorageCurrentVolume() {
2026 final StorageManager storage = mContext.getSystemService(StorageManager.class);
2027 final String volumeUuid = storage.getPrimaryStorageUuid();
Jeff Sharkey50a05452015-04-29 11:24:52 -07002028 return storage.findVolumeByQualifiedUuid(volumeUuid);
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002029 }
2030
Jeff Sharkey275e3e42015-04-24 16:10:32 -07002031 @Override
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002032 public @NonNull List<VolumeInfo> getPrimaryStorageCandidateVolumes() {
2033 final StorageManager storage = mContext.getSystemService(StorageManager.class);
2034 final VolumeInfo currentVol = getPrimaryStorageCurrentVolume();
2035 final List<VolumeInfo> vols = storage.getVolumes();
2036 final List<VolumeInfo> candidates = new ArrayList<>();
Jeff Sharkeyfced5342015-05-10 14:53:34 -07002037 if (Objects.equals(StorageManager.UUID_PRIMARY_PHYSICAL,
2038 storage.getPrimaryStorageUuid()) && currentVol != null) {
2039 // TODO: support moving primary physical to emulated volume
2040 candidates.add(currentVol);
2041 } else {
2042 for (VolumeInfo vol : vols) {
2043 if (Objects.equals(vol, currentVol) || isPrimaryStorageCandidateVolume(vol)) {
2044 candidates.add(vol);
2045 }
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002046 }
2047 }
2048 return candidates;
2049 }
2050
2051 private static boolean isPrimaryStorageCandidateVolume(VolumeInfo vol) {
2052 // Private internal is always an option
2053 if (VolumeInfo.ID_PRIVATE_INTERNAL.equals(vol.getId())) {
2054 return true;
2055 }
2056
2057 // Gotta be able to write there
2058 if (!vol.isMountedWritable()) {
2059 return false;
2060 }
2061
Jeff Sharkeyfced5342015-05-10 14:53:34 -07002062 // We can move to any private volume
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002063 return (vol.getType() == VolumeInfo.TYPE_PRIVATE);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002064 }
2065
2066 @Override
2067 public void deletePackage(String packageName, IPackageDeleteObserver observer, int flags) {
Robin Lee0e27c872015-09-28 14:37:40 +01002068 deletePackageAsUser(packageName, observer, flags, mContext.getUserId());
Nicolas Prevot9a80e532015-09-23 15:49:28 +01002069 }
2070
2071 @Override
Svet Ganov67882122016-12-11 16:36:34 -08002072 public void deletePackageAsUser(String packageName, IPackageDeleteObserver observer,
2073 int flags, int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002074 try {
Svet Ganov67882122016-12-11 16:36:34 -08002075 mPM.deletePackageAsUser(packageName, PackageManager.VERSION_CODE_HIGHEST,
2076 observer, userId, flags);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002077 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002078 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002079 }
2080 }
Jeff Sharkeyfbd0e9f2014-08-06 16:34:34 -07002081
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002082 @Override
2083 public void clearApplicationUserData(String packageName,
2084 IPackageDataObserver observer) {
2085 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -07002086 mPM.clearApplicationUserData(packageName, observer, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002087 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002088 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002089 }
2090 }
2091 @Override
2092 public void deleteApplicationCacheFiles(String packageName,
2093 IPackageDataObserver observer) {
2094 try {
2095 mPM.deleteApplicationCacheFiles(packageName, observer);
2096 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002097 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002098 }
2099 }
Jeff Sharkey529f91f2015-04-18 20:23:13 -07002100
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002101 @Override
Suprabh Shukla78c9eb82016-04-12 15:51:35 -07002102 public void deleteApplicationCacheFilesAsUser(String packageName, int userId,
2103 IPackageDataObserver observer) {
2104 try {
2105 mPM.deleteApplicationCacheFilesAsUser(packageName, userId, observer);
2106 } catch (RemoteException e) {
2107 throw e.rethrowFromSystemServer();
2108 }
2109 }
2110
2111 @Override
Jeff Sharkey529f91f2015-04-18 20:23:13 -07002112 public void freeStorageAndNotify(String volumeUuid, long idealStorageSize,
2113 IPackageDataObserver observer) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002114 try {
Jeff Sharkeyddff8072017-05-26 13:10:46 -06002115 mPM.freeStorageAndNotify(volumeUuid, idealStorageSize, 0, observer);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002116 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002117 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002118 }
2119 }
2120
2121 @Override
Jeff Sharkey529f91f2015-04-18 20:23:13 -07002122 public void freeStorage(String volumeUuid, long freeStorageSize, IntentSender pi) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002123 try {
Jeff Sharkeyddff8072017-05-26 13:10:46 -06002124 mPM.freeStorage(volumeUuid, freeStorageSize, 0, pi);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002125 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002126 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002127 }
2128 }
2129
2130 @Override
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00002131 public String[] setPackagesSuspendedAsUser(String[] packageNames, boolean suspended,
2132 int userId) {
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00002133 try {
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00002134 return mPM.setPackagesSuspendedAsUser(packageNames, suspended, userId);
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00002135 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002136 throw e.rethrowFromSystemServer();
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00002137 }
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00002138 }
2139
2140 @Override
Andrei Stingaceanu355b2322016-02-12 16:43:51 +00002141 public boolean isPackageSuspendedForUser(String packageName, int userId) {
2142 try {
2143 return mPM.isPackageSuspendedForUser(packageName, userId);
2144 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002145 throw e.rethrowFromSystemServer();
Andrei Stingaceanu355b2322016-02-12 16:43:51 +00002146 }
Andrei Stingaceanu355b2322016-02-12 16:43:51 +00002147 }
2148
Jeff Sharkey9bc89af2017-01-11 11:25:50 -07002149 /** @hide */
2150 @Override
2151 public void setApplicationCategoryHint(String packageName, int categoryHint) {
2152 try {
2153 mPM.setApplicationCategoryHint(packageName, categoryHint,
2154 mContext.getOpPackageName());
2155 } catch (RemoteException e) {
2156 throw e.rethrowFromSystemServer();
2157 }
2158 }
2159
Andrei Stingaceanu355b2322016-02-12 16:43:51 +00002160 @Override
Jeff Sharkeye06b4d12016-01-06 14:51:50 -07002161 public void getPackageSizeInfoAsUser(String packageName, int userHandle,
Dianne Hackborn0c380492012-08-20 17:23:30 -07002162 IPackageStatsObserver observer) {
Jeff Sharkey6f4b2a32017-03-21 14:13:41 -06002163 final String msg = "Shame on you for calling the hidden API "
2164 + "getPackageSizeInfoAsUser(). Shame!";
Jeff Sharkeye6306c42017-03-07 21:03:18 -07002165 if (mContext.getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.O) {
Jeff Sharkey6f4b2a32017-03-21 14:13:41 -06002166 throw new UnsupportedOperationException(msg);
Jeff Sharkeye6306c42017-03-07 21:03:18 -07002167 } else if (observer != null) {
Jeff Sharkey6f4b2a32017-03-21 14:13:41 -06002168 Log.d(TAG, msg);
Jeff Sharkeye6306c42017-03-07 21:03:18 -07002169 try {
2170 observer.onGetStatsCompleted(null, false);
2171 } catch (RemoteException ignored) {
2172 }
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002173 }
2174 }
Jeff Sharkeyd5896632016-03-04 16:16:00 -07002175
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002176 @Override
2177 public void addPackageToPreferred(String packageName) {
Jeff Sharkeyd5896632016-03-04 16:16:00 -07002178 Log.w(TAG, "addPackageToPreferred() is a no-op");
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002179 }
2180
2181 @Override
2182 public void removePackageFromPreferred(String packageName) {
Jeff Sharkeyd5896632016-03-04 16:16:00 -07002183 Log.w(TAG, "removePackageFromPreferred() is a no-op");
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002184 }
2185
2186 @Override
2187 public List<PackageInfo> getPreferredPackages(int flags) {
Jeff Sharkeyd5896632016-03-04 16:16:00 -07002188 Log.w(TAG, "getPreferredPackages() is a no-op");
2189 return Collections.emptyList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002190 }
2191
2192 @Override
2193 public void addPreferredActivity(IntentFilter filter,
2194 int match, ComponentName[] set, ComponentName activity) {
2195 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -07002196 mPM.addPreferredActivity(filter, match, set, activity, mContext.getUserId());
Amith Yamasania3f133a2012-08-09 17:11:28 -07002197 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002198 throw e.rethrowFromSystemServer();
Amith Yamasania3f133a2012-08-09 17:11:28 -07002199 }
2200 }
2201
2202 @Override
Jeff Sharkeye06b4d12016-01-06 14:51:50 -07002203 public void addPreferredActivityAsUser(IntentFilter filter, int match,
Amith Yamasania3f133a2012-08-09 17:11:28 -07002204 ComponentName[] set, ComponentName activity, int userId) {
2205 try {
2206 mPM.addPreferredActivity(filter, match, set, activity, userId);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002207 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002208 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002209 }
2210 }
2211
2212 @Override
2213 public void replacePreferredActivity(IntentFilter filter,
2214 int match, ComponentName[] set, ComponentName activity) {
2215 try {
Robin Lee0e27c872015-09-28 14:37:40 +01002216 mPM.replacePreferredActivity(filter, match, set, activity, mContext.getUserId());
Amith Yamasani41c1ded2014-08-05 11:15:05 -07002217 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002218 throw e.rethrowFromSystemServer();
Amith Yamasani41c1ded2014-08-05 11:15:05 -07002219 }
2220 }
2221
2222 @Override
2223 public void replacePreferredActivityAsUser(IntentFilter filter,
2224 int match, ComponentName[] set, ComponentName activity,
2225 int userId) {
2226 try {
2227 mPM.replacePreferredActivity(filter, match, set, activity, userId);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002228 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002229 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002230 }
2231 }
2232
2233 @Override
2234 public void clearPackagePreferredActivities(String packageName) {
2235 try {
2236 mPM.clearPackagePreferredActivities(packageName);
2237 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002238 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002239 }
2240 }
2241
2242 @Override
2243 public int getPreferredActivities(List<IntentFilter> outFilters,
2244 List<ComponentName> outActivities, String packageName) {
2245 try {
2246 return mPM.getPreferredActivities(outFilters, outActivities, packageName);
2247 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002248 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002249 }
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002250 }
2251
2252 @Override
Christopher Tatea2a0850d2013-09-05 16:38:58 -07002253 public ComponentName getHomeActivities(List<ResolveInfo> outActivities) {
2254 try {
2255 return mPM.getHomeActivities(outActivities);
2256 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002257 throw e.rethrowFromSystemServer();
Christopher Tatea2a0850d2013-09-05 16:38:58 -07002258 }
Christopher Tatea2a0850d2013-09-05 16:38:58 -07002259 }
2260
2261 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002262 public void setComponentEnabledSetting(ComponentName componentName,
2263 int newState, int flags) {
2264 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -07002265 mPM.setComponentEnabledSetting(componentName, newState, flags, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002266 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002267 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002268 }
2269 }
2270
2271 @Override
2272 public int getComponentEnabledSetting(ComponentName componentName) {
2273 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -07002274 return mPM.getComponentEnabledSetting(componentName, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002275 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002276 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002277 }
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002278 }
2279
2280 @Override
2281 public void setApplicationEnabledSetting(String packageName,
2282 int newState, int flags) {
2283 try {
Dianne Hackborn3fa3c28a2013-03-26 16:15:41 -07002284 mPM.setApplicationEnabledSetting(packageName, newState, flags,
Dianne Hackborn95d78532013-09-11 09:51:14 -07002285 mContext.getUserId(), mContext.getOpPackageName());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002286 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002287 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002288 }
2289 }
2290
2291 @Override
2292 public int getApplicationEnabledSetting(String packageName) {
2293 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -07002294 return mPM.getApplicationEnabledSetting(packageName, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002295 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002296 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002297 }
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002298 }
2299
Amith Yamasani655d0e22013-06-12 14:19:10 -07002300 @Override
Sudheer Shankabbb3ff22015-07-09 15:39:23 +01002301 public void flushPackageRestrictionsAsUser(int userId) {
2302 try {
2303 mPM.flushPackageRestrictionsAsUser(userId);
2304 } catch (RemoteException e) {
2305 throw e.rethrowFromSystemServer();
2306 }
2307 }
2308
2309 @Override
Amith Yamasanie5bcff62014-07-19 15:44:09 -07002310 public boolean setApplicationHiddenSettingAsUser(String packageName, boolean hidden,
Amith Yamasani655d0e22013-06-12 14:19:10 -07002311 UserHandle user) {
2312 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07002313 return mPM.setApplicationHiddenSettingAsUser(packageName, hidden,
Amith Yamasani655d0e22013-06-12 14:19:10 -07002314 user.getIdentifier());
Jeff Sharkey27b2e692016-02-25 17:40:12 -07002315 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002316 throw e.rethrowFromSystemServer();
Amith Yamasani655d0e22013-06-12 14:19:10 -07002317 }
Amith Yamasani655d0e22013-06-12 14:19:10 -07002318 }
2319
2320 @Override
Amith Yamasanie5bcff62014-07-19 15:44:09 -07002321 public boolean getApplicationHiddenSettingAsUser(String packageName, UserHandle user) {
Amith Yamasani655d0e22013-06-12 14:19:10 -07002322 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07002323 return mPM.getApplicationHiddenSettingAsUser(packageName, user.getIdentifier());
Jeff Sharkey27b2e692016-02-25 17:40:12 -07002324 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002325 throw e.rethrowFromSystemServer();
Amith Yamasani655d0e22013-06-12 14:19:10 -07002326 }
Amith Yamasani655d0e22013-06-12 14:19:10 -07002327 }
2328
dcashmanc6f22492014-08-14 09:54:51 -07002329 /** @hide */
dcashman9d2f4412014-06-09 09:27:54 -07002330 @Override
2331 public KeySet getKeySetByAlias(String packageName, String alias) {
2332 Preconditions.checkNotNull(packageName);
2333 Preconditions.checkNotNull(alias);
dcashman9d2f4412014-06-09 09:27:54 -07002334 try {
Jeff Sharkey27b2e692016-02-25 17:40:12 -07002335 return mPM.getKeySetByAlias(packageName, alias);
dcashman9d2f4412014-06-09 09:27:54 -07002336 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002337 throw e.rethrowFromSystemServer();
dcashman9d2f4412014-06-09 09:27:54 -07002338 }
dcashman9d2f4412014-06-09 09:27:54 -07002339 }
2340
dcashmanc6f22492014-08-14 09:54:51 -07002341 /** @hide */
dcashman9d2f4412014-06-09 09:27:54 -07002342 @Override
2343 public KeySet getSigningKeySet(String packageName) {
2344 Preconditions.checkNotNull(packageName);
dcashman9d2f4412014-06-09 09:27:54 -07002345 try {
Jeff Sharkey27b2e692016-02-25 17:40:12 -07002346 return mPM.getSigningKeySet(packageName);
dcashman9d2f4412014-06-09 09:27:54 -07002347 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002348 throw e.rethrowFromSystemServer();
dcashman9d2f4412014-06-09 09:27:54 -07002349 }
dcashman9d2f4412014-06-09 09:27:54 -07002350 }
2351
dcashmanc6f22492014-08-14 09:54:51 -07002352 /** @hide */
dcashman9d2f4412014-06-09 09:27:54 -07002353 @Override
2354 public boolean isSignedBy(String packageName, KeySet ks) {
2355 Preconditions.checkNotNull(packageName);
2356 Preconditions.checkNotNull(ks);
dcashman9d2f4412014-06-09 09:27:54 -07002357 try {
dcashmanc6f22492014-08-14 09:54:51 -07002358 return mPM.isPackageSignedByKeySet(packageName, ks);
dcashman9d2f4412014-06-09 09:27:54 -07002359 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002360 throw e.rethrowFromSystemServer();
dcashman9d2f4412014-06-09 09:27:54 -07002361 }
2362 }
2363
dcashmanc6f22492014-08-14 09:54:51 -07002364 /** @hide */
dcashman9d2f4412014-06-09 09:27:54 -07002365 @Override
2366 public boolean isSignedByExactly(String packageName, KeySet ks) {
2367 Preconditions.checkNotNull(packageName);
2368 Preconditions.checkNotNull(ks);
dcashman9d2f4412014-06-09 09:27:54 -07002369 try {
dcashmanc6f22492014-08-14 09:54:51 -07002370 return mPM.isPackageSignedByKeySetExactly(packageName, ks);
dcashman9d2f4412014-06-09 09:27:54 -07002371 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002372 throw e.rethrowFromSystemServer();
dcashman9d2f4412014-06-09 09:27:54 -07002373 }
2374 }
2375
Kenny Root0aaa0d92011-09-12 16:42:55 -07002376 /**
2377 * @hide
2378 */
2379 @Override
2380 public VerifierDeviceIdentity getVerifierDeviceIdentity() {
2381 try {
2382 return mPM.getVerifierDeviceIdentity();
2383 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002384 throw e.rethrowFromSystemServer();
Kenny Root0aaa0d92011-09-12 16:42:55 -07002385 }
Kenny Root0aaa0d92011-09-12 16:42:55 -07002386 }
2387
Jeff Hao9f60c082014-10-28 18:51:07 -07002388 /**
2389 * @hide
2390 */
2391 @Override
2392 public boolean isUpgrade() {
2393 try {
2394 return mPM.isUpgrade();
2395 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002396 throw e.rethrowFromSystemServer();
Jeff Hao9f60c082014-10-28 18:51:07 -07002397 }
2398 }
2399
Jeff Sharkey3a44f3f2014-04-28 17:36:31 -07002400 @Override
Jeff Sharkey16c8e3f2014-07-24 17:08:17 -07002401 public PackageInstaller getPackageInstaller() {
2402 synchronized (mLock) {
2403 if (mInstaller == null) {
2404 try {
Svet Ganov67882122016-12-11 16:36:34 -08002405 mInstaller = new PackageInstaller(mPM.getPackageInstaller(),
Jeff Sharkey16c8e3f2014-07-24 17:08:17 -07002406 mContext.getPackageName(), mContext.getUserId());
2407 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002408 throw e.rethrowFromSystemServer();
Jeff Sharkey16c8e3f2014-07-24 17:08:17 -07002409 }
2410 }
2411 return mInstaller;
Jeff Sharkey3a44f3f2014-04-28 17:36:31 -07002412 }
2413 }
2414
Jeff Sharkey6c833e02014-07-14 22:44:30 -07002415 @Override
2416 public boolean isPackageAvailable(String packageName) {
2417 try {
2418 return mPM.isPackageAvailable(packageName, mContext.getUserId());
2419 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002420 throw e.rethrowFromSystemServer();
Jeff Sharkey6c833e02014-07-14 22:44:30 -07002421 }
2422 }
2423
Nicolas Prevotc79586e2014-05-06 12:47:57 +01002424 /**
2425 * @hide
2426 */
2427 @Override
Nicolas Prevot63798c52014-05-27 13:22:38 +01002428 public void addCrossProfileIntentFilter(IntentFilter filter, int sourceUserId, int targetUserId,
2429 int flags) {
Nicolas Prevotc79586e2014-05-06 12:47:57 +01002430 try {
Nicolas Prevot3f7777f2014-07-24 15:58:39 +01002431 mPM.addCrossProfileIntentFilter(filter, mContext.getOpPackageName(),
Nicolas Prevot4b8d5822015-03-05 15:20:49 +00002432 sourceUserId, targetUserId, flags);
Nicolas Prevotc79586e2014-05-06 12:47:57 +01002433 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002434 throw e.rethrowFromSystemServer();
Nicolas Prevotc79586e2014-05-06 12:47:57 +01002435 }
2436 }
2437
2438 /**
2439 * @hide
2440 */
2441 @Override
Nicolas Prevot81948992014-05-16 18:25:26 +01002442 public void clearCrossProfileIntentFilters(int sourceUserId) {
Nicolas Prevotc79586e2014-05-06 12:47:57 +01002443 try {
Nicolas Prevot4b8d5822015-03-05 15:20:49 +00002444 mPM.clearCrossProfileIntentFilters(sourceUserId, mContext.getOpPackageName());
Nicolas Prevotc79586e2014-05-06 12:47:57 +01002445 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002446 throw e.rethrowFromSystemServer();
Nicolas Prevotc79586e2014-05-06 12:47:57 +01002447 }
2448 }
2449
Nicolas Prevot88cc3462014-05-14 14:51:48 +01002450 /**
2451 * @hide
2452 */
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +01002453 public Drawable loadItemIcon(PackageItemInfo itemInfo, ApplicationInfo appInfo) {
Benjamin Franzec2d48b2014-10-01 15:38:43 +01002454 Drawable dr = loadUnbadgedItemIcon(itemInfo, appInfo);
2455 if (itemInfo.showUserIcon != UserHandle.USER_NULL) {
2456 return dr;
2457 }
2458 return getUserBadgedIcon(dr, new UserHandle(mContext.getUserId()));
2459 }
2460
2461 /**
2462 * @hide
2463 */
2464 public Drawable loadUnbadgedItemIcon(PackageItemInfo itemInfo, ApplicationInfo appInfo) {
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +01002465 if (itemInfo.showUserIcon != UserHandle.USER_NULL) {
Alexandra Gherghina64d4dca2014-08-28 18:26:56 +01002466 Bitmap bitmap = getUserManager().getUserIcon(itemInfo.showUserIcon);
2467 if (bitmap == null) {
Tony Mak213955e2017-11-23 16:57:08 +08002468 return UserIcons.getDefaultUserIcon(
2469 mContext.getResources(), itemInfo.showUserIcon, /* light= */ false);
Alexandra Gherghina64d4dca2014-08-28 18:26:56 +01002470 }
2471 return new BitmapDrawable(bitmap);
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +01002472 }
Alexandra Gherghinadb811db2014-08-29 13:43:59 +01002473 Drawable dr = null;
2474 if (itemInfo.packageName != null) {
2475 dr = getDrawable(itemInfo.packageName, itemInfo.icon, appInfo);
2476 }
Alexandra Gherghinaa71e3902014-07-25 20:03:47 +01002477 if (dr == null) {
Alexandra Gherghinaa7093142014-07-30 13:43:39 +01002478 dr = itemInfo.loadDefaultIcon(this);
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +01002479 }
Benjamin Franzec2d48b2014-10-01 15:38:43 +01002480 return dr;
Svetoslavc7d62f02014-09-04 15:39:54 -07002481 }
2482
2483 private Drawable getBadgedDrawable(Drawable drawable, Drawable badgeDrawable,
2484 Rect badgeLocation, boolean tryBadgeInPlace) {
2485 final int badgedWidth = drawable.getIntrinsicWidth();
2486 final int badgedHeight = drawable.getIntrinsicHeight();
2487 final boolean canBadgeInPlace = tryBadgeInPlace
2488 && (drawable instanceof BitmapDrawable)
2489 && ((BitmapDrawable) drawable).getBitmap().isMutable();
2490
2491 final Bitmap bitmap;
2492 if (canBadgeInPlace) {
2493 bitmap = ((BitmapDrawable) drawable).getBitmap();
2494 } else {
2495 bitmap = Bitmap.createBitmap(badgedWidth, badgedHeight, Bitmap.Config.ARGB_8888);
2496 }
2497 Canvas canvas = new Canvas(bitmap);
2498
2499 if (!canBadgeInPlace) {
2500 drawable.setBounds(0, 0, badgedWidth, badgedHeight);
2501 drawable.draw(canvas);
2502 }
2503
2504 if (badgeLocation != null) {
2505 if (badgeLocation.left < 0 || badgeLocation.top < 0
2506 || badgeLocation.width() > badgedWidth || badgeLocation.height() > badgedHeight) {
2507 throw new IllegalArgumentException("Badge location " + badgeLocation
2508 + " not in badged drawable bounds "
2509 + new Rect(0, 0, badgedWidth, badgedHeight));
2510 }
2511 badgeDrawable.setBounds(0, 0, badgeLocation.width(), badgeLocation.height());
2512
2513 canvas.save();
2514 canvas.translate(badgeLocation.left, badgeLocation.top);
2515 badgeDrawable.draw(canvas);
2516 canvas.restore();
2517 } else {
2518 badgeDrawable.setBounds(0, 0, badgedWidth, badgedHeight);
2519 badgeDrawable.draw(canvas);
2520 }
2521
2522 if (!canBadgeInPlace) {
2523 BitmapDrawable mergedDrawable = new BitmapDrawable(mContext.getResources(), bitmap);
2524
2525 if (drawable instanceof BitmapDrawable) {
2526 BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
2527 mergedDrawable.setTargetDensity(bitmapDrawable.getBitmap().getDensity());
2528 }
2529
2530 return mergedDrawable;
2531 }
2532
2533 return drawable;
2534 }
2535
Tony Mak8673b282016-03-21 21:10:59 +00002536 private boolean isManagedProfile(int userId) {
2537 return getUserManager().isManagedProfile(userId);
Nicolas Prevot88cc3462014-05-14 14:51:48 +01002538 }
2539
Bartosz Fabianowskia34f53f2017-01-11 18:08:47 +01002540 /**
2541 * @hide
2542 */
2543 @Override
2544 public int getInstallReason(String packageName, UserHandle user) {
2545 try {
2546 return mPM.getInstallReason(packageName, user.getIdentifier());
2547 } catch (RemoteException e) {
2548 throw e.rethrowFromSystemServer();
2549 }
2550 }
2551
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002552 /** {@hide} */
2553 private static class MoveCallbackDelegate extends IPackageMoveObserver.Stub implements
2554 Handler.Callback {
Jeff Sharkey50a05452015-04-29 11:24:52 -07002555 private static final int MSG_CREATED = 1;
2556 private static final int MSG_STATUS_CHANGED = 2;
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002557
2558 final MoveCallback mCallback;
2559 final Handler mHandler;
2560
2561 public MoveCallbackDelegate(MoveCallback callback, Looper looper) {
2562 mCallback = callback;
2563 mHandler = new Handler(looper, this);
2564 }
2565
2566 @Override
2567 public boolean handleMessage(Message msg) {
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002568 switch (msg.what) {
Jeff Sharkey50a05452015-04-29 11:24:52 -07002569 case MSG_CREATED: {
Jeff Sharkeyb36586a2015-04-27 08:42:28 -07002570 final SomeArgs args = (SomeArgs) msg.obj;
Jeff Sharkey50a05452015-04-29 11:24:52 -07002571 mCallback.onCreated(args.argi1, (Bundle) args.arg2);
Jeff Sharkeyb36586a2015-04-27 08:42:28 -07002572 args.recycle();
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002573 return true;
Jeff Sharkey50a05452015-04-29 11:24:52 -07002574 }
2575 case MSG_STATUS_CHANGED: {
2576 final SomeArgs args = (SomeArgs) msg.obj;
2577 mCallback.onStatusChanged(args.argi1, args.argi2, (long) args.arg3);
2578 args.recycle();
2579 return true;
2580 }
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002581 }
2582 return false;
2583 }
2584
2585 @Override
Jeff Sharkey50a05452015-04-29 11:24:52 -07002586 public void onCreated(int moveId, Bundle extras) {
Jeff Sharkeyb36586a2015-04-27 08:42:28 -07002587 final SomeArgs args = SomeArgs.obtain();
2588 args.argi1 = moveId;
Jeff Sharkey50a05452015-04-29 11:24:52 -07002589 args.arg2 = extras;
2590 mHandler.obtainMessage(MSG_CREATED, args).sendToTarget();
2591 }
2592
2593 @Override
2594 public void onStatusChanged(int moveId, int status, long estMillis) {
2595 final SomeArgs args = SomeArgs.obtain();
2596 args.argi1 = moveId;
2597 args.argi2 = status;
2598 args.arg3 = estMillis;
Jeff Sharkeyb36586a2015-04-27 08:42:28 -07002599 mHandler.obtainMessage(MSG_STATUS_CHANGED, args).sendToTarget();
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002600 }
2601 }
2602
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002603 private final ContextImpl mContext;
2604 private final IPackageManager mPM;
2605
2606 private static final Object sSync = new Object();
Dianne Hackbornadd005c2013-07-17 18:43:12 -07002607 private static ArrayMap<ResourceName, WeakReference<Drawable.ConstantState>> sIconCache
2608 = new ArrayMap<ResourceName, WeakReference<Drawable.ConstantState>>();
2609 private static ArrayMap<ResourceName, WeakReference<CharSequence>> sStringCache
2610 = new ArrayMap<ResourceName, WeakReference<CharSequence>>();
Svetoslavf7c06eb2015-06-10 18:43:22 -07002611
2612 private final Map<OnPermissionsChangedListener, IOnPermissionsChangeListener>
2613 mPermissionListeners = new ArrayMap<>();
2614
2615 public class OnPermissionsChangeListenerDelegate extends IOnPermissionsChangeListener.Stub
2616 implements Handler.Callback{
2617 private static final int MSG_PERMISSIONS_CHANGED = 1;
2618
2619 private final OnPermissionsChangedListener mListener;
2620 private final Handler mHandler;
2621
2622
2623 public OnPermissionsChangeListenerDelegate(OnPermissionsChangedListener listener,
2624 Looper looper) {
2625 mListener = listener;
2626 mHandler = new Handler(looper, this);
2627 }
2628
2629 @Override
2630 public void onPermissionsChanged(int uid) {
2631 mHandler.obtainMessage(MSG_PERMISSIONS_CHANGED, uid, 0).sendToTarget();
2632 }
2633
2634 @Override
2635 public boolean handleMessage(Message msg) {
2636 switch (msg.what) {
2637 case MSG_PERMISSIONS_CHANGED: {
2638 final int uid = msg.arg1;
2639 mListener.onPermissionsChanged(uid);
2640 return true;
2641 }
2642 }
2643 return false;
2644 }
2645 }
Suprabh Shuklaaef25132017-01-23 18:09:03 -08002646
2647 @Override
2648 public boolean canRequestPackageInstalls() {
2649 try {
2650 return mPM.canRequestPackageInstalls(mContext.getPackageName(), mContext.getUserId());
2651 } catch (RemoteException e) {
2652 throw e.rethrowAsRuntimeException();
2653 }
2654 }
Chad Brubaker336ae5b2017-03-24 15:53:09 -07002655
2656 @Override
2657 public ComponentName getInstantAppResolverSettingsComponent() {
2658 try {
2659 return mPM.getInstantAppResolverSettingsComponent();
2660 } catch (RemoteException e) {
2661 throw e.rethrowAsRuntimeException();
2662 }
2663 }
Todd Kennedy801e6592017-04-12 14:10:12 -07002664
2665 @Override
2666 public ComponentName getInstantAppInstallerComponent() {
2667 try {
2668 return mPM.getInstantAppInstallerComponent();
2669 } catch (RemoteException e) {
2670 throw e.rethrowAsRuntimeException();
2671 }
2672 }
Chad Brubaker0d277a72017-04-12 16:56:53 -07002673
2674 @Override
2675 public String getInstantAppAndroidId(String packageName, UserHandle user) {
2676 try {
2677 return mPM.getInstantAppAndroidId(packageName, user.getIdentifier());
2678 } catch (RemoteException e) {
2679 throw e.rethrowAsRuntimeException();
2680 }
2681 }
Calin Juravle3d2af7f2017-04-19 19:56:21 -07002682
2683 private static class DexModuleRegisterResult {
2684 final String dexModulePath;
2685 final boolean success;
2686 final String message;
2687
2688 private DexModuleRegisterResult(String dexModulePath, boolean success, String message) {
2689 this.dexModulePath = dexModulePath;
2690 this.success = success;
2691 this.message = message;
2692 }
2693 }
2694
2695 private static class DexModuleRegisterCallbackDelegate
2696 extends android.content.pm.IDexModuleRegisterCallback.Stub
2697 implements Handler.Callback {
2698 private static final int MSG_DEX_MODULE_REGISTERED = 1;
2699 private final DexModuleRegisterCallback callback;
2700 private final Handler mHandler;
2701
2702 DexModuleRegisterCallbackDelegate(@NonNull DexModuleRegisterCallback callback) {
2703 this.callback = callback;
2704 mHandler = new Handler(Looper.getMainLooper(), this);
2705 }
2706
2707 @Override
2708 public void onDexModuleRegistered(@NonNull String dexModulePath, boolean success,
2709 @Nullable String message)throws RemoteException {
2710 mHandler.obtainMessage(MSG_DEX_MODULE_REGISTERED,
2711 new DexModuleRegisterResult(dexModulePath, success, message)).sendToTarget();
2712 }
2713
2714 @Override
2715 public boolean handleMessage(Message msg) {
2716 if (msg.what != MSG_DEX_MODULE_REGISTERED) {
2717 return false;
2718 }
2719 DexModuleRegisterResult result = (DexModuleRegisterResult)msg.obj;
2720 callback.onDexModuleRegistered(result.dexModulePath, result.success, result.message);
2721 return true;
2722 }
2723 }
2724
2725 @Override
2726 public void registerDexModule(@NonNull String dexModule,
2727 @Nullable DexModuleRegisterCallback callback) {
2728 // Check if this is a shared module by looking if the others can read it.
2729 boolean isSharedModule = false;
2730 try {
2731 StructStat stat = Os.stat(dexModule);
2732 if ((OsConstants.S_IROTH & stat.st_mode) != 0) {
2733 isSharedModule = true;
2734 }
2735 } catch (ErrnoException e) {
2736 callback.onDexModuleRegistered(dexModule, false,
2737 "Could not get stat the module file: " + e.getMessage());
2738 return;
2739 }
2740
2741 // Module path is ok.
2742 // Create the callback delegate to be passed to package manager service.
2743 DexModuleRegisterCallbackDelegate callbackDelegate = null;
2744 if (callback != null) {
2745 callbackDelegate = new DexModuleRegisterCallbackDelegate(callback);
2746 }
2747
2748 // Invoke the package manager service.
2749 try {
2750 mPM.registerDexModule(mContext.getPackageName(), dexModule,
2751 isSharedModule, callbackDelegate);
2752 } catch (RemoteException e) {
2753 throw e.rethrowAsRuntimeException();
2754 }
2755 }
Calin Juravle45f8b292017-11-07 18:49:43 -08002756
2757 @Override
2758 public ArtManager getArtManager() {
2759 synchronized (mLock) {
2760 if (mArtManager == null) {
2761 try {
2762 mArtManager = new ArtManager(mPM.getArtManager());
2763 } catch (RemoteException e) {
2764 throw e.rethrowFromSystemServer();
2765 }
2766 }
2767 return mArtManager;
2768 }
2769 }
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002770}