Example usage for android.telephony SmsManager getSmsManagerForSubscriptionId

List of usage examples for android.telephony SmsManager getSmsManagerForSubscriptionId

Introduction

In this page you can find the example usage for android.telephony SmsManager getSmsManagerForSubscriptionId.

Prototype

public static SmsManager getSmsManagerForSubscriptionId(int subId) 

Source Link

Document

Get the instance of the SmsManager associated with a particular subscription ID.

Usage

From source file:com.android.mms.transaction.SendTransaction.java

public void run() {
    Log.d(MmsApp.TXN_TAG, "SendTransaction: run");
    RateController rateCtlr = RateController.getInstance();
    if (rateCtlr.isLimitSurpassed() && !rateCtlr.isAllowedByUser()) {
        Log.e(TAG, "Sending rate limit surpassed.");
        return;//from   ww  w . j  a v a 2s.c  o m
    }

    try {
        final PduPersister persister = PduPersister.getPduPersister(mContext);
        final SendReq sendReq = (SendReq) persister.load(mUri);
        if (sendReq == null) {
            Log.w(MmsApp.TXN_TAG, "Send req is null!");
            return;
        }
        byte[] datas = new PduComposer(mContext, sendReq).make();
        mPduFile = createPduFile(datas, SEND_REQ_NAME + mUri.getLastPathSegment());
        if (mPduFile == null) {
            Log.w(MmsApp.TXN_TAG, "create pdu file req failed!");
            return;
        }

        //Intent intent = new Intent(TransactionService.ACTION_TRANSACION_PROCESSED);
        //intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, mSubId);
        //intent.putExtra(TransactionBundle.URI, mUri.toString());
        Log.d(MmsApp.TXN_TAG, "SendTransaction mUri:" + mUri);
        final Intent intent = new Intent(TransactionService.ACTION_TRANSACION_PROCESSED, mUri, mContext,
                MmsReceiver.class);
        intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, mSubId);

        PendingIntent sentIntent = PendingIntent.getBroadcast(mContext, 0, intent,
                PendingIntent.FLAG_UPDATE_CURRENT);
        Log.d(MmsApp.TXN_TAG,
                "send MMS with param, mUri = " + mUri + " mPdufile = " + mPduFile + ", subId = " + mSubId);
        Uri pduFileUri = FileProvider.getUriForFile(mContext, MMS_FILE_PROVIDER_AUTHORITIES, mPduFile);
        /// M: Add MmsService configure param @{
        SmsManager.getSmsManagerForSubscriptionId(mSubId).sendMultimediaMessage(mContext, pduFileUri, null,
                MmsConfig.getMmsServiceConfig(), sentIntent);
        /// @}
    } catch (Throwable t) {
        Log.e(TAG, Log.getStackTraceString(t));
        getState().setState(FAILED);
        getState().setContentUri(mUri);
        notifyObservers();
    }
}

From source file:com.android.mms.transaction.ReadRecTransaction.java

