Improper initialization of the accessibility manager service.

Initially the current user in the accessibility manager service is the
owner. This is correct since the system should be able to respond to
queries immediately and their result depends on the current user. However,
the system is calling the user switch callback with the current user
which is the same as the one we initialized with. Switching the user
causes clearing state for the old user winch is in case the current
one. Hence, we are losing state for the current user. This behavior was
masked from the fact that accidentally no events in the system were
fired before the first use user switch call.

repo Losing current user state puts the manager service in an inconsistent
state and it binds to accessibility services more than once. As a result
the accessibility layer starts to misbehave rendering the device useless
to a blind user.

Now we are ignoring user switch callbacks if the new user is the same
as the current one. Since we can no longer initialize at the first user
switch, this change adds explicit system ready method called from
the system server at the right moment.

bug:9496697

Change-Id: Icb39e929ea44e6c0360aba7ddc12f941ca2c9f98
diff --git a/services/java/com/android/server/accessibility/AccessibilityManagerService.java b/services/java/com/android/server/accessibility/AccessibilityManagerService.java
index 2f8250f..f1e4b0c 100644
--- a/services/java/com/android/server/accessibility/AccessibilityManagerService.java
+++ b/services/java/com/android/server/accessibility/AccessibilityManagerService.java
@@ -195,6 +195,9 @@
 
     private int mCurrentUserId = UserHandle.USER_OWNER;
 
+    //TODO: Remove this hack
+    private boolean mInitialized;
+
     private UserState getCurrentUserStateLocked() {
         return getUserStateLocked(mCurrentUserId);
     }
@@ -771,6 +774,10 @@
 
     private void switchUser(int userId) {
         synchronized (mLock) {
+            if (mCurrentUserId == userId && mInitialized) {
+                return;
+            }
+
             // Disconnect from services for the old user.
             UserState oldUserState = getUserStateLocked(mCurrentUserId);
             oldUserState.onSwitchToAnotherUser();
@@ -1283,6 +1290,8 @@
     }
 
     private void onUserStateChangedLocked(UserState userState) {
+        // TODO: Remove this hack
+        mInitialized = true;
         updateLegacyCapabilities(userState);
         updateServicesLocked(userState);
         updateFilterKeyEventsLocked(userState);