blob: b8c4ef783a608c03eb7ab61f1d200b63b7562c9d [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;
Philip P. Moltmann18e3eb82018-03-09 16:55:55 -080023import android.annotation.UserIdInt;
Tor Norbye7b9c9122013-05-30 16:48:33 -070024import android.annotation.XmlRes;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080025import android.content.ComponentName;
26import android.content.ContentResolver;
Yao Chen022b8ea2016-12-16 11:03:28 -080027import android.content.Context;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080028import android.content.Intent;
29import android.content.IntentFilter;
30import android.content.IntentSender;
31import android.content.pm.ActivityInfo;
32import android.content.pm.ApplicationInfo;
Todd Kennedy9106c642017-02-08 14:16:53 -080033import android.content.pm.ChangedPackages;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080034import android.content.pm.ComponentInfo;
35import 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;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080039import android.content.pm.IPackageManager;
40import android.content.pm.IPackageMoveObserver;
41import android.content.pm.IPackageStatsObserver;
Todd Kennedy9da8b8a72017-07-25 15:38:39 -070042import android.content.pm.InstantAppInfo;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080043import 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;
Calin Juravle45f8b292017-11-07 18:49:43 -080059import android.content.pm.dex.ArtManager;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080060import android.content.res.Resources;
61import android.content.res.XmlResourceParser;
Svetoslavc7d62f02014-09-04 15:39:54 -070062import android.graphics.Bitmap;
63import android.graphics.Canvas;
64import android.graphics.Rect;
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +010065import android.graphics.drawable.BitmapDrawable;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080066import android.graphics.drawable.Drawable;
Kenny Guy02c89902016-11-15 19:36:38 +000067import android.graphics.drawable.LayerDrawable;
Jeff Sharkeye6306c42017-03-07 21:03:18 -070068import android.os.Build;
Jeff Sharkey50a05452015-04-29 11:24:52 -070069import android.os.Bundle;
Jeff Sharkey620b32b2015-04-23 19:36:02 -070070import android.os.Handler;
71import android.os.Looper;
72import android.os.Message;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080073import android.os.Process;
74import android.os.RemoteException;
Jeff Sharkeyb2b9ab82015-04-05 21:10:42 -070075import android.os.SystemProperties;
Amith Yamasani67df64b2012-12-14 12:09:36 -080076import android.os.UserHandle;
Nicolas Prevot88cc3462014-05-14 14:51:48 +010077import android.os.UserManager;
Jeff Sharkeye2d45be2015-04-15 17:14:12 -070078import android.os.storage.StorageManager;
79import android.os.storage.VolumeInfo;
Todd Kennedyf39ca8f2015-08-07 14:15:07 -070080import android.provider.Settings;
Calin Juravle3d2af7f2017-04-19 19:56:21 -070081import android.system.ErrnoException;
82import android.system.Os;
83import android.system.OsConstants;
84import android.system.StructStat;
Dianne Hackbornadd005c2013-07-17 18:43:12 -070085import android.util.ArrayMap;
Sunny Goyalbab30752017-04-12 15:36:42 -070086import android.util.IconDrawableFactory;
87import android.util.LauncherIcons;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080088import android.util.Log;
Jeff Browna492c3a2012-08-23 19:48:44 -070089import android.view.Display;
Jeff Sharkeyb2b9ab82015-04-05 21:10:42 -070090
Jeff Sharkey16c8e3f2014-07-24 17:08:17 -070091import com.android.internal.annotations.GuardedBy;
Kenny Guy02c89902016-11-15 19:36:38 +000092import com.android.internal.annotations.VisibleForTesting;
Jeff Sharkeyb36586a2015-04-27 08:42:28 -070093import com.android.internal.os.SomeArgs;
dcashman9d2f4412014-06-09 09:27:54 -070094import com.android.internal.util.Preconditions;
Alexandra Gherghina64d4dca2014-08-28 18:26:56 +010095import com.android.internal.util.UserIcons;
Todd Kennedy9da8b8a72017-07-25 15:38:39 -070096
97import dalvik.system.VMRuntime;
98
Svet Ganov2acf0632015-11-24 19:10:59 -080099import libcore.util.EmptyArray;
Jeff Sharkey16c8e3f2014-07-24 17:08:17 -0700100
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800101import java.lang.ref.WeakReference;
102import java.util.ArrayList;
Svet Ganov2acf0632015-11-24 19:10:59 -0800103import java.util.Collections;
Jeff Sharkey620b32b2015-04-23 19:36:02 -0700104import java.util.Iterator;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800105import java.util.List;
Svetoslavf7c06eb2015-06-10 18:43:22 -0700106import java.util.Map;
Jeff Sharkey620b32b2015-04-23 19:36:02 -0700107import java.util.Objects;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800108
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700109/** @hide */
110public class ApplicationPackageManager extends PackageManager {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800111 private static final String TAG = "ApplicationPackageManager";
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800112 private final static boolean DEBUG_ICONS = false;
113
Svet Ganov2acf0632015-11-24 19:10:59 -0800114 private static final int DEFAULT_EPHEMERAL_COOKIE_MAX_SIZE_BYTES = 16384; // 16KB
115
Adam Lesinskid00bb5e2014-10-07 12:14:45 -0700116 // Default flags to use with PackageManager when no flags are given.
117 private final static int sDefaultFlags = PackageManager.GET_SHARED_LIBRARY_FILES;
118
Jeff Sharkey16c8e3f2014-07-24 17:08:17 -0700119 private final Object mLock = new Object();
120
121 @GuardedBy("mLock")
122 private UserManager mUserManager;
123 @GuardedBy("mLock")
124 private PackageInstaller mInstaller;
Calin Juravle45f8b292017-11-07 18:49:43 -0800125 @GuardedBy("mLock")
126 private ArtManager mArtManager;
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +0100127
Jeff Sharkey620b32b2015-04-23 19:36:02 -0700128 @GuardedBy("mDelegates")
129 private final ArrayList<MoveCallbackDelegate> mDelegates = new ArrayList<>();
130
Svet Ganovf1b7f202015-07-29 08:33:42 -0700131 @GuardedBy("mLock")
132 private String mPermissionsControllerPackageName;
133
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +0100134 UserManager getUserManager() {
Jeff Sharkey16c8e3f2014-07-24 17:08:17 -0700135 synchronized (mLock) {
136 if (mUserManager == null) {
137 mUserManager = UserManager.get(mContext);
138 }
139 return mUserManager;
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +0100140 }
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +0100141 }
142
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800143 @Override
Jeff Sharkeyad357d12018-02-02 13:25:31 -0700144 public int getUserId() {
145 return mContext.getUserId();
146 }
147
148 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800149 public PackageInfo getPackageInfo(String packageName, int flags)
150 throws NameNotFoundException {
Nicolas Prevot9a80e532015-09-23 15:49:28 +0100151 return getPackageInfoAsUser(packageName, flags, mContext.getUserId());
152 }
153
154 @Override
Svet Ganov67882122016-12-11 16:36:34 -0800155 public PackageInfo getPackageInfo(VersionedPackage versionedPackage, int flags)
156 throws NameNotFoundException {
157 try {
158 PackageInfo pi = mPM.getPackageInfoVersioned(versionedPackage, flags,
159 mContext.getUserId());
160 if (pi != null) {
161 return pi;
162 }
163 } catch (RemoteException e) {
164 throw e.rethrowFromSystemServer();
165 }
166 throw new NameNotFoundException(versionedPackage.toString());
167 }
168
169 @Override
Nicolas Prevot9a80e532015-09-23 15:49:28 +0100170 public PackageInfo getPackageInfoAsUser(String packageName, int flags, int userId)
171 throws NameNotFoundException {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800172 try {
Nicolas Prevot9a80e532015-09-23 15:49:28 +0100173 PackageInfo pi = mPM.getPackageInfo(packageName, flags, userId);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800174 if (pi != null) {
175 return pi;
176 }
177 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700178 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800179 }
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800180 throw new NameNotFoundException(packageName);
181 }
182
183 @Override
184 public String[] currentToCanonicalPackageNames(String[] names) {
185 try {
186 return mPM.currentToCanonicalPackageNames(names);
187 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700188 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800189 }
190 }
191
192 @Override
193 public String[] canonicalToCurrentPackageNames(String[] names) {
194 try {
195 return mPM.canonicalToCurrentPackageNames(names);
196 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700197 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800198 }
199 }
200
201 @Override
202 public Intent getLaunchIntentForPackage(String packageName) {
203 // First see if the package has an INFO activity; the existence of
204 // such an activity is implied to be the desired front-door for the
205 // overall package (such as if it has multiple launcher entries).
206 Intent intentToResolve = new Intent(Intent.ACTION_MAIN);
207 intentToResolve.addCategory(Intent.CATEGORY_INFO);
208 intentToResolve.setPackage(packageName);
Dianne Hackborn19415762010-12-15 00:20:27 -0800209 List<ResolveInfo> ris = queryIntentActivities(intentToResolve, 0);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800210
211 // Otherwise, try to find a main launcher activity.
Dianne Hackborn19415762010-12-15 00:20:27 -0800212 if (ris == null || ris.size() <= 0) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800213 // reuse the intent instance
214 intentToResolve.removeCategory(Intent.CATEGORY_INFO);
215 intentToResolve.addCategory(Intent.CATEGORY_LAUNCHER);
216 intentToResolve.setPackage(packageName);
Dianne Hackborn19415762010-12-15 00:20:27 -0800217 ris = queryIntentActivities(intentToResolve, 0);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800218 }
Dianne Hackborn19415762010-12-15 00:20:27 -0800219 if (ris == null || ris.size() <= 0) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800220 return null;
221 }
222 Intent intent = new Intent(intentToResolve);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800223 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Dianne Hackborn19415762010-12-15 00:20:27 -0800224 intent.setClassName(ris.get(0).activityInfo.packageName,
225 ris.get(0).activityInfo.name);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800226 return intent;
227 }
228
229 @Override
Jose Lima970417c2014-04-10 10:42:19 -0700230 public Intent getLeanbackLaunchIntentForPackage(String packageName) {
Roberto Perez7ee1a7a2017-12-04 17:14:33 -0800231 return getLaunchIntentForPackageAndCategory(packageName, Intent.CATEGORY_LEANBACK_LAUNCHER);
232 }
233
234 @Override
235 public Intent getCarLaunchIntentForPackage(String packageName) {
236 return getLaunchIntentForPackageAndCategory(packageName, Intent.CATEGORY_CAR_LAUNCHER);
237 }
238
239 private Intent getLaunchIntentForPackageAndCategory(String packageName, String category) {
240 // Try to find a main launcher activity for the given categories.
Jose Lima970417c2014-04-10 10:42:19 -0700241 Intent intentToResolve = new Intent(Intent.ACTION_MAIN);
Roberto Perez7ee1a7a2017-12-04 17:14:33 -0800242 intentToResolve.addCategory(category);
Jose Lima970417c2014-04-10 10:42:19 -0700243 intentToResolve.setPackage(packageName);
244 List<ResolveInfo> ris = queryIntentActivities(intentToResolve, 0);
245
246 if (ris == null || ris.size() <= 0) {
247 return null;
248 }
249 Intent intent = new Intent(intentToResolve);
250 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
251 intent.setClassName(ris.get(0).activityInfo.packageName,
252 ris.get(0).activityInfo.name);
253 return intent;
254 }
255
256 @Override
Jeff Sharkey8588bc12016-01-06 16:47:42 -0700257 public int[] getPackageGids(String packageName) throws NameNotFoundException {
258 return getPackageGids(packageName, 0);
259 }
260
261 @Override
262 public int[] getPackageGids(String packageName, int flags)
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800263 throws NameNotFoundException {
264 try {
Jeff Sharkeycd654482016-01-08 17:42:11 -0700265 int[] gids = mPM.getPackageGids(packageName, flags, mContext.getUserId());
Svetoslavc6d1c342015-02-26 14:44:43 -0800266 if (gids != null) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800267 return gids;
268 }
269 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700270 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800271 }
272
273 throw new NameNotFoundException(packageName);
274 }
275
276 @Override
Jeff Sharkey8588bc12016-01-06 16:47:42 -0700277 public int getPackageUid(String packageName, int flags) throws NameNotFoundException {
278 return getPackageUidAsUser(packageName, flags, mContext.getUserId());
279 }
280
281 @Override
282 public int getPackageUidAsUser(String packageName, int userId) throws NameNotFoundException {
283 return getPackageUidAsUser(packageName, 0, userId);
284 }
285
286 @Override
287 public int getPackageUidAsUser(String packageName, int flags, int userId)
Dianne Hackborna06de0f2012-12-11 16:34:47 -0800288 throws NameNotFoundException {
289 try {
Jeff Sharkeycd654482016-01-08 17:42:11 -0700290 int uid = mPM.getPackageUid(packageName, flags, userId);
Dianne Hackborna06de0f2012-12-11 16:34:47 -0800291 if (uid >= 0) {
292 return uid;
293 }
294 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700295 throw e.rethrowFromSystemServer();
Dianne Hackborna06de0f2012-12-11 16:34:47 -0800296 }
297
298 throw new NameNotFoundException(packageName);
299 }
300
301 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800302 public PermissionInfo getPermissionInfo(String name, int flags)
303 throws NameNotFoundException {
304 try {
Svetoslav Ganovadb8c522017-07-28 05:46:53 +0000305 PermissionInfo pi = mPM.getPermissionInfo(name,
306 mContext.getOpPackageName(), flags);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800307 if (pi != null) {
308 return pi;
309 }
310 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700311 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800312 }
313
314 throw new NameNotFoundException(name);
315 }
316
317 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700318 @SuppressWarnings("unchecked")
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800319 public List<PermissionInfo> queryPermissionsByGroup(String group, int flags)
320 throws NameNotFoundException {
321 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700322 ParceledListSlice<PermissionInfo> parceledList =
323 mPM.queryPermissionsByGroup(group, flags);
324 if (parceledList != null) {
325 List<PermissionInfo> pi = parceledList.getList();
326 if (pi != null) {
327 return pi;
328 }
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800329 }
330 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700331 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800332 }
333
334 throw new NameNotFoundException(group);
335 }
336
337 @Override
Paul Navin7b89a7b2017-01-26 23:56:08 +0000338 public boolean isPermissionReviewModeEnabled() {
339 return mContext.getResources().getBoolean(
340 com.android.internal.R.bool.config_permissionReviewRequired);
341 }
342
343 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800344 public PermissionGroupInfo getPermissionGroupInfo(String name,
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700345 int flags) throws NameNotFoundException {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800346 try {
347 PermissionGroupInfo pgi = mPM.getPermissionGroupInfo(name, flags);
348 if (pgi != null) {
349 return pgi;
350 }
351 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700352 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800353 }
354
355 throw new NameNotFoundException(name);
356 }
357
358 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700359 @SuppressWarnings("unchecked")
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800360 public List<PermissionGroupInfo> getAllPermissionGroups(int flags) {
361 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700362 ParceledListSlice<PermissionGroupInfo> parceledList =
363 mPM.getAllPermissionGroups(flags);
364 if (parceledList == null) {
365 return Collections.emptyList();
366 }
367 return parceledList.getList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800368 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700369 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800370 }
371 }
372
373 @Override
374 public ApplicationInfo getApplicationInfo(String packageName, int flags)
375 throws NameNotFoundException {
Jeff Sharkeycd654482016-01-08 17:42:11 -0700376 return getApplicationInfoAsUser(packageName, flags, mContext.getUserId());
377 }
378
379 @Override
380 public ApplicationInfo getApplicationInfoAsUser(String packageName, int flags, int userId)
381 throws NameNotFoundException {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800382 try {
Jeff Sharkeycd654482016-01-08 17:42:11 -0700383 ApplicationInfo ai = mPM.getApplicationInfo(packageName, flags, userId);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800384 if (ai != null) {
Narayan Kamathcaa71192014-07-16 11:06:43 +0100385 // This is a temporary hack. Callers must use
386 // createPackageContext(packageName).getApplicationInfo() to
387 // get the right paths.
Tao Baic9a02372016-01-12 15:02:24 -0800388 return maybeAdjustApplicationInfo(ai);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800389 }
390 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700391 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800392 }
393
394 throw new NameNotFoundException(packageName);
395 }
396
Tao Baic9a02372016-01-12 15:02:24 -0800397 private static ApplicationInfo maybeAdjustApplicationInfo(ApplicationInfo info) {
Narayan Kamathcaa71192014-07-16 11:06:43 +0100398 // If we're dealing with a multi-arch application that has both
399 // 32 and 64 bit shared libraries, we might need to choose the secondary
400 // depending on what the current runtime's instruction set is.
401 if (info.primaryCpuAbi != null && info.secondaryCpuAbi != null) {
402 final String runtimeIsa = VMRuntime.getRuntime().vmInstructionSet();
jgu214741cd92014-12-17 17:23:29 -0500403
404 // Get the instruction set that the libraries of secondary Abi is supported.
405 // In presence of a native bridge this might be different than the one secondary Abi used.
406 String secondaryIsa = VMRuntime.getInstructionSet(info.secondaryCpuAbi);
407 final String secondaryDexCodeIsa = SystemProperties.get("ro.dalvik.vm.isa." + secondaryIsa);
408 secondaryIsa = secondaryDexCodeIsa.isEmpty() ? secondaryIsa : secondaryDexCodeIsa;
Narayan Kamathcaa71192014-07-16 11:06:43 +0100409
410 // If the runtimeIsa is the same as the primary isa, then we do nothing.
411 // Everything will be set up correctly because info.nativeLibraryDir will
412 // correspond to the right ISA.
413 if (runtimeIsa.equals(secondaryIsa)) {
Tao Baic9a02372016-01-12 15:02:24 -0800414 ApplicationInfo modified = new ApplicationInfo(info);
415 modified.nativeLibraryDir = info.secondaryNativeLibraryDir;
416 return modified;
Narayan Kamathcaa71192014-07-16 11:06:43 +0100417 }
418 }
Tao Baic9a02372016-01-12 15:02:24 -0800419 return info;
Narayan Kamathcaa71192014-07-16 11:06:43 +0100420 }
421
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800422 @Override
423 public ActivityInfo getActivityInfo(ComponentName className, int flags)
424 throws NameNotFoundException {
425 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700426 ActivityInfo ai = mPM.getActivityInfo(className, flags, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800427 if (ai != null) {
428 return ai;
429 }
430 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700431 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800432 }
433
434 throw new NameNotFoundException(className.toString());
435 }
436
437 @Override
438 public ActivityInfo getReceiverInfo(ComponentName className, int flags)
439 throws NameNotFoundException {
440 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700441 ActivityInfo ai = mPM.getReceiverInfo(className, flags, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800442 if (ai != null) {
443 return ai;
444 }
445 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700446 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800447 }
448
449 throw new NameNotFoundException(className.toString());
450 }
451
452 @Override
453 public ServiceInfo getServiceInfo(ComponentName className, int flags)
454 throws NameNotFoundException {
455 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700456 ServiceInfo si = mPM.getServiceInfo(className, flags, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800457 if (si != null) {
458 return si;
459 }
460 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700461 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800462 }
463
464 throw new NameNotFoundException(className.toString());
465 }
466
467 @Override
468 public ProviderInfo getProviderInfo(ComponentName className, int flags)
469 throws NameNotFoundException {
470 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700471 ProviderInfo pi = mPM.getProviderInfo(className, flags, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800472 if (pi != null) {
473 return pi;
474 }
475 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700476 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800477 }
478
479 throw new NameNotFoundException(className.toString());
480 }
481
482 @Override
483 public String[] getSystemSharedLibraryNames() {
484 try {
485 return mPM.getSystemSharedLibraryNames();
486 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700487 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800488 }
489 }
490
Svet Ganovd7b1f4112016-02-09 18:49:23 -0800491 /** @hide */
492 @Override
Svet Ganov67882122016-12-11 16:36:34 -0800493 public @NonNull List<SharedLibraryInfo> getSharedLibraries(int flags) {
494 return getSharedLibrariesAsUser(flags, mContext.getUserId());
495 }
496
497 /** @hide */
498 @Override
499 @SuppressWarnings("unchecked")
500 public @NonNull List<SharedLibraryInfo> getSharedLibrariesAsUser(int flags, int userId) {
501 try {
502 ParceledListSlice<SharedLibraryInfo> sharedLibs = mPM.getSharedLibraries(
Svet Ganov58c99f02017-05-15 14:07:17 -0700503 mContext.getOpPackageName(), flags, userId);
Svet Ganov67882122016-12-11 16:36:34 -0800504 if (sharedLibs == null) {
505 return Collections.emptyList();
506 }
507 return sharedLibs.getList();
508 } catch (RemoteException e) {
509 throw e.rethrowFromSystemServer();
510 }
511 }
512
513 /** @hide */
514 @Override
Svetoslav Ganova9c25002016-04-13 19:25:56 -0700515 public @NonNull String getServicesSystemSharedLibraryPackageName() {
Svet Ganovd7b1f4112016-02-09 18:49:23 -0800516 try {
517 return mPM.getServicesSystemSharedLibraryPackageName();
518 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700519 throw e.rethrowFromSystemServer();
Svet Ganovd7b1f4112016-02-09 18:49:23 -0800520 }
521 }
522
Svetoslav Ganova9c25002016-04-13 19:25:56 -0700523 /**
524 * @hide
525 */
526 public @NonNull String getSharedSystemSharedLibraryPackageName() {
527 try {
528 return mPM.getSharedSystemSharedLibraryPackageName();
529 } catch (RemoteException e) {
530 throw e.rethrowFromSystemServer();
531 }
532 }
533
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800534 @Override
Todd Kennedy9106c642017-02-08 14:16:53 -0800535 public ChangedPackages getChangedPackages(int sequenceNumber) {
536 try {
537 return mPM.getChangedPackages(sequenceNumber, mContext.getUserId());
538 } catch (RemoteException e) {
539 throw e.rethrowFromSystemServer();
540 }
541 }
542
543 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700544 @SuppressWarnings("unchecked")
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800545 public FeatureInfo[] getSystemAvailableFeatures() {
546 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700547 ParceledListSlice<FeatureInfo> parceledList =
548 mPM.getSystemAvailableFeatures();
549 if (parceledList == null) {
550 return new FeatureInfo[0];
551 }
552 final List<FeatureInfo> list = parceledList.getList();
Jeff Sharkeyd5896632016-03-04 16:16:00 -0700553 final FeatureInfo[] res = new FeatureInfo[list.size()];
554 for (int i = 0; i < res.length; i++) {
555 res[i] = list.get(i);
556 }
557 return res;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800558 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700559 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800560 }
561 }
562
563 @Override
564 public boolean hasSystemFeature(String name) {
Jeff Sharkey115d2c12016-02-15 17:25:57 -0700565 return hasSystemFeature(name, 0);
566 }
567
568 @Override
569 public boolean hasSystemFeature(String name, int version) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800570 try {
Jeff Sharkey115d2c12016-02-15 17:25:57 -0700571 return mPM.hasSystemFeature(name, version);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800572 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700573 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800574 }
575 }
576
577 @Override
578 public int checkPermission(String permName, String pkgName) {
579 try {
Svetoslavc6d1c342015-02-26 14:44:43 -0800580 return mPM.checkPermission(permName, pkgName, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800581 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700582 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800583 }
584 }
585
586 @Override
Svet Ganovad3b2972015-07-07 22:49:17 -0700587 public boolean isPermissionRevokedByPolicy(String permName, String pkgName) {
588 try {
589 return mPM.isPermissionRevokedByPolicy(permName, pkgName, mContext.getUserId());
590 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700591 throw e.rethrowFromSystemServer();
Svet Ganovad3b2972015-07-07 22:49:17 -0700592 }
593 }
594
Svet Ganovf1b7f202015-07-29 08:33:42 -0700595 /**
596 * @hide
597 */
598 @Override
599 public String getPermissionControllerPackageName() {
600 synchronized (mLock) {
601 if (mPermissionsControllerPackageName == null) {
602 try {
603 mPermissionsControllerPackageName = mPM.getPermissionControllerPackageName();
604 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700605 throw e.rethrowFromSystemServer();
Svet Ganovf1b7f202015-07-29 08:33:42 -0700606 }
607 }
608 return mPermissionsControllerPackageName;
609 }
610 }
611
Svet Ganovad3b2972015-07-07 22:49:17 -0700612 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800613 public boolean addPermission(PermissionInfo info) {
614 try {
615 return mPM.addPermission(info);
616 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700617 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800618 }
619 }
620
621 @Override
622 public boolean addPermissionAsync(PermissionInfo info) {
623 try {
624 return mPM.addPermissionAsync(info);
625 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700626 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800627 }
628 }
629
630 @Override
631 public void removePermission(String name) {
632 try {
633 mPM.removePermission(name);
634 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700635 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800636 }
637 }
638
639 @Override
Svet Ganov8c7f7002015-05-07 10:48:44 -0700640 public void grantRuntimePermission(String packageName, String permissionName,
641 UserHandle user) {
Dianne Hackborne639da72012-02-21 15:11:13 -0800642 try {
Svet Ganov8c7f7002015-05-07 10:48:44 -0700643 mPM.grantRuntimePermission(packageName, permissionName, user.getIdentifier());
Dianne Hackborne639da72012-02-21 15:11:13 -0800644 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700645 throw e.rethrowFromSystemServer();
Dianne Hackborne639da72012-02-21 15:11:13 -0800646 }
647 }
648
649 @Override
Svet Ganov8c7f7002015-05-07 10:48:44 -0700650 public void revokeRuntimePermission(String packageName, String permissionName,
651 UserHandle user) {
Dianne Hackborne639da72012-02-21 15:11:13 -0800652 try {
Svet Ganov8c7f7002015-05-07 10:48:44 -0700653 mPM.revokeRuntimePermission(packageName, permissionName, user.getIdentifier());
654 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700655 throw e.rethrowFromSystemServer();
Svet Ganov8c7f7002015-05-07 10:48:44 -0700656 }
657 }
658
659 @Override
660 public int getPermissionFlags(String permissionName, String packageName, UserHandle user) {
661 try {
662 return mPM.getPermissionFlags(permissionName, packageName, user.getIdentifier());
663 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700664 throw e.rethrowFromSystemServer();
Svet Ganov8c7f7002015-05-07 10:48:44 -0700665 }
666 }
667
668 @Override
669 public void updatePermissionFlags(String permissionName, String packageName,
670 int flagMask, int flagValues, UserHandle user) {
671 try {
672 mPM.updatePermissionFlags(permissionName, packageName, flagMask,
673 flagValues, user.getIdentifier());
Dianne Hackborne639da72012-02-21 15:11:13 -0800674 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700675 throw e.rethrowFromSystemServer();
Dianne Hackborne639da72012-02-21 15:11:13 -0800676 }
677 }
678
679 @Override
Svetoslav20770dd2015-05-29 15:43:04 -0700680 public boolean shouldShowRequestPermissionRationale(String permission) {
681 try {
682 return mPM.shouldShowRequestPermissionRationale(permission,
683 mContext.getPackageName(), mContext.getUserId());
684 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700685 throw e.rethrowFromSystemServer();
Svetoslav20770dd2015-05-29 15:43:04 -0700686 }
687 }
688
689 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800690 public int checkSignatures(String pkg1, String pkg2) {
691 try {
692 return mPM.checkSignatures(pkg1, pkg2);
693 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700694 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800695 }
696 }
697
698 @Override
699 public int checkSignatures(int uid1, int uid2) {
700 try {
701 return mPM.checkUidSignatures(uid1, uid2);
702 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700703 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800704 }
705 }
706
707 @Override
Daniel Cashman5cdda342018-01-19 07:22:52 -0800708 public boolean hasSigningCertificate(
709 String packageName, byte[] certificate, @PackageManager.CertificateInputType int type) {
710 try {
711 return mPM.hasSigningCertificate(packageName, certificate, type);
712 } catch (RemoteException e) {
713 throw e.rethrowFromSystemServer();
714 }
715 }
716
717 @Override
718 public boolean hasSigningCertificate(
719 int uid, byte[] certificate, @PackageManager.CertificateInputType int type) {
720 try {
721 return mPM.hasUidSigningCertificate(uid, certificate, type);
722 } catch (RemoteException e) {
723 throw e.rethrowFromSystemServer();
724 }
725 }
726
727 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800728 public String[] getPackagesForUid(int uid) {
729 try {
730 return mPM.getPackagesForUid(uid);
731 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700732 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800733 }
734 }
735
736 @Override
737 public String getNameForUid(int uid) {
738 try {
739 return mPM.getNameForUid(uid);
740 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700741 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800742 }
743 }
744
745 @Override
Todd Kennedy9da8b8a72017-07-25 15:38:39 -0700746 public String[] getNamesForUids(int[] uids) {
747 try {
748 return mPM.getNamesForUids(uids);
749 } catch (RemoteException e) {
750 throw e.rethrowFromSystemServer();
751 }
752 }
753
754 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800755 public int getUidForSharedUser(String sharedUserName)
756 throws NameNotFoundException {
757 try {
758 int uid = mPM.getUidForSharedUser(sharedUserName);
759 if(uid != -1) {
760 return uid;
761 }
762 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700763 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800764 }
765 throw new NameNotFoundException("No shared userid for user:"+sharedUserName);
766 }
767
Kenny Roote6cd0c72011-05-19 12:48:14 -0700768 @SuppressWarnings("unchecked")
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800769 @Override
770 public List<PackageInfo> getInstalledPackages(int flags) {
Jeff Sharkeye06b4d12016-01-06 14:51:50 -0700771 return getInstalledPackagesAsUser(flags, mContext.getUserId());
Amith Yamasani151ec4c2012-09-07 19:25:16 -0700772 }
773
774 /** @hide */
775 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700776 @SuppressWarnings("unchecked")
Jeff Sharkeye06b4d12016-01-06 14:51:50 -0700777 public List<PackageInfo> getInstalledPackagesAsUser(int flags, int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800778 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700779 ParceledListSlice<PackageInfo> parceledList =
780 mPM.getInstalledPackages(flags, userId);
781 if (parceledList == null) {
782 return Collections.emptyList();
783 }
784 return parceledList.getList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800785 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700786 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800787 }
788 }
789
Kenny Roote6cd0c72011-05-19 12:48:14 -0700790 @SuppressWarnings("unchecked")
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800791 @Override
Dianne Hackborne7991752013-01-16 17:56:46 -0800792 public List<PackageInfo> getPackagesHoldingPermissions(
793 String[] permissions, int flags) {
794 final int userId = mContext.getUserId();
795 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700796 ParceledListSlice<PackageInfo> parceledList =
797 mPM.getPackagesHoldingPermissions(permissions, flags, userId);
798 if (parceledList == null) {
799 return Collections.emptyList();
800 }
801 return parceledList.getList();
Dianne Hackborne7991752013-01-16 17:56:46 -0800802 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700803 throw e.rethrowFromSystemServer();
Dianne Hackborne7991752013-01-16 17:56:46 -0800804 }
805 }
806
807 @SuppressWarnings("unchecked")
808 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800809 public List<ApplicationInfo> getInstalledApplications(int flags) {
Bartosz Fabianowski11334242016-11-17 20:49:16 +0100810 return getInstalledApplicationsAsUser(flags, mContext.getUserId());
811 }
812
813 /** @hide */
814 @SuppressWarnings("unchecked")
815 @Override
816 public List<ApplicationInfo> getInstalledApplicationsAsUser(int flags, int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800817 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700818 ParceledListSlice<ApplicationInfo> parceledList =
819 mPM.getInstalledApplications(flags, userId);
820 if (parceledList == null) {
821 return Collections.emptyList();
822 }
823 return parceledList.getList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800824 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700825 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800826 }
827 }
828
Svet Ganov2acf0632015-11-24 19:10:59 -0800829 /** @hide */
830 @SuppressWarnings("unchecked")
831 @Override
Svetoslav Ganov096d3042017-01-30 16:34:13 -0800832 public List<InstantAppInfo> getInstantApps() {
Svet Ganov2acf0632015-11-24 19:10:59 -0800833 try {
Svetoslav Ganov096d3042017-01-30 16:34:13 -0800834 ParceledListSlice<InstantAppInfo> slice =
835 mPM.getInstantApps(mContext.getUserId());
Svet Ganov2acf0632015-11-24 19:10:59 -0800836 if (slice != null) {
837 return slice.getList();
838 }
839 return Collections.emptyList();
840 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700841 throw e.rethrowFromSystemServer();
Svet Ganov2acf0632015-11-24 19:10:59 -0800842 }
843 }
844
845 /** @hide */
846 @Override
Svetoslav Ganov096d3042017-01-30 16:34:13 -0800847 public Drawable getInstantAppIcon(String packageName) {
Svet Ganov2acf0632015-11-24 19:10:59 -0800848 try {
Svetoslav Ganov096d3042017-01-30 16:34:13 -0800849 Bitmap bitmap = mPM.getInstantAppIcon(
Svet Ganov2acf0632015-11-24 19:10:59 -0800850 packageName, mContext.getUserId());
851 if (bitmap != null) {
852 return new BitmapDrawable(null, bitmap);
853 }
854 return null;
855 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700856 throw e.rethrowFromSystemServer();
Svet Ganov2acf0632015-11-24 19:10:59 -0800857 }
858 }
859
860 @Override
Svetoslav Ganov096d3042017-01-30 16:34:13 -0800861 public boolean isInstantApp() {
David Christie31a16552017-03-01 15:08:45 -0800862 return isInstantApp(mContext.getPackageName());
863 }
864
865 @Override
866 public boolean isInstantApp(String packageName) {
Svet Ganov2acf0632015-11-24 19:10:59 -0800867 try {
David Christie31a16552017-03-01 15:08:45 -0800868 return mPM.isInstantApp(packageName, mContext.getUserId());
Svet Ganov2acf0632015-11-24 19:10:59 -0800869 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700870 throw e.rethrowFromSystemServer();
Svet Ganov2acf0632015-11-24 19:10:59 -0800871 }
Svet Ganov2acf0632015-11-24 19:10:59 -0800872 }
873
Svetoslav Ganov345ffa52017-04-18 16:08:41 -0700874 public int getInstantAppCookieMaxBytes() {
Svet Ganov2acf0632015-11-24 19:10:59 -0800875 return Settings.Global.getInt(mContext.getContentResolver(),
876 Settings.Global.EPHEMERAL_COOKIE_MAX_SIZE_BYTES,
877 DEFAULT_EPHEMERAL_COOKIE_MAX_SIZE_BYTES);
878 }
879
880 @Override
Svetoslav Ganov345ffa52017-04-18 16:08:41 -0700881 public int getInstantAppCookieMaxSize() {
882 return getInstantAppCookieMaxBytes();
883 }
884
885 @Override
Svetoslav Ganov096d3042017-01-30 16:34:13 -0800886 public @NonNull byte[] getInstantAppCookie() {
Svet Ganov2acf0632015-11-24 19:10:59 -0800887 try {
Svetoslav Ganov096d3042017-01-30 16:34:13 -0800888 final byte[] cookie = mPM.getInstantAppCookie(
Svet Ganov2acf0632015-11-24 19:10:59 -0800889 mContext.getPackageName(), mContext.getUserId());
890 if (cookie != null) {
891 return cookie;
Jeff Sharkey27b2e692016-02-25 17:40:12 -0700892 } else {
893 return EmptyArray.BYTE;
Svet Ganov2acf0632015-11-24 19:10:59 -0800894 }
895 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700896 throw e.rethrowFromSystemServer();
Svet Ganov2acf0632015-11-24 19:10:59 -0800897 }
Svet Ganov2acf0632015-11-24 19:10:59 -0800898 }
899
900 @Override
Svetoslav Ganov345ffa52017-04-18 16:08:41 -0700901 public void clearInstantAppCookie() {
902 updateInstantAppCookie(null);
903 }
904
905 @Override
906 public void updateInstantAppCookie(@NonNull byte[] cookie) {
907 if (cookie != null && cookie.length > getInstantAppCookieMaxBytes()) {
908 throw new IllegalArgumentException("instant cookie longer than "
909 + getInstantAppCookieMaxBytes());
910 }
911 try {
912 mPM.setInstantAppCookie(mContext.getPackageName(),
913 cookie, mContext.getUserId());
914 } catch (RemoteException e) {
915 throw e.rethrowFromSystemServer();
916 }
917 }
918
919 @Override
Svetoslav Ganov096d3042017-01-30 16:34:13 -0800920 public boolean setInstantAppCookie(@NonNull byte[] cookie) {
Svet Ganov2acf0632015-11-24 19:10:59 -0800921 try {
Svetoslav Ganov096d3042017-01-30 16:34:13 -0800922 return mPM.setInstantAppCookie(mContext.getPackageName(),
923 cookie, mContext.getUserId());
Svet Ganov2acf0632015-11-24 19:10:59 -0800924 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700925 throw e.rethrowFromSystemServer();
Svet Ganov2acf0632015-11-24 19:10:59 -0800926 }
Svet Ganov2acf0632015-11-24 19:10:59 -0800927 }
928
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800929 @Override
930 public ResolveInfo resolveActivity(Intent intent, int flags) {
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700931 return resolveActivityAsUser(intent, flags, mContext.getUserId());
Svetoslav Ganov58d37b52012-09-18 12:04:19 -0700932 }
933
934 @Override
935 public ResolveInfo resolveActivityAsUser(Intent intent, int flags, int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800936 try {
937 return mPM.resolveIntent(
938 intent,
939 intent.resolveTypeIfNeeded(mContext.getContentResolver()),
Svetoslav Ganov58d37b52012-09-18 12:04:19 -0700940 flags,
941 userId);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800942 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700943 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800944 }
945 }
946
947 @Override
948 public List<ResolveInfo> queryIntentActivities(Intent intent,
949 int flags) {
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700950 return queryIntentActivitiesAsUser(intent, flags, mContext.getUserId());
Amith Yamasani151ec4c2012-09-07 19:25:16 -0700951 }
952
953 /** @hide Same as above but for a specific user */
954 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700955 @SuppressWarnings("unchecked")
Svetoslav Ganov58d37b52012-09-18 12:04:19 -0700956 public List<ResolveInfo> queryIntentActivitiesAsUser(Intent intent,
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700957 int flags, int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800958 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700959 ParceledListSlice<ResolveInfo> parceledList =
960 mPM.queryIntentActivities(intent,
961 intent.resolveTypeIfNeeded(mContext.getContentResolver()),
962 flags, userId);
963 if (parceledList == null) {
964 return Collections.emptyList();
965 }
966 return parceledList.getList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800967 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700968 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800969 }
970 }
971
972 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700973 @SuppressWarnings("unchecked")
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800974 public List<ResolveInfo> queryIntentActivityOptions(
975 ComponentName caller, Intent[] specifics, Intent intent,
976 int flags) {
977 final ContentResolver resolver = mContext.getContentResolver();
978
979 String[] specificTypes = null;
980 if (specifics != null) {
981 final int N = specifics.length;
982 for (int i=0; i<N; i++) {
983 Intent sp = specifics[i];
984 if (sp != null) {
985 String t = sp.resolveTypeIfNeeded(resolver);
986 if (t != null) {
987 if (specificTypes == null) {
988 specificTypes = new String[N];
989 }
990 specificTypes[i] = t;
991 }
992 }
993 }
994 }
995
996 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700997 ParceledListSlice<ResolveInfo> parceledList =
998 mPM.queryIntentActivityOptions(caller, specifics, specificTypes, intent,
999 intent.resolveTypeIfNeeded(resolver), flags, mContext.getUserId());
1000 if (parceledList == null) {
1001 return Collections.emptyList();
1002 }
1003 return parceledList.getList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001004 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001005 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001006 }
1007 }
1008
Amith Yamasanif203aee2012-08-29 18:41:53 -07001009 /**
1010 * @hide
1011 */
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001012 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001013 @SuppressWarnings("unchecked")
Jeff Sharkeye06b4d12016-01-06 14:51:50 -07001014 public List<ResolveInfo> queryBroadcastReceiversAsUser(Intent intent, int flags, int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001015 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001016 ParceledListSlice<ResolveInfo> parceledList =
1017 mPM.queryIntentReceivers(intent,
1018 intent.resolveTypeIfNeeded(mContext.getContentResolver()),
1019 flags, userId);
1020 if (parceledList == null) {
1021 return Collections.emptyList();
1022 }
1023 return parceledList.getList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001024 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001025 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001026 }
1027 }
1028
1029 @Override
Amith Yamasanif203aee2012-08-29 18:41:53 -07001030 public List<ResolveInfo> queryBroadcastReceivers(Intent intent, int flags) {
Jeff Sharkeye06b4d12016-01-06 14:51:50 -07001031 return queryBroadcastReceiversAsUser(intent, flags, mContext.getUserId());
Amith Yamasanif203aee2012-08-29 18:41:53 -07001032 }
1033
1034 @Override
Philip P. Moltmann18e3eb82018-03-09 16:55:55 -08001035 public ResolveInfo resolveServiceAsUser(Intent intent, @ResolveInfoFlags int flags,
1036 @UserIdInt int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001037 try {
1038 return mPM.resolveService(
1039 intent,
1040 intent.resolveTypeIfNeeded(mContext.getContentResolver()),
Amith Yamasani483f3b02012-03-13 16:08:00 -07001041 flags,
Philip P. Moltmann18e3eb82018-03-09 16:55:55 -08001042 userId);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001043 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001044 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001045 }
1046 }
1047
1048 @Override
Philip P. Moltmann18e3eb82018-03-09 16:55:55 -08001049 public ResolveInfo resolveService(Intent intent, int flags) {
1050 return resolveServiceAsUser(intent, flags, mContext.getUserId());
1051 }
1052
1053 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001054 @SuppressWarnings("unchecked")
Svetoslav Ganov58d37b52012-09-18 12:04:19 -07001055 public List<ResolveInfo> queryIntentServicesAsUser(Intent intent, int flags, int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001056 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001057 ParceledListSlice<ResolveInfo> parceledList =
1058 mPM.queryIntentServices(intent,
1059 intent.resolveTypeIfNeeded(mContext.getContentResolver()),
1060 flags, userId);
1061 if (parceledList == null) {
1062 return Collections.emptyList();
1063 }
1064 return parceledList.getList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001065 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001066 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001067 }
1068 }
1069
1070 @Override
Svetoslav Ganov58d37b52012-09-18 12:04:19 -07001071 public List<ResolveInfo> queryIntentServices(Intent intent, int flags) {
Jeff Sharkeyded653b2012-09-27 19:09:24 -07001072 return queryIntentServicesAsUser(intent, flags, mContext.getUserId());
Svetoslav Ganov58d37b52012-09-18 12:04:19 -07001073 }
1074
1075 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001076 @SuppressWarnings("unchecked")
Jeff Sharkey85f5f812013-10-07 10:16:12 -07001077 public List<ResolveInfo> queryIntentContentProvidersAsUser(
1078 Intent intent, int flags, int userId) {
1079 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001080 ParceledListSlice<ResolveInfo> parceledList =
1081 mPM.queryIntentContentProviders(intent,
1082 intent.resolveTypeIfNeeded(mContext.getContentResolver()),
1083 flags, userId);
1084 if (parceledList == null) {
1085 return Collections.emptyList();
1086 }
1087 return parceledList.getList();
Jeff Sharkey85f5f812013-10-07 10:16:12 -07001088 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001089 throw e.rethrowFromSystemServer();
Jeff Sharkey85f5f812013-10-07 10:16:12 -07001090 }
1091 }
1092
1093 @Override
1094 public List<ResolveInfo> queryIntentContentProviders(Intent intent, int flags) {
1095 return queryIntentContentProvidersAsUser(intent, flags, mContext.getUserId());
1096 }
1097
1098 @Override
Alexandra Gherghina0363c3e2014-06-23 13:34:59 +01001099 public ProviderInfo resolveContentProvider(String name, int flags) {
1100 return resolveContentProviderAsUser(name, flags, mContext.getUserId());
1101 }
1102
1103 /** @hide **/
1104 @Override
1105 public ProviderInfo resolveContentProviderAsUser(String name, int flags, int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001106 try {
Alexandra Gherghina0363c3e2014-06-23 13:34:59 +01001107 return mPM.resolveContentProvider(name, flags, userId);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001108 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001109 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001110 }
1111 }
1112
1113 @Override
1114 public List<ProviderInfo> queryContentProviders(String processName,
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001115 int uid, int flags) {
Makoto Onuki32757292017-02-22 14:36:59 -08001116 return queryContentProviders(processName, uid, flags, null);
1117 }
1118
1119 @Override
1120 @SuppressWarnings("unchecked")
1121 public List<ProviderInfo> queryContentProviders(String processName,
1122 int uid, int flags, String metaDataKey) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001123 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001124 ParceledListSlice<ProviderInfo> slice =
Makoto Onuki32757292017-02-22 14:36:59 -08001125 mPM.queryContentProviders(processName, uid, flags, metaDataKey);
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001126 return slice != null ? slice.getList() : Collections.<ProviderInfo>emptyList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001127 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001128 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001129 }
1130 }
1131
1132 @Override
1133 public InstrumentationInfo getInstrumentationInfo(
1134 ComponentName className, int flags)
1135 throws NameNotFoundException {
1136 try {
1137 InstrumentationInfo ii = mPM.getInstrumentationInfo(
1138 className, flags);
1139 if (ii != null) {
1140 return ii;
1141 }
1142 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001143 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001144 }
1145
1146 throw new NameNotFoundException(className.toString());
1147 }
1148
1149 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001150 @SuppressWarnings("unchecked")
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001151 public List<InstrumentationInfo> queryInstrumentation(
1152 String targetPackage, int flags) {
1153 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001154 ParceledListSlice<InstrumentationInfo> parceledList =
1155 mPM.queryInstrumentation(targetPackage, flags);
1156 if (parceledList == null) {
1157 return Collections.emptyList();
1158 }
1159 return parceledList.getList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001160 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001161 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001162 }
1163 }
1164
Alan Viveretteecd585a2015-04-13 10:32:51 -07001165 @Nullable
1166 @Override
1167 public Drawable getDrawable(String packageName, @DrawableRes int resId,
1168 @Nullable ApplicationInfo appInfo) {
1169 final ResourceName name = new ResourceName(packageName, resId);
1170 final Drawable cachedIcon = getCachedIcon(name);
1171 if (cachedIcon != null) {
1172 return cachedIcon;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001173 }
Alan Viveretteecd585a2015-04-13 10:32:51 -07001174
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001175 if (appInfo == null) {
1176 try {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001177 appInfo = getApplicationInfo(packageName, sDefaultFlags);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001178 } catch (NameNotFoundException e) {
1179 return null;
1180 }
1181 }
Alan Viveretteecd585a2015-04-13 10:32:51 -07001182
1183 if (resId != 0) {
1184 try {
1185 final Resources r = getResourcesForApplication(appInfo);
1186 final Drawable dr = r.getDrawable(resId, null);
1187 if (dr != null) {
1188 putCachedIcon(name, dr);
1189 }
1190
1191 if (false) {
1192 RuntimeException e = new RuntimeException("here");
1193 e.fillInStackTrace();
1194 Log.w(TAG, "Getting drawable 0x" + Integer.toHexString(resId)
1195 + " from package " + packageName
1196 + ": app scale=" + r.getCompatibilityInfo().applicationScale
1197 + ", caller scale=" + mContext.getResources()
1198 .getCompatibilityInfo().applicationScale,
1199 e);
1200 }
Ricky Wai3ce46252015-04-15 16:12:22 +01001201 if (DEBUG_ICONS) {
Alan Viveretteecd585a2015-04-13 10:32:51 -07001202 Log.v(TAG, "Getting drawable 0x"
1203 + Integer.toHexString(resId) + " from " + r
1204 + ": " + dr);
Ricky Wai3ce46252015-04-15 16:12:22 +01001205 }
1206 return dr;
Alan Viveretteecd585a2015-04-13 10:32:51 -07001207 } catch (NameNotFoundException e) {
1208 Log.w("PackageManager", "Failure retrieving resources for "
1209 + appInfo.packageName);
1210 } catch (Resources.NotFoundException e) {
1211 Log.w("PackageManager", "Failure retrieving resources for "
1212 + appInfo.packageName + ": " + e.getMessage());
1213 } catch (Exception e) {
1214 // If an exception was thrown, fall through to return
1215 // default icon.
1216 Log.w("PackageManager", "Failure retrieving icon 0x"
1217 + Integer.toHexString(resId) + " in package "
1218 + packageName, e);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001219 }
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001220 }
Alan Viveretteecd585a2015-04-13 10:32:51 -07001221
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001222 return null;
1223 }
1224
1225 @Override public Drawable getActivityIcon(ComponentName activityName)
1226 throws NameNotFoundException {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001227 return getActivityInfo(activityName, sDefaultFlags).loadIcon(this);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001228 }
1229
1230 @Override public Drawable getActivityIcon(Intent intent)
1231 throws NameNotFoundException {
1232 if (intent.getComponent() != null) {
1233 return getActivityIcon(intent.getComponent());
1234 }
1235
1236 ResolveInfo info = resolveActivity(
1237 intent, PackageManager.MATCH_DEFAULT_ONLY);
1238 if (info != null) {
1239 return info.activityInfo.loadIcon(this);
1240 }
1241
Romain Guy39fe17c2011-11-30 10:34:07 -08001242 throw new NameNotFoundException(intent.toUri(0));
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001243 }
1244
1245 @Override public Drawable getDefaultActivityIcon() {
1246 return Resources.getSystem().getDrawable(
1247 com.android.internal.R.drawable.sym_def_app_icon);
1248 }
1249
1250 @Override public Drawable getApplicationIcon(ApplicationInfo info) {
1251 return info.loadIcon(this);
1252 }
1253
1254 @Override public Drawable getApplicationIcon(String packageName)
1255 throws NameNotFoundException {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001256 return getApplicationIcon(getApplicationInfo(packageName, sDefaultFlags));
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001257 }
1258
1259 @Override
Jose Limaf78e3122014-03-06 12:13:15 -08001260 public Drawable getActivityBanner(ComponentName activityName)
1261 throws NameNotFoundException {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001262 return getActivityInfo(activityName, sDefaultFlags).loadBanner(this);
Jose Limaf78e3122014-03-06 12:13:15 -08001263 }
1264
1265 @Override
1266 public Drawable getActivityBanner(Intent intent)
1267 throws NameNotFoundException {
1268 if (intent.getComponent() != null) {
1269 return getActivityBanner(intent.getComponent());
1270 }
1271
1272 ResolveInfo info = resolveActivity(
1273 intent, PackageManager.MATCH_DEFAULT_ONLY);
1274 if (info != null) {
1275 return info.activityInfo.loadBanner(this);
1276 }
1277
1278 throw new NameNotFoundException(intent.toUri(0));
1279 }
1280
1281 @Override
1282 public Drawable getApplicationBanner(ApplicationInfo info) {
1283 return info.loadBanner(this);
1284 }
1285
1286 @Override
1287 public Drawable getApplicationBanner(String packageName)
1288 throws NameNotFoundException {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001289 return getApplicationBanner(getApplicationInfo(packageName, sDefaultFlags));
Jose Limaf78e3122014-03-06 12:13:15 -08001290 }
1291
1292 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001293 public Drawable getActivityLogo(ComponentName activityName)
1294 throws NameNotFoundException {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001295 return getActivityInfo(activityName, sDefaultFlags).loadLogo(this);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001296 }
1297
1298 @Override
1299 public Drawable getActivityLogo(Intent intent)
1300 throws NameNotFoundException {
1301 if (intent.getComponent() != null) {
1302 return getActivityLogo(intent.getComponent());
1303 }
1304
1305 ResolveInfo info = resolveActivity(
1306 intent, PackageManager.MATCH_DEFAULT_ONLY);
1307 if (info != null) {
1308 return info.activityInfo.loadLogo(this);
1309 }
1310
1311 throw new NameNotFoundException(intent.toUri(0));
1312 }
1313
1314 @Override
1315 public Drawable getApplicationLogo(ApplicationInfo info) {
1316 return info.loadLogo(this);
1317 }
1318
1319 @Override
1320 public Drawable getApplicationLogo(String packageName)
1321 throws NameNotFoundException {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001322 return getApplicationLogo(getApplicationInfo(packageName, sDefaultFlags));
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001323 }
1324
Svetoslavc7d62f02014-09-04 15:39:54 -07001325 @Override
1326 public Drawable getUserBadgedIcon(Drawable icon, UserHandle user) {
Kenny Guy02c89902016-11-15 19:36:38 +00001327 if (!isManagedProfile(user.getIdentifier())) {
Svetoslavc7d62f02014-09-04 15:39:54 -07001328 return icon;
1329 }
Sunny Goyalbab30752017-04-12 15:36:42 -07001330 Drawable badge = new LauncherIcons(mContext).getBadgeDrawable(
1331 com.android.internal.R.drawable.ic_corp_icon_badge_case,
1332 getUserBadgeColor(user));
Kenny Guy02c89902016-11-15 19:36:38 +00001333 return getBadgedDrawable(icon, badge, null, true);
Svetoslavc7d62f02014-09-04 15:39:54 -07001334 }
1335
1336 @Override
1337 public Drawable getUserBadgedDrawableForDensity(Drawable drawable, UserHandle user,
1338 Rect badgeLocation, int badgeDensity) {
1339 Drawable badgeDrawable = getUserBadgeForDensity(user, badgeDensity);
1340 if (badgeDrawable == null) {
1341 return drawable;
1342 }
1343 return getBadgedDrawable(drawable, badgeDrawable, badgeLocation, true);
1344 }
1345
Kenny Guy02c89902016-11-15 19:36:38 +00001346 @VisibleForTesting
1347 public static final int[] CORP_BADGE_LABEL_RES_ID = new int[] {
1348 com.android.internal.R.string.managed_profile_label_badge,
1349 com.android.internal.R.string.managed_profile_label_badge_2,
1350 com.android.internal.R.string.managed_profile_label_badge_3
1351 };
1352
1353 private int getUserBadgeColor(UserHandle user) {
Sunny Goyalbab30752017-04-12 15:36:42 -07001354 return IconDrawableFactory.getUserBadgeColor(getUserManager(), user.getIdentifier());
Kenny Guy02c89902016-11-15 19:36:38 +00001355 }
1356
Svetoslavc7d62f02014-09-04 15:39:54 -07001357 @Override
1358 public Drawable getUserBadgeForDensity(UserHandle user, int density) {
Kenny Guy02c89902016-11-15 19:36:38 +00001359 Drawable badgeColor = getManagedProfileIconForDensity(user,
1360 com.android.internal.R.drawable.ic_corp_badge_color, density);
1361 if (badgeColor == null) {
1362 return null;
1363 }
Kenny Guy02c89902016-11-15 19:36:38 +00001364 Drawable badgeForeground = getDrawableForDensity(
1365 com.android.internal.R.drawable.ic_corp_badge_case, density);
Tony Make21a1d02018-02-16 11:46:58 +00001366 badgeForeground.setTint(getUserBadgeColor(user));
1367 Drawable badge = new LayerDrawable(new Drawable[] {badgeColor, badgeForeground });
Kenny Guy02c89902016-11-15 19:36:38 +00001368 return badge;
Selim Cineke6ff9462016-01-15 15:07:06 -08001369 }
1370
1371 @Override
1372 public Drawable getUserBadgeForDensityNoBackground(UserHandle user, int density) {
Kenny Guy02c89902016-11-15 19:36:38 +00001373 Drawable badge = getManagedProfileIconForDensity(user,
Vadim Tryshev66ae66a2016-02-18 15:41:21 -08001374 com.android.internal.R.drawable.ic_corp_badge_no_background, density);
Kenny Guy02c89902016-11-15 19:36:38 +00001375 if (badge != null) {
1376 badge.setTint(getUserBadgeColor(user));
1377 }
1378 return badge;
Selim Cineke6ff9462016-01-15 15:07:06 -08001379 }
1380
Vadim Tryshev66ae66a2016-02-18 15:41:21 -08001381 private Drawable getDrawableForDensity(int drawableId, int density) {
1382 if (density <= 0) {
1383 density = mContext.getResources().getDisplayMetrics().densityDpi;
1384 }
1385 return Resources.getSystem().getDrawableForDensity(drawableId, density);
1386 }
1387
1388 private Drawable getManagedProfileIconForDensity(UserHandle user, int drawableId, int density) {
Tony Mak8673b282016-03-21 21:10:59 +00001389 if (isManagedProfile(user.getIdentifier())) {
Vadim Tryshev66ae66a2016-02-18 15:41:21 -08001390 return getDrawableForDensity(drawableId, density);
Svetoslavc7d62f02014-09-04 15:39:54 -07001391 }
1392 return null;
1393 }
1394
1395 @Override
1396 public CharSequence getUserBadgedLabel(CharSequence label, UserHandle user) {
Tony Mak8673b282016-03-21 21:10:59 +00001397 if (isManagedProfile(user.getIdentifier())) {
Kenny Guy02c89902016-11-15 19:36:38 +00001398 int badge = getUserManager().getManagedProfileBadge(user.getIdentifier());
1399 int resourceId = CORP_BADGE_LABEL_RES_ID[badge % CORP_BADGE_LABEL_RES_ID.length];
1400 return Resources.getSystem().getString(resourceId, label);
Svetoslavc7d62f02014-09-04 15:39:54 -07001401 }
1402 return label;
1403 }
1404
Alan Viveretteecd585a2015-04-13 10:32:51 -07001405 @Override
1406 public Resources getResourcesForActivity(ComponentName activityName)
1407 throws NameNotFoundException {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001408 return getResourcesForApplication(
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001409 getActivityInfo(activityName, sDefaultFlags).applicationInfo);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001410 }
1411
Alan Viveretteecd585a2015-04-13 10:32:51 -07001412 @Override
1413 public Resources getResourcesForApplication(@NonNull ApplicationInfo app)
1414 throws NameNotFoundException {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001415 if (app.packageName.equals("system")) {
Adam Lesinskia82b6262017-03-21 16:56:17 -07001416 return mContext.mMainThread.getSystemUiContext().getResources();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001417 }
Jeff Sharkey8a4c9722014-06-16 13:48:42 -07001418 final boolean sameUid = (app.uid == Process.myUid());
Adam Lesinski53fafdf2016-08-03 13:36:39 -07001419 final Resources r = mContext.mMainThread.getTopLevelResources(
Adam Lesinskic82f28a2016-06-08 17:19:09 -07001420 sameUid ? app.sourceDir : app.publicSourceDir,
1421 sameUid ? app.splitSourceDirs : app.splitPublicSourceDirs,
1422 app.resourceDirs, app.sharedLibraryFiles, Display.DEFAULT_DISPLAY,
Todd Kennedy233a0b12018-01-29 20:30:24 +00001423 mContext.mPackageInfo);
Adam Lesinski53fafdf2016-08-03 13:36:39 -07001424 if (r != null) {
1425 return r;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001426 }
Adam Lesinski53fafdf2016-08-03 13:36:39 -07001427 throw new NameNotFoundException("Unable to open " + app.publicSourceDir);
1428
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001429 }
1430
Alan Viveretteecd585a2015-04-13 10:32:51 -07001431 @Override
1432 public Resources getResourcesForApplication(String appPackageName)
1433 throws NameNotFoundException {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001434 return getResourcesForApplication(
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001435 getApplicationInfo(appPackageName, sDefaultFlags));
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001436 }
1437
Amith Yamasani98edc952012-09-25 14:09:27 -07001438 /** @hide */
1439 @Override
1440 public Resources getResourcesForApplicationAsUser(String appPackageName, int userId)
1441 throws NameNotFoundException {
Jeff Sharkeyded653b2012-09-27 19:09:24 -07001442 if (userId < 0) {
1443 throw new IllegalArgumentException(
1444 "Call does not support special user #" + userId);
1445 }
1446 if ("system".equals(appPackageName)) {
Adam Lesinskia82b6262017-03-21 16:56:17 -07001447 return mContext.mMainThread.getSystemUiContext().getResources();
Jeff Sharkeyded653b2012-09-27 19:09:24 -07001448 }
Amith Yamasani98edc952012-09-25 14:09:27 -07001449 try {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001450 ApplicationInfo ai = mPM.getApplicationInfo(appPackageName, sDefaultFlags, userId);
Amith Yamasani98edc952012-09-25 14:09:27 -07001451 if (ai != null) {
1452 return getResourcesForApplication(ai);
1453 }
1454 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001455 throw e.rethrowFromSystemServer();
Amith Yamasani98edc952012-09-25 14:09:27 -07001456 }
1457 throw new NameNotFoundException("Package " + appPackageName + " doesn't exist");
1458 }
1459
Jeff Sharkeycd654482016-01-08 17:42:11 -07001460 volatile int mCachedSafeMode = -1;
1461
1462 @Override
1463 public boolean isSafeMode() {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001464 try {
1465 if (mCachedSafeMode < 0) {
1466 mCachedSafeMode = mPM.isSafeMode() ? 1 : 0;
1467 }
1468 return mCachedSafeMode != 0;
1469 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001470 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001471 }
1472 }
1473
Svetoslavf7c06eb2015-06-10 18:43:22 -07001474 @Override
1475 public void addOnPermissionsChangeListener(OnPermissionsChangedListener listener) {
1476 synchronized (mPermissionListeners) {
1477 if (mPermissionListeners.get(listener) != null) {
1478 return;
1479 }
1480 OnPermissionsChangeListenerDelegate delegate =
1481 new OnPermissionsChangeListenerDelegate(listener, Looper.getMainLooper());
1482 try {
1483 mPM.addOnPermissionsChangeListener(delegate);
1484 mPermissionListeners.put(listener, delegate);
1485 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001486 throw e.rethrowFromSystemServer();
Svetoslavf7c06eb2015-06-10 18:43:22 -07001487 }
1488 }
1489 }
1490
1491 @Override
1492 public void removeOnPermissionsChangeListener(OnPermissionsChangedListener listener) {
1493 synchronized (mPermissionListeners) {
1494 IOnPermissionsChangeListener delegate = mPermissionListeners.get(listener);
1495 if (delegate != null) {
1496 try {
1497 mPM.removeOnPermissionsChangeListener(delegate);
1498 mPermissionListeners.remove(listener);
1499 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001500 throw e.rethrowFromSystemServer();
Svetoslavf7c06eb2015-06-10 18:43:22 -07001501 }
1502 }
1503 }
1504 }
1505
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001506 static void configurationChanged() {
1507 synchronized (sSync) {
1508 sIconCache.clear();
1509 sStringCache.clear();
1510 }
1511 }
1512
Yao Chen022b8ea2016-12-16 11:03:28 -08001513 protected ApplicationPackageManager(ContextImpl context,
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001514 IPackageManager pm) {
1515 mContext = context;
1516 mPM = pm;
1517 }
1518
Alan Viveretteecd585a2015-04-13 10:32:51 -07001519 @Nullable
1520 private Drawable getCachedIcon(@NonNull ResourceName name) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001521 synchronized (sSync) {
Alan Viveretteecd585a2015-04-13 10:32:51 -07001522 final WeakReference<Drawable.ConstantState> wr = sIconCache.get(name);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001523 if (DEBUG_ICONS) Log.v(TAG, "Get cached weak drawable ref for "
1524 + name + ": " + wr);
1525 if (wr != null) { // we have the activity
Alan Viveretteecd585a2015-04-13 10:32:51 -07001526 final Drawable.ConstantState state = wr.get();
Romain Guy39fe17c2011-11-30 10:34:07 -08001527 if (state != null) {
1528 if (DEBUG_ICONS) {
1529 Log.v(TAG, "Get cached drawable state for " + name + ": " + state);
1530 }
1531 // Note: It's okay here to not use the newDrawable(Resources) variant
1532 // of the API. The ConstantState comes from a drawable that was
1533 // originally created by passing the proper app Resources instance
1534 // which means the state should already contain the proper
1535 // resources specific information (like density.) See
1536 // BitmapDrawable.BitmapState for instance.
1537 return state.newDrawable();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001538 }
1539 // our entry has been purged
1540 sIconCache.remove(name);
1541 }
1542 }
1543 return null;
1544 }
1545
Alan Viveretteecd585a2015-04-13 10:32:51 -07001546 private void putCachedIcon(@NonNull ResourceName name, @NonNull Drawable dr) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001547 synchronized (sSync) {
Alan Viveretteecd585a2015-04-13 10:32:51 -07001548 sIconCache.put(name, new WeakReference<>(dr.getConstantState()));
Romain Guy39fe17c2011-11-30 10:34:07 -08001549 if (DEBUG_ICONS) Log.v(TAG, "Added cached drawable state for " + name + ": " + dr);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001550 }
1551 }
1552
Romain Guy39fe17c2011-11-30 10:34:07 -08001553 static void handlePackageBroadcast(int cmd, String[] pkgList, boolean hasPkgInfo) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001554 boolean immediateGc = false;
Sudheer Shankacc6418f2016-10-13 12:03:44 -07001555 if (cmd == ApplicationThreadConstants.EXTERNAL_STORAGE_UNAVAILABLE) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001556 immediateGc = true;
1557 }
1558 if (pkgList != null && (pkgList.length > 0)) {
1559 boolean needCleanup = false;
1560 for (String ssp : pkgList) {
1561 synchronized (sSync) {
Dianne Hackbornadd005c2013-07-17 18:43:12 -07001562 for (int i=sIconCache.size()-1; i>=0; i--) {
1563 ResourceName nm = sIconCache.keyAt(i);
1564 if (nm.packageName.equals(ssp)) {
1565 //Log.i(TAG, "Removing cached drawable for " + nm);
1566 sIconCache.removeAt(i);
1567 needCleanup = true;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001568 }
1569 }
Dianne Hackbornadd005c2013-07-17 18:43:12 -07001570 for (int i=sStringCache.size()-1; i>=0; i--) {
1571 ResourceName nm = sStringCache.keyAt(i);
1572 if (nm.packageName.equals(ssp)) {
1573 //Log.i(TAG, "Removing cached string for " + nm);
1574 sStringCache.removeAt(i);
1575 needCleanup = true;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001576 }
1577 }
1578 }
1579 }
1580 if (needCleanup || hasPkgInfo) {
1581 if (immediateGc) {
1582 // Schedule an immediate gc.
1583 Runtime.getRuntime().gc();
1584 } else {
1585 ActivityThread.currentActivityThread().scheduleGcIdler();
1586 }
1587 }
1588 }
1589 }
1590
1591 private static final class ResourceName {
1592 final String packageName;
1593 final int iconId;
1594
1595 ResourceName(String _packageName, int _iconId) {
1596 packageName = _packageName;
1597 iconId = _iconId;
1598 }
1599
1600 ResourceName(ApplicationInfo aInfo, int _iconId) {
1601 this(aInfo.packageName, _iconId);
1602 }
1603
1604 ResourceName(ComponentInfo cInfo, int _iconId) {
1605 this(cInfo.applicationInfo.packageName, _iconId);
1606 }
1607
1608 ResourceName(ResolveInfo rInfo, int _iconId) {
1609 this(rInfo.activityInfo.applicationInfo.packageName, _iconId);
1610 }
1611
1612 @Override
1613 public boolean equals(Object o) {
1614 if (this == o) return true;
1615 if (o == null || getClass() != o.getClass()) return false;
1616
1617 ResourceName that = (ResourceName) o;
1618
1619 if (iconId != that.iconId) return false;
1620 return !(packageName != null ?
1621 !packageName.equals(that.packageName) : that.packageName != null);
1622
1623 }
1624
1625 @Override
1626 public int hashCode() {
1627 int result;
1628 result = packageName.hashCode();
1629 result = 31 * result + iconId;
1630 return result;
1631 }
1632
1633 @Override
1634 public String toString() {
1635 return "{ResourceName " + packageName + " / " + iconId + "}";
1636 }
1637 }
1638
1639 private CharSequence getCachedString(ResourceName name) {
1640 synchronized (sSync) {
1641 WeakReference<CharSequence> wr = sStringCache.get(name);
1642 if (wr != null) { // we have the activity
1643 CharSequence cs = wr.get();
1644 if (cs != null) {
1645 return cs;
1646 }
1647 // our entry has been purged
1648 sStringCache.remove(name);
1649 }
1650 }
1651 return null;
1652 }
1653
1654 private void putCachedString(ResourceName name, CharSequence cs) {
1655 synchronized (sSync) {
1656 sStringCache.put(name, new WeakReference<CharSequence>(cs));
1657 }
1658 }
1659
1660 @Override
Tor Norbye7b9c9122013-05-30 16:48:33 -07001661 public CharSequence getText(String packageName, @StringRes int resid,
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001662 ApplicationInfo appInfo) {
1663 ResourceName name = new ResourceName(packageName, resid);
1664 CharSequence text = getCachedString(name);
1665 if (text != null) {
1666 return text;
1667 }
1668 if (appInfo == null) {
1669 try {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001670 appInfo = getApplicationInfo(packageName, sDefaultFlags);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001671 } catch (NameNotFoundException e) {
1672 return null;
1673 }
1674 }
1675 try {
1676 Resources r = getResourcesForApplication(appInfo);
1677 text = r.getText(resid);
1678 putCachedString(name, text);
1679 return text;
1680 } catch (NameNotFoundException e) {
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07001681 Log.w("PackageManager", "Failure retrieving resources for "
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001682 + appInfo.packageName);
1683 } catch (RuntimeException e) {
1684 // If an exception was thrown, fall through to return
1685 // default icon.
1686 Log.w("PackageManager", "Failure retrieving text 0x"
1687 + Integer.toHexString(resid) + " in package "
1688 + packageName, e);
1689 }
1690 return null;
1691 }
1692
1693 @Override
Tor Norbye7b9c9122013-05-30 16:48:33 -07001694 public XmlResourceParser getXml(String packageName, @XmlRes int resid,
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001695 ApplicationInfo appInfo) {
1696 if (appInfo == null) {
1697 try {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001698 appInfo = getApplicationInfo(packageName, sDefaultFlags);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001699 } catch (NameNotFoundException e) {
1700 return null;
1701 }
1702 }
1703 try {
1704 Resources r = getResourcesForApplication(appInfo);
1705 return r.getXml(resid);
1706 } catch (RuntimeException e) {
1707 // If an exception was thrown, fall through to return
1708 // default icon.
1709 Log.w("PackageManager", "Failure retrieving xml 0x"
1710 + Integer.toHexString(resid) + " in package "
1711 + packageName, e);
1712 } catch (NameNotFoundException e) {
Alon Albert3fa51e32010-11-11 09:24:04 -08001713 Log.w("PackageManager", "Failure retrieving resources for "
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001714 + appInfo.packageName);
1715 }
1716 return null;
1717 }
1718
1719 @Override
1720 public CharSequence getApplicationLabel(ApplicationInfo info) {
1721 return info.loadLabel(this);
1722 }
1723
1724 @Override
Nicolas Prevot9a80e532015-09-23 15:49:28 +01001725 public int installExistingPackage(String packageName) throws NameNotFoundException {
Sunny Goyala31a74b2017-05-11 15:59:19 -07001726 return installExistingPackage(packageName, PackageManager.INSTALL_REASON_UNKNOWN);
1727 }
1728
1729 @Override
1730 public int installExistingPackage(String packageName, int installReason)
1731 throws NameNotFoundException {
1732 return installExistingPackageAsUser(packageName, installReason, mContext.getUserId());
Nicolas Prevot9a80e532015-09-23 15:49:28 +01001733 }
1734
1735 @Override
1736 public int installExistingPackageAsUser(String packageName, int userId)
Dianne Hackborn7767eac2012-08-23 18:25:40 -07001737 throws NameNotFoundException {
Sunny Goyala31a74b2017-05-11 15:59:19 -07001738 return installExistingPackageAsUser(packageName, PackageManager.INSTALL_REASON_UNKNOWN,
1739 userId);
1740 }
1741
1742 private int installExistingPackageAsUser(String packageName, int installReason, int userId)
1743 throws NameNotFoundException {
Dianne Hackborn7767eac2012-08-23 18:25:40 -07001744 try {
Todd Kennedybe0b8892017-02-15 14:13:52 -08001745 int res = mPM.installExistingPackageAsUser(packageName, userId, 0 /*installFlags*/,
Sunny Goyala31a74b2017-05-11 15:59:19 -07001746 installReason);
Dianne Hackborn7767eac2012-08-23 18:25:40 -07001747 if (res == INSTALL_FAILED_INVALID_URI) {
1748 throw new NameNotFoundException("Package " + packageName + " doesn't exist");
1749 }
1750 return res;
1751 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001752 throw e.rethrowFromSystemServer();
Dianne Hackborn7767eac2012-08-23 18:25:40 -07001753 }
1754 }
1755
1756 @Override
Kenny Root3a9b5fb2011-09-20 14:15:38 -07001757 public void verifyPendingInstall(int id, int response) {
Kenny Root5ab21572011-07-27 11:11:19 -07001758 try {
Kenny Root3a9b5fb2011-09-20 14:15:38 -07001759 mPM.verifyPendingInstall(id, response);
Kenny Root5ab21572011-07-27 11:11:19 -07001760 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001761 throw e.rethrowFromSystemServer();
Kenny Root5ab21572011-07-27 11:11:19 -07001762 }
1763 }
1764
1765 @Override
rich canningsd9ef3e52012-08-22 14:28:05 -07001766 public void extendVerificationTimeout(int id, int verificationCodeAtTimeout,
1767 long millisecondsToDelay) {
1768 try {
1769 mPM.extendVerificationTimeout(id, verificationCodeAtTimeout, millisecondsToDelay);
1770 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001771 throw e.rethrowFromSystemServer();
rich canningsd9ef3e52012-08-22 14:28:05 -07001772 }
1773 }
1774
1775 @Override
Todd Kennedydfa93ab2016-03-03 15:24:33 -08001776 public void verifyIntentFilter(int id, int verificationCode, List<String> failedDomains) {
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001777 try {
Todd Kennedydfa93ab2016-03-03 15:24:33 -08001778 mPM.verifyIntentFilter(id, verificationCode, failedDomains);
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001779 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001780 throw e.rethrowFromSystemServer();
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001781 }
1782 }
1783
1784 @Override
Jeff Sharkeye06b4d12016-01-06 14:51:50 -07001785 public int getIntentVerificationStatusAsUser(String packageName, int userId) {
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001786 try {
1787 return mPM.getIntentVerificationStatus(packageName, userId);
1788 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001789 throw e.rethrowFromSystemServer();
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001790 }
1791 }
1792
1793 @Override
Jeff Sharkeye06b4d12016-01-06 14:51:50 -07001794 public boolean updateIntentVerificationStatusAsUser(String packageName, int status, int userId) {
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001795 try {
1796 return mPM.updateIntentVerificationStatus(packageName, status, userId);
1797 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001798 throw e.rethrowFromSystemServer();
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001799 }
1800 }
1801
1802 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001803 @SuppressWarnings("unchecked")
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001804 public List<IntentFilterVerificationInfo> getIntentFilterVerifications(String packageName) {
1805 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001806 ParceledListSlice<IntentFilterVerificationInfo> parceledList =
1807 mPM.getIntentFilterVerifications(packageName);
1808 if (parceledList == null) {
1809 return Collections.emptyList();
1810 }
1811 return parceledList.getList();
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001812 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001813 throw e.rethrowFromSystemServer();
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001814 }
1815 }
1816
1817 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001818 @SuppressWarnings("unchecked")
Fabrice Di Meglio07885952015-04-06 19:41:28 -07001819 public List<IntentFilter> getAllIntentFilters(String packageName) {
1820 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001821 ParceledListSlice<IntentFilter> parceledList =
1822 mPM.getAllIntentFilters(packageName);
1823 if (parceledList == null) {
1824 return Collections.emptyList();
1825 }
1826 return parceledList.getList();
Fabrice Di Meglio07885952015-04-06 19:41:28 -07001827 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001828 throw e.rethrowFromSystemServer();
Fabrice Di Meglio07885952015-04-06 19:41:28 -07001829 }
1830 }
1831
1832 @Override
Jeff Sharkeye06b4d12016-01-06 14:51:50 -07001833 public String getDefaultBrowserPackageNameAsUser(int userId) {
Fabrice Di Meglio62271722015-04-10 17:24:02 -07001834 try {
1835 return mPM.getDefaultBrowserPackageName(userId);
1836 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001837 throw e.rethrowFromSystemServer();
Fabrice Di Meglio62271722015-04-10 17:24:02 -07001838 }
1839 }
1840
1841 @Override
Jeff Sharkeye06b4d12016-01-06 14:51:50 -07001842 public boolean setDefaultBrowserPackageNameAsUser(String packageName, int userId) {
Fabrice Di Meglio62271722015-04-10 17:24:02 -07001843 try {
1844 return mPM.setDefaultBrowserPackageName(packageName, userId);
1845 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001846 throw e.rethrowFromSystemServer();
Fabrice Di Meglio62271722015-04-10 17:24:02 -07001847 }
1848 }
1849
1850 @Override
Dianne Hackborn880119b2010-11-18 22:26:40 -08001851 public void setInstallerPackageName(String targetPackage,
1852 String installerPackageName) {
1853 try {
1854 mPM.setInstallerPackageName(targetPackage, installerPackageName);
1855 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001856 throw e.rethrowFromSystemServer();
Dianne Hackborn880119b2010-11-18 22:26:40 -08001857 }
1858 }
1859
1860 @Override
Todd Kennedyab532892017-03-08 14:19:49 -08001861 public void setUpdateAvailable(String packageName, boolean updateAvailable) {
1862 try {
1863 mPM.setUpdateAvailable(packageName, updateAvailable);
1864 } catch (RemoteException e) {
1865 throw e.rethrowFromSystemServer();
1866 }
1867 }
1868
1869 @Override
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001870 public String getInstallerPackageName(String packageName) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001871 try {
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001872 return mPM.getInstallerPackageName(packageName);
1873 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001874 throw e.rethrowFromSystemServer();
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001875 }
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001876 }
1877
1878 @Override
1879 public int getMoveStatus(int moveId) {
1880 try {
1881 return mPM.getMoveStatus(moveId);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001882 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001883 throw e.rethrowFromSystemServer();
Jeff Sharkeyb2b9ab82015-04-05 21:10:42 -07001884 }
1885 }
1886
1887 @Override
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001888 public void registerMoveCallback(MoveCallback callback, Handler handler) {
1889 synchronized (mDelegates) {
1890 final MoveCallbackDelegate delegate = new MoveCallbackDelegate(callback,
1891 handler.getLooper());
1892 try {
1893 mPM.registerMoveCallback(delegate);
1894 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001895 throw e.rethrowFromSystemServer();
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001896 }
1897 mDelegates.add(delegate);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001898 }
1899 }
1900
1901 @Override
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001902 public void unregisterMoveCallback(MoveCallback callback) {
1903 synchronized (mDelegates) {
1904 for (Iterator<MoveCallbackDelegate> i = mDelegates.iterator(); i.hasNext();) {
1905 final MoveCallbackDelegate delegate = i.next();
1906 if (delegate.mCallback == callback) {
1907 try {
1908 mPM.unregisterMoveCallback(delegate);
1909 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001910 throw e.rethrowFromSystemServer();
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001911 }
1912 i.remove();
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001913 }
1914 }
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001915 }
1916 }
1917
1918 @Override
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001919 public int movePackage(String packageName, VolumeInfo vol) {
1920 try {
1921 final String volumeUuid;
1922 if (VolumeInfo.ID_PRIVATE_INTERNAL.equals(vol.id)) {
1923 volumeUuid = StorageManager.UUID_PRIVATE_INTERNAL;
1924 } else if (vol.isPrimaryPhysical()) {
1925 volumeUuid = StorageManager.UUID_PRIMARY_PHYSICAL;
1926 } else {
1927 volumeUuid = Preconditions.checkNotNull(vol.fsUuid);
1928 }
1929
1930 return mPM.movePackage(packageName, volumeUuid);
1931 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001932 throw e.rethrowFromSystemServer();
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001933 }
1934 }
1935
1936 @Override
1937 public @Nullable VolumeInfo getPackageCurrentVolume(ApplicationInfo app) {
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001938 final StorageManager storage = mContext.getSystemService(StorageManager.class);
Yao Chen022b8ea2016-12-16 11:03:28 -08001939 return getPackageCurrentVolume(app, storage);
1940 }
1941
1942 @VisibleForTesting
1943 protected @Nullable VolumeInfo getPackageCurrentVolume(ApplicationInfo app,
1944 StorageManager storage) {
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001945 if (app.isInternal()) {
1946 return storage.findVolumeById(VolumeInfo.ID_PRIVATE_INTERNAL);
1947 } else if (app.isExternalAsec()) {
1948 return storage.getPrimaryPhysicalVolume();
1949 } else {
1950 return storage.findVolumeByUuid(app.volumeUuid);
1951 }
1952 }
1953
1954 @Override
1955 public @NonNull List<VolumeInfo> getPackageCandidateVolumes(ApplicationInfo app) {
Yao Chen022b8ea2016-12-16 11:03:28 -08001956 final StorageManager storageManager = mContext.getSystemService(StorageManager.class);
1957 return getPackageCandidateVolumes(app, storageManager, mPM);
1958 }
1959
1960 @VisibleForTesting
1961 protected @NonNull List<VolumeInfo> getPackageCandidateVolumes(ApplicationInfo app,
1962 StorageManager storageManager, IPackageManager pm) {
1963 final VolumeInfo currentVol = getPackageCurrentVolume(app, storageManager);
1964 final List<VolumeInfo> vols = storageManager.getVolumes();
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001965 final List<VolumeInfo> candidates = new ArrayList<>();
1966 for (VolumeInfo vol : vols) {
Yao Chen022b8ea2016-12-16 11:03:28 -08001967 if (Objects.equals(vol, currentVol)
1968 || isPackageCandidateVolume(mContext, app, vol, pm)) {
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001969 candidates.add(vol);
1970 }
1971 }
1972 return candidates;
1973 }
1974
Yao Chen022b8ea2016-12-16 11:03:28 -08001975 @VisibleForTesting
1976 protected boolean isForceAllowOnExternal(Context context) {
1977 return Settings.Global.getInt(
Todd Kennedyf39ca8f2015-08-07 14:15:07 -07001978 context.getContentResolver(), Settings.Global.FORCE_ALLOW_ON_EXTERNAL, 0) != 0;
Yao Chen022b8ea2016-12-16 11:03:28 -08001979 }
1980
1981 @VisibleForTesting
1982 protected boolean isAllow3rdPartyOnInternal(Context context) {
1983 return context.getResources().getBoolean(
1984 com.android.internal.R.bool.config_allow3rdPartyAppOnInternal);
1985 }
1986
1987 private boolean isPackageCandidateVolume(
1988 ContextImpl context, ApplicationInfo app, VolumeInfo vol, IPackageManager pm) {
1989 final boolean forceAllowOnExternal = isForceAllowOnExternal(context);
1990
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001991 if (VolumeInfo.ID_PRIVATE_INTERNAL.equals(vol.getId())) {
Yao Chen022b8ea2016-12-16 11:03:28 -08001992 return app.isSystemApp() || isAllow3rdPartyOnInternal(context);
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001993 }
1994
1995 // System apps and apps demanding internal storage can't be moved
1996 // anywhere else
Todd Kennedyf39ca8f2015-08-07 14:15:07 -07001997 if (app.isSystemApp()) {
1998 return false;
1999 }
2000 if (!forceAllowOnExternal
Dianne Hackborn30a4e6d2015-10-12 17:14:56 -07002001 && (app.installLocation == PackageInfo.INSTALL_LOCATION_INTERNAL_ONLY
2002 || app.installLocation == PackageInfo.INSTALL_LOCATION_UNSPECIFIED)) {
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07002003 return false;
2004 }
2005
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002006 // Gotta be able to write there
2007 if (!vol.isMountedWritable()) {
2008 return false;
2009 }
2010
2011 // Moving into an ASEC on public primary is only option internal
2012 if (vol.isPrimaryPhysical()) {
2013 return app.isInternal();
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07002014 }
2015
Makoto Onukif34db0a2016-02-17 11:17:15 -08002016 // Some apps can't be moved. (e.g. device admins)
2017 try {
Yao Chen022b8ea2016-12-16 11:03:28 -08002018 if (pm.isPackageDeviceAdminOnAnyUser(app.packageName)) {
Makoto Onukif34db0a2016-02-17 11:17:15 -08002019 return false;
2020 }
2021 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002022 throw e.rethrowFromSystemServer();
Makoto Onukif34db0a2016-02-17 11:17:15 -08002023 }
2024
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07002025 // Otherwise we can move to any private volume
2026 return (vol.getType() == VolumeInfo.TYPE_PRIVATE);
2027 }
2028
2029 @Override
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002030 public int movePrimaryStorage(VolumeInfo vol) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002031 try {
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002032 final String volumeUuid;
2033 if (VolumeInfo.ID_PRIVATE_INTERNAL.equals(vol.id)) {
2034 volumeUuid = StorageManager.UUID_PRIVATE_INTERNAL;
2035 } else if (vol.isPrimaryPhysical()) {
2036 volumeUuid = StorageManager.UUID_PRIMARY_PHYSICAL;
2037 } else {
2038 volumeUuid = Preconditions.checkNotNull(vol.fsUuid);
2039 }
2040
2041 return mPM.movePrimaryStorage(volumeUuid);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002042 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002043 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002044 }
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002045 }
2046
Jeff Sharkey275e3e42015-04-24 16:10:32 -07002047 @Override
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002048 public @Nullable VolumeInfo getPrimaryStorageCurrentVolume() {
2049 final StorageManager storage = mContext.getSystemService(StorageManager.class);
2050 final String volumeUuid = storage.getPrimaryStorageUuid();
Jeff Sharkey50a05452015-04-29 11:24:52 -07002051 return storage.findVolumeByQualifiedUuid(volumeUuid);
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002052 }
2053
Jeff Sharkey275e3e42015-04-24 16:10:32 -07002054 @Override
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002055 public @NonNull List<VolumeInfo> getPrimaryStorageCandidateVolumes() {
2056 final StorageManager storage = mContext.getSystemService(StorageManager.class);
2057 final VolumeInfo currentVol = getPrimaryStorageCurrentVolume();
2058 final List<VolumeInfo> vols = storage.getVolumes();
2059 final List<VolumeInfo> candidates = new ArrayList<>();
Jeff Sharkeyfced5342015-05-10 14:53:34 -07002060 if (Objects.equals(StorageManager.UUID_PRIMARY_PHYSICAL,
2061 storage.getPrimaryStorageUuid()) && currentVol != null) {
2062 // TODO: support moving primary physical to emulated volume
2063 candidates.add(currentVol);
2064 } else {
2065 for (VolumeInfo vol : vols) {
2066 if (Objects.equals(vol, currentVol) || isPrimaryStorageCandidateVolume(vol)) {
2067 candidates.add(vol);
2068 }
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002069 }
2070 }
2071 return candidates;
2072 }
2073
2074 private static boolean isPrimaryStorageCandidateVolume(VolumeInfo vol) {
2075 // Private internal is always an option
2076 if (VolumeInfo.ID_PRIVATE_INTERNAL.equals(vol.getId())) {
2077 return true;
2078 }
2079
2080 // Gotta be able to write there
2081 if (!vol.isMountedWritable()) {
2082 return false;
2083 }
2084
Jeff Sharkeyfced5342015-05-10 14:53:34 -07002085 // We can move to any private volume
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002086 return (vol.getType() == VolumeInfo.TYPE_PRIVATE);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002087 }
2088
2089 @Override
2090 public void deletePackage(String packageName, IPackageDeleteObserver observer, int flags) {
Robin Lee0e27c872015-09-28 14:37:40 +01002091 deletePackageAsUser(packageName, observer, flags, mContext.getUserId());
Nicolas Prevot9a80e532015-09-23 15:49:28 +01002092 }
2093
2094 @Override
Svet Ganov67882122016-12-11 16:36:34 -08002095 public void deletePackageAsUser(String packageName, IPackageDeleteObserver observer,
2096 int flags, int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002097 try {
Svet Ganov67882122016-12-11 16:36:34 -08002098 mPM.deletePackageAsUser(packageName, PackageManager.VERSION_CODE_HIGHEST,
2099 observer, userId, flags);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002100 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002101 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002102 }
2103 }
Jeff Sharkeyfbd0e9f2014-08-06 16:34:34 -07002104
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002105 @Override
2106 public void clearApplicationUserData(String packageName,
2107 IPackageDataObserver observer) {
2108 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -07002109 mPM.clearApplicationUserData(packageName, observer, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002110 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002111 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002112 }
2113 }
2114 @Override
2115 public void deleteApplicationCacheFiles(String packageName,
2116 IPackageDataObserver observer) {
2117 try {
2118 mPM.deleteApplicationCacheFiles(packageName, observer);
2119 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002120 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002121 }
2122 }
Jeff Sharkey529f91f2015-04-18 20:23:13 -07002123
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002124 @Override
Suprabh Shukla78c9eb82016-04-12 15:51:35 -07002125 public void deleteApplicationCacheFilesAsUser(String packageName, int userId,
2126 IPackageDataObserver observer) {
2127 try {
2128 mPM.deleteApplicationCacheFilesAsUser(packageName, userId, observer);
2129 } catch (RemoteException e) {
2130 throw e.rethrowFromSystemServer();
2131 }
2132 }
2133
2134 @Override
Jeff Sharkey529f91f2015-04-18 20:23:13 -07002135 public void freeStorageAndNotify(String volumeUuid, long idealStorageSize,
2136 IPackageDataObserver observer) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002137 try {
Jeff Sharkeyddff8072017-05-26 13:10:46 -06002138 mPM.freeStorageAndNotify(volumeUuid, idealStorageSize, 0, observer);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002139 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002140 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002141 }
2142 }
2143
2144 @Override
Jeff Sharkey529f91f2015-04-18 20:23:13 -07002145 public void freeStorage(String volumeUuid, long freeStorageSize, IntentSender pi) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002146 try {
Jeff Sharkeyddff8072017-05-26 13:10:46 -06002147 mPM.freeStorage(volumeUuid, freeStorageSize, 0, pi);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002148 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002149 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002150 }
2151 }
2152
2153 @Override
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00002154 public String[] setPackagesSuspendedAsUser(String[] packageNames, boolean suspended,
2155 int userId) {
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00002156 try {
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00002157 return mPM.setPackagesSuspendedAsUser(packageNames, suspended, userId);
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00002158 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002159 throw e.rethrowFromSystemServer();
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00002160 }
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00002161 }
2162
2163 @Override
Andrei Stingaceanu355b2322016-02-12 16:43:51 +00002164 public boolean isPackageSuspendedForUser(String packageName, int userId) {
2165 try {
2166 return mPM.isPackageSuspendedForUser(packageName, userId);
2167 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002168 throw e.rethrowFromSystemServer();
Andrei Stingaceanu355b2322016-02-12 16:43:51 +00002169 }
Andrei Stingaceanu355b2322016-02-12 16:43:51 +00002170 }
2171
Jeff Sharkey9bc89af2017-01-11 11:25:50 -07002172 /** @hide */
2173 @Override
2174 public void setApplicationCategoryHint(String packageName, int categoryHint) {
2175 try {
2176 mPM.setApplicationCategoryHint(packageName, categoryHint,
2177 mContext.getOpPackageName());
2178 } catch (RemoteException e) {
2179 throw e.rethrowFromSystemServer();
2180 }
2181 }
2182
Andrei Stingaceanu355b2322016-02-12 16:43:51 +00002183 @Override
Jeff Sharkeye06b4d12016-01-06 14:51:50 -07002184 public void getPackageSizeInfoAsUser(String packageName, int userHandle,
Dianne Hackborn0c380492012-08-20 17:23:30 -07002185 IPackageStatsObserver observer) {
Jeff Sharkey6f4b2a32017-03-21 14:13:41 -06002186 final String msg = "Shame on you for calling the hidden API "
2187 + "getPackageSizeInfoAsUser(). Shame!";
Jeff Sharkeye6306c42017-03-07 21:03:18 -07002188 if (mContext.getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.O) {
Jeff Sharkey6f4b2a32017-03-21 14:13:41 -06002189 throw new UnsupportedOperationException(msg);
Jeff Sharkeye6306c42017-03-07 21:03:18 -07002190 } else if (observer != null) {
Jeff Sharkey6f4b2a32017-03-21 14:13:41 -06002191 Log.d(TAG, msg);
Jeff Sharkeye6306c42017-03-07 21:03:18 -07002192 try {
2193 observer.onGetStatsCompleted(null, false);
2194 } catch (RemoteException ignored) {
2195 }
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002196 }
2197 }
Jeff Sharkeyd5896632016-03-04 16:16:00 -07002198
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002199 @Override
2200 public void addPackageToPreferred(String packageName) {
Jeff Sharkeyd5896632016-03-04 16:16:00 -07002201 Log.w(TAG, "addPackageToPreferred() is a no-op");
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002202 }
2203
2204 @Override
2205 public void removePackageFromPreferred(String packageName) {
Jeff Sharkeyd5896632016-03-04 16:16:00 -07002206 Log.w(TAG, "removePackageFromPreferred() is a no-op");
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002207 }
2208
2209 @Override
2210 public List<PackageInfo> getPreferredPackages(int flags) {
Jeff Sharkeyd5896632016-03-04 16:16:00 -07002211 Log.w(TAG, "getPreferredPackages() is a no-op");
2212 return Collections.emptyList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002213 }
2214
2215 @Override
2216 public void addPreferredActivity(IntentFilter filter,
2217 int match, ComponentName[] set, ComponentName activity) {
2218 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -07002219 mPM.addPreferredActivity(filter, match, set, activity, mContext.getUserId());
Amith Yamasania3f133a2012-08-09 17:11:28 -07002220 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002221 throw e.rethrowFromSystemServer();
Amith Yamasania3f133a2012-08-09 17:11:28 -07002222 }
2223 }
2224
2225 @Override
Jeff Sharkeye06b4d12016-01-06 14:51:50 -07002226 public void addPreferredActivityAsUser(IntentFilter filter, int match,
Amith Yamasania3f133a2012-08-09 17:11:28 -07002227 ComponentName[] set, ComponentName activity, int userId) {
2228 try {
2229 mPM.addPreferredActivity(filter, match, set, activity, userId);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002230 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002231 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002232 }
2233 }
2234
2235 @Override
2236 public void replacePreferredActivity(IntentFilter filter,
2237 int match, ComponentName[] set, ComponentName activity) {
2238 try {
Robin Lee0e27c872015-09-28 14:37:40 +01002239 mPM.replacePreferredActivity(filter, match, set, activity, mContext.getUserId());
Amith Yamasani41c1ded2014-08-05 11:15:05 -07002240 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002241 throw e.rethrowFromSystemServer();
Amith Yamasani41c1ded2014-08-05 11:15:05 -07002242 }
2243 }
2244
2245 @Override
2246 public void replacePreferredActivityAsUser(IntentFilter filter,
2247 int match, ComponentName[] set, ComponentName activity,
2248 int userId) {
2249 try {
2250 mPM.replacePreferredActivity(filter, match, set, activity, userId);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002251 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002252 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002253 }
2254 }
2255
2256 @Override
2257 public void clearPackagePreferredActivities(String packageName) {
2258 try {
2259 mPM.clearPackagePreferredActivities(packageName);
2260 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002261 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002262 }
2263 }
2264
2265 @Override
2266 public int getPreferredActivities(List<IntentFilter> outFilters,
2267 List<ComponentName> outActivities, String packageName) {
2268 try {
2269 return mPM.getPreferredActivities(outFilters, outActivities, packageName);
2270 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002271 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002272 }
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002273 }
2274
2275 @Override
Christopher Tatea2a0850d2013-09-05 16:38:58 -07002276 public ComponentName getHomeActivities(List<ResolveInfo> outActivities) {
2277 try {
2278 return mPM.getHomeActivities(outActivities);
2279 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002280 throw e.rethrowFromSystemServer();
Christopher Tatea2a0850d2013-09-05 16:38:58 -07002281 }
Christopher Tatea2a0850d2013-09-05 16:38:58 -07002282 }
2283
2284 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002285 public void setComponentEnabledSetting(ComponentName componentName,
2286 int newState, int flags) {
2287 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -07002288 mPM.setComponentEnabledSetting(componentName, newState, flags, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002289 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002290 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002291 }
2292 }
2293
2294 @Override
2295 public int getComponentEnabledSetting(ComponentName componentName) {
2296 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -07002297 return mPM.getComponentEnabledSetting(componentName, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002298 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002299 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002300 }
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002301 }
2302
2303 @Override
2304 public void setApplicationEnabledSetting(String packageName,
2305 int newState, int flags) {
2306 try {
Dianne Hackborn3fa3c28a2013-03-26 16:15:41 -07002307 mPM.setApplicationEnabledSetting(packageName, newState, flags,
Dianne Hackborn95d78532013-09-11 09:51:14 -07002308 mContext.getUserId(), mContext.getOpPackageName());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002309 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002310 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002311 }
2312 }
2313
2314 @Override
2315 public int getApplicationEnabledSetting(String packageName) {
2316 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -07002317 return mPM.getApplicationEnabledSetting(packageName, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002318 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002319 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002320 }
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002321 }
2322
Amith Yamasani655d0e22013-06-12 14:19:10 -07002323 @Override
Sudheer Shankabbb3ff22015-07-09 15:39:23 +01002324 public void flushPackageRestrictionsAsUser(int userId) {
2325 try {
2326 mPM.flushPackageRestrictionsAsUser(userId);
2327 } catch (RemoteException e) {
2328 throw e.rethrowFromSystemServer();
2329 }
2330 }
2331
2332 @Override
Amith Yamasanie5bcff62014-07-19 15:44:09 -07002333 public boolean setApplicationHiddenSettingAsUser(String packageName, boolean hidden,
Amith Yamasani655d0e22013-06-12 14:19:10 -07002334 UserHandle user) {
2335 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07002336 return mPM.setApplicationHiddenSettingAsUser(packageName, hidden,
Amith Yamasani655d0e22013-06-12 14:19:10 -07002337 user.getIdentifier());
Jeff Sharkey27b2e692016-02-25 17:40:12 -07002338 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002339 throw e.rethrowFromSystemServer();
Amith Yamasani655d0e22013-06-12 14:19:10 -07002340 }
Amith Yamasani655d0e22013-06-12 14:19:10 -07002341 }
2342
2343 @Override
Amith Yamasanie5bcff62014-07-19 15:44:09 -07002344 public boolean getApplicationHiddenSettingAsUser(String packageName, UserHandle user) {
Amith Yamasani655d0e22013-06-12 14:19:10 -07002345 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07002346 return mPM.getApplicationHiddenSettingAsUser(packageName, user.getIdentifier());
Jeff Sharkey27b2e692016-02-25 17:40:12 -07002347 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002348 throw e.rethrowFromSystemServer();
Amith Yamasani655d0e22013-06-12 14:19:10 -07002349 }
Amith Yamasani655d0e22013-06-12 14:19:10 -07002350 }
2351
dcashmanc6f22492014-08-14 09:54:51 -07002352 /** @hide */
dcashman9d2f4412014-06-09 09:27:54 -07002353 @Override
2354 public KeySet getKeySetByAlias(String packageName, String alias) {
2355 Preconditions.checkNotNull(packageName);
2356 Preconditions.checkNotNull(alias);
dcashman9d2f4412014-06-09 09:27:54 -07002357 try {
Jeff Sharkey27b2e692016-02-25 17:40:12 -07002358 return mPM.getKeySetByAlias(packageName, alias);
dcashman9d2f4412014-06-09 09:27:54 -07002359 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002360 throw e.rethrowFromSystemServer();
dcashman9d2f4412014-06-09 09:27:54 -07002361 }
dcashman9d2f4412014-06-09 09:27:54 -07002362 }
2363
dcashmanc6f22492014-08-14 09:54:51 -07002364 /** @hide */
dcashman9d2f4412014-06-09 09:27:54 -07002365 @Override
2366 public KeySet getSigningKeySet(String packageName) {
2367 Preconditions.checkNotNull(packageName);
dcashman9d2f4412014-06-09 09:27:54 -07002368 try {
Jeff Sharkey27b2e692016-02-25 17:40:12 -07002369 return mPM.getSigningKeySet(packageName);
dcashman9d2f4412014-06-09 09:27:54 -07002370 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002371 throw e.rethrowFromSystemServer();
dcashman9d2f4412014-06-09 09:27:54 -07002372 }
dcashman9d2f4412014-06-09 09:27:54 -07002373 }
2374
dcashmanc6f22492014-08-14 09:54:51 -07002375 /** @hide */
dcashman9d2f4412014-06-09 09:27:54 -07002376 @Override
2377 public boolean isSignedBy(String packageName, KeySet ks) {
2378 Preconditions.checkNotNull(packageName);
2379 Preconditions.checkNotNull(ks);
dcashman9d2f4412014-06-09 09:27:54 -07002380 try {
dcashmanc6f22492014-08-14 09:54:51 -07002381 return mPM.isPackageSignedByKeySet(packageName, ks);
dcashman9d2f4412014-06-09 09:27:54 -07002382 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002383 throw e.rethrowFromSystemServer();
dcashman9d2f4412014-06-09 09:27:54 -07002384 }
2385 }
2386
dcashmanc6f22492014-08-14 09:54:51 -07002387 /** @hide */
dcashman9d2f4412014-06-09 09:27:54 -07002388 @Override
2389 public boolean isSignedByExactly(String packageName, KeySet ks) {
2390 Preconditions.checkNotNull(packageName);
2391 Preconditions.checkNotNull(ks);
dcashman9d2f4412014-06-09 09:27:54 -07002392 try {
dcashmanc6f22492014-08-14 09:54:51 -07002393 return mPM.isPackageSignedByKeySetExactly(packageName, ks);
dcashman9d2f4412014-06-09 09:27:54 -07002394 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002395 throw e.rethrowFromSystemServer();
dcashman9d2f4412014-06-09 09:27:54 -07002396 }
2397 }
2398
Kenny Root0aaa0d92011-09-12 16:42:55 -07002399 /**
2400 * @hide
2401 */
2402 @Override
2403 public VerifierDeviceIdentity getVerifierDeviceIdentity() {
2404 try {
2405 return mPM.getVerifierDeviceIdentity();
2406 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002407 throw e.rethrowFromSystemServer();
Kenny Root0aaa0d92011-09-12 16:42:55 -07002408 }
Kenny Root0aaa0d92011-09-12 16:42:55 -07002409 }
2410
Jeff Hao9f60c082014-10-28 18:51:07 -07002411 /**
2412 * @hide
2413 */
2414 @Override
2415 public boolean isUpgrade() {
2416 try {
2417 return mPM.isUpgrade();
2418 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002419 throw e.rethrowFromSystemServer();
Jeff Hao9f60c082014-10-28 18:51:07 -07002420 }
2421 }
2422
Jeff Sharkey3a44f3f2014-04-28 17:36:31 -07002423 @Override
Jeff Sharkey16c8e3f2014-07-24 17:08:17 -07002424 public PackageInstaller getPackageInstaller() {
2425 synchronized (mLock) {
2426 if (mInstaller == null) {
2427 try {
Svet Ganov67882122016-12-11 16:36:34 -08002428 mInstaller = new PackageInstaller(mPM.getPackageInstaller(),
Jeff Sharkey16c8e3f2014-07-24 17:08:17 -07002429 mContext.getPackageName(), mContext.getUserId());
2430 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002431 throw e.rethrowFromSystemServer();
Jeff Sharkey16c8e3f2014-07-24 17:08:17 -07002432 }
2433 }
2434 return mInstaller;
Jeff Sharkey3a44f3f2014-04-28 17:36:31 -07002435 }
2436 }
2437
Jeff Sharkey6c833e02014-07-14 22:44:30 -07002438 @Override
2439 public boolean isPackageAvailable(String packageName) {
2440 try {
2441 return mPM.isPackageAvailable(packageName, mContext.getUserId());
2442 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002443 throw e.rethrowFromSystemServer();
Jeff Sharkey6c833e02014-07-14 22:44:30 -07002444 }
2445 }
2446
Nicolas Prevotc79586e2014-05-06 12:47:57 +01002447 /**
2448 * @hide
2449 */
2450 @Override
Nicolas Prevot63798c52014-05-27 13:22:38 +01002451 public void addCrossProfileIntentFilter(IntentFilter filter, int sourceUserId, int targetUserId,
2452 int flags) {
Nicolas Prevotc79586e2014-05-06 12:47:57 +01002453 try {
Nicolas Prevot3f7777f2014-07-24 15:58:39 +01002454 mPM.addCrossProfileIntentFilter(filter, mContext.getOpPackageName(),
Nicolas Prevot4b8d5822015-03-05 15:20:49 +00002455 sourceUserId, targetUserId, flags);
Nicolas Prevotc79586e2014-05-06 12:47:57 +01002456 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002457 throw e.rethrowFromSystemServer();
Nicolas Prevotc79586e2014-05-06 12:47:57 +01002458 }
2459 }
2460
2461 /**
2462 * @hide
2463 */
2464 @Override
Nicolas Prevot81948992014-05-16 18:25:26 +01002465 public void clearCrossProfileIntentFilters(int sourceUserId) {
Nicolas Prevotc79586e2014-05-06 12:47:57 +01002466 try {
Nicolas Prevot4b8d5822015-03-05 15:20:49 +00002467 mPM.clearCrossProfileIntentFilters(sourceUserId, mContext.getOpPackageName());
Nicolas Prevotc79586e2014-05-06 12:47:57 +01002468 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002469 throw e.rethrowFromSystemServer();
Nicolas Prevotc79586e2014-05-06 12:47:57 +01002470 }
2471 }
2472
Nicolas Prevot88cc3462014-05-14 14:51:48 +01002473 /**
2474 * @hide
2475 */
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +01002476 public Drawable loadItemIcon(PackageItemInfo itemInfo, ApplicationInfo appInfo) {
Benjamin Franzec2d48b2014-10-01 15:38:43 +01002477 Drawable dr = loadUnbadgedItemIcon(itemInfo, appInfo);
2478 if (itemInfo.showUserIcon != UserHandle.USER_NULL) {
2479 return dr;
2480 }
2481 return getUserBadgedIcon(dr, new UserHandle(mContext.getUserId()));
2482 }
2483
2484 /**
2485 * @hide
2486 */
2487 public Drawable loadUnbadgedItemIcon(PackageItemInfo itemInfo, ApplicationInfo appInfo) {
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +01002488 if (itemInfo.showUserIcon != UserHandle.USER_NULL) {
Alexandra Gherghina64d4dca2014-08-28 18:26:56 +01002489 Bitmap bitmap = getUserManager().getUserIcon(itemInfo.showUserIcon);
2490 if (bitmap == null) {
Tony Mak213955e2017-11-23 16:57:08 +08002491 return UserIcons.getDefaultUserIcon(
2492 mContext.getResources(), itemInfo.showUserIcon, /* light= */ false);
Alexandra Gherghina64d4dca2014-08-28 18:26:56 +01002493 }
2494 return new BitmapDrawable(bitmap);
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +01002495 }
Alexandra Gherghinadb811db2014-08-29 13:43:59 +01002496 Drawable dr = null;
2497 if (itemInfo.packageName != null) {
2498 dr = getDrawable(itemInfo.packageName, itemInfo.icon, appInfo);
2499 }
Alexandra Gherghinaa71e3902014-07-25 20:03:47 +01002500 if (dr == null) {
Alexandra Gherghinaa7093142014-07-30 13:43:39 +01002501 dr = itemInfo.loadDefaultIcon(this);
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +01002502 }
Benjamin Franzec2d48b2014-10-01 15:38:43 +01002503 return dr;
Svetoslavc7d62f02014-09-04 15:39:54 -07002504 }
2505
2506 private Drawable getBadgedDrawable(Drawable drawable, Drawable badgeDrawable,
2507 Rect badgeLocation, boolean tryBadgeInPlace) {
2508 final int badgedWidth = drawable.getIntrinsicWidth();
2509 final int badgedHeight = drawable.getIntrinsicHeight();
2510 final boolean canBadgeInPlace = tryBadgeInPlace
2511 && (drawable instanceof BitmapDrawable)
2512 && ((BitmapDrawable) drawable).getBitmap().isMutable();
2513
2514 final Bitmap bitmap;
2515 if (canBadgeInPlace) {
2516 bitmap = ((BitmapDrawable) drawable).getBitmap();
2517 } else {
2518 bitmap = Bitmap.createBitmap(badgedWidth, badgedHeight, Bitmap.Config.ARGB_8888);
2519 }
2520 Canvas canvas = new Canvas(bitmap);
2521
2522 if (!canBadgeInPlace) {
2523 drawable.setBounds(0, 0, badgedWidth, badgedHeight);
2524 drawable.draw(canvas);
2525 }
2526
2527 if (badgeLocation != null) {
2528 if (badgeLocation.left < 0 || badgeLocation.top < 0
2529 || badgeLocation.width() > badgedWidth || badgeLocation.height() > badgedHeight) {
2530 throw new IllegalArgumentException("Badge location " + badgeLocation
2531 + " not in badged drawable bounds "
2532 + new Rect(0, 0, badgedWidth, badgedHeight));
2533 }
2534 badgeDrawable.setBounds(0, 0, badgeLocation.width(), badgeLocation.height());
2535
2536 canvas.save();
2537 canvas.translate(badgeLocation.left, badgeLocation.top);
2538 badgeDrawable.draw(canvas);
2539 canvas.restore();
2540 } else {
2541 badgeDrawable.setBounds(0, 0, badgedWidth, badgedHeight);
2542 badgeDrawable.draw(canvas);
2543 }
2544
2545 if (!canBadgeInPlace) {
2546 BitmapDrawable mergedDrawable = new BitmapDrawable(mContext.getResources(), bitmap);
2547
2548 if (drawable instanceof BitmapDrawable) {
2549 BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
2550 mergedDrawable.setTargetDensity(bitmapDrawable.getBitmap().getDensity());
2551 }
2552
2553 return mergedDrawable;
2554 }
2555
2556 return drawable;
2557 }
2558
Tony Mak8673b282016-03-21 21:10:59 +00002559 private boolean isManagedProfile(int userId) {
2560 return getUserManager().isManagedProfile(userId);
Nicolas Prevot88cc3462014-05-14 14:51:48 +01002561 }
2562
Bartosz Fabianowskia34f53f2017-01-11 18:08:47 +01002563 /**
2564 * @hide
2565 */
2566 @Override
2567 public int getInstallReason(String packageName, UserHandle user) {
2568 try {
2569 return mPM.getInstallReason(packageName, user.getIdentifier());
2570 } catch (RemoteException e) {
2571 throw e.rethrowFromSystemServer();
2572 }
2573 }
2574
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002575 /** {@hide} */
2576 private static class MoveCallbackDelegate extends IPackageMoveObserver.Stub implements
2577 Handler.Callback {
Jeff Sharkey50a05452015-04-29 11:24:52 -07002578 private static final int MSG_CREATED = 1;
2579 private static final int MSG_STATUS_CHANGED = 2;
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002580
2581 final MoveCallback mCallback;
2582 final Handler mHandler;
2583
2584 public MoveCallbackDelegate(MoveCallback callback, Looper looper) {
2585 mCallback = callback;
2586 mHandler = new Handler(looper, this);
2587 }
2588
2589 @Override
2590 public boolean handleMessage(Message msg) {
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002591 switch (msg.what) {
Jeff Sharkey50a05452015-04-29 11:24:52 -07002592 case MSG_CREATED: {
Jeff Sharkeyb36586a2015-04-27 08:42:28 -07002593 final SomeArgs args = (SomeArgs) msg.obj;
Jeff Sharkey50a05452015-04-29 11:24:52 -07002594 mCallback.onCreated(args.argi1, (Bundle) args.arg2);
Jeff Sharkeyb36586a2015-04-27 08:42:28 -07002595 args.recycle();
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002596 return true;
Jeff Sharkey50a05452015-04-29 11:24:52 -07002597 }
2598 case MSG_STATUS_CHANGED: {
2599 final SomeArgs args = (SomeArgs) msg.obj;
2600 mCallback.onStatusChanged(args.argi1, args.argi2, (long) args.arg3);
2601 args.recycle();
2602 return true;
2603 }
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002604 }
2605 return false;
2606 }
2607
2608 @Override
Jeff Sharkey50a05452015-04-29 11:24:52 -07002609 public void onCreated(int moveId, Bundle extras) {
Jeff Sharkeyb36586a2015-04-27 08:42:28 -07002610 final SomeArgs args = SomeArgs.obtain();
2611 args.argi1 = moveId;
Jeff Sharkey50a05452015-04-29 11:24:52 -07002612 args.arg2 = extras;
2613 mHandler.obtainMessage(MSG_CREATED, args).sendToTarget();
2614 }
2615
2616 @Override
2617 public void onStatusChanged(int moveId, int status, long estMillis) {
2618 final SomeArgs args = SomeArgs.obtain();
2619 args.argi1 = moveId;
2620 args.argi2 = status;
2621 args.arg3 = estMillis;
Jeff Sharkeyb36586a2015-04-27 08:42:28 -07002622 mHandler.obtainMessage(MSG_STATUS_CHANGED, args).sendToTarget();
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002623 }
2624 }
2625
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002626 private final ContextImpl mContext;
2627 private final IPackageManager mPM;
2628
2629 private static final Object sSync = new Object();
Dianne Hackbornadd005c2013-07-17 18:43:12 -07002630 private static ArrayMap<ResourceName, WeakReference<Drawable.ConstantState>> sIconCache
2631 = new ArrayMap<ResourceName, WeakReference<Drawable.ConstantState>>();
2632 private static ArrayMap<ResourceName, WeakReference<CharSequence>> sStringCache
2633 = new ArrayMap<ResourceName, WeakReference<CharSequence>>();
Svetoslavf7c06eb2015-06-10 18:43:22 -07002634
2635 private final Map<OnPermissionsChangedListener, IOnPermissionsChangeListener>
2636 mPermissionListeners = new ArrayMap<>();
2637
2638 public class OnPermissionsChangeListenerDelegate extends IOnPermissionsChangeListener.Stub
2639 implements Handler.Callback{
2640 private static final int MSG_PERMISSIONS_CHANGED = 1;
2641
2642 private final OnPermissionsChangedListener mListener;
2643 private final Handler mHandler;
2644
2645
2646 public OnPermissionsChangeListenerDelegate(OnPermissionsChangedListener listener,
2647 Looper looper) {
2648 mListener = listener;
2649 mHandler = new Handler(looper, this);
2650 }
2651
2652 @Override
2653 public void onPermissionsChanged(int uid) {
2654 mHandler.obtainMessage(MSG_PERMISSIONS_CHANGED, uid, 0).sendToTarget();
2655 }
2656
2657 @Override
2658 public boolean handleMessage(Message msg) {
2659 switch (msg.what) {
2660 case MSG_PERMISSIONS_CHANGED: {
2661 final int uid = msg.arg1;
2662 mListener.onPermissionsChanged(uid);
2663 return true;
2664 }
2665 }
2666 return false;
2667 }
2668 }
Suprabh Shuklaaef25132017-01-23 18:09:03 -08002669
2670 @Override
2671 public boolean canRequestPackageInstalls() {
2672 try {
2673 return mPM.canRequestPackageInstalls(mContext.getPackageName(), mContext.getUserId());
2674 } catch (RemoteException e) {
2675 throw e.rethrowAsRuntimeException();
2676 }
2677 }
Chad Brubaker336ae5b2017-03-24 15:53:09 -07002678
2679 @Override
2680 public ComponentName getInstantAppResolverSettingsComponent() {
2681 try {
2682 return mPM.getInstantAppResolverSettingsComponent();
2683 } catch (RemoteException e) {
2684 throw e.rethrowAsRuntimeException();
2685 }
2686 }
Todd Kennedy801e6592017-04-12 14:10:12 -07002687
2688 @Override
2689 public ComponentName getInstantAppInstallerComponent() {
2690 try {
2691 return mPM.getInstantAppInstallerComponent();
2692 } catch (RemoteException e) {
2693 throw e.rethrowAsRuntimeException();
2694 }
2695 }
Chad Brubaker0d277a72017-04-12 16:56:53 -07002696
2697 @Override
2698 public String getInstantAppAndroidId(String packageName, UserHandle user) {
2699 try {
2700 return mPM.getInstantAppAndroidId(packageName, user.getIdentifier());
2701 } catch (RemoteException e) {
2702 throw e.rethrowAsRuntimeException();
2703 }
2704 }
Calin Juravle3d2af7f2017-04-19 19:56:21 -07002705
2706 private static class DexModuleRegisterResult {
2707 final String dexModulePath;
2708 final boolean success;
2709 final String message;
2710
2711 private DexModuleRegisterResult(String dexModulePath, boolean success, String message) {
2712 this.dexModulePath = dexModulePath;
2713 this.success = success;
2714 this.message = message;
2715 }
2716 }
2717
2718 private static class DexModuleRegisterCallbackDelegate
2719 extends android.content.pm.IDexModuleRegisterCallback.Stub
2720 implements Handler.Callback {
2721 private static final int MSG_DEX_MODULE_REGISTERED = 1;
2722 private final DexModuleRegisterCallback callback;
2723 private final Handler mHandler;
2724
2725 DexModuleRegisterCallbackDelegate(@NonNull DexModuleRegisterCallback callback) {
2726 this.callback = callback;
2727 mHandler = new Handler(Looper.getMainLooper(), this);
2728 }
2729
2730 @Override
2731 public void onDexModuleRegistered(@NonNull String dexModulePath, boolean success,
2732 @Nullable String message)throws RemoteException {
2733 mHandler.obtainMessage(MSG_DEX_MODULE_REGISTERED,
2734 new DexModuleRegisterResult(dexModulePath, success, message)).sendToTarget();
2735 }
2736
2737 @Override
2738 public boolean handleMessage(Message msg) {
2739 if (msg.what != MSG_DEX_MODULE_REGISTERED) {
2740 return false;
2741 }
2742 DexModuleRegisterResult result = (DexModuleRegisterResult)msg.obj;
2743 callback.onDexModuleRegistered(result.dexModulePath, result.success, result.message);
2744 return true;
2745 }
2746 }
2747
2748 @Override
2749 public void registerDexModule(@NonNull String dexModule,
2750 @Nullable DexModuleRegisterCallback callback) {
2751 // Check if this is a shared module by looking if the others can read it.
2752 boolean isSharedModule = false;
2753 try {
2754 StructStat stat = Os.stat(dexModule);
2755 if ((OsConstants.S_IROTH & stat.st_mode) != 0) {
2756 isSharedModule = true;
2757 }
2758 } catch (ErrnoException e) {
2759 callback.onDexModuleRegistered(dexModule, false,
2760 "Could not get stat the module file: " + e.getMessage());
2761 return;
2762 }
2763
2764 // Module path is ok.
2765 // Create the callback delegate to be passed to package manager service.
2766 DexModuleRegisterCallbackDelegate callbackDelegate = null;
2767 if (callback != null) {
2768 callbackDelegate = new DexModuleRegisterCallbackDelegate(callback);
2769 }
2770
2771 // Invoke the package manager service.
2772 try {
2773 mPM.registerDexModule(mContext.getPackageName(), dexModule,
2774 isSharedModule, callbackDelegate);
2775 } catch (RemoteException e) {
2776 throw e.rethrowAsRuntimeException();
2777 }
2778 }
Calin Juravle45f8b292017-11-07 18:49:43 -08002779
2780 @Override
Ben Gruver1ab3d6e2017-12-07 13:45:08 -08002781 public CharSequence getHarmfulAppWarning(String packageName) {
2782 try {
2783 return mPM.getHarmfulAppWarning(packageName, mContext.getUserId());
2784 } catch (RemoteException e) {
2785 throw e.rethrowAsRuntimeException();
2786 }
2787 }
2788
2789 @Override
2790 public void setHarmfulAppWarning(String packageName, CharSequence warning) {
2791 try {
2792 mPM.setHarmfulAppWarning(packageName, warning, mContext.getUserId());
2793 } catch (RemoteException e) {
2794 throw e.rethrowAsRuntimeException();
2795 }
2796 }
2797
2798 @Override
Calin Juravle45f8b292017-11-07 18:49:43 -08002799 public ArtManager getArtManager() {
2800 synchronized (mLock) {
2801 if (mArtManager == null) {
2802 try {
2803 mArtManager = new ArtManager(mPM.getArtManager());
2804 } catch (RemoteException e) {
2805 throw e.rethrowFromSystemServer();
2806 }
2807 }
2808 return mArtManager;
2809 }
2810 }
Makoto Onuki700feef2018-02-15 10:59:41 -08002811
2812 @Override
2813 public String getSystemTextClassifierPackageName() {
2814 try {
2815 return mPM.getSystemTextClassifierPackageName();
2816 } catch (RemoteException e) {
2817 throw e.rethrowAsRuntimeException();
2818 }
2819 }
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002820}