[Settings] update the db list when back to UI

Bug: 271524675
Test: local test
Change-Id: I26c7d64e6f040c62c9efb1438efe328f5744fa02
This commit is contained in:
Zoey Chen
2023-03-16 18:40:59 +00:00
parent b9f6bb7958
commit db02f10b07
10 changed files with 49 additions and 40 deletions

View File

@@ -101,7 +101,7 @@ public class InternetPreferenceController extends AbstractPreferenceController i
mInternetUpdater = new InternetUpdater(context, lifecycle, this); mInternetUpdater = new InternetUpdater(context, lifecycle, this);
mInternetType = mInternetUpdater.getInternetType(); mInternetType = mInternetUpdater.getInternetType();
mLifecycleOwner = lifecycleOwner; mLifecycleOwner = lifecycleOwner;
mMobileNetworkRepository = MobileNetworkRepository.create(context, this); mMobileNetworkRepository = MobileNetworkRepository.getInstance(context);
lifecycle.addObserver(this); lifecycle.addObserver(this);
} }
@@ -156,14 +156,16 @@ public class InternetPreferenceController extends AbstractPreferenceController i
/** @OnLifecycleEvent(ON_RESUME) */ /** @OnLifecycleEvent(ON_RESUME) */
@OnLifecycleEvent(ON_RESUME) @OnLifecycleEvent(ON_RESUME)
public void onResume() { public void onResume() {
mMobileNetworkRepository.addRegister(mLifecycleOwner); mMobileNetworkRepository.addRegister(mLifecycleOwner, this,
SubscriptionManager.INVALID_SUBSCRIPTION_ID);
mMobileNetworkRepository.updateEntity();
mSummaryHelper.register(true); mSummaryHelper.register(true);
} }
/** @OnLifecycleEvent(ON_PAUSE) */ /** @OnLifecycleEvent(ON_PAUSE) */
@OnLifecycleEvent(ON_PAUSE) @OnLifecycleEvent(ON_PAUSE)
public void onPause() { public void onPause() {
mMobileNetworkRepository.removeRegister(); mMobileNetworkRepository.removeRegister(this);
mSummaryHelper.register(false); mSummaryHelper.register(false);
} }

View File

@@ -22,6 +22,7 @@ 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.telephony.SubscriptionManager;
import android.telephony.euicc.EuiccManager; import android.telephony.euicc.EuiccManager;
import android.util.Log; import android.util.Log;
@@ -87,7 +88,7 @@ public class MobileNetworkSummaryController extends AbstractPreferenceController
mMetricsFeatureProvider = FeatureFactory.getFactory(mContext).getMetricsFeatureProvider(); mMetricsFeatureProvider = FeatureFactory.getFactory(mContext).getMetricsFeatureProvider();
mUserManager = context.getSystemService(UserManager.class); mUserManager = context.getSystemService(UserManager.class);
mLifecycleOwner = lifecycleOwner; mLifecycleOwner = lifecycleOwner;
mMobileNetworkRepository = MobileNetworkRepository.create(context, this); mMobileNetworkRepository = MobileNetworkRepository.getInstance(context);
mIsAirplaneModeOn = mMobileNetworkRepository.isAirplaneModeOn(); mIsAirplaneModeOn = mMobileNetworkRepository.isAirplaneModeOn();
if (lifecycle != null) { if (lifecycle != null) {
lifecycle.addObserver(this); lifecycle.addObserver(this);
@@ -96,13 +97,14 @@ public class MobileNetworkSummaryController extends AbstractPreferenceController
@OnLifecycleEvent(ON_RESUME) @OnLifecycleEvent(ON_RESUME)
public void onResume() { public void onResume() {
mMobileNetworkRepository.addRegister(mLifecycleOwner); mMobileNetworkRepository.addRegister(mLifecycleOwner, this,
update(); SubscriptionManager.INVALID_SUBSCRIPTION_ID);
mMobileNetworkRepository.updateEntity();
} }
@OnLifecycleEvent(ON_PAUSE) @OnLifecycleEvent(ON_PAUSE)
public void onPause() { public void onPause() {
mMobileNetworkRepository.removeRegister(); mMobileNetworkRepository.removeRegister(this);
} }
@Override @Override

View File

@@ -21,6 +21,7 @@ import static androidx.lifecycle.Lifecycle.Event;
import android.content.Context; import android.content.Context;
import android.os.UserManager; import android.os.UserManager;
import android.telephony.ServiceState; import android.telephony.ServiceState;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager; import android.telephony.TelephonyManager;
import android.util.Log; import android.util.Log;
import android.view.View; import android.view.View;
@@ -71,7 +72,7 @@ public class NetworkProviderCallsSmsController extends AbstractPreferenceControl
mIsRtlMode = context.getResources().getConfiguration().getLayoutDirection() mIsRtlMode = context.getResources().getConfiguration().getLayoutDirection()
== View.LAYOUT_DIRECTION_RTL; == View.LAYOUT_DIRECTION_RTL;
mLifecycleOwner = lifecycleOwner; mLifecycleOwner = lifecycleOwner;
mMobileNetworkRepository = MobileNetworkRepository.create(context, this); mMobileNetworkRepository = MobileNetworkRepository.getInstance(context);
if (lifecycle != null) { if (lifecycle != null) {
lifecycle.addObserver(this); lifecycle.addObserver(this);
} }
@@ -79,13 +80,14 @@ public class NetworkProviderCallsSmsController extends AbstractPreferenceControl
@OnLifecycleEvent(Event.ON_RESUME) @OnLifecycleEvent(Event.ON_RESUME)
public void onResume() { public void onResume() {
mMobileNetworkRepository.addRegister(mLifecycleOwner); mMobileNetworkRepository.addRegister(mLifecycleOwner, this,
update(); SubscriptionManager.INVALID_SUBSCRIPTION_ID);
mMobileNetworkRepository.updateEntity();
} }
@OnLifecycleEvent(Event.ON_PAUSE) @OnLifecycleEvent(Event.ON_PAUSE)
public void onPause() { public void onPause() {
mMobileNetworkRepository.removeRegister(); mMobileNetworkRepository.removeRegister(this);
} }
@Override @Override

View File

@@ -65,19 +65,20 @@ public class NetworkProviderSimListController extends AbstractPreferenceControll
mSubscriptionManager = context.getSystemService(SubscriptionManager.class); mSubscriptionManager = context.getSystemService(SubscriptionManager.class);
mPreferences = new ArrayMap<>(); mPreferences = new ArrayMap<>();
mLifecycleOwner = lifecycleOwner; mLifecycleOwner = lifecycleOwner;
mMobileNetworkRepository = MobileNetworkRepository.create(context, this); mMobileNetworkRepository = MobileNetworkRepository.getInstance(context);
lifecycle.addObserver(this); lifecycle.addObserver(this);
} }
@OnLifecycleEvent(ON_RESUME) @OnLifecycleEvent(ON_RESUME)
public void onResume() { public void onResume() {
mMobileNetworkRepository.addRegister(mLifecycleOwner); mMobileNetworkRepository.addRegister(mLifecycleOwner, this,
update(); SubscriptionManager.INVALID_SUBSCRIPTION_ID);
mMobileNetworkRepository.updateEntity();
} }
@OnLifecycleEvent(ON_PAUSE) @OnLifecycleEvent(ON_PAUSE)
public void onPause() { public void onPause() {
mMobileNetworkRepository.removeRegister(); mMobileNetworkRepository.removeRegister(this);
} }
@Override @Override

View File

@@ -52,7 +52,7 @@ public class ConvertToEsimPreferenceController extends TelephonyBasePreferenceCo
LifecycleOwner lifecycleOwner, int subId) { LifecycleOwner lifecycleOwner, int subId) {
super(context, key); super(context, key);
mSubId = subId; mSubId = subId;
mMobileNetworkRepository = MobileNetworkRepository.createBySubId(context, this, mSubId); mMobileNetworkRepository = MobileNetworkRepository.getInstance(context);
mLifecycleOwner = lifecycleOwner; mLifecycleOwner = lifecycleOwner;
if (lifecycle != null) { if (lifecycle != null) {
lifecycle.addObserver(this); lifecycle.addObserver(this);
@@ -66,12 +66,13 @@ public class ConvertToEsimPreferenceController extends TelephonyBasePreferenceCo
@OnLifecycleEvent(ON_START) @OnLifecycleEvent(ON_START)
public void onStart() { public void onStart() {
mMobileNetworkRepository.addRegister(mLifecycleOwner); mMobileNetworkRepository.addRegister(mLifecycleOwner, this, mSubId);
mMobileNetworkRepository.updateEntity();
} }
@OnLifecycleEvent(ON_STOP) @OnLifecycleEvent(ON_STOP)
public void onStop() { public void onStop() {
mMobileNetworkRepository.removeRegister(); mMobileNetworkRepository.removeRegister(this);
} }
@Override @Override

View File

@@ -75,7 +75,7 @@ public abstract class DefaultSubscriptionController extends TelephonyBasePrefere
mManager = context.getSystemService(SubscriptionManager.class); mManager = context.getSystemService(SubscriptionManager.class);
mIsRtlMode = context.getResources().getConfiguration().getLayoutDirection() mIsRtlMode = context.getResources().getConfiguration().getLayoutDirection()
== View.LAYOUT_DIRECTION_RTL; == View.LAYOUT_DIRECTION_RTL;
mMobileNetworkRepository = MobileNetworkRepository.create(context, this); mMobileNetworkRepository = MobileNetworkRepository.getInstance(context);
mLifecycleOwner = lifecycleOwner; mLifecycleOwner = lifecycleOwner;
if (lifecycle != null) { if (lifecycle != null) {
lifecycle.addObserver(this); lifecycle.addObserver(this);
@@ -104,13 +104,13 @@ public abstract class DefaultSubscriptionController extends TelephonyBasePrefere
@OnLifecycleEvent(ON_RESUME) @OnLifecycleEvent(ON_RESUME)
public void onResume() { public void onResume() {
mMobileNetworkRepository.addRegister(mLifecycleOwner); mMobileNetworkRepository.addRegister(mLifecycleOwner, this, getDefaultSubscriptionId());
updateEntries(); mMobileNetworkRepository.updateEntity();
} }
@OnLifecycleEvent(ON_PAUSE) @OnLifecycleEvent(ON_PAUSE)
public void onPause() { public void onPause() {
mMobileNetworkRepository.removeRegister(); mMobileNetworkRepository.removeRegister(this);
} }
@Override @Override
@@ -303,6 +303,4 @@ public abstract class DefaultSubscriptionController extends TelephonyBasePrefere
updateEntries(); updateEntries();
refreshSummary(mPreference); refreshSummary(mPreference);
} }
} }

View File

@@ -58,7 +58,6 @@ public class MobileDataPreferenceController extends TelephonyTogglePreferenceCon
private SwitchPreference mPreference; private SwitchPreference mPreference;
private TelephonyManager mTelephonyManager; private TelephonyManager mTelephonyManager;
private SubscriptionManager mSubscriptionManager; private SubscriptionManager mSubscriptionManager;
private MobileDataContentObserver mDataContentObserver;
private FragmentManager mFragmentManager; private FragmentManager mFragmentManager;
@VisibleForTesting @VisibleForTesting
int mDialogType; int mDialogType;
@@ -79,9 +78,7 @@ public class MobileDataPreferenceController extends TelephonyTogglePreferenceCon
super(context, key); super(context, key);
mSubId = subId; mSubId = subId;
mSubscriptionManager = context.getSystemService(SubscriptionManager.class); mSubscriptionManager = context.getSystemService(SubscriptionManager.class);
mDataContentObserver = new MobileDataContentObserver(new Handler(Looper.getMainLooper())); mMobileNetworkRepository = MobileNetworkRepository.getInstance(context);
mDataContentObserver.setOnMobileDataChangedListener(() -> updateState(mPreference));
mMobileNetworkRepository = MobileNetworkRepository.createBySubId(context, this, mSubId);
mLifecycleOwner = lifecycleOwner; mLifecycleOwner = lifecycleOwner;
if (lifecycle != null) { if (lifecycle != null) {
lifecycle.addObserver(this); lifecycle.addObserver(this);
@@ -103,12 +100,13 @@ public class MobileDataPreferenceController extends TelephonyTogglePreferenceCon
@OnLifecycleEvent(ON_START) @OnLifecycleEvent(ON_START)
public void onStart() { public void onStart() {
mMobileNetworkRepository.addRegister(mLifecycleOwner); mMobileNetworkRepository.addRegister(mLifecycleOwner, this, mSubId);
mMobileNetworkRepository.updateEntity();
} }
@OnLifecycleEvent(ON_STOP) @OnLifecycleEvent(ON_STOP)
public void onStop() { public void onStop() {
mMobileNetworkRepository.removeRegister(); mMobileNetworkRepository.removeRegister(this);
} }
@Override @Override

View File

@@ -158,7 +158,7 @@ public class MobileNetworkSettings extends AbstractMobileNetworkSettings impleme
MobileNetworkUtils.getSearchableSubscriptionId(context)); MobileNetworkUtils.getSearchableSubscriptionId(context));
Log.d(LOG_TAG, "display subId from getArguments(): " + mSubId); Log.d(LOG_TAG, "display subId from getArguments(): " + mSubId);
} }
mMobileNetworkRepository = MobileNetworkRepository.create(context, this); mMobileNetworkRepository = MobileNetworkRepository.getInstance(context);
mExecutor.execute(() -> { mExecutor.execute(() -> {
mSubscriptionInfoEntity = mMobileNetworkRepository.getSubInfoById( mSubscriptionInfoEntity = mMobileNetworkRepository.getSubInfoById(
String.valueOf(mSubId)); String.valueOf(mSubId));
@@ -177,6 +177,8 @@ public class MobileNetworkSettings extends AbstractMobileNetworkSettings impleme
new SmsDefaultSubscriptionController(context, KEY_SMS_PREF, getSettingsLifecycle(), new SmsDefaultSubscriptionController(context, KEY_SMS_PREF, getSettingsLifecycle(),
this), this),
new MobileDataPreferenceController(context, KEY_MOBILE_DATA_PREF, new MobileDataPreferenceController(context, KEY_MOBILE_DATA_PREF,
getSettingsLifecycle(), this, mSubId),
new ConvertToEsimPreferenceController(context, KEY_CONVERT_TO_ESIM_PREF,
getSettingsLifecycle(), this, mSubId)); getSettingsLifecycle(), this, mSubId));
} }
@@ -322,7 +324,8 @@ public class MobileNetworkSettings extends AbstractMobileNetworkSettings impleme
@Override @Override
public void onResume() { public void onResume() {
super.onResume(); super.onResume();
mMobileNetworkRepository.addRegister(this); mMobileNetworkRepository.addRegister(this, this, mSubId);
mMobileNetworkRepository.updateEntity();
// TODO: remove log after fixing b/182326102 // TODO: remove log after fixing b/182326102
Log.d(LOG_TAG, "onResume() subId=" + mSubId); Log.d(LOG_TAG, "onResume() subId=" + mSubId);
} }
@@ -350,7 +353,7 @@ public class MobileNetworkSettings extends AbstractMobileNetworkSettings impleme
@Override @Override
public void onDestroy() { public void onDestroy() {
super.onDestroy(); super.onDestroy();
mMobileNetworkRepository.removeRegister(); mMobileNetworkRepository.removeRegister(this);
} }
@VisibleForTesting @VisibleForTesting
@@ -505,7 +508,7 @@ public class MobileNetworkSettings extends AbstractMobileNetworkSettings impleme
break; break;
} else if (entity.isDefaultSubscriptionSelection) { } else if (entity.isDefaultSubscriptionSelection) {
mSubscriptionInfoEntity = entity; mSubscriptionInfoEntity = entity;
Log.d(LOG_TAG, "Set subInfo to the default subInfo."); Log.d(LOG_TAG, "Set subInfo to default subInfo.");
} }
} }
onSubscriptionDetailChanged(); onSubscriptionDetailChanged();

View File

@@ -81,7 +81,7 @@ public class RoamingPreferenceController extends TelephonyTogglePreferenceContro
super(context, key); super(context, key);
mSubId = subId; mSubId = subId;
mCarrierConfigManager = context.getSystemService(CarrierConfigManager.class); mCarrierConfigManager = context.getSystemService(CarrierConfigManager.class);
mMobileNetworkRepository = MobileNetworkRepository.createBySubId(context, this, mSubId); mMobileNetworkRepository = MobileNetworkRepository.getInstance(context);
mLifecycleOwner = lifecycleOwner; mLifecycleOwner = lifecycleOwner;
if (lifecycle != null) { if (lifecycle != null) {
lifecycle.addObserver(this); lifecycle.addObserver(this);
@@ -100,7 +100,8 @@ public class RoamingPreferenceController extends TelephonyTogglePreferenceContro
@OnLifecycleEvent(ON_START) @OnLifecycleEvent(ON_START)
public void onStart() { public void onStart() {
mMobileNetworkRepository.addRegister(mLifecycleOwner); mMobileNetworkRepository.addRegister(mLifecycleOwner, this, mSubId);
mMobileNetworkRepository.updateEntity();
if (mListener == null) { if (mListener == null) {
mListener = new GlobalSettingsChangeListener(mContext, mListener = new GlobalSettingsChangeListener(mContext,
Settings.Global.DATA_ROAMING) { Settings.Global.DATA_ROAMING) {
@@ -126,7 +127,7 @@ public class RoamingPreferenceController extends TelephonyTogglePreferenceContro
@OnLifecycleEvent(ON_STOP) @OnLifecycleEvent(ON_STOP)
public void onStop() { public void onStop() {
mMobileNetworkRepository.removeRegister(); mMobileNetworkRepository.removeRegister(this);
stopMonitor(); stopMonitor();
stopMonitorSubIdSpecific(); stopMonitorSubIdSpecific();
} }

View File

@@ -95,10 +95,11 @@ 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 = MobileNetworkRepository.create(mContext, mMobileNetworkCallback); mMobileNetworkRepository = MobileNetworkRepository.getInstance(mContext);
mLifecycleOwner = () -> mLifecycle; mLifecycleOwner = () -> mLifecycle;
mLifecycle = new Lifecycle(mLifecycleOwner); mLifecycle = new Lifecycle(mLifecycleOwner);
mMobileNetworkRepository.addRegister(mLifecycleOwner); mMobileNetworkRepository.addRegister(mLifecycleOwner, mMobileNetworkCallback,
SubscriptionManager.INVALID_SUBSCRIPTION_ID);
when(mTelephonyManager.getNetworkCountryIso()).thenReturn(""); when(mTelephonyManager.getNetworkCountryIso()).thenReturn("");
when(mSubscriptionManager.isActiveSubscriptionId(anyInt())).thenReturn(true); when(mSubscriptionManager.isActiveSubscriptionId(anyInt())).thenReturn(true);
@@ -114,7 +115,7 @@ public class MobileNetworkSummaryControllerTest {
@After @After
public void tearDown() { public void tearDown() {
mMobileNetworkRepository.removeRegister(); mMobileNetworkRepository.removeRegister(mMobileNetworkCallback);
SubscriptionUtil.setActiveSubscriptionsForTesting(null); SubscriptionUtil.setActiveSubscriptionsForTesting(null);
SubscriptionUtil.setAvailableSubscriptionsForTesting(null); SubscriptionUtil.setAvailableSubscriptionsForTesting(null);
} }