Fix NPE for checking for whether animators should play together

BUG: 29586505
Change-Id: Ic2a67d51d2ac8d5bfb11ed7773c7c7e413cc28c7
diff --git a/libs/hwui/PropertyValuesAnimatorSet.cpp b/libs/hwui/PropertyValuesAnimatorSet.cpp
index e416e0c..796c73b 100644
--- a/libs/hwui/PropertyValuesAnimatorSet.cpp
+++ b/libs/hwui/PropertyValuesAnimatorSet.cpp
@@ -29,7 +29,6 @@
     PropertyAnimator* animator = new PropertyAnimator(propertyValuesHolder,
             interpolator, startDelay, duration, repeatCount);
     mAnimators.emplace_back(animator);
-    setListener(new PropertyAnimatorSetListener(this));
 
     // Check whether any child animator is infinite after adding it them to the set.
     if (repeatCount == -1) {
@@ -42,6 +41,7 @@
     setStartValue(0);
     mLastFraction = 0.0f;
     setInterpolator(new LinearInterpolator());
+    setListener(new PropertyAnimatorSetListener(this));
 }
 
 void PropertyValuesAnimatorSet::onFinished(BaseRenderNodeAnimator* animator) {
@@ -115,7 +115,7 @@
     std::sort(mAnimators.begin(), mAnimators.end(), [](auto& a, auto&b) {
         return a->getTotalDuration() < b->getTotalDuration();
     });
-    mDuration = mAnimators[mAnimators.size() - 1]->getTotalDuration();
+    mDuration = mAnimators.empty() ? 0 : mAnimators[mAnimators.size() - 1]->getTotalDuration();
     mInitialized = true;
 }