Merge "[Provider Model] Show scanning sub-title once in the internet panel" into sc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
059b3fab8e
@@ -84,12 +84,13 @@ public class InternetConnectivityPanel implements PanelContent, LifecycleObserve
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (TextUtils.equals(intent.getAction(), WifiManager.SCAN_RESULTS_AVAILABLE_ACTION)) {
|
if (TextUtils.equals(intent.getAction(), WifiManager.SCAN_RESULTS_AVAILABLE_ACTION)) {
|
||||||
showProgressBar();
|
updateProgressBar();
|
||||||
updatePanelTitle();
|
updatePanelTitle();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (TextUtils.equals(intent.getAction(), WifiManager.NETWORK_STATE_CHANGED_ACTION)) {
|
if (TextUtils.equals(intent.getAction(), WifiManager.NETWORK_STATE_CHANGED_ACTION)) {
|
||||||
|
updateProgressBar();
|
||||||
updatePanelTitle();
|
updatePanelTitle();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -110,13 +111,40 @@ public class InternetConnectivityPanel implements PanelContent, LifecycleObserve
|
|||||||
private int mDefaultDataSubid = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
|
private int mDefaultDataSubid = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
|
||||||
|
|
||||||
// Wi-Fi scanning progress bar
|
// Wi-Fi scanning progress bar
|
||||||
|
protected HandlerInjector mHandlerInjector;
|
||||||
protected boolean mIsProgressBarVisible;
|
protected boolean mIsProgressBarVisible;
|
||||||
protected final Runnable mHideProgressBarRunnable = () -> {
|
protected boolean mIsScanningSubTitleShownOnce;
|
||||||
|
protected Runnable mHideProgressBarRunnable = () -> {
|
||||||
setProgressBarVisible(false);
|
setProgressBarVisible(false);
|
||||||
};
|
};
|
||||||
|
protected Runnable mHideScanningSubTitleRunnable = () -> {
|
||||||
|
mIsScanningSubTitleShownOnce = true;
|
||||||
|
updatePanelTitle();
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wrapper for testing compatibility.
|
||||||
|
*/
|
||||||
|
@VisibleForTesting
|
||||||
|
static class HandlerInjector {
|
||||||
|
protected final Handler mHandler;
|
||||||
|
|
||||||
|
HandlerInjector(Context context) {
|
||||||
|
mHandler = context.getMainThreadHandler();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void postDelay(Runnable runnable) {
|
||||||
|
mHandler.postDelayed(runnable, 2000 /* delay millis */);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeCallbacks(Runnable runnable) {
|
||||||
|
mHandler.removeCallbacks(runnable);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private InternetConnectivityPanel(Context context) {
|
private InternetConnectivityPanel(Context context) {
|
||||||
mContext = context.getApplicationContext();
|
mContext = context.getApplicationContext();
|
||||||
|
mHandlerInjector = new HandlerInjector(context);
|
||||||
mIsProviderModelEnabled = Utils.isProviderModelEnabled(mContext);
|
mIsProviderModelEnabled = Utils.isProviderModelEnabled(mContext);
|
||||||
mInternetUpdater = new InternetUpdater(context, null /* Lifecycle */, this);
|
mInternetUpdater = new InternetUpdater(context, null /* Lifecycle */, this);
|
||||||
|
|
||||||
@@ -150,7 +178,7 @@ public class InternetConnectivityPanel implements PanelContent, LifecycleObserve
|
|||||||
mTelephonyManager.registerTelephonyCallback(
|
mTelephonyManager.registerTelephonyCallback(
|
||||||
new HandlerExecutor(new Handler(Looper.getMainLooper())), mTelephonyCallback);
|
new HandlerExecutor(new Handler(Looper.getMainLooper())), mTelephonyCallback);
|
||||||
mContext.registerReceiver(mWifiStateReceiver, mWifiStateFilter);
|
mContext.registerReceiver(mWifiStateReceiver, mWifiStateFilter);
|
||||||
showProgressBar();
|
updateProgressBar();
|
||||||
updatePanelTitle();
|
updatePanelTitle();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -165,7 +193,8 @@ public class InternetConnectivityPanel implements PanelContent, LifecycleObserve
|
|||||||
mConnectivityListener.stop();
|
mConnectivityListener.stop();
|
||||||
mTelephonyManager.unregisterTelephonyCallback(mTelephonyCallback);
|
mTelephonyManager.unregisterTelephonyCallback(mTelephonyCallback);
|
||||||
mContext.unregisterReceiver(mWifiStateReceiver);
|
mContext.unregisterReceiver(mWifiStateReceiver);
|
||||||
mContext.getMainThreadHandler().removeCallbacks(mHideProgressBarRunnable);
|
mHandlerInjector.removeCallbacks(mHideProgressBarRunnable);
|
||||||
|
mHandlerInjector.removeCallbacks(mHideScanningSubTitleRunnable);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -246,6 +275,7 @@ public class InternetConnectivityPanel implements PanelContent, LifecycleObserve
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void onAirplaneModeChanged(boolean isAirplaneModeOn) {
|
public void onAirplaneModeChanged(boolean isAirplaneModeOn) {
|
||||||
|
log("onAirplaneModeChanged: isAirplaneModeOn:" + isAirplaneModeOn);
|
||||||
updatePanelTitle();
|
updatePanelTitle();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -254,6 +284,7 @@ public class InternetConnectivityPanel implements PanelContent, LifecycleObserve
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void onWifiEnabledChanged(boolean enabled) {
|
public void onWifiEnabledChanged(boolean enabled) {
|
||||||
|
log("onWifiEnabledChanged: enabled:" + enabled);
|
||||||
updatePanelTitle();
|
updatePanelTitle();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -305,13 +336,6 @@ public class InternetConnectivityPanel implements PanelContent, LifecycleObserve
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mIsProgressBarVisible) {
|
|
||||||
// When the Wi-Fi scan result callback is received
|
|
||||||
// Sub-Title: Searching for networks...
|
|
||||||
mSubtitle = SUBTITLE_TEXT_SEARCHING_FOR_NETWORKS;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mInternetUpdater.isAirplaneModeOn()) {
|
if (mInternetUpdater.isAirplaneModeOn()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -319,11 +343,18 @@ public class InternetConnectivityPanel implements PanelContent, LifecycleObserve
|
|||||||
final List<ScanResult> wifiList = mWifiManager.getScanResults();
|
final List<ScanResult> wifiList = mWifiManager.getScanResults();
|
||||||
if (wifiList != null && wifiList.size() != 0) {
|
if (wifiList != null && wifiList.size() != 0) {
|
||||||
// When the Wi-Fi scan result is not empty
|
// When the Wi-Fi scan result is not empty
|
||||||
// Sub-Title: Select the network you want to use for data
|
// Sub-Title: Tap a network to connect
|
||||||
mSubtitle = SUBTITLE_TEXT_TAP_A_NETWORK_TO_CONNECT;
|
mSubtitle = SUBTITLE_TEXT_TAP_A_NETWORK_TO_CONNECT;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!mIsScanningSubTitleShownOnce && mIsProgressBarVisible) {
|
||||||
|
// When the Wi-Fi scan result callback is received
|
||||||
|
// Sub-Title: Searching for networks...
|
||||||
|
mSubtitle = SUBTITLE_TEXT_SEARCHING_FOR_NETWORKS;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Sub-Title:
|
// Sub-Title:
|
||||||
// show non_carrier_network_unavailable
|
// show non_carrier_network_unavailable
|
||||||
// - while Wi-Fi on + no Wi-Fi item
|
// - while Wi-Fi on + no Wi-Fi item
|
||||||
@@ -353,7 +384,7 @@ public class InternetConnectivityPanel implements PanelContent, LifecycleObserve
|
|||||||
mSubtitle = SUBTITLE_TEXT_NON_CARRIER_NETWORK_UNAVAILABLE;
|
mSubtitle = SUBTITLE_TEXT_NON_CARRIER_NETWORK_UNAVAILABLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void showProgressBar() {
|
protected void updateProgressBar() {
|
||||||
if (mWifiManager == null || !mInternetUpdater.isWifiEnabled()) {
|
if (mWifiManager == null || !mInternetUpdater.isWifiEnabled()) {
|
||||||
setProgressBarVisible(false);
|
setProgressBarVisible(false);
|
||||||
return;
|
return;
|
||||||
@@ -362,8 +393,9 @@ public class InternetConnectivityPanel implements PanelContent, LifecycleObserve
|
|||||||
setProgressBarVisible(true);
|
setProgressBarVisible(true);
|
||||||
List<ScanResult> wifiScanResults = mWifiManager.getScanResults();
|
List<ScanResult> wifiScanResults = mWifiManager.getScanResults();
|
||||||
if (wifiScanResults != null && wifiScanResults.size() > 0) {
|
if (wifiScanResults != null && wifiScanResults.size() > 0) {
|
||||||
mContext.getMainThreadHandler().postDelayed(mHideProgressBarRunnable,
|
mHandlerInjector.postDelay(mHideProgressBarRunnable);
|
||||||
2000 /* delay millis */);
|
} else if (!mIsScanningSubTitleShownOnce) {
|
||||||
|
mHandlerInjector.postDelay(mHideScanningSubTitleRunnable);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -18,8 +18,6 @@ package com.android.settings.panel;
|
|||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
import static org.mockito.ArgumentMatchers.any;
|
|
||||||
import static org.mockito.ArgumentMatchers.anyLong;
|
|
||||||
import static org.mockito.Mockito.clearInvocations;
|
import static org.mockito.Mockito.clearInvocations;
|
||||||
import static org.mockito.Mockito.doReturn;
|
import static org.mockito.Mockito.doReturn;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
@@ -95,11 +93,31 @@ public class InternetConnectivityPanelTest {
|
|||||||
private FragmentActivity mPanelActivity;
|
private FragmentActivity mPanelActivity;
|
||||||
|
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
|
private FakeHandlerInjector mFakeHandlerInjector;
|
||||||
private InternetConnectivityPanel mPanel;
|
private InternetConnectivityPanel mPanel;
|
||||||
|
|
||||||
|
private class FakeHandlerInjector extends InternetConnectivityPanel.HandlerInjector {
|
||||||
|
|
||||||
|
private Runnable mRunnable;
|
||||||
|
|
||||||
|
FakeHandlerInjector(Context context) {
|
||||||
|
super(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void postDelay(Runnable runnable) {
|
||||||
|
mRunnable = runnable;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Runnable getRunnable() {
|
||||||
|
return mRunnable;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
mContext = spy(ApplicationProvider.getApplicationContext());
|
mContext = spy(ApplicationProvider.getApplicationContext());
|
||||||
|
mFakeHandlerInjector = new FakeHandlerInjector(mContext);
|
||||||
when(mContext.getApplicationContext()).thenReturn(mContext);
|
when(mContext.getApplicationContext()).thenReturn(mContext);
|
||||||
when(mContext.getMainThreadHandler()).thenReturn(mMainThreadHandler);
|
when(mContext.getMainThreadHandler()).thenReturn(mMainThreadHandler);
|
||||||
when(mContext.getSystemService(WifiManager.class)).thenReturn(mWifiManager);
|
when(mContext.getSystemService(WifiManager.class)).thenReturn(mWifiManager);
|
||||||
@@ -109,6 +127,7 @@ public class InternetConnectivityPanelTest {
|
|||||||
mPanel.mIsProviderModelEnabled = true;
|
mPanel.mIsProviderModelEnabled = true;
|
||||||
mPanel.mInternetUpdater = mInternetUpdater;
|
mPanel.mInternetUpdater = mInternetUpdater;
|
||||||
mPanel.mProviderModelSliceHelper = mProviderModelSliceHelper;
|
mPanel.mProviderModelSliceHelper = mProviderModelSliceHelper;
|
||||||
|
mPanel.mHandlerInjector = mFakeHandlerInjector;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -295,36 +314,41 @@ public class InternetConnectivityPanelTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void showProgressBar_wifiDisabled_hideProgress() {
|
public void updateProgressBar_wifiDisabled_hideProgress() {
|
||||||
mPanel.mIsProgressBarVisible = true;
|
mPanel.mIsProgressBarVisible = true;
|
||||||
doReturn(false).when(mInternetUpdater).isWifiEnabled();
|
doReturn(false).when(mInternetUpdater).isWifiEnabled();
|
||||||
clearInvocations(mPanelContentCallback);
|
clearInvocations(mPanelContentCallback);
|
||||||
|
|
||||||
mPanel.showProgressBar();
|
mPanel.updateProgressBar();
|
||||||
|
|
||||||
assertThat(mPanel.isProgressBarVisible()).isFalse();
|
assertThat(mPanel.isProgressBarVisible()).isFalse();
|
||||||
verify(mPanelContentCallback).onProgressBarVisibleChanged();
|
verify(mPanelContentCallback).onProgressBarVisibleChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void showProgressBar_noWifiScanResults_showProgressForever() {
|
public void updateProgressBar_noWifiScanResults_showProgressForever() {
|
||||||
|
mPanel.mIsScanningSubTitleShownOnce = false;
|
||||||
mPanel.mIsProgressBarVisible = false;
|
mPanel.mIsProgressBarVisible = false;
|
||||||
doReturn(true).when(mInternetUpdater).isWifiEnabled();
|
doReturn(true).when(mInternetUpdater).isWifiEnabled();
|
||||||
List<ScanResult> noWifiScanResults = new ArrayList<>();
|
List<ScanResult> noWifiScanResults = new ArrayList<>();
|
||||||
doReturn(noWifiScanResults).when(mWifiManager).getScanResults();
|
doReturn(noWifiScanResults).when(mWifiManager).getScanResults();
|
||||||
clearInvocations(mPanelContentCallback);
|
clearInvocations(mPanelContentCallback);
|
||||||
|
|
||||||
mPanel.showProgressBar();
|
mPanel.updateProgressBar();
|
||||||
|
|
||||||
assertThat(mPanel.isProgressBarVisible()).isTrue();
|
assertThat(mPanel.mIsProgressBarVisible).isTrue();
|
||||||
verify(mPanelContentCallback).onProgressBarVisibleChanged();
|
verify(mPanelContentCallback).onProgressBarVisibleChanged();
|
||||||
verify(mPanelContentCallback).onHeaderChanged();
|
verify(mPanelContentCallback).onHeaderChanged();
|
||||||
verify(mMainThreadHandler, never())
|
|
||||||
.postDelayed(any() /* mHideProgressBarRunnable */, anyLong());
|
assertThat(mFakeHandlerInjector.getRunnable())
|
||||||
|
.isEqualTo(mPanel.mHideScanningSubTitleRunnable);
|
||||||
|
mFakeHandlerInjector.getRunnable().run();
|
||||||
|
assertThat(mPanel.mIsScanningSubTitleShownOnce).isTrue();
|
||||||
|
assertThat(mPanel.mIsProgressBarVisible).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void showProgressBar_hasWifiScanResults_showProgressDelayedHide() {
|
public void updateProgressBar_hasWifiScanResults_showProgressDelayedHide() {
|
||||||
mPanel.mIsProgressBarVisible = false;
|
mPanel.mIsProgressBarVisible = false;
|
||||||
doReturn(true).when(mInternetUpdater).isWifiEnabled();
|
doReturn(true).when(mInternetUpdater).isWifiEnabled();
|
||||||
List<ScanResult> hasWifiScanResults = mock(ArrayList.class);
|
List<ScanResult> hasWifiScanResults = mock(ArrayList.class);
|
||||||
@@ -332,11 +356,15 @@ public class InternetConnectivityPanelTest {
|
|||||||
doReturn(hasWifiScanResults).when(mWifiManager).getScanResults();
|
doReturn(hasWifiScanResults).when(mWifiManager).getScanResults();
|
||||||
clearInvocations(mPanelContentCallback);
|
clearInvocations(mPanelContentCallback);
|
||||||
|
|
||||||
mPanel.showProgressBar();
|
mPanel.updateProgressBar();
|
||||||
|
|
||||||
assertThat(mPanel.isProgressBarVisible()).isTrue();
|
assertThat(mPanel.isProgressBarVisible()).isTrue();
|
||||||
verify(mPanelContentCallback).onProgressBarVisibleChanged();
|
verify(mPanelContentCallback).onProgressBarVisibleChanged();
|
||||||
verify(mMainThreadHandler).postDelayed(any() /* mHideProgressBarRunnable */, anyLong());
|
|
||||||
|
assertThat(mFakeHandlerInjector.getRunnable())
|
||||||
|
.isEqualTo(mPanel.mHideProgressBarRunnable);
|
||||||
|
mFakeHandlerInjector.getRunnable().run();
|
||||||
|
assertThat(mPanel.mIsProgressBarVisible).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
Reference in New Issue
Block a user