DexoptOptions.java revision 1d0e83d2cee794ba576d573119e826905a4422cd
1/* 2 * Copyright (C) 2017 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 17package com.android.server.pm.dex; 18 19import static com.android.server.pm.PackageManagerServiceCompilerMapping.getCompilerFilterForReason; 20 21/** 22 * Options used for dexopt invocations. 23 */ 24public final class DexoptOptions { 25 // When set, the profiles will be checked for updates before calling dexopt. If 26 // the apps profiles didn't update in a meaningful way (decided by the compiler), dexopt 27 // will be skipped. 28 // Currently this only affects the optimization of primary apks. Secondary dex files 29 // will always check the profiles for updates. 30 public static final int DEXOPT_CHECK_FOR_PROFILES_UPDATES = 1 << 0; 31 32 // When set, dexopt will execute unconditionally (even if not needed). 33 public static final int DEXOPT_FORCE = 1 << 1; 34 35 // Whether or not the invocation of dexopt is done after the boot is completed. This is used 36 // in order to adjust the priority of the compilation thread. 37 public static final int DEXOPT_BOOT_COMPLETE = 1 << 2; 38 39 // When set, the dexopt invocation will optimize only the secondary dex files. If false, dexopt 40 // will only consider the primary apk. 41 public static final int DEXOPT_ONLY_SECONDARY_DEX = 1 << 3; 42 43 // When set, dexopt will optimize only dex files that are used by other apps. 44 // Currently, this flag is ignored for primary apks. 45 public static final int DEXOPT_ONLY_SHARED_DEX = 1 << 4; 46 47 // When set, dexopt will attempt to scale down the optimizations previously applied in order 48 // save disk space. 49 public static final int DEXOPT_DOWNGRADE = 1 << 5; 50 51 // The name of package to optimize. 52 private final String mPackageName; 53 54 // The intended target compiler filter. Note that dexopt might adjust the filter before the 55 // execution based on factors like: vmSafeMode and packageUsedByOtherApps. 56 private final String mCompilerFilter; 57 58 // The set of flags for the dexopt options. It's a mix of the DEXOPT_* flags. 59 private final int mFlags; 60 61 public DexoptOptions(String packageName, String compilerFilter, int flags) { 62 int validityMask = 63 DEXOPT_CHECK_FOR_PROFILES_UPDATES | 64 DEXOPT_FORCE | 65 DEXOPT_BOOT_COMPLETE | 66 DEXOPT_ONLY_SECONDARY_DEX | 67 DEXOPT_ONLY_SHARED_DEX | 68 DEXOPT_DOWNGRADE; 69 if ((flags & (~validityMask)) != 0) { 70 throw new IllegalArgumentException("Invalid flags : " + Integer.toHexString(flags)); 71 } 72 73 mPackageName = packageName; 74 mCompilerFilter = compilerFilter; 75 mFlags = flags; 76 } 77 78 public DexoptOptions(String packageName, int compilerReason, int flags) { 79 this(packageName, getCompilerFilterForReason(compilerReason), flags); 80 } 81 82 public String getPackageName() { 83 return mPackageName; 84 } 85 86 public boolean isCheckForProfileUpdates() { 87 return (mFlags & DEXOPT_CHECK_FOR_PROFILES_UPDATES) != 0; 88 } 89 90 public String getCompilerFilter() { 91 return mCompilerFilter; 92 } 93 94 public boolean isForce() { 95 return (mFlags & DEXOPT_FORCE) != 0; 96 } 97 98 public boolean isBootComplete() { 99 return (mFlags & DEXOPT_BOOT_COMPLETE) != 0; 100 } 101 102 public boolean isDexoptOnlySecondaryDex() { 103 return (mFlags & DEXOPT_ONLY_SECONDARY_DEX) != 0; 104 } 105 106 public boolean isDexoptOnlySharedDex() { 107 return (mFlags & DEXOPT_ONLY_SHARED_DEX) != 0; 108 } 109 110 public boolean isDowngrade() { 111 return (mFlags & DEXOPT_DOWNGRADE) != 0; 112 } 113} 114