您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 

55 行
1.5 KiB

  1. #!/bin/sh
  2. unlock() {
  3. ### Activates the screen and unlocks the phone
  4. # Reads the current screen state eturns any combination of ON/OFF and
  5. # LOCKED/UNLOCKED (i.e. OFF_LOCKED).
  6. # Works only on NFC enabled phones but alternative methods exist.
  7. IFS='_' read -ra screenstate <<< $(adb shell dumpsys nfc | awk -F'=' \
  8. '/mScreenState/ {print $2}')
  9. # Emulate Power-Button press if screen is OFF.
  10. [ "${screenstate[0]}" == "OFF" ] && adb shell input keyevent 26 && \
  11. echo Screen activated
  12. # Emulate Menu-button press if phone is locked. Requires the phone to
  13. # unlock without PIN or password.
  14. [ "${screenstate[1]}" == "LOCKED" ] && adb shell input keyevent 82 && \
  15. echo Device unlocked
  16. }
  17. blank() {
  18. ### Blanks the screen (optionally wait X seconds)
  19. [ -z "${1}" ] && sleep "${1}"
  20. IFS='_' read -ra screenstate <<< $(adb shell dumpsys nfc | awk -F'=' \
  21. '/mScreenState/ {print $2}')
  22. [ "${screenstate[0]}" == "ON" ] && adb shell input keyevent 26 && \
  23. echo Screen deactivated
  24. }
  25. run() {
  26. # Unlock phone
  27. unlock
  28. # Start intent
  29. [ -z "${1}" ] && APP="com.dev47apps.obsdroidcam" || APP="${1}"
  30. adb shell am start -n "${APP}/.MainActivity"
  31. blank 5
  32. }
  33. usage() {
  34. echo "Usage: ${0} [-u|b] [-r INTENT]
  35. -u unlock device (default if no option is given)
  36. -b blank device screen
  37. -r INTENT unlock device, run given intent and blank device screen
  38. -h this help"
  39. }
  40. while getopts ":ubr:h" opt; do
  41. case "${opt}" in
  42. u) unlock ;;
  43. b) blank ;;
  44. r) run "${OPTARG}" ;;
  45. h) usage ;;
  46. *) unlock ;;
  47. esac
  48. done