Merge changes I79b4c3d4,Icc8a7793
* changes: [Provider mode] Carrier item display network type on slice. The provider model slice carrier toggle is broke.
This commit is contained in:
committed by
Android (Google) Code Review
commit
8ee28c1baa
@@ -115,7 +115,10 @@ public class ProviderModelSlice extends WifiSlice {
|
||||
|
||||
// Second section: Add a carrier item.
|
||||
if (hasCarrier) {
|
||||
listBuilder.addRow(mHelper.createCarrierRow());
|
||||
mHelper.updateTelephony();
|
||||
listBuilder.addRow(
|
||||
mHelper.createCarrierRow(
|
||||
worker != null ? worker.getNetworkTypeDescription() : ""));
|
||||
maxListSize--;
|
||||
}
|
||||
|
||||
@@ -141,7 +144,7 @@ public class ProviderModelSlice extends WifiSlice {
|
||||
if (worker == null || wifiList == null) {
|
||||
log("wifiList is null");
|
||||
int resId = R.string.non_carrier_network_unavailable;
|
||||
if (!hasCarrier || mHelper.isNoCarrierData()) {
|
||||
if (!hasCarrier || !mHelper.isDataSimActive()) {
|
||||
log("No carrier item or no carrier data.");
|
||||
resId = R.string.all_network_unavailable;
|
||||
}
|
||||
|
@@ -63,7 +63,7 @@ import java.util.stream.Collectors;
|
||||
public class ProviderModelSliceHelper {
|
||||
private static final String TAG = "ProviderModelSlice";
|
||||
private final SubscriptionManager mSubscriptionManager;
|
||||
private final TelephonyManager mTelephonyManager;
|
||||
private TelephonyManager mTelephonyManager;
|
||||
protected final Context mContext;
|
||||
private CustomSliceable mSliceable;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
@@ -277,4 +276,16 @@ public class ProviderModelSliceHelper {
|
||||
.map(String::trim)
|
||||
.collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
/**
|
||||
* To update the telephony with subid.
|
||||
*/
|
||||
public void updateTelephony() {
|
||||
if (mSubscriptionManager == null || mSubscriptionManager.getDefaultDataSubscriptionId()
|
||||
== mSubscriptionManager.INVALID_SUBSCRIPTION_ID) {
|
||||
return;
|
||||
}
|
||||
mTelephonyManager = mTelephonyManager.createForSubscriptionId(
|
||||
mSubscriptionManager.getDefaultDataSubscriptionId());
|
||||
}
|
||||
}
|
||||
|
@@ -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;
|
||||
@@ -23,7 +26,6 @@ import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.telephony.PhoneStateListener;
|
||||
import android.telephony.ServiceState;
|
||||
import android.telephony.SubscriptionInfo;
|
||||
import android.telephony.SubscriptionManager;
|
||||
import android.telephony.TelephonyDisplayInfo;
|
||||
import android.telephony.TelephonyManager;
|
||||
@@ -35,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;
|
||||
@@ -54,12 +58,15 @@ public class NetworkProviderWorker extends WifiScanWorker implements
|
||||
private SubscriptionsChangeListener mSubscriptionsListener;
|
||||
private MobileDataEnabledListener mDataEnabledListener;
|
||||
private DataConnectivityListener mConnectivityListener;
|
||||
|
||||
private int mDefaultDataSubid = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
|
||||
private final Context mContext;
|
||||
@VisibleForTesting
|
||||
final PhoneStateListener mPhoneStateListener;
|
||||
private final SubscriptionManager mSubscriptionManager;
|
||||
private final TelephonyManager mTelephonyManager;
|
||||
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);
|
||||
@@ -68,27 +75,26 @@ public class NetworkProviderWorker extends WifiScanWorker implements
|
||||
mMobileDataObserver = new DataContentObserver(handler, this);
|
||||
|
||||
mContext = context;
|
||||
mSubscriptionManager = mContext.getSystemService(SubscriptionManager.class);
|
||||
mTelephonyManager = mContext.getSystemService(TelephonyManager.class);
|
||||
mDefaultDataSubid = getDefaultDataSubscriptionId();
|
||||
|
||||
mTelephonyManager = mContext.getSystemService(
|
||||
TelephonyManager.class).createForSubscriptionId(mDefaultDataSubid);
|
||||
mPhoneStateListener = new NetworkProviderPhoneStateListener(handler::post);
|
||||
mSubscriptionsListener = new SubscriptionsChangeListener(context, this);
|
||||
mDataEnabledListener = new MobileDataEnabledListener(context, this);
|
||||
mConnectivityListener = new DataConnectivityListener(context, this);
|
||||
mSignalStrengthListener = new SignalStrengthListener(context, this);
|
||||
mConfig = getConfig(mContext);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSlicePinned() {
|
||||
mMobileDataObserver.register(mContext,
|
||||
getDefaultSubscriptionId(mSubscriptionManager));
|
||||
|
||||
mMobileDataObserver.register(mContext, mDefaultDataSubid);
|
||||
mSubscriptionsListener.start();
|
||||
mDataEnabledListener.start(SubscriptionManager.getDefaultDataSubscriptionId());
|
||||
mDataEnabledListener.start(mDefaultDataSubid);
|
||||
mConnectivityListener.start();
|
||||
mSignalStrengthListener.resume();
|
||||
mTelephonyManager.listen(mPhoneStateListener, PhoneStateListener.LISTEN_SERVICE_STATE
|
||||
| PhoneStateListener.LISTEN_ACTIVE_DATA_SUBSCRIPTION_ID_CHANGE
|
||||
| PhoneStateListener.LISTEN_DISPLAY_INFO_CHANGED);
|
||||
|
||||
super.onSlicePinned();
|
||||
@@ -125,15 +131,23 @@ public class NetworkProviderWorker extends WifiScanWorker implements
|
||||
|
||||
@Override
|
||||
public void onSubscriptionsChanged() {
|
||||
int defaultDataSubId = SubscriptionManager.getDefaultDataSubscriptionId();
|
||||
int defaultDataSubId = getDefaultDataSubscriptionId();
|
||||
Log.d(TAG, "onSubscriptionsChanged: defaultDataSubId:" + defaultDataSubId);
|
||||
if (mDefaultDataSubid == defaultDataSubId) {
|
||||
return;
|
||||
}
|
||||
if (SubscriptionManager.isUsableSubscriptionId(defaultDataSubId)) {
|
||||
mTelephonyManager.listen(mPhoneStateListener, PhoneStateListener.LISTEN_NONE);
|
||||
mMobileDataObserver.unregister(mContext);
|
||||
|
||||
mSignalStrengthListener.updateSubscriptionIds(
|
||||
SubscriptionManager.isUsableSubscriptionId(defaultDataSubId)
|
||||
? Collections.singleton(defaultDataSubId) : Collections.emptySet());
|
||||
if (defaultDataSubId != mDataEnabledListener.getSubId()) {
|
||||
mDataEnabledListener.stop();
|
||||
mDataEnabledListener.start(defaultDataSubId);
|
||||
mSignalStrengthListener.updateSubscriptionIds(Collections.singleton(defaultDataSubId));
|
||||
mTelephonyManager = mTelephonyManager.createForSubscriptionId(defaultDataSubId);
|
||||
mTelephonyManager.listen(mPhoneStateListener, PhoneStateListener.LISTEN_SERVICE_STATE
|
||||
| PhoneStateListener.LISTEN_DISPLAY_INFO_CHANGED);
|
||||
mMobileDataObserver.register(mContext, mDefaultDataSubid);
|
||||
mConfig = getConfig(mContext);
|
||||
} else {
|
||||
mSignalStrengthListener.updateSubscriptionIds(Collections.emptySet());
|
||||
}
|
||||
updateSlice();
|
||||
}
|
||||
@@ -180,6 +194,7 @@ public class NetworkProviderWorker extends WifiScanWorker implements
|
||||
|
||||
/**
|
||||
* To register the observer for mobile data changed.
|
||||
*
|
||||
* @param context the Context object.
|
||||
* @param subId the default data subscription id.
|
||||
*/
|
||||
@@ -190,6 +205,7 @@ public class NetworkProviderWorker extends WifiScanWorker implements
|
||||
|
||||
/**
|
||||
* To unregister the observer for mobile data changed.
|
||||
*
|
||||
* @param context the Context object.
|
||||
*/
|
||||
public void unregister(Context context) {
|
||||
@@ -209,26 +225,39 @@ public class NetworkProviderWorker extends WifiScanWorker implements
|
||||
updateSlice();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActiveDataSubscriptionIdChanged(int subId) {
|
||||
Log.d(TAG, "onActiveDataSubscriptionIdChanged: subId=" + subId);
|
||||
updateSlice();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisplayInfoChanged(TelephonyDisplayInfo telephonyDisplayInfo) {
|
||||
Log.d(TAG, "onDisplayInfoChanged: telephonyDisplayInfo=" + telephonyDisplayInfo);
|
||||
mTelephonyDisplayInfo = telephonyDisplayInfo;
|
||||
updateSlice();
|
||||
}
|
||||
}
|
||||
|
||||
protected static int getDefaultSubscriptionId(SubscriptionManager subscriptionManager) {
|
||||
final SubscriptionInfo defaultSubscription = subscriptionManager.getActiveSubscriptionInfo(
|
||||
subscriptionManager.getDefaultDataSubscriptionId());
|
||||
@VisibleForTesting
|
||||
int getDefaultDataSubscriptionId() {
|
||||
return SubscriptionManager.getDefaultDataSubscriptionId();
|
||||
}
|
||||
|
||||
if (defaultSubscription == null) {
|
||||
return SubscriptionManager.INVALID_SUBSCRIPTION_ID; // No default subscription
|
||||
}
|
||||
return defaultSubscription.getSubscriptionId();
|
||||
|
||||
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
|
||||
|
@@ -178,7 +178,7 @@ public class ProviderModelSliceTest {
|
||||
public void getSlice_noWifiAndHasCarrierNoData_oneCarrierOneGridRowWithAllNetworkUnavailable() {
|
||||
mWifiList.clear();
|
||||
mMockNetworkProviderWorker.updateSelfResults(null);
|
||||
mockHelperCondition(false, true, true, null);
|
||||
mockHelperCondition(false, true, false, null);
|
||||
|
||||
final Slice slice = mMockProviderModelSlice.getSlice();
|
||||
|
||||
@@ -192,7 +192,7 @@ public class ProviderModelSliceTest {
|
||||
public void getSlice_noWifiAndNoCarrier_oneCarrierOneGridRowWithNonCarrierNetworkUnavailable() {
|
||||
mWifiList.clear();
|
||||
mMockProviderModelSlice = new MockProviderModelSlice(mContext, null);
|
||||
mockHelperCondition(false, true, false, null);
|
||||
mockHelperCondition(false, true, true, null);
|
||||
|
||||
final Slice slice = mMockProviderModelSlice.getSlice();
|
||||
|
||||
@@ -212,7 +212,7 @@ public class ProviderModelSliceTest {
|
||||
WifiEntry.CONNECTED_STATE_DISCONNECTED, "wifi2_key", true);
|
||||
mWifiList.add(mMockWifiSliceItem2);
|
||||
mMockNetworkProviderWorker.updateSelfResults(mWifiList);
|
||||
mockHelperCondition(false, true, false, mWifiList.get(0));
|
||||
mockHelperCondition(false, true, true, mWifiList.get(0));
|
||||
|
||||
final Slice slice = mMockProviderModelSlice.getSlice();
|
||||
|
||||
@@ -268,10 +268,10 @@ public class ProviderModelSliceTest {
|
||||
}
|
||||
|
||||
private void mockHelperCondition(boolean airplaneMode, boolean hasCarrier,
|
||||
boolean isNoCarrierData, WifiSliceItem connectedWifiItem) {
|
||||
boolean isDataSimActive, WifiSliceItem connectedWifiItem) {
|
||||
when(mProviderModelSliceHelper.isAirplaneModeEnabled()).thenReturn(airplaneMode);
|
||||
when(mProviderModelSliceHelper.hasCarrier()).thenReturn(hasCarrier);
|
||||
when(mProviderModelSliceHelper.isNoCarrierData()).thenReturn(isNoCarrierData);
|
||||
when(mProviderModelSliceHelper.isDataSimActive()).thenReturn(isDataSimActive);
|
||||
when(mProviderModelSliceHelper.getConnectedWifiItem(any())).thenReturn(connectedWifiItem);
|
||||
}
|
||||
|
||||
@@ -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() {
|
||||
|
@@ -69,7 +69,6 @@ public class NetworkProviderWorkerTest {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = spy(ApplicationProvider.getApplicationContext());
|
||||
|
||||
when(mContext.getSystemService(SubscriptionManager.class)).thenReturn(mSubscriptionManager);
|
||||
when(mContext.getSystemService(ConnectivityManager.class)).thenReturn(mConnectivityManager);
|
||||
when(mContext.getSystemService(TelephonyManager.class)).thenReturn(mTelephonyManager);
|
||||
when(mTelephonyManager.createForSubscriptionId(anyInt())).thenReturn(mTelephonyManager);
|
||||
@@ -141,6 +140,7 @@ public class NetworkProviderWorkerTest {
|
||||
public void onSubscriptionsChanged_notifySubscriptionChanged_callUpdateSlice() {
|
||||
mMockNetworkProviderWorker.onSlicePinned();
|
||||
mMockNetworkProviderWorker.receiveNotification(false);
|
||||
mMockNetworkProviderWorker.setDefaultDataSubscriptionId(2);
|
||||
|
||||
mMockNetworkProviderWorker.onSubscriptionsChanged();
|
||||
|
||||
@@ -213,17 +213,6 @@ public class NetworkProviderWorkerTest {
|
||||
assertThat(mMockNetworkProviderWorker.hasNotification()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@UiThreadTest
|
||||
public void onActiveDataSubscriptionIdChanged_notifyPhoneStateListener_callUpdateSlice() {
|
||||
mMockNetworkProviderWorker.onSlicePinned();
|
||||
mMockNetworkProviderWorker.receiveNotification(false);
|
||||
|
||||
mMockNetworkProviderWorker.mPhoneStateListener.onActiveDataSubscriptionIdChanged(1);
|
||||
|
||||
assertThat(mMockNetworkProviderWorker.hasNotification()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@UiThreadTest
|
||||
public void onDisplayInfoChanged_notifyPhoneStateListener_callUpdateSlice() {
|
||||
@@ -238,7 +227,7 @@ public class NetworkProviderWorkerTest {
|
||||
|
||||
public class MockNetworkProviderWorker extends NetworkProviderWorker {
|
||||
private boolean mHasNotification = false;
|
||||
|
||||
private int mDefaultDataSubId = 1;
|
||||
MockNetworkProviderWorker(Context context, Uri uri) {
|
||||
super(context, uri);
|
||||
}
|
||||
@@ -260,5 +249,14 @@ public class NetworkProviderWorkerTest {
|
||||
public void setWifiPickerTracker(WifiPickerTracker wifiPickerTracker) {
|
||||
mWifiPickerTracker = wifiPickerTracker;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDefaultDataSubscriptionId() {
|
||||
return mDefaultDataSubId;
|
||||
}
|
||||
|
||||
public void setDefaultDataSubscriptionId(int defaultDataSubId) {
|
||||
mDefaultDataSubId = defaultDataSubId;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user