summaryrefslogtreecommitdiffstats
path: root/packages
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
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')
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java7
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarHeaderView.java7
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/policy/MobileSignalController.java8
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/policy/NetworkControllerImpl.java38
-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
7 files changed, 102 insertions, 33 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java
index 33e8e59..c77e7f0 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java
@@ -812,12 +812,7 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,
signalClusterQs.setNetworkController(mNetworkController);
final boolean isAPhone = mNetworkController.hasVoiceCallingFeature();
if (isAPhone) {
- mNetworkController.addEmergencyListener(new NetworkControllerImpl.EmergencyListener() {
- @Override
- public void setEmergencyCallsOnly(boolean emergencyOnly) {
- mHeader.setShowEmergencyCallsOnly(emergencyOnly);
- }
- });
+ mNetworkController.addEmergencyListener(mHeader);
}
mFlashlightController = new FlashlightController(mContext);
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarHeaderView.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarHeaderView.java
index dfc6924..a81f06e 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarHeaderView.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarHeaderView.java
@@ -45,6 +45,7 @@ import com.android.systemui.R;
import com.android.systemui.qs.QSPanel;
import com.android.systemui.qs.QSTile;
import com.android.systemui.statusbar.policy.BatteryController;
+import com.android.systemui.statusbar.policy.NetworkControllerImpl.EmergencyListener;
import com.android.systemui.statusbar.policy.NextAlarmController;
import com.android.systemui.statusbar.policy.UserInfoController;
@@ -54,7 +55,8 @@ import java.text.NumberFormat;
* The view to manage the header area in the expanded status bar.
*/
public class StatusBarHeaderView extends RelativeLayout implements View.OnClickListener,
- BatteryController.BatteryStateChangeCallback, NextAlarmController.NextAlarmChangeCallback {
+ BatteryController.BatteryStateChangeCallback, NextAlarmController.NextAlarmChangeCallback,
+ EmergencyListener {
private boolean mExpanded;
private boolean mListening;
@@ -527,7 +529,8 @@ public class StatusBarHeaderView extends RelativeLayout implements View.OnClickL
return true;
}
- public void setShowEmergencyCallsOnly(boolean show) {
+ @Override
+ public void setEmergencyCallsOnly(boolean show) {
boolean changed = show != mShowEmergencyCallsOnly;
if (changed) {
mShowEmergencyCallsOnly = show;
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/MobileSignalController.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/MobileSignalController.java
index 686e24c..0aa0b4a 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/MobileSignalController.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/MobileSignalController.java
@@ -34,6 +34,7 @@ import com.android.internal.telephony.cdma.EriInfo;
import com.android.systemui.R;
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 java.io.PrintWriter;
import java.util.BitSet;
@@ -43,6 +44,7 @@ import java.util.Objects;
public class MobileSignalController extends SignalController<
MobileSignalController.MobileState, MobileSignalController.MobileIconGroup> {
private final TelephonyManager mPhone;
+ private final SubscriptionDefaults mDefaults;
private final String mNetworkNameDefault;
private final String mNetworkNameSeparator;
@VisibleForTesting
@@ -67,13 +69,15 @@ public class MobileSignalController extends SignalController<
// need listener lists anymore.
public MobileSignalController(Context context, Config config, boolean hasMobileData,
TelephonyManager phone, CallbackHandler callbackHandler,
- NetworkControllerImpl networkController, SubscriptionInfo info, Looper receiverLooper) {
+ NetworkControllerImpl networkController, SubscriptionInfo info,
+ SubscriptionDefaults defaults, Looper receiverLooper) {
super("MobileSignalController(" + info.getSubscriptionId() + ")", context,
NetworkCapabilities.TRANSPORT_CELLULAR, callbackHandler,
networkController);
mNetworkToIconLookup = new SparseArray<>();
mConfig = config;
mPhone = phone;
+ mDefaults = defaults;
mSubscriptionInfo = info;
mPhoneStateListener = new MobilePhoneStateListener(info.getSubscriptionId(),
receiverLooper);
@@ -290,7 +294,7 @@ public class MobileSignalController extends SignalController<
}
private void updateDataSim() {
- int defaultDataSub = SubscriptionManager.getDefaultDataSubId();
+ int defaultDataSub = mDefaults.getDefaultDataSubId();
if (SubscriptionManager.isValidSubscriptionId(defaultDataSub)) {
mCurrentState.dataSim = defaultDataSub == mSubscriptionInfo.getSubscriptionId();
} else {
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 e8957f9..18b5820 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/NetworkControllerImpl.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/NetworkControllerImpl.java
@@ -71,6 +71,7 @@ public class NetworkControllerImpl extends BroadcastReceiver
private final ConnectivityManager mConnectivityManager;
private final SubscriptionManager mSubscriptionManager;
private final boolean mHasMobileDataFeature;
+ private final SubscriptionDefaults mSubDefaults;
private Config mConfig;
// Subcontrollers.
@@ -124,7 +125,8 @@ public class NetworkControllerImpl extends BroadcastReceiver
SubscriptionManager.from(context), Config.readConfig(context), bgLooper,
new CallbackHandler(),
new AccessPointControllerImpl(context, bgLooper),
- new MobileDataControllerImpl(context));
+ new MobileDataControllerImpl(context),
+ new SubscriptionDefaults());
mReceiverHandler.post(mRegisterListeners);
}
@@ -134,13 +136,15 @@ public class NetworkControllerImpl extends BroadcastReceiver
SubscriptionManager subManager, Config config, Looper bgLooper,
CallbackHandler callbackHandler,
AccessPointControllerImpl accessPointController,
- MobileDataControllerImpl mobileDataController) {
+ MobileDataControllerImpl mobileDataController,
+ SubscriptionDefaults defaultsHandler) {
mContext = context;
mConfig = config;
mReceiverHandler = new Handler(bgLooper);
mCallbackHandler = callbackHandler;
mSubscriptionManager = subManager;
+ mSubDefaults = defaultsHandler;
mConnectivityManager = connectivityManager;
mHasMobileDataFeature =
mConnectivityManager.isNetworkSupported(ConnectivityManager.TYPE_MOBILE);
@@ -233,7 +237,7 @@ public class NetworkControllerImpl extends BroadcastReceiver
}
private MobileSignalController getDataController() {
- int dataSubId = SubscriptionManager.getDefaultDataSubId();
+ int dataSubId = mSubDefaults.getDefaultDataSubId();
if (!SubscriptionManager.isValidSubscriptionId(dataSubId)) {
if (DEBUG) Log.e(TAG, "No data sim selected");
return mDefaultSignalController;
@@ -251,17 +255,19 @@ public class NetworkControllerImpl extends BroadcastReceiver
}
public boolean isEmergencyOnly() {
- int voiceSubId = SubscriptionManager.getDefaultVoiceSubId();
+ int voiceSubId = mSubDefaults.getDefaultVoiceSubId();
if (!SubscriptionManager.isValidSubscriptionId(voiceSubId)) {
for (MobileSignalController mobileSignalController :
mMobileSignalControllers.values()) {
- if (!mobileSignalController.isEmergencyOnly()) {
+ if (!mobileSignalController.getState().isEmergency) {
+ if (DEBUG) Log.d(TAG, "Found emergency " + mobileSignalController.mTag);
return false;
}
}
}
if (mMobileSignalControllers.containsKey(voiceSubId)) {
- return mMobileSignalControllers.get(voiceSubId).isEmergencyOnly();
+ if (DEBUG) Log.d(TAG, "Getting emergency from " + voiceSubId);
+ return mMobileSignalControllers.get(voiceSubId).getState().isEmergency;
}
if (DEBUG) Log.e(TAG, "Cannot find controller for voice sub: " + voiceSubId);
// Something is wrong, better assume we can't make calls...
@@ -375,6 +381,11 @@ public class NetworkControllerImpl extends BroadcastReceiver
if (!mListening) {
return;
}
+ doUpdateMobileControllers();
+ }
+
+ @VisibleForTesting
+ void doUpdateMobileControllers() {
List<SubscriptionInfo> subscriptions = mSubscriptionManager.getActiveSubscriptionInfoList();
if (subscriptions == null) {
subscriptions = Collections.emptyList();
@@ -389,6 +400,7 @@ public class NetworkControllerImpl extends BroadcastReceiver
}
setCurrentSubscriptions(subscriptions);
updateNoSims();
+ recalculateEmergency();
}
@VisibleForTesting
@@ -425,7 +437,7 @@ public class NetworkControllerImpl extends BroadcastReceiver
} else {
MobileSignalController controller = new MobileSignalController(mContext, mConfig,
mHasMobileDataFeature, mPhone, mCallbackHandler,
- this, subscriptions.get(i), mReceiverHandler.getLooper());
+ this, subscriptions.get(i), mSubDefaults, mReceiverHandler.getLooper());
mMobileSignalControllers.put(subId, controller);
if (subscriptions.get(i).getSimSlotIndex() == 0) {
mDefaultSignalController = controller;
@@ -708,7 +720,7 @@ public class NetworkControllerImpl extends BroadcastReceiver
null, 0, 0, "");
mMobileSignalControllers.put(id, new MobileSignalController(mContext,
mConfig, mHasMobileDataFeature, mPhone, mCallbackHandler, this, info,
- mReceiverHandler.getLooper()));
+ mSubDefaults, mReceiverHandler.getLooper()));
return info;
}
@@ -735,6 +747,16 @@ public class NetworkControllerImpl extends BroadcastReceiver
void setEmergencyCallsOnly(boolean emergencyOnly);
}
+ public static class SubscriptionDefaults {
+ public int getDefaultVoiceSubId() {
+ return SubscriptionManager.getDefaultVoiceSubId();
+ }
+
+ public int getDefaultDataSubId() {
+ return SubscriptionManager.getDefaultDataSubId();
+ }
+ }
+
@VisibleForTesting
static class Config {
boolean showAtLeast3G = false;
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());
+ }
}