|
17 | 17 | #include "HardwareBase.h" |
18 | 18 |
|
19 | 19 | #include <cutils/properties.h> |
| 20 | +#include <dlfcn.h> |
20 | 21 | #include <log/log.h> |
21 | 22 |
|
22 | 23 | #include <fstream> |
23 | 24 | #include <sstream> |
24 | 25 |
|
25 | 26 | #include "utils.h" |
26 | 27 |
|
| 28 | +namespace { |
| 29 | + |
| 30 | +// TA functions |
| 31 | +static void* ta_handle = nullptr; |
| 32 | +static int (*miscta_get_unit_size)(uint32_t unit, uint32_t* size) = nullptr; |
| 33 | +static int (*miscta_read_unit)(uint32_t id, void* buf, uint32_t* size) = nullptr; |
| 34 | + |
| 35 | +template <typename T> |
| 36 | +static bool ta_read_unit(T& out, uint32_t unit) { |
| 37 | + uint32_t size = 0; |
| 38 | + |
| 39 | + int ret = miscta_get_unit_size(unit, &size); |
| 40 | + if (ret) { |
| 41 | + ALOGE("%s: Cannot retrieve TA unit %d size error %d", __func__, unit, ret); |
| 42 | + return false; |
| 43 | + } |
| 44 | + |
| 45 | + if (size != sizeof(T)) { |
| 46 | + ALOGE("%s: Unexpected TA unit size %d != %lu", __func__, size, sizeof(T)); |
| 47 | + return false; |
| 48 | + } |
| 49 | + |
| 50 | + ret = miscta_read_unit(unit, &out, &size); |
| 51 | + if (ret) { |
| 52 | + ALOGE("%s: Cannot read TA unit %d of size %u: error %d", __func__, unit, size, ret); |
| 53 | + return false; |
| 54 | + } |
| 55 | + |
| 56 | + return true; |
| 57 | +} |
| 58 | + |
| 59 | +}; // namespace |
| 60 | + |
27 | 61 | namespace aidl { |
28 | 62 | namespace android { |
29 | 63 | namespace hardware { |
@@ -79,16 +113,29 @@ HwCalBase::HwCalBase() { |
79 | 113 | ALOGE("Failed get property prefix!"); |
80 | 114 | } |
81 | 115 |
|
82 | | - utils::fileFromEnv("CALIBRATION_FILEPATH", &calfile); |
| 116 | + ta_handle = dlopen("libmiscta.so", RTLD_NOW); |
| 117 | + if (ta_handle) { |
| 118 | + // Load related symbols |
| 119 | + miscta_get_unit_size = reinterpret_cast<typeof(miscta_get_unit_size)>( |
| 120 | + dlsym(ta_handle, "miscta_get_unit_size")); |
| 121 | + if (!miscta_get_unit_size) { |
| 122 | + ALOGE("%s: Cannot find symbol: miscta_get_unit_size", __func__); |
| 123 | + return; |
| 124 | + } |
83 | 125 |
|
84 | | - for (std::string line; std::getline(calfile, line);) { |
85 | | - if (line.empty() || line[0] == '#') { |
86 | | - continue; |
| 126 | + miscta_read_unit = |
| 127 | + reinterpret_cast<typeof(miscta_read_unit)>(dlsym(ta_handle, "miscta_read_unit")); |
| 128 | + if (!miscta_read_unit) { |
| 129 | + ALOGE("%s: Cannot find symbol: miscta_read_unit", __func__); |
| 130 | + return; |
87 | 131 | } |
88 | | - std::istringstream is_line(line); |
89 | | - std::string key, value; |
90 | | - if (std::getline(is_line, key, ':') && std::getline(is_line, value)) { |
91 | | - mCalData[utils::trim(key)] = utils::trim(value); |
| 132 | + |
| 133 | + int redc_measured = 0; |
| 134 | + int f0_measured = 0; |
| 135 | + |
| 136 | + if (ta_read_unit(redc_measured, 4732) && ta_read_unit(f0_measured, 4733)) { |
| 137 | + mCalData["f0_measured"] = std::to_string(f0_measured); |
| 138 | + mCalData["redc_measured"] = std::to_string(redc_measured); |
92 | 139 | } |
93 | 140 | } |
94 | 141 | } |
|
0 commit comments