diff options
author | Michael W <baddaemon87@gmail.com> | 2020-04-21 13:29:35 +0200 |
---|---|---|
committer | Michael W <baddaemon87@gmail.com> | 2020-04-22 08:09:46 +0200 |
commit | 373a11adfb194d877f79fc4e8a905563c9ca08a4 (patch) | |
tree | 8c38610cda0872fbc825fca5871aa8539ff7ae40 | |
parent | fdf30702a73b6d778b6f5904d5c75593142b19ff (diff) | |
download | lineage-sdk-373a11adfb194d877f79fc4e8a905563c9ca08a4.tar.gz lineage-sdk-373a11adfb194d877f79fc4e8a905563c9ca08a4.tar.bz2 lineage-sdk-373a11adfb194d877f79fc4e8a905563c9ca08a4.zip |
Profiles: Work with a list of subscriptions
* This is a better approach to work with all subscriptions independently
Change-Id: Ibb8f8a2483bfc1e36dc27e5d6abaf9fc653fbeeb
-rw-r--r-- | sdk/src/java/lineageos/profiles/ConnectionSettings.java | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/sdk/src/java/lineageos/profiles/ConnectionSettings.java b/sdk/src/java/lineageos/profiles/ConnectionSettings.java index 4647ccd9..0a2fcb75 100644 --- a/sdk/src/java/lineageos/profiles/ConnectionSettings.java +++ b/sdk/src/java/lineageos/profiles/ConnectionSettings.java @@ -29,6 +29,7 @@ import android.os.Parcel; import android.os.Parcelable; import android.os.UserHandle; import android.provider.Settings; +import android.telephony.SubscriptionInfo; import android.telephony.SubscriptionManager; import android.telephony.TelephonyManager; @@ -42,6 +43,7 @@ import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; import java.io.IOException; +import java.util.List; /** * The {@link ConnectionSettings} class allows for creating Network/Hardware overrides @@ -269,6 +271,7 @@ public final class ConnectionSettings implements Parcelable { (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); + SubscriptionManager sm = context.getSystemService(SubscriptionManager.class); NfcAdapter nfcAdapter = null; try { nfcAdapter = NfcAdapter.getNfcAdapter(context); @@ -281,14 +284,17 @@ public final class ConnectionSettings implements Parcelable { switch (getConnectionId()) { case PROFILE_CONNECTION_MOBILEDATA: - currentState = tm.getDataEnabled(); - if (forcedState != currentState) { - int phoneCount = tm.getPhoneCount(); - for (int i = 0; i < phoneCount; i++) { - Settings.Global.putInt(context.getContentResolver(), - Settings.Global.MOBILE_DATA + i, (forcedState) ? 1 : 0); - int[] subId = SubscriptionManager.getSubId(i); - tm.setDataEnabled(subId[0], forcedState); + List<SubscriptionInfo> list = sm.getActiveSubscriptionInfoList(); + if (list != null) { + for (int i = 0; i < list.size(); i++) { + int subId = list.get(i).getSubscriptionId(); + int slotIndex = list.get(i).getSimSlotIndex(); + currentState = tm.getDataEnabled(subId); + if (forcedState != currentState) { + Settings.Global.putInt(context.getContentResolver(), + Settings.Global.MOBILE_DATA + i, (forcedState) ? 1 : 0); + tm.setDataEnabled(subId, forcedState); + } } } break; |