Merge "[Display] B5: Modify Brightness Settings" into rvc-dev
diff --git a/audio/cs35l41/R-cs35l41-dsp1-spk-prot.bin b/audio/cs35l41/R-cs35l41-dsp1-spk-prot.bin
index 1650b20..b4081bf 100644
--- a/audio/cs35l41/R-cs35l41-dsp1-spk-prot.bin
+++ b/audio/cs35l41/R-cs35l41-dsp1-spk-prot.bin
Binary files differ
diff --git a/audio/cs35l41/cs35l41-dsp1-spk-prot.bin b/audio/cs35l41/cs35l41-dsp1-spk-prot.bin
index 1cc6067..f8f4aeb 100644
--- a/audio/cs35l41/cs35l41-dsp1-spk-prot.bin
+++ b/audio/cs35l41/cs35l41-dsp1-spk-prot.bin
Binary files differ
diff --git a/bramble/BoardConfig.mk b/bramble/BoardConfig.mk
index 5b7e33a..0c7647e 100644
--- a/bramble/BoardConfig.mk
+++ b/bramble/BoardConfig.mk
@@ -18,8 +18,6 @@
 TARGET_SCREEN_DENSITY := 420
 TARGET_RECOVERY_UI_MARGIN_HEIGHT := 165
 
-CAMERA_VSYNC_COUNT := 2
-
 include device/google/redbull/BoardConfig-common.mk
 include device/google/bramble-sepolicy/bramble-sepolicy.mk
 
diff --git a/config.fs b/config.fs
index 4e916e4..fbe2dd7 100644
--- a/config.fs
+++ b/config.fs
@@ -71,12 +71,6 @@
 group: AID_RADIO
 caps: NET_BIND_SERVICE
 
-[vendor/bin/hw/android.hardware.health@2.0-service.bramble]
-mode: 0755
-user: AID_SYSTEM
-group: AID_SYSTEM
-caps: WAKE_ALARM
-
 [vendor/bin/loc_launcher]
 mode: 0755
 user:  AID_GPS
diff --git a/device-bramble.mk b/device-bramble.mk
index d2562d9..e98a7e0 100644
--- a/device-bramble.mk
+++ b/device-bramble.mk
@@ -94,7 +94,8 @@
     android.hardware.usb@1.2-service.bramble
 
 PRODUCT_PACKAGES += \
-    android.hardware.health@2.0-service.bramble
+    android.hardware.health@2.1-impl-bramble \
+    android.hardware.health@2.1-service
 
 # Vibrator HAL
 PRODUCT_PACKAGES += \
diff --git a/dumpstate/DumpstateDevice.cpp b/dumpstate/DumpstateDevice.cpp
index bd98a81..160fa0a 100755
--- a/dumpstate/DumpstateDevice.cpp
+++ b/dumpstate/DumpstateDevice.cpp
@@ -22,6 +22,7 @@
 #include <android-base/unique_fd.h>
 #include <cutils/properties.h>
 #include <hidl/HidlBinderSupport.h>
+#include <hidl/HidlSupport.h>
 
 #include <log/log.h>
 #include <pthread.h>
@@ -429,13 +430,20 @@
         return DumpstateStatus::ILLEGAL_ARGUMENT;
     }
 
