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     private SetupEventListSettings mSetupEventListSettings = null;
     37     private boolean mLoadIconFailed = false;
     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         mLoadIconFailed =  cmdParams.mLoadIconFailed;
     76         switch(getCmdType()) {
     77         case SET_UP_MENU:
     78         case SELECT_ITEM:
     79             mMenu = ((SelectItemParams) cmdParams).mMenu;
     80             break;
     81         case DISPLAY_TEXT:
     82         case SET_UP_IDLE_MODE_TEXT:
     83         case SEND_DTMF:
     84         case SEND_SMS:
     85         case SEND_SS:
     86         case SEND_USSD:
     87             mTextMsg = ((DisplayTextParams) cmdParams).mTextMsg;
     88             break;
     89         case GET_INPUT:
     90         case GET_INKEY:
     91             mInput = ((GetInputParams) cmdParams).mInput;
     92             break;
     93         case LAUNCH_BROWSER:
     94             mTextMsg = ((LaunchBrowserParams) cmdParams).mConfirmMsg;
     95             mBrowserSettings = new BrowserSettings();
     96             mBrowserSettings.url = ((LaunchBrowserParams) cmdParams).mUrl;
     97             mBrowserSettings.mode = ((LaunchBrowserParams) cmdParams).mMode;
     98             break;
     99         case PLAY_TONE:
    100             PlayToneParams params = (PlayToneParams) cmdParams;
    101             mToneSettings = params.mSettings;
    102             mTextMsg = params.mTextMsg;
    103             break;
    104         case GET_CHANNEL_STATUS:
    105             mTextMsg = ((CallSetupParams) cmdParams).mConfirmMsg;
    106             break;
    107         case SET_UP_CALL:
    108             mCallSettings = new CallSettings();
    109             mCallSettings.confirmMsg = ((CallSetupParams) cmdParams).mConfirmMsg;
    110             mCallSettings.callMsg = ((CallSetupParams) cmdParams).mCallMsg;
    111             break;
    112         case OPEN_CHANNEL:
    113         case CLOSE_CHANNEL:
    114         case RECEIVE_DATA:
    115         case SEND_DATA:
    116             BIPClientParams param = (BIPClientParams) cmdParams;
    117             mTextMsg = param.mTextMsg;
    118             break;
    119         case SET_UP_EVENT_LIST:
    120             mSetupEventListSettings = new SetupEventListSettings();
    121             mSetupEventListSettings.eventList = ((SetEventListParams) cmdParams).mEventInfo;
    122             break;
    123         case PROVIDE_LOCAL_INFORMATION:
    124         case REFRESH:
    125         default:
    126             break;
    127         }
    128     }
    129 
    130     public CatCmdMessage(Parcel in) {
    131         mCmdDet = in.readParcelable(null);
    132         mTextMsg = in.readParcelable(null);
    133         mMenu = in.readParcelable(null);
    134         mInput = in.readParcelable(null);
    135         mLoadIconFailed = (in.readByte() == 1);
    136         switch (getCmdType()) {
    137         case LAUNCH_BROWSER:
    138             mBrowserSettings = new BrowserSettings();
    139             mBrowserSettings.url = in.readString();
    140             mBrowserSettings.mode = LaunchBrowserMode.values()[in.readInt()];
    141             break;
    142         case PLAY_TONE:
    143             mToneSettings = in.readParcelable(null);
    144             break;
    145         case SET_UP_CALL:
    146             mCallSettings = new CallSettings();
    147             mCallSettings.confirmMsg = in.readParcelable(null);
    148             mCallSettings.callMsg = in.readParcelable(null);
    149             break;
    150         case SET_UP_EVENT_LIST:
    151             mSetupEventListSettings = new SetupEventListSettings();
    152             int length = in.readInt();
    153             mSetupEventListSettings.eventList = new int[length];
    154             for (int i = 0; i < length; i++) {
    155                 mSetupEventListSettings.eventList[i] = in.readInt();
    156             }
    157             break;
    158         default:
    159             break;
    160         }
    161     }
    162 
    163     @Override
    164     public void writeToParcel(Parcel dest, int flags) {
    165         dest.writeParcelable(mCmdDet, 0);
    166         dest.writeParcelable(mTextMsg, 0);
    167         dest.writeParcelable(mMenu, 0);
    168         dest.writeParcelable(mInput, 0);
    169         dest.writeByte((byte) (mLoadIconFailed ? 1 : 0));
    170         switch(getCmdType()) {
    171         case LAUNCH_BROWSER:
    172             dest.writeString(mBrowserSettings.url);
    173             dest.writeInt(mBrowserSettings.mode.ordinal());
    174             break;
    175         case PLAY_TONE:
    176             dest.writeParcelable(mToneSettings, 0);
    177             break;
    178         case SET_UP_CALL:
    179             dest.writeParcelable(mCallSettings.confirmMsg, 0);
    180             dest.writeParcelable(mCallSettings.callMsg, 0);
    181             break;
    182         case SET_UP_EVENT_LIST:
    183             dest.writeIntArray(mSetupEventListSettings.eventList);
    184             break;
    185         default:
    186             break;
    187         }
    188     }
    189 
    190     public static final Parcelable.Creator<CatCmdMessage> CREATOR = new Parcelable.Creator<CatCmdMessage>() {
    191         @Override
    192         public CatCmdMessage createFromParcel(Parcel in) {
    193             return new CatCmdMessage(in);
    194         }
    195 
    196         @Override
    197         public CatCmdMessage[] newArray(int size) {
    198             return new CatCmdMessage[size];
    199         }
    200     };
    201 
    202     @Override
    203     public int describeContents() {
    204         return 0;
    205     }
    206 
    207     /* external API to be used by application */
    208     public AppInterface.CommandType getCmdType() {
    209         return AppInterface.CommandType.fromInt(mCmdDet.typeOfCommand);
    210     }
    211 
    212     public Menu getMenu() {
    213         return mMenu;
    214     }
    215 
    216     public Input geInput() {
    217         return mInput;
    218     }
    219 
    220     public TextMessage geTextMessage() {
    221         return mTextMsg;
    222     }
    223 
    224     public BrowserSettings getBrowserSettings() {
    225         return mBrowserSettings;
    226     }
    227 
    228     public ToneSettings getToneSettings() {
    229         return mToneSettings;
    230     }
    231 
    232     public CallSettings getCallSettings() {
    233         return mCallSettings;
    234     }
    235 
    236     public SetupEventListSettings getSetEventList() {
    237         return mSetupEventListSettings;
    238     }
    239 
    240     /**
    241      * API to be used by application to check if loading optional icon
    242      * has failed
    243      */
    244     public boolean hasIconLoadFailed() {
    245         return mLoadIconFailed;
    246     }
    247 }
    248