Fixed invalid MCC MNC for VVM config upon connection.

TelephonyManager.getNetworkOperator() is unreliable on CDMA network.
When the network has just connected, it could report invalid value such
as "00000", and cause an invalid config for visual voicemail to be
loaded.

TelephonyManager.getSimOperator() is more reliable. It should return a
correct value once the SIM is ready, before the network is connected.

The full cause of b/29254367 should be:
1. Full reboot:
The system is busy, activation of VVM is delayed so much that when it
is finally processing, getNetworkOperator() was stabilized and VVM config
is valid. The enabled status is written to the preferences before
ag/1126917.

2. SIM insertion:
Activation run much faster. getNetworkOperator() is called when the
network has just connected and returned a invalid value. VVM config is
deemed invalid, and the enabled status is not set which defaulted to
false before ag/1126917.

Bug: 29254367
Change-Id: I5d6dd17e7de6d04cad6f46dcddfb68d5b00df7aa
diff --git a/src/com/android/phone/vvm/omtp/OmtpVvmCarrierConfigHelper.java b/src/com/android/phone/vvm/omtp/OmtpVvmCarrierConfigHelper.java
index cd27ade..8a6cf30 100644
--- a/src/com/android/phone/vvm/omtp/OmtpVvmCarrierConfigHelper.java
+++ b/src/com/android/phone/vvm/omtp/OmtpVvmCarrierConfigHelper.java
@@ -99,7 +99,7 @@
         TelephonyManager telephonyManager =
                 (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
         mTelephonyConfig = new TelephonyVvmConfigManager(context.getResources())
-                .getConfig(telephonyManager.getNetworkOperator(subId));
+                .getConfig(telephonyManager.getSimOperator(subId));
 
         mVvmType = getVvmType();
         mProtocol = VisualVoicemailProtocolFactory.create(mVvmType);
diff --git a/src/com/android/phone/vvm/omtp/SimChangeReceiver.java b/src/com/android/phone/vvm/omtp/SimChangeReceiver.java
index 833daa9..30876ce 100644
--- a/src/com/android/phone/vvm/omtp/SimChangeReceiver.java
+++ b/src/com/android/phone/vvm/omtp/SimChangeReceiver.java
@@ -23,6 +23,7 @@
 import android.telecom.PhoneAccountHandle;
 import android.telephony.CarrierConfigManager;
 import android.telephony.SubscriptionManager;
+import android.telephony.TelephonyManager;
 import android.util.Log;
 
 import com.android.internal.telephony.IccCardConstants;
@@ -42,7 +43,7 @@
  */
 public class SimChangeReceiver extends BroadcastReceiver {
 
-    private static final String TAG = "SimChangeReceiver";
+    private static final String TAG = "VvmSimChangeReceiver";
 
     @Override
     public void onReceive(Context context, Intent intent) {
@@ -73,8 +74,9 @@
                     Log.i(TAG, "Received SIM change for invalid subscription id.");
                     return;
                 }
-
+                Log.d(TAG, "Carrier config changed");
                 if (!UserManager.get(context).isUserUnlocked()) {
+                    Log.d(TAG, "User locked, activation request delayed until unlock");
                     OmtpBootCompletedReceiver.addDeferredSubId(context, subId);
                 } else {
                     processSubId(context, subId);
@@ -90,7 +92,7 @@
             PhoneAccountHandle phoneAccount = PhoneAccountHandleConverter.fromSubId(subId);
 
             if (VisualVoicemailSettingsUtil.isVisualVoicemailEnabled(context, phoneAccount)) {
-                LocalLogHelper.log(TAG, "Sim state or carrier config changed: requesting"
+                Log.i(TAG, "Sim state or carrier config changed: requesting"
                         + " activation for " + phoneAccount.getId());
 
                 // Add a phone state listener so that changes to the communication channels
@@ -104,6 +106,10 @@
                 OmtpVvmSourceManager.getInstance(context).removeSource(phoneAccount);
                 Log.v(TAG, "Sim change for disabled account.");
             }
+        } else {
+            String mccMnc = context.getSystemService(TelephonyManager.class).getSimOperator(subId);
+            Log.d(TAG,
+                    "visual voicemail not supported for carrier " + mccMnc + " on subId " + subId);
         }
     }
 }
\ No newline at end of file