mirror of
https://github.com/KDE/kdeconnect-android
synced 2025-08-31 22:25:08 +00:00
[SMS Plugin] Prevent crashing when trying to send when we do not know the device's local number
This commit is contained in:
@@ -105,14 +105,24 @@ public class SmsMmsUtils {
|
|||||||
sendingPhoneNumber = maybeSendingPhoneNumber.get();
|
sendingPhoneNumber = maybeSendingPhoneNumber.get();
|
||||||
} else {
|
} else {
|
||||||
if (allPhoneNumbers.isEmpty()) {
|
if (allPhoneNumbers.isEmpty()) {
|
||||||
sendingPhoneNumber = null;
|
// We were not able to get any phone number for the user's device
|
||||||
|
// Use a null "dummy" number instead. This should behave the same as not setting
|
||||||
|
// the FromAddress (below) since the default value there is null.
|
||||||
|
// The only more-correct thing we could do here is query the user (maybe in a
|
||||||
|
// persistent configuration) for their phone number(s).
|
||||||
|
sendingPhoneNumber = new TelephonyHelper.LocalPhoneNumber(null, subID);
|
||||||
|
Log.w(SENDING_MESSAGE, "We do not know *any* phone numbers for this device. "
|
||||||
|
+ "Attempting to send a message without knowing the local phone number is likely "
|
||||||
|
+ "to result in strange behavior, such as the message being sent to yourself, "
|
||||||
|
+ "or might entirely fail to send (or be received).");
|
||||||
} else {
|
} else {
|
||||||
|
// Pick an arbitrary phone number
|
||||||
sendingPhoneNumber = allPhoneNumbers.get(0);
|
sendingPhoneNumber = allPhoneNumbers.get(0);
|
||||||
}
|
}
|
||||||
Log.w(SENDING_MESSAGE, "Unable to get outgoing address for sub ID " + subID + " using " + sendingPhoneNumber);
|
Log.w(SENDING_MESSAGE, "Unable to determine correct outgoing address for sub ID " + subID + ". Using " + sendingPhoneNumber);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sendingPhoneNumber != null) {
|
if (sendingPhoneNumber.number != null) {
|
||||||
// Remove the user's phone number if present in the list of recipients
|
// Remove the user's phone number if present in the list of recipients
|
||||||
addressList.removeIf(address -> sendingPhoneNumber.isMatchingPhoneNumber(address.address));
|
addressList.removeIf(address -> sendingPhoneNumber.isMatchingPhoneNumber(address.address));
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user