blob: 45f1a2b8250a22c9a33f3a5951b2dca012d40e11 [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;
Jeff Sharkey9f2f2182016-12-21 09:18:33 -070031import android.text.format.DateUtils;
Joe Onorato8a9b2202010-02-26 18:56:32 -080032import android.util.Slog;
Jeff Sharkey790a4ec2015-04-09 13:18:44 -070033
Jeff Sharkey9f2f2182016-12-21 09:18:33 -070034import com.android.internal.os.BackgroundThread;
Narayan Kamath29564cd2014-08-07 10:57:40 +010035import com.android.server.SystemService;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080036
Jeff Sharkeyfdeeeea2016-01-11 17:34:24 -070037import dalvik.system.VMRuntime;
38
Victor Hsieh55f14992018-01-13 14:12:59 -080039import java.io.FileDescriptor;
40
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -070041public class Installer extends SystemService {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080042 private static final String TAG = "Installer";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080043
Todd Kennedyfa54ab72015-09-25 07:46:12 -070044 /* ***************************************************************************
45 * IMPORTANT: These values are passed to native code. Keep them in sync with
46 * frameworks/native/cmds/installd/installd.h
47 * **************************************************************************/
48 /** Application should be visible to everyone */
Andreas Gampebdd30d82016-03-20 11:32:11 -070049 public static final int DEXOPT_PUBLIC = 1 << 1;
Todd Kennedyfa54ab72015-09-25 07:46:12 -070050 /** Application wants to allow debugging of its code */
Nicolas Geoffray56123ba2017-05-05 14:30:02 +010051 public static final int DEXOPT_DEBUGGABLE = 1 << 2;
Todd Kennedyfa54ab72015-09-25 07:46:12 -070052 /** The system boot has finished */
Nicolas Geoffray56123ba2017-05-05 14:30:02 +010053 public static final int DEXOPT_BOOTCOMPLETE = 1 << 3;
Andreas Gampebdd30d82016-03-20 11:32:11 -070054 /** Hint that the dexopt type is profile-guided. */
Nicolas Geoffray56123ba2017-05-05 14:30:02 +010055 public static final int DEXOPT_PROFILE_GUIDED = 1 << 4;
Calin Juravlec22c30e2017-01-16 19:18:48 -080056 /** The compilation is for a secondary dex file. */
Nicolas Geoffray56123ba2017-05-05 14:30:02 +010057 public static final int DEXOPT_SECONDARY_DEX = 1 << 5;
Calin Juravlec22c30e2017-01-16 19:18:48 -080058 /** Ignore the result of dexoptNeeded and force compilation. */
Nicolas Geoffray56123ba2017-05-05 14:30:02 +010059 public static final int DEXOPT_FORCE = 1 << 6;
Calin Juravlec22c30e2017-01-16 19:18:48 -080060 /** Indicates that the dex file passed to dexopt in on CE storage. */
Nicolas Geoffray56123ba2017-05-05 14:30:02 +010061 public static final int DEXOPT_STORAGE_CE = 1 << 7;
Calin Juravlec22c30e2017-01-16 19:18:48 -080062 /** Indicates that the dex file passed to dexopt in on DE storage. */
Nicolas Geoffray56123ba2017-05-05 14:30:02 +010063 public static final int DEXOPT_STORAGE_DE = 1 << 8;
David Sehr2118ec42017-10-25 14:28:29 -070064 /** Indicates that dexopt is invoked from the background service. */
65 public static final int DEXOPT_IDLE_BACKGROUND_JOB = 1 << 9;
David Brazdilf7e31c02018-02-13 17:04:26 +000066 /** Indicates that dexopt should restrict access to private APIs. */
67 public static final int DEXOPT_ENABLE_HIDDEN_API_CHECKS = 1 << 10;
Mathieu Chartierfa3e9762018-03-06 18:28:22 -080068 /** Indicates that dexopt should convert to CompactDex. */
69 public static final int DEXOPT_GENERATE_COMPACT_DEX = 1 << 11;
Mathieu Chartiera9c34332018-03-12 17:11:07 -070070 /** Indicates that dexopt should generate an app image */
71 public static final int DEXOPT_GENERATE_APP_IMAGE = 1 << 12;
Todd Kennedyfa54ab72015-09-25 07:46:12 -070072
Jeff Sharkey47f71082016-02-01 17:03:54 -070073 // NOTE: keep in sync with installd
74 public static final int FLAG_CLEAR_CACHE_ONLY = 1 << 8;
75 public static final int FLAG_CLEAR_CODE_CACHE_ONLY = 1 << 9;
Jeff Sharkey5eb3eb52016-12-13 08:44:51 -070076 public static final int FLAG_USE_QUOTA = 1 << 12;
Jeff Sharkey458428e2017-02-22 11:47:15 -070077 public static final int FLAG_FREE_CACHE_V2 = 1 << 13;
78 public static final int FLAG_FREE_CACHE_V2_DEFY_QUOTA = 1 << 14;
79 public static final int FLAG_FREE_CACHE_NOOP = 1 << 15;
Jeff Sharkey15662332017-04-03 16:41:29 -060080 public static final int FLAG_FORCE = 1 << 16;
Jeff Sharkeyfdeeeea2016-01-11 17:34:24 -070081
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -070082 private final boolean mIsolated;
83
Jeff Sharkey740f5232016-12-09 14:31:26 -070084 private volatile IInstalld mInstalld;
Jeff Sharkeyc8ddc2d2016-12-05 23:14:41 -070085 private volatile Object mWarnIfHeld;
86
Jeff Brownb880d882014-02-10 19:47:07 -080087 public Installer(Context context) {
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -070088 this(context, false);
Jeff Brownb880d882014-02-10 19:47:07 -080089 }
90
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -070091 /**
92 * @param isolated indicates if this object should <em>not</em> connect to
93 * the real {@code installd}. All remote calls will be ignored
94 * unless you extend this class and intercept them.
95 */
96 public Installer(Context context, boolean isolated) {
Andreas Gamped15300c2016-06-23 20:27:12 -070097 super(context);
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -070098 mIsolated = isolated;
Andreas Gamped15300c2016-06-23 20:27:12 -070099 }
100
Jeff Sharkey8948c012015-11-03 12:33:54 -0800101 /**
102 * Yell loudly if someone tries making future calls while holding a lock on
103 * the given object.
104 */
105 public void setWarnIfHeld(Object warnIfHeld) {
Jeff Sharkeyc8ddc2d2016-12-05 23:14:41 -0700106 mWarnIfHeld = warnIfHeld;
Jeff Sharkey8948c012015-11-03 12:33:54 -0800107 }
108
Jeff Brown6f357d32014-01-15 20:40:55 -0800109 @Override
110 public void onStart() {
Jeff Sharkey740f5232016-12-09 14:31:26 -0700111 if (mIsolated) {
112 mInstalld = null;
113 } else {
Jeff Sharkey9f2f2182016-12-21 09:18:33 -0700114 connect();
115 }
116 }
117
118 private void connect() {
119 IBinder binder = ServiceManager.getService("installd");
120 if (binder != null) {
121 try {
122 binder.linkToDeath(new DeathRecipient() {
123 @Override
124 public void binderDied() {
125 Slog.w(TAG, "installd died; reconnecting");
126 connect();
127 }
128 }, 0);
129 } catch (RemoteException e) {
130 binder = null;
131 }
132 }
133
134 if (binder != null) {
135 mInstalld = IInstalld.Stub.asInterface(binder);
Jeff Sharkey82add8a2017-03-11 19:44:16 -0700136 try {
137 invalidateMounts();
138 } catch (InstallerException ignored) {
139 }
Jeff Sharkey9f2f2182016-12-21 09:18:33 -0700140 } else {
141 Slog.w(TAG, "installd not found; trying again");
142 BackgroundThread.getHandler().postDelayed(() -> {
143 connect();
144 }, DateUtils.SECOND_IN_MILLIS);
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -0700145 }
Jeff Brown6f357d32014-01-15 20:40:55 -0800146 }
147
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -0700148 /**
149 * Do several pre-flight checks before making a remote call.
150 *
151 * @return if the remote call should continue.
152 */
153 private boolean checkBeforeRemote() {
Jeff Sharkeyc8ddc2d2016-12-05 23:14:41 -0700154 if (mWarnIfHeld != null && Thread.holdsLock(mWarnIfHeld)) {
155 Slog.wtf(TAG, "Calling thread " + Thread.currentThread().getName() + " is holding 0x"
156 + Integer.toHexString(System.identityHashCode(mWarnIfHeld)), new Throwable());
157 }
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -0700158 if (mIsolated) {
159 Slog.i(TAG, "Ignoring request because this installer is isolated");
160 return false;
161 } else {
162 return true;
163 }
Jeff Sharkeyc8ddc2d2016-12-05 23:14:41 -0700164 }
165
Jeff Sharkey1c6f7232016-12-19 16:39:02 -0700166 public long createAppData(String uuid, String packageName, int userId, int flags, int appId,
Jeff Sharkeyc8ddc2d2016-12-05 23:14:41 -0700167 String seInfo, int targetSdkVersion) throws InstallerException {
Jeff Sharkey1c6f7232016-12-19 16:39:02 -0700168 if (!checkBeforeRemote()) return -1;
Jeff Sharkeyc8ddc2d2016-12-05 23:14:41 -0700169 try {
Jeff Sharkey1c6f7232016-12-19 16:39:02 -0700170 return mInstalld.createAppData(uuid, packageName, userId, flags, appId, seInfo,
Jeff Sharkey70b4d102016-12-05 11:19:28 -0700171 targetSdkVersion);
Jeff Sharkey447a3ac2016-12-12 10:15:37 -0700172 } catch (Exception e) {
Jeff Sharkey740f5232016-12-09 14:31:26 -0700173 throw InstallerException.from(e);
Jeff Sharkey70b4d102016-12-05 11:19:28 -0700174 }
Jeff Sharkey790a4ec2015-04-09 13:18:44 -0700175 }
176
Jeff Sharkey019ac852016-12-05 23:39:46 -0700177 public void restoreconAppData(String uuid, String packageName, int userId, int flags, int appId,
178 String seInfo) throws InstallerException {
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -0700179 if (!checkBeforeRemote()) return;
Jeff Sharkey019ac852016-12-05 23:39:46 -0700180 try {
181 mInstalld.restoreconAppData(uuid, packageName, userId, flags, appId, seInfo);
Jeff Sharkey447a3ac2016-12-12 10:15:37 -0700182 } catch (Exception e) {
Jeff Sharkey740f5232016-12-09 14:31:26 -0700183 throw InstallerException.from(e);
Jeff Sharkey019ac852016-12-05 23:39:46 -0700184 }
Jeff Sharkey790a4ec2015-04-09 13:18:44 -0700185 }
186
Jeff Sharkey019ac852016-12-05 23:39:46 -0700187 public void migrateAppData(String uuid, String packageName, int userId, int flags)
Jeff Sharkeye4697132016-02-06 19:46:15 -0700188 throws InstallerException {
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -0700189 if (!checkBeforeRemote()) return;
Jeff Sharkey019ac852016-12-05 23:39:46 -0700190 try {
191 mInstalld.migrateAppData(uuid, packageName, userId, flags);
Jeff Sharkey447a3ac2016-12-12 10:15:37 -0700192 } catch (Exception e) {
Jeff Sharkey740f5232016-12-09 14:31:26 -0700193 throw InstallerException.from(e);
Jeff Sharkey019ac852016-12-05 23:39:46 -0700194 }
Jeff Sharkeye4697132016-02-06 19:46:15 -0700195 }
196
Jeff Sharkey019ac852016-12-05 23:39:46 -0700197 public void clearAppData(String uuid, String packageName, int userId, int flags,
198 long ceDataInode) throws InstallerException {
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -0700199 if (!checkBeforeRemote()) return;
Jeff Sharkey019ac852016-12-05 23:39:46 -0700200 try {
201 mInstalld.clearAppData(uuid, packageName, userId, flags, ceDataInode);
Jeff Sharkey447a3ac2016-12-12 10:15:37 -0700202 } catch (Exception e) {
Jeff Sharkey740f5232016-12-09 14:31:26 -0700203 throw InstallerException.from(e);
Jeff Sharkey019ac852016-12-05 23:39:46 -0700204 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800205 }
206
Jeff Sharkey019ac852016-12-05 23:39:46 -0700207 public void destroyAppData(String uuid, String packageName, int userId, int flags,
208 long ceDataInode) throws InstallerException {
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -0700209 if (!checkBeforeRemote()) return;
Jeff Sharkey019ac852016-12-05 23:39:46 -0700210 try {
211 mInstalld.destroyAppData(uuid, packageName, userId, flags, ceDataInode);
Jeff Sharkey447a3ac2016-12-12 10:15:37 -0700212 } catch (Exception e) {
Jeff Sharkey740f5232016-12-09 14:31:26 -0700213 throw InstallerException.from(e);
Jeff Sharkey019ac852016-12-05 23:39:46 -0700214 }
Dave Allison0efbd9a2014-01-30 14:19:51 -0800215 }
216
Jeff Sharkey15662332017-04-03 16:41:29 -0600217 public void fixupAppData(String uuid, int flags) throws InstallerException {
218 if (!checkBeforeRemote()) return;
219 try {
220 mInstalld.fixupAppData(uuid, flags);
221 } catch (Exception e) {
222 throw InstallerException.from(e);
223 }
224 }
225
Jeff Sharkeyc8ddc2d2016-12-05 23:14:41 -0700226 public void moveCompleteApp(String fromUuid, String toUuid, String packageName,
227 String dataAppName, int appId, String seInfo, int targetSdkVersion)
Janis Danisevskisf3409742016-01-12 14:46:33 +0000228 throws InstallerException {
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -0700229 if (!checkBeforeRemote()) return;
Jeff Sharkeyc8ddc2d2016-12-05 23:14:41 -0700230 try {
231 mInstalld.moveCompleteApp(fromUuid, toUuid, packageName, dataAppName, appId, seInfo,
232 targetSdkVersion);
Jeff Sharkey447a3ac2016-12-12 10:15:37 -0700233 } catch (Exception e) {
Jeff Sharkey740f5232016-12-09 14:31:26 -0700234 throw InstallerException.from(e);
Jeff Sharkeyc8ddc2d2016-12-05 23:14:41 -0700235 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800236 }
237
Jeff Sharkey82ca9012017-01-08 17:06:58 -0700238 public void getAppSize(String uuid, String[] packageNames, int userId, int flags, int appId,
239 long[] ceDataInodes, String[] codePaths, PackageStats stats)
Jeff Sharkey5eb3eb52016-12-13 08:44:51 -0700240 throws InstallerException {
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -0700241 if (!checkBeforeRemote()) return;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800242 try {
Jeff Sharkey82ca9012017-01-08 17:06:58 -0700243 final long[] res = mInstalld.getAppSize(uuid, packageNames, userId, flags,
244 appId, ceDataInodes, codePaths);
Jeff Sharkey740f5232016-12-09 14:31:26 -0700245 stats.codeSize += res[0];
246 stats.dataSize += res[1];
247 stats.cacheSize += res[2];
Jeff Sharkey82ca9012017-01-08 17:06:58 -0700248 stats.externalCodeSize += res[3];
249 stats.externalDataSize += res[4];
250 stats.externalCacheSize += res[5];
251 } catch (Exception e) {
252 throw InstallerException.from(e);
253 }
254 }
255
256 public void getUserSize(String uuid, int userId, int flags, int[] appIds, PackageStats stats)
257 throws InstallerException {
258 if (!checkBeforeRemote()) return;
259 try {
260 final long[] res = mInstalld.getUserSize(uuid, userId, flags, appIds);
261 stats.codeSize += res[0];
262 stats.dataSize += res[1];
263 stats.cacheSize += res[2];
264 stats.externalCodeSize += res[3];
265 stats.externalDataSize += res[4];
266 stats.externalCacheSize += res[5];
267 } catch (Exception e) {
268 throw InstallerException.from(e);
269 }
270 }
271
Jeff Sharkey00347882017-04-17 16:44:12 -0600272 public long[] getExternalSize(String uuid, int userId, int flags, int[] appIds)
273 throws InstallerException {
Jeff Sharkeyc8b29ac2017-07-06 11:29:06 -0600274 if (!checkBeforeRemote()) return new long[6];
Jeff Sharkey82ca9012017-01-08 17:06:58 -0700275 try {
Jeff Sharkey00347882017-04-17 16:44:12 -0600276 return mInstalld.getExternalSize(uuid, userId, flags, appIds);
Jeff Sharkey447a3ac2016-12-12 10:15:37 -0700277 } catch (Exception e) {
Jeff Sharkey740f5232016-12-09 14:31:26 -0700278 throw InstallerException.from(e);
Jeff Sharkey42884192016-04-09 16:12:01 -0600279 }
280 }
281
Jeff Sharkey36ba0222017-01-18 12:11:31 -0700282 public void setAppQuota(String uuid, int userId, int appId, long cacheQuota)
283 throws InstallerException {
284 if (!checkBeforeRemote()) return;
285 try {
286 mInstalld.setAppQuota(uuid, userId, appId, cacheQuota);
287 } catch (Exception e) {
288 throw InstallerException.from(e);
289 }
290 }
291
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -0700292 public void dexopt(String apkPath, int uid, @Nullable String pkgName, String instructionSet,
Calin Juravledb4a79a2015-12-23 18:55:08 +0200293 int dexoptNeeded, @Nullable String outputPath, int dexFlags,
Calin Juravle811a75a2017-04-05 22:49:38 -0700294 String compilerFilter, @Nullable String volumeUuid, @Nullable String sharedLibraries,
Calin Juravle6ae39fc2018-01-19 20:32:47 -0800295 @Nullable String seInfo, boolean downgrade, int targetSdkVersion,
Calin Juravle4bc8f4d2018-02-12 12:00:44 -0800296 @Nullable String profileName, @Nullable String dexMetadataPath,
297 @Nullable String compilationReason) throws InstallerException {
Jeff Sharkeyfdeeeea2016-01-11 17:34:24 -0700298 assertValidInstructionSet(instructionSet);
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -0700299 if (!checkBeforeRemote()) return;
Jeff Sharkey740f5232016-12-09 14:31:26 -0700300 try {
301 mInstalld.dexopt(apkPath, uid, pkgName, instructionSet, dexoptNeeded, outputPath,
David Brazdil3d44ed02018-01-16 20:01:47 +0000302 dexFlags, compilerFilter, volumeUuid, sharedLibraries, seInfo, downgrade,
Calin Juravle4bc8f4d2018-02-12 12:00:44 -0800303 targetSdkVersion, profileName, dexMetadataPath, compilationReason);
Jeff Sharkey447a3ac2016-12-12 10:15:37 -0700304 } catch (Exception e) {
Jeff Sharkey740f5232016-12-09 14:31:26 -0700305 throw InstallerException.from(e);
306 }
Andreas Gampebdd30d82016-03-20 11:32:11 -0700307 }
308
Calin Juravle6ae39fc2018-01-19 20:32:47 -0800309 public boolean mergeProfiles(int uid, String packageName, String profileName)
David Sehra8777082016-05-24 15:25:23 -0700310 throws InstallerException {
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -0700311 if (!checkBeforeRemote()) return false;
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700312 try {
Calin Juravle6ae39fc2018-01-19 20:32:47 -0800313 return mInstalld.mergeProfiles(uid, packageName, profileName);
Jeff Sharkey447a3ac2016-12-12 10:15:37 -0700314 } catch (Exception e) {
Jeff Sharkey740f5232016-12-09 14:31:26 -0700315 throw InstallerException.from(e);
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700316 }
David Sehra8777082016-05-24 15:25:23 -0700317 }
318
Calin Juravle6ae39fc2018-01-19 20:32:47 -0800319 public boolean dumpProfiles(int uid, String packageName, String profileName, String codePath)
Mathieu Chartier235845d2017-05-10 15:09:19 -0700320 throws InstallerException {
321 if (!checkBeforeRemote()) return false;
322 try {
Calin Juravle6ae39fc2018-01-19 20:32:47 -0800323 return mInstalld.dumpProfiles(uid, packageName, profileName, codePath);
324 } catch (Exception e) {
325 throw InstallerException.from(e);
326 }
327 }
328
329 public boolean copySystemProfile(String systemProfile, int uid, String packageName,
330 String profileName) throws InstallerException {
331 if (!checkBeforeRemote()) return false;
332 try {
333 return mInstalld.copySystemProfile(systemProfile, uid, packageName, profileName);
Mathieu Chartier235845d2017-05-10 15:09:19 -0700334 } catch (Exception e) {
335 throw InstallerException.from(e);
336 }
337 }
338
Jeff Sharkeyfdeeeea2016-01-11 17:34:24 -0700339 public void idmap(String targetApkPath, String overlayApkPath, int uid)
340 throws InstallerException {
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -0700341 if (!checkBeforeRemote()) return;
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700342 try {
343 mInstalld.idmap(targetApkPath, overlayApkPath, uid);
Jeff Sharkey447a3ac2016-12-12 10:15:37 -0700344 } catch (Exception e) {
Jeff Sharkey740f5232016-12-09 14:31:26 -0700345 throw InstallerException.from(e);
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700346 }
Jeff Sharkeyfdeeeea2016-01-11 17:34:24 -0700347 }
348
MÃ¥rten Kongstad163826342016-06-02 09:35:09 +0200349 public void removeIdmap(String overlayApkPath) throws InstallerException {
350 if (!checkBeforeRemote()) return;
351 try {
352 mInstalld.removeIdmap(overlayApkPath);
353 } catch (Exception e) {
354 throw InstallerException.from(e);
355 }
356 }
357
Jeff Sharkeyfdeeeea2016-01-11 17:34:24 -0700358 public void rmdex(String codePath, String instructionSet) throws InstallerException {
359 assertValidInstructionSet(instructionSet);
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -0700360 if (!checkBeforeRemote()) return;
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700361 try {
362 mInstalld.rmdex(codePath, instructionSet);
Jeff Sharkey447a3ac2016-12-12 10:15:37 -0700363 } catch (Exception e) {
Jeff Sharkey740f5232016-12-09 14:31:26 -0700364 throw InstallerException.from(e);
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700365 }
Jeff Sharkeyfdeeeea2016-01-11 17:34:24 -0700366 }
367
368 public void rmPackageDir(String packageDir) throws InstallerException {
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -0700369 if (!checkBeforeRemote()) return;
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700370 try {
371 mInstalld.rmPackageDir(packageDir);
Jeff Sharkey447a3ac2016-12-12 10:15:37 -0700372 } catch (Exception e) {
Jeff Sharkey740f5232016-12-09 14:31:26 -0700373 throw InstallerException.from(e);
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700374 }
Jeff Sharkeyfdeeeea2016-01-11 17:34:24 -0700375 }
376
Calin Juravle6ae39fc2018-01-19 20:32:47 -0800377 public void clearAppProfiles(String packageName, String profileName) throws InstallerException {
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -0700378 if (!checkBeforeRemote()) return;
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700379 try {
Calin Juravle6ae39fc2018-01-19 20:32:47 -0800380 mInstalld.clearAppProfiles(packageName, profileName);
Jeff Sharkey447a3ac2016-12-12 10:15:37 -0700381 } catch (Exception e) {
Jeff Sharkey740f5232016-12-09 14:31:26 -0700382 throw InstallerException.from(e);
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700383 }
Calin Juravled6d27e32016-03-23 13:59:18 +0000384 }
385
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700386 public void destroyAppProfiles(String packageName) throws InstallerException {
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -0700387 if (!checkBeforeRemote()) return;
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700388 try {
389 mInstalld.destroyAppProfiles(packageName);
Jeff Sharkey447a3ac2016-12-12 10:15:37 -0700390 } catch (Exception e) {
Jeff Sharkey740f5232016-12-09 14:31:26 -0700391 throw InstallerException.from(e);
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700392 }
David Brazdil9aa6db02016-03-08 12:57:12 +0000393 }
394
Jeff Sharkeyfcf1e552016-04-14 20:44:58 -0600395 public void createUserData(String uuid, int userId, int userSerial, int flags)
396 throws InstallerException {
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -0700397 if (!checkBeforeRemote()) return;
Jeff Sharkey019ac852016-12-05 23:39:46 -0700398 try {
399 mInstalld.createUserData(uuid, userId, userSerial, flags);
Jeff Sharkey447a3ac2016-12-12 10:15:37 -0700400 } catch (Exception e) {
Jeff Sharkey740f5232016-12-09 14:31:26 -0700401 throw InstallerException.from(e);
Jeff Sharkey019ac852016-12-05 23:39:46 -0700402 }
Jeff Sharkeyfdeeeea2016-01-11 17:34:24 -0700403 }
404
Jeff Sharkeyfcf1e552016-04-14 20:44:58 -0600405 public void destroyUserData(String uuid, int userId, int flags) throws InstallerException {
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -0700406 if (!checkBeforeRemote()) return;
Jeff Sharkey019ac852016-12-05 23:39:46 -0700407 try {
408 mInstalld.destroyUserData(uuid, userId, flags);
Jeff Sharkey447a3ac2016-12-12 10:15:37 -0700409 } catch (Exception e) {
Jeff Sharkey740f5232016-12-09 14:31:26 -0700410 throw InstallerException.from(e);
Jeff Sharkey019ac852016-12-05 23:39:46 -0700411 }
Jeff Sharkeyfdeeeea2016-01-11 17:34:24 -0700412 }
413
414 public void markBootComplete(String instructionSet) throws InstallerException {
415 assertValidInstructionSet(instructionSet);
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -0700416 if (!checkBeforeRemote()) return;
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700417 try {
418 mInstalld.markBootComplete(instructionSet);
Jeff Sharkey447a3ac2016-12-12 10:15:37 -0700419 } catch (Exception e) {
Jeff Sharkey740f5232016-12-09 14:31:26 -0700420 throw InstallerException.from(e);
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700421 }
Jeff Sharkeyfdeeeea2016-01-11 17:34:24 -0700422 }
423
Jeff Sharkeyddff8072017-05-26 13:10:46 -0600424 public void freeCache(String uuid, long targetFreeBytes, long cacheReservedBytes, int flags)
425 throws InstallerException {
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -0700426 if (!checkBeforeRemote()) return;
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700427 try {
Jeff Sharkeyddff8072017-05-26 13:10:46 -0600428 mInstalld.freeCache(uuid, targetFreeBytes, cacheReservedBytes, flags);
Jeff Sharkey447a3ac2016-12-12 10:15:37 -0700429 } catch (Exception e) {
Jeff Sharkey740f5232016-12-09 14:31:26 -0700430 throw InstallerException.from(e);
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700431 }
Jeff Sharkeyfdeeeea2016-01-11 17:34:24 -0700432 }
433
Kenny Rootddbe50d2012-09-06 13:18:37 -0700434 /**
Jeff Sharkeyfdeeeea2016-01-11 17:34:24 -0700435 * Links the 32 bit native library directory in an application's data
436 * directory to the real location for backward compatibility. Note that no
437 * such symlink is created for 64 bit shared libraries.
Kenny Rootddbe50d2012-09-06 13:18:37 -0700438 */
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700439 public void linkNativeLibraryDirectory(String uuid, String packageName, String nativeLibPath32,
Jeff Sharkeyfdeeeea2016-01-11 17:34:24 -0700440 int userId) throws InstallerException {
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -0700441 if (!checkBeforeRemote()) return;
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700442 try {
443 mInstalld.linkNativeLibraryDirectory(uuid, packageName, nativeLibPath32, userId);
Jeff Sharkey447a3ac2016-12-12 10:15:37 -0700444 } catch (Exception e) {
Jeff Sharkey740f5232016-12-09 14:31:26 -0700445 throw InstallerException.from(e);
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700446 }
Kenny Root6a6b0072010-10-07 16:46:10 -0700447 }
Robert Craig43853432014-03-04 11:57:23 -0500448
Jeff Sharkeyfdeeeea2016-01-11 17:34:24 -0700449 public void createOatDir(String oatDir, String dexInstructionSet)
450 throws InstallerException {
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -0700451 if (!checkBeforeRemote()) return;
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700452 try {
453 mInstalld.createOatDir(oatDir, dexInstructionSet);
Jeff Sharkey447a3ac2016-12-12 10:15:37 -0700454 } catch (Exception e) {
Jeff Sharkey740f5232016-12-09 14:31:26 -0700455 throw InstallerException.from(e);
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700456 }
Jeff Sharkey790a4ec2015-04-09 13:18:44 -0700457 }
458
Jeff Sharkeyfdeeeea2016-01-11 17:34:24 -0700459 public void linkFile(String relativePath, String fromBase, String toBase)
460 throws InstallerException {
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -0700461 if (!checkBeforeRemote()) return;
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700462 try {
463 mInstalld.linkFile(relativePath, fromBase, toBase);
Jeff Sharkey447a3ac2016-12-12 10:15:37 -0700464 } catch (Exception e) {
Jeff Sharkey740f5232016-12-09 14:31:26 -0700465 throw InstallerException.from(e);
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700466 }
Robert Craig43853432014-03-04 11:57:23 -0500467 }
Narayan Kamath6c4b9de2014-08-08 12:44:12 +0100468
Andreas Gampeabcbe2f2016-02-26 11:25:36 -0800469 public void moveAb(String apkPath, String instructionSet, String outputPath)
470 throws InstallerException {
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -0700471 if (!checkBeforeRemote()) return;
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700472 try {
473 mInstalld.moveAb(apkPath, instructionSet, outputPath);
Jeff Sharkey447a3ac2016-12-12 10:15:37 -0700474 } catch (Exception e) {
Jeff Sharkey740f5232016-12-09 14:31:26 -0700475 throw InstallerException.from(e);
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700476 }
Andreas Gampeabcbe2f2016-02-26 11:25:36 -0800477 }
478
Andreas Gampe33c592d2016-09-09 17:08:53 -0700479 public void deleteOdex(String apkPath, String instructionSet, String outputPath)
480 throws InstallerException {
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -0700481 if (!checkBeforeRemote()) return;
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700482 try {
483 mInstalld.deleteOdex(apkPath, instructionSet, outputPath);
Jeff Sharkey447a3ac2016-12-12 10:15:37 -0700484 } catch (Exception e) {
Jeff Sharkey740f5232016-12-09 14:31:26 -0700485 throw InstallerException.from(e);
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700486 }
Andreas Gampe33c592d2016-09-09 17:08:53 -0700487 }
488
Victor Hsiehcccad192018-03-19 15:57:02 -0700489 public void installApkVerity(String filePath, FileDescriptor verityInput, int contentSize)
Victor Hsieh55f14992018-01-13 14:12:59 -0800490 throws InstallerException {
491 if (!checkBeforeRemote()) return;
492 try {
Victor Hsiehcccad192018-03-19 15:57:02 -0700493 mInstalld.installApkVerity(filePath, verityInput, contentSize);
Victor Hsieh55f14992018-01-13 14:12:59 -0800494 } catch (Exception e) {
495 throw InstallerException.from(e);
496 }
497 }
498
Victor Hsieh5f761242018-01-20 10:30:12 -0800499 public void assertFsverityRootHashMatches(String filePath, @NonNull byte[] expectedHash)
500 throws InstallerException {
501 if (!checkBeforeRemote()) return;
502 try {
503 mInstalld.assertFsverityRootHashMatches(filePath, expectedHash);
504 } catch (Exception e) {
505 throw InstallerException.from(e);
506 }
507 }
508
Calin Juravle1aa5f882017-01-25 01:05:50 -0800509 public boolean reconcileSecondaryDexFile(String apkPath, String packageName, int uid,
510 String[] isas, @Nullable String volumeUuid, int flags) throws InstallerException {
511 for (int i = 0; i < isas.length; i++) {
512 assertValidInstructionSet(isas[i]);
513 }
514 if (!checkBeforeRemote()) return false;
515 try {
516 return mInstalld.reconcileSecondaryDexFile(apkPath, packageName, uid, isas,
517 volumeUuid, flags);
518 } catch (Exception e) {
519 throw InstallerException.from(e);
520 }
521 }
522
Alan Stokesa0023602017-10-16 12:31:44 +0100523 public byte[] hashSecondaryDexFile(String dexPath, String packageName, int uid,
524 @Nullable String volumeUuid, int flags) throws InstallerException {
525 if (!checkBeforeRemote()) return new byte[0];
526 try {
527 return mInstalld.hashSecondaryDexFile(dexPath, packageName, uid, volumeUuid, flags);
528 } catch (Exception e) {
529 throw InstallerException.from(e);
530 }
531 }
532
Calin Juravlefcbb74a2018-01-21 21:39:18 -0800533 public boolean createProfileSnapshot(int appId, String packageName, String profileName,
534 String classpath) throws InstallerException {
Calin Juravlefd9f8ae2017-11-29 18:26:55 -0800535 if (!checkBeforeRemote()) return false;
536 try {
Calin Juravlefcbb74a2018-01-21 21:39:18 -0800537 return mInstalld.createProfileSnapshot(appId, packageName, profileName, classpath);
Calin Juravlefd9f8ae2017-11-29 18:26:55 -0800538 } catch (Exception e) {
539 throw InstallerException.from(e);
540 }
541 }
542
Calin Juravle6ae39fc2018-01-19 20:32:47 -0800543 public void destroyProfileSnapshot(String packageName, String profileName)
Calin Juravlefd9f8ae2017-11-29 18:26:55 -0800544 throws InstallerException {
545 if (!checkBeforeRemote()) return;
546 try {
Calin Juravle6ae39fc2018-01-19 20:32:47 -0800547 mInstalld.destroyProfileSnapshot(packageName, profileName);
Calin Juravlefd9f8ae2017-11-29 18:26:55 -0800548 } catch (Exception e) {
549 throw InstallerException.from(e);
550 }
551 }
552
Jeff Sharkey7d25faf2017-01-16 20:58:40 -0700553 public void invalidateMounts() throws InstallerException {
554 if (!checkBeforeRemote()) return;
555 try {
556 mInstalld.invalidateMounts();
557 } catch (Exception e) {
558 throw InstallerException.from(e);
559 }
560 }
561
Jeff Sharkeyd5d5e922017-02-21 10:51:23 -0700562 public boolean isQuotaSupported(String volumeUuid) throws InstallerException {
563 if (!checkBeforeRemote()) return false;
564 try {
565 return mInstalld.isQuotaSupported(volumeUuid);
566 } catch (Exception e) {
567 throw InstallerException.from(e);
568 }
569 }
570
Calin Juravle3621be72018-01-18 15:17:29 -0800571 public boolean prepareAppProfile(String pkg, @UserIdInt int userId, @AppIdInt int appId,
572 String profileName, String codePath, String dexMetadataPath) throws InstallerException {
573 if (!checkBeforeRemote()) return false;
574 try {
575 return mInstalld.prepareAppProfile(pkg, userId, appId, profileName, codePath,
576 dexMetadataPath);
577 } catch (Exception e) {
578 throw InstallerException.from(e);
579 }
580 }
581
Jeff Sharkeyfdeeeea2016-01-11 17:34:24 -0700582 private static void assertValidInstructionSet(String instructionSet)
583 throws InstallerException {
Narayan Kamath6c4b9de2014-08-08 12:44:12 +0100584 for (String abi : Build.SUPPORTED_ABIS) {
Jeff Sharkeyfdeeeea2016-01-11 17:34:24 -0700585 if (VMRuntime.getInstructionSet(abi).equals(instructionSet)) {
586 return;
Narayan Kamath6c4b9de2014-08-08 12:44:12 +0100587 }
588 }
Jeff Sharkeyfdeeeea2016-01-11 17:34:24 -0700589 throw new InstallerException("Invalid instruction set: " + instructionSet);
Narayan Kamath6c4b9de2014-08-08 12:44:12 +0100590 }
Jeff Sharkey740f5232016-12-09 14:31:26 -0700591
592 public static class InstallerException extends Exception {
593 public InstallerException(String detailMessage) {
594 super(detailMessage);
595 }
596
597 public static InstallerException from(Exception e) throws InstallerException {
Jeff Sharkey447a3ac2016-12-12 10:15:37 -0700598 throw new InstallerException(e.toString());
Jeff Sharkey740f5232016-12-09 14:31:26 -0700599 }
600 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800601}