Multi-user support for the accessibility layer.

1. This change converts the accessibility manager service to
   maintain a state per user. When the user changes the services
   for the user that is going away are disconnected, the local
   accessibility managers in the processes for this user are
   disabled, the state is swapped with the new user's one, and
   the new user state is refreshed.

   This change updates all calls into the system to use their
   user specific versions when applicable. For example, regisetring
   content observers, package monitors, calls into other system
   services, etc.

   There are some components that are shared across users such
   as UI created by the system process and the SystemUI package.
   Such components are managed as a global state shared across
   all users and are updated accordingly on a user switch. Since
   the SystemUI is running in a normal app process this change
   adds hidden APIs on the local window manager to allow the
   SystemUI to notify the accessibility layer that it will run
   accross users.

   Calls to AccessibiltyManager's isEnabled(), isTouchExplorationEnabled()
   and sendAccessibilityEvent return false or a are a nop for a
   background user sice he should not send accessibility events,
   and should not perform touch exploration.

   Update the internal accessibility tests due to changes in the
   AccessibilityManager.

   This change also fixes several issues that were encountered
   such as calling out the accessibility manager service with a
   lock held.

   Removed some incorrect debugging code from the TouchExplorer
   that was leading to a system crash.

bug:6967373

Change-Id: I2cf32ffdee1d827a8197ae4ce717dc0ff798b259
diff --git a/core/java/android/app/ApplicationPackageManager.java b/core/java/android/app/ApplicationPackageManager.java
index 7870031..18503f6 100644
--- a/core/java/android/app/ApplicationPackageManager.java
+++ b/core/java/android/app/ApplicationPackageManager.java
@@ -42,10 +42,8 @@
 import android.content.pm.ResolveInfo;
 import android.content.pm.ServiceInfo;
 import android.content.pm.ManifestDigest;
-import android.content.pm.UserInfo;
 import android.content.pm.VerificationParams;
 import android.content.pm.VerifierDeviceIdentity;
-import android.content.pm.PackageManager.NameNotFoundException;
 import android.content.res.Resources;
 import android.content.res.XmlResourceParser;
 import android.graphics.drawable.Drawable;
@@ -453,11 +451,17 @@
 
     @Override
     public ResolveInfo resolveActivity(Intent intent, int flags) {
+        return resolveActivityAsUser(intent, flags, UserHandle.myUserId());
+    }
+
+    @Override
+    public ResolveInfo resolveActivityAsUser(Intent intent, int flags, int userId) {
         try {
             return mPM.resolveIntent(
                 intent,
                 intent.resolveTypeIfNeeded(mContext.getContentResolver()),
-                    flags, UserHandle.myUserId());
+                flags,
+                userId);
         } catch (RemoteException e) {
             throw new RuntimeException("Package manager has died", e);
         }
@@ -466,12 +470,12 @@
     @Override
     public List<ResolveInfo> queryIntentActivities(Intent intent,
                                                    int flags) {
-        return queryIntentActivitiesForUser(intent, flags, UserHandle.myUserId());
+        return queryIntentActivitiesAsUser(intent, flags, UserHandle.myUserId());
     }
 
     /** @hide Same as above but for a specific user */
     @Override
-    public List<ResolveInfo> queryIntentActivitiesForUser(Intent intent,
+    public List<ResolveInfo> queryIntentActivitiesAsUser(Intent intent,
                                                    int flags, int userId) {
         try {
             return mPM.queryIntentActivities(
@@ -551,19 +555,24 @@
     }
 
     @Override
-    public List<ResolveInfo> queryIntentServices(Intent intent, int flags) {
+    public List<ResolveInfo> queryIntentServicesAsUser(Intent intent, int flags, int userId) {
         try {
             return mPM.queryIntentServices(
                 intent,
                 intent.resolveTypeIfNeeded(mContext.getContentResolver()),
                 flags,
-                UserHandle.myUserId());
+                userId);
         } catch (RemoteException e) {
             throw new RuntimeException("Package manager has died", e);
         }
     }
 
     @Override
+    public List<ResolveInfo> queryIntentServices(Intent intent, int flags) {
+        return queryIntentServicesAsUser(intent, flags, UserHandle.myUserId());
+    }
+
+    @Override
     public ProviderInfo resolveContentProvider(String name,
                                                int flags) {
         try {