Merge "Fix NPE in VvmSimStateTracker"
diff --git a/src/com/android/phone/vvm/VvmSimStateTracker.java b/src/com/android/phone/vvm/VvmSimStateTracker.java
index 069111a..1059f86 100644
--- a/src/com/android/phone/vvm/VvmSimStateTracker.java
+++ b/src/com/android/phone/vvm/VvmSimStateTracker.java
@@ -80,12 +80,19 @@
}
public void listen() {
- getTelephonyManager(mContext, mPhoneAccountHandle)
- .listen(this, PhoneStateListener.LISTEN_SERVICE_STATE);
+ TelephonyManager telephonyManager = getTelephonyManager(mContext, mPhoneAccountHandle);
+ if(telephonyManager == null){
+ VvmLog.e(TAG, "Cannot create TelephonyManager from " + mPhoneAccountHandle);
+ return;
+ }
+ telephonyManager.listen(this, PhoneStateListener.LISTEN_SERVICE_STATE);
}
public void unlisten() {
- getTelephonyManager(mContext, mPhoneAccountHandle)
+ // TelephonyManager does not need to be pinned to an account when removing a
+ // PhoneStateListener, and mPhoneAccountHandle might be invalid at this point
+ // (e.g. SIM removal)
+ mContext.getSystemService(TelephonyManager.class)
.listen(this, PhoneStateListener.LISTEN_NONE);
sListeners.put(mPhoneAccountHandle, null);
}