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 17 package com.android.internal.telephony.cat; 18 19 import android.os.Parcel; 20 import android.os.Parcelable; 21 22 /** 23 * Class used to pass CAT messages from telephony to application. Application 24 * should call getXXX() to get commands's specific values. 25 * 26 */ 27 public class CatCmdMessage implements Parcelable { 28 // members 29 CommandDetails mCmdDet; 30 private TextMessage mTextMsg; 31 private Menu mMenu; 32 private Input mInput; 33 private BrowserSettings mBrowserSettings = null; 34 private ToneSettings mToneSettings = null; 35 private CallSettings mCallSettings = null; 36 private SetupEventListSettings mSetupEventListSettings = null; 37 38 39 /* 40 * Container for Launch Browser command settings. 41 */ 42 public class BrowserSettings { 43 public String url; 44 public LaunchBrowserMode mode; 45 } 46 47 /* 48 * Container for Call Setup command settings. 49 */ 50 public class CallSettings { 51 public TextMessage confirmMsg; 52 public TextMessage callMsg; 53 } 54 55 public class SetupEventListSettings { 56 public int[] eventList; 57 } 58 59 public final class SetupEventListConstants { 60 // Event values in SETUP_EVENT_LIST Proactive Command as per ETSI 102.223 61 public static final int USER_ACTIVITY_EVENT = 0x04; 62 public static final int IDLE_SCREEN_AVAILABLE_EVENT = 0x05; 63 public static final int LANGUAGE_SELECTION_EVENT = 0x07; 64 public static final int BROWSER_TERMINATION_EVENT = 0x08; 65 public static final int BROWSING_STATUS_EVENT = 0x0F; 66 } 67 68 public final class BrowserTerminationCauses { 69 public static final int USER_TERMINATION = 0x00; 70 public static final int ERROR_TERMINATION = 0x01; 71 } 72 73 CatCmdMessage(CommandParams cmdParams) { 74 mCmdDet = cmdParams.mCmdDet; 75 switch(getCmdType()) { 76 case SET_UP_MENU: 77 case SELECT_ITEM: 78 mMenu = ((SelectItemParams) cmdParams).mMenu; 79 break; 80 case DISPLAY_TEXT: 81 case SET_UP_IDLE_MODE_TEXT: 82 case SEND_DTMF: 83 case SEND_SMS: 84 case SEND_SS: 85 case SEND_USSD: 86 mTextMsg = ((DisplayTextParams) cmdParams).mTextMsg; 87 break; 88 case GET_INPUT: 89 case GET_INKEY: 90 mInput = ((GetInputParams) cmdParams).mInput; 91 break; 92 case LAUNCH_BROWSER: 93 mTextMsg = ((LaunchBrowserParams) cmdParams).mConfirmMsg; 94 mBrowserSettings = new BrowserSettings(); 95 mBrowserSettings.url = ((LaunchBrowserParams) cmdParams).mUrl; 96 mBrowserSettings.mode = ((LaunchBrowserParams) cmdParams).mMode; 97 break; 98 case PLAY_TONE: 99 PlayToneParams params = (PlayToneParams) cmdParams; 100 mToneSettings = params.mSettings; 101 mTextMsg = params.mTextMsg; 102 break; 103 case GET_CHANNEL_STATUS: 104 mTextMsg = ((CallSetupParams) cmdParams).mConfirmMsg; 105 break; 106 case SET_UP_CALL: 107 mCallSettings = new CallSettings(); 108 mCallSettings.confirmMsg = ((CallSetupParams) cmdParams).mConfirmMsg; 109 mCallSettings.callMsg = ((CallSetupParams) cmdParams).mCallMsg; 110 break; 111 case OPEN_CHANNEL: 112 case CLOSE_CHANNEL: 113 case RECEIVE_DATA: 114 case SEND_DATA: 115 BIPClientParams param = (BIPClientParams) cmdParams; 116 mTextMsg = param.mTextMsg; 117 break; 118 case SET_UP_EVENT_LIST: 119 mSetupEventListSettings = new SetupEventListSettings(); 120 mSetupEventListSettings.eventList = ((SetEventListParams) cmdParams).mEventInfo; 121 break; 122 case PROVIDE_LOCAL_INFORMATION: 123 case REFRESH: 124 default: 125 break; 126 } 127 } 128 129 public CatCmdMessage(Parcel in) { 130 mCmdDet = in.readParcelable(null); 131 mTextMsg = in.readParcelable(null); 132 mMenu = in.readParcelable(null); 133 mInput = in.readParcelable(null); 134 switch (getCmdType()) { 135 case LAUNCH_BROWSER: 136 mBrowserSettings = new BrowserSettings(); 137 mBrowserSettings.url = in.readString(); 138 mBrowserSettings.mode = LaunchBrowserMode.values()[in.readInt()]; 139 break; 140 case PLAY_TONE: 141 mToneSettings = in.readParcelable(null); 142 break; 143 case SET_UP_CALL: 144 mCallSettings = new CallSettings(); 145 mCallSettings.confirmMsg = in.readParcelable(null); 146 mCallSettings.callMsg = in.readParcelable(null); 147 break; 148 case SET_UP_EVENT_LIST: 149 mSetupEventListSettings = new SetupEventListSettings(); 150 int length = in.readInt(); 151 mSetupEventListSettings.eventList = new int[length]; 152 for (int i = 0; i < length; i++) { 153 mSetupEventListSettings.eventList[i] = in.readInt(); 154 } 155 break; 156 default: 157 break; 158 } 159 } 160 161 @Override 162 public void writeToParcel(Parcel dest, int flags) { 163 dest.writeParcelable(mCmdDet, 0); 164 dest.writeParcelable(mTextMsg, 0); 165 dest.writeParcelable(mMenu, 0); 166 dest.writeParcelable(mInput, 0); 167 switch(getCmdType()) { 168 case LAUNCH_BROWSER: 169 dest.writeString(mBrowserSettings.url); 170 dest.writeInt(mBrowserSettings.mode.ordinal()); 171 break; 172 case PLAY_TONE: 173 dest.writeParcelable(mToneSettings, 0); 174 break; 175 case SET_UP_CALL: 176 dest.writeParcelable(mCallSettings.confirmMsg, 0); 177 dest.writeParcelable(mCallSettings.callMsg, 0); 178 break; 179 case SET_UP_EVENT_LIST: 180 dest.writeIntArray(mSetupEventListSettings.eventList); 181 break; 182 default: 183 break; 184 } 185 } 186 187 public static final Parcelable.Creator<CatCmdMessage> CREATOR = new Parcelable.Creator<CatCmdMessage>() { 188 @Override 189 public CatCmdMessage createFromParcel(Parcel in) { 190 return new CatCmdMessage(in); 191 } 192 193 @Override 194 public CatCmdMessage[] newArray(int size) { 195 return new CatCmdMessage[size]; 196 } 197 }; 198 199 @Override 200 public int describeContents() { 201 return 0; 202 } 203 204 /* external API to be used by application */ 205 public AppInterface.CommandType getCmdType() { 206 return AppInterface.CommandType.fromInt(mCmdDet.typeOfCommand); 207 } 208 209 public Menu getMenu() { 210 return mMenu; 211 } 212 213 public Input geInput() { 214 return mInput; 215 } 216 217 public TextMessage geTextMessage() { 218 return mTextMsg; 219 } 220 221 public BrowserSettings getBrowserSettings() { 222 return mBrowserSettings; 223 } 224 225 public ToneSettings getToneSettings() { 226 return mToneSettings; 227 } 228 229 public CallSettings getCallSettings() { 230 return mCallSettings; 231 } 232 233 public SetupEventListSettings getSetEventList() { 234 return mSetupEventListSettings; 235 } 236 } 237