Do not allow default SMS application to be set or get on non-phone devices
David Braun [Fri, 4 Oct 2013 23:52:29 +0000 (16:52 -0700)]
Bug: 11072894 People app should not launch into default SMS app on tablets
Change-Id: I9cedf3840f46bbc135f535b60659e5527f79a5aa

src/java/com/android/internal/telephony/SmsApplication.java

index 906c757..c01c9f0 100644 (file)
@@ -195,9 +195,13 @@ public final class SmsApplication {
         }
 
         // Remove any entries for which we did not find all required intents.
-        for (ResolveInfo r : smsReceivers) {
-            String packageName = r.activityInfo.packageName;
-            SmsApplicationData smsApplicationData = receivers.get(packageName);
+        for (ResolveInfo resolveInfo : smsReceivers) {
+            final ActivityInfo activityInfo = resolveInfo.activityInfo;
+            if (activityInfo == null) {
+                continue;
+            }
+            final String packageName = activityInfo.packageName;
+            final SmsApplicationData smsApplicationData = receivers.get(packageName);
             if (smsApplicationData != null) {
                 if (!smsApplicationData.isComplete()) {
                     receivers.remove(packageName);
@@ -235,6 +239,12 @@ public final class SmsApplication {
      * (4) Null
      */
     private static SmsApplicationData getApplication(Context context, boolean updateIfNeeded) {
+        TelephonyManager tm = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
+        if (tm.getPhoneType() == TelephonyManager.PHONE_TYPE_NONE) {
+            // No phone, no SMS
+            return null;
+        }
+
         Collection<SmsApplicationData> applications = getApplicationCollection(context);
 
         // Determine which application receives the broadcast
@@ -275,6 +285,12 @@ public final class SmsApplication {
      * needs to have permission to set AppOps and write to secure settings.
      */
     public static void setDefaultApplication(String packageName, Context context) {
+        TelephonyManager tm = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
+        if (tm.getPhoneType() == TelephonyManager.PHONE_TYPE_NONE) {
+            // No phone, no SMS
+            return;
+        }
+
         Collection<SmsApplicationData> applications = getApplicationCollection(context);
         String oldPackageName = Settings.Secure.getString(context.getContentResolver(),
                 Settings.Secure.SMS_DEFAULT_APPLICATION);