1#!/usr/bin/env python3 2# 3# Copyright 2020 - 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 17import logging 18import http 19 20import acts.controllers.fuchsia_lib.base_lib as base_lib 21 22HW_PWR_STATE_CONTROL_TIMEOUT = 5 23 24 25class FuchsiaHardwarePowerStatecontrolLib(base_lib.BaseLib): 26 27 def __init__(self, addr: str) -> None: 28 super().__init__(addr, "hardware_power_statecontrol") 29 30 def send_command(self, test_cmd, test_args, response_timeout=30): 31 """Wrap send_command to allow disconnects after sending the request.""" 32 try: 33 response = super().send_command(test_cmd, test_args, 34 response_timeout) 35 except (TimeoutError, http.client.RemoteDisconnected, 36 base_lib.DeviceOffline) as e: 37 logging.warn(f'Error while sending power command: {e}') 38 return 39 return response 40 41 def suspendReboot(self, timeout=HW_PWR_STATE_CONTROL_TIMEOUT): 42 """Call Suspend Reboot. 43 44 Returns: 45 None if success. 46 """ 47 test_cmd = "hardware_power_statecontrol_facade.SuspendReboot" 48 test_args = {} 49 return self.send_command(test_cmd, test_args, response_timeout=timeout) 50 51 def suspendRebootBootloader(self, timeout=HW_PWR_STATE_CONTROL_TIMEOUT): 52 """Call Suspend Reboot Bootloader 53 54 Returns: 55 None if success. 56 """ 57 test_cmd = "hardware_power_statecontrol_facade.SuspendRebootBootloader" 58 test_args = {} 59 return self.send_command(test_cmd, test_args, response_timeout=timeout) 60 61 def suspendPoweroff(self, timeout=HW_PWR_STATE_CONTROL_TIMEOUT): 62 """Call Suspend Poweroff 63 64 Returns: 65 None if success. 66 """ 67 test_cmd = "hardware_power_statecontrol_facade.SuspendPoweroff" 68 test_args = {} 69 return self.send_command(test_cmd, test_args, response_timeout=timeout) 70 71 def suspendMexec(self, timeout=HW_PWR_STATE_CONTROL_TIMEOUT): 72 """Call Suspend Mexec 73 74 Returns: 75 None if success. 76 """ 77 test_cmd = "hardware_power_statecontrol_facade.SuspendMexec" 78 test_args = {} 79 return self.send_command(test_cmd, test_args, response_timeout=timeout) 80 81 def suspendRam(self, timeout=HW_PWR_STATE_CONTROL_TIMEOUT): 82 """Call Suspend Ram 83 84 Returns: 85 None if success. 86 """ 87 test_cmd = "hardware_power_statecontrol_facade.SuspendRam" 88 test_args = {} 89 return self.send_command(test_cmd, test_args, response_timeout=timeout) 90