Change status bar icons upon capability changes in the default network.
SysUI status bar updates currently happen upon receiving either the
CONNECTIVITY_ACTION broadcast (which is deprecated) and
INET_CONDITION_ACTION broadcast (which is sent upon validation state
change of networks only).
This leads to status bar showing stale connectivity state. The correct
fix for this is to listen to changes in network state by registering
NetworkCallbacks (see more details in http://b/79286300#comment9).
In the P timeframe, not listening to the broadcasts completely is out of
scope. So this CL just listens for changing network capabilities of the
default data network, which should fix all the cases where the
broadcasts are not getting sent.
Later, when we stop relying on the broadcasts, we will also have to
override onAvailable and onLost (and perhaps the other callbacks too).
Test: runtest --path frameworks/base/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/
Bug: 71904788
Change-Id: I2e58b9cfceb9937a0b54874dee116ead5339b37b
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 714ad1f..35f0dba 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
@@ -17,20 +17,25 @@
package com.android.systemui.statusbar.policy;
import static junit.framework.Assert.assertEquals;
+import static junit.framework.Assert.assertNotNull;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyBoolean;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.eq;
+import static org.mockito.Matchers.isA;
+import static org.mockito.Mockito.atLeastOnce;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import android.content.Intent;
import android.net.ConnectivityManager;
+import android.net.Network;
import android.net.NetworkCapabilities;
import android.net.wifi.WifiManager;
+import android.os.Handler;
import android.provider.Settings;
import android.provider.Settings.Global;
import android.telephony.PhoneStateListener;
@@ -90,6 +95,7 @@
protected int mSubId;
private NetworkCapabilities mNetCapabilities;
+ private ConnectivityManager.NetworkCallback mNetworkCallback;
@Rule
public TestWatcher failWatcher = new TestWatcher() {
@@ -154,6 +160,13 @@
setSubscriptions(mSubId);
mMobileSignalController = mNetworkController.mMobileSignalControllers.get(mSubId);
mPhoneStateListener = mMobileSignalController.mPhoneStateListener;
+
+ ArgumentCaptor<ConnectivityManager.NetworkCallback> callbackArg =
+ ArgumentCaptor.forClass(ConnectivityManager.NetworkCallback.class);
+ Mockito.verify(mMockCm, atLeastOnce())
+ .registerDefaultNetworkCallback(callbackArg.capture(), isA(Handler.class));
+ mNetworkCallback = callbackArg.getValue();
+ assertNotNull(mNetworkCallback);
}
protected void setDefaultSubId(int subId) {
@@ -195,24 +208,37 @@
setLevel(DEFAULT_LEVEL);
updateDataConnectionState(TelephonyManager.DATA_CONNECTED,
TelephonyManager.NETWORK_TYPE_UMTS);
- setConnectivity(NetworkCapabilities.TRANSPORT_CELLULAR, true, true);
+ setConnectivityViaBroadcast(
+ NetworkCapabilities.TRANSPORT_CELLULAR, true, true);
}
- public void setConnectivity(int networkType, boolean inetCondition, boolean isConnected) {
+ public void setConnectivityViaBroadcast(
+ int networkType, boolean validated, boolean isConnected) {
+ setConnectivityCommon(networkType, validated, isConnected);
Intent i = new Intent(ConnectivityManager.INET_CONDITION_ACTION);
+ mNetworkController.onReceive(mContext, i);
+ }
+
+ public void setConnectivityViaCallback(
+ int networkType, boolean validated, boolean isConnected){
+ setConnectivityCommon(networkType, validated, isConnected);
+ mNetworkCallback.onCapabilitiesChanged(
+ mock(Network.class), new NetworkCapabilities(mNetCapabilities));
+ }
+
+ private void setConnectivityCommon(
+ int networkType, boolean validated, boolean isConnected){
// TODO: Separate out into several NetworkCapabilities.
if (isConnected) {
mNetCapabilities.addTransportType(networkType);
} else {
mNetCapabilities.removeTransportType(networkType);
}
- if (inetCondition) {
+ if (validated) {
mNetCapabilities.addCapability(NetworkCapabilities.NET_CAPABILITY_VALIDATED);
} else {
mNetCapabilities.removeCapability(NetworkCapabilities.NET_CAPABILITY_VALIDATED);
}
-
- mNetworkController.onReceive(mContext, i);
}
public void setGsmRoaming(boolean isRoaming) {