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; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 23 | import android.util.Slog; |
Jeff Sharkey | 790a4ec | 2015-04-09 13:18:44 -0700 | [diff] [blame] | 24 | |
Narayan Kamath | 29564cd | 2014-08-07 10:57:40 +0100 | [diff] [blame] | 25 | import com.android.internal.os.InstallerConnection; |
Jeff Sharkey | fdeeeea | 2016-01-11 17:34:24 -0700 | [diff] [blame] | 26 | import com.android.internal.os.InstallerConnection.InstallerException; |
Narayan Kamath | 29564cd | 2014-08-07 10:57:40 +0100 | [diff] [blame] | 27 | import com.android.server.SystemService; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 28 | |
Jeff Sharkey | fdeeeea | 2016-01-11 17:34:24 -0700 | [diff] [blame] | 29 | import dalvik.system.VMRuntime; |
| 30 | |
Jeff Sharkey | 4288419 | 2016-04-09 16:12:01 -0600 | [diff] [blame] | 31 | import java.util.Arrays; |
| 32 | |
Jeff Brown | 6f357d3 | 2014-01-15 20:40:55 -0800 | [diff] [blame] | 33 | public final class Installer extends SystemService { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 34 | private static final String TAG = "Installer"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 35 | |
Todd Kennedy | fa54ab7 | 2015-09-25 07:46:12 -0700 | [diff] [blame] | 36 | /* *************************************************************************** |
| 37 | * IMPORTANT: These values are passed to native code. Keep them in sync with |
| 38 | * frameworks/native/cmds/installd/installd.h |
| 39 | * **************************************************************************/ |
| 40 | /** Application should be visible to everyone */ |
Andreas Gampe | bdd30d8 | 2016-03-20 11:32:11 -0700 | [diff] [blame] | 41 | public static final int DEXOPT_PUBLIC = 1 << 1; |
Todd Kennedy | fa54ab7 | 2015-09-25 07:46:12 -0700 | [diff] [blame] | 42 | /** Application wants to run in VM safe mode */ |
Andreas Gampe | bdd30d8 | 2016-03-20 11:32:11 -0700 | [diff] [blame] | 43 | public static final int DEXOPT_SAFEMODE = 1 << 2; |
Todd Kennedy | fa54ab7 | 2015-09-25 07:46:12 -0700 | [diff] [blame] | 44 | /** Application wants to allow debugging of its code */ |
Andreas Gampe | bdd30d8 | 2016-03-20 11:32:11 -0700 | [diff] [blame] | 45 | public static final int DEXOPT_DEBUGGABLE = 1 << 3; |
Todd Kennedy | fa54ab7 | 2015-09-25 07:46:12 -0700 | [diff] [blame] | 46 | /** The system boot has finished */ |
Andreas Gampe | bdd30d8 | 2016-03-20 11:32:11 -0700 | [diff] [blame] | 47 | public static final int DEXOPT_BOOTCOMPLETE = 1 << 4; |
| 48 | /** Hint that the dexopt type is profile-guided. */ |
| 49 | public static final int DEXOPT_PROFILE_GUIDED = 1 << 5; |
Andreas Gampe | a890875 | 2015-11-10 08:58:14 -0800 | [diff] [blame] | 50 | /** This is an OTA update dexopt */ |
Andreas Gampe | bdd30d8 | 2016-03-20 11:32:11 -0700 | [diff] [blame] | 51 | public static final int DEXOPT_OTA = 1 << 6; |
Todd Kennedy | fa54ab7 | 2015-09-25 07:46:12 -0700 | [diff] [blame] | 52 | |
Jeff Sharkey | 47f7108 | 2016-02-01 17:03:54 -0700 | [diff] [blame] | 53 | // NOTE: keep in sync with installd |
| 54 | public static final int FLAG_CLEAR_CACHE_ONLY = 1 << 8; |
| 55 | public static final int FLAG_CLEAR_CODE_CACHE_ONLY = 1 << 9; |
Jeff Sharkey | fdeeeea | 2016-01-11 17:34:24 -0700 | [diff] [blame] | 56 | |
Narayan Kamath | 29564cd | 2014-08-07 10:57:40 +0100 | [diff] [blame] | 57 | private final InstallerConnection mInstaller; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 58 | |
Jeff Brown | b880d88 | 2014-02-10 19:47:07 -0800 | [diff] [blame] | 59 | public Installer(Context context) { |
| 60 | super(context); |
Narayan Kamath | 29564cd | 2014-08-07 10:57:40 +0100 | [diff] [blame] | 61 | mInstaller = new InstallerConnection(); |
Jeff Brown | b880d88 | 2014-02-10 19:47:07 -0800 | [diff] [blame] | 62 | } |
| 63 | |
Andreas Gampe | cc241a5 | 2016-06-23 20:27:12 -0700 | [diff] [blame] | 64 | // Package-private installer that accepts a custom InstallerConnection. Used for |
| 65 | // OtaDexoptService. |
| 66 | Installer(Context context, InstallerConnection connection) { |
| 67 | super(context); |
| 68 | mInstaller = connection; |
| 69 | } |
| 70 | |
Jeff Sharkey | 8948c01 | 2015-11-03 12:33:54 -0800 | [diff] [blame] | 71 | /** |
| 72 | * Yell loudly if someone tries making future calls while holding a lock on |
| 73 | * the given object. |
| 74 | */ |
| 75 | public void setWarnIfHeld(Object warnIfHeld) { |
| 76 | mInstaller.setWarnIfHeld(warnIfHeld); |
| 77 | } |
| 78 | |
Jeff Brown | 6f357d3 | 2014-01-15 20:40:55 -0800 | [diff] [blame] | 79 | @Override |
| 80 | public void onStart() { |
| 81 | Slog.i(TAG, "Waiting for installd to be ready."); |
Makoto Onuki | c8a2cfe | 2015-06-23 16:33:48 -0700 | [diff] [blame] | 82 | mInstaller.waitForConnection(); |
Jeff Brown | 6f357d3 | 2014-01-15 20:40:55 -0800 | [diff] [blame] | 83 | } |
| 84 | |
Jeff Sharkey | fdeeeea | 2016-01-11 17:34:24 -0700 | [diff] [blame] | 85 | 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] | 86 | String seinfo, int targetSdkVersion) throws InstallerException { |
| 87 | mInstaller.execute("create_app_data", uuid, pkgname, userid, flags, appid, seinfo, |
| 88 | targetSdkVersion); |
Jeff Sharkey | 790a4ec | 2015-04-09 13:18:44 -0700 | [diff] [blame] | 89 | } |
| 90 | |
Jeff Sharkey | fdeeeea | 2016-01-11 17:34:24 -0700 | [diff] [blame] | 91 | public void restoreconAppData(String uuid, String pkgname, int userid, int flags, int appid, |
| 92 | String seinfo) throws InstallerException { |
| 93 | mInstaller.execute("restorecon_app_data", uuid, pkgname, userid, flags, appid, |
| 94 | seinfo); |
Jeff Sharkey | 790a4ec | 2015-04-09 13:18:44 -0700 | [diff] [blame] | 95 | } |
| 96 | |
Jeff Sharkey | e469713 | 2016-02-06 19:46:15 -0700 | [diff] [blame] | 97 | public void migrateAppData(String uuid, String pkgname, int userid, int flags) |
| 98 | throws InstallerException { |
| 99 | mInstaller.execute("migrate_app_data", uuid, pkgname, userid, flags); |
| 100 | } |
| 101 | |
Jeff Sharkey | 4288419 | 2016-04-09 16:12:01 -0600 | [diff] [blame] | 102 | public void clearAppData(String uuid, String pkgname, int userid, int flags, long ceDataInode) |
Jeff Sharkey | fdeeeea | 2016-01-11 17:34:24 -0700 | [diff] [blame] | 103 | throws InstallerException { |
Jeff Sharkey | 4288419 | 2016-04-09 16:12:01 -0600 | [diff] [blame] | 104 | mInstaller.execute("clear_app_data", uuid, pkgname, userid, flags, ceDataInode); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 105 | } |
| 106 | |
Jeff Sharkey | 4288419 | 2016-04-09 16:12:01 -0600 | [diff] [blame] | 107 | public void destroyAppData(String uuid, String pkgname, int userid, int flags, long ceDataInode) |
Jeff Sharkey | fdeeeea | 2016-01-11 17:34:24 -0700 | [diff] [blame] | 108 | throws InstallerException { |
Jeff Sharkey | 4288419 | 2016-04-09 16:12:01 -0600 | [diff] [blame] | 109 | mInstaller.execute("destroy_app_data", uuid, pkgname, userid, flags, ceDataInode); |
Dave Allison | 0efbd9a | 2014-01-30 14:19:51 -0800 | [diff] [blame] | 110 | } |
| 111 | |
Jeff Sharkey | fdeeeea | 2016-01-11 17:34:24 -0700 | [diff] [blame] | 112 | public void moveCompleteApp(String from_uuid, String to_uuid, String package_name, |
Janis Danisevskis | f340974 | 2016-01-12 14:46:33 +0000 | [diff] [blame] | 113 | String data_app_name, int appid, String seinfo, int targetSdkVersion) |
| 114 | throws InstallerException { |
Jeff Sharkey | fdeeeea | 2016-01-11 17:34:24 -0700 | [diff] [blame] | 115 | mInstaller.execute("move_complete_app", from_uuid, to_uuid, package_name, |
Janis Danisevskis | f340974 | 2016-01-12 14:46:33 +0000 | [diff] [blame] | 116 | data_app_name, appid, seinfo, targetSdkVersion); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 117 | } |
| 118 | |
Jeff Sharkey | 4288419 | 2016-04-09 16:12:01 -0600 | [diff] [blame] | 119 | public void getAppSize(String uuid, String pkgname, int userid, int flags, long ceDataInode, |
| 120 | String codePath, PackageStats stats) throws InstallerException { |
| 121 | final String[] res = mInstaller.execute("get_app_size", uuid, pkgname, userid, flags, |
| 122 | ceDataInode, codePath); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 123 | try { |
Jeff Sharkey | 4288419 | 2016-04-09 16:12:01 -0600 | [diff] [blame] | 124 | stats.codeSize += Long.parseLong(res[1]); |
| 125 | stats.dataSize += Long.parseLong(res[2]); |
| 126 | stats.cacheSize += Long.parseLong(res[3]); |
| 127 | } catch (ArrayIndexOutOfBoundsException | NumberFormatException e) { |
| 128 | throw new InstallerException("Invalid size result: " + Arrays.toString(res)); |
| 129 | } |
| 130 | } |
| 131 | |
| 132 | public long getAppDataInode(String uuid, String pkgname, int userid, int flags) |
| 133 | throws InstallerException { |
| 134 | final String[] res = mInstaller.execute("get_app_data_inode", uuid, pkgname, userid, flags); |
| 135 | try { |
| 136 | return Long.parseLong(res[1]); |
| 137 | } catch (ArrayIndexOutOfBoundsException | NumberFormatException e) { |
| 138 | throw new InstallerException("Invalid inode result: " + Arrays.toString(res)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 139 | } |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 140 | } |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 141 | |
Jeff Sharkey | fdeeeea | 2016-01-11 17:34:24 -0700 | [diff] [blame] | 142 | public void dexopt(String apkPath, int uid, String instructionSet, int dexoptNeeded, |
Jeff Hao | c7b9482 | 2016-03-16 15:56:07 -0700 | [diff] [blame] | 143 | int dexFlags, String compilerFilter, String volumeUuid, String sharedLibraries) |
| 144 | throws InstallerException { |
Jeff Sharkey | fdeeeea | 2016-01-11 17:34:24 -0700 | [diff] [blame] | 145 | assertValidInstructionSet(instructionSet); |
Calin Juravle | db4a79a | 2015-12-23 18:55:08 +0200 | [diff] [blame] | 146 | mInstaller.dexopt(apkPath, uid, instructionSet, dexoptNeeded, dexFlags, |
Jeff Hao | c7b9482 | 2016-03-16 15:56:07 -0700 | [diff] [blame] | 147 | compilerFilter, volumeUuid, sharedLibraries); |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 148 | } |
Kenny Root | 6a6b007 | 2010-10-07 16:46:10 -0700 | [diff] [blame] | 149 | |
Jeff Sharkey | fdeeeea | 2016-01-11 17:34:24 -0700 | [diff] [blame] | 150 | public void dexopt(String apkPath, int uid, String pkgName, String instructionSet, |
Calin Juravle | db4a79a | 2015-12-23 18:55:08 +0200 | [diff] [blame] | 151 | int dexoptNeeded, @Nullable String outputPath, int dexFlags, |
Jeff Hao | c7b9482 | 2016-03-16 15:56:07 -0700 | [diff] [blame] | 152 | String compilerFilter, String volumeUuid, String sharedLibraries) |
| 153 | throws InstallerException { |
Jeff Sharkey | fdeeeea | 2016-01-11 17:34:24 -0700 | [diff] [blame] | 154 | assertValidInstructionSet(instructionSet); |
| 155 | mInstaller.dexopt(apkPath, uid, pkgName, instructionSet, dexoptNeeded, |
Jeff Hao | c7b9482 | 2016-03-16 15:56:07 -0700 | [diff] [blame] | 156 | outputPath, dexFlags, compilerFilter, volumeUuid, sharedLibraries); |
Andreas Gampe | bdd30d8 | 2016-03-20 11:32:11 -0700 | [diff] [blame] | 157 | } |
| 158 | |
| 159 | public boolean mergeProfiles(int uid, String pkgName) throws InstallerException { |
| 160 | return mInstaller.mergeProfiles(uid, pkgName); |
Jeff Sharkey | fdeeeea | 2016-01-11 17:34:24 -0700 | [diff] [blame] | 161 | } |
| 162 | |
David Sehr | a877708 | 2016-05-24 15:25:23 -0700 | [diff] [blame] | 163 | public boolean dumpProfiles(String gid, String packageName, String codePaths) |
| 164 | throws InstallerException { |
| 165 | return mInstaller.dumpProfiles(gid, packageName, codePaths); |
| 166 | } |
| 167 | |
Jeff Sharkey | fdeeeea | 2016-01-11 17:34:24 -0700 | [diff] [blame] | 168 | public void idmap(String targetApkPath, String overlayApkPath, int uid) |
| 169 | throws InstallerException { |
| 170 | mInstaller.execute("idmap", targetApkPath, overlayApkPath, uid); |
| 171 | } |
| 172 | |
| 173 | public void rmdex(String codePath, String instructionSet) throws InstallerException { |
| 174 | assertValidInstructionSet(instructionSet); |
| 175 | mInstaller.execute("rmdex", codePath, instructionSet); |
| 176 | } |
| 177 | |
| 178 | public void rmPackageDir(String packageDir) throws InstallerException { |
| 179 | mInstaller.execute("rmpackagedir", packageDir); |
| 180 | } |
| 181 | |
Calin Juravle | d6d27e3 | 2016-03-23 13:59:18 +0000 | [diff] [blame] | 182 | public void clearAppProfiles(String pkgName) throws InstallerException { |
| 183 | mInstaller.execute("clear_app_profiles", pkgName); |
| 184 | } |
| 185 | |
| 186 | public void destroyAppProfiles(String pkgName) throws InstallerException { |
| 187 | mInstaller.execute("destroy_app_profiles", pkgName); |
David Brazdil | 9aa6db0 | 2016-03-08 12:57:12 +0000 | [diff] [blame] | 188 | } |
| 189 | |
Jeff Sharkey | fcf1e55 | 2016-04-14 20:44:58 -0600 | [diff] [blame] | 190 | public void createUserData(String uuid, int userId, int userSerial, int flags) |
| 191 | throws InstallerException { |
| 192 | mInstaller.execute("create_user_data", uuid, userId, userSerial, flags); |
Jeff Sharkey | fdeeeea | 2016-01-11 17:34:24 -0700 | [diff] [blame] | 193 | } |
| 194 | |
Jeff Sharkey | fcf1e55 | 2016-04-14 20:44:58 -0600 | [diff] [blame] | 195 | public void destroyUserData(String uuid, int userId, int flags) throws InstallerException { |
| 196 | mInstaller.execute("destroy_user_data", uuid, userId, flags); |
Jeff Sharkey | fdeeeea | 2016-01-11 17:34:24 -0700 | [diff] [blame] | 197 | } |
| 198 | |
| 199 | public void markBootComplete(String instructionSet) throws InstallerException { |
| 200 | assertValidInstructionSet(instructionSet); |
| 201 | mInstaller.execute("markbootcomplete", instructionSet); |
| 202 | } |
| 203 | |
| 204 | public void freeCache(String uuid, long freeStorageSize) throws InstallerException { |
| 205 | mInstaller.execute("freecache", uuid, freeStorageSize); |
| 206 | } |
| 207 | |
Kenny Root | ddbe50d | 2012-09-06 13:18:37 -0700 | [diff] [blame] | 208 | /** |
Jeff Sharkey | fdeeeea | 2016-01-11 17:34:24 -0700 | [diff] [blame] | 209 | * Links the 32 bit native library directory in an application's data |
| 210 | * directory to the real location for backward compatibility. Note that no |
| 211 | * such symlink is created for 64 bit shared libraries. |
Kenny Root | ddbe50d | 2012-09-06 13:18:37 -0700 | [diff] [blame] | 212 | */ |
Jeff Sharkey | fdeeeea | 2016-01-11 17:34:24 -0700 | [diff] [blame] | 213 | public void linkNativeLibraryDirectory(String uuid, String dataPath, String nativeLibPath32, |
| 214 | int userId) throws InstallerException { |
| 215 | mInstaller.execute("linklib", uuid, dataPath, nativeLibPath32, userId); |
Kenny Root | 6a6b007 | 2010-10-07 16:46:10 -0700 | [diff] [blame] | 216 | } |
Robert Craig | 4385343 | 2014-03-04 11:57:23 -0500 | [diff] [blame] | 217 | |
Jeff Sharkey | fdeeeea | 2016-01-11 17:34:24 -0700 | [diff] [blame] | 218 | public void createOatDir(String oatDir, String dexInstructionSet) |
| 219 | throws InstallerException { |
| 220 | mInstaller.execute("createoatdir", oatDir, dexInstructionSet); |
Jeff Sharkey | 790a4ec | 2015-04-09 13:18:44 -0700 | [diff] [blame] | 221 | } |
| 222 | |
Jeff Sharkey | fdeeeea | 2016-01-11 17:34:24 -0700 | [diff] [blame] | 223 | public void linkFile(String relativePath, String fromBase, String toBase) |
| 224 | throws InstallerException { |
| 225 | mInstaller.execute("linkfile", relativePath, fromBase, toBase); |
Robert Craig | 4385343 | 2014-03-04 11:57:23 -0500 | [diff] [blame] | 226 | } |
Narayan Kamath | 6c4b9de | 2014-08-08 12:44:12 +0100 | [diff] [blame] | 227 | |
Andreas Gampe | abcbe2f | 2016-02-26 11:25:36 -0800 | [diff] [blame] | 228 | public void moveAb(String apkPath, String instructionSet, String outputPath) |
| 229 | throws InstallerException { |
| 230 | mInstaller.execute("move_ab", apkPath, instructionSet, outputPath); |
| 231 | } |
| 232 | |
Andreas Gampe | e5fedb9 | 2016-09-09 17:08:53 -0700 | [diff] [blame] | 233 | public void deleteOdex(String apkPath, String instructionSet, String outputPath) |
| 234 | throws InstallerException { |
| 235 | mInstaller.execute("delete_odex", apkPath, instructionSet, outputPath); |
| 236 | } |
| 237 | |
Jeff Sharkey | fdeeeea | 2016-01-11 17:34:24 -0700 | [diff] [blame] | 238 | private static void assertValidInstructionSet(String instructionSet) |
| 239 | throws InstallerException { |
Narayan Kamath | 6c4b9de | 2014-08-08 12:44:12 +0100 | [diff] [blame] | 240 | for (String abi : Build.SUPPORTED_ABIS) { |
Jeff Sharkey | fdeeeea | 2016-01-11 17:34:24 -0700 | [diff] [blame] | 241 | if (VMRuntime.getInstructionSet(abi).equals(instructionSet)) { |
| 242 | return; |
Narayan Kamath | 6c4b9de | 2014-08-08 12:44:12 +0100 | [diff] [blame] | 243 | } |
| 244 | } |
Jeff Sharkey | fdeeeea | 2016-01-11 17:34:24 -0700 | [diff] [blame] | 245 | throw new InstallerException("Invalid instruction set: " + instructionSet); |
Narayan Kamath | 6c4b9de | 2014-08-08 12:44:12 +0100 | [diff] [blame] | 246 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 247 | } |