Fix NPE when trying to clear MWI for invalid subId
VvmPhoneStateListener can be trigger with a when the PhoneAccountHanlde
no longer has a valid subId. why this can happen still needs
investigation.
This CL changed VvmPhoneStateListener to ignore invalid subIds, and
guard PhoneGlobals.clearMwiIndicator against null phone.
Bug: 30315483
Change-Id: I3d062991d8af63aaf0ebc76b3961a335dace3192
diff --git a/src/com/android/phone/PhoneGlobals.java b/src/com/android/phone/PhoneGlobals.java
index 4ff8d8e..2d87e78 100644
--- a/src/com/android/phone/PhoneGlobals.java
+++ b/src/com/android/phone/PhoneGlobals.java
@@ -45,7 +45,6 @@
import android.telephony.SubscriptionManager;
import android.util.Log;
import android.widget.Toast;
-
import com.android.internal.telephony.Call;
import com.android.internal.telephony.CallManager;
import com.android.internal.telephony.IccCardConstants;
@@ -850,6 +849,11 @@
public void clearMwiIndicator(int subId) {
// Setting voiceMessageCount to 0 will remove the current notification and clear the system
// cached value.
- getPhone(subId).setVoiceMessageCount(0);
+ Phone phone = getPhone(subId);
+ if (phone == null) {
+ Log.w(LOG_TAG, "clearMwiIndicator on null phone, subId:" + subId);
+ } else {
+ phone.setVoiceMessageCount(0);
+ }
}
}
diff --git a/src/com/android/phone/vvm/omtp/VvmPhoneStateListener.java b/src/com/android/phone/vvm/omtp/VvmPhoneStateListener.java
index f64d15b..94e616c 100644
--- a/src/com/android/phone/vvm/omtp/VvmPhoneStateListener.java
+++ b/src/com/android/phone/vvm/omtp/VvmPhoneStateListener.java
@@ -19,6 +19,7 @@
import android.telecom.PhoneAccountHandle;
import android.telephony.PhoneStateListener;
import android.telephony.ServiceState;
+import android.telephony.SubscriptionManager;
import com.android.phone.PhoneGlobals;
import com.android.phone.PhoneUtils;
import com.android.phone.VoicemailStatus;
@@ -47,6 +48,13 @@
@Override
public void onServiceStateChanged(ServiceState serviceState) {
+ int subId = PhoneAccountHandleConverter.toSubId(mPhoneAccount);
+ if (!SubscriptionManager.isValidSubscriptionId(subId)) {
+ VvmLog.e(TAG, "onServiceStateChanged on phoneAccount " + mPhoneAccount
+ + " with invalid subId, ignoring");
+ return;
+ }
+
int state = serviceState.getState();
if (state == mPreviousState || (state != ServiceState.STATE_IN_SERVICE
&& mPreviousState != ServiceState.STATE_IN_SERVICE)) {
@@ -56,7 +64,6 @@
return;
}
- int subId = PhoneAccountHandleConverter.toSubId(mPhoneAccount);
OmtpVvmCarrierConfigHelper helper = new OmtpVvmCarrierConfigHelper(mContext, subId);
if (state == ServiceState.STATE_IN_SERVICE) {