use of com.android.internal.telephony.cdma.sms.BearerData in project XobotOS by xamarin.
the class SmsMessage method privateGetSubmitPdu.
/**
* Creates BearerData and Envelope from parameters for a Submit SMS.
* @return byte stream for SubmitPdu.
*/
private static SubmitPdu privateGetSubmitPdu(String destAddrStr, boolean statusReportRequested, UserData userData) {
/**
* TODO(cleanup): give this function a more meaningful name.
*/
/**
* TODO(cleanup): Make returning null from the getSubmitPdu
* variations meaningful -- clean up the error feedback
* mechanism, and avoid null pointer exceptions.
*/
/**
* North America Plus Code :
* Convert + code to 011 and dial out for international SMS
*/
CdmaSmsAddress destAddr = CdmaSmsAddress.parse(PhoneNumberUtils.cdmaCheckAndProcessPlusCode(destAddrStr));
if (destAddr == null)
return null;
BearerData bearerData = new BearerData();
bearerData.messageType = BearerData.MESSAGE_TYPE_SUBMIT;
bearerData.messageId = getNextMessageId();
bearerData.deliveryAckReq = statusReportRequested;
bearerData.userAckReq = false;
bearerData.readAckReq = false;
bearerData.reportReq = false;
bearerData.userData = userData;
byte[] encodedBearerData = BearerData.encode(bearerData);
if (Log.isLoggable(LOGGABLE_TAG, Log.VERBOSE)) {
Log.d(LOG_TAG, "MO (encoded) BearerData = " + bearerData);
Log.d(LOG_TAG, "MO raw BearerData = '" + HexDump.toHexString(encodedBearerData) + "'");
}
if (encodedBearerData == null)
return null;
int teleservice = bearerData.hasUserDataHeader ? SmsEnvelope.TELESERVICE_WEMT : SmsEnvelope.TELESERVICE_WMT;
SmsEnvelope envelope = new SmsEnvelope();
envelope.messageType = SmsEnvelope.MESSAGE_TYPE_POINT_TO_POINT;
envelope.teleService = teleservice;
envelope.destAddress = destAddr;
envelope.bearerReply = RETURN_ACK;
envelope.bearerData = encodedBearerData;
try {
/**
* TODO(cleanup): reference a spec and get rid of the ugly comments
*/
ByteArrayOutputStream baos = new ByteArrayOutputStream(100);
DataOutputStream dos = new DataOutputStream(baos);
dos.writeInt(envelope.teleService);
//servicePresent
dos.writeInt(0);
//serviceCategory
dos.writeInt(0);
dos.write(destAddr.digitMode);
dos.write(destAddr.numberMode);
// number_type
dos.write(destAddr.ton);
dos.write(destAddr.numberPlan);
dos.write(destAddr.numberOfDigits);
// digits
dos.write(destAddr.origBytes, 0, destAddr.origBytes.length);
// Subaddress is not supported.
//subaddressType
dos.write(0);
//subaddr_odd
dos.write(0);
//subaddr_nbr_of_digits
dos.write(0);
dos.write(encodedBearerData.length);
dos.write(encodedBearerData, 0, encodedBearerData.length);
dos.close();
SubmitPdu pdu = new SubmitPdu();
pdu.encodedMessage = baos.toByteArray();
pdu.encodedScAddress = null;
return pdu;
} catch (IOException ex) {
Log.e(LOG_TAG, "creating SubmitPdu failed: " + ex);
}
return null;
}
use of com.android.internal.telephony.cdma.sms.BearerData in project XobotOS by xamarin.
the class SmsMessage method parseSms.
/**
* Parses a SMS message from its BearerData stream. (mobile-terminated only)
*/
protected void parseSms() {
// It contains only an 8-bit number with the number of messages waiting
if (mEnvelope.teleService == SmsEnvelope.TELESERVICE_MWI) {
mBearerData = new BearerData();
if (mEnvelope.bearerData != null) {
mBearerData.numberOfMessages = 0x000000FF & mEnvelope.bearerData[0];
}
if (false) {
Log.d(LOG_TAG, "parseSms: get MWI " + Integer.toString(mBearerData.numberOfMessages));
}
return;
}
mBearerData = BearerData.decode(mEnvelope.bearerData);
if (Log.isLoggable(LOGGABLE_TAG, Log.VERBOSE)) {
Log.d(LOG_TAG, "MT raw BearerData = '" + HexDump.toHexString(mEnvelope.bearerData) + "'");
Log.d(LOG_TAG, "MT (decoded) BearerData = " + mBearerData);
}
messageRef = mBearerData.messageId;
if (mBearerData.userData != null) {
userData = mBearerData.userData.payload;
userDataHeader = mBearerData.userData.userDataHeader;
messageBody = mBearerData.userData.payloadStr;
}
if (originatingAddress != null) {
originatingAddress.address = new String(originatingAddress.origBytes);
if (false)
Log.v(LOG_TAG, "SMS originating address: " + originatingAddress.address);
}
if (mBearerData.msgCenterTimeStamp != null) {
scTimeMillis = mBearerData.msgCenterTimeStamp.toMillis(true);
}
if (false)
Log.d(LOG_TAG, "SMS SC timestamp: " + scTimeMillis);
// Message Type (See 3GPP2 C.S0015-B, v2, 4.5.1)
if (mBearerData.messageType == BearerData.MESSAGE_TYPE_DELIVERY_ACK) {
// indicate successful delivery (status == 0).
if (!mBearerData.messageStatusSet) {
Log.d(LOG_TAG, "DELIVERY_ACK message without msgStatus (" + (userData == null ? "also missing" : "does have") + " userData).");
status = 0;
} else {
status = mBearerData.errorClass << 8;
status |= mBearerData.messageStatus;
}
} else if (mBearerData.messageType != BearerData.MESSAGE_TYPE_DELIVER) {
throw new RuntimeException("Unsupported message type: " + mBearerData.messageType);
}
if (messageBody != null) {
if (false)
Log.v(LOG_TAG, "SMS message body: '" + messageBody + "'");
parseMessageBody();
} else if ((userData != null) && (false)) {
Log.v(LOG_TAG, "SMS payload: '" + IccUtils.bytesToHexString(userData) + "'");
}
}
Aggregations