From 753aa1063e431fca6445659c6308812a7227bd3d Mon Sep 17 00:00:00 2001 From: Tyler Gunn Date: Thu, 23 Apr 2020 10:16:26 -0700 Subject: [PATCH] Fix createLaunchEmergencyDialerIntent API behavior when Telecom unavailable. The API contract for createLaunchEmergencyDialerIntent indicates that the return value is @NonNull, however the code clearly can return a null value if either: 1. Telecom is unavailable. 2. There is a remote exception. Since the API just returns a new ACTION_EMERGENCY_DIAL intent with the package name of the emergency dialer (from Telecom string resources), we can provide a reasonable fallback behavior by just returning a new ACTION_EMERGENCY_DIAL intent with no targeted package. The system will still launch the emergency dialer in this case, but if there is a scenario where multiple emergency dialers are installed on a device, the AOSP one may get launched instead. This is, however, better than there being NO emergency dialer launched. Test: Comment out call to Telecom service and verify the AOSP emergency dialer still launches. Fixes: 152187752 Change-Id: I06f8a5bebace5b22822f7bb714e14915126b904f --- telecomm/java/android/telecom/TelecomManager.java | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/telecomm/java/android/telecom/TelecomManager.java b/telecomm/java/android/telecom/TelecomManager.java index b974c567008f6..0983db6d9663c 100644 --- a/telecomm/java/android/telecom/TelecomManager.java +++ b/telecomm/java/android/telecom/TelecomManager.java @@ -2218,15 +2218,23 @@ public class TelecomManager { @NonNull public Intent createLaunchEmergencyDialerIntent(@Nullable String number) { ITelecomService service = getTelecomService(); - Intent result = null; if (service != null) { try { - result = service.createLaunchEmergencyDialerIntent(number); + return service.createLaunchEmergencyDialerIntent(number); } catch (RemoteException e) { Log.e(TAG, "Error createLaunchEmergencyDialerIntent", e); } + } else { + Log.w(TAG, "createLaunchEmergencyDialerIntent - Telecom service not available."); } - return result; + + // Telecom service knows the package name of the expected emergency dialer package; if it + // is not available, then fallback to not targeting a specific package. + Intent intent = new Intent(Intent.ACTION_DIAL_EMERGENCY); + if (!TextUtils.isEmpty(number) && TextUtils.isDigitsOnly(number)) { + intent.setData(Uri.fromParts(PhoneAccount.SCHEME_TEL, number, null)); + } + return intent; } /**