diff --git a/telecomm/java/android/telecom/TelecomManager.java b/telecomm/java/android/telecom/TelecomManager.java index 1f5be6e4fedee..c69a17c04206a 100644 --- a/telecomm/java/android/telecom/TelecomManager.java +++ b/telecomm/java/android/telecom/TelecomManager.java @@ -20,6 +20,7 @@ import android.content.Context; import android.os.Bundle; import android.os.RemoteException; import android.os.ServiceManager; +import android.telephony.TelephonyManager; import android.util.Log; import com.android.internal.telecom.ITelecomService; @@ -661,11 +662,35 @@ public class TelecomManager { return getTelecomService().isInCall(); } } catch (RemoteException e) { - Log.e(TAG, "RemoteException attempting to get default phone app.", e); + Log.e(TAG, "RemoteException calling isInCall().", e); } return false; } + /** + * Returns one of the following constants that represents the current state of Telecom: + * + * {@link TelephonyManager#CALL_STATE_RINGING} + * {@link TelephonyManager#CALL_STATE_OFFHOOK} + * {@link TelephonyManager#CALL_STATE_IDLE} + * + *

+ * Requires permission: {@link android.Manifest.permission#READ_PHONE_STATE} + *

+ * @hide + */ + @SystemApi + public int getCallState() { + try { + if (isServiceConnected()) { + return getTelecomService().getCallState(); + } + } catch (RemoteException e) { + Log.d(TAG, "RemoteException calling getCallState().", e); + } + return TelephonyManager.CALL_STATE_IDLE; + } + /** * Returns whether there currently exists is a ringing incoming-call. * diff --git a/telecomm/java/com/android/internal/telecom/ITelecomService.aidl b/telecomm/java/com/android/internal/telecom/ITelecomService.aidl index 4edce534f3474..4875cc3fd6608 100644 --- a/telecomm/java/com/android/internal/telecom/ITelecomService.aidl +++ b/telecomm/java/com/android/internal/telecom/ITelecomService.aidl @@ -138,6 +138,11 @@ interface ITelecomService { */ boolean isRinging(); + /** + * @see TelecomServiceImpl#getCallState + */ + int getCallState(); + /** * @see TelecomServiceImpl#endCall */ diff --git a/telephony/java/android/telephony/TelephonyManager.java b/telephony/java/android/telephony/TelephonyManager.java index 6e3325bf6ef14..34b1454158d9f 100644 --- a/telephony/java/android/telephony/TelephonyManager.java +++ b/telephony/java/android/telephony/TelephonyManager.java @@ -2045,7 +2045,11 @@ public class TelephonyManager { * Returns a constant indicating the call state (cellular) on the device. */ public int getCallState() { - return getCallState(getDefaultSubscription()); + try { + return getTelecomService().getCallState(); + } catch (RemoteException | NullPointerException e) { + return CALL_STATE_IDLE; + } } /** @@ -2142,7 +2146,7 @@ public class TelephonyManager { return ITelephony.Stub.asInterface(ServiceManager.getService(Context.TELEPHONY_SERVICE)); } - private ITelecomService getTelecommService() { + private ITelecomService getTelecomService() { return ITelecomService.Stub.asInterface(ServiceManager.getService(Context.TELECOM_SERVICE)); } @@ -3132,7 +3136,7 @@ public class TelephonyManager { @SystemApi public void silenceRinger() { try { - getTelecommService().silenceRinger(); + getTelecomService().silenceRinger(); } catch (RemoteException e) { Log.e(TAG, "Error calling ITelecomService#silenceRinger", e); }