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

Commit 633fe60b authored by Irfan Sheriff's avatar Irfan Sheriff
Browse files

Fix suspend bugs

Listen to screen broadcast all the time to avoid situations of losing
this information when wifi is turned on and off

Avoid duplicate suspend commands to driver

Bug: 7156907
Change-Id: I162b7ba249ae8925119a534229045965c0c13d1f
parent fd2ccaff
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -49,6 +49,7 @@ public class WifiNative {
    static final int BLUETOOTH_COEXISTENCE_MODE_SENSE = 2;

    String mInterface = "";
    private boolean mSuspendOptEnabled = false;

    public native static boolean loadDriver();

@@ -349,6 +350,8 @@ public class WifiNative {
    }

    public boolean setSuspendOptimizations(boolean enabled) {
        if (mSuspendOptEnabled == enabled) return true;
        mSuspendOptEnabled = enabled;
        if (enabled) {
            return doBooleanCommand("DRIVER SETSUSPENDMODE 1");
        } else {
+7 −11
Original line number Diff line number Diff line
@@ -141,8 +141,6 @@ public class WifiStateMachine extends StateMachine {

    private boolean mBluetoothConnectionActive = false;

    private BroadcastReceiver mScreenReceiver;
    private IntentFilter mScreenFilter;
    private PowerManager.WakeLock mSuspendWakeLock;

    /**
@@ -628,15 +626,16 @@ public class WifiStateMachine extends StateMachine {
                },
                new IntentFilter(ACTION_START_SCAN));

        mScreenFilter = new IntentFilter();
        mScreenFilter.addAction(Intent.ACTION_SCREEN_ON);
        mScreenFilter.addAction(Intent.ACTION_SCREEN_OFF);
        mScreenReceiver = new BroadcastReceiver() {
        IntentFilter screenFilter = new IntentFilter();
        screenFilter.addAction(Intent.ACTION_SCREEN_ON);
        screenFilter.addAction(Intent.ACTION_SCREEN_OFF);
        BroadcastReceiver screenReceiver = new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
                String action = intent.getAction();

                if (action.equals(Intent.ACTION_SCREEN_ON)) {
                    if (DBG) log("ACTION_SCREEN_ON");
                    enableRssiPolling(true);
                    if (mBackgroundScanSupported) {
                        enableBackgroundScanCommand(false);
@@ -647,6 +646,7 @@ public class WifiStateMachine extends StateMachine {
                        sendMessage(obtainMessage(CMD_SET_SUSPEND_OPT_ENABLED, 0, 0));
                    }
                } else if (action.equals(Intent.ACTION_SCREEN_OFF)) {
                    if (DBG) log("ACTION_SCREEN_OFF");
                    enableRssiPolling(false);
                    if (mBackgroundScanSupported) {
                        enableBackgroundScanCommand(true);
@@ -660,6 +660,7 @@ public class WifiStateMachine extends StateMachine {
                }
            }
        };
        mContext.registerReceiver(screenReceiver, screenFilter);

        mContext.registerReceiver(
                new BroadcastReceiver() {
@@ -1335,12 +1336,10 @@ public class WifiStateMachine extends StateMachine {
            /* None of dhcp, screen or highperf need it disabled and user wants it enabled */
            if (mSuspendOptNeedsDisabled == 0 && mUserWantsSuspendOpt.get()) {
                mWifiNative.setSuspendOptimizations(true);
                if (DBG) log("Enabled, mSuspendOptNeedsDisabled " + mSuspendOptNeedsDisabled);
            }
        } else {
            mSuspendOptNeedsDisabled |= reason;
            mWifiNative.setSuspendOptimizations(false);
            if (DBG) log("Disabled, mSuspendOptNeedsDisabled " + mSuspendOptNeedsDisabled);
        }
    }

@@ -2723,8 +2722,6 @@ public class WifiStateMachine extends StateMachine {
            }

            if (mP2pSupported) mWifiP2pChannel.sendMessage(WifiStateMachine.CMD_ENABLE_P2P);

            mContext.registerReceiver(mScreenReceiver, mScreenFilter);
        }
        @Override
        public boolean processMessage(Message message) {
@@ -2861,7 +2858,6 @@ public class WifiStateMachine extends StateMachine {
            mScanResults = new ArrayList<ScanResult>();

            if (mP2pSupported) mWifiP2pChannel.sendMessage(WifiStateMachine.CMD_DISABLE_P2P);
            mContext.unregisterReceiver(mScreenReceiver);
        }
    }