Merge "Unify profile and device lock by setting the work lock on the device"
This commit is contained in:
committed by
Android (Google) Code Review
commit
3d71918c58
@@ -60,7 +60,8 @@ public class ProfileChallengePreferenceFragment extends SettingsPreferenceFragme
|
|||||||
public static final String TAG_UNIFICATION_DIALOG = "unification_dialog";
|
public static final String TAG_UNIFICATION_DIALOG = "unification_dialog";
|
||||||
|
|
||||||
private static final int SET_OR_CHANGE_LOCK_METHOD_REQUEST = 123;
|
private static final int SET_OR_CHANGE_LOCK_METHOD_REQUEST = 123;
|
||||||
private static final int UNIFY_LOCK_METHOD_REQUEST = 124;
|
private static final int UNIFY_LOCK_CONFIRM_DEVICE_REQUEST = 124;
|
||||||
|
private static final int UNIFY_LOCK_CONFIRM_PROFILE_REQUEST = 125;
|
||||||
|
|
||||||
// Not all preferences make sense for the Work Challenge, this is a whitelist.
|
// Not all preferences make sense for the Work Challenge, this is a whitelist.
|
||||||
private static final Set<String> ALLOWED_PREFERENCE_KEYS = new HashSet<>();
|
private static final Set<String> ALLOWED_PREFERENCE_KEYS = new HashSet<>();
|
||||||
@@ -77,6 +78,9 @@ public class ProfileChallengePreferenceFragment extends SettingsPreferenceFragme
|
|||||||
private LockPatternUtils mLockPatternUtils;
|
private LockPatternUtils mLockPatternUtils;
|
||||||
private int mProfileUserId;
|
private int mProfileUserId;
|
||||||
|
|
||||||
|
private String mCurrentDevicePassword;
|
||||||
|
private String mCurrentProfilePassword;
|
||||||
|
|
||||||
private SwitchPreference mVisiblePattern;
|
private SwitchPreference mVisiblePattern;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -127,15 +131,58 @@ public class ProfileChallengePreferenceFragment extends SettingsPreferenceFragme
|
|||||||
@Override
|
@Override
|
||||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||||
super.onActivityResult(requestCode, resultCode, data);
|
super.onActivityResult(requestCode, resultCode, data);
|
||||||
if (requestCode == UNIFY_LOCK_METHOD_REQUEST && resultCode == Activity.RESULT_OK) {
|
if (requestCode == UNIFY_LOCK_CONFIRM_DEVICE_REQUEST && resultCode == Activity.RESULT_OK) {
|
||||||
|
mCurrentDevicePassword =
|
||||||
|
data.getStringExtra(ChooseLockSettingsHelper.EXTRA_KEY_PASSWORD);
|
||||||
|
launchConfirmProfileLockForUnification();
|
||||||
|
return;
|
||||||
|
} else if (requestCode == UNIFY_LOCK_CONFIRM_PROFILE_REQUEST
|
||||||
|
&& resultCode == Activity.RESULT_OK) {
|
||||||
|
mCurrentProfilePassword =
|
||||||
|
data.getStringExtra(ChooseLockSettingsHelper.EXTRA_KEY_PASSWORD);
|
||||||
unifyLocks();
|
unifyLocks();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void launchConfirmDeviceLockForUnification() {
|
||||||
|
final String title = getActivity().getString(
|
||||||
|
R.string.lock_settings_profile_screen_lock_title);
|
||||||
|
final ChooseLockSettingsHelper helper =
|
||||||
|
new ChooseLockSettingsHelper(getActivity(), this);
|
||||||
|
if (!helper.launchConfirmationActivity(
|
||||||
|
UNIFY_LOCK_CONFIRM_DEVICE_REQUEST, title, true, UserHandle.myUserId())) {
|
||||||
|
launchConfirmProfileLockForUnification();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void launchConfirmProfileLockForUnification() {
|
||||||
|
final String title = getActivity().getString(
|
||||||
|
R.string.lock_settings_profile_screen_lock_title);
|
||||||
|
final ChooseLockSettingsHelper helper =
|
||||||
|
new ChooseLockSettingsHelper(getActivity(), this);
|
||||||
|
if (!helper.launchConfirmationActivity(
|
||||||
|
UNIFY_LOCK_CONFIRM_PROFILE_REQUEST, title, true, mProfileUserId)) {
|
||||||
|
unifyLocks();
|
||||||
|
createPreferenceHierarchy();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void unifyLocks() {
|
private void unifyLocks() {
|
||||||
|
int profileQuality = mLockPatternUtils.getKeyguardStoredPasswordQuality(mProfileUserId);
|
||||||
mLockPatternUtils.clearLock(mProfileUserId);
|
mLockPatternUtils.clearLock(mProfileUserId);
|
||||||
mLockPatternUtils.setSeparateProfileChallengeEnabled(mProfileUserId, false);
|
mLockPatternUtils.setSeparateProfileChallengeEnabled(mProfileUserId, false);
|
||||||
|
if (profileQuality == DevicePolicyManager.PASSWORD_QUALITY_SOMETHING) {
|
||||||
|
mLockPatternUtils.saveLockPattern(
|
||||||
|
LockPatternUtils.stringToPattern(mCurrentProfilePassword),
|
||||||
|
mCurrentDevicePassword, UserHandle.myUserId());
|
||||||
|
} else {
|
||||||
|
mLockPatternUtils.saveLockPassword(
|
||||||
|
mCurrentProfilePassword, mCurrentDevicePassword,
|
||||||
|
profileQuality, UserHandle.myUserId());
|
||||||
|
}
|
||||||
|
mCurrentDevicePassword = null;
|
||||||
|
mCurrentProfilePassword = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -172,7 +219,7 @@ public class ProfileChallengePreferenceFragment extends SettingsPreferenceFragme
|
|||||||
root.findPreference(KEY_SECURITY_CATEGORY);
|
root.findPreference(KEY_SECURITY_CATEGORY);
|
||||||
if (securityCategory != null) {
|
if (securityCategory != null) {
|
||||||
if (mLockPatternUtils.isSeparateProfileChallengeEnabled(mProfileUserId)) {
|
if (mLockPatternUtils.isSeparateProfileChallengeEnabled(mProfileUserId)) {
|
||||||
addUnificationPreference(securityCategory);
|
maybeAddUnificationPreference(securityCategory);
|
||||||
} else {
|
} else {
|
||||||
Preference lockPreference =
|
Preference lockPreference =
|
||||||
securityCategory.findPreference(KEY_UNLOCK_SET_OR_CHANGE);
|
securityCategory.findPreference(KEY_UNLOCK_SET_OR_CHANGE);
|
||||||
@@ -183,12 +230,15 @@ public class ProfileChallengePreferenceFragment extends SettingsPreferenceFragme
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addUnificationPreference(PreferenceGroup securityCategory) {
|
private void maybeAddUnificationPreference(PreferenceGroup securityCategory) {
|
||||||
Preference unificationPreference = new Preference(securityCategory.getContext());
|
if (mLockPatternUtils.getKeyguardStoredPasswordQuality(mProfileUserId)
|
||||||
unificationPreference.setKey(KEY_UNIFICATION);
|
>= DevicePolicyManager.PASSWORD_QUALITY_SOMETHING) {
|
||||||
unificationPreference.setTitle(R.string.lock_settings_profile_unification_title);
|
Preference unificationPreference = new Preference(securityCategory.getContext());
|
||||||
unificationPreference.setSummary(R.string.lock_settings_profile_unification_summary);
|
unificationPreference.setKey(KEY_UNIFICATION);
|
||||||
securityCategory.addPreference(unificationPreference);
|
unificationPreference.setTitle(R.string.lock_settings_profile_unification_title);
|
||||||
|
unificationPreference.setSummary(R.string.lock_settings_profile_unification_summary);
|
||||||
|
securityCategory.addPreference(unificationPreference);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void removeNonWhitelistedItems(PreferenceGroup prefScreen) {
|
private void removeNonWhitelistedItems(PreferenceGroup prefScreen) {
|
||||||
@@ -243,13 +293,9 @@ public class ProfileChallengePreferenceFragment extends SettingsPreferenceFragme
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static class UnificationConfirmationDialog extends DialogFragment {
|
public static class UnificationConfirmationDialog extends DialogFragment {
|
||||||
private static final String ARG_USER_ID = "userId";
|
|
||||||
|
|
||||||
public static UnificationConfirmationDialog newIntance(int userId) {
|
public static UnificationConfirmationDialog newIntance(int userId) {
|
||||||
UnificationConfirmationDialog dialog = new UnificationConfirmationDialog();
|
UnificationConfirmationDialog dialog = new UnificationConfirmationDialog();
|
||||||
Bundle args = new Bundle();
|
|
||||||
args.putInt(ARG_USER_ID, userId);
|
|
||||||
dialog.setArguments(args);
|
|
||||||
return dialog;
|
return dialog;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -263,7 +309,6 @@ public class ProfileChallengePreferenceFragment extends SettingsPreferenceFragme
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||||
final Bundle args = getArguments();
|
|
||||||
final ProfileChallengePreferenceFragment parentFragment =
|
final ProfileChallengePreferenceFragment parentFragment =
|
||||||
((ProfileChallengePreferenceFragment) getParentFragment());
|
((ProfileChallengePreferenceFragment) getParentFragment());
|
||||||
return new AlertDialog.Builder(getActivity())
|
return new AlertDialog.Builder(getActivity())
|
||||||
@@ -273,17 +318,7 @@ public class ProfileChallengePreferenceFragment extends SettingsPreferenceFragme
|
|||||||
new DialogInterface.OnClickListener() {
|
new DialogInterface.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(DialogInterface dialog, int whichButton) {
|
public void onClick(DialogInterface dialog, int whichButton) {
|
||||||
String title = getContext().getString(
|
parentFragment.launchConfirmDeviceLockForUnification();
|
||||||
R.string.lock_settings_profile_screen_lock_title);
|
|
||||||
ChooseLockSettingsHelper helper =
|
|
||||||
new ChooseLockSettingsHelper(
|
|
||||||
getActivity(), parentFragment);
|
|
||||||
if (!helper.launchConfirmationActivity(
|
|
||||||
UNIFY_LOCK_METHOD_REQUEST,
|
|
||||||
title, true, args.getInt(ARG_USER_ID))) {
|
|
||||||
parentFragment.unifyLocks();
|
|
||||||
parentFragment.createPreferenceHierarchy();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
Reference in New Issue
Block a user