[Provider mode] Carrier item display network type on slice.
Bug: 176871752 Test: (PASS)atest NetworkProviderWorkerTest (PASS)atest ProviderModelSliceTest (PASS)atest ProviderModelSliceHelperTest Change-Id: I79b4c3d45a52f0be0c058044f1d79a7056386193
This commit is contained in:
@@ -116,7 +116,9 @@ public class ProviderModelSlice extends WifiSlice {
|
||||
// Second section: Add a carrier item.
|
||||
if (hasCarrier) {
|
||||
mHelper.updateTelephony();
|
||||
listBuilder.addRow(mHelper.createCarrierRow());
|
||||
listBuilder.addRow(
|
||||
mHelper.createCarrierRow(
|
||||
worker != null ? worker.getNetworkTypeDescription() : ""));
|
||||
maxListSize--;
|
||||
}
|
||||
|
||||
|
@@ -120,9 +120,9 @@ public class ProviderModelSliceHelper {
|
||||
return true;
|
||||
}
|
||||
|
||||
protected ListBuilder.RowBuilder createCarrierRow() {
|
||||
protected ListBuilder.RowBuilder createCarrierRow(String networkTypeDescription) {
|
||||
final String title = getMobileTitle();
|
||||
final String summary = getMobileSummary();
|
||||
final String summary = getMobileSummary(networkTypeDescription);
|
||||
Drawable drawable = mContext.getDrawable(
|
||||
R.drawable.ic_signal_strength_zero_bar_no_internet);
|
||||
try {
|
||||
@@ -241,13 +241,12 @@ public class ProviderModelSliceHelper {
|
||||
NO_CELL_DATA_TYPE_ICON, false);
|
||||
}
|
||||
|
||||
private String getMobileSummary() {
|
||||
String summary = "";
|
||||
//TODO: get radio technology.
|
||||
String networkType = "";
|
||||
private String getMobileSummary(String networkTypeDescription) {
|
||||
String summary = networkTypeDescription;
|
||||
if (isDataSimActive()) {
|
||||
summary = mContext.getString(R.string.preference_summary_default_combination,
|
||||
mContext.getString(R.string.mobile_data_connection_active), networkType);
|
||||
mContext.getString(R.string.mobile_data_connection_active),
|
||||
networkTypeDescription);
|
||||
} else if (!isMobileDataEnabled()) {
|
||||
summary = mContext.getString(R.string.mobile_data_off_summary);
|
||||
}
|
||||
|
@@ -16,6 +16,9 @@
|
||||
|
||||
package com.android.settings.network.telephony;
|
||||
|
||||
import static com.android.settingslib.mobile.MobileMappings.getIconKey;
|
||||
import static com.android.settingslib.mobile.MobileMappings.mapIconSets;
|
||||
|
||||
import android.content.Context;
|
||||
import android.database.ContentObserver;
|
||||
import android.net.Uri;
|
||||
@@ -34,6 +37,8 @@ import com.android.settings.network.MobileDataContentObserver;
|
||||
import com.android.settings.network.MobileDataEnabledListener;
|
||||
import com.android.settings.network.SubscriptionsChangeListener;
|
||||
import com.android.settings.wifi.slice.WifiScanWorker;
|
||||
import com.android.settingslib.mobile.MobileMappings;
|
||||
import com.android.settingslib.mobile.MobileMappings.Config;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.concurrent.Executor;
|
||||
@@ -58,6 +63,10 @@ public class NetworkProviderWorker extends WifiScanWorker implements
|
||||
@VisibleForTesting
|
||||
final PhoneStateListener mPhoneStateListener;
|
||||
private TelephonyManager mTelephonyManager;
|
||||
private Config mConfig = null;
|
||||
private TelephonyDisplayInfo mTelephonyDisplayInfo =
|
||||
new TelephonyDisplayInfo(TelephonyManager.NETWORK_TYPE_UNKNOWN,
|
||||
TelephonyDisplayInfo.OVERRIDE_NETWORK_TYPE_NONE);
|
||||
|
||||
public NetworkProviderWorker(Context context, Uri uri) {
|
||||
super(context, uri);
|
||||
@@ -75,6 +84,7 @@ public class NetworkProviderWorker extends WifiScanWorker implements
|
||||
mDataEnabledListener = new MobileDataEnabledListener(context, this);
|
||||
mConnectivityListener = new DataConnectivityListener(context, this);
|
||||
mSignalStrengthListener = new SignalStrengthListener(context, this);
|
||||
mConfig = getConfig(mContext);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -135,6 +145,7 @@ public class NetworkProviderWorker extends WifiScanWorker implements
|
||||
mTelephonyManager.listen(mPhoneStateListener, PhoneStateListener.LISTEN_SERVICE_STATE
|
||||
| PhoneStateListener.LISTEN_DISPLAY_INFO_CHANGED);
|
||||
mMobileDataObserver.register(mContext, mDefaultDataSubid);
|
||||
mConfig = getConfig(mContext);
|
||||
} else {
|
||||
mSignalStrengthListener.updateSubscriptionIds(Collections.emptySet());
|
||||
}
|
||||
@@ -217,6 +228,7 @@ public class NetworkProviderWorker extends WifiScanWorker implements
|
||||
@Override
|
||||
public void onDisplayInfoChanged(TelephonyDisplayInfo telephonyDisplayInfo) {
|
||||
Log.d(TAG, "onDisplayInfoChanged: telephonyDisplayInfo=" + telephonyDisplayInfo);
|
||||
mTelephonyDisplayInfo = telephonyDisplayInfo;
|
||||
updateSlice();
|
||||
}
|
||||
}
|
||||
@@ -225,4 +237,27 @@ public class NetworkProviderWorker extends WifiScanWorker implements
|
||||
int getDefaultDataSubscriptionId() {
|
||||
return SubscriptionManager.getDefaultDataSubscriptionId();
|
||||
}
|
||||
|
||||
|
||||
private String updateNetworkTypeName(Context context, Config config,
|
||||
TelephonyDisplayInfo telephonyDisplayInfo, int subId) {
|
||||
String iconKey = getIconKey(telephonyDisplayInfo);
|
||||
int resId = mapIconSets(config).get(iconKey).dataContentDescription;
|
||||
return resId != 0
|
||||
? SubscriptionManager.getResourcesForSubId(context, subId).getString(resId) : "";
|
||||
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
Config getConfig(Context context) {
|
||||
return MobileMappings.Config.readConfig(context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get currently description of mobile network type.
|
||||
*/
|
||||
public String getNetworkTypeDescription() {
|
||||
return updateNetworkTypeName(mContext, mConfig, mTelephonyDisplayInfo,
|
||||
mDefaultDataSubid);
|
||||
}
|
||||
}
|
||||
|
@@ -164,18 +164,49 @@ public class ProviderModelSliceHelperTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createCarrierRow_hasDefaultDataSubscriptionId_verifyTitle() {
|
||||
public void createCarrierRow_hasDdsAndActiveNetworkIsNotCellular_verifyTitleAndSummary() {
|
||||
String expectDisplayName = "Name1";
|
||||
String expectedSubtitle = "5G";
|
||||
String networkType = "5G";
|
||||
int defaultDataSubId = SubscriptionManager.getDefaultDataSubscriptionId();
|
||||
when(mSubscriptionManager.getActiveSubscriptionInfo(defaultDataSubId)).thenReturn(
|
||||
mDefaultDataSubscriptionInfo);
|
||||
when(mDefaultDataSubscriptionInfo.getDisplayName()).thenReturn(expectDisplayName);
|
||||
when(mServiceState.getState()).thenReturn(ServiceState.STATE_IN_SERVICE);
|
||||
mBundle.putBoolean(CarrierConfigManager.KEY_INFLATE_SIGNAL_STRENGTH_BOOL, false);
|
||||
addNetworkTransportType(NetworkCapabilities.TRANSPORT_WIFI);
|
||||
when(mTelephonyManager.isDataEnabled()).thenReturn(true);
|
||||
|
||||
ListBuilder.RowBuilder testRowBuild = mProviderModelSliceHelper.createCarrierRow();
|
||||
|
||||
ListBuilder.RowBuilder testRowBuild = mProviderModelSliceHelper.createCarrierRow(
|
||||
networkType);
|
||||
|
||||
assertThat(testRowBuild.getTitle()).isEqualTo(expectDisplayName);
|
||||
assertThat(testRowBuild.getSubtitle()).isEqualTo(expectedSubtitle);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createCarrierRow_hasDdsAndActiveNetworkIsCellular_verifyTitleAndSummary() {
|
||||
String expectDisplayName = "Name1";
|
||||
String networkType = "5G";
|
||||
String connectedText = ResourcesUtils.getResourcesString(mContext,
|
||||
"mobile_data_connection_active");
|
||||
String expectedSubtitle = ResourcesUtils.getResourcesString(mContext,
|
||||
"preference_summary_default_combination", connectedText, networkType);
|
||||
|
||||
int defaultDataSubId = SubscriptionManager.getDefaultDataSubscriptionId();
|
||||
when(mSubscriptionManager.getActiveSubscriptionInfo(defaultDataSubId)).thenReturn(
|
||||
mDefaultDataSubscriptionInfo);
|
||||
when(mDefaultDataSubscriptionInfo.getDisplayName()).thenReturn(expectDisplayName);
|
||||
when(mServiceState.getState()).thenReturn(ServiceState.STATE_IN_SERVICE);
|
||||
mBundle.putBoolean(CarrierConfigManager.KEY_INFLATE_SIGNAL_STRENGTH_BOOL, false);
|
||||
addNetworkTransportType(NetworkCapabilities.TRANSPORT_CELLULAR);
|
||||
|
||||
ListBuilder.RowBuilder testRowBuild = mProviderModelSliceHelper.createCarrierRow(
|
||||
networkType);
|
||||
|
||||
assertThat(testRowBuild.getTitle()).isEqualTo(expectDisplayName);
|
||||
assertThat(testRowBuild.getSubtitle()).isEqualTo(expectedSubtitle);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@@ -302,7 +302,8 @@ public class ProviderModelSliceTest {
|
||||
|
||||
when(mMockCarrierRowBuild.getTitle()).thenReturn("mockRow");
|
||||
when(mMockCarrierRowBuild.getPrimaryAction()).thenReturn(mockSliceAction);
|
||||
when(mProviderModelSliceHelper.createCarrierRow()).thenReturn(mMockCarrierRowBuild);
|
||||
when(mProviderModelSliceHelper.createCarrierRow(anyString())).thenReturn(
|
||||
mMockCarrierRowBuild);
|
||||
}
|
||||
|
||||
private SliceAction getPrimarySliceAction() {
|
||||
|
Reference in New Issue
Block a user