• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2023 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 package com.android.csuite.core;
17 
18 import com.android.tradefed.config.Option;
19 
20 import java.io.File;
21 import java.util.ArrayList;
22 import java.util.List;
23 
24 /** A class for receiving and storing option values for the AppCrawlTester class. */
25 public class AppCrawlTesterOptions {
26 
27     public static final String OBJECT_TYPE = "APP_CRAWL_TESTER_OPTIONS";
28 
29     @Option(name = "record-screen", description = "Whether to record screen during test.")
30     private boolean mRecordScreen;
31 
32     @Option(
33             name = "collect-app-version",
34             description =
35                     "Whether to collect package version information and store the information"
36                             + " in test log files.")
37     private boolean mCollectAppVersion;
38 
39     @Option(
40             name = "collect-gms-version",
41             description =
42                     "Whether to collect GMS core version information and store the information"
43                             + " in test log files.")
44     private boolean mCollectGmsVersion;
45 
46     @Option(
47             name = "repack-apk",
48             mandatory = false,
49             description =
50                     "Path to an apk file or a directory containing apk files of a single"
51                             + " package to repack and install in Espresso mode")
52     private File mRepackApk;
53 
54     @Option(
55             name = "install-apk",
56             mandatory = false,
57             description =
58                     "The path to an apk file or a directory of apk files to be installed on the"
59                             + " device. In Ui-automator mode, this includes both the target apk to"
60                             + " install and any dependencies. In Espresso mode this can include"
61                             + " additional libraries or dependencies.")
62     private List<File> mInstallApkPaths = new ArrayList<>();
63 
64     @Option(
65             name = "install-arg",
66             description =
67                     "Arguments for the 'adb install-multiple' package installation command for"
68                             + " UI-automator mode.")
69     private List<String> mInstallArgs = new ArrayList<>();
70 
71     @Option(
72             name = "crawl-controller-endpoint",
73             mandatory = false,
74             description = "The crawl controller endpoint to target.")
75     private String mCrawlControllerEndpoint;
76 
77     @Option(
78             name = "ui-automator-mode",
79             mandatory = false,
80             description =
81                     "Run the crawler with UIAutomator mode. Apk option is not required in this"
82                             + " mode. This option is by default true. Setting it to false enables"
83                             + " espresso mode which is less stable.")
84     private boolean mUiAutomatorMode = true;
85 
86     @Option(
87             name = "timeout-sec",
88             mandatory = false,
89             description = "The timeout for the crawl test.")
90     private int mTimeoutSec = 60;
91 
92     @Option(
93             name = "robo-script-file",
94             description = "A Roboscript file to be executed by the crawler.")
95     private File mRoboscriptFile;
96 
97     // TODO(b/234512223): add support for contextual roboscript files
98 
99     @Option(
100             name = "crawl-guidance-proto-file",
101             description = "A CrawlGuidance file to be executed by the crawler.")
102     private File mCrawlGuidanceProtoFile;
103 
104     @Option(
105             name = "login-config-dir",
106             description =
107                     "A directory containing Roboscript and CrawlGuidance files with login"
108                             + " credentials that are passed to the crawler. There should be one"
109                             + " config file per package name. If both Roboscript and CrawlGuidance"
110                             + " files are present, only the Roboscript file will be used.")
111     private File mLoginConfigDir;
112 
113     @Option(
114             name = "save-apk-when",
115             description = "When to save apk files to the test result artifacts.")
116     private TestUtils.TakeEffectWhen mSaveApkWhen = TestUtils.TakeEffectWhen.NEVER;
117 
118     @Option(
119             name = "grant-external-storage",
120             mandatory = false,
121             description = "After an apks are installed, grant MANAGE_EXTERNAL_STORAGE permissions.")
122     private boolean mGrantExternalStoragePermission = false;
123 
124     /** Returns the config value for whether to record the screen. */
isRecordScreen()125     public boolean isRecordScreen() {
126         return mRecordScreen;
127     }
128 
129     /** Sets whether to enable screen recording. */
setRecordScreen(boolean recordScreen)130     public AppCrawlTesterOptions setRecordScreen(boolean recordScreen) {
131         this.mRecordScreen = recordScreen;
132         return this;
133     }
134 
135     /** Returns the config value for whether to collect app version information. */
isCollectAppVersion()136     public boolean isCollectAppVersion() {
137         return mCollectAppVersion;
138     }
139 
140     /** Sets whether to enable app version collection. */
setCollectAppVersion(boolean collectAppVersion)141     public AppCrawlTesterOptions setCollectAppVersion(boolean collectAppVersion) {
142         this.mCollectAppVersion = collectAppVersion;
143         return this;
144     }
145 
146     /** Returns the config value for whether to collect GMS version information. */
isCollectGmsVersion()147     public boolean isCollectGmsVersion() {
148         return mCollectGmsVersion;
149     }
150 
151     /** Sets whether to enable GMS version collection. */
setCollectGmsVersion(boolean collectGmsVersion)152     public AppCrawlTesterOptions setCollectGmsVersion(boolean collectGmsVersion) {
153         this.mCollectGmsVersion = collectGmsVersion;
154         return this;
155     }
156 
157     /** Returns the config value for the repacked APK file path. */
getRepackApk()158     public File getRepackApk() {
159         return mRepackApk;
160     }
161 
162     /** Sets the repacked APK file path. */
setRepackApk(File repackApk)163     public AppCrawlTesterOptions setRepackApk(File repackApk) {
164         this.mRepackApk = repackApk;
165         return this;
166     }
167 
168     /** Returns the config value for the list of APK paths for installation. */
getInstallApkPaths()169     public List<File> getInstallApkPaths() {
170         return mInstallApkPaths;
171     }
172 
173     /** Sets the list of APK paths for installation. */
setInstallApkPaths(List<File> installApkPaths)174     public AppCrawlTesterOptions setInstallApkPaths(List<File> installApkPaths) {
175         this.mInstallApkPaths = installApkPaths;
176         return this;
177     }
178 
179     /** Returns the config value for the list of installation arguments. */
getInstallArgs()180     public List<String> getInstallArgs() {
181         return mInstallArgs;
182     }
183 
184     /** Sets the list of installation arguments. */
setInstallArgs(List<String> installArgs)185     public AppCrawlTesterOptions setInstallArgs(List<String> installArgs) {
186         this.mInstallArgs = installArgs;
187         return this;
188     }
189 
190     /** Returns the config value for the crawl controller endpoint URL. */
getCrawlControllerEndpoint()191     public String getCrawlControllerEndpoint() {
192         return mCrawlControllerEndpoint;
193     }
194 
195     /** Sets the crawl controller endpoint URL. */
setCrawlControllerEndpoint(String crawlControllerEndpoint)196     public AppCrawlTesterOptions setCrawlControllerEndpoint(String crawlControllerEndpoint) {
197         this.mCrawlControllerEndpoint = crawlControllerEndpoint;
198         return this;
199     }
200 
201     /** Returns the config value for whether to enable UiAutomator mode. */
isUiAutomatorMode()202     public boolean isUiAutomatorMode() {
203         return mUiAutomatorMode;
204     }
205 
206     /** Sets whether to enable UiAutomator mode. */
setUiAutomatorMode(boolean uiAutomatorMode)207     public AppCrawlTesterOptions setUiAutomatorMode(boolean uiAutomatorMode) {
208         this.mUiAutomatorMode = uiAutomatorMode;
209         return this;
210     }
211 
212     /** Returns the config value for the timeout duration in seconds. */
getTimeoutSec()213     public int getTimeoutSec() {
214         return mTimeoutSec;
215     }
216 
217     /** Sets the timeout duration in seconds. */
setTimeoutSec(int timeoutSec)218     public AppCrawlTesterOptions setTimeoutSec(int timeoutSec) {
219         this.mTimeoutSec = timeoutSec;
220         return this;
221     }
222 
223     /** Returns the config value for the Roboscript file path. */
getRoboscriptFile()224     public File getRoboscriptFile() {
225         return mRoboscriptFile;
226     }
227 
228     /** Sets the Roboscript file path. */
setRoboscriptFile(File roboscriptFile)229     public AppCrawlTesterOptions setRoboscriptFile(File roboscriptFile) {
230         this.mRoboscriptFile = roboscriptFile;
231         return this;
232     }
233 
234     /** Returns the config value for the crawl guidance proto file path. */
getCrawlGuidanceProtoFile()235     public File getCrawlGuidanceProtoFile() {
236         return mCrawlGuidanceProtoFile;
237     }
238 
239     /** Sets the crawl guidance proto file path. */
setCrawlGuidanceProtoFile(File crawlGuidanceProtoFile)240     public AppCrawlTesterOptions setCrawlGuidanceProtoFile(File crawlGuidanceProtoFile) {
241         this.mCrawlGuidanceProtoFile = crawlGuidanceProtoFile;
242         return this;
243     }
244 
245     /** Gets the config value of login config directory. */
getLoginConfigDir()246     public File getLoginConfigDir() {
247         return mLoginConfigDir;
248     }
249 
250     /** Sets the login config directory. */
setLoginConfigDir(File loginConfigDir)251     public AppCrawlTesterOptions setLoginConfigDir(File loginConfigDir) {
252         this.mLoginConfigDir = loginConfigDir;
253         return this;
254     }
255 
256     /** Gets the config value for when to save apks. */
getSaveApkWhen()257     public TestUtils.TakeEffectWhen getSaveApkWhen() {
258         return mSaveApkWhen;
259     }
260 
261     /** Sets when to save the apks to test artifacts. */
setSaveApkWhen(TestUtils.TakeEffectWhen saveApkWhen)262     public AppCrawlTesterOptions setSaveApkWhen(TestUtils.TakeEffectWhen saveApkWhen) {
263         this.mSaveApkWhen = saveApkWhen;
264         return this;
265     }
266 
267     /**
268      * Gets the config value for whether to grant external storage permission to the subject package
269      */
isGrantExternalStoragePermission()270     public boolean isGrantExternalStoragePermission() {
271         return mGrantExternalStoragePermission;
272     }
273 
274     /** Sets whether to grant external storage permission to the subject package. */
setGrantExternalStoragePermission( boolean grantExternalStoragePermission)275     public AppCrawlTesterOptions setGrantExternalStoragePermission(
276             boolean grantExternalStoragePermission) {
277         this.mGrantExternalStoragePermission = grantExternalStoragePermission;
278         return this;
279     }
280 }
281