Work around for telephony service crashing under FBE

b/29358683 is suspected to be a bug in file based encryption.
UserManger.isUserUnlocked() is reporting true even if the phone is still
locked, and subsequent operations that depends on being unlocked will
crash.

This is a temporary workaround until the issue is resolved. Note that
after this change telephony service is no longer crashing, but the
phone will be stuck in airplane mode when locked so something else is
still wrong.

Change-Id: Ibe5b6f3bdf072b87aa482485d1c6909863dcf1c9
diff --git a/src/com/android/phone/vvm/omtp/SimChangeReceiver.java b/src/com/android/phone/vvm/omtp/SimChangeReceiver.java
index a8de8cd..677e8b2 100644
--- a/src/com/android/phone/vvm/omtp/SimChangeReceiver.java
+++ b/src/com/android/phone/vvm/omtp/SimChangeReceiver.java
@@ -79,7 +79,22 @@
                     Log.d(TAG, "User locked, activation request delayed until unlock");
                     OmtpBootCompletedReceiver.addDeferredSubId(context, subId);
                 } else {
-                    processSubId(context, subId);
+                    try {
+                        processSubId(context, subId);
+                    } catch (IllegalArgumentException e) {
+                        // b/29358683 for some unknown reason UserManager.isUserUnlocked() could
+                        // return true even if the device is not unlocked, which will cause a
+                        // IllegalArgumentException when trying to write voicemail status.
+                        // Catch it as a workaround while investigating.
+                        Log.e(TAG, e.toString());
+                        Log.e(TAG, "UserManager.isUserUnlocked: " + UserManager.get(context)
+                            .isUserUnlocked());
+                        PhoneAccountHandle phoneAccount = PhoneAccountHandleConverter
+                            .fromSubId(subId);
+                        OmtpVvmSourceManager.getInstance(context)
+                            .removePhoneStateListener(phoneAccount);
+                        OmtpBootCompletedReceiver.addDeferredSubId(context, subId);
+                    }
                 }
                 break;
         }