[Provider mode] Display network type on mobile data preference.

Connect to 5G mobile network
  - https://screenshot.googleplex.com/8RziSbSjstMaFiK
 Connect to Wi-Fi
  - https://screenshot.googleplex.com/6ND3DFFsnLKSQRd

Bug: 176141828
Test: Manual test passed.
Test: Atest passed

Change-Id: I69b8ce0c1f5a16f0ff492be0b4ab26166a51bdc3
This commit is contained in:
tom hsu
2021-01-14 01:34:49 +08:00
parent f27d3c33c4
commit b392d43fff
3 changed files with 252 additions and 10 deletions

View File

@@ -20,6 +20,8 @@ import static androidx.lifecycle.Lifecycle.Event.ON_PAUSE;
import static androidx.lifecycle.Lifecycle.Event.ON_RESUME;
import static com.android.settings.network.telephony.MobileNetworkUtils.NO_CELL_DATA_TYPE_ICON;
import static com.android.settingslib.mobile.MobileMappings.getIconKey;
import static com.android.settingslib.mobile.MobileMappings.mapIconSets;
import android.content.BroadcastReceiver;
import android.content.Context;
@@ -31,6 +33,7 @@ import android.telephony.ServiceState;
import android.telephony.SignalStrength;
import android.telephony.SubscriptionInfo;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyDisplayInfo;
import android.telephony.TelephonyManager;
import android.util.ArraySet;
@@ -49,9 +52,12 @@ import com.android.settings.network.telephony.DataConnectivityListener;
import com.android.settings.network.telephony.MobileNetworkActivity;
import com.android.settings.network.telephony.MobileNetworkUtils;
import com.android.settings.network.telephony.SignalStrengthListener;
import com.android.settings.network.telephony.TelephonyDisplayInfoListener;
import com.android.settings.widget.GearPreference;
import com.android.settings.wifi.WifiPickerTrackerHelper;
import com.android.settingslib.core.AbstractPreferenceController;
import com.android.settingslib.mobile.MobileMappings;
import com.android.settingslib.mobile.MobileMappings.Config;
import com.android.settingslib.net.SignalStrengthUtil;
import java.util.Collections;
@@ -73,7 +79,7 @@ import java.util.Set;
public class SubscriptionsPreferenceController extends AbstractPreferenceController implements
LifecycleObserver, SubscriptionsChangeListener.SubscriptionsChangeListenerClient,
MobileDataEnabledListener.Client, DataConnectivityListener.Client,
SignalStrengthListener.Callback {
SignalStrengthListener.Callback, TelephonyDisplayInfoListener.Callback {
private static final String TAG = "SubscriptionsPrefCntrlr";
private UpdateListener mUpdateListener;
@@ -85,6 +91,7 @@ public class SubscriptionsPreferenceController extends AbstractPreferenceControl
private MobileDataEnabledListener mDataEnabledListener;
private DataConnectivityListener mConnectivityListener;
private SignalStrengthListener mSignalStrengthListener;
private TelephonyDisplayInfoListener mTelephonyDisplayInfoListener;
private WifiPickerTrackerHelper mWifiPickerTrackerHelper;
@VisibleForTesting
@@ -93,6 +100,7 @@ public class SubscriptionsPreferenceController extends AbstractPreferenceControl
public void onReceive(Context context, Intent intent) {
final String action = intent.getAction();
if (action.equals(TelephonyManager.ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED)) {
mConfig = mSubsPrefCtrlInjector.getConfig(mContext);
update();
}
}
@@ -102,8 +110,12 @@ public class SubscriptionsPreferenceController extends AbstractPreferenceControl
private Map<Integer, Preference> mSubscriptionPreferences;
private int mStartOrder;
private GearPreference mSubsGearPref;
private Config mConfig = null;
private SubsPrefCtrlInjector mSubsPrefCtrlInjector;
private TelephonyDisplayInfo mTelephonyDisplayInfo =
new TelephonyDisplayInfo(TelephonyManager.NETWORK_TYPE_UNKNOWN,
TelephonyDisplayInfo.OVERRIDE_NETWORK_TYPE_NONE);
/**
* This interface lets a parent of this class know that some change happened - this could
* either be because overall availability changed, or because we've added/removed/updated some
@@ -140,8 +152,10 @@ public class SubscriptionsPreferenceController extends AbstractPreferenceControl
mDataEnabledListener = new MobileDataEnabledListener(context, this);
mConnectivityListener = new DataConnectivityListener(context, this);
mSignalStrengthListener = new SignalStrengthListener(context, this);
mTelephonyDisplayInfoListener = new TelephonyDisplayInfoListener(context, this);
lifecycle.addObserver(this);
mSubsPrefCtrlInjector = createSubsPrefCtrlInjector();
mConfig = mSubsPrefCtrlInjector.getConfig(mContext);
}
private void registerDataSubscriptionChangedReceiver() {
@@ -163,6 +177,7 @@ public class SubscriptionsPreferenceController extends AbstractPreferenceControl
mDataEnabledListener.start(mSubsPrefCtrlInjector.getDefaultDataSubscriptionId());
mConnectivityListener.start();
mSignalStrengthListener.resume();
mTelephonyDisplayInfoListener.resume();
registerDataSubscriptionChangedReceiver();
update();
}
@@ -173,6 +188,7 @@ public class SubscriptionsPreferenceController extends AbstractPreferenceControl
mDataEnabledListener.stop();
mConnectivityListener.stop();
mSignalStrengthListener.pause();
mTelephonyDisplayInfoListener.pause();
unRegisterDataSubscriptionChangedReceiver();
}
@@ -196,6 +212,7 @@ public class SubscriptionsPreferenceController extends AbstractPreferenceControl
mSubscriptionPreferences.clear();
mSignalStrengthListener.updateSubscriptionIds(Collections.emptySet());
mTelephonyDisplayInfoListener.updateSubscriptionIds(Collections.emptySet());
mUpdateListener.onChildrenUpdated();
return;
}
@@ -226,22 +243,23 @@ public class SubscriptionsPreferenceController extends AbstractPreferenceControl
mSubsGearPref.setTitle(subInfo.getDisplayName());
mSubsGearPref.setOrder(mStartOrder);
//TODO(b/176141828) Wait for api provided by system ui.
mSubsGearPref.setSummary(getMobilePreferenceSummary());
mSubsGearPref.setSummary(getMobilePreferenceSummary(subInfo.getSubscriptionId()));
mSubsGearPref.setIcon(getIcon(subInfo.getSubscriptionId()));
mPreferenceGroup.addPreference(mSubsGearPref);
final Set<Integer> activeDataSubIds = new ArraySet<>();
activeDataSubIds.add(subInfo.getSubscriptionId());
mSignalStrengthListener.updateSubscriptionIds(activeDataSubIds);
mTelephonyDisplayInfoListener.updateSubscriptionIds(activeDataSubIds);
mUpdateListener.onChildrenUpdated();
}
private String getMobilePreferenceSummary() {
//TODO(b/176141828) Waiting for the api provided by system UI.
String result = "5G";
if (MobileNetworkUtils.activeNetworkIsCellular(mContext)) {
result = "Active, " + result;
private String getMobilePreferenceSummary(int subId) {
String result = mSubsPrefCtrlInjector.getNetworkType(
mContext, mConfig, mTelephonyDisplayInfo, subId);
if (!result.isEmpty() && mSubsPrefCtrlInjector.isActiveCellularNetwork(mContext)) {
result = mContext.getString(R.string.preference_summary_default_combination,
mContext.getString(R.string.mobile_data_connection_active), result);
}
return result;
}
@@ -462,6 +480,12 @@ public class SubscriptionsPreferenceController extends AbstractPreferenceControl
update();
}
@Override
public void onTelephonyDisplayInfoChanged(TelephonyDisplayInfo telephonyDisplayInfo) {
mTelephonyDisplayInfo = telephonyDisplayInfo;
update();
}
@VisibleForTesting
boolean canSubscriptionBeDisplayed(Context context, int subId) {
return (SubscriptionUtil.getAvailableSubscription(context,
@@ -534,6 +558,24 @@ public class SubscriptionsPreferenceController extends AbstractPreferenceControl
return Utils.isProviderModelEnabled(context);
}
/**
* Get config for carrier customization.
*/
public Config getConfig(Context context) {
return MobileMappings.Config.readConfig(context);
}
/**
* Get current mobile network type.
*/
public String getNetworkType(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) : "";
}
/**
* Get signal icon with different signal level.
*/