Merge changes from topics "isDataAllow", "set_data_enabled"

* changes:
  SetDataEnabled indicate calling package
  Support isDataAllow correctly
diff --git a/src/com/android/phone/PhoneGlobals.java b/src/com/android/phone/PhoneGlobals.java
index 036a9be..426c473 100644
--- a/src/com/android/phone/PhoneGlobals.java
+++ b/src/com/android/phone/PhoneGlobals.java
@@ -66,6 +66,7 @@
 import com.android.internal.telephony.TelephonyCapabilities;
 import com.android.internal.telephony.TelephonyComponentFactory;
 import com.android.internal.telephony.TelephonyIntents;
+import com.android.internal.telephony.data.DataEvaluation.DataDisallowedReason;
 import com.android.internal.telephony.dataconnection.DataConnectionReasons;
 import com.android.internal.telephony.dataconnection.DataConnectionReasons.DataDisallowedReasonType;
 import com.android.internal.telephony.ims.ImsResolver;
@@ -834,11 +835,26 @@
             return;
         }
 
-        DataConnectionReasons reasons = new DataConnectionReasons();
-        boolean dataAllowed = phone.isDataAllowed(ApnSetting.TYPE_DEFAULT, reasons);
-        mDataRoamingNotifLog.log("dataAllowed=" + dataAllowed + ", reasons=" + reasons);
-        if (VDBG) Log.v(LOG_TAG, "dataAllowed=" + dataAllowed + ", reasons=" + reasons);
-        if (!dataAllowed && reasons.containsOnly(DataDisallowedReasonType.ROAMING_DISABLED)) {
+        boolean dataAllowed;
+        boolean notAllowedDueToRoamingOff;
+        if (phone.isUsingNewDataStack()) {
+            List<DataDisallowedReason> reasons = phone.getDataNetworkController()
+                    .getInternetDataDisallowedReasons();
+            dataAllowed = reasons.isEmpty();
+            notAllowedDueToRoamingOff = (reasons.size() == 1
+                    && reasons.contains(DataDisallowedReason.ROAMING_DISABLED));
+            mDataRoamingNotifLog.log("dataAllowed=" + dataAllowed + ", reasons=" + reasons);
+            if (VDBG) Log.v(LOG_TAG, "dataAllowed=" + dataAllowed + ", reasons=" + reasons);
+        } else {
+            DataConnectionReasons reasons = new DataConnectionReasons();
+            dataAllowed = phone.isDataAllowed(ApnSetting.TYPE_DEFAULT, reasons);
+            notAllowedDueToRoamingOff = reasons.containsOnly(
+                    DataDisallowedReasonType.ROAMING_DISABLED);
+            mDataRoamingNotifLog.log("dataAllowed=" + dataAllowed + ", reasons=" + reasons);
+            if (VDBG) Log.v(LOG_TAG, "dataAllowed=" + dataAllowed + ", reasons=" + reasons);
+        }
+
+        if (!dataAllowed && notAllowedDueToRoamingOff) {
             // No need to show it again if we never cancelled it explicitly.
             if (mPrevRoamingNotification == ROAMING_NOTIFICATION_DISCONNECTED) return;
             // If the only reason of no data is data roaming disabled, then we notify the user
@@ -866,7 +882,7 @@
             // showed earlier.
             mPrevRoamingNotification = ROAMING_NOTIFICATION_NO_NOTIFICATION;
             Log.d(LOG_TAG, "Dismiss roaming notification");
-            mDataRoamingNotifLog.log("Hide. data allowed=" + dataAllowed + ", reasons=" + reasons);
+            mDataRoamingNotifLog.log("Hide. data allowed=" + dataAllowed);
             mHandler.sendEmptyMessage(EVENT_DATA_ROAMING_OK);
         }
     }
diff --git a/src/com/android/phone/PhoneInterfaceManager.java b/src/com/android/phone/PhoneInterfaceManager.java
index c28e968..ba72539 100755
--- a/src/com/android/phone/PhoneInterfaceManager.java
+++ b/src/com/android/phone/PhoneInterfaceManager.java
@@ -2840,7 +2840,7 @@
 
     // FIXME: subId version needed
     @Override
