From 2c6d8d536ef330c4feaf420947a8035cd5322fad Mon Sep 17 00:00:00 2001 From: Bonian Chen Date: Mon, 9 May 2022 16:28:14 +0800 Subject: [PATCH] [Settings] Avoid from crash UI when querying data usage Screen update been requested while querying data usage and response not yet available. This change tried to avoid from updating the UI in this case. Bug: 210664126 Test: local Merged-In: Id055fbd441936a9842b4acc978a894a855165bb7 Change-Id: Ia57f831d78b12754d60f920a9dbe057400dc4ce2 --- .../android/settings/datausage/DataUsageList.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/com/android/settings/datausage/DataUsageList.java b/src/com/android/settings/datausage/DataUsageList.java index 6beb3d89953..4ee653017e4 100644 --- a/src/com/android/settings/datausage/DataUsageList.java +++ b/src/com/android/settings/datausage/DataUsageList.java @@ -37,7 +37,6 @@ import android.os.UserManager; import android.provider.Settings; import android.telephony.SubscriptionInfo; import android.telephony.SubscriptionManager; -import android.util.FeatureFlagUtils; import android.util.Log; import android.util.SparseArray; import android.view.View; @@ -49,6 +48,7 @@ import android.widget.ImageView; import android.widget.Spinner; import androidx.annotation.VisibleForTesting; +import androidx.lifecycle.Lifecycle; import androidx.loader.app.LoaderManager.LoaderCallbacks; import androidx.loader.content.Loader; import androidx.preference.Preference; @@ -501,6 +501,17 @@ public class DataUsageList extends DataUsageBaseFragment + cycle.end + "]"); } + // Avoid from updating UI after #onStop. + if (!getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED)) { + return; + } + + // Avoid from updating UI when async query still on-going. + // This could happen when a request from #onMobileDataEnabledChange. + if (mCycleData == null) { + return; + } + // update chart to show selected cycle, and update detail data // to match updated sweep bounds. mChart.setNetworkCycleData(mCycleData.get(position));