LineageParts: Use correct API to determine mobile data state
Change-Id: I711d23d6faa20a476465e8a3dd8ccee35c417a08
diff --git a/src/org/lineageos/lineageparts/profiles/SetupActionsFragment.java b/src/org/lineageos/lineageparts/profiles/SetupActionsFragment.java
index 2c7d0cc..a760110 100644
--- a/src/org/lineageos/lineageparts/profiles/SetupActionsFragment.java
+++ b/src/org/lineageos/lineageparts/profiles/SetupActionsFragment.java
@@ -414,7 +414,7 @@
ConnectivityManager cm = context.getSystemService(ConnectivityManager.class);
profile.setConnectionSettings(
new ConnectionSettings(ConnectionSettings.PROFILE_CONNECTION_MOBILEDATA,
- cm.getMobileDataEnabled() ? 1 : 0, true));
+ DeviceUtils.isMobileDataEnabled(context) ? 1 : 0, true));
}
// wifi hotspot
diff --git a/src/org/lineageos/lineageparts/utils/DeviceUtils.java b/src/org/lineageos/lineageparts/utils/DeviceUtils.java
index 5234536..12ff417 100644
--- a/src/org/lineageos/lineageparts/utils/DeviceUtils.java
+++ b/src/org/lineageos/lineageparts/utils/DeviceUtils.java
@@ -35,6 +35,8 @@
import android.os.Build;
import android.os.SystemProperties;
import android.provider.Settings;
+import android.telephony.TelephonyManager;
+import android.telephony.SubscriptionManager;
import android.text.TextUtils;
import android.view.KeyCharacterMap;
import android.view.KeyEvent;
@@ -211,8 +213,8 @@
}
public static boolean deviceSupportsMobileData(Context ctx) {
- ConnectivityManager cm = ctx.getSystemService(ConnectivityManager.class);
- return cm.isNetworkSupported(ConnectivityManager.TYPE_MOBILE);
+ TelephonyManager telephonyManager = ctx.getSystemService(TelephonyManager.class);
+ return telephonyManager.isDataCapable();
}
public static boolean deviceSupportsBluetooth() {
@@ -244,6 +246,12 @@
return false;
}
+ public static boolean isMobileDataEnabled(Context context) {
+ TelephonyManager telephonyManager = context.getSystemService(TelephonyManager.class);
+ int subId = SubscriptionManager.getDefaultDataSubscriptionId();
+ return telephonyManager.createForSubscriptionId(subId).isDataEnabled();
+ }
+
public static boolean isSwipeUpEnabled(Context context) {
if (isEdgeToEdgeEnabled(context)) {
return false;