use of com.google.android.mms.pdu_alt.EncodedStringValue in project qksms by moezbhatti.
the class ReadRecTransaction method run.
public void run() {
PduPersister persister = PduPersister.getPduPersister(mContext);
try {
// Load M-read-rec.ind from outbox
ReadRecInd readRecInd = (ReadRecInd) persister.load(mReadReportURI);
// insert the 'from' address per spec
String lineNumber = Utils.getMyPhoneNumber(mContext);
readRecInd.setFrom(new EncodedStringValue(lineNumber));
// Pack M-read-rec.ind and send it
byte[] postingData = new PduComposer(mContext, readRecInd).make();
sendPdu(postingData);
Uri uri = persister.move(mReadReportURI, Uri.parse("content://mms/sent"));
mTransactionState.setState(TransactionState.SUCCESS);
mTransactionState.setContentUri(uri);
} catch (IOException e) {
if (LOCAL_LOGV)
Log.v(TAG, "Failed to send M-Read-Rec.Ind.", e);
} catch (MmsException e) {
if (LOCAL_LOGV)
Log.v(TAG, "Failed to load message from Outbox.", e);
} catch (RuntimeException e) {
Log.e(TAG, "Unexpected RuntimeException.", e);
} finally {
if (mTransactionState.getState() != TransactionState.SUCCESS) {
mTransactionState.setState(TransactionState.FAILED);
mTransactionState.setContentUri(mReadReportURI);
}
notifyObservers();
}
}
use of com.google.android.mms.pdu_alt.EncodedStringValue in project qksms by moezbhatti.
the class RetrieveTransaction method isDuplicateMessageExtra.
private static boolean isDuplicateMessageExtra(Cursor cursor, RetrieveConf rc) {
// Compare message subjects, taking encoding into account
EncodedStringValue encodedSubjectReceived;
EncodedStringValue encodedSubjectStored = null;
String subjectReceived = null;
String subjectStored;
String subject;
encodedSubjectReceived = rc.getSubject();
if (encodedSubjectReceived != null) {
subjectReceived = encodedSubjectReceived.getString();
}
for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
int subjectIdx = cursor.getColumnIndex(Mms.SUBJECT);
int charsetIdx = cursor.getColumnIndex(Mms.SUBJECT_CHARSET);
subject = cursor.getString(subjectIdx);
int charset = cursor.getInt(charsetIdx);
if (subject != null) {
encodedSubjectStored = new EncodedStringValue(charset, PduPersister.getBytes(subject));
}
if (encodedSubjectStored == null && encodedSubjectReceived == null) {
// Both encoded subjects are null - return true
return true;
} else if (encodedSubjectStored != null && encodedSubjectReceived != null) {
subjectStored = encodedSubjectStored.getString();
if (!TextUtils.isEmpty(subjectStored) && !TextUtils.isEmpty(subjectReceived)) {
// Both decoded subjects are non-empty - compare them
return subjectStored.equals(subjectReceived);
} else if (TextUtils.isEmpty(subjectStored) && TextUtils.isEmpty(subjectReceived)) {
// Both decoded subjects are "" - return true
return true;
}
}
}
return false;
}
use of com.google.android.mms.pdu_alt.EncodedStringValue in project qksms by moezbhatti.
the class MmsMessageSender method sendReadRec.
public static void sendReadRec(Context context, String to, String messageId, int status) {
EncodedStringValue[] sender = new EncodedStringValue[1];
sender[0] = new EncodedStringValue(to);
try {
final ReadRecInd readRec = new ReadRecInd(new EncodedStringValue(PduHeaders.FROM_INSERT_ADDRESS_TOKEN_STR.getBytes()), messageId.getBytes(), PduHeaders.CURRENT_MMS_VERSION, status, sender);
readRec.setDate(System.currentTimeMillis() / 1000);
boolean group;
try {
group = com.moez.QKSMS.mmssms.Transaction.settings.getGroup();
} catch (Exception e) {
group = PreferenceManager.getDefaultSharedPreferences(context).getBoolean("pref_key_compose_group", true);
}
PduPersister.getPduPersister(context).persist(readRec, Uri.parse("content://mms/outbox"), true, group, null);
Intent service = new Intent(TransactionService.HANDLE_PENDING_TRANSACTIONS_ACTION, null, context, TransactionService.class);
context.startService(service);
} catch (InvalidHeaderValueException e) {
Log.e(TAG, "Invalide header value", e);
} catch (MmsException e) {
Log.e(TAG, "Persist message failed", e);
}
}
use of com.google.android.mms.pdu_alt.EncodedStringValue in project qksms by moezbhatti.
the class SendTransaction method run.
public void run() {
try {
RateController.init(mContext);
RateController rateCtlr = RateController.getInstance();
if (rateCtlr.isLimitSurpassed() && !rateCtlr.isAllowedByUser()) {
Log.e(TAG, "Sending rate limit surpassed.");
return;
}
// Load M-Send.req from outbox
PduPersister persister = PduPersister.getPduPersister(mContext);
SendReq sendReq = (SendReq) persister.load(mSendReqURI);
// Update the 'date' field of the PDU right before sending it.
long date = System.currentTimeMillis() / 1000L;
sendReq.setDate(date);
// Persist the new date value into database.
ContentValues values = new ContentValues(1);
values.put(Mms.DATE, date);
SqliteWrapper.update(mContext, mContext.getContentResolver(), mSendReqURI, values, null, null);
// fix bug 2100169: insert the 'from' address per spec
String lineNumber = Utils.getMyPhoneNumber(mContext);
if (!TextUtils.isEmpty(lineNumber)) {
sendReq.setFrom(new EncodedStringValue(lineNumber));
}
// Pack M-Send.req, send it, retrieve confirmation data, and parse it
long tokenKey = ContentUris.parseId(mSendReqURI);
byte[] response = sendPdu(SendingProgressTokenManager.get(tokenKey), new PduComposer(mContext, sendReq).make());
SendingProgressTokenManager.remove(tokenKey);
if (LOCAL_LOGV) {
String respStr = new String(response);
Log.d(TAG, "[SendTransaction] run: send mms msg (" + mId + "), resp=" + respStr);
}
SendConf conf = (SendConf) new PduParser(response).parse();
if (conf == null) {
Log.e(TAG, "No M-Send.conf received.");
}
// Check whether the responding Transaction-ID is consistent
// with the sent one.
byte[] reqId = sendReq.getTransactionId();
byte[] confId = conf.getTransactionId();
if (!Arrays.equals(reqId, confId)) {
Log.e(TAG, "Inconsistent Transaction-ID: req=" + new String(reqId) + ", conf=" + new String(confId));
return;
}
// From now on, we won't save the whole M-Send.conf into
// our database. Instead, we just save some interesting fields
// into the related M-Send.req.
values = new ContentValues(2);
int respStatus = conf.getResponseStatus();
values.put(Mms.RESPONSE_STATUS, respStatus);
if (respStatus != PduHeaders.RESPONSE_STATUS_OK) {
SqliteWrapper.update(mContext, mContext.getContentResolver(), mSendReqURI, values, null, null);
Log.e(TAG, "Server returned an error code: " + respStatus);
return;
}
String messageId = PduPersister.toIsoString(conf.getMessageId());
values.put(Mms.MESSAGE_ID, messageId);
SqliteWrapper.update(mContext, mContext.getContentResolver(), mSendReqURI, values, null, null);
// Move M-Send.req from Outbox into Sent.
Uri uri = persister.move(mSendReqURI, Sent.CONTENT_URI);
mTransactionState.setState(TransactionState.SUCCESS);
mTransactionState.setContentUri(uri);
} catch (Throwable t) {
Log.e(TAG, Log.getStackTraceString(t));
} finally {
if (mTransactionState.getState() != TransactionState.SUCCESS) {
mTransactionState.setState(TransactionState.FAILED);
mTransactionState.setContentUri(mSendReqURI);
Log.e(TAG, "Delivery failed.");
}
notifyObservers();
}
}
use of com.google.android.mms.pdu_alt.EncodedStringValue in project qksms by moezbhatti.
the class AddressUtils method getFrom.
public static String getFrom(Context context, Uri uri) {
String msgId = uri.getLastPathSegment();
Uri.Builder builder = Mms.CONTENT_URI.buildUpon();
builder.appendPath(msgId).appendPath("addr");
Cursor cursor = SqliteWrapper.query(context, context.getContentResolver(), builder.build(), new String[] { Addr.ADDRESS, Addr.CHARSET }, Addr.TYPE + "=" + PduHeaders.FROM, null, null);
if (cursor != null) {
try {
if (cursor.moveToFirst()) {
String from = cursor.getString(0);
if (!TextUtils.isEmpty(from)) {
byte[] bytes = PduPersister.getBytes(from);
int charset = cursor.getInt(1);
return new EncodedStringValue(charset, bytes).getString();
}
}
} finally {
cursor.close();
}
}
return context.getString(R.string.hidden_sender_address);
}
Aggregations