[Settings] Use TelephonyManasger.registerTelephonyCallback instead of TelephonyManager.listen

Bug: 175270951
Test: make and atest
Change-Id: I15e1a199e6a34914db97055bfea9392c5bbdc9c6
This commit is contained in:
Zoey Chen
2021-03-10 16:01:18 +08:00
parent 0872d40a75
commit b8a639f8fd
12 changed files with 202 additions and 175 deletions

View File

@@ -20,11 +20,11 @@ import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Looper;
import android.os.PersistableBundle;
import android.telephony.CarrierConfigManager;
import android.telephony.PhoneStateListener;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyCallback;
import android.telephony.TelephonyManager;
import android.telephony.ims.ImsMmTelManager;
import android.util.Log;
@@ -53,7 +53,7 @@ public class Enhanced4gBasePreferenceController extends TelephonyTogglePreferenc
@VisibleForTesting
Preference mPreference;
private PhoneCallStateListener mPhoneStateListener;
private PhoneCallStateTelephonyCallback mTelephonyCallback;
private boolean mShow5gLimitedDialog;
boolean mIsNrEnabledFromCarrierConfig;
private boolean mHas5gCapability;
@@ -72,8 +72,8 @@ public class Enhanced4gBasePreferenceController extends TelephonyTogglePreferenc
}
public Enhanced4gBasePreferenceController init(int subId) {
if (mPhoneStateListener == null) {
mPhoneStateListener = new PhoneCallStateListener();
if (mTelephonyCallback == null) {
mTelephonyCallback = new PhoneCallStateTelephonyCallback();
}
if (mSubId == subId) {
@@ -134,18 +134,18 @@ public class Enhanced4gBasePreferenceController extends TelephonyTogglePreferenc
@Override
public void onStart() {
if (!isModeMatched() || (mPhoneStateListener == null)) {
if (!isModeMatched() || (mTelephonyCallback == null)) {
return;
}
mPhoneStateListener.register(mContext, mSubId);
mTelephonyCallback.register(mContext, mSubId);
}
@Override
public void onStop() {
if (mPhoneStateListener == null) {
if (mTelephonyCallback == null) {
return;
}
mPhoneStateListener.unregister();
mTelephonyCallback.unregister();
}
@Override
@@ -218,16 +218,13 @@ public class Enhanced4gBasePreferenceController extends TelephonyTogglePreferenc
CarrierConfigManager.KEY_EDITABLE_ENHANCED_4G_LTE_BOOL);
}
private class PhoneCallStateListener extends PhoneStateListener {
PhoneCallStateListener() {
super(Looper.getMainLooper());
}
private class PhoneCallStateTelephonyCallback extends TelephonyCallback implements
TelephonyCallback.CallStateListener {
private TelephonyManager mTelephonyManager;
@Override
public void onCallStateChanged(int state, String incomingNumber) {
public void onCallStateChanged(int state) {
mCallState = state;
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
// before first onCallStateChanged() by initial registration.
mCallState = mTelephonyManager.getCallState(subId);
mTelephonyManager.listen(this, PhoneStateListener.LISTEN_CALL_STATE);
mTelephonyManager.registerTelephonyCallback(
mContext.getMainExecutor(), mTelephonyCallback);
final long supportedRadioBitmask = mTelephonyManager.getSupportedRadioAccessFamily();
mHas5gCapability =
@@ -250,7 +248,7 @@ public class Enhanced4gBasePreferenceController extends TelephonyTogglePreferenc
public void unregister() {
mCallState = null;
if (mTelephonyManager != null) {
mTelephonyManager.listen(this, PhoneStateListener.LISTEN_NONE);
mTelephonyManager.unregisterTelephonyCallback(this);
}
}
}