Clean up MobileNetworkRepository.DataRoamingObserver
Bug: 348118234 Flag: EXEMPT clean up Test: manual - on Mobile Settings Change-Id: If9e7ed7cde0d7864ff00d135339a7725de179f1b
This commit is contained in:
@@ -85,7 +85,6 @@ public class MobileNetworkRepository extends SubscriptionManager.OnSubscriptions
|
|||||||
private List<SubscriptionInfoEntity> mActiveSubInfoEntityList = new ArrayList<>();
|
private List<SubscriptionInfoEntity> mActiveSubInfoEntityList = new ArrayList<>();
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
private AirplaneModeObserver mAirplaneModeObserver;
|
private AirplaneModeObserver mAirplaneModeObserver;
|
||||||
private DataRoamingObserver mDataRoamingObserver;
|
|
||||||
private MetricsFeatureProvider mMetricsFeatureProvider;
|
private MetricsFeatureProvider mMetricsFeatureProvider;
|
||||||
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;
|
||||||
@@ -122,7 +121,6 @@ public class MobileNetworkRepository extends SubscriptionManager.OnSubscriptions
|
|||||||
mSubscriptionInfoDao = mMobileNetworkDatabase.mSubscriptionInfoDao();
|
mSubscriptionInfoDao = mMobileNetworkDatabase.mSubscriptionInfoDao();
|
||||||
mMobileNetworkInfoDao = mMobileNetworkDatabase.mMobileNetworkInfoDao();
|
mMobileNetworkInfoDao = mMobileNetworkDatabase.mMobileNetworkInfoDao();
|
||||||
mAirplaneModeObserver = new AirplaneModeObserver(new Handler(Looper.getMainLooper()));
|
mAirplaneModeObserver = new AirplaneModeObserver(new Handler(Looper.getMainLooper()));
|
||||||
mDataRoamingObserver = new DataRoamingObserver(new Handler(Looper.getMainLooper()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private class AirplaneModeObserver extends ContentObserver {
|
private class AirplaneModeObserver extends ContentObserver {
|
||||||
@@ -153,47 +151,6 @@ public class MobileNetworkRepository extends SubscriptionManager.OnSubscriptions
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class DataRoamingObserver extends ContentObserver {
|
|
||||||
private int mRegSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
|
|
||||||
private String mBaseField = Settings.Global.DATA_ROAMING;
|
|
||||||
|
|
||||||
DataRoamingObserver(Handler handler) {
|
|
||||||
super(handler);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void register(Context context, int subId) {
|
|
||||||
mRegSubId = subId;
|
|
||||||
String lastField = mBaseField;
|
|
||||||
createTelephonyManagerBySubId(subId);
|
|
||||||
TelephonyManager tm = mTelephonyManagerMap.get(subId);
|
|
||||||
if (tm.getSimCount() != 1) {
|
|
||||||
lastField += subId;
|
|
||||||
}
|
|
||||||
context.getContentResolver().registerContentObserver(
|
|
||||||
Settings.Global.getUriFor(lastField), false, this);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void unRegister(Context context) {
|
|
||||||
context.getContentResolver().unregisterContentObserver(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onChange(boolean selfChange, Uri uri) {
|
|
||||||
TelephonyManager tm = mTelephonyManagerMap.get(mRegSubId);
|
|
||||||
if (tm == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
sExecutor.execute(() -> {
|
|
||||||
Log.d(TAG, "DataRoamingObserver changed");
|
|
||||||
insertMobileNetworkInfo(mContext, mRegSubId, tm);
|
|
||||||
});
|
|
||||||
boolean isDataRoamingEnabled = tm.isDataRoamingEnabled();
|
|
||||||
for (MobileNetworkCallback callback : sCallbacks) {
|
|
||||||
callback.onDataRoamingChanged(mRegSubId, isDataRoamingEnabled);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register all callbacks and listener.
|
* Register all callbacks and listener.
|
||||||
*
|
*
|
||||||
@@ -219,7 +176,6 @@ public class MobileNetworkRepository extends SubscriptionManager.OnSubscriptions
|
|||||||
observeAllMobileNetworkInfo(lifecycleOwner);
|
observeAllMobileNetworkInfo(lifecycleOwner);
|
||||||
if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
|
if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
|
||||||
createTelephonyManagerBySubId(subId);
|
createTelephonyManagerBySubId(subId);
|
||||||
mDataRoamingObserver.register(mContext, subId);
|
|
||||||
}
|
}
|
||||||
// When one client registers callback first time, convey the cached results to the client
|
// When one client registers callback first time, convey the cached results to the client
|
||||||
// so that the client is aware of the content therein.
|
// so that the client is aware of the content therein.
|
||||||
@@ -283,7 +239,6 @@ public class MobileNetworkRepository extends SubscriptionManager.OnSubscriptions
|
|||||||
if (sCallbacks.isEmpty()) {
|
if (sCallbacks.isEmpty()) {
|
||||||
mSubscriptionManager.removeOnSubscriptionsChangedListener(this);
|
mSubscriptionManager.removeOnSubscriptionsChangedListener(this);
|
||||||
mAirplaneModeObserver.unRegister(mContext);
|
mAirplaneModeObserver.unRegister(mContext);
|
||||||
mDataRoamingObserver.unRegister(mContext);
|
|
||||||
|
|
||||||
mTelephonyManagerMap.forEach((id, manager) -> {
|
mTelephonyManagerMap.forEach((id, manager) -> {
|
||||||
TelephonyCallback callback = mTelephonyCallbackMap.get(id);
|
TelephonyCallback callback = mTelephonyCallbackMap.get(id);
|
||||||
@@ -588,10 +543,8 @@ public class MobileNetworkRepository extends SubscriptionManager.OnSubscriptions
|
|||||||
private MobileNetworkInfoEntity convertToMobileNetworkInfoEntity(Context context, int subId,
|
private MobileNetworkInfoEntity convertToMobileNetworkInfoEntity(Context context, int subId,
|
||||||
TelephonyManager telephonyManager) {
|
TelephonyManager telephonyManager) {
|
||||||
boolean isDataEnabled = false;
|
boolean isDataEnabled = false;
|
||||||
boolean isDataRoamingEnabled = false;
|
|
||||||
if (telephonyManager != null) {
|
if (telephonyManager != null) {
|
||||||
isDataEnabled = telephonyManager.isDataEnabled();
|
isDataEnabled = telephonyManager.isDataEnabled();
|
||||||
isDataRoamingEnabled = telephonyManager.isDataRoamingEnabled();
|
|
||||||
} else {
|
} else {
|
||||||
Log.d(TAG, "TelephonyManager is null, subId = " + subId);
|
Log.d(TAG, "TelephonyManager is null, subId = " + subId);
|
||||||
}
|
}
|
||||||
@@ -607,7 +560,7 @@ public class MobileNetworkRepository extends SubscriptionManager.OnSubscriptions
|
|||||||
MobileNetworkUtils.isTdscdmaSupported(context, subId),
|
MobileNetworkUtils.isTdscdmaSupported(context, subId),
|
||||||
MobileNetworkUtils.activeNetworkIsCellular(context),
|
MobileNetworkUtils.activeNetworkIsCellular(context),
|
||||||
SubscriptionUtil.showToggleForPhysicalSim(mSubscriptionManager),
|
SubscriptionUtil.showToggleForPhysicalSim(mSubscriptionManager),
|
||||||
isDataRoamingEnabled
|
/* deprecated isDataRoamingEnabled = */ false
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -754,12 +707,6 @@ public class MobileNetworkRepository extends SubscriptionManager.OnSubscriptions
|
|||||||
|
|
||||||
default void onAirplaneModeChanged(boolean enabled) {
|
default void onAirplaneModeChanged(boolean enabled) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Notify clients data roaming changed of subscription.
|
|
||||||
*/
|
|
||||||
default void onDataRoamingChanged(int subId, boolean enabled) {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void dump(IndentingPrintWriter printwriter) {
|
public void dump(IndentingPrintWriter printwriter) {
|
||||||
|
Reference in New Issue
Block a user