1 /* 2 * Copyright (C) 2007-2008 Esmertec AG. 3 * Copyright (C) 2007-2008 The Android Open Source Project 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18 package com.android.mms.transaction; 19 20 import android.os.Bundle; 21 22 /** 23 * A wrapper around the Bundle instances used to start the TransactionService. 24 * It provides high-level APIs to set the information required for the latter to 25 * instantiate transactions. 26 */ 27 public class TransactionBundle { 28 /** 29 * Key for the transaction-type. 30 * Allowed values for this key are: TYPE_PUSH_TRANSACTION, TYPE_RETRIEVE_TRANSACTION, 31 * TYPE_SEND_TRANSACTION, and TYPE_READREC_TRANSACTION. 32 */ 33 public static final String TRANSACTION_TYPE = "type"; 34 35 /** 36 * Key of the push-data. 37 * Used when TRANSACTION_TYPE is TYPE_PUSH_TRANSACTION. 38 */ 39 private static final String PUSH_DATA = "mms-push-data"; 40 41 /** 42 * Key of the MMSC server URL. 43 */ 44 private static final String MMSC_URL = "mmsc-url"; 45 46 /** 47 * Key of the HTTP Proxy address. 48 */ 49 private static final String PROXY_ADDRESS = "proxy-address"; 50 51 /** 52 * Key of the HTTP Proxy port. 53 */ 54 private static final String PROXY_PORT = "proxy-port"; 55 56 /** 57 * Key of the URI. 58 * Indicates the URL of the M-Retrieve.conf in TYPE_RETRIEVE_TRANSACTION, or the 59 * Uri of the M-Send.req/M-Read-Rec.ind in TYPE_SEND_TRANSACTION and 60 * TYPE_READREC_TRANSACTION, respectively. 61 */ 62 public static final String URI = "uri"; 63 64 /** 65 * This is the real Bundle to be sent to the TransactionService upon calling 66 * startService. 67 */ 68 private final Bundle mBundle; 69 70 /** 71 * Private constructor. 72 * 73 * @param transactionType 74 */ TransactionBundle(int transactionType)75 private TransactionBundle(int transactionType) { 76 mBundle = new Bundle(); 77 mBundle.putInt(TRANSACTION_TYPE, transactionType); 78 } 79 80 /** 81 * Constructor of a bundle used for TransactionBundle instances of type 82 * TYPE_RETRIEVE_TRANSACTION, TYPE_SEND_TRANSACTION, and TYPE_READREC_TRANSACTION. 83 * 84 * @param transactionType 85 * @param uri The relevant URI for this transaction. Indicates the URL of the 86 * M-Retrieve.conf in TYPE_RETRIEVE_TRANSACTION, or the Uri of the 87 * M-Send.req/M-Read-Rec.ind in TYPE_SEND_TRANSACTION and 88 * TYPE_READREC_TRANSACTION, respectively. 89 */ TransactionBundle(int transactionType, String uri)90 public TransactionBundle(int transactionType, String uri) { 91 this(transactionType); 92 mBundle.putString(URI, uri); 93 } 94 95 /** 96 * Constructor of a transaction bundle used for incoming bundle instances. 97 * 98 * @param bundle The incoming bundle 99 */ TransactionBundle(Bundle bundle)100 public TransactionBundle(Bundle bundle) { 101 mBundle = bundle; 102 } 103 setConnectionSettings(String mmscUrl, String proxyAddress, int proxyPort)104 public void setConnectionSettings(String mmscUrl, 105 String proxyAddress, 106 int proxyPort) { 107 mBundle.putString(MMSC_URL, mmscUrl); 108 mBundle.putString(PROXY_ADDRESS, proxyAddress); 109 mBundle.putInt(PROXY_PORT, proxyPort); 110 } 111 setConnectionSettings(TransactionSettings settings)112 public void setConnectionSettings(TransactionSettings settings) { 113 setConnectionSettings( 114 settings.getMmscUrl(), 115 settings.getProxyAddress(), 116 settings.getProxyPort()); 117 } 118 getBundle()119 public Bundle getBundle() { 120 return mBundle; 121 } 122 getTransactionType()123 public int getTransactionType() { 124 return mBundle.getInt(TRANSACTION_TYPE); 125 } 126 getUri()127 public String getUri() { 128 return mBundle.getString(URI); 129 } 130 getPushData()131 public byte[] getPushData() { 132 return mBundle.getByteArray(PUSH_DATA); 133 } 134 getMmscUrl()135 public String getMmscUrl() { 136 return mBundle.getString(MMSC_URL); 137 } 138 getProxyAddress()139 public String getProxyAddress() { 140 return mBundle.getString(PROXY_ADDRESS); 141 } 142 getProxyPort()143 public int getProxyPort() { 144 return mBundle.getInt(PROXY_PORT); 145 } 146 147 @Override toString()148 public String toString() { 149 return "transactionType: " + getTransactionType() + 150 " uri: " + getUri() + 151 " pushData: " + getPushData() + 152 " mmscUrl: " + getMmscUrl() + 153 " proxyAddress: " + getProxyAddress() + 154 " proxyPort: " + getProxyPort(); 155 } 156 } 157