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

Commit 4601c9fd authored by Adnan Begovic's avatar Adnan Begovic
Browse files

SystemUi: Readd LockscreenToggleTile.

Change-Id: Ib1e627bf5432ce54a9f81a5ba65da7c687c232d6
parent 36cf3468
Loading
Loading
Loading
Loading
+13 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
    android:width="64dp"
    android:height="64dp"
    android:viewportWidth="48"
    android:viewportHeight="48">

    <path
        android:fillColor="#4DFFFFFF"
        android:pathData="M36,16h-2v-4c0-5.5-4.5-10-10-10S14,6.5,14,12h3.8c0-3.4,2.8-6.2,6.2-6.2
s6.2,2.8,6.2,6.2v4H12c-2.2,0-4,1.8-4,4v20c0,2.2,1.8,4,4,4h24c2.2,0,4-1.8,4-4V20C40,17.8,38.2,16,36,16Z
M36,40H12V20L36,40z" />
</vector>
+14 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
    android:width="64dp"
    android:height="64dp"
    android:viewportWidth="48"
    android:viewportHeight="48">

    <path
        android:fillColor="#FFFFFF"
        android:pathData="M36,16h-2v-4c0-5.5-4.5-10-10-10S14,6.5,14,12v4h-2c-2.2,0-4,1.8-4,4v20
c0,2.2,1.8,4,4,4h24c2.2,0,4-1.8,4-4V20C40,17.8,38.2,16,36,16Z
M24,5.8c3.4,0,6.2,2.8,6.2,6.2v4H17.8v-4C17.8,8.6,20.6,5.8,24,5.8z
M36,40H12V20L36,40z" />
</vector>
+12 −0
Original line number Diff line number Diff line
@@ -124,6 +124,8 @@
    <string name="quick_settings_volume_panel_label">Volume panel</string>
    <string name="quick_settings_usb_tether_label">USB tethering</string>
    <string name="quick_settings_screen_timeout_detail_title">Screen timeout</string>
    <string name="quick_settings_lockscreen_label">Lock screen</string>
    <string name="quick_settings_lockscreen_label_enforced">Lock screen enforced</string>
    <!-- Content description of the screen timeout tile in quick settings (not shown on the screen). [CHAR LIMIT=NONE] -->
    <string name="accessibility_quick_settings_screen_timeout">Screen timeout: <xliff:g id="timeout" example="30 seconds">%s</xliff:g>.</string>

@@ -154,6 +156,16 @@
    <string name="accessibility_quick_settings_perf_profile_changed_bias_perf">Battery mode changed to quick mode.</string>
    <string name="quick_settings_performance_profile_detail_title">Battery mode</string>

    <!-- Content description of the lock screen tile in quick settings when off (not shown on the screen). [CHAR LIMIT=NONE] -->
    <string name="accessibility_quick_settings_lock_screen_off">Lock screen off.</string>
    <!-- Content description of the lock screen tile in quick settings when on (not shown on the screen). [CHAR LIMIT=NONE] -->
    <string name="accessibility_quick_settings_lock_screen_on">Lock screen on.</string>

    <!-- Announcement made when lock screen changes to off (not shown on the screen). [CHAR LIMIT=NONE] -->
    <string name="accessibility_quick_settings_lock_screen_changed_off">Lock screen turned off.</string>
    <!-- Announcement made when lock screen changes to on (not shown on the screen). [CHAR LIMIT=NONE] -->
    <string name="accessibility_quick_settings_lock_screen_changed_on">Lock screen turned on.</string>

    <!-- Dynamic tiles -->
    <string name="quick_settings_dynamic_tile_detail_title">Dynamic tile</string>
    <string name="dynamic_qs_tile_next_alarm_label">Next alarm</string>
+21 −0
Original line number Diff line number Diff line
@@ -56,6 +56,7 @@ import android.view.WindowManagerPolicy;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;

import com.android.systemui.qs.tiles.LockscreenToggleTile;
import cyanogenmod.app.Profile;
import cyanogenmod.app.ProfileManager;

@@ -141,6 +142,10 @@ public class KeyguardViewMediator extends SystemUI {
    private static final String DISMISS_KEYGUARD_SECURELY_ACTION =
        "com.android.keyguard.action.DISMISS_KEYGUARD_SECURELY";

    private static final String KEYGUARD_SERVICE_ACTION_STATE_CHANGE =
            "com.android.internal.action.KEYGUARD_SERVICE_STATE_CHANGED";
    private static final String KEYGUARD_SERVICE_EXTRA_ACTIVE = "active";

    // used for handler messages
    private static final int SHOW = 2;
    private static final int HIDE = 3;
@@ -256,6 +261,11 @@ public class KeyguardViewMediator extends SystemUI {
     */
    private IKeyguardExitCallback mExitSecureCallback;

    /**
     * Whether we are bound to the service delegate
     */
    private boolean mKeyguardBound;

    // the properties of the keyguard

    private KeyguardUpdateMonitor mUpdateMonitor;
@@ -565,6 +575,8 @@ public class KeyguardViewMediator extends SystemUI {
        mContext.registerReceiver(mBroadcastReceiver, new IntentFilter(DELAYED_KEYGUARD_ACTION));
        mContext.registerReceiver(mBroadcastReceiver, new IntentFilter(DISMISS_KEYGUARD_SECURELY_ACTION),
                android.Manifest.permission.CONTROL_KEYGUARD, null);
        mContext.registerReceiver(mBroadcastReceiver, new IntentFilter(KEYGUARD_SERVICE_ACTION_STATE_CHANGE),
                android.Manifest.permission.CONTROL_KEYGUARD, null);

        mKeyguardDisplayManager = new KeyguardDisplayManager(mContext);

@@ -770,6 +782,10 @@ public class KeyguardViewMediator extends SystemUI {
        mDelayedShowingSequence++;
    }

    public boolean isKeyguardBound() {
        return mKeyguardBound;
    }

    /**
     * Let's us know when the device is waking up.
     */
@@ -1234,6 +1250,11 @@ public class KeyguardViewMediator extends SystemUI {
                synchronized (KeyguardViewMediator.this) {
                    dismiss();
                }
            } else if (KEYGUARD_SERVICE_ACTION_STATE_CHANGE.equals(intent.getAction())) {
                mKeyguardBound = intent.getBooleanExtra(KEYGUARD_SERVICE_EXTRA_ACTIVE, false);
                context.sendBroadcast(new Intent(
                        LockscreenToggleTile.ACTION_APPLY_LOCKSCREEN_STATE)
                        .setPackage(context.getPackageName()));
            }
        }
    };
+170 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2015 The CyanogenMod Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.systemui.qs.tiles;

import android.app.admin.DevicePolicyManager;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;

import android.widget.Toast;
import com.android.internal.logging.MetricsLogger;
import com.android.systemui.R;
import com.android.systemui.SystemUIApplication;
import com.android.systemui.keyguard.KeyguardViewMediator;
import com.android.systemui.qs.QSTile;
import com.android.systemui.statusbar.policy.KeyguardMonitor;

public class LockscreenToggleTile extends QSTile<QSTile.BooleanState>
        implements KeyguardMonitor.Callback {

    public static final String ACTION_APPLY_LOCKSCREEN_STATE =
            "com.android.systemui.qs.tiles.action.APPLY_LOCKSCREEN_STATE";

    private static final String KEY_ENABLED = "lockscreen_enabled";

    private static final Intent LOCK_SCREEN_SETTINGS =
            new Intent("android.settings.LOCK_SCREEN_SETTINGS");

    private KeyguardViewMediator mKeyguardViewMediator;
    private KeyguardMonitor mKeyguard;
    private boolean mPersistedState;
    private boolean mKeyguardBound;
    private SharedPreferences mPrefs;

    private BroadcastReceiver mReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            if (mKeyguardViewMediator != null) {
                mKeyguardBound = mKeyguardViewMediator.isKeyguardBound();
                applyLockscreenState();
                refreshState();
            }
        }
    };

    public LockscreenToggleTile(Host host) {
        super(host);
        mPrefs = mContext.getSharedPreferences("quicksettings", Context.MODE_PRIVATE);

        mKeyguard = host.getKeyguardMonitor();
        mKeyguardViewMediator =
                ((SystemUIApplication)
                        mContext.getApplicationContext()).getComponent(KeyguardViewMediator.class);
        mPersistedState = getPersistedState();
        mKeyguardBound = mKeyguardViewMediator.isKeyguardBound();
        applyLockscreenState();

        mContext.registerReceiver(mReceiver, new IntentFilter(ACTION_APPLY_LOCKSCREEN_STATE));
    }

    @Override
    public void setListening(boolean listening) {
        if (listening) {
            mKeyguard.addCallback(this);
        } else {
            mKeyguard.removeCallback(this);
        }
    }

    @Override
    protected BooleanState newTileState() {
        return new BooleanState();
    }

    @Override
    protected void handleClick() {
        setPersistedState(!mPersistedState);
        applyLockscreenState();
        refreshState();
    }

    @Override
    protected void handleLongClick() {
        mHost.startActivityDismissingKeyguard(LOCK_SCREEN_SETTINGS);
    }

    @Override
    protected void handleUpdateState(BooleanState state, Object arg) {
        final boolean lockscreenEnforced = mKeyguardViewMediator.lockscreenEnforcedByDevicePolicy();
        final boolean lockscreenEnabled = lockscreenEnforced
                || mPersistedState
                || mKeyguardViewMediator.getKeyguardEnabledInternal();

        state.value = lockscreenEnabled;
        state.visible = !mKeyguard.isShowing() || !mKeyguard.isSecure();
        state.label = mContext.getString(lockscreenEnforced
                ? R.string.quick_settings_lockscreen_label_enforced
                : R.string.quick_settings_lockscreen_label);
        if (lockscreenEnabled) {
            state.icon = ResourceIcon.get(R.drawable.ic_qs_lock_screen_on);
            state.contentDescription = mContext.getString(
                    R.string.accessibility_quick_settings_lock_screen_on);
        } else {
            state.icon = ResourceIcon.get(R.drawable.ic_qs_lock_screen_off);
            state.contentDescription = mContext.getString(
                    R.string.accessibility_quick_settings_lock_screen_off);
        }
    }

    @Override
    public int getMetricsCategory() {
        return MetricsLogger.DONT_TRACK_ME_BRO;
    }

    @Override
    protected String composeChangeAnnouncement() {
        if (mState.value) {
            return mContext.getString(
                    R.string.accessibility_quick_settings_lock_screen_changed_on);
        } else {
            return mContext.getString(
                    R.string.accessibility_quick_settings_lock_screen_changed_off);
        }
    }

    @Override
    protected void handleDestroy() {
        super.handleDestroy();
        mContext.unregisterReceiver(mReceiver);
    }

    @Override
    public void onKeyguardChanged() {
        refreshState();
    }

    private void applyLockscreenState() {
        if (!mKeyguardBound) {
            // do nothing yet
            return;
        }

        mKeyguardViewMediator.setKeyguardEnabledInternal(mPersistedState);
    }

    private boolean getPersistedState() {
        return mPrefs.getBoolean(KEY_ENABLED, true);
    }

    private void setPersistedState(boolean enabled) {
        mPrefs.edit().putBoolean(KEY_ENABLED, enabled).apply();
        mPersistedState = enabled;
    }
}
 No newline at end of file
Loading