blob: a147d3036566857ad031ecbc1a75593fd7161c23 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
|
/*
* 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.
* 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.content.Intent;
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.app.Profile;
import cyanogenmod.app.ProfileManager;
import cyanogenmod.providers.CMSettings;
import org.cyanogenmod.internal.logging.CMMetricsLogger;
public class LockscreenToggleTile extends QSTile<QSTile.BooleanState>
implements KeyguardMonitor.Callback {
private static final Intent LOCK_SCREEN_SETTINGS =
new Intent("android.settings.LOCK_SCREEN_SETTINGS");
private KeyguardMonitor mKeyguard;
private boolean mListening;
private KeyguardViewMediator.LockscreenEnabledSettingsObserver mSettingsObserver;
public LockscreenToggleTile(Host host) {
super(host);
mKeyguard = host.getKeyguardMonitor();
mSettingsObserver = new KeyguardViewMediator.LockscreenEnabledSettingsObserver(mContext,
mUiHandler) {
@Override
public void update() {
refreshState();
}
};
}
@Override
public void setListening(boolean listening) {
if (mListening == listening) {
return;
}
mListening = listening;
if (listening) {
mSettingsObserver.observe();
mKeyguard.addCallback(this);
refreshState();
} else {
mSettingsObserver.unobserve();
mKeyguard.removeCallback(this);
}
}
@Override
protected BooleanState newTileState() {
return new BooleanState();
}
@Override
protected void handleClick() {
final boolean newState = !getState().value;
setPersistedState(newState);
refreshState(newState);
}
@Override
protected void handleLongClick() {
mHost.startActivityDismissingKeyguard(LOCK_SCREEN_SETTINGS);
}
@Override
protected void handleUpdateState(BooleanState state, Object arg) {
KeyguardViewMediator mediator = ((SystemUIApplication)
mContext.getApplicationContext()).getComponent(KeyguardViewMediator.class);
if (mediator == null) {
state.visible = false;
state.value = false;
state.enabled = false;
} else {
final boolean lockscreenEnforced = mediator.lockscreenEnforcedByDevicePolicy();
final boolean lockscreenEnabled = lockscreenEnforced ||
arg != null ? (Boolean) arg : mediator.getKeyguardEnabledInternal();
state.visible = mediator.isKeyguardBound();
if (mediator.isProfileDisablingKeyguard()) {
state.value = false;
state.enabled = false;
state.label = mContext.getString(
R.string.quick_settings_lockscreen_label_locked_by_profile);
} else if (lockscreenEnforced) {
state.value = true;
state.enabled = false;
state.label = mContext.getString(
R.string.quick_settings_lockscreen_label_enforced);
} else {
state.value = lockscreenEnabled;
state.enabled = !mKeyguard.isShowing() || !mKeyguard.isSecure();
state.label = mContext.getString(R.string.quick_settings_lockscreen_label);
}
// update icon
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 CMMetricsLogger.TILE_LOCKSCREEN_TOGGLE;
}
@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
public void onKeyguardChanged() {
refreshState();
}
private void setPersistedState(boolean enabled) {
CMSettings.Secure.putIntForUser(mContext.getContentResolver(),
CMSettings.Secure.LOCKSCREEN_INTERNALLY_ENABLED,
enabled ? 1 : 0, UserHandle.USER_CURRENT);
}
}
|