• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 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 #ifndef HARDWARE_GOOGLE_PIXEL_HEALTH_CYCLECOUNTBACKUPRESTORE_H
18 #define HARDWARE_GOOGLE_PIXEL_HEALTH_CYCLECOUNTBACKUPRESTORE_H
19 
20 #include <android-base/file.h>
21 #include <android-base/logging.h>
22 #include <android-base/strings.h>
23 #include <string>
24 
25 namespace hardware {
26 namespace google {
27 namespace pixel {
28 namespace health {
29 
30 class CycleCountBackupRestore {
31   public:
32     CycleCountBackupRestore(int nb_buckets, const char *sysfs_path, const char *persist_path,
33                             const char *serial_path = "");
34     void Restore();
35     void Backup(int battery_level);
36 
37   private:
38     const char *kPersistSerial = "/persist/battery/serial_number";
39 
40     int nb_buckets_;
41     int *sw_bins_;
42     int *hw_bins_;
43     int saved_soc_;
44     int soc_inc_;
45     std::string sysfs_path_;
46     std::string persist_path_;
47     std::string serial_path_;
48 
49     void Read(const std::string &path, int *bins);
50     void Write(int *bins, const std::string &path);
51     void UpdateAndSave();
52     bool CheckSerial();
53 };
54 
55 }  // namespace health
56 }  // namespace pixel
57 }  // namespace google
58 }  // namespace hardware
59 
60 #endif  // #ifndef HARDWARE_GOOGLE_PIXEL_HEALTH_CYCLECOUNTBACKUPRESTORE_H
61