@Override
 public void onPostDialContinue(String callId, boolean proceed) {
   SomeArgs args = SomeArgs.obtain();
   args.arg1 = callId;
   args.argi1 = proceed ? 1 : 0;
   mHandler.obtainMessage(MSG_ON_POST_DIAL_CONTINUE, args).sendToTarget();
 }
 @Override
 public void onAudioStateChanged(String callId, AudioState audioState) {
   SomeArgs args = SomeArgs.obtain();
   args.arg1 = callId;
   args.arg2 = audioState;
   mHandler.obtainMessage(MSG_ON_AUDIO_STATE_CHANGED, args).sendToTarget();
 }
 @Override
 public void conference(String callId1, String callId2) {
   SomeArgs args = SomeArgs.obtain();
   args.arg1 = callId1;
   args.arg2 = callId2;
   mHandler.obtainMessage(MSG_CONFERENCE, args).sendToTarget();
 }
 @Override
 public void rejectWithMessage(String callId, String message) {
   SomeArgs args = SomeArgs.obtain();
   args.arg1 = callId;
   args.arg2 = message;
   mHandler.obtainMessage(MSG_REJECT_WITH_MESSAGE, args).sendToTarget();
 }
 @Override
 public void answerVideo(String callId, int videoState) {
   SomeArgs args = SomeArgs.obtain();
   args.arg1 = callId;
   args.argi1 = videoState;
   mHandler.obtainMessage(MSG_ANSWER_VIDEO, args).sendToTarget();
 }
 @Override
 public boolean[] supportsCommands(String callingPackage, String[] commands) {
   Message msg =
       mHandlerCaller.obtainMessageIOO(
           MSG_SUPPORTS_COMMANDS,
           0,
           new Caller(callingPackage, Binder.getCallingUid()),
           commands);
   SomeArgs args = mHandlerCaller.sendMessageAndWait(msg);
   if (args != null) {
     boolean[] res = (boolean[]) args.arg1;
     args.recycle();
     return res;
   }
   return new boolean[commands.length];
 }
    @Override
    public void handleMessage(Message msg) {
      switch (msg.what) {
        case MSG_GET_APP_PERMISSIONS:
          {
            SomeArgs args = (SomeArgs) msg.obj;
            String packageName = (String) args.arg1;
            RemoteCallback callback = (RemoteCallback) args.arg2;
            args.recycle();
            List<RuntimePermissionPresentationInfo> permissions = onGetAppPermissions(packageName);
            if (permissions != null && !permissions.isEmpty()) {
              Bundle result = new Bundle();
              result.putParcelableList(RuntimePermissionPresenter.KEY_RESULT, permissions);
              callback.sendResult(result);
            } else {
              callback.sendResult(null);
            }
          }
          break;

        case MSG_GET_APPS_USING_PERMISSIONS:
          {
            RemoteCallback callback = (RemoteCallback) msg.obj;
            final boolean system = msg.arg1 == 1;
            List<ApplicationInfo> apps = onGetAppsUsingPermissions(system);
            if (apps != null && !apps.isEmpty()) {
              Bundle result = new Bundle();
              result.putParcelableList(RuntimePermissionPresenter.KEY_RESULT, apps);
              callback.sendResult(result);
            } else {
              callback.sendResult(null);
            }
          }
          break;
      }
    }
 @Override
 public void createConnection(
     PhoneAccountHandle connectionManagerPhoneAccount,
     String id,
     ConnectionRequest request,
     boolean isIncoming,
     boolean isUnknown) {
   SomeArgs args = SomeArgs.obtain();
   args.arg1 = connectionManagerPhoneAccount;
   args.arg2 = id;
   args.arg3 = request;
   args.argi1 = isIncoming ? 1 : 0;
   args.argi2 = isUnknown ? 1 : 0;
   mHandler.obtainMessage(MSG_CREATE_CONNECTION, args).sendToTarget();
 }
 public void onRectangleOnScreenRequestedLocked(Rect rectangle, boolean immediate) {
   if (DEBUG_RECTANGLE_REQUESTED) {
     Slog.i(LOG_TAG, "Rectangle on screen requested: " + rectangle);
   }
   if (!mMagnifedViewport.isMagnifyingLocked()) {
     return;
   }
   Rect magnifiedRegionBounds = mTempRect2;
   mMagnifedViewport.getMagnifiedFrameInContentCoordsLocked(magnifiedRegionBounds);
   if (magnifiedRegionBounds.contains(rectangle)) {
     return;
   }
   SomeArgs args = SomeArgs.obtain();
   args.argi1 = rectangle.left;
   args.argi2 = rectangle.top;
   args.argi3 = rectangle.right;
   args.argi4 = rectangle.bottom;
   mHandler
       .obtainMessage(MyHandler.MESSAGE_NOTIFY_RECTANGLE_ON_SCREEN_REQUESTED, args)
       .sendToTarget();
 }
 @Override
 public void handleMessage(Message message) {
   switch (message.what) {
     case MESSAGE_NOTIFY_MAGNIFIED_BOUNDS_CHANGED:
       {
         Region bounds = (Region) message.obj;
         try {
           mCallbacks.onMagnifedBoundsChanged(bounds);
         } catch (RemoteException re) {
           /* ignore */
         } finally {
           bounds.recycle();
         }
       }
       break;
     case MESSAGE_NOTIFY_RECTANGLE_ON_SCREEN_REQUESTED:
       {
         SomeArgs args = (SomeArgs) message.obj;
         final int left = args.argi1;
         final int top = args.argi2;
         final int right = args.argi3;
         final int bottom = args.argi4;
         try {
           mCallbacks.onRectangleOnScreenRequested(left, top, right, bottom);
         } catch (RemoteException re) {
           /* ignore */
         } finally {
           args.recycle();
         }
       }
       break;
     case MESSAGE_NOTIFY_USER_CONTEXT_CHANGED:
       {
         try {
           mCallbacks.onUserContextChanged();
         } catch (RemoteException re) {
           /* ignore */
         }
       }
       break;
     case MESSAGE_NOTIFY_ROTATION_CHANGED:
       {
         final int rotation = message.arg1;
         try {
           mCallbacks.onRotationChanged(rotation);
         } catch (RemoteException re) {
           /* ignore */
         }
       }
       break;
     case MESSAGE_SHOW_MAGNIFIED_REGION_BOUNDS_IF_NEEDED:
       {
         synchronized (mWindowManagerService.mWindowMap) {
           if (mMagnifedViewport.isMagnifyingLocked()) {
             mMagnifedViewport.setMagnifiedRegionBorderShownLocked(true, true);
             mWindowManagerService.scheduleAnimationLocked();
           }
         }
       }
       break;
       /// M:[ALPS01397351]Fix system server JE @{
     case MESSAGE_ON_ROTATION_CHANGED:
       {
         synchronized (mWindowManagerService.mWindowMap) {
           mMagnifedViewport.onRotationChangedLocked();
         }
       }
       break;
       /// @}
   }
 }
 @Override
 public void handleMessage(Message msg) {
   switch (msg.what) {
     case MSG_ADD_CONNECTION_SERVICE_ADAPTER:
       mAdapter.addAdapter((IConnectionServiceAdapter) msg.obj);
       onAdapterAttached();
       break;
     case MSG_REMOVE_CONNECTION_SERVICE_ADAPTER:
       mAdapter.removeAdapter((IConnectionServiceAdapter) msg.obj);
       break;
     case MSG_CREATE_CONNECTION:
       {
         SomeArgs args = (SomeArgs) msg.obj;
         try {
           final PhoneAccountHandle connectionManagerPhoneAccount =
               (PhoneAccountHandle) args.arg1;
           final String id = (String) args.arg2;
           final ConnectionRequest request = (ConnectionRequest) args.arg3;
           final boolean isIncoming = args.argi1 == 1;
           final boolean isUnknown = args.argi2 == 1;
           if (!mAreAccountsInitialized) {
             Log.d(this, "Enqueueing pre-init request %s", id);
             mPreInitializationConnectionRequests.add(
                 new Runnable() {
                   @Override
                   public void run() {
                     createConnection(
                         connectionManagerPhoneAccount, id, request, isIncoming, isUnknown);
                   }
                 });
           } else {
             createConnection(
                 connectionManagerPhoneAccount, id, request, isIncoming, isUnknown);
           }
         } finally {
           args.recycle();
         }
         break;
       }
     case MSG_ABORT:
       abort((String) msg.obj);
       break;
     case MSG_ANSWER:
       answer((String) msg.obj);
       break;
     case MSG_ANSWER_VIDEO:
       {
         SomeArgs args = (SomeArgs) msg.obj;
         try {
           String callId = (String) args.arg1;
           int videoState = args.argi1;
           answerVideo(callId, videoState);
         } finally {
           args.recycle();
         }
         break;
       }
     case MSG_REJECT:
       reject((String) msg.obj);
       break;
     case MSG_DISCONNECT:
       disconnect((String) msg.obj);
       break;
     case MSG_HOLD:
       hold((String) msg.obj);
       break;
     case MSG_UNHOLD:
       unhold((String) msg.obj);
       break;
     case MSG_ON_AUDIO_STATE_CHANGED:
       {
         SomeArgs args = (SomeArgs) msg.obj;
         try {
           String callId = (String) args.arg1;
           AudioState audioState = (AudioState) args.arg2;
           onAudioStateChanged(callId, audioState);
         } finally {
           args.recycle();
         }
         break;
       }
     case MSG_PLAY_DTMF_TONE:
       playDtmfTone((String) msg.obj, (char) msg.arg1);
       break;
     case MSG_STOP_DTMF_TONE:
       stopDtmfTone((String) msg.obj);
       break;
     case MSG_CONFERENCE:
       {
         SomeArgs args = (SomeArgs) msg.obj;
         try {
           String callId1 = (String) args.arg1;
           String callId2 = (String) args.arg2;
           conference(callId1, callId2);
         } finally {
           args.recycle();
         }
         break;
       }
     case MSG_SPLIT_FROM_CONFERENCE:
       splitFromConference((String) msg.obj);
       break;
     case MSG_MERGE_CONFERENCE:
       mergeConference((String) msg.obj);
       break;
     case MSG_SWAP_CONFERENCE:
       swapConference((String) msg.obj);
       break;
     case MSG_ON_POST_DIAL_CONTINUE:
       {
         SomeArgs args = (SomeArgs) msg.obj;
         try {
           String callId = (String) args.arg1;
           boolean proceed = (args.argi1 == 1);
           onPostDialContinue(callId, proceed);
         } finally {
           args.recycle();
         }
         break;
       }
     default:
       break;
   }
 }
  public void executeMessage(Message msg) {
    InputMethod inputMethod = mInputMethod.get();
    // Need a valid reference to the inputMethod for everything except a dump.
    if (inputMethod == null && msg.what != DO_DUMP) {
      Log.w(TAG, "Input method reference was null, ignoring message: " + msg.what);
      return;
    }

    switch (msg.what) {
      case DO_DUMP:
        {
          AbstractInputMethodService target = mTarget.get();
          if (target == null) {
            return;
          }
          SomeArgs args = (SomeArgs) msg.obj;
          try {
            target.dump((FileDescriptor) args.arg1, (PrintWriter) args.arg2, (String[]) args.arg3);
          } catch (RuntimeException e) {
            ((PrintWriter) args.arg2).println("Exception: " + e);
          }
          synchronized (args.arg4) {
            ((CountDownLatch) args.arg4).countDown();
          }
          args.recycle();
          return;
        }

      case DO_ATTACH_TOKEN:
        {
          inputMethod.attachToken((IBinder) msg.obj);
          return;
        }
      case DO_SET_INPUT_CONTEXT:
        {
          inputMethod.bindInput((InputBinding) msg.obj);
          return;
        }
      case DO_UNSET_INPUT_CONTEXT:
        inputMethod.unbindInput();
        return;
      case DO_START_INPUT:
        {
          SomeArgs args = (SomeArgs) msg.obj;
          IInputContext inputContext = (IInputContext) args.arg1;
          InputConnection ic =
              inputContext != null ? new InputConnectionWrapper(inputContext) : null;
          EditorInfo info = (EditorInfo) args.arg2;
          info.makeCompatible(mTargetSdkVersion);
          inputMethod.startInput(ic, info);
          args.recycle();
          return;
        }
      case DO_RESTART_INPUT:
        {
          SomeArgs args = (SomeArgs) msg.obj;
          IInputContext inputContext = (IInputContext) args.arg1;
          InputConnection ic =
              inputContext != null ? new InputConnectionWrapper(inputContext) : null;
          EditorInfo info = (EditorInfo) args.arg2;
          info.makeCompatible(mTargetSdkVersion);
          inputMethod.restartInput(ic, info);
          args.recycle();
          return;
        }
      case DO_CREATE_SESSION:
        {
          inputMethod.createSession(
              new InputMethodSessionCallbackWrapper(
                  mCaller.mContext, (IInputMethodCallback) msg.obj));
          return;
        }
      case DO_SET_SESSION_ENABLED:
        inputMethod.setSessionEnabled((InputMethodSession) msg.obj, msg.arg1 != 0);
        return;
      case DO_REVOKE_SESSION:
        inputMethod.revokeSession((InputMethodSession) msg.obj);
        return;
      case DO_SHOW_SOFT_INPUT:
        inputMethod.showSoftInput(msg.arg1, (ResultReceiver) msg.obj);
        return;
      case DO_HIDE_SOFT_INPUT:
        inputMethod.hideSoftInput(msg.arg1, (ResultReceiver) msg.obj);
        return;
      case DO_CHANGE_INPUTMETHOD_SUBTYPE:
        inputMethod.changeInputMethodSubtype((InputMethodSubtype) msg.obj);
        return;
    }
    Log.w(TAG, "Unhandled message code: " + msg.what);
  }
 @Override
 public void executeMessage(Message msg) {
   SomeArgs args;
   switch (msg.what) {
     case MSG_START_CONFIRMATION:
       args = (SomeArgs) msg.obj;
       if (DEBUG)
         Log.d(
             TAG,
             "onConfirm: req="
                 + ((Request) args.arg2).mInterface
                 + " prompt="
                 + args.arg3
                 + " extras="
                 + args.arg4);
       onConfirm(
           (Caller) args.arg1,
           (Request) args.arg2,
           (CharSequence) args.arg3,
           (Bundle) args.arg4);
       break;
     case MSG_START_COMPLETE_VOICE:
       args = (SomeArgs) msg.obj;
       if (DEBUG)
         Log.d(
             TAG,
             "onCompleteVoice: req="
                 + ((Request) args.arg2).mInterface
                 + " message="
                 + args.arg3
                 + " extras="
                 + args.arg4);
       onCompleteVoice(
           (Caller) args.arg1,
           (Request) args.arg2,
           (CharSequence) args.arg3,
           (Bundle) args.arg4);
       break;
     case MSG_START_ABORT_VOICE:
       args = (SomeArgs) msg.obj;
       if (DEBUG)
         Log.d(
             TAG,
             "onAbortVoice: req="
                 + ((Request) args.arg2).mInterface
                 + " message="
                 + args.arg3
                 + " extras="
                 + args.arg4);
       onAbortVoice(
           (Caller) args.arg1,
           (Request) args.arg2,
           (CharSequence) args.arg3,
           (Bundle) args.arg4);
       break;
     case MSG_START_COMMAND:
       args = (SomeArgs) msg.obj;
       if (DEBUG)
         Log.d(
             TAG,
             "onCommand: req="
                 + ((Request) args.arg2).mInterface
                 + " command="
                 + args.arg3
                 + " extras="
                 + args.arg4);
       onCommand(
           (Caller) args.arg1, (Request) args.arg2, (String) args.arg3, (Bundle) args.arg4);
       break;
     case MSG_SUPPORTS_COMMANDS:
       args = (SomeArgs) msg.obj;
       if (DEBUG) Log.d(TAG, "onGetSupportedCommands: cmds=" + args.arg2);
       args.arg1 = onGetSupportedCommands((Caller) args.arg1, (String[]) args.arg2);
       break;
     case MSG_CANCEL:
       args = (SomeArgs) msg.obj;
       if (DEBUG) Log.d(TAG, "onCancel: req=" + ((Request) args.arg1).mInterface);
       onCancel((Request) args.arg1);
       break;
     case MSG_TASK_STARTED:
       if (DEBUG) Log.d(TAG, "onTaskStarted: intent=" + msg.obj + " taskId=" + msg.arg1);
       onTaskStarted((Intent) msg.obj, msg.arg1);
       break;
     case MSG_TASK_FINISHED:
       if (DEBUG) Log.d(TAG, "onTaskFinished: intent=" + msg.obj + " taskId=" + msg.arg1);
       onTaskFinished((Intent) msg.obj, msg.arg1);
       break;
     case MSG_CLOSE_SYSTEM_DIALOGS:
       if (DEBUG) Log.d(TAG, "onCloseSystemDialogs");
       onCloseSystemDialogs();
       break;
     case MSG_DESTROY:
       if (DEBUG) Log.d(TAG, "doDestroy");
       doDestroy();
       break;
   }
 }