Work around SmsMessage.calculateLength NPE on broken ROMs

//FREEBIE
This commit is contained in:
Markus Brenneis 2017-05-15 21:13:27 +02:00 committed by Moxie Marlinspike
parent 37a5622525
commit 66062f200a

View File

@ -17,16 +17,30 @@
package org.thoughtcrime.securesms.util;
import android.telephony.SmsMessage;
import android.util.Log;
public class SmsCharacterCalculator extends CharacterCalculator {
private static final String TAG = SmsCharacterCalculator.class.getSimpleName();
@Override
public CharacterState calculateCharacters(String messageBody) {
int[] length;
int messagesSpent;
int charactersSpent;
int charactersRemaining;
int[] length = SmsMessage.calculateLength(messageBody, false);
int messagesSpent = length[0];
int charactersSpent = length[1];
int charactersRemaining = length[2];
try {
length = SmsMessage.calculateLength(messageBody, false);
messagesSpent = length[0];
charactersSpent = length[1];
charactersRemaining = length[2];
} catch (NullPointerException e) {
Log.w(TAG, e);
messagesSpent = 1;
charactersSpent = messageBody.length();
charactersRemaining = 1000;
}
int maxMessageSize;