From 19afd4690fe76829c755f575109344a47b35f2d4 Mon Sep 17 00:00:00 2001 From: Ritwika Mitra Date: Wed, 29 May 2019 13:05:01 -0700 Subject: [PATCH] Initializing the Telephony Sms DB based on RoleManager.ROLE_SMS Fix: 133356079 Test: manual Change-Id: I49dcdc450e1113ffae887ad488d39f74a96787ed --- .../android/internal/telephony/SmsApplication.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/telephony/java/com/android/internal/telephony/SmsApplication.java b/telephony/java/com/android/internal/telephony/SmsApplication.java index ef7c60545ba0d..44dc24bf716e2 100644 --- a/telephony/java/com/android/internal/telephony/SmsApplication.java +++ b/telephony/java/com/android/internal/telephony/SmsApplication.java @@ -465,7 +465,11 @@ public final class SmsApplication { int userId) { TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); - if (!tm.isSmsCapable()) { + RoleManager roleManager = (RoleManager) context.getSystemService(Context.ROLE_SERVICE); + // (b/134400042) RoleManager might be null in unit tests running older mockito versions + // that do not support mocking final classes. + if (!tm.isSmsCapable() && (roleManager == null || !roleManager.isRoleAvailable( + RoleManager.ROLE_SMS))) { // No phone, no SMS return null; } @@ -584,7 +588,11 @@ public final class SmsApplication { public static void setDefaultApplicationAsUser(String packageName, Context context, int userId) { TelephonyManager tm = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE); - if (!tm.isSmsCapable()) { + RoleManager roleManager = (RoleManager) context.getSystemService(Context.ROLE_SERVICE); + // (b/134400042) RoleManager might be null in unit tests running older mockito versions + // that do not support mocking final classes. + if (!tm.isSmsCapable() && (roleManager == null || !roleManager.isRoleAvailable( + RoleManager.ROLE_SMS))) { // No phone, no SMS return; }