blob: c8411119430f2e8af73f031d2e118e4e7ac7acb9 [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
Vadim Tryshev66ae66a2016-02-18 15:41:21 -08001096 public Drawable getManagedUserBadgedDrawable(Drawable drawable, Rect badgeLocation,
1097 int badgeDensity) {
1098 Drawable badgeDrawable = getDrawableForDensity(
1099 com.android.internal.R.drawable.ic_corp_badge, badgeDensity);
1100 return getBadgedDrawable(drawable, badgeDrawable, badgeLocation, true);
1101 }
1102
1103 @Override
Svetoslavc7d62f02014-09-04 15:39:54 -07001104 public Drawable getUserBadgedIcon(Drawable icon, UserHandle user) {
1105 final int badgeResId = getBadgeResIdForUser(user.getIdentifier());
1106 if (badgeResId == 0) {
1107 return icon;
1108 }
1109 Drawable badgeIcon = getDrawable("system", badgeResId, null);
1110 return getBadgedDrawable(icon, badgeIcon, null, true);
1111 }
1112
1113 @Override
1114 public Drawable getUserBadgedDrawableForDensity(Drawable drawable, UserHandle user,
1115 Rect badgeLocation, int badgeDensity) {
1116 Drawable badgeDrawable = getUserBadgeForDensity(user, badgeDensity);
1117 if (badgeDrawable == null) {
1118 return drawable;
1119 }
1120 return getBadgedDrawable(drawable, badgeDrawable, badgeLocation, true);
1121 }
1122
1123 @Override
1124 public Drawable getUserBadgeForDensity(UserHandle user, int density) {
Vadim Tryshev66ae66a2016-02-18 15:41:21 -08001125 return getManagedProfileIconForDensity(user, com.android.internal.R.drawable.ic_corp_badge,
1126 density);
Selim Cineke6ff9462016-01-15 15:07:06 -08001127 }
1128
1129 @Override
1130 public Drawable getUserBadgeForDensityNoBackground(UserHandle user, int density) {
Vadim Tryshev66ae66a2016-02-18 15:41:21 -08001131 return getManagedProfileIconForDensity(user,
1132 com.android.internal.R.drawable.ic_corp_badge_no_background, density);
Selim Cineke6ff9462016-01-15 15:07:06 -08001133 }
1134
Vadim Tryshev66ae66a2016-02-18 15:41:21 -08001135 private Drawable getDrawableForDensity(int drawableId, int density) {
1136 if (density <= 0) {
1137 density = mContext.getResources().getDisplayMetrics().densityDpi;
1138 }
1139 return Resources.getSystem().getDrawableForDensity(drawableId, density);
1140 }
1141
1142 private Drawable getManagedProfileIconForDensity(UserHandle user, int drawableId, int density) {
Svetoslavc7d62f02014-09-04 15:39:54 -07001143 UserInfo userInfo = getUserIfProfile(user.getIdentifier());
1144 if (userInfo != null && userInfo.isManagedProfile()) {
Vadim Tryshev66ae66a2016-02-18 15:41:21 -08001145 return getDrawableForDensity(drawableId, density);
Svetoslavc7d62f02014-09-04 15:39:54 -07001146 }
1147 return null;
1148 }
1149
1150 @Override
1151 public CharSequence getUserBadgedLabel(CharSequence label, UserHandle user) {
1152 UserInfo userInfo = getUserIfProfile(user.getIdentifier());
1153 if (userInfo != null && userInfo.isManagedProfile()) {
1154 return Resources.getSystem().getString(
1155 com.android.internal.R.string.managed_profile_label_badge, label);
1156 }
1157 return label;
1158 }
1159
Alan Viveretteecd585a2015-04-13 10:32:51 -07001160 @Override
1161 public Resources getResourcesForActivity(ComponentName activityName)
1162 throws NameNotFoundException {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001163 return getResourcesForApplication(
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001164 getActivityInfo(activityName, sDefaultFlags).applicationInfo);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001165 }
1166
Alan Viveretteecd585a2015-04-13 10:32:51 -07001167 @Override
1168 public Resources getResourcesForApplication(@NonNull ApplicationInfo app)
1169 throws NameNotFoundException {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001170 if (app.packageName.equals("system")) {
1171 return mContext.mMainThread.getSystemContext().getResources();
1172 }
Jeff Sharkey8a4c9722014-06-16 13:48:42 -07001173 final boolean sameUid = (app.uid == Process.myUid());
Alan Viveretteecd585a2015-04-13 10:32:51 -07001174 final Resources r = mContext.mMainThread.getTopLevelResources(
Jeff Sharkey8a4c9722014-06-16 13:48:42 -07001175 sameUid ? app.sourceDir : app.publicSourceDir,
1176 sameUid ? app.splitSourceDirs : app.splitPublicSourceDirs,
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001177 app.resourceDirs, app.sharedLibraryFiles, Display.DEFAULT_DISPLAY,
1178 null, mContext.mPackageInfo);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001179 if (r != null) {
1180 return r;
1181 }
1182 throw new NameNotFoundException("Unable to open " + app.publicSourceDir);
1183 }
1184
Alan Viveretteecd585a2015-04-13 10:32:51 -07001185 @Override
1186 public Resources getResourcesForApplication(String appPackageName)
1187 throws NameNotFoundException {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001188 return getResourcesForApplication(
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001189 getApplicationInfo(appPackageName, sDefaultFlags));
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001190 }
1191
Amith Yamasani98edc952012-09-25 14:09:27 -07001192 /** @hide */
1193 @Override
1194 public Resources getResourcesForApplicationAsUser(String appPackageName, int userId)
1195 throws NameNotFoundException {
Jeff Sharkeyded653b2012-09-27 19:09:24 -07001196 if (userId < 0) {
1197 throw new IllegalArgumentException(
1198 "Call does not support special user #" + userId);
1199 }
1200 if ("system".equals(appPackageName)) {
1201 return mContext.mMainThread.getSystemContext().getResources();
1202 }
Amith Yamasani98edc952012-09-25 14:09:27 -07001203 try {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001204 ApplicationInfo ai = mPM.getApplicationInfo(appPackageName, sDefaultFlags, userId);
Amith Yamasani98edc952012-09-25 14:09:27 -07001205 if (ai != null) {
1206 return getResourcesForApplication(ai);
1207 }
1208 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001209 throw e.rethrowFromSystemServer();
Amith Yamasani98edc952012-09-25 14:09:27 -07001210 }
1211 throw new NameNotFoundException("Package " + appPackageName + " doesn't exist");
1212 }
1213
Jeff Sharkeycd654482016-01-08 17:42:11 -07001214 volatile int mCachedSafeMode = -1;
1215
1216 @Override
1217 public boolean isSafeMode() {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001218 try {
1219 if (mCachedSafeMode < 0) {
1220 mCachedSafeMode = mPM.isSafeMode() ? 1 : 0;
1221 }
1222 return mCachedSafeMode != 0;
1223 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001224 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001225 }
1226 }
1227
Svetoslavf7c06eb2015-06-10 18:43:22 -07001228 @Override
1229 public void addOnPermissionsChangeListener(OnPermissionsChangedListener listener) {
1230 synchronized (mPermissionListeners) {
1231 if (mPermissionListeners.get(listener) != null) {
1232 return;
1233 }
1234 OnPermissionsChangeListenerDelegate delegate =
1235 new OnPermissionsChangeListenerDelegate(listener, Looper.getMainLooper());
1236 try {
1237 mPM.addOnPermissionsChangeListener(delegate);
1238 mPermissionListeners.put(listener, delegate);
1239 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001240 throw e.rethrowFromSystemServer();
Svetoslavf7c06eb2015-06-10 18:43:22 -07001241 }
1242 }
1243 }
1244
1245 @Override
1246 public void removeOnPermissionsChangeListener(OnPermissionsChangedListener listener) {
1247 synchronized (mPermissionListeners) {
1248 IOnPermissionsChangeListener delegate = mPermissionListeners.get(listener);
1249 if (delegate != null) {
1250 try {
1251 mPM.removeOnPermissionsChangeListener(delegate);
1252 mPermissionListeners.remove(listener);
1253 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001254 throw e.rethrowFromSystemServer();
Svetoslavf7c06eb2015-06-10 18:43:22 -07001255 }
1256 }
1257 }
1258 }
1259
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001260 static void configurationChanged() {
1261 synchronized (sSync) {
1262 sIconCache.clear();
1263 sStringCache.clear();
1264 }
1265 }
1266
1267 ApplicationPackageManager(ContextImpl context,
1268 IPackageManager pm) {
1269 mContext = context;
1270 mPM = pm;
1271 }
1272
Alan Viveretteecd585a2015-04-13 10:32:51 -07001273 @Nullable
1274 private Drawable getCachedIcon(@NonNull ResourceName name) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001275 synchronized (sSync) {
Alan Viveretteecd585a2015-04-13 10:32:51 -07001276 final WeakReference<Drawable.ConstantState> wr = sIconCache.get(name);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001277 if (DEBUG_ICONS) Log.v(TAG, "Get cached weak drawable ref for "
1278 + name + ": " + wr);
1279 if (wr != null) { // we have the activity
Alan Viveretteecd585a2015-04-13 10:32:51 -07001280 final Drawable.ConstantState state = wr.get();
Romain Guy39fe17c2011-11-30 10:34:07 -08001281 if (state != null) {
1282 if (DEBUG_ICONS) {
1283 Log.v(TAG, "Get cached drawable state for " + name + ": " + state);
1284 }
1285 // Note: It's okay here to not use the newDrawable(Resources) variant
1286 // of the API. The ConstantState comes from a drawable that was
1287 // originally created by passing the proper app Resources instance
1288 // which means the state should already contain the proper
1289 // resources specific information (like density.) See
1290 // BitmapDrawable.BitmapState for instance.
1291 return state.newDrawable();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001292 }
1293 // our entry has been purged
1294 sIconCache.remove(name);
1295 }
1296 }
1297 return null;
1298 }
1299
Alan Viveretteecd585a2015-04-13 10:32:51 -07001300 private void putCachedIcon(@NonNull ResourceName name, @NonNull Drawable dr) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001301 synchronized (sSync) {
Alan Viveretteecd585a2015-04-13 10:32:51 -07001302 sIconCache.put(name, new WeakReference<>(dr.getConstantState()));
Romain Guy39fe17c2011-11-30 10:34:07 -08001303 if (DEBUG_ICONS) Log.v(TAG, "Added cached drawable state for " + name + ": " + dr);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001304 }
1305 }
1306
Romain Guy39fe17c2011-11-30 10:34:07 -08001307 static void handlePackageBroadcast(int cmd, String[] pkgList, boolean hasPkgInfo) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001308 boolean immediateGc = false;
1309 if (cmd == IApplicationThread.EXTERNAL_STORAGE_UNAVAILABLE) {
1310 immediateGc = true;
1311 }
1312 if (pkgList != null && (pkgList.length > 0)) {
1313 boolean needCleanup = false;
1314 for (String ssp : pkgList) {
1315 synchronized (sSync) {
Dianne Hackbornadd005c2013-07-17 18:43:12 -07001316 for (int i=sIconCache.size()-1; i>=0; i--) {
1317 ResourceName nm = sIconCache.keyAt(i);
1318 if (nm.packageName.equals(ssp)) {
1319 //Log.i(TAG, "Removing cached drawable for " + nm);
1320 sIconCache.removeAt(i);
1321 needCleanup = true;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001322 }
1323 }
Dianne Hackbornadd005c2013-07-17 18:43:12 -07001324 for (int i=sStringCache.size()-1; i>=0; i--) {
1325 ResourceName nm = sStringCache.keyAt(i);
1326 if (nm.packageName.equals(ssp)) {
1327 //Log.i(TAG, "Removing cached string for " + nm);
1328 sStringCache.removeAt(i);
1329 needCleanup = true;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001330 }
1331 }
1332 }
1333 }
1334 if (needCleanup || hasPkgInfo) {
1335 if (immediateGc) {
1336 // Schedule an immediate gc.
1337 Runtime.getRuntime().gc();
1338 } else {
1339 ActivityThread.currentActivityThread().scheduleGcIdler();
1340 }
1341 }
1342 }
1343 }
1344
1345 private static final class ResourceName {
1346 final String packageName;
1347 final int iconId;
1348
1349 ResourceName(String _packageName, int _iconId) {
1350 packageName = _packageName;
1351 iconId = _iconId;
1352 }
1353
1354 ResourceName(ApplicationInfo aInfo, int _iconId) {
1355 this(aInfo.packageName, _iconId);
1356 }
1357
1358 ResourceName(ComponentInfo cInfo, int _iconId) {
1359 this(cInfo.applicationInfo.packageName, _iconId);
1360 }
1361
1362 ResourceName(ResolveInfo rInfo, int _iconId) {
1363 this(rInfo.activityInfo.applicationInfo.packageName, _iconId);
1364 }
1365
1366 @Override
1367 public boolean equals(Object o) {
1368 if (this == o) return true;
1369 if (o == null || getClass() != o.getClass()) return false;
1370
1371 ResourceName that = (ResourceName) o;
1372
1373 if (iconId != that.iconId) return false;
1374 return !(packageName != null ?
1375 !packageName.equals(that.packageName) : that.packageName != null);
1376
1377 }
1378
1379 @Override
1380 public int hashCode() {
1381 int result;
1382 result = packageName.hashCode();
1383 result = 31 * result + iconId;
1384 return result;
1385 }
1386
1387 @Override
1388 public String toString() {
1389 return "{ResourceName " + packageName + " / " + iconId + "}";
1390 }
1391 }
1392
1393 private CharSequence getCachedString(ResourceName name) {
1394 synchronized (sSync) {
1395 WeakReference<CharSequence> wr = sStringCache.get(name);
1396 if (wr != null) { // we have the activity
1397 CharSequence cs = wr.get();
1398 if (cs != null) {
1399 return cs;
1400 }
1401 // our entry has been purged
1402 sStringCache.remove(name);
1403 }
1404 }
1405 return null;
1406 }
1407
1408 private void putCachedString(ResourceName name, CharSequence cs) {
1409 synchronized (sSync) {
1410 sStringCache.put(name, new WeakReference<CharSequence>(cs));
1411 }
1412 }
1413
1414 @Override
Tor Norbye7b9c9122013-05-30 16:48:33 -07001415 public CharSequence getText(String packageName, @StringRes int resid,
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001416 ApplicationInfo appInfo) {
1417 ResourceName name = new ResourceName(packageName, resid);
1418 CharSequence text = getCachedString(name);
1419 if (text != null) {
1420 return text;
1421 }
1422 if (appInfo == null) {
1423 try {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001424 appInfo = getApplicationInfo(packageName, sDefaultFlags);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001425 } catch (NameNotFoundException e) {
1426 return null;
1427 }
1428 }
1429 try {
1430 Resources r = getResourcesForApplication(appInfo);
1431 text = r.getText(resid);
1432 putCachedString(name, text);
1433 return text;
1434 } catch (NameNotFoundException e) {
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07001435 Log.w("PackageManager", "Failure retrieving resources for "
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001436 + appInfo.packageName);
1437 } catch (RuntimeException e) {
1438 // If an exception was thrown, fall through to return
1439 // default icon.
1440 Log.w("PackageManager", "Failure retrieving text 0x"
1441 + Integer.toHexString(resid) + " in package "
1442 + packageName, e);
1443 }
1444 return null;
1445 }
1446
1447 @Override
Tor Norbye7b9c9122013-05-30 16:48:33 -07001448 public XmlResourceParser getXml(String packageName, @XmlRes int resid,
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001449 ApplicationInfo appInfo) {
1450 if (appInfo == null) {
1451 try {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001452 appInfo = getApplicationInfo(packageName, sDefaultFlags);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001453 } catch (NameNotFoundException e) {
1454 return null;
1455 }
1456 }
1457 try {
1458 Resources r = getResourcesForApplication(appInfo);
1459 return r.getXml(resid);
1460 } catch (RuntimeException e) {
1461 // If an exception was thrown, fall through to return
1462 // default icon.
1463 Log.w("PackageManager", "Failure retrieving xml 0x"
1464 + Integer.toHexString(resid) + " in package "
1465 + packageName, e);
1466 } catch (NameNotFoundException e) {
Alon Albert3fa51e32010-11-11 09:24:04 -08001467 Log.w("PackageManager", "Failure retrieving resources for "
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001468 + appInfo.packageName);
1469 }
1470 return null;
1471 }
1472
1473 @Override
1474 public CharSequence getApplicationLabel(ApplicationInfo info) {
1475 return info.loadLabel(this);
1476 }
1477
1478 @Override
1479 public void installPackage(Uri packageURI, IPackageInstallObserver observer, int flags,
1480 String installerPackageName) {
Jeff Sharkey513a0742014-07-08 17:10:32 -07001481 installCommon(packageURI, new LegacyPackageInstallObserver(observer), flags,
Todd Kennedya6793232016-02-24 22:46:00 +00001482 installerPackageName, mContext.getUserId());
Christopher Tatef1977b42014-03-24 16:25:51 -07001483 }
1484
Christopher Tatef1977b42014-03-24 16:25:51 -07001485 @Override
1486 public void installPackage(Uri packageURI, PackageInstallObserver observer,
1487 int flags, String installerPackageName) {
Todd Kennedya6793232016-02-24 22:46:00 +00001488 installCommon(packageURI, observer, flags, installerPackageName, mContext.getUserId());
Jeff Sharkey513a0742014-07-08 17:10:32 -07001489 }
1490
1491 private void installCommon(Uri packageURI,
1492 PackageInstallObserver observer, int flags, String installerPackageName,
Nicolas Prevot9a80e532015-09-23 15:49:28 +01001493 int userId) {
Jeff Sharkey513a0742014-07-08 17:10:32 -07001494 if (!"file".equals(packageURI.getScheme())) {
1495 throw new UnsupportedOperationException("Only file:// URIs are supported");
1496 }
Jeff Sharkey513a0742014-07-08 17:10:32 -07001497
1498 final String originPath = packageURI.getPath();
Christopher Tatef1977b42014-03-24 16:25:51 -07001499 try {
Nicolas Prevot9a80e532015-09-23 15:49:28 +01001500 mPM.installPackageAsUser(originPath, observer.getBinder(), flags, installerPackageName,
Todd Kennedya6793232016-02-24 22:46:00 +00001501 userId);
Jeff Sharkey27b2e692016-02-25 17:40:12 -07001502 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001503 throw e.rethrowFromSystemServer();
rich cannings706e8ba2012-08-20 13:20:14 -07001504 }
1505 }
1506
1507 @Override
Nicolas Prevot9a80e532015-09-23 15:49:28 +01001508 public int installExistingPackage(String packageName) throws NameNotFoundException {
Robin Lee0e27c872015-09-28 14:37:40 +01001509 return installExistingPackageAsUser(packageName, mContext.getUserId());
Nicolas Prevot9a80e532015-09-23 15:49:28 +01001510 }
1511
1512 @Override
1513 public int installExistingPackageAsUser(String packageName, int userId)
Dianne Hackborn7767eac2012-08-23 18:25:40 -07001514 throws NameNotFoundException {
1515 try {
Nicolas Prevot9a80e532015-09-23 15:49:28 +01001516 int res = mPM.installExistingPackageAsUser(packageName, userId);
Dianne Hackborn7767eac2012-08-23 18:25:40 -07001517 if (res == INSTALL_FAILED_INVALID_URI) {
1518 throw new NameNotFoundException("Package " + packageName + " doesn't exist");
1519 }
1520 return res;
1521 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001522 throw e.rethrowFromSystemServer();
Dianne Hackborn7767eac2012-08-23 18:25:40 -07001523 }
1524 }
1525
1526 @Override
Kenny Root3a9b5fb2011-09-20 14:15:38 -07001527 public void verifyPendingInstall(int id, int response) {
Kenny Root5ab21572011-07-27 11:11:19 -07001528 try {
Kenny Root3a9b5fb2011-09-20 14:15:38 -07001529 mPM.verifyPendingInstall(id, response);
Kenny Root5ab21572011-07-27 11:11:19 -07001530 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001531 throw e.rethrowFromSystemServer();
Kenny Root5ab21572011-07-27 11:11:19 -07001532 }
1533 }
1534
1535 @Override
rich canningsd9ef3e52012-08-22 14:28:05 -07001536 public void extendVerificationTimeout(int id, int verificationCodeAtTimeout,
1537 long millisecondsToDelay) {
1538 try {
1539 mPM.extendVerificationTimeout(id, verificationCodeAtTimeout, millisecondsToDelay);
1540 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001541 throw e.rethrowFromSystemServer();
rich canningsd9ef3e52012-08-22 14:28:05 -07001542 }
1543 }
1544
1545 @Override
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001546 public void verifyIntentFilter(int id, int verificationCode, List<String> outFailedDomains) {
1547 try {
1548 mPM.verifyIntentFilter(id, verificationCode, outFailedDomains);
1549 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001550 throw e.rethrowFromSystemServer();
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001551 }
1552 }
1553
1554 @Override
Jeff Sharkeye06b4d12016-01-06 14:51:50 -07001555 public int getIntentVerificationStatusAsUser(String packageName, int userId) {
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001556 try {
1557 return mPM.getIntentVerificationStatus(packageName, userId);
1558 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001559 throw e.rethrowFromSystemServer();
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001560 }
1561 }
1562
1563 @Override
Jeff Sharkeye06b4d12016-01-06 14:51:50 -07001564 public boolean updateIntentVerificationStatusAsUser(String packageName, int status, int userId) {
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001565 try {
1566 return mPM.updateIntentVerificationStatus(packageName, status, userId);
1567 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001568 throw e.rethrowFromSystemServer();
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001569 }
1570 }
1571
1572 @Override
1573 public List<IntentFilterVerificationInfo> getIntentFilterVerifications(String packageName) {
1574 try {
1575 return mPM.getIntentFilterVerifications(packageName);
1576 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001577 throw e.rethrowFromSystemServer();
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001578 }
1579 }
1580
1581 @Override
Fabrice Di Meglio07885952015-04-06 19:41:28 -07001582 public List<IntentFilter> getAllIntentFilters(String packageName) {
1583 try {
1584 return mPM.getAllIntentFilters(packageName);
1585 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001586 throw e.rethrowFromSystemServer();
Fabrice Di Meglio07885952015-04-06 19:41:28 -07001587 }
1588 }
1589
1590 @Override
Jeff Sharkeye06b4d12016-01-06 14:51:50 -07001591 public String getDefaultBrowserPackageNameAsUser(int userId) {
Fabrice Di Meglio62271722015-04-10 17:24:02 -07001592 try {
1593 return mPM.getDefaultBrowserPackageName(userId);
1594 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001595 throw e.rethrowFromSystemServer();
Fabrice Di Meglio62271722015-04-10 17:24:02 -07001596 }
1597 }
1598
1599 @Override
Jeff Sharkeye06b4d12016-01-06 14:51:50 -07001600 public boolean setDefaultBrowserPackageNameAsUser(String packageName, int userId) {
Fabrice Di Meglio62271722015-04-10 17:24:02 -07001601 try {
1602 return mPM.setDefaultBrowserPackageName(packageName, userId);
1603 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001604 throw e.rethrowFromSystemServer();
Fabrice Di Meglio62271722015-04-10 17:24:02 -07001605 }
1606 }
1607
1608 @Override
Dianne Hackborn880119b2010-11-18 22:26:40 -08001609 public void setInstallerPackageName(String targetPackage,
1610 String installerPackageName) {
1611 try {
1612 mPM.setInstallerPackageName(targetPackage, installerPackageName);
1613 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001614 throw e.rethrowFromSystemServer();
Dianne Hackborn880119b2010-11-18 22:26:40 -08001615 }
1616 }
1617
1618 @Override
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001619 public String getInstallerPackageName(String packageName) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001620 try {
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001621 return mPM.getInstallerPackageName(packageName);
1622 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001623 throw e.rethrowFromSystemServer();
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001624 }
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001625 }
1626
1627 @Override
1628 public int getMoveStatus(int moveId) {
1629 try {
1630 return mPM.getMoveStatus(moveId);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001631 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001632 throw e.rethrowFromSystemServer();
Jeff Sharkeyb2b9ab82015-04-05 21:10:42 -07001633 }
1634 }
1635
1636 @Override
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001637 public void registerMoveCallback(MoveCallback callback, Handler handler) {
1638 synchronized (mDelegates) {
1639 final MoveCallbackDelegate delegate = new MoveCallbackDelegate(callback,
1640 handler.getLooper());
1641 try {
1642 mPM.registerMoveCallback(delegate);
1643 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001644 throw e.rethrowFromSystemServer();
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001645 }
1646 mDelegates.add(delegate);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001647 }
1648 }
1649
1650 @Override
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001651 public void unregisterMoveCallback(MoveCallback callback) {
1652 synchronized (mDelegates) {
1653 for (Iterator<MoveCallbackDelegate> i = mDelegates.iterator(); i.hasNext();) {
1654 final MoveCallbackDelegate delegate = i.next();
1655 if (delegate.mCallback == callback) {
1656 try {
1657 mPM.unregisterMoveCallback(delegate);
1658 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001659 throw e.rethrowFromSystemServer();
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001660 }
1661 i.remove();
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001662 }
1663 }
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001664 }
1665 }
1666
1667 @Override
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001668 public int movePackage(String packageName, VolumeInfo vol) {
1669 try {
1670 final String volumeUuid;
1671 if (VolumeInfo.ID_PRIVATE_INTERNAL.equals(vol.id)) {
1672 volumeUuid = StorageManager.UUID_PRIVATE_INTERNAL;
1673 } else if (vol.isPrimaryPhysical()) {
1674 volumeUuid = StorageManager.UUID_PRIMARY_PHYSICAL;
1675 } else {
1676 volumeUuid = Preconditions.checkNotNull(vol.fsUuid);
1677 }
1678
1679 return mPM.movePackage(packageName, volumeUuid);
1680 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001681 throw e.rethrowFromSystemServer();
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001682 }
1683 }
1684
1685 @Override
1686 public @Nullable VolumeInfo getPackageCurrentVolume(ApplicationInfo app) {
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001687 final StorageManager storage = mContext.getSystemService(StorageManager.class);
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001688 if (app.isInternal()) {
1689 return storage.findVolumeById(VolumeInfo.ID_PRIVATE_INTERNAL);
1690 } else if (app.isExternalAsec()) {
1691 return storage.getPrimaryPhysicalVolume();
1692 } else {
1693 return storage.findVolumeByUuid(app.volumeUuid);
1694 }
1695 }
1696
1697 @Override
1698 public @NonNull List<VolumeInfo> getPackageCandidateVolumes(ApplicationInfo app) {
1699 final StorageManager storage = mContext.getSystemService(StorageManager.class);
1700 final VolumeInfo currentVol = getPackageCurrentVolume(app);
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001701 final List<VolumeInfo> vols = storage.getVolumes();
1702 final List<VolumeInfo> candidates = new ArrayList<>();
1703 for (VolumeInfo vol : vols) {
Todd Kennedyf39ca8f2015-08-07 14:15:07 -07001704 if (Objects.equals(vol, currentVol) || isPackageCandidateVolume(mContext, app, vol)) {
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001705 candidates.add(vol);
1706 }
1707 }
1708 return candidates;
1709 }
1710
Makoto Onukif34db0a2016-02-17 11:17:15 -08001711 private boolean isPackageCandidateVolume(
Todd Kennedyf39ca8f2015-08-07 14:15:07 -07001712 ContextImpl context, ApplicationInfo app, VolumeInfo vol) {
1713 final boolean forceAllowOnExternal = Settings.Global.getInt(
1714 context.getContentResolver(), Settings.Global.FORCE_ALLOW_ON_EXTERNAL, 0) != 0;
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001715 // Private internal is always an option
1716 if (VolumeInfo.ID_PRIVATE_INTERNAL.equals(vol.getId())) {
1717 return true;
1718 }
1719
1720 // System apps and apps demanding internal storage can't be moved
1721 // anywhere else
Todd Kennedyf39ca8f2015-08-07 14:15:07 -07001722 if (app.isSystemApp()) {
1723 return false;
1724 }
1725 if (!forceAllowOnExternal
Dianne Hackborn30a4e6d2015-10-12 17:14:56 -07001726 && (app.installLocation == PackageInfo.INSTALL_LOCATION_INTERNAL_ONLY
1727 || app.installLocation == PackageInfo.INSTALL_LOCATION_UNSPECIFIED)) {
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001728 return false;
1729 }
1730
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001731 // Gotta be able to write there
1732 if (!vol.isMountedWritable()) {
1733 return false;
1734 }
1735
1736 // Moving into an ASEC on public primary is only option internal
1737 if (vol.isPrimaryPhysical()) {
1738 return app.isInternal();
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001739 }
1740
Makoto Onukif34db0a2016-02-17 11:17:15 -08001741 // Some apps can't be moved. (e.g. device admins)
1742 try {
1743 if (mPM.isPackageDeviceAdminOnAnyUser(app.packageName)) {
1744 return false;
1745 }
1746 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001747 throw e.rethrowFromSystemServer();
Makoto Onukif34db0a2016-02-17 11:17:15 -08001748 }
1749
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001750 // Otherwise we can move to any private volume
1751 return (vol.getType() == VolumeInfo.TYPE_PRIVATE);
1752 }
1753
1754 @Override
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001755 public int movePrimaryStorage(VolumeInfo vol) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001756 try {
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001757 final String volumeUuid;
1758 if (VolumeInfo.ID_PRIVATE_INTERNAL.equals(vol.id)) {
1759 volumeUuid = StorageManager.UUID_PRIVATE_INTERNAL;
1760 } else if (vol.isPrimaryPhysical()) {
1761 volumeUuid = StorageManager.UUID_PRIMARY_PHYSICAL;
1762 } else {
1763 volumeUuid = Preconditions.checkNotNull(vol.fsUuid);
1764 }
1765
1766 return mPM.movePrimaryStorage(volumeUuid);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001767 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001768 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001769 }
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001770 }
1771
Jeff Sharkey275e3e42015-04-24 16:10:32 -07001772 @Override
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001773 public @Nullable VolumeInfo getPrimaryStorageCurrentVolume() {
1774 final StorageManager storage = mContext.getSystemService(StorageManager.class);
1775 final String volumeUuid = storage.getPrimaryStorageUuid();
Jeff Sharkey50a05452015-04-29 11:24:52 -07001776 return storage.findVolumeByQualifiedUuid(volumeUuid);
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001777 }
1778
Jeff Sharkey275e3e42015-04-24 16:10:32 -07001779 @Override
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001780 public @NonNull List<VolumeInfo> getPrimaryStorageCandidateVolumes() {
1781 final StorageManager storage = mContext.getSystemService(StorageManager.class);
1782 final VolumeInfo currentVol = getPrimaryStorageCurrentVolume();
1783 final List<VolumeInfo> vols = storage.getVolumes();
1784 final List<VolumeInfo> candidates = new ArrayList<>();
Jeff Sharkeyfced5342015-05-10 14:53:34 -07001785 if (Objects.equals(StorageManager.UUID_PRIMARY_PHYSICAL,
1786 storage.getPrimaryStorageUuid()) && currentVol != null) {
1787 // TODO: support moving primary physical to emulated volume
1788 candidates.add(currentVol);
1789 } else {
1790 for (VolumeInfo vol : vols) {
1791 if (Objects.equals(vol, currentVol) || isPrimaryStorageCandidateVolume(vol)) {
1792 candidates.add(vol);
1793 }
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001794 }
1795 }
1796 return candidates;
1797 }
1798
1799 private static boolean isPrimaryStorageCandidateVolume(VolumeInfo vol) {
1800 // Private internal is always an option
1801 if (VolumeInfo.ID_PRIVATE_INTERNAL.equals(vol.getId())) {
1802 return true;
1803 }
1804
1805 // Gotta be able to write there
1806 if (!vol.isMountedWritable()) {
1807 return false;
1808 }
1809
Jeff Sharkeyfced5342015-05-10 14:53:34 -07001810 // We can move to any private volume
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001811 return (vol.getType() == VolumeInfo.TYPE_PRIVATE);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001812 }
1813
1814 @Override
1815 public void deletePackage(String packageName, IPackageDeleteObserver observer, int flags) {
Robin Lee0e27c872015-09-28 14:37:40 +01001816 deletePackageAsUser(packageName, observer, flags, mContext.getUserId());
Nicolas Prevot9a80e532015-09-23 15:49:28 +01001817 }
1818
1819 @Override
1820 public void deletePackageAsUser(String packageName, IPackageDeleteObserver observer, int flags,
1821 int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001822 try {
Nicolas Prevot9a80e532015-09-23 15:49:28 +01001823 mPM.deletePackageAsUser(packageName, observer, userId, flags);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001824 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001825 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001826 }
1827 }
Jeff Sharkeyfbd0e9f2014-08-06 16:34:34 -07001828
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001829 @Override
1830 public void clearApplicationUserData(String packageName,
1831 IPackageDataObserver observer) {
1832 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -07001833 mPM.clearApplicationUserData(packageName, observer, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001834 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001835 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001836 }
1837 }
1838 @Override
1839 public void deleteApplicationCacheFiles(String packageName,
1840 IPackageDataObserver observer) {
1841 try {
1842 mPM.deleteApplicationCacheFiles(packageName, observer);
1843 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001844 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001845 }
1846 }
Jeff Sharkey529f91f2015-04-18 20:23:13 -07001847
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001848 @Override
Jeff Sharkey529f91f2015-04-18 20:23:13 -07001849 public void freeStorageAndNotify(String volumeUuid, long idealStorageSize,
1850 IPackageDataObserver observer) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001851 try {
Jeff Sharkey529f91f2015-04-18 20:23:13 -07001852 mPM.freeStorageAndNotify(volumeUuid, idealStorageSize, observer);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001853 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001854 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001855 }
1856 }
1857
1858 @Override
Jeff Sharkey529f91f2015-04-18 20:23:13 -07001859 public void freeStorage(String volumeUuid, long freeStorageSize, IntentSender pi) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001860 try {
Jeff Sharkey529f91f2015-04-18 20:23:13 -07001861 mPM.freeStorage(volumeUuid, freeStorageSize, pi);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001862 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001863 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001864 }
1865 }
1866
1867 @Override
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00001868 public String[] setPackagesSuspendedAsUser(String[] packageNames, boolean suspended,
1869 int userId) {
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00001870 try {
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00001871 return mPM.setPackagesSuspendedAsUser(packageNames, suspended, userId);
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00001872 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001873 throw e.rethrowFromSystemServer();
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00001874 }
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00001875 }
1876
1877 @Override
Andrei Stingaceanu355b2322016-02-12 16:43:51 +00001878 public boolean isPackageSuspendedForUser(String packageName, int userId) {
1879 try {
1880 return mPM.isPackageSuspendedForUser(packageName, userId);
1881 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001882 throw e.rethrowFromSystemServer();
Andrei Stingaceanu355b2322016-02-12 16:43:51 +00001883 }
Andrei Stingaceanu355b2322016-02-12 16:43:51 +00001884 }
1885
1886 @Override
Jeff Sharkeye06b4d12016-01-06 14:51:50 -07001887 public void getPackageSizeInfoAsUser(String packageName, int userHandle,
Dianne Hackborn0c380492012-08-20 17:23:30 -07001888 IPackageStatsObserver observer) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001889 try {
Dianne Hackborn0c380492012-08-20 17:23:30 -07001890 mPM.getPackageSizeInfo(packageName, userHandle, observer);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001891 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001892 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001893 }
1894 }
1895 @Override
1896 public void addPackageToPreferred(String packageName) {
1897 try {
1898 mPM.addPackageToPreferred(packageName);
1899 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001900 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001901 }
1902 }
1903
1904 @Override
1905 public void removePackageFromPreferred(String packageName) {
1906 try {
1907 mPM.removePackageFromPreferred(packageName);
1908 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001909 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001910 }
1911 }
1912
1913 @Override
1914 public List<PackageInfo> getPreferredPackages(int flags) {
1915 try {
1916 return mPM.getPreferredPackages(flags);
1917 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001918 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001919 }
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001920 }
1921
1922 @Override
1923 public void addPreferredActivity(IntentFilter filter,
1924 int match, ComponentName[] set, ComponentName activity) {
1925 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -07001926 mPM.addPreferredActivity(filter, match, set, activity, mContext.getUserId());
Amith Yamasania3f133a2012-08-09 17:11:28 -07001927 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001928 throw e.rethrowFromSystemServer();
Amith Yamasania3f133a2012-08-09 17:11:28 -07001929 }
1930 }
1931
1932 @Override
Jeff Sharkeye06b4d12016-01-06 14:51:50 -07001933 public void addPreferredActivityAsUser(IntentFilter filter, int match,
Amith Yamasania3f133a2012-08-09 17:11:28 -07001934 ComponentName[] set, ComponentName activity, int userId) {
1935 try {
1936 mPM.addPreferredActivity(filter, match, set, activity, userId);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001937 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001938 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001939 }
1940 }
1941
1942 @Override
1943 public void replacePreferredActivity(IntentFilter filter,
1944 int match, ComponentName[] set, ComponentName activity) {
1945 try {
Robin Lee0e27c872015-09-28 14:37:40 +01001946 mPM.replacePreferredActivity(filter, match, set, activity, mContext.getUserId());
Amith Yamasani41c1ded2014-08-05 11:15:05 -07001947 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001948 throw e.rethrowFromSystemServer();
Amith Yamasani41c1ded2014-08-05 11:15:05 -07001949 }
1950 }
1951
1952 @Override
1953 public void replacePreferredActivityAsUser(IntentFilter filter,
1954 int match, ComponentName[] set, ComponentName activity,
1955 int userId) {
1956 try {
1957 mPM.replacePreferredActivity(filter, match, set, activity, userId);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001958 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001959 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001960 }
1961 }
1962
1963 @Override
1964 public void clearPackagePreferredActivities(String packageName) {
1965 try {
1966 mPM.clearPackagePreferredActivities(packageName);
1967 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001968 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001969 }
1970 }
1971
1972 @Override
1973 public int getPreferredActivities(List<IntentFilter> outFilters,
1974 List<ComponentName> outActivities, String packageName) {
1975 try {
1976 return mPM.getPreferredActivities(outFilters, outActivities, packageName);
1977 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001978 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001979 }
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001980 }
1981
1982 @Override
Christopher Tatea2a0850d2013-09-05 16:38:58 -07001983 public ComponentName getHomeActivities(List<ResolveInfo> outActivities) {
1984 try {
1985 return mPM.getHomeActivities(outActivities);
1986 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001987 throw e.rethrowFromSystemServer();
Christopher Tatea2a0850d2013-09-05 16:38:58 -07001988 }
Christopher Tatea2a0850d2013-09-05 16:38:58 -07001989 }
1990
1991 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001992 public void setComponentEnabledSetting(ComponentName componentName,
1993 int newState, int flags) {
1994 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -07001995 mPM.setComponentEnabledSetting(componentName, newState, flags, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001996 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001997 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001998 }
1999 }
2000
2001 @Override
2002 public int getComponentEnabledSetting(ComponentName componentName) {
2003 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -07002004 return mPM.getComponentEnabledSetting(componentName, mContext.getUserId());
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 }
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002008 }
2009
2010 @Override
2011 public void setApplicationEnabledSetting(String packageName,
2012 int newState, int flags) {
2013 try {
Dianne Hackborn3fa3c28a2013-03-26 16:15:41 -07002014 mPM.setApplicationEnabledSetting(packageName, newState, flags,
Dianne Hackborn95d78532013-09-11 09:51:14 -07002015 mContext.getUserId(), mContext.getOpPackageName());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002016 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002017 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002018 }
2019 }
2020
2021 @Override
2022 public int getApplicationEnabledSetting(String packageName) {
2023 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -07002024 return mPM.getApplicationEnabledSetting(packageName, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002025 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002026 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002027 }
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002028 }
2029
Amith Yamasani655d0e22013-06-12 14:19:10 -07002030 @Override
Amith Yamasanie5bcff62014-07-19 15:44:09 -07002031 public boolean setApplicationHiddenSettingAsUser(String packageName, boolean hidden,
Amith Yamasani655d0e22013-06-12 14:19:10 -07002032 UserHandle user) {
2033 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07002034 return mPM.setApplicationHiddenSettingAsUser(packageName, hidden,
Amith Yamasani655d0e22013-06-12 14:19:10 -07002035 user.getIdentifier());
Jeff Sharkey27b2e692016-02-25 17:40:12 -07002036 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002037 throw e.rethrowFromSystemServer();
Amith Yamasani655d0e22013-06-12 14:19:10 -07002038 }
Amith Yamasani655d0e22013-06-12 14:19:10 -07002039 }
2040
2041 @Override
Amith Yamasanie5bcff62014-07-19 15:44:09 -07002042 public boolean getApplicationHiddenSettingAsUser(String packageName, UserHandle user) {
Amith Yamasani655d0e22013-06-12 14:19:10 -07002043 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07002044 return mPM.getApplicationHiddenSettingAsUser(packageName, user.getIdentifier());
Jeff Sharkey27b2e692016-02-25 17:40:12 -07002045 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002046 throw e.rethrowFromSystemServer();
Amith Yamasani655d0e22013-06-12 14:19:10 -07002047 }
Amith Yamasani655d0e22013-06-12 14:19:10 -07002048 }
2049
dcashmanc6f22492014-08-14 09:54:51 -07002050 /** @hide */
dcashman9d2f4412014-06-09 09:27:54 -07002051 @Override
2052 public KeySet getKeySetByAlias(String packageName, String alias) {
2053 Preconditions.checkNotNull(packageName);
2054 Preconditions.checkNotNull(alias);
dcashman9d2f4412014-06-09 09:27:54 -07002055 try {
Jeff Sharkey27b2e692016-02-25 17:40:12 -07002056 return mPM.getKeySetByAlias(packageName, alias);
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 KeySet getSigningKeySet(String packageName) {
2065 Preconditions.checkNotNull(packageName);
dcashman9d2f4412014-06-09 09:27:54 -07002066 try {
Jeff Sharkey27b2e692016-02-25 17:40:12 -07002067 return mPM.getSigningKeySet(packageName);
dcashman9d2f4412014-06-09 09:27:54 -07002068 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002069 throw e.rethrowFromSystemServer();
dcashman9d2f4412014-06-09 09:27:54 -07002070 }
dcashman9d2f4412014-06-09 09:27:54 -07002071 }
2072
dcashmanc6f22492014-08-14 09:54:51 -07002073 /** @hide */
dcashman9d2f4412014-06-09 09:27:54 -07002074 @Override
2075 public boolean isSignedBy(String packageName, KeySet ks) {
2076 Preconditions.checkNotNull(packageName);
2077 Preconditions.checkNotNull(ks);
dcashman9d2f4412014-06-09 09:27:54 -07002078 try {
dcashmanc6f22492014-08-14 09:54:51 -07002079 return mPM.isPackageSignedByKeySet(packageName, ks);
dcashman9d2f4412014-06-09 09:27:54 -07002080 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002081 throw e.rethrowFromSystemServer();
dcashman9d2f4412014-06-09 09:27:54 -07002082 }
2083 }
2084
dcashmanc6f22492014-08-14 09:54:51 -07002085 /** @hide */
dcashman9d2f4412014-06-09 09:27:54 -07002086 @Override
2087 public boolean isSignedByExactly(String packageName, KeySet ks) {
2088 Preconditions.checkNotNull(packageName);
2089 Preconditions.checkNotNull(ks);
dcashman9d2f4412014-06-09 09:27:54 -07002090 try {
dcashmanc6f22492014-08-14 09:54:51 -07002091 return mPM.isPackageSignedByKeySetExactly(packageName, ks);
dcashman9d2f4412014-06-09 09:27:54 -07002092 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002093 throw e.rethrowFromSystemServer();
dcashman9d2f4412014-06-09 09:27:54 -07002094 }
2095 }
2096
Kenny Root0aaa0d92011-09-12 16:42:55 -07002097 /**
2098 * @hide
2099 */
2100 @Override
2101 public VerifierDeviceIdentity getVerifierDeviceIdentity() {
2102 try {
2103 return mPM.getVerifierDeviceIdentity();
2104 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002105 throw e.rethrowFromSystemServer();
Kenny Root0aaa0d92011-09-12 16:42:55 -07002106 }
Kenny Root0aaa0d92011-09-12 16:42:55 -07002107 }
2108
Jeff Hao9f60c082014-10-28 18:51:07 -07002109 /**
2110 * @hide
2111 */
2112 @Override
2113 public boolean isUpgrade() {
2114 try {
2115 return mPM.isUpgrade();
2116 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002117 throw e.rethrowFromSystemServer();
Jeff Hao9f60c082014-10-28 18:51:07 -07002118 }
2119 }
2120
Jeff Sharkey3a44f3f2014-04-28 17:36:31 -07002121 @Override
Jeff Sharkey16c8e3f2014-07-24 17:08:17 -07002122 public PackageInstaller getPackageInstaller() {
2123 synchronized (mLock) {
2124 if (mInstaller == null) {
2125 try {
Jeff Sharkeya0907432014-08-15 10:23:11 -07002126 mInstaller = new PackageInstaller(mContext, this, mPM.getPackageInstaller(),
Jeff Sharkey16c8e3f2014-07-24 17:08:17 -07002127 mContext.getPackageName(), mContext.getUserId());
2128 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002129 throw e.rethrowFromSystemServer();
Jeff Sharkey16c8e3f2014-07-24 17:08:17 -07002130 }
2131 }
2132 return mInstaller;
Jeff Sharkey3a44f3f2014-04-28 17:36:31 -07002133 }
2134 }
2135
Jeff Sharkey6c833e02014-07-14 22:44:30 -07002136 @Override
2137 public boolean isPackageAvailable(String packageName) {
2138 try {
2139 return mPM.isPackageAvailable(packageName, mContext.getUserId());
2140 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002141 throw e.rethrowFromSystemServer();
Jeff Sharkey6c833e02014-07-14 22:44:30 -07002142 }
2143 }
2144
Nicolas Prevotc79586e2014-05-06 12:47:57 +01002145 /**
2146 * @hide
2147 */
2148 @Override
Nicolas Prevot63798c52014-05-27 13:22:38 +01002149 public void addCrossProfileIntentFilter(IntentFilter filter, int sourceUserId, int targetUserId,
2150 int flags) {
Nicolas Prevotc79586e2014-05-06 12:47:57 +01002151 try {
Nicolas Prevot3f7777f2014-07-24 15:58:39 +01002152 mPM.addCrossProfileIntentFilter(filter, mContext.getOpPackageName(),
Nicolas Prevot4b8d5822015-03-05 15:20:49 +00002153 sourceUserId, targetUserId, flags);
Nicolas Prevotc79586e2014-05-06 12:47:57 +01002154 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002155 throw e.rethrowFromSystemServer();
Nicolas Prevotc79586e2014-05-06 12:47:57 +01002156 }
2157 }
2158
2159 /**
2160 * @hide
2161 */
2162 @Override
Nicolas Prevot81948992014-05-16 18:25:26 +01002163 public void clearCrossProfileIntentFilters(int sourceUserId) {
Nicolas Prevotc79586e2014-05-06 12:47:57 +01002164 try {
Nicolas Prevot4b8d5822015-03-05 15:20:49 +00002165 mPM.clearCrossProfileIntentFilters(sourceUserId, mContext.getOpPackageName());
Nicolas Prevotc79586e2014-05-06 12:47:57 +01002166 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002167 throw e.rethrowFromSystemServer();
Nicolas Prevotc79586e2014-05-06 12:47:57 +01002168 }
2169 }
2170
Nicolas Prevot88cc3462014-05-14 14:51:48 +01002171 /**
2172 * @hide
2173 */
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +01002174 public Drawable loadItemIcon(PackageItemInfo itemInfo, ApplicationInfo appInfo) {
Benjamin Franzec2d48b2014-10-01 15:38:43 +01002175 Drawable dr = loadUnbadgedItemIcon(itemInfo, appInfo);
2176 if (itemInfo.showUserIcon != UserHandle.USER_NULL) {
2177 return dr;
2178 }
2179 return getUserBadgedIcon(dr, new UserHandle(mContext.getUserId()));
2180 }
2181
2182 /**
2183 * @hide
2184 */
2185 public Drawable loadUnbadgedItemIcon(PackageItemInfo itemInfo, ApplicationInfo appInfo) {
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +01002186 if (itemInfo.showUserIcon != UserHandle.USER_NULL) {
Alexandra Gherghina64d4dca2014-08-28 18:26:56 +01002187 Bitmap bitmap = getUserManager().getUserIcon(itemInfo.showUserIcon);
2188 if (bitmap == null) {
2189 return UserIcons.getDefaultUserIcon(itemInfo.showUserIcon, /* light= */ false);
2190 }
2191 return new BitmapDrawable(bitmap);
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +01002192 }
Alexandra Gherghinadb811db2014-08-29 13:43:59 +01002193 Drawable dr = null;
2194 if (itemInfo.packageName != null) {
2195 dr = getDrawable(itemInfo.packageName, itemInfo.icon, appInfo);
2196 }
Alexandra Gherghinaa71e3902014-07-25 20:03:47 +01002197 if (dr == null) {
Alexandra Gherghinaa7093142014-07-30 13:43:39 +01002198 dr = itemInfo.loadDefaultIcon(this);
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +01002199 }
Benjamin Franzec2d48b2014-10-01 15:38:43 +01002200 return dr;
Svetoslavc7d62f02014-09-04 15:39:54 -07002201 }
2202
2203 private Drawable getBadgedDrawable(Drawable drawable, Drawable badgeDrawable,
2204 Rect badgeLocation, boolean tryBadgeInPlace) {
2205 final int badgedWidth = drawable.getIntrinsicWidth();
2206 final int badgedHeight = drawable.getIntrinsicHeight();
2207 final boolean canBadgeInPlace = tryBadgeInPlace
2208 && (drawable instanceof BitmapDrawable)
2209 && ((BitmapDrawable) drawable).getBitmap().isMutable();
2210
2211 final Bitmap bitmap;
2212 if (canBadgeInPlace) {
2213 bitmap = ((BitmapDrawable) drawable).getBitmap();
2214 } else {
2215 bitmap = Bitmap.createBitmap(badgedWidth, badgedHeight, Bitmap.Config.ARGB_8888);
2216 }
2217 Canvas canvas = new Canvas(bitmap);
2218
2219 if (!canBadgeInPlace) {
2220 drawable.setBounds(0, 0, badgedWidth, badgedHeight);
2221 drawable.draw(canvas);
2222 }
2223
2224 if (badgeLocation != null) {
2225 if (badgeLocation.left < 0 || badgeLocation.top < 0
2226 || badgeLocation.width() > badgedWidth || badgeLocation.height() > badgedHeight) {
2227 throw new IllegalArgumentException("Badge location " + badgeLocation
2228 + " not in badged drawable bounds "
2229 + new Rect(0, 0, badgedWidth, badgedHeight));
2230 }
2231 badgeDrawable.setBounds(0, 0, badgeLocation.width(), badgeLocation.height());
2232
2233 canvas.save();
2234 canvas.translate(badgeLocation.left, badgeLocation.top);
2235 badgeDrawable.draw(canvas);
2236 canvas.restore();
2237 } else {
2238 badgeDrawable.setBounds(0, 0, badgedWidth, badgedHeight);
2239 badgeDrawable.draw(canvas);
2240 }
2241
2242 if (!canBadgeInPlace) {
2243 BitmapDrawable mergedDrawable = new BitmapDrawable(mContext.getResources(), bitmap);
2244
2245 if (drawable instanceof BitmapDrawable) {
2246 BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
2247 mergedDrawable.setTargetDensity(bitmapDrawable.getBitmap().getDensity());
2248 }
2249
2250 return mergedDrawable;
2251 }
2252
2253 return drawable;
2254 }
2255
2256 private int getBadgeResIdForUser(int userHandle) {
2257 // Return the framework-provided badge.
2258 UserInfo userInfo = getUserIfProfile(userHandle);
2259 if (userInfo != null && userInfo.isManagedProfile()) {
2260 return com.android.internal.R.drawable.ic_corp_icon_badge;
2261 }
2262 return 0;
2263 }
2264
2265 private UserInfo getUserIfProfile(int userHandle) {
Robin Lee0e27c872015-09-28 14:37:40 +01002266 List<UserInfo> userProfiles = getUserManager().getProfiles(mContext.getUserId());
Svetoslavc7d62f02014-09-04 15:39:54 -07002267 for (UserInfo user : userProfiles) {
2268 if (user.id == userHandle) {
2269 return user;
2270 }
2271 }
2272 return null;
Nicolas Prevot88cc3462014-05-14 14:51:48 +01002273 }
2274
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002275 /** {@hide} */
2276 private static class MoveCallbackDelegate extends IPackageMoveObserver.Stub implements
2277 Handler.Callback {
Jeff Sharkey50a05452015-04-29 11:24:52 -07002278 private static final int MSG_CREATED = 1;
2279 private static final int MSG_STATUS_CHANGED = 2;
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002280
2281 final MoveCallback mCallback;
2282 final Handler mHandler;
2283
2284 public MoveCallbackDelegate(MoveCallback callback, Looper looper) {
2285 mCallback = callback;
2286 mHandler = new Handler(looper, this);
2287 }
2288
2289 @Override
2290 public boolean handleMessage(Message msg) {
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002291 switch (msg.what) {
Jeff Sharkey50a05452015-04-29 11:24:52 -07002292 case MSG_CREATED: {
Jeff Sharkeyb36586a2015-04-27 08:42:28 -07002293 final SomeArgs args = (SomeArgs) msg.obj;
Jeff Sharkey50a05452015-04-29 11:24:52 -07002294 mCallback.onCreated(args.argi1, (Bundle) args.arg2);
Jeff Sharkeyb36586a2015-04-27 08:42:28 -07002295 args.recycle();
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002296 return true;
Jeff Sharkey50a05452015-04-29 11:24:52 -07002297 }
2298 case MSG_STATUS_CHANGED: {
2299 final SomeArgs args = (SomeArgs) msg.obj;
2300 mCallback.onStatusChanged(args.argi1, args.argi2, (long) args.arg3);
2301 args.recycle();
2302 return true;
2303 }
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002304 }
2305 return false;
2306 }
2307
2308 @Override
Jeff Sharkey50a05452015-04-29 11:24:52 -07002309 public void onCreated(int moveId, Bundle extras) {
Jeff Sharkeyb36586a2015-04-27 08:42:28 -07002310 final SomeArgs args = SomeArgs.obtain();
2311 args.argi1 = moveId;
Jeff Sharkey50a05452015-04-29 11:24:52 -07002312 args.arg2 = extras;
2313 mHandler.obtainMessage(MSG_CREATED, args).sendToTarget();
2314 }
2315
2316 @Override
2317 public void onStatusChanged(int moveId, int status, long estMillis) {
2318 final SomeArgs args = SomeArgs.obtain();
2319 args.argi1 = moveId;
2320 args.argi2 = status;
2321 args.arg3 = estMillis;
Jeff Sharkeyb36586a2015-04-27 08:42:28 -07002322 mHandler.obtainMessage(MSG_STATUS_CHANGED, args).sendToTarget();
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002323 }
2324 }
2325
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002326 private final ContextImpl mContext;
2327 private final IPackageManager mPM;
2328
2329 private static final Object sSync = new Object();
Dianne Hackbornadd005c2013-07-17 18:43:12 -07002330 private static ArrayMap<ResourceName, WeakReference<Drawable.ConstantState>> sIconCache
2331 = new ArrayMap<ResourceName, WeakReference<Drawable.ConstantState>>();
2332 private static ArrayMap<ResourceName, WeakReference<CharSequence>> sStringCache
2333 = new ArrayMap<ResourceName, WeakReference<CharSequence>>();
Svetoslavf7c06eb2015-06-10 18:43:22 -07002334
2335 private final Map<OnPermissionsChangedListener, IOnPermissionsChangeListener>
2336 mPermissionListeners = new ArrayMap<>();
2337
2338 public class OnPermissionsChangeListenerDelegate extends IOnPermissionsChangeListener.Stub
2339 implements Handler.Callback{
2340 private static final int MSG_PERMISSIONS_CHANGED = 1;
2341
2342 private final OnPermissionsChangedListener mListener;
2343 private final Handler mHandler;
2344
2345
2346 public OnPermissionsChangeListenerDelegate(OnPermissionsChangedListener listener,
2347 Looper looper) {
2348 mListener = listener;
2349 mHandler = new Handler(looper, this);
2350 }
2351
2352 @Override
2353 public void onPermissionsChanged(int uid) {
2354 mHandler.obtainMessage(MSG_PERMISSIONS_CHANGED, uid, 0).sendToTarget();
2355 }
2356
2357 @Override
2358 public boolean handleMessage(Message msg) {
2359 switch (msg.what) {
2360 case MSG_PERMISSIONS_CHANGED: {
2361 final int uid = msg.arg1;
2362 mListener.onPermissionsChanged(uid);
2363 return true;
2364 }
2365 }
2366 return false;
2367 }
2368 }
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002369}