Convert PhoneAccount sort order to integers am: 948be1a7f1
Original change: https://android-review.googlesource.com/c/platform/packages/services/Telecomm/+/1471169
Change-Id: I40e744ba43dfdde3a508808b9d139c280c56aba9
diff --git a/src/com/android/server/telecom/PhoneAccountRegistrar.java b/src/com/android/server/telecom/PhoneAccountRegistrar.java
index e9ddfa0..9a4f7df 100644
--- a/src/com/android/server/telecom/PhoneAccountRegistrar.java
+++ b/src/com/android/server/telecom/PhoneAccountRegistrar.java
@@ -1266,11 +1266,11 @@
// Comparator which places PhoneAccounts with a specified sort order first, followed by
// those with no sort order.
Comparator<PhoneAccount> bySortOrder = (p1, p2) -> {
- String sort1 = p1.getExtras() == null ? null :
- p1.getExtras().getString(PhoneAccount.EXTRA_SORT_ORDER, null);
- String sort2 = p2.getExtras() == null ? null :
- p2.getExtras().getString(PhoneAccount.EXTRA_SORT_ORDER, null);
- return nullSafeStringComparator.compare(sort1, sort2);
+ int sort1 = p1.getExtras() == null ? Integer.MAX_VALUE:
+ p1.getExtras().getInt(PhoneAccount.EXTRA_SORT_ORDER, Integer.MAX_VALUE);
+ int sort2 = p2.getExtras() == null ? Integer.MAX_VALUE:
+ p2.getExtras().getInt(PhoneAccount.EXTRA_SORT_ORDER, Integer.MAX_VALUE);
+ return Integer.compare(sort1, sort2);
};
// Comparator which sorts PhoneAccounts by label.
diff --git a/tests/src/com/android/server/telecom/tests/PhoneAccountRegistrarTest.java b/tests/src/com/android/server/telecom/tests/PhoneAccountRegistrarTest.java
index 00ef87c..a56036a 100644
--- a/tests/src/com/android/server/telecom/tests/PhoneAccountRegistrarTest.java
+++ b/tests/src/com/android/server/telecom/tests/PhoneAccountRegistrarTest.java
@@ -725,16 +725,20 @@
mComponentContextFixture.addConnectionService(componentC,
Mockito.mock(IConnectionService.class));
+ Bundle account1Extras = new Bundle();
+ account1Extras.putInt(PhoneAccount.EXTRA_SORT_ORDER, 1);
PhoneAccount account1 = new PhoneAccount.Builder(
makeQuickAccountHandle(componentA, "c"), "c")
.setCapabilities(PhoneAccount.CAPABILITY_CALL_PROVIDER)
- .setExtras(Bundle.forPair(PhoneAccount.EXTRA_SORT_ORDER, "A"))
+ .setExtras(account1Extras)
.build();
+ Bundle account2Extras = new Bundle();
+ account2Extras.putInt(PhoneAccount.EXTRA_SORT_ORDER, 2);
PhoneAccount account2 = new PhoneAccount.Builder(
makeQuickAccountHandle(componentB, "b"), "b")
.setCapabilities(PhoneAccount.CAPABILITY_CALL_PROVIDER)
- .setExtras(Bundle.forPair(PhoneAccount.EXTRA_SORT_ORDER, "B"))
+ .setExtras(account2Extras)
.build();
PhoneAccount account3 = new PhoneAccount.Builder(
@@ -814,18 +818,23 @@
Mockito.mock(IConnectionService.class));
mComponentContextFixture.addConnectionService(componentZ,
Mockito.mock(IConnectionService.class));
+
+ Bundle account1Extras = new Bundle();
+ account1Extras.putInt(PhoneAccount.EXTRA_SORT_ORDER, 2);
PhoneAccount account1 = new PhoneAccount.Builder(makeQuickAccountHandle(
makeQuickConnectionServiceComponentName(), "y"), "y")
.setCapabilities(PhoneAccount.CAPABILITY_CALL_PROVIDER |
PhoneAccount.CAPABILITY_SIM_SUBSCRIPTION)
- .setExtras(Bundle.forPair(PhoneAccount.EXTRA_SORT_ORDER, "2"))
+ .setExtras(account1Extras)
.build();
+ Bundle account2Extras = new Bundle();
+ account2Extras.putInt(PhoneAccount.EXTRA_SORT_ORDER, 1);
PhoneAccount account2 = new PhoneAccount.Builder(makeQuickAccountHandle(
makeQuickConnectionServiceComponentName(), "z"), "z")
.setCapabilities(PhoneAccount.CAPABILITY_CALL_PROVIDER |
PhoneAccount.CAPABILITY_SIM_SUBSCRIPTION)
- .setExtras(Bundle.forPair(PhoneAccount.EXTRA_SORT_ORDER, "1"))
+ .setExtras(account2Extras)
.build();
PhoneAccount account3 = new PhoneAccount.Builder(makeQuickAccountHandle(