Skip to content

Commit be1cc57

Browse files
committed
Update the usage of locknow in testdpc
Change-Id: I8dc17569d5d03a6ee7a30409a3778a1871717f11 Fix: 29379761
1 parent 9368f50 commit be1cc57

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ public void onPositiveButtonClicked(String[] lockTaskArray) {
501501
showResetPasswordPrompt();
502502
return false;
503503
case LOCK_NOW_KEY:
504-
mDevicePolicyManager.lockNow();
504+
lockNow();
505505
return true;
506506
case START_LOCK_TASK:
507507
getActivity().startLockTask();
@@ -695,6 +695,19 @@ public void onPositiveButtonClicked(String[] lockTaskArray) {
695695
return false;
696696
}
697697

698+
@TargetApi(Build.VERSION_CODES.N)
699+
private void lockNow() {
700+
if (Util.isBeforeN() || !Util.isManagedProfile(getActivity(), mAdminComponentName)) {
701+
mDevicePolicyManager.lockNow();
702+
} else {
703+
// In N for work profiles we should call lockNow on the parent instance to
704+
// lock the device.
705+
DevicePolicyManager parentDpm
706+
= mDevicePolicyManager.getParentProfileInstance(mAdminComponentName);
707+
parentDpm.lockNow();
708+
}
709+
}
710+
698711
@Override
699712
@SuppressLint("NewApi")
700713
public boolean onPreferenceChange(Preference preference, Object newValue) {

0 commit comments

Comments
 (0)