1 /*
2  * Copyright (C) 2017 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 #ifndef _UID_INFO_H_
17 #define _UID_INFO_H_
18 
19 #include <string>
20 #include <unordered_map>
21 
22 #include <binder/Parcelable.h>
23 
24 namespace android {
25 namespace os {
26 namespace storaged {
27 
28 enum uid_stat_t {
29     FOREGROUND = 0,
30     BACKGROUND = 1,
31     UID_STATS = 2
32 };
33 
34 enum charger_stat_t {
35     CHARGER_OFF = 0,
36     CHARGER_ON = 1,
37     CHARGER_STATS = 2
38 };
39 
40 enum io_type_t {
41     READ = 0,
42     WRITE = 1,
43     IO_TYPES = 2
44 };
45 
46 struct io_stats {
47     uint64_t rchar;                 // characters read
48     uint64_t wchar;                 // characters written
49     uint64_t read_bytes;            // bytes read (from storage layer)
50     uint64_t write_bytes;           // bytes written (to storage layer)
51     uint64_t fsync;                 // number of fsync syscalls
52 };
53 
54 class task_info {
55 public:
56     std::string comm;
57     pid_t pid;
58     io_stats io[UID_STATS];
59     bool parse_task_io_stats(std::string&& s);
60 };
61 
62 class UidInfo : public Parcelable {
63 public:
64     uint32_t uid;                     // user id
65     std::string name;                 // package name
66     io_stats io[UID_STATS];           // [0]:foreground [1]:background
67     std::unordered_map<uint32_t, task_info> tasks; // mapped from pid
68 
69     status_t writeToParcel(Parcel* parcel) const override;
70     status_t readFromParcel(const Parcel* parcel) override;
71 };
72 
73 } // namespace storaged
74 } // namespace os
75 } // namespace android
76 
77 #endif /*  _UID_INFO_H_ */