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