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 import com.android.internal.telephony.uicc.IccUtils;
23 
24 /**
25  * A wrapper around the Bundle instances used to start the TransactionService.
26  * It provides high-level APIs to set the information required for the latter to
27  * instantiate transactions.
28  */
29 public class TransactionBundle {
30     /**
31      * Key for the transaction-type.
32      * Allowed values for this key are: TYPE_PUSH_TRANSACTION, TYPE_RETRIEVE_TRANSACTION,
33      * TYPE_SEND_TRANSACTION, and TYPE_READREC_TRANSACTION.
34      */
35     public static final String TRANSACTION_TYPE = "type";
36 
37     /**
38      * Key of the push-data.
39      * Used when TRANSACTION_TYPE is TYPE_PUSH_TRANSACTION.
40      */
41     private static final String PUSH_DATA = "mms-push-data";
42 
43     /**
44      * Key of the MMSC server URL.
45      */
46     private static final String MMSC_URL = "mmsc-url";
47 
48     /**
49      * Key of the HTTP Proxy address.
50      */
51     private static final String PROXY_ADDRESS = "proxy-address";
52 
53     /**
54      * Key of the HTTP Proxy port.
55      */
56     private static final String PROXY_PORT = "proxy-port";
57 
58     /**
59      * Key of the URI.
60      * Indicates the URL of the M-Retrieve.conf in TYPE_RETRIEVE_TRANSACTION, or the
61      * Uri of the M-Send.req/M-Read-Rec.ind in TYPE_SEND_TRANSACTION and
62      * TYPE_READREC_TRANSACTION, respectively.
63      */
64     public static final String URI = "uri";
65 
66     /**
67      * This is the real Bundle to be sent to the TransactionService upon calling
68      * startService.
69      */
70     private final Bundle mBundle;
71 
72     /**
73      * Private constructor.
74      *
75      * @param transactionType
76      */
TransactionBundle(int transactionType)77     private TransactionBundle(int transactionType) {
78         mBundle = new Bundle();
79         mBundle.putInt(TRANSACTION_TYPE, transactionType);
80     }
81 
82     /**
83      * Constructor of a bundle used for TransactionBundle instances of type
84      * TYPE_RETRIEVE_TRANSACTION, TYPE_SEND_TRANSACTION, and TYPE_READREC_TRANSACTION.
85      *
86      * @param transactionType
87      * @param uri The relevant URI for this transaction. Indicates the URL of the
88      * M-Retrieve.conf in TYPE_RETRIEVE_TRANSACTION, or the Uri of the
89      * M-Send.req/M-Read-Rec.ind in TYPE_SEND_TRANSACTION and
90      * TYPE_READREC_TRANSACTION, respectively.
91      */
TransactionBundle(int transactionType, String uri)92     public TransactionBundle(int transactionType, String uri) {
93         this(transactionType);
94         mBundle.putString(URI, uri);
95     }
96 
97     /**
98      * Constructor of a transaction bundle used for incoming bundle instances.
99      *
100      * @param bundle The incoming bundle
101      */
TransactionBundle(Bundle bundle)102     public TransactionBundle(Bundle bundle) {
103         mBundle = bundle;
104     }
105 
setConnectionSettings(String mmscUrl, String proxyAddress, int proxyPort)106     public void setConnectionSettings(String mmscUrl,
107             String proxyAddress,
108             int proxyPort) {
109         mBundle.putString(MMSC_URL, mmscUrl);
110         mBundle.putString(PROXY_ADDRESS, proxyAddress);
111         mBundle.putInt(PROXY_PORT, proxyPort);
112     }
113 
setConnectionSettings(TransactionSettings settings)114     public void setConnectionSettings(TransactionSettings settings) {
115         setConnectionSettings(
116                 settings.getMmscUrl(),
117                 settings.getProxyAddress(),
118                 settings.getProxyPort());
119     }
120 
getBundle()121     public Bundle getBundle() {
122         return mBundle;
123     }
124 
getTransactionType()125     public int getTransactionType() {
126         return mBundle.getInt(TRANSACTION_TYPE);
127     }
128 
getUri()129     public String getUri() {
130         return mBundle.getString(URI);
131     }
132 
getPushData()133     public byte[] getPushData() {
134         return mBundle.getByteArray(PUSH_DATA);
135     }
136 
getMmscUrl()137     public String getMmscUrl() {
138         return mBundle.getString(MMSC_URL);
139     }
140 
getProxyAddress()141     public String getProxyAddress() {
142         return mBundle.getString(PROXY_ADDRESS);
143     }
144 
getProxyPort()145     public int getProxyPort() {
146         return mBundle.getInt(PROXY_PORT);
147     }
148 
149     @Override
toString()150     public String toString() {
151         return "transactionType: " + getTransactionType() +
152             " uri: " + getUri() +
153             " pushData: " + IccUtils.bytesToHexString(getPushData()) +
154             " mmscUrl: " + getMmscUrl() +
155             " proxyAddress: " + getProxyAddress() +
156             " proxyPort: " + getProxyPort();
157     }
158 }
159