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
This commit is contained in:
Yury Kotlyarov
2019-08-06 15:10:59 -05:00
parent f0723588de
commit ee7b0a6ab2

View File

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