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

Commit f48fb85a authored by Vishal Mahaveer's avatar Vishal Mahaveer Committed by Irfan Sheriff
Browse files

Fix delayed wifi shutdown



Use a wake up alarm to ensure delayed shut down message is sent

Bug: 5926285
Change-Id: I26a3353ddabb17d55299d8b5f9faf4c7ef5b2448
Signed-off-by: default avatarVishal Mahaveer <vishalm@ti.com>
parent ae147152
Loading
Loading
Loading
Loading
+26 −2
Original line number Diff line number Diff line
@@ -208,6 +208,8 @@ public class WifiStateMachine extends StateMachine {

    private AlarmManager mAlarmManager;
    private PendingIntent mScanIntent;
    private PendingIntent mDriverStopIntent;

    /* Tracks current frequency mode */
    private AtomicInteger mFrequencyBand = new AtomicInteger(WifiManager.WIFI_FREQUENCY_BAND_AUTO);

@@ -520,6 +522,11 @@ public class WifiStateMachine extends StateMachine {
    private static final String ACTION_START_SCAN =
        "com.android.server.WifiManager.action.START_SCAN";

    private static final String DELAYED_STOP_COUNTER = "DelayedStopCounter";
    private static final int DRIVER_STOP_REQUEST = 0;
    private static final String ACTION_DELAYED_DRIVER_STOP =
        "com.android.server.WifiManager.action.DELAYED_DRIVER_STOP";

    /**
     * Keep track of whether WIFI is running.
     */
@@ -637,6 +644,15 @@ public class WifiStateMachine extends StateMachine {
                }
            }
        };
        mContext.registerReceiver(
                new BroadcastReceiver() {
                    @Override
                    public void onReceive(Context context, Intent intent) {
                       int counter = intent.getIntExtra(DELAYED_STOP_COUNTER, 0);
                       sendMessage(obtainMessage(CMD_DELAYED_STOP_DRIVER, counter, 0));
                    }
                },
                new IntentFilter(ACTION_DELAYED_DRIVER_STOP));

        mScanResultCache = new LruCache<String, ScanResult>(SCAN_RESULT_CACHE_SIZE);

@@ -2666,18 +2682,26 @@ public class WifiStateMachine extends StateMachine {
                        sendMessage(obtainMessage(CMD_DELAYED_STOP_DRIVER, mDelayedStopCounter, 0));
                    } else {
                        /* send regular delayed shut down */
                        sendMessageDelayed(obtainMessage(CMD_DELAYED_STOP_DRIVER,
                                mDelayedStopCounter, 0), mDriverStopDelayMs);
                        Intent driverStopIntent = new Intent(ACTION_DELAYED_DRIVER_STOP, null);
                        driverStopIntent.putExtra(DELAYED_STOP_COUNTER, mDelayedStopCounter);
                        mDriverStopIntent = PendingIntent.getBroadcast(mContext,
                                DRIVER_STOP_REQUEST, driverStopIntent,
                                PendingIntent.FLAG_UPDATE_CURRENT);

                        mAlarmManager.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis()
                                + mDriverStopDelayMs, mDriverStopIntent);
                    }
                    break;
                case CMD_START_DRIVER:
                    if (mInDelayedStop) {
                        mInDelayedStop = false;
                        mDelayedStopCounter++;
                        mAlarmManager.cancel(mDriverStopIntent);
                        if (DBG) log("Delayed stop ignored due to start");
                    }
                    break;
                case CMD_DELAYED_STOP_DRIVER:
                    if (DBG) log("delayed stop " + message.arg1 + " " + mDelayedStopCounter);
                    if (message.arg1 != mDelayedStopCounter) break;
                    if (getCurrentState() != mDisconnectedState) {
                        mWifiNative.disconnect();