Skip to content

Commit

Permalink
fix(android): fix multisim issues on old phones
Browse files Browse the repository at this point in the history
  • Loading branch information
vernu committed Apr 1, 2024
1 parent 415e845 commit 923da3b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,21 +96,23 @@ protected void onCreate(Bundle savedInstanceState) {

defaultSimSlotRadioGroup = findViewById(R.id.defaultSimSlotRadioGroup);

getAvailableSimSlots().forEach(subscriptionInfo -> {
try{
RadioButton radioButton = new RadioButton(mContext);
radioButton.setText(subscriptionInfo.getDisplayName().toString());
radioButton.setId(subscriptionInfo.getSubscriptionId());
radioButton.setOnClickListener(view -> {
SharedPreferenceHelper.setSharedPreferenceInt(mContext, "PREFERED_SIM", subscriptionInfo.getSubscriptionId());

try {
getAvailableSimSlots().forEach(subscriptionInfo -> {
RadioButton radioButton = new RadioButton(mContext);
radioButton.setText(subscriptionInfo.getDisplayName().toString());
radioButton.setId(subscriptionInfo.getSubscriptionId());
radioButton.setOnClickListener(view -> {
SharedPreferenceHelper.setSharedPreferenceInt(mContext, "PREFERED_SIM", subscriptionInfo.getSubscriptionId());
});
radioButton.setChecked(subscriptionInfo.getSubscriptionId() == SharedPreferenceHelper.getSharedPreferenceInt(mContext, "PREFERED_SIM", 0));
defaultSimSlotRadioGroup.addView(radioButton);
});
radioButton.setChecked(subscriptionInfo.getSubscriptionId() == SharedPreferenceHelper.getSharedPreferenceInt(mContext, "PREFERED_SIM", 0));
defaultSimSlotRadioGroup.addView(radioButton);
} catch (Exception e) {
Snackbar.make(defaultSimSlotRadioGroup.getRootView(), "Error: " + e.getMessage(), Snackbar.LENGTH_LONG).show();
Log.e("SIM_SLOT_ERROR", e.getMessage());
}
});


deviceIdTxt.setText(deviceId);
deviceBrandAndModelTxt.setText(Build.BRAND + " " + Build.MODEL);
Expand Down Expand Up @@ -302,11 +304,11 @@ private boolean isReadPhoneStatePermissionGranted(Context context) {

private List<SubscriptionInfo> getAvailableSimSlots() {

SubscriptionManager subscriptionManager = SubscriptionManager.from(mContext);
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED) {
return new ArrayList<>();
}

SubscriptionManager subscriptionManager = SubscriptionManager.from(mContext);
return subscriptionManager.getActiveSubscriptionInfoList();

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,16 @@ public void onMessageReceived(RemoteMessage remoteMessage) {

// Check if message contains a data payload.
if (remoteMessage.getData().size() > 0) {

int preferedSim = SharedPreferenceHelper.getSharedPreferenceInt(this, "PREFERED_SIM", -1);
for (String receiver : smsPayload.getReceivers()) {
int preferedSim = SharedPreferenceHelper.getSharedPreferenceInt(this, "PREFERED_SIM", 0);
if(preferedSim == -1) {
SMSHelper.sendSMS(receiver, smsPayload.getSmsBody());
continue;
}
try {
SMSHelper.sendSMSFromSpecificSim(receiver, smsPayload.getSmsBody(), preferedSim);
} catch(Exception e) {
Log.d("SMS_SEND_ERROR", e.getMessage());
SMSHelper.sendSMS(receiver, smsPayload.getSmsBody());
}
}
}
Expand Down

0 comments on commit 923da3b

Please sign in to comment.