TrebleDroid / treble_experimentations

Scripts to automatically build/CI/Release TrebleDroid GSI
Other
203 stars 26 forks source link

CAT S22 Front Screen inoperable #75

Open Saphar opened 7 months ago

Saphar commented 7 months ago

Related:

https://github.com/phhusson/treble_experimentations/issues/2338

Current Behavior:

Screen does not start on boot.

Describe the bug

I would like that the external screen would start turn on on boot.

Expected behavior

Turn on screen and show notifications.

Smartphone (please complete the following information):

Additional context

Following that thread I am able to set the property to false and if I restart the hwcomposer then the screen lights up and I am able to write an app that would show notifications. (Presentation screen, I copied some code from stock rom SystemUI.apk) I tried adding this property to rw-system.sh but doesn't work.

I have a rooted stock rom in case anyone could help me debug this and set the right property. There must be a simple trigger that sets the external display power on.

Saphar commented 7 months ago

logcat.txt Here is the booting of the stock ROM rooted.

B-CyberFunker commented 1 month ago

Hey,

I know it's been awhile since you posted but this is an issue I'm wanting to look into also - it's basically the only reason I'm still running the stock ROM and it seems most are focused on VoLTE for the S22. That isn't something I care about. Android specific coding knowledge is a bit limited so bare with.

Based on what I know right now there are three possible ways of doing this:

Looking at the logcat nothing specific to that property or GSI in general sticks out, but there are a few interesting things:

HWComposer: isConnected failed for display 1: Invalid display

DisplayManagerService: Display device added: DisplayDeviceInfo{"HDMI Screen": uniqueId="local:1", 128 x 128, modeId 2, defaultModeId 2, supportedModes [{id=2, width=128, height=128, fps=30.000002}], colorMode 0, supportedColorModes [0], HdrCapabilities HdrCapabilities{mSupportedHdrTypes=[], mMaxLuminance=500.0, mMaxAverageLuminance=500.0, mMinLuminance=0.0}, allmSupported false, gameContentTypeSupported false, density 213, 325.12 x 325.12 dpi, appVsyncOff 1000000, presDeadline 33333333, touch EXTERNAL, rotation 0, type EXTERNAL, address {port=1}, deviceProductInfo null, state UNKNOWN, FLAG_SECURE, FLAG_SUPPORTS_PROTECTED_BUFFERS, FLAG_PRESENTATION}

SurfaceFlinger: Setting power mode 2 on display 1 SDM : DisplayBase::SetDisplayState: Set state = 1, display 1 SurfaceFlinger: Finished setting power mode 2 on display 1 DisplayManagerService: Display device changed state: "HDMI Screen", ON

MediaRouter: Selecting route: RouteInfo{ name=Phone, description=null, status=null, category=RouteCategory{ name=System types=ROUTE_TYPE_LIVE_AUDIO ROUTE_TYPE_LIVE_VIDEO groupable=false }, supportedTypes=ROUTE_TYPE_LIVE_AUDIO ROUTE_TYPE_LIVE_VIDEO , presentationDisplay=Display id 1: DisplayInfo{"HDMI Screen", displayId 1, FLAG_SECURE, FLAG_SUPPORTS_PROTECTED_BUFFERS, FLAG_PRESENTATION, FLAG_TRUSTED, real 128 x 128, largest app 128 x 128, smallest app 128 x 128, appVsyncOff 1000000, presDeadline 33333333, mode 2, defaultMode 2, modes [{id=2, width=128, height=128, fps=30.000002}], hdrCapabilities HdrCapabilities{mSupportedHdrTypes=[], mMaxLuminance=500.0, mMaxAverageLuminance=500.0, mMinLuminance=0.0}, minimalPostProcessingSupported false, rotation 0, state ON, type EXTERNAL, uniqueId "local:1", app 128 x 128, density 213 (325.12 x 325.12) dpi, layerStack 1, colorMode 0, supportedColorModes [0], address {port=1}, deviceProductInfo null, removeMode 0}, DisplayMetrics{density=1.3312501, width=128, height=128, scaledDensity=1.3312501, xdpi=325.12, ydpi=325.12}, isValid=true }

