File tree Expand file tree Collapse file tree 1 file changed +14
-1
lines changed
app/src/main/java/com/afwsamples/testdpc/policy Expand file tree Collapse file tree 1 file changed +14
-1
lines changed Original file line number Diff line number Diff line change @@ -501,7 +501,7 @@ public void onPositiveButtonClicked(String[] lockTaskArray) {
501
501
showResetPasswordPrompt ();
502
502
return false ;
503
503
case LOCK_NOW_KEY :
504
- mDevicePolicyManager . lockNow ();
504
+ lockNow ();
505
505
return true ;
506
506
case START_LOCK_TASK :
507
507
getActivity ().startLockTask ();
@@ -695,6 +695,19 @@ public void onPositiveButtonClicked(String[] lockTaskArray) {
695
695
return false ;
696
696
}
697
697
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
+
698
711
@ Override
699
712
@ SuppressLint ("NewApi" )
700
713
public boolean onPreferenceChange (Preference preference , Object newValue ) {
You can’t perform that action at this time.
0 commit comments