-    if (mode == DumpstateMode::WEAR) {
+    bool isModeValid = false;
+    for (const auto dumpstateMode : hidl_enum_range<DumpstateMode>()) {
+        if (mode == dumpstateMode) {
+            isModeValid = true;
+            break;
+        }
+    }
+    if (!isModeValid) {
+        ALOGE("Invalid mode: %d\n", mode);
+        return DumpstateStatus::ILLEGAL_ARGUMENT;
+    } else if (mode == DumpstateMode::WEAR) {
         // We aren't a Wear device.
         ALOGE("Unsupported mode: %d\n", mode);
         return DumpstateStatus::UNSUPPORTED_MODE;
-    } else if (mode < DumpstateMode::FULL || mode > DumpstateMode::DEFAULT) {
-        ALOGE("Invalid mode: %d\n", mode);
-        return DumpstateStatus::ILLEGAL_ARGUMENT;
     }
 
     RunCommandToFd(fd, "Notify modem", {"/vendor/bin/modem_svc", "-s"}, CommandOptions::WithTimeout(1).Build());
diff --git a/health/Android.bp b/health/Android.bp
index affcf4f..b56e0ca 100644
--- a/health/Android.bp
+++ b/health/Android.bp
@@ -14,13 +14,14 @@
  * limitations under the License.
  */
 
-cc_binary {
-    name: "android.hardware.health@2.0-service.bramble",
-    init_rc: ["android.hardware.health@2.0-service.bramble.rc"],
+cc_library_shared {
+    name: "android.hardware.health@2.1-impl-bramble",
+    stem: "android.hardware.health@2.0-impl-2.1-bramble",
+
     proprietary: true,
     relative_install_path: "hw",
     srcs: [
-        "HealthService.cpp",
+        "Health.cpp",
     ],
 
     cflags: [
@@ -29,10 +30,10 @@
     ],
 
     static_libs: [
-        "android.hardware.health@2.0-impl",
         "android.hardware.health@1.0-convert",
-        "libhealthservice",
         "libbatterymonitor",
+        "libhealth2impl",
+        "libhealthloop",
     ],
 
     shared_libs: [
@@ -42,11 +43,6 @@
         "libpixelhealth",
         "libutils",
         "android.hardware.health@2.0",
-    ],
-
-    header_libs: ["libhealthd_headers"],
-
-    overrides: [
-        "healthd",
+        "android.hardware.health@2.1",
     ],
 }
diff --git a/health/Health.cpp b/health/Health.cpp
new file mode 100644
index 0000000..a561d32
--- /dev/null
+++ b/health/Health.cpp
@@ -0,0 +1,212 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#define LOG_TAG "android.hardware.health@2.1-impl-bramble"
+#include <android-base/logging.h>
+
+#include <android-base/file.h>
+#include <android-base/parseint.h>
+#include <android-base/strings.h>
+#include <android/hardware/health/2.0/types.h>
+#include <health2impl/Health.h>
+#include <health/utils.h>
+#include <hal_conversion.h>
+
+#include <pixelhealth/BatteryDefender.h>
+#include <pixelhealth/BatteryMetricsLogger.h>
+#include <pixelhealth/DeviceHealth.h>
+#include <pixelhealth/LowBatteryShutdownMetrics.h>
+
+#include <fstream>
+#include <iomanip>
+#include <string>
+#include <vector>
+
+namespace {
+
+using namespace std::literals;
+
+using android::hardware::health::V1_0::hal_conversion::convertFromHealthInfo;
+using android::hardware::health::V1_0::hal_conversion::convertToHealthInfo;
+using android::hardware::health::V2_0::DiskStats;
+using android::hardware::health::V2_0::StorageAttribute;
+using android::hardware::health::V2_0::StorageInfo;
+using android::hardware::health::V2_0::Result;
+using ::android::hardware::health::V2_1::IHealth;
+using android::hardware::health::InitHealthdConfig;
+
+using hardware::google::pixel::health::BatteryDefender;
+using hardware::google::pixel::health::BatteryMetricsLogger;
+using hardware::google::pixel::health::DeviceHealth;
+using hardware::google::pixel::health::LowBatteryShutdownMetrics;
+
+#define FG_DIR "/sys/class/power_supply"
+constexpr char kBatteryResistance[] {FG_DIR "/bms/resistance"};
+constexpr char kBatteryOCV[] {FG_DIR "/bms/voltage_ocv"};
+constexpr char kVoltageAvg[] {FG_DIR "/battery/voltage_now"};
+
+static BatteryDefender battDefender;
+static BatteryMetricsLogger battMetricsLogger(kBatteryResistance, kBatteryOCV);
+static LowBatteryShutdownMetrics shutdownMetrics(kVoltageAvg);
+static DeviceHealth deviceHealth;
+
+#define UFS_DIR "/sys/devices/platform/soc/1d84000.ufshc"
+constexpr char kUfsHealthEol[]{UFS_DIR "/health_descriptor/eol_info"};
+constexpr char kUfsHealthLifetimeA[]{UFS_DIR "/health_descriptor/life_time_estimation_a"};
+constexpr char kUfsHealthLifetimeB[]{UFS_DIR "/health_descriptor/life_time_estimation_b"};
+constexpr char kUfsVersion[]{UFS_DIR "/device_descriptor/specification_version"};
+constexpr char kDiskStatsFile[]{"/sys/block/sda/stat"};
+constexpr char kUFSName[]{"UFS0"};
+
+constexpr char kTCPMPSYName[]{"tcpm-source-psy-usbpd0"};
+
+std::ifstream assert_open(const std::string &path) {
+  std::ifstream stream(path);
+  if (!stream.is_open()) {
+    LOG(FATAL) << "Cannot read " << path;
+  }
+  return stream;
+}
+
+template <typename T>
+void read_value_from_file(const std::string &path, T *field) {
+  auto stream = assert_open(path);
+  stream.unsetf(std::ios_base::basefield);
+  stream >> *field;
+}
+
+void read_ufs_version(StorageInfo *info) {
+  uint64_t value;
+  read_value_from_file(kUfsVersion, &value);
+  std::stringstream ss;
+  ss << "ufs " << std::hex << value;
+  info->version = ss.str();
+}
+
+void fill_ufs_storage_attribute(StorageAttribute *attr) {
+  attr->isInternal = true;
+  attr->isBootDevice = true;
+  attr->name = kUFSName;
+}
+
+void private_healthd_board_init(struct healthd_config *hc) {
+  hc->ignorePowerSupplyNames.push_back(android::String8(kTCPMPSYName));
+  battDefender.update();
+}
+
+int private_healthd_board_battery_update(struct android::BatteryProperties *props) {
+  deviceHealth.update(props);
+  battMetricsLogger.logBatteryProperties(props);
+  shutdownMetrics.logShutdownVoltage(props);
+  battDefender.update();
+  return 0;
+}
+
+void private_get_storage_info(std::vector<StorageInfo> &vec_storage_info) {
+  vec_storage_info.resize(1);
+  StorageInfo *storage_info = &vec_storage_info[0];
+  fill_ufs_storage_attribute(&storage_info->attr);
+
+  read_ufs_version(storage_info);
+  read_value_from_file(kUfsHealthEol, &storage_info->eol);
+  read_value_from_file(kUfsHealthLifetimeA, &storage_info->lifetimeA);
+  read_value_from_file(kUfsHealthLifetimeB, &storage_info->lifetimeB);
+  return;
+}
+
+void private_get_disk_stats(std::vector<DiskStats> &vec_stats) {
+  vec_stats.resize(1);
+  DiskStats *stats = &vec_stats[0];
+  fill_ufs_storage_attribute(&stats->attr);
+
+  auto stream = assert_open(kDiskStatsFile);
+  // Regular diskstats entries
+  stream >> stats->reads >> stats->readMerges >> stats->readSectors >>
+      stats->readTicks >> stats->writes >> stats->writeMerges >>
+      stats->writeSectors >> stats->writeTicks >> stats->ioInFlight >>
+      stats->ioTicks >> stats->ioInQueue;
+  return;
+}
+}  // anonymous namespace
+
+namespace android {
+namespace hardware {
+namespace health {
+namespace V2_1 {
+namespace implementation {
+class HealthImpl : public Health {
+ public:
+  HealthImpl(std::unique_ptr<healthd_config>&& config)
+    : Health(std::move(config)) {}
+
+  Return<void> getStorageInfo(getStorageInfo_cb _hidl_cb) override;
+  Return<void> getDiskStats(getDiskStats_cb _hidl_cb) override;
+
+ protected:
+  void UpdateHealthInfo(HealthInfo* health_info) override;
+
+};
+
+void HealthImpl::UpdateHealthInfo(HealthInfo* health_info) {
+  struct BatteryProperties props;
+  convertFromHealthInfo(health_info->legacy.legacy, &props);
+  private_healthd_board_battery_update(&props);
+  convertToHealthInfo(&props, health_info->legacy.legacy);
+}
+
+Return<void> HealthImpl::getStorageInfo(getStorageInfo_cb _hidl_cb)
+{
+  std::vector<struct StorageInfo> info;
+  private_get_storage_info(info);
+  hidl_vec<struct StorageInfo> info_vec(info);
+  if (!info.size()) {
+      _hidl_cb(Result::NOT_SUPPORTED, info_vec);
+  } else {
+      _hidl_cb(Result::SUCCESS, info_vec);
+  }
+  return Void();
+}
+
+Return<void> HealthImpl::getDiskStats(getDiskStats_cb _hidl_cb)
+{
+  std::vector<struct DiskStats> stats;
+  private_get_disk_stats(stats);
+  hidl_vec<struct DiskStats> stats_vec(stats);
+  if (!stats.size()) {
+      _hidl_cb(Result::NOT_SUPPORTED, stats_vec);
+  } else {
+      _hidl_cb(Result::SUCCESS, stats_vec);
+  }
+  return Void();
+}
+
+}  // namespace implementation
+}  // namespace V2_1
+}  // namespace health
+}  // namespace hardware
+}  // namespace android
+
+extern "C" IHealth* HIDL_FETCH_IHealth(const char* instance) {
+  using ::android::hardware::health::V2_1::implementation::HealthImpl;
+  if (instance != "default"sv) {
+      return nullptr;
+  }
+  auto config = std::make_unique<healthd_config>();
+  InitHealthdConfig(config.get());
+
+  private_healthd_board_init(config.get());
+
+  return new HealthImpl(std::move(config));
+}
diff --git a/health/HealthService.cpp b/health/HealthService.cpp
deleted file mode 100644
index 067a91a..0000000
--- a/health/HealthService.cpp
+++ /dev/null
@@ -1,121 +0,0 @@
-/*
- * Copyright (C) 2018 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#define LOG_TAG "android.hardware.health@2.0-service.bramble"
-#include <android-base/logging.h>
-
-#include <android-base/file.h>
-#include <android-base/parseint.h>
-#include <android-base/strings.h>
-#include <health2/Health.h>
-#include <health2/service.h>
-#include <healthd/healthd.h>
-#include <hidl/HidlTransportSupport.h>
-#include <pixelhealth/BatteryMetricsLogger.h>
-#include <pixelhealth/DeviceHealth.h>
-#include <pixelhealth/LowBatteryShutdownMetrics.h>
-
-#include <fstream>
-#include <iomanip>
-#include <string>
-#include <vector>
-
-namespace {
-
-using android::hardware::health::V2_0::DiskStats;
-using android::hardware::health::V2_0::StorageAttribute;
-using android::hardware::health::V2_0::StorageInfo;
-using hardware::google::pixel::health::BatteryMetricsLogger;
-using hardware::google::pixel::health::DeviceHealth;
-using hardware::google::pixel::health::LowBatteryShutdownMetrics;
-
-#define FG_DIR "/sys/class/power_supply"
-constexpr char kBatteryResistance[] {FG_DIR "/bms/resistance"};
-constexpr char kBatteryOCV[] {FG_DIR "/bms/voltage_ocv"};
-constexpr char kVoltageAvg[] {FG_DIR "/battery/voltage_now"};
-
-static BatteryMetricsLogger battMetricsLogger(kBatteryResistance, kBatteryOCV);
-static LowBatteryShutdownMetrics shutdownMetrics(kVoltageAvg);
-static DeviceHealth deviceHealth;
-
-#define UFS_DIR "/sys/devices/platform/soc/1d84000.ufshc"
-constexpr char kUfsHealthEol[]{UFS_DIR "/health_descriptor/eol_info"};
-constexpr char kUfsHealthLifetimeA[]{UFS_DIR "/health_descriptor/life_time_estimation_a"};
-constexpr char kUfsHealthLifetimeB[]{UFS_DIR "/health_descriptor/life_time_estimation_b"};
-constexpr char kDiskStatsFile[]{"/sys/block/sda/stat"};
-constexpr char kUFSName[]{"UFS0"};
-
-constexpr char kTCPMPSYName[]{"tcpm-source-psy-usbpd0"};
-
-std::ifstream assert_open(const std::string &path) {
-  std::ifstream stream(path);
-  if (!stream.is_open()) {
-    LOG(FATAL) << "Cannot read " << path;
-  }
-  return stream;
-}
-
-template <typename T>
-void read_value_from_file(const std::string &path, T *field) {
-  auto stream = assert_open(path);
-  stream.unsetf(std::ios_base::basefield);
-  stream >> *field;
-}
-
-void fill_ufs_storage_attribute(StorageAttribute *attr) {
-  attr->isInternal = true;
-  attr->isBootDevice = true;
-  attr->name = kUFSName;
-}
-
-}  // anonymous namespace
-
-void healthd_board_init(struct healthd_config *hc) {
-  hc->ignorePowerSupplyNames.push_back(android::String8(kTCPMPSYName));
-}
-
-int healthd_board_battery_update(struct android::BatteryProperties *props) {
-  deviceHealth.update(props);
-  battMetricsLogger.logBatteryProperties(props);
-  shutdownMetrics.logShutdownVoltage(props);
-  return 0;
-}
-
-void get_storage_info(std::vector<StorageInfo> &vec_storage_info) {
-  vec_storage_info.resize(1);
-  StorageInfo *storage_info = &vec_storage_info[0];
-  fill_ufs_storage_attribute(&storage_info->attr);
-
-  read_value_from_file(kUfsHealthEol, &storage_info->eol);
-  read_value_from_file(kUfsHealthLifetimeA, &storage_info->lifetimeA);
-  read_value_from_file(kUfsHealthLifetimeB, &storage_info->lifetimeB);
-  return;
-}
-
-void get_disk_stats(std::vector<DiskStats> &vec_stats) {
-  vec_stats.resize(1);
-  DiskStats *stats = &vec_stats[0];
-  fill_ufs_storage_attribute(&stats->attr);
-
-  auto stream = assert_open(kDiskStatsFile);
-  // Regular diskstats entries
-  stream >> stats->reads >> stats->readMerges >> stats->readSectors >>
-      stats->readTicks >> stats->writes >> stats->writeMerges >>
-      stats->writeSectors >> stats->writeTicks >> stats->ioInFlight >>
-      stats->ioTicks >> stats->ioInQueue;
-  return;
-}
-
-int main(void) { return health_service_main(); }
diff --git a/health/android.hardware.health@2.0-service.bramble.rc b/health/android.hardware.health@2.0-service.bramble.rc
deleted file mode 100644
index 7026c5b..0000000
--- a/health/android.hardware.health@2.0-service.bramble.rc
+++ /dev/null
@@ -1,5 +0,0 @@
-service vendor.health-hal-2-0 /vendor/bin/hw/android.hardware.health@2.0-service.bramble
-    class hal
-    user system
-    group system
-    file /dev/kmsg w
diff --git a/vibrator/drv2624/Vibrator.cpp b/vibrator/drv2624/Vibrator.cpp
index 1811c9f..494b4f9 100644
--- a/vibrator/drv2624/Vibrator.cpp
+++ b/vibrator/drv2624/Vibrator.cpp
@@ -57,7 +57,7 @@
 static constexpr std::array<float, 5> EFFECT_TARGET_G = {0.175, 0.325, 0.37, 0.475, 0.6};
 static constexpr std::array<float, 3> STEADY_TARGET_G = {1.38, 1.145, 0.905};
 
-#define FLOAT_EPS 1e-6
+#define FLOAT_EPS 1e-7
 
 static std::uint32_t freqPeriodFormula(std::uint32_t in) {
     return 1000000000 / (24615 * in);