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

Commit 72534295 authored by Ben Lin's avatar Ben Lin Committed by David Jacobo
Browse files

Do isAvailable() checks when accessing AirplaneEnabler.

This instance is only initialized if isAvailable() returns true in the
first place, so we should check for it everytime we try to access it, or
else we will result in a NPE.

Bug: 271223463
Test: atest AirplaneModePreferenceControllerTest
Change-Id: I43d35b91c86517201c8ec4f458f8c0328a9fb768
parent 4c3ac9b9
Loading
Loading
Loading
Loading
+9 −5
Original line number Diff line number Diff line
@@ -79,7 +79,7 @@ public class AirplaneModePreferenceController extends TogglePreferenceController

    @Override
    public boolean handlePreferenceTreeClick(Preference preference) {
        if (KEY_AIRPLANE_MODE.equals(preference.getKey())
        if (KEY_AIRPLANE_MODE.equals(preference.getKey()) && isAvailable()
                && mAirplaneModeEnabler.isInEcmMode()) {
            // In ECM mode launch ECM app dialog
            if (mFragment != null) {
@@ -141,12 +141,14 @@ public class AirplaneModePreferenceController extends TogglePreferenceController

    @Override
    public void onDestroy() {
        if (isAvailable()) {
            mAirplaneModeEnabler.close();
        }
    }


    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == REQUEST_CODE_EXIT_ECM) {
        if (requestCode == REQUEST_CODE_EXIT_ECM && isAvailable()) {
            final boolean isChoiceYes = (resultCode == Activity.RESULT_OK);
            // Set Airplane mode based on the return value and checkbox state
            mAirplaneModeEnabler.setAirplaneModeInECM(isChoiceYes,
@@ -156,7 +158,7 @@ public class AirplaneModePreferenceController extends TogglePreferenceController

    @Override
    public boolean isChecked() {
        return mAirplaneModeEnabler.isAirplaneModeOn();
        return isAvailable() && mAirplaneModeEnabler.isAirplaneModeOn();
    }

    @Override
@@ -164,7 +166,9 @@ public class AirplaneModePreferenceController extends TogglePreferenceController
        if (isChecked() == isChecked) {
            return false;
        }
        if (isAvailable()) {
            mAirplaneModeEnabler.setAirplaneMode(isChecked);
        }
        return true;
    }