Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d26416ce authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "[Provider Model] Show carrier network to internet preference" into sc-dev

parents 74babf6e 627efc46
Loading
Loading
Loading
Loading
+13 −0
Original line number Diff line number Diff line
@@ -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.
     */
+14 −0
Original line number Diff line number Diff line
@@ -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);
    }
}