blob: 4df633fabf3c25d635c2e066e4c34a9088e40b7f [file] [log] [blame]
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001/*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.app;
18
Tor Norbye7b9c9122013-05-30 16:48:33 -070019import android.annotation.DrawableRes;
Alan Viveretteecd585a2015-04-13 10:32:51 -070020import android.annotation.NonNull;
21import android.annotation.Nullable;
Tor Norbye7b9c9122013-05-30 16:48:33 -070022import android.annotation.StringRes;
23import android.annotation.XmlRes;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080024import android.content.ComponentName;
25import android.content.ContentResolver;
Yao Chen022b8ea2016-12-16 11:03:28 -080026import android.content.Context;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080027import android.content.Intent;
28import android.content.IntentFilter;
29import android.content.IntentSender;
30import android.content.pm.ActivityInfo;
31import android.content.pm.ApplicationInfo;
Todd Kennedy9106c642017-02-08 14:16:53 -080032import android.content.pm.ChangedPackages;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080033import android.content.pm.ComponentInfo;
Svetoslav Ganov096d3042017-01-30 16:34:13 -080034import android.content.pm.InstantAppInfo;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080035import android.content.pm.FeatureInfo;
Svetoslavf7c06eb2015-06-10 18:43:22 -070036import android.content.pm.IOnPermissionsChangeListener;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080037import android.content.pm.IPackageDataObserver;
38import android.content.pm.IPackageDeleteObserver;
39import android.content.pm.IPackageInstallObserver;
40import android.content.pm.IPackageManager;
41import android.content.pm.IPackageMoveObserver;
42import android.content.pm.IPackageStatsObserver;
43import android.content.pm.InstrumentationInfo;
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -080044import android.content.pm.IntentFilterVerificationInfo;
dcashman9d2f4412014-06-09 09:27:54 -070045import android.content.pm.KeySet;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080046import android.content.pm.PackageInfo;
Jeff Sharkey3a44f3f2014-04-28 17:36:31 -070047import android.content.pm.PackageInstaller;
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +010048import android.content.pm.PackageItemInfo;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080049import android.content.pm.PackageManager;
Kenny Roote6cd0c72011-05-19 12:48:14 -070050import android.content.pm.ParceledListSlice;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080051import android.content.pm.PermissionGroupInfo;
52import android.content.pm.PermissionInfo;
53import android.content.pm.ProviderInfo;
54import android.content.pm.ResolveInfo;
55import android.content.pm.ServiceInfo;
Svet Ganov67882122016-12-11 16:36:34 -080056import android.content.pm.SharedLibraryInfo;
Kenny Root0aaa0d92011-09-12 16:42:55 -070057import android.content.pm.VerifierDeviceIdentity;
Svet Ganov67882122016-12-11 16:36:34 -080058import android.content.pm.VersionedPackage;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080059import android.content.res.Resources;
60import android.content.res.XmlResourceParser;
Svetoslavc7d62f02014-09-04 15:39:54 -070061import android.graphics.Bitmap;
62import android.graphics.Canvas;
63import android.graphics.Rect;
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +010064import android.graphics.drawable.BitmapDrawable;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080065import android.graphics.drawable.Drawable;
Kenny Guy02c89902016-11-15 19:36:38 +000066import android.graphics.drawable.LayerDrawable;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080067import android.net.Uri;
Jeff Sharkeye6306c42017-03-07 21:03:18 -070068import android.os.Build;
Jeff Sharkey50a05452015-04-29 11:24:52 -070069import android.os.Bundle;
Jeff Sharkey620b32b2015-04-23 19:36:02 -070070import android.os.Handler;
71import android.os.Looper;
72import android.os.Message;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080073import android.os.Process;
74import android.os.RemoteException;
Jeff Sharkeyb2b9ab82015-04-05 21:10:42 -070075import android.os.SystemProperties;
Amith Yamasani67df64b2012-12-14 12:09:36 -080076import android.os.UserHandle;
Nicolas Prevot88cc3462014-05-14 14:51:48 +010077import android.os.UserManager;
Jeff Sharkeye2d45be2015-04-15 17:14:12 -070078import android.os.storage.StorageManager;
79import android.os.storage.VolumeInfo;
Todd Kennedyf39ca8f2015-08-07 14:15:07 -070080import android.provider.Settings;
Dianne Hackbornadd005c2013-07-17 18:43:12 -070081import android.util.ArrayMap;
Sunny Goyalbab30752017-04-12 15:36:42 -070082import android.util.IconDrawableFactory;
83import android.util.LauncherIcons;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080084import android.util.Log;
Jeff Browna492c3a2012-08-23 19:48:44 -070085import android.view.Display;
Jeff Sharkeyb2b9ab82015-04-05 21:10:42 -070086
87import dalvik.system.VMRuntime;
Jeff Sharkey16c8e3f2014-07-24 17:08:17 -070088
89import com.android.internal.annotations.GuardedBy;
Kenny Guy02c89902016-11-15 19:36:38 +000090import com.android.internal.annotations.VisibleForTesting;
Jeff Sharkeyb36586a2015-04-27 08:42:28 -070091import com.android.internal.os.SomeArgs;
dcashman9d2f4412014-06-09 09:27:54 -070092import com.android.internal.util.Preconditions;
Alexandra Gherghina64d4dca2014-08-28 18:26:56 +010093import com.android.internal.util.UserIcons;
Svet Ganov2acf0632015-11-24 19:10:59 -080094import libcore.util.EmptyArray;
Jeff Sharkey16c8e3f2014-07-24 17:08:17 -070095
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080096import java.lang.ref.WeakReference;
97import java.util.ArrayList;
Svet Ganov2acf0632015-11-24 19:10:59 -080098import java.util.Collections;
Jeff Sharkey620b32b2015-04-23 19:36:02 -070099import java.util.Iterator;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800100import java.util.List;
Svetoslavf7c06eb2015-06-10 18:43:22 -0700101import java.util.Map;
Jeff Sharkey620b32b2015-04-23 19:36:02 -0700102import java.util.Objects;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800103
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700104/** @hide */
105public class ApplicationPackageManager extends PackageManager {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800106 private static final String TAG = "ApplicationPackageManager";
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800107 private final static boolean DEBUG_ICONS = false;
108
Svet Ganov2acf0632015-11-24 19:10:59 -0800109 private static final int DEFAULT_EPHEMERAL_COOKIE_MAX_SIZE_BYTES = 16384; // 16KB
110
Adam Lesinskid00bb5e2014-10-07 12:14:45 -0700111 // Default flags to use with PackageManager when no flags are given.
112 private final static int sDefaultFlags = PackageManager.GET_SHARED_LIBRARY_FILES;
113
Jeff Sharkey16c8e3f2014-07-24 17:08:17 -0700114 private final Object mLock = new Object();
115
116 @GuardedBy("mLock")
117 private UserManager mUserManager;
118 @GuardedBy("mLock")
119 private PackageInstaller mInstaller;
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +0100120
Jeff Sharkey620b32b2015-04-23 19:36:02 -0700121 @GuardedBy("mDelegates")
122 private final ArrayList<MoveCallbackDelegate> mDelegates = new ArrayList<>();
123
Svet Ganovf1b7f202015-07-29 08:33:42 -0700124 @GuardedBy("mLock")
125 private String mPermissionsControllerPackageName;
126
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +0100127 UserManager getUserManager() {
Jeff Sharkey16c8e3f2014-07-24 17:08:17 -0700128 synchronized (mLock) {
129 if (mUserManager == null) {
130 mUserManager = UserManager.get(mContext);
131 }
132 return mUserManager;
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +0100133 }
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +0100134 }
135
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800136 @Override
137 public PackageInfo getPackageInfo(String packageName, int flags)
138 throws NameNotFoundException {
Nicolas Prevot9a80e532015-09-23 15:49:28 +0100139 return getPackageInfoAsUser(packageName, flags, mContext.getUserId());
140 }
141
142 @Override
Svet Ganov67882122016-12-11 16:36:34 -0800143 public PackageInfo getPackageInfo(VersionedPackage versionedPackage, int flags)
144 throws NameNotFoundException {
145 try {
146 PackageInfo pi = mPM.getPackageInfoVersioned(versionedPackage, flags,
147 mContext.getUserId());
148 if (pi != null) {
149 return pi;
150 }
151 } catch (RemoteException e) {
152 throw e.rethrowFromSystemServer();
153 }
154 throw new NameNotFoundException(versionedPackage.toString());
155 }
156
157 @Override
Nicolas Prevot9a80e532015-09-23 15:49:28 +0100158 public PackageInfo getPackageInfoAsUser(String packageName, int flags, int userId)
159 throws NameNotFoundException {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800160 try {
Nicolas Prevot9a80e532015-09-23 15:49:28 +0100161 PackageInfo pi = mPM.getPackageInfo(packageName, flags, userId);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800162 if (pi != null) {
163 return pi;
164 }
165 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700166 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800167 }
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800168 throw new NameNotFoundException(packageName);
169 }
170
171 @Override
172 public String[] currentToCanonicalPackageNames(String[] names) {
173 try {
174 return mPM.currentToCanonicalPackageNames(names);
175 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700176 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800177 }
178 }
179
180 @Override
181 public String[] canonicalToCurrentPackageNames(String[] names) {
182 try {
183 return mPM.canonicalToCurrentPackageNames(names);
184 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700185 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800186 }
187 }
188
189 @Override
190 public Intent getLaunchIntentForPackage(String packageName) {
191 // First see if the package has an INFO activity; the existence of
192 // such an activity is implied to be the desired front-door for the
193 // overall package (such as if it has multiple launcher entries).
194 Intent intentToResolve = new Intent(Intent.ACTION_MAIN);
195 intentToResolve.addCategory(Intent.CATEGORY_INFO);
196 intentToResolve.setPackage(packageName);
Dianne Hackborn19415762010-12-15 00:20:27 -0800197 List<ResolveInfo> ris = queryIntentActivities(intentToResolve, 0);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800198
199 // Otherwise, try to find a main launcher activity.
Dianne Hackborn19415762010-12-15 00:20:27 -0800200 if (ris == null || ris.size() <= 0) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800201 // reuse the intent instance
202 intentToResolve.removeCategory(Intent.CATEGORY_INFO);
203 intentToResolve.addCategory(Intent.CATEGORY_LAUNCHER);
204 intentToResolve.setPackage(packageName);
Dianne Hackborn19415762010-12-15 00:20:27 -0800205 ris = queryIntentActivities(intentToResolve, 0);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800206 }
Dianne Hackborn19415762010-12-15 00:20:27 -0800207 if (ris == null || ris.size() <= 0) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800208 return null;
209 }
210 Intent intent = new Intent(intentToResolve);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800211 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Dianne Hackborn19415762010-12-15 00:20:27 -0800212 intent.setClassName(ris.get(0).activityInfo.packageName,
213 ris.get(0).activityInfo.name);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800214 return intent;
215 }
216
217 @Override
Jose Lima970417c2014-04-10 10:42:19 -0700218 public Intent getLeanbackLaunchIntentForPackage(String packageName) {
219 // Try to find a main leanback_launcher activity.
220 Intent intentToResolve = new Intent(Intent.ACTION_MAIN);
221 intentToResolve.addCategory(Intent.CATEGORY_LEANBACK_LAUNCHER);
222 intentToResolve.setPackage(packageName);
223 List<ResolveInfo> ris = queryIntentActivities(intentToResolve, 0);
224
225 if (ris == null || ris.size() <= 0) {
226 return null;
227 }
228 Intent intent = new Intent(intentToResolve);
229 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
230 intent.setClassName(ris.get(0).activityInfo.packageName,
231 ris.get(0).activityInfo.name);
232 return intent;
233 }
234
235 @Override
Jeff Sharkey8588bc12016-01-06 16:47:42 -0700236 public int[] getPackageGids(String packageName) throws NameNotFoundException {
237 return getPackageGids(packageName, 0);
238 }
239
240 @Override
241 public int[] getPackageGids(String packageName, int flags)
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800242 throws NameNotFoundException {
243 try {
Jeff Sharkeycd654482016-01-08 17:42:11 -0700244 int[] gids = mPM.getPackageGids(packageName, flags, mContext.getUserId());
Svetoslavc6d1c342015-02-26 14:44:43 -0800245 if (gids != null) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800246 return gids;
247 }
248 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700249 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800250 }
251
252 throw new NameNotFoundException(packageName);
253 }
254
255 @Override
Jeff Sharkey8588bc12016-01-06 16:47:42 -0700256 public int getPackageUid(String packageName, int flags) throws NameNotFoundException {
257 return getPackageUidAsUser(packageName, flags, mContext.getUserId());
258 }
259
260 @Override
261 public int getPackageUidAsUser(String packageName, int userId) throws NameNotFoundException {
262 return getPackageUidAsUser(packageName, 0, userId);
263 }
264
265 @Override
266 public int getPackageUidAsUser(String packageName, int flags, int userId)
Dianne Hackborna06de0f2012-12-11 16:34:47 -0800267 throws NameNotFoundException {
268 try {
Jeff Sharkeycd654482016-01-08 17:42:11 -0700269 int uid = mPM.getPackageUid(packageName, flags, userId);
Dianne Hackborna06de0f2012-12-11 16:34:47 -0800270 if (uid >= 0) {
271 return uid;
272 }
273 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700274 throw e.rethrowFromSystemServer();
Dianne Hackborna06de0f2012-12-11 16:34:47 -0800275 }
276
277 throw new NameNotFoundException(packageName);
278 }
279
280 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800281 public PermissionInfo getPermissionInfo(String name, int flags)
282 throws NameNotFoundException {
283 try {
Svetoslav Ganovadb8c522017-07-28 05:46:53 +0000284 PermissionInfo pi = mPM.getPermissionInfo(name,
285 mContext.getOpPackageName(), flags);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800286 if (pi != null) {
287 return pi;
288 }
289 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700290 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800291 }
292
293 throw new NameNotFoundException(name);
294 }
295
296 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700297 @SuppressWarnings("unchecked")
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800298 public List<PermissionInfo> queryPermissionsByGroup(String group, int flags)
299 throws NameNotFoundException {
300 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700301 ParceledListSlice<PermissionInfo> parceledList =
302 mPM.queryPermissionsByGroup(group, flags);
303 if (parceledList != null) {
304 List<PermissionInfo> pi = parceledList.getList();
305 if (pi != null) {
306 return pi;
307 }
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800308 }
309 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700310 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800311 }
312
313 throw new NameNotFoundException(group);
314 }
315
316 @Override
Paul Navin7b89a7b2017-01-26 23:56:08 +0000317 public boolean isPermissionReviewModeEnabled() {
318 return mContext.getResources().getBoolean(
319 com.android.internal.R.bool.config_permissionReviewRequired);
320 }
321
322 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800323 public PermissionGroupInfo getPermissionGroupInfo(String name,
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700324 int flags) throws NameNotFoundException {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800325 try {
326 PermissionGroupInfo pgi = mPM.getPermissionGroupInfo(name, flags);
327 if (pgi != null) {
328 return pgi;
329 }
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(name);
335 }
336
337 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700338 @SuppressWarnings("unchecked")
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800339 public List<PermissionGroupInfo> getAllPermissionGroups(int flags) {
340 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700341 ParceledListSlice<PermissionGroupInfo> parceledList =
342 mPM.getAllPermissionGroups(flags);
343 if (parceledList == null) {
344 return Collections.emptyList();
345 }
346 return parceledList.getList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800347 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700348 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800349 }
350 }
351
352 @Override
353 public ApplicationInfo getApplicationInfo(String packageName, int flags)
354 throws NameNotFoundException {
Jeff Sharkeycd654482016-01-08 17:42:11 -0700355 return getApplicationInfoAsUser(packageName, flags, mContext.getUserId());
356 }
357
358 @Override
359 public ApplicationInfo getApplicationInfoAsUser(String packageName, int flags, int userId)
360 throws NameNotFoundException {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800361 try {
Jeff Sharkeycd654482016-01-08 17:42:11 -0700362 ApplicationInfo ai = mPM.getApplicationInfo(packageName, flags, userId);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800363 if (ai != null) {
Narayan Kamathcaa71192014-07-16 11:06:43 +0100364 // This is a temporary hack. Callers must use
365 // createPackageContext(packageName).getApplicationInfo() to
366 // get the right paths.
Tao Baic9a02372016-01-12 15:02:24 -0800367 return maybeAdjustApplicationInfo(ai);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800368 }
369 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700370 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800371 }
372
373 throw new NameNotFoundException(packageName);
374 }
375
Tao Baic9a02372016-01-12 15:02:24 -0800376 private static ApplicationInfo maybeAdjustApplicationInfo(ApplicationInfo info) {
Narayan Kamathcaa71192014-07-16 11:06:43 +0100377 // If we're dealing with a multi-arch application that has both
378 // 32 and 64 bit shared libraries, we might need to choose the secondary
379 // depending on what the current runtime's instruction set is.
380 if (info.primaryCpuAbi != null && info.secondaryCpuAbi != null) {
381 final String runtimeIsa = VMRuntime.getRuntime().vmInstructionSet();
jgu214741cd92014-12-17 17:23:29 -0500382
383 // Get the instruction set that the libraries of secondary Abi is supported.
384 // In presence of a native bridge this might be different than the one secondary Abi used.
385 String secondaryIsa = VMRuntime.getInstructionSet(info.secondaryCpuAbi);
386 final String secondaryDexCodeIsa = SystemProperties.get("ro.dalvik.vm.isa." + secondaryIsa);
387 secondaryIsa = secondaryDexCodeIsa.isEmpty() ? secondaryIsa : secondaryDexCodeIsa;
Narayan Kamathcaa71192014-07-16 11:06:43 +0100388
389 // If the runtimeIsa is the same as the primary isa, then we do nothing.
390 // Everything will be set up correctly because info.nativeLibraryDir will
391 // correspond to the right ISA.
392 if (runtimeIsa.equals(secondaryIsa)) {
Tao Baic9a02372016-01-12 15:02:24 -0800393 ApplicationInfo modified = new ApplicationInfo(info);
394 modified.nativeLibraryDir = info.secondaryNativeLibraryDir;
395 return modified;
Narayan Kamathcaa71192014-07-16 11:06:43 +0100396 }
397 }
Tao Baic9a02372016-01-12 15:02:24 -0800398 return info;
Narayan Kamathcaa71192014-07-16 11:06:43 +0100399 }
400
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800401 @Override
402 public ActivityInfo getActivityInfo(ComponentName className, int flags)
403 throws NameNotFoundException {
404 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700405 ActivityInfo ai = mPM.getActivityInfo(className, flags, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800406 if (ai != null) {
407 return ai;
408 }
409 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700410 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800411 }
412
413 throw new NameNotFoundException(className.toString());
414 }
415
416 @Override
417 public ActivityInfo getReceiverInfo(ComponentName className, int flags)
418 throws NameNotFoundException {
419 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700420 ActivityInfo ai = mPM.getReceiverInfo(className, flags, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800421 if (ai != null) {
422 return ai;
423 }
424 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700425 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800426 }
427
428 throw new NameNotFoundException(className.toString());
429 }
430
431 @Override
432 public ServiceInfo getServiceInfo(ComponentName className, int flags)
433 throws NameNotFoundException {
434 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700435 ServiceInfo si = mPM.getServiceInfo(className, flags, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800436 if (si != null) {
437 return si;
438 }
439 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700440 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800441 }
442
443 throw new NameNotFoundException(className.toString());
444 }
445
446 @Override
447 public ProviderInfo getProviderInfo(ComponentName className, int flags)
448 throws NameNotFoundException {
449 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700450 ProviderInfo pi = mPM.getProviderInfo(className, flags, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800451 if (pi != null) {
452 return pi;
453 }
454 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700455 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800456 }
457
458 throw new NameNotFoundException(className.toString());
459 }
460
461 @Override
462 public String[] getSystemSharedLibraryNames() {
463 try {
464 return mPM.getSystemSharedLibraryNames();
465 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700466 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800467 }
468 }
469
Svet Ganovd7b1f4112016-02-09 18:49:23 -0800470 /** @hide */
471 @Override
Svet Ganov67882122016-12-11 16:36:34 -0800472 public @NonNull List<SharedLibraryInfo> getSharedLibraries(int flags) {
473 return getSharedLibrariesAsUser(flags, mContext.getUserId());
474 }
475
476 /** @hide */
477 @Override
478 @SuppressWarnings("unchecked")
479 public @NonNull List<SharedLibraryInfo> getSharedLibrariesAsUser(int flags, int userId) {
480 try {
481 ParceledListSlice<SharedLibraryInfo> sharedLibs = mPM.getSharedLibraries(
Svet Ganov58c99f02017-05-15 14:07:17 -0700482 mContext.getOpPackageName(), flags, userId);
Svet Ganov67882122016-12-11 16:36:34 -0800483 if (sharedLibs == null) {
484 return Collections.emptyList();
485 }
486 return sharedLibs.getList();
487 } catch (RemoteException e) {
488 throw e.rethrowFromSystemServer();
489 }
490 }
491
492 /** @hide */
493 @Override
Svetoslav Ganova9c25002016-04-13 19:25:56 -0700494 public @NonNull String getServicesSystemSharedLibraryPackageName() {
Svet Ganovd7b1f4112016-02-09 18:49:23 -0800495 try {
496 return mPM.getServicesSystemSharedLibraryPackageName();
497 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700498 throw e.rethrowFromSystemServer();
Svet Ganovd7b1f4112016-02-09 18:49:23 -0800499 }
500 }
501
Svetoslav Ganova9c25002016-04-13 19:25:56 -0700502 /**
503 * @hide
504 */
505 public @NonNull String getSharedSystemSharedLibraryPackageName() {
506 try {
507 return mPM.getSharedSystemSharedLibraryPackageName();
508 } catch (RemoteException e) {
509 throw e.rethrowFromSystemServer();
510 }
511 }
512
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800513 @Override
Todd Kennedy9106c642017-02-08 14:16:53 -0800514 public ChangedPackages getChangedPackages(int sequenceNumber) {
515 try {
516 return mPM.getChangedPackages(sequenceNumber, mContext.getUserId());
517 } catch (RemoteException e) {
518 throw e.rethrowFromSystemServer();
519 }
520 }
521
522 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700523 @SuppressWarnings("unchecked")
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800524 public FeatureInfo[] getSystemAvailableFeatures() {
525 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700526 ParceledListSlice<FeatureInfo> parceledList =
527 mPM.getSystemAvailableFeatures();
528 if (parceledList == null) {
529 return new FeatureInfo[0];
530 }
531 final List<FeatureInfo> list = parceledList.getList();
Jeff Sharkeyd5896632016-03-04 16:16:00 -0700532 final FeatureInfo[] res = new FeatureInfo[list.size()];
533 for (int i = 0; i < res.length; i++) {
534 res[i] = list.get(i);
535 }
536 return res;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800537 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700538 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800539 }
540 }
541
542 @Override
543 public boolean hasSystemFeature(String name) {
Jeff Sharkey115d2c12016-02-15 17:25:57 -0700544 return hasSystemFeature(name, 0);
545 }
546
547 @Override
548 public boolean hasSystemFeature(String name, int version) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800549 try {
Jeff Sharkey115d2c12016-02-15 17:25:57 -0700550 return mPM.hasSystemFeature(name, version);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800551 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700552 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800553 }
554 }
555
556 @Override
557 public int checkPermission(String permName, String pkgName) {
558 try {
Svetoslavc6d1c342015-02-26 14:44:43 -0800559 return mPM.checkPermission(permName, pkgName, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800560 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700561 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800562 }
563 }
564
565 @Override
Svet Ganovad3b2972015-07-07 22:49:17 -0700566 public boolean isPermissionRevokedByPolicy(String permName, String pkgName) {
567 try {
568 return mPM.isPermissionRevokedByPolicy(permName, pkgName, mContext.getUserId());
569 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700570 throw e.rethrowFromSystemServer();
Svet Ganovad3b2972015-07-07 22:49:17 -0700571 }
572 }
573
Svet Ganovf1b7f202015-07-29 08:33:42 -0700574 /**
575 * @hide
576 */
577 @Override
578 public String getPermissionControllerPackageName() {
579 synchronized (mLock) {
580 if (mPermissionsControllerPackageName == null) {
581 try {
582 mPermissionsControllerPackageName = mPM.getPermissionControllerPackageName();
583 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700584 throw e.rethrowFromSystemServer();
Svet Ganovf1b7f202015-07-29 08:33:42 -0700585 }
586 }
587 return mPermissionsControllerPackageName;
588 }
589 }
590
Svet Ganovad3b2972015-07-07 22:49:17 -0700591 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800592 public boolean addPermission(PermissionInfo info) {
593 try {
594 return mPM.addPermission(info);
595 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700596 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800597 }
598 }
599
600 @Override
601 public boolean addPermissionAsync(PermissionInfo info) {
602 try {
603 return mPM.addPermissionAsync(info);
604 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700605 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800606 }
607 }
608
609 @Override
610 public void removePermission(String name) {
611 try {
612 mPM.removePermission(name);
613 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700614 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800615 }
616 }
617
618 @Override
Svet Ganov8c7f7002015-05-07 10:48:44 -0700619 public void grantRuntimePermission(String packageName, String permissionName,
620 UserHandle user) {
Dianne Hackborne639da72012-02-21 15:11:13 -0800621 try {
Svet Ganov8c7f7002015-05-07 10:48:44 -0700622 mPM.grantRuntimePermission(packageName, permissionName, user.getIdentifier());
Dianne Hackborne639da72012-02-21 15:11:13 -0800623 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700624 throw e.rethrowFromSystemServer();
Dianne Hackborne639da72012-02-21 15:11:13 -0800625 }
626 }
627
628 @Override
Svet Ganov8c7f7002015-05-07 10:48:44 -0700629 public void revokeRuntimePermission(String packageName, String permissionName,
630 UserHandle user) {
Dianne Hackborne639da72012-02-21 15:11:13 -0800631 try {
Svet Ganov8c7f7002015-05-07 10:48:44 -0700632 mPM.revokeRuntimePermission(packageName, permissionName, user.getIdentifier());
633 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700634 throw e.rethrowFromSystemServer();
Svet Ganov8c7f7002015-05-07 10:48:44 -0700635 }
636 }
637
638 @Override
639 public int getPermissionFlags(String permissionName, String packageName, UserHandle user) {
640 try {
641 return mPM.getPermissionFlags(permissionName, packageName, user.getIdentifier());
642 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700643 throw e.rethrowFromSystemServer();
Svet Ganov8c7f7002015-05-07 10:48:44 -0700644 }
645 }
646
647 @Override
648 public void updatePermissionFlags(String permissionName, String packageName,
649 int flagMask, int flagValues, UserHandle user) {
650 try {
651 mPM.updatePermissionFlags(permissionName, packageName, flagMask,
652 flagValues, user.getIdentifier());
Dianne Hackborne639da72012-02-21 15:11:13 -0800653 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700654 throw e.rethrowFromSystemServer();
Dianne Hackborne639da72012-02-21 15:11:13 -0800655 }
656 }
657
658 @Override
Svetoslav20770dd2015-05-29 15:43:04 -0700659 public boolean shouldShowRequestPermissionRationale(String permission) {
660 try {
661 return mPM.shouldShowRequestPermissionRationale(permission,
662 mContext.getPackageName(), mContext.getUserId());
663 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700664 throw e.rethrowFromSystemServer();
Svetoslav20770dd2015-05-29 15:43:04 -0700665 }
666 }
667
668 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800669 public int checkSignatures(String pkg1, String pkg2) {
670 try {
671 return mPM.checkSignatures(pkg1, pkg2);
672 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700673 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800674 }
675 }
676
677 @Override
678 public int checkSignatures(int uid1, int uid2) {
679 try {
680 return mPM.checkUidSignatures(uid1, uid2);
681 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700682 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800683 }
684 }
685
686 @Override
687 public String[] getPackagesForUid(int uid) {
688 try {
689 return mPM.getPackagesForUid(uid);
690 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700691 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800692 }
693 }
694
695 @Override
696 public String getNameForUid(int uid) {
697 try {
698 return mPM.getNameForUid(uid);
699 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700700 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800701 }
702 }
703
704 @Override
705 public int getUidForSharedUser(String sharedUserName)
706 throws NameNotFoundException {
707 try {
708 int uid = mPM.getUidForSharedUser(sharedUserName);
709 if(uid != -1) {
710 return uid;
711 }
712 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700713 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800714 }
715 throw new NameNotFoundException("No shared userid for user:"+sharedUserName);
716 }
717
Kenny Roote6cd0c72011-05-19 12:48:14 -0700718 @SuppressWarnings("unchecked")
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800719 @Override
720 public List<PackageInfo> getInstalledPackages(int flags) {
Jeff Sharkeye06b4d12016-01-06 14:51:50 -0700721 return getInstalledPackagesAsUser(flags, mContext.getUserId());
Amith Yamasani151ec4c2012-09-07 19:25:16 -0700722 }
723
724 /** @hide */
725 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700726 @SuppressWarnings("unchecked")
Jeff Sharkeye06b4d12016-01-06 14:51:50 -0700727 public List<PackageInfo> getInstalledPackagesAsUser(int flags, int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800728 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700729 ParceledListSlice<PackageInfo> parceledList =
730 mPM.getInstalledPackages(flags, userId);
731 if (parceledList == null) {
732 return Collections.emptyList();
733 }
734 return parceledList.getList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800735 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700736 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800737 }
738 }
739
Kenny Roote6cd0c72011-05-19 12:48:14 -0700740 @SuppressWarnings("unchecked")
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800741 @Override
Dianne Hackborne7991752013-01-16 17:56:46 -0800742 public List<PackageInfo> getPackagesHoldingPermissions(
743 String[] permissions, int flags) {
744 final int userId = mContext.getUserId();
745 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700746 ParceledListSlice<PackageInfo> parceledList =
747 mPM.getPackagesHoldingPermissions(permissions, flags, userId);
748 if (parceledList == null) {
749 return Collections.emptyList();
750 }
751 return parceledList.getList();
Dianne Hackborne7991752013-01-16 17:56:46 -0800752 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700753 throw e.rethrowFromSystemServer();
Dianne Hackborne7991752013-01-16 17:56:46 -0800754 }
755 }
756
757 @SuppressWarnings("unchecked")
758 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800759 public List<ApplicationInfo> getInstalledApplications(int flags) {
Bartosz Fabianowski11334242016-11-17 20:49:16 +0100760 return getInstalledApplicationsAsUser(flags, mContext.getUserId());
761 }
762
763 /** @hide */
764 @SuppressWarnings("unchecked")
765 @Override
766 public List<ApplicationInfo> getInstalledApplicationsAsUser(int flags, int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800767 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700768 ParceledListSlice<ApplicationInfo> parceledList =
769 mPM.getInstalledApplications(flags, userId);
770 if (parceledList == null) {
771 return Collections.emptyList();
772 }
773 return parceledList.getList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800774 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700775 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800776 }
777 }
778
Svet Ganov2acf0632015-11-24 19:10:59 -0800779 /** @hide */
780 @SuppressWarnings("unchecked")
781 @Override
Svetoslav Ganov096d3042017-01-30 16:34:13 -0800782 public List<InstantAppInfo> getInstantApps() {
Svet Ganov2acf0632015-11-24 19:10:59 -0800783 try {
Svetoslav Ganov096d3042017-01-30 16:34:13 -0800784 ParceledListSlice<InstantAppInfo> slice =
785 mPM.getInstantApps(mContext.getUserId());
Svet Ganov2acf0632015-11-24 19:10:59 -0800786 if (slice != null) {
787 return slice.getList();
788 }
789 return Collections.emptyList();
790 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700791 throw e.rethrowFromSystemServer();
Svet Ganov2acf0632015-11-24 19:10:59 -0800792 }
793 }
794
795 /** @hide */
796 @Override
Svetoslav Ganov096d3042017-01-30 16:34:13 -0800797 public Drawable getInstantAppIcon(String packageName) {
Svet Ganov2acf0632015-11-24 19:10:59 -0800798 try {
Svetoslav Ganov096d3042017-01-30 16:34:13 -0800799 Bitmap bitmap = mPM.getInstantAppIcon(
Svet Ganov2acf0632015-11-24 19:10:59 -0800800 packageName, mContext.getUserId());
801 if (bitmap != null) {
802 return new BitmapDrawable(null, bitmap);
803 }
804 return null;
805 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700806 throw e.rethrowFromSystemServer();
Svet Ganov2acf0632015-11-24 19:10:59 -0800807 }
808 }
809
810 @Override
Svetoslav Ganov096d3042017-01-30 16:34:13 -0800811 public boolean isInstantApp() {
David Christie31a16552017-03-01 15:08:45 -0800812 return isInstantApp(mContext.getPackageName());
813 }
814
815 @Override
816 public boolean isInstantApp(String packageName) {
Svet Ganov2acf0632015-11-24 19:10:59 -0800817 try {
David Christie31a16552017-03-01 15:08:45 -0800818 return mPM.isInstantApp(packageName, mContext.getUserId());
Svet Ganov2acf0632015-11-24 19:10:59 -0800819 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700820 throw e.rethrowFromSystemServer();
Svet Ganov2acf0632015-11-24 19:10:59 -0800821 }
Svet Ganov2acf0632015-11-24 19:10:59 -0800822 }
823
Svetoslav Ganov345ffa52017-04-18 16:08:41 -0700824 public int getInstantAppCookieMaxBytes() {
Svet Ganov2acf0632015-11-24 19:10:59 -0800825 return Settings.Global.getInt(mContext.getContentResolver(),
826 Settings.Global.EPHEMERAL_COOKIE_MAX_SIZE_BYTES,
827 DEFAULT_EPHEMERAL_COOKIE_MAX_SIZE_BYTES);
828 }
829
830 @Override
Svetoslav Ganov345ffa52017-04-18 16:08:41 -0700831 public int getInstantAppCookieMaxSize() {
832 return getInstantAppCookieMaxBytes();
833 }
834
835 @Override
Svetoslav Ganov096d3042017-01-30 16:34:13 -0800836 public @NonNull byte[] getInstantAppCookie() {
Svet Ganov2acf0632015-11-24 19:10:59 -0800837 try {
Svetoslav Ganov096d3042017-01-30 16:34:13 -0800838 final byte[] cookie = mPM.getInstantAppCookie(
Svet Ganov2acf0632015-11-24 19:10:59 -0800839 mContext.getPackageName(), mContext.getUserId());
840 if (cookie != null) {
841 return cookie;
Jeff Sharkey27b2e692016-02-25 17:40:12 -0700842 } else {
843 return EmptyArray.BYTE;
Svet Ganov2acf0632015-11-24 19:10:59 -0800844 }
845 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700846 throw e.rethrowFromSystemServer();
Svet Ganov2acf0632015-11-24 19:10:59 -0800847 }
Svet Ganov2acf0632015-11-24 19:10:59 -0800848 }
849
850 @Override
Svetoslav Ganov345ffa52017-04-18 16:08:41 -0700851 public void clearInstantAppCookie() {
852 updateInstantAppCookie(null);
853 }
854
855 @Override
856 public void updateInstantAppCookie(@NonNull byte[] cookie) {
857 if (cookie != null && cookie.length > getInstantAppCookieMaxBytes()) {
858 throw new IllegalArgumentException("instant cookie longer than "
859 + getInstantAppCookieMaxBytes());
860 }
861 try {
862 mPM.setInstantAppCookie(mContext.getPackageName(),
863 cookie, mContext.getUserId());
864 } catch (RemoteException e) {
865 throw e.rethrowFromSystemServer();
866 }
867 }
868
869 @Override
Svetoslav Ganov096d3042017-01-30 16:34:13 -0800870 public boolean setInstantAppCookie(@NonNull byte[] cookie) {
Svet Ganov2acf0632015-11-24 19:10:59 -0800871 try {
Svetoslav Ganov096d3042017-01-30 16:34:13 -0800872 return mPM.setInstantAppCookie(mContext.getPackageName(),
873 cookie, mContext.getUserId());
Svet Ganov2acf0632015-11-24 19:10:59 -0800874 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700875 throw e.rethrowFromSystemServer();
Svet Ganov2acf0632015-11-24 19:10:59 -0800876 }
Svet Ganov2acf0632015-11-24 19:10:59 -0800877 }
878
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800879 @Override
880 public ResolveInfo resolveActivity(Intent intent, int flags) {
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700881 return resolveActivityAsUser(intent, flags, mContext.getUserId());
Svetoslav Ganov58d37b52012-09-18 12:04:19 -0700882 }
883
884 @Override
885 public ResolveInfo resolveActivityAsUser(Intent intent, int flags, int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800886 try {
887 return mPM.resolveIntent(
888 intent,
889 intent.resolveTypeIfNeeded(mContext.getContentResolver()),
Svetoslav Ganov58d37b52012-09-18 12:04:19 -0700890 flags,
891 userId);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800892 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700893 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800894 }
895 }
896
897 @Override
898 public List<ResolveInfo> queryIntentActivities(Intent intent,
899 int flags) {
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700900 return queryIntentActivitiesAsUser(intent, flags, mContext.getUserId());
Amith Yamasani151ec4c2012-09-07 19:25:16 -0700901 }
902
903 /** @hide Same as above but for a specific user */
904 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700905 @SuppressWarnings("unchecked")
Svetoslav Ganov58d37b52012-09-18 12:04:19 -0700906 public List<ResolveInfo> queryIntentActivitiesAsUser(Intent intent,
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700907 int flags, int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800908 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700909 ParceledListSlice<ResolveInfo> parceledList =
910 mPM.queryIntentActivities(intent,
911 intent.resolveTypeIfNeeded(mContext.getContentResolver()),
912 flags, userId);
913 if (parceledList == null) {
914 return Collections.emptyList();
915 }
916 return parceledList.getList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800917 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700918 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800919 }
920 }
921
922 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700923 @SuppressWarnings("unchecked")
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800924 public List<ResolveInfo> queryIntentActivityOptions(
925 ComponentName caller, Intent[] specifics, Intent intent,
926 int flags) {
927 final ContentResolver resolver = mContext.getContentResolver();
928
929 String[] specificTypes = null;
930 if (specifics != null) {
931 final int N = specifics.length;
932 for (int i=0; i<N; i++) {
933 Intent sp = specifics[i];
934 if (sp != null) {
935 String t = sp.resolveTypeIfNeeded(resolver);
936 if (t != null) {
937 if (specificTypes == null) {
938 specificTypes = new String[N];
939 }
940 specificTypes[i] = t;
941 }
942 }
943 }
944 }
945
946 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700947 ParceledListSlice<ResolveInfo> parceledList =
948 mPM.queryIntentActivityOptions(caller, specifics, specificTypes, intent,
949 intent.resolveTypeIfNeeded(resolver), flags, mContext.getUserId());
950 if (parceledList == null) {
951 return Collections.emptyList();
952 }
953 return parceledList.getList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800954 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700955 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800956 }
957 }
958
Amith Yamasanif203aee2012-08-29 18:41:53 -0700959 /**
960 * @hide
961 */
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800962 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700963 @SuppressWarnings("unchecked")
Jeff Sharkeye06b4d12016-01-06 14:51:50 -0700964 public List<ResolveInfo> queryBroadcastReceiversAsUser(Intent intent, int flags, int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800965 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700966 ParceledListSlice<ResolveInfo> parceledList =
967 mPM.queryIntentReceivers(intent,
968 intent.resolveTypeIfNeeded(mContext.getContentResolver()),
969 flags, userId);
970 if (parceledList == null) {
971 return Collections.emptyList();
972 }
973 return parceledList.getList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800974 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700975 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800976 }
977 }
978
979 @Override
Amith Yamasanif203aee2012-08-29 18:41:53 -0700980 public List<ResolveInfo> queryBroadcastReceivers(Intent intent, int flags) {
Jeff Sharkeye06b4d12016-01-06 14:51:50 -0700981 return queryBroadcastReceiversAsUser(intent, flags, mContext.getUserId());
Amith Yamasanif203aee2012-08-29 18:41:53 -0700982 }
983
984 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800985 public ResolveInfo resolveService(Intent intent, int flags) {
986 try {
987 return mPM.resolveService(
988 intent,
989 intent.resolveTypeIfNeeded(mContext.getContentResolver()),
Amith Yamasani483f3b02012-03-13 16:08:00 -0700990 flags,
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700991 mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800992 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700993 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800994 }
995 }
996
997 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700998 @SuppressWarnings("unchecked")
Svetoslav Ganov58d37b52012-09-18 12:04:19 -0700999 public List<ResolveInfo> queryIntentServicesAsUser(Intent intent, int flags, int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001000 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001001 ParceledListSlice<ResolveInfo> parceledList =
1002 mPM.queryIntentServices(intent,
1003 intent.resolveTypeIfNeeded(mContext.getContentResolver()),
1004 flags, userId);
1005 if (parceledList == null) {
1006 return Collections.emptyList();
1007 }
1008 return parceledList.getList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001009 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001010 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001011 }
1012 }
1013
1014 @Override
Svetoslav Ganov58d37b52012-09-18 12:04:19 -07001015 public List<ResolveInfo> queryIntentServices(Intent intent, int flags) {
Jeff Sharkeyded653b2012-09-27 19:09:24 -07001016 return queryIntentServicesAsUser(intent, flags, mContext.getUserId());
Svetoslav Ganov58d37b52012-09-18 12:04:19 -07001017 }
1018
1019 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001020 @SuppressWarnings("unchecked")
Jeff Sharkey85f5f812013-10-07 10:16:12 -07001021 public List<ResolveInfo> queryIntentContentProvidersAsUser(
1022 Intent intent, int flags, int userId) {
1023 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001024 ParceledListSlice<ResolveInfo> parceledList =
1025 mPM.queryIntentContentProviders(intent,
1026 intent.resolveTypeIfNeeded(mContext.getContentResolver()),
1027 flags, userId);
1028 if (parceledList == null) {
1029 return Collections.emptyList();
1030 }
1031 return parceledList.getList();
Jeff Sharkey85f5f812013-10-07 10:16:12 -07001032 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001033 throw e.rethrowFromSystemServer();
Jeff Sharkey85f5f812013-10-07 10:16:12 -07001034 }
1035 }
1036
1037 @Override
1038 public List<ResolveInfo> queryIntentContentProviders(Intent intent, int flags) {
1039 return queryIntentContentProvidersAsUser(intent, flags, mContext.getUserId());
1040 }
1041
1042 @Override
Alexandra Gherghina0363c3e2014-06-23 13:34:59 +01001043 public ProviderInfo resolveContentProvider(String name, int flags) {
1044 return resolveContentProviderAsUser(name, flags, mContext.getUserId());
1045 }
1046
1047 /** @hide **/
1048 @Override
1049 public ProviderInfo resolveContentProviderAsUser(String name, int flags, int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001050 try {
Alexandra Gherghina0363c3e2014-06-23 13:34:59 +01001051 return mPM.resolveContentProvider(name, flags, userId);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001052 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001053 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001054 }
1055 }
1056
1057 @Override
1058 public List<ProviderInfo> queryContentProviders(String processName,
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001059 int uid, int flags) {
Makoto Onuki32757292017-02-22 14:36:59 -08001060 return queryContentProviders(processName, uid, flags, null);
1061 }
1062
1063 @Override
1064 @SuppressWarnings("unchecked")
1065 public List<ProviderInfo> queryContentProviders(String processName,
1066 int uid, int flags, String metaDataKey) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001067 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001068 ParceledListSlice<ProviderInfo> slice =
Makoto Onuki32757292017-02-22 14:36:59 -08001069 mPM.queryContentProviders(processName, uid, flags, metaDataKey);
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001070 return slice != null ? slice.getList() : Collections.<ProviderInfo>emptyList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001071 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001072 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001073 }
1074 }
1075
1076 @Override
1077 public InstrumentationInfo getInstrumentationInfo(
1078 ComponentName className, int flags)
1079 throws NameNotFoundException {
1080 try {
1081 InstrumentationInfo ii = mPM.getInstrumentationInfo(
1082 className, flags);
1083 if (ii != null) {
1084 return ii;
1085 }
1086 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001087 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001088 }
1089
1090 throw new NameNotFoundException(className.toString());
1091 }
1092
1093 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001094 @SuppressWarnings("unchecked")
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001095 public List<InstrumentationInfo> queryInstrumentation(
1096 String targetPackage, int flags) {
1097 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001098 ParceledListSlice<InstrumentationInfo> parceledList =
1099 mPM.queryInstrumentation(targetPackage, flags);
1100 if (parceledList == null) {
1101 return Collections.emptyList();
1102 }
1103 return parceledList.getList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001104 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001105 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001106 }
1107 }
1108
Alan Viveretteecd585a2015-04-13 10:32:51 -07001109 @Nullable
1110 @Override
1111 public Drawable getDrawable(String packageName, @DrawableRes int resId,
1112 @Nullable ApplicationInfo appInfo) {
1113 final ResourceName name = new ResourceName(packageName, resId);
1114 final Drawable cachedIcon = getCachedIcon(name);
1115 if (cachedIcon != null) {
1116 return cachedIcon;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001117 }
Alan Viveretteecd585a2015-04-13 10:32:51 -07001118
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001119 if (appInfo == null) {
1120 try {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001121 appInfo = getApplicationInfo(packageName, sDefaultFlags);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001122 } catch (NameNotFoundException e) {
1123 return null;
1124 }
1125 }
Alan Viveretteecd585a2015-04-13 10:32:51 -07001126
1127 if (resId != 0) {
1128 try {
1129 final Resources r = getResourcesForApplication(appInfo);
1130 final Drawable dr = r.getDrawable(resId, null);
1131 if (dr != null) {
1132 putCachedIcon(name, dr);
1133 }
1134
1135 if (false) {
1136 RuntimeException e = new RuntimeException("here");
1137 e.fillInStackTrace();
1138 Log.w(TAG, "Getting drawable 0x" + Integer.toHexString(resId)
1139 + " from package " + packageName
1140 + ": app scale=" + r.getCompatibilityInfo().applicationScale
1141 + ", caller scale=" + mContext.getResources()
1142 .getCompatibilityInfo().applicationScale,
1143 e);
1144 }
Ricky Wai3ce46252015-04-15 16:12:22 +01001145 if (DEBUG_ICONS) {
Alan Viveretteecd585a2015-04-13 10:32:51 -07001146 Log.v(TAG, "Getting drawable 0x"
1147 + Integer.toHexString(resId) + " from " + r
1148 + ": " + dr);
Ricky Wai3ce46252015-04-15 16:12:22 +01001149 }
1150 return dr;
Alan Viveretteecd585a2015-04-13 10:32:51 -07001151 } catch (NameNotFoundException e) {
1152 Log.w("PackageManager", "Failure retrieving resources for "
1153 + appInfo.packageName);
1154 } catch (Resources.NotFoundException e) {
1155 Log.w("PackageManager", "Failure retrieving resources for "
1156 + appInfo.packageName + ": " + e.getMessage());
1157 } catch (Exception e) {
1158 // If an exception was thrown, fall through to return
1159 // default icon.
1160 Log.w("PackageManager", "Failure retrieving icon 0x"
1161 + Integer.toHexString(resId) + " in package "
1162 + packageName, e);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001163 }
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001164 }
Alan Viveretteecd585a2015-04-13 10:32:51 -07001165
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001166 return null;
1167 }
1168
1169 @Override public Drawable getActivityIcon(ComponentName activityName)
1170 throws NameNotFoundException {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001171 return getActivityInfo(activityName, sDefaultFlags).loadIcon(this);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001172 }
1173
1174 @Override public Drawable getActivityIcon(Intent intent)
1175 throws NameNotFoundException {
1176 if (intent.getComponent() != null) {
1177 return getActivityIcon(intent.getComponent());
1178 }
1179
1180 ResolveInfo info = resolveActivity(
1181 intent, PackageManager.MATCH_DEFAULT_ONLY);
1182 if (info != null) {
1183 return info.activityInfo.loadIcon(this);
1184 }
1185
Romain Guy39fe17c2011-11-30 10:34:07 -08001186 throw new NameNotFoundException(intent.toUri(0));
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001187 }
1188
1189 @Override public Drawable getDefaultActivityIcon() {
1190 return Resources.getSystem().getDrawable(
1191 com.android.internal.R.drawable.sym_def_app_icon);
1192 }
1193
1194 @Override public Drawable getApplicationIcon(ApplicationInfo info) {
1195 return info.loadIcon(this);
1196 }
1197
1198 @Override public Drawable getApplicationIcon(String packageName)
1199 throws NameNotFoundException {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001200 return getApplicationIcon(getApplicationInfo(packageName, sDefaultFlags));
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001201 }
1202
1203 @Override
Jose Limaf78e3122014-03-06 12:13:15 -08001204 public Drawable getActivityBanner(ComponentName activityName)
1205 throws NameNotFoundException {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001206 return getActivityInfo(activityName, sDefaultFlags).loadBanner(this);
Jose Limaf78e3122014-03-06 12:13:15 -08001207 }
1208
1209 @Override
1210 public Drawable getActivityBanner(Intent intent)
1211 throws NameNotFoundException {
1212 if (intent.getComponent() != null) {
1213 return getActivityBanner(intent.getComponent());
1214 }
1215
1216 ResolveInfo info = resolveActivity(
1217 intent, PackageManager.MATCH_DEFAULT_ONLY);
1218 if (info != null) {
1219 return info.activityInfo.loadBanner(this);
1220 }
1221
1222 throw new NameNotFoundException(intent.toUri(0));
1223 }
1224
1225 @Override
1226 public Drawable getApplicationBanner(ApplicationInfo info) {
1227 return info.loadBanner(this);
1228 }
1229
1230 @Override
1231 public Drawable getApplicationBanner(String packageName)
1232 throws NameNotFoundException {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001233 return getApplicationBanner(getApplicationInfo(packageName, sDefaultFlags));
Jose Limaf78e3122014-03-06 12:13:15 -08001234 }
1235
1236 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001237 public Drawable getActivityLogo(ComponentName activityName)
1238 throws NameNotFoundException {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001239 return getActivityInfo(activityName, sDefaultFlags).loadLogo(this);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001240 }
1241
1242 @Override
1243 public Drawable getActivityLogo(Intent intent)
1244 throws NameNotFoundException {
1245 if (intent.getComponent() != null) {
1246 return getActivityLogo(intent.getComponent());
1247 }
1248
1249 ResolveInfo info = resolveActivity(
1250 intent, PackageManager.MATCH_DEFAULT_ONLY);
1251 if (info != null) {
1252 return info.activityInfo.loadLogo(this);
1253 }
1254
1255 throw new NameNotFoundException(intent.toUri(0));
1256 }
1257
1258 @Override
1259 public Drawable getApplicationLogo(ApplicationInfo info) {
1260 return info.loadLogo(this);
1261 }
1262
1263 @Override
1264 public Drawable getApplicationLogo(String packageName)
1265 throws NameNotFoundException {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001266 return getApplicationLogo(getApplicationInfo(packageName, sDefaultFlags));
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001267 }
1268
Svetoslavc7d62f02014-09-04 15:39:54 -07001269 @Override
1270 public Drawable getUserBadgedIcon(Drawable icon, UserHandle user) {
Kenny Guy02c89902016-11-15 19:36:38 +00001271 if (!isManagedProfile(user.getIdentifier())) {
Svetoslavc7d62f02014-09-04 15:39:54 -07001272 return icon;
1273 }
Sunny Goyalbab30752017-04-12 15:36:42 -07001274 Drawable badge = new LauncherIcons(mContext).getBadgeDrawable(
1275 com.android.internal.R.drawable.ic_corp_icon_badge_case,
1276 getUserBadgeColor(user));
Kenny Guy02c89902016-11-15 19:36:38 +00001277 return getBadgedDrawable(icon, badge, null, true);
Svetoslavc7d62f02014-09-04 15:39:54 -07001278 }
1279
1280 @Override
1281 public Drawable getUserBadgedDrawableForDensity(Drawable drawable, UserHandle user,
1282 Rect badgeLocation, int badgeDensity) {
1283 Drawable badgeDrawable = getUserBadgeForDensity(user, badgeDensity);
1284 if (badgeDrawable == null) {
1285 return drawable;
1286 }
1287 return getBadgedDrawable(drawable, badgeDrawable, badgeLocation, true);
1288 }
1289
Kenny Guy02c89902016-11-15 19:36:38 +00001290 @VisibleForTesting
1291 public static final int[] CORP_BADGE_LABEL_RES_ID = new int[] {
1292 com.android.internal.R.string.managed_profile_label_badge,
1293 com.android.internal.R.string.managed_profile_label_badge_2,
1294 com.android.internal.R.string.managed_profile_label_badge_3
1295 };
1296
1297 private int getUserBadgeColor(UserHandle user) {
Sunny Goyalbab30752017-04-12 15:36:42 -07001298 return IconDrawableFactory.getUserBadgeColor(getUserManager(), user.getIdentifier());
Kenny Guy02c89902016-11-15 19:36:38 +00001299 }
1300
Svetoslavc7d62f02014-09-04 15:39:54 -07001301 @Override
1302 public Drawable getUserBadgeForDensity(UserHandle user, int density) {
Kenny Guy02c89902016-11-15 19:36:38 +00001303 Drawable badgeColor = getManagedProfileIconForDensity(user,
1304 com.android.internal.R.drawable.ic_corp_badge_color, density);
1305 if (badgeColor == null) {
1306 return null;
1307 }
1308 badgeColor.setTint(getUserBadgeColor(user));
1309 Drawable badgeForeground = getDrawableForDensity(
1310 com.android.internal.R.drawable.ic_corp_badge_case, density);
1311 Drawable badge = new LayerDrawable(
1312 new Drawable[] {badgeColor, badgeForeground });
1313 return badge;
Selim Cineke6ff9462016-01-15 15:07:06 -08001314 }
1315
1316 @Override
1317 public Drawable getUserBadgeForDensityNoBackground(UserHandle user, int density) {
Kenny Guy02c89902016-11-15 19:36:38 +00001318 Drawable badge = getManagedProfileIconForDensity(user,
Vadim Tryshev66ae66a2016-02-18 15:41:21 -08001319 com.android.internal.R.drawable.ic_corp_badge_no_background, density);
Kenny Guy02c89902016-11-15 19:36:38 +00001320 if (badge != null) {
1321 badge.setTint(getUserBadgeColor(user));
1322 }
1323 return badge;
Selim Cineke6ff9462016-01-15 15:07:06 -08001324 }
1325
Vadim Tryshev66ae66a2016-02-18 15:41:21 -08001326 private Drawable getDrawableForDensity(int drawableId, int density) {
1327 if (density <= 0) {
1328 density = mContext.getResources().getDisplayMetrics().densityDpi;
1329 }
1330 return Resources.getSystem().getDrawableForDensity(drawableId, density);
1331 }
1332
1333 private Drawable getManagedProfileIconForDensity(UserHandle user, int drawableId, int density) {
Tony Mak8673b282016-03-21 21:10:59 +00001334 if (isManagedProfile(user.getIdentifier())) {
Vadim Tryshev66ae66a2016-02-18 15:41:21 -08001335 return getDrawableForDensity(drawableId, density);
Svetoslavc7d62f02014-09-04 15:39:54 -07001336 }
1337 return null;
1338 }
1339
1340 @Override
1341 public CharSequence getUserBadgedLabel(CharSequence label, UserHandle user) {
Tony Mak8673b282016-03-21 21:10:59 +00001342 if (isManagedProfile(user.getIdentifier())) {
Kenny Guy02c89902016-11-15 19:36:38 +00001343 int badge = getUserManager().getManagedProfileBadge(user.getIdentifier());
1344 int resourceId = CORP_BADGE_LABEL_RES_ID[badge % CORP_BADGE_LABEL_RES_ID.length];
1345 return Resources.getSystem().getString(resourceId, label);
Svetoslavc7d62f02014-09-04 15:39:54 -07001346 }
1347 return label;
1348 }
1349
Alan Viveretteecd585a2015-04-13 10:32:51 -07001350 @Override
1351 public Resources getResourcesForActivity(ComponentName activityName)
1352 throws NameNotFoundException {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001353 return getResourcesForApplication(
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001354 getActivityInfo(activityName, sDefaultFlags).applicationInfo);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001355 }
1356
Alan Viveretteecd585a2015-04-13 10:32:51 -07001357 @Override
1358 public Resources getResourcesForApplication(@NonNull ApplicationInfo app)
1359 throws NameNotFoundException {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001360 if (app.packageName.equals("system")) {
Adam Lesinskia82b6262017-03-21 16:56:17 -07001361 return mContext.mMainThread.getSystemUiContext().getResources();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001362 }
Jeff Sharkey8a4c9722014-06-16 13:48:42 -07001363 final boolean sameUid = (app.uid == Process.myUid());
Adam Lesinski53fafdf2016-08-03 13:36:39 -07001364 final Resources r = mContext.mMainThread.getTopLevelResources(
Adam Lesinskic82f28a2016-06-08 17:19:09 -07001365 sameUid ? app.sourceDir : app.publicSourceDir,
1366 sameUid ? app.splitSourceDirs : app.splitPublicSourceDirs,
1367 app.resourceDirs, app.sharedLibraryFiles, Display.DEFAULT_DISPLAY,
1368 mContext.mPackageInfo);
Adam Lesinski53fafdf2016-08-03 13:36:39 -07001369 if (r != null) {
1370 return r;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001371 }
Adam Lesinski53fafdf2016-08-03 13:36:39 -07001372 throw new NameNotFoundException("Unable to open " + app.publicSourceDir);
1373
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001374 }
1375
Alan Viveretteecd585a2015-04-13 10:32:51 -07001376 @Override
1377 public Resources getResourcesForApplication(String appPackageName)
1378 throws NameNotFoundException {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001379 return getResourcesForApplication(
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001380 getApplicationInfo(appPackageName, sDefaultFlags));
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001381 }
1382
Amith Yamasani98edc952012-09-25 14:09:27 -07001383 /** @hide */
1384 @Override
1385 public Resources getResourcesForApplicationAsUser(String appPackageName, int userId)
1386 throws NameNotFoundException {
Jeff Sharkeyded653b2012-09-27 19:09:24 -07001387 if (userId < 0) {
1388 throw new IllegalArgumentException(
1389 "Call does not support special user #" + userId);
1390 }
1391 if ("system".equals(appPackageName)) {
Adam Lesinskia82b6262017-03-21 16:56:17 -07001392 return mContext.mMainThread.getSystemUiContext().getResources();
Jeff Sharkeyded653b2012-09-27 19:09:24 -07001393 }
Amith Yamasani98edc952012-09-25 14:09:27 -07001394 try {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001395 ApplicationInfo ai = mPM.getApplicationInfo(appPackageName, sDefaultFlags, userId);
Amith Yamasani98edc952012-09-25 14:09:27 -07001396 if (ai != null) {
1397 return getResourcesForApplication(ai);
1398 }
1399 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001400 throw e.rethrowFromSystemServer();
Amith Yamasani98edc952012-09-25 14:09:27 -07001401 }
1402 throw new NameNotFoundException("Package " + appPackageName + " doesn't exist");
1403 }
1404
Jeff Sharkeycd654482016-01-08 17:42:11 -07001405 volatile int mCachedSafeMode = -1;
1406
1407 @Override
1408 public boolean isSafeMode() {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001409 try {
1410 if (mCachedSafeMode < 0) {
1411 mCachedSafeMode = mPM.isSafeMode() ? 1 : 0;
1412 }
1413 return mCachedSafeMode != 0;
1414 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001415 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001416 }
1417 }
1418
Svetoslavf7c06eb2015-06-10 18:43:22 -07001419 @Override
1420 public void addOnPermissionsChangeListener(OnPermissionsChangedListener listener) {
1421 synchronized (mPermissionListeners) {
1422 if (mPermissionListeners.get(listener) != null) {
1423 return;
1424 }
1425 OnPermissionsChangeListenerDelegate delegate =
1426 new OnPermissionsChangeListenerDelegate(listener, Looper.getMainLooper());
1427 try {
1428 mPM.addOnPermissionsChangeListener(delegate);
1429 mPermissionListeners.put(listener, delegate);
1430 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001431 throw e.rethrowFromSystemServer();
Svetoslavf7c06eb2015-06-10 18:43:22 -07001432 }
1433 }
1434 }
1435
1436 @Override
1437 public void removeOnPermissionsChangeListener(OnPermissionsChangedListener listener) {
1438 synchronized (mPermissionListeners) {
1439 IOnPermissionsChangeListener delegate = mPermissionListeners.get(listener);
1440 if (delegate != null) {
1441 try {
1442 mPM.removeOnPermissionsChangeListener(delegate);
1443 mPermissionListeners.remove(listener);
1444 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001445 throw e.rethrowFromSystemServer();
Svetoslavf7c06eb2015-06-10 18:43:22 -07001446 }
1447 }
1448 }
1449 }
1450
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001451 static void configurationChanged() {
1452 synchronized (sSync) {
1453 sIconCache.clear();
1454 sStringCache.clear();
1455 }
1456 }
1457
Yao Chen022b8ea2016-12-16 11:03:28 -08001458 protected ApplicationPackageManager(ContextImpl context,
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001459 IPackageManager pm) {
1460 mContext = context;
1461 mPM = pm;
1462 }
1463
Alan Viveretteecd585a2015-04-13 10:32:51 -07001464 @Nullable
1465 private Drawable getCachedIcon(@NonNull ResourceName name) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001466 synchronized (sSync) {
Alan Viveretteecd585a2015-04-13 10:32:51 -07001467 final WeakReference<Drawable.ConstantState> wr = sIconCache.get(name);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001468 if (DEBUG_ICONS) Log.v(TAG, "Get cached weak drawable ref for "
1469 + name + ": " + wr);
1470 if (wr != null) { // we have the activity
Alan Viveretteecd585a2015-04-13 10:32:51 -07001471 final Drawable.ConstantState state = wr.get();
Romain Guy39fe17c2011-11-30 10:34:07 -08001472 if (state != null) {
1473 if (DEBUG_ICONS) {
1474 Log.v(TAG, "Get cached drawable state for " + name + ": " + state);
1475 }
1476 // Note: It's okay here to not use the newDrawable(Resources) variant
1477 // of the API. The ConstantState comes from a drawable that was
1478 // originally created by passing the proper app Resources instance
1479 // which means the state should already contain the proper
1480 // resources specific information (like density.) See
1481 // BitmapDrawable.BitmapState for instance.
1482 return state.newDrawable();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001483 }
1484 // our entry has been purged
1485 sIconCache.remove(name);
1486 }
1487 }
1488 return null;
1489 }
1490
Alan Viveretteecd585a2015-04-13 10:32:51 -07001491 private void putCachedIcon(@NonNull ResourceName name, @NonNull Drawable dr) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001492 synchronized (sSync) {
Alan Viveretteecd585a2015-04-13 10:32:51 -07001493 sIconCache.put(name, new WeakReference<>(dr.getConstantState()));
Romain Guy39fe17c2011-11-30 10:34:07 -08001494 if (DEBUG_ICONS) Log.v(TAG, "Added cached drawable state for " + name + ": " + dr);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001495 }
1496 }
1497
Romain Guy39fe17c2011-11-30 10:34:07 -08001498 static void handlePackageBroadcast(int cmd, String[] pkgList, boolean hasPkgInfo) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001499 boolean immediateGc = false;
Sudheer Shankacc6418f2016-10-13 12:03:44 -07001500 if (cmd == ApplicationThreadConstants.EXTERNAL_STORAGE_UNAVAILABLE) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001501 immediateGc = true;
1502 }
1503 if (pkgList != null && (pkgList.length > 0)) {
1504 boolean needCleanup = false;
1505 for (String ssp : pkgList) {
1506 synchronized (sSync) {
Dianne Hackbornadd005c2013-07-17 18:43:12 -07001507 for (int i=sIconCache.size()-1; i>=0; i--) {
1508 ResourceName nm = sIconCache.keyAt(i);
1509 if (nm.packageName.equals(ssp)) {
1510 //Log.i(TAG, "Removing cached drawable for " + nm);
1511 sIconCache.removeAt(i);
1512 needCleanup = true;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001513 }
1514 }
Dianne Hackbornadd005c2013-07-17 18:43:12 -07001515 for (int i=sStringCache.size()-1; i>=0; i--) {
1516 ResourceName nm = sStringCache.keyAt(i);
1517 if (nm.packageName.equals(ssp)) {
1518 //Log.i(TAG, "Removing cached string for " + nm);
1519 sStringCache.removeAt(i);
1520 needCleanup = true;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001521 }
1522 }
1523 }
1524 }
1525 if (needCleanup || hasPkgInfo) {
1526 if (immediateGc) {
1527 // Schedule an immediate gc.
1528 Runtime.getRuntime().gc();
1529 } else {
1530 ActivityThread.currentActivityThread().scheduleGcIdler();
1531 }
1532 }
1533 }
1534 }
1535
1536 private static final class ResourceName {
1537 final String packageName;
1538 final int iconId;
1539
1540 ResourceName(String _packageName, int _iconId) {
1541 packageName = _packageName;
1542 iconId = _iconId;
1543 }
1544
1545 ResourceName(ApplicationInfo aInfo, int _iconId) {
1546 this(aInfo.packageName, _iconId);
1547 }
1548
1549 ResourceName(ComponentInfo cInfo, int _iconId) {
1550 this(cInfo.applicationInfo.packageName, _iconId);
1551 }
1552
1553 ResourceName(ResolveInfo rInfo, int _iconId) {
1554 this(rInfo.activityInfo.applicationInfo.packageName, _iconId);
1555 }
1556
1557 @Override
1558 public boolean equals(Object o) {
1559 if (this == o) return true;
1560 if (o == null || getClass() != o.getClass()) return false;
1561
1562 ResourceName that = (ResourceName) o;
1563
1564 if (iconId != that.iconId) return false;
1565 return !(packageName != null ?
1566 !packageName.equals(that.packageName) : that.packageName != null);
1567
1568 }
1569
1570 @Override
1571 public int hashCode() {
1572 int result;
1573 result = packageName.hashCode();
1574 result = 31 * result + iconId;
1575 return result;
1576 }
1577
1578 @Override
1579 public String toString() {
1580 return "{ResourceName " + packageName + " / " + iconId + "}";
1581 }
1582 }
1583
1584 private CharSequence getCachedString(ResourceName name) {
1585 synchronized (sSync) {
1586 WeakReference<CharSequence> wr = sStringCache.get(name);
1587 if (wr != null) { // we have the activity
1588 CharSequence cs = wr.get();
1589 if (cs != null) {
1590 return cs;
1591 }
1592 // our entry has been purged
1593 sStringCache.remove(name);
1594 }
1595 }
1596 return null;
1597 }
1598
1599 private void putCachedString(ResourceName name, CharSequence cs) {
1600 synchronized (sSync) {
1601 sStringCache.put(name, new WeakReference<CharSequence>(cs));
1602 }
1603 }
1604
1605 @Override
Tor Norbye7b9c9122013-05-30 16:48:33 -07001606 public CharSequence getText(String packageName, @StringRes int resid,
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001607 ApplicationInfo appInfo) {
1608 ResourceName name = new ResourceName(packageName, resid);
1609 CharSequence text = getCachedString(name);
1610 if (text != null) {
1611 return text;
1612 }
1613 if (appInfo == null) {
1614 try {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001615 appInfo = getApplicationInfo(packageName, sDefaultFlags);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001616 } catch (NameNotFoundException e) {
1617 return null;
1618 }
1619 }
1620 try {
1621 Resources r = getResourcesForApplication(appInfo);
1622 text = r.getText(resid);
1623 putCachedString(name, text);
1624 return text;
1625 } catch (NameNotFoundException e) {
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07001626 Log.w("PackageManager", "Failure retrieving resources for "
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001627 + appInfo.packageName);
1628 } catch (RuntimeException e) {
1629 // If an exception was thrown, fall through to return
1630 // default icon.
1631 Log.w("PackageManager", "Failure retrieving text 0x"
1632 + Integer.toHexString(resid) + " in package "
1633 + packageName, e);
1634 }
1635 return null;
1636 }
1637
1638 @Override
Tor Norbye7b9c9122013-05-30 16:48:33 -07001639 public XmlResourceParser getXml(String packageName, @XmlRes int resid,
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001640 ApplicationInfo appInfo) {
1641 if (appInfo == null) {
1642 try {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001643 appInfo = getApplicationInfo(packageName, sDefaultFlags);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001644 } catch (NameNotFoundException e) {
1645 return null;
1646 }
1647 }
1648 try {
1649 Resources r = getResourcesForApplication(appInfo);
1650 return r.getXml(resid);
1651 } catch (RuntimeException e) {
1652 // If an exception was thrown, fall through to return
1653 // default icon.
1654 Log.w("PackageManager", "Failure retrieving xml 0x"
1655 + Integer.toHexString(resid) + " in package "
1656 + packageName, e);
1657 } catch (NameNotFoundException e) {
Alon Albert3fa51e32010-11-11 09:24:04 -08001658 Log.w("PackageManager", "Failure retrieving resources for "
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001659 + appInfo.packageName);
1660 }
1661 return null;
1662 }
1663
1664 @Override
1665 public CharSequence getApplicationLabel(ApplicationInfo info) {
1666 return info.loadLabel(this);
1667 }
1668
1669 @Override
1670 public void installPackage(Uri packageURI, IPackageInstallObserver observer, int flags,
1671 String installerPackageName) {
Jeff Sharkey513a0742014-07-08 17:10:32 -07001672 installCommon(packageURI, new LegacyPackageInstallObserver(observer), flags,
Todd Kennedya6793232016-02-24 22:46:00 +00001673 installerPackageName, mContext.getUserId());
Christopher Tatef1977b42014-03-24 16:25:51 -07001674 }
1675
Christopher Tatef1977b42014-03-24 16:25:51 -07001676 @Override
1677 public void installPackage(Uri packageURI, PackageInstallObserver observer,
1678 int flags, String installerPackageName) {
Todd Kennedya6793232016-02-24 22:46:00 +00001679 installCommon(packageURI, observer, flags, installerPackageName, mContext.getUserId());
Jeff Sharkey513a0742014-07-08 17:10:32 -07001680 }
1681
1682 private void installCommon(Uri packageURI,
1683 PackageInstallObserver observer, int flags, String installerPackageName,
Nicolas Prevot9a80e532015-09-23 15:49:28 +01001684 int userId) {
Jeff Sharkey513a0742014-07-08 17:10:32 -07001685 if (!"file".equals(packageURI.getScheme())) {
1686 throw new UnsupportedOperationException("Only file:// URIs are supported");
1687 }
Jeff Sharkey513a0742014-07-08 17:10:32 -07001688
1689 final String originPath = packageURI.getPath();
Christopher Tatef1977b42014-03-24 16:25:51 -07001690 try {
Nicolas Prevot9a80e532015-09-23 15:49:28 +01001691 mPM.installPackageAsUser(originPath, observer.getBinder(), flags, installerPackageName,
Todd Kennedya6793232016-02-24 22:46:00 +00001692 userId);
Jeff Sharkey27b2e692016-02-25 17:40:12 -07001693 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001694 throw e.rethrowFromSystemServer();
rich cannings706e8ba2012-08-20 13:20:14 -07001695 }
1696 }
1697
1698 @Override
Nicolas Prevot9a80e532015-09-23 15:49:28 +01001699 public int installExistingPackage(String packageName) throws NameNotFoundException {
Sunny Goyala31a74b2017-05-11 15:59:19 -07001700 return installExistingPackage(packageName, PackageManager.INSTALL_REASON_UNKNOWN);
1701 }
1702
1703 @Override
1704 public int installExistingPackage(String packageName, int installReason)
1705 throws NameNotFoundException {
1706 return installExistingPackageAsUser(packageName, installReason, mContext.getUserId());
Nicolas Prevot9a80e532015-09-23 15:49:28 +01001707 }
1708
1709 @Override
1710 public int installExistingPackageAsUser(String packageName, int userId)
Dianne Hackborn7767eac2012-08-23 18:25:40 -07001711 throws NameNotFoundException {
Sunny Goyala31a74b2017-05-11 15:59:19 -07001712 return installExistingPackageAsUser(packageName, PackageManager.INSTALL_REASON_UNKNOWN,
1713 userId);
1714 }
1715
1716 private int installExistingPackageAsUser(String packageName, int installReason, int userId)
1717 throws NameNotFoundException {
Dianne Hackborn7767eac2012-08-23 18:25:40 -07001718 try {
Todd Kennedybe0b8892017-02-15 14:13:52 -08001719 int res = mPM.installExistingPackageAsUser(packageName, userId, 0 /*installFlags*/,
Sunny Goyala31a74b2017-05-11 15:59:19 -07001720 installReason);
Dianne Hackborn7767eac2012-08-23 18:25:40 -07001721 if (res == INSTALL_FAILED_INVALID_URI) {
1722 throw new NameNotFoundException("Package " + packageName + " doesn't exist");
1723 }
1724 return res;
1725 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001726 throw e.rethrowFromSystemServer();
Dianne Hackborn7767eac2012-08-23 18:25:40 -07001727 }
1728 }
1729
1730 @Override
Kenny Root3a9b5fb2011-09-20 14:15:38 -07001731 public void verifyPendingInstall(int id, int response) {
Kenny Root5ab21572011-07-27 11:11:19 -07001732 try {
Kenny Root3a9b5fb2011-09-20 14:15:38 -07001733 mPM.verifyPendingInstall(id, response);
Kenny Root5ab21572011-07-27 11:11:19 -07001734 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001735 throw e.rethrowFromSystemServer();
Kenny Root5ab21572011-07-27 11:11:19 -07001736 }
1737 }
1738
1739 @Override
rich canningsd9ef3e52012-08-22 14:28:05 -07001740 public void extendVerificationTimeout(int id, int verificationCodeAtTimeout,
1741 long millisecondsToDelay) {
1742 try {
1743 mPM.extendVerificationTimeout(id, verificationCodeAtTimeout, millisecondsToDelay);
1744 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001745 throw e.rethrowFromSystemServer();
rich canningsd9ef3e52012-08-22 14:28:05 -07001746 }
1747 }
1748
1749 @Override
Todd Kennedydfa93ab2016-03-03 15:24:33 -08001750 public void verifyIntentFilter(int id, int verificationCode, List<String> failedDomains) {
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001751 try {
Todd Kennedydfa93ab2016-03-03 15:24:33 -08001752 mPM.verifyIntentFilter(id, verificationCode, failedDomains);
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001753 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001754 throw e.rethrowFromSystemServer();
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001755 }
1756 }
1757
1758 @Override
Jeff Sharkeye06b4d12016-01-06 14:51:50 -07001759 public int getIntentVerificationStatusAsUser(String packageName, int userId) {
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001760 try {
1761 return mPM.getIntentVerificationStatus(packageName, userId);
1762 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001763 throw e.rethrowFromSystemServer();
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001764 }
1765 }
1766
1767 @Override
Jeff Sharkeye06b4d12016-01-06 14:51:50 -07001768 public boolean updateIntentVerificationStatusAsUser(String packageName, int status, int userId) {
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001769 try {
1770 return mPM.updateIntentVerificationStatus(packageName, status, userId);
1771 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001772 throw e.rethrowFromSystemServer();
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001773 }
1774 }
1775
1776 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001777 @SuppressWarnings("unchecked")
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001778 public List<IntentFilterVerificationInfo> getIntentFilterVerifications(String packageName) {
1779 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001780 ParceledListSlice<IntentFilterVerificationInfo> parceledList =
1781 mPM.getIntentFilterVerifications(packageName);
1782 if (parceledList == null) {
1783 return Collections.emptyList();
1784 }
1785 return parceledList.getList();
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001786 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001787 throw e.rethrowFromSystemServer();
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001788 }
1789 }
1790
1791 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001792 @SuppressWarnings("unchecked")
Fabrice Di Meglio07885952015-04-06 19:41:28 -07001793 public List<IntentFilter> getAllIntentFilters(String packageName) {
1794 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001795 ParceledListSlice<IntentFilter> parceledList =
1796 mPM.getAllIntentFilters(packageName);
1797 if (parceledList == null) {
1798 return Collections.emptyList();
1799 }
1800 return parceledList.getList();
Fabrice Di Meglio07885952015-04-06 19:41:28 -07001801 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001802 throw e.rethrowFromSystemServer();
Fabrice Di Meglio07885952015-04-06 19:41:28 -07001803 }
1804 }
1805
1806 @Override
Jeff Sharkeye06b4d12016-01-06 14:51:50 -07001807 public String getDefaultBrowserPackageNameAsUser(int userId) {
Fabrice Di Meglio62271722015-04-10 17:24:02 -07001808 try {
1809 return mPM.getDefaultBrowserPackageName(userId);
1810 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001811 throw e.rethrowFromSystemServer();
Fabrice Di Meglio62271722015-04-10 17:24:02 -07001812 }
1813 }
1814
1815 @Override
Jeff Sharkeye06b4d12016-01-06 14:51:50 -07001816 public boolean setDefaultBrowserPackageNameAsUser(String packageName, int userId) {
Fabrice Di Meglio62271722015-04-10 17:24:02 -07001817 try {
1818 return mPM.setDefaultBrowserPackageName(packageName, userId);
1819 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001820 throw e.rethrowFromSystemServer();
Fabrice Di Meglio62271722015-04-10 17:24:02 -07001821 }
1822 }
1823
1824 @Override
Dianne Hackborn880119b2010-11-18 22:26:40 -08001825 public void setInstallerPackageName(String targetPackage,
1826 String installerPackageName) {
1827 try {
1828 mPM.setInstallerPackageName(targetPackage, installerPackageName);
1829 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001830 throw e.rethrowFromSystemServer();
Dianne Hackborn880119b2010-11-18 22:26:40 -08001831 }
1832 }
1833
1834 @Override
Todd Kennedyab532892017-03-08 14:19:49 -08001835 public void setUpdateAvailable(String packageName, boolean updateAvailable) {
1836 try {
1837 mPM.setUpdateAvailable(packageName, updateAvailable);
1838 } catch (RemoteException e) {
1839 throw e.rethrowFromSystemServer();
1840 }
1841 }
1842
1843 @Override
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001844 public String getInstallerPackageName(String packageName) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001845 try {
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001846 return mPM.getInstallerPackageName(packageName);
1847 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001848 throw e.rethrowFromSystemServer();
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001849 }
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001850 }
1851
1852 @Override
1853 public int getMoveStatus(int moveId) {
1854 try {
1855 return mPM.getMoveStatus(moveId);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001856 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001857 throw e.rethrowFromSystemServer();
Jeff Sharkeyb2b9ab82015-04-05 21:10:42 -07001858 }
1859 }
1860
1861 @Override
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001862 public void registerMoveCallback(MoveCallback callback, Handler handler) {
1863 synchronized (mDelegates) {
1864 final MoveCallbackDelegate delegate = new MoveCallbackDelegate(callback,
1865 handler.getLooper());
1866 try {
1867 mPM.registerMoveCallback(delegate);
1868 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001869 throw e.rethrowFromSystemServer();
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001870 }
1871 mDelegates.add(delegate);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001872 }
1873 }
1874
1875 @Override
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001876 public void unregisterMoveCallback(MoveCallback callback) {
1877 synchronized (mDelegates) {
1878 for (Iterator<MoveCallbackDelegate> i = mDelegates.iterator(); i.hasNext();) {
1879 final MoveCallbackDelegate delegate = i.next();
1880 if (delegate.mCallback == callback) {
1881 try {
1882 mPM.unregisterMoveCallback(delegate);
1883 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001884 throw e.rethrowFromSystemServer();
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001885 }
1886 i.remove();
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001887 }
1888 }
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001889 }
1890 }
1891
1892 @Override
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001893 public int movePackage(String packageName, VolumeInfo vol) {
1894 try {
1895 final String volumeUuid;
1896 if (VolumeInfo.ID_PRIVATE_INTERNAL.equals(vol.id)) {
1897 volumeUuid = StorageManager.UUID_PRIVATE_INTERNAL;
1898 } else if (vol.isPrimaryPhysical()) {
1899 volumeUuid = StorageManager.UUID_PRIMARY_PHYSICAL;
1900 } else {
1901 volumeUuid = Preconditions.checkNotNull(vol.fsUuid);
1902 }
1903
1904 return mPM.movePackage(packageName, volumeUuid);
1905 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001906 throw e.rethrowFromSystemServer();
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001907 }
1908 }
1909
1910 @Override
1911 public @Nullable VolumeInfo getPackageCurrentVolume(ApplicationInfo app) {
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001912 final StorageManager storage = mContext.getSystemService(StorageManager.class);
Yao Chen022b8ea2016-12-16 11:03:28 -08001913 return getPackageCurrentVolume(app, storage);
1914 }
1915
1916 @VisibleForTesting
1917 protected @Nullable VolumeInfo getPackageCurrentVolume(ApplicationInfo app,
1918 StorageManager storage) {
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001919 if (app.isInternal()) {
1920 return storage.findVolumeById(VolumeInfo.ID_PRIVATE_INTERNAL);
1921 } else if (app.isExternalAsec()) {
1922 return storage.getPrimaryPhysicalVolume();
1923 } else {
1924 return storage.findVolumeByUuid(app.volumeUuid);
1925 }
1926 }
1927
1928 @Override
1929 public @NonNull List<VolumeInfo> getPackageCandidateVolumes(ApplicationInfo app) {
Yao Chen022b8ea2016-12-16 11:03:28 -08001930 final StorageManager storageManager = mContext.getSystemService(StorageManager.class);
1931 return getPackageCandidateVolumes(app, storageManager, mPM);
1932 }
1933
1934 @VisibleForTesting
1935 protected @NonNull List<VolumeInfo> getPackageCandidateVolumes(ApplicationInfo app,
1936 StorageManager storageManager, IPackageManager pm) {
1937 final VolumeInfo currentVol = getPackageCurrentVolume(app, storageManager);
1938 final List<VolumeInfo> vols = storageManager.getVolumes();
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001939 final List<VolumeInfo> candidates = new ArrayList<>();
1940 for (VolumeInfo vol : vols) {
Yao Chen022b8ea2016-12-16 11:03:28 -08001941 if (Objects.equals(vol, currentVol)
1942 || isPackageCandidateVolume(mContext, app, vol, pm)) {
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001943 candidates.add(vol);
1944 }
1945 }
1946 return candidates;
1947 }
1948
Yao Chen022b8ea2016-12-16 11:03:28 -08001949 @VisibleForTesting
1950 protected boolean isForceAllowOnExternal(Context context) {
1951 return Settings.Global.getInt(
Todd Kennedyf39ca8f2015-08-07 14:15:07 -07001952 context.getContentResolver(), Settings.Global.FORCE_ALLOW_ON_EXTERNAL, 0) != 0;
Yao Chen022b8ea2016-12-16 11:03:28 -08001953 }
1954
1955 @VisibleForTesting
1956 protected boolean isAllow3rdPartyOnInternal(Context context) {
1957 return context.getResources().getBoolean(
1958 com.android.internal.R.bool.config_allow3rdPartyAppOnInternal);
1959 }
1960
1961 private boolean isPackageCandidateVolume(
1962 ContextImpl context, ApplicationInfo app, VolumeInfo vol, IPackageManager pm) {
1963 final boolean forceAllowOnExternal = isForceAllowOnExternal(context);
1964
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001965 if (VolumeInfo.ID_PRIVATE_INTERNAL.equals(vol.getId())) {
Yao Chen022b8ea2016-12-16 11:03:28 -08001966 return app.isSystemApp() || isAllow3rdPartyOnInternal(context);
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001967 }
1968
1969 // System apps and apps demanding internal storage can't be moved
1970 // anywhere else
Todd Kennedyf39ca8f2015-08-07 14:15:07 -07001971 if (app.isSystemApp()) {
1972 return false;
1973 }
1974 if (!forceAllowOnExternal
Dianne Hackborn30a4e6d2015-10-12 17:14:56 -07001975 && (app.installLocation == PackageInfo.INSTALL_LOCATION_INTERNAL_ONLY
1976 || app.installLocation == PackageInfo.INSTALL_LOCATION_UNSPECIFIED)) {
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001977 return false;
1978 }
1979
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001980 // Gotta be able to write there
1981 if (!vol.isMountedWritable()) {
1982 return false;
1983 }
1984
1985 // Moving into an ASEC on public primary is only option internal
1986 if (vol.isPrimaryPhysical()) {
1987 return app.isInternal();
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001988 }
1989
Makoto Onukif34db0a2016-02-17 11:17:15 -08001990 // Some apps can't be moved. (e.g. device admins)
1991 try {
Yao Chen022b8ea2016-12-16 11:03:28 -08001992 if (pm.isPackageDeviceAdminOnAnyUser(app.packageName)) {
Makoto Onukif34db0a2016-02-17 11:17:15 -08001993 return false;
1994 }
1995 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001996 throw e.rethrowFromSystemServer();
Makoto Onukif34db0a2016-02-17 11:17:15 -08001997 }
1998
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001999 // Otherwise we can move to any private volume
2000 return (vol.getType() == VolumeInfo.TYPE_PRIVATE);
2001 }
2002
2003 @Override
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002004 public int movePrimaryStorage(VolumeInfo vol) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002005 try {
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002006 final String volumeUuid;
2007 if (VolumeInfo.ID_PRIVATE_INTERNAL.equals(vol.id)) {
2008 volumeUuid = StorageManager.UUID_PRIVATE_INTERNAL;
2009 } else if (vol.isPrimaryPhysical()) {
2010 volumeUuid = StorageManager.UUID_PRIMARY_PHYSICAL;
2011 } else {
2012 volumeUuid = Preconditions.checkNotNull(vol.fsUuid);
2013 }
2014
2015 return mPM.movePrimaryStorage(volumeUuid);
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 }
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002019 }
2020
Jeff Sharkey275e3e42015-04-24 16:10:32 -07002021 @Override
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002022 public @Nullable VolumeInfo getPrimaryStorageCurrentVolume() {
2023 final StorageManager storage = mContext.getSystemService(StorageManager.class);
2024 final String volumeUuid = storage.getPrimaryStorageUuid();
Jeff Sharkey50a05452015-04-29 11:24:52 -07002025 return storage.findVolumeByQualifiedUuid(volumeUuid);
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002026 }
2027
Jeff Sharkey275e3e42015-04-24 16:10:32 -07002028 @Override
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002029 public @NonNull List<VolumeInfo> getPrimaryStorageCandidateVolumes() {
2030 final StorageManager storage = mContext.getSystemService(StorageManager.class);
2031 final VolumeInfo currentVol = getPrimaryStorageCurrentVolume();
2032 final List<VolumeInfo> vols = storage.getVolumes();
2033 final List<VolumeInfo> candidates = new ArrayList<>();
Jeff Sharkeyfced5342015-05-10 14:53:34 -07002034 if (Objects.equals(StorageManager.UUID_PRIMARY_PHYSICAL,
2035 storage.getPrimaryStorageUuid()) && currentVol != null) {
2036 // TODO: support moving primary physical to emulated volume
2037 candidates.add(currentVol);
2038 } else {
2039 for (VolumeInfo vol : vols) {
2040 if (Objects.equals(vol, currentVol) || isPrimaryStorageCandidateVolume(vol)) {
2041 candidates.add(vol);
2042 }
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002043 }
2044 }
2045 return candidates;
2046 }
2047
2048 private static boolean isPrimaryStorageCandidateVolume(VolumeInfo vol) {
2049 // Private internal is always an option
2050 if (VolumeInfo.ID_PRIVATE_INTERNAL.equals(vol.getId())) {
2051 return true;
2052 }
2053
2054 // Gotta be able to write there
2055 if (!vol.isMountedWritable()) {
2056 return false;
2057 }
2058
Jeff Sharkeyfced5342015-05-10 14:53:34 -07002059 // We can move to any private volume
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002060 return (vol.getType() == VolumeInfo.TYPE_PRIVATE);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002061 }
2062
2063 @Override
2064 public void deletePackage(String packageName, IPackageDeleteObserver observer, int flags) {
Robin Lee0e27c872015-09-28 14:37:40 +01002065 deletePackageAsUser(packageName, observer, flags, mContext.getUserId());
Nicolas Prevot9a80e532015-09-23 15:49:28 +01002066 }
2067
2068 @Override
Svet Ganov67882122016-12-11 16:36:34 -08002069 public void deletePackageAsUser(String packageName, IPackageDeleteObserver observer,
2070 int flags, int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002071 try {
Svet Ganov67882122016-12-11 16:36:34 -08002072 mPM.deletePackageAsUser(packageName, PackageManager.VERSION_CODE_HIGHEST,
2073 observer, userId, flags);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002074 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002075 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002076 }
2077 }
Jeff Sharkeyfbd0e9f2014-08-06 16:34:34 -07002078
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002079 @Override
2080 public void clearApplicationUserData(String packageName,
2081 IPackageDataObserver observer) {
2082 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -07002083 mPM.clearApplicationUserData(packageName, observer, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002084 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002085 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002086 }
2087 }
2088 @Override
2089 public void deleteApplicationCacheFiles(String packageName,
2090 IPackageDataObserver observer) {
2091 try {
2092 mPM.deleteApplicationCacheFiles(packageName, observer);
2093 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002094 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002095 }
2096 }
Jeff Sharkey529f91f2015-04-18 20:23:13 -07002097
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002098 @Override
Suprabh Shukla78c9eb82016-04-12 15:51:35 -07002099 public void deleteApplicationCacheFilesAsUser(String packageName, int userId,
2100 IPackageDataObserver observer) {
2101 try {
2102 mPM.deleteApplicationCacheFilesAsUser(packageName, userId, observer);
2103 } catch (RemoteException e) {
2104 throw e.rethrowFromSystemServer();
2105 }
2106 }
2107
2108 @Override
Jeff Sharkey529f91f2015-04-18 20:23:13 -07002109 public void freeStorageAndNotify(String volumeUuid, long idealStorageSize,
2110 IPackageDataObserver observer) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002111 try {
Jeff Sharkeyddff8072017-05-26 13:10:46 -06002112 mPM.freeStorageAndNotify(volumeUuid, idealStorageSize, 0, observer);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002113 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002114 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002115 }
2116 }
2117
2118 @Override
Jeff Sharkey529f91f2015-04-18 20:23:13 -07002119 public void freeStorage(String volumeUuid, long freeStorageSize, IntentSender pi) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002120 try {
Jeff Sharkeyddff8072017-05-26 13:10:46 -06002121 mPM.freeStorage(volumeUuid, freeStorageSize, 0, pi);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002122 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002123 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002124 }
2125 }
2126
2127 @Override
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00002128 public String[] setPackagesSuspendedAsUser(String[] packageNames, boolean suspended,
2129 int userId) {
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00002130 try {
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00002131 return mPM.setPackagesSuspendedAsUser(packageNames, suspended, userId);
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00002132 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002133 throw e.rethrowFromSystemServer();
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00002134 }
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00002135 }
2136
2137 @Override
Andrei Stingaceanu355b2322016-02-12 16:43:51 +00002138 public boolean isPackageSuspendedForUser(String packageName, int userId) {
2139 try {
2140 return mPM.isPackageSuspendedForUser(packageName, userId);
2141 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002142 throw e.rethrowFromSystemServer();
Andrei Stingaceanu355b2322016-02-12 16:43:51 +00002143 }
Andrei Stingaceanu355b2322016-02-12 16:43:51 +00002144 }
2145
Jeff Sharkey9bc89af2017-01-11 11:25:50 -07002146 /** @hide */
2147 @Override
2148 public void setApplicationCategoryHint(String packageName, int categoryHint) {
2149 try {
2150 mPM.setApplicationCategoryHint(packageName, categoryHint,
2151 mContext.getOpPackageName());
2152 } catch (RemoteException e) {
2153 throw e.rethrowFromSystemServer();
2154 }
2155 }
2156
Andrei Stingaceanu355b2322016-02-12 16:43:51 +00002157 @Override
Jeff Sharkeye06b4d12016-01-06 14:51:50 -07002158 public void getPackageSizeInfoAsUser(String packageName, int userHandle,
Dianne Hackborn0c380492012-08-20 17:23:30 -07002159 IPackageStatsObserver observer) {
Jeff Sharkey6f4b2a32017-03-21 14:13:41 -06002160 final String msg = "Shame on you for calling the hidden API "
2161 + "getPackageSizeInfoAsUser(). Shame!";
Jeff Sharkeye6306c42017-03-07 21:03:18 -07002162 if (mContext.getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.O) {
Jeff Sharkey6f4b2a32017-03-21 14:13:41 -06002163 throw new UnsupportedOperationException(msg);
Jeff Sharkeye6306c42017-03-07 21:03:18 -07002164 } else if (observer != null) {
Jeff Sharkey6f4b2a32017-03-21 14:13:41 -06002165 Log.d(TAG, msg);
Jeff Sharkeye6306c42017-03-07 21:03:18 -07002166 try {
2167 observer.onGetStatsCompleted(null, false);
2168 } catch (RemoteException ignored) {
2169 }
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002170 }
2171 }
Jeff Sharkeyd5896632016-03-04 16:16:00 -07002172
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002173 @Override
2174 public void addPackageToPreferred(String packageName) {
Jeff Sharkeyd5896632016-03-04 16:16:00 -07002175 Log.w(TAG, "addPackageToPreferred() is a no-op");
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002176 }
2177
2178 @Override
2179 public void removePackageFromPreferred(String packageName) {
Jeff Sharkeyd5896632016-03-04 16:16:00 -07002180 Log.w(TAG, "removePackageFromPreferred() is a no-op");
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002181 }
2182
2183 @Override
2184 public List<PackageInfo> getPreferredPackages(int flags) {
Jeff Sharkeyd5896632016-03-04 16:16:00 -07002185 Log.w(TAG, "getPreferredPackages() is a no-op");
2186 return Collections.emptyList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002187 }
2188
2189 @Override
2190 public void addPreferredActivity(IntentFilter filter,
2191 int match, ComponentName[] set, ComponentName activity) {
2192 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -07002193 mPM.addPreferredActivity(filter, match, set, activity, mContext.getUserId());
Amith Yamasania3f133a2012-08-09 17:11:28 -07002194 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002195 throw e.rethrowFromSystemServer();
Amith Yamasania3f133a2012-08-09 17:11:28 -07002196 }
2197 }
2198
2199 @Override
Jeff Sharkeye06b4d12016-01-06 14:51:50 -07002200 public void addPreferredActivityAsUser(IntentFilter filter, int match,
Amith Yamasania3f133a2012-08-09 17:11:28 -07002201 ComponentName[] set, ComponentName activity, int userId) {
2202 try {
2203 mPM.addPreferredActivity(filter, match, set, activity, userId);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002204 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002205 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002206 }
2207 }
2208
2209 @Override
2210 public void replacePreferredActivity(IntentFilter filter,
2211 int match, ComponentName[] set, ComponentName activity) {
2212 try {
Robin Lee0e27c872015-09-28 14:37:40 +01002213 mPM.replacePreferredActivity(filter, match, set, activity, mContext.getUserId());
Amith Yamasani41c1ded2014-08-05 11:15:05 -07002214 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002215 throw e.rethrowFromSystemServer();
Amith Yamasani41c1ded2014-08-05 11:15:05 -07002216 }
2217 }
2218
2219 @Override
2220 public void replacePreferredActivityAsUser(IntentFilter filter,
2221 int match, ComponentName[] set, ComponentName activity,
2222 int userId) {
2223 try {
2224 mPM.replacePreferredActivity(filter, match, set, activity, userId);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002225 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002226 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002227 }
2228 }
2229
2230 @Override
2231 public void clearPackagePreferredActivities(String packageName) {
2232 try {
2233 mPM.clearPackagePreferredActivities(packageName);
2234 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002235 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002236 }
2237 }
2238
2239 @Override
2240 public int getPreferredActivities(List<IntentFilter> outFilters,
2241 List<ComponentName> outActivities, String packageName) {
2242 try {
2243 return mPM.getPreferredActivities(outFilters, outActivities, packageName);
2244 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002245 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002246 }
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002247 }
2248
2249 @Override
Christopher Tatea2a0850d2013-09-05 16:38:58 -07002250 public ComponentName getHomeActivities(List<ResolveInfo> outActivities) {
2251 try {
2252 return mPM.getHomeActivities(outActivities);
2253 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002254 throw e.rethrowFromSystemServer();
Christopher Tatea2a0850d2013-09-05 16:38:58 -07002255 }
Christopher Tatea2a0850d2013-09-05 16:38:58 -07002256 }
2257
2258 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002259 public void setComponentEnabledSetting(ComponentName componentName,
2260 int newState, int flags) {
2261 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -07002262 mPM.setComponentEnabledSetting(componentName, newState, flags, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002263 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002264 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002265 }
2266 }
2267
2268 @Override
2269 public int getComponentEnabledSetting(ComponentName componentName) {
2270 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -07002271 return mPM.getComponentEnabledSetting(componentName, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002272 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002273 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002274 }
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002275 }
2276
2277 @Override
2278 public void setApplicationEnabledSetting(String packageName,
2279 int newState, int flags) {
2280 try {
Dianne Hackborn3fa3c28a2013-03-26 16:15:41 -07002281 mPM.setApplicationEnabledSetting(packageName, newState, flags,
Dianne Hackborn95d78532013-09-11 09:51:14 -07002282 mContext.getUserId(), mContext.getOpPackageName());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002283 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002284 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002285 }
2286 }
2287
2288 @Override
2289 public int getApplicationEnabledSetting(String packageName) {
2290 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -07002291 return mPM.getApplicationEnabledSetting(packageName, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002292 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002293 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002294 }
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002295 }
2296
Amith Yamasani655d0e22013-06-12 14:19:10 -07002297 @Override
Sudheer Shankabbb3ff22015-07-09 15:39:23 +01002298 public void flushPackageRestrictionsAsUser(int userId) {
2299 try {
2300 mPM.flushPackageRestrictionsAsUser(userId);
2301 } catch (RemoteException e) {
2302 throw e.rethrowFromSystemServer();
2303 }
2304 }
2305
2306 @Override
Amith Yamasanie5bcff62014-07-19 15:44:09 -07002307 public boolean setApplicationHiddenSettingAsUser(String packageName, boolean hidden,
Amith Yamasani655d0e22013-06-12 14:19:10 -07002308 UserHandle user) {
2309 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07002310 return mPM.setApplicationHiddenSettingAsUser(packageName, hidden,
Amith Yamasani655d0e22013-06-12 14:19:10 -07002311 user.getIdentifier());
Jeff Sharkey27b2e692016-02-25 17:40:12 -07002312 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002313 throw e.rethrowFromSystemServer();
Amith Yamasani655d0e22013-06-12 14:19:10 -07002314 }
Amith Yamasani655d0e22013-06-12 14:19:10 -07002315 }
2316
2317 @Override
Amith Yamasanie5bcff62014-07-19 15:44:09 -07002318 public boolean getApplicationHiddenSettingAsUser(String packageName, UserHandle user) {
Amith Yamasani655d0e22013-06-12 14:19:10 -07002319 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07002320 return mPM.getApplicationHiddenSettingAsUser(packageName, user.getIdentifier());
Jeff Sharkey27b2e692016-02-25 17:40:12 -07002321 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002322 throw e.rethrowFromSystemServer();
Amith Yamasani655d0e22013-06-12 14:19:10 -07002323 }
Amith Yamasani655d0e22013-06-12 14:19:10 -07002324 }
2325
dcashmanc6f22492014-08-14 09:54:51 -07002326 /** @hide */
dcashman9d2f4412014-06-09 09:27:54 -07002327 @Override
2328 public KeySet getKeySetByAlias(String packageName, String alias) {
2329 Preconditions.checkNotNull(packageName);
2330 Preconditions.checkNotNull(alias);
dcashman9d2f4412014-06-09 09:27:54 -07002331 try {
Jeff Sharkey27b2e692016-02-25 17:40:12 -07002332 return mPM.getKeySetByAlias(packageName, alias);
dcashman9d2f4412014-06-09 09:27:54 -07002333 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002334 throw e.rethrowFromSystemServer();
dcashman9d2f4412014-06-09 09:27:54 -07002335 }
dcashman9d2f4412014-06-09 09:27:54 -07002336 }
2337
dcashmanc6f22492014-08-14 09:54:51 -07002338 /** @hide */
dcashman9d2f4412014-06-09 09:27:54 -07002339 @Override
2340 public KeySet getSigningKeySet(String packageName) {
2341 Preconditions.checkNotNull(packageName);
dcashman9d2f4412014-06-09 09:27:54 -07002342 try {
Jeff Sharkey27b2e692016-02-25 17:40:12 -07002343 return mPM.getSigningKeySet(packageName);
dcashman9d2f4412014-06-09 09:27:54 -07002344 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002345 throw e.rethrowFromSystemServer();
dcashman9d2f4412014-06-09 09:27:54 -07002346 }
dcashman9d2f4412014-06-09 09:27:54 -07002347 }
2348
dcashmanc6f22492014-08-14 09:54:51 -07002349 /** @hide */
dcashman9d2f4412014-06-09 09:27:54 -07002350 @Override
2351 public boolean isSignedBy(String packageName, KeySet ks) {
2352 Preconditions.checkNotNull(packageName);
2353 Preconditions.checkNotNull(ks);
dcashman9d2f4412014-06-09 09:27:54 -07002354 try {
dcashmanc6f22492014-08-14 09:54:51 -07002355 return mPM.isPackageSignedByKeySet(packageName, ks);
dcashman9d2f4412014-06-09 09:27:54 -07002356 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002357 throw e.rethrowFromSystemServer();
dcashman9d2f4412014-06-09 09:27:54 -07002358 }
2359 }
2360
dcashmanc6f22492014-08-14 09:54:51 -07002361 /** @hide */
dcashman9d2f4412014-06-09 09:27:54 -07002362 @Override
2363 public boolean isSignedByExactly(String packageName, KeySet ks) {
2364 Preconditions.checkNotNull(packageName);
2365 Preconditions.checkNotNull(ks);
dcashman9d2f4412014-06-09 09:27:54 -07002366 try {
dcashmanc6f22492014-08-14 09:54:51 -07002367 return mPM.isPackageSignedByKeySetExactly(packageName, ks);
dcashman9d2f4412014-06-09 09:27:54 -07002368 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002369 throw e.rethrowFromSystemServer();
dcashman9d2f4412014-06-09 09:27:54 -07002370 }
2371 }
2372
Kenny Root0aaa0d92011-09-12 16:42:55 -07002373 /**
2374 * @hide
2375 */
2376 @Override
2377 public VerifierDeviceIdentity getVerifierDeviceIdentity() {
2378 try {
2379 return mPM.getVerifierDeviceIdentity();
2380 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002381 throw e.rethrowFromSystemServer();
Kenny Root0aaa0d92011-09-12 16:42:55 -07002382 }
Kenny Root0aaa0d92011-09-12 16:42:55 -07002383 }
2384
Jeff Hao9f60c082014-10-28 18:51:07 -07002385 /**
2386 * @hide
2387 */
2388 @Override
2389 public boolean isUpgrade() {
2390 try {
2391 return mPM.isUpgrade();
2392 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002393 throw e.rethrowFromSystemServer();
Jeff Hao9f60c082014-10-28 18:51:07 -07002394 }
2395 }
2396
Jeff Sharkey3a44f3f2014-04-28 17:36:31 -07002397 @Override
Jeff Sharkey16c8e3f2014-07-24 17:08:17 -07002398 public PackageInstaller getPackageInstaller() {
2399 synchronized (mLock) {
2400 if (mInstaller == null) {
2401 try {
Svet Ganov67882122016-12-11 16:36:34 -08002402 mInstaller = new PackageInstaller(mPM.getPackageInstaller(),
Jeff Sharkey16c8e3f2014-07-24 17:08:17 -07002403 mContext.getPackageName(), mContext.getUserId());
2404 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002405 throw e.rethrowFromSystemServer();
Jeff Sharkey16c8e3f2014-07-24 17:08:17 -07002406 }
2407 }
2408 return mInstaller;
Jeff Sharkey3a44f3f2014-04-28 17:36:31 -07002409 }
2410 }
2411
Jeff Sharkey6c833e02014-07-14 22:44:30 -07002412 @Override
2413 public boolean isPackageAvailable(String packageName) {
2414 try {
2415 return mPM.isPackageAvailable(packageName, mContext.getUserId());
2416 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002417 throw e.rethrowFromSystemServer();
Jeff Sharkey6c833e02014-07-14 22:44:30 -07002418 }
2419 }
2420
Nicolas Prevotc79586e2014-05-06 12:47:57 +01002421 /**
2422 * @hide
2423 */
2424 @Override
Nicolas Prevot63798c52014-05-27 13:22:38 +01002425 public void addCrossProfileIntentFilter(IntentFilter filter, int sourceUserId, int targetUserId,
2426 int flags) {
Nicolas Prevotc79586e2014-05-06 12:47:57 +01002427 try {
Nicolas Prevot3f7777f2014-07-24 15:58:39 +01002428 mPM.addCrossProfileIntentFilter(filter, mContext.getOpPackageName(),
Nicolas Prevot4b8d5822015-03-05 15:20:49 +00002429 sourceUserId, targetUserId, flags);
Nicolas Prevotc79586e2014-05-06 12:47:57 +01002430 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002431 throw e.rethrowFromSystemServer();
Nicolas Prevotc79586e2014-05-06 12:47:57 +01002432 }
2433 }
2434
2435 /**
2436 * @hide
2437 */
2438 @Override
Nicolas Prevot81948992014-05-16 18:25:26 +01002439 public void clearCrossProfileIntentFilters(int sourceUserId) {
Nicolas Prevotc79586e2014-05-06 12:47:57 +01002440 try {
Nicolas Prevot4b8d5822015-03-05 15:20:49 +00002441 mPM.clearCrossProfileIntentFilters(sourceUserId, mContext.getOpPackageName());
Nicolas Prevotc79586e2014-05-06 12:47:57 +01002442 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002443 throw e.rethrowFromSystemServer();
Nicolas Prevotc79586e2014-05-06 12:47:57 +01002444 }
2445 }
2446
Nicolas Prevot88cc3462014-05-14 14:51:48 +01002447 /**
2448 * @hide
2449 */
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +01002450 public Drawable loadItemIcon(PackageItemInfo itemInfo, ApplicationInfo appInfo) {
Benjamin Franzec2d48b2014-10-01 15:38:43 +01002451 Drawable dr = loadUnbadgedItemIcon(itemInfo, appInfo);
2452 if (itemInfo.showUserIcon != UserHandle.USER_NULL) {
2453 return dr;
2454 }
2455 return getUserBadgedIcon(dr, new UserHandle(mContext.getUserId()));
2456 }
2457
2458 /**
2459 * @hide
2460 */
2461 public Drawable loadUnbadgedItemIcon(PackageItemInfo itemInfo, ApplicationInfo appInfo) {
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +01002462 if (itemInfo.showUserIcon != UserHandle.USER_NULL) {
Alexandra Gherghina64d4dca2014-08-28 18:26:56 +01002463 Bitmap bitmap = getUserManager().getUserIcon(itemInfo.showUserIcon);
2464 if (bitmap == null) {
2465 return UserIcons.getDefaultUserIcon(itemInfo.showUserIcon, /* light= */ false);
2466 }
2467 return new BitmapDrawable(bitmap);
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +01002468 }
Alexandra Gherghinadb811db2014-08-29 13:43:59 +01002469 Drawable dr = null;
2470 if (itemInfo.packageName != null) {
2471 dr = getDrawable(itemInfo.packageName, itemInfo.icon, appInfo);
2472 }
Alexandra Gherghinaa71e3902014-07-25 20:03:47 +01002473 if (dr == null) {
Alexandra Gherghinaa7093142014-07-30 13:43:39 +01002474 dr = itemInfo.loadDefaultIcon(this);
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +01002475 }
Benjamin Franzec2d48b2014-10-01 15:38:43 +01002476 return dr;
Svetoslavc7d62f02014-09-04 15:39:54 -07002477 }
2478
2479 private Drawable getBadgedDrawable(Drawable drawable, Drawable badgeDrawable,
2480 Rect badgeLocation, boolean tryBadgeInPlace) {
2481 final int badgedWidth = drawable.getIntrinsicWidth();
2482 final int badgedHeight = drawable.getIntrinsicHeight();
2483 final boolean canBadgeInPlace = tryBadgeInPlace
2484 && (drawable instanceof BitmapDrawable)
2485 && ((BitmapDrawable) drawable).getBitmap().isMutable();
2486
2487 final Bitmap bitmap;
2488 if (canBadgeInPlace) {
2489 bitmap = ((BitmapDrawable) drawable).getBitmap();
2490 } else {
2491 bitmap = Bitmap.createBitmap(badgedWidth, badgedHeight, Bitmap.Config.ARGB_8888);
2492 }
2493 Canvas canvas = new Canvas(bitmap);
2494
2495 if (!canBadgeInPlace) {
2496 drawable.setBounds(0, 0, badgedWidth, badgedHeight);
2497 drawable.draw(canvas);
2498 }
2499
2500 if (badgeLocation != null) {
2501 if (badgeLocation.left < 0 || badgeLocation.top < 0
2502 || badgeLocation.width() > badgedWidth || badgeLocation.height() > badgedHeight) {
2503 throw new IllegalArgumentException("Badge location " + badgeLocation
2504 + " not in badged drawable bounds "
2505 + new Rect(0, 0, badgedWidth, badgedHeight));
2506 }
2507 badgeDrawable.setBounds(0, 0, badgeLocation.width(), badgeLocation.height());
2508
2509 canvas.save();
2510 canvas.translate(badgeLocation.left, badgeLocation.top);
2511 badgeDrawable.draw(canvas);
2512 canvas.restore();
2513 } else {
2514 badgeDrawable.setBounds(0, 0, badgedWidth, badgedHeight);
2515 badgeDrawable.draw(canvas);
2516 }
2517
2518 if (!canBadgeInPlace) {
2519 BitmapDrawable mergedDrawable = new BitmapDrawable(mContext.getResources(), bitmap);
2520
2521 if (drawable instanceof BitmapDrawable) {
2522 BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
2523 mergedDrawable.setTargetDensity(bitmapDrawable.getBitmap().getDensity());
2524 }
2525
2526 return mergedDrawable;
2527 }
2528
2529 return drawable;
2530 }
2531
Tony Mak8673b282016-03-21 21:10:59 +00002532 private boolean isManagedProfile(int userId) {
2533 return getUserManager().isManagedProfile(userId);
Nicolas Prevot88cc3462014-05-14 14:51:48 +01002534 }
2535
Bartosz Fabianowskia34f53f2017-01-11 18:08:47 +01002536 /**
2537 * @hide
2538 */
2539 @Override
2540 public int getInstallReason(String packageName, UserHandle user) {
2541 try {
2542 return mPM.getInstallReason(packageName, user.getIdentifier());
2543 } catch (RemoteException e) {
2544 throw e.rethrowFromSystemServer();
2545 }
2546 }
2547
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002548 /** {@hide} */
2549 private static class MoveCallbackDelegate extends IPackageMoveObserver.Stub implements
2550 Handler.Callback {
Jeff Sharkey50a05452015-04-29 11:24:52 -07002551 private static final int MSG_CREATED = 1;
2552 private static final int MSG_STATUS_CHANGED = 2;
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002553
2554 final MoveCallback mCallback;
2555 final Handler mHandler;
2556
2557 public MoveCallbackDelegate(MoveCallback callback, Looper looper) {
2558 mCallback = callback;
2559 mHandler = new Handler(looper, this);
2560 }
2561
2562 @Override
2563 public boolean handleMessage(Message msg) {
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002564 switch (msg.what) {
Jeff Sharkey50a05452015-04-29 11:24:52 -07002565 case MSG_CREATED: {
Jeff Sharkeyb36586a2015-04-27 08:42:28 -07002566 final SomeArgs args = (SomeArgs) msg.obj;
Jeff Sharkey50a05452015-04-29 11:24:52 -07002567 mCallback.onCreated(args.argi1, (Bundle) args.arg2);
Jeff Sharkeyb36586a2015-04-27 08:42:28 -07002568 args.recycle();
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002569 return true;
Jeff Sharkey50a05452015-04-29 11:24:52 -07002570 }
2571 case MSG_STATUS_CHANGED: {
2572 final SomeArgs args = (SomeArgs) msg.obj;
2573 mCallback.onStatusChanged(args.argi1, args.argi2, (long) args.arg3);
2574 args.recycle();
2575 return true;
2576 }
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002577 }
2578 return false;
2579 }
2580
2581 @Override
Jeff Sharkey50a05452015-04-29 11:24:52 -07002582 public void onCreated(int moveId, Bundle extras) {
Jeff Sharkeyb36586a2015-04-27 08:42:28 -07002583 final SomeArgs args = SomeArgs.obtain();
2584 args.argi1 = moveId;
Jeff Sharkey50a05452015-04-29 11:24:52 -07002585 args.arg2 = extras;
2586 mHandler.obtainMessage(MSG_CREATED, args).sendToTarget();
2587 }
2588
2589 @Override
2590 public void onStatusChanged(int moveId, int status, long estMillis) {
2591 final SomeArgs args = SomeArgs.obtain();
2592 args.argi1 = moveId;
2593 args.argi2 = status;
2594 args.arg3 = estMillis;
Jeff Sharkeyb36586a2015-04-27 08:42:28 -07002595 mHandler.obtainMessage(MSG_STATUS_CHANGED, args).sendToTarget();
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002596 }
2597 }
2598
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002599 private final ContextImpl mContext;
2600 private final IPackageManager mPM;
2601
2602 private static final Object sSync = new Object();
Dianne Hackbornadd005c2013-07-17 18:43:12 -07002603 private static ArrayMap<ResourceName, WeakReference<Drawable.ConstantState>> sIconCache
2604 = new ArrayMap<ResourceName, WeakReference<Drawable.ConstantState>>();
2605 private static ArrayMap<ResourceName, WeakReference<CharSequence>> sStringCache
2606 = new ArrayMap<ResourceName, WeakReference<CharSequence>>();
Svetoslavf7c06eb2015-06-10 18:43:22 -07002607
2608 private final Map<OnPermissionsChangedListener, IOnPermissionsChangeListener>
2609 mPermissionListeners = new ArrayMap<>();
2610
2611 public class OnPermissionsChangeListenerDelegate extends IOnPermissionsChangeListener.Stub
2612 implements Handler.Callback{
2613 private static final int MSG_PERMISSIONS_CHANGED = 1;
2614
2615 private final OnPermissionsChangedListener mListener;
2616 private final Handler mHandler;
2617
2618
2619 public OnPermissionsChangeListenerDelegate(OnPermissionsChangedListener listener,
2620 Looper looper) {
2621 mListener = listener;
2622 mHandler = new Handler(looper, this);
2623 }
2624
2625 @Override
2626 public void onPermissionsChanged(int uid) {
2627 mHandler.obtainMessage(MSG_PERMISSIONS_CHANGED, uid, 0).sendToTarget();
2628 }
2629
2630 @Override
2631 public boolean handleMessage(Message msg) {
2632 switch (msg.what) {
2633 case MSG_PERMISSIONS_CHANGED: {
2634 final int uid = msg.arg1;
2635 mListener.onPermissionsChanged(uid);
2636 return true;
2637 }
2638 }
2639 return false;
2640 }
2641 }
Suprabh Shuklaaef25132017-01-23 18:09:03 -08002642
2643 @Override
2644 public boolean canRequestPackageInstalls() {
2645 try {
2646 return mPM.canRequestPackageInstalls(mContext.getPackageName(), mContext.getUserId());
2647 } catch (RemoteException e) {
2648 throw e.rethrowAsRuntimeException();
2649 }
2650 }
Chad Brubaker336ae5b2017-03-24 15:53:09 -07002651
2652 @Override
2653 public ComponentName getInstantAppResolverSettingsComponent() {
2654 try {
2655 return mPM.getInstantAppResolverSettingsComponent();
2656 } catch (RemoteException e) {
2657 throw e.rethrowAsRuntimeException();
2658 }
2659 }
Todd Kennedy801e6592017-04-12 14:10:12 -07002660
2661 @Override
2662 public ComponentName getInstantAppInstallerComponent() {
2663 try {
2664 return mPM.getInstantAppInstallerComponent();
2665 } catch (RemoteException e) {
2666 throw e.rethrowAsRuntimeException();
2667 }
2668 }
Chad Brubaker0d277a72017-04-12 16:56:53 -07002669
2670 @Override
2671 public String getInstantAppAndroidId(String packageName, UserHandle user) {
2672 try {
2673 return mPM.getInstantAppAndroidId(packageName, user.getIdentifier());
2674 } catch (RemoteException e) {
2675 throw e.rethrowAsRuntimeException();
2676 }
2677 }
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002678}