title: Context.checkCallingPermission checking always fails?
body: <p>I'm encountering such a scenario in Android.
  App <code>A</code> has permission <code>PERM</code> to get some information. Instead of directly getting this information, it sends an intent to one BroadCastReceiver inside App <code>B</code> (of course <code>B</code> has <code>PERM</code>). In order to ensure all such apps like <code>A</code> has the permission, I use a context.checkCallingPermission (with the help of <a href="https://stackoverflow.com/a/8522090/528929">this answer</a>).</p>
  
  <p>However it always fails.</p>
  
  <pre><code>public void onReceive(Context context, Intent intent) {
      String info;
      String perm = Manifest.permission.READ_PHONE_STATE;
      Log.i(TAG, "callPid="+ Binder.getCallingPid()+" myPid="+ Process.myPid()); /// SAME PID
      if (context.checkCallingPermission(perm) != PackageManager.PERMISSION_GRANTED) {
          Log.i(TAG, "not granted " + perm);
          info = "denied perm " + perm;
      } else {
          Log.i(TAG, perm + " already granted");
          info = dumpDeviceInfoImpl(context);
      }
  }
  </code></pre>
  
  <p>Specially, the comment line always return SAME pid (<code>B</code>'s), when I send intent from <code>A</code>. I can confirm <code>A</code> and <code>B</code> have different PIDs.</p>
  
  <p><strong>update</strong></p>
  
  <p>Previously I was thinking it is due to <code>BroadCastReceiver</code>, so I tried to <code>startActivity</code> from <code>A</code> and then start an activity in <code>B</code>. Once again, during <code>checkCallingPermission</code>, it fails again. Surprisingly, still returning the SAME pid.</p>
  
  <p>So what's the correct way to use <code>checkCallingPermission</code>?</p>