blob: 53cc9caf5a2fb07eb1684d446b7d6eb26da92ea2 [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;
Makoto Onukif34db0a2016-02-17 11:17:15 -080024import android.app.admin.DevicePolicyManager;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080025import android.content.ComponentName;
26import android.content.ContentResolver;
27import android.content.Intent;
28import android.content.IntentFilter;
29import android.content.IntentSender;
30import android.content.pm.ActivityInfo;
31import android.content.pm.ApplicationInfo;
32import android.content.pm.ComponentInfo;
Svet Ganov2acf0632015-11-24 19:10:59 -080033import android.content.pm.EphemeralApplicationInfo;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080034import 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;
38import android.content.pm.IPackageInstallObserver;
39import android.content.pm.IPackageManager;
40import android.content.pm.IPackageMoveObserver;
41import android.content.pm.IPackageStatsObserver;
42import 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;
Svetoslavc7d62f02014-09-04 15:39:54 -070055import android.content.pm.UserInfo;
Kenny Root0aaa0d92011-09-12 16:42:55 -070056import android.content.pm.VerifierDeviceIdentity;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080057import android.content.res.Resources;
58import android.content.res.XmlResourceParser;
Svetoslavc7d62f02014-09-04 15:39:54 -070059import android.graphics.Bitmap;
60import android.graphics.Canvas;
61import android.graphics.Rect;
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +010062import android.graphics.drawable.BitmapDrawable;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080063import android.graphics.drawable.Drawable;
64import android.net.Uri;
Jeff Sharkey50a05452015-04-29 11:24:52 -070065import android.os.Bundle;
Jeff Sharkey620b32b2015-04-23 19:36:02 -070066import android.os.Handler;
67import android.os.Looper;
68import android.os.Message;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080069import android.os.Process;
70import android.os.RemoteException;
Jeff Sharkeyb2b9ab82015-04-05 21:10:42 -070071import android.os.SystemProperties;
Amith Yamasani67df64b2012-12-14 12:09:36 -080072import android.os.UserHandle;
Nicolas Prevot88cc3462014-05-14 14:51:48 +010073import android.os.UserManager;
Jeff Sharkeye2d45be2015-04-15 17:14:12 -070074import android.os.storage.StorageManager;
75import android.os.storage.VolumeInfo;
Todd Kennedyf39ca8f2015-08-07 14:15:07 -070076import android.provider.Settings;
Dianne Hackbornadd005c2013-07-17 18:43:12 -070077import android.util.ArrayMap;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080078import android.util.Log;
Jeff Browna492c3a2012-08-23 19:48:44 -070079import android.view.Display;
Jeff Sharkeyb2b9ab82015-04-05 21:10:42 -070080
81import dalvik.system.VMRuntime;
Jeff Sharkey16c8e3f2014-07-24 17:08:17 -070082
83import com.android.internal.annotations.GuardedBy;
Jeff Sharkeyb36586a2015-04-27 08:42:28 -070084import com.android.internal.os.SomeArgs;
dcashman9d2f4412014-06-09 09:27:54 -070085import com.android.internal.util.Preconditions;
Alexandra Gherghina64d4dca2014-08-28 18:26:56 +010086import com.android.internal.util.UserIcons;
Svet Ganov2acf0632015-11-24 19:10:59 -080087import libcore.util.EmptyArray;
Jeff Sharkey16c8e3f2014-07-24 17:08:17 -070088
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080089import java.lang.ref.WeakReference;
90import java.util.ArrayList;
Svet Ganov2acf0632015-11-24 19:10:59 -080091import java.util.Collections;
Jeff Sharkey620b32b2015-04-23 19:36:02 -070092import java.util.Iterator;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080093import java.util.List;
Svetoslavf7c06eb2015-06-10 18:43:22 -070094import java.util.Map;
Jeff Sharkey620b32b2015-04-23 19:36:02 -070095import java.util.Objects;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080096
Makoto Onukicc4bbeb2015-09-17 10:28:24 -070097/** @hide */
98public class ApplicationPackageManager extends PackageManager {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080099 private static final String TAG = "ApplicationPackageManager";
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800100 private final static boolean DEBUG_ICONS = false;
101
Svet Ganov2acf0632015-11-24 19:10:59 -0800102 private static final int DEFAULT_EPHEMERAL_COOKIE_MAX_SIZE_BYTES = 16384; // 16KB
103
Adam Lesinskid00bb5e2014-10-07 12:14:45 -0700104 // Default flags to use with PackageManager when no flags are given.
105 private final static int sDefaultFlags = PackageManager.GET_SHARED_LIBRARY_FILES;
106
Jeff Sharkey16c8e3f2014-07-24 17:08:17 -0700107 private final Object mLock = new Object();
108
109 @GuardedBy("mLock")
110 private UserManager mUserManager;
111 @GuardedBy("mLock")
112 private PackageInstaller mInstaller;
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +0100113
Jeff Sharkey620b32b2015-04-23 19:36:02 -0700114 @GuardedBy("mDelegates")
115 private final ArrayList<MoveCallbackDelegate> mDelegates = new ArrayList<>();
116
Svet Ganovf1b7f202015-07-29 08:33:42 -0700117 @GuardedBy("mLock")
118 private String mPermissionsControllerPackageName;
119
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +0100120 UserManager getUserManager() {
Jeff Sharkey16c8e3f2014-07-24 17:08:17 -0700121 synchronized (mLock) {
122 if (mUserManager == null) {
123 mUserManager = UserManager.get(mContext);
124 }
125 return mUserManager;
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +0100126 }
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +0100127 }
128
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800129 @Override
130 public PackageInfo getPackageInfo(String packageName, int flags)
131 throws NameNotFoundException {
Nicolas Prevot9a80e532015-09-23 15:49:28 +0100132 return getPackageInfoAsUser(packageName, flags, mContext.getUserId());
133 }
134
135 @Override
136 public PackageInfo getPackageInfoAsUser(String packageName, int flags, int userId)
137 throws NameNotFoundException {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800138 try {
Nicolas Prevot9a80e532015-09-23 15:49:28 +0100139 PackageInfo pi = mPM.getPackageInfo(packageName, flags, userId);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800140 if (pi != null) {
141 return pi;
142 }
143 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700144 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800145 }
146
147 throw new NameNotFoundException(packageName);
148 }
149
150 @Override
151 public String[] currentToCanonicalPackageNames(String[] names) {
152 try {
153 return mPM.currentToCanonicalPackageNames(names);
154 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700155 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800156 }
157 }
158
159 @Override
160 public String[] canonicalToCurrentPackageNames(String[] names) {
161 try {
162 return mPM.canonicalToCurrentPackageNames(names);
163 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700164 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800165 }
166 }
167
168 @Override
169 public Intent getLaunchIntentForPackage(String packageName) {
170 // First see if the package has an INFO activity; the existence of
171 // such an activity is implied to be the desired front-door for the
172 // overall package (such as if it has multiple launcher entries).
173 Intent intentToResolve = new Intent(Intent.ACTION_MAIN);
174 intentToResolve.addCategory(Intent.CATEGORY_INFO);
175 intentToResolve.setPackage(packageName);
Dianne Hackborn19415762010-12-15 00:20:27 -0800176 List<ResolveInfo> ris = queryIntentActivities(intentToResolve, 0);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800177
178 // Otherwise, try to find a main launcher activity.
Dianne Hackborn19415762010-12-15 00:20:27 -0800179 if (ris == null || ris.size() <= 0) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800180 // reuse the intent instance
181 intentToResolve.removeCategory(Intent.CATEGORY_INFO);
182 intentToResolve.addCategory(Intent.CATEGORY_LAUNCHER);
183 intentToResolve.setPackage(packageName);
Dianne Hackborn19415762010-12-15 00:20:27 -0800184 ris = queryIntentActivities(intentToResolve, 0);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800185 }
Dianne Hackborn19415762010-12-15 00:20:27 -0800186 if (ris == null || ris.size() <= 0) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800187 return null;
188 }
189 Intent intent = new Intent(intentToResolve);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800190 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Dianne Hackborn19415762010-12-15 00:20:27 -0800191 intent.setClassName(ris.get(0).activityInfo.packageName,
192 ris.get(0).activityInfo.name);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800193 return intent;
194 }
195
196 @Override
Jose Lima970417c2014-04-10 10:42:19 -0700197 public Intent getLeanbackLaunchIntentForPackage(String packageName) {
198 // Try to find a main leanback_launcher activity.
199 Intent intentToResolve = new Intent(Intent.ACTION_MAIN);
200 intentToResolve.addCategory(Intent.CATEGORY_LEANBACK_LAUNCHER);
201 intentToResolve.setPackage(packageName);
202 List<ResolveInfo> ris = queryIntentActivities(intentToResolve, 0);
203
204 if (ris == null || ris.size() <= 0) {
205 return null;
206 }
207 Intent intent = new Intent(intentToResolve);
208 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
209 intent.setClassName(ris.get(0).activityInfo.packageName,
210 ris.get(0).activityInfo.name);
211 return intent;
212 }
213
214 @Override
Jeff Sharkey8588bc12016-01-06 16:47:42 -0700215 public int[] getPackageGids(String packageName) throws NameNotFoundException {
216 return getPackageGids(packageName, 0);
217 }
218
219 @Override
220 public int[] getPackageGids(String packageName, int flags)
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800221 throws NameNotFoundException {
222 try {
Jeff Sharkeycd654482016-01-08 17:42:11 -0700223 int[] gids = mPM.getPackageGids(packageName, flags, mContext.getUserId());
Svetoslavc6d1c342015-02-26 14:44:43 -0800224 if (gids != null) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800225 return gids;
226 }
227 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700228 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800229 }
230
231 throw new NameNotFoundException(packageName);
232 }
233
234 @Override
Jeff Sharkey8588bc12016-01-06 16:47:42 -0700235 public int getPackageUid(String packageName, int flags) throws NameNotFoundException {
236 return getPackageUidAsUser(packageName, flags, mContext.getUserId());
237 }
238
239 @Override
240 public int getPackageUidAsUser(String packageName, int userId) throws NameNotFoundException {
241 return getPackageUidAsUser(packageName, 0, userId);
242 }
243
244 @Override
245 public int getPackageUidAsUser(String packageName, int flags, int userId)
Dianne Hackborna06de0f2012-12-11 16:34:47 -0800246 throws NameNotFoundException {
247 try {
Jeff Sharkeycd654482016-01-08 17:42:11 -0700248 int uid = mPM.getPackageUid(packageName, flags, userId);
Dianne Hackborna06de0f2012-12-11 16:34:47 -0800249 if (uid >= 0) {
250 return uid;
251 }
252 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700253 throw e.rethrowFromSystemServer();
Dianne Hackborna06de0f2012-12-11 16:34:47 -0800254 }
255
256 throw new NameNotFoundException(packageName);
257 }
258
259 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800260 public PermissionInfo getPermissionInfo(String name, int flags)
261 throws NameNotFoundException {
262 try {
263 PermissionInfo pi = mPM.getPermissionInfo(name, flags);
264 if (pi != null) {
265 return pi;
266 }
267 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700268 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800269 }
270
271 throw new NameNotFoundException(name);
272 }
273
274 @Override
275 public List<PermissionInfo> queryPermissionsByGroup(String group, int flags)
276 throws NameNotFoundException {
277 try {
278 List<PermissionInfo> pi = mPM.queryPermissionsByGroup(group, flags);
279 if (pi != null) {
280 return pi;
281 }
282 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700283 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800284 }
285
286 throw new NameNotFoundException(group);
287 }
288
289 @Override
290 public PermissionGroupInfo getPermissionGroupInfo(String name,
291 int flags) throws NameNotFoundException {
292 try {
293 PermissionGroupInfo pgi = mPM.getPermissionGroupInfo(name, flags);
294 if (pgi != null) {
295 return pgi;
296 }
297 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700298 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800299 }
300
301 throw new NameNotFoundException(name);
302 }
303
304 @Override
305 public List<PermissionGroupInfo> getAllPermissionGroups(int flags) {
306 try {
307 return mPM.getAllPermissionGroups(flags);
308 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700309 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800310 }
311 }
312
313 @Override
314 public ApplicationInfo getApplicationInfo(String packageName, int flags)
315 throws NameNotFoundException {
Jeff Sharkeycd654482016-01-08 17:42:11 -0700316 return getApplicationInfoAsUser(packageName, flags, mContext.getUserId());
317 }
318
319 @Override
320 public ApplicationInfo getApplicationInfoAsUser(String packageName, int flags, int userId)
321 throws NameNotFoundException {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800322 try {
Jeff Sharkeycd654482016-01-08 17:42:11 -0700323 ApplicationInfo ai = mPM.getApplicationInfo(packageName, flags, userId);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800324 if (ai != null) {
Narayan Kamathcaa71192014-07-16 11:06:43 +0100325 // This is a temporary hack. Callers must use
326 // createPackageContext(packageName).getApplicationInfo() to
327 // get the right paths.
Tao Baic9a02372016-01-12 15:02:24 -0800328 return maybeAdjustApplicationInfo(ai);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800329 }
330 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700331 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800332 }
333
334 throw new NameNotFoundException(packageName);
335 }
336
Tao Baic9a02372016-01-12 15:02:24 -0800337 private static ApplicationInfo maybeAdjustApplicationInfo(ApplicationInfo info) {
Narayan Kamathcaa71192014-07-16 11:06:43 +0100338 // If we're dealing with a multi-arch application that has both
339 // 32 and 64 bit shared libraries, we might need to choose the secondary
340 // depending on what the current runtime's instruction set is.
341 if (info.primaryCpuAbi != null && info.secondaryCpuAbi != null) {
342 final String runtimeIsa = VMRuntime.getRuntime().vmInstructionSet();
jgu214741cd92014-12-17 17:23:29 -0500343
344 // Get the instruction set that the libraries of secondary Abi is supported.
345 // In presence of a native bridge this might be different than the one secondary Abi used.
346 String secondaryIsa = VMRuntime.getInstructionSet(info.secondaryCpuAbi);
347 final String secondaryDexCodeIsa = SystemProperties.get("ro.dalvik.vm.isa." + secondaryIsa);
348 secondaryIsa = secondaryDexCodeIsa.isEmpty() ? secondaryIsa : secondaryDexCodeIsa;
Narayan Kamathcaa71192014-07-16 11:06:43 +0100349
350 // If the runtimeIsa is the same as the primary isa, then we do nothing.
351 // Everything will be set up correctly because info.nativeLibraryDir will
352 // correspond to the right ISA.
353 if (runtimeIsa.equals(secondaryIsa)) {
Tao Baic9a02372016-01-12 15:02:24 -0800354 ApplicationInfo modified = new ApplicationInfo(info);
355 modified.nativeLibraryDir = info.secondaryNativeLibraryDir;
356 return modified;
Narayan Kamathcaa71192014-07-16 11:06:43 +0100357 }
358 }
Tao Baic9a02372016-01-12 15:02:24 -0800359 return info;
Narayan Kamathcaa71192014-07-16 11:06:43 +0100360 }
361
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800362 @Override
363 public ActivityInfo getActivityInfo(ComponentName className, int flags)
364 throws NameNotFoundException {
365 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700366 ActivityInfo ai = mPM.getActivityInfo(className, flags, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800367 if (ai != null) {
368 return ai;
369 }
370 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700371 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800372 }
373
374 throw new NameNotFoundException(className.toString());
375 }
376
377 @Override
378 public ActivityInfo getReceiverInfo(ComponentName className, int flags)
379 throws NameNotFoundException {
380 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700381 ActivityInfo ai = mPM.getReceiverInfo(className, flags, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800382 if (ai != null) {
383 return ai;
384 }
385 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700386 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800387 }
388
389 throw new NameNotFoundException(className.toString());
390 }
391
392 @Override
393 public ServiceInfo getServiceInfo(ComponentName className, int flags)
394 throws NameNotFoundException {
395 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700396 ServiceInfo si = mPM.getServiceInfo(className, flags, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800397 if (si != null) {
398 return si;
399 }
400 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700401 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800402 }
403
404 throw new NameNotFoundException(className.toString());
405 }
406
407 @Override
408 public ProviderInfo getProviderInfo(ComponentName className, int flags)
409 throws NameNotFoundException {
410 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700411 ProviderInfo pi = mPM.getProviderInfo(className, flags, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800412 if (pi != null) {
413 return pi;
414 }
415 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700416 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800417 }
418
419 throw new NameNotFoundException(className.toString());
420 }
421
422 @Override
423 public String[] getSystemSharedLibraryNames() {
424 try {
425 return mPM.getSystemSharedLibraryNames();
426 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700427 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800428 }
429 }
430
Svet Ganovd7b1f4112016-02-09 18:49:23 -0800431 /** @hide */
432 @Override
433 public @Nullable String getServicesSystemSharedLibraryPackageName() {
434 try {
435 return mPM.getServicesSystemSharedLibraryPackageName();
436 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700437 throw e.rethrowFromSystemServer();
Svet Ganovd7b1f4112016-02-09 18:49:23 -0800438 }
439 }
440
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800441 @Override
442 public FeatureInfo[] getSystemAvailableFeatures() {
443 try {
444 return mPM.getSystemAvailableFeatures();
445 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700446 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800447 }
448 }
449
450 @Override
451 public boolean hasSystemFeature(String name) {
Jeff Sharkey115d2c12016-02-15 17:25:57 -0700452 return hasSystemFeature(name, 0);
453 }
454
455 @Override
456 public boolean hasSystemFeature(String name, int version) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800457 try {
Jeff Sharkey115d2c12016-02-15 17:25:57 -0700458 return mPM.hasSystemFeature(name, version);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800459 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700460 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800461 }
462 }
463
464 @Override
465 public int checkPermission(String permName, String pkgName) {
466 try {
Svetoslavc6d1c342015-02-26 14:44:43 -0800467 return mPM.checkPermission(permName, pkgName, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800468 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700469 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800470 }
471 }
472
473 @Override
Svet Ganovad3b2972015-07-07 22:49:17 -0700474 public boolean isPermissionRevokedByPolicy(String permName, String pkgName) {
475 try {
476 return mPM.isPermissionRevokedByPolicy(permName, pkgName, mContext.getUserId());
477 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700478 throw e.rethrowFromSystemServer();
Svet Ganovad3b2972015-07-07 22:49:17 -0700479 }
480 }
481
Svet Ganovf1b7f202015-07-29 08:33:42 -0700482 /**
483 * @hide
484 */
485 @Override
486 public String getPermissionControllerPackageName() {
487 synchronized (mLock) {
488 if (mPermissionsControllerPackageName == null) {
489 try {
490 mPermissionsControllerPackageName = mPM.getPermissionControllerPackageName();
491 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700492 throw e.rethrowFromSystemServer();
Svet Ganovf1b7f202015-07-29 08:33:42 -0700493 }
494 }
495 return mPermissionsControllerPackageName;
496 }
497 }
498
Svet Ganovad3b2972015-07-07 22:49:17 -0700499 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800500 public boolean addPermission(PermissionInfo info) {
501 try {
502 return mPM.addPermission(info);
503 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700504 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800505 }
506 }
507
508 @Override
509 public boolean addPermissionAsync(PermissionInfo info) {
510 try {
511 return mPM.addPermissionAsync(info);
512 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700513 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800514 }
515 }
516
517 @Override
518 public void removePermission(String name) {
519 try {
520 mPM.removePermission(name);
521 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700522 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800523 }
524 }
525
526 @Override
Svet Ganov8c7f7002015-05-07 10:48:44 -0700527 public void grantRuntimePermission(String packageName, String permissionName,
528 UserHandle user) {
Dianne Hackborne639da72012-02-21 15:11:13 -0800529 try {
Svet Ganov8c7f7002015-05-07 10:48:44 -0700530 mPM.grantRuntimePermission(packageName, permissionName, user.getIdentifier());
Dianne Hackborne639da72012-02-21 15:11:13 -0800531 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700532 throw e.rethrowFromSystemServer();
Dianne Hackborne639da72012-02-21 15:11:13 -0800533 }
534 }
535
536 @Override
Svet Ganov8c7f7002015-05-07 10:48:44 -0700537 public void revokeRuntimePermission(String packageName, String permissionName,
538 UserHandle user) {
Dianne Hackborne639da72012-02-21 15:11:13 -0800539 try {
Svet Ganov8c7f7002015-05-07 10:48:44 -0700540 mPM.revokeRuntimePermission(packageName, permissionName, user.getIdentifier());
541 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700542 throw e.rethrowFromSystemServer();
Svet Ganov8c7f7002015-05-07 10:48:44 -0700543 }
544 }
545
546 @Override
547 public int getPermissionFlags(String permissionName, String packageName, UserHandle user) {
548 try {
549 return mPM.getPermissionFlags(permissionName, packageName, user.getIdentifier());
550 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700551 throw e.rethrowFromSystemServer();
Svet Ganov8c7f7002015-05-07 10:48:44 -0700552 }
553 }
554
555 @Override
556 public void updatePermissionFlags(String permissionName, String packageName,
557 int flagMask, int flagValues, UserHandle user) {
558 try {
559 mPM.updatePermissionFlags(permissionName, packageName, flagMask,
560 flagValues, user.getIdentifier());
Dianne Hackborne639da72012-02-21 15:11:13 -0800561 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700562 throw e.rethrowFromSystemServer();
Dianne Hackborne639da72012-02-21 15:11:13 -0800563 }
564 }
565
566 @Override
Svetoslav20770dd2015-05-29 15:43:04 -0700567 public boolean shouldShowRequestPermissionRationale(String permission) {
568 try {
569 return mPM.shouldShowRequestPermissionRationale(permission,
570 mContext.getPackageName(), mContext.getUserId());
571 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700572 throw e.rethrowFromSystemServer();
Svetoslav20770dd2015-05-29 15:43:04 -0700573 }
574 }
575
576 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800577 public int checkSignatures(String pkg1, String pkg2) {
578 try {
579 return mPM.checkSignatures(pkg1, pkg2);
580 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700581 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800582 }
583 }
584
585 @Override
586 public int checkSignatures(int uid1, int uid2) {
587 try {
588 return mPM.checkUidSignatures(uid1, uid2);
589 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700590 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800591 }
592 }
593
594 @Override
595 public String[] getPackagesForUid(int uid) {
596 try {
597 return mPM.getPackagesForUid(uid);
598 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700599 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800600 }
601 }
602
603 @Override
604 public String getNameForUid(int uid) {
605 try {
606 return mPM.getNameForUid(uid);
607 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700608 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800609 }
610 }
611
612 @Override
613 public int getUidForSharedUser(String sharedUserName)
614 throws NameNotFoundException {
615 try {
616 int uid = mPM.getUidForSharedUser(sharedUserName);
617 if(uid != -1) {
618 return uid;
619 }
620 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700621 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800622 }
623 throw new NameNotFoundException("No shared userid for user:"+sharedUserName);
624 }
625
Kenny Roote6cd0c72011-05-19 12:48:14 -0700626 @SuppressWarnings("unchecked")
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800627 @Override
628 public List<PackageInfo> getInstalledPackages(int flags) {
Jeff Sharkeye06b4d12016-01-06 14:51:50 -0700629 return getInstalledPackagesAsUser(flags, mContext.getUserId());
Amith Yamasani151ec4c2012-09-07 19:25:16 -0700630 }
631
632 /** @hide */
633 @Override
Jeff Sharkeye06b4d12016-01-06 14:51:50 -0700634 public List<PackageInfo> getInstalledPackagesAsUser(int flags, int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800635 try {
Dianne Hackbornd8e1dbb2013-01-17 17:47:37 -0800636 ParceledListSlice<PackageInfo> slice = mPM.getInstalledPackages(flags, userId);
637 return slice.getList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800638 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700639 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800640 }
641 }
642
Kenny Roote6cd0c72011-05-19 12:48:14 -0700643 @SuppressWarnings("unchecked")
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800644 @Override
Dianne Hackborne7991752013-01-16 17:56:46 -0800645 public List<PackageInfo> getPackagesHoldingPermissions(
646 String[] permissions, int flags) {
647 final int userId = mContext.getUserId();
648 try {
Dianne Hackbornd8e1dbb2013-01-17 17:47:37 -0800649 ParceledListSlice<PackageInfo> slice = mPM.getPackagesHoldingPermissions(
650 permissions, flags, userId);
651 return slice.getList();
Dianne Hackborne7991752013-01-16 17:56:46 -0800652 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700653 throw e.rethrowFromSystemServer();
Dianne Hackborne7991752013-01-16 17:56:46 -0800654 }
655 }
656
657 @SuppressWarnings("unchecked")
658 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800659 public List<ApplicationInfo> getInstalledApplications(int flags) {
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700660 final int userId = mContext.getUserId();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800661 try {
Dianne Hackbornd8e1dbb2013-01-17 17:47:37 -0800662 ParceledListSlice<ApplicationInfo> slice = mPM.getInstalledApplications(flags, userId);
663 return slice.getList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800664 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700665 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800666 }
667 }
668
Svet Ganov2acf0632015-11-24 19:10:59 -0800669 /** @hide */
670 @SuppressWarnings("unchecked")
671 @Override
672 public List<EphemeralApplicationInfo> getEphemeralApplications() {
673 try {
674 ParceledListSlice<EphemeralApplicationInfo> slice =
675 mPM.getEphemeralApplications(mContext.getUserId());
676 if (slice != null) {
677 return slice.getList();
678 }
679 return Collections.emptyList();
680 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700681 throw e.rethrowFromSystemServer();
Svet Ganov2acf0632015-11-24 19:10:59 -0800682 }
683 }
684
685 /** @hide */
686 @Override
687 public Drawable getEphemeralApplicationIcon(String packageName) {
688 try {
689 Bitmap bitmap = mPM.getEphemeralApplicationIcon(
690 packageName, mContext.getUserId());
691 if (bitmap != null) {
692 return new BitmapDrawable(null, bitmap);
693 }
694 return null;
695 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700696 throw e.rethrowFromSystemServer();
Svet Ganov2acf0632015-11-24 19:10:59 -0800697 }
698 }
699
700 @Override
701 public boolean isEphemeralApplication() {
702 try {
703 return mPM.isEphemeralApplication(
704 mContext.getPackageName(), mContext.getUserId());
705 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700706 throw e.rethrowFromSystemServer();
Svet Ganov2acf0632015-11-24 19:10:59 -0800707 }
Svet Ganov2acf0632015-11-24 19:10:59 -0800708 }
709
710 @Override
711 public int getEphemeralCookieMaxSizeBytes() {
712 return Settings.Global.getInt(mContext.getContentResolver(),
713 Settings.Global.EPHEMERAL_COOKIE_MAX_SIZE_BYTES,
714 DEFAULT_EPHEMERAL_COOKIE_MAX_SIZE_BYTES);
715 }
716
717 @Override
718 public @NonNull byte[] getEphemeralCookie() {
719 try {
720 final byte[] cookie = mPM.getEphemeralApplicationCookie(
721 mContext.getPackageName(), mContext.getUserId());
722 if (cookie != null) {
723 return cookie;
Jeff Sharkey27b2e692016-02-25 17:40:12 -0700724 } else {
725 return EmptyArray.BYTE;
Svet Ganov2acf0632015-11-24 19:10:59 -0800726 }
727 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700728 throw e.rethrowFromSystemServer();
Svet Ganov2acf0632015-11-24 19:10:59 -0800729 }
Svet Ganov2acf0632015-11-24 19:10:59 -0800730 }
731
732 @Override
733 public boolean setEphemeralCookie(@NonNull byte[] cookie) {
734 try {
735 return mPM.setEphemeralApplicationCookie(
736 mContext.getPackageName(), cookie, mContext.getUserId());
737 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700738 throw e.rethrowFromSystemServer();
Svet Ganov2acf0632015-11-24 19:10:59 -0800739 }
Svet Ganov2acf0632015-11-24 19:10:59 -0800740 }
741
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800742 @Override
743 public ResolveInfo resolveActivity(Intent intent, int flags) {
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700744 return resolveActivityAsUser(intent, flags, mContext.getUserId());
Svetoslav Ganov58d37b52012-09-18 12:04:19 -0700745 }
746
747 @Override
748 public ResolveInfo resolveActivityAsUser(Intent intent, int flags, int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800749 try {
750 return mPM.resolveIntent(
751 intent,
752 intent.resolveTypeIfNeeded(mContext.getContentResolver()),
Svetoslav Ganov58d37b52012-09-18 12:04:19 -0700753 flags,
754 userId);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800755 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700756 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800757 }
758 }
759
760 @Override
761 public List<ResolveInfo> queryIntentActivities(Intent intent,
762 int flags) {
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700763 return queryIntentActivitiesAsUser(intent, flags, mContext.getUserId());
Amith Yamasani151ec4c2012-09-07 19:25:16 -0700764 }
765
766 /** @hide Same as above but for a specific user */
767 @Override
Svetoslav Ganov58d37b52012-09-18 12:04:19 -0700768 public List<ResolveInfo> queryIntentActivitiesAsUser(Intent intent,
Amith Yamasani151ec4c2012-09-07 19:25:16 -0700769 int flags, int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800770 try {
771 return mPM.queryIntentActivities(
772 intent,
773 intent.resolveTypeIfNeeded(mContext.getContentResolver()),
Amith Yamasani483f3b02012-03-13 16:08:00 -0700774 flags,
Amith Yamasani151ec4c2012-09-07 19:25:16 -0700775 userId);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800776 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700777 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800778 }
779 }
780
781 @Override
782 public List<ResolveInfo> queryIntentActivityOptions(
783 ComponentName caller, Intent[] specifics, Intent intent,
784 int flags) {
785 final ContentResolver resolver = mContext.getContentResolver();
786
787 String[] specificTypes = null;
788 if (specifics != null) {
789 final int N = specifics.length;
790 for (int i=0; i<N; i++) {
791 Intent sp = specifics[i];
792 if (sp != null) {
793 String t = sp.resolveTypeIfNeeded(resolver);
794 if (t != null) {
795 if (specificTypes == null) {
796 specificTypes = new String[N];
797 }
798 specificTypes[i] = t;
799 }
800 }
801 }
802 }
803
804 try {
805 return mPM.queryIntentActivityOptions(caller, specifics,
806 specificTypes, intent, intent.resolveTypeIfNeeded(resolver),
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700807 flags, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800808 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700809 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800810 }
811 }
812
Amith Yamasanif203aee2012-08-29 18:41:53 -0700813 /**
814 * @hide
815 */
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800816 @Override
Jeff Sharkeye06b4d12016-01-06 14:51:50 -0700817 public List<ResolveInfo> queryBroadcastReceiversAsUser(Intent intent, int flags, int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800818 try {
819 return mPM.queryIntentReceivers(
820 intent,
821 intent.resolveTypeIfNeeded(mContext.getContentResolver()),
Amith Yamasani483f3b02012-03-13 16:08:00 -0700822 flags,
Amith Yamasanif203aee2012-08-29 18:41:53 -0700823 userId);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800824 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700825 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800826 }
827 }
828
829 @Override
Amith Yamasanif203aee2012-08-29 18:41:53 -0700830 public List<ResolveInfo> queryBroadcastReceivers(Intent intent, int flags) {
Jeff Sharkeye06b4d12016-01-06 14:51:50 -0700831 return queryBroadcastReceiversAsUser(intent, flags, mContext.getUserId());
Amith Yamasanif203aee2012-08-29 18:41:53 -0700832 }
833
834 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800835 public ResolveInfo resolveService(Intent intent, int flags) {
836 try {
837 return mPM.resolveService(
838 intent,
839 intent.resolveTypeIfNeeded(mContext.getContentResolver()),
Amith Yamasani483f3b02012-03-13 16:08:00 -0700840 flags,
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700841 mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800842 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700843 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800844 }
845 }
846
847 @Override
Svetoslav Ganov58d37b52012-09-18 12:04:19 -0700848 public List<ResolveInfo> queryIntentServicesAsUser(Intent intent, int flags, int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800849 try {
850 return mPM.queryIntentServices(
851 intent,
852 intent.resolveTypeIfNeeded(mContext.getContentResolver()),
Amith Yamasani483f3b02012-03-13 16:08:00 -0700853 flags,
Svetoslav Ganov58d37b52012-09-18 12:04:19 -0700854 userId);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800855 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700856 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800857 }
858 }
859
860 @Override
Svetoslav Ganov58d37b52012-09-18 12:04:19 -0700861 public List<ResolveInfo> queryIntentServices(Intent intent, int flags) {
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700862 return queryIntentServicesAsUser(intent, flags, mContext.getUserId());
Svetoslav Ganov58d37b52012-09-18 12:04:19 -0700863 }
864
865 @Override
Jeff Sharkey85f5f812013-10-07 10:16:12 -0700866 public List<ResolveInfo> queryIntentContentProvidersAsUser(
867 Intent intent, int flags, int userId) {
868 try {
869 return mPM.queryIntentContentProviders(intent,
870 intent.resolveTypeIfNeeded(mContext.getContentResolver()), flags, userId);
871 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700872 throw e.rethrowFromSystemServer();
Jeff Sharkey85f5f812013-10-07 10:16:12 -0700873 }
874 }
875
876 @Override
877 public List<ResolveInfo> queryIntentContentProviders(Intent intent, int flags) {
878 return queryIntentContentProvidersAsUser(intent, flags, mContext.getUserId());
879 }
880
881 @Override
Alexandra Gherghina0363c3e2014-06-23 13:34:59 +0100882 public ProviderInfo resolveContentProvider(String name, int flags) {
883 return resolveContentProviderAsUser(name, flags, mContext.getUserId());
884 }
885
886 /** @hide **/
887 @Override
888 public ProviderInfo resolveContentProviderAsUser(String name, int flags, int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800889 try {
Alexandra Gherghina0363c3e2014-06-23 13:34:59 +0100890 return mPM.resolveContentProvider(name, flags, userId);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800891 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700892 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800893 }
894 }
895
896 @Override
897 public List<ProviderInfo> queryContentProviders(String processName,
898 int uid, int flags) {
899 try {
Dianne Hackborn28ec27c2015-08-03 15:28:28 -0700900 ParceledListSlice<ProviderInfo> slice
901 = mPM.queryContentProviders(processName, uid, flags);
902 return slice != null ? slice.getList() : null;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800903 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700904 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800905 }
906 }
907
908 @Override
909 public InstrumentationInfo getInstrumentationInfo(
910 ComponentName className, int flags)
911 throws NameNotFoundException {
912 try {
913 InstrumentationInfo ii = mPM.getInstrumentationInfo(
914 className, flags);
915 if (ii != null) {
916 return ii;
917 }
918 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700919 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800920 }
921
922 throw new NameNotFoundException(className.toString());
923 }
924
925 @Override
926 public List<InstrumentationInfo> queryInstrumentation(
927 String targetPackage, int flags) {
928 try {
929 return mPM.queryInstrumentation(targetPackage, flags);
930 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700931 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800932 }
933 }
934
Alan Viveretteecd585a2015-04-13 10:32:51 -0700935 @Nullable
936 @Override
937 public Drawable getDrawable(String packageName, @DrawableRes int resId,
938 @Nullable ApplicationInfo appInfo) {
939 final ResourceName name = new ResourceName(packageName, resId);
940 final Drawable cachedIcon = getCachedIcon(name);
941 if (cachedIcon != null) {
942 return cachedIcon;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800943 }
Alan Viveretteecd585a2015-04-13 10:32:51 -0700944
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800945 if (appInfo == null) {
946 try {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -0700947 appInfo = getApplicationInfo(packageName, sDefaultFlags);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800948 } catch (NameNotFoundException e) {
949 return null;
950 }
951 }
Alan Viveretteecd585a2015-04-13 10:32:51 -0700952
953 if (resId != 0) {
954 try {
955 final Resources r = getResourcesForApplication(appInfo);
956 final Drawable dr = r.getDrawable(resId, null);
957 if (dr != null) {
958 putCachedIcon(name, dr);
959 }
960
961 if (false) {
962 RuntimeException e = new RuntimeException("here");
963 e.fillInStackTrace();
964 Log.w(TAG, "Getting drawable 0x" + Integer.toHexString(resId)
965 + " from package " + packageName
966 + ": app scale=" + r.getCompatibilityInfo().applicationScale
967 + ", caller scale=" + mContext.getResources()
968 .getCompatibilityInfo().applicationScale,
969 e);
970 }
Ricky Wai3ce46252015-04-15 16:12:22 +0100971 if (DEBUG_ICONS) {
Alan Viveretteecd585a2015-04-13 10:32:51 -0700972 Log.v(TAG, "Getting drawable 0x"
973 + Integer.toHexString(resId) + " from " + r
974 + ": " + dr);
Ricky Wai3ce46252015-04-15 16:12:22 +0100975 }
976 return dr;
Alan Viveretteecd585a2015-04-13 10:32:51 -0700977 } catch (NameNotFoundException e) {
978 Log.w("PackageManager", "Failure retrieving resources for "
979 + appInfo.packageName);
980 } catch (Resources.NotFoundException e) {
981 Log.w("PackageManager", "Failure retrieving resources for "
982 + appInfo.packageName + ": " + e.getMessage());
983 } catch (Exception e) {
984 // If an exception was thrown, fall through to return
985 // default icon.
986 Log.w("PackageManager", "Failure retrieving icon 0x"
987 + Integer.toHexString(resId) + " in package "
988 + packageName, e);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800989 }
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800990 }
Alan Viveretteecd585a2015-04-13 10:32:51 -0700991
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800992 return null;
993 }
994
995 @Override public Drawable getActivityIcon(ComponentName activityName)
996 throws NameNotFoundException {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -0700997 return getActivityInfo(activityName, sDefaultFlags).loadIcon(this);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800998 }
999
1000 @Override public Drawable getActivityIcon(Intent intent)
1001 throws NameNotFoundException {
1002 if (intent.getComponent() != null) {
1003 return getActivityIcon(intent.getComponent());
1004 }
1005
1006 ResolveInfo info = resolveActivity(
1007 intent, PackageManager.MATCH_DEFAULT_ONLY);
1008 if (info != null) {
1009 return info.activityInfo.loadIcon(this);
1010 }
1011
Romain Guy39fe17c2011-11-30 10:34:07 -08001012 throw new NameNotFoundException(intent.toUri(0));
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001013 }
1014
1015 @Override public Drawable getDefaultActivityIcon() {
1016 return Resources.getSystem().getDrawable(
1017 com.android.internal.R.drawable.sym_def_app_icon);
1018 }
1019
1020 @Override public Drawable getApplicationIcon(ApplicationInfo info) {
1021 return info.loadIcon(this);
1022 }
1023
1024 @Override public Drawable getApplicationIcon(String packageName)
1025 throws NameNotFoundException {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001026 return getApplicationIcon(getApplicationInfo(packageName, sDefaultFlags));
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001027 }
1028
1029 @Override
Jose Limaf78e3122014-03-06 12:13:15 -08001030 public Drawable getActivityBanner(ComponentName activityName)
1031 throws NameNotFoundException {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001032 return getActivityInfo(activityName, sDefaultFlags).loadBanner(this);
Jose Limaf78e3122014-03-06 12:13:15 -08001033 }
1034
1035 @Override
1036 public Drawable getActivityBanner(Intent intent)
1037 throws NameNotFoundException {
1038 if (intent.getComponent() != null) {
1039 return getActivityBanner(intent.getComponent());
1040 }
1041
1042 ResolveInfo info = resolveActivity(
1043 intent, PackageManager.MATCH_DEFAULT_ONLY);
1044 if (info != null) {
1045 return info.activityInfo.loadBanner(this);
1046 }
1047
1048 throw new NameNotFoundException(intent.toUri(0));
1049 }
1050
1051 @Override
1052 public Drawable getApplicationBanner(ApplicationInfo info) {
1053 return info.loadBanner(this);
1054 }
1055
1056 @Override
1057 public Drawable getApplicationBanner(String packageName)
1058 throws NameNotFoundException {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001059 return getApplicationBanner(getApplicationInfo(packageName, sDefaultFlags));
Jose Limaf78e3122014-03-06 12:13:15 -08001060 }
1061
1062 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001063 public Drawable getActivityLogo(ComponentName activityName)
1064 throws NameNotFoundException {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001065 return getActivityInfo(activityName, sDefaultFlags).loadLogo(this);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001066 }
1067
1068 @Override
1069 public Drawable getActivityLogo(Intent intent)
1070 throws NameNotFoundException {
1071 if (intent.getComponent() != null) {
1072 return getActivityLogo(intent.getComponent());
1073 }
1074
1075 ResolveInfo info = resolveActivity(
1076 intent, PackageManager.MATCH_DEFAULT_ONLY);
1077 if (info != null) {
1078 return info.activityInfo.loadLogo(this);
1079 }
1080
1081 throw new NameNotFoundException(intent.toUri(0));
1082 }
1083
1084 @Override
1085 public Drawable getApplicationLogo(ApplicationInfo info) {
1086 return info.loadLogo(this);
1087 }
1088
1089 @Override
1090 public Drawable getApplicationLogo(String packageName)
1091 throws NameNotFoundException {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001092 return getApplicationLogo(getApplicationInfo(packageName, sDefaultFlags));
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001093 }
1094
Svetoslavc7d62f02014-09-04 15:39:54 -07001095 @Override
1096 public Drawable getUserBadgedIcon(Drawable icon, UserHandle user) {
1097 final int badgeResId = getBadgeResIdForUser(user.getIdentifier());
1098 if (badgeResId == 0) {
1099 return icon;
1100 }
1101 Drawable badgeIcon = getDrawable("system", badgeResId, null);
1102 return getBadgedDrawable(icon, badgeIcon, null, true);
1103 }
1104
1105 @Override
1106 public Drawable getUserBadgedDrawableForDensity(Drawable drawable, UserHandle user,
1107 Rect badgeLocation, int badgeDensity) {
1108 Drawable badgeDrawable = getUserBadgeForDensity(user, badgeDensity);
1109 if (badgeDrawable == null) {
1110 return drawable;
1111 }
1112 return getBadgedDrawable(drawable, badgeDrawable, badgeLocation, true);
1113 }
1114
1115 @Override
1116 public Drawable getUserBadgeForDensity(UserHandle user, int density) {
Selim Cineke6ff9462016-01-15 15:07:06 -08001117 return getManagedProfileIconForDensity(user, density,
1118 com.android.internal.R.drawable.ic_corp_badge);
1119 }
1120
1121 @Override
1122 public Drawable getUserBadgeForDensityNoBackground(UserHandle user, int density) {
1123 return getManagedProfileIconForDensity(user, density,
1124 com.android.internal.R.drawable.ic_corp_badge_no_background);
1125 }
1126
1127 private Drawable getManagedProfileIconForDensity(UserHandle user, int density,
1128 int drawableId) {
Svetoslavc7d62f02014-09-04 15:39:54 -07001129 UserInfo userInfo = getUserIfProfile(user.getIdentifier());
1130 if (userInfo != null && userInfo.isManagedProfile()) {
Vadim Tryshev093622f2016-03-02 01:51:42 +00001131 if (density <= 0) {
1132 density = mContext.getResources().getDisplayMetrics().densityDpi;
1133 }
1134 return Resources.getSystem().getDrawableForDensity(drawableId, density);
Svetoslavc7d62f02014-09-04 15:39:54 -07001135 }
1136 return null;
1137 }
1138
1139 @Override
1140 public CharSequence getUserBadgedLabel(CharSequence label, UserHandle user) {
1141 UserInfo userInfo = getUserIfProfile(user.getIdentifier());
1142 if (userInfo != null && userInfo.isManagedProfile()) {
1143 return Resources.getSystem().getString(
1144 com.android.internal.R.string.managed_profile_label_badge, label);
1145 }
1146 return label;
1147 }
1148
Alan Viveretteecd585a2015-04-13 10:32:51 -07001149 @Override
1150 public Resources getResourcesForActivity(ComponentName activityName)
1151 throws NameNotFoundException {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001152 return getResourcesForApplication(
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001153 getActivityInfo(activityName, sDefaultFlags).applicationInfo);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001154 }
1155
Alan Viveretteecd585a2015-04-13 10:32:51 -07001156 @Override
1157 public Resources getResourcesForApplication(@NonNull ApplicationInfo app)
1158 throws NameNotFoundException {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001159 if (app.packageName.equals("system")) {
1160 return mContext.mMainThread.getSystemContext().getResources();
1161 }
Jeff Sharkey8a4c9722014-06-16 13:48:42 -07001162 final boolean sameUid = (app.uid == Process.myUid());
Alan Viveretteecd585a2015-04-13 10:32:51 -07001163 final Resources r = mContext.mMainThread.getTopLevelResources(
Jeff Sharkey8a4c9722014-06-16 13:48:42 -07001164 sameUid ? app.sourceDir : app.publicSourceDir,
1165 sameUid ? app.splitSourceDirs : app.splitPublicSourceDirs,
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001166 app.resourceDirs, app.sharedLibraryFiles, Display.DEFAULT_DISPLAY,
1167 null, mContext.mPackageInfo);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001168 if (r != null) {
1169 return r;
1170 }
1171 throw new NameNotFoundException("Unable to open " + app.publicSourceDir);
1172 }
1173
Alan Viveretteecd585a2015-04-13 10:32:51 -07001174 @Override
1175 public Resources getResourcesForApplication(String appPackageName)
1176 throws NameNotFoundException {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001177 return getResourcesForApplication(
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001178 getApplicationInfo(appPackageName, sDefaultFlags));
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001179 }
1180
Amith Yamasani98edc952012-09-25 14:09:27 -07001181 /** @hide */
1182 @Override
1183 public Resources getResourcesForApplicationAsUser(String appPackageName, int userId)
1184 throws NameNotFoundException {
Jeff Sharkeyded653b2012-09-27 19:09:24 -07001185 if (userId < 0) {
1186 throw new IllegalArgumentException(
1187 "Call does not support special user #" + userId);
1188 }
1189 if ("system".equals(appPackageName)) {
1190 return mContext.mMainThread.getSystemContext().getResources();
1191 }
Amith Yamasani98edc952012-09-25 14:09:27 -07001192 try {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001193 ApplicationInfo ai = mPM.getApplicationInfo(appPackageName, sDefaultFlags, userId);
Amith Yamasani98edc952012-09-25 14:09:27 -07001194 if (ai != null) {
1195 return getResourcesForApplication(ai);
1196 }
1197 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001198 throw e.rethrowFromSystemServer();
Amith Yamasani98edc952012-09-25 14:09:27 -07001199 }
1200 throw new NameNotFoundException("Package " + appPackageName + " doesn't exist");
1201 }
1202
Jeff Sharkeycd654482016-01-08 17:42:11 -07001203 volatile int mCachedSafeMode = -1;
1204
1205 @Override
1206 public boolean isSafeMode() {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001207 try {
1208 if (mCachedSafeMode < 0) {
1209 mCachedSafeMode = mPM.isSafeMode() ? 1 : 0;
1210 }
1211 return mCachedSafeMode != 0;
1212 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001213 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001214 }
1215 }
1216
Svetoslavf7c06eb2015-06-10 18:43:22 -07001217 @Override
1218 public void addOnPermissionsChangeListener(OnPermissionsChangedListener listener) {
1219 synchronized (mPermissionListeners) {
1220 if (mPermissionListeners.get(listener) != null) {
1221 return;
1222 }
1223 OnPermissionsChangeListenerDelegate delegate =
1224 new OnPermissionsChangeListenerDelegate(listener, Looper.getMainLooper());
1225 try {
1226 mPM.addOnPermissionsChangeListener(delegate);
1227 mPermissionListeners.put(listener, delegate);
1228 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001229 throw e.rethrowFromSystemServer();
Svetoslavf7c06eb2015-06-10 18:43:22 -07001230 }
1231 }
1232 }
1233
1234 @Override
1235 public void removeOnPermissionsChangeListener(OnPermissionsChangedListener listener) {
1236 synchronized (mPermissionListeners) {
1237 IOnPermissionsChangeListener delegate = mPermissionListeners.get(listener);
1238 if (delegate != null) {
1239 try {
1240 mPM.removeOnPermissionsChangeListener(delegate);
1241 mPermissionListeners.remove(listener);
1242 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001243 throw e.rethrowFromSystemServer();
Svetoslavf7c06eb2015-06-10 18:43:22 -07001244 }
1245 }
1246 }
1247 }
1248
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001249 static void configurationChanged() {
1250 synchronized (sSync) {
1251 sIconCache.clear();
1252 sStringCache.clear();
1253 }
1254 }
1255
1256 ApplicationPackageManager(ContextImpl context,
1257 IPackageManager pm) {
1258 mContext = context;
1259 mPM = pm;
1260 }
1261
Alan Viveretteecd585a2015-04-13 10:32:51 -07001262 @Nullable
1263 private Drawable getCachedIcon(@NonNull ResourceName name) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001264 synchronized (sSync) {
Alan Viveretteecd585a2015-04-13 10:32:51 -07001265 final WeakReference<Drawable.ConstantState> wr = sIconCache.get(name);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001266 if (DEBUG_ICONS) Log.v(TAG, "Get cached weak drawable ref for "
1267 + name + ": " + wr);
1268 if (wr != null) { // we have the activity
Alan Viveretteecd585a2015-04-13 10:32:51 -07001269 final Drawable.ConstantState state = wr.get();
Romain Guy39fe17c2011-11-30 10:34:07 -08001270 if (state != null) {
1271 if (DEBUG_ICONS) {
1272 Log.v(TAG, "Get cached drawable state for " + name + ": " + state);
1273 }
1274 // Note: It's okay here to not use the newDrawable(Resources) variant
1275 // of the API. The ConstantState comes from a drawable that was
1276 // originally created by passing the proper app Resources instance
1277 // which means the state should already contain the proper
1278 // resources specific information (like density.) See
1279 // BitmapDrawable.BitmapState for instance.
1280 return state.newDrawable();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001281 }
1282 // our entry has been purged
1283 sIconCache.remove(name);
1284 }
1285 }
1286 return null;
1287 }
1288
Alan Viveretteecd585a2015-04-13 10:32:51 -07001289 private void putCachedIcon(@NonNull ResourceName name, @NonNull Drawable dr) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001290 synchronized (sSync) {
Alan Viveretteecd585a2015-04-13 10:32:51 -07001291 sIconCache.put(name, new WeakReference<>(dr.getConstantState()));
Romain Guy39fe17c2011-11-30 10:34:07 -08001292 if (DEBUG_ICONS) Log.v(TAG, "Added cached drawable state for " + name + ": " + dr);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001293 }
1294 }
1295
Romain Guy39fe17c2011-11-30 10:34:07 -08001296 static void handlePackageBroadcast(int cmd, String[] pkgList, boolean hasPkgInfo) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001297 boolean immediateGc = false;
1298 if (cmd == IApplicationThread.EXTERNAL_STORAGE_UNAVAILABLE) {
1299 immediateGc = true;
1300 }
1301 if (pkgList != null && (pkgList.length > 0)) {
1302 boolean needCleanup = false;
1303 for (String ssp : pkgList) {
1304 synchronized (sSync) {
Dianne Hackbornadd005c2013-07-17 18:43:12 -07001305 for (int i=sIconCache.size()-1; i>=0; i--) {
1306 ResourceName nm = sIconCache.keyAt(i);
1307 if (nm.packageName.equals(ssp)) {
1308 //Log.i(TAG, "Removing cached drawable for " + nm);
1309 sIconCache.removeAt(i);
1310 needCleanup = true;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001311 }
1312 }
Dianne Hackbornadd005c2013-07-17 18:43:12 -07001313 for (int i=sStringCache.size()-1; i>=0; i--) {
1314 ResourceName nm = sStringCache.keyAt(i);
1315 if (nm.packageName.equals(ssp)) {
1316 //Log.i(TAG, "Removing cached string for " + nm);
1317 sStringCache.removeAt(i);
1318 needCleanup = true;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001319 }
1320 }
1321 }
1322 }
1323 if (needCleanup || hasPkgInfo) {
1324 if (immediateGc) {
1325 // Schedule an immediate gc.
1326 Runtime.getRuntime().gc();
1327 } else {
1328 ActivityThread.currentActivityThread().scheduleGcIdler();
1329 }
1330 }
1331 }
1332 }
1333
1334 private static final class ResourceName {
1335 final String packageName;
1336 final int iconId;
1337
1338 ResourceName(String _packageName, int _iconId) {
1339 packageName = _packageName;
1340 iconId = _iconId;
1341 }
1342
1343 ResourceName(ApplicationInfo aInfo, int _iconId) {
1344 this(aInfo.packageName, _iconId);
1345 }
1346
1347 ResourceName(ComponentInfo cInfo, int _iconId) {
1348 this(cInfo.applicationInfo.packageName, _iconId);
1349 }
1350
1351 ResourceName(ResolveInfo rInfo, int _iconId) {
1352 this(rInfo.activityInfo.applicationInfo.packageName, _iconId);
1353 }
1354
1355 @Override
1356 public boolean equals(Object o) {
1357 if (this == o) return true;
1358 if (o == null || getClass() != o.getClass()) return false;
1359
1360 ResourceName that = (ResourceName) o;
1361
1362 if (iconId != that.iconId) return false;
1363 return !(packageName != null ?
1364 !packageName.equals(that.packageName) : that.packageName != null);
1365
1366 }
1367
1368 @Override
1369 public int hashCode() {
1370 int result;
1371 result = packageName.hashCode();
1372 result = 31 * result + iconId;
1373 return result;
1374 }
1375
1376 @Override
1377 public String toString() {
1378 return "{ResourceName " + packageName + " / " + iconId + "}";
1379 }
1380 }
1381
1382 private CharSequence getCachedString(ResourceName name) {
1383 synchronized (sSync) {
1384 WeakReference<CharSequence> wr = sStringCache.get(name);
1385 if (wr != null) { // we have the activity
1386 CharSequence cs = wr.get();
1387 if (cs != null) {
1388 return cs;
1389 }
1390 // our entry has been purged
1391 sStringCache.remove(name);
1392 }
1393 }
1394 return null;
1395 }
1396
1397 private void putCachedString(ResourceName name, CharSequence cs) {
1398 synchronized (sSync) {
1399 sStringCache.put(name, new WeakReference<CharSequence>(cs));
1400 }
1401 }
1402
1403 @Override
Tor Norbye7b9c9122013-05-30 16:48:33 -07001404 public CharSequence getText(String packageName, @StringRes int resid,
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001405 ApplicationInfo appInfo) {
1406 ResourceName name = new ResourceName(packageName, resid);
1407 CharSequence text = getCachedString(name);
1408 if (text != null) {
1409 return text;
1410 }
1411 if (appInfo == null) {
1412 try {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001413 appInfo = getApplicationInfo(packageName, sDefaultFlags);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001414 } catch (NameNotFoundException e) {
1415 return null;
1416 }
1417 }
1418 try {
1419 Resources r = getResourcesForApplication(appInfo);
1420 text = r.getText(resid);
1421 putCachedString(name, text);
1422 return text;
1423 } catch (NameNotFoundException e) {
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07001424 Log.w("PackageManager", "Failure retrieving resources for "
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001425 + appInfo.packageName);
1426 } catch (RuntimeException e) {
1427 // If an exception was thrown, fall through to return
1428 // default icon.
1429 Log.w("PackageManager", "Failure retrieving text 0x"
1430 + Integer.toHexString(resid) + " in package "
1431 + packageName, e);
1432 }
1433 return null;
1434 }
1435
1436 @Override
Tor Norbye7b9c9122013-05-30 16:48:33 -07001437 public XmlResourceParser getXml(String packageName, @XmlRes int resid,
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001438 ApplicationInfo appInfo) {
1439 if (appInfo == null) {
1440 try {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001441 appInfo = getApplicationInfo(packageName, sDefaultFlags);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001442 } catch (NameNotFoundException e) {
1443 return null;
1444 }
1445 }
1446 try {
1447 Resources r = getResourcesForApplication(appInfo);
1448 return r.getXml(resid);
1449 } catch (RuntimeException e) {
1450 // If an exception was thrown, fall through to return
1451 // default icon.
1452 Log.w("PackageManager", "Failure retrieving xml 0x"
1453 + Integer.toHexString(resid) + " in package "
1454 + packageName, e);
1455 } catch (NameNotFoundException e) {
Alon Albert3fa51e32010-11-11 09:24:04 -08001456 Log.w("PackageManager", "Failure retrieving resources for "
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001457 + appInfo.packageName);
1458 }
1459 return null;
1460 }
1461
1462 @Override
1463 public CharSequence getApplicationLabel(ApplicationInfo info) {
1464 return info.loadLabel(this);
1465 }
1466
1467 @Override
1468 public void installPackage(Uri packageURI, IPackageInstallObserver observer, int flags,
1469 String installerPackageName) {
Jeff Sharkey513a0742014-07-08 17:10:32 -07001470 installCommon(packageURI, new LegacyPackageInstallObserver(observer), flags,
Todd Kennedya6793232016-02-24 22:46:00 +00001471 installerPackageName, mContext.getUserId());
Christopher Tatef1977b42014-03-24 16:25:51 -07001472 }
1473
Christopher Tatef1977b42014-03-24 16:25:51 -07001474 @Override
1475 public void installPackage(Uri packageURI, PackageInstallObserver observer,
1476 int flags, String installerPackageName) {
Todd Kennedya6793232016-02-24 22:46:00 +00001477 installCommon(packageURI, observer, flags, installerPackageName, mContext.getUserId());
Jeff Sharkey513a0742014-07-08 17:10:32 -07001478 }
1479
1480 private void installCommon(Uri packageURI,
1481 PackageInstallObserver observer, int flags, String installerPackageName,
Nicolas Prevot9a80e532015-09-23 15:49:28 +01001482 int userId) {
Jeff Sharkey513a0742014-07-08 17:10:32 -07001483 if (!"file".equals(packageURI.getScheme())) {
1484 throw new UnsupportedOperationException("Only file:// URIs are supported");
1485 }
Jeff Sharkey513a0742014-07-08 17:10:32 -07001486
1487 final String originPath = packageURI.getPath();
Christopher Tatef1977b42014-03-24 16:25:51 -07001488 try {
Nicolas Prevot9a80e532015-09-23 15:49:28 +01001489 mPM.installPackageAsUser(originPath, observer.getBinder(), flags, installerPackageName,
Todd Kennedya6793232016-02-24 22:46:00 +00001490 userId);
Jeff Sharkey27b2e692016-02-25 17:40:12 -07001491 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001492 throw e.rethrowFromSystemServer();
rich cannings706e8ba2012-08-20 13:20:14 -07001493 }
1494 }
1495
1496 @Override
Nicolas Prevot9a80e532015-09-23 15:49:28 +01001497 public int installExistingPackage(String packageName) throws NameNotFoundException {
Robin Lee0e27c872015-09-28 14:37:40 +01001498 return installExistingPackageAsUser(packageName, mContext.getUserId());
Nicolas Prevot9a80e532015-09-23 15:49:28 +01001499 }
1500
1501 @Override
1502 public int installExistingPackageAsUser(String packageName, int userId)
Dianne Hackborn7767eac2012-08-23 18:25:40 -07001503 throws NameNotFoundException {
1504 try {
Nicolas Prevot9a80e532015-09-23 15:49:28 +01001505 int res = mPM.installExistingPackageAsUser(packageName, userId);
Dianne Hackborn7767eac2012-08-23 18:25:40 -07001506 if (res == INSTALL_FAILED_INVALID_URI) {
1507 throw new NameNotFoundException("Package " + packageName + " doesn't exist");
1508 }
1509 return res;
1510 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001511 throw e.rethrowFromSystemServer();
Dianne Hackborn7767eac2012-08-23 18:25:40 -07001512 }
1513 }
1514
1515 @Override
Kenny Root3a9b5fb2011-09-20 14:15:38 -07001516 public void verifyPendingInstall(int id, int response) {
Kenny Root5ab21572011-07-27 11:11:19 -07001517 try {
Kenny Root3a9b5fb2011-09-20 14:15:38 -07001518 mPM.verifyPendingInstall(id, response);
Kenny Root5ab21572011-07-27 11:11:19 -07001519 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001520 throw e.rethrowFromSystemServer();
Kenny Root5ab21572011-07-27 11:11:19 -07001521 }
1522 }
1523
1524 @Override
rich canningsd9ef3e52012-08-22 14:28:05 -07001525 public void extendVerificationTimeout(int id, int verificationCodeAtTimeout,
1526 long millisecondsToDelay) {
1527 try {
1528 mPM.extendVerificationTimeout(id, verificationCodeAtTimeout, millisecondsToDelay);
1529 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001530 throw e.rethrowFromSystemServer();
rich canningsd9ef3e52012-08-22 14:28:05 -07001531 }
1532 }
1533
1534 @Override
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001535 public void verifyIntentFilter(int id, int verificationCode, List<String> outFailedDomains) {
1536 try {
1537 mPM.verifyIntentFilter(id, verificationCode, outFailedDomains);
1538 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001539 throw e.rethrowFromSystemServer();
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001540 }
1541 }
1542
1543 @Override
Jeff Sharkeye06b4d12016-01-06 14:51:50 -07001544 public int getIntentVerificationStatusAsUser(String packageName, int userId) {
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001545 try {
1546 return mPM.getIntentVerificationStatus(packageName, userId);
1547 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001548 throw e.rethrowFromSystemServer();
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001549 }
1550 }
1551
1552 @Override
Jeff Sharkeye06b4d12016-01-06 14:51:50 -07001553 public boolean updateIntentVerificationStatusAsUser(String packageName, int status, int userId) {
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001554 try {
1555 return mPM.updateIntentVerificationStatus(packageName, status, userId);
1556 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001557 throw e.rethrowFromSystemServer();
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001558 }
1559 }
1560
1561 @Override
1562 public List<IntentFilterVerificationInfo> getIntentFilterVerifications(String packageName) {
1563 try {
1564 return mPM.getIntentFilterVerifications(packageName);
1565 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001566 throw e.rethrowFromSystemServer();
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001567 }
1568 }
1569
1570 @Override
Fabrice Di Meglio07885952015-04-06 19:41:28 -07001571 public List<IntentFilter> getAllIntentFilters(String packageName) {
1572 try {
1573 return mPM.getAllIntentFilters(packageName);
1574 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001575 throw e.rethrowFromSystemServer();
Fabrice Di Meglio07885952015-04-06 19:41:28 -07001576 }
1577 }
1578
1579 @Override
Jeff Sharkeye06b4d12016-01-06 14:51:50 -07001580 public String getDefaultBrowserPackageNameAsUser(int userId) {
Fabrice Di Meglio62271722015-04-10 17:24:02 -07001581 try {
1582 return mPM.getDefaultBrowserPackageName(userId);
1583 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001584 throw e.rethrowFromSystemServer();
Fabrice Di Meglio62271722015-04-10 17:24:02 -07001585 }
1586 }
1587
1588 @Override
Jeff Sharkeye06b4d12016-01-06 14:51:50 -07001589 public boolean setDefaultBrowserPackageNameAsUser(String packageName, int userId) {
Fabrice Di Meglio62271722015-04-10 17:24:02 -07001590 try {
1591 return mPM.setDefaultBrowserPackageName(packageName, userId);
1592 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001593 throw e.rethrowFromSystemServer();
Fabrice Di Meglio62271722015-04-10 17:24:02 -07001594 }
1595 }
1596
1597 @Override
Dianne Hackborn880119b2010-11-18 22:26:40 -08001598 public void setInstallerPackageName(String targetPackage,
1599 String installerPackageName) {
1600 try {
1601 mPM.setInstallerPackageName(targetPackage, installerPackageName);
1602 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001603 throw e.rethrowFromSystemServer();
Dianne Hackborn880119b2010-11-18 22:26:40 -08001604 }
1605 }
1606
1607 @Override
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001608 public String getInstallerPackageName(String packageName) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001609 try {
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001610 return mPM.getInstallerPackageName(packageName);
1611 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001612 throw e.rethrowFromSystemServer();
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001613 }
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001614 }
1615
1616 @Override
1617 public int getMoveStatus(int moveId) {
1618 try {
1619 return mPM.getMoveStatus(moveId);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001620 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001621 throw e.rethrowFromSystemServer();
Jeff Sharkeyb2b9ab82015-04-05 21:10:42 -07001622 }
1623 }
1624
1625 @Override
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001626 public void registerMoveCallback(MoveCallback callback, Handler handler) {
1627 synchronized (mDelegates) {
1628 final MoveCallbackDelegate delegate = new MoveCallbackDelegate(callback,
1629 handler.getLooper());
1630 try {
1631 mPM.registerMoveCallback(delegate);
1632 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001633 throw e.rethrowFromSystemServer();
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001634 }
1635 mDelegates.add(delegate);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001636 }
1637 }
1638
1639 @Override
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001640 public void unregisterMoveCallback(MoveCallback callback) {
1641 synchronized (mDelegates) {
1642 for (Iterator<MoveCallbackDelegate> i = mDelegates.iterator(); i.hasNext();) {
1643 final MoveCallbackDelegate delegate = i.next();
1644 if (delegate.mCallback == callback) {
1645 try {
1646 mPM.unregisterMoveCallback(delegate);
1647 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001648 throw e.rethrowFromSystemServer();
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001649 }
1650 i.remove();
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001651 }
1652 }
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001653 }
1654 }
1655
1656 @Override
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001657 public int movePackage(String packageName, VolumeInfo vol) {
1658 try {
1659 final String volumeUuid;
1660 if (VolumeInfo.ID_PRIVATE_INTERNAL.equals(vol.id)) {
1661 volumeUuid = StorageManager.UUID_PRIVATE_INTERNAL;
1662 } else if (vol.isPrimaryPhysical()) {
1663 volumeUuid = StorageManager.UUID_PRIMARY_PHYSICAL;
1664 } else {
1665 volumeUuid = Preconditions.checkNotNull(vol.fsUuid);
1666 }
1667
1668 return mPM.movePackage(packageName, volumeUuid);
1669 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001670 throw e.rethrowFromSystemServer();
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001671 }
1672 }
1673
1674 @Override
1675 public @Nullable VolumeInfo getPackageCurrentVolume(ApplicationInfo app) {
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001676 final StorageManager storage = mContext.getSystemService(StorageManager.class);
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001677 if (app.isInternal()) {
1678 return storage.findVolumeById(VolumeInfo.ID_PRIVATE_INTERNAL);
1679 } else if (app.isExternalAsec()) {
1680 return storage.getPrimaryPhysicalVolume();
1681 } else {
1682 return storage.findVolumeByUuid(app.volumeUuid);
1683 }
1684 }
1685
1686 @Override
1687 public @NonNull List<VolumeInfo> getPackageCandidateVolumes(ApplicationInfo app) {
1688 final StorageManager storage = mContext.getSystemService(StorageManager.class);
1689 final VolumeInfo currentVol = getPackageCurrentVolume(app);
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001690 final List<VolumeInfo> vols = storage.getVolumes();
1691 final List<VolumeInfo> candidates = new ArrayList<>();
1692 for (VolumeInfo vol : vols) {
Todd Kennedyf39ca8f2015-08-07 14:15:07 -07001693 if (Objects.equals(vol, currentVol) || isPackageCandidateVolume(mContext, app, vol)) {
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001694 candidates.add(vol);
1695 }
1696 }
1697 return candidates;
1698 }
1699
Makoto Onukif34db0a2016-02-17 11:17:15 -08001700 private boolean isPackageCandidateVolume(
Todd Kennedyf39ca8f2015-08-07 14:15:07 -07001701 ContextImpl context, ApplicationInfo app, VolumeInfo vol) {
1702 final boolean forceAllowOnExternal = Settings.Global.getInt(
1703 context.getContentResolver(), Settings.Global.FORCE_ALLOW_ON_EXTERNAL, 0) != 0;
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001704 // Private internal is always an option
1705 if (VolumeInfo.ID_PRIVATE_INTERNAL.equals(vol.getId())) {
1706 return true;
1707 }
1708
1709 // System apps and apps demanding internal storage can't be moved
1710 // anywhere else
Todd Kennedyf39ca8f2015-08-07 14:15:07 -07001711 if (app.isSystemApp()) {
1712 return false;
1713 }
1714 if (!forceAllowOnExternal
Dianne Hackborn30a4e6d2015-10-12 17:14:56 -07001715 && (app.installLocation == PackageInfo.INSTALL_LOCATION_INTERNAL_ONLY
1716 || app.installLocation == PackageInfo.INSTALL_LOCATION_UNSPECIFIED)) {
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001717 return false;
1718 }
1719
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001720 // Gotta be able to write there
1721 if (!vol.isMountedWritable()) {
1722 return false;
1723 }
1724
1725 // Moving into an ASEC on public primary is only option internal
1726 if (vol.isPrimaryPhysical()) {
1727 return app.isInternal();
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001728 }
1729
Makoto Onukif34db0a2016-02-17 11:17:15 -08001730 // Some apps can't be moved. (e.g. device admins)
1731 try {
1732 if (mPM.isPackageDeviceAdminOnAnyUser(app.packageName)) {
1733 return false;
1734 }
1735 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001736 throw e.rethrowFromSystemServer();
Makoto Onukif34db0a2016-02-17 11:17:15 -08001737 }
1738
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001739 // Otherwise we can move to any private volume
1740 return (vol.getType() == VolumeInfo.TYPE_PRIVATE);
1741 }
1742
1743 @Override
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001744 public int movePrimaryStorage(VolumeInfo vol) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001745 try {
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001746 final String volumeUuid;
1747 if (VolumeInfo.ID_PRIVATE_INTERNAL.equals(vol.id)) {
1748 volumeUuid = StorageManager.UUID_PRIVATE_INTERNAL;
1749 } else if (vol.isPrimaryPhysical()) {
1750 volumeUuid = StorageManager.UUID_PRIMARY_PHYSICAL;
1751 } else {
1752 volumeUuid = Preconditions.checkNotNull(vol.fsUuid);
1753 }
1754
1755 return mPM.movePrimaryStorage(volumeUuid);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001756 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001757 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001758 }
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001759 }
1760
Jeff Sharkey275e3e42015-04-24 16:10:32 -07001761 @Override
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001762 public @Nullable VolumeInfo getPrimaryStorageCurrentVolume() {
1763 final StorageManager storage = mContext.getSystemService(StorageManager.class);
1764 final String volumeUuid = storage.getPrimaryStorageUuid();
Jeff Sharkey50a05452015-04-29 11:24:52 -07001765 return storage.findVolumeByQualifiedUuid(volumeUuid);
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001766 }
1767
Jeff Sharkey275e3e42015-04-24 16:10:32 -07001768 @Override
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001769 public @NonNull List<VolumeInfo> getPrimaryStorageCandidateVolumes() {
1770 final StorageManager storage = mContext.getSystemService(StorageManager.class);
1771 final VolumeInfo currentVol = getPrimaryStorageCurrentVolume();
1772 final List<VolumeInfo> vols = storage.getVolumes();
1773 final List<VolumeInfo> candidates = new ArrayList<>();
Jeff Sharkeyfced5342015-05-10 14:53:34 -07001774 if (Objects.equals(StorageManager.UUID_PRIMARY_PHYSICAL,
1775 storage.getPrimaryStorageUuid()) && currentVol != null) {
1776 // TODO: support moving primary physical to emulated volume
1777 candidates.add(currentVol);
1778 } else {
1779 for (VolumeInfo vol : vols) {
1780 if (Objects.equals(vol, currentVol) || isPrimaryStorageCandidateVolume(vol)) {
1781 candidates.add(vol);
1782 }
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001783 }
1784 }
1785 return candidates;
1786 }
1787
1788 private static boolean isPrimaryStorageCandidateVolume(VolumeInfo vol) {
1789 // Private internal is always an option
1790 if (VolumeInfo.ID_PRIVATE_INTERNAL.equals(vol.getId())) {
1791 return true;
1792 }
1793
1794 // Gotta be able to write there
1795 if (!vol.isMountedWritable()) {
1796 return false;
1797 }
1798
Jeff Sharkeyfced5342015-05-10 14:53:34 -07001799 // We can move to any private volume
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001800 return (vol.getType() == VolumeInfo.TYPE_PRIVATE);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001801 }
1802
1803 @Override
1804 public void deletePackage(String packageName, IPackageDeleteObserver observer, int flags) {
Robin Lee0e27c872015-09-28 14:37:40 +01001805 deletePackageAsUser(packageName, observer, flags, mContext.getUserId());
Nicolas Prevot9a80e532015-09-23 15:49:28 +01001806 }
1807
1808 @Override
1809 public void deletePackageAsUser(String packageName, IPackageDeleteObserver observer, int flags,
1810 int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001811 try {
Nicolas Prevot9a80e532015-09-23 15:49:28 +01001812 mPM.deletePackageAsUser(packageName, observer, userId, flags);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001813 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001814 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001815 }
1816 }
Jeff Sharkeyfbd0e9f2014-08-06 16:34:34 -07001817
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001818 @Override
1819 public void clearApplicationUserData(String packageName,
1820 IPackageDataObserver observer) {
1821 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -07001822 mPM.clearApplicationUserData(packageName, observer, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001823 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001824 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001825 }
1826 }
1827 @Override
1828 public void deleteApplicationCacheFiles(String packageName,
1829 IPackageDataObserver observer) {
1830 try {
1831 mPM.deleteApplicationCacheFiles(packageName, observer);
1832 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001833 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001834 }
1835 }
Jeff Sharkey529f91f2015-04-18 20:23:13 -07001836
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001837 @Override
Jeff Sharkey529f91f2015-04-18 20:23:13 -07001838 public void freeStorageAndNotify(String volumeUuid, long idealStorageSize,
1839 IPackageDataObserver observer) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001840 try {
Jeff Sharkey529f91f2015-04-18 20:23:13 -07001841 mPM.freeStorageAndNotify(volumeUuid, idealStorageSize, observer);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001842 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001843 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001844 }
1845 }
1846
1847 @Override
Jeff Sharkey529f91f2015-04-18 20:23:13 -07001848 public void freeStorage(String volumeUuid, long freeStorageSize, IntentSender pi) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001849 try {
Jeff Sharkey529f91f2015-04-18 20:23:13 -07001850 mPM.freeStorage(volumeUuid, freeStorageSize, pi);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001851 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001852 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001853 }
1854 }
1855
1856 @Override
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00001857 public String[] setPackagesSuspendedAsUser(String[] packageNames, boolean suspended,
1858 int userId) {
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00001859 try {
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00001860 return mPM.setPackagesSuspendedAsUser(packageNames, suspended, userId);
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00001861 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001862 throw e.rethrowFromSystemServer();
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00001863 }
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00001864 }
1865
1866 @Override
Andrei Stingaceanu355b2322016-02-12 16:43:51 +00001867 public boolean isPackageSuspendedForUser(String packageName, int userId) {
1868 try {
1869 return mPM.isPackageSuspendedForUser(packageName, userId);
1870 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001871 throw e.rethrowFromSystemServer();
Andrei Stingaceanu355b2322016-02-12 16:43:51 +00001872 }
Andrei Stingaceanu355b2322016-02-12 16:43:51 +00001873 }
1874
1875 @Override
Jeff Sharkeye06b4d12016-01-06 14:51:50 -07001876 public void getPackageSizeInfoAsUser(String packageName, int userHandle,
Dianne Hackborn0c380492012-08-20 17:23:30 -07001877 IPackageStatsObserver observer) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001878 try {
Dianne Hackborn0c380492012-08-20 17:23:30 -07001879 mPM.getPackageSizeInfo(packageName, userHandle, observer);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001880 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001881 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001882 }
1883 }
1884 @Override
1885 public void addPackageToPreferred(String packageName) {
1886 try {
1887 mPM.addPackageToPreferred(packageName);
1888 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001889 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001890 }
1891 }
1892
1893 @Override
1894 public void removePackageFromPreferred(String packageName) {
1895 try {
1896 mPM.removePackageFromPreferred(packageName);
1897 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001898 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001899 }
1900 }
1901
1902 @Override
1903 public List<PackageInfo> getPreferredPackages(int flags) {
1904 try {
1905 return mPM.getPreferredPackages(flags);
1906 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001907 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001908 }
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001909 }
1910
1911 @Override
1912 public void addPreferredActivity(IntentFilter filter,
1913 int match, ComponentName[] set, ComponentName activity) {
1914 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -07001915 mPM.addPreferredActivity(filter, match, set, activity, mContext.getUserId());
Amith Yamasania3f133a2012-08-09 17:11:28 -07001916 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001917 throw e.rethrowFromSystemServer();
Amith Yamasania3f133a2012-08-09 17:11:28 -07001918 }
1919 }
1920
1921 @Override
Jeff Sharkeye06b4d12016-01-06 14:51:50 -07001922 public void addPreferredActivityAsUser(IntentFilter filter, int match,
Amith Yamasania3f133a2012-08-09 17:11:28 -07001923 ComponentName[] set, ComponentName activity, int userId) {
1924 try {
1925 mPM.addPreferredActivity(filter, match, set, activity, userId);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001926 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001927 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001928 }
1929 }
1930
1931 @Override
1932 public void replacePreferredActivity(IntentFilter filter,
1933 int match, ComponentName[] set, ComponentName activity) {
1934 try {
Robin Lee0e27c872015-09-28 14:37:40 +01001935 mPM.replacePreferredActivity(filter, match, set, activity, mContext.getUserId());
Amith Yamasani41c1ded2014-08-05 11:15:05 -07001936 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001937 throw e.rethrowFromSystemServer();
Amith Yamasani41c1ded2014-08-05 11:15:05 -07001938 }
1939 }
1940
1941 @Override
1942 public void replacePreferredActivityAsUser(IntentFilter filter,
1943 int match, ComponentName[] set, ComponentName activity,
1944 int userId) {
1945 try {
1946 mPM.replacePreferredActivity(filter, match, set, activity, userId);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001947 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001948 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001949 }
1950 }
1951
1952 @Override
1953 public void clearPackagePreferredActivities(String packageName) {
1954 try {
1955 mPM.clearPackagePreferredActivities(packageName);
1956 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001957 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001958 }
1959 }
1960
1961 @Override
1962 public int getPreferredActivities(List<IntentFilter> outFilters,
1963 List<ComponentName> outActivities, String packageName) {
1964 try {
1965 return mPM.getPreferredActivities(outFilters, outActivities, packageName);
1966 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001967 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001968 }
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001969 }
1970
1971 @Override
Christopher Tatea2a0850d2013-09-05 16:38:58 -07001972 public ComponentName getHomeActivities(List<ResolveInfo> outActivities) {
1973 try {
1974 return mPM.getHomeActivities(outActivities);
1975 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001976 throw e.rethrowFromSystemServer();
Christopher Tatea2a0850d2013-09-05 16:38:58 -07001977 }
Christopher Tatea2a0850d2013-09-05 16:38:58 -07001978 }
1979
1980 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001981 public void setComponentEnabledSetting(ComponentName componentName,
1982 int newState, int flags) {
1983 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -07001984 mPM.setComponentEnabledSetting(componentName, newState, flags, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001985 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001986 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001987 }
1988 }
1989
1990 @Override
1991 public int getComponentEnabledSetting(ComponentName componentName) {
1992 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -07001993 return mPM.getComponentEnabledSetting(componentName, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001994 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001995 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001996 }
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001997 }
1998
1999 @Override
2000 public void setApplicationEnabledSetting(String packageName,
2001 int newState, int flags) {
2002 try {
Dianne Hackborn3fa3c28a2013-03-26 16:15:41 -07002003 mPM.setApplicationEnabledSetting(packageName, newState, flags,
Dianne Hackborn95d78532013-09-11 09:51:14 -07002004 mContext.getUserId(), mContext.getOpPackageName());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002005 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002006 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002007 }
2008 }
2009
2010 @Override
2011 public int getApplicationEnabledSetting(String packageName) {
2012 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -07002013 return mPM.getApplicationEnabledSetting(packageName, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002014 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002015 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002016 }
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002017 }
2018
Amith Yamasani655d0e22013-06-12 14:19:10 -07002019 @Override
Amith Yamasanie5bcff62014-07-19 15:44:09 -07002020 public boolean setApplicationHiddenSettingAsUser(String packageName, boolean hidden,
Amith Yamasani655d0e22013-06-12 14:19:10 -07002021 UserHandle user) {
2022 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07002023 return mPM.setApplicationHiddenSettingAsUser(packageName, hidden,
Amith Yamasani655d0e22013-06-12 14:19:10 -07002024 user.getIdentifier());
Jeff Sharkey27b2e692016-02-25 17:40:12 -07002025 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002026 throw e.rethrowFromSystemServer();
Amith Yamasani655d0e22013-06-12 14:19:10 -07002027 }
Amith Yamasani655d0e22013-06-12 14:19:10 -07002028 }
2029
2030 @Override
Amith Yamasanie5bcff62014-07-19 15:44:09 -07002031 public boolean getApplicationHiddenSettingAsUser(String packageName, UserHandle user) {
Amith Yamasani655d0e22013-06-12 14:19:10 -07002032 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07002033 return mPM.getApplicationHiddenSettingAsUser(packageName, user.getIdentifier());
Jeff Sharkey27b2e692016-02-25 17:40:12 -07002034 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002035 throw e.rethrowFromSystemServer();
Amith Yamasani655d0e22013-06-12 14:19:10 -07002036 }
Amith Yamasani655d0e22013-06-12 14:19:10 -07002037 }
2038
dcashmanc6f22492014-08-14 09:54:51 -07002039 /** @hide */
dcashman9d2f4412014-06-09 09:27:54 -07002040 @Override
2041 public KeySet getKeySetByAlias(String packageName, String alias) {
2042 Preconditions.checkNotNull(packageName);
2043 Preconditions.checkNotNull(alias);
dcashman9d2f4412014-06-09 09:27:54 -07002044 try {
Jeff Sharkey27b2e692016-02-25 17:40:12 -07002045 return mPM.getKeySetByAlias(packageName, alias);
dcashman9d2f4412014-06-09 09:27:54 -07002046 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002047 throw e.rethrowFromSystemServer();
dcashman9d2f4412014-06-09 09:27:54 -07002048 }
dcashman9d2f4412014-06-09 09:27:54 -07002049 }
2050
dcashmanc6f22492014-08-14 09:54:51 -07002051 /** @hide */
dcashman9d2f4412014-06-09 09:27:54 -07002052 @Override
2053 public KeySet getSigningKeySet(String packageName) {
2054 Preconditions.checkNotNull(packageName);
dcashman9d2f4412014-06-09 09:27:54 -07002055 try {
Jeff Sharkey27b2e692016-02-25 17:40:12 -07002056 return mPM.getSigningKeySet(packageName);
dcashman9d2f4412014-06-09 09:27:54 -07002057 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002058 throw e.rethrowFromSystemServer();
dcashman9d2f4412014-06-09 09:27:54 -07002059 }
dcashman9d2f4412014-06-09 09:27:54 -07002060 }
2061
dcashmanc6f22492014-08-14 09:54:51 -07002062 /** @hide */
dcashman9d2f4412014-06-09 09:27:54 -07002063 @Override
2064 public boolean isSignedBy(String packageName, KeySet ks) {
2065 Preconditions.checkNotNull(packageName);
2066 Preconditions.checkNotNull(ks);
dcashman9d2f4412014-06-09 09:27:54 -07002067 try {
dcashmanc6f22492014-08-14 09:54:51 -07002068 return mPM.isPackageSignedByKeySet(packageName, ks);
dcashman9d2f4412014-06-09 09:27:54 -07002069 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002070 throw e.rethrowFromSystemServer();
dcashman9d2f4412014-06-09 09:27:54 -07002071 }
2072 }
2073
dcashmanc6f22492014-08-14 09:54:51 -07002074 /** @hide */
dcashman9d2f4412014-06-09 09:27:54 -07002075 @Override
2076 public boolean isSignedByExactly(String packageName, KeySet ks) {
2077 Preconditions.checkNotNull(packageName);
2078 Preconditions.checkNotNull(ks);
dcashman9d2f4412014-06-09 09:27:54 -07002079 try {
dcashmanc6f22492014-08-14 09:54:51 -07002080 return mPM.isPackageSignedByKeySetExactly(packageName, ks);
dcashman9d2f4412014-06-09 09:27:54 -07002081 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002082 throw e.rethrowFromSystemServer();
dcashman9d2f4412014-06-09 09:27:54 -07002083 }
2084 }
2085
Kenny Root0aaa0d92011-09-12 16:42:55 -07002086 /**
2087 * @hide
2088 */
2089 @Override
2090 public VerifierDeviceIdentity getVerifierDeviceIdentity() {
2091 try {
2092 return mPM.getVerifierDeviceIdentity();
2093 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002094 throw e.rethrowFromSystemServer();
Kenny Root0aaa0d92011-09-12 16:42:55 -07002095 }
Kenny Root0aaa0d92011-09-12 16:42:55 -07002096 }
2097
Jeff Hao9f60c082014-10-28 18:51:07 -07002098 /**
2099 * @hide
2100 */
2101 @Override
2102 public boolean isUpgrade() {
2103 try {
2104 return mPM.isUpgrade();
2105 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002106 throw e.rethrowFromSystemServer();
Jeff Hao9f60c082014-10-28 18:51:07 -07002107 }
2108 }
2109
Jeff Sharkey3a44f3f2014-04-28 17:36:31 -07002110 @Override
Jeff Sharkey16c8e3f2014-07-24 17:08:17 -07002111 public PackageInstaller getPackageInstaller() {
2112 synchronized (mLock) {
2113 if (mInstaller == null) {
2114 try {
Jeff Sharkeya0907432014-08-15 10:23:11 -07002115 mInstaller = new PackageInstaller(mContext, this, mPM.getPackageInstaller(),
Jeff Sharkey16c8e3f2014-07-24 17:08:17 -07002116 mContext.getPackageName(), mContext.getUserId());
2117 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002118 throw e.rethrowFromSystemServer();
Jeff Sharkey16c8e3f2014-07-24 17:08:17 -07002119 }
2120 }
2121 return mInstaller;
Jeff Sharkey3a44f3f2014-04-28 17:36:31 -07002122 }
2123 }
2124
Jeff Sharkey6c833e02014-07-14 22:44:30 -07002125 @Override
2126 public boolean isPackageAvailable(String packageName) {
2127 try {
2128 return mPM.isPackageAvailable(packageName, mContext.getUserId());
2129 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002130 throw e.rethrowFromSystemServer();
Jeff Sharkey6c833e02014-07-14 22:44:30 -07002131 }
2132 }
2133
Nicolas Prevotc79586e2014-05-06 12:47:57 +01002134 /**
2135 * @hide
2136 */
2137 @Override
Nicolas Prevot63798c52014-05-27 13:22:38 +01002138 public void addCrossProfileIntentFilter(IntentFilter filter, int sourceUserId, int targetUserId,
2139 int flags) {
Nicolas Prevotc79586e2014-05-06 12:47:57 +01002140 try {
Nicolas Prevot3f7777f2014-07-24 15:58:39 +01002141 mPM.addCrossProfileIntentFilter(filter, mContext.getOpPackageName(),
Nicolas Prevot4b8d5822015-03-05 15:20:49 +00002142 sourceUserId, targetUserId, flags);
Nicolas Prevotc79586e2014-05-06 12:47:57 +01002143 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002144 throw e.rethrowFromSystemServer();
Nicolas Prevotc79586e2014-05-06 12:47:57 +01002145 }
2146 }
2147
2148 /**
2149 * @hide
2150 */
2151 @Override
Nicolas Prevot81948992014-05-16 18:25:26 +01002152 public void clearCrossProfileIntentFilters(int sourceUserId) {
Nicolas Prevotc79586e2014-05-06 12:47:57 +01002153 try {
Nicolas Prevot4b8d5822015-03-05 15:20:49 +00002154 mPM.clearCrossProfileIntentFilters(sourceUserId, mContext.getOpPackageName());
Nicolas Prevotc79586e2014-05-06 12:47:57 +01002155 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002156 throw e.rethrowFromSystemServer();
Nicolas Prevotc79586e2014-05-06 12:47:57 +01002157 }
2158 }
2159
Nicolas Prevot88cc3462014-05-14 14:51:48 +01002160 /**
2161 * @hide
2162 */
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +01002163 public Drawable loadItemIcon(PackageItemInfo itemInfo, ApplicationInfo appInfo) {
Benjamin Franzec2d48b2014-10-01 15:38:43 +01002164 Drawable dr = loadUnbadgedItemIcon(itemInfo, appInfo);
2165 if (itemInfo.showUserIcon != UserHandle.USER_NULL) {
2166 return dr;
2167 }
2168 return getUserBadgedIcon(dr, new UserHandle(mContext.getUserId()));
2169 }
2170
2171 /**
2172 * @hide
2173 */
2174 public Drawable loadUnbadgedItemIcon(PackageItemInfo itemInfo, ApplicationInfo appInfo) {
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +01002175 if (itemInfo.showUserIcon != UserHandle.USER_NULL) {
Alexandra Gherghina64d4dca2014-08-28 18:26:56 +01002176 Bitmap bitmap = getUserManager().getUserIcon(itemInfo.showUserIcon);
2177 if (bitmap == null) {
2178 return UserIcons.getDefaultUserIcon(itemInfo.showUserIcon, /* light= */ false);
2179 }
2180 return new BitmapDrawable(bitmap);
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +01002181 }
Alexandra Gherghinadb811db2014-08-29 13:43:59 +01002182 Drawable dr = null;
2183 if (itemInfo.packageName != null) {
2184 dr = getDrawable(itemInfo.packageName, itemInfo.icon, appInfo);
2185 }
Alexandra Gherghinaa71e3902014-07-25 20:03:47 +01002186 if (dr == null) {
Alexandra Gherghinaa7093142014-07-30 13:43:39 +01002187 dr = itemInfo.loadDefaultIcon(this);
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +01002188 }
Benjamin Franzec2d48b2014-10-01 15:38:43 +01002189 return dr;
Svetoslavc7d62f02014-09-04 15:39:54 -07002190 }
2191
2192 private Drawable getBadgedDrawable(Drawable drawable, Drawable badgeDrawable,
2193 Rect badgeLocation, boolean tryBadgeInPlace) {
2194 final int badgedWidth = drawable.getIntrinsicWidth();
2195 final int badgedHeight = drawable.getIntrinsicHeight();
2196 final boolean canBadgeInPlace = tryBadgeInPlace
2197 && (drawable instanceof BitmapDrawable)
2198 && ((BitmapDrawable) drawable).getBitmap().isMutable();
2199
2200 final Bitmap bitmap;
2201 if (canBadgeInPlace) {
2202 bitmap = ((BitmapDrawable) drawable).getBitmap();
2203 } else {
2204 bitmap = Bitmap.createBitmap(badgedWidth, badgedHeight, Bitmap.Config.ARGB_8888);
2205 }
2206 Canvas canvas = new Canvas(bitmap);
2207
2208 if (!canBadgeInPlace) {
2209 drawable.setBounds(0, 0, badgedWidth, badgedHeight);
2210 drawable.draw(canvas);
2211 }
2212
2213 if (badgeLocation != null) {
2214 if (badgeLocation.left < 0 || badgeLocation.top < 0
2215 || badgeLocation.width() > badgedWidth || badgeLocation.height() > badgedHeight) {
2216 throw new IllegalArgumentException("Badge location " + badgeLocation
2217 + " not in badged drawable bounds "
2218 + new Rect(0, 0, badgedWidth, badgedHeight));
2219 }
2220 badgeDrawable.setBounds(0, 0, badgeLocation.width(), badgeLocation.height());
2221
2222 canvas.save();
2223 canvas.translate(badgeLocation.left, badgeLocation.top);
2224 badgeDrawable.draw(canvas);
2225 canvas.restore();
2226 } else {
2227 badgeDrawable.setBounds(0, 0, badgedWidth, badgedHeight);
2228 badgeDrawable.draw(canvas);
2229 }
2230
2231 if (!canBadgeInPlace) {
2232 BitmapDrawable mergedDrawable = new BitmapDrawable(mContext.getResources(), bitmap);
2233
2234 if (drawable instanceof BitmapDrawable) {
2235 BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
2236 mergedDrawable.setTargetDensity(bitmapDrawable.getBitmap().getDensity());
2237 }
2238
2239 return mergedDrawable;
2240 }
2241
2242 return drawable;
2243 }
2244
2245 private int getBadgeResIdForUser(int userHandle) {
2246 // Return the framework-provided badge.
2247 UserInfo userInfo = getUserIfProfile(userHandle);
2248 if (userInfo != null && userInfo.isManagedProfile()) {
2249 return com.android.internal.R.drawable.ic_corp_icon_badge;
2250 }
2251 return 0;
2252 }
2253
2254 private UserInfo getUserIfProfile(int userHandle) {
Robin Lee0e27c872015-09-28 14:37:40 +01002255 List<UserInfo> userProfiles = getUserManager().getProfiles(mContext.getUserId());
Svetoslavc7d62f02014-09-04 15:39:54 -07002256 for (UserInfo user : userProfiles) {
2257 if (user.id == userHandle) {
2258 return user;
2259 }
2260 }
2261 return null;
Nicolas Prevot88cc3462014-05-14 14:51:48 +01002262 }
2263
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002264 /** {@hide} */
2265 private static class MoveCallbackDelegate extends IPackageMoveObserver.Stub implements
2266 Handler.Callback {
Jeff Sharkey50a05452015-04-29 11:24:52 -07002267 private static final int MSG_CREATED = 1;
2268 private static final int MSG_STATUS_CHANGED = 2;
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002269
2270 final MoveCallback mCallback;
2271 final Handler mHandler;
2272
2273 public MoveCallbackDelegate(MoveCallback callback, Looper looper) {
2274 mCallback = callback;
2275 mHandler = new Handler(looper, this);
2276 }
2277
2278 @Override
2279 public boolean handleMessage(Message msg) {
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002280 switch (msg.what) {
Jeff Sharkey50a05452015-04-29 11:24:52 -07002281 case MSG_CREATED: {
Jeff Sharkeyb36586a2015-04-27 08:42:28 -07002282 final SomeArgs args = (SomeArgs) msg.obj;
Jeff Sharkey50a05452015-04-29 11:24:52 -07002283 mCallback.onCreated(args.argi1, (Bundle) args.arg2);
Jeff Sharkeyb36586a2015-04-27 08:42:28 -07002284 args.recycle();
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002285 return true;
Jeff Sharkey50a05452015-04-29 11:24:52 -07002286 }
2287 case MSG_STATUS_CHANGED: {
2288 final SomeArgs args = (SomeArgs) msg.obj;
2289 mCallback.onStatusChanged(args.argi1, args.argi2, (long) args.arg3);
2290 args.recycle();
2291 return true;
2292 }
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002293 }
2294 return false;
2295 }
2296
2297 @Override
Jeff Sharkey50a05452015-04-29 11:24:52 -07002298 public void onCreated(int moveId, Bundle extras) {
Jeff Sharkeyb36586a2015-04-27 08:42:28 -07002299 final SomeArgs args = SomeArgs.obtain();
2300 args.argi1 = moveId;
Jeff Sharkey50a05452015-04-29 11:24:52 -07002301 args.arg2 = extras;
2302 mHandler.obtainMessage(MSG_CREATED, args).sendToTarget();
2303 }
2304
2305 @Override
2306 public void onStatusChanged(int moveId, int status, long estMillis) {
2307 final SomeArgs args = SomeArgs.obtain();
2308 args.argi1 = moveId;
2309 args.argi2 = status;
2310 args.arg3 = estMillis;
Jeff Sharkeyb36586a2015-04-27 08:42:28 -07002311 mHandler.obtainMessage(MSG_STATUS_CHANGED, args).sendToTarget();
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002312 }
2313 }
2314
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002315 private final ContextImpl mContext;
2316 private final IPackageManager mPM;
2317
2318 private static final Object sSync = new Object();
Dianne Hackbornadd005c2013-07-17 18:43:12 -07002319 private static ArrayMap<ResourceName, WeakReference<Drawable.ConstantState>> sIconCache
2320 = new ArrayMap<ResourceName, WeakReference<Drawable.ConstantState>>();
2321 private static ArrayMap<ResourceName, WeakReference<CharSequence>> sStringCache
2322 = new ArrayMap<ResourceName, WeakReference<CharSequence>>();
Svetoslavf7c06eb2015-06-10 18:43:22 -07002323
2324 private final Map<OnPermissionsChangedListener, IOnPermissionsChangeListener>
2325 mPermissionListeners = new ArrayMap<>();
2326
2327 public class OnPermissionsChangeListenerDelegate extends IOnPermissionsChangeListener.Stub
2328 implements Handler.Callback{
2329 private static final int MSG_PERMISSIONS_CHANGED = 1;
2330
2331 private final OnPermissionsChangedListener mListener;
2332 private final Handler mHandler;
2333
2334
2335 public OnPermissionsChangeListenerDelegate(OnPermissionsChangedListener listener,
2336 Looper looper) {
2337 mListener = listener;
2338 mHandler = new Handler(looper, this);
2339 }
2340
2341 @Override
2342 public void onPermissionsChanged(int uid) {
2343 mHandler.obtainMessage(MSG_PERMISSIONS_CHANGED, uid, 0).sendToTarget();
2344 }
2345
2346 @Override
2347 public boolean handleMessage(Message msg) {
2348 switch (msg.what) {
2349 case MSG_PERMISSIONS_CHANGED: {
2350 final int uid = msg.arg1;
2351 mListener.onPermissionsChanged(uid);
2352 return true;
2353 }
2354 }
2355 return false;
2356 }
2357 }
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002358}