title: Why ITelephony.aidl works?
body: <p>I saw some SO posts which discussed about how to end a phone call programmtically, for example, <a href="https://stackoverflow.com/questions/18065144/end-call-in-android-programatically">this one</a>. Yep, people focus on the result but no one actually explain the reason <strong>why it works?</strong></p>
  
  <p>I tried the code, it works well. But I would like to know more details about what is going on underneath? Why by creating the <strong>ITelephony.aidl</strong> , the android hidden internal <code>ITelephony</code> interface is exposed in our project? How does ourself created <strong>ITelephony.aidl</strong> &amp; the automatically generated java (/gen/ITelephony.java) <strong>link to</strong> android's <code>ITelephony</code> interface? Is it only because of the name matching (package name &amp; aidl file name)?</p>
  
  <pre><code>TelephonyManager tm = (TelephonyManager) context
                  .getSystemService(Context.TELEPHONY_SERVICE);
  
  Class c = Class.forName(tm.getClass().getName());
  Method m = c.getDeclaredMethod("getITelephony");
  m.setAccessible(true);
  
  //Why does the android internal ITelephony interface is exposed after created the ITelephony.aidl?
  com.android.internal.telephony.ITelephony telephonyService = (ITelephony) m.invoke(tm);
  telephonyService.endCall(); 
  </code></pre>