1/*
2 * Copyright (C) 2007 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.internal.telephony.cat;
18
19import android.graphics.Bitmap;
20
21/**
22 * Container class for proactive command parameters.
23 *
24 */
25class CommandParams {
26    CommandDetails mCmdDet;
27
28    CommandParams(CommandDetails cmdDet) {
29        mCmdDet = cmdDet;
30    }
31
32    AppInterface.CommandType getCommandType() {
33        return AppInterface.CommandType.fromInt(mCmdDet.typeOfCommand);
34    }
35
36    boolean setIcon(Bitmap icon) { return true; }
37
38    @Override
39    public String toString() {
40        return mCmdDet.toString();
41    }
42}
43
44class DisplayTextParams extends CommandParams {
45    TextMessage mTextMsg;
46
47    DisplayTextParams(CommandDetails cmdDet, TextMessage textMsg) {
48        super(cmdDet);
49        mTextMsg = textMsg;
50    }
51
52    @Override
53    boolean setIcon(Bitmap icon) {
54        if (icon != null && mTextMsg != null) {
55            mTextMsg.icon = icon;
56            return true;
57        }
58        return false;
59    }
60
61    @Override
62    public String toString() {
63        return "TextMessage=" + mTextMsg + " " + super.toString();
64    }
65}
66
67class LaunchBrowserParams extends CommandParams {
68    TextMessage mConfirmMsg;
69    LaunchBrowserMode mMode;
70    String mUrl;
71
72    LaunchBrowserParams(CommandDetails cmdDet, TextMessage confirmMsg,
73            String url, LaunchBrowserMode mode) {
74        super(cmdDet);
75        mConfirmMsg = confirmMsg;
76        mMode = mode;
77        mUrl = url;
78    }
79
80    @Override
81    boolean setIcon(Bitmap icon) {
82        if (icon != null && mConfirmMsg != null) {
83            mConfirmMsg.icon = icon;
84            return true;
85        }
86        return false;
87    }
88
89    @Override
90    public String toString() {
91        return "TextMessage=" + mConfirmMsg + " " + super.toString();
92    }
93}
94
95class SetEventListParams extends CommandParams {
96    int[] mEventInfo;
97    SetEventListParams(CommandDetails cmdDet, int[] eventInfo) {
98        super(cmdDet);
99        this.mEventInfo = eventInfo;
100    }
101}
102
103class PlayToneParams extends CommandParams {
104    TextMessage mTextMsg;
105    ToneSettings mSettings;
106
107    PlayToneParams(CommandDetails cmdDet, TextMessage textMsg,
108            Tone tone, Duration duration, boolean vibrate) {
109        super(cmdDet);
110        mTextMsg = textMsg;
111        mSettings = new ToneSettings(duration, tone, vibrate);
112    }
113
114    @Override
115    boolean setIcon(Bitmap icon) {
116        if (icon != null && mTextMsg != null) {
117            mTextMsg.icon = icon;
118            return true;
119        }
120        return false;
121    }
122}
123
124class CallSetupParams extends CommandParams {
125    TextMessage mConfirmMsg;
126    TextMessage mCallMsg;
127
128    CallSetupParams(CommandDetails cmdDet, TextMessage confirmMsg,
129            TextMessage callMsg) {
130        super(cmdDet);
131        mConfirmMsg = confirmMsg;
132        mCallMsg = callMsg;
133    }
134
135    @Override
136    boolean setIcon(Bitmap icon) {
137        if (icon == null) {
138            return false;
139        }
140        if (mConfirmMsg != null && mConfirmMsg.icon == null) {
141            mConfirmMsg.icon = icon;
142            return true;
143        } else if (mCallMsg != null && mCallMsg.icon == null) {
144            mCallMsg.icon = icon;
145            return true;
146        }
147        return false;
148    }
149}
150
151class SelectItemParams extends CommandParams {
152    Menu mMenu = null;
153    boolean mLoadTitleIcon = false;
154
155    SelectItemParams(CommandDetails cmdDet, Menu menu, boolean loadTitleIcon) {
156        super(cmdDet);
157        mMenu = menu;
158        mLoadTitleIcon = loadTitleIcon;
159    }
160
161    @Override
162    boolean setIcon(Bitmap icon) {
163        if (icon != null && mMenu != null) {
164            if (mLoadTitleIcon && mMenu.titleIcon == null) {
165                mMenu.titleIcon = icon;
166            } else {
167                for (Item item : mMenu.items) {
168                    if (item.icon != null) {
169                        continue;
170                    }
171                    item.icon = icon;
172                    break;
173                }
174            }
175            return true;
176        }
177        return false;
178    }
179}
180
181class GetInputParams extends CommandParams {
182    Input mInput = null;
183
184    GetInputParams(CommandDetails cmdDet, Input input) {
185        super(cmdDet);
186        mInput = input;
187    }
188
189    @Override
190    boolean setIcon(Bitmap icon) {
191        if (icon != null && mInput != null) {
192            mInput.icon = icon;
193        }
194        return true;
195    }
196}
197
198/*
199 * BIP (Bearer Independent Protocol) is the mechanism for SIM card applications
200 * to access data connection through the mobile device.
201 *
202 * SIM utilizes proactive commands (OPEN CHANNEL, CLOSE CHANNEL, SEND DATA and
203 * RECEIVE DATA to control/read/write data for BIP. Refer to ETSI TS 102 223 for
204 * the details of proactive commands procedures and their structures.
205 */
206class BIPClientParams extends CommandParams {
207    TextMessage mTextMsg;
208    boolean mHasAlphaId;
209
210    BIPClientParams(CommandDetails cmdDet, TextMessage textMsg, boolean has_alpha_id) {
211        super(cmdDet);
212        mTextMsg = textMsg;
213        mHasAlphaId = has_alpha_id;
214    }
215
216    @Override
217    boolean setIcon(Bitmap icon) {
218        if (icon != null && mTextMsg != null) {
219            mTextMsg.icon = icon;
220            return true;
221        }
222        return false;
223    }
224}
225