Merge "Refacotr mobile data observer for repository" into main am: 12d49a521c
Original change: https://android-review.googlesource.com/c/platform/packages/apps/Settings/+/3059652 Change-Id: I50454802ab304a46699c0754fa077b79d637bc9f Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -91,7 +91,6 @@ public class MobileNetworkRepository extends SubscriptionManager.OnSubscriptions
|
|||||||
private AirplaneModeObserver mAirplaneModeObserver;
|
private AirplaneModeObserver mAirplaneModeObserver;
|
||||||
private DataRoamingObserver mDataRoamingObserver;
|
private DataRoamingObserver mDataRoamingObserver;
|
||||||
private MetricsFeatureProvider mMetricsFeatureProvider;
|
private MetricsFeatureProvider mMetricsFeatureProvider;
|
||||||
private Map<Integer, MobileDataContentObserver> mDataContentObserverMap = new HashMap<>();
|
|
||||||
private int mPhysicalSlotIndex = SubscriptionManager.INVALID_SIM_SLOT_INDEX;
|
private int mPhysicalSlotIndex = SubscriptionManager.INVALID_SIM_SLOT_INDEX;
|
||||||
private int mLogicalSlotIndex = SubscriptionManager.INVALID_SIM_SLOT_INDEX;
|
private int mLogicalSlotIndex = SubscriptionManager.INVALID_SIM_SLOT_INDEX;
|
||||||
private int mCardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
|
private int mCardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
|
||||||
@@ -209,6 +208,9 @@ public class MobileNetworkRepository extends SubscriptionManager.OnSubscriptions
|
|||||||
*/
|
*/
|
||||||
public void addRegister(LifecycleOwner lifecycleOwner,
|
public void addRegister(LifecycleOwner lifecycleOwner,
|
||||||
MobileNetworkCallback mobileNetworkCallback, int subId) {
|
MobileNetworkCallback mobileNetworkCallback, int subId) {
|
||||||
|
if (DEBUG) {
|
||||||
|
Log.d(TAG, "addRegister by SUB ID " + subId);
|
||||||
|
}
|
||||||
if (sCallbacks.isEmpty()) {
|
if (sCallbacks.isEmpty()) {
|
||||||
mSubscriptionManager.addOnSubscriptionsChangedListener(mContext.getMainExecutor(),
|
mSubscriptionManager.addOnSubscriptionsChangedListener(mContext.getMainExecutor(),
|
||||||
this);
|
this);
|
||||||
@@ -222,7 +224,6 @@ public class MobileNetworkRepository extends SubscriptionManager.OnSubscriptions
|
|||||||
observeAllUiccInfo(lifecycleOwner);
|
observeAllUiccInfo(lifecycleOwner);
|
||||||
observeAllMobileNetworkInfo(lifecycleOwner);
|
observeAllMobileNetworkInfo(lifecycleOwner);
|
||||||
if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
|
if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
|
||||||
addRegisterBySubId(subId);
|
|
||||||
createTelephonyManagerBySubId(subId);
|
createTelephonyManagerBySubId(subId);
|
||||||
mDataRoamingObserver.register(mContext, subId);
|
mDataRoamingObserver.register(mContext, subId);
|
||||||
}
|
}
|
||||||
@@ -231,19 +232,6 @@ public class MobileNetworkRepository extends SubscriptionManager.OnSubscriptions
|
|||||||
sendAvailableSubInfoCache(mobileNetworkCallback);
|
sendAvailableSubInfoCache(mobileNetworkCallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addRegisterBySubId(int subId) {
|
|
||||||
MobileDataContentObserver dataContentObserver = new MobileDataContentObserver(
|
|
||||||
new Handler(Looper.getMainLooper()));
|
|
||||||
dataContentObserver.setOnMobileDataChangedListener(() -> {
|
|
||||||
sExecutor.execute(() -> {
|
|
||||||
insertMobileNetworkInfo(mContext, subId,
|
|
||||||
getTelephonyManagerBySubId(mContext, subId));
|
|
||||||
});
|
|
||||||
});
|
|
||||||
dataContentObserver.register(mContext, subId);
|
|
||||||
mDataContentObserverMap.put(subId, dataContentObserver);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void createTelephonyManagerBySubId(int subId) {
|
private void createTelephonyManagerBySubId(int subId) {
|
||||||
if (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID
|
if (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID
|
||||||
|| mTelephonyCallbackMap.containsKey(subId)) {
|
|| mTelephonyCallbackMap.containsKey(subId)) {
|
||||||
@@ -253,7 +241,7 @@ public class MobileNetworkRepository extends SubscriptionManager.OnSubscriptions
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
PhoneCallStateTelephonyCallback
|
PhoneCallStateTelephonyCallback
|
||||||
telephonyCallback = new PhoneCallStateTelephonyCallback();
|
telephonyCallback = new PhoneCallStateTelephonyCallback(subId);
|
||||||
TelephonyManager telephonyManager = mContext.getSystemService(
|
TelephonyManager telephonyManager = mContext.getSystemService(
|
||||||
TelephonyManager.class).createForSubscriptionId(subId);
|
TelephonyManager.class).createForSubscriptionId(subId);
|
||||||
telephonyManager.registerTelephonyCallback(mContext.getMainExecutor(),
|
telephonyManager.registerTelephonyCallback(mContext.getMainExecutor(),
|
||||||
@@ -292,10 +280,6 @@ public class MobileNetworkRepository extends SubscriptionManager.OnSubscriptions
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (mDataContentObserverMap.containsKey(subId)) {
|
|
||||||
mDataContentObserverMap.get(subId).unRegister(mContext);
|
|
||||||
mDataContentObserverMap.remove(subId);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeRegister(MobileNetworkCallback mobileNetworkCallback) {
|
public void removeRegister(MobileNetworkCallback mobileNetworkCallback) {
|
||||||
@@ -304,10 +288,6 @@ public class MobileNetworkRepository extends SubscriptionManager.OnSubscriptions
|
|||||||
mSubscriptionManager.removeOnSubscriptionsChangedListener(this);
|
mSubscriptionManager.removeOnSubscriptionsChangedListener(this);
|
||||||
mAirplaneModeObserver.unRegister(mContext);
|
mAirplaneModeObserver.unRegister(mContext);
|
||||||
mDataRoamingObserver.unRegister(mContext);
|
mDataRoamingObserver.unRegister(mContext);
|
||||||
mDataContentObserverMap.forEach((id, observer) -> {
|
|
||||||
observer.unRegister(mContext);
|
|
||||||
});
|
|
||||||
mDataContentObserverMap.clear();
|
|
||||||
|
|
||||||
mTelephonyManagerMap.forEach((id, manager) -> {
|
mTelephonyManagerMap.forEach((id, manager) -> {
|
||||||
TelephonyCallback callback = mTelephonyCallbackMap.get(id);
|
TelephonyCallback callback = mTelephonyCallbackMap.get(id);
|
||||||
@@ -768,7 +748,14 @@ public class MobileNetworkRepository extends SubscriptionManager.OnSubscriptions
|
|||||||
}
|
}
|
||||||
|
|
||||||
private class PhoneCallStateTelephonyCallback extends TelephonyCallback implements
|
private class PhoneCallStateTelephonyCallback extends TelephonyCallback implements
|
||||||
TelephonyCallback.CallStateListener {
|
TelephonyCallback.CallStateListener,
|
||||||
|
TelephonyCallback.UserMobileDataStateListener {
|
||||||
|
|
||||||
|
private int mSubId;
|
||||||
|
|
||||||
|
public PhoneCallStateTelephonyCallback(int subId) {
|
||||||
|
mSubId = subId;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCallStateChanged(int state) {
|
public void onCallStateChanged(int state) {
|
||||||
@@ -776,6 +763,15 @@ public class MobileNetworkRepository extends SubscriptionManager.OnSubscriptions
|
|||||||
callback.onCallStateChanged(state);
|
callback.onCallStateChanged(state);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onUserMobileDataStateChanged(boolean enabled) {
|
||||||
|
Log.d(TAG, "onUserMobileDataStateChanged enabled " + enabled + " on SUB " + mSubId);
|
||||||
|
sExecutor.execute(() -> {
|
||||||
|
insertMobileNetworkInfo(mContext, mSubId,
|
||||||
|
getTelephonyManagerBySubId(mContext, mSubId));
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -96,9 +96,6 @@ public abstract class DefaultSubscriptionController extends TelephonyBasePrefere
|
|||||||
mMobileNetworkRepository.addRegister(mLifecycleOwner, this,
|
mMobileNetworkRepository.addRegister(mLifecycleOwner, this,
|
||||||
SubscriptionManager.INVALID_SUBSCRIPTION_ID);
|
SubscriptionManager.INVALID_SUBSCRIPTION_ID);
|
||||||
mMobileNetworkRepository.updateEntity();
|
mMobileNetworkRepository.updateEntity();
|
||||||
// Can not get default subId from database until get the callback, add register by subId
|
|
||||||
// later.
|
|
||||||
mMobileNetworkRepository.addRegisterBySubId(getDefaultSubscriptionId());
|
|
||||||
mDataSubscriptionChangedReceiver.registerReceiver();
|
mDataSubscriptionChangedReceiver.registerReceiver();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user