1 /* 2 * Copyright (C) 2018 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.game.qualification; 18 19 import com.android.game.qualification.GameCoreConfigurationXmlParser.Field; 20 21 import java.util.List; 22 23 public class ApkInfo { 24 public static final String APK_LIST_LOCATION = 25 "/sdcard/Android/data/com.android.game.qualification.device/apk-info.xml"; 26 27 public static class Argument { 28 public enum Type { 29 STRING, 30 BOOLEAN, 31 BYTE, 32 INT, 33 LONG, 34 FLOAT, 35 DOUBLE, 36 }; 37 38 private String mKey; 39 private String mValue; 40 private Type mType; 41 Argument(String key, String value, Type type)42 public Argument(String key, String value, Type type) { 43 mKey = key; 44 mValue = value; 45 mType = type; 46 } 47 getKey()48 public String getKey() { 49 return mKey; 50 } 51 getValue()52 public String getValue() { 53 return mValue; 54 } 55 getType()56 public Type getType() { 57 return mType; 58 } 59 } 60 61 private String mName; 62 private String mFileName; 63 private String mPackageName; 64 private String mActivityName; 65 private String mLayerName; 66 private String mScript; 67 private List<Argument> mArgs; 68 private int mLoadTime; 69 private int mRunTime; 70 private boolean mExpectIntents; 71 ApkInfo( String name, String fileName, String packageName, String activityName, String layerName, String script, List<Argument> args, int loadTime, int runTime, boolean expectIntents)72 public ApkInfo( 73 String name, 74 String fileName, 75 String packageName, 76 String activityName, 77 String layerName, 78 String script, 79 List<Argument> args, 80 int loadTime, 81 int runTime, 82 boolean expectIntents) { 83 mActivityName = activityName; 84 checkNotNull(name, Field.NAME.getTag()); 85 checkNotNull(fileName, Field.FILE_NAME.getTag()); 86 checkNotNull(packageName, Field.PACKAGE_NAME.getTag()); 87 checkNotNull(layerName, Field.LAYER_NAME.getTag()); 88 89 this.mName = name; 90 this.mFileName = fileName; 91 this.mPackageName = packageName; 92 this.mLayerName = layerName; 93 this.mScript = script; 94 this.mArgs = args; 95 this.mLoadTime = loadTime; 96 this.mRunTime = runTime; 97 this.mExpectIntents = expectIntents; 98 } 99 100 /** Name of the test */ getName()101 public String getName() { 102 return mName; 103 } 104 105 /** Filename of the APK */ getFileName()106 public String getFileName() { 107 return mFileName; 108 } 109 110 /** Package name of the app */ getPackageName()111 public String getPackageName() { 112 return mPackageName; 113 } 114 115 /** (Optional) name of the activity to launch if different from the default of the package. */ getActivityName()116 public String getActivityName() { 117 return mActivityName; 118 } 119 120 /** Name of the layer to collect metrics from */ getLayerName()121 public String getLayerName() { 122 return mLayerName; 123 } 124 125 /** (Optional) Shell command to be executed before the installation of the APK */ getScript()126 public String getScript() { 127 return mScript; 128 } 129 130 /** (Optional) Arguments supplied to the Intent used to start the app */ getArgs()131 public List<Argument> getArgs() { 132 return mArgs; 133 } 134 135 /** 136 * (Optional) Duration (in milliseconds) the app will be run for before it is terminated, prior 137 * to producing a START_LOOP intent. [default: 10000] 138 */ getLoadTime()139 public int getLoadTime() { 140 return mLoadTime; 141 } 142 143 /** 144 * (Optional) Duration (in milliseconds) the app will be run for after the first START_LOOP 145 * intent is received. [default: 10000] 146 */ getRunTime()147 public int getRunTime() { 148 return mRunTime; 149 } 150 151 /** 152 * Whether the app integrates properly with the harness via intents. 153 * 154 * If true, then we require that the app send its first START_LOOP intent within getLoadTime(), 155 * and run it for an additional getRunTime() milliseconds after the first intent is received. 156 * 157 * Otherwise, we will run the app for getLoadTime() + getRunTime(), and produce a synthetic 158 * "finished loading" marker after getLoadTime() milliseconds. 159 */ getExpectIntents()160 public boolean getExpectIntents() { 161 return mExpectIntents; 162 } 163 checkNotNull(Object value, String fieldName)164 private void checkNotNull(Object value, String fieldName) { 165 if (value == null) { 166 throw new IllegalArgumentException( 167 "Failed to parse apk info. Required field '" + fieldName + "' is missing."); 168 } 169 } 170 } 171