Merge "Add log for setDataEnabledForReason" into main
diff --git a/src/com/android/settings/datausage/CellDataPreference.java b/src/com/android/settings/datausage/CellDataPreference.java
index 3bd3ecc..a64bc19 100644
--- a/src/com/android/settings/datausage/CellDataPreference.java
+++ b/src/com/android/settings/datausage/CellDataPreference.java
@@ -152,8 +152,7 @@
     }
 
     private void setMobileDataEnabled(boolean enabled) {
-        if (DataUsageSummary.LOGD) Log.d(TAG, "setMobileDataEnabled(" + enabled + ","
-                + mSubId + ")");
+        Log.d(TAG, "setDataEnabledForReason (" + enabled + "," + mSubId + ")");
         getContext().getSystemService(TelephonyManager.class).setDataEnabled(mSubId, enabled);
         setChecked(enabled);
     }
diff --git a/src/com/android/settings/homepage/contextualcards/conditional/CellularDataConditionController.java b/src/com/android/settings/homepage/contextualcards/conditional/CellularDataConditionController.java
index 9c936b9..e017114 100644
--- a/src/com/android/settings/homepage/contextualcards/conditional/CellularDataConditionController.java
+++ b/src/com/android/settings/homepage/contextualcards/conditional/CellularDataConditionController.java
@@ -23,6 +23,7 @@
 import android.telephony.PreciseDataConnectionState;
 import android.telephony.SubscriptionManager;
 import android.telephony.TelephonyManager;
+import android.util.Log;
 
 import com.android.settings.R;
 import com.android.settings.Settings;
@@ -32,6 +33,7 @@
 import java.util.Objects;
 
 public class CellularDataConditionController implements ConditionalCardController {
+    private static final String TAG = "CellularDataConditionController";
 
     static final int ID = Objects.hash("CellularDataConditionController");
 
@@ -85,6 +87,7 @@
 
     @Override
     public void onActionClick() {
+        Log.d(TAG, "setDataEnabledForReason true");
         mTelephonyManager.setDataEnabled(true);
     }
 
diff --git a/src/com/android/settings/network/MobileNetworkRepository.java b/src/com/android/settings/network/MobileNetworkRepository.java
index 672e2ed..6820f10 100644
--- a/src/com/android/settings/network/MobileNetworkRepository.java
+++ b/src/com/android/settings/network/MobileNetworkRepository.java
@@ -190,6 +190,7 @@
                 return;
             }
             sExecutor.execute(() -> {
+                Log.d(TAG, "DataRoamingObserver changed");
                 insertMobileNetworkInfo(mContext, mRegSubId, tm);
             });
             boolean isDataRoamingEnabled = tm.isDataRoamingEnabled();
@@ -213,9 +214,7 @@
             mSubscriptionManager.addOnSubscriptionsChangedListener(mContext.getMainExecutor(),
                     this);
             mAirplaneModeObserver.register(mContext);
-            if (DEBUG) {
-                Log.d(TAG, "addRegister done");
-            }
+            Log.d(TAG, "addRegister done");
         }
         sCallbacks.add(mobileNetworkCallback);
         observeAllSubInfo(lifecycleOwner);
@@ -232,10 +231,12 @@
     }
 
     public void addRegisterBySubId(int subId) {
+        Log.d(TAG, "MobileDataContentObserver addRegisterBySubId: " + subId);
         MobileDataContentObserver dataContentObserver = new MobileDataContentObserver(
                 new Handler(Looper.getMainLooper()));
         dataContentObserver.setOnMobileDataChangedListener(() -> {
             sExecutor.execute(() -> {
+                Log.d(TAG, "MobileDataContentObserver changed");
                 insertMobileNetworkInfo(mContext, subId,
                         getTelephonyManagerBySubId(mContext, subId));
             });
@@ -319,9 +320,7 @@
             });
             mTelephonyCallbackMap.clear();
             mTelephonyManagerMap.clear();
-            if (DEBUG) {
-                Log.d(TAG, "removeRegister done");
-            }
+            Log.d(TAG, "removeRegister done");
         }
     }
 
