Global gesture to toggle Accessibility system-wide.

1. This change adds a global gesture for enabling accessibility.
   To enable this gesture the user has to allow it from the
   accessibility settings or use the setup wizard to enable
   accessibility. When the global gesture is enabled the user
   can long press on power to bring the global actions dialog
   and then hold with two fingers for a few seconds to enable
   accessibility. The appropriate feedback is also provided.

2. The global gesture is writing directly into the settings for
   the current user if performed when the keyguard is not on. If
   the keygaurd is on and the current user has no accessibility
   enabled, the gesture will temporary enable accessibility
   for the current user, i.e. no settings are changed, to allow
   the blind user to log into his account. As soon as a user
   switch happens the new user settings are inherited. If no
   user change happens after temporary enabling accessibility
   the temporary changes will be undone when the keyguard goes
   away and the device will works as expected by the current user.

bug:6171929

3. The initialization code for the owner was not executed due
   to a redundant check, thus putting the accessibility layer in
   an inconsistent state which breaks pretty much everything.

bug:7240414

Change-Id: Ie7d7aba80f5867b7f88d5893b848b53fb02a7537
diff --git a/core/java/android/provider/Settings.java b/core/java/android/provider/Settings.java
index ffc48d8..550713d 100644
--- a/core/java/android/provider/Settings.java
+++ b/core/java/android/provider/Settings.java
@@ -3300,7 +3300,7 @@
             "enabled_accessibility_services";
 
         /**
-         * List of the accessibility services to which the user has graned
+         * List of the accessibility services to which the user has granted
          * permission to put the device into touch exploration mode.
          *
          * @hide
@@ -3319,7 +3319,7 @@
          * <p>
          *   Note: The JavaScript based screen-reader is served by the
          *   Google infrastructure and enable users with disabilities to
-         *   efficiantly navigate in and explore web content.
+         *   efficiently navigate in and explore web content.
          * </p>
          * <p>
          *   This property represents a boolean value.
@@ -3331,7 +3331,7 @@
 
         /**
          * The URL for the injected JavaScript based screen-reader used
-         * for providing accessiblity of content in WebView.
+         * for providing accessibility of content in WebView.
          * <p>
          *   Note: The JavaScript based screen-reader is served by the
          *   Google infrastructure and enable users with disabilities to
@@ -4110,6 +4110,15 @@
         public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY + "/global");
 
         /**
+         * Setting whether the global gesture for enabling accessibility is enabled.
+         * If this gesture is enabled the user will be able to perfrom it to enable
+         * the accessibility state without visiting the settings app.
+         * @hide
+         */
+        public static final String ENABLE_ACCESSIBILITY_GLOBAL_GESTURE_ENABLED =
+                "enable_accessibility_global_gesture_enabled";
+
+        /**
          * Whether Airplane Mode is on.
          */
         public static final String AIRPLANE_MODE_ON = "airplane_mode_on";
diff --git a/core/java/android/view/accessibility/IAccessibilityManager.aidl b/core/java/android/view/accessibility/IAccessibilityManager.aidl
index 60238627..c3ef54c 100644
--- a/core/java/android/view/accessibility/IAccessibilityManager.aidl
+++ b/core/java/android/view/accessibility/IAccessibilityManager.aidl
@@ -20,6 +20,7 @@
 import android.accessibilityservice.AccessibilityServiceInfo;
 import android.accessibilityservice.IAccessibilityServiceConnection;
 import android.accessibilityservice.IAccessibilityServiceClient;
+import android.content.ComponentName;
 import android.view.accessibility.AccessibilityEvent;
 import android.view.accessibility.AccessibilityNodeInfo;
 import android.view.accessibility.IAccessibilityInteractionConnection;
@@ -53,4 +54,7 @@
         in AccessibilityServiceInfo info);
 
     void unregisterUiTestAutomationService(IAccessibilityServiceClient client);
+
+    void temporaryEnableAccessibilityStateUntilKeyguardRemoved(in ComponentName service,
+            boolean touchExplorationEnabled);
 }
diff --git a/core/res/AndroidManifest.xml b/core/res/AndroidManifest.xml
index a8bee4d..8dbaa26 100644
--- a/core/res/AndroidManifest.xml
+++ b/core/res/AndroidManifest.xml
@@ -1578,6 +1578,12 @@
         android:description="@string/permdesc_retrieve_window_info"
         android:protectionLevel="signature" />
 
+    <!-- @hide Allows an application to temporary enable accessibility on the device. -->
+    <permission android:name="android.permission.TEMPORARY_ENABLE_ACCESSIBILITY"
+        android:label="@string/permlab_temporary_enable_accessibility"
+        android:description="@string/permdesc_temporary_enable_accessibility"
+        android:protectionLevel="signature" />
+
     <!-- @hide Allows an application to magnify the content of a display. -->
     <permission android:name="android.permission.MAGNIFY_DISPLAY"
         android:label="@string/permlab_magnify_display"