public void run() {
    MmsLog.d(MmsApp.TXN_TAG, "ReadRecTransaction: process()");
    // prepare for ReadRec
    int readReportState = 0;
    String messageId = null;/*  ww w.  j a  v  a 2  s .  com*/
    long msgId = 0;
    EncodedStringValue[] sender = new EncodedStringValue[1];
    Cursor cursor = null;
    cursor = SqliteWrapper.query(mContext, mContext.getContentResolver(), mUri,
            new String[] { Mms.MESSAGE_ID, Mms.READ_REPORT, Mms._ID }, null, null, null);
    if (cursor != null) {
        try {
            if (cursor.moveToFirst()) {
                messageId = cursor.getString(0);
                readReportState = cursor.getInt(1);
                msgId = cursor.getLong(2);
            }
            // if curosr==null, this means the mms is deleted during
            // processing.
            // exception will happened. catched by out catch clause.
            // so do not catch exception here.
        } finally {
            cursor.close();
        }
    }
    MmsLog.d(MmsApp.TXN_TAG,
            "messageid:" + messageId + ",and readreport flag:" + readReportState + ", mSubId = " + mSubId);

    cursor = null;
    cursor = SqliteWrapper.query(mContext, mContext.getContentResolver(),
            Uri.parse("content://mms/" + msgId + "/addr"), new String[] { Mms.Addr.ADDRESS, Mms.Addr.CHARSET },
            Mms.Addr.TYPE + " = " + PduHeaders.FROM, null, null);
    if (cursor != null) {
        try {
            if (cursor.moveToFirst()) {
                String address = cursor.getString(0);
                int charSet = cursor.getInt(1);
                MmsLog.d(MmsApp.TXN_TAG, "find address:" + address + ",charset:" + charSet);
                sender[0] = new EncodedStringValue(charSet, PduPersister.getBytes(address));
            }
            // if cursor == null exception will catched by out catch clause.
        } finally {
            cursor.close();
        }
    }
    try {
        ReadRecInd readRecInd = new ReadRecInd(
                new EncodedStringValue(PduHeaders.FROM_INSERT_ADDRESS_TOKEN_STR.getBytes()),
                messageId.getBytes(), PduHeaders.CURRENT_MMS_VERSION, PduHeaders.READ_STATUS_READ, // always
                // set
                // read.
                sender);
        readRecInd.setDate(System.currentTimeMillis() / 1000);
        Uri uri = PduPersister.getPduPersister(mContext).persist(readRecInd, Mms.Outbox.CONTENT_URI, true,
                MmsPreferenceActivity.getIsGroupMmsEnabled(mContext), null);

        byte[] datas = new PduComposer(mContext, readRecInd).make();
        mPduFile = createPduFile(datas, READREP_REQ_NAME + uri.getLastPathSegment());
        if (mPduFile == null) {
            Log.e(MmsApp.TXN_TAG, "create pdu file req failed!");
            return;
        }
        //Intent intent = new Intent(TransactionService.ACTION_TRANSACION_PROCESSED);
        //intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, mSubId);
        //intent.putExtra(TransactionBundle.URI, mUri.toString());
        Log.d(MmsApp.TXN_TAG, "ReadRecTransaction mUri:" + mUri);
        final Intent intent = new Intent(TransactionService.ACTION_TRANSACION_PROCESSED, mUri, mContext,
                MmsReceiver.class);
        intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, mSubId);

        PendingIntent sentIntent = PendingIntent.getBroadcast(mContext, 0, intent,
                PendingIntent.FLAG_UPDATE_CURRENT);
        Uri pduFileUri = FileProvider.getUriForFile(mContext, MMS_FILE_PROVIDER_AUTHORITIES, mPduFile);
        SmsManager.getSmsManagerForSubscriptionId(mSubId).sendMultimediaMessage(mContext, pduFileUri, null,
                null, sentIntent);
    } catch (InvalidHeaderValueException e) {
        Log.e(TAG, "Invalide header value", e);
        getState().setState(FAILED);
        getState().setContentUri(mUri);
        notifyObservers();
    } catch (MmsException e) {
        Log.e(TAG, "Persist message failed", e);
        getState().setState(FAILED);
        getState().setContentUri(mUri);
        notifyObservers();
    } catch (Throwable t) {
        Log.e(TAG, Log.getStackTraceString(t));
        getState().setState(FAILED);
        getState().setContentUri(mUri);
        notifyObservers();
    }
}

From source file:com.android.mms.transaction.NotificationTransaction.java

