diff --git a/src/org/thoughtcrime/securesms/TransportOptions.java b/src/org/thoughtcrime/securesms/TransportOptions.java index 889e8dea73..e835f4604b 100644 --- a/src/org/thoughtcrime/securesms/TransportOptions.java +++ b/src/org/thoughtcrime/securesms/TransportOptions.java @@ -34,10 +34,12 @@ public class TransportOptions { private Optional defaultSubscriptionId = Optional.absent(); private Optional selectedOption = Optional.absent(); + private final Optional systemSubscriptionId; + public TransportOptions(Context context, boolean media) { - this.context = context; - this.enabledTransports = initializeAvailableTransports(media); - this.defaultSubscriptionId = new SubscriptionManagerCompat(context).getPreferredSubscriptionId(); + this.context = context; + this.enabledTransports = initializeAvailableTransports(media); + this.systemSubscriptionId = new SubscriptionManagerCompat(context).getPreferredSubscriptionId(); } public void reset(boolean media) { @@ -88,13 +90,10 @@ public class TransportOptions { public @NonNull TransportOption getSelectedTransport() { if (selectedOption.isPresent()) return selectedOption.get(); - if (defaultSubscriptionId.isPresent()) { - for (TransportOption transportOption : enabledTransports) { - if (transportOption.getType() == defaultTransportType && - (int)defaultSubscriptionId.get() == transportOption.getSimSubscriptionId().or(-1)) - { - return transportOption; - } + if (defaultTransportType == Type.SMS) { + TransportOption transportOption = findEnabledSmsTransportOption(defaultSubscriptionId.or(systemSubscriptionId)); + if (transportOption != null) { + return transportOption; } } @@ -107,6 +106,20 @@ public class TransportOptions { throw new AssertionError("No options of default type!"); } + private @Nullable TransportOption findEnabledSmsTransportOption(Optional subscriptionId) { + if (subscriptionId.isPresent()) { + final int subId = subscriptionId.get(); + + for (TransportOption transportOption : enabledTransports) { + if (transportOption.getType() == Type.SMS && + subId == transportOption.getSimSubscriptionId().or(-1)) { + return transportOption; + } + } + } + return null; + } + public void disableTransport(Type type) { TransportOption selected = selectedOption.orNull();