• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2016 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#      http://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
15import re
16import subprocess
17import sys
18
19
20def main():
21    """Put screen to sleep."""
22    screen_id = ''
23    for s in sys.argv[1:]:
24        if s[:7] == 'screen=' and len(s) > 7:
25            screen_id = s[7:]
26
27    if not screen_id:
28        print 'Error: need to specify screen serial'
29        assert False
30
31    cmd = ('adb -s %s shell dumpsys power | egrep "Display Power"'
32           % screen_id)
33    process = subprocess.Popen(cmd.split(), stdout=subprocess.PIPE)
34    cmd_ret = process.stdout.read()
35    screen_state = re.split(r'[s|=]', cmd_ret)[-1]
36    if screen_state == 'OFF\n':
37        print 'Screen OFF. Turning ON.'
38    else:
39        wakeup = ('adb -s %s shell input keyevent POWER' % screen_id)
40        subprocess.Popen(wakeup.split())
41if __name__ == '__main__':
42    main()
43