diff options
author | Tyler Gunn <tgunn@google.com> | 2020-04-23 10:16:26 -0700 |
---|---|---|
committer | Tyler Gunn <tgunn@google.com> | 2020-08-05 13:37:27 -0700 |
commit | 893a602e61ebcd85748a4d74b71e055d5c4ed81a (patch) | |
tree | 2963656ce7ccc587f35f49a7dd62fd6d7c70d526 | |
parent | 9255edfa7d63e3708b91695d10d2bd65b38d7d8d (diff) |
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.
Bug: 152187752
Fixes: 155097434
Merged-In: I1665d456dace8e41cc035e792f319d98dd07219c
Change-Id: I06f8a5bebace5b22822f7bb714e14915126b904f
-rw-r--r-- | telecomm/java/android/telecom/TelecomManager.java | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/telecomm/java/android/telecom/TelecomManager.java b/telecomm/java/android/telecom/TelecomManager.java index 15b26dcfabbe..08f31a9ea9eb 100644 --- a/telecomm/java/android/telecom/TelecomManager.java +++ b/telecomm/java/android/telecom/TelecomManager.java @@ -2202,15 +2202,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; } /** |