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 | 790a4ec | 2015-04-09 13:18:44 -0700 | [diff] [blame] | 23 | import android.text.TextUtils; |
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 | 6c4b9de | 2014-08-08 12:44:12 +0100 | [diff] [blame] | 26 | import dalvik.system.VMRuntime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 27 | |
Narayan Kamath | 29564cd | 2014-08-07 10:57:40 +0100 | [diff] [blame] | 28 | import com.android.internal.os.InstallerConnection; |
| 29 | import com.android.server.SystemService; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 30 | |
Jeff Brown | 6f357d3 | 2014-01-15 20:40:55 -0800 | [diff] [blame] | 31 | public final class Installer extends SystemService { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 32 | private static final String TAG = "Installer"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 33 | |
Narayan Kamath | 29564cd | 2014-08-07 10:57:40 +0100 | [diff] [blame] | 34 | private final InstallerConnection mInstaller; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 35 | |
Jeff Brown | b880d88 | 2014-02-10 19:47:07 -0800 | [diff] [blame] | 36 | public Installer(Context context) { |
| 37 | super(context); |
Narayan Kamath | 29564cd | 2014-08-07 10:57:40 +0100 | [diff] [blame] | 38 | mInstaller = new InstallerConnection(); |
Jeff Brown | b880d88 | 2014-02-10 19:47:07 -0800 | [diff] [blame] | 39 | } |
| 40 | |
Jeff Brown | 6f357d3 | 2014-01-15 20:40:55 -0800 | [diff] [blame] | 41 | @Override |
| 42 | public void onStart() { |
| 43 | Slog.i(TAG, "Waiting for installd to be ready."); |
| 44 | ping(); |
| 45 | } |
| 46 | |
Jeff Sharkey | 790a4ec | 2015-04-09 13:18:44 -0700 | [diff] [blame] | 47 | private static String escapeNull(String arg) { |
| 48 | if (TextUtils.isEmpty(arg)) { |
| 49 | return "!"; |
| 50 | } else { |
| 51 | return arg; |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | @Deprecated |
Robert Craig | 0f40dc9 | 2013-03-25 06:33:03 -0400 | [diff] [blame] | 56 | public int install(String name, int uid, int gid, String seinfo) { |
Jeff Sharkey | 790a4ec | 2015-04-09 13:18:44 -0700 | [diff] [blame] | 57 | return install(null, name, uid, gid, seinfo); |
| 58 | } |
| 59 | |
| 60 | public int install(String uuid, String name, int uid, int gid, String seinfo) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 61 | StringBuilder builder = new StringBuilder("install"); |
| 62 | builder.append(' '); |
Jeff Sharkey | 790a4ec | 2015-04-09 13:18:44 -0700 | [diff] [blame] | 63 | builder.append(escapeNull(uuid)); |
| 64 | builder.append(' '); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 65 | builder.append(name); |
| 66 | builder.append(' '); |
| 67 | builder.append(uid); |
| 68 | builder.append(' '); |
| 69 | builder.append(gid); |
Robert Craig | 0f40dc9 | 2013-03-25 06:33:03 -0400 | [diff] [blame] | 70 | builder.append(' '); |
| 71 | builder.append(seinfo != null ? seinfo : "!"); |
Narayan Kamath | 29564cd | 2014-08-07 10:57:40 +0100 | [diff] [blame] | 72 | return mInstaller.execute(builder.toString()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 73 | } |
| 74 | |
Richard Uhler | 7b08b35 | 2015-03-25 16:25:57 -0700 | [diff] [blame] | 75 | public int dexopt(String apkPath, int uid, boolean isPublic, |
| 76 | String instructionSet, int dexoptNeeded) { |
Narayan Kamath | 6c4b9de | 2014-08-08 12:44:12 +0100 | [diff] [blame] | 77 | if (!isValidInstructionSet(instructionSet)) { |
| 78 | Slog.e(TAG, "Invalid instruction set: " + instructionSet); |
| 79 | return -1; |
| 80 | } |
| 81 | |
Richard Uhler | 7b08b35 | 2015-03-25 16:25:57 -0700 | [diff] [blame] | 82 | return mInstaller.dexopt(apkPath, uid, isPublic, instructionSet, dexoptNeeded); |
Dave Allison | 0efbd9a | 2014-01-30 14:19:51 -0800 | [diff] [blame] | 83 | } |
| 84 | |
Narayan Kamath | 0349e8c | 2014-05-01 11:41:20 +0100 | [diff] [blame] | 85 | public int dexopt(String apkPath, int uid, boolean isPublic, String pkgName, |
Richard Uhler | 7b08b35 | 2015-03-25 16:25:57 -0700 | [diff] [blame] | 86 | String instructionSet, int dexoptNeeded, boolean vmSafeMode, |
| 87 | boolean debuggable, @Nullable String outputPath) { |
Narayan Kamath | 6c4b9de | 2014-08-08 12:44:12 +0100 | [diff] [blame] | 88 | if (!isValidInstructionSet(instructionSet)) { |
| 89 | Slog.e(TAG, "Invalid instruction set: " + instructionSet); |
| 90 | return -1; |
| 91 | } |
Richard Uhler | 7b08b35 | 2015-03-25 16:25:57 -0700 | [diff] [blame] | 92 | return mInstaller.dexopt(apkPath, uid, isPublic, pkgName, |
| 93 | instructionSet, dexoptNeeded, vmSafeMode, |
Fyodor Kupolov | b94c165 | 2015-03-03 12:25:30 -0800 | [diff] [blame] | 94 | debuggable, outputPath); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 95 | } |
| 96 | |
MÃ¥rten Kongstad | 48d2232 | 2014-01-31 14:43:27 +0100 | [diff] [blame] | 97 | public int idmap(String targetApkPath, String overlayApkPath, int uid) { |
| 98 | StringBuilder builder = new StringBuilder("idmap"); |
| 99 | builder.append(' '); |
| 100 | builder.append(targetApkPath); |
| 101 | builder.append(' '); |
| 102 | builder.append(overlayApkPath); |
| 103 | builder.append(' '); |
| 104 | builder.append(uid); |
Narayan Kamath | 29564cd | 2014-08-07 10:57:40 +0100 | [diff] [blame] | 105 | return mInstaller.execute(builder.toString()); |
MÃ¥rten Kongstad | 48d2232 | 2014-01-31 14:43:27 +0100 | [diff] [blame] | 106 | } |
| 107 | |
Narayan Kamath | 0349e8c | 2014-05-01 11:41:20 +0100 | [diff] [blame] | 108 | public int movedex(String srcPath, String dstPath, String instructionSet) { |
Narayan Kamath | 6c4b9de | 2014-08-08 12:44:12 +0100 | [diff] [blame] | 109 | if (!isValidInstructionSet(instructionSet)) { |
| 110 | Slog.e(TAG, "Invalid instruction set: " + instructionSet); |
| 111 | return -1; |
| 112 | } |
| 113 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 114 | StringBuilder builder = new StringBuilder("movedex"); |
| 115 | builder.append(' '); |
| 116 | builder.append(srcPath); |
| 117 | builder.append(' '); |
| 118 | builder.append(dstPath); |
Narayan Kamath | 0349e8c | 2014-05-01 11:41:20 +0100 | [diff] [blame] | 119 | builder.append(' '); |
| 120 | builder.append(instructionSet); |
Narayan Kamath | 29564cd | 2014-08-07 10:57:40 +0100 | [diff] [blame] | 121 | return mInstaller.execute(builder.toString()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 122 | } |
| 123 | |
Narayan Kamath | 0349e8c | 2014-05-01 11:41:20 +0100 | [diff] [blame] | 124 | public int rmdex(String codePath, String instructionSet) { |
Narayan Kamath | 6c4b9de | 2014-08-08 12:44:12 +0100 | [diff] [blame] | 125 | if (!isValidInstructionSet(instructionSet)) { |
| 126 | Slog.e(TAG, "Invalid instruction set: " + instructionSet); |
| 127 | return -1; |
| 128 | } |
| 129 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 130 | StringBuilder builder = new StringBuilder("rmdex"); |
| 131 | builder.append(' '); |
| 132 | builder.append(codePath); |
Narayan Kamath | 0349e8c | 2014-05-01 11:41:20 +0100 | [diff] [blame] | 133 | builder.append(' '); |
| 134 | builder.append(instructionSet); |
Narayan Kamath | 29564cd | 2014-08-07 10:57:40 +0100 | [diff] [blame] | 135 | return mInstaller.execute(builder.toString()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 136 | } |
| 137 | |
Fyodor Kupolov | b94c165 | 2015-03-03 12:25:30 -0800 | [diff] [blame] | 138 | /** |
| 139 | * Removes packageDir or its subdirectory |
| 140 | */ |
| 141 | public int rmPackageDir(String packageDir) { |
| 142 | StringBuilder builder = new StringBuilder("rmpackagedir"); |
| 143 | builder.append(' '); |
| 144 | builder.append(packageDir); |
| 145 | return mInstaller.execute(builder.toString()); |
| 146 | } |
| 147 | |
Jeff Sharkey | 790a4ec | 2015-04-09 13:18:44 -0700 | [diff] [blame] | 148 | @Deprecated |
Amith Yamasani | 0b28549 | 2011-04-14 17:35:23 -0700 | [diff] [blame] | 149 | public int remove(String name, int userId) { |
Jeff Sharkey | 790a4ec | 2015-04-09 13:18:44 -0700 | [diff] [blame] | 150 | return remove(null, name, userId); |
| 151 | } |
| 152 | |
| 153 | public int remove(String uuid, String name, int userId) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 154 | StringBuilder builder = new StringBuilder("remove"); |
| 155 | builder.append(' '); |
Jeff Sharkey | 790a4ec | 2015-04-09 13:18:44 -0700 | [diff] [blame] | 156 | builder.append(escapeNull(uuid)); |
| 157 | builder.append(' '); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 158 | builder.append(name); |
Amith Yamasani | 0b28549 | 2011-04-14 17:35:23 -0700 | [diff] [blame] | 159 | builder.append(' '); |
| 160 | builder.append(userId); |
Narayan Kamath | 29564cd | 2014-08-07 10:57:40 +0100 | [diff] [blame] | 161 | return mInstaller.execute(builder.toString()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 162 | } |
| 163 | |
Kenny Root | 35ab3ad | 2011-02-02 16:42:14 -0800 | [diff] [blame] | 164 | public int rename(String oldname, String newname) { |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 165 | StringBuilder builder = new StringBuilder("rename"); |
| 166 | builder.append(' '); |
| 167 | builder.append(oldname); |
| 168 | builder.append(' '); |
| 169 | builder.append(newname); |
Narayan Kamath | 29564cd | 2014-08-07 10:57:40 +0100 | [diff] [blame] | 170 | return mInstaller.execute(builder.toString()); |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 171 | } |
| 172 | |
Jeff Sharkey | 790a4ec | 2015-04-09 13:18:44 -0700 | [diff] [blame] | 173 | @Deprecated |
Dave Burke | 383fa18 | 2012-10-23 23:12:19 -0700 | [diff] [blame] | 174 | public int fixUid(String name, int uid, int gid) { |
Jeff Sharkey | 790a4ec | 2015-04-09 13:18:44 -0700 | [diff] [blame] | 175 | return fixUid(null, name, uid, gid); |
| 176 | } |
| 177 | |
| 178 | public int fixUid(String uuid, String name, int uid, int gid) { |
Dianne Hackborn | d0c5f51 | 2012-06-07 16:53:59 -0700 | [diff] [blame] | 179 | StringBuilder builder = new StringBuilder("fixuid"); |
| 180 | builder.append(' '); |
Jeff Sharkey | 790a4ec | 2015-04-09 13:18:44 -0700 | [diff] [blame] | 181 | builder.append(escapeNull(uuid)); |
| 182 | builder.append(' '); |
Dianne Hackborn | d0c5f51 | 2012-06-07 16:53:59 -0700 | [diff] [blame] | 183 | builder.append(name); |
| 184 | builder.append(' '); |
| 185 | builder.append(uid); |
| 186 | builder.append(' '); |
Dave Burke | 383fa18 | 2012-10-23 23:12:19 -0700 | [diff] [blame] | 187 | builder.append(gid); |
Narayan Kamath | 29564cd | 2014-08-07 10:57:40 +0100 | [diff] [blame] | 188 | return mInstaller.execute(builder.toString()); |
Dianne Hackborn | d0c5f51 | 2012-06-07 16:53:59 -0700 | [diff] [blame] | 189 | } |
| 190 | |
Jeff Sharkey | 790a4ec | 2015-04-09 13:18:44 -0700 | [diff] [blame] | 191 | @Deprecated |
Amith Yamasani | 54289b8 | 2012-10-01 10:39:14 -0700 | [diff] [blame] | 192 | public int deleteCacheFiles(String name, int userId) { |
Jeff Sharkey | 790a4ec | 2015-04-09 13:18:44 -0700 | [diff] [blame] | 193 | return deleteCacheFiles(null, name, userId); |
| 194 | } |
| 195 | |
| 196 | public int deleteCacheFiles(String uuid, String name, int userId) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 197 | StringBuilder builder = new StringBuilder("rmcache"); |
| 198 | builder.append(' '); |
Jeff Sharkey | 790a4ec | 2015-04-09 13:18:44 -0700 | [diff] [blame] | 199 | builder.append(escapeNull(uuid)); |
| 200 | builder.append(' '); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 201 | builder.append(name); |
Amith Yamasani | 54289b8 | 2012-10-01 10:39:14 -0700 | [diff] [blame] | 202 | builder.append(' '); |
| 203 | builder.append(userId); |
Narayan Kamath | 29564cd | 2014-08-07 10:57:40 +0100 | [diff] [blame] | 204 | return mInstaller.execute(builder.toString()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 205 | } |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 206 | |
Jeff Sharkey | 790a4ec | 2015-04-09 13:18:44 -0700 | [diff] [blame] | 207 | @Deprecated |
Jeff Sharkey | 4ed745d | 2014-07-15 20:39:15 -0700 | [diff] [blame] | 208 | public int deleteCodeCacheFiles(String name, int userId) { |
Jeff Sharkey | 790a4ec | 2015-04-09 13:18:44 -0700 | [diff] [blame] | 209 | return deleteCodeCacheFiles(null, name, userId); |
| 210 | } |
| 211 | |
| 212 | public int deleteCodeCacheFiles(String uuid, String name, int userId) { |
Jeff Sharkey | 4ed745d | 2014-07-15 20:39:15 -0700 | [diff] [blame] | 213 | StringBuilder builder = new StringBuilder("rmcodecache"); |
| 214 | builder.append(' '); |
Jeff Sharkey | 790a4ec | 2015-04-09 13:18:44 -0700 | [diff] [blame] | 215 | builder.append(escapeNull(uuid)); |
| 216 | builder.append(' '); |
Jeff Sharkey | 4ed745d | 2014-07-15 20:39:15 -0700 | [diff] [blame] | 217 | builder.append(name); |
| 218 | builder.append(' '); |
| 219 | builder.append(userId); |
Narayan Kamath | 29564cd | 2014-08-07 10:57:40 +0100 | [diff] [blame] | 220 | return mInstaller.execute(builder.toString()); |
Jeff Sharkey | 4ed745d | 2014-07-15 20:39:15 -0700 | [diff] [blame] | 221 | } |
| 222 | |
Jeff Sharkey | 790a4ec | 2015-04-09 13:18:44 -0700 | [diff] [blame] | 223 | @Deprecated |
Robert Craig | 8643dc6 | 2013-07-29 09:06:51 -0400 | [diff] [blame] | 224 | public int createUserData(String name, int uid, int userId, String seinfo) { |
Jeff Sharkey | 790a4ec | 2015-04-09 13:18:44 -0700 | [diff] [blame] | 225 | return createUserData(null, name, uid, userId, seinfo); |
| 226 | } |
| 227 | |
| 228 | public int createUserData(String uuid, String name, int uid, int userId, String seinfo) { |
Amith Yamasani | 0b28549 | 2011-04-14 17:35:23 -0700 | [diff] [blame] | 229 | StringBuilder builder = new StringBuilder("mkuserdata"); |
| 230 | builder.append(' '); |
Jeff Sharkey | 790a4ec | 2015-04-09 13:18:44 -0700 | [diff] [blame] | 231 | builder.append(escapeNull(uuid)); |
| 232 | builder.append(' '); |
Amith Yamasani | 0b28549 | 2011-04-14 17:35:23 -0700 | [diff] [blame] | 233 | builder.append(name); |
| 234 | builder.append(' '); |
| 235 | builder.append(uid); |
| 236 | builder.append(' '); |
| 237 | builder.append(userId); |
Robert Craig | 8643dc6 | 2013-07-29 09:06:51 -0400 | [diff] [blame] | 238 | builder.append(' '); |
| 239 | builder.append(seinfo != null ? seinfo : "!"); |
Narayan Kamath | 29564cd | 2014-08-07 10:57:40 +0100 | [diff] [blame] | 240 | return mInstaller.execute(builder.toString()); |
Amith Yamasani | 0b28549 | 2011-04-14 17:35:23 -0700 | [diff] [blame] | 241 | } |
| 242 | |
Robin Lee | 06505d2 | 2014-07-09 17:43:56 +0000 | [diff] [blame] | 243 | public int createUserConfig(int userId) { |
| 244 | StringBuilder builder = new StringBuilder("mkuserconfig"); |
| 245 | builder.append(' '); |
| 246 | builder.append(userId); |
Narayan Kamath | 29564cd | 2014-08-07 10:57:40 +0100 | [diff] [blame] | 247 | return mInstaller.execute(builder.toString()); |
Robin Lee | 06505d2 | 2014-07-09 17:43:56 +0000 | [diff] [blame] | 248 | } |
| 249 | |
Jeff Sharkey | 790a4ec | 2015-04-09 13:18:44 -0700 | [diff] [blame] | 250 | @Deprecated |
Amith Yamasani | 0b28549 | 2011-04-14 17:35:23 -0700 | [diff] [blame] | 251 | public int removeUserDataDirs(int userId) { |
Jeff Sharkey | 790a4ec | 2015-04-09 13:18:44 -0700 | [diff] [blame] | 252 | return removeUserDataDirs(null, userId); |
| 253 | } |
| 254 | |
| 255 | public int removeUserDataDirs(String uuid, int userId) { |
Amith Yamasani | 0b28549 | 2011-04-14 17:35:23 -0700 | [diff] [blame] | 256 | StringBuilder builder = new StringBuilder("rmuser"); |
| 257 | builder.append(' '); |
Jeff Sharkey | 790a4ec | 2015-04-09 13:18:44 -0700 | [diff] [blame] | 258 | builder.append(escapeNull(uuid)); |
| 259 | builder.append(' '); |
Amith Yamasani | 0b28549 | 2011-04-14 17:35:23 -0700 | [diff] [blame] | 260 | builder.append(userId); |
Narayan Kamath | 29564cd | 2014-08-07 10:57:40 +0100 | [diff] [blame] | 261 | return mInstaller.execute(builder.toString()); |
Amith Yamasani | 0b28549 | 2011-04-14 17:35:23 -0700 | [diff] [blame] | 262 | } |
| 263 | |
Jeff Sharkey | b9f3674 | 2015-04-08 21:02:14 -0700 | [diff] [blame] | 264 | public int moveUserDataDirs(String fromUuid, String toUuid, String packageName, int appId, |
| 265 | String seinfo) { |
| 266 | StringBuilder builder = new StringBuilder("mvuserdata"); |
| 267 | builder.append(' '); |
| 268 | builder.append(escapeNull(fromUuid)); |
| 269 | builder.append(' '); |
| 270 | builder.append(escapeNull(toUuid)); |
| 271 | builder.append(' '); |
| 272 | builder.append(packageName); |
| 273 | builder.append(' '); |
| 274 | builder.append(appId); |
| 275 | builder.append(' '); |
| 276 | builder.append(seinfo); |
| 277 | return mInstaller.execute(builder.toString()); |
| 278 | } |
| 279 | |
Jeff Sharkey | 790a4ec | 2015-04-09 13:18:44 -0700 | [diff] [blame] | 280 | @Deprecated |
Amith Yamasani | 0b28549 | 2011-04-14 17:35:23 -0700 | [diff] [blame] | 281 | public int clearUserData(String name, int userId) { |
Jeff Sharkey | 790a4ec | 2015-04-09 13:18:44 -0700 | [diff] [blame] | 282 | return clearUserData(null, name, userId); |
| 283 | } |
| 284 | |
| 285 | public int clearUserData(String uuid, String name, int userId) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 286 | StringBuilder builder = new StringBuilder("rmuserdata"); |
| 287 | builder.append(' '); |
Jeff Sharkey | 790a4ec | 2015-04-09 13:18:44 -0700 | [diff] [blame] | 288 | builder.append(escapeNull(uuid)); |
| 289 | builder.append(' '); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 290 | builder.append(name); |
Amith Yamasani | 0b28549 | 2011-04-14 17:35:23 -0700 | [diff] [blame] | 291 | builder.append(' '); |
| 292 | builder.append(userId); |
Narayan Kamath | 29564cd | 2014-08-07 10:57:40 +0100 | [diff] [blame] | 293 | return mInstaller.execute(builder.toString()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 294 | } |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 295 | |
Narayan Kamath | 343f478 | 2014-11-10 14:23:41 +0000 | [diff] [blame] | 296 | public int markBootComplete(String instructionSet) { |
| 297 | if (!isValidInstructionSet(instructionSet)) { |
| 298 | Slog.e(TAG, "Invalid instruction set: " + instructionSet); |
| 299 | return -1; |
| 300 | } |
| 301 | |
| 302 | StringBuilder builder = new StringBuilder("markbootcomplete"); |
| 303 | builder.append(' '); |
| 304 | builder.append(instructionSet); |
| 305 | return mInstaller.execute(builder.toString()); |
| 306 | } |
| 307 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 308 | public boolean ping() { |
Narayan Kamath | 29564cd | 2014-08-07 10:57:40 +0100 | [diff] [blame] | 309 | if (mInstaller.execute("ping") < 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 310 | return false; |
| 311 | } else { |
| 312 | return true; |
| 313 | } |
| 314 | } |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 315 | |
Jeff Sharkey | 790a4ec | 2015-04-09 13:18:44 -0700 | [diff] [blame] | 316 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 317 | public int freeCache(long freeStorageSize) { |
Jeff Sharkey | 790a4ec | 2015-04-09 13:18:44 -0700 | [diff] [blame] | 318 | return freeCache(null, freeStorageSize); |
| 319 | } |
| 320 | |
| 321 | public int freeCache(String uuid, long freeStorageSize) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 322 | StringBuilder builder = new StringBuilder("freecache"); |
| 323 | builder.append(' '); |
Jeff Sharkey | 790a4ec | 2015-04-09 13:18:44 -0700 | [diff] [blame] | 324 | builder.append(escapeNull(uuid)); |
| 325 | builder.append(' '); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 326 | builder.append(String.valueOf(freeStorageSize)); |
Narayan Kamath | 29564cd | 2014-08-07 10:57:40 +0100 | [diff] [blame] | 327 | return mInstaller.execute(builder.toString()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 328 | } |
| 329 | |
Jeff Sharkey | 790a4ec | 2015-04-09 13:18:44 -0700 | [diff] [blame] | 330 | @Deprecated |
Dianne Hackborn | ecc8d6f | 2013-05-01 18:54:11 -0700 | [diff] [blame] | 331 | public int getSizeInfo(String pkgName, int persona, String apkPath, String libDirPath, |
Narayan Kamath | ff110bd | 2014-07-04 18:30:45 +0100 | [diff] [blame] | 332 | String fwdLockApkPath, String asecPath, String[] instructionSets, PackageStats pStats) { |
Jeff Sharkey | 790a4ec | 2015-04-09 13:18:44 -0700 | [diff] [blame] | 333 | return getSizeInfo(null, pkgName, persona, apkPath, libDirPath, fwdLockApkPath, asecPath, |
| 334 | instructionSets, pStats); |
| 335 | } |
| 336 | |
| 337 | public int getSizeInfo(String uuid, String pkgName, int persona, String apkPath, |
| 338 | String libDirPath, String fwdLockApkPath, String asecPath, String[] instructionSets, |
| 339 | PackageStats pStats) { |
Narayan Kamath | 6c4b9de | 2014-08-08 12:44:12 +0100 | [diff] [blame] | 340 | for (String instructionSet : instructionSets) { |
| 341 | if (!isValidInstructionSet(instructionSet)) { |
| 342 | Slog.e(TAG, "Invalid instruction set: " + instructionSet); |
| 343 | return -1; |
| 344 | } |
| 345 | } |
| 346 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 347 | StringBuilder builder = new StringBuilder("getsize"); |
| 348 | builder.append(' '); |
Jeff Sharkey | 790a4ec | 2015-04-09 13:18:44 -0700 | [diff] [blame] | 349 | builder.append(escapeNull(uuid)); |
| 350 | builder.append(' '); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 351 | builder.append(pkgName); |
| 352 | builder.append(' '); |
Dianne Hackborn | 0c38049 | 2012-08-20 17:23:30 -0700 | [diff] [blame] | 353 | builder.append(persona); |
| 354 | builder.append(' '); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 355 | builder.append(apkPath); |
| 356 | builder.append(' '); |
Narayan Kamath | ff110bd | 2014-07-04 18:30:45 +0100 | [diff] [blame] | 357 | // TODO: Extend getSizeInfo to look at the full subdirectory tree, |
| 358 | // not just the first level. |
Dianne Hackborn | ecc8d6f | 2013-05-01 18:54:11 -0700 | [diff] [blame] | 359 | builder.append(libDirPath != null ? libDirPath : "!"); |
| 360 | builder.append(' '); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 361 | builder.append(fwdLockApkPath != null ? fwdLockApkPath : "!"); |
Dianne Hackborn | 292f8bc | 2011-06-27 16:27:41 -0700 | [diff] [blame] | 362 | builder.append(' '); |
| 363 | builder.append(asecPath != null ? asecPath : "!"); |
Narayan Kamath | 0349e8c | 2014-05-01 11:41:20 +0100 | [diff] [blame] | 364 | builder.append(' '); |
Narayan Kamath | ff110bd | 2014-07-04 18:30:45 +0100 | [diff] [blame] | 365 | // TODO: Extend getSizeInfo to look at *all* instrution sets, not |
| 366 | // just the primary. |
| 367 | builder.append(instructionSets[0]); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 368 | |
Narayan Kamath | 29564cd | 2014-08-07 10:57:40 +0100 | [diff] [blame] | 369 | String s = mInstaller.transact(builder.toString()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 370 | String res[] = s.split(" "); |
| 371 | |
Dianne Hackborn | 292f8bc | 2011-06-27 16:27:41 -0700 | [diff] [blame] | 372 | if ((res == null) || (res.length != 5)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 373 | return -1; |
| 374 | } |
| 375 | try { |
| 376 | pStats.codeSize = Long.parseLong(res[1]); |
| 377 | pStats.dataSize = Long.parseLong(res[2]); |
| 378 | pStats.cacheSize = Long.parseLong(res[3]); |
Dianne Hackborn | 292f8bc | 2011-06-27 16:27:41 -0700 | [diff] [blame] | 379 | pStats.externalCodeSize = Long.parseLong(res[4]); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 380 | return Integer.parseInt(res[0]); |
| 381 | } catch (NumberFormatException e) { |
| 382 | return -1; |
| 383 | } |
Kenny Root | cf0b38c | 2011-03-22 14:17:59 -0700 | [diff] [blame] | 384 | } |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 385 | |
| 386 | public int moveFiles() { |
Narayan Kamath | 29564cd | 2014-08-07 10:57:40 +0100 | [diff] [blame] | 387 | return mInstaller.execute("movefiles"); |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 388 | } |
Kenny Root | 6a6b007 | 2010-10-07 16:46:10 -0700 | [diff] [blame] | 389 | |
Jeff Sharkey | 790a4ec | 2015-04-09 13:18:44 -0700 | [diff] [blame] | 390 | @Deprecated |
| 391 | public int linkNativeLibraryDirectory(String dataPath, String nativeLibPath32, int userId) { |
| 392 | return linkNativeLibraryDirectory(null, dataPath, nativeLibPath32, userId); |
| 393 | } |
| 394 | |
Kenny Root | ddbe50d | 2012-09-06 13:18:37 -0700 | [diff] [blame] | 395 | /** |
Narayan Kamath | ff110bd | 2014-07-04 18:30:45 +0100 | [diff] [blame] | 396 | * Links the 32 bit native library directory in an application's data directory to the |
| 397 | * real location for backward compatibility. Note that no such symlink is created for |
| 398 | * 64 bit shared libraries. |
Kenny Root | ddbe50d | 2012-09-06 13:18:37 -0700 | [diff] [blame] | 399 | * |
Kenny Root | ddbe50d | 2012-09-06 13:18:37 -0700 | [diff] [blame] | 400 | * @return -1 on error |
| 401 | */ |
Jeff Sharkey | 790a4ec | 2015-04-09 13:18:44 -0700 | [diff] [blame] | 402 | public int linkNativeLibraryDirectory(String uuid, String dataPath, String nativeLibPath32, |
| 403 | int userId) { |
Kenny Root | 6a6b007 | 2010-10-07 16:46:10 -0700 | [diff] [blame] | 404 | if (dataPath == null) { |
Kenny Root | 9bbd70a | 2012-09-10 11:13:36 -0700 | [diff] [blame] | 405 | Slog.e(TAG, "linkNativeLibraryDirectory dataPath is null"); |
Kenny Root | 6a6b007 | 2010-10-07 16:46:10 -0700 | [diff] [blame] | 406 | return -1; |
Narayan Kamath | ff110bd | 2014-07-04 18:30:45 +0100 | [diff] [blame] | 407 | } else if (nativeLibPath32 == null) { |
Kenny Root | 9bbd70a | 2012-09-10 11:13:36 -0700 | [diff] [blame] | 408 | Slog.e(TAG, "linkNativeLibraryDirectory nativeLibPath is null"); |
Kenny Root | 6a6b007 | 2010-10-07 16:46:10 -0700 | [diff] [blame] | 409 | return -1; |
| 410 | } |
| 411 | |
Jeff Sharkey | 790a4ec | 2015-04-09 13:18:44 -0700 | [diff] [blame] | 412 | StringBuilder builder = new StringBuilder("linklib"); |
| 413 | builder.append(' '); |
| 414 | builder.append(escapeNull(uuid)); |
| 415 | builder.append(' '); |
Kenny Root | 6a6b007 | 2010-10-07 16:46:10 -0700 | [diff] [blame] | 416 | builder.append(dataPath); |
| 417 | builder.append(' '); |
Narayan Kamath | ff110bd | 2014-07-04 18:30:45 +0100 | [diff] [blame] | 418 | builder.append(nativeLibPath32); |
Kenny Root | a3e9079 | 2012-10-18 10:58:36 -0700 | [diff] [blame] | 419 | builder.append(' '); |
| 420 | builder.append(userId); |
Kenny Root | 6a6b007 | 2010-10-07 16:46:10 -0700 | [diff] [blame] | 421 | |
Narayan Kamath | 29564cd | 2014-08-07 10:57:40 +0100 | [diff] [blame] | 422 | return mInstaller.execute(builder.toString()); |
Kenny Root | 6a6b007 | 2010-10-07 16:46:10 -0700 | [diff] [blame] | 423 | } |
Robert Craig | 4385343 | 2014-03-04 11:57:23 -0500 | [diff] [blame] | 424 | |
Jeff Sharkey | 790a4ec | 2015-04-09 13:18:44 -0700 | [diff] [blame] | 425 | @Deprecated |
Nick Kralevich | ce30fca85 | 2014-03-31 20:20:41 +0000 | [diff] [blame] | 426 | public boolean restoreconData(String pkgName, String seinfo, int uid) { |
Jeff Sharkey | 790a4ec | 2015-04-09 13:18:44 -0700 | [diff] [blame] | 427 | return restoreconData(null, pkgName, seinfo, uid); |
| 428 | } |
| 429 | |
| 430 | public boolean restoreconData(String uuid, String pkgName, String seinfo, int uid) { |
Nick Kralevich | ce30fca85 | 2014-03-31 20:20:41 +0000 | [diff] [blame] | 431 | StringBuilder builder = new StringBuilder("restorecondata"); |
| 432 | builder.append(' '); |
Jeff Sharkey | 790a4ec | 2015-04-09 13:18:44 -0700 | [diff] [blame] | 433 | builder.append(escapeNull(uuid)); |
| 434 | builder.append(' '); |
Nick Kralevich | ce30fca85 | 2014-03-31 20:20:41 +0000 | [diff] [blame] | 435 | builder.append(pkgName); |
| 436 | builder.append(' '); |
| 437 | builder.append(seinfo != null ? seinfo : "!"); |
| 438 | builder.append(' '); |
| 439 | builder.append(uid); |
Narayan Kamath | 29564cd | 2014-08-07 10:57:40 +0100 | [diff] [blame] | 440 | return (mInstaller.execute(builder.toString()) == 0); |
Robert Craig | 4385343 | 2014-03-04 11:57:23 -0500 | [diff] [blame] | 441 | } |
Narayan Kamath | 6c4b9de | 2014-08-08 12:44:12 +0100 | [diff] [blame] | 442 | |
Fyodor Kupolov | b94c165 | 2015-03-03 12:25:30 -0800 | [diff] [blame] | 443 | public int createOatDir(String oatDir, String dexInstructionSet) { |
| 444 | StringBuilder builder = new StringBuilder("createoatdir"); |
| 445 | builder.append(' '); |
| 446 | builder.append(oatDir); |
| 447 | builder.append(' '); |
| 448 | builder.append(dexInstructionSet); |
| 449 | return mInstaller.execute(builder.toString()); |
| 450 | } |
| 451 | |
Narayan Kamath | 6c4b9de | 2014-08-08 12:44:12 +0100 | [diff] [blame] | 452 | /** |
| 453 | * Returns true iff. {@code instructionSet} is a valid instruction set. |
| 454 | */ |
| 455 | private static boolean isValidInstructionSet(String instructionSet) { |
| 456 | if (instructionSet == null) { |
| 457 | return false; |
| 458 | } |
| 459 | |
| 460 | for (String abi : Build.SUPPORTED_ABIS) { |
| 461 | if (instructionSet.equals(VMRuntime.getInstructionSet(abi))) { |
| 462 | return true; |
| 463 | } |
| 464 | } |
| 465 | |
| 466 | return false; |
| 467 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 468 | } |