summaryrefslogtreecommitdiffstats
path: root/packages/SystemUI/src/com/android/systemui/qs/tiles
diff options
context:
space:
mode:
authorRoman Birg <roman@cyngn.com>2016-01-08 13:28:51 -0800
committerGerrit Code Review <gerrit@cyanogenmod.org>2016-01-13 13:02:11 -0800
commit9501c4aaa1602eb3d2aaa0087f7aacf042253a4a (patch)
tree759eb616b07a327a7f984487c5a2cb0bfd9a1d74 /packages/SystemUI/src/com/android/systemui/qs/tiles
parent70524943904138e66fef9fbe0c062e39d870f13e (diff)
downloadframeworks_base-9501c4aaa1602eb3d2aaa0087f7aacf042253a4a.zip
frameworks_base-9501c4aaa1602eb3d2aaa0087f7aacf042253a4a.tar.gz
frameworks_base-9501c4aaa1602eb3d2aaa0087f7aacf042253a4a.tar.bz2
SystemUI: write keyguard enabled setting to CMSettings
Instead of saving this to a shared preference in SystemUI, let's leverage the CM SDK Settings Provider so we can query this state and let the user know why the keyguard is disabled. Also move the logic into KeyguardViewMediator to monitor the state change and apply it locally. Ref: CYNGNOS-1513 Change-Id: I08a984797921178082e1e7bda881b7b8a7965ddf Signed-off-by: Roman Birg <roman@cyngn.com>
Diffstat (limited to 'packages/SystemUI/src/com/android/systemui/qs/tiles')
-rw-r--r--packages/SystemUI/src/com/android/systemui/qs/tiles/LockscreenToggleTile.java85
1 files changed, 32 insertions, 53 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/qs/tiles/LockscreenToggleTile.java b/packages/SystemUI/src/com/android/systemui/qs/tiles/LockscreenToggleTile.java
index f762d3e..6f1a921 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/tiles/LockscreenToggleTile.java
+++ b/packages/SystemUI/src/com/android/systemui/qs/tiles/LockscreenToggleTile.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2015 The CyanogenMod Project
+ * Copyright (C) 2015-2016 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.
@@ -16,69 +16,67 @@
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 android.os.UserHandle;
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;
+import cyanogenmod.providers.CMSettings;
import org.cyanogenmod.internal.logging.CMMetricsLogger;
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();
- }
- }
- };
+ private boolean mListening;
+
+ private KeyguardViewMediator.LockscreenEnabledSettingsObserver mSettingsObserver;
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));
+ mSettingsObserver = new KeyguardViewMediator.LockscreenEnabledSettingsObserver(mContext,
+ mUiHandler) {
+
+ @Override
+ public void update() {
+ boolean newEnabledState = CMSettings.Secure.getIntForUser(
+ mContext.getContentResolver(),
+ CMSettings.Secure.LOCKSCREEN_INTERNALLY_ENABLED,
+ getPersistedDefaultOldSetting() ? 1 : 0,
+ UserHandle.USER_CURRENT) != 0;
+ if (newEnabledState != mPersistedState) {
+ mPersistedState = newEnabledState;
+ refreshState();
+ }
+ }
+ };
+
}
@Override
public void setListening(boolean listening) {
+ if (mListening == listening) {
+ return;
+ }
+ mListening = listening;
if (listening) {
+ mSettingsObserver.observe();
mKeyguard.addCallback(this);
} else {
+ mSettingsObserver.unobserve();
mKeyguard.removeCallback(this);
}
}
@@ -91,8 +89,6 @@ public class LockscreenToggleTile extends QSTile<QSTile.BooleanState>
@Override
protected void handleClick() {
setPersistedState(!mPersistedState);
- applyLockscreenState();
- refreshState();
}
@Override
@@ -140,31 +136,14 @@ public class LockscreenToggleTile extends QSTile<QSTile.BooleanState>
}
@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();
+ CMSettings.Secure.putIntForUser(mContext.getContentResolver(),
+ CMSettings.Secure.LOCKSCREEN_INTERNALLY_ENABLED,
+ enabled ? 1 : 0, UserHandle.USER_CURRENT);
mPersistedState = enabled;
}
} \ No newline at end of file