@@ -22,20 +22,13 @@ public abstract class PhoneCallReceiver extends BroadcastReceiver {
2222
2323 @ Override
2424 public void onReceive (Context context , Intent intent ) {
25-
2625 //We listen to two intents. The new outgoing call only tells us of an outgoing call. We use it to get the number.
2726 if (intent .getAction ().equals (CallRecordReceiver .ACTION_OUT )) {
28-
2927 savedNumber = intent .getExtras ().getString (CallRecordReceiver .EXTRA_PHONE_NUMBER );
30-
3128 } else {
32-
3329 String stateStr = intent .getExtras ().getString (TelephonyManager .EXTRA_STATE );
34-
3530 String number = intent .getExtras ().getString (TelephonyManager .EXTRA_INCOMING_NUMBER );
36-
3731 savedNumber = number ;
38-
3932 int state = 0 ;
4033
4134 if (stateStr .equals (TelephonyManager .EXTRA_STATE_IDLE )) {
@@ -45,8 +38,6 @@ public void onReceive(Context context, Intent intent) {
4538 } else if (stateStr .equals (TelephonyManager .EXTRA_STATE_RINGING )) {
4639 state = TelephonyManager .CALL_STATE_RINGING ;
4740 }
48-
49-
5041 onCallStateChanged (context , state , number );
5142 }
5243 }
@@ -69,61 +60,45 @@ public void onReceive(Context context, Intent intent) {
6960 //Incoming call- goes from IDLE to RINGING when it rings, to OFFHOOK when it's answered, to IDLE when its hung up
7061 //Outgoing call- goes from IDLE to OFFHOOK when it dials out, to IDLE when hung up
7162 public void onCallStateChanged (Context context , int state , String number ) {
72-
7363 if (lastState == state ) {
7464 //No change, debounce extras
7565 return ;
7666 }
7767
7868 switch (state ) {
7969 case TelephonyManager .CALL_STATE_RINGING :
80-
8170 isIncoming = true ;
8271 callStartTime = new Date ();
8372 savedNumber = number ;
8473
8574 onIncomingCallReceived (context , number , callStartTime );
86-
8775 break ;
8876 case TelephonyManager .CALL_STATE_OFFHOOK :
8977 //Transition of ringing->offhook are pickups of incoming calls. Nothing done on them
9078 if (lastState != TelephonyManager .CALL_STATE_RINGING ) {
91-
9279 isIncoming = false ;
9380 callStartTime = new Date ();
9481
9582 onOutgoingCallStarted (context , savedNumber , callStartTime );
96-
9783 } else {
98-
9984 isIncoming = true ;
10085 callStartTime = new Date ();
10186
10287 onIncomingCallAnswered (context , savedNumber , callStartTime );
103-
10488 }
105-
10689 break ;
10790 case TelephonyManager .CALL_STATE_IDLE :
108-
10991 //Went to idle- this is the end of a call. What type depends on previous state(s)
11092 if (lastState == TelephonyManager .CALL_STATE_RINGING ) {
11193 //Ring but no pickup- a miss
112-
11394 onMissedCall (context , savedNumber , callStartTime );
114-
11595 } else if (isIncoming ) {
116-
11796 onIncomingCallEnded (context , savedNumber , callStartTime , new Date ());
118-
11997 } else {
120-
12198 onOutgoingCallEnded (context , savedNumber , callStartTime , new Date ());
122-
12399 }
124100 break ;
125101 }
126-
127102 lastState = state ;
128103 }
129104}
0 commit comments