From 5962e168ec596f0afbe36b60522bb4e8410b6f1a Mon Sep 17 00:00:00 2001 From: Kai Shi Date: Fri, 24 Apr 2020 13:48:40 -0700 Subject: Skip self recovery and bug report capture during SHUTDOWN Skip ActiveModeWarden's self recovery and bug report data capture during ACTION_SHUTDOWN event. Bug: 154263486 Test: atest com.android.server.wifi Change-Id: Idca3e8f100119ab385ee633a4dfa0009b01ed150 --- .../java/com/android/server/wifi/ActiveModeWarden.java | 12 +++++++++++- .../java/com/android/server/wifi/WifiServiceImpl.java | 16 +++++++++++----- 2 files changed, 22 insertions(+), 6 deletions(-) (limited to 'service') diff --git a/service/java/com/android/server/wifi/ActiveModeWarden.java b/service/java/com/android/server/wifi/ActiveModeWarden.java index 457b68773..03334584b 100644 --- a/service/java/com/android/server/wifi/ActiveModeWarden.java +++ b/service/java/com/android/server/wifi/ActiveModeWarden.java @@ -79,6 +79,7 @@ public class ActiveModeWarden { private boolean mCanRequestMoreClientModeManagers = false; private boolean mCanRequestMoreSoftApManagers = false; + private boolean mIsShuttingdown = false; /** * Called from WifiServiceImpl to register a callback for notifications from SoftApManager @@ -122,7 +123,7 @@ public class ActiveModeWarden { mWifiController = new WifiController(); wifiNative.registerStatusListener(isReady -> { - if (!isReady) { + if (!isReady && !mIsShuttingdown) { mHandler.post(() -> { Log.e(TAG, "One of the native daemons died. Triggering recovery"); wifiDiagnostics.captureBugReportData( @@ -148,6 +149,15 @@ public class ActiveModeWarden { })); } + /** + * Notify that device is shutting down + * Keep it simple and don't add collection access codes + * to avoid concurrentModificationException when it is directly called from a different thread + */ + public void notifyShuttingDown() { + mIsShuttingdown = true; + } + /** * @return Returns whether we can create more client mode managers or not. */ diff --git a/service/java/com/android/server/wifi/WifiServiceImpl.java b/service/java/com/android/server/wifi/WifiServiceImpl.java index 436cb94f3..73fb306f9 100644 --- a/service/java/com/android/server/wifi/WifiServiceImpl.java +++ b/service/java/com/android/server/wifi/WifiServiceImpl.java @@ -571,11 +571,17 @@ public class WifiServiceImpl extends BaseWifiService { } private void handleShutDown() { - // There is no explicit disconnection event in clientModeImpl during shutdown. - // Call resetConnectionState() so that connection duration is calculated correctly - // before memory store write triggered by mMemoryStoreImpl.stop(). - mWifiScoreCard.resetConnectionState(); - mMemoryStoreImpl.stop(); + // Direct call to notify ActiveModeWarden as soon as possible with the assumption that + // notifyShuttingDown() doesn't have codes that may cause concurrentModificationException, + // e.g., access to a collection. + mActiveModeWarden.notifyShuttingDown(); + mWifiThreadRunner.post(()-> { + // There is no explicit disconnection event in clientModeImpl during shutdown. + // Call resetConnectionState() so that connection duration is calculated + // before memory store write triggered by mMemoryStoreImpl.stop(). + mWifiScoreCard.resetConnectionState(); + mMemoryStoreImpl.stop(); + }); } private boolean checkNetworkSettingsPermission(int pid, int uid) { -- cgit v1.2.3