1#!/usr/bin/env python3
2#
3# Copyright (C) 2018 The Android Open Source Project
4#
5# Licensed under the Apache License, Version 2.0 (the "License"); you may not
6# use this file except in compliance with the License. You may obtain a copy of
7# 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, WITHOUT
13# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14# License for the specific language governing permissions and limitations under
15# the License.
16"""
17Shell command library.
18"""
19
20
21class ShellCommands():
22    def __init__(self, log, dut):
23        self.dut = dut
24        self.log = log
25
26    def set_battery_level(self, level):
27        """Set the battery level via ADB shell
28        Args:
29            level: the percent level to set
30        """
31        self.dut.adb.shell("dumpsys battery set level {}".format(level))
32
33    def disable_ble_scanning(self):
34        """Disable BLE scanning via ADB shell"""
35        self.dut.adb.shell("settings put global ble_scan_always_enabled 0")
36
37    def enable_ble_scanning(self):
38        """Enable BLE scanning via ADB shell"""
39        self.dut.adb.shell("settings put global ble_scan_always_enabled 1")
40
41    def consume_cpu_core(self):
42        """Consume a CPU core on the Android device via ADB shell"""
43        self.dut.adb.shell("echo $$ > /dev/cpuset/top-app/tasks")
44        self.dut.adb.shell("cat /dev/urandom > /dev/null &")
45