mirror of
https://github.com/oxen-io/session-android.git
synced 2024-12-25 09:17:44 +00:00
Keep system default SIM as a fallback for when no conversation default SIM.
Fixes #8452
This commit is contained in:
parent
88dac70087
commit
3cba8ab58a
@ -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();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user