Data flow analysis of phone calls in Android

  • 2020-05-07 20:27:56
  • OfStack

1. The starting point of all process starts, press the dial key after dialing code in this step in/android sourcecode/packages/Contacts/src/com/android/contacts/directory TwelveKeyDialer. java file, the code is as follows:
 
dialButtonPressed() { 
......... 
final String number = mDigits.getText().toString(); 
startActivity(newDialNumberIntent(number)); 
mDigits.getText().clear(); 
finish(); 
} 

The newDialNumberIntent() method in code is defined as :
 
private Intent newDialNumberIntent(String number) { 
final Intent intent = new Intent(Intent.ACTION_CALL_PRIVILEGED, Uri.fromParts("tel", number, null)); 
............. 
} 

It can be seen from the definition of newDialNumberIntent that when the dial key is pressed, TwelveKeyDial will launch a specific component. The ACTION of this component is ACTION_CALL_PRIVILEGED. After searching, the component launched by ACTION is a file of the following: /android sourcecode/packeges/Phone/. PrivilegedOutgoingCallBroadcast, but we to/android sourcecode/packeges/Phone src /... The file cannot be found because it is marked AndroidMenifest.xml with something special :
< activity-alias / > , this tag means that this Activity is the alias of another Activity. The real Activity is marked with "android:targetActivity = OutgoingCallBroadcast" in the tag, so the real "identity" of PrivilegedOutgoingCallBroadcast initiated by "ACTION_CALL_PRIVILEGED" is "OutgoingCallBroadcast".

2. At this time, the data of the phone has been transferred to OutgoingCallBroadcast.java.
In the onCreate() method of OutgoingCallBroadcast.java:
 
<PRE class=java name="code">protected void onCreate(Bundle icicle) { 
....... 
Intent intent = getIntent(); 
........ 
String action = intent.getAction(); 
....... 
final boolean emergencyNum = (number != null) && PhoneNumUtils.isEmergencyNumber(number);// Determine if the number is an emergency number  
....... 
if (Intent.ACTION_CALL_PRIVILEGED.equals(action))  {  
action = emergencyNum ? Intent.ACTION_CALL_EMERGENCY : Intent.ACTION_CALL; 
intent.setAction(action); 
} 
....... 
intent.setClass(this, InCallScreen.class); 
startActivity(intent); 
}</PRE><P></P> 
<PRE></PRE> 
 In this method, determine if received ACTION Is" ACTION_CALL_PRIVILEGED ", then convert according to whether the number entered is an emergency number. If it is an emergency number, then ACTION  =  Intent.ACTION_CALL_EMERGENCY, Otherwise, ACTION  =  Intent.ACTION_CALL, And start the transformation Activity  : InCallScreen.java 
