Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e87e9302 authored by Gabriel Biren's avatar Gabriel Biren
Browse files

Add a lock around the wificond death handler and

teardownInterfaces in WifiNl80211Manager.

Prevents a specific race condition when the wificond
service dies at the same time as the Vendor HAL (whose
death handler calls into teardownInterfaces).

No other race conditions have been observed in this file,
so we can limit the locks to these 2 methods.

Bug: 273175980
Test: atest WifiNl80211ManagerTest
Change-Id: Ib3936ed8ddb3c0dc5fb25a56e535ab27a28cfa65
parent 994a65df
Loading
Loading
Loading
Loading
+29 −24
Original line number Diff line number Diff line
@@ -113,6 +113,7 @@ public class WifiNl80211Manager {
    private HashMap<String, IPnoScanEvent> mPnoScanEventHandlers = new HashMap<>();
    private HashMap<String, IApInterfaceEventCallback> mApInterfaceListeners = new HashMap<>();
    private Runnable mDeathEventHandler;
    private Object mLock = new Object();
    /**
     * Ensures that no more than one sendMgmtFrame operation runs concurrently.
     */
@@ -625,6 +626,7 @@ public class WifiNl80211Manager {
    @VisibleForTesting
    public void binderDied() {
        mEventHandler.post(() -> {
            synchronized (mLock) {
                Log.e(TAG, "Wificond died!");
                clearState();
                // Invalidate the global wificond handle on death. Will be refreshed
@@ -633,6 +635,7 @@ public class WifiNl80211Manager {
                if (mDeathEventHandler != null) {
                    mDeathEventHandler.run();
                }
            }
        });
    }

@@ -867,8 +870,9 @@ public class WifiNl80211Manager {
    * @return Returns true on success.
    */
    public boolean tearDownInterfaces() {
        synchronized (mLock) {
            Log.d(TAG, "tearing down interfaces in wificond");
        // Explicitly refresh the wificodn handler because |tearDownInterfaces()|
            // Explicitly refresh the wificond handler because |tearDownInterfaces()|
            // could be used to cleanup before we setup any interfaces.
            if (!retrieveWificondAndRegisterForDeath()) {
                return false;
@@ -888,6 +892,7 @@ public class WifiNl80211Manager {

            return false;
        }
    }

    /** Helper function to look up the interface handle using name */
    private IClientInterface getClientInterface(@NonNull String ifaceName) {