droidian-mt6765 / adaptation-droidian-garden

Droidian adaptation files for Redmi 9A/9AT codenamed dandelion and Redmi 9C/9C NFC codenamed angelica (and possibly 9i, 10A)
5 stars 2 forks source link

Screen touching and power button not work on Dandelion #1

Closed maxiee closed 1 year ago

maxiee commented 2 years ago

Hi @FakeShell:

Thanks for your porting Droidian to Redmi 9A (Dandelion), is amzing! I followed the guide and got it running successfully!

I'm having some problems with the touch screen and power button not taking effect. So I can only use the mouse, and once the device is locked, I can't unlock it.

My installation process is as follows:

File Preparation

I already have OrangeFox in my phone, so I don't have OrangeFox-R11-garden-droidian.img installed.

The install process is following Dandelion installation.

Is there something wrong with my configuration?

Thanks for your guidance, and if there is anything I can do to help make Droidian work better, I'd be happy to participate.

FakeShell commented 2 years ago

Hey Maxiee Yes i am aware of this issue. We had a workaround when I was porting dandelion/angelica back in the day but it does not work anymore. The issue is not specific to this device, same issue with rosemary (Redmi Note 10S) and VollaPhone. Apparently it is an issue with MTK devices. You can join https://t.me/DroidianLinux and follow up on https://t.me/DroidianLinux/46528 to see what is going on. It is a very weird issue we have not found any fix so far. Any help is appreciated.

maxiee commented 2 years ago

Thanks for your explanation. I'm going to join the TG group. 😄

maxiee commented 2 years ago

Progress update on two things.

I flashed newer nightly droidian-OFFICIAL-phosh-phone-rootfs-api29-armhf-nightly_20220809.zip with adaptation-droidian-garden.zip.

  1. I captured some logs:

Logs with: sudo journalctl -b 0 --no-pager |grep pho > log_pho_2022-08-10.log:

log_pho_2022-08-10.log

Logs with sudo journalctl -b 0 --no-pager > log_pho_2022-08-10-all.log:

log_pho_2022-08-10-all.log

These logs are from the Dandelion device with abnormal touch screen and power button.

  1. I observed some new phenomena:

The touch screen took effect once! But I didn't do anything special, I was just on my computer at the time ssh to my phone via LAN. I don't think it has anything to do with ssh. At least this means that the core of Dandelion's touchscreen is working under bookworm.

I've observed some new patterns with the power button, after the device starts up (goes to the lock screen page), if I do nothing and wait for the device to naturally rest the screen. Then pressing the power button may wakes up the screen. But it doesn't work all the time, at least I've succeeded a few times.

Tomorrow I will study the captured logs carefully and look for useful details. My country has disabled Telegram, so I'm having some trouble registering for an account. Currently I am accessing Droidian channels through the bridge from Droidian TG to Matrix. :rofl:

FakeShell commented 2 years ago

Hey About that power button and letting the device sleep after boot: Yes I have realized the same kind of behavior. After letting it sleep naturally and waking it up via the power button then the power button cannot be used anymore.

Normally getting called or getting a notification wakes up the device atleast it has this behavior on my port of surya (Poco X3 NFC) and my daily driver miatoll (Redmi Note 9S) but it does not wake up the screen on dandelion/angelica.

Apparently if we set brightness to 0 then turn the screen off then turn the screen on and set the brightness to max (2047) it will wake up. During this discovery i found out that when the power button is pressed even tho screen does not turn back on but the state of display changes in wlr-randr.

So as a result of this I thought of a simple script. I wrote a script which used wlr-randr to see if the screen is on or not. If it was on then set brightness to 0 (to make it lock the screen without issues) and set it to max when screen if off (to get the same kind of behavior from my last experiment). It failed miserably brightness was set but no display. I also tried it the other way around just for the hell of it. Also failed.

There is a method to force the screen on in whatever state it is: wlr-randr --output HWCOMPOSER-1 --on && echo 0 > /sys/class/leds/lcd-backlight/brightness && wlr-randr --output HWCOMPOSER-1 --off && wlr-randr --output HWCOMPOSER-1 --on && echo 2047 > /sys/class/leds/lcd-backlight/brightness but this bugs out phosh and screen cannot be unlocked. So right now the only way to actually turn the screen back on is to restart phosh.

Running libinput debug-events shows that the power button does register and works fine aswell. While speaking to Eugenio (Maintainer of Droidian) he said that this is probably because of the compositor not setting brightness to 0 at lock.