<P></P> 
<P>3. InCallScreen.java Still in the catalog /packeges/Phone/src/com/android/phone Under. </P> 
<P>InCallScreen the onCreate In the call initInCallScreen Initialize the call interface and call registerForPhoneStates Register phone status monitor .<BR> 
</P> 
<P> in onNewIntent() Among the methods: </P> 
<P><PRE class=java name="code">protected void onNewIntent(Intent intent) { 
.......... 
String action = intent.getAction(); 
.......... 
else if (action.equals(Intent.ACTION_CALL) || action.equals(Intent.ACTION_CALL_EMERGENCY)) { 
.......... 
InCallInitStatus status = placeCall(intent); 
} 
} 
//placeCall 
private InCallInitStatus placeCall(Intent intent) { 
.............. 
int callStatus = PhoneUtils.placeCall(........); 
}</PRE>InCallScreen.java In the placeCall The method call PhoneUtils.java Of the file placeCall Methods. <BR> 
<P></P> 
<P>4. PhoneUtils.java Still in the catalog /packeges/Phone/src/com/android/phone Under. </P> 
<P><PRE class=java name="code">public static int placeCall(...) { 
Connection connection; 
connection = PhoneApp.getInstance().mCM.dial(phone, numberToDial); 
}</PRE> Keep tracking, in PhoneApp.java Found in, mCM is CallManager.java Of the class 1 Objects, and CallManager.java It is to belong to frameworks Layer, so at this point the data stream has entered frameworks.<P></P> 
<P>5.  Enter the /frameworks/base/telephony/java/com/android/internal/telephony Directory. </P> 
<P> in CallManager.java the dial() In the method, there are: </P> 
<P><PRE class=java name="code"><SPAN style="BACKGROUND-COLOR: rgb(255,255,255); FONT-FAMILY: Arial, Verdana, sans-serif; WHITE-SPACE: normal"></SPAN><PRE class=java name="code">public Connection dial(Phone phone, String dialNumber) throws CallStateException { 
Phone basePhone = getPhoneBase(phone); 
Connection result; 
<SPAN style="COLOR: #3333ff">result = basePhone.dial(dialString);</SPAN> 
........ 
} 
private static Phone getPhoneBase(Phone phone) { 
if (phone instanceof PhoneProxy) { 
<SPAN style="COLOR: #ff0000">return phone.getForegroundCall().getPhone();</SPAN> 
} 
return phone; 
}</PRE><P></P> 
<PRE></PRE> 
<PRE class=java name="code"><SPAN style="BACKGROUND-COLOR: rgb(255,255,255); FONT-FAMILY: Arial, Verdana, sans-serif; WHITE-SPACE: normal"> Follow up and find: </SPAN></PRE><PRE class=java name="code"><SPAN style="BACKGROUND-COLOR: rgb(255,255,255); FONT-FAMILY: Arial, Verdana, sans-serif; WHITE-SPACE: normal">PhoneBase.java The abstract class implements the interface Phone.java, while GSMPhone.java It also implements abstract classes PhoneBase, so :</SPAN></PRE> 
<P></P> 
<P> In the above code: phone.getForegroundCall() Actual equivalent GSMPhone The object executes getForegroundCall() Methods. </P> 
<P>6.  Continue to track GSMPhone.java, This class is located in the /frameworks/base/telephony/java/com/android/internal/telephony/gsm/ Under. </P> 
<P><PRE class=java name="code">GSMPhone.java :  
GsmCallTracker mCT; 
public GsmCall getForegroundCall() { 
return mCT.foregroundCall; 
}</PRE> It can be seen that getForegroundCall() Function continues to call GsmCallTracker.java the foregroundCall Properties. <P></P> 
<P>7.GsmCallTracker.java Located in the /frameworks/base/telephony/java/com/android/internal/telephony/gsm/ Under the .</P> 
<P><PRE class=cpp name="code">GsmCallTracker.java: 
GSMCall foregroundCall = new GSMCall(this);</PRE><P></P> 
<P> Open the GSMCall.java, find getPhone() Methods: </P> 
<P><PRE class=java name="code">GSMCallTracker owner; 
public Phone getPhone() { 
return owner.phone; 
}</PRE><P></P> 
<P> And in the GSMCallTracker.java Has the following statement: </P> 
<P><PRE class=cpp name="code">GSMPhone phone;</PRE><P></P> 
<P><SPAN style="COLOR: #ff0000"> So here we are 1 Conclusion: no. 5 Part of the code marked red is what is returned GSMPhone The object, </SPAN><SPAN style="COLOR: #3333ff"> Into the 1 The step is going to be number one 5 Part of the code marked in blue is called GSMPhone The object's dial Methods. </SPAN></P> 
<P>8.  in GSMPhone.java In: </P> 
<P><PRE class=java name="code">GSMCallTracker mCT; 
public Connection dial(String dialString) throws CallStateException { 
return dial(dialString, null); 
} 
public Connection dial(String dialString, UUSInfo uusInfo) throws CallStateException { 
....... 
mCT.dial(.......); 
}</PRE><P></P> 
<P> Continue to call GSMCallTracker.java In the dial() Methods: </P> 
<P><PRE class=cpp name="code">GSMCallTracker.java :  
GSMCallTracker(GSMPhone phone) { 
cm = phone.mCM; 
} 
Connection dial(String dialString, int clirMode, UUSInfo uusInfo) { 
<SPAN style="COLOR: #ff0000">cm.dial(........);</SPAN> 
}</PRE> tracking mCM, found  :<P></P> 
<P>public CommandsInterface mCM;</P> 
<P> so GSMCallTracker hold CommandsInterface Objects, that is, RIL.Java Class object, so "cm.dial(....)" That is called RIL The class object dial() Methods. </P> 
<P>9. RIL.java</P> 
<P>BOSS Appear. </P> 
<P>RIL Object is responsible for following the client's call request 1 The specified format is sent to "rild"socket, At this point, the request process is complete. </P> 
</PRE> 

Related articles: