[Settings] Replacing SubscriptionManager#addOnSubscriptionsChangedListener API
Replace SubscriptionManager#addOnSubscriptionsChangedListener API in order to compatible with legacy design. Bug: 151838951 Test: m RunSettingsRoboTests -j ROBOTEST_FILTER=SubscriptionsChangeListenerTest Test: m RunSettingsRoboTests -j ROBOTEST_FILTER=ActiveSubsciptionsListenerTest Test: m RunSettingsRoboTests -j ROBOTEST_FILTER=SimStatusDialogControllerTest Merged-In: Ib98ce0dcbf18b6f48a6f267dd9e7be017d571157 Merged-In: I350604a64a56151195f52d38bd258e34c76e40c5 Change-Id: I4fc89e91381b1562ee7e2f48cfc159949c81a414
This commit is contained in:
@@ -268,7 +268,8 @@ public class SimStatusDialogController implements LifecycleObserver, OnResume, O
|
||||
PhoneStateListener.LISTEN_DATA_CONNECTION_STATE
|
||||
| PhoneStateListener.LISTEN_SIGNAL_STRENGTHS
|
||||
| PhoneStateListener.LISTEN_SERVICE_STATE);
|
||||
mSubscriptionManager.addOnSubscriptionsChangedListener(mOnSubscriptionsChangedListener);
|
||||
mSubscriptionManager.addOnSubscriptionsChangedListener(
|
||||
mContext.getMainExecutor(), mOnSubscriptionsChangedListener);
|
||||
registerImsRegistrationCallback(mSubscriptionInfo.getSubscriptionId());
|
||||
|
||||
if (mShowLatestAreaInfo) {
|
||||
|
@@ -46,6 +46,26 @@ public abstract class ActiveSubsciptionsListener
|
||||
private static final String TAG = "ActiveSubsciptions";
|
||||
private static final boolean DEBUG = false;
|
||||
|
||||
private Looper mLooper;
|
||||
private Context mContext;
|
||||
|
||||
private static final int STATE_NOT_LISTENING = 0;
|
||||
private static final int STATE_STOPPING = 1;
|
||||
private static final int STATE_PREPARING = 2;
|
||||
private static final int STATE_LISTENING = 3;
|
||||
private static final int STATE_DATA_CACHED = 4;
|
||||
|
||||
private AtomicInteger mCacheState;
|
||||
private SubscriptionManager mSubscriptionManager;
|
||||
|
||||
private IntentFilter mSubscriptionChangeIntentFilter;
|
||||
private BroadcastReceiver mSubscriptionChangeReceiver;
|
||||
|
||||
private static final int MAX_SUBSCRIPTION_UNKNOWN = -1;
|
||||
|
||||
private AtomicInteger mMaxActiveSubscriptionInfos;
|
||||
private List<SubscriptionInfo> mCachedActiveSubscriptionInfo;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
@@ -93,26 +113,6 @@ public abstract class ActiveSubsciptionsListener
|
||||
};
|
||||
}
|
||||
|
||||
private Looper mLooper;
|
||||
private Context mContext;
|
||||
|
||||
private static final int STATE_NOT_LISTENING = 0;
|
||||
private static final int STATE_STOPPING = 1;
|
||||
private static final int STATE_PREPARING = 2;
|
||||
private static final int STATE_LISTENING = 3;
|
||||
private static final int STATE_DATA_CACHED = 4;
|
||||
|
||||
private AtomicInteger mCacheState;
|
||||
private SubscriptionManager mSubscriptionManager;
|
||||
|
||||
private IntentFilter mSubscriptionChangeIntentFilter;
|
||||
private BroadcastReceiver mSubscriptionChangeReceiver;
|
||||
|
||||
private static final int MAX_SUBSCRIPTION_UNKNOWN = -1;
|
||||
|
||||
private AtomicInteger mMaxActiveSubscriptionInfos;
|
||||
private List<SubscriptionInfo> mCachedActiveSubscriptionInfo;
|
||||
|
||||
/**
|
||||
* Active subscriptions got changed
|
||||
*/
|
||||
@@ -266,6 +266,12 @@ public abstract class ActiveSubsciptionsListener
|
||||
mCachedActiveSubscriptionInfo = null;
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
void registerForSubscriptionsChange() {
|
||||
getSubscriptionManager().addOnSubscriptionsChangedListener(
|
||||
mContext.getMainExecutor(), this);
|
||||
}
|
||||
|
||||
private void monitorSubscriptionsChange(boolean on) {
|
||||
if (on) {
|
||||
if (!mCacheState.compareAndSet(STATE_NOT_LISTENING, STATE_PREPARING)) {
|
||||
@@ -277,7 +283,7 @@ public abstract class ActiveSubsciptionsListener
|
||||
}
|
||||
mContext.registerReceiver(mSubscriptionChangeReceiver,
|
||||
mSubscriptionChangeIntentFilter, null, new Handler(mLooper));
|
||||
getSubscriptionManager().addOnSubscriptionsChangedListener(this);
|
||||
registerForSubscriptionsChange();
|
||||
mCacheState.compareAndSet(STATE_PREPARING, STATE_LISTENING);
|
||||
return;
|
||||
}
|
||||
|
@@ -67,7 +67,8 @@ public class SubscriptionsChangeListener extends ContentObserver {
|
||||
}
|
||||
|
||||
public void start() {
|
||||
mSubscriptionManager.addOnSubscriptionsChangedListener(mSubscriptionsChangedListener);
|
||||
mSubscriptionManager.addOnSubscriptionsChangedListener(
|
||||
mContext.getMainExecutor(), mSubscriptionsChangedListener);
|
||||
mContext.getContentResolver()
|
||||
.registerContentObserver(mAirplaneModeSettingUri, false, this);
|
||||
final IntentFilter radioTechnologyChangedFilter = new IntentFilter(
|
||||
|
@@ -108,6 +108,10 @@ public class ActiveSubsciptionsListenerTest {
|
||||
private ActiveSubsciptionsListenerImpl(Looper looper, Context context) {
|
||||
super(looper, context);
|
||||
}
|
||||
|
||||
@Override
|
||||
void registerForSubscriptionsChange() {}
|
||||
|
||||
public void onChanged() {}
|
||||
}
|
||||
|
||||
|
@@ -83,7 +83,7 @@ public class SubscriptionsChangeListenerTest {
|
||||
initListener(false);
|
||||
verify(contentResolver, never()).registerContentObserver(any(Uri.class), anyBoolean(),
|
||||
any(ContentObserver.class));
|
||||
verify(mSubscriptionManager, never()).addOnSubscriptionsChangedListener(any());
|
||||
verify(mSubscriptionManager, never()).addOnSubscriptionsChangedListener(any(), any());
|
||||
verify(mContext, never()).registerReceiver(any(), any());
|
||||
}
|
||||
|
||||
@@ -92,7 +92,7 @@ public class SubscriptionsChangeListenerTest {
|
||||
initListener(true);
|
||||
final ArgumentCaptor<SubscriptionManager.OnSubscriptionsChangedListener> captor =
|
||||
ArgumentCaptor.forClass(SubscriptionManager.OnSubscriptionsChangedListener.class);
|
||||
verify(mSubscriptionManager).addOnSubscriptionsChangedListener(captor.capture());
|
||||
verify(mSubscriptionManager).addOnSubscriptionsChangedListener(any(), captor.capture());
|
||||
captor.getValue().onSubscriptionsChanged();
|
||||
verify(mClient).onSubscriptionsChanged();
|
||||
}
|
||||
|
Reference in New Issue
Block a user