diff --git a/packages/SystemUI/src/com/android/keyguard/CarrierTextManager.java b/packages/SystemUI/src/com/android/keyguard/CarrierTextManager.java index 3bf3fb3a1ebd2ef8f3a232d234401e59b44cc83c..b116e297ccbfa2d325db6a5b3b8735fe65aef09b 100644 --- a/packages/SystemUI/src/com/android/keyguard/CarrierTextManager.java +++ b/packages/SystemUI/src/com/android/keyguard/CarrierTextManager.java @@ -308,7 +308,13 @@ public class CarrierTextManager { } else { // Don't listen and clear out the text when the device isn't a phone. mMainExecutor.execute(() -> callback.updateCarrierInfo( - new CarrierTextCallbackInfo("", null, false, null) + new CarrierTextCallbackInfo( + /* carrierText= */ "", + /* listOfCarriers= */ null, + /* anySimReady= */ false, + /* isInSatelliteMode= */ false, + /* subscriptionIds= */ null, + /* airplaneMode= */ false) )); } } else { @@ -448,10 +454,12 @@ public class CarrierTextManager { displayText = currentSatelliteText; } + boolean isInSatelliteMode = mSatelliteCarrierText != null; final CarrierTextCallbackInfo info = new CarrierTextCallbackInfo( displayText, carrierNames, !allSimsMissing, + isInSatelliteMode, subsIds, airplaneMode); mLogger.logCallbackSentFromUpdate(info); @@ -757,21 +765,35 @@ public class CarrierTextManager { public final CharSequence carrierText; public final CharSequence[] listOfCarriers; public final boolean anySimReady; + public final boolean isInSatelliteMode; public final int[] subscriptionIds; public boolean airplaneMode; @VisibleForTesting - public CarrierTextCallbackInfo(CharSequence carrierText, CharSequence[] listOfCarriers, - boolean anySimReady, int[] subscriptionIds) { - this(carrierText, listOfCarriers, anySimReady, subscriptionIds, false); + public CarrierTextCallbackInfo( + CharSequence carrierText, + CharSequence[] listOfCarriers, + boolean anySimReady, + int[] subscriptionIds) { + this(carrierText, + listOfCarriers, + anySimReady, + /* isInSatelliteMode= */ false, + subscriptionIds, + /* airplaneMode= */ false); } - @VisibleForTesting - public CarrierTextCallbackInfo(CharSequence carrierText, CharSequence[] listOfCarriers, - boolean anySimReady, int[] subscriptionIds, boolean airplaneMode) { + public CarrierTextCallbackInfo( + CharSequence carrierText, + CharSequence[] listOfCarriers, + boolean anySimReady, + boolean isInSatelliteMode, + int[] subscriptionIds, + boolean airplaneMode) { this.carrierText = carrierText; this.listOfCarriers = listOfCarriers; this.anySimReady = anySimReady; + this.isInSatelliteMode = isInSatelliteMode; this.subscriptionIds = subscriptionIds; this.airplaneMode = airplaneMode; } @@ -782,6 +804,7 @@ public class CarrierTextManager { + "carrierText=" + carrierText + ", listOfCarriers=" + Arrays.toString(listOfCarriers) + ", anySimReady=" + anySimReady + + ", isInSatelliteMode=" + isInSatelliteMode + ", subscriptionIds=" + Arrays.toString(subscriptionIds) + ", airplaneMode=" + airplaneMode + '}'; diff --git a/packages/SystemUI/src/com/android/systemui/shade/carrier/ShadeCarrierGroupController.java b/packages/SystemUI/src/com/android/systemui/shade/carrier/ShadeCarrierGroupController.java index 5e4b1732bd4234444c742280a5197fa94747dc32..a171d33ddb479c022abe7e75595cc49438aa37b3 100644 --- a/packages/SystemUI/src/com/android/systemui/shade/carrier/ShadeCarrierGroupController.java +++ b/packages/SystemUI/src/com/android/systemui/shade/carrier/ShadeCarrierGroupController.java @@ -381,7 +381,10 @@ public class ShadeCarrierGroupController { mLogger.logHandleUpdateCarrierInfo(info); mNoSimTextView.setVisibility(View.GONE); - if (!info.airplaneMode && info.anySimReady) { + if (info.isInSatelliteMode) { + mLogger.logUsingSatelliteText(info.carrierText); + showSingleText(info.carrierText); + } else if (!info.airplaneMode && info.anySimReady) { boolean[] slotSeen = new boolean[SIM_SLOTS]; if (info.listOfCarriers.length == info.subscriptionIds.length) { mLogger.logUsingSimViews(); @@ -416,22 +419,31 @@ public class ShadeCarrierGroupController { info.listOfCarriers.length, info.subscriptionIds.length); } } else { + // No sims or airplane mode (but not WFC), so just show the main carrier text. mLogger.logUsingNoSimView(info.carrierText); - // No sims or airplane mode (but not WFC). Do not show ShadeCarrierGroup, - // instead just show info.carrierText in a different view. - for (int i = 0; i < SIM_SLOTS; i++) { - mInfos[i] = mInfos[i].changeVisibility(false); - mCarrierGroups[i].setCarrierText(""); - mCarrierGroups[i].setVisibility(View.GONE); - } - mNoSimTextView.setText(info.carrierText); - if (!TextUtils.isEmpty(info.carrierText)) { - mNoSimTextView.setVisibility(View.VISIBLE); - } + showSingleText(info.carrierText); } handleUpdateState(); // handleUpdateCarrierInfo is always called from main thread. } + /** + * Shows only the given text in a single TextView and hides ShadeCarrierGroup (which would show + * individual SIM details). + */ + private void showSingleText(CharSequence text) { + for (int i = 0; i < SIM_SLOTS; i++) { + mInfos[i] = mInfos[i].changeVisibility(false); + mCarrierGroups[i].setCarrierText(""); + mCarrierGroups[i].setVisibility(View.GONE); + } + // TODO(b/341841138): Re-name this view now that it's being used for more than just the + // no-SIM case. + mNoSimTextView.setText(text); + if (!TextUtils.isEmpty(text)) { + mNoSimTextView.setVisibility(View.VISIBLE); + } + } + private static class H extends Handler { private Consumer<CarrierTextManager.CarrierTextCallbackInfo> mUpdateCarrierInfo; private Runnable mUpdateState; diff --git a/packages/SystemUI/src/com/android/systemui/shade/carrier/ShadeCarrierGroupControllerLogger.kt b/packages/SystemUI/src/com/android/systemui/shade/carrier/ShadeCarrierGroupControllerLogger.kt index af06a356002b6fe63b147bc9d8e68e6995bfc188..b563cd9f0301fc52d40ff7029f7eff41bb99c3cb 100644 --- a/packages/SystemUI/src/com/android/systemui/shade/carrier/ShadeCarrierGroupControllerLogger.kt +++ b/packages/SystemUI/src/com/android/systemui/shade/carrier/ShadeCarrierGroupControllerLogger.kt @@ -65,6 +65,15 @@ constructor(@ShadeCarrierGroupControllerLog val buffer: LogBuffer) { ) } + fun logUsingSatelliteText(text: CharSequence) { + buffer.log( + TAG, + LogLevel.VERBOSE, + { str1 = "$text" }, + { "â”— updating No SIM view with satellite text=$str1" }, + ) + } + fun logUsingSimViews() { buffer.log(TAG, LogLevel.VERBOSE, {}, { "â”— updating SIM views" }) } diff --git a/packages/SystemUI/tests/src/com/android/keyguard/CarrierTextManagerTest.java b/packages/SystemUI/tests/src/com/android/keyguard/CarrierTextManagerTest.java index 8c4179d385ba15a73a66814768b63f6c1693f720..0a3225eecbe4fd5f0405624563bb9133619c57b3 100644 --- a/packages/SystemUI/tests/src/com/android/keyguard/CarrierTextManagerTest.java +++ b/packages/SystemUI/tests/src/com/android/keyguard/CarrierTextManagerTest.java @@ -161,8 +161,11 @@ public class CarrierTextManagerTest extends SysuiTestCase { doAnswer(this::checkMainThread).when(mKeyguardUpdateMonitor) .removeCallback(any(KeyguardUpdateMonitorCallback.class)); - mCarrierTextCallbackInfo = new CarrierTextManager.CarrierTextCallbackInfo("", - new CharSequence[]{}, false, new int[]{}); + mCarrierTextCallbackInfo = new CarrierTextManager.CarrierTextCallbackInfo( + /* carrierText= */ "", + /* listOfCarriers= */ new CharSequence[]{}, + /* anySimReady= */ false, + /* subscriptionIds= */ new int[]{}); when(mTelephonyManager.getSupportedModemCount()).thenReturn(3); when(mTelephonyManager.getActiveModemCount()).thenReturn(3); @@ -473,7 +476,7 @@ public class CarrierTextManagerTest extends SysuiTestCase { } @Test - public void carrierText_satelliteTextNull_notUsed() { + public void carrierText_satelliteTextNull_isSatelliteFalse_textNotUsed() { reset(mCarrierTextCallback); List<SubscriptionInfo> list = new ArrayList<>(); list.add(TEST_SUBSCRIPTION); @@ -491,11 +494,37 @@ public class CarrierTextManagerTest extends SysuiTestCase { CarrierTextManager.CarrierTextCallbackInfo.class); FakeExecutor.exhaustExecutors(mMainExecutor, mBgExecutor); - // THEN the default subscription carrier text is used + // THEN satellite mode is false and the default subscription carrier text is used verify(mCarrierTextCallback).updateCarrierInfo(captor.capture()); + assertThat(captor.getValue().isInSatelliteMode).isFalse(); assertThat(captor.getValue().carrierText).isEqualTo(TEST_CARRIER); } + @Test + public void carrierText_hasSatelliteText_isSatelliteTrue_textUsed() { + reset(mCarrierTextCallback); + List<SubscriptionInfo> list = new ArrayList<>(); + list.add(TEST_SUBSCRIPTION); + when(mKeyguardUpdateMonitor.getSimState(anyInt())).thenReturn( + TelephonyManager.SIM_STATE_READY); + when(mKeyguardUpdateMonitor.getFilteredSubscriptionInfo()).thenReturn(list); + mKeyguardUpdateMonitor.mServiceStates = new HashMap<>(); + + // WHEN the satellite text is non-null + mSatelliteViewModel.getCarrierText().setValue("Satellite Test Text"); + mTestScope.getTestScheduler().runCurrent(); + + ArgumentCaptor<CarrierTextManager.CarrierTextCallbackInfo> captor = + ArgumentCaptor.forClass( + CarrierTextManager.CarrierTextCallbackInfo.class); + FakeExecutor.exhaustExecutors(mMainExecutor, mBgExecutor); + + // THEN satellite mode is true and the satellite text is used + verify(mCarrierTextCallback).updateCarrierInfo(captor.capture()); + assertThat(captor.getValue().isInSatelliteMode).isTrue(); + assertThat(captor.getValue().carrierText).isEqualTo("Satellite Test Text"); + } + @Test public void carrierText_satelliteTextUpdates_autoTriggersCallback() { reset(mCarrierTextCallback); @@ -517,6 +546,7 @@ public class CarrierTextManagerTest extends SysuiTestCase { FakeExecutor.exhaustExecutors(mMainExecutor, mBgExecutor); verify(mCarrierTextCallback).updateCarrierInfo(captor.capture()); // AND use the satellite text as the carrier text + assertThat(captor.getValue().isInSatelliteMode).isTrue(); assertThat(captor.getValue().carrierText).isEqualTo("Test satellite text"); // WHEN the satellite text is reset to null @@ -528,6 +558,7 @@ public class CarrierTextManagerTest extends SysuiTestCase { // that doesn't include the satellite info FakeExecutor.exhaustExecutors(mMainExecutor, mBgExecutor); verify(mCarrierTextCallback).updateCarrierInfo(captor.capture()); + assertThat(captor.getValue().isInSatelliteMode).isFalse(); assertThat(captor.getValue().carrierText).isEqualTo(TEST_CARRIER); } @@ -566,10 +597,11 @@ public class CarrierTextManagerTest extends SysuiTestCase { mCarrierTextManager.setListening(mCarrierTextCallback); // THEN we should automatically re-trigger #updateCarrierText and get callback info - // that includes the new satellite text + // that includes the new satellite state and text mTestScope.getTestScheduler().runCurrent(); FakeExecutor.exhaustExecutors(mMainExecutor, mBgExecutor); verify(mCarrierTextCallback).updateCarrierInfo(captor.capture()); + assertThat(captor.getValue().isInSatelliteMode).isTrue(); assertThat(captor.getValue().carrierText).isEqualTo("New satellite text"); } diff --git a/packages/SystemUI/tests/src/com/android/systemui/shade/carrier/ShadeCarrierGroupControllerTest.java b/packages/SystemUI/tests/src/com/android/systemui/shade/carrier/ShadeCarrierGroupControllerTest.java index 5363c57c1bad5b267c5da507a2da7b164e5b79e0..308b3708e40716a35c59f99bcb0c7588d0b5df41 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/shade/carrier/ShadeCarrierGroupControllerTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/shade/carrier/ShadeCarrierGroupControllerTest.java @@ -312,9 +312,10 @@ public class ShadeCarrierGroupControllerTest extends LeakCheckedTest { info = new CarrierTextManager.CarrierTextCallbackInfo( "", new CharSequence[]{""}, - true, + /* anySimReady= */ true, + /* isInSatelliteMode= */ false, new int[]{0}, - true /* airplaneMode */); + /* airplaneMode= */ true); mCallback.updateCarrierInfo(info); mTestableLooper.processAllMessages(); assertEquals(View.GONE, mShadeCarrierGroup.getNoSimTextView().getVisibility()); @@ -326,14 +327,58 @@ public class ShadeCarrierGroupControllerTest extends LeakCheckedTest { info = new CarrierTextManager.CarrierTextCallbackInfo( "", new CharSequence[]{FIRST_CARRIER_NAME, ""}, - true, + /* anySimReady= */ true, + /* isInSatelliteMode= */ false, new int[]{0, 1}, - false /* airplaneMode */); + /* airplaneMode= */ false); mCallback.updateCarrierInfo(info); mTestableLooper.processAllMessages(); assertEquals(View.VISIBLE, mShadeCarrierGroupController.getShadeCarrierVisibility(0)); } + @Test + public void isInSatelliteMode_true_noSimViewShownWithText() { + CarrierTextManager.CarrierTextCallbackInfo + info = new CarrierTextManager.CarrierTextCallbackInfo( + "Satellite Mode Test", + new CharSequence[]{FIRST_CARRIER_NAME}, + /* anySimReady= */ true, + /* isInSatelliteMode= */ true, + new int[]{1}, + /* airplaneMode= */ false); + + mCallback.updateCarrierInfo(info); + mTestableLooper.processAllMessages(); + + assertThat(mShadeCarrierGroup.getNoSimTextView().getVisibility()).isEqualTo(View.VISIBLE); + assertThat(mShadeCarrierGroup.getNoSimTextView().getText()).isEqualTo( + "Satellite Mode Test"); + + verify(mShadeCarrier1).setVisibility(View.GONE); + verify(mShadeCarrier2).setVisibility(View.GONE); + verify(mShadeCarrier3).setVisibility(View.GONE); + } + + @Test + public void isInSatelliteMode_false_normalSimViewsShown() { + CarrierTextManager.CarrierTextCallbackInfo + info = new CarrierTextManager.CarrierTextCallbackInfo( + "Satellite Mode Test", + new CharSequence[]{FIRST_CARRIER_NAME, SECOND_CARRIER_NAME}, + /* anySimReady= */ true, + /* isInSatelliteMode= */ false, + new int[]{0, 1}, + /* airplaneMode= */ false); + + mCallback.updateCarrierInfo(info); + mTestableLooper.processAllMessages(); + + assertThat(mShadeCarrierGroup.getNoSimTextView().getVisibility()).isEqualTo(View.GONE); + + verify(mShadeCarrier1).setVisibility(View.VISIBLE); + verify(mShadeCarrier2).setVisibility(View.VISIBLE); + } + @Test public void testListenerNotCalledOnRegistreation() { mShadeCarrierGroupController @@ -350,8 +395,7 @@ public class ShadeCarrierGroupControllerTest extends LeakCheckedTest { SINGLE_CARRIER_TEXT, new CharSequence[]{SINGLE_CARRIER_TEXT}, true, - new int[]{0}, - false /* airplaneMode */); + new int[]{0}); mCallback.updateCarrierInfo(info); mTestableLooper.processAllMessages(); @@ -369,8 +413,7 @@ public class ShadeCarrierGroupControllerTest extends LeakCheckedTest { MULTI_CARRIER_TEXT, new CharSequence[]{FIRST_CARRIER_NAME, SECOND_CARRIER_NAME}, true, - new int[]{0, 1}, - false /* airplaneMode */); + new int[]{0, 1}); mCallback.updateCarrierInfo(info); mTestableLooper.processAllMessages(); @@ -387,16 +430,14 @@ public class ShadeCarrierGroupControllerTest extends LeakCheckedTest { SINGLE_CARRIER_TEXT, new CharSequence[]{FIRST_CARRIER_NAME}, true, - new int[]{0}, - false /* airplaneMode */); + new int[]{0}); CarrierTextManager.CarrierTextCallbackInfo multiCarrierInfo = new CarrierTextManager.CarrierTextCallbackInfo( MULTI_CARRIER_TEXT, new CharSequence[]{FIRST_CARRIER_NAME, SECOND_CARRIER_NAME}, true, - new int[]{0, 1}, - false /* airplaneMode */); + new int[]{0, 1}); mCallback.updateCarrierInfo(singleCarrierInfo); mTestableLooper.processAllMessages(); @@ -421,8 +462,7 @@ public class ShadeCarrierGroupControllerTest extends LeakCheckedTest { SINGLE_CARRIER_TEXT, new CharSequence[]{FIRST_CARRIER_NAME}, true, - new int[]{0}, - false /* airplaneMode */); + new int[]{0}); mCallback.updateCarrierInfo(singleCarrierInfo); mTestableLooper.processAllMessages(); @@ -443,8 +483,7 @@ public class ShadeCarrierGroupControllerTest extends LeakCheckedTest { MULTI_CARRIER_TEXT, new CharSequence[]{FIRST_CARRIER_NAME, SECOND_CARRIER_NAME}, true, - new int[]{0, 1}, - false /* airplaneMode */); + new int[]{0, 1}); mCallback.updateCarrierInfo(multiCarrierInfo); mTestableLooper.processAllMessages();