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:
SongFerng Wang
2021-01-19 05:55:17 +00:00
committed by Android (Google) Code Review
6 changed files with 135 additions and 62 deletions

View File

@@ -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;
}

View File

@@ -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());
}
}

View File

@@ -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);
}
}