Home | History | Annotate | Download | only in cat
      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.mCmdDet;
     55         switch(getCmdType()) {
     56         case SET_UP_MENU:
     57         case SELECT_ITEM:
     58             mMenu = ((SelectItemParams) cmdParams).mMenu;
     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).mTextMsg;
     67             break;
     68         case GET_INPUT:
     69         case GET_INKEY:
     70             mInput = ((GetInputParams) cmdParams).mInput;
     71             break;
     72         case LAUNCH_BROWSER:
     73             mTextMsg = ((LaunchBrowserParams) cmdParams).mConfirmMsg;
     74             mBrowserSettings = new BrowserSettings();
     75             mBrowserSettings.url = ((LaunchBrowserParams) cmdParams).mUrl;
     76             mBrowserSettings.mode = ((LaunchBrowserParams) cmdParams).mMode;
     77             break;
     78         case PLAY_TONE:
     79             PlayToneParams params = (PlayToneParams) cmdParams;
     80             mToneSettings = params.mSettings;
     81             mTextMsg = params.mTextMsg;
     82             break;
     83         case GET_CHANNEL_STATUS:
     84             mTextMsg = ((CallSetupParams) cmdParams).mConfirmMsg;
     85             break;
     86         case SET_UP_CALL:
     87             mCallSettings = new CallSettings();
     88             mCallSettings.confirmMsg = ((CallSetupParams) cmdParams).mConfirmMsg;
     89             mCallSettings.callMsg = ((CallSetupParams) cmdParams).mCallMsg;
     90             break;
     91         case OPEN_CHANNEL:
     92         case CLOSE_CHANNEL:
     93         case RECEIVE_DATA:
     94         case SEND_DATA:
     95             BIPClientParams param = (BIPClientParams) cmdParams;
     96             mTextMsg = param.mTextMsg;
     97             break;
     98         case PROVIDE_LOCAL_INFORMATION:
     99         case REFRESH:
    100         case SET_UP_EVENT_LIST:
    101         default:
    102             break;
    103         }
    104     }
    105 
    106     public CatCmdMessage(Parcel in) {
    107         mCmdDet = in.readParcelable(null);
    108         mTextMsg = in.readParcelable(null);
    109         mMenu = in.readParcelable(null);
    110         mInput = in.readParcelable(null);
    111         switch (getCmdType()) {
    112         case LAUNCH_BROWSER:
    113             mBrowserSettings = new BrowserSettings();
    114             mBrowserSettings.url = in.readString();
    115             mBrowserSettings.mode = LaunchBrowserMode.values()[in.readInt()];
    116             break;
    117         case PLAY_TONE:
    118             mToneSettings = in.readParcelable(null);
    119             break;
    120         case SET_UP_CALL:
    121             mCallSettings = new CallSettings();
    122             mCallSettings.confirmMsg = in.readParcelable(null);
    123             mCallSettings.callMsg = in.readParcelable(null);
    124             break;
    125         default:
    126             break;
    127         }
    128     }
    129 
    130     @Override
    131     public void writeToParcel(Parcel dest, int flags) {
    132         dest.writeParcelable(mCmdDet, 0);
    133         dest.writeParcelable(mTextMsg, 0);
    134         dest.writeParcelable(mMenu, 0);
    135         dest.writeParcelable(mInput, 0);
    136         switch(getCmdType()) {
    137         case LAUNCH_BROWSER:
    138             dest.writeString(mBrowserSettings.url);
    139             dest.writeInt(mBrowserSettings.mode.ordinal());
    140             break;
    141         case PLAY_TONE:
    142             dest.writeParcelable(mToneSettings, 0);
    143             break;
    144         case SET_UP_CALL:
    145             dest.writeParcelable(mCallSettings.confirmMsg, 0);
    146             dest.writeParcelable(mCallSettings.callMsg, 0);
    147             break;
    148         default:
    149             break;
    150         }
    151     }
    152 
    153     public static final Parcelable.Creator<CatCmdMessage> CREATOR = new Parcelable.Creator<CatCmdMessage>() {
    154         @Override
    155         public CatCmdMessage createFromParcel(Parcel in) {
    156             return new CatCmdMessage(in);
    157         }
    158 
    159         @Override
    160         public CatCmdMessage[] newArray(int size) {
    161             return new CatCmdMessage[size];
    162         }
    163     };
    164 
    165     @Override
    166     public int describeContents() {
    167         return 0;
    168     }
    169 
    170     /* external API to be used by application */
    171     public AppInterface.CommandType getCmdType() {
    172         return AppInterface.CommandType.fromInt(mCmdDet.typeOfCommand);
    173     }
    174 
    175     public Menu getMenu() {
    176         return mMenu;
    177     }
    178 
    179     public Input geInput() {
    180         return mInput;
    181     }
    182 
    183     public TextMessage geTextMessage() {
    184         return mTextMsg;
    185     }
    186 
    187     public BrowserSettings getBrowserSettings() {
    188         return mBrowserSettings;
    189     }
    190 
    191     public ToneSettings getToneSettings() {
    192         return mToneSettings;
    193     }
    194 
    195     public CallSettings getCallSettings() {
    196         return mCallSettings;
    197     }
    198 }
    199