public void run() {
    MmsLog.d(MmsApp.TXN_TAG, "NotificationTransaction: run");
    DownloadManager downloadManager = DownloadManager.getInstance();
    boolean autoDownload = allowAutoDownload(mContext, mSubId);
    try {/*from w w  w.  ja  va2s.co  m*/
        if (LOCAL_LOGV) {
            Log.v(TAG, "Notification transaction launched: " + this);
        }

        // By default, we set status to STATUS_DEFERRED because we
        // should response MMSC with STATUS_DEFERRED when we cannot
        // download a MM immediately.
        int status = STATUS_DEFERRED;
        // Don't try to download when data is suspended, as it will fail, so defer download
        if (!autoDownload) {
            // M: change API for ALPS01889178, use sub id.
            downloadManager.markState(mUri, DownloadManager.STATE_UNSTARTED, mSubId);
            sendNotifyRespInd(status);
            getState().setState(SUCCESS);
            getState().setContentUri(mUri);
            notifyObservers();
            return;
        }

        // M: change API for ALPS01889178, use sub id.
        downloadManager.markState(mUri, DownloadManager.STATE_DOWNLOADING, mSubId);

        if (mOpNotificationTransactionExt.run(mIsCancelling, mUri, mContext, getUri(), mContentLocation)) {
            mTransactionState.setState(TransactionState.SUCCESS);
            mTransactionState.setContentUri(mUri);
            mIsCancelling = false;
            return;
        }

        if (LOCAL_LOGV) {
            Log.v(TAG, "Content-Location: " + mContentLocation);
        }
        mPduFile = createPduFile(null, RETRIEVE_RESULT_NAME + mUri.getLastPathSegment());
        mPduFile.setWritable(true, false);

        //Intent intent = new Intent(TransactionService.ACTION_TRANSACION_PROCESSED);
        //intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, mSubId);
        //intent.putExtra(TransactionBundle.URI, mUri.toString());

        Log.d(MmsApp.TXN_TAG, "NotificationTransaction mUri:" + mUri);
        final Intent intent = new Intent(TransactionService.ACTION_TRANSACION_PROCESSED, mUri, mContext,
                MmsReceiver.class);
        intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, mSubId);

        PendingIntent downloadedIntent = PendingIntent.getBroadcast(mContext, 0, intent,
                PendingIntent.FLAG_UPDATE_CURRENT);

        SmsManager manager = SmsManager.getSmsManagerForSubscriptionId(mSubId);
        Log.d(MmsApp.TXN_TAG, "download MMS with param, mContentLocation = " + mContentLocation + ", mUri = "
                + mUri + ", subId" + mSubId);

        /// M: Add MmsService configure param @{
        Uri pduFileUri = FileProvider.getUriForFile(mContext, MMS_FILE_PROVIDER_AUTHORITIES, mPduFile);
        manager.downloadMultimediaMessage(mContext, mContentLocation, pduFileUri,
                MmsConfig.getMmsServiceConfig(), downloadedIntent);
        /// @}

        // sendNotifyRespInd(status);

        // Make sure this thread isn't over the limits in message count.
        Recycler.getMmsRecycler().deleteOldMessagesInSameThreadAsMessage(mContext, mUri);
        MmsWidgetProvider.notifyDatasetChanged(mContext);
    } catch (Throwable t) {
        getState().setState(FAILED);
        getState().setContentUri(mUri);
        notifyObservers();
        Log.e(TAG, Log.getStackTraceString(t));
    }
}

From source file:com.android.mms.transaction.RetrieveTransaction.java

public void run() {
    MmsLog.i(MmsApp.TXN_TAG, "RetrieveTransaction: run()");
    try {/*from   www  .j ava2 s.co m*/
        NotificationInd nInd = (NotificationInd) PduPersister.getPduPersister(mContext).load(mUri);
        if (nInd.getExpiry() < System.currentTimeMillis() / 1000L) {
            MmsLog.d(MmsApp.TXN_TAG, "The message is expired!");
            sendExpiredRes();
            // Change the downloading state of the M-Notification.ind.
            DownloadManager.getInstance().markState(mUri, DownloadManager.STATE_DOWNLOADING);
            mTransactionState.setState(TransactionState.SUCCESS);
            mTransactionState.setContentUri(mUri);
            notifyObservers();
            return;
        }

        // Change the downloading state of the M-Notification.ind.
        DownloadManager.getInstance().markState(mUri, DownloadManager.STATE_DOWNLOADING);

        /// M: For OP009, check if cancel download requested. @{
        /*            if (MmsConfig.isCancelDownloadEnable() && mIsCancelling) {
        mTransactionState.setState(TransactionState.SUCCESS);
        mTransactionState.setContentUri(mUri);
                
        if (MmsConfig.isCancelDownloadEnable()) {
            sMmsFailedNotifyPlugin.popupToast(mContext,
                IMmsFailedNotifyExt.CANCEL_DOWNLOAD, null);
        }
        mIsCancelling = false;
        final Uri trxnUri = getUri();
        sCancelDownloadPlugin.markStateExt(trxnUri, sCancelDownloadPlugin.STATE_COMPLETE);
        DownloadManager.getInstance().markState(trxnUri, DownloadManager.STATE_UNSTARTED);
                
        return;
                    }*/
        /// @}

        if (mOpRetrieveTransactionExt.run(mIsCancelling, mUri, mContext, getUri(), mContentLocation)) {
            mTransactionState.setState(TransactionState.SUCCESS);
            mTransactionState.setContentUri(mUri);
            mIsCancelling = false;
            return;
        }

        mPduFile = createPduFile(null, RETRIEVE_RESULT_NAME + mUri.getLastPathSegment());
        mPduFile.setWritable(true, false);
        //Intent intent = new Intent(TransactionService.ACTION_TRANSACION_PROCESSED);
        //intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, mSubId);
        //intent.putExtra(TransactionBundle.URI, mUri.toString());
        Log.d(MmsApp.TXN_TAG, "RetrieveTransaction mUri:" + mUri);
        final Intent intent = new Intent(TransactionService.ACTION_TRANSACION_PROCESSED, mUri, mContext,
                MmsReceiver.class);
        intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, mSubId);

        PendingIntent downloadedIntent = PendingIntent.getBroadcast(mContext, 0, intent,
                PendingIntent.FLAG_UPDATE_CURRENT);
        SmsManager manager = SmsManager.getSmsManagerForSubscriptionId(mSubId);
        Log.d(MmsApp.TXN_TAG, "download MMS with param, mContentLocation = " + mContentLocation + ", mUri = "
                + mUri + ", subId" + mSubId);
        /// M: Add MmsService configure param @{
        Uri pduFileUri = FileProvider.getUriForFile(mContext, MMS_FILE_PROVIDER_AUTHORITIES, mPduFile);
        manager.downloadMultimediaMessage(mContext, mContentLocation, pduFileUri,
                MmsConfig.getMmsServiceConfig(), downloadedIntent);
        /// @}

        // Make sure this thread isn't over the limits in message count.
        Recycler.getMmsRecycler().deleteOldMessagesInSameThreadAsMessage(mContext, mUri);

        /// OP009 MMS Feature: cancel download Mms @{
        /*            if (MmsConfig.isCancelDownloadEnable()) {
        sCancelDownloadPlugin.addHttpClient(mContentLocation, mUri);
                    }*/
        /// @}

        // Send ACK to the Proxy-Relay to indicate we have fetched the
        // MM successfully.
        // Don't mark the transaction as failed if we failed to send it.
        // sendAcknowledgeInd(retrieveConf);
    } catch (Throwable t) {
        Log.e(TAG, Log.getStackTraceString(t));
        mTransactionState.setState(TransactionState.FAILED);
        mTransactionState.setContentUri(mUri);
        notifyObservers();
    }
}

