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

Commit 7e0d6365 authored by Danny Baumann's avatar Danny Baumann
Browse files

Fix lockscreen button behaviour.

Unlike the other buttons, the lockscreen disable button keeps the state
(disabled/enabled) in it instead of just displaying it, so in order to
make it reliable, a few things needed to be fixed:

- The actual lockscreen blocker was a member variable while the state
  information was static. This could lead to the two variables getting
  out of sync.
- On orientation or theme change, all widgets were destroyed and
  recreated. If that happened while the lockscreen was disabled, the
  blocker instance was lost, thus, there was no way to enable the
  lockscreen again. Fix that by only recreating the views, not the whole
  widgets.
- The lockscreen disable state wasn't stored persistently, thus didn't
  survive a reboot.

Fixes http://code.google.com/p/cyanogenmod/issues/detail?id=2978.

Change-Id: I6f619740659cfedec3a3c9517fb55275f601d792
parent 81af0ca9
Loading
Loading
Loading
Loading
+6 −7
Original line number Diff line number Diff line
@@ -21,8 +21,8 @@ public class AirplaneButton extends PowerButton {
    public AirplaneButton() { mType = BUTTON_AIRPLANE; }

    @Override
    protected void updateState() {
        if (getState(mView.getContext())) {
    protected void updateState(Context context) {
        if (getState(context)) {
            mIcon = R.drawable.stat_airplane_on;
            mState = STATE_ENABLED;
        } else {
@@ -32,8 +32,7 @@ public class AirplaneButton extends PowerButton {
    }

    @Override
    protected void toggleState() {
        Context context = mView.getContext();
    protected void toggleState(Context context) {
        boolean state = getState(context);
        Settings.System.putInt(context.getContentResolver(),
            Settings.System.AIRPLANE_MODE_ON, state ? 0 : 1);
@@ -45,11 +44,11 @@ public class AirplaneButton extends PowerButton {
    }

    @Override
    protected boolean handleLongClick() {
    protected boolean handleLongClick(Context context) {
        Intent intent = new Intent("android.settings.AIRPLANE_MODE_SETTINGS");
        intent.addCategory(Intent.CATEGORY_DEFAULT);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        mView.getContext().startActivity(intent);
        context.startActivity(intent);
        return true;
    }

@@ -58,7 +57,7 @@ public class AirplaneButton extends PowerButton {
        return OBSERVED_URIS;
    }

    private static boolean getState(Context context) {
    private boolean getState(Context context) {
        return Settings.System.getInt(context.getContentResolver(),
                 Settings.System.AIRPLANE_MODE_ON,0) == 1;
    }
+7 −8
Original line number Diff line number Diff line
@@ -20,8 +20,8 @@ public class AutoRotateButton extends PowerButton {
    public AutoRotateButton() { mType = BUTTON_AUTOROTATE; }

    @Override
    protected void updateState() {
        if (getOrientationState(mView.getContext()) == 1) {
    protected void updateState(Context context) {
        if (getOrientationState(context) == 1) {
            mIcon = R.drawable.stat_orientation_on;
            mState = STATE_ENABLED;
        } else {
@@ -31,8 +31,7 @@ public class AutoRotateButton extends PowerButton {
    }

    @Override
    protected void toggleState() {
        Context context = mView.getContext();
    protected void toggleState(Context context) {
        if (getOrientationState(context) == 0) {
            Settings.System.putInt(
                    context.getContentResolver(),
@@ -46,11 +45,11 @@ public class AutoRotateButton extends PowerButton {


    @Override
    protected boolean handleLongClick() {
    protected boolean handleLongClick(Context context) {
        Intent intent = new Intent("android.settings.DISPLAY_SETTINGS");
        intent.addCategory(Intent.CATEGORY_DEFAULT);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        mView.getContext().startActivity(intent);
        context.startActivity(intent);
        return true;
    }

@@ -59,7 +58,7 @@ public class AutoRotateButton extends PowerButton {
        return OBSERVED_URIS;
    }

    private static int getOrientationState(Context context) {
    private int getOrientationState(Context context) {
        return Settings.System.getInt(
                context.getContentResolver(),
                Settings.System.ACCELEROMETER_ROTATION, 0);
+6 −6
Original line number Diff line number Diff line
@@ -80,8 +80,8 @@ public class BluetoothButton extends PowerButton {
    public BluetoothButton() { mType = BUTTON_BLUETOOTH; }

    @Override
    protected void updateState() {
        mState = sBluetoothState.getTriState(mView.getContext());
    protected void updateState(Context context) {
        mState = sBluetoothState.getTriState(context);
        switch (mState) {
            case STATE_DISABLED:
                mIcon = R.drawable.stat_bluetooth_off;
@@ -105,16 +105,16 @@ public class BluetoothButton extends PowerButton {
    }

    @Override
    protected void toggleState() {
        sBluetoothState.toggleState(mView.getContext());
    protected void toggleState(Context context) {
        sBluetoothState.toggleState(context);
    }

    @Override
    protected boolean handleLongClick() {
    protected boolean handleLongClick(Context context) {
        Intent intent = new Intent("android.settings.BLUETOOTH_SETTINGS");
        intent.addCategory(Intent.CATEGORY_DEFAULT);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        mView.getContext().startActivity(intent);
        context.startActivity(intent);
        return true;
    }

+29 −39
Original line number Diff line number Diff line
@@ -7,8 +7,8 @@ import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.IPowerManager;
import android.os.Power;
import android.os.PowerManager;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.preference.MultiSelectListPreference;
@@ -79,12 +79,12 @@ public class BrightnessButton extends PowerButton {
            Context context = mView.getContext();
            mAutoBrightnessSupported = context.getResources().getBoolean(
                    com.android.internal.R.bool.config_automatic_brightness_available);
            updateSettings();
            updateSettings(context.getContentResolver());
        }
    }

    @Override
    protected void updateState() {
    protected void updateState(Context context) {
        if (mAutoBrightness) {
            mIcon = R.drawable.stat_brightness_auto;
            mState = STATE_ENABLED;
@@ -101,18 +101,18 @@ public class BrightnessButton extends PowerButton {
    }

    @Override
    protected void toggleState() {
        try {
            IPowerManager power = IPowerManager.Stub
                    .asInterface(ServiceManager.getService("power"));
            if (power != null) {
                ContentResolver resolver = mView.getContext().getContentResolver();
    protected void toggleState(Context context) {
        PowerManager power = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
        ContentResolver resolver = context.getContentResolver();

        mCurrentBacklightIndex++;
        if (mCurrentBacklightIndex > mBacklightValues.length - 1) {
            mCurrentBacklightIndex = 0;
        }

        int backlightIndex = mBacklightValues[mCurrentBacklightIndex];
        int brightness = BACKLIGHTS[backlightIndex];

        if (brightness == AUTO_BACKLIGHT) {
            Settings.System.putInt(resolver, Settings.System.SCREEN_BRIGHTNESS_MODE,
                    Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC);
@@ -125,18 +125,13 @@ public class BrightnessButton extends PowerButton {
            Settings.System.putInt(resolver, Settings.System.SCREEN_BRIGHTNESS, brightness);
        }
    }
        } catch (RemoteException e) {
            Log.e(TAG, "toggleState()", e);
        }

    }

    @Override
    protected boolean handleLongClick() {
    protected boolean handleLongClick(Context context) {
        Intent intent = new Intent("android.settings.DISPLAY_SETTINGS");
        intent.addCategory(Intent.CATEGORY_DEFAULT);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        mView.getContext().startActivity(intent);
        context.startActivity(intent);
        return true;
    }

@@ -146,8 +141,7 @@ public class BrightnessButton extends PowerButton {
    }

    @Override
    protected void onChangeUri(Uri uri) {
        ContentResolver resolver = mView.getContext().getContentResolver();
    protected void onChangeUri(ContentResolver resolver, Uri uri) {
        if (BRIGHTNESS_URI.equals(uri)) {
            mCurrentBrightness = Settings.System.getInt(resolver,
                    Settings.System.SCREEN_BRIGHTNESS, 0);
@@ -155,13 +149,11 @@ public class BrightnessButton extends PowerButton {
            mAutoBrightness = (Settings.System.getInt(resolver,
                    Settings.System.SCREEN_BRIGHTNESS_MODE, 0) == Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC);
        } else {
            updateSettings();
            updateSettings(resolver);
        }
    }

    private void updateSettings() {
        ContentResolver resolver = mView.getContext().getContentResolver();

    private void updateSettings(ContentResolver resolver) {
        boolean lightSensorCustom = (Settings.System.getInt(resolver,
                Settings.System.LIGHT_SENSOR_CUSTOM, 0) != 0);
        if (lightSensorCustom) {
@@ -198,7 +190,5 @@ public class BrightnessButton extends PowerButton {
                }
            }
        }
        updateState();
    }

}
+5 −6
Original line number Diff line number Diff line
@@ -20,8 +20,8 @@ public class FlashlightButton extends PowerButton {
    public FlashlightButton() { mType = BUTTON_FLASHLIGHT; }

    @Override
    protected void updateState() {
        boolean enabled = Settings.System.getInt(mView.getContext().getContentResolver(), Settings.System.TORCH_STATE, 0) == 1;
    protected void updateState(Context context) {
        boolean enabled = Settings.System.getInt(context.getContentResolver(), Settings.System.TORCH_STATE, 0) == 1;
        if(enabled) {
            mIcon = R.drawable.stat_flashlight_on;
            mState = STATE_ENABLED;
@@ -32,8 +32,7 @@ public class FlashlightButton extends PowerButton {
    }

    @Override
    protected void toggleState() {
        Context context = mView.getContext();
    protected void toggleState(Context context) {
        boolean bright = Settings.System.getInt(context.getContentResolver(),
                Settings.System.EXPANDED_FLASH_MODE, 0) == 1;
        Intent i = new Intent("net.cactii.flash2.TOGGLE_FLASHLIGHT");
@@ -42,13 +41,13 @@ public class FlashlightButton extends PowerButton {
    }

    @Override
    protected boolean handleLongClick() {
    protected boolean handleLongClick(Context context) {
        // it may be better to make an Intent action for the Torch
        // we may want to look at that option later
        Intent intent = new Intent(Intent.ACTION_MAIN);
        intent.setClassName("net.cactii.flash2", "net.cactii.flash2.MainActivity");
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        mView.getContext().startActivity(intent);
        context.startActivity(intent);
        return true;
    }

Loading