From f851d0347ec4a655ec0857f142743d2360efd958 Mon Sep 17 00:00:00 2001 From: Lorenzo Colitti Date: Fri, 23 Jun 2017 01:21:25 +0900 Subject: [PATCH] Don't crash if the interface disappears just after appearing. If the interface disappears between interfaceAdded() and setInterfaceUp, we'll crash with an IllegalStateException in NetworkManagementService#setInterfaceConfig. Ignore the error instead. This should be safe because we don't modify any state unless our calls succeed. (cherry picked from commit 17f4e4a0276a246926f5b151099dbdb92e5d80d7) Bug: 62870779 Test: builds aosp_bullhead-eng Test: builds marlin-eng Test: exception is logged and device doesn't crash when unplugging USB ethernet adapter while it's being initialized Change-Id: If8c2375f7fffe25a9fa79dc4f1981c745384a276 --- .../com/android/server/ethernet/EthernetNetworkFactory.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/service-t/src/com/android/server/ethernet/EthernetNetworkFactory.java b/service-t/src/com/android/server/ethernet/EthernetNetworkFactory.java index 7ff3f6c310..d6d0defd32 100644 --- a/service-t/src/com/android/server/ethernet/EthernetNetworkFactory.java +++ b/service-t/src/com/android/server/ethernet/EthernetNetworkFactory.java @@ -208,7 +208,7 @@ class EthernetNetworkFactory { InterfaceConfiguration config = mNMService.getInterfaceConfig(iface); if (config == null) { - Log.e(TAG, "Null iterface config for " + iface + ". Bailing out."); + Log.e(TAG, "Null interface config for " + iface + ". Bailing out."); return; } @@ -220,7 +220,9 @@ class EthernetNetworkFactory { Log.e(TAG, "Interface unexpectedly changed from " + iface + " to " + mIface); mNMService.setInterfaceDown(iface); } - } catch (RemoteException e) { + } catch (RemoteException | IllegalStateException e) { + // Either the system is crashing or the interface has disappeared. Just ignore the + // error; we haven't modified any state because we only do that if our calls succeed. Log.e(TAG, "Error upping interface " + mIface + ": " + e); } }