MediaRouter: Selecting route: RouteInfo{ name=Phone, description=null, status=null, category=RouteCategory{ name=System types=ROUTE_TYPE_LIVE_AUDIO ROUTE_TYPE_LIVE_VIDEO groupable=false }, supportedTypes=ROUTE_TYPE_LIVE_AUDIO ROUTE_TYPE_LIVE_VIDEO , presentationDisplay=Display id 1: DisplayInfo{"HDMI Screen", displayId 1, FLAG_SECURE, FLAG_SUPPORTS_PROTECTED_BUFFERS, FLAG_PRESENTATION, FLAG_TRUSTED, real 128 x 128, largest app 128 x 128, smallest app 128 x 128, appVsyncOff 1000000, presDeadline 33333333, mode 2, defaultMode 2, modes [{id=2, width=128, height=128, fps=30.000002}], hdrCapabilities HdrCapabilities{mSupportedHdrTypes=[], mMaxLuminance=500.0, mMaxAverageLuminance=500.0, mMinLuminance=0.0}, minimalPostProcessingSupported false, rotation 0, state ON}, DisplayMetrics{density=1.3312501, width=128, height=128, scaledDensity=1.3312501, xdpi=325.12, ydpi=325.12}, isValid=true }

StatusBar: presentationDisplay != null true

StatusBar: Showing presentation on display: Display id 1: DisplayInfo{"HDMI Screen", displayId 1, FLAG_SECURE, FLAG_SUPPORTS_PROTECTED_BUFFERS, FLAG_PRESENTATION, FLAG_TRUSTED, real 128 x 128, largest app 128 x 128, smallest app 128 x 128, appVsyncOff 1000000, presDeadline 33333333, mode 2, defaultMode 2, modes [{id=2, width=128, height=128, fps=30.000002}], hdrCapabilities HdrCapabilities{mSupportedHdrTypes=[], mMaxLuminance=500.0, mMaxAverageLuminance=500.0, mMinLuminance=0.0}, minimalPostProcessingSupported false, rotation 0, state ON}, DisplayMetrics{density=1.3312501, width=128, height=128, scaledDensity=1.3312501, xdpi=325.12, ydpi=325.12}, isValid=true

PresentationScreen: PresentationScreen registerReceiver PresentationScreen: onCreate() PresentationScreen: External display: Set black background by default .... there are a few more mentions of "PresentationScreen" but I think at this point it's all just stuff that happens whenever the presentation screen is on. What we want to do happens before this.

It seems hardware wise the screen is treated like an external display, hence the name "HDMI Screen". It seems before Display manager sets the display up HW composer actually fails to pick it up. I think we'd want to somehow make Display Manager do that same setup on GSI, but I honestly have no idea how you'd do that at this point.

I'm guessing you reused code from the presentationscreen classes in the systemui apk? How exactly did you apply this to GSI, did you some how implement these into the GSI SystemUI? Or is an additional app able to do it?

Saphar commented 1 month ago

Hi,

Thank you for your posting. It's interesting what you found in the init.cpp. Here is what I did so far: I stick with Treble build on Android 11, I have a feeling that since the stock ROM is on Android 11 this works the best. All I know is testing other versions there were many lacks on it. Then I wrote some patches for the code, for example added this to phh-on-boot.sh file:

if getprop ro.vendor.build.fingerprint | grep -iq -e S22FLIP; then
        if ! getprop ro.vendor.gsi.image_running | grep -iq -F false; then
                setprop ro.vendor.gsi.image_running false
                setprop ctl.restart vendor.hwcomposer-2-1
        fi
fi

This will restart the hardware composer after boot to and enable the external screen. To me it's still a mistery why this value has to be set...

Then to display anything on the external screen you can either use that stock presentation screen or write your own app. I started writing a simple app that shows the clock and some more info.

There is one main issue which I am not able to figure out. That from time to time when you wake up the phone it is extremely slow, not responding to anything for 1min sometimes. After which it works normal.

(then there are some hardware problems I am facing, in certain countries it only connects with certain providers)

B-CyberFunker commented 1 month ago

I think given the several different ROMs currently in play, a seperate app is better for compatability. From what I can find on the presentation class something that works on A11 should be fine up to 14 also.

I can't find any meaningful info on that value, and it doesn't seem to have any other consequences. Maybe a Logcat with it unset/true would shed some light.

I had the same issue occasionally on the stock ROM also. It's become a rarity since removing google services and only really happens if I leave it for a very, very long time. It seems eventually everything gets cached and trying to use it again requires everything to be pulled out of cache.

