blob: c9031b711657b3adeeefef078b2ec3336340def6 [file] [log] [blame]
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001/*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.app;
18
Tor Norbye7b9c9122013-05-30 16:48:33 -070019import android.annotation.DrawableRes;
Alan Viveretteecd585a2015-04-13 10:32:51 -070020import android.annotation.NonNull;
21import android.annotation.Nullable;
Tor Norbye7b9c9122013-05-30 16:48:33 -070022import android.annotation.StringRes;
Philip P. Moltmann18e3eb82018-03-09 16:55:55 -080023import android.annotation.UserIdInt;
Tor Norbye7b9c9122013-05-30 16:48:33 -070024import android.annotation.XmlRes;
Artur Satayevc895b1b2019-12-10 17:47:51 +000025import android.compat.annotation.UnsupportedAppUsage;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080026import android.content.ComponentName;
27import android.content.ContentResolver;
Yao Chen022b8ea2016-12-16 11:03:28 -080028import android.content.Context;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080029import android.content.Intent;
30import android.content.IntentFilter;
31import android.content.IntentSender;
32import android.content.pm.ActivityInfo;
33import android.content.pm.ApplicationInfo;
Todd Kennedy9106c642017-02-08 14:16:53 -080034import android.content.pm.ChangedPackages;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080035import android.content.pm.ComponentInfo;
36import android.content.pm.FeatureInfo;
37import android.content.pm.IPackageDataObserver;
38import android.content.pm.IPackageDeleteObserver;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080039import android.content.pm.IPackageManager;
40import android.content.pm.IPackageMoveObserver;
41import android.content.pm.IPackageStatsObserver;
Alan Stokescae316d2019-11-26 09:39:02 +000042import android.content.pm.InstallSourceInfo;
Todd Kennedy9da8b8a72017-07-25 15:38:39 -070043import android.content.pm.InstantAppInfo;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080044import android.content.pm.InstrumentationInfo;
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -080045import android.content.pm.IntentFilterVerificationInfo;
dcashman9d2f4412014-06-09 09:27:54 -070046import android.content.pm.KeySet;
Todd Kennedy3dbf83a2018-11-13 13:29:16 -080047import android.content.pm.ModuleInfo;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080048import android.content.pm.PackageInfo;
Jeff Sharkey3a44f3f2014-04-28 17:36:31 -070049import android.content.pm.PackageInstaller;
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +010050import android.content.pm.PackageItemInfo;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080051import android.content.pm.PackageManager;
Kenny Roote6cd0c72011-05-19 12:48:14 -070052import android.content.pm.ParceledListSlice;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080053import android.content.pm.PermissionGroupInfo;
54import android.content.pm.PermissionInfo;
55import android.content.pm.ProviderInfo;
56import android.content.pm.ResolveInfo;
57import android.content.pm.ServiceInfo;
Svet Ganov67882122016-12-11 16:36:34 -080058import android.content.pm.SharedLibraryInfo;
Suprabh Shukla389cb6f2018-10-01 18:20:39 -070059import android.content.pm.SuspendDialogInfo;
Kenny Root0aaa0d92011-09-12 16:42:55 -070060import android.content.pm.VerifierDeviceIdentity;
Svet Ganov67882122016-12-11 16:36:34 -080061import android.content.pm.VersionedPackage;
Calin Juravle45f8b292017-11-07 18:49:43 -080062import android.content.pm.dex.ArtManager;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080063import android.content.res.Resources;
64import android.content.res.XmlResourceParser;
Svetoslavc7d62f02014-09-04 15:39:54 -070065import android.graphics.Bitmap;
66import android.graphics.Canvas;
67import android.graphics.Rect;
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +010068import android.graphics.drawable.BitmapDrawable;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080069import android.graphics.drawable.Drawable;
Kenny Guy02c89902016-11-15 19:36:38 +000070import android.graphics.drawable.LayerDrawable;
Jeff Sharkeye6306c42017-03-07 21:03:18 -070071import android.os.Build;
Jeff Sharkey50a05452015-04-29 11:24:52 -070072import android.os.Bundle;
Jeff Sharkey620b32b2015-04-23 19:36:02 -070073import android.os.Handler;
74import android.os.Looper;
75import android.os.Message;
Suprabh Shukla021b57a2018-03-08 18:21:50 -080076import android.os.PersistableBundle;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080077import android.os.Process;
78import android.os.RemoteException;
Jeff Sharkeyc59a5e72018-06-21 19:14:58 -060079import android.os.StrictMode;
Jeff Sharkeyb2b9ab82015-04-05 21:10:42 -070080import android.os.SystemProperties;
Amith Yamasani67df64b2012-12-14 12:09:36 -080081import android.os.UserHandle;
Nicolas Prevot88cc3462014-05-14 14:51:48 +010082import android.os.UserManager;
Jeff Sharkeye2d45be2015-04-15 17:14:12 -070083import android.os.storage.StorageManager;
84import android.os.storage.VolumeInfo;
Todd Kennedy7e3dd3a2019-07-08 10:34:29 -070085import android.permission.IOnPermissionsChangeListener;
Todd Kennedy8f135982019-07-02 07:35:15 -070086import android.permission.IPermissionManager;
Daniel Colascionea46b7b32020-01-24 13:30:25 -080087import android.permission.PermissionManager;
Todd Kennedyf39ca8f2015-08-07 14:15:07 -070088import android.provider.Settings;
Calin Juravle3d2af7f2017-04-19 19:56:21 -070089import android.system.ErrnoException;
90import android.system.Os;
91import android.system.OsConstants;
92import android.system.StructStat;
Suprabh Shukla389cb6f2018-10-01 18:20:39 -070093import android.text.TextUtils;
Dianne Hackbornadd005c2013-07-17 18:43:12 -070094import android.util.ArrayMap;
Svet Ganovd8eb8b22019-04-05 18:52:08 -070095import android.util.ArraySet;
Eugene Suslad516bee2019-05-01 09:48:43 -070096import android.util.DebugUtils;
Sunny Goyalbab30752017-04-12 15:36:42 -070097import android.util.LauncherIcons;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080098import android.util.Log;
Jeff Browna492c3a2012-08-23 19:48:44 -070099import android.view.Display;
Jeff Sharkeyb2b9ab82015-04-05 21:10:42 -0700100
Jeff Sharkey16c8e3f2014-07-24 17:08:17 -0700101import com.android.internal.annotations.GuardedBy;
Lee Shombert1f771842020-02-22 13:24:02 -0800102import com.android.internal.annotations.Immutable;
Kenny Guy02c89902016-11-15 19:36:38 +0000103import com.android.internal.annotations.VisibleForTesting;
Jeff Sharkeyb36586a2015-04-27 08:42:28 -0700104import com.android.internal.os.SomeArgs;
Alexandra Gherghina64d4dca2014-08-28 18:26:56 +0100105import com.android.internal.util.UserIcons;
Todd Kennedy9da8b8a72017-07-25 15:38:39 -0700106
107import dalvik.system.VMRuntime;
108
Svet Ganov2acf0632015-11-24 19:10:59 -0800109import libcore.util.EmptyArray;
Jeff Sharkey16c8e3f2014-07-24 17:08:17 -0700110
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800111import java.lang.ref.WeakReference;
112import java.util.ArrayList;
Svet Ganov2acf0632015-11-24 19:10:59 -0800113import java.util.Collections;
Jeff Sharkey620b32b2015-04-23 19:36:02 -0700114import java.util.Iterator;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800115import java.util.List;
Svetoslavf7c06eb2015-06-10 18:43:22 -0700116import java.util.Map;
Jeff Sharkey620b32b2015-04-23 19:36:02 -0700117import java.util.Objects;
Svet Ganovd8eb8b22019-04-05 18:52:08 -0700118import java.util.Set;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800119
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700120/** @hide */
121public class ApplicationPackageManager extends PackageManager {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800122 private static final String TAG = "ApplicationPackageManager";
Eugene Suslad516bee2019-05-01 09:48:43 -0700123 private static final boolean DEBUG_ICONS = false;
124 /**
125 * Note: Changing this won't do anything on it's own - you should also change the filtering in
126 * {@link #shouldTraceGrant}
127 *
128 * @hide
129 */
130 public static final boolean DEBUG_TRACE_GRANTS = false;
Eugene Suslacb923e32019-08-20 16:48:55 -0700131 public static final boolean DEBUG_TRACE_PERMISSION_UPDATES = false;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800132
Svet Ganov2acf0632015-11-24 19:10:59 -0800133 private static final int DEFAULT_EPHEMERAL_COOKIE_MAX_SIZE_BYTES = 16384; // 16KB
134
Adam Lesinskid00bb5e2014-10-07 12:14:45 -0700135 // Default flags to use with PackageManager when no flags are given.
Peter Wang09014f12020-01-24 08:15:38 +0800136 private static final int sDefaultFlags = GET_SHARED_LIBRARY_FILES;
Adam Lesinskid00bb5e2014-10-07 12:14:45 -0700137
Evan Seversoncfae44a2020-01-09 12:43:08 -0800138 // Name of the resource which provides background permission button string
139 public static final String APP_PERMISSION_BUTTON_ALLOW_ALWAYS =
140 "app_permission_button_allow_always";
141
Evan Seversoneb1e3292020-06-01 11:56:48 -0700142 // Name of the package which the permission controller's resources are in.
143 public static final String PERMISSION_CONTROLLER_RESOURCE_PACKAGE =
144 "com.android.permissioncontroller";
145
Jeff Sharkey16c8e3f2014-07-24 17:08:17 -0700146 private final Object mLock = new Object();
147
148 @GuardedBy("mLock")
149 private UserManager mUserManager;
150 @GuardedBy("mLock")
151 private PackageInstaller mInstaller;
Calin Juravle45f8b292017-11-07 18:49:43 -0800152 @GuardedBy("mLock")
153 private ArtManager mArtManager;
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +0100154
Jeff Sharkey620b32b2015-04-23 19:36:02 -0700155 @GuardedBy("mDelegates")
156 private final ArrayList<MoveCallbackDelegate> mDelegates = new ArrayList<>();
157
Svet Ganovf1b7f202015-07-29 08:33:42 -0700158 @GuardedBy("mLock")
159 private String mPermissionsControllerPackageName;
160
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +0100161 UserManager getUserManager() {
Jeff Sharkey16c8e3f2014-07-24 17:08:17 -0700162 synchronized (mLock) {
163 if (mUserManager == null) {
164 mUserManager = UserManager.get(mContext);
165 }
166 return mUserManager;
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +0100167 }
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +0100168 }
169
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800170 @Override
Jeff Sharkeyad357d12018-02-02 13:25:31 -0700171 public int getUserId() {
172 return mContext.getUserId();
173 }
174
175 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800176 public PackageInfo getPackageInfo(String packageName, int flags)
177 throws NameNotFoundException {
Jeff Sharkeyc59a5e72018-06-21 19:14:58 -0600178 return getPackageInfoAsUser(packageName, flags, getUserId());
Nicolas Prevot9a80e532015-09-23 15:49:28 +0100179 }
180
181 @Override
Svet Ganov67882122016-12-11 16:36:34 -0800182 public PackageInfo getPackageInfo(VersionedPackage versionedPackage, int flags)
183 throws NameNotFoundException {
Jeff Sharkeyc59a5e72018-06-21 19:14:58 -0600184 final int userId = getUserId();
Svet Ganov67882122016-12-11 16:36:34 -0800185 try {
Jeff Sharkeyc59a5e72018-06-21 19:14:58 -0600186 PackageInfo pi = mPM.getPackageInfoVersioned(versionedPackage,
187 updateFlagsForPackage(flags, userId), userId);
Svet Ganov67882122016-12-11 16:36:34 -0800188 if (pi != null) {
189 return pi;
190 }
191 } catch (RemoteException e) {
192 throw e.rethrowFromSystemServer();
193 }
194 throw new NameNotFoundException(versionedPackage.toString());
195 }
196
197 @Override
Nicolas Prevot9a80e532015-09-23 15:49:28 +0100198 public PackageInfo getPackageInfoAsUser(String packageName, int flags, int userId)
199 throws NameNotFoundException {
Daniel Colascionea46b7b32020-01-24 13:30:25 -0800200 PackageInfo pi =
201 getPackageInfoAsUserCached(
202 packageName,
203 updateFlagsForPackage(flags, userId),
204 userId);
205 if (pi == null) {
206 throw new NameNotFoundException(packageName);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800207 }
Daniel Colascionea46b7b32020-01-24 13:30:25 -0800208 return pi;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800209 }
210
211 @Override
212 public String[] currentToCanonicalPackageNames(String[] names) {
213 try {
214 return mPM.currentToCanonicalPackageNames(names);
215 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700216 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800217 }
218 }
219
220 @Override
221 public String[] canonicalToCurrentPackageNames(String[] names) {
222 try {
223 return mPM.canonicalToCurrentPackageNames(names);
224 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700225 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800226 }
227 }
228
229 @Override
230 public Intent getLaunchIntentForPackage(String packageName) {
231 // First see if the package has an INFO activity; the existence of
232 // such an activity is implied to be the desired front-door for the
233 // overall package (such as if it has multiple launcher entries).
234 Intent intentToResolve = new Intent(Intent.ACTION_MAIN);
235 intentToResolve.addCategory(Intent.CATEGORY_INFO);
236 intentToResolve.setPackage(packageName);
Dianne Hackborn19415762010-12-15 00:20:27 -0800237 List<ResolveInfo> ris = queryIntentActivities(intentToResolve, 0);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800238
239 // Otherwise, try to find a main launcher activity.
Dianne Hackborn19415762010-12-15 00:20:27 -0800240 if (ris == null || ris.size() <= 0) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800241 // reuse the intent instance
242 intentToResolve.removeCategory(Intent.CATEGORY_INFO);
243 intentToResolve.addCategory(Intent.CATEGORY_LAUNCHER);
244 intentToResolve.setPackage(packageName);
Dianne Hackborn19415762010-12-15 00:20:27 -0800245 ris = queryIntentActivities(intentToResolve, 0);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800246 }
Dianne Hackborn19415762010-12-15 00:20:27 -0800247 if (ris == null || ris.size() <= 0) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800248 return null;
249 }
250 Intent intent = new Intent(intentToResolve);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800251 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Dianne Hackborn19415762010-12-15 00:20:27 -0800252 intent.setClassName(ris.get(0).activityInfo.packageName,
253 ris.get(0).activityInfo.name);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800254 return intent;
255 }
256
257 @Override
Jose Lima970417c2014-04-10 10:42:19 -0700258 public Intent getLeanbackLaunchIntentForPackage(String packageName) {
Roberto Perez7ee1a7a2017-12-04 17:14:33 -0800259 return getLaunchIntentForPackageAndCategory(packageName, Intent.CATEGORY_LEANBACK_LAUNCHER);
260 }
261
262 @Override
263 public Intent getCarLaunchIntentForPackage(String packageName) {
264 return getLaunchIntentForPackageAndCategory(packageName, Intent.CATEGORY_CAR_LAUNCHER);
265 }
266
267 private Intent getLaunchIntentForPackageAndCategory(String packageName, String category) {
268 // Try to find a main launcher activity for the given categories.
Jose Lima970417c2014-04-10 10:42:19 -0700269 Intent intentToResolve = new Intent(Intent.ACTION_MAIN);
Roberto Perez7ee1a7a2017-12-04 17:14:33 -0800270 intentToResolve.addCategory(category);
Jose Lima970417c2014-04-10 10:42:19 -0700271 intentToResolve.setPackage(packageName);
272 List<ResolveInfo> ris = queryIntentActivities(intentToResolve, 0);
273
274 if (ris == null || ris.size() <= 0) {
275 return null;
276 }
277 Intent intent = new Intent(intentToResolve);
278 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
279 intent.setClassName(ris.get(0).activityInfo.packageName,
280 ris.get(0).activityInfo.name);
281 return intent;
282 }
283
284 @Override
Jeff Sharkey8588bc12016-01-06 16:47:42 -0700285 public int[] getPackageGids(String packageName) throws NameNotFoundException {
286 return getPackageGids(packageName, 0);
287 }
288
289 @Override
290 public int[] getPackageGids(String packageName, int flags)
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800291 throws NameNotFoundException {
Jeff Sharkeyc59a5e72018-06-21 19:14:58 -0600292 final int userId = getUserId();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800293 try {
Jeff Sharkeyc59a5e72018-06-21 19:14:58 -0600294 int[] gids = mPM.getPackageGids(packageName,
295 updateFlagsForPackage(flags, userId), userId);
Svetoslavc6d1c342015-02-26 14:44:43 -0800296 if (gids != null) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800297 return gids;
298 }
299 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700300 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800301 }
302
303 throw new NameNotFoundException(packageName);
304 }
305
306 @Override
Jeff Sharkey8588bc12016-01-06 16:47:42 -0700307 public int getPackageUid(String packageName, int flags) throws NameNotFoundException {
Jeff Sharkeyc59a5e72018-06-21 19:14:58 -0600308 return getPackageUidAsUser(packageName, flags, getUserId());
Jeff Sharkey8588bc12016-01-06 16:47:42 -0700309 }
310
311 @Override
312 public int getPackageUidAsUser(String packageName, int userId) throws NameNotFoundException {
313 return getPackageUidAsUser(packageName, 0, userId);
314 }
315
316 @Override
317 public int getPackageUidAsUser(String packageName, int flags, int userId)
Dianne Hackborna06de0f2012-12-11 16:34:47 -0800318 throws NameNotFoundException {
319 try {
Jeff Sharkeyc59a5e72018-06-21 19:14:58 -0600320 int uid = mPM.getPackageUid(packageName,
321 updateFlagsForPackage(flags, userId), userId);
Dianne Hackborna06de0f2012-12-11 16:34:47 -0800322 if (uid >= 0) {
323 return uid;
324 }
325 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700326 throw e.rethrowFromSystemServer();
Dianne Hackborna06de0f2012-12-11 16:34:47 -0800327 }
328
329 throw new NameNotFoundException(packageName);
330 }
331
332 @Override
Todd Kennedy1d29b4a2019-07-02 14:49:28 -0700333 @SuppressWarnings("unchecked")
334 public List<PermissionGroupInfo> getAllPermissionGroups(int flags) {
335 try {
336 final ParceledListSlice<PermissionGroupInfo> parceledList =
337 mPermissionManager.getAllPermissionGroups(flags);
338 if (parceledList == null) {
339 return Collections.emptyList();
340 }
341 return parceledList.getList();
342 } catch (RemoteException e) {
343 throw e.rethrowFromSystemServer();
344 }
345 }
346
347 @Override
348 public PermissionGroupInfo getPermissionGroupInfo(String groupName, int flags)
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800349 throws NameNotFoundException {
350 try {
Todd Kennedy1d29b4a2019-07-02 14:49:28 -0700351 final PermissionGroupInfo pgi =
352 mPermissionManager.getPermissionGroupInfo(groupName, flags);
353 if (pgi != null) {
354 return pgi;
355 }
356 } catch (RemoteException e) {
357 throw e.rethrowFromSystemServer();
358 }
359 throw new NameNotFoundException(groupName);
360 }
361
362 @Override
363 public PermissionInfo getPermissionInfo(String permName, int flags)
364 throws NameNotFoundException {
365 try {
366 final String packageName = mContext.getOpPackageName();
367 final PermissionInfo pi =
368 mPermissionManager.getPermissionInfo(permName, packageName, flags);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800369 if (pi != null) {
370 return pi;
371 }
372 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700373 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800374 }
Todd Kennedy1d29b4a2019-07-02 14:49:28 -0700375 throw new NameNotFoundException(permName);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800376 }
377
378 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700379 @SuppressWarnings("unchecked")
Todd Kennedy1d29b4a2019-07-02 14:49:28 -0700380 public List<PermissionInfo> queryPermissionsByGroup(String groupName, int flags)
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800381 throws NameNotFoundException {
382 try {
Todd Kennedy1d29b4a2019-07-02 14:49:28 -0700383 final ParceledListSlice<PermissionInfo> parceledList =
384 mPermissionManager.queryPermissionsByGroup(groupName, flags);
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700385 if (parceledList != null) {
Todd Kennedy1d29b4a2019-07-02 14:49:28 -0700386 final List<PermissionInfo> pi = parceledList.getList();
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700387 if (pi != null) {
388 return pi;
389 }
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800390 }
391 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700392 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800393 }
Todd Kennedy1d29b4a2019-07-02 14:49:28 -0700394 throw new NameNotFoundException(groupName);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800395 }
396
397 @Override
Philip P. Moltmann6c644e62018-07-18 15:41:24 -0700398 public boolean arePermissionsIndividuallyControlled() {
Paul Navin7b89a7b2017-01-26 23:56:08 +0000399 return mContext.getResources().getBoolean(
Philip P. Moltmann6c644e62018-07-18 15:41:24 -0700400 com.android.internal.R.bool.config_permissionsIndividuallyControlled);
401 }
402
403 @Override
404 public boolean isWirelessConsentModeEnabled() {
405 return mContext.getResources().getBoolean(
406 com.android.internal.R.bool.config_wirelessConsentRequired);
Paul Navin7b89a7b2017-01-26 23:56:08 +0000407 }
408
409 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800410 public ApplicationInfo getApplicationInfo(String packageName, int flags)
411 throws NameNotFoundException {
Jeff Sharkeyc59a5e72018-06-21 19:14:58 -0600412 return getApplicationInfoAsUser(packageName, flags, getUserId());
Jeff Sharkeycd654482016-01-08 17:42:11 -0700413 }
414
415 @Override
416 public ApplicationInfo getApplicationInfoAsUser(String packageName, int flags, int userId)
417 throws NameNotFoundException {
Daniel Colascionea46b7b32020-01-24 13:30:25 -0800418 ApplicationInfo ai = getApplicationInfoAsUserCached(
419 packageName,
420 updateFlagsForApplication(flags, userId),
421 userId);
422 if (ai == null) {
423 throw new NameNotFoundException(packageName);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800424 }
Daniel Colascionea46b7b32020-01-24 13:30:25 -0800425 return maybeAdjustApplicationInfo(ai);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800426 }
427
Tao Baic9a02372016-01-12 15:02:24 -0800428 private static ApplicationInfo maybeAdjustApplicationInfo(ApplicationInfo info) {
Narayan Kamathcaa71192014-07-16 11:06:43 +0100429 // If we're dealing with a multi-arch application that has both
430 // 32 and 64 bit shared libraries, we might need to choose the secondary
431 // depending on what the current runtime's instruction set is.
432 if (info.primaryCpuAbi != null && info.secondaryCpuAbi != null) {
433 final String runtimeIsa = VMRuntime.getRuntime().vmInstructionSet();
jgu214741cd92014-12-17 17:23:29 -0500434
435 // Get the instruction set that the libraries of secondary Abi is supported.
436 // In presence of a native bridge this might be different than the one secondary Abi used.
437 String secondaryIsa = VMRuntime.getInstructionSet(info.secondaryCpuAbi);
438 final String secondaryDexCodeIsa = SystemProperties.get("ro.dalvik.vm.isa." + secondaryIsa);
439 secondaryIsa = secondaryDexCodeIsa.isEmpty() ? secondaryIsa : secondaryDexCodeIsa;
Narayan Kamathcaa71192014-07-16 11:06:43 +0100440
441 // If the runtimeIsa is the same as the primary isa, then we do nothing.
442 // Everything will be set up correctly because info.nativeLibraryDir will
443 // correspond to the right ISA.
444 if (runtimeIsa.equals(secondaryIsa)) {
Tao Baic9a02372016-01-12 15:02:24 -0800445 ApplicationInfo modified = new ApplicationInfo(info);
446 modified.nativeLibraryDir = info.secondaryNativeLibraryDir;
447 return modified;
Narayan Kamathcaa71192014-07-16 11:06:43 +0100448 }
449 }
Tao Baic9a02372016-01-12 15:02:24 -0800450 return info;
Narayan Kamathcaa71192014-07-16 11:06:43 +0100451 }
452
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800453 @Override
454 public ActivityInfo getActivityInfo(ComponentName className, int flags)
455 throws NameNotFoundException {
Jeff Sharkeyc59a5e72018-06-21 19:14:58 -0600456 final int userId = getUserId();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800457 try {
Jeff Sharkeyc59a5e72018-06-21 19:14:58 -0600458 ActivityInfo ai = mPM.getActivityInfo(className,
459 updateFlagsForComponent(flags, userId, null), userId);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800460 if (ai != null) {
461 return ai;
462 }
463 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700464 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800465 }
466
467 throw new NameNotFoundException(className.toString());
468 }
469
470 @Override
471 public ActivityInfo getReceiverInfo(ComponentName className, int flags)
472 throws NameNotFoundException {
Jeff Sharkeyc59a5e72018-06-21 19:14:58 -0600473 final int userId = getUserId();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800474 try {
Jeff Sharkeyc59a5e72018-06-21 19:14:58 -0600475 ActivityInfo ai = mPM.getReceiverInfo(className,
476 updateFlagsForComponent(flags, userId, null), userId);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800477 if (ai != null) {
478 return ai;
479 }
480 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700481 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800482 }
483
484 throw new NameNotFoundException(className.toString());
485 }
486
487 @Override
488 public ServiceInfo getServiceInfo(ComponentName className, int flags)
489 throws NameNotFoundException {
Jeff Sharkeyc59a5e72018-06-21 19:14:58 -0600490 final int userId = getUserId();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800491 try {
Jeff Sharkeyc59a5e72018-06-21 19:14:58 -0600492 ServiceInfo si = mPM.getServiceInfo(className,
493 updateFlagsForComponent(flags, userId, null), userId);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800494 if (si != null) {
495 return si;
496 }
497 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700498 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800499 }
500
501 throw new NameNotFoundException(className.toString());
502 }
503
504 @Override
505 public ProviderInfo getProviderInfo(ComponentName className, int flags)
506 throws NameNotFoundException {
Jeff Sharkeyc59a5e72018-06-21 19:14:58 -0600507 final int userId = getUserId();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800508 try {
Jeff Sharkeyc59a5e72018-06-21 19:14:58 -0600509 ProviderInfo pi = mPM.getProviderInfo(className,
510 updateFlagsForComponent(flags, userId, null), userId);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800511 if (pi != null) {
512 return pi;
513 }
514 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700515 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800516 }
517
518 throw new NameNotFoundException(className.toString());
519 }
520
521 @Override
522 public String[] getSystemSharedLibraryNames() {
523 try {
524 return mPM.getSystemSharedLibraryNames();
525 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700526 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800527 }
528 }
529
Svet Ganovd7b1f4112016-02-09 18:49:23 -0800530 /** @hide */
531 @Override
Svet Ganov67882122016-12-11 16:36:34 -0800532 public @NonNull List<SharedLibraryInfo> getSharedLibraries(int flags) {
Jeff Sharkeyc59a5e72018-06-21 19:14:58 -0600533 return getSharedLibrariesAsUser(flags, getUserId());
Svet Ganov67882122016-12-11 16:36:34 -0800534 }
535
536 /** @hide */
537 @Override
538 @SuppressWarnings("unchecked")
539 public @NonNull List<SharedLibraryInfo> getSharedLibrariesAsUser(int flags, int userId) {
540 try {
541 ParceledListSlice<SharedLibraryInfo> sharedLibs = mPM.getSharedLibraries(
Svet Ganov58c99f02017-05-15 14:07:17 -0700542 mContext.getOpPackageName(), flags, userId);
Svet Ganov67882122016-12-11 16:36:34 -0800543 if (sharedLibs == null) {
544 return Collections.emptyList();
545 }
546 return sharedLibs.getList();
547 } catch (RemoteException e) {
548 throw e.rethrowFromSystemServer();
549 }
550 }
551
Hai Zhang1ad238f2019-03-20 16:11:07 -0700552 @NonNull
553 @Override
554 public List<SharedLibraryInfo> getDeclaredSharedLibraries(@NonNull String packageName,
555 @InstallFlags int flags) {
556 try {
557 ParceledListSlice<SharedLibraryInfo> sharedLibraries = mPM.getDeclaredSharedLibraries(
558 packageName, flags, mContext.getUserId());
559 return sharedLibraries != null ? sharedLibraries.getList() : Collections.emptyList();
560 } catch (RemoteException e) {
561 throw e.rethrowFromSystemServer();
562 }
563 }
564
Svet Ganov67882122016-12-11 16:36:34 -0800565 /** @hide */
566 @Override
Svetoslav Ganova9c25002016-04-13 19:25:56 -0700567 public @NonNull String getServicesSystemSharedLibraryPackageName() {
Svet Ganovd7b1f4112016-02-09 18:49:23 -0800568 try {
569 return mPM.getServicesSystemSharedLibraryPackageName();
570 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700571 throw e.rethrowFromSystemServer();
Svet Ganovd7b1f4112016-02-09 18:49:23 -0800572 }
573 }
574
Svetoslav Ganova9c25002016-04-13 19:25:56 -0700575 /**
576 * @hide
577 */
578 public @NonNull String getSharedSystemSharedLibraryPackageName() {
579 try {
580 return mPM.getSharedSystemSharedLibraryPackageName();
581 } catch (RemoteException e) {
582 throw e.rethrowFromSystemServer();
583 }
584 }
585
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800586 @Override
Todd Kennedy9106c642017-02-08 14:16:53 -0800587 public ChangedPackages getChangedPackages(int sequenceNumber) {
588 try {
Jeff Sharkeyc59a5e72018-06-21 19:14:58 -0600589 return mPM.getChangedPackages(sequenceNumber, getUserId());
Todd Kennedy9106c642017-02-08 14:16:53 -0800590 } catch (RemoteException e) {
591 throw e.rethrowFromSystemServer();
592 }
593 }
594
595 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700596 @SuppressWarnings("unchecked")
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800597 public FeatureInfo[] getSystemAvailableFeatures() {
598 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700599 ParceledListSlice<FeatureInfo> parceledList =
600 mPM.getSystemAvailableFeatures();
601 if (parceledList == null) {
602 return new FeatureInfo[0];
603 }
604 final List<FeatureInfo> list = parceledList.getList();
Jeff Sharkeyd5896632016-03-04 16:16:00 -0700605 final FeatureInfo[] res = new FeatureInfo[list.size()];
606 for (int i = 0; i < res.length; i++) {
607 res[i] = list.get(i);
608 }
609 return res;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800610 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700611 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800612 }
613 }
614
615 @Override
616 public boolean hasSystemFeature(String name) {
Jeff Sharkey115d2c12016-02-15 17:25:57 -0700617 return hasSystemFeature(name, 0);
618 }
619
Lee Shombert1f771842020-02-22 13:24:02 -0800620 /**
621 * Identifies a single hasSystemFeature query.
622 */
623 @Immutable
624 private static final class HasSystemFeatureQuery {
Lee Shombert72635f62019-12-19 15:40:21 -0800625 public final String name;
626 public final int version;
Lee Shombert89608112020-01-29 10:00:22 -0800627 public HasSystemFeatureQuery(String n, int v) {
Lee Shombert72635f62019-12-19 15:40:21 -0800628 name = n;
629 version = v;
630 }
631 @Override
632 public String toString() {
Lee Shombert89608112020-01-29 10:00:22 -0800633 return String.format("HasSystemFeatureQuery(name=\"%s\", version=%d)",
Lee Shombert72635f62019-12-19 15:40:21 -0800634 name, version);
635 }
636 @Override
637 public boolean equals(Object o) {
Lee Shombert89608112020-01-29 10:00:22 -0800638 if (o instanceof HasSystemFeatureQuery) {
639 HasSystemFeatureQuery r = (HasSystemFeatureQuery) o;
Lee Shombert72635f62019-12-19 15:40:21 -0800640 return Objects.equals(name, r.name) && version == r.version;
641 } else {
642 return false;
643 }
644 }
645 @Override
646 public int hashCode() {
Lee Shombert89608112020-01-29 10:00:22 -0800647 return Objects.hashCode(name) * 13 + version;
Lee Shombert72635f62019-12-19 15:40:21 -0800648 }
649 }
650
Lee Shombert89608112020-01-29 10:00:22 -0800651 // Make this cache relatively large. There are many system features and
652 // none are ever invalidated. MPTS tests suggests that the cache should
653 // hold at least 150 entries.
654 private final static PropertyInvalidatedCache<HasSystemFeatureQuery, Boolean>
655 mHasSystemFeatureCache =
656 new PropertyInvalidatedCache<HasSystemFeatureQuery, Boolean>(
657 256, "cache_key.has_system_feature") {
Lee Shombert72635f62019-12-19 15:40:21 -0800658 @Override
Lee Shombert89608112020-01-29 10:00:22 -0800659 protected Boolean recompute(HasSystemFeatureQuery query) {
660 try {
661 return ActivityThread.currentActivityThread().getPackageManager().
662 hasSystemFeature(query.name, query.version);
663 } catch (RemoteException e) {
664 throw e.rethrowFromSystemServer();
665 }
Lee Shombert72635f62019-12-19 15:40:21 -0800666 }
667 };
668
669 @Override
670 public boolean hasSystemFeature(String name, int version) {
Lee Shombert89608112020-01-29 10:00:22 -0800671 return mHasSystemFeatureCache.query(new HasSystemFeatureQuery(name, version));
Lee Shombert72635f62019-12-19 15:40:21 -0800672 }
673
674 /** @hide */
Lee Shombert89608112020-01-29 10:00:22 -0800675 public void disableHasSystemFeatureCache() {
676 mHasSystemFeatureCache.disableLocal();
Lee Shombert72635f62019-12-19 15:40:21 -0800677 }
678
679 /** @hide */
Lee Shombert89608112020-01-29 10:00:22 -0800680 public static void invalidateHasSystemFeatureCache() {
681 mHasSystemFeatureCache.invalidateCache();
Lee Shombert72635f62019-12-19 15:40:21 -0800682 }
683
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800684 @Override
685 public int checkPermission(String permName, String pkgName) {
Daniel Colascionea46b7b32020-01-24 13:30:25 -0800686 return PermissionManager
Daniel Colascione614105b2020-02-27 03:30:03 -0800687 .checkPackageNamePermission(permName, pkgName, getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800688 }
689
690 @Override
Svet Ganovad3b2972015-07-07 22:49:17 -0700691 public boolean isPermissionRevokedByPolicy(String permName, String pkgName) {
692 try {
Todd Kennedyc5b0e862019-07-16 09:47:58 -0700693 return mPermissionManager.isPermissionRevokedByPolicy(permName, pkgName, getUserId());
Svet Ganovad3b2972015-07-07 22:49:17 -0700694 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700695 throw e.rethrowFromSystemServer();
Svet Ganovad3b2972015-07-07 22:49:17 -0700696 }
697 }
698
Svet Ganovf1b7f202015-07-29 08:33:42 -0700699 /**
700 * @hide
701 */
702 @Override
703 public String getPermissionControllerPackageName() {
704 synchronized (mLock) {
705 if (mPermissionsControllerPackageName == null) {
706 try {
707 mPermissionsControllerPackageName = mPM.getPermissionControllerPackageName();
708 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700709 throw e.rethrowFromSystemServer();
Svet Ganovf1b7f202015-07-29 08:33:42 -0700710 }
711 }
712 return mPermissionsControllerPackageName;
713 }
714 }
715
Svet Ganovad3b2972015-07-07 22:49:17 -0700716 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800717 public boolean addPermission(PermissionInfo info) {
718 try {
Todd Kennedy6ffc5a62019-07-03 09:35:31 -0700719 return mPermissionManager.addPermission(info, false);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800720 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700721 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800722 }
723 }
724
725 @Override
726 public boolean addPermissionAsync(PermissionInfo info) {
727 try {
Todd Kennedy6ffc5a62019-07-03 09:35:31 -0700728 return mPermissionManager.addPermission(info, true);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800729 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700730 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800731 }
732 }
733
734 @Override
735 public void removePermission(String name) {
736 try {
Todd Kennedy6ffc5a62019-07-03 09:35:31 -0700737 mPermissionManager.removePermission(name);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800738 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700739 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800740 }
741 }
742
743 @Override
Svet Ganov8c7f7002015-05-07 10:48:44 -0700744 public void grantRuntimePermission(String packageName, String permissionName,
745 UserHandle user) {
Eugene Suslad516bee2019-05-01 09:48:43 -0700746 if (DEBUG_TRACE_GRANTS
747 && shouldTraceGrant(packageName, permissionName, user.getIdentifier())) {
Eugene Suslacb923e32019-08-20 16:48:55 -0700748 Log.i(TAG, "App " + mContext.getPackageName() + " is granting " + packageName + " "
Eugene Suslad516bee2019-05-01 09:48:43 -0700749 + permissionName + " for user " + user.getIdentifier(), new RuntimeException());
750 }
Dianne Hackborne639da72012-02-21 15:11:13 -0800751 try {
Svet Ganov8c7f7002015-05-07 10:48:44 -0700752 mPM.grantRuntimePermission(packageName, permissionName, user.getIdentifier());
Dianne Hackborne639da72012-02-21 15:11:13 -0800753 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700754 throw e.rethrowFromSystemServer();
Dianne Hackborne639da72012-02-21 15:11:13 -0800755 }
756 }
757
Eugene Suslad516bee2019-05-01 09:48:43 -0700758 /** @hide */
759 public static boolean shouldTraceGrant(String packageName, String permissionName, int userId) {
760 // To be modified when debugging
761 return false;
762 }
763
Dianne Hackborne639da72012-02-21 15:11:13 -0800764 @Override
Todd Kennedyc971a452019-07-08 16:04:52 -0700765 public void revokeRuntimePermission(String packageName, String permName, UserHandle user) {
Evan Seversonaacd48b2020-06-22 16:45:03 -0700766 revokeRuntimePermission(packageName, permName, user, null);
Svet Ganov8c7f7002015-05-07 10:48:44 -0700767 }
768
769 @Override
Evan Severson43b2a192020-02-19 13:45:49 -0800770 public void revokeRuntimePermission(String packageName, String permName, UserHandle user,
771 String reason) {
Evan Seversonaacd48b2020-06-22 16:45:03 -0700772 if (DEBUG_TRACE_PERMISSION_UPDATES
773 && shouldTraceGrant(packageName, permName, user.getIdentifier())) {
774 Log.i(TAG, "App " + mContext.getPackageName() + " is revoking " + packageName + " "
775 + permName + " for user " + user.getIdentifier() + " with reason " + reason,
776 new RuntimeException());
777 }
778 try {
779 mPermissionManager
780 .revokeRuntimePermission(packageName, permName, user.getIdentifier(), reason);
781 } catch (RemoteException e) {
782 throw e.rethrowFromSystemServer();
783 }
Evan Severson43b2a192020-02-19 13:45:49 -0800784 }
785
786 @Override
Todd Kennedy230c0a72019-07-03 13:06:35 -0700787 public int getPermissionFlags(String permName, String packageName, UserHandle user) {
Svet Ganov8c7f7002015-05-07 10:48:44 -0700788 try {
Todd Kennedy230c0a72019-07-03 13:06:35 -0700789 return mPermissionManager
790 .getPermissionFlags(permName, packageName, user.getIdentifier());
Svet Ganov8c7f7002015-05-07 10:48:44 -0700791 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700792 throw e.rethrowFromSystemServer();
Svet Ganov8c7f7002015-05-07 10:48:44 -0700793 }
794 }
795
796 @Override
Todd Kennedy230c0a72019-07-03 13:06:35 -0700797 public void updatePermissionFlags(String permName, String packageName,
Svet Ganov8c7f7002015-05-07 10:48:44 -0700798 int flagMask, int flagValues, UserHandle user) {
Eugene Suslacb923e32019-08-20 16:48:55 -0700799 if (DEBUG_TRACE_PERMISSION_UPDATES
Todd Kennedy230c0a72019-07-03 13:06:35 -0700800 && shouldTraceGrant(packageName, permName, user.getIdentifier())) {
Eugene Suslad516bee2019-05-01 09:48:43 -0700801 Log.i(TAG, "App " + mContext.getPackageName() + " is updating flags for "
Eugene Suslacb923e32019-08-20 16:48:55 -0700802 + packageName + " "
Todd Kennedy230c0a72019-07-03 13:06:35 -0700803 + permName + " for user " + user.getIdentifier() + ": "
Eugene Suslad516bee2019-05-01 09:48:43 -0700804 + DebugUtils.flagsToString(PackageManager.class, "FLAG_PERMISSION_", flagMask)
805 + " := " + DebugUtils.flagsToString(
806 PackageManager.class, "FLAG_PERMISSION_", flagValues),
807 new RuntimeException());
808 }
Svet Ganov8c7f7002015-05-07 10:48:44 -0700809 try {
Todd Kennedy230c0a72019-07-03 13:06:35 -0700810 final boolean checkAdjustPolicyFlagPermission =
811 mContext.getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.Q;
812 mPermissionManager.updatePermissionFlags(permName, packageName, flagMask,
813 flagValues, checkAdjustPolicyFlagPermission, user.getIdentifier());
Dianne Hackborne639da72012-02-21 15:11:13 -0800814 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700815 throw e.rethrowFromSystemServer();
Dianne Hackborne639da72012-02-21 15:11:13 -0800816 }
817 }
818
819 @Override
Svet Ganovd8eb8b22019-04-05 18:52:08 -0700820 public @NonNull Set<String> getWhitelistedRestrictedPermissions(
Todd Kennedy7e3dd3a2019-07-08 10:34:29 -0700821 @NonNull String packageName, @PermissionWhitelistFlags int flags) {
Svet Ganovd8eb8b22019-04-05 18:52:08 -0700822 try {
Todd Kennedy7e3dd3a2019-07-08 10:34:29 -0700823 final int userId = getUserId();
824 final List<String> whitelist = mPermissionManager
825 .getWhitelistedRestrictedPermissions(packageName, flags, userId);
Svet Ganovd8eb8b22019-04-05 18:52:08 -0700826 if (whitelist != null) {
827 return new ArraySet<>(whitelist);
828 }
829 return Collections.emptySet();
830 } catch (RemoteException e) {
831 throw e.rethrowFromSystemServer();
832 }
833 }
834
835 @Override
836 public boolean addWhitelistedRestrictedPermission(@NonNull String packageName,
Todd Kennedy7e3dd3a2019-07-08 10:34:29 -0700837 @NonNull String permName, @PermissionWhitelistFlags int flags) {
Svet Ganovd8eb8b22019-04-05 18:52:08 -0700838 try {
Todd Kennedy7e3dd3a2019-07-08 10:34:29 -0700839 final int userId = getUserId();
840 return mPermissionManager
841 .addWhitelistedRestrictedPermission(packageName, permName, flags, userId);
Svet Ganovd8eb8b22019-04-05 18:52:08 -0700842 } catch (RemoteException e) {
843 throw e.rethrowFromSystemServer();
844 }
845 }
846
847 @Override
Eugene Susla922cd082020-03-11 12:38:17 -0700848 public boolean setAutoRevokeWhitelisted(
849 @NonNull String packageName, boolean whitelisted) {
850 try {
851 final int userId = getUserId();
852 return mPermissionManager.setAutoRevokeWhitelisted(packageName, whitelisted, userId);
853 } catch (RemoteException e) {
854 throw e.rethrowFromSystemServer();
855 }
856 }
857
858 @Override
859 public boolean isAutoRevokeWhitelisted(@NonNull String packageName) {
860 try {
861 final int userId = getUserId();
862 return mPermissionManager.isAutoRevokeWhitelisted(packageName, userId);
863 } catch (RemoteException e) {
864 throw e.rethrowFromSystemServer();
865 }
866 }
867
868 @Override
Svet Ganovd8eb8b22019-04-05 18:52:08 -0700869 public boolean removeWhitelistedRestrictedPermission(@NonNull String packageName,
Todd Kennedy7e3dd3a2019-07-08 10:34:29 -0700870 @NonNull String permName, @PermissionWhitelistFlags int flags) {
Svet Ganovd8eb8b22019-04-05 18:52:08 -0700871 try {
Todd Kennedy7e3dd3a2019-07-08 10:34:29 -0700872 final int userId = getUserId();
873 return mPermissionManager
874 .removeWhitelistedRestrictedPermission(packageName, permName, flags, userId);
Svet Ganovd8eb8b22019-04-05 18:52:08 -0700875 } catch (RemoteException e) {
876 throw e.rethrowFromSystemServer();
877 }
878 }
879
880 @Override
Mathew Inwood61e8ae62018-08-14 14:17:44 +0100881 @UnsupportedAppUsage
Todd Kennedyc5b0e862019-07-16 09:47:58 -0700882 public boolean shouldShowRequestPermissionRationale(String permName) {
Svetoslav20770dd2015-05-29 15:43:04 -0700883 try {
Todd Kennedyc5b0e862019-07-16 09:47:58 -0700884 final String packageName = mContext.getPackageName();
885 return mPermissionManager
886 .shouldShowRequestPermissionRationale(permName, packageName, getUserId());
Svetoslav20770dd2015-05-29 15:43:04 -0700887 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700888 throw e.rethrowFromSystemServer();
Svetoslav20770dd2015-05-29 15:43:04 -0700889 }
890 }
891
892 @Override
Evan Seversond60c7852020-01-21 16:04:44 -0800893 public CharSequence getBackgroundPermissionOptionLabel() {
Evan Seversoncfae44a2020-01-09 12:43:08 -0800894 try {
895
896 String permissionController = getPermissionControllerPackageName();
897 Context context =
898 mContext.createPackageContext(permissionController, 0);
899
900 int textId = context.getResources().getIdentifier(APP_PERMISSION_BUTTON_ALLOW_ALWAYS,
Evan Seversoneb1e3292020-06-01 11:56:48 -0700901 "string", PERMISSION_CONTROLLER_RESOURCE_PACKAGE);
Evan Seversoncfae44a2020-01-09 12:43:08 -0800902 if (textId != 0) {
903 return context.getText(textId);
904 }
905 } catch (NameNotFoundException e) {
906 Log.e(TAG, "Permission controller not found.", e);
907 }
908 return "";
909 }
910
911 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800912 public int checkSignatures(String pkg1, String pkg2) {
913 try {
914 return mPM.checkSignatures(pkg1, pkg2);
915 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700916 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800917 }
918 }
919
920 @Override
921 public int checkSignatures(int uid1, int uid2) {
922 try {
923 return mPM.checkUidSignatures(uid1, uid2);
924 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700925 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800926 }
927 }
928
929 @Override
Daniel Cashman5cdda342018-01-19 07:22:52 -0800930 public boolean hasSigningCertificate(
Peter Wang09014f12020-01-24 08:15:38 +0800931 String packageName, byte[] certificate, @CertificateInputType int type) {
Daniel Cashman5cdda342018-01-19 07:22:52 -0800932 try {
933 return mPM.hasSigningCertificate(packageName, certificate, type);
934 } catch (RemoteException e) {
935 throw e.rethrowFromSystemServer();
936 }
937 }
938
939 @Override
940 public boolean hasSigningCertificate(
Peter Wang09014f12020-01-24 08:15:38 +0800941 int uid, byte[] certificate, @CertificateInputType int type) {
Daniel Cashman5cdda342018-01-19 07:22:52 -0800942 try {
943 return mPM.hasUidSigningCertificate(uid, certificate, type);
944 } catch (RemoteException e) {
945 throw e.rethrowFromSystemServer();
946 }
947 }
948
949 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800950 public String[] getPackagesForUid(int uid) {
951 try {
952 return mPM.getPackagesForUid(uid);
953 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700954 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800955 }
956 }
957
958 @Override
959 public String getNameForUid(int uid) {
960 try {
961 return mPM.getNameForUid(uid);
962 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700963 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800964 }
965 }
966
967 @Override
Todd Kennedy9da8b8a72017-07-25 15:38:39 -0700968 public String[] getNamesForUids(int[] uids) {
969 try {
970 return mPM.getNamesForUids(uids);
971 } catch (RemoteException e) {
972 throw e.rethrowFromSystemServer();
973 }
974 }
975
976 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800977 public int getUidForSharedUser(String sharedUserName)
978 throws NameNotFoundException {
979 try {
980 int uid = mPM.getUidForSharedUser(sharedUserName);
981 if(uid != -1) {
982 return uid;
983 }
984 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700985 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800986 }
987 throw new NameNotFoundException("No shared userid for user:"+sharedUserName);
988 }
989
Todd Kennedy3dbf83a2018-11-13 13:29:16 -0800990 @Override
991 public List<ModuleInfo> getInstalledModules(int flags) {
Narayan Kamath2c828c1d2018-12-10 17:36:31 +0000992 try {
993 return mPM.getInstalledModules(flags);
994 } catch (RemoteException e) {
995 throw e.rethrowFromSystemServer();
996 }
Todd Kennedy3dbf83a2018-11-13 13:29:16 -0800997 }
998
999 @Override
1000 public ModuleInfo getModuleInfo(String packageName, int flags) throws NameNotFoundException {
Narayan Kamath2c828c1d2018-12-10 17:36:31 +00001001 try {
1002 ModuleInfo mi = mPM.getModuleInfo(packageName, flags);
1003 if (mi != null) {
1004 return mi;
1005 }
1006 } catch (RemoteException e) {
1007 throw e.rethrowFromSystemServer();
1008 }
1009
1010 throw new NameNotFoundException("No module info for package: " + packageName);
Todd Kennedy3dbf83a2018-11-13 13:29:16 -08001011 }
1012
Kenny Roote6cd0c72011-05-19 12:48:14 -07001013 @SuppressWarnings("unchecked")
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001014 @Override
1015 public List<PackageInfo> getInstalledPackages(int flags) {
Jeff Sharkeyc59a5e72018-06-21 19:14:58 -06001016 return getInstalledPackagesAsUser(flags, getUserId());
Amith Yamasani151ec4c2012-09-07 19:25:16 -07001017 }
1018
1019 /** @hide */
1020 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001021 @SuppressWarnings("unchecked")
Jeff Sharkeye06b4d12016-01-06 14:51:50 -07001022 public List<PackageInfo> getInstalledPackagesAsUser(int flags, int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001023 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001024 ParceledListSlice<PackageInfo> parceledList =
Jeff Sharkeyc59a5e72018-06-21 19:14:58 -06001025 mPM.getInstalledPackages(updateFlagsForPackage(flags, userId), userId);
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001026 if (parceledList == null) {
1027 return Collections.emptyList();
1028 }
1029 return parceledList.getList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001030 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001031 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001032 }
1033 }
1034
Kenny Roote6cd0c72011-05-19 12:48:14 -07001035 @SuppressWarnings("unchecked")
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001036 @Override
Dianne Hackborne7991752013-01-16 17:56:46 -08001037 public List<PackageInfo> getPackagesHoldingPermissions(
1038 String[] permissions, int flags) {
Jeff Sharkeyc59a5e72018-06-21 19:14:58 -06001039 final int userId = getUserId();
Dianne Hackborne7991752013-01-16 17:56:46 -08001040 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001041 ParceledListSlice<PackageInfo> parceledList =
Jeff Sharkeyc59a5e72018-06-21 19:14:58 -06001042 mPM.getPackagesHoldingPermissions(permissions,
1043 updateFlagsForPackage(flags, userId), userId);
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001044 if (parceledList == null) {
1045 return Collections.emptyList();
1046 }
1047 return parceledList.getList();
Dianne Hackborne7991752013-01-16 17:56:46 -08001048 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001049 throw e.rethrowFromSystemServer();
Dianne Hackborne7991752013-01-16 17:56:46 -08001050 }
1051 }
1052
1053 @SuppressWarnings("unchecked")
1054 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001055 public List<ApplicationInfo> getInstalledApplications(int flags) {
Jeff Sharkeyc59a5e72018-06-21 19:14:58 -06001056 return getInstalledApplicationsAsUser(flags, getUserId());
Bartosz Fabianowski11334242016-11-17 20:49:16 +01001057 }
1058
1059 /** @hide */
1060 @SuppressWarnings("unchecked")
1061 @Override
1062 public List<ApplicationInfo> getInstalledApplicationsAsUser(int flags, int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001063 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001064 ParceledListSlice<ApplicationInfo> parceledList =
Jeff Sharkeyc59a5e72018-06-21 19:14:58 -06001065 mPM.getInstalledApplications(updateFlagsForApplication(flags, userId), userId);
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001066 if (parceledList == null) {
1067 return Collections.emptyList();
1068 }
1069 return parceledList.getList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001070 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001071 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001072 }
1073 }
1074
Svet Ganov2acf0632015-11-24 19:10:59 -08001075 /** @hide */
1076 @SuppressWarnings("unchecked")
1077 @Override
Svetoslav Ganov096d3042017-01-30 16:34:13 -08001078 public List<InstantAppInfo> getInstantApps() {
Svet Ganov2acf0632015-11-24 19:10:59 -08001079 try {
Jeff Sharkeyc59a5e72018-06-21 19:14:58 -06001080 ParceledListSlice<InstantAppInfo> slice = mPM.getInstantApps(getUserId());
Svet Ganov2acf0632015-11-24 19:10:59 -08001081 if (slice != null) {
1082 return slice.getList();
1083 }
1084 return Collections.emptyList();
1085 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001086 throw e.rethrowFromSystemServer();
Svet Ganov2acf0632015-11-24 19:10:59 -08001087 }
1088 }
1089
1090 /** @hide */
1091 @Override
Svetoslav Ganov096d3042017-01-30 16:34:13 -08001092 public Drawable getInstantAppIcon(String packageName) {
Svet Ganov2acf0632015-11-24 19:10:59 -08001093 try {
Jeff Sharkeyc59a5e72018-06-21 19:14:58 -06001094 Bitmap bitmap = mPM.getInstantAppIcon(packageName, getUserId());
Svet Ganov2acf0632015-11-24 19:10:59 -08001095 if (bitmap != null) {
1096 return new BitmapDrawable(null, bitmap);
1097 }
1098 return null;
1099 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001100 throw e.rethrowFromSystemServer();
Svet Ganov2acf0632015-11-24 19:10:59 -08001101 }
1102 }
1103
1104 @Override
Svetoslav Ganov096d3042017-01-30 16:34:13 -08001105 public boolean isInstantApp() {
David Christie31a16552017-03-01 15:08:45 -08001106 return isInstantApp(mContext.getPackageName());
1107 }
1108
1109 @Override
1110 public boolean isInstantApp(String packageName) {
Svet Ganov2acf0632015-11-24 19:10:59 -08001111 try {
Jeff Sharkeyc59a5e72018-06-21 19:14:58 -06001112 return mPM.isInstantApp(packageName, getUserId());
Svet Ganov2acf0632015-11-24 19:10:59 -08001113 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001114 throw e.rethrowFromSystemServer();
Svet Ganov2acf0632015-11-24 19:10:59 -08001115 }
Svet Ganov2acf0632015-11-24 19:10:59 -08001116 }
1117
Svetoslav Ganov345ffa52017-04-18 16:08:41 -07001118 public int getInstantAppCookieMaxBytes() {
Svet Ganov2acf0632015-11-24 19:10:59 -08001119 return Settings.Global.getInt(mContext.getContentResolver(),
1120 Settings.Global.EPHEMERAL_COOKIE_MAX_SIZE_BYTES,
1121 DEFAULT_EPHEMERAL_COOKIE_MAX_SIZE_BYTES);
1122 }
1123
1124 @Override
Svetoslav Ganov345ffa52017-04-18 16:08:41 -07001125 public int getInstantAppCookieMaxSize() {
1126 return getInstantAppCookieMaxBytes();
1127 }
1128
1129 @Override
Svetoslav Ganov096d3042017-01-30 16:34:13 -08001130 public @NonNull byte[] getInstantAppCookie() {
Svet Ganov2acf0632015-11-24 19:10:59 -08001131 try {
Jeff Sharkeyc59a5e72018-06-21 19:14:58 -06001132 final byte[] cookie = mPM.getInstantAppCookie(mContext.getPackageName(), getUserId());
Svet Ganov2acf0632015-11-24 19:10:59 -08001133 if (cookie != null) {
1134 return cookie;
Jeff Sharkey27b2e692016-02-25 17:40:12 -07001135 } else {
1136 return EmptyArray.BYTE;
Svet Ganov2acf0632015-11-24 19:10:59 -08001137 }
1138 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001139 throw e.rethrowFromSystemServer();
Svet Ganov2acf0632015-11-24 19:10:59 -08001140 }
Svet Ganov2acf0632015-11-24 19:10:59 -08001141 }
1142
1143 @Override
Svetoslav Ganov345ffa52017-04-18 16:08:41 -07001144 public void clearInstantAppCookie() {
1145 updateInstantAppCookie(null);
1146 }
1147
1148 @Override
1149 public void updateInstantAppCookie(@NonNull byte[] cookie) {
1150 if (cookie != null && cookie.length > getInstantAppCookieMaxBytes()) {
1151 throw new IllegalArgumentException("instant cookie longer than "
1152 + getInstantAppCookieMaxBytes());
1153 }
1154 try {
Jeff Sharkeyc59a5e72018-06-21 19:14:58 -06001155 mPM.setInstantAppCookie(mContext.getPackageName(), cookie, getUserId());
Svetoslav Ganov345ffa52017-04-18 16:08:41 -07001156 } catch (RemoteException e) {
1157 throw e.rethrowFromSystemServer();
1158 }
1159 }
1160
Mathew Inwood3a75f262019-06-27 12:47:38 +01001161 @UnsupportedAppUsage
Svetoslav Ganov345ffa52017-04-18 16:08:41 -07001162 @Override
Svetoslav Ganov096d3042017-01-30 16:34:13 -08001163 public boolean setInstantAppCookie(@NonNull byte[] cookie) {
Svet Ganov2acf0632015-11-24 19:10:59 -08001164 try {
Jeff Sharkeyc59a5e72018-06-21 19:14:58 -06001165 return mPM.setInstantAppCookie(mContext.getPackageName(), cookie, getUserId());
Svet Ganov2acf0632015-11-24 19:10:59 -08001166 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001167 throw e.rethrowFromSystemServer();
Svet Ganov2acf0632015-11-24 19:10:59 -08001168 }
Svet Ganov2acf0632015-11-24 19:10:59 -08001169 }
1170
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001171 @Override
1172 public ResolveInfo resolveActivity(Intent intent, int flags) {
Jeff Sharkeyc59a5e72018-06-21 19:14:58 -06001173 return resolveActivityAsUser(intent, flags, getUserId());
Svetoslav Ganov58d37b52012-09-18 12:04:19 -07001174 }
1175
1176 @Override
1177 public ResolveInfo resolveActivityAsUser(Intent intent, int flags, int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001178 try {
1179 return mPM.resolveIntent(
1180 intent,
1181 intent.resolveTypeIfNeeded(mContext.getContentResolver()),
Jeff Sharkeyc59a5e72018-06-21 19:14:58 -06001182 updateFlagsForComponent(flags, userId, intent),
Svetoslav Ganov58d37b52012-09-18 12:04:19 -07001183 userId);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001184 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001185 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001186 }
1187 }
1188
1189 @Override
1190 public List<ResolveInfo> queryIntentActivities(Intent intent,
1191 int flags) {
Jeff Sharkeyc59a5e72018-06-21 19:14:58 -06001192 return queryIntentActivitiesAsUser(intent, flags, getUserId());
Amith Yamasani151ec4c2012-09-07 19:25:16 -07001193 }
1194
1195 /** @hide Same as above but for a specific user */
1196 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001197 @SuppressWarnings("unchecked")
Svetoslav Ganov58d37b52012-09-18 12:04:19 -07001198 public List<ResolveInfo> queryIntentActivitiesAsUser(Intent intent,
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001199 int flags, int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001200 try {
Jeff Sharkeyc59a5e72018-06-21 19:14:58 -06001201 ParceledListSlice<ResolveInfo> parceledList = mPM.queryIntentActivities(
1202 intent,
1203 intent.resolveTypeIfNeeded(mContext.getContentResolver()),
1204 updateFlagsForComponent(flags, userId, intent),
1205 userId);
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001206 if (parceledList == null) {
1207 return Collections.emptyList();
1208 }
1209 return parceledList.getList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001210 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001211 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001212 }
1213 }
1214
1215 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001216 @SuppressWarnings("unchecked")
Jeff Sharkeyc59a5e72018-06-21 19:14:58 -06001217 public List<ResolveInfo> queryIntentActivityOptions(ComponentName caller, Intent[] specifics,
1218 Intent intent, int flags) {
1219 final int userId = getUserId();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001220 final ContentResolver resolver = mContext.getContentResolver();
1221
1222 String[] specificTypes = null;
1223 if (specifics != null) {
1224 final int N = specifics.length;
1225 for (int i=0; i<N; i++) {
1226 Intent sp = specifics[i];
1227 if (sp != null) {
1228 String t = sp.resolveTypeIfNeeded(resolver);
1229 if (t != null) {
1230 if (specificTypes == null) {
1231 specificTypes = new String[N];
1232 }
1233 specificTypes[i] = t;
1234 }
1235 }
1236 }
1237 }
1238
1239 try {
Jeff Sharkeyc59a5e72018-06-21 19:14:58 -06001240 ParceledListSlice<ResolveInfo> parceledList = mPM.queryIntentActivityOptions(
1241 caller,
1242 specifics,
1243 specificTypes,
1244 intent,
1245 intent.resolveTypeIfNeeded(resolver),
1246 updateFlagsForComponent(flags, userId, intent),
1247 userId);
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001248 if (parceledList == null) {
1249 return Collections.emptyList();
1250 }
1251 return parceledList.getList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001252 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001253 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001254 }
1255 }
1256
Amith Yamasanif203aee2012-08-29 18:41:53 -07001257 /**
1258 * @hide
1259 */
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001260 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001261 @SuppressWarnings("unchecked")
Jeff Sharkeye06b4d12016-01-06 14:51:50 -07001262 public List<ResolveInfo> queryBroadcastReceiversAsUser(Intent intent, int flags, int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001263 try {
Jeff Sharkeyc59a5e72018-06-21 19:14:58 -06001264 ParceledListSlice<ResolveInfo> parceledList = mPM.queryIntentReceivers(
1265 intent,
1266 intent.resolveTypeIfNeeded(mContext.getContentResolver()),
1267 updateFlagsForComponent(flags, userId, intent),
1268 userId);
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001269 if (parceledList == null) {
1270 return Collections.emptyList();
1271 }
1272 return parceledList.getList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001273 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001274 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001275 }
1276 }
1277
1278 @Override
Amith Yamasanif203aee2012-08-29 18:41:53 -07001279 public List<ResolveInfo> queryBroadcastReceivers(Intent intent, int flags) {
Jeff Sharkeyc59a5e72018-06-21 19:14:58 -06001280 return queryBroadcastReceiversAsUser(intent, flags, getUserId());
Amith Yamasanif203aee2012-08-29 18:41:53 -07001281 }
1282
1283 @Override
Philip P. Moltmann18e3eb82018-03-09 16:55:55 -08001284 public ResolveInfo resolveServiceAsUser(Intent intent, @ResolveInfoFlags int flags,
1285 @UserIdInt int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001286 try {
1287 return mPM.resolveService(
1288 intent,
1289 intent.resolveTypeIfNeeded(mContext.getContentResolver()),
Jeff Sharkeyc59a5e72018-06-21 19:14:58 -06001290 updateFlagsForComponent(flags, userId, intent),
Philip P. Moltmann18e3eb82018-03-09 16:55:55 -08001291 userId);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001292 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001293 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001294 }
1295 }
1296
1297 @Override
Philip P. Moltmann18e3eb82018-03-09 16:55:55 -08001298 public ResolveInfo resolveService(Intent intent, int flags) {
Jeff Sharkeyc59a5e72018-06-21 19:14:58 -06001299 return resolveServiceAsUser(intent, flags, getUserId());
Philip P. Moltmann18e3eb82018-03-09 16:55:55 -08001300 }
1301
1302 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001303 @SuppressWarnings("unchecked")
Svetoslav Ganov58d37b52012-09-18 12:04:19 -07001304 public List<ResolveInfo> queryIntentServicesAsUser(Intent intent, int flags, int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001305 try {
Jeff Sharkeyc59a5e72018-06-21 19:14:58 -06001306 ParceledListSlice<ResolveInfo> parceledList = mPM.queryIntentServices(
1307 intent,
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001308 intent.resolveTypeIfNeeded(mContext.getContentResolver()),
Jeff Sharkeyc59a5e72018-06-21 19:14:58 -06001309 updateFlagsForComponent(flags, userId, intent),
1310 userId);
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001311 if (parceledList == null) {
1312 return Collections.emptyList();
1313 }
1314 return parceledList.getList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001315 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001316 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001317 }
1318 }
1319
1320 @Override
Svetoslav Ganov58d37b52012-09-18 12:04:19 -07001321 public List<ResolveInfo> queryIntentServices(Intent intent, int flags) {
Jeff Sharkeyc59a5e72018-06-21 19:14:58 -06001322 return queryIntentServicesAsUser(intent, flags, getUserId());
Svetoslav Ganov58d37b52012-09-18 12:04:19 -07001323 }
1324
1325 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001326 @SuppressWarnings("unchecked")
Jeff Sharkey85f5f812013-10-07 10:16:12 -07001327 public List<ResolveInfo> queryIntentContentProvidersAsUser(
1328 Intent intent, int flags, int userId) {
1329 try {
Jeff Sharkeyc59a5e72018-06-21 19:14:58 -06001330 ParceledListSlice<ResolveInfo> parceledList = mPM.queryIntentContentProviders(
1331 intent,
1332 intent.resolveTypeIfNeeded(mContext.getContentResolver()),
1333 updateFlagsForComponent(flags, userId, intent),
1334 userId);
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001335 if (parceledList == null) {
1336 return Collections.emptyList();
1337 }
1338 return parceledList.getList();
Jeff Sharkey85f5f812013-10-07 10:16:12 -07001339 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001340 throw e.rethrowFromSystemServer();
Jeff Sharkey85f5f812013-10-07 10:16:12 -07001341 }
1342 }
1343
1344 @Override
1345 public List<ResolveInfo> queryIntentContentProviders(Intent intent, int flags) {
Jeff Sharkeyc59a5e72018-06-21 19:14:58 -06001346 return queryIntentContentProvidersAsUser(intent, flags, getUserId());
Jeff Sharkey85f5f812013-10-07 10:16:12 -07001347 }
1348
1349 @Override
Alexandra Gherghina0363c3e2014-06-23 13:34:59 +01001350 public ProviderInfo resolveContentProvider(String name, int flags) {
Jeff Sharkeyc59a5e72018-06-21 19:14:58 -06001351 return resolveContentProviderAsUser(name, flags, getUserId());
Alexandra Gherghina0363c3e2014-06-23 13:34:59 +01001352 }
1353
1354 /** @hide **/
1355 @Override
1356 public ProviderInfo resolveContentProviderAsUser(String name, int flags, int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001357 try {
Jeff Sharkeyc59a5e72018-06-21 19:14:58 -06001358 return mPM.resolveContentProvider(name,
1359 updateFlagsForComponent(flags, userId, null), userId);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001360 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001361 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001362 }
1363 }
1364
1365 @Override
1366 public List<ProviderInfo> queryContentProviders(String processName,
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001367 int uid, int flags) {
Makoto Onuki32757292017-02-22 14:36:59 -08001368 return queryContentProviders(processName, uid, flags, null);
1369 }
1370
1371 @Override
1372 @SuppressWarnings("unchecked")
1373 public List<ProviderInfo> queryContentProviders(String processName,
1374 int uid, int flags, String metaDataKey) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001375 try {
Jeff Sharkeyc59a5e72018-06-21 19:14:58 -06001376 ParceledListSlice<ProviderInfo> slice = mPM.queryContentProviders(processName, uid,
1377 updateFlagsForComponent(flags, UserHandle.getUserId(uid), null), metaDataKey);
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001378 return slice != null ? slice.getList() : Collections.<ProviderInfo>emptyList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001379 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001380 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001381 }
1382 }
1383
1384 @Override
1385 public InstrumentationInfo getInstrumentationInfo(
1386 ComponentName className, int flags)
1387 throws NameNotFoundException {
1388 try {
1389 InstrumentationInfo ii = mPM.getInstrumentationInfo(
1390 className, flags);
1391 if (ii != null) {
1392 return ii;
1393 }
1394 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001395 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001396 }
1397
1398 throw new NameNotFoundException(className.toString());
1399 }
1400
1401 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001402 @SuppressWarnings("unchecked")
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001403 public List<InstrumentationInfo> queryInstrumentation(
1404 String targetPackage, int flags) {
1405 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001406 ParceledListSlice<InstrumentationInfo> parceledList =
1407 mPM.queryInstrumentation(targetPackage, flags);
1408 if (parceledList == null) {
1409 return Collections.emptyList();
1410 }
1411 return parceledList.getList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001412 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001413 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001414 }
1415 }
1416
Alan Viveretteecd585a2015-04-13 10:32:51 -07001417 @Nullable
1418 @Override
1419 public Drawable getDrawable(String packageName, @DrawableRes int resId,
1420 @Nullable ApplicationInfo appInfo) {
1421 final ResourceName name = new ResourceName(packageName, resId);
1422 final Drawable cachedIcon = getCachedIcon(name);
1423 if (cachedIcon != null) {
1424 return cachedIcon;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001425 }
Alan Viveretteecd585a2015-04-13 10:32:51 -07001426
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001427 if (appInfo == null) {
1428 try {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001429 appInfo = getApplicationInfo(packageName, sDefaultFlags);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001430 } catch (NameNotFoundException e) {
1431 return null;
1432 }
1433 }
Alan Viveretteecd585a2015-04-13 10:32:51 -07001434
1435 if (resId != 0) {
1436 try {
1437 final Resources r = getResourcesForApplication(appInfo);
1438 final Drawable dr = r.getDrawable(resId, null);
1439 if (dr != null) {
1440 putCachedIcon(name, dr);
1441 }
1442
1443 if (false) {
1444 RuntimeException e = new RuntimeException("here");
1445 e.fillInStackTrace();
1446 Log.w(TAG, "Getting drawable 0x" + Integer.toHexString(resId)
1447 + " from package " + packageName
1448 + ": app scale=" + r.getCompatibilityInfo().applicationScale
1449 + ", caller scale=" + mContext.getResources()
1450 .getCompatibilityInfo().applicationScale,
1451 e);
1452 }
Ricky Wai3ce46252015-04-15 16:12:22 +01001453 if (DEBUG_ICONS) {
Alan Viveretteecd585a2015-04-13 10:32:51 -07001454 Log.v(TAG, "Getting drawable 0x"
1455 + Integer.toHexString(resId) + " from " + r
1456 + ": " + dr);
Ricky Wai3ce46252015-04-15 16:12:22 +01001457 }
1458 return dr;
Alan Viveretteecd585a2015-04-13 10:32:51 -07001459 } catch (NameNotFoundException e) {
1460 Log.w("PackageManager", "Failure retrieving resources for "
1461 + appInfo.packageName);
1462 } catch (Resources.NotFoundException e) {
1463 Log.w("PackageManager", "Failure retrieving resources for "
1464 + appInfo.packageName + ": " + e.getMessage());
1465 } catch (Exception e) {
1466 // If an exception was thrown, fall through to return
1467 // default icon.
1468 Log.w("PackageManager", "Failure retrieving icon 0x"
1469 + Integer.toHexString(resId) + " in package "
1470 + packageName, e);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001471 }
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001472 }
Alan Viveretteecd585a2015-04-13 10:32:51 -07001473
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001474 return null;
1475 }
1476
1477 @Override public Drawable getActivityIcon(ComponentName activityName)
1478 throws NameNotFoundException {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001479 return getActivityInfo(activityName, sDefaultFlags).loadIcon(this);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001480 }
1481
1482 @Override public Drawable getActivityIcon(Intent intent)
1483 throws NameNotFoundException {
1484 if (intent.getComponent() != null) {
1485 return getActivityIcon(intent.getComponent());
1486 }
1487
Peter Wang09014f12020-01-24 08:15:38 +08001488 ResolveInfo info = resolveActivity(intent, MATCH_DEFAULT_ONLY);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001489 if (info != null) {
1490 return info.activityInfo.loadIcon(this);
1491 }
1492
Romain Guy39fe17c2011-11-30 10:34:07 -08001493 throw new NameNotFoundException(intent.toUri(0));
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001494 }
1495
1496 @Override public Drawable getDefaultActivityIcon() {
Hyunyoung Song013f0622019-03-12 14:17:30 -07001497 return mContext.getDrawable(com.android.internal.R.drawable.sym_def_app_icon);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001498 }
1499
1500 @Override public Drawable getApplicationIcon(ApplicationInfo info) {
1501 return info.loadIcon(this);
1502 }
1503
1504 @Override public Drawable getApplicationIcon(String packageName)
1505 throws NameNotFoundException {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001506 return getApplicationIcon(getApplicationInfo(packageName, sDefaultFlags));
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001507 }
1508
1509 @Override
Jose Limaf78e3122014-03-06 12:13:15 -08001510 public Drawable getActivityBanner(ComponentName activityName)
1511 throws NameNotFoundException {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001512 return getActivityInfo(activityName, sDefaultFlags).loadBanner(this);
Jose Limaf78e3122014-03-06 12:13:15 -08001513 }
1514
1515 @Override
1516 public Drawable getActivityBanner(Intent intent)
1517 throws NameNotFoundException {
1518 if (intent.getComponent() != null) {
1519 return getActivityBanner(intent.getComponent());
1520 }
1521
1522 ResolveInfo info = resolveActivity(
Peter Wang09014f12020-01-24 08:15:38 +08001523 intent, MATCH_DEFAULT_ONLY);
Jose Limaf78e3122014-03-06 12:13:15 -08001524 if (info != null) {
1525 return info.activityInfo.loadBanner(this);
1526 }
1527
1528 throw new NameNotFoundException(intent.toUri(0));
1529 }
1530
1531 @Override
1532 public Drawable getApplicationBanner(ApplicationInfo info) {
1533 return info.loadBanner(this);
1534 }
1535
1536 @Override
1537 public Drawable getApplicationBanner(String packageName)
1538 throws NameNotFoundException {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001539 return getApplicationBanner(getApplicationInfo(packageName, sDefaultFlags));
Jose Limaf78e3122014-03-06 12:13:15 -08001540 }
1541
1542 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001543 public Drawable getActivityLogo(ComponentName activityName)
1544 throws NameNotFoundException {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001545 return getActivityInfo(activityName, sDefaultFlags).loadLogo(this);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001546 }
1547
1548 @Override
1549 public Drawable getActivityLogo(Intent intent)
1550 throws NameNotFoundException {
1551 if (intent.getComponent() != null) {
1552 return getActivityLogo(intent.getComponent());
1553 }
1554
Peter Wang09014f12020-01-24 08:15:38 +08001555 ResolveInfo info = resolveActivity(intent, MATCH_DEFAULT_ONLY);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001556 if (info != null) {
1557 return info.activityInfo.loadLogo(this);
1558 }
1559
1560 throw new NameNotFoundException(intent.toUri(0));
1561 }
1562
1563 @Override
1564 public Drawable getApplicationLogo(ApplicationInfo info) {
1565 return info.loadLogo(this);
1566 }
1567
1568 @Override
1569 public Drawable getApplicationLogo(String packageName)
1570 throws NameNotFoundException {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001571 return getApplicationLogo(getApplicationInfo(packageName, sDefaultFlags));
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001572 }
1573
Svetoslavc7d62f02014-09-04 15:39:54 -07001574 @Override
1575 public Drawable getUserBadgedIcon(Drawable icon, UserHandle user) {
Bookatz029832a2019-10-04 16:50:22 -07001576 if (!hasUserBadge(user.getIdentifier())) {
Svetoslavc7d62f02014-09-04 15:39:54 -07001577 return icon;
1578 }
Sunny Goyalbab30752017-04-12 15:36:42 -07001579 Drawable badge = new LauncherIcons(mContext).getBadgeDrawable(
Bookatz029832a2019-10-04 16:50:22 -07001580 getUserManager().getUserIconBadgeResId(user.getIdentifier()),
Beverly2b4306a2020-04-27 16:15:15 -04001581 getUserBadgeColor(user, false));
Kenny Guy02c89902016-11-15 19:36:38 +00001582 return getBadgedDrawable(icon, badge, null, true);
Svetoslavc7d62f02014-09-04 15:39:54 -07001583 }
1584
1585 @Override
1586 public Drawable getUserBadgedDrawableForDensity(Drawable drawable, UserHandle user,
1587 Rect badgeLocation, int badgeDensity) {
1588 Drawable badgeDrawable = getUserBadgeForDensity(user, badgeDensity);
1589 if (badgeDrawable == null) {
1590 return drawable;
1591 }
1592 return getBadgedDrawable(drawable, badgeDrawable, badgeLocation, true);
1593 }
1594
Beverly2b4306a2020-04-27 16:15:15 -04001595 /**
1596 * Returns the color of the user's actual badge (not the badge's shadow).
1597 * @param checkTheme whether to check the theme to determine the badge color. This should be
1598 * true if the background is determined by the theme. Otherwise, if
1599 * checkTheme is false, returns the color assuming a light background.
1600 */
1601 private int getUserBadgeColor(UserHandle user, boolean checkTheme) {
1602 if (checkTheme && mContext.getResources().getConfiguration().isNightModeActive()) {
1603 return getUserManager().getUserBadgeDarkColor(user.getIdentifier());
1604 }
Bookatz029832a2019-10-04 16:50:22 -07001605 return getUserManager().getUserBadgeColor(user.getIdentifier());
Kenny Guy02c89902016-11-15 19:36:38 +00001606 }
1607
Svetoslavc7d62f02014-09-04 15:39:54 -07001608 @Override
1609 public Drawable getUserBadgeForDensity(UserHandle user, int density) {
Bookatz029832a2019-10-04 16:50:22 -07001610 // This is part of the shadow, not the main color, and is not actually corp-specific.
1611 Drawable badgeColor = getProfileIconForDensity(user,
Kenny Guy02c89902016-11-15 19:36:38 +00001612 com.android.internal.R.drawable.ic_corp_badge_color, density);
1613 if (badgeColor == null) {
1614 return null;
1615 }
Kenny Guy02c89902016-11-15 19:36:38 +00001616 Drawable badgeForeground = getDrawableForDensity(
Bookatz029832a2019-10-04 16:50:22 -07001617 getUserManager().getUserBadgeResId(user.getIdentifier()), density);
Beverly2b4306a2020-04-27 16:15:15 -04001618 badgeForeground.setTint(getUserBadgeColor(user, false));
Tony Make21a1d02018-02-16 11:46:58 +00001619 Drawable badge = new LayerDrawable(new Drawable[] {badgeColor, badgeForeground });
Kenny Guy02c89902016-11-15 19:36:38 +00001620 return badge;
Selim Cineke6ff9462016-01-15 15:07:06 -08001621 }
1622
Beverly2b4306a2020-04-27 16:15:15 -04001623 /**
1624 * Returns the badge color based on whether device has dark theme enabled or not.
1625 */
Selim Cineke6ff9462016-01-15 15:07:06 -08001626 @Override
1627 public Drawable getUserBadgeForDensityNoBackground(UserHandle user, int density) {
Adam Bookatz9b6d51e2020-03-31 12:26:47 -07001628 if (!hasUserBadge(user.getIdentifier())) {
1629 return null;
1630 }
1631 Drawable badge = getDrawableForDensity(
Bookatz029832a2019-10-04 16:50:22 -07001632 getUserManager().getUserBadgeNoBackgroundResId(user.getIdentifier()), density);
Kenny Guy02c89902016-11-15 19:36:38 +00001633 if (badge != null) {
Beverly2b4306a2020-04-27 16:15:15 -04001634 badge.setTint(getUserBadgeColor(user, true));
Kenny Guy02c89902016-11-15 19:36:38 +00001635 }
1636 return badge;
Selim Cineke6ff9462016-01-15 15:07:06 -08001637 }
1638
Vadim Tryshev66ae66a2016-02-18 15:41:21 -08001639 private Drawable getDrawableForDensity(int drawableId, int density) {
1640 if (density <= 0) {
1641 density = mContext.getResources().getDisplayMetrics().densityDpi;
1642 }
Hyunyoung Song013f0622019-03-12 14:17:30 -07001643 return mContext.getResources().getDrawableForDensity(drawableId, density);
Vadim Tryshev66ae66a2016-02-18 15:41:21 -08001644 }
1645
Bookatz029832a2019-10-04 16:50:22 -07001646 private Drawable getProfileIconForDensity(UserHandle user, int drawableId, int density) {
1647 if (hasUserBadge(user.getIdentifier())) {
Vadim Tryshev66ae66a2016-02-18 15:41:21 -08001648 return getDrawableForDensity(drawableId, density);
Svetoslavc7d62f02014-09-04 15:39:54 -07001649 }
1650 return null;
1651 }
1652
1653 @Override
1654 public CharSequence getUserBadgedLabel(CharSequence label, UserHandle user) {
Bookatz029832a2019-10-04 16:50:22 -07001655 return getUserManager().getBadgedLabelForUser(label, user);
Svetoslavc7d62f02014-09-04 15:39:54 -07001656 }
1657
Alan Viveretteecd585a2015-04-13 10:32:51 -07001658 @Override
1659 public Resources getResourcesForActivity(ComponentName activityName)
1660 throws NameNotFoundException {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001661 return getResourcesForApplication(
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001662 getActivityInfo(activityName, sDefaultFlags).applicationInfo);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001663 }
1664
Alan Viveretteecd585a2015-04-13 10:32:51 -07001665 @Override
1666 public Resources getResourcesForApplication(@NonNull ApplicationInfo app)
1667 throws NameNotFoundException {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001668 if (app.packageName.equals("system")) {
Adam Lesinskia82b6262017-03-21 16:56:17 -07001669 return mContext.mMainThread.getSystemUiContext().getResources();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001670 }
Jeff Sharkey8a4c9722014-06-16 13:48:42 -07001671 final boolean sameUid = (app.uid == Process.myUid());
Adam Lesinski53fafdf2016-08-03 13:36:39 -07001672 final Resources r = mContext.mMainThread.getTopLevelResources(
Adam Lesinskic82f28a2016-06-08 17:19:09 -07001673 sameUid ? app.sourceDir : app.publicSourceDir,
1674 sameUid ? app.splitSourceDirs : app.splitPublicSourceDirs,
1675 app.resourceDirs, app.sharedLibraryFiles, Display.DEFAULT_DISPLAY,
Todd Kennedy233a0b12018-01-29 20:30:24 +00001676 mContext.mPackageInfo);
Adam Lesinski53fafdf2016-08-03 13:36:39 -07001677 if (r != null) {
1678 return r;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001679 }
Adam Lesinski53fafdf2016-08-03 13:36:39 -07001680 throw new NameNotFoundException("Unable to open " + app.publicSourceDir);
1681
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001682 }
1683
Alan Viveretteecd585a2015-04-13 10:32:51 -07001684 @Override
1685 public Resources getResourcesForApplication(String appPackageName)
1686 throws NameNotFoundException {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001687 return getResourcesForApplication(
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001688 getApplicationInfo(appPackageName, sDefaultFlags));
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001689 }
1690
Amith Yamasani98edc952012-09-25 14:09:27 -07001691 /** @hide */
1692 @Override
1693 public Resources getResourcesForApplicationAsUser(String appPackageName, int userId)
1694 throws NameNotFoundException {
Jeff Sharkeyded653b2012-09-27 19:09:24 -07001695 if (userId < 0) {
1696 throw new IllegalArgumentException(
1697 "Call does not support special user #" + userId);
1698 }
1699 if ("system".equals(appPackageName)) {
Adam Lesinskia82b6262017-03-21 16:56:17 -07001700 return mContext.mMainThread.getSystemUiContext().getResources();
Jeff Sharkeyded653b2012-09-27 19:09:24 -07001701 }
Amith Yamasani98edc952012-09-25 14:09:27 -07001702 try {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001703 ApplicationInfo ai = mPM.getApplicationInfo(appPackageName, sDefaultFlags, userId);
Amith Yamasani98edc952012-09-25 14:09:27 -07001704 if (ai != null) {
1705 return getResourcesForApplication(ai);
1706 }
1707 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001708 throw e.rethrowFromSystemServer();
Amith Yamasani98edc952012-09-25 14:09:27 -07001709 }
1710 throw new NameNotFoundException("Package " + appPackageName + " doesn't exist");
1711 }
1712
Jeff Sharkeycd654482016-01-08 17:42:11 -07001713 volatile int mCachedSafeMode = -1;
1714
1715 @Override
1716 public boolean isSafeMode() {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001717 try {
1718 if (mCachedSafeMode < 0) {
1719 mCachedSafeMode = mPM.isSafeMode() ? 1 : 0;
1720 }
1721 return mCachedSafeMode != 0;
1722 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001723 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001724 }
1725 }
1726
Svetoslavf7c06eb2015-06-10 18:43:22 -07001727 @Override
1728 public void addOnPermissionsChangeListener(OnPermissionsChangedListener listener) {
1729 synchronized (mPermissionListeners) {
1730 if (mPermissionListeners.get(listener) != null) {
1731 return;
1732 }
1733 OnPermissionsChangeListenerDelegate delegate =
1734 new OnPermissionsChangeListenerDelegate(listener, Looper.getMainLooper());
1735 try {
Todd Kennedy7e3dd3a2019-07-08 10:34:29 -07001736 mPermissionManager.addOnPermissionsChangeListener(delegate);
Svetoslavf7c06eb2015-06-10 18:43:22 -07001737 mPermissionListeners.put(listener, delegate);
1738 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001739 throw e.rethrowFromSystemServer();
Svetoslavf7c06eb2015-06-10 18:43:22 -07001740 }
1741 }
1742 }
1743
1744 @Override
1745 public void removeOnPermissionsChangeListener(OnPermissionsChangedListener listener) {
1746 synchronized (mPermissionListeners) {
1747 IOnPermissionsChangeListener delegate = mPermissionListeners.get(listener);
1748 if (delegate != null) {
1749 try {
Todd Kennedy7e3dd3a2019-07-08 10:34:29 -07001750 mPermissionManager.removeOnPermissionsChangeListener(delegate);
Svetoslavf7c06eb2015-06-10 18:43:22 -07001751 mPermissionListeners.remove(listener);
1752 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001753 throw e.rethrowFromSystemServer();
Svetoslavf7c06eb2015-06-10 18:43:22 -07001754 }
1755 }
1756 }
1757 }
1758
Mathew Inwood61e8ae62018-08-14 14:17:44 +01001759 @UnsupportedAppUsage
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001760 static void configurationChanged() {
1761 synchronized (sSync) {
1762 sIconCache.clear();
1763 sStringCache.clear();
1764 }
1765 }
1766
Mathew Inwood61e8ae62018-08-14 14:17:44 +01001767 @UnsupportedAppUsage
Todd Kennedyd9d985b2020-01-17 06:08:05 -08001768 protected ApplicationPackageManager(ContextImpl context, IPackageManager pm) {
1769 this(context, pm, ActivityThread.getPermissionManager());
1770 }
1771
Todd Kennedy8f135982019-07-02 07:35:15 -07001772 protected ApplicationPackageManager(ContextImpl context, IPackageManager pm,
1773 IPermissionManager permissionManager) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001774 mContext = context;
1775 mPM = pm;
Todd Kennedy8f135982019-07-02 07:35:15 -07001776 mPermissionManager = permissionManager;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001777 }
1778
Jeff Sharkeyc59a5e72018-06-21 19:14:58 -06001779 /**
1780 * Update given flags when being used to request {@link PackageInfo}.
1781 */
1782 private int updateFlagsForPackage(int flags, int userId) {
1783 if ((flags & (GET_ACTIVITIES | GET_RECEIVERS | GET_SERVICES | GET_PROVIDERS)) != 0) {
1784 // Caller is asking for component details, so they'd better be
1785 // asking for specific Direct Boot matching behavior
1786 if ((flags & (MATCH_DIRECT_BOOT_UNAWARE
1787 | MATCH_DIRECT_BOOT_AWARE
1788 | MATCH_DIRECT_BOOT_AUTO)) == 0) {
1789 onImplicitDirectBoot(userId);
1790 }
1791 }
1792 return flags;
1793 }
1794
1795 /**
1796 * Update given flags when being used to request {@link ApplicationInfo}.
1797 */
1798 private int updateFlagsForApplication(int flags, int userId) {
1799 return updateFlagsForPackage(flags, userId);
1800 }
1801
1802 /**
1803 * Update given flags when being used to request {@link ComponentInfo}.
1804 */
1805 private int updateFlagsForComponent(int flags, int userId, Intent intent) {
1806 if (intent != null) {
1807 if ((intent.getFlags() & Intent.FLAG_DIRECT_BOOT_AUTO) != 0) {
1808 flags |= MATCH_DIRECT_BOOT_AUTO;
1809 }
1810 }
1811
1812 // Caller is asking for component details, so they'd better be
1813 // asking for specific Direct Boot matching behavior
1814 if ((flags & (MATCH_DIRECT_BOOT_UNAWARE
1815 | MATCH_DIRECT_BOOT_AWARE
1816 | MATCH_DIRECT_BOOT_AUTO)) == 0) {
1817 onImplicitDirectBoot(userId);
1818 }
1819 return flags;
1820 }
1821
1822 private void onImplicitDirectBoot(int userId) {
1823 // Only report if someone is relying on implicit behavior while the user
1824 // is locked; code running when unlocked is going to see both aware and
1825 // unaware components.
1826 if (StrictMode.vmImplicitDirectBootEnabled()) {
1827 // We can cache the unlocked state for the userId we're running as,
1828 // since any relocking of that user will always result in our
1829 // process being killed to release any CE FDs we're holding onto.
1830 if (userId == UserHandle.myUserId()) {
1831 if (mUserUnlocked) {
1832 return;
1833 } else if (mContext.getSystemService(UserManager.class)
1834 .isUserUnlockingOrUnlocked(userId)) {
1835 mUserUnlocked = true;
1836 } else {
1837 StrictMode.onImplicitDirectBoot();
1838 }
1839 } else if (!mContext.getSystemService(UserManager.class)
1840 .isUserUnlockingOrUnlocked(userId)) {
1841 StrictMode.onImplicitDirectBoot();
1842 }
1843 }
1844 }
1845
Alan Viveretteecd585a2015-04-13 10:32:51 -07001846 @Nullable
1847 private Drawable getCachedIcon(@NonNull ResourceName name) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001848 synchronized (sSync) {
Alan Viveretteecd585a2015-04-13 10:32:51 -07001849 final WeakReference<Drawable.ConstantState> wr = sIconCache.get(name);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001850 if (DEBUG_ICONS) Log.v(TAG, "Get cached weak drawable ref for "
1851 + name + ": " + wr);
1852 if (wr != null) { // we have the activity
Alan Viveretteecd585a2015-04-13 10:32:51 -07001853 final Drawable.ConstantState state = wr.get();
Romain Guy39fe17c2011-11-30 10:34:07 -08001854 if (state != null) {
1855 if (DEBUG_ICONS) {
1856 Log.v(TAG, "Get cached drawable state for " + name + ": " + state);
1857 }
1858 // Note: It's okay here to not use the newDrawable(Resources) variant
1859 // of the API. The ConstantState comes from a drawable that was
1860 // originally created by passing the proper app Resources instance
1861 // which means the state should already contain the proper
1862 // resources specific information (like density.) See
1863 // BitmapDrawable.BitmapState for instance.
1864 return state.newDrawable();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001865 }
1866 // our entry has been purged
1867 sIconCache.remove(name);
1868 }
1869 }
1870 return null;
1871 }
1872
Alan Viveretteecd585a2015-04-13 10:32:51 -07001873 private void putCachedIcon(@NonNull ResourceName name, @NonNull Drawable dr) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001874 synchronized (sSync) {
Alan Viveretteecd585a2015-04-13 10:32:51 -07001875 sIconCache.put(name, new WeakReference<>(dr.getConstantState()));
Romain Guy39fe17c2011-11-30 10:34:07 -08001876 if (DEBUG_ICONS) Log.v(TAG, "Added cached drawable state for " + name + ": " + dr);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001877 }
1878 }
1879
Romain Guy39fe17c2011-11-30 10:34:07 -08001880 static void handlePackageBroadcast(int cmd, String[] pkgList, boolean hasPkgInfo) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001881 boolean immediateGc = false;
Sudheer Shankacc6418f2016-10-13 12:03:44 -07001882 if (cmd == ApplicationThreadConstants.EXTERNAL_STORAGE_UNAVAILABLE) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001883 immediateGc = true;
1884 }
1885 if (pkgList != null && (pkgList.length > 0)) {
1886 boolean needCleanup = false;
1887 for (String ssp : pkgList) {
1888 synchronized (sSync) {
Dianne Hackbornadd005c2013-07-17 18:43:12 -07001889 for (int i=sIconCache.size()-1; i>=0; i--) {
1890 ResourceName nm = sIconCache.keyAt(i);
1891 if (nm.packageName.equals(ssp)) {
1892 //Log.i(TAG, "Removing cached drawable for " + nm);
1893 sIconCache.removeAt(i);
1894 needCleanup = true;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001895 }
1896 }
Dianne Hackbornadd005c2013-07-17 18:43:12 -07001897 for (int i=sStringCache.size()-1; i>=0; i--) {
1898 ResourceName nm = sStringCache.keyAt(i);
1899 if (nm.packageName.equals(ssp)) {
1900 //Log.i(TAG, "Removing cached string for " + nm);
1901 sStringCache.removeAt(i);
1902 needCleanup = true;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001903 }
1904 }
1905 }
1906 }
1907 if (needCleanup || hasPkgInfo) {
1908 if (immediateGc) {
1909 // Schedule an immediate gc.
1910 Runtime.getRuntime().gc();
1911 } else {
1912 ActivityThread.currentActivityThread().scheduleGcIdler();
1913 }
1914 }
1915 }
1916 }
1917
1918 private static final class ResourceName {
1919 final String packageName;
1920 final int iconId;
1921
1922 ResourceName(String _packageName, int _iconId) {
1923 packageName = _packageName;
1924 iconId = _iconId;
1925 }
1926
1927 ResourceName(ApplicationInfo aInfo, int _iconId) {
1928 this(aInfo.packageName, _iconId);
1929 }
1930
1931 ResourceName(ComponentInfo cInfo, int _iconId) {
1932 this(cInfo.applicationInfo.packageName, _iconId);
1933 }
1934
1935 ResourceName(ResolveInfo rInfo, int _iconId) {
1936 this(rInfo.activityInfo.applicationInfo.packageName, _iconId);
1937 }
1938
1939 @Override
1940 public boolean equals(Object o) {
1941 if (this == o) return true;
1942 if (o == null || getClass() != o.getClass()) return false;
1943
1944 ResourceName that = (ResourceName) o;
1945
1946 if (iconId != that.iconId) return false;
1947 return !(packageName != null ?
1948 !packageName.equals(that.packageName) : that.packageName != null);
1949
1950 }
1951
1952 @Override
1953 public int hashCode() {
1954 int result;
1955 result = packageName.hashCode();
1956 result = 31 * result + iconId;
1957 return result;
1958 }
1959
1960 @Override
1961 public String toString() {
1962 return "{ResourceName " + packageName + " / " + iconId + "}";
1963 }
1964 }
1965
1966 private CharSequence getCachedString(ResourceName name) {
1967 synchronized (sSync) {
1968 WeakReference<CharSequence> wr = sStringCache.get(name);
1969 if (wr != null) { // we have the activity
1970 CharSequence cs = wr.get();
1971 if (cs != null) {
1972 return cs;
1973 }
1974 // our entry has been purged
1975 sStringCache.remove(name);
1976 }
1977 }
1978 return null;
1979 }
1980
1981 private void putCachedString(ResourceName name, CharSequence cs) {
1982 synchronized (sSync) {
1983 sStringCache.put(name, new WeakReference<CharSequence>(cs));
1984 }
1985 }
1986
1987 @Override
Tor Norbye7b9c9122013-05-30 16:48:33 -07001988 public CharSequence getText(String packageName, @StringRes int resid,
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001989 ApplicationInfo appInfo) {
1990 ResourceName name = new ResourceName(packageName, resid);
1991 CharSequence text = getCachedString(name);
1992 if (text != null) {
1993 return text;
1994 }
1995 if (appInfo == null) {
1996 try {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001997 appInfo = getApplicationInfo(packageName, sDefaultFlags);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001998 } catch (NameNotFoundException e) {
1999 return null;
2000 }
2001 }
2002 try {
2003 Resources r = getResourcesForApplication(appInfo);
2004 text = r.getText(resid);
2005 putCachedString(name, text);
2006 return text;
2007 } catch (NameNotFoundException e) {
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07002008 Log.w("PackageManager", "Failure retrieving resources for "
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002009 + appInfo.packageName);
2010 } catch (RuntimeException e) {
2011 // If an exception was thrown, fall through to return
2012 // default icon.
2013 Log.w("PackageManager", "Failure retrieving text 0x"
2014 + Integer.toHexString(resid) + " in package "
2015 + packageName, e);
2016 }
2017 return null;
2018 }
2019
2020 @Override
Tor Norbye7b9c9122013-05-30 16:48:33 -07002021 public XmlResourceParser getXml(String packageName, @XmlRes int resid,
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002022 ApplicationInfo appInfo) {
2023 if (appInfo == null) {
2024 try {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07002025 appInfo = getApplicationInfo(packageName, sDefaultFlags);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002026 } catch (NameNotFoundException e) {
2027 return null;
2028 }
2029 }
2030 try {
2031 Resources r = getResourcesForApplication(appInfo);
2032 return r.getXml(resid);
2033 } catch (RuntimeException e) {
2034 // If an exception was thrown, fall through to return
2035 // default icon.
2036 Log.w("PackageManager", "Failure retrieving xml 0x"
2037 + Integer.toHexString(resid) + " in package "
2038 + packageName, e);
2039 } catch (NameNotFoundException e) {
Alon Albert3fa51e32010-11-11 09:24:04 -08002040 Log.w("PackageManager", "Failure retrieving resources for "
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002041 + appInfo.packageName);
2042 }
2043 return null;
2044 }
2045
2046 @Override
2047 public CharSequence getApplicationLabel(ApplicationInfo info) {
2048 return info.loadLabel(this);
2049 }
2050
2051 @Override
Nicolas Prevot9a80e532015-09-23 15:49:28 +01002052 public int installExistingPackage(String packageName) throws NameNotFoundException {
Peter Wang09014f12020-01-24 08:15:38 +08002053 return installExistingPackage(packageName, INSTALL_REASON_UNKNOWN);
Sunny Goyala31a74b2017-05-11 15:59:19 -07002054 }
2055
2056 @Override
2057 public int installExistingPackage(String packageName, int installReason)
2058 throws NameNotFoundException {
Jeff Sharkeyc59a5e72018-06-21 19:14:58 -06002059 return installExistingPackageAsUser(packageName, installReason, getUserId());
Nicolas Prevot9a80e532015-09-23 15:49:28 +01002060 }
2061
2062 @Override
2063 public int installExistingPackageAsUser(String packageName, int userId)
Dianne Hackborn7767eac2012-08-23 18:25:40 -07002064 throws NameNotFoundException {
Peter Wang09014f12020-01-24 08:15:38 +08002065 return installExistingPackageAsUser(packageName, INSTALL_REASON_UNKNOWN,
Sunny Goyala31a74b2017-05-11 15:59:19 -07002066 userId);
2067 }
2068
2069 private int installExistingPackageAsUser(String packageName, int installReason, int userId)
2070 throws NameNotFoundException {
Dianne Hackborn7767eac2012-08-23 18:25:40 -07002071 try {
Philip P. Moltmannbfcffa02019-05-13 17:10:46 -07002072 int res = mPM.installExistingPackageAsUser(packageName, userId,
2073 INSTALL_ALL_WHITELIST_RESTRICTED_PERMISSIONS, installReason, null);
Dianne Hackborn7767eac2012-08-23 18:25:40 -07002074 if (res == INSTALL_FAILED_INVALID_URI) {
2075 throw new NameNotFoundException("Package " + packageName + " doesn't exist");
2076 }
2077 return res;
2078 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002079 throw e.rethrowFromSystemServer();
Dianne Hackborn7767eac2012-08-23 18:25:40 -07002080 }
2081 }
2082
2083 @Override
Kenny Root3a9b5fb2011-09-20 14:15:38 -07002084 public void verifyPendingInstall(int id, int response) {
Kenny Root5ab21572011-07-27 11:11:19 -07002085 try {
Kenny Root3a9b5fb2011-09-20 14:15:38 -07002086 mPM.verifyPendingInstall(id, response);
Kenny Root5ab21572011-07-27 11:11:19 -07002087 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002088 throw e.rethrowFromSystemServer();
Kenny Root5ab21572011-07-27 11:11:19 -07002089 }
2090 }
2091
2092 @Override
rich canningsd9ef3e52012-08-22 14:28:05 -07002093 public void extendVerificationTimeout(int id, int verificationCodeAtTimeout,
2094 long millisecondsToDelay) {
2095 try {
2096 mPM.extendVerificationTimeout(id, verificationCodeAtTimeout, millisecondsToDelay);
2097 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002098 throw e.rethrowFromSystemServer();
rich canningsd9ef3e52012-08-22 14:28:05 -07002099 }
2100 }
2101
2102 @Override
Todd Kennedydfa93ab2016-03-03 15:24:33 -08002103 public void verifyIntentFilter(int id, int verificationCode, List<String> failedDomains) {
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08002104 try {
Todd Kennedydfa93ab2016-03-03 15:24:33 -08002105 mPM.verifyIntentFilter(id, verificationCode, failedDomains);
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08002106 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002107 throw e.rethrowFromSystemServer();
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08002108 }
2109 }
2110
2111 @Override
Jeff Sharkeye06b4d12016-01-06 14:51:50 -07002112 public int getIntentVerificationStatusAsUser(String packageName, int userId) {
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08002113 try {
2114 return mPM.getIntentVerificationStatus(packageName, userId);
2115 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002116 throw e.rethrowFromSystemServer();
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08002117 }
2118 }
2119
2120 @Override
Jeff Sharkeye06b4d12016-01-06 14:51:50 -07002121 public boolean updateIntentVerificationStatusAsUser(String packageName, int status, int userId) {
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08002122 try {
2123 return mPM.updateIntentVerificationStatus(packageName, status, userId);
2124 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002125 throw e.rethrowFromSystemServer();
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08002126 }
2127 }
2128
2129 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07002130 @SuppressWarnings("unchecked")
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08002131 public List<IntentFilterVerificationInfo> getIntentFilterVerifications(String packageName) {
2132 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07002133 ParceledListSlice<IntentFilterVerificationInfo> parceledList =
2134 mPM.getIntentFilterVerifications(packageName);
2135 if (parceledList == null) {
2136 return Collections.emptyList();
2137 }
2138 return parceledList.getList();
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08002139 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002140 throw e.rethrowFromSystemServer();
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08002141 }
2142 }
2143
2144 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07002145 @SuppressWarnings("unchecked")
Fabrice Di Meglio07885952015-04-06 19:41:28 -07002146 public List<IntentFilter> getAllIntentFilters(String packageName) {
2147 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07002148 ParceledListSlice<IntentFilter> parceledList =
2149 mPM.getAllIntentFilters(packageName);
2150 if (parceledList == null) {
2151 return Collections.emptyList();
2152 }
2153 return parceledList.getList();
Fabrice Di Meglio07885952015-04-06 19:41:28 -07002154 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002155 throw e.rethrowFromSystemServer();
Fabrice Di Meglio07885952015-04-06 19:41:28 -07002156 }
2157 }
2158
2159 @Override
Jeff Sharkeye06b4d12016-01-06 14:51:50 -07002160 public String getDefaultBrowserPackageNameAsUser(int userId) {
Fabrice Di Meglio62271722015-04-10 17:24:02 -07002161 try {
Todd Kennedy583378d2019-07-12 06:50:30 -07002162 return mPermissionManager.getDefaultBrowser(userId);
Fabrice Di Meglio62271722015-04-10 17:24:02 -07002163 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002164 throw e.rethrowFromSystemServer();
Fabrice Di Meglio62271722015-04-10 17:24:02 -07002165 }
2166 }
2167
2168 @Override
Jeff Sharkeye06b4d12016-01-06 14:51:50 -07002169 public boolean setDefaultBrowserPackageNameAsUser(String packageName, int userId) {
Fabrice Di Meglio62271722015-04-10 17:24:02 -07002170 try {
Todd Kennedy583378d2019-07-12 06:50:30 -07002171 return mPermissionManager.setDefaultBrowser(packageName, userId);
Fabrice Di Meglio62271722015-04-10 17:24:02 -07002172 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002173 throw e.rethrowFromSystemServer();
Fabrice Di Meglio62271722015-04-10 17:24:02 -07002174 }
2175 }
2176
2177 @Override
Dianne Hackborn880119b2010-11-18 22:26:40 -08002178 public void setInstallerPackageName(String targetPackage,
2179 String installerPackageName) {
2180 try {
2181 mPM.setInstallerPackageName(targetPackage, installerPackageName);
2182 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002183 throw e.rethrowFromSystemServer();
Dianne Hackborn880119b2010-11-18 22:26:40 -08002184 }
2185 }
2186
2187 @Override
Todd Kennedyab532892017-03-08 14:19:49 -08002188 public void setUpdateAvailable(String packageName, boolean updateAvailable) {
2189 try {
2190 mPM.setUpdateAvailable(packageName, updateAvailable);
2191 } catch (RemoteException e) {
2192 throw e.rethrowFromSystemServer();
2193 }
2194 }
2195
2196 @Override
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002197 public String getInstallerPackageName(String packageName) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002198 try {
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002199 return mPM.getInstallerPackageName(packageName);
2200 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002201 throw e.rethrowFromSystemServer();
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002202 }
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002203 }
2204
2205 @Override
Alan Stokescae316d2019-11-26 09:39:02 +00002206 @NonNull
2207 public InstallSourceInfo getInstallSourceInfo(String packageName) throws NameNotFoundException {
2208 final InstallSourceInfo installSourceInfo;
2209 try {
2210 installSourceInfo = mPM.getInstallSourceInfo(packageName);
2211 } catch (RemoteException e) {
2212 throw e.rethrowFromSystemServer();
2213 }
2214 if (installSourceInfo == null) {
2215 throw new NameNotFoundException(packageName);
2216 }
2217 return installSourceInfo;
2218 }
2219
2220 @Override
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002221 public int getMoveStatus(int moveId) {
2222 try {
2223 return mPM.getMoveStatus(moveId);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002224 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002225 throw e.rethrowFromSystemServer();
Jeff Sharkeyb2b9ab82015-04-05 21:10:42 -07002226 }
2227 }
2228
2229 @Override
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002230 public void registerMoveCallback(MoveCallback callback, Handler handler) {
2231 synchronized (mDelegates) {
2232 final MoveCallbackDelegate delegate = new MoveCallbackDelegate(callback,
2233 handler.getLooper());
2234 try {
2235 mPM.registerMoveCallback(delegate);
2236 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002237 throw e.rethrowFromSystemServer();
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002238 }
2239 mDelegates.add(delegate);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002240 }
2241 }
2242
2243 @Override
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002244 public void unregisterMoveCallback(MoveCallback callback) {
2245 synchronized (mDelegates) {
2246 for (Iterator<MoveCallbackDelegate> i = mDelegates.iterator(); i.hasNext();) {
2247 final MoveCallbackDelegate delegate = i.next();
2248 if (delegate.mCallback == callback) {
2249 try {
2250 mPM.unregisterMoveCallback(delegate);
2251 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002252 throw e.rethrowFromSystemServer();
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002253 }
2254 i.remove();
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07002255 }
2256 }
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07002257 }
2258 }
2259
2260 @Override
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002261 public int movePackage(String packageName, VolumeInfo vol) {
2262 try {
2263 final String volumeUuid;
2264 if (VolumeInfo.ID_PRIVATE_INTERNAL.equals(vol.id)) {
2265 volumeUuid = StorageManager.UUID_PRIVATE_INTERNAL;
2266 } else if (vol.isPrimaryPhysical()) {
2267 volumeUuid = StorageManager.UUID_PRIMARY_PHYSICAL;
2268 } else {
Daulet Zhanguzin0af97d62019-12-30 15:41:28 +00002269 volumeUuid = Objects.requireNonNull(vol.fsUuid);
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002270 }
2271
2272 return mPM.movePackage(packageName, volumeUuid);
2273 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002274 throw e.rethrowFromSystemServer();
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002275 }
2276 }
2277
2278 @Override
Mathew Inwood61e8ae62018-08-14 14:17:44 +01002279 @UnsupportedAppUsage
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002280 public @Nullable VolumeInfo getPackageCurrentVolume(ApplicationInfo app) {
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07002281 final StorageManager storage = mContext.getSystemService(StorageManager.class);
Yao Chen022b8ea2016-12-16 11:03:28 -08002282 return getPackageCurrentVolume(app, storage);
2283 }
2284
2285 @VisibleForTesting
2286 protected @Nullable VolumeInfo getPackageCurrentVolume(ApplicationInfo app,
2287 StorageManager storage) {
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002288 if (app.isInternal()) {
2289 return storage.findVolumeById(VolumeInfo.ID_PRIVATE_INTERNAL);
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002290 } else {
2291 return storage.findVolumeByUuid(app.volumeUuid);
2292 }
2293 }
2294
2295 @Override
2296 public @NonNull List<VolumeInfo> getPackageCandidateVolumes(ApplicationInfo app) {
Yao Chen022b8ea2016-12-16 11:03:28 -08002297 final StorageManager storageManager = mContext.getSystemService(StorageManager.class);
2298 return getPackageCandidateVolumes(app, storageManager, mPM);
2299 }
2300
2301 @VisibleForTesting
2302 protected @NonNull List<VolumeInfo> getPackageCandidateVolumes(ApplicationInfo app,
2303 StorageManager storageManager, IPackageManager pm) {
2304 final VolumeInfo currentVol = getPackageCurrentVolume(app, storageManager);
2305 final List<VolumeInfo> vols = storageManager.getVolumes();
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07002306 final List<VolumeInfo> candidates = new ArrayList<>();
2307 for (VolumeInfo vol : vols) {
Yao Chen022b8ea2016-12-16 11:03:28 -08002308 if (Objects.equals(vol, currentVol)
2309 || isPackageCandidateVolume(mContext, app, vol, pm)) {
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07002310 candidates.add(vol);
2311 }
2312 }
2313 return candidates;
2314 }
2315
Yao Chen022b8ea2016-12-16 11:03:28 -08002316 @VisibleForTesting
2317 protected boolean isForceAllowOnExternal(Context context) {
2318 return Settings.Global.getInt(
Todd Kennedyf39ca8f2015-08-07 14:15:07 -07002319 context.getContentResolver(), Settings.Global.FORCE_ALLOW_ON_EXTERNAL, 0) != 0;
Yao Chen022b8ea2016-12-16 11:03:28 -08002320 }
2321
2322 @VisibleForTesting
2323 protected boolean isAllow3rdPartyOnInternal(Context context) {
2324 return context.getResources().getBoolean(
2325 com.android.internal.R.bool.config_allow3rdPartyAppOnInternal);
2326 }
2327
2328 private boolean isPackageCandidateVolume(
2329 ContextImpl context, ApplicationInfo app, VolumeInfo vol, IPackageManager pm) {
2330 final boolean forceAllowOnExternal = isForceAllowOnExternal(context);
2331
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07002332 if (VolumeInfo.ID_PRIVATE_INTERNAL.equals(vol.getId())) {
Yao Chen022b8ea2016-12-16 11:03:28 -08002333 return app.isSystemApp() || isAllow3rdPartyOnInternal(context);
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07002334 }
2335
2336 // System apps and apps demanding internal storage can't be moved
2337 // anywhere else
Todd Kennedyf39ca8f2015-08-07 14:15:07 -07002338 if (app.isSystemApp()) {
2339 return false;
2340 }
2341 if (!forceAllowOnExternal
Dianne Hackborn30a4e6d2015-10-12 17:14:56 -07002342 && (app.installLocation == PackageInfo.INSTALL_LOCATION_INTERNAL_ONLY
2343 || app.installLocation == PackageInfo.INSTALL_LOCATION_UNSPECIFIED)) {
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07002344 return false;
2345 }
2346
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002347 // Gotta be able to write there
2348 if (!vol.isMountedWritable()) {
2349 return false;
2350 }
2351
2352 // Moving into an ASEC on public primary is only option internal
2353 if (vol.isPrimaryPhysical()) {
2354 return app.isInternal();
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07002355 }
2356
Makoto Onukif34db0a2016-02-17 11:17:15 -08002357 // Some apps can't be moved. (e.g. device admins)
2358 try {
Yao Chen022b8ea2016-12-16 11:03:28 -08002359 if (pm.isPackageDeviceAdminOnAnyUser(app.packageName)) {
Makoto Onukif34db0a2016-02-17 11:17:15 -08002360 return false;
2361 }
2362 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002363 throw e.rethrowFromSystemServer();
Makoto Onukif34db0a2016-02-17 11:17:15 -08002364 }
2365
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07002366 // Otherwise we can move to any private volume
2367 return (vol.getType() == VolumeInfo.TYPE_PRIVATE);
2368 }
2369
2370 @Override
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002371 public int movePrimaryStorage(VolumeInfo vol) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002372 try {
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002373 final String volumeUuid;
2374 if (VolumeInfo.ID_PRIVATE_INTERNAL.equals(vol.id)) {
2375 volumeUuid = StorageManager.UUID_PRIVATE_INTERNAL;
2376 } else if (vol.isPrimaryPhysical()) {
2377 volumeUuid = StorageManager.UUID_PRIMARY_PHYSICAL;
2378 } else {
Daulet Zhanguzin0af97d62019-12-30 15:41:28 +00002379 volumeUuid = Objects.requireNonNull(vol.fsUuid);
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002380 }
2381
2382 return mPM.movePrimaryStorage(volumeUuid);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002383 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002384 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002385 }
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002386 }
2387
Jeff Sharkey275e3e42015-04-24 16:10:32 -07002388 @Override
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002389 public @Nullable VolumeInfo getPrimaryStorageCurrentVolume() {
2390 final StorageManager storage = mContext.getSystemService(StorageManager.class);
2391 final String volumeUuid = storage.getPrimaryStorageUuid();
Jeff Sharkey50a05452015-04-29 11:24:52 -07002392 return storage.findVolumeByQualifiedUuid(volumeUuid);
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002393 }
2394
Jeff Sharkey275e3e42015-04-24 16:10:32 -07002395 @Override
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002396 public @NonNull List<VolumeInfo> getPrimaryStorageCandidateVolumes() {
2397 final StorageManager storage = mContext.getSystemService(StorageManager.class);
2398 final VolumeInfo currentVol = getPrimaryStorageCurrentVolume();
2399 final List<VolumeInfo> vols = storage.getVolumes();
2400 final List<VolumeInfo> candidates = new ArrayList<>();
Jeff Sharkeyfced5342015-05-10 14:53:34 -07002401 if (Objects.equals(StorageManager.UUID_PRIMARY_PHYSICAL,
2402 storage.getPrimaryStorageUuid()) && currentVol != null) {
2403 // TODO: support moving primary physical to emulated volume
2404 candidates.add(currentVol);
2405 } else {
2406 for (VolumeInfo vol : vols) {
2407 if (Objects.equals(vol, currentVol) || isPrimaryStorageCandidateVolume(vol)) {
2408 candidates.add(vol);
2409 }
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002410 }
2411 }
2412 return candidates;
2413 }
2414
2415 private static boolean isPrimaryStorageCandidateVolume(VolumeInfo vol) {
2416 // Private internal is always an option
2417 if (VolumeInfo.ID_PRIVATE_INTERNAL.equals(vol.getId())) {
2418 return true;
2419 }
2420
2421 // Gotta be able to write there
2422 if (!vol.isMountedWritable()) {
2423 return false;
2424 }
2425
Jeff Sharkeyfced5342015-05-10 14:53:34 -07002426 // We can move to any private volume
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002427 return (vol.getType() == VolumeInfo.TYPE_PRIVATE);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002428 }
2429
2430 @Override
Mathew Inwood61e8ae62018-08-14 14:17:44 +01002431 @UnsupportedAppUsage
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002432 public void deletePackage(String packageName, IPackageDeleteObserver observer, int flags) {
Jeff Sharkeyc59a5e72018-06-21 19:14:58 -06002433 deletePackageAsUser(packageName, observer, flags, getUserId());
Nicolas Prevot9a80e532015-09-23 15:49:28 +01002434 }
2435
2436 @Override
Svet Ganov67882122016-12-11 16:36:34 -08002437 public void deletePackageAsUser(String packageName, IPackageDeleteObserver observer,
2438 int flags, int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002439 try {
Peter Wang09014f12020-01-24 08:15:38 +08002440 mPM.deletePackageAsUser(packageName, VERSION_CODE_HIGHEST,
Svet Ganov67882122016-12-11 16:36:34 -08002441 observer, userId, flags);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002442 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002443 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002444 }
2445 }
Jeff Sharkeyfbd0e9f2014-08-06 16:34:34 -07002446
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002447 @Override
2448 public void clearApplicationUserData(String packageName,
2449 IPackageDataObserver observer) {
2450 try {
Jeff Sharkeyc59a5e72018-06-21 19:14:58 -06002451 mPM.clearApplicationUserData(packageName, observer, getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002452 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002453 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002454 }
2455 }
2456 @Override
2457 public void deleteApplicationCacheFiles(String packageName,
2458 IPackageDataObserver observer) {
2459 try {
2460 mPM.deleteApplicationCacheFiles(packageName, observer);
2461 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002462 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002463 }
2464 }
Jeff Sharkey529f91f2015-04-18 20:23:13 -07002465
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002466 @Override
Suprabh Shukla78c9eb82016-04-12 15:51:35 -07002467 public void deleteApplicationCacheFilesAsUser(String packageName, int userId,
2468 IPackageDataObserver observer) {
2469 try {
2470 mPM.deleteApplicationCacheFilesAsUser(packageName, userId, observer);
2471 } catch (RemoteException e) {
2472 throw e.rethrowFromSystemServer();
2473 }
2474 }
2475
2476 @Override
Jeff Sharkey529f91f2015-04-18 20:23:13 -07002477 public void freeStorageAndNotify(String volumeUuid, long idealStorageSize,
2478 IPackageDataObserver observer) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002479 try {
Jeff Sharkeyddff8072017-05-26 13:10:46 -06002480 mPM.freeStorageAndNotify(volumeUuid, idealStorageSize, 0, observer);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002481 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002482 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002483 }
2484 }
2485
2486 @Override
Jeff Sharkey529f91f2015-04-18 20:23:13 -07002487 public void freeStorage(String volumeUuid, long freeStorageSize, IntentSender pi) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002488 try {
Jeff Sharkeyddff8072017-05-26 13:10:46 -06002489 mPM.freeStorage(volumeUuid, freeStorageSize, 0, pi);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002490 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002491 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002492 }
2493 }
2494
2495 @Override
Suprabh Shukla79000492018-12-24 17:03:02 -08002496 public String[] setDistractingPackageRestrictions(String[] packages, int distractionFlags) {
2497 try {
2498 return mPM.setDistractingPackageRestrictionsAsUser(packages, distractionFlags,
2499 mContext.getUserId());
2500 } catch (RemoteException e) {
2501 throw e.rethrowFromSystemServer();
2502 }
2503 }
2504
2505 @Override
Suprabh Shukla021b57a2018-03-08 18:21:50 -08002506 public String[] setPackagesSuspended(String[] packageNames, boolean suspended,
2507 PersistableBundle appExtras, PersistableBundle launcherExtras,
2508 String dialogMessage) {
Suprabh Shukla389cb6f2018-10-01 18:20:39 -07002509 final SuspendDialogInfo dialogInfo = !TextUtils.isEmpty(dialogMessage)
2510 ? new SuspendDialogInfo.Builder().setMessage(dialogMessage).build()
2511 : null;
2512 return setPackagesSuspended(packageNames, suspended, appExtras, launcherExtras, dialogInfo);
2513 }
2514
2515 @Override
2516 public String[] setPackagesSuspended(String[] packageNames, boolean suspended,
2517 PersistableBundle appExtras, PersistableBundle launcherExtras,
2518 SuspendDialogInfo dialogInfo) {
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00002519 try {
Suprabh Shukla021b57a2018-03-08 18:21:50 -08002520 return mPM.setPackagesSuspendedAsUser(packageNames, suspended, appExtras,
Suprabh Shukla389cb6f2018-10-01 18:20:39 -07002521 launcherExtras, dialogInfo, mContext.getOpPackageName(),
Jeff Sharkeyc59a5e72018-06-21 19:14:58 -06002522 getUserId());
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00002523 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002524 throw e.rethrowFromSystemServer();
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00002525 }
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00002526 }
2527
2528 @Override
Suprabh Shukla436d093ba2018-12-12 16:01:41 +00002529 public String[] getUnsuspendablePackages(String[] packageNames) {
Suprabh Shukla1f1de702018-11-09 22:49:23 -08002530 try {
Suprabh Shukla436d093ba2018-12-12 16:01:41 +00002531 return mPM.getUnsuspendablePackagesForUser(packageNames, mContext.getUserId());
Suprabh Shukla1f1de702018-11-09 22:49:23 -08002532 } catch (RemoteException e) {
2533 throw e.rethrowFromSystemServer();
2534 }
2535 }
2536
2537 @Override
Suprabh Shukla45b9e402018-04-09 17:33:53 -07002538 public Bundle getSuspendedPackageAppExtras() {
Suprabh Shukla021b57a2018-03-08 18:21:50 -08002539 try {
Suprabh Shuklad3278442019-08-27 15:58:03 -07002540 return mPM.getSuspendedPackageAppExtras(mContext.getOpPackageName(), getUserId());
Suprabh Shukla021b57a2018-03-08 18:21:50 -08002541 } catch (RemoteException e) {
2542 throw e.rethrowFromSystemServer();
2543 }
Suprabh Shukla021b57a2018-03-08 18:21:50 -08002544 }
2545
2546 @Override
Andrei Stingaceanu355b2322016-02-12 16:43:51 +00002547 public boolean isPackageSuspendedForUser(String packageName, int userId) {
2548 try {
2549 return mPM.isPackageSuspendedForUser(packageName, userId);
2550 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002551 throw e.rethrowFromSystemServer();
Andrei Stingaceanu355b2322016-02-12 16:43:51 +00002552 }
Andrei Stingaceanu355b2322016-02-12 16:43:51 +00002553 }
2554
Jeff Sharkey9bc89af2017-01-11 11:25:50 -07002555 /** @hide */
2556 @Override
Suprabh Shukla96212bc2018-04-10 15:04:51 -07002557 public boolean isPackageSuspended(String packageName) throws NameNotFoundException {
2558 try {
Jeff Sharkeyc59a5e72018-06-21 19:14:58 -06002559 return isPackageSuspendedForUser(packageName, getUserId());
Suprabh Shukla96212bc2018-04-10 15:04:51 -07002560 } catch (IllegalArgumentException ie) {
2561 throw new NameNotFoundException(packageName);
2562 }
Suprabh Shukla021b57a2018-03-08 18:21:50 -08002563 }
2564
2565 @Override
2566 public boolean isPackageSuspended() {
Jeff Sharkeyc59a5e72018-06-21 19:14:58 -06002567 return isPackageSuspendedForUser(mContext.getOpPackageName(), getUserId());
Suprabh Shukla021b57a2018-03-08 18:21:50 -08002568 }
2569
2570 /** @hide */
2571 @Override
Jeff Sharkey9bc89af2017-01-11 11:25:50 -07002572 public void setApplicationCategoryHint(String packageName, int categoryHint) {
2573 try {
2574 mPM.setApplicationCategoryHint(packageName, categoryHint,
2575 mContext.getOpPackageName());
2576 } catch (RemoteException e) {
2577 throw e.rethrowFromSystemServer();
2578 }
2579 }
2580
Andrei Stingaceanu355b2322016-02-12 16:43:51 +00002581 @Override
Mathew Inwood61e8ae62018-08-14 14:17:44 +01002582 @UnsupportedAppUsage
Jeff Sharkeye06b4d12016-01-06 14:51:50 -07002583 public void getPackageSizeInfoAsUser(String packageName, int userHandle,
Dianne Hackborn0c380492012-08-20 17:23:30 -07002584 IPackageStatsObserver observer) {
Jeff Sharkey6f4b2a32017-03-21 14:13:41 -06002585 final String msg = "Shame on you for calling the hidden API "
2586 + "getPackageSizeInfoAsUser(). Shame!";
Jeff Sharkeye6306c42017-03-07 21:03:18 -07002587 if (mContext.getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.O) {
Jeff Sharkey6f4b2a32017-03-21 14:13:41 -06002588 throw new UnsupportedOperationException(msg);
Jeff Sharkeye6306c42017-03-07 21:03:18 -07002589 } else if (observer != null) {
Jeff Sharkey6f4b2a32017-03-21 14:13:41 -06002590 Log.d(TAG, msg);
Jeff Sharkeye6306c42017-03-07 21:03:18 -07002591 try {
2592 observer.onGetStatsCompleted(null, false);
2593 } catch (RemoteException ignored) {
2594 }
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002595 }
2596 }
Jeff Sharkeyd5896632016-03-04 16:16:00 -07002597
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002598 @Override
2599 public void addPackageToPreferred(String packageName) {
Jeff Sharkeyd5896632016-03-04 16:16:00 -07002600 Log.w(TAG, "addPackageToPreferred() is a no-op");
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002601 }
2602
2603 @Override
2604 public void removePackageFromPreferred(String packageName) {
Jeff Sharkeyd5896632016-03-04 16:16:00 -07002605 Log.w(TAG, "removePackageFromPreferred() is a no-op");
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002606 }
2607
2608 @Override
2609 public List<PackageInfo> getPreferredPackages(int flags) {
Jeff Sharkeyd5896632016-03-04 16:16:00 -07002610 Log.w(TAG, "getPreferredPackages() is a no-op");
2611 return Collections.emptyList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002612 }
2613
2614 @Override
2615 public void addPreferredActivity(IntentFilter filter,
2616 int match, ComponentName[] set, ComponentName activity) {
2617 try {
Jeff Sharkeyc59a5e72018-06-21 19:14:58 -06002618 mPM.addPreferredActivity(filter, match, set, activity, getUserId());
Amith Yamasania3f133a2012-08-09 17:11:28 -07002619 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002620 throw e.rethrowFromSystemServer();
Amith Yamasania3f133a2012-08-09 17:11:28 -07002621 }
2622 }
2623
2624 @Override
Jeff Sharkeye06b4d12016-01-06 14:51:50 -07002625 public void addPreferredActivityAsUser(IntentFilter filter, int match,
Amith Yamasania3f133a2012-08-09 17:11:28 -07002626 ComponentName[] set, ComponentName activity, int userId) {
2627 try {
2628 mPM.addPreferredActivity(filter, match, set, activity, userId);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002629 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002630 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002631 }
2632 }
2633
2634 @Override
2635 public void replacePreferredActivity(IntentFilter filter,
2636 int match, ComponentName[] set, ComponentName activity) {
2637 try {
Jeff Sharkeyc59a5e72018-06-21 19:14:58 -06002638 mPM.replacePreferredActivity(filter, match, set, activity, getUserId());
Amith Yamasani41c1ded2014-08-05 11:15:05 -07002639 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002640 throw e.rethrowFromSystemServer();
Amith Yamasani41c1ded2014-08-05 11:15:05 -07002641 }
2642 }
2643
2644 @Override
2645 public void replacePreferredActivityAsUser(IntentFilter filter,
2646 int match, ComponentName[] set, ComponentName activity,
2647 int userId) {
2648 try {
2649 mPM.replacePreferredActivity(filter, match, set, activity, userId);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002650 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002651 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002652 }
2653 }
2654
2655 @Override
2656 public void clearPackagePreferredActivities(String packageName) {
2657 try {
2658 mPM.clearPackagePreferredActivities(packageName);
2659 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002660 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002661 }
2662 }
2663
2664 @Override
2665 public int getPreferredActivities(List<IntentFilter> outFilters,
2666 List<ComponentName> outActivities, String packageName) {
2667 try {
2668 return mPM.getPreferredActivities(outFilters, outActivities, packageName);
2669 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002670 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002671 }
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002672 }
2673
2674 @Override
Christopher Tatea2a0850d2013-09-05 16:38:58 -07002675 public ComponentName getHomeActivities(List<ResolveInfo> outActivities) {
2676 try {
2677 return mPM.getHomeActivities(outActivities);
2678 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002679 throw e.rethrowFromSystemServer();
Christopher Tatea2a0850d2013-09-05 16:38:58 -07002680 }
Christopher Tatea2a0850d2013-09-05 16:38:58 -07002681 }
2682
2683 @Override
Ricky Waia52e4262019-03-13 17:39:16 +00002684 public void setSyntheticAppDetailsActivityEnabled(String packageName, boolean enabled) {
Ricky Wai92cd0062019-02-14 20:23:22 +00002685 try {
2686 ComponentName componentName = new ComponentName(packageName,
Peter Wang09014f12020-01-24 08:15:38 +08002687 APP_DETAILS_ACTIVITY_CLASS_NAME);
Ricky Wai92cd0062019-02-14 20:23:22 +00002688 mPM.setComponentEnabledSetting(componentName, enabled
Peter Wang09014f12020-01-24 08:15:38 +08002689 ? COMPONENT_ENABLED_STATE_DEFAULT
2690 : COMPONENT_ENABLED_STATE_DISABLED,
2691 DONT_KILL_APP, getUserId());
Ricky Wai92cd0062019-02-14 20:23:22 +00002692 } catch (RemoteException e) {
2693 throw e.rethrowFromSystemServer();
2694 }
2695 }
2696
2697 @Override
Ricky Waia52e4262019-03-13 17:39:16 +00002698 public boolean getSyntheticAppDetailsActivityEnabled(String packageName) {
Ricky Wai92cd0062019-02-14 20:23:22 +00002699 try {
2700 ComponentName componentName = new ComponentName(packageName,
Peter Wang09014f12020-01-24 08:15:38 +08002701 APP_DETAILS_ACTIVITY_CLASS_NAME);
Ricky Wai92cd0062019-02-14 20:23:22 +00002702 int state = mPM.getComponentEnabledSetting(componentName, getUserId());
Peter Wang09014f12020-01-24 08:15:38 +08002703 return state == COMPONENT_ENABLED_STATE_ENABLED
2704 || state == COMPONENT_ENABLED_STATE_DEFAULT;
Ricky Wai92cd0062019-02-14 20:23:22 +00002705 } catch (RemoteException e) {
2706 throw e.rethrowFromSystemServer();
2707 }
2708 }
2709
2710 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002711 public void setComponentEnabledSetting(ComponentName componentName,
2712 int newState, int flags) {
2713 try {
Jeff Sharkeyc59a5e72018-06-21 19:14:58 -06002714 mPM.setComponentEnabledSetting(componentName, newState, flags, getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002715 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002716 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002717 }
2718 }
2719
2720 @Override
2721 public int getComponentEnabledSetting(ComponentName componentName) {
2722 try {
Jeff Sharkeyc59a5e72018-06-21 19:14:58 -06002723 return mPM.getComponentEnabledSetting(componentName, getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002724 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002725 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002726 }
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002727 }
2728
2729 @Override
2730 public void setApplicationEnabledSetting(String packageName,
2731 int newState, int flags) {
2732 try {
Dianne Hackborn3fa3c28a2013-03-26 16:15:41 -07002733 mPM.setApplicationEnabledSetting(packageName, newState, flags,
Jeff Sharkeyc59a5e72018-06-21 19:14:58 -06002734 getUserId(), mContext.getOpPackageName());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002735 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002736 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002737 }
2738 }
2739
2740 @Override
2741 public int getApplicationEnabledSetting(String packageName) {
2742 try {
Jeff Sharkeyc59a5e72018-06-21 19:14:58 -06002743 return mPM.getApplicationEnabledSetting(packageName, getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002744 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002745 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002746 }
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002747 }
2748
Amith Yamasani655d0e22013-06-12 14:19:10 -07002749 @Override
Sudheer Shankabbb3ff22015-07-09 15:39:23 +01002750 public void flushPackageRestrictionsAsUser(int userId) {
2751 try {
2752 mPM.flushPackageRestrictionsAsUser(userId);
2753 } catch (RemoteException e) {
2754 throw e.rethrowFromSystemServer();
2755 }
2756 }
2757
2758 @Override
Amith Yamasanie5bcff62014-07-19 15:44:09 -07002759 public boolean setApplicationHiddenSettingAsUser(String packageName, boolean hidden,
Amith Yamasani655d0e22013-06-12 14:19:10 -07002760 UserHandle user) {
2761 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07002762 return mPM.setApplicationHiddenSettingAsUser(packageName, hidden,
Amith Yamasani655d0e22013-06-12 14:19:10 -07002763 user.getIdentifier());
Jeff Sharkey27b2e692016-02-25 17:40:12 -07002764 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002765 throw e.rethrowFromSystemServer();
Amith Yamasani655d0e22013-06-12 14:19:10 -07002766 }
Amith Yamasani655d0e22013-06-12 14:19:10 -07002767 }
2768
2769 @Override
Amith Yamasanie5bcff62014-07-19 15:44:09 -07002770 public boolean getApplicationHiddenSettingAsUser(String packageName, UserHandle user) {
Amith Yamasani655d0e22013-06-12 14:19:10 -07002771 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07002772 return mPM.getApplicationHiddenSettingAsUser(packageName, user.getIdentifier());
Jeff Sharkey27b2e692016-02-25 17:40:12 -07002773 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002774 throw e.rethrowFromSystemServer();
Amith Yamasani655d0e22013-06-12 14:19:10 -07002775 }
Amith Yamasani655d0e22013-06-12 14:19:10 -07002776 }
2777
dcashmanc6f22492014-08-14 09:54:51 -07002778 /** @hide */
dcashman9d2f4412014-06-09 09:27:54 -07002779 @Override
Peter Wang09014f12020-01-24 08:15:38 +08002780 public void setSystemAppState(String packageName, @SystemAppState int state) {
2781 try {
2782 switch (state) {
2783 case SYSTEM_APP_STATE_HIDDEN_UNTIL_INSTALLED_HIDDEN:
2784 mPM.setSystemAppHiddenUntilInstalled(packageName, true);
2785 break;
2786 case SYSTEM_APP_STATE_HIDDEN_UNTIL_INSTALLED_VISIBLE:
2787 mPM.setSystemAppHiddenUntilInstalled(packageName, false);
2788 break;
2789 case SYSTEM_APP_STATE_INSTALLED:
2790 mPM.setSystemAppInstallState(packageName, true, getUserId());
2791 break;
2792 case SYSTEM_APP_STATE_UNINSTALLED:
2793 mPM.setSystemAppInstallState(packageName, false, getUserId());
2794 break;
2795 default:
2796 }
2797 } catch (RemoteException e) {
2798 throw e.rethrowFromSystemServer();
2799 }
2800 }
2801
2802 /** @hide */
2803 @Override
dcashman9d2f4412014-06-09 09:27:54 -07002804 public KeySet getKeySetByAlias(String packageName, String alias) {
Daulet Zhanguzin0af97d62019-12-30 15:41:28 +00002805 Objects.requireNonNull(packageName);
2806 Objects.requireNonNull(alias);
dcashman9d2f4412014-06-09 09:27:54 -07002807 try {
Jeff Sharkey27b2e692016-02-25 17:40:12 -07002808 return mPM.getKeySetByAlias(packageName, alias);
dcashman9d2f4412014-06-09 09:27:54 -07002809 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002810 throw e.rethrowFromSystemServer();
dcashman9d2f4412014-06-09 09:27:54 -07002811 }
dcashman9d2f4412014-06-09 09:27:54 -07002812 }
2813
dcashmanc6f22492014-08-14 09:54:51 -07002814 /** @hide */
dcashman9d2f4412014-06-09 09:27:54 -07002815 @Override
2816 public KeySet getSigningKeySet(String packageName) {
Daulet Zhanguzin0af97d62019-12-30 15:41:28 +00002817 Objects.requireNonNull(packageName);
dcashman9d2f4412014-06-09 09:27:54 -07002818 try {
Jeff Sharkey27b2e692016-02-25 17:40:12 -07002819 return mPM.getSigningKeySet(packageName);
dcashman9d2f4412014-06-09 09:27:54 -07002820 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002821 throw e.rethrowFromSystemServer();
dcashman9d2f4412014-06-09 09:27:54 -07002822 }
dcashman9d2f4412014-06-09 09:27:54 -07002823 }
2824
dcashmanc6f22492014-08-14 09:54:51 -07002825 /** @hide */
dcashman9d2f4412014-06-09 09:27:54 -07002826 @Override
2827 public boolean isSignedBy(String packageName, KeySet ks) {
Daulet Zhanguzin0af97d62019-12-30 15:41:28 +00002828 Objects.requireNonNull(packageName);
2829 Objects.requireNonNull(ks);
dcashman9d2f4412014-06-09 09:27:54 -07002830 try {
dcashmanc6f22492014-08-14 09:54:51 -07002831 return mPM.isPackageSignedByKeySet(packageName, ks);
dcashman9d2f4412014-06-09 09:27:54 -07002832 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002833 throw e.rethrowFromSystemServer();
dcashman9d2f4412014-06-09 09:27:54 -07002834 }
2835 }
2836
dcashmanc6f22492014-08-14 09:54:51 -07002837 /** @hide */
dcashman9d2f4412014-06-09 09:27:54 -07002838 @Override
2839 public boolean isSignedByExactly(String packageName, KeySet ks) {
Daulet Zhanguzin0af97d62019-12-30 15:41:28 +00002840 Objects.requireNonNull(packageName);
2841 Objects.requireNonNull(ks);
dcashman9d2f4412014-06-09 09:27:54 -07002842 try {
dcashmanc6f22492014-08-14 09:54:51 -07002843 return mPM.isPackageSignedByKeySetExactly(packageName, ks);
dcashman9d2f4412014-06-09 09:27:54 -07002844 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002845 throw e.rethrowFromSystemServer();
dcashman9d2f4412014-06-09 09:27:54 -07002846 }
2847 }
2848
Kenny Root0aaa0d92011-09-12 16:42:55 -07002849 /**
2850 * @hide
2851 */
2852 @Override
2853 public VerifierDeviceIdentity getVerifierDeviceIdentity() {
2854 try {
2855 return mPM.getVerifierDeviceIdentity();
2856 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002857 throw e.rethrowFromSystemServer();
Kenny Root0aaa0d92011-09-12 16:42:55 -07002858 }
Kenny Root0aaa0d92011-09-12 16:42:55 -07002859 }
2860
Jeff Hao9f60c082014-10-28 18:51:07 -07002861 @Override
2862 public boolean isUpgrade() {
Svet Ganovd8eb8b22019-04-05 18:52:08 -07002863 return isDeviceUpgrading();
2864 }
2865
2866 @Override
2867 public boolean isDeviceUpgrading() {
Jeff Hao9f60c082014-10-28 18:51:07 -07002868 try {
Svet Ganovd8eb8b22019-04-05 18:52:08 -07002869 return mPM.isDeviceUpgrading();
Jeff Hao9f60c082014-10-28 18:51:07 -07002870 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002871 throw e.rethrowFromSystemServer();
Jeff Hao9f60c082014-10-28 18:51:07 -07002872 }
2873 }
2874
Jeff Sharkey3a44f3f2014-04-28 17:36:31 -07002875 @Override
Jeff Sharkey16c8e3f2014-07-24 17:08:17 -07002876 public PackageInstaller getPackageInstaller() {
2877 synchronized (mLock) {
2878 if (mInstaller == null) {
2879 try {
Svet Ganov67882122016-12-11 16:36:34 -08002880 mInstaller = new PackageInstaller(mPM.getPackageInstaller(),
Jeff Sharkeyc59a5e72018-06-21 19:14:58 -06002881 mContext.getPackageName(), getUserId());
Jeff Sharkey16c8e3f2014-07-24 17:08:17 -07002882 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002883 throw e.rethrowFromSystemServer();
Jeff Sharkey16c8e3f2014-07-24 17:08:17 -07002884 }
2885 }
2886 return mInstaller;
Jeff Sharkey3a44f3f2014-04-28 17:36:31 -07002887 }
2888 }
2889
Jeff Sharkey6c833e02014-07-14 22:44:30 -07002890 @Override
2891 public boolean isPackageAvailable(String packageName) {
2892 try {
Jeff Sharkeyc59a5e72018-06-21 19:14:58 -06002893 return mPM.isPackageAvailable(packageName, getUserId());
Jeff Sharkey6c833e02014-07-14 22:44:30 -07002894 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002895 throw e.rethrowFromSystemServer();
Jeff Sharkey6c833e02014-07-14 22:44:30 -07002896 }
2897 }
2898
Nicolas Prevotc79586e2014-05-06 12:47:57 +01002899 /**
2900 * @hide
2901 */
2902 @Override
Nicolas Prevot63798c52014-05-27 13:22:38 +01002903 public void addCrossProfileIntentFilter(IntentFilter filter, int sourceUserId, int targetUserId,
2904 int flags) {
Nicolas Prevotc79586e2014-05-06 12:47:57 +01002905 try {
Nicolas Prevot3f7777f2014-07-24 15:58:39 +01002906 mPM.addCrossProfileIntentFilter(filter, mContext.getOpPackageName(),
Nicolas Prevot4b8d5822015-03-05 15:20:49 +00002907 sourceUserId, targetUserId, flags);
Nicolas Prevotc79586e2014-05-06 12:47:57 +01002908 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002909 throw e.rethrowFromSystemServer();
Nicolas Prevotc79586e2014-05-06 12:47:57 +01002910 }
2911 }
2912
2913 /**
2914 * @hide
2915 */
2916 @Override
Nicolas Prevot81948992014-05-16 18:25:26 +01002917 public void clearCrossProfileIntentFilters(int sourceUserId) {
Nicolas Prevotc79586e2014-05-06 12:47:57 +01002918 try {
Nicolas Prevot4b8d5822015-03-05 15:20:49 +00002919 mPM.clearCrossProfileIntentFilters(sourceUserId, mContext.getOpPackageName());
Nicolas Prevotc79586e2014-05-06 12:47:57 +01002920 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002921 throw e.rethrowFromSystemServer();
Nicolas Prevotc79586e2014-05-06 12:47:57 +01002922 }
2923 }
2924
Nicolas Prevot88cc3462014-05-14 14:51:48 +01002925 /**
2926 * @hide
2927 */
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +01002928 public Drawable loadItemIcon(PackageItemInfo itemInfo, ApplicationInfo appInfo) {
Benjamin Franzec2d48b2014-10-01 15:38:43 +01002929 Drawable dr = loadUnbadgedItemIcon(itemInfo, appInfo);
2930 if (itemInfo.showUserIcon != UserHandle.USER_NULL) {
2931 return dr;
2932 }
Jeff Sharkeyc59a5e72018-06-21 19:14:58 -06002933 return getUserBadgedIcon(dr, new UserHandle(getUserId()));
Benjamin Franzec2d48b2014-10-01 15:38:43 +01002934 }
2935
2936 /**
2937 * @hide
2938 */
Winson41605232019-05-06 11:53:30 -07002939 public Drawable loadUnbadgedItemIcon(@NonNull PackageItemInfo itemInfo,
2940 @Nullable ApplicationInfo appInfo) {
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +01002941 if (itemInfo.showUserIcon != UserHandle.USER_NULL) {
Alan Stokescae316d2019-11-26 09:39:02 +00002942 // Indicates itemInfo is for a different user (e.g. a profile's parent), so use a
Bookatz9313af62019-06-04 09:14:42 -07002943 // generic user icon (users generally lack permission to view each other's actual icons)
2944 int targetUserId = itemInfo.showUserIcon;
2945 return UserIcons.getDefaultUserIcon(
2946 mContext.getResources(), targetUserId, /* light= */ false);
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +01002947 }
Alexandra Gherghinadb811db2014-08-29 13:43:59 +01002948 Drawable dr = null;
2949 if (itemInfo.packageName != null) {
2950 dr = getDrawable(itemInfo.packageName, itemInfo.icon, appInfo);
2951 }
Winson41605232019-05-06 11:53:30 -07002952 if (dr == null && itemInfo != appInfo && appInfo != null) {
Patrick Baumanne34a75d2019-04-30 11:18:04 -07002953 dr = loadUnbadgedItemIcon(appInfo, appInfo);
2954 }
Alexandra Gherghinaa71e3902014-07-25 20:03:47 +01002955 if (dr == null) {
Alexandra Gherghinaa7093142014-07-30 13:43:39 +01002956 dr = itemInfo.loadDefaultIcon(this);
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +01002957 }
Benjamin Franzec2d48b2014-10-01 15:38:43 +01002958 return dr;
Svetoslavc7d62f02014-09-04 15:39:54 -07002959 }
2960
2961 private Drawable getBadgedDrawable(Drawable drawable, Drawable badgeDrawable,
2962 Rect badgeLocation, boolean tryBadgeInPlace) {
2963 final int badgedWidth = drawable.getIntrinsicWidth();
2964 final int badgedHeight = drawable.getIntrinsicHeight();
2965 final boolean canBadgeInPlace = tryBadgeInPlace
2966 && (drawable instanceof BitmapDrawable)
2967 && ((BitmapDrawable) drawable).getBitmap().isMutable();
2968
2969 final Bitmap bitmap;
2970 if (canBadgeInPlace) {
2971 bitmap = ((BitmapDrawable) drawable).getBitmap();
2972 } else {
2973 bitmap = Bitmap.createBitmap(badgedWidth, badgedHeight, Bitmap.Config.ARGB_8888);
2974 }
2975 Canvas canvas = new Canvas(bitmap);
2976
2977 if (!canBadgeInPlace) {
2978 drawable.setBounds(0, 0, badgedWidth, badgedHeight);
2979 drawable.draw(canvas);
2980 }
2981
2982 if (badgeLocation != null) {
2983 if (badgeLocation.left < 0 || badgeLocation.top < 0
2984 || badgeLocation.width() > badgedWidth || badgeLocation.height() > badgedHeight) {
2985 throw new IllegalArgumentException("Badge location " + badgeLocation
2986 + " not in badged drawable bounds "
2987 + new Rect(0, 0, badgedWidth, badgedHeight));
2988 }
2989 badgeDrawable.setBounds(0, 0, badgeLocation.width(), badgeLocation.height());
2990
2991 canvas.save();
2992 canvas.translate(badgeLocation.left, badgeLocation.top);
2993 badgeDrawable.draw(canvas);
2994 canvas.restore();
2995 } else {
2996 badgeDrawable.setBounds(0, 0, badgedWidth, badgedHeight);
2997 badgeDrawable.draw(canvas);
2998 }
2999
3000 if (!canBadgeInPlace) {
3001 BitmapDrawable mergedDrawable = new BitmapDrawable(mContext.getResources(), bitmap);
3002
3003 if (drawable instanceof BitmapDrawable) {
3004 BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
3005 mergedDrawable.setTargetDensity(bitmapDrawable.getBitmap().getDensity());
3006 }
3007
3008 return mergedDrawable;
3009 }
3010
3011 return drawable;
3012 }
3013
Bookatz029832a2019-10-04 16:50:22 -07003014 private boolean hasUserBadge(int userId) {
3015 return getUserManager().hasBadge(userId);
Nicolas Prevot88cc3462014-05-14 14:51:48 +01003016 }
3017
Bartosz Fabianowskia34f53f2017-01-11 18:08:47 +01003018 /**
3019 * @hide
3020 */
3021 @Override
3022 public int getInstallReason(String packageName, UserHandle user) {
3023 try {
3024 return mPM.getInstallReason(packageName, user.getIdentifier());
3025 } catch (RemoteException e) {
3026 throw e.rethrowFromSystemServer();
3027 }
3028 }
3029
Jeff Sharkey620b32b2015-04-23 19:36:02 -07003030 /** {@hide} */
3031 private static class MoveCallbackDelegate extends IPackageMoveObserver.Stub implements
3032 Handler.Callback {
Jeff Sharkey50a05452015-04-29 11:24:52 -07003033 private static final int MSG_CREATED = 1;
3034 private static final int MSG_STATUS_CHANGED = 2;
Jeff Sharkey620b32b2015-04-23 19:36:02 -07003035
3036 final MoveCallback mCallback;
3037 final Handler mHandler;
3038
3039 public MoveCallbackDelegate(MoveCallback callback, Looper looper) {
3040 mCallback = callback;
3041 mHandler = new Handler(looper, this);
3042 }
3043
3044 @Override
3045 public boolean handleMessage(Message msg) {
Jeff Sharkey620b32b2015-04-23 19:36:02 -07003046 switch (msg.what) {
Jeff Sharkey50a05452015-04-29 11:24:52 -07003047 case MSG_CREATED: {
Jeff Sharkeyb36586a2015-04-27 08:42:28 -07003048 final SomeArgs args = (SomeArgs) msg.obj;
Jeff Sharkey50a05452015-04-29 11:24:52 -07003049 mCallback.onCreated(args.argi1, (Bundle) args.arg2);
Jeff Sharkeyb36586a2015-04-27 08:42:28 -07003050 args.recycle();
Jeff Sharkey620b32b2015-04-23 19:36:02 -07003051 return true;
Jeff Sharkey50a05452015-04-29 11:24:52 -07003052 }
3053 case MSG_STATUS_CHANGED: {
3054 final SomeArgs args = (SomeArgs) msg.obj;
3055 mCallback.onStatusChanged(args.argi1, args.argi2, (long) args.arg3);
3056 args.recycle();
3057 return true;
3058 }
Jeff Sharkey620b32b2015-04-23 19:36:02 -07003059 }
3060 return false;
3061 }
3062
3063 @Override
Jeff Sharkey50a05452015-04-29 11:24:52 -07003064 public void onCreated(int moveId, Bundle extras) {
Jeff Sharkeyb36586a2015-04-27 08:42:28 -07003065 final SomeArgs args = SomeArgs.obtain();
3066 args.argi1 = moveId;
Jeff Sharkey50a05452015-04-29 11:24:52 -07003067 args.arg2 = extras;
3068 mHandler.obtainMessage(MSG_CREATED, args).sendToTarget();
3069 }
3070
3071 @Override
3072 public void onStatusChanged(int moveId, int status, long estMillis) {
3073 final SomeArgs args = SomeArgs.obtain();
3074 args.argi1 = moveId;
3075 args.argi2 = status;
3076 args.arg3 = estMillis;
Jeff Sharkeyb36586a2015-04-27 08:42:28 -07003077 mHandler.obtainMessage(MSG_STATUS_CHANGED, args).sendToTarget();
Jeff Sharkey620b32b2015-04-23 19:36:02 -07003078 }
3079 }
3080
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08003081 private final ContextImpl mContext;
Mathew Inwood61e8ae62018-08-14 14:17:44 +01003082 @UnsupportedAppUsage
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08003083 private final IPackageManager mPM;
Todd Kennedy8f135982019-07-02 07:35:15 -07003084 private final IPermissionManager mPermissionManager;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08003085
Jeff Sharkeyc59a5e72018-06-21 19:14:58 -06003086 /** Assume locked until we hear otherwise */
3087 private volatile boolean mUserUnlocked = false;
3088
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08003089 private static final Object sSync = new Object();
Dianne Hackbornadd005c2013-07-17 18:43:12 -07003090 private static ArrayMap<ResourceName, WeakReference<Drawable.ConstantState>> sIconCache
3091 = new ArrayMap<ResourceName, WeakReference<Drawable.ConstantState>>();
3092 private static ArrayMap<ResourceName, WeakReference<CharSequence>> sStringCache
3093 = new ArrayMap<ResourceName, WeakReference<CharSequence>>();
Svetoslavf7c06eb2015-06-10 18:43:22 -07003094
3095 private final Map<OnPermissionsChangedListener, IOnPermissionsChangeListener>
3096 mPermissionListeners = new ArrayMap<>();
3097
3098 public class OnPermissionsChangeListenerDelegate extends IOnPermissionsChangeListener.Stub
3099 implements Handler.Callback{
3100 private static final int MSG_PERMISSIONS_CHANGED = 1;
3101
3102 private final OnPermissionsChangedListener mListener;
3103 private final Handler mHandler;
3104
3105
3106 public OnPermissionsChangeListenerDelegate(OnPermissionsChangedListener listener,
3107 Looper looper) {
3108 mListener = listener;
3109 mHandler = new Handler(looper, this);
3110 }
3111
3112 @Override
3113 public void onPermissionsChanged(int uid) {
3114 mHandler.obtainMessage(MSG_PERMISSIONS_CHANGED, uid, 0).sendToTarget();
3115 }
3116
3117 @Override
3118 public boolean handleMessage(Message msg) {
3119 switch (msg.what) {
3120 case MSG_PERMISSIONS_CHANGED: {
3121 final int uid = msg.arg1;
3122 mListener.onPermissionsChanged(uid);
3123 return true;
3124 }
3125 }
3126 return false;
3127 }
3128 }
Suprabh Shuklaaef25132017-01-23 18:09:03 -08003129
3130 @Override
3131 public boolean canRequestPackageInstalls() {
3132 try {
Jeff Sharkeyc59a5e72018-06-21 19:14:58 -06003133 return mPM.canRequestPackageInstalls(mContext.getPackageName(), getUserId());
Suprabh Shuklaaef25132017-01-23 18:09:03 -08003134 } catch (RemoteException e) {
3135 throw e.rethrowAsRuntimeException();
3136 }
3137 }
Chad Brubaker336ae5b2017-03-24 15:53:09 -07003138
3139 @Override
3140 public ComponentName getInstantAppResolverSettingsComponent() {
3141 try {
3142 return mPM.getInstantAppResolverSettingsComponent();
3143 } catch (RemoteException e) {
3144 throw e.rethrowAsRuntimeException();
3145 }
3146 }
Todd Kennedy801e6592017-04-12 14:10:12 -07003147
3148 @Override
3149 public ComponentName getInstantAppInstallerComponent() {
3150 try {
3151 return mPM.getInstantAppInstallerComponent();
3152 } catch (RemoteException e) {
3153 throw e.rethrowAsRuntimeException();
3154 }
3155 }
Chad Brubaker0d277a72017-04-12 16:56:53 -07003156
3157 @Override
3158 public String getInstantAppAndroidId(String packageName, UserHandle user) {
3159 try {
3160 return mPM.getInstantAppAndroidId(packageName, user.getIdentifier());
3161 } catch (RemoteException e) {
3162 throw e.rethrowAsRuntimeException();
3163 }
3164 }
Calin Juravle3d2af7f2017-04-19 19:56:21 -07003165
3166 private static class DexModuleRegisterResult {
3167 final String dexModulePath;
3168 final boolean success;
3169 final String message;
3170
3171 private DexModuleRegisterResult(String dexModulePath, boolean success, String message) {
3172 this.dexModulePath = dexModulePath;
3173 this.success = success;
3174 this.message = message;
3175 }
3176 }
3177
3178 private static class DexModuleRegisterCallbackDelegate
3179 extends android.content.pm.IDexModuleRegisterCallback.Stub
3180 implements Handler.Callback {
3181 private static final int MSG_DEX_MODULE_REGISTERED = 1;
3182 private final DexModuleRegisterCallback callback;
3183 private final Handler mHandler;
3184
3185 DexModuleRegisterCallbackDelegate(@NonNull DexModuleRegisterCallback callback) {
3186 this.callback = callback;
3187 mHandler = new Handler(Looper.getMainLooper(), this);
3188 }
3189
3190 @Override
3191 public void onDexModuleRegistered(@NonNull String dexModulePath, boolean success,
3192 @Nullable String message)throws RemoteException {
3193 mHandler.obtainMessage(MSG_DEX_MODULE_REGISTERED,
3194 new DexModuleRegisterResult(dexModulePath, success, message)).sendToTarget();
3195 }
3196
3197 @Override
3198 public boolean handleMessage(Message msg) {
3199 if (msg.what != MSG_DEX_MODULE_REGISTERED) {
3200 return false;
3201 }
3202 DexModuleRegisterResult result = (DexModuleRegisterResult)msg.obj;
3203 callback.onDexModuleRegistered(result.dexModulePath, result.success, result.message);
3204 return true;
3205 }
3206 }
3207
3208 @Override
3209 public void registerDexModule(@NonNull String dexModule,
3210 @Nullable DexModuleRegisterCallback callback) {
3211 // Check if this is a shared module by looking if the others can read it.
3212 boolean isSharedModule = false;
3213 try {
3214 StructStat stat = Os.stat(dexModule);
3215 if ((OsConstants.S_IROTH & stat.st_mode) != 0) {
3216 isSharedModule = true;
3217 }
3218 } catch (ErrnoException e) {
3219 callback.onDexModuleRegistered(dexModule, false,
3220 "Could not get stat the module file: " + e.getMessage());
3221 return;
3222 }
3223
3224 // Module path is ok.
3225 // Create the callback delegate to be passed to package manager service.
3226 DexModuleRegisterCallbackDelegate callbackDelegate = null;
3227 if (callback != null) {
3228 callbackDelegate = new DexModuleRegisterCallbackDelegate(callback);
3229 }
3230
3231 // Invoke the package manager service.
3232 try {
3233 mPM.registerDexModule(mContext.getPackageName(), dexModule,
3234 isSharedModule, callbackDelegate);
3235 } catch (RemoteException e) {
3236 throw e.rethrowAsRuntimeException();
3237 }
3238 }
Calin Juravle45f8b292017-11-07 18:49:43 -08003239
3240 @Override
Ben Gruver1ab3d6e2017-12-07 13:45:08 -08003241 public CharSequence getHarmfulAppWarning(String packageName) {
3242 try {
Jeff Sharkeyc59a5e72018-06-21 19:14:58 -06003243 return mPM.getHarmfulAppWarning(packageName, getUserId());
Ben Gruver1ab3d6e2017-12-07 13:45:08 -08003244 } catch (RemoteException e) {
3245 throw e.rethrowAsRuntimeException();
3246 }
3247 }
3248
3249 @Override
3250 public void setHarmfulAppWarning(String packageName, CharSequence warning) {
3251 try {
Jeff Sharkeyc59a5e72018-06-21 19:14:58 -06003252 mPM.setHarmfulAppWarning(packageName, warning, getUserId());
Ben Gruver1ab3d6e2017-12-07 13:45:08 -08003253 } catch (RemoteException e) {
3254 throw e.rethrowAsRuntimeException();
3255 }
3256 }
3257
3258 @Override
Calin Juravle45f8b292017-11-07 18:49:43 -08003259 public ArtManager getArtManager() {
3260 synchronized (mLock) {
3261 if (mArtManager == null) {
3262 try {
Jeff Sharkey0ad62832018-04-19 11:20:57 -06003263 mArtManager = new ArtManager(mContext, mPM.getArtManager());
Calin Juravle45f8b292017-11-07 18:49:43 -08003264 } catch (RemoteException e) {
3265 throw e.rethrowFromSystemServer();
3266 }
3267 }
3268 return mArtManager;
3269 }
3270 }
Makoto Onuki700feef2018-02-15 10:59:41 -08003271
3272 @Override
Tony Makc5a74322020-02-04 17:18:15 +00003273 public String getDefaultTextClassifierPackageName() {
Makoto Onuki700feef2018-02-15 10:59:41 -08003274 try {
Tony Makc5a74322020-02-04 17:18:15 +00003275 return mPM.getDefaultTextClassifierPackageName();
Makoto Onuki700feef2018-02-15 10:59:41 -08003276 } catch (RemoteException e) {
3277 throw e.rethrowAsRuntimeException();
3278 }
3279 }
Benjamin Franz7cc9a812018-03-22 10:11:29 +00003280
3281 @Override
Tony Makc5a74322020-02-04 17:18:15 +00003282 public String getSystemTextClassifierPackageName() {
Joanne Chungb50ab4b2019-10-14 16:40:57 +08003283 try {
Tony Makc5a74322020-02-04 17:18:15 +00003284 return mPM.getSystemTextClassifierPackageName();
Joanne Chungb50ab4b2019-10-14 16:40:57 +08003285 } catch (RemoteException e) {
3286 throw e.rethrowAsRuntimeException();
3287 }
3288 }
3289
3290 @Override
Yi Jiang8915b352019-03-21 12:02:53 -07003291 public String getAttentionServicePackageName() {
3292 try {
3293 return mPM.getAttentionServicePackageName();
3294 } catch (RemoteException e) {
3295 throw e.rethrowAsRuntimeException();
3296 }
3297 }
3298
3299 @Override
Varun Shah5f303652018-11-16 18:11:19 -08003300 public String getWellbeingPackageName() {
3301 try {
3302 return mPM.getWellbeingPackageName();
3303 } catch (RemoteException e) {
3304 throw e.rethrowAsRuntimeException();
3305 }
3306 }
3307
3308 @Override
George Hodulikcd7695d2019-01-29 18:17:05 -08003309 public String getAppPredictionServicePackageName() {
3310 try {
3311 return mPM.getAppPredictionServicePackageName();
3312 } catch (RemoteException e) {
3313 throw e.rethrowAsRuntimeException();
3314 }
3315 }
3316
3317 @Override
Nadav Bar1a1f5a212019-03-17 16:15:14 +02003318 public String getSystemCaptionsServicePackageName() {
Nadav Bar6d79ab72019-01-10 10:52:11 +02003319 try {
Nadav Bar1a1f5a212019-03-17 16:15:14 +02003320 return mPM.getSystemCaptionsServicePackageName();
Nadav Bar6d79ab72019-01-10 10:52:11 +02003321 } catch (RemoteException e) {
3322 throw e.rethrowAsRuntimeException();
3323 }
3324 }
3325
3326 @Override
Christopher Tatee4f5f2d2019-10-08 15:49:43 -07003327 public String getSetupWizardPackageName() {
3328 try {
3329 return mPM.getSetupWizardPackageName();
3330 } catch (RemoteException e) {
3331 throw e.rethrowAsRuntimeException();
3332 }
3333 }
3334
3335 @Override
Joe Onorato5a15b552018-12-18 10:40:04 -08003336 public String getIncidentReportApproverPackageName() {
3337 try {
3338 return mPM.getIncidentReportApproverPackageName();
3339 } catch (RemoteException e) {
3340 throw e.rethrowAsRuntimeException();
3341 }
3342 }
3343
3344 @Override
Joanne Chungfba3e882019-08-20 18:47:38 +08003345 public String getContentCaptureServicePackageName() {
3346 try {
3347 return mPM.getContentCaptureServicePackageName();
3348 } catch (RemoteException e) {
3349 throw e.rethrowAsRuntimeException();
3350 }
3351 }
3352
3353 @Override
Benjamin Franz7cc9a812018-03-22 10:11:29 +00003354 public boolean isPackageStateProtected(String packageName, int userId) {
3355 try {
3356 return mPM.isPackageStateProtected(packageName, userId);
3357 } catch (RemoteException e) {
3358 throw e.rethrowAsRuntimeException();
3359 }
3360 }
Mårten Kongstadfd20b832018-10-26 15:36:20 +02003361
Mårten Kongstadfd20b832018-10-26 15:36:20 +02003362 public void sendDeviceCustomizationReadyBroadcast() {
3363 try {
3364 mPM.sendDeviceCustomizationReadyBroadcast();
3365 } catch (RemoteException e) {
3366 throw e.rethrowAsRuntimeException();
3367 }
3368 }
Taras Antoshchuka7d9c732019-10-29 13:46:19 +01003369
Eugene Susla2ac02b02020-03-10 12:18:21 -07003370 @Override
3371 public boolean isAutoRevokeWhitelisted() {
3372 try {
3373 return mPM.isAutoRevokeWhitelisted(mContext.getPackageName());
3374 } catch (RemoteException e) {
3375 throw e.rethrowAsRuntimeException();
3376 }
3377 }
3378
Taras Antoshchuk8a600242020-03-17 22:56:54 +01003379 @Override
Taras Antoshchuka7d9c732019-10-29 13:46:19 +01003380 public void setMimeGroup(String mimeGroup, Set<String> mimeTypes) {
3381 try {
Taras Antoshchuk8a600242020-03-17 22:56:54 +01003382 mPM.setMimeGroup(mContext.getPackageName(), mimeGroup, new ArrayList<>(mimeTypes));
Taras Antoshchuka7d9c732019-10-29 13:46:19 +01003383 } catch (RemoteException e) {
3384 throw e.rethrowAsRuntimeException();
3385 }
3386 }
3387
Taras Antoshchuk8a600242020-03-17 22:56:54 +01003388 @NonNull
Taras Antoshchuka7d9c732019-10-29 13:46:19 +01003389 @Override
3390 public Set<String> getMimeGroup(String group) {
3391 try {
3392 List<String> mimeGroup = mPM.getMimeGroup(mContext.getPackageName(), group);
Taras Antoshchuka7d9c732019-10-29 13:46:19 +01003393 return new ArraySet<>(mimeGroup);
3394 } catch (RemoteException e) {
3395 throw e.rethrowAsRuntimeException();
3396 }
3397 }
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08003398}