72 Zeilen
2.1 KiB

  1. #!/bin/bash
  2. #RESOLUTION="1280x720"
  3. RESOLUTION="1920x1080"
  4. VIDEODEV="/dev/video10"
  5. function unlock {
  6. ### Activates the screen and unlocks the phone
  7. # Reads the current screen state eturns any combination of ON/OFF and
  8. # LOCKED/UNLOCKED (i.e. OFF_LOCKED).
  9. # Works only on NFC enabled phones but alternative methods exist.
  10. IFS='_' read -ra screenstate <<< $(adb shell dumpsys nfc | awk -F'=' \
  11. '/mScreenState/ {print $2}')
  12. # Emulate Power-Button press if screen is OFF.
  13. [[ ${screenstate[0]} == "OFF" ]] && adb shell input keyevent 26 && \
  14. echo Screen activated
  15. # Emulate Menu-button press if phone is locked. Requires the phone to
  16. # unlock without PIN or password.
  17. [[ ${screenstate[1]} == "LOCKED" ]] && adb shell input keyevent 82 && \
  18. echo Device unlocked
  19. }
  20. function blank {
  21. ### Blanks the screen after X seconds
  22. sleep ${1}
  23. IFS='_' read -ra screenstate <<< $(adb shell dumpsys nfc | awk -F'=' \
  24. '/mScreenState/ {print $2}')
  25. [[ ${screenstate[0]} == "ON" ]] && adb shell input keyevent 26 && \
  26. echo Screen deactivated
  27. }
  28. function end {
  29. ### Cleans up after exiting
  30. # Stop DroidCamX on device
  31. echo "Stopping DroidCamX"
  32. adb shell am force-stop com.dev47apps.droidcamx
  33. # blank device
  34. blank 0
  35. }
  36. # Unlock phone
  37. unlock
  38. # Start DroidCamX app, intent may vary for free DroidCam version
  39. echo "(Re-)Starting DroidCamX"
  40. adb shell << EOF
  41. am force-stop com.dev47apps.droidcamx
  42. am start -n com.dev47apps.droidcamx/com.dev47apps.droidcamx.DroidCamX
  43. EOF
  44. # Wait some seconds for the app to settle
  45. sleep 3
  46. # Initiate screen blanking in X seconds (mind the background function "&")
  47. x=10
  48. blank ${x} &
  49. # Start droidcam binary
  50. # 1920x1080 breaks Skype!
  51. echo ""
  52. echo "+-------------------------------------------------------------+"
  53. echo "| |"
  54. echo "| SCREEN WILL BLANK IN ${x} SECONDS. CONNECT WITHIN THIS LIMIT! |"
  55. echo "| |"
  56. echo "+-------------------------------------------------------------+"
  57. echo ""
  58. /usr/bin/droidcam -v -dev=${VIDEODEV} -size=${RESOLUTION} adb 4747 > /dev/null
  59. # Cleanup when droidcam binary exited
  60. end