From 19c2a20d9a35efbb1fb54231a4e47a1e6ec59384 Mon Sep 17 00:00:00 2001 From: Yi-Ling Chuang Date: Tue, 1 Oct 2019 15:14:18 +0800 Subject: [PATCH] Add onErrorListner for SliceLiveData SliceLiveData is changed in the framework, where the way it handles null slices is different. Thus, we handle the case of null slices by adding onSliceError() to make slice refreshing back to normal and to prevent from non responding action on slices. Fixes: 141293788 Test: visual Change-Id: I4751d57ae478eec66a1a951841d36521556cacd7 --- .../slices/SliceContextualCardRenderer.java | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/com/android/settings/homepage/contextualcards/slices/SliceContextualCardRenderer.java b/src/com/android/settings/homepage/contextualcards/slices/SliceContextualCardRenderer.java index 9d1b883177c..45be727c344 100644 --- a/src/com/android/settings/homepage/contextualcards/slices/SliceContextualCardRenderer.java +++ b/src/com/android/settings/homepage/contextualcards/slices/SliceContextualCardRenderer.java @@ -43,6 +43,7 @@ import com.android.settings.homepage.contextualcards.CardContentProvider; import com.android.settings.homepage.contextualcards.ContextualCard; import com.android.settings.homepage.contextualcards.ContextualCardRenderer; import com.android.settings.homepage.contextualcards.ControllerRendererPool; +import com.android.settingslib.utils.ThreadUtils; import java.util.Map; import java.util.Set; @@ -104,7 +105,15 @@ public class SliceContextualCardRenderer implements ContextualCardRenderer, Life LiveData sliceLiveData = mSliceLiveDataMap.get(uri); if (sliceLiveData == null) { - sliceLiveData = SliceLiveData.fromUri(mContext, uri); + sliceLiveData = SliceLiveData.fromUri(mContext, uri, + (int type, Throwable source) -> { + // onSliceError doesn't handle error Slices. + Log.w(TAG, "Slice may be null. uri = " + uri + ", error = " + type); + ThreadUtils.postOnMainThread( + () -> mSliceLiveDataMap.get(uri).removeObservers(mLifecycleOwner)); + mContext.getContentResolver() + .notifyChange(CardContentProvider.REFRESH_CARD_URI, null); + }); mSliceLiveDataMap.put(uri, sliceLiveData); } @@ -115,13 +124,6 @@ public class SliceContextualCardRenderer implements ContextualCardRenderer, Life swipeBackground.setVisibility(View.GONE); } sliceLiveData.observe(mLifecycleOwner, slice -> { - if (slice == null) { - Log.w(TAG, "Slice is null"); - mContext.getContentResolver().notifyChange(CardContentProvider.REFRESH_CARD_URI, - null); - return; - } - if (slice.hasHint(HINT_ERROR)) { Log.w(TAG, "Slice has HINT_ERROR, skipping rendering. uri=" + slice.getUri()); mSliceLiveDataMap.get(slice.getUri()).removeObservers(mLifecycleOwner);