Profiles: Work with a list of subscriptions

* This is a better approach to work with all subscriptions independently

Change-Id: Ibb8f8a2483bfc1e36dc27e5d6abaf9fc653fbeeb
This commit is contained in:
Michael W
2020-04-21 13:29:35 +02:00
parent fdf30702a7
commit 373a11adfb

View File

@@ -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;