Skip to content

Commit 6115224

Browse files
committed
Update testdpc with latest lock task behaviour
The platform now enforces that FEATURE_NOTIFICATION can only be used together with FEATURE_HOME. Therefore we update the UI in TestDpc to block the disallowed combination. Bug: 71790952 Test: manual Change-Id: I9313fb63aa8f08ef915aca63f126c2a534033368
1 parent 8076038 commit 6115224

File tree

1 file changed

+10
-16
lines changed

1 file changed

+10
-16
lines changed

app/src/main/java/com/afwsamples/testdpc/policy/locktask/SetLockTaskFeaturesFragment.java

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import static android.app.admin.DevicePolicyManager.LOCK_TASK_FEATURE_HOME;
2121
import static android.app.admin.DevicePolicyManager.LOCK_TASK_FEATURE_KEYGUARD;
2222
import static android.app.admin.DevicePolicyManager.LOCK_TASK_FEATURE_NOTIFICATIONS;
23+
import static android.app.admin.DevicePolicyManager.LOCK_TASK_FEATURE_OVERVIEW;
2324
import static android.app.admin.DevicePolicyManager.LOCK_TASK_FEATURE_SYSTEM_INFO;
2425

2526
import android.annotation.TargetApi;
@@ -60,18 +61,6 @@ public class SetLockTaskFeaturesFragment
6061
private static final String KEY_GLOBAL_ACTIONS = "lock_task_feature_global_actions";
6162
private static final String KEY_KEYGUARD = "lock_task_feature_keyguard";
6263

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-
7564
/** Maps from preference keys to {@link DevicePolicyManager#setLockTaskFeatures}'s flags. */
7665
private static final ArrayMap<String, Integer> FEATURE_FLAGS = new ArrayMap<>();
7766
static {
@@ -129,8 +118,8 @@ public boolean onPreferenceChange(Preference pref, Object val) {
129118
? flagsBefore | FEATURE_FLAGS.get(key)
130119
: flagsBefore & ~FEATURE_FLAGS.get(key);
131120
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);
134123
}
135124
if (flagsAfter != flagsBefore) {
136125
Log.i(TAG, "LockTask feature flags changing from 0x" + Integer.toHexString(flagsBefore)
@@ -155,8 +144,13 @@ public boolean isAvailable(Context context) {
155144
}
156145

157146
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);
160154
if (!pref.isEnabled() && pref.isChecked()) {
161155
pref.setChecked(false);
162156
}

0 commit comments

Comments
 (0)