Listen to subscription info changes to update MWI.
MWI refers to "message waiting indicator" (aka. voicemail
notifications). Before, there custom delay/retry code to handle if
the SIM was not yet registered, but the network indicated a voicemail.
This CL deletes that custom logic, and instead listens for changes
to the subscription info (which should change with SIM registration)
as a trigger for retrying to show the message waiting. I moved some
logic into NotificationMgr so this behavior can be centralized in
one class.
This clears the way to implement some MSIM voicemail notification
settings; the retry logic was written assuming there was only one
internal.telephony.Phone, but there may now be multiple ones. This
change makes it easier to iterate over all the phones and update
their MWIs, which will be done in a subsequent CL.
It's a little tricky to test the exact scenario which this case
accounted for; I tested by removing/re-inserting a SIM to see if
it updated accordingly (which it did successfully).
Bug: 18232725
Change-Id: Ica2c5a2ddef8a2efc2c40c2f4d8729b485eb0bf7
diff --git a/src/com/android/phone/NotificationMgr.java b/src/com/android/phone/NotificationMgr.java
index 77daabb..badca74 100644
--- a/src/com/android/phone/NotificationMgr.java
+++ b/src/com/android/phone/NotificationMgr.java
@@ -35,6 +35,8 @@
import android.telecom.PhoneAccount;
import android.telephony.PhoneNumberUtils;
import android.telephony.ServiceState;
+import android.telephony.SubscriptionManager;
+import android.telephony.SubscriptionManager.OnSubscriptionsChangedListener;
import android.text.TextUtils;
import android.util.Log;
import android.widget.Toast;
@@ -56,7 +58,7 @@
* @see PhoneGlobals.notificationMgr
*/
public class NotificationMgr {
- private static final String LOG_TAG = "NotificationMgr";
+ private static final String LOG_TAG = NotificationMgr.class.getSimpleName();
private static final boolean DBG =
(PhoneGlobals.DBG_LEVEL >= 1) && (SystemProperties.getInt("ro.debuggable", 0) == 1);
// Do not check in with VDBG = true, since that may write PII to the system log.
@@ -87,11 +89,6 @@
// used to track the notification of selected network unavailable
private boolean mSelectedUnavailableNotify = false;
- // Retry params for the getVoiceMailNumber() call; see updateMwi().
- private static final int MAX_VM_NUMBER_RETRIES = 5;
- private static final int VM_NUMBER_RETRY_DELAY_MILLIS = 10000;
- private int mVmNumberRetriesRemaining = MAX_VM_NUMBER_RETRIES;
-
/**
* Private constructor (this is a singleton).
* @see #init(PhoneGlobals)
@@ -106,6 +103,15 @@
mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
mPhone = app.phone; // TODO: better style to use mCM.getDefaultPhone() everywhere instead
statusBarHelper = new StatusBarHelper();
+
+ SubscriptionManager.from(mContext).registerOnSubscriptionsChangedListener(
+ new OnSubscriptionsChangedListener() {
+ @Override
+ public void onSubscriptionsChanged() {
+ // Update the message waiting indicator if the SIM is changed.
+ updateMwi(mPhone.getMessageWaitingIndicator());
+ }
+ });
}
/**
@@ -237,6 +243,13 @@
/* package */ void updateMwi(boolean visible) {
if (DBG) log("updateMwi(): " + visible);
+ if (!PhoneGlobals.sVoiceCapable) {
+ // Do not show the message waiting indicator on devices which are not voice capable.
+ // These events *should* be blocked at the telephony layer for such devices.
+ Log.w(LOG_TAG, "Called updateMwi() on non-voice-capable device! Ignoring...");
+ return;
+ }
+
if (visible) {
int resId = android.R.drawable.stat_notify_voicemail;
@@ -254,45 +267,16 @@
String vmNumber = mPhone.getVoiceMailNumber();
if (DBG) log("- got vm number: '" + vmNumber + "'");
- // Watch out: vmNumber may be null, for two possible reasons:
- //
- // (1) This phone really has no voicemail number
- //
- // (2) This phone *does* have a voicemail number, but
- // the SIM isn't ready yet.
- //
- // Case (2) *does* happen in practice if you have voicemail
- // messages when the device first boots: we get an MWI
- // notification as soon as we register on the network, but the
- // SIM hasn't finished loading yet.
- //
- // So handle case (2) by retrying the lookup after a short
- // delay.
-
+ // The voicemail number may be null because:
+ // (1) This phone has no voicemail number.
+ // (2) This phone has a voicemail number, but the SIM isn't ready yet. This may
+ // happen when the device first boots if we get a MWI notification when we
+ // register on the network before the SIM has loaded. In this case, the
+ // SubscriptionListener this class registers on the SubscriptionManager will
+ // call this method again once the SIM is loaded.
if ((vmNumber == null) && !mPhone.getIccRecordsLoaded()) {
if (DBG) log("- Null vm number: SIM records not loaded (yet)...");
-
- // TODO: rather than retrying after an arbitrary delay, it
- // would be cleaner to instead just wait for a
- // SIM_RECORDS_LOADED notification.
- // (Unfortunately right now there's no convenient way to
- // get that notification in phone app code. We'd first
- // want to add a call like registerForSimRecordsLoaded()
- // to Phone.java and GSMPhone.java, and *then* we could
- // listen for that in the CallNotifier class.)
-
- // Limit the number of retries (in case the SIM is broken
- // or missing and can *never* load successfully.)
- if (mVmNumberRetriesRemaining-- > 0) {
- if (DBG) log(" - Retrying in " + VM_NUMBER_RETRY_DELAY_MILLIS + " msec...");
- mApp.notifier.sendMwiChangedDelayed(VM_NUMBER_RETRY_DELAY_MILLIS);
- return;
- } else {
- Log.w(LOG_TAG, "NotificationMgr.updateMwi: getVoiceMailNumber() failed after "
- + MAX_VM_NUMBER_RETRIES + " retries; giving up.");
- // ...and continue with vmNumber==null, just as if the
- // phone had no VM number set up in the first place.
- }
+ return;
}
if (TelephonyCapabilities.supportsVoiceMessageCount(mPhone)) {