Fix crash on Wi-Fi Slice when it's continuously pinned and unpinned

It's because WifiTracker's initialization and onStop is on different
thread. Fine tune the thread logic in SliceBackgroundWorker.

Fixes: 118165942
Test: manual
Change-Id: Icc86b5df7ec3c6fd0e4a79a62ea0c84465e9528d
This commit is contained in:
Jason Chiu
2018-10-23 15:31:54 +08:00
parent 61a8d1fbe4
commit 89b15785c7
4 changed files with 64 additions and 21 deletions

View File

@@ -16,9 +16,11 @@
package com.android.settings.slices;
import android.annotation.MainThread;
import android.content.ContentResolver;
import android.net.Uri;
import java.io.Closeable;
import java.util.ArrayList;
import java.util.List;
@@ -32,7 +34,7 @@ import java.util.List;
* {@link SliceBackgroundWorker} caches the results, uses the cache to compare if there is any data
* changed, and then notifies the Slice {@link Uri} to update.
*/
public abstract class SliceBackgroundWorker<E> {
public abstract class SliceBackgroundWorker<E> implements Closeable {
private final ContentResolver mContentResolver;
private final Uri mUri;
@@ -48,12 +50,14 @@ public abstract class SliceBackgroundWorker<E> {
* Called when the Slice is pinned. This is the place to register callbacks or initialize scan
* tasks.
*/
@MainThread
protected abstract void onSlicePinned();
/**
* Called when the Slice is unpinned. This is the place to unregister callbacks or perform any
* final cleanup.
*/
@MainThread
protected abstract void onSliceUnpinned();
/**