This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm whether you accept or reject these cookies being set.

A cookie will be stored in your browser regardless of choice to prevent you being asked this question again. You will be able to change your cookie settings at any time using the link in the footer.

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to Control HDMI on/off from app ?
#1
Android 7.1
Setting --> Display --> HDMI -->On 
My app must be able to control this function.(example:am 8:00 on,pm 18:00 off)
or other ways to switch HDMI regularly。
thanks~
Reply
#2
hi imprezakd,

if tinker board - TinkerOS_Android 7 Nougat, 
behaved like normal Android installs.. then..
send power key press by..
Code:
input keyevent 26
& screen will turn off...

to turn screen back on again..
Code:
input keyevent KEYCODE_WAKEUP

or.. maybe send a menu key press..
Code:
input keyevent 82

but.... sadly [[[[[[.... TinkerOS_Android 7 Nougat, misbehaves...

if you send power key press.. tinker board will power down...

workaround.. is to make sure you keep moving mouse while you send power key signal..
Code:
input keyevent 26
but this will only lock the screen...

its crazy.. ;-]..... &  from
adb shell dumpsys power
Code:
POWER MANAGER (dumpsys power)

Power Manager State:
 mDirty=0x0
 mWakefulness=Dreaming
 mWakefulnessChanging=false
 mIsPowered=true
 mPlugType=1
 mBatteryLevel=100
 mBatteryLevelWhenDreamStarted=100
 mDockState=0
 mStayOn=false
 mProximityPositive=false
 mBootCompleted=true
 mSystemReady=true
 mHalAutoSuspendModeEnabled=false
 mHalInteractiveModeEnabled=true
 mWakeLockSummary=0x0
 mNotifyLongScheduled=+6s106ms
 mNotifyLongDispatched=-53s893ms
 mNotifyLongNextCheck=+6s106ms
 mUserActivitySummary=0x4
 mRequestWaitForNegativeProximity=false
 mSandmanScheduled=false
 mSandmanSummoned=false
 mLowPowerModeEnabled=false
 mBatteryLevelLow=false
 mLightDeviceIdleMode=false
 mDeviceIdleMode=false
 mDeviceIdleWhitelist=[10007]
 mDeviceIdleTempWhitelist=[]
 mLastWakeTime=2699765 (1808208 ms ago)
 mLastSleepTime=0 (4507973 ms ago)
 mLastUserActivityTime=2868030 (1639943 ms ago)
 mLastUserActivityTimeNoChangeLights=0 (4507973 ms ago)
 mLastInteractivePowerHintTime=2868030 (1639943 ms ago)
 mLastScreenBrightnessBoostTime=0 (4507973 ms ago)
 mScreenBrightnessBoostInProgress=false
 mDisplayReady=true
 mHoldingWakeLockSuspendBlocker=false
 mHoldingDisplaySuspendBlocker=true

Settings and Configuration:
 mDecoupleHalAutoSuspendModeFromDisplayConfig=false
 mDecoupleHalInteractiveModeFromDisplayConfig=false
 mWakeUpWhenPluggedOrUnpluggedConfig=true
 mWakeUpWhenPluggedOrUnpluggedInTheaterModeConfig=false
 mTheaterModeEnabled=false
 mSuspendWhenScreenOffDueToProximityConfig=false
 mDreamsSupportedConfig=true
 mDreamsEnabledByDefaultConfig=true
 mDreamsActivatedOnSleepByDefaultConfig=false
 mDreamsActivatedOnDockByDefaultConfig=true
 mDreamsEnabledOnBatteryConfig=false
 mDreamsBatteryLevelMinimumWhenPoweredConfig=-1
 mDreamsBatteryLevelMinimumWhenNotPoweredConfig=15
 mDreamsBatteryLevelDrainCutoffConfig=5
 mDreamsEnabledSetting=true
 mDreamsActivateOnSleepSetting=true
 mDreamsActivateOnDockSetting=true
 mDozeAfterScreenOffConfig=false
 mLowPowerModeSetting=false
 mAutoLowPowerModeConfigured=false
 mAutoLowPowerModeSnoozing=false
 mMinimumScreenOffTimeoutConfig=10000
 mMaximumScreenDimDurationConfig=7000
 mMaximumScreenDimRatioConfig=0.20000005
 mScreenOffTimeoutSetting=15000
 mSleepTimeoutSetting=-1
 mMaximumScreenOffTimeoutFromDeviceAdmin=2147483647 (enforced=false)
 mStayOnWhilePluggedInSetting=0
 mScreenBrightnessSetting=102
 mScreenAutoBrightnessAdjustmentSetting=0.0
 mScreenBrightnessModeSetting=0
 mScreenBrightnessOverrideFromWindowManager=-1
 mUserActivityTimeoutOverrideFromWindowManager=-1
 mUserInactiveOverrideFromWindowManager=false
 mTemporaryScreenBrightnessSettingOverride=-1
 mTemporaryScreenAutoBrightnessAdjustmentSettingOverride=NaN
 mDozeScreenStateOverrideFromDreamManager=0
 mDozeScreenBrightnessOverrideFromDreamManager=-1
 mScreenBrightnessSettingMinimum=10
 mScreenBrightnessSettingMaximum=255
 mScreenBrightnessSettingDefault=102
 mScreenBrightnessForVrSettingDefault=86
 mScreenBrightnessForVrSetting=86
 mDoubleTapWakeEnabled=false
 mIsVrModeEnabled=false

Sleep timeout: -1 ms
Screen off timeout: 15000 ms
Screen dim duration: 3000 ms

UID states:
 UID 1000: 0
 UID 1001: 0
 UID 1002: 6
 UID 1037: 16
 UID u0a2: 16
 UID u0a7: 16
 UID u0a8: 3
 UID u0a11: 16
 UID u0a19: 0
 UID u0a22: 7
 UID u0a23: 16
 UID u0a24: 16
 UID u0a40: 7
 UID u0a41: 5
 UID u0a44: 16
 UID u0a50: 16
 UID u0a51: 16
 UID u0a56: 6
 UID u0a64: 3
 UID u0a80: 16
 UID u0a84: 3
 UID u0a86: 6
 UID u0a133: 4

Looper state:
 Looper (PowerManagerService, tid 28) {2dd669}
   Message 0: { when=+6s106ms what=4 target=com.android.server.power.PowerManagerService$PowerManagerHandler }
   (Total messages: 1, polling=true, quitting=false)

Wake Locks: size=0

Suspend Blockers: size=4
 PowerManagerService.WakeLocks: ref count=0
 PowerManagerService.Display: ref count=1
 PowerManagerService.Broadcasts: ref count=0
 PowerManagerService.WirelessChargerDetector: ref count=0

Display Power: state=ON

Wireless Charger Detector State:
 mGravitySensor={Sensor name="MPL Gravity", vendor="Invensense", version=1, type=9, maxRange=9.81, resolution=1.0E-5, power=16.239, minDelay=5000}
 mPoweredWirelessly=false
 mAtRest=false
 mRestX=0.0, mRestY=0.0, mRestZ=0.0
 mDetectionInProgress=false
 mDetectionStartTime=0 (never)
 mMustUpdateRestPosition=false
 mTotalSamples=0
 mMovingSamples=0
 mFirstSampleX=0.0, mFirstSampleY=0.0, mFirstSampleZ=0.0
 mLastSampleX=0.0, mLastSampleY=0.0, mLastSampleZ=0.0

...
Settings and Configuration:

  mDecoupleHalAutoSuspendModeFromDisplayConfig=false
  mDecoupleHalInteractiveModeFromDisplayConfig=false
...

maybe setting mDecoupleHalInteractiveModeFromDisplayConfig to true will fix...
but i don't know how to do this [[...

once.. 
[input keyevent 26] & [input keyevent KEYCODE_WAKEUP] or [input keyevent 82]
are working.. then have to figure out how to schedule these commands in a shell script..  
does android have cron jobs ??? 
..I do not know... tbc..

------------------
hope this helps,
k,
Reply
#3
hi imprezakd,

managed to turn off hdmi monitor.. using...  
[input keyevent 61] & [input keyevent 62]

after.. opening Display Setting menu with...
Code:
am start -a android.settings.DISPLAY_SETTINGS
note.. [input keyevent 20] did not work in TinkerOS_Android v14.4.0.5

soooo.... to test.. adb connect to tinker board & adb shell...
Code:
rk3288:/ $ am start -a android.settings.DISPLAY_SETTINGS
Starting: Intent { act=android.settings.DISPLAY_SETTINGS }
Warning: Activity not started, its current task has been brought to the front
rk3288:/ $ input keyevent 61
rk3288:/ $ input keyevent 61
rk3288:/ $ input keyevent 61
rk3288:/ $ input keyevent 61
rk3288:/ $ input keyevent 61
rk3288:/ $ input keyevent 61
rk3288:/ $ input keyevent 61
rk3288:/ $ input keyevent 61
rk3288:/ $ input keyevent 62
this will open HDMI menu....

to toggle the on / off switch, one more "KEYCODE_SPACE" ..
Code:
rk3288:/ $ input keyevent 62

as long as the HDMI menu remains open & active at the front..
you can use [input keyevent 62] to toggle hdmi on/off switch ;-]..

if for some reason.. hdmi menu is closed.. 
then just open Display menu again with..
Code:
am start -a android.settings.DISPLAY_SETTINGS
[input keyevent 61] 8 times.. & then [input keyevent 62]

you can make shell script... 
not a very nice way to do this [[...

nano displayHDMIswitchToggleOnOff
Code:
#!/system/bin/sh
#
# shell script to toggle Display Hdmi Switch from Setting menu..
################################################################
#
# use "KEYCODE_BACK" to go back,
# incase HDMI menu is already open..
sleep 0.25
input keyevent 4
#
# use "KEYCODE_HOME" to start from Home...
input keyevent 3
sleep 0.25
#
# open Display menu..
am start -a android.settings.DISPLAY_SETTINGS
sleep 1
#
# use "KEYCODE_TAB" to pad down to HDMI..
input keyevent 61
sleep 0.0125
input keyevent 61
sleep 0.0125
input keyevent 61
sleep 0.0125
input keyevent 61
sleep 0.0125
input keyevent 61
sleep 0.0125
input keyevent 61
sleep 0.0125
input keyevent 61
sleep 0.0125
input keyevent 61
#
# use "KEYCODE_SPACE" to select tap HDMI..
sleep 0.25
input keyevent 62
#
#  use "KEYCODE_SPACE" to select tap toggle Switch On/Off...
sleep 0.35
input keyevent 62
sleep 0.25
#
# use "KEYCODE_BACK" to go back..
sleep 0.35
input keyevent 4
sleep 0.25
input keyevent 4

connect to tinker board to push file...
Code:
adb connect IP
adb root
adb connect IP
adb remount

adb push displayHDMIswitchToggleOnOff /system/bin

adb shell chmod 755 /system/bin
Code:
rk3288:/ # ll /system/bin/displayHDMIswitchToggleOnOff
-rwxr-xr-x 1 root shell 948 2020-10-19 08:39 /system/bin/displayHDMIswitchToggleOnOff*
rk3288:/ # stat /system/bin/displayHDMIswitchToggleOnOff
 File: `/system/bin/displayHDMIswitchToggleOnOff'
 Size: 948      Blocks: 8       IO Blocks: 4096        regular file
Device: b30ah/45834d     Inode: 1899     Links: 1
Access: (755/-rwxr-xr-x)        Uid: (0/    root)       Gid: (2000/   shell)
Access: 2020-10-19 08:39:27.000000000
Modify: 2020-10-19 08:39:27.000000000
Change: 2020-10-19 08:43:08.650477570
rk3288:/ #

now you can use..
Code:
rk3288:/ # displayHDMIswitchToggleOnOff
Starting: Intent { act=android.settings.DISPLAY_SETTINGS }
rk3288:/ #
from inside adb shell...

or..
Code:
adb shell displayHDMIswitchToggleOnOff

note... sometimes the timing is off.. 
so you have to run it again.. 

now have to find a way to check from shell the state of HDMI.. 
if its on/off..
then run displayHDMIswitchToggleOnOff...
check HDMI state again.. 
if not set.. 
run again.. ;-]..

great.. just found [sys.hdmi_status.aux].. with getprop..

when HDMI is On...
adb shell getprop | grep hdmi
Code:
[persist.sys.hdmi.addr.playback]: [4]
[persist.sys.hdmi.cec_enable]: [false]
[ro.hdmi.device_type]: [4]
[ro.rk.hdmi_enable]: [true]
[sys.hdmi_status.aux]: [on]
[sys.hdmicec.version]: [1.0]
note.. [sys.hdmi_status.aux]: [on]

then .. run..
Code:
adb shell displayHDMIswitchToggleOnOff

when HDMI is Off..
adb shell getprop | grep hdmi
Code:
[persist.sys.hdmi.addr.playback]: [4]
[persist.sys.hdmi.cec_enable]: [false]
[ro.hdmi.device_type]: [4]
[ro.rk.hdmi_enable]: [true]
[sys.hdmi_status.aux]: [off]
[sys.hdmicec.version]: [1.0]
note.. [sys.hdmi_status.aux]: [off]

then .. run..
Code:
adb shell displayHDMIswitchToggleOnOff
again to turn HDMI back on....

I wonder if you can set [sys.hdmi_status.aux] with getprop / setprop ???
hmmmmmm....

Code:
k247@yoga700-11isk:~/temp/tinkerboard/v14_4_0_5
$ adb shell getprop sys.hdmi_status.aux
on
k247@yoga700-11isk:~/temp/tinkerboard/v14_4_0_5
$ adb shell setprop sys.hdmi_status.aux off
k247@yoga700-11isk:~/temp/tinkerboard/v14_4_0_5
$ adb shell setprop sys.hdmi_status.aux on
k247@yoga700-11isk:~/temp/tinkerboard/v14_4_0_5

omg.... it's that easy... ;-]...

from shell....
Code:
setprop sys.hdmi_status.aux off
to turn off HDMI...

&
Code:
setprop sys.hdmi_status.aux on
to turn on HDMI...

to find status of HDMI,, use..
Code:
getprop sys.hdmi_status.aux

---------------
hope it helps,
k,
[-] The following 1 user Likes k247tEK's post:
  • imprezakd
Reply
#4
(10-20-2020, 06:32 PM)Rajaghere Wrote: My app must be able to control this function.(example:am 8:00 on,pm 18:00 off)

or other ways to switch HDMI regularly。

is this any help ?
Schedule tasks and jobs intelligently in Android
Multiple ways to schedule repeated tasks in android

---------------
k,
Reply
#5
This worked for me !
Thanks a million/bunch for your help! It was very kind of you.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)