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.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         }
     89     }
     90 
     91     public CatCmdMessage(Parcel in) {
     92         mCmdDet = in.readParcelable(null);
     93         mTextMsg = in.readParcelable(null);
     94         mMenu = in.readParcelable(null);
     95         mInput = in.readParcelable(null);
     96         switch (getCmdType()) {
     97         case LAUNCH_BROWSER:
     98             mBrowserSettings = new BrowserSettings();
     99             mBrowserSettings.url = in.readString();
    100             mBrowserSettings.mode = LaunchBrowserMode.values()[in.readInt()];
    101             break;
    102         case PLAY_TONE:
    103             mToneSettings = in.readParcelable(null);
    104             break;
    105         case SET_UP_CALL:
    106             mCallSettings = new CallSettings();
    107             mCallSettings.confirmMsg = in.readParcelable(null);
    108             mCallSettings.callMsg = in.readParcelable(null);
    109             break;
    110         }
    111     }
    112 
    113     public void writeToParcel(Parcel dest, int flags) {
    114         dest.writeParcelable(mCmdDet, 0);
    115         dest.writeParcelable(mTextMsg, 0);
    116         dest.writeParcelable(mMenu, 0);
    117         dest.writeParcelable(mInput, 0);
    118         switch(getCmdType()) {
    119         case LAUNCH_BROWSER:
    120             dest.writeString(mBrowserSettings.url);
    121             dest.writeInt(mBrowserSettings.mode.ordinal());
    122             break;
    123         case PLAY_TONE:
    124             dest.writeParcelable(mToneSettings, 0);
    125             break;
    126         case SET_UP_CALL:
    127             dest.writeParcelable(mCallSettings.confirmMsg, 0);
    128             dest.writeParcelable(mCallSettings.callMsg, 0);
    129             break;
    130         }
    131     }
    132 
    133     public static final Parcelable.Creator<CatCmdMessage> CREATOR = new Parcelable.Creator<CatCmdMessage>() {
    134         public CatCmdMessage createFromParcel(Parcel in) {
    135             return new CatCmdMessage(in);
    136         }
    137 
    138         public CatCmdMessage[] newArray(int size) {
    139             return new CatCmdMessage[size];
    140         }
    141     };
    142 
    143     public int describeContents() {
    144         return 0;
    145     }
    146 
    147     /* external API to be used by application */
    148     public AppInterface.CommandType getCmdType() {
    149         return AppInterface.CommandType.fromInt(mCmdDet.typeOfCommand);
    150     }
    151 
    152     public Menu getMenu() {
    153         return mMenu;
    154     }
    155 
    156     public Input geInput() {
    157         return mInput;
    158     }
    159 
    160     public TextMessage geTextMessage() {
    161         return mTextMsg;
    162     }
    163 
    164     public BrowserSettings getBrowserSettings() {
    165         return mBrowserSettings;
    166     }
    167 
    168     public ToneSettings getToneSettings() {
    169         return mToneSettings;
    170     }
    171 
    172     public CallSettings getCallSettings() {
    173         return mCallSettings;
    174     }
    175 }
    176