Keep system default SIM as a fallback for when no conversation default SIM.

Fixes #8452
This commit is contained in:
Alan Evans 2019-05-22 16:59:00 -03:00 committed by GitHub
parent 88dac70087
commit 3cba8ab58a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -34,10 +34,12 @@ public class TransportOptions {
private Optional<Integer> defaultSubscriptionId = Optional.absent(); private Optional<Integer> defaultSubscriptionId = Optional.absent();
private Optional<TransportOption> selectedOption = Optional.absent(); private Optional<TransportOption> selectedOption = Optional.absent();
private final Optional<Integer> systemSubscriptionId;
public TransportOptions(Context context, boolean media) { public TransportOptions(Context context, boolean media) {
this.context = context; this.context = context;
this.enabledTransports = initializeAvailableTransports(media); this.enabledTransports = initializeAvailableTransports(media);
this.defaultSubscriptionId = new SubscriptionManagerCompat(context).getPreferredSubscriptionId(); this.systemSubscriptionId = new SubscriptionManagerCompat(context).getPreferredSubscriptionId();
} }
public void reset(boolean media) { public void reset(boolean media) {
@ -88,13 +90,10 @@ public class TransportOptions {
public @NonNull TransportOption getSelectedTransport() { public @NonNull TransportOption getSelectedTransport() {
if (selectedOption.isPresent()) return selectedOption.get(); if (selectedOption.isPresent()) return selectedOption.get();
if (defaultSubscriptionId.isPresent()) { if (defaultTransportType == Type.SMS) {
for (TransportOption transportOption : enabledTransports) { TransportOption transportOption = findEnabledSmsTransportOption(defaultSubscriptionId.or(systemSubscriptionId));
if (transportOption.getType() == defaultTransportType && if (transportOption != null) {
(int)defaultSubscriptionId.get() == transportOption.getSimSubscriptionId().or(-1)) return transportOption;
{
return transportOption;
}
} }
} }
@ -107,6 +106,20 @@ public class TransportOptions {
throw new AssertionError("No options of default type!"); throw new AssertionError("No options of default type!");
} }
private @Nullable TransportOption findEnabledSmsTransportOption(Optional<Integer> 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) { public void disableTransport(Type type) {
TransportOption selected = selectedOption.orNull(); TransportOption selected = selectedOption.orNull();