Skip to content

Commit

Permalink
Improve multi SIM support (#439)
Browse files Browse the repository at this point in the history
  • Loading branch information
frimtec authored May 12, 2023
1 parent 7782614 commit 3e6c7a9
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ static ApplicationPreferences instance() {

int getSuperviseSignalStrengthSubscription(Context context);

void setSuperviseSignalStrengthSubscription(Context context, int subscriptionId);

void setSuperviseSignalStrength(Context context, boolean supervise);

boolean getNotifyLowSignal(Context context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@ public int getSuperviseSignalStrengthSubscription(Context context) {
return Integer.parseInt(getSharedPreferences(context, PREF_KEY_SUPERVISE_SIGNAL_STRENGTH_SUBSCRIPTION, context.getString(R.string.pref_default_supervise_signal_strength_subscription)));
}

@Override
public void setSuperviseSignalStrengthSubscription(Context context, int subscriptionId) {
setSharedPreferences(context, setter -> setter.putString(PREF_KEY_SUPERVISE_SIGNAL_STRENGTH_SUBSCRIPTION, String.valueOf(subscriptionId)));
}

@Override
public void setSuperviseSignalStrength(Context context, boolean supervise) {
setSharedPreferences(context, setter -> setter.putBoolean(PREF_KEY_SUPERVISE_SIGNAL_STRENGTH, supervise));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public static class SettingsFragment extends PreferenceFragmentCompat {

private static final String TAG = "SettingsFragment";

private static final int MAX_SUPPORTED_SIMS = 2;
private static final int MAX_SUPPORTED_SIMS = 3;

@SuppressLint("DefaultLocale")
@Override
Expand Down Expand Up @@ -150,12 +150,13 @@ public void onCreatePreferencesFix(@Nullable Bundle savedInstanceState, String r
List<CharSequence> entriesValues = new ArrayList<>();

if (context != null) {
for (int i = 0; i < MAX_SUPPORTED_SIMS; i++) {
// Subscription are mostly counted starting from 1 therefor lets check for one more
for (int i = 0; i < MAX_SUPPORTED_SIMS + 1; i++) {
SignalStrengthService signalStrengthService = new SignalStrengthService(context, i);
String networkOperatorName = signalStrengthService.getNetworkOperatorName();
if (networkOperatorName != null) {
entriesValues.add(String.valueOf(i));
entries.add(String.format(Locale.getDefault(), "%s %d: %s", getString(R.string.subscription), i + 1, networkOperatorName));
entries.add(String.format(Locale.getDefault(), "%s %d: %s", getString(R.string.subscription), i, networkOperatorName));
} else {
Log.d(TAG, "No phone manager for subscriptionId " + i);
}
Expand All @@ -167,6 +168,14 @@ public void onCreatePreferencesFix(@Nullable Bundle savedInstanceState, String r
if (entries.size() < 2) {
superviseSignalStrengthSubscription.setVisible(false);
}
if (entries.size() == 1) {
int subscriptionId = Integer.parseInt(String.valueOf(entriesValues.get(0)));
ApplicationPreferences.instance().setSuperviseSignalStrengthSubscription(
context,
subscriptionId
);
Log.d(TAG, "Setting rest to one and only subscriptionId: " + subscriptionId);
}
}
}
if (Build.VERSION.SDK_INT >= 33) {
Expand Down

0 comments on commit 3e6c7a9

Please sign in to comment.