blob: 4b3758d2e293ecab0880d88c2ca61c2fff457830 [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;
David Sehr2118ec42017-10-25 14:28:29 -070059 /** Indicates that dexopt is invoked from the background service. */
60 public static final int DEXOPT_IDLE_BACKGROUND_JOB = 1 << 9;
Todd Kennedyfa54ab72015-09-25 07:46:12 -070061
Jeff Sharkey47f71082016-02-01 17:03:54 -070062 // NOTE: keep in sync with installd
63 public static final int FLAG_CLEAR_CACHE_ONLY = 1 << 8;
64 public static final int FLAG_CLEAR_CODE_CACHE_ONLY = 1 << 9;
Jeff Sharkey5eb3eb52016-12-13 08:44:51 -070065 public static final int FLAG_USE_QUOTA = 1 << 12;
Jeff Sharkey458428e2017-02-22 11:47:15 -070066 public static final int FLAG_FREE_CACHE_V2 = 1 << 13;
67 public static final int FLAG_FREE_CACHE_V2_DEFY_QUOTA = 1 << 14;
68 public static final int FLAG_FREE_CACHE_NOOP = 1 << 15;
Jeff Sharkey15662332017-04-03 16:41:29 -060069 public static final int FLAG_FORCE = 1 << 16;
Jeff Sharkeyfdeeeea2016-01-11 17:34:24 -070070
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -070071 private final boolean mIsolated;
72
Jeff Sharkey740f5232016-12-09 14:31:26 -070073 private volatile IInstalld mInstalld;
Jeff Sharkeyc8ddc2d2016-12-05 23:14:41 -070074 private volatile Object mWarnIfHeld;
75
Jeff Brownb880d882014-02-10 19:47:07 -080076 public Installer(Context context) {
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -070077 this(context, false);
Jeff Brownb880d882014-02-10 19:47:07 -080078 }
79
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -070080 /**
81 * @param isolated indicates if this object should <em>not</em> connect to
82 * the real {@code installd}. All remote calls will be ignored
83 * unless you extend this class and intercept them.
84 */
85 public Installer(Context context, boolean isolated) {
Andreas Gamped15300c2016-06-23 20:27:12 -070086 super(context);
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -070087 mIsolated = isolated;
Andreas Gamped15300c2016-06-23 20:27:12 -070088 }
89
Jeff Sharkey8948c012015-11-03 12:33:54 -080090 /**
91 * Yell loudly if someone tries making future calls while holding a lock on
92 * the given object.
93 */
94 public void setWarnIfHeld(Object warnIfHeld) {
Jeff Sharkeyc8ddc2d2016-12-05 23:14:41 -070095 mWarnIfHeld = warnIfHeld;
Jeff Sharkey8948c012015-11-03 12:33:54 -080096 }
97
Jeff Brown6f357d32014-01-15 20:40:55 -080098 @Override
99 public void onStart() {
Jeff Sharkey740f5232016-12-09 14:31:26 -0700100 if (mIsolated) {
101 mInstalld = null;
102 } else {
Jeff Sharkey9f2f2182016-12-21 09:18:33 -0700103 connect();
104 }
105 }
106
107 private void connect() {
108 IBinder binder = ServiceManager.getService("installd");
109 if (binder != null) {
110 try {
111 binder.linkToDeath(new DeathRecipient() {
112 @Override
113 public void binderDied() {
114 Slog.w(TAG, "installd died; reconnecting");
115 connect();
116 }
117 }, 0);
118 } catch (RemoteException e) {
119 binder = null;
120 }
121 }
122
123 if (binder != null) {
124 mInstalld = IInstalld.Stub.asInterface(binder);
Jeff Sharkey82add8a2017-03-11 19:44:16 -0700125 try {
126 invalidateMounts();
127 } catch (InstallerException ignored) {
128 }
Jeff Sharkey9f2f2182016-12-21 09:18:33 -0700129 } else {
130 Slog.w(TAG, "installd not found; trying again");
131 BackgroundThread.getHandler().postDelayed(() -> {
132 connect();
133 }, DateUtils.SECOND_IN_MILLIS);
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -0700134 }
Jeff Brown6f357d32014-01-15 20:40:55 -0800135 }
136
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -0700137 /**
138 * Do several pre-flight checks before making a remote call.
139 *
140 * @return if the remote call should continue.
141 */
142 private boolean checkBeforeRemote() {
Jeff Sharkeyc8ddc2d2016-12-05 23:14:41 -0700143 if (mWarnIfHeld != null && Thread.holdsLock(mWarnIfHeld)) {
144 Slog.wtf(TAG, "Calling thread " + Thread.currentThread().getName() + " is holding 0x"
145 + Integer.toHexString(System.identityHashCode(mWarnIfHeld)), new Throwable());
146 }
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -0700147 if (mIsolated) {
148 Slog.i(TAG, "Ignoring request because this installer is isolated");
149 return false;
150 } else {
151 return true;
152 }
Jeff Sharkeyc8ddc2d2016-12-05 23:14:41 -0700153 }
154
Jeff Sharkey1c6f7232016-12-19 16:39:02 -0700155 public long createAppData(String uuid, String packageName, int userId, int flags, int appId,
Jeff Sharkeyc8ddc2d2016-12-05 23:14:41 -0700156 String seInfo, int targetSdkVersion) throws InstallerException {
Jeff Sharkey1c6f7232016-12-19 16:39:02 -0700157 if (!checkBeforeRemote()) return -1;
Jeff Sharkeyc8ddc2d2016-12-05 23:14:41 -0700158 try {
Jeff Sharkey1c6f7232016-12-19 16:39:02 -0700159 return mInstalld.createAppData(uuid, packageName, userId, flags, appId, seInfo,
Jeff Sharkey70b4d102016-12-05 11:19:28 -0700160 targetSdkVersion);
Jeff Sharkey447a3ac2016-12-12 10:15:37 -0700161 } catch (Exception e) {
Jeff Sharkey740f5232016-12-09 14:31:26 -0700162 throw InstallerException.from(e);
Jeff Sharkey70b4d102016-12-05 11:19:28 -0700163 }
Jeff Sharkey790a4ec2015-04-09 13:18:44 -0700164 }
165
Jeff Sharkey019ac852016-12-05 23:39:46 -0700166 public void restoreconAppData(String uuid, String packageName, int userId, int flags, int appId,
167 String seInfo) throws InstallerException {
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -0700168 if (!checkBeforeRemote()) return;
Jeff Sharkey019ac852016-12-05 23:39:46 -0700169 try {
170 mInstalld.restoreconAppData(uuid, packageName, userId, flags, appId, seInfo);
Jeff Sharkey447a3ac2016-12-12 10:15:37 -0700171 } catch (Exception e) {
Jeff Sharkey740f5232016-12-09 14:31:26 -0700172 throw InstallerException.from(e);
Jeff Sharkey019ac852016-12-05 23:39:46 -0700173 }
Jeff Sharkey790a4ec2015-04-09 13:18:44 -0700174 }
175
Jeff Sharkey019ac852016-12-05 23:39:46 -0700176 public void migrateAppData(String uuid, String packageName, int userId, int flags)
Jeff Sharkeye4697132016-02-06 19:46:15 -0700177 throws InstallerException {
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -0700178 if (!checkBeforeRemote()) return;
Jeff Sharkey019ac852016-12-05 23:39:46 -0700179 try {
180 mInstalld.migrateAppData(uuid, packageName, userId, flags);
Jeff Sharkey447a3ac2016-12-12 10:15:37 -0700181 } catch (Exception e) {
Jeff Sharkey740f5232016-12-09 14:31:26 -0700182 throw InstallerException.from(e);
Jeff Sharkey019ac852016-12-05 23:39:46 -0700183 }
Jeff Sharkeye4697132016-02-06 19:46:15 -0700184 }
185
Jeff Sharkey019ac852016-12-05 23:39:46 -0700186 public void clearAppData(String uuid, String packageName, int userId, int flags,
187 long ceDataInode) throws InstallerException {
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -0700188 if (!checkBeforeRemote()) return;
Jeff Sharkey019ac852016-12-05 23:39:46 -0700189 try {
190 mInstalld.clearAppData(uuid, packageName, userId, flags, ceDataInode);
Jeff Sharkey447a3ac2016-12-12 10:15:37 -0700191 } catch (Exception e) {
Jeff Sharkey740f5232016-12-09 14:31:26 -0700192 throw InstallerException.from(e);
Jeff Sharkey019ac852016-12-05 23:39:46 -0700193 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800194 }
195
Jeff Sharkey019ac852016-12-05 23:39:46 -0700196 public void destroyAppData(String uuid, String packageName, int userId, int flags,
197 long ceDataInode) throws InstallerException {
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -0700198 if (!checkBeforeRemote()) return;
Jeff Sharkey019ac852016-12-05 23:39:46 -0700199 try {
200 mInstalld.destroyAppData(uuid, packageName, userId, flags, ceDataInode);
Jeff Sharkey447a3ac2016-12-12 10:15:37 -0700201 } catch (Exception e) {
Jeff Sharkey740f5232016-12-09 14:31:26 -0700202 throw InstallerException.from(e);
Jeff Sharkey019ac852016-12-05 23:39:46 -0700203 }
Dave Allison0efbd9a2014-01-30 14:19:51 -0800204 }
205
Jeff Sharkey15662332017-04-03 16:41:29 -0600206 public void fixupAppData(String uuid, int flags) throws InstallerException {
207 if (!checkBeforeRemote()) return;
208 try {
209 mInstalld.fixupAppData(uuid, flags);
210 } catch (Exception e) {
211 throw InstallerException.from(e);
212 }
213 }
214
Jeff Sharkeyc8ddc2d2016-12-05 23:14:41 -0700215 public void moveCompleteApp(String fromUuid, String toUuid, String packageName,
216 String dataAppName, int appId, String seInfo, int targetSdkVersion)
Janis Danisevskisf3409742016-01-12 14:46:33 +0000217 throws InstallerException {
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -0700218 if (!checkBeforeRemote()) return;
Jeff Sharkeyc8ddc2d2016-12-05 23:14:41 -0700219 try {
220 mInstalld.moveCompleteApp(fromUuid, toUuid, packageName, dataAppName, appId, seInfo,
221 targetSdkVersion);
Jeff Sharkey447a3ac2016-12-12 10:15:37 -0700222 } catch (Exception e) {
Jeff Sharkey740f5232016-12-09 14:31:26 -0700223 throw InstallerException.from(e);
Jeff Sharkeyc8ddc2d2016-12-05 23:14:41 -0700224 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800225 }
226
Jeff Sharkey82ca9012017-01-08 17:06:58 -0700227 public void getAppSize(String uuid, String[] packageNames, int userId, int flags, int appId,
228 long[] ceDataInodes, String[] codePaths, PackageStats stats)
Jeff Sharkey5eb3eb52016-12-13 08:44:51 -0700229 throws InstallerException {
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -0700230 if (!checkBeforeRemote()) return;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800231 try {
Jeff Sharkey82ca9012017-01-08 17:06:58 -0700232 final long[] res = mInstalld.getAppSize(uuid, packageNames, userId, flags,
233 appId, ceDataInodes, codePaths);
Jeff Sharkey740f5232016-12-09 14:31:26 -0700234 stats.codeSize += res[0];
235 stats.dataSize += res[1];
236 stats.cacheSize += res[2];
Jeff Sharkey82ca9012017-01-08 17:06:58 -0700237 stats.externalCodeSize += res[3];
238 stats.externalDataSize += res[4];
239 stats.externalCacheSize += res[5];
240 } catch (Exception e) {
241 throw InstallerException.from(e);
242 }
243 }
244
245 public void getUserSize(String uuid, int userId, int flags, int[] appIds, PackageStats stats)
246 throws InstallerException {
247 if (!checkBeforeRemote()) return;
248 try {
249 final long[] res = mInstalld.getUserSize(uuid, userId, flags, appIds);
250 stats.codeSize += res[0];
251 stats.dataSize += res[1];
252 stats.cacheSize += res[2];
253 stats.externalCodeSize += res[3];
254 stats.externalDataSize += res[4];
255 stats.externalCacheSize += res[5];
256 } catch (Exception e) {
257 throw InstallerException.from(e);
258 }
259 }
260
Jeff Sharkey00347882017-04-17 16:44:12 -0600261 public long[] getExternalSize(String uuid, int userId, int flags, int[] appIds)
262 throws InstallerException {
Jeff Sharkeyc8b29ac2017-07-06 11:29:06 -0600263 if (!checkBeforeRemote()) return new long[6];
Jeff Sharkey82ca9012017-01-08 17:06:58 -0700264 try {
Jeff Sharkey00347882017-04-17 16:44:12 -0600265 return mInstalld.getExternalSize(uuid, userId, flags, appIds);
Jeff Sharkey447a3ac2016-12-12 10:15:37 -0700266 } catch (Exception e) {
Jeff Sharkey740f5232016-12-09 14:31:26 -0700267 throw InstallerException.from(e);
Jeff Sharkey42884192016-04-09 16:12:01 -0600268 }
269 }
270
Jeff Sharkey36ba0222017-01-18 12:11:31 -0700271 public void setAppQuota(String uuid, int userId, int appId, long cacheQuota)
272 throws InstallerException {
273 if (!checkBeforeRemote()) return;
274 try {
275 mInstalld.setAppQuota(uuid, userId, appId, cacheQuota);
276 } catch (Exception e) {
277 throw InstallerException.from(e);
278 }
279 }
280
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -0700281 public void dexopt(String apkPath, int uid, @Nullable String pkgName, String instructionSet,
Calin Juravledb4a79a2015-12-23 18:55:08 +0200282 int dexoptNeeded, @Nullable String outputPath, int dexFlags,
Calin Juravle811a75a2017-04-05 22:49:38 -0700283 String compilerFilter, @Nullable String volumeUuid, @Nullable String sharedLibraries,
David Brazdil3d44ed02018-01-16 20:01:47 +0000284 @Nullable String seInfo, boolean downgrade, int targetSdkVersion)
Jeff Haoc7b94822016-03-16 15:56:07 -0700285 throws InstallerException {
Jeff Sharkeyfdeeeea2016-01-11 17:34:24 -0700286 assertValidInstructionSet(instructionSet);
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -0700287 if (!checkBeforeRemote()) return;
Jeff Sharkey740f5232016-12-09 14:31:26 -0700288 try {
289 mInstalld.dexopt(apkPath, uid, pkgName, instructionSet, dexoptNeeded, outputPath,
David Brazdil3d44ed02018-01-16 20:01:47 +0000290 dexFlags, compilerFilter, volumeUuid, sharedLibraries, seInfo, downgrade,
291 targetSdkVersion);
Jeff Sharkey447a3ac2016-12-12 10:15:37 -0700292 } catch (Exception e) {
Jeff Sharkey740f5232016-12-09 14:31:26 -0700293 throw InstallerException.from(e);
294 }
Andreas Gampebdd30d82016-03-20 11:32:11 -0700295 }
296
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700297 public boolean mergeProfiles(int uid, String packageName) throws InstallerException {
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -0700298 if (!checkBeforeRemote()) return false;
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700299 try {
300 return mInstalld.mergeProfiles(uid, packageName);
Jeff Sharkey447a3ac2016-12-12 10:15:37 -0700301 } catch (Exception e) {
Jeff Sharkey740f5232016-12-09 14:31:26 -0700302 throw InstallerException.from(e);
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700303 }
Jeff Sharkeyfdeeeea2016-01-11 17:34:24 -0700304 }
305
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700306 public boolean dumpProfiles(int uid, String packageName, String codePaths)
David Sehra8777082016-05-24 15:25:23 -0700307 throws InstallerException {
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -0700308 if (!checkBeforeRemote()) return false;
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700309 try {
310 return mInstalld.dumpProfiles(uid, packageName, codePaths);
Jeff Sharkey447a3ac2016-12-12 10:15:37 -0700311 } catch (Exception e) {
Jeff Sharkey740f5232016-12-09 14:31:26 -0700312 throw InstallerException.from(e);
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700313 }
David Sehra8777082016-05-24 15:25:23 -0700314 }
315
Mathieu Chartier235845d2017-05-10 15:09:19 -0700316 public boolean copySystemProfile(String systemProfile, int uid, String packageName)
317 throws InstallerException {
318 if (!checkBeforeRemote()) return false;
319 try {
320 return mInstalld.copySystemProfile(systemProfile, uid, packageName);
321 } catch (Exception e) {
322 throw InstallerException.from(e);
323 }
324 }
325
Jeff Sharkeyfdeeeea2016-01-11 17:34:24 -0700326 public void idmap(String targetApkPath, String overlayApkPath, int uid)
327 throws InstallerException {
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -0700328 if (!checkBeforeRemote()) return;
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700329 try {
330 mInstalld.idmap(targetApkPath, overlayApkPath, uid);
Jeff Sharkey447a3ac2016-12-12 10:15:37 -0700331 } catch (Exception e) {
Jeff Sharkey740f5232016-12-09 14:31:26 -0700332 throw InstallerException.from(e);
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700333 }
Jeff Sharkeyfdeeeea2016-01-11 17:34:24 -0700334 }
335
MÃ¥rten Kongstad163826342016-06-02 09:35:09 +0200336 public void removeIdmap(String overlayApkPath) throws InstallerException {
337 if (!checkBeforeRemote()) return;
338 try {
339 mInstalld.removeIdmap(overlayApkPath);
340 } catch (Exception e) {
341 throw InstallerException.from(e);
342 }
343 }
344
Jeff Sharkeyfdeeeea2016-01-11 17:34:24 -0700345 public void rmdex(String codePath, String instructionSet) throws InstallerException {
346 assertValidInstructionSet(instructionSet);
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -0700347 if (!checkBeforeRemote()) return;
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700348 try {
349 mInstalld.rmdex(codePath, instructionSet);
Jeff Sharkey447a3ac2016-12-12 10:15:37 -0700350 } catch (Exception e) {
Jeff Sharkey740f5232016-12-09 14:31:26 -0700351 throw InstallerException.from(e);
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700352 }
Jeff Sharkeyfdeeeea2016-01-11 17:34:24 -0700353 }
354
355 public void rmPackageDir(String packageDir) throws InstallerException {
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -0700356 if (!checkBeforeRemote()) return;
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700357 try {
358 mInstalld.rmPackageDir(packageDir);
Jeff Sharkey447a3ac2016-12-12 10:15:37 -0700359 } catch (Exception e) {
Jeff Sharkey740f5232016-12-09 14:31:26 -0700360 throw InstallerException.from(e);
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700361 }
Jeff Sharkeyfdeeeea2016-01-11 17:34:24 -0700362 }
363
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700364 public void clearAppProfiles(String packageName) throws InstallerException {
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -0700365 if (!checkBeforeRemote()) return;
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700366 try {
367 mInstalld.clearAppProfiles(packageName);
Jeff Sharkey447a3ac2016-12-12 10:15:37 -0700368 } catch (Exception e) {
Jeff Sharkey740f5232016-12-09 14:31:26 -0700369 throw InstallerException.from(e);
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700370 }
Calin Juravled6d27e32016-03-23 13:59:18 +0000371 }
372
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700373 public void destroyAppProfiles(String packageName) throws InstallerException {
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -0700374 if (!checkBeforeRemote()) return;
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700375 try {
376 mInstalld.destroyAppProfiles(packageName);
Jeff Sharkey447a3ac2016-12-12 10:15:37 -0700377 } catch (Exception e) {
Jeff Sharkey740f5232016-12-09 14:31:26 -0700378 throw InstallerException.from(e);
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700379 }
David Brazdil9aa6db02016-03-08 12:57:12 +0000380 }
381
Jeff Sharkeyfcf1e552016-04-14 20:44:58 -0600382 public void createUserData(String uuid, int userId, int userSerial, int flags)
383 throws InstallerException {
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -0700384 if (!checkBeforeRemote()) return;
Jeff Sharkey019ac852016-12-05 23:39:46 -0700385 try {
386 mInstalld.createUserData(uuid, userId, userSerial, flags);
Jeff Sharkey447a3ac2016-12-12 10:15:37 -0700387 } catch (Exception e) {
Jeff Sharkey740f5232016-12-09 14:31:26 -0700388 throw InstallerException.from(e);
Jeff Sharkey019ac852016-12-05 23:39:46 -0700389 }
Jeff Sharkeyfdeeeea2016-01-11 17:34:24 -0700390 }
391
Jeff Sharkeyfcf1e552016-04-14 20:44:58 -0600392 public void destroyUserData(String uuid, int userId, int flags) throws InstallerException {
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -0700393 if (!checkBeforeRemote()) return;
Jeff Sharkey019ac852016-12-05 23:39:46 -0700394 try {
395 mInstalld.destroyUserData(uuid, userId, flags);
Jeff Sharkey447a3ac2016-12-12 10:15:37 -0700396 } catch (Exception e) {
Jeff Sharkey740f5232016-12-09 14:31:26 -0700397 throw InstallerException.from(e);
Jeff Sharkey019ac852016-12-05 23:39:46 -0700398 }
Jeff Sharkeyfdeeeea2016-01-11 17:34:24 -0700399 }
400
401 public void markBootComplete(String instructionSet) throws InstallerException {
402 assertValidInstructionSet(instructionSet);
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -0700403 if (!checkBeforeRemote()) return;
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700404 try {
405 mInstalld.markBootComplete(instructionSet);
Jeff Sharkey447a3ac2016-12-12 10:15:37 -0700406 } catch (Exception e) {
Jeff Sharkey740f5232016-12-09 14:31:26 -0700407 throw InstallerException.from(e);
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700408 }
Jeff Sharkeyfdeeeea2016-01-11 17:34:24 -0700409 }
410
Jeff Sharkeyddff8072017-05-26 13:10:46 -0600411 public void freeCache(String uuid, long targetFreeBytes, long cacheReservedBytes, int flags)
412 throws InstallerException {
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -0700413 if (!checkBeforeRemote()) return;
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700414 try {
Jeff Sharkeyddff8072017-05-26 13:10:46 -0600415 mInstalld.freeCache(uuid, targetFreeBytes, cacheReservedBytes, flags);
Jeff Sharkey447a3ac2016-12-12 10:15:37 -0700416 } catch (Exception e) {
Jeff Sharkey740f5232016-12-09 14:31:26 -0700417 throw InstallerException.from(e);
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700418 }
Jeff Sharkeyfdeeeea2016-01-11 17:34:24 -0700419 }
420
Kenny Rootddbe50d2012-09-06 13:18:37 -0700421 /**
Jeff Sharkeyfdeeeea2016-01-11 17:34:24 -0700422 * Links the 32 bit native library directory in an application's data
423 * directory to the real location for backward compatibility. Note that no
424 * such symlink is created for 64 bit shared libraries.
Kenny Rootddbe50d2012-09-06 13:18:37 -0700425 */
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700426 public void linkNativeLibraryDirectory(String uuid, String packageName, String nativeLibPath32,
Jeff Sharkeyfdeeeea2016-01-11 17:34:24 -0700427 int userId) throws InstallerException {
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -0700428 if (!checkBeforeRemote()) return;
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700429 try {
430 mInstalld.linkNativeLibraryDirectory(uuid, packageName, nativeLibPath32, userId);
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 }
Kenny Root6a6b0072010-10-07 16:46:10 -0700434 }
Robert Craig43853432014-03-04 11:57:23 -0500435
Jeff Sharkeyfdeeeea2016-01-11 17:34:24 -0700436 public void createOatDir(String oatDir, String dexInstructionSet)
437 throws InstallerException {
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -0700438 if (!checkBeforeRemote()) return;
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700439 try {
440 mInstalld.createOatDir(oatDir, dexInstructionSet);
Jeff Sharkey447a3ac2016-12-12 10:15:37 -0700441 } catch (Exception e) {
Jeff Sharkey740f5232016-12-09 14:31:26 -0700442 throw InstallerException.from(e);
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700443 }
Jeff Sharkey790a4ec2015-04-09 13:18:44 -0700444 }
445
Jeff Sharkeyfdeeeea2016-01-11 17:34:24 -0700446 public void linkFile(String relativePath, String fromBase, String toBase)
447 throws InstallerException {
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -0700448 if (!checkBeforeRemote()) return;
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700449 try {
450 mInstalld.linkFile(relativePath, fromBase, toBase);
Jeff Sharkey447a3ac2016-12-12 10:15:37 -0700451 } catch (Exception e) {
Jeff Sharkey740f5232016-12-09 14:31:26 -0700452 throw InstallerException.from(e);
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700453 }
Robert Craig43853432014-03-04 11:57:23 -0500454 }
Narayan Kamath6c4b9de2014-08-08 12:44:12 +0100455
Andreas Gampeabcbe2f2016-02-26 11:25:36 -0800456 public void moveAb(String apkPath, String instructionSet, String outputPath)
457 throws InstallerException {
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -0700458 if (!checkBeforeRemote()) return;
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700459 try {
460 mInstalld.moveAb(apkPath, instructionSet, outputPath);
Jeff Sharkey447a3ac2016-12-12 10:15:37 -0700461 } catch (Exception e) {
Jeff Sharkey740f5232016-12-09 14:31:26 -0700462 throw InstallerException.from(e);
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700463 }
Andreas Gampeabcbe2f2016-02-26 11:25:36 -0800464 }
465
Andreas Gampe33c592d2016-09-09 17:08:53 -0700466 public void deleteOdex(String apkPath, String instructionSet, String outputPath)
467 throws InstallerException {
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -0700468 if (!checkBeforeRemote()) return;
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700469 try {
470 mInstalld.deleteOdex(apkPath, instructionSet, outputPath);
Jeff Sharkey447a3ac2016-12-12 10:15:37 -0700471 } catch (Exception e) {
Jeff Sharkey740f5232016-12-09 14:31:26 -0700472 throw InstallerException.from(e);
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700473 }
Andreas Gampe33c592d2016-09-09 17:08:53 -0700474 }
475
Calin Juravle1aa5f882017-01-25 01:05:50 -0800476 public boolean reconcileSecondaryDexFile(String apkPath, String packageName, int uid,
477 String[] isas, @Nullable String volumeUuid, int flags) throws InstallerException {
478 for (int i = 0; i < isas.length; i++) {
479 assertValidInstructionSet(isas[i]);
480 }
481 if (!checkBeforeRemote()) return false;
482 try {
483 return mInstalld.reconcileSecondaryDexFile(apkPath, packageName, uid, isas,
484 volumeUuid, flags);
485 } catch (Exception e) {
486 throw InstallerException.from(e);
487 }
488 }
489
Alan Stokesa0023602017-10-16 12:31:44 +0100490 public byte[] hashSecondaryDexFile(String dexPath, String packageName, int uid,
491 @Nullable String volumeUuid, int flags) throws InstallerException {
492 if (!checkBeforeRemote()) return new byte[0];
493 try {
494 return mInstalld.hashSecondaryDexFile(dexPath, packageName, uid, volumeUuid, flags);
495 } catch (Exception e) {
496 throw InstallerException.from(e);
497 }
498 }
499
Calin Juravlefd9f8ae2017-11-29 18:26:55 -0800500 public boolean createProfileSnapshot(int appId, String packageName, String codePath)
501 throws InstallerException {
502 if (!checkBeforeRemote()) return false;
503 try {
Calin Juravle388cd5f2017-12-05 12:33:32 -0800504 return mInstalld.createProfileSnapshot(appId, packageName, codePath);
Calin Juravlefd9f8ae2017-11-29 18:26:55 -0800505 } catch (Exception e) {
506 throw InstallerException.from(e);
507 }
508 }
509
510 public void destroyProfileSnapshot(String packageName, String codePath)
511 throws InstallerException {
512 if (!checkBeforeRemote()) return;
513 try {
514 mInstalld.destroyProfileSnapshot(packageName, codePath);
515 } catch (Exception e) {
516 throw InstallerException.from(e);
517 }
518 }
519
Jeff Sharkey7d25faf2017-01-16 20:58:40 -0700520 public void invalidateMounts() throws InstallerException {
521 if (!checkBeforeRemote()) return;
522 try {
523 mInstalld.invalidateMounts();
524 } catch (Exception e) {
525 throw InstallerException.from(e);
526 }
527 }
528
Jeff Sharkeyd5d5e922017-02-21 10:51:23 -0700529 public boolean isQuotaSupported(String volumeUuid) throws InstallerException {
530 if (!checkBeforeRemote()) return false;
531 try {
532 return mInstalld.isQuotaSupported(volumeUuid);
533 } catch (Exception e) {
534 throw InstallerException.from(e);
535 }
536 }
537
Jeff Sharkeyfdeeeea2016-01-11 17:34:24 -0700538 private static void assertValidInstructionSet(String instructionSet)
539 throws InstallerException {
Narayan Kamath6c4b9de2014-08-08 12:44:12 +0100540 for (String abi : Build.SUPPORTED_ABIS) {
Jeff Sharkeyfdeeeea2016-01-11 17:34:24 -0700541 if (VMRuntime.getInstructionSet(abi).equals(instructionSet)) {
542 return;
Narayan Kamath6c4b9de2014-08-08 12:44:12 +0100543 }
544 }
Jeff Sharkeyfdeeeea2016-01-11 17:34:24 -0700545 throw new InstallerException("Invalid instruction set: " + instructionSet);
Narayan Kamath6c4b9de2014-08-08 12:44:12 +0100546 }
Jeff Sharkey740f5232016-12-09 14:31:26 -0700547
548 public static class InstallerException extends Exception {
549 public InstallerException(String detailMessage) {
550 super(detailMessage);
551 }
552
553 public static InstallerException from(Exception e) throws InstallerException {
Jeff Sharkey447a3ac2016-12-12 10:15:37 -0700554 throw new InstallerException(e.toString());
Jeff Sharkey740f5232016-12-09 14:31:26 -0700555 }
556 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800557}