From source file:com.android.mms.transaction.NotificationTransaction.java

public void sendNotifyRespInd(int status) {
    MmsLog.i(MmsApp.TXN_TAG, "NotificationTransaction: sendNotifyRespInd()");
    // Create the M-NotifyResp.ind
    NotifyRespInd notifyRespInd = null;//from   ww w.  j  a  v  a 2 s.co m
    try {
        notifyRespInd = new NotifyRespInd(PduHeaders.CURRENT_MMS_VERSION, mNotificationInd.getTransactionId(),
                status);
    } catch (InvalidHeaderValueException ex) {
        ex.printStackTrace();
        return;
    }

    /// M:Code analyze 014, this paragraph below is using for judging if it is allowed
    /// to send delivery report,at present,we don't support delivery report in MMS @{
    mOpNotificationTransactionExt.sendNotifyRespInd(mContext, mSubId, notifyRespInd);

    byte[] datas = new PduComposer(mContext, notifyRespInd).make();
    File pduFile = createPduFile(datas, NOTIFY_RESP_NAME + mUri.getLastPathSegment());
    if (pduFile == null) {
        return;
    }

    SmsManager manager = SmsManager.getSmsManagerForSubscriptionId(mSubId);
    /*
    Intent intent = new Intent(TransactionService.ACTION_TRANSACION_PROCESSED);
    intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, mSubId);
    // intent.putExtra(TransactionBundle.URI, mUri.toString());
    PendingIntent sentIntent = PendingIntent.getBroadcast(mContext, 0, intent,
        PendingIntent.FLAG_UPDATE_CURRENT);
        */
    // Pack M-NotifyResp.ind and send it
    Uri pduFileUri = FileProvider.getUriForFile(mContext, MMS_FILE_PROVIDER_AUTHORITIES, pduFile);
    if (MmsConfig.getNotifyWapMMSC()) {
        manager.sendMultimediaMessage(mContext, pduFileUri, mContentLocation, null, null);
    } else {
        manager.sendMultimediaMessage(mContext, pduFileUri, null, null, null);
    }
}

From source file:com.android.mms.transaction.RetrieveTransaction.java

