Commit f9798733 authored by Bastien Le Querrec's avatar Bastien Le Querrec

fix keys management if app subscription ID is not equal to device's one

parent 89d78c8e
......@@ -592,8 +592,8 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
}
private void handleVerifyIdentity() {
if (Build.VERSION.SDK_INT < 22 || activeSubscriptions.size() < 2) {
int subscriptionId = Build.VERSION.SDK_INT < 22 ? -1 : activeSubscriptions.get(0).getSubscriptionId();
if (activeSubscriptions.size() < 2) {
int subscriptionId = activeSubscriptions.get(0).getSubscriptionId();
handleVerifyIdentity(subscriptionId);
}
}
......@@ -606,8 +606,8 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
}
private void handleStartSecureSession() {
if (Build.VERSION.SDK_INT < 22 || activeSubscriptions.size() < 2) {
int subscriptionId = Build.VERSION.SDK_INT < 22 ? -1 : activeSubscriptions.get(0).getSubscriptionId();
if (activeSubscriptions.size() < 2) {
int subscriptionId = activeSubscriptions.get(0).getSubscriptionId();
handleStartSecureSession(subscriptionId);
}
}
......@@ -655,8 +655,8 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
}
private void handleAbortSecureSession() {
if (Build.VERSION.SDK_INT < 22 || activeSubscriptions.size() < 2) {
int subscriptionId = Build.VERSION.SDK_INT < 22 ? -1 : activeSubscriptions.get(0).getSubscriptionId();
if (activeSubscriptions.size() < 2) {
int subscriptionId = activeSubscriptions.get(0).getSubscriptionId();
handleAbortSecureSession(subscriptionId);
}
}
......
......@@ -404,7 +404,7 @@ public class ConversationItem extends LinearLayout
private void setSimInfo(MessageRecord messageRecord) {
SubscriptionManagerCompat subscriptionManager = SubscriptionManagerCompat.from(context);
if (messageRecord.getSubscriptionId() == -1 || subscriptionManager.getActiveSubscriptionInfoList().size() < 2) {
if (subscriptionManager.getActiveSubscriptionInfoList().size() < 2) {
simInfoText.setVisibility(View.GONE);
} else {
Optional<SubscriptionInfoCompat> subscriptionInfo = subscriptionManager.getActiveSubscriptionInfo(messageRecord.getSubscriptionId());
......
......@@ -229,8 +229,8 @@ public class ConversationListActivity extends PassphraseRequiredActionBarActivit
}
private void handleMyIdentity() {
if (Build.VERSION.SDK_INT < 22 || activeSubscriptions.size() < 2) {
int subscriptionId = Build.VERSION.SDK_INT < 22 ? -1 : activeSubscriptions.get(0).getSubscriptionId();
if (activeSubscriptions.size() < 2) {
int subscriptionId = activeSubscriptions.get(0).getSubscriptionId();
handleMyIdentity(subscriptionId);
}
}
......
......@@ -32,7 +32,7 @@ import android.widget.ProgressBar;
import org.smssecure.smssecure.crypto.MasterSecret;
import org.smssecure.smssecure.database.DatabaseFactory;
import org.smssecure.smssecure.notifications.MessageNotifier;
import org.smssecure.smssecure.util.dualsim.DualSimUpgradeUtil;
import org.smssecure.smssecure.util.dualsim.DualSimUtil;
import org.smssecure.smssecure.util.dualsim.SubscriptionInfoCompat;
import org.smssecure.smssecure.util.dualsim.SubscriptionManagerCompat;
import org.smssecure.smssecure.util.ParcelUtil;
......@@ -160,11 +160,6 @@ public class DatabaseUpgradeActivity extends BaseActivity {
SubscriptionManager subscriptionManager = SubscriptionManager.from(context);
List<SubscriptionInfo> activeSubscriptions = subscriptionManager.getActiveSubscriptionInfoList();
for (SubscriptionInfo subscriptionInfo : activeSubscriptions) {
int subscriptionId = subscriptionInfo.getSubscriptionId();
SilencePreferences.setAppSubscriptionId(context, subscriptionId, subscriptionId);
}
/*
* getDefaultSubscriptionId() is available for API 24+ only, so we
* move keys and sessions to SIM card in slot 1, not to the default one.
......@@ -173,9 +168,9 @@ public class DatabaseUpgradeActivity extends BaseActivity {
List<SubscriptionInfoCompat> activeSubscriptionsCompat = SubscriptionManagerCompat.from(context).getActiveSubscriptionInfoList();
DualSimUpgradeUtil.moveIdentityKeysAndSessionsToSubscriptionId(context, -1, defaultSubscriptionId);
DualSimUpgradeUtil.generateKeysIfDoNotExist(context, masterSecret, activeSubscriptionsCompat);
DualSimUpgradeUtil.bindSubscriptionId(context, activeSubscriptionsCompat);
DualSimUtil.moveIdentityKeysAndSessionsToSubscriptionId(context, -1, defaultSubscriptionId);
DualSimUtil.generateKeysIfDoNotExist(context, masterSecret, activeSubscriptionsCompat);
SubscriptionManagerCompat.from(context).updateActiveSubscriptionInfoList();
}
}
......
......@@ -24,7 +24,7 @@ import android.support.v7.app.ActionBar;
import org.smssecure.smssecure.crypto.IdentityKeyUtil;
import org.smssecure.smssecure.crypto.MasterSecret;
import org.smssecure.smssecure.crypto.MasterSecretUtil;
import org.smssecure.smssecure.util.dualsim.DualSimUpgradeUtil;
import org.smssecure.smssecure.util.dualsim.DualSimUtil;
import org.smssecure.smssecure.util.dualsim.SubscriptionInfoCompat;
import org.smssecure.smssecure.util.dualsim.SubscriptionManagerCompat;
import org.smssecure.smssecure.util.SilencePreferences;
......@@ -59,7 +59,7 @@ public class PassphraseCreateActivity extends PassphraseActivity {
}
private class SecretGenerator extends AsyncTask<String, Void, Void> {
private MasterSecret masterSecret;
private MasterSecret masterSecret;
@Override
protected void onPreExecute() {
......@@ -73,12 +73,14 @@ public class PassphraseCreateActivity extends PassphraseActivity {
MasterSecretUtil.generateAsymmetricMasterSecret(PassphraseCreateActivity.this, masterSecret);
SubscriptionManagerCompat subscriptionManagerCompat = SubscriptionManagerCompat.from(PassphraseCreateActivity.this);
if (Build.VERSION.SDK_INT >= 22) {
List<SubscriptionInfoCompat> activeSubscriptions = SubscriptionManagerCompat.from(PassphraseCreateActivity.this).getActiveSubscriptionInfoList();
DualSimUpgradeUtil.generateKeysIfDoNotExist(PassphraseCreateActivity.this, masterSecret, activeSubscriptions);
DualSimUpgradeUtil.bindSubscriptionId(PassphraseCreateActivity.this, activeSubscriptions);
List<SubscriptionInfoCompat> activeSubscriptions = subscriptionManagerCompat.getActiveSubscriptionInfoList();
DualSimUtil.generateKeysIfDoNotExist(PassphraseCreateActivity.this, masterSecret, activeSubscriptions);
} else {
IdentityKeyUtil.generateIdentityKeys(PassphraseCreateActivity.this, masterSecret, -1);
subscriptionManagerCompat.updateActiveSubscriptionInfoList();
}
VersionTracker.updateLastSeenVersion(PassphraseCreateActivity.this);
SilencePreferences.setPasswordDisabled(PassphraseCreateActivity.this, true);
......
/**
/**
* Copyright (C) 2011 Whisper Systems
* Copyright (C) 2013 Open Whisper Systems
*
......
......@@ -42,6 +42,7 @@ public class SilenceSessionStore implements SessionStore {
public SilenceSessionStore(Context context, MasterSecret masterSecret, int subscriptionId) {
Log.w(TAG, "SilenceSessionStore for subscription ID " + subscriptionId);
if (subscriptionId == -1) throw new AssertionError("Subscription ID cannot be -1 but should be >1");
this.context = context.getApplicationContext();
this.masterSecret = masterSecret;
this.subscriptionId = subscriptionId;
......
......@@ -5,7 +5,7 @@ import android.util.Log;
import org.smssecure.smssecure.crypto.MasterSecret;
import org.smssecure.smssecure.jobs.requirements.MasterSecretRequirement;
import org.smssecure.smssecure.util.dualsim.DualSimUpgradeUtil;
import org.smssecure.smssecure.util.dualsim.DualSimUtil;
import org.smssecure.smssecure.util.dualsim.SubscriptionInfoCompat;
import org.smssecure.smssecure.util.dualsim.SubscriptionManagerCompat;
import org.whispersystems.jobqueue.JobParameters;
......@@ -13,12 +13,12 @@ import org.whispersystems.jobqueue.JobParameters;
import java.util.List;
public class CheckSimStateJob extends MasterSecretJob {
private static final String TAG = CheckSimStateJob.class.getSimpleName();
public class GenerateKeysJob extends MasterSecretJob {
private static final String TAG = GenerateKeysJob.class.getSimpleName();
private List<SubscriptionInfoCompat> activeSubscriptions;
public CheckSimStateJob(Context context) {
public GenerateKeysJob(Context context) {
super(context, JobParameters.newBuilder()
.withPersistence()
.withRequirement(new MasterSecretRequirement(context))
......@@ -33,10 +33,8 @@ public class CheckSimStateJob extends MasterSecretJob {
@Override
public void onRun(MasterSecret masterSecret) {
Log.w(TAG, "onRun()");
List<SubscriptionInfoCompat> activeSubscriptions = SubscriptionManagerCompat.from(context).getActiveSubscriptionInfoList();
DualSimUpgradeUtil.bindAppSubscriptionId(context, activeSubscriptions);
DualSimUpgradeUtil.generateKeysIfDoNotExist(context, masterSecret, activeSubscriptions);
DualSimUpgradeUtil.bindSubscriptionId(context, activeSubscriptions);
List<SubscriptionInfoCompat> activeSubscriptions = SubscriptionManagerCompat.from(context).updateActiveSubscriptionInfoList();
DualSimUtil.generateKeysIfDoNotExist(context, masterSecret, activeSubscriptions);
}
@Override
......
......@@ -37,6 +37,7 @@ import org.smssecure.smssecure.recipients.Recipient;
import org.smssecure.smssecure.recipients.Recipients;
import org.smssecure.smssecure.recipients.RecipientFormattingException;
import org.smssecure.smssecure.transport.UndeliverableMessageException;
import org.smssecure.smssecure.util.dualsim.DualSimUtil;
import org.smssecure.smssecure.util.Hex;
import org.smssecure.smssecure.util.NumberUtil;
import org.smssecure.smssecure.util.Util;
......@@ -96,7 +97,7 @@ public class MmsSendJob extends SendJob {
validateDestinations(message, pdu);
final byte[] pduBytes = getPduBytes(masterSecret, pdu);
final SendConf sendConf = new CompatMmsConnection(context).send(pduBytes, message.getSubscriptionId());
final SendConf sendConf = new CompatMmsConnection(context).send(pduBytes, DualSimUtil.getSubscriptionIdFromAppSubscriptionId(context, message.getSubscriptionId()));
final MmsSendResult result = getSendResult(sendConf, pdu, upgradedSecure);
database.markAsSent(messageId, result.isUpgradedSecure());
......
......@@ -26,6 +26,7 @@ import org.smssecure.smssecure.service.SmsDeliveryListener;
import org.smssecure.smssecure.sms.MultipartSmsMessageHandler;
import org.smssecure.smssecure.sms.OutgoingTextMessage;
import org.smssecure.smssecure.transport.UndeliverableMessageException;
import org.smssecure.smssecure.util.dualsim.DualSimUtil;
import org.smssecure.smssecure.util.NumberUtil;
import org.smssecure.smssecure.util.SilencePreferences;
import org.whispersystems.jobqueue.JobParameters;
......@@ -119,8 +120,14 @@ public class SmsSendJob extends SendJob {
ArrayList<PendingIntent> sentIntents = constructSentIntents(message.getId(), message.getType(), messages, message.isSecure());
ArrayList<PendingIntent> deliveredIntents = constructDeliveredIntents(message.getId(), message.getType(), messages);
int deviceSubscriptionId = DualSimUtil.getSubscriptionIdFromAppSubscriptionId(context, message.getSubscriptionId());
// NOTE 11/04/14 -- There's apparently a bug where for some unknown recipients
// and messages, this will throw an NPE. We have no idea why, so we're just
// catching it and marking the message as a failure. That way at least it doesn't
// repeatedly crash every time you start the app.
try {
getSmsManagerFor(message.getSubscriptionId()).sendMultipartTextMessage(recipient, null, messages, sentIntents, deliveredIntents);
getSmsManagerFor(deviceSubscriptionId).sendMultipartTextMessage(recipient, null, messages, sentIntents, deliveredIntents);
} catch (NullPointerException npe) {
Log.w(TAG, npe);
Log.w(TAG, "Recipient: " + recipient);
......
......@@ -12,13 +12,14 @@ import org.smssecure.smssecure.crypto.MasterSecret;
import org.smssecure.smssecure.crypto.MasterSecretUtil;
import org.smssecure.smssecure.crypto.storage.SilenceSessionStore;
import org.smssecure.smssecure.util.SilencePreferences;
import org.whispersystems.libsignal.util.guava.Optional;
import java.io.File;
import java.util.LinkedList;
import java.util.List;
public class DualSimUpgradeUtil {
private static final String TAG = DualSimUpgradeUtil.class.getSimpleName();
public class DualSimUtil {
private static final String TAG = DualSimUtil.class.getSimpleName();
public static void moveIdentityKeysAndSessionsToSubscriptionId(Context context, int originalSubscriptionId, int subscriptionId) {
Log.w(TAG, "moveIdentityKeysMasterSecretAndSessionsToSubscriptionId(" + originalSubscriptionId + ", " + subscriptionId + ")");
......@@ -87,110 +88,9 @@ public class DualSimUpgradeUtil {
}
}
public static void bindSubscriptionId(Context context, List<SubscriptionInfoCompat> activeSubscriptions) {
List<SubscriptionInfoCompat> remainingSubscriptions;
remainingSubscriptions = bindSubscriptionIdToPhoneNumber(context, activeSubscriptions);
remainingSubscriptions = bindSubscriptionIdToIccId(context, remainingSubscriptions);
if (remainingSubscriptions.size() > 0) Log.w(TAG, "WARNING: Cannot bind " + remainingSubscriptions.size() + " subscription(s)!");
}
private static List<SubscriptionInfoCompat> bindSubscriptionIdToPhoneNumber(Context context, List<SubscriptionInfoCompat> activeSubscriptions) {
List<SubscriptionInfoCompat> remainingSubscriptions = new LinkedList<SubscriptionInfoCompat>(activeSubscriptions);
for (SubscriptionInfoCompat subscriptionInfo : new LinkedList<SubscriptionInfoCompat>(activeSubscriptions)) {
String number = subscriptionInfo.getNumber();
if (number != null && !number.equals("")) {
SilencePreferences.setNumberForSubscriptionId(context, subscriptionInfo.getSubscriptionId(), number);
remainingSubscriptions.remove(subscriptionInfo);
}
}
return remainingSubscriptions;
}
private static List<SubscriptionInfoCompat> bindSubscriptionIdToIccId(Context context, List<SubscriptionInfoCompat> activeSubscriptions) {
List<SubscriptionInfoCompat> remainingSubscriptions = new LinkedList<SubscriptionInfoCompat>(activeSubscriptions);
for (SubscriptionInfoCompat subscriptionInfo : new LinkedList<SubscriptionInfoCompat>(activeSubscriptions)) {
String iccId = subscriptionInfo.getIccId();
if (iccId != null && !iccId.equals("")) {
SilencePreferences.setIccIdForSubscriptionId(context, subscriptionInfo.getSubscriptionId(), iccId);
remainingSubscriptions.remove(subscriptionInfo);
}
}
return remainingSubscriptions;
}
public static void bindAppSubscriptionId(Context context, List<SubscriptionInfoCompat> activeSubscriptions) {
if (Build.VERSION.SDK_INT >= 22) {
for (SubscriptionInfoCompat subscriptionInfo : activeSubscriptions) {
int appSubscriptionId = SilencePreferences.getLastAppSubscriptionId(context) + 1;
if (subscriptionInfo.getSubscriptionId() == -1) SilencePreferences.setAppSubscriptionId(context, subscriptionInfo.getDeviceSubscriptionId(), appSubscriptionId);
}
}
}
public static void checkAndFixAppSubscriptionIds(Context context) {
if (Build.VERSION.SDK_INT >= 22) {
SubscriptionManagerCompat subscriptionManagerCompat = SubscriptionManagerCompat.from(context);
List<SubscriptionInfoCompat> activeSubscriptionsCompat = subscriptionManagerCompat.updateActiveSubscriptionInfoList();
for (SubscriptionInfoCompat subscriptionInfoCompat : activeSubscriptionsCompat) {
Log.w(TAG, "getDeviceSubscriptionId(): " + subscriptionInfoCompat.getDeviceSubscriptionId());
Log.w(TAG, "getSubscriptionId(): " + subscriptionInfoCompat.getSubscriptionId());
loop:
if (subscriptionInfoCompat.getDeviceSubscriptionId() != -1 && subscriptionInfoCompat.getSubscriptionId() == -1) {
fixSubscriptionsIds(context, activeSubscriptionsCompat);
break loop;
}
}
}
}
@TargetApi(22)
private static void fixSubscriptionsIds(Context context, List<SubscriptionInfoCompat> activeSubscriptionsCompat) {
SubscriptionManager subscriptionManager = SubscriptionManager.from(context);
List<SubscriptionInfo> activeSubscriptions = subscriptionManager.getActiveSubscriptionInfoList();
for (SubscriptionInfoCompat subscriptionInfoCompat : activeSubscriptionsCompat) {
loop:
if (!subscriptionInfoCompat.getNumber().equals("")) {
int subscriptionId = findSubscriptionIdForNumber(context, subscriptionInfoCompat.getNumber(), activeSubscriptions);
Log.w(TAG, "findSubscriptionIdForNumber(" + subscriptionInfoCompat.getNumber() + "): " + subscriptionId);
if (subscriptionId != -1) {
subscriptionInfoCompat.setSubscriptionId(subscriptionId);
break loop;
}
} else {
int subscriptionId = findSubscriptionIdForIccId(context, subscriptionInfoCompat.getIccId(), activeSubscriptions);
Log.w(TAG, "findSubscriptionIdForIccId(" + subscriptionInfoCompat.getIccId() + "): " + subscriptionId);
if (subscriptionId != -1) {
subscriptionInfoCompat.setSubscriptionId(subscriptionId);
break loop;
}
}
int subscriptionId = SilencePreferences.getLastAppSubscriptionId(context) + 1;
subscriptionInfoCompat.setSubscriptionId(subscriptionId);
}
}
@TargetApi(22)
private static int findSubscriptionIdForNumber(Context context, String number, List<SubscriptionInfo> activeSubscriptions) {
for (SubscriptionInfo subscriptionInfo : activeSubscriptions) {
String eligibleNumber = subscriptionInfo.getNumber();
if (eligibleNumber != null && eligibleNumber.equals(number)) return subscriptionInfo.getSubscriptionId();
}
return -1;
}
@TargetApi(22)
private static int findSubscriptionIdForIccId(Context context, String iccId, List<SubscriptionInfo> activeSubscriptions) {
for (SubscriptionInfo subscriptionInfo : activeSubscriptions) {
String eligibleIccId = subscriptionInfo.getIccId();
if (eligibleIccId != null && eligibleIccId.equals(iccId)) return subscriptionInfo.getSubscriptionId();
}
return -1;
public static int getSubscriptionIdFromAppSubscriptionId(Context context, int appSubscriptionId) {
Optional<SubscriptionInfoCompat> subscriptionInfo = SubscriptionManagerCompat.from(context).getActiveSubscriptionInfo(appSubscriptionId);
if (subscriptionInfo.isPresent()) return subscriptionInfo.get().getDeviceSubscriptionId();
else return -1;
}
}
......@@ -10,7 +10,7 @@ import android.util.Log;
import org.smssecure.smssecure.ApplicationContext;
import org.smssecure.smssecure.util.SilencePreferences;
import org.smssecure.smssecure.jobs.CheckSimStateJob;
import org.smssecure.smssecure.jobs.GenerateKeysJob;
import java.util.Arrays;
import java.util.List;
......@@ -31,10 +31,9 @@ public class SimChangedReceiver extends BroadcastReceiver {
public static void checkSimState(final Context context) {
if (hasDifferentSubscriptions(context)) {
DualSimUpgradeUtil.checkAndFixAppSubscriptionIds(context);
ApplicationContext.getInstance(context)
.getJobManager()
.add(new CheckSimStateJob(context));
.add(new GenerateKeysJob(context));
SilencePreferences.setDeviceSubscriptions(context, getDeviceSubscriptions(context));
}
}
......@@ -46,16 +45,16 @@ public class SimChangedReceiver extends BroadcastReceiver {
Log.w(TAG, "getDeviceSubscriptions(): " + getDeviceSubscriptions(context));
Log.w(TAG, "getActiveDeviceSubscriptionIds(): " + getActiveDeviceSubscriptionIds(context));
return subscriptions != null && !subscriptions.equals(registeredSubscriptions);
return !subscriptions.equals(registeredSubscriptions);
}
private static String getDeviceSubscriptions(Context context) {
if (Build.VERSION.SDK_INT < 22) return null;
if (Build.VERSION.SDK_INT < 22) return "1";
SubscriptionManager subscriptionManager = SubscriptionManager.from(context);
List<SubscriptionInfo> activeSubscriptions = subscriptionManager.getActiveSubscriptionInfoList();
if (activeSubscriptions == null) return null;
if (activeSubscriptions == null) return "1";
String[] subscriptions = new String[activeSubscriptions.size()];
for(int i=0; i<activeSubscriptions.size(); i++){
......
......@@ -31,8 +31,6 @@ public class SubscriptionInfoCompat {
int mnc,
boolean duplicateDisplayName)
{
int subscriptionId = SilencePreferences.getAppSubscriptionId(context, deviceSubscriptionId);
this.context = context;
this.deviceSubscriptionId = deviceSubscriptionId;
this.subscriptionId = subscriptionId;
......@@ -43,6 +41,7 @@ public class SubscriptionInfoCompat {
this.mcc = mcc;
this.mnc = mnc;
this.duplicateDisplayName = duplicateDisplayName;
this.subscriptionId = findAppId(context, number, iccId);
}
public @NonNull CharSequence getDisplayName() {
......@@ -80,6 +79,57 @@ public class SubscriptionInfoCompat {
return iccId;
}
private static int findAppId(Context context, String number, String iccId) {
int appSubscriptionId = -1;
appSubscriptionId = findAppIdFromNumber(context, number);
if (appSubscriptionId == -1) appSubscriptionId = findAppIdFromIccId(context, iccId);
if (appSubscriptionId == -1) appSubscriptionId = bumpAppSubcriptionId(context);
saveInfo(context, appSubscriptionId, number, iccId);
return appSubscriptionId;
}
private static int findAppIdFromNumber(Context context, String number) {
if (number == null || number.equals("")) return -1;
int lastAppSubscriptionId = SilencePreferences.getLastAppSubscriptionId(context);
for( int i = 0; i <= lastAppSubscriptionId; i++ ) {
String eligibleNumber = SilencePreferences.getNumberForSubscriptionId(context, i);
if (eligibleNumber != null && eligibleNumber.equals(number)) return i;
}
return -1;
}
private static int findAppIdFromIccId(Context context, String iccId) {
if (iccId == null || iccId.equals("")) return -1;
int lastAppSubscriptionId = SilencePreferences.getLastAppSubscriptionId(context);
for( int i = 0; i <= lastAppSubscriptionId; i++ ) {
String eligibleIccId = SilencePreferences.getIccIdForSubscriptionId(context, i);
if (eligibleIccId != null && eligibleIccId.equals(iccId)) return i;
}
return -1;
}
private static int bumpAppSubcriptionId(Context context) {
int lastAppSubscriptionId = SilencePreferences.getLastAppSubscriptionId(context);
SilencePreferences.setLastAppSubscriptionId(context, lastAppSubscriptionId+1);
return lastAppSubscriptionId+1;
}
private static void saveInfo(Context context, int appSubscriptionId, String number, String iccId) {
if (number != null && !number.equals(""))
SilencePreferences.setNumberForSubscriptionId(context, appSubscriptionId, number);
if (iccId != null && !iccId.equals(""))
SilencePreferences.setIccIdForSubscriptionId(context, appSubscriptionId, iccId);
}
public int getMnc() {
return mnc;
}
......
......@@ -45,21 +45,11 @@ public class SubscriptionManagerCompat {
return Optional.absent();
}
SubscriptionInfo subscriptionInfo = SubscriptionManager.from(context).getActiveSubscriptionInfo(subscriptionId);
if (subscriptionInfo != null) {
return Optional.of(new SubscriptionInfoCompat(context,
subscriptionId,
subscriptionInfo.getDisplayName(),
subscriptionInfo.getNumber(),
subscriptionInfo.getIccId(),
subscriptionInfo.getSimSlotIndex()+1,
subscriptionInfo.getMcc(),
subscriptionInfo.getMnc(),
knowThisDisplayNameTwice(subscriptionInfo.getDisplayName())));
} else {
return Optional.absent();
for (SubscriptionInfoCompat subscriptionInfo : getActiveSubscriptionInfoList()) {
if (subscriptionInfo.getSubscriptionId() == subscriptionId) return Optional.of(subscriptionInfo);
}
return Optional.absent();
}
@TargetApi(22)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment