The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 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 Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 17 | package com.android.server.pm; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 18 | |
Fyodor Kupolov | b94c165 | 2015-03-03 12:25:30 -0800 | [diff] [blame] | 19 | import android.annotation.Nullable; |
Jeff Brown | b880d88 | 2014-02-10 19:47:07 -0800 | [diff] [blame] | 20 | import android.content.Context; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 21 | import android.content.pm.PackageStats; |
Narayan Kamath | 29564cd | 2014-08-07 10:57:40 +0100 | [diff] [blame] | 22 | import android.os.Build; |
Jeff Sharkey | 47f7108 | 2016-02-01 17:03:54 -0700 | [diff] [blame] | 23 | import android.os.storage.StorageManager; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 24 | import android.util.Slog; |
Jeff Sharkey | 790a4ec | 2015-04-09 13:18:44 -0700 | [diff] [blame] | 25 | |
Narayan Kamath | 29564cd | 2014-08-07 10:57:40 +0100 | [diff] [blame] | 26 | import com.android.internal.os.InstallerConnection; |
Jeff Sharkey | fdeeeea | 2016-01-11 17:34:24 -0700 | [diff] [blame] | 27 | import com.android.internal.os.InstallerConnection.InstallerException; |
Narayan Kamath | 29564cd | 2014-08-07 10:57:40 +0100 | [diff] [blame] | 28 | import com.android.server.SystemService; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 29 | |
Jeff Sharkey | fdeeeea | 2016-01-11 17:34:24 -0700 | [diff] [blame] | 30 | import dalvik.system.VMRuntime; |
| 31 | |
Jeff Brown | 6f357d3 | 2014-01-15 20:40:55 -0800 | [diff] [blame] | 32 | public final class Installer extends SystemService { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 33 | private static final String TAG = "Installer"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 34 | |
Todd Kennedy | fa54ab7 | 2015-09-25 07:46:12 -0700 | [diff] [blame] | 35 | /* *************************************************************************** |
| 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 Brazdil | a0e1043 | 2016-01-20 14:04:40 +0000 | [diff] [blame] | 47 | /** Do not compile, only extract bytecode into an OAT file */ |
| 48 | public static final int DEXOPT_EXTRACTONLY = 1 << 5; |
Andreas Gampe | a890875 | 2015-11-10 08:58:14 -0800 | [diff] [blame] | 49 | /** This is an OTA update dexopt */ |
| 50 | public static final int DEXOPT_OTA = 1 << 6; |
Todd Kennedy | fa54ab7 | 2015-09-25 07:46:12 -0700 | [diff] [blame] | 51 | |
Jeff Sharkey | 47f7108 | 2016-02-01 17:03:54 -0700 | [diff] [blame] | 52 | // 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 Sharkey | fdeeeea | 2016-01-11 17:34:24 -0700 | [diff] [blame] | 55 | |
Narayan Kamath | 29564cd | 2014-08-07 10:57:40 +0100 | [diff] [blame] | 56 | private final InstallerConnection mInstaller; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 57 | |
Jeff Brown | b880d88 | 2014-02-10 19:47:07 -0800 | [diff] [blame] | 58 | public Installer(Context context) { |
| 59 | super(context); |
Narayan Kamath | 29564cd | 2014-08-07 10:57:40 +0100 | [diff] [blame] | 60 | mInstaller = new InstallerConnection(); |
Jeff Brown | b880d88 | 2014-02-10 19:47:07 -0800 | [diff] [blame] | 61 | } |
| 62 | |
Jeff Sharkey | 8948c01 | 2015-11-03 12:33:54 -0800 | [diff] [blame] | 63 | /** |
| 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 Brown | 6f357d3 | 2014-01-15 20:40:55 -0800 | [diff] [blame] | 71 | @Override |
| 72 | public void onStart() { |
| 73 | Slog.i(TAG, "Waiting for installd to be ready."); |
Makoto Onuki | c8a2cfe | 2015-06-23 16:33:48 -0700 | [diff] [blame] | 74 | mInstaller.waitForConnection(); |
Jeff Brown | 6f357d3 | 2014-01-15 20:40:55 -0800 | [diff] [blame] | 75 | } |
| 76 | |
Jeff Sharkey | fdeeeea | 2016-01-11 17:34:24 -0700 | [diff] [blame] | 77 | public void createAppData(String uuid, String pkgname, int userid, int flags, int appid, |
Janis Danisevskis | f340974 | 2016-01-12 14:46:33 +0000 | [diff] [blame] | 78 | String seinfo, int targetSdkVersion) throws InstallerException { |
| 79 | mInstaller.execute("create_app_data", uuid, pkgname, userid, flags, appid, seinfo, |
| 80 | targetSdkVersion); |
Jeff Sharkey | 790a4ec | 2015-04-09 13:18:44 -0700 | [diff] [blame] | 81 | } |
| 82 | |
Jeff Sharkey | fdeeeea | 2016-01-11 17:34:24 -0700 | [diff] [blame] | 83 | 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 Sharkey | 790a4ec | 2015-04-09 13:18:44 -0700 | [diff] [blame] | 87 | } |
| 88 | |
Jeff Sharkey | e469713 | 2016-02-06 19:46:15 -0700 | [diff] [blame] | 89 | 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 Sharkey | fdeeeea | 2016-01-11 17:34:24 -0700 | [diff] [blame] | 94 | 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 Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 97 | } |
| 98 | |
Jeff Sharkey | fdeeeea | 2016-01-11 17:34:24 -0700 | [diff] [blame] | 99 | 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 Allison | 0efbd9a | 2014-01-30 14:19:51 -0800 | [diff] [blame] | 102 | } |
| 103 | |
Jeff Sharkey | fdeeeea | 2016-01-11 17:34:24 -0700 | [diff] [blame] | 104 | public void moveCompleteApp(String from_uuid, String to_uuid, String package_name, |
Janis Danisevskis | f340974 | 2016-01-12 14:46:33 +0000 | [diff] [blame] | 105 | String data_app_name, int appid, String seinfo, int targetSdkVersion) |
| 106 | throws InstallerException { |
Jeff Sharkey | fdeeeea | 2016-01-11 17:34:24 -0700 | [diff] [blame] | 107 | mInstaller.execute("move_complete_app", from_uuid, to_uuid, package_name, |
Janis Danisevskis | f340974 | 2016-01-12 14:46:33 +0000 | [diff] [blame] | 108 | data_app_name, appid, seinfo, targetSdkVersion); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 109 | } |
| 110 | |
Jeff Sharkey | fdeeeea | 2016-01-11 17:34:24 -0700 | [diff] [blame] | 111 | public void getAppSize(String uuid, String pkgname, int userid, int flags, String apkPath, |
Jeff Sharkey | 790a4ec | 2015-04-09 13:18:44 -0700 | [diff] [blame] | 112 | String libDirPath, String fwdLockApkPath, String asecPath, String[] instructionSets, |
Jeff Sharkey | fdeeeea | 2016-01-11 17:34:24 -0700 | [diff] [blame] | 113 | PackageStats pStats) throws InstallerException { |
Narayan Kamath | 6c4b9de | 2014-08-08 12:44:12 +0100 | [diff] [blame] | 114 | for (String instructionSet : instructionSets) { |
Jeff Sharkey | fdeeeea | 2016-01-11 17:34:24 -0700 | [diff] [blame] | 115 | assertValidInstructionSet(instructionSet); |
Narayan Kamath | 6c4b9de | 2014-08-08 12:44:12 +0100 | [diff] [blame] | 116 | } |
| 117 | |
Narayan Kamath | ff110bd | 2014-07-04 18:30:45 +0100 | [diff] [blame] | 118 | // TODO: Extend getSizeInfo to look at the full subdirectory tree, |
| 119 | // not just the first level. |
Narayan Kamath | ff110bd | 2014-07-04 18:30:45 +0100 | [diff] [blame] | 120 | // TODO: Extend getSizeInfo to look at *all* instrution sets, not |
| 121 | // just the primary. |
Jeff Sharkey | fdeeeea | 2016-01-11 17:34:24 -0700 | [diff] [blame] | 122 | 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 Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 125 | |
Dianne Hackborn | 292f8bc | 2011-06-27 16:27:41 -0700 | [diff] [blame] | 126 | if ((res == null) || (res.length != 5)) { |
Jeff Sharkey | fdeeeea | 2016-01-11 17:34:24 -0700 | [diff] [blame] | 127 | throw new InstallerException("Invalid size result: " + rawRes); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 128 | } |
| 129 | try { |
| 130 | pStats.codeSize = Long.parseLong(res[1]); |
| 131 | pStats.dataSize = Long.parseLong(res[2]); |
| 132 | pStats.cacheSize = Long.parseLong(res[3]); |
Dianne Hackborn | 292f8bc | 2011-06-27 16:27:41 -0700 | [diff] [blame] | 133 | pStats.externalCodeSize = Long.parseLong(res[4]); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 134 | } catch (NumberFormatException e) { |
Jeff Sharkey | fdeeeea | 2016-01-11 17:34:24 -0700 | [diff] [blame] | 135 | throw new InstallerException("Invalid size result: " + rawRes); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 136 | } |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 137 | } |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 138 | |
Jeff Sharkey | fdeeeea | 2016-01-11 17:34:24 -0700 | [diff] [blame] | 139 | public void dexopt(String apkPath, int uid, String instructionSet, int dexoptNeeded, |
Calin Juravle | db4a79a | 2015-12-23 18:55:08 +0200 | [diff] [blame] | 140 | int dexFlags, String volumeUuid, boolean useProfiles) throws InstallerException { |
Jeff Sharkey | fdeeeea | 2016-01-11 17:34:24 -0700 | [diff] [blame] | 141 | assertValidInstructionSet(instructionSet); |
Calin Juravle | db4a79a | 2015-12-23 18:55:08 +0200 | [diff] [blame] | 142 | mInstaller.dexopt(apkPath, uid, instructionSet, dexoptNeeded, dexFlags, |
| 143 | volumeUuid, useProfiles); |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 144 | } |
Kenny Root | 6a6b007 | 2010-10-07 16:46:10 -0700 | [diff] [blame] | 145 | |
Jeff Sharkey | fdeeeea | 2016-01-11 17:34:24 -0700 | [diff] [blame] | 146 | public void dexopt(String apkPath, int uid, String pkgName, String instructionSet, |
Calin Juravle | db4a79a | 2015-12-23 18:55:08 +0200 | [diff] [blame] | 147 | int dexoptNeeded, @Nullable String outputPath, int dexFlags, |
| 148 | String volumeUuid, boolean useProfiles) |
Jeff Sharkey | fdeeeea | 2016-01-11 17:34:24 -0700 | [diff] [blame] | 149 | throws InstallerException { |
| 150 | assertValidInstructionSet(instructionSet); |
| 151 | mInstaller.dexopt(apkPath, uid, pkgName, instructionSet, dexoptNeeded, |
Calin Juravle | db4a79a | 2015-12-23 18:55:08 +0200 | [diff] [blame] | 152 | outputPath, dexFlags, volumeUuid, useProfiles); |
Jeff Sharkey | fdeeeea | 2016-01-11 17:34:24 -0700 | [diff] [blame] | 153 | } |
| 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 Root | ddbe50d | 2012-09-06 13:18:37 -0700 | [diff] [blame] | 186 | /** |
Jeff Sharkey | fdeeeea | 2016-01-11 17:34:24 -0700 | [diff] [blame] | 187 | * 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 Root | ddbe50d | 2012-09-06 13:18:37 -0700 | [diff] [blame] | 190 | */ |
Jeff Sharkey | fdeeeea | 2016-01-11 17:34:24 -0700 | [diff] [blame] | 191 | public void linkNativeLibraryDirectory(String uuid, String dataPath, String nativeLibPath32, |
| 192 | int userId) throws InstallerException { |
| 193 | mInstaller.execute("linklib", uuid, dataPath, nativeLibPath32, userId); |
Kenny Root | 6a6b007 | 2010-10-07 16:46:10 -0700 | [diff] [blame] | 194 | } |
Robert Craig | 4385343 | 2014-03-04 11:57:23 -0500 | [diff] [blame] | 195 | |
Jeff Sharkey | fdeeeea | 2016-01-11 17:34:24 -0700 | [diff] [blame] | 196 | public void createOatDir(String oatDir, String dexInstructionSet) |
| 197 | throws InstallerException { |
| 198 | mInstaller.execute("createoatdir", oatDir, dexInstructionSet); |
Jeff Sharkey | 790a4ec | 2015-04-09 13:18:44 -0700 | [diff] [blame] | 199 | } |
| 200 | |
Jeff Sharkey | fdeeeea | 2016-01-11 17:34:24 -0700 | [diff] [blame] | 201 | public void linkFile(String relativePath, String fromBase, String toBase) |
| 202 | throws InstallerException { |
| 203 | mInstaller.execute("linkfile", relativePath, fromBase, toBase); |
Robert Craig | 4385343 | 2014-03-04 11:57:23 -0500 | [diff] [blame] | 204 | } |
Narayan Kamath | 6c4b9de | 2014-08-08 12:44:12 +0100 | [diff] [blame] | 205 | |
Jeff Sharkey | fdeeeea | 2016-01-11 17:34:24 -0700 | [diff] [blame] | 206 | private static void assertValidInstructionSet(String instructionSet) |
| 207 | throws InstallerException { |
Narayan Kamath | 6c4b9de | 2014-08-08 12:44:12 +0100 | [diff] [blame] | 208 | for (String abi : Build.SUPPORTED_ABIS) { |
Jeff Sharkey | fdeeeea | 2016-01-11 17:34:24 -0700 | [diff] [blame] | 209 | if (VMRuntime.getInstructionSet(abi).equals(instructionSet)) { |
| 210 | return; |
Narayan Kamath | 6c4b9de | 2014-08-08 12:44:12 +0100 | [diff] [blame] | 211 | } |
| 212 | } |
Jeff Sharkey | fdeeeea | 2016-01-11 17:34:24 -0700 | [diff] [blame] | 213 | throw new InstallerException("Invalid instruction set: " + instructionSet); |
Narayan Kamath | 6c4b9de | 2014-08-08 12:44:12 +0100 | [diff] [blame] | 214 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 215 | } |