blob: 6f8233d5de9bd30dd054dfe1ba62413d2dce2550 [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) {
Eugene Suslacb923e32019-08-20 16:48:55 -0700766 if (DEBUG_TRACE_PERMISSION_UPDATES
Todd Kennedyc971a452019-07-08 16:04:52 -0700767 && shouldTraceGrant(packageName, permName, user.getIdentifier())) {
Eugene Suslacb923e32019-08-20 16:48:55 -0700768 Log.i(TAG, "App " + mContext.getPackageName() + " is revoking " + packageName + " "
Todd Kennedyc971a452019-07-08 16:04:52 -0700769 + permName + " for user " + user.getIdentifier(), new RuntimeException());
Eugene Suslad516bee2019-05-01 09:48:43 -0700770 }
Dianne Hackborne639da72012-02-21 15:11:13 -0800771 try {
Todd Kennedyc971a452019-07-08 16:04:52 -0700772 mPermissionManager
773 .revokeRuntimePermission(packageName, permName, user.getIdentifier());
Svet Ganov8c7f7002015-05-07 10:48:44 -0700774 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700775 throw e.rethrowFromSystemServer();
Svet Ganov8c7f7002015-05-07 10:48:44 -0700776 }
777 }
778
779 @Override
Evan Severson43b2a192020-02-19 13:45:49 -0800780 public void revokeRuntimePermission(String packageName, String permName, UserHandle user,
781 String reason) {
782 // TODO evanseverson: impl
783 }
784
785 @Override
Todd Kennedy230c0a72019-07-03 13:06:35 -0700786 public int getPermissionFlags(String permName, String packageName, UserHandle user) {
Svet Ganov8c7f7002015-05-07 10:48:44 -0700787 try {
Todd Kennedy230c0a72019-07-03 13:06:35 -0700788 return mPermissionManager
789 .getPermissionFlags(permName, packageName, user.getIdentifier());
Svet Ganov8c7f7002015-05-07 10:48:44 -0700790 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700791 throw e.rethrowFromSystemServer();
Svet Ganov8c7f7002015-05-07 10:48:44 -0700792 }
793 }
794
795 @Override
Todd Kennedy230c0a72019-07-03 13:06:35 -0700796 public void updatePermissionFlags(String permName, String packageName,
Svet Ganov8c7f7002015-05-07 10:48:44 -0700797 int flagMask, int flagValues, UserHandle user) {
Eugene Suslacb923e32019-08-20 16:48:55 -0700798 if (DEBUG_TRACE_PERMISSION_UPDATES
Todd Kennedy230c0a72019-07-03 13:06:35 -0700799 && shouldTraceGrant(packageName, permName, user.getIdentifier())) {
Eugene Suslad516bee2019-05-01 09:48:43 -0700800 Log.i(TAG, "App " + mContext.getPackageName() + " is updating flags for "
Eugene Suslacb923e32019-08-20 16:48:55 -0700801 + packageName + " "
Todd Kennedy230c0a72019-07-03 13:06:35 -0700802 + permName + " for user " + user.getIdentifier() + ": "
Eugene Suslad516bee2019-05-01 09:48:43 -0700803 + DebugUtils.flagsToString(PackageManager.class, "FLAG_PERMISSION_", flagMask)
804 + " := " + DebugUtils.flagsToString(
805 PackageManager.class, "FLAG_PERMISSION_", flagValues),
806 new RuntimeException());
807 }
Svet Ganov8c7f7002015-05-07 10:48:44 -0700808 try {
Todd Kennedy230c0a72019-07-03 13:06:35 -0700809 final boolean checkAdjustPolicyFlagPermission =
810 mContext.getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.Q;
811 mPermissionManager.updatePermissionFlags(permName, packageName, flagMask,
812 flagValues, checkAdjustPolicyFlagPermission, user.getIdentifier());
Dianne Hackborne639da72012-02-21 15:11:13 -0800813 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700814 throw e.rethrowFromSystemServer();
Dianne Hackborne639da72012-02-21 15:11:13 -0800815 }
816 }
817
818 @Override
Svet Ganovd8eb8b22019-04-05 18:52:08 -0700819 public @NonNull Set<String> getWhitelistedRestrictedPermissions(
Todd Kennedy7e3dd3a2019-07-08 10:34:29 -0700820 @NonNull String packageName, @PermissionWhitelistFlags int flags) {
Svet Ganovd8eb8b22019-04-05 18:52:08 -0700821 try {
Todd Kennedy7e3dd3a2019-07-08 10:34:29 -0700822 final int userId = getUserId();
823 final List<String> whitelist = mPermissionManager
824 .getWhitelistedRestrictedPermissions(packageName, flags, userId);
Svet Ganovd8eb8b22019-04-05 18:52:08 -0700825 if (whitelist != null) {
826 return new ArraySet<>(whitelist);
827 }
828 return Collections.emptySet();
829 } catch (RemoteException e) {
830 throw e.rethrowFromSystemServer();
831 }
832 }
833
834 @Override
835 public boolean addWhitelistedRestrictedPermission(@NonNull String packageName,
Todd Kennedy7e3dd3a2019-07-08 10:34:29 -0700836 @NonNull String permName, @PermissionWhitelistFlags int flags) {
Svet Ganovd8eb8b22019-04-05 18:52:08 -0700837 try {
Todd Kennedy7e3dd3a2019-07-08 10:34:29 -0700838 final int userId = getUserId();
839 return mPermissionManager
840 .addWhitelistedRestrictedPermission(packageName, permName, flags, userId);
Svet Ganovd8eb8b22019-04-05 18:52:08 -0700841 } catch (RemoteException e) {
842 throw e.rethrowFromSystemServer();
843 }
844 }
845
846 @Override
Eugene Susla922cd082020-03-11 12:38:17 -0700847 public boolean setAutoRevokeWhitelisted(
848 @NonNull String packageName, boolean whitelisted) {
849 try {
850 final int userId = getUserId();
851 return mPermissionManager.setAutoRevokeWhitelisted(packageName, whitelisted, userId);
852 } catch (RemoteException e) {
853 throw e.rethrowFromSystemServer();
854 }
855 }
856
857 @Override
858 public boolean isAutoRevokeWhitelisted(@NonNull String packageName) {
859 try {
860 final int userId = getUserId();
861 return mPermissionManager.isAutoRevokeWhitelisted(packageName, userId);
862 } catch (RemoteException e) {
863 throw e.rethrowFromSystemServer();
864 }
865 }
866
867 @Override
Svet Ganovd8eb8b22019-04-05 18:52:08 -0700868 public boolean removeWhitelistedRestrictedPermission(@NonNull String packageName,
Todd Kennedy7e3dd3a2019-07-08 10:34:29 -0700869 @NonNull String permName, @PermissionWhitelistFlags int flags) {
Svet Ganovd8eb8b22019-04-05 18:52:08 -0700870 try {
Todd Kennedy7e3dd3a2019-07-08 10:34:29 -0700871 final int userId = getUserId();
872 return mPermissionManager
873 .removeWhitelistedRestrictedPermission(packageName, permName, flags, userId);
Svet Ganovd8eb8b22019-04-05 18:52:08 -0700874 } catch (RemoteException e) {
875 throw e.rethrowFromSystemServer();
876 }
877 }
878
879 @Override
Mathew Inwood61e8ae62018-08-14 14:17:44 +0100880 @UnsupportedAppUsage
Todd Kennedyc5b0e862019-07-16 09:47:58 -0700881 public boolean shouldShowRequestPermissionRationale(String permName) {
Svetoslav20770dd2015-05-29 15:43:04 -0700882 try {
Todd Kennedyc5b0e862019-07-16 09:47:58 -0700883 final String packageName = mContext.getPackageName();
884 return mPermissionManager
885 .shouldShowRequestPermissionRationale(permName, packageName, getUserId());
Svetoslav20770dd2015-05-29 15:43:04 -0700886 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700887 throw e.rethrowFromSystemServer();
Svetoslav20770dd2015-05-29 15:43:04 -0700888 }
889 }
890
891 @Override
Evan Seversond60c7852020-01-21 16:04:44 -0800892 public CharSequence getBackgroundPermissionOptionLabel() {
Evan Seversoncfae44a2020-01-09 12:43:08 -0800893 try {
894
895 String permissionController = getPermissionControllerPackageName();
896 Context context =
897 mContext.createPackageContext(permissionController, 0);
898
899 int textId = context.getResources().getIdentifier(APP_PERMISSION_BUTTON_ALLOW_ALWAYS,
Evan Seversoneb1e3292020-06-01 11:56:48 -0700900 "string", PERMISSION_CONTROLLER_RESOURCE_PACKAGE);
Evan Seversoncfae44a2020-01-09 12:43:08 -0800901 if (textId != 0) {
902 return context.getText(textId);
903 }
904 } catch (NameNotFoundException e) {
905 Log.e(TAG, "Permission controller not found.", e);
906 }
907 return "";
908 }
909
910 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800911 public int checkSignatures(String pkg1, String pkg2) {
912 try {
913 return mPM.checkSignatures(pkg1, pkg2);
914 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700915 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800916 }
917 }
918
919 @Override
920 public int checkSignatures(int uid1, int uid2) {
921 try {
922 return mPM.checkUidSignatures(uid1, uid2);
923 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700924 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800925 }
926 }
927
928 @Override
Daniel Cashman5cdda342018-01-19 07:22:52 -0800929 public boolean hasSigningCertificate(
Peter Wang09014f12020-01-24 08:15:38 +0800930 String packageName, byte[] certificate, @CertificateInputType int type) {
Daniel Cashman5cdda342018-01-19 07:22:52 -0800931 try {
932 return mPM.hasSigningCertificate(packageName, certificate, type);
933 } catch (RemoteException e) {
934 throw e.rethrowFromSystemServer();
935 }
936 }
937
938 @Override
939 public boolean hasSigningCertificate(
Peter Wang09014f12020-01-24 08:15:38 +0800940 int uid, byte[] certificate, @CertificateInputType int type) {
Daniel Cashman5cdda342018-01-19 07:22:52 -0800941 try {
942 return mPM.hasUidSigningCertificate(uid, certificate, type);
943 } catch (RemoteException e) {
944 throw e.rethrowFromSystemServer();
945 }
946 }
947
948 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800949 public String[] getPackagesForUid(int uid) {
950 try {
951 return mPM.getPackagesForUid(uid);
952 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700953 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800954 }
955 }
956
957 @Override
958 public String getNameForUid(int uid) {
959 try {
960 return mPM.getNameForUid(uid);
961 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700962 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800963 }
964 }
965
966 @Override
Todd Kennedy9da8b8a72017-07-25 15:38:39 -0700967 public String[] getNamesForUids(int[] uids) {
968 try {
969 return mPM.getNamesForUids(uids);
970 } catch (RemoteException e) {
971 throw e.rethrowFromSystemServer();
972 }
973 }
974
975 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800976 public int getUidForSharedUser(String sharedUserName)
977 throws NameNotFoundException {
978 try {
979 int uid = mPM.getUidForSharedUser(sharedUserName);
980 if(uid != -1) {
981 return uid;
982 }
983 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700984 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800985 }
986 throw new NameNotFoundException("No shared userid for user:"+sharedUserName);
987 }
988
Todd Kennedy3dbf83a2018-11-13 13:29:16 -0800989 @Override
990 public List<ModuleInfo> getInstalledModules(int flags) {
Narayan Kamath2c828c1d2018-12-10 17:36:31 +0000991 try {
992 return mPM.getInstalledModules(flags);
993 } catch (RemoteException e) {
994 throw e.rethrowFromSystemServer();
995 }
Todd Kennedy3dbf83a2018-11-13 13:29:16 -0800996 }
997
998 @Override
999 public ModuleInfo getModuleInfo(String packageName, int flags) throws NameNotFoundException {
Narayan Kamath2c828c1d2018-12-10 17:36:31 +00001000 try {
1001 ModuleInfo mi = mPM.getModuleInfo(packageName, flags);
1002 if (mi != null) {
1003 return mi;
1004 }
1005 } catch (RemoteException e) {
1006 throw e.rethrowFromSystemServer();
1007 }
1008
1009 throw new NameNotFoundException("No module info for package: " + packageName);
Todd Kennedy3dbf83a2018-11-13 13:29:16 -08001010 }
1011
Kenny Roote6cd0c72011-05-19 12:48:14 -07001012 @SuppressWarnings("unchecked")
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001013 @Override
1014 public List<PackageInfo> getInstalledPackages(int flags) {
Jeff Sharkeyc59a5e72018-06-21 19:14:58 -06001015 return getInstalledPackagesAsUser(flags, getUserId());
Amith Yamasani151ec4c2012-09-07 19:25:16 -07001016 }
1017
1018 /** @hide */
1019 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001020 @SuppressWarnings("unchecked")
Jeff Sharkeye06b4d12016-01-06 14:51:50 -07001021 public List<PackageInfo> getInstalledPackagesAsUser(int flags, int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001022 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001023 ParceledListSlice<PackageInfo> parceledList =
Jeff Sharkeyc59a5e72018-06-21 19:14:58 -06001024 mPM.getInstalledPackages(updateFlagsForPackage(flags, userId), userId);
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001025 if (parceledList == null) {
1026 return Collections.emptyList();
1027 }
1028 return parceledList.getList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001029 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001030 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001031 }
1032 }
1033
Kenny Roote6cd0c72011-05-19 12:48:14 -07001034 @SuppressWarnings("unchecked")
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001035 @Override
Dianne Hackborne7991752013-01-16 17:56:46 -08001036 public List<PackageInfo> getPackagesHoldingPermissions(
1037 String[] permissions, int flags) {
Jeff Sharkeyc59a5e72018-06-21 19:14:58 -06001038 final int userId = getUserId();
Dianne Hackborne7991752013-01-16 17:56:46 -08001039 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001040 ParceledListSlice<PackageInfo> parceledList =
Jeff Sharkeyc59a5e72018-06-21 19:14:58 -06001041 mPM.getPackagesHoldingPermissions(permissions,
1042 updateFlagsForPackage(flags, userId), userId);
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001043 if (parceledList == null) {
1044 return Collections.emptyList();
1045 }
1046 return parceledList.getList();
Dianne Hackborne7991752013-01-16 17:56:46 -08001047 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001048 throw e.rethrowFromSystemServer();
Dianne Hackborne7991752013-01-16 17:56:46 -08001049 }
1050 }
1051
1052 @SuppressWarnings("unchecked")
1053 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001054 public List<ApplicationInfo> getInstalledApplications(int flags) {
Jeff Sharkeyc59a5e72018-06-21 19:14:58 -06001055 return getInstalledApplicationsAsUser(flags, getUserId());
Bartosz Fabianowski11334242016-11-17 20:49:16 +01001056 }
1057
1058 /** @hide */
1059 @SuppressWarnings("unchecked")
1060 @Override
1061 public List<ApplicationInfo> getInstalledApplicationsAsUser(int flags, int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001062 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001063 ParceledListSlice<ApplicationInfo> parceledList =
Jeff Sharkeyc59a5e72018-06-21 19:14:58 -06001064 mPM.getInstalledApplications(updateFlagsForApplication(flags, userId), userId);
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001065 if (parceledList == null) {
1066 return Collections.emptyList();
1067 }
1068 return parceledList.getList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001069 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001070 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001071 }
1072 }
1073
Svet Ganov2acf0632015-11-24 19:10:59 -08001074 /** @hide */
1075 @SuppressWarnings("unchecked")
1076 @Override
Svetoslav Ganov096d3042017-01-30 16:34:13 -08001077 public List<InstantAppInfo> getInstantApps() {
Svet Ganov2acf0632015-11-24 19:10:59 -08001078 try {
Jeff Sharkeyc59a5e72018-06-21 19:14:58 -06001079 ParceledListSlice<InstantAppInfo> slice = mPM.getInstantApps(getUserId());
Svet Ganov2acf0632015-11-24 19:10:59 -08001080 if (slice != null) {
1081 return slice.getList();
1082 }
1083 return Collections.emptyList();
1084 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001085 throw e.rethrowFromSystemServer();
Svet Ganov2acf0632015-11-24 19:10:59 -08001086 }
1087 }
1088
1089 /** @hide */
1090 @Override
Svetoslav Ganov096d3042017-01-30 16:34:13 -08001091 public Drawable getInstantAppIcon(String packageName) {
Svet Ganov2acf0632015-11-24 19:10:59 -08001092 try {
Jeff Sharkeyc59a5e72018-06-21 19:14:58 -06001093 Bitmap bitmap = mPM.getInstantAppIcon(packageName, getUserId());
Svet Ganov2acf0632015-11-24 19:10:59 -08001094 if (bitmap != null) {
1095 return new BitmapDrawable(null, bitmap);
1096 }
1097 return null;
1098 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001099 throw e.rethrowFromSystemServer();
Svet Ganov2acf0632015-11-24 19:10:59 -08001100 }
1101 }
1102
1103 @Override
Svetoslav Ganov096d3042017-01-30 16:34:13 -08001104 public boolean isInstantApp() {
David Christie31a16552017-03-01 15:08:45 -08001105 return isInstantApp(mContext.getPackageName());
1106 }
1107
1108 @Override
1109 public boolean isInstantApp(String packageName) {
Svet Ganov2acf0632015-11-24 19:10:59 -08001110 try {
Jeff Sharkeyc59a5e72018-06-21 19:14:58 -06001111 return mPM.isInstantApp(packageName, getUserId());
Svet Ganov2acf0632015-11-24 19:10:59 -08001112 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001113 throw e.rethrowFromSystemServer();
Svet Ganov2acf0632015-11-24 19:10:59 -08001114 }
Svet Ganov2acf0632015-11-24 19:10:59 -08001115 }
1116
Svetoslav Ganov345ffa52017-04-18 16:08:41 -07001117 public int getInstantAppCookieMaxBytes() {
Svet Ganov2acf0632015-11-24 19:10:59 -08001118 return Settings.Global.getInt(mContext.getContentResolver(),
1119 Settings.Global.EPHEMERAL_COOKIE_MAX_SIZE_BYTES,
1120 DEFAULT_EPHEMERAL_COOKIE_MAX_SIZE_BYTES);
1121 }
1122
1123 @Override
Svetoslav Ganov345ffa52017-04-18 16:08:41 -07001124 public int getInstantAppCookieMaxSize() {
1125 return getInstantAppCookieMaxBytes();
1126 }
1127
1128 @Override
Svetoslav Ganov096d3042017-01-30 16:34:13 -08001129 public @NonNull byte[] getInstantAppCookie() {
Svet Ganov2acf0632015-11-24 19:10:59 -08001130 try {
Jeff Sharkeyc59a5e72018-06-21 19:14:58 -06001131 final byte[] cookie = mPM.getInstantAppCookie(mContext.getPackageName(), getUserId());
Svet Ganov2acf0632015-11-24 19:10:59 -08001132 if (cookie != null) {
1133 return cookie;
Jeff Sharkey27b2e692016-02-25 17:40:12 -07001134 } else {
1135 return EmptyArray.BYTE;
Svet Ganov2acf0632015-11-24 19:10:59 -08001136 }
1137 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001138 throw e.rethrowFromSystemServer();
Svet Ganov2acf0632015-11-24 19:10:59 -08001139 }
Svet Ganov2acf0632015-11-24 19:10:59 -08001140 }
1141
1142 @Override
Svetoslav Ganov345ffa52017-04-18 16:08:41 -07001143 public void clearInstantAppCookie() {
1144 updateInstantAppCookie(null);
1145 }
1146
1147 @Override
1148 public void updateInstantAppCookie(@NonNull byte[] cookie) {
1149 if (cookie != null && cookie.length > getInstantAppCookieMaxBytes()) {
1150 throw new IllegalArgumentException("instant cookie longer than "
1151 + getInstantAppCookieMaxBytes());
1152 }
1153 try {
Jeff Sharkeyc59a5e72018-06-21 19:14:58 -06001154 mPM.setInstantAppCookie(mContext.getPackageName(), cookie, getUserId());
Svetoslav Ganov345ffa52017-04-18 16:08:41 -07001155 } catch (RemoteException e) {
1156 throw e.rethrowFromSystemServer();
1157 }
1158 }
1159
Mathew Inwood3a75f262019-06-27 12:47:38 +01001160 @UnsupportedAppUsage
Svetoslav Ganov345ffa52017-04-18 16:08:41 -07001161 @Override
Svetoslav Ganov096d3042017-01-30 16:34:13 -08001162 public boolean setInstantAppCookie(@NonNull byte[] cookie) {
Svet Ganov2acf0632015-11-24 19:10:59 -08001163 try {
Jeff Sharkeyc59a5e72018-06-21 19:14:58 -06001164 return mPM.setInstantAppCookie(mContext.getPackageName(), cookie, getUserId());
Svet Ganov2acf0632015-11-24 19:10:59 -08001165 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001166 throw e.rethrowFromSystemServer();
Svet Ganov2acf0632015-11-24 19:10:59 -08001167 }
Svet Ganov2acf0632015-11-24 19:10:59 -08001168 }
1169
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001170 @Override
1171 public ResolveInfo resolveActivity(Intent intent, int flags) {
Jeff Sharkeyc59a5e72018-06-21 19:14:58 -06001172 return resolveActivityAsUser(intent, flags, getUserId());
Svetoslav Ganov58d37b52012-09-18 12:04:19 -07001173 }
1174
1175 @Override
1176 public ResolveInfo resolveActivityAsUser(Intent intent, int flags, int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001177 try {
1178 return mPM.resolveIntent(
1179 intent,
1180 intent.resolveTypeIfNeeded(mContext.getContentResolver()),
Jeff Sharkeyc59a5e72018-06-21 19:14:58 -06001181 updateFlagsForComponent(flags, userId, intent),
Svetoslav Ganov58d37b52012-09-18 12:04:19 -07001182 userId);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001183 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001184 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001185 }
1186 }
1187
1188 @Override
1189 public List<ResolveInfo> queryIntentActivities(Intent intent,
1190 int flags) {
Jeff Sharkeyc59a5e72018-06-21 19:14:58 -06001191 return queryIntentActivitiesAsUser(intent, flags, getUserId());
Amith Yamasani151ec4c2012-09-07 19:25:16 -07001192 }
1193
1194 /** @hide Same as above but for a specific user */
1195 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001196 @SuppressWarnings("unchecked")
Svetoslav Ganov58d37b52012-09-18 12:04:19 -07001197 public List<ResolveInfo> queryIntentActivitiesAsUser(Intent intent,
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001198 int flags, int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001199 try {
Jeff Sharkeyc59a5e72018-06-21 19:14:58 -06001200 ParceledListSlice<ResolveInfo> parceledList = mPM.queryIntentActivities(
1201 intent,
1202 intent.resolveTypeIfNeeded(mContext.getContentResolver()),
1203 updateFlagsForComponent(flags, userId, intent),
1204 userId);
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001205 if (parceledList == null) {
1206 return Collections.emptyList();
1207 }
1208 return parceledList.getList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001209 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001210 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001211 }
1212 }
1213
1214 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001215 @SuppressWarnings("unchecked")
Jeff Sharkeyc59a5e72018-06-21 19:14:58 -06001216 public List<ResolveInfo> queryIntentActivityOptions(ComponentName caller, Intent[] specifics,
1217 Intent intent, int flags) {
1218 final int userId = getUserId();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001219 final ContentResolver resolver = mContext.getContentResolver();
1220
1221 String[] specificTypes = null;
1222 if (specifics != null) {
1223 final int N = specifics.length;
1224 for (int i=0; i<N; i++) {
1225 Intent sp = specifics[i];
1226 if (sp != null) {
1227 String t = sp.resolveTypeIfNeeded(resolver);
1228 if (t != null) {
1229 if (specificTypes == null) {
1230 specificTypes = new String[N];
1231 }
1232 specificTypes[i] = t;
1233 }
1234 }
1235 }
1236 }
1237
1238 try {
Jeff Sharkeyc59a5e72018-06-21 19:14:58 -06001239 ParceledListSlice<ResolveInfo> parceledList = mPM.queryIntentActivityOptions(
1240 caller,
1241 specifics,
1242 specificTypes,
1243 intent,
1244 intent.resolveTypeIfNeeded(resolver),
1245 updateFlagsForComponent(flags, userId, intent),
1246 userId);
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001247 if (parceledList == null) {
1248 return Collections.emptyList();
1249 }
1250 return parceledList.getList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001251 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001252 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001253 }
1254 }
1255
Amith Yamasanif203aee2012-08-29 18:41:53 -07001256 /**
1257 * @hide
1258 */
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001259 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001260 @SuppressWarnings("unchecked")
Jeff Sharkeye06b4d12016-01-06 14:51:50 -07001261 public List<ResolveInfo> queryBroadcastReceiversAsUser(Intent intent, int flags, int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001262 try {
Jeff Sharkeyc59a5e72018-06-21 19:14:58 -06001263 ParceledListSlice<ResolveInfo> parceledList = mPM.queryIntentReceivers(
1264 intent,
1265 intent.resolveTypeIfNeeded(mContext.getContentResolver()),
1266 updateFlagsForComponent(flags, userId, intent),
1267 userId);
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001268 if (parceledList == null) {
1269 return Collections.emptyList();
1270 }
1271 return parceledList.getList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001272 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001273 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001274 }
1275 }
1276
1277 @Override
Amith Yamasanif203aee2012-08-29 18:41:53 -07001278 public List<ResolveInfo> queryBroadcastReceivers(Intent intent, int flags) {
Jeff Sharkeyc59a5e72018-06-21 19:14:58 -06001279 return queryBroadcastReceiversAsUser(intent, flags, getUserId());
Amith Yamasanif203aee2012-08-29 18:41:53 -07001280 }
1281
1282 @Override
Philip P. Moltmann18e3eb82018-03-09 16:55:55 -08001283 public ResolveInfo resolveServiceAsUser(Intent intent, @ResolveInfoFlags int flags,
1284 @UserIdInt int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001285 try {
1286 return mPM.resolveService(
1287 intent,
1288 intent.resolveTypeIfNeeded(mContext.getContentResolver()),
Jeff Sharkeyc59a5e72018-06-21 19:14:58 -06001289 updateFlagsForComponent(flags, userId, intent),
Philip P. Moltmann18e3eb82018-03-09 16:55:55 -08001290 userId);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001291 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001292 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001293 }
1294 }
1295
1296 @Override
Philip P. Moltmann18e3eb82018-03-09 16:55:55 -08001297 public ResolveInfo resolveService(Intent intent, int flags) {
Jeff Sharkeyc59a5e72018-06-21 19:14:58 -06001298 return resolveServiceAsUser(intent, flags, getUserId());
Philip P. Moltmann18e3eb82018-03-09 16:55:55 -08001299 }
1300
1301 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001302 @SuppressWarnings("unchecked")
Svetoslav Ganov58d37b52012-09-18 12:04:19 -07001303 public List<ResolveInfo> queryIntentServicesAsUser(Intent intent, int flags, int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001304 try {
Jeff Sharkeyc59a5e72018-06-21 19:14:58 -06001305 ParceledListSlice<ResolveInfo> parceledList = mPM.queryIntentServices(
1306 intent,
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001307 intent.resolveTypeIfNeeded(mContext.getContentResolver()),
Jeff Sharkeyc59a5e72018-06-21 19:14:58 -06001308 updateFlagsForComponent(flags, userId, intent),
1309 userId);
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001310 if (parceledList == null) {
1311 return Collections.emptyList();
1312 }
1313 return parceledList.getList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001314 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001315 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001316 }
1317 }
1318
1319 @Override
Svetoslav Ganov58d37b52012-09-18 12:04:19 -07001320 public List<ResolveInfo> queryIntentServices(Intent intent, int flags) {
Jeff Sharkeyc59a5e72018-06-21 19:14:58 -06001321 return queryIntentServicesAsUser(intent, flags, getUserId());
Svetoslav Ganov58d37b52012-09-18 12:04:19 -07001322 }
1323
1324 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001325 @SuppressWarnings("unchecked")
Jeff Sharkey85f5f812013-10-07 10:16:12 -07001326 public List<ResolveInfo> queryIntentContentProvidersAsUser(
1327 Intent intent, int flags, int userId) {
1328 try {
Jeff Sharkeyc59a5e72018-06-21 19:14:58 -06001329 ParceledListSlice<ResolveInfo> parceledList = mPM.queryIntentContentProviders(
1330 intent,
1331 intent.resolveTypeIfNeeded(mContext.getContentResolver()),
1332 updateFlagsForComponent(flags, userId, intent),
1333 userId);
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001334 if (parceledList == null) {
1335 return Collections.emptyList();
1336 }
1337 return parceledList.getList();
Jeff Sharkey85f5f812013-10-07 10:16:12 -07001338 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001339 throw e.rethrowFromSystemServer();
Jeff Sharkey85f5f812013-10-07 10:16:12 -07001340 }
1341 }
1342
1343 @Override
1344 public List<ResolveInfo> queryIntentContentProviders(Intent intent, int flags) {
Jeff Sharkeyc59a5e72018-06-21 19:14:58 -06001345 return queryIntentContentProvidersAsUser(intent, flags, getUserId());
Jeff Sharkey85f5f812013-10-07 10:16:12 -07001346 }
1347
1348 @Override
Alexandra Gherghina0363c3e2014-06-23 13:34:59 +01001349 public ProviderInfo resolveContentProvider(String name, int flags) {
Jeff Sharkeyc59a5e72018-06-21 19:14:58 -06001350 return resolveContentProviderAsUser(name, flags, getUserId());
Alexandra Gherghina0363c3e2014-06-23 13:34:59 +01001351 }
1352
1353 /** @hide **/
1354 @Override
1355 public ProviderInfo resolveContentProviderAsUser(String name, int flags, int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001356 try {
Jeff Sharkeyc59a5e72018-06-21 19:14:58 -06001357 return mPM.resolveContentProvider(name,
1358 updateFlagsForComponent(flags, userId, null), userId);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001359 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001360 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001361 }
1362 }
1363
1364 @Override
1365 public List<ProviderInfo> queryContentProviders(String processName,
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001366 int uid, int flags) {
Makoto Onuki32757292017-02-22 14:36:59 -08001367 return queryContentProviders(processName, uid, flags, null);
1368 }
1369
1370 @Override
1371 @SuppressWarnings("unchecked")
1372 public List<ProviderInfo> queryContentProviders(String processName,
1373 int uid, int flags, String metaDataKey) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001374 try {
Jeff Sharkeyc59a5e72018-06-21 19:14:58 -06001375 ParceledListSlice<ProviderInfo> slice = mPM.queryContentProviders(processName, uid,
1376 updateFlagsForComponent(flags, UserHandle.getUserId(uid), null), metaDataKey);
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001377 return slice != null ? slice.getList() : Collections.<ProviderInfo>emptyList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001378 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001379 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001380 }
1381 }
1382
1383 @Override
1384 public InstrumentationInfo getInstrumentationInfo(
1385 ComponentName className, int flags)
1386 throws NameNotFoundException {
1387 try {
1388 InstrumentationInfo ii = mPM.getInstrumentationInfo(
1389 className, flags);
1390 if (ii != null) {
1391 return ii;
1392 }
1393 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001394 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001395 }
1396
1397 throw new NameNotFoundException(className.toString());
1398 }
1399
1400 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001401 @SuppressWarnings("unchecked")
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001402 public List<InstrumentationInfo> queryInstrumentation(
1403 String targetPackage, int flags) {
1404 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001405 ParceledListSlice<InstrumentationInfo> parceledList =
1406 mPM.queryInstrumentation(targetPackage, flags);
1407 if (parceledList == null) {
1408 return Collections.emptyList();
1409 }
1410 return parceledList.getList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001411 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001412 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001413 }
1414 }
1415
Alan Viveretteecd585a2015-04-13 10:32:51 -07001416 @Nullable
1417 @Override
1418 public Drawable getDrawable(String packageName, @DrawableRes int resId,
1419 @Nullable ApplicationInfo appInfo) {
1420 final ResourceName name = new ResourceName(packageName, resId);
1421 final Drawable cachedIcon = getCachedIcon(name);
1422 if (cachedIcon != null) {
1423 return cachedIcon;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001424 }
Alan Viveretteecd585a2015-04-13 10:32:51 -07001425
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001426 if (appInfo == null) {
1427 try {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001428 appInfo = getApplicationInfo(packageName, sDefaultFlags);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001429 } catch (NameNotFoundException e) {
1430 return null;
1431 }
1432 }
Alan Viveretteecd585a2015-04-13 10:32:51 -07001433
1434 if (resId != 0) {
1435 try {
1436 final Resources r = getResourcesForApplication(appInfo);
1437 final Drawable dr = r.getDrawable(resId, null);
1438 if (dr != null) {
1439 putCachedIcon(name, dr);
1440 }
1441
1442 if (false) {
1443 RuntimeException e = new RuntimeException("here");
1444 e.fillInStackTrace();
1445 Log.w(TAG, "Getting drawable 0x" + Integer.toHexString(resId)
1446 + " from package " + packageName
1447 + ": app scale=" + r.getCompatibilityInfo().applicationScale
1448 + ", caller scale=" + mContext.getResources()
1449 .getCompatibilityInfo().applicationScale,
1450 e);
1451 }
Ricky Wai3ce46252015-04-15 16:12:22 +01001452 if (DEBUG_ICONS) {
Alan Viveretteecd585a2015-04-13 10:32:51 -07001453 Log.v(TAG, "Getting drawable 0x"
1454 + Integer.toHexString(resId) + " from " + r
1455 + ": " + dr);
Ricky Wai3ce46252015-04-15 16:12:22 +01001456 }
1457 return dr;
Alan Viveretteecd585a2015-04-13 10:32:51 -07001458 } catch (NameNotFoundException e) {
1459 Log.w("PackageManager", "Failure retrieving resources for "
1460 + appInfo.packageName);
1461 } catch (Resources.NotFoundException e) {
1462 Log.w("PackageManager", "Failure retrieving resources for "
1463 + appInfo.packageName + ": " + e.getMessage());
1464 } catch (Exception e) {
1465 // If an exception was thrown, fall through to return
1466 // default icon.
1467 Log.w("PackageManager", "Failure retrieving icon 0x"
1468 + Integer.toHexString(resId) + " in package "
1469 + packageName, e);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001470 }
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001471 }
Alan Viveretteecd585a2015-04-13 10:32:51 -07001472
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001473 return null;
1474 }
1475
1476 @Override public Drawable getActivityIcon(ComponentName activityName)
1477 throws NameNotFoundException {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001478 return getActivityInfo(activityName, sDefaultFlags).loadIcon(this);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001479 }
1480
1481 @Override public Drawable getActivityIcon(Intent intent)
1482 throws NameNotFoundException {
1483 if (intent.getComponent() != null) {
1484 return getActivityIcon(intent.getComponent());
1485 }
1486
Peter Wang09014f12020-01-24 08:15:38 +08001487 ResolveInfo info = resolveActivity(intent, MATCH_DEFAULT_ONLY);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001488 if (info != null) {
1489 return info.activityInfo.loadIcon(this);
1490 }
1491
Romain Guy39fe17c2011-11-30 10:34:07 -08001492 throw new NameNotFoundException(intent.toUri(0));
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001493 }
1494
1495 @Override public Drawable getDefaultActivityIcon() {
Hyunyoung Song013f0622019-03-12 14:17:30 -07001496 return mContext.getDrawable(com.android.internal.R.drawable.sym_def_app_icon);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001497 }
1498
1499 @Override public Drawable getApplicationIcon(ApplicationInfo info) {
1500 return info.loadIcon(this);
1501 }
1502
1503 @Override public Drawable getApplicationIcon(String packageName)
1504 throws NameNotFoundException {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001505 return getApplicationIcon(getApplicationInfo(packageName, sDefaultFlags));
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001506 }
1507
1508 @Override
Jose Limaf78e3122014-03-06 12:13:15 -08001509 public Drawable getActivityBanner(ComponentName activityName)
1510 throws NameNotFoundException {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001511 return getActivityInfo(activityName, sDefaultFlags).loadBanner(this);
Jose Limaf78e3122014-03-06 12:13:15 -08001512 }
1513
1514 @Override
1515 public Drawable getActivityBanner(Intent intent)
1516 throws NameNotFoundException {
1517 if (intent.getComponent() != null) {
1518 return getActivityBanner(intent.getComponent());
1519 }
1520
1521 ResolveInfo info = resolveActivity(
Peter Wang09014f12020-01-24 08:15:38 +08001522 intent, MATCH_DEFAULT_ONLY);
Jose Limaf78e3122014-03-06 12:13:15 -08001523 if (info != null) {
1524 return info.activityInfo.loadBanner(this);
1525 }
1526
1527 throw new NameNotFoundException(intent.toUri(0));
1528 }
1529
1530 @Override
1531 public Drawable getApplicationBanner(ApplicationInfo info) {
1532 return info.loadBanner(this);
1533 }
1534
1535 @Override
1536 public Drawable getApplicationBanner(String packageName)
1537 throws NameNotFoundException {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001538 return getApplicationBanner(getApplicationInfo(packageName, sDefaultFlags));
Jose Limaf78e3122014-03-06 12:13:15 -08001539 }
1540
1541 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001542 public Drawable getActivityLogo(ComponentName activityName)
1543 throws NameNotFoundException {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001544 return getActivityInfo(activityName, sDefaultFlags).loadLogo(this);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001545 }
1546
1547 @Override
1548 public Drawable getActivityLogo(Intent intent)
1549 throws NameNotFoundException {
1550 if (intent.getComponent() != null) {
1551 return getActivityLogo(intent.getComponent());
1552 }
1553
Peter Wang09014f12020-01-24 08:15:38 +08001554 ResolveInfo info = resolveActivity(intent, MATCH_DEFAULT_ONLY);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001555 if (info != null) {
1556 return info.activityInfo.loadLogo(this);
1557 }
1558
1559 throw new NameNotFoundException(intent.toUri(0));
1560 }
1561
1562 @Override
1563 public Drawable getApplicationLogo(ApplicationInfo info) {
1564 return info.loadLogo(this);
1565 }
1566
1567 @Override
1568 public Drawable getApplicationLogo(String packageName)
1569 throws NameNotFoundException {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001570 return getApplicationLogo(getApplicationInfo(packageName, sDefaultFlags));
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001571 }
1572
Svetoslavc7d62f02014-09-04 15:39:54 -07001573 @Override
1574 public Drawable getUserBadgedIcon(Drawable icon, UserHandle user) {
Bookatz029832a2019-10-04 16:50:22 -07001575 if (!hasUserBadge(user.getIdentifier())) {
Svetoslavc7d62f02014-09-04 15:39:54 -07001576 return icon;
1577 }
Sunny Goyalbab30752017-04-12 15:36:42 -07001578 Drawable badge = new LauncherIcons(mContext).getBadgeDrawable(
Bookatz029832a2019-10-04 16:50:22 -07001579 getUserManager().getUserIconBadgeResId(user.getIdentifier()),
Beverly2b4306a2020-04-27 16:15:15 -04001580 getUserBadgeColor(user, false));
Kenny Guy02c89902016-11-15 19:36:38 +00001581 return getBadgedDrawable(icon, badge, null, true);
Svetoslavc7d62f02014-09-04 15:39:54 -07001582 }
1583
1584 @Override
1585 public Drawable getUserBadgedDrawableForDensity(Drawable drawable, UserHandle user,
1586 Rect badgeLocation, int badgeDensity) {
1587 Drawable badgeDrawable = getUserBadgeForDensity(user, badgeDensity);
1588 if (badgeDrawable == null) {
1589 return drawable;
1590 }
1591 return getBadgedDrawable(drawable, badgeDrawable, badgeLocation, true);
1592 }
1593
Beverly2b4306a2020-04-27 16:15:15 -04001594 /**
1595 * Returns the color of the user's actual badge (not the badge's shadow).
1596 * @param checkTheme whether to check the theme to determine the badge color. This should be
1597 * true if the background is determined by the theme. Otherwise, if
1598 * checkTheme is false, returns the color assuming a light background.
1599 */
1600 private int getUserBadgeColor(UserHandle user, boolean checkTheme) {
1601 if (checkTheme && mContext.getResources().getConfiguration().isNightModeActive()) {
1602 return getUserManager().getUserBadgeDarkColor(user.getIdentifier());
1603 }
Bookatz029832a2019-10-04 16:50:22 -07001604 return getUserManager().getUserBadgeColor(user.getIdentifier());
Kenny Guy02c89902016-11-15 19:36:38 +00001605 }
1606
Svetoslavc7d62f02014-09-04 15:39:54 -07001607 @Override
1608 public Drawable getUserBadgeForDensity(UserHandle user, int density) {
Bookatz029832a2019-10-04 16:50:22 -07001609 // This is part of the shadow, not the main color, and is not actually corp-specific.
1610 Drawable badgeColor = getProfileIconForDensity(user,
Kenny Guy02c89902016-11-15 19:36:38 +00001611 com.android.internal.R.drawable.ic_corp_badge_color, density);
1612 if (badgeColor == null) {
1613 return null;
1614 }
Kenny Guy02c89902016-11-15 19:36:38 +00001615 Drawable badgeForeground = getDrawableForDensity(
Bookatz029832a2019-10-04 16:50:22 -07001616 getUserManager().getUserBadgeResId(user.getIdentifier()), density);
Beverly2b4306a2020-04-27 16:15:15 -04001617 badgeForeground.setTint(getUserBadgeColor(user, false));
Tony Make21a1d02018-02-16 11:46:58 +00001618 Drawable badge = new LayerDrawable(new Drawable[] {badgeColor, badgeForeground });
Kenny Guy02c89902016-11-15 19:36:38 +00001619 return badge;
Selim Cineke6ff9462016-01-15 15:07:06 -08001620 }
1621
Beverly2b4306a2020-04-27 16:15:15 -04001622 /**
1623 * Returns the badge color based on whether device has dark theme enabled or not.
1624 */
Selim Cineke6ff9462016-01-15 15:07:06 -08001625 @Override
1626 public Drawable getUserBadgeForDensityNoBackground(UserHandle user, int density) {
Adam Bookatz9b6d51e2020-03-31 12:26:47 -07001627 if (!hasUserBadge(user.getIdentifier())) {
1628 return null;
1629 }
1630 Drawable badge = getDrawableForDensity(
Bookatz029832a2019-10-04 16:50:22 -07001631 getUserManager().getUserBadgeNoBackgroundResId(user.getIdentifier()), density);
Kenny Guy02c89902016-11-15 19:36:38 +00001632 if (badge != null) {
Beverly2b4306a2020-04-27 16:15:15 -04001633 badge.setTint(getUserBadgeColor(user, true));
Kenny Guy02c89902016-11-15 19:36:38 +00001634 }
1635 return badge;
Selim Cineke6ff9462016-01-15 15:07:06 -08001636 }
1637
Vadim Tryshev66ae66a2016-02-18 15:41:21 -08001638 private Drawable getDrawableForDensity(int drawableId, int density) {
1639 if (density <= 0) {
1640 density = mContext.getResources().getDisplayMetrics().densityDpi;
1641 }
Hyunyoung Song013f0622019-03-12 14:17:30 -07001642 return mContext.getResources().getDrawableForDensity(drawableId, density);
Vadim Tryshev66ae66a2016-02-18 15:41:21 -08001643 }
1644
Bookatz029832a2019-10-04 16:50:22 -07001645 private Drawable getProfileIconForDensity(UserHandle user, int drawableId, int density) {
1646 if (hasUserBadge(user.getIdentifier())) {
Vadim Tryshev66ae66a2016-02-18 15:41:21 -08001647 return getDrawableForDensity(drawableId, density);
Svetoslavc7d62f02014-09-04 15:39:54 -07001648 }
1649 return null;
1650 }
1651
1652 @Override
1653 public CharSequence getUserBadgedLabel(CharSequence label, UserHandle user) {
Bookatz029832a2019-10-04 16:50:22 -07001654 return getUserManager().getBadgedLabelForUser(label, user);
Svetoslavc7d62f02014-09-04 15:39:54 -07001655 }
1656
Alan Viveretteecd585a2015-04-13 10:32:51 -07001657 @Override
1658 public Resources getResourcesForActivity(ComponentName activityName)
1659 throws NameNotFoundException {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001660 return getResourcesForApplication(
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001661 getActivityInfo(activityName, sDefaultFlags).applicationInfo);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001662 }
1663
Alan Viveretteecd585a2015-04-13 10:32:51 -07001664 @Override
1665 public Resources getResourcesForApplication(@NonNull ApplicationInfo app)
1666 throws NameNotFoundException {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001667 if (app.packageName.equals("system")) {
Adam Lesinskia82b6262017-03-21 16:56:17 -07001668 return mContext.mMainThread.getSystemUiContext().getResources();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001669 }
Jeff Sharkey8a4c9722014-06-16 13:48:42 -07001670 final boolean sameUid = (app.uid == Process.myUid());
Adam Lesinski53fafdf2016-08-03 13:36:39 -07001671 final Resources r = mContext.mMainThread.getTopLevelResources(
Adam Lesinskic82f28a2016-06-08 17:19:09 -07001672 sameUid ? app.sourceDir : app.publicSourceDir,
1673 sameUid ? app.splitSourceDirs : app.splitPublicSourceDirs,
1674 app.resourceDirs, app.sharedLibraryFiles, Display.DEFAULT_DISPLAY,
Todd Kennedy233a0b12018-01-29 20:30:24 +00001675 mContext.mPackageInfo);
Adam Lesinski53fafdf2016-08-03 13:36:39 -07001676 if (r != null) {
1677 return r;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001678 }
Adam Lesinski53fafdf2016-08-03 13:36:39 -07001679 throw new NameNotFoundException("Unable to open " + app.publicSourceDir);
1680
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001681 }
1682
Alan Viveretteecd585a2015-04-13 10:32:51 -07001683 @Override
1684 public Resources getResourcesForApplication(String appPackageName)
1685 throws NameNotFoundException {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001686 return getResourcesForApplication(
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001687 getApplicationInfo(appPackageName, sDefaultFlags));
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001688 }
1689
Amith Yamasani98edc952012-09-25 14:09:27 -07001690 /** @hide */
1691 @Override
1692 public Resources getResourcesForApplicationAsUser(String appPackageName, int userId)
1693 throws NameNotFoundException {
Jeff Sharkeyded653b2012-09-27 19:09:24 -07001694 if (userId < 0) {
1695 throw new IllegalArgumentException(
1696 "Call does not support special user #" + userId);
1697 }
1698 if ("system".equals(appPackageName)) {
Adam Lesinskia82b6262017-03-21 16:56:17 -07001699 return mContext.mMainThread.getSystemUiContext().getResources();
Jeff Sharkeyded653b2012-09-27 19:09:24 -07001700 }
Amith Yamasani98edc952012-09-25 14:09:27 -07001701 try {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001702 ApplicationInfo ai = mPM.getApplicationInfo(appPackageName, sDefaultFlags, userId);
Amith Yamasani98edc952012-09-25 14:09:27 -07001703 if (ai != null) {
1704 return getResourcesForApplication(ai);
1705 }
1706 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001707 throw e.rethrowFromSystemServer();
Amith Yamasani98edc952012-09-25 14:09:27 -07001708 }
1709 throw new NameNotFoundException("Package " + appPackageName + " doesn't exist");
1710 }
1711
Jeff Sharkeycd654482016-01-08 17:42:11 -07001712 volatile int mCachedSafeMode = -1;
1713
1714 @Override
1715 public boolean isSafeMode() {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001716 try {
1717 if (mCachedSafeMode < 0) {
1718 mCachedSafeMode = mPM.isSafeMode() ? 1 : 0;
1719 }
1720 return mCachedSafeMode != 0;
1721 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001722 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001723 }
1724 }
1725
Svetoslavf7c06eb2015-06-10 18:43:22 -07001726 @Override
1727 public void addOnPermissionsChangeListener(OnPermissionsChangedListener listener) {
1728 synchronized (mPermissionListeners) {
1729 if (mPermissionListeners.get(listener) != null) {
1730 return;
1731 }
1732 OnPermissionsChangeListenerDelegate delegate =
1733 new OnPermissionsChangeListenerDelegate(listener, Looper.getMainLooper());
1734 try {
Todd Kennedy7e3dd3a2019-07-08 10:34:29 -07001735 mPermissionManager.addOnPermissionsChangeListener(delegate);
Svetoslavf7c06eb2015-06-10 18:43:22 -07001736 mPermissionListeners.put(listener, delegate);
1737 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001738 throw e.rethrowFromSystemServer();
Svetoslavf7c06eb2015-06-10 18:43:22 -07001739 }
1740 }
1741 }
1742
1743 @Override
1744 public void removeOnPermissionsChangeListener(OnPermissionsChangedListener listener) {
1745 synchronized (mPermissionListeners) {
1746 IOnPermissionsChangeListener delegate = mPermissionListeners.get(listener);
1747 if (delegate != null) {
1748 try {
Todd Kennedy7e3dd3a2019-07-08 10:34:29 -07001749 mPermissionManager.removeOnPermissionsChangeListener(delegate);
Svetoslavf7c06eb2015-06-10 18:43:22 -07001750 mPermissionListeners.remove(listener);
1751 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001752 throw e.rethrowFromSystemServer();
Svetoslavf7c06eb2015-06-10 18:43:22 -07001753 }
1754 }
1755 }
1756 }
1757
Mathew Inwood61e8ae62018-08-14 14:17:44 +01001758 @UnsupportedAppUsage
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001759 static void configurationChanged() {
1760 synchronized (sSync) {
1761 sIconCache.clear();
1762 sStringCache.clear();
1763 }
1764 }
1765
Mathew Inwood61e8ae62018-08-14 14:17:44 +01001766 @UnsupportedAppUsage
Todd Kennedyd9d985b2020-01-17 06:08:05 -08001767 protected ApplicationPackageManager(ContextImpl context, IPackageManager pm) {
1768 this(context, pm, ActivityThread.getPermissionManager());
1769 }
1770
Todd Kennedy8f135982019-07-02 07:35:15 -07001771 protected ApplicationPackageManager(ContextImpl context, IPackageManager pm,
1772 IPermissionManager permissionManager) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001773 mContext = context;
1774 mPM = pm;
Todd Kennedy8f135982019-07-02 07:35:15 -07001775 mPermissionManager = permissionManager;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001776 }
1777
Jeff Sharkeyc59a5e72018-06-21 19:14:58 -06001778 /**
1779 * Update given flags when being used to request {@link PackageInfo}.
1780 */
1781 private int updateFlagsForPackage(int flags, int userId) {
1782 if ((flags & (GET_ACTIVITIES | GET_RECEIVERS | GET_SERVICES | GET_PROVIDERS)) != 0) {
1783 // Caller is asking for component details, so they'd better be
1784 // asking for specific Direct Boot matching behavior
1785 if ((flags & (MATCH_DIRECT_BOOT_UNAWARE
1786 | MATCH_DIRECT_BOOT_AWARE
1787 | MATCH_DIRECT_BOOT_AUTO)) == 0) {
1788 onImplicitDirectBoot(userId);
1789 }
1790 }
1791 return flags;
1792 }
1793
1794 /**
1795 * Update given flags when being used to request {@link ApplicationInfo}.
1796 */
1797 private int updateFlagsForApplication(int flags, int userId) {
1798 return updateFlagsForPackage(flags, userId);
1799 }
1800
1801 /**
1802 * Update given flags when being used to request {@link ComponentInfo}.
1803 */
1804 private int updateFlagsForComponent(int flags, int userId, Intent intent) {
1805 if (intent != null) {
1806 if ((intent.getFlags() & Intent.FLAG_DIRECT_BOOT_AUTO) != 0) {
1807 flags |= MATCH_DIRECT_BOOT_AUTO;
1808 }
1809 }
1810
1811 // Caller is asking for component details, so they'd better be
1812 // asking for specific Direct Boot matching behavior
1813 if ((flags & (MATCH_DIRECT_BOOT_UNAWARE
1814 | MATCH_DIRECT_BOOT_AWARE
1815 | MATCH_DIRECT_BOOT_AUTO)) == 0) {
1816 onImplicitDirectBoot(userId);
1817 }
1818 return flags;
1819 }
1820
1821 private void onImplicitDirectBoot(int userId) {
1822 // Only report if someone is relying on implicit behavior while the user
1823 // is locked; code running when unlocked is going to see both aware and
1824 // unaware components.
1825 if (StrictMode.vmImplicitDirectBootEnabled()) {
1826 // We can cache the unlocked state for the userId we're running as,
1827 // since any relocking of that user will always result in our
1828 // process being killed to release any CE FDs we're holding onto.
1829 if (userId == UserHandle.myUserId()) {
1830 if (mUserUnlocked) {
1831 return;
1832 } else if (mContext.getSystemService(UserManager.class)
1833 .isUserUnlockingOrUnlocked(userId)) {
1834 mUserUnlocked = true;
1835 } else {
1836 StrictMode.onImplicitDirectBoot();
1837 }
1838 } else if (!mContext.getSystemService(UserManager.class)
1839 .isUserUnlockingOrUnlocked(userId)) {
1840 StrictMode.onImplicitDirectBoot();
1841 }
1842 }
1843 }
1844
Alan Viveretteecd585a2015-04-13 10:32:51 -07001845 @Nullable
1846 private Drawable getCachedIcon(@NonNull ResourceName name) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001847 synchronized (sSync) {
Alan Viveretteecd585a2015-04-13 10:32:51 -07001848 final WeakReference<Drawable.ConstantState> wr = sIconCache.get(name);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001849 if (DEBUG_ICONS) Log.v(TAG, "Get cached weak drawable ref for "
1850 + name + ": " + wr);
1851 if (wr != null) { // we have the activity
Alan Viveretteecd585a2015-04-13 10:32:51 -07001852 final Drawable.ConstantState state = wr.get();
Romain Guy39fe17c2011-11-30 10:34:07 -08001853 if (state != null) {
1854 if (DEBUG_ICONS) {
1855 Log.v(TAG, "Get cached drawable state for " + name + ": " + state);
1856 }
1857 // Note: It's okay here to not use the newDrawable(Resources) variant
1858 // of the API. The ConstantState comes from a drawable that was
1859 // originally created by passing the proper app Resources instance
1860 // which means the state should already contain the proper
1861 // resources specific information (like density.) See
1862 // BitmapDrawable.BitmapState for instance.
1863 return state.newDrawable();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001864 }
1865 // our entry has been purged
1866 sIconCache.remove(name);
1867 }
1868 }
1869 return null;
1870 }
1871
Alan Viveretteecd585a2015-04-13 10:32:51 -07001872 private void putCachedIcon(@NonNull ResourceName name, @NonNull Drawable dr) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001873 synchronized (sSync) {
Alan Viveretteecd585a2015-04-13 10:32:51 -07001874 sIconCache.put(name, new WeakReference<>(dr.getConstantState()));
Romain Guy39fe17c2011-11-30 10:34:07 -08001875 if (DEBUG_ICONS) Log.v(TAG, "Added cached drawable state for " + name + ": " + dr);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001876 }
1877 }
1878
Romain Guy39fe17c2011-11-30 10:34:07 -08001879 static void handlePackageBroadcast(int cmd, String[] pkgList, boolean hasPkgInfo) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001880 boolean immediateGc = false;
Sudheer Shankacc6418f2016-10-13 12:03:44 -07001881 if (cmd == ApplicationThreadConstants.EXTERNAL_STORAGE_UNAVAILABLE) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001882 immediateGc = true;
1883 }
1884 if (pkgList != null && (pkgList.length > 0)) {
1885 boolean needCleanup = false;
1886 for (String ssp : pkgList) {
1887 synchronized (sSync) {
Dianne Hackbornadd005c2013-07-17 18:43:12 -07001888 for (int i=sIconCache.size()-1; i>=0; i--) {
1889 ResourceName nm = sIconCache.keyAt(i);
1890 if (nm.packageName.equals(ssp)) {
1891 //Log.i(TAG, "Removing cached drawable for " + nm);
1892 sIconCache.removeAt(i);
1893 needCleanup = true;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001894 }
1895 }
Dianne Hackbornadd005c2013-07-17 18:43:12 -07001896 for (int i=sStringCache.size()-1; i>=0; i--) {
1897 ResourceName nm = sStringCache.keyAt(i);
1898 if (nm.packageName.equals(ssp)) {
1899 //Log.i(TAG, "Removing cached string for " + nm);
1900 sStringCache.removeAt(i);
1901 needCleanup = true;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001902 }
1903 }
1904 }
1905 }
1906 if (needCleanup || hasPkgInfo) {
1907 if (immediateGc) {
1908 // Schedule an immediate gc.
1909 Runtime.getRuntime().gc();
1910 } else {
1911 ActivityThread.currentActivityThread().scheduleGcIdler();
1912 }
1913 }
1914 }
1915 }
1916
1917 private static final class ResourceName {
1918 final String packageName;
1919 final int iconId;
1920
1921 ResourceName(String _packageName, int _iconId) {
1922 packageName = _packageName;
1923 iconId = _iconId;
1924 }
1925
1926 ResourceName(ApplicationInfo aInfo, int _iconId) {
1927 this(aInfo.packageName, _iconId);
1928 }
1929
1930 ResourceName(ComponentInfo cInfo, int _iconId) {
1931 this(cInfo.applicationInfo.packageName, _iconId);
1932 }
1933
1934 ResourceName(ResolveInfo rInfo, int _iconId) {
1935 this(rInfo.activityInfo.applicationInfo.packageName, _iconId);
1936 }
1937
1938 @Override
1939 public boolean equals(Object o) {
1940 if (this == o) return true;
1941 if (o == null || getClass() != o.getClass()) return false;
1942
1943 ResourceName that = (ResourceName) o;
1944
1945 if (iconId != that.iconId) return false;
1946 return !(packageName != null ?
1947 !packageName.equals(that.packageName) : that.packageName != null);
1948
1949 }
1950
1951 @Override
1952 public int hashCode() {
1953 int result;
1954 result = packageName.hashCode();
1955 result = 31 * result + iconId;
1956 return result;
1957 }
1958
1959 @Override
1960 public String toString() {
1961 return "{ResourceName " + packageName + " / " + iconId + "}";
1962 }
1963 }
1964
1965 private CharSequence getCachedString(ResourceName name) {
1966 synchronized (sSync) {
1967 WeakReference<CharSequence> wr = sStringCache.get(name);
1968 if (wr != null) { // we have the activity
1969 CharSequence cs = wr.get();
1970 if (cs != null) {
1971 return cs;
1972 }
1973 // our entry has been purged
1974 sStringCache.remove(name);
1975 }
1976 }
1977 return null;
1978 }
1979
1980 private void putCachedString(ResourceName name, CharSequence cs) {
1981 synchronized (sSync) {
1982 sStringCache.put(name, new WeakReference<CharSequence>(cs));
1983 }
1984 }
1985
1986 @Override
Tor Norbye7b9c9122013-05-30 16:48:33 -07001987 public CharSequence getText(String packageName, @StringRes int resid,
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001988 ApplicationInfo appInfo) {
1989 ResourceName name = new ResourceName(packageName, resid);
1990 CharSequence text = getCachedString(name);
1991 if (text != null) {
1992 return text;
1993 }
1994 if (appInfo == null) {
1995 try {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001996 appInfo = getApplicationInfo(packageName, sDefaultFlags);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001997 } catch (NameNotFoundException e) {
1998 return null;
1999 }
2000 }
2001 try {
2002 Resources r = getResourcesForApplication(appInfo);
2003 text = r.getText(resid);
2004 putCachedString(name, text);
2005 return text;
2006 } catch (NameNotFoundException e) {
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07002007 Log.w("PackageManager", "Failure retrieving resources for "
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002008 + appInfo.packageName);
2009 } catch (RuntimeException e) {
2010 // If an exception was thrown, fall through to return
2011 // default icon.
2012 Log.w("PackageManager", "Failure retrieving text 0x"
2013 + Integer.toHexString(resid) + " in package "
2014 + packageName, e);
2015 }
2016 return null;
2017 }
2018
2019 @Override
Tor Norbye7b9c9122013-05-30 16:48:33 -07002020 public XmlResourceParser getXml(String packageName, @XmlRes int resid,
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002021 ApplicationInfo appInfo) {
2022 if (appInfo == null) {
2023 try {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07002024 appInfo = getApplicationInfo(packageName, sDefaultFlags);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002025 } catch (NameNotFoundException e) {
2026 return null;
2027 }
2028 }
2029 try {
2030 Resources r = getResourcesForApplication(appInfo);
2031 return r.getXml(resid);
2032 } catch (RuntimeException e) {
2033 // If an exception was thrown, fall through to return
2034 // default icon.
2035 Log.w("PackageManager", "Failure retrieving xml 0x"
2036 + Integer.toHexString(resid) + " in package "
2037 + packageName, e);
2038 } catch (NameNotFoundException e) {
Alon Albert3fa51e32010-11-11 09:24:04 -08002039 Log.w("PackageManager", "Failure retrieving resources for "
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002040 + appInfo.packageName);
2041 }
2042 return null;
2043 }
2044
2045 @Override
2046 public CharSequence getApplicationLabel(ApplicationInfo info) {
2047 return info.loadLabel(this);
2048 }
2049
2050 @Override
Nicolas Prevot9a80e532015-09-23 15:49:28 +01002051 public int installExistingPackage(String packageName) throws NameNotFoundException {
Peter Wang09014f12020-01-24 08:15:38 +08002052 return installExistingPackage(packageName, INSTALL_REASON_UNKNOWN);
Sunny Goyala31a74b2017-05-11 15:59:19 -07002053 }
2054
2055 @Override
2056 public int installExistingPackage(String packageName, int installReason)
2057 throws NameNotFoundException {
Jeff Sharkeyc59a5e72018-06-21 19:14:58 -06002058 return installExistingPackageAsUser(packageName, installReason, getUserId());
Nicolas Prevot9a80e532015-09-23 15:49:28 +01002059 }
2060
2061 @Override
2062 public int installExistingPackageAsUser(String packageName, int userId)
Dianne Hackborn7767eac2012-08-23 18:25:40 -07002063 throws NameNotFoundException {
Peter Wang09014f12020-01-24 08:15:38 +08002064 return installExistingPackageAsUser(packageName, INSTALL_REASON_UNKNOWN,
Sunny Goyala31a74b2017-05-11 15:59:19 -07002065 userId);
2066 }
2067
2068 private int installExistingPackageAsUser(String packageName, int installReason, int userId)
2069 throws NameNotFoundException {
Dianne Hackborn7767eac2012-08-23 18:25:40 -07002070 try {
Philip P. Moltmannbfcffa02019-05-13 17:10:46 -07002071 int res = mPM.installExistingPackageAsUser(packageName, userId,
2072 INSTALL_ALL_WHITELIST_RESTRICTED_PERMISSIONS, installReason, null);
Dianne Hackborn7767eac2012-08-23 18:25:40 -07002073 if (res == INSTALL_FAILED_INVALID_URI) {
2074 throw new NameNotFoundException("Package " + packageName + " doesn't exist");
2075 }
2076 return res;
2077 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002078 throw e.rethrowFromSystemServer();
Dianne Hackborn7767eac2012-08-23 18:25:40 -07002079 }
2080 }
2081
2082 @Override
Kenny Root3a9b5fb2011-09-20 14:15:38 -07002083 public void verifyPendingInstall(int id, int response) {
Kenny Root5ab21572011-07-27 11:11:19 -07002084 try {
Kenny Root3a9b5fb2011-09-20 14:15:38 -07002085 mPM.verifyPendingInstall(id, response);
Kenny Root5ab21572011-07-27 11:11:19 -07002086 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002087 throw e.rethrowFromSystemServer();
Kenny Root5ab21572011-07-27 11:11:19 -07002088 }
2089 }
2090
2091 @Override
rich canningsd9ef3e52012-08-22 14:28:05 -07002092 public void extendVerificationTimeout(int id, int verificationCodeAtTimeout,
2093 long millisecondsToDelay) {
2094 try {
2095 mPM.extendVerificationTimeout(id, verificationCodeAtTimeout, millisecondsToDelay);
2096 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002097 throw e.rethrowFromSystemServer();
rich canningsd9ef3e52012-08-22 14:28:05 -07002098 }
2099 }
2100
2101 @Override
Todd Kennedydfa93ab2016-03-03 15:24:33 -08002102 public void verifyIntentFilter(int id, int verificationCode, List<String> failedDomains) {
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08002103 try {
Todd Kennedydfa93ab2016-03-03 15:24:33 -08002104 mPM.verifyIntentFilter(id, verificationCode, failedDomains);
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08002105 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002106 throw e.rethrowFromSystemServer();
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08002107 }
2108 }
2109
2110 @Override
Jeff Sharkeye06b4d12016-01-06 14:51:50 -07002111 public int getIntentVerificationStatusAsUser(String packageName, int userId) {
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08002112 try {
2113 return mPM.getIntentVerificationStatus(packageName, userId);
2114 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002115 throw e.rethrowFromSystemServer();
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08002116 }
2117 }
2118
2119 @Override
Jeff Sharkeye06b4d12016-01-06 14:51:50 -07002120 public boolean updateIntentVerificationStatusAsUser(String packageName, int status, int userId) {
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08002121 try {
2122 return mPM.updateIntentVerificationStatus(packageName, status, userId);
2123 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002124 throw e.rethrowFromSystemServer();
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08002125 }
2126 }
2127
2128 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07002129 @SuppressWarnings("unchecked")
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08002130 public List<IntentFilterVerificationInfo> getIntentFilterVerifications(String packageName) {
2131 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07002132 ParceledListSlice<IntentFilterVerificationInfo> parceledList =
2133 mPM.getIntentFilterVerifications(packageName);
2134 if (parceledList == null) {
2135 return Collections.emptyList();
2136 }
2137 return parceledList.getList();
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08002138 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002139 throw e.rethrowFromSystemServer();
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08002140 }
2141 }
2142
2143 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07002144 @SuppressWarnings("unchecked")
Fabrice Di Meglio07885952015-04-06 19:41:28 -07002145 public List<IntentFilter> getAllIntentFilters(String packageName) {
2146 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07002147 ParceledListSlice<IntentFilter> parceledList =
2148 mPM.getAllIntentFilters(packageName);
2149 if (parceledList == null) {
2150 return Collections.emptyList();
2151 }
2152 return parceledList.getList();
Fabrice Di Meglio07885952015-04-06 19:41:28 -07002153 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002154 throw e.rethrowFromSystemServer();
Fabrice Di Meglio07885952015-04-06 19:41:28 -07002155 }
2156 }
2157
2158 @Override
Jeff Sharkeye06b4d12016-01-06 14:51:50 -07002159 public String getDefaultBrowserPackageNameAsUser(int userId) {
Fabrice Di Meglio62271722015-04-10 17:24:02 -07002160 try {
Todd Kennedy583378d2019-07-12 06:50:30 -07002161 return mPermissionManager.getDefaultBrowser(userId);
Fabrice Di Meglio62271722015-04-10 17:24:02 -07002162 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002163 throw e.rethrowFromSystemServer();
Fabrice Di Meglio62271722015-04-10 17:24:02 -07002164 }
2165 }
2166
2167 @Override
Jeff Sharkeye06b4d12016-01-06 14:51:50 -07002168 public boolean setDefaultBrowserPackageNameAsUser(String packageName, int userId) {
Fabrice Di Meglio62271722015-04-10 17:24:02 -07002169 try {
Todd Kennedy583378d2019-07-12 06:50:30 -07002170 return mPermissionManager.setDefaultBrowser(packageName, userId);
Fabrice Di Meglio62271722015-04-10 17:24:02 -07002171 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002172 throw e.rethrowFromSystemServer();
Fabrice Di Meglio62271722015-04-10 17:24:02 -07002173 }
2174 }
2175
2176 @Override
Dianne Hackborn880119b2010-11-18 22:26:40 -08002177 public void setInstallerPackageName(String targetPackage,
2178 String installerPackageName) {
2179 try {
2180 mPM.setInstallerPackageName(targetPackage, installerPackageName);
2181 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002182 throw e.rethrowFromSystemServer();
Dianne Hackborn880119b2010-11-18 22:26:40 -08002183 }
2184 }
2185
2186 @Override
Todd Kennedyab532892017-03-08 14:19:49 -08002187 public void setUpdateAvailable(String packageName, boolean updateAvailable) {
2188 try {
2189 mPM.setUpdateAvailable(packageName, updateAvailable);
2190 } catch (RemoteException e) {
2191 throw e.rethrowFromSystemServer();
2192 }
2193 }
2194
2195 @Override
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002196 public String getInstallerPackageName(String packageName) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002197 try {
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002198 return mPM.getInstallerPackageName(packageName);
2199 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002200 throw e.rethrowFromSystemServer();
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002201 }
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002202 }
2203
2204 @Override
Alan Stokescae316d2019-11-26 09:39:02 +00002205 @NonNull
2206 public InstallSourceInfo getInstallSourceInfo(String packageName) throws NameNotFoundException {
2207 final InstallSourceInfo installSourceInfo;
2208 try {
2209 installSourceInfo = mPM.getInstallSourceInfo(packageName);
2210 } catch (RemoteException e) {
2211 throw e.rethrowFromSystemServer();
2212 }
2213 if (installSourceInfo == null) {
2214 throw new NameNotFoundException(packageName);
2215 }
2216 return installSourceInfo;
2217 }
2218
2219 @Override
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002220 public int getMoveStatus(int moveId) {
2221 try {
2222 return mPM.getMoveStatus(moveId);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002223 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002224 throw e.rethrowFromSystemServer();
Jeff Sharkeyb2b9ab82015-04-05 21:10:42 -07002225 }
2226 }
2227
2228 @Override
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002229 public void registerMoveCallback(MoveCallback callback, Handler handler) {
2230 synchronized (mDelegates) {
2231 final MoveCallbackDelegate delegate = new MoveCallbackDelegate(callback,
2232 handler.getLooper());
2233 try {
2234 mPM.registerMoveCallback(delegate);
2235 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002236 throw e.rethrowFromSystemServer();
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002237 }
2238 mDelegates.add(delegate);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002239 }
2240 }
2241
2242 @Override
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002243 public void unregisterMoveCallback(MoveCallback callback) {
2244 synchronized (mDelegates) {
2245 for (Iterator<MoveCallbackDelegate> i = mDelegates.iterator(); i.hasNext();) {
2246 final MoveCallbackDelegate delegate = i.next();
2247 if (delegate.mCallback == callback) {
2248 try {
2249 mPM.unregisterMoveCallback(delegate);
2250 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002251 throw e.rethrowFromSystemServer();
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002252 }
2253 i.remove();
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07002254 }
2255 }
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07002256 }
2257 }
2258
2259 @Override
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002260 public int movePackage(String packageName, VolumeInfo vol) {
2261 try {
2262 final String volumeUuid;
2263 if (VolumeInfo.ID_PRIVATE_INTERNAL.equals(vol.id)) {
2264 volumeUuid = StorageManager.UUID_PRIVATE_INTERNAL;
2265 } else if (vol.isPrimaryPhysical()) {
2266 volumeUuid = StorageManager.UUID_PRIMARY_PHYSICAL;
2267 } else {
Daulet Zhanguzin0af97d62019-12-30 15:41:28 +00002268 volumeUuid = Objects.requireNonNull(vol.fsUuid);
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002269 }
2270
2271 return mPM.movePackage(packageName, volumeUuid);
2272 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002273 throw e.rethrowFromSystemServer();
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002274 }
2275 }
2276
2277 @Override
Mathew Inwood61e8ae62018-08-14 14:17:44 +01002278 @UnsupportedAppUsage
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002279 public @Nullable VolumeInfo getPackageCurrentVolume(ApplicationInfo app) {
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07002280 final StorageManager storage = mContext.getSystemService(StorageManager.class);
Yao Chen022b8ea2016-12-16 11:03:28 -08002281 return getPackageCurrentVolume(app, storage);
2282 }
2283
2284 @VisibleForTesting
2285 protected @Nullable VolumeInfo getPackageCurrentVolume(ApplicationInfo app,
2286 StorageManager storage) {
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002287 if (app.isInternal()) {
2288 return storage.findVolumeById(VolumeInfo.ID_PRIVATE_INTERNAL);
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002289 } else {
2290 return storage.findVolumeByUuid(app.volumeUuid);
2291 }
2292 }
2293
2294 @Override
2295 public @NonNull List<VolumeInfo> getPackageCandidateVolumes(ApplicationInfo app) {
Yao Chen022b8ea2016-12-16 11:03:28 -08002296 final StorageManager storageManager = mContext.getSystemService(StorageManager.class);
2297 return getPackageCandidateVolumes(app, storageManager, mPM);
2298 }
2299
2300 @VisibleForTesting
2301 protected @NonNull List<VolumeInfo> getPackageCandidateVolumes(ApplicationInfo app,
2302 StorageManager storageManager, IPackageManager pm) {
2303 final VolumeInfo currentVol = getPackageCurrentVolume(app, storageManager);
2304 final List<VolumeInfo> vols = storageManager.getVolumes();
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07002305 final List<VolumeInfo> candidates = new ArrayList<>();
2306 for (VolumeInfo vol : vols) {
Yao Chen022b8ea2016-12-16 11:03:28 -08002307 if (Objects.equals(vol, currentVol)
2308 || isPackageCandidateVolume(mContext, app, vol, pm)) {
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07002309 candidates.add(vol);
2310 }
2311 }
2312 return candidates;
2313 }
2314
Yao Chen022b8ea2016-12-16 11:03:28 -08002315 @VisibleForTesting
2316 protected boolean isForceAllowOnExternal(Context context) {
2317 return Settings.Global.getInt(
Todd Kennedyf39ca8f2015-08-07 14:15:07 -07002318 context.getContentResolver(), Settings.Global.FORCE_ALLOW_ON_EXTERNAL, 0) != 0;
Yao Chen022b8ea2016-12-16 11:03:28 -08002319 }
2320
2321 @VisibleForTesting
2322 protected boolean isAllow3rdPartyOnInternal(Context context) {
2323 return context.getResources().getBoolean(
2324 com.android.internal.R.bool.config_allow3rdPartyAppOnInternal);
2325 }
2326
2327 private boolean isPackageCandidateVolume(
2328 ContextImpl context, ApplicationInfo app, VolumeInfo vol, IPackageManager pm) {
2329 final boolean forceAllowOnExternal = isForceAllowOnExternal(context);
2330
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07002331 if (VolumeInfo.ID_PRIVATE_INTERNAL.equals(vol.getId())) {
Yao Chen022b8ea2016-12-16 11:03:28 -08002332 return app.isSystemApp() || isAllow3rdPartyOnInternal(context);
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07002333 }
2334
2335 // System apps and apps demanding internal storage can't be moved
2336 // anywhere else
Todd Kennedyf39ca8f2015-08-07 14:15:07 -07002337 if (app.isSystemApp()) {
2338 return false;
2339 }
2340 if (!forceAllowOnExternal
Dianne Hackborn30a4e6d2015-10-12 17:14:56 -07002341 && (app.installLocation == PackageInfo.INSTALL_LOCATION_INTERNAL_ONLY
2342 || app.installLocation == PackageInfo.INSTALL_LOCATION_UNSPECIFIED)) {
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07002343 return false;
2344 }
2345
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002346 // Gotta be able to write there
2347 if (!vol.isMountedWritable()) {
2348 return false;
2349 }
2350
2351 // Moving into an ASEC on public primary is only option internal
2352 if (vol.isPrimaryPhysical()) {
2353 return app.isInternal();
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07002354 }
2355
Makoto Onukif34db0a2016-02-17 11:17:15 -08002356 // Some apps can't be moved. (e.g. device admins)
2357 try {
Yao Chen022b8ea2016-12-16 11:03:28 -08002358 if (pm.isPackageDeviceAdminOnAnyUser(app.packageName)) {
Makoto Onukif34db0a2016-02-17 11:17:15 -08002359 return false;
2360 }
2361 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002362 throw e.rethrowFromSystemServer();
Makoto Onukif34db0a2016-02-17 11:17:15 -08002363 }
2364
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07002365 // Otherwise we can move to any private volume
2366 return (vol.getType() == VolumeInfo.TYPE_PRIVATE);
2367 }
2368
2369 @Override
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002370 public int movePrimaryStorage(VolumeInfo vol) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002371 try {
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002372 final String volumeUuid;
2373 if (VolumeInfo.ID_PRIVATE_INTERNAL.equals(vol.id)) {
2374 volumeUuid = StorageManager.UUID_PRIVATE_INTERNAL;
2375 } else if (vol.isPrimaryPhysical()) {
2376 volumeUuid = StorageManager.UUID_PRIMARY_PHYSICAL;
2377 } else {
Daulet Zhanguzin0af97d62019-12-30 15:41:28 +00002378 volumeUuid = Objects.requireNonNull(vol.fsUuid);
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002379 }
2380
2381 return mPM.movePrimaryStorage(volumeUuid);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002382 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002383 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002384 }
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002385 }
2386
Jeff Sharkey275e3e42015-04-24 16:10:32 -07002387 @Override
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002388 public @Nullable VolumeInfo getPrimaryStorageCurrentVolume() {
2389 final StorageManager storage = mContext.getSystemService(StorageManager.class);
2390 final String volumeUuid = storage.getPrimaryStorageUuid();
Jeff Sharkey50a05452015-04-29 11:24:52 -07002391 return storage.findVolumeByQualifiedUuid(volumeUuid);
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002392 }
2393
Jeff Sharkey275e3e42015-04-24 16:10:32 -07002394 @Override
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002395 public @NonNull List<VolumeInfo> getPrimaryStorageCandidateVolumes() {
2396 final StorageManager storage = mContext.getSystemService(StorageManager.class);
2397 final VolumeInfo currentVol = getPrimaryStorageCurrentVolume();
2398 final List<VolumeInfo> vols = storage.getVolumes();
2399 final List<VolumeInfo> candidates = new ArrayList<>();
Jeff Sharkeyfced5342015-05-10 14:53:34 -07002400 if (Objects.equals(StorageManager.UUID_PRIMARY_PHYSICAL,
2401 storage.getPrimaryStorageUuid()) && currentVol != null) {
2402 // TODO: support moving primary physical to emulated volume
2403 candidates.add(currentVol);
2404 } else {
2405 for (VolumeInfo vol : vols) {
2406 if (Objects.equals(vol, currentVol) || isPrimaryStorageCandidateVolume(vol)) {
2407 candidates.add(vol);
2408 }
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002409 }
2410 }
2411 return candidates;
2412 }
2413
2414 private static boolean isPrimaryStorageCandidateVolume(VolumeInfo vol) {
2415 // Private internal is always an option
2416 if (VolumeInfo.ID_PRIVATE_INTERNAL.equals(vol.getId())) {
2417 return true;
2418 }
2419
2420 // Gotta be able to write there
2421 if (!vol.isMountedWritable()) {
2422 return false;
2423 }
2424
Jeff Sharkeyfced5342015-05-10 14:53:34 -07002425 // We can move to any private volume
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002426 return (vol.getType() == VolumeInfo.TYPE_PRIVATE);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002427 }
2428
2429 @Override
Mathew Inwood61e8ae62018-08-14 14:17:44 +01002430 @UnsupportedAppUsage
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002431 public void deletePackage(String packageName, IPackageDeleteObserver observer, int flags) {
Jeff Sharkeyc59a5e72018-06-21 19:14:58 -06002432 deletePackageAsUser(packageName, observer, flags, getUserId());
Nicolas Prevot9a80e532015-09-23 15:49:28 +01002433 }
2434
2435 @Override
Svet Ganov67882122016-12-11 16:36:34 -08002436 public void deletePackageAsUser(String packageName, IPackageDeleteObserver observer,
2437 int flags, int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002438 try {
Peter Wang09014f12020-01-24 08:15:38 +08002439 mPM.deletePackageAsUser(packageName, VERSION_CODE_HIGHEST,
Svet Ganov67882122016-12-11 16:36:34 -08002440 observer, userId, flags);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002441 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002442 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002443 }
2444 }
Jeff Sharkeyfbd0e9f2014-08-06 16:34:34 -07002445
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002446 @Override
2447 public void clearApplicationUserData(String packageName,
2448 IPackageDataObserver observer) {
2449 try {
Jeff Sharkeyc59a5e72018-06-21 19:14:58 -06002450 mPM.clearApplicationUserData(packageName, observer, getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002451 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002452 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002453 }
2454 }
2455 @Override
2456 public void deleteApplicationCacheFiles(String packageName,
2457 IPackageDataObserver observer) {
2458 try {
2459 mPM.deleteApplicationCacheFiles(packageName, observer);
2460 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002461 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002462 }
2463 }
Jeff Sharkey529f91f2015-04-18 20:23:13 -07002464
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002465 @Override
Suprabh Shukla78c9eb82016-04-12 15:51:35 -07002466 public void deleteApplicationCacheFilesAsUser(String packageName, int userId,
2467 IPackageDataObserver observer) {
2468 try {
2469 mPM.deleteApplicationCacheFilesAsUser(packageName, userId, observer);
2470 } catch (RemoteException e) {
2471 throw e.rethrowFromSystemServer();
2472 }
2473 }
2474
2475 @Override
Jeff Sharkey529f91f2015-04-18 20:23:13 -07002476 public void freeStorageAndNotify(String volumeUuid, long idealStorageSize,
2477 IPackageDataObserver observer) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002478 try {
Jeff Sharkeyddff8072017-05-26 13:10:46 -06002479 mPM.freeStorageAndNotify(volumeUuid, idealStorageSize, 0, observer);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002480 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002481 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002482 }
2483 }
2484
2485 @Override
Jeff Sharkey529f91f2015-04-18 20:23:13 -07002486 public void freeStorage(String volumeUuid, long freeStorageSize, IntentSender pi) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002487 try {
Jeff Sharkeyddff8072017-05-26 13:10:46 -06002488 mPM.freeStorage(volumeUuid, freeStorageSize, 0, pi);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002489 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002490 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002491 }
2492 }
2493
2494 @Override
Suprabh Shukla79000492018-12-24 17:03:02 -08002495 public String[] setDistractingPackageRestrictions(String[] packages, int distractionFlags) {
2496 try {
2497 return mPM.setDistractingPackageRestrictionsAsUser(packages, distractionFlags,
2498 mContext.getUserId());
2499 } catch (RemoteException e) {
2500 throw e.rethrowFromSystemServer();
2501 }
2502 }
2503
2504 @Override
Suprabh Shukla021b57a2018-03-08 18:21:50 -08002505 public String[] setPackagesSuspended(String[] packageNames, boolean suspended,
2506 PersistableBundle appExtras, PersistableBundle launcherExtras,
2507 String dialogMessage) {
Suprabh Shukla389cb6f2018-10-01 18:20:39 -07002508 final SuspendDialogInfo dialogInfo = !TextUtils.isEmpty(dialogMessage)
2509 ? new SuspendDialogInfo.Builder().setMessage(dialogMessage).build()
2510 : null;
2511 return setPackagesSuspended(packageNames, suspended, appExtras, launcherExtras, dialogInfo);
2512 }
2513
2514 @Override
2515 public String[] setPackagesSuspended(String[] packageNames, boolean suspended,
2516 PersistableBundle appExtras, PersistableBundle launcherExtras,
2517 SuspendDialogInfo dialogInfo) {
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00002518 try {
Suprabh Shukla021b57a2018-03-08 18:21:50 -08002519 return mPM.setPackagesSuspendedAsUser(packageNames, suspended, appExtras,
Suprabh Shukla389cb6f2018-10-01 18:20:39 -07002520 launcherExtras, dialogInfo, mContext.getOpPackageName(),
Jeff Sharkeyc59a5e72018-06-21 19:14:58 -06002521 getUserId());
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00002522 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002523 throw e.rethrowFromSystemServer();
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00002524 }
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00002525 }
2526
2527 @Override
Suprabh Shukla436d093ba2018-12-12 16:01:41 +00002528 public String[] getUnsuspendablePackages(String[] packageNames) {
Suprabh Shukla1f1de702018-11-09 22:49:23 -08002529 try {
Suprabh Shukla436d093ba2018-12-12 16:01:41 +00002530 return mPM.getUnsuspendablePackagesForUser(packageNames, mContext.getUserId());
Suprabh Shukla1f1de702018-11-09 22:49:23 -08002531 } catch (RemoteException e) {
2532 throw e.rethrowFromSystemServer();
2533 }
2534 }
2535
2536 @Override
Suprabh Shukla45b9e402018-04-09 17:33:53 -07002537 public Bundle getSuspendedPackageAppExtras() {
Suprabh Shukla021b57a2018-03-08 18:21:50 -08002538 try {
Suprabh Shuklad3278442019-08-27 15:58:03 -07002539 return mPM.getSuspendedPackageAppExtras(mContext.getOpPackageName(), getUserId());
Suprabh Shukla021b57a2018-03-08 18:21:50 -08002540 } catch (RemoteException e) {
2541 throw e.rethrowFromSystemServer();
2542 }
Suprabh Shukla021b57a2018-03-08 18:21:50 -08002543 }
2544
2545 @Override
Andrei Stingaceanu355b2322016-02-12 16:43:51 +00002546 public boolean isPackageSuspendedForUser(String packageName, int userId) {
2547 try {
2548 return mPM.isPackageSuspendedForUser(packageName, userId);
2549 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002550 throw e.rethrowFromSystemServer();
Andrei Stingaceanu355b2322016-02-12 16:43:51 +00002551 }
Andrei Stingaceanu355b2322016-02-12 16:43:51 +00002552 }
2553
Jeff Sharkey9bc89af2017-01-11 11:25:50 -07002554 /** @hide */
2555 @Override
Suprabh Shukla96212bc2018-04-10 15:04:51 -07002556 public boolean isPackageSuspended(String packageName) throws NameNotFoundException {
2557 try {
Jeff Sharkeyc59a5e72018-06-21 19:14:58 -06002558 return isPackageSuspendedForUser(packageName, getUserId());
Suprabh Shukla96212bc2018-04-10 15:04:51 -07002559 } catch (IllegalArgumentException ie) {
2560 throw new NameNotFoundException(packageName);
2561 }
Suprabh Shukla021b57a2018-03-08 18:21:50 -08002562 }
2563
2564 @Override
2565 public boolean isPackageSuspended() {
Jeff Sharkeyc59a5e72018-06-21 19:14:58 -06002566 return isPackageSuspendedForUser(mContext.getOpPackageName(), getUserId());
Suprabh Shukla021b57a2018-03-08 18:21:50 -08002567 }
2568
2569 /** @hide */
2570 @Override
Jeff Sharkey9bc89af2017-01-11 11:25:50 -07002571 public void setApplicationCategoryHint(String packageName, int categoryHint) {
2572 try {
2573 mPM.setApplicationCategoryHint(packageName, categoryHint,
2574 mContext.getOpPackageName());
2575 } catch (RemoteException e) {
2576 throw e.rethrowFromSystemServer();
2577 }
2578 }
2579
Andrei Stingaceanu355b2322016-02-12 16:43:51 +00002580 @Override
Mathew Inwood61e8ae62018-08-14 14:17:44 +01002581 @UnsupportedAppUsage
Jeff Sharkeye06b4d12016-01-06 14:51:50 -07002582 public void getPackageSizeInfoAsUser(String packageName, int userHandle,
Dianne Hackborn0c380492012-08-20 17:23:30 -07002583 IPackageStatsObserver observer) {
Jeff Sharkey6f4b2a32017-03-21 14:13:41 -06002584 final String msg = "Shame on you for calling the hidden API "
2585 + "getPackageSizeInfoAsUser(). Shame!";
Jeff Sharkeye6306c42017-03-07 21:03:18 -07002586 if (mContext.getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.O) {
Jeff Sharkey6f4b2a32017-03-21 14:13:41 -06002587 throw new UnsupportedOperationException(msg);
Jeff Sharkeye6306c42017-03-07 21:03:18 -07002588 } else if (observer != null) {
Jeff Sharkey6f4b2a32017-03-21 14:13:41 -06002589 Log.d(TAG, msg);
Jeff Sharkeye6306c42017-03-07 21:03:18 -07002590 try {
2591 observer.onGetStatsCompleted(null, false);
2592 } catch (RemoteException ignored) {
2593 }
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002594 }
2595 }
Jeff Sharkeyd5896632016-03-04 16:16:00 -07002596
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002597 @Override
2598 public void addPackageToPreferred(String packageName) {
Jeff Sharkeyd5896632016-03-04 16:16:00 -07002599 Log.w(TAG, "addPackageToPreferred() is a no-op");
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002600 }
2601
2602 @Override
2603 public void removePackageFromPreferred(String packageName) {
Jeff Sharkeyd5896632016-03-04 16:16:00 -07002604 Log.w(TAG, "removePackageFromPreferred() is a no-op");
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002605 }
2606
2607 @Override
2608 public List<PackageInfo> getPreferredPackages(int flags) {
Jeff Sharkeyd5896632016-03-04 16:16:00 -07002609 Log.w(TAG, "getPreferredPackages() is a no-op");
2610 return Collections.emptyList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002611 }
2612
2613 @Override
2614 public void addPreferredActivity(IntentFilter filter,
2615 int match, ComponentName[] set, ComponentName activity) {
2616 try {
Jeff Sharkeyc59a5e72018-06-21 19:14:58 -06002617 mPM.addPreferredActivity(filter, match, set, activity, getUserId());
Amith Yamasania3f133a2012-08-09 17:11:28 -07002618 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002619 throw e.rethrowFromSystemServer();
Amith Yamasania3f133a2012-08-09 17:11:28 -07002620 }
2621 }
2622
2623 @Override
Jeff Sharkeye06b4d12016-01-06 14:51:50 -07002624 public void addPreferredActivityAsUser(IntentFilter filter, int match,
Amith Yamasania3f133a2012-08-09 17:11:28 -07002625 ComponentName[] set, ComponentName activity, int userId) {
2626 try {
2627 mPM.addPreferredActivity(filter, match, set, activity, userId);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002628 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002629 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002630 }
2631 }
2632
2633 @Override
2634 public void replacePreferredActivity(IntentFilter filter,
2635 int match, ComponentName[] set, ComponentName activity) {
2636 try {
Jeff Sharkeyc59a5e72018-06-21 19:14:58 -06002637 mPM.replacePreferredActivity(filter, match, set, activity, getUserId());
Amith Yamasani41c1ded2014-08-05 11:15:05 -07002638 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002639 throw e.rethrowFromSystemServer();
Amith Yamasani41c1ded2014-08-05 11:15:05 -07002640 }
2641 }
2642
2643 @Override
2644 public void replacePreferredActivityAsUser(IntentFilter filter,
2645 int match, ComponentName[] set, ComponentName activity,
2646 int userId) {
2647 try {
2648 mPM.replacePreferredActivity(filter, match, set, activity, userId);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002649 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002650 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002651 }
2652 }
2653
2654 @Override
2655 public void clearPackagePreferredActivities(String packageName) {
2656 try {
2657 mPM.clearPackagePreferredActivities(packageName);
2658 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002659 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002660 }
2661 }
2662
2663 @Override
2664 public int getPreferredActivities(List<IntentFilter> outFilters,
2665 List<ComponentName> outActivities, String packageName) {
2666 try {
2667 return mPM.getPreferredActivities(outFilters, outActivities, packageName);
2668 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002669 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002670 }
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002671 }
2672
2673 @Override
Christopher Tatea2a0850d2013-09-05 16:38:58 -07002674 public ComponentName getHomeActivities(List<ResolveInfo> outActivities) {
2675 try {
2676 return mPM.getHomeActivities(outActivities);
2677 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002678 throw e.rethrowFromSystemServer();
Christopher Tatea2a0850d2013-09-05 16:38:58 -07002679 }
Christopher Tatea2a0850d2013-09-05 16:38:58 -07002680 }
2681
2682 @Override
Ricky Waia52e4262019-03-13 17:39:16 +00002683 public void setSyntheticAppDetailsActivityEnabled(String packageName, boolean enabled) {
Ricky Wai92cd0062019-02-14 20:23:22 +00002684 try {
2685 ComponentName componentName = new ComponentName(packageName,
Peter Wang09014f12020-01-24 08:15:38 +08002686 APP_DETAILS_ACTIVITY_CLASS_NAME);
Ricky Wai92cd0062019-02-14 20:23:22 +00002687 mPM.setComponentEnabledSetting(componentName, enabled
Peter Wang09014f12020-01-24 08:15:38 +08002688 ? COMPONENT_ENABLED_STATE_DEFAULT
2689 : COMPONENT_ENABLED_STATE_DISABLED,
2690 DONT_KILL_APP, getUserId());
Ricky Wai92cd0062019-02-14 20:23:22 +00002691 } catch (RemoteException e) {
2692 throw e.rethrowFromSystemServer();
2693 }
2694 }
2695
2696 @Override
Ricky Waia52e4262019-03-13 17:39:16 +00002697 public boolean getSyntheticAppDetailsActivityEnabled(String packageName) {
Ricky Wai92cd0062019-02-14 20:23:22 +00002698 try {
2699 ComponentName componentName = new ComponentName(packageName,
Peter Wang09014f12020-01-24 08:15:38 +08002700 APP_DETAILS_ACTIVITY_CLASS_NAME);
Ricky Wai92cd0062019-02-14 20:23:22 +00002701 int state = mPM.getComponentEnabledSetting(componentName, getUserId());
Peter Wang09014f12020-01-24 08:15:38 +08002702 return state == COMPONENT_ENABLED_STATE_ENABLED
2703 || state == COMPONENT_ENABLED_STATE_DEFAULT;
Ricky Wai92cd0062019-02-14 20:23:22 +00002704 } catch (RemoteException e) {
2705 throw e.rethrowFromSystemServer();
2706 }
2707 }
2708
2709 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002710 public void setComponentEnabledSetting(ComponentName componentName,
2711 int newState, int flags) {
2712 try {
Jeff Sharkeyc59a5e72018-06-21 19:14:58 -06002713 mPM.setComponentEnabledSetting(componentName, newState, flags, getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002714 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002715 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002716 }
2717 }
2718
2719 @Override
2720 public int getComponentEnabledSetting(ComponentName componentName) {
2721 try {
Jeff Sharkeyc59a5e72018-06-21 19:14:58 -06002722 return mPM.getComponentEnabledSetting(componentName, getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002723 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002724 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002725 }
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002726 }
2727
2728 @Override
2729 public void setApplicationEnabledSetting(String packageName,
2730 int newState, int flags) {
2731 try {
Dianne Hackborn3fa3c28a2013-03-26 16:15:41 -07002732 mPM.setApplicationEnabledSetting(packageName, newState, flags,
Jeff Sharkeyc59a5e72018-06-21 19:14:58 -06002733 getUserId(), mContext.getOpPackageName());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002734 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002735 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002736 }
2737 }
2738
2739 @Override
2740 public int getApplicationEnabledSetting(String packageName) {
2741 try {
Jeff Sharkeyc59a5e72018-06-21 19:14:58 -06002742 return mPM.getApplicationEnabledSetting(packageName, getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002743 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002744 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002745 }
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002746 }
2747
Amith Yamasani655d0e22013-06-12 14:19:10 -07002748 @Override
Sudheer Shankabbb3ff22015-07-09 15:39:23 +01002749 public void flushPackageRestrictionsAsUser(int userId) {
2750 try {
2751 mPM.flushPackageRestrictionsAsUser(userId);
2752 } catch (RemoteException e) {
2753 throw e.rethrowFromSystemServer();
2754 }
2755 }
2756
2757 @Override
Amith Yamasanie5bcff62014-07-19 15:44:09 -07002758 public boolean setApplicationHiddenSettingAsUser(String packageName, boolean hidden,
Amith Yamasani655d0e22013-06-12 14:19:10 -07002759 UserHandle user) {
2760 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07002761 return mPM.setApplicationHiddenSettingAsUser(packageName, hidden,
Amith Yamasani655d0e22013-06-12 14:19:10 -07002762 user.getIdentifier());
Jeff Sharkey27b2e692016-02-25 17:40:12 -07002763 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002764 throw e.rethrowFromSystemServer();
Amith Yamasani655d0e22013-06-12 14:19:10 -07002765 }
Amith Yamasani655d0e22013-06-12 14:19:10 -07002766 }
2767
2768 @Override
Amith Yamasanie5bcff62014-07-19 15:44:09 -07002769 public boolean getApplicationHiddenSettingAsUser(String packageName, UserHandle user) {
Amith Yamasani655d0e22013-06-12 14:19:10 -07002770 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07002771 return mPM.getApplicationHiddenSettingAsUser(packageName, user.getIdentifier());
Jeff Sharkey27b2e692016-02-25 17:40:12 -07002772 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002773 throw e.rethrowFromSystemServer();
Amith Yamasani655d0e22013-06-12 14:19:10 -07002774 }
Amith Yamasani655d0e22013-06-12 14:19:10 -07002775 }
2776
dcashmanc6f22492014-08-14 09:54:51 -07002777 /** @hide */
dcashman9d2f4412014-06-09 09:27:54 -07002778 @Override
Peter Wang09014f12020-01-24 08:15:38 +08002779 public void setSystemAppState(String packageName, @SystemAppState int state) {
2780 try {
2781 switch (state) {
2782 case SYSTEM_APP_STATE_HIDDEN_UNTIL_INSTALLED_HIDDEN:
2783 mPM.setSystemAppHiddenUntilInstalled(packageName, true);
2784 break;
2785 case SYSTEM_APP_STATE_HIDDEN_UNTIL_INSTALLED_VISIBLE:
2786 mPM.setSystemAppHiddenUntilInstalled(packageName, false);
2787 break;
2788 case SYSTEM_APP_STATE_INSTALLED:
2789 mPM.setSystemAppInstallState(packageName, true, getUserId());
2790 break;
2791 case SYSTEM_APP_STATE_UNINSTALLED:
2792 mPM.setSystemAppInstallState(packageName, false, getUserId());
2793 break;
2794 default:
2795 }
2796 } catch (RemoteException e) {
2797 throw e.rethrowFromSystemServer();
2798 }
2799 }
2800
2801 /** @hide */
2802 @Override
dcashman9d2f4412014-06-09 09:27:54 -07002803 public KeySet getKeySetByAlias(String packageName, String alias) {
Daulet Zhanguzin0af97d62019-12-30 15:41:28 +00002804 Objects.requireNonNull(packageName);
2805 Objects.requireNonNull(alias);
dcashman9d2f4412014-06-09 09:27:54 -07002806 try {
Jeff Sharkey27b2e692016-02-25 17:40:12 -07002807 return mPM.getKeySetByAlias(packageName, alias);
dcashman9d2f4412014-06-09 09:27:54 -07002808 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002809 throw e.rethrowFromSystemServer();
dcashman9d2f4412014-06-09 09:27:54 -07002810 }
dcashman9d2f4412014-06-09 09:27:54 -07002811 }
2812
dcashmanc6f22492014-08-14 09:54:51 -07002813 /** @hide */
dcashman9d2f4412014-06-09 09:27:54 -07002814 @Override
2815 public KeySet getSigningKeySet(String packageName) {
Daulet Zhanguzin0af97d62019-12-30 15:41:28 +00002816 Objects.requireNonNull(packageName);
dcashman9d2f4412014-06-09 09:27:54 -07002817 try {
Jeff Sharkey27b2e692016-02-25 17:40:12 -07002818 return mPM.getSigningKeySet(packageName);
dcashman9d2f4412014-06-09 09:27:54 -07002819 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002820 throw e.rethrowFromSystemServer();
dcashman9d2f4412014-06-09 09:27:54 -07002821 }
dcashman9d2f4412014-06-09 09:27:54 -07002822 }
2823
dcashmanc6f22492014-08-14 09:54:51 -07002824 /** @hide */
dcashman9d2f4412014-06-09 09:27:54 -07002825 @Override
2826 public boolean isSignedBy(String packageName, KeySet ks) {
Daulet Zhanguzin0af97d62019-12-30 15:41:28 +00002827 Objects.requireNonNull(packageName);
2828 Objects.requireNonNull(ks);
dcashman9d2f4412014-06-09 09:27:54 -07002829 try {
dcashmanc6f22492014-08-14 09:54:51 -07002830 return mPM.isPackageSignedByKeySet(packageName, ks);
dcashman9d2f4412014-06-09 09:27:54 -07002831 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002832 throw e.rethrowFromSystemServer();
dcashman9d2f4412014-06-09 09:27:54 -07002833 }
2834 }
2835
dcashmanc6f22492014-08-14 09:54:51 -07002836 /** @hide */
dcashman9d2f4412014-06-09 09:27:54 -07002837 @Override
2838 public boolean isSignedByExactly(String packageName, KeySet ks) {
Daulet Zhanguzin0af97d62019-12-30 15:41:28 +00002839 Objects.requireNonNull(packageName);
2840 Objects.requireNonNull(ks);
dcashman9d2f4412014-06-09 09:27:54 -07002841 try {
dcashmanc6f22492014-08-14 09:54:51 -07002842 return mPM.isPackageSignedByKeySetExactly(packageName, ks);
dcashman9d2f4412014-06-09 09:27:54 -07002843 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002844 throw e.rethrowFromSystemServer();
dcashman9d2f4412014-06-09 09:27:54 -07002845 }
2846 }
2847
Kenny Root0aaa0d92011-09-12 16:42:55 -07002848 /**
2849 * @hide
2850 */
2851 @Override
2852 public VerifierDeviceIdentity getVerifierDeviceIdentity() {
2853 try {
2854 return mPM.getVerifierDeviceIdentity();
2855 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002856 throw e.rethrowFromSystemServer();
Kenny Root0aaa0d92011-09-12 16:42:55 -07002857 }
Kenny Root0aaa0d92011-09-12 16:42:55 -07002858 }
2859
Jeff Hao9f60c082014-10-28 18:51:07 -07002860 @Override
2861 public boolean isUpgrade() {
Svet Ganovd8eb8b22019-04-05 18:52:08 -07002862 return isDeviceUpgrading();
2863 }
2864
2865 @Override
2866 public boolean isDeviceUpgrading() {
Jeff Hao9f60c082014-10-28 18:51:07 -07002867 try {
Svet Ganovd8eb8b22019-04-05 18:52:08 -07002868 return mPM.isDeviceUpgrading();
Jeff Hao9f60c082014-10-28 18:51:07 -07002869 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002870 throw e.rethrowFromSystemServer();
Jeff Hao9f60c082014-10-28 18:51:07 -07002871 }
2872 }
2873
Jeff Sharkey3a44f3f2014-04-28 17:36:31 -07002874 @Override
Jeff Sharkey16c8e3f2014-07-24 17:08:17 -07002875 public PackageInstaller getPackageInstaller() {
2876 synchronized (mLock) {
2877 if (mInstaller == null) {
2878 try {
Svet Ganov67882122016-12-11 16:36:34 -08002879 mInstaller = new PackageInstaller(mPM.getPackageInstaller(),
Jeff Sharkeyc59a5e72018-06-21 19:14:58 -06002880 mContext.getPackageName(), getUserId());
Jeff Sharkey16c8e3f2014-07-24 17:08:17 -07002881 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002882 throw e.rethrowFromSystemServer();
Jeff Sharkey16c8e3f2014-07-24 17:08:17 -07002883 }
2884 }
2885 return mInstaller;
Jeff Sharkey3a44f3f2014-04-28 17:36:31 -07002886 }
2887 }
2888
Jeff Sharkey6c833e02014-07-14 22:44:30 -07002889 @Override
2890 public boolean isPackageAvailable(String packageName) {
2891 try {
Jeff Sharkeyc59a5e72018-06-21 19:14:58 -06002892 return mPM.isPackageAvailable(packageName, getUserId());
Jeff Sharkey6c833e02014-07-14 22:44:30 -07002893 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002894 throw e.rethrowFromSystemServer();
Jeff Sharkey6c833e02014-07-14 22:44:30 -07002895 }
2896 }
2897
Nicolas Prevotc79586e2014-05-06 12:47:57 +01002898 /**
2899 * @hide
2900 */
2901 @Override
Nicolas Prevot63798c52014-05-27 13:22:38 +01002902 public void addCrossProfileIntentFilter(IntentFilter filter, int sourceUserId, int targetUserId,
2903 int flags) {
Nicolas Prevotc79586e2014-05-06 12:47:57 +01002904 try {
Nicolas Prevot3f7777f2014-07-24 15:58:39 +01002905 mPM.addCrossProfileIntentFilter(filter, mContext.getOpPackageName(),
Nicolas Prevot4b8d5822015-03-05 15:20:49 +00002906 sourceUserId, targetUserId, flags);
Nicolas Prevotc79586e2014-05-06 12:47:57 +01002907 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002908 throw e.rethrowFromSystemServer();
Nicolas Prevotc79586e2014-05-06 12:47:57 +01002909 }
2910 }
2911
2912 /**
2913 * @hide
2914 */
2915 @Override
Nicolas Prevot81948992014-05-16 18:25:26 +01002916 public void clearCrossProfileIntentFilters(int sourceUserId) {
Nicolas Prevotc79586e2014-05-06 12:47:57 +01002917 try {
Nicolas Prevot4b8d5822015-03-05 15:20:49 +00002918 mPM.clearCrossProfileIntentFilters(sourceUserId, mContext.getOpPackageName());
Nicolas Prevotc79586e2014-05-06 12:47:57 +01002919 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002920 throw e.rethrowFromSystemServer();
Nicolas Prevotc79586e2014-05-06 12:47:57 +01002921 }
2922 }
2923
Nicolas Prevot88cc3462014-05-14 14:51:48 +01002924 /**
2925 * @hide
2926 */
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +01002927 public Drawable loadItemIcon(PackageItemInfo itemInfo, ApplicationInfo appInfo) {
Benjamin Franzec2d48b2014-10-01 15:38:43 +01002928 Drawable dr = loadUnbadgedItemIcon(itemInfo, appInfo);
2929 if (itemInfo.showUserIcon != UserHandle.USER_NULL) {
2930 return dr;
2931 }
Jeff Sharkeyc59a5e72018-06-21 19:14:58 -06002932 return getUserBadgedIcon(dr, new UserHandle(getUserId()));
Benjamin Franzec2d48b2014-10-01 15:38:43 +01002933 }
2934
2935 /**
2936 * @hide
2937 */
Winson41605232019-05-06 11:53:30 -07002938 public Drawable loadUnbadgedItemIcon(@NonNull PackageItemInfo itemInfo,
2939 @Nullable ApplicationInfo appInfo) {
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +01002940 if (itemInfo.showUserIcon != UserHandle.USER_NULL) {
Alan Stokescae316d2019-11-26 09:39:02 +00002941 // Indicates itemInfo is for a different user (e.g. a profile's parent), so use a
Bookatz9313af62019-06-04 09:14:42 -07002942 // generic user icon (users generally lack permission to view each other's actual icons)
2943 int targetUserId = itemInfo.showUserIcon;
2944 return UserIcons.getDefaultUserIcon(
2945 mContext.getResources(), targetUserId, /* light= */ false);
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +01002946 }
Alexandra Gherghinadb811db2014-08-29 13:43:59 +01002947 Drawable dr = null;
2948 if (itemInfo.packageName != null) {
2949 dr = getDrawable(itemInfo.packageName, itemInfo.icon, appInfo);
2950 }
Winson41605232019-05-06 11:53:30 -07002951 if (dr == null && itemInfo != appInfo && appInfo != null) {
Patrick Baumanne34a75d2019-04-30 11:18:04 -07002952 dr = loadUnbadgedItemIcon(appInfo, appInfo);
2953 }
Alexandra Gherghinaa71e3902014-07-25 20:03:47 +01002954 if (dr == null) {
Alexandra Gherghinaa7093142014-07-30 13:43:39 +01002955 dr = itemInfo.loadDefaultIcon(this);
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +01002956 }
Benjamin Franzec2d48b2014-10-01 15:38:43 +01002957 return dr;
Svetoslavc7d62f02014-09-04 15:39:54 -07002958 }
2959
2960 private Drawable getBadgedDrawable(Drawable drawable, Drawable badgeDrawable,
2961 Rect badgeLocation, boolean tryBadgeInPlace) {
2962 final int badgedWidth = drawable.getIntrinsicWidth();
2963 final int badgedHeight = drawable.getIntrinsicHeight();
2964 final boolean canBadgeInPlace = tryBadgeInPlace
2965 && (drawable instanceof BitmapDrawable)
2966 && ((BitmapDrawable) drawable).getBitmap().isMutable();
2967
2968 final Bitmap bitmap;
2969 if (canBadgeInPlace) {
2970 bitmap = ((BitmapDrawable) drawable).getBitmap();
2971 } else {
2972 bitmap = Bitmap.createBitmap(badgedWidth, badgedHeight, Bitmap.Config.ARGB_8888);
2973 }
2974 Canvas canvas = new Canvas(bitmap);
2975
2976 if (!canBadgeInPlace) {
2977 drawable.setBounds(0, 0, badgedWidth, badgedHeight);
2978 drawable.draw(canvas);
2979 }
2980
2981 if (badgeLocation != null) {
2982 if (badgeLocation.left < 0 || badgeLocation.top < 0
2983 || badgeLocation.width() > badgedWidth || badgeLocation.height() > badgedHeight) {
2984 throw new IllegalArgumentException("Badge location " + badgeLocation
2985 + " not in badged drawable bounds "
2986 + new Rect(0, 0, badgedWidth, badgedHeight));
2987 }
2988 badgeDrawable.setBounds(0, 0, badgeLocation.width(), badgeLocation.height());
2989
2990 canvas.save();
2991 canvas.translate(badgeLocation.left, badgeLocation.top);
2992 badgeDrawable.draw(canvas);
2993 canvas.restore();
2994 } else {
2995 badgeDrawable.setBounds(0, 0, badgedWidth, badgedHeight);
2996 badgeDrawable.draw(canvas);
2997 }
2998
2999 if (!canBadgeInPlace) {
3000 BitmapDrawable mergedDrawable = new BitmapDrawable(mContext.getResources(), bitmap);
3001
3002 if (drawable instanceof BitmapDrawable) {
3003 BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
3004 mergedDrawable.setTargetDensity(bitmapDrawable.getBitmap().getDensity());
3005 }
3006
3007 return mergedDrawable;
3008 }
3009
3010 return drawable;
3011 }
3012
Bookatz029832a2019-10-04 16:50:22 -07003013 private boolean hasUserBadge(int userId) {
3014 return getUserManager().hasBadge(userId);
Nicolas Prevot88cc3462014-05-14 14:51:48 +01003015 }
3016
Bartosz Fabianowskia34f53f2017-01-11 18:08:47 +01003017 /**
3018 * @hide
3019 */
3020 @Override
3021 public int getInstallReason(String packageName, UserHandle user) {
3022 try {
3023 return mPM.getInstallReason(packageName, user.getIdentifier());
3024 } catch (RemoteException e) {
3025 throw e.rethrowFromSystemServer();
3026 }
3027 }
3028
Jeff Sharkey620b32b2015-04-23 19:36:02 -07003029 /** {@hide} */
3030 private static class MoveCallbackDelegate extends IPackageMoveObserver.Stub implements
3031 Handler.Callback {
Jeff Sharkey50a05452015-04-29 11:24:52 -07003032 private static final int MSG_CREATED = 1;
3033 private static final int MSG_STATUS_CHANGED = 2;
Jeff Sharkey620b32b2015-04-23 19:36:02 -07003034
3035 final MoveCallback mCallback;
3036 final Handler mHandler;
3037
3038 public MoveCallbackDelegate(MoveCallback callback, Looper looper) {
3039 mCallback = callback;
3040 mHandler = new Handler(looper, this);
3041 }
3042
3043 @Override
3044 public boolean handleMessage(Message msg) {
Jeff Sharkey620b32b2015-04-23 19:36:02 -07003045 switch (msg.what) {
Jeff Sharkey50a05452015-04-29 11:24:52 -07003046 case MSG_CREATED: {
Jeff Sharkeyb36586a2015-04-27 08:42:28 -07003047 final SomeArgs args = (SomeArgs) msg.obj;
Jeff Sharkey50a05452015-04-29 11:24:52 -07003048 mCallback.onCreated(args.argi1, (Bundle) args.arg2);
Jeff Sharkeyb36586a2015-04-27 08:42:28 -07003049 args.recycle();
Jeff Sharkey620b32b2015-04-23 19:36:02 -07003050 return true;
Jeff Sharkey50a05452015-04-29 11:24:52 -07003051 }
3052 case MSG_STATUS_CHANGED: {
3053 final SomeArgs args = (SomeArgs) msg.obj;
3054 mCallback.onStatusChanged(args.argi1, args.argi2, (long) args.arg3);
3055 args.recycle();
3056 return true;
3057 }
Jeff Sharkey620b32b2015-04-23 19:36:02 -07003058 }
3059 return false;
3060 }
3061
3062 @Override
Jeff Sharkey50a05452015-04-29 11:24:52 -07003063 public void onCreated(int moveId, Bundle extras) {
Jeff Sharkeyb36586a2015-04-27 08:42:28 -07003064 final SomeArgs args = SomeArgs.obtain();
3065 args.argi1 = moveId;
Jeff Sharkey50a05452015-04-29 11:24:52 -07003066 args.arg2 = extras;
3067 mHandler.obtainMessage(MSG_CREATED, args).sendToTarget();
3068 }
3069
3070 @Override
3071 public void onStatusChanged(int moveId, int status, long estMillis) {
3072 final SomeArgs args = SomeArgs.obtain();
3073 args.argi1 = moveId;
3074 args.argi2 = status;
3075 args.arg3 = estMillis;
Jeff Sharkeyb36586a2015-04-27 08:42:28 -07003076 mHandler.obtainMessage(MSG_STATUS_CHANGED, args).sendToTarget();
Jeff Sharkey620b32b2015-04-23 19:36:02 -07003077 }
3078 }
3079
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08003080 private final ContextImpl mContext;
Mathew Inwood61e8ae62018-08-14 14:17:44 +01003081 @UnsupportedAppUsage
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08003082 private final IPackageManager mPM;
Todd Kennedy8f135982019-07-02 07:35:15 -07003083 private final IPermissionManager mPermissionManager;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08003084
Jeff Sharkeyc59a5e72018-06-21 19:14:58 -06003085 /** Assume locked until we hear otherwise */
3086 private volatile boolean mUserUnlocked = false;
3087
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08003088 private static final Object sSync = new Object();
Dianne Hackbornadd005c2013-07-17 18:43:12 -07003089 private static ArrayMap<ResourceName, WeakReference<Drawable.ConstantState>> sIconCache
3090 = new ArrayMap<ResourceName, WeakReference<Drawable.ConstantState>>();
3091 private static ArrayMap<ResourceName, WeakReference<CharSequence>> sStringCache
3092 = new ArrayMap<ResourceName, WeakReference<CharSequence>>();
Svetoslavf7c06eb2015-06-10 18:43:22 -07003093
3094 private final Map<OnPermissionsChangedListener, IOnPermissionsChangeListener>
3095 mPermissionListeners = new ArrayMap<>();
3096
3097 public class OnPermissionsChangeListenerDelegate extends IOnPermissionsChangeListener.Stub
3098 implements Handler.Callback{
3099 private static final int MSG_PERMISSIONS_CHANGED = 1;
3100
3101 private final OnPermissionsChangedListener mListener;
3102 private final Handler mHandler;
3103
3104
3105 public OnPermissionsChangeListenerDelegate(OnPermissionsChangedListener listener,
3106 Looper looper) {
3107 mListener = listener;
3108 mHandler = new Handler(looper, this);
3109 }
3110
3111 @Override
3112 public void onPermissionsChanged(int uid) {
3113 mHandler.obtainMessage(MSG_PERMISSIONS_CHANGED, uid, 0).sendToTarget();
3114 }
3115
3116 @Override
3117 public boolean handleMessage(Message msg) {
3118 switch (msg.what) {
3119 case MSG_PERMISSIONS_CHANGED: {
3120 final int uid = msg.arg1;
3121 mListener.onPermissionsChanged(uid);
3122 return true;
3123 }
3124 }
3125 return false;
3126 }
3127 }
Suprabh Shuklaaef25132017-01-23 18:09:03 -08003128
3129 @Override
3130 public boolean canRequestPackageInstalls() {
3131 try {
Jeff Sharkeyc59a5e72018-06-21 19:14:58 -06003132 return mPM.canRequestPackageInstalls(mContext.getPackageName(), getUserId());
Suprabh Shuklaaef25132017-01-23 18:09:03 -08003133 } catch (RemoteException e) {
3134 throw e.rethrowAsRuntimeException();
3135 }
3136 }
Chad Brubaker336ae5b2017-03-24 15:53:09 -07003137
3138 @Override
3139 public ComponentName getInstantAppResolverSettingsComponent() {
3140 try {
3141 return mPM.getInstantAppResolverSettingsComponent();
3142 } catch (RemoteException e) {
3143 throw e.rethrowAsRuntimeException();
3144 }
3145 }
Todd Kennedy801e6592017-04-12 14:10:12 -07003146
3147 @Override
3148 public ComponentName getInstantAppInstallerComponent() {
3149 try {
3150 return mPM.getInstantAppInstallerComponent();
3151 } catch (RemoteException e) {
3152 throw e.rethrowAsRuntimeException();
3153 }
3154 }
Chad Brubaker0d277a72017-04-12 16:56:53 -07003155
3156 @Override
3157 public String getInstantAppAndroidId(String packageName, UserHandle user) {
3158 try {
3159 return mPM.getInstantAppAndroidId(packageName, user.getIdentifier());
3160 } catch (RemoteException e) {
3161 throw e.rethrowAsRuntimeException();
3162 }
3163 }
Calin Juravle3d2af7f2017-04-19 19:56:21 -07003164
3165 private static class DexModuleRegisterResult {
3166 final String dexModulePath;
3167 final boolean success;
3168 final String message;
3169
3170 private DexModuleRegisterResult(String dexModulePath, boolean success, String message) {
3171 this.dexModulePath = dexModulePath;
3172 this.success = success;
3173 this.message = message;
3174 }
3175 }
3176
3177 private static class DexModuleRegisterCallbackDelegate
3178 extends android.content.pm.IDexModuleRegisterCallback.Stub
3179 implements Handler.Callback {
3180 private static final int MSG_DEX_MODULE_REGISTERED = 1;
3181 private final DexModuleRegisterCallback callback;
3182 private final Handler mHandler;
3183
3184 DexModuleRegisterCallbackDelegate(@NonNull DexModuleRegisterCallback callback) {
3185 this.callback = callback;
3186 mHandler = new Handler(Looper.getMainLooper(), this);
3187 }
3188
3189 @Override
3190 public void onDexModuleRegistered(@NonNull String dexModulePath, boolean success,
3191 @Nullable String message)throws RemoteException {
3192 mHandler.obtainMessage(MSG_DEX_MODULE_REGISTERED,
3193 new DexModuleRegisterResult(dexModulePath, success, message)).sendToTarget();
3194 }
3195
3196 @Override
3197 public boolean handleMessage(Message msg) {
3198 if (msg.what != MSG_DEX_MODULE_REGISTERED) {
3199 return false;
3200 }
3201 DexModuleRegisterResult result = (DexModuleRegisterResult)msg.obj;
3202 callback.onDexModuleRegistered(result.dexModulePath, result.success, result.message);
3203 return true;
3204 }
3205 }
3206
3207 @Override
3208 public void registerDexModule(@NonNull String dexModule,
3209 @Nullable DexModuleRegisterCallback callback) {
3210 // Check if this is a shared module by looking if the others can read it.
3211 boolean isSharedModule = false;
3212 try {
3213 StructStat stat = Os.stat(dexModule);
3214 if ((OsConstants.S_IROTH & stat.st_mode) != 0) {
3215 isSharedModule = true;
3216 }
3217 } catch (ErrnoException e) {
3218 callback.onDexModuleRegistered(dexModule, false,
3219 "Could not get stat the module file: " + e.getMessage());
3220 return;
3221 }
3222
3223 // Module path is ok.
3224 // Create the callback delegate to be passed to package manager service.
3225 DexModuleRegisterCallbackDelegate callbackDelegate = null;
3226 if (callback != null) {
3227 callbackDelegate = new DexModuleRegisterCallbackDelegate(callback);
3228 }
3229
3230 // Invoke the package manager service.
3231 try {
3232 mPM.registerDexModule(mContext.getPackageName(), dexModule,
3233 isSharedModule, callbackDelegate);
3234 } catch (RemoteException e) {
3235 throw e.rethrowAsRuntimeException();
3236 }
3237 }
Calin Juravle45f8b292017-11-07 18:49:43 -08003238
3239 @Override
Ben Gruver1ab3d6e2017-12-07 13:45:08 -08003240 public CharSequence getHarmfulAppWarning(String packageName) {
3241 try {
Jeff Sharkeyc59a5e72018-06-21 19:14:58 -06003242 return mPM.getHarmfulAppWarning(packageName, getUserId());
Ben Gruver1ab3d6e2017-12-07 13:45:08 -08003243 } catch (RemoteException e) {
3244 throw e.rethrowAsRuntimeException();
3245 }
3246 }
3247
3248 @Override
3249 public void setHarmfulAppWarning(String packageName, CharSequence warning) {
3250 try {
Jeff Sharkeyc59a5e72018-06-21 19:14:58 -06003251 mPM.setHarmfulAppWarning(packageName, warning, getUserId());
Ben Gruver1ab3d6e2017-12-07 13:45:08 -08003252 } catch (RemoteException e) {
3253 throw e.rethrowAsRuntimeException();
3254 }
3255 }
3256
3257 @Override
Calin Juravle45f8b292017-11-07 18:49:43 -08003258 public ArtManager getArtManager() {
3259 synchronized (mLock) {
3260 if (mArtManager == null) {
3261 try {
Jeff Sharkey0ad62832018-04-19 11:20:57 -06003262 mArtManager = new ArtManager(mContext, mPM.getArtManager());
Calin Juravle45f8b292017-11-07 18:49:43 -08003263 } catch (RemoteException e) {
3264 throw e.rethrowFromSystemServer();
3265 }
3266 }
3267 return mArtManager;
3268 }
3269 }
Makoto Onuki700feef2018-02-15 10:59:41 -08003270
3271 @Override
Tony Makc5a74322020-02-04 17:18:15 +00003272 public String getDefaultTextClassifierPackageName() {
Makoto Onuki700feef2018-02-15 10:59:41 -08003273 try {
Tony Makc5a74322020-02-04 17:18:15 +00003274 return mPM.getDefaultTextClassifierPackageName();
Makoto Onuki700feef2018-02-15 10:59:41 -08003275 } catch (RemoteException e) {
3276 throw e.rethrowAsRuntimeException();
3277 }
3278 }
Benjamin Franz7cc9a812018-03-22 10:11:29 +00003279
3280 @Override
Tony Makc5a74322020-02-04 17:18:15 +00003281 public String getSystemTextClassifierPackageName() {
Joanne Chungb50ab4b2019-10-14 16:40:57 +08003282 try {
Tony Makc5a74322020-02-04 17:18:15 +00003283 return mPM.getSystemTextClassifierPackageName();
Joanne Chungb50ab4b2019-10-14 16:40:57 +08003284 } catch (RemoteException e) {
3285 throw e.rethrowAsRuntimeException();
3286 }
3287 }
3288
3289 @Override
Yi Jiang8915b352019-03-21 12:02:53 -07003290 public String getAttentionServicePackageName() {
3291 try {
3292 return mPM.getAttentionServicePackageName();
3293 } catch (RemoteException e) {
3294 throw e.rethrowAsRuntimeException();
3295 }
3296 }
3297
3298 @Override
Varun Shah5f303652018-11-16 18:11:19 -08003299 public String getWellbeingPackageName() {
3300 try {
3301 return mPM.getWellbeingPackageName();
3302 } catch (RemoteException e) {
3303 throw e.rethrowAsRuntimeException();
3304 }
3305 }
3306
3307 @Override
George Hodulikcd7695d2019-01-29 18:17:05 -08003308 public String getAppPredictionServicePackageName() {
3309 try {
3310 return mPM.getAppPredictionServicePackageName();
3311 } catch (RemoteException e) {
3312 throw e.rethrowAsRuntimeException();
3313 }
3314 }
3315
3316 @Override
Nadav Bar1a1f5a212019-03-17 16:15:14 +02003317 public String getSystemCaptionsServicePackageName() {
Nadav Bar6d79ab72019-01-10 10:52:11 +02003318 try {
Nadav Bar1a1f5a212019-03-17 16:15:14 +02003319 return mPM.getSystemCaptionsServicePackageName();
Nadav Bar6d79ab72019-01-10 10:52:11 +02003320 } catch (RemoteException e) {
3321 throw e.rethrowAsRuntimeException();
3322 }
3323 }
3324
3325 @Override
Christopher Tatee4f5f2d2019-10-08 15:49:43 -07003326 public String getSetupWizardPackageName() {
3327 try {
3328 return mPM.getSetupWizardPackageName();
3329 } catch (RemoteException e) {
3330 throw e.rethrowAsRuntimeException();
3331 }
3332 }
3333
3334 @Override
Joe Onorato5a15b552018-12-18 10:40:04 -08003335 public String getIncidentReportApproverPackageName() {
3336 try {
3337 return mPM.getIncidentReportApproverPackageName();
3338 } catch (RemoteException e) {
3339 throw e.rethrowAsRuntimeException();
3340 }
3341 }
3342
3343 @Override
Joanne Chungfba3e882019-08-20 18:47:38 +08003344 public String getContentCaptureServicePackageName() {
3345 try {
3346 return mPM.getContentCaptureServicePackageName();
3347 } catch (RemoteException e) {
3348 throw e.rethrowAsRuntimeException();
3349 }
3350 }
3351
3352 @Override
Benjamin Franz7cc9a812018-03-22 10:11:29 +00003353 public boolean isPackageStateProtected(String packageName, int userId) {
3354 try {
3355 return mPM.isPackageStateProtected(packageName, userId);
3356 } catch (RemoteException e) {
3357 throw e.rethrowAsRuntimeException();
3358 }
3359 }
Mårten Kongstadfd20b832018-10-26 15:36:20 +02003360
Mårten Kongstadfd20b832018-10-26 15:36:20 +02003361 public void sendDeviceCustomizationReadyBroadcast() {
3362 try {
3363 mPM.sendDeviceCustomizationReadyBroadcast();
3364 } catch (RemoteException e) {
3365 throw e.rethrowAsRuntimeException();
3366 }
3367 }
Taras Antoshchuka7d9c732019-10-29 13:46:19 +01003368
Eugene Susla2ac02b02020-03-10 12:18:21 -07003369 @Override
3370 public boolean isAutoRevokeWhitelisted() {
3371 try {
3372 return mPM.isAutoRevokeWhitelisted(mContext.getPackageName());
3373 } catch (RemoteException e) {
3374 throw e.rethrowAsRuntimeException();
3375 }
3376 }
3377
Taras Antoshchuk8a600242020-03-17 22:56:54 +01003378 @Override
Taras Antoshchuka7d9c732019-10-29 13:46:19 +01003379 public void setMimeGroup(String mimeGroup, Set<String> mimeTypes) {
3380 try {
Taras Antoshchuk8a600242020-03-17 22:56:54 +01003381 mPM.setMimeGroup(mContext.getPackageName(), mimeGroup, new ArrayList<>(mimeTypes));
Taras Antoshchuka7d9c732019-10-29 13:46:19 +01003382 } catch (RemoteException e) {
3383 throw e.rethrowAsRuntimeException();
3384 }
3385 }
3386
Taras Antoshchuk8a600242020-03-17 22:56:54 +01003387 @NonNull
Taras Antoshchuka7d9c732019-10-29 13:46:19 +01003388 @Override
3389 public Set<String> getMimeGroup(String group) {
3390 try {
3391 List<String> mimeGroup = mPM.getMimeGroup(mContext.getPackageName(), group);
Taras Antoshchuka7d9c732019-10-29 13:46:19 +01003392 return new ArraySet<>(mimeGroup);
3393 } catch (RemoteException e) {
3394 throw e.rethrowAsRuntimeException();
3395 }
3396 }
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08003397}