[Provider Model] Add WiFi toggle in internet panel
- Move Wi-Fi toggle from menu button to slice row - Remove Wi-Fi disconnect action - Show scanning sub-title once only Bug: 189912933 Test: manual test atest -c InternetConnectivityPanelTest \ ProviderModelSliceTest Change-Id: I2baf05362f5cd0a8ce94c7b3b2b112a7e9fe6894
This commit is contained in:
@@ -38,7 +38,6 @@ import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
import androidx.lifecycle.LifecycleObserver;
|
||||
import androidx.lifecycle.OnLifecycleEvent;
|
||||
|
||||
@@ -84,12 +83,13 @@ public class InternetConnectivityPanel implements PanelContent, LifecycleObserve
|
||||
}
|
||||
|
||||
if (TextUtils.equals(intent.getAction(), WifiManager.SCAN_RESULTS_AVAILABLE_ACTION)) {
|
||||
showProgressBar();
|
||||
updateProgressBar();
|
||||
updatePanelTitle();
|
||||
return;
|
||||
}
|
||||
|
||||
if (TextUtils.equals(intent.getAction(), WifiManager.NETWORK_STATE_CHANGED_ACTION)) {
|
||||
updateProgressBar();
|
||||
updatePanelTitle();
|
||||
}
|
||||
}
|
||||
@@ -110,13 +110,40 @@ public class InternetConnectivityPanel implements PanelContent, LifecycleObserve
|
||||
private int mDefaultDataSubid = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
|
||||
|
||||
// Wi-Fi scanning progress bar
|
||||
protected HandlerInjector mHandlerInjector;
|
||||
protected boolean mIsProgressBarVisible;
|
||||
protected final Runnable mHideProgressBarRunnable = () -> {
|
||||
protected boolean mIsScanningSubTitleShownOnce;
|
||||
protected Runnable mHideProgressBarRunnable = () -> {
|
||||
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) {
|
||||
mContext = context.getApplicationContext();
|
||||
mHandlerInjector = new HandlerInjector(context);
|
||||
mIsProviderModelEnabled = Utils.isProviderModelEnabled(mContext);
|
||||
mInternetUpdater = new InternetUpdater(context, null /* Lifecycle */, this);
|
||||
|
||||
@@ -150,7 +177,7 @@ public class InternetConnectivityPanel implements PanelContent, LifecycleObserve
|
||||
mTelephonyManager.registerTelephonyCallback(
|
||||
new HandlerExecutor(new Handler(Looper.getMainLooper())), mTelephonyCallback);
|
||||
mContext.registerReceiver(mWifiStateReceiver, mWifiStateFilter);
|
||||
showProgressBar();
|
||||
updateProgressBar();
|
||||
updatePanelTitle();
|
||||
}
|
||||
|
||||
@@ -165,7 +192,8 @@ public class InternetConnectivityPanel implements PanelContent, LifecycleObserve
|
||||
mConnectivityListener.stop();
|
||||
mTelephonyManager.unregisterTelephonyCallback(mTelephonyCallback);
|
||||
mContext.unregisterReceiver(mWifiStateReceiver);
|
||||
mContext.getMainThreadHandler().removeCallbacks(mHideProgressBarRunnable);
|
||||
mHandlerInjector.removeCallbacks(mHideProgressBarRunnable);
|
||||
mHandlerInjector.removeCallbacks(mHideScanningSubTitleRunnable);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -209,23 +237,6 @@ public class InternetConnectivityPanel implements PanelContent, LifecycleObserve
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCustomizedButtonUsed() {
|
||||
return mIsProviderModelEnabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getCustomizedButtonTitle() {
|
||||
return mContext.getText(
|
||||
mInternetUpdater.isWifiEnabled() ? R.string.turn_off_wifi : R.string.turn_on_wifi);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClickCustomizedButton(FragmentActivity panelActivity) {
|
||||
// Don't finish the panel activity
|
||||
mWifiManager.setWifiEnabled(!mInternetUpdater.isWifiEnabled());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isProgressBarVisible() {
|
||||
return mIsProgressBarVisible;
|
||||
@@ -246,6 +257,7 @@ public class InternetConnectivityPanel implements PanelContent, LifecycleObserve
|
||||
*/
|
||||
@Override
|
||||
public void onAirplaneModeChanged(boolean isAirplaneModeOn) {
|
||||
log("onAirplaneModeChanged: isAirplaneModeOn:" + isAirplaneModeOn);
|
||||
updatePanelTitle();
|
||||
}
|
||||
|
||||
@@ -254,6 +266,7 @@ public class InternetConnectivityPanel implements PanelContent, LifecycleObserve
|
||||
*/
|
||||
@Override
|
||||
public void onWifiEnabledChanged(boolean enabled) {
|
||||
log("onWifiEnabledChanged: enabled:" + enabled);
|
||||
updatePanelTitle();
|
||||
}
|
||||
|
||||
@@ -305,13 +318,6 @@ public class InternetConnectivityPanel implements PanelContent, LifecycleObserve
|
||||
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()) {
|
||||
return;
|
||||
}
|
||||
@@ -319,11 +325,18 @@ public class InternetConnectivityPanel implements PanelContent, LifecycleObserve
|
||||
final List<ScanResult> wifiList = mWifiManager.getScanResults();
|
||||
if (wifiList != null && wifiList.size() != 0) {
|
||||
// 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;
|
||||
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:
|
||||
// show non_carrier_network_unavailable
|
||||
// - while Wi-Fi on + no Wi-Fi item
|
||||
@@ -353,7 +366,7 @@ public class InternetConnectivityPanel implements PanelContent, LifecycleObserve
|
||||
mSubtitle = SUBTITLE_TEXT_NON_CARRIER_NETWORK_UNAVAILABLE;
|
||||
}
|
||||
|
||||
protected void showProgressBar() {
|
||||
protected void updateProgressBar() {
|
||||
if (mWifiManager == null || !mInternetUpdater.isWifiEnabled()) {
|
||||
setProgressBarVisible(false);
|
||||
return;
|
||||
@@ -362,8 +375,9 @@ public class InternetConnectivityPanel implements PanelContent, LifecycleObserve
|
||||
setProgressBarVisible(true);
|
||||
List<ScanResult> wifiScanResults = mWifiManager.getScanResults();
|
||||
if (wifiScanResults != null && wifiScanResults.size() > 0) {
|
||||
mContext.getMainThreadHandler().postDelayed(mHideProgressBarRunnable,
|
||||
2000 /* delay millis */);
|
||||
mHandlerInjector.postDelay(mHideProgressBarRunnable);
|
||||
} else if (!mIsScanningSubTitleShownOnce) {
|
||||
mHandlerInjector.postDelay(mHideScanningSubTitleRunnable);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user