mirror of
https://github.com/oxen-io/session-android.git
synced 2024-12-25 09:17:44 +00:00
Fix potential crash when retrieving SIM list.
This commit is contained in:
parent
ecea6abeb6
commit
bb90987e7c
@ -10,6 +10,7 @@ import android.os.Build;
|
|||||||
import android.os.PowerManager;
|
import android.os.PowerManager;
|
||||||
import android.os.Vibrator;
|
import android.os.Vibrator;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
import android.support.annotation.RequiresApi;
|
import android.support.annotation.RequiresApi;
|
||||||
import android.support.v4.content.ContextCompat;
|
import android.support.v4.content.ContextCompat;
|
||||||
import android.telephony.SubscriptionManager;
|
import android.telephony.SubscriptionManager;
|
||||||
@ -55,7 +56,7 @@ public class ServiceUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP_MR1)
|
@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);
|
return ContextCompat.getSystemService(context, SubscriptionManager.class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,7 @@ import android.telephony.SubscriptionInfo;
|
|||||||
import android.telephony.SubscriptionManager;
|
import android.telephony.SubscriptionManager;
|
||||||
import android.telephony.TelephonyManager;
|
import android.telephony.TelephonyManager;
|
||||||
|
|
||||||
|
import org.thoughtcrime.securesms.logging.Log;
|
||||||
import org.thoughtcrime.securesms.util.ServiceUtil;
|
import org.thoughtcrime.securesms.util.ServiceUtil;
|
||||||
import org.whispersystems.libsignal.util.guava.Function;
|
import org.whispersystems.libsignal.util.guava.Function;
|
||||||
import org.whispersystems.libsignal.util.guava.Optional;
|
import org.whispersystems.libsignal.util.guava.Optional;
|
||||||
@ -25,6 +26,8 @@ import java.util.Set;
|
|||||||
|
|
||||||
public final class SubscriptionManagerCompat {
|
public final class SubscriptionManagerCompat {
|
||||||
|
|
||||||
|
private static final String TAG = Log.tag(SubscriptionManagerCompat.class);
|
||||||
|
|
||||||
private final Context context;
|
private final Context context;
|
||||||
|
|
||||||
public SubscriptionManagerCompat(Context context) {
|
public SubscriptionManagerCompat(Context context) {
|
||||||
@ -57,7 +60,14 @@ public final class SubscriptionManagerCompat {
|
|||||||
|
|
||||||
@RequiresApi(api = 22)
|
@RequiresApi(api = 22)
|
||||||
private @NonNull Map<Integer, SubscriptionInfoCompat> getActiveSubscriptionInfoMap(boolean excludeUnreadySubscriptions) {
|
private @NonNull Map<Integer, SubscriptionInfoCompat> getActiveSubscriptionInfoMap(boolean excludeUnreadySubscriptions) {
|
||||||
List<SubscriptionInfo> subscriptionInfos = ServiceUtil.getSubscriptionManager(context).getActiveSubscriptionInfoList();
|
SubscriptionManager subscriptionManager = ServiceUtil.getSubscriptionManager(context);
|
||||||
|
|
||||||
|
if (subscriptionManager == null) {
|
||||||
|
Log.w(TAG, "Missing SubscriptionManager.");
|
||||||
|
return Collections.emptyMap();
|
||||||
|
}
|
||||||
|
|
||||||
|
List<SubscriptionInfo> subscriptionInfos = subscriptionManager.getActiveSubscriptionInfoList();
|
||||||
|
|
||||||
if (subscriptionInfos == null || subscriptionInfos.isEmpty()) {
|
if (subscriptionInfos == null || subscriptionInfos.isEmpty()) {
|
||||||
return Collections.emptyMap();
|
return Collections.emptyMap();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user