Enabled accessibility services settings may end with a separator.

SetupWizard was adding a separator after the last service name while
building the enabled accessibility services string. This case was not
handled by the settings. Added code to handle that case since it is
possible to have not well-formed settings backed up.

bug:5098493

Change-Id: I8381872037611a7456ca31526c85effdb9949885
diff --git a/src/com/android/settings/AccessibilitySettings.java b/src/com/android/settings/AccessibilitySettings.java
index f98ca7e..3718ced 100644
--- a/src/com/android/settings/AccessibilitySettings.java
+++ b/src/com/android/settings/AccessibilitySettings.java
@@ -84,7 +84,7 @@
     // the AccessibilityServiceInfo we need for proper presentation.
     private static final long DELAY_UPDATE_SERVICES_PREFERENCES_MILLIS = 1000;
 
-    private static final char ENABLED_ACCESSIBILITY_SERVICES_SEPARATOR = ':';
+    private static final String ENABLED_ACCESSIBILITY_SERVICES_SEPARATOR = ":";
 
     private static final String KEY_ACCESSIBILITY_TUTORIAL_LAUNCHED_ONCE =
         "key_accessibility_tutorial_launched_once";
@@ -126,7 +126,7 @@
 
     // Auxiliary members.
     private final SimpleStringSplitter mStringColonSplitter =
-        new SimpleStringSplitter(ENABLED_ACCESSIBILITY_SERVICES_SEPARATOR);
+        new SimpleStringSplitter(ENABLED_ACCESSIBILITY_SERVICES_SEPARATOR.charAt(0));
 
     private final Map<String, String> mLongPressTimeoutValuetoTitleMap =
         new HashMap<String, String>();
@@ -572,6 +572,11 @@
             if (enabledServices == null) {
                 enabledServices = "";
             }
+            // Due to a legacy bug we can get an enabled services value ending with a
+            // separator. Make sure to catch and fix that before handling.
+            if (enabledServices.endsWith(ENABLED_ACCESSIBILITY_SERVICES_SEPARATOR)) {
+                enabledServices = enabledServices.substring(0, enabledServices.length() - 1);
+            }
             final int length = enabledServices.length();
             if (enabled) {
                 if (enabledServices.contains(preferenceKey)) {