Skip to content

Commit 69b3255

Browse files
committed
Cherry-pick of ag/3568768 into ub-testdpc-pic
Test: manual Change-Id: I03e14d905e446e517fedce0649db2f78bdd41b37
1 parent ae247a1 commit 69b3255

File tree

4 files changed

+49
-11
lines changed

4 files changed

+49
-11
lines changed

app/src/main/java/com/afwsamples/testdpc/policy/PolicyManagementFragment.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1344,6 +1344,11 @@ private void showManageLockTaskListPrompt(int dialogTitle,
13441344
launcherIntent.addCategory(Intent.CATEGORY_LAUNCHER);
13451345
final List<ResolveInfo> primaryUserAppList = mPackageManager
13461346
.queryIntentActivities(launcherIntent, 0);
1347+
Intent homeIntent = new Intent(Intent.ACTION_MAIN);
1348+
homeIntent.addCategory(Intent.CATEGORY_HOME);
1349+
// Also show the default launcher in this list
1350+
final ResolveInfo defaultLauncher = mPackageManager.resolveActivity(homeIntent, 0);
1351+
primaryUserAppList.add(defaultLauncher);
13471352
if (primaryUserAppList.isEmpty()) {
13481353
showToast(R.string.no_primary_app_available);
13491354
} else {

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

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@
1616

1717
package com.afwsamples.testdpc.policy.locktask;
1818

19+
import static android.app.admin.DevicePolicyManager.LOCK_TASK_FEATURE_GLOBAL_ACTIONS;
20+
import static android.app.admin.DevicePolicyManager.LOCK_TASK_FEATURE_HOME;
21+
import static android.app.admin.DevicePolicyManager.LOCK_TASK_FEATURE_KEYGUARD;
22+
import static android.app.admin.DevicePolicyManager.LOCK_TASK_FEATURE_NOTIFICATIONS;
23+
import static android.app.admin.DevicePolicyManager.LOCK_TASK_FEATURE_SYSTEM_INFO;
24+
1925
import android.annotation.TargetApi;
2026
import android.app.admin.DevicePolicyManager;
2127
import android.content.ComponentName;
@@ -28,6 +34,7 @@
2834
import com.afwsamples.testdpc.DeviceAdminReceiver;
2935
import com.afwsamples.testdpc.R;
3036
import com.afwsamples.testdpc.common.BaseSearchablePolicyPreferenceFragment;
37+
import com.afwsamples.testdpc.common.ReflectionUtil;
3138
import com.afwsamples.testdpc.common.preference.DpcSwitchPreference;
3239
import java.util.Map;
3340

@@ -49,19 +56,31 @@ public class SetLockTaskFeaturesFragment
4956
private static final String KEY_SYSTEM_INFO = "lock_task_feature_system_info";
5057
private static final String KEY_NOTIFICATIONS = "lock_task_feature_notifications";
5158
private static final String KEY_HOME = "lock_task_feature_home";
52-
private static final String KEY_RECENTS = "lock_task_feature_recents";
59+
private static final String KEY_OVERVIEW = "lock_task_feature_overview";
5360
private static final String KEY_GLOBAL_ACTIONS = "lock_task_feature_global_actions";
5461
private static final String KEY_KEYGUARD = "lock_task_feature_keyguard";
5562

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+
5675
/** Maps from preference keys to {@link DevicePolicyManager#setLockTaskFeatures}'s flags. */
5776
private static final ArrayMap<String, Integer> FEATURE_FLAGS = new ArrayMap<>();
5877
static {
59-
FEATURE_FLAGS.put(KEY_SYSTEM_INFO, DevicePolicyManager.LOCK_TASK_FEATURE_SYSTEM_INFO);
60-
FEATURE_FLAGS.put(KEY_NOTIFICATIONS, DevicePolicyManager.LOCK_TASK_FEATURE_NOTIFICATIONS);
61-
FEATURE_FLAGS.put(KEY_HOME, DevicePolicyManager.LOCK_TASK_FEATURE_HOME);
62-
FEATURE_FLAGS.put(KEY_RECENTS, DevicePolicyManager.LOCK_TASK_FEATURE_RECENTS);
63-
FEATURE_FLAGS.put(KEY_GLOBAL_ACTIONS, DevicePolicyManager.LOCK_TASK_FEATURE_GLOBAL_ACTIONS);
64-
FEATURE_FLAGS.put(KEY_KEYGUARD, DevicePolicyManager.LOCK_TASK_FEATURE_KEYGUARD);
78+
FEATURE_FLAGS.put(KEY_SYSTEM_INFO, LOCK_TASK_FEATURE_SYSTEM_INFO);
79+
FEATURE_FLAGS.put(KEY_NOTIFICATIONS, LOCK_TASK_FEATURE_NOTIFICATIONS);
80+
FEATURE_FLAGS.put(KEY_HOME, LOCK_TASK_FEATURE_HOME);
81+
FEATURE_FLAGS.put(KEY_OVERVIEW, LOCK_TASK_FEATURE_OVERVIEW);
82+
FEATURE_FLAGS.put(KEY_GLOBAL_ACTIONS, LOCK_TASK_FEATURE_GLOBAL_ACTIONS);
83+
FEATURE_FLAGS.put(KEY_KEYGUARD, LOCK_TASK_FEATURE_KEYGUARD);
6584
}
6685

6786
private DevicePolicyManager mDpm;
@@ -94,6 +113,7 @@ public void onResume() {
94113
DpcSwitchPreference pref = (DpcSwitchPreference) findPreference(entry.getKey());
95114
pref.setChecked((enabledFeatures & entry.getValue()) != 0);
96115
}
116+
enforceEnablingRestrictions(enabledFeatures);
97117
}
98118

99119
@Override
@@ -105,14 +125,19 @@ public boolean onPreferenceChange(Preference pref, Object val) {
105125
}
106126

107127
final int flagsBefore = getLockTaskFeatures();
108-
final int flagsAfter = (Boolean) val
128+
int flagsAfter = (Boolean) val
109129
? flagsBefore | FEATURE_FLAGS.get(key)
110130
: flagsBefore & ~FEATURE_FLAGS.get(key);
131+
if ((flagsAfter & LOCK_TASK_FEATURE_HOME) == 0) {
132+
// Disable OVERVIEW when HOME is disabled
133+
flagsAfter &= ~LOCK_TASK_FEATURE_OVERVIEW;
134+
}
111135
if (flagsAfter != flagsBefore) {
112136
Log.i(TAG, "LockTask feature flags changing from 0x" + Integer.toHexString(flagsBefore)
113137
+ " to 0x" + Integer.toHexString(flagsAfter));
114138
try {
115139
setLockTaskFeatures(flagsAfter);
140+
enforceEnablingRestrictions(flagsAfter);
116141
return true;
117142
} catch (SecurityException e) {
118143
Log.e(TAG, "setLockTaskFeatures() can only be called by DO and affiliated PO");
@@ -129,6 +154,14 @@ public boolean isAvailable(Context context) {
129154
return true;
130155
}
131156

157+
private void enforceEnablingRestrictions(int enabledFeatures) {
158+
DpcSwitchPreference pref = (DpcSwitchPreference) findPreference(KEY_OVERVIEW);
159+
pref.setEnabled((enabledFeatures & LOCK_TASK_FEATURE_HOME) != 0);
160+
if (!pref.isEnabled() && pref.isChecked()) {
161+
pref.setChecked(false);
162+
}
163+
}
164+
132165
@TargetApi(28)
133166
private int getLockTaskFeatures() {
134167
return mDpm.getLockTaskFeatures(mAdmin);

app/src/main/res/values/strings.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@
345345
<string name="lock_task_feature_system_info">System info</string>
346346
<string name="lock_task_feature_notifications">Notifications</string>
347347
<string name="lock_task_feature_home">Home</string>
348-
<string name="lock_task_feature_recents">Recents</string>
348+
<string name="lock_task_feature_overview">Overview</string>
349349
<string name="lock_task_feature_global_actions">Global actions (power button menu)</string>
350350
<string name="lock_task_feature_keyguard">Keyguard</string>
351351
<string name="start_lock_task">Self-start lock task mode</string>

app/src/main/res/xml/lock_task_features_preferences.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@
4444
testdpc:minSdkVersion="P" />
4545

4646
<com.afwsamples.testdpc.common.preference.DpcSwitchPreference
47-
android:key="lock_task_feature_recents"
48-
android:title="@string/lock_task_feature_recents"
47+
android:key="lock_task_feature_overview"
48+
android:title="@string/lock_task_feature_overview"
4949
android:persistent="false"
5050
android:defaultValue="false"
5151
testdpc:admin="deviceOwner|profileOwner"

0 commit comments

Comments
 (0)