0

I have a call recording app that reacts to call state changes from a dedicated BroadcastReceiver.
BroadcastReceiver is registered correctly in my manifest, along with the PROCESS_OUTGOING_CALLS and READ_PHONE_STATE permissions.

My issue is that for some reason, in some of the calls I get the CALL_STATE_OFFHOOK state broadcast several minutes after call has already ended.
It seems that the broadcasts are somehow stuck, and then triggered after a while. The 'CALL_STATE_IDLE' subsequent broadcast is received approximately after X time since CALL_STATE_OFFHOOK broadcast, where X is the time the actual call took.
My logs verify that previous onReceive calls are not hanging the process or the BroadcastReceiver.

What can be the cause for such behavior?

UPDATE:
I found that this occurs after I turn my Wi-Fi on or off and start a call relatively close to Wi-Fi change.
Is this the cause for the issue or a symptom of the actual issue?

Oren
  • 937
  • 1
  • 10
  • 34

2 Answers2

0

In Android System, broadcast are processed internally.

Sometimes, due to system loading/ restart/ high runtime, the broadcast receiver gets time to receive some intent

Workaround is, to add Flag FLAG_RECEIVER_FOREGROUND to intent sending broadcast

intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);

This will speed up the broadcast delivery much than before in problem scenario

Kushal
  • 8,100
  • 9
  • 63
  • 82
  • The broadcasts are sent from Android TeleohonyManager, not by me. Is this still applicable? Thanks – Oren Mar 19 '15 at 13:25
  • No then it is not applicable. I thought you are sending this broadcast and receiving at some other place. But in this problem, i think Google updates may have solved this problem, we need to wait for next release – Kushal Mar 19 '15 at 13:29
  • I found that this occurs after I turn my Wi-Fi on or off and start a call relatively close to Wi-Fi change. Is this the cause for the issue or a symptom of the actual issue? – Oren Mar 22 '15 at 11:09
0

It turned out to be a bug in the Broadcast sending by android (or alternatively some malfunctional receiver). Investigating log cat showed that some system receivers did get broadcasts on time while others (prior to mine) received it after a long time.
This happens frequently whenever Wi-Fi state changes during call start.

What I did was creating an ITelephony proxy (credit to End call in android programmatically) and monitor its state.


Thanks for the helpers :)

Community
  • 1
  • 1
Oren
  • 937
  • 1
  • 10
  • 34