summaryrefslogtreecommitdiffstats
path: root/packages/SystemUI/tests
diff options
context:
space:
mode:
authorJason Monk <jmonk@google.com>2015-06-11 11:10:15 -0400
committerJason Monk <jmonk@google.com>2015-06-11 11:10:15 -0400
commitc6cc6266c9325f180b1a073f733fdf0a64e9286f (patch)
tree42203cf3643f5b0f713d883246820f2b6e555f02 /packages/SystemUI/tests
parentfd9a2dafdc6516a62bdf13c81ec2ac579a8fd998 (diff)
downloadframeworks_base-c6cc6266c9325f180b1a073f733fdf0a64e9286f.zip
frameworks_base-c6cc6266c9325f180b1a073f733fdf0a64e9286f.tar.gz
frameworks_base-c6cc6266c9325f180b1a073f733fdf0a64e9286f.tar.bz2
Fix EmergencyCallback in NetworkController
- Do some cleanup so that things are more testable - Test emergency callback since its possible - Fix emergency callback in no sims case Bug: 16218652 Change-Id: Ic859eff732cc11c5ae8aa6ced3584905bbe215c7
Diffstat (limited to 'packages/SystemUI/tests')
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/NetworkControllerBaseTest.java39
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/NetworkControllerDataTest.java2
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/NetworkControllerSignalTest.java34
3 files changed, 60 insertions, 15 deletions
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/NetworkControllerBaseTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/NetworkControllerBaseTest.java
index 441bb16..30c08cd 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/NetworkControllerBaseTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/NetworkControllerBaseTest.java
@@ -36,6 +36,7 @@ import com.android.internal.telephony.cdma.EriInfo;
import com.android.systemui.SysuiTestCase;
import com.android.systemui.statusbar.policy.NetworkController.IconState;
import com.android.systemui.statusbar.policy.NetworkControllerImpl.Config;
+import com.android.systemui.statusbar.policy.NetworkControllerImpl.SubscriptionDefaults;
import org.mockito.ArgumentCaptor;
import org.mockito.Mockito;
@@ -66,6 +67,7 @@ public class NetworkControllerBaseTest extends SysuiTestCase {
protected TelephonyManager mMockTm;
protected Config mConfig;
protected CallbackHandler mCallbackHandler;
+ protected SubscriptionDefaults mMockSubDefaults;
protected int mSubId;
@@ -79,6 +81,7 @@ public class NetworkControllerBaseTest extends SysuiTestCase {
mMockTm = mock(TelephonyManager.class);
mMockSm = mock(SubscriptionManager.class);
mMockCm = mock(ConnectivityManager.class);
+ mMockSubDefaults = mock(SubscriptionDefaults.class);
mNetCapabilities = new NetworkCapabilities();
when(mMockCm.isNetworkSupported(ConnectivityManager.TYPE_MOBILE)).thenReturn(true);
when(mMockCm.getDefaultNetworkCapabilitiesForUser(0)).thenReturn(
@@ -92,25 +95,39 @@ public class NetworkControllerBaseTest extends SysuiTestCase {
mCallbackHandler = mock(CallbackHandler.class);
mNetworkController = new NetworkControllerImpl(mContext, mMockCm, mMockTm, mMockWm, mMockSm,
mConfig, Looper.getMainLooper(), mCallbackHandler,
- mock(AccessPointControllerImpl.class), mock(MobileDataControllerImpl.class));
+ mock(AccessPointControllerImpl.class), mock(MobileDataControllerImpl.class),
+ mMockSubDefaults);
setupNetworkController();
+
+ // Trigger blank callbacks to always get the current state (some tests don't trigger
+ // changes from default state).
+ mNetworkController.addSignalCallback(null);
+ mNetworkController.addEmergencyListener(null);
}
protected void setupNetworkController() {
// For now just pretend to be the data sim, so we can test that too.
mSubId = SubscriptionManager.DEFAULT_SUBSCRIPTION_ID;
- SubscriptionInfo subscription = mock(SubscriptionInfo.class);
- List<SubscriptionInfo> subs = new ArrayList<SubscriptionInfo>();
- when(subscription.getSubscriptionId()).thenReturn(mSubId);
- subs.add(subscription);
- mNetworkController.setCurrentSubscriptions(subs);
+ setDefaultSubId(mSubId);
+ setSubscriptions(mSubId);
mMobileSignalController = mNetworkController.mMobileSignalControllers.get(mSubId);
- mMobileSignalController.getState().dataSim = true;
mPhoneStateListener = mMobileSignalController.mPhoneStateListener;
+ }
- // Trigger blank callbacks to always get the current state (some tests don't trigger
- // changes from default state).
- mNetworkController.addSignalCallback(null);
+ protected void setDefaultSubId(int subId) {
+ when(mMockSubDefaults.getDefaultDataSubId()).thenReturn(subId);
+ when(mMockSubDefaults.getDefaultVoiceSubId()).thenReturn(subId);
+ }
+
+ protected void setSubscriptions(int... subIds) {
+ List<SubscriptionInfo> subs = new ArrayList<SubscriptionInfo>();
+ for (int subId : subIds) {
+ SubscriptionInfo subscription = mock(SubscriptionInfo.class);
+ when(subscription.getSubscriptionId()).thenReturn(subId);
+ subs.add(subscription);
+ }
+ when(mMockSm.getActiveSubscriptionInfoList()).thenReturn(subs);
+ mNetworkController.doUpdateMobileControllers();
}
protected NetworkControllerImpl setUpNoMobileData() {
@@ -119,7 +136,7 @@ public class NetworkControllerBaseTest extends SysuiTestCase {
= new NetworkControllerImpl(mContext, mMockCm, mMockTm, mMockWm, mMockSm,
mConfig, Looper.getMainLooper(), mCallbackHandler,
mock(AccessPointControllerImpl.class),
- mock(MobileDataControllerImpl.class));
+ mock(MobileDataControllerImpl.class), mMockSubDefaults);
setupNetworkController();
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/NetworkControllerDataTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/NetworkControllerDataTest.java
index 15752e1..e60e0a6 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/NetworkControllerDataTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/NetworkControllerDataTest.java
@@ -77,7 +77,7 @@ public class NetworkControllerDataTest extends NetworkControllerBaseTest {
mNetworkController = new NetworkControllerImpl(mContext, mMockCm, mMockTm, mMockWm, mMockSm,
mConfig, Looper.getMainLooper(), mCallbackHandler,
Mockito.mock(AccessPointControllerImpl.class),
- Mockito.mock(MobileDataControllerImpl.class));
+ Mockito.mock(MobileDataControllerImpl.class), mMockSubDefaults);
setupNetworkController();
setupDefaultSignal();
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
index 2df1980..168aebe 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/NetworkControllerSignalTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/NetworkControllerSignalTest.java
@@ -21,7 +21,6 @@ import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkCapabilities;
import android.os.Looper;
-import android.telephony.ServiceState;
import android.telephony.SignalStrength;
import android.telephony.SubscriptionInfo;
import android.telephony.TelephonyManager;
@@ -30,6 +29,7 @@ import com.android.internal.telephony.PhoneConstants;
import com.android.internal.telephony.TelephonyIntents;
import com.android.systemui.R;
+import org.mockito.ArgumentCaptor;
import org.mockito.Mockito;
import java.util.ArrayList;
@@ -43,7 +43,8 @@ public class NetworkControllerSignalTest extends NetworkControllerBaseTest {
// Create a new NetworkController as this is currently handled in constructor.
mNetworkController = new NetworkControllerImpl(mContext, mMockCm, mMockTm, mMockWm, mMockSm,
mConfig, Looper.getMainLooper(), mCallbackHandler,
- mock(AccessPointControllerImpl.class), mock(MobileDataControllerImpl.class));
+ mock(AccessPointControllerImpl.class), mock(MobileDataControllerImpl.class),
+ mMockSubDefaults);
setupNetworkController();
verifyLastMobileDataIndicators(false, 0, 0);
@@ -57,13 +58,33 @@ public class NetworkControllerSignalTest extends NetworkControllerBaseTest {
verifyHasNoSims(true);
}
+ public void testEmergencyOnly() {
+ setupDefaultSignal();
+ mNetworkController.recalculateEmergency();
+ verifyEmergencyOnly(false);
+
+ mMobileSignalController.getState().isEmergency = true;
+ mNetworkController.recalculateEmergency();
+ verifyEmergencyOnly(true);
+ }
+
+ public void testEmergencyOnlyNoSubscriptions() {
+ setupDefaultSignal();
+ mNetworkController.recalculateEmergency();
+ verifyEmergencyOnly(false);
+
+ setSubscriptions();
+ verifyEmergencyOnly(true);
+ }
+
public void testNoSimlessIconWithoutMobile() {
// Turn off mobile network support.
Mockito.when(mMockCm.isNetworkSupported(ConnectivityManager.TYPE_MOBILE)).thenReturn(false);
// Create a new NetworkController as this is currently handled in constructor.
mNetworkController = new NetworkControllerImpl(mContext, mMockCm, mMockTm, mMockWm, mMockSm,
mConfig, Looper.getMainLooper(), mCallbackHandler,
- mock(AccessPointControllerImpl.class), mock(MobileDataControllerImpl.class));
+ mock(AccessPointControllerImpl.class), mock(MobileDataControllerImpl.class),
+ mMockSubDefaults);
setupNetworkController();
// No Subscriptions.
@@ -418,4 +439,11 @@ public class NetworkControllerSignalTest extends NetworkControllerBaseTest {
TelephonyIcons.TELEPHONY_SIGNAL_STRENGTH[1][strength] /* strengthIcon */,
DEFAULT_ICON /* typeIcon */);
}
+
+ private void verifyEmergencyOnly(boolean isEmergencyOnly) {
+ ArgumentCaptor<Boolean> emergencyOnly = ArgumentCaptor.forClass(Boolean.class);
+ Mockito.verify(mCallbackHandler, Mockito.atLeastOnce()).setEmergencyCallsOnly(
+ emergencyOnly.capture());
+ assertEquals(isEmergencyOnly, (boolean) emergencyOnly.getValue());
+ }
}