blob: 0406f11350e85b15dec965ac7c5d0299f1c6ae7f [file] [log] [blame]
Stefan Lafoncdb1a0e2017-09-27 20:24:15 -07001/*
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
17syntax = "proto2";
Stefan Lafoncdb1a0e2017-09-27 20:24:15 -070018
Yao Chend54f9dd2017-10-17 17:37:48 +000019// TODO: Not the right package and class name
Stefan Lafoncdb1a0e2017-09-27 20:24:15 -070020package android.os.statsd;
Stefan Lafoncdb1a0e2017-09-27 20:24:15 -070021option java_package = "com.android.os";
22option java_outer_classname = "StatsEventProto";
23
Yao Chend54f9dd2017-10-17 17:37:48 +000024/**
25 * The master event class. This message defines all of the available
26 * raw stats log events from the Android system, also known as "atoms."
27 *
28 * This field contains a single oneof with all of the available messages.
29 * The stats-log-api-gen tool runs as part of the Android build and
30 * generates the android.util.StatsLog class, which contains the constants
31 * and methods that Android uses to log.
32 *
33 * This StatsEvent class is not actually built into the Android system.
34 * Instead, statsd on Android constructs these messages synthetically,
35 * in the format defined here and in stats_log.proto.
36 */
Stefan Lafoncdb1a0e2017-09-27 20:24:15 -070037message StatsEvent {
Yao Chend54f9dd2017-10-17 17:37:48 +000038 oneof event {
Bookatzc1a050a2017-10-10 15:49:28 -070039 // For StatsLog reasons, 1 is illegal and will not work. Must start at 2.
40 BleScanStateChanged ble_scan_state_changed = 2;
41 BleUnoptimizedScanStateChanged ble_unoptimized_scan_state_changed = 3;
42 BleScanResultReceived ble_scan_result_received = 4;
43 SensorStateChanged sensor_state_changed = 5;
44 GpsScanStateChanged gps_scan_state_changed = 6; // TODO: untested
45 SyncStateChanged sync_state_changed = 7;
46 ScheduledJobStateChanged scheduled_job_state_changed = 8;
47 ScreenBrightnessChanged screen_brightness_changed = 9;
48 // 10-20 are temporarily reserved for wakelocks etc.
49 UidWakelockStateChanged uid_wakelock_state_changed = 11;
50 LongPartialWakelockStateChanged long_partial_wakelock_state_changed = 12;
51 BatterySaverModeStateChanged battery_saver_mode_state_changed = 21;
52 DeviceIdleModeStateChanged device_idle_mode_state_changed = 22;
53 AudioStateChanged audio_state_changed = 23;
54 MediaCodecActivityChanged media_codec_activity_changed = 24;
55 CameraStateChanged camera_state_changed = 25;
56 FlashlightStateChanged flashlight_state_changed = 26;
57 UidProcessStateChanged uid_process_state_changed = 27;
58 ProcessLifeCycleStateChanged process_life_cycle_state_changed = 28;
59 ScreenStateChanged screen_state_changed = 29;
Bookatz8c6571b2017-10-24 15:04:41 -070060 BatteryLevelChanged battery_level_changed = 30;
61 ChargingStateChanged charging_state_changed = 31;
62 PluggedStateChanged plugged_state_changed = 32;
63 DeviceTemperatureReported device_temperature_reported = 33;
64 DeviceOnStatusChanged device_on_status_changed = 34;
65 WakeupAlarmOccurred wakeup_alarm_occurred = 35;
66 KernelWakeupReported kernel_wakeup_reported = 36;
67
Bookatzc1a050a2017-10-10 15:49:28 -070068 // TODO: Reorder the numbering so that the most frequent occur events occur in the first 15.
Yao Chend54f9dd2017-10-17 17:37:48 +000069 }
Stefan Lafoncdb1a0e2017-09-27 20:24:15 -070070}
71
Yao Chend54f9dd2017-10-17 17:37:48 +000072/**
73 * A WorkSource represents the chained attribution of applications that
74 * resulted in a particular bit of work being done.
75 */
76message WorkSource {
77 // TODO
Stefan Lafoncdb1a0e2017-09-27 20:24:15 -070078}
79
Yao Chend54f9dd2017-10-17 17:37:48 +000080/*
81 * *****************************************************************************
82 * Below are all of the individual atoms that are logged by Android via statsd
83 * and Westworld.
84 *
85 * RULES:
86 * - The field ids for each atom must start at 1, and count upwards by 1.
87 * Skipping field ids is not allowed.
88 * - These form an API, so renaming, renumbering or removing fields is
89 * not allowed between android releases. (This is not currently enforced,
90 * but there will be a tool to enforce this restriction).
91 * - The types must be built-in protocol buffer types, namely, no sub-messages
92 * are allowed (yet). The bytes type is also not allowed.
93 * - The CamelCase name of the message type should match the
94 * underscore_separated name as defined in StatsEvent.
95 * - If an atom represents work that can be attributed to an app, there can
96 * be exactly one WorkSource field. It must be field number 1.
97 * - A field that is a uid should be a string field, tagged with the [xxx]
98 * annotation. The generated code on android will be represented by UIDs,
99 * and those UIDs will be translated in xxx to those strings.
100 *
101 * CONVENTIONS:
Bookatzc1a050a2017-10-10 15:49:28 -0700102 * - Events are past tense. e.g. ScreenStateChanged, not ScreenStateChange.
Yao Chend54f9dd2017-10-17 17:37:48 +0000103 * - If there is a UID, it goes first. Think in an object-oriented fashion.
104 * *****************************************************************************
105 */
Stefan Lafoncdb1a0e2017-09-27 20:24:15 -0700106
Yao Chend54f9dd2017-10-17 17:37:48 +0000107/**
108 * Logs when the screen state changes.
109 *
110 * Logged from:
111 * frameworks/base/services/core/java/com/android/server/am/BatteryStatsService.java
112 */
113message ScreenStateChanged {
114 // TODO: Use the real screen state.
115 enum State {
116 STATE_UNKNOWN = 0;
117 STATE_OFF = 1;
118 STATE_ON = 2;
119 STATE_DOZE = 3;
120 STATE_DOZE_SUSPEND = 4;
121 STATE_VR = 5;
122 }
123 // New screen state.
124 optional State display_state = 1;
Stefan Lafoncdb1a0e2017-09-27 20:24:15 -0700125}
Yao Chend54f9dd2017-10-17 17:37:48 +0000126
127/**
Bookatzc1a050a2017-10-10 15:49:28 -0700128 * Logs that the state of a process state, as per the activity manager, has changed.
Yao Chend54f9dd2017-10-17 17:37:48 +0000129 *
130 * Logged from:
131 * frameworks/base/services/core/java/com/android/server/am/BatteryStatsService.java
132 */
Bookatzc1a050a2017-10-10 15:49:28 -0700133message UidProcessStateChanged {
Yao Chend54f9dd2017-10-17 17:37:48 +0000134 optional int32 uid = 1; // TODO: should be a string tagged w/ uid annotation
135
136 // The state.
Bookatzc1a050a2017-10-10 15:49:28 -0700137 // TODO: Use the real (mapped) process states.
Yao Chend54f9dd2017-10-17 17:37:48 +0000138 optional int32 state = 2;
139}
140
141/**
Bookatzc1a050a2017-10-10 15:49:28 -0700142 * Logs that a process started, finished, crashed, or ANRed.
143 *
144 * Logged from:
145 * frameworks/base/services/core/java/com/android/server/am/BatteryStatsService.java
146 */
147message ProcessLifeCycleStateChanged {
148 // TODO: Use the real (mapped) process states.
149 optional int32 uid = 1; // TODO: should be a string tagged w/ uid annotation
150
151 // TODO: What is this?
152 optional string name = 2;
153
154 // The state.
155 // TODO: Use an enum.
156 optional int32 event = 3;
157}
158
159
160
161/**
162 * Logs when the ble scan state changes.
163 *
164 * Logged from:
165 * frameworks/base/core/java/com/android/internal/os/BatteryStatsImpl.java
166 */
167message BleScanStateChanged {
168 // TODO: Add attribution instead of uid.
169 optional int32 uid = 1;
170
171 enum State {
172 OFF = 0;
173 ON = 1;
174 }
175 optional State state = 2;
176}
177
178/**
179 * Logs when an unoptimized ble scan state changes.
180 *
181 * Logged from:
182 * frameworks/base/core/java/com/android/internal/os/BatteryStatsImpl.java
183 */
184// TODO: Consider changing to tracking per-scanner-id (log from AppScanStats).
185message BleUnoptimizedScanStateChanged {
186 // TODO: Add attribution instead of uid.
187 optional int32 uid = 1;
188
189 enum State {
190 OFF = 0;
191 ON = 1;
192 }
193 optional State state = 2;
194}
195
196/**
197 * Logs reporting of a ble scan finding results.
198 *
199 * Logged from:
200 * frameworks/base/core/java/com/android/internal/os/BatteryStatsImpl.java
201 */
202// TODO: Consider changing to tracking per-scanner-id (log from AppScanStats).
203message BleScanResultReceived {
204 // TODO: Add attribution instead of uid.
205 optional int32 uid = 1;
206
207 // Number of ble scan results returned.
208 optional int32 num_of_results = 2;
209}
210
211/**
212 * Logs when a sensor state changes.
213 *
214 * Logged from:
215 * frameworks/base/core/java/com/android/internal/os/BatteryStatsImpl.java
216 */
217message SensorStateChanged {
218 // TODO: Add attribution instead of uid.
219 optional int32 uid = 1;
220
221 // TODO: Is there a way to get the actual name of the sensor?
222 // The id (int) of the sensor.
223 optional int32 sensor_id = 2;
224
225 enum State {
226 OFF = 0;
227 ON = 1;
228 }
229 optional State state = 3;
230}
231
232
233/**
234 * Logs when GPS state changes.
235 *
236 * Logged from:
237 * frameworks/base/core/java/com/android/internal/os/BatteryStatsImpl.java
238 */
239message GpsScanStateChanged {
240 // TODO: Add attribution instead of uid.
241 optional int32 uid = 1;
242
243 enum State {
244 OFF = 0;
245 ON = 1;
246 }
247 optional State state = 2;
248}
249
250
251/**
252 * Logs when a sync manager sync state changes.
253 *
254 * Logged from:
255 * frameworks/base/core/java/com/android/internal/os/BatteryStatsImpl.java
256 */
257message SyncStateChanged {
258 // TODO: Add attribution instead of uid.
259 optional int32 uid = 1;
260
261 // Name of the sync (as named in the app)
262 optional string name = 2;
263
264 enum State {
265 OFF = 0;
266 ON = 1;
267 }
268 optional State state = 3;
269}
270
271/**
272 * Logs when a job scheduler job state changes.
273 *
274 * Logged from:
275 * frameworks/base/core/java/com/android/internal/os/BatteryStatsImpl.java
276 */
277message ScheduledJobStateChanged {
278 // TODO: Add attribution instead of uid.
279 optional int32 uid = 1;
280
281 // Name of the job (as named in the app)
282 optional string name = 2;
283
284 enum State {
285 OFF = 0;
286 ON = 1;
287 }
288 optional State state = 3;
289
290 // TODO: Consider adding the stopReason (int)
291}
292
293/**
294 * Logs when the audio state changes.
295 *
296 * Logged from:
297 * frameworks/base/core/java/com/android/internal/os/BatteryStatsImpl.java
298 */
299message AudioStateChanged {
300 // TODO: Add attribution instead of uid.
301 optional int32 uid = 1;
302
303 enum State {
304 OFF = 0;
305 ON = 1;
306 }
307 optional State state = 2;
308}
309
310/**
311 * Logs when the video codec state changes.
312 *
313 * Logged from:
314 * frameworks/base/core/java/com/android/internal/os/BatteryStatsImpl.java
315 */
316message MediaCodecActivityChanged {
317 // TODO: Add attribution instead of uid.
318 optional int32 uid = 1;
319
320 enum State {
321 OFF = 0;
322 ON = 1;
323 }
324 optional State state = 2;
325}
326
327/**
328 * Logs when the flashlight state changes.
329 *
330 * Logged from:
331 * frameworks/base/core/java/com/android/internal/os/BatteryStatsImpl.java
332 */
333message FlashlightStateChanged {
334 // TODO: Add attribution instead of uid.
335 optional int32 uid = 1;
336
337 enum State {
338 OFF = 0;
339 ON = 1;
340 }
341 optional State state = 2;
342}
343
344/**
345 * Logs when the camera state changes.
346 *
347 * Logged from:
348 * frameworks/base/core/java/com/android/internal/os/BatteryStatsImpl.java
349 */
350message CameraStateChanged {
351 // TODO: Add attribution instead of uid.
352 optional int32 uid = 1;
353
354 enum State {
355 OFF = 0;
356 ON = 1;
357 }
358 optional State state = 2;
359}
360
361/**
362 * Logs that the state of a wakelock (per app and per wakelock name) has changed.
Yao Chend54f9dd2017-10-17 17:37:48 +0000363 *
364 * Logged from:
365 * TODO
366 */
Bookatzc1a050a2017-10-10 15:49:28 -0700367message WakelockChanged {
Yao Chend54f9dd2017-10-17 17:37:48 +0000368 // TODO: Add attribution instead of uid.
369 optional int32 uid = 1;
370
Bookatzc1a050a2017-10-10 15:49:28 -0700371 // Type of wakelock.
372 enum Type {
373 PARTIAL = 0;
374 FULL = 1;
375 WINDOW = 2;
376 }
377 optional int32 type = 2;
378
379 // The wakelock tag (Called tag in the Java API, sometimes name elsewhere).
380 optional string tag = 3;
381
382 enum State {
383 OFF = 0;
384 ON = 1;
385 }
386 optional State state = 4;
387}
388
389/**
390 * Logs when an app is holding a wakelock, regardless of the wakelock's name.
391 *
392 * Logged from:
393 * frameworks/base/core/java/com/android/internal/os/BatteryStatsImpl.java
394 */
395message UidWakelockStateChanged {
396 // TODO: Add attribution instead of uid.
397 optional int32 uid = 1;
398
399 // Type of wakelock.
400 enum Type {
401 PARTIAL = 0;
402 FULL = 1;
403 WINDOW = 2;
404 }
405 optional int32 type = 2;
406
407 enum State {
408 OFF = 0;
409 ON = 1;
410 }
411 optional State state = 3;
412}
413
414/**
415 * Logs when a partial wakelock is considered 'long' (over 1 min).
416 *
417 * Logged from:
418 * frameworks/base/core/java/com/android/internal/os/BatteryStatsImpl.java
419 */
420message LongPartialWakelockStateChanged {
421 // TODO: Add attribution instead of uid?
422 optional int32 uid = 1;
423
Yao Chend54f9dd2017-10-17 17:37:48 +0000424 // The wakelock tag (Called tag in the Java API, sometimes name elsewhere).
425 optional string tag = 2;
426
Bookatzc1a050a2017-10-10 15:49:28 -0700427 // TODO: I have no idea what this is.
428 optional string history_tag = 3;
429
430 enum State {
431 OFF = 0;
432 ON = 1;
433 }
434 optional State state = 4;
Yao Chend54f9dd2017-10-17 17:37:48 +0000435}
436
Bookatzc1a050a2017-10-10 15:49:28 -0700437/**
438 * Logs Battery Saver state change.
439 *
440 * Logged from:
441 * frameworks/base/core/java/com/android/internal/os/BatteryStatsImpl.java
442 */
443message BatterySaverModeStateChanged {
444 enum State {
445 OFF = 0;
446 ON = 1;
447 }
448 optional State state = 1;
449}
450
451/**
452 * Logs Doze mode state change.
453 *
454 * Logged from:
455 * frameworks/base/services/core/java/com/android/server/am/BatteryStatsService.java
456 */
457message DeviceIdleModeStateChanged {
458 // TODO: Use the enum matching BatteryStats.DEVICE_IDLE_MODE_.
459 optional int32 state = 1;
460}
461
462/**
463 * Logs screen brightness level.
464 *
465 * Logged from:
466 * frameworks/base/services/core/java/com/android/server/am/BatteryStatsService.java
467 */
468message ScreenBrightnessChanged {
469 // Screen brightness level. Should be in [-1, 255] according to PowerManager.java.
470 optional int32 level = 1;
Bookatz8c6571b2017-10-24 15:04:41 -0700471}
472
473/**
474 * Logs battery level (percent full, from 0 to 100).
475 *
476 * Logged from:
477 * frameworks/base/core/java/com/android/internal/os/BatteryStatsImpl.java
478 */
479message BatteryLevelChanged {
480 // Battery level. Should be in [0, 100].
481 optional int32 battery_level = 1;
482}
483
484/**
485 * Logs change in charging status of the device.
486 *
487 * Logged from:
488 * frameworks/base/core/java/com/android/internal/os/BatteryStatsImpl.java
489 */
490message ChargingStateChanged {
491 // TODO: Link directly to BatteryManager.java's constants (via a proto).
492 enum State {
493 BATTERY_STATUS_UNKNOWN = 1;
494 BATTERY_STATUS_CHARGING = 2;
495 BATTERY_STATUS_DISCHARGING = 3;
496 BATTERY_STATUS_NOT_CHARGING = 4;
497 BATTERY_STATUS_FULL = 5;
498 }
499 optional State charging_state = 1;
500}
501
502/**
503 * Logs whether the device is plugged in, and what power source it is using.
504 *
505 * Logged from:
506 * frameworks/base/core/java/com/android/internal/os/BatteryStatsImpl.java
507 */
508message PluggedStateChanged {
509 // TODO: Link directly to BatteryManager.java's constants (via a proto).
510 enum State {
511 // Note that NONE is not in BatteryManager.java's constants.
512 BATTERY_PLUGGED_NONE = 0;
513 // Power source is an AC charger.
514 BATTERY_PLUGGED_AC = 1;
515 // Power source is a USB port.
516 BATTERY_PLUGGED_USB = 2;
517 // Power source is wireless.
518 BATTERY_PLUGGED_WIRELESS = 4;
519 }
520 optional State plugged_state = 1;
521}
522
523/**
524 * Logs the temperature of the device, in tenths of a degree Celsius.
525 *
526 * Logged from:
527 * frameworks/base/core/java/com/android/internal/os/BatteryStatsImpl.java
528 */
529message DeviceTemperatureReported {
530 // Temperature in tenths of a degree C.
531 optional int32 temperature = 1;
532}
533
534// TODO: Define this more precisely.
535// TODO: Log the ON state somewhere. It isn't currently logged anywhere.
536/**
537 * Logs when the device turns off or on.
538 *
539 * Logged from:
540 * frameworks/base/services/core/java/com/android/server/am/ActivityManagerService.java
541 */
542message DeviceOnStatusChanged {
543 enum State {
544 OFF = 0;
545 ON = 1;
546 }
547 optional State state = 1;
548}
549
550/**
551 * Logs when an app's wakeup alarm fires.
552 *
553 * Logged from:
554 * frameworks/base/services/core/java/com/android/server/am/ActivityManagerService.java
555 */
556message WakeupAlarmOccurred {
557 // TODO: Add attribution instead of uid?
558 optional int32 uid = 1;
559}
560
561/**
562 * Logs kernel wakeup reasons and aborts.
563 *
564 * Logged from:
565 * frameworks/base/services/core/java/com/android/server/am/BatteryStatsService.java
566 */
567message KernelWakeupReported {
568 // Name of the kernel wakeup reason (or abort).
569 optional string wakeup_reason_name = 1;
570
571 // Duration (in microseconds) for the wake-up interrupt to be serviced.
572 optional int64 duration_usec = 2;
Bookatzc1a050a2017-10-10 15:49:28 -0700573}