Fix ANR in SliceRelayReceiver
The same broadcast are handled in SliceRelayReceiver and WifiScanWorker. We will only use WifiScanWorker to handle wifi broadcast. Change-Id: I32c2fcc699ae240f12bd1049ba33e1792ae123b0 Fixes: 120284615 Test: manual
This commit is contained in:
@@ -58,6 +58,10 @@ public abstract class SliceBackgroundWorker<E> implements Closeable {
|
||||
mUri = uri;
|
||||
}
|
||||
|
||||
public Uri getUri() {
|
||||
return mUri;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the singleton instance of the {@link SliceBackgroundWorker} for specified {@link
|
||||
* CustomSliceable}
|
||||
|
@@ -25,7 +25,6 @@ import android.annotation.ColorInt;
|
||||
import android.app.PendingIntent;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.net.Uri;
|
||||
import android.net.wifi.WifiInfo;
|
||||
import android.net.wifi.WifiManager;
|
||||
@@ -75,14 +74,6 @@ public class WifiSlice implements CustomSliceable {
|
||||
return WIFI_SLICE_URI;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IntentFilter getIntentFilter() {
|
||||
final IntentFilter filter = new IntentFilter();
|
||||
filter.addAction(WifiManager.WIFI_STATE_CHANGED_ACTION);
|
||||
filter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION);
|
||||
return filter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Slice getSlice() {
|
||||
final boolean isWifiEnabled = isWifiEnabled();
|
||||
@@ -200,7 +191,7 @@ public class WifiSlice implements CustomSliceable {
|
||||
mWifiManager.isWifiEnabled());
|
||||
mWifiManager.setWifiEnabled(newState);
|
||||
// Do not notifyChange on Uri. The service takes longer to update the current value than it
|
||||
// does for the Slice to check the current value again. Let {@link SliceBroadcastRelay}
|
||||
// does for the Slice to check the current value again. Let {@link WifiScanWorker}
|
||||
// handle it.
|
||||
}
|
||||
|
||||
@@ -292,6 +283,7 @@ public class WifiSlice implements CustomSliceable {
|
||||
|
||||
@Override
|
||||
public void onWifiStateChanged(int state) {
|
||||
mContext.getContentResolver().notifyChange(getUri(), null);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -20,10 +20,18 @@ package com.android.settings.wifi;
|
||||
import static android.app.slice.Slice.HINT_LIST_ITEM;
|
||||
import static android.app.slice.SliceItem.FORMAT_SLICE;
|
||||
|
||||
import static com.android.settings.slices.CustomSliceRegistry.WIFI_SLICE_URI;
|
||||
import static com.android.settings.wifi.WifiSlice.DEFAULT_EXPANDED_ROW_COUNT;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.wifi.WifiManager;
|
||||
@@ -52,13 +60,16 @@ import java.util.List;
|
||||
public class WifiSliceTest {
|
||||
|
||||
private Context mContext;
|
||||
|
||||
private ContentResolver mResolver;
|
||||
private WifiManager mWifiManager;
|
||||
private WifiSlice mWifiSlice;
|
||||
private WifiSlice.WifiScanWorker mWifiScanWorker;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mContext = spy(RuntimeEnvironment.application);
|
||||
mResolver = mock(ContentResolver.class);
|
||||
doReturn(mResolver).when(mContext).getContentResolver();
|
||||
mWifiManager = mContext.getSystemService(WifiManager.class);
|
||||
|
||||
// Set-up specs for SliceMetadata.
|
||||
@@ -66,6 +77,7 @@ public class WifiSliceTest {
|
||||
mWifiManager.setWifiEnabled(true);
|
||||
|
||||
mWifiSlice = new WifiSlice(mContext);
|
||||
mWifiScanWorker = new WifiSlice.WifiScanWorker(mContext, WIFI_SLICE_URI);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -122,4 +134,11 @@ public class WifiSliceTest {
|
||||
|
||||
assertThat(wifiManager.getWifiState()).isEqualTo(WifiManager.WIFI_STATE_ENABLED);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onWifiStateChanged_shouldNotifyChange() {
|
||||
mWifiScanWorker.onWifiStateChanged(WifiManager.WIFI_STATE_DISABLED);
|
||||
|
||||
verify(mResolver).notifyChange(WIFI_SLICE_URI, null);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user