private void sendNotifyRespInd(int status) {
    MmsLog.i(MmsApp.TXN_TAG, "RetrieveTransaction: sendNotifyRespInd()");
    // Create the M-NotifyResp.ind
    try {//from   w ww. j av  a 2 s  .  c o m
        NotificationInd notificationInd = (NotificationInd) PduPersister.getPduPersister(mContext).load(mUri);

        NotifyRespInd notifyRespInd = null;
        try {
            notifyRespInd = new NotifyRespInd(PduHeaders.CURRENT_MMS_VERSION,
                    notificationInd.getTransactionId(), status);
        } catch (InvalidHeaderValueException ex) {
            ex.printStackTrace();
            return;
        }
        byte[] datas = new PduComposer(mContext, notifyRespInd).make();
        File pduFile = createPduFile(datas, NOTIFY_RESP_NAME + mUri.getLastPathSegment());
        if (pduFile == null) {
            return;
        }

        SmsManager manager = SmsManager.getSmsManagerForSubscriptionId(mSubId);
        /*
        Intent intent = new Intent(TransactionService.ACTION_TRANSACION_PROCESSED);
        intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, mSubId);
        // intent.putExtra(TransactionBundle.URI, mUri.toString());
        PendingIntent sentIntent = PendingIntent.getBroadcast(mContext, 0, intent,
            PendingIntent.FLAG_UPDATE_CURRENT);
            */
        // Pack M-NotifyResp.ind and send it
        Uri pduFileUri = FileProvider.getUriForFile(mContext, MMS_FILE_PROVIDER_AUTHORITIES, pduFile);
        if (MmsConfig.getNotifyWapMMSC()) {
            manager.sendMultimediaMessage(mContext, pduFileUri, mContentLocation, null, null);
        } else {
            manager.sendMultimediaMessage(mContext, pduFileUri, null, null, null);
        }
    } catch (Throwable t) {
        Log.e(TAG, Log.getStackTraceString(t));
    }
}

From source file:com.android.mms.transaction.RetrieveTransaction.java

public void sendAcknowledgeInd() {
    if (mMessageUri == null) {
        MmsLog.w(MmsApp.TXN_TAG, "RetrieveTransaction: mMessageUri is null");
        return;// w  w  w. j a v  a 2s  .  c  om
    }
    // Send M-Acknowledge.ind to MMSC if required.
    // If the Transaction-ID isn't set in the M-Retrieve.conf, it means
    // the MMS proxy-relay doesn't require an ACK.
    MmsLog.i(MmsApp.TXN_TAG, "RetrieveTransaction: sendAcknowledgeInd()");
    try {
        Uri uri = Uri.parse(mMessageUri);
        PduPersister persister = PduPersister.getPduPersister(mContext);
        RetrieveConf retrieveConf = null;

        retrieveConf = (RetrieveConf) persister.load(uri);

        byte[] tranId = retrieveConf.getTransactionId();
        if (tranId != null) {
            // Create M-Acknowledge.ind
            AcknowledgeInd acknowledgeInd = new AcknowledgeInd(PduHeaders.CURRENT_MMS_VERSION, tranId);

            // insert the 'from' address per spec
            String lineNumber = MessageUtils.getLocalNumber(mSubId);
            if (lineNumber != null) {
                acknowledgeInd.setFrom(new EncodedStringValue(lineNumber));
            } else {
                MmsLog.d(MmsApp.TXN_TAG, "getLocalNumber(" + mSubId + "),return null");
            }

            /// M:Code analyze 012,add for new feature,judge if it is allowed
            /// to send delivery report for acknowledgeInd transaction @{
            /// M: modify for MmsPreference Plugin @{
            mOpRetrieveTransactionExt.sendAcknowledgeInd(mContext, mSubId, acknowledgeInd);
            /// @}

            byte[] datas = new PduComposer(mContext, acknowledgeInd).make();
            File pduFile = createPduFile(datas, ACK_RESP_NAME + mUri.getLastPathSegment());
            if (pduFile == null) {
                return;
            }

            SmsManager manager = SmsManager.getSmsManagerForSubscriptionId(mSubId);
            /*
            Intent intent = new Intent(TransactionService.ACTION_TRANSACION_PROCESSED);
            intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, mSubId);
            // intent.putExtra(TransactionBundle.URI, mUri.toString());
            PendingIntent sentIntent = PendingIntent.getBroadcast(mContext, 0, intent,
                PendingIntent.FLAG_UPDATE_CURRENT);
                */
            // Pack M-NotifyResp.ind and send it
            Uri pduFileUri = FileProvider.getUriForFile(mContext, MMS_FILE_PROVIDER_AUTHORITIES, pduFile);
            if (MmsConfig.getNotifyWapMMSC()) {
                manager.sendMultimediaMessage(mContext, pduFileUri, mContentLocation, null, null);
            } else {
                manager.sendMultimediaMessage(mContext, pduFileUri, null, null, null);
            }
        }
    } catch (MmsException ex) {
        ex.printStackTrace();
    }
}