You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

69 lines
2.1 KiB

  1. #!/bin/bash
  2. function 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. function blank {
  18. ### Blanks the screen after X seconds
  19. 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. function end {
  26. ### Cleans up after exiting
  27. # Stop DroidCamX on device
  28. echo "Stopping DroidCamX"
  29. adb shell am force-stop com.dev47apps.droidcamx
  30. # blank device
  31. blank 0
  32. }
  33. # Unlock phone
  34. unlock
  35. # Start DroidCamX app, intent may vary for free DroidCam version
  36. echo "(Re-)Starting DroidCamX"
  37. adb shell << EOF
  38. am force-stop com.dev47apps.droidcamx
  39. am start -n com.dev47apps.droidcamx/com.dev47apps.droidcamx.DroidCamX
  40. EOF
  41. # Wait some seconds for the app to settle
  42. sleep 3
  43. # Initiate screen blanking in X seconds (mind the background function "&")
  44. x=10
  45. blank ${x} &
  46. # Start droidcam binary
  47. # 1920x1080 breaks Skype!
  48. echo ""
  49. echo "+-------------------------------------------------------------+"
  50. echo "| |"
  51. echo "| SCREEN WILL BLANK IN ${x} SECONDS. CONNECT WITHIN THIS LIMIT! |"
  52. echo "| |"
  53. echo "+-------------------------------------------------------------+"
  54. echo ""
  55. /usr/bin/droidcam -v -dev=/dev/video10 -size=1280x720 adb 4747 > /dev/null
  56. #/usr/bin/droidcam -v -dev=/dev/video10 -size=1920x1080 adb 4747 > /dev/null
  57. # Cleanup when droidcam binary exited
  58. end