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

Commit f5539a19 authored by jeffreyhuang's avatar jeffreyhuang
Browse files

Add isAvailable check to devOptionsController

 - This avoids the null check for PreferenceControllers where isAvailable()
 is not always true

Bug: 34203528
Test: make RunSettingsRoboTests -j40
Change-Id: Ibed8bc6a2a812355c521620d77fb571c1fd8a649
parent ff397103
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -69,12 +69,12 @@ public class BluetoothSnoopLogPreferenceController extends
    }

    @Override
    public void onDeveloperOptionsEnabled() {
    protected void onDeveloperOptionsSwitchEnabled() {
        mPreference.setEnabled(true);
    }

    @Override
    public void onDeveloperOptionsDisabled() {
    protected void onDeveloperOptionsSwitchDisabled() {
        SystemProperties.set(BLUETOOTH_BTSNOOP_ENABLE_PROPERTY, Boolean.toString(false));
        mPreference.setChecked(false);
        mPreference.setEnabled(false);
+21 −2
Original line number Diff line number Diff line
@@ -54,10 +54,29 @@ public abstract class DeveloperOptionsPreferenceController extends
    /**
     * Called when developer options is enabled
     */
    public abstract void onDeveloperOptionsEnabled();
    public void onDeveloperOptionsEnabled() {
        if (isAvailable()) {
            onDeveloperOptionsSwitchEnabled();
        }
    }

    /**
     * Called when developer options is disabled
     */
    public abstract void onDeveloperOptionsDisabled();
    public void onDeveloperOptionsDisabled() {
        if (isAvailable()) {
            onDeveloperOptionsSwitchDisabled();
        }
    }

    /**
     * Called when developer options is enabled and the preference is available
     */
    protected abstract void onDeveloperOptionsSwitchEnabled();

    /**
     * Called when developer options is disabled and the preference is available
     */
    protected abstract void onDeveloperOptionsSwitchDisabled();

}
+2 −6
Original line number Diff line number Diff line
@@ -122,12 +122,12 @@ public class OemUnlockPreferenceController extends DeveloperOptionsPreferenceCon
    }

    @Override
    public void onDeveloperOptionsEnabled() {
    protected void onDeveloperOptionsSwitchEnabled() {
        handleDeveloperOptionsToggled();
    }

    @Override
    public void onDeveloperOptionsDisabled() {
    protected void onDeveloperOptionsSwitchDisabled() {
        handleDeveloperOptionsToggled();
    }

@@ -143,10 +143,6 @@ public class OemUnlockPreferenceController extends DeveloperOptionsPreferenceCon
    }

    private void handleDeveloperOptionsToggled() {
        if (mPreference == null) {
            return;
        }

        mPreference.setEnabled(enableOemUnlockPreference());
        if (mPreference.isEnabled()) {
            // Check restriction, disable mEnableOemUnlock and apply policy transparency.
+13 −13
Original line number Diff line number Diff line
@@ -100,19 +100,6 @@ public class StayAwakePreferenceController extends DeveloperOptionsPreferenceCon
        mPreference.setChecked(stayAwakeMode != SETTING_VALUE_OFF);
    }

    @Override
    public void onDeveloperOptionsEnabled() {
        mPreference.setEnabled(true);
    }

    @Override
    public void onDeveloperOptionsDisabled() {
        Settings.Global.putInt(mContext.getContentResolver(),
                Settings.Global.STAY_ON_WHILE_PLUGGED_IN, SETTING_VALUE_OFF);
        mPreference.setChecked(false);
        mPreference.setEnabled(false);
    }

    @Override
    public void onResume() {
        if (mPreference != null) {
@@ -127,6 +114,19 @@ public class StayAwakePreferenceController extends DeveloperOptionsPreferenceCon
        }
    }

    @Override
    protected void onDeveloperOptionsSwitchEnabled() {
        mPreference.setEnabled(true);
    }

    @Override
    protected void onDeveloperOptionsSwitchDisabled() {
        Settings.Global.putInt(mContext.getContentResolver(),
                Settings.Global.STAY_ON_WHILE_PLUGGED_IN, SETTING_VALUE_OFF);
        mPreference.setChecked(false);
        mPreference.setEnabled(false);
    }

    @VisibleForTesting
    RestrictedLockUtils.EnforcedAdmin checkIfMaximumTimeToLockSetByAdmin() {
        // A DeviceAdmin has specified a maximum time until the device