1 /* Copyright (C) 2011 The Android Open Source Project 2 ** 3 ** This software is licensed under the terms of the GNU General Public 4 ** License version 2, as published by the Free Software Foundation, and 5 ** may be copied, distributed, and modified under those terms. 6 ** 7 ** This program is distributed in the hope that it will be useful, 8 ** but WITHOUT ANY WARRANTY; without even the implied warranty of 9 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 ** GNU General Public License for more details. 11 */ 12 #ifndef _ANDROID_AVD_UTIL_H 13 #define _ANDROID_AVD_UTIL_H 14 15 #include "android/utils/compiler.h" 16 #include "android/utils/file_data.h" 17 18 ANDROID_BEGIN_HEADER 19 20 /* A collection of simple functions to extract relevant AVD-related 21 * information either from an SDK AVD or a platform build. 22 */ 23 24 /* Return the path to the Android SDK root installation. 25 * 26 * (*pFromEnv) will be set to 1 if it comes from the $ANDROID_SDK_ROOT 27 * environment variable, or 0 otherwise. 28 * 29 * Caller must free() returned string. 30 */ 31 char* path_getSdkRoot( char *pFromEnv ); 32 33 /* Return the path to the AVD's root configuration .ini file. it is located in 34 * ~/.android/avd/<name>.ini or Windows equivalent 35 * 36 * This file contains the path to the AVD's content directory, which 37 * includes its own config.ini. 38 */ 39 char* path_getRootIniPath( const char* avdName ); 40 41 /* Return the target architecture for a given AVD. 42 * Called must free() returned string. 43 */ 44 char* path_getAvdTargetArch( const char* avdName ); 45 46 typedef enum { 47 RESULT_INVALID = -1, // key was found but value contained invalid data 48 RESULT_FOUND = 0, // key was found and value parsed correctly 49 RESULT_NOT_FOUND = 1, // key was not found (default used) 50 } SearchResult; 51 52 /* Retrieves an integer value associated with the key parameter 53 * 54 * |data| is a FileData instance 55 * |key| name of key to search for 56 * |searchResult| if non-null, this is set to RESULT_INVALID, RESULT_FOUND, 57 * or RESULT_NOT_FOUND 58 * Returns valid parsed int value if found, |default| otherwise 59 */ 60 int propertyFile_getInt(const FileData* data, const char* key, int _default, 61 SearchResult* searchResult); 62 63 /* Retrieves a string corresponding to the target architecture 64 * extracted from a build properties file. 65 * 66 * |data| is a FileData instance holding the build.prop contents. 67 * Returns a a new string that must be freed by the caller, which can 68 * be 'armeabi', 'armeabi-v7a', 'x86', etc... or NULL if 69 * it cannot be determined. 70 */ 71 char* propertyFile_getTargetAbi(const FileData* data); 72 73 /* Retrieves a string corresponding to the target architecture 74 * extracted from a build properties file. 75 * 76 * |data| is a FileData instance holding the build.prop contents. 77 * Returns a new string that must be freed by the caller, which can 78 * be 'arm', 'x86, 'mips', etc..., or NULL if if cannot be determined. 79 */ 80 char* propertyFile_getTargetArch(const FileData* data); 81 82 /* Retrieve the target API level from the build.prop contents. 83 * Returns a very large value (e.g. 100000) if it cannot be determined 84 * (which happens for platform builds), or 3 (the minimum SDK API level) 85 * if there is invalid value. 86 */ 87 int propertyFile_getApiLevel(const FileData* data); 88 89 /* Retrieve the mode describing how the ADB daemon is communicating with 90 * the emulator from inside the guest. 91 * Return 0 for legacy mode, which uses TCP port 5555. 92 * Return 1 for the 'qemud' mode, which uses a QEMUD service instead. 93 */ 94 int propertyFile_getAdbdCommunicationMode(const FileData* data); 95 96 /* Return the path of the build properties file (build.prop) from an 97 * Android platform build, or NULL if it doesn't exist. 98 */ 99 char* path_getBuildBuildProp( const char* androidOut ); 100 101 /* Return the path of the boot properties file (boot.prop) from an 102 * Android platform build, or NULL if it doesn't exit. 103 */ 104 char* path_getBuildBootProp( const char* androidOut ); 105 106 /* Return the target architecture from the build properties file 107 * (build.prop) of an Android platformn build. Return NULL or a new 108 * string that must be freed by the caller. 109 */ 110 char* path_getBuildTargetArch( const char* androidOut ); 111 112 /* Given an AVD's target architecture, return the suffix of the 113 * corresponding emulator backend program, e.g. 'x86' for x86 and x86_64 114 * CPUs, 'arm' for ARM ones (including ARM64 when support is complete), 115 * etc. Returned string must not be freed by the caller. 116 */ 117 const char* emulator_getBackendSuffix(const char* targetArch); 118 119 ANDROID_END_HEADER 120 121 #endif /* _ANDROID_AVD_UTIL_H */ 122