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.build;
17 
18 import java.util.HashSet;
19 import java.util.Set;
20 
21 /** Class holding enumeration related to build information queries. */
22 public class BuildInfoKey {
23 
24     /**
25      * Enum describing all the known file types that can be queried through {@link
26      * IBuildInfo#getFile(BuildInfoFileKey)}.
27      */
28     public enum BuildInfoFileKey {
29         DEVICE_IMAGE("device", false),
30         USERDATA_IMAGE("userdata", false),
31         TESTDIR_IMAGE("testsdir", false),
32         BASEBAND_IMAGE("baseband", false),
33         BOOTLOADER_IMAGE("bootloader", false),
34         OTA_IMAGE("ota", false),
35         MKBOOTIMG_IMAGE("mkbootimg", false),
36         RAMDISK_IMAGE("ramdisk", false),
37 
38         // Root folder directory
39         ROOT_DIRECTORY("rootdirectory", false),
40 
41         // Externally linked files in the testsdir:
42         // ANDROID_HOST_OUT_TESTCASES and ANDROID_TARGET_OUT_TESTCASES are linked in the tests dir
43         // of the build info.
44         TARGET_LINKED_DIR("target_testcases", false),
45         HOST_LINKED_DIR("host_testcases", false),
46 
47         // Keys that can hold lists of files.
48         PACKAGE_FILES("package_files", true);
49 
50         private final String mFileKey;
51         private final boolean mCanBeList;
52 
BuildInfoFileKey(String fileKey, boolean canBeList)53         private BuildInfoFileKey(String fileKey, boolean canBeList) {
54             mFileKey = fileKey;
55             mCanBeList = canBeList;
56         }
57 
getFileKey()58         public String getFileKey() {
59             return mFileKey;
60         }
61 
isList()62         public boolean isList() {
63             return mCanBeList;
64         }
65 
66         @Override
toString()67         public String toString() {
68             return mFileKey;
69         }
70 
71         /**
72          * Convert a key name to its {@link BuildInfoFileKey} if any is found. Returns null
73          * otherwise.
74          */
fromString(String keyName)75         public static BuildInfoFileKey fromString(String keyName) {
76             for (BuildInfoFileKey v : BuildInfoFileKey.values()) {
77                 if (v.getFileKey().equals(keyName)) {
78                     return v;
79                 }
80             }
81             return null;
82         }
83     }
84 
85     /**
86      * Files key that should be shared from a resources build info to all build infos via the {@link
87      * IDeviceBuildInfo#getResourcesDir()}.
88      */
89     public static final Set<BuildInfoFileKey> SHARED_KEY = new HashSet<>();
90 
91     static {
92         SHARED_KEY.add(BuildInfoFileKey.PACKAGE_FILES);
93         SHARED_KEY.add(BuildInfoFileKey.TESTDIR_IMAGE);
94         SHARED_KEY.add(BuildInfoFileKey.ROOT_DIRECTORY);
95     }
96 }
97