I am trying to create an app specifically for devices with a front and rear screen, and a custom ROM. The Hardware I’m using for testing is a S22 Flip.
On devices like these when you install a custom ROM the second screen functionality can be lost, the main aim of my app is to restore functionality like displaying time, date, signal, battery, and notifications on the second screen.
The default behaviour on custom ROMs is for it to be on whenever the main display is, and for it to turn off about 5 seconds after the main display. I need it to be off whenever the main display is on, and for it to turn on for a few seconds in certain circumstances when the main display is off – like immediately after the main display is switched off, when notifications are received, etc.
Capturing these isn’t a problem – the problem is actually making the screen turn on.
I’m using surface flinger to invoke “setDisplayPowerMode”.
It is invoked by a Root Service: https://github.com/topjohnwu/libsu – since without root access any attempt to use this results in Permission Denial even with android.permission.ACCESS_SURFACE_FLINGER in the manifest.
// Grab Display IDs
val sfids = SurfaceControl::class.java.getMethod("getPhysicalDisplayIds").invoke(null) as LongArray
// Grab Token for Display 1
val token = SurfaceControl::class.java.getMethod("getPhysicalDisplayToken", Long::class.java).invoke(null, Globals.sfids[1])
// Define the Powermethod
val displayPowerMethod = SurfaceControl::class.java.getMethod("setDisplayPowerMode", IBinder::class.java, Int::class.java)
// Turn Display 1 off
displayPowerMethod.invoke(null,token,0)
// Turn Display 1 On
displayPowerMethod.invoke(null,token,2)
When I try to turn the display off this way, Logcat reads:
surfaceFlinger: Setting power mode 0 on display 1
surfaceFlinger: Finished setting power mode 0 on display 1
and the display turns off.
When I try to turn the display on this way, Logcat reads:
surfaceFlinger: Setting power mode 2 on display 1
surfaceFlinger: Finished setting power mode 2 on display 1
…except nothing happens.
Why could this be?
Is there another method for turning on a specific display (not all displays! I’m currently using that as a work around but I want the main display to remain off if possible) that I can try?
TalkB is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.