blob: 125e6c6d2f42369cea6729665c2e1616d769db15 [file] [log] [blame]
Jack Wu024f2f52021-07-23 13:20:03 +08001/*
2 * Copyright (C) 2021 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#define LOG_TAG "pixelstats-uevent"
18
19#include <android-base/file.h>
20#include <android-base/logging.h>
21#include <android-base/parseint.h>
22#include <android-base/strings.h>
23#include <hardware/google/pixel/pixelstats/pixelatoms.pb.h>
24#include <log/log.h>
25#include <pixelstats/PcaChargeStats.h>
26
27namespace android {
28namespace hardware {
29namespace google {
30namespace pixel {
31
32using android::base::ReadFileToString;
33using android::base::WriteStringToFile;
34
35bool PcaChargeStats::CheckPcaContentsAndAck(std::string *file_contents) {
Jack Wu97c29d42022-06-14 17:42:58 +080036 std::string path = kPcaChargeMetricsPath;
Jack Wu024f2f52021-07-23 13:20:03 +080037 std::string line;
38 std::istringstream ss;
39
Jack Wu97c29d42022-06-14 17:42:58 +080040 if (!ReadFileToString(path.c_str(), file_contents)) {
41 path = kPca94xxChargeMetricsPath;
42 if (!ReadFileToString(path.c_str(), file_contents)) {
43 return false;
44 }
Jack Wu024f2f52021-07-23 13:20:03 +080045 }
46
47 ss.str(*file_contents);
48
49 if (!std::getline(ss, line)) {
Jack Wu97c29d42022-06-14 17:42:58 +080050 ALOGE("Unable to read first line %s - %s", path.c_str(), strerror(errno));
Jack Wu024f2f52021-07-23 13:20:03 +080051 return false;
52 }
Jack Wu97c29d42022-06-14 17:42:58 +080053 if (!WriteStringToFile(std::to_string(0), path.c_str())) {
54 ALOGE("Couldn't clear %s - %s", path.c_str(), strerror(errno));
Jack Wu024f2f52021-07-23 13:20:03 +080055 return false;
56 }
57 return true;
58}
59
Jack Wu97c29d42022-06-14 17:42:58 +080060PcaChargeStats::PcaChargeStats(const std::string pca_charge_metrics_path,
61 const std::string pca94xx_charge_metrics_path)
62 : kPcaChargeMetricsPath(pca_charge_metrics_path),
63 kPca94xxChargeMetricsPath(pca94xx_charge_metrics_path) {}
Jack Wu024f2f52021-07-23 13:20:03 +080064
65} // namespace pixel
66} // namespace google
67} // namespace hardware
68} // namespace android