reset carrier actions on sim loaded

There are some use cases where carriers activate SIM's data service by
updating EF files with an ICC refresh event. Slightly different from hot
sim swap, this might not go through the complete SIM loading procedure
and won't recreate any new Icc Record as well.
- Move carrier action reset to recordsLoaded event handler which handles
both ICC refresh and hot sim swap.
- refactor carrier action reset from individual modules to carrier
action agent

Bug: 36154348
Test: Manual
Change-Id: I7af8b1d956ba7dfa1efdc8858b49903f24382dbe
diff --git a/src/java/com/android/internal/telephony/CarrierActionAgent.java b/src/java/com/android/internal/telephony/CarrierActionAgent.java
index f32daa0..be30739 100644
--- a/src/java/com/android/internal/telephony/CarrierActionAgent.java
+++ b/src/java/com/android/internal/telephony/CarrierActionAgent.java
@@ -15,6 +15,10 @@
  */
 package com.android.internal.telephony;
 
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
 import android.os.AsyncResult;
 import android.os.Handler;
 import android.os.Message;
@@ -25,7 +29,6 @@
 import android.util.Log;
 
 import com.android.internal.util.IndentingPrintWriter;
-
 import java.io.FileDescriptor;
 import java.io.PrintWriter;
 
@@ -49,6 +52,7 @@
     /** A list of carrier actions */
     public static final int CARRIER_ACTION_SET_METERED_APNS_ENABLED      = 0;
     public static final int CARRIER_ACTION_SET_RADIO_ENABLED             = 1;
+    public static final int CARRIER_ACTION_RESET                         = 2;
 
     /** Member variables */
     private final Phone mPhone;
@@ -62,9 +66,24 @@
     private Boolean mCarrierActionOnMeteredApnEnabled = true;
     private Boolean mCarrierActionOnRadioEnabled = true;
 
+    private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
+        @Override
+        public void onReceive(Context context, Intent intent) {
+            final String action = intent.getAction();
+            if (TelephonyIntents.ACTION_SIM_STATE_CHANGED.equals(action)){
+                if (IccCardConstants.INTENT_VALUE_ICC_LOADED.equals(
+                        intent.getStringExtra(IccCardConstants.INTENT_KEY_ICC_STATE))) {
+                    sendEmptyMessage(CARRIER_ACTION_RESET);
+                }
+            }
+        }
+    };
+
     /** Constructor */
     public CarrierActionAgent(Phone phone) {
         mPhone = phone;
+        mPhone.getContext().registerReceiver(mReceiver,
+                new IntentFilter(TelephonyIntents.ACTION_SIM_STATE_CHANGED));
         if (DBG) log("Creating CarrierActionAgent");
     }
 
@@ -86,6 +105,11 @@
                 mRadioEnableRegistrants.notifyRegistrants(
                         new AsyncResult(null, mCarrierActionOnRadioEnabled, null));
                 break;
+            case CARRIER_ACTION_RESET:
+                log("CARRIER_ACTION_RESET");
+                carrierActionSetMeteredApnsEnabled(true);
+                carrierActionSetRadioEnabled(true);
+                break;
             default:
                 loge("Unknown carrier action: " + msg.what);
         }
diff --git a/src/java/com/android/internal/telephony/dataconnection/DcTracker.java b/src/java/com/android/internal/telephony/dataconnection/DcTracker.java
index 25480d4..b7e18bc 100644
--- a/src/java/com/android/internal/telephony/dataconnection/DcTracker.java
+++ b/src/java/com/android/internal/telephony/dataconnection/DcTracker.java
@@ -4066,10 +4066,6 @@
                     mIccRecords.set(newIccRecords);
                     newIccRecords.registerForRecordsLoaded(
                             this, DctConstants.EVENT_RECORDS_LOADED, null);
-                    // reset carrier actions on sim loaded
-                    final ServiceStateTracker sst = mPhone.getServiceStateTracker();
-                    sst.setRadioPowerFromCarrier(true);
-                    mDataEnabledSettings.setCarrierDataEnabled(true);
                 }
             } else {
                 onSimNotReady();