From ee7b0a6ab2cf7a38699fcdcfe4096b1de232f7f0 Mon Sep 17 00:00:00 2001 From: Yury Kotlyarov Date: Tue, 6 Aug 2019 15:10:59 -0500 Subject: [PATCH] Fix LocalOnlyHotspotReservation double stop of local hotspot. If user executed startLocalOnlyHotspot(), then reservation.close() garbage collector still keeps reservation object until drain. If user executed startLocalOnlyHotspot second time during application life cycle, garbage collector can delete previously allocated reservation object. In this case finalize() of old reservation object will be executed, then close(), then stopLocalOnlyHotspot(). As result, new started LocalOnlyHostpot can be immediatly stopped by old reservation object delete. Steps to reproduce: execute startLocalOnlyHostpot() and reservation.close() multiple times during application life cycle, check if hotspot up couple of seconds after start. This fix prevents stopping of local hotspot if reservation was previously closed. Test: manual Bug: 139074896 Change-Id: I86c10b577dbab8cad2d5f7e19805511a93bcb668 --- wifi/java/android/net/wifi/WifiManager.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/wifi/java/android/net/wifi/WifiManager.java b/wifi/java/android/net/wifi/WifiManager.java index 2aed2de064f28..70e5160711b03 100644 --- a/wifi/java/android/net/wifi/WifiManager.java +++ b/wifi/java/android/net/wifi/WifiManager.java @@ -2563,6 +2563,7 @@ public class WifiManager { private final CloseGuard mCloseGuard = CloseGuard.get(); private final WifiConfiguration mConfig; + private boolean mClosed = false; /** @hide */ @VisibleForTesting @@ -2578,8 +2579,13 @@ public class WifiManager { @Override public void close() { try { - stopLocalOnlyHotspot(); - mCloseGuard.close(); + synchronized (mLock) { + if (!mClosed) { + mClosed = true; + stopLocalOnlyHotspot(); + mCloseGuard.close(); + } + } } catch (Exception e) { Log.e(TAG, "Failed to stop Local Only Hotspot."); }