• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2020 The Android Open Source Project
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 #pragma once
15 
16 class FileData;
17 
18 /* A collection of simple functions to extract relevant AVD-related
19  * information either from an SDK AVD or a platform build.
20  */
21 
22 /* Return the path to the Android SDK root installation.
23  * Caller must free() returned string.
24  */
25 char* path_getSdkRoot();
26 
27 /* Return the path to the AVD's root configuration .ini file. it is located in
28  * ~/.android/avd/<name>.ini or Windows equivalent
29  *
30  * This file contains the path to the AVD's content directory, which
31  * includes its own config.ini.
32  */
33 char* path_getRootIniPath( const char*  avdName );
34 
35 /* Return the path to the AVD's content directory. it is located in
36  *  ~/.android/avd/<name>.avd or Windows equivalent
37  * Caller must free() returned string.
38  */
39 char* path_getAvdContentPath( const char* avdName );
40 
41 /* Return the target architecture for a given AVD.
42  * Caller must free() returned string.
43  */
44 char* path_getAvdTargetArch( const char* avdName );
45 
46 /* Return the snapshot.present for a given AVD.
47  * Caller must free() returned string.
48  */
49 char* path_getAvdSnapshotPresent( const char* avdName );
50 
51 /* Return the path to an AVD's system images directory, relative to a given
52  * root SDK path. Caller must free() the result.
53  */
54 char* path_getAvdSystemPath(const char* avdName,
55                             const char* sdkRootPath);
56 
57 /* Return the value of hw.gpu.mode for a given AVD.
58  * Caller must free() returned string.
59  *
60  * NOTE: If hw.gpu.enabled is false, then this returns NULL
61  */
62 char* path_getAvdGpuMode(const char* avdName);
63 
64 typedef enum {
65     RESULT_INVALID   = -1, // key was found but value contained invalid data
66     RESULT_FOUND     =  0, // key was found and value parsed correctly
67     RESULT_NOT_FOUND =  1, // key was not found (default used)
68 } SearchResult;
69 
70 /* Retrieves an integer value associated with the key parameter
71  *
72  * |data| is a FileData instance
73  * |key| name of key to search for
74  * |searchResult| if non-null, this is set to RESULT_INVALID, RESULT_FOUND,
75  *                or RESULT_NOT_FOUND
76  * Returns valid parsed int value if found, |default| otherwise
77  */
78 int propertyFile_getInt(const FileData* data, const char* key, int _default,
79                         SearchResult* searchResult);
80 
81 /* Retrieves a string corresponding to the target architecture
82  * extracted from a build properties file.
83  *
84  * |data| is a FileData instance holding the build.prop contents.
85  * Returns a a new string that must be freed by the caller, which can
86  * be 'armeabi', 'armeabi-v7a', 'x86', etc... or NULL if
87  * it cannot be determined.
88  */
89 char* propertyFile_getTargetAbi(const FileData* data);
90 
91 /* Retrieves a string corresponding to the target architecture
92  * extracted from a build properties file.
93  *
94  * |data| is a FileData instance holding the build.prop contents.
95  * Returns a new string that must be freed by the caller, which can
96  * be 'arm', 'x86, 'mips', etc..., or NULL if if cannot be determined.
97  */
98 char* propertyFile_getTargetArch(const FileData* data);
99 
100 /* Retrieve the target API level from the build.prop contents.
101  * Returns a very large value (e.g. 100000) if it cannot be determined
102  * (which happens for platform builds), or 3 (the minimum SDK API level)
103  * if there is invalid value.
104  */
105 int propertyFile_getApiLevel(const FileData* data);
106 
107 typedef enum {
108     AVD_PHONE = 0,
109     AVD_TV = 1,
110     AVD_WEAR = 2,
111     AVD_ANDROID_AUTO = 3,
112     AVD_OTHER = 255,
113 } AvdFlavor;
114 
115 /* Determine the flavor of system image. */
116 AvdFlavor propertyFile_getAvdFlavor(const FileData* data);
117 
118 /* Determine whether a Google API's system image is used. */
119 bool propertyFile_isGoogleApis(const FileData* data);
120 
121 /* Determine whether the system image is a user build. */
122 bool propertyFile_isUserBuild(const FileData* data);
123 
124 /* Return whether the product name in property file has a substring matching any
125  * of the the given ones.
126  *
127  * |productNames| is a list of product names to compare to.
128  * |len| is the number of product names.
129  * |prefix| is whether the given product name needs to be the prefix.
130  */
131 bool propertyFile_findProductName(const FileData* data,
132                                   const char *productNames[],
133                                   int len,
134                                   bool prefix);
135 
136 /* Retrieve the mode describing how the ADB daemon is communicating with
137  * the emulator from inside the guest.
138  * Return 0 for legacy mode, which uses TCP port 5555.
139  * Return 1 for the 'qemud' mode, which uses a QEMUD service instead.
140  */
141 int propertyFile_getAdbdCommunicationMode(const FileData* data);
142 
143 /* Return the path of the build properties file (build.prop) from an
144  * Android platform build, or NULL if it doesn't exist.
145  */
146 char* path_getBuildBuildProp( const char* androidOut );
147 
148 /* Return the path of the boot properties file (boot.prop) from an
149  * Android platform build, or NULL if it doesn't exit.
150  */
151 char* path_getBuildBootProp( const char* androidOut );
152 
153 /* Return the target architecture from the build properties file
154  *  (build.prop) of an Android platformn build. Return NULL or a new
155  * string that must be freed by the caller.
156  */
157 char* path_getBuildTargetArch( const char* androidOut );
158 
159 /* Given an AVD's target architecture, return the suffix of the
160  * corresponding emulator backend program, e.g. 'x86' for x86 and x86_64
161  * CPUs, 'arm' for ARM ones (including ARM64 when support is complete),
162  * etc. Returned string must not be freed by the caller.
163  */
164 const char* emulator_getBackendSuffix(const char* targetArch);
165 
166 /* this is the subdirectory of $HOME/.android where all
167  * root configuration files (and default content directories)
168  * are located.
169  */
170 #define  ANDROID_AVD_DIR    "avd"
171 
172 #define ANDROID_AVD_TMP_ADB_COMMAND_DIR "tmpAdbCmds"
173