SmsAddresspublic class SmsAddress extends Object
Fields Summary |
---|
static final int | TON_UNKNOWN | static final int | TON_INTERNATIONAL | static final int | TON_NATIONAL | static final int | TON_NETWORK | static final int | TON_SUBSCRIBER | static final int | TON_ALPHANUMERIC | static final int | TON_APPREVIATED | static final int | OFFSET_ADDRESS_LENGTH | static final int | OFFSET_TOA | static final int | OFFSET_ADDRESS_VALUE | int | ton | String | address | byte[] | origBytes |
Constructors Summary |
---|
SmsAddress(byte[] data, int offset, int length)New SmsAddress from TS 23.040 9.1.2.5 Address Field
origBytes = new byte[length];
System.arraycopy(data, offset, origBytes, 0, length);
// addressLength is the count of semi-octets, not bytes
int addressLength = origBytes[OFFSET_ADDRESS_LENGTH] & 0xff;
int toa = origBytes[OFFSET_TOA] & 0xff;
ton = 0x7 & (toa >> 4);
// TOA must have its high bit set
if ((toa & 0x80) != 0x80) {
throw new RuntimeException("Invalid TOA - high bit must be set");
}
if (isAlphanumeric()) {
// An alphanumeric address
int countSeptets = addressLength * 4 / 7;
address = GsmAlphabet.gsm7BitPackedToString(origBytes,
OFFSET_ADDRESS_VALUE, countSeptets);
} else {
// TS 23.040 9.1.2.5 says
// that "the MS shall interpret reserved values as 'Unknown'
// but shall store them exactly as received"
byte lastByte = origBytes[length - 1];
if ((addressLength & 1) == 1) {
// Make sure the final unused BCD digit is 0xf
origBytes[length - 1] |= 0xf0;
}
address = PhoneNumberUtils.calledPartyBCDToString(origBytes,
OFFSET_TOA, length - OFFSET_TOA);
// And restore origBytes
origBytes[length - 1] = lastByte;
}
|
Methods Summary |
---|
public boolean | couldBeEmailGateway()
// Some carriers seems to send email gateway messages in this form:
// from: an UNKNOWN TON, 3 or 4 digits long, beginning with a 5
// PID: 0x00, Data coding scheme 0x03
// So we just attempt to treat any message from an address length <= 4
// as an email gateway
return address.length() <= 4;
| public java.lang.String | getAddressString()
return address;
| public boolean | isAlphanumeric()Returns true if this is an alphanumeric addres
return ton == TON_ALPHANUMERIC;
| public boolean | isCphsVoiceMessageClear()Returns true if this is a valid CPHS voice message waiting indicator
address indicationg a "clear" of "indicator 1" of type "voice message
waiting"
// 0x10 means "clear" "voice message waiting" "indicator 1"
return isCphsVoiceMessageIndicatorAddress()
&& (origBytes[OFFSET_ADDRESS_VALUE] & 0xff) == 0x10;
| public boolean | isCphsVoiceMessageIndicatorAddress()Returns true of this is a valid CPHS voice message waiting indicator
address
// CPHS-style MWI message
// See CPHS 4.7 B.4.2.1
//
// Basically:
//
// - Originating address should be 4 bytes long and alphanumeric
// - Decode will result with two chars:
// - Char 1
// 76543210
// ^ set/clear indicator (0 = clear)
// ^^^ type of indicator (000 = voice)
// ^^^^ must be equal to 0001
// - Char 2:
// 76543210
// ^ line number (0 = line 1)
// ^^^^^^^ set to 0
//
// Remember, since the alpha address is stored in 7-bit compact form,
// the "line number" is really the top bit of the first address value
// byte
return (origBytes[OFFSET_ADDRESS_LENGTH] & 0xff) == 4
&& isAlphanumeric() && (origBytes[OFFSET_TOA] & 0x0f) == 0;
| public boolean | isCphsVoiceMessageSet()Returns true if this is a valid CPHS voice message waiting indicator
address indicating a "set" of "indicator 1" of type "voice message
waiting"
// 0x11 means "set" "voice message waiting" "indicator 1"
return isCphsVoiceMessageIndicatorAddress()
&& (origBytes[OFFSET_ADDRESS_VALUE] & 0xff) == 0x11;
| public boolean | isNetworkSpecific()
return ton == TON_NETWORK;
|
|