Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 19c2a20d authored by Yi-Ling Chuang's avatar Yi-Ling Chuang
Browse files

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
parent 8a4cf7c9
Loading
Loading
Loading
Loading
+10 −8
Original line number Diff line number Diff line
@@ -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<Slice> 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);