Merge "Replace usages of ServiceState#getDataNetworkType"

am: 922ec35d28

Change-Id: Icbdeb12e752bfd77e8c818251b442acb93079f66
This commit is contained in:
Hall Liu
2020-01-14 20:10:00 -08:00
committed by android-build-merger
4 changed files with 44 additions and 6 deletions

View File

@@ -15,6 +15,9 @@
*/ */
package com.android.systemui.statusbar.policy; package com.android.systemui.statusbar.policy;
import static android.telephony.AccessNetworkConstants.TRANSPORT_TYPE_WWAN;
import static android.telephony.NetworkRegistrationInfo.DOMAIN_PS;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.database.ContentObserver; import android.database.ContentObserver;
@@ -708,7 +711,11 @@ public class MobileSignalController extends SignalController<
} }
mServiceState = state; mServiceState = state;
if (mServiceState != null) { if (mServiceState != null) {
updateDataNetType(mServiceState.getDataNetworkType()); NetworkRegistrationInfo regInfo = mServiceState.getNetworkRegistrationInfo(
DOMAIN_PS, TRANSPORT_TYPE_WWAN);
if (regInfo != null) {
updateDataNetType(regInfo.getAccessNetworkTechnology());
}
} }
updateTelephony(); updateTelephony();
} }

View File

@@ -16,6 +16,9 @@
package com.android.systemui.statusbar.policy; package com.android.systemui.statusbar.policy;
import static android.telephony.AccessNetworkConstants.TRANSPORT_TYPE_WWAN;
import static android.telephony.NetworkRegistrationInfo.DOMAIN_PS;
import static junit.framework.Assert.assertEquals; import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertNotNull; import static junit.framework.Assert.assertNotNull;
@@ -39,6 +42,7 @@ import android.net.wifi.WifiManager;
import android.os.Handler; import android.os.Handler;
import android.provider.Settings; import android.provider.Settings;
import android.provider.Settings.Global; import android.provider.Settings.Global;
import android.telephony.NetworkRegistrationInfo;
import android.telephony.PhoneStateListener; import android.telephony.PhoneStateListener;
import android.telephony.ServiceState; import android.telephony.ServiceState;
import android.telephony.SignalStrength; import android.telephony.SignalStrength;
@@ -347,7 +351,13 @@ public class NetworkControllerBaseTest extends SysuiTestCase {
} }
public void updateDataConnectionState(int dataState, int dataNetType) { public void updateDataConnectionState(int dataState, int dataNetType) {
when(mServiceState.getDataNetworkType()).thenReturn(dataNetType); NetworkRegistrationInfo fakeRegInfo = new NetworkRegistrationInfo.Builder()
.setTransportType(TRANSPORT_TYPE_WWAN)
.setDomain(DOMAIN_PS)
.setAccessNetworkTechnology(dataNetType)
.build();
when(mServiceState.getNetworkRegistrationInfo(DOMAIN_PS, TRANSPORT_TYPE_WWAN))
.thenReturn(fakeRegInfo);
mPhoneStateListener.onDataConnectionStateChanged(dataState, dataNetType); mPhoneStateListener.onDataConnectionStateChanged(dataState, dataNetType);
} }

View File

@@ -1,5 +1,8 @@
package com.android.systemui.statusbar.policy; package com.android.systemui.statusbar.policy;
import static android.telephony.AccessNetworkConstants.TRANSPORT_TYPE_WWAN;
import static android.telephony.NetworkRegistrationInfo.DOMAIN_PS;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.anyInt; import static org.mockito.Matchers.anyInt;
@@ -418,7 +421,13 @@ public class NetworkControllerDataTest extends NetworkControllerBaseTest {
// State from NR_5G to NONE NR_STATE_RESTRICTED, showing corresponding icon // State from NR_5G to NONE NR_STATE_RESTRICTED, showing corresponding icon
doReturn(NetworkRegistrationInfo.NR_STATE_RESTRICTED).when(mServiceState).getNrState(); doReturn(NetworkRegistrationInfo.NR_STATE_RESTRICTED).when(mServiceState).getNrState();
doReturn(TelephonyManager.NETWORK_TYPE_LTE).when(mServiceState).getDataNetworkType(); NetworkRegistrationInfo fakeRegInfo = new NetworkRegistrationInfo.Builder()
.setTransportType(TRANSPORT_TYPE_WWAN)
.setDomain(DOMAIN_PS)
.setAccessNetworkTechnology(TelephonyManager.NETWORK_TYPE_LTE)
.build();
doReturn(fakeRegInfo).when(mServiceState)
.getNetworkRegistrationInfo(DOMAIN_PS, TRANSPORT_TYPE_WWAN);
mPhoneStateListener.onDataConnectionStateChanged(TelephonyManager.DATA_CONNECTED, mPhoneStateListener.onDataConnectionStateChanged(TelephonyManager.DATA_CONNECTED,
TelephonyManager.NETWORK_TYPE_LTE); TelephonyManager.NETWORK_TYPE_LTE);
@@ -480,8 +489,13 @@ public class NetworkControllerDataTest extends NetworkControllerBaseTest {
verifyDataIndicators(TelephonyIcons.ICON_LTE); verifyDataIndicators(TelephonyIcons.ICON_LTE);
when(mServiceState.getDataNetworkType()) NetworkRegistrationInfo fakeRegInfo = new NetworkRegistrationInfo.Builder()
.thenReturn(TelephonyManager.NETWORK_TYPE_HSPA); .setTransportType(TRANSPORT_TYPE_WWAN)
.setDomain(DOMAIN_PS)
.setAccessNetworkTechnology(TelephonyManager.NETWORK_TYPE_HSPA)
.build();
when(mServiceState.getNetworkRegistrationInfo(DOMAIN_PS, TRANSPORT_TYPE_WWAN))
.thenReturn(fakeRegInfo);
updateServiceState(); updateServiceState();
verifyDataIndicators(TelephonyIcons.ICON_H); verifyDataIndicators(TelephonyIcons.ICON_H);
} }

View File

@@ -16,6 +16,9 @@
package com.android.server.connectivity; package com.android.server.connectivity;
import static android.telephony.AccessNetworkConstants.TRANSPORT_TYPE_WWAN;
import static android.telephony.NetworkRegistrationInfo.DOMAIN_PS;
import android.content.BroadcastReceiver; import android.content.BroadcastReceiver;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
@@ -24,6 +27,7 @@ import android.net.ConnectivityManager;
import android.os.Handler; import android.os.Handler;
import android.os.Looper; import android.os.Looper;
import android.os.RemoteException; import android.os.RemoteException;
import android.telephony.NetworkRegistrationInfo;
import android.telephony.PhoneStateListener; import android.telephony.PhoneStateListener;
import android.telephony.ServiceState; import android.telephony.ServiceState;
import android.telephony.SignalStrength; import android.telephony.SignalStrength;
@@ -91,7 +95,10 @@ public class DataConnectionStats extends BroadcastReceiver {
boolean visible = (simReadyOrUnknown || isCdma()) // we only check the sim state for GSM boolean visible = (simReadyOrUnknown || isCdma()) // we only check the sim state for GSM
&& hasService() && hasService()
&& mDataState == TelephonyManager.DATA_CONNECTED; && mDataState == TelephonyManager.DATA_CONNECTED;
int networkType = mServiceState.getDataNetworkType(); NetworkRegistrationInfo regInfo =
mServiceState.getNetworkRegistrationInfo(DOMAIN_PS, TRANSPORT_TYPE_WWAN);
int networkType = regInfo == null ? TelephonyManager.NETWORK_TYPE_UNKNOWN
: regInfo.getAccessNetworkTechnology();
if (DEBUG) Log.d(TAG, String.format("Noting data connection for network type %s: %svisible", if (DEBUG) Log.d(TAG, String.format("Noting data connection for network type %s: %svisible",
networkType, visible ? "" : "not ")); networkType, visible ? "" : "not "));
try { try {