Jiakai Zhang | c3db1c7 | 2022-10-18 10:59:13 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2022 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.art; |
| 18 | |
| 19 | import static com.android.server.art.GetDexoptNeededResult.ArtifactsLocation; |
| 20 | import static com.android.server.art.OutputArtifacts.PermissionSettings; |
| 21 | import static com.android.server.art.ProfilePath.TmpProfilePath; |
| 22 | import static com.android.server.art.Utils.Abi; |
Jiakai Zhang | 771f64e | 2023-01-12 17:32:36 +0800 | [diff] [blame] | 23 | import static com.android.server.art.model.ArtFlags.DexoptFlags; |
| 24 | import static com.android.server.art.model.DexoptResult.DexContainerFileDexoptResult; |
Jiakai Zhang | c3db1c7 | 2022-10-18 10:59:13 +0100 | [diff] [blame] | 25 | |
| 26 | import android.R; |
| 27 | import android.annotation.NonNull; |
| 28 | import android.annotation.Nullable; |
| 29 | import android.content.Context; |
Jiakai Zhang | 914197f | 2022-12-21 10:22:14 +0000 | [diff] [blame] | 30 | import android.content.pm.ApplicationInfo; |
Jiakai Zhang | c3db1c7 | 2022-10-18 10:59:13 +0100 | [diff] [blame] | 31 | import android.os.CancellationSignal; |
| 32 | import android.os.RemoteException; |
| 33 | import android.os.ServiceSpecificException; |
| 34 | import android.os.SystemProperties; |
| 35 | import android.os.UserManager; |
Jiakai Zhang | de3844b | 2022-11-30 11:28:11 +0000 | [diff] [blame] | 36 | import android.os.storage.StorageManager; |
Jiakai Zhang | c3db1c7 | 2022-10-18 10:59:13 +0100 | [diff] [blame] | 37 | import android.text.TextUtils; |
| 38 | import android.util.Log; |
| 39 | import android.util.Pair; |
| 40 | |
| 41 | import com.android.internal.annotations.VisibleForTesting; |
Jiakai Zhang | 91fe951 | 2022-11-14 19:42:32 +0000 | [diff] [blame] | 42 | import com.android.server.LocalManagerRegistry; |
Jiakai Zhang | c3db1c7 | 2022-10-18 10:59:13 +0100 | [diff] [blame] | 43 | import com.android.server.art.model.ArtFlags; |
| 44 | import com.android.server.art.model.DetailedDexInfo; |
Jiakai Zhang | 771f64e | 2023-01-12 17:32:36 +0800 | [diff] [blame] | 45 | import com.android.server.art.model.DexoptParams; |
| 46 | import com.android.server.art.model.DexoptResult; |
Jiakai Zhang | c3db1c7 | 2022-10-18 10:59:13 +0100 | [diff] [blame] | 47 | import com.android.server.pm.pkg.AndroidPackage; |
| 48 | import com.android.server.pm.pkg.PackageState; |
| 49 | |
| 50 | import dalvik.system.DexFile; |
| 51 | |
| 52 | import com.google.auto.value.AutoValue; |
| 53 | |
Jiakai Zhang | de3844b | 2022-11-30 11:28:11 +0000 | [diff] [blame] | 54 | import java.io.IOException; |
Jiakai Zhang | c3db1c7 | 2022-10-18 10:59:13 +0100 | [diff] [blame] | 55 | import java.util.ArrayList; |
| 56 | import java.util.List; |
| 57 | import java.util.Objects; |
| 58 | |
| 59 | /** @hide */ |
Jiakai Zhang | 2777d7a | 2023-01-13 15:37:13 +0800 | [diff] [blame] | 60 | public abstract class Dexopter<DexInfoType extends DetailedDexInfo> { |
| 61 | private static final String TAG = "Dexopter"; |
Jiakai Zhang | c3db1c7 | 2022-10-18 10:59:13 +0100 | [diff] [blame] | 62 | |
| 63 | @NonNull protected final Injector mInjector; |
| 64 | @NonNull protected final PackageState mPkgState; |
| 65 | /** This is always {@code mPkgState.getAndroidPackage()} and guaranteed to be non-null. */ |
| 66 | @NonNull protected final AndroidPackage mPkg; |
Jiakai Zhang | 771f64e | 2023-01-12 17:32:36 +0800 | [diff] [blame] | 67 | @NonNull protected final DexoptParams mParams; |
Jiakai Zhang | c3db1c7 | 2022-10-18 10:59:13 +0100 | [diff] [blame] | 68 | @NonNull protected final CancellationSignal mCancellationSignal; |
| 69 | |
Jiakai Zhang | 2777d7a | 2023-01-13 15:37:13 +0800 | [diff] [blame] | 70 | protected Dexopter(@NonNull Injector injector, @NonNull PackageState pkgState, |
Jiakai Zhang | 771f64e | 2023-01-12 17:32:36 +0800 | [diff] [blame] | 71 | @NonNull AndroidPackage pkg, @NonNull DexoptParams params, |
Jiakai Zhang | c3db1c7 | 2022-10-18 10:59:13 +0100 | [diff] [blame] | 72 | @NonNull CancellationSignal cancellationSignal) { |
| 73 | mInjector = injector; |
| 74 | mPkgState = pkgState; |
| 75 | mPkg = pkg; |
| 76 | mParams = params; |
| 77 | mCancellationSignal = cancellationSignal; |
| 78 | if (pkgState.getAppId() < 0) { |
| 79 | throw new IllegalStateException( |
| 80 | "Package '" + pkgState.getPackageName() + "' has invalid app ID"); |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | /** |
| 85 | * DO NOT use this method directly. Use {@link |
Jiakai Zhang | 771f64e | 2023-01-12 17:32:36 +0800 | [diff] [blame] | 86 | * ArtManagerLocal#dexoptPackage(PackageManagerLocal.FilteredSnapshot, String, |
| 87 | * DexoptParams)}. |
Jiakai Zhang | c3db1c7 | 2022-10-18 10:59:13 +0100 | [diff] [blame] | 88 | */ |
| 89 | @NonNull |
Jiakai Zhang | 771f64e | 2023-01-12 17:32:36 +0800 | [diff] [blame] | 90 | public final List<DexContainerFileDexoptResult> dexopt() throws RemoteException { |
| 91 | List<DexContainerFileDexoptResult> results = new ArrayList<>(); |
Jiakai Zhang | c3db1c7 | 2022-10-18 10:59:13 +0100 | [diff] [blame] | 92 | |
Jiakai Zhang | c3db1c7 | 2022-10-18 10:59:13 +0100 | [diff] [blame] | 93 | for (DexInfoType dexInfo : getDexInfoList()) { |
| 94 | ProfilePath profile = null; |
| 95 | boolean succeeded = true; |
| 96 | try { |
Jiakai Zhang | 771f64e | 2023-01-12 17:32:36 +0800 | [diff] [blame] | 97 | if (!isDexoptable(dexInfo)) { |
Jiakai Zhang | c3db1c7 | 2022-10-18 10:59:13 +0100 | [diff] [blame] | 98 | continue; |
| 99 | } |
| 100 | |
Jiakai Zhang | 12f45c4 | 2022-10-27 15:23:03 +0100 | [diff] [blame] | 101 | String compilerFilter = adjustCompilerFilter(mParams.getCompilerFilter(), dexInfo); |
Jiakai Zhang | 771f64e | 2023-01-12 17:32:36 +0800 | [diff] [blame] | 102 | if (compilerFilter.equals(DexoptParams.COMPILER_FILTER_NOOP)) { |
Jiakai Zhang | 12f45c4 | 2022-10-27 15:23:03 +0100 | [diff] [blame] | 103 | continue; |
| 104 | } |
Jiakai Zhang | c3db1c7 | 2022-10-18 10:59:13 +0100 | [diff] [blame] | 105 | |
| 106 | boolean needsToBeShared = needsToBeShared(dexInfo); |
| 107 | boolean isOtherReadable = true; |
| 108 | // If true, implies that the profile has changed since the last compilation. |
| 109 | boolean profileMerged = false; |
| 110 | if (DexFile.isProfileGuidedCompilerFilter(compilerFilter)) { |
| 111 | if (needsToBeShared) { |
| 112 | profile = initReferenceProfile(dexInfo); |
| 113 | } else { |
| 114 | Pair<ProfilePath, Boolean> pair = getOrInitReferenceProfile(dexInfo); |
| 115 | if (pair != null) { |
| 116 | profile = pair.first; |
| 117 | isOtherReadable = pair.second; |
| 118 | } |
| 119 | ProfilePath mergedProfile = mergeProfiles(dexInfo, profile); |
| 120 | if (mergedProfile != null) { |
| 121 | if (profile != null && profile.getTag() == ProfilePath.tmpProfilePath) { |
| 122 | mInjector.getArtd().deleteProfile(profile); |
| 123 | } |
| 124 | profile = mergedProfile; |
| 125 | isOtherReadable = false; |
| 126 | profileMerged = true; |
| 127 | } |
| 128 | } |
| 129 | if (profile == null) { |
Jiakai Zhang | 771f64e | 2023-01-12 17:32:36 +0800 | [diff] [blame] | 130 | // A profile guided dexopt with no profile is essentially 'verify', |
Jiakai Zhang | c3db1c7 | 2022-10-18 10:59:13 +0100 | [diff] [blame] | 131 | // and dex2oat already makes this transformation. However, we need to |
| 132 | // explicitly make this transformation here to guide the later decisions |
| 133 | // such as whether the artifacts can be public and whether dexopt is needed. |
| 134 | compilerFilter = needsToBeShared |
| 135 | ? ReasonMapping.getCompilerFilterForShared() |
| 136 | : "verify"; |
| 137 | } |
| 138 | } |
| 139 | boolean isProfileGuidedCompilerFilter = |
| 140 | DexFile.isProfileGuidedCompilerFilter(compilerFilter); |
| 141 | Utils.check(isProfileGuidedCompilerFilter == (profile != null)); |
| 142 | |
Jiakai Zhang | 12f45c4 | 2022-10-27 15:23:03 +0100 | [diff] [blame] | 143 | boolean canBePublic = (!isProfileGuidedCompilerFilter || isOtherReadable) |
| 144 | && isDexFilePublic(dexInfo); |
Jiakai Zhang | c3db1c7 | 2022-10-18 10:59:13 +0100 | [diff] [blame] | 145 | Utils.check(Utils.implies(needsToBeShared, canBePublic)); |
| 146 | PermissionSettings permissionSettings = getPermissionSettings(dexInfo, canBePublic); |
| 147 | |
Jiakai Zhang | 2698a49 | 2022-11-14 14:36:01 +0000 | [diff] [blame] | 148 | DexoptOptions dexoptOptions = |
| 149 | getDexoptOptions(dexInfo, isProfileGuidedCompilerFilter); |
Jiakai Zhang | c3db1c7 | 2022-10-18 10:59:13 +0100 | [diff] [blame] | 150 | |
| 151 | for (Abi abi : getAllAbis(dexInfo)) { |
Jiakai Zhang | 771f64e | 2023-01-12 17:32:36 +0800 | [diff] [blame] | 152 | @DexoptResult.DexoptResultStatus int status = DexoptResult.DEXOPT_SKIPPED; |
Jiakai Zhang | c3db1c7 | 2022-10-18 10:59:13 +0100 | [diff] [blame] | 153 | long wallTimeMs = 0; |
| 154 | long cpuTimeMs = 0; |
Jiakai Zhang | 843ce52 | 2022-11-11 14:00:39 +0000 | [diff] [blame] | 155 | long sizeBytes = 0; |
| 156 | long sizeBeforeBytes = 0; |
Jiakai Zhang | de3844b | 2022-11-30 11:28:11 +0000 | [diff] [blame] | 157 | boolean isSkippedDueToStorageLow = false; |
Jiakai Zhang | c3db1c7 | 2022-10-18 10:59:13 +0100 | [diff] [blame] | 158 | try { |
Jiakai Zhang | bfd155d | 2022-11-08 13:17:50 +0000 | [diff] [blame] | 159 | var target = DexoptTarget.<DexInfoType>builder() |
Jiakai Zhang | 2777d7a | 2023-01-13 15:37:13 +0800 | [diff] [blame] | 160 | .setDexInfo(dexInfo) |
| 161 | .setIsa(abi.isa()) |
| 162 | .setIsInDalvikCache(isInDalvikCache()) |
| 163 | .setCompilerFilter(compilerFilter) |
| 164 | .build(); |
| 165 | var options = GetDexoptNeededOptions.builder() |
| 166 | .setProfileMerged(profileMerged) |
| 167 | .setFlags(mParams.getFlags()) |
| 168 | .setNeedsToBePublic(needsToBeShared) |
| 169 | .build(); |
Jiakai Zhang | c3db1c7 | 2022-10-18 10:59:13 +0100 | [diff] [blame] | 170 | |
| 171 | GetDexoptNeededResult getDexoptNeededResult = |
| 172 | getDexoptNeeded(target, options); |
| 173 | |
| 174 | if (!getDexoptNeededResult.isDexoptNeeded) { |
| 175 | continue; |
| 176 | } |
| 177 | |
Jiakai Zhang | de3844b | 2022-11-30 11:28:11 +0000 | [diff] [blame] | 178 | try { |
| 179 | // `StorageManager.getAllocatableBytes` returns (free space + space used |
| 180 | // by clearable cache - low storage threshold). Since we only compare |
| 181 | // the result with 0, the clearable cache doesn't make a difference. |
| 182 | // When the free space is below the threshold, there should be no |
| 183 | // clearable cache left because system cleans up cache every minute. |
| 184 | if ((mParams.getFlags() & ArtFlags.FLAG_SKIP_IF_STORAGE_LOW) != 0 |
| 185 | && mInjector.getStorageManager().getAllocatableBytes( |
| 186 | mPkg.getStorageUuid()) |
| 187 | <= 0) { |
| 188 | isSkippedDueToStorageLow = true; |
| 189 | continue; |
| 190 | } |
| 191 | } catch (IOException e) { |
| 192 | Log.e(TAG, "Failed to check storage. Assuming storage not low", e); |
| 193 | } |
| 194 | |
Jiakai Zhang | c3db1c7 | 2022-10-18 10:59:13 +0100 | [diff] [blame] | 195 | IArtdCancellationSignal artdCancellationSignal = |
| 196 | mInjector.getArtd().createCancellationSignal(); |
| 197 | mCancellationSignal.setOnCancelListener(() -> { |
| 198 | try { |
| 199 | artdCancellationSignal.cancel(); |
| 200 | } catch (RemoteException e) { |
| 201 | Log.e(TAG, "An error occurred when sending a cancellation signal", |
| 202 | e); |
| 203 | } |
| 204 | }); |
| 205 | |
Jiakai Zhang | 771f64e | 2023-01-12 17:32:36 +0800 | [diff] [blame] | 206 | ArtdDexoptResult dexoptResult = dexoptFile(target, profile, |
Jiakai Zhang | c3db1c7 | 2022-10-18 10:59:13 +0100 | [diff] [blame] | 207 | getDexoptNeededResult, permissionSettings, |
| 208 | mParams.getPriorityClass(), dexoptOptions, artdCancellationSignal); |
Jiakai Zhang | 771f64e | 2023-01-12 17:32:36 +0800 | [diff] [blame] | 209 | status = dexoptResult.cancelled ? DexoptResult.DEXOPT_CANCELLED |
| 210 | : DexoptResult.DEXOPT_PERFORMED; |
Jiakai Zhang | c3db1c7 | 2022-10-18 10:59:13 +0100 | [diff] [blame] | 211 | wallTimeMs = dexoptResult.wallTimeMs; |
| 212 | cpuTimeMs = dexoptResult.cpuTimeMs; |
Jiakai Zhang | 843ce52 | 2022-11-11 14:00:39 +0000 | [diff] [blame] | 213 | sizeBytes = dexoptResult.sizeBytes; |
| 214 | sizeBeforeBytes = dexoptResult.sizeBeforeBytes; |
Jiakai Zhang | c3db1c7 | 2022-10-18 10:59:13 +0100 | [diff] [blame] | 215 | |
Jiakai Zhang | 771f64e | 2023-01-12 17:32:36 +0800 | [diff] [blame] | 216 | if (status == DexoptResult.DEXOPT_CANCELLED) { |
Jiakai Zhang | c3db1c7 | 2022-10-18 10:59:13 +0100 | [diff] [blame] | 217 | return results; |
| 218 | } |
| 219 | } catch (ServiceSpecificException e) { |
| 220 | // Log the error and continue. |
| 221 | Log.e(TAG, |
| 222 | String.format("Failed to dexopt [packageName = %s, dexPath = %s, " |
| 223 | + "isa = %s, classLoaderContext = %s]", |
| 224 | mPkgState.getPackageName(), dexInfo.dexPath(), abi.isa(), |
| 225 | dexInfo.classLoaderContext()), |
| 226 | e); |
Jiakai Zhang | 771f64e | 2023-01-12 17:32:36 +0800 | [diff] [blame] | 227 | status = DexoptResult.DEXOPT_FAILED; |
Jiakai Zhang | c3db1c7 | 2022-10-18 10:59:13 +0100 | [diff] [blame] | 228 | } finally { |
Jiakai Zhang | 771f64e | 2023-01-12 17:32:36 +0800 | [diff] [blame] | 229 | results.add(DexContainerFileDexoptResult.create(dexInfo.dexPath(), |
Jiakai Zhang | c3db1c7 | 2022-10-18 10:59:13 +0100 | [diff] [blame] | 230 | abi.isPrimaryAbi(), abi.name(), compilerFilter, status, wallTimeMs, |
Jiakai Zhang | de3844b | 2022-11-30 11:28:11 +0000 | [diff] [blame] | 231 | cpuTimeMs, sizeBytes, sizeBeforeBytes, isSkippedDueToStorageLow)); |
Jiakai Zhang | 771f64e | 2023-01-12 17:32:36 +0800 | [diff] [blame] | 232 | if (status != DexoptResult.DEXOPT_SKIPPED |
| 233 | && status != DexoptResult.DEXOPT_PERFORMED) { |
Jiakai Zhang | c3db1c7 | 2022-10-18 10:59:13 +0100 | [diff] [blame] | 234 | succeeded = false; |
| 235 | } |
| 236 | // Make sure artd does not leak even if the caller holds |
| 237 | // `mCancellationSignal` forever. |
| 238 | mCancellationSignal.setOnCancelListener(null); |
| 239 | } |
| 240 | } |
| 241 | |
| 242 | if (profile != null && succeeded) { |
| 243 | if (profile.getTag() == ProfilePath.tmpProfilePath) { |
| 244 | // Commit the profile only if dexopt succeeds. |
| 245 | if (commitProfileChanges(profile.getTmpProfilePath())) { |
| 246 | profile = null; |
| 247 | } |
| 248 | } |
| 249 | if (profileMerged) { |
| 250 | // Note that this is just an optimization, to reduce the amount of data that |
| 251 | // the runtime writes on every profile save. The profile merge result on the |
| 252 | // next run won't change regardless of whether the cleanup is done or not |
| 253 | // because profman only looks at the diff. |
| 254 | // A caveat is that it may delete more than what has been merged, if the |
| 255 | // runtime writes additional entries between the merge and the cleanup, but |
| 256 | // this is fine because the runtime writes all JITed classes and methods on |
| 257 | // every save and the additional entries will likely be written back on the |
| 258 | // next save. |
| 259 | cleanupCurProfiles(dexInfo); |
| 260 | } |
| 261 | } |
| 262 | } finally { |
| 263 | if (profile != null && profile.getTag() == ProfilePath.tmpProfilePath) { |
| 264 | mInjector.getArtd().deleteProfile(profile); |
| 265 | } |
| 266 | } |
| 267 | } |
| 268 | |
| 269 | return results; |
| 270 | } |
| 271 | |
| 272 | @NonNull |
Jiakai Zhang | 12f45c4 | 2022-10-27 15:23:03 +0100 | [diff] [blame] | 273 | private String adjustCompilerFilter( |
| 274 | @NonNull String targetCompilerFilter, @NonNull DexInfoType dexInfo) { |
Jiakai Zhang | c3db1c7 | 2022-10-18 10:59:13 +0100 | [diff] [blame] | 275 | if (mInjector.isSystemUiPackage(mPkgState.getPackageName())) { |
| 276 | String systemUiCompilerFilter = getSystemUiCompilerFilter(); |
| 277 | if (!systemUiCompilerFilter.isEmpty()) { |
| 278 | return systemUiCompilerFilter; |
| 279 | } |
| 280 | } |
| 281 | |
| 282 | // We force vmSafeMode on debuggable apps as well: |
| 283 | // - the runtime ignores their compiled code |
| 284 | // - they generally have lots of methods that could make the compiler used run out of |
| 285 | // memory (b/130828957) |
| 286 | // Note that forcing the compiler filter here applies to all compilations (even if they |
| 287 | // are done via adb shell commands). This is okay because the runtime will ignore the |
| 288 | // compiled code anyway. |
| 289 | if (mPkg.isVmSafeMode() || mPkg.isDebuggable()) { |
| 290 | return DexFile.getSafeModeCompilerFilter(targetCompilerFilter); |
| 291 | } |
| 292 | |
Jiakai Zhang | 12f45c4 | 2022-10-27 15:23:03 +0100 | [diff] [blame] | 293 | // We cannot do AOT compilation if we don't have a valid class loader context. |
Jiakai Zhang | 4851c47 | 2022-11-14 16:32:03 +0000 | [diff] [blame] | 294 | if (dexInfo.classLoaderContext() == null) { |
| 295 | return DexFile.isOptimizedCompilerFilter(targetCompilerFilter) ? "verify" |
| 296 | : targetCompilerFilter; |
| 297 | } |
| 298 | |
| 299 | // This application wants to use the embedded dex in the APK, rather than extracted or |
| 300 | // locally compiled variants, so we only verify it. |
| 301 | // "verify" does not prevent dex2oat from extracting the dex code, but in practice, dex2oat |
| 302 | // won't extract the dex code because the APK is uncompressed, and the assumption is that |
| 303 | // such applications always use uncompressed APKs. |
| 304 | if (mPkg.isUseEmbeddedDex()) { |
| 305 | return DexFile.isOptimizedCompilerFilter(targetCompilerFilter) ? "verify" |
| 306 | : targetCompilerFilter; |
Jiakai Zhang | 12f45c4 | 2022-10-27 15:23:03 +0100 | [diff] [blame] | 307 | } |
| 308 | |
Jiakai Zhang | c3db1c7 | 2022-10-18 10:59:13 +0100 | [diff] [blame] | 309 | return targetCompilerFilter; |
| 310 | } |
| 311 | |
| 312 | @NonNull |
| 313 | private String getSystemUiCompilerFilter() { |
| 314 | String compilerFilter = SystemProperties.get("dalvik.vm.systemuicompilerfilter"); |
| 315 | if (!compilerFilter.isEmpty() && !Utils.isValidArtServiceCompilerFilter(compilerFilter)) { |
| 316 | throw new IllegalStateException( |
| 317 | "Got invalid compiler filter '" + compilerFilter + "' for System UI"); |
| 318 | } |
| 319 | return compilerFilter; |
| 320 | } |
| 321 | |
| 322 | /** |
| 323 | * Gets the existing reference profile if exists, or initializes a reference profile from an |
| 324 | * external profile. |
| 325 | * |
| 326 | * @return A pair where the first element is the found or initialized profile, and the second |
| 327 | * element is true if the profile is readable by others. Or null if there is no |
| 328 | * reference profile or external profile to use. |
| 329 | */ |
| 330 | @Nullable |
| 331 | private Pair<ProfilePath, Boolean> getOrInitReferenceProfile(@NonNull DexInfoType dexInfo) |
| 332 | throws RemoteException { |
| 333 | ProfilePath refProfile = buildRefProfilePath(dexInfo); |
| 334 | try { |
| 335 | if (mInjector.getArtd().isProfileUsable(refProfile, dexInfo.dexPath())) { |
| 336 | boolean isOtherReadable = mInjector.getArtd().getProfileVisibility(refProfile) |
| 337 | == FileVisibility.OTHER_READABLE; |
| 338 | return Pair.create(refProfile, isOtherReadable); |
| 339 | } |
| 340 | } catch (ServiceSpecificException e) { |
| 341 | Log.e(TAG, |
| 342 | "Failed to use the existing reference profile " |
| 343 | + AidlUtils.toString(refProfile), |
| 344 | e); |
| 345 | } |
| 346 | |
| 347 | ProfilePath initializedProfile = initReferenceProfile(dexInfo); |
| 348 | return initializedProfile != null ? Pair.create(initializedProfile, true) : null; |
| 349 | } |
| 350 | |
| 351 | @NonNull |
Jiakai Zhang | 2698a49 | 2022-11-14 14:36:01 +0000 | [diff] [blame] | 352 | private DexoptOptions getDexoptOptions( |
| 353 | @NonNull DexInfoType dexInfo, boolean isProfileGuidedFilter) { |
Jiakai Zhang | c3db1c7 | 2022-10-18 10:59:13 +0100 | [diff] [blame] | 354 | DexoptOptions dexoptOptions = new DexoptOptions(); |
| 355 | dexoptOptions.compilationReason = mParams.getReason(); |
| 356 | dexoptOptions.targetSdkVersion = mPkg.getTargetSdkVersion(); |
| 357 | dexoptOptions.debuggable = mPkg.isDebuggable() || isAlwaysDebuggable(); |
| 358 | // Generating a meaningful app image needs a profile to determine what to include in the |
| 359 | // image. Otherwise, the app image will be nearly empty. |
| 360 | dexoptOptions.generateAppImage = |
Jiakai Zhang | 2698a49 | 2022-11-14 14:36:01 +0000 | [diff] [blame] | 361 | isProfileGuidedFilter && isAppImageAllowed(dexInfo) && isAppImageEnabled(); |
Jiakai Zhang | c3db1c7 | 2022-10-18 10:59:13 +0100 | [diff] [blame] | 362 | dexoptOptions.hiddenApiPolicyEnabled = isHiddenApiPolicyEnabled(); |
| 363 | return dexoptOptions; |
| 364 | } |
| 365 | |
| 366 | private boolean isAlwaysDebuggable() { |
| 367 | return SystemProperties.getBoolean("dalvik.vm.always_debuggable", false /* def */); |
| 368 | } |
| 369 | |
| 370 | private boolean isAppImageEnabled() { |
| 371 | return !SystemProperties.get("dalvik.vm.appimageformat").isEmpty(); |
| 372 | } |
| 373 | |
| 374 | private boolean isHiddenApiPolicyEnabled() { |
Jiakai Zhang | 914197f | 2022-12-21 10:22:14 +0000 | [diff] [blame] | 375 | return mPkgState.getHiddenApiEnforcementPolicy() |
| 376 | != ApplicationInfo.HIDDEN_API_ENFORCEMENT_DISABLED; |
Jiakai Zhang | c3db1c7 | 2022-10-18 10:59:13 +0100 | [diff] [blame] | 377 | } |
| 378 | |
| 379 | @NonNull |
Jiakai Zhang | bfd155d | 2022-11-08 13:17:50 +0000 | [diff] [blame] | 380 | GetDexoptNeededResult getDexoptNeeded(@NonNull DexoptTarget<DexInfoType> target, |
Jiakai Zhang | c3db1c7 | 2022-10-18 10:59:13 +0100 | [diff] [blame] | 381 | @NonNull GetDexoptNeededOptions options) throws RemoteException { |
| 382 | int dexoptTrigger = getDexoptTrigger(target, options); |
| 383 | |
| 384 | // The result should come from artd even if all the bits of `dexoptTrigger` are set |
| 385 | // because the result also contains information about the usable VDEX file. |
Jiakai Zhang | 12f45c4 | 2022-10-27 15:23:03 +0100 | [diff] [blame] | 386 | // Note that the class loader context can be null. In that case, we intentionally pass the |
| 387 | // null value down to lower levels to indicate that the class loader context check should be |
| 388 | // skipped because we are only going to verify the dex code (see `adjustCompilerFilter`). |
Jiakai Zhang | c3db1c7 | 2022-10-18 10:59:13 +0100 | [diff] [blame] | 389 | GetDexoptNeededResult result = mInjector.getArtd().getDexoptNeeded( |
| 390 | target.dexInfo().dexPath(), target.isa(), target.dexInfo().classLoaderContext(), |
| 391 | target.compilerFilter(), dexoptTrigger); |
| 392 | |
| 393 | return result; |
| 394 | } |
| 395 | |
Jiakai Zhang | bfd155d | 2022-11-08 13:17:50 +0000 | [diff] [blame] | 396 | int getDexoptTrigger(@NonNull DexoptTarget<DexInfoType> target, |
| 397 | @NonNull GetDexoptNeededOptions options) throws RemoteException { |
Jiakai Zhang | c3db1c7 | 2022-10-18 10:59:13 +0100 | [diff] [blame] | 398 | if ((options.flags() & ArtFlags.FLAG_FORCE) != 0) { |
| 399 | return DexoptTrigger.COMPILER_FILTER_IS_BETTER | DexoptTrigger.COMPILER_FILTER_IS_SAME |
| 400 | | DexoptTrigger.COMPILER_FILTER_IS_WORSE |
| 401 | | DexoptTrigger.PRIMARY_BOOT_IMAGE_BECOMES_USABLE; |
| 402 | } |
| 403 | |
| 404 | if ((options.flags() & ArtFlags.FLAG_SHOULD_DOWNGRADE) != 0) { |
| 405 | return DexoptTrigger.COMPILER_FILTER_IS_WORSE; |
| 406 | } |
| 407 | |
| 408 | int dexoptTrigger = DexoptTrigger.COMPILER_FILTER_IS_BETTER |
| 409 | | DexoptTrigger.PRIMARY_BOOT_IMAGE_BECOMES_USABLE; |
| 410 | if (options.profileMerged()) { |
| 411 | dexoptTrigger |= DexoptTrigger.COMPILER_FILTER_IS_SAME; |
| 412 | } |
| 413 | |
| 414 | ArtifactsPath existingArtifactsPath = AidlUtils.buildArtifactsPath( |
| 415 | target.dexInfo().dexPath(), target.isa(), target.isInDalvikCache()); |
| 416 | |
| 417 | if (options.needsToBePublic() |
| 418 | && mInjector.getArtd().getArtifactsVisibility(existingArtifactsPath) |
| 419 | == FileVisibility.NOT_OTHER_READABLE) { |
| 420 | // Typically, this happens after an app starts being used by other apps. |
| 421 | // This case should be the same as force as we have no choice but to trigger a new |
| 422 | // dexopt. |
| 423 | dexoptTrigger |= |
| 424 | DexoptTrigger.COMPILER_FILTER_IS_SAME | DexoptTrigger.COMPILER_FILTER_IS_WORSE; |
| 425 | } |
| 426 | |
| 427 | return dexoptTrigger; |
| 428 | } |
| 429 | |
Jiakai Zhang | 771f64e | 2023-01-12 17:32:36 +0800 | [diff] [blame] | 430 | private ArtdDexoptResult dexoptFile(@NonNull DexoptTarget<DexInfoType> target, |
Jiakai Zhang | bfd155d | 2022-11-08 13:17:50 +0000 | [diff] [blame] | 431 | @Nullable ProfilePath profile, @NonNull GetDexoptNeededResult getDexoptNeededResult, |
Jiakai Zhang | c3db1c7 | 2022-10-18 10:59:13 +0100 | [diff] [blame] | 432 | @NonNull PermissionSettings permissionSettings, @PriorityClass int priorityClass, |
| 433 | @NonNull DexoptOptions dexoptOptions, IArtdCancellationSignal artdCancellationSignal) |
| 434 | throws RemoteException { |
| 435 | OutputArtifacts outputArtifacts = AidlUtils.buildOutputArtifacts(target.dexInfo().dexPath(), |
| 436 | target.isa(), target.isInDalvikCache(), permissionSettings); |
| 437 | |
| 438 | VdexPath inputVdex = |
| 439 | getInputVdex(getDexoptNeededResult, target.dexInfo().dexPath(), target.isa()); |
| 440 | |
Jiakai Zhang | bfd155d | 2022-11-08 13:17:50 +0000 | [diff] [blame] | 441 | DexMetadataPath dmFile = getDmFile(target.dexInfo()); |
| 442 | if (dmFile != null |
| 443 | && ReasonMapping.REASONS_FOR_INSTALL.contains(dexoptOptions.compilationReason)) { |
| 444 | // If the DM file is passed to dex2oat, then add the "-dm" suffix to the reason (e.g., |
| 445 | // "install-dm"). |
| 446 | // Note that this only applies to reasons for app install because the goal is to give |
| 447 | // Play a signal that a DM file is downloaded at install time. We actually pass the DM |
| 448 | // file regardless of the compilation reason, but we don't append a suffix when the |
| 449 | // compilation reason is not a reason for app install. |
| 450 | // Also note that the "-dm" suffix does NOT imply anything in the DM file being used by |
| 451 | // dex2oat. dex2oat may ignore some contents of the DM file when appropriate. The |
| 452 | // compilation reason can still be "install-dm" even if dex2oat left all contents of the |
| 453 | // DM file unused or an empty DM file is passed to dex2oat. |
| 454 | dexoptOptions.compilationReason = dexoptOptions.compilationReason + "-dm"; |
| 455 | } |
| 456 | |
Jiakai Zhang | c3db1c7 | 2022-10-18 10:59:13 +0100 | [diff] [blame] | 457 | return mInjector.getArtd().dexopt(outputArtifacts, target.dexInfo().dexPath(), target.isa(), |
| 458 | target.dexInfo().classLoaderContext(), target.compilerFilter(), profile, inputVdex, |
Jiakai Zhang | bfd155d | 2022-11-08 13:17:50 +0000 | [diff] [blame] | 459 | dmFile, priorityClass, dexoptOptions, artdCancellationSignal); |
Jiakai Zhang | c3db1c7 | 2022-10-18 10:59:13 +0100 | [diff] [blame] | 460 | } |
| 461 | |
| 462 | @Nullable |
| 463 | private VdexPath getInputVdex(@NonNull GetDexoptNeededResult getDexoptNeededResult, |
| 464 | @NonNull String dexPath, @NonNull String isa) { |
| 465 | if (!getDexoptNeededResult.isVdexUsable) { |
| 466 | return null; |
| 467 | } |
| 468 | switch (getDexoptNeededResult.artifactsLocation) { |
| 469 | case ArtifactsLocation.DALVIK_CACHE: |
| 470 | return VdexPath.artifactsPath( |
| 471 | AidlUtils.buildArtifactsPath(dexPath, isa, true /* isInDalvikCache */)); |
| 472 | case ArtifactsLocation.NEXT_TO_DEX: |
| 473 | return VdexPath.artifactsPath( |
| 474 | AidlUtils.buildArtifactsPath(dexPath, isa, false /* isInDalvikCache */)); |
| 475 | case ArtifactsLocation.DM: |
Jiakai Zhang | bfd155d | 2022-11-08 13:17:50 +0000 | [diff] [blame] | 476 | // The DM file is passed to dex2oat as a separate flag whenever it exists. |
| 477 | return null; |
Jiakai Zhang | c3db1c7 | 2022-10-18 10:59:13 +0100 | [diff] [blame] | 478 | default: |
| 479 | // This should never happen as the value is got from artd. |
| 480 | throw new IllegalStateException( |
| 481 | "Unknown artifacts location " + getDexoptNeededResult.artifactsLocation); |
| 482 | } |
| 483 | } |
| 484 | |
Jiakai Zhang | bfd155d | 2022-11-08 13:17:50 +0000 | [diff] [blame] | 485 | @Nullable |
| 486 | private DexMetadataPath getDmFile(@NonNull DexInfoType dexInfo) throws RemoteException { |
| 487 | DexMetadataPath path = buildDmPath(dexInfo); |
| 488 | if (path == null) { |
| 489 | return null; |
| 490 | } |
| 491 | try { |
| 492 | if (mInjector.getArtd().getDmFileVisibility(path) != FileVisibility.NOT_FOUND) { |
| 493 | return path; |
| 494 | } |
| 495 | } catch (ServiceSpecificException e) { |
| 496 | Log.e(TAG, "Failed to check DM file for " + dexInfo.dexPath(), e); |
| 497 | } |
| 498 | return null; |
| 499 | } |
| 500 | |
Jiakai Zhang | c3db1c7 | 2022-10-18 10:59:13 +0100 | [diff] [blame] | 501 | private boolean commitProfileChanges(@NonNull TmpProfilePath profile) throws RemoteException { |
| 502 | try { |
| 503 | mInjector.getArtd().commitTmpProfile(profile); |
| 504 | return true; |
| 505 | } catch (ServiceSpecificException e) { |
| 506 | Log.e(TAG, "Failed to commit profile changes " + AidlUtils.toString(profile.finalPath), |
| 507 | e); |
| 508 | return false; |
| 509 | } |
| 510 | } |
| 511 | |
| 512 | @Nullable |
| 513 | private ProfilePath mergeProfiles(@NonNull DexInfoType dexInfo, |
| 514 | @Nullable ProfilePath referenceProfile) throws RemoteException { |
| 515 | OutputProfile output = buildOutputProfile(dexInfo, false /* isPublic */); |
| 516 | |
| 517 | try { |
Jiakai Zhang | b1d3db6 | 2022-11-11 14:00:44 +0000 | [diff] [blame] | 518 | if (mInjector.getArtd().mergeProfiles(getCurProfiles(dexInfo), referenceProfile, output, |
| 519 | List.of(dexInfo.dexPath()), new MergeProfileOptions())) { |
Jiakai Zhang | c3db1c7 | 2022-10-18 10:59:13 +0100 | [diff] [blame] | 520 | return ProfilePath.tmpProfilePath(output.profilePath); |
| 521 | } |
| 522 | } catch (ServiceSpecificException e) { |
| 523 | Log.e(TAG, |
| 524 | "Failed to merge profiles " + AidlUtils.toString(output.profilePath.finalPath), |
| 525 | e); |
| 526 | } |
| 527 | |
| 528 | return null; |
| 529 | } |
| 530 | |
| 531 | private void cleanupCurProfiles(@NonNull DexInfoType dexInfo) throws RemoteException { |
| 532 | for (ProfilePath profile : getCurProfiles(dexInfo)) { |
| 533 | mInjector.getArtd().deleteProfile(profile); |
| 534 | } |
| 535 | } |
| 536 | |
| 537 | // Methods to be implemented by child classes. |
| 538 | |
| 539 | /** Returns true if the artifacts should be written to the global dalvik-cache directory. */ |
| 540 | protected abstract boolean isInDalvikCache(); |
| 541 | |
| 542 | /** Returns information about all dex files. */ |
| 543 | @NonNull protected abstract List<DexInfoType> getDexInfoList(); |
| 544 | |
Jiakai Zhang | 771f64e | 2023-01-12 17:32:36 +0800 | [diff] [blame] | 545 | /** Returns true if the given dex file should be dexopted. */ |
| 546 | protected abstract boolean isDexoptable(@NonNull DexInfoType dexInfo); |
Jiakai Zhang | c3db1c7 | 2022-10-18 10:59:13 +0100 | [diff] [blame] | 547 | |
Jiakai Zhang | 12f45c4 | 2022-10-27 15:23:03 +0100 | [diff] [blame] | 548 | /** |
| 549 | * Returns true if the artifacts should be shared with other apps. Note that this must imply |
| 550 | * {@link #isDexFilePublic(DexInfoType)}. |
| 551 | */ |
Jiakai Zhang | c3db1c7 | 2022-10-18 10:59:13 +0100 | [diff] [blame] | 552 | protected abstract boolean needsToBeShared(@NonNull DexInfoType dexInfo); |
| 553 | |
| 554 | /** |
Jiakai Zhang | 12f45c4 | 2022-10-27 15:23:03 +0100 | [diff] [blame] | 555 | * Returns true if the filesystem permission of the dex file has the "read" bit for "others" |
| 556 | * (S_IROTH). |
| 557 | */ |
| 558 | protected abstract boolean isDexFilePublic(@NonNull DexInfoType dexInfo); |
| 559 | |
| 560 | /** |
Jiakai Zhang | c3db1c7 | 2022-10-18 10:59:13 +0100 | [diff] [blame] | 561 | * Returns a reference profile initialized from an external profile (e.g., a DM profile) if |
| 562 | * one exists, or null otherwise. |
| 563 | */ |
| 564 | @Nullable |
| 565 | protected abstract ProfilePath initReferenceProfile(@NonNull DexInfoType dexInfo) |
| 566 | throws RemoteException; |
| 567 | |
| 568 | /** Returns the permission settings to use for the artifacts of the given dex file. */ |
| 569 | @NonNull |
| 570 | protected abstract PermissionSettings getPermissionSettings( |
| 571 | @NonNull DexInfoType dexInfo, boolean canBePublic); |
| 572 | |
| 573 | /** Returns all ABIs that the given dex file should be compiled for. */ |
| 574 | @NonNull protected abstract List<Abi> getAllAbis(@NonNull DexInfoType dexInfo); |
| 575 | |
| 576 | /** Returns the path to the reference profile of the given dex file. */ |
| 577 | @NonNull protected abstract ProfilePath buildRefProfilePath(@NonNull DexInfoType dexInfo); |
| 578 | |
| 579 | /** Returns true if app image (--app-image-fd) is allowed. */ |
Jiakai Zhang | 2698a49 | 2022-11-14 14:36:01 +0000 | [diff] [blame] | 580 | protected abstract boolean isAppImageAllowed(@NonNull DexInfoType dexInfo); |
Jiakai Zhang | c3db1c7 | 2022-10-18 10:59:13 +0100 | [diff] [blame] | 581 | |
| 582 | /** |
| 583 | * Returns the data structure that represents the temporary profile to use during processing. |
| 584 | */ |
| 585 | @NonNull |
| 586 | protected abstract OutputProfile buildOutputProfile( |
| 587 | @NonNull DexInfoType dexInfo, boolean isPublic); |
| 588 | |
| 589 | /** Returns the paths to the current profiles of the given dex file. */ |
| 590 | @NonNull protected abstract List<ProfilePath> getCurProfiles(@NonNull DexInfoType dexInfo); |
| 591 | |
Jiakai Zhang | bfd155d | 2022-11-08 13:17:50 +0000 | [diff] [blame] | 592 | /** |
| 593 | * Returns the path to the DM file that should be passed to dex2oat, or null if no DM file |
| 594 | * should be passed. |
| 595 | */ |
| 596 | @Nullable protected abstract DexMetadataPath buildDmPath(@NonNull DexInfoType dexInfo); |
| 597 | |
Jiakai Zhang | c3db1c7 | 2022-10-18 10:59:13 +0100 | [diff] [blame] | 598 | @AutoValue |
Jiakai Zhang | bfd155d | 2022-11-08 13:17:50 +0000 | [diff] [blame] | 599 | abstract static class DexoptTarget<DexInfoType extends DetailedDexInfo> { |
| 600 | abstract @NonNull DexInfoType dexInfo(); |
Jiakai Zhang | c3db1c7 | 2022-10-18 10:59:13 +0100 | [diff] [blame] | 601 | abstract @NonNull String isa(); |
| 602 | abstract boolean isInDalvikCache(); |
| 603 | abstract @NonNull String compilerFilter(); |
| 604 | |
Jiakai Zhang | bfd155d | 2022-11-08 13:17:50 +0000 | [diff] [blame] | 605 | static <DexInfoType extends DetailedDexInfo> Builder<DexInfoType> builder() { |
Jiakai Zhang | 2777d7a | 2023-01-13 15:37:13 +0800 | [diff] [blame] | 606 | return new AutoValue_Dexopter_DexoptTarget.Builder<DexInfoType>(); |
Jiakai Zhang | c3db1c7 | 2022-10-18 10:59:13 +0100 | [diff] [blame] | 607 | } |
| 608 | |
| 609 | @AutoValue.Builder |
Jiakai Zhang | bfd155d | 2022-11-08 13:17:50 +0000 | [diff] [blame] | 610 | abstract static class Builder<DexInfoType extends DetailedDexInfo> { |
| 611 | abstract Builder setDexInfo(@NonNull DexInfoType value); |
Jiakai Zhang | c3db1c7 | 2022-10-18 10:59:13 +0100 | [diff] [blame] | 612 | abstract Builder setIsa(@NonNull String value); |
| 613 | abstract Builder setIsInDalvikCache(boolean value); |
| 614 | abstract Builder setCompilerFilter(@NonNull String value); |
Jiakai Zhang | bfd155d | 2022-11-08 13:17:50 +0000 | [diff] [blame] | 615 | abstract DexoptTarget<DexInfoType> build(); |
Jiakai Zhang | c3db1c7 | 2022-10-18 10:59:13 +0100 | [diff] [blame] | 616 | } |
| 617 | } |
| 618 | |
| 619 | @AutoValue |
| 620 | abstract static class GetDexoptNeededOptions { |
Jiakai Zhang | 771f64e | 2023-01-12 17:32:36 +0800 | [diff] [blame] | 621 | abstract @DexoptFlags int flags(); |
Jiakai Zhang | c3db1c7 | 2022-10-18 10:59:13 +0100 | [diff] [blame] | 622 | abstract boolean profileMerged(); |
| 623 | abstract boolean needsToBePublic(); |
| 624 | |
| 625 | static Builder builder() { |
Jiakai Zhang | 2777d7a | 2023-01-13 15:37:13 +0800 | [diff] [blame] | 626 | return new AutoValue_Dexopter_GetDexoptNeededOptions.Builder(); |
Jiakai Zhang | c3db1c7 | 2022-10-18 10:59:13 +0100 | [diff] [blame] | 627 | } |
| 628 | |
| 629 | @AutoValue.Builder |
| 630 | abstract static class Builder { |
Jiakai Zhang | 771f64e | 2023-01-12 17:32:36 +0800 | [diff] [blame] | 631 | abstract Builder setFlags(@DexoptFlags int value); |
Jiakai Zhang | c3db1c7 | 2022-10-18 10:59:13 +0100 | [diff] [blame] | 632 | abstract Builder setProfileMerged(boolean value); |
| 633 | abstract Builder setNeedsToBePublic(boolean value); |
| 634 | abstract GetDexoptNeededOptions build(); |
| 635 | } |
| 636 | } |
| 637 | |
| 638 | /** |
| 639 | * Injector pattern for testing purpose. |
| 640 | * |
| 641 | * @hide |
| 642 | */ |
Jiakai Zhang | 12f45c4 | 2022-10-27 15:23:03 +0100 | [diff] [blame] | 643 | @VisibleForTesting(visibility = VisibleForTesting.Visibility.PROTECTED) |
Jiakai Zhang | c3db1c7 | 2022-10-18 10:59:13 +0100 | [diff] [blame] | 644 | public static class Injector { |
| 645 | @NonNull private final Context mContext; |
| 646 | |
Jiakai Zhang | 12f45c4 | 2022-10-27 15:23:03 +0100 | [diff] [blame] | 647 | public Injector(@NonNull Context context) { |
Jiakai Zhang | c3db1c7 | 2022-10-18 10:59:13 +0100 | [diff] [blame] | 648 | mContext = context; |
Jiakai Zhang | 20a8542 | 2022-12-21 13:58:00 +0000 | [diff] [blame] | 649 | |
| 650 | // Call the getters for various dependencies, to ensure correct initialization order. |
| 651 | getUserManager(); |
| 652 | getDexUseManager(); |
| 653 | getStorageManager(); |
| 654 | ArtModuleServiceInitializer.getArtModuleServiceManager(); |
Jiakai Zhang | c3db1c7 | 2022-10-18 10:59:13 +0100 | [diff] [blame] | 655 | } |
| 656 | |
Jiakai Zhang | 12f45c4 | 2022-10-27 15:23:03 +0100 | [diff] [blame] | 657 | public boolean isSystemUiPackage(@NonNull String packageName) { |
Jiakai Zhang | c3db1c7 | 2022-10-18 10:59:13 +0100 | [diff] [blame] | 658 | return packageName.equals(mContext.getString(R.string.config_systemUi)); |
| 659 | } |
| 660 | |
| 661 | @NonNull |
Jiakai Zhang | 12f45c4 | 2022-10-27 15:23:03 +0100 | [diff] [blame] | 662 | public UserManager getUserManager() { |
Jiakai Zhang | c3db1c7 | 2022-10-18 10:59:13 +0100 | [diff] [blame] | 663 | return Objects.requireNonNull(mContext.getSystemService(UserManager.class)); |
| 664 | } |
| 665 | |
| 666 | @NonNull |
Jiakai Zhang | 91fe951 | 2022-11-14 19:42:32 +0000 | [diff] [blame] | 667 | public DexUseManagerLocal getDexUseManager() { |
| 668 | return Objects.requireNonNull( |
| 669 | LocalManagerRegistry.getManager(DexUseManagerLocal.class)); |
Jiakai Zhang | c3db1c7 | 2022-10-18 10:59:13 +0100 | [diff] [blame] | 670 | } |
| 671 | |
| 672 | @NonNull |
Jiakai Zhang | 12f45c4 | 2022-10-27 15:23:03 +0100 | [diff] [blame] | 673 | public IArtd getArtd() { |
Jiakai Zhang | c3db1c7 | 2022-10-18 10:59:13 +0100 | [diff] [blame] | 674 | return Utils.getArtd(); |
| 675 | } |
Jiakai Zhang | de3844b | 2022-11-30 11:28:11 +0000 | [diff] [blame] | 676 | |
| 677 | @NonNull |
| 678 | public StorageManager getStorageManager() { |
| 679 | return Objects.requireNonNull(mContext.getSystemService(StorageManager.class)); |
| 680 | } |
Jiakai Zhang | c3db1c7 | 2022-10-18 10:59:13 +0100 | [diff] [blame] | 681 | } |
| 682 | } |