blob: 7cee286c445146ff70551acbe70fef94b2d9a456 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2008 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
Kenny Rootcf0b38c2011-03-22 14:17:59 -070017package com.android.server.pm;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080018
Calin Juravle3621be72018-01-18 15:17:29 -080019import android.annotation.AppIdInt;
Victor Hsieh5f761242018-01-20 10:30:12 -080020import android.annotation.NonNull;
Fyodor Kupolovb94c1652015-03-03 12:25:30 -080021import android.annotation.Nullable;
Calin Juravle3621be72018-01-18 15:17:29 -080022import android.annotation.UserIdInt;
Jeff Brownb880d882014-02-10 19:47:07 -080023import android.content.Context;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080024import android.content.pm.PackageStats;
Narayan Kamath29564cd2014-08-07 10:57:40 +010025import android.os.Build;
Jeff Sharkey9f2f2182016-12-21 09:18:33 -070026import android.os.IBinder;
27import android.os.IBinder.DeathRecipient;
Jeff Sharkey70b4d102016-12-05 11:19:28 -070028import android.os.IInstalld;
Jeff Sharkey9f2f2182016-12-21 09:18:33 -070029import android.os.RemoteException;
Jeff Sharkey70b4d102016-12-05 11:19:28 -070030import android.os.ServiceManager;
Felka Chang71e3efe2019-11-20 14:11:13 +080031import android.os.storage.CrateMetadata;
Jeff Sharkey9f2f2182016-12-21 09:18:33 -070032import android.text.format.DateUtils;
Joe Onorato8a9b2202010-02-26 18:56:32 -080033import android.util.Slog;
Jeff Sharkey790a4ec2015-04-09 13:18:44 -070034
Jeff Sharkey9f2f2182016-12-21 09:18:33 -070035import com.android.internal.os.BackgroundThread;
Narayan Kamath29564cd2014-08-07 10:57:40 +010036import com.android.server.SystemService;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080037
Jeff Sharkeydd02e332018-06-27 14:41:57 -060038import dalvik.system.BlockGuard;
Jeff Sharkeyfdeeeea2016-01-11 17:34:24 -070039import dalvik.system.VMRuntime;
40
Victor Hsieh55f14992018-01-13 14:12:59 -080041import java.io.FileDescriptor;
42
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -070043public class Installer extends SystemService {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080044 private static final String TAG = "Installer";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080045
Todd Kennedyfa54ab72015-09-25 07:46:12 -070046 /* ***************************************************************************
47 * IMPORTANT: These values are passed to native code. Keep them in sync with
Mathew Inwood3c8277d2018-03-09 14:06:08 +000048 * frameworks/native/cmds/installd/installd_constants.h
Todd Kennedyfa54ab72015-09-25 07:46:12 -070049 * **************************************************************************/
50 /** Application should be visible to everyone */
Andreas Gampebdd30d82016-03-20 11:32:11 -070051 public static final int DEXOPT_PUBLIC = 1 << 1;
Todd Kennedyfa54ab72015-09-25 07:46:12 -070052 /** Application wants to allow debugging of its code */
Nicolas Geoffray56123ba2017-05-05 14:30:02 +010053 public static final int DEXOPT_DEBUGGABLE = 1 << 2;
Todd Kennedyfa54ab72015-09-25 07:46:12 -070054 /** The system boot has finished */
Nicolas Geoffray56123ba2017-05-05 14:30:02 +010055 public static final int DEXOPT_BOOTCOMPLETE = 1 << 3;
Andreas Gampebdd30d82016-03-20 11:32:11 -070056 /** Hint that the dexopt type is profile-guided. */
Nicolas Geoffray56123ba2017-05-05 14:30:02 +010057 public static final int DEXOPT_PROFILE_GUIDED = 1 << 4;
Calin Juravlec22c30e2017-01-16 19:18:48 -080058 /** The compilation is for a secondary dex file. */
Nicolas Geoffray56123ba2017-05-05 14:30:02 +010059 public static final int DEXOPT_SECONDARY_DEX = 1 << 5;
Calin Juravlec22c30e2017-01-16 19:18:48 -080060 /** Ignore the result of dexoptNeeded and force compilation. */
Nicolas Geoffray56123ba2017-05-05 14:30:02 +010061 public static final int DEXOPT_FORCE = 1 << 6;
Calin Juravlec22c30e2017-01-16 19:18:48 -080062 /** Indicates that the dex file passed to dexopt in on CE storage. */
Nicolas Geoffray56123ba2017-05-05 14:30:02 +010063 public static final int DEXOPT_STORAGE_CE = 1 << 7;
Calin Juravlec22c30e2017-01-16 19:18:48 -080064 /** Indicates that the dex file passed to dexopt in on DE storage. */
Nicolas Geoffray56123ba2017-05-05 14:30:02 +010065 public static final int DEXOPT_STORAGE_DE = 1 << 8;
David Sehr2118ec42017-10-25 14:28:29 -070066 /** Indicates that dexopt is invoked from the background service. */
67 public static final int DEXOPT_IDLE_BACKGROUND_JOB = 1 << 9;
David Brazdilf7e31c02018-02-13 17:04:26 +000068 /** Indicates that dexopt should restrict access to private APIs. */
69 public static final int DEXOPT_ENABLE_HIDDEN_API_CHECKS = 1 << 10;
Mathieu Chartierf890c3e2018-03-06 18:28:22 -080070 /** Indicates that dexopt should convert to CompactDex. */
71 public static final int DEXOPT_GENERATE_COMPACT_DEX = 1 << 11;
Mathieu Chartiera9c34332018-03-12 17:11:07 -070072 /** Indicates that dexopt should generate an app image */
73 public static final int DEXOPT_GENERATE_APP_IMAGE = 1 << 12;
Patrick Baumann90d4e0d2020-04-14 16:57:30 -070074 /** Indicates that dexopt may be run with different performance / priority tuned for restore */
75 public static final int DEXOPT_FOR_RESTORE = 1 << 13; // TODO(b/135202722): remove
Todd Kennedyfa54ab72015-09-25 07:46:12 -070076
Jeff Sharkey4e7a7652018-08-24 17:25:42 -060077 public static final int FLAG_STORAGE_DE = IInstalld.FLAG_STORAGE_DE;
78 public static final int FLAG_STORAGE_CE = IInstalld.FLAG_STORAGE_CE;
Jeff Sharkey3f704632019-05-14 14:55:13 -060079 public static final int FLAG_STORAGE_EXTERNAL = IInstalld.FLAG_STORAGE_EXTERNAL;
Jeff Sharkey4e7a7652018-08-24 17:25:42 -060080
81 public static final int FLAG_CLEAR_CACHE_ONLY = IInstalld.FLAG_CLEAR_CACHE_ONLY;
82 public static final int FLAG_CLEAR_CODE_CACHE_ONLY = IInstalld.FLAG_CLEAR_CODE_CACHE_ONLY;
83
84 public static final int FLAG_FREE_CACHE_V2 = IInstalld.FLAG_FREE_CACHE_V2;
85 public static final int FLAG_FREE_CACHE_V2_DEFY_QUOTA = IInstalld.FLAG_FREE_CACHE_V2_DEFY_QUOTA;
86 public static final int FLAG_FREE_CACHE_NOOP = IInstalld.FLAG_FREE_CACHE_NOOP;
87
88 public static final int FLAG_USE_QUOTA = IInstalld.FLAG_USE_QUOTA;
89 public static final int FLAG_FORCE = IInstalld.FLAG_FORCE;
Jeff Sharkeyfdeeeea2016-01-11 17:34:24 -070090
Calin Juravle86b6bbd2019-06-17 17:13:55 -070091 public static final int FLAG_CLEAR_APP_DATA_KEEP_ART_PROFILES =
92 IInstalld.FLAG_CLEAR_APP_DATA_KEEP_ART_PROFILES;
93
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -070094 private final boolean mIsolated;
95
Jeff Sharkey740f5232016-12-09 14:31:26 -070096 private volatile IInstalld mInstalld;
Jeff Sharkeyc8ddc2d2016-12-05 23:14:41 -070097 private volatile Object mWarnIfHeld;
98
Jeff Brownb880d882014-02-10 19:47:07 -080099 public Installer(Context context) {
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -0700100 this(context, false);
Jeff Brownb880d882014-02-10 19:47:07 -0800101 }
102
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -0700103 /**
104 * @param isolated indicates if this object should <em>not</em> connect to
105 * the real {@code installd}. All remote calls will be ignored
106 * unless you extend this class and intercept them.
107 */
108 public Installer(Context context, boolean isolated) {
Andreas Gamped15300c2016-06-23 20:27:12 -0700109 super(context);
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -0700110 mIsolated = isolated;
Andreas Gamped15300c2016-06-23 20:27:12 -0700111 }
112
Jeff Sharkey8948c012015-11-03 12:33:54 -0800113 /**
114 * Yell loudly if someone tries making future calls while holding a lock on
115 * the given object.
116 */
117 public void setWarnIfHeld(Object warnIfHeld) {
Jeff Sharkeyc8ddc2d2016-12-05 23:14:41 -0700118 mWarnIfHeld = warnIfHeld;
Jeff Sharkey8948c012015-11-03 12:33:54 -0800119 }
120
Jeff Brown6f357d32014-01-15 20:40:55 -0800121 @Override
122 public void onStart() {
Jeff Sharkey740f5232016-12-09 14:31:26 -0700123 if (mIsolated) {
124 mInstalld = null;
125 } else {
Jeff Sharkey9f2f2182016-12-21 09:18:33 -0700126 connect();
127 }
128 }
129
130 private void connect() {
131 IBinder binder = ServiceManager.getService("installd");
132 if (binder != null) {
133 try {
134 binder.linkToDeath(new DeathRecipient() {
135 @Override
136 public void binderDied() {
137 Slog.w(TAG, "installd died; reconnecting");
138 connect();
139 }
140 }, 0);
141 } catch (RemoteException e) {
142 binder = null;
143 }
144 }
145
146 if (binder != null) {
147 mInstalld = IInstalld.Stub.asInterface(binder);
Jeff Sharkey82add8a2017-03-11 19:44:16 -0700148 try {
149 invalidateMounts();
150 } catch (InstallerException ignored) {
151 }
Jeff Sharkey9f2f2182016-12-21 09:18:33 -0700152 } else {
153 Slog.w(TAG, "installd not found; trying again");
154 BackgroundThread.getHandler().postDelayed(() -> {
155 connect();
156 }, DateUtils.SECOND_IN_MILLIS);
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -0700157 }
Jeff Brown6f357d32014-01-15 20:40:55 -0800158 }
159
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -0700160 /**
161 * Do several pre-flight checks before making a remote call.
162 *
163 * @return if the remote call should continue.
164 */
165 private boolean checkBeforeRemote() {
Jeff Sharkeyc8ddc2d2016-12-05 23:14:41 -0700166 if (mWarnIfHeld != null && Thread.holdsLock(mWarnIfHeld)) {
167 Slog.wtf(TAG, "Calling thread " + Thread.currentThread().getName() + " is holding 0x"
168 + Integer.toHexString(System.identityHashCode(mWarnIfHeld)), new Throwable());
169 }
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -0700170 if (mIsolated) {
171 Slog.i(TAG, "Ignoring request because this installer is isolated");
172 return false;
173 } else {
174 return true;
175 }
Jeff Sharkeyc8ddc2d2016-12-05 23:14:41 -0700176 }
177
Jeff Sharkey1c6f7232016-12-19 16:39:02 -0700178 public long createAppData(String uuid, String packageName, int userId, int flags, int appId,
Jeff Sharkeyc8ddc2d2016-12-05 23:14:41 -0700179 String seInfo, int targetSdkVersion) throws InstallerException {
Jeff Sharkey1c6f7232016-12-19 16:39:02 -0700180 if (!checkBeforeRemote()) return -1;
Jeff Sharkeyc8ddc2d2016-12-05 23:14:41 -0700181 try {
Jeff Sharkey1c6f7232016-12-19 16:39:02 -0700182 return mInstalld.createAppData(uuid, packageName, userId, flags, appId, seInfo,
Jeff Sharkey70b4d102016-12-05 11:19:28 -0700183 targetSdkVersion);
Jeff Sharkey447a3ac2016-12-12 10:15:37 -0700184 } catch (Exception e) {
Jeff Sharkey740f5232016-12-09 14:31:26 -0700185 throw InstallerException.from(e);
Jeff Sharkey70b4d102016-12-05 11:19:28 -0700186 }
Jeff Sharkey790a4ec2015-04-09 13:18:44 -0700187 }
188
Jeff Sharkey019ac852016-12-05 23:39:46 -0700189 public void restoreconAppData(String uuid, String packageName, int userId, int flags, int appId,
190 String seInfo) throws InstallerException {
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -0700191 if (!checkBeforeRemote()) return;
Jeff Sharkey019ac852016-12-05 23:39:46 -0700192 try {
193 mInstalld.restoreconAppData(uuid, packageName, userId, flags, appId, seInfo);
Jeff Sharkey447a3ac2016-12-12 10:15:37 -0700194 } catch (Exception e) {
Jeff Sharkey740f5232016-12-09 14:31:26 -0700195 throw InstallerException.from(e);
Jeff Sharkey019ac852016-12-05 23:39:46 -0700196 }
Jeff Sharkey790a4ec2015-04-09 13:18:44 -0700197 }
198
Jeff Sharkey019ac852016-12-05 23:39:46 -0700199 public void migrateAppData(String uuid, String packageName, int userId, int flags)
Jeff Sharkeye4697132016-02-06 19:46:15 -0700200 throws InstallerException {
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -0700201 if (!checkBeforeRemote()) return;
Jeff Sharkey019ac852016-12-05 23:39:46 -0700202 try {
203 mInstalld.migrateAppData(uuid, packageName, userId, flags);
Jeff Sharkey447a3ac2016-12-12 10:15:37 -0700204 } catch (Exception e) {
Jeff Sharkey740f5232016-12-09 14:31:26 -0700205 throw InstallerException.from(e);
Jeff Sharkey019ac852016-12-05 23:39:46 -0700206 }
Jeff Sharkeye4697132016-02-06 19:46:15 -0700207 }
208
Jeff Sharkey019ac852016-12-05 23:39:46 -0700209 public void clearAppData(String uuid, String packageName, int userId, int flags,
210 long ceDataInode) throws InstallerException {
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -0700211 if (!checkBeforeRemote()) return;
Jeff Sharkey019ac852016-12-05 23:39:46 -0700212 try {
213 mInstalld.clearAppData(uuid, packageName, userId, flags, ceDataInode);
Jeff Sharkey447a3ac2016-12-12 10:15:37 -0700214 } catch (Exception e) {
Jeff Sharkey740f5232016-12-09 14:31:26 -0700215 throw InstallerException.from(e);
Jeff Sharkey019ac852016-12-05 23:39:46 -0700216 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800217 }
218
Jeff Sharkey019ac852016-12-05 23:39:46 -0700219 public void destroyAppData(String uuid, String packageName, int userId, int flags,
220 long ceDataInode) throws InstallerException {
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -0700221 if (!checkBeforeRemote()) return;
Jeff Sharkey019ac852016-12-05 23:39:46 -0700222 try {
223 mInstalld.destroyAppData(uuid, packageName, userId, flags, ceDataInode);
Jeff Sharkey447a3ac2016-12-12 10:15:37 -0700224 } catch (Exception e) {
Jeff Sharkey740f5232016-12-09 14:31:26 -0700225 throw InstallerException.from(e);
Jeff Sharkey019ac852016-12-05 23:39:46 -0700226 }
Dave Allison0efbd9a2014-01-30 14:19:51 -0800227 }
228
Jeff Sharkey15662332017-04-03 16:41:29 -0600229 public void fixupAppData(String uuid, int flags) throws InstallerException {
230 if (!checkBeforeRemote()) return;
231 try {
232 mInstalld.fixupAppData(uuid, flags);
233 } catch (Exception e) {
234 throw InstallerException.from(e);
235 }
236 }
237
Jeff Sharkeyc8ddc2d2016-12-05 23:14:41 -0700238 public void moveCompleteApp(String fromUuid, String toUuid, String packageName,
Songchun Fan7c0f3292020-02-13 09:38:58 -0800239 int appId, String seInfo, int targetSdkVersion,
Songchun Fan480b78b2020-02-05 12:07:28 -0800240 String fromCodePath) throws InstallerException {
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -0700241 if (!checkBeforeRemote()) return;
Jeff Sharkeyc8ddc2d2016-12-05 23:14:41 -0700242 try {
Songchun Fan7c0f3292020-02-13 09:38:58 -0800243 mInstalld.moveCompleteApp(fromUuid, toUuid, packageName, appId, seInfo,
Songchun Fan480b78b2020-02-05 12:07:28 -0800244 targetSdkVersion, fromCodePath);
Jeff Sharkey447a3ac2016-12-12 10:15:37 -0700245 } catch (Exception e) {
Jeff Sharkey740f5232016-12-09 14:31:26 -0700246 throw InstallerException.from(e);
Jeff Sharkeyc8ddc2d2016-12-05 23:14:41 -0700247 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800248 }
249
Jeff Sharkey82ca9012017-01-08 17:06:58 -0700250 public void getAppSize(String uuid, String[] packageNames, int userId, int flags, int appId,
251 long[] ceDataInodes, String[] codePaths, PackageStats stats)
Jeff Sharkey5eb3eb52016-12-13 08:44:51 -0700252 throws InstallerException {
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -0700253 if (!checkBeforeRemote()) return;
Jeff Sharkeydd02e332018-06-27 14:41:57 -0600254 if (codePaths != null) {
255 for (String codePath : codePaths) {
256 BlockGuard.getVmPolicy().onPathAccess(codePath);
257 }
258 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800259 try {
Jeff Sharkey82ca9012017-01-08 17:06:58 -0700260 final long[] res = mInstalld.getAppSize(uuid, packageNames, userId, flags,
261 appId, ceDataInodes, codePaths);
Jeff Sharkey740f5232016-12-09 14:31:26 -0700262 stats.codeSize += res[0];
263 stats.dataSize += res[1];
264 stats.cacheSize += res[2];
Jeff Sharkey82ca9012017-01-08 17:06:58 -0700265 stats.externalCodeSize += res[3];
266 stats.externalDataSize += res[4];
267 stats.externalCacheSize += res[5];
268 } catch (Exception e) {
269 throw InstallerException.from(e);
270 }
271 }
272
273 public void getUserSize(String uuid, int userId, int flags, int[] appIds, PackageStats stats)
274 throws InstallerException {
275 if (!checkBeforeRemote()) return;
276 try {
277 final long[] res = mInstalld.getUserSize(uuid, userId, flags, appIds);
278 stats.codeSize += res[0];
279 stats.dataSize += res[1];
280 stats.cacheSize += res[2];
281 stats.externalCodeSize += res[3];
282 stats.externalDataSize += res[4];
283 stats.externalCacheSize += res[5];
284 } catch (Exception e) {
285 throw InstallerException.from(e);
286 }
287 }
288
Jeff Sharkey00347882017-04-17 16:44:12 -0600289 public long[] getExternalSize(String uuid, int userId, int flags, int[] appIds)
290 throws InstallerException {
Jeff Sharkeyc8b29ac2017-07-06 11:29:06 -0600291 if (!checkBeforeRemote()) return new long[6];
Jeff Sharkey82ca9012017-01-08 17:06:58 -0700292 try {
Jeff Sharkey00347882017-04-17 16:44:12 -0600293 return mInstalld.getExternalSize(uuid, userId, flags, appIds);
Jeff Sharkey447a3ac2016-12-12 10:15:37 -0700294 } catch (Exception e) {
Jeff Sharkey740f5232016-12-09 14:31:26 -0700295 throw InstallerException.from(e);
Jeff Sharkey42884192016-04-09 16:12:01 -0600296 }
297 }
298
Felka Chang71e3efe2019-11-20 14:11:13 +0800299 /**
300 * To get all of the CrateMetadata of the crates for the specified user app by the installd.
301 *
302 * @param uuid the UUID
303 * @param packageNames the application package names
304 * @param userId the user id
305 * @return the array of CrateMetadata
306 */
307 @Nullable
308 public CrateMetadata[] getAppCrates(@NonNull String uuid, @NonNull String[] packageNames,
309 @UserIdInt int userId) throws InstallerException {
310 if (!checkBeforeRemote()) return null;
311 try {
312 return mInstalld.getAppCrates(uuid, packageNames, userId);
313 } catch (Exception e) {
314 throw InstallerException.from(e);
315 }
316 }
317
318 /**
319 * To retrieve all of the CrateMetadata of the crate for the specified user app by the installd.
320 *
321 * @param uuid the UUID
322 * @param userId the user id
323 * @return the array of CrateMetadata
324 */
325 @Nullable
326 public CrateMetadata[] getUserCrates(String uuid, @UserIdInt int userId)
327 throws InstallerException {
328 if (!checkBeforeRemote()) return null;
329 try {
330 return mInstalld.getUserCrates(uuid, userId);
331 } catch (Exception e) {
332 throw InstallerException.from(e);
333 }
334 }
335
Jeff Sharkey36ba0222017-01-18 12:11:31 -0700336 public void setAppQuota(String uuid, int userId, int appId, long cacheQuota)
337 throws InstallerException {
338 if (!checkBeforeRemote()) return;
339 try {
340 mInstalld.setAppQuota(uuid, userId, appId, cacheQuota);
341 } catch (Exception e) {
342 throw InstallerException.from(e);
343 }
344 }
345
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -0700346 public void dexopt(String apkPath, int uid, @Nullable String pkgName, String instructionSet,
Calin Juravledb4a79a2015-12-23 18:55:08 +0200347 int dexoptNeeded, @Nullable String outputPath, int dexFlags,
Calin Juravle811a75a2017-04-05 22:49:38 -0700348 String compilerFilter, @Nullable String volumeUuid, @Nullable String sharedLibraries,
Calin Juravle6ae39fc2018-01-19 20:32:47 -0800349 @Nullable String seInfo, boolean downgrade, int targetSdkVersion,
Calin Juravle4bc8f4d2018-02-12 12:00:44 -0800350 @Nullable String profileName, @Nullable String dexMetadataPath,
351 @Nullable String compilationReason) throws InstallerException {
Jeff Sharkeyfdeeeea2016-01-11 17:34:24 -0700352 assertValidInstructionSet(instructionSet);
Jeff Sharkeydd02e332018-06-27 14:41:57 -0600353 BlockGuard.getVmPolicy().onPathAccess(apkPath);
354 BlockGuard.getVmPolicy().onPathAccess(outputPath);
355 BlockGuard.getVmPolicy().onPathAccess(dexMetadataPath);
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -0700356 if (!checkBeforeRemote()) return;
Jeff Sharkey740f5232016-12-09 14:31:26 -0700357 try {
358 mInstalld.dexopt(apkPath, uid, pkgName, instructionSet, dexoptNeeded, outputPath,
David Brazdil3d44ed02018-01-16 20:01:47 +0000359 dexFlags, compilerFilter, volumeUuid, sharedLibraries, seInfo, downgrade,
Calin Juravle4bc8f4d2018-02-12 12:00:44 -0800360 targetSdkVersion, profileName, dexMetadataPath, compilationReason);
Jeff Sharkey447a3ac2016-12-12 10:15:37 -0700361 } catch (Exception e) {
Jeff Sharkey740f5232016-12-09 14:31:26 -0700362 throw InstallerException.from(e);
363 }
Andreas Gampebdd30d82016-03-20 11:32:11 -0700364 }
365
Calin Juravle6ae39fc2018-01-19 20:32:47 -0800366 public boolean mergeProfiles(int uid, String packageName, String profileName)
David Sehra8777082016-05-24 15:25:23 -0700367 throws InstallerException {
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -0700368 if (!checkBeforeRemote()) return false;
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700369 try {
Calin Juravle6ae39fc2018-01-19 20:32:47 -0800370 return mInstalld.mergeProfiles(uid, packageName, profileName);
Jeff Sharkey447a3ac2016-12-12 10:15:37 -0700371 } catch (Exception e) {
Jeff Sharkey740f5232016-12-09 14:31:26 -0700372 throw InstallerException.from(e);
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700373 }
David Sehra8777082016-05-24 15:25:23 -0700374 }
375
Calin Juravle6ae39fc2018-01-19 20:32:47 -0800376 public boolean dumpProfiles(int uid, String packageName, String profileName, String codePath)
Mathieu Chartier235845d2017-05-10 15:09:19 -0700377 throws InstallerException {
378 if (!checkBeforeRemote()) return false;
Jeff Sharkeydd02e332018-06-27 14:41:57 -0600379 BlockGuard.getVmPolicy().onPathAccess(codePath);
Mathieu Chartier235845d2017-05-10 15:09:19 -0700380 try {
Calin Juravle6ae39fc2018-01-19 20:32:47 -0800381 return mInstalld.dumpProfiles(uid, packageName, profileName, codePath);
382 } catch (Exception e) {
383 throw InstallerException.from(e);
384 }
385 }
386
387 public boolean copySystemProfile(String systemProfile, int uid, String packageName,
388 String profileName) throws InstallerException {
389 if (!checkBeforeRemote()) return false;
390 try {
391 return mInstalld.copySystemProfile(systemProfile, uid, packageName, profileName);
Mathieu Chartier235845d2017-05-10 15:09:19 -0700392 } catch (Exception e) {
393 throw InstallerException.from(e);
394 }
395 }
396
Jeff Sharkeyfdeeeea2016-01-11 17:34:24 -0700397 public void rmdex(String codePath, String instructionSet) throws InstallerException {
398 assertValidInstructionSet(instructionSet);
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -0700399 if (!checkBeforeRemote()) return;
Jeff Sharkeydd02e332018-06-27 14:41:57 -0600400 BlockGuard.getVmPolicy().onPathAccess(codePath);
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700401 try {
402 mInstalld.rmdex(codePath, instructionSet);
Jeff Sharkey447a3ac2016-12-12 10:15:37 -0700403 } catch (Exception e) {
Jeff Sharkey740f5232016-12-09 14:31:26 -0700404 throw InstallerException.from(e);
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700405 }
Jeff Sharkeyfdeeeea2016-01-11 17:34:24 -0700406 }
407
408 public void rmPackageDir(String packageDir) throws InstallerException {
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -0700409 if (!checkBeforeRemote()) return;
Jeff Sharkeydd02e332018-06-27 14:41:57 -0600410 BlockGuard.getVmPolicy().onPathAccess(packageDir);
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700411 try {
412 mInstalld.rmPackageDir(packageDir);
Jeff Sharkey447a3ac2016-12-12 10:15:37 -0700413 } catch (Exception e) {
Jeff Sharkey740f5232016-12-09 14:31:26 -0700414 throw InstallerException.from(e);
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700415 }
Jeff Sharkeyfdeeeea2016-01-11 17:34:24 -0700416 }
417
Calin Juravle6ae39fc2018-01-19 20:32:47 -0800418 public void clearAppProfiles(String packageName, String profileName) throws InstallerException {
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -0700419 if (!checkBeforeRemote()) return;
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700420 try {
Calin Juravle6ae39fc2018-01-19 20:32:47 -0800421 mInstalld.clearAppProfiles(packageName, profileName);
Jeff Sharkey447a3ac2016-12-12 10:15:37 -0700422 } catch (Exception e) {
Jeff Sharkey740f5232016-12-09 14:31:26 -0700423 throw InstallerException.from(e);
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700424 }
Calin Juravled6d27e32016-03-23 13:59:18 +0000425 }
426
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700427 public void destroyAppProfiles(String packageName) throws InstallerException {
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -0700428 if (!checkBeforeRemote()) return;
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700429 try {
430 mInstalld.destroyAppProfiles(packageName);
Jeff Sharkey447a3ac2016-12-12 10:15:37 -0700431 } catch (Exception e) {
Jeff Sharkey740f5232016-12-09 14:31:26 -0700432 throw InstallerException.from(e);
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700433 }
David Brazdil9aa6db02016-03-08 12:57:12 +0000434 }
435
Jeff Sharkeyfcf1e552016-04-14 20:44:58 -0600436 public void createUserData(String uuid, int userId, int userSerial, int flags)
437 throws InstallerException {
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -0700438 if (!checkBeforeRemote()) return;
Jeff Sharkey019ac852016-12-05 23:39:46 -0700439 try {
440 mInstalld.createUserData(uuid, userId, userSerial, flags);
Jeff Sharkey447a3ac2016-12-12 10:15:37 -0700441 } catch (Exception e) {
Jeff Sharkey740f5232016-12-09 14:31:26 -0700442 throw InstallerException.from(e);
Jeff Sharkey019ac852016-12-05 23:39:46 -0700443 }
Jeff Sharkeyfdeeeea2016-01-11 17:34:24 -0700444 }
445
Jeff Sharkeyfcf1e552016-04-14 20:44:58 -0600446 public void destroyUserData(String uuid, int userId, int flags) throws InstallerException {
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -0700447 if (!checkBeforeRemote()) return;
Jeff Sharkey019ac852016-12-05 23:39:46 -0700448 try {
449 mInstalld.destroyUserData(uuid, userId, flags);
Jeff Sharkey447a3ac2016-12-12 10:15:37 -0700450 } catch (Exception e) {
Jeff Sharkey740f5232016-12-09 14:31:26 -0700451 throw InstallerException.from(e);
Jeff Sharkey019ac852016-12-05 23:39:46 -0700452 }
Jeff Sharkeyfdeeeea2016-01-11 17:34:24 -0700453 }
454
Jeff Sharkeyddff8072017-05-26 13:10:46 -0600455 public void freeCache(String uuid, long targetFreeBytes, long cacheReservedBytes, int flags)
456 throws InstallerException {
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -0700457 if (!checkBeforeRemote()) return;
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700458 try {
Jeff Sharkeyddff8072017-05-26 13:10:46 -0600459 mInstalld.freeCache(uuid, targetFreeBytes, cacheReservedBytes, flags);
Jeff Sharkey447a3ac2016-12-12 10:15:37 -0700460 } catch (Exception e) {
Jeff Sharkey740f5232016-12-09 14:31:26 -0700461 throw InstallerException.from(e);
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700462 }
Jeff Sharkeyfdeeeea2016-01-11 17:34:24 -0700463 }
464
Kenny Rootddbe50d2012-09-06 13:18:37 -0700465 /**
Jeff Sharkeyfdeeeea2016-01-11 17:34:24 -0700466 * Links the 32 bit native library directory in an application's data
467 * directory to the real location for backward compatibility. Note that no
468 * such symlink is created for 64 bit shared libraries.
Kenny Rootddbe50d2012-09-06 13:18:37 -0700469 */
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700470 public void linkNativeLibraryDirectory(String uuid, String packageName, String nativeLibPath32,
Jeff Sharkeyfdeeeea2016-01-11 17:34:24 -0700471 int userId) throws InstallerException {
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -0700472 if (!checkBeforeRemote()) return;
Jeff Sharkeydd02e332018-06-27 14:41:57 -0600473 BlockGuard.getVmPolicy().onPathAccess(nativeLibPath32);
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700474 try {
475 mInstalld.linkNativeLibraryDirectory(uuid, packageName, nativeLibPath32, userId);
Jeff Sharkey447a3ac2016-12-12 10:15:37 -0700476 } catch (Exception e) {
Jeff Sharkey740f5232016-12-09 14:31:26 -0700477 throw InstallerException.from(e);
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700478 }
Kenny Root6a6b0072010-10-07 16:46:10 -0700479 }
Robert Craig43853432014-03-04 11:57:23 -0500480
Jeff Sharkeyfdeeeea2016-01-11 17:34:24 -0700481 public void createOatDir(String oatDir, String dexInstructionSet)
482 throws InstallerException {
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -0700483 if (!checkBeforeRemote()) return;
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700484 try {
485 mInstalld.createOatDir(oatDir, dexInstructionSet);
Jeff Sharkey447a3ac2016-12-12 10:15:37 -0700486 } catch (Exception e) {
Jeff Sharkey740f5232016-12-09 14:31:26 -0700487 throw InstallerException.from(e);
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700488 }
Jeff Sharkey790a4ec2015-04-09 13:18:44 -0700489 }
490
Jeff Sharkeyfdeeeea2016-01-11 17:34:24 -0700491 public void linkFile(String relativePath, String fromBase, String toBase)
492 throws InstallerException {
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -0700493 if (!checkBeforeRemote()) return;
Jeff Sharkeydd02e332018-06-27 14:41:57 -0600494 BlockGuard.getVmPolicy().onPathAccess(fromBase);
495 BlockGuard.getVmPolicy().onPathAccess(toBase);
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700496 try {
497 mInstalld.linkFile(relativePath, fromBase, toBase);
Jeff Sharkey447a3ac2016-12-12 10:15:37 -0700498 } catch (Exception e) {
Jeff Sharkey740f5232016-12-09 14:31:26 -0700499 throw InstallerException.from(e);
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700500 }
Robert Craig43853432014-03-04 11:57:23 -0500501 }
Narayan Kamath6c4b9de2014-08-08 12:44:12 +0100502
Andreas Gampeabcbe2f2016-02-26 11:25:36 -0800503 public void moveAb(String apkPath, String instructionSet, String outputPath)
504 throws InstallerException {
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -0700505 if (!checkBeforeRemote()) return;
Jeff Sharkeydd02e332018-06-27 14:41:57 -0600506 BlockGuard.getVmPolicy().onPathAccess(apkPath);
507 BlockGuard.getVmPolicy().onPathAccess(outputPath);
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700508 try {
509 mInstalld.moveAb(apkPath, instructionSet, outputPath);
Jeff Sharkey447a3ac2016-12-12 10:15:37 -0700510 } catch (Exception e) {
Jeff Sharkey740f5232016-12-09 14:31:26 -0700511 throw InstallerException.from(e);
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700512 }
Andreas Gampeabcbe2f2016-02-26 11:25:36 -0800513 }
514
Andreas Gampe33c592d2016-09-09 17:08:53 -0700515 public void deleteOdex(String apkPath, String instructionSet, String outputPath)
516 throws InstallerException {
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -0700517 if (!checkBeforeRemote()) return;
Jeff Sharkeydd02e332018-06-27 14:41:57 -0600518 BlockGuard.getVmPolicy().onPathAccess(apkPath);
519 BlockGuard.getVmPolicy().onPathAccess(outputPath);
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700520 try {
521 mInstalld.deleteOdex(apkPath, instructionSet, outputPath);
Jeff Sharkey447a3ac2016-12-12 10:15:37 -0700522 } catch (Exception e) {
Jeff Sharkey740f5232016-12-09 14:31:26 -0700523 throw InstallerException.from(e);
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700524 }
Andreas Gampe33c592d2016-09-09 17:08:53 -0700525 }
526
Victor Hsiehcccad192018-03-19 15:57:02 -0700527 public void installApkVerity(String filePath, FileDescriptor verityInput, int contentSize)
Victor Hsieh55f14992018-01-13 14:12:59 -0800528 throws InstallerException {
529 if (!checkBeforeRemote()) return;
Jeff Sharkeydd02e332018-06-27 14:41:57 -0600530 BlockGuard.getVmPolicy().onPathAccess(filePath);
Victor Hsieh55f14992018-01-13 14:12:59 -0800531 try {
Victor Hsiehcccad192018-03-19 15:57:02 -0700532 mInstalld.installApkVerity(filePath, verityInput, contentSize);
Victor Hsieh55f14992018-01-13 14:12:59 -0800533 } catch (Exception e) {
534 throw InstallerException.from(e);
535 }
536 }
537
Victor Hsieh5f761242018-01-20 10:30:12 -0800538 public void assertFsverityRootHashMatches(String filePath, @NonNull byte[] expectedHash)
539 throws InstallerException {
540 if (!checkBeforeRemote()) return;
Jeff Sharkeydd02e332018-06-27 14:41:57 -0600541 BlockGuard.getVmPolicy().onPathAccess(filePath);
Victor Hsieh5f761242018-01-20 10:30:12 -0800542 try {
543 mInstalld.assertFsverityRootHashMatches(filePath, expectedHash);
544 } catch (Exception e) {
545 throw InstallerException.from(e);
546 }
547 }
548
Calin Juravle1aa5f882017-01-25 01:05:50 -0800549 public boolean reconcileSecondaryDexFile(String apkPath, String packageName, int uid,
550 String[] isas, @Nullable String volumeUuid, int flags) throws InstallerException {
551 for (int i = 0; i < isas.length; i++) {
552 assertValidInstructionSet(isas[i]);
553 }
554 if (!checkBeforeRemote()) return false;
Jeff Sharkeydd02e332018-06-27 14:41:57 -0600555 BlockGuard.getVmPolicy().onPathAccess(apkPath);
Calin Juravle1aa5f882017-01-25 01:05:50 -0800556 try {
557 return mInstalld.reconcileSecondaryDexFile(apkPath, packageName, uid, isas,
558 volumeUuid, flags);
559 } catch (Exception e) {
560 throw InstallerException.from(e);
561 }
562 }
563
Alan Stokesa0023602017-10-16 12:31:44 +0100564 public byte[] hashSecondaryDexFile(String dexPath, String packageName, int uid,
565 @Nullable String volumeUuid, int flags) throws InstallerException {
566 if (!checkBeforeRemote()) return new byte[0];
Jeff Sharkeydd02e332018-06-27 14:41:57 -0600567 BlockGuard.getVmPolicy().onPathAccess(dexPath);
Alan Stokesa0023602017-10-16 12:31:44 +0100568 try {
569 return mInstalld.hashSecondaryDexFile(dexPath, packageName, uid, volumeUuid, flags);
570 } catch (Exception e) {
571 throw InstallerException.from(e);
572 }
573 }
574
Calin Juravlefcbb74a2018-01-21 21:39:18 -0800575 public boolean createProfileSnapshot(int appId, String packageName, String profileName,
576 String classpath) throws InstallerException {
Calin Juravlefd9f8ae2017-11-29 18:26:55 -0800577 if (!checkBeforeRemote()) return false;
578 try {
Calin Juravlefcbb74a2018-01-21 21:39:18 -0800579 return mInstalld.createProfileSnapshot(appId, packageName, profileName, classpath);
Calin Juravlefd9f8ae2017-11-29 18:26:55 -0800580 } catch (Exception e) {
581 throw InstallerException.from(e);
582 }
583 }
584
Calin Juravle6ae39fc2018-01-19 20:32:47 -0800585 public void destroyProfileSnapshot(String packageName, String profileName)
Calin Juravlefd9f8ae2017-11-29 18:26:55 -0800586 throws InstallerException {
587 if (!checkBeforeRemote()) return;
588 try {
Calin Juravle6ae39fc2018-01-19 20:32:47 -0800589 mInstalld.destroyProfileSnapshot(packageName, profileName);
Calin Juravlefd9f8ae2017-11-29 18:26:55 -0800590 } catch (Exception e) {
591 throw InstallerException.from(e);
592 }
593 }
594
Jeff Sharkey7d25faf2017-01-16 20:58:40 -0700595 public void invalidateMounts() throws InstallerException {
596 if (!checkBeforeRemote()) return;
597 try {
598 mInstalld.invalidateMounts();
599 } catch (Exception e) {
600 throw InstallerException.from(e);
601 }
602 }
603
Jeff Sharkeyd5d5e922017-02-21 10:51:23 -0700604 public boolean isQuotaSupported(String volumeUuid) throws InstallerException {
605 if (!checkBeforeRemote()) return false;
606 try {
607 return mInstalld.isQuotaSupported(volumeUuid);
608 } catch (Exception e) {
609 throw InstallerException.from(e);
610 }
611 }
612
Ricky Wai4482ab52019-12-10 19:08:18 +0000613 /**
614 * Bind mount private volume CE and DE mirror storage.
615 */
Ricky Wai88b369a2020-02-07 16:26:29 +0000616 public void tryMountDataMirror(String volumeUuid) throws InstallerException {
Ricky Wai4482ab52019-12-10 19:08:18 +0000617 if (!checkBeforeRemote()) return;
618 try {
Ricky Wai88b369a2020-02-07 16:26:29 +0000619 mInstalld.tryMountDataMirror(volumeUuid);
Ricky Wai4482ab52019-12-10 19:08:18 +0000620 } catch (Exception e) {
621 throw InstallerException.from(e);
622 }
623 }
624
625 /**
626 * Unmount private volume CE and DE mirror storage.
627 */
628 public void onPrivateVolumeRemoved(String volumeUuid) throws InstallerException {
629 if (!checkBeforeRemote()) return;
630 try {
631 mInstalld.onPrivateVolumeRemoved(volumeUuid);
632 } catch (Exception e) {
633 throw InstallerException.from(e);
634 }
635 }
636
Calin Juravle3621be72018-01-18 15:17:29 -0800637 public boolean prepareAppProfile(String pkg, @UserIdInt int userId, @AppIdInt int appId,
638 String profileName, String codePath, String dexMetadataPath) throws InstallerException {
639 if (!checkBeforeRemote()) return false;
Jeff Sharkeydd02e332018-06-27 14:41:57 -0600640 BlockGuard.getVmPolicy().onPathAccess(codePath);
641 BlockGuard.getVmPolicy().onPathAccess(dexMetadataPath);
Calin Juravle3621be72018-01-18 15:17:29 -0800642 try {
643 return mInstalld.prepareAppProfile(pkg, userId, appId, profileName, codePath,
644 dexMetadataPath);
645 } catch (Exception e) {
646 throw InstallerException.from(e);
647 }
648 }
649
Nikita Ioffe952aa7b2019-01-28 19:49:56 +0000650 /**
651 * Snapshots user data of the given package.
652 *
653 * @param pkg name of the package to snapshot user data for.
654 * @param userId id of the user whose data to snapshot.
Nikita Ioffe5dcd17972019-02-04 11:08:13 +0000655 * @param snapshotId id of this snapshot.
Nikita Ioffe952aa7b2019-01-28 19:49:56 +0000656 * @param storageFlags flags controlling which data (CE or DE) to snapshot.
657 *
658 * @return inode of the snapshot of users CE package data, or {@code 0} if a remote calls
659 * shouldn't be continued. See {@link #checkBeforeRemote}.
660 *
661 * @throws InstallerException if failed to snapshot user data.
662 */
Nikita Ioffe5dcd17972019-02-04 11:08:13 +0000663 public long snapshotAppData(String pkg, @UserIdInt int userId, int snapshotId, int storageFlags)
Narayan Kamath869f7062019-01-10 12:24:15 +0000664 throws InstallerException {
Nikita Ioffe952aa7b2019-01-28 19:49:56 +0000665 if (!checkBeforeRemote()) return 0;
Narayan Kamath869f7062019-01-10 12:24:15 +0000666
667 try {
Nikita Ioffe5dcd17972019-02-04 11:08:13 +0000668 return mInstalld.snapshotAppData(null, pkg, userId, snapshotId, storageFlags);
Narayan Kamath869f7062019-01-10 12:24:15 +0000669 } catch (Exception e) {
670 throw InstallerException.from(e);
671 }
672 }
673
Nikita Ioffe952aa7b2019-01-28 19:49:56 +0000674 /**
675 * Restores user data snapshot of the given package.
676 *
677 * @param pkg name of the package to restore user data for.
678 * @param appId id of the package to restore user data for.
Nikita Ioffe952aa7b2019-01-28 19:49:56 +0000679 * @param userId id of the user whose data to restore.
Nikita Ioffe5dcd17972019-02-04 11:08:13 +0000680 * @param snapshotId id of the snapshot to restore.
Nikita Ioffe952aa7b2019-01-28 19:49:56 +0000681 * @param storageFlags flags controlling which data (CE or DE) to restore.
682 *
683 * @return {@code true} if user data restore was successful, or {@code false} if a remote call
684 * shouldn't be continued. See {@link #checkBeforeRemote}.
685 *
686 * @throws InstallerException if failed to restore user data.
687 */
Nikita Ioffe5dcd17972019-02-04 11:08:13 +0000688 public boolean restoreAppDataSnapshot(String pkg, @AppIdInt int appId, String seInfo,
689 @UserIdInt int userId, int snapshotId, int storageFlags) throws InstallerException {
Narayan Kamath869f7062019-01-10 12:24:15 +0000690 if (!checkBeforeRemote()) return false;
691
692 try {
Nikita Ioffe5dcd17972019-02-04 11:08:13 +0000693 mInstalld.restoreAppDataSnapshot(null, pkg, appId, seInfo, userId, snapshotId,
Narayan Kamath869f7062019-01-10 12:24:15 +0000694 storageFlags);
695 return true;
696 } catch (Exception e) {
697 throw InstallerException.from(e);
698 }
699 }
700
Nikita Ioffe952aa7b2019-01-28 19:49:56 +0000701 /**
702 * Deletes user data snapshot of the given package.
703 *
704 * @param pkg name of the package to delete user data snapshot for.
705 * @param userId id of the user whose user data snapshot to delete.
706 * @param ceSnapshotInode inode of CE user data snapshot.
Nikita Ioffe5dcd17972019-02-04 11:08:13 +0000707 * @param snapshotId id of the snapshot to delete.
Nikita Ioffe952aa7b2019-01-28 19:49:56 +0000708 * @param storageFlags flags controlling which user data snapshot (CE or DE) to delete.
709 *
710 * @return {@code true} if user data snapshot was successfully deleted, or {@code false} if a
711 * remote call shouldn't be continued. See {@link #checkBeforeRemote}.
712 *
713 * @throws InstallerException if failed to delete user data snapshot.
714 */
715 public boolean destroyAppDataSnapshot(String pkg, @UserIdInt int userId, long ceSnapshotInode,
Nikita Ioffe5dcd17972019-02-04 11:08:13 +0000716 int snapshotId, int storageFlags) throws InstallerException {
Nikita Ioffe952aa7b2019-01-28 19:49:56 +0000717 if (!checkBeforeRemote()) return false;
718
719 try {
Nikita Ioffe5dcd17972019-02-04 11:08:13 +0000720 mInstalld.destroyAppDataSnapshot(null, pkg, userId, ceSnapshotInode, snapshotId,
721 storageFlags);
Nikita Ioffe952aa7b2019-01-28 19:49:56 +0000722 return true;
723 } catch (Exception e) {
724 throw InstallerException.from(e);
725 }
726 }
727
Narayan Kamath157dd1d2019-06-12 13:06:30 +0100728 /**
Oli Lan27bec232020-03-17 16:31:10 +0000729 * Deletes all snapshots of credential encrypted user data, where the snapshot id is not
730 * included in {@code retainSnapshotIds}.
731 *
732 * @param userId id of the user whose user data snapshots to delete.
733 * @param retainSnapshotIds ids of the snapshots that should not be deleted.
734 *
735 * @return {@code true} if the operation was successful, or {@code false} if a remote call
736 * shouldn't be continued. See {@link #checkBeforeRemote}.
737 *
738 * @throws InstallerException if failed to delete user data snapshot.
739 */
740 public boolean destroyCeSnapshotsNotSpecified(@UserIdInt int userId,
741 int[] retainSnapshotIds) throws InstallerException {
742 if (!checkBeforeRemote()) return false;
743
744 try {
745 mInstalld.destroyCeSnapshotsNotSpecified(null, userId, retainSnapshotIds);
746 return true;
747 } catch (Exception e) {
748 throw InstallerException.from(e);
749 }
750 }
751
752 /**
Narayan Kamath157dd1d2019-06-12 13:06:30 +0100753 * Migrates obb data from its legacy location {@code /data/media/obb} to
754 * {@code /data/media/0/Android/obb}. This call is idempotent and a fast no-op if data has
755 * already been migrated.
756 *
757 * @throws InstallerException if an error occurs.
758 */
759 public boolean migrateLegacyObbData() throws InstallerException {
760 if (!checkBeforeRemote()) return false;
761
762 try {
763 mInstalld.migrateLegacyObbData();
764 return true;
765 } catch (Exception e) {
766 throw InstallerException.from(e);
767 }
768 }
769
Jeff Sharkeyfdeeeea2016-01-11 17:34:24 -0700770 private static void assertValidInstructionSet(String instructionSet)
771 throws InstallerException {
Narayan Kamath6c4b9de2014-08-08 12:44:12 +0100772 for (String abi : Build.SUPPORTED_ABIS) {
Jeff Sharkeyfdeeeea2016-01-11 17:34:24 -0700773 if (VMRuntime.getInstructionSet(abi).equals(instructionSet)) {
774 return;
Narayan Kamath6c4b9de2014-08-08 12:44:12 +0100775 }
776 }
Jeff Sharkeyfdeeeea2016-01-11 17:34:24 -0700777 throw new InstallerException("Invalid instruction set: " + instructionSet);
Narayan Kamath6c4b9de2014-08-08 12:44:12 +0100778 }
Jeff Sharkey740f5232016-12-09 14:31:26 -0700779
Eric Holka1485f62019-01-07 13:58:25 -0800780 public boolean compileLayouts(String apkPath, String packageName, String outDexFile, int uid) {
781 try {
782 return mInstalld.compileLayouts(apkPath, packageName, outDexFile, uid);
783 } catch (RemoteException e) {
784 return false;
785 }
786 }
787
Jeff Sharkey740f5232016-12-09 14:31:26 -0700788 public static class InstallerException extends Exception {
789 public InstallerException(String detailMessage) {
790 super(detailMessage);
791 }
792
793 public static InstallerException from(Exception e) throws InstallerException {
Jeff Sharkey447a3ac2016-12-12 10:15:37 -0700794 throw new InstallerException(e.toString());
Jeff Sharkey740f5232016-12-09 14:31:26 -0700795 }
796 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800797}