• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 datetime
18import http
19import requests
20
21import acts.controllers.fuchsia_lib.base_lib as base_lib
22
23HW_PWR_STATE_CONTROL_TIMEOUT = 5
24
25
26class FuchsiaHardwarePowerStatecontrolLib(base_lib.BaseLib):
27    def __init__(self, addr, tc, client_id):
28        self.address = addr
29        self.test_counter = tc
30        self.client_id = client_id
31
32    def suspendReboot(self, timeout=HW_PWR_STATE_CONTROL_TIMEOUT):
33        """Call Suspend Reboot.
34
35        Returns:
36            None if success.
37        """
38        test_cmd = "hardware_power_statecontrol_facade.SuspendReboot"
39        test_args = {}
40        test_id = self.build_id(self.test_counter)
41        self.test_counter += 1
42        try:
43            response = self.send_command(test_id,
44                                         test_cmd,
45                                         test_args,
46                                         response_timeout=timeout)
47        except (ConnectionResetError, base_lib.DeviceOffline,
48                requests.exceptions.ConnectionError,
49                requests.exceptions.ReadTimeout):
50            return
51        return response
52
53    def suspendRebootBootloader(self, timeout=HW_PWR_STATE_CONTROL_TIMEOUT):
54        """Call Suspend Reboot Bootloader
55
56        Returns:
57            None if success.
58        """
59        test_cmd = "hardware_power_statecontrol_facade.SuspendRebootBootloader"
60        test_args = {}
61        test_id = self.build_id(self.test_counter)
62        self.test_counter += 1
63        try:
64            response = self.send_command(test_id,
65                                         test_cmd,
66                                         test_args,
67                                         response_timeout=timeout)
68        except (requests.exceptions.ReadTimeout,
69                http.client.RemoteDisconnected, base_lib.DeviceOffline):
70            return
71        return response
72
73    def suspendPoweroff(self, timeout=HW_PWR_STATE_CONTROL_TIMEOUT):
74        """Call Suspend Poweroff
75
76        Returns:
77            None if success.
78        """
79        test_cmd = "hardware_power_statecontrol_facade.SuspendPoweroff"
80        test_args = {}
81        test_id = self.build_id(self.test_counter)
82        self.test_counter += 1
83        try:
84            response = self.send_command(test_id,
85                                         test_cmd,
86                                         test_args,
87                                         response_timeout=timeout)
88        except (requests.exceptions.ReadTimeout,
89                http.client.RemoteDisconnected, base_lib.DeviceOffline):
90            return
91        return response
92
93    def suspendMexec(self, timeout=HW_PWR_STATE_CONTROL_TIMEOUT):
94        """Call Suspend Mexec
95
96        Returns:
97            None if success.
98        """
99        test_cmd = "hardware_power_statecontrol_facade.SuspendMexec"
100        test_args = {}
101        test_id = self.build_id(self.test_counter)
102        self.test_counter += 1
103        try:
104            response = self.send_command(test_id,
105                                         test_cmd,
106                                         test_args,
107                                         response_timeout=timeout)
108        except (requests.exceptions.ReadTimeout,
109                http.client.RemoteDisconnected, base_lib.DeviceOffline):
110            return
111        return response
112
113    def suspendRam(self, timeout=HW_PWR_STATE_CONTROL_TIMEOUT):
114        """Call Suspend Ram
115
116        Returns:
117            None if success.
118        """
119        test_cmd = "hardware_power_statecontrol_facade.SuspendRam"
120        test_args = {}
121        test_id = self.build_id(self.test_counter)
122        self.test_counter += 1
123        try:
124            response = self.send_command(test_id,
125                                         test_cmd,
126                                         test_args,
127                                         response_timeout=timeout)
128        except (requests.exceptions.ReadTimeout,
129                http.client.RemoteDisconnected, base_lib.DeviceOffline):
130            return
131        return response
132