1#!/usr/bin/env python3
2#
3#   Copyright 2019 - The Android Open Source Project
4#
5#   Licensed under the Apache License, Version 2.0 (the 'License');
6#   you may not use this file except in compliance with the License.
7#   You may obtain a copy of the License at
8#
9#       http://www.apache.org/licenses/LICENSE-2.0
10#
11#   Unless required by applicable law or agreed to in writing, software
12#   distributed under the License is distributed on an 'AS IS' BASIS,
13#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14#   See the License for the specific language governing permissions and
15#   limitations under the License.
16
17from acts.test_utils.instrumentation.device.command.adb_command_types \
18    import DeviceBinaryCommandSeries
19from acts.test_utils.instrumentation.device.command.adb_command_types import \
20    DeviceSetprop
21from acts.test_utils.instrumentation.device.command.adb_command_types import \
22    DeviceSetting
23from acts.test_utils.instrumentation.device.command.adb_command_types import \
24    DeviceState
25
26GLOBAL = 'global'
27SYSTEM = 'system'
28SECURE = 'secure'
29
30"""Common device settings for power testing."""
31
32# TODO: add descriptions to each setting
33
34# Network/Connectivity
35
36airplane_mode = DeviceBinaryCommandSeries(
37    [
38        DeviceSetting(GLOBAL, 'airplane_mode_on'),
39        DeviceState(
40            'am broadcast -a android.intent.action.AIRPLANE_MODE --ez state',
41            'true', 'false')
42    ]
43)
44
45mobile_data = DeviceBinaryCommandSeries(
46    [
47        DeviceSetting(GLOBAL, 'mobile_data'),
48        DeviceState('svc data', 'enable', 'disable')
49    ]
50)
51
52cellular = DeviceSetting(GLOBAL, 'cell_on')
53
54wifi = DeviceBinaryCommandSeries(
55    [
56        DeviceSetting(GLOBAL, 'wifi_on'),
57        DeviceState('svc wifi', 'enable', 'disable')
58    ]
59)
60
61ethernet = DeviceState('ifconfig eth0', 'up', 'down')
62
63bluetooth = DeviceState('service call bluetooth_manager', '6', '8')
64
65nfc = DeviceState('svc nfc', 'enable', 'disable')
66
67
68# Calling
69
70disable_dialing = DeviceSetprop('ro.telephony.disable-call', 'true', 'false')
71
72
73# Screen
74
75screen_adaptive_brightness = DeviceSetting(SYSTEM, 'screen_brightness_mode')
76
77screen_brightness = DeviceSetting(SYSTEM, 'screen_brightness')
78
79screen_always_on = DeviceState('svc power stayon', 'true', 'false')
80
81screen_timeout_ms = DeviceSetting(SYSTEM, 'screen_off_timeout')
82
83doze_mode = DeviceSetting(SECURE, 'doze_enabled')
84
85doze_always_on = DeviceSetting(SECURE, 'doze_always_on')
86
87wake_gesture = DeviceSetting(SECURE, 'wake_gesture_enabled')
88
89screensaver = DeviceSetting(SECURE, 'screensaver_enabled')
90
91notification_led = DeviceSetting(SYSTEM, 'notification_light_pulse')
92
93
94# Accelerometer
95
96auto_rotate = DeviceSetting(SYSTEM, 'accelerometer_rotation')
97
98
99# Time
100
101auto_time = DeviceSetting(GLOBAL, 'auto_time')
102
103auto_timezone = DeviceSetting(GLOBAL, 'auto_timezone')
104
105timezone = DeviceSetprop('persist.sys.timezone')
106
107
108# Location
109
110location_gps = DeviceSetting(SECURE, 'location_providers_allowed',
111                             '+gps', '-gps')
112
113location_network = DeviceSetting(SECURE, 'location_providers_allowed',
114                                 '+network', '-network')
115
116
117# Power
118
119battery_saver_mode = DeviceSetting(GLOBAL, 'low_power')
120
121battery_saver_trigger = DeviceSetting(GLOBAL, 'low_power_trigger_level')
122
123enable_full_batterystats_history = 'dumpsys batterystats --enable full-history'
124
125disable_doze = 'dumpsys deviceidle disable'
126
127
128# Sensors
129
130disable_sensors = 'dumpsys sensorservice restrict blah'
131
132MOISTURE_DETECTION_SETTING_FILE = '/sys/class/power_supply/usb/moisture_detection_enabled'
133disable_moisture_detection = 'echo 0 > %s' % MOISTURE_DETECTION_SETTING_FILE
134
135## Ambient EQ: https://support.google.com/googlenest/answer/9137130?hl=en
136ambient_eq = DeviceSetting(SECURE, 'display_white_balance_enabled')
137
138# Miscellaneous
139
140test_harness = DeviceBinaryCommandSeries(
141    [
142        DeviceSetprop('ro.monkey'),
143        DeviceSetprop('ro.test_harness')
144    ]
145)
146
147dismiss_keyguard = 'wm dismiss-keyguard'
148