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