OSDN Git Service

User should confirm device lock before un-unifying
authorMahaver Chopra <mahaver@google.com>
Fri, 18 Mar 2016 19:08:05 +0000 (19:08 +0000)
committerMahaver Chopra <mahaver@google.com>
Fri, 18 Mar 2016 19:36:47 +0000 (19:36 +0000)
User should confirm device lock before un-unifying
Move Use the same lock toggle the first option
When Unifying Title while confirming device password is of profile.

Bug: 26815727
Bug: 27523804
Bug: 27547551

Change-Id: I44857f7dcff3d68486e7e4d2ae8565b56d7c91b7

res/values/strings.xml
src/com/android/settings/SecuritySettings.java

index 5fa5bf5..23d9e3f 100644 (file)
     <string name="lock_settings_profile_unification_dialog_body">You can use your work profile lock for your device screen lock as well. If you do, any work lock policies will also apply to your device screen lock.</string>
     <!-- Security & location settings screen, explanation in the dialog asking if the user wants to create a new lock for personal and work as the current work lock is not enough for the device. -->
     <string name="lock_settings_profile_unification_dialog_uncompliant_body">Your work profile lock doesn\'t meet your organization\'s security requirements.\n\nYou can set a new screen lock for both your device and your work profile, but any work lock policies will apply to your device screen lock as well.</string>
-    <!-- Security & location settings screen, confirmation button of the dialog asking if the user wants to create a new lock for both personal and work profiles. -->
+    <!-- Security & location settings screen, confirmation button of the dialog for user with compliant lock, asking to create a new lock for both personal and work profiles. -->
     <string name="lock_settings_profile_unification_dialog_confirm">Change device lock</string>
-    <!-- Security & location settings screen, confirmation button of the dialog asking if the user wants to create a new lock for both personal and work profiles. -->
+    <!-- Security & location settings screen, confirmation button of the dialog for user with uncompliant lock, asking to create a new lock for both personal and work profiles. -->
     <string name="lock_settings_profile_unification_dialog_uncompliant_confirm">Change lock</string>
     <!-- Security & location settings screen, summary of the item that changes your work profile lock when it is unified with the personal lock -->
     <string name="lock_settings_profile_unified_summary">Same as device screen lock</string>
index 4097d04..06c05c8 100644 (file)
@@ -97,6 +97,7 @@ public class SecuritySettings extends SettingsPreferenceFragment
     private static final int SET_OR_CHANGE_LOCK_METHOD_REQUEST_PROFILE = 127;
     private static final int UNIFY_LOCK_CONFIRM_DEVICE_REQUEST = 128;
     private static final int UNIFY_LOCK_CONFIRM_PROFILE_REQUEST = 129;
+    private static final int UNUNIFY_LOCK_CONFIRM_DEVICE_REQUEST = 130;
     private static final String TAG_UNIFICATION_DIALOG = "unification_dialog";
 
     // Misc Settings
@@ -247,11 +248,11 @@ public class SecuritySettings extends SettingsPreferenceFragment
         if (mProfileChallengeUserId != UserHandle.USER_NULL
                 && mLockPatternUtils.isSeparateProfileChallengeAllowed(mProfileChallengeUserId)) {
             addPreferencesFromResource(R.xml.security_settings_profile);
+            addPreferencesFromResource(R.xml.security_settings_unification);
             final int profileResid = getResIdForLockUnlockScreen(
                     getActivity(), mLockPatternUtils, mProfileChallengeUserId);
             addPreferencesFromResource(profileResid);
             maybeAddFingerprintPreference(root, mProfileChallengeUserId);
-            addPreferencesFromResource(R.xml.security_settings_unification);
             if (!mLockPatternUtils.isSeparateProfileChallengeEnabled(mProfileChallengeUserId)) {
                 Preference lockPreference = root.findPreference(KEY_UNLOCK_SET_OR_CHANGE_PROFILE);
                 String summary = getContext().getString(
@@ -646,24 +647,28 @@ public class SecuritySettings extends SettingsPreferenceFragment
                     data.getStringExtra(ChooseLockSettingsHelper.EXTRA_KEY_PASSWORD);
             unifyLocks();
             return;
+        } else if (requestCode == UNUNIFY_LOCK_CONFIRM_DEVICE_REQUEST
+                && resultCode == Activity.RESULT_OK) {
+            ununifyLocks();
+            return;
         }
         createPreferenceHierarchy();
     }
 
     private void launchConfirmDeviceLockForUnification() {
         final String title = getActivity().getString(
-                R.string.lock_settings_profile_screen_lock_title);
+                R.string.unlock_set_unlock_launch_picker_title);
         final ChooseLockSettingsHelper helper =
                 new ChooseLockSettingsHelper(getActivity(), this);
         if (!helper.launchConfirmationActivity(
-                UNIFY_LOCK_CONFIRM_DEVICE_REQUEST, title, true, UserHandle.myUserId())) {
+                UNIFY_LOCK_CONFIRM_DEVICE_REQUEST, title, true, MY_USER_ID)) {
             launchConfirmProfileLockForUnification();
         }
     }
 
     private void launchConfirmProfileLockForUnification() {
         final String title = getActivity().getString(
-                R.string.lock_settings_profile_screen_lock_title);
+                R.string.unlock_set_unlock_launch_picker_title_profile);
         final ChooseLockSettingsHelper helper =
                 new ChooseLockSettingsHelper(getActivity(), this);
         if (!helper.launchConfirmationActivity(
@@ -681,11 +686,11 @@ public class SecuritySettings extends SettingsPreferenceFragment
         if (profileQuality == DevicePolicyManager.PASSWORD_QUALITY_SOMETHING) {
             mLockPatternUtils.saveLockPattern(
                     LockPatternUtils.stringToPattern(mCurrentProfilePassword),
-                    mCurrentDevicePassword, UserHandle.myUserId());
+                    mCurrentDevicePassword, MY_USER_ID);
         } else {
             mLockPatternUtils.saveLockPassword(
                     mCurrentProfilePassword, mCurrentDevicePassword,
-                    profileQuality, UserHandle.myUserId());
+                    profileQuality, MY_USER_ID);
         }
         mCurrentDevicePassword = null;
         mCurrentProfilePassword = null;
