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

Commit f730abf9 authored by Bruno Martins's avatar Bruno Martins Committed by Luca Stefani
Browse files

AODTile: Rewrite AOD setting handling

This fixes the tile status on clean installs, which was showing as
active despite AOD being disabled.

Change-Id: I148cfb34938165395bc52c830d1f2e374b5427df
parent 230e19d9
Loading
Loading
Loading
Loading
+22 −11
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import android.service.quicksettings.Tile;
import com.android.systemui.R;
import com.android.systemui.plugins.qs.QSTile.BooleanState;
import com.android.systemui.qs.QSHost;
import com.android.systemui.qs.SecureSetting;
import com.android.systemui.qs.tileimpl.QSTileImpl;
import com.android.systemui.statusbar.policy.BatteryController;

@@ -33,15 +34,22 @@ import javax.inject.Inject;

public class AODTile extends QSTileImpl<BooleanState> implements
        BatteryController.BatteryStateChangeCallback {
    private boolean mAodDisabled;

    private final Icon mIcon = ResourceIcon.get(R.drawable.ic_qs_aod);
    private final BatteryController mBatteryController;

    private final SecureSetting mSetting;

    @Inject
    public AODTile(QSHost host, BatteryController batteryController) {
        super(host);
        mAodDisabled = Settings.Secure.getInt(mContext.getContentResolver(),
                Settings.Secure.DOZE_ALWAYS_ON, 1) == 0;

        mSetting = new SecureSetting(mContext, mHandler, Settings.Secure.DOZE_ALWAYS_ON) {
            @Override
            protected void handleValueChanged(int value, boolean observedChange) {
                handleRefreshState(value);
            }
        };

        mBatteryController = batteryController;
        batteryController.observe(getLifecycle(), this);
@@ -67,10 +75,7 @@ public class AODTile extends QSTileImpl<BooleanState> implements

    @Override
    public void handleClick() {
        mAodDisabled = !mAodDisabled;
        Settings.Secure.putInt(mContext.getContentResolver(),
                Settings.Secure.DOZE_ALWAYS_ON,
                mAodDisabled ? 0 : 1);
        setEnabled(!mState.value);
        refreshState();
    }

@@ -79,6 +84,12 @@ public class AODTile extends QSTileImpl<BooleanState> implements
        return null;
    }

    private void setEnabled(boolean enabled) {
        Settings.Secure.putInt(mContext.getContentResolver(),
                Settings.Secure.DOZE_ALWAYS_ON,
                enabled ? 1 : 0);
    }

    @Override
    public CharSequence getTileLabel() {
        if (mBatteryController.isAodPowerSave()) {
@@ -89,19 +100,19 @@ public class AODTile extends QSTileImpl<BooleanState> implements

    @Override
    protected void handleUpdateState(BooleanState state, Object arg) {
        final int value = arg instanceof Integer ? (Integer) arg : mSetting.getValue();
        final boolean enable = value != 0;
        if (state.slash == null) {
            state.slash = new SlashState();
        }
        state.icon = mIcon;
        state.value = mAodDisabled;
        state.value = enable;
        state.slash.isSlashed = state.value;
        state.label = mContext.getString(R.string.quick_settings_aod_label);
        if (mBatteryController.isAodPowerSave()) {
            state.state = Tile.STATE_UNAVAILABLE;
        } else if (mAodDisabled) {
            state.state = Tile.STATE_INACTIVE;
        } else {
            state.state = Tile.STATE_ACTIVE;
            state.state = enable ? Tile.STATE_ACTIVE : Tile.STATE_INACTIVE;
        }
    }