EthernetDataTracker: Update hardware address when interface is changed
Change-Id: I154f151ca676e1e4137eb8210fd377659cfc7867
diff --git a/core/java/android/net/EthernetDataTracker.java b/core/java/android/net/EthernetDataTracker.java
index ec44661..6c61046 100644
--- a/core/java/android/net/EthernetDataTracker.java
+++ b/core/java/android/net/EthernetDataTracker.java
@@ -106,6 +106,24 @@
mLinkCapabilities = new LinkCapabilities();
}
+ private void interfaceUpdated() {
+ // we don't get link status indications unless the iface is up - bring it up
+ try {
+ mNMService.setInterfaceUp(mIface);
+ String hwAddr = null;
+ InterfaceConfiguration config = mNMService.getInterfaceConfig(mIface);
+ if (config != null) {
+ hwAddr = config.getHardwareAddress();
+ }
+ synchronized (this) {
+ mHwAddr = hwAddr;
+ mNetworkInfo.setExtraInfo(mHwAddr);
+ }
+ } catch (RemoteException e) {
+ Log.e(TAG, "Error upping interface " + mIface + ": " + e);
+ }
+ }
+
private void interfaceAdded(String iface) {
if (!iface.matches(sIfaceMatch))
return;
@@ -118,12 +136,7 @@
mIface = iface;
}
- // we don't get link status indications unless the iface is up - bring it up
- try {
- mNMService.setInterfaceUp(iface);
- } catch (Exception e) {
- Log.e(TAG, "Error upping interface " + iface + ": " + e);
- }
+ interfaceUpdated();
mNetworkInfo.setIsAvailable(true);
Message msg = mCsHandler.obtainMessage(EVENT_CONFIGURATION_CHANGED, mNetworkInfo);
@@ -159,7 +172,11 @@
Log.d(TAG, "Removing " + iface);
disconnect();
- mIface = "";
+ synchronized (this) {
+ mIface = "";
+ mHwAddr = null;
+ mNetworkInfo.setExtraInfo(null);
+ }
}
private void runDhcp() {
@@ -220,15 +237,7 @@
for (String iface : ifaces) {
if (iface.matches(sIfaceMatch)) {
mIface = iface;
- mNMService.setInterfaceUp(iface);
- InterfaceConfiguration config = mNMService.getInterfaceConfig(iface);
- mLinkUp = config.hasFlag("up");
- if (config != null && mHwAddr == null) {
- mHwAddr = config.getHardwareAddress();
- if (mHwAddr != null) {
- mNetworkInfo.setExtraInfo(mHwAddr);
- }
- }
+ interfaceUpdated();
// if a DHCP client had previously been started for this interface, then stop it
NetworkUtils.stopDhcp(mIface);