@Override
  protected void dump(FileDescriptor fd, PrintWriter fout, String[] args) {
    AbstractInputMethodService target = mTarget.get();
    if (target == null) {
      return;
    }
    if (target.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
        != PackageManager.PERMISSION_GRANTED) {

      fout.println(
          "Permission Denial: can't dump InputMethodManager from from pid="
              + Binder.getCallingPid()
              + ", uid="
              + Binder.getCallingUid());
      return;
    }

    CountDownLatch latch = new CountDownLatch(1);
    mCaller.executeOrSendMessage(mCaller.obtainMessageOOOO(DO_DUMP, fd, fout, args, latch));
    try {
      if (!latch.await(5, TimeUnit.SECONDS)) {
        fout.println("Timeout waiting for dump");
      }
    } catch (InterruptedException e) {
      fout.println("Interrupted waiting for dump");
    }
  }
 public void revokeSession(IInputMethodSession session) {
   try {
     InputMethodSession ls =
         ((IInputMethodSessionWrapper) session).getInternalInputMethodSession();
     mCaller.executeOrSendMessage(mCaller.obtainMessageO(DO_REVOKE_SESSION, ls));
   } catch (ClassCastException e) {
     Log.w(TAG, "Incoming session not of correct type: " + session, e);
   }
 }
 public void setSessionEnabled(IInputMethodSession session, boolean enabled) {
   try {
     InputMethodSession ls =
         ((IInputMethodSessionWrapper) session).getInternalInputMethodSession();
     mCaller.executeOrSendMessage(
         mCaller.obtainMessageIO(DO_SET_SESSION_ENABLED, enabled ? 1 : 0, ls));
   } catch (ClassCastException e) {
     Log.w(TAG, "Incoming session not of correct type: " + session, e);
   }
 }
  public void createPrintJob(PrintJobInfo printJob) {
    synchronized (mLock) {
      addPrintJobLocked(printJob);
      setPrintJobState(printJob.getId(), PrintJobInfo.STATE_CREATED, null);

      Message message =
          mHandlerCaller.obtainMessageO(
              HandlerCallerCallback.MSG_ON_PRINT_JOB_STATE_CHANGED, printJob);
      mHandlerCaller.executeOrSendMessage(message);
    }
  }
  public void setPrintJobCancelling(PrintJobId printJobId, boolean cancelling) {
    synchronized (mLock) {
      PrintJobInfo printJob = getPrintJobInfo(printJobId, PrintManager.APP_ID_ANY);
      if (printJob != null) {
        printJob.setCancelling(cancelling);
        if (shouldPersistPrintJob(printJob)) {
          mPersistanceManager.writeStateLocked();
        }
        mNotificationController.onUpdateNotifications(mPrintJobs);

        Message message =
            mHandlerCaller.obtainMessageO(
                HandlerCallerCallback.MSG_ON_PRINT_JOB_STATE_CHANGED, printJob);
        mHandlerCaller.executeOrSendMessage(message);
      }
    }
  }
 public void changeInputMethodSubtype(InputMethodSubtype subtype) {
   mCaller.executeOrSendMessage(mCaller.obtainMessageO(DO_CHANGE_INPUTMETHOD_SUBTYPE, subtype));
 }
 public void hideSoftInput(int flags, ResultReceiver resultReceiver) {
   mCaller.executeOrSendMessage(
       mCaller.obtainMessageIO(DO_HIDE_SOFT_INPUT, flags, resultReceiver));
 }
 public void createSession(IInputMethodCallback callback) {
   mCaller.executeOrSendMessage(mCaller.obtainMessageO(DO_CREATE_SESSION, callback));
 }
 public void restartInput(IInputContext inputContext, EditorInfo attribute) {
   mCaller.executeOrSendMessage(
       mCaller.obtainMessageOO(DO_RESTART_INPUT, inputContext, attribute));
 }
 public void unbindInput() {
   mCaller.executeOrSendMessage(mCaller.obtainMessage(DO_UNSET_INPUT_CONTEXT));
 }
 public void bindInput(InputBinding binding) {
   InputConnection ic =
       new InputConnectionWrapper(IInputContext.Stub.asInterface(binding.getConnectionToken()));
   InputBinding nu = new InputBinding(ic, binding);
   mCaller.executeOrSendMessage(mCaller.obtainMessageO(DO_SET_INPUT_CONTEXT, nu));
 }
 public void attachToken(IBinder token) {
   mCaller.executeOrSendMessage(mCaller.obtainMessageO(DO_ATTACH_TOKEN, token));
 }
  public boolean setPrintJobState(PrintJobId printJobId, int state, String error) {
    boolean success = false;

    synchronized (mLock) {
      PrintJobInfo printJob = getPrintJobInfo(printJobId, PrintManager.APP_ID_ANY);
      if (printJob != null) {
        final int oldState = printJob.getState();
        if (oldState == state) {
          return false;
        }

        success = true;

        printJob.setState(state);
        printJob.setStateReason(error);
        printJob.setCancelling(false);

        if (DEBUG_PRINT_JOB_LIFECYCLE) {
          Slog.i(LOG_TAG, "[STATE CHANGED] " + printJob);
        }

        switch (state) {
          case PrintJobInfo.STATE_COMPLETED:
          case PrintJobInfo.STATE_CANCELED:
            mPrintJobs.remove(printJob);
            removePrintJobFileLocked(printJob.getId());
            // $fall-through$

          case PrintJobInfo.STATE_FAILED:
            {
              PrinterId printerId = printJob.getPrinterId();
              if (printerId != null) {
                ComponentName service = printerId.getServiceName();
                if (!hasActivePrintJobsForServiceLocked(service)) {
                  sendOnAllPrintJobsForServiceHandled(service);
                }
              }
            }
            break;

          case PrintJobInfo.STATE_QUEUED:
            {
              sendOnPrintJobQueued(new PrintJobInfo(printJob));
            }
            break;
        }

        if (shouldPersistPrintJob(printJob)) {
          mPersistanceManager.writeStateLocked();
        }

        if (!hasActivePrintJobsLocked()) {
          notifyOnAllPrintJobsHandled();
        }

        Message message =
            mHandlerCaller.obtainMessageO(
                HandlerCallerCallback.MSG_ON_PRINT_JOB_STATE_CHANGED, printJob);
        mHandlerCaller.executeOrSendMessage(message);

        mNotificationController.onUpdateNotifications(mPrintJobs);
      }
    }

    return success;
  }
 private void sendOnAllPrintJobsHandled() {
   Message message =
       mHandlerCaller.obtainMessage(HandlerCallerCallback.MSG_ON_ALL_PRINT_JOBS_HANDLED);
   mHandlerCaller.executeOrSendMessage(message);
 }
 private void sendOnAllPrintJobsForServiceHandled(ComponentName service) {
   Message message =
       mHandlerCaller.obtainMessageO(
           HandlerCallerCallback.MSG_ON_ALL_PRINT_JOBS_FOR_SERIVICE_HANDLED, service);
   mHandlerCaller.executeOrSendMessage(message);
 }
 private void sendOnPrintJobQueued(PrintJobInfo printJob) {
   Message message =
       mHandlerCaller.obtainMessageO(HandlerCallerCallback.MSG_ON_PRINT_JOB_QUEUED, printJob);
   mHandlerCaller.executeOrSendMessage(message);
 }