cmeng-git / atalk-android

xmpp/jabber client for android
Apache License 2.0
159 stars 59 forks source link

Confusing loading state in Battery Saver #215

Closed graciouselectric closed 4 months ago

graciouselectric commented 5 months ago

Dear developer,

I noticed that, when I enable Battery Saver on Android 8.1, the indeterminate ProgressBars in the app disappear. This is a known problem in Android API level <28, see e.g. this StackOverflow question. Battery Saver disables animations, also on progress bars on these versions. This is quite confusing because the loading state is not properly represented. It is fixed in later Android versions, where progress bars do animate.

Looking at the code, indeterminate progress bars are created at these locations:

className='org.atalk.android.gui.webview.WebViewFragment$1', lineNumber=80
className='org.atalk.android.gui.webview.WebViewFragment$1', lineNumber=103

To fix this issue, you can check ValueAnimator.areAnimatorsEnabled() and provide a different UI element when animations are disabled, such as a text label.

cmeng-git commented 5 months ago

I have tested many android devices including API-27 (Pixel 4), with debug message added into the source.

    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
        boolean enable = ValueAnimator.areAnimatorsEnabled();
        Timber.e("Animation Enable: %s", enable);
    }

However all the devices show: 09:05:26.759 E Animation Enable: true.

Are you able to give the test procedure to reproduce your observed problem?

graciouselectric commented 5 months ago

Hi @cmeng-git!

Are you enabling Battery Saver? Trying something very basic like this:

protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        if (ValueAnimator.areAnimatorsEnabled()) {
            System.out.println("animators enabled");
        } else {
            System.out.println("animators disabled");
        }

prints animators enabled when BS is off, disabled when BS is on.

cmeng-git commented 5 months ago

On aTalk initial launch, the app will check and put aTalk in whitelist to REQUEST_IGNORE_BATTERY_OPTIMIZATIONS (See PermissionsActivity.java source for detail implementations) i.e. not to put aTalk into sleep when android system goes into sleep mode. This is a must for aTalk to work properly under all conditions. The test result "Animation Enable: true", is based on the above assumption.

I am not sure if your 'enabling Battery Saver" is actually allow android system to put aTalk into sleep mode on standby. This is an undesired settings for aTalk to operate properly.

cmeng-git commented 5 months ago

I proceed to check for ValueAnimator.areAnimatorsEnabled() for both cases i.e. battery saver enabled/disabled for aTalk, the return result for API-27 (Pixel 4) is always: 09:00:10.707 E Animation Enable: true

Below are the screenShots on aTalk initial launch. The prompt will be shown if aTalk checked and found that battery saver is enabled on aTalk.

By the way, the source to print the result is inserted in WebViewFragment#onCreateView().

image

image

graciouselectric commented 5 months ago

Thanks for getting back and all the info you've provided! I've allowed the app to run in the background and disabled Battery Optimizations, sadly I'm still seeing the animation issue, e.g. in the video below:

Screenshot 2024-05-06 at 10 40 23

https://github.com/cmeng-git/atalk-android/assets/165037835/eb7f774b-2d63-493d-b1f4-50728f5fe4c6

cmeng-git commented 5 months ago

I have repeated your test with battery saver disabled for aTalk on API-27 (Pixel 4). Attached is the video shot on aTalk start up. Again I do not see the problem on Pixel API-27. Your observed behaviour seems to be related to android device specific implementation. This is no uncommon for android manufacturers having various implementation, based on my past aTalk system testing. As the observed problem is cosmetic, and it does not affect aTalk normal operation. Furthermore the relevant UI message is shown to the user, and the observation is product specific. aTalk will drop support on this type of problem.

aTalk.webm

graciouselectric commented 5 months ago

Hi @cmeng-git!

Thanks for getting back!

I'm a bit confused, I don't see the red top and bottom bars in your video, which I always see on Android 8.1 when enabling Battery Saver.

As to your comment on this being device-specific, I can reproduce this on the emulator, so if it would be device-specific I suppose it's device-specific to clean Android...

cmeng-git commented 5 months ago

The top and bottom red bar is device implementation variations. I do not see them on all my Samsung android devices (x4), including Huawei matePro 13.2.

My test was carried out on AVD Pixel, which android OS development team will only refer this as the standard device. May I know which emulator did you perform your test.

graciouselectric commented 5 months ago

I tested on an AVD Pixel 7 on Android 8.1.

cmeng-git commented 5 months ago

Below is the test result for and with attached Pixel 7 on Android 8.1 settings. Please check your AVD version to ensure it is the latest.

Pixel-7_8,1_Oreo-API-27 pixel-7 (android 8.1).webm

graciouselectric commented 5 months ago

In the video you sent, it looks to me like Battery Saver isn't enabled, because there is no "+" icon in the battery indicator in the status bar. Are you sure we're talking about the same thing? I'm talking about the separate mode, this one:

Screenshot 2024-05-08 at 09 27 03

Not the "battery optimization" toggle in Setttings, or anything else.

graciouselectric commented 5 months ago

Also I'm running a slightly newer emulator version than you

Screenshot 2024-05-08 at 09 28 44
cmeng-git commented 5 months ago

aTalk Battery Optimisation has been disabled as shown in the android settings below. I see that your AVD is running on macOS, whereas mine is running on Ubuntu. Both AVD's have different UI implementations. From all the previous discussions, the problem seems to be AVD implementation related error. aTalk will drop further pursue on this matter. You can raise the issue with android development team for further action.

image

graciouselectric commented 5 months ago

Hi @cmeng-git, thanks for getting back!

My impression is that you are not testing in Battery Saver mode. Could you try going to Settings -> Battery and check?

Screenshot 2024-05-08 at 15 25 55

aTalk is also set not to be optimized on my emulator, I don't think that is why you are not able to reproduce this. At risk of repeating myself, I believe this issue is caused by the system-level Battery Saver functionality, not the app-level Battery Optimization functionality.

Screenshot 2024-05-08 at 15 24 06
cmeng-git commented 5 months ago

What I shown not optimized setting is what is required for aTalk to operate properly. On all my android devices and AVD there is no other battery setting that can be set for battery saver..

graciouselectric commented 5 months ago

What is shown if you drag down from the status bar? To see notifications etc?

I see this view:

Screenshot 2024-05-08 at 16 41 34
cmeng-git commented 5 months ago

Screenshot_20240508-225612_Device care Screenshot_20240508-225600_aTalk

graciouselectric commented 5 months ago

I'm sorry, I meant on the emulator!

cmeng-git commented 5 months ago

Yes, I see the same UI as yours, when the battery saver is enabled, the indeterminate progress bar stop animation. I do not see this option in all other AVD's or on my physical android devices.

This is android OS 8.1 battery saver implementation problem. You can raise the issue with the android development team for further advice. aTalk will not attempt to resolve this type of problem.

graciouselectric commented 4 months ago

This is android OS 8.1 battery saver implementation problem.

Yeah, this I agree with, I just didn't agree with your earlier assessment that it was related to the "battery optimization" setting or an emulator version / OS problem, and I wanted to make sure you could reproduce it, which it now sounds like you can. On whether to work around it, that's of course in your hands. Thanks for the info you provided!

cmeng-git commented 4 months ago

Found the similar Battery Saver option in all other android OS API's. Enable and disable of this option has no effect on the indeterminate progress bars, and it works as expected.

Your observation problem on device with android 8.1 API-27 is a clear indication of the android OS implementation limitations; it has nothing to do with aTalk. Issue closed.