import android.util.SparseArray;
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;
import com.android.systemui.R;
updateTelephony();
}
- /**
- * Get (the mobile parts of) the carrier string.
- *
- * @param currentLabel can be used for concatenation, currently just empty
- * @param connected whether the device has connection to the internet at all
- * @param isMobileLabel whether to always return the network or just when data is connected
- */
- public String getLabel(String currentLabel, boolean connected, boolean isMobileLabel) {
- if (!mCurrentState.enabled) {
- return "";
- } else {
- String mobileLabel = "";
- // We want to show the carrier name if in service and either:
- // - We are connected to mobile data, or
- // - We are not connected to mobile data, as long as the *reason* packets are not
- // being routed over that link is that we have better connectivity via wifi.
- // If data is disconnected for some other reason but wifi (or ethernet/bluetooth)
- // is connected, we show nothing.
- // Otherwise (nothing connected) we show "No internet connection".
- if (mCurrentState.dataConnected) {
- mobileLabel = mCurrentState.networkName;
- } else if (connected || mCurrentState.isEmergency) {
- if (mCurrentState.connected || mCurrentState.isEmergency) {
- // The isEmergencyOnly test covers the case of a phone with no SIM
- mobileLabel = mCurrentState.networkName;
- }
- } else {
- mobileLabel = mContext.getString(
- R.string.status_bar_settings_signal_meter_disconnected);
- }
-
- if (currentLabel.length() != 0) {
- currentLabel = currentLabel + mNetworkNameSeparator;
- }
- // Now for things that should only be shown when actually using mobile data.
- if (isMobileLabel) {
- return currentLabel + mobileLabel;
- } else {
- return currentLabel
- + (mCurrentState.dataConnected ? mobileLabel : currentLabel);
- }
- }
- }
-
public int getDataContentDescription() {
return getIcons().mDataContentDescription;
}
package com.android.systemui.statusbar.policy;
import static android.net.NetworkCapabilities.NET_CAPABILITY_VALIDATED;
-import static android.net.NetworkCapabilities.TRANSPORT_BLUETOOTH;
-import static android.net.NetworkCapabilities.TRANSPORT_ETHERNET;
import android.content.BroadcastReceiver;
import android.content.Context;
private final AccessPointControllerImpl mAccessPoints;
private final MobileDataControllerImpl mMobileDataController;
- // Network types that replace the carrier label if the device does not support mobile data.
- private boolean mBluetoothTethered = false;
- private boolean mEthernetConnected = false;
-
- // state of inet connection
- private boolean mConnected = false;
private boolean mInetCondition; // Used for Logging and demo.
// BitSets indicating which network transport types (e.g., TRANSPORT_WIFI, TRANSPORT_MOBILE) are
// All the callbacks.
private ArrayList<EmergencyListener> mEmergencyListeners = new ArrayList<EmergencyListener>();
- private ArrayList<CarrierLabelListener> mCarrierListeners =
- new ArrayList<CarrierLabelListener>();
private ArrayList<SignalCluster> mSignalClusters = new ArrayList<SignalCluster>();
private ArrayList<NetworkSignalChangedCallback> mSignalsChangedCallbacks =
new ArrayList<NetworkSignalChangedCallback>();
listener.setEmergencyCallsOnly(isEmergencyOnly());
}
- public void addCarrierLabel(CarrierLabelListener listener) {
- mCarrierListeners.add(listener);
- refreshCarrierLabel();
- }
-
private void notifyMobileDataEnabled(boolean enabled) {
final int length = mSignalsChangedCallbacks.size();
for (int i = 0; i < length; i++) {
for (int i = 0; i < length; i++) {
mEmergencyListeners.get(i).setEmergencyCallsOnly(emergencyOnly);
}
- // If the emergency has a chance to change, then so does the carrier
- // label.
- refreshCarrierLabel();
}
public void addSignalCluster(SignalCluster cluster) {
mCurrentUserId = newUserId;
mAccessPoints.onUserSwitched(newUserId);
updateConnectivity();
- refreshCarrierLabel();
}
@Override
if (action.equals(ConnectivityManager.CONNECTIVITY_ACTION_IMMEDIATE) ||
action.equals(ConnectivityManager.INET_CONDITION_ACTION)) {
updateConnectivity();
- refreshCarrierLabel();
} else if (action.equals(Intent.ACTION_CONFIGURATION_CHANGED)) {
mConfig = Config.readConfig(mContext);
handleConfigurationChanged();
} else if (action.equals(Intent.ACTION_AIRPLANE_MODE_CHANGED)) {
refreshLocale();
updateAirplaneMode(false);
- refreshCarrierLabel();
} else if (action.equals(TelephonyIntents.ACTION_DEFAULT_VOICE_SUBSCRIPTION_CHANGED)) {
// We are using different subs now, we might be able to make calls.
recalculateEmergency();
mobileSignalController.setConfiguration(mConfig);
}
refreshLocale();
- refreshCarrierLabel();
}
private void updateMobileControllers() {
mobileSignalController.setAirplaneMode(mAirplaneMode);
}
notifyListeners();
- refreshCarrierLabel();
}
}
Log.d(TAG, "updateConnectivity: mValidatedTransports=" + mValidatedTransports);
}
- mConnected = !mConnectedTransports.isEmpty();
mInetCondition = !mValidatedTransports.isEmpty();
- mBluetoothTethered = mConnectedTransports.get(TRANSPORT_BLUETOOTH);
- mEthernetConnected = mConnectedTransports.get(TRANSPORT_ETHERNET);
pushConnectivityToSignals();
}
mValidatedTransports.get(mWifiSignalController.getTransportType()) ? 1 : 0);
}
- /**
- * Recalculate and update the carrier label.
- */
- void refreshCarrierLabel() {
- Context context = mContext;
-
- WifiSignalController.WifiState wifiState = mWifiSignalController.getState();
- String label = "";
- for (MobileSignalController controller : mMobileSignalControllers.values()) {
- label = controller.getLabel(label, mConnected, mHasMobileDataFeature);
- }
-
- // TODO Simplify this ugliness, some of the flows below shouldn't be possible anymore
- // but stay for the sake of history.
- if (mBluetoothTethered && !mHasMobileDataFeature) {
- label = mContext.getString(R.string.bluetooth_tethered);
- }
-
- if (mEthernetConnected && !mHasMobileDataFeature) {
- label = context.getString(R.string.ethernet_label);
- }
-
- if (mAirplaneMode && !isEmergencyOnly()) {
- // combined values from connected wifi take precedence over airplane mode
- if (wifiState.connected && mHasMobileDataFeature) {
- // Suppress "No internet connection." from mobile if wifi connected.
- label = "";
- } else {
- if (!mHasMobileDataFeature) {
- label = context.getString(
- R.string.status_bar_settings_signal_meter_disconnected);
- }
- }
- } else if (!isMobileDataConnected() && !wifiState.connected && !mBluetoothTethered &&
- !mEthernetConnected && !mHasMobileDataFeature) {
- // Pretty much no connection.
- label = context.getString(R.string.status_bar_settings_signal_meter_disconnected);
- }
-
- // for mobile devices, we always show mobile connection info here (SPN/PLMN)
- // for other devices, we show whatever network is connected
- // This is determined above by references to mHasMobileDataFeature.
- int length = mCarrierListeners.size();
- for (int i = 0; i < length; i++) {
- mCarrierListeners.get(i).setCarrierLabel(label);
- }
- }
-
- private boolean isMobileDataConnected() {
- MobileSignalController controller = getDataController();
- return controller != null ? controller.getState().dataConnected : false;
- }
-
public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
pw.println("NetworkController state:");
pw.print(" hasVoiceCallingFeature()=");
pw.println(hasVoiceCallingFeature());
- pw.println(" - Bluetooth ----");
- pw.print(" mBtReverseTethered=");
- pw.println(mBluetoothTethered);
-
pw.println(" - connectivity ------");
pw.print(" mConnectedTransports=");
pw.println(mConnectedTransports);
mWifiSignalController.resetLastState();
registerListeners();
notifyAllListeners();
- refreshCarrierLabel();
} else if (mDemoMode && command.equals(COMMAND_NETWORK)) {
String airplane = args.getString("airplane");
if (airplane != null) {
controller.getState().enabled = show;
controller.notifyListeners();
}
- refreshCarrierLabel();
}
}