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 | 9f2f218 | 2016-12-21 09:18:33 -0700 | [diff] [blame] | 23 | import android.os.IBinder; |
| 24 | import android.os.IBinder.DeathRecipient; |
Jeff Sharkey | 70b4d10 | 2016-12-05 11:19:28 -0700 | [diff] [blame] | 25 | import android.os.IInstalld; |
Jeff Sharkey | 9f2f218 | 2016-12-21 09:18:33 -0700 | [diff] [blame] | 26 | import android.os.RemoteException; |
Jeff Sharkey | 70b4d10 | 2016-12-05 11:19:28 -0700 | [diff] [blame] | 27 | import android.os.ServiceManager; |
Jeff Sharkey | 9f2f218 | 2016-12-21 09:18:33 -0700 | [diff] [blame] | 28 | import android.text.format.DateUtils; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 29 | import android.util.Slog; |
Jeff Sharkey | 790a4ec | 2015-04-09 13:18:44 -0700 | [diff] [blame] | 30 | |
Jeff Sharkey | 9f2f218 | 2016-12-21 09:18:33 -0700 | [diff] [blame] | 31 | import com.android.internal.os.BackgroundThread; |
Narayan Kamath | 29564cd | 2014-08-07 10:57:40 +0100 | [diff] [blame] | 32 | import com.android.server.SystemService; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 33 | |
Jeff Sharkey | fdeeeea | 2016-01-11 17:34:24 -0700 | [diff] [blame] | 34 | import dalvik.system.VMRuntime; |
| 35 | |
Jeff Sharkey | c98c7bc | 2016-12-07 14:57:34 -0700 | [diff] [blame] | 36 | public class Installer extends SystemService { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 37 | private static final String TAG = "Installer"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 38 | |
Todd Kennedy | fa54ab7 | 2015-09-25 07:46:12 -0700 | [diff] [blame] | 39 | /* *************************************************************************** |
| 40 | * IMPORTANT: These values are passed to native code. Keep them in sync with |
| 41 | * frameworks/native/cmds/installd/installd.h |
| 42 | * **************************************************************************/ |
| 43 | /** Application should be visible to everyone */ |
Andreas Gampe | bdd30d8 | 2016-03-20 11:32:11 -0700 | [diff] [blame] | 44 | public static final int DEXOPT_PUBLIC = 1 << 1; |
Todd Kennedy | fa54ab7 | 2015-09-25 07:46:12 -0700 | [diff] [blame] | 45 | /** Application wants to run in VM safe mode */ |
Andreas Gampe | bdd30d8 | 2016-03-20 11:32:11 -0700 | [diff] [blame] | 46 | public static final int DEXOPT_SAFEMODE = 1 << 2; |
Todd Kennedy | fa54ab7 | 2015-09-25 07:46:12 -0700 | [diff] [blame] | 47 | /** Application wants to allow debugging of its code */ |
Andreas Gampe | bdd30d8 | 2016-03-20 11:32:11 -0700 | [diff] [blame] | 48 | public static final int DEXOPT_DEBUGGABLE = 1 << 3; |
Todd Kennedy | fa54ab7 | 2015-09-25 07:46:12 -0700 | [diff] [blame] | 49 | /** The system boot has finished */ |
Andreas Gampe | bdd30d8 | 2016-03-20 11:32:11 -0700 | [diff] [blame] | 50 | public static final int DEXOPT_BOOTCOMPLETE = 1 << 4; |
| 51 | /** Hint that the dexopt type is profile-guided. */ |
| 52 | public static final int DEXOPT_PROFILE_GUIDED = 1 << 5; |
Todd Kennedy | fa54ab7 | 2015-09-25 07:46:12 -0700 | [diff] [blame] | 53 | |
Jeff Sharkey | 47f7108 | 2016-02-01 17:03:54 -0700 | [diff] [blame] | 54 | // NOTE: keep in sync with installd |
| 55 | public static final int FLAG_CLEAR_CACHE_ONLY = 1 << 8; |
| 56 | public static final int FLAG_CLEAR_CODE_CACHE_ONLY = 1 << 9; |
Jeff Sharkey | 5eb3eb5 | 2016-12-13 08:44:51 -0700 | [diff] [blame] | 57 | public static final int FLAG_USE_QUOTA = 1 << 12; |
Jeff Sharkey | fdeeeea | 2016-01-11 17:34:24 -0700 | [diff] [blame] | 58 | |
Jeff Sharkey | c98c7bc | 2016-12-07 14:57:34 -0700 | [diff] [blame] | 59 | private final boolean mIsolated; |
| 60 | |
Jeff Sharkey | 740f523 | 2016-12-09 14:31:26 -0700 | [diff] [blame] | 61 | private volatile IInstalld mInstalld; |
Jeff Sharkey | c8ddc2d | 2016-12-05 23:14:41 -0700 | [diff] [blame] | 62 | private volatile Object mWarnIfHeld; |
| 63 | |
Jeff Brown | b880d88 | 2014-02-10 19:47:07 -0800 | [diff] [blame] | 64 | public Installer(Context context) { |
Jeff Sharkey | c98c7bc | 2016-12-07 14:57:34 -0700 | [diff] [blame] | 65 | this(context, false); |
Jeff Brown | b880d88 | 2014-02-10 19:47:07 -0800 | [diff] [blame] | 66 | } |
| 67 | |
Jeff Sharkey | c98c7bc | 2016-12-07 14:57:34 -0700 | [diff] [blame] | 68 | /** |
| 69 | * @param isolated indicates if this object should <em>not</em> connect to |
| 70 | * the real {@code installd}. All remote calls will be ignored |
| 71 | * unless you extend this class and intercept them. |
| 72 | */ |
| 73 | public Installer(Context context, boolean isolated) { |
Andreas Gampe | d15300c | 2016-06-23 20:27:12 -0700 | [diff] [blame] | 74 | super(context); |
Jeff Sharkey | c98c7bc | 2016-12-07 14:57:34 -0700 | [diff] [blame] | 75 | mIsolated = isolated; |
Andreas Gampe | d15300c | 2016-06-23 20:27:12 -0700 | [diff] [blame] | 76 | } |
| 77 | |
Jeff Sharkey | 8948c01 | 2015-11-03 12:33:54 -0800 | [diff] [blame] | 78 | /** |
| 79 | * Yell loudly if someone tries making future calls while holding a lock on |
| 80 | * the given object. |
| 81 | */ |
| 82 | public void setWarnIfHeld(Object warnIfHeld) { |
Jeff Sharkey | c8ddc2d | 2016-12-05 23:14:41 -0700 | [diff] [blame] | 83 | mWarnIfHeld = warnIfHeld; |
Jeff Sharkey | 8948c01 | 2015-11-03 12:33:54 -0800 | [diff] [blame] | 84 | } |
| 85 | |
Jeff Brown | 6f357d3 | 2014-01-15 20:40:55 -0800 | [diff] [blame] | 86 | @Override |
| 87 | public void onStart() { |
Jeff Sharkey | 740f523 | 2016-12-09 14:31:26 -0700 | [diff] [blame] | 88 | if (mIsolated) { |
| 89 | mInstalld = null; |
| 90 | } else { |
Jeff Sharkey | 9f2f218 | 2016-12-21 09:18:33 -0700 | [diff] [blame] | 91 | connect(); |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | private void connect() { |
| 96 | IBinder binder = ServiceManager.getService("installd"); |
| 97 | if (binder != null) { |
| 98 | try { |
| 99 | binder.linkToDeath(new DeathRecipient() { |
| 100 | @Override |
| 101 | public void binderDied() { |
| 102 | Slog.w(TAG, "installd died; reconnecting"); |
| 103 | connect(); |
| 104 | } |
| 105 | }, 0); |
| 106 | } catch (RemoteException e) { |
| 107 | binder = null; |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | if (binder != null) { |
| 112 | mInstalld = IInstalld.Stub.asInterface(binder); |
| 113 | } else { |
| 114 | Slog.w(TAG, "installd not found; trying again"); |
| 115 | BackgroundThread.getHandler().postDelayed(() -> { |
| 116 | connect(); |
| 117 | }, DateUtils.SECOND_IN_MILLIS); |
Jeff Sharkey | c98c7bc | 2016-12-07 14:57:34 -0700 | [diff] [blame] | 118 | } |
Jeff Brown | 6f357d3 | 2014-01-15 20:40:55 -0800 | [diff] [blame] | 119 | } |
| 120 | |
Jeff Sharkey | c98c7bc | 2016-12-07 14:57:34 -0700 | [diff] [blame] | 121 | /** |
| 122 | * Do several pre-flight checks before making a remote call. |
| 123 | * |
| 124 | * @return if the remote call should continue. |
| 125 | */ |
| 126 | private boolean checkBeforeRemote() { |
Jeff Sharkey | c8ddc2d | 2016-12-05 23:14:41 -0700 | [diff] [blame] | 127 | if (mWarnIfHeld != null && Thread.holdsLock(mWarnIfHeld)) { |
| 128 | Slog.wtf(TAG, "Calling thread " + Thread.currentThread().getName() + " is holding 0x" |
| 129 | + Integer.toHexString(System.identityHashCode(mWarnIfHeld)), new Throwable()); |
| 130 | } |
Jeff Sharkey | c98c7bc | 2016-12-07 14:57:34 -0700 | [diff] [blame] | 131 | if (mIsolated) { |
| 132 | Slog.i(TAG, "Ignoring request because this installer is isolated"); |
| 133 | return false; |
| 134 | } else { |
| 135 | return true; |
| 136 | } |
Jeff Sharkey | c8ddc2d | 2016-12-05 23:14:41 -0700 | [diff] [blame] | 137 | } |
| 138 | |
Jeff Sharkey | 1c6f723 | 2016-12-19 16:39:02 -0700 | [diff] [blame] | 139 | public long createAppData(String uuid, String packageName, int userId, int flags, int appId, |
Jeff Sharkey | c8ddc2d | 2016-12-05 23:14:41 -0700 | [diff] [blame] | 140 | String seInfo, int targetSdkVersion) throws InstallerException { |
Jeff Sharkey | 1c6f723 | 2016-12-19 16:39:02 -0700 | [diff] [blame] | 141 | if (!checkBeforeRemote()) return -1; |
Jeff Sharkey | c8ddc2d | 2016-12-05 23:14:41 -0700 | [diff] [blame] | 142 | try { |
Jeff Sharkey | 1c6f723 | 2016-12-19 16:39:02 -0700 | [diff] [blame] | 143 | return mInstalld.createAppData(uuid, packageName, userId, flags, appId, seInfo, |
Jeff Sharkey | 70b4d10 | 2016-12-05 11:19:28 -0700 | [diff] [blame] | 144 | targetSdkVersion); |
Jeff Sharkey | 447a3ac | 2016-12-12 10:15:37 -0700 | [diff] [blame] | 145 | } catch (Exception e) { |
Jeff Sharkey | 740f523 | 2016-12-09 14:31:26 -0700 | [diff] [blame] | 146 | throw InstallerException.from(e); |
Jeff Sharkey | 70b4d10 | 2016-12-05 11:19:28 -0700 | [diff] [blame] | 147 | } |
Jeff Sharkey | 790a4ec | 2015-04-09 13:18:44 -0700 | [diff] [blame] | 148 | } |
| 149 | |
Jeff Sharkey | 019ac85 | 2016-12-05 23:39:46 -0700 | [diff] [blame] | 150 | public void restoreconAppData(String uuid, String packageName, int userId, int flags, int appId, |
| 151 | String seInfo) throws InstallerException { |
Jeff Sharkey | c98c7bc | 2016-12-07 14:57:34 -0700 | [diff] [blame] | 152 | if (!checkBeforeRemote()) return; |
Jeff Sharkey | 019ac85 | 2016-12-05 23:39:46 -0700 | [diff] [blame] | 153 | try { |
| 154 | mInstalld.restoreconAppData(uuid, packageName, userId, flags, appId, seInfo); |
Jeff Sharkey | 447a3ac | 2016-12-12 10:15:37 -0700 | [diff] [blame] | 155 | } catch (Exception e) { |
Jeff Sharkey | 740f523 | 2016-12-09 14:31:26 -0700 | [diff] [blame] | 156 | throw InstallerException.from(e); |
Jeff Sharkey | 019ac85 | 2016-12-05 23:39:46 -0700 | [diff] [blame] | 157 | } |
Jeff Sharkey | 790a4ec | 2015-04-09 13:18:44 -0700 | [diff] [blame] | 158 | } |
| 159 | |
Jeff Sharkey | 019ac85 | 2016-12-05 23:39:46 -0700 | [diff] [blame] | 160 | public void migrateAppData(String uuid, String packageName, int userId, int flags) |
Jeff Sharkey | e469713 | 2016-02-06 19:46:15 -0700 | [diff] [blame] | 161 | throws InstallerException { |
Jeff Sharkey | c98c7bc | 2016-12-07 14:57:34 -0700 | [diff] [blame] | 162 | if (!checkBeforeRemote()) return; |
Jeff Sharkey | 019ac85 | 2016-12-05 23:39:46 -0700 | [diff] [blame] | 163 | try { |
| 164 | mInstalld.migrateAppData(uuid, packageName, userId, flags); |
Jeff Sharkey | 447a3ac | 2016-12-12 10:15:37 -0700 | [diff] [blame] | 165 | } catch (Exception e) { |
Jeff Sharkey | 740f523 | 2016-12-09 14:31:26 -0700 | [diff] [blame] | 166 | throw InstallerException.from(e); |
Jeff Sharkey | 019ac85 | 2016-12-05 23:39:46 -0700 | [diff] [blame] | 167 | } |
Jeff Sharkey | e469713 | 2016-02-06 19:46:15 -0700 | [diff] [blame] | 168 | } |
| 169 | |
Jeff Sharkey | 019ac85 | 2016-12-05 23:39:46 -0700 | [diff] [blame] | 170 | public void clearAppData(String uuid, String packageName, int userId, int flags, |
| 171 | long ceDataInode) throws InstallerException { |
Jeff Sharkey | c98c7bc | 2016-12-07 14:57:34 -0700 | [diff] [blame] | 172 | if (!checkBeforeRemote()) return; |
Jeff Sharkey | 019ac85 | 2016-12-05 23:39:46 -0700 | [diff] [blame] | 173 | try { |
| 174 | mInstalld.clearAppData(uuid, packageName, userId, flags, ceDataInode); |
Jeff Sharkey | 447a3ac | 2016-12-12 10:15:37 -0700 | [diff] [blame] | 175 | } catch (Exception e) { |
Jeff Sharkey | 740f523 | 2016-12-09 14:31:26 -0700 | [diff] [blame] | 176 | throw InstallerException.from(e); |
Jeff Sharkey | 019ac85 | 2016-12-05 23:39:46 -0700 | [diff] [blame] | 177 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 178 | } |
| 179 | |
Jeff Sharkey | 019ac85 | 2016-12-05 23:39:46 -0700 | [diff] [blame] | 180 | public void destroyAppData(String uuid, String packageName, int userId, int flags, |
| 181 | long ceDataInode) throws InstallerException { |
Jeff Sharkey | c98c7bc | 2016-12-07 14:57:34 -0700 | [diff] [blame] | 182 | if (!checkBeforeRemote()) return; |
Jeff Sharkey | 019ac85 | 2016-12-05 23:39:46 -0700 | [diff] [blame] | 183 | try { |
| 184 | mInstalld.destroyAppData(uuid, packageName, userId, flags, ceDataInode); |
Jeff Sharkey | 447a3ac | 2016-12-12 10:15:37 -0700 | [diff] [blame] | 185 | } catch (Exception e) { |
Jeff Sharkey | 740f523 | 2016-12-09 14:31:26 -0700 | [diff] [blame] | 186 | throw InstallerException.from(e); |
Jeff Sharkey | 019ac85 | 2016-12-05 23:39:46 -0700 | [diff] [blame] | 187 | } |
Dave Allison | 0efbd9a | 2014-01-30 14:19:51 -0800 | [diff] [blame] | 188 | } |
| 189 | |
Jeff Sharkey | c8ddc2d | 2016-12-05 23:14:41 -0700 | [diff] [blame] | 190 | public void moveCompleteApp(String fromUuid, String toUuid, String packageName, |
| 191 | String dataAppName, int appId, String seInfo, int targetSdkVersion) |
Janis Danisevskis | f340974 | 2016-01-12 14:46:33 +0000 | [diff] [blame] | 192 | throws InstallerException { |
Jeff Sharkey | c98c7bc | 2016-12-07 14:57:34 -0700 | [diff] [blame] | 193 | if (!checkBeforeRemote()) return; |
Jeff Sharkey | c8ddc2d | 2016-12-05 23:14:41 -0700 | [diff] [blame] | 194 | try { |
| 195 | mInstalld.moveCompleteApp(fromUuid, toUuid, packageName, dataAppName, appId, seInfo, |
| 196 | targetSdkVersion); |
Jeff Sharkey | 447a3ac | 2016-12-12 10:15:37 -0700 | [diff] [blame] | 197 | } catch (Exception e) { |
Jeff Sharkey | 740f523 | 2016-12-09 14:31:26 -0700 | [diff] [blame] | 198 | throw InstallerException.from(e); |
Jeff Sharkey | c8ddc2d | 2016-12-05 23:14:41 -0700 | [diff] [blame] | 199 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 200 | } |
| 201 | |
Jeff Sharkey | 82ca901 | 2017-01-08 17:06:58 -0700 | [diff] [blame] | 202 | public void getAppSize(String uuid, String[] packageNames, int userId, int flags, int appId, |
| 203 | long[] ceDataInodes, String[] codePaths, PackageStats stats) |
Jeff Sharkey | 5eb3eb5 | 2016-12-13 08:44:51 -0700 | [diff] [blame] | 204 | throws InstallerException { |
Jeff Sharkey | c98c7bc | 2016-12-07 14:57:34 -0700 | [diff] [blame] | 205 | if (!checkBeforeRemote()) return; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 206 | try { |
Jeff Sharkey | 82ca901 | 2017-01-08 17:06:58 -0700 | [diff] [blame] | 207 | final long[] res = mInstalld.getAppSize(uuid, packageNames, userId, flags, |
| 208 | appId, ceDataInodes, codePaths); |
Jeff Sharkey | 740f523 | 2016-12-09 14:31:26 -0700 | [diff] [blame] | 209 | stats.codeSize += res[0]; |
| 210 | stats.dataSize += res[1]; |
| 211 | stats.cacheSize += res[2]; |
Jeff Sharkey | 82ca901 | 2017-01-08 17:06:58 -0700 | [diff] [blame] | 212 | stats.externalCodeSize += res[3]; |
| 213 | stats.externalDataSize += res[4]; |
| 214 | stats.externalCacheSize += res[5]; |
| 215 | } catch (Exception e) { |
| 216 | throw InstallerException.from(e); |
| 217 | } |
| 218 | } |
| 219 | |
| 220 | public void getUserSize(String uuid, int userId, int flags, int[] appIds, PackageStats stats) |
| 221 | throws InstallerException { |
| 222 | if (!checkBeforeRemote()) return; |
| 223 | try { |
| 224 | final long[] res = mInstalld.getUserSize(uuid, userId, flags, appIds); |
| 225 | stats.codeSize += res[0]; |
| 226 | stats.dataSize += res[1]; |
| 227 | stats.cacheSize += res[2]; |
| 228 | stats.externalCodeSize += res[3]; |
| 229 | stats.externalDataSize += res[4]; |
| 230 | stats.externalCacheSize += res[5]; |
| 231 | } catch (Exception e) { |
| 232 | throw InstallerException.from(e); |
| 233 | } |
| 234 | } |
| 235 | |
| 236 | public long[] getExternalSize(String uuid, int userId, int flags) throws InstallerException { |
| 237 | if (!checkBeforeRemote()) return new long[4]; |
| 238 | try { |
| 239 | return mInstalld.getExternalSize(uuid, userId, flags); |
Jeff Sharkey | 447a3ac | 2016-12-12 10:15:37 -0700 | [diff] [blame] | 240 | } catch (Exception e) { |
Jeff Sharkey | 740f523 | 2016-12-09 14:31:26 -0700 | [diff] [blame] | 241 | throw InstallerException.from(e); |
Jeff Sharkey | 4288419 | 2016-04-09 16:12:01 -0600 | [diff] [blame] | 242 | } |
| 243 | } |
| 244 | |
Jeff Sharkey | c98c7bc | 2016-12-07 14:57:34 -0700 | [diff] [blame] | 245 | public void dexopt(String apkPath, int uid, @Nullable String pkgName, String instructionSet, |
Calin Juravle | db4a79a | 2015-12-23 18:55:08 +0200 | [diff] [blame] | 246 | int dexoptNeeded, @Nullable String outputPath, int dexFlags, |
Jeff Sharkey | c98c7bc | 2016-12-07 14:57:34 -0700 | [diff] [blame] | 247 | String compilerFilter, @Nullable String volumeUuid, @Nullable String sharedLibraries) |
Jeff Hao | c7b9482 | 2016-03-16 15:56:07 -0700 | [diff] [blame] | 248 | throws InstallerException { |
Jeff Sharkey | fdeeeea | 2016-01-11 17:34:24 -0700 | [diff] [blame] | 249 | assertValidInstructionSet(instructionSet); |
Jeff Sharkey | c98c7bc | 2016-12-07 14:57:34 -0700 | [diff] [blame] | 250 | if (!checkBeforeRemote()) return; |
Jeff Sharkey | 740f523 | 2016-12-09 14:31:26 -0700 | [diff] [blame] | 251 | try { |
| 252 | mInstalld.dexopt(apkPath, uid, pkgName, instructionSet, dexoptNeeded, outputPath, |
| 253 | dexFlags, compilerFilter, volumeUuid, sharedLibraries); |
Jeff Sharkey | 447a3ac | 2016-12-12 10:15:37 -0700 | [diff] [blame] | 254 | } catch (Exception e) { |
Jeff Sharkey | 740f523 | 2016-12-09 14:31:26 -0700 | [diff] [blame] | 255 | throw InstallerException.from(e); |
| 256 | } |
Andreas Gampe | bdd30d8 | 2016-03-20 11:32:11 -0700 | [diff] [blame] | 257 | } |
| 258 | |
Jeff Sharkey | c24fa02 | 2016-12-07 10:37:47 -0700 | [diff] [blame] | 259 | public boolean mergeProfiles(int uid, String packageName) throws InstallerException { |
Jeff Sharkey | c98c7bc | 2016-12-07 14:57:34 -0700 | [diff] [blame] | 260 | if (!checkBeforeRemote()) return false; |
Jeff Sharkey | c24fa02 | 2016-12-07 10:37:47 -0700 | [diff] [blame] | 261 | try { |
| 262 | return mInstalld.mergeProfiles(uid, packageName); |
Jeff Sharkey | 447a3ac | 2016-12-12 10:15:37 -0700 | [diff] [blame] | 263 | } catch (Exception e) { |
Jeff Sharkey | 740f523 | 2016-12-09 14:31:26 -0700 | [diff] [blame] | 264 | throw InstallerException.from(e); |
Jeff Sharkey | c24fa02 | 2016-12-07 10:37:47 -0700 | [diff] [blame] | 265 | } |
Jeff Sharkey | fdeeeea | 2016-01-11 17:34:24 -0700 | [diff] [blame] | 266 | } |
| 267 | |
Jeff Sharkey | c24fa02 | 2016-12-07 10:37:47 -0700 | [diff] [blame] | 268 | public boolean dumpProfiles(int uid, String packageName, String codePaths) |
David Sehr | a877708 | 2016-05-24 15:25:23 -0700 | [diff] [blame] | 269 | throws InstallerException { |
Jeff Sharkey | c98c7bc | 2016-12-07 14:57:34 -0700 | [diff] [blame] | 270 | if (!checkBeforeRemote()) return false; |
Jeff Sharkey | c24fa02 | 2016-12-07 10:37:47 -0700 | [diff] [blame] | 271 | try { |
| 272 | return mInstalld.dumpProfiles(uid, packageName, codePaths); |
Jeff Sharkey | 447a3ac | 2016-12-12 10:15:37 -0700 | [diff] [blame] | 273 | } catch (Exception e) { |
Jeff Sharkey | 740f523 | 2016-12-09 14:31:26 -0700 | [diff] [blame] | 274 | throw InstallerException.from(e); |
Jeff Sharkey | c24fa02 | 2016-12-07 10:37:47 -0700 | [diff] [blame] | 275 | } |
David Sehr | a877708 | 2016-05-24 15:25:23 -0700 | [diff] [blame] | 276 | } |
| 277 | |
Jeff Sharkey | fdeeeea | 2016-01-11 17:34:24 -0700 | [diff] [blame] | 278 | public void idmap(String targetApkPath, String overlayApkPath, int uid) |
| 279 | throws InstallerException { |
Jeff Sharkey | c98c7bc | 2016-12-07 14:57:34 -0700 | [diff] [blame] | 280 | if (!checkBeforeRemote()) return; |
Jeff Sharkey | c24fa02 | 2016-12-07 10:37:47 -0700 | [diff] [blame] | 281 | try { |
| 282 | mInstalld.idmap(targetApkPath, overlayApkPath, uid); |
Jeff Sharkey | 447a3ac | 2016-12-12 10:15:37 -0700 | [diff] [blame] | 283 | } catch (Exception e) { |
Jeff Sharkey | 740f523 | 2016-12-09 14:31:26 -0700 | [diff] [blame] | 284 | throw InstallerException.from(e); |
Jeff Sharkey | c24fa02 | 2016-12-07 10:37:47 -0700 | [diff] [blame] | 285 | } |
Jeff Sharkey | fdeeeea | 2016-01-11 17:34:24 -0700 | [diff] [blame] | 286 | } |
| 287 | |
| 288 | public void rmdex(String codePath, String instructionSet) throws InstallerException { |
| 289 | assertValidInstructionSet(instructionSet); |
Jeff Sharkey | c98c7bc | 2016-12-07 14:57:34 -0700 | [diff] [blame] | 290 | if (!checkBeforeRemote()) return; |
Jeff Sharkey | c24fa02 | 2016-12-07 10:37:47 -0700 | [diff] [blame] | 291 | try { |
| 292 | mInstalld.rmdex(codePath, instructionSet); |
Jeff Sharkey | 447a3ac | 2016-12-12 10:15:37 -0700 | [diff] [blame] | 293 | } catch (Exception e) { |
Jeff Sharkey | 740f523 | 2016-12-09 14:31:26 -0700 | [diff] [blame] | 294 | throw InstallerException.from(e); |
Jeff Sharkey | c24fa02 | 2016-12-07 10:37:47 -0700 | [diff] [blame] | 295 | } |
Jeff Sharkey | fdeeeea | 2016-01-11 17:34:24 -0700 | [diff] [blame] | 296 | } |
| 297 | |
| 298 | public void rmPackageDir(String packageDir) throws InstallerException { |
Jeff Sharkey | c98c7bc | 2016-12-07 14:57:34 -0700 | [diff] [blame] | 299 | if (!checkBeforeRemote()) return; |
Jeff Sharkey | c24fa02 | 2016-12-07 10:37:47 -0700 | [diff] [blame] | 300 | try { |
| 301 | mInstalld.rmPackageDir(packageDir); |
Jeff Sharkey | 447a3ac | 2016-12-12 10:15:37 -0700 | [diff] [blame] | 302 | } catch (Exception e) { |
Jeff Sharkey | 740f523 | 2016-12-09 14:31:26 -0700 | [diff] [blame] | 303 | throw InstallerException.from(e); |
Jeff Sharkey | c24fa02 | 2016-12-07 10:37:47 -0700 | [diff] [blame] | 304 | } |
Jeff Sharkey | fdeeeea | 2016-01-11 17:34:24 -0700 | [diff] [blame] | 305 | } |
| 306 | |
Jeff Sharkey | c24fa02 | 2016-12-07 10:37:47 -0700 | [diff] [blame] | 307 | public void clearAppProfiles(String packageName) throws InstallerException { |
Jeff Sharkey | c98c7bc | 2016-12-07 14:57:34 -0700 | [diff] [blame] | 308 | if (!checkBeforeRemote()) return; |
Jeff Sharkey | c24fa02 | 2016-12-07 10:37:47 -0700 | [diff] [blame] | 309 | try { |
| 310 | mInstalld.clearAppProfiles(packageName); |
Jeff Sharkey | 447a3ac | 2016-12-12 10:15:37 -0700 | [diff] [blame] | 311 | } catch (Exception e) { |
Jeff Sharkey | 740f523 | 2016-12-09 14:31:26 -0700 | [diff] [blame] | 312 | throw InstallerException.from(e); |
Jeff Sharkey | c24fa02 | 2016-12-07 10:37:47 -0700 | [diff] [blame] | 313 | } |
Calin Juravle | d6d27e3 | 2016-03-23 13:59:18 +0000 | [diff] [blame] | 314 | } |
| 315 | |
Jeff Sharkey | c24fa02 | 2016-12-07 10:37:47 -0700 | [diff] [blame] | 316 | public void destroyAppProfiles(String packageName) throws InstallerException { |
Jeff Sharkey | c98c7bc | 2016-12-07 14:57:34 -0700 | [diff] [blame] | 317 | if (!checkBeforeRemote()) return; |
Jeff Sharkey | c24fa02 | 2016-12-07 10:37:47 -0700 | [diff] [blame] | 318 | try { |
| 319 | mInstalld.destroyAppProfiles(packageName); |
Jeff Sharkey | 447a3ac | 2016-12-12 10:15:37 -0700 | [diff] [blame] | 320 | } catch (Exception e) { |
Jeff Sharkey | 740f523 | 2016-12-09 14:31:26 -0700 | [diff] [blame] | 321 | throw InstallerException.from(e); |
Jeff Sharkey | c24fa02 | 2016-12-07 10:37:47 -0700 | [diff] [blame] | 322 | } |
David Brazdil | 9aa6db0 | 2016-03-08 12:57:12 +0000 | [diff] [blame] | 323 | } |
| 324 | |
Jeff Sharkey | fcf1e55 | 2016-04-14 20:44:58 -0600 | [diff] [blame] | 325 | public void createUserData(String uuid, int userId, int userSerial, int flags) |
| 326 | throws InstallerException { |
Jeff Sharkey | c98c7bc | 2016-12-07 14:57:34 -0700 | [diff] [blame] | 327 | if (!checkBeforeRemote()) return; |
Jeff Sharkey | 019ac85 | 2016-12-05 23:39:46 -0700 | [diff] [blame] | 328 | try { |
| 329 | mInstalld.createUserData(uuid, userId, userSerial, flags); |
Jeff Sharkey | 447a3ac | 2016-12-12 10:15:37 -0700 | [diff] [blame] | 330 | } catch (Exception e) { |
Jeff Sharkey | 740f523 | 2016-12-09 14:31:26 -0700 | [diff] [blame] | 331 | throw InstallerException.from(e); |
Jeff Sharkey | 019ac85 | 2016-12-05 23:39:46 -0700 | [diff] [blame] | 332 | } |
Jeff Sharkey | fdeeeea | 2016-01-11 17:34:24 -0700 | [diff] [blame] | 333 | } |
| 334 | |
Jeff Sharkey | fcf1e55 | 2016-04-14 20:44:58 -0600 | [diff] [blame] | 335 | public void destroyUserData(String uuid, int userId, int flags) throws InstallerException { |
Jeff Sharkey | c98c7bc | 2016-12-07 14:57:34 -0700 | [diff] [blame] | 336 | if (!checkBeforeRemote()) return; |
Jeff Sharkey | 019ac85 | 2016-12-05 23:39:46 -0700 | [diff] [blame] | 337 | try { |
| 338 | mInstalld.destroyUserData(uuid, userId, flags); |
Jeff Sharkey | 447a3ac | 2016-12-12 10:15:37 -0700 | [diff] [blame] | 339 | } catch (Exception e) { |
Jeff Sharkey | 740f523 | 2016-12-09 14:31:26 -0700 | [diff] [blame] | 340 | throw InstallerException.from(e); |
Jeff Sharkey | 019ac85 | 2016-12-05 23:39:46 -0700 | [diff] [blame] | 341 | } |
Jeff Sharkey | fdeeeea | 2016-01-11 17:34:24 -0700 | [diff] [blame] | 342 | } |
| 343 | |
| 344 | public void markBootComplete(String instructionSet) throws InstallerException { |
| 345 | assertValidInstructionSet(instructionSet); |
Jeff Sharkey | c98c7bc | 2016-12-07 14:57:34 -0700 | [diff] [blame] | 346 | if (!checkBeforeRemote()) return; |
Jeff Sharkey | c24fa02 | 2016-12-07 10:37:47 -0700 | [diff] [blame] | 347 | try { |
| 348 | mInstalld.markBootComplete(instructionSet); |
Jeff Sharkey | 447a3ac | 2016-12-12 10:15:37 -0700 | [diff] [blame] | 349 | } catch (Exception e) { |
Jeff Sharkey | 740f523 | 2016-12-09 14:31:26 -0700 | [diff] [blame] | 350 | throw InstallerException.from(e); |
Jeff Sharkey | c24fa02 | 2016-12-07 10:37:47 -0700 | [diff] [blame] | 351 | } |
Jeff Sharkey | fdeeeea | 2016-01-11 17:34:24 -0700 | [diff] [blame] | 352 | } |
| 353 | |
| 354 | public void freeCache(String uuid, long freeStorageSize) throws InstallerException { |
Jeff Sharkey | c98c7bc | 2016-12-07 14:57:34 -0700 | [diff] [blame] | 355 | if (!checkBeforeRemote()) return; |
Jeff Sharkey | c24fa02 | 2016-12-07 10:37:47 -0700 | [diff] [blame] | 356 | try { |
| 357 | mInstalld.freeCache(uuid, freeStorageSize); |
Jeff Sharkey | 447a3ac | 2016-12-12 10:15:37 -0700 | [diff] [blame] | 358 | } catch (Exception e) { |
Jeff Sharkey | 740f523 | 2016-12-09 14:31:26 -0700 | [diff] [blame] | 359 | throw InstallerException.from(e); |
Jeff Sharkey | c24fa02 | 2016-12-07 10:37:47 -0700 | [diff] [blame] | 360 | } |
Jeff Sharkey | fdeeeea | 2016-01-11 17:34:24 -0700 | [diff] [blame] | 361 | } |
| 362 | |
Kenny Root | ddbe50d | 2012-09-06 13:18:37 -0700 | [diff] [blame] | 363 | /** |
Jeff Sharkey | fdeeeea | 2016-01-11 17:34:24 -0700 | [diff] [blame] | 364 | * Links the 32 bit native library directory in an application's data |
| 365 | * directory to the real location for backward compatibility. Note that no |
| 366 | * such symlink is created for 64 bit shared libraries. |
Kenny Root | ddbe50d | 2012-09-06 13:18:37 -0700 | [diff] [blame] | 367 | */ |
Jeff Sharkey | c24fa02 | 2016-12-07 10:37:47 -0700 | [diff] [blame] | 368 | public void linkNativeLibraryDirectory(String uuid, String packageName, String nativeLibPath32, |
Jeff Sharkey | fdeeeea | 2016-01-11 17:34:24 -0700 | [diff] [blame] | 369 | int userId) throws InstallerException { |
Jeff Sharkey | c98c7bc | 2016-12-07 14:57:34 -0700 | [diff] [blame] | 370 | if (!checkBeforeRemote()) return; |
Jeff Sharkey | c24fa02 | 2016-12-07 10:37:47 -0700 | [diff] [blame] | 371 | try { |
| 372 | mInstalld.linkNativeLibraryDirectory(uuid, packageName, nativeLibPath32, userId); |
Jeff Sharkey | 447a3ac | 2016-12-12 10:15:37 -0700 | [diff] [blame] | 373 | } catch (Exception e) { |
Jeff Sharkey | 740f523 | 2016-12-09 14:31:26 -0700 | [diff] [blame] | 374 | throw InstallerException.from(e); |
Jeff Sharkey | c24fa02 | 2016-12-07 10:37:47 -0700 | [diff] [blame] | 375 | } |
Kenny Root | 6a6b007 | 2010-10-07 16:46:10 -0700 | [diff] [blame] | 376 | } |
Robert Craig | 4385343 | 2014-03-04 11:57:23 -0500 | [diff] [blame] | 377 | |
Jeff Sharkey | fdeeeea | 2016-01-11 17:34:24 -0700 | [diff] [blame] | 378 | public void createOatDir(String oatDir, String dexInstructionSet) |
| 379 | throws InstallerException { |
Jeff Sharkey | c98c7bc | 2016-12-07 14:57:34 -0700 | [diff] [blame] | 380 | if (!checkBeforeRemote()) return; |
Jeff Sharkey | c24fa02 | 2016-12-07 10:37:47 -0700 | [diff] [blame] | 381 | try { |
| 382 | mInstalld.createOatDir(oatDir, dexInstructionSet); |
Jeff Sharkey | 447a3ac | 2016-12-12 10:15:37 -0700 | [diff] [blame] | 383 | } catch (Exception e) { |
Jeff Sharkey | 740f523 | 2016-12-09 14:31:26 -0700 | [diff] [blame] | 384 | throw InstallerException.from(e); |
Jeff Sharkey | c24fa02 | 2016-12-07 10:37:47 -0700 | [diff] [blame] | 385 | } |
Jeff Sharkey | 790a4ec | 2015-04-09 13:18:44 -0700 | [diff] [blame] | 386 | } |
| 387 | |
Jeff Sharkey | fdeeeea | 2016-01-11 17:34:24 -0700 | [diff] [blame] | 388 | public void linkFile(String relativePath, String fromBase, String toBase) |
| 389 | throws InstallerException { |
Jeff Sharkey | c98c7bc | 2016-12-07 14:57:34 -0700 | [diff] [blame] | 390 | if (!checkBeforeRemote()) return; |
Jeff Sharkey | c24fa02 | 2016-12-07 10:37:47 -0700 | [diff] [blame] | 391 | try { |
| 392 | mInstalld.linkFile(relativePath, fromBase, toBase); |
Jeff Sharkey | 447a3ac | 2016-12-12 10:15:37 -0700 | [diff] [blame] | 393 | } catch (Exception e) { |
Jeff Sharkey | 740f523 | 2016-12-09 14:31:26 -0700 | [diff] [blame] | 394 | throw InstallerException.from(e); |
Jeff Sharkey | c24fa02 | 2016-12-07 10:37:47 -0700 | [diff] [blame] | 395 | } |
Robert Craig | 4385343 | 2014-03-04 11:57:23 -0500 | [diff] [blame] | 396 | } |
Narayan Kamath | 6c4b9de | 2014-08-08 12:44:12 +0100 | [diff] [blame] | 397 | |
Andreas Gampe | abcbe2f | 2016-02-26 11:25:36 -0800 | [diff] [blame] | 398 | public void moveAb(String apkPath, String instructionSet, String outputPath) |
| 399 | throws InstallerException { |
Jeff Sharkey | c98c7bc | 2016-12-07 14:57:34 -0700 | [diff] [blame] | 400 | if (!checkBeforeRemote()) return; |
Jeff Sharkey | c24fa02 | 2016-12-07 10:37:47 -0700 | [diff] [blame] | 401 | try { |
| 402 | mInstalld.moveAb(apkPath, instructionSet, outputPath); |
Jeff Sharkey | 447a3ac | 2016-12-12 10:15:37 -0700 | [diff] [blame] | 403 | } catch (Exception e) { |
Jeff Sharkey | 740f523 | 2016-12-09 14:31:26 -0700 | [diff] [blame] | 404 | throw InstallerException.from(e); |
Jeff Sharkey | c24fa02 | 2016-12-07 10:37:47 -0700 | [diff] [blame] | 405 | } |
Andreas Gampe | abcbe2f | 2016-02-26 11:25:36 -0800 | [diff] [blame] | 406 | } |
| 407 | |
Andreas Gampe | 33c592d | 2016-09-09 17:08:53 -0700 | [diff] [blame] | 408 | public void deleteOdex(String apkPath, String instructionSet, String outputPath) |
| 409 | throws InstallerException { |
Jeff Sharkey | c98c7bc | 2016-12-07 14:57:34 -0700 | [diff] [blame] | 410 | if (!checkBeforeRemote()) return; |
Jeff Sharkey | c24fa02 | 2016-12-07 10:37:47 -0700 | [diff] [blame] | 411 | try { |
| 412 | mInstalld.deleteOdex(apkPath, instructionSet, outputPath); |
Jeff Sharkey | 447a3ac | 2016-12-12 10:15:37 -0700 | [diff] [blame] | 413 | } catch (Exception e) { |
Jeff Sharkey | 740f523 | 2016-12-09 14:31:26 -0700 | [diff] [blame] | 414 | throw InstallerException.from(e); |
Jeff Sharkey | c24fa02 | 2016-12-07 10:37:47 -0700 | [diff] [blame] | 415 | } |
Andreas Gampe | 33c592d | 2016-09-09 17:08:53 -0700 | [diff] [blame] | 416 | } |
| 417 | |
Jeff Sharkey | fdeeeea | 2016-01-11 17:34:24 -0700 | [diff] [blame] | 418 | private static void assertValidInstructionSet(String instructionSet) |
| 419 | throws InstallerException { |
Narayan Kamath | 6c4b9de | 2014-08-08 12:44:12 +0100 | [diff] [blame] | 420 | for (String abi : Build.SUPPORTED_ABIS) { |
Jeff Sharkey | fdeeeea | 2016-01-11 17:34:24 -0700 | [diff] [blame] | 421 | if (VMRuntime.getInstructionSet(abi).equals(instructionSet)) { |
| 422 | return; |
Narayan Kamath | 6c4b9de | 2014-08-08 12:44:12 +0100 | [diff] [blame] | 423 | } |
| 424 | } |
Jeff Sharkey | fdeeeea | 2016-01-11 17:34:24 -0700 | [diff] [blame] | 425 | throw new InstallerException("Invalid instruction set: " + instructionSet); |
Narayan Kamath | 6c4b9de | 2014-08-08 12:44:12 +0100 | [diff] [blame] | 426 | } |
Jeff Sharkey | 740f523 | 2016-12-09 14:31:26 -0700 | [diff] [blame] | 427 | |
| 428 | public static class InstallerException extends Exception { |
| 429 | public InstallerException(String detailMessage) { |
| 430 | super(detailMessage); |
| 431 | } |
| 432 | |
| 433 | public static InstallerException from(Exception e) throws InstallerException { |
Jeff Sharkey | 447a3ac | 2016-12-12 10:15:37 -0700 | [diff] [blame] | 434 | throw new InstallerException(e.toString()); |
Jeff Sharkey | 740f523 | 2016-12-09 14:31:26 -0700 | [diff] [blame] | 435 | } |
| 436 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 437 | } |