Fyodor Kupolov | 7487657 | 2015-02-23 17:14:45 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 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 | |
| 17 | package com.android.server.pm; |
| 18 | |
Fyodor Kupolov | b94c165 | 2015-03-03 12:25:30 -0800 | [diff] [blame] | 19 | import android.annotation.Nullable; |
Fyodor Kupolov | a627c09 | 2015-05-05 18:44:39 -0700 | [diff] [blame] | 20 | import android.content.Context; |
Fyodor Kupolov | 7487657 | 2015-02-23 17:14:45 -0800 | [diff] [blame] | 21 | import android.content.pm.ApplicationInfo; |
| 22 | import android.content.pm.PackageParser; |
Andreas Gampe | a890875 | 2015-11-10 08:58:14 -0800 | [diff] [blame] | 23 | import android.content.pm.PackageParser.Package; |
Calin Juravle | d479b52 | 2016-02-24 16:22:03 +0000 | [diff] [blame] | 24 | import android.os.Environment; |
Fyodor Kupolov | a627c09 | 2015-05-05 18:44:39 -0700 | [diff] [blame] | 25 | import android.os.PowerManager; |
Fyodor Kupolov | 7487657 | 2015-02-23 17:14:45 -0800 | [diff] [blame] | 26 | import android.os.UserHandle; |
Fyodor Kupolov | a627c09 | 2015-05-05 18:44:39 -0700 | [diff] [blame] | 27 | import android.os.WorkSource; |
Calin Juravle | db4a79a | 2015-12-23 18:55:08 +0200 | [diff] [blame] | 28 | import android.os.storage.StorageManager; |
Fyodor Kupolov | 7487657 | 2015-02-23 17:14:45 -0800 | [diff] [blame] | 29 | import android.util.ArraySet; |
| 30 | import android.util.Log; |
| 31 | import android.util.Slog; |
| 32 | |
Jeff Sharkey | fdeeeea | 2016-01-11 17:34:24 -0700 | [diff] [blame] | 33 | import com.android.internal.os.InstallerConnection.InstallerException; |
| 34 | |
Fyodor Kupolov | b94c165 | 2015-03-03 12:25:30 -0800 | [diff] [blame] | 35 | import java.io.File; |
Fyodor Kupolov | 7487657 | 2015-02-23 17:14:45 -0800 | [diff] [blame] | 36 | import java.io.IOException; |
| 37 | import java.util.ArrayList; |
| 38 | import java.util.List; |
| 39 | |
| 40 | import dalvik.system.DexFile; |
Fyodor Kupolov | 7487657 | 2015-02-23 17:14:45 -0800 | [diff] [blame] | 41 | |
Todd Kennedy | fa54ab7 | 2015-09-25 07:46:12 -0700 | [diff] [blame] | 42 | import static com.android.server.pm.Installer.DEXOPT_BOOTCOMPLETE; |
| 43 | import static com.android.server.pm.Installer.DEXOPT_DEBUGGABLE; |
| 44 | import static com.android.server.pm.Installer.DEXOPT_PUBLIC; |
| 45 | import static com.android.server.pm.Installer.DEXOPT_SAFEMODE; |
David Brazdil | a0e1043 | 2016-01-20 14:04:40 +0000 | [diff] [blame] | 46 | import static com.android.server.pm.Installer.DEXOPT_EXTRACTONLY; |
Fyodor Kupolov | 7487657 | 2015-02-23 17:14:45 -0800 | [diff] [blame] | 47 | import static com.android.server.pm.InstructionSets.getAppDexInstructionSets; |
| 48 | import static com.android.server.pm.InstructionSets.getDexCodeInstructionSets; |
| 49 | |
| 50 | /** |
| 51 | * Helper class for running dexopt command on packages. |
| 52 | */ |
Andreas Gampe | a890875 | 2015-11-10 08:58:14 -0800 | [diff] [blame] | 53 | class PackageDexOptimizer { |
Fyodor Kupolov | b94c165 | 2015-03-03 12:25:30 -0800 | [diff] [blame] | 54 | private static final String TAG = "PackageManager.DexOptimizer"; |
| 55 | static final String OAT_DIR_NAME = "oat"; |
| 56 | // TODO b/19550105 Remove error codes and use exceptions |
Fyodor Kupolov | 7487657 | 2015-02-23 17:14:45 -0800 | [diff] [blame] | 57 | static final int DEX_OPT_SKIPPED = 0; |
| 58 | static final int DEX_OPT_PERFORMED = 1; |
| 59 | static final int DEX_OPT_DEFERRED = 2; |
| 60 | static final int DEX_OPT_FAILED = -1; |
| 61 | |
Andreas Gampe | a890875 | 2015-11-10 08:58:14 -0800 | [diff] [blame] | 62 | private static final boolean DEBUG_DEXOPT = PackageManagerService.DEBUG_DEXOPT; |
| 63 | |
| 64 | private final Installer mInstaller; |
| 65 | private final Object mInstallLock; |
Fyodor Kupolov | 7487657 | 2015-02-23 17:14:45 -0800 | [diff] [blame] | 66 | |
Fyodor Kupolov | a627c09 | 2015-05-05 18:44:39 -0700 | [diff] [blame] | 67 | private final PowerManager.WakeLock mDexoptWakeLock; |
| 68 | private volatile boolean mSystemReady; |
| 69 | |
Andreas Gampe | a890875 | 2015-11-10 08:58:14 -0800 | [diff] [blame] | 70 | PackageDexOptimizer(Installer installer, Object installLock, Context context, |
| 71 | String wakeLockTag) { |
| 72 | this.mInstaller = installer; |
| 73 | this.mInstallLock = installLock; |
| 74 | |
| 75 | PowerManager powerManager = (PowerManager)context.getSystemService(Context.POWER_SERVICE); |
| 76 | mDexoptWakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, wakeLockTag); |
| 77 | } |
| 78 | |
| 79 | protected PackageDexOptimizer(PackageDexOptimizer from) { |
| 80 | this.mInstaller = from.mInstaller; |
| 81 | this.mInstallLock = from.mInstallLock; |
| 82 | this.mDexoptWakeLock = from.mDexoptWakeLock; |
| 83 | this.mSystemReady = from.mSystemReady; |
Fyodor Kupolov | 7487657 | 2015-02-23 17:14:45 -0800 | [diff] [blame] | 84 | } |
| 85 | |
Calin Juravle | db4a79a | 2015-12-23 18:55:08 +0200 | [diff] [blame] | 86 | static boolean canOptimizePackage(PackageParser.Package pkg) { |
Calin Juravle | 6dfd83d | 2016-01-29 18:23:57 +0000 | [diff] [blame] | 87 | return (pkg.applicationInfo.flags & ApplicationInfo.FLAG_HAS_CODE) != 0; |
Calin Juravle | db4a79a | 2015-12-23 18:55:08 +0200 | [diff] [blame] | 88 | } |
| 89 | |
Fyodor Kupolov | 7487657 | 2015-02-23 17:14:45 -0800 | [diff] [blame] | 90 | /** |
| 91 | * Performs dexopt on all code paths and libraries of the specified package for specified |
| 92 | * instruction sets. |
| 93 | * |
Andreas Gampe | a890875 | 2015-11-10 08:58:14 -0800 | [diff] [blame] | 94 | * <p>Calls to {@link com.android.server.pm.Installer#dexopt} on {@link #mInstaller} are |
| 95 | * synchronized on {@link #mInstallLock}. |
Fyodor Kupolov | 7487657 | 2015-02-23 17:14:45 -0800 | [diff] [blame] | 96 | */ |
Andreas Gampe | a890875 | 2015-11-10 08:58:14 -0800 | [diff] [blame] | 97 | int performDexOpt(PackageParser.Package pkg, String[] instructionSets, boolean useProfiles, |
| 98 | boolean extractOnly) { |
| 99 | synchronized (mInstallLock) { |
Fyodor Kupolov | a627c09 | 2015-05-05 18:44:39 -0700 | [diff] [blame] | 100 | final boolean useLock = mSystemReady; |
| 101 | if (useLock) { |
| 102 | mDexoptWakeLock.setWorkSource(new WorkSource(pkg.applicationInfo.uid)); |
| 103 | mDexoptWakeLock.acquire(); |
| 104 | } |
| 105 | try { |
Andreas Gampe | a890875 | 2015-11-10 08:58:14 -0800 | [diff] [blame] | 106 | return performDexOptLI(pkg, instructionSets, useProfiles, extractOnly); |
Fyodor Kupolov | a627c09 | 2015-05-05 18:44:39 -0700 | [diff] [blame] | 107 | } finally { |
| 108 | if (useLock) { |
| 109 | mDexoptWakeLock.release(); |
| 110 | } |
| 111 | } |
Fyodor Kupolov | 7487657 | 2015-02-23 17:14:45 -0800 | [diff] [blame] | 112 | } |
| 113 | } |
| 114 | |
Andreas Gampe | a890875 | 2015-11-10 08:58:14 -0800 | [diff] [blame] | 115 | /** |
| 116 | * Determine whether the package should be skipped for the given instruction set. A return |
| 117 | * value of true means the package will be skipped. A return value of false means that the |
| 118 | * package will be further investigated, and potentially compiled. |
| 119 | */ |
| 120 | protected boolean shouldSkipBasedOnISA(PackageParser.Package pkg, String instructionSet) { |
| 121 | return pkg.mDexOptPerformed.contains(instructionSet); |
| 122 | } |
| 123 | |
| 124 | /** |
| 125 | * Adjust the given dexopt-needed value. Can be overridden to influence the decision to |
| 126 | * optimize or not (and in what way). |
| 127 | */ |
| 128 | protected int adjustDexoptNeeded(int dexoptNeeded) { |
| 129 | return dexoptNeeded; |
| 130 | } |
| 131 | |
| 132 | /** |
| 133 | * Adjust the given dexopt flags that will be passed to the installer. |
| 134 | */ |
| 135 | protected int adjustDexoptFlags(int dexoptFlags) { |
| 136 | return dexoptFlags; |
| 137 | } |
| 138 | |
| 139 | /** |
| 140 | * Update the package status after a successful compilation. |
| 141 | */ |
| 142 | protected void recordSuccessfulDexopt(PackageParser.Package pkg, String instructionSet) { |
| 143 | pkg.mDexOptPerformed.add(instructionSet); |
| 144 | } |
| 145 | |
Fyodor Kupolov | 7487657 | 2015-02-23 17:14:45 -0800 | [diff] [blame] | 146 | private int performDexOptLI(PackageParser.Package pkg, String[] targetInstructionSets, |
Andreas Gampe | a890875 | 2015-11-10 08:58:14 -0800 | [diff] [blame] | 147 | boolean useProfiles, boolean extractOnly) { |
Fyodor Kupolov | 7487657 | 2015-02-23 17:14:45 -0800 | [diff] [blame] | 148 | final String[] instructionSets = targetInstructionSets != null ? |
| 149 | targetInstructionSets : getAppDexInstructionSets(pkg.applicationInfo); |
| 150 | |
Calin Juravle | db4a79a | 2015-12-23 18:55:08 +0200 | [diff] [blame] | 151 | if (!canOptimizePackage(pkg)) { |
Fyodor Kupolov | 7487657 | 2015-02-23 17:14:45 -0800 | [diff] [blame] | 152 | return DEX_OPT_SKIPPED; |
| 153 | } |
| 154 | |
| 155 | final boolean vmSafeMode = (pkg.applicationInfo.flags & ApplicationInfo.FLAG_VM_SAFE_MODE) != 0; |
| 156 | final boolean debuggable = (pkg.applicationInfo.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0; |
| 157 | |
| 158 | final List<String> paths = pkg.getAllCodePathsExcludingResourceOnly(); |
| 159 | boolean performedDexOpt = false; |
Fyodor Kupolov | 7487657 | 2015-02-23 17:14:45 -0800 | [diff] [blame] | 160 | final String[] dexCodeInstructionSets = getDexCodeInstructionSets(instructionSets); |
| 161 | for (String dexCodeInstructionSet : dexCodeInstructionSets) { |
Andreas Gampe | a890875 | 2015-11-10 08:58:14 -0800 | [diff] [blame] | 162 | if (!useProfiles && shouldSkipBasedOnISA(pkg, dexCodeInstructionSet)) { |
| 163 | // Skip only if we do not use profiles since they might trigger a recompilation. |
Fyodor Kupolov | 7487657 | 2015-02-23 17:14:45 -0800 | [diff] [blame] | 164 | continue; |
| 165 | } |
| 166 | |
| 167 | for (String path : paths) { |
Calin Juravle | d479b52 | 2016-02-24 16:22:03 +0000 | [diff] [blame] | 168 | if (useProfiles && isUsedByOtherApps(path)) { |
| 169 | // We cannot use profile guided compilation if the apk was used by another app. |
| 170 | useProfiles = false; |
| 171 | } |
Calin Juravle | db4a79a | 2015-12-23 18:55:08 +0200 | [diff] [blame] | 172 | int dexoptNeeded; |
David Brazdil | 493411a | 2016-02-01 13:48:46 +0000 | [diff] [blame] | 173 | |
Andreas Gampe | a890875 | 2015-11-10 08:58:14 -0800 | [diff] [blame] | 174 | try { |
| 175 | dexoptNeeded = DexFile.getDexOptNeeded(path, pkg.packageName, |
| 176 | dexCodeInstructionSet, /* defer */false); |
| 177 | } catch (IOException ioe) { |
| 178 | Slog.w(TAG, "IOException reading apk: " + path, ioe); |
| 179 | return DEX_OPT_FAILED; |
Narayan Kamath | 01dcb76 | 2015-05-07 17:48:42 +0100 | [diff] [blame] | 180 | } |
Andreas Gampe | a890875 | 2015-11-10 08:58:14 -0800 | [diff] [blame] | 181 | dexoptNeeded = adjustDexoptNeeded(dexoptNeeded); |
Richard Uhler | 7b08b35 | 2015-03-25 16:25:57 -0700 | [diff] [blame] | 182 | |
Calin Juravle | db4a79a | 2015-12-23 18:55:08 +0200 | [diff] [blame] | 183 | if (dexoptNeeded == DexFile.NO_DEXOPT_NEEDED) { |
Calin Juravle | 0cf8cc6 | 2016-02-03 19:05:18 +0000 | [diff] [blame] | 184 | if (useProfiles) { |
| 185 | // Profiles may trigger re-compilation. The final decision is taken in |
| 186 | // installd. |
| 187 | dexoptNeeded = DexFile.DEX2OAT_NEEDED; |
| 188 | } else { |
| 189 | // No dexopt needed and we don't use profiles. Nothing to do. |
| 190 | continue; |
| 191 | } |
Calin Juravle | db4a79a | 2015-12-23 18:55:08 +0200 | [diff] [blame] | 192 | } |
| 193 | final String dexoptType; |
| 194 | String oatDir = null; |
| 195 | if (dexoptNeeded == DexFile.DEX2OAT_NEEDED) { |
| 196 | dexoptType = "dex2oat"; |
| 197 | oatDir = createOatDirIfSupported(pkg, dexCodeInstructionSet); |
| 198 | } else if (dexoptNeeded == DexFile.PATCHOAT_NEEDED) { |
| 199 | dexoptType = "patchoat"; |
| 200 | } else if (dexoptNeeded == DexFile.SELF_PATCHOAT_NEEDED) { |
| 201 | dexoptType = "self patchoat"; |
| 202 | } else { |
| 203 | throw new IllegalStateException("Invalid dexopt needed: " + dexoptNeeded); |
| 204 | } |
Narayan Kamath | 01dcb76 | 2015-05-07 17:48:42 +0100 | [diff] [blame] | 205 | |
Andreas Gampe | a890875 | 2015-11-10 08:58:14 -0800 | [diff] [blame] | 206 | |
Calin Juravle | db4a79a | 2015-12-23 18:55:08 +0200 | [diff] [blame] | 207 | Log.i(TAG, "Running dexopt (" + dexoptType + ") on: " + path + " pkg=" |
| 208 | + pkg.applicationInfo.packageName + " isa=" + dexCodeInstructionSet |
| 209 | + " vmSafeMode=" + vmSafeMode + " debuggable=" + debuggable |
David Brazdil | a0e1043 | 2016-01-20 14:04:40 +0000 | [diff] [blame] | 210 | + " extractOnly=" + extractOnly + " oatDir = " + oatDir); |
Calin Juravle | db4a79a | 2015-12-23 18:55:08 +0200 | [diff] [blame] | 211 | final int sharedGid = UserHandle.getSharedAppGid(pkg.applicationInfo.uid); |
Calin Juravle | d479b52 | 2016-02-24 16:22:03 +0000 | [diff] [blame] | 212 | // Profile guide compiled oat files should not be public. |
| 213 | final boolean isPublic = !pkg.isForwardLocked() && !useProfiles; |
Andreas Gampe | a890875 | 2015-11-10 08:58:14 -0800 | [diff] [blame] | 214 | final int dexFlags = adjustDexoptFlags( |
Calin Juravle | d479b52 | 2016-02-24 16:22:03 +0000 | [diff] [blame] | 215 | ( isPublic ? DEXOPT_PUBLIC : 0) |
Calin Juravle | db4a79a | 2015-12-23 18:55:08 +0200 | [diff] [blame] | 216 | | (vmSafeMode ? DEXOPT_SAFEMODE : 0) |
| 217 | | (debuggable ? DEXOPT_DEBUGGABLE : 0) |
David Brazdil | a0e1043 | 2016-01-20 14:04:40 +0000 | [diff] [blame] | 218 | | (extractOnly ? DEXOPT_EXTRACTONLY : 0) |
Andreas Gampe | a890875 | 2015-11-10 08:58:14 -0800 | [diff] [blame] | 219 | | DEXOPT_BOOTCOMPLETE); |
| 220 | |
Calin Juravle | db4a79a | 2015-12-23 18:55:08 +0200 | [diff] [blame] | 221 | try { |
Andreas Gampe | a890875 | 2015-11-10 08:58:14 -0800 | [diff] [blame] | 222 | mInstaller.dexopt(path, sharedGid, pkg.packageName, dexCodeInstructionSet, |
| 223 | dexoptNeeded, oatDir, dexFlags, pkg.volumeUuid, useProfiles); |
Calin Juravle | db4a79a | 2015-12-23 18:55:08 +0200 | [diff] [blame] | 224 | performedDexOpt = true; |
| 225 | } catch (InstallerException e) { |
| 226 | Slog.w(TAG, "Failed to dexopt", e); |
Fyodor Kupolov | 7487657 | 2015-02-23 17:14:45 -0800 | [diff] [blame] | 227 | } |
| 228 | } |
| 229 | |
David Brazdil | a0e1043 | 2016-01-20 14:04:40 +0000 | [diff] [blame] | 230 | if (!extractOnly) { |
| 231 | // At this point we haven't failed dexopt and we haven't deferred dexopt. We must |
| 232 | // either have either succeeded dexopt, or have had getDexOptNeeded tell us |
| 233 | // it isn't required. We therefore mark that this package doesn't need dexopt unless |
| 234 | // it's forced. performedDexOpt will tell us whether we performed dex-opt or skipped |
| 235 | // it. |
Andreas Gampe | a890875 | 2015-11-10 08:58:14 -0800 | [diff] [blame] | 236 | recordSuccessfulDexopt(pkg, dexCodeInstructionSet); |
David Brazdil | a0e1043 | 2016-01-20 14:04:40 +0000 | [diff] [blame] | 237 | } |
Fyodor Kupolov | 7487657 | 2015-02-23 17:14:45 -0800 | [diff] [blame] | 238 | } |
| 239 | |
| 240 | // If we've gotten here, we're sure that no error occurred and that we haven't |
| 241 | // deferred dex-opt. We've either dex-opted one more paths or instruction sets or |
| 242 | // we've skipped all of them because they are up to date. In both cases this |
| 243 | // package doesn't need dexopt any longer. |
| 244 | return performedDexOpt ? DEX_OPT_PERFORMED : DEX_OPT_SKIPPED; |
| 245 | } |
| 246 | |
Fyodor Kupolov | b94c165 | 2015-03-03 12:25:30 -0800 | [diff] [blame] | 247 | /** |
| 248 | * Creates oat dir for the specified package. In certain cases oat directory |
| 249 | * <strong>cannot</strong> be created: |
| 250 | * <ul> |
| 251 | * <li>{@code pkg} is a system app, which is not updated.</li> |
| 252 | * <li>Package location is not a directory, i.e. monolithic install.</li> |
| 253 | * </ul> |
| 254 | * |
Richard Uhler | 7b08b35 | 2015-03-25 16:25:57 -0700 | [diff] [blame] | 255 | * @return Absolute path to the oat directory or null, if oat directory |
| 256 | * cannot be created. |
Fyodor Kupolov | b94c165 | 2015-03-03 12:25:30 -0800 | [diff] [blame] | 257 | */ |
| 258 | @Nullable |
Todd Kennedy | 27c24fb | 2015-09-17 16:49:25 -0700 | [diff] [blame] | 259 | private String createOatDirIfSupported(PackageParser.Package pkg, String dexInstructionSet) { |
Fyodor Kupolov | ebcac16 | 2015-09-09 15:56:45 -0700 | [diff] [blame] | 260 | if (!pkg.canHaveOatDir()) { |
Fyodor Kupolov | b94c165 | 2015-03-03 12:25:30 -0800 | [diff] [blame] | 261 | return null; |
| 262 | } |
| 263 | File codePath = new File(pkg.codePath); |
| 264 | if (codePath.isDirectory()) { |
| 265 | File oatDir = getOatDir(codePath); |
Jeff Sharkey | fdeeeea | 2016-01-11 17:34:24 -0700 | [diff] [blame] | 266 | try { |
Andreas Gampe | a890875 | 2015-11-10 08:58:14 -0800 | [diff] [blame] | 267 | mInstaller.createOatDir(oatDir.getAbsolutePath(), dexInstructionSet); |
Jeff Sharkey | fdeeeea | 2016-01-11 17:34:24 -0700 | [diff] [blame] | 268 | } catch (InstallerException e) { |
| 269 | Slog.w(TAG, "Failed to create oat dir", e); |
| 270 | return null; |
| 271 | } |
Richard Uhler | 7b08b35 | 2015-03-25 16:25:57 -0700 | [diff] [blame] | 272 | return oatDir.getAbsolutePath(); |
Fyodor Kupolov | b94c165 | 2015-03-03 12:25:30 -0800 | [diff] [blame] | 273 | } |
| 274 | return null; |
| 275 | } |
| 276 | |
| 277 | static File getOatDir(File codePath) { |
| 278 | return new File(codePath, OAT_DIR_NAME); |
| 279 | } |
| 280 | |
Fyodor Kupolov | a627c09 | 2015-05-05 18:44:39 -0700 | [diff] [blame] | 281 | void systemReady() { |
| 282 | mSystemReady = true; |
| 283 | } |
Andreas Gampe | a890875 | 2015-11-10 08:58:14 -0800 | [diff] [blame] | 284 | |
Calin Juravle | d479b52 | 2016-02-24 16:22:03 +0000 | [diff] [blame] | 285 | private boolean isUsedByOtherApps(String apkPath) { |
| 286 | try { |
| 287 | apkPath = new File(apkPath).getCanonicalPath(); |
| 288 | } catch (IOException e) { |
| 289 | // Log an error but continue without it. |
| 290 | Slog.w(TAG, "Failed to get canonical path", e); |
| 291 | } |
| 292 | String useMarker = apkPath.replace('/', '@'); |
| 293 | final int[] currentUserIds = UserManagerService.getInstance().getUserIds(); |
| 294 | for (int i = 0; i < currentUserIds.length; i++) { |
| 295 | File profileDir = Environment.getDataProfilesDeForeignDexDirectory(currentUserIds[i]); |
| 296 | File foreignUseMark = new File(profileDir, useMarker); |
| 297 | if (foreignUseMark.exists()) { |
| 298 | return true; |
| 299 | } |
| 300 | } |
| 301 | return false; |
| 302 | } |
| 303 | |
Andreas Gampe | a890875 | 2015-11-10 08:58:14 -0800 | [diff] [blame] | 304 | /** |
| 305 | * A specialized PackageDexOptimizer that overrides already-installed checks, forcing a |
| 306 | * dexopt path. |
| 307 | */ |
| 308 | public static class ForcedUpdatePackageDexOptimizer extends PackageDexOptimizer { |
| 309 | |
| 310 | public ForcedUpdatePackageDexOptimizer(Installer installer, Object installLock, |
| 311 | Context context, String wakeLockTag) { |
| 312 | super(installer, installLock, context, wakeLockTag); |
| 313 | } |
| 314 | |
| 315 | public ForcedUpdatePackageDexOptimizer(PackageDexOptimizer from) { |
| 316 | super(from); |
| 317 | } |
| 318 | |
| 319 | @Override |
| 320 | protected boolean shouldSkipBasedOnISA(Package pkg, String instructionSet) { |
| 321 | // Forced compilation, never skip. |
| 322 | return false; |
| 323 | } |
| 324 | |
| 325 | @Override |
| 326 | protected int adjustDexoptNeeded(int dexoptNeeded) { |
| 327 | // Ensure compilation, no matter the current state. |
| 328 | // TODO: The return value is wrong when patchoat is needed. |
| 329 | return DexFile.DEX2OAT_NEEDED; |
| 330 | } |
| 331 | } |
Fyodor Kupolov | 7487657 | 2015-02-23 17:14:45 -0800 | [diff] [blame] | 332 | } |