@@ -121,8 +121,12 @@ public class NetworkController extends BroadcastReceiver {
121121 private int mWimaxSignal = 0 ;
122122 private int mWimaxState = 0 ;
123123 private int mWimaxExtraState = 0 ;
124+
124125 // data connectivity (regardless of state, can we access the internet?)
125126 // state of inet connection - 0 not connected, 100 connected
127+ private boolean mConnected = false ;
128+ private int mConnectedNetworkType = ConnectivityManager .TYPE_NONE ;
129+ private String mConnectedNetworkTypeName ;
126130 private int mInetCondition = 0 ;
127131 private static final int INET_CONDITION_THRESHOLD = 50 ;
128132
@@ -868,6 +872,16 @@ private void updateConnectivity(Intent intent) {
868872 .getSystemService (Context .CONNECTIVITY_SERVICE );
869873 final NetworkInfo info = connManager .getActiveNetworkInfo ();
870874
875+ // Are we connected at all, by any interface?
876+ mConnected = info != null && info .isConnected ();
877+ if (mConnected ) {
878+ mConnectedNetworkType = info .getType ();
879+ mConnectedNetworkTypeName = info .getTypeName ();
880+ } else {
881+ mConnectedNetworkType = ConnectivityManager .TYPE_NONE ;
882+ mConnectedNetworkTypeName = null ;
883+ }
884+
871885 int connectionStatus = intent .getIntExtra (ConnectivityManager .EXTRA_INET_CONDITION , 0 );
872886
873887 if (CHATTY ) {
@@ -912,12 +926,13 @@ void refreshViews() {
912926 // - We are connected to mobile data, or
913927 // - We are not connected to mobile data, as long as the *reason* packets are not
914928 // being routed over that link is that we have better connectivity via wifi.
915- // If data is disconnected for some other reason but wifi is connected, we show nothing.
929+ // If data is disconnected for some other reason but wifi (or ethernet/bluetooth)
930+ // is connected, we show nothing.
916931 // Otherwise (nothing connected) we show "No internet connection".
917932
918933 if (mDataConnected ) {
919934 mobileLabel = mNetworkName ;
920- } else if (mWifiConnected ) {
935+ } else if (mConnected ) {
921936 if (hasService ()) {
922937 mobileLabel = mNetworkName ;
923938 } else {
@@ -997,6 +1012,12 @@ void refreshViews() {
9971012 R .string .accessibility_bluetooth_tether );
9981013 }
9991014
1015+ final boolean ethernetConnected = (mConnectedNetworkType == ConnectivityManager .TYPE_ETHERNET );
1016+ if (ethernetConnected ) {
1017+ // TODO: icons and strings for Ethernet connectivity
1018+ combinedLabel = mConnectedNetworkTypeName ;
1019+ }
1020+
10001021 if (mAirplaneMode &&
10011022 (mServiceState == null || (!hasService () && !mServiceState .isEmergencyOnly ()))) {
10021023 // Only display the flight-mode icon if not in "emergency calls only" mode.
@@ -1023,7 +1044,7 @@ void refreshViews() {
10231044 combinedSignalIconId = mDataSignalIconId ;
10241045 }
10251046 }
1026- else if (!mDataConnected && !mWifiConnected && !mBluetoothTethered && !mWimaxConnected ) {
1047+ else if (!mDataConnected && !mWifiConnected && !mBluetoothTethered && !mWimaxConnected && ! ethernetConnected ) {
10271048 // pretty much totally disconnected
10281049
10291050 combinedLabel = context .getString (R .string .status_bar_settings_signal_meter_disconnected );
@@ -1224,6 +1245,9 @@ else if (!mDataConnected && !mWifiConnected && !mBluetoothTethered && !mWimaxCon
12241245
12251246 public void dump (FileDescriptor fd , PrintWriter pw , String [] args ) {
12261247 pw .println ("NetworkController state:" );
1248+ pw .println (String .format (" %s network type %d (%s)" ,
1249+ mConnected ?"CONNECTED" :"DISCONNECTED" ,
1250+ mConnectedNetworkType , mConnectedNetworkTypeName ));
12271251 pw .println (" - telephony ------" );
12281252 pw .print (" hasService()=" );
12291253 pw .println (hasService ());
0 commit comments