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 | |
Calin Juravle | 3621be7 | 2018-01-18 15:17:29 -0800 | [diff] [blame] | 19 | import android.annotation.AppIdInt; |
Victor Hsieh | 5f76124 | 2018-01-20 10:30:12 -0800 | [diff] [blame] | 20 | import android.annotation.NonNull; |
Fyodor Kupolov | b94c165 | 2015-03-03 12:25:30 -0800 | [diff] [blame] | 21 | import android.annotation.Nullable; |
Calin Juravle | 3621be7 | 2018-01-18 15:17:29 -0800 | [diff] [blame] | 22 | import android.annotation.UserIdInt; |
Jeff Brown | b880d88 | 2014-02-10 19:47:07 -0800 | [diff] [blame] | 23 | import android.content.Context; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 24 | import android.content.pm.PackageStats; |
Narayan Kamath | 29564cd | 2014-08-07 10:57:40 +0100 | [diff] [blame] | 25 | import android.os.Build; |
Jeff Sharkey | 9f2f218 | 2016-12-21 09:18:33 -0700 | [diff] [blame] | 26 | import android.os.IBinder; |
| 27 | import android.os.IBinder.DeathRecipient; |
Jeff Sharkey | 70b4d10 | 2016-12-05 11:19:28 -0700 | [diff] [blame] | 28 | import android.os.IInstalld; |
Jeff Sharkey | 9f2f218 | 2016-12-21 09:18:33 -0700 | [diff] [blame] | 29 | import android.os.RemoteException; |
Jeff Sharkey | 70b4d10 | 2016-12-05 11:19:28 -0700 | [diff] [blame] | 30 | import android.os.ServiceManager; |
Jeff Sharkey | 9f2f218 | 2016-12-21 09:18:33 -0700 | [diff] [blame] | 31 | import android.text.format.DateUtils; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 32 | import android.util.Slog; |
Jeff Sharkey | 790a4ec | 2015-04-09 13:18:44 -0700 | [diff] [blame] | 33 | |
Jeff Sharkey | 9f2f218 | 2016-12-21 09:18:33 -0700 | [diff] [blame] | 34 | import com.android.internal.os.BackgroundThread; |
Narayan Kamath | 29564cd | 2014-08-07 10:57:40 +0100 | [diff] [blame] | 35 | import com.android.server.SystemService; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 36 | |
Jeff Sharkey | dd02e33 | 2018-06-27 14:41:57 -0600 | [diff] [blame] | 37 | import dalvik.system.BlockGuard; |
Jeff Sharkey | fdeeeea | 2016-01-11 17:34:24 -0700 | [diff] [blame] | 38 | import dalvik.system.VMRuntime; |
| 39 | |
Victor Hsieh | 55f1499 | 2018-01-13 14:12:59 -0800 | [diff] [blame] | 40 | import java.io.FileDescriptor; |
| 41 | |
Jeff Sharkey | c98c7bc | 2016-12-07 14:57:34 -0700 | [diff] [blame] | 42 | public class Installer extends SystemService { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 43 | private static final String TAG = "Installer"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 44 | |
Todd Kennedy | fa54ab7 | 2015-09-25 07:46:12 -0700 | [diff] [blame] | 45 | /* *************************************************************************** |
| 46 | * IMPORTANT: These values are passed to native code. Keep them in sync with |
Mathew Inwood | 3c8277d | 2018-03-09 14:06:08 +0000 | [diff] [blame] | 47 | * frameworks/native/cmds/installd/installd_constants.h |
Todd Kennedy | fa54ab7 | 2015-09-25 07:46:12 -0700 | [diff] [blame] | 48 | * **************************************************************************/ |
| 49 | /** Application should be visible to everyone */ |
Andreas Gampe | bdd30d8 | 2016-03-20 11:32:11 -0700 | [diff] [blame] | 50 | public static final int DEXOPT_PUBLIC = 1 << 1; |
Todd Kennedy | fa54ab7 | 2015-09-25 07:46:12 -0700 | [diff] [blame] | 51 | /** Application wants to allow debugging of its code */ |
Nicolas Geoffray | 56123ba | 2017-05-05 14:30:02 +0100 | [diff] [blame] | 52 | public static final int DEXOPT_DEBUGGABLE = 1 << 2; |
Todd Kennedy | fa54ab7 | 2015-09-25 07:46:12 -0700 | [diff] [blame] | 53 | /** The system boot has finished */ |
Nicolas Geoffray | 56123ba | 2017-05-05 14:30:02 +0100 | [diff] [blame] | 54 | public static final int DEXOPT_BOOTCOMPLETE = 1 << 3; |
Andreas Gampe | bdd30d8 | 2016-03-20 11:32:11 -0700 | [diff] [blame] | 55 | /** Hint that the dexopt type is profile-guided. */ |
Nicolas Geoffray | 56123ba | 2017-05-05 14:30:02 +0100 | [diff] [blame] | 56 | public static final int DEXOPT_PROFILE_GUIDED = 1 << 4; |
Calin Juravle | c22c30e | 2017-01-16 19:18:48 -0800 | [diff] [blame] | 57 | /** The compilation is for a secondary dex file. */ |
Nicolas Geoffray | 56123ba | 2017-05-05 14:30:02 +0100 | [diff] [blame] | 58 | public static final int DEXOPT_SECONDARY_DEX = 1 << 5; |
Calin Juravle | c22c30e | 2017-01-16 19:18:48 -0800 | [diff] [blame] | 59 | /** Ignore the result of dexoptNeeded and force compilation. */ |
Nicolas Geoffray | 56123ba | 2017-05-05 14:30:02 +0100 | [diff] [blame] | 60 | public static final int DEXOPT_FORCE = 1 << 6; |
Calin Juravle | c22c30e | 2017-01-16 19:18:48 -0800 | [diff] [blame] | 61 | /** Indicates that the dex file passed to dexopt in on CE storage. */ |
Nicolas Geoffray | 56123ba | 2017-05-05 14:30:02 +0100 | [diff] [blame] | 62 | public static final int DEXOPT_STORAGE_CE = 1 << 7; |
Calin Juravle | c22c30e | 2017-01-16 19:18:48 -0800 | [diff] [blame] | 63 | /** Indicates that the dex file passed to dexopt in on DE storage. */ |
Nicolas Geoffray | 56123ba | 2017-05-05 14:30:02 +0100 | [diff] [blame] | 64 | public static final int DEXOPT_STORAGE_DE = 1 << 8; |
David Sehr | 2118ec4 | 2017-10-25 14:28:29 -0700 | [diff] [blame] | 65 | /** Indicates that dexopt is invoked from the background service. */ |
| 66 | public static final int DEXOPT_IDLE_BACKGROUND_JOB = 1 << 9; |
David Brazdil | f7e31c0 | 2018-02-13 17:04:26 +0000 | [diff] [blame] | 67 | /** Indicates that dexopt should restrict access to private APIs. */ |
| 68 | public static final int DEXOPT_ENABLE_HIDDEN_API_CHECKS = 1 << 10; |
Mathieu Chartier | f890c3e | 2018-03-06 18:28:22 -0800 | [diff] [blame] | 69 | /** Indicates that dexopt should convert to CompactDex. */ |
| 70 | public static final int DEXOPT_GENERATE_COMPACT_DEX = 1 << 11; |
Mathieu Chartier | a9c3433 | 2018-03-12 17:11:07 -0700 | [diff] [blame] | 71 | /** Indicates that dexopt should generate an app image */ |
| 72 | public static final int DEXOPT_GENERATE_APP_IMAGE = 1 << 12; |
Todd Kennedy | fa54ab7 | 2015-09-25 07:46:12 -0700 | [diff] [blame] | 73 | |
Jeff Sharkey | 4e7a765 | 2018-08-24 17:25:42 -0600 | [diff] [blame] | 74 | public static final int FLAG_STORAGE_DE = IInstalld.FLAG_STORAGE_DE; |
| 75 | public static final int FLAG_STORAGE_CE = IInstalld.FLAG_STORAGE_CE; |
| 76 | |
| 77 | public static final int FLAG_CLEAR_CACHE_ONLY = IInstalld.FLAG_CLEAR_CACHE_ONLY; |
| 78 | public static final int FLAG_CLEAR_CODE_CACHE_ONLY = IInstalld.FLAG_CLEAR_CODE_CACHE_ONLY; |
| 79 | |
| 80 | public static final int FLAG_FREE_CACHE_V2 = IInstalld.FLAG_FREE_CACHE_V2; |
| 81 | public static final int FLAG_FREE_CACHE_V2_DEFY_QUOTA = IInstalld.FLAG_FREE_CACHE_V2_DEFY_QUOTA; |
| 82 | public static final int FLAG_FREE_CACHE_NOOP = IInstalld.FLAG_FREE_CACHE_NOOP; |
| 83 | |
| 84 | public static final int FLAG_USE_QUOTA = IInstalld.FLAG_USE_QUOTA; |
| 85 | public static final int FLAG_FORCE = IInstalld.FLAG_FORCE; |
Jeff Sharkey | fdeeeea | 2016-01-11 17:34:24 -0700 | [diff] [blame] | 86 | |
Jeff Sharkey | c98c7bc | 2016-12-07 14:57:34 -0700 | [diff] [blame] | 87 | private final boolean mIsolated; |
| 88 | |
Jeff Sharkey | 740f523 | 2016-12-09 14:31:26 -0700 | [diff] [blame] | 89 | private volatile IInstalld mInstalld; |
Jeff Sharkey | c8ddc2d | 2016-12-05 23:14:41 -0700 | [diff] [blame] | 90 | private volatile Object mWarnIfHeld; |
| 91 | |
Jeff Brown | b880d88 | 2014-02-10 19:47:07 -0800 | [diff] [blame] | 92 | public Installer(Context context) { |
Jeff Sharkey | c98c7bc | 2016-12-07 14:57:34 -0700 | [diff] [blame] | 93 | this(context, false); |
Jeff Brown | b880d88 | 2014-02-10 19:47:07 -0800 | [diff] [blame] | 94 | } |
| 95 | |
Jeff Sharkey | c98c7bc | 2016-12-07 14:57:34 -0700 | [diff] [blame] | 96 | /** |
| 97 | * @param isolated indicates if this object should <em>not</em> connect to |
| 98 | * the real {@code installd}. All remote calls will be ignored |
| 99 | * unless you extend this class and intercept them. |
| 100 | */ |
| 101 | public Installer(Context context, boolean isolated) { |
Andreas Gampe | d15300c | 2016-06-23 20:27:12 -0700 | [diff] [blame] | 102 | super(context); |
Jeff Sharkey | c98c7bc | 2016-12-07 14:57:34 -0700 | [diff] [blame] | 103 | mIsolated = isolated; |
Andreas Gampe | d15300c | 2016-06-23 20:27:12 -0700 | [diff] [blame] | 104 | } |
| 105 | |
Jeff Sharkey | 8948c01 | 2015-11-03 12:33:54 -0800 | [diff] [blame] | 106 | /** |
| 107 | * Yell loudly if someone tries making future calls while holding a lock on |
| 108 | * the given object. |
| 109 | */ |
| 110 | public void setWarnIfHeld(Object warnIfHeld) { |
Jeff Sharkey | c8ddc2d | 2016-12-05 23:14:41 -0700 | [diff] [blame] | 111 | mWarnIfHeld = warnIfHeld; |
Jeff Sharkey | 8948c01 | 2015-11-03 12:33:54 -0800 | [diff] [blame] | 112 | } |
| 113 | |
Jeff Brown | 6f357d3 | 2014-01-15 20:40:55 -0800 | [diff] [blame] | 114 | @Override |
| 115 | public void onStart() { |
Jeff Sharkey | 740f523 | 2016-12-09 14:31:26 -0700 | [diff] [blame] | 116 | if (mIsolated) { |
| 117 | mInstalld = null; |
| 118 | } else { |
Jeff Sharkey | 9f2f218 | 2016-12-21 09:18:33 -0700 | [diff] [blame] | 119 | connect(); |
| 120 | } |
| 121 | } |
| 122 | |
| 123 | private void connect() { |
| 124 | IBinder binder = ServiceManager.getService("installd"); |
| 125 | if (binder != null) { |
| 126 | try { |
| 127 | binder.linkToDeath(new DeathRecipient() { |
| 128 | @Override |
| 129 | public void binderDied() { |
| 130 | Slog.w(TAG, "installd died; reconnecting"); |
| 131 | connect(); |
| 132 | } |
| 133 | }, 0); |
| 134 | } catch (RemoteException e) { |
| 135 | binder = null; |
| 136 | } |
| 137 | } |
| 138 | |
| 139 | if (binder != null) { |
| 140 | mInstalld = IInstalld.Stub.asInterface(binder); |
Jeff Sharkey | 82add8a | 2017-03-11 19:44:16 -0700 | [diff] [blame] | 141 | try { |
| 142 | invalidateMounts(); |
| 143 | } catch (InstallerException ignored) { |
| 144 | } |
Jeff Sharkey | 9f2f218 | 2016-12-21 09:18:33 -0700 | [diff] [blame] | 145 | } else { |
| 146 | Slog.w(TAG, "installd not found; trying again"); |
| 147 | BackgroundThread.getHandler().postDelayed(() -> { |
| 148 | connect(); |
| 149 | }, DateUtils.SECOND_IN_MILLIS); |
Jeff Sharkey | c98c7bc | 2016-12-07 14:57:34 -0700 | [diff] [blame] | 150 | } |
Jeff Brown | 6f357d3 | 2014-01-15 20:40:55 -0800 | [diff] [blame] | 151 | } |
| 152 | |
Jeff Sharkey | c98c7bc | 2016-12-07 14:57:34 -0700 | [diff] [blame] | 153 | /** |
| 154 | * Do several pre-flight checks before making a remote call. |
| 155 | * |
| 156 | * @return if the remote call should continue. |
| 157 | */ |
| 158 | private boolean checkBeforeRemote() { |
Jeff Sharkey | c8ddc2d | 2016-12-05 23:14:41 -0700 | [diff] [blame] | 159 | if (mWarnIfHeld != null && Thread.holdsLock(mWarnIfHeld)) { |
| 160 | Slog.wtf(TAG, "Calling thread " + Thread.currentThread().getName() + " is holding 0x" |
| 161 | + Integer.toHexString(System.identityHashCode(mWarnIfHeld)), new Throwable()); |
| 162 | } |
Jeff Sharkey | c98c7bc | 2016-12-07 14:57:34 -0700 | [diff] [blame] | 163 | if (mIsolated) { |
| 164 | Slog.i(TAG, "Ignoring request because this installer is isolated"); |
| 165 | return false; |
| 166 | } else { |
| 167 | return true; |
| 168 | } |
Jeff Sharkey | c8ddc2d | 2016-12-05 23:14:41 -0700 | [diff] [blame] | 169 | } |
| 170 | |
Jeff Sharkey | 1c6f723 | 2016-12-19 16:39:02 -0700 | [diff] [blame] | 171 | 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] | 172 | String seInfo, int targetSdkVersion) throws InstallerException { |
Jeff Sharkey | 1c6f723 | 2016-12-19 16:39:02 -0700 | [diff] [blame] | 173 | if (!checkBeforeRemote()) return -1; |
Jeff Sharkey | c8ddc2d | 2016-12-05 23:14:41 -0700 | [diff] [blame] | 174 | try { |
Jeff Sharkey | 1c6f723 | 2016-12-19 16:39:02 -0700 | [diff] [blame] | 175 | return mInstalld.createAppData(uuid, packageName, userId, flags, appId, seInfo, |
Jeff Sharkey | 70b4d10 | 2016-12-05 11:19:28 -0700 | [diff] [blame] | 176 | targetSdkVersion); |
Jeff Sharkey | 447a3ac | 2016-12-12 10:15:37 -0700 | [diff] [blame] | 177 | } catch (Exception e) { |
Jeff Sharkey | 740f523 | 2016-12-09 14:31:26 -0700 | [diff] [blame] | 178 | throw InstallerException.from(e); |
Jeff Sharkey | 70b4d10 | 2016-12-05 11:19:28 -0700 | [diff] [blame] | 179 | } |
Jeff Sharkey | 790a4ec | 2015-04-09 13:18:44 -0700 | [diff] [blame] | 180 | } |
| 181 | |
Jeff Sharkey | 019ac85 | 2016-12-05 23:39:46 -0700 | [diff] [blame] | 182 | public void restoreconAppData(String uuid, String packageName, int userId, int flags, int appId, |
| 183 | String seInfo) throws InstallerException { |
Jeff Sharkey | c98c7bc | 2016-12-07 14:57:34 -0700 | [diff] [blame] | 184 | if (!checkBeforeRemote()) return; |
Jeff Sharkey | 019ac85 | 2016-12-05 23:39:46 -0700 | [diff] [blame] | 185 | try { |
| 186 | mInstalld.restoreconAppData(uuid, packageName, userId, flags, appId, seInfo); |
Jeff Sharkey | 447a3ac | 2016-12-12 10:15:37 -0700 | [diff] [blame] | 187 | } catch (Exception e) { |
Jeff Sharkey | 740f523 | 2016-12-09 14:31:26 -0700 | [diff] [blame] | 188 | throw InstallerException.from(e); |
Jeff Sharkey | 019ac85 | 2016-12-05 23:39:46 -0700 | [diff] [blame] | 189 | } |
Jeff Sharkey | 790a4ec | 2015-04-09 13:18:44 -0700 | [diff] [blame] | 190 | } |
| 191 | |
Jeff Sharkey | 019ac85 | 2016-12-05 23:39:46 -0700 | [diff] [blame] | 192 | public void migrateAppData(String uuid, String packageName, int userId, int flags) |
Jeff Sharkey | e469713 | 2016-02-06 19:46:15 -0700 | [diff] [blame] | 193 | throws InstallerException { |
Jeff Sharkey | c98c7bc | 2016-12-07 14:57:34 -0700 | [diff] [blame] | 194 | if (!checkBeforeRemote()) return; |
Jeff Sharkey | 019ac85 | 2016-12-05 23:39:46 -0700 | [diff] [blame] | 195 | try { |
| 196 | mInstalld.migrateAppData(uuid, packageName, userId, flags); |
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 | 019ac85 | 2016-12-05 23:39:46 -0700 | [diff] [blame] | 199 | } |
Jeff Sharkey | e469713 | 2016-02-06 19:46:15 -0700 | [diff] [blame] | 200 | } |
| 201 | |
Jeff Sharkey | 019ac85 | 2016-12-05 23:39:46 -0700 | [diff] [blame] | 202 | public void clearAppData(String uuid, String packageName, int userId, int flags, |
| 203 | long ceDataInode) throws InstallerException { |
Jeff Sharkey | c98c7bc | 2016-12-07 14:57:34 -0700 | [diff] [blame] | 204 | if (!checkBeforeRemote()) return; |
Jeff Sharkey | 019ac85 | 2016-12-05 23:39:46 -0700 | [diff] [blame] | 205 | try { |
| 206 | mInstalld.clearAppData(uuid, packageName, userId, flags, ceDataInode); |
Jeff Sharkey | 447a3ac | 2016-12-12 10:15:37 -0700 | [diff] [blame] | 207 | } catch (Exception e) { |
Jeff Sharkey | 740f523 | 2016-12-09 14:31:26 -0700 | [diff] [blame] | 208 | throw InstallerException.from(e); |
Jeff Sharkey | 019ac85 | 2016-12-05 23:39:46 -0700 | [diff] [blame] | 209 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 210 | } |
| 211 | |
Jeff Sharkey | 019ac85 | 2016-12-05 23:39:46 -0700 | [diff] [blame] | 212 | public void destroyAppData(String uuid, String packageName, int userId, int flags, |
| 213 | long ceDataInode) throws InstallerException { |
Jeff Sharkey | c98c7bc | 2016-12-07 14:57:34 -0700 | [diff] [blame] | 214 | if (!checkBeforeRemote()) return; |
Jeff Sharkey | 019ac85 | 2016-12-05 23:39:46 -0700 | [diff] [blame] | 215 | try { |
| 216 | mInstalld.destroyAppData(uuid, packageName, userId, flags, ceDataInode); |
Jeff Sharkey | 447a3ac | 2016-12-12 10:15:37 -0700 | [diff] [blame] | 217 | } catch (Exception e) { |
Jeff Sharkey | 740f523 | 2016-12-09 14:31:26 -0700 | [diff] [blame] | 218 | throw InstallerException.from(e); |
Jeff Sharkey | 019ac85 | 2016-12-05 23:39:46 -0700 | [diff] [blame] | 219 | } |
Dave Allison | 0efbd9a | 2014-01-30 14:19:51 -0800 | [diff] [blame] | 220 | } |
| 221 | |
Jeff Sharkey | 1566233 | 2017-04-03 16:41:29 -0600 | [diff] [blame] | 222 | public void fixupAppData(String uuid, int flags) throws InstallerException { |
| 223 | if (!checkBeforeRemote()) return; |
| 224 | try { |
| 225 | mInstalld.fixupAppData(uuid, flags); |
| 226 | } catch (Exception e) { |
| 227 | throw InstallerException.from(e); |
| 228 | } |
| 229 | } |
| 230 | |
Jeff Sharkey | c8ddc2d | 2016-12-05 23:14:41 -0700 | [diff] [blame] | 231 | public void moveCompleteApp(String fromUuid, String toUuid, String packageName, |
| 232 | String dataAppName, int appId, String seInfo, int targetSdkVersion) |
Janis Danisevskis | f340974 | 2016-01-12 14:46:33 +0000 | [diff] [blame] | 233 | throws InstallerException { |
Jeff Sharkey | c98c7bc | 2016-12-07 14:57:34 -0700 | [diff] [blame] | 234 | if (!checkBeforeRemote()) return; |
Jeff Sharkey | c8ddc2d | 2016-12-05 23:14:41 -0700 | [diff] [blame] | 235 | try { |
| 236 | mInstalld.moveCompleteApp(fromUuid, toUuid, packageName, dataAppName, appId, seInfo, |
| 237 | targetSdkVersion); |
Jeff Sharkey | 447a3ac | 2016-12-12 10:15:37 -0700 | [diff] [blame] | 238 | } catch (Exception e) { |
Jeff Sharkey | 740f523 | 2016-12-09 14:31:26 -0700 | [diff] [blame] | 239 | throw InstallerException.from(e); |
Jeff Sharkey | c8ddc2d | 2016-12-05 23:14:41 -0700 | [diff] [blame] | 240 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 241 | } |
| 242 | |
Jeff Sharkey | 82ca901 | 2017-01-08 17:06:58 -0700 | [diff] [blame] | 243 | public void getAppSize(String uuid, String[] packageNames, int userId, int flags, int appId, |
| 244 | long[] ceDataInodes, String[] codePaths, PackageStats stats) |
Jeff Sharkey | 5eb3eb5 | 2016-12-13 08:44:51 -0700 | [diff] [blame] | 245 | throws InstallerException { |
Jeff Sharkey | c98c7bc | 2016-12-07 14:57:34 -0700 | [diff] [blame] | 246 | if (!checkBeforeRemote()) return; |
Jeff Sharkey | dd02e33 | 2018-06-27 14:41:57 -0600 | [diff] [blame] | 247 | if (codePaths != null) { |
| 248 | for (String codePath : codePaths) { |
| 249 | BlockGuard.getVmPolicy().onPathAccess(codePath); |
| 250 | } |
| 251 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 252 | try { |
Jeff Sharkey | 82ca901 | 2017-01-08 17:06:58 -0700 | [diff] [blame] | 253 | final long[] res = mInstalld.getAppSize(uuid, packageNames, userId, flags, |
| 254 | appId, ceDataInodes, codePaths); |
Jeff Sharkey | 740f523 | 2016-12-09 14:31:26 -0700 | [diff] [blame] | 255 | stats.codeSize += res[0]; |
| 256 | stats.dataSize += res[1]; |
| 257 | stats.cacheSize += res[2]; |
Jeff Sharkey | 82ca901 | 2017-01-08 17:06:58 -0700 | [diff] [blame] | 258 | stats.externalCodeSize += res[3]; |
| 259 | stats.externalDataSize += res[4]; |
| 260 | stats.externalCacheSize += res[5]; |
| 261 | } catch (Exception e) { |
| 262 | throw InstallerException.from(e); |
| 263 | } |
| 264 | } |
| 265 | |
| 266 | public void getUserSize(String uuid, int userId, int flags, int[] appIds, PackageStats stats) |
| 267 | throws InstallerException { |
| 268 | if (!checkBeforeRemote()) return; |
| 269 | try { |
| 270 | final long[] res = mInstalld.getUserSize(uuid, userId, flags, appIds); |
| 271 | stats.codeSize += res[0]; |
| 272 | stats.dataSize += res[1]; |
| 273 | stats.cacheSize += res[2]; |
| 274 | stats.externalCodeSize += res[3]; |
| 275 | stats.externalDataSize += res[4]; |
| 276 | stats.externalCacheSize += res[5]; |
| 277 | } catch (Exception e) { |
| 278 | throw InstallerException.from(e); |
| 279 | } |
| 280 | } |
| 281 | |
Jeff Sharkey | 0034788 | 2017-04-17 16:44:12 -0600 | [diff] [blame] | 282 | public long[] getExternalSize(String uuid, int userId, int flags, int[] appIds) |
| 283 | throws InstallerException { |
Jeff Sharkey | c8b29ac | 2017-07-06 11:29:06 -0600 | [diff] [blame] | 284 | if (!checkBeforeRemote()) return new long[6]; |
Jeff Sharkey | 82ca901 | 2017-01-08 17:06:58 -0700 | [diff] [blame] | 285 | try { |
Jeff Sharkey | 0034788 | 2017-04-17 16:44:12 -0600 | [diff] [blame] | 286 | return mInstalld.getExternalSize(uuid, userId, flags, appIds); |
Jeff Sharkey | 447a3ac | 2016-12-12 10:15:37 -0700 | [diff] [blame] | 287 | } catch (Exception e) { |
Jeff Sharkey | 740f523 | 2016-12-09 14:31:26 -0700 | [diff] [blame] | 288 | throw InstallerException.from(e); |
Jeff Sharkey | 4288419 | 2016-04-09 16:12:01 -0600 | [diff] [blame] | 289 | } |
| 290 | } |
| 291 | |
Jeff Sharkey | 36ba022 | 2017-01-18 12:11:31 -0700 | [diff] [blame] | 292 | public void setAppQuota(String uuid, int userId, int appId, long cacheQuota) |
| 293 | throws InstallerException { |
| 294 | if (!checkBeforeRemote()) return; |
| 295 | try { |
| 296 | mInstalld.setAppQuota(uuid, userId, appId, cacheQuota); |
| 297 | } catch (Exception e) { |
| 298 | throw InstallerException.from(e); |
| 299 | } |
| 300 | } |
| 301 | |
Jeff Sharkey | c98c7bc | 2016-12-07 14:57:34 -0700 | [diff] [blame] | 302 | public void dexopt(String apkPath, int uid, @Nullable String pkgName, String instructionSet, |
Calin Juravle | db4a79a | 2015-12-23 18:55:08 +0200 | [diff] [blame] | 303 | int dexoptNeeded, @Nullable String outputPath, int dexFlags, |
Calin Juravle | 811a75a | 2017-04-05 22:49:38 -0700 | [diff] [blame] | 304 | String compilerFilter, @Nullable String volumeUuid, @Nullable String sharedLibraries, |
Calin Juravle | 6ae39fc | 2018-01-19 20:32:47 -0800 | [diff] [blame] | 305 | @Nullable String seInfo, boolean downgrade, int targetSdkVersion, |
Calin Juravle | 4bc8f4d | 2018-02-12 12:00:44 -0800 | [diff] [blame] | 306 | @Nullable String profileName, @Nullable String dexMetadataPath, |
| 307 | @Nullable String compilationReason) throws InstallerException { |
Jeff Sharkey | fdeeeea | 2016-01-11 17:34:24 -0700 | [diff] [blame] | 308 | assertValidInstructionSet(instructionSet); |
Jeff Sharkey | dd02e33 | 2018-06-27 14:41:57 -0600 | [diff] [blame] | 309 | BlockGuard.getVmPolicy().onPathAccess(apkPath); |
| 310 | BlockGuard.getVmPolicy().onPathAccess(outputPath); |
| 311 | BlockGuard.getVmPolicy().onPathAccess(dexMetadataPath); |
Jeff Sharkey | c98c7bc | 2016-12-07 14:57:34 -0700 | [diff] [blame] | 312 | if (!checkBeforeRemote()) return; |
Jeff Sharkey | 740f523 | 2016-12-09 14:31:26 -0700 | [diff] [blame] | 313 | try { |
| 314 | mInstalld.dexopt(apkPath, uid, pkgName, instructionSet, dexoptNeeded, outputPath, |
David Brazdil | 3d44ed0 | 2018-01-16 20:01:47 +0000 | [diff] [blame] | 315 | dexFlags, compilerFilter, volumeUuid, sharedLibraries, seInfo, downgrade, |
Calin Juravle | 4bc8f4d | 2018-02-12 12:00:44 -0800 | [diff] [blame] | 316 | targetSdkVersion, profileName, dexMetadataPath, compilationReason); |
Jeff Sharkey | 447a3ac | 2016-12-12 10:15:37 -0700 | [diff] [blame] | 317 | } catch (Exception e) { |
Jeff Sharkey | 740f523 | 2016-12-09 14:31:26 -0700 | [diff] [blame] | 318 | throw InstallerException.from(e); |
| 319 | } |
Andreas Gampe | bdd30d8 | 2016-03-20 11:32:11 -0700 | [diff] [blame] | 320 | } |
| 321 | |
Calin Juravle | 6ae39fc | 2018-01-19 20:32:47 -0800 | [diff] [blame] | 322 | public boolean mergeProfiles(int uid, String packageName, String profileName) |
David Sehr | a877708 | 2016-05-24 15:25:23 -0700 | [diff] [blame] | 323 | throws InstallerException { |
Jeff Sharkey | c98c7bc | 2016-12-07 14:57:34 -0700 | [diff] [blame] | 324 | if (!checkBeforeRemote()) return false; |
Jeff Sharkey | c24fa02 | 2016-12-07 10:37:47 -0700 | [diff] [blame] | 325 | try { |
Calin Juravle | 6ae39fc | 2018-01-19 20:32:47 -0800 | [diff] [blame] | 326 | return mInstalld.mergeProfiles(uid, packageName, profileName); |
Jeff Sharkey | 447a3ac | 2016-12-12 10:15:37 -0700 | [diff] [blame] | 327 | } catch (Exception e) { |
Jeff Sharkey | 740f523 | 2016-12-09 14:31:26 -0700 | [diff] [blame] | 328 | throw InstallerException.from(e); |
Jeff Sharkey | c24fa02 | 2016-12-07 10:37:47 -0700 | [diff] [blame] | 329 | } |
David Sehr | a877708 | 2016-05-24 15:25:23 -0700 | [diff] [blame] | 330 | } |
| 331 | |
Calin Juravle | 6ae39fc | 2018-01-19 20:32:47 -0800 | [diff] [blame] | 332 | public boolean dumpProfiles(int uid, String packageName, String profileName, String codePath) |
Mathieu Chartier | 235845d | 2017-05-10 15:09:19 -0700 | [diff] [blame] | 333 | throws InstallerException { |
| 334 | if (!checkBeforeRemote()) return false; |
Jeff Sharkey | dd02e33 | 2018-06-27 14:41:57 -0600 | [diff] [blame] | 335 | BlockGuard.getVmPolicy().onPathAccess(codePath); |
Mathieu Chartier | 235845d | 2017-05-10 15:09:19 -0700 | [diff] [blame] | 336 | try { |
Calin Juravle | 6ae39fc | 2018-01-19 20:32:47 -0800 | [diff] [blame] | 337 | return mInstalld.dumpProfiles(uid, packageName, profileName, codePath); |
| 338 | } catch (Exception e) { |
| 339 | throw InstallerException.from(e); |
| 340 | } |
| 341 | } |
| 342 | |
| 343 | public boolean copySystemProfile(String systemProfile, int uid, String packageName, |
| 344 | String profileName) throws InstallerException { |
| 345 | if (!checkBeforeRemote()) return false; |
| 346 | try { |
| 347 | return mInstalld.copySystemProfile(systemProfile, uid, packageName, profileName); |
Mathieu Chartier | 235845d | 2017-05-10 15:09:19 -0700 | [diff] [blame] | 348 | } catch (Exception e) { |
| 349 | throw InstallerException.from(e); |
| 350 | } |
| 351 | } |
| 352 | |
Jeff Sharkey | fdeeeea | 2016-01-11 17:34:24 -0700 | [diff] [blame] | 353 | public void idmap(String targetApkPath, String overlayApkPath, int uid) |
| 354 | throws InstallerException { |
Jeff Sharkey | c98c7bc | 2016-12-07 14:57:34 -0700 | [diff] [blame] | 355 | if (!checkBeforeRemote()) return; |
Jeff Sharkey | dd02e33 | 2018-06-27 14:41:57 -0600 | [diff] [blame] | 356 | BlockGuard.getVmPolicy().onPathAccess(targetApkPath); |
| 357 | BlockGuard.getVmPolicy().onPathAccess(overlayApkPath); |
Jeff Sharkey | c24fa02 | 2016-12-07 10:37:47 -0700 | [diff] [blame] | 358 | try { |
| 359 | mInstalld.idmap(targetApkPath, overlayApkPath, uid); |
Jeff Sharkey | 447a3ac | 2016-12-12 10:15:37 -0700 | [diff] [blame] | 360 | } catch (Exception e) { |
Jeff Sharkey | 740f523 | 2016-12-09 14:31:26 -0700 | [diff] [blame] | 361 | throw InstallerException.from(e); |
Jeff Sharkey | c24fa02 | 2016-12-07 10:37:47 -0700 | [diff] [blame] | 362 | } |
Jeff Sharkey | fdeeeea | 2016-01-11 17:34:24 -0700 | [diff] [blame] | 363 | } |
| 364 | |
MÃ¥rten Kongstad | 16382634 | 2016-06-02 09:35:09 +0200 | [diff] [blame] | 365 | public void removeIdmap(String overlayApkPath) throws InstallerException { |
| 366 | if (!checkBeforeRemote()) return; |
Jeff Sharkey | dd02e33 | 2018-06-27 14:41:57 -0600 | [diff] [blame] | 367 | BlockGuard.getVmPolicy().onPathAccess(overlayApkPath); |
MÃ¥rten Kongstad | 16382634 | 2016-06-02 09:35:09 +0200 | [diff] [blame] | 368 | try { |
| 369 | mInstalld.removeIdmap(overlayApkPath); |
| 370 | } catch (Exception e) { |
| 371 | throw InstallerException.from(e); |
| 372 | } |
| 373 | } |
| 374 | |
Jeff Sharkey | fdeeeea | 2016-01-11 17:34:24 -0700 | [diff] [blame] | 375 | public void rmdex(String codePath, String instructionSet) throws InstallerException { |
| 376 | assertValidInstructionSet(instructionSet); |
Jeff Sharkey | c98c7bc | 2016-12-07 14:57:34 -0700 | [diff] [blame] | 377 | if (!checkBeforeRemote()) return; |
Jeff Sharkey | dd02e33 | 2018-06-27 14:41:57 -0600 | [diff] [blame] | 378 | BlockGuard.getVmPolicy().onPathAccess(codePath); |
Jeff Sharkey | c24fa02 | 2016-12-07 10:37:47 -0700 | [diff] [blame] | 379 | try { |
| 380 | mInstalld.rmdex(codePath, instructionSet); |
Jeff Sharkey | 447a3ac | 2016-12-12 10:15:37 -0700 | [diff] [blame] | 381 | } catch (Exception e) { |
Jeff Sharkey | 740f523 | 2016-12-09 14:31:26 -0700 | [diff] [blame] | 382 | throw InstallerException.from(e); |
Jeff Sharkey | c24fa02 | 2016-12-07 10:37:47 -0700 | [diff] [blame] | 383 | } |
Jeff Sharkey | fdeeeea | 2016-01-11 17:34:24 -0700 | [diff] [blame] | 384 | } |
| 385 | |
| 386 | public void rmPackageDir(String packageDir) throws InstallerException { |
Jeff Sharkey | c98c7bc | 2016-12-07 14:57:34 -0700 | [diff] [blame] | 387 | if (!checkBeforeRemote()) return; |
Jeff Sharkey | dd02e33 | 2018-06-27 14:41:57 -0600 | [diff] [blame] | 388 | BlockGuard.getVmPolicy().onPathAccess(packageDir); |
Jeff Sharkey | c24fa02 | 2016-12-07 10:37:47 -0700 | [diff] [blame] | 389 | try { |
| 390 | mInstalld.rmPackageDir(packageDir); |
Jeff Sharkey | 447a3ac | 2016-12-12 10:15:37 -0700 | [diff] [blame] | 391 | } catch (Exception e) { |
Jeff Sharkey | 740f523 | 2016-12-09 14:31:26 -0700 | [diff] [blame] | 392 | throw InstallerException.from(e); |
Jeff Sharkey | c24fa02 | 2016-12-07 10:37:47 -0700 | [diff] [blame] | 393 | } |
Jeff Sharkey | fdeeeea | 2016-01-11 17:34:24 -0700 | [diff] [blame] | 394 | } |
| 395 | |
Calin Juravle | 6ae39fc | 2018-01-19 20:32:47 -0800 | [diff] [blame] | 396 | public void clearAppProfiles(String packageName, String profileName) throws InstallerException { |
Jeff Sharkey | c98c7bc | 2016-12-07 14:57:34 -0700 | [diff] [blame] | 397 | if (!checkBeforeRemote()) return; |
Jeff Sharkey | c24fa02 | 2016-12-07 10:37:47 -0700 | [diff] [blame] | 398 | try { |
Calin Juravle | 6ae39fc | 2018-01-19 20:32:47 -0800 | [diff] [blame] | 399 | mInstalld.clearAppProfiles(packageName, profileName); |
Jeff Sharkey | 447a3ac | 2016-12-12 10:15:37 -0700 | [diff] [blame] | 400 | } catch (Exception e) { |
Jeff Sharkey | 740f523 | 2016-12-09 14:31:26 -0700 | [diff] [blame] | 401 | throw InstallerException.from(e); |
Jeff Sharkey | c24fa02 | 2016-12-07 10:37:47 -0700 | [diff] [blame] | 402 | } |
Calin Juravle | d6d27e3 | 2016-03-23 13:59:18 +0000 | [diff] [blame] | 403 | } |
| 404 | |
Jeff Sharkey | c24fa02 | 2016-12-07 10:37:47 -0700 | [diff] [blame] | 405 | public void destroyAppProfiles(String packageName) throws InstallerException { |
Jeff Sharkey | c98c7bc | 2016-12-07 14:57:34 -0700 | [diff] [blame] | 406 | if (!checkBeforeRemote()) return; |
Jeff Sharkey | c24fa02 | 2016-12-07 10:37:47 -0700 | [diff] [blame] | 407 | try { |
| 408 | mInstalld.destroyAppProfiles(packageName); |
Jeff Sharkey | 447a3ac | 2016-12-12 10:15:37 -0700 | [diff] [blame] | 409 | } catch (Exception e) { |
Jeff Sharkey | 740f523 | 2016-12-09 14:31:26 -0700 | [diff] [blame] | 410 | throw InstallerException.from(e); |
Jeff Sharkey | c24fa02 | 2016-12-07 10:37:47 -0700 | [diff] [blame] | 411 | } |
David Brazdil | 9aa6db0 | 2016-03-08 12:57:12 +0000 | [diff] [blame] | 412 | } |
| 413 | |
Jeff Sharkey | fcf1e55 | 2016-04-14 20:44:58 -0600 | [diff] [blame] | 414 | public void createUserData(String uuid, int userId, int userSerial, int flags) |
| 415 | throws InstallerException { |
Jeff Sharkey | c98c7bc | 2016-12-07 14:57:34 -0700 | [diff] [blame] | 416 | if (!checkBeforeRemote()) return; |
Jeff Sharkey | 019ac85 | 2016-12-05 23:39:46 -0700 | [diff] [blame] | 417 | try { |
| 418 | mInstalld.createUserData(uuid, userId, userSerial, flags); |
Jeff Sharkey | 447a3ac | 2016-12-12 10:15:37 -0700 | [diff] [blame] | 419 | } catch (Exception e) { |
Jeff Sharkey | 740f523 | 2016-12-09 14:31:26 -0700 | [diff] [blame] | 420 | throw InstallerException.from(e); |
Jeff Sharkey | 019ac85 | 2016-12-05 23:39:46 -0700 | [diff] [blame] | 421 | } |
Jeff Sharkey | fdeeeea | 2016-01-11 17:34:24 -0700 | [diff] [blame] | 422 | } |
| 423 | |
Jeff Sharkey | fcf1e55 | 2016-04-14 20:44:58 -0600 | [diff] [blame] | 424 | public void destroyUserData(String uuid, int userId, int flags) throws InstallerException { |
Jeff Sharkey | c98c7bc | 2016-12-07 14:57:34 -0700 | [diff] [blame] | 425 | if (!checkBeforeRemote()) return; |
Jeff Sharkey | 019ac85 | 2016-12-05 23:39:46 -0700 | [diff] [blame] | 426 | try { |
| 427 | mInstalld.destroyUserData(uuid, userId, flags); |
Jeff Sharkey | 447a3ac | 2016-12-12 10:15:37 -0700 | [diff] [blame] | 428 | } catch (Exception e) { |
Jeff Sharkey | 740f523 | 2016-12-09 14:31:26 -0700 | [diff] [blame] | 429 | throw InstallerException.from(e); |
Jeff Sharkey | 019ac85 | 2016-12-05 23:39:46 -0700 | [diff] [blame] | 430 | } |
Jeff Sharkey | fdeeeea | 2016-01-11 17:34:24 -0700 | [diff] [blame] | 431 | } |
| 432 | |
| 433 | public void markBootComplete(String instructionSet) throws InstallerException { |
| 434 | assertValidInstructionSet(instructionSet); |
Jeff Sharkey | c98c7bc | 2016-12-07 14:57:34 -0700 | [diff] [blame] | 435 | if (!checkBeforeRemote()) return; |
Jeff Sharkey | c24fa02 | 2016-12-07 10:37:47 -0700 | [diff] [blame] | 436 | try { |
| 437 | mInstalld.markBootComplete(instructionSet); |
Jeff Sharkey | 447a3ac | 2016-12-12 10:15:37 -0700 | [diff] [blame] | 438 | } catch (Exception e) { |
Jeff Sharkey | 740f523 | 2016-12-09 14:31:26 -0700 | [diff] [blame] | 439 | throw InstallerException.from(e); |
Jeff Sharkey | c24fa02 | 2016-12-07 10:37:47 -0700 | [diff] [blame] | 440 | } |
Jeff Sharkey | fdeeeea | 2016-01-11 17:34:24 -0700 | [diff] [blame] | 441 | } |
| 442 | |
Jeff Sharkey | ddff807 | 2017-05-26 13:10:46 -0600 | [diff] [blame] | 443 | public void freeCache(String uuid, long targetFreeBytes, long cacheReservedBytes, int flags) |
| 444 | throws InstallerException { |
Jeff Sharkey | c98c7bc | 2016-12-07 14:57:34 -0700 | [diff] [blame] | 445 | if (!checkBeforeRemote()) return; |
Jeff Sharkey | c24fa02 | 2016-12-07 10:37:47 -0700 | [diff] [blame] | 446 | try { |
Jeff Sharkey | ddff807 | 2017-05-26 13:10:46 -0600 | [diff] [blame] | 447 | mInstalld.freeCache(uuid, targetFreeBytes, cacheReservedBytes, flags); |
Jeff Sharkey | 447a3ac | 2016-12-12 10:15:37 -0700 | [diff] [blame] | 448 | } catch (Exception e) { |
Jeff Sharkey | 740f523 | 2016-12-09 14:31:26 -0700 | [diff] [blame] | 449 | throw InstallerException.from(e); |
Jeff Sharkey | c24fa02 | 2016-12-07 10:37:47 -0700 | [diff] [blame] | 450 | } |
Jeff Sharkey | fdeeeea | 2016-01-11 17:34:24 -0700 | [diff] [blame] | 451 | } |
| 452 | |
Kenny Root | ddbe50d | 2012-09-06 13:18:37 -0700 | [diff] [blame] | 453 | /** |
Jeff Sharkey | fdeeeea | 2016-01-11 17:34:24 -0700 | [diff] [blame] | 454 | * Links the 32 bit native library directory in an application's data |
| 455 | * directory to the real location for backward compatibility. Note that no |
| 456 | * such symlink is created for 64 bit shared libraries. |
Kenny Root | ddbe50d | 2012-09-06 13:18:37 -0700 | [diff] [blame] | 457 | */ |
Jeff Sharkey | c24fa02 | 2016-12-07 10:37:47 -0700 | [diff] [blame] | 458 | public void linkNativeLibraryDirectory(String uuid, String packageName, String nativeLibPath32, |
Jeff Sharkey | fdeeeea | 2016-01-11 17:34:24 -0700 | [diff] [blame] | 459 | int userId) throws InstallerException { |
Jeff Sharkey | c98c7bc | 2016-12-07 14:57:34 -0700 | [diff] [blame] | 460 | if (!checkBeforeRemote()) return; |
Jeff Sharkey | dd02e33 | 2018-06-27 14:41:57 -0600 | [diff] [blame] | 461 | BlockGuard.getVmPolicy().onPathAccess(nativeLibPath32); |
Jeff Sharkey | c24fa02 | 2016-12-07 10:37:47 -0700 | [diff] [blame] | 462 | try { |
| 463 | mInstalld.linkNativeLibraryDirectory(uuid, packageName, nativeLibPath32, userId); |
Jeff Sharkey | 447a3ac | 2016-12-12 10:15:37 -0700 | [diff] [blame] | 464 | } catch (Exception e) { |
Jeff Sharkey | 740f523 | 2016-12-09 14:31:26 -0700 | [diff] [blame] | 465 | throw InstallerException.from(e); |
Jeff Sharkey | c24fa02 | 2016-12-07 10:37:47 -0700 | [diff] [blame] | 466 | } |
Kenny Root | 6a6b007 | 2010-10-07 16:46:10 -0700 | [diff] [blame] | 467 | } |
Robert Craig | 4385343 | 2014-03-04 11:57:23 -0500 | [diff] [blame] | 468 | |
Jeff Sharkey | fdeeeea | 2016-01-11 17:34:24 -0700 | [diff] [blame] | 469 | public void createOatDir(String oatDir, String dexInstructionSet) |
| 470 | throws InstallerException { |
Jeff Sharkey | c98c7bc | 2016-12-07 14:57:34 -0700 | [diff] [blame] | 471 | if (!checkBeforeRemote()) return; |
Jeff Sharkey | c24fa02 | 2016-12-07 10:37:47 -0700 | [diff] [blame] | 472 | try { |
| 473 | mInstalld.createOatDir(oatDir, dexInstructionSet); |
Jeff Sharkey | 447a3ac | 2016-12-12 10:15:37 -0700 | [diff] [blame] | 474 | } catch (Exception e) { |
Jeff Sharkey | 740f523 | 2016-12-09 14:31:26 -0700 | [diff] [blame] | 475 | throw InstallerException.from(e); |
Jeff Sharkey | c24fa02 | 2016-12-07 10:37:47 -0700 | [diff] [blame] | 476 | } |
Jeff Sharkey | 790a4ec | 2015-04-09 13:18:44 -0700 | [diff] [blame] | 477 | } |
| 478 | |
Jeff Sharkey | fdeeeea | 2016-01-11 17:34:24 -0700 | [diff] [blame] | 479 | public void linkFile(String relativePath, String fromBase, String toBase) |
| 480 | throws InstallerException { |
Jeff Sharkey | c98c7bc | 2016-12-07 14:57:34 -0700 | [diff] [blame] | 481 | if (!checkBeforeRemote()) return; |
Jeff Sharkey | dd02e33 | 2018-06-27 14:41:57 -0600 | [diff] [blame] | 482 | BlockGuard.getVmPolicy().onPathAccess(fromBase); |
| 483 | BlockGuard.getVmPolicy().onPathAccess(toBase); |
Jeff Sharkey | c24fa02 | 2016-12-07 10:37:47 -0700 | [diff] [blame] | 484 | try { |
| 485 | mInstalld.linkFile(relativePath, fromBase, toBase); |
Jeff Sharkey | 447a3ac | 2016-12-12 10:15:37 -0700 | [diff] [blame] | 486 | } catch (Exception e) { |
Jeff Sharkey | 740f523 | 2016-12-09 14:31:26 -0700 | [diff] [blame] | 487 | throw InstallerException.from(e); |
Jeff Sharkey | c24fa02 | 2016-12-07 10:37:47 -0700 | [diff] [blame] | 488 | } |
Robert Craig | 4385343 | 2014-03-04 11:57:23 -0500 | [diff] [blame] | 489 | } |
Narayan Kamath | 6c4b9de | 2014-08-08 12:44:12 +0100 | [diff] [blame] | 490 | |
Andreas Gampe | abcbe2f | 2016-02-26 11:25:36 -0800 | [diff] [blame] | 491 | public void moveAb(String apkPath, String instructionSet, String outputPath) |
| 492 | throws InstallerException { |
Jeff Sharkey | c98c7bc | 2016-12-07 14:57:34 -0700 | [diff] [blame] | 493 | if (!checkBeforeRemote()) return; |
Jeff Sharkey | dd02e33 | 2018-06-27 14:41:57 -0600 | [diff] [blame] | 494 | BlockGuard.getVmPolicy().onPathAccess(apkPath); |
| 495 | BlockGuard.getVmPolicy().onPathAccess(outputPath); |
Jeff Sharkey | c24fa02 | 2016-12-07 10:37:47 -0700 | [diff] [blame] | 496 | try { |
| 497 | mInstalld.moveAb(apkPath, instructionSet, outputPath); |
Jeff Sharkey | 447a3ac | 2016-12-12 10:15:37 -0700 | [diff] [blame] | 498 | } catch (Exception e) { |
Jeff Sharkey | 740f523 | 2016-12-09 14:31:26 -0700 | [diff] [blame] | 499 | throw InstallerException.from(e); |
Jeff Sharkey | c24fa02 | 2016-12-07 10:37:47 -0700 | [diff] [blame] | 500 | } |
Andreas Gampe | abcbe2f | 2016-02-26 11:25:36 -0800 | [diff] [blame] | 501 | } |
| 502 | |
Andreas Gampe | 33c592d | 2016-09-09 17:08:53 -0700 | [diff] [blame] | 503 | public void deleteOdex(String apkPath, String instructionSet, String outputPath) |
| 504 | throws InstallerException { |
Jeff Sharkey | c98c7bc | 2016-12-07 14:57:34 -0700 | [diff] [blame] | 505 | if (!checkBeforeRemote()) return; |
Jeff Sharkey | dd02e33 | 2018-06-27 14:41:57 -0600 | [diff] [blame] | 506 | BlockGuard.getVmPolicy().onPathAccess(apkPath); |
| 507 | BlockGuard.getVmPolicy().onPathAccess(outputPath); |
Jeff Sharkey | c24fa02 | 2016-12-07 10:37:47 -0700 | [diff] [blame] | 508 | try { |
| 509 | mInstalld.deleteOdex(apkPath, instructionSet, outputPath); |
Jeff Sharkey | 447a3ac | 2016-12-12 10:15:37 -0700 | [diff] [blame] | 510 | } catch (Exception e) { |
Jeff Sharkey | 740f523 | 2016-12-09 14:31:26 -0700 | [diff] [blame] | 511 | throw InstallerException.from(e); |
Jeff Sharkey | c24fa02 | 2016-12-07 10:37:47 -0700 | [diff] [blame] | 512 | } |
Andreas Gampe | 33c592d | 2016-09-09 17:08:53 -0700 | [diff] [blame] | 513 | } |
| 514 | |
Victor Hsieh | cccad19 | 2018-03-19 15:57:02 -0700 | [diff] [blame] | 515 | public void installApkVerity(String filePath, FileDescriptor verityInput, int contentSize) |
Victor Hsieh | 55f1499 | 2018-01-13 14:12:59 -0800 | [diff] [blame] | 516 | throws InstallerException { |
| 517 | if (!checkBeforeRemote()) return; |
Jeff Sharkey | dd02e33 | 2018-06-27 14:41:57 -0600 | [diff] [blame] | 518 | BlockGuard.getVmPolicy().onPathAccess(filePath); |
Victor Hsieh | 55f1499 | 2018-01-13 14:12:59 -0800 | [diff] [blame] | 519 | try { |
Victor Hsieh | cccad19 | 2018-03-19 15:57:02 -0700 | [diff] [blame] | 520 | mInstalld.installApkVerity(filePath, verityInput, contentSize); |
Victor Hsieh | 55f1499 | 2018-01-13 14:12:59 -0800 | [diff] [blame] | 521 | } catch (Exception e) { |
| 522 | throw InstallerException.from(e); |
| 523 | } |
| 524 | } |
| 525 | |
Victor Hsieh | 5f76124 | 2018-01-20 10:30:12 -0800 | [diff] [blame] | 526 | public void assertFsverityRootHashMatches(String filePath, @NonNull byte[] expectedHash) |
| 527 | throws InstallerException { |
| 528 | if (!checkBeforeRemote()) return; |
Jeff Sharkey | dd02e33 | 2018-06-27 14:41:57 -0600 | [diff] [blame] | 529 | BlockGuard.getVmPolicy().onPathAccess(filePath); |
Victor Hsieh | 5f76124 | 2018-01-20 10:30:12 -0800 | [diff] [blame] | 530 | try { |
| 531 | mInstalld.assertFsverityRootHashMatches(filePath, expectedHash); |
| 532 | } catch (Exception e) { |
| 533 | throw InstallerException.from(e); |
| 534 | } |
| 535 | } |
| 536 | |
Calin Juravle | 1aa5f88 | 2017-01-25 01:05:50 -0800 | [diff] [blame] | 537 | public boolean reconcileSecondaryDexFile(String apkPath, String packageName, int uid, |
| 538 | String[] isas, @Nullable String volumeUuid, int flags) throws InstallerException { |
| 539 | for (int i = 0; i < isas.length; i++) { |
| 540 | assertValidInstructionSet(isas[i]); |
| 541 | } |
| 542 | if (!checkBeforeRemote()) return false; |
Jeff Sharkey | dd02e33 | 2018-06-27 14:41:57 -0600 | [diff] [blame] | 543 | BlockGuard.getVmPolicy().onPathAccess(apkPath); |
Calin Juravle | 1aa5f88 | 2017-01-25 01:05:50 -0800 | [diff] [blame] | 544 | try { |
| 545 | return mInstalld.reconcileSecondaryDexFile(apkPath, packageName, uid, isas, |
| 546 | volumeUuid, flags); |
| 547 | } catch (Exception e) { |
| 548 | throw InstallerException.from(e); |
| 549 | } |
| 550 | } |
| 551 | |
Alan Stokes | a002360 | 2017-10-16 12:31:44 +0100 | [diff] [blame] | 552 | public byte[] hashSecondaryDexFile(String dexPath, String packageName, int uid, |
| 553 | @Nullable String volumeUuid, int flags) throws InstallerException { |
| 554 | if (!checkBeforeRemote()) return new byte[0]; |
Jeff Sharkey | dd02e33 | 2018-06-27 14:41:57 -0600 | [diff] [blame] | 555 | BlockGuard.getVmPolicy().onPathAccess(dexPath); |
Alan Stokes | a002360 | 2017-10-16 12:31:44 +0100 | [diff] [blame] | 556 | try { |
| 557 | return mInstalld.hashSecondaryDexFile(dexPath, packageName, uid, volumeUuid, flags); |
| 558 | } catch (Exception e) { |
| 559 | throw InstallerException.from(e); |
| 560 | } |
| 561 | } |
| 562 | |
Calin Juravle | fcbb74a | 2018-01-21 21:39:18 -0800 | [diff] [blame] | 563 | public boolean createProfileSnapshot(int appId, String packageName, String profileName, |
| 564 | String classpath) throws InstallerException { |
Calin Juravle | fd9f8ae | 2017-11-29 18:26:55 -0800 | [diff] [blame] | 565 | if (!checkBeforeRemote()) return false; |
| 566 | try { |
Calin Juravle | fcbb74a | 2018-01-21 21:39:18 -0800 | [diff] [blame] | 567 | return mInstalld.createProfileSnapshot(appId, packageName, profileName, classpath); |
Calin Juravle | fd9f8ae | 2017-11-29 18:26:55 -0800 | [diff] [blame] | 568 | } catch (Exception e) { |
| 569 | throw InstallerException.from(e); |
| 570 | } |
| 571 | } |
| 572 | |
Calin Juravle | 6ae39fc | 2018-01-19 20:32:47 -0800 | [diff] [blame] | 573 | public void destroyProfileSnapshot(String packageName, String profileName) |
Calin Juravle | fd9f8ae | 2017-11-29 18:26:55 -0800 | [diff] [blame] | 574 | throws InstallerException { |
| 575 | if (!checkBeforeRemote()) return; |
| 576 | try { |
Calin Juravle | 6ae39fc | 2018-01-19 20:32:47 -0800 | [diff] [blame] | 577 | mInstalld.destroyProfileSnapshot(packageName, profileName); |
Calin Juravle | fd9f8ae | 2017-11-29 18:26:55 -0800 | [diff] [blame] | 578 | } catch (Exception e) { |
| 579 | throw InstallerException.from(e); |
| 580 | } |
| 581 | } |
| 582 | |
Jeff Sharkey | 7d25faf | 2017-01-16 20:58:40 -0700 | [diff] [blame] | 583 | public void invalidateMounts() throws InstallerException { |
| 584 | if (!checkBeforeRemote()) return; |
| 585 | try { |
| 586 | mInstalld.invalidateMounts(); |
| 587 | } catch (Exception e) { |
| 588 | throw InstallerException.from(e); |
| 589 | } |
| 590 | } |
| 591 | |
Jeff Sharkey | d5d5e92 | 2017-02-21 10:51:23 -0700 | [diff] [blame] | 592 | public boolean isQuotaSupported(String volumeUuid) throws InstallerException { |
| 593 | if (!checkBeforeRemote()) return false; |
| 594 | try { |
| 595 | return mInstalld.isQuotaSupported(volumeUuid); |
| 596 | } catch (Exception e) { |
| 597 | throw InstallerException.from(e); |
| 598 | } |
| 599 | } |
| 600 | |
Calin Juravle | 3621be7 | 2018-01-18 15:17:29 -0800 | [diff] [blame] | 601 | public boolean prepareAppProfile(String pkg, @UserIdInt int userId, @AppIdInt int appId, |
| 602 | String profileName, String codePath, String dexMetadataPath) throws InstallerException { |
| 603 | if (!checkBeforeRemote()) return false; |
Jeff Sharkey | dd02e33 | 2018-06-27 14:41:57 -0600 | [diff] [blame] | 604 | BlockGuard.getVmPolicy().onPathAccess(codePath); |
| 605 | BlockGuard.getVmPolicy().onPathAccess(dexMetadataPath); |
Calin Juravle | 3621be7 | 2018-01-18 15:17:29 -0800 | [diff] [blame] | 606 | try { |
| 607 | return mInstalld.prepareAppProfile(pkg, userId, appId, profileName, codePath, |
| 608 | dexMetadataPath); |
| 609 | } catch (Exception e) { |
| 610 | throw InstallerException.from(e); |
| 611 | } |
| 612 | } |
| 613 | |
Jeff Sharkey | fdeeeea | 2016-01-11 17:34:24 -0700 | [diff] [blame] | 614 | private static void assertValidInstructionSet(String instructionSet) |
| 615 | throws InstallerException { |
Narayan Kamath | 6c4b9de | 2014-08-08 12:44:12 +0100 | [diff] [blame] | 616 | for (String abi : Build.SUPPORTED_ABIS) { |
Jeff Sharkey | fdeeeea | 2016-01-11 17:34:24 -0700 | [diff] [blame] | 617 | if (VMRuntime.getInstructionSet(abi).equals(instructionSet)) { |
| 618 | return; |
Narayan Kamath | 6c4b9de | 2014-08-08 12:44:12 +0100 | [diff] [blame] | 619 | } |
| 620 | } |
Jeff Sharkey | fdeeeea | 2016-01-11 17:34:24 -0700 | [diff] [blame] | 621 | throw new InstallerException("Invalid instruction set: " + instructionSet); |
Narayan Kamath | 6c4b9de | 2014-08-08 12:44:12 +0100 | [diff] [blame] | 622 | } |
Jeff Sharkey | 740f523 | 2016-12-09 14:31:26 -0700 | [diff] [blame] | 623 | |
| 624 | public static class InstallerException extends Exception { |
| 625 | public InstallerException(String detailMessage) { |
| 626 | super(detailMessage); |
| 627 | } |
| 628 | |
| 629 | public static InstallerException from(Exception e) throws InstallerException { |
Jeff Sharkey | 447a3ac | 2016-12-12 10:15:37 -0700 | [diff] [blame] | 630 | throw new InstallerException(e.toString()); |
Jeff Sharkey | 740f523 | 2016-12-09 14:31:26 -0700 | [diff] [blame] | 631 | } |
| 632 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 633 | } |