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