Commit 48a01380 authored by Bastien Le Querrec's avatar Bastien Le Querrec

fix key management for dual-sim devices with 1 card inserted

parent f705084a
......@@ -25,17 +25,6 @@ public class TransportOption {
private final @NonNull Optional<CharSequence> simName;
private final @NonNull Optional<Integer> simSubscriptionId;
public TransportOption(@NonNull Type type,
@DrawableRes int drawable,
int backgroundColor,
@NonNull String text,
@NonNull String composeHint,
@NonNull CharacterCalculator characterCalculator)
{
this(type, drawable, backgroundColor, text, composeHint, characterCalculator,
Optional.<CharSequence>absent(), Optional.<Integer>absent());
}
public TransportOption(@NonNull Type type,
@DrawableRes int drawable,
int backgroundColor,
......
......@@ -179,24 +179,15 @@ public class TransportOptions {
subscriptions = new LinkedList<>();
}
if (subscriptions.size() < 2) {
for (SubscriptionInfoCompat subscriptionInfo : subscriptions) {
results.add(new TransportOption(type,
drawable,
backgroundColor,
text,
composeHint,
characterCalculator));
} else {
for (SubscriptionInfoCompat subscriptionInfo : subscriptions) {
results.add(new TransportOption(type,
drawable,
backgroundColor,
text,
composeHint,
characterCalculator,
Optional.of(subscriptionInfo.getDisplayName()),
Optional.of(subscriptionInfo.getSubscriptionId())));
}
characterCalculator,
Optional.of(subscriptionInfo.getDisplayName()),
Optional.of(subscriptionInfo.getSubscriptionId())));
}
return results;
......
......@@ -42,7 +42,8 @@ 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");
if (subscriptionId == -1) Log.w(TAG, "Subscription ID should not be -1!");
this.context = context.getApplicationContext();
this.masterSecret = masterSecret;
this.subscriptionId = subscriptionId;
......
......@@ -17,8 +17,7 @@ import org.smssecure.smssecure.recipients.Recipients;
import org.smssecure.smssecure.service.KeyCachingService;
import org.smssecure.smssecure.sms.IncomingTextMessage;
import org.smssecure.smssecure.sms.MultipartSmsMessageHandler;
import org.smssecure.smssecure.util.dualsim.SubscriptionInfoCompat;
import org.smssecure.smssecure.util.dualsim.SubscriptionManagerCompat;
import org.smssecure.smssecure.util.dualsim.DualSimUtil;
import org.whispersystems.jobqueue.JobParameters;
import org.whispersystems.libsignal.util.guava.Optional;
......@@ -42,8 +41,11 @@ public class SmsReceiveJob extends ContextJob {
.withWakeLock(true)
.create());
Log.w(TAG, "subscriptionId: " + subscriptionId);
Log.w(TAG, "Found app subscription ID: " + DualSimUtil.getSubscriptionIdFromDeviceSubscriptionId(context, subscriptionId));
this.pdus = pdus;
this.subscriptionId = findAppSubscriptionId(context, subscriptionId);
this.subscriptionId = DualSimUtil.getSubscriptionIdFromDeviceSubscriptionId(context, subscriptionId);
}
@Override
......@@ -140,10 +142,4 @@ public class SmsReceiveJob extends ContextJob {
return Optional.of(message);
}
}
private static int findAppSubscriptionId(Context context, int subscriptionId) {
Optional<SubscriptionInfoCompat> subscriptionInfo = SubscriptionManagerCompat.from(context).getActiveSubscriptionInfo(subscriptionId);
if (!subscriptionInfo.isPresent()) return -1;
return subscriptionInfo.get().getDeviceSubscriptionId();
}
}
......@@ -106,6 +106,12 @@ public class DualSimUtil {
else return -1;
}
public static int getSubscriptionIdFromDeviceSubscriptionId(Context context, int deviceSubscriptionId) {
Optional<SubscriptionInfoCompat> subscriptionInfo = SubscriptionManagerCompat.from(context).getActiveSubscriptionInfoFromDeviceSubscriptionId(deviceSubscriptionId);
if (subscriptionInfo.isPresent()) return subscriptionInfo.get().getSubscriptionId();
else return -1;
}
public static void displayNotification(Context context) {
Intent targetIntent = context.getPackageManager().getLaunchIntentForPackage(context.getPackageName());
Notification notification = new NotificationCompat.Builder(context)
......
......@@ -52,6 +52,18 @@ public class SubscriptionManagerCompat {
return Optional.absent();
}
public Optional<SubscriptionInfoCompat> getActiveSubscriptionInfoFromDeviceSubscriptionId(int subscriptionId) {
if (getActiveSubscriptionInfoList().size() <= 0) {
return Optional.absent();
}
for (SubscriptionInfoCompat subscriptionInfo : getActiveSubscriptionInfoList()) {
if (subscriptionInfo.getDeviceSubscriptionId() == subscriptionId) return Optional.of(subscriptionInfo);
}
return Optional.absent();
}
@TargetApi(22)
private void updateDisplayNameList(List<SubscriptionInfo> activeSubscriptions) {
displayNameList = new LinkedList<String>();
......
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