Merge "[Settings] Change the way in MobileNetworkSummaryController for getting the subscription info from room db"
This commit is contained in:
@@ -298,6 +298,10 @@ public class MobileNetworkRepository extends SubscriptionManager.OnSubscriptions
|
|||||||
getUiccInfoBySubscriptionInfo(uiccSlotInfos, subInfo);
|
getUiccInfoBySubscriptionInfo(uiccSlotInfos, subInfo);
|
||||||
insertUiccInfo();
|
insertUiccInfo();
|
||||||
insertMobileNetworkInfo(context);
|
insertMobileNetworkInfo(context);
|
||||||
|
SubscriptionInfo firstRemovableSubInfo = SubscriptionUtil.getFirstRemovableSubscription(
|
||||||
|
context);
|
||||||
|
SubscriptionInfo subscriptionOrDefault = SubscriptionUtil.getSubscriptionOrDefault(
|
||||||
|
context, mSubId);
|
||||||
Log.d(TAG, "convert subscriptionInfo to entity for subId = " + mSubId);
|
Log.d(TAG, "convert subscriptionInfo to entity for subId = " + mSubId);
|
||||||
return new SubscriptionInfoEntity(String.valueOf(mSubId),
|
return new SubscriptionInfoEntity(String.valueOf(mSubId),
|
||||||
subInfo.getSimSlotIndex(),
|
subInfo.getSimSlotIndex(),
|
||||||
@@ -311,12 +315,11 @@ public class MobileNetworkRepository extends SubscriptionManager.OnSubscriptions
|
|||||||
SubscriptionUtil.getUniqueSubscriptionDisplayName(subInfo, context).toString(),
|
SubscriptionUtil.getUniqueSubscriptionDisplayName(subInfo, context).toString(),
|
||||||
SubscriptionUtil.isSubscriptionVisible(mSubscriptionManager, context, subInfo),
|
SubscriptionUtil.isSubscriptionVisible(mSubscriptionManager, context, subInfo),
|
||||||
SubscriptionUtil.getFormattedPhoneNumber(context, subInfo),
|
SubscriptionUtil.getFormattedPhoneNumber(context, subInfo),
|
||||||
SubscriptionUtil.getFirstRemovableSubscription(context) == null ? false
|
firstRemovableSubInfo == null ? false
|
||||||
: SubscriptionUtil.getFirstRemovableSubscription(
|
: firstRemovableSubInfo.getSubscriptionId() == mSubId,
|
||||||
context).getSubscriptionId() == mSubId,
|
|
||||||
String.valueOf(SubscriptionUtil.getDefaultSimConfig(context, mSubId)),
|
String.valueOf(SubscriptionUtil.getDefaultSimConfig(context, mSubId)),
|
||||||
SubscriptionUtil.getSubscriptionOrDefault(context, mSubId).getSubscriptionId()
|
subscriptionOrDefault == null ? false
|
||||||
== mSubId,
|
: subscriptionOrDefault.getSubscriptionId() == mSubId,
|
||||||
mSubscriptionManager.isValidSubscriptionId(mSubId),
|
mSubscriptionManager.isValidSubscriptionId(mSubId),
|
||||||
mSubscriptionManager.isUsableSubscriptionId(mSubId),
|
mSubscriptionManager.isUsableSubscriptionId(mSubId),
|
||||||
mSubscriptionManager.isActiveSubscriptionId(mSubId),
|
mSubscriptionManager.isActiveSubscriptionId(mSubId),
|
||||||
|
@@ -22,12 +22,12 @@ import static androidx.lifecycle.Lifecycle.Event.ON_RESUME;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.UserManager;
|
import android.os.UserManager;
|
||||||
import android.provider.Settings;
|
|
||||||
import android.telephony.SubscriptionManager;
|
|
||||||
import android.telephony.euicc.EuiccManager;
|
import android.telephony.euicc.EuiccManager;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
import androidx.lifecycle.Lifecycle;
|
import androidx.lifecycle.Lifecycle;
|
||||||
import androidx.lifecycle.LifecycleObserver;
|
import androidx.lifecycle.LifecycleObserver;
|
||||||
|
import androidx.lifecycle.LifecycleOwner;
|
||||||
import androidx.lifecycle.OnLifecycleEvent;
|
import androidx.lifecycle.OnLifecycleEvent;
|
||||||
import androidx.preference.Preference;
|
import androidx.preference.Preference;
|
||||||
import androidx.preference.PreferenceScreen;
|
import androidx.preference.PreferenceScreen;
|
||||||
@@ -35,32 +35,36 @@ import androidx.preference.PreferenceScreen;
|
|||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.core.PreferenceControllerMixin;
|
import com.android.settings.core.PreferenceControllerMixin;
|
||||||
import com.android.settings.dashboard.DashboardFragment;
|
import com.android.settings.dashboard.DashboardFragment;
|
||||||
import com.android.settings.network.helper.SubscriptionAnnotation;
|
|
||||||
import com.android.settings.network.telephony.MobileNetworkUtils;
|
import com.android.settings.network.telephony.MobileNetworkUtils;
|
||||||
import com.android.settings.overlay.FeatureFactory;
|
import com.android.settings.overlay.FeatureFactory;
|
||||||
import com.android.settings.widget.AddPreference;
|
import com.android.settings.widget.AddPreference;
|
||||||
import com.android.settingslib.Utils;
|
import com.android.settingslib.Utils;
|
||||||
import com.android.settingslib.core.AbstractPreferenceController;
|
import com.android.settingslib.core.AbstractPreferenceController;
|
||||||
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
|
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
|
||||||
|
import com.android.settingslib.mobile.dataservice.MobileNetworkInfoEntity;
|
||||||
|
import com.android.settingslib.mobile.dataservice.SubscriptionInfoEntity;
|
||||||
|
import com.android.settingslib.mobile.dataservice.UiccInfoEntity;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class MobileNetworkSummaryController extends AbstractPreferenceController implements
|
public class MobileNetworkSummaryController extends AbstractPreferenceController implements
|
||||||
SubscriptionsChangeListener.SubscriptionsChangeListenerClient, LifecycleObserver,
|
LifecycleObserver, PreferenceControllerMixin,
|
||||||
PreferenceControllerMixin {
|
MobileNetworkRepository.MobileNetworkCallback {
|
||||||
private static final String TAG = "MobileNetSummaryCtlr";
|
private static final String TAG = "MobileNetSummaryCtlr";
|
||||||
|
|
||||||
private static final String KEY = "mobile_network_list";
|
private static final String KEY = "mobile_network_list";
|
||||||
|
|
||||||
private final MetricsFeatureProvider mMetricsFeatureProvider;
|
private final MetricsFeatureProvider mMetricsFeatureProvider;
|
||||||
|
|
||||||
private SubscriptionManager mSubscriptionManager;
|
|
||||||
private UserManager mUserManager;
|
private UserManager mUserManager;
|
||||||
private SubscriptionsChangeListener mChangeListener;
|
|
||||||
private AddPreference mPreference;
|
private AddPreference mPreference;
|
||||||
|
|
||||||
private MobileNetworkSummaryStatus mStatusCache = new MobileNetworkSummaryStatus();
|
private MobileNetworkRepository mMobileNetworkRepository;
|
||||||
|
private List<SubscriptionInfoEntity> mSubInfoEntityList;
|
||||||
|
private List<UiccInfoEntity> mUiccInfoEntityList;
|
||||||
|
private List<MobileNetworkInfoEntity> mMobileNetworkInfoEntityList;
|
||||||
|
private boolean mIsAirplaneModeOn;
|
||||||
|
private LifecycleOwner mLifecycleOwner;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This controls the summary text and click behavior of the "Mobile network" item on the
|
* This controls the summary text and click behavior of the "Mobile network" item on the
|
||||||
@@ -77,26 +81,27 @@ public class MobileNetworkSummaryController extends AbstractPreferenceController
|
|||||||
* and the summary text gives the count of SIMs</li>
|
* and the summary text gives the count of SIMs</li>
|
||||||
* </ul>
|
* </ul>
|
||||||
*/
|
*/
|
||||||
public MobileNetworkSummaryController(Context context, Lifecycle lifecycle) {
|
public MobileNetworkSummaryController(Context context, Lifecycle lifecycle,
|
||||||
|
LifecycleOwner lifecycleOwner) {
|
||||||
super(context);
|
super(context);
|
||||||
mMetricsFeatureProvider = FeatureFactory.getFactory(mContext).getMetricsFeatureProvider();
|
mMetricsFeatureProvider = FeatureFactory.getFactory(mContext).getMetricsFeatureProvider();
|
||||||
mSubscriptionManager = context.getSystemService(SubscriptionManager.class);
|
|
||||||
mUserManager = context.getSystemService(UserManager.class);
|
mUserManager = context.getSystemService(UserManager.class);
|
||||||
|
mLifecycleOwner = lifecycleOwner;
|
||||||
|
mMobileNetworkRepository = new MobileNetworkRepository(context, this);
|
||||||
if (lifecycle != null) {
|
if (lifecycle != null) {
|
||||||
mChangeListener = new SubscriptionsChangeListener(context, this);
|
|
||||||
lifecycle.addObserver(this);
|
lifecycle.addObserver(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@OnLifecycleEvent(ON_RESUME)
|
@OnLifecycleEvent(ON_RESUME)
|
||||||
public void onResume() {
|
public void onResume() {
|
||||||
mChangeListener.start();
|
mMobileNetworkRepository.addRegister(mLifecycleOwner);
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
@OnLifecycleEvent(ON_PAUSE)
|
@OnLifecycleEvent(ON_PAUSE)
|
||||||
public void onPause() {
|
public void onPause() {
|
||||||
mChangeListener.stop();
|
mMobileNetworkRepository.removeRegister();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -107,28 +112,27 @@ public class MobileNetworkSummaryController extends AbstractPreferenceController
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CharSequence getSummary() {
|
public CharSequence getSummary() {
|
||||||
mStatusCache.update(mContext, null);
|
|
||||||
List<SubscriptionAnnotation> subs = mStatusCache.getSubscriptionList();
|
|
||||||
|
|
||||||
if (subs.isEmpty()) {
|
if ((mSubInfoEntityList == null || mSubInfoEntityList.isEmpty()) || (
|
||||||
if (mStatusCache.isEuiccConfigSupport()) {
|
mUiccInfoEntityList == null || mUiccInfoEntityList.isEmpty()) || (
|
||||||
|
mMobileNetworkInfoEntityList == null || mMobileNetworkInfoEntityList.isEmpty())) {
|
||||||
|
if (MobileNetworkUtils.showEuiccSettingsDetecting(mContext)) {
|
||||||
return mContext.getResources().getString(
|
return mContext.getResources().getString(
|
||||||
R.string.mobile_network_summary_add_a_network);
|
R.string.mobile_network_summary_add_a_network);
|
||||||
}
|
}
|
||||||
// set empty string to override previous text for carrier when SIM available
|
// set empty string to override previous text for carrier when SIM available
|
||||||
return "";
|
return "";
|
||||||
} else if (subs.size() == 1) {
|
} else if (mSubInfoEntityList.size() == 1) {
|
||||||
SubscriptionAnnotation info = subs.get(0);
|
SubscriptionInfoEntity info = mSubInfoEntityList.get(0);
|
||||||
CharSequence displayName = mStatusCache.getDisplayName(info.getSubscriptionId());
|
CharSequence displayName = info.uniqueName;
|
||||||
if (info.getSubInfo().isEmbedded() || info.isActive()
|
if (info.isEmbedded || mUiccInfoEntityList.get(0).isActive
|
||||||
|| mStatusCache.isPhysicalSimDisableSupport()) {
|
|| mMobileNetworkInfoEntityList.get(0).showToggleForPhysicalSim) {
|
||||||
return displayName;
|
return displayName;
|
||||||
}
|
}
|
||||||
return mContext.getString(R.string.mobile_network_tap_to_activate, displayName);
|
return mContext.getString(R.string.mobile_network_tap_to_activate, displayName);
|
||||||
} else {
|
} else {
|
||||||
return subs.stream()
|
return mSubInfoEntityList.stream()
|
||||||
.mapToInt(SubscriptionAnnotation::getSubscriptionId)
|
.map(SubscriptionInfoEntity::getUniqueDisplayName)
|
||||||
.mapToObj(subId -> mStatusCache.getDisplayName(subId))
|
|
||||||
.collect(Collectors.joining(", "));
|
.collect(Collectors.joining(", "));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -149,7 +153,7 @@ public class MobileNetworkSummaryController extends AbstractPreferenceController
|
|||||||
mPreference.setOnPreferenceClickListener(null);
|
mPreference.setOnPreferenceClickListener(null);
|
||||||
mPreference.setOnAddClickListener(null);
|
mPreference.setOnAddClickListener(null);
|
||||||
mPreference.setFragment(null);
|
mPreference.setFragment(null);
|
||||||
mPreference.setEnabled(!mChangeListener.isAirplaneModeOn());
|
mPreference.setEnabled(!mIsAirplaneModeOn);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void update() {
|
private void update() {
|
||||||
@@ -157,11 +161,12 @@ public class MobileNetworkSummaryController extends AbstractPreferenceController
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
mStatusCache.update(mContext, statusCache -> initPreference());
|
initPreference();
|
||||||
|
if (((mSubInfoEntityList == null || mSubInfoEntityList.isEmpty())
|
||||||
List<SubscriptionAnnotation> subs = mStatusCache.getSubscriptionList();
|
|| (mUiccInfoEntityList == null || mUiccInfoEntityList.isEmpty())
|
||||||
if (subs.isEmpty()) {
|
|| (mMobileNetworkInfoEntityList == null
|
||||||
if (mStatusCache.isEuiccConfigSupport()) {
|
|| mMobileNetworkInfoEntityList.isEmpty()))) {
|
||||||
|
if (MobileNetworkUtils.showEuiccSettingsDetecting(mContext)) {
|
||||||
mPreference.setOnPreferenceClickListener((Preference pref) -> {
|
mPreference.setOnPreferenceClickListener((Preference pref) -> {
|
||||||
logPreferenceClick(pref);
|
logPreferenceClick(pref);
|
||||||
startAddSimFlow();
|
startAddSimFlow();
|
||||||
@@ -175,28 +180,26 @@ public class MobileNetworkSummaryController extends AbstractPreferenceController
|
|||||||
|
|
||||||
// We have one or more existing subscriptions, so we want the plus button if eSIM is
|
// We have one or more existing subscriptions, so we want the plus button if eSIM is
|
||||||
// supported.
|
// supported.
|
||||||
if (mStatusCache.isEuiccConfigSupport()) {
|
if (MobileNetworkUtils.showEuiccSettingsDetecting(mContext)) {
|
||||||
mPreference.setAddWidgetEnabled(!mChangeListener.isAirplaneModeOn());
|
mPreference.setAddWidgetEnabled(!mIsAirplaneModeOn);
|
||||||
mPreference.setOnAddClickListener(p -> {
|
mPreference.setOnAddClickListener(p -> {
|
||||||
logPreferenceClick(p);
|
logPreferenceClick(p);
|
||||||
startAddSimFlow();
|
startAddSimFlow();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (subs.size() == 1) {
|
if (mSubInfoEntityList.size() == 1) {
|
||||||
mPreference.setOnPreferenceClickListener((Preference pref) -> {
|
mPreference.setOnPreferenceClickListener((Preference pref) -> {
|
||||||
logPreferenceClick(pref);
|
logPreferenceClick(pref);
|
||||||
|
SubscriptionInfoEntity info = mSubInfoEntityList.get(0);
|
||||||
SubscriptionAnnotation info = subs.get(0);
|
if (info.isEmbedded || mUiccInfoEntityList.get(0).isActive
|
||||||
if (info.getSubInfo().isEmbedded() || info.isActive()
|
|| mMobileNetworkInfoEntityList.get(0).showToggleForPhysicalSim) {
|
||||||
|| mStatusCache.isPhysicalSimDisableSupport()) {
|
MobileNetworkUtils.launchMobileNetworkSettings(mContext, info);
|
||||||
MobileNetworkUtils.launchMobileNetworkSettings(mContext,
|
|
||||||
info.getSubInfo());
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
SubscriptionUtil.startToggleSubscriptionDialogActivity(
|
SubscriptionUtil.startToggleSubscriptionDialogActivity(
|
||||||
mContext, info.getSubscriptionId(), true);
|
mContext, Integer.parseInt(info.subId), true);
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
@@ -216,14 +219,35 @@ public class MobileNetworkSummaryController extends AbstractPreferenceController
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAirplaneModeChanged(boolean airplaneModeEnabled) {
|
public void onAirplaneModeChanged(boolean airplaneModeEnabled) {
|
||||||
mStatusCache.update(mContext, statusCache -> update());
|
mIsAirplaneModeOn = airplaneModeEnabled;
|
||||||
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSubscriptionsChanged() {
|
public void onAvailableSubInfoChanged(List<SubscriptionInfoEntity> subInfoEntityList) {
|
||||||
mStatusCache.update(mContext, statusCache -> {
|
if ((mSubInfoEntityList != null &&
|
||||||
refreshSummary(mPreference);
|
(subInfoEntityList.isEmpty() || !subInfoEntityList.equals(mSubInfoEntityList)))
|
||||||
|
|| (!subInfoEntityList.isEmpty() && mSubInfoEntityList == null)) {
|
||||||
|
Log.d(TAG, "subInfo list from framework is changed, update the subInfo entity list.");
|
||||||
|
mSubInfoEntityList = subInfoEntityList;
|
||||||
update();
|
update();
|
||||||
});
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onActiveSubInfoChanged(List<SubscriptionInfoEntity> activeSubInfoList) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onAllUiccInfoChanged(List<UiccInfoEntity> uiccInfoEntityList) {
|
||||||
|
mUiccInfoEntityList = uiccInfoEntityList;
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onAllMobileNetworkInfoChanged(
|
||||||
|
List<MobileNetworkInfoEntity> mobileNetworkInfoEntityList) {
|
||||||
|
mMobileNetworkInfoEntityList = mobileNetworkInfoEntityList;
|
||||||
|
update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -27,6 +27,7 @@ import android.util.Log;
|
|||||||
|
|
||||||
import androidx.appcompat.app.AlertDialog;
|
import androidx.appcompat.app.AlertDialog;
|
||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
|
import androidx.lifecycle.LifecycleOwner;
|
||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.Utils;
|
import com.android.settings.Utils;
|
||||||
@@ -87,12 +88,12 @@ public class NetworkDashboardFragment extends DashboardFragment implements
|
|||||||
@Override
|
@Override
|
||||||
protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
|
protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
|
||||||
return buildPreferenceControllers(context, getSettingsLifecycle(), mMetricsFeatureProvider,
|
return buildPreferenceControllers(context, getSettingsLifecycle(), mMetricsFeatureProvider,
|
||||||
this /* fragment */, this /* mobilePlanHost */);
|
this /* fragment */, this /* mobilePlanHost */, this /* LifecycleOwner */);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static List<AbstractPreferenceController> buildPreferenceControllers(Context context,
|
private static List<AbstractPreferenceController> buildPreferenceControllers(Context context,
|
||||||
Lifecycle lifecycle, MetricsFeatureProvider metricsFeatureProvider, Fragment fragment,
|
Lifecycle lifecycle, MetricsFeatureProvider metricsFeatureProvider, Fragment fragment,
|
||||||
MobilePlanPreferenceHost mobilePlanHost) {
|
MobilePlanPreferenceHost mobilePlanHost, LifecycleOwner lifecycleOwner) {
|
||||||
final MobilePlanPreferenceController mobilePlanPreferenceController =
|
final MobilePlanPreferenceController mobilePlanPreferenceController =
|
||||||
new MobilePlanPreferenceController(context, mobilePlanHost);
|
new MobilePlanPreferenceController(context, mobilePlanHost);
|
||||||
final InternetPreferenceController internetPreferenceController =
|
final InternetPreferenceController internetPreferenceController =
|
||||||
@@ -111,7 +112,7 @@ public class NetworkDashboardFragment extends DashboardFragment implements
|
|||||||
|
|
||||||
final List<AbstractPreferenceController> controllers = new ArrayList<>();
|
final List<AbstractPreferenceController> controllers = new ArrayList<>();
|
||||||
|
|
||||||
controllers.add(new MobileNetworkSummaryController(context, lifecycle));
|
controllers.add(new MobileNetworkSummaryController(context, lifecycle, lifecycleOwner));
|
||||||
controllers.add(new TetherPreferenceController(context, lifecycle));
|
controllers.add(new TetherPreferenceController(context, lifecycle));
|
||||||
controllers.add(vpnPreferenceController);
|
controllers.add(vpnPreferenceController);
|
||||||
controllers.add(new ProxyPreferenceController(context));
|
controllers.add(new ProxyPreferenceController(context));
|
||||||
@@ -172,7 +173,7 @@ public class NetworkDashboardFragment extends DashboardFragment implements
|
|||||||
context) {
|
context) {
|
||||||
return buildPreferenceControllers(context, null /* lifecycle */,
|
return buildPreferenceControllers(context, null /* lifecycle */,
|
||||||
null /* metricsFeatureProvider */, null /* fragment */,
|
null /* metricsFeatureProvider */, null /* fragment */,
|
||||||
null /* mobilePlanHost */);
|
null /* mobilePlanHost */, null /* LifecycleOwner */);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@@ -82,6 +82,7 @@ import com.android.settings.network.telephony.TelephonyConstants.TelephonyManage
|
|||||||
import com.android.settingslib.core.instrumentation.Instrumentable;
|
import com.android.settingslib.core.instrumentation.Instrumentable;
|
||||||
import com.android.settingslib.development.DevelopmentSettingsEnabler;
|
import com.android.settingslib.development.DevelopmentSettingsEnabler;
|
||||||
import com.android.settingslib.graph.SignalDrawable;
|
import com.android.settingslib.graph.SignalDrawable;
|
||||||
|
import com.android.settingslib.mobile.dataservice.SubscriptionInfoEntity;
|
||||||
import com.android.settingslib.utils.ThreadUtils;
|
import com.android.settingslib.utils.ThreadUtils;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
@@ -1031,4 +1032,22 @@ public class MobileNetworkUtils {
|
|||||||
.launch();
|
.launch();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void launchMobileNetworkSettings(Context context, SubscriptionInfoEntity info) {
|
||||||
|
final int subId = Integer.valueOf(info.subId);
|
||||||
|
if (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
|
||||||
|
Log.d(TAG, "launchMobileNetworkSettings fail, subId is invalid.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Log.d(TAG, "launchMobileNetworkSettings for SubscriptionInfoEntity subId: " + subId);
|
||||||
|
final Bundle extra = new Bundle();
|
||||||
|
extra.putInt(Settings.EXTRA_SUB_ID, subId);
|
||||||
|
new SubSettingLauncher(context)
|
||||||
|
.setTitleText(info.uniqueName)
|
||||||
|
.setDestination(MobileNetworkSettings.class.getCanonicalName())
|
||||||
|
.setSourceMetricsCategory(Instrumentable.METRICS_CATEGORY_UNKNOWN)
|
||||||
|
.setArguments(extra)
|
||||||
|
.launch();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -40,7 +40,7 @@ import android.telephony.TelephonyManager;
|
|||||||
import android.telephony.euicc.EuiccManager;
|
import android.telephony.euicc.EuiccManager;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
|
||||||
import androidx.lifecycle.Lifecycle;
|
import androidx.lifecycle.LifecycleOwner;
|
||||||
import androidx.preference.PreferenceScreen;
|
import androidx.preference.PreferenceScreen;
|
||||||
|
|
||||||
import com.android.settings.Settings.MobileNetworkActivity;
|
import com.android.settings.Settings.MobileNetworkActivity;
|
||||||
@@ -48,6 +48,7 @@ import com.android.settings.network.helper.SubscriptionAnnotation;
|
|||||||
import com.android.settings.network.helper.SubscriptionGrouping;
|
import com.android.settings.network.helper.SubscriptionGrouping;
|
||||||
import com.android.settings.widget.AddPreference;
|
import com.android.settings.widget.AddPreference;
|
||||||
import com.android.settingslib.RestrictedLockUtils;
|
import com.android.settingslib.RestrictedLockUtils;
|
||||||
|
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||||
|
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
@@ -64,8 +65,7 @@ import java.util.Arrays;
|
|||||||
|
|
||||||
@RunWith(RobolectricTestRunner.class)
|
@RunWith(RobolectricTestRunner.class)
|
||||||
public class MobileNetworkSummaryControllerTest {
|
public class MobileNetworkSummaryControllerTest {
|
||||||
@Mock
|
|
||||||
private Lifecycle mLifecycle;
|
|
||||||
@Mock
|
@Mock
|
||||||
private TelephonyManager mTelephonyManager;
|
private TelephonyManager mTelephonyManager;
|
||||||
@Mock
|
@Mock
|
||||||
@@ -76,10 +76,16 @@ public class MobileNetworkSummaryControllerTest {
|
|||||||
private PreferenceScreen mPreferenceScreen;
|
private PreferenceScreen mPreferenceScreen;
|
||||||
@Mock
|
@Mock
|
||||||
private UserManager mUserManager;
|
private UserManager mUserManager;
|
||||||
|
@Mock
|
||||||
|
private MobileNetworkRepository mMobileNetworkRepository;
|
||||||
|
@Mock
|
||||||
|
private MobileNetworkRepository.MobileNetworkCallback mMobileNetworkCallback;
|
||||||
|
|
||||||
private AddPreference mPreference;
|
private AddPreference mPreference;
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
private MobileNetworkSummaryController mController;
|
private MobileNetworkSummaryController mController;
|
||||||
|
private LifecycleOwner mLifecycleOwner;
|
||||||
|
private Lifecycle mLifecycle;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
@@ -89,13 +95,17 @@ public class MobileNetworkSummaryControllerTest {
|
|||||||
doReturn(mSubscriptionManager).when(mContext).getSystemService(SubscriptionManager.class);
|
doReturn(mSubscriptionManager).when(mContext).getSystemService(SubscriptionManager.class);
|
||||||
doReturn(mEuiccManager).when(mContext).getSystemService(EuiccManager.class);
|
doReturn(mEuiccManager).when(mContext).getSystemService(EuiccManager.class);
|
||||||
doReturn(mUserManager).when(mContext).getSystemService(UserManager.class);
|
doReturn(mUserManager).when(mContext).getSystemService(UserManager.class);
|
||||||
|
mMobileNetworkRepository = new MobileNetworkRepository(mContext, mMobileNetworkCallback);
|
||||||
|
mLifecycleOwner = () -> mLifecycle;
|
||||||
|
mLifecycle = new Lifecycle(mLifecycleOwner);
|
||||||
|
mMobileNetworkRepository.addRegister(mLifecycleOwner);
|
||||||
|
|
||||||
when(mTelephonyManager.getNetworkCountryIso()).thenReturn("");
|
when(mTelephonyManager.getNetworkCountryIso()).thenReturn("");
|
||||||
when(mSubscriptionManager.isActiveSubscriptionId(anyInt())).thenReturn(true);
|
when(mSubscriptionManager.isActiveSubscriptionId(anyInt())).thenReturn(true);
|
||||||
when(mEuiccManager.isEnabled()).thenReturn(true);
|
when(mEuiccManager.isEnabled()).thenReturn(true);
|
||||||
Settings.Global.putInt(mContext.getContentResolver(), Settings.Global.EUICC_PROVISIONED, 1);
|
Settings.Global.putInt(mContext.getContentResolver(), Settings.Global.EUICC_PROVISIONED, 1);
|
||||||
|
|
||||||
mController = new MobileNetworkSummaryController(mContext, mLifecycle);
|
mController = new MobileNetworkSummaryController(mContext, mLifecycle, mLifecycleOwner);
|
||||||
mPreference = spy(new AddPreference(mContext, null));
|
mPreference = spy(new AddPreference(mContext, null));
|
||||||
mPreference.setKey(mController.getPreferenceKey());
|
mPreference.setKey(mController.getPreferenceKey());
|
||||||
when(mPreferenceScreen.findPreference(eq(mController.getPreferenceKey()))).thenReturn(
|
when(mPreferenceScreen.findPreference(eq(mController.getPreferenceKey()))).thenReturn(
|
||||||
@@ -104,6 +114,7 @@ public class MobileNetworkSummaryControllerTest {
|
|||||||
|
|
||||||
@After
|
@After
|
||||||
public void tearDown() {
|
public void tearDown() {
|
||||||
|
mMobileNetworkRepository.removeRegister();
|
||||||
SubscriptionUtil.setActiveSubscriptionsForTesting(null);
|
SubscriptionUtil.setActiveSubscriptionsForTesting(null);
|
||||||
SubscriptionUtil.setAvailableSubscriptionsForTesting(null);
|
SubscriptionUtil.setAvailableSubscriptionsForTesting(null);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user