Merge "[Settings] Use TelephonyManasger.registerTelephonyCallback instead of TelephonyManager.listen" into sc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
c7d3c5f1be
@@ -24,6 +24,7 @@ import android.os.UserHandle;
|
|||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
import android.telephony.PhoneStateListener;
|
import android.telephony.PhoneStateListener;
|
||||||
import android.telephony.SubscriptionInfo;
|
import android.telephony.SubscriptionInfo;
|
||||||
|
import android.telephony.TelephonyCallback;
|
||||||
import android.telephony.TelephonyManager;
|
import android.telephony.TelephonyManager;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
@@ -61,7 +62,7 @@ public class AirplaneModeEnabler extends GlobalSettingsChangeListener {
|
|||||||
|
|
||||||
private TelephonyManager mTelephonyManager;
|
private TelephonyManager mTelephonyManager;
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
PhoneStateListener mPhoneStateListener;
|
AirplaneModeTelephonyCallback mTelephonyCallback;
|
||||||
|
|
||||||
public AirplaneModeEnabler(Context context, OnAirplaneModeChangedListener listener) {
|
public AirplaneModeEnabler(Context context, OnAirplaneModeChangedListener listener) {
|
||||||
super(context, Settings.Global.AIRPLANE_MODE_ON);
|
super(context, Settings.Global.AIRPLANE_MODE_ON);
|
||||||
@@ -71,16 +72,18 @@ public class AirplaneModeEnabler extends GlobalSettingsChangeListener {
|
|||||||
mOnAirplaneModeChangedListener = listener;
|
mOnAirplaneModeChangedListener = listener;
|
||||||
|
|
||||||
mTelephonyManager = context.getSystemService(TelephonyManager.class);
|
mTelephonyManager = context.getSystemService(TelephonyManager.class);
|
||||||
|
mTelephonyCallback = new AirplaneModeTelephonyCallback();
|
||||||
|
}
|
||||||
|
|
||||||
mPhoneStateListener = new PhoneStateListener(Looper.getMainLooper()) {
|
class AirplaneModeTelephonyCallback extends TelephonyCallback implements
|
||||||
@Override
|
TelephonyCallback.RadioPowerStateListener {
|
||||||
public void onRadioPowerStateChanged(int state) {
|
@Override
|
||||||
if (DEBUG) {
|
public void onRadioPowerStateChanged(int state) {
|
||||||
Log.d(LOG_TAG, "RadioPower: " + state);
|
if (DEBUG) {
|
||||||
}
|
Log.d(LOG_TAG, "RadioPower: " + state);
|
||||||
onAirplaneModeChanged();
|
|
||||||
}
|
}
|
||||||
};
|
onAirplaneModeChanged();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -98,16 +101,14 @@ public class AirplaneModeEnabler extends GlobalSettingsChangeListener {
|
|||||||
* Start listening to the phone state change
|
* Start listening to the phone state change
|
||||||
*/
|
*/
|
||||||
public void start() {
|
public void start() {
|
||||||
mTelephonyManager.listen(mPhoneStateListener,
|
mTelephonyManager.registerTelephonyCallback(mContext.getMainExecutor(), mTelephonyCallback);
|
||||||
PhoneStateListener.LISTEN_RADIO_POWER_STATE_CHANGED);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stop listening to the phone state change
|
* Stop listening to the phone state change
|
||||||
*/
|
*/
|
||||||
public void stop() {
|
public void stop() {
|
||||||
mTelephonyManager.listen(mPhoneStateListener,
|
mTelephonyManager.unregisterTelephonyCallback(mTelephonyCallback);
|
||||||
PhoneStateListener.LISTEN_NONE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setAirplaneModeOn(boolean enabling) {
|
private void setAirplaneModeOn(boolean enabling) {
|
||||||
|
@@ -44,6 +44,7 @@ import android.telephony.SignalStrength;
|
|||||||
import android.telephony.SubscriptionInfo;
|
import android.telephony.SubscriptionInfo;
|
||||||
import android.telephony.SubscriptionManager;
|
import android.telephony.SubscriptionManager;
|
||||||
import android.telephony.SubscriptionManager.OnSubscriptionsChangedListener;
|
import android.telephony.SubscriptionManager.OnSubscriptionsChangedListener;
|
||||||
|
import android.telephony.TelephonyCallback;
|
||||||
import android.telephony.TelephonyDisplayInfo;
|
import android.telephony.TelephonyDisplayInfo;
|
||||||
import android.telephony.TelephonyManager;
|
import android.telephony.TelephonyManager;
|
||||||
import android.telephony.UiccCardInfo;
|
import android.telephony.UiccCardInfo;
|
||||||
@@ -170,7 +171,8 @@ public class SimStatusDialogController implements LifecycleObserver {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private PhoneStateListener mPhoneStateListener;
|
@VisibleForTesting
|
||||||
|
protected SimStatusDialogTelephonyCallback mTelephonyCallback;
|
||||||
|
|
||||||
private CellBroadcastServiceConnection mCellBroadcastServiceConnection;
|
private CellBroadcastServiceConnection mCellBroadcastServiceConnection;
|
||||||
|
|
||||||
@@ -235,7 +237,7 @@ public class SimStatusDialogController implements LifecycleObserver {
|
|||||||
}
|
}
|
||||||
mTelephonyManager =
|
mTelephonyManager =
|
||||||
mTelephonyManager.createForSubscriptionId(mSubscriptionInfo.getSubscriptionId());
|
mTelephonyManager.createForSubscriptionId(mSubscriptionInfo.getSubscriptionId());
|
||||||
mPhoneStateListener = getPhoneStateListener();
|
mTelephonyCallback = new SimStatusDialogTelephonyCallback();
|
||||||
updateLatestAreaInfo();
|
updateLatestAreaInfo();
|
||||||
updateSubscriptionStatus();
|
updateSubscriptionStatus();
|
||||||
}
|
}
|
||||||
@@ -278,11 +280,7 @@ public class SimStatusDialogController implements LifecycleObserver {
|
|||||||
}
|
}
|
||||||
mTelephonyManager = mTelephonyManager.createForSubscriptionId(
|
mTelephonyManager = mTelephonyManager.createForSubscriptionId(
|
||||||
mSubscriptionInfo.getSubscriptionId());
|
mSubscriptionInfo.getSubscriptionId());
|
||||||
mTelephonyManager.listen(mPhoneStateListener,
|
mTelephonyManager.registerTelephonyCallback(mContext.getMainExecutor(), mTelephonyCallback);
|
||||||
PhoneStateListener.LISTEN_DATA_CONNECTION_STATE
|
|
||||||
| PhoneStateListener.LISTEN_SIGNAL_STRENGTHS
|
|
||||||
| PhoneStateListener.LISTEN_SERVICE_STATE
|
|
||||||
| PhoneStateListener.LISTEN_DISPLAY_INFO_CHANGED);
|
|
||||||
mSubscriptionManager.addOnSubscriptionsChangedListener(
|
mSubscriptionManager.addOnSubscriptionsChangedListener(
|
||||||
mContext.getMainExecutor(), mOnSubscriptionsChangedListener);
|
mContext.getMainExecutor(), mOnSubscriptionsChangedListener);
|
||||||
registerImsRegistrationCallback(mSubscriptionInfo.getSubscriptionId());
|
registerImsRegistrationCallback(mSubscriptionInfo.getSubscriptionId());
|
||||||
@@ -305,7 +303,7 @@ public class SimStatusDialogController implements LifecycleObserver {
|
|||||||
if (mIsRegisteredListener) {
|
if (mIsRegisteredListener) {
|
||||||
mSubscriptionManager.removeOnSubscriptionsChangedListener(
|
mSubscriptionManager.removeOnSubscriptionsChangedListener(
|
||||||
mOnSubscriptionsChangedListener);
|
mOnSubscriptionsChangedListener);
|
||||||
mTelephonyManager.listen(mPhoneStateListener, PhoneStateListener.LISTEN_NONE);
|
mTelephonyManager.unregisterTelephonyCallback(mTelephonyCallback);
|
||||||
if (mShowLatestAreaInfo) {
|
if (mShowLatestAreaInfo) {
|
||||||
mContext.unregisterReceiver(mAreaInfoReceiver);
|
mContext.unregisterReceiver(mAreaInfoReceiver);
|
||||||
}
|
}
|
||||||
@@ -316,7 +314,7 @@ public class SimStatusDialogController implements LifecycleObserver {
|
|||||||
|
|
||||||
unregisterImsRegistrationCallback(mSubscriptionInfo.getSubscriptionId());
|
unregisterImsRegistrationCallback(mSubscriptionInfo.getSubscriptionId());
|
||||||
mSubscriptionManager.removeOnSubscriptionsChangedListener(mOnSubscriptionsChangedListener);
|
mSubscriptionManager.removeOnSubscriptionsChangedListener(mOnSubscriptionsChangedListener);
|
||||||
mTelephonyManager.listen(mPhoneStateListener, PhoneStateListener.LISTEN_NONE);
|
mTelephonyManager.unregisterTelephonyCallback(mTelephonyCallback);
|
||||||
|
|
||||||
if (mShowLatestAreaInfo) {
|
if (mShowLatestAreaInfo) {
|
||||||
mContext.unregisterReceiver(mAreaInfoReceiver);
|
mContext.unregisterReceiver(mAreaInfoReceiver);
|
||||||
@@ -768,33 +766,35 @@ public class SimStatusDialogController implements LifecycleObserver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
protected PhoneStateListener getPhoneStateListener() {
|
class SimStatusDialogTelephonyCallback extends TelephonyCallback implements
|
||||||
return new PhoneStateListener() {
|
TelephonyCallback.DataConnectionStateListener,
|
||||||
@Override
|
TelephonyCallback.SignalStrengthsListener,
|
||||||
public void onDataConnectionStateChanged(int state) {
|
TelephonyCallback.ServiceStateListener,
|
||||||
updateDataState(state);
|
TelephonyCallback.DisplayInfoListener {
|
||||||
updateNetworkType();
|
@Override
|
||||||
}
|
public void onDataConnectionStateChanged(int state, int networkType) {
|
||||||
|
updateDataState(state);
|
||||||
|
updateNetworkType();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSignalStrengthsChanged(SignalStrength signalStrength) {
|
public void onSignalStrengthsChanged(SignalStrength signalStrength) {
|
||||||
updateSignalStrength(signalStrength);
|
updateSignalStrength(signalStrength);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onServiceStateChanged(ServiceState serviceState) {
|
public void onServiceStateChanged(ServiceState serviceState) {
|
||||||
updateNetworkProvider();
|
updateNetworkProvider();
|
||||||
updateServiceState(serviceState);
|
updateServiceState(serviceState);
|
||||||
updateRoamingStatus(serviceState);
|
updateRoamingStatus(serviceState);
|
||||||
mPreviousServiceState = serviceState;
|
mPreviousServiceState = serviceState;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDisplayInfoChanged(@NonNull TelephonyDisplayInfo displayInfo) {
|
public void onDisplayInfoChanged(@NonNull TelephonyDisplayInfo displayInfo) {
|
||||||
mTelephonyDisplayInfo = displayInfo;
|
mTelephonyDisplayInfo = displayInfo;
|
||||||
updateNetworkType();
|
updateNetworkType();
|
||||||
}
|
}
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
|
@@ -28,6 +28,7 @@ import android.os.UserManager;
|
|||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
import android.telephony.PhoneStateListener;
|
import android.telephony.PhoneStateListener;
|
||||||
import android.telephony.ServiceState;
|
import android.telephony.ServiceState;
|
||||||
|
import android.telephony.TelephonyCallback;
|
||||||
import android.telephony.TelephonyManager;
|
import android.telephony.TelephonyManager;
|
||||||
|
|
||||||
import androidx.annotation.VisibleForTesting;
|
import androidx.annotation.VisibleForTesting;
|
||||||
@@ -55,7 +56,7 @@ public class MobileNetworkPreferenceController extends AbstractPreferenceControl
|
|||||||
private final UserManager mUserManager;
|
private final UserManager mUserManager;
|
||||||
private Preference mPreference;
|
private Preference mPreference;
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
PhoneStateListener mPhoneStateListener;
|
MobileNetworkTelephonyCallback mTelephonyCallback;
|
||||||
|
|
||||||
private BroadcastReceiver mAirplanModeChangedReceiver;
|
private BroadcastReceiver mAirplanModeChangedReceiver;
|
||||||
|
|
||||||
@@ -97,18 +98,22 @@ public class MobileNetworkPreferenceController extends AbstractPreferenceControl
|
|||||||
return KEY_MOBILE_NETWORK_SETTINGS;
|
return KEY_MOBILE_NETWORK_SETTINGS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class MobileNetworkTelephonyCallback extends TelephonyCallback implements
|
||||||
|
TelephonyCallback.ServiceStateListener {
|
||||||
|
@Override
|
||||||
|
public void onServiceStateChanged(ServiceState serviceState) {
|
||||||
|
updateState(mPreference);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@OnLifecycleEvent(Event.ON_START)
|
@OnLifecycleEvent(Event.ON_START)
|
||||||
public void onStart() {
|
public void onStart() {
|
||||||
if (isAvailable()) {
|
if (isAvailable()) {
|
||||||
if (mPhoneStateListener == null) {
|
if (mTelephonyCallback == null) {
|
||||||
mPhoneStateListener = new PhoneStateListener() {
|
mTelephonyCallback = new MobileNetworkTelephonyCallback();
|
||||||
@Override
|
|
||||||
public void onServiceStateChanged(ServiceState serviceState) {
|
|
||||||
updateState(mPreference);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
mTelephonyManager.listen(mPhoneStateListener, PhoneStateListener.LISTEN_SERVICE_STATE);
|
mTelephonyManager.registerTelephonyCallback(
|
||||||
|
mContext.getMainExecutor(), mTelephonyCallback);
|
||||||
}
|
}
|
||||||
if (mAirplanModeChangedReceiver != null) {
|
if (mAirplanModeChangedReceiver != null) {
|
||||||
mContext.registerReceiver(mAirplanModeChangedReceiver,
|
mContext.registerReceiver(mAirplanModeChangedReceiver,
|
||||||
@@ -118,8 +123,8 @@ public class MobileNetworkPreferenceController extends AbstractPreferenceControl
|
|||||||
|
|
||||||
@OnLifecycleEvent(Event.ON_STOP)
|
@OnLifecycleEvent(Event.ON_STOP)
|
||||||
public void onStop() {
|
public void onStop() {
|
||||||
if (mPhoneStateListener != null) {
|
if (mTelephonyCallback != null) {
|
||||||
mTelephonyManager.listen(mPhoneStateListener, PhoneStateListener.LISTEN_NONE);
|
mTelephonyManager.unregisterTelephonyCallback(mTelephonyCallback);
|
||||||
}
|
}
|
||||||
if (mAirplanModeChangedReceiver != null) {
|
if (mAirplanModeChangedReceiver != null) {
|
||||||
mContext.unregisterReceiver(mAirplanModeChangedReceiver);
|
mContext.unregisterReceiver(mAirplanModeChangedReceiver);
|
||||||
|
@@ -20,11 +20,11 @@ import android.app.AlertDialog;
|
|||||||
import android.app.Dialog;
|
import android.app.Dialog;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.os.Looper;
|
|
||||||
import android.os.PersistableBundle;
|
import android.os.PersistableBundle;
|
||||||
import android.telephony.CarrierConfigManager;
|
import android.telephony.CarrierConfigManager;
|
||||||
import android.telephony.PhoneStateListener;
|
import android.telephony.PhoneStateListener;
|
||||||
import android.telephony.SubscriptionManager;
|
import android.telephony.SubscriptionManager;
|
||||||
|
import android.telephony.TelephonyCallback;
|
||||||
import android.telephony.TelephonyManager;
|
import android.telephony.TelephonyManager;
|
||||||
import android.telephony.ims.ImsMmTelManager;
|
import android.telephony.ims.ImsMmTelManager;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
@@ -53,7 +53,7 @@ public class Enhanced4gBasePreferenceController extends TelephonyTogglePreferenc
|
|||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
Preference mPreference;
|
Preference mPreference;
|
||||||
private PhoneCallStateListener mPhoneStateListener;
|
private PhoneCallStateTelephonyCallback mTelephonyCallback;
|
||||||
private boolean mShow5gLimitedDialog;
|
private boolean mShow5gLimitedDialog;
|
||||||
boolean mIsNrEnabledFromCarrierConfig;
|
boolean mIsNrEnabledFromCarrierConfig;
|
||||||
private boolean mHas5gCapability;
|
private boolean mHas5gCapability;
|
||||||
@@ -72,8 +72,8 @@ public class Enhanced4gBasePreferenceController extends TelephonyTogglePreferenc
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Enhanced4gBasePreferenceController init(int subId) {
|
public Enhanced4gBasePreferenceController init(int subId) {
|
||||||
if (mPhoneStateListener == null) {
|
if (mTelephonyCallback == null) {
|
||||||
mPhoneStateListener = new PhoneCallStateListener();
|
mTelephonyCallback = new PhoneCallStateTelephonyCallback();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mSubId == subId) {
|
if (mSubId == subId) {
|
||||||
@@ -134,18 +134,18 @@ public class Enhanced4gBasePreferenceController extends TelephonyTogglePreferenc
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onStart() {
|
public void onStart() {
|
||||||
if (!isModeMatched() || (mPhoneStateListener == null)) {
|
if (!isModeMatched() || (mTelephonyCallback == null)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
mPhoneStateListener.register(mContext, mSubId);
|
mTelephonyCallback.register(mContext, mSubId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onStop() {
|
public void onStop() {
|
||||||
if (mPhoneStateListener == null) {
|
if (mTelephonyCallback == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
mPhoneStateListener.unregister();
|
mTelephonyCallback.unregister();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -218,16 +218,13 @@ public class Enhanced4gBasePreferenceController extends TelephonyTogglePreferenc
|
|||||||
CarrierConfigManager.KEY_EDITABLE_ENHANCED_4G_LTE_BOOL);
|
CarrierConfigManager.KEY_EDITABLE_ENHANCED_4G_LTE_BOOL);
|
||||||
}
|
}
|
||||||
|
|
||||||
private class PhoneCallStateListener extends PhoneStateListener {
|
private class PhoneCallStateTelephonyCallback extends TelephonyCallback implements
|
||||||
|
TelephonyCallback.CallStateListener {
|
||||||
PhoneCallStateListener() {
|
|
||||||
super(Looper.getMainLooper());
|
|
||||||
}
|
|
||||||
|
|
||||||
private TelephonyManager mTelephonyManager;
|
private TelephonyManager mTelephonyManager;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCallStateChanged(int state, String incomingNumber) {
|
public void onCallStateChanged(int state) {
|
||||||
mCallState = state;
|
mCallState = state;
|
||||||
updateState(mPreference);
|
updateState(mPreference);
|
||||||
}
|
}
|
||||||
@@ -240,7 +237,8 @@ public class Enhanced4gBasePreferenceController extends TelephonyTogglePreferenc
|
|||||||
// assign current call state so that it helps to show correct preference state even
|
// assign current call state so that it helps to show correct preference state even
|
||||||
// before first onCallStateChanged() by initial registration.
|
// before first onCallStateChanged() by initial registration.
|
||||||
mCallState = mTelephonyManager.getCallState(subId);
|
mCallState = mTelephonyManager.getCallState(subId);
|
||||||
mTelephonyManager.listen(this, PhoneStateListener.LISTEN_CALL_STATE);
|
mTelephonyManager.registerTelephonyCallback(
|
||||||
|
mContext.getMainExecutor(), mTelephonyCallback);
|
||||||
|
|
||||||
final long supportedRadioBitmask = mTelephonyManager.getSupportedRadioAccessFamily();
|
final long supportedRadioBitmask = mTelephonyManager.getSupportedRadioAccessFamily();
|
||||||
mHas5gCapability =
|
mHas5gCapability =
|
||||||
@@ -250,7 +248,7 @@ public class Enhanced4gBasePreferenceController extends TelephonyTogglePreferenc
|
|||||||
public void unregister() {
|
public void unregister() {
|
||||||
mCallState = null;
|
mCallState = null;
|
||||||
if (mTelephonyManager != null) {
|
if (mTelephonyManager != null) {
|
||||||
mTelephonyManager.listen(this, PhoneStateListener.LISTEN_NONE);
|
mTelephonyManager.unregisterTelephonyCallback(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -19,9 +19,12 @@ package com.android.settings.network.telephony;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.telephony.PhoneStateListener;
|
import android.telephony.PhoneStateListener;
|
||||||
import android.telephony.SignalStrength;
|
import android.telephony.SignalStrength;
|
||||||
|
import android.telephony.TelephonyCallback;
|
||||||
import android.telephony.TelephonyManager;
|
import android.telephony.TelephonyManager;
|
||||||
import android.util.ArraySet;
|
import android.util.ArraySet;
|
||||||
|
|
||||||
|
import androidx.annotation.VisibleForTesting;
|
||||||
|
|
||||||
import com.google.common.collect.Sets;
|
import com.google.common.collect.Sets;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -34,7 +37,9 @@ public class SignalStrengthListener {
|
|||||||
|
|
||||||
private TelephonyManager mBaseTelephonyManager;
|
private TelephonyManager mBaseTelephonyManager;
|
||||||
private Callback mCallback;
|
private Callback mCallback;
|
||||||
private Map<Integer, PhoneStateListener> mListeners;
|
private Context mContext;
|
||||||
|
@VisibleForTesting
|
||||||
|
Map<Integer, SignalStrengthTelephonyCallback> mTelephonyCallbacks;
|
||||||
|
|
||||||
public interface Callback {
|
public interface Callback {
|
||||||
void onSignalStrengthChanged();
|
void onSignalStrengthChanged();
|
||||||
@@ -43,20 +48,21 @@ public class SignalStrengthListener {
|
|||||||
public SignalStrengthListener(Context context, Callback callback) {
|
public SignalStrengthListener(Context context, Callback callback) {
|
||||||
mBaseTelephonyManager = context.getSystemService(TelephonyManager.class);
|
mBaseTelephonyManager = context.getSystemService(TelephonyManager.class);
|
||||||
mCallback = callback;
|
mCallback = callback;
|
||||||
mListeners = new TreeMap<>();
|
mContext = context;
|
||||||
|
mTelephonyCallbacks = new TreeMap<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Resumes listening for signal strength changes for the set of ids from the last call to
|
/** Resumes listening for signal strength changes for the set of ids from the last call to
|
||||||
* {@link #updateSubscriptionIds(Set)} */
|
* {@link #updateSubscriptionIds(Set)} */
|
||||||
public void resume() {
|
public void resume() {
|
||||||
for (int subId : mListeners.keySet()) {
|
for (int subId : mTelephonyCallbacks.keySet()) {
|
||||||
startListening(subId);
|
startListening(subId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Pauses listening for signal strength changes */
|
/** Pauses listening for signal strength changes */
|
||||||
public void pause() {
|
public void pause() {
|
||||||
for (int subId : mListeners.keySet()) {
|
for (int subId : mTelephonyCallbacks.keySet()) {
|
||||||
stopListening(subId);
|
stopListening(subId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -64,30 +70,36 @@ public class SignalStrengthListener {
|
|||||||
/** Updates the set of ids we want to be listening for, beginning to listen for any new ids and
|
/** Updates the set of ids we want to be listening for, beginning to listen for any new ids and
|
||||||
* stopping listening for any ids not contained in the new set */
|
* stopping listening for any ids not contained in the new set */
|
||||||
public void updateSubscriptionIds(Set<Integer> ids) {
|
public void updateSubscriptionIds(Set<Integer> ids) {
|
||||||
Set<Integer> currentIds = new ArraySet<>(mListeners.keySet());
|
Set<Integer> currentIds = new ArraySet<>(mTelephonyCallbacks.keySet());
|
||||||
for (int idToRemove : Sets.difference(currentIds, ids)) {
|
for (int idToRemove : Sets.difference(currentIds, ids)) {
|
||||||
stopListening(idToRemove);
|
stopListening(idToRemove);
|
||||||
mListeners.remove(idToRemove);
|
mTelephonyCallbacks.remove(idToRemove);
|
||||||
}
|
}
|
||||||
for (int idToAdd : Sets.difference(ids, currentIds)) {
|
for (int idToAdd : Sets.difference(ids, currentIds)) {
|
||||||
PhoneStateListener listener = new PhoneStateListener() {
|
SignalStrengthTelephonyCallback telephonyCallback =
|
||||||
@Override
|
new SignalStrengthTelephonyCallback();
|
||||||
public void onSignalStrengthsChanged(SignalStrength signalStrength) {
|
mTelephonyCallbacks.put(idToAdd, telephonyCallback);
|
||||||
mCallback.onSignalStrengthChanged();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
mListeners.put(idToAdd, listener);
|
|
||||||
startListening(idToAdd);
|
startListening(idToAdd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@VisibleForTesting
|
||||||
|
class SignalStrengthTelephonyCallback extends TelephonyCallback implements
|
||||||
|
TelephonyCallback.SignalStrengthsListener {
|
||||||
|
@Override
|
||||||
|
public void onSignalStrengthsChanged(SignalStrength signalStrength) {
|
||||||
|
mCallback.onSignalStrengthChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void startListening(int subId) {
|
private void startListening(int subId) {
|
||||||
TelephonyManager mgr = mBaseTelephonyManager.createForSubscriptionId(subId);
|
TelephonyManager mgr = mBaseTelephonyManager.createForSubscriptionId(subId);
|
||||||
mgr.listen(mListeners.get(subId), PhoneStateListener.LISTEN_SIGNAL_STRENGTHS);
|
mgr.registerTelephonyCallback(
|
||||||
|
mContext.getMainExecutor(), mTelephonyCallbacks.get(subId));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void stopListening(int subId) {
|
private void stopListening(int subId) {
|
||||||
TelephonyManager mgr = mBaseTelephonyManager.createForSubscriptionId(subId);
|
TelephonyManager mgr = mBaseTelephonyManager.createForSubscriptionId(subId);
|
||||||
mgr.listen(mListeners.get(subId), PhoneStateListener.LISTEN_NONE);
|
mgr.unregisterTelephonyCallback(mTelephonyCallbacks.get(subId));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -17,11 +17,11 @@
|
|||||||
package com.android.settings.network.telephony;
|
package com.android.settings.network.telephony;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.Looper;
|
|
||||||
import android.os.PersistableBundle;
|
import android.os.PersistableBundle;
|
||||||
import android.telephony.CarrierConfigManager;
|
import android.telephony.CarrierConfigManager;
|
||||||
import android.telephony.PhoneStateListener;
|
import android.telephony.PhoneStateListener;
|
||||||
import android.telephony.SubscriptionManager;
|
import android.telephony.SubscriptionManager;
|
||||||
|
import android.telephony.TelephonyCallback;
|
||||||
import android.telephony.TelephonyManager;
|
import android.telephony.TelephonyManager;
|
||||||
import android.telephony.ims.ImsMmTelManager;
|
import android.telephony.ims.ImsMmTelManager;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
@@ -50,7 +50,7 @@ public class VideoCallingPreferenceController extends TelephonyTogglePreferenceC
|
|||||||
|
|
||||||
private Preference mPreference;
|
private Preference mPreference;
|
||||||
private CarrierConfigManager mCarrierConfigManager;
|
private CarrierConfigManager mCarrierConfigManager;
|
||||||
private PhoneCallStateListener mPhoneStateListener;
|
private PhoneTelephonyCallback mTelephonyCallback;
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
Integer mCallState;
|
Integer mCallState;
|
||||||
private MobileDataEnabledListener mDataContentObserver;
|
private MobileDataEnabledListener mDataContentObserver;
|
||||||
@@ -59,7 +59,7 @@ public class VideoCallingPreferenceController extends TelephonyTogglePreferenceC
|
|||||||
super(context, key);
|
super(context, key);
|
||||||
mCarrierConfigManager = context.getSystemService(CarrierConfigManager.class);
|
mCarrierConfigManager = context.getSystemService(CarrierConfigManager.class);
|
||||||
mDataContentObserver = new MobileDataEnabledListener(context, this);
|
mDataContentObserver = new MobileDataEnabledListener(context, this);
|
||||||
mPhoneStateListener = new PhoneCallStateListener();
|
mTelephonyCallback = new PhoneTelephonyCallback();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -78,13 +78,13 @@ public class VideoCallingPreferenceController extends TelephonyTogglePreferenceC
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onStart() {
|
public void onStart() {
|
||||||
mPhoneStateListener.register(mContext, mSubId);
|
mTelephonyCallback.register(mContext, mSubId);
|
||||||
mDataContentObserver.start(mSubId);
|
mDataContentObserver.start(mSubId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onStop() {
|
public void onStop() {
|
||||||
mPhoneStateListener.unregister();
|
mTelephonyCallback.unregister();
|
||||||
mDataContentObserver.stop();
|
mDataContentObserver.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -163,16 +163,13 @@ public class VideoCallingPreferenceController extends TelephonyTogglePreferenceC
|
|||||||
updateState(mPreference);
|
updateState(mPreference);
|
||||||
}
|
}
|
||||||
|
|
||||||
private class PhoneCallStateListener extends PhoneStateListener {
|
private class PhoneTelephonyCallback extends TelephonyCallback implements
|
||||||
|
TelephonyCallback.CallStateListener {
|
||||||
PhoneCallStateListener() {
|
|
||||||
super(Looper.getMainLooper());
|
|
||||||
}
|
|
||||||
|
|
||||||
private TelephonyManager mTelephonyManager;
|
private TelephonyManager mTelephonyManager;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCallStateChanged(int state, String incomingNumber) {
|
public void onCallStateChanged(int state) {
|
||||||
mCallState = state;
|
mCallState = state;
|
||||||
updateState(mPreference);
|
updateState(mPreference);
|
||||||
}
|
}
|
||||||
@@ -185,12 +182,12 @@ public class VideoCallingPreferenceController extends TelephonyTogglePreferenceC
|
|||||||
// assign current call state so that it helps to show correct preference state even
|
// assign current call state so that it helps to show correct preference state even
|
||||||
// before first onCallStateChanged() by initial registration.
|
// before first onCallStateChanged() by initial registration.
|
||||||
mCallState = mTelephonyManager.getCallState(subId);
|
mCallState = mTelephonyManager.getCallState(subId);
|
||||||
mTelephonyManager.listen(this, PhoneStateListener.LISTEN_CALL_STATE);
|
mTelephonyManager.registerTelephonyCallback(context.getMainExecutor(), this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void unregister() {
|
public void unregister() {
|
||||||
mCallState = null;
|
mCallState = null;
|
||||||
mTelephonyManager.listen(this, PhoneStateListener.LISTEN_NONE);
|
mTelephonyManager.unregisterTelephonyCallback(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -20,7 +20,6 @@ import android.content.Context;
|
|||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.content.pm.ResolveInfo;
|
import android.content.pm.ResolveInfo;
|
||||||
import android.os.Looper;
|
|
||||||
import android.os.PersistableBundle;
|
import android.os.PersistableBundle;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
import android.telecom.PhoneAccountHandle;
|
import android.telecom.PhoneAccountHandle;
|
||||||
@@ -28,6 +27,7 @@ import android.telecom.TelecomManager;
|
|||||||
import android.telephony.CarrierConfigManager;
|
import android.telephony.CarrierConfigManager;
|
||||||
import android.telephony.PhoneStateListener;
|
import android.telephony.PhoneStateListener;
|
||||||
import android.telephony.SubscriptionManager;
|
import android.telephony.SubscriptionManager;
|
||||||
|
import android.telephony.TelephonyCallback;
|
||||||
import android.telephony.TelephonyManager;
|
import android.telephony.TelephonyManager;
|
||||||
import android.telephony.ims.ImsMmTelManager;
|
import android.telephony.ims.ImsMmTelManager;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
@@ -60,13 +60,13 @@ public class WifiCallingPreferenceController extends TelephonyBasePreferenceCont
|
|||||||
private ImsMmTelManager mImsMmTelManager;
|
private ImsMmTelManager mImsMmTelManager;
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
PhoneAccountHandle mSimCallManager;
|
PhoneAccountHandle mSimCallManager;
|
||||||
private PhoneCallStateListener mPhoneStateListener;
|
private PhoneTelephonyCallback mTelephonyCallback;
|
||||||
private Preference mPreference;
|
private Preference mPreference;
|
||||||
|
|
||||||
public WifiCallingPreferenceController(Context context, String key) {
|
public WifiCallingPreferenceController(Context context, String key) {
|
||||||
super(context, key);
|
super(context, key);
|
||||||
mCarrierConfigManager = context.getSystemService(CarrierConfigManager.class);
|
mCarrierConfigManager = context.getSystemService(CarrierConfigManager.class);
|
||||||
mPhoneStateListener = new PhoneCallStateListener();
|
mTelephonyCallback = new PhoneTelephonyCallback();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -79,12 +79,12 @@ public class WifiCallingPreferenceController extends TelephonyBasePreferenceCont
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onStart() {
|
public void onStart() {
|
||||||
mPhoneStateListener.register(mContext, mSubId);
|
mTelephonyCallback.register(mContext, mSubId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onStop() {
|
public void onStop() {
|
||||||
mPhoneStateListener.unregister();
|
mTelephonyCallback.unregister();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -195,16 +195,13 @@ public class WifiCallingPreferenceController extends TelephonyBasePreferenceCont
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private class PhoneCallStateListener extends PhoneStateListener {
|
private class PhoneTelephonyCallback extends TelephonyCallback implements
|
||||||
|
TelephonyCallback.CallStateListener {
|
||||||
PhoneCallStateListener() {
|
|
||||||
super(Looper.getMainLooper());
|
|
||||||
}
|
|
||||||
|
|
||||||
private TelephonyManager mTelephonyManager;
|
private TelephonyManager mTelephonyManager;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCallStateChanged(int state, String incomingNumber) {
|
public void onCallStateChanged(int state) {
|
||||||
mCallState = state;
|
mCallState = state;
|
||||||
updateState(mPreference);
|
updateState(mPreference);
|
||||||
}
|
}
|
||||||
@@ -214,12 +211,12 @@ public class WifiCallingPreferenceController extends TelephonyBasePreferenceCont
|
|||||||
// assign current call state so that it helps to show correct preference state even
|
// assign current call state so that it helps to show correct preference state even
|
||||||
// before first onCallStateChanged() by initial registration.
|
// before first onCallStateChanged() by initial registration.
|
||||||
mCallState = mTelephonyManager.getCallState(subId);
|
mCallState = mTelephonyManager.getCallState(subId);
|
||||||
mTelephonyManager.listen(this, PhoneStateListener.LISTEN_CALL_STATE);
|
mTelephonyManager.registerTelephonyCallback(context.getMainExecutor(), this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void unregister() {
|
public void unregister() {
|
||||||
mCallState = null;
|
mCallState = null;
|
||||||
mTelephonyManager.listen(this, PhoneStateListener.LISTEN_NONE);
|
mTelephonyManager.unregisterTelephonyCallback(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -29,6 +29,7 @@ import android.os.PersistableBundle;
|
|||||||
import android.telephony.CarrierConfigManager;
|
import android.telephony.CarrierConfigManager;
|
||||||
import android.telephony.PhoneStateListener;
|
import android.telephony.PhoneStateListener;
|
||||||
import android.telephony.SubscriptionManager;
|
import android.telephony.SubscriptionManager;
|
||||||
|
import android.telephony.TelephonyCallback;
|
||||||
import android.telephony.TelephonyManager;
|
import android.telephony.TelephonyManager;
|
||||||
import android.telephony.ims.ImsManager;
|
import android.telephony.ims.ImsManager;
|
||||||
import android.telephony.ims.ImsMmTelManager;
|
import android.telephony.ims.ImsMmTelManager;
|
||||||
@@ -102,7 +103,10 @@ public class WifiCallingSettingsForSub extends SettingsPreferenceFragment
|
|||||||
private ProvisioningManager mProvisioningManager;
|
private ProvisioningManager mProvisioningManager;
|
||||||
private TelephonyManager mTelephonyManager;
|
private TelephonyManager mTelephonyManager;
|
||||||
|
|
||||||
private final PhoneStateListener mPhoneStateListener = new PhoneStateListener() {
|
private final PhoneTelephonyCallback mTelephonyCallback = new PhoneTelephonyCallback();
|
||||||
|
|
||||||
|
private class PhoneTelephonyCallback extends TelephonyCallback implements
|
||||||
|
TelephonyCallback.CallStateListener {
|
||||||
/*
|
/*
|
||||||
* Enable/disable controls when in/out of a call and depending on
|
* Enable/disable controls when in/out of a call and depending on
|
||||||
* TTY mode and TTY support over VoLTE.
|
* TTY mode and TTY support over VoLTE.
|
||||||
@@ -110,7 +114,7 @@ public class WifiCallingSettingsForSub extends SettingsPreferenceFragment
|
|||||||
* java.lang.String)
|
* java.lang.String)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void onCallStateChanged(int state, String incomingNumber) {
|
public void onCallStateChanged(int state) {
|
||||||
final SettingsActivity activity = (SettingsActivity) getActivity();
|
final SettingsActivity activity = (SettingsActivity) getActivity();
|
||||||
final boolean isNonTtyOrTtyOnVolteEnabled =
|
final boolean isNonTtyOrTtyOnVolteEnabled =
|
||||||
queryImsState(WifiCallingSettingsForSub.this.mSubId).isAllowUserControl();
|
queryImsState(WifiCallingSettingsForSub.this.mSubId).isAllowUserControl();
|
||||||
@@ -149,7 +153,7 @@ public class WifiCallingSettingsForSub extends SettingsPreferenceFragment
|
|||||||
&& isCallStateIdle);
|
&& isCallStateIdle);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Launch carrier emergency address managemnent activity
|
* Launch carrier emergency address managemnent activity
|
||||||
@@ -398,7 +402,7 @@ public class WifiCallingSettingsForSub extends SettingsPreferenceFragment
|
|||||||
res.getStringArray(R.array.wifi_calling_mode_summaries_without_wifi_only));
|
res.getStringArray(R.array.wifi_calling_mode_summaries_without_wifi_only));
|
||||||
}
|
}
|
||||||
|
|
||||||
// NOTE: Buttons will be enabled/disabled in mPhoneStateListener
|
// NOTE: Buttons will be enabled/disabled in mTelephonyCallback
|
||||||
final WifiCallingQueryImsState queryIms = queryImsState(mSubId);
|
final WifiCallingQueryImsState queryIms = queryImsState(mSubId);
|
||||||
final boolean wfcEnabled = queryIms.isEnabledByUser()
|
final boolean wfcEnabled = queryIms.isEnabledByUser()
|
||||||
&& queryIms.isAllowUserControl();
|
&& queryIms.isAllowUserControl();
|
||||||
@@ -416,16 +420,16 @@ public class WifiCallingSettingsForSub extends SettingsPreferenceFragment
|
|||||||
|
|
||||||
updateBody();
|
updateBody();
|
||||||
|
|
||||||
|
final Context context = getActivity();
|
||||||
if (queryImsState(mSubId).isWifiCallingSupported()) {
|
if (queryImsState(mSubId).isWifiCallingSupported()) {
|
||||||
getTelephonyManagerForSub(mSubId).listen(mPhoneStateListener,
|
getTelephonyManagerForSub(mSubId).registerTelephonyCallback(
|
||||||
PhoneStateListener.LISTEN_CALL_STATE);
|
context.getMainExecutor(), mTelephonyCallback);
|
||||||
|
|
||||||
mSwitchBar.addOnSwitchChangeListener(this);
|
mSwitchBar.addOnSwitchChangeListener(this);
|
||||||
|
|
||||||
mValidListener = true;
|
mValidListener = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
final Context context = getActivity();
|
|
||||||
context.registerReceiver(mIntentReceiver, mIntentFilter);
|
context.registerReceiver(mIntentReceiver, mIntentFilter);
|
||||||
|
|
||||||
final Intent intent = getActivity().getIntent();
|
final Intent intent = getActivity().getIntent();
|
||||||
@@ -446,8 +450,7 @@ public class WifiCallingSettingsForSub extends SettingsPreferenceFragment
|
|||||||
if (mValidListener) {
|
if (mValidListener) {
|
||||||
mValidListener = false;
|
mValidListener = false;
|
||||||
|
|
||||||
getTelephonyManagerForSub(mSubId).listen(mPhoneStateListener,
|
getTelephonyManagerForSub(mSubId).unregisterTelephonyCallback(mTelephonyCallback);
|
||||||
PhoneStateListener.LISTEN_NONE);
|
|
||||||
|
|
||||||
mSwitchBar.removeOnSwitchChangeListener(this);
|
mSwitchBar.removeOnSwitchChangeListener(this);
|
||||||
}
|
}
|
||||||
|
@@ -57,7 +57,7 @@ public final class AirplaneModeEnablerTest {
|
|||||||
|
|
||||||
ShadowSettings.setAirplaneMode(true);
|
ShadowSettings.setAirplaneMode(true);
|
||||||
|
|
||||||
mAirplaneModeEnabler.mPhoneStateListener.onRadioPowerStateChanged(
|
mAirplaneModeEnabler.mTelephonyCallback.onRadioPowerStateChanged(
|
||||||
TelephonyManager.RADIO_POWER_OFF);
|
TelephonyManager.RADIO_POWER_OFF);
|
||||||
|
|
||||||
verify(mAirplaneModeChangedListener, times(1)).onAirplaneModeChanged(true);
|
verify(mAirplaneModeChangedListener, times(1)).onAirplaneModeChanged(true);
|
||||||
|
@@ -16,13 +16,9 @@
|
|||||||
|
|
||||||
package com.android.settings.network.telephony;
|
package com.android.settings.network.telephony;
|
||||||
|
|
||||||
import static android.telephony.PhoneStateListener.LISTEN_NONE;
|
|
||||||
import static android.telephony.PhoneStateListener.LISTEN_SIGNAL_STRENGTHS;
|
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
import static org.mockito.ArgumentMatchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
import static org.mockito.ArgumentMatchers.anyInt;
|
|
||||||
import static org.mockito.ArgumentMatchers.eq;
|
import static org.mockito.ArgumentMatchers.eq;
|
||||||
import static org.mockito.Mockito.never;
|
import static org.mockito.Mockito.never;
|
||||||
import static org.mockito.Mockito.spy;
|
import static org.mockito.Mockito.spy;
|
||||||
@@ -31,7 +27,7 @@ import static org.mockito.Mockito.verify;
|
|||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.telephony.PhoneStateListener;
|
import android.telephony.TelephonyCallback;
|
||||||
import android.telephony.TelephonyManager;
|
import android.telephony.TelephonyManager;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
@@ -44,6 +40,8 @@ import org.mockito.internal.util.collections.Sets;
|
|||||||
import org.robolectric.RobolectricTestRunner;
|
import org.robolectric.RobolectricTestRunner;
|
||||||
import org.robolectric.RuntimeEnvironment;
|
import org.robolectric.RuntimeEnvironment;
|
||||||
|
|
||||||
|
import java.util.concurrent.Executor;
|
||||||
|
|
||||||
@RunWith(RobolectricTestRunner.class)
|
@RunWith(RobolectricTestRunner.class)
|
||||||
public class SignalStrengthListenerTest {
|
public class SignalStrengthListenerTest {
|
||||||
private static final int SUB_ID_1 = 111;
|
private static final int SUB_ID_1 = 111;
|
||||||
@@ -88,13 +86,19 @@ public class SignalStrengthListenerTest {
|
|||||||
@Test
|
@Test
|
||||||
public void updateSubscriptionIds_beforeResume_startedListening() {
|
public void updateSubscriptionIds_beforeResume_startedListening() {
|
||||||
mListener.updateSubscriptionIds(Sets.newSet(SUB_ID_1, SUB_ID_2));
|
mListener.updateSubscriptionIds(Sets.newSet(SUB_ID_1, SUB_ID_2));
|
||||||
ArgumentCaptor<PhoneStateListener> captor1 = ArgumentCaptor.forClass(
|
ArgumentCaptor<SignalStrengthListener.SignalStrengthTelephonyCallback> captor1 =
|
||||||
PhoneStateListener.class);
|
ArgumentCaptor.forClass(
|
||||||
ArgumentCaptor<PhoneStateListener> captor2 = ArgumentCaptor.forClass(
|
SignalStrengthListener.SignalStrengthTelephonyCallback.class);
|
||||||
PhoneStateListener.class);
|
ArgumentCaptor<SignalStrengthListener.SignalStrengthTelephonyCallback> captor2 =
|
||||||
verify(mManager1).listen(captor1.capture(), eq(LISTEN_SIGNAL_STRENGTHS));
|
ArgumentCaptor.forClass(
|
||||||
verify(mManager2).listen(captor2.capture(), eq(LISTEN_SIGNAL_STRENGTHS));
|
SignalStrengthListener.SignalStrengthTelephonyCallback.class);
|
||||||
verify(mManager3, never()).listen(any(), anyInt());
|
|
||||||
|
verify(mManager1).registerTelephonyCallback(
|
||||||
|
any(Executor.class), captor1.capture());
|
||||||
|
verify(mManager2).registerTelephonyCallback(
|
||||||
|
any(Executor.class), captor2.capture());
|
||||||
|
verify(mManager3, never()).registerTelephonyCallback(any(), any());
|
||||||
|
|
||||||
assertThat(captor1.getValue()).isNotNull();
|
assertThat(captor1.getValue()).isNotNull();
|
||||||
assertThat(captor2.getValue()).isNotNull();
|
assertThat(captor2.getValue()).isNotNull();
|
||||||
|
|
||||||
@@ -105,46 +109,57 @@ public class SignalStrengthListenerTest {
|
|||||||
@Test
|
@Test
|
||||||
public void updateSubscriptionIds_twoCalls_oneIdAdded() {
|
public void updateSubscriptionIds_twoCalls_oneIdAdded() {
|
||||||
mListener.updateSubscriptionIds(Sets.newSet(SUB_ID_1, SUB_ID_2));
|
mListener.updateSubscriptionIds(Sets.newSet(SUB_ID_1, SUB_ID_2));
|
||||||
verify(mManager1).listen(any(PhoneStateListener.class), eq(LISTEN_SIGNAL_STRENGTHS));
|
|
||||||
verify(mManager2).listen(any(PhoneStateListener.class), eq(LISTEN_SIGNAL_STRENGTHS));
|
verify(mManager1).registerTelephonyCallback(any(Executor.class),
|
||||||
|
eq(mListener.mTelephonyCallbacks.get(SUB_ID_1)));
|
||||||
|
verify(mManager2).registerTelephonyCallback(any(Executor.class),
|
||||||
|
eq(mListener.mTelephonyCallbacks.get(SUB_ID_2)));
|
||||||
|
|
||||||
mListener.updateSubscriptionIds(Sets.newSet(SUB_ID_1, SUB_ID_2, SUB_ID_3));
|
mListener.updateSubscriptionIds(Sets.newSet(SUB_ID_1, SUB_ID_2, SUB_ID_3));
|
||||||
verify(mManager1, never()).listen(any(PhoneStateListener.class), eq(LISTEN_NONE));
|
verify(mManager1, never()).unregisterTelephonyCallback(
|
||||||
verify(mManager2, never()).listen(any(PhoneStateListener.class), eq(LISTEN_NONE));
|
mListener.mTelephonyCallbacks.get(SUB_ID_1));
|
||||||
verify(mManager3).listen(any(PhoneStateListener.class), eq(LISTEN_SIGNAL_STRENGTHS));
|
verify(mManager2, never()).unregisterTelephonyCallback(
|
||||||
|
mListener.mTelephonyCallbacks.get(SUB_ID_2));
|
||||||
|
verify(mManager3).registerTelephonyCallback(
|
||||||
|
any(Executor.class), eq(mListener.mTelephonyCallbacks.get(SUB_ID_3)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void updateSubscriptionIds_twoCalls_oneIdRemoved() {
|
public void updateSubscriptionIds_twoCalls_oneIdRemoved() {
|
||||||
ArgumentCaptor<PhoneStateListener> captor1 = ArgumentCaptor.forClass(
|
ArgumentCaptor<SignalStrengthListener.SignalStrengthTelephonyCallback> captor1 =
|
||||||
PhoneStateListener.class);
|
ArgumentCaptor.forClass(
|
||||||
|
SignalStrengthListener.SignalStrengthTelephonyCallback.class);
|
||||||
|
|
||||||
mListener.updateSubscriptionIds(Sets.newSet(SUB_ID_1, SUB_ID_2));
|
mListener.updateSubscriptionIds(Sets.newSet(SUB_ID_1, SUB_ID_2));
|
||||||
verify(mManager1).listen(captor1.capture(), eq(LISTEN_SIGNAL_STRENGTHS));
|
verify(mManager1).registerTelephonyCallback(any(Executor.class), captor1.capture());
|
||||||
verify(mManager2).listen(any(PhoneStateListener.class), eq(LISTEN_SIGNAL_STRENGTHS));
|
verify(mManager2).registerTelephonyCallback(
|
||||||
|
any(Executor.class), any(TelephonyCallback.class));
|
||||||
|
|
||||||
mListener.updateSubscriptionIds(Sets.newSet(SUB_ID_2));
|
mListener.updateSubscriptionIds(Sets.newSet(SUB_ID_2));
|
||||||
verify(mManager1).listen(captor1.capture(), eq(LISTEN_NONE));
|
verify(mManager1).unregisterTelephonyCallback(captor1.capture());
|
||||||
verify(mManager2, never()).listen(any(PhoneStateListener.class), eq(LISTEN_NONE));
|
verify(mManager2, never()).unregisterTelephonyCallback(any(TelephonyCallback.class));
|
||||||
// Make sure the correct listener was removed.
|
// Make sure the correct listener was removed.
|
||||||
assertThat(captor1.getAllValues().get(0) == captor1.getAllValues().get(1)).isTrue();
|
assertThat(captor1.getAllValues().get(0) == captor1.getAllValues().get(1)).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void updateSubscriptionIds_twoCalls_twoIdsRemovedOneAdded() {
|
public void updateSubscriptionIds_twoCalls_twoIdsRemovedOneAdded() {
|
||||||
ArgumentCaptor<PhoneStateListener> captor1 = ArgumentCaptor.forClass(
|
ArgumentCaptor<SignalStrengthListener.SignalStrengthTelephonyCallback> captor1 =
|
||||||
PhoneStateListener.class);
|
ArgumentCaptor.forClass(
|
||||||
ArgumentCaptor<PhoneStateListener> captor2 = ArgumentCaptor.forClass(
|
SignalStrengthListener.SignalStrengthTelephonyCallback.class);
|
||||||
PhoneStateListener.class);
|
ArgumentCaptor<SignalStrengthListener.SignalStrengthTelephonyCallback> captor2 =
|
||||||
|
ArgumentCaptor.forClass(
|
||||||
|
SignalStrengthListener.SignalStrengthTelephonyCallback.class);
|
||||||
|
|
||||||
mListener.updateSubscriptionIds(Sets.newSet(SUB_ID_1, SUB_ID_2));
|
mListener.updateSubscriptionIds(Sets.newSet(SUB_ID_1, SUB_ID_2));
|
||||||
verify(mManager1).listen(captor1.capture(), eq(LISTEN_SIGNAL_STRENGTHS));
|
verify(mManager1).registerTelephonyCallback(any(Executor.class), captor1.capture());
|
||||||
verify(mManager2).listen(captor2.capture(), eq(LISTEN_SIGNAL_STRENGTHS));
|
verify(mManager2).registerTelephonyCallback(any(Executor.class), captor2.capture());
|
||||||
|
|
||||||
mListener.updateSubscriptionIds(Sets.newSet(SUB_ID_3));
|
mListener.updateSubscriptionIds(Sets.newSet(SUB_ID_3));
|
||||||
verify(mManager1).listen(captor1.capture(), eq(LISTEN_NONE));
|
verify(mManager1).unregisterTelephonyCallback(captor1.capture());
|
||||||
verify(mManager2).listen(captor2.capture(), eq(LISTEN_NONE));
|
verify(mManager2).unregisterTelephonyCallback(captor2.capture());
|
||||||
verify(mManager3).listen(any(PhoneStateListener.class), eq(LISTEN_SIGNAL_STRENGTHS));
|
verify(mManager3).registerTelephonyCallback(
|
||||||
|
any(Executor.class), any(TelephonyCallback.class));
|
||||||
// Make sure the correct listeners were removed.
|
// Make sure the correct listeners were removed.
|
||||||
assertThat(captor1.getValue() != captor2.getValue()).isTrue();
|
assertThat(captor1.getValue() != captor2.getValue()).isTrue();
|
||||||
assertThat(captor1.getAllValues().get(0) == captor1.getAllValues().get(1)).isTrue();
|
assertThat(captor1.getAllValues().get(0) == captor1.getAllValues().get(1)).isTrue();
|
||||||
@@ -157,15 +172,19 @@ public class SignalStrengthListenerTest {
|
|||||||
mListener.pause();
|
mListener.pause();
|
||||||
mListener.resume();
|
mListener.resume();
|
||||||
|
|
||||||
ArgumentCaptor<PhoneStateListener> captor1 = ArgumentCaptor.forClass(
|
ArgumentCaptor<SignalStrengthListener.SignalStrengthTelephonyCallback> captor1 =
|
||||||
PhoneStateListener.class);
|
ArgumentCaptor.forClass(
|
||||||
ArgumentCaptor<PhoneStateListener> captor2 = ArgumentCaptor.forClass(
|
SignalStrengthListener.SignalStrengthTelephonyCallback.class);
|
||||||
PhoneStateListener.class);
|
ArgumentCaptor<SignalStrengthListener.SignalStrengthTelephonyCallback> captor2 =
|
||||||
verify(mManager1, times(2)).listen(captor1.capture(), eq(LISTEN_SIGNAL_STRENGTHS));
|
ArgumentCaptor.forClass(
|
||||||
verify(mManager1).listen(captor1.capture(), eq(LISTEN_NONE));
|
SignalStrengthListener.SignalStrengthTelephonyCallback.class);
|
||||||
|
verify(mManager1, times(2)).registerTelephonyCallback(
|
||||||
|
any(Executor.class), captor1.capture());
|
||||||
|
verify(mManager1).unregisterTelephonyCallback(captor1.capture());
|
||||||
|
|
||||||
verify(mManager2, times(2)).listen(captor2.capture(), eq(LISTEN_SIGNAL_STRENGTHS));
|
verify(mManager2, times(2)).registerTelephonyCallback(
|
||||||
verify(mManager2).listen(captor2.capture(), eq(LISTEN_NONE));
|
any(Executor.class), captor2.capture());
|
||||||
|
verify(mManager2).unregisterTelephonyCallback(captor2.capture());
|
||||||
|
|
||||||
assertThat(captor1.getAllValues().get(0) == captor1.getAllValues().get(1)).isTrue();
|
assertThat(captor1.getAllValues().get(0) == captor1.getAllValues().get(1)).isTrue();
|
||||||
assertThat(captor1.getAllValues().get(0) == captor1.getAllValues().get(2)).isTrue();
|
assertThat(captor1.getAllValues().get(0) == captor1.getAllValues().get(2)).isTrue();
|
||||||
|
@@ -48,7 +48,6 @@ import android.content.Context;
|
|||||||
import android.os.PersistableBundle;
|
import android.os.PersistableBundle;
|
||||||
import android.telephony.CarrierConfigManager;
|
import android.telephony.CarrierConfigManager;
|
||||||
import android.telephony.CellSignalStrength;
|
import android.telephony.CellSignalStrength;
|
||||||
import android.telephony.PhoneStateListener;
|
|
||||||
import android.telephony.ServiceState;
|
import android.telephony.ServiceState;
|
||||||
import android.telephony.SignalStrength;
|
import android.telephony.SignalStrength;
|
||||||
import android.telephony.SubscriptionInfo;
|
import android.telephony.SubscriptionInfo;
|
||||||
@@ -89,8 +88,6 @@ public class SimStatusDialogControllerTest {
|
|||||||
@Mock
|
@Mock
|
||||||
private ServiceState mServiceState;
|
private ServiceState mServiceState;
|
||||||
@Mock
|
@Mock
|
||||||
private PhoneStateListener mPhoneStateListener;
|
|
||||||
@Mock
|
|
||||||
private SignalStrength mSignalStrength;
|
private SignalStrength mSignalStrength;
|
||||||
@Mock
|
@Mock
|
||||||
private CellSignalStrength mCellSignalStrengthCdma;
|
private CellSignalStrength mCellSignalStrengthCdma;
|
||||||
@@ -150,7 +147,6 @@ public class SimStatusDialogControllerTest {
|
|||||||
doReturn(0).when(mCellSignalStrengthWcdma).getAsuLevel();
|
doReturn(0).when(mCellSignalStrengthWcdma).getAsuLevel();
|
||||||
|
|
||||||
doReturn(null).when(mSignalStrength).getCellSignalStrengths();
|
doReturn(null).when(mSignalStrength).getCellSignalStrengths();
|
||||||
doReturn(mPhoneStateListener).when(mController).getPhoneStateListener();
|
|
||||||
doReturn(mSubscriptionInfo).when(mSubscriptionManager).getActiveSubscriptionInfo(anyInt());
|
doReturn(mSubscriptionInfo).when(mSubscriptionManager).getActiveSubscriptionInfo(anyInt());
|
||||||
|
|
||||||
when(mTelephonyManager.getActiveModemCount()).thenReturn(MAX_PHONE_COUNT_SINGLE_SIM);
|
when(mTelephonyManager.getActiveModemCount()).thenReturn(MAX_PHONE_COUNT_SINGLE_SIM);
|
||||||
|
@@ -124,13 +124,12 @@ public class MobileNetworkPreferenceControllerTest {
|
|||||||
|
|
||||||
mLifecycleRegistry.handleLifecycleEvent(Event.ON_START);
|
mLifecycleRegistry.handleLifecycleEvent(Event.ON_START);
|
||||||
verify(mController).onStart();
|
verify(mController).onStart();
|
||||||
verify(mTelephonyManager).listen(mController.mPhoneStateListener,
|
verify(mTelephonyManager).registerTelephonyCallback(
|
||||||
PhoneStateListener.LISTEN_SERVICE_STATE);
|
mContext.getMainExecutor(), mController.mTelephonyCallback);
|
||||||
|
|
||||||
mLifecycleRegistry.handleLifecycleEvent(Event.ON_STOP);
|
mLifecycleRegistry.handleLifecycleEvent(Event.ON_STOP);
|
||||||
verify(mController).onStop();
|
verify(mController).onStop();
|
||||||
verify(mTelephonyManager).listen(mController.mPhoneStateListener,
|
verify(mTelephonyManager).unregisterTelephonyCallback(mController.mTelephonyCallback);
|
||||||
PhoneStateListener.LISTEN_NONE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -148,12 +147,12 @@ public class MobileNetworkPreferenceControllerTest {
|
|||||||
mController.displayPreference(mScreen);
|
mController.displayPreference(mScreen);
|
||||||
mLifecycleRegistry.handleLifecycleEvent(Event.ON_START);
|
mLifecycleRegistry.handleLifecycleEvent(Event.ON_START);
|
||||||
verify(mController).onStart();
|
verify(mController).onStart();
|
||||||
verify(mTelephonyManager).listen(mController.mPhoneStateListener,
|
verify(mTelephonyManager).registerTelephonyCallback(
|
||||||
PhoneStateListener.LISTEN_SERVICE_STATE);
|
mContext.getMainExecutor(), mController.mTelephonyCallback);
|
||||||
|
|
||||||
doReturn(testCarrierName).when(mController).getSummary();
|
doReturn(testCarrierName).when(mController).getSummary();
|
||||||
|
|
||||||
mController.mPhoneStateListener.onServiceStateChanged(null);
|
mController.mTelephonyCallback.onServiceStateChanged(null);
|
||||||
|
|
||||||
// Carrier name should be set.
|
// Carrier name should be set.
|
||||||
Assert.assertEquals(mPreference.getSummary(), testCarrierName);
|
Assert.assertEquals(mPreference.getSummary(), testCarrierName);
|
||||||
|
Reference in New Issue
Block a user