FileDocCategorySizeDatePackage
Transaction.javaAPI DocAndroid 1.5 API8124Wed May 06 22:42:46 BST 2009com.android.mms.transaction

Transaction

public abstract class Transaction extends Observable
Transaction is an abstract class for notification transaction, send transaction and other transactions described in MMS spec. It provides the interfaces of them and some common methods for them.

Fields Summary
private final int
mServiceId
protected android.content.Context
mContext
protected String
mId
protected TransactionState
mTransactionState
protected TransactionSettings
mTransactionSettings
public static final int
NOTIFICATION_TRANSACTION
Identifies push requests.
public static final int
RETRIEVE_TRANSACTION
Identifies deferred retrieve requests.
public static final int
SEND_TRANSACTION
Identifies send multimedia message requests.
public static final int
READREC_TRANSACTION
Identifies send read report requests.
Constructors Summary
public Transaction(android.content.Context context, int serviceId, TransactionSettings settings)


        
              
        mContext = context;
        mTransactionState = new TransactionState();
        mServiceId = serviceId;
        mTransactionSettings = settings;
    
Methods Summary
private voidensureRouteToHost(java.lang.String url, TransactionSettings settings)
Make sure that a network route exists to allow us to reach the host in the supplied URL, and to the MMS proxy host as well, if a proxy is used.

param
url The URL of the MMSC to which we need a route
param
settings Specifies the address of the proxy host, if any
throws
IOException if the host doesn't exist, or adding the route fails.

        ConnectivityManager connMgr =
                (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE);

        int inetAddr;
        if (settings.isProxySet()) {
            String proxyAddr = settings.getProxyAddress();
            inetAddr = NetworkUtils.lookupHost(proxyAddr);
            if (inetAddr == -1) {
                throw new IOException("Cannot establish route for " + url + ": Unknown host");
            } else {
                if (!connMgr.requestRouteToHost(ConnectivityManager.TYPE_MOBILE, inetAddr)) {
                    throw new IOException("Cannot establish route to proxy " + inetAddr);
                }
            }
        } else {
            Uri uri = Uri.parse(url);
            inetAddr = NetworkUtils.lookupHost(uri.getHost());
            if (inetAddr == -1) {
                throw new IOException("Cannot establish route for " + url + ": Unknown host");
            } else {
                if (!connMgr.requestRouteToHost(ConnectivityManager.TYPE_MOBILE, inetAddr)) {
                    throw new IOException("Cannot establish route to " + inetAddr + " for " + url);
                }
            }
        }
    
public TransactionSettingsgetConnectionSettings()

        return mTransactionSettings;
    
protected byte[]getPdu(java.lang.String url)
A common method to retrieve a PDU from MMSC.

param
url The URL of the message which we are going to retrieve.
return
A byte array which contains the data of the PDU. If the status code is not correct, an IOException will be thrown.
throws
IOException if any error occurred on network interface or an HTTP error code(>=400) returned from the server.

        ensureRouteToHost(url, mTransactionSettings);
        return HttpUtils.httpConnection(
                mContext, SendingProgressTokenManager.NO_TOKEN,
                url, null, HttpUtils.HTTP_GET_METHOD,
                mTransactionSettings.isProxySet(),
                mTransactionSettings.getProxyAddress(),
                mTransactionSettings.getProxyPort());
    
public intgetServiceId()
Get the service-id of this transaction which was assigned by the framework.

return
the service-id of the transaction

        return mServiceId;
    
public TransactionStategetState()
Returns the transaction state of this transaction.

return
Current state of the Transaction.

        return mTransactionState;
    
public abstract intgetType()
Get the type of the transaction.

return
Transaction type in integer.

public booleanisEquivalent(com.android.mms.transaction.Transaction transaction)
Used to determine whether a transaction is equivalent to this instance.

param
transaction the transaction which is compared to this instance.
return
true if transaction is equivalent to this instance, false otherwise.

        return getClass().equals(transaction.getClass())
                && mId.equals(transaction.mId);
    
public abstract voidprocess()
An instance of Transaction encapsulates the actions required during a MMS Client transaction.

protected byte[]sendPdu(byte[] pdu)
A common method to send a PDU to MMSC.

param
pdu A byte array which contains the data of the PDU.
return
A byte array which contains the response data. If an HTTP error code is returned, an IOException will be thrown.
throws
IOException if any error occurred on network interface or an HTTP error code(>=400) returned from the server.

        String mmscUrl = mTransactionSettings.getMmscUrl();
        ensureRouteToHost(mmscUrl, mTransactionSettings);
        return HttpUtils.httpConnection(
                mContext, SendingProgressTokenManager.NO_TOKEN,
                mmscUrl,
                pdu, HttpUtils.HTTP_POST_METHOD,
                mTransactionSettings.isProxySet(),
                mTransactionSettings.getProxyAddress(),
                mTransactionSettings.getProxyPort());
    
protected byte[]sendPdu(long token, byte[] pdu)
A common method to send a PDU to MMSC.

param
token The token to identify the sending progress.
param
pdu A byte array which contains the data of the PDU.
return
A byte array which contains the response data. If an HTTP error code is returned, an IOException will be thrown.
throws
IOException if any error occurred on network interface or an HTTP error code(>=400) returned from the server.

        String mmscUrl = mTransactionSettings.getMmscUrl();
        ensureRouteToHost(mmscUrl, mTransactionSettings);
        return HttpUtils.httpConnection(
                mContext, token,
                mmscUrl,
                pdu, HttpUtils.HTTP_POST_METHOD,
                mTransactionSettings.isProxySet(),
                mTransactionSettings.getProxyAddress(),
                mTransactionSettings.getProxyPort());
    
public voidsetConnectionSettings(TransactionSettings settings)

        mTransactionSettings = settings;
    
public java.lang.StringtoString()

        return getClass().getName() + ": serviceId=" + mServiceId;