From 166f256958a04bc08cd0d849c018aa7675e109eb 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 Bug: 143653311 Change-Id: I86c10b577dbab8cad2d5f7e19805511a93bcb668 Merged-In: I86c10b577dbab8cad2d5f7e19805511a93bcb668 (cherry-picked from ee7b0a6ab2cf7a38699fcdcfe4096b1de232f7f0) --- 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 f540492266c5b..77e02df105c8f 100644 --- a/wifi/java/android/net/wifi/WifiManager.java +++ b/wifi/java/android/net/wifi/WifiManager.java @@ -3214,6 +3214,7 @@ public class WifiManager { private final CloseGuard mCloseGuard = CloseGuard.get(); private final WifiConfiguration mConfig; + private boolean mClosed = false; /** @hide */ @VisibleForTesting @@ -3229,8 +3230,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."); }