Merge "Add log for setDataEnabledForReason" into main

This commit is contained in:
SongFerng Wang
2024-03-30 15:37:14 +00:00
committed by Android (Google) Code Review
10 changed files with 41 additions and 33 deletions

View File

@@ -152,8 +152,7 @@ public class CellDataPreference extends CustomDialogPreferenceCompat
} }
private void setMobileDataEnabled(boolean enabled) { private void setMobileDataEnabled(boolean enabled) {
if (DataUsageSummary.LOGD) Log.d(TAG, "setMobileDataEnabled(" + enabled + "," Log.d(TAG, "setDataEnabledForReason (" + enabled + "," + mSubId + ")");
+ mSubId + ")");
getContext().getSystemService(TelephonyManager.class).setDataEnabled(mSubId, enabled); getContext().getSystemService(TelephonyManager.class).setDataEnabled(mSubId, enabled);
setChecked(enabled); setChecked(enabled);
} }

View File

@@ -23,6 +23,7 @@ import android.telephony.PhoneStateListener;
import android.telephony.PreciseDataConnectionState; import android.telephony.PreciseDataConnectionState;
import android.telephony.SubscriptionManager; import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager; import android.telephony.TelephonyManager;
import android.util.Log;
import com.android.settings.R; import com.android.settings.R;
import com.android.settings.Settings; import com.android.settings.Settings;
@@ -32,6 +33,7 @@ import com.android.settings.network.GlobalSettingsChangeListener;
import java.util.Objects; import java.util.Objects;
public class CellularDataConditionController implements ConditionalCardController { public class CellularDataConditionController implements ConditionalCardController {
private static final String TAG = "CellularDataConditionController";
static final int ID = Objects.hash("CellularDataConditionController"); static final int ID = Objects.hash("CellularDataConditionController");
@@ -85,6 +87,7 @@ public class CellularDataConditionController implements ConditionalCardControlle
@Override @Override
public void onActionClick() { public void onActionClick() {
Log.d(TAG, "setDataEnabledForReason true");
mTelephonyManager.setDataEnabled(true); mTelephonyManager.setDataEnabled(true);
} }

View File

@@ -190,6 +190,7 @@ public class MobileNetworkRepository extends SubscriptionManager.OnSubscriptions
return; return;
} }
sExecutor.execute(() -> { sExecutor.execute(() -> {
Log.d(TAG, "DataRoamingObserver changed");
insertMobileNetworkInfo(mContext, mRegSubId, tm); insertMobileNetworkInfo(mContext, mRegSubId, tm);
}); });
boolean isDataRoamingEnabled = tm.isDataRoamingEnabled(); boolean isDataRoamingEnabled = tm.isDataRoamingEnabled();
@@ -213,10 +214,8 @@ public class MobileNetworkRepository extends SubscriptionManager.OnSubscriptions
mSubscriptionManager.addOnSubscriptionsChangedListener(mContext.getMainExecutor(), mSubscriptionManager.addOnSubscriptionsChangedListener(mContext.getMainExecutor(),
this); this);
mAirplaneModeObserver.register(mContext); mAirplaneModeObserver.register(mContext);
if (DEBUG) {
Log.d(TAG, "addRegister done"); Log.d(TAG, "addRegister done");
} }
}
sCallbacks.add(mobileNetworkCallback); sCallbacks.add(mobileNetworkCallback);
observeAllSubInfo(lifecycleOwner); observeAllSubInfo(lifecycleOwner);
observeAllUiccInfo(lifecycleOwner); observeAllUiccInfo(lifecycleOwner);
@@ -232,10 +231,12 @@ public class MobileNetworkRepository extends SubscriptionManager.OnSubscriptions
} }
public void addRegisterBySubId(int subId) { public void addRegisterBySubId(int subId) {
Log.d(TAG, "MobileDataContentObserver addRegisterBySubId: " + subId);
MobileDataContentObserver dataContentObserver = new MobileDataContentObserver( MobileDataContentObserver dataContentObserver = new MobileDataContentObserver(
new Handler(Looper.getMainLooper())); new Handler(Looper.getMainLooper()));
dataContentObserver.setOnMobileDataChangedListener(() -> { dataContentObserver.setOnMobileDataChangedListener(() -> {
sExecutor.execute(() -> { sExecutor.execute(() -> {
Log.d(TAG, "MobileDataContentObserver changed");
insertMobileNetworkInfo(mContext, subId, insertMobileNetworkInfo(mContext, subId,
getTelephonyManagerBySubId(mContext, subId)); getTelephonyManagerBySubId(mContext, subId));
}); });
@@ -319,11 +320,9 @@ public class MobileNetworkRepository extends SubscriptionManager.OnSubscriptions
}); });
mTelephonyCallbackMap.clear(); mTelephonyCallbackMap.clear();
mTelephonyManagerMap.clear(); mTelephonyManagerMap.clear();
if (DEBUG) {
Log.d(TAG, "removeRegister done"); Log.d(TAG, "removeRegister done");
} }
} }
}
public void updateEntity() { public void updateEntity() {
// Check the latest state after back to the UI. // Check the latest state after back to the UI.
@@ -356,9 +355,7 @@ public class MobileNetworkRepository extends SubscriptionManager.OnSubscriptions
} }
private void observeAllMobileNetworkInfo(LifecycleOwner lifecycleOwner) { private void observeAllMobileNetworkInfo(LifecycleOwner lifecycleOwner) {
if (DEBUG) {
Log.d(TAG, "Observe mobile network info."); Log.d(TAG, "Observe mobile network info.");
}
mMobileNetworkDatabase.queryAllMobileNetworkInfo().observe( mMobileNetworkDatabase.queryAllMobileNetworkInfo().observe(
lifecycleOwner, this::onAllMobileNetworkInfoChanged); lifecycleOwner, this::onAllMobileNetworkInfoChanged);
} }
@@ -434,10 +431,10 @@ public class MobileNetworkRepository extends SubscriptionManager.OnSubscriptions
} }
mAvailableSubInfoEntityList = new ArrayList<>(availableSubInfoEntityList); mAvailableSubInfoEntityList = new ArrayList<>(availableSubInfoEntityList);
} }
if (DEBUG) {
Log.d(TAG, "onAvailableSubInfoChanged, availableSubInfoEntityList = " Log.d(TAG, "onAvailableSubInfoChanged, availableSubInfoEntityList = "
+ availableSubInfoEntityList); + availableSubInfoEntityList);
}
for (MobileNetworkCallback callback : sCallbacks) { for (MobileNetworkCallback callback : sCallbacks) {
callback.onAvailableSubInfoChanged(availableSubInfoEntityList); callback.onAvailableSubInfoChanged(availableSubInfoEntityList);
} }
@@ -453,10 +450,10 @@ public class MobileNetworkRepository extends SubscriptionManager.OnSubscriptions
.filter(SubscriptionInfoEntity::isActiveSubscription) .filter(SubscriptionInfoEntity::isActiveSubscription)
.filter(SubscriptionInfoEntity::isSubscriptionVisible) .filter(SubscriptionInfoEntity::isSubscriptionVisible)
.collect(Collectors.toList()); .collect(Collectors.toList());
if (DEBUG) {
Log.d(TAG, "onActiveSubInfoChanged, activeSubInfoEntityList = " Log.d(TAG, "onActiveSubInfoChanged, activeSubInfoEntityList = "
+ activeSubInfoEntityList); + activeSubInfoEntityList);
}
List<SubscriptionInfoEntity> tempActiveSubInfoEntityList = new ArrayList<>( List<SubscriptionInfoEntity> tempActiveSubInfoEntityList = new ArrayList<>(
activeSubInfoEntityList); activeSubInfoEntityList);
synchronized (this) { synchronized (this) {
@@ -521,6 +518,8 @@ public class MobileNetworkRepository extends SubscriptionManager.OnSubscriptions
if (DEBUG) { if (DEBUG) {
Log.d(TAG, "Convert subId " + subId + " to SubscriptionInfoEntity: " Log.d(TAG, "Convert subId " + subId + " to SubscriptionInfoEntity: "
+ subInfoEntity); + subInfoEntity);
} else {
Log.d(TAG, "insertSubsInfo into SubscriptionInfoEntity");
} }
mMobileNetworkDatabase.insertSubsInfo(subInfoEntity); mMobileNetworkDatabase.insertSubsInfo(subInfoEntity);
mMetricsFeatureProvider.action(mContext, mMetricsFeatureProvider.action(mContext,
@@ -534,9 +533,7 @@ public class MobileNetworkRepository extends SubscriptionManager.OnSubscriptions
} }
private void deleteAllInfoBySubId(String subId) { private void deleteAllInfoBySubId(String subId) {
if (DEBUG) {
Log.d(TAG, "deleteAllInfoBySubId, subId = " + subId); Log.d(TAG, "deleteAllInfoBySubId, subId = " + subId);
}
mMobileNetworkDatabase.deleteSubInfoBySubId(subId); mMobileNetworkDatabase.deleteSubInfoBySubId(subId);
mMobileNetworkDatabase.deleteUiccInfoBySubId(subId); mMobileNetworkDatabase.deleteUiccInfoBySubId(subId);
mMobileNetworkDatabase.deleteMobileNetworkInfoBySubId(subId); mMobileNetworkDatabase.deleteMobileNetworkInfoBySubId(subId);
@@ -617,10 +614,10 @@ public class MobileNetworkRepository extends SubscriptionManager.OnSubscriptions
MobileNetworkInfoEntity mobileNetworkInfoEntity = convertToMobileNetworkInfoEntity(context, MobileNetworkInfoEntity mobileNetworkInfoEntity = convertToMobileNetworkInfoEntity(context,
subId, telephonyManager); subId, telephonyManager);
if (DEBUG) {
Log.d(TAG, "insertMobileNetworkInfo, mobileNetworkInfoEntity = " Log.d(TAG, "insertMobileNetworkInfo, mobileNetworkInfoEntity = "
+ mobileNetworkInfoEntity); + mobileNetworkInfoEntity);
}
if (mobileNetworkInfoEntity == null) { if (mobileNetworkInfoEntity == null) {
return; return;
@@ -642,7 +639,7 @@ public class MobileNetworkRepository extends SubscriptionManager.OnSubscriptions
if (telephonyManager != null) { if (telephonyManager != null) {
isDataEnabled = telephonyManager.isDataEnabled(); isDataEnabled = telephonyManager.isDataEnabled();
isDataRoamingEnabled = telephonyManager.isDataRoamingEnabled(); isDataRoamingEnabled = telephonyManager.isDataRoamingEnabled();
} else if (DEBUG) { } else {
Log.d(TAG, "TelephonyManager is null, subId = " + subId); Log.d(TAG, "TelephonyManager is null, subId = " + subId);
} }
@@ -671,17 +668,13 @@ public class MobileNetworkRepository extends SubscriptionManager.OnSubscriptions
private boolean isMultipleEnabledProfilesSupported(TelephonyManager telephonyManager) { private boolean isMultipleEnabledProfilesSupported(TelephonyManager telephonyManager) {
if (telephonyManager == null) { if (telephonyManager == null) {
if (DEBUG) {
Log.d(TAG, "TelephonyManager is null"); Log.d(TAG, "TelephonyManager is null");
}
return false; return false;
} }
List<UiccCardInfo> cardInfos = telephonyManager.getUiccCardsInfo(); List<UiccCardInfo> cardInfos = telephonyManager.getUiccCardsInfo();
if (cardInfos == null) { 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 false;
} }
return cardInfos.stream().anyMatch( return cardInfos.stream().anyMatch(

View File

@@ -222,6 +222,7 @@ public class ProviderModelSlice extends WifiSlice {
// If we need to display a reminder dialog box, do nothing here. // If we need to display a reminder dialog box, do nothing here.
return; return;
} else { } else {
log("setMobileDataEnabled: " + newState);
MobileNetworkUtils.setMobileDataEnabled(mContext, defaultSubId, newState, MobileNetworkUtils.setMobileDataEnabled(mContext, defaultSubId, newState,
false /* disableOtherSubscriptions */); false /* disableOtherSubscriptions */);
} }
@@ -251,6 +252,7 @@ public class ProviderModelSlice extends WifiSlice {
.setPositiveButton( .setPositiveButton(
com.android.internal.R.string.alert_windows_notification_turn_off_action, com.android.internal.R.string.alert_windows_notification_turn_off_action,
(dialog, which) -> { (dialog, which) -> {
log("setMobileDataEnabled: false");
MobileNetworkUtils.setMobileDataEnabled(mContext, defaultSubId, MobileNetworkUtils.setMobileDataEnabled(mContext, defaultSubId,
false /* enabled */, false /* enabled */,
false /* disableOtherSubscriptions */); false /* disableOtherSubscriptions */);

View File

@@ -23,6 +23,7 @@ import android.content.DialogInterface;
import android.os.Bundle; import android.os.Bundle;
import android.telephony.SubscriptionInfo; import android.telephony.SubscriptionInfo;
import android.telephony.SubscriptionManager; import android.telephony.SubscriptionManager;
import android.util.Log;
import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AlertDialog;
@@ -40,6 +41,7 @@ import com.android.settings.wifi.WifiPickerTrackerHelper;
*/ */
public class MobileDataDialogFragment extends InstrumentedDialogFragment implements public class MobileDataDialogFragment extends InstrumentedDialogFragment implements
DialogInterface.OnClickListener { DialogInterface.OnClickListener {
private static final String TAG = "MobileDataDialogFragment";
public static final int TYPE_DISABLE_DIALOG = 0; public static final int TYPE_DISABLE_DIALOG = 0;
public static final int TYPE_MULTI_SIM_DIALOG = 1; public static final int TYPE_MULTI_SIM_DIALOG = 1;
@@ -129,6 +131,7 @@ public class MobileDataDialogFragment extends InstrumentedDialogFragment impleme
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
switch (mType) { switch (mType) {
case TYPE_DISABLE_DIALOG: case TYPE_DISABLE_DIALOG:
Log.d(TAG, "setMobileDataEnabled: false");
MobileNetworkUtils.setMobileDataEnabled(getContext(), mSubId, false /* enabled */, MobileNetworkUtils.setMobileDataEnabled(getContext(), mSubId, false /* enabled */,
false /* disableOtherSubscriptions */); false /* disableOtherSubscriptions */);
if (mWifiPickerTrackerHelper != null if (mWifiPickerTrackerHelper != null
@@ -138,6 +141,7 @@ public class MobileDataDialogFragment extends InstrumentedDialogFragment impleme
break; break;
case TYPE_MULTI_SIM_DIALOG: case TYPE_MULTI_SIM_DIALOG:
mSubscriptionManager.setDefaultDataSubId(mSubId); mSubscriptionManager.setDefaultDataSubId(mSubId);
Log.d(TAG, "setMobileDataEnabled: true");
MobileNetworkUtils.setMobileDataEnabled(getContext(), mSubId, true /* enabled */, MobileNetworkUtils.setMobileDataEnabled(getContext(), mSubId, true /* enabled */,
true /* disableOtherSubscriptions */); true /* disableOtherSubscriptions */);
if (mWifiPickerTrackerHelper != null if (mWifiPickerTrackerHelper != null

View File

@@ -23,6 +23,7 @@ import android.content.Context;
import android.telephony.SubscriptionManager; import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager; import android.telephony.TelephonyManager;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log;
import androidx.annotation.VisibleForTesting; import androidx.annotation.VisibleForTesting;
import androidx.fragment.app.FragmentManager; import androidx.fragment.app.FragmentManager;
@@ -127,6 +128,7 @@ public class MobileDataPreferenceController extends TelephonyTogglePreferenceCon
if (!mNeedDialog) { if (!mNeedDialog) {
// Update data directly if we don't need dialog // Update data directly if we don't need dialog
Log.d(DIALOG_TAG, "setMobileDataEnabled: " + isChecked);
MobileNetworkUtils.setMobileDataEnabled(mContext, mSubId, isChecked, false); MobileNetworkUtils.setMobileDataEnabled(mContext, mSubId, isChecked, false);
if (mWifiPickerTrackerHelper != null if (mWifiPickerTrackerHelper != null
&& !mWifiPickerTrackerHelper.isCarrierNetworkProvisionEnabled(mSubId)) { && !mWifiPickerTrackerHelper.isCarrierNetworkProvisionEnabled(mSubId)) {

View File

@@ -33,6 +33,7 @@ import android.provider.Settings;
import android.telephony.SubscriptionInfo; import android.telephony.SubscriptionInfo;
import android.telephony.SubscriptionManager; import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager; import android.telephony.TelephonyManager;
import android.util.Log;
import androidx.core.graphics.drawable.IconCompat; import androidx.core.graphics.drawable.IconCompat;
import androidx.slice.Slice; import androidx.slice.Slice;
@@ -64,6 +65,7 @@ import java.util.List;
* *
*/ */
public class MobileDataSlice implements CustomSliceable { public class MobileDataSlice implements CustomSliceable {
private static final String TAG = "MobileDataSlice";
private final Context mContext; private final Context mContext;
private final SubscriptionManager mSubscriptionManager; private final SubscriptionManager mSubscriptionManager;
@@ -128,7 +130,7 @@ public class MobileDataSlice implements CustomSliceable {
if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) { if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
return; // No subscription - do nothing. return; // No subscription - do nothing.
} }
Log.d(TAG, "setMobileDataEnabled: " + newState);
MobileNetworkUtils.setMobileDataEnabled(mContext, defaultSubId, newState, MobileNetworkUtils.setMobileDataEnabled(mContext, defaultSubId, newState,
false /* disableOtherSubscriptions */); false /* disableOtherSubscriptions */);
// Do not notifyChange on Uri. The service takes longer to update the current value than it // Do not notifyChange on Uri. The service takes longer to update the current value than it

View File

@@ -359,6 +359,7 @@ public class MobileNetworkUtils {
.createForSubscriptionId(subId); .createForSubscriptionId(subId);
final SubscriptionManager subscriptionManager = context.getSystemService( final SubscriptionManager subscriptionManager = context.getSystemService(
SubscriptionManager.class).createForAllUserProfiles(); SubscriptionManager.class).createForAllUserProfiles();
Log.d(TAG, "setDataEnabledForReason: " + enabled);
telephonyManager.setDataEnabledForReason(TelephonyManager.DATA_ENABLED_REASON_USER, telephonyManager.setDataEnabledForReason(TelephonyManager.DATA_ENABLED_REASON_USER,
enabled); enabled);

View File

@@ -359,6 +359,7 @@ public class SimDialogActivity extends FragmentActivity {
TelephonyManager.class).createForSubscriptionId(subId); TelephonyManager.class).createForSubscriptionId(subId);
subscriptionManager.setDefaultDataSubId(subId); subscriptionManager.setDefaultDataSubId(subId);
if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) { if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
Log.d(TAG, "setDataEnabledForReason true");
telephonyManager.setDataEnabledForReason(TelephonyManager.DATA_ENABLED_REASON_USER, telephonyManager.setDataEnabledForReason(TelephonyManager.DATA_ENABLED_REASON_USER,
true); true);
Toast.makeText(this, R.string.data_switch_started, Toast.LENGTH_LONG).show(); Toast.makeText(this, R.string.data_switch_started, Toast.LENGTH_LONG).show();

View File

@@ -337,6 +337,7 @@ suspend fun setDefaultData(
): Unit = ): Unit =
withContext(Dispatchers.Default) { withContext(Dispatchers.Default) {
subscriptionManager?.setDefaultDataSubId(subId) subscriptionManager?.setDefaultDataSubId(subId)
Log.d(NetworkCellularGroupProvider.name, "setMobileDataEnabled: true")
MobileNetworkUtils.setMobileDataEnabled( MobileNetworkUtils.setMobileDataEnabled(
context, context,
subId, subId,