Merge "update sim activation state for otasp" am: 6b784f4c92 am: 046fdb7d99
am: 774dfb7212

Change-Id: I62c993ce47043b9310265c0688b4ed6af8ed4938
diff --git a/src/com/android/phone/otasp/OtaspActivationService.java b/src/com/android/phone/otasp/OtaspActivationService.java
index 504315f..158925a 100644
--- a/src/com/android/phone/otasp/OtaspActivationService.java
+++ b/src/com/android/phone/otasp/OtaspActivationService.java
@@ -16,12 +16,15 @@
 package com.android.phone.otasp;
 
 import android.app.Service;
+import android.content.Context;
 import android.content.Intent;
 import android.os.AsyncResult;
 import android.os.Handler;
 import android.os.IBinder;
 import android.os.Message;
 import android.telephony.ServiceState;
+import android.telephony.SubscriptionManager;
+import android.telephony.TelephonyManager;
 
 import com.android.internal.telephony.Phone;
 import com.android.internal.telephony.PhoneConstants;
@@ -80,7 +83,7 @@
         logd("OTASP call tried " + sOtaspCallRetries + " times");
         if (sOtaspCallRetries > OTASP_CALL_RETRIES_MAX) {
             logd("OTASP call exceeds max retries => activation failed");
-            //TODO updateActivationState(DEACTIVATED)
+            updateActivationState(this, false);
             onComplete();
             return;
         }
@@ -180,10 +183,10 @@
         if (mPhone.getState().equals(PhoneConstants.State.IDLE)) {
             if (mIsOtaspCallCommitted) {
                 logd("Otasp activation succeed");
-                //TODO updateActivationState(ACTIVATED)
+                updateActivationState(this, true);
             } else {
                 logd("Otasp activation failed");
-                //TODO updateActivationState(DEACTIVATED)
+                updateActivationState(this, false);
             }
             onComplete();
         }
@@ -203,6 +206,15 @@
         mHandler.removeCallbacksAndMessages(null);
     }
 
+    public static void updateActivationState(Context context, boolean success) {
+        final TelephonyManager mTelephonyMgr = TelephonyManager.from(context);
+        int state = (success) ? TelephonyManager.SIM_ACTIVATION_STATE_ACTIVATED :
+                TelephonyManager.SIM_ACTIVATION_STATE_DEACTIVATED;
+        int subId = SubscriptionManager.getDefaultSubscriptionId();
+        mTelephonyMgr.setVoiceActivationState(subId, state);
+        mTelephonyMgr.setDataActivationState(subId, state);
+    }
+
     private static void logd(String s) {
         android.util.Log.d(TAG, s);
     }
diff --git a/src/com/android/phone/otasp/OtaspSimStateReceiver.java b/src/com/android/phone/otasp/OtaspSimStateReceiver.java
index ef34e20..c0409ba 100644
--- a/src/com/android/phone/otasp/OtaspSimStateReceiver.java
+++ b/src/com/android/phone/otasp/OtaspSimStateReceiver.java
@@ -36,10 +36,11 @@
         @Override
         public void onOtaspChanged(int otaspMode) {
             logd("onOtaspChanged: otaspMode=" + otaspMode);
-            if (otaspMode == ServiceStateTracker.OTASP_NEEDED && isCarrierSupported()
-                    && PhoneGlobals.getPhone().getIccRecordsLoaded()) {
+            if (otaspMode == ServiceStateTracker.OTASP_NEEDED) {
                 logd("otasp activation required, start otaspActivationService");
                 mContext.startService(new Intent(mContext, OtaspActivationService.class));
+            } else if (otaspMode == ServiceStateTracker.OTASP_NOT_NEEDED) {
+                OtaspActivationService.updateActivationState(mContext, true);
             }
         }
     };
@@ -72,9 +73,11 @@
         mContext = context;
         if(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED.equals(intent.getAction())) {
             if (DBG) logd("Received intent: " + intent.getAction());
-            final TelephonyManager telephonyManager = (TelephonyManager) context
-                    .getSystemService(Context.TELEPHONY_SERVICE);
-            telephonyManager.listen(mPhoneStateListener, PhoneStateListener.LISTEN_OTASP_CHANGED);
+            if (PhoneGlobals.getPhone().getIccRecordsLoaded() && isCarrierSupported()) {
+                final TelephonyManager telephonyManager = TelephonyManager.from(context);
+                telephonyManager.listen(mPhoneStateListener,
+                        PhoneStateListener.LISTEN_OTASP_CHANGED);
+            }
         }
     }