SetupWizard: Use TelephonyManager for checking/enabling mobile data
Change-Id: I6135d9a92efea56a50f5200827e0734f974c4849
This commit is contained in:
parent
17c2db964e
commit
b0e3ace8ca
|
@ -83,29 +83,28 @@ public class SetupWizardUtils {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isMobileDataEnabled(Context context) {
|
public static boolean isMobileDataEnabled(Context context) {
|
||||||
TelephonyManager tm =
|
try {
|
||||||
(TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
|
TelephonyManager tm =
|
||||||
if (tm.isMultiSimEnabled()) {
|
(TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
|
||||||
int subscription = SubscriptionManager.getDefaultDataPhoneId();
|
return tm.getDataEnabled();
|
||||||
return android.provider.Settings.Global.getInt(context.getContentResolver(),
|
} catch (Exception e) {
|
||||||
android.provider.Settings.Global.MOBILE_DATA + subscription, 0) != 0;
|
return false;
|
||||||
} else {
|
|
||||||
return android.provider.Settings.Global.getInt(context.getContentResolver(),
|
|
||||||
android.provider.Settings.Global.MOBILE_DATA, 0) != 0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setMobileDataEnabled(Context context, boolean enabled) {
|
public static void setMobileDataEnabled(Context context, boolean enabled) {
|
||||||
TelephonyManager tm =
|
TelephonyManager tm =
|
||||||
(TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
|
(TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
|
||||||
tm.setDataEnabled(enabled);
|
|
||||||
if (tm.isMultiSimEnabled()) {
|
if (tm.isMultiSimEnabled()) {
|
||||||
int subscription = SubscriptionManager.getDefaultDataPhoneId();
|
int phoneId = SubscriptionManager.getDefaultDataPhoneId();
|
||||||
android.provider.Settings.Global.putInt(context.getContentResolver(),
|
android.provider.Settings.Global.putInt(context.getContentResolver(),
|
||||||
android.provider.Settings.Global.MOBILE_DATA + subscription, enabled ? 1 : 0);
|
android.provider.Settings.Global.MOBILE_DATA + phoneId, enabled ? 1 : 0);
|
||||||
|
long subId = SubscriptionManager.getDefaultDataSubId();
|
||||||
|
tm.setDataEnabledUsingSubId(subId, enabled);
|
||||||
} else {
|
} else {
|
||||||
android.provider.Settings.Global.putInt(context.getContentResolver(),
|
android.provider.Settings.Global.putInt(context.getContentResolver(),
|
||||||
android.provider.Settings.Global.MOBILE_DATA, enabled ? 1 : 0);
|
android.provider.Settings.Global.MOBILE_DATA, enabled ? 1 : 0);
|
||||||
|
tm.setDataEnabled(enabled);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue