* commit 'f8dd5f6a19791fdb6fbe1fc40863c1e8dcf785e6': Handle config changes in NetworkController
This commit is contained in:
@ -21,7 +21,6 @@ import static android.net.NetworkCapabilities.TRANSPORT_BLUETOOTH;
|
|||||||
import static android.net.NetworkCapabilities.TRANSPORT_CELLULAR;
|
import static android.net.NetworkCapabilities.TRANSPORT_CELLULAR;
|
||||||
import static android.net.NetworkCapabilities.TRANSPORT_ETHERNET;
|
import static android.net.NetworkCapabilities.TRANSPORT_ETHERNET;
|
||||||
import static android.net.NetworkCapabilities.TRANSPORT_WIFI;
|
import static android.net.NetworkCapabilities.TRANSPORT_WIFI;
|
||||||
|
|
||||||
import android.content.BroadcastReceiver;
|
import android.content.BroadcastReceiver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
@ -49,6 +48,7 @@ import android.telephony.TelephonyManager;
|
|||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.text.format.DateFormat;
|
import android.text.format.DateFormat;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
import android.util.SparseArray;
|
||||||
|
|
||||||
import com.android.internal.annotations.VisibleForTesting;
|
import com.android.internal.annotations.VisibleForTesting;
|
||||||
import com.android.internal.telephony.IccCardConstants;
|
import com.android.internal.telephony.IccCardConstants;
|
||||||
@ -92,7 +92,7 @@ public class NetworkControllerImpl extends BroadcastReceiver
|
|||||||
private final ConnectivityManager mConnectivityManager;
|
private final ConnectivityManager mConnectivityManager;
|
||||||
private final SubscriptionManager mSubscriptionManager;
|
private final SubscriptionManager mSubscriptionManager;
|
||||||
private final boolean mHasMobileDataFeature;
|
private final boolean mHasMobileDataFeature;
|
||||||
private final Config mConfig;
|
private Config mConfig;
|
||||||
|
|
||||||
// Subcontrollers.
|
// Subcontrollers.
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
@ -377,8 +377,8 @@ public class NetworkControllerImpl extends BroadcastReceiver
|
|||||||
updateConnectivity();
|
updateConnectivity();
|
||||||
refreshCarrierLabel();
|
refreshCarrierLabel();
|
||||||
} else if (action.equals(Intent.ACTION_CONFIGURATION_CHANGED)) {
|
} else if (action.equals(Intent.ACTION_CONFIGURATION_CHANGED)) {
|
||||||
refreshLocale();
|
mConfig = Config.readConfig(mContext);
|
||||||
refreshCarrierLabel();
|
handleConfigurationChanged();
|
||||||
} else if (action.equals(Intent.ACTION_AIRPLANE_MODE_CHANGED)) {
|
} else if (action.equals(Intent.ACTION_AIRPLANE_MODE_CHANGED)) {
|
||||||
refreshLocale();
|
refreshLocale();
|
||||||
updateAirplaneMode(false);
|
updateAirplaneMode(false);
|
||||||
@ -412,6 +412,15 @@ public class NetworkControllerImpl extends BroadcastReceiver
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@VisibleForTesting
|
||||||
|
void handleConfigurationChanged() {
|
||||||
|
for (MobileSignalController mobileSignalController : mMobileSignalControllers.values()) {
|
||||||
|
mobileSignalController.setConfiguration(mConfig);
|
||||||
|
}
|
||||||
|
refreshLocale();
|
||||||
|
refreshCarrierLabel();
|
||||||
|
}
|
||||||
|
|
||||||
private void updateMobileControllers() {
|
private void updateMobileControllers() {
|
||||||
if (!mListening) {
|
if (!mListening) {
|
||||||
return;
|
return;
|
||||||
@ -983,7 +992,6 @@ public class NetworkControllerImpl extends BroadcastReceiver
|
|||||||
// TODO: Move to its own file.
|
// TODO: Move to its own file.
|
||||||
static class MobileSignalController extends SignalController<MobileSignalController.MobileState,
|
static class MobileSignalController extends SignalController<MobileSignalController.MobileState,
|
||||||
MobileSignalController.MobileIconGroup> {
|
MobileSignalController.MobileIconGroup> {
|
||||||
private final Config mConfig;
|
|
||||||
private final TelephonyManager mPhone;
|
private final TelephonyManager mPhone;
|
||||||
private final String mNetworkNameDefault;
|
private final String mNetworkNameDefault;
|
||||||
private final String mNetworkNameSeparator;
|
private final String mNetworkNameSeparator;
|
||||||
@ -993,7 +1001,7 @@ public class NetworkControllerImpl extends BroadcastReceiver
|
|||||||
private final SubscriptionInfo mSubscriptionInfo;
|
private final SubscriptionInfo mSubscriptionInfo;
|
||||||
|
|
||||||
// @VisibleForDemoMode
|
// @VisibleForDemoMode
|
||||||
Map<Integer, MobileIconGroup> mNetworkToIconLookup;
|
final SparseArray<MobileIconGroup> mNetworkToIconLookup;
|
||||||
|
|
||||||
// Since some pieces of the phone state are interdependent we store it locally,
|
// Since some pieces of the phone state are interdependent we store it locally,
|
||||||
// this could potentially become part of MobileState for simplification/complication
|
// this could potentially become part of MobileState for simplification/complication
|
||||||
@ -1004,6 +1012,7 @@ public class NetworkControllerImpl extends BroadcastReceiver
|
|||||||
private ServiceState mServiceState;
|
private ServiceState mServiceState;
|
||||||
private SignalStrength mSignalStrength;
|
private SignalStrength mSignalStrength;
|
||||||
private MobileIconGroup mDefaultIcons;
|
private MobileIconGroup mDefaultIcons;
|
||||||
|
private Config mConfig;
|
||||||
|
|
||||||
// TODO: Reduce number of vars passed in, if we have the NetworkController, probably don't
|
// TODO: Reduce number of vars passed in, if we have the NetworkController, probably don't
|
||||||
// need listener lists anymore.
|
// need listener lists anymore.
|
||||||
@ -1014,6 +1023,7 @@ public class NetworkControllerImpl extends BroadcastReceiver
|
|||||||
super("MobileSignalController(" + info.getSubscriptionId() + ")", context,
|
super("MobileSignalController(" + info.getSubscriptionId() + ")", context,
|
||||||
NetworkCapabilities.TRANSPORT_CELLULAR, signalCallbacks, signalClusters,
|
NetworkCapabilities.TRANSPORT_CELLULAR, signalCallbacks, signalClusters,
|
||||||
networkController);
|
networkController);
|
||||||
|
mNetworkToIconLookup = new SparseArray<>();
|
||||||
mConfig = config;
|
mConfig = config;
|
||||||
mPhone = phone;
|
mPhone = phone;
|
||||||
mSubscriptionInfo = info;
|
mSubscriptionInfo = info;
|
||||||
@ -1031,6 +1041,12 @@ public class NetworkControllerImpl extends BroadcastReceiver
|
|||||||
updateDataSim();
|
updateDataSim();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setConfiguration(Config config) {
|
||||||
|
mConfig = config;
|
||||||
|
mapIconSets();
|
||||||
|
updateTelephony();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get (the mobile parts of) the carrier string.
|
* Get (the mobile parts of) the carrier string.
|
||||||
*
|
*
|
||||||
@ -1115,12 +1131,9 @@ public class NetworkControllerImpl extends BroadcastReceiver
|
|||||||
/**
|
/**
|
||||||
* Produce a mapping of data network types to icon groups for simple and quick use in
|
* Produce a mapping of data network types to icon groups for simple and quick use in
|
||||||
* updateTelephony.
|
* updateTelephony.
|
||||||
*
|
|
||||||
* TODO: See if config can change with locale, this may need to be regenerated on Locale
|
|
||||||
* change.
|
|
||||||
*/
|
*/
|
||||||
private void mapIconSets() {
|
private void mapIconSets() {
|
||||||
mNetworkToIconLookup = new HashMap<Integer, MobileIconGroup>();
|
mNetworkToIconLookup.clear();
|
||||||
|
|
||||||
mNetworkToIconLookup.put(TelephonyManager.NETWORK_TYPE_EVDO_0, TelephonyIcons.THREE_G);
|
mNetworkToIconLookup.put(TelephonyManager.NETWORK_TYPE_EVDO_0, TelephonyIcons.THREE_G);
|
||||||
mNetworkToIconLookup.put(TelephonyManager.NETWORK_TYPE_EVDO_A, TelephonyIcons.THREE_G);
|
mNetworkToIconLookup.put(TelephonyManager.NETWORK_TYPE_EVDO_A, TelephonyIcons.THREE_G);
|
||||||
@ -1324,7 +1337,7 @@ public class NetworkControllerImpl extends BroadcastReceiver
|
|||||||
mCurrentState.level = mSignalStrength.getLevel();
|
mCurrentState.level = mSignalStrength.getLevel();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (mNetworkToIconLookup.containsKey(mDataNetType)) {
|
if (mNetworkToIconLookup.indexOfKey(mDataNetType) >= 0) {
|
||||||
mCurrentState.iconGroup = mNetworkToIconLookup.get(mDataNetType);
|
mCurrentState.iconGroup = mNetworkToIconLookup.get(mDataNetType);
|
||||||
} else {
|
} else {
|
||||||
mCurrentState.iconGroup = mDefaultIcons;
|
mCurrentState.iconGroup = mDefaultIcons;
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
package com.android.systemui.statusbar.policy;
|
package com.android.systemui.statusbar.policy;
|
||||||
|
|
||||||
|
import org.mockito.Mockito;
|
||||||
|
|
||||||
import android.telephony.TelephonyManager;
|
import android.telephony.TelephonyManager;
|
||||||
|
|
||||||
// WARNING: Many of these tests may fail with config showMin3G.
|
|
||||||
// TODO: Maybe fix the above.
|
|
||||||
public class NetworkControllerDataTest extends NetworkControllerBaseTest {
|
public class NetworkControllerDataTest extends NetworkControllerBaseTest {
|
||||||
|
|
||||||
public void test3gDataIcon() {
|
public void test3gDataIcon() {
|
||||||
@ -57,7 +57,6 @@ public class NetworkControllerDataTest extends NetworkControllerBaseTest {
|
|||||||
updateDataConnectionState(TelephonyManager.DATA_CONNECTED,
|
updateDataConnectionState(TelephonyManager.DATA_CONNECTED,
|
||||||
TelephonyManager.NETWORK_TYPE_LTE);
|
TelephonyManager.NETWORK_TYPE_LTE);
|
||||||
|
|
||||||
// WARNING: May fail depending on config.
|
|
||||||
verifyDataIndicators(TelephonyIcons.DATA_LTE[1][0 /* No direction */],
|
verifyDataIndicators(TelephonyIcons.DATA_LTE[1][0 /* No direction */],
|
||||||
TelephonyIcons.QS_DATA_LTE[1]);
|
TelephonyIcons.QS_DATA_LTE[1]);
|
||||||
}
|
}
|
||||||
@ -67,11 +66,42 @@ public class NetworkControllerDataTest extends NetworkControllerBaseTest {
|
|||||||
updateDataConnectionState(TelephonyManager.DATA_CONNECTED,
|
updateDataConnectionState(TelephonyManager.DATA_CONNECTED,
|
||||||
TelephonyManager.NETWORK_TYPE_HSPA);
|
TelephonyManager.NETWORK_TYPE_HSPA);
|
||||||
|
|
||||||
// WARNING: May fail depending on config.
|
|
||||||
verifyDataIndicators(TelephonyIcons.DATA_H[1][0 /* No direction */],
|
verifyDataIndicators(TelephonyIcons.DATA_H[1][0 /* No direction */],
|
||||||
TelephonyIcons.QS_DATA_H[1]);
|
TelephonyIcons.QS_DATA_H[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void test4gDataIcon() {
|
||||||
|
// Switch to showing 4g icon and re-initialize the NetworkController.
|
||||||
|
mConfig.show4gForLte = true;
|
||||||
|
mNetworkController = new NetworkControllerImpl(mContext, mMockCm, mMockTm, mMockWm, mMockSm,
|
||||||
|
mConfig, Mockito.mock(AccessPointControllerImpl.class),
|
||||||
|
Mockito.mock(MobileDataControllerImpl.class));
|
||||||
|
setupNetworkController();
|
||||||
|
|
||||||
|
setupDefaultSignal();
|
||||||
|
updateDataConnectionState(TelephonyManager.DATA_CONNECTED,
|
||||||
|
TelephonyManager.NETWORK_TYPE_LTE);
|
||||||
|
|
||||||
|
verifyDataIndicators(TelephonyIcons.DATA_4G[1][0 /* No direction */],
|
||||||
|
TelephonyIcons.QS_DATA_4G[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void test4gDataIconConfigChange() {
|
||||||
|
setupDefaultSignal();
|
||||||
|
updateDataConnectionState(TelephonyManager.DATA_CONNECTED,
|
||||||
|
TelephonyManager.NETWORK_TYPE_LTE);
|
||||||
|
|
||||||
|
// Switch to showing 4g icon and re-initialize the NetworkController.
|
||||||
|
mConfig.show4gForLte = true;
|
||||||
|
// Can't send the broadcast as that would actually read the config from
|
||||||
|
// the context. Instead we'll just poke at a function that does all of
|
||||||
|
// the after work.
|
||||||
|
mNetworkController.handleConfigurationChanged();
|
||||||
|
|
||||||
|
verifyDataIndicators(TelephonyIcons.DATA_4G[1][0 /* No direction */],
|
||||||
|
TelephonyIcons.QS_DATA_4G[1]);
|
||||||
|
}
|
||||||
|
|
||||||
public void testDataActivity() {
|
public void testDataActivity() {
|
||||||
setupDefaultSignal();
|
setupDefaultSignal();
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user