blob: cd50531a327f7a37eaa6de1e3952f7c05f1e91b8 [file] [log] [blame]
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001/*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.app;
18
Tor Norbye7b9c9122013-05-30 16:48:33 -070019import android.annotation.DrawableRes;
Alan Viveretteecd585a2015-04-13 10:32:51 -070020import android.annotation.NonNull;
21import android.annotation.Nullable;
Tor Norbye7b9c9122013-05-30 16:48:33 -070022import android.annotation.StringRes;
23import android.annotation.XmlRes;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080024import android.content.ComponentName;
25import android.content.ContentResolver;
Yao Chen022b8ea2016-12-16 11:03:28 -080026import android.content.Context;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080027import android.content.Intent;
28import android.content.IntentFilter;
29import android.content.IntentSender;
30import android.content.pm.ActivityInfo;
31import android.content.pm.ApplicationInfo;
Todd Kennedy9106c642017-02-08 14:16:53 -080032import android.content.pm.ChangedPackages;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080033import android.content.pm.ComponentInfo;
34import android.content.pm.FeatureInfo;
Svetoslavf7c06eb2015-06-10 18:43:22 -070035import android.content.pm.IOnPermissionsChangeListener;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080036import android.content.pm.IPackageDataObserver;
37import android.content.pm.IPackageDeleteObserver;
38import android.content.pm.IPackageInstallObserver;
39import android.content.pm.IPackageManager;
40import android.content.pm.IPackageMoveObserver;
41import android.content.pm.IPackageStatsObserver;
Todd Kennedy9da8b8a72017-07-25 15:38:39 -070042import android.content.pm.InstantAppInfo;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080043import android.content.pm.InstrumentationInfo;
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -080044import android.content.pm.IntentFilterVerificationInfo;
dcashman9d2f4412014-06-09 09:27:54 -070045import android.content.pm.KeySet;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080046import android.content.pm.PackageInfo;
Jeff Sharkey3a44f3f2014-04-28 17:36:31 -070047import android.content.pm.PackageInstaller;
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +010048import android.content.pm.PackageItemInfo;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080049import android.content.pm.PackageManager;
Kenny Roote6cd0c72011-05-19 12:48:14 -070050import android.content.pm.ParceledListSlice;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080051import android.content.pm.PermissionGroupInfo;
52import android.content.pm.PermissionInfo;
53import android.content.pm.ProviderInfo;
54import android.content.pm.ResolveInfo;
55import android.content.pm.ServiceInfo;
Svet Ganov67882122016-12-11 16:36:34 -080056import android.content.pm.SharedLibraryInfo;
Kenny Root0aaa0d92011-09-12 16:42:55 -070057import android.content.pm.VerifierDeviceIdentity;
Svet Ganov67882122016-12-11 16:36:34 -080058import android.content.pm.VersionedPackage;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080059import android.content.res.Resources;
60import android.content.res.XmlResourceParser;
Svetoslavc7d62f02014-09-04 15:39:54 -070061import android.graphics.Bitmap;
62import android.graphics.Canvas;
63import android.graphics.Rect;
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +010064import android.graphics.drawable.BitmapDrawable;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080065import android.graphics.drawable.Drawable;
Kenny Guy02c89902016-11-15 19:36:38 +000066import android.graphics.drawable.LayerDrawable;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080067import android.net.Uri;
Jeff Sharkeye6306c42017-03-07 21:03:18 -070068import android.os.Build;
Jeff Sharkey50a05452015-04-29 11:24:52 -070069import android.os.Bundle;
Jeff Sharkey620b32b2015-04-23 19:36:02 -070070import android.os.Handler;
71import android.os.Looper;
72import android.os.Message;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080073import android.os.Process;
74import android.os.RemoteException;
Jeff Sharkeyb2b9ab82015-04-05 21:10:42 -070075import android.os.SystemProperties;
Amith Yamasani67df64b2012-12-14 12:09:36 -080076import android.os.UserHandle;
Nicolas Prevot88cc3462014-05-14 14:51:48 +010077import android.os.UserManager;
Jeff Sharkeye2d45be2015-04-15 17:14:12 -070078import android.os.storage.StorageManager;
79import android.os.storage.VolumeInfo;
Todd Kennedyf39ca8f2015-08-07 14:15:07 -070080import android.provider.Settings;
Calin Juravle3d2af7f2017-04-19 19:56:21 -070081import android.system.ErrnoException;
82import android.system.Os;
83import android.system.OsConstants;
84import android.system.StructStat;
Dianne Hackbornadd005c2013-07-17 18:43:12 -070085import android.util.ArrayMap;
Sunny Goyalbab30752017-04-12 15:36:42 -070086import android.util.IconDrawableFactory;
87import android.util.LauncherIcons;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -080088import android.util.Log;
Jeff Browna492c3a2012-08-23 19:48:44 -070089import android.view.Display;
Jeff Sharkeyb2b9ab82015-04-05 21:10:42 -070090
Jeff Sharkey16c8e3f2014-07-24 17:08:17 -070091import com.android.internal.annotations.GuardedBy;
Kenny Guy02c89902016-11-15 19:36:38 +000092import com.android.internal.annotations.VisibleForTesting;
Jeff Sharkeyb36586a2015-04-27 08:42:28 -070093import com.android.internal.os.SomeArgs;
dcashman9d2f4412014-06-09 09:27:54 -070094import com.android.internal.util.Preconditions;
Alexandra Gherghina64d4dca2014-08-28 18:26:56 +010095import com.android.internal.util.UserIcons;
Todd Kennedy9da8b8a72017-07-25 15:38:39 -070096
97import dalvik.system.VMRuntime;
98
Svet Ganov2acf0632015-11-24 19:10:59 -080099import libcore.util.EmptyArray;
Jeff Sharkey16c8e3f2014-07-24 17:08:17 -0700100
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800101import java.lang.ref.WeakReference;
102import java.util.ArrayList;
Svet Ganov2acf0632015-11-24 19:10:59 -0800103import java.util.Collections;
Jeff Sharkey620b32b2015-04-23 19:36:02 -0700104import java.util.Iterator;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800105import java.util.List;
Svetoslavf7c06eb2015-06-10 18:43:22 -0700106import java.util.Map;
Jeff Sharkey620b32b2015-04-23 19:36:02 -0700107import java.util.Objects;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800108
Makoto Onukicc4bbeb2015-09-17 10:28:24 -0700109/** @hide */
110public class ApplicationPackageManager extends PackageManager {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800111 private static final String TAG = "ApplicationPackageManager";
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800112 private final static boolean DEBUG_ICONS = false;
113
Svet Ganov2acf0632015-11-24 19:10:59 -0800114 private static final int DEFAULT_EPHEMERAL_COOKIE_MAX_SIZE_BYTES = 16384; // 16KB
115
Adam Lesinskid00bb5e2014-10-07 12:14:45 -0700116 // Default flags to use with PackageManager when no flags are given.
117 private final static int sDefaultFlags = PackageManager.GET_SHARED_LIBRARY_FILES;
118
Jeff Sharkey16c8e3f2014-07-24 17:08:17 -0700119 private final Object mLock = new Object();
120
121 @GuardedBy("mLock")
122 private UserManager mUserManager;
123 @GuardedBy("mLock")
124 private PackageInstaller mInstaller;
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +0100125
Jeff Sharkey620b32b2015-04-23 19:36:02 -0700126 @GuardedBy("mDelegates")
127 private final ArrayList<MoveCallbackDelegate> mDelegates = new ArrayList<>();
128
Svet Ganovf1b7f202015-07-29 08:33:42 -0700129 @GuardedBy("mLock")
130 private String mPermissionsControllerPackageName;
131
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +0100132 UserManager getUserManager() {
Jeff Sharkey16c8e3f2014-07-24 17:08:17 -0700133 synchronized (mLock) {
134 if (mUserManager == null) {
135 mUserManager = UserManager.get(mContext);
136 }
137 return mUserManager;
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +0100138 }
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +0100139 }
140
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800141 @Override
142 public PackageInfo getPackageInfo(String packageName, int flags)
143 throws NameNotFoundException {
Nicolas Prevot9a80e532015-09-23 15:49:28 +0100144 return getPackageInfoAsUser(packageName, flags, mContext.getUserId());
145 }
146
147 @Override
Svet Ganov67882122016-12-11 16:36:34 -0800148 public PackageInfo getPackageInfo(VersionedPackage versionedPackage, int flags)
149 throws NameNotFoundException {
150 try {
151 PackageInfo pi = mPM.getPackageInfoVersioned(versionedPackage, flags,
152 mContext.getUserId());
153 if (pi != null) {
154 return pi;
155 }
156 } catch (RemoteException e) {
157 throw e.rethrowFromSystemServer();
158 }
159 throw new NameNotFoundException(versionedPackage.toString());
160 }
161
162 @Override
Nicolas Prevot9a80e532015-09-23 15:49:28 +0100163 public PackageInfo getPackageInfoAsUser(String packageName, int flags, int userId)
164 throws NameNotFoundException {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800165 try {
Nicolas Prevot9a80e532015-09-23 15:49:28 +0100166 PackageInfo pi = mPM.getPackageInfo(packageName, flags, userId);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800167 if (pi != null) {
168 return pi;
169 }
170 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700171 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800172 }
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800173 throw new NameNotFoundException(packageName);
174 }
175
176 @Override
177 public String[] currentToCanonicalPackageNames(String[] names) {
178 try {
179 return mPM.currentToCanonicalPackageNames(names);
180 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700181 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800182 }
183 }
184
185 @Override
186 public String[] canonicalToCurrentPackageNames(String[] names) {
187 try {
188 return mPM.canonicalToCurrentPackageNames(names);
189 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700190 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800191 }
192 }
193
194 @Override
195 public Intent getLaunchIntentForPackage(String packageName) {
196 // First see if the package has an INFO activity; the existence of
197 // such an activity is implied to be the desired front-door for the
198 // overall package (such as if it has multiple launcher entries).
199 Intent intentToResolve = new Intent(Intent.ACTION_MAIN);
200 intentToResolve.addCategory(Intent.CATEGORY_INFO);
201 intentToResolve.setPackage(packageName);
Dianne Hackborn19415762010-12-15 00:20:27 -0800202 List<ResolveInfo> ris = queryIntentActivities(intentToResolve, 0);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800203
204 // Otherwise, try to find a main launcher activity.
Dianne Hackborn19415762010-12-15 00:20:27 -0800205 if (ris == null || ris.size() <= 0) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800206 // reuse the intent instance
207 intentToResolve.removeCategory(Intent.CATEGORY_INFO);
208 intentToResolve.addCategory(Intent.CATEGORY_LAUNCHER);
209 intentToResolve.setPackage(packageName);
Dianne Hackborn19415762010-12-15 00:20:27 -0800210 ris = queryIntentActivities(intentToResolve, 0);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800211 }
Dianne Hackborn19415762010-12-15 00:20:27 -0800212 if (ris == null || ris.size() <= 0) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800213 return null;
214 }
215 Intent intent = new Intent(intentToResolve);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800216 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Dianne Hackborn19415762010-12-15 00:20:27 -0800217 intent.setClassName(ris.get(0).activityInfo.packageName,
218 ris.get(0).activityInfo.name);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800219 return intent;
220 }
221
222 @Override
Jose Lima970417c2014-04-10 10:42:19 -0700223 public Intent getLeanbackLaunchIntentForPackage(String packageName) {
224 // Try to find a main leanback_launcher activity.
225 Intent intentToResolve = new Intent(Intent.ACTION_MAIN);
226 intentToResolve.addCategory(Intent.CATEGORY_LEANBACK_LAUNCHER);
227 intentToResolve.setPackage(packageName);
228 List<ResolveInfo> ris = queryIntentActivities(intentToResolve, 0);
229
230 if (ris == null || ris.size() <= 0) {
231 return null;
232 }
233 Intent intent = new Intent(intentToResolve);
234 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
235 intent.setClassName(ris.get(0).activityInfo.packageName,
236 ris.get(0).activityInfo.name);
237 return intent;
238 }
239
240 @Override
Jeff Sharkey8588bc12016-01-06 16:47:42 -0700241 public int[] getPackageGids(String packageName) throws NameNotFoundException {
242 return getPackageGids(packageName, 0);
243 }
244
245 @Override
246 public int[] getPackageGids(String packageName, int flags)
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800247 throws NameNotFoundException {
248 try {
Jeff Sharkeycd654482016-01-08 17:42:11 -0700249 int[] gids = mPM.getPackageGids(packageName, flags, mContext.getUserId());
Svetoslavc6d1c342015-02-26 14:44:43 -0800250 if (gids != null) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800251 return gids;
252 }
253 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700254 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800255 }
256
257 throw new NameNotFoundException(packageName);
258 }
259
260 @Override
Jeff Sharkey8588bc12016-01-06 16:47:42 -0700261 public int getPackageUid(String packageName, int flags) throws NameNotFoundException {
262 return getPackageUidAsUser(packageName, flags, mContext.getUserId());
263 }
264
265 @Override
266 public int getPackageUidAsUser(String packageName, int userId) throws NameNotFoundException {
267 return getPackageUidAsUser(packageName, 0, userId);
268 }
269
270 @Override
271 public int getPackageUidAsUser(String packageName, int flags, int userId)
Dianne Hackborna06de0f2012-12-11 16:34:47 -0800272 throws NameNotFoundException {
273 try {
Jeff Sharkeycd654482016-01-08 17:42:11 -0700274 int uid = mPM.getPackageUid(packageName, flags, userId);
Dianne Hackborna06de0f2012-12-11 16:34:47 -0800275 if (uid >= 0) {
276 return uid;
277 }
278 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700279 throw e.rethrowFromSystemServer();
Dianne Hackborna06de0f2012-12-11 16:34:47 -0800280 }
281
282 throw new NameNotFoundException(packageName);
283 }
284
285 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800286 public PermissionInfo getPermissionInfo(String name, int flags)
287 throws NameNotFoundException {
288 try {
Svetoslav Ganovadb8c522017-07-28 05:46:53 +0000289 PermissionInfo pi = mPM.getPermissionInfo(name,
290 mContext.getOpPackageName(), flags);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800291 if (pi != null) {
292 return pi;
293 }
294 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700295 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800296 }
297
298 throw new NameNotFoundException(name);
299 }
300
301 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700302 @SuppressWarnings("unchecked")
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800303 public List<PermissionInfo> queryPermissionsByGroup(String group, int flags)
304 throws NameNotFoundException {
305 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700306 ParceledListSlice<PermissionInfo> parceledList =
307 mPM.queryPermissionsByGroup(group, flags);
308 if (parceledList != null) {
309 List<PermissionInfo> pi = parceledList.getList();
310 if (pi != null) {
311 return pi;
312 }
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800313 }
314 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700315 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800316 }
317
318 throw new NameNotFoundException(group);
319 }
320
321 @Override
Paul Navin7b89a7b2017-01-26 23:56:08 +0000322 public boolean isPermissionReviewModeEnabled() {
323 return mContext.getResources().getBoolean(
324 com.android.internal.R.bool.config_permissionReviewRequired);
325 }
326
327 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800328 public PermissionGroupInfo getPermissionGroupInfo(String name,
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700329 int flags) throws NameNotFoundException {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800330 try {
331 PermissionGroupInfo pgi = mPM.getPermissionGroupInfo(name, flags);
332 if (pgi != null) {
333 return pgi;
334 }
335 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700336 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800337 }
338
339 throw new NameNotFoundException(name);
340 }
341
342 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700343 @SuppressWarnings("unchecked")
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800344 public List<PermissionGroupInfo> getAllPermissionGroups(int flags) {
345 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700346 ParceledListSlice<PermissionGroupInfo> parceledList =
347 mPM.getAllPermissionGroups(flags);
348 if (parceledList == null) {
349 return Collections.emptyList();
350 }
351 return parceledList.getList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800352 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700353 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800354 }
355 }
356
357 @Override
358 public ApplicationInfo getApplicationInfo(String packageName, int flags)
359 throws NameNotFoundException {
Jeff Sharkeycd654482016-01-08 17:42:11 -0700360 return getApplicationInfoAsUser(packageName, flags, mContext.getUserId());
361 }
362
363 @Override
364 public ApplicationInfo getApplicationInfoAsUser(String packageName, int flags, int userId)
365 throws NameNotFoundException {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800366 try {
Jeff Sharkeycd654482016-01-08 17:42:11 -0700367 ApplicationInfo ai = mPM.getApplicationInfo(packageName, flags, userId);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800368 if (ai != null) {
Narayan Kamathcaa71192014-07-16 11:06:43 +0100369 // This is a temporary hack. Callers must use
370 // createPackageContext(packageName).getApplicationInfo() to
371 // get the right paths.
Tao Baic9a02372016-01-12 15:02:24 -0800372 return maybeAdjustApplicationInfo(ai);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800373 }
374 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700375 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800376 }
377
378 throw new NameNotFoundException(packageName);
379 }
380
Tao Baic9a02372016-01-12 15:02:24 -0800381 private static ApplicationInfo maybeAdjustApplicationInfo(ApplicationInfo info) {
Narayan Kamathcaa71192014-07-16 11:06:43 +0100382 // If we're dealing with a multi-arch application that has both
383 // 32 and 64 bit shared libraries, we might need to choose the secondary
384 // depending on what the current runtime's instruction set is.
385 if (info.primaryCpuAbi != null && info.secondaryCpuAbi != null) {
386 final String runtimeIsa = VMRuntime.getRuntime().vmInstructionSet();
jgu214741cd92014-12-17 17:23:29 -0500387
388 // Get the instruction set that the libraries of secondary Abi is supported.
389 // In presence of a native bridge this might be different than the one secondary Abi used.
390 String secondaryIsa = VMRuntime.getInstructionSet(info.secondaryCpuAbi);
391 final String secondaryDexCodeIsa = SystemProperties.get("ro.dalvik.vm.isa." + secondaryIsa);
392 secondaryIsa = secondaryDexCodeIsa.isEmpty() ? secondaryIsa : secondaryDexCodeIsa;
Narayan Kamathcaa71192014-07-16 11:06:43 +0100393
394 // If the runtimeIsa is the same as the primary isa, then we do nothing.
395 // Everything will be set up correctly because info.nativeLibraryDir will
396 // correspond to the right ISA.
397 if (runtimeIsa.equals(secondaryIsa)) {
Tao Baic9a02372016-01-12 15:02:24 -0800398 ApplicationInfo modified = new ApplicationInfo(info);
399 modified.nativeLibraryDir = info.secondaryNativeLibraryDir;
400 return modified;
Narayan Kamathcaa71192014-07-16 11:06:43 +0100401 }
402 }
Tao Baic9a02372016-01-12 15:02:24 -0800403 return info;
Narayan Kamathcaa71192014-07-16 11:06:43 +0100404 }
405
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800406 @Override
407 public ActivityInfo getActivityInfo(ComponentName className, int flags)
408 throws NameNotFoundException {
409 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700410 ActivityInfo ai = mPM.getActivityInfo(className, flags, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800411 if (ai != null) {
412 return ai;
413 }
414 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700415 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800416 }
417
418 throw new NameNotFoundException(className.toString());
419 }
420
421 @Override
422 public ActivityInfo getReceiverInfo(ComponentName className, int flags)
423 throws NameNotFoundException {
424 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700425 ActivityInfo ai = mPM.getReceiverInfo(className, flags, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800426 if (ai != null) {
427 return ai;
428 }
429 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700430 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800431 }
432
433 throw new NameNotFoundException(className.toString());
434 }
435
436 @Override
437 public ServiceInfo getServiceInfo(ComponentName className, int flags)
438 throws NameNotFoundException {
439 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700440 ServiceInfo si = mPM.getServiceInfo(className, flags, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800441 if (si != null) {
442 return si;
443 }
444 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700445 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800446 }
447
448 throw new NameNotFoundException(className.toString());
449 }
450
451 @Override
452 public ProviderInfo getProviderInfo(ComponentName className, int flags)
453 throws NameNotFoundException {
454 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700455 ProviderInfo pi = mPM.getProviderInfo(className, flags, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800456 if (pi != null) {
457 return pi;
458 }
459 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700460 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800461 }
462
463 throw new NameNotFoundException(className.toString());
464 }
465
466 @Override
467 public String[] getSystemSharedLibraryNames() {
468 try {
469 return mPM.getSystemSharedLibraryNames();
470 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700471 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800472 }
473 }
474
Svet Ganovd7b1f4112016-02-09 18:49:23 -0800475 /** @hide */
476 @Override
Svet Ganov67882122016-12-11 16:36:34 -0800477 public @NonNull List<SharedLibraryInfo> getSharedLibraries(int flags) {
478 return getSharedLibrariesAsUser(flags, mContext.getUserId());
479 }
480
481 /** @hide */
482 @Override
483 @SuppressWarnings("unchecked")
484 public @NonNull List<SharedLibraryInfo> getSharedLibrariesAsUser(int flags, int userId) {
485 try {
486 ParceledListSlice<SharedLibraryInfo> sharedLibs = mPM.getSharedLibraries(
Svet Ganov58c99f02017-05-15 14:07:17 -0700487 mContext.getOpPackageName(), flags, userId);
Svet Ganov67882122016-12-11 16:36:34 -0800488 if (sharedLibs == null) {
489 return Collections.emptyList();
490 }
491 return sharedLibs.getList();
492 } catch (RemoteException e) {
493 throw e.rethrowFromSystemServer();
494 }
495 }
496
497 /** @hide */
498 @Override
Svetoslav Ganova9c25002016-04-13 19:25:56 -0700499 public @NonNull String getServicesSystemSharedLibraryPackageName() {
Svet Ganovd7b1f4112016-02-09 18:49:23 -0800500 try {
501 return mPM.getServicesSystemSharedLibraryPackageName();
502 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700503 throw e.rethrowFromSystemServer();
Svet Ganovd7b1f4112016-02-09 18:49:23 -0800504 }
505 }
506
Svetoslav Ganova9c25002016-04-13 19:25:56 -0700507 /**
508 * @hide
509 */
510 public @NonNull String getSharedSystemSharedLibraryPackageName() {
511 try {
512 return mPM.getSharedSystemSharedLibraryPackageName();
513 } catch (RemoteException e) {
514 throw e.rethrowFromSystemServer();
515 }
516 }
517
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800518 @Override
Todd Kennedy9106c642017-02-08 14:16:53 -0800519 public ChangedPackages getChangedPackages(int sequenceNumber) {
520 try {
521 return mPM.getChangedPackages(sequenceNumber, mContext.getUserId());
522 } catch (RemoteException e) {
523 throw e.rethrowFromSystemServer();
524 }
525 }
526
527 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700528 @SuppressWarnings("unchecked")
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800529 public FeatureInfo[] getSystemAvailableFeatures() {
530 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700531 ParceledListSlice<FeatureInfo> parceledList =
532 mPM.getSystemAvailableFeatures();
533 if (parceledList == null) {
534 return new FeatureInfo[0];
535 }
536 final List<FeatureInfo> list = parceledList.getList();
Jeff Sharkeyd5896632016-03-04 16:16:00 -0700537 final FeatureInfo[] res = new FeatureInfo[list.size()];
538 for (int i = 0; i < res.length; i++) {
539 res[i] = list.get(i);
540 }
541 return res;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800542 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700543 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800544 }
545 }
546
547 @Override
548 public boolean hasSystemFeature(String name) {
Jeff Sharkey115d2c12016-02-15 17:25:57 -0700549 return hasSystemFeature(name, 0);
550 }
551
552 @Override
553 public boolean hasSystemFeature(String name, int version) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800554 try {
Jeff Sharkey115d2c12016-02-15 17:25:57 -0700555 return mPM.hasSystemFeature(name, version);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800556 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700557 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800558 }
559 }
560
561 @Override
562 public int checkPermission(String permName, String pkgName) {
563 try {
Svetoslavc6d1c342015-02-26 14:44:43 -0800564 return mPM.checkPermission(permName, pkgName, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800565 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700566 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800567 }
568 }
569
570 @Override
Svet Ganovad3b2972015-07-07 22:49:17 -0700571 public boolean isPermissionRevokedByPolicy(String permName, String pkgName) {
572 try {
573 return mPM.isPermissionRevokedByPolicy(permName, pkgName, mContext.getUserId());
574 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700575 throw e.rethrowFromSystemServer();
Svet Ganovad3b2972015-07-07 22:49:17 -0700576 }
577 }
578
Svet Ganovf1b7f202015-07-29 08:33:42 -0700579 /**
580 * @hide
581 */
582 @Override
583 public String getPermissionControllerPackageName() {
584 synchronized (mLock) {
585 if (mPermissionsControllerPackageName == null) {
586 try {
587 mPermissionsControllerPackageName = mPM.getPermissionControllerPackageName();
588 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700589 throw e.rethrowFromSystemServer();
Svet Ganovf1b7f202015-07-29 08:33:42 -0700590 }
591 }
592 return mPermissionsControllerPackageName;
593 }
594 }
595
Svet Ganovad3b2972015-07-07 22:49:17 -0700596 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800597 public boolean addPermission(PermissionInfo info) {
598 try {
599 return mPM.addPermission(info);
600 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700601 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800602 }
603 }
604
605 @Override
606 public boolean addPermissionAsync(PermissionInfo info) {
607 try {
608 return mPM.addPermissionAsync(info);
609 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700610 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800611 }
612 }
613
614 @Override
615 public void removePermission(String name) {
616 try {
617 mPM.removePermission(name);
618 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700619 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800620 }
621 }
622
623 @Override
Svet Ganov8c7f7002015-05-07 10:48:44 -0700624 public void grantRuntimePermission(String packageName, String permissionName,
625 UserHandle user) {
Dianne Hackborne639da72012-02-21 15:11:13 -0800626 try {
Svet Ganov8c7f7002015-05-07 10:48:44 -0700627 mPM.grantRuntimePermission(packageName, permissionName, user.getIdentifier());
Dianne Hackborne639da72012-02-21 15:11:13 -0800628 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700629 throw e.rethrowFromSystemServer();
Dianne Hackborne639da72012-02-21 15:11:13 -0800630 }
631 }
632
633 @Override
Svet Ganov8c7f7002015-05-07 10:48:44 -0700634 public void revokeRuntimePermission(String packageName, String permissionName,
635 UserHandle user) {
Dianne Hackborne639da72012-02-21 15:11:13 -0800636 try {
Svet Ganov8c7f7002015-05-07 10:48:44 -0700637 mPM.revokeRuntimePermission(packageName, permissionName, user.getIdentifier());
638 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700639 throw e.rethrowFromSystemServer();
Svet Ganov8c7f7002015-05-07 10:48:44 -0700640 }
641 }
642
643 @Override
644 public int getPermissionFlags(String permissionName, String packageName, UserHandle user) {
645 try {
646 return mPM.getPermissionFlags(permissionName, packageName, user.getIdentifier());
647 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700648 throw e.rethrowFromSystemServer();
Svet Ganov8c7f7002015-05-07 10:48:44 -0700649 }
650 }
651
652 @Override
653 public void updatePermissionFlags(String permissionName, String packageName,
654 int flagMask, int flagValues, UserHandle user) {
655 try {
656 mPM.updatePermissionFlags(permissionName, packageName, flagMask,
657 flagValues, user.getIdentifier());
Dianne Hackborne639da72012-02-21 15:11:13 -0800658 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700659 throw e.rethrowFromSystemServer();
Dianne Hackborne639da72012-02-21 15:11:13 -0800660 }
661 }
662
663 @Override
Svetoslav20770dd2015-05-29 15:43:04 -0700664 public boolean shouldShowRequestPermissionRationale(String permission) {
665 try {
666 return mPM.shouldShowRequestPermissionRationale(permission,
667 mContext.getPackageName(), mContext.getUserId());
668 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700669 throw e.rethrowFromSystemServer();
Svetoslav20770dd2015-05-29 15:43:04 -0700670 }
671 }
672
673 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800674 public int checkSignatures(String pkg1, String pkg2) {
675 try {
676 return mPM.checkSignatures(pkg1, pkg2);
677 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700678 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800679 }
680 }
681
682 @Override
683 public int checkSignatures(int uid1, int uid2) {
684 try {
685 return mPM.checkUidSignatures(uid1, uid2);
686 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700687 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800688 }
689 }
690
691 @Override
692 public String[] getPackagesForUid(int uid) {
693 try {
694 return mPM.getPackagesForUid(uid);
695 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700696 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800697 }
698 }
699
700 @Override
701 public String getNameForUid(int uid) {
702 try {
703 return mPM.getNameForUid(uid);
704 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700705 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800706 }
707 }
708
709 @Override
Todd Kennedy9da8b8a72017-07-25 15:38:39 -0700710 public String[] getNamesForUids(int[] uids) {
711 try {
712 return mPM.getNamesForUids(uids);
713 } catch (RemoteException e) {
714 throw e.rethrowFromSystemServer();
715 }
716 }
717
718 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800719 public int getUidForSharedUser(String sharedUserName)
720 throws NameNotFoundException {
721 try {
722 int uid = mPM.getUidForSharedUser(sharedUserName);
723 if(uid != -1) {
724 return uid;
725 }
726 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700727 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800728 }
729 throw new NameNotFoundException("No shared userid for user:"+sharedUserName);
730 }
731
Kenny Roote6cd0c72011-05-19 12:48:14 -0700732 @SuppressWarnings("unchecked")
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800733 @Override
734 public List<PackageInfo> getInstalledPackages(int flags) {
Jeff Sharkeye06b4d12016-01-06 14:51:50 -0700735 return getInstalledPackagesAsUser(flags, mContext.getUserId());
Amith Yamasani151ec4c2012-09-07 19:25:16 -0700736 }
737
738 /** @hide */
739 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700740 @SuppressWarnings("unchecked")
Jeff Sharkeye06b4d12016-01-06 14:51:50 -0700741 public List<PackageInfo> getInstalledPackagesAsUser(int flags, int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800742 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700743 ParceledListSlice<PackageInfo> parceledList =
744 mPM.getInstalledPackages(flags, userId);
745 if (parceledList == null) {
746 return Collections.emptyList();
747 }
748 return parceledList.getList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800749 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700750 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800751 }
752 }
753
Kenny Roote6cd0c72011-05-19 12:48:14 -0700754 @SuppressWarnings("unchecked")
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800755 @Override
Dianne Hackborne7991752013-01-16 17:56:46 -0800756 public List<PackageInfo> getPackagesHoldingPermissions(
757 String[] permissions, int flags) {
758 final int userId = mContext.getUserId();
759 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700760 ParceledListSlice<PackageInfo> parceledList =
761 mPM.getPackagesHoldingPermissions(permissions, flags, userId);
762 if (parceledList == null) {
763 return Collections.emptyList();
764 }
765 return parceledList.getList();
Dianne Hackborne7991752013-01-16 17:56:46 -0800766 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700767 throw e.rethrowFromSystemServer();
Dianne Hackborne7991752013-01-16 17:56:46 -0800768 }
769 }
770
771 @SuppressWarnings("unchecked")
772 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800773 public List<ApplicationInfo> getInstalledApplications(int flags) {
Bartosz Fabianowski11334242016-11-17 20:49:16 +0100774 return getInstalledApplicationsAsUser(flags, mContext.getUserId());
775 }
776
777 /** @hide */
778 @SuppressWarnings("unchecked")
779 @Override
780 public List<ApplicationInfo> getInstalledApplicationsAsUser(int flags, int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800781 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700782 ParceledListSlice<ApplicationInfo> parceledList =
783 mPM.getInstalledApplications(flags, userId);
784 if (parceledList == null) {
785 return Collections.emptyList();
786 }
787 return parceledList.getList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800788 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700789 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800790 }
791 }
792
Svet Ganov2acf0632015-11-24 19:10:59 -0800793 /** @hide */
794 @SuppressWarnings("unchecked")
795 @Override
Svetoslav Ganov096d3042017-01-30 16:34:13 -0800796 public List<InstantAppInfo> getInstantApps() {
Svet Ganov2acf0632015-11-24 19:10:59 -0800797 try {
Svetoslav Ganov096d3042017-01-30 16:34:13 -0800798 ParceledListSlice<InstantAppInfo> slice =
799 mPM.getInstantApps(mContext.getUserId());
Svet Ganov2acf0632015-11-24 19:10:59 -0800800 if (slice != null) {
801 return slice.getList();
802 }
803 return Collections.emptyList();
804 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700805 throw e.rethrowFromSystemServer();
Svet Ganov2acf0632015-11-24 19:10:59 -0800806 }
807 }
808
809 /** @hide */
810 @Override
Svetoslav Ganov096d3042017-01-30 16:34:13 -0800811 public Drawable getInstantAppIcon(String packageName) {
Svet Ganov2acf0632015-11-24 19:10:59 -0800812 try {
Svetoslav Ganov096d3042017-01-30 16:34:13 -0800813 Bitmap bitmap = mPM.getInstantAppIcon(
Svet Ganov2acf0632015-11-24 19:10:59 -0800814 packageName, mContext.getUserId());
815 if (bitmap != null) {
816 return new BitmapDrawable(null, bitmap);
817 }
818 return null;
819 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700820 throw e.rethrowFromSystemServer();
Svet Ganov2acf0632015-11-24 19:10:59 -0800821 }
822 }
823
824 @Override
Svetoslav Ganov096d3042017-01-30 16:34:13 -0800825 public boolean isInstantApp() {
David Christie31a16552017-03-01 15:08:45 -0800826 return isInstantApp(mContext.getPackageName());
827 }
828
829 @Override
830 public boolean isInstantApp(String packageName) {
Svet Ganov2acf0632015-11-24 19:10:59 -0800831 try {
David Christie31a16552017-03-01 15:08:45 -0800832 return mPM.isInstantApp(packageName, mContext.getUserId());
Svet Ganov2acf0632015-11-24 19:10:59 -0800833 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700834 throw e.rethrowFromSystemServer();
Svet Ganov2acf0632015-11-24 19:10:59 -0800835 }
Svet Ganov2acf0632015-11-24 19:10:59 -0800836 }
837
Svetoslav Ganov345ffa52017-04-18 16:08:41 -0700838 public int getInstantAppCookieMaxBytes() {
Svet Ganov2acf0632015-11-24 19:10:59 -0800839 return Settings.Global.getInt(mContext.getContentResolver(),
840 Settings.Global.EPHEMERAL_COOKIE_MAX_SIZE_BYTES,
841 DEFAULT_EPHEMERAL_COOKIE_MAX_SIZE_BYTES);
842 }
843
844 @Override
Svetoslav Ganov345ffa52017-04-18 16:08:41 -0700845 public int getInstantAppCookieMaxSize() {
846 return getInstantAppCookieMaxBytes();
847 }
848
849 @Override
Svetoslav Ganov096d3042017-01-30 16:34:13 -0800850 public @NonNull byte[] getInstantAppCookie() {
Svet Ganov2acf0632015-11-24 19:10:59 -0800851 try {
Svetoslav Ganov096d3042017-01-30 16:34:13 -0800852 final byte[] cookie = mPM.getInstantAppCookie(
Svet Ganov2acf0632015-11-24 19:10:59 -0800853 mContext.getPackageName(), mContext.getUserId());
854 if (cookie != null) {
855 return cookie;
Jeff Sharkey27b2e692016-02-25 17:40:12 -0700856 } else {
857 return EmptyArray.BYTE;
Svet Ganov2acf0632015-11-24 19:10:59 -0800858 }
859 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700860 throw e.rethrowFromSystemServer();
Svet Ganov2acf0632015-11-24 19:10:59 -0800861 }
Svet Ganov2acf0632015-11-24 19:10:59 -0800862 }
863
864 @Override
Svetoslav Ganov345ffa52017-04-18 16:08:41 -0700865 public void clearInstantAppCookie() {
866 updateInstantAppCookie(null);
867 }
868
869 @Override
870 public void updateInstantAppCookie(@NonNull byte[] cookie) {
871 if (cookie != null && cookie.length > getInstantAppCookieMaxBytes()) {
872 throw new IllegalArgumentException("instant cookie longer than "
873 + getInstantAppCookieMaxBytes());
874 }
875 try {
876 mPM.setInstantAppCookie(mContext.getPackageName(),
877 cookie, mContext.getUserId());
878 } catch (RemoteException e) {
879 throw e.rethrowFromSystemServer();
880 }
881 }
882
883 @Override
Svetoslav Ganov096d3042017-01-30 16:34:13 -0800884 public boolean setInstantAppCookie(@NonNull byte[] cookie) {
Svet Ganov2acf0632015-11-24 19:10:59 -0800885 try {
Svetoslav Ganov096d3042017-01-30 16:34:13 -0800886 return mPM.setInstantAppCookie(mContext.getPackageName(),
887 cookie, mContext.getUserId());
Svet Ganov2acf0632015-11-24 19:10:59 -0800888 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700889 throw e.rethrowFromSystemServer();
Svet Ganov2acf0632015-11-24 19:10:59 -0800890 }
Svet Ganov2acf0632015-11-24 19:10:59 -0800891 }
892
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800893 @Override
894 public ResolveInfo resolveActivity(Intent intent, int flags) {
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700895 return resolveActivityAsUser(intent, flags, mContext.getUserId());
Svetoslav Ganov58d37b52012-09-18 12:04:19 -0700896 }
897
898 @Override
899 public ResolveInfo resolveActivityAsUser(Intent intent, int flags, int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800900 try {
901 return mPM.resolveIntent(
902 intent,
903 intent.resolveTypeIfNeeded(mContext.getContentResolver()),
Svetoslav Ganov58d37b52012-09-18 12:04:19 -0700904 flags,
905 userId);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800906 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700907 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800908 }
909 }
910
911 @Override
912 public List<ResolveInfo> queryIntentActivities(Intent intent,
913 int flags) {
Jeff Sharkeyded653b2012-09-27 19:09:24 -0700914 return queryIntentActivitiesAsUser(intent, flags, mContext.getUserId());
Amith Yamasani151ec4c2012-09-07 19:25:16 -0700915 }
916
917 /** @hide Same as above but for a specific user */
918 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700919 @SuppressWarnings("unchecked")
Svetoslav Ganov58d37b52012-09-18 12:04:19 -0700920 public List<ResolveInfo> queryIntentActivitiesAsUser(Intent intent,
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700921 int flags, int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800922 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700923 ParceledListSlice<ResolveInfo> parceledList =
924 mPM.queryIntentActivities(intent,
925 intent.resolveTypeIfNeeded(mContext.getContentResolver()),
926 flags, userId);
927 if (parceledList == null) {
928 return Collections.emptyList();
929 }
930 return parceledList.getList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800931 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700932 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800933 }
934 }
935
936 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700937 @SuppressWarnings("unchecked")
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800938 public List<ResolveInfo> queryIntentActivityOptions(
939 ComponentName caller, Intent[] specifics, Intent intent,
940 int flags) {
941 final ContentResolver resolver = mContext.getContentResolver();
942
943 String[] specificTypes = null;
944 if (specifics != null) {
945 final int N = specifics.length;
946 for (int i=0; i<N; i++) {
947 Intent sp = specifics[i];
948 if (sp != null) {
949 String t = sp.resolveTypeIfNeeded(resolver);
950 if (t != null) {
951 if (specificTypes == null) {
952 specificTypes = new String[N];
953 }
954 specificTypes[i] = t;
955 }
956 }
957 }
958 }
959
960 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700961 ParceledListSlice<ResolveInfo> parceledList =
962 mPM.queryIntentActivityOptions(caller, specifics, specificTypes, intent,
963 intent.resolveTypeIfNeeded(resolver), flags, mContext.getUserId());
964 if (parceledList == null) {
965 return Collections.emptyList();
966 }
967 return parceledList.getList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800968 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700969 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800970 }
971 }
972
Amith Yamasanif203aee2012-08-29 18:41:53 -0700973 /**
974 * @hide
975 */
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800976 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700977 @SuppressWarnings("unchecked")
Jeff Sharkeye06b4d12016-01-06 14:51:50 -0700978 public List<ResolveInfo> queryBroadcastReceiversAsUser(Intent intent, int flags, int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800979 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -0700980 ParceledListSlice<ResolveInfo> parceledList =
981 mPM.queryIntentReceivers(intent,
982 intent.resolveTypeIfNeeded(mContext.getContentResolver()),
983 flags, userId);
984 if (parceledList == null) {
985 return Collections.emptyList();
986 }
987 return parceledList.getList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800988 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700989 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800990 }
991 }
992
993 @Override
Amith Yamasanif203aee2012-08-29 18:41:53 -0700994 public List<ResolveInfo> queryBroadcastReceivers(Intent intent, int flags) {
Jeff Sharkeye06b4d12016-01-06 14:51:50 -0700995 return queryBroadcastReceiversAsUser(intent, flags, mContext.getUserId());
Amith Yamasanif203aee2012-08-29 18:41:53 -0700996 }
997
998 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -0800999 public ResolveInfo resolveService(Intent intent, int flags) {
1000 try {
1001 return mPM.resolveService(
1002 intent,
1003 intent.resolveTypeIfNeeded(mContext.getContentResolver()),
Amith Yamasani483f3b02012-03-13 16:08:00 -07001004 flags,
Jeff Sharkeyded653b2012-09-27 19:09:24 -07001005 mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001006 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001007 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001008 }
1009 }
1010
1011 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001012 @SuppressWarnings("unchecked")
Svetoslav Ganov58d37b52012-09-18 12:04:19 -07001013 public List<ResolveInfo> queryIntentServicesAsUser(Intent intent, int flags, int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001014 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001015 ParceledListSlice<ResolveInfo> parceledList =
1016 mPM.queryIntentServices(intent,
1017 intent.resolveTypeIfNeeded(mContext.getContentResolver()),
1018 flags, userId);
1019 if (parceledList == null) {
1020 return Collections.emptyList();
1021 }
1022 return parceledList.getList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001023 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001024 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001025 }
1026 }
1027
1028 @Override
Svetoslav Ganov58d37b52012-09-18 12:04:19 -07001029 public List<ResolveInfo> queryIntentServices(Intent intent, int flags) {
Jeff Sharkeyded653b2012-09-27 19:09:24 -07001030 return queryIntentServicesAsUser(intent, flags, mContext.getUserId());
Svetoslav Ganov58d37b52012-09-18 12:04:19 -07001031 }
1032
1033 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001034 @SuppressWarnings("unchecked")
Jeff Sharkey85f5f812013-10-07 10:16:12 -07001035 public List<ResolveInfo> queryIntentContentProvidersAsUser(
1036 Intent intent, int flags, int userId) {
1037 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001038 ParceledListSlice<ResolveInfo> parceledList =
1039 mPM.queryIntentContentProviders(intent,
1040 intent.resolveTypeIfNeeded(mContext.getContentResolver()),
1041 flags, userId);
1042 if (parceledList == null) {
1043 return Collections.emptyList();
1044 }
1045 return parceledList.getList();
Jeff Sharkey85f5f812013-10-07 10:16:12 -07001046 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001047 throw e.rethrowFromSystemServer();
Jeff Sharkey85f5f812013-10-07 10:16:12 -07001048 }
1049 }
1050
1051 @Override
1052 public List<ResolveInfo> queryIntentContentProviders(Intent intent, int flags) {
1053 return queryIntentContentProvidersAsUser(intent, flags, mContext.getUserId());
1054 }
1055
1056 @Override
Alexandra Gherghina0363c3e2014-06-23 13:34:59 +01001057 public ProviderInfo resolveContentProvider(String name, int flags) {
1058 return resolveContentProviderAsUser(name, flags, mContext.getUserId());
1059 }
1060
1061 /** @hide **/
1062 @Override
1063 public ProviderInfo resolveContentProviderAsUser(String name, int flags, int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001064 try {
Alexandra Gherghina0363c3e2014-06-23 13:34:59 +01001065 return mPM.resolveContentProvider(name, flags, userId);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001066 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001067 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001068 }
1069 }
1070
1071 @Override
1072 public List<ProviderInfo> queryContentProviders(String processName,
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001073 int uid, int flags) {
Makoto Onuki32757292017-02-22 14:36:59 -08001074 return queryContentProviders(processName, uid, flags, null);
1075 }
1076
1077 @Override
1078 @SuppressWarnings("unchecked")
1079 public List<ProviderInfo> queryContentProviders(String processName,
1080 int uid, int flags, String metaDataKey) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001081 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001082 ParceledListSlice<ProviderInfo> slice =
Makoto Onuki32757292017-02-22 14:36:59 -08001083 mPM.queryContentProviders(processName, uid, flags, metaDataKey);
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001084 return slice != null ? slice.getList() : Collections.<ProviderInfo>emptyList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001085 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001086 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001087 }
1088 }
1089
1090 @Override
1091 public InstrumentationInfo getInstrumentationInfo(
1092 ComponentName className, int flags)
1093 throws NameNotFoundException {
1094 try {
1095 InstrumentationInfo ii = mPM.getInstrumentationInfo(
1096 className, flags);
1097 if (ii != null) {
1098 return ii;
1099 }
1100 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001101 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001102 }
1103
1104 throw new NameNotFoundException(className.toString());
1105 }
1106
1107 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001108 @SuppressWarnings("unchecked")
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001109 public List<InstrumentationInfo> queryInstrumentation(
1110 String targetPackage, int flags) {
1111 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001112 ParceledListSlice<InstrumentationInfo> parceledList =
1113 mPM.queryInstrumentation(targetPackage, flags);
1114 if (parceledList == null) {
1115 return Collections.emptyList();
1116 }
1117 return parceledList.getList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001118 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001119 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001120 }
1121 }
1122
Alan Viveretteecd585a2015-04-13 10:32:51 -07001123 @Nullable
1124 @Override
1125 public Drawable getDrawable(String packageName, @DrawableRes int resId,
1126 @Nullable ApplicationInfo appInfo) {
1127 final ResourceName name = new ResourceName(packageName, resId);
1128 final Drawable cachedIcon = getCachedIcon(name);
1129 if (cachedIcon != null) {
1130 return cachedIcon;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001131 }
Alan Viveretteecd585a2015-04-13 10:32:51 -07001132
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001133 if (appInfo == null) {
1134 try {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001135 appInfo = getApplicationInfo(packageName, sDefaultFlags);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001136 } catch (NameNotFoundException e) {
1137 return null;
1138 }
1139 }
Alan Viveretteecd585a2015-04-13 10:32:51 -07001140
1141 if (resId != 0) {
1142 try {
1143 final Resources r = getResourcesForApplication(appInfo);
1144 final Drawable dr = r.getDrawable(resId, null);
1145 if (dr != null) {
1146 putCachedIcon(name, dr);
1147 }
1148
1149 if (false) {
1150 RuntimeException e = new RuntimeException("here");
1151 e.fillInStackTrace();
1152 Log.w(TAG, "Getting drawable 0x" + Integer.toHexString(resId)
1153 + " from package " + packageName
1154 + ": app scale=" + r.getCompatibilityInfo().applicationScale
1155 + ", caller scale=" + mContext.getResources()
1156 .getCompatibilityInfo().applicationScale,
1157 e);
1158 }
Ricky Wai3ce46252015-04-15 16:12:22 +01001159 if (DEBUG_ICONS) {
Alan Viveretteecd585a2015-04-13 10:32:51 -07001160 Log.v(TAG, "Getting drawable 0x"
1161 + Integer.toHexString(resId) + " from " + r
1162 + ": " + dr);
Ricky Wai3ce46252015-04-15 16:12:22 +01001163 }
1164 return dr;
Alan Viveretteecd585a2015-04-13 10:32:51 -07001165 } catch (NameNotFoundException e) {
1166 Log.w("PackageManager", "Failure retrieving resources for "
1167 + appInfo.packageName);
1168 } catch (Resources.NotFoundException e) {
1169 Log.w("PackageManager", "Failure retrieving resources for "
1170 + appInfo.packageName + ": " + e.getMessage());
1171 } catch (Exception e) {
1172 // If an exception was thrown, fall through to return
1173 // default icon.
1174 Log.w("PackageManager", "Failure retrieving icon 0x"
1175 + Integer.toHexString(resId) + " in package "
1176 + packageName, e);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001177 }
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001178 }
Alan Viveretteecd585a2015-04-13 10:32:51 -07001179
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001180 return null;
1181 }
1182
1183 @Override public Drawable getActivityIcon(ComponentName activityName)
1184 throws NameNotFoundException {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001185 return getActivityInfo(activityName, sDefaultFlags).loadIcon(this);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001186 }
1187
1188 @Override public Drawable getActivityIcon(Intent intent)
1189 throws NameNotFoundException {
1190 if (intent.getComponent() != null) {
1191 return getActivityIcon(intent.getComponent());
1192 }
1193
1194 ResolveInfo info = resolveActivity(
1195 intent, PackageManager.MATCH_DEFAULT_ONLY);
1196 if (info != null) {
1197 return info.activityInfo.loadIcon(this);
1198 }
1199
Romain Guy39fe17c2011-11-30 10:34:07 -08001200 throw new NameNotFoundException(intent.toUri(0));
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001201 }
1202
1203 @Override public Drawable getDefaultActivityIcon() {
1204 return Resources.getSystem().getDrawable(
1205 com.android.internal.R.drawable.sym_def_app_icon);
1206 }
1207
1208 @Override public Drawable getApplicationIcon(ApplicationInfo info) {
1209 return info.loadIcon(this);
1210 }
1211
1212 @Override public Drawable getApplicationIcon(String packageName)
1213 throws NameNotFoundException {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001214 return getApplicationIcon(getApplicationInfo(packageName, sDefaultFlags));
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001215 }
1216
1217 @Override
Jose Limaf78e3122014-03-06 12:13:15 -08001218 public Drawable getActivityBanner(ComponentName activityName)
1219 throws NameNotFoundException {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001220 return getActivityInfo(activityName, sDefaultFlags).loadBanner(this);
Jose Limaf78e3122014-03-06 12:13:15 -08001221 }
1222
1223 @Override
1224 public Drawable getActivityBanner(Intent intent)
1225 throws NameNotFoundException {
1226 if (intent.getComponent() != null) {
1227 return getActivityBanner(intent.getComponent());
1228 }
1229
1230 ResolveInfo info = resolveActivity(
1231 intent, PackageManager.MATCH_DEFAULT_ONLY);
1232 if (info != null) {
1233 return info.activityInfo.loadBanner(this);
1234 }
1235
1236 throw new NameNotFoundException(intent.toUri(0));
1237 }
1238
1239 @Override
1240 public Drawable getApplicationBanner(ApplicationInfo info) {
1241 return info.loadBanner(this);
1242 }
1243
1244 @Override
1245 public Drawable getApplicationBanner(String packageName)
1246 throws NameNotFoundException {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001247 return getApplicationBanner(getApplicationInfo(packageName, sDefaultFlags));
Jose Limaf78e3122014-03-06 12:13:15 -08001248 }
1249
1250 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001251 public Drawable getActivityLogo(ComponentName activityName)
1252 throws NameNotFoundException {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001253 return getActivityInfo(activityName, sDefaultFlags).loadLogo(this);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001254 }
1255
1256 @Override
1257 public Drawable getActivityLogo(Intent intent)
1258 throws NameNotFoundException {
1259 if (intent.getComponent() != null) {
1260 return getActivityLogo(intent.getComponent());
1261 }
1262
1263 ResolveInfo info = resolveActivity(
1264 intent, PackageManager.MATCH_DEFAULT_ONLY);
1265 if (info != null) {
1266 return info.activityInfo.loadLogo(this);
1267 }
1268
1269 throw new NameNotFoundException(intent.toUri(0));
1270 }
1271
1272 @Override
1273 public Drawable getApplicationLogo(ApplicationInfo info) {
1274 return info.loadLogo(this);
1275 }
1276
1277 @Override
1278 public Drawable getApplicationLogo(String packageName)
1279 throws NameNotFoundException {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001280 return getApplicationLogo(getApplicationInfo(packageName, sDefaultFlags));
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001281 }
1282
Svetoslavc7d62f02014-09-04 15:39:54 -07001283 @Override
1284 public Drawable getUserBadgedIcon(Drawable icon, UserHandle user) {
Kenny Guy02c89902016-11-15 19:36:38 +00001285 if (!isManagedProfile(user.getIdentifier())) {
Svetoslavc7d62f02014-09-04 15:39:54 -07001286 return icon;
1287 }
Sunny Goyalbab30752017-04-12 15:36:42 -07001288 Drawable badge = new LauncherIcons(mContext).getBadgeDrawable(
1289 com.android.internal.R.drawable.ic_corp_icon_badge_case,
1290 getUserBadgeColor(user));
Kenny Guy02c89902016-11-15 19:36:38 +00001291 return getBadgedDrawable(icon, badge, null, true);
Svetoslavc7d62f02014-09-04 15:39:54 -07001292 }
1293
1294 @Override
1295 public Drawable getUserBadgedDrawableForDensity(Drawable drawable, UserHandle user,
1296 Rect badgeLocation, int badgeDensity) {
1297 Drawable badgeDrawable = getUserBadgeForDensity(user, badgeDensity);
1298 if (badgeDrawable == null) {
1299 return drawable;
1300 }
1301 return getBadgedDrawable(drawable, badgeDrawable, badgeLocation, true);
1302 }
1303
Kenny Guy02c89902016-11-15 19:36:38 +00001304 @VisibleForTesting
1305 public static final int[] CORP_BADGE_LABEL_RES_ID = new int[] {
1306 com.android.internal.R.string.managed_profile_label_badge,
1307 com.android.internal.R.string.managed_profile_label_badge_2,
1308 com.android.internal.R.string.managed_profile_label_badge_3
1309 };
1310
1311 private int getUserBadgeColor(UserHandle user) {
Sunny Goyalbab30752017-04-12 15:36:42 -07001312 return IconDrawableFactory.getUserBadgeColor(getUserManager(), user.getIdentifier());
Kenny Guy02c89902016-11-15 19:36:38 +00001313 }
1314
Svetoslavc7d62f02014-09-04 15:39:54 -07001315 @Override
1316 public Drawable getUserBadgeForDensity(UserHandle user, int density) {
Kenny Guy02c89902016-11-15 19:36:38 +00001317 Drawable badgeColor = getManagedProfileIconForDensity(user,
1318 com.android.internal.R.drawable.ic_corp_badge_color, density);
1319 if (badgeColor == null) {
1320 return null;
1321 }
1322 badgeColor.setTint(getUserBadgeColor(user));
1323 Drawable badgeForeground = getDrawableForDensity(
1324 com.android.internal.R.drawable.ic_corp_badge_case, density);
1325 Drawable badge = new LayerDrawable(
1326 new Drawable[] {badgeColor, badgeForeground });
1327 return badge;
Selim Cineke6ff9462016-01-15 15:07:06 -08001328 }
1329
1330 @Override
1331 public Drawable getUserBadgeForDensityNoBackground(UserHandle user, int density) {
Kenny Guy02c89902016-11-15 19:36:38 +00001332 Drawable badge = getManagedProfileIconForDensity(user,
Vadim Tryshev66ae66a2016-02-18 15:41:21 -08001333 com.android.internal.R.drawable.ic_corp_badge_no_background, density);
Kenny Guy02c89902016-11-15 19:36:38 +00001334 if (badge != null) {
1335 badge.setTint(getUserBadgeColor(user));
1336 }
1337 return badge;
Selim Cineke6ff9462016-01-15 15:07:06 -08001338 }
1339
Vadim Tryshev66ae66a2016-02-18 15:41:21 -08001340 private Drawable getDrawableForDensity(int drawableId, int density) {
1341 if (density <= 0) {
1342 density = mContext.getResources().getDisplayMetrics().densityDpi;
1343 }
1344 return Resources.getSystem().getDrawableForDensity(drawableId, density);
1345 }
1346
1347 private Drawable getManagedProfileIconForDensity(UserHandle user, int drawableId, int density) {
Tony Mak8673b282016-03-21 21:10:59 +00001348 if (isManagedProfile(user.getIdentifier())) {
Vadim Tryshev66ae66a2016-02-18 15:41:21 -08001349 return getDrawableForDensity(drawableId, density);
Svetoslavc7d62f02014-09-04 15:39:54 -07001350 }
1351 return null;
1352 }
1353
1354 @Override
1355 public CharSequence getUserBadgedLabel(CharSequence label, UserHandle user) {
Tony Mak8673b282016-03-21 21:10:59 +00001356 if (isManagedProfile(user.getIdentifier())) {
Kenny Guy02c89902016-11-15 19:36:38 +00001357 int badge = getUserManager().getManagedProfileBadge(user.getIdentifier());
1358 int resourceId = CORP_BADGE_LABEL_RES_ID[badge % CORP_BADGE_LABEL_RES_ID.length];
1359 return Resources.getSystem().getString(resourceId, label);
Svetoslavc7d62f02014-09-04 15:39:54 -07001360 }
1361 return label;
1362 }
1363
Alan Viveretteecd585a2015-04-13 10:32:51 -07001364 @Override
1365 public Resources getResourcesForActivity(ComponentName activityName)
1366 throws NameNotFoundException {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001367 return getResourcesForApplication(
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001368 getActivityInfo(activityName, sDefaultFlags).applicationInfo);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001369 }
1370
Alan Viveretteecd585a2015-04-13 10:32:51 -07001371 @Override
1372 public Resources getResourcesForApplication(@NonNull ApplicationInfo app)
1373 throws NameNotFoundException {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001374 if (app.packageName.equals("system")) {
Adam Lesinskia82b6262017-03-21 16:56:17 -07001375 return mContext.mMainThread.getSystemUiContext().getResources();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001376 }
Jeff Sharkey8a4c9722014-06-16 13:48:42 -07001377 final boolean sameUid = (app.uid == Process.myUid());
Adam Lesinski53fafdf2016-08-03 13:36:39 -07001378 final Resources r = mContext.mMainThread.getTopLevelResources(
Adam Lesinskic82f28a2016-06-08 17:19:09 -07001379 sameUid ? app.sourceDir : app.publicSourceDir,
1380 sameUid ? app.splitSourceDirs : app.splitPublicSourceDirs,
1381 app.resourceDirs, app.sharedLibraryFiles, Display.DEFAULT_DISPLAY,
1382 mContext.mPackageInfo);
Adam Lesinski53fafdf2016-08-03 13:36:39 -07001383 if (r != null) {
1384 return r;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001385 }
Adam Lesinski53fafdf2016-08-03 13:36:39 -07001386 throw new NameNotFoundException("Unable to open " + app.publicSourceDir);
1387
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001388 }
1389
Alan Viveretteecd585a2015-04-13 10:32:51 -07001390 @Override
1391 public Resources getResourcesForApplication(String appPackageName)
1392 throws NameNotFoundException {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001393 return getResourcesForApplication(
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001394 getApplicationInfo(appPackageName, sDefaultFlags));
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001395 }
1396
Amith Yamasani98edc952012-09-25 14:09:27 -07001397 /** @hide */
1398 @Override
1399 public Resources getResourcesForApplicationAsUser(String appPackageName, int userId)
1400 throws NameNotFoundException {
Jeff Sharkeyded653b2012-09-27 19:09:24 -07001401 if (userId < 0) {
1402 throw new IllegalArgumentException(
1403 "Call does not support special user #" + userId);
1404 }
1405 if ("system".equals(appPackageName)) {
Adam Lesinskia82b6262017-03-21 16:56:17 -07001406 return mContext.mMainThread.getSystemUiContext().getResources();
Jeff Sharkeyded653b2012-09-27 19:09:24 -07001407 }
Amith Yamasani98edc952012-09-25 14:09:27 -07001408 try {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001409 ApplicationInfo ai = mPM.getApplicationInfo(appPackageName, sDefaultFlags, userId);
Amith Yamasani98edc952012-09-25 14:09:27 -07001410 if (ai != null) {
1411 return getResourcesForApplication(ai);
1412 }
1413 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001414 throw e.rethrowFromSystemServer();
Amith Yamasani98edc952012-09-25 14:09:27 -07001415 }
1416 throw new NameNotFoundException("Package " + appPackageName + " doesn't exist");
1417 }
1418
Jeff Sharkeycd654482016-01-08 17:42:11 -07001419 volatile int mCachedSafeMode = -1;
1420
1421 @Override
1422 public boolean isSafeMode() {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001423 try {
1424 if (mCachedSafeMode < 0) {
1425 mCachedSafeMode = mPM.isSafeMode() ? 1 : 0;
1426 }
1427 return mCachedSafeMode != 0;
1428 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001429 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001430 }
1431 }
1432
Svetoslavf7c06eb2015-06-10 18:43:22 -07001433 @Override
1434 public void addOnPermissionsChangeListener(OnPermissionsChangedListener listener) {
1435 synchronized (mPermissionListeners) {
1436 if (mPermissionListeners.get(listener) != null) {
1437 return;
1438 }
1439 OnPermissionsChangeListenerDelegate delegate =
1440 new OnPermissionsChangeListenerDelegate(listener, Looper.getMainLooper());
1441 try {
1442 mPM.addOnPermissionsChangeListener(delegate);
1443 mPermissionListeners.put(listener, delegate);
1444 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001445 throw e.rethrowFromSystemServer();
Svetoslavf7c06eb2015-06-10 18:43:22 -07001446 }
1447 }
1448 }
1449
1450 @Override
1451 public void removeOnPermissionsChangeListener(OnPermissionsChangedListener listener) {
1452 synchronized (mPermissionListeners) {
1453 IOnPermissionsChangeListener delegate = mPermissionListeners.get(listener);
1454 if (delegate != null) {
1455 try {
1456 mPM.removeOnPermissionsChangeListener(delegate);
1457 mPermissionListeners.remove(listener);
1458 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001459 throw e.rethrowFromSystemServer();
Svetoslavf7c06eb2015-06-10 18:43:22 -07001460 }
1461 }
1462 }
1463 }
1464
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001465 static void configurationChanged() {
1466 synchronized (sSync) {
1467 sIconCache.clear();
1468 sStringCache.clear();
1469 }
1470 }
1471
Yao Chen022b8ea2016-12-16 11:03:28 -08001472 protected ApplicationPackageManager(ContextImpl context,
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001473 IPackageManager pm) {
1474 mContext = context;
1475 mPM = pm;
1476 }
1477
Alan Viveretteecd585a2015-04-13 10:32:51 -07001478 @Nullable
1479 private Drawable getCachedIcon(@NonNull ResourceName name) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001480 synchronized (sSync) {
Alan Viveretteecd585a2015-04-13 10:32:51 -07001481 final WeakReference<Drawable.ConstantState> wr = sIconCache.get(name);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001482 if (DEBUG_ICONS) Log.v(TAG, "Get cached weak drawable ref for "
1483 + name + ": " + wr);
1484 if (wr != null) { // we have the activity
Alan Viveretteecd585a2015-04-13 10:32:51 -07001485 final Drawable.ConstantState state = wr.get();
Romain Guy39fe17c2011-11-30 10:34:07 -08001486 if (state != null) {
1487 if (DEBUG_ICONS) {
1488 Log.v(TAG, "Get cached drawable state for " + name + ": " + state);
1489 }
1490 // Note: It's okay here to not use the newDrawable(Resources) variant
1491 // of the API. The ConstantState comes from a drawable that was
1492 // originally created by passing the proper app Resources instance
1493 // which means the state should already contain the proper
1494 // resources specific information (like density.) See
1495 // BitmapDrawable.BitmapState for instance.
1496 return state.newDrawable();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001497 }
1498 // our entry has been purged
1499 sIconCache.remove(name);
1500 }
1501 }
1502 return null;
1503 }
1504
Alan Viveretteecd585a2015-04-13 10:32:51 -07001505 private void putCachedIcon(@NonNull ResourceName name, @NonNull Drawable dr) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001506 synchronized (sSync) {
Alan Viveretteecd585a2015-04-13 10:32:51 -07001507 sIconCache.put(name, new WeakReference<>(dr.getConstantState()));
Romain Guy39fe17c2011-11-30 10:34:07 -08001508 if (DEBUG_ICONS) Log.v(TAG, "Added cached drawable state for " + name + ": " + dr);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001509 }
1510 }
1511
Romain Guy39fe17c2011-11-30 10:34:07 -08001512 static void handlePackageBroadcast(int cmd, String[] pkgList, boolean hasPkgInfo) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001513 boolean immediateGc = false;
Sudheer Shankacc6418f2016-10-13 12:03:44 -07001514 if (cmd == ApplicationThreadConstants.EXTERNAL_STORAGE_UNAVAILABLE) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001515 immediateGc = true;
1516 }
1517 if (pkgList != null && (pkgList.length > 0)) {
1518 boolean needCleanup = false;
1519 for (String ssp : pkgList) {
1520 synchronized (sSync) {
Dianne Hackbornadd005c2013-07-17 18:43:12 -07001521 for (int i=sIconCache.size()-1; i>=0; i--) {
1522 ResourceName nm = sIconCache.keyAt(i);
1523 if (nm.packageName.equals(ssp)) {
1524 //Log.i(TAG, "Removing cached drawable for " + nm);
1525 sIconCache.removeAt(i);
1526 needCleanup = true;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001527 }
1528 }
Dianne Hackbornadd005c2013-07-17 18:43:12 -07001529 for (int i=sStringCache.size()-1; i>=0; i--) {
1530 ResourceName nm = sStringCache.keyAt(i);
1531 if (nm.packageName.equals(ssp)) {
1532 //Log.i(TAG, "Removing cached string for " + nm);
1533 sStringCache.removeAt(i);
1534 needCleanup = true;
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001535 }
1536 }
1537 }
1538 }
1539 if (needCleanup || hasPkgInfo) {
1540 if (immediateGc) {
1541 // Schedule an immediate gc.
1542 Runtime.getRuntime().gc();
1543 } else {
1544 ActivityThread.currentActivityThread().scheduleGcIdler();
1545 }
1546 }
1547 }
1548 }
1549
1550 private static final class ResourceName {
1551 final String packageName;
1552 final int iconId;
1553
1554 ResourceName(String _packageName, int _iconId) {
1555 packageName = _packageName;
1556 iconId = _iconId;
1557 }
1558
1559 ResourceName(ApplicationInfo aInfo, int _iconId) {
1560 this(aInfo.packageName, _iconId);
1561 }
1562
1563 ResourceName(ComponentInfo cInfo, int _iconId) {
1564 this(cInfo.applicationInfo.packageName, _iconId);
1565 }
1566
1567 ResourceName(ResolveInfo rInfo, int _iconId) {
1568 this(rInfo.activityInfo.applicationInfo.packageName, _iconId);
1569 }
1570
1571 @Override
1572 public boolean equals(Object o) {
1573 if (this == o) return true;
1574 if (o == null || getClass() != o.getClass()) return false;
1575
1576 ResourceName that = (ResourceName) o;
1577
1578 if (iconId != that.iconId) return false;
1579 return !(packageName != null ?
1580 !packageName.equals(that.packageName) : that.packageName != null);
1581
1582 }
1583
1584 @Override
1585 public int hashCode() {
1586 int result;
1587 result = packageName.hashCode();
1588 result = 31 * result + iconId;
1589 return result;
1590 }
1591
1592 @Override
1593 public String toString() {
1594 return "{ResourceName " + packageName + " / " + iconId + "}";
1595 }
1596 }
1597
1598 private CharSequence getCachedString(ResourceName name) {
1599 synchronized (sSync) {
1600 WeakReference<CharSequence> wr = sStringCache.get(name);
1601 if (wr != null) { // we have the activity
1602 CharSequence cs = wr.get();
1603 if (cs != null) {
1604 return cs;
1605 }
1606 // our entry has been purged
1607 sStringCache.remove(name);
1608 }
1609 }
1610 return null;
1611 }
1612
1613 private void putCachedString(ResourceName name, CharSequence cs) {
1614 synchronized (sSync) {
1615 sStringCache.put(name, new WeakReference<CharSequence>(cs));
1616 }
1617 }
1618
1619 @Override
Tor Norbye7b9c9122013-05-30 16:48:33 -07001620 public CharSequence getText(String packageName, @StringRes int resid,
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001621 ApplicationInfo appInfo) {
1622 ResourceName name = new ResourceName(packageName, resid);
1623 CharSequence text = getCachedString(name);
1624 if (text != null) {
1625 return text;
1626 }
1627 if (appInfo == null) {
1628 try {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001629 appInfo = getApplicationInfo(packageName, sDefaultFlags);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001630 } catch (NameNotFoundException e) {
1631 return null;
1632 }
1633 }
1634 try {
1635 Resources r = getResourcesForApplication(appInfo);
1636 text = r.getText(resid);
1637 putCachedString(name, text);
1638 return text;
1639 } catch (NameNotFoundException e) {
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07001640 Log.w("PackageManager", "Failure retrieving resources for "
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001641 + appInfo.packageName);
1642 } catch (RuntimeException e) {
1643 // If an exception was thrown, fall through to return
1644 // default icon.
1645 Log.w("PackageManager", "Failure retrieving text 0x"
1646 + Integer.toHexString(resid) + " in package "
1647 + packageName, e);
1648 }
1649 return null;
1650 }
1651
1652 @Override
Tor Norbye7b9c9122013-05-30 16:48:33 -07001653 public XmlResourceParser getXml(String packageName, @XmlRes int resid,
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001654 ApplicationInfo appInfo) {
1655 if (appInfo == null) {
1656 try {
Adam Lesinskid00bb5e2014-10-07 12:14:45 -07001657 appInfo = getApplicationInfo(packageName, sDefaultFlags);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001658 } catch (NameNotFoundException e) {
1659 return null;
1660 }
1661 }
1662 try {
1663 Resources r = getResourcesForApplication(appInfo);
1664 return r.getXml(resid);
1665 } catch (RuntimeException e) {
1666 // If an exception was thrown, fall through to return
1667 // default icon.
1668 Log.w("PackageManager", "Failure retrieving xml 0x"
1669 + Integer.toHexString(resid) + " in package "
1670 + packageName, e);
1671 } catch (NameNotFoundException e) {
Alon Albert3fa51e32010-11-11 09:24:04 -08001672 Log.w("PackageManager", "Failure retrieving resources for "
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001673 + appInfo.packageName);
1674 }
1675 return null;
1676 }
1677
1678 @Override
1679 public CharSequence getApplicationLabel(ApplicationInfo info) {
1680 return info.loadLabel(this);
1681 }
1682
1683 @Override
1684 public void installPackage(Uri packageURI, IPackageInstallObserver observer, int flags,
1685 String installerPackageName) {
Jeff Sharkey513a0742014-07-08 17:10:32 -07001686 installCommon(packageURI, new LegacyPackageInstallObserver(observer), flags,
Todd Kennedya6793232016-02-24 22:46:00 +00001687 installerPackageName, mContext.getUserId());
Christopher Tatef1977b42014-03-24 16:25:51 -07001688 }
1689
Christopher Tatef1977b42014-03-24 16:25:51 -07001690 @Override
1691 public void installPackage(Uri packageURI, PackageInstallObserver observer,
1692 int flags, String installerPackageName) {
Todd Kennedya6793232016-02-24 22:46:00 +00001693 installCommon(packageURI, observer, flags, installerPackageName, mContext.getUserId());
Jeff Sharkey513a0742014-07-08 17:10:32 -07001694 }
1695
1696 private void installCommon(Uri packageURI,
1697 PackageInstallObserver observer, int flags, String installerPackageName,
Nicolas Prevot9a80e532015-09-23 15:49:28 +01001698 int userId) {
Jeff Sharkey513a0742014-07-08 17:10:32 -07001699 if (!"file".equals(packageURI.getScheme())) {
1700 throw new UnsupportedOperationException("Only file:// URIs are supported");
1701 }
Jeff Sharkey513a0742014-07-08 17:10:32 -07001702
1703 final String originPath = packageURI.getPath();
Christopher Tatef1977b42014-03-24 16:25:51 -07001704 try {
Nicolas Prevot9a80e532015-09-23 15:49:28 +01001705 mPM.installPackageAsUser(originPath, observer.getBinder(), flags, installerPackageName,
Todd Kennedya6793232016-02-24 22:46:00 +00001706 userId);
Jeff Sharkey27b2e692016-02-25 17:40:12 -07001707 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001708 throw e.rethrowFromSystemServer();
rich cannings706e8ba2012-08-20 13:20:14 -07001709 }
1710 }
1711
1712 @Override
Nicolas Prevot9a80e532015-09-23 15:49:28 +01001713 public int installExistingPackage(String packageName) throws NameNotFoundException {
Sunny Goyala31a74b2017-05-11 15:59:19 -07001714 return installExistingPackage(packageName, PackageManager.INSTALL_REASON_UNKNOWN);
1715 }
1716
1717 @Override
1718 public int installExistingPackage(String packageName, int installReason)
1719 throws NameNotFoundException {
1720 return installExistingPackageAsUser(packageName, installReason, mContext.getUserId());
Nicolas Prevot9a80e532015-09-23 15:49:28 +01001721 }
1722
1723 @Override
1724 public int installExistingPackageAsUser(String packageName, int userId)
Dianne Hackborn7767eac2012-08-23 18:25:40 -07001725 throws NameNotFoundException {
Sunny Goyala31a74b2017-05-11 15:59:19 -07001726 return installExistingPackageAsUser(packageName, PackageManager.INSTALL_REASON_UNKNOWN,
1727 userId);
1728 }
1729
1730 private int installExistingPackageAsUser(String packageName, int installReason, int userId)
1731 throws NameNotFoundException {
Dianne Hackborn7767eac2012-08-23 18:25:40 -07001732 try {
Todd Kennedybe0b8892017-02-15 14:13:52 -08001733 int res = mPM.installExistingPackageAsUser(packageName, userId, 0 /*installFlags*/,
Sunny Goyala31a74b2017-05-11 15:59:19 -07001734 installReason);
Dianne Hackborn7767eac2012-08-23 18:25:40 -07001735 if (res == INSTALL_FAILED_INVALID_URI) {
1736 throw new NameNotFoundException("Package " + packageName + " doesn't exist");
1737 }
1738 return res;
1739 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001740 throw e.rethrowFromSystemServer();
Dianne Hackborn7767eac2012-08-23 18:25:40 -07001741 }
1742 }
1743
1744 @Override
Kenny Root3a9b5fb2011-09-20 14:15:38 -07001745 public void verifyPendingInstall(int id, int response) {
Kenny Root5ab21572011-07-27 11:11:19 -07001746 try {
Kenny Root3a9b5fb2011-09-20 14:15:38 -07001747 mPM.verifyPendingInstall(id, response);
Kenny Root5ab21572011-07-27 11:11:19 -07001748 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001749 throw e.rethrowFromSystemServer();
Kenny Root5ab21572011-07-27 11:11:19 -07001750 }
1751 }
1752
1753 @Override
rich canningsd9ef3e52012-08-22 14:28:05 -07001754 public void extendVerificationTimeout(int id, int verificationCodeAtTimeout,
1755 long millisecondsToDelay) {
1756 try {
1757 mPM.extendVerificationTimeout(id, verificationCodeAtTimeout, millisecondsToDelay);
1758 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001759 throw e.rethrowFromSystemServer();
rich canningsd9ef3e52012-08-22 14:28:05 -07001760 }
1761 }
1762
1763 @Override
Todd Kennedydfa93ab2016-03-03 15:24:33 -08001764 public void verifyIntentFilter(int id, int verificationCode, List<String> failedDomains) {
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001765 try {
Todd Kennedydfa93ab2016-03-03 15:24:33 -08001766 mPM.verifyIntentFilter(id, verificationCode, failedDomains);
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001767 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001768 throw e.rethrowFromSystemServer();
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001769 }
1770 }
1771
1772 @Override
Jeff Sharkeye06b4d12016-01-06 14:51:50 -07001773 public int getIntentVerificationStatusAsUser(String packageName, int userId) {
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001774 try {
1775 return mPM.getIntentVerificationStatus(packageName, userId);
1776 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001777 throw e.rethrowFromSystemServer();
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001778 }
1779 }
1780
1781 @Override
Jeff Sharkeye06b4d12016-01-06 14:51:50 -07001782 public boolean updateIntentVerificationStatusAsUser(String packageName, int status, int userId) {
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001783 try {
1784 return mPM.updateIntentVerificationStatus(packageName, status, userId);
1785 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001786 throw e.rethrowFromSystemServer();
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001787 }
1788 }
1789
1790 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001791 @SuppressWarnings("unchecked")
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001792 public List<IntentFilterVerificationInfo> getIntentFilterVerifications(String packageName) {
1793 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001794 ParceledListSlice<IntentFilterVerificationInfo> parceledList =
1795 mPM.getIntentFilterVerifications(packageName);
1796 if (parceledList == null) {
1797 return Collections.emptyList();
1798 }
1799 return parceledList.getList();
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001800 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001801 throw e.rethrowFromSystemServer();
Fabrice Di Meglio1c1b4712014-11-19 17:12:32 -08001802 }
1803 }
1804
1805 @Override
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001806 @SuppressWarnings("unchecked")
Fabrice Di Meglio07885952015-04-06 19:41:28 -07001807 public List<IntentFilter> getAllIntentFilters(String packageName) {
1808 try {
Svetoslav Ganovb2c2e452016-03-24 18:01:17 -07001809 ParceledListSlice<IntentFilter> parceledList =
1810 mPM.getAllIntentFilters(packageName);
1811 if (parceledList == null) {
1812 return Collections.emptyList();
1813 }
1814 return parceledList.getList();
Fabrice Di Meglio07885952015-04-06 19:41:28 -07001815 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001816 throw e.rethrowFromSystemServer();
Fabrice Di Meglio07885952015-04-06 19:41:28 -07001817 }
1818 }
1819
1820 @Override
Jeff Sharkeye06b4d12016-01-06 14:51:50 -07001821 public String getDefaultBrowserPackageNameAsUser(int userId) {
Fabrice Di Meglio62271722015-04-10 17:24:02 -07001822 try {
1823 return mPM.getDefaultBrowserPackageName(userId);
1824 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001825 throw e.rethrowFromSystemServer();
Fabrice Di Meglio62271722015-04-10 17:24:02 -07001826 }
1827 }
1828
1829 @Override
Jeff Sharkeye06b4d12016-01-06 14:51:50 -07001830 public boolean setDefaultBrowserPackageNameAsUser(String packageName, int userId) {
Fabrice Di Meglio62271722015-04-10 17:24:02 -07001831 try {
1832 return mPM.setDefaultBrowserPackageName(packageName, userId);
1833 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001834 throw e.rethrowFromSystemServer();
Fabrice Di Meglio62271722015-04-10 17:24:02 -07001835 }
1836 }
1837
1838 @Override
Dianne Hackborn880119b2010-11-18 22:26:40 -08001839 public void setInstallerPackageName(String targetPackage,
1840 String installerPackageName) {
1841 try {
1842 mPM.setInstallerPackageName(targetPackage, installerPackageName);
1843 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001844 throw e.rethrowFromSystemServer();
Dianne Hackborn880119b2010-11-18 22:26:40 -08001845 }
1846 }
1847
1848 @Override
Todd Kennedyab532892017-03-08 14:19:49 -08001849 public void setUpdateAvailable(String packageName, boolean updateAvailable) {
1850 try {
1851 mPM.setUpdateAvailable(packageName, updateAvailable);
1852 } catch (RemoteException e) {
1853 throw e.rethrowFromSystemServer();
1854 }
1855 }
1856
1857 @Override
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001858 public String getInstallerPackageName(String packageName) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001859 try {
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001860 return mPM.getInstallerPackageName(packageName);
1861 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001862 throw e.rethrowFromSystemServer();
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001863 }
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001864 }
1865
1866 @Override
1867 public int getMoveStatus(int moveId) {
1868 try {
1869 return mPM.getMoveStatus(moveId);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001870 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001871 throw e.rethrowFromSystemServer();
Jeff Sharkeyb2b9ab82015-04-05 21:10:42 -07001872 }
1873 }
1874
1875 @Override
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001876 public void registerMoveCallback(MoveCallback callback, Handler handler) {
1877 synchronized (mDelegates) {
1878 final MoveCallbackDelegate delegate = new MoveCallbackDelegate(callback,
1879 handler.getLooper());
1880 try {
1881 mPM.registerMoveCallback(delegate);
1882 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001883 throw e.rethrowFromSystemServer();
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001884 }
1885 mDelegates.add(delegate);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08001886 }
1887 }
1888
1889 @Override
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001890 public void unregisterMoveCallback(MoveCallback callback) {
1891 synchronized (mDelegates) {
1892 for (Iterator<MoveCallbackDelegate> i = mDelegates.iterator(); i.hasNext();) {
1893 final MoveCallbackDelegate delegate = i.next();
1894 if (delegate.mCallback == callback) {
1895 try {
1896 mPM.unregisterMoveCallback(delegate);
1897 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001898 throw e.rethrowFromSystemServer();
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001899 }
1900 i.remove();
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001901 }
1902 }
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001903 }
1904 }
1905
1906 @Override
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001907 public int movePackage(String packageName, VolumeInfo vol) {
1908 try {
1909 final String volumeUuid;
1910 if (VolumeInfo.ID_PRIVATE_INTERNAL.equals(vol.id)) {
1911 volumeUuid = StorageManager.UUID_PRIVATE_INTERNAL;
1912 } else if (vol.isPrimaryPhysical()) {
1913 volumeUuid = StorageManager.UUID_PRIMARY_PHYSICAL;
1914 } else {
1915 volumeUuid = Preconditions.checkNotNull(vol.fsUuid);
1916 }
1917
1918 return mPM.movePackage(packageName, volumeUuid);
1919 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001920 throw e.rethrowFromSystemServer();
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001921 }
1922 }
1923
1924 @Override
1925 public @Nullable VolumeInfo getPackageCurrentVolume(ApplicationInfo app) {
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001926 final StorageManager storage = mContext.getSystemService(StorageManager.class);
Yao Chen022b8ea2016-12-16 11:03:28 -08001927 return getPackageCurrentVolume(app, storage);
1928 }
1929
1930 @VisibleForTesting
1931 protected @Nullable VolumeInfo getPackageCurrentVolume(ApplicationInfo app,
1932 StorageManager storage) {
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001933 if (app.isInternal()) {
1934 return storage.findVolumeById(VolumeInfo.ID_PRIVATE_INTERNAL);
1935 } else if (app.isExternalAsec()) {
1936 return storage.getPrimaryPhysicalVolume();
1937 } else {
1938 return storage.findVolumeByUuid(app.volumeUuid);
1939 }
1940 }
1941
1942 @Override
1943 public @NonNull List<VolumeInfo> getPackageCandidateVolumes(ApplicationInfo app) {
Yao Chen022b8ea2016-12-16 11:03:28 -08001944 final StorageManager storageManager = mContext.getSystemService(StorageManager.class);
1945 return getPackageCandidateVolumes(app, storageManager, mPM);
1946 }
1947
1948 @VisibleForTesting
1949 protected @NonNull List<VolumeInfo> getPackageCandidateVolumes(ApplicationInfo app,
1950 StorageManager storageManager, IPackageManager pm) {
1951 final VolumeInfo currentVol = getPackageCurrentVolume(app, storageManager);
1952 final List<VolumeInfo> vols = storageManager.getVolumes();
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001953 final List<VolumeInfo> candidates = new ArrayList<>();
1954 for (VolumeInfo vol : vols) {
Yao Chen022b8ea2016-12-16 11:03:28 -08001955 if (Objects.equals(vol, currentVol)
1956 || isPackageCandidateVolume(mContext, app, vol, pm)) {
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001957 candidates.add(vol);
1958 }
1959 }
1960 return candidates;
1961 }
1962
Yao Chen022b8ea2016-12-16 11:03:28 -08001963 @VisibleForTesting
1964 protected boolean isForceAllowOnExternal(Context context) {
1965 return Settings.Global.getInt(
Todd Kennedyf39ca8f2015-08-07 14:15:07 -07001966 context.getContentResolver(), Settings.Global.FORCE_ALLOW_ON_EXTERNAL, 0) != 0;
Yao Chen022b8ea2016-12-16 11:03:28 -08001967 }
1968
1969 @VisibleForTesting
1970 protected boolean isAllow3rdPartyOnInternal(Context context) {
1971 return context.getResources().getBoolean(
1972 com.android.internal.R.bool.config_allow3rdPartyAppOnInternal);
1973 }
1974
1975 private boolean isPackageCandidateVolume(
1976 ContextImpl context, ApplicationInfo app, VolumeInfo vol, IPackageManager pm) {
1977 final boolean forceAllowOnExternal = isForceAllowOnExternal(context);
1978
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001979 if (VolumeInfo.ID_PRIVATE_INTERNAL.equals(vol.getId())) {
Yao Chen022b8ea2016-12-16 11:03:28 -08001980 return app.isSystemApp() || isAllow3rdPartyOnInternal(context);
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001981 }
1982
1983 // System apps and apps demanding internal storage can't be moved
1984 // anywhere else
Todd Kennedyf39ca8f2015-08-07 14:15:07 -07001985 if (app.isSystemApp()) {
1986 return false;
1987 }
1988 if (!forceAllowOnExternal
Dianne Hackborn30a4e6d2015-10-12 17:14:56 -07001989 && (app.installLocation == PackageInfo.INSTALL_LOCATION_INTERNAL_ONLY
1990 || app.installLocation == PackageInfo.INSTALL_LOCATION_UNSPECIFIED)) {
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07001991 return false;
1992 }
1993
Jeff Sharkey620b32b2015-04-23 19:36:02 -07001994 // Gotta be able to write there
1995 if (!vol.isMountedWritable()) {
1996 return false;
1997 }
1998
1999 // Moving into an ASEC on public primary is only option internal
2000 if (vol.isPrimaryPhysical()) {
2001 return app.isInternal();
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07002002 }
2003
Makoto Onukif34db0a2016-02-17 11:17:15 -08002004 // Some apps can't be moved. (e.g. device admins)
2005 try {
Yao Chen022b8ea2016-12-16 11:03:28 -08002006 if (pm.isPackageDeviceAdminOnAnyUser(app.packageName)) {
Makoto Onukif34db0a2016-02-17 11:17:15 -08002007 return false;
2008 }
2009 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002010 throw e.rethrowFromSystemServer();
Makoto Onukif34db0a2016-02-17 11:17:15 -08002011 }
2012
Jeff Sharkeye2d45be2015-04-15 17:14:12 -07002013 // Otherwise we can move to any private volume
2014 return (vol.getType() == VolumeInfo.TYPE_PRIVATE);
2015 }
2016
2017 @Override
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002018 public int movePrimaryStorage(VolumeInfo vol) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002019 try {
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002020 final String volumeUuid;
2021 if (VolumeInfo.ID_PRIVATE_INTERNAL.equals(vol.id)) {
2022 volumeUuid = StorageManager.UUID_PRIVATE_INTERNAL;
2023 } else if (vol.isPrimaryPhysical()) {
2024 volumeUuid = StorageManager.UUID_PRIMARY_PHYSICAL;
2025 } else {
2026 volumeUuid = Preconditions.checkNotNull(vol.fsUuid);
2027 }
2028
2029 return mPM.movePrimaryStorage(volumeUuid);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002030 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002031 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002032 }
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002033 }
2034
Jeff Sharkey275e3e42015-04-24 16:10:32 -07002035 @Override
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002036 public @Nullable VolumeInfo getPrimaryStorageCurrentVolume() {
2037 final StorageManager storage = mContext.getSystemService(StorageManager.class);
2038 final String volumeUuid = storage.getPrimaryStorageUuid();
Jeff Sharkey50a05452015-04-29 11:24:52 -07002039 return storage.findVolumeByQualifiedUuid(volumeUuid);
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002040 }
2041
Jeff Sharkey275e3e42015-04-24 16:10:32 -07002042 @Override
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002043 public @NonNull List<VolumeInfo> getPrimaryStorageCandidateVolumes() {
2044 final StorageManager storage = mContext.getSystemService(StorageManager.class);
2045 final VolumeInfo currentVol = getPrimaryStorageCurrentVolume();
2046 final List<VolumeInfo> vols = storage.getVolumes();
2047 final List<VolumeInfo> candidates = new ArrayList<>();
Jeff Sharkeyfced5342015-05-10 14:53:34 -07002048 if (Objects.equals(StorageManager.UUID_PRIMARY_PHYSICAL,
2049 storage.getPrimaryStorageUuid()) && currentVol != null) {
2050 // TODO: support moving primary physical to emulated volume
2051 candidates.add(currentVol);
2052 } else {
2053 for (VolumeInfo vol : vols) {
2054 if (Objects.equals(vol, currentVol) || isPrimaryStorageCandidateVolume(vol)) {
2055 candidates.add(vol);
2056 }
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002057 }
2058 }
2059 return candidates;
2060 }
2061
2062 private static boolean isPrimaryStorageCandidateVolume(VolumeInfo vol) {
2063 // Private internal is always an option
2064 if (VolumeInfo.ID_PRIVATE_INTERNAL.equals(vol.getId())) {
2065 return true;
2066 }
2067
2068 // Gotta be able to write there
2069 if (!vol.isMountedWritable()) {
2070 return false;
2071 }
2072
Jeff Sharkeyfced5342015-05-10 14:53:34 -07002073 // We can move to any private volume
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002074 return (vol.getType() == VolumeInfo.TYPE_PRIVATE);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002075 }
2076
2077 @Override
2078 public void deletePackage(String packageName, IPackageDeleteObserver observer, int flags) {
Robin Lee0e27c872015-09-28 14:37:40 +01002079 deletePackageAsUser(packageName, observer, flags, mContext.getUserId());
Nicolas Prevot9a80e532015-09-23 15:49:28 +01002080 }
2081
2082 @Override
Svet Ganov67882122016-12-11 16:36:34 -08002083 public void deletePackageAsUser(String packageName, IPackageDeleteObserver observer,
2084 int flags, int userId) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002085 try {
Svet Ganov67882122016-12-11 16:36:34 -08002086 mPM.deletePackageAsUser(packageName, PackageManager.VERSION_CODE_HIGHEST,
2087 observer, userId, flags);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002088 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002089 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002090 }
2091 }
Jeff Sharkeyfbd0e9f2014-08-06 16:34:34 -07002092
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002093 @Override
2094 public void clearApplicationUserData(String packageName,
2095 IPackageDataObserver observer) {
2096 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -07002097 mPM.clearApplicationUserData(packageName, observer, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002098 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002099 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002100 }
2101 }
2102 @Override
2103 public void deleteApplicationCacheFiles(String packageName,
2104 IPackageDataObserver observer) {
2105 try {
2106 mPM.deleteApplicationCacheFiles(packageName, observer);
2107 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002108 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002109 }
2110 }
Jeff Sharkey529f91f2015-04-18 20:23:13 -07002111
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002112 @Override
Suprabh Shukla78c9eb82016-04-12 15:51:35 -07002113 public void deleteApplicationCacheFilesAsUser(String packageName, int userId,
2114 IPackageDataObserver observer) {
2115 try {
2116 mPM.deleteApplicationCacheFilesAsUser(packageName, userId, observer);
2117 } catch (RemoteException e) {
2118 throw e.rethrowFromSystemServer();
2119 }
2120 }
2121
2122 @Override
Jeff Sharkey529f91f2015-04-18 20:23:13 -07002123 public void freeStorageAndNotify(String volumeUuid, long idealStorageSize,
2124 IPackageDataObserver observer) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002125 try {
Jeff Sharkeyddff8072017-05-26 13:10:46 -06002126 mPM.freeStorageAndNotify(volumeUuid, idealStorageSize, 0, observer);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002127 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002128 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002129 }
2130 }
2131
2132 @Override
Jeff Sharkey529f91f2015-04-18 20:23:13 -07002133 public void freeStorage(String volumeUuid, long freeStorageSize, IntentSender pi) {
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002134 try {
Jeff Sharkeyddff8072017-05-26 13:10:46 -06002135 mPM.freeStorage(volumeUuid, freeStorageSize, 0, pi);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002136 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002137 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002138 }
2139 }
2140
2141 @Override
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00002142 public String[] setPackagesSuspendedAsUser(String[] packageNames, boolean suspended,
2143 int userId) {
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00002144 try {
Andrei Stingaceanueb84b182016-01-26 18:39:55 +00002145 return mPM.setPackagesSuspendedAsUser(packageNames, suspended, userId);
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00002146 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002147 throw e.rethrowFromSystemServer();
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00002148 }
Andrei Stingaceanu1e283912015-11-26 15:26:28 +00002149 }
2150
2151 @Override
Andrei Stingaceanu355b2322016-02-12 16:43:51 +00002152 public boolean isPackageSuspendedForUser(String packageName, int userId) {
2153 try {
2154 return mPM.isPackageSuspendedForUser(packageName, userId);
2155 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002156 throw e.rethrowFromSystemServer();
Andrei Stingaceanu355b2322016-02-12 16:43:51 +00002157 }
Andrei Stingaceanu355b2322016-02-12 16:43:51 +00002158 }
2159
Jeff Sharkey9bc89af2017-01-11 11:25:50 -07002160 /** @hide */
2161 @Override
2162 public void setApplicationCategoryHint(String packageName, int categoryHint) {
2163 try {
2164 mPM.setApplicationCategoryHint(packageName, categoryHint,
2165 mContext.getOpPackageName());
2166 } catch (RemoteException e) {
2167 throw e.rethrowFromSystemServer();
2168 }
2169 }
2170
Andrei Stingaceanu355b2322016-02-12 16:43:51 +00002171 @Override
Jeff Sharkeye06b4d12016-01-06 14:51:50 -07002172 public void getPackageSizeInfoAsUser(String packageName, int userHandle,
Dianne Hackborn0c380492012-08-20 17:23:30 -07002173 IPackageStatsObserver observer) {
Jeff Sharkey6f4b2a32017-03-21 14:13:41 -06002174 final String msg = "Shame on you for calling the hidden API "
2175 + "getPackageSizeInfoAsUser(). Shame!";
Jeff Sharkeye6306c42017-03-07 21:03:18 -07002176 if (mContext.getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.O) {
Jeff Sharkey6f4b2a32017-03-21 14:13:41 -06002177 throw new UnsupportedOperationException(msg);
Jeff Sharkeye6306c42017-03-07 21:03:18 -07002178 } else if (observer != null) {
Jeff Sharkey6f4b2a32017-03-21 14:13:41 -06002179 Log.d(TAG, msg);
Jeff Sharkeye6306c42017-03-07 21:03:18 -07002180 try {
2181 observer.onGetStatsCompleted(null, false);
2182 } catch (RemoteException ignored) {
2183 }
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002184 }
2185 }
Jeff Sharkeyd5896632016-03-04 16:16:00 -07002186
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002187 @Override
2188 public void addPackageToPreferred(String packageName) {
Jeff Sharkeyd5896632016-03-04 16:16:00 -07002189 Log.w(TAG, "addPackageToPreferred() is a no-op");
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002190 }
2191
2192 @Override
2193 public void removePackageFromPreferred(String packageName) {
Jeff Sharkeyd5896632016-03-04 16:16:00 -07002194 Log.w(TAG, "removePackageFromPreferred() is a no-op");
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002195 }
2196
2197 @Override
2198 public List<PackageInfo> getPreferredPackages(int flags) {
Jeff Sharkeyd5896632016-03-04 16:16:00 -07002199 Log.w(TAG, "getPreferredPackages() is a no-op");
2200 return Collections.emptyList();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002201 }
2202
2203 @Override
2204 public void addPreferredActivity(IntentFilter filter,
2205 int match, ComponentName[] set, ComponentName activity) {
2206 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -07002207 mPM.addPreferredActivity(filter, match, set, activity, mContext.getUserId());
Amith Yamasania3f133a2012-08-09 17:11:28 -07002208 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002209 throw e.rethrowFromSystemServer();
Amith Yamasania3f133a2012-08-09 17:11:28 -07002210 }
2211 }
2212
2213 @Override
Jeff Sharkeye06b4d12016-01-06 14:51:50 -07002214 public void addPreferredActivityAsUser(IntentFilter filter, int match,
Amith Yamasania3f133a2012-08-09 17:11:28 -07002215 ComponentName[] set, ComponentName activity, int userId) {
2216 try {
2217 mPM.addPreferredActivity(filter, match, set, activity, userId);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002218 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002219 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002220 }
2221 }
2222
2223 @Override
2224 public void replacePreferredActivity(IntentFilter filter,
2225 int match, ComponentName[] set, ComponentName activity) {
2226 try {
Robin Lee0e27c872015-09-28 14:37:40 +01002227 mPM.replacePreferredActivity(filter, match, set, activity, mContext.getUserId());
Amith Yamasani41c1ded2014-08-05 11:15:05 -07002228 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002229 throw e.rethrowFromSystemServer();
Amith Yamasani41c1ded2014-08-05 11:15:05 -07002230 }
2231 }
2232
2233 @Override
2234 public void replacePreferredActivityAsUser(IntentFilter filter,
2235 int match, ComponentName[] set, ComponentName activity,
2236 int userId) {
2237 try {
2238 mPM.replacePreferredActivity(filter, match, set, activity, userId);
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002239 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002240 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002241 }
2242 }
2243
2244 @Override
2245 public void clearPackagePreferredActivities(String packageName) {
2246 try {
2247 mPM.clearPackagePreferredActivities(packageName);
2248 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002249 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002250 }
2251 }
2252
2253 @Override
2254 public int getPreferredActivities(List<IntentFilter> outFilters,
2255 List<ComponentName> outActivities, String packageName) {
2256 try {
2257 return mPM.getPreferredActivities(outFilters, outActivities, packageName);
2258 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002259 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002260 }
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002261 }
2262
2263 @Override
Christopher Tatea2a0850d2013-09-05 16:38:58 -07002264 public ComponentName getHomeActivities(List<ResolveInfo> outActivities) {
2265 try {
2266 return mPM.getHomeActivities(outActivities);
2267 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002268 throw e.rethrowFromSystemServer();
Christopher Tatea2a0850d2013-09-05 16:38:58 -07002269 }
Christopher Tatea2a0850d2013-09-05 16:38:58 -07002270 }
2271
2272 @Override
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002273 public void setComponentEnabledSetting(ComponentName componentName,
2274 int newState, int flags) {
2275 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -07002276 mPM.setComponentEnabledSetting(componentName, newState, flags, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002277 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002278 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002279 }
2280 }
2281
2282 @Override
2283 public int getComponentEnabledSetting(ComponentName componentName) {
2284 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -07002285 return mPM.getComponentEnabledSetting(componentName, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002286 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002287 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002288 }
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002289 }
2290
2291 @Override
2292 public void setApplicationEnabledSetting(String packageName,
2293 int newState, int flags) {
2294 try {
Dianne Hackborn3fa3c28a2013-03-26 16:15:41 -07002295 mPM.setApplicationEnabledSetting(packageName, newState, flags,
Dianne Hackborn95d78532013-09-11 09:51:14 -07002296 mContext.getUserId(), mContext.getOpPackageName());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002297 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002298 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002299 }
2300 }
2301
2302 @Override
2303 public int getApplicationEnabledSetting(String packageName) {
2304 try {
Jeff Sharkeyded653b2012-09-27 19:09:24 -07002305 return mPM.getApplicationEnabledSetting(packageName, mContext.getUserId());
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002306 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002307 throw e.rethrowFromSystemServer();
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002308 }
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002309 }
2310
Amith Yamasani655d0e22013-06-12 14:19:10 -07002311 @Override
Sudheer Shankabbb3ff22015-07-09 15:39:23 +01002312 public void flushPackageRestrictionsAsUser(int userId) {
2313 try {
2314 mPM.flushPackageRestrictionsAsUser(userId);
2315 } catch (RemoteException e) {
2316 throw e.rethrowFromSystemServer();
2317 }
2318 }
2319
2320 @Override
Amith Yamasanie5bcff62014-07-19 15:44:09 -07002321 public boolean setApplicationHiddenSettingAsUser(String packageName, boolean hidden,
Amith Yamasani655d0e22013-06-12 14:19:10 -07002322 UserHandle user) {
2323 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07002324 return mPM.setApplicationHiddenSettingAsUser(packageName, hidden,
Amith Yamasani655d0e22013-06-12 14:19:10 -07002325 user.getIdentifier());
Jeff Sharkey27b2e692016-02-25 17:40:12 -07002326 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002327 throw e.rethrowFromSystemServer();
Amith Yamasani655d0e22013-06-12 14:19:10 -07002328 }
Amith Yamasani655d0e22013-06-12 14:19:10 -07002329 }
2330
2331 @Override
Amith Yamasanie5bcff62014-07-19 15:44:09 -07002332 public boolean getApplicationHiddenSettingAsUser(String packageName, UserHandle user) {
Amith Yamasani655d0e22013-06-12 14:19:10 -07002333 try {
Amith Yamasanie5bcff62014-07-19 15:44:09 -07002334 return mPM.getApplicationHiddenSettingAsUser(packageName, user.getIdentifier());
Jeff Sharkey27b2e692016-02-25 17:40:12 -07002335 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002336 throw e.rethrowFromSystemServer();
Amith Yamasani655d0e22013-06-12 14:19:10 -07002337 }
Amith Yamasani655d0e22013-06-12 14:19:10 -07002338 }
2339
dcashmanc6f22492014-08-14 09:54:51 -07002340 /** @hide */
dcashman9d2f4412014-06-09 09:27:54 -07002341 @Override
2342 public KeySet getKeySetByAlias(String packageName, String alias) {
2343 Preconditions.checkNotNull(packageName);
2344 Preconditions.checkNotNull(alias);
dcashman9d2f4412014-06-09 09:27:54 -07002345 try {
Jeff Sharkey27b2e692016-02-25 17:40:12 -07002346 return mPM.getKeySetByAlias(packageName, alias);
dcashman9d2f4412014-06-09 09:27:54 -07002347 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002348 throw e.rethrowFromSystemServer();
dcashman9d2f4412014-06-09 09:27:54 -07002349 }
dcashman9d2f4412014-06-09 09:27:54 -07002350 }
2351
dcashmanc6f22492014-08-14 09:54:51 -07002352 /** @hide */
dcashman9d2f4412014-06-09 09:27:54 -07002353 @Override
2354 public KeySet getSigningKeySet(String packageName) {
2355 Preconditions.checkNotNull(packageName);
dcashman9d2f4412014-06-09 09:27:54 -07002356 try {
Jeff Sharkey27b2e692016-02-25 17:40:12 -07002357 return mPM.getSigningKeySet(packageName);
dcashman9d2f4412014-06-09 09:27:54 -07002358 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002359 throw e.rethrowFromSystemServer();
dcashman9d2f4412014-06-09 09:27:54 -07002360 }
dcashman9d2f4412014-06-09 09:27:54 -07002361 }
2362
dcashmanc6f22492014-08-14 09:54:51 -07002363 /** @hide */
dcashman9d2f4412014-06-09 09:27:54 -07002364 @Override
2365 public boolean isSignedBy(String packageName, KeySet ks) {
2366 Preconditions.checkNotNull(packageName);
2367 Preconditions.checkNotNull(ks);
dcashman9d2f4412014-06-09 09:27:54 -07002368 try {
dcashmanc6f22492014-08-14 09:54:51 -07002369 return mPM.isPackageSignedByKeySet(packageName, ks);
dcashman9d2f4412014-06-09 09:27:54 -07002370 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002371 throw e.rethrowFromSystemServer();
dcashman9d2f4412014-06-09 09:27:54 -07002372 }
2373 }
2374
dcashmanc6f22492014-08-14 09:54:51 -07002375 /** @hide */
dcashman9d2f4412014-06-09 09:27:54 -07002376 @Override
2377 public boolean isSignedByExactly(String packageName, KeySet ks) {
2378 Preconditions.checkNotNull(packageName);
2379 Preconditions.checkNotNull(ks);
dcashman9d2f4412014-06-09 09:27:54 -07002380 try {
dcashmanc6f22492014-08-14 09:54:51 -07002381 return mPM.isPackageSignedByKeySetExactly(packageName, ks);
dcashman9d2f4412014-06-09 09:27:54 -07002382 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002383 throw e.rethrowFromSystemServer();
dcashman9d2f4412014-06-09 09:27:54 -07002384 }
2385 }
2386
Kenny Root0aaa0d92011-09-12 16:42:55 -07002387 /**
2388 * @hide
2389 */
2390 @Override
2391 public VerifierDeviceIdentity getVerifierDeviceIdentity() {
2392 try {
2393 return mPM.getVerifierDeviceIdentity();
2394 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002395 throw e.rethrowFromSystemServer();
Kenny Root0aaa0d92011-09-12 16:42:55 -07002396 }
Kenny Root0aaa0d92011-09-12 16:42:55 -07002397 }
2398
Jeff Hao9f60c082014-10-28 18:51:07 -07002399 /**
2400 * @hide
2401 */
2402 @Override
2403 public boolean isUpgrade() {
2404 try {
2405 return mPM.isUpgrade();
2406 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002407 throw e.rethrowFromSystemServer();
Jeff Hao9f60c082014-10-28 18:51:07 -07002408 }
2409 }
2410
Jeff Sharkey3a44f3f2014-04-28 17:36:31 -07002411 @Override
Jeff Sharkey16c8e3f2014-07-24 17:08:17 -07002412 public PackageInstaller getPackageInstaller() {
2413 synchronized (mLock) {
2414 if (mInstaller == null) {
2415 try {
Svet Ganov67882122016-12-11 16:36:34 -08002416 mInstaller = new PackageInstaller(mPM.getPackageInstaller(),
Jeff Sharkey16c8e3f2014-07-24 17:08:17 -07002417 mContext.getPackageName(), mContext.getUserId());
2418 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002419 throw e.rethrowFromSystemServer();
Jeff Sharkey16c8e3f2014-07-24 17:08:17 -07002420 }
2421 }
2422 return mInstaller;
Jeff Sharkey3a44f3f2014-04-28 17:36:31 -07002423 }
2424 }
2425
Jeff Sharkey6c833e02014-07-14 22:44:30 -07002426 @Override
2427 public boolean isPackageAvailable(String packageName) {
2428 try {
2429 return mPM.isPackageAvailable(packageName, mContext.getUserId());
2430 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002431 throw e.rethrowFromSystemServer();
Jeff Sharkey6c833e02014-07-14 22:44:30 -07002432 }
2433 }
2434
Nicolas Prevotc79586e2014-05-06 12:47:57 +01002435 /**
2436 * @hide
2437 */
2438 @Override
Nicolas Prevot63798c52014-05-27 13:22:38 +01002439 public void addCrossProfileIntentFilter(IntentFilter filter, int sourceUserId, int targetUserId,
2440 int flags) {
Nicolas Prevotc79586e2014-05-06 12:47:57 +01002441 try {
Nicolas Prevot3f7777f2014-07-24 15:58:39 +01002442 mPM.addCrossProfileIntentFilter(filter, mContext.getOpPackageName(),
Nicolas Prevot4b8d5822015-03-05 15:20:49 +00002443 sourceUserId, targetUserId, flags);
Nicolas Prevotc79586e2014-05-06 12:47:57 +01002444 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002445 throw e.rethrowFromSystemServer();
Nicolas Prevotc79586e2014-05-06 12:47:57 +01002446 }
2447 }
2448
2449 /**
2450 * @hide
2451 */
2452 @Override
Nicolas Prevot81948992014-05-16 18:25:26 +01002453 public void clearCrossProfileIntentFilters(int sourceUserId) {
Nicolas Prevotc79586e2014-05-06 12:47:57 +01002454 try {
Nicolas Prevot4b8d5822015-03-05 15:20:49 +00002455 mPM.clearCrossProfileIntentFilters(sourceUserId, mContext.getOpPackageName());
Nicolas Prevotc79586e2014-05-06 12:47:57 +01002456 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002457 throw e.rethrowFromSystemServer();
Nicolas Prevotc79586e2014-05-06 12:47:57 +01002458 }
2459 }
2460
Nicolas Prevot88cc3462014-05-14 14:51:48 +01002461 /**
2462 * @hide
2463 */
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +01002464 public Drawable loadItemIcon(PackageItemInfo itemInfo, ApplicationInfo appInfo) {
Benjamin Franzec2d48b2014-10-01 15:38:43 +01002465 Drawable dr = loadUnbadgedItemIcon(itemInfo, appInfo);
2466 if (itemInfo.showUserIcon != UserHandle.USER_NULL) {
2467 return dr;
2468 }
2469 return getUserBadgedIcon(dr, new UserHandle(mContext.getUserId()));
2470 }
2471
2472 /**
2473 * @hide
2474 */
2475 public Drawable loadUnbadgedItemIcon(PackageItemInfo itemInfo, ApplicationInfo appInfo) {
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +01002476 if (itemInfo.showUserIcon != UserHandle.USER_NULL) {
Alexandra Gherghina64d4dca2014-08-28 18:26:56 +01002477 Bitmap bitmap = getUserManager().getUserIcon(itemInfo.showUserIcon);
2478 if (bitmap == null) {
Tony Mak213955e2017-11-23 16:57:08 +08002479 return UserIcons.getDefaultUserIcon(
2480 mContext.getResources(), itemInfo.showUserIcon, /* light= */ false);
Alexandra Gherghina64d4dca2014-08-28 18:26:56 +01002481 }
2482 return new BitmapDrawable(bitmap);
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +01002483 }
Alexandra Gherghinadb811db2014-08-29 13:43:59 +01002484 Drawable dr = null;
2485 if (itemInfo.packageName != null) {
2486 dr = getDrawable(itemInfo.packageName, itemInfo.icon, appInfo);
2487 }
Alexandra Gherghinaa71e3902014-07-25 20:03:47 +01002488 if (dr == null) {
Alexandra Gherghinaa7093142014-07-30 13:43:39 +01002489 dr = itemInfo.loadDefaultIcon(this);
Nicolas Prevot7f7b0c72014-06-23 15:59:38 +01002490 }
Benjamin Franzec2d48b2014-10-01 15:38:43 +01002491 return dr;
Svetoslavc7d62f02014-09-04 15:39:54 -07002492 }
2493
2494 private Drawable getBadgedDrawable(Drawable drawable, Drawable badgeDrawable,
2495 Rect badgeLocation, boolean tryBadgeInPlace) {
2496 final int badgedWidth = drawable.getIntrinsicWidth();
2497 final int badgedHeight = drawable.getIntrinsicHeight();
2498 final boolean canBadgeInPlace = tryBadgeInPlace
2499 && (drawable instanceof BitmapDrawable)
2500 && ((BitmapDrawable) drawable).getBitmap().isMutable();
2501
2502 final Bitmap bitmap;
2503 if (canBadgeInPlace) {
2504 bitmap = ((BitmapDrawable) drawable).getBitmap();
2505 } else {
2506 bitmap = Bitmap.createBitmap(badgedWidth, badgedHeight, Bitmap.Config.ARGB_8888);
2507 }
2508 Canvas canvas = new Canvas(bitmap);
2509
2510 if (!canBadgeInPlace) {
2511 drawable.setBounds(0, 0, badgedWidth, badgedHeight);
2512 drawable.draw(canvas);
2513 }
2514
2515 if (badgeLocation != null) {
2516 if (badgeLocation.left < 0 || badgeLocation.top < 0
2517 || badgeLocation.width() > badgedWidth || badgeLocation.height() > badgedHeight) {
2518 throw new IllegalArgumentException("Badge location " + badgeLocation
2519 + " not in badged drawable bounds "
2520 + new Rect(0, 0, badgedWidth, badgedHeight));
2521 }
2522 badgeDrawable.setBounds(0, 0, badgeLocation.width(), badgeLocation.height());
2523
2524 canvas.save();
2525 canvas.translate(badgeLocation.left, badgeLocation.top);
2526 badgeDrawable.draw(canvas);
2527 canvas.restore();
2528 } else {
2529 badgeDrawable.setBounds(0, 0, badgedWidth, badgedHeight);
2530 badgeDrawable.draw(canvas);
2531 }
2532
2533 if (!canBadgeInPlace) {
2534 BitmapDrawable mergedDrawable = new BitmapDrawable(mContext.getResources(), bitmap);
2535
2536 if (drawable instanceof BitmapDrawable) {
2537 BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
2538 mergedDrawable.setTargetDensity(bitmapDrawable.getBitmap().getDensity());
2539 }
2540
2541 return mergedDrawable;
2542 }
2543
2544 return drawable;
2545 }
2546
Tony Mak8673b282016-03-21 21:10:59 +00002547 private boolean isManagedProfile(int userId) {
2548 return getUserManager().isManagedProfile(userId);
Nicolas Prevot88cc3462014-05-14 14:51:48 +01002549 }
2550
Bartosz Fabianowskia34f53f2017-01-11 18:08:47 +01002551 /**
2552 * @hide
2553 */
2554 @Override
2555 public int getInstallReason(String packageName, UserHandle user) {
2556 try {
2557 return mPM.getInstallReason(packageName, user.getIdentifier());
2558 } catch (RemoteException e) {
2559 throw e.rethrowFromSystemServer();
2560 }
2561 }
2562
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002563 /** {@hide} */
2564 private static class MoveCallbackDelegate extends IPackageMoveObserver.Stub implements
2565 Handler.Callback {
Jeff Sharkey50a05452015-04-29 11:24:52 -07002566 private static final int MSG_CREATED = 1;
2567 private static final int MSG_STATUS_CHANGED = 2;
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002568
2569 final MoveCallback mCallback;
2570 final Handler mHandler;
2571
2572 public MoveCallbackDelegate(MoveCallback callback, Looper looper) {
2573 mCallback = callback;
2574 mHandler = new Handler(looper, this);
2575 }
2576
2577 @Override
2578 public boolean handleMessage(Message msg) {
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002579 switch (msg.what) {
Jeff Sharkey50a05452015-04-29 11:24:52 -07002580 case MSG_CREATED: {
Jeff Sharkeyb36586a2015-04-27 08:42:28 -07002581 final SomeArgs args = (SomeArgs) msg.obj;
Jeff Sharkey50a05452015-04-29 11:24:52 -07002582 mCallback.onCreated(args.argi1, (Bundle) args.arg2);
Jeff Sharkeyb36586a2015-04-27 08:42:28 -07002583 args.recycle();
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002584 return true;
Jeff Sharkey50a05452015-04-29 11:24:52 -07002585 }
2586 case MSG_STATUS_CHANGED: {
2587 final SomeArgs args = (SomeArgs) msg.obj;
2588 mCallback.onStatusChanged(args.argi1, args.argi2, (long) args.arg3);
2589 args.recycle();
2590 return true;
2591 }
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002592 }
2593 return false;
2594 }
2595
2596 @Override
Jeff Sharkey50a05452015-04-29 11:24:52 -07002597 public void onCreated(int moveId, Bundle extras) {
Jeff Sharkeyb36586a2015-04-27 08:42:28 -07002598 final SomeArgs args = SomeArgs.obtain();
2599 args.argi1 = moveId;
Jeff Sharkey50a05452015-04-29 11:24:52 -07002600 args.arg2 = extras;
2601 mHandler.obtainMessage(MSG_CREATED, args).sendToTarget();
2602 }
2603
2604 @Override
2605 public void onStatusChanged(int moveId, int status, long estMillis) {
2606 final SomeArgs args = SomeArgs.obtain();
2607 args.argi1 = moveId;
2608 args.argi2 = status;
2609 args.arg3 = estMillis;
Jeff Sharkeyb36586a2015-04-27 08:42:28 -07002610 mHandler.obtainMessage(MSG_STATUS_CHANGED, args).sendToTarget();
Jeff Sharkey620b32b2015-04-23 19:36:02 -07002611 }
2612 }
2613
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002614 private final ContextImpl mContext;
2615 private final IPackageManager mPM;
2616
2617 private static final Object sSync = new Object();
Dianne Hackbornadd005c2013-07-17 18:43:12 -07002618 private static ArrayMap<ResourceName, WeakReference<Drawable.ConstantState>> sIconCache
2619 = new ArrayMap<ResourceName, WeakReference<Drawable.ConstantState>>();
2620 private static ArrayMap<ResourceName, WeakReference<CharSequence>> sStringCache
2621 = new ArrayMap<ResourceName, WeakReference<CharSequence>>();
Svetoslavf7c06eb2015-06-10 18:43:22 -07002622
2623 private final Map<OnPermissionsChangedListener, IOnPermissionsChangeListener>
2624 mPermissionListeners = new ArrayMap<>();
2625
2626 public class OnPermissionsChangeListenerDelegate extends IOnPermissionsChangeListener.Stub
2627 implements Handler.Callback{
2628 private static final int MSG_PERMISSIONS_CHANGED = 1;
2629
2630 private final OnPermissionsChangedListener mListener;
2631 private final Handler mHandler;
2632
2633
2634 public OnPermissionsChangeListenerDelegate(OnPermissionsChangedListener listener,
2635 Looper looper) {
2636 mListener = listener;
2637 mHandler = new Handler(looper, this);
2638 }
2639
2640 @Override
2641 public void onPermissionsChanged(int uid) {
2642 mHandler.obtainMessage(MSG_PERMISSIONS_CHANGED, uid, 0).sendToTarget();
2643 }
2644
2645 @Override
2646 public boolean handleMessage(Message msg) {
2647 switch (msg.what) {
2648 case MSG_PERMISSIONS_CHANGED: {
2649 final int uid = msg.arg1;
2650 mListener.onPermissionsChanged(uid);
2651 return true;
2652 }
2653 }
2654 return false;
2655 }
2656 }
Suprabh Shuklaaef25132017-01-23 18:09:03 -08002657
2658 @Override
2659 public boolean canRequestPackageInstalls() {
2660 try {
2661 return mPM.canRequestPackageInstalls(mContext.getPackageName(), mContext.getUserId());
2662 } catch (RemoteException e) {
2663 throw e.rethrowAsRuntimeException();
2664 }
2665 }
Chad Brubaker336ae5b2017-03-24 15:53:09 -07002666
2667 @Override
2668 public ComponentName getInstantAppResolverSettingsComponent() {
2669 try {
2670 return mPM.getInstantAppResolverSettingsComponent();
2671 } catch (RemoteException e) {
2672 throw e.rethrowAsRuntimeException();
2673 }
2674 }
Todd Kennedy801e6592017-04-12 14:10:12 -07002675
2676 @Override
2677 public ComponentName getInstantAppInstallerComponent() {
2678 try {
2679 return mPM.getInstantAppInstallerComponent();
2680 } catch (RemoteException e) {
2681 throw e.rethrowAsRuntimeException();
2682 }
2683 }
Chad Brubaker0d277a72017-04-12 16:56:53 -07002684
2685 @Override
2686 public String getInstantAppAndroidId(String packageName, UserHandle user) {
2687 try {
2688 return mPM.getInstantAppAndroidId(packageName, user.getIdentifier());
2689 } catch (RemoteException e) {
2690 throw e.rethrowAsRuntimeException();
2691 }
2692 }
Calin Juravle3d2af7f2017-04-19 19:56:21 -07002693
2694 private static class DexModuleRegisterResult {
2695 final String dexModulePath;
2696 final boolean success;
2697 final String message;
2698
2699 private DexModuleRegisterResult(String dexModulePath, boolean success, String message) {
2700 this.dexModulePath = dexModulePath;
2701 this.success = success;
2702 this.message = message;
2703 }
2704 }
2705
2706 private static class DexModuleRegisterCallbackDelegate
2707 extends android.content.pm.IDexModuleRegisterCallback.Stub
2708 implements Handler.Callback {
2709 private static final int MSG_DEX_MODULE_REGISTERED = 1;
2710 private final DexModuleRegisterCallback callback;
2711 private final Handler mHandler;
2712
2713 DexModuleRegisterCallbackDelegate(@NonNull DexModuleRegisterCallback callback) {
2714 this.callback = callback;
2715 mHandler = new Handler(Looper.getMainLooper(), this);
2716 }
2717
2718 @Override
2719 public void onDexModuleRegistered(@NonNull String dexModulePath, boolean success,
2720 @Nullable String message)throws RemoteException {
2721 mHandler.obtainMessage(MSG_DEX_MODULE_REGISTERED,
2722 new DexModuleRegisterResult(dexModulePath, success, message)).sendToTarget();
2723 }
2724
2725 @Override
2726 public boolean handleMessage(Message msg) {
2727 if (msg.what != MSG_DEX_MODULE_REGISTERED) {
2728 return false;
2729 }
2730 DexModuleRegisterResult result = (DexModuleRegisterResult)msg.obj;
2731 callback.onDexModuleRegistered(result.dexModulePath, result.success, result.message);
2732 return true;
2733 }
2734 }
2735
2736 @Override
2737 public void registerDexModule(@NonNull String dexModule,
2738 @Nullable DexModuleRegisterCallback callback) {
2739 // Check if this is a shared module by looking if the others can read it.
2740 boolean isSharedModule = false;
2741 try {
2742 StructStat stat = Os.stat(dexModule);
2743 if ((OsConstants.S_IROTH & stat.st_mode) != 0) {
2744 isSharedModule = true;
2745 }
2746 } catch (ErrnoException e) {
2747 callback.onDexModuleRegistered(dexModule, false,
2748 "Could not get stat the module file: " + e.getMessage());
2749 return;
2750 }
2751
2752 // Module path is ok.
2753 // Create the callback delegate to be passed to package manager service.
2754 DexModuleRegisterCallbackDelegate callbackDelegate = null;
2755 if (callback != null) {
2756 callbackDelegate = new DexModuleRegisterCallbackDelegate(callback);
2757 }
2758
2759 // Invoke the package manager service.
2760 try {
2761 mPM.registerDexModule(mContext.getPackageName(), dexModule,
2762 isSharedModule, callbackDelegate);
2763 } catch (RemoteException e) {
2764 throw e.rethrowAsRuntimeException();
2765 }
2766 }
Brad Fitzpatrick390dae12010-11-10 08:27:28 -08002767}