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 package com.android.tradefed.testtype.suite.params;
17 
18 import java.util.HashMap;
19 import java.util.Map;
20 
21 /** Helper to get the {@link IModuleParameter} associated with the parameter. */
22 public class ModuleParametersHelper {
23 
24     private static Map<ModuleParameters, IModuleParameter> sHandlerMap = new HashMap<>();
25 
26     static {
sHandlerMap.put(ModuleParameters.INSTANT_APP, new InstantAppHandler())27         sHandlerMap.put(ModuleParameters.INSTANT_APP, new InstantAppHandler());
sHandlerMap.put(ModuleParameters.NOT_INSTANT_APP, new NegativeHandler())28         sHandlerMap.put(ModuleParameters.NOT_INSTANT_APP, new NegativeHandler());
29 
sHandlerMap.put(ModuleParameters.MULTI_ABI, new NegativeHandler())30         sHandlerMap.put(ModuleParameters.MULTI_ABI, new NegativeHandler());
sHandlerMap.put(ModuleParameters.NOT_MULTI_ABI, new NotMultiAbiHandler())31         sHandlerMap.put(ModuleParameters.NOT_MULTI_ABI, new NotMultiAbiHandler());
32     }
33 
34     /**
35      * Optional parameters are params that will not automatically be created when the module
36      * parameterization is enabled. They will need to be explicitly enabled. They represent a second
37      * set of parameterization that is less commonly requested to run. They could be upgraded to
38      * main parameters in the future by moving them above.
39      */
40     private static Map<ModuleParameters, IModuleParameter> sOptionalHandlerMap = new HashMap<>();
41 
42     static {
sOptionalHandlerMap.put(ModuleParameters.SECONDARY_USER, new SecondaryUserHandler())43         sOptionalHandlerMap.put(ModuleParameters.SECONDARY_USER, new SecondaryUserHandler());
sOptionalHandlerMap.put(ModuleParameters.NOT_SECONDARY_USER, new NegativeHandler())44         sOptionalHandlerMap.put(ModuleParameters.NOT_SECONDARY_USER, new NegativeHandler());
45     }
46 
47     /**
48      * Returns the {@link IModuleParameter} associated with the requested parameter.
49      *
50      * @param withOptional Whether or not to also check optional params.
51      */
getParameterHandler( ModuleParameters param, boolean withOptional)52     public static IModuleParameter getParameterHandler(
53             ModuleParameters param, boolean withOptional) {
54         IModuleParameter value = sHandlerMap.get(param);
55         if (value == null && withOptional) {
56             return sOptionalHandlerMap.get(param);
57         }
58         return value;
59     }
60 }
61