From d109630e74259ddd0c9a5163c39503508307f5a3 Mon Sep 17 00:00:00 2001 From: Daniele Gobbetti Date: Wed, 16 May 2018 18:56:36 +0200 Subject: [PATCH] Use TelephonyManager getCallState() instead of the provided extras According to the documentation the current call state might be not correctly contained in the extra, and using getCallState() is the right thing to do Might help for #799 (and #756) --- .../externalevents/PhoneCallReceiver.java | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/PhoneCallReceiver.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/PhoneCallReceiver.java index 0cbb0a399..fb5dfdd6f 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/PhoneCallReceiver.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/PhoneCallReceiver.java @@ -18,6 +18,7 @@ package nodomain.freeyourgadget.gadgetbridge.externalevents; import android.app.NotificationManager; import android.app.NotificationManager.Policy; +import android.app.Service; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; @@ -35,19 +36,12 @@ public class PhoneCallReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { + TelephonyManager tm = (TelephonyManager) context.getSystemService(Service.TELEPHONY_SERVICE); if (intent.getAction().equals("android.intent.action.NEW_OUTGOING_CALL")) { mSavedNumber = intent.getExtras().getString("android.intent.extra.PHONE_NUMBER"); } else { - String stateStr = intent.getExtras().getString(TelephonyManager.EXTRA_STATE); String number = intent.getExtras().getString(TelephonyManager.EXTRA_INCOMING_NUMBER); - int state = 0; - if (TelephonyManager.EXTRA_STATE_IDLE.equals(stateStr)) { - state = TelephonyManager.CALL_STATE_IDLE; - } else if (TelephonyManager.EXTRA_STATE_OFFHOOK.equals(stateStr)) { - state = TelephonyManager.CALL_STATE_OFFHOOK; - } else if (TelephonyManager.EXTRA_STATE_RINGING.equals(stateStr)) { - state = TelephonyManager.CALL_STATE_RINGING; - } + int state = tm.getCallState(); onCallStateChanged(context, state, number); } }