blob: 1476e6ea8904b61d20b677e3c4d6ed16cce5e7f2 [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 Sharkey47f71082016-02-01 17:03:54 -070023import android.os.storage.StorageManager;
Joe Onorato8a9b2202010-02-26 18:56:32 -080024import android.util.Slog;
Jeff Sharkey790a4ec2015-04-09 13:18:44 -070025
Narayan Kamath29564cd2014-08-07 10:57:40 +010026import com.android.internal.os.InstallerConnection;
Jeff Sharkeyfdeeeea2016-01-11 17:34:24 -070027import com.android.internal.os.InstallerConnection.InstallerException;
Narayan Kamath29564cd2014-08-07 10:57:40 +010028import com.android.server.SystemService;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080029
Jeff Sharkeyfdeeeea2016-01-11 17:34:24 -070030import dalvik.system.VMRuntime;
31
Jeff Brown6f357d32014-01-15 20:40:55 -080032public final class Installer extends SystemService {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080033 private static final String TAG = "Installer";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080034
Todd Kennedyfa54ab72015-09-25 07:46:12 -070035 /* ***************************************************************************
36 * IMPORTANT: These values are passed to native code. Keep them in sync with
37 * frameworks/native/cmds/installd/installd.h
38 * **************************************************************************/
39 /** Application should be visible to everyone */
40 public static final int DEXOPT_PUBLIC = 1 << 1;
41 /** Application wants to run in VM safe mode */
42 public static final int DEXOPT_SAFEMODE = 1 << 2;
43 /** Application wants to allow debugging of its code */
44 public static final int DEXOPT_DEBUGGABLE = 1 << 3;
45 /** The system boot has finished */
46 public static final int DEXOPT_BOOTCOMPLETE = 1 << 4;
David Brazdila0e10432016-01-20 14:04:40 +000047 /** Do not compile, only extract bytecode into an OAT file */
48 public static final int DEXOPT_EXTRACTONLY = 1 << 5;
Andreas Gampea8908752015-11-10 08:58:14 -080049 /** This is an OTA update dexopt */
50 public static final int DEXOPT_OTA = 1 << 6;
Todd Kennedyfa54ab72015-09-25 07:46:12 -070051
Jeff Sharkey47f71082016-02-01 17:03:54 -070052 // NOTE: keep in sync with installd
53 public static final int FLAG_CLEAR_CACHE_ONLY = 1 << 8;
54 public static final int FLAG_CLEAR_CODE_CACHE_ONLY = 1 << 9;
Jeff Sharkeyfdeeeea2016-01-11 17:34:24 -070055
Narayan Kamath29564cd2014-08-07 10:57:40 +010056 private final InstallerConnection mInstaller;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080057
Jeff Brownb880d882014-02-10 19:47:07 -080058 public Installer(Context context) {
59 super(context);
Narayan Kamath29564cd2014-08-07 10:57:40 +010060 mInstaller = new InstallerConnection();
Jeff Brownb880d882014-02-10 19:47:07 -080061 }
62
Jeff Sharkey8948c012015-11-03 12:33:54 -080063 /**
64 * Yell loudly if someone tries making future calls while holding a lock on
65 * the given object.
66 */
67 public void setWarnIfHeld(Object warnIfHeld) {
68 mInstaller.setWarnIfHeld(warnIfHeld);
69 }
70
Jeff Brown6f357d32014-01-15 20:40:55 -080071 @Override
72 public void onStart() {
73 Slog.i(TAG, "Waiting for installd to be ready.");
Makoto Onukic8a2cfe2015-06-23 16:33:48 -070074 mInstaller.waitForConnection();
Jeff Brown6f357d32014-01-15 20:40:55 -080075 }
76
Jeff Sharkeyfdeeeea2016-01-11 17:34:24 -070077 public void createAppData(String uuid, String pkgname, int userid, int flags, int appid,
Janis Danisevskisf3409742016-01-12 14:46:33 +000078 String seinfo, int targetSdkVersion) throws InstallerException {
79 mInstaller.execute("create_app_data", uuid, pkgname, userid, flags, appid, seinfo,
80 targetSdkVersion);
Jeff Sharkey790a4ec2015-04-09 13:18:44 -070081 }
82
Jeff Sharkeyfdeeeea2016-01-11 17:34:24 -070083 public void restoreconAppData(String uuid, String pkgname, int userid, int flags, int appid,
84 String seinfo) throws InstallerException {
85 mInstaller.execute("restorecon_app_data", uuid, pkgname, userid, flags, appid,
86 seinfo);
Jeff Sharkey790a4ec2015-04-09 13:18:44 -070087 }
88
Jeff Sharkeye4697132016-02-06 19:46:15 -070089 public void migrateAppData(String uuid, String pkgname, int userid, int flags)
90 throws InstallerException {
91 mInstaller.execute("migrate_app_data", uuid, pkgname, userid, flags);
92 }
93
Jeff Sharkeyfdeeeea2016-01-11 17:34:24 -070094 public void clearAppData(String uuid, String pkgname, int userid, int flags)
95 throws InstallerException {
96 mInstaller.execute("clear_app_data", uuid, pkgname, userid, flags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080097 }
98
Jeff Sharkeyfdeeeea2016-01-11 17:34:24 -070099 public void destroyAppData(String uuid, String pkgname, int userid, int flags)
100 throws InstallerException {
101 mInstaller.execute("destroy_app_data", uuid, pkgname, userid, flags);
Dave Allison0efbd9a2014-01-30 14:19:51 -0800102 }
103
Jeff Sharkeyfdeeeea2016-01-11 17:34:24 -0700104 public void moveCompleteApp(String from_uuid, String to_uuid, String package_name,
Janis Danisevskisf3409742016-01-12 14:46:33 +0000105 String data_app_name, int appid, String seinfo, int targetSdkVersion)
106 throws InstallerException {
Jeff Sharkeyfdeeeea2016-01-11 17:34:24 -0700107 mInstaller.execute("move_complete_app", from_uuid, to_uuid, package_name,
Janis Danisevskisf3409742016-01-12 14:46:33 +0000108 data_app_name, appid, seinfo, targetSdkVersion);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800109 }
110
Jeff Sharkeyfdeeeea2016-01-11 17:34:24 -0700111 public void getAppSize(String uuid, String pkgname, int userid, int flags, String apkPath,
Jeff Sharkey790a4ec2015-04-09 13:18:44 -0700112 String libDirPath, String fwdLockApkPath, String asecPath, String[] instructionSets,
Jeff Sharkeyfdeeeea2016-01-11 17:34:24 -0700113 PackageStats pStats) throws InstallerException {
Narayan Kamath6c4b9de2014-08-08 12:44:12 +0100114 for (String instructionSet : instructionSets) {
Jeff Sharkeyfdeeeea2016-01-11 17:34:24 -0700115 assertValidInstructionSet(instructionSet);
Narayan Kamath6c4b9de2014-08-08 12:44:12 +0100116 }
117
Narayan Kamathff110bd2014-07-04 18:30:45 +0100118 // TODO: Extend getSizeInfo to look at the full subdirectory tree,
119 // not just the first level.
Narayan Kamathff110bd2014-07-04 18:30:45 +0100120 // TODO: Extend getSizeInfo to look at *all* instrution sets, not
121 // just the primary.
Jeff Sharkeyfdeeeea2016-01-11 17:34:24 -0700122 final String rawRes = mInstaller.executeForResult("get_app_size", uuid, pkgname, userid,
123 flags, apkPath, libDirPath, fwdLockApkPath, asecPath, instructionSets[0]);
124 final String res[] = rawRes.split(" ");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800125
Dianne Hackborn292f8bc2011-06-27 16:27:41 -0700126 if ((res == null) || (res.length != 5)) {
Jeff Sharkeyfdeeeea2016-01-11 17:34:24 -0700127 throw new InstallerException("Invalid size result: " + rawRes);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800128 }
129 try {
130 pStats.codeSize = Long.parseLong(res[1]);
131 pStats.dataSize = Long.parseLong(res[2]);
132 pStats.cacheSize = Long.parseLong(res[3]);
Dianne Hackborn292f8bc2011-06-27 16:27:41 -0700133 pStats.externalCodeSize = Long.parseLong(res[4]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800134 } catch (NumberFormatException e) {
Jeff Sharkeyfdeeeea2016-01-11 17:34:24 -0700135 throw new InstallerException("Invalid size result: " + rawRes);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800136 }
Kenny Rootcf0b38c2011-03-22 14:17:59 -0700137 }
Dianne Hackbornb858dfd2010-02-02 10:49:14 -0800138
Jeff Sharkeyfdeeeea2016-01-11 17:34:24 -0700139 public void dexopt(String apkPath, int uid, String instructionSet, int dexoptNeeded,
Calin Juravledb4a79a2015-12-23 18:55:08 +0200140 int dexFlags, String volumeUuid, boolean useProfiles) throws InstallerException {
Jeff Sharkeyfdeeeea2016-01-11 17:34:24 -0700141 assertValidInstructionSet(instructionSet);
Calin Juravledb4a79a2015-12-23 18:55:08 +0200142 mInstaller.dexopt(apkPath, uid, instructionSet, dexoptNeeded, dexFlags,
143 volumeUuid, useProfiles);
Dianne Hackbornb858dfd2010-02-02 10:49:14 -0800144 }
Kenny Root6a6b0072010-10-07 16:46:10 -0700145
Jeff Sharkeyfdeeeea2016-01-11 17:34:24 -0700146 public void dexopt(String apkPath, int uid, String pkgName, String instructionSet,
Calin Juravledb4a79a2015-12-23 18:55:08 +0200147 int dexoptNeeded, @Nullable String outputPath, int dexFlags,
148 String volumeUuid, boolean useProfiles)
Jeff Sharkeyfdeeeea2016-01-11 17:34:24 -0700149 throws InstallerException {
150 assertValidInstructionSet(instructionSet);
151 mInstaller.dexopt(apkPath, uid, pkgName, instructionSet, dexoptNeeded,
Calin Juravledb4a79a2015-12-23 18:55:08 +0200152 outputPath, dexFlags, volumeUuid, useProfiles);
Jeff Sharkeyfdeeeea2016-01-11 17:34:24 -0700153 }
154
155 public void idmap(String targetApkPath, String overlayApkPath, int uid)
156 throws InstallerException {
157 mInstaller.execute("idmap", targetApkPath, overlayApkPath, uid);
158 }
159
160 public void rmdex(String codePath, String instructionSet) throws InstallerException {
161 assertValidInstructionSet(instructionSet);
162 mInstaller.execute("rmdex", codePath, instructionSet);
163 }
164
165 public void rmPackageDir(String packageDir) throws InstallerException {
166 mInstaller.execute("rmpackagedir", packageDir);
167 }
168
169 public void createUserConfig(int userid) throws InstallerException {
170 mInstaller.execute("mkuserconfig", userid);
171 }
172
173 public void removeUserDataDirs(String uuid, int userid) throws InstallerException {
174 mInstaller.execute("rmuser", uuid, userid);
175 }
176
177 public void markBootComplete(String instructionSet) throws InstallerException {
178 assertValidInstructionSet(instructionSet);
179 mInstaller.execute("markbootcomplete", instructionSet);
180 }
181
182 public void freeCache(String uuid, long freeStorageSize) throws InstallerException {
183 mInstaller.execute("freecache", uuid, freeStorageSize);
184 }
185
Kenny Rootddbe50d2012-09-06 13:18:37 -0700186 /**
Jeff Sharkeyfdeeeea2016-01-11 17:34:24 -0700187 * Links the 32 bit native library directory in an application's data
188 * directory to the real location for backward compatibility. Note that no
189 * such symlink is created for 64 bit shared libraries.
Kenny Rootddbe50d2012-09-06 13:18:37 -0700190 */
Jeff Sharkeyfdeeeea2016-01-11 17:34:24 -0700191 public void linkNativeLibraryDirectory(String uuid, String dataPath, String nativeLibPath32,
192 int userId) throws InstallerException {
193 mInstaller.execute("linklib", uuid, dataPath, nativeLibPath32, userId);
Kenny Root6a6b0072010-10-07 16:46:10 -0700194 }
Robert Craig43853432014-03-04 11:57:23 -0500195
Jeff Sharkeyfdeeeea2016-01-11 17:34:24 -0700196 public void createOatDir(String oatDir, String dexInstructionSet)
197 throws InstallerException {
198 mInstaller.execute("createoatdir", oatDir, dexInstructionSet);
Jeff Sharkey790a4ec2015-04-09 13:18:44 -0700199 }
200
Jeff Sharkeyfdeeeea2016-01-11 17:34:24 -0700201 public void linkFile(String relativePath, String fromBase, String toBase)
202 throws InstallerException {
203 mInstaller.execute("linkfile", relativePath, fromBase, toBase);
Robert Craig43853432014-03-04 11:57:23 -0500204 }
Narayan Kamath6c4b9de2014-08-08 12:44:12 +0100205
Jeff Sharkeyfdeeeea2016-01-11 17:34:24 -0700206 private static void assertValidInstructionSet(String instructionSet)
207 throws InstallerException {
Narayan Kamath6c4b9de2014-08-08 12:44:12 +0100208 for (String abi : Build.SUPPORTED_ABIS) {
Jeff Sharkeyfdeeeea2016-01-11 17:34:24 -0700209 if (VMRuntime.getInstructionSet(abi).equals(instructionSet)) {
210 return;
Narayan Kamath6c4b9de2014-08-08 12:44:12 +0100211 }
212 }
Jeff Sharkeyfdeeeea2016-01-11 17:34:24 -0700213 throw new InstallerException("Invalid instruction set: " + instructionSet);
Narayan Kamath6c4b9de2014-08-08 12:44:12 +0100214 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800215}