#!/bin/bash #RESOLUTION="1280x720" RESOLUTION="1920x1080" VIDEODEV="/dev/video10" function unlock { ### Activates the screen and unlocks the phone # Reads the current screen state eturns any combination of ON/OFF and # LOCKED/UNLOCKED (i.e. OFF_LOCKED). # Works only on NFC enabled phones but alternative methods exist. IFS='_' read -ra screenstate <<< $(adb shell dumpsys nfc | awk -F'=' \ '/mScreenState/ {print $2}') # Emulate Power-Button press if screen is OFF. [[ ${screenstate[0]} == "OFF" ]] && adb shell input keyevent 26 && \ echo Screen activated # Emulate Menu-button press if phone is locked. Requires the phone to # unlock without PIN or password. [[ ${screenstate[1]} == "LOCKED" ]] && adb shell input keyevent 82 && \ echo Device unlocked } function blank { ### Blanks the screen after X seconds sleep ${1} IFS='_' read -ra screenstate <<< $(adb shell dumpsys nfc | awk -F'=' \ '/mScreenState/ {print $2}') [[ ${screenstate[0]} == "ON" ]] && adb shell input keyevent 26 && \ echo Screen deactivated } function end { ### Cleans up after exiting # Stop DroidCamX on device echo "Stopping DroidCamX" adb shell am force-stop com.dev47apps.droidcamx # blank device blank 0 } # Unlock phone unlock # Start DroidCamX app, intent may vary for free DroidCam version echo "(Re-)Starting DroidCamX" adb shell << EOF am force-stop com.dev47apps.droidcamx am start -n com.dev47apps.droidcamx/com.dev47apps.droidcamx.DroidCamX EOF # Wait some seconds for the app to settle sleep 3 # Initiate screen blanking in X seconds (mind the background function "&") x=10 blank ${x} & # Start droidcam binary # 1920x1080 breaks Skype! echo "" echo "+-------------------------------------------------------------+" echo "| |" echo "| SCREEN WILL BLANK IN ${x} SECONDS. CONNECT WITHIN THIS LIMIT! |" echo "| |" echo "+-------------------------------------------------------------+" echo "" /usr/bin/droidcam -v -dev=${VIDEODEV} -size=${RESOLUTION} adb 4747 > /dev/null # Cleanup when droidcam binary exited end