Merge "[Settings] Revert the test for using mPhoneStateListener since the Robolectric test is broken" into sc-dev
This commit is contained in:
@@ -24,7 +24,6 @@ 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;
|
||||||
|
|
||||||
@@ -62,7 +61,7 @@ public class AirplaneModeEnabler extends GlobalSettingsChangeListener {
|
|||||||
|
|
||||||
private TelephonyManager mTelephonyManager;
|
private TelephonyManager mTelephonyManager;
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
AirplaneModeTelephonyCallback mTelephonyCallback;
|
PhoneStateListener mPhoneStateListener;
|
||||||
|
|
||||||
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);
|
||||||
@@ -72,18 +71,16 @@ public class AirplaneModeEnabler extends GlobalSettingsChangeListener {
|
|||||||
mOnAirplaneModeChangedListener = listener;
|
mOnAirplaneModeChangedListener = listener;
|
||||||
|
|
||||||
mTelephonyManager = context.getSystemService(TelephonyManager.class);
|
mTelephonyManager = context.getSystemService(TelephonyManager.class);
|
||||||
mTelephonyCallback = new AirplaneModeTelephonyCallback();
|
|
||||||
}
|
|
||||||
|
|
||||||
class AirplaneModeTelephonyCallback extends TelephonyCallback implements
|
mPhoneStateListener = new PhoneStateListener(Looper.getMainLooper()) {
|
||||||
TelephonyCallback.RadioPowerStateListener {
|
@Override
|
||||||
@Override
|
public void onRadioPowerStateChanged(int state) {
|
||||||
public void onRadioPowerStateChanged(int state) {
|
if (DEBUG) {
|
||||||
if (DEBUG) {
|
Log.d(LOG_TAG, "RadioPower: " + state);
|
||||||
Log.d(LOG_TAG, "RadioPower: " + state);
|
}
|
||||||
|
onAirplaneModeChanged();
|
||||||
}
|
}
|
||||||
onAirplaneModeChanged();
|
};
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -101,14 +98,16 @@ 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.registerTelephonyCallback(mContext.getMainExecutor(), mTelephonyCallback);
|
mTelephonyManager.listen(mPhoneStateListener,
|
||||||
|
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.unregisterTelephonyCallback(mTelephonyCallback);
|
mTelephonyManager.listen(mPhoneStateListener,
|
||||||
|
PhoneStateListener.LISTEN_NONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setAirplaneModeOn(boolean enabling) {
|
private void setAirplaneModeOn(boolean enabling) {
|
||||||
@@ -193,3 +192,4 @@ public class AirplaneModeEnabler extends GlobalSettingsChangeListener {
|
|||||||
return WirelessUtils.isAirplaneModeOn(mContext);
|
return WirelessUtils.isAirplaneModeOn(mContext);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -57,7 +57,7 @@ public final class AirplaneModeEnablerTest {
|
|||||||
|
|
||||||
ShadowSettings.setAirplaneMode(true);
|
ShadowSettings.setAirplaneMode(true);
|
||||||
|
|
||||||
mAirplaneModeEnabler.mTelephonyCallback.onRadioPowerStateChanged(
|
mAirplaneModeEnabler.mPhoneStateListener.onRadioPowerStateChanged(
|
||||||
TelephonyManager.RADIO_POWER_OFF);
|
TelephonyManager.RADIO_POWER_OFF);
|
||||||
|
|
||||||
verify(mAirplaneModeChangedListener, times(1)).onAirplaneModeChanged(true);
|
verify(mAirplaneModeChangedListener, times(1)).onAirplaneModeChanged(true);
|
||||||
|
Reference in New Issue
Block a user