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

Commit 08cfb882 authored by Cristoforo Cataldo's avatar Cristoforo Cataldo Committed by Sam Mortimer
Browse files

GlobalActions: Set the initial status of airplane mode toggle

Actually, the initial status of airplane mode toggle is set to false
when the power menu dialog is initialized.
This causes an issue if you set airplane mode and then reboot.
After the reboot, the dialog displays the wrong airplane mode status,
eg. "Airplane mode is not active", and if you toggle that option, a wrong
intent is sent again to put ON the airplane mode, instead of OFF, the
toggle (that is in transition state) will be set disabled.

This commit fixes this issue.

Change-Id: Id30355c1e090355645c437086c79ab59093c27a8
parent b55db4a6
Loading
Loading
Loading
Loading
+10 −5
Original line number Diff line number Diff line
@@ -173,6 +173,9 @@ class GlobalActionsDialog implements DialogInterface.OnDismissListener, DialogIn
                R.bool.config_useFixedVolume);

        mEmergencyAffordanceManager = new EmergencyAffordanceManager(context);

        // Set the initial status of airplane mode toggle
        mAirplaneState = getUpdatedAirplaneToggleState();
    }

    /**
@@ -1177,15 +1180,17 @@ class GlobalActionsDialog implements DialogInterface.OnDismissListener, DialogIn
        }
    };

    private ToggleAction.State getUpdatedAirplaneToggleState() {
        return (Settings.Global.getInt(mContext.getContentResolver(),
                    Settings.Global.AIRPLANE_MODE_ON, 0) == 1) ?
                ToggleAction.State.On : ToggleAction.State.Off;
    }

    private void onAirplaneModeChanged() {
        // Let the service state callbacks handle the state.
        if (mHasTelephony) return;

        boolean airplaneModeOn = Settings.Global.getInt(
                mContext.getContentResolver(),
                Settings.Global.AIRPLANE_MODE_ON,
                0) == 1;
        mAirplaneState = airplaneModeOn ? ToggleAction.State.On : ToggleAction.State.Off;
        mAirplaneState = getUpdatedAirplaneToggleState();
        mAirplaneModeOn.updateState(mAirplaneState);
    }