Merge changes Ic8ff7f34,Ibe4ba3d6
* changes:
Enable MS OS descriptors for adb.
Remove uses of sprintf.
diff --git a/atrace/Android.bp b/atrace/Android.bp
index 560f47b..8ddb7c8 100644
--- a/atrace/Android.bp
+++ b/atrace/Android.bp
@@ -29,7 +29,6 @@
"libbase",
"libutils",
"libhidlbase",
- "libhidltransport",
"android.hardware.atrace@1.0",
],
}
diff --git a/fastboot/Android.bp b/fastboot/Android.bp
index 72ade19..646c0a9 100644
--- a/fastboot/Android.bp
+++ b/fastboot/Android.bp
@@ -24,7 +24,6 @@
shared_libs: [
"libbase",
"libhidlbase",
- "libhidltransport",
"libutils",
"libcutils",
"android.hardware.fastboot@1.0",
diff --git a/health/Android.bp b/health/Android.bp
index 256bf12..46a0a4d 100644
--- a/health/Android.bp
+++ b/health/Android.bp
@@ -29,8 +29,6 @@
"libbase",
"libcutils",
"libhidlbase",
- "libhidltransport",
- "libhwbinder",
"libutils",
],
}
diff --git a/health/BatteryMetricsLogger.cpp b/health/BatteryMetricsLogger.cpp
index b5e8991..58c6b58 100644
--- a/health/BatteryMetricsLogger.cpp
+++ b/health/BatteryMetricsLogger.cpp
@@ -28,19 +28,20 @@
using android::frameworks::stats::V1_0::IStats;
BatteryMetricsLogger::BatteryMetricsLogger(const char *const batt_res, const char *const batt_ocv,
- int sample_period, int upload_period)
+ const char *const batt_avg_res, int sample_period,
+ int upload_period)
: kBatteryResistance(batt_res),
kBatteryOCV(batt_ocv),
+ kBatteryAvgResistance(batt_avg_res),
kSamplePeriod(sample_period),
kUploadPeriod(upload_period),
kMaxSamples(upload_period / sample_period) {
last_sample_ = 0;
last_upload_ = 0;
- num_res_samples_ = 0;
num_samples_ = 0;
+ num_res_samples_ = 0;
memset(min_, 0, sizeof(min_));
memset(max_, 0, sizeof(max_));
- accum_resistance_ = 0;
}
int64_t BatteryMetricsLogger::getTime(void) {
@@ -77,9 +78,39 @@
return true;
}
+bool BatteryMetricsLogger::uploadAverageBatteryResistance(sp<IStats> stats_client) {
+ if (strlen(kBatteryAvgResistance) == 0) {
+ LOG(INFO) << "Sysfs path for average battery resistance not specified";
+ return true;
+ }
+
+ std::string file_content;
+ int32_t batt_avg_res;
+
+ if (!android::base::ReadFileToString(kBatteryAvgResistance, &file_content)) {
+ LOG(ERROR) << "Can't read " << kBatteryAvgResistance;
+ return false;
+ }
+ std::stringstream ss(file_content);
+ if (!(ss >> batt_avg_res)) {
+ LOG(ERROR) << "Can't parse average battery resistance " << file_content;
+ return false;
+ }
+ // Upload average metric
+ BatteryHealthSnapshotArgs avg_res_ss_stats = {
+ .type = BatteryHealthSnapshotArgs::BatterySnapshotType::AVG_RESISTANCE,
+ .temperatureDeciC = 0,
+ .voltageMicroV = 0,
+ .currentMicroA = 0,
+ .openCircuitVoltageMicroV = 0,
+ .resistanceMicroOhm = batt_avg_res,
+ .levelPercent = 0};
+ stats_client->reportBatteryHealthSnapshot(avg_res_ss_stats);
+ return true;
+}
+
bool BatteryMetricsLogger::uploadMetrics(void) {
int64_t time = getTime();
- int32_t avg_resistance = 0;
if (last_sample_ == 0)
return false;
@@ -87,11 +118,6 @@
LOG(INFO) << "Uploading metrics at time " << std::to_string(time) << " w/ "
<< std::to_string(num_samples_) << " samples";
- if (num_res_samples_)
- avg_resistance = accum_resistance_ / num_res_samples_;
-
- LOG(INFO) << "Logging metrics";
-
sp<IStats> stats_client = IStats::tryGetService();
if (!stats_client) {
LOG(ERROR) << "Unable to connect to Stats service";
@@ -114,26 +140,14 @@
uploadOutlierMetric(stats_client, static_cast<sampleType>(metric));
}
- // Upload average metric
- BatteryHealthSnapshotArgs avg_res_ss_stats = {
- .type = BatteryHealthSnapshotArgs::BatterySnapshotType::AVG_RESISTANCE,
- .temperatureDeciC = 0,
- .voltageMicroV = 0,
- .currentMicroA = 0,
- .openCircuitVoltageMicroV = 0,
- .resistanceMicroOhm = avg_resistance,
- .levelPercent = 0};
- if (num_res_samples_) {
- stats_client->reportBatteryHealthSnapshot(avg_res_ss_stats);
- }
+ uploadAverageBatteryResistance(stats_client);
// Clear existing data
memset(min_, 0, sizeof(min_));
memset(max_, 0, sizeof(max_));
- num_res_samples_ = 0;
num_samples_ = 0;
+ num_res_samples_ = 0;
last_upload_ = time;
- accum_resistance_ = 0;
LOG(INFO) << "Finished uploading to tron";
return true;
}
@@ -146,17 +160,19 @@
LOG(INFO) << "Recording a sample at time " << std::to_string(time);
if (!android::base::ReadFileToString(kBatteryResistance, &resistance_str)) {
- LOG(ERROR) << "Can't read the battery resistance";
- resistance = 0;
- } else if (!(resistance = stoi(resistance_str))) {
+ LOG(ERROR) << "Can't read the battery resistance from " << kBatteryResistance;
+ resistance = -INT_MAX;
+ } else if (!(std::stringstream(resistance_str) >> resistance)) {
LOG(ERROR) << "Can't parse battery resistance value " << resistance_str;
+ resistance = -INT_MAX;
}
if (!android::base::ReadFileToString(kBatteryOCV, &ocv_str)) {
- LOG(ERROR) << "Can't read the open-circuit voltage (ocv) value";
- ocv = 0;
- } else if (!(ocv = stoi(ocv_str))) {
+ LOG(ERROR) << "Can't read open-circuit voltage (ocv) value from " << kBatteryOCV;
+ ocv = -INT_MAX;
+ } else if (!(std::stringstream(ocv_str) >> ocv)) {
LOG(ERROR) << "Can't parse open-circuit voltage (ocv) value " << ocv_str;
+ ocv = -INT_MAX;
}
int32_t sample[NUM_FIELDS] = {[TIME] = time,
@@ -167,7 +183,6 @@
[SOC] = props->batteryLevel,
[OCV] = ocv};
if (props->batteryStatus != android::BATTERY_STATUS_CHARGING) {
- accum_resistance_ += resistance;
num_res_samples_++;
}
diff --git a/health/include/pixelhealth/BatteryMetricsLogger.h b/health/include/pixelhealth/BatteryMetricsLogger.h
index bf1d840..790a6ed 100644
--- a/health/include/pixelhealth/BatteryMetricsLogger.h
+++ b/health/include/pixelhealth/BatteryMetricsLogger.h
@@ -20,13 +20,13 @@
#include <android-base/file.h>
#include <android-base/logging.h>
#include <android-base/strings.h>
+#include <android/frameworks/stats/1.0/IStats.h>
#include <batteryservice/BatteryService.h>
#include <math.h>
#include <time.h>
#include <utils/Timers.h>
-#include <string>
-#include <android/frameworks/stats/1.0/IStats.h>
+#include <string>
namespace hardware {
namespace google {
@@ -40,7 +40,8 @@
class BatteryMetricsLogger {
public:
BatteryMetricsLogger(const char *const batt_res, const char *const batt_ocv,
- int sample_period = TEN_MINUTES_SEC, int upload_period = ONE_DAY_SEC);
+ const char *const batt_avg_res = "", int sample_period = TEN_MINUTES_SEC,
+ int upload_period = ONE_DAY_SEC);
void logBatteryProperties(struct android::BatteryProperties *props);
private:
@@ -67,6 +68,7 @@
const char *const kBatteryResistance;
const char *const kBatteryOCV;
+ const char *const kBatteryAvgResistance;
const int kSamplePeriod;
const int kUploadPeriod;
const int kMaxSamples;
@@ -78,16 +80,16 @@
// min[TYPE][TYPE] is the reading of that type at that minimum event
int32_t min_[NUM_FIELDS][NUM_FIELDS];
int32_t max_[NUM_FIELDS][NUM_FIELDS];
- int32_t num_res_samples_; // number of res samples since last upload
- int32_t num_samples_; // number of min/max samples since last upload
- int64_t accum_resistance_; // accumulative resistance
- int64_t last_sample_; // time in seconds since boot of last sample
- int64_t last_upload_; // time in seconds since boot of last upload
+ int32_t num_res_samples_; // number of res samples since last upload
+ int32_t num_samples_; // number of min/max samples since last upload
+ int64_t last_sample_; // time in seconds since boot of last sample
+ int64_t last_upload_; // time in seconds since boot of last upload
int64_t getTime();
bool recordSample(struct android::BatteryProperties *props);
bool uploadMetrics();
bool uploadOutlierMetric(sp<IStats> stats_client, sampleType type);
+ bool uploadAverageBatteryResistance(sp<IStats> stats_client);
};
} // namespace health
diff --git a/misc_writer/Android.bp b/misc_writer/Android.bp
new file mode 100644
index 0000000..73c44d2
--- /dev/null
+++ b/misc_writer/Android.bp
@@ -0,0 +1,110 @@
+//
+// Copyright (C) 2019 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.
+//
+
+cc_defaults {
+ name: "misc_writer_defaults",
+ vendor: true,
+ cpp_std: "experimental",
+
+ cflags: [
+ "-Wall",
+ "-Werror",
+ ],
+
+ shared_libs: [
+ "libbase",
+ ],
+
+ static_libs: [
+ "libbootloader_message_vendor",
+ "libfstab",
+ ],
+}
+
+// TODO(xunchang) Remove duplicates after we convert the device specific librecovery_ui to recovery
+// module. Then libmisc_writer can build as a vendor module available in recovery.
+cc_library_static {
+ name: "libmisc_writer",
+ cpp_std: "experimental",
+
+ cflags: [
+ "-Wall",
+ "-Werror",
+ ],
+
+ shared_libs: [
+ "libbase",
+ ],
+
+ static_libs: [
+ "libbootloader_message",
+ "libfstab",
+ ],
+
+ srcs: [
+ "misc_writer.cpp",
+ ],
+
+ export_include_dirs: [
+ "include",
+ ],
+}
+
+cc_library_static {
+ name: "libmisc_writer_vendor",
+ defaults: [
+ "misc_writer_defaults",
+ ],
+
+ srcs: [
+ "misc_writer.cpp",
+ ],
+
+ export_include_dirs: [
+ "include",
+ ],
+}
+
+cc_binary {
+ name: "misc_writer",
+ defaults: [
+ "misc_writer_defaults",
+ ],
+
+ srcs: [
+ "misc_writer_main.cpp",
+ ],
+
+ static_libs: [
+ "libmisc_writer_vendor",
+ ]
+}
+
+cc_test {
+ name: "misc_writer_test",
+ defaults: [
+ "misc_writer_defaults",
+ ],
+
+ srcs: [
+ "misc_writer_test.cpp",
+ ],
+ test_suites: ["device-tests"],
+
+ static_libs: [
+ "libmisc_writer_vendor",
+ ]
+}
diff --git a/misc_writer/include/misc_writer/misc_writer.h b/misc_writer/include/misc_writer/misc_writer.h
new file mode 100644
index 0000000..6a32ffe
--- /dev/null
+++ b/misc_writer/include/misc_writer/misc_writer.h
@@ -0,0 +1,66 @@
+/*
+ * Copyright (C) 2019 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.
+ */
+
+#pragma once
+
+#include <stddef.h>
+#include <stdint.h>
+
+#include <optional>
+#include <string>
+
+namespace android {
+namespace hardware {
+namespace google {
+namespace pixel {
+
+enum class MiscWriterActions : int32_t {
+ kSetDarkThemeFlag = 0,
+ kClearDarkThemeFlag,
+ kSetSotaFlag,
+ kClearSotaFlag,
+
+ kUnset = -1,
+};
+
+class MiscWriter {
+ public:
+ static constexpr uint32_t kThemeFlagOffsetInVendorSpace = 0;
+ static constexpr char kDarkThemeFlag[] = "theme-dark";
+ static constexpr uint32_t kSotaFlagOffsetInVendorSpace = 32;
+ static constexpr char kSotaFlag[] = "enable-sota";
+
+ // Returns true of |size| bytes data starting from |offset| is fully inside the vendor space.
+ static bool OffsetAndSizeInVendorSpace(size_t offset, size_t size);
+ // Writes the given data to the vendor space in /misc partition, at the given offset. Note that
+ // offset is in relative to the start of the vendor space.
+ static bool WriteMiscPartitionVendorSpace(const void* data, size_t size, size_t offset,
+ std::string* err);
+
+ explicit MiscWriter(const MiscWriterActions& action) : action_(action) {}
+
+ // Performs the stored MiscWriterActions. If |override_offset| is set, writes to the input offset
+ // in the vendor space of /misc instead of the default offset.
+ bool PerformAction(std::optional<size_t> override_offset = std::nullopt);
+
+ private:
+ MiscWriterActions action_{ MiscWriterActions::kUnset };
+};
+
+} // namespace pixel
+} // namespace google
+} // namespace hardware
+} // namespace android
diff --git a/misc_writer/misc_writer.cpp b/misc_writer/misc_writer.cpp
new file mode 100644
index 0000000..bf589d3
--- /dev/null
+++ b/misc_writer/misc_writer.cpp
@@ -0,0 +1,83 @@
+/*
+ * Copyright (C) 2019 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.
+ */
+
+#include "misc_writer/misc_writer.h"
+
+#include <string.h>
+
+#include <android-base/file.h>
+#include <android-base/logging.h>
+#include <android-base/stringprintf.h>
+#include <bootloader_message/bootloader_message.h>
+
+namespace android {
+namespace hardware {
+namespace google {
+namespace pixel {
+
+bool MiscWriter::OffsetAndSizeInVendorSpace(size_t offset, size_t size) {
+ auto total_size = WIPE_PACKAGE_OFFSET_IN_MISC - VENDOR_SPACE_OFFSET_IN_MISC;
+ return size <= total_size && offset <= total_size - size;
+}
+
+bool MiscWriter::WriteMiscPartitionVendorSpace(const void* data, size_t size, size_t offset,
+ std::string* err) {
+ if (!OffsetAndSizeInVendorSpace(offset, size)) {
+ *err = android::base::StringPrintf("Out of bound write (offset %zu size %zu)", offset, size);
+ return false;
+ }
+ auto misc_blk_device = get_misc_blk_device(err);
+ if (misc_blk_device.empty()) {
+ return false;
+ }
+ return write_misc_partition(data, size, misc_blk_device, VENDOR_SPACE_OFFSET_IN_MISC + offset,
+ err);
+}
+
+bool MiscWriter::PerformAction(std::optional<size_t> override_offset) {
+ size_t offset = 0;
+ std::string content;
+ switch (action_) {
+ case MiscWriterActions::kSetDarkThemeFlag:
+ case MiscWriterActions::kClearDarkThemeFlag:
+ offset = override_offset.value_or(kThemeFlagOffsetInVendorSpace);
+ content = (action_ == MiscWriterActions::kSetDarkThemeFlag)
+ ? kDarkThemeFlag
+ : std::string(strlen(kDarkThemeFlag), 0);
+ break;
+ case MiscWriterActions::kSetSotaFlag:
+ case MiscWriterActions::kClearSotaFlag:
+ offset = override_offset.value_or(kSotaFlagOffsetInVendorSpace);
+ content = (action_ == MiscWriterActions::kSetSotaFlag) ? kSotaFlag
+ : std::string(strlen(kSotaFlag), 0);
+ break;
+ case MiscWriterActions::kUnset:
+ LOG(ERROR) << "The misc writer action must be set";
+ return false;
+ }
+
+ if (std::string err;
+ !WriteMiscPartitionVendorSpace(content.data(), content.size(), offset, &err)) {
+ LOG(ERROR) << "Failed to write " << content << " at offset " << offset << " : " << err;
+ return false;
+ }
+ return true;
+}
+
+} // namespace pixel
+} // namespace google
+} // namespace hardware
+} // namespace android
diff --git a/misc_writer/misc_writer_main.cpp b/misc_writer/misc_writer_main.cpp
new file mode 100644
index 0000000..69a9fe3
--- /dev/null
+++ b/misc_writer/misc_writer_main.cpp
@@ -0,0 +1,109 @@
+/*
+ * Copyright (C) 2019 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.
+ */
+
+#include <getopt.h>
+#include <stdint.h>
+#include <stdlib.h>
+
+#include <iostream>
+#include <map>
+#include <memory>
+#include <optional>
+#include <string>
+#include <string_view>
+
+#include <android-base/logging.h>
+#include <android-base/parseint.h>
+
+#include "misc_writer/misc_writer.h"
+
+using namespace std::string_literals;
+using android::hardware::google::pixel::MiscWriter;
+using android::hardware::google::pixel::MiscWriterActions;
+
+static int Usage(std::string_view name) {
+ std::cerr << name << " usage:\n";
+ std::cerr << name << " [--override-vendor-space-offset <offset>] --<misc_writer_action>\n";
+ std::cerr << "Supported misc_writer_action is one of: \n";
+ std::cerr << " --set-dark-theme Write the dark theme flag\n";
+ std::cerr << " --clear-dark-theme Clear the dark theme flag\n";
+ std::cerr << " --set-sota Write the silent OTA flag\n";
+ std::cerr << " --clear-sota Clear the silent OTA flag\n";
+ std::cerr << "Writes the given hex string to the specified offset in vendor space in /misc "
+ "partition.\nDefault offset is used for each action unless "
+ "--override-vendor-space-offset is specified.\n";
+ return EXIT_FAILURE;
+}
+
+// misc_writer is a vendor tool that writes data to the vendor space in /misc.
+int main(int argc, char** argv) {
+ constexpr struct option OPTIONS[] = {
+ { "set-dark-theme", no_argument, nullptr, 0 },
+ { "clear-dark-theme", no_argument, nullptr, 0 },
+ { "set-sota", no_argument, nullptr, 0 },
+ { "clear-sota", no_argument, nullptr, 0 },
+ { "override-vendor-space-offset", required_argument, nullptr, 0 },
+ { nullptr, 0, nullptr, 0 },
+ };
+
+ std::map<std::string, MiscWriterActions> action_map{
+ { "set-dark-theme", MiscWriterActions::kSetDarkThemeFlag },
+ { "clear-dark-theme", MiscWriterActions::kClearDarkThemeFlag },
+ { "set-sota", MiscWriterActions::kSetSotaFlag },
+ { "clear-sota", MiscWriterActions::kClearSotaFlag },
+ };
+
+ std::unique_ptr<MiscWriter> misc_writer;
+ std::optional<size_t> override_offset;
+
+ int arg;
+ int option_index = 0;
+ while ((arg = getopt_long(argc, argv, "", OPTIONS, &option_index)) != -1) {
+ if (arg != 0) {
+ LOG(ERROR) << "Invalid command argument";
+ return Usage(argv[0]);
+ }
+ auto option_name = OPTIONS[option_index].name;
+ if (option_name == "override-vendor-space-offset"s) {
+ LOG(WARNING) << "Overriding the vendor space offset in misc partition to " << optarg;
+ size_t offset;
+ if (!android::base::ParseUint(optarg, &offset)) {
+ LOG(ERROR) << "Failed to parse the offset: " << optarg;
+ return Usage(argv[0]);
+ }
+ override_offset = offset;
+ } else if (auto iter = action_map.find(option_name); iter != action_map.end()) {
+ if (misc_writer) {
+ LOG(ERROR) << "Misc writer action has already been set";
+ return Usage(argv[0]);
+ }
+ misc_writer = std::make_unique<MiscWriter>(iter->second);
+ } else {
+ LOG(FATAL) << "Unreachable path, option_name: " << option_name;
+ }
+ }
+
+ if (!misc_writer) {
+ LOG(ERROR) << "An action must be specified for misc writer";
+ return Usage(argv[0]);
+ }
+
+ if (!misc_writer->PerformAction(override_offset)) {
+ return EXIT_FAILURE;
+ }
+
+ return EXIT_SUCCESS;
+}
diff --git a/misc_writer/misc_writer_test.cpp b/misc_writer/misc_writer_test.cpp
new file mode 100644
index 0000000..e8b207a
--- /dev/null
+++ b/misc_writer/misc_writer_test.cpp
@@ -0,0 +1,140 @@
+/*
+ * Copyright (C) 2016 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.
+ */
+
+#include <memory>
+#include <string>
+#include <string_view>
+#include <vector>
+
+#include <android-base/file.h>
+#include <bootloader_message/bootloader_message.h>
+#include <gtest/gtest.h>
+
+#include "misc_writer/misc_writer.h"
+
+using namespace std::string_literals;
+
+namespace android {
+namespace hardware {
+namespace google {
+namespace pixel {
+
+class MiscWriterTest : public ::testing::Test {
+ protected:
+ void TearDown() override {
+ // Clear the vendor space.
+ auto zeros = std::string(WIPE_PACKAGE_OFFSET_IN_MISC - VENDOR_SPACE_OFFSET_IN_MISC, 0);
+ std::string err;
+ ASSERT_TRUE(MiscWriter::WriteMiscPartitionVendorSpace(zeros.data(), zeros.size(), 0, &err))
+ << err;
+ }
+
+ void CheckMiscPartitionVendorSpaceContent(size_t offset, const std::string& expected);
+
+ std::unique_ptr<MiscWriter> misc_writer_;
+};
+
+void MiscWriterTest::CheckMiscPartitionVendorSpaceContent(size_t offset,
+ const std::string& expected) {
+ ASSERT_TRUE(MiscWriter::OffsetAndSizeInVendorSpace(offset, expected.size()));
+ std::string err;
+ auto misc_blk_device = get_misc_blk_device(&err);
+ ASSERT_FALSE(misc_blk_device.empty());
+ android::base::unique_fd fd(open(misc_blk_device.c_str(), O_RDONLY));
+ ASSERT_NE(-1, fd);
+
+ std::string content(expected.size(), 0);
+ ASSERT_TRUE(android::base::ReadFullyAtOffset(fd, content.data(), content.size(),
+ VENDOR_SPACE_OFFSET_IN_MISC + offset));
+ ASSERT_EQ(expected, content);
+}
+
+TEST_F(MiscWriterTest, SetClearDarkTheme) {
+ misc_writer_ = std::make_unique<MiscWriter>(MiscWriterActions::kSetDarkThemeFlag);
+ ASSERT_TRUE(misc_writer_);
+ ASSERT_TRUE(misc_writer_->PerformAction());
+ std::string expected = "theme-dark";
+ CheckMiscPartitionVendorSpaceContent(0, expected);
+
+ misc_writer_ = std::make_unique<MiscWriter>(MiscWriterActions::kClearDarkThemeFlag);
+ ASSERT_TRUE(misc_writer_->PerformAction());
+ std::string zeros(expected.size(), 0);
+ CheckMiscPartitionVendorSpaceContent(0, zeros);
+}
+
+TEST_F(MiscWriterTest, SetClearDarkTheme_OffsetOverride) {
+ misc_writer_ = std::make_unique<MiscWriter>(MiscWriterActions::kSetDarkThemeFlag);
+ size_t offset = 12360;
+ ASSERT_TRUE(misc_writer_->PerformAction(offset));
+ std::string expected = "theme-dark";
+ CheckMiscPartitionVendorSpaceContent(offset, expected);
+
+ misc_writer_ = std::make_unique<MiscWriter>(MiscWriterActions::kClearDarkThemeFlag);
+ ASSERT_TRUE(misc_writer_->PerformAction(offset));
+ std::string zeros(expected.size(), 0);
+ CheckMiscPartitionVendorSpaceContent(offset, zeros);
+}
+
+TEST_F(MiscWriterTest, SetClearSota) {
+ misc_writer_ = std::make_unique<MiscWriter>(MiscWriterActions::kSetSotaFlag);
+ ASSERT_TRUE(misc_writer_);
+ ASSERT_TRUE(misc_writer_->PerformAction());
+ std::string expected = "enable-sota";
+ CheckMiscPartitionVendorSpaceContent(32, expected);
+
+ // Test we can write to the override offset.
+ size_t override_offset = 12360;
+ ASSERT_FALSE(misc_writer_->PerformAction(override_offset));
+ CheckMiscPartitionVendorSpaceContent(override_offset, expected);
+
+ misc_writer_ = std::make_unique<MiscWriter>(MiscWriterActions::kClearSotaFlag);
+ ASSERT_TRUE(misc_writer_->PerformAction());
+ std::string zeros(expected.size(), 0);
+ CheckMiscPartitionVendorSpaceContent(32, zeros);
+}
+
+TEST_F(MiscWriterTest, WriteMiscPartitionVendorSpace) {
+ std::string kTestMessage = "kTestMessage";
+ std::string err;
+ ASSERT_TRUE(
+ MiscWriter::WriteMiscPartitionVendorSpace(kTestMessage.data(), kTestMessage.size(), 0, &err));
+
+ CheckMiscPartitionVendorSpaceContent(0, kTestMessage);
+
+ // Write with an offset.
+ ASSERT_TRUE(MiscWriter::WriteMiscPartitionVendorSpace("\x00\x00", 2, 5, &err));
+ CheckMiscPartitionVendorSpaceContent(0, "kTest\x00\x00ssage"s);
+
+ // Write with the right size.
+ auto start_offset =
+ WIPE_PACKAGE_OFFSET_IN_MISC - VENDOR_SPACE_OFFSET_IN_MISC - kTestMessage.size();
+ ASSERT_TRUE(MiscWriter::WriteMiscPartitionVendorSpace(kTestMessage.data(), kTestMessage.size(),
+ start_offset, &err));
+
+ // Out-of-bound write.
+ ASSERT_FALSE(MiscWriter::WriteMiscPartitionVendorSpace(kTestMessage.data(), kTestMessage.size(),
+ start_offset + 1, &err));
+
+ // Message won't fit.
+ std::string long_message(WIPE_PACKAGE_OFFSET_IN_MISC - VENDOR_SPACE_OFFSET_IN_MISC + 1, 'a');
+ ASSERT_FALSE(
+ MiscWriter::WriteMiscPartitionVendorSpace(long_message.data(), long_message.size(), 0, &err));
+}
+
+} // namespace pixel
+} // namespace google
+} // namespace hardware
+} // namespace android
diff --git a/perfstatsd/Android.bp b/perfstatsd/Android.bp
index a65d1a9..541aff7 100644
--- a/perfstatsd/Android.bp
+++ b/perfstatsd/Android.bp
@@ -22,7 +22,6 @@
"libbinder",
"libcutils",
"libhidlbase",
- "libhwbinder",
"liblog",
"libutils",
],
diff --git a/perfstatsd/cpu_usage.cpp b/perfstatsd/cpu_usage.cpp
index 6bbeb2d..5a26ace 100644
--- a/perfstatsd/cpu_usage.cpp
+++ b/perfstatsd/cpu_usage.cpp
@@ -51,22 +51,22 @@
key == CPU_TOPCOUNT) {
uint32_t val = 0;
if (!base::ParseUint(value, &val)) {
- LOG_TO(SYSTEM, ERROR) << "Invalid value: " << value;
+ LOG(ERROR) << "Invalid value: " << value;
return;
}
if (key == PROCPROF_THRESHOLD) {
mProfileThreshold = val;
- LOG_TO(SYSTEM, INFO) << "set profile threshold " << mProfileThreshold;
+ LOG(INFO) << "set profile threshold " << mProfileThreshold;
} else if (key == CPU_DISABLED) {
mDisabled = (val != 0);
- LOG_TO(SYSTEM, INFO) << "set disabled " << mDisabled;
+ LOG(INFO) << "set disabled " << mDisabled;
} else if (key == CPU_DEBUG) {
cDebug = (val != 0);
- LOG_TO(SYSTEM, INFO) << "set debug " << cDebug;
+ LOG(INFO) << "set debug " << cDebug;
} else if (key == CPU_TOPCOUNT) {
mTopcount = val;
- LOG_TO(SYSTEM, INFO) << "set top count " << mTopcount;
+ LOG(INFO) << "set top count " << mTopcount;
}
}
}
@@ -98,7 +98,7 @@
!base::ParseUint(fields[14], &stime) ||
!base::ParseUint(fields[15], &cutime) ||
!base::ParseUint(fields[16], &cstime)) {
- LOG_TO(SYSTEM, ERROR) << "Invalid proc data\n" << pidStat;
+ LOG(ERROR) << "Invalid proc data\n" << pidStat;
continue;
}
std::string proc = fields[1];
@@ -120,10 +120,10 @@
float usageRatio = (float)(diffUsage * 100.0 / mDiffCpu);
if (cDebug && usageRatio > 100) {
- LOG_TO(SYSTEM, INFO) << "pid: " << pid << " , ratio: " << usageRatio
- << " , prev usage: " << mPrevProcdata[pid].usage
- << " , cur usage: " << totalUsage
- << " , total cpu diff: " << mDiffCpu;
+ LOG(INFO) << "pid: " << pid << " , ratio: " << usageRatio
+ << " , prev usage: " << mPrevProcdata[pid].usage
+ << " , cur usage: " << totalUsage
+ << " , total cpu diff: " << mDiffCpu;
}
ProcData data;
@@ -147,7 +147,7 @@
}
closedir(dir);
} else {
- LOG_TO(SYSTEM, ERROR) << "Fail to open /proc/";
+ LOG(ERROR) << "Fail to open /proc/";
}
}
@@ -186,7 +186,7 @@
!base::ParseUint(fields[base + 5], &irq) ||
!base::ParseUint(fields[base + 6], &softirq) ||
!base::ParseUint(fields[base + 7], &steal)) {
- LOG_TO(SYSTEM, ERROR) << "Invalid /proc/stat data\n" << line;
+ LOG(ERROR) << "Invalid /proc/stat data\n" << line;
continue;
}
@@ -207,10 +207,9 @@
float ioRatio = (float)(diffIo * 100.0 / mDiffCpu);
if (cDebug) {
- LOG_TO(SYSTEM, INFO)
- << "prev total: " << mPrevUsage.cpuUsage
- << " , cur total: " << cpuUsage << " , diffusage: " << diffUsage
- << " , diffcpu: " << mDiffCpu << " , ratio: " << mTotalRatio;
+ LOG(INFO) << "prev total: " << mPrevUsage.cpuUsage
+ << " , cur total: " << cpuUsage << " , diffusage: " << diffUsage
+ << " , diffcpu: " << mDiffCpu << " , ratio: " << mTotalRatio;
}
mPrevUsage.cpuUsage = cpuUsage;
@@ -227,16 +226,18 @@
// calculate total cpu usage of each core
uint32_t c = 0;
if (!base::ParseUint(core, &c)) {
- LOG_TO(SYSTEM, ERROR) << "Invalid core: " << core;
+ LOG(ERROR) << "Invalid core: " << core;
continue;
}
uint64_t diffUsage = cpuUsage - mPrevCoresUsage[c].cpuUsage;
float coreTotalRatio = (float)(diffUsage * 100.0 / mDiffCpu);
if (cDebug) {
- LOG_TO(SYSTEM, INFO)
- << "core " << c << " , prev cpu usage: " << mPrevCoresUsage[c].cpuUsage
- << " , cur cpu usage: " << cpuUsage << " , diffusage: " << diffUsage
- << " , difftotalcpu: " << mDiffCpu << " , ratio: " << coreTotalRatio;
+ LOG(INFO) << "core " << c
+ << " , prev cpu usage: " << mPrevCoresUsage[c].cpuUsage
+ << " , cur cpu usage: " << cpuUsage
+ << " , diffusage: " << diffUsage
+ << " , difftotalcpu: " << mDiffCpu
+ << " , ratio: " << coreTotalRatio;
}
mPrevCoresUsage[c].cpuUsage = cpuUsage;
@@ -248,7 +249,7 @@
}
out->append("\n");
} else {
- LOG_TO(SYSTEM, ERROR) << "Fail to read /proc/stat";
+ LOG(ERROR) << "Fail to read /proc/stat";
}
}
@@ -263,7 +264,7 @@
if (mTotalRatio >= mProfileThreshold) {
if (cDebug)
- LOG_TO(SYSTEM, INFO) << "Total CPU usage over " << mProfileThreshold << "%";
+ LOG(INFO) << "Total CPU usage over " << mProfileThreshold << "%";
std::string profileResult;
profileProcess(&profileResult);
if (mProfileProcess) {
@@ -279,6 +280,6 @@
if (cDebug) {
auto ms = std::chrono::duration_cast<std::chrono::milliseconds>(
std::chrono::system_clock::now() - now);
- LOG_TO(SYSTEM, INFO) << "Took " << ms.count() << " ms, data bytes: " << out.length();
+ LOG(INFO) << "Took " << ms.count() << " ms, data bytes: " << out.length();
}
}
diff --git a/perfstatsd/include/io_usage.h b/perfstatsd/include/io_usage.h
index 49232ad..e96ca37 100644
--- a/perfstatsd/include/io_usage.h
+++ b/perfstatsd/include/io_usage.h
@@ -118,7 +118,7 @@
if (!mDisabled) {
std::string msg;
dump(&msg);
- LOG_TO(SYSTEM, INFO) << msg;
+ LOG(INFO) << msg;
}
}
void setEnabled(bool enabled) { mDisabled = !enabled; }
diff --git a/perfstatsd/io_usage.cpp b/perfstatsd/io_usage.cpp
index 7c06791..a325bef 100644
--- a/perfstatsd/io_usage.cpp
+++ b/perfstatsd/io_usage.cpp
@@ -97,7 +97,7 @@
DIR *dir;
struct dirent *ent;
if ((dir = opendir("/proc/")) == NULL) {
- LOG_TO(SYSTEM, ERROR) << "failed on opendir '/proc/'";
+ LOG(ERROR) << "failed on opendir '/proc/'";
return;
}
while ((ent = readdir(dir)) != NULL) {
@@ -113,12 +113,12 @@
for (int i = 0, len = newpids.size(); i < len; i++) {
uint32_t pid = newpids[i];
if (sOptDebug > 1)
- LOG_TO(SYSTEM, INFO) << i << ".";
+ LOG(INFO) << i << ".";
std::string buffer;
if (!android::base::ReadFileToString("/proc/" + std::to_string(pid) + "/status", &buffer)) {
if (sOptDebug)
- LOG_TO(SYSTEM, INFO) << "/proc/" << std::to_string(pid) << "/status"
- << ": ReadFileToString failed (process died?)";
+ LOG(INFO) << "/proc/" << std::to_string(pid) << "/status"
+ << ": ReadFileToString failed (process died?)";
continue;
}
// --- Find Name ---
@@ -154,8 +154,8 @@
std::string strUid(buffer, s, e - s);
if (sOptDebug > 1)
- LOG_TO(SYSTEM, INFO) << "(pid, name, uid)=(" << pid << ", " << pname << ", " << strUid
- << ")" << std::endl;
+ LOG(INFO) << "(pid, name, uid)=(" << pid << ", " << pname << ", " << strUid << ")"
+ << std::endl;
uint32_t uid = (uint32_t)std::stoi(strUid);
mUidNameMapping[uid] = pname;
}
@@ -207,7 +207,7 @@
std::string pname;
if (!mProcIoStats.getNameForUid(uid, &pname)) {
if (sOptDebug)
- LOG_TO(SYSTEM, WARNING) << "unable to find App uid:" << uid;
+ LOG(WARNING) << "unable to find App uid:" << uid;
continue;
}
mUidNameMap[uid] = pname;
@@ -216,7 +216,7 @@
passwd *usrpwd = getpwuid(uid);
if (!usrpwd) {
if (sOptDebug)
- LOG_TO(SYSTEM, WARNING) << "unable to find uid:" << uid << " by getpwuid";
+ LOG(WARNING) << "unable to find uid:" << uid << " by getpwuid";
continue;
}
mUidNameMap[uid] = std::string(usrpwd->pw_name);
@@ -234,7 +234,7 @@
for (const auto &i : mUnknownUidList) {
msg << i << ", ";
}
- LOG_TO(SYSTEM, WARNING) << msg.str();
+ LOG(WARNING) << msg.str();
}
mUnknownUidList.clear();
}
@@ -320,12 +320,10 @@
char readTotal[32];
char writeTotal[32];
if (!formatNum(mTotal.sumRead(), readTotal, 32)) {
- LOG_TO(SYSTEM, ERROR) << "formatNum buffer size is too small for read: "
- << mTotal.sumRead();
+ LOG(ERROR) << "formatNum buffer size is too small for read: " << mTotal.sumRead();
}
if (!formatNum(mTotal.sumWrite(), writeTotal, 32)) {
- LOG_TO(SYSTEM, ERROR) << "formatNum buffer size is too small for write: "
- << mTotal.sumWrite();
+ LOG(ERROR) << "formatNum buffer size is too small for write: " << mTotal.sumWrite();
}
out << android::base::StringPrintf(FMT_STR_TOTAL_USAGE, ms.count() / 1000, ms.count() % 1000,
@@ -385,7 +383,7 @@
!android::base::ParseUint(fields[8], &data.bgWrite) ||
!android::base::ParseUint(fields[9], &data.fgFsync) ||
!android::base::ParseUint(fields[10], &data.bgFsync)) {
- LOG_TO(SYSTEM, WARNING) << "Invalid uid I/O stats: \"" << line << "\"";
+ LOG(WARNING) << "Invalid uid I/O stats: \"" << line << "\"";
return false;
}
return true;
@@ -416,7 +414,7 @@
uint64_t val = 0;
if (!android::base::ParseUint(value, &val)) {
out << "!!!! unable to parse value to uint64";
- LOG_TO(SYSTEM, ERROR) << out.str();
+ LOG(ERROR) << out.str();
return;
}
if (key == "iostats.min") {
@@ -431,7 +429,7 @@
} else if (key == "iostats.debug") {
sOptDebug = (val != 0);
}
- LOG_TO(SYSTEM, INFO) << out.str() << ": Success";
+ LOG(INFO) << out.str() << ": Success";
}
}
@@ -442,10 +440,10 @@
_debugTimer.setEnabled(sOptDebug);
std::string buffer;
if (!android::base::ReadFileToString(UID_IO_STATS_PATH, &buffer)) {
- LOG_TO(SYSTEM, ERROR) << UID_IO_STATS_PATH << ": ReadFileToString failed";
+ LOG(ERROR) << UID_IO_STATS_PATH << ": ReadFileToString failed";
}
if (sOptDebug)
- LOG_TO(SYSTEM, INFO) << "read " << UID_IO_STATS_PATH << " OK.";
+ LOG(INFO) << "read " << UID_IO_STATS_PATH << " OK.";
std::vector<std::string> lines = android::base::Split(std::move(buffer), "\n");
std::unordered_map<uint32_t, UserIo> datas;
for (uint32_t i = 0; i < lines.size(); i++) {
@@ -462,8 +460,8 @@
mStats.dump(&out);
const std::string &str = out.str();
if (sOptDebug) {
- LOG_TO(SYSTEM, INFO) << str;
- LOG_TO(SYSTEM, INFO) << "output append length:" << str.length();
+ LOG(INFO) << str;
+ LOG(INFO) << "output append length:" << str.length();
}
append((std::string &)str);
}
diff --git a/perfstatsd/main.cpp b/perfstatsd/main.cpp
index fc05484..16fc20e 100644
--- a/perfstatsd/main.cpp
+++ b/perfstatsd/main.cpp
@@ -24,7 +24,7 @@
android::sp<Perfstatsd> perfstatsdSp;
void *perfstatsdMain(void *) {
- LOG_TO(SYSTEM, INFO) << "main thread started";
+ LOG(INFO) << "main thread started";
perfstatsdSp = new Perfstatsd();
while (true) {
@@ -49,7 +49,7 @@
pthread_t perfstatsdMainThread;
errno = pthread_create(&perfstatsdMainThread, NULL, perfstatsdMain, NULL);
if (errno != 0) {
- PLOG_TO(SYSTEM, ERROR) << "Failed to create main thread";
+ PLOG(ERROR) << "Failed to create main thread";
return -1;
} else {
pthread_setname_np(perfstatsdMainThread, "perfstatsd_main");
@@ -58,10 +58,10 @@
android::ProcessState::initWithDriver("/dev/vndbinder");
if (PerfstatsdPrivateService::start() != android::OK) {
- PLOG_TO(SYSTEM, ERROR) << "Failed to start perfstatsd service";
+ PLOG(ERROR) << "Failed to start perfstatsd service";
return -1;
} else
- LOG_TO(SYSTEM, INFO) << "perfstatsd_pri_service started";
+ LOG(INFO) << "perfstatsd_pri_service started";
android::ProcessState::self()->startThreadPool();
android::IPCThreadState::self()->joinThreadPool();
@@ -74,7 +74,7 @@
android::sp<IPerfstatsdPrivate> perfstatsdPrivateService = getPerfstatsdPrivateService();
if (perfstatsdPrivateService == NULL) {
- PLOG_TO(SYSTEM, ERROR) << "Cannot find perfstatsd service.";
+ PLOG(ERROR) << "Cannot find perfstatsd service.";
fprintf(stdout, "Cannot find perfstatsd service.\n");
return -1;
}
@@ -82,9 +82,9 @@
switch (mode) {
case DUMP_HISTORY: {
std::string history;
- LOG_TO(SYSTEM, INFO) << "dump perfstats history.";
+ LOG(INFO) << "dump perfstats history.";
if (!perfstatsdPrivateService->dumpHistory(&history).isOk() || history.empty()) {
- PLOG_TO(SYSTEM, ERROR) << "perf stats history is not available";
+ PLOG(ERROR) << "perf stats history is not available";
fprintf(stdout, "perf stats history is not available\n");
return -1;
}
@@ -92,12 +92,12 @@
break;
}
case SET_OPTION:
- LOG_TO(SYSTEM, INFO) << "set option: " << key << " , " << value;
+ LOG(INFO) << "set option: " << key << " , " << value;
if (!perfstatsdPrivateService
->setOptions(std::forward<const std::string>(key),
std::forward<const std::string>(value))
.isOk()) {
- PLOG_TO(SYSTEM, ERROR) << "fail to set options";
+ PLOG(ERROR) << "fail to set options";
fprintf(stdout, "fail to set options\n");
return -1;
}
@@ -112,6 +112,8 @@
}
int main(int argc, char **argv) {
+ android::base::InitLogging(argv, android::base::LogdLogger(android::base::SYSTEM));
+
int c;
while ((c = getopt(argc, argv, "sdo:h")) != -1) {
switch (c) {
diff --git a/perfstatsd/perfstatsd.cpp b/perfstatsd/perfstatsd.cpp
index 6a16e47..60836c5 100644
--- a/perfstatsd/perfstatsd.cpp
+++ b/perfstatsd/perfstatsd.cpp
@@ -64,18 +64,17 @@
}
if (ret->size() > 400_KiB)
- LOG_TO(SYSTEM, WARNING) << "Data might be too large. size: " << ret->size() << " bytes\n"
- << *ret;
+ LOG(WARNING) << "Data might be too large. size: " << ret->size() << " bytes\n" << *ret;
}
void Perfstatsd::setOptions(const std::string &key, const std::string &value) {
if (key == PERFSTATSD_PERIOD) {
uint32_t val = 0;
if (!base::ParseUint(value, &val) || val < 1) {
- LOG_TO(SYSTEM, ERROR) << "Invalid value. Minimum refresh period is 1 second";
+ LOG(ERROR) << "Invalid value. Minimum refresh period is 1 second";
} else {
mRefreshPeriod = val;
- LOG_TO(SYSTEM, INFO) << "set period to " << value << " seconds";
+ LOG(INFO) << "set period to " << value << " seconds";
}
return;
}
diff --git a/pixelstats/Android.bp b/pixelstats/Android.bp
index 48c946d..d0627aa 100644
--- a/pixelstats/Android.bp
+++ b/pixelstats/Android.bp
@@ -34,6 +34,7 @@
srcs: [
"pixelatoms.proto",
],
+ sdk_version: "current",
}
cc_library {
@@ -56,7 +57,6 @@
"libbinder",
"libcutils",
"libhidlbase",
- "libhidltransport",
"liblog",
"libutils",
"pixelatoms-cpp",
diff --git a/pixelstats/UeventListener.cpp b/pixelstats/UeventListener.cpp
index 312a8e5..4614293 100644
--- a/pixelstats/UeventListener.cpp
+++ b/pixelstats/UeventListener.cpp
@@ -32,6 +32,7 @@
using android::sp;
using android::base::ReadFileToString;
+using android::base::WriteStringToFile;
using android::frameworks::stats::V1_0::HardwareFailed;
using android::frameworks::stats::V1_0::IStats;
using android::frameworks::stats::V1_0::UsbPortOverheatEvent;
@@ -231,6 +232,10 @@
return;
}
+ if (!WriteStringToFile(kChargeMetricsPath.c_str(), std::to_string(0))) {
+ ALOGE("Couldn't clear %s", kChargeMetricsPath.c_str());
+ }
+
sp<IStats> stats_client = IStats::tryGetService();
if (!stats_client) {
ALOGE("Couldn't connect to IStats service");
diff --git a/pixelstats/pixelatoms.proto b/pixelstats/pixelatoms.proto
index ab6509f..804a952 100644
--- a/pixelstats/pixelatoms.proto
+++ b/pixelstats/pixelatoms.proto
@@ -62,10 +62,10 @@
ADAPTER_TYPE_USB_PD_BRICKID = 10;
ADAPTER_TYPE_HVDCP = 11;
ADAPTER_TYPE_HVDCP3 = 12;
- ADAPTER_TYPE_WLC = 13;
- ADAPTER_TYPE_WLC_EPP = 14;
- ADAPTER_TYPE_WLC_SPP = 15;
- ADAPTER_TYPE_FLOAT = 16;
+ ADAPTER_TYPE_FLOAT = 13;
+ ADAPTER_TYPE_WLC = 14;
+ ADAPTER_TYPE_WLC_EPP = 15;
+ ADAPTER_TYPE_WLC_SPP = 16;
}
/* Type of charge adapter, enumerated above. */
optional AdapterType adapter_type = 2;
diff --git a/power-libperfmgr/Android.bp b/power-libperfmgr/Android.bp
index 7874d10..ca2aeda 100644
--- a/power-libperfmgr/Android.bp
+++ b/power-libperfmgr/Android.bp
@@ -33,7 +33,6 @@
shared_libs: [
"libbase",
"libhidlbase",
- "libhidltransport",
"liblog",
"libutils",
"libcutils",
diff --git a/power-libperfmgr/CameraMode.h b/power-libperfmgr/CameraMode.h
index 6558ce8..1e05623 100644
--- a/power-libperfmgr/CameraMode.h
+++ b/power-libperfmgr/CameraMode.h
@@ -21,7 +21,9 @@
CAMERA_STREAMING_OFF = 0,
CAMERA_STREAMING,
CAMERA_STREAMING_1080P,
+ CAMERA_STREAMING_60FPS,
CAMERA_STREAMING_4K,
+ CAMERA_STREAMING_SECURE,
CAMERA_STREAMING_MAX
};
diff --git a/power-libperfmgr/Power.cpp b/power-libperfmgr/Power.cpp
index aca64ca..f199bfb 100644
--- a/power-libperfmgr/Power.cpp
+++ b/power-libperfmgr/Power.cpp
@@ -51,10 +51,12 @@
constexpr char kPowerHalConfigPath[] = "/vendor/etc/powerhint.json";
static const std::map<enum CameraStreamingMode, std::string> kCamStreamingHint = {
- {CAMERA_STREAMING_OFF, "CAMERA_STREAMING_OFF"},
- {CAMERA_STREAMING, "CAMERA_STREAMING"},
- {CAMERA_STREAMING_1080P, "CAMERA_STREAMING_1080P"},
- {CAMERA_STREAMING_4K, "CAMERA_STREAMING_4K"}};
+ {CAMERA_STREAMING_OFF, "CAMERA_STREAMING_OFF"},
+ {CAMERA_STREAMING, "CAMERA_STREAMING"},
+ {CAMERA_STREAMING_1080P, "CAMERA_STREAMING_1080P"},
+ {CAMERA_STREAMING_60FPS, "CAMERA_STREAMING_60FPS"},
+ {CAMERA_STREAMING_4K, "CAMERA_STREAMING_4K"},
+ {CAMERA_STREAMING_SECURE, "CAMERA_STREAMING_SECURE"}};
Power::Power()
: mHintManager(nullptr),
@@ -80,10 +82,18 @@
ALOGI("Initialize CAMERA_STREAMING_1080P on");
mHintManager->DoHint("CAMERA_STREAMING_1080P");
mCameraStreamingMode = CAMERA_STREAMING_1080P;
+ } else if (state == "CAMERA_STREAMING_60FPS") {
+ ALOGI("Initialize CAMERA_STREAMING_60FPS on");
+ mHintManager->DoHint("CAMERA_STREAMING_60FPS");
+ mCameraStreamingMode = CAMERA_STREAMING_60FPS;
} else if (state == "CAMERA_STREAMING_4K") {
ALOGI("Initialize with CAMERA_STREAMING_4K on");
mHintManager->DoHint("CAMERA_STREAMING_4K");
mCameraStreamingMode = CAMERA_STREAMING_4K;
+ } else if (state == "CAMERA_STREAMING_SECURE") {
+ ALOGI("Initialize with CAMERA_STREAMING_SECURE on");
+ mHintManager->DoHint("CAMERA_STREAMING_SECURE");
+ mCameraStreamingMode = CAMERA_STREAMING_SECURE;
} else if (state == "SUSTAINED_PERFORMANCE") {
ALOGI("Initialize with SUSTAINED_PERFORMANCE on");
mHintManager->DoHint("SUSTAINED_PERFORMANCE");
@@ -289,8 +299,10 @@
if ((mCameraStreamingMode != CAMERA_STREAMING_OFF)) {
const auto modeValue = kCamStreamingHint.at(mCameraStreamingMode);
mHintManager->EndHint(modeValue);
- // Boost 1s for tear down
- mHintManager->DoHint("CAMERA_LAUNCH", std::chrono::seconds(1));
+ if ((mCameraStreamingMode != CAMERA_STREAMING_SECURE)) {
+ // Boost 1s for tear down if not secure streaming use case
+ mHintManager->DoHint("CAMERA_LAUNCH", std::chrono::seconds(1));
+ }
}
if (mode != CAMERA_STREAMING_OFF) {
diff --git a/power-libperfmgr/android.hardware.power@1.3-service.pixel-libperfmgr.rc b/power-libperfmgr/android.hardware.power@1.3-service.pixel-libperfmgr.rc
index fa00587..6179f6e 100644
--- a/power-libperfmgr/android.hardware.power@1.3-service.pixel-libperfmgr.rc
+++ b/power-libperfmgr/android.hardware.power@1.3-service.pixel-libperfmgr.rc
@@ -2,6 +2,7 @@
class hal
user root
group system
+ priority -20
interface android.hardware.power@1.0::IPower default
interface android.hardware.power@1.1::IPower default
interface android.hardware.power@1.2::IPower default
diff --git a/power-libperfmgr/service.cpp b/power-libperfmgr/service.cpp
index a64761c..7bcc907 100644
--- a/power-libperfmgr/service.cpp
+++ b/power-libperfmgr/service.cpp
@@ -41,7 +41,7 @@
ALOGE("Can not create an instance of Power HAL Iface, exiting.");
return 1;
}
-
+ android::hardware::setMinSchedulerPolicy(service, SCHED_NORMAL, -20);
configureRpcThreadpool(1, true /*callerWillJoin*/);
status_t status = service->registerAsService();
diff --git a/recovery/Android.bp b/recovery/Android.bp
new file mode 100644
index 0000000..d904e8e
--- /dev/null
+++ b/recovery/Android.bp
@@ -0,0 +1,25 @@
+cc_library_static {
+ name: "librecovery_ui_pixel",
+ owner: "google",
+ cflags: [
+ "-Wall",
+ "-Wextra",
+ "-Werror",
+ "-pedantic",
+ ],
+ srcs: [
+ "recovery_ui.cpp",
+ ],
+
+ whole_static_libs: [
+ "libmisc_writer",
+ "libbootloader_message",
+ "libnos_for_recovery",
+ "libnos_citadel_for_recovery",
+ ],
+
+ shared_libs: [
+ "libbase",
+ "librecovery_ui",
+ ],
+}
diff --git a/recovery/recovery_ui.cpp b/recovery/recovery_ui.cpp
new file mode 100644
index 0000000..f404f93
--- /dev/null
+++ b/recovery/recovery_ui.cpp
@@ -0,0 +1,133 @@
+/*
+ * Copyright (C) 2019 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.
+ */
+
+#include <stdint.h>
+#include <string.h>
+
+#include <string>
+#include <string_view>
+#include <vector>
+
+#include <android-base/endian.h>
+#include <android-base/logging.h>
+#include <android-base/strings.h>
+#include <app_nugget.h>
+#include <misc_writer/misc_writer.h>
+#include <nos/NuggetClient.h>
+#include <nos/debug.h>
+#include <recovery_ui/device.h>
+#include <recovery_ui/screen_ui.h>
+
+namespace android {
+namespace hardware {
+namespace google {
+namespace pixel {
+
+namespace {
+
+/** Wipe user data from Titan M. */
+bool WipeTitanM() {
+ // Connect to Titan M
+ ::nos::NuggetClient client;
+ client.Open();
+ if (!client.IsOpen()) {
+ LOG(ERROR) << "Failed to connect to Titan M";
+ return false;
+ }
+
+ // Tell it to wipe user data
+ const uint32_t magicValue = htole32(ERASE_CONFIRMATION);
+ std::vector<uint8_t> magic(sizeof(magicValue));
+ memcpy(magic.data(), &magicValue, sizeof(magicValue));
+ const uint32_t status
+ = client.CallApp(APP_ID_NUGGET, NUGGET_PARAM_NUKE_FROM_ORBIT, magic, nullptr);
+ if (status != APP_SUCCESS) {
+ LOG(ERROR) << "Titan M user data wipe failed: " << ::nos::StatusCodeString(status)
+ << " (" << status << ")";
+ return false;
+ }
+
+ LOG(INFO) << "Titan M wipe successful";
+ return true;
+}
+
+// Wipes the provisioned flag as part of data wipe.
+bool WipeProvisionedFlag() {
+ // Must be consistent with the one in init.hardware.rc (10-byte `theme-dark`).
+ MiscWriter misc_writer(MiscWriterActions::kClearDarkThemeFlag);
+ if (!misc_writer.PerformAction()) {
+ LOG(ERROR) << "Failed to clear the dark theme flag";
+ return false;
+ }
+ LOG(INFO) << "Provisioned flag wiped successful";
+ return true;
+}
+
+// Provision Silent OTA(SOTA) flag while reason is "enable-sota"
+bool ProvisionSilentOtaFlag(const std::string& reason) {
+ if (android::base::StartsWith(reason, MiscWriter::kSotaFlag)) {
+ MiscWriter misc_writer(MiscWriterActions::kSetSotaFlag);
+ if (!misc_writer.PerformAction()) {
+ LOG(ERROR) << "Failed to set the silent ota flag";
+ return false;
+ }
+ LOG(INFO) << "Silent ota flag set successful";
+ }
+ return true;
+}
+
+} // namespace
+
+class PixelDevice : public ::Device {
+ public:
+ explicit PixelDevice(::ScreenRecoveryUI* const ui) : ::Device(ui) {}
+
+ /** Hook to wipe user data not stored in /data */
+ bool PostWipeData() override {
+ // Try to do everything but report a failure if anything wasn't successful
+ bool totalSuccess = true;
+ ::RecoveryUI* const ui = GetUI();
+
+ ui->Print("Wiping Titan M...\n");
+ if (!WipeTitanM()) {
+ totalSuccess = false;
+ }
+
+ if (!WipeProvisionedFlag()) {
+ totalSuccess = false;
+ }
+
+ // Extendable to wipe other components
+
+ // Additional behavior along with wiping data
+ auto reason = GetReason();
+ CHECK(reason.has_value());
+ if (!ProvisionSilentOtaFlag(reason.value())) {
+ totalSuccess = false;
+ }
+
+ return totalSuccess;
+ }
+};
+
+} // namespace pixel
+} // namespace google
+} // namespace hardware
+} // namespace android
+
+Device *make_device() {
+ return new ::android::hardware::google::pixel::PixelDevice(new ::ScreenRecoveryUI);
+}
diff --git a/thermal/Android.bp b/thermal/Android.bp
index 60d1c70..dce083b 100644
--- a/thermal/Android.bp
+++ b/thermal/Android.bp
@@ -17,14 +17,11 @@
"utils/thermal_files.cpp",
"utils/thermal_watcher.cpp",
],
- static_libs: [
- "libjsoncpp",
- ],
shared_libs: [
"libbase",
"libcutils",
"libhidlbase",
- "libhidltransport",
+ "libjsoncpp",
"libutils",
"android.hardware.thermal@1.0",
"android.hardware.thermal@2.0",
diff --git a/thermal/android.hardware.thermal@2.0-service.pixel.rc b/thermal/android.hardware.thermal@2.0-service.pixel.rc
index 27fc14a..fd2735b 100644
--- a/thermal/android.hardware.thermal@2.0-service.pixel.rc
+++ b/thermal/android.hardware.thermal@2.0-service.pixel.rc
@@ -1,4 +1,5 @@
service vendor.thermal-hal-2-0 /vendor/bin/hw/android.hardware.thermal@2.0-service.pixel
+ interface android.hardware.thermal@1.0::IThermal default
interface android.hardware.thermal@2.0::IThermal default
class hal
user system
diff --git a/usb/Android.bp b/usb/Android.bp
index 6df6c36..2290918 100644
--- a/usb/Android.bp
+++ b/usb/Android.bp
@@ -34,8 +34,6 @@
"libbase",
"libcutils",
"libhidlbase",
- "libhidltransport",
- "libhwbinder",
"libutils",
],
}