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