blob: 98249dd126341dff247eda376a6d9df632c2f4f2 [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 run in VM safe mode */
Andreas Gampebdd30d82016-03-20 11:32:11 -070046 public static final int DEXOPT_SAFEMODE = 1 << 2;
Todd Kennedyfa54ab72015-09-25 07:46:12 -070047 /** Application wants to allow debugging of its code */
Andreas Gampebdd30d82016-03-20 11:32:11 -070048 public static final int DEXOPT_DEBUGGABLE = 1 << 3;
Todd Kennedyfa54ab72015-09-25 07:46:12 -070049 /** The system boot has finished */
Andreas Gampebdd30d82016-03-20 11:32:11 -070050 public static final int DEXOPT_BOOTCOMPLETE = 1 << 4;
51 /** Hint that the dexopt type is profile-guided. */
52 public static final int DEXOPT_PROFILE_GUIDED = 1 << 5;
Todd Kennedyfa54ab72015-09-25 07:46:12 -070053
Jeff Sharkey47f71082016-02-01 17:03:54 -070054 // NOTE: keep in sync with installd
55 public static final int FLAG_CLEAR_CACHE_ONLY = 1 << 8;
56 public static final int FLAG_CLEAR_CODE_CACHE_ONLY = 1 << 9;
Jeff Sharkey5eb3eb52016-12-13 08:44:51 -070057 public static final int FLAG_USE_QUOTA = 1 << 12;
Jeff Sharkeyfdeeeea2016-01-11 17:34:24 -070058
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -070059 private final boolean mIsolated;
60
Jeff Sharkey740f5232016-12-09 14:31:26 -070061 private volatile IInstalld mInstalld;
Jeff Sharkeyc8ddc2d2016-12-05 23:14:41 -070062 private volatile Object mWarnIfHeld;
63
Jeff Brownb880d882014-02-10 19:47:07 -080064 public Installer(Context context) {
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -070065 this(context, false);
Jeff Brownb880d882014-02-10 19:47:07 -080066 }
67
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -070068 /**
69 * @param isolated indicates if this object should <em>not</em> connect to
70 * the real {@code installd}. All remote calls will be ignored
71 * unless you extend this class and intercept them.
72 */
73 public Installer(Context context, boolean isolated) {
Andreas Gamped15300c2016-06-23 20:27:12 -070074 super(context);
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -070075 mIsolated = isolated;
Andreas Gamped15300c2016-06-23 20:27:12 -070076 }
77
Jeff Sharkey8948c012015-11-03 12:33:54 -080078 /**
79 * Yell loudly if someone tries making future calls while holding a lock on
80 * the given object.
81 */
82 public void setWarnIfHeld(Object warnIfHeld) {
Jeff Sharkeyc8ddc2d2016-12-05 23:14:41 -070083 mWarnIfHeld = warnIfHeld;
Jeff Sharkey8948c012015-11-03 12:33:54 -080084 }
85
Jeff Brown6f357d32014-01-15 20:40:55 -080086 @Override
87 public void onStart() {
Jeff Sharkey740f5232016-12-09 14:31:26 -070088 if (mIsolated) {
89 mInstalld = null;
90 } else {
Jeff Sharkey9f2f2182016-12-21 09:18:33 -070091 connect();
92 }
93 }
94
95 private void connect() {
96 IBinder binder = ServiceManager.getService("installd");
97 if (binder != null) {
98 try {
99 binder.linkToDeath(new DeathRecipient() {
100 @Override
101 public void binderDied() {
102 Slog.w(TAG, "installd died; reconnecting");
103 connect();
104 }
105 }, 0);
106 } catch (RemoteException e) {
107 binder = null;
108 }
109 }
110
111 if (binder != null) {
112 mInstalld = IInstalld.Stub.asInterface(binder);
113 } else {
114 Slog.w(TAG, "installd not found; trying again");
115 BackgroundThread.getHandler().postDelayed(() -> {
116 connect();
117 }, DateUtils.SECOND_IN_MILLIS);
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -0700118 }
Jeff Brown6f357d32014-01-15 20:40:55 -0800119 }
120
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -0700121 /**
122 * Do several pre-flight checks before making a remote call.
123 *
124 * @return if the remote call should continue.
125 */
126 private boolean checkBeforeRemote() {
Jeff Sharkeyc8ddc2d2016-12-05 23:14:41 -0700127 if (mWarnIfHeld != null && Thread.holdsLock(mWarnIfHeld)) {
128 Slog.wtf(TAG, "Calling thread " + Thread.currentThread().getName() + " is holding 0x"
129 + Integer.toHexString(System.identityHashCode(mWarnIfHeld)), new Throwable());
130 }
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -0700131 if (mIsolated) {
132 Slog.i(TAG, "Ignoring request because this installer is isolated");
133 return false;
134 } else {
135 return true;
136 }
Jeff Sharkeyc8ddc2d2016-12-05 23:14:41 -0700137 }
138
Jeff Sharkey1c6f7232016-12-19 16:39:02 -0700139 public long createAppData(String uuid, String packageName, int userId, int flags, int appId,
Jeff Sharkeyc8ddc2d2016-12-05 23:14:41 -0700140 String seInfo, int targetSdkVersion) throws InstallerException {
Jeff Sharkey1c6f7232016-12-19 16:39:02 -0700141 if (!checkBeforeRemote()) return -1;
Jeff Sharkeyc8ddc2d2016-12-05 23:14:41 -0700142 try {
Jeff Sharkey1c6f7232016-12-19 16:39:02 -0700143 return mInstalld.createAppData(uuid, packageName, userId, flags, appId, seInfo,
Jeff Sharkey70b4d102016-12-05 11:19:28 -0700144 targetSdkVersion);
Jeff Sharkey447a3ac2016-12-12 10:15:37 -0700145 } catch (Exception e) {
Jeff Sharkey740f5232016-12-09 14:31:26 -0700146 throw InstallerException.from(e);
Jeff Sharkey70b4d102016-12-05 11:19:28 -0700147 }
Jeff Sharkey790a4ec2015-04-09 13:18:44 -0700148 }
149
Jeff Sharkey019ac852016-12-05 23:39:46 -0700150 public void restoreconAppData(String uuid, String packageName, int userId, int flags, int appId,
151 String seInfo) throws InstallerException {
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -0700152 if (!checkBeforeRemote()) return;
Jeff Sharkey019ac852016-12-05 23:39:46 -0700153 try {
154 mInstalld.restoreconAppData(uuid, packageName, userId, flags, appId, seInfo);
Jeff Sharkey447a3ac2016-12-12 10:15:37 -0700155 } catch (Exception e) {
Jeff Sharkey740f5232016-12-09 14:31:26 -0700156 throw InstallerException.from(e);
Jeff Sharkey019ac852016-12-05 23:39:46 -0700157 }
Jeff Sharkey790a4ec2015-04-09 13:18:44 -0700158 }
159
Jeff Sharkey019ac852016-12-05 23:39:46 -0700160 public void migrateAppData(String uuid, String packageName, int userId, int flags)
Jeff Sharkeye4697132016-02-06 19:46:15 -0700161 throws InstallerException {
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -0700162 if (!checkBeforeRemote()) return;
Jeff Sharkey019ac852016-12-05 23:39:46 -0700163 try {
164 mInstalld.migrateAppData(uuid, packageName, userId, flags);
Jeff Sharkey447a3ac2016-12-12 10:15:37 -0700165 } catch (Exception e) {
Jeff Sharkey740f5232016-12-09 14:31:26 -0700166 throw InstallerException.from(e);
Jeff Sharkey019ac852016-12-05 23:39:46 -0700167 }
Jeff Sharkeye4697132016-02-06 19:46:15 -0700168 }
169
Jeff Sharkey019ac852016-12-05 23:39:46 -0700170 public void clearAppData(String uuid, String packageName, int userId, int flags,
171 long ceDataInode) throws InstallerException {
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -0700172 if (!checkBeforeRemote()) return;
Jeff Sharkey019ac852016-12-05 23:39:46 -0700173 try {
174 mInstalld.clearAppData(uuid, packageName, userId, flags, ceDataInode);
Jeff Sharkey447a3ac2016-12-12 10:15:37 -0700175 } catch (Exception e) {
Jeff Sharkey740f5232016-12-09 14:31:26 -0700176 throw InstallerException.from(e);
Jeff Sharkey019ac852016-12-05 23:39:46 -0700177 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800178 }
179
Jeff Sharkey019ac852016-12-05 23:39:46 -0700180 public void destroyAppData(String uuid, String packageName, int userId, int flags,
181 long ceDataInode) throws InstallerException {
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -0700182 if (!checkBeforeRemote()) return;
Jeff Sharkey019ac852016-12-05 23:39:46 -0700183 try {
184 mInstalld.destroyAppData(uuid, packageName, userId, flags, ceDataInode);
Jeff Sharkey447a3ac2016-12-12 10:15:37 -0700185 } catch (Exception e) {
Jeff Sharkey740f5232016-12-09 14:31:26 -0700186 throw InstallerException.from(e);
Jeff Sharkey019ac852016-12-05 23:39:46 -0700187 }
Dave Allison0efbd9a2014-01-30 14:19:51 -0800188 }
189
Jeff Sharkeyc8ddc2d2016-12-05 23:14:41 -0700190 public void moveCompleteApp(String fromUuid, String toUuid, String packageName,
191 String dataAppName, int appId, String seInfo, int targetSdkVersion)
Janis Danisevskisf3409742016-01-12 14:46:33 +0000192 throws InstallerException {
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -0700193 if (!checkBeforeRemote()) return;
Jeff Sharkeyc8ddc2d2016-12-05 23:14:41 -0700194 try {
195 mInstalld.moveCompleteApp(fromUuid, toUuid, packageName, dataAppName, appId, seInfo,
196 targetSdkVersion);
Jeff Sharkey447a3ac2016-12-12 10:15:37 -0700197 } catch (Exception e) {
Jeff Sharkey740f5232016-12-09 14:31:26 -0700198 throw InstallerException.from(e);
Jeff Sharkeyc8ddc2d2016-12-05 23:14:41 -0700199 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800200 }
201
Jeff Sharkey82ca9012017-01-08 17:06:58 -0700202 public void getAppSize(String uuid, String[] packageNames, int userId, int flags, int appId,
203 long[] ceDataInodes, String[] codePaths, PackageStats stats)
Jeff Sharkey5eb3eb52016-12-13 08:44:51 -0700204 throws InstallerException {
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -0700205 if (!checkBeforeRemote()) return;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800206 try {
Jeff Sharkey82ca9012017-01-08 17:06:58 -0700207 final long[] res = mInstalld.getAppSize(uuid, packageNames, userId, flags,
208 appId, ceDataInodes, codePaths);
Jeff Sharkey740f5232016-12-09 14:31:26 -0700209 stats.codeSize += res[0];
210 stats.dataSize += res[1];
211 stats.cacheSize += res[2];
Jeff Sharkey82ca9012017-01-08 17:06:58 -0700212 stats.externalCodeSize += res[3];
213 stats.externalDataSize += res[4];
214 stats.externalCacheSize += res[5];
215 } catch (Exception e) {
216 throw InstallerException.from(e);
217 }
218 }
219
220 public void getUserSize(String uuid, int userId, int flags, int[] appIds, PackageStats stats)
221 throws InstallerException {
222 if (!checkBeforeRemote()) return;
223 try {
224 final long[] res = mInstalld.getUserSize(uuid, userId, flags, appIds);
225 stats.codeSize += res[0];
226 stats.dataSize += res[1];
227 stats.cacheSize += res[2];
228 stats.externalCodeSize += res[3];
229 stats.externalDataSize += res[4];
230 stats.externalCacheSize += res[5];
231 } catch (Exception e) {
232 throw InstallerException.from(e);
233 }
234 }
235
236 public long[] getExternalSize(String uuid, int userId, int flags) throws InstallerException {
237 if (!checkBeforeRemote()) return new long[4];
238 try {
239 return mInstalld.getExternalSize(uuid, userId, flags);
Jeff Sharkey447a3ac2016-12-12 10:15:37 -0700240 } catch (Exception e) {
Jeff Sharkey740f5232016-12-09 14:31:26 -0700241 throw InstallerException.from(e);
Jeff Sharkey42884192016-04-09 16:12:01 -0600242 }
243 }
244
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -0700245 public void dexopt(String apkPath, int uid, @Nullable String pkgName, String instructionSet,
Calin Juravledb4a79a2015-12-23 18:55:08 +0200246 int dexoptNeeded, @Nullable String outputPath, int dexFlags,
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -0700247 String compilerFilter, @Nullable String volumeUuid, @Nullable String sharedLibraries)
Jeff Haoc7b94822016-03-16 15:56:07 -0700248 throws InstallerException {
Jeff Sharkeyfdeeeea2016-01-11 17:34:24 -0700249 assertValidInstructionSet(instructionSet);
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -0700250 if (!checkBeforeRemote()) return;
Jeff Sharkey740f5232016-12-09 14:31:26 -0700251 try {
252 mInstalld.dexopt(apkPath, uid, pkgName, instructionSet, dexoptNeeded, outputPath,
253 dexFlags, compilerFilter, volumeUuid, sharedLibraries);
Jeff Sharkey447a3ac2016-12-12 10:15:37 -0700254 } catch (Exception e) {
Jeff Sharkey740f5232016-12-09 14:31:26 -0700255 throw InstallerException.from(e);
256 }
Andreas Gampebdd30d82016-03-20 11:32:11 -0700257 }
258
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700259 public boolean mergeProfiles(int uid, String packageName) throws InstallerException {
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -0700260 if (!checkBeforeRemote()) return false;
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700261 try {
262 return mInstalld.mergeProfiles(uid, packageName);
Jeff Sharkey447a3ac2016-12-12 10:15:37 -0700263 } catch (Exception e) {
Jeff Sharkey740f5232016-12-09 14:31:26 -0700264 throw InstallerException.from(e);
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700265 }
Jeff Sharkeyfdeeeea2016-01-11 17:34:24 -0700266 }
267
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700268 public boolean dumpProfiles(int uid, String packageName, String codePaths)
David Sehra8777082016-05-24 15:25:23 -0700269 throws InstallerException {
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -0700270 if (!checkBeforeRemote()) return false;
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700271 try {
272 return mInstalld.dumpProfiles(uid, packageName, codePaths);
Jeff Sharkey447a3ac2016-12-12 10:15:37 -0700273 } catch (Exception e) {
Jeff Sharkey740f5232016-12-09 14:31:26 -0700274 throw InstallerException.from(e);
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700275 }
David Sehra8777082016-05-24 15:25:23 -0700276 }
277
Jeff Sharkeyfdeeeea2016-01-11 17:34:24 -0700278 public void idmap(String targetApkPath, String overlayApkPath, int uid)
279 throws InstallerException {
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -0700280 if (!checkBeforeRemote()) return;
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700281 try {
282 mInstalld.idmap(targetApkPath, overlayApkPath, uid);
Jeff Sharkey447a3ac2016-12-12 10:15:37 -0700283 } catch (Exception e) {
Jeff Sharkey740f5232016-12-09 14:31:26 -0700284 throw InstallerException.from(e);
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700285 }
Jeff Sharkeyfdeeeea2016-01-11 17:34:24 -0700286 }
287
288 public void rmdex(String codePath, String instructionSet) throws InstallerException {
289 assertValidInstructionSet(instructionSet);
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -0700290 if (!checkBeforeRemote()) return;
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700291 try {
292 mInstalld.rmdex(codePath, instructionSet);
Jeff Sharkey447a3ac2016-12-12 10:15:37 -0700293 } catch (Exception e) {
Jeff Sharkey740f5232016-12-09 14:31:26 -0700294 throw InstallerException.from(e);
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700295 }
Jeff Sharkeyfdeeeea2016-01-11 17:34:24 -0700296 }
297
298 public void rmPackageDir(String packageDir) throws InstallerException {
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -0700299 if (!checkBeforeRemote()) return;
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700300 try {
301 mInstalld.rmPackageDir(packageDir);
Jeff Sharkey447a3ac2016-12-12 10:15:37 -0700302 } catch (Exception e) {
Jeff Sharkey740f5232016-12-09 14:31:26 -0700303 throw InstallerException.from(e);
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700304 }
Jeff Sharkeyfdeeeea2016-01-11 17:34:24 -0700305 }
306
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700307 public void clearAppProfiles(String packageName) throws InstallerException {
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -0700308 if (!checkBeforeRemote()) return;
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700309 try {
310 mInstalld.clearAppProfiles(packageName);
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 }
Calin Juravled6d27e32016-03-23 13:59:18 +0000314 }
315
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700316 public void destroyAppProfiles(String packageName) throws InstallerException {
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -0700317 if (!checkBeforeRemote()) return;
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700318 try {
319 mInstalld.destroyAppProfiles(packageName);
Jeff Sharkey447a3ac2016-12-12 10:15:37 -0700320 } catch (Exception e) {
Jeff Sharkey740f5232016-12-09 14:31:26 -0700321 throw InstallerException.from(e);
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700322 }
David Brazdil9aa6db02016-03-08 12:57:12 +0000323 }
324
Jeff Sharkeyfcf1e552016-04-14 20:44:58 -0600325 public void createUserData(String uuid, int userId, int userSerial, int flags)
326 throws InstallerException {
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -0700327 if (!checkBeforeRemote()) return;
Jeff Sharkey019ac852016-12-05 23:39:46 -0700328 try {
329 mInstalld.createUserData(uuid, userId, userSerial, flags);
Jeff Sharkey447a3ac2016-12-12 10:15:37 -0700330 } catch (Exception e) {
Jeff Sharkey740f5232016-12-09 14:31:26 -0700331 throw InstallerException.from(e);
Jeff Sharkey019ac852016-12-05 23:39:46 -0700332 }
Jeff Sharkeyfdeeeea2016-01-11 17:34:24 -0700333 }
334
Jeff Sharkeyfcf1e552016-04-14 20:44:58 -0600335 public void destroyUserData(String uuid, int userId, int flags) throws InstallerException {
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -0700336 if (!checkBeforeRemote()) return;
Jeff Sharkey019ac852016-12-05 23:39:46 -0700337 try {
338 mInstalld.destroyUserData(uuid, userId, flags);
Jeff Sharkey447a3ac2016-12-12 10:15:37 -0700339 } catch (Exception e) {
Jeff Sharkey740f5232016-12-09 14:31:26 -0700340 throw InstallerException.from(e);
Jeff Sharkey019ac852016-12-05 23:39:46 -0700341 }
Jeff Sharkeyfdeeeea2016-01-11 17:34:24 -0700342 }
343
344 public void markBootComplete(String instructionSet) throws InstallerException {
345 assertValidInstructionSet(instructionSet);
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -0700346 if (!checkBeforeRemote()) return;
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700347 try {
348 mInstalld.markBootComplete(instructionSet);
Jeff Sharkey447a3ac2016-12-12 10:15:37 -0700349 } catch (Exception e) {
Jeff Sharkey740f5232016-12-09 14:31:26 -0700350 throw InstallerException.from(e);
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700351 }
Jeff Sharkeyfdeeeea2016-01-11 17:34:24 -0700352 }
353
354 public void freeCache(String uuid, long freeStorageSize) throws InstallerException {
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -0700355 if (!checkBeforeRemote()) return;
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700356 try {
357 mInstalld.freeCache(uuid, freeStorageSize);
Jeff Sharkey447a3ac2016-12-12 10:15:37 -0700358 } catch (Exception e) {
Jeff Sharkey740f5232016-12-09 14:31:26 -0700359 throw InstallerException.from(e);
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700360 }
Jeff Sharkeyfdeeeea2016-01-11 17:34:24 -0700361 }
362
Kenny Rootddbe50d2012-09-06 13:18:37 -0700363 /**
Jeff Sharkeyfdeeeea2016-01-11 17:34:24 -0700364 * Links the 32 bit native library directory in an application's data
365 * directory to the real location for backward compatibility. Note that no
366 * such symlink is created for 64 bit shared libraries.
Kenny Rootddbe50d2012-09-06 13:18:37 -0700367 */
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700368 public void linkNativeLibraryDirectory(String uuid, String packageName, String nativeLibPath32,
Jeff Sharkeyfdeeeea2016-01-11 17:34:24 -0700369 int userId) throws InstallerException {
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -0700370 if (!checkBeforeRemote()) return;
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700371 try {
372 mInstalld.linkNativeLibraryDirectory(uuid, packageName, nativeLibPath32, userId);
Jeff Sharkey447a3ac2016-12-12 10:15:37 -0700373 } catch (Exception e) {
Jeff Sharkey740f5232016-12-09 14:31:26 -0700374 throw InstallerException.from(e);
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700375 }
Kenny Root6a6b0072010-10-07 16:46:10 -0700376 }
Robert Craig43853432014-03-04 11:57:23 -0500377
Jeff Sharkeyfdeeeea2016-01-11 17:34:24 -0700378 public void createOatDir(String oatDir, String dexInstructionSet)
379 throws InstallerException {
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -0700380 if (!checkBeforeRemote()) return;
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700381 try {
382 mInstalld.createOatDir(oatDir, dexInstructionSet);
Jeff Sharkey447a3ac2016-12-12 10:15:37 -0700383 } catch (Exception e) {
Jeff Sharkey740f5232016-12-09 14:31:26 -0700384 throw InstallerException.from(e);
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700385 }
Jeff Sharkey790a4ec2015-04-09 13:18:44 -0700386 }
387
Jeff Sharkeyfdeeeea2016-01-11 17:34:24 -0700388 public void linkFile(String relativePath, String fromBase, String toBase)
389 throws InstallerException {
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -0700390 if (!checkBeforeRemote()) return;
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700391 try {
392 mInstalld.linkFile(relativePath, fromBase, toBase);
Jeff Sharkey447a3ac2016-12-12 10:15:37 -0700393 } catch (Exception e) {
Jeff Sharkey740f5232016-12-09 14:31:26 -0700394 throw InstallerException.from(e);
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700395 }
Robert Craig43853432014-03-04 11:57:23 -0500396 }
Narayan Kamath6c4b9de2014-08-08 12:44:12 +0100397
Andreas Gampeabcbe2f2016-02-26 11:25:36 -0800398 public void moveAb(String apkPath, String instructionSet, String outputPath)
399 throws InstallerException {
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -0700400 if (!checkBeforeRemote()) return;
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700401 try {
402 mInstalld.moveAb(apkPath, instructionSet, outputPath);
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 }
Andreas Gampeabcbe2f2016-02-26 11:25:36 -0800406 }
407
Andreas Gampe33c592d2016-09-09 17:08:53 -0700408 public void deleteOdex(String apkPath, String instructionSet, String outputPath)
409 throws InstallerException {
Jeff Sharkeyc98c7bc2016-12-07 14:57:34 -0700410 if (!checkBeforeRemote()) return;
Jeff Sharkeyc24fa022016-12-07 10:37:47 -0700411 try {
412 mInstalld.deleteOdex(apkPath, instructionSet, outputPath);
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 }
Andreas Gampe33c592d2016-09-09 17:08:53 -0700416 }
417
Jeff Sharkeyfdeeeea2016-01-11 17:34:24 -0700418 private static void assertValidInstructionSet(String instructionSet)
419 throws InstallerException {
Narayan Kamath6c4b9de2014-08-08 12:44:12 +0100420 for (String abi : Build.SUPPORTED_ABIS) {
Jeff Sharkeyfdeeeea2016-01-11 17:34:24 -0700421 if (VMRuntime.getInstructionSet(abi).equals(instructionSet)) {
422 return;
Narayan Kamath6c4b9de2014-08-08 12:44:12 +0100423 }
424 }
Jeff Sharkeyfdeeeea2016-01-11 17:34:24 -0700425 throw new InstallerException("Invalid instruction set: " + instructionSet);
Narayan Kamath6c4b9de2014-08-08 12:44:12 +0100426 }
Jeff Sharkey740f5232016-12-09 14:31:26 -0700427
428 public static class InstallerException extends Exception {
429 public InstallerException(String detailMessage) {
430 super(detailMessage);
431 }
432
433 public static InstallerException from(Exception e) throws InstallerException {
Jeff Sharkey447a3ac2016-12-12 10:15:37 -0700434 throw new InstallerException(e.toString());
Jeff Sharkey740f5232016-12-09 14:31:26 -0700435 }
436 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800437}