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 37 /* 38 * Container for Launch Browser command settings. 39 */ 40 public class BrowserSettings { 41 public String url; 42 public LaunchBrowserMode mode; 43 } 44 45 /* 46 * Container for Call Setup command settings. 47 */ 48 public class CallSettings { 49 public TextMessage confirmMsg; 50 public TextMessage callMsg; 51 } 52 53 CatCmdMessage(CommandParams cmdParams) { 54 mCmdDet = cmdParams.cmdDet; 55 switch(getCmdType()) { 56 case SET_UP_MENU: 57 case SELECT_ITEM: 58 mMenu = ((SelectItemParams) cmdParams).menu; 59 break; 60 case DISPLAY_TEXT: 61 case SET_UP_IDLE_MODE_TEXT: 62 case SEND_DTMF: 63 case SEND_SMS: 64 case SEND_SS: 65 case SEND_USSD: 66 mTextMsg = ((DisplayTextParams) cmdParams).textMsg; 67 break; 68 case GET_INPUT: 69 case GET_INKEY: 70 mInput = ((GetInputParams) cmdParams).input; 71 break; 72 case LAUNCH_BROWSER: 73 mTextMsg = ((LaunchBrowserParams) cmdParams).confirmMsg; 74 mBrowserSettings = new BrowserSettings(); 75 mBrowserSettings.url = ((LaunchBrowserParams) cmdParams).url; 76 mBrowserSettings.mode = ((LaunchBrowserParams) cmdParams).mode; 77 break; 78 case PLAY_TONE: 79 PlayToneParams params = (PlayToneParams) cmdParams; 80 mToneSettings = params.settings; 81 mTextMsg = params.textMsg; 82 break; 83 case SET_UP_CALL: 84 mCallSettings = new CallSettings(); 85 mCallSettings.confirmMsg = ((CallSetupParams) cmdParams).confirmMsg; 86 mCallSettings.callMsg = ((CallSetupParams) cmdParams).callMsg; 87 break; 88 case OPEN_CHANNEL: 89 case CLOSE_CHANNEL: 90 case RECEIVE_DATA: 91 case SEND_DATA: 92 BIPClientParams param = (BIPClientParams) cmdParams; 93 mTextMsg = param.textMsg; 94 break; 95 } 96 } 97 98 public CatCmdMessage(Parcel in) { 99 mCmdDet = in.readParcelable(null); 100 mTextMsg = in.readParcelable(null); 101 mMenu = in.readParcelable(null); 102 mInput = in.readParcelable(null); 103 switch (getCmdType()) { 104 case LAUNCH_BROWSER: 105 mBrowserSettings = new BrowserSettings(); 106 mBrowserSettings.url = in.readString(); 107 mBrowserSettings.mode = LaunchBrowserMode.values()[in.readInt()]; 108 break; 109 case PLAY_TONE: 110 mToneSettings = in.readParcelable(null); 111 break; 112 case SET_UP_CALL: 113 mCallSettings = new CallSettings(); 114 mCallSettings.confirmMsg = in.readParcelable(null); 115 mCallSettings.callMsg = in.readParcelable(null); 116 break; 117 } 118 } 119 120 public void writeToParcel(Parcel dest, int flags) { 121 dest.writeParcelable(mCmdDet, 0); 122 dest.writeParcelable(mTextMsg, 0); 123 dest.writeParcelable(mMenu, 0); 124 dest.writeParcelable(mInput, 0); 125 switch(getCmdType()) { 126 case LAUNCH_BROWSER: 127 dest.writeString(mBrowserSettings.url); 128 dest.writeInt(mBrowserSettings.mode.ordinal()); 129 break; 130 case PLAY_TONE: 131 dest.writeParcelable(mToneSettings, 0); 132 break; 133 case SET_UP_CALL: 134 dest.writeParcelable(mCallSettings.confirmMsg, 0); 135 dest.writeParcelable(mCallSettings.callMsg, 0); 136 break; 137 } 138 } 139 140 public static final Parcelable.Creator<CatCmdMessage> CREATOR = new Parcelable.Creator<CatCmdMessage>() { 141 public CatCmdMessage createFromParcel(Parcel in) { 142 return new CatCmdMessage(in); 143 } 144 145 public CatCmdMessage[] newArray(int size) { 146 return new CatCmdMessage[size]; 147 } 148 }; 149 150 public int describeContents() { 151 return 0; 152 } 153 154 /* external API to be used by application */ 155 public AppInterface.CommandType getCmdType() { 156 return AppInterface.CommandType.fromInt(mCmdDet.typeOfCommand); 157 } 158 159 public Menu getMenu() { 160 return mMenu; 161 } 162 163 public Input geInput() { 164 return mInput; 165 } 166 167 public TextMessage geTextMessage() { 168 return mTextMsg; 169 } 170 171 public BrowserSettings getBrowserSettings() { 172 return mBrowserSettings; 173 } 174 175 public ToneSettings getToneSettings() { 176 return mToneSettings; 177 } 178 179 public CallSettings getCallSettings() { 180 return mCallSettings; 181 } 182 } 183