選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

57 行
1.5 KiB

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