Revert "Support api to control data by thermal service"

Revert "Support api to control data by thermal service"

Revert submission 11171206-setDataEnabled

Bug: 155765311
Reason for revert: wembley gets into boot loop on reboot due to this code
Reverted Changes:
I3cdab9b04:Support api to control data by thermal service
I716cf6c45:CTS test for api to control data by thermal servic...
Ic5634e6f7:Support api to control data by thermal service
I763c422ba:Support api to control data by thermal service

Change-Id: I743b7fb26528188401aa0ff996f2485e5908167c
diff --git a/src/com/android/phone/PhoneInterfaceManager.java b/src/com/android/phone/PhoneInterfaceManager.java
index 8d360f6..e0d16bd 100755
--- a/src/com/android/phone/PhoneInterfaceManager.java
+++ b/src/com/android/phone/PhoneInterfaceManager.java
@@ -2134,8 +2134,7 @@
             int subId = mSubscriptionController.getDefaultDataSubId();
             final Phone phone = getPhone(subId);
             if (phone != null) {
-                phone.getDataEnabledSettings().setDataEnabled(
-                        TelephonyManager.DATA_ENABLED_REASON_USER, true);
+                phone.getDataEnabledSettings().setUserDataEnabled(true);
                 return true;
             } else {
                 return false;
@@ -2155,8 +2154,7 @@
             int subId = mSubscriptionController.getDefaultDataSubId();
             final Phone phone = getPhone(subId);
             if (phone != null) {
-                phone.getDataEnabledSettings().setDataEnabled(
-                        TelephonyManager.DATA_ENABLED_REASON_USER, false);
+                phone.getDataEnabledSettings().setUserDataEnabled(false);
                 return true;
             } else {
                 return false;
@@ -5587,6 +5585,33 @@
     }
 
     /**
+     * Set mobile data enabled
+     * Used by the user through settings etc to turn on/off mobile data
+     *
+     * @param enable {@code true} turn turn data on, else {@code false}
+     */
+    @Override
+    public void setUserDataEnabled(int subId, boolean enable) {
+        TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
+                mApp, subId, "setUserDataEnabled");
+
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            int phoneId = mSubscriptionController.getPhoneId(subId);
+            if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
+            Phone phone = PhoneFactory.getPhone(phoneId);
+            if (phone != null) {
+                if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
+                phone.getDataEnabledSettings().setUserDataEnabled(enable);
+            } else {
+                loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
+            }
+        } finally {
+            Binder.restoreCallingIdentity(identity);
+        }
+    }
+
+    /**
      * Enable or disable always reporting signal strength changes from radio.
      *
      * @param isEnable {@code true} for enabling; {@code false} for disabling.
@@ -5696,53 +5721,6 @@
         }
     }
 
-    /**
-     * Check if data is enabled for a specific reason
-     * @param subId Subscription index
-     * @param reason the reason the data enable change is taking place
-     * @return {@code true} if the overall data is enabled; {@code false} if not.
-     */
-    @Override
-    public boolean isDataEnabledWithReason(int subId,
-            @TelephonyManager.DataEnabledReason int reason) {
-        try {
-            mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
-                    null);
-        } catch (Exception e) {
-            mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
-                    "isDataEnabledWithReason");
-        }
-
-
-        final long identity = Binder.clearCallingIdentity();
-        try {
-            int phoneId = mSubscriptionController.getPhoneId(subId);
-            if (DBG) {
-                log("isDataEnabledWithReason: subId=" + subId + " phoneId=" + phoneId
-                        + " reason=" + reason);
-            }
-            Phone phone = PhoneFactory.getPhone(phoneId);
-            if (phone != null) {
-                boolean retVal;
-                if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
-                    retVal = phone.isUserDataEnabled();
-                } else {
-                    retVal = phone.getDataEnabledSettings().isDataEnabledWithReason(reason);
-                }
-                if (DBG) log("isDataEnabledWithReason: retVal=" + retVal);
-                return retVal;
-            } else {
-                if (DBG) {
-                    loge("isDataEnabledWithReason: no phone subId="
-                            + subId + " retVal=false");
-                }
-                return false;
-            }
-        } finally {
-            Binder.restoreCallingIdentity(identity);
-        }
-    }
-
     private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
             Phone phone) {
         //load access rules from carrier configs, and check those as well: b/139133814
@@ -6552,8 +6530,7 @@
         try {
             if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
                     UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
-                setDataEnabledWithReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
-                        getDefaultDataEnabled());
+                setUserDataEnabled(subId, getDefaultDataEnabled());
                 setNetworkSelectionModeAutomatic(subId);
                 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
                 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
@@ -7073,6 +7050,31 @@
     }
 
     /**
+     * Action set from carrier signalling broadcast receivers to enable/disable metered apns
+     * @param subId the subscription ID that this action applies to.
+     * @param enabled control enable or disable metered apns.
+     * {@hide}
+     */
+    @Override
+    public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
+        enforceModifyPermission();
+        final Phone phone = getPhone(subId);
+
+        final long identity = Binder.clearCallingIdentity();
+        if (phone == null) {
+            loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
+            return;
+        }
+        try {
+            phone.carrierActionSetMeteredApnsEnabled(enabled);
+        } catch (Exception e) {
+            Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
+        } finally {
+            Binder.restoreCallingIdentity(identity);
+        }
+    }
+
+    /**
      * Action set from carrier signalling broadcast receivers to enable/disable radio
      * @param subId the subscription ID that this action applies to.
      * @param enabled control enable or disable radio.
@@ -7173,36 +7175,20 @@
     }
 
     /**
-     * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
-     * @param subId Subscription index
-     * @param reason the reason the data enable change is taking place
+     * Policy control of data connection. Usually used when data limit is passed.
      * @param enabled True if enabling the data, otherwise disabling.
-     * @hide
+     * @param subId Subscription index
+     * {@hide}
      */
     @Override
-    public void setDataEnabledWithReason(int subId, @TelephonyManager.DataEnabledReason int reason,
-            boolean enabled) {
-        if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
-                || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
-            try {
-                TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
-                        mApp, subId, "setDataEnabledWithReason");
-            } catch (SecurityException se) {
-                enforceModifyPermission();
-            }
-        } else {
-            enforceModifyPermission();
-        }
+    public void setPolicyDataEnabled(boolean enabled, int subId) {
+        enforceModifyPermission();
 
         final long identity = Binder.clearCallingIdentity();
         try {
             Phone phone = getPhone(subId);
             if (phone != null) {
-                if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
-                    phone.carrierActionSetMeteredApnsEnabled(enabled);
-                } else {
-                    phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
-                }
+                phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
             }
         } finally {
             Binder.restoreCallingIdentity(identity);