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 ee7b0a6ab2)
This commit is contained in:
Yury Kotlyarov
2019-08-06 15:10:59 -05:00
committed by Pavel Maltsev
parent c60e032391
commit 166f256958

View File

@@ -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.");
}