yashsingh1/xdaforums huggingface dataset:
[Upgrading, Modifying and Unlocking] TalkB:
That first issue is interesting. There shouldn't be any interaction with the primary display at all. I did notice at times when restarting hwcomposer, it'd restart twice. The only crashes I've encountered are limited to the app and occur if the second screen isn't connected.

Currently it just uses a standard service so the screen there isn't any direct interaction with the screen other than displaying the time on it. Brightness, timeout time, etc, are just whatever the system decides.

Getting it to come on only when the main screen is off and remaining on for a decent time afterwards is the next step. Android does have a default call you can listen for whenever the device is "interactive" - so volume button presses and notifications should make the screen light up.

gsi.image_running does reset after reboot. I've been trying to use magisk to set the value early enough in the boot to remove the need for a hwcomposer restart, so far I've failed. If you set it too early it'll just get overridden.

Really we need to know what is setting the value to blank to begin with, but there is essentially no information about that property.
[Upgrading, Modifying and Unlocking] TalkB:
Rear screen update: it turns out, since Android 10, turning a screen off is quite hard. Apps signed with the same signature as the ROM can do it - the treble app does it when you fold the device.

Normal apps cannot do it at all. I am able to ask for the screen to be turned off, but Surface flinger just responds that permission is denied. You cannot grant this permission in the traditional ways.

I'm able to make the app execute shell commands with root - this sadly doesn't solve my problem, but it could be useful for other things. I could quite easily make it so the keyboard backlight turns on/off when the screen is on/off.

I've just added some libraries that allow me to create a service with root permissions. Once I read through the documentation and figure out how to use it, I should be there.

I'm trying to make this as minimal as possible but I just don't see another way, and since this app is intended for use on aftermarket ROMs I imagine most will be rooted anyway.

All of that aside, the service is able to listen for the screen turning on/off reliably. It is very easy to listen for additional system events also. Everything is logged in logcat which makes everything easier for everyone.

In my testing the presentation runs very reliably throughout the day, by it's killed when you leave the phone overnight, so more work is needed.

It is technically "useful" in it's current state, but the display remains on when you're using the phone which isn't ideal. That's my main hurdle at the moment. It really doesn't help that most of my research brings up solutions that involve turning off all displays, or even locking the device - which doesn't help here.
[Upgrading, Modifying and Unlocking] OwedtAlex:
I have attempted the installation of Lineage 18 on my CAT S22 using nuttydoc's guide. I got as far as step 6 (Prepare partitions and install GSI image) and have hit a problem.

I ran the code:

fastboot delete-logical-partition product

The terminal confirmed this had been done.

I then ran the code:

fastboot flash system lineage-18.1-20240121-UNOFFICIAL-a64_bvS.img

The terminal responded with:

fastboot: error: cannot load 'lineage-18.1-20240121-UNOFFICIAL-a64_bvS.img': No such file or directory

The phone will now not work (presumably because the product partition is missing).

I have been able to access the Android Recovery Menu and ran the "wipe data/factory reset" option and also the "wipe cache partition" option.

The phone stays on the CAT logo splash screen for about 30 seconds then displays a menu with Start, Restart Bootloader, Recovery Mode, Power Off, Boot to FFBM.

I am a complete novice to Linux and phone modding so please excuse my ignorance of these skills, but is it possible that the phone can be restored to a position where I can re-attempt the Lineage installation or have I completely wrecked it?

I would be very grateful for any help anyone can offer - thanks!
[Upgrading, Modifying and Unlocking] nuttydoc:
"fastboot: error: cannot load 'lineage-18.1-20240121-UNOFFICIAL-a64_bvS.img': No such file or directory"

Fastboot command is not able to find file named 'lineage-18.1-20240121-UNOFFICIAL-a64_bvS.img'

Is there file with such name in same folder from which you are running fastboot command?
[Upgrading, Modifying and Unlocking] OwedtAlex:
Thanks for your reply. I must admit that I was unsure about this step and have since completely deleted the image file from my Linux machine and downloaded it again. I used the unxz command to decompress it and it now resides in my Downloads directory.

When I first attempted this it was residing in my Desktop directory - I am unsure whether or not I executed the fastboot command from there.
[Upgrading, Modifying and Unlocking] TalkB:
Try again, and make note of the directory before the fastboot command. it should be the folder the file is in. If it isn't, either move the file to the current folder, or use cd to navigate to the folder where the image is. That should resolve it.
[Upgrading, Modifying and Unlocking] OwedtAlex:
Thanks for your reply.

