blob: f8f50a2785110c664d06c6d303351dff529235a1 [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 }
1357 badgeColor.setTint(getUserBadgeColor(user));
1358 Drawable badgeForeground = getDrawableForDensity(
1359 com.android.internal.R.drawable.ic_corp_badge_case, density);
1360 Drawable badge = new LayerDrawable(
1361 new Drawable[] {badgeColor, badgeForeground });
1362 return badge;
Selim Cineke6ff9462016-01-15 15:07:06 -08001363 }
1364
1365 @Override
1366 public Drawable getUserBadgeForDensityNoBackground(UserHandle user, int density) {
Kenny Guy02c89902016-11-15 19:36:38 +00001367 Drawable badge = getManagedProfileIconForDensity(user,
Vadim Tryshev66ae66a2016-02-18 15:41:21 -08001368 com.android.internal.R.drawable.ic_corp_badge_no_background, density);
Kenny Guy02c89902016-11-15 19:36:38 +00001369 if (badge != null) {
1370 badge.setTint(getUserBadgeColor(user));
1371 }
1372 return badge;
Selim Cineke6ff9462016-01-15 15:07:06 -08001373 }
1374
Vadim Tryshev66ae66a2016-02-18 15:41:21 -08001375 private Drawable getDrawableForDensity(int drawableId, int density) {
1376 if (density <= 0) {
1377 density = mContext.getResources().getDisplayMetrics().densityDpi;
1378 }
1379 return Resources.getSystem().getDrawableForDensity(drawableId, density);
1380 }
1381
1382 private Drawable getManagedProfileIconForDensity(UserHandle user, int drawableId, int density) {
Tony Mak8673b282016-03-21 21:10:59 +00001383 if (isManagedProfile(user.getIdentifier())) {
Vadim Tryshev66ae66a2016-02-18 15:41:21 -08001384 return getDrawableForDensity(drawableId, density);
Svetoslavc7d62f02014-09-04 15:39:54 -07001385 }
1386 return null;
1387 }
1388
1389 @Override
1390 public CharSequence getUserBadgedLabel(CharSequence label, UserHandle user) {
Tony Mak8673b282016-03-21 21:10:59 +00001391 if (isManagedProfile(user.getIdentifier())) {
Kenny Guy02c89902016-11-15 19:36:38 +00001392 int badge = getUserManager().getManagedProfileBadge(user.getIdentifier());
1393 int resourceId = CORP_BADGE_LABEL_RES_ID[badge % CORP_BADGE_LABEL_RES_ID.length];
1394 return Resources.getSystem().getString(resourceId, label);
Svetoslavc7d62f02014-09-04 15:39:54 -07001395 }
1396 return label;
1397 }
1398
Alan Viveretteecd585a2015-04-13 10:32:51 -07001399 @Override
1400 public Resources getResourcesForActivity(ComponentName activityName)
1401 throws NameNotFoundException {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001402 return getResourcesForApplication(
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001403 getActivityInfo(activityName, sDefaultFlags).applicationInfo);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001404 }
1405
Alan Viveretteecd585a2015-04-13 10:32:51 -07001406 @Override
1407 public Resources getResourcesForApplication(@NonNull ApplicationInfo app)
1408 throws NameNotFoundException {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001409 if (app.packageName.equals("system")) {
Adam Lesinskia82b6262017-03-21 16:56:17 -07001410 return mContext.mMainThread.getSystemUiContext().getResources();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001411 }
Jeff Sharkey8a4c9722014-06-16 13:48:42 -07001412 final boolean sameUid = (app.uid == Process.myUid());
Adam Lesinski53fafdf2016-08-03 13:36:39 -07001413 final Resources r = mContext.mMainThread.getTopLevelResources(
Adam Lesinskic82f28a2016-06-08 17:19:09 -07001414 sameUid ? app.sourceDir : app.publicSourceDir,
1415 sameUid ? app.splitSourceDirs : app.splitPublicSourceDirs,
1416 app.resourceDirs, app.sharedLibraryFiles, Display.DEFAULT_DISPLAY,
Todd Kennedy233a0b12018-01-29 20:30:24 +00001417 mContext.mPackageInfo);
Adam Lesinski53fafdf2016-08-03 13:36:39 -07001418 if (r != null) {
1419 return r;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001420 }
Adam Lesinski53fafdf2016-08-03 13:36:39 -07001421 throw new NameNotFoundException("Unable to open " + app.publicSourceDir);
1422
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001423 }
1424
Alan Viveretteecd585a2015-04-13 10:32:51 -07001425 @Override
1426 public Resources getResourcesForApplication(String appPackageName)
1427 throws NameNotFoundException {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001428 return getResourcesForApplication(
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001429 getApplicationInfo(appPackageName, sDefaultFlags));
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001430 }
1431
Amith Yamasani98edc952012-09-25 14:09:27 -07001432 /** @hide */
1433 @Override
1434 public Resources getResourcesForApplicationAsUser(String appPackageName, int userId)
1435 throws NameNotFoundException {
Jeff Sharkeyded653b2012-09-27 19:09:24 -07001436 if (userId < 0) {
1437 throw new IllegalArgumentException(
1438 "Call does not support special user #" + userId);
1439 }
1440 if ("system".equals(appPackageName)) {
Adam Lesinskia82b6262017-03-21 16:56:17 -07001441 return mContext.mMainThread.getSystemUiContext().getResources();
Jeff Sharkeyded653b2012-09-27 19:09:24 -07001442 }
Amith Yamasani98edc952012-09-25 14:09:27 -07001443 try {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001444 ApplicationInfo ai = mPM.getApplicationInfo(appPackageName, sDefaultFlags, userId);
Amith Yamasani98edc952012-09-25 14:09:27 -07001445 if (ai != null) {
1446 return getResourcesForApplication(ai);
1447 }
1448 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001449 throw e.rethrowFromSystemServer();
Amith Yamasani98edc952012-09-25 14:09:27 -07001450 }
1451 throw new NameNotFoundException("Package " + appPackageName + " doesn't exist");
1452 }
1453
Jeff Sharkeycd654482016-01-08 17:42:11 -07001454 volatile int mCachedSafeMode = -1;
1455
1456 @Override
1457 public boolean isSafeMode() {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001458 try {
1459 if (mCachedSafeMode < 0) {
1460 mCachedSafeMode = mPM.isSafeMode() ? 1 : 0;
1461 }
1462 return mCachedSafeMode != 0;
1463 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001464 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001465 }
1466 }
1467
Svetoslavf7c06eb2015-06-10 18:43:22 -07001468 @Override
1469 public void addOnPermissionsChangeListener(OnPermissionsChangedListener listener) {
1470 synchronized (mPermissionListeners) {
1471 if (mPermissionListeners.get(listener) != null) {
1472 return;
1473 }
1474 OnPermissionsChangeListenerDelegate delegate =
1475 new OnPermissionsChangeListenerDelegate(listener, Looper.getMainLooper());
1476 try {
1477 mPM.addOnPermissionsChangeListener(delegate);
1478 mPermissionListeners.put(listener, delegate);
1479 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001480 throw e.rethrowFromSystemServer();
Svetoslavf7c06eb2015-06-10 18:43:22 -07001481 }
1482 }
1483 }
1484
1485 @Override
1486 public void removeOnPermissionsChangeListener(OnPermissionsChangedListener listener) {
1487 synchronized (mPermissionListeners) {
1488 IOnPermissionsChangeListener delegate = mPermissionListeners.get(listener);
1489 if (delegate != null) {
1490 try {
1491 mPM.removeOnPermissionsChangeListener(delegate);
1492 mPermissionListeners.remove(listener);
1493 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001494 throw e.rethrowFromSystemServer();
Svetoslavf7c06eb2015-06-10 18:43:22 -07001495 }
1496 }
1497 }
1498 }
1499
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001500 static void configurationChanged() {
1501 synchronized (sSync) {
1502 sIconCache.clear();
1503 sStringCache.clear();
1504 }
1505 }
1506
Yao Chen022b8ea2016-12-16 11:03:28 -08001507 protected ApplicationPackageManager(ContextImpl context,
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001508 IPackageManager pm) {
1509 mContext = context;
1510 mPM = pm;
1511 }
1512
Alan Viveretteecd585a2015-04-13 10:32:51 -07001513 @Nullable
1514 private Drawable getCachedIcon(@NonNull ResourceName name) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001515 synchronized (sSync) {
Alan Viveretteecd585a2015-04-13 10:32:51 -07001516 final WeakReference<Drawable.ConstantState> wr = sIconCache.get(name);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001517 if (DEBUG_ICONS) Log.v(TAG, "Get cached weak drawable ref for "
1518 + name + ": " + wr);
1519 if (wr != null) { // we have the activity
Alan Viveretteecd585a2015-04-13 10:32:51 -07001520 final Drawable.ConstantState state = wr.get();
Romain Guy39fe17c2011-11-30 10:34:07 -08001521 if (state != null) {
1522 if (DEBUG_ICONS) {
1523 Log.v(TAG, "Get cached drawable state for " + name + ": " + state);
1524 }
1525 // Note: It's okay here to not use the newDrawable(Resources) variant
1526 // of the API. The ConstantState comes from a drawable that was
1527 // originally created by passing the proper app Resources instance
1528 // which means the state should already contain the proper
1529 // resources specific information (like density.) See
1530 // BitmapDrawable.BitmapState for instance.
1531 return state.newDrawable();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001532 }
1533 // our entry has been purged
1534 sIconCache.remove(name);
1535 }
1536 }
1537 return null;
1538 }
1539
Alan Viveretteecd585a2015-04-13 10:32:51 -07001540 private void putCachedIcon(@NonNull ResourceName name, @NonNull Drawable dr) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001541 synchronized (sSync) {
Alan Viveretteecd585a2015-04-13 10:32:51 -07001542 sIconCache.put(name, new WeakReference<>(dr.getConstantState()));
Romain Guy39fe17c2011-11-30 10:34:07 -08001543 if (DEBUG_ICONS) Log.v(TAG, "Added cached drawable state for " + name + ": " + dr);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001544 }
1545 }
1546
Romain Guy39fe17c2011-11-30 10:34:07 -08001547 static void handlePackageBroadcast(int cmd, String[] pkgList, boolean hasPkgInfo) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001548 boolean immediateGc = false;
Sudheer Shankacc6418f2016-10-13 12:03:44 -07001549 if (cmd == ApplicationThreadConstants.EXTERNAL_STORAGE_UNAVAILABLE) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001550 immediateGc = true;
1551 }
1552 if (pkgList != null && (pkgList.length > 0)) {
1553 boolean needCleanup = false;
1554 for (String ssp : pkgList) {
1555 synchronized (sSync) {
Dianne Hackbornadd005c2013-07-17 18:43:12 -07001556 for (int i=sIconCache.size()-1; i>=0; i--) {
1557 ResourceName nm = sIconCache.keyAt(i);
1558 if (nm.packageName.equals(ssp)) {
1559 //Log.i(TAG, "Removing cached drawable for " + nm);
1560 sIconCache.removeAt(i);
1561 needCleanup = true;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001562 }
1563 }
Dianne Hackbornadd005c2013-07-17 18:43:12 -07001564 for (int i=sStringCache.size()-1; i>=0; i--) {
1565 ResourceName nm = sStringCache.keyAt(i);
1566 if (nm.packageName.equals(ssp)) {
1567 //Log.i(TAG, "Removing cached string for " + nm);
1568 sStringCache.removeAt(i);
1569 needCleanup = true;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001570 }
1571 }
1572 }
1573 }
1574 if (needCleanup || hasPkgInfo) {
1575 if (immediateGc) {
1576 // Schedule an immediate gc.
1577 Runtime.getRuntime().gc();
1578 } else {
1579 ActivityThread.currentActivityThread().scheduleGcIdler();
1580 }
1581 }
1582 }
1583 }
1584
1585 private static final class ResourceName {
1586 final String packageName;
1587 final int iconId;
1588
1589 ResourceName(String _packageName, int _iconId) {
1590 packageName = _packageName;
1591 iconId = _iconId;
1592 }
1593
1594 ResourceName(ApplicationInfo aInfo, int _iconId) {
1595 this(aInfo.packageName, _iconId);
1596 }
1597
1598 ResourceName(ComponentInfo cInfo, int _iconId) {
1599 this(cInfo.applicationInfo.packageName, _iconId);
1600 }
1601
1602 ResourceName(ResolveInfo rInfo, int _iconId) {
1603 this(rInfo.activityInfo.applicationInfo.packageName, _iconId);
1604 }
1605
1606 @Override
1607 public boolean equals(Object o) {
1608 if (this == o) return true;
1609 if (o == null || getClass() != o.getClass()) return false;
1610
1611 ResourceName that = (ResourceName) o;
1612
1613 if (iconId != that.iconId) return false;
1614 return !(packageName != null ?
1615 !packageName.equals(that.packageName) : that.packageName != null);
1616
1617 }
1618
1619 @Override
1620 public int hashCode() {
1621 int result;
1622 result = packageName.hashCode();
1623 result = 31 * result + iconId;
1624 return result;
1625 }
1626
1627 @Override
1628 public String toString() {
1629 return "{ResourceName " + packageName + " / " + iconId + "}";
1630 }
1631 }
1632
1633 private CharSequence getCachedString(ResourceName name) {
1634 synchronized (sSync) {
1635 WeakReference<CharSequence> wr = sStringCache.get(name);
1636 if (wr != null) { // we have the activity
1637 CharSequence cs = wr.get();
1638 if (cs != null) {
1639 return cs;
1640 }
1641 // our entry has been purged
1642 sStringCache.remove(name);
1643 }
1644 }
1645 return null;
1646 }
1647
1648 private void putCachedString(ResourceName name, CharSequence cs) {
1649 synchronized (sSync) {
1650 sStringCache.put(name, new WeakReference<CharSequence>(cs));
1651 }
1652 }
1653
1654 @Override
Tor Norbye7b9c9122013-05-30 16:48:33 -07001655 public CharSequence getText(String packageName, @StringRes int resid,
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001656 ApplicationInfo appInfo) {
1657 ResourceName name = new ResourceName(packageName, resid);
1658 CharSequence text = getCachedString(name);
1659 if (text != null) {
1660 return text;
1661 }
1662 if (appInfo == null) {
1663 try {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001664 appInfo = getApplicationInfo(packageName, sDefaultFlags);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001665 } catch (NameNotFoundException e) {
1666 return null;
1667 }
1668 }
1669 try {
1670 Resources r = getResourcesForApplication(appInfo);
1671 text = r.getText(resid);
1672 putCachedString(name, text);
1673 return text;
1674 } catch (NameNotFoundException e) {
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07001675 Log.w("PackageManager", "Failure retrieving resources for "
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001676 + appInfo.packageName);
1677 } catch (RuntimeException e) {
1678 // If an exception was thrown, fall through to return
1679 // default icon.
1680 Log.w("PackageManager", "Failure retrieving text 0x"
1681 + Integer.toHexString(resid) + " in package "
1682 + packageName, e);
1683 }
1684 return null;
1685 }
1686
1687 @Override
Tor Norbye7b9c9122013-05-30 16:48:33 -07001688 public XmlResourceParser getXml(String packageName, @XmlRes int resid,
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001689 ApplicationInfo appInfo) {
1690 if (appInfo == null) {
1691 try {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001692 appInfo = getApplicationInfo(packageName, sDefaultFlags);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001693 } catch (NameNotFoundException e) {
1694 return null;
1695 }
1696 }
1697 try {
1698 Resources r = getResourcesForApplication(appInfo);
1699 return r.getXml(resid);
1700 } catch (RuntimeException e) {
1701 // If an exception was thrown, fall through to return
1702 // default icon.
1703 Log.w("PackageManager", "Failure retrieving xml 0x"
1704 + Integer.toHexString(resid) + " in package "
1705 + packageName, e);
1706 } catch (NameNotFoundException e) {
Alon Albert3fa51e32010-11-11 09:24:04 -08001707 Log.w("PackageManager", "Failure retrieving resources for "
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001708 + appInfo.packageName);
1709 }
1710 return null;
1711 }
1712
1713 @Override
1714 public CharSequence getApplicationLabel(ApplicationInfo info) {
1715 return info.loadLabel(this);
1716 }
1717
1718 @Override
Nicolas Prevot9a80e532015-09-23 15:49:28 +01001719 public int installExistingPackage(String packageName) throws NameNotFoundException {
Sunny Goyala31a74b2017-05-11 15:59:19 -07001720 return installExistingPackage(packageName, PackageManager.INSTALL_REASON_UNKNOWN);
1721 }
1722
1723 @Override
1724 public int installExistingPackage(String packageName, int installReason)
1725 throws NameNotFoundException {
1726 return installExistingPackageAsUser(packageName, installReason, mContext.getUserId());
Nicolas Prevot9a80e532015-09-23 15:49:28 +01001727 }
1728
1729 @Override
1730 public int installExistingPackageAsUser(String packageName, int userId)
Dianne Hackborn7767eac2012-08-23 18:25:40 -07001731 throws NameNotFoundException {
Sunny Goyala31a74b2017-05-11 15:59:19 -07001732 return installExistingPackageAsUser(packageName, PackageManager.INSTALL_REASON_UNKNOWN,
1733 userId);
1734 }
1735
1736 private int installExistingPackageAsUser(String packageName, int installReason, int userId)
1737 throws NameNotFoundException {
Dianne Hackborn7767eac2012-08-23 18:25:40 -07001738 try {
Todd Kennedybe0b8892017-02-15 14:13:52 -08001739 int res = mPM.installExistingPackageAsUser(packageName, userId, 0 /*installFlags*/,
Sunny Goyala31a74b2017-05-11 15:59:19 -07001740 installReason);
Dianne Hackborn7767eac2012-08-23 18:25:40 -07001741 if (res == INSTALL_FAILED_INVALID_URI) {
1742 throw new NameNotFoundException("Package " + packageName + " doesn't exist");
1743 }
1744 return res;
1745 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001746 throw e.rethrowFromSystemServer();
Dianne Hackborn7767eac2012-08-23 18:25:40 -07001747 }
1748 }
1749
1750 @Override
Kenny Root3a9b5fb2011-09-20 14:15:38 -07001751 public void verifyPendingInstall(int id, int response) {
Kenny Root5ab21572011-07-27 11:11:19 -07001752 try {
Kenny Root3a9b5fb2011-09-20 14:15:38 -07001753 mPM.verifyPendingInstall(id, response);
Kenny Root5ab21572011-07-27 11:11:19 -07001754 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001755 throw e.rethrowFromSystemServer();
Kenny Root5ab21572011-07-27 11:11:19 -07001756 }
1757 }
1758
1759 @Override
rich canningsd9ef3e52012-08-22 14:28:05 -07001760 public void extendVerificationTimeout(int id, int verificationCodeAtTimeout,
1761 long millisecondsToDelay) {
1762 try {
1763 mPM.extendVerificationTimeout(id, verificationCodeAtTimeout, millisecondsToDelay);
1764 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001765 throw e.rethrowFromSystemServer();
rich canningsd9ef3e52012-08-22 14:28:05 -07001766 }
1767 }
1768
1769 @Override
Todd Kennedydfa93ab2016-03-03 15:24:33 -08001770 public void verifyIntentFilter(int id, int verificationCode, List<String> failedDomains) {
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001771 try {
Todd Kennedydfa93ab2016-03-03 15:24:33 -08001772 mPM.verifyIntentFilter(id, verificationCode, failedDomains);
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001773 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001774 throw e.rethrowFromSystemServer();
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001775 }
1776 }
1777
1778 @Override
Jeff Sharkeye06b4d12016-01-06 14:51:50 -07001779 public int getIntentVerificationStatusAsUser(String packageName, int userId) {
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001780 try {
1781 return mPM.getIntentVerificationStatus(packageName, userId);
1782 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001783 throw e.rethrowFromSystemServer();
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001784 }
1785 }
1786
1787 @Override
Jeff Sharkeye06b4d12016-01-06 14:51:50 -07001788 public boolean updateIntentVerificationStatusAsUser(String packageName, int status, int userId) {
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001789 try {
1790 return mPM.updateIntentVerificationStatus(packageName, status, userId);
1791 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001792 throw e.rethrowFromSystemServer();
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001793 }
1794 }
1795
1796 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001797 @SuppressWarnings("unchecked")
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001798 public List<IntentFilterVerificationInfo> getIntentFilterVerifications(String packageName) {
1799 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001800 ParceledListSlice<IntentFilterVerificationInfo> parceledList =
1801 mPM.getIntentFilterVerifications(packageName);
1802 if (parceledList == null) {
1803 return Collections.emptyList();
1804 }
1805 return parceledList.getList();
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001806 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001807 throw e.rethrowFromSystemServer();
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001808 }
1809 }
1810
1811 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001812 @SuppressWarnings("unchecked")
Fabrice Di Meglio07885952015-04-06 19:41:28 -07001813 public List<IntentFilter> getAllIntentFilters(String packageName) {
1814 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001815 ParceledListSlice<IntentFilter> parceledList =
1816 mPM.getAllIntentFilters(packageName);
1817 if (parceledList == null) {
1818 return Collections.emptyList();
1819 }
1820 return parceledList.getList();
Fabrice Di Meglio07885952015-04-06 19:41:28 -07001821 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001822 throw e.rethrowFromSystemServer();
Fabrice Di Meglio07885952015-04-06 19:41:28 -07001823 }
1824 }
1825
1826 @Override
Jeff Sharkeye06b4d12016-01-06 14:51:50 -07001827 public String getDefaultBrowserPackageNameAsUser(int userId) {
Fabrice Di Meglio62271722015-04-10 17:24:02 -07001828 try {
1829 return mPM.getDefaultBrowserPackageName(userId);
1830 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001831 throw e.rethrowFromSystemServer();
Fabrice Di Meglio62271722015-04-10 17:24:02 -07001832 }
1833 }
1834
1835 @Override
Jeff Sharkeye06b4d12016-01-06 14:51:50 -07001836 public boolean setDefaultBrowserPackageNameAsUser(String packageName, int userId) {
Fabrice Di Meglio62271722015-04-10 17:24:02 -07001837 try {
1838 return mPM.setDefaultBrowserPackageName(packageName, userId);
1839 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001840 throw e.rethrowFromSystemServer();
Fabrice Di Meglio62271722015-04-10 17:24:02 -07001841 }
1842 }
1843
1844 @Override
Dianne Hackborn880119b2010-11-18 22:26:40 -08001845 public void setInstallerPackageName(String targetPackage,
1846 String installerPackageName) {
1847 try {
1848 mPM.setInstallerPackageName(targetPackage, installerPackageName);
1849 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001850 throw e.rethrowFromSystemServer();
Dianne Hackborn880119b2010-11-18 22:26:40 -08001851 }
1852 }
1853
1854 @Override
Todd Kennedyab532892017-03-08 14:19:49 -08001855 public void setUpdateAvailable(String packageName, boolean updateAvailable) {
1856 try {
1857 mPM.setUpdateAvailable(packageName, updateAvailable);
1858 } catch (RemoteException e) {
1859 throw e.rethrowFromSystemServer();
1860 }
1861 }
1862
1863 @Override
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001864 public String getInstallerPackageName(String packageName) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001865 try {
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001866 return mPM.getInstallerPackageName(packageName);
1867 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001868 throw e.rethrowFromSystemServer();
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001869 }
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001870 }
1871
1872 @Override
1873 public int getMoveStatus(int moveId) {
1874 try {
1875 return mPM.getMoveStatus(moveId);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001876 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001877 throw e.rethrowFromSystemServer();
Jeff Sharkeyb2b9ab82015-04-05 21:10:42 -07001878 }
1879 }
1880
1881 @Override
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001882 public void registerMoveCallback(MoveCallback callback, Handler handler) {
1883 synchronized (mDelegates) {
1884 final MoveCallbackDelegate delegate = new MoveCallbackDelegate(callback,
1885 handler.getLooper());
1886 try {
1887 mPM.registerMoveCallback(delegate);
1888 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001889 throw e.rethrowFromSystemServer();
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001890 }
1891 mDelegates.add(delegate);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001892 }
1893 }
1894
1895 @Override
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001896 public void unregisterMoveCallback(MoveCallback callback) {
1897 synchronized (mDelegates) {
1898 for (Iterator<MoveCallbackDelegate> i = mDelegates.iterator(); i.hasNext();) {
1899 final MoveCallbackDelegate delegate = i.next();
1900 if (delegate.mCallback == callback) {
1901 try {
1902 mPM.unregisterMoveCallback(delegate);
1903 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001904 throw e.rethrowFromSystemServer();
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001905 }
1906 i.remove();
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001907 }
1908 }
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001909 }
1910 }
1911
1912 @Override
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001913 public int movePackage(String packageName, VolumeInfo vol) {
1914 try {
1915 final String volumeUuid;
1916 if (VolumeInfo.ID_PRIVATE_INTERNAL.equals(vol.id)) {
1917 volumeUuid = StorageManager.UUID_PRIVATE_INTERNAL;
1918 } else if (vol.isPrimaryPhysical()) {
1919 volumeUuid = StorageManager.UUID_PRIMARY_PHYSICAL;
1920 } else {
1921 volumeUuid = Preconditions.checkNotNull(vol.fsUuid);
1922 }
1923
1924 return mPM.movePackage(packageName, volumeUuid);
1925 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001926 throw e.rethrowFromSystemServer();
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001927 }
1928 }
1929
1930 @Override
1931 public @Nullable VolumeInfo getPackageCurrentVolume(ApplicationInfo app) {
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001932 final StorageManager storage = mContext.getSystemService(StorageManager.class);
Yao Chen022b8ea2016-12-16 11:03:28 -08001933 return getPackageCurrentVolume(app, storage);
1934 }
1935
1936 @VisibleForTesting
1937 protected @Nullable VolumeInfo getPackageCurrentVolume(ApplicationInfo app,
1938 StorageManager storage) {
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001939 if (app.isInternal()) {
1940 return storage.findVolumeById(VolumeInfo.ID_PRIVATE_INTERNAL);
1941 } else if (app.isExternalAsec()) {
1942 return storage.getPrimaryPhysicalVolume();
1943 } else {
1944 return storage.findVolumeByUuid(app.volumeUuid);
1945 }
1946 }
1947
1948 @Override
1949 public @NonNull List<VolumeInfo> getPackageCandidateVolumes(ApplicationInfo app) {
Yao Chen022b8ea2016-12-16 11:03:28 -08001950 final StorageManager storageManager = mContext.getSystemService(StorageManager.class);
1951 return getPackageCandidateVolumes(app, storageManager, mPM);
1952 }
1953
1954 @VisibleForTesting
1955 protected @NonNull List<VolumeInfo> getPackageCandidateVolumes(ApplicationInfo app,
1956 StorageManager storageManager, IPackageManager pm) {
1957 final VolumeInfo currentVol = getPackageCurrentVolume(app, storageManager);
1958 final List<VolumeInfo> vols = storageManager.getVolumes();
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001959 final List<VolumeInfo> candidates = new ArrayList<>();
1960 for (VolumeInfo vol : vols) {
Yao Chen022b8ea2016-12-16 11:03:28 -08001961 if (Objects.equals(vol, currentVol)
1962 || isPackageCandidateVolume(mContext, app, vol, pm)) {
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001963 candidates.add(vol);
1964 }
1965 }
1966 return candidates;
1967 }
1968
Yao Chen022b8ea2016-12-16 11:03:28 -08001969 @VisibleForTesting
1970 protected boolean isForceAllowOnExternal(Context context) {
1971 return Settings.Global.getInt(
Todd Kennedyf39ca8f2015-08-07 14:15:07 -07001972 context.getContentResolver(), Settings.Global.FORCE_ALLOW_ON_EXTERNAL, 0) != 0;
Yao Chen022b8ea2016-12-16 11:03:28 -08001973 }
1974
1975 @VisibleForTesting
1976 protected boolean isAllow3rdPartyOnInternal(Context context) {
1977 return context.getResources().getBoolean(
1978 com.android.internal.R.bool.config_allow3rdPartyAppOnInternal);
1979 }
1980
1981 private boolean isPackageCandidateVolume(
1982 ContextImpl context, ApplicationInfo app, VolumeInfo vol, IPackageManager pm) {
1983 final boolean forceAllowOnExternal = isForceAllowOnExternal(context);
1984
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001985 if (VolumeInfo.ID_PRIVATE_INTERNAL.equals(vol.getId())) {
Yao Chen022b8ea2016-12-16 11:03:28 -08001986 return app.isSystemApp() || isAllow3rdPartyOnInternal(context);
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001987 }
1988
1989 // System apps and apps demanding internal storage can't be moved
1990 // anywhere else
Todd Kennedyf39ca8f2015-08-07 14:15:07 -07001991 if (app.isSystemApp()) {
1992 return false;
1993 }
1994 if (!forceAllowOnExternal
Dianne Hackborn30a4e6d2015-10-12 17:14:56 -07001995 && (app.installLocation == PackageInfo.INSTALL_LOCATION_INTERNAL_ONLY
1996 || app.installLocation == PackageInfo.INSTALL_LOCATION_UNSPECIFIED)) {
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001997 return false;
1998 }
1999
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002000 // Gotta be able to write there
2001 if (!vol.isMountedWritable()) {
2002 return false;
2003 }
2004
2005 // Moving into an ASEC on public primary is only option internal
2006 if (vol.isPrimaryPhysical()) {
2007 return app.isInternal();
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07002008 }
2009
Makoto Onukif34db0a2016-02-17 11:17:15 -08002010 // Some apps can't be moved. (e.g. device admins)
2011 try {
Yao Chen022b8ea2016-12-16 11:03:28 -08002012 if (pm.isPackageDeviceAdminOnAnyUser(app.packageName)) {
Makoto Onukif34db0a2016-02-17 11:17:15 -08002013 return false;
2014 }
2015 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002016 throw e.rethrowFromSystemServer();
Makoto Onukif34db0a2016-02-17 11:17:15 -08002017 }
2018
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07002019 // Otherwise we can move to any private volume
2020 return (vol.getType() == VolumeInfo.TYPE_PRIVATE);
2021 }
2022
2023 @Override
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002024 public int movePrimaryStorage(VolumeInfo vol) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002025 try {
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002026 final String volumeUuid;
2027 if (VolumeInfo.ID_PRIVATE_INTERNAL.equals(vol.id)) {
2028 volumeUuid = StorageManager.UUID_PRIVATE_INTERNAL;
2029 } else if (vol.isPrimaryPhysical()) {
2030 volumeUuid = StorageManager.UUID_PRIMARY_PHYSICAL;
2031 } else {
2032 volumeUuid = Preconditions.checkNotNull(vol.fsUuid);
2033 }
2034
2035 return mPM.movePrimaryStorage(volumeUuid);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002036 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002037 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002038 }
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002039 }
2040
Jeff Sharkey275e3e42015-04-24 16:10:32 -07002041 @Override
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002042 public @Nullable VolumeInfo getPrimaryStorageCurrentVolume() {
2043 final StorageManager storage = mContext.getSystemService(StorageManager.class);
2044 final String volumeUuid = storage.getPrimaryStorageUuid();
Jeff Sharkey50a05452015-04-29 11:24:52 -07002045 return storage.findVolumeByQualifiedUuid(volumeUuid);
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002046 }
2047
Jeff Sharkey275e3e42015-04-24 16:10:32 -07002048 @Override
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002049 public @NonNull List<VolumeInfo> getPrimaryStorageCandidateVolumes() {
2050 final StorageManager storage = mContext.getSystemService(StorageManager.class);
2051 final VolumeInfo currentVol = getPrimaryStorageCurrentVolume();
2052 final List<VolumeInfo> vols = storage.getVolumes();
2053 final List<VolumeInfo> candidates = new ArrayList<>();
Jeff Sharkeyfced5342015-05-10 14:53:34 -07002054 if (Objects.equals(StorageManager.UUID_PRIMARY_PHYSICAL,
2055 storage.getPrimaryStorageUuid()) && currentVol != null) {
2056 // TODO: support moving primary physical to emulated volume
2057 candidates.add(currentVol);
2058 } else {
2059 for (VolumeInfo vol : vols) {
2060 if (Objects.equals(vol, currentVol) || isPrimaryStorageCandidateVolume(vol)) {
2061 candidates.add(vol);
2062 }
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002063 }
2064 }
2065 return candidates;
2066 }
2067
2068 private static boolean isPrimaryStorageCandidateVolume(VolumeInfo vol) {
2069 // Private internal is always an option
2070 if (VolumeInfo.ID_PRIVATE_INTERNAL.equals(vol.getId())) {
2071 return true;
2072 }
2073
2074 // Gotta be able to write there
2075 if (!vol.isMountedWritable()) {
2076 return false;
2077 }
2078
Jeff Sharkeyfced5342015-05-10 14:53:34 -07002079 // We can move to any private volume
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002080 return (vol.getType() == VolumeInfo.TYPE_PRIVATE);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002081 }
2082
2083 @Override
2084 public void deletePackage(String packageName, IPackageDeleteObserver observer, int flags) {
Robin Lee0e27c872015-09-28 14:37:40 +01002085 deletePackageAsUser(packageName, observer, flags, mContext.getUserId());
Nicolas Prevot9a80e532015-09-23 15:49:28 +01002086 }
2087
2088 @Override
Svet Ganov67882122016-12-11 16:36:34 -08002089 public void deletePackageAsUser(String packageName, IPackageDeleteObserver observer,
2090 int flags, int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002091 try {
Svet Ganov67882122016-12-11 16:36:34 -08002092 mPM.deletePackageAsUser(packageName, PackageManager.VERSION_CODE_HIGHEST,
2093 observer, userId, flags);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002094 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002095 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002096 }
2097 }
Jeff Sharkeyfbd0e9f2014-08-06 16:34:34 -07002098
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002099 @Override
2100 public void clearApplicationUserData(String packageName,
2101 IPackageDataObserver observer) {
2102 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -07002103 mPM.clearApplicationUserData(packageName, observer, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002104 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002105 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002106 }
2107 }
2108 @Override
2109 public void deleteApplicationCacheFiles(String packageName,
2110 IPackageDataObserver observer) {
2111 try {
2112 mPM.deleteApplicationCacheFiles(packageName, observer);
2113 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002114 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002115 }
2116 }
Jeff Sharkey529f91f2015-04-18 20:23:13 -07002117
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002118 @Override
Suprabh Shukla78c9eb82016-04-12 15:51:35 -07002119 public void deleteApplicationCacheFilesAsUser(String packageName, int userId,
2120 IPackageDataObserver observer) {
2121 try {
2122 mPM.deleteApplicationCacheFilesAsUser(packageName, userId, observer);
2123 } catch (RemoteException e) {
2124 throw e.rethrowFromSystemServer();
2125 }
2126 }
2127
2128 @Override
Jeff Sharkey529f91f2015-04-18 20:23:13 -07002129 public void freeStorageAndNotify(String volumeUuid, long idealStorageSize,
2130 IPackageDataObserver observer) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002131 try {
Jeff Sharkeyddff8072017-05-26 13:10:46 -06002132 mPM.freeStorageAndNotify(volumeUuid, idealStorageSize, 0, observer);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002133 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002134 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002135 }
2136 }
2137
2138 @Override
Jeff Sharkey529f91f2015-04-18 20:23:13 -07002139 public void freeStorage(String volumeUuid, long freeStorageSize, IntentSender pi) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002140 try {
Jeff Sharkeyddff8072017-05-26 13:10:46 -06002141 mPM.freeStorage(volumeUuid, freeStorageSize, 0, pi);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002142 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002143 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002144 }
2145 }
2146
2147 @Override
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00002148 public String[] setPackagesSuspendedAsUser(String[] packageNames, boolean suspended,
2149 int userId) {
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00002150 try {
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00002151 return mPM.setPackagesSuspendedAsUser(packageNames, suspended, userId);
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00002152 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002153 throw e.rethrowFromSystemServer();
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00002154 }
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00002155 }
2156
2157 @Override
Andrei Stingaceanu355b2322016-02-12 16:43:51 +00002158 public boolean isPackageSuspendedForUser(String packageName, int userId) {
2159 try {
2160 return mPM.isPackageSuspendedForUser(packageName, userId);
2161 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002162 throw e.rethrowFromSystemServer();
Andrei Stingaceanu355b2322016-02-12 16:43:51 +00002163 }
Andrei Stingaceanu355b2322016-02-12 16:43:51 +00002164 }
2165
Jeff Sharkey9bc89af2017-01-11 11:25:50 -07002166 /** @hide */
2167 @Override
2168 public void setApplicationCategoryHint(String packageName, int categoryHint) {
2169 try {
2170 mPM.setApplicationCategoryHint(packageName, categoryHint,
2171 mContext.getOpPackageName());
2172 } catch (RemoteException e) {
2173 throw e.rethrowFromSystemServer();
2174 }
2175 }
2176
Andrei Stingaceanu355b2322016-02-12 16:43:51 +00002177 @Override
Jeff Sharkeye06b4d12016-01-06 14:51:50 -07002178 public void getPackageSizeInfoAsUser(String packageName, int userHandle,
Dianne Hackborn0c380492012-08-20 17:23:30 -07002179 IPackageStatsObserver observer) {
Jeff Sharkey6f4b2a32017-03-21 14:13:41 -06002180 final String msg = "Shame on you for calling the hidden API "
2181 + "getPackageSizeInfoAsUser(). Shame!";
Jeff Sharkeye6306c42017-03-07 21:03:18 -07002182 if (mContext.getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.O) {
Jeff Sharkey6f4b2a32017-03-21 14:13:41 -06002183 throw new UnsupportedOperationException(msg);
Jeff Sharkeye6306c42017-03-07 21:03:18 -07002184 } else if (observer != null) {
Jeff Sharkey6f4b2a32017-03-21 14:13:41 -06002185 Log.d(TAG, msg);
Jeff Sharkeye6306c42017-03-07 21:03:18 -07002186 try {
2187 observer.onGetStatsCompleted(null, false);
2188 } catch (RemoteException ignored) {
2189 }
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002190 }
2191 }
Jeff Sharkeyd5896632016-03-04 16:16:00 -07002192
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002193 @Override
2194 public void addPackageToPreferred(String packageName) {
Jeff Sharkeyd5896632016-03-04 16:16:00 -07002195 Log.w(TAG, "addPackageToPreferred() is a no-op");
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002196 }
2197
2198 @Override
2199 public void removePackageFromPreferred(String packageName) {
Jeff Sharkeyd5896632016-03-04 16:16:00 -07002200 Log.w(TAG, "removePackageFromPreferred() is a no-op");
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002201 }
2202
2203 @Override
2204 public List<PackageInfo> getPreferredPackages(int flags) {
Jeff Sharkeyd5896632016-03-04 16:16:00 -07002205 Log.w(TAG, "getPreferredPackages() is a no-op");
2206 return Collections.emptyList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002207 }
2208
2209 @Override
2210 public void addPreferredActivity(IntentFilter filter,
2211 int match, ComponentName[] set, ComponentName activity) {
2212 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -07002213 mPM.addPreferredActivity(filter, match, set, activity, mContext.getUserId());
Amith Yamasania3f133a2012-08-09 17:11:28 -07002214 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002215 throw e.rethrowFromSystemServer();
Amith Yamasania3f133a2012-08-09 17:11:28 -07002216 }
2217 }
2218
2219 @Override
Jeff Sharkeye06b4d12016-01-06 14:51:50 -07002220 public void addPreferredActivityAsUser(IntentFilter filter, int match,
Amith Yamasania3f133a2012-08-09 17:11:28 -07002221 ComponentName[] set, ComponentName activity, int userId) {
2222 try {
2223 mPM.addPreferredActivity(filter, match, set, activity, userId);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002224 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002225 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002226 }
2227 }
2228
2229 @Override
2230 public void replacePreferredActivity(IntentFilter filter,
2231 int match, ComponentName[] set, ComponentName activity) {
2232 try {
Robin Lee0e27c872015-09-28 14:37:40 +01002233 mPM.replacePreferredActivity(filter, match, set, activity, mContext.getUserId());
Amith Yamasani41c1ded2014-08-05 11:15:05 -07002234 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002235 throw e.rethrowFromSystemServer();
Amith Yamasani41c1ded2014-08-05 11:15:05 -07002236 }
2237 }
2238
2239 @Override
2240 public void replacePreferredActivityAsUser(IntentFilter filter,
2241 int match, ComponentName[] set, ComponentName activity,
2242 int userId) {
2243 try {
2244 mPM.replacePreferredActivity(filter, match, set, activity, userId);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002245 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002246 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002247 }
2248 }
2249
2250 @Override
2251 public void clearPackagePreferredActivities(String packageName) {
2252 try {
2253 mPM.clearPackagePreferredActivities(packageName);
2254 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002255 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002256 }
2257 }
2258
2259 @Override
2260 public int getPreferredActivities(List<IntentFilter> outFilters,
2261 List<ComponentName> outActivities, String packageName) {
2262 try {
2263 return mPM.getPreferredActivities(outFilters, outActivities, packageName);
2264 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002265 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002266 }
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002267 }
2268
2269 @Override
Christopher Tatea2a0850d2013-09-05 16:38:58 -07002270 public ComponentName getHomeActivities(List<ResolveInfo> outActivities) {
2271 try {
2272 return mPM.getHomeActivities(outActivities);
2273 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002274 throw e.rethrowFromSystemServer();
Christopher Tatea2a0850d2013-09-05 16:38:58 -07002275 }
Christopher Tatea2a0850d2013-09-05 16:38:58 -07002276 }
2277
2278 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002279 public void setComponentEnabledSetting(ComponentName componentName,
2280 int newState, int flags) {
2281 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -07002282 mPM.setComponentEnabledSetting(componentName, newState, flags, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002283 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002284 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002285 }
2286 }
2287
2288 @Override
2289 public int getComponentEnabledSetting(ComponentName componentName) {
2290 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -07002291 return mPM.getComponentEnabledSetting(componentName, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002292 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002293 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002294 }
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002295 }
2296
2297 @Override
2298 public void setApplicationEnabledSetting(String packageName,
2299 int newState, int flags) {
2300 try {
Dianne Hackborn3fa3c28a2013-03-26 16:15:41 -07002301 mPM.setApplicationEnabledSetting(packageName, newState, flags,
Dianne Hackborn95d78532013-09-11 09:51:14 -07002302 mContext.getUserId(), mContext.getOpPackageName());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002303 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002304 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002305 }
2306 }
2307
2308 @Override
2309 public int getApplicationEnabledSetting(String packageName) {
2310 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -07002311 return mPM.getApplicationEnabledSetting(packageName, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002312 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002313 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002314 }
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002315 }
2316
Amith Yamasani655d0e22013-06-12 14:19:10 -07002317 @Override
Sudheer Shankabbb3ff22015-07-09 15:39:23 +01002318 public void flushPackageRestrictionsAsUser(int userId) {
2319 try {
2320 mPM.flushPackageRestrictionsAsUser(userId);
2321 } catch (RemoteException e) {
2322 throw e.rethrowFromSystemServer();
2323 }
2324 }
2325
2326 @Override
Amith Yamasanie5bcff62014-07-19 15:44:09 -07002327 public boolean setApplicationHiddenSettingAsUser(String packageName, boolean hidden,
Amith Yamasani655d0e22013-06-12 14:19:10 -07002328 UserHandle user) {
2329 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07002330 return mPM.setApplicationHiddenSettingAsUser(packageName, hidden,
Amith Yamasani655d0e22013-06-12 14:19:10 -07002331 user.getIdentifier());
Jeff Sharkey27b2e692016-02-25 17:40:12 -07002332 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002333 throw e.rethrowFromSystemServer();
Amith Yamasani655d0e22013-06-12 14:19:10 -07002334 }
Amith Yamasani655d0e22013-06-12 14:19:10 -07002335 }
2336
2337 @Override
Amith Yamasanie5bcff62014-07-19 15:44:09 -07002338 public boolean getApplicationHiddenSettingAsUser(String packageName, UserHandle user) {
Amith Yamasani655d0e22013-06-12 14:19:10 -07002339 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07002340 return mPM.getApplicationHiddenSettingAsUser(packageName, user.getIdentifier());
Jeff Sharkey27b2e692016-02-25 17:40:12 -07002341 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002342 throw e.rethrowFromSystemServer();
Amith Yamasani655d0e22013-06-12 14:19:10 -07002343 }
Amith Yamasani655d0e22013-06-12 14:19:10 -07002344 }
2345
dcashmanc6f22492014-08-14 09:54:51 -07002346 /** @hide */
dcashman9d2f4412014-06-09 09:27:54 -07002347 @Override
2348 public KeySet getKeySetByAlias(String packageName, String alias) {
2349 Preconditions.checkNotNull(packageName);
2350 Preconditions.checkNotNull(alias);
dcashman9d2f4412014-06-09 09:27:54 -07002351 try {
Jeff Sharkey27b2e692016-02-25 17:40:12 -07002352 return mPM.getKeySetByAlias(packageName, alias);
dcashman9d2f4412014-06-09 09:27:54 -07002353 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002354 throw e.rethrowFromSystemServer();
dcashman9d2f4412014-06-09 09:27:54 -07002355 }
dcashman9d2f4412014-06-09 09:27:54 -07002356 }
2357
dcashmanc6f22492014-08-14 09:54:51 -07002358 /** @hide */
dcashman9d2f4412014-06-09 09:27:54 -07002359 @Override
2360 public KeySet getSigningKeySet(String packageName) {
2361 Preconditions.checkNotNull(packageName);
dcashman9d2f4412014-06-09 09:27:54 -07002362 try {
Jeff Sharkey27b2e692016-02-25 17:40:12 -07002363 return mPM.getSigningKeySet(packageName);
dcashman9d2f4412014-06-09 09:27:54 -07002364 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002365 throw e.rethrowFromSystemServer();
dcashman9d2f4412014-06-09 09:27:54 -07002366 }
dcashman9d2f4412014-06-09 09:27:54 -07002367 }
2368
dcashmanc6f22492014-08-14 09:54:51 -07002369 /** @hide */
dcashman9d2f4412014-06-09 09:27:54 -07002370 @Override
2371 public boolean isSignedBy(String packageName, KeySet ks) {
2372 Preconditions.checkNotNull(packageName);
2373 Preconditions.checkNotNull(ks);
dcashman9d2f4412014-06-09 09:27:54 -07002374 try {
dcashmanc6f22492014-08-14 09:54:51 -07002375 return mPM.isPackageSignedByKeySet(packageName, ks);
dcashman9d2f4412014-06-09 09:27:54 -07002376 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002377 throw e.rethrowFromSystemServer();
dcashman9d2f4412014-06-09 09:27:54 -07002378 }
2379 }
2380
dcashmanc6f22492014-08-14 09:54:51 -07002381 /** @hide */
dcashman9d2f4412014-06-09 09:27:54 -07002382 @Override
2383 public boolean isSignedByExactly(String packageName, KeySet ks) {
2384 Preconditions.checkNotNull(packageName);
2385 Preconditions.checkNotNull(ks);
dcashman9d2f4412014-06-09 09:27:54 -07002386 try {
dcashmanc6f22492014-08-14 09:54:51 -07002387 return mPM.isPackageSignedByKeySetExactly(packageName, ks);
dcashman9d2f4412014-06-09 09:27:54 -07002388 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002389 throw e.rethrowFromSystemServer();
dcashman9d2f4412014-06-09 09:27:54 -07002390 }
2391 }
2392
Kenny Root0aaa0d92011-09-12 16:42:55 -07002393 /**
2394 * @hide
2395 */
2396 @Override
2397 public VerifierDeviceIdentity getVerifierDeviceIdentity() {
2398 try {
2399 return mPM.getVerifierDeviceIdentity();
2400 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002401 throw e.rethrowFromSystemServer();
Kenny Root0aaa0d92011-09-12 16:42:55 -07002402 }
Kenny Root0aaa0d92011-09-12 16:42:55 -07002403 }
2404
Jeff Hao9f60c082014-10-28 18:51:07 -07002405 /**
2406 * @hide
2407 */
2408 @Override
2409 public boolean isUpgrade() {
2410 try {
2411 return mPM.isUpgrade();
2412 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002413 throw e.rethrowFromSystemServer();
Jeff Hao9f60c082014-10-28 18:51:07 -07002414 }
2415 }
2416
Jeff Sharkey3a44f3f2014-04-28 17:36:31 -07002417 @Override
Jeff Sharkey16c8e3f2014-07-24 17:08:17 -07002418 public PackageInstaller getPackageInstaller() {
2419 synchronized (mLock) {
2420 if (mInstaller == null) {
2421 try {
Svet Ganov67882122016-12-11 16:36:34 -08002422 mInstaller = new PackageInstaller(mPM.getPackageInstaller(),
Jeff Sharkey16c8e3f2014-07-24 17:08:17 -07002423 mContext.getPackageName(), mContext.getUserId());
2424 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002425 throw e.rethrowFromSystemServer();
Jeff Sharkey16c8e3f2014-07-24 17:08:17 -07002426 }
2427 }
2428 return mInstaller;
Jeff Sharkey3a44f3f2014-04-28 17:36:31 -07002429 }
2430 }
2431
Jeff Sharkey6c833e02014-07-14 22:44:30 -07002432 @Override
2433 public boolean isPackageAvailable(String packageName) {
2434 try {
2435 return mPM.isPackageAvailable(packageName, mContext.getUserId());
2436 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002437 throw e.rethrowFromSystemServer();
Jeff Sharkey6c833e02014-07-14 22:44:30 -07002438 }
2439 }
2440
Nicolas Prevotc79586e2014-05-06 12:47:57 +01002441 /**
2442 * @hide
2443 */
2444 @Override
Nicolas Prevot63798c52014-05-27 13:22:38 +01002445 public void addCrossProfileIntentFilter(IntentFilter filter, int sourceUserId, int targetUserId,
2446 int flags) {
Nicolas Prevotc79586e2014-05-06 12:47:57 +01002447 try {
Nicolas Prevot3f7777f2014-07-24 15:58:39 +01002448 mPM.addCrossProfileIntentFilter(filter, mContext.getOpPackageName(),
Nicolas Prevot4b8d5822015-03-05 15:20:49 +00002449 sourceUserId, targetUserId, flags);
Nicolas Prevotc79586e2014-05-06 12:47:57 +01002450 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002451 throw e.rethrowFromSystemServer();
Nicolas Prevotc79586e2014-05-06 12:47:57 +01002452 }
2453 }
2454
2455 /**
2456 * @hide
2457 */
2458 @Override
Nicolas Prevot81948992014-05-16 18:25:26 +01002459 public void clearCrossProfileIntentFilters(int sourceUserId) {
Nicolas Prevotc79586e2014-05-06 12:47:57 +01002460 try {
Nicolas Prevot4b8d5822015-03-05 15:20:49 +00002461 mPM.clearCrossProfileIntentFilters(sourceUserId, mContext.getOpPackageName());
Nicolas Prevotc79586e2014-05-06 12:47:57 +01002462 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002463 throw e.rethrowFromSystemServer();
Nicolas Prevotc79586e2014-05-06 12:47:57 +01002464 }
2465 }
2466
Nicolas Prevot88cc3462014-05-14 14:51:48 +01002467 /**
2468 * @hide
2469 */
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +01002470 public Drawable loadItemIcon(PackageItemInfo itemInfo, ApplicationInfo appInfo) {
Benjamin Franzec2d48b2014-10-01 15:38:43 +01002471 Drawable dr = loadUnbadgedItemIcon(itemInfo, appInfo);
2472 if (itemInfo.showUserIcon != UserHandle.USER_NULL) {
2473 return dr;
2474 }
2475 return getUserBadgedIcon(dr, new UserHandle(mContext.getUserId()));
2476 }
2477
2478 /**
2479 * @hide
2480 */
2481 public Drawable loadUnbadgedItemIcon(PackageItemInfo itemInfo, ApplicationInfo appInfo) {
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +01002482 if (itemInfo.showUserIcon != UserHandle.USER_NULL) {
Alexandra Gherghina64d4dca2014-08-28 18:26:56 +01002483 Bitmap bitmap = getUserManager().getUserIcon(itemInfo.showUserIcon);
2484 if (bitmap == null) {
Tony Mak213955e2017-11-23 16:57:08 +08002485 return UserIcons.getDefaultUserIcon(
2486 mContext.getResources(), itemInfo.showUserIcon, /* light= */ false);
Alexandra Gherghina64d4dca2014-08-28 18:26:56 +01002487 }
2488 return new BitmapDrawable(bitmap);
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +01002489 }
Alexandra Gherghinadb811db2014-08-29 13:43:59 +01002490 Drawable dr = null;
2491 if (itemInfo.packageName != null) {
2492 dr = getDrawable(itemInfo.packageName, itemInfo.icon, appInfo);
2493 }
Alexandra Gherghinaa71e3902014-07-25 20:03:47 +01002494 if (dr == null) {
Alexandra Gherghinaa7093142014-07-30 13:43:39 +01002495 dr = itemInfo.loadDefaultIcon(this);
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +01002496 }
Benjamin Franzec2d48b2014-10-01 15:38:43 +01002497 return dr;
Svetoslavc7d62f02014-09-04 15:39:54 -07002498 }
2499
2500 private Drawable getBadgedDrawable(Drawable drawable, Drawable badgeDrawable,
2501 Rect badgeLocation, boolean tryBadgeInPlace) {
2502 final int badgedWidth = drawable.getIntrinsicWidth();
2503 final int badgedHeight = drawable.getIntrinsicHeight();
2504 final boolean canBadgeInPlace = tryBadgeInPlace
2505 && (drawable instanceof BitmapDrawable)
2506 && ((BitmapDrawable) drawable).getBitmap().isMutable();
2507
2508 final Bitmap bitmap;
2509 if (canBadgeInPlace) {
2510 bitmap = ((BitmapDrawable) drawable).getBitmap();
2511 } else {
2512 bitmap = Bitmap.createBitmap(badgedWidth, badgedHeight, Bitmap.Config.ARGB_8888);
2513 }
2514 Canvas canvas = new Canvas(bitmap);
2515
2516 if (!canBadgeInPlace) {
2517 drawable.setBounds(0, 0, badgedWidth, badgedHeight);
2518 drawable.draw(canvas);
2519 }
2520
2521 if (badgeLocation != null) {
2522 if (badgeLocation.left < 0 || badgeLocation.top < 0
2523 || badgeLocation.width() > badgedWidth || badgeLocation.height() > badgedHeight) {
2524 throw new IllegalArgumentException("Badge location " + badgeLocation
2525 + " not in badged drawable bounds "
2526 + new Rect(0, 0, badgedWidth, badgedHeight));
2527 }
2528 badgeDrawable.setBounds(0, 0, badgeLocation.width(), badgeLocation.height());
2529
2530 canvas.save();
2531 canvas.translate(badgeLocation.left, badgeLocation.top);
2532 badgeDrawable.draw(canvas);
2533 canvas.restore();
2534 } else {
2535 badgeDrawable.setBounds(0, 0, badgedWidth, badgedHeight);
2536 badgeDrawable.draw(canvas);
2537 }
2538
2539 if (!canBadgeInPlace) {
2540 BitmapDrawable mergedDrawable = new BitmapDrawable(mContext.getResources(), bitmap);
2541
2542 if (drawable instanceof BitmapDrawable) {
2543 BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
2544 mergedDrawable.setTargetDensity(bitmapDrawable.getBitmap().getDensity());
2545 }
2546
2547 return mergedDrawable;
2548 }
2549
2550 return drawable;
2551 }
2552
Tony Mak8673b282016-03-21 21:10:59 +00002553 private boolean isManagedProfile(int userId) {
2554 return getUserManager().isManagedProfile(userId);
Nicolas Prevot88cc3462014-05-14 14:51:48 +01002555 }
2556
Bartosz Fabianowskia34f53f2017-01-11 18:08:47 +01002557 /**
2558 * @hide
2559 */
2560 @Override
2561 public int getInstallReason(String packageName, UserHandle user) {
2562 try {
2563 return mPM.getInstallReason(packageName, user.getIdentifier());
2564 } catch (RemoteException e) {
2565 throw e.rethrowFromSystemServer();
2566 }
2567 }
2568
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002569 /** {@hide} */
2570 private static class MoveCallbackDelegate extends IPackageMoveObserver.Stub implements
2571 Handler.Callback {
Jeff Sharkey50a05452015-04-29 11:24:52 -07002572 private static final int MSG_CREATED = 1;
2573 private static final int MSG_STATUS_CHANGED = 2;
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002574
2575 final MoveCallback mCallback;
2576 final Handler mHandler;
2577
2578 public MoveCallbackDelegate(MoveCallback callback, Looper looper) {
2579 mCallback = callback;
2580 mHandler = new Handler(looper, this);
2581 }
2582
2583 @Override
2584 public boolean handleMessage(Message msg) {
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002585 switch (msg.what) {
Jeff Sharkey50a05452015-04-29 11:24:52 -07002586 case MSG_CREATED: {
Jeff Sharkeyb36586a2015-04-27 08:42:28 -07002587 final SomeArgs args = (SomeArgs) msg.obj;
Jeff Sharkey50a05452015-04-29 11:24:52 -07002588 mCallback.onCreated(args.argi1, (Bundle) args.arg2);
Jeff Sharkeyb36586a2015-04-27 08:42:28 -07002589 args.recycle();
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002590 return true;
Jeff Sharkey50a05452015-04-29 11:24:52 -07002591 }
2592 case MSG_STATUS_CHANGED: {
2593 final SomeArgs args = (SomeArgs) msg.obj;
2594 mCallback.onStatusChanged(args.argi1, args.argi2, (long) args.arg3);
2595 args.recycle();
2596 return true;
2597 }
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002598 }
2599 return false;
2600 }
2601
2602 @Override
Jeff Sharkey50a05452015-04-29 11:24:52 -07002603 public void onCreated(int moveId, Bundle extras) {
Jeff Sharkeyb36586a2015-04-27 08:42:28 -07002604 final SomeArgs args = SomeArgs.obtain();
2605 args.argi1 = moveId;
Jeff Sharkey50a05452015-04-29 11:24:52 -07002606 args.arg2 = extras;
2607 mHandler.obtainMessage(MSG_CREATED, args).sendToTarget();
2608 }
2609
2610 @Override
2611 public void onStatusChanged(int moveId, int status, long estMillis) {
2612 final SomeArgs args = SomeArgs.obtain();
2613 args.argi1 = moveId;
2614 args.argi2 = status;
2615 args.arg3 = estMillis;
Jeff Sharkeyb36586a2015-04-27 08:42:28 -07002616 mHandler.obtainMessage(MSG_STATUS_CHANGED, args).sendToTarget();
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002617 }
2618 }
2619
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002620 private final ContextImpl mContext;
2621 private final IPackageManager mPM;
2622
2623 private static final Object sSync = new Object();
Dianne Hackbornadd005c2013-07-17 18:43:12 -07002624 private static ArrayMap<ResourceName, WeakReference<Drawable.ConstantState>> sIconCache
2625 = new ArrayMap<ResourceName, WeakReference<Drawable.ConstantState>>();
2626 private static ArrayMap<ResourceName, WeakReference<CharSequence>> sStringCache
2627 = new ArrayMap<ResourceName, WeakReference<CharSequence>>();
Svetoslavf7c06eb2015-06-10 18:43:22 -07002628
2629 private final Map<OnPermissionsChangedListener, IOnPermissionsChangeListener>
2630 mPermissionListeners = new ArrayMap<>();
2631
2632 public class OnPermissionsChangeListenerDelegate extends IOnPermissionsChangeListener.Stub
2633 implements Handler.Callback{
2634 private static final int MSG_PERMISSIONS_CHANGED = 1;
2635
2636 private final OnPermissionsChangedListener mListener;
2637 private final Handler mHandler;
2638
2639
2640 public OnPermissionsChangeListenerDelegate(OnPermissionsChangedListener listener,
2641 Looper looper) {
2642 mListener = listener;
2643 mHandler = new Handler(looper, this);
2644 }
2645
2646 @Override
2647 public void onPermissionsChanged(int uid) {
2648 mHandler.obtainMessage(MSG_PERMISSIONS_CHANGED, uid, 0).sendToTarget();
2649 }
2650
2651 @Override
2652 public boolean handleMessage(Message msg) {
2653 switch (msg.what) {
2654 case MSG_PERMISSIONS_CHANGED: {
2655 final int uid = msg.arg1;
2656 mListener.onPermissionsChanged(uid);
2657 return true;
2658 }
2659 }
2660 return false;
2661 }
2662 }
Suprabh Shuklaaef25132017-01-23 18:09:03 -08002663
2664 @Override
2665 public boolean canRequestPackageInstalls() {
2666 try {
2667 return mPM.canRequestPackageInstalls(mContext.getPackageName(), mContext.getUserId());
2668 } catch (RemoteException e) {
2669 throw e.rethrowAsRuntimeException();
2670 }
2671 }
Chad Brubaker336ae5b2017-03-24 15:53:09 -07002672
2673 @Override
2674 public ComponentName getInstantAppResolverSettingsComponent() {
2675 try {
2676 return mPM.getInstantAppResolverSettingsComponent();
2677 } catch (RemoteException e) {
2678 throw e.rethrowAsRuntimeException();
2679 }
2680 }
Todd Kennedy801e6592017-04-12 14:10:12 -07002681
2682 @Override
2683 public ComponentName getInstantAppInstallerComponent() {
2684 try {
2685 return mPM.getInstantAppInstallerComponent();
2686 } catch (RemoteException e) {
2687 throw e.rethrowAsRuntimeException();
2688 }
2689 }
Chad Brubaker0d277a72017-04-12 16:56:53 -07002690
2691 @Override
2692 public String getInstantAppAndroidId(String packageName, UserHandle user) {
2693 try {
2694 return mPM.getInstantAppAndroidId(packageName, user.getIdentifier());
2695 } catch (RemoteException e) {
2696 throw e.rethrowAsRuntimeException();
2697 }
2698 }
Calin Juravle3d2af7f2017-04-19 19:56:21 -07002699
2700 private static class DexModuleRegisterResult {
2701 final String dexModulePath;
2702 final boolean success;
2703 final String message;
2704
2705 private DexModuleRegisterResult(String dexModulePath, boolean success, String message) {
2706 this.dexModulePath = dexModulePath;
2707 this.success = success;
2708 this.message = message;
2709 }
2710 }
2711
2712 private static class DexModuleRegisterCallbackDelegate
2713 extends android.content.pm.IDexModuleRegisterCallback.Stub
2714 implements Handler.Callback {
2715 private static final int MSG_DEX_MODULE_REGISTERED = 1;
2716 private final DexModuleRegisterCallback callback;
2717 private final Handler mHandler;
2718
2719 DexModuleRegisterCallbackDelegate(@NonNull DexModuleRegisterCallback callback) {
2720 this.callback = callback;
2721 mHandler = new Handler(Looper.getMainLooper(), this);
2722 }
2723
2724 @Override
2725 public void onDexModuleRegistered(@NonNull String dexModulePath, boolean success,
2726 @Nullable String message)throws RemoteException {
2727 mHandler.obtainMessage(MSG_DEX_MODULE_REGISTERED,
2728 new DexModuleRegisterResult(dexModulePath, success, message)).sendToTarget();
2729 }
2730
2731 @Override
2732 public boolean handleMessage(Message msg) {
2733 if (msg.what != MSG_DEX_MODULE_REGISTERED) {
2734 return false;
2735 }
2736 DexModuleRegisterResult result = (DexModuleRegisterResult)msg.obj;
2737 callback.onDexModuleRegistered(result.dexModulePath, result.success, result.message);
2738 return true;
2739 }
2740 }
2741
2742 @Override
2743 public void registerDexModule(@NonNull String dexModule,
2744 @Nullable DexModuleRegisterCallback callback) {
2745 // Check if this is a shared module by looking if the others can read it.
2746 boolean isSharedModule = false;
2747 try {
2748 StructStat stat = Os.stat(dexModule);
2749 if ((OsConstants.S_IROTH & stat.st_mode) != 0) {
2750 isSharedModule = true;
2751 }
2752 } catch (ErrnoException e) {
2753 callback.onDexModuleRegistered(dexModule, false,
2754 "Could not get stat the module file: " + e.getMessage());
2755 return;
2756 }
2757
2758 // Module path is ok.
2759 // Create the callback delegate to be passed to package manager service.
2760 DexModuleRegisterCallbackDelegate callbackDelegate = null;
2761 if (callback != null) {
2762 callbackDelegate = new DexModuleRegisterCallbackDelegate(callback);
2763 }
2764
2765 // Invoke the package manager service.
2766 try {
2767 mPM.registerDexModule(mContext.getPackageName(), dexModule,
2768 isSharedModule, callbackDelegate);
2769 } catch (RemoteException e) {
2770 throw e.rethrowAsRuntimeException();
2771 }
2772 }
Calin Juravle45f8b292017-11-07 18:49:43 -08002773
2774 @Override
Ben Gruver1ab3d6e2017-12-07 13:45:08 -08002775 public CharSequence getHarmfulAppWarning(String packageName) {
2776 try {
2777 return mPM.getHarmfulAppWarning(packageName, mContext.getUserId());
2778 } catch (RemoteException e) {
2779 throw e.rethrowAsRuntimeException();
2780 }
2781 }
2782
2783 @Override
2784 public void setHarmfulAppWarning(String packageName, CharSequence warning) {
2785 try {
2786 mPM.setHarmfulAppWarning(packageName, warning, mContext.getUserId());
2787 } catch (RemoteException e) {
2788 throw e.rethrowAsRuntimeException();
2789 }
2790 }
2791
2792 @Override
Calin Juravle45f8b292017-11-07 18:49:43 -08002793 public ArtManager getArtManager() {
2794 synchronized (mLock) {
2795 if (mArtManager == null) {
2796 try {
2797 mArtManager = new ArtManager(mPM.getArtManager());
2798 } catch (RemoteException e) {
2799 throw e.rethrowFromSystemServer();
2800 }
2801 }
2802 return mArtManager;
2803 }
2804 }
Makoto Onuki700feef2018-02-15 10:59:41 -08002805
2806 @Override
2807 public String getSystemTextClassifierPackageName() {
2808 try {
2809 return mPM.getSystemTextClassifierPackageName();
2810 } catch (RemoteException e) {
2811 throw e.rethrowAsRuntimeException();
2812 }
2813 }
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002814}