Merge "Fixed concatenation to properly discard empty strings" into qt-dev
am: cc9e2873df
Change-Id: Ia2e2e99134d1a422a4fd569aae26e2b756f04b7f
This commit is contained in:
@@ -383,7 +383,7 @@ public class CarrierTextController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (TextUtils.isEmpty(displayText) && !airplaneMode) {
|
if (TextUtils.isEmpty(displayText) && !airplaneMode) {
|
||||||
displayText = TextUtils.join(mSeparator, carrierNames);
|
displayText = joinNotEmpty(mSeparator, carrierNames);
|
||||||
}
|
}
|
||||||
final CarrierTextCallbackInfo info = new CarrierTextCallbackInfo(
|
final CarrierTextCallbackInfo info = new CarrierTextCallbackInfo(
|
||||||
displayText,
|
displayText,
|
||||||
@@ -546,6 +546,25 @@ public class CarrierTextController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Joins the strings in a sequence using a separator. Empty strings are discarded with no extra
|
||||||
|
* separator added so there are no extra separators that are not needed.
|
||||||
|
*/
|
||||||
|
private static CharSequence joinNotEmpty(CharSequence separator, CharSequence[] sequences) {
|
||||||
|
int length = sequences.length;
|
||||||
|
if (length == 0) return "";
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
for (int i = 0; i < length; i++) {
|
||||||
|
if (!TextUtils.isEmpty(sequences[i])) {
|
||||||
|
if (!TextUtils.isEmpty(sb)) {
|
||||||
|
sb.append(separator);
|
||||||
|
}
|
||||||
|
sb.append(sequences[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
|
||||||
private static List<CharSequence> append(List<CharSequence> list, CharSequence string) {
|
private static List<CharSequence> append(List<CharSequence> list, CharSequence string) {
|
||||||
if (!TextUtils.isEmpty(string)) {
|
if (!TextUtils.isEmpty(string)) {
|
||||||
list.add(string);
|
list.add(string);
|
||||||
|
|||||||
@@ -104,7 +104,8 @@ public class CarrierTextControllerTest extends SysuiTestCase {
|
|||||||
|
|
||||||
mCarrierTextCallbackInfo = new CarrierTextController.CarrierTextCallbackInfo("",
|
mCarrierTextCallbackInfo = new CarrierTextController.CarrierTextCallbackInfo("",
|
||||||
new CharSequence[]{}, false, new int[]{});
|
new CharSequence[]{}, false, new int[]{});
|
||||||
when(mTelephonyManager.getPhoneCount()).thenReturn(2);
|
when(mTelephonyManager.getPhoneCount()).thenReturn(3);
|
||||||
|
|
||||||
mCarrierTextController = new TestCarrierTextController(mContext, SEPARATOR, true, true,
|
mCarrierTextController = new TestCarrierTextController(mContext, SEPARATOR, true, true,
|
||||||
mKeyguardUpdateMonitor);
|
mKeyguardUpdateMonitor);
|
||||||
// This should not start listening on any of the real dependencies
|
// This should not start listening on any of the real dependencies
|
||||||
@@ -130,6 +131,12 @@ public class CarrierTextControllerTest extends SysuiTestCase {
|
|||||||
reset(mCarrierTextCallback);
|
reset(mCarrierTextCallback);
|
||||||
when(mKeyguardUpdateMonitor.getSubscriptionInfo(anyBoolean())).thenReturn(
|
when(mKeyguardUpdateMonitor.getSubscriptionInfo(anyBoolean())).thenReturn(
|
||||||
new ArrayList<>());
|
new ArrayList<>());
|
||||||
|
|
||||||
|
// STOPSHIP(b/130246708) This line makes sure that SubscriptionManager provides the
|
||||||
|
// same answer as KeyguardUpdateMonitor. Remove when this is addressed
|
||||||
|
when(mSubscriptionManager.getActiveSubscriptionInfoList(anyBoolean())).thenReturn(
|
||||||
|
new ArrayList<>());
|
||||||
|
|
||||||
when(mKeyguardUpdateMonitor.getSimState(anyInt())).thenReturn(
|
when(mKeyguardUpdateMonitor.getSimState(anyInt())).thenReturn(
|
||||||
IccCardConstants.State.CARD_IO_ERROR);
|
IccCardConstants.State.CARD_IO_ERROR);
|
||||||
// This should not produce an out of bounds error, even though there are no subscriptions
|
// This should not produce an out of bounds error, even though there are no subscriptions
|
||||||
@@ -173,7 +180,11 @@ public class CarrierTextControllerTest extends SysuiTestCase {
|
|||||||
list.add(TEST_SUBSCRIPTION);
|
list.add(TEST_SUBSCRIPTION);
|
||||||
when(mKeyguardUpdateMonitor.getSimState(anyInt())).thenReturn(IccCardConstants.State.READY);
|
when(mKeyguardUpdateMonitor.getSimState(anyInt())).thenReturn(IccCardConstants.State.READY);
|
||||||
when(mKeyguardUpdateMonitor.getSubscriptionInfo(anyBoolean())).thenReturn(list);
|
when(mKeyguardUpdateMonitor.getSubscriptionInfo(anyBoolean())).thenReturn(list);
|
||||||
|
|
||||||
|
// STOPSHIP(b/130246708) This line makes sure that SubscriptionManager provides the
|
||||||
|
// same answer as KeyguardUpdateMonitor. Remove when this is addressed
|
||||||
when(mSubscriptionManager.getActiveSubscriptionInfoList(anyBoolean())).thenReturn(list);
|
when(mSubscriptionManager.getActiveSubscriptionInfoList(anyBoolean())).thenReturn(list);
|
||||||
|
|
||||||
mKeyguardUpdateMonitor.mServiceStates = new HashMap<>();
|
mKeyguardUpdateMonitor.mServiceStates = new HashMap<>();
|
||||||
|
|
||||||
ArgumentCaptor<CarrierTextController.CarrierTextCallbackInfo> captor =
|
ArgumentCaptor<CarrierTextController.CarrierTextCallbackInfo> captor =
|
||||||
@@ -197,7 +208,11 @@ public class CarrierTextControllerTest extends SysuiTestCase {
|
|||||||
list.add(TEST_SUBSCRIPTION_ROAMING);
|
list.add(TEST_SUBSCRIPTION_ROAMING);
|
||||||
when(mKeyguardUpdateMonitor.getSimState(anyInt())).thenReturn(IccCardConstants.State.READY);
|
when(mKeyguardUpdateMonitor.getSimState(anyInt())).thenReturn(IccCardConstants.State.READY);
|
||||||
when(mKeyguardUpdateMonitor.getSubscriptionInfo(anyBoolean())).thenReturn(list);
|
when(mKeyguardUpdateMonitor.getSubscriptionInfo(anyBoolean())).thenReturn(list);
|
||||||
|
|
||||||
|
// STOPSHIP(b/130246708) This line makes sure that SubscriptionManager provides the
|
||||||
|
// same answer as KeyguardUpdateMonitor. Remove when this is addressed
|
||||||
when(mSubscriptionManager.getActiveSubscriptionInfoList(anyBoolean())).thenReturn(list);
|
when(mSubscriptionManager.getActiveSubscriptionInfoList(anyBoolean())).thenReturn(list);
|
||||||
|
|
||||||
mKeyguardUpdateMonitor.mServiceStates = new HashMap<>();
|
mKeyguardUpdateMonitor.mServiceStates = new HashMap<>();
|
||||||
|
|
||||||
ArgumentCaptor<CarrierTextController.CarrierTextCallbackInfo> captor =
|
ArgumentCaptor<CarrierTextController.CarrierTextCallbackInfo> captor =
|
||||||
@@ -219,6 +234,12 @@ public class CarrierTextControllerTest extends SysuiTestCase {
|
|||||||
reset(mCarrierTextCallback);
|
reset(mCarrierTextCallback);
|
||||||
when(mKeyguardUpdateMonitor.getSubscriptionInfo(anyBoolean())).thenReturn(
|
when(mKeyguardUpdateMonitor.getSubscriptionInfo(anyBoolean())).thenReturn(
|
||||||
new ArrayList<>());
|
new ArrayList<>());
|
||||||
|
|
||||||
|
// STOPSHIP(b/130246708) This line makes sure that SubscriptionManager provides the
|
||||||
|
// same answer as KeyguardUpdateMonitor. Remove when this is addressed
|
||||||
|
when(mSubscriptionManager.getActiveSubscriptionInfoList(anyBoolean())).thenReturn(
|
||||||
|
new ArrayList<>());
|
||||||
|
|
||||||
ArgumentCaptor<CarrierTextController.CarrierTextCallbackInfo> captor =
|
ArgumentCaptor<CarrierTextController.CarrierTextCallbackInfo> captor =
|
||||||
ArgumentCaptor.forClass(
|
ArgumentCaptor.forClass(
|
||||||
CarrierTextController.CarrierTextCallbackInfo.class);
|
CarrierTextController.CarrierTextCallbackInfo.class);
|
||||||
@@ -233,6 +254,121 @@ public class CarrierTextControllerTest extends SysuiTestCase {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCarrierText_twoValidSubscriptions() {
|
||||||
|
reset(mCarrierTextCallback);
|
||||||
|
List<SubscriptionInfo> list = new ArrayList<>();
|
||||||
|
list.add(TEST_SUBSCRIPTION);
|
||||||
|
list.add(TEST_SUBSCRIPTION);
|
||||||
|
when(mKeyguardUpdateMonitor.getSimState(anyInt())).thenReturn(IccCardConstants.State.READY);
|
||||||
|
when(mKeyguardUpdateMonitor.getSubscriptionInfo(anyBoolean())).thenReturn(list);
|
||||||
|
|
||||||
|
// STOPSHIP(b/130246708) This line makes sure that SubscriptionManager provides the
|
||||||
|
// same answer as KeyguardUpdateMonitor. Remove when this is addressed
|
||||||
|
when(mSubscriptionManager.getActiveSubscriptionInfoList(anyBoolean())).thenReturn(list);
|
||||||
|
|
||||||
|
mKeyguardUpdateMonitor.mServiceStates = new HashMap<>();
|
||||||
|
|
||||||
|
ArgumentCaptor<CarrierTextController.CarrierTextCallbackInfo> captor =
|
||||||
|
ArgumentCaptor.forClass(
|
||||||
|
CarrierTextController.CarrierTextCallbackInfo.class);
|
||||||
|
|
||||||
|
mCarrierTextController.updateCarrierText();
|
||||||
|
mTestableLooper.processAllMessages();
|
||||||
|
verify(mCarrierTextCallback).updateCarrierInfo(captor.capture());
|
||||||
|
|
||||||
|
assertEquals(TEST_CARRIER + SEPARATOR + TEST_CARRIER,
|
||||||
|
captor.getValue().carrierText);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCarrierText_oneDisabledSub() {
|
||||||
|
reset(mCarrierTextCallback);
|
||||||
|
List<SubscriptionInfo> list = new ArrayList<>();
|
||||||
|
list.add(TEST_SUBSCRIPTION);
|
||||||
|
list.add(TEST_SUBSCRIPTION);
|
||||||
|
when(mKeyguardUpdateMonitor.getSimState(anyInt()))
|
||||||
|
.thenReturn(IccCardConstants.State.READY)
|
||||||
|
.thenReturn(IccCardConstants.State.NOT_READY);
|
||||||
|
when(mKeyguardUpdateMonitor.getSubscriptionInfo(anyBoolean())).thenReturn(list);
|
||||||
|
|
||||||
|
// STOPSHIP(b/130246708) This line makes sure that SubscriptionManager provides the
|
||||||
|
// same answer as KeyguardUpdateMonitor. Remove when this is addressed
|
||||||
|
when(mSubscriptionManager.getActiveSubscriptionInfoList(anyBoolean())).thenReturn(list);
|
||||||
|
|
||||||
|
mKeyguardUpdateMonitor.mServiceStates = new HashMap<>();
|
||||||
|
|
||||||
|
ArgumentCaptor<CarrierTextController.CarrierTextCallbackInfo> captor =
|
||||||
|
ArgumentCaptor.forClass(
|
||||||
|
CarrierTextController.CarrierTextCallbackInfo.class);
|
||||||
|
|
||||||
|
mCarrierTextController.updateCarrierText();
|
||||||
|
mTestableLooper.processAllMessages();
|
||||||
|
verify(mCarrierTextCallback).updateCarrierInfo(captor.capture());
|
||||||
|
|
||||||
|
assertEquals(TEST_CARRIER,
|
||||||
|
captor.getValue().carrierText);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCarrierText_firstDisabledSub() {
|
||||||
|
reset(mCarrierTextCallback);
|
||||||
|
List<SubscriptionInfo> list = new ArrayList<>();
|
||||||
|
list.add(TEST_SUBSCRIPTION);
|
||||||
|
list.add(TEST_SUBSCRIPTION);
|
||||||
|
when(mKeyguardUpdateMonitor.getSimState(anyInt()))
|
||||||
|
.thenReturn(IccCardConstants.State.NOT_READY)
|
||||||
|
.thenReturn(IccCardConstants.State.READY);
|
||||||
|
when(mKeyguardUpdateMonitor.getSubscriptionInfo(anyBoolean())).thenReturn(list);
|
||||||
|
|
||||||
|
// STOPSHIP(b/130246708) This line makes sure that SubscriptionManager provides the
|
||||||
|
// same answer as KeyguardUpdateMonitor. Remove when this is addressed
|
||||||
|
when(mSubscriptionManager.getActiveSubscriptionInfoList(anyBoolean())).thenReturn(list);
|
||||||
|
|
||||||
|
mKeyguardUpdateMonitor.mServiceStates = new HashMap<>();
|
||||||
|
|
||||||
|
ArgumentCaptor<CarrierTextController.CarrierTextCallbackInfo> captor =
|
||||||
|
ArgumentCaptor.forClass(
|
||||||
|
CarrierTextController.CarrierTextCallbackInfo.class);
|
||||||
|
|
||||||
|
mCarrierTextController.updateCarrierText();
|
||||||
|
mTestableLooper.processAllMessages();
|
||||||
|
verify(mCarrierTextCallback).updateCarrierInfo(captor.capture());
|
||||||
|
|
||||||
|
assertEquals(TEST_CARRIER,
|
||||||
|
captor.getValue().carrierText);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCarrierText_threeSubsMiddleDisabled() {
|
||||||
|
reset(mCarrierTextCallback);
|
||||||
|
List<SubscriptionInfo> list = new ArrayList<>();
|
||||||
|
list.add(TEST_SUBSCRIPTION);
|
||||||
|
list.add(TEST_SUBSCRIPTION);
|
||||||
|
list.add(TEST_SUBSCRIPTION);
|
||||||
|
when(mKeyguardUpdateMonitor.getSimState(anyInt()))
|
||||||
|
.thenReturn(IccCardConstants.State.READY)
|
||||||
|
.thenReturn(IccCardConstants.State.NOT_READY)
|
||||||
|
.thenReturn(IccCardConstants.State.READY);
|
||||||
|
when(mKeyguardUpdateMonitor.getSubscriptionInfo(anyBoolean())).thenReturn(list);
|
||||||
|
mKeyguardUpdateMonitor.mServiceStates = new HashMap<>();
|
||||||
|
|
||||||
|
// STOPSHIP(b/130246708) This line makes sure that SubscriptionManager provides the
|
||||||
|
// same answer as KeyguardUpdateMonitor. Remove when this is addressed
|
||||||
|
when(mSubscriptionManager.getActiveSubscriptionInfoList(anyBoolean())).thenReturn(list);
|
||||||
|
|
||||||
|
ArgumentCaptor<CarrierTextController.CarrierTextCallbackInfo> captor =
|
||||||
|
ArgumentCaptor.forClass(
|
||||||
|
CarrierTextController.CarrierTextCallbackInfo.class);
|
||||||
|
|
||||||
|
mCarrierTextController.updateCarrierText();
|
||||||
|
mTestableLooper.processAllMessages();
|
||||||
|
verify(mCarrierTextCallback).updateCarrierInfo(captor.capture());
|
||||||
|
|
||||||
|
assertEquals(TEST_CARRIER + SEPARATOR + TEST_CARRIER,
|
||||||
|
captor.getValue().carrierText);
|
||||||
|
}
|
||||||
|
|
||||||
public static class TestCarrierTextController extends CarrierTextController {
|
public static class TestCarrierTextController extends CarrierTextController {
|
||||||
private KeyguardUpdateMonitor mKUM;
|
private KeyguardUpdateMonitor mKUM;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user