I think my main problem is that with the phone in its current state I will not be able to access the developer options menu in order to enable OEM unlock and enable usb debugging.
[Upgrading, Modifying and Unlocking] nuttydoc:
You only need to unlock bootloader once. There is no need of usb debugging for fastboot to work.
[Upgrading, Modifying and Unlocking] OwedtAlex:
OK - thanks. I will away and try it and report back here with the results.
[Upgrading, Modifying and Unlocking] OwedtAlex:
When I run:

~/Downloads$ adb reboot bootloader

The terminal responds with:

daemon not running; starting now at tcp:5037

* daemon started successfully

error: no devices/emulators found

It appears that the terminal is not connecting to my phone.
[Upgrading, Modifying and Unlocking] nuttydoc:
Use power + vol down (long press), it will start phone in bootloader, use "fastboot reboot fastboot" to go in fastbootd
[Upgrading, Modifying and Unlocking] OwedtAlex:
OK - thanks. I'll give it a try.
[Upgrading, Modifying and Unlocking] OwedtAlex:
OK this returned:

:~/Downloads$ fastboot reboot fastboot

Rebooting into fastboot OKAY [ 0.162s]

< waiting for any device >

Finished. Total time: 38.468s

Will I be able to proceed with the rest of the installation from here?
[Upgrading, Modifying and Unlocking] nuttydoc:
yes
[Upgrading, Modifying and Unlocking] OwedtAlex:
OK - thanks!
[Upgrading, Modifying and Unlocking] OwedtAlex:
OK - it's done! Just going through the Lineage OS setup screen now.

Can't say how grateful I am to you for helping me to resurrect my phone and install Lineage OS on it.

No doubt I will be back again when I have explored Lineage and the rest of the phone with some more questions but in the meantime - many thanks!
[Upgrading, Modifying and Unlocking] TalkB:
Hello all,

I've been busy the last few days trying to get this app working right.

My main issue is now, the best way to toggle a specific screen is using Surfaceflinger's SetPowerMode. I am able to turn the screen off with this, but I cannot turn the screen on again even though LogCat shows Surfaceflinger setting power mode 2 on display 1.

Research turns up nothing since most people just wake the device up if they want the screen to turn on, trying to get control of a second screen on a dual display device is a very niche requirement... I'm going to have to make some posts and hope someone spots what I'm doing wrong.

For now I have implemented a work around - I am waking the device and then putting it to sleep again. It's not ideal as it limits the responsiveness significantly and if you try and use the device ~4 seconds after locking it, you can create issues. But it's a start.

Besides that, the second screen is turned off reliably when you use the phone, a button has been added to trigger the shell commands for you, and the app now listens for Phone calls, SMS and dis/connecting chargers.

There's also a progress bar which gets to full once both services are running, and handling for no second display and exceptions which should prevent most crashes. The user is also prompted in cases where the second screen couldn't be found, or root access wasn't obtained.

Finally, the date is now on the presentation as well as the time.

I've also added a lot of comments to the source, as well as logcat logging, so feel free to try and figure out how it's working and suggest anything better if you have any ideas.

If you're interested, https://github.com/B-CyberFunker/CATS22Present/releases

Once I figure out how to turn the screen on without using this sketchy workaround the app will work much and I'll be able to easily control how long I want the screen to be on for. With that we'll be well on our way to having something useful.
[Upgrading, Modifying and Unlocking] arkeo-ca:
Based on the development work in this thread, I jumped in and I purchased an S22. I should receiving it today. I'll set it up over the weekend (flash over to LOS20, most likely), but I'd love contributing to further development, especially as it comes to that second screen.

My programming background is in Python and Rust, so I'll have to learn Kotlin, but once I'm settled in and have a good grasp of the device, I'd love to start contributing where I can to that app/service you're building, @TalkB .

I am hoping to be able to turn this phone in the ultimate privacy-oriented feature-phone down the road.
[Upgrading, Modifying and Unlocking] nuttydoc:
I am not able to find out adb commands required for starting needed services for this app, can you post them here.
[Upgrading, Modifying and Unlocking] TalkB:
That'd be great. Here's the source: https://github.com/B-CyberFunker/CATS22Present I'm far from the best dev out there but it should give you some idea of how services can communicate with one another and listening for system events.

