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

Commit 5ce924dc authored by Gegham Zakaryan's avatar Gegham Zakaryan Committed by Bruno Martins
Browse files

GlobalActionsDialog: Remove broken PhoneStateListener for airplane mode toggle



The Airplane Mode toggle in GlobalActions is completely broken,
being stuck in TurningOn transition state when pressing it when
Airplane Mode is off. This happens because the PhoneStateListener
doesn't trigger onServiceStateChanged when Airplane Mode turns on.
This commit removes the redundant PhoneStateListener and makes the
logic work for Telephony and non-Telephony devices pretty much the
same way by allowing onAirplaneModeChanged() to handle both cases.

Change-Id: Ifd1e06ff144addf8dd2c8494769b2d646599ae0a
Signed-off-by: default avatarGegham Zakaryan <zakaryan.2004@outlook.com>
parent d68b0efb
Loading
Loading
Loading
Loading
+0 −20
Original line number Diff line number Diff line
@@ -82,8 +82,6 @@ import android.provider.Settings;
import android.service.dreams.IDreamManager;
import android.sysprop.TelephonyProperties;
import android.telecom.TelecomManager;
import android.telephony.PhoneStateListener;
import android.telephony.ServiceState;
import android.telephony.TelephonyManager;
import android.transition.AutoTransition;
import android.transition.TransitionManager;
@@ -380,7 +378,6 @@ public class GlobalActionsDialog implements DialogInterface.OnDismissListener,
        mHasTelephony = connectivityManager.isNetworkSupported(ConnectivityManager.TYPE_MOBILE);

        // get notified of phone state changes
        telephonyManager.listen(mPhoneStateListener, PhoneStateListener.LISTEN_SERVICE_STATE);
        contentResolver.registerContentObserver(
                Settings.Global.getUriFor(Settings.Global.AIRPLANE_MODE_ON), true,
                mAirplaneModeObserver);
@@ -2344,20 +2341,6 @@ public class GlobalActionsDialog implements DialogInterface.OnDismissListener,
        }
    };

    PhoneStateListener mPhoneStateListener = new PhoneStateListener() {
        @Override
        public void onServiceStateChanged(ServiceState serviceState) {
            if (!mHasTelephony) return;
            final boolean inAirplaneMode = serviceState.getState() == ServiceState.STATE_POWER_OFF;
            mAirplaneState = inAirplaneMode ? ToggleState.On : ToggleState.Off;
            mAirplaneModeOn.updateState(mAirplaneState);
            mAdapter.notifyDataSetChanged();
            mOverflowAdapter.notifyDataSetChanged();
            mPowerAdapter.notifyDataSetChanged();
            mRestartAdapter.notifyDataSetChanged();
        }
    };

    @Override
    public void onTuningChanged(String key, String newValue) {
        if (POWER_MENU_ACTIONS_STRING.equals(key)) {
@@ -2403,9 +2386,6 @@ public class GlobalActionsDialog implements DialogInterface.OnDismissListener,
    };

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

        boolean airplaneModeOn = Settings.Global.getInt(
                mContentResolver,
                Settings.Global.AIRPLANE_MODE_ON,