1/*
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
17syntax = "proto2";
18package android.os;
19
20option java_multiple_files = true;
21
22import "frameworks/proto_logging/stats/enums/os/enums.proto";
23
24// This message is used for statsd logging and should be kept in sync with
25// frameworks/proto_logging/stats/atoms.proto
26/**
27 * Represents a device's BatteryUsageStats, with power usage information about the device
28 * and each app.
29 */
30message BatteryUsageStatsAtomsProto {
31
32    // The session start timestamp in UTC milliseconds since January 1, 1970, per Date#getTime().
33    // All data is no older than this time.
34    optional int64 session_start_millis = 1;
35
36    // The session end timestamp in UTC milliseconds since January 1, 1970, per Date#getTime().
37    // All data is no more recent than this time.
38    optional int64 session_end_millis = 2;
39
40    // Length that the reported data covered. This usually will be equal to the entire session,
41    // session_end_millis - session_start_millis, but may not be if some data during this time frame
42    // is missing.
43    optional int64 session_duration_millis = 3;
44
45    // Represents usage of a consumer, storing all of its power component usage.
46    message BatteryConsumerData {
47        // Total power consumed by this BatteryConsumer (including all of its PowerComponents).
48        // May not equal the sum of the PowerComponentUsage due to under- or over-estimations.
49        // Multiply by 1/36 to obtain mAh.
50        optional int64 total_consumed_power_deci_coulombs = 1;
51
52        // Represents power and time usage of a particular power component.
53        message PowerComponentUsage {
54            // Holds android.os.PowerComponentEnum, or custom component value between 1000 and 9999.
55            // Evidently, if one attempts to write an int to an enum field that is out of range, it
56            // is treated as 0, so we must make this an int32.
57            optional int32 component = 1;
58
59            // Power consumed by this component. Multiply by 1/36 to obtain mAh.
60            optional int64 power_deci_coulombs = 2;
61
62            optional int64 duration_millis = 3;
63        }
64        repeated PowerComponentUsage power_components = 2;
65
66        // Represents a slice of power attribution, e.g. "cpu while in the background"
67        // or "wifi when running a background service".  Queries that care about
68        // PowerComponentUsage slices need to be aware of all supported dimensions.
69        // There are no roll-ups included in the slices - it is up to the clients
70        // of this data to aggregate values as needed.
71        message PowerComponentUsageSlice {
72            optional PowerComponentUsage power_component = 1;
73
74            enum ProcessState {
75                UNSPECIFIED = 0;
76                FOREGROUND = 1;
77                BACKGROUND = 2;
78                FOREGROUND_SERVICE = 3;
79                CACHED = 4;
80            }
81
82            optional ProcessState process_state = 2;
83        }
84
85        repeated PowerComponentUsageSlice slices = 3;
86    }
87
88    // Total power usage for the device during this session.
89    optional BatteryConsumerData device_battery_consumer = 4;
90
91    // Power usage by a uid during this session.
92    message UidBatteryConsumer {
93        optional int32 uid = 1;
94        optional BatteryConsumerData battery_consumer_data = 2;
95        // DEPRECATED Use time_in_state instead.
96        optional int64 time_in_foreground_millis = 3 [deprecated = true];
97        // DEPRECATED Use time_in_state instead.
98        optional int64 time_in_background_millis = 4 [deprecated = true];
99
100        message TimeInState {
101            enum ProcessState {
102                UNSPECIFIED = 0;
103                FOREGROUND = 1;
104                BACKGROUND = 2;
105                FOREGROUND_SERVICE = 3;
106            }
107
108            optional ProcessState process_state = 1;
109            optional int64 time_in_state_millis = 2;
110        }
111
112        repeated TimeInState time_in_state = 5;
113    }
114    repeated UidBatteryConsumer uid_battery_consumers = 5;
115
116    // Sum of all discharge percentage point drops during the reported session.
117    optional int32 session_discharge_percentage = 6;
118
119    // Total amount of time battery was discharging during the reported session
120    optional int64 discharge_duration_millis = 7;
121
122    // Notes the power model used for a power component.
123    message PowerComponentModel {
124        // Holds android.os.PowerComponentEnum, or custom component value between 1000 and 9999.
125        optional int32 component = 1;
126
127        enum PowerModel {
128            UNDEFINED = 0;
129            POWER_PROFILE = 1;
130            MEASURED_ENERGY = 2;
131        }
132
133        optional PowerModel power_model = 2;
134    }
135
136    // The power model used for each power component.
137    repeated PowerComponentModel component_models = 8;
138}
139