Advertisement
Guest User

Untitled

a guest
Jun 24th, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 KB | None | 0 0
  1. #!/bin/sh
  2.  
  3. # Returns the power state of the screen 1 = on, 0 = off
  4. getDisplayState() {
  5. state=$(adb -s $1 shell dumpsys power | grep mScreenOn= | grep -oE '(true|false)')
  6.  
  7. # If we didn't get anything it might be a pre-lollipop device
  8. if [ "$state" = "" ]; then
  9. state=$(adb -s $1 shell dumpsys power | grep 'Display Power' | grep -oE '(ON|OFF)')
  10. fi
  11.  
  12. if [ "$state" = "ON" ] || [ "$state" = "true" ]; then
  13. return 1;
  14. else
  15. return 0;
  16. fi
  17. }
  18.  
  19. if [ $# -eq 0 ]; then
  20. echo "Usage: $0 [on|off]"
  21. exit 1;
  22. fi
  23.  
  24. if [ "$1" = "on" ]; then
  25. echo "Turning on screen on all connected devices..."
  26.  
  27. for device in `adb devices | grep device$ | cut -f1`
  28. do
  29. echo -n "Found device: $device ... "
  30.  
  31. getDisplayState $device
  32. state=$?
  33.  
  34. # If the display is off, turn it on and unlock
  35. if [ $state -eq 0 ]; then
  36. echo "display was off, turning on"
  37.  
  38. # press power on
  39. adb -s $device shell input keyevent 26
  40.  
  41. # press menu
  42. adb -s $device shell input keyevent 82
  43.  
  44. # enter pin
  45. adb -s $device shell input keyevent xxx
  46. adb -s $device shell input keyevent xxx
  47. adb -s $device shell input keyevent xxx
  48. adb -s $device shell input keyevent xxx
  49.  
  50. # press enter
  51. adb -s $device shell input keyevent 66
  52. else
  53. echo "display was on, pressing home button to keep alive"
  54. adb -s $device shell input keyevent 3
  55. fi
  56.  
  57. done
  58.  
  59. exit 0;
  60. fi
  61.  
  62. if [ "$1" = "off" ]; then
  63. echo "Turning off screen on all connected devices..."
  64.  
  65. for device in `adb devices | grep device$ | cut -f1`
  66. do
  67. echo -n "Found device: $device ... "
  68.  
  69. getDisplayState $device
  70. state=$?
  71.  
  72. # If the display is on, turn it off
  73. if [ $state -eq 1 ]; then
  74. echo "display was on, turning off"
  75. adb -s $device shell input keyevent 26
  76. else
  77. echo "display was off"
  78. fi
  79.  
  80. done
  81.  
  82. exit 0;
  83. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement