diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/NetworkControllerImpl.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/NetworkControllerImpl.java
index 6c0b425ab3617..9cfd26b322e5d 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/NetworkControllerImpl.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/NetworkControllerImpl.java
@@ -41,6 +41,7 @@ import android.util.Log;
import android.view.View;
import android.widget.TextView;
+import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.telephony.IccCardConstants;
import com.android.internal.telephony.TelephonyIntents;
import com.android.internal.telephony.cdma.EriInfo;
@@ -170,6 +171,7 @@ public class NetworkControllerImpl extends BroadcastReceiver
private final AccessPointController mAccessPoints;
private final MobileDataController mMobileDataController;
+ private final ConnectivityManager mConnectivityManager;
/**
* Construct this controller object and register for updates.
@@ -178,9 +180,9 @@ public class NetworkControllerImpl extends BroadcastReceiver
mContext = context;
final Resources res = context.getResources();
- ConnectivityManager cm = (ConnectivityManager)mContext.getSystemService(
- Context.CONNECTIVITY_SERVICE);
- mHasMobileDataFeature = cm.isNetworkSupported(ConnectivityManager.TYPE_MOBILE);
+ mConnectivityManager =
+ (ConnectivityManager)mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
+ mHasMobileDataFeature = getCM().isNetworkSupported(ConnectivityManager.TYPE_MOBILE);
mShowPhoneRSSIForData = res.getBoolean(R.bool.config_showPhoneRSSIForData);
mShowAtLeastThreeGees = res.getBoolean(R.bool.config_showMin3G);
@@ -192,13 +194,7 @@ public class NetworkControllerImpl extends BroadcastReceiver
updateWimaxIcons();
// telephony
- mPhone = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
- mPhone.listen(mPhoneStateListener,
- PhoneStateListener.LISTEN_SERVICE_STATE
- | PhoneStateListener.LISTEN_SIGNAL_STRENGTHS
- | PhoneStateListener.LISTEN_CALL_STATE
- | PhoneStateListener.LISTEN_DATA_CONNECTION_STATE
- | PhoneStateListener.LISTEN_DATA_ACTIVITY);
+ mPhone = (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE);
mHspaDataDistinguishable = mContext.getResources().getBoolean(
R.bool.config_hspa_data_distinguishable);
mNetworkNameSeparator = mContext.getString(R.string.status_bar_network_name_separator);
@@ -215,6 +211,36 @@ public class NetworkControllerImpl extends BroadcastReceiver
mWifiChannel.connect(mContext, handler, wifiMessenger);
}
+ registerListeners();
+
+ // AIRPLANE_MODE_CHANGED is sent at boot; we've probably already missed it
+ updateAirplaneMode();
+
+ mLastLocale = mContext.getResources().getConfiguration().locale;
+ mAccessPoints = new AccessPointController(mContext);
+ mMobileDataController = new MobileDataController(mContext);
+ mMobileDataController.setCallback(new MobileDataController.Callback() {
+ @Override
+ public void onMobileDataEnabled(boolean enabled) {
+ notifyMobileDataEnabled(enabled);
+ }
+ });
+ }
+
+ @VisibleForTesting
+ protected ConnectivityManager getCM() {
+ return mConnectivityManager;
+ }
+
+ @VisibleForTesting
+ protected void registerListeners() {
+ mPhone.listen(mPhoneStateListener,
+ PhoneStateListener.LISTEN_SERVICE_STATE
+ | PhoneStateListener.LISTEN_SIGNAL_STRENGTHS
+ | PhoneStateListener.LISTEN_CALL_STATE
+ | PhoneStateListener.LISTEN_DATA_CONNECTION_STATE
+ | PhoneStateListener.LISTEN_DATA_ACTIVITY);
+
// broadcasts
IntentFilter filter = new IntentFilter();
filter.addAction(WifiManager.RSSI_CHANGED_ACTION);
@@ -233,20 +259,7 @@ public class NetworkControllerImpl extends BroadcastReceiver
filter.addAction(WimaxManagerConstants.SIGNAL_LEVEL_CHANGED_ACTION);
filter.addAction(WimaxManagerConstants.NET_4G_STATE_CHANGED_ACTION);
}
- context.registerReceiver(this, filter);
-
- // AIRPLANE_MODE_CHANGED is sent at boot; we've probably already missed it
- updateAirplaneMode();
-
- mLastLocale = mContext.getResources().getConfiguration().locale;
- mAccessPoints = new AccessPointController(mContext);
- mMobileDataController = new MobileDataController(mContext);
- mMobileDataController.setCallback(new MobileDataController.Callback() {
- @Override
- public void onMobileDataEnabled(boolean enabled) {
- notifyMobileDataEnabled(enabled);
- }
- });
+ mContext.registerReceiver(this, filter);
}
@Override
@@ -1072,9 +1085,7 @@ public class NetworkControllerImpl extends BroadcastReceiver
Log.d(TAG, "updateConnectivity: intent=" + intent);
}
- final ConnectivityManager connManager = (ConnectivityManager) mContext
- .getSystemService(Context.CONNECTIVITY_SERVICE);
- final NetworkInfo info = connManager.getActiveNetworkInfo();
+ final NetworkInfo info = getCM().getActiveNetworkInfo();
// Are we connected at all, by any interface?
mConnected = info != null && info.isConnected();
diff --git a/packages/SystemUI/tests/Android.mk b/packages/SystemUI/tests/Android.mk
index 28e4b860b59bf..262e0714f660c 100644
--- a/packages/SystemUI/tests/Android.mk
+++ b/packages/SystemUI/tests/Android.mk
@@ -22,6 +22,9 @@ LOCAL_SRC_FILES := $(call all-java-files-under, src)
LOCAL_JAVA_LIBRARIES := android.test.runner
LOCAL_PACKAGE_NAME := SystemUITests
+LOCAL_INSTRUMENTATION_FOR := SystemUI
+
+LOCAL_STATIC_JAVA_LIBRARIES := mockito-target
# sign this with platform cert, so this test is allowed to inject key events into
# UI it doesn't own. This is necessary to allow screenshots to be taken
diff --git a/packages/SystemUI/tests/AndroidManifest.xml b/packages/SystemUI/tests/AndroidManifest.xml
index e52806d6a7acd..1d319cf0bd0a8 100644
--- a/packages/SystemUI/tests/AndroidManifest.xml
+++ b/packages/SystemUI/tests/AndroidManifest.xml
@@ -25,7 +25,7 @@
diff --git a/packages/SystemUI/tests/src/com/android/systemui/screenshot/ScreenshotTest.java b/packages/SystemUI/tests/src/com/android/systemui/screenshot/ScreenshotTest.java
index a0bc4d7da7466..5e5c2849523b8 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/screenshot/ScreenshotTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/screenshot/ScreenshotTest.java
@@ -44,6 +44,10 @@ public class ScreenshotTest extends ActivityInstrumentationTestCase2 iconArg = ArgumentCaptor.forClass(Integer.class);
+ ArgumentCaptor visibleArg = ArgumentCaptor.forClass(Boolean.class);
+
+ // TODO: Verify all fields.
+ Mockito.verify(mSignalCluster, Mockito.atLeastOnce()).setMobileDataIndicators(
+ visibleArg.capture(), iconArg.capture(),
+ ArgumentCaptor.forClass(Integer.class).capture(),
+ ArgumentCaptor.forClass(String.class).capture(),
+ ArgumentCaptor.forClass(String.class).capture(),
+ ArgumentCaptor.forClass(Boolean.class).capture());
+
+ assertEquals(icon, (int) iconArg.getValue());
+ assertEquals(visible, (boolean) visibleArg.getValue());
+ }
+
+ private class FakeNetworkControllerImpl extends NetworkControllerImpl {
+ public FakeNetworkControllerImpl(Context context) {
+ super(context);
+ }
+
+ @Override
+ public ConnectivityManager getCM() {
+ return mMockCM;
+ }
+
+ public void registerListeners() {};
+ }
+}
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/NetworkControllerSignalTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/NetworkControllerSignalTest.java
new file mode 100644
index 0000000000000..fc2b1aa6da08b
--- /dev/null
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/NetworkControllerSignalTest.java
@@ -0,0 +1,37 @@
+package com.android.systemui.statusbar.policy;
+
+import android.net.ConnectivityManager;
+import android.telephony.ServiceState;
+import android.telephony.SignalStrength;
+import android.telephony.TelephonyManager;
+
+public class NetworkControllerSignalTest extends NetworkControllerBaseTest {
+
+ public void testSignalStrength() {
+ int testStrength = SignalStrength.SIGNAL_STRENGTH_MODERATE;
+ setIsGsm(true);
+ setVoiceRegState(ServiceState.STATE_IN_SERVICE);
+ setGsmRoaming(false);
+ setLevel(testStrength);
+ updateDataConnectionState(TelephonyManager.DATA_CONNECTED,
+ TelephonyManager.NETWORK_TYPE_UMTS);
+ setConnectivity(100, ConnectivityManager.TYPE_MOBILE, true);
+
+ verifyLastMobileDataIndicators(true,
+ TelephonyIcons.TELEPHONY_SIGNAL_STRENGTH[1][testStrength]);
+ }
+
+ public void testSignalRoaming() {
+ int testStrength = SignalStrength.SIGNAL_STRENGTH_MODERATE;
+ setIsGsm(true);
+ setVoiceRegState(ServiceState.STATE_IN_SERVICE);
+ setGsmRoaming(true);
+ setLevel(testStrength);
+ updateDataConnectionState(TelephonyManager.DATA_CONNECTED,
+ TelephonyManager.NETWORK_TYPE_UMTS);
+ setConnectivity(100, ConnectivityManager.TYPE_MOBILE, true);
+
+ verifyLastMobileDataIndicators(true,
+ TelephonyIcons.TELEPHONY_SIGNAL_STRENGTH_ROAMING[1][testStrength]);
+ }
+}