@@ -356,9 +355,7 @@
     }
 
     private void observeAllMobileNetworkInfo(LifecycleOwner lifecycleOwner) {
-        if (DEBUG) {
-            Log.d(TAG, "Observe mobile network info.");
-        }
+        Log.d(TAG, "Observe mobile network info.");
         mMobileNetworkDatabase.queryAllMobileNetworkInfo().observe(
                 lifecycleOwner, this::onAllMobileNetworkInfoChanged);
     }
@@ -434,10 +431,10 @@
             }
             mAvailableSubInfoEntityList = new ArrayList<>(availableSubInfoEntityList);
         }
-        if (DEBUG) {
-            Log.d(TAG, "onAvailableSubInfoChanged, availableSubInfoEntityList = "
+
+        Log.d(TAG, "onAvailableSubInfoChanged, availableSubInfoEntityList = "
                     + availableSubInfoEntityList);
-        }
+
         for (MobileNetworkCallback callback : sCallbacks) {
             callback.onAvailableSubInfoChanged(availableSubInfoEntityList);
         }
@@ -453,10 +450,10 @@
                 .filter(SubscriptionInfoEntity::isActiveSubscription)
                 .filter(SubscriptionInfoEntity::isSubscriptionVisible)
                 .collect(Collectors.toList());
-        if (DEBUG) {
-            Log.d(TAG, "onActiveSubInfoChanged, activeSubInfoEntityList = "
-                    + activeSubInfoEntityList);
-        }
+
+        Log.d(TAG, "onActiveSubInfoChanged, activeSubInfoEntityList = "
+                + activeSubInfoEntityList);
+
         List<SubscriptionInfoEntity> tempActiveSubInfoEntityList = new ArrayList<>(
                 activeSubInfoEntityList);
         synchronized (this) {
@@ -521,6 +518,8 @@
                 if (DEBUG) {
                     Log.d(TAG, "Convert subId " + subId + " to SubscriptionInfoEntity: "
                             + subInfoEntity);
+                } else {
+                    Log.d(TAG, "insertSubsInfo into SubscriptionInfoEntity");
                 }
                 mMobileNetworkDatabase.insertSubsInfo(subInfoEntity);
                 mMetricsFeatureProvider.action(mContext,
@@ -534,9 +533,7 @@
     }
 
     private void deleteAllInfoBySubId(String subId) {
-        if (DEBUG) {
-            Log.d(TAG, "deleteAllInfoBySubId, subId = " + subId);
-        }
+        Log.d(TAG, "deleteAllInfoBySubId, subId = " + subId);
         mMobileNetworkDatabase.deleteSubInfoBySubId(subId);
         mMobileNetworkDatabase.deleteUiccInfoBySubId(subId);
         mMobileNetworkDatabase.deleteMobileNetworkInfoBySubId(subId);
@@ -617,10 +614,10 @@
         MobileNetworkInfoEntity mobileNetworkInfoEntity = convertToMobileNetworkInfoEntity(context,
                 subId, telephonyManager);
 
-        if (DEBUG) {
-            Log.d(TAG, "insertMobileNetworkInfo, mobileNetworkInfoEntity = "
-                    + mobileNetworkInfoEntity);
-        }
+
+        Log.d(TAG, "insertMobileNetworkInfo, mobileNetworkInfoEntity = "
+                + mobileNetworkInfoEntity);
+
 
         if (mobileNetworkInfoEntity == null) {
             return;
@@ -642,7 +639,7 @@
         if (telephonyManager != null) {
             isDataEnabled = telephonyManager.isDataEnabled();
             isDataRoamingEnabled = telephonyManager.isDataRoamingEnabled();
-        } else if (DEBUG) {
+        } else {
             Log.d(TAG, "TelephonyManager is null, subId = " + subId);
         }
 
@@ -671,17 +668,13 @@
 
     private boolean isMultipleEnabledProfilesSupported(TelephonyManager telephonyManager) {
         if (telephonyManager == null) {
-            if (DEBUG) {
-                Log.d(TAG, "TelephonyManager is null");
-            }
+            Log.d(TAG, "TelephonyManager is null");
             return false;
         }
 
         List<UiccCardInfo> cardInfos = telephonyManager.getUiccCardsInfo();
         if (cardInfos == null) {
-            if (DEBUG) {
-                Log.d(TAG, "UICC card info list is empty.");
-            }
+            Log.d(TAG, "UICC card info list is empty.");
             return false;
         }
         return cardInfos.stream().anyMatch(
diff --git a/src/com/android/settings/network/ProviderModelSlice.java b/src/com/android/settings/network/ProviderModelSlice.java
index 86ba563..bbe1374 100644
--- a/src/com/android/settings/network/ProviderModelSlice.java
+++ b/src/com/android/settings/network/ProviderModelSlice.java
@@ -222,6 +222,7 @@
                 // If we need to display a reminder dialog box, do nothing here.
                 return;
             } else {
+                log("setMobileDataEnabled: " + newState);
                 MobileNetworkUtils.setMobileDataEnabled(mContext, defaultSubId, newState,
                         false /* disableOtherSubscriptions */);
             }
@@ -251,6 +252,7 @@
                 .setPositiveButton(
                         com.android.internal.R.string.alert_windows_notification_turn_off_action,
                         (dialog, which) -> {
+                            log("setMobileDataEnabled: false");
                             MobileNetworkUtils.setMobileDataEnabled(mContext, defaultSubId,
                                     false /* enabled */,
                                     false /* disableOtherSubscriptions */);
diff --git a/src/com/android/settings/network/telephony/MobileDataDialogFragment.java b/src/com/android/settings/network/telephony/MobileDataDialogFragment.java
index aa772ad..0e01e45 100644
--- a/src/com/android/settings/network/telephony/MobileDataDialogFragment.java
+++ b/src/com/android/settings/network/telephony/MobileDataDialogFragment.java
@@ -23,6 +23,7 @@
 import android.os.Bundle;
 import android.telephony.SubscriptionInfo;
 import android.telephony.SubscriptionManager;
+import android.util.Log;
 
 import androidx.appcompat.app.AlertDialog;
 
@@ -40,6 +41,7 @@
  */
 public class MobileDataDialogFragment extends InstrumentedDialogFragment implements
         DialogInterface.OnClickListener {
+    private static final String TAG = "MobileDataDialogFragment";
 
     public static final int TYPE_DISABLE_DIALOG = 0;
     public static final int TYPE_MULTI_SIM_DIALOG = 1;
@@ -129,6 +131,7 @@
     public void onClick(DialogInterface dialog, int which) {
         switch (mType) {
             case TYPE_DISABLE_DIALOG:
+                Log.d(TAG, "setMobileDataEnabled: false");
                 MobileNetworkUtils.setMobileDataEnabled(getContext(), mSubId, false /* enabled */,
                         false /* disableOtherSubscriptions */);
                 if (mWifiPickerTrackerHelper != null
@@ -138,6 +141,7 @@
                 break;
             case TYPE_MULTI_SIM_DIALOG:
                 mSubscriptionManager.setDefaultDataSubId(mSubId);
+                Log.d(TAG, "setMobileDataEnabled: true");
                 MobileNetworkUtils.setMobileDataEnabled(getContext(), mSubId, true /* enabled */,
                         true /* disableOtherSubscriptions */);
                 if (mWifiPickerTrackerHelper != null
diff --git a/src/com/android/settings/network/telephony/MobileDataPreferenceController.java b/src/com/android/settings/network/telephony/MobileDataPreferenceController.java
index bec7ee7..2c3ab18 100644
--- a/src/com/android/settings/network/telephony/MobileDataPreferenceController.java
+++ b/src/com/android/settings/network/telephony/MobileDataPreferenceController.java
@@ -23,6 +23,7 @@
 import android.telephony.SubscriptionManager;
 import android.telephony.TelephonyManager;
 import android.text.TextUtils;
+import android.util.Log;
 
 import androidx.annotation.VisibleForTesting;
 import androidx.fragment.app.FragmentManager;
@@ -127,6 +128,7 @@
 
         if (!mNeedDialog) {
             // Update data directly if we don't need dialog
+            Log.d(DIALOG_TAG, "setMobileDataEnabled: " + isChecked);
             MobileNetworkUtils.setMobileDataEnabled(mContext, mSubId, isChecked, false);
             if (mWifiPickerTrackerHelper != null
                     && !mWifiPickerTrackerHelper.isCarrierNetworkProvisionEnabled(mSubId)) {
diff --git a/src/com/android/settings/network/telephony/MobileDataSlice.java b/src/com/android/settings/network/telephony/MobileDataSlice.java
index d25ae65..fd65e85 100644
--- a/src/com/android/settings/network/telephony/MobileDataSlice.java
+++ b/src/com/android/settings/network/telephony/MobileDataSlice.java
@@ -33,6 +33,7 @@
 import android.telephony.SubscriptionInfo;
 import android.telephony.SubscriptionManager;
 import android.telephony.TelephonyManager;
+import android.util.Log;
 
 import androidx.core.graphics.drawable.IconCompat;
 import androidx.slice.Slice;
@@ -64,6 +65,7 @@
  *
  */
 public class MobileDataSlice implements CustomSliceable {
+    private static final String TAG = "MobileDataSlice";
 
     private final Context mContext;
     private final SubscriptionManager mSubscriptionManager;
@@ -128,7 +130,7 @@
         if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
             return; // No subscription - do nothing.
         }
-
+        Log.d(TAG, "setMobileDataEnabled: " + newState);
         MobileNetworkUtils.setMobileDataEnabled(mContext, defaultSubId, newState,
                 false /* disableOtherSubscriptions */);
         // Do not notifyChange on Uri. The service takes longer to update the current value than it
diff --git a/src/com/android/settings/network/telephony/MobileNetworkUtils.java b/src/com/android/settings/network/telephony/MobileNetworkUtils.java
index 0407b6a..4430642 100644
--- a/src/com/android/settings/network/telephony/MobileNetworkUtils.java
+++ b/src/com/android/settings/network/telephony/MobileNetworkUtils.java
@@ -359,6 +359,7 @@
                 .createForSubscriptionId(subId);
         final SubscriptionManager subscriptionManager = context.getSystemService(
                 SubscriptionManager.class).createForAllUserProfiles();
+        Log.d(TAG, "setDataEnabledForReason: " + enabled);
         telephonyManager.setDataEnabledForReason(TelephonyManager.DATA_ENABLED_REASON_USER,
                 enabled);
 
diff --git a/src/com/android/settings/sim/SimDialogActivity.java b/src/com/android/settings/sim/SimDialogActivity.java
index 8840994..2e19641 100644
--- a/src/com/android/settings/sim/SimDialogActivity.java
+++ b/src/com/android/settings/sim/SimDialogActivity.java
@@ -359,6 +359,7 @@
                 TelephonyManager.class).createForSubscriptionId(subId);
         subscriptionManager.setDefaultDataSubId(subId);
         if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
+            Log.d(TAG, "setDataEnabledForReason true");
             telephonyManager.setDataEnabledForReason(TelephonyManager.DATA_ENABLED_REASON_USER,
                     true);
             Toast.makeText(this, R.string.data_switch_started, Toast.LENGTH_LONG).show();
diff --git a/src/com/android/settings/spa/network/NetworkCellularGroupProvider.kt b/src/com/android/settings/spa/network/NetworkCellularGroupProvider.kt
index bc5a4b7..80be970 100644
--- a/src/com/android/settings/spa/network/NetworkCellularGroupProvider.kt
+++ b/src/com/android/settings/spa/network/NetworkCellularGroupProvider.kt
@@ -337,6 +337,7 @@
 ): Unit =
     withContext(Dispatchers.Default) {
         subscriptionManager?.setDefaultDataSubId(subId)
+        Log.d(NetworkCellularGroupProvider.name, "setMobileDataEnabled: true")
         MobileNetworkUtils.setMobileDataEnabled(
             context,
             subId,