Helper function to return the unique name for subscription info

Many classes within Settings have access to the subscription info, rather
than only having access to the subscription id. For these classes, it is
more convenient to have a helper method where the whole subscription
info can be passed in, rather than having to call the
getSubscriptionId() helper method in so many locations within the
telephony settings codebase.

Bug: 150370656
Bug: 148303118
Test: atest -c SubscriptionUtilTest
Change-Id: I181960933ab8610d5572b7a7d6671fab8c1dbd22
This commit is contained in:
Jeremy Goldman
2021-01-19 17:26:13 +08:00
parent 119bbbd308
commit 67c75ac102
2 changed files with 37 additions and 0 deletions

View File

@@ -324,6 +324,23 @@ public class SubscriptionUtil {
return displayNames.getOrDefault(subscriptionId, "");
}
/**
* Return the display name for a subscription, which is guaranteed to be unique.
* The logic to create this name has the following order of operations:
* 1) If the original display name is not unique, the last four digits of the phone number
* will be appended.
* 2) If the phone number is not visible or the last four digits are shared with another
* subscription, the subscription id will be appended to the original display name.
* More details can be found at go/unique-sub-display-names.
*
* @return map of active subscription ids to diaplay names.
*/
@VisibleForTesting
public static CharSequence getUniqueSubscriptionDisplayName(
SubscriptionInfo info, Context context) {
return getUniqueSubscriptionDisplayName(info.getSubscriptionId(), context);
}
public static String getDisplayName(SubscriptionInfo info) {
final CharSequence name = info.getDisplayName();
if (name != null) {