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

Commit 7aac5547 authored by Irfan Sheriff's avatar Irfan Sheriff
Browse files

Synchronize all WifiNative calls

Some of the native calls were left unsynchronized in the framework. Pre-empted IOCTL call
interrupted by another call from the framework cannot be handled in the driver.

Bug: 2310455
parent 660cc346
Loading
Loading
Loading
Loading
+123 −118
Original line number Diff line number Diff line
@@ -333,6 +333,7 @@ public class WifiService extends IWifiManager.Stub {
        setWifiEnabledState(enable ? WIFI_STATE_ENABLING : WIFI_STATE_DISABLING, uid);

        if (enable) {
            synchronized (mWifiStateTracker) {
                if (!WifiNative.loadDriver()) {
                    Log.e(TAG, "Failed to load Wi-Fi driver.");
                    setWifiEnabledState(WIFI_STATE_UNKNOWN, uid);
@@ -344,6 +345,7 @@ public class WifiService extends IWifiManager.Stub {
                    setWifiEnabledState(WIFI_STATE_UNKNOWN, uid);
                    return false;
                }
            }
            registerForBroadcasts();
            mWifiStateTracker.startEventLoop();
        } else {
@@ -353,6 +355,7 @@ public class WifiService extends IWifiManager.Stub {
            mWifiStateTracker.setNotificationVisible(false, 0, false, 0);

            boolean failedToStopSupplicantOrUnloadDriver = false;
            synchronized (mWifiStateTracker) {
                if (!WifiNative.stopSupplicant()) {
                    Log.e(TAG, "Failed to stop supplicant daemon.");
                    setWifiEnabledState(WIFI_STATE_UNKNOWN, uid);
@@ -369,6 +372,7 @@ public class WifiService extends IWifiManager.Stub {
                        failedToStopSupplicantOrUnloadDriver = true;
                    }
                }
            }
            if (failedToStopSupplicantOrUnloadDriver) {
                return false;
            }
@@ -380,7 +384,6 @@ public class WifiService extends IWifiManager.Stub {
            persistWifiEnabled(enable);
        }
        setWifiEnabledState(eventualWifiState, uid);

        return true;
    }

@@ -698,7 +701,7 @@ public class WifiService extends IWifiManager.Stub {
     * @return the supplicant-assigned identifier for the new or updated
     * network if the operation succeeds, or {@code -1} if it fails
     */
    public synchronized int addOrUpdateNetwork(WifiConfiguration config) {
    public int addOrUpdateNetwork(WifiConfiguration config) {
        enforceChangePermission();
        /*
         * If the supplied networkId is -1, we create a new empty
@@ -710,6 +713,7 @@ public class WifiService extends IWifiManager.Stub {
        boolean doReconfig;
        int currentPriority;
        // networkId of -1 means we want to create a new network
        synchronized (mWifiStateTracker) {
            if (newNetwork) {
                netId = WifiNative.addNetworkCommand();
                if (netId < 0) {
@@ -739,7 +743,6 @@ public class WifiService extends IWifiManager.Stub {
             * will fail, so we don't bother to make a separate check
             * for the validity of the ID up front.
             */

            if (config.SSID != null &&
                    !WifiNative.setNetworkVariableCommand(
                        netId,
@@ -940,6 +943,7 @@ public class WifiService extends IWifiManager.Stub {
                            + netId);
                }
            }
        }
        return -1;
    }

@@ -1849,16 +1853,17 @@ public class WifiService extends IWifiManager.Stub {

    public void initializeMulticastFiltering() {
        enforceMulticastChangePermission();

        synchronized (mMulticasters) {
            // if anybody had requested filters be off, leave off
            if (mMulticasters.size() != 0) {
                return;
            } else {
                synchronized (mWifiStateTracker) {
                    WifiNative.startPacketFiltering();
                }
            }
        }
    }

    public void acquireMulticastLock(IBinder binder, String tag) {
        enforceMulticastChangePermission();
+4 −3
Original line number Diff line number Diff line
@@ -616,7 +616,7 @@ public class WifiStateTracker extends NetworkStateTracker {
     * @return {@code true} if the operation succeeds, {@code false} otherwise, e.g.,
     * the number of channels is invalid.
     */
    public boolean setNumAllowedChannels() {
    public synchronized boolean setNumAllowedChannels() {
        try {
            return setNumAllowedChannels(
                    Settings.Secure.getInt(mContext.getContentResolver(),
@@ -859,8 +859,10 @@ public class WifiStateTracker extends NetworkStateTracker {
                // Only do this if we haven't gotten a new supplicant status since the timer
                // started
                if (mNumSupplicantStateChanges == msg.arg1) {
                    synchronized (this) {
                        WifiNative.scanCommand(false); // do a passive scan
                    }
                }
                break;

            case EVENT_SUPPLICANT_STATE_CHANGED:
@@ -1154,7 +1156,6 @@ public class WifiStateTracker extends NetworkStateTracker {
                    // [31- 1] Reserved for future use
                    // [ 0- 0] Interface configuration succeeded (1) or failed (0)
                    EventLog.writeEvent(EVENTLOG_INTERFACE_CONFIGURATION_STATE_CHANGED, 0);
                
                    mHaveIpAddress = false;
                    mWifiInfo.setIpAddress(0);
                    mObtainingIpAddress = false;