1 /* 2 * Copyright (C) 2009 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 vogar; 18 19 import java.util.ArrayList; 20 import java.util.Arrays; 21 import java.util.List; 22 23 public enum ModeId { 24 /** ART (works >= L) */ 25 DEVICE, 26 /** ART (works >= L) */ 27 HOST, 28 /** Local Java */ 29 JVM, 30 /** Device, execution as an Android app with Zygote */ 31 ACTIVITY, 32 /** Device using app_process binary */ 33 APP_PROCESS; 34 35 // $BOOTCLASSPATH defined by system/core/rootdir/init.rc 36 // - DEVICE_JARS are appended automatically. 37 // (Intended for use with app_process and activities.) 38 // See PRODUCT_BOOT_JARS in build/make/target/product/core_tiny.mk 39 private static final String[] APP_JARS = new String[] { 40 "legacy-test", 41 "bouncycastle", 42 "framework", 43 "telephony-common", 44 "voip-common", 45 "ims-common", 46 "apache-xml", 47 "nullwebview", 48 "org.apache.http.legacy.boot", 49 "android.hidl.base-V1.0-java", 50 "android.hidl.manager-V1.0-java" 51 // TODO: get this list programatically 52 }; 53 54 // $BOOTCLASSPATH for art+libcore only. 55 // (Intended for use with dalvikvm only.) 56 // See TARGET_CORE_JARS in art/build/Android.common_path.mk 57 private static final String[] DEVICE_JARS = new String[] { 58 "core-libart", 59 "core-oj", 60 "conscrypt", 61 "okhttp", 62 "bouncycastle", 63 "apache-xml" 64 }; 65 66 // $BOOTCLASSPATH for art+libcore only (host version). 67 // - Must be same as DEVICE_JARS + "hostdex" suffix. 68 // (Intended for use with dalvikvm only.) 69 // See HOST_CORE_JARS in art/build/Android.common_path.mk 70 private static final String[] HOST_JARS = new String[] { 71 "core-libart-hostdex", 72 "core-oj-hostdex", 73 "conscrypt-hostdex", 74 "okhttp-hostdex", 75 "bouncycastle-hostdex", 76 "apache-xml-hostdex" 77 }; 78 acceptsVmArgs()79 public boolean acceptsVmArgs() { 80 return this != ACTIVITY; 81 } 82 83 /** 84 * Returns {@code true} if execution happens on the local machine. e.g. host-mode android or a 85 * JVM. 86 */ isLocal()87 public boolean isLocal() { 88 return isHost() || this == ModeId.JVM; 89 } 90 91 /** Returns {@code true} if execution takes place with a host-mode Android runtime */ isHost()92 public boolean isHost() { 93 return this == HOST; 94 } 95 96 /** Returns {@code true} if execution takes place with a device-mode Android runtime */ isDevice()97 public boolean isDevice() { 98 return this == ModeId.DEVICE || this == ModeId.APP_PROCESS; 99 } 100 requiresAndroidSdk()101 public boolean requiresAndroidSdk() { 102 return this != JVM; 103 } 104 supportsVariant(Variant variant)105 public boolean supportsVariant(Variant variant) { 106 return (variant == Variant.X32) 107 || ((this == HOST || this == DEVICE) && (variant == Variant.X64)); 108 } 109 110 /** The default command to use for the mode unless overridden by --vm-command */ defaultVmCommand(Variant variant)111 public String defaultVmCommand(Variant variant) { 112 if (!supportsVariant(variant)) { 113 throw new AssertionError("Unsupported variant: " + variant + " for " + this); 114 } 115 switch (this) { 116 case DEVICE: 117 case HOST: 118 if (variant == Variant.X32) { 119 return "dalvikvm32"; 120 } else { 121 return "dalvikvm64"; 122 } 123 124 case JVM: 125 return "java"; 126 case APP_PROCESS: 127 return "app_process"; 128 case ACTIVITY: 129 return null; 130 default: 131 throw new IllegalArgumentException("Unknown mode: " + this); 132 } 133 } 134 135 /** 136 * Return the names of jars required to compile in this mode when android.jar is not being used. 137 * Also used to generated the bootclasspath in HOST* and DEVICE* modes. 138 */ getJarNames()139 public String[] getJarNames() { 140 List<String> jarNames = new ArrayList<String>(); 141 switch (this) { 142 case ACTIVITY: 143 case APP_PROCESS: 144 // Order matters. Add device-jars before app-jars. 145 jarNames.addAll(Arrays.asList(DEVICE_JARS)); 146 jarNames.addAll(Arrays.asList(APP_JARS)); 147 break; 148 case DEVICE: 149 jarNames.addAll(Arrays.asList(DEVICE_JARS)); 150 break; 151 case HOST: 152 jarNames.addAll(Arrays.asList(HOST_JARS)); 153 break; 154 default: 155 throw new IllegalArgumentException("Unsupported mode: " + this); 156 } 157 return jarNames.toArray(new String[jarNames.size()]); 158 } 159 } 160