Make sure caller verification is done inside a lock

This caller verification needs to be done in an atomic manner.  There
is a possible race condition in the following code.

  @BinderThread
  public boolean doSomething() {
      if (!calledFromValidUser()) {
          return false;
      }
      // possible race condition here.
      synchronized(mMethodMap) {
          // actual operations
      }
  }

Insted, we should check the caller after taking a lock.

  @BinderThread
  public boolean doSomething() {
      synchronized(mMethodMap) {
          if (!calledFromValidUserLocked()) {
              return false;
          }

          // actual operations
      }
  }

Bug: 34886274
Test: atest CtsInputMethodTestCases CtsInputMethodServiceHostTestCases
Change-Id: I02df0307ce2aecc77de8fb2afaa39e5ecf8f3fe2
1 file changed