Merge "Several fixes to new EncryptionInterstitial dialog." into lmp-dev
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 8384902..e73825e 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -3676,18 +3676,18 @@
         your device won’t use your screen lock to enhance data encryption.</string>
 
     <!-- Message to the user to enter his pattern before enabling an accessibility service. [CHAR LIMIT=NONE] -->
-    <string name="enable_service_pattern_reason">Turning on <xliff:g id="service"
-        example="TalkBack">%1$s</xliff:g> reduces data protection.
+    <string name="enable_service_pattern_reason">Because turning on <xliff:g id="service"
+        example="TalkBack">%1$s</xliff:g> affects data encryption, you need to confirm your pattern.
     </string>
 
     <!-- Message to the user to enter his PIN before enabling an accessibility service. [CHAR LIMIT=NONE] -->
-    <string name="enable_service_pin_reason">Turning on <xliff:g id="service"
-        example="TalkBack">%1$s</xliff:g> reduces data protection.
+    <string name="enable_service_pin_reason">Because turning on <xliff:g id="service"
+        example="TalkBack">%1$s</xliff:g> affects data encryption, you need to confirm your PIN.
     </string>
 
     <!-- Message to the user to enter his password before enabling an accessibility service. [CHAR LIMIT=NONE] -->
-    <string name="enable_service_password_reason">Turning on <xliff:g id="service"
-        example="TalkBack">%1$s</xliff:g> reduces data protection.
+    <string name="enable_service_password_reason">Because turning on <xliff:g id="service"
+        example="TalkBack">%1$s</xliff:g> affects data encryption, you need to confirm your password.
     </string>
 
     <!-- Title for the capability of an accessibility service to receive events and keys. -->
@@ -5971,12 +5971,12 @@
    <string name="encrypt_talkback_dialog_require_password">Require password?</string>
 
    <!-- Message for encryption dialog telling the user that Talkback and other accessibility services will be disabled. -->
-   <string name="encrypt_talkback_dialog_message_pin">When entering your PIN to start your device, accessibility services like TalkBack won\'t yet be available.</string>
+   <string name="encrypt_talkback_dialog_message_pin">When you enter your PIN to start this device, accessibility services like Talkback won\'t yet be available.</string>
 
    <!-- Message for encryption dialog telling the user that Talkback and other accessibility services will be disabled. -->
-   <string name="encrypt_talkback_dialog_message_pattern">When entering your pattern to start your device, accessibility services like TalkBack won\'t yet be available.</string>
+   <string name="encrypt_talkback_dialog_message_pattern">When you enter your pattern to start this device, accessibility services like Talkback won\'t yet be available.</string>
 
    <!-- Message for encryption dialog telling the user that Talkback and other accessibility services will be disabled. -->
-   <string name="encrypt_talkback_dialog_message_password">When entering your password to start your device, accessibility services like TalkBack won\'t yet be available.</string>
+   <string name="encrypt_talkback_dialog_message_password">When you enter your password to start this device, accessibility services like Talkback won\'t yet be available.</string>
 
 </resources>
diff --git a/src/com/android/settings/ChooseLockGeneric.java b/src/com/android/settings/ChooseLockGeneric.java
index a3deb00..e3a9932 100644
--- a/src/com/android/settings/ChooseLockGeneric.java
+++ b/src/com/android/settings/ChooseLockGeneric.java
@@ -344,6 +344,10 @@
         }
 
         private void updatePreferenceSummaryIfNeeded() {
+            if (LockPatternUtils.isDeviceEncrypted()) {
+                return;
+            }
+
             if (AccessibilityManager.getInstance(getActivity()).getEnabledAccessibilityServiceList(
                     AccessibilityServiceInfo.FEEDBACK_ALL_MASK).isEmpty()) {
                 return;
diff --git a/src/com/android/settings/accessibility/ToggleAccessibilityServicePreferenceFragment.java b/src/com/android/settings/accessibility/ToggleAccessibilityServicePreferenceFragment.java
index 71b5862..08fba67 100644
--- a/src/com/android/settings/accessibility/ToggleAccessibilityServicePreferenceFragment.java
+++ b/src/com/android/settings/accessibility/ToggleAccessibilityServicePreferenceFragment.java
@@ -55,7 +55,7 @@
     private static final int DIALOG_ID_ENABLE_WARNING = 1;
     private static final int DIALOG_ID_DISABLE_WARNING = 2;
 
-    public static final int ACTIVITY_REQUEST_CONFIRM_CREDENTIAL = 1;
+    public static final int ACTIVITY_REQUEST_CONFIRM_CREDENTIAL_FOR_WEAKER_ENCRYPTION = 1;
 
     private LockPatternUtils mLockPatternUtils;
 
@@ -284,9 +284,17 @@
 
     @Override
     public void onActivityResult(int requestCode, int resultCode, Intent data) {
-        if (requestCode == ACTIVITY_REQUEST_CONFIRM_CREDENTIAL) {
+        if (requestCode == ACTIVITY_REQUEST_CONFIRM_CREDENTIAL_FOR_WEAKER_ENCRYPTION) {
             if (resultCode == Activity.RESULT_OK) {
                 handleConfirmServiceEnabled(true);
+                // The user confirmed that they accept weaker encryption when
+                // enabling the accessibility service, so change encryption.
+                // Since we came here asynchronously, check encryption again.
+                if (LockPatternUtils.isDeviceEncrypted()) {
+                    mLockPatternUtils.clearEncryptionPassword();
+                    Settings.Global.putInt(getContentResolver(),
+                            Settings.Global.REQUIRE_PASSWORD_TO_DECRYPT, 0);
+                }
             } else {
                 handleConfirmServiceEnabled(false);
             }
@@ -302,7 +310,8 @@
                     if (LockPatternUtils.isDeviceEncrypted()) {
                         String title = createConfirmCredentialReasonMessage();
                         Intent intent = ConfirmDeviceCredentialActivity.createIntent(title, null);
-                        startActivityForResult(intent, ACTIVITY_REQUEST_CONFIRM_CREDENTIAL);
+                        startActivityForResult(intent,
+                                ACTIVITY_REQUEST_CONFIRM_CREDENTIAL_FOR_WEAKER_ENCRYPTION);
                     } else {
                         handleConfirmServiceEnabled(true);
                     }