Merge "Revert "Revert "Workaround of Slice not pinned bug when using Sl..."" into rvc-dev
diff --git a/src/com/android/settings/homepage/contextualcards/EligibleCardChecker.java b/src/com/android/settings/homepage/contextualcards/EligibleCardChecker.java
index 4340330..46b4c86 100644
--- a/src/com/android/settings/homepage/contextualcards/EligibleCardChecker.java
+++ b/src/com/android/settings/homepage/contextualcards/EligibleCardChecker.java
@@ -22,6 +22,7 @@
import android.content.ContentResolver;
import android.content.Context;
import android.net.Uri;
+import android.os.AsyncTask;
import android.util.Log;
import androidx.annotation.VisibleForTesting;
@@ -32,6 +33,7 @@
import com.android.settings.overlay.FeatureFactory;
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
+import com.android.settingslib.utils.ThreadUtils;
import java.util.List;
import java.util.concurrent.Callable;
@@ -115,7 +117,12 @@
// Register a trivial callback to pin the slice
manager.registerSliceCallback(uri, callback);
final Slice slice = manager.bindSlice(uri);
- manager.unregisterSliceCallback(uri, callback);
+
+ // Workaround of unpinning slice in the same SerialExecutor of AsyncTask as SliceCallback's
+ // observer.
+ ThreadUtils.postOnMainThread(() ->
+ AsyncTask.execute(() -> manager.unregisterSliceCallback(uri, callback))
+ );
return slice;
}