diff --git a/core/res/res/values/dimens.xml b/core/res/res/values/dimens.xml
index e860dfe..63ed18e 100644
--- a/core/res/res/values/dimens.xml
+++ b/core/res/res/values/dimens.xml
@@ -285,4 +285,7 @@
     <!-- Space reserved at the bottom of secure views (pin/pattern/password/SIM pin/SIM puk) -->
     <dimen name="kg_secure_padding_height">46dp</dimen>
 
+    <!-- Touch slop for the global toggle accessibility gesture -->
+    <dimen name="accessibility_touch_slop">80dip</dimen>
+
 </resources>
diff --git a/core/res/res/values/strings.xml b/core/res/res/values/strings.xml
index c90f4f2..02aa537 100755
--- a/core/res/res/values/strings.xml
+++ b/core/res/res/values/strings.xml
@@ -744,6 +744,13 @@
         the entire window content and examine all its text except passwords.</string>
 
     <!-- Title of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
+    <string name="permlab_temporary_enable_accessibility">temporary enable accessibility</string>
+    <!-- Description of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
+    <string name="permdesc_temporary_enable_accessibility">Allows an application to temporarily
+         enable accessibility on the device. Malicious apps may enable accessibility without
+         user consent.</string>
+
+    <!-- Title of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
     <string name="permlab_retrieve_window_info">retrieve window info</string>
     <!-- Description of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
     <string name="permdesc_retrieve_window_info">Allows an application to retrieve
@@ -3903,4 +3910,13 @@
     </string>
 
 
+    <!-- Text spoken when the user is performing a gesture that will enable accessibility. [CHAR LIMIT=none] -->
+    <string name="continue_to_enable_accessibility">Continue touching the screen to enable accessibility.</string>
+    <!-- Text spoken when the user enabled accessibility. [CHAR LIMIT=none] -->
+    <string name="accessibility_enabled">Accessibility enabled.</string>
+    <!-- Text spoken when the user stops preforming a gesture that would enable accessibility. [CHAR LIMIT=none] -->
+    <string name="enable_accessibility_canceled">Enable accessibility canceled.</string>
+    <!-- Text spoken when the current user is switched if accessibility is enabled. [CHAR LIMIT=none] -->
+    <string name="user_switched">Switched to user <xliff:g id="name" example="Bob">%1$s</xliff:g>.</string>
+
 </resources>
diff --git a/core/res/res/values/symbols.xml b/core/res/res/values/symbols.xml
index d85e581..9a4136b 100644
--- a/core/res/res/values/symbols.xml
+++ b/core/res/res/values/symbols.xml
@@ -290,6 +290,7 @@
 
   <java-symbol type="color" name="tab_indicator_text_v4" />
 
+  <java-symbol type="dimen" name="accessibility_touch_slop" />
   <java-symbol type="dimen" name="config_prefDialogWidth" />
   <java-symbol type="dimen" name="config_viewConfigurationTouchSlop" />
   <java-symbol type="dimen" name="default_app_widget_padding_bottom" />
@@ -357,6 +358,7 @@
   <java-symbol type="string" name="abbrev_month_day_year" />
   <java-symbol type="string" name="abbrev_month_year" />
   <java-symbol type="string" name="accept" />
+  <java-symbol type="string" name="accessibility_enabled" />
   <java-symbol type="string" name="activity_chooser_view_see_all" />
   <java-symbol type="string" name="activitychooserview_choose_application" />
   <java-symbol type="string" name="alternate_eri_file" />
@@ -437,6 +439,7 @@
   <java-symbol type="string" name="contentServiceSync" />
   <java-symbol type="string" name="contentServiceSyncNotificationTitle" />
   <java-symbol type="string" name="contentServiceTooManyDeletesNotificationDesc" />
+  <java-symbol type="string" name="continue_to_enable_accessibility" />
   <java-symbol type="string" name="date1_date2" />
   <java-symbol type="string" name="date1_time1_date2_time2" />
   <java-symbol type="string" name="date_and_time" />
@@ -470,6 +473,7 @@
   <java-symbol type="string" name="emailTypeWork" />
   <java-symbol type="string" name="emergency_call_dialog_number_for_display" />
   <java-symbol type="string" name="emergency_calls_only" />
+  <java-symbol type="string" name="enable_accessibility_canceled" />
   <java-symbol type="string" name="eventTypeAnniversary" />
   <java-symbol type="string" name="eventTypeBirthday" />
   <java-symbol type="string" name="eventTypeCustom" />
@@ -778,6 +782,7 @@
   <java-symbol type="string" name="twelve_hour_time_format" />
   <java-symbol type="string" name="twenty_four_hour_time_format" />
   <java-symbol type="string" name="upload_file" />
+  <java-symbol type="string" name="user_switched" />
   <java-symbol type="string" name="volume_alarm" />
   <java-symbol type="string" name="volume_icon_description_bluetooth" />
   <java-symbol type="string" name="volume_icon_description_incall" />