Also I'm using https://github.com/topjohnwu/libsu for root access which is required here. I can't find any way of getting extensive root access without it.

The only programming I've done in the last 5 years is PowerFX, I'm not even sure if that counts. Before that it was Python and C#. I'm learning from scratch also.

Currently my main issue is a very strange one and it'd be interesting to see if it's related to the ROM, if you install LOS, we can test if it's still a problem on that ROM.

Basically I'm using an Android Service called SurfaceFlinger to ask the secondary display to turn on/off. This is done like so:

// Identify the Display and setup a Power Method
// 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, sfids[1])
// Define the Powermethod
val displayPowerMethod = SurfaceControl::class.java.getMethod("setDisplayPowerMode", IBinder::class.java, Int::class.java)

// Invoke the Power Method with a parameter for the Power Mode.
// Turn Display 1 off
displayPowerMethod.invoke(null,token,0)
// Turn Display 1 On
displayPowerMethod.invoke(null,token,2)

Turning the second screen off like this works, but turning it on doesn't.

As a work around, I'm executing shell commands that wake the device (input keyevent KEYCODE_WAKE_UP) and put it back to sleep (input keyevent KEYCODE_SOFT_SLEEP).

The issue is, the main display turning on/off is a trigger for turning the secondary display off/on, so this method requires additional checks to prevent that, and it's not very responsive.

The weirdest part is in logcat, SurfaceFlinger reports that the display has infact been turned on even though it hasn't....

I could put something barebones together to test this as I'm starting to think it's something quite deep with how the ROM operates.

If it does work on LOS then I'd move over and focus on that until I can somehow come up with a fix for Trebledroid. Most people seem to be using LOS anyway.
[Upgrading, Modifying and Unlocking] TalkB:
They shouldn't be needed anymore. Assuming you have some sort of root access, push the button and it'll do it for you. Sorry, I don't think I made that very clear, I am no UI designer :p

Just in case:

To allow the app to get display Ids (this only needs to be done once):

settings put global hidden_api_policy_pre_p_apps 1

settings put global hidden_api_policy_p_apps 1

To enable the second dispaly:

setprop ro.vendor.gsi.image_running false

setprop ctl.restart vendor.hwcomposer-2-1
[Upgrading, Modifying and Unlocking] nuttydoc:
Currently app just force closes after starting even after enabling secondary display.
[Upgrading, Modifying and Unlocking] TalkB:
Bugger. Can you post a logcat?
[Upgrading, Modifying and Unlocking] nuttydoc:
I started logcat, launched the app --> crash, stopped logcat, nothing else.
[Upgrading, Modifying and Unlocking] TalkB:
Interesting. You're getting java.lang.NoSuchMethodException: android.view.SurfaceControl.getPhysicalDisplayIds suggesting the code for obtaining the ID of the displays is wrong... yet, it works on my device. Are you running LOS?

I've added exception handling and additional logging to the assingment of all global variables, can you run the attached APK and send a logcat again? It probably won't work but it'll narrow down where the issue is.
[Upgrading, Modifying and Unlocking] nuttydoc:
Yes, I am running LOS18 + kitsune magisk +microg. Here is new logcat with debug app.

EDIT: first version of your app worked with same device.
[Upgrading, Modifying and Unlocking] TalkB:
Based on what I'm seeing that's to be expected as the first version didn't have any actual control of the second screen, since I had no idea how to do that.

This seems to suggest that, whilst getting display IDs is working, getting display 1 ID fails (there is supposed exception handling for that but I caught the wrong type of exception, oops).

The attached should hopefully not crash. But whether it does or not doesn't explain why the display can't be found.

Can you do "dumpsys display | grep mBaseDisplayInfo" in a shell and send the output? Along with another Logcat?

I really appreciate you testing this out as till now as far as I was concerned, it was working. I much prefer dealing with this stuff before trying to make it work better or have more functionality.
[Upgrading, Modifying and Unlocking] nuttydoc:
Yes, app is now not crashing. I will get and upload logs little later.
[Upgrading, Modifying and Unlocking] TalkB:
Thanks, since it's actually running now I should be able to see the exact failure - although I have a good idea already.