My Telegram name is Barry (My ID is FakeShell but I'm guessing you cannot see my ID over at the matrix side). You can also reply to my message if you have any question or any discovery. I am very curious to know why this is happening because it worked with older images.

maxiee commented 2 years ago

Report some progress:

The touch screen is working fine. I just flashed PBRP Recovery, rebooted, and the touch worked fine after that. I couldn't figure out why, but kept a log of the before and after for subsequent research.

I went through the chat logs in the TG Channel and saw people discussing the power button issue, so I guess I'm keeping up with the context. :smile:

I tried your steps for brightness and lock screen in the last message and came to the same conclusion.

So for the next few days, I will also focus on the power button issue. If I make progress, I'll try to join the discussion in the TG Channel.

thatsitipl commented 1 year ago

I also have done some debugging with the power button issue. I found out that if i press the power button and do the gestures to set the backlight brightness it turns on. After some digging through the dmesg logs i saw that this uses the gnome settings daemon which calls this function : [3870:gsd-power][LCM]lcm_setbacklight_cmdq,nt36525b backlight: level = 1378 lcd_bl_en = 1. Hope this helps.

thatsitipl commented 1 year ago

I now have a simple C programm which polls every second and it doesn't bug out phosh. I achieved the screen detection by looking at the /sys/android_brightness/brightness_light file which sets it's value to 5 if the screen is on and to 0 if it is off. This is the code: button_detect.c.txt

Here is a statically compiled version: power_button_helper.zip

FakeShell commented 1 year ago

pardon i just looked at your comment have been very busy with fastbootable images (added support for fastbootable images or over 5 devices during the last week) can you explain more of what you did and what you achieved during the last few days? thanks

thatsitipl commented 1 year ago

Explanation:

In the last days i tried to get the power button problem fixed. I achieved this by writing a simple C program which checks every half second if /sys/android_brightness/brightness_light changed from 0 to 5. This indicates that the device is now on. If it sees that it switched to 5 it reads the current status of sys/class/leds/lcd-backlight/brightness which holds the brightness before the device was looked. Lastly it writes a 0 into /sys/class/leds/lcd-backlight/brightness and after that the saved value. This has to be done because the brightness must change if you want the screen to light up.

Changes:

I now changed the sleep method from sleep() to usleep() to allow for faster polling rates. And it also saves the old brightness instead of fully turning it on.

The source is located in power_button_helper.c and can be compiled with : gcc -O3 -static power_button_helper.c -o power_button_helper

A precompiled version is already included : power_button_helper

(For testing purpose) I also have a python program which allows you to set the brightness using dbus.

power_button.zip

To run on startup:

  1. Copy the power_button_helper to /usr/local/bin/power_button_helper e.g. : sudo cp power_button_helper /usr/local/bin/power_button_helper
  2. Create a file in /etc/systemd/system/power_button_helper.service and copy this into it :

[Unit] Description=A Workaround for the power button problem. [Service] ExecStart=/usr/local/bin/power_button_helper [Install] WantedBy=multi-user.target

  1. run : sudo sytemctl enable power_button_helper
  2. Reboot
thatsitipl commented 1 year ago

Hope this is enough explanation.

FakeShell commented 1 year ago

after testing it seems to set the brightness to max at each power press but good job please make a github repository for your power button helper program and pr the compiled version to this repository (the binary to /usr/bin and the service to /debian) thanks

thatsitipl commented 1 year ago

@FakeShell which version did you run the first one or the second one. If the second one still doesn't save the brightness try recompiling it with Debug enabled (line 12). And post the output.

thatsitipl commented 1 year ago

I now have created a pr #2 for the fix and a repo with the source code located at : power_button_helper.

thatsitipl commented 1 year ago

I now discovered that the touch screen is not rotating but the screen is. I don't know if this is a problem with phosh,phoc or the mediatek driver. And all the methods for rotating the touchscreen using "Coordinate Transformation Matrix" with xinput don't work since phosh is using wayland.

FakeShell commented 1 year ago

rotation is an issue with some devices with phosh works on a few but not on others haven't investigated that. it used to work fine i will check your pr and fork your repository just to have it on this organization

thatsitipl commented 1 year ago

Ok i will investigate the rotation issue next.

FakeShell commented 1 year ago

Closing as the issue if now resolved If you want you can open another issue for rotation