title: Android AIDL oneway method blocked when trying asynchronous RPC using remote service
body: <p>I was trying to make asynchronous RPC using keyword <strong>oneway</strong> in .aidl file. My test project contains 3 parts:</p>
  
  <ul>
  <li>AIDLAsynchronousClientActivity.java </li>
  <li>AIDLAsynchronousRPCService.java</li>
  <li>IAsynchronousInterface.aidl</li>
  </ul>
  
  <p>The service is in <strong>a remote process</strong> and registered in AndroidManifest.xml as follow:</p>
  
  <pre><code>&lt;service
          android:name=".threading.AIDLAsynchronousRPCService"
          android:enabled="true"
          android:exported="true"
          android:process=":test"&gt;
          &lt;intent-filter&gt;
              &lt;action android:name="hahaha.hehe.heihei2" /&gt;
          &lt;/intent-filter&gt;
  &lt;/service&gt; 
  </code></pre>
  
  <p>IAsynchronousInterface.aidl contains keyword <strong>oneway</strong>:</p>
  
  <pre><code>interface IAsynchronousInterface {
      /* hide basic methods */ 
  
      oneway void getThreadNameBlocking();
  
      oneway void getThreadNameUnblock();
  }
  </code></pre>
  
  <p>The implementation of the methods above in AIDLAsynchronousRPCService.java:</p>
  
  <pre><code>    IAsynchronousInterface.Stub mBinder = new IAsynchronousInterface.Stub() {
          CountDownLatch mLatch = new CountDownLatch(1);
  
          /* hide basic methods */ 
  
          @Override
          public void getThreadNameBlocking() throws RemoteException {
              Log.d(TAG, "*************blocking...");
              Log.d(TAG, Thread.currentThread().getName());
  
              try {
                  mLatch.await();
              } catch (InterruptedException e) {
                  e.printStackTrace();
              }
  
              Log.d(TAG, "*************blocked");
          }
  
          @Override
          public void getThreadNameUnblock() throws RemoteException {
              Log.d(TAG, "#############unblocking...");
              Log.d(TAG, Thread.currentThread().getName());
  
              mLatch.countDown();
  
              Log.d(TAG, "############unblocked");
          }
      };
  </code></pre>
  
  <p>And the activity will do:</p>
  
  <ol>
  <li>bind the service(AIDLAsynchronousRPCService), get the IBinder returned when service connected</li>
  <li>call <strong><em>getThreadNameBlocking()</em></strong> above</li>
  <li>call <strong><em>getThreadNameUnblock()</em></strong> above</li>
  <li>restart from step 2(loop)</li>
  </ol>
  
  <p>Then the application executing as follow:</p>
  
  <ol>
  <li>the RPC call loop worked well in Activity, no blocks</li>
  <li>the service was blocked, nothing was executing after calling <strong><em>getThreadNameBlocking()</em></strong>  </li>
  </ol>
  
  <p>I thought the service should not block cause I commented the <em>mLatch.await();</em>, and the log was printed as follow:</p>
  
  <pre><code>10-11 23:24:30.524 1933-1950/com.example.yu.testapplication:test D/RPCService: *************blocking...
  10-11 23:24:30.524 1933-1950/com.example.yu.testapplication:test D/RPCService: Binder_1
  10-11 23:24:30.524 1933-1950/com.example.yu.testapplication:test D/RPCService: *************blocked
  10-11 23:24:31.024 1933-1951/com.example.yu.testapplication:test D/RPCService: #############unblocking...
  10-11 23:24:31.024 1933-1951/com.example.yu.testapplication:test D/RPCService: Binder_2
  10-11 23:24:31.024 1933-1951/com.example.yu.testapplication:test D/RPCService: ############unblocked
  10-11 23:24:31.024 1933-1951/com.example.yu.testapplication:test D/RPCService: *************blocking...
  10-11 23:24:31.024 1933-1951/com.example.yu.testapplication:test D/RPCService: Binder_2
  10-11 23:24:31.024 1933-1951/com.example.yu.testapplication:test D/RPCService: *************blocked
  10-11 23:24:31.524 1933-1950/com.example.yu.testapplication:test D/RPCService: #############unblocking...
  10-11 23:24:31.524 1933-1950/com.example.yu.testapplication:test D/RPCService: Binder_1
  10-11 23:24:31.524 1933-1950/com.example.yu.testapplication:test D/RPCService: ############unblocked
  10-11 23:24:31.524 1933-1950/com.example.yu.testapplication:test D/RPCService: *************blocking...
  10-11 23:24:31.524 1933-1950/com.example.yu.testapplication:test D/RPCService: Binder_1
  10-11 23:24:31.524 1933-1950/com.example.yu.testapplication:test D/RPCService: *************blocked
  10-11 23:24:32.024 1933-1951/com.example.yu.testapplication:test D/RPCService: #############unblocking...
  10-11 23:24:32.024 1933-1951/com.example.yu.testapplication:test D/RPCService: Binder_2
  10-11 23:24:32.024 1933-1951/com.example.yu.testapplication:test D/RPCService: ############unblocked
  10-11 23:24:32.024 1933-1951/com.example.yu.testapplication:test D/RPCService: *************blocking...
  10-11 23:24:32.024 1933-1951/com.example.yu.testapplication:test D/RPCService: Binder_2
  10-11 23:24:32.024 1933-1951/com.example.yu.testapplication:test D/RPCService: *************blocked
  10-11 23:24:32.525 1933-1950/com.example.yu.testapplication:test D/RPCService: #############unblocking...
  10-11 23:24:32.525 1933-1950/com.example.yu.testapplication:test D/RPCService: Binder_1
  10-11 23:24:32.525 1933-1950/com.example.yu.testapplication:test D/RPCService: ############unblocked
  10-11 23:24:32.525 1933-1950/com.example.yu.testapplication:test D/RPCService: *************blocking...
  10-11 23:24:32.525 1933-1950/com.example.yu.testapplication:test D/RPCService: Binder_1
  10-11 23:24:32.525 1933-1950/com.example.yu.testapplication:test D/RPCService: *************blocked
  10-11 23:24:33.026 1933-1951/com.example.yu.testapplication:test D/RPCService: #############unblocking...
  10-11 23:24:33.026 1933-1951/com.example.yu.testapplication:test D/RPCService: Binder_2
  10-11 23:24:33.026 1933-1951/com.example.yu.testapplication:test D/RPCService: ############unblocked
  </code></pre>
  
  <p>There were 2 binder threads working in the remote process. So I thought the remote process call would be managed by Android System as above: <strong>RPC calls would be on different binder threads</strong>. But the fact was the blocking call blocked the whole process. I am confused about and willing to know the mechanism behind this kind of RPC call in Android.</p>