I'm going to put something together to display a presentation screen and expirement. Ideally we'd wanna know where that value originally comes from so we can avoid the hwcomposer restart.

B-CyberFunker commented 2 weeks ago

Hello again,

So for one I've not found any way to get the screen to be active on boot. I managed to get MagiskHidePropsConfig to set gsi running to false on boot, but I had to do it so late in the boot that hwcomposer still needed to be restarted.

Besides that I have been putting together an app that can push content to the second display and it's already got the potential to be better than that on the stock ROM as I am pulling through information for all notifications (Stock ROM only does calls/texts if I remember right). I'm also currently working on basic customization like fonts and of course the wallpaper.

I'm quite happy with the progress, especially since I've never made anything in android or kotlin before and I haven't done any proper dev since the early 2010s (unless PowerFX counts...).

My main issue is getting only display 1 to turn on. So after a lot of headache I realized that the method I was using to turn it off, (surface flinger) cannot turn the display on. At best, it sets the display to "Normal" which as you might expect is off when the device is locked.

This is the bit where I need your help. You said in the original post that you'd pulled some code from the stock systemui, would you be able to find out how it turns that display on? Currently I'm having to wake the whole device and I'd prefer not doing that if possible. I had a look and although I've found info on how the presentation manages what's on the display, I've not found the code that actually manages the display(s).

I would've thought that since the presentation classes are in systemui, whatever code launches the presentation is also in there, and potentially the code that turns the second screen on/off is also there, since the app will have to at minimum identify the second display to display the presentation on it.

However since there has to be something that watches for the folds of the phone, I have a feeling it might be built into whatever does that. I have no idea what that might be.

phhusson commented 2 weeks ago

Cool on your development! I'd be curious to see it, both a demo and the code!

WRT turning screen off and on, this might have been burried, but originally I had this code: https://github.com/phhusson/treble_app/blob/dev/razr/app/src/main/java/me/phh/treble/app/Razr.kt#L95

I can't really tell whether it suffers the issues you mentionned or not

Saphar commented 2 weeks ago

Exactly, then in your Lid.kt file I added this to turn it off after 2s:

                            handler.postDelayed({
                                Log.d("PHH", "Turn off external screen delayed 2s.")
                                setDisplayPowerModeMethod.invoke(null, displayToken, 0)
                            }, 2000)

This is only on my development version of the Treble app, I still want to add keyboard light and some other features.

@B-CyberFunker do you have an email where I could exchange with you also what I did so far? I am unable to actively continue, but maybe I could help you.

B-CyberFunker commented 2 weeks ago

Hey guys,

@phhusson I referenced the Razr code and also Lid.Kt a fair bit for this project, both have been extremely helpful. I tried also using a UeventObserver for the lid, even using identical code to what you used, but it doesn't seem to detect anything. Currently I'm using a combination of the screen and proximity sensor... It's good enough but not ideal.

I've been using setDisplayPowerModeMethod.invoke(null, displayToken, 0) to turn the display off no problem, but as I described my main issue is using setDisplayPowerModeMethod.invoke(null, displayToken, 2) to turn it back on doesn't work. Logcat reports the powermode has been set but nothing actually happens.

I can't recall if on the stock rom, the second display is just turned on by itself or if the whole device is woke. If it's the former I'd like to know how.

@Saphar Keyboard light is quite easy actually since it can be toggled with shell commands. All you need is something like Runtime.getRuntime().exec("echo 0 > /sys/class/leds/keyboard_light/brightness") (echo 0 for off, 1 for on).

It would be ideal if I could build this into the Treble app since I'm currently fighting it a little bit, and I think a lot of things would be easier if this was a system app. There are a number of things I've had to use work arounds for, and some things seem outright impossible at this stage.

Although I briefly tried to do this it didn't work I'm guessing because I didn't sign the apk correctly. I have frankly no idea how to do it. If you could help me out with that @Saphar I could make the performance a hell of a lot better very quickly. There are a few people on XDA who I've been sorta using as guinea pigs so it'd be nice to give them something more stable...

Code is here: https://github.com/B-CyberFunker/CATS22Present There are some images here: https://github.com/B-CyberFunker/CATS22Present/issues/11

You can email me @ quackprivate@duck.com , and I'll email you my discord if you want it.