blob: 80ed0ea825f19a24b8101db049f16f599f95c350 [file] [log] [blame]
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001/*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.app;
18
Tor Norbye7b9c9122013-05-30 16:48:33 -070019import android.annotation.DrawableRes;
Alan Viveretteecd585a2015-04-13 10:32:51 -070020import android.annotation.NonNull;
21import android.annotation.Nullable;
Tor Norbye7b9c9122013-05-30 16:48:33 -070022import android.annotation.StringRes;
23import android.annotation.XmlRes;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080024import android.content.ComponentName;
25import android.content.ContentResolver;
Yao Chen022b8ea2016-12-16 11:03:28 -080026import android.content.Context;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080027import android.content.Intent;
28import android.content.IntentFilter;
29import android.content.IntentSender;
30import android.content.pm.ActivityInfo;
31import android.content.pm.ApplicationInfo;
Todd Kennedy9106c642017-02-08 14:16:53 -080032import android.content.pm.ChangedPackages;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080033import android.content.pm.ComponentInfo;
34import android.content.pm.FeatureInfo;
Svetoslavf7c06eb2015-06-10 18:43:22 -070035import android.content.pm.IOnPermissionsChangeListener;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080036import android.content.pm.IPackageDataObserver;
37import android.content.pm.IPackageDeleteObserver;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080038import android.content.pm.IPackageManager;
39import android.content.pm.IPackageMoveObserver;
40import android.content.pm.IPackageStatsObserver;
Todd Kennedy9da8b8a72017-07-25 15:38:39 -070041import android.content.pm.InstantAppInfo;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080042import android.content.pm.InstrumentationInfo;
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -080043import android.content.pm.IntentFilterVerificationInfo;
dcashman9d2f4412014-06-09 09:27:54 -070044import android.content.pm.KeySet;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080045import android.content.pm.PackageInfo;
Jeff Sharkey3a44f3f2014-04-28 17:36:31 -070046import android.content.pm.PackageInstaller;
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +010047import android.content.pm.PackageItemInfo;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080048import android.content.pm.PackageManager;
Kenny Roote6cd0c72011-05-19 12:48:14 -070049import android.content.pm.ParceledListSlice;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080050import android.content.pm.PermissionGroupInfo;
51import android.content.pm.PermissionInfo;
52import android.content.pm.ProviderInfo;
53import android.content.pm.ResolveInfo;
54import android.content.pm.ServiceInfo;
Svet Ganov67882122016-12-11 16:36:34 -080055import android.content.pm.SharedLibraryInfo;
Kenny Root0aaa0d92011-09-12 16:42:55 -070056import android.content.pm.VerifierDeviceIdentity;
Svet Ganov67882122016-12-11 16:36:34 -080057import android.content.pm.VersionedPackage;
Calin Juravle45f8b292017-11-07 18:49:43 -080058import android.content.pm.dex.ArtManager;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080059import android.content.res.Resources;
60import android.content.res.XmlResourceParser;
Svetoslavc7d62f02014-09-04 15:39:54 -070061import android.graphics.Bitmap;
62import android.graphics.Canvas;
63import android.graphics.Rect;
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +010064import android.graphics.drawable.BitmapDrawable;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080065import android.graphics.drawable.Drawable;
Kenny Guy02c89902016-11-15 19:36:38 +000066import android.graphics.drawable.LayerDrawable;
Jeff Sharkeye6306c42017-03-07 21:03:18 -070067import android.os.Build;
Jeff Sharkey50a05452015-04-29 11:24:52 -070068import android.os.Bundle;
Jeff Sharkey620b32b2015-04-23 19:36:02 -070069import android.os.Handler;
70import android.os.Looper;
71import android.os.Message;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080072import android.os.Process;
73import android.os.RemoteException;
Jeff Sharkeyb2b9ab82015-04-05 21:10:42 -070074import android.os.SystemProperties;
Amith Yamasani67df64b2012-12-14 12:09:36 -080075import android.os.UserHandle;
Nicolas Prevot88cc3462014-05-14 14:51:48 +010076import android.os.UserManager;
Jeff Sharkeye2d45be2015-04-15 17:14:12 -070077import android.os.storage.StorageManager;
78import android.os.storage.VolumeInfo;
Todd Kennedyf39ca8f2015-08-07 14:15:07 -070079import android.provider.Settings;
Calin Juravle3d2af7f2017-04-19 19:56:21 -070080import android.system.ErrnoException;
81import android.system.Os;
82import android.system.OsConstants;
83import android.system.StructStat;
Dianne Hackbornadd005c2013-07-17 18:43:12 -070084import android.util.ArrayMap;
Sunny Goyalbab30752017-04-12 15:36:42 -070085import android.util.IconDrawableFactory;
86import android.util.LauncherIcons;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080087import android.util.Log;
Jeff Browna492c3a2012-08-23 19:48:44 -070088import android.view.Display;
Jeff Sharkeyb2b9ab82015-04-05 21:10:42 -070089
Jeff Sharkey16c8e3f2014-07-24 17:08:17 -070090import com.android.internal.annotations.GuardedBy;
Kenny Guy02c89902016-11-15 19:36:38 +000091import com.android.internal.annotations.VisibleForTesting;
Jeff Sharkeyb36586a2015-04-27 08:42:28 -070092import com.android.internal.os.SomeArgs;
dcashman9d2f4412014-06-09 09:27:54 -070093import com.android.internal.util.Preconditions;
Alexandra Gherghina64d4dca2014-08-28 18:26:56 +010094import com.android.internal.util.UserIcons;
Todd Kennedy9da8b8a72017-07-25 15:38:39 -070095
96import dalvik.system.VMRuntime;
97
Svet Ganov2acf0632015-11-24 19:10:59 -080098import libcore.util.EmptyArray;
Jeff Sharkey16c8e3f2014-07-24 17:08:17 -070099
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800100import java.lang.ref.WeakReference;
101import java.util.ArrayList;
Svet Ganov2acf0632015-11-24 19:10:59 -0800102import java.util.Collections;
Jeff Sharkey620b32b2015-04-23 19:36:02 -0700103import java.util.Iterator;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800104import java.util.List;
Svetoslavf7c06eb2015-06-10 18:43:22 -0700105import java.util.Map;
Jeff Sharkey620b32b2015-04-23 19:36:02 -0700106import java.util.Objects;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800107
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700108/** @hide */
109public class ApplicationPackageManager extends PackageManager {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800110 private static final String TAG = "ApplicationPackageManager";
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800111 private final static boolean DEBUG_ICONS = false;
112
Svet Ganov2acf0632015-11-24 19:10:59 -0800113 private static final int DEFAULT_EPHEMERAL_COOKIE_MAX_SIZE_BYTES = 16384; // 16KB
114
Adam Lesinskid00bb5e2014-10-07 12:14:45 -0700115 // Default flags to use with PackageManager when no flags are given.
116 private final static int sDefaultFlags = PackageManager.GET_SHARED_LIBRARY_FILES;
117
Jeff Sharkey16c8e3f2014-07-24 17:08:17 -0700118 private final Object mLock = new Object();
119
120 @GuardedBy("mLock")
121 private UserManager mUserManager;
122 @GuardedBy("mLock")
123 private PackageInstaller mInstaller;
Calin Juravle45f8b292017-11-07 18:49:43 -0800124 @GuardedBy("mLock")
125 private ArtManager mArtManager;
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +0100126
Jeff Sharkey620b32b2015-04-23 19:36:02 -0700127 @GuardedBy("mDelegates")
128 private final ArrayList<MoveCallbackDelegate> mDelegates = new ArrayList<>();
129
Svet Ganovf1b7f202015-07-29 08:33:42 -0700130 @GuardedBy("mLock")
131 private String mPermissionsControllerPackageName;
132
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +0100133 UserManager getUserManager() {
Jeff Sharkey16c8e3f2014-07-24 17:08:17 -0700134 synchronized (mLock) {
135 if (mUserManager == null) {
136 mUserManager = UserManager.get(mContext);
137 }
138 return mUserManager;
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +0100139 }
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +0100140 }
141
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800142 @Override
Jeff Sharkeyad357d12018-02-02 13:25:31 -0700143 public int getUserId() {
144 return mContext.getUserId();
145 }
146
147 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800148 public PackageInfo getPackageInfo(String packageName, int flags)
149 throws NameNotFoundException {
Nicolas Prevot9a80e532015-09-23 15:49:28 +0100150 return getPackageInfoAsUser(packageName, flags, mContext.getUserId());
151 }
152
153 @Override
Svet Ganov67882122016-12-11 16:36:34 -0800154 public PackageInfo getPackageInfo(VersionedPackage versionedPackage, int flags)
155 throws NameNotFoundException {
156 try {
157 PackageInfo pi = mPM.getPackageInfoVersioned(versionedPackage, flags,
158 mContext.getUserId());
159 if (pi != null) {
160 return pi;
161 }
162 } catch (RemoteException e) {
163 throw e.rethrowFromSystemServer();
164 }
165 throw new NameNotFoundException(versionedPackage.toString());
166 }
167
168 @Override
Nicolas Prevot9a80e532015-09-23 15:49:28 +0100169 public PackageInfo getPackageInfoAsUser(String packageName, int flags, int userId)
170 throws NameNotFoundException {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800171 try {
Nicolas Prevot9a80e532015-09-23 15:49:28 +0100172 PackageInfo pi = mPM.getPackageInfo(packageName, flags, userId);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800173 if (pi != null) {
174 return pi;
175 }
176 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700177 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800178 }
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800179 throw new NameNotFoundException(packageName);
180 }
181
182 @Override
183 public String[] currentToCanonicalPackageNames(String[] names) {
184 try {
185 return mPM.currentToCanonicalPackageNames(names);
186 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700187 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800188 }
189 }
190
191 @Override
192 public String[] canonicalToCurrentPackageNames(String[] names) {
193 try {
194 return mPM.canonicalToCurrentPackageNames(names);
195 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700196 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800197 }
198 }
199
200 @Override
201 public Intent getLaunchIntentForPackage(String packageName) {
202 // First see if the package has an INFO activity; the existence of
203 // such an activity is implied to be the desired front-door for the
204 // overall package (such as if it has multiple launcher entries).
205 Intent intentToResolve = new Intent(Intent.ACTION_MAIN);
206 intentToResolve.addCategory(Intent.CATEGORY_INFO);
207 intentToResolve.setPackage(packageName);
Dianne Hackborn19415762010-12-15 00:20:27 -0800208 List<ResolveInfo> ris = queryIntentActivities(intentToResolve, 0);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800209
210 // Otherwise, try to find a main launcher activity.
Dianne Hackborn19415762010-12-15 00:20:27 -0800211 if (ris == null || ris.size() <= 0) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800212 // reuse the intent instance
213 intentToResolve.removeCategory(Intent.CATEGORY_INFO);
214 intentToResolve.addCategory(Intent.CATEGORY_LAUNCHER);
215 intentToResolve.setPackage(packageName);
Dianne Hackborn19415762010-12-15 00:20:27 -0800216 ris = queryIntentActivities(intentToResolve, 0);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800217 }
Dianne Hackborn19415762010-12-15 00:20:27 -0800218 if (ris == null || ris.size() <= 0) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800219 return null;
220 }
221 Intent intent = new Intent(intentToResolve);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800222 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Dianne Hackborn19415762010-12-15 00:20:27 -0800223 intent.setClassName(ris.get(0).activityInfo.packageName,
224 ris.get(0).activityInfo.name);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800225 return intent;
226 }
227
228 @Override
Jose Lima970417c2014-04-10 10:42:19 -0700229 public Intent getLeanbackLaunchIntentForPackage(String packageName) {
Roberto Perez7ee1a7a2017-12-04 17:14:33 -0800230 return getLaunchIntentForPackageAndCategory(packageName, Intent.CATEGORY_LEANBACK_LAUNCHER);
231 }
232
233 @Override
234 public Intent getCarLaunchIntentForPackage(String packageName) {
235 return getLaunchIntentForPackageAndCategory(packageName, Intent.CATEGORY_CAR_LAUNCHER);
236 }
237
238 private Intent getLaunchIntentForPackageAndCategory(String packageName, String category) {
239 // Try to find a main launcher activity for the given categories.
Jose Lima970417c2014-04-10 10:42:19 -0700240 Intent intentToResolve = new Intent(Intent.ACTION_MAIN);
Roberto Perez7ee1a7a2017-12-04 17:14:33 -0800241 intentToResolve.addCategory(category);
Jose Lima970417c2014-04-10 10:42:19 -0700242 intentToResolve.setPackage(packageName);
243 List<ResolveInfo> ris = queryIntentActivities(intentToResolve, 0);
244
245 if (ris == null || ris.size() <= 0) {
246 return null;
247 }
248 Intent intent = new Intent(intentToResolve);
249 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
250 intent.setClassName(ris.get(0).activityInfo.packageName,
251 ris.get(0).activityInfo.name);
252 return intent;
253 }
254
255 @Override
Jeff Sharkey8588bc12016-01-06 16:47:42 -0700256 public int[] getPackageGids(String packageName) throws NameNotFoundException {
257 return getPackageGids(packageName, 0);
258 }
259
260 @Override
261 public int[] getPackageGids(String packageName, int flags)
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800262 throws NameNotFoundException {
263 try {
Jeff Sharkeycd654482016-01-08 17:42:11 -0700264 int[] gids = mPM.getPackageGids(packageName, flags, mContext.getUserId());
Svetoslavc6d1c342015-02-26 14:44:43 -0800265 if (gids != null) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800266 return gids;
267 }
268 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700269 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800270 }
271
272 throw new NameNotFoundException(packageName);
273 }
274
275 @Override
Jeff Sharkey8588bc12016-01-06 16:47:42 -0700276 public int getPackageUid(String packageName, int flags) throws NameNotFoundException {
277 return getPackageUidAsUser(packageName, flags, mContext.getUserId());
278 }
279
280 @Override
281 public int getPackageUidAsUser(String packageName, int userId) throws NameNotFoundException {
282 return getPackageUidAsUser(packageName, 0, userId);
283 }
284
285 @Override
286 public int getPackageUidAsUser(String packageName, int flags, int userId)
Dianne Hackborna06de0f2012-12-11 16:34:47 -0800287 throws NameNotFoundException {
288 try {
Jeff Sharkeycd654482016-01-08 17:42:11 -0700289 int uid = mPM.getPackageUid(packageName, flags, userId);
Dianne Hackborna06de0f2012-12-11 16:34:47 -0800290 if (uid >= 0) {
291 return uid;
292 }
293 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700294 throw e.rethrowFromSystemServer();
Dianne Hackborna06de0f2012-12-11 16:34:47 -0800295 }
296
297 throw new NameNotFoundException(packageName);
298 }
299
300 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800301 public PermissionInfo getPermissionInfo(String name, int flags)
302 throws NameNotFoundException {
303 try {
Svetoslav Ganovadb8c522017-07-28 05:46:53 +0000304 PermissionInfo pi = mPM.getPermissionInfo(name,
305 mContext.getOpPackageName(), flags);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800306 if (pi != null) {
307 return pi;
308 }
309 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700310 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800311 }
312
313 throw new NameNotFoundException(name);
314 }
315
316 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700317 @SuppressWarnings("unchecked")
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800318 public List<PermissionInfo> queryPermissionsByGroup(String group, int flags)
319 throws NameNotFoundException {
320 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700321 ParceledListSlice<PermissionInfo> parceledList =
322 mPM.queryPermissionsByGroup(group, flags);
323 if (parceledList != null) {
324 List<PermissionInfo> pi = parceledList.getList();
325 if (pi != null) {
326 return pi;
327 }
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800328 }
329 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700330 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800331 }
332
333 throw new NameNotFoundException(group);
334 }
335
336 @Override
Paul Navin7b89a7b2017-01-26 23:56:08 +0000337 public boolean isPermissionReviewModeEnabled() {
338 return mContext.getResources().getBoolean(
339 com.android.internal.R.bool.config_permissionReviewRequired);
340 }
341
342 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800343 public PermissionGroupInfo getPermissionGroupInfo(String name,
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700344 int flags) throws NameNotFoundException {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800345 try {
346 PermissionGroupInfo pgi = mPM.getPermissionGroupInfo(name, flags);
347 if (pgi != null) {
348 return pgi;
349 }
350 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700351 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800352 }
353
354 throw new NameNotFoundException(name);
355 }
356
357 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700358 @SuppressWarnings("unchecked")
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800359 public List<PermissionGroupInfo> getAllPermissionGroups(int flags) {
360 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700361 ParceledListSlice<PermissionGroupInfo> parceledList =
362 mPM.getAllPermissionGroups(flags);
363 if (parceledList == null) {
364 return Collections.emptyList();
365 }
366 return parceledList.getList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800367 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700368 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800369 }
370 }
371
372 @Override
373 public ApplicationInfo getApplicationInfo(String packageName, int flags)
374 throws NameNotFoundException {
Jeff Sharkeycd654482016-01-08 17:42:11 -0700375 return getApplicationInfoAsUser(packageName, flags, mContext.getUserId());
376 }
377
378 @Override
379 public ApplicationInfo getApplicationInfoAsUser(String packageName, int flags, int userId)
380 throws NameNotFoundException {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800381 try {
Jeff Sharkeycd654482016-01-08 17:42:11 -0700382 ApplicationInfo ai = mPM.getApplicationInfo(packageName, flags, userId);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800383 if (ai != null) {
Narayan Kamathcaa71192014-07-16 11:06:43 +0100384 // This is a temporary hack. Callers must use
385 // createPackageContext(packageName).getApplicationInfo() to
386 // get the right paths.
Tao Baic9a02372016-01-12 15:02:24 -0800387 return maybeAdjustApplicationInfo(ai);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800388 }
389 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700390 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800391 }
392
393 throw new NameNotFoundException(packageName);
394 }
395
Tao Baic9a02372016-01-12 15:02:24 -0800396 private static ApplicationInfo maybeAdjustApplicationInfo(ApplicationInfo info) {
Narayan Kamathcaa71192014-07-16 11:06:43 +0100397 // If we're dealing with a multi-arch application that has both
398 // 32 and 64 bit shared libraries, we might need to choose the secondary
399 // depending on what the current runtime's instruction set is.
400 if (info.primaryCpuAbi != null && info.secondaryCpuAbi != null) {
401 final String runtimeIsa = VMRuntime.getRuntime().vmInstructionSet();
jgu214741cd92014-12-17 17:23:29 -0500402
403 // Get the instruction set that the libraries of secondary Abi is supported.
404 // In presence of a native bridge this might be different than the one secondary Abi used.
405 String secondaryIsa = VMRuntime.getInstructionSet(info.secondaryCpuAbi);
406 final String secondaryDexCodeIsa = SystemProperties.get("ro.dalvik.vm.isa." + secondaryIsa);
407 secondaryIsa = secondaryDexCodeIsa.isEmpty() ? secondaryIsa : secondaryDexCodeIsa;
Narayan Kamathcaa71192014-07-16 11:06:43 +0100408
409 // If the runtimeIsa is the same as the primary isa, then we do nothing.
410 // Everything will be set up correctly because info.nativeLibraryDir will
411 // correspond to the right ISA.
412 if (runtimeIsa.equals(secondaryIsa)) {
Tao Baic9a02372016-01-12 15:02:24 -0800413 ApplicationInfo modified = new ApplicationInfo(info);
414 modified.nativeLibraryDir = info.secondaryNativeLibraryDir;
415 return modified;
Narayan Kamathcaa71192014-07-16 11:06:43 +0100416 }
417 }
Tao Baic9a02372016-01-12 15:02:24 -0800418 return info;
Narayan Kamathcaa71192014-07-16 11:06:43 +0100419 }
420
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800421 @Override
422 public ActivityInfo getActivityInfo(ComponentName className, int flags)
423 throws NameNotFoundException {
424 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700425 ActivityInfo ai = mPM.getActivityInfo(className, flags, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800426 if (ai != null) {
427 return ai;
428 }
429 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700430 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800431 }
432
433 throw new NameNotFoundException(className.toString());
434 }
435
436 @Override
437 public ActivityInfo getReceiverInfo(ComponentName className, int flags)
438 throws NameNotFoundException {
439 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700440 ActivityInfo ai = mPM.getReceiverInfo(className, flags, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800441 if (ai != null) {
442 return ai;
443 }
444 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700445 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800446 }
447
448 throw new NameNotFoundException(className.toString());
449 }
450
451 @Override
452 public ServiceInfo getServiceInfo(ComponentName className, int flags)
453 throws NameNotFoundException {
454 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700455 ServiceInfo si = mPM.getServiceInfo(className, flags, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800456 if (si != null) {
457 return si;
458 }
459 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700460 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800461 }
462
463 throw new NameNotFoundException(className.toString());
464 }
465
466 @Override
467 public ProviderInfo getProviderInfo(ComponentName className, int flags)
468 throws NameNotFoundException {
469 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700470 ProviderInfo pi = mPM.getProviderInfo(className, flags, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800471 if (pi != null) {
472 return pi;
473 }
474 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700475 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800476 }
477
478 throw new NameNotFoundException(className.toString());
479 }
480
481 @Override
482 public String[] getSystemSharedLibraryNames() {
483 try {
484 return mPM.getSystemSharedLibraryNames();
485 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700486 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800487 }
488 }
489
Svet Ganovd7b1f4112016-02-09 18:49:23 -0800490 /** @hide */
491 @Override
Svet Ganov67882122016-12-11 16:36:34 -0800492 public @NonNull List<SharedLibraryInfo> getSharedLibraries(int flags) {
493 return getSharedLibrariesAsUser(flags, mContext.getUserId());
494 }
495
496 /** @hide */
497 @Override
498 @SuppressWarnings("unchecked")
499 public @NonNull List<SharedLibraryInfo> getSharedLibrariesAsUser(int flags, int userId) {
500 try {
501 ParceledListSlice<SharedLibraryInfo> sharedLibs = mPM.getSharedLibraries(
Svet Ganov58c99f02017-05-15 14:07:17 -0700502 mContext.getOpPackageName(), flags, userId);
Svet Ganov67882122016-12-11 16:36:34 -0800503 if (sharedLibs == null) {
504 return Collections.emptyList();
505 }
506 return sharedLibs.getList();
507 } catch (RemoteException e) {
508 throw e.rethrowFromSystemServer();
509 }
510 }
511
512 /** @hide */
513 @Override
Svetoslav Ganova9c25002016-04-13 19:25:56 -0700514 public @NonNull String getServicesSystemSharedLibraryPackageName() {
Svet Ganovd7b1f4112016-02-09 18:49:23 -0800515 try {
516 return mPM.getServicesSystemSharedLibraryPackageName();
517 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700518 throw e.rethrowFromSystemServer();
Svet Ganovd7b1f4112016-02-09 18:49:23 -0800519 }
520 }
521
Svetoslav Ganova9c25002016-04-13 19:25:56 -0700522 /**
523 * @hide
524 */
525 public @NonNull String getSharedSystemSharedLibraryPackageName() {
526 try {
527 return mPM.getSharedSystemSharedLibraryPackageName();
528 } catch (RemoteException e) {
529 throw e.rethrowFromSystemServer();
530 }
531 }
532
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800533 @Override
Todd Kennedy9106c642017-02-08 14:16:53 -0800534 public ChangedPackages getChangedPackages(int sequenceNumber) {
535 try {
536 return mPM.getChangedPackages(sequenceNumber, mContext.getUserId());
537 } catch (RemoteException e) {
538 throw e.rethrowFromSystemServer();
539 }
540 }
541
542 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700543 @SuppressWarnings("unchecked")
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800544 public FeatureInfo[] getSystemAvailableFeatures() {
545 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700546 ParceledListSlice<FeatureInfo> parceledList =
547 mPM.getSystemAvailableFeatures();
548 if (parceledList == null) {
549 return new FeatureInfo[0];
550 }
551 final List<FeatureInfo> list = parceledList.getList();
Jeff Sharkeyd5896632016-03-04 16:16:00 -0700552 final FeatureInfo[] res = new FeatureInfo[list.size()];
553 for (int i = 0; i < res.length; i++) {
554 res[i] = list.get(i);
555 }
556 return res;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800557 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700558 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800559 }
560 }
561
562 @Override
563 public boolean hasSystemFeature(String name) {
Jeff Sharkey115d2c12016-02-15 17:25:57 -0700564 return hasSystemFeature(name, 0);
565 }
566
567 @Override
568 public boolean hasSystemFeature(String name, int version) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800569 try {
Jeff Sharkey115d2c12016-02-15 17:25:57 -0700570 return mPM.hasSystemFeature(name, version);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800571 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700572 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800573 }
574 }
575
576 @Override
577 public int checkPermission(String permName, String pkgName) {
578 try {
Svetoslavc6d1c342015-02-26 14:44:43 -0800579 return mPM.checkPermission(permName, pkgName, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800580 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700581 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800582 }
583 }
584
585 @Override
Svet Ganovad3b2972015-07-07 22:49:17 -0700586 public boolean isPermissionRevokedByPolicy(String permName, String pkgName) {
587 try {
588 return mPM.isPermissionRevokedByPolicy(permName, pkgName, mContext.getUserId());
589 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700590 throw e.rethrowFromSystemServer();
Svet Ganovad3b2972015-07-07 22:49:17 -0700591 }
592 }
593
Svet Ganovf1b7f202015-07-29 08:33:42 -0700594 /**
595 * @hide
596 */
597 @Override
598 public String getPermissionControllerPackageName() {
599 synchronized (mLock) {
600 if (mPermissionsControllerPackageName == null) {
601 try {
602 mPermissionsControllerPackageName = mPM.getPermissionControllerPackageName();
603 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700604 throw e.rethrowFromSystemServer();
Svet Ganovf1b7f202015-07-29 08:33:42 -0700605 }
606 }
607 return mPermissionsControllerPackageName;
608 }
609 }
610
Svet Ganovad3b2972015-07-07 22:49:17 -0700611 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800612 public boolean addPermission(PermissionInfo info) {
613 try {
614 return mPM.addPermission(info);
615 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700616 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800617 }
618 }
619
620 @Override
621 public boolean addPermissionAsync(PermissionInfo info) {
622 try {
623 return mPM.addPermissionAsync(info);
624 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700625 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800626 }
627 }
628
629 @Override
630 public void removePermission(String name) {
631 try {
632 mPM.removePermission(name);
633 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700634 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800635 }
636 }
637
638 @Override
Svet Ganov8c7f7002015-05-07 10:48:44 -0700639 public void grantRuntimePermission(String packageName, String permissionName,
640 UserHandle user) {
Dianne Hackborne639da72012-02-21 15:11:13 -0800641 try {
Svet Ganov8c7f7002015-05-07 10:48:44 -0700642 mPM.grantRuntimePermission(packageName, permissionName, user.getIdentifier());
Dianne Hackborne639da72012-02-21 15:11:13 -0800643 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700644 throw e.rethrowFromSystemServer();
Dianne Hackborne639da72012-02-21 15:11:13 -0800645 }
646 }
647
648 @Override
Svet Ganov8c7f7002015-05-07 10:48:44 -0700649 public void revokeRuntimePermission(String packageName, String permissionName,
650 UserHandle user) {
Dianne Hackborne639da72012-02-21 15:11:13 -0800651 try {
Svet Ganov8c7f7002015-05-07 10:48:44 -0700652 mPM.revokeRuntimePermission(packageName, permissionName, user.getIdentifier());
653 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700654 throw e.rethrowFromSystemServer();
Svet Ganov8c7f7002015-05-07 10:48:44 -0700655 }
656 }
657
658 @Override
659 public int getPermissionFlags(String permissionName, String packageName, UserHandle user) {
660 try {
661 return mPM.getPermissionFlags(permissionName, packageName, user.getIdentifier());
662 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700663 throw e.rethrowFromSystemServer();
Svet Ganov8c7f7002015-05-07 10:48:44 -0700664 }
665 }
666
667 @Override
668 public void updatePermissionFlags(String permissionName, String packageName,
669 int flagMask, int flagValues, UserHandle user) {
670 try {
671 mPM.updatePermissionFlags(permissionName, packageName, flagMask,
672 flagValues, user.getIdentifier());
Dianne Hackborne639da72012-02-21 15:11:13 -0800673 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700674 throw e.rethrowFromSystemServer();
Dianne Hackborne639da72012-02-21 15:11:13 -0800675 }
676 }
677
678 @Override
Svetoslav20770dd2015-05-29 15:43:04 -0700679 public boolean shouldShowRequestPermissionRationale(String permission) {
680 try {
681 return mPM.shouldShowRequestPermissionRationale(permission,
682 mContext.getPackageName(), mContext.getUserId());
683 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700684 throw e.rethrowFromSystemServer();
Svetoslav20770dd2015-05-29 15:43:04 -0700685 }
686 }
687
688 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800689 public int checkSignatures(String pkg1, String pkg2) {
690 try {
691 return mPM.checkSignatures(pkg1, pkg2);
692 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700693 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800694 }
695 }
696
697 @Override
698 public int checkSignatures(int uid1, int uid2) {
699 try {
700 return mPM.checkUidSignatures(uid1, uid2);
701 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700702 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800703 }
704 }
705
706 @Override
Daniel Cashman5cdda342018-01-19 07:22:52 -0800707 public boolean hasSigningCertificate(
708 String packageName, byte[] certificate, @PackageManager.CertificateInputType int type) {
709 try {
710 return mPM.hasSigningCertificate(packageName, certificate, type);
711 } catch (RemoteException e) {
712 throw e.rethrowFromSystemServer();
713 }
714 }
715
716 @Override
717 public boolean hasSigningCertificate(
718 int uid, byte[] certificate, @PackageManager.CertificateInputType int type) {
719 try {
720 return mPM.hasUidSigningCertificate(uid, certificate, type);
721 } catch (RemoteException e) {
722 throw e.rethrowFromSystemServer();
723 }
724 }
725
726 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800727 public String[] getPackagesForUid(int uid) {
728 try {
729 return mPM.getPackagesForUid(uid);
730 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700731 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800732 }
733 }
734
735 @Override
736 public String getNameForUid(int uid) {
737 try {
738 return mPM.getNameForUid(uid);
739 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700740 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800741 }
742 }
743
744 @Override
Todd Kennedy9da8b8a72017-07-25 15:38:39 -0700745 public String[] getNamesForUids(int[] uids) {
746 try {
747 return mPM.getNamesForUids(uids);
748 } catch (RemoteException e) {
749 throw e.rethrowFromSystemServer();
750 }
751 }
752
753 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800754 public int getUidForSharedUser(String sharedUserName)
755 throws NameNotFoundException {
756 try {
757 int uid = mPM.getUidForSharedUser(sharedUserName);
758 if(uid != -1) {
759 return uid;
760 }
761 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700762 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800763 }
764 throw new NameNotFoundException("No shared userid for user:"+sharedUserName);
765 }
766
Kenny Roote6cd0c72011-05-19 12:48:14 -0700767 @SuppressWarnings("unchecked")
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800768 @Override
769 public List<PackageInfo> getInstalledPackages(int flags) {
Jeff Sharkeye06b4d12016-01-06 14:51:50 -0700770 return getInstalledPackagesAsUser(flags, mContext.getUserId());
Amith Yamasani151ec4c2012-09-07 19:25:16 -0700771 }
772
773 /** @hide */
774 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700775 @SuppressWarnings("unchecked")
Jeff Sharkeye06b4d12016-01-06 14:51:50 -0700776 public List<PackageInfo> getInstalledPackagesAsUser(int flags, int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800777 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700778 ParceledListSlice<PackageInfo> parceledList =
779 mPM.getInstalledPackages(flags, userId);
780 if (parceledList == null) {
781 return Collections.emptyList();
782 }
783 return parceledList.getList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800784 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700785 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800786 }
787 }
788
Kenny Roote6cd0c72011-05-19 12:48:14 -0700789 @SuppressWarnings("unchecked")
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800790 @Override
Dianne Hackborne7991752013-01-16 17:56:46 -0800791 public List<PackageInfo> getPackagesHoldingPermissions(
792 String[] permissions, int flags) {
793 final int userId = mContext.getUserId();
794 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700795 ParceledListSlice<PackageInfo> parceledList =
796 mPM.getPackagesHoldingPermissions(permissions, flags, userId);
797 if (parceledList == null) {
798 return Collections.emptyList();
799 }
800 return parceledList.getList();
Dianne Hackborne7991752013-01-16 17:56:46 -0800801 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700802 throw e.rethrowFromSystemServer();
Dianne Hackborne7991752013-01-16 17:56:46 -0800803 }
804 }
805
806 @SuppressWarnings("unchecked")
807 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800808 public List<ApplicationInfo> getInstalledApplications(int flags) {
Bartosz Fabianowski11334242016-11-17 20:49:16 +0100809 return getInstalledApplicationsAsUser(flags, mContext.getUserId());
810 }
811
812 /** @hide */
813 @SuppressWarnings("unchecked")
814 @Override
815 public List<ApplicationInfo> getInstalledApplicationsAsUser(int flags, int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800816 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700817 ParceledListSlice<ApplicationInfo> parceledList =
818 mPM.getInstalledApplications(flags, userId);
819 if (parceledList == null) {
820 return Collections.emptyList();
821 }
822 return parceledList.getList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800823 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700824 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800825 }
826 }
827
Svet Ganov2acf0632015-11-24 19:10:59 -0800828 /** @hide */
829 @SuppressWarnings("unchecked")
830 @Override
Svetoslav Ganov096d3042017-01-30 16:34:13 -0800831 public List<InstantAppInfo> getInstantApps() {
Svet Ganov2acf0632015-11-24 19:10:59 -0800832 try {
Svetoslav Ganov096d3042017-01-30 16:34:13 -0800833 ParceledListSlice<InstantAppInfo> slice =
834 mPM.getInstantApps(mContext.getUserId());
Svet Ganov2acf0632015-11-24 19:10:59 -0800835 if (slice != null) {
836 return slice.getList();
837 }
838 return Collections.emptyList();
839 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700840 throw e.rethrowFromSystemServer();
Svet Ganov2acf0632015-11-24 19:10:59 -0800841 }
842 }
843
844 /** @hide */
845 @Override
Svetoslav Ganov096d3042017-01-30 16:34:13 -0800846 public Drawable getInstantAppIcon(String packageName) {
Svet Ganov2acf0632015-11-24 19:10:59 -0800847 try {
Svetoslav Ganov096d3042017-01-30 16:34:13 -0800848 Bitmap bitmap = mPM.getInstantAppIcon(
Svet Ganov2acf0632015-11-24 19:10:59 -0800849 packageName, mContext.getUserId());
850 if (bitmap != null) {
851 return new BitmapDrawable(null, bitmap);
852 }
853 return null;
854 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700855 throw e.rethrowFromSystemServer();
Svet Ganov2acf0632015-11-24 19:10:59 -0800856 }
857 }
858
859 @Override
Svetoslav Ganov096d3042017-01-30 16:34:13 -0800860 public boolean isInstantApp() {
David Christie31a16552017-03-01 15:08:45 -0800861 return isInstantApp(mContext.getPackageName());
862 }
863
864 @Override
865 public boolean isInstantApp(String packageName) {
Svet Ganov2acf0632015-11-24 19:10:59 -0800866 try {
David Christie31a16552017-03-01 15:08:45 -0800867 return mPM.isInstantApp(packageName, mContext.getUserId());
Svet Ganov2acf0632015-11-24 19:10:59 -0800868 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700869 throw e.rethrowFromSystemServer();
Svet Ganov2acf0632015-11-24 19:10:59 -0800870 }
Svet Ganov2acf0632015-11-24 19:10:59 -0800871 }
872
Svetoslav Ganov345ffa52017-04-18 16:08:41 -0700873 public int getInstantAppCookieMaxBytes() {
Svet Ganov2acf0632015-11-24 19:10:59 -0800874 return Settings.Global.getInt(mContext.getContentResolver(),
875 Settings.Global.EPHEMERAL_COOKIE_MAX_SIZE_BYTES,
876 DEFAULT_EPHEMERAL_COOKIE_MAX_SIZE_BYTES);
877 }
878
879 @Override
Svetoslav Ganov345ffa52017-04-18 16:08:41 -0700880 public int getInstantAppCookieMaxSize() {
881 return getInstantAppCookieMaxBytes();
882 }
883
884 @Override
Svetoslav Ganov096d3042017-01-30 16:34:13 -0800885 public @NonNull byte[] getInstantAppCookie() {
Svet Ganov2acf0632015-11-24 19:10:59 -0800886 try {
Svetoslav Ganov096d3042017-01-30 16:34:13 -0800887 final byte[] cookie = mPM.getInstantAppCookie(
Svet Ganov2acf0632015-11-24 19:10:59 -0800888 mContext.getPackageName(), mContext.getUserId());
889 if (cookie != null) {
890 return cookie;
Jeff Sharkey27b2e692016-02-25 17:40:12 -0700891 } else {
892 return EmptyArray.BYTE;
Svet Ganov2acf0632015-11-24 19:10:59 -0800893 }
894 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700895 throw e.rethrowFromSystemServer();
Svet Ganov2acf0632015-11-24 19:10:59 -0800896 }
Svet Ganov2acf0632015-11-24 19:10:59 -0800897 }
898
899 @Override
Svetoslav Ganov345ffa52017-04-18 16:08:41 -0700900 public void clearInstantAppCookie() {
901 updateInstantAppCookie(null);
902 }
903
904 @Override
905 public void updateInstantAppCookie(@NonNull byte[] cookie) {
906 if (cookie != null && cookie.length > getInstantAppCookieMaxBytes()) {
907 throw new IllegalArgumentException("instant cookie longer than "
908 + getInstantAppCookieMaxBytes());
909 }
910 try {
911 mPM.setInstantAppCookie(mContext.getPackageName(),
912 cookie, mContext.getUserId());
913 } catch (RemoteException e) {
914 throw e.rethrowFromSystemServer();
915 }
916 }
917
918 @Override
Svetoslav Ganov096d3042017-01-30 16:34:13 -0800919 public boolean setInstantAppCookie(@NonNull byte[] cookie) {
Svet Ganov2acf0632015-11-24 19:10:59 -0800920 try {
Svetoslav Ganov096d3042017-01-30 16:34:13 -0800921 return mPM.setInstantAppCookie(mContext.getPackageName(),
922 cookie, mContext.getUserId());
Svet Ganov2acf0632015-11-24 19:10:59 -0800923 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700924 throw e.rethrowFromSystemServer();
Svet Ganov2acf0632015-11-24 19:10:59 -0800925 }
Svet Ganov2acf0632015-11-24 19:10:59 -0800926 }
927
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800928 @Override
929 public ResolveInfo resolveActivity(Intent intent, int flags) {
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700930 return resolveActivityAsUser(intent, flags, mContext.getUserId());
Svetoslav Ganov58d37b52012-09-18 12:04:19 -0700931 }
932
933 @Override
934 public ResolveInfo resolveActivityAsUser(Intent intent, int flags, int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800935 try {
936 return mPM.resolveIntent(
937 intent,
938 intent.resolveTypeIfNeeded(mContext.getContentResolver()),
Svetoslav Ganov58d37b52012-09-18 12:04:19 -0700939 flags,
940 userId);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800941 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700942 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800943 }
944 }
945
946 @Override
947 public List<ResolveInfo> queryIntentActivities(Intent intent,
948 int flags) {
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700949 return queryIntentActivitiesAsUser(intent, flags, mContext.getUserId());
Amith Yamasani151ec4c2012-09-07 19:25:16 -0700950 }
951
952 /** @hide Same as above but for a specific user */
953 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700954 @SuppressWarnings("unchecked")
Svetoslav Ganov58d37b52012-09-18 12:04:19 -0700955 public List<ResolveInfo> queryIntentActivitiesAsUser(Intent intent,
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700956 int flags, int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800957 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700958 ParceledListSlice<ResolveInfo> parceledList =
959 mPM.queryIntentActivities(intent,
960 intent.resolveTypeIfNeeded(mContext.getContentResolver()),
961 flags, userId);
962 if (parceledList == null) {
963 return Collections.emptyList();
964 }
965 return parceledList.getList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800966 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700967 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800968 }
969 }
970
971 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700972 @SuppressWarnings("unchecked")
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800973 public List<ResolveInfo> queryIntentActivityOptions(
974 ComponentName caller, Intent[] specifics, Intent intent,
975 int flags) {
976 final ContentResolver resolver = mContext.getContentResolver();
977
978 String[] specificTypes = null;
979 if (specifics != null) {
980 final int N = specifics.length;
981 for (int i=0; i<N; i++) {
982 Intent sp = specifics[i];
983 if (sp != null) {
984 String t = sp.resolveTypeIfNeeded(resolver);
985 if (t != null) {
986 if (specificTypes == null) {
987 specificTypes = new String[N];
988 }
989 specificTypes[i] = t;
990 }
991 }
992 }
993 }
994
995 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700996 ParceledListSlice<ResolveInfo> parceledList =
997 mPM.queryIntentActivityOptions(caller, specifics, specificTypes, intent,
998 intent.resolveTypeIfNeeded(resolver), flags, mContext.getUserId());
999 if (parceledList == null) {
1000 return Collections.emptyList();
1001 }
1002 return parceledList.getList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001003 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001004 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001005 }
1006 }
1007
Amith Yamasanif203aee2012-08-29 18:41:53 -07001008 /**
1009 * @hide
1010 */
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001011 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001012 @SuppressWarnings("unchecked")
Jeff Sharkeye06b4d12016-01-06 14:51:50 -07001013 public List<ResolveInfo> queryBroadcastReceiversAsUser(Intent intent, int flags, int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001014 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001015 ParceledListSlice<ResolveInfo> parceledList =
1016 mPM.queryIntentReceivers(intent,
1017 intent.resolveTypeIfNeeded(mContext.getContentResolver()),
1018 flags, userId);
1019 if (parceledList == null) {
1020 return Collections.emptyList();
1021 }
1022 return parceledList.getList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001023 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001024 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001025 }
1026 }
1027
1028 @Override
Amith Yamasanif203aee2012-08-29 18:41:53 -07001029 public List<ResolveInfo> queryBroadcastReceivers(Intent intent, int flags) {
Jeff Sharkeye06b4d12016-01-06 14:51:50 -07001030 return queryBroadcastReceiversAsUser(intent, flags, mContext.getUserId());
Amith Yamasanif203aee2012-08-29 18:41:53 -07001031 }
1032
1033 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001034 public ResolveInfo resolveService(Intent intent, int flags) {
1035 try {
1036 return mPM.resolveService(
1037 intent,
1038 intent.resolveTypeIfNeeded(mContext.getContentResolver()),
Amith Yamasani483f3b02012-03-13 16:08:00 -07001039 flags,
Jeff Sharkeyded653b2012-09-27 19:09:24 -07001040 mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001041 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001042 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001043 }
1044 }
1045
1046 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001047 @SuppressWarnings("unchecked")
Svetoslav Ganov58d37b52012-09-18 12:04:19 -07001048 public List<ResolveInfo> queryIntentServicesAsUser(Intent intent, int flags, int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001049 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001050 ParceledListSlice<ResolveInfo> parceledList =
1051 mPM.queryIntentServices(intent,
1052 intent.resolveTypeIfNeeded(mContext.getContentResolver()),
1053 flags, userId);
1054 if (parceledList == null) {
1055 return Collections.emptyList();
1056 }
1057 return parceledList.getList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001058 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001059 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001060 }
1061 }
1062
1063 @Override
Svetoslav Ganov58d37b52012-09-18 12:04:19 -07001064 public List<ResolveInfo> queryIntentServices(Intent intent, int flags) {
Jeff Sharkeyded653b2012-09-27 19:09:24 -07001065 return queryIntentServicesAsUser(intent, flags, mContext.getUserId());
Svetoslav Ganov58d37b52012-09-18 12:04:19 -07001066 }
1067
1068 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001069 @SuppressWarnings("unchecked")
Jeff Sharkey85f5f812013-10-07 10:16:12 -07001070 public List<ResolveInfo> queryIntentContentProvidersAsUser(
1071 Intent intent, int flags, int userId) {
1072 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001073 ParceledListSlice<ResolveInfo> parceledList =
1074 mPM.queryIntentContentProviders(intent,
1075 intent.resolveTypeIfNeeded(mContext.getContentResolver()),
1076 flags, userId);
1077 if (parceledList == null) {
1078 return Collections.emptyList();
1079 }
1080 return parceledList.getList();
Jeff Sharkey85f5f812013-10-07 10:16:12 -07001081 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001082 throw e.rethrowFromSystemServer();
Jeff Sharkey85f5f812013-10-07 10:16:12 -07001083 }
1084 }
1085
1086 @Override
1087 public List<ResolveInfo> queryIntentContentProviders(Intent intent, int flags) {
1088 return queryIntentContentProvidersAsUser(intent, flags, mContext.getUserId());
1089 }
1090
1091 @Override
Alexandra Gherghina0363c3e2014-06-23 13:34:59 +01001092 public ProviderInfo resolveContentProvider(String name, int flags) {
1093 return resolveContentProviderAsUser(name, flags, mContext.getUserId());
1094 }
1095
1096 /** @hide **/
1097 @Override
1098 public ProviderInfo resolveContentProviderAsUser(String name, int flags, int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001099 try {
Alexandra Gherghina0363c3e2014-06-23 13:34:59 +01001100 return mPM.resolveContentProvider(name, flags, userId);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001101 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001102 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001103 }
1104 }
1105
1106 @Override
1107 public List<ProviderInfo> queryContentProviders(String processName,
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001108 int uid, int flags) {
Makoto Onuki32757292017-02-22 14:36:59 -08001109 return queryContentProviders(processName, uid, flags, null);
1110 }
1111
1112 @Override
1113 @SuppressWarnings("unchecked")
1114 public List<ProviderInfo> queryContentProviders(String processName,
1115 int uid, int flags, String metaDataKey) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001116 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001117 ParceledListSlice<ProviderInfo> slice =
Makoto Onuki32757292017-02-22 14:36:59 -08001118 mPM.queryContentProviders(processName, uid, flags, metaDataKey);
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001119 return slice != null ? slice.getList() : Collections.<ProviderInfo>emptyList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001120 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001121 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001122 }
1123 }
1124
1125 @Override
1126 public InstrumentationInfo getInstrumentationInfo(
1127 ComponentName className, int flags)
1128 throws NameNotFoundException {
1129 try {
1130 InstrumentationInfo ii = mPM.getInstrumentationInfo(
1131 className, flags);
1132 if (ii != null) {
1133 return ii;
1134 }
1135 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001136 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001137 }
1138
1139 throw new NameNotFoundException(className.toString());
1140 }
1141
1142 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001143 @SuppressWarnings("unchecked")
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001144 public List<InstrumentationInfo> queryInstrumentation(
1145 String targetPackage, int flags) {
1146 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001147 ParceledListSlice<InstrumentationInfo> parceledList =
1148 mPM.queryInstrumentation(targetPackage, flags);
1149 if (parceledList == null) {
1150 return Collections.emptyList();
1151 }
1152 return parceledList.getList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001153 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001154 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001155 }
1156 }
1157
Alan Viveretteecd585a2015-04-13 10:32:51 -07001158 @Nullable
1159 @Override
1160 public Drawable getDrawable(String packageName, @DrawableRes int resId,
1161 @Nullable ApplicationInfo appInfo) {
1162 final ResourceName name = new ResourceName(packageName, resId);
1163 final Drawable cachedIcon = getCachedIcon(name);
1164 if (cachedIcon != null) {
1165 return cachedIcon;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001166 }
Alan Viveretteecd585a2015-04-13 10:32:51 -07001167
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001168 if (appInfo == null) {
1169 try {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001170 appInfo = getApplicationInfo(packageName, sDefaultFlags);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001171 } catch (NameNotFoundException e) {
1172 return null;
1173 }
1174 }
Alan Viveretteecd585a2015-04-13 10:32:51 -07001175
1176 if (resId != 0) {
1177 try {
1178 final Resources r = getResourcesForApplication(appInfo);
1179 final Drawable dr = r.getDrawable(resId, null);
1180 if (dr != null) {
1181 putCachedIcon(name, dr);
1182 }
1183
1184 if (false) {
1185 RuntimeException e = new RuntimeException("here");
1186 e.fillInStackTrace();
1187 Log.w(TAG, "Getting drawable 0x" + Integer.toHexString(resId)
1188 + " from package " + packageName
1189 + ": app scale=" + r.getCompatibilityInfo().applicationScale
1190 + ", caller scale=" + mContext.getResources()
1191 .getCompatibilityInfo().applicationScale,
1192 e);
1193 }
Ricky Wai3ce46252015-04-15 16:12:22 +01001194 if (DEBUG_ICONS) {
Alan Viveretteecd585a2015-04-13 10:32:51 -07001195 Log.v(TAG, "Getting drawable 0x"
1196 + Integer.toHexString(resId) + " from " + r
1197 + ": " + dr);
Ricky Wai3ce46252015-04-15 16:12:22 +01001198 }
1199 return dr;
Alan Viveretteecd585a2015-04-13 10:32:51 -07001200 } catch (NameNotFoundException e) {
1201 Log.w("PackageManager", "Failure retrieving resources for "
1202 + appInfo.packageName);
1203 } catch (Resources.NotFoundException e) {
1204 Log.w("PackageManager", "Failure retrieving resources for "
1205 + appInfo.packageName + ": " + e.getMessage());
1206 } catch (Exception e) {
1207 // If an exception was thrown, fall through to return
1208 // default icon.
1209 Log.w("PackageManager", "Failure retrieving icon 0x"
1210 + Integer.toHexString(resId) + " in package "
1211 + packageName, e);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001212 }
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001213 }
Alan Viveretteecd585a2015-04-13 10:32:51 -07001214
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001215 return null;
1216 }
1217
1218 @Override public Drawable getActivityIcon(ComponentName activityName)
1219 throws NameNotFoundException {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001220 return getActivityInfo(activityName, sDefaultFlags).loadIcon(this);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001221 }
1222
1223 @Override public Drawable getActivityIcon(Intent intent)
1224 throws NameNotFoundException {
1225 if (intent.getComponent() != null) {
1226 return getActivityIcon(intent.getComponent());
1227 }
1228
1229 ResolveInfo info = resolveActivity(
1230 intent, PackageManager.MATCH_DEFAULT_ONLY);
1231 if (info != null) {
1232 return info.activityInfo.loadIcon(this);
1233 }
1234
Romain Guy39fe17c2011-11-30 10:34:07 -08001235 throw new NameNotFoundException(intent.toUri(0));
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001236 }
1237
1238 @Override public Drawable getDefaultActivityIcon() {
1239 return Resources.getSystem().getDrawable(
1240 com.android.internal.R.drawable.sym_def_app_icon);
1241 }
1242
1243 @Override public Drawable getApplicationIcon(ApplicationInfo info) {
1244 return info.loadIcon(this);
1245 }
1246
1247 @Override public Drawable getApplicationIcon(String packageName)
1248 throws NameNotFoundException {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001249 return getApplicationIcon(getApplicationInfo(packageName, sDefaultFlags));
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001250 }
1251
1252 @Override
Jose Limaf78e3122014-03-06 12:13:15 -08001253 public Drawable getActivityBanner(ComponentName activityName)
1254 throws NameNotFoundException {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001255 return getActivityInfo(activityName, sDefaultFlags).loadBanner(this);
Jose Limaf78e3122014-03-06 12:13:15 -08001256 }
1257
1258 @Override
1259 public Drawable getActivityBanner(Intent intent)
1260 throws NameNotFoundException {
1261 if (intent.getComponent() != null) {
1262 return getActivityBanner(intent.getComponent());
1263 }
1264
1265 ResolveInfo info = resolveActivity(
1266 intent, PackageManager.MATCH_DEFAULT_ONLY);
1267 if (info != null) {
1268 return info.activityInfo.loadBanner(this);
1269 }
1270
1271 throw new NameNotFoundException(intent.toUri(0));
1272 }
1273
1274 @Override
1275 public Drawable getApplicationBanner(ApplicationInfo info) {
1276 return info.loadBanner(this);
1277 }
1278
1279 @Override
1280 public Drawable getApplicationBanner(String packageName)
1281 throws NameNotFoundException {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001282 return getApplicationBanner(getApplicationInfo(packageName, sDefaultFlags));
Jose Limaf78e3122014-03-06 12:13:15 -08001283 }
1284
1285 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001286 public Drawable getActivityLogo(ComponentName activityName)
1287 throws NameNotFoundException {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001288 return getActivityInfo(activityName, sDefaultFlags).loadLogo(this);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001289 }
1290
1291 @Override
1292 public Drawable getActivityLogo(Intent intent)
1293 throws NameNotFoundException {
1294 if (intent.getComponent() != null) {
1295 return getActivityLogo(intent.getComponent());
1296 }
1297
1298 ResolveInfo info = resolveActivity(
1299 intent, PackageManager.MATCH_DEFAULT_ONLY);
1300 if (info != null) {
1301 return info.activityInfo.loadLogo(this);
1302 }
1303
1304 throw new NameNotFoundException(intent.toUri(0));
1305 }
1306
1307 @Override
1308 public Drawable getApplicationLogo(ApplicationInfo info) {
1309 return info.loadLogo(this);
1310 }
1311
1312 @Override
1313 public Drawable getApplicationLogo(String packageName)
1314 throws NameNotFoundException {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001315 return getApplicationLogo(getApplicationInfo(packageName, sDefaultFlags));
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001316 }
1317
Svetoslavc7d62f02014-09-04 15:39:54 -07001318 @Override
1319 public Drawable getUserBadgedIcon(Drawable icon, UserHandle user) {
Kenny Guy02c89902016-11-15 19:36:38 +00001320 if (!isManagedProfile(user.getIdentifier())) {
Svetoslavc7d62f02014-09-04 15:39:54 -07001321 return icon;
1322 }
Sunny Goyalbab30752017-04-12 15:36:42 -07001323 Drawable badge = new LauncherIcons(mContext).getBadgeDrawable(
1324 com.android.internal.R.drawable.ic_corp_icon_badge_case,
1325 getUserBadgeColor(user));
Kenny Guy02c89902016-11-15 19:36:38 +00001326 return getBadgedDrawable(icon, badge, null, true);
Svetoslavc7d62f02014-09-04 15:39:54 -07001327 }
1328
1329 @Override
1330 public Drawable getUserBadgedDrawableForDensity(Drawable drawable, UserHandle user,
1331 Rect badgeLocation, int badgeDensity) {
1332 Drawable badgeDrawable = getUserBadgeForDensity(user, badgeDensity);
1333 if (badgeDrawable == null) {
1334 return drawable;
1335 }
1336 return getBadgedDrawable(drawable, badgeDrawable, badgeLocation, true);
1337 }
1338
Kenny Guy02c89902016-11-15 19:36:38 +00001339 @VisibleForTesting
1340 public static final int[] CORP_BADGE_LABEL_RES_ID = new int[] {
1341 com.android.internal.R.string.managed_profile_label_badge,
1342 com.android.internal.R.string.managed_profile_label_badge_2,
1343 com.android.internal.R.string.managed_profile_label_badge_3
1344 };
1345
1346 private int getUserBadgeColor(UserHandle user) {
Sunny Goyalbab30752017-04-12 15:36:42 -07001347 return IconDrawableFactory.getUserBadgeColor(getUserManager(), user.getIdentifier());
Kenny Guy02c89902016-11-15 19:36:38 +00001348 }
1349
Svetoslavc7d62f02014-09-04 15:39:54 -07001350 @Override
1351 public Drawable getUserBadgeForDensity(UserHandle user, int density) {
Kenny Guy02c89902016-11-15 19:36:38 +00001352 Drawable badgeColor = getManagedProfileIconForDensity(user,
1353 com.android.internal.R.drawable.ic_corp_badge_color, density);
1354 if (badgeColor == null) {
1355 return null;
1356 }
Kenny Guy02c89902016-11-15 19:36:38 +00001357 Drawable badgeForeground = getDrawableForDensity(
1358 com.android.internal.R.drawable.ic_corp_badge_case, density);
Tony Make21a1d02018-02-16 11:46:58 +00001359 badgeForeground.setTint(getUserBadgeColor(user));
1360 Drawable badge = new LayerDrawable(new Drawable[] {badgeColor, badgeForeground });
Kenny Guy02c89902016-11-15 19:36:38 +00001361 return badge;
Selim Cineke6ff9462016-01-15 15:07:06 -08001362 }
1363
1364 @Override
1365 public Drawable getUserBadgeForDensityNoBackground(UserHandle user, int density) {
Kenny Guy02c89902016-11-15 19:36:38 +00001366 Drawable badge = getManagedProfileIconForDensity(user,
Vadim Tryshev66ae66a2016-02-18 15:41:21 -08001367 com.android.internal.R.drawable.ic_corp_badge_no_background, density);
Kenny Guy02c89902016-11-15 19:36:38 +00001368 if (badge != null) {
1369 badge.setTint(getUserBadgeColor(user));
1370 }
1371 return badge;
Selim Cineke6ff9462016-01-15 15:07:06 -08001372 }
1373
Vadim Tryshev66ae66a2016-02-18 15:41:21 -08001374 private Drawable getDrawableForDensity(int drawableId, int density) {
1375 if (density <= 0) {
1376 density = mContext.getResources().getDisplayMetrics().densityDpi;
1377 }
1378 return Resources.getSystem().getDrawableForDensity(drawableId, density);
1379 }
1380
1381 private Drawable getManagedProfileIconForDensity(UserHandle user, int drawableId, int density) {
Tony Mak8673b282016-03-21 21:10:59 +00001382 if (isManagedProfile(user.getIdentifier())) {
Vadim Tryshev66ae66a2016-02-18 15:41:21 -08001383 return getDrawableForDensity(drawableId, density);
Svetoslavc7d62f02014-09-04 15:39:54 -07001384 }
1385 return null;
1386 }
1387
1388 @Override
1389 public CharSequence getUserBadgedLabel(CharSequence label, UserHandle user) {
Tony Mak8673b282016-03-21 21:10:59 +00001390 if (isManagedProfile(user.getIdentifier())) {
Kenny Guy02c89902016-11-15 19:36:38 +00001391 int badge = getUserManager().getManagedProfileBadge(user.getIdentifier());
1392 int resourceId = CORP_BADGE_LABEL_RES_ID[badge % CORP_BADGE_LABEL_RES_ID.length];
1393 return Resources.getSystem().getString(resourceId, label);
Svetoslavc7d62f02014-09-04 15:39:54 -07001394 }
1395 return label;
1396 }
1397
Alan Viveretteecd585a2015-04-13 10:32:51 -07001398 @Override
1399 public Resources getResourcesForActivity(ComponentName activityName)
1400 throws NameNotFoundException {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001401 return getResourcesForApplication(
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001402 getActivityInfo(activityName, sDefaultFlags).applicationInfo);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001403 }
1404
Alan Viveretteecd585a2015-04-13 10:32:51 -07001405 @Override
1406 public Resources getResourcesForApplication(@NonNull ApplicationInfo app)
1407 throws NameNotFoundException {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001408 if (app.packageName.equals("system")) {
Adam Lesinskia82b6262017-03-21 16:56:17 -07001409 return mContext.mMainThread.getSystemUiContext().getResources();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001410 }
Jeff Sharkey8a4c9722014-06-16 13:48:42 -07001411 final boolean sameUid = (app.uid == Process.myUid());
Adam Lesinski53fafdf2016-08-03 13:36:39 -07001412 final Resources r = mContext.mMainThread.getTopLevelResources(
Adam Lesinskic82f28a2016-06-08 17:19:09 -07001413 sameUid ? app.sourceDir : app.publicSourceDir,
1414 sameUid ? app.splitSourceDirs : app.splitPublicSourceDirs,
1415 app.resourceDirs, app.sharedLibraryFiles, Display.DEFAULT_DISPLAY,
Todd Kennedy233a0b12018-01-29 20:30:24 +00001416 mContext.mPackageInfo);
Adam Lesinski53fafdf2016-08-03 13:36:39 -07001417 if (r != null) {
1418 return r;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001419 }
Adam Lesinski53fafdf2016-08-03 13:36:39 -07001420 throw new NameNotFoundException("Unable to open " + app.publicSourceDir);
1421
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001422 }
1423
Alan Viveretteecd585a2015-04-13 10:32:51 -07001424 @Override
1425 public Resources getResourcesForApplication(String appPackageName)
1426 throws NameNotFoundException {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001427 return getResourcesForApplication(
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001428 getApplicationInfo(appPackageName, sDefaultFlags));
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001429 }
1430
Amith Yamasani98edc952012-09-25 14:09:27 -07001431 /** @hide */
1432 @Override
1433 public Resources getResourcesForApplicationAsUser(String appPackageName, int userId)
1434 throws NameNotFoundException {
Jeff Sharkeyded653b2012-09-27 19:09:24 -07001435 if (userId < 0) {
1436 throw new IllegalArgumentException(
1437 "Call does not support special user #" + userId);
1438 }
1439 if ("system".equals(appPackageName)) {
Adam Lesinskia82b6262017-03-21 16:56:17 -07001440 return mContext.mMainThread.getSystemUiContext().getResources();
Jeff Sharkeyded653b2012-09-27 19:09:24 -07001441 }
Amith Yamasani98edc952012-09-25 14:09:27 -07001442 try {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001443 ApplicationInfo ai = mPM.getApplicationInfo(appPackageName, sDefaultFlags, userId);
Amith Yamasani98edc952012-09-25 14:09:27 -07001444 if (ai != null) {
1445 return getResourcesForApplication(ai);
1446 }
1447 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001448 throw e.rethrowFromSystemServer();
Amith Yamasani98edc952012-09-25 14:09:27 -07001449 }
1450 throw new NameNotFoundException("Package " + appPackageName + " doesn't exist");
1451 }
1452
Jeff Sharkeycd654482016-01-08 17:42:11 -07001453 volatile int mCachedSafeMode = -1;
1454
1455 @Override
1456 public boolean isSafeMode() {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001457 try {
1458 if (mCachedSafeMode < 0) {
1459 mCachedSafeMode = mPM.isSafeMode() ? 1 : 0;
1460 }
1461 return mCachedSafeMode != 0;
1462 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001463 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001464 }
1465 }
1466
Svetoslavf7c06eb2015-06-10 18:43:22 -07001467 @Override
1468 public void addOnPermissionsChangeListener(OnPermissionsChangedListener listener) {
1469 synchronized (mPermissionListeners) {
1470 if (mPermissionListeners.get(listener) != null) {
1471 return;
1472 }
1473 OnPermissionsChangeListenerDelegate delegate =
1474 new OnPermissionsChangeListenerDelegate(listener, Looper.getMainLooper());
1475 try {
1476 mPM.addOnPermissionsChangeListener(delegate);
1477 mPermissionListeners.put(listener, delegate);
1478 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001479 throw e.rethrowFromSystemServer();
Svetoslavf7c06eb2015-06-10 18:43:22 -07001480 }
1481 }
1482 }
1483
1484 @Override
1485 public void removeOnPermissionsChangeListener(OnPermissionsChangedListener listener) {
1486 synchronized (mPermissionListeners) {
1487 IOnPermissionsChangeListener delegate = mPermissionListeners.get(listener);
1488 if (delegate != null) {
1489 try {
1490 mPM.removeOnPermissionsChangeListener(delegate);
1491 mPermissionListeners.remove(listener);
1492 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001493 throw e.rethrowFromSystemServer();
Svetoslavf7c06eb2015-06-10 18:43:22 -07001494 }
1495 }
1496 }
1497 }
1498
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001499 static void configurationChanged() {
1500 synchronized (sSync) {
1501 sIconCache.clear();
1502 sStringCache.clear();
1503 }
1504 }
1505
Yao Chen022b8ea2016-12-16 11:03:28 -08001506 protected ApplicationPackageManager(ContextImpl context,
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001507 IPackageManager pm) {
1508 mContext = context;
1509 mPM = pm;
1510 }
1511
Alan Viveretteecd585a2015-04-13 10:32:51 -07001512 @Nullable
1513 private Drawable getCachedIcon(@NonNull ResourceName name) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001514 synchronized (sSync) {
Alan Viveretteecd585a2015-04-13 10:32:51 -07001515 final WeakReference<Drawable.ConstantState> wr = sIconCache.get(name);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001516 if (DEBUG_ICONS) Log.v(TAG, "Get cached weak drawable ref for "
1517 + name + ": " + wr);
1518 if (wr != null) { // we have the activity
Alan Viveretteecd585a2015-04-13 10:32:51 -07001519 final Drawable.ConstantState state = wr.get();
Romain Guy39fe17c2011-11-30 10:34:07 -08001520 if (state != null) {
1521 if (DEBUG_ICONS) {
1522 Log.v(TAG, "Get cached drawable state for " + name + ": " + state);
1523 }
1524 // Note: It's okay here to not use the newDrawable(Resources) variant
1525 // of the API. The ConstantState comes from a drawable that was
1526 // originally created by passing the proper app Resources instance
1527 // which means the state should already contain the proper
1528 // resources specific information (like density.) See
1529 // BitmapDrawable.BitmapState for instance.
1530 return state.newDrawable();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001531 }
1532 // our entry has been purged
1533 sIconCache.remove(name);
1534 }
1535 }
1536 return null;
1537 }
1538
Alan Viveretteecd585a2015-04-13 10:32:51 -07001539 private void putCachedIcon(@NonNull ResourceName name, @NonNull Drawable dr) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001540 synchronized (sSync) {
Alan Viveretteecd585a2015-04-13 10:32:51 -07001541 sIconCache.put(name, new WeakReference<>(dr.getConstantState()));
Romain Guy39fe17c2011-11-30 10:34:07 -08001542 if (DEBUG_ICONS) Log.v(TAG, "Added cached drawable state for " + name + ": " + dr);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001543 }
1544 }
1545
Romain Guy39fe17c2011-11-30 10:34:07 -08001546 static void handlePackageBroadcast(int cmd, String[] pkgList, boolean hasPkgInfo) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001547 boolean immediateGc = false;
Sudheer Shankacc6418f2016-10-13 12:03:44 -07001548 if (cmd == ApplicationThreadConstants.EXTERNAL_STORAGE_UNAVAILABLE) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001549 immediateGc = true;
1550 }
1551 if (pkgList != null && (pkgList.length > 0)) {
1552 boolean needCleanup = false;
1553 for (String ssp : pkgList) {
1554 synchronized (sSync) {
Dianne Hackbornadd005c2013-07-17 18:43:12 -07001555 for (int i=sIconCache.size()-1; i>=0; i--) {
1556 ResourceName nm = sIconCache.keyAt(i);
1557 if (nm.packageName.equals(ssp)) {
1558 //Log.i(TAG, "Removing cached drawable for " + nm);
1559 sIconCache.removeAt(i);
1560 needCleanup = true;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001561 }
1562 }
Dianne Hackbornadd005c2013-07-17 18:43:12 -07001563 for (int i=sStringCache.size()-1; i>=0; i--) {
1564 ResourceName nm = sStringCache.keyAt(i);
1565 if (nm.packageName.equals(ssp)) {
1566 //Log.i(TAG, "Removing cached string for " + nm);
1567 sStringCache.removeAt(i);
1568 needCleanup = true;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001569 }
1570 }
1571 }
1572 }
1573 if (needCleanup || hasPkgInfo) {
1574 if (immediateGc) {
1575 // Schedule an immediate gc.
1576 Runtime.getRuntime().gc();
1577 } else {
1578 ActivityThread.currentActivityThread().scheduleGcIdler();
1579 }
1580 }
1581 }
1582 }
1583
1584 private static final class ResourceName {
1585 final String packageName;
1586 final int iconId;
1587
1588 ResourceName(String _packageName, int _iconId) {
1589 packageName = _packageName;
1590 iconId = _iconId;
1591 }
1592
1593 ResourceName(ApplicationInfo aInfo, int _iconId) {
1594 this(aInfo.packageName, _iconId);
1595 }
1596
1597 ResourceName(ComponentInfo cInfo, int _iconId) {
1598 this(cInfo.applicationInfo.packageName, _iconId);
1599 }
1600
1601 ResourceName(ResolveInfo rInfo, int _iconId) {
1602 this(rInfo.activityInfo.applicationInfo.packageName, _iconId);
1603 }
1604
1605 @Override
1606 public boolean equals(Object o) {
1607 if (this == o) return true;
1608 if (o == null || getClass() != o.getClass()) return false;
1609
1610 ResourceName that = (ResourceName) o;
1611
1612 if (iconId != that.iconId) return false;
1613 return !(packageName != null ?
1614 !packageName.equals(that.packageName) : that.packageName != null);
1615
1616 }
1617
1618 @Override
1619 public int hashCode() {
1620 int result;
1621 result = packageName.hashCode();
1622 result = 31 * result + iconId;
1623 return result;
1624 }
1625
1626 @Override
1627 public String toString() {
1628 return "{ResourceName " + packageName + " / " + iconId + "}";
1629 }
1630 }
1631
1632 private CharSequence getCachedString(ResourceName name) {
1633 synchronized (sSync) {
1634 WeakReference<CharSequence> wr = sStringCache.get(name);
1635 if (wr != null) { // we have the activity
1636 CharSequence cs = wr.get();
1637 if (cs != null) {
1638 return cs;
1639 }
1640 // our entry has been purged
1641 sStringCache.remove(name);
1642 }
1643 }
1644 return null;
1645 }
1646
1647 private void putCachedString(ResourceName name, CharSequence cs) {
1648 synchronized (sSync) {
1649 sStringCache.put(name, new WeakReference<CharSequence>(cs));
1650 }
1651 }
1652
1653 @Override
Tor Norbye7b9c9122013-05-30 16:48:33 -07001654 public CharSequence getText(String packageName, @StringRes int resid,
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001655 ApplicationInfo appInfo) {
1656 ResourceName name = new ResourceName(packageName, resid);
1657 CharSequence text = getCachedString(name);
1658 if (text != null) {
1659 return text;
1660 }
1661 if (appInfo == null) {
1662 try {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001663 appInfo = getApplicationInfo(packageName, sDefaultFlags);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001664 } catch (NameNotFoundException e) {
1665 return null;
1666 }
1667 }
1668 try {
1669 Resources r = getResourcesForApplication(appInfo);
1670 text = r.getText(resid);
1671 putCachedString(name, text);
1672 return text;
1673 } catch (NameNotFoundException e) {
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07001674 Log.w("PackageManager", "Failure retrieving resources for "
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001675 + appInfo.packageName);
1676 } catch (RuntimeException e) {
1677 // If an exception was thrown, fall through to return
1678 // default icon.
1679 Log.w("PackageManager", "Failure retrieving text 0x"
1680 + Integer.toHexString(resid) + " in package "
1681 + packageName, e);
1682 }
1683 return null;
1684 }
1685
1686 @Override
Tor Norbye7b9c9122013-05-30 16:48:33 -07001687 public XmlResourceParser getXml(String packageName, @XmlRes int resid,
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001688 ApplicationInfo appInfo) {
1689 if (appInfo == null) {
1690 try {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001691 appInfo = getApplicationInfo(packageName, sDefaultFlags);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001692 } catch (NameNotFoundException e) {
1693 return null;
1694 }
1695 }
1696 try {
1697 Resources r = getResourcesForApplication(appInfo);
1698 return r.getXml(resid);
1699 } catch (RuntimeException e) {
1700 // If an exception was thrown, fall through to return
1701 // default icon.
1702 Log.w("PackageManager", "Failure retrieving xml 0x"
1703 + Integer.toHexString(resid) + " in package "
1704 + packageName, e);
1705 } catch (NameNotFoundException e) {
Alon Albert3fa51e32010-11-11 09:24:04 -08001706 Log.w("PackageManager", "Failure retrieving resources for "
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001707 + appInfo.packageName);
1708 }
1709 return null;
1710 }
1711
1712 @Override
1713 public CharSequence getApplicationLabel(ApplicationInfo info) {
1714 return info.loadLabel(this);
1715 }
1716
1717 @Override
Nicolas Prevot9a80e532015-09-23 15:49:28 +01001718 public int installExistingPackage(String packageName) throws NameNotFoundException {
Sunny Goyala31a74b2017-05-11 15:59:19 -07001719 return installExistingPackage(packageName, PackageManager.INSTALL_REASON_UNKNOWN);
1720 }
1721
1722 @Override
1723 public int installExistingPackage(String packageName, int installReason)
1724 throws NameNotFoundException {
1725 return installExistingPackageAsUser(packageName, installReason, mContext.getUserId());
Nicolas Prevot9a80e532015-09-23 15:49:28 +01001726 }
1727
1728 @Override
1729 public int installExistingPackageAsUser(String packageName, int userId)
Dianne Hackborn7767eac2012-08-23 18:25:40 -07001730 throws NameNotFoundException {
Sunny Goyala31a74b2017-05-11 15:59:19 -07001731 return installExistingPackageAsUser(packageName, PackageManager.INSTALL_REASON_UNKNOWN,
1732 userId);
1733 }
1734
1735 private int installExistingPackageAsUser(String packageName, int installReason, int userId)
1736 throws NameNotFoundException {
Dianne Hackborn7767eac2012-08-23 18:25:40 -07001737 try {
Todd Kennedybe0b8892017-02-15 14:13:52 -08001738 int res = mPM.installExistingPackageAsUser(packageName, userId, 0 /*installFlags*/,
Sunny Goyala31a74b2017-05-11 15:59:19 -07001739 installReason);
Dianne Hackborn7767eac2012-08-23 18:25:40 -07001740 if (res == INSTALL_FAILED_INVALID_URI) {
1741 throw new NameNotFoundException("Package " + packageName + " doesn't exist");
1742 }
1743 return res;
1744 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001745 throw e.rethrowFromSystemServer();
Dianne Hackborn7767eac2012-08-23 18:25:40 -07001746 }
1747 }
1748
1749 @Override
Kenny Root3a9b5fb2011-09-20 14:15:38 -07001750 public void verifyPendingInstall(int id, int response) {
Kenny Root5ab21572011-07-27 11:11:19 -07001751 try {
Kenny Root3a9b5fb2011-09-20 14:15:38 -07001752 mPM.verifyPendingInstall(id, response);
Kenny Root5ab21572011-07-27 11:11:19 -07001753 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001754 throw e.rethrowFromSystemServer();
Kenny Root5ab21572011-07-27 11:11:19 -07001755 }
1756 }
1757
1758 @Override
rich canningsd9ef3e52012-08-22 14:28:05 -07001759 public void extendVerificationTimeout(int id, int verificationCodeAtTimeout,
1760 long millisecondsToDelay) {
1761 try {
1762 mPM.extendVerificationTimeout(id, verificationCodeAtTimeout, millisecondsToDelay);
1763 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001764 throw e.rethrowFromSystemServer();
rich canningsd9ef3e52012-08-22 14:28:05 -07001765 }
1766 }
1767
1768 @Override
Todd Kennedydfa93ab2016-03-03 15:24:33 -08001769 public void verifyIntentFilter(int id, int verificationCode, List<String> failedDomains) {
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001770 try {
Todd Kennedydfa93ab2016-03-03 15:24:33 -08001771 mPM.verifyIntentFilter(id, verificationCode, failedDomains);
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001772 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001773 throw e.rethrowFromSystemServer();
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001774 }
1775 }
1776
1777 @Override
Jeff Sharkeye06b4d12016-01-06 14:51:50 -07001778 public int getIntentVerificationStatusAsUser(String packageName, int userId) {
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001779 try {
1780 return mPM.getIntentVerificationStatus(packageName, userId);
1781 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001782 throw e.rethrowFromSystemServer();
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001783 }
1784 }
1785
1786 @Override
Jeff Sharkeye06b4d12016-01-06 14:51:50 -07001787 public boolean updateIntentVerificationStatusAsUser(String packageName, int status, int userId) {
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001788 try {
1789 return mPM.updateIntentVerificationStatus(packageName, status, userId);
1790 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001791 throw e.rethrowFromSystemServer();
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001792 }
1793 }
1794
1795 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001796 @SuppressWarnings("unchecked")
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001797 public List<IntentFilterVerificationInfo> getIntentFilterVerifications(String packageName) {
1798 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001799 ParceledListSlice<IntentFilterVerificationInfo> parceledList =
1800 mPM.getIntentFilterVerifications(packageName);
1801 if (parceledList == null) {
1802 return Collections.emptyList();
1803 }
1804 return parceledList.getList();
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001805 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001806 throw e.rethrowFromSystemServer();
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001807 }
1808 }
1809
1810 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001811 @SuppressWarnings("unchecked")
Fabrice Di Meglio07885952015-04-06 19:41:28 -07001812 public List<IntentFilter> getAllIntentFilters(String packageName) {
1813 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001814 ParceledListSlice<IntentFilter> parceledList =
1815 mPM.getAllIntentFilters(packageName);
1816 if (parceledList == null) {
1817 return Collections.emptyList();
1818 }
1819 return parceledList.getList();
Fabrice Di Meglio07885952015-04-06 19:41:28 -07001820 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001821 throw e.rethrowFromSystemServer();
Fabrice Di Meglio07885952015-04-06 19:41:28 -07001822 }
1823 }
1824
1825 @Override
Jeff Sharkeye06b4d12016-01-06 14:51:50 -07001826 public String getDefaultBrowserPackageNameAsUser(int userId) {
Fabrice Di Meglio62271722015-04-10 17:24:02 -07001827 try {
1828 return mPM.getDefaultBrowserPackageName(userId);
1829 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001830 throw e.rethrowFromSystemServer();
Fabrice Di Meglio62271722015-04-10 17:24:02 -07001831 }
1832 }
1833
1834 @Override
Jeff Sharkeye06b4d12016-01-06 14:51:50 -07001835 public boolean setDefaultBrowserPackageNameAsUser(String packageName, int userId) {
Fabrice Di Meglio62271722015-04-10 17:24:02 -07001836 try {
1837 return mPM.setDefaultBrowserPackageName(packageName, userId);
1838 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001839 throw e.rethrowFromSystemServer();
Fabrice Di Meglio62271722015-04-10 17:24:02 -07001840 }
1841 }
1842
1843 @Override
Dianne Hackborn880119b2010-11-18 22:26:40 -08001844 public void setInstallerPackageName(String targetPackage,
1845 String installerPackageName) {
1846 try {
1847 mPM.setInstallerPackageName(targetPackage, installerPackageName);
1848 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001849 throw e.rethrowFromSystemServer();
Dianne Hackborn880119b2010-11-18 22:26:40 -08001850 }
1851 }
1852
1853 @Override
Todd Kennedyab532892017-03-08 14:19:49 -08001854 public void setUpdateAvailable(String packageName, boolean updateAvailable) {
1855 try {
1856 mPM.setUpdateAvailable(packageName, updateAvailable);
1857 } catch (RemoteException e) {
1858 throw e.rethrowFromSystemServer();
1859 }
1860 }
1861
1862 @Override
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001863 public String getInstallerPackageName(String packageName) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001864 try {
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001865 return mPM.getInstallerPackageName(packageName);
1866 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001867 throw e.rethrowFromSystemServer();
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001868 }
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001869 }
1870
1871 @Override
1872 public int getMoveStatus(int moveId) {
1873 try {
1874 return mPM.getMoveStatus(moveId);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001875 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001876 throw e.rethrowFromSystemServer();
Jeff Sharkeyb2b9ab82015-04-05 21:10:42 -07001877 }
1878 }
1879
1880 @Override
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001881 public void registerMoveCallback(MoveCallback callback, Handler handler) {
1882 synchronized (mDelegates) {
1883 final MoveCallbackDelegate delegate = new MoveCallbackDelegate(callback,
1884 handler.getLooper());
1885 try {
1886 mPM.registerMoveCallback(delegate);
1887 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001888 throw e.rethrowFromSystemServer();
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001889 }
1890 mDelegates.add(delegate);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001891 }
1892 }
1893
1894 @Override
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001895 public void unregisterMoveCallback(MoveCallback callback) {
1896 synchronized (mDelegates) {
1897 for (Iterator<MoveCallbackDelegate> i = mDelegates.iterator(); i.hasNext();) {
1898 final MoveCallbackDelegate delegate = i.next();
1899 if (delegate.mCallback == callback) {
1900 try {
1901 mPM.unregisterMoveCallback(delegate);
1902 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001903 throw e.rethrowFromSystemServer();
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001904 }
1905 i.remove();
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001906 }
1907 }
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001908 }
1909 }
1910
1911 @Override
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001912 public int movePackage(String packageName, VolumeInfo vol) {
1913 try {
1914 final String volumeUuid;
1915 if (VolumeInfo.ID_PRIVATE_INTERNAL.equals(vol.id)) {
1916 volumeUuid = StorageManager.UUID_PRIVATE_INTERNAL;
1917 } else if (vol.isPrimaryPhysical()) {
1918 volumeUuid = StorageManager.UUID_PRIMARY_PHYSICAL;
1919 } else {
1920 volumeUuid = Preconditions.checkNotNull(vol.fsUuid);
1921 }
1922
1923 return mPM.movePackage(packageName, volumeUuid);
1924 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001925 throw e.rethrowFromSystemServer();
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001926 }
1927 }
1928
1929 @Override
1930 public @Nullable VolumeInfo getPackageCurrentVolume(ApplicationInfo app) {
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001931 final StorageManager storage = mContext.getSystemService(StorageManager.class);
Yao Chen022b8ea2016-12-16 11:03:28 -08001932 return getPackageCurrentVolume(app, storage);
1933 }
1934
1935 @VisibleForTesting
1936 protected @Nullable VolumeInfo getPackageCurrentVolume(ApplicationInfo app,
1937 StorageManager storage) {
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001938 if (app.isInternal()) {
1939 return storage.findVolumeById(VolumeInfo.ID_PRIVATE_INTERNAL);
1940 } else if (app.isExternalAsec()) {
1941 return storage.getPrimaryPhysicalVolume();
1942 } else {
1943 return storage.findVolumeByUuid(app.volumeUuid);
1944 }
1945 }
1946
1947 @Override
1948 public @NonNull List<VolumeInfo> getPackageCandidateVolumes(ApplicationInfo app) {
Yao Chen022b8ea2016-12-16 11:03:28 -08001949 final StorageManager storageManager = mContext.getSystemService(StorageManager.class);
1950 return getPackageCandidateVolumes(app, storageManager, mPM);
1951 }
1952
1953 @VisibleForTesting
1954 protected @NonNull List<VolumeInfo> getPackageCandidateVolumes(ApplicationInfo app,
1955 StorageManager storageManager, IPackageManager pm) {
1956 final VolumeInfo currentVol = getPackageCurrentVolume(app, storageManager);
1957 final List<VolumeInfo> vols = storageManager.getVolumes();
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001958 final List<VolumeInfo> candidates = new ArrayList<>();
1959 for (VolumeInfo vol : vols) {
Yao Chen022b8ea2016-12-16 11:03:28 -08001960 if (Objects.equals(vol, currentVol)
1961 || isPackageCandidateVolume(mContext, app, vol, pm)) {
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001962 candidates.add(vol);
1963 }
1964 }
1965 return candidates;
1966 }
1967
Yao Chen022b8ea2016-12-16 11:03:28 -08001968 @VisibleForTesting
1969 protected boolean isForceAllowOnExternal(Context context) {
1970 return Settings.Global.getInt(
Todd Kennedyf39ca8f2015-08-07 14:15:07 -07001971 context.getContentResolver(), Settings.Global.FORCE_ALLOW_ON_EXTERNAL, 0) != 0;
Yao Chen022b8ea2016-12-16 11:03:28 -08001972 }
1973
1974 @VisibleForTesting
1975 protected boolean isAllow3rdPartyOnInternal(Context context) {
1976 return context.getResources().getBoolean(
1977 com.android.internal.R.bool.config_allow3rdPartyAppOnInternal);
1978 }
1979
1980 private boolean isPackageCandidateVolume(
1981 ContextImpl context, ApplicationInfo app, VolumeInfo vol, IPackageManager pm) {
1982 final boolean forceAllowOnExternal = isForceAllowOnExternal(context);
1983
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001984 if (VolumeInfo.ID_PRIVATE_INTERNAL.equals(vol.getId())) {
Yao Chen022b8ea2016-12-16 11:03:28 -08001985 return app.isSystemApp() || isAllow3rdPartyOnInternal(context);
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001986 }
1987
1988 // System apps and apps demanding internal storage can't be moved
1989 // anywhere else
Todd Kennedyf39ca8f2015-08-07 14:15:07 -07001990 if (app.isSystemApp()) {
1991 return false;
1992 }
1993 if (!forceAllowOnExternal
Dianne Hackborn30a4e6d2015-10-12 17:14:56 -07001994 && (app.installLocation == PackageInfo.INSTALL_LOCATION_INTERNAL_ONLY
1995 || app.installLocation == PackageInfo.INSTALL_LOCATION_UNSPECIFIED)) {
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001996 return false;
1997 }
1998
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001999 // Gotta be able to write there
2000 if (!vol.isMountedWritable()) {
2001 return false;
2002 }
2003
2004 // Moving into an ASEC on public primary is only option internal
2005 if (vol.isPrimaryPhysical()) {
2006 return app.isInternal();
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07002007 }
2008
Makoto Onukif34db0a2016-02-17 11:17:15 -08002009 // Some apps can't be moved. (e.g. device admins)
2010 try {
Yao Chen022b8ea2016-12-16 11:03:28 -08002011 if (pm.isPackageDeviceAdminOnAnyUser(app.packageName)) {
Makoto Onukif34db0a2016-02-17 11:17:15 -08002012 return false;
2013 }
2014 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002015 throw e.rethrowFromSystemServer();
Makoto Onukif34db0a2016-02-17 11:17:15 -08002016 }
2017
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07002018 // Otherwise we can move to any private volume
2019 return (vol.getType() == VolumeInfo.TYPE_PRIVATE);
2020 }
2021
2022 @Override
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002023 public int movePrimaryStorage(VolumeInfo vol) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002024 try {
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002025 final String volumeUuid;
2026 if (VolumeInfo.ID_PRIVATE_INTERNAL.equals(vol.id)) {
2027 volumeUuid = StorageManager.UUID_PRIVATE_INTERNAL;
2028 } else if (vol.isPrimaryPhysical()) {
2029 volumeUuid = StorageManager.UUID_PRIMARY_PHYSICAL;
2030 } else {
2031 volumeUuid = Preconditions.checkNotNull(vol.fsUuid);
2032 }
2033
2034 return mPM.movePrimaryStorage(volumeUuid);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002035 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002036 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002037 }
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002038 }
2039
Jeff Sharkey275e3e42015-04-24 16:10:32 -07002040 @Override
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002041 public @Nullable VolumeInfo getPrimaryStorageCurrentVolume() {
2042 final StorageManager storage = mContext.getSystemService(StorageManager.class);
2043 final String volumeUuid = storage.getPrimaryStorageUuid();
Jeff Sharkey50a05452015-04-29 11:24:52 -07002044 return storage.findVolumeByQualifiedUuid(volumeUuid);
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 @NonNull List<VolumeInfo> getPrimaryStorageCandidateVolumes() {
2049 final StorageManager storage = mContext.getSystemService(StorageManager.class);
2050 final VolumeInfo currentVol = getPrimaryStorageCurrentVolume();
2051 final List<VolumeInfo> vols = storage.getVolumes();
2052 final List<VolumeInfo> candidates = new ArrayList<>();
Jeff Sharkeyfced5342015-05-10 14:53:34 -07002053 if (Objects.equals(StorageManager.UUID_PRIMARY_PHYSICAL,
2054 storage.getPrimaryStorageUuid()) && currentVol != null) {
2055 // TODO: support moving primary physical to emulated volume
2056 candidates.add(currentVol);
2057 } else {
2058 for (VolumeInfo vol : vols) {
2059 if (Objects.equals(vol, currentVol) || isPrimaryStorageCandidateVolume(vol)) {
2060 candidates.add(vol);
2061 }
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002062 }
2063 }
2064 return candidates;
2065 }
2066
2067 private static boolean isPrimaryStorageCandidateVolume(VolumeInfo vol) {
2068 // Private internal is always an option
2069 if (VolumeInfo.ID_PRIVATE_INTERNAL.equals(vol.getId())) {
2070 return true;
2071 }
2072
2073 // Gotta be able to write there
2074 if (!vol.isMountedWritable()) {
2075 return false;
2076 }
2077
Jeff Sharkeyfced5342015-05-10 14:53:34 -07002078 // We can move to any private volume
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002079 return (vol.getType() == VolumeInfo.TYPE_PRIVATE);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002080 }
2081
2082 @Override
2083 public void deletePackage(String packageName, IPackageDeleteObserver observer, int flags) {
Robin Lee0e27c872015-09-28 14:37:40 +01002084 deletePackageAsUser(packageName, observer, flags, mContext.getUserId());
Nicolas Prevot9a80e532015-09-23 15:49:28 +01002085 }
2086
2087 @Override
Svet Ganov67882122016-12-11 16:36:34 -08002088 public void deletePackageAsUser(String packageName, IPackageDeleteObserver observer,
2089 int flags, int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002090 try {
Svet Ganov67882122016-12-11 16:36:34 -08002091 mPM.deletePackageAsUser(packageName, PackageManager.VERSION_CODE_HIGHEST,
2092 observer, userId, flags);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002093 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002094 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002095 }
2096 }
Jeff Sharkeyfbd0e9f2014-08-06 16:34:34 -07002097
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002098 @Override
2099 public void clearApplicationUserData(String packageName,
2100 IPackageDataObserver observer) {
2101 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -07002102 mPM.clearApplicationUserData(packageName, observer, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002103 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002104 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002105 }
2106 }
2107 @Override
2108 public void deleteApplicationCacheFiles(String packageName,
2109 IPackageDataObserver observer) {
2110 try {
2111 mPM.deleteApplicationCacheFiles(packageName, observer);
2112 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002113 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002114 }
2115 }
Jeff Sharkey529f91f2015-04-18 20:23:13 -07002116
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002117 @Override
Suprabh Shukla78c9eb82016-04-12 15:51:35 -07002118 public void deleteApplicationCacheFilesAsUser(String packageName, int userId,
2119 IPackageDataObserver observer) {
2120 try {
2121 mPM.deleteApplicationCacheFilesAsUser(packageName, userId, observer);
2122 } catch (RemoteException e) {
2123 throw e.rethrowFromSystemServer();
2124 }
2125 }
2126
2127 @Override
Jeff Sharkey529f91f2015-04-18 20:23:13 -07002128 public void freeStorageAndNotify(String volumeUuid, long idealStorageSize,
2129 IPackageDataObserver observer) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002130 try {
Jeff Sharkeyddff8072017-05-26 13:10:46 -06002131 mPM.freeStorageAndNotify(volumeUuid, idealStorageSize, 0, observer);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002132 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002133 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002134 }
2135 }
2136
2137 @Override
Jeff Sharkey529f91f2015-04-18 20:23:13 -07002138 public void freeStorage(String volumeUuid, long freeStorageSize, IntentSender pi) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002139 try {
Jeff Sharkeyddff8072017-05-26 13:10:46 -06002140 mPM.freeStorage(volumeUuid, freeStorageSize, 0, pi);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002141 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002142 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002143 }
2144 }
2145
2146 @Override
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00002147 public String[] setPackagesSuspendedAsUser(String[] packageNames, boolean suspended,
2148 int userId) {
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00002149 try {
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00002150 return mPM.setPackagesSuspendedAsUser(packageNames, suspended, userId);
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00002151 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002152 throw e.rethrowFromSystemServer();
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00002153 }
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00002154 }
2155
2156 @Override
Andrei Stingaceanu355b2322016-02-12 16:43:51 +00002157 public boolean isPackageSuspendedForUser(String packageName, int userId) {
2158 try {
2159 return mPM.isPackageSuspendedForUser(packageName, userId);
2160 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002161 throw e.rethrowFromSystemServer();
Andrei Stingaceanu355b2322016-02-12 16:43:51 +00002162 }
Andrei Stingaceanu355b2322016-02-12 16:43:51 +00002163 }
2164
Jeff Sharkey9bc89af2017-01-11 11:25:50 -07002165 /** @hide */
2166 @Override
2167 public void setApplicationCategoryHint(String packageName, int categoryHint) {
2168 try {
2169 mPM.setApplicationCategoryHint(packageName, categoryHint,
2170 mContext.getOpPackageName());
2171 } catch (RemoteException e) {
2172 throw e.rethrowFromSystemServer();
2173 }
2174 }
2175
Andrei Stingaceanu355b2322016-02-12 16:43:51 +00002176 @Override
Jeff Sharkeye06b4d12016-01-06 14:51:50 -07002177 public void getPackageSizeInfoAsUser(String packageName, int userHandle,
Dianne Hackborn0c380492012-08-20 17:23:30 -07002178 IPackageStatsObserver observer) {
Jeff Sharkey6f4b2a32017-03-21 14:13:41 -06002179 final String msg = "Shame on you for calling the hidden API "
2180 + "getPackageSizeInfoAsUser(). Shame!";
Jeff Sharkeye6306c42017-03-07 21:03:18 -07002181 if (mContext.getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.O) {
Jeff Sharkey6f4b2a32017-03-21 14:13:41 -06002182 throw new UnsupportedOperationException(msg);
Jeff Sharkeye6306c42017-03-07 21:03:18 -07002183 } else if (observer != null) {
Jeff Sharkey6f4b2a32017-03-21 14:13:41 -06002184 Log.d(TAG, msg);
Jeff Sharkeye6306c42017-03-07 21:03:18 -07002185 try {
2186 observer.onGetStatsCompleted(null, false);
2187 } catch (RemoteException ignored) {
2188 }
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002189 }
2190 }
Jeff Sharkeyd5896632016-03-04 16:16:00 -07002191
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002192 @Override
2193 public void addPackageToPreferred(String packageName) {
Jeff Sharkeyd5896632016-03-04 16:16:00 -07002194 Log.w(TAG, "addPackageToPreferred() is a no-op");
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002195 }
2196
2197 @Override
2198 public void removePackageFromPreferred(String packageName) {
Jeff Sharkeyd5896632016-03-04 16:16:00 -07002199 Log.w(TAG, "removePackageFromPreferred() is a no-op");
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002200 }
2201
2202 @Override
2203 public List<PackageInfo> getPreferredPackages(int flags) {
Jeff Sharkeyd5896632016-03-04 16:16:00 -07002204 Log.w(TAG, "getPreferredPackages() is a no-op");
2205 return Collections.emptyList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002206 }
2207
2208 @Override
2209 public void addPreferredActivity(IntentFilter filter,
2210 int match, ComponentName[] set, ComponentName activity) {
2211 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -07002212 mPM.addPreferredActivity(filter, match, set, activity, mContext.getUserId());
Amith Yamasania3f133a2012-08-09 17:11:28 -07002213 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002214 throw e.rethrowFromSystemServer();
Amith Yamasania3f133a2012-08-09 17:11:28 -07002215 }
2216 }
2217
2218 @Override
Jeff Sharkeye06b4d12016-01-06 14:51:50 -07002219 public void addPreferredActivityAsUser(IntentFilter filter, int match,
Amith Yamasania3f133a2012-08-09 17:11:28 -07002220 ComponentName[] set, ComponentName activity, int userId) {
2221 try {
2222 mPM.addPreferredActivity(filter, match, set, activity, userId);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002223 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002224 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002225 }
2226 }
2227
2228 @Override
2229 public void replacePreferredActivity(IntentFilter filter,
2230 int match, ComponentName[] set, ComponentName activity) {
2231 try {
Robin Lee0e27c872015-09-28 14:37:40 +01002232 mPM.replacePreferredActivity(filter, match, set, activity, mContext.getUserId());
Amith Yamasani41c1ded2014-08-05 11:15:05 -07002233 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002234 throw e.rethrowFromSystemServer();
Amith Yamasani41c1ded2014-08-05 11:15:05 -07002235 }
2236 }
2237
2238 @Override
2239 public void replacePreferredActivityAsUser(IntentFilter filter,
2240 int match, ComponentName[] set, ComponentName activity,
2241 int userId) {
2242 try {
2243 mPM.replacePreferredActivity(filter, match, set, activity, userId);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002244 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002245 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002246 }
2247 }
2248
2249 @Override
2250 public void clearPackagePreferredActivities(String packageName) {
2251 try {
2252 mPM.clearPackagePreferredActivities(packageName);
2253 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002254 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002255 }
2256 }
2257
2258 @Override
2259 public int getPreferredActivities(List<IntentFilter> outFilters,
2260 List<ComponentName> outActivities, String packageName) {
2261 try {
2262 return mPM.getPreferredActivities(outFilters, outActivities, packageName);
2263 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002264 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002265 }
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002266 }
2267
2268 @Override
Christopher Tatea2a0850d2013-09-05 16:38:58 -07002269 public ComponentName getHomeActivities(List<ResolveInfo> outActivities) {
2270 try {
2271 return mPM.getHomeActivities(outActivities);
2272 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002273 throw e.rethrowFromSystemServer();
Christopher Tatea2a0850d2013-09-05 16:38:58 -07002274 }
Christopher Tatea2a0850d2013-09-05 16:38:58 -07002275 }
2276
2277 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002278 public void setComponentEnabledSetting(ComponentName componentName,
2279 int newState, int flags) {
2280 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -07002281 mPM.setComponentEnabledSetting(componentName, newState, flags, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002282 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002283 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002284 }
2285 }
2286
2287 @Override
2288 public int getComponentEnabledSetting(ComponentName componentName) {
2289 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -07002290 return mPM.getComponentEnabledSetting(componentName, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002291 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002292 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002293 }
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002294 }
2295
2296 @Override
2297 public void setApplicationEnabledSetting(String packageName,
2298 int newState, int flags) {
2299 try {
Dianne Hackborn3fa3c28a2013-03-26 16:15:41 -07002300 mPM.setApplicationEnabledSetting(packageName, newState, flags,
Dianne Hackborn95d78532013-09-11 09:51:14 -07002301 mContext.getUserId(), mContext.getOpPackageName());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002302 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002303 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002304 }
2305 }
2306
2307 @Override
2308 public int getApplicationEnabledSetting(String packageName) {
2309 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -07002310 return mPM.getApplicationEnabledSetting(packageName, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002311 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002312 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002313 }
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002314 }
2315
Amith Yamasani655d0e22013-06-12 14:19:10 -07002316 @Override
Sudheer Shankabbb3ff22015-07-09 15:39:23 +01002317 public void flushPackageRestrictionsAsUser(int userId) {
2318 try {
2319 mPM.flushPackageRestrictionsAsUser(userId);
2320 } catch (RemoteException e) {
2321 throw e.rethrowFromSystemServer();
2322 }
2323 }
2324
2325 @Override
Amith Yamasanie5bcff62014-07-19 15:44:09 -07002326 public boolean setApplicationHiddenSettingAsUser(String packageName, boolean hidden,
Amith Yamasani655d0e22013-06-12 14:19:10 -07002327 UserHandle user) {
2328 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07002329 return mPM.setApplicationHiddenSettingAsUser(packageName, hidden,
Amith Yamasani655d0e22013-06-12 14:19:10 -07002330 user.getIdentifier());
Jeff Sharkey27b2e692016-02-25 17:40:12 -07002331 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002332 throw e.rethrowFromSystemServer();
Amith Yamasani655d0e22013-06-12 14:19:10 -07002333 }
Amith Yamasani655d0e22013-06-12 14:19:10 -07002334 }
2335
2336 @Override
Amith Yamasanie5bcff62014-07-19 15:44:09 -07002337 public boolean getApplicationHiddenSettingAsUser(String packageName, UserHandle user) {
Amith Yamasani655d0e22013-06-12 14:19:10 -07002338 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07002339 return mPM.getApplicationHiddenSettingAsUser(packageName, user.getIdentifier());
Jeff Sharkey27b2e692016-02-25 17:40:12 -07002340 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002341 throw e.rethrowFromSystemServer();
Amith Yamasani655d0e22013-06-12 14:19:10 -07002342 }
Amith Yamasani655d0e22013-06-12 14:19:10 -07002343 }
2344
dcashmanc6f22492014-08-14 09:54:51 -07002345 /** @hide */
dcashman9d2f4412014-06-09 09:27:54 -07002346 @Override
2347 public KeySet getKeySetByAlias(String packageName, String alias) {
2348 Preconditions.checkNotNull(packageName);
2349 Preconditions.checkNotNull(alias);
dcashman9d2f4412014-06-09 09:27:54 -07002350 try {
Jeff Sharkey27b2e692016-02-25 17:40:12 -07002351 return mPM.getKeySetByAlias(packageName, alias);
dcashman9d2f4412014-06-09 09:27:54 -07002352 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002353 throw e.rethrowFromSystemServer();
dcashman9d2f4412014-06-09 09:27:54 -07002354 }
dcashman9d2f4412014-06-09 09:27:54 -07002355 }
2356
dcashmanc6f22492014-08-14 09:54:51 -07002357 /** @hide */
dcashman9d2f4412014-06-09 09:27:54 -07002358 @Override
2359 public KeySet getSigningKeySet(String packageName) {
2360 Preconditions.checkNotNull(packageName);
dcashman9d2f4412014-06-09 09:27:54 -07002361 try {
Jeff Sharkey27b2e692016-02-25 17:40:12 -07002362 return mPM.getSigningKeySet(packageName);
dcashman9d2f4412014-06-09 09:27:54 -07002363 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002364 throw e.rethrowFromSystemServer();
dcashman9d2f4412014-06-09 09:27:54 -07002365 }
dcashman9d2f4412014-06-09 09:27:54 -07002366 }
2367
dcashmanc6f22492014-08-14 09:54:51 -07002368 /** @hide */
dcashman9d2f4412014-06-09 09:27:54 -07002369 @Override
2370 public boolean isSignedBy(String packageName, KeySet ks) {
2371 Preconditions.checkNotNull(packageName);
2372 Preconditions.checkNotNull(ks);
dcashman9d2f4412014-06-09 09:27:54 -07002373 try {
dcashmanc6f22492014-08-14 09:54:51 -07002374 return mPM.isPackageSignedByKeySet(packageName, ks);
dcashman9d2f4412014-06-09 09:27:54 -07002375 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002376 throw e.rethrowFromSystemServer();
dcashman9d2f4412014-06-09 09:27:54 -07002377 }
2378 }
2379
dcashmanc6f22492014-08-14 09:54:51 -07002380 /** @hide */
dcashman9d2f4412014-06-09 09:27:54 -07002381 @Override
2382 public boolean isSignedByExactly(String packageName, KeySet ks) {
2383 Preconditions.checkNotNull(packageName);
2384 Preconditions.checkNotNull(ks);
dcashman9d2f4412014-06-09 09:27:54 -07002385 try {
dcashmanc6f22492014-08-14 09:54:51 -07002386 return mPM.isPackageSignedByKeySetExactly(packageName, ks);
dcashman9d2f4412014-06-09 09:27:54 -07002387 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002388 throw e.rethrowFromSystemServer();
dcashman9d2f4412014-06-09 09:27:54 -07002389 }
2390 }
2391
Kenny Root0aaa0d92011-09-12 16:42:55 -07002392 /**
2393 * @hide
2394 */
2395 @Override
2396 public VerifierDeviceIdentity getVerifierDeviceIdentity() {
2397 try {
2398 return mPM.getVerifierDeviceIdentity();
2399 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002400 throw e.rethrowFromSystemServer();
Kenny Root0aaa0d92011-09-12 16:42:55 -07002401 }
Kenny Root0aaa0d92011-09-12 16:42:55 -07002402 }
2403
Jeff Hao9f60c082014-10-28 18:51:07 -07002404 /**
2405 * @hide
2406 */
2407 @Override
2408 public boolean isUpgrade() {
2409 try {
2410 return mPM.isUpgrade();
2411 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002412 throw e.rethrowFromSystemServer();
Jeff Hao9f60c082014-10-28 18:51:07 -07002413 }
2414 }
2415
Jeff Sharkey3a44f3f2014-04-28 17:36:31 -07002416 @Override
Jeff Sharkey16c8e3f2014-07-24 17:08:17 -07002417 public PackageInstaller getPackageInstaller() {
2418 synchronized (mLock) {
2419 if (mInstaller == null) {
2420 try {
Svet Ganov67882122016-12-11 16:36:34 -08002421 mInstaller = new PackageInstaller(mPM.getPackageInstaller(),
Jeff Sharkey16c8e3f2014-07-24 17:08:17 -07002422 mContext.getPackageName(), mContext.getUserId());
2423 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002424 throw e.rethrowFromSystemServer();
Jeff Sharkey16c8e3f2014-07-24 17:08:17 -07002425 }
2426 }
2427 return mInstaller;
Jeff Sharkey3a44f3f2014-04-28 17:36:31 -07002428 }
2429 }
2430
Jeff Sharkey6c833e02014-07-14 22:44:30 -07002431 @Override
2432 public boolean isPackageAvailable(String packageName) {
2433 try {
2434 return mPM.isPackageAvailable(packageName, mContext.getUserId());
2435 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002436 throw e.rethrowFromSystemServer();
Jeff Sharkey6c833e02014-07-14 22:44:30 -07002437 }
2438 }
2439
Nicolas Prevotc79586e2014-05-06 12:47:57 +01002440 /**
2441 * @hide
2442 */
2443 @Override
Nicolas Prevot63798c52014-05-27 13:22:38 +01002444 public void addCrossProfileIntentFilter(IntentFilter filter, int sourceUserId, int targetUserId,
2445 int flags) {
Nicolas Prevotc79586e2014-05-06 12:47:57 +01002446 try {
Nicolas Prevot3f7777f2014-07-24 15:58:39 +01002447 mPM.addCrossProfileIntentFilter(filter, mContext.getOpPackageName(),
Nicolas Prevot4b8d5822015-03-05 15:20:49 +00002448 sourceUserId, targetUserId, flags);
Nicolas Prevotc79586e2014-05-06 12:47:57 +01002449 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002450 throw e.rethrowFromSystemServer();
Nicolas Prevotc79586e2014-05-06 12:47:57 +01002451 }
2452 }
2453
2454 /**
2455 * @hide
2456 */
2457 @Override
Nicolas Prevot81948992014-05-16 18:25:26 +01002458 public void clearCrossProfileIntentFilters(int sourceUserId) {
Nicolas Prevotc79586e2014-05-06 12:47:57 +01002459 try {
Nicolas Prevot4b8d5822015-03-05 15:20:49 +00002460 mPM.clearCrossProfileIntentFilters(sourceUserId, mContext.getOpPackageName());
Nicolas Prevotc79586e2014-05-06 12:47:57 +01002461 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002462 throw e.rethrowFromSystemServer();
Nicolas Prevotc79586e2014-05-06 12:47:57 +01002463 }
2464 }
2465
Nicolas Prevot88cc3462014-05-14 14:51:48 +01002466 /**
2467 * @hide
2468 */
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +01002469 public Drawable loadItemIcon(PackageItemInfo itemInfo, ApplicationInfo appInfo) {
Benjamin Franzec2d48b2014-10-01 15:38:43 +01002470 Drawable dr = loadUnbadgedItemIcon(itemInfo, appInfo);
2471 if (itemInfo.showUserIcon != UserHandle.USER_NULL) {
2472 return dr;
2473 }
2474 return getUserBadgedIcon(dr, new UserHandle(mContext.getUserId()));
2475 }
2476
2477 /**
2478 * @hide
2479 */
2480 public Drawable loadUnbadgedItemIcon(PackageItemInfo itemInfo, ApplicationInfo appInfo) {
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +01002481 if (itemInfo.showUserIcon != UserHandle.USER_NULL) {
Alexandra Gherghina64d4dca2014-08-28 18:26:56 +01002482 Bitmap bitmap = getUserManager().getUserIcon(itemInfo.showUserIcon);
2483 if (bitmap == null) {
Tony Mak213955e2017-11-23 16:57:08 +08002484 return UserIcons.getDefaultUserIcon(
2485 mContext.getResources(), itemInfo.showUserIcon, /* light= */ false);
Alexandra Gherghina64d4dca2014-08-28 18:26:56 +01002486 }
2487 return new BitmapDrawable(bitmap);
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +01002488 }
Alexandra Gherghinadb811db2014-08-29 13:43:59 +01002489 Drawable dr = null;
2490 if (itemInfo.packageName != null) {
2491 dr = getDrawable(itemInfo.packageName, itemInfo.icon, appInfo);
2492 }
Alexandra Gherghinaa71e3902014-07-25 20:03:47 +01002493 if (dr == null) {
Alexandra Gherghinaa7093142014-07-30 13:43:39 +01002494 dr = itemInfo.loadDefaultIcon(this);
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +01002495 }
Benjamin Franzec2d48b2014-10-01 15:38:43 +01002496 return dr;
Svetoslavc7d62f02014-09-04 15:39:54 -07002497 }
2498
2499 private Drawable getBadgedDrawable(Drawable drawable, Drawable badgeDrawable,
2500 Rect badgeLocation, boolean tryBadgeInPlace) {
2501 final int badgedWidth = drawable.getIntrinsicWidth();
2502 final int badgedHeight = drawable.getIntrinsicHeight();
2503 final boolean canBadgeInPlace = tryBadgeInPlace
2504 && (drawable instanceof BitmapDrawable)
2505 && ((BitmapDrawable) drawable).getBitmap().isMutable();
2506
2507 final Bitmap bitmap;
2508 if (canBadgeInPlace) {
2509 bitmap = ((BitmapDrawable) drawable).getBitmap();
2510 } else {
2511 bitmap = Bitmap.createBitmap(badgedWidth, badgedHeight, Bitmap.Config.ARGB_8888);
2512 }
2513 Canvas canvas = new Canvas(bitmap);
2514
2515 if (!canBadgeInPlace) {
2516 drawable.setBounds(0, 0, badgedWidth, badgedHeight);
2517 drawable.draw(canvas);
2518 }
2519
2520 if (badgeLocation != null) {
2521 if (badgeLocation.left < 0 || badgeLocation.top < 0
2522 || badgeLocation.width() > badgedWidth || badgeLocation.height() > badgedHeight) {
2523 throw new IllegalArgumentException("Badge location " + badgeLocation
2524 + " not in badged drawable bounds "
2525 + new Rect(0, 0, badgedWidth, badgedHeight));
2526 }
2527 badgeDrawable.setBounds(0, 0, badgeLocation.width(), badgeLocation.height());
2528
2529 canvas.save();
2530 canvas.translate(badgeLocation.left, badgeLocation.top);
2531 badgeDrawable.draw(canvas);
2532 canvas.restore();
2533 } else {
2534 badgeDrawable.setBounds(0, 0, badgedWidth, badgedHeight);
2535 badgeDrawable.draw(canvas);
2536 }
2537
2538 if (!canBadgeInPlace) {
2539 BitmapDrawable mergedDrawable = new BitmapDrawable(mContext.getResources(), bitmap);
2540
2541 if (drawable instanceof BitmapDrawable) {
2542 BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
2543 mergedDrawable.setTargetDensity(bitmapDrawable.getBitmap().getDensity());
2544 }
2545
2546 return mergedDrawable;
2547 }
2548
2549 return drawable;
2550 }
2551
Tony Mak8673b282016-03-21 21:10:59 +00002552 private boolean isManagedProfile(int userId) {
2553 return getUserManager().isManagedProfile(userId);
Nicolas Prevot88cc3462014-05-14 14:51:48 +01002554 }
2555
Bartosz Fabianowskia34f53f2017-01-11 18:08:47 +01002556 /**
2557 * @hide
2558 */
2559 @Override
2560 public int getInstallReason(String packageName, UserHandle user) {
2561 try {
2562 return mPM.getInstallReason(packageName, user.getIdentifier());
2563 } catch (RemoteException e) {
2564 throw e.rethrowFromSystemServer();
2565 }
2566 }
2567
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002568 /** {@hide} */
2569 private static class MoveCallbackDelegate extends IPackageMoveObserver.Stub implements
2570 Handler.Callback {
Jeff Sharkey50a05452015-04-29 11:24:52 -07002571 private static final int MSG_CREATED = 1;
2572 private static final int MSG_STATUS_CHANGED = 2;
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002573
2574 final MoveCallback mCallback;
2575 final Handler mHandler;
2576
2577 public MoveCallbackDelegate(MoveCallback callback, Looper looper) {
2578 mCallback = callback;
2579 mHandler = new Handler(looper, this);
2580 }
2581
2582 @Override
2583 public boolean handleMessage(Message msg) {
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002584 switch (msg.what) {
Jeff Sharkey50a05452015-04-29 11:24:52 -07002585 case MSG_CREATED: {
Jeff Sharkeyb36586a2015-04-27 08:42:28 -07002586 final SomeArgs args = (SomeArgs) msg.obj;
Jeff Sharkey50a05452015-04-29 11:24:52 -07002587 mCallback.onCreated(args.argi1, (Bundle) args.arg2);
Jeff Sharkeyb36586a2015-04-27 08:42:28 -07002588 args.recycle();
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002589 return true;
Jeff Sharkey50a05452015-04-29 11:24:52 -07002590 }
2591 case MSG_STATUS_CHANGED: {
2592 final SomeArgs args = (SomeArgs) msg.obj;
2593 mCallback.onStatusChanged(args.argi1, args.argi2, (long) args.arg3);
2594 args.recycle();
2595 return true;
2596 }
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002597 }
2598 return false;
2599 }
2600
2601 @Override
Jeff Sharkey50a05452015-04-29 11:24:52 -07002602 public void onCreated(int moveId, Bundle extras) {
Jeff Sharkeyb36586a2015-04-27 08:42:28 -07002603 final SomeArgs args = SomeArgs.obtain();
2604 args.argi1 = moveId;
Jeff Sharkey50a05452015-04-29 11:24:52 -07002605 args.arg2 = extras;
2606 mHandler.obtainMessage(MSG_CREATED, args).sendToTarget();
2607 }
2608
2609 @Override
2610 public void onStatusChanged(int moveId, int status, long estMillis) {
2611 final SomeArgs args = SomeArgs.obtain();
2612 args.argi1 = moveId;
2613 args.argi2 = status;
2614 args.arg3 = estMillis;
Jeff Sharkeyb36586a2015-04-27 08:42:28 -07002615 mHandler.obtainMessage(MSG_STATUS_CHANGED, args).sendToTarget();
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002616 }
2617 }
2618
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002619 private final ContextImpl mContext;
2620 private final IPackageManager mPM;
2621
2622 private static final Object sSync = new Object();
Dianne Hackbornadd005c2013-07-17 18:43:12 -07002623 private static ArrayMap<ResourceName, WeakReference<Drawable.ConstantState>> sIconCache
2624 = new ArrayMap<ResourceName, WeakReference<Drawable.ConstantState>>();
2625 private static ArrayMap<ResourceName, WeakReference<CharSequence>> sStringCache
2626 = new ArrayMap<ResourceName, WeakReference<CharSequence>>();
Svetoslavf7c06eb2015-06-10 18:43:22 -07002627
2628 private final Map<OnPermissionsChangedListener, IOnPermissionsChangeListener>
2629 mPermissionListeners = new ArrayMap<>();
2630
2631 public class OnPermissionsChangeListenerDelegate extends IOnPermissionsChangeListener.Stub
2632 implements Handler.Callback{
2633 private static final int MSG_PERMISSIONS_CHANGED = 1;
2634
2635 private final OnPermissionsChangedListener mListener;
2636 private final Handler mHandler;
2637
2638
2639 public OnPermissionsChangeListenerDelegate(OnPermissionsChangedListener listener,
2640 Looper looper) {
2641 mListener = listener;
2642 mHandler = new Handler(looper, this);
2643 }
2644
2645 @Override
2646 public void onPermissionsChanged(int uid) {
2647 mHandler.obtainMessage(MSG_PERMISSIONS_CHANGED, uid, 0).sendToTarget();
2648 }
2649
2650 @Override
2651 public boolean handleMessage(Message msg) {
2652 switch (msg.what) {
2653 case MSG_PERMISSIONS_CHANGED: {
2654 final int uid = msg.arg1;
2655 mListener.onPermissionsChanged(uid);
2656 return true;
2657 }
2658 }
2659 return false;
2660 }
2661 }
Suprabh Shuklaaef25132017-01-23 18:09:03 -08002662
2663 @Override
2664 public boolean canRequestPackageInstalls() {
2665 try {
2666 return mPM.canRequestPackageInstalls(mContext.getPackageName(), mContext.getUserId());
2667 } catch (RemoteException e) {
2668 throw e.rethrowAsRuntimeException();
2669 }
2670 }
Chad Brubaker336ae5b2017-03-24 15:53:09 -07002671
2672 @Override
2673 public ComponentName getInstantAppResolverSettingsComponent() {
2674 try {
2675 return mPM.getInstantAppResolverSettingsComponent();
2676 } catch (RemoteException e) {
2677 throw e.rethrowAsRuntimeException();
2678 }
2679 }
Todd Kennedy801e6592017-04-12 14:10:12 -07002680
2681 @Override
2682 public ComponentName getInstantAppInstallerComponent() {
2683 try {
2684 return mPM.getInstantAppInstallerComponent();
2685 } catch (RemoteException e) {
2686 throw e.rethrowAsRuntimeException();
2687 }
2688 }
Chad Brubaker0d277a72017-04-12 16:56:53 -07002689
2690 @Override
2691 public String getInstantAppAndroidId(String packageName, UserHandle user) {
2692 try {
2693 return mPM.getInstantAppAndroidId(packageName, user.getIdentifier());
2694 } catch (RemoteException e) {
2695 throw e.rethrowAsRuntimeException();
2696 }
2697 }
Calin Juravle3d2af7f2017-04-19 19:56:21 -07002698
2699 private static class DexModuleRegisterResult {
2700 final String dexModulePath;
2701 final boolean success;
2702 final String message;
2703
2704 private DexModuleRegisterResult(String dexModulePath, boolean success, String message) {
2705 this.dexModulePath = dexModulePath;
2706 this.success = success;
2707 this.message = message;
2708 }
2709 }
2710
2711 private static class DexModuleRegisterCallbackDelegate
2712 extends android.content.pm.IDexModuleRegisterCallback.Stub
2713 implements Handler.Callback {
2714 private static final int MSG_DEX_MODULE_REGISTERED = 1;
2715 private final DexModuleRegisterCallback callback;
2716 private final Handler mHandler;
2717
2718 DexModuleRegisterCallbackDelegate(@NonNull DexModuleRegisterCallback callback) {
2719 this.callback = callback;
2720 mHandler = new Handler(Looper.getMainLooper(), this);
2721 }
2722
2723 @Override
2724 public void onDexModuleRegistered(@NonNull String dexModulePath, boolean success,
2725 @Nullable String message)throws RemoteException {
2726 mHandler.obtainMessage(MSG_DEX_MODULE_REGISTERED,
2727 new DexModuleRegisterResult(dexModulePath, success, message)).sendToTarget();
2728 }
2729
2730 @Override
2731 public boolean handleMessage(Message msg) {
2732 if (msg.what != MSG_DEX_MODULE_REGISTERED) {
2733 return false;
2734 }
2735 DexModuleRegisterResult result = (DexModuleRegisterResult)msg.obj;
2736 callback.onDexModuleRegistered(result.dexModulePath, result.success, result.message);
2737 return true;
2738 }
2739 }
2740
2741 @Override
2742 public void registerDexModule(@NonNull String dexModule,
2743 @Nullable DexModuleRegisterCallback callback) {
2744 // Check if this is a shared module by looking if the others can read it.
2745 boolean isSharedModule = false;
2746 try {
2747 StructStat stat = Os.stat(dexModule);
2748 if ((OsConstants.S_IROTH & stat.st_mode) != 0) {
2749 isSharedModule = true;
2750 }
2751 } catch (ErrnoException e) {
2752 callback.onDexModuleRegistered(dexModule, false,
2753 "Could not get stat the module file: " + e.getMessage());
2754 return;
2755 }
2756
2757 // Module path is ok.
2758 // Create the callback delegate to be passed to package manager service.
2759 DexModuleRegisterCallbackDelegate callbackDelegate = null;
2760 if (callback != null) {
2761 callbackDelegate = new DexModuleRegisterCallbackDelegate(callback);
2762 }
2763
2764 // Invoke the package manager service.
2765 try {
2766 mPM.registerDexModule(mContext.getPackageName(), dexModule,
2767 isSharedModule, callbackDelegate);
2768 } catch (RemoteException e) {
2769 throw e.rethrowAsRuntimeException();
2770 }
2771 }
Calin Juravle45f8b292017-11-07 18:49:43 -08002772
2773 @Override
Ben Gruver1ab3d6e2017-12-07 13:45:08 -08002774 public CharSequence getHarmfulAppWarning(String packageName) {
2775 try {
2776 return mPM.getHarmfulAppWarning(packageName, mContext.getUserId());
2777 } catch (RemoteException e) {
2778 throw e.rethrowAsRuntimeException();
2779 }
2780 }
2781
2782 @Override
2783 public void setHarmfulAppWarning(String packageName, CharSequence warning) {
2784 try {
2785 mPM.setHarmfulAppWarning(packageName, warning, mContext.getUserId());
2786 } catch (RemoteException e) {
2787 throw e.rethrowAsRuntimeException();
2788 }
2789 }
2790
2791 @Override
Calin Juravle45f8b292017-11-07 18:49:43 -08002792 public ArtManager getArtManager() {
2793 synchronized (mLock) {
2794 if (mArtManager == null) {
2795 try {
2796 mArtManager = new ArtManager(mPM.getArtManager());
2797 } catch (RemoteException e) {
2798 throw e.rethrowFromSystemServer();
2799 }
2800 }
2801 return mArtManager;
2802 }
2803 }
Makoto Onuki700feef2018-02-15 10:59:41 -08002804
2805 @Override
2806 public String getSystemTextClassifierPackageName() {
2807 try {
2808 return mPM.getSystemTextClassifierPackageName();
2809 } catch (RemoteException e) {
2810 throw e.rethrowAsRuntimeException();
2811 }
2812 }
Benjamin Franz7cc9a812018-03-22 10:11:29 +00002813
2814 @Override
2815 public boolean isPackageStateProtected(String packageName, int userId) {
2816 try {
2817 return mPM.isPackageStateProtected(packageName, userId);
2818 } catch (RemoteException e) {
2819 throw e.rethrowAsRuntimeException();
2820 }
2821 }
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002822}