| The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 1 | /* Copyright (C) 2008 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 | #include "android/avd/hw-config.h" |
| 13 | #include "android/utils/ini.h" |
| David 'Digit' Turner | b64325d | 2011-03-22 16:07:01 +0100 | [diff] [blame] | 14 | #include "android/utils/system.h" |
| The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 15 | #include <string.h> |
| 16 | #include <stdlib.h> |
| 17 | |
| 18 | |
| 19 | /* the global variable containing the hardware config for this device */ |
| 20 | AndroidHwConfig android_hw[1]; |
| 21 | |
| David 'Digit' Turner | b64325d | 2011-03-22 16:07:01 +0100 | [diff] [blame] | 22 | static int |
| 23 | stringToBoolean( const char* value ) |
| 24 | { |
| 25 | if (!strcmp(value,"1") || |
| 26 | !strcmp(value,"yes") || |
| 27 | !strcmp(value,"YES") || |
| 28 | !strcmp(value,"true") || |
| 29 | !strcmp(value,"TRUE")) |
| 30 | { |
| 31 | return 1; |
| 32 | } |
| 33 | else |
| 34 | return 0; |
| 35 | } |
| 36 | |
| 37 | static int64_t |
| 38 | diskSizeToInt64( const char* diskSize ) |
| 39 | { |
| 40 | char* end; |
| 41 | int64_t value; |
| 42 | |
| 43 | value = strtoll(diskSize, &end, 10); |
| 44 | if (*end == 'k' || *end == 'K') |
| 45 | value *= 1024ULL; |
| 46 | else if (*end == 'm' || *end == 'M') |
| 47 | value *= 1024*1024ULL; |
| 48 | else if (*end == 'g' || *end == 'G') |
| 49 | value *= 1024*1024*1024ULL; |
| 50 | |
| 51 | return value; |
| 52 | } |
| 53 | |
| 54 | |
| 55 | void |
| 56 | androidHwConfig_init( AndroidHwConfig* config, |
| 57 | int apiLevel ) |
| 58 | { |
| 59 | #define HWCFG_BOOL(n,s,d,a,t) config->n = stringToBoolean(d); |
| 60 | #define HWCFG_INT(n,s,d,a,t) config->n = d; |
| 61 | #define HWCFG_STRING(n,s,d,a,t) config->n = ASTRDUP(d); |
| 62 | #define HWCFG_DOUBLE(n,s,d,a,t) config->n = d; |
| 63 | #define HWCFG_DISKSIZE(n,s,d,a,t) config->n = diskSizeToInt64(d); |
| 64 | |
| 65 | #include "android/avd/hw-config-defs.h" |
| 66 | |
| 67 | /* Special case for hw.keyboard.lid, we need to set the |
| 68 | * default to FALSE for apiLevel >= 12. This allows platform builds |
| 69 | * to get correct orientation emulation even if they don't bring |
| 70 | * a custom hardware.ini |
| 71 | */ |
| 72 | if (apiLevel >= 12) { |
| 73 | config->hw_keyboard_lid = 0; |
| 74 | } |
| 75 | } |
| 76 | |
| The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 77 | int |
| 78 | androidHwConfig_read( AndroidHwConfig* config, |
| 79 | IniFile* ini ) |
| 80 | { |
| 81 | if (ini == NULL) |
| 82 | return -1; |
| 83 | |
| 84 | /* use the magic of macros to implement the hardware configuration loaded */ |
| 85 | |
| David 'Digit' Turner | b64325d | 2011-03-22 16:07:01 +0100 | [diff] [blame] | 86 | #define HWCFG_BOOL(n,s,d,a,t) if (iniFile_getValue(ini, s)) { config->n = iniFile_getBoolean(ini, s, d); } |
| 87 | #define HWCFG_INT(n,s,d,a,t) if (iniFile_getValue(ini, s)) { config->n = iniFile_getInteger(ini, s, d); } |
| 88 | #define HWCFG_STRING(n,s,d,a,t) if (iniFile_getValue(ini, s)) { AFREE(config->n); config->n = iniFile_getString(ini, s, d); } |
| 89 | #define HWCFG_DOUBLE(n,s,d,a,t) if (iniFile_getValue(ini, s)) { config->n = iniFile_getDouble(ini, s, d); } |
| 90 | #define HWCFG_DISKSIZE(n,s,d,a,t) if (iniFile_getValue(ini, s)) { config->n = iniFile_getDiskSize(ini, s, d); } |
| The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 91 | |
| 92 | #include "android/avd/hw-config-defs.h" |
| 93 | |
| 94 | return 0; |
| 95 | } |
| David 'Digit' Turner | 622f153 | 2011-02-01 17:48:37 +0100 | [diff] [blame] | 96 | |
| 97 | int |
| 98 | androidHwConfig_write( AndroidHwConfig* config, |
| 99 | IniFile* ini ) |
| 100 | { |
| 101 | if (ini == NULL) |
| 102 | return -1; |
| 103 | |
| 104 | /* use the magic of macros to implement the hardware configuration loaded */ |
| 105 | |
| 106 | #define HWCFG_BOOL(n,s,d,a,t) iniFile_setBoolean(ini, s, config->n); |
| 107 | #define HWCFG_INT(n,s,d,a,t) iniFile_setInteger(ini, s, config->n); |
| 108 | #define HWCFG_STRING(n,s,d,a,t) iniFile_setValue(ini, s, config->n); |
| 109 | #define HWCFG_DOUBLE(n,s,d,a,t) iniFile_setDouble(ini, s, config->n); |
| 110 | #define HWCFG_DISKSIZE(n,s,d,a,t) iniFile_setDiskSize(ini, s, config->n); |
| 111 | |
| 112 | #include "android/avd/hw-config-defs.h" |
| 113 | |
| 114 | return 0; |
| 115 | } |
| David 'Digit' Turner | b64325d | 2011-03-22 16:07:01 +0100 | [diff] [blame] | 116 | |
| 117 | void |
| 118 | androidHwConfig_done( AndroidHwConfig* config ) |
| 119 | { |
| 120 | #define HWCFG_BOOL(n,s,d,a,t) config->n = 0; |
| 121 | #define HWCFG_INT(n,s,d,a,t) config->n = 0; |
| 122 | #define HWCFG_STRING(n,s,d,a,t) AFREE(config->n); |
| 123 | #define HWCFG_DOUBLE(n,s,d,a,t) config->n = 0.0; |
| 124 | #define HWCFG_DISKSIZE(n,s,d,a,t) config->n = 0; |
| 125 | |
| 126 | #include "android/avd/hw-config-defs.h" |
| 127 | } |
| Vladimir Chtchetkine | 863d101 | 2012-03-16 12:25:23 -0700 | [diff] [blame] | 128 | |
| 129 | int |
| 130 | androidHwConfig_isScreenNoTouch( AndroidHwConfig* config ) |
| 131 | { |
| 132 | return strcmp(config->hw_screen, "no-touch") == 0; |
| 133 | } |
| 134 | |
| 135 | int |
| 136 | androidHwConfig_isScreenTouch( AndroidHwConfig* config ) |
| 137 | { |
| 138 | return strcmp(config->hw_screen, "touch") == 0; |
| 139 | } |
| 140 | |
| 141 | int |
| 142 | androidHwConfig_isScreenMultiTouch( AndroidHwConfig* config ) |
| 143 | { |
| 144 | return strcmp(config->hw_screen, "multi-touch") == 0; |
| 145 | } |
| David 'Digit' Turner | c6e0cae | 2014-03-07 23:08:30 +0100 | [diff] [blame] | 146 | |
| 147 | int |
| 148 | androidHwConfig_getKernelDeviceNaming( AndroidHwConfig* config ) |
| 149 | { |
| 150 | if (!strcmp(config->kernel_newDeviceNaming, "no")) |
| 151 | return 0; |
| 152 | if (!strcmp(config->kernel_newDeviceNaming, "yes")) |
| 153 | return 1; |
| 154 | return -1; |
| 155 | } |
| 156 | |
| David 'Digit' Turner | cc5804c | 2014-06-12 19:26:27 +0200 | [diff] [blame] | 157 | int |
| 158 | androidHwConfig_getKernelYaffs2Support( AndroidHwConfig* config ) |
| 159 | { |
| 160 | if (!strcmp(config->kernel_supportsYaffs2, "no")) |
| 161 | return 0; |
| 162 | if (!strcmp(config->kernel_supportsYaffs2, "yes")) |
| 163 | return 1; |
| 164 | return -1; |
| 165 | } |
| 166 | |
| David 'Digit' Turner | c6e0cae | 2014-03-07 23:08:30 +0100 | [diff] [blame] | 167 | const char* androidHwConfig_getKernelSerialPrefix(AndroidHwConfig* config ) |
| 168 | { |
| 169 | if (androidHwConfig_getKernelDeviceNaming(config) >= 1) { |
| 170 | return "ttyGF"; |
| 171 | } else { |
| 172 | return "ttyS"; |
| 173 | } |
| 174 | } |