Loading telephony/java/com/android/internal/telephony/EncodeException.java +15 −0 Original line number Diff line number Diff line Loading @@ -22,6 +22,12 @@ import android.annotation.UnsupportedAppUsage; * {@hide} */ public class EncodeException extends Exception { private int mError = ERROR_UNENCODABLE; public static final int ERROR_UNENCODABLE = 0; public static final int ERROR_EXCEED_SIZE = 1; public EncodeException() { super(); } Loading @@ -31,9 +37,18 @@ public class EncodeException extends Exception { super(s); } public EncodeException(String s, int error) { super(s); mError = error; } @UnsupportedAppUsage public EncodeException(char c) { super("Unencodable char: '" + c + "'"); } public int getError() { return mError; } } telephony/java/com/android/internal/telephony/GsmAlphabet.java +3 −2 Original line number Diff line number Diff line Loading @@ -388,7 +388,7 @@ public class GsmAlphabet { * GSM extension table * @return the encoded message * * @throws EncodeException if String is too large to encode * @throws EncodeException if String is too large to encode or any characters are unencodable */ @UnsupportedAppUsage public static byte[] stringToGsm7BitPacked(String data, int startingSeptetOffset, Loading @@ -402,7 +402,8 @@ public class GsmAlphabet { } septetCount += startingSeptetOffset; if (septetCount > 255) { throw new EncodeException("Payload cannot exceed 255 septets"); throw new EncodeException( "Payload cannot exceed 255 septets", EncodeException.ERROR_EXCEED_SIZE); } int byteCount = ((septetCount * 7) + 7) / 8; byte[] ret = new byte[byteCount + 1]; // Include space for one byte length prefix. Loading telephony/java/com/android/internal/telephony/gsm/SmsMessage.java +21 −10 Original line number Diff line number Diff line Loading @@ -384,18 +384,24 @@ public class SmsMessage extends SmsMessageBase { } } } catch (EncodeException ex) { if (ex.getError() == EncodeException.ERROR_EXCEED_SIZE) { Rlog.e(LOG_TAG, "Exceed size limitation EncodeException", ex); return null; } else { // Encoding to the 7-bit alphabet failed. Let's see if we can // send it as a UCS-2 encoded message try { userData = encodeUCS2(message, header); encoding = ENCODING_16BIT; } catch (EncodeException ex1) { Rlog.e(LOG_TAG, "Exceed size limitation EncodeException", ex1); return null; } catch (UnsupportedEncodingException uex) { Rlog.e(LOG_TAG, "Implausible UnsupportedEncodingException ", uex); Rlog.e(LOG_TAG, "Implausible UnsupportedEncodingException ", uex); return null; } } } if (encoding == ENCODING_7BIT) { if ((0xff & userData[0]) > MAX_USER_DATA_SEPTETS) { Loading Loading @@ -438,9 +444,10 @@ public class SmsMessage extends SmsMessageBase { * * @return encoded message as UCS2 * @throws UnsupportedEncodingException * @throws EncodeException if String is too large to encode */ private static byte[] encodeUCS2(String message, byte[] header) throws UnsupportedEncodingException { throws UnsupportedEncodingException, EncodeException { byte[] userData, textPart; textPart = message.getBytes("utf-16be"); Loading @@ -455,6 +462,10 @@ public class SmsMessage extends SmsMessageBase { else { userData = textPart; } if (userData.length > 255) { throw new EncodeException( "Payload cannot exceed 255 bytes", EncodeException.ERROR_EXCEED_SIZE); } byte[] ret = new byte[userData.length+1]; ret[0] = (byte) (userData.length & 0xff ); System.arraycopy(userData, 0, ret, 1, userData.length); Loading Loading
telephony/java/com/android/internal/telephony/EncodeException.java +15 −0 Original line number Diff line number Diff line Loading @@ -22,6 +22,12 @@ import android.annotation.UnsupportedAppUsage; * {@hide} */ public class EncodeException extends Exception { private int mError = ERROR_UNENCODABLE; public static final int ERROR_UNENCODABLE = 0; public static final int ERROR_EXCEED_SIZE = 1; public EncodeException() { super(); } Loading @@ -31,9 +37,18 @@ public class EncodeException extends Exception { super(s); } public EncodeException(String s, int error) { super(s); mError = error; } @UnsupportedAppUsage public EncodeException(char c) { super("Unencodable char: '" + c + "'"); } public int getError() { return mError; } }
telephony/java/com/android/internal/telephony/GsmAlphabet.java +3 −2 Original line number Diff line number Diff line Loading @@ -388,7 +388,7 @@ public class GsmAlphabet { * GSM extension table * @return the encoded message * * @throws EncodeException if String is too large to encode * @throws EncodeException if String is too large to encode or any characters are unencodable */ @UnsupportedAppUsage public static byte[] stringToGsm7BitPacked(String data, int startingSeptetOffset, Loading @@ -402,7 +402,8 @@ public class GsmAlphabet { } septetCount += startingSeptetOffset; if (septetCount > 255) { throw new EncodeException("Payload cannot exceed 255 septets"); throw new EncodeException( "Payload cannot exceed 255 septets", EncodeException.ERROR_EXCEED_SIZE); } int byteCount = ((septetCount * 7) + 7) / 8; byte[] ret = new byte[byteCount + 1]; // Include space for one byte length prefix. Loading
telephony/java/com/android/internal/telephony/gsm/SmsMessage.java +21 −10 Original line number Diff line number Diff line Loading @@ -384,18 +384,24 @@ public class SmsMessage extends SmsMessageBase { } } } catch (EncodeException ex) { if (ex.getError() == EncodeException.ERROR_EXCEED_SIZE) { Rlog.e(LOG_TAG, "Exceed size limitation EncodeException", ex); return null; } else { // Encoding to the 7-bit alphabet failed. Let's see if we can // send it as a UCS-2 encoded message try { userData = encodeUCS2(message, header); encoding = ENCODING_16BIT; } catch (EncodeException ex1) { Rlog.e(LOG_TAG, "Exceed size limitation EncodeException", ex1); return null; } catch (UnsupportedEncodingException uex) { Rlog.e(LOG_TAG, "Implausible UnsupportedEncodingException ", uex); Rlog.e(LOG_TAG, "Implausible UnsupportedEncodingException ", uex); return null; } } } if (encoding == ENCODING_7BIT) { if ((0xff & userData[0]) > MAX_USER_DATA_SEPTETS) { Loading Loading @@ -438,9 +444,10 @@ public class SmsMessage extends SmsMessageBase { * * @return encoded message as UCS2 * @throws UnsupportedEncodingException * @throws EncodeException if String is too large to encode */ private static byte[] encodeUCS2(String message, byte[] header) throws UnsupportedEncodingException { throws UnsupportedEncodingException, EncodeException { byte[] userData, textPart; textPart = message.getBytes("utf-16be"); Loading @@ -455,6 +462,10 @@ public class SmsMessage extends SmsMessageBase { else { userData = textPart; } if (userData.length > 255) { throw new EncodeException( "Payload cannot exceed 255 bytes", EncodeException.ERROR_EXCEED_SIZE); } byte[] ret = new byte[userData.length+1]; ret[0] = (byte) (userData.length & 0xff ); System.arraycopy(userData, 0, ret, 1, userData.length); Loading