I may keep the changes I made permenatntly - the display token is stored in a "Globals" class, which isn't a processes at all, it's just a file. Whatever process needs the token can refrence the Globals class which will essentially provide the process with instructions on how to get that variable.

This is done to avoid having to put the code in to ID the second display multiple times.

It seems at the DisplayManager part, the app was crashing with errors about SurfaceFlinger. Indicating that somehow the instructions for that variable were being executed.

What I've done is make all of the values blank by default and the app populates them the first time they're requried. This still makes life easier in terms of coding but removes that issue, and also allows me to use "Try" statements. That means in the event of a failure, the app won't crash, and I can notify the user.
[Upgrading, Modifying and Unlocking] TalkB:
Turns out grabbing notifications is quite easy: https://github.com/B-CyberFunker/CATS22Present/issues/11
[Upgrading, Modifying and Unlocking] arkeo-ca:
That's really cool! Keep up the good work.

I finally got my s22. Almost had to return as it was "carrier locked" to T-Mobile and they refused to unlock it. Weirdly enough though, the SIM card from Canadian carrier is recognized and works without issues, so I'll keep my fingers crossed that nothings changes on that front.

So far, I've flash LOS 20 (BvS variant) and I'm currently working on migrating all my data from one phone to the next. I look forward to test/contribute to the more advanced projects you guys are working on.

Regarding VoLTE, I wasn't able to make it work, neither on LOS20 or Stock v30. Next thing I'll try is the Pixel IMS trick, but it may very well be my carrier that wants nothing to do with this phone... Oh well, 3G/HSPA+ is alive and well in Canada, so I've got a few good years to figure it all out.
[Upgrading, Modifying and Unlocking] GorgeComoote:
Hello, thank you for all theses guide, I installed Lineage OS 20 on my Cat S22 Flip without issues. Working like a charm.

But i'm trying to install Magisk to have root acess for the Key Mapper app. I used this image: https://sourceforge.net/projects/an...0-20240525-UNOFFICIAL-a64_bgN.img.xz/download but cannot make it work with sideloading from the recovery (Signature failed).

In seems that i have the stock recovery and not a Lineage one, is this good ? I'm very new to this.

Or should i go with the tutorial to root with stock boot image ? I'm a little lost.

Thank you.
[Upgrading, Modifying and Unlocking] nuttydoc:
There is only stock recovery available for this device, no LOS recoery or twrp. You can not use it to sideload unverified images. To get magisk you will have to use GSI rom without "su" binary (unrooted rom), like one I have uploaded in first image and flash magisk patched boot image to boot partition using fastboot, after that you can install magisk apk.
[Upgrading, Modifying and Unlocking] GorgeComoote:
Ok thank you. So i should use a BvS GSI image for my Lineage instead of BvN like this one: https://sourceforge.net/projects/an...0-20240516-UNOFFICIAL-a64_bvS.img.xz/download
[Upgrading, Modifying and Unlocking] nuttydoc:
No, Use one with "N" --> no superuser and flash magisk patched boot image with fastboot " fastboot flash boot <patched_boot.img>"
[Upgrading, Modifying and Unlocking] GorgeComoote:
Ok i have one with N (BvN) so i'm good on this part.

If i understood the procedure correctly i'll do:

- Install trough the Magisk app to patch image

- pull the magisk path image to my pc

- flashboot flash boot <patch image>

What i don't understand is the part where i need a copy of the boot image to start the procedure (from the magisk documentation), How can i obtain it ?
[Upgrading, Modifying and Unlocking] nuttydoc:
I guess you are using v30 rom with GSI. In that case use v30 boot image from "how to root cat s22" thread, and patch it using magisk app.
[Upgrading, Modifying and Unlocking] GorgeComoote:
Yep updated to V30 before installing Lineage. I'll try with that thank you !
[Upgrading, Modifying and Unlocking] Dunkin_dude:
I've just installed and flashed the .img file from the link at the start of this thread, (lineage-18.1-20240121-UNOFFICIAL-a64_bvS.img) from v29. It would seem now that my Cat S22 doesn't want to go past a bootloop with the lineage loading screen, and a subsequent scene on the (blank) home screen saying "Device is starting...". I have never had an Android phone before this, though I'm relatively tech savvy. I drive Debian and am familiar with a terminal.

