Hamza417 / Peristyle

Simple wallpaper manager app for Android with awesome UI, tags and multiple folder support and a native live wallpaper picker.
Apache License 2.0
248 stars 6 forks source link

On Samsung Galaxy Z Flip5, auto wallpaper sets only the cover screen background #22

Closed matildepark closed 7 months ago

matildepark commented 7 months ago

The Flip5 has two screens: a cover screen and the actual phone screen. When auto wallpaper changing is set, it only happens on the cover screen (changing the cover screen at all is undesirable in my case — I could see people who want both screens to rotate wallpapers, but that's aside). Presumably there's some way we can tell it to find the "main" screen and set it there, because that sets perfectly fine if I manually open Peristyle and set a wallpaper.

Hamza417 commented 7 months ago

@matildepark What do you mean?

matildepark commented 7 months ago

Here is a photo of a Galaxy Z Flip5:

image

The phone closes up, which reveals a cover screen. When you open it, the phone screen takes over.

Now I'm aware that we just write setBitmap to whatever the system's main screen is:

https://github.com/Hamza417/Peristyle/blob/92b438bac5a55dcacf066d9ee2f3da42948fe6ca/app/src/main/java/app/simple/peri/services/AutoWallpaperService.kt#L115

and I can't actually find anywhere on the Android documentation for wallpaperManager to be more specific about which of a phone's displays to set, when it has multiple displays. But it appears that when the phone is closed, the "system screen" is considered to be the outer, cover screen, so we end up setting wallpaper on that screen if the timer passes while the phone is closed up. I'm not sure how to enforce only changing the wallpaper on the phone's main screen.

matildepark commented 7 months ago

As per https://developer.samsung.com/sdp/blog/en/2024/01/09/best-practices-of-app-development-for-various-screen-sizespowered-by-good-lock and https://developer.android.com/guide/topics/large-screens/make-apps-fold-aware it recommends prompting the Jetpack WindowManager for information about the device:

The WindowLayoutInfo object contains a displayFeatures object that contains the current state of your application. The displayFeatures object also contains the FoldingFeature interface, which describes device states and orientations specific to foldable devices:

  • If the displayFeatures object is null, the device is closed or folded.
  • If FoldingFeature.State is HALF_OPENED and FoldingFeature.Orientation is VERTICAL, the device is a Galaxy Flip device in Flex Mode.
  • If FoldingFeature.State is HALF_OPENED and FoldingFeature.Orientation is HORIZONTAL, the device is a Galaxy Fold device in Flex Mode.
  • If FoldingFeature.State is Flat, the device is fully open.

It may just be that in the case where the device is a foldable, if the timer hits for changing a wallpaper and the displayFeatures object is null, we postpone until the FoldingFeature.State becomes Flat so that when we apply the wallpaper it's on the right screen. I can't really see another way right now, but I'm not an Android developer. It seems that the system legitimately just changes what the "system display" is, when the device opens or closes.

Hamza417 commented 7 months ago

Thanks, I think a simple check for if the device is locked or sleeping then skip changing the wallpaper should work in this condition. I'm still not sure if the device is closed, but the secondary screen is awake, does it count as asleep or awake?

matildepark commented 7 months ago

I'm not sure this solution will fix it. If you tap the outer screen twice it wakes up the phone as a whole.

Any app can be used on the outer screen technically, and it resizes dynamically. So I think it counts as awake. The system juggles whether it's open or closed and sets which screen is on based on that. If I can help debug by opening the device and doing adb stuff, let me know.

On Sun, Mar 10, 2024, 04:45 Hamza Rizwan @.***> wrote:

Thanks, I think a simple check for if the device is locked or sleeping then skip changing the wallpaper should work in this condition. I'm still not sure if the device is closed, but the secondary screen is awake, does it count as asleep or awake?

— Reply to this email directly, view it on GitHub https://github.com/Hamza417/Peristyle/issues/22#issuecomment-1987146494, or unsubscribe https://github.com/notifications/unsubscribe-auth/AE7BOTVPAYWXI34WWG435KTYXQMTJAVCNFSM6AAAAABEOPKFDGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSOBXGE2DMNBZGQ . You are receiving this because you were mentioned.Message ID: @.***>

matildepark commented 7 months ago

I think probably the best decision is that if there's a way to specify a non-default screen to set the wallpaper to (it seems MAIN_SCREEN is 1 etc etc.) then for people who need to change it, they can tweak. Only doing it when not sleeping is unlikely to help here.

Hamza417 commented 7 months ago

@matildepark Android doesn't have any ways to specify which screen I want to set the wallpaper to, but only detect some of the states of it. That's why I went with the solution above. Detection won't do any good if I can't specify the screen.

Hamza417 commented 7 months ago

I did a thorough study and unfortunately there's no possible way to control the screens in WallpaperManager to set the wallpaper to. The only solution I could think of is to detect the fold state and only change the wallpaper when the screen is fully flat. It'd be more accurate if the service is run indefinitely and monitor the states in real-time.

matildepark commented 7 months ago

Yes, that does seem to be the case. I am guessing Samsung is doing something proprietary and weird, since they let you set independent backgrounds on each screen, and they do seem to keep track of them separately.

I guess it could be a toggle option for foldables to listen to the fold state? Is it possible to listen to the display state and apply when it changes? I just feel like if it skips applying the wallpaper, it may very well not change the wallpaper for days, unless the phone is open at the exact time it's supposed to change.

Hamza417 commented 7 months ago

I guess it could be a toggle option for foldables to listen to the fold state? Is it possible to listen to the display state and apply when it changes?

It's doable, but running a service like that is a bad idea when it can be done without it and adding a device specific workaround is bad for the software as well, why not use any automation software like Tasker to run Peristyle auto wallpaper service when you lock or unlock your device?

Hamza417 commented 7 months ago

I've added some possible features that can help you in your situations, since specifying a screen isn't entirely possible. Make sure to check the latest release and see if you can manage to fix your problem to some extent. For better support, I'd suggest filing a feature request to Android for multiple screen support in WallpaperManager API.

matildepark commented 7 months ago

Thank you. For the sake of posterity, allow me to tell future flip phone users what I did.

  1. I had to buy the Tasker app.
  2. I made a profile attached to a Sensor.
  3. I picked 'any sensor', and chose hinge_angle Wakeup - Hinge angle which is also type 36 if you choose the integer value instead.
  4. I chose an interval type of None and the conditions used %as_values(). The value is set to 180.0 (fully open).
  5. In the profile, I picked "Send Intent."
  6. The intent is easy: under Action, you put app.peristyle.START_AUTO_WALLPAPER_SERVICE and exit the menu.

Then you can also long press the profile after and in the settings, add a cooldown timer so it only fires once a day at most. There's a brief flash before it's changed but it's chill.

Thanks for the extensibility @Hamza417 !