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