• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1-- Copyright 2025 The Android Open Source Project
2--
3-- Licensed under the Apache License, Version 2.0 (the "License");
4-- you may not use this file except in compliance with the License.
5-- You may obtain a copy of the License at
6--
7--     https://www.apache.org/licenses/LICENSE-2.0
8--
9-- Unless required by applicable law or agreed to in writing, software
10-- distributed under the License is distributed on an "AS IS" BASIS,
11-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12-- See the License for the specific language governing permissions and
13-- limitations under the License.
14
15INCLUDE PERFETTO MODULE counters.intervals;
16
17-- Light idle states. This is the state machine that quickly detects the
18-- device is unused and restricts background activity.
19-- See https://developer.android.com/training/monitoring-device-state/doze-standby
20CREATE PERFETTO TABLE android_light_idle_state (
21  -- ID
22  id LONG,
23  -- Timestamp.
24  ts TIMESTAMP,
25  -- Duration.
26  dur DURATION,
27  -- Description of the light idle state.
28  light_idle_state STRING
29) AS
30WITH
31  _counter AS (
32    SELECT
33      counter.id,
34      ts,
35      0 AS track_id,
36      value
37    FROM counter
38    JOIN counter_track
39      ON counter_track.id = counter.track_id
40    WHERE
41      name = 'DozeLightState'
42  )
43SELECT
44  id,
45  ts,
46  dur,
47  CASE value
48    -- device is used or on power
49    WHEN 0
50    THEN 'active'
51    -- device is waiting to go idle
52    WHEN 1
53    THEN 'inactive'
54    -- device is idle
55    WHEN 4
56    THEN 'idle'
57    -- waiting for connectivity before maintenance
58    WHEN 5
59    THEN 'waiting_for_network'
60    -- maintenance running
61    WHEN 6
62    THEN 'idle_maintenance'
63    -- device has gone deep idle, light idle state irrelevant
64    WHEN 7
65    THEN 'override'
66    ELSE 'unmapped'
67  END AS light_idle_state
68FROM counter_leading_intervals!(_counter);
69
70-- Deep idle states. This is the state machine that more slowly detects deeper
71-- levels of device unuse and restricts background activity further.
72-- See https://developer.android.com/training/monitoring-device-state/doze-standby
73CREATE PERFETTO TABLE android_deep_idle_state (
74  -- ID
75  id LONG,
76  -- Timestamp.
77  ts TIMESTAMP,
78  -- Duration.
79  dur DURATION,
80  -- Description of the deep idle state.
81  deep_idle_state STRING
82) AS
83WITH
84  _counter AS (
85    SELECT
86      counter.id,
87      ts,
88      0 AS track_id,
89      value
90    FROM counter
91    JOIN counter_track
92      ON counter_track.id = counter.track_id
93    WHERE
94      name = 'DozeDeepState'
95  )
96SELECT
97  id,
98  ts,
99  dur,
100  CASE value
101    WHEN 0
102    THEN 'active'
103    WHEN 1
104    THEN 'inactive'
105    -- waiting for next idle period
106    WHEN 2
107    THEN 'idle_pending'
108    -- device is sensing motion
109    WHEN 3
110    THEN 'sensing'
111    -- device is finding location
112    WHEN 4
113    THEN 'locating'
114    WHEN 5
115    THEN 'idle'
116    WHEN 6
117    THEN 'idle_maintenance'
118    -- inactive, should go straight to idle without motion / location
119    -- sensing.
120    WHEN 7
121    THEN 'quick_doze_delay'
122    ELSE 'unmapped'
123  END AS deep_idle_state
124FROM counter_leading_intervals!(_counter);
125