blob: 5c4c0401b63cbbbfd9cf1469c0185ac628e3e823 [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
Fyodor Kupolovb94c1652015-03-03 12:25:30 -080019import android.annotation.Nullable;
Jeff Brownb880d882014-02-10 19:47:07 -080020import android.content.Context;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080021import android.content.pm.PackageStats;
Narayan Kamath29564cd2014-08-07 10:57:40 +010022import android.os.Build;
Jeff Sharkey9f2f2182016-12-21 09:18:33 -070023import android.os.IBinder;
24import android.os.IBinder.DeathRecipient;
Jeff Sharkey70b4d102016-12-05 11:19:28 -070025import android.os.IInstalld;
Jeff Sharkey9f2f2182016-12-21 09:18:33 -070026import android.os.RemoteException;
Jeff Sharkey70b4d102016-12-05 11:19:28 -070027import android.os.ServiceManager;
Jeff Sharkey9f2f2182016-12-21 09:18:33 -070028import android.text.format.DateUtils;
Joe Onorato8a9b2202010-02-26 18:56:32 -080029import android.util.Slog;
Jeff Sharkey790a4ec2015-04-09 13:18:44 -070030
Jeff Sharkey9f2f2182016-12-21 09:18:33 -070031import com.android.internal.os.BackgroundThread;
Narayan Kamath29564cd2014-08-07 10:57:40 +010032import com.android.server.SystemService;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080033
Jeff Sharkeyfdeeeea2016-01-11 17:34:24 -070034import dalvik.system.VMRuntime;
35
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -070036public class Installer extends SystemService {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080037 private static final String TAG = "Installer";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080038
Todd Kennedyfa54ab72015-09-25 07:46:12 -070039 /* ***************************************************************************
40 * IMPORTANT: These values are passed to native code. Keep them in sync with
41 * frameworks/native/cmds/installd/installd.h
42 * **************************************************************************/
43 /** Application should be visible to everyone */
Andreas Gampebdd30d82016-03-20 11:32:11 -070044 public static final int DEXOPT_PUBLIC = 1 << 1;
Todd Kennedyfa54ab72015-09-25 07:46:12 -070045 /** Application wants to allow debugging of its code */
Nicolas Geoffray56123ba2017-05-05 14:30:02 +010046 public static final int DEXOPT_DEBUGGABLE = 1 << 2;
Todd Kennedyfa54ab72015-09-25 07:46:12 -070047 /** The system boot has finished */
Nicolas Geoffray56123ba2017-05-05 14:30:02 +010048 public static final int DEXOPT_BOOTCOMPLETE = 1 << 3;
Andreas Gampebdd30d82016-03-20 11:32:11 -070049 /** Hint that the dexopt type is profile-guided. */
Nicolas Geoffray56123ba2017-05-05 14:30:02 +010050 public static final int DEXOPT_PROFILE_GUIDED = 1 << 4;
Calin Juravlec22c30e2017-01-16 19:18:48 -080051 /** The compilation is for a secondary dex file. */
Nicolas Geoffray56123ba2017-05-05 14:30:02 +010052 public static final int DEXOPT_SECONDARY_DEX = 1 << 5;
Calin Juravlec22c30e2017-01-16 19:18:48 -080053 /** Ignore the result of dexoptNeeded and force compilation. */
Nicolas Geoffray56123ba2017-05-05 14:30:02 +010054 public static final int DEXOPT_FORCE = 1 << 6;
Calin Juravlec22c30e2017-01-16 19:18:48 -080055 /** Indicates that the dex file passed to dexopt in on CE storage. */
Nicolas Geoffray56123ba2017-05-05 14:30:02 +010056 public static final int DEXOPT_STORAGE_CE = 1 << 7;
Calin Juravlec22c30e2017-01-16 19:18:48 -080057 /** Indicates that the dex file passed to dexopt in on DE storage. */
Nicolas Geoffray56123ba2017-05-05 14:30:02 +010058 public static final int DEXOPT_STORAGE_DE = 1 << 8;
Todd Kennedyfa54ab72015-09-25 07:46:12 -070059
Jeff Sharkey47f71082016-02-01 17:03:54 -070060 // NOTE: keep in sync with installd
61 public static final int FLAG_CLEAR_CACHE_ONLY = 1 << 8;
62 public static final int FLAG_CLEAR_CODE_CACHE_ONLY = 1 << 9;
Jeff Sharkey5eb3eb52016-12-13 08:44:51 -070063 public static final int FLAG_USE_QUOTA = 1 << 12;
Jeff Sharkey458428e2017-02-22 11:47:15 -070064 public static final int FLAG_FREE_CACHE_V2 = 1 << 13;
65 public static final int FLAG_FREE_CACHE_V2_DEFY_QUOTA = 1 << 14;
66 public static final int FLAG_FREE_CACHE_NOOP = 1 << 15;
Jeff Sharkey15662332017-04-03 16:41:29 -060067 public static final int FLAG_FORCE = 1 << 16;
Jeff Sharkeyfdeeeea2016-01-11 17:34:24 -070068
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -070069 private final boolean mIsolated;
70
Jeff Sharkey740f5232016-12-09 14:31:26 -070071 private volatile IInstalld mInstalld;
Jeff Sharkeyc8ddc2d2016-12-05 23:14:41 -070072 private volatile Object mWarnIfHeld;
73
Jeff Brownb880d882014-02-10 19:47:07 -080074 public Installer(Context context) {
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -070075 this(context, false);
Jeff Brownb880d882014-02-10 19:47:07 -080076 }
77
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -070078 /**
79 * @param isolated indicates if this object should <em>not</em> connect to
80 * the real {@code installd}. All remote calls will be ignored
81 * unless you extend this class and intercept them.
82 */
83 public Installer(Context context, boolean isolated) {
Andreas Gamped15300c2016-06-23 20:27:12 -070084 super(context);
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -070085 mIsolated = isolated;
Andreas Gamped15300c2016-06-23 20:27:12 -070086 }
87
Jeff Sharkey8948c012015-11-03 12:33:54 -080088 /**
89 * Yell loudly if someone tries making future calls while holding a lock on
90 * the given object.
91 */
92 public void setWarnIfHeld(Object warnIfHeld) {
Jeff Sharkeyc8ddc2d2016-12-05 23:14:41 -070093 mWarnIfHeld = warnIfHeld;
Jeff Sharkey8948c012015-11-03 12:33:54 -080094 }
95
Jeff Brown6f357d32014-01-15 20:40:55 -080096 @Override
97 public void onStart() {
Jeff Sharkey740f5232016-12-09 14:31:26 -070098 if (mIsolated) {
99 mInstalld = null;
100 } else {
Jeff Sharkey9f2f2182016-12-21 09:18:33 -0700101 connect();
102 }
103 }
104
105 private void connect() {
106 IBinder binder = ServiceManager.getService("installd");
107 if (binder != null) {
108 try {
109 binder.linkToDeath(new DeathRecipient() {
110 @Override
111 public void binderDied() {
112 Slog.w(TAG, "installd died; reconnecting");
113 connect();
114 }
115 }, 0);
116 } catch (RemoteException e) {
117 binder = null;
118 }
119 }
120
121 if (binder != null) {
122 mInstalld = IInstalld.Stub.asInterface(binder);
Jeff Sharkey82add8a2017-03-11 19:44:16 -0700123 try {
124 invalidateMounts();
125 } catch (InstallerException ignored) {
126 }
Jeff Sharkey9f2f2182016-12-21 09:18:33 -0700127 } else {
128 Slog.w(TAG, "installd not found; trying again");
129 BackgroundThread.getHandler().postDelayed(() -> {
130 connect();
131 }, DateUtils.SECOND_IN_MILLIS);
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -0700132 }
Jeff Brown6f357d32014-01-15 20:40:55 -0800133 }
134
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -0700135 /**
136 * Do several pre-flight checks before making a remote call.
137 *
138 * @return if the remote call should continue.
139 */
140 private boolean checkBeforeRemote() {
Jeff Sharkeyc8ddc2d2016-12-05 23:14:41 -0700141 if (mWarnIfHeld != null && Thread.holdsLock(mWarnIfHeld)) {
142 Slog.wtf(TAG, "Calling thread " + Thread.currentThread().getName() + " is holding 0x"
143 + Integer.toHexString(System.identityHashCode(mWarnIfHeld)), new Throwable());
144 }
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -0700145 if (mIsolated) {
146 Slog.i(TAG, "Ignoring request because this installer is isolated");
147 return false;
148 } else {
149 return true;
150 }
Jeff Sharkeyc8ddc2d2016-12-05 23:14:41 -0700151 }
152
Jeff Sharkey1c6f7232016-12-19 16:39:02 -0700153 public long createAppData(String uuid, String packageName, int userId, int flags, int appId,
Jeff Sharkeyc8ddc2d2016-12-05 23:14:41 -0700154 String seInfo, int targetSdkVersion) throws InstallerException {
Jeff Sharkey1c6f7232016-12-19 16:39:02 -0700155 if (!checkBeforeRemote()) return -1;
Jeff Sharkeyc8ddc2d2016-12-05 23:14:41 -0700156 try {
Jeff Sharkey1c6f7232016-12-19 16:39:02 -0700157 return mInstalld.createAppData(uuid, packageName, userId, flags, appId, seInfo,
Jeff Sharkey70b4d102016-12-05 11:19:28 -0700158 targetSdkVersion);
Jeff Sharkey447a3ac2016-12-12 10:15:37 -0700159 } catch (Exception e) {
Jeff Sharkey740f5232016-12-09 14:31:26 -0700160 throw InstallerException.from(e);
Jeff Sharkey70b4d102016-12-05 11:19:28 -0700161 }
Jeff Sharkey790a4ec2015-04-09 13:18:44 -0700162 }
163
Jeff Sharkey019ac852016-12-05 23:39:46 -0700164 public void restoreconAppData(String uuid, String packageName, int userId, int flags, int appId,
165 String seInfo) throws InstallerException {
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -0700166 if (!checkBeforeRemote()) return;
Jeff Sharkey019ac852016-12-05 23:39:46 -0700167 try {
168 mInstalld.restoreconAppData(uuid, packageName, userId, flags, appId, seInfo);
Jeff Sharkey447a3ac2016-12-12 10:15:37 -0700169 } catch (Exception e) {
Jeff Sharkey740f5232016-12-09 14:31:26 -0700170 throw InstallerException.from(e);
Jeff Sharkey019ac852016-12-05 23:39:46 -0700171 }
Jeff Sharkey790a4ec2015-04-09 13:18:44 -0700172 }
173
Jeff Sharkey019ac852016-12-05 23:39:46 -0700174 public void migrateAppData(String uuid, String packageName, int userId, int flags)
Jeff Sharkeye4697132016-02-06 19:46:15 -0700175 throws InstallerException {
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -0700176 if (!checkBeforeRemote()) return;
Jeff Sharkey019ac852016-12-05 23:39:46 -0700177 try {
178 mInstalld.migrateAppData(uuid, packageName, userId, flags);
Jeff Sharkey447a3ac2016-12-12 10:15:37 -0700179 } catch (Exception e) {
Jeff Sharkey740f5232016-12-09 14:31:26 -0700180 throw InstallerException.from(e);
Jeff Sharkey019ac852016-12-05 23:39:46 -0700181 }
Jeff Sharkeye4697132016-02-06 19:46:15 -0700182 }
183
Jeff Sharkey019ac852016-12-05 23:39:46 -0700184 public void clearAppData(String uuid, String packageName, int userId, int flags,
185 long ceDataInode) throws InstallerException {
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -0700186 if (!checkBeforeRemote()) return;
Jeff Sharkey019ac852016-12-05 23:39:46 -0700187 try {
188 mInstalld.clearAppData(uuid, packageName, userId, flags, ceDataInode);
Jeff Sharkey447a3ac2016-12-12 10:15:37 -0700189 } catch (Exception e) {
Jeff Sharkey740f5232016-12-09 14:31:26 -0700190 throw InstallerException.from(e);
Jeff Sharkey019ac852016-12-05 23:39:46 -0700191 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800192 }
193
Jeff Sharkey019ac852016-12-05 23:39:46 -0700194 public void destroyAppData(String uuid, String packageName, int userId, int flags,
195 long ceDataInode) throws InstallerException {
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -0700196 if (!checkBeforeRemote()) return;
Jeff Sharkey019ac852016-12-05 23:39:46 -0700197 try {
198 mInstalld.destroyAppData(uuid, packageName, userId, flags, ceDataInode);
Jeff Sharkey447a3ac2016-12-12 10:15:37 -0700199 } catch (Exception e) {
Jeff Sharkey740f5232016-12-09 14:31:26 -0700200 throw InstallerException.from(e);
Jeff Sharkey019ac852016-12-05 23:39:46 -0700201 }
Dave Allison0efbd9a2014-01-30 14:19:51 -0800202 }
203
Jeff Sharkey15662332017-04-03 16:41:29 -0600204 public void fixupAppData(String uuid, int flags) throws InstallerException {
205 if (!checkBeforeRemote()) return;
206 try {
207 mInstalld.fixupAppData(uuid, flags);
208 } catch (Exception e) {
209 throw InstallerException.from(e);
210 }
211 }
212
Jeff Sharkeyc8ddc2d2016-12-05 23:14:41 -0700213 public void moveCompleteApp(String fromUuid, String toUuid, String packageName,
214 String dataAppName, int appId, String seInfo, int targetSdkVersion)
Janis Danisevskisf3409742016-01-12 14:46:33 +0000215 throws InstallerException {
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -0700216 if (!checkBeforeRemote()) return;
Jeff Sharkeyc8ddc2d2016-12-05 23:14:41 -0700217 try {
218 mInstalld.moveCompleteApp(fromUuid, toUuid, packageName, dataAppName, appId, seInfo,
219 targetSdkVersion);
Jeff Sharkey447a3ac2016-12-12 10:15:37 -0700220 } catch (Exception e) {
Jeff Sharkey740f5232016-12-09 14:31:26 -0700221 throw InstallerException.from(e);
Jeff Sharkeyc8ddc2d2016-12-05 23:14:41 -0700222 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800223 }
224
Jeff Sharkey82ca9012017-01-08 17:06:58 -0700225 public void getAppSize(String uuid, String[] packageNames, int userId, int flags, int appId,
226 long[] ceDataInodes, String[] codePaths, PackageStats stats)
Jeff Sharkey5eb3eb52016-12-13 08:44:51 -0700227 throws InstallerException {
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -0700228 if (!checkBeforeRemote()) return;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800229 try {
Jeff Sharkey82ca9012017-01-08 17:06:58 -0700230 final long[] res = mInstalld.getAppSize(uuid, packageNames, userId, flags,
231 appId, ceDataInodes, codePaths);
Jeff Sharkey740f5232016-12-09 14:31:26 -0700232 stats.codeSize += res[0];
233 stats.dataSize += res[1];
234 stats.cacheSize += res[2];
Jeff Sharkey82ca9012017-01-08 17:06:58 -0700235 stats.externalCodeSize += res[3];
236 stats.externalDataSize += res[4];
237 stats.externalCacheSize += res[5];
238 } catch (Exception e) {
239 throw InstallerException.from(e);
240 }
241 }
242
243 public void getUserSize(String uuid, int userId, int flags, int[] appIds, PackageStats stats)
244 throws InstallerException {
245 if (!checkBeforeRemote()) return;
246 try {
247 final long[] res = mInstalld.getUserSize(uuid, userId, flags, appIds);
248 stats.codeSize += res[0];
249 stats.dataSize += res[1];
250 stats.cacheSize += res[2];
251 stats.externalCodeSize += res[3];
252 stats.externalDataSize += res[4];
253 stats.externalCacheSize += res[5];
254 } catch (Exception e) {
255 throw InstallerException.from(e);
256 }
257 }
258
Jeff Sharkey00347882017-04-17 16:44:12 -0600259 public long[] getExternalSize(String uuid, int userId, int flags, int[] appIds)
260 throws InstallerException {
Jeff Sharkey82ca9012017-01-08 17:06:58 -0700261 if (!checkBeforeRemote()) return new long[4];
262 try {
Jeff Sharkey00347882017-04-17 16:44:12 -0600263 return mInstalld.getExternalSize(uuid, userId, flags, appIds);
Jeff Sharkey447a3ac2016-12-12 10:15:37 -0700264 } catch (Exception e) {
Jeff Sharkey740f5232016-12-09 14:31:26 -0700265 throw InstallerException.from(e);
Jeff Sharkey42884192016-04-09 16:12:01 -0600266 }
267 }
268
Jeff Sharkey36ba0222017-01-18 12:11:31 -0700269 public void setAppQuota(String uuid, int userId, int appId, long cacheQuota)
270 throws InstallerException {
271 if (!checkBeforeRemote()) return;
272 try {
273 mInstalld.setAppQuota(uuid, userId, appId, cacheQuota);
274 } catch (Exception e) {
275 throw InstallerException.from(e);
276 }
277 }
278
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -0700279 public void dexopt(String apkPath, int uid, @Nullable String pkgName, String instructionSet,
Calin Juravledb4a79a2015-12-23 18:55:08 +0200280 int dexoptNeeded, @Nullable String outputPath, int dexFlags,
Calin Juravle811a75a2017-04-05 22:49:38 -0700281 String compilerFilter, @Nullable String volumeUuid, @Nullable String sharedLibraries,
282 @Nullable String seInfo)
Jeff Haoc7b94822016-03-16 15:56:07 -0700283 throws InstallerException {
Jeff Sharkeyfdeeeea2016-01-11 17:34:24 -0700284 assertValidInstructionSet(instructionSet);
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -0700285 if (!checkBeforeRemote()) return;
Jeff Sharkey740f5232016-12-09 14:31:26 -0700286 try {
287 mInstalld.dexopt(apkPath, uid, pkgName, instructionSet, dexoptNeeded, outputPath,
Calin Juravle811a75a2017-04-05 22:49:38 -0700288 dexFlags, compilerFilter, volumeUuid, sharedLibraries, seInfo);
Jeff Sharkey447a3ac2016-12-12 10:15:37 -0700289 } catch (Exception e) {
Jeff Sharkey740f5232016-12-09 14:31:26 -0700290 throw InstallerException.from(e);
291 }
Andreas Gampebdd30d82016-03-20 11:32:11 -0700292 }
293
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700294 public boolean mergeProfiles(int uid, String packageName) throws InstallerException {
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -0700295 if (!checkBeforeRemote()) return false;
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700296 try {
297 return mInstalld.mergeProfiles(uid, packageName);
Jeff Sharkey447a3ac2016-12-12 10:15:37 -0700298 } catch (Exception e) {
Jeff Sharkey740f5232016-12-09 14:31:26 -0700299 throw InstallerException.from(e);
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700300 }
Jeff Sharkeyfdeeeea2016-01-11 17:34:24 -0700301 }
302
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700303 public boolean dumpProfiles(int uid, String packageName, String codePaths)
David Sehra8777082016-05-24 15:25:23 -0700304 throws InstallerException {
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -0700305 if (!checkBeforeRemote()) return false;
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700306 try {
307 return mInstalld.dumpProfiles(uid, packageName, codePaths);
Jeff Sharkey447a3ac2016-12-12 10:15:37 -0700308 } catch (Exception e) {
Jeff Sharkey740f5232016-12-09 14:31:26 -0700309 throw InstallerException.from(e);
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700310 }
David Sehra8777082016-05-24 15:25:23 -0700311 }
312
Mathieu Chartier235845d2017-05-10 15:09:19 -0700313 public boolean copySystemProfile(String systemProfile, int uid, String packageName)
314 throws InstallerException {
315 if (!checkBeforeRemote()) return false;
316 try {
317 return mInstalld.copySystemProfile(systemProfile, uid, packageName);
318 } catch (Exception e) {
319 throw InstallerException.from(e);
320 }
321 }
322
Jeff Sharkeyfdeeeea2016-01-11 17:34:24 -0700323 public void idmap(String targetApkPath, String overlayApkPath, int uid)
324 throws InstallerException {
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -0700325 if (!checkBeforeRemote()) return;
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700326 try {
327 mInstalld.idmap(targetApkPath, overlayApkPath, uid);
Jeff Sharkey447a3ac2016-12-12 10:15:37 -0700328 } catch (Exception e) {
Jeff Sharkey740f5232016-12-09 14:31:26 -0700329 throw InstallerException.from(e);
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700330 }
Jeff Sharkeyfdeeeea2016-01-11 17:34:24 -0700331 }
332
MÃ¥rten Kongstad163826342016-06-02 09:35:09 +0200333 public void removeIdmap(String overlayApkPath) throws InstallerException {
334 if (!checkBeforeRemote()) return;
335 try {
336 mInstalld.removeIdmap(overlayApkPath);
337 } catch (Exception e) {
338 throw InstallerException.from(e);
339 }
340 }
341
Jeff Sharkeyfdeeeea2016-01-11 17:34:24 -0700342 public void rmdex(String codePath, String instructionSet) throws InstallerException {
343 assertValidInstructionSet(instructionSet);
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -0700344 if (!checkBeforeRemote()) return;
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700345 try {
346 mInstalld.rmdex(codePath, instructionSet);
Jeff Sharkey447a3ac2016-12-12 10:15:37 -0700347 } catch (Exception e) {
Jeff Sharkey740f5232016-12-09 14:31:26 -0700348 throw InstallerException.from(e);
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700349 }
Jeff Sharkeyfdeeeea2016-01-11 17:34:24 -0700350 }
351
352 public void rmPackageDir(String packageDir) throws InstallerException {
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -0700353 if (!checkBeforeRemote()) return;
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700354 try {
355 mInstalld.rmPackageDir(packageDir);
Jeff Sharkey447a3ac2016-12-12 10:15:37 -0700356 } catch (Exception e) {
Jeff Sharkey740f5232016-12-09 14:31:26 -0700357 throw InstallerException.from(e);
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700358 }
Jeff Sharkeyfdeeeea2016-01-11 17:34:24 -0700359 }
360
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700361 public void clearAppProfiles(String packageName) throws InstallerException {
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -0700362 if (!checkBeforeRemote()) return;
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700363 try {
364 mInstalld.clearAppProfiles(packageName);
Jeff Sharkey447a3ac2016-12-12 10:15:37 -0700365 } catch (Exception e) {
Jeff Sharkey740f5232016-12-09 14:31:26 -0700366 throw InstallerException.from(e);
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700367 }
Calin Juravled6d27e32016-03-23 13:59:18 +0000368 }
369
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700370 public void destroyAppProfiles(String packageName) throws InstallerException {
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -0700371 if (!checkBeforeRemote()) return;
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700372 try {
373 mInstalld.destroyAppProfiles(packageName);
Jeff Sharkey447a3ac2016-12-12 10:15:37 -0700374 } catch (Exception e) {
Jeff Sharkey740f5232016-12-09 14:31:26 -0700375 throw InstallerException.from(e);
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700376 }
David Brazdil9aa6db02016-03-08 12:57:12 +0000377 }
378
Jeff Sharkeyfcf1e552016-04-14 20:44:58 -0600379 public void createUserData(String uuid, int userId, int userSerial, int flags)
380 throws InstallerException {
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -0700381 if (!checkBeforeRemote()) return;
Jeff Sharkey019ac852016-12-05 23:39:46 -0700382 try {
383 mInstalld.createUserData(uuid, userId, userSerial, flags);
Jeff Sharkey447a3ac2016-12-12 10:15:37 -0700384 } catch (Exception e) {
Jeff Sharkey740f5232016-12-09 14:31:26 -0700385 throw InstallerException.from(e);
Jeff Sharkey019ac852016-12-05 23:39:46 -0700386 }
Jeff Sharkeyfdeeeea2016-01-11 17:34:24 -0700387 }
388
Jeff Sharkeyfcf1e552016-04-14 20:44:58 -0600389 public void destroyUserData(String uuid, int userId, int flags) throws InstallerException {
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -0700390 if (!checkBeforeRemote()) return;
Jeff Sharkey019ac852016-12-05 23:39:46 -0700391 try {
392 mInstalld.destroyUserData(uuid, userId, flags);
Jeff Sharkey447a3ac2016-12-12 10:15:37 -0700393 } catch (Exception e) {
Jeff Sharkey740f5232016-12-09 14:31:26 -0700394 throw InstallerException.from(e);
Jeff Sharkey019ac852016-12-05 23:39:46 -0700395 }
Jeff Sharkeyfdeeeea2016-01-11 17:34:24 -0700396 }
397
398 public void markBootComplete(String instructionSet) throws InstallerException {
399 assertValidInstructionSet(instructionSet);
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -0700400 if (!checkBeforeRemote()) return;
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700401 try {
402 mInstalld.markBootComplete(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
Jeff Sharkeyddff8072017-05-26 13:10:46 -0600408 public void freeCache(String uuid, long targetFreeBytes, long cacheReservedBytes, int flags)
409 throws InstallerException {
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -0700410 if (!checkBeforeRemote()) return;
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700411 try {
Jeff Sharkeyddff8072017-05-26 13:10:46 -0600412 mInstalld.freeCache(uuid, targetFreeBytes, cacheReservedBytes, flags);
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
Kenny Rootddbe50d2012-09-06 13:18:37 -0700418 /**
Jeff Sharkeyfdeeeea2016-01-11 17:34:24 -0700419 * Links the 32 bit native library directory in an application's data
420 * directory to the real location for backward compatibility. Note that no
421 * such symlink is created for 64 bit shared libraries.
Kenny Rootddbe50d2012-09-06 13:18:37 -0700422 */
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700423 public void linkNativeLibraryDirectory(String uuid, String packageName, String nativeLibPath32,
Jeff Sharkeyfdeeeea2016-01-11 17:34:24 -0700424 int userId) throws InstallerException {
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -0700425 if (!checkBeforeRemote()) return;
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700426 try {
427 mInstalld.linkNativeLibraryDirectory(uuid, packageName, nativeLibPath32, userId);
Jeff Sharkey447a3ac2016-12-12 10:15:37 -0700428 } catch (Exception e) {
Jeff Sharkey740f5232016-12-09 14:31:26 -0700429 throw InstallerException.from(e);
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700430 }
Kenny Root6a6b0072010-10-07 16:46:10 -0700431 }
Robert Craig43853432014-03-04 11:57:23 -0500432
Jeff Sharkeyfdeeeea2016-01-11 17:34:24 -0700433 public void createOatDir(String oatDir, String dexInstructionSet)
434 throws InstallerException {
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -0700435 if (!checkBeforeRemote()) return;
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700436 try {
437 mInstalld.createOatDir(oatDir, dexInstructionSet);
Jeff Sharkey447a3ac2016-12-12 10:15:37 -0700438 } catch (Exception e) {
Jeff Sharkey740f5232016-12-09 14:31:26 -0700439 throw InstallerException.from(e);
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700440 }
Jeff Sharkey790a4ec2015-04-09 13:18:44 -0700441 }
442
Jeff Sharkeyfdeeeea2016-01-11 17:34:24 -0700443 public void linkFile(String relativePath, String fromBase, String toBase)
444 throws InstallerException {
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -0700445 if (!checkBeforeRemote()) return;
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700446 try {
447 mInstalld.linkFile(relativePath, fromBase, toBase);
Jeff Sharkey447a3ac2016-12-12 10:15:37 -0700448 } catch (Exception e) {
Jeff Sharkey740f5232016-12-09 14:31:26 -0700449 throw InstallerException.from(e);
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700450 }
Robert Craig43853432014-03-04 11:57:23 -0500451 }
Narayan Kamath6c4b9de2014-08-08 12:44:12 +0100452
Andreas Gampeabcbe2f2016-02-26 11:25:36 -0800453 public void moveAb(String apkPath, String instructionSet, String outputPath)
454 throws InstallerException {
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -0700455 if (!checkBeforeRemote()) return;
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700456 try {
457 mInstalld.moveAb(apkPath, instructionSet, outputPath);
Jeff Sharkey447a3ac2016-12-12 10:15:37 -0700458 } catch (Exception e) {
Jeff Sharkey740f5232016-12-09 14:31:26 -0700459 throw InstallerException.from(e);
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700460 }
Andreas Gampeabcbe2f2016-02-26 11:25:36 -0800461 }
462
Andreas Gampe33c592d2016-09-09 17:08:53 -0700463 public void deleteOdex(String apkPath, String instructionSet, String outputPath)
464 throws InstallerException {
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -0700465 if (!checkBeforeRemote()) return;
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700466 try {
467 mInstalld.deleteOdex(apkPath, instructionSet, outputPath);
Jeff Sharkey447a3ac2016-12-12 10:15:37 -0700468 } catch (Exception e) {
Jeff Sharkey740f5232016-12-09 14:31:26 -0700469 throw InstallerException.from(e);
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700470 }
Andreas Gampe33c592d2016-09-09 17:08:53 -0700471 }
472
Calin Juravle1aa5f882017-01-25 01:05:50 -0800473 public boolean reconcileSecondaryDexFile(String apkPath, String packageName, int uid,
474 String[] isas, @Nullable String volumeUuid, int flags) throws InstallerException {
475 for (int i = 0; i < isas.length; i++) {
476 assertValidInstructionSet(isas[i]);
477 }
478 if (!checkBeforeRemote()) return false;
479 try {
480 return mInstalld.reconcileSecondaryDexFile(apkPath, packageName, uid, isas,
481 volumeUuid, flags);
482 } catch (Exception e) {
483 throw InstallerException.from(e);
484 }
485 }
486
Jeff Sharkey7d25faf2017-01-16 20:58:40 -0700487 public void invalidateMounts() throws InstallerException {
488 if (!checkBeforeRemote()) return;
489 try {
490 mInstalld.invalidateMounts();
491 } catch (Exception e) {
492 throw InstallerException.from(e);
493 }
494 }
495
Jeff Sharkeyd5d5e922017-02-21 10:51:23 -0700496 public boolean isQuotaSupported(String volumeUuid) throws InstallerException {
497 if (!checkBeforeRemote()) return false;
498 try {
499 return mInstalld.isQuotaSupported(volumeUuid);
500 } catch (Exception e) {
501 throw InstallerException.from(e);
502 }
503 }
504
Jeff Sharkeyfdeeeea2016-01-11 17:34:24 -0700505 private static void assertValidInstructionSet(String instructionSet)
506 throws InstallerException {
Narayan Kamath6c4b9de2014-08-08 12:44:12 +0100507 for (String abi : Build.SUPPORTED_ABIS) {
Jeff Sharkeyfdeeeea2016-01-11 17:34:24 -0700508 if (VMRuntime.getInstructionSet(abi).equals(instructionSet)) {
509 return;
Narayan Kamath6c4b9de2014-08-08 12:44:12 +0100510 }
511 }
Jeff Sharkeyfdeeeea2016-01-11 17:34:24 -0700512 throw new InstallerException("Invalid instruction set: " + instructionSet);
Narayan Kamath6c4b9de2014-08-08 12:44:12 +0100513 }
Jeff Sharkey740f5232016-12-09 14:31:26 -0700514
515 public static class InstallerException extends Exception {
516 public InstallerException(String detailMessage) {
517 super(detailMessage);
518 }
519
520 public static InstallerException from(Exception e) throws InstallerException {
Jeff Sharkey447a3ac2016-12-12 10:15:37 -0700521 throw new InstallerException(e.toString());
Jeff Sharkey740f5232016-12-09 14:31:26 -0700522 }
523 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800524}