20
20
import static android .app .admin .DevicePolicyManager .LOCK_TASK_FEATURE_HOME ;
21
21
import static android .app .admin .DevicePolicyManager .LOCK_TASK_FEATURE_KEYGUARD ;
22
22
import static android .app .admin .DevicePolicyManager .LOCK_TASK_FEATURE_NOTIFICATIONS ;
23
+ import static android .app .admin .DevicePolicyManager .LOCK_TASK_FEATURE_OVERVIEW ;
23
24
import static android .app .admin .DevicePolicyManager .LOCK_TASK_FEATURE_SYSTEM_INFO ;
24
25
25
26
import android .annotation .TargetApi ;
@@ -60,18 +61,6 @@ public class SetLockTaskFeaturesFragment
60
61
private static final String KEY_GLOBAL_ACTIONS = "lock_task_feature_global_actions" ;
61
62
private static final String KEY_KEYGUARD = "lock_task_feature_keyguard" ;
62
63
63
- private static final int LOCK_TASK_FEATURE_OVERVIEW ;
64
- static {
65
- int flag = 1 << 3 ;
66
- try {
67
- flag = ReflectionUtil .intConstant (
68
- DevicePolicyManager .class , "LOCK_TASK_FEATURE_OVERVIEW" );
69
- } catch (ReflectionUtil .ReflectionIsTemporaryException e ) {
70
- } finally {
71
- LOCK_TASK_FEATURE_OVERVIEW = flag ;
72
- }
73
- }
74
-
75
64
/** Maps from preference keys to {@link DevicePolicyManager#setLockTaskFeatures}'s flags. */
76
65
private static final ArrayMap <String , Integer > FEATURE_FLAGS = new ArrayMap <>();
77
66
static {
@@ -129,8 +118,8 @@ public boolean onPreferenceChange(Preference pref, Object val) {
129
118
? flagsBefore | FEATURE_FLAGS .get (key )
130
119
: flagsBefore & ~FEATURE_FLAGS .get (key );
131
120
if ((flagsAfter & LOCK_TASK_FEATURE_HOME ) == 0 ) {
132
- // Disable OVERVIEW when HOME is disabled
133
- flagsAfter &= ~LOCK_TASK_FEATURE_OVERVIEW ;
121
+ // Disable OVERVIEW and NOTIFICATION when HOME is disabled
122
+ flagsAfter &= ~( LOCK_TASK_FEATURE_OVERVIEW | LOCK_TASK_FEATURE_NOTIFICATIONS ) ;
134
123
}
135
124
if (flagsAfter != flagsBefore ) {
136
125
Log .i (TAG , "LockTask feature flags changing from 0x" + Integer .toHexString (flagsBefore )
@@ -155,8 +144,13 @@ public boolean isAvailable(Context context) {
155
144
}
156
145
157
146
private void enforceEnablingRestrictions (int enabledFeatures ) {
158
- DpcSwitchPreference pref = (DpcSwitchPreference ) findPreference (KEY_OVERVIEW );
159
- pref .setEnabled ((enabledFeatures & LOCK_TASK_FEATURE_HOME ) != 0 );
147
+ boolean isHomeEnabled = (enabledFeatures & LOCK_TASK_FEATURE_HOME ) != 0 ;
148
+ setPrefEnabledState ((DpcSwitchPreference ) findPreference (KEY_OVERVIEW ), isHomeEnabled );
149
+ setPrefEnabledState ((DpcSwitchPreference ) findPreference (KEY_NOTIFICATIONS ), isHomeEnabled );
150
+ }
151
+
152
+ private void setPrefEnabledState (DpcSwitchPreference pref , boolean enabled ) {
153
+ pref .setEnabled (enabled );
160
154
if (!pref .isEnabled () && pref .isChecked ()) {
161
155
pref .setChecked (false );
162
156
}
0 commit comments