mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-24 10:35:19 +00:00
parent
f3f6cc87d9
commit
48efcaa785
@ -6,8 +6,13 @@ import android.app.NotificationManager;
|
||||
import android.content.Context;
|
||||
import android.media.AudioManager;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.os.Build;
|
||||
import android.os.PowerManager;
|
||||
import android.os.Vibrator;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.RequiresApi;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.telephony.SubscriptionManager;
|
||||
import android.telephony.TelephonyManager;
|
||||
import android.view.WindowManager;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
@ -48,4 +53,9 @@ public class ServiceUtil {
|
||||
public static Vibrator getVibrator(Context context) {
|
||||
return (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE);
|
||||
}
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP_MR1)
|
||||
public static SubscriptionManager getSubscriptionManager(@NonNull Context context) {
|
||||
return ContextCompat.getSystemService(context, SubscriptionManager.class);
|
||||
}
|
||||
}
|
||||
|
@ -3,15 +3,18 @@ package org.thoughtcrime.securesms.util.dualsim;
|
||||
import android.content.Context;
|
||||
import android.os.Build;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.RequiresApi;
|
||||
import android.telephony.SubscriptionInfo;
|
||||
import android.telephony.SubscriptionManager;
|
||||
import android.telephony.TelephonyManager;
|
||||
|
||||
import org.thoughtcrime.securesms.util.ServiceUtil;
|
||||
import org.whispersystems.libsignal.util.guava.Optional;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
public class SubscriptionManagerCompat {
|
||||
public final class SubscriptionManagerCompat {
|
||||
|
||||
private final Context context;
|
||||
|
||||
@ -32,7 +35,7 @@ public class SubscriptionManagerCompat {
|
||||
return Optional.absent();
|
||||
}
|
||||
|
||||
SubscriptionInfo subscriptionInfo = SubscriptionManager.from(context).getActiveSubscriptionInfo(subscriptionId);
|
||||
SubscriptionInfo subscriptionInfo = getSubscriptionManager().getActiveSubscriptionInfo(subscriptionId);
|
||||
|
||||
if (subscriptionInfo != null) {
|
||||
return Optional.of(new SubscriptionInfoCompat(subscriptionId, subscriptionInfo.getDisplayName(),
|
||||
@ -47,7 +50,7 @@ public class SubscriptionManagerCompat {
|
||||
return new LinkedList<>();
|
||||
}
|
||||
|
||||
List<SubscriptionInfo> subscriptionInfos = SubscriptionManager.from(context).getActiveSubscriptionInfoList();
|
||||
List<SubscriptionInfo> subscriptionInfos = getSubscriptionManager().getActiveSubscriptionInfoList();
|
||||
|
||||
if (subscriptionInfos == null || subscriptionInfos.isEmpty()) {
|
||||
return new LinkedList<>();
|
||||
@ -56,13 +59,29 @@ public class SubscriptionManagerCompat {
|
||||
List<SubscriptionInfoCompat> compatList = new LinkedList<>();
|
||||
|
||||
for (SubscriptionInfo subscriptionInfo : subscriptionInfos) {
|
||||
if (isReady(subscriptionInfo)) {
|
||||
compatList.add(new SubscriptionInfoCompat(subscriptionInfo.getSubscriptionId(),
|
||||
subscriptionInfo.getDisplayName(),
|
||||
subscriptionInfo.getMcc(),
|
||||
subscriptionInfo.getMnc()));
|
||||
}
|
||||
}
|
||||
|
||||
return compatList;
|
||||
}
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP_MR1)
|
||||
private SubscriptionManager getSubscriptionManager() {
|
||||
return ServiceUtil.getSubscriptionManager(context);
|
||||
}
|
||||
|
||||
private boolean isReady(@NonNull SubscriptionInfo subscriptionInfo) {
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) return true;
|
||||
|
||||
TelephonyManager telephonyManager = ServiceUtil.getTelephonyManager(context);
|
||||
|
||||
TelephonyManager specificTelephonyManager = telephonyManager.createForSubscriptionId(subscriptionInfo.getSubscriptionId());
|
||||
|
||||
return specificTelephonyManager.getSimState() == TelephonyManager.SIM_STATE_READY;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user