I've heard something about missing home screen launchers, but I'm lost as to how to install one if this is the case.

Any recommendations?
[Upgrading, Modifying and Unlocking] nuttydoc:
Go to recovery, ( power+vol down --> fastbootd --> recovery), clear cache and do factory reset.
[Upgrading, Modifying and Unlocking] Dunkin_dude:
Perfect! Worked like a charm.

Thanks, doc :]
[Upgrading, Modifying and Unlocking] Dunkin_dude:
One last thing, this may seem idiotic: is the unofficial lineage-18.1 file you linked also the boot.img? Or the recovery image? I'm lost to this, it would seem I need it for magisk.
[Upgrading, Modifying and Unlocking] nuttydoc:
No it is system image, should be flashed to system partition. We have to use boot image from stock rom. I am uploading magisk patched boot here for you.
[Upgrading, Modifying and Unlocking] TalkB:
Hey everyone,

I have updated the present app.

I managed to recreate and find the cause of the crashes - as I thought referencing the shared variables somehow references all of them, some of which will be blank if there's no second display active and that causes a crash.

To fix it the check for a second display is the first thing that occurs and it's all done using local variables.

As well as this reliability has been improved and the display now shows the latest notification info.

You should go to the android settings and set the app to have unrestricted background power use. Power drain is minimal and this ensures that the services run in the background indefinitely.

The alternative is using a foreground service which requires a notification which I'd rather not do.

Release V0.2 · B-CyberFunker/CATS22Present

The first useful release. Changes Notifications The presentation now reacts to notificaitons. When a notification is received (and the screen is off), the device is woken breifly to show you. Titl...

github.com

I have since also created a fairly reliable way to tell if the device is folded. The service listens for changes in the proximity sensor - if the proximity sensor changes to 0 and the screen is turned off, the device is deemed folded. If it changes to above 0 and the screen is on, the device is deemed unfolded.

This allows me to vary how long the device is woke and not risk the device being put to sleep if you start using it soon after getting a notification - if the device is unfolded it won't be put to sleep.

I've also made the app broadcast the fact that the phone is folded/unfolded so in theory other devs can tap into these events.

This has seemingly made it more likely to be killed but my phones RAM use is also quite high for reasons I can't figure out (The app is using under 20mb so it's not that...).
[Upgrading, Modifying and Unlocking] nuttydoc:
$ adb install S22Present.apk

Performing Streamed Install

adb: failed to install S22_screen.apk: Failure [INSTALL_PARSE_FAILED_NO_CERTIFICATES: Failed collecting certificates for /data/app/vmdl1837023838.tmp/base.apk: Failed to collect certificates from /data/app/vmdl1837023838.tmp/base.apk: Attempt to get length of null array]
[Upgrading, Modifying and Unlocking] TalkB:
My bad... so this is the first release without an android studio debugger attached. I didn't realize that if you didn't sign an apk like this it'd fail to install.

I've signed it and it now installs on my device, try again with the new file.
[Upgrading, Modifying and Unlocking] nuttydoc:
Installation is okay but app crashes after activating second screen.

Another issue is when second screen is active my banking app doesn't work, with error "access to remote tools feature is not allowed".
[Upgrading, Modifying and Unlocking] TalkB:
Interesting... I've always wondered if there's any consequences of changing vendor.gsi.image_running and I think that might be one of them.

Either that or maybe the app is misinterpreting the second display as a TV...?

Can you send a logcat? Are you rooted with Magisk or similar?
[Upgrading, Modifying and Unlocking] nuttydoc:
Here is logcat, from launching s22 app --> activating display --> reboot --> s22 app crashing on launch

EDIT: I am using magisk (kitsune)
[Upgrading, Modifying and Unlocking] TalkB:
Based on this: Accessing hidden method Landroid/view/SurfaceControl;->getPhysicalDisplayIds()[J (blacklist, reflection, denied)

I think I may have used the wrong permissions commands (well correct commands but for a different android version). Can you do:

adb shell settings put global hidden_api_policy 1

and try again (effect should be immediate?)
[Upgrading, Modifying and Unlocking] nuttydoc:
after this command there is no crash.
[Upgrading, Modifying and Unlocking] TalkB:
Nice. Does it finally work now?

In my research it looks like there's way to add privileges for hidden apis to the app. Security wise it's probably best if it's off.