From bf3ff516ca9606324410bd5919ed29fd4c2fb173 Mon Sep 17 00:00:00 2001 From: Chungjui Fan Date: Fri, 30 Dec 2022 11:53:55 +0000 Subject: [PATCH 1/3] lights: Add golden calibration support The units should deploy the golden calibration data in either case of replacement of MLB or CG. Bug: 264023021 Change-Id: Idb670bfefb3585ee1413e16c3e07d4d818f3f9ab Signed-off-by: Chungjui Fan --- device-tangorpro.mk | 5 ++ lights/Android.bp | 6 +++ lights/Lights.cpp | 46 +++++++++++++++++-- .../led_golden_calibration_LUT_black_CG.txt | 3 ++ .../led_golden_calibration_LUT_white_CG.txt | 3 ++ lights/led_lut_calibrator.cpp | 32 +++++++++++-- lights/led_lut_calibrator.h | 6 ++- 7 files changed, 92 insertions(+), 9 deletions(-) create mode 100644 lights/led_golden_calibration_LUT_black_CG.txt create mode 100644 lights/led_golden_calibration_LUT_white_CG.txt diff --git a/device-tangorpro.mk b/device-tangorpro.mk index 02e1702..c2cdabf 100644 --- a/device-tangorpro.mk +++ b/device-tangorpro.mk @@ -190,6 +190,11 @@ PRODUCT_PACKAGES_DEBUG += \ PRODUCT_PACKAGES += \ android.hardware.lights-service.tangorpro +# LED Golden Config +PRODUCT_COPY_FILES += \ + device/google/tangorpro/lights/led_golden_calibration_LUT_white_CG.txt:$(TARGET_COPY_OUT_VENDOR)/etc/led_golden_calibration_LUT_white_CG.txt \ + device/google/tangorpro/lights/led_golden_calibration_LUT_black_CG.txt:$(TARGET_COPY_OUT_VENDOR)/etc/led_golden_calibration_LUT_black_CG.txt + # Device features PRODUCT_COPY_FILES += \ frameworks/native/data/etc/tablet_core_hardware.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/tablet_core_hardware.xml diff --git a/lights/Android.bp b/lights/Android.bp index dc4a269..9544e19 100644 --- a/lights/Android.bp +++ b/lights/Android.bp @@ -19,5 +19,11 @@ cc_binary { "android.hardware.light-V2-ndk", ], + static_libs: [ + "//hardware/google/interfaces:com.google.hardware.pixel.display-V7-ndk", + "android.hardware.common-V2-ndk", + "android.hardware.graphics.common-V4-ndk", + ], + srcs: ["Lights.cpp", "led_lut_calibrator.cpp"], } diff --git a/lights/Lights.cpp b/lights/Lights.cpp index 0c94698..c6594bd 100644 --- a/lights/Lights.cpp +++ b/lights/Lights.cpp @@ -15,6 +15,7 @@ */ #include +#include #include #include #include @@ -29,6 +30,10 @@ using ::aidl::android::hardware::light::ILights; using ::aidl::android::hardware::light::LightType; using ::ndk::ScopedAStatus; using ::ndk::SharedRefBase; +using ::ndk::SpAIBinder; + +using aidl::com::google::hardware::pixel::display::IDisplay; +using PanelCalibrationStatus = aidl::com::google::hardware::pixel::display::PanelCalibrationStatus; static pthread_mutex_t g_lock = PTHREAD_MUTEX_INITIALIZER; @@ -79,10 +84,34 @@ static int sys_write_int(int fd, int value) { return amount == -1 ? -errno : 0; } +static SpAIBinder WaitForDisplayService() { + LOG(INFO) << "waiting for display service to appear"; + static std::mutex svc_mutex; + static SpAIBinder svc; + std::unique_lock l(svc_mutex); + uint8_t retrycount = 0; + + if (svc != nullptr && AIBinder_isAlive(svc.get())) return svc; + + while (true && retrycount < 20) { + svc = SpAIBinder(AServiceManager_waitForService( + "com.google.hardware.pixel.display.IDisplay/default")); + if (svc != nullptr) { + LOG(INFO) << "A wild display service has appeared!"; + return svc; + } + retrycount++; + sleep(2); + } + + LOG(ERROR) << "Failed to get the display service"; + return NULL; +} + class Lights : public BnLights { private: std::vector availableLights; - LedLutCalibrator calibrator; + LedLutCalibrator *calibrator; void addLight(LightType const type, int const ordinal) { HwLight light{}; @@ -117,12 +146,18 @@ class Lights : public BnLights { addLight(LightType::MICROPHONE, 0); addLight(LightType::CAMERA, 0); + SpAIBinder display_service = WaitForDisplayService(); + auto ser = IDisplay::fromBinder(display_service); + PanelCalibrationStatus cal; + ser->getPanelCalibrationStatus(&cal); + calibrator = new LedLutCalibrator(cal); + int cal_color = 0; - cal_color = calibrator.GetByColorIntensity("green", MODE_DAY); + cal_color = calibrator->GetByColorIntensity("green", MODE_DAY); if (cal_color >= 0) { pwmIds[0].pwm = cal_color; } - cal_color = calibrator.GetByColorIntensity("green", MODE_NIGHT); + cal_color = calibrator->GetByColorIntensity("green", MODE_NIGHT); if (cal_color >= 0) { pwmIds[1].pwm = cal_color << 1; pwmIds[2].pwm = cal_color; @@ -166,6 +201,11 @@ class Lights : public BnLights { int main() { ABinderProcess_setThreadPoolMaxThreadCount(0); + SpAIBinder display_service = WaitForDisplayService(); + if (display_service == nullptr) { + return -1; + } + std::shared_ptr light = SharedRefBase::make(); const std::string instance = std::string() + ILights::descriptor + "/default"; diff --git a/lights/led_golden_calibration_LUT_black_CG.txt b/lights/led_golden_calibration_LUT_black_CG.txt new file mode 100644 index 0000000..9160177 --- /dev/null +++ b/lights/led_golden_calibration_LUT_black_CG.txt @@ -0,0 +1,3 @@ +green:4095:2100 +green:0000:243 +green_cal:1 diff --git a/lights/led_golden_calibration_LUT_white_CG.txt b/lights/led_golden_calibration_LUT_white_CG.txt new file mode 100644 index 0000000..f316c09 --- /dev/null +++ b/lights/led_golden_calibration_LUT_white_CG.txt @@ -0,0 +1,3 @@ +green:4095:680 +green:0000:49 +green_cal:1 diff --git a/lights/led_lut_calibrator.cpp b/lights/led_lut_calibrator.cpp index 0668693..860615d 100644 --- a/lights/led_lut_calibrator.cpp +++ b/lights/led_lut_calibrator.cpp @@ -17,14 +17,20 @@ #include "led_lut_calibrator.h" #include +#include #include #include #include -const char kCalibrationPath[] = "/mnt/vendor/persist/led/led_calibration_LUT.txt"; +using ::android::base::GetProperty; -LedLutCalibrator::LedLutCalibrator() { +const char D_kCalibrationPath[] = "/mnt/vendor/persist/led/led_calibration_LUT.txt"; +const char G_WHT_kCalibrationPath[] = "/vendor/etc/led_golden_calibration_LUT_white_CG.txt"; +const char G_BLK_kCalibrationPath[] = "/vendor/etc/led_golden_calibration_LUT_black_CG.txt"; + +LedLutCalibrator::LedLutCalibrator(PanelCalibrationStatus status) { + cal_status_ = status; if (!ReadCalibrationTable()) { LOG(ERROR) << "Failed to read calibration table"; cal_table_.clear(); @@ -47,19 +53,35 @@ bool LedLutCalibrator::ReadCalibrationTable() { int fd; int bytes; bool ret = true; + const char *k_path = D_kCalibrationPath; std::vector buffer; buffer.resize(512); - fd = open(kCalibrationPath, O_RDONLY); + fd = open(D_kCalibrationPath, O_RDONLY); + // If default calibration not found or display changed, deploy golen calibration. + if (fd < 0 || cal_status_ == PanelCalibrationStatus::GOLDEN) { + // Using golden white calibration as default + // even though bezel prooerty not found. + k_path = G_WHT_kCalibrationPath; + std::string cdt_hwid = GetProperty("ro.boot.cdt_hwid", ""); + std::string hex_variant_str = cdt_hwid.substr(16, 2); + int bezel_color; + sscanf(hex_variant_str.c_str(), "%x", &bezel_color); + // 0: white, 2: black + if (bezel_color == 2) + k_path = G_BLK_kCalibrationPath; + } + + fd = open(k_path, O_RDONLY); if (fd < 0) { - LOG(ERROR) << "Failed to open " << kCalibrationPath; + LOG(ERROR) << "Failed to open " << k_path; ret = false; goto ReadCalibrationTable_err; } bytes = read(fd, buffer.data(), buffer.size()); if (bytes == -1) { - LOG(ERROR) << "Failed to read " << kCalibrationPath; + LOG(ERROR) << "Failed to read " << k_path; ret = false; goto ReadCalibrationTable_err; } diff --git a/lights/led_lut_calibrator.h b/lights/led_lut_calibrator.h index 3756e86..7fb0eaa 100644 --- a/lights/led_lut_calibrator.h +++ b/lights/led_lut_calibrator.h @@ -20,10 +20,13 @@ #include #include #include +#include + +using PanelCalibrationStatus = aidl::com::google::hardware::pixel::display::PanelCalibrationStatus; class LedLutCalibrator { public: - LedLutCalibrator(); + LedLutCalibrator(PanelCalibrationStatus status); LedLutCalibrator &operator=(const LedLutCalibrator &) = delete; ~LedLutCalibrator() = default; int GetByColorIntensity(const std::string &color, int intensity) const; @@ -34,6 +37,7 @@ class LedLutCalibrator { std::string MakeLutKey(const std::string &color, int intensity) const; std::unordered_map cal_table_; + PanelCalibrationStatus cal_status_; }; #endif // GOOGLE_TANGOTRON_LIGHTS_LED_LUT_CALIBRATOR_H_ From 291e1c2ea35b39c4eb3bc63f95e835ff629580d9 Mon Sep 17 00:00:00 2001 From: kuanyuhuang Date: Fri, 6 Jan 2023 09:02:36 +0000 Subject: [PATCH 2/3] Bluetooth: add BT SAR tables Bluetooth SAR tables are for setting tx power of Bluetooth Bug: 264631351 Test: build and check log of reading SAR table Change-Id: I0025c9328b4b6b0b290909fe7a70a36975e3817a --- bluetooth/bluetooth_power_limits_tangorpro.csv | 2 ++ .../bluetooth_power_limits_tangorpro_GTU8P_CA.csv | 2 ++ .../bluetooth_power_limits_tangorpro_GTU8P_EU.csv | 2 ++ .../bluetooth_power_limits_tangorpro_GTU8P_JP.csv | 2 ++ .../bluetooth_power_limits_tangorpro_GTU8P_US.csv | 2 ++ bluetooth/syna_default.mk | 11 ++++++++++- 6 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 bluetooth/bluetooth_power_limits_tangorpro.csv create mode 100644 bluetooth/bluetooth_power_limits_tangorpro_GTU8P_CA.csv create mode 100644 bluetooth/bluetooth_power_limits_tangorpro_GTU8P_EU.csv create mode 100644 bluetooth/bluetooth_power_limits_tangorpro_GTU8P_JP.csv create mode 100644 bluetooth/bluetooth_power_limits_tangorpro_GTU8P_US.csv diff --git a/bluetooth/bluetooth_power_limits_tangorpro.csv b/bluetooth/bluetooth_power_limits_tangorpro.csv new file mode 100644 index 0000000..826f182 --- /dev/null +++ b/bluetooth/bluetooth_power_limits_tangorpro.csv @@ -0,0 +1,2 @@ +Head,BTHotspot,WIFI5Ghz,HotspotVoice,Cell,IMU,BDR_Single_Chain_0,EDR_Single_Chain_0,BLE_Single_Chain_0,BDR_Single_Chain_1,EDR_Single_Chain_1,BLE_Single_Chain_1,BDR_Dual_Chain_0,EDR_Dual_Chain_0,BLE_Dual_Chain_0,BDR_Dual_Chain_1,EDR_Dual_Chain_1,BLE_Dual_Chain_1 +any,any,any,any,any,any,61,27,19,61,27,19,61,27,19,61,27,19 diff --git a/bluetooth/bluetooth_power_limits_tangorpro_GTU8P_CA.csv b/bluetooth/bluetooth_power_limits_tangorpro_GTU8P_CA.csv new file mode 100644 index 0000000..995f6f5 --- /dev/null +++ b/bluetooth/bluetooth_power_limits_tangorpro_GTU8P_CA.csv @@ -0,0 +1,2 @@ +Head,BTHotspot,WIFI5Ghz,HotspotVoice,Cell,IMU,BDR_Single_Chain_0,EDR_Single_Chain_0,BLE_Single_Chain_0,BDR_Single_Chain_1,EDR_Single_Chain_1,BLE_Single_Chain_1,BDR_Dual_Chain_0,EDR_Dual_Chain_0,BLE_Dual_Chain_0,BDR_Dual_Chain_1,EDR_Dual_Chain_1,BLE_Dual_Chain_1 +any,any,any,any,any,any,61,61,56,61,61,56,61,61,56,61,61,56 diff --git a/bluetooth/bluetooth_power_limits_tangorpro_GTU8P_EU.csv b/bluetooth/bluetooth_power_limits_tangorpro_GTU8P_EU.csv new file mode 100644 index 0000000..d044ee9 --- /dev/null +++ b/bluetooth/bluetooth_power_limits_tangorpro_GTU8P_EU.csv @@ -0,0 +1,2 @@ +Head,BTHotspot,WIFI5Ghz,HotspotVoice,Cell,IMU,BDR_Single_Chain_0,EDR_Single_Chain_0,BLE_Single_Chain_0,BDR_Single_Chain_1,EDR_Single_Chain_1,BLE_Single_Chain_1,BDR_Dual_Chain_0,EDR_Dual_Chain_0,BLE_Dual_Chain_0,BDR_Dual_Chain_1,EDR_Dual_Chain_1,BLE_Dual_Chain_1 +any,any,any,any,any,any,62,35,19,62,35,19,62,35,19,62,35,19 diff --git a/bluetooth/bluetooth_power_limits_tangorpro_GTU8P_JP.csv b/bluetooth/bluetooth_power_limits_tangorpro_GTU8P_JP.csv new file mode 100644 index 0000000..389c01b --- /dev/null +++ b/bluetooth/bluetooth_power_limits_tangorpro_GTU8P_JP.csv @@ -0,0 +1,2 @@ +Head,BTHotspot,WIFI5Ghz,HotspotVoice,Cell,IMU,BDR_Single_Chain_0,EDR_Single_Chain_0,BLE_Single_Chain_0,BDR_Single_Chain_1,EDR_Single_Chain_1,BLE_Single_Chain_1,BDR_Dual_Chain_0,EDR_Dual_Chain_0,BLE_Dual_Chain_0,BDR_Dual_Chain_1,EDR_Dual_Chain_1,BLE_Dual_Chain_1 +any,any,any,any,any,any,61,27,28,61,27,28,61,27,28,61,27,28 diff --git a/bluetooth/bluetooth_power_limits_tangorpro_GTU8P_US.csv b/bluetooth/bluetooth_power_limits_tangorpro_GTU8P_US.csv new file mode 100644 index 0000000..995f6f5 --- /dev/null +++ b/bluetooth/bluetooth_power_limits_tangorpro_GTU8P_US.csv @@ -0,0 +1,2 @@ +Head,BTHotspot,WIFI5Ghz,HotspotVoice,Cell,IMU,BDR_Single_Chain_0,EDR_Single_Chain_0,BLE_Single_Chain_0,BDR_Single_Chain_1,EDR_Single_Chain_1,BLE_Single_Chain_1,BDR_Dual_Chain_0,EDR_Dual_Chain_0,BLE_Dual_Chain_0,BDR_Dual_Chain_1,EDR_Dual_Chain_1,BLE_Dual_Chain_1 +any,any,any,any,any,any,61,61,56,61,61,56,61,61,56,61,61,56 diff --git a/bluetooth/syna_default.mk b/bluetooth/syna_default.mk index fe3c67d..ca6109e 100644 --- a/bluetooth/syna_default.mk +++ b/bluetooth/syna_default.mk @@ -20,7 +20,16 @@ DEVICE_MANIFEST_FILE += \ BOARD_SEPOLICY_DIRS += device/google/tangorpro-sepolicy/bluetooth PRODUCT_PACKAGES += android.hardware.bluetooth@1.1-service.synabtlinux # Bluetooth SAR test tools -PRODUCT_PACKAGES_DEBUG += bluetooth_sar_test +PRODUCT_PACKAGES_DEBUG += bt_sar_test + +# Bluetooth Tx power caps +PRODUCT_COPY_FILES += \ + device/google/tangorpro/bluetooth/bluetooth_power_limits_tangorpro.csv:$(TARGET_COPY_OUT_VENDOR)/etc/bluetooth_power_limits.csv \ + device/google/tangorpro/bluetooth/bluetooth_power_limits_tangorpro_GTU8P_CA.csv:$(TARGET_COPY_OUT_VENDOR)/etc/bluetooth_power_limits_GTU8P_CA.csv \ + device/google/tangorpro/bluetooth/bluetooth_power_limits_tangorpro_GTU8P_EU.csv:$(TARGET_COPY_OUT_VENDOR)/etc/bluetooth_power_limits_GTU8P_EU.csv \ + device/google/tangorpro/bluetooth/bluetooth_power_limits_tangorpro_GTU8P_JP.csv:$(TARGET_COPY_OUT_VENDOR)/etc/bluetooth_power_limits_GTU8P_JP.csv \ + device/google/tangorpro/bluetooth/bluetooth_power_limits_tangorpro_GTU8P_US.csv:$(TARGET_COPY_OUT_VENDOR)/etc/bluetooth_power_limits_GTU8P_US.csv \ + # default BDADDR for EVB only PRODUCT_PROPERTY_OVERRIDES += \ ro.vendor.bluetooth.evb_bdaddr="22:22:22:33:44:55" From e10a95b4b1cc3e6400a5b8c742369a8a9eaf02fe Mon Sep 17 00:00:00 2001 From: Chungjui Fan Date: Fri, 30 Dec 2022 11:53:55 +0000 Subject: [PATCH 3/3] [DO NOT MERGE]lights: Add golden calibration support The units should deploy the golden calibration data in either case of replacement of MLB or CG. Bug: 264023021 Change-Id: Idb670bfefb3585ee1413e16c3e07d4d818f3f9ab Merged-In: Idb670bfefb3585ee1413e16c3e07d4d818f3f9ab Signed-off-by: Chungjui Fan --- device-tangorpro.mk | 5 ++ lights/Android.bp | 6 +++ lights/Lights.cpp | 46 +++++++++++++++++-- .../led_golden_calibration_LUT_black_CG.txt | 3 ++ .../led_golden_calibration_LUT_white_CG.txt | 3 ++ lights/led_lut_calibrator.cpp | 32 +++++++++++-- lights/led_lut_calibrator.h | 6 ++- 7 files changed, 92 insertions(+), 9 deletions(-) create mode 100644 lights/led_golden_calibration_LUT_black_CG.txt create mode 100644 lights/led_golden_calibration_LUT_white_CG.txt diff --git a/device-tangorpro.mk b/device-tangorpro.mk index 50f3e7c..f771a54 100644 --- a/device-tangorpro.mk +++ b/device-tangorpro.mk @@ -185,6 +185,11 @@ PRODUCT_PACKAGES_DEBUG += \ PRODUCT_PACKAGES += \ android.hardware.lights-service.tangorpro +# LED Golden Config +PRODUCT_COPY_FILES += \ + device/google/tangorpro/lights/led_golden_calibration_LUT_white_CG.txt:$(TARGET_COPY_OUT_VENDOR)/etc/led_golden_calibration_LUT_white_CG.txt \ + device/google/tangorpro/lights/led_golden_calibration_LUT_black_CG.txt:$(TARGET_COPY_OUT_VENDOR)/etc/led_golden_calibration_LUT_black_CG.txt + # Use GmsCorePrebuilt y2022w41 USE_GMSCORE_PREBUILT_Y2022W41 := true diff --git a/lights/Android.bp b/lights/Android.bp index dc4a269..c1c6a35 100644 --- a/lights/Android.bp +++ b/lights/Android.bp @@ -19,5 +19,11 @@ cc_binary { "android.hardware.light-V2-ndk", ], + static_libs: [ + "//hardware/google/interfaces:com.google.hardware.pixel.display-V7-ndk", + "android.hardware.common-V2-ndk", + "android.hardware.graphics.common-V3-ndk", + ], + srcs: ["Lights.cpp", "led_lut_calibrator.cpp"], } diff --git a/lights/Lights.cpp b/lights/Lights.cpp index 0c94698..c6594bd 100644 --- a/lights/Lights.cpp +++ b/lights/Lights.cpp @@ -15,6 +15,7 @@ */ #include +#include #include #include #include @@ -29,6 +30,10 @@ using ::aidl::android::hardware::light::ILights; using ::aidl::android::hardware::light::LightType; using ::ndk::ScopedAStatus; using ::ndk::SharedRefBase; +using ::ndk::SpAIBinder; + +using aidl::com::google::hardware::pixel::display::IDisplay; +using PanelCalibrationStatus = aidl::com::google::hardware::pixel::display::PanelCalibrationStatus; static pthread_mutex_t g_lock = PTHREAD_MUTEX_INITIALIZER; @@ -79,10 +84,34 @@ static int sys_write_int(int fd, int value) { return amount == -1 ? -errno : 0; } +static SpAIBinder WaitForDisplayService() { + LOG(INFO) << "waiting for display service to appear"; + static std::mutex svc_mutex; + static SpAIBinder svc; + std::unique_lock l(svc_mutex); + uint8_t retrycount = 0; + + if (svc != nullptr && AIBinder_isAlive(svc.get())) return svc; + + while (true && retrycount < 20) { + svc = SpAIBinder(AServiceManager_waitForService( + "com.google.hardware.pixel.display.IDisplay/default")); + if (svc != nullptr) { + LOG(INFO) << "A wild display service has appeared!"; + return svc; + } + retrycount++; + sleep(2); + } + + LOG(ERROR) << "Failed to get the display service"; + return NULL; +} + class Lights : public BnLights { private: std::vector availableLights; - LedLutCalibrator calibrator; + LedLutCalibrator *calibrator; void addLight(LightType const type, int const ordinal) { HwLight light{}; @@ -117,12 +146,18 @@ class Lights : public BnLights { addLight(LightType::MICROPHONE, 0); addLight(LightType::CAMERA, 0); + SpAIBinder display_service = WaitForDisplayService(); + auto ser = IDisplay::fromBinder(display_service); + PanelCalibrationStatus cal; + ser->getPanelCalibrationStatus(&cal); + calibrator = new LedLutCalibrator(cal); + int cal_color = 0; - cal_color = calibrator.GetByColorIntensity("green", MODE_DAY); + cal_color = calibrator->GetByColorIntensity("green", MODE_DAY); if (cal_color >= 0) { pwmIds[0].pwm = cal_color; } - cal_color = calibrator.GetByColorIntensity("green", MODE_NIGHT); + cal_color = calibrator->GetByColorIntensity("green", MODE_NIGHT); if (cal_color >= 0) { pwmIds[1].pwm = cal_color << 1; pwmIds[2].pwm = cal_color; @@ -166,6 +201,11 @@ class Lights : public BnLights { int main() { ABinderProcess_setThreadPoolMaxThreadCount(0); + SpAIBinder display_service = WaitForDisplayService(); + if (display_service == nullptr) { + return -1; + } + std::shared_ptr light = SharedRefBase::make(); const std::string instance = std::string() + ILights::descriptor + "/default"; diff --git a/lights/led_golden_calibration_LUT_black_CG.txt b/lights/led_golden_calibration_LUT_black_CG.txt new file mode 100644 index 0000000..9160177 --- /dev/null +++ b/lights/led_golden_calibration_LUT_black_CG.txt @@ -0,0 +1,3 @@ +green:4095:2100 +green:0000:243 +green_cal:1 diff --git a/lights/led_golden_calibration_LUT_white_CG.txt b/lights/led_golden_calibration_LUT_white_CG.txt new file mode 100644 index 0000000..f316c09 --- /dev/null +++ b/lights/led_golden_calibration_LUT_white_CG.txt @@ -0,0 +1,3 @@ +green:4095:680 +green:0000:49 +green_cal:1 diff --git a/lights/led_lut_calibrator.cpp b/lights/led_lut_calibrator.cpp index 0668693..860615d 100644 --- a/lights/led_lut_calibrator.cpp +++ b/lights/led_lut_calibrator.cpp @@ -17,14 +17,20 @@ #include "led_lut_calibrator.h" #include +#include #include #include #include -const char kCalibrationPath[] = "/mnt/vendor/persist/led/led_calibration_LUT.txt"; +using ::android::base::GetProperty; -LedLutCalibrator::LedLutCalibrator() { +const char D_kCalibrationPath[] = "/mnt/vendor/persist/led/led_calibration_LUT.txt"; +const char G_WHT_kCalibrationPath[] = "/vendor/etc/led_golden_calibration_LUT_white_CG.txt"; +const char G_BLK_kCalibrationPath[] = "/vendor/etc/led_golden_calibration_LUT_black_CG.txt"; + +LedLutCalibrator::LedLutCalibrator(PanelCalibrationStatus status) { + cal_status_ = status; if (!ReadCalibrationTable()) { LOG(ERROR) << "Failed to read calibration table"; cal_table_.clear(); @@ -47,19 +53,35 @@ bool LedLutCalibrator::ReadCalibrationTable() { int fd; int bytes; bool ret = true; + const char *k_path = D_kCalibrationPath; std::vector buffer; buffer.resize(512); - fd = open(kCalibrationPath, O_RDONLY); + fd = open(D_kCalibrationPath, O_RDONLY); + // If default calibration not found or display changed, deploy golen calibration. + if (fd < 0 || cal_status_ == PanelCalibrationStatus::GOLDEN) { + // Using golden white calibration as default + // even though bezel prooerty not found. + k_path = G_WHT_kCalibrationPath; + std::string cdt_hwid = GetProperty("ro.boot.cdt_hwid", ""); + std::string hex_variant_str = cdt_hwid.substr(16, 2); + int bezel_color; + sscanf(hex_variant_str.c_str(), "%x", &bezel_color); + // 0: white, 2: black + if (bezel_color == 2) + k_path = G_BLK_kCalibrationPath; + } + + fd = open(k_path, O_RDONLY); if (fd < 0) { - LOG(ERROR) << "Failed to open " << kCalibrationPath; + LOG(ERROR) << "Failed to open " << k_path; ret = false; goto ReadCalibrationTable_err; } bytes = read(fd, buffer.data(), buffer.size()); if (bytes == -1) { - LOG(ERROR) << "Failed to read " << kCalibrationPath; + LOG(ERROR) << "Failed to read " << k_path; ret = false; goto ReadCalibrationTable_err; } diff --git a/lights/led_lut_calibrator.h b/lights/led_lut_calibrator.h index 3756e86..7fb0eaa 100644 --- a/lights/led_lut_calibrator.h +++ b/lights/led_lut_calibrator.h @@ -20,10 +20,13 @@ #include #include #include +#include + +using PanelCalibrationStatus = aidl::com::google::hardware::pixel::display::PanelCalibrationStatus; class LedLutCalibrator { public: - LedLutCalibrator(); + LedLutCalibrator(PanelCalibrationStatus status); LedLutCalibrator &operator=(const LedLutCalibrator &) = delete; ~LedLutCalibrator() = default; int GetByColorIntensity(const std::string &color, int intensity) const; @@ -34,6 +37,7 @@ class LedLutCalibrator { std::string MakeLutKey(const std::string &color, int intensity) const; std::unordered_map cal_table_; + PanelCalibrationStatus cal_status_; }; #endif // GOOGLE_TANGOTRON_LIGHTS_LED_LUT_CALIBRATOR_H_