[Provider Model] Show carrier network to internet preference
- If the connected network is the merged carrier Wi-Fi, then show carrier network to internet prefernce. Bug: 191091045 Test: manual test atest -c InternetUpdaterTest Change-Id: Iad3869f086ea0a4d0607691c6709ee12567831c7
This commit is contained in:
@@ -33,6 +33,7 @@ import android.net.ConnectivityManager;
|
||||
import android.net.ConnectivityManager.NetworkCallback;
|
||||
import android.net.Network;
|
||||
import android.net.NetworkCapabilities;
|
||||
import android.net.wifi.WifiInfo;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.util.Log;
|
||||
|
||||
@@ -249,6 +250,9 @@ public class InternetUpdater implements AirplaneModeEnabler.OnAirplaneModeChange
|
||||
@InternetType int internetType = INTERNET_NETWORKS_AVAILABLE;
|
||||
if (mInternetAvailable) {
|
||||
internetType = sTransportMap.get(mTransport);
|
||||
if (internetType == INTERNET_WIFI && isCarrierWifiActive()) {
|
||||
internetType = INTERNET_CELLULAR;
|
||||
}
|
||||
} else if (mAirplaneModeEnabler.isAirplaneModeOn()
|
||||
&& mWifiManager.getWifiState() != WifiManager.WIFI_STATE_ENABLED) {
|
||||
internetType = INTERNET_OFF;
|
||||
@@ -260,6 +264,15 @@ public class InternetUpdater implements AirplaneModeEnabler.OnAirplaneModeChange
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean isCarrierWifiActive() {
|
||||
final WifiInfo wifiInfo = mWifiManager.getConnectionInfo();
|
||||
if (wifiInfo == null || !wifiInfo.isCarrierMerged()) {
|
||||
return false;
|
||||
}
|
||||
Log.i(TAG, "Detect a merged carrier Wi-Fi connected.");
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the internet type.
|
||||
*/
|
||||
|
@@ -39,6 +39,7 @@ import android.content.Context;
|
||||
import android.content.IntentFilter;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.NetworkCapabilities;
|
||||
import android.net.wifi.WifiInfo;
|
||||
import android.net.wifi.WifiManager;
|
||||
|
||||
import androidx.lifecycle.Lifecycle;
|
||||
@@ -194,4 +195,17 @@ public class InternetUpdaterTest {
|
||||
|
||||
assertThat(mInternetUpdater.getInternetType()).isEqualTo(INTERNET_ETHERNET);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateInternetType_carrierWifiConnected_getInternetCellular() {
|
||||
final WifiInfo wifiInfo = mock(WifiInfo.class);
|
||||
doReturn(wifiInfo).when(mWifiManager).getConnectionInfo();
|
||||
doReturn(true).when(wifiInfo).isCarrierMerged();
|
||||
mInternetUpdater.mInternetAvailable = true;
|
||||
mInternetUpdater.mTransport = TRANSPORT_WIFI;
|
||||
|
||||
mInternetUpdater.updateInternetType();
|
||||
|
||||
assertThat(mInternetUpdater.getInternetType()).isEqualTo(INTERNET_CELLULAR);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user