@@ -698,6 +703,16 @@ public class SecuritySettings extends SettingsPreferenceFragment
                 R.string.lock_settings_picker_title, SET_OR_CHANGE_LOCK_METHOD_REQUEST, null);
     }
 
+    private void ununifyLocks() {
+        mLockPatternUtils.setSeparateProfileChallengeEnabled(mProfileChallengeUserId, true);
+        Bundle extras = new Bundle();
+        extras.putInt(Intent.EXTRA_USER_ID, mProfileChallengeUserId);
+        startFragment(this,
+                "com.android.settings.ChooseLockGeneric$ChooseLockGenericFragment",
+                R.string.lock_settings_picker_title_profile,
+                SET_OR_CHANGE_LOCK_METHOD_REQUEST_PROFILE, extras);
+    }
+
     @Override
     public boolean onPreferenceChange(Preference preference, Object value) {
         boolean result = true;
@@ -716,13 +731,14 @@ public class SecuritySettings extends SettingsPreferenceFragment
                         UnificationConfirmationDialog.newIntance(compliantForDevice);
                 dialog.show(getChildFragmentManager(), TAG_UNIFICATION_DIALOG);
             } else {
-                mLockPatternUtils.setSeparateProfileChallengeEnabled(mProfileChallengeUserId, true);
-                Bundle extras = new Bundle();
-                extras.putInt(Intent.EXTRA_USER_ID, mProfileChallengeUserId);
-                startFragment(this,
-                        "com.android.settings.ChooseLockGeneric$ChooseLockGenericFragment",
-                        R.string.lock_settings_picker_title_profile,
-                        SET_OR_CHANGE_LOCK_METHOD_REQUEST_PROFILE, extras);
+                final String title = getActivity().getString(
+                        R.string.unlock_set_unlock_launch_picker_title);
+                final ChooseLockSettingsHelper helper =
+                        new ChooseLockSettingsHelper(getActivity(), this);
+                if(!helper.launchConfirmationActivity(
+                        UNUNIFY_LOCK_CONFIRM_DEVICE_REQUEST, title, true, MY_USER_ID)) {
+                    ununifyLocks();
+                }
             }
         } else if (KEY_SHOW_PASSWORD.equals(key)) {
             Settings.System.putInt(getContentResolver(), Settings.System.TEXT_SHOW_PASSWORD,
@@ -1207,7 +1223,8 @@ public class SecuritySettings extends SettingsPreferenceFragment
                     .setTitle(R.string.lock_settings_profile_unification_dialog_title)
                     .setMessage(compliant ? R.string.lock_settings_profile_unification_dialog_body
                             : R.string.lock_settings_profile_unification_dialog_uncompliant_body)
-                    .setPositiveButton(compliant ? R.string.okay
+                    .setPositiveButton(
+                            compliant ? R.string.lock_settings_profile_unification_dialog_confirm
                             : R.string.lock_settings_profile_unification_dialog_uncompliant_confirm,
                             new DialogInterface.OnClickListener() {
                                 @Override