Bug 56831 - Animation tasks do not complete when Battery Saver enabled
Summary: Animation tasks do not complete when Battery Saver enabled
Status: RESOLVED ANSWERED
Alias: None
Product: Forms
Classification: Xamarin
Component: Forms ()
Version: unspecified
Hardware: Macintosh Mac OS
: --- blocker
Target Milestone: ---
Assignee: Paul DiPietro [MSFT]
URL:
Depends on:
Blocks:
 
Reported: 2017-05-25 09:35 UTC by Tom Gilder
Modified: 2018-01-11 14:01 UTC (History)
6 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
Repro solution (52.89 KB, application/zip)
2017-05-25 09:38 UTC, Tom Gilder
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED ANSWERED

Description Tom Gilder 2017-05-25 09:35:52 UTC
# Steps to reproduce

1. Enable Battery Saver mode on an Android phone that disables animation whilst the mode is enabled (such as Nexus 6P on Android 7.1.2)
2. Call any animation -  var animationTask = label.FadeTo(1)
3. await the resulting task


# Expected behavior

Animation completes instantly, Task immediately completes.


# Actual behavior

Animation does not occur, Task never completes. Tested with Xamarin.Forms 2.3.4.247.

This caused our production app to completely break on several phones when Battery Saver was enabled, due to a start-up animation never completing.

This bug can also be emulated by setting "Animator duration scale" to “Animation off” in Android developer options.


# Work-around

We're using code like this to prevent calling animation methods:

bool AreAnimationsDisabled()
{
    var powerManager = Application.Context.GetSystemService(Context.PowerService) as PowerManager;
    if (powerManager != null)
    {
        if(powerManager.IsPowerSaveMode)
        {
            return true;
        }
    }

    return Settings.Global.GetFloat(Application.Context.ContentResolver, Settings.Global.AnimatorDurationScale, 0) == 0;
}
Comment 1 Tom Gilder 2017-05-25 09:38:05 UTC
Created attachment 22448 [details]
Repro solution

Expected result: app should show "Success!" 
Actual result: when animations disabled, app shows blank screen
Comment 2 Paul DiPietro [MSFT] 2017-05-26 14:05:06 UTC
Does this only occur on physical devices or have you been able to reproduce it on an emulator and/or only with specific versions of Android? The reproduction project returns a success as expected on an emulator with the battery saver mode enabled as well as the developer options setting as mentioned. I have yet to test against a physical device (I need to dig one out) but would like to get your feedback in the meantime.
Comment 3 José Fabio Martinez Gonzalez 2017-06-12 15:33:46 UTC
I am not the thread owner but I got exactly the same problem on a Nexus 6P. This only occurs on a Nexus 6P physical device and not in a simulator
Comment 4 Antonino 2017-11-14 08:26:44 UTC
+1 My app actually await FadeTo, TranslateTo and ScaleTo forever in production on some devices. I think it shouldn't await forever if animations are disabled but simply return immediately from the task.
Comment 5 Antonino 2017-11-14 08:30:58 UTC
PS. It happens in Forms 2.3.2.127 and in Forms 2.4.0.38779.
Comment 6 Dale Cebula 2017-12-01 09:39:52 UTC
I can confirm that this is still an issue in Forms 2.5.0.91635.

If you use the repro project on an actual device, this will not complete

await label.FadeTo(1);


However, this will


label.FadeTo(1);

So, is this an issue in XF possibly a deadlock or by design?
Comment 7 Dale Cebula 2017-12-01 11:32:39 UTC
In addition to this, TranslateTo does not seem to work whether it is awaited or not. 


On FadeTo, in the ViewExtensions class, finished never fires so I'm assuming the problem is with all animations.

   new Animation(fade, view.Opacity, opacity, easing).Commit(view, "FadeTo", 16, length,
                    finished: (f, a) =>
                    {



                    });

If you wrap it with  return Task.Factory.StartNew FadeTo will work but the finished action is still not called. TranslateTo didn't seem to work, even with this method.

            return Task.Factory.StartNew(() => {

                if (view == null)

                    throw new ArgumentNullException("view");

                if (easing == null)

                    easing = Easing.Linear;



                var tcs = new TaskCompletionSource<bool>();

                var weakView = new WeakReference<VisualElement>(view);

                Action<double> fade = f =>

                {

                    VisualElement v;

                    if (weakView.TryGetTarget(out v))

                        v.Opacity = f;

                };





                new Animation(fade, view.Opacity, opacity, easing).Commit(view, "FadeTo", 16, length,
                    finished: (f, a) =>
                    {



                    });

            });
Comment 8 David Ortinau [MSFT] 2018-01-11 14:01:31 UTC
This issue has been migrated to GitHub. Please follow https://github.com/xamarin/Xamarin.Forms/issues/1556 for adding future comments and receiving updates.