private void unregisterUiTestAutomationServiceLocked() {
   IAccessibilityManager manager =
       IAccessibilityManager.Stub.asInterface(
           ServiceManager.getService(Context.ACCESSIBILITY_SERVICE));
   try {
     // Calling out with a lock held is fine since if the system
     // process is gone the client calling in will be killed.
     manager.unregisterUiTestAutomationService(mClient);
     mClient = null;
   } catch (RemoteException re) {
     throw new IllegalStateException("Error while unregistering UiTestAutomationService", re);
   }
 }
 private void registerUiTestAutomationServiceLocked(IAccessibilityServiceClient client) {
   IAccessibilityManager manager =
       IAccessibilityManager.Stub.asInterface(
           ServiceManager.getService(Context.ACCESSIBILITY_SERVICE));
   AccessibilityServiceInfo info = new AccessibilityServiceInfo();
   info.eventTypes = AccessibilityEvent.TYPES_ALL_MASK;
   info.feedbackType = AccessibilityServiceInfo.FEEDBACK_GENERIC;
   info.flags |=
       AccessibilityServiceInfo.FLAG_INCLUDE_NOT_IMPORTANT_VIEWS
           | AccessibilityServiceInfo.FLAG_REPORT_VIEW_IDS;
   info.setCapabilities(
       AccessibilityServiceInfo.CAPABILITY_CAN_RETRIEVE_WINDOW_CONTENT
           | AccessibilityServiceInfo.CAPABILITY_CAN_REQUEST_TOUCH_EXPLORATION
           | AccessibilityServiceInfo.CAPABILITY_CAN_REQUEST_ENHANCED_WEB_ACCESSIBILITY
           | AccessibilityServiceInfo.CAPABILITY_CAN_REQUEST_FILTER_KEY_EVENTS);
   try {
     // Calling out with a lock held is fine since if the system
     // process is gone the client calling in will be killed.
     manager.registerUiTestAutomationService(mToken, client, info);
     mClient = client;
   } catch (RemoteException re) {
     throw new IllegalStateException("Error while registering UiTestAutomationService.", re);
   }
 }
 @Override
 public WindowContentFrameStats getWindowContentFrameStats(int windowId) throws RemoteException {
   synchronized (mLock) {
     throwIfCalledByNotTrustedUidLocked();
     throwIfShutdownLocked();
     throwIfNotConnectedLocked();
   }
   final long identity = Binder.clearCallingIdentity();
   try {
     IBinder token = mAccessibilityManager.getWindowToken(windowId);
     if (token == null) {
       return null;
     }
     return mWindowManager.getWindowContentFrameStats(token);
   } finally {
     Binder.restoreCallingIdentity(identity);
   }
 }