-    public boolean enableDataConnectivity() {
+    public boolean enableDataConnectivity(String callingPackage) {
         enforceModifyPermission();
 
         final long identity = Binder.clearCallingIdentity();
@@ -2850,7 +2850,7 @@
             if (phone != null) {
                 if (phone.isUsingNewDataStack()) {
                     phone.getDataSettingsManager().setDataEnabled(
-                            TelephonyManager.DATA_ENABLED_REASON_USER, true);
+                            TelephonyManager.DATA_ENABLED_REASON_USER, true, callingPackage);
                 } else {
                     phone.getDataEnabledSettings().setDataEnabled(
                             TelephonyManager.DATA_ENABLED_REASON_USER, true);
@@ -2866,7 +2866,7 @@
 
     // FIXME: subId version needed
     @Override
-    public boolean disableDataConnectivity() {
+    public boolean disableDataConnectivity(String callingPackage) {
         enforceModifyPermission();
 
         final long identity = Binder.clearCallingIdentity();
@@ -2876,7 +2876,7 @@
             if (phone != null) {
                 if (phone.isUsingNewDataStack()) {
                     phone.getDataSettingsManager().setDataEnabled(
-                            TelephonyManager.DATA_ENABLED_REASON_USER, false);
+                            TelephonyManager.DATA_ENABLED_REASON_USER, false, callingPackage);
                 } else {
                     phone.getDataEnabledSettings().setDataEnabled(
                             TelephonyManager.DATA_ENABLED_REASON_USER, false);
@@ -7613,7 +7613,7 @@
     }
 
     @Override
-    public void factoryReset(int subId) {
+    public void factoryReset(int subId, String callingPackage) {
         enforceSettingsPermission();
         if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
             return;
@@ -7629,7 +7629,7 @@
             if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
                     UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
                 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
-                        getDefaultDataEnabled());
+                        getDefaultDataEnabled(), callingPackage);
                 setNetworkSelectionModeAutomatic(subId);
                 Phone phone = getPhone(subId);
                 cleanUpAllowedNetworkTypes(phone, subId);
@@ -8345,13 +8345,14 @@
     /**
      * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
      * @param subId Subscription index
-     * @param reason the reason the data enable change is taking place
+     * @param reason The reason the data enable change is taking place.
      * @param enabled True if enabling the data, otherwise disabling.
+     * @param callingPackage The package that changed the data enabled state.
      * @hide
      */
     @Override
     public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
-            boolean enabled) {
+            boolean enabled, String callingPackage) {
         if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
                 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
             try {
@@ -8372,7 +8373,8 @@
                     phone.carrierActionSetMeteredApnsEnabled(enabled);
                 } else {
                     if (phone.isUsingNewDataStack()) {
-                        phone.getDataSettingsManager().setDataEnabled(reason, enabled);
+                        phone.getDataSettingsManager().setDataEnabled(
+                                reason, enabled, callingPackage);
                     } else {
                         phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
                     }
@@ -10094,7 +10096,7 @@
     }
 
     private int handleDataThrottlingRequest(int subId,
-            DataThrottlingRequest dataThrottlingRequest) {
+            DataThrottlingRequest dataThrottlingRequest, String callingPackage) {
         boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
                 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
         if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
@@ -10108,7 +10110,8 @@
             return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
         }
 
-        setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true);
+        setDataEnabledForReason(
+                subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage);
 
         if (isDataThrottlingSupported) {
             int thermalMitigationResult =
@@ -10210,7 +10213,8 @@
                 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
                     thermalMitigationResult =
                         handleDataThrottlingRequest(subId,
-                                thermalMitigationRequest.getDataThrottlingRequest());
+                                thermalMitigationRequest.getDataThrottlingRequest(),
+                                callingPackage);
                     break;
                 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
                     if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
@@ -10227,7 +10231,7 @@
                     }
 
                     setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
-                            false);
+                            false, callingPackage);
                     thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
                     break;
                 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
diff --git a/src/com/android/phone/TelephonyShellCommand.java b/src/com/android/phone/TelephonyShellCommand.java
index ac83fa9..899e391 100644
--- a/src/com/android/phone/TelephonyShellCommand.java
+++ b/src/com/android/phone/TelephonyShellCommand.java
@@ -734,7 +734,7 @@
         switch (arg) {
             case ENABLE: {
                 try {
-                    mInterface.enableDataConnectivity();
+                    mInterface.enableDataConnectivity(mContext.getOpPackageName());
                 } catch (RemoteException ex) {
                     Log.w(LOG_TAG, "data enable, error " + ex.getMessage());
                     errPw.println("Exception: " + ex.getMessage());
@@ -744,7 +744,7 @@
             }
             case DISABLE: {
                 try {
-                    mInterface.disableDataConnectivity();
+                    mInterface.disableDataConnectivity(mContext.getOpPackageName());
                 } catch (RemoteException ex) {
                     Log.w(LOG_TAG, "data disable, error " + ex.getMessage());
                     errPw.println("Exception: " + ex.getMessage());