diff --git a/src/org/thoughtcrime/securesms/util/ServiceUtil.java b/src/org/thoughtcrime/securesms/util/ServiceUtil.java index 66f3879887..8cb1111c6d 100644 --- a/src/org/thoughtcrime/securesms/util/ServiceUtil.java +++ b/src/org/thoughtcrime/securesms/util/ServiceUtil.java @@ -10,6 +10,7 @@ import android.os.Build; import android.os.PowerManager; import android.os.Vibrator; import android.support.annotation.NonNull; +import android.support.annotation.Nullable; import android.support.annotation.RequiresApi; import android.support.v4.content.ContextCompat; import android.telephony.SubscriptionManager; @@ -55,7 +56,7 @@ public class ServiceUtil { } @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP_MR1) - public static SubscriptionManager getSubscriptionManager(@NonNull Context context) { + public static @Nullable SubscriptionManager getSubscriptionManager(@NonNull Context context) { return ContextCompat.getSystemService(context, SubscriptionManager.class); } } diff --git a/src/org/thoughtcrime/securesms/util/dualsim/SubscriptionManagerCompat.java b/src/org/thoughtcrime/securesms/util/dualsim/SubscriptionManagerCompat.java index e9c53d20b6..789d2405b0 100644 --- a/src/org/thoughtcrime/securesms/util/dualsim/SubscriptionManagerCompat.java +++ b/src/org/thoughtcrime/securesms/util/dualsim/SubscriptionManagerCompat.java @@ -8,6 +8,7 @@ import android.telephony.SubscriptionInfo; import android.telephony.SubscriptionManager; import android.telephony.TelephonyManager; +import org.thoughtcrime.securesms.logging.Log; import org.thoughtcrime.securesms.util.ServiceUtil; import org.whispersystems.libsignal.util.guava.Function; import org.whispersystems.libsignal.util.guava.Optional; @@ -25,6 +26,8 @@ import java.util.Set; public final class SubscriptionManagerCompat { + private static final String TAG = Log.tag(SubscriptionManagerCompat.class); + private final Context context; public SubscriptionManagerCompat(Context context) { @@ -57,7 +60,14 @@ public final class SubscriptionManagerCompat { @RequiresApi(api = 22) private @NonNull Map getActiveSubscriptionInfoMap(boolean excludeUnreadySubscriptions) { - List subscriptionInfos = ServiceUtil.getSubscriptionManager(context).getActiveSubscriptionInfoList(); + SubscriptionManager subscriptionManager = ServiceUtil.getSubscriptionManager(context); + + if (subscriptionManager == null) { + Log.w(TAG, "Missing SubscriptionManager."); + return Collections.emptyMap(); + } + + List subscriptionInfos = subscriptionManager.getActiveSubscriptionInfoList(); if (subscriptionInfos == null || subscriptionInfos.isEmpty()) { return Collections.emptyMap();