Fix incorrect text when on Airplane Mode

Only generate missing sim text if there are no CarrierName present AND
no sims READY. This was an issue when airplane mode with WFC.

Also, replace using mCarrierGroups[0] for its text when the sims are
missing. Instead use a different view that is made visible when all the
QSCarrierGroups should be invisible.

Test: manual, using APM
Test: atest
Fixes: 139556559

Change-Id: I9d83b0eb2a21b786d50c243903bf32b6e761dc77
This commit is contained in:
Fabian Kozynski
2019-08-29 09:47:07 -04:00
parent 4617a582a7
commit 0f49f207c6
4 changed files with 123 additions and 40 deletions

View File

@@ -25,6 +25,17 @@
android:orientation="horizontal">
<com.android.systemui.util.AutoMarqueeTextView
android:id="@+id/no_carrier_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="@style/TextAppearance.QS.Status"
android:textDirection="locale"
android:marqueeRepeatLimit="marquee_forever"
android:singleLine="true"
android:maxEms="7"
android:visibility="gone"/>
<include
layout="@layout/qs_carrier"
android:id="@+id/carrier1"

View File

@@ -299,7 +299,9 @@ public class CarrierTextController {
}
}
}
if (allSimsMissing) {
// Only create "No SIM card" if no cards with CarrierName && no wifi when some sim is READY
// This condition will also be true always when numSubs == 0
if (allSimsMissing && !anySimReadyAndInService) {
if (numSubs != 0) {
// Shows "No SIM card | Emergency calls only" on devices that are voice-capable.
// This depends on mPlmn containing the text "Emergency calls only" when the radio

View File

@@ -27,6 +27,7 @@ import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.annotation.VisibleForTesting;
@@ -55,6 +56,7 @@ public class QSCarrierGroup extends LinearLayout implements
private View[] mCarrierDividers = new View[SIM_SLOTS - 1];
private QSCarrier[] mCarrierGroups = new QSCarrier[SIM_SLOTS];
private TextView mNoSimTextView;
private final CellSignalState[] mInfos = new CellSignalState[SIM_SLOTS];
private CarrierTextController mCarrierTextController;
private ActivityStarter mActivityStarter;
@@ -94,10 +96,13 @@ public class QSCarrierGroup extends LinearLayout implements
mCarrierDividers[0] = findViewById(R.id.qs_carrier_divider1);
mCarrierDividers[1] = findViewById(R.id.qs_carrier_divider2);
mNoSimTextView = findViewById(R.id.no_carrier_text);
for (int i = 0; i < SIM_SLOTS; i++) {
mInfos[i] = new CellSignalState();
mCarrierGroups[i].setOnClickListener(this);
}
mNoSimTextView.setOnClickListener(this);
CharSequence separator = mContext.getString(
com.android.internal.R.string.kg_text_message_separator);
@@ -155,50 +160,47 @@ public class QSCarrierGroup extends LinearLayout implements
@Override
public void updateCarrierInfo(CarrierTextController.CarrierTextCallbackInfo info) {
if (info.airplaneMode) {
setVisibility(View.GONE);
} else {
setVisibility(View.VISIBLE);
if (info.anySimReady) {
boolean[] slotSeen = new boolean[SIM_SLOTS];
if (info.listOfCarriers.length == info.subscriptionIds.length) {
for (int i = 0; i < SIM_SLOTS && i < info.listOfCarriers.length; i++) {
int slot = getSlotIndex(info.subscriptionIds[i]);
if (slot >= SIM_SLOTS) {
Log.w(TAG, "updateInfoCarrier - slot: " + slot);
continue;
}
if (slot == SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
Log.e(TAG,
"Invalid SIM slot index for subscription: "
+ info.subscriptionIds[i]);
continue;
}
mInfos[slot].visible = true;
slotSeen[slot] = true;
mCarrierGroups[slot].setCarrierText(
info.listOfCarriers[i].toString().trim());
mCarrierGroups[slot].setVisibility(View.VISIBLE);
mNoSimTextView.setVisibility(View.GONE);
if (!info.airplaneMode && info.anySimReady) {
boolean[] slotSeen = new boolean[SIM_SLOTS];
if (info.listOfCarriers.length == info.subscriptionIds.length) {
for (int i = 0; i < SIM_SLOTS && i < info.listOfCarriers.length; i++) {
int slot = getSlotIndex(info.subscriptionIds[i]);
if (slot >= SIM_SLOTS) {
Log.w(TAG, "updateInfoCarrier - slot: " + slot);
continue;
}
for (int i = 0; i < SIM_SLOTS; i++) {
if (!slotSeen[i]) {
mInfos[i].visible = false;
mCarrierGroups[i].setVisibility(View.GONE);
}
if (slot == SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
Log.e(TAG,
"Invalid SIM slot index for subscription: "
+ info.subscriptionIds[i]);
continue;
}
mInfos[slot].visible = true;
slotSeen[slot] = true;
mCarrierGroups[slot].setCarrierText(
info.listOfCarriers[i].toString().trim());
mCarrierGroups[slot].setVisibility(View.VISIBLE);
}
for (int i = 0; i < SIM_SLOTS; i++) {
if (!slotSeen[i]) {
mInfos[i].visible = false;
mCarrierGroups[i].setVisibility(View.GONE);
}
} else {
Log.e(TAG, "Carrier information arrays not of same length");
}
} else {
mInfos[0].visible = false;
mCarrierGroups[0].setCarrierText(info.carrierText);
mCarrierGroups[0].setVisibility(View.VISIBLE);
for (int i = 1; i < SIM_SLOTS; i++) {
mInfos[i].visible = false;
mCarrierGroups[i].setCarrierText("");
mCarrierGroups[i].setVisibility(View.GONE);
}
Log.e(TAG, "Carrier information arrays not of same length");
}
} else {
// No sims or airplane mode (but not WFC). Do not show QSCarrierGroup, instead just show
// info.carrierText in a different view.
for (int i = 0; i < SIM_SLOTS; i++) {
mInfos[i].visible = false;
mCarrierGroups[i].setCarrierText("");
mCarrierGroups[i].setVisibility(View.GONE);
}
mNoSimTextView.setText(info.carrierText);
mNoSimTextView.setVisibility(View.VISIBLE);
}
handleUpdateState();
}

View File

@@ -22,11 +22,14 @@ import static android.telephony.SubscriptionManager.DATA_ROAMING_ENABLE;
import static android.telephony.SubscriptionManager.NAME_SOURCE_DEFAULT_SOURCE;
import static junit.framework.Assert.assertTrue;
import static junit.framework.TestCase.assertFalse;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.verify;
@@ -34,15 +37,18 @@ import static org.mockito.Mockito.when;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.os.Handler;
import android.provider.Settings;
import android.telephony.ServiceState;
import android.telephony.SubscriptionInfo;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
import android.test.suitebuilder.annotation.SmallTest;
import android.testing.AndroidTestingRunner;
import android.testing.TestableLooper;
import android.text.TextUtils;
import com.android.internal.telephony.IccCardConstants;
import com.android.systemui.Dependency;
@@ -76,6 +82,9 @@ public class CarrierTextControllerTest extends SysuiTestCase {
TEST_CARRIER, TEST_CARRIER, NAME_SOURCE_DEFAULT_SOURCE, 0xFFFFFF, "",
DATA_ROAMING_DISABLE, null, null, null, null, false, null, "", false, null,
TEST_CARRIER_ID, 0);
private static final SubscriptionInfo TEST_SUBSCRIPTION_NULL = new SubscriptionInfo(0, "", 0,
TEST_CARRIER, null, NAME_SOURCE_DEFAULT_SOURCE, 0xFFFFFF, "", DATA_ROAMING_DISABLE,
null, null, null, null, false, null, "");
private static final SubscriptionInfo TEST_SUBSCRIPTION_ROAMING = new SubscriptionInfo(0, "", 0,
TEST_CARRIER, TEST_CARRIER, NAME_SOURCE_DEFAULT_SOURCE, 0xFFFFFF, "",
DATA_ROAMING_ENABLE, null, null, null, null, false, null, "");
@@ -280,6 +289,65 @@ public class CarrierTextControllerTest extends SysuiTestCase {
assertEquals(1, info.subscriptionIds.length);
}
@Test
public void testCarrierText_noTextOnReadySimWhenNull() {
reset(mCarrierTextCallback);
List<SubscriptionInfo> list = new ArrayList<>();
list.add(TEST_SUBSCRIPTION_NULL);
when(mKeyguardUpdateMonitor.getSimState(anyInt())).thenReturn(IccCardConstants.State.READY);
when(mKeyguardUpdateMonitor.getFilteredSubscriptionInfo(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());
assertTrue("Carrier text should be empty, instead it's " + captor.getValue().carrierText,
TextUtils.isEmpty(captor.getValue().carrierText));
assertFalse("No SIM should be available", captor.getValue().anySimReady);
}
@Test
public void testCarrierText_noTextOnReadySimWhenNull_airplaneMode_wifiOn() {
Settings.Global.putInt(mContext.getContentResolver(), Settings.Global.AIRPLANE_MODE_ON, 1);
reset(mCarrierTextCallback);
List<SubscriptionInfo> list = new ArrayList<>();
list.add(TEST_SUBSCRIPTION_NULL);
when(mKeyguardUpdateMonitor.getSimState(anyInt())).thenReturn(IccCardConstants.State.READY);
when(mKeyguardUpdateMonitor.getFilteredSubscriptionInfo(anyBoolean())).thenReturn(list);
mockWifi();
mKeyguardUpdateMonitor.mServiceStates = new HashMap<>();
ServiceState ss = mock(ServiceState.class);
when(ss.getDataRegState()).thenReturn(ServiceState.STATE_IN_SERVICE);
mKeyguardUpdateMonitor.mServiceStates.put(TEST_SUBSCRIPTION_NULL.getSubscriptionId(), ss);
ArgumentCaptor<CarrierTextController.CarrierTextCallbackInfo> captor =
ArgumentCaptor.forClass(
CarrierTextController.CarrierTextCallbackInfo.class);
mCarrierTextController.updateCarrierText();
mTestableLooper.processAllMessages();
verify(mCarrierTextCallback).updateCarrierInfo(captor.capture());
assertFalse("No SIM should be available", captor.getValue().anySimReady);
// There's no airplane mode if at least one SIM is State.READY and there's wifi
assertFalse("Device should not be in airplane mode", captor.getValue().airplaneMode);
assertNotEquals(AIRPLANE_MODE_TEXT, captor.getValue().carrierText);
}
private void mockWifi() {
when(mWifiManager.isWifiEnabled()).thenReturn(true);
WifiInfo wifiInfo = mock(WifiInfo.class);
when(wifiInfo.getBSSID()).thenReturn("");
when(mWifiManager.getConnectionInfo()).thenReturn(wifiInfo);
}
@Test
public void testCreateInfo_noSubscriptions() {
reset(mCarrierTextCallback);