Fallback to SIM index.

#8725
This commit is contained in:
Alan Evans 2019-05-02 18:16:59 -03:00 committed by GitHub
parent ff1531b836
commit ec20b0e0e3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 14 deletions

View File

@ -863,6 +863,7 @@
<string name="conversation_activity__type_message_sms_insecure">Unsecured SMS</string> <string name="conversation_activity__type_message_sms_insecure">Unsecured SMS</string>
<string name="conversation_activity__type_message_mms_insecure">Unsecured MMS</string> <string name="conversation_activity__type_message_mms_insecure">Unsecured MMS</string>
<string name="conversation_activity__from_sim_name">From %1$s</string> <string name="conversation_activity__from_sim_name">From %1$s</string>
<string name="conversation_activity__sim_n">SIM %1$d</string>
<string name="conversation_activity__send">Send</string> <string name="conversation_activity__send">Send</string>
<string name="conversation_activity__compose_description">Message composition</string> <string name="conversation_activity__compose_description">Message composition</string>
<string name="conversation_activity__emoji_toggle_description">Toggle emoji keyboard</string> <string name="conversation_activity__emoji_toggle_description">Toggle emoji keyboard</string>

View File

@ -8,12 +8,11 @@ import android.telephony.SubscriptionInfo;
import android.telephony.SubscriptionManager; import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager; import android.telephony.TelephonyManager;
import org.thoughtcrime.securesms.R;
import org.thoughtcrime.securesms.logging.Log; import org.thoughtcrime.securesms.logging.Log;
import org.thoughtcrime.securesms.util.ServiceUtil; import org.thoughtcrime.securesms.util.ServiceUtil;
import org.whispersystems.libsignal.util.guava.Function; import org.whispersystems.libsignal.util.guava.Function;
import org.whispersystems.libsignal.util.guava.Optional; import org.whispersystems.libsignal.util.guava.Optional;
import org.whispersystems.signalservice.api.util.InvalidNumberException;
import org.whispersystems.signalservice.api.util.PhoneNumberFormatter;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
@ -90,16 +89,18 @@ public final class SubscriptionManagerCompat {
} }
@RequiresApi(api = 22) @RequiresApi(api = 22)
private static Map<SubscriptionInfo, CharSequence> getDescriptionsFor(@NonNull Collection<SubscriptionInfo> subscriptions) { private Map<SubscriptionInfo, CharSequence> getDescriptionsFor(@NonNull Collection<SubscriptionInfo> subscriptions) {
Map<SubscriptionInfo, CharSequence> descriptions; Map<SubscriptionInfo, CharSequence> descriptions;
descriptions = createDescriptionMap(subscriptions, SubscriptionInfo::getDisplayName); descriptions = createDescriptionMap(subscriptions, SubscriptionInfo::getDisplayName);
if (hasNoDuplicates(descriptions.values())) return descriptions; if (hasNoDuplicates(descriptions.values())) return descriptions;
descriptions = createDescriptionMap(subscriptions, SubscriptionInfo::getCarrierName); return createDescriptionMap(subscriptions, this::describeSimIndex);
if (hasNoDuplicates(descriptions.values())) return descriptions; }
return createDescriptionMap(subscriptions, (subscriptionInfo) -> formatNumber(subscriptionInfo.getNumber())); @RequiresApi(api = 22)
private String describeSimIndex(SubscriptionInfo info) {
return context.getString(R.string.conversation_activity__sim_n, info.getSimSlotIndex() + 1);
} }
private static Map<SubscriptionInfo, CharSequence> createDescriptionMap(@NonNull Collection<SubscriptionInfo> subscriptions, private static Map<SubscriptionInfo, CharSequence> createDescriptionMap(@NonNull Collection<SubscriptionInfo> subscriptions,
@ -123,14 +124,6 @@ public final class SubscriptionManagerCompat {
return true; return true;
} }
private static String formatNumber(String number) {
try {
return PhoneNumberFormatter.formatNumber(number, number);
} catch (InvalidNumberException e) {
return number;
}
}
private boolean isReady(@NonNull SubscriptionInfo subscriptionInfo) { private boolean isReady(@NonNull SubscriptionInfo subscriptionInfo) {
if (Build.VERSION.SDK_INT < 24) return true; if (Build.VERSION.SDK_INT < 24) return true;