After an ax service permanently crashes, it won't eat keys

The volume keys will work again, the ax button will reset back to the
correct state, and a bunch of other things.
This is cause we are not tracking the state of the service correctly in
this "Service won't run, but is on" state. Previously we just assumed it
was on.

Bug: 74593001
Test: Verified on device. By getting testback to crash. Tested, turning
service on and off in settings. Crashing it once, and having it restart
automiatically. Continuesouly crashing it until the system decides this
is bad. And after that state rebooting to make sure the service starts
up again.

Change-Id: I00e9c978d6807d8508968286a7545e48f9ae5800
diff --git a/services/accessibility/java/com/android/server/accessibility/AccessibilityManagerService.java b/services/accessibility/java/com/android/server/accessibility/AccessibilityManagerService.java
index 7798cf7..b2c1bed 100644
--- a/services/accessibility/java/com/android/server/accessibility/AccessibilityManagerService.java
+++ b/services/accessibility/java/com/android/server/accessibility/AccessibilityManagerService.java
@@ -3743,6 +3743,8 @@
 
         /**
          * Removes a service.
+         * There are three states to a service here: off, bound, and binding.
+         * This stops tracking the service as bound.
          *
          * @param serviceConnection The service.
          */
@@ -3759,6 +3761,19 @@
             scheduleNotifyClientsOfServicesStateChange(this);
         }
 
+        /**
+         * Make sure a services disconnected but still 'on' state is reflected in UserState
+         * There are three states to a service here: off, bound, and binding.
+         * This drops a service from a bound state, to the binding state.
+         * The binding state describes the situation where a service is on, but not bound.
+         *
+         * @param serviceConnection The service.
+         */
+        public void serviceDisconnectedLocked(AccessibilityServiceConnection serviceConnection) {
+            removeServiceLocked(serviceConnection);
+            mBindingServices.add(serviceConnection.getComponentName());
+        }
+
         public Set<ComponentName> getBindingServicesLocked() {
             return mBindingServices;
         }
diff --git a/services/accessibility/java/com/android/server/accessibility/AccessibilityServiceConnection.java b/services/accessibility/java/com/android/server/accessibility/AccessibilityServiceConnection.java
index eb18f06..105df92 100644
--- a/services/accessibility/java/com/android/server/accessibility/AccessibilityServiceConnection.java
+++ b/services/accessibility/java/com/android/server/accessibility/AccessibilityServiceConnection.java
@@ -258,7 +258,10 @@
                 return;
             }
             mWasConnectedAndDied = true;
-            resetLocked();
+            UserState userState = mUserStateWeakReference.get();
+            if (userState != null) {
+                userState.serviceDisconnectedLocked(this);
+            }
             if (mId == mSystemSupport.getMagnificationController().getIdOfLastServiceToMagnify()) {
                 mSystemSupport.getMagnificationController().resetIfNeeded(true);
             }