Merge "[Settings] Do not creat multiple database"
This commit is contained in:
@@ -101,7 +101,7 @@ public class InternetPreferenceController extends AbstractPreferenceController i
|
||||
mInternetUpdater = new InternetUpdater(context, lifecycle, this);
|
||||
mInternetType = mInternetUpdater.getInternetType();
|
||||
mLifecycleOwner = lifecycleOwner;
|
||||
mMobileNetworkRepository = new MobileNetworkRepository(context, this);
|
||||
mMobileNetworkRepository = MobileNetworkRepository.create(context, this);
|
||||
lifecycle.addObserver(this);
|
||||
}
|
||||
|
||||
@@ -163,7 +163,6 @@ public class InternetPreferenceController extends AbstractPreferenceController i
|
||||
/** @OnLifecycleEvent(ON_PAUSE) */
|
||||
@OnLifecycleEvent(ON_PAUSE)
|
||||
public void onPause() {
|
||||
mMobileNetworkRepository.removeRegister();
|
||||
mSummaryHelper.register(false);
|
||||
}
|
||||
|
||||
@@ -203,22 +202,38 @@ public class InternetPreferenceController extends AbstractPreferenceController i
|
||||
@VisibleForTesting
|
||||
void updateCellularSummary() {
|
||||
CharSequence summary = null;
|
||||
for (SubscriptionInfoEntity subInfo : mSubInfoEntityList) {
|
||||
if (subInfo.isSubscriptionVisible && subInfo.isActiveDataSubscriptionId) {
|
||||
summary = subInfo.uniqueName;
|
||||
break;
|
||||
} else if (subInfo.isDefaultDataSubscription) {
|
||||
summary = mContext.getString(
|
||||
R.string.mobile_data_temp_using, subInfo.uniqueName);
|
||||
SubscriptionInfoEntity activeSubInfo = null;
|
||||
SubscriptionInfoEntity defaultSubInfo = null;
|
||||
|
||||
for (SubscriptionInfoEntity subInfo : getSubscriptionInfoList()) {
|
||||
if (subInfo.isActiveDataSubscriptionId) {
|
||||
activeSubInfo = subInfo;
|
||||
}
|
||||
if (subInfo.isDefaultDataSubscription) {
|
||||
defaultSubInfo = subInfo;
|
||||
}
|
||||
}
|
||||
|
||||
if (summary == null) {
|
||||
if (activeSubInfo == null) {
|
||||
return;
|
||||
}
|
||||
activeSubInfo = activeSubInfo.isSubscriptionVisible ? activeSubInfo : defaultSubInfo;
|
||||
|
||||
if (activeSubInfo.equals(defaultSubInfo)) {
|
||||
// DDS is active
|
||||
summary = activeSubInfo.uniqueName;
|
||||
} else {
|
||||
summary = mContext.getString(
|
||||
R.string.mobile_data_temp_using, activeSubInfo.uniqueName);
|
||||
}
|
||||
|
||||
mPreference.setSummary(summary);
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
protected List<SubscriptionInfoEntity> getSubscriptionInfoList() {
|
||||
return mSubInfoEntityList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAvailableSubInfoChanged(List<SubscriptionInfoEntity> subInfoEntityList) {
|
||||
if ((mSubInfoEntityList != null &&
|
||||
|
@@ -93,10 +93,15 @@ public class MobileNetworkRepository extends SubscriptionManager.OnSubscriptions
|
||||
private boolean mIsRemovable = false;
|
||||
private boolean mIsActive = false;
|
||||
|
||||
MobileNetworkRepository(Context context, MobileNetworkCallback mobileNetworkCallback) {
|
||||
public static MobileNetworkRepository create(Context context,
|
||||
MobileNetworkCallback mobileNetworkCallback) {
|
||||
return new MobileNetworkRepository(context, mobileNetworkCallback);
|
||||
}
|
||||
|
||||
private MobileNetworkRepository(Context context, MobileNetworkCallback mobileNetworkCallback) {
|
||||
mContext = context;
|
||||
mCallback = mobileNetworkCallback;
|
||||
mMobileNetworkDatabase = MobileNetworkDatabase.createDatabase(context);
|
||||
mMobileNetworkDatabase = MobileNetworkDatabase.getInstance(context);
|
||||
mSubscriptionInfoDao = mMobileNetworkDatabase.mSubscriptionInfoDao();
|
||||
mUiccInfoDao = mMobileNetworkDatabase.mUiccInfoDao();
|
||||
mMobileNetworkInfoDao = mMobileNetworkDatabase.mMobileNetworkInfoDao();
|
||||
@@ -194,6 +199,10 @@ public class MobileNetworkRepository extends SubscriptionManager.OnSubscriptions
|
||||
return mMobileNetworkInfoEntityList;
|
||||
}
|
||||
|
||||
public SubscriptionInfoEntity getSubInfoById(String subId) {
|
||||
return mSubscriptionInfoDao.querySubInfoById(subId);
|
||||
}
|
||||
|
||||
public int getSubInfosCount() {
|
||||
return mSubscriptionInfoDao.count();
|
||||
}
|
||||
@@ -439,7 +448,7 @@ public class MobileNetworkRepository extends SubscriptionManager.OnSubscriptions
|
||||
* Callback for clients to get the latest info changes if the framework or content observers.
|
||||
* updates the relevant info.
|
||||
*/
|
||||
interface MobileNetworkCallback {
|
||||
public interface MobileNetworkCallback {
|
||||
void onAvailableSubInfoChanged(List<SubscriptionInfoEntity> subInfoEntityList);
|
||||
|
||||
void onActiveSubInfoChanged(List<SubscriptionInfoEntity> subInfoEntityList);
|
||||
|
@@ -87,7 +87,7 @@ public class MobileNetworkSummaryController extends AbstractPreferenceController
|
||||
mMetricsFeatureProvider = FeatureFactory.getFactory(mContext).getMetricsFeatureProvider();
|
||||
mUserManager = context.getSystemService(UserManager.class);
|
||||
mLifecycleOwner = lifecycleOwner;
|
||||
mMobileNetworkRepository = new MobileNetworkRepository(context, this);
|
||||
mMobileNetworkRepository = MobileNetworkRepository.create(context, this);
|
||||
if (lifecycle != null) {
|
||||
lifecycle.addObserver(this);
|
||||
}
|
||||
@@ -101,7 +101,6 @@ public class MobileNetworkSummaryController extends AbstractPreferenceController
|
||||
|
||||
@OnLifecycleEvent(ON_PAUSE)
|
||||
public void onPause() {
|
||||
mMobileNetworkRepository.removeRegister();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -71,7 +71,7 @@ public class NetworkProviderCallsSmsController extends AbstractPreferenceControl
|
||||
mIsRtlMode = context.getResources().getConfiguration().getLayoutDirection()
|
||||
== View.LAYOUT_DIRECTION_RTL;
|
||||
mLifecycleOwner = lifecycleOwner;
|
||||
mMobileNetworkRepository = new MobileNetworkRepository(context, this);
|
||||
mMobileNetworkRepository = MobileNetworkRepository.create(context, this);
|
||||
if (lifecycle != null) {
|
||||
lifecycle.addObserver(this);
|
||||
}
|
||||
@@ -85,7 +85,6 @@ public class NetworkProviderCallsSmsController extends AbstractPreferenceControl
|
||||
|
||||
@OnLifecycleEvent(Event.ON_PAUSE)
|
||||
public void onPause() {
|
||||
mMobileNetworkRepository.removeRegister();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -72,7 +72,7 @@ public class NetworkProviderDownloadedSimListController extends
|
||||
mSubscriptionManager = context.getSystemService(SubscriptionManager.class);
|
||||
mPreferences = new ArrayMap<>();
|
||||
mLifecycleOwner = lifecycleOwner;
|
||||
mMobileNetworkRepository = new MobileNetworkRepository(context, this);
|
||||
mMobileNetworkRepository = MobileNetworkRepository.create(context, this);
|
||||
lifecycle.addObserver(this);
|
||||
}
|
||||
|
||||
|
@@ -68,7 +68,7 @@ public class NetworkProviderSimListController extends AbstractPreferenceControll
|
||||
mSubscriptionManager = context.getSystemService(SubscriptionManager.class);
|
||||
mPreferences = new ArrayMap<>();
|
||||
mLifecycleOwner = lifecycleOwner;
|
||||
mMobileNetworkRepository = new MobileNetworkRepository(context, this);
|
||||
mMobileNetworkRepository = MobileNetworkRepository.create(context, this);
|
||||
lifecycle.addObserver(this);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user