Home | History | Annotate | Download | only in jni
      1 /*
      2  * Copyright (C) 2014 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 #ifndef DMSERVICE_ALERT_H
     18 #define DMSERVICE_ALERT_H
     19 
     20 #ifndef __cplusplus
     21 #error "This is a C++ header file; it requires C++ to compile."
     22 #endif
     23 
     24 /**
     25  * \file  DMServiceAlert.h
     26  * \brief Declaration of JNI implementation of DMServiceAlert.
     27  */
     28 
     29 #include <DMServiceMain.h>
     30 #include "xpl_dm_ServerAlert.h"
     31 
     32 // DMServiceAlert Response Code
     33 static const int DM_SERVICE_ALERT_RESP_FAIL     = -1;
     34 static const int DM_SERVICE_ALERT_RESP_NONE     = 0;
     35 static const int DM_SERVICE_ALERT_RESP_NO       = 1;
     36 static const int DM_SERVICE_ALERT_RESP_YES      = 2;
     37 static const int DM_SERVICE_ALERT_RESP_CANCEL   = 3;
     38 static const int DM_SERVICE_ALERT_RESP_TIMEOUT  = 4;
     39 
     40 #ifdef DM_SDMSERVICES
     41 static const int DM_SERVICE_ALERT_MAX_MSG_SIZE  = 250;
     42 #endif
     43 
     44 // DMServiceAlert Input Type
     45 static const int DM_SERVICE_ALERT_INPUT_ALPHA       = 0;
     46 static const int DM_SERVICE_ALERT_INPUT_NUMERIC     = 1;
     47 static const int DM_SERVICE_ALERT_INPUT_DATE        = 2;
     48 static const int DM_SERVICE_ALERT_INPUT_TIME        = 3;
     49 static const int DM_SERVICE_ALERT_INPUT_PHONE_NUM   = 4;
     50 static const int DM_SERVICE_ALERT_INPUT_IP_ADDR     = 5;
     51 
     52 // DMServiceAlert Echo Type
     53 static const int DM_SERVICE_ALERT_ECHO_TEXT         = 0;
     54 static const int DM_SERVICE_ALERT_ECHO_PASSWD       = 1;
     55 
     56 // DMServiceAlert Icon Type
     57 static const int DM_SERVICE_ALERT_ICON_GENERIC      = 0;
     58 static const int DM_SERVICE_ALERT_ICON_PROGRESS     = 1;
     59 static const int DM_SERVICE_ALERT_ICON_OK           = 2;
     60 static const int DM_SERVICE_ALERT_ICON_ERROR        = 3;
     61 static const int DM_SERVICE_ALERT_ICON_CONFIRM      = 4;
     62 static const int DM_SERVICE_ALERT_ICON_ACTION       = 5;
     63 static const int DM_SERVICE_ALERT_ICON_INFO         = 6;
     64 
     65 // DMServiceAlert Title Type
     66 static const int DM_SERVICE_ALERT_TITLE_NULL                = 0;
     67 static const int PMF_RESOURCE_ID_TITLE_SYSTEM_UPDATE        = 1;
     68 static const int PMF_RESOURCE_ID_TITLE_NEED_AUTHENTICATION  = 2;
     69 static const int PMF_RESOURCE_ID_TITLE_UPDATE_COMPLETE      = 3;
     70 static const int PMF_RESOURCE_ID_TITLE_SYSTEM_MESSAGE           = 4;
     71 static const int PMF_RESOURCE_ID_TITLE_AUTHENTICATION_FAILED    = 5;
     72 static const int PMF_RESOURCE_ID_TITLE_UPDATE_ERROR             = 6;
     73 static const int PMF_RESOURCE_ID_TITLE_UPDATE_CANCELLED         = 7;
     74 static const int PMF_RESOURCE_ID_TITLE_PROFILE_FOR_BROWSER      = 8;
     75 static const int PMF_RESOURCE_ID_TITLE_PROFILE_FOR_MMS          = 9;
     76 static const int PMF_RESOURCE_ID_TITLE_CONNECTION_FAILED        = 10;
     77 static const int PMF_RESOURCE_ID_TITLE_CONNECTION_FAILURE       = 11;
     78 static const int PMF_RESOURCE_ID_TITLE_SW_UPDATE                = 12;
     79 static const int PMF_RESOURCE_ID_14674_TITLE_REGISTRATION       = 13;
     80 static const int PMF_RESOURCE_ID_CONTEXT_SYSTEM_UPDATE_SEVERAL_MINUTES_NO_PROCEED = 14;
     81 static const int PMF_RESOURCE_ID_CONTEXT_SYSTEM_UPDATE_NOTICE   = 15;
     82 static const int PMF_RESOURCE_ID_CONTEXT_SYSTEM_UPDATE          = 16;
     83 static const int PMF_RESOURCE_ID_CONTEXT_ENTER_PIN_CARRIER      = 17;
     84 static const int PMF_RESOURCE_ID_CONTEXT_SYSTEM_UPDATE_IN_PROGRESS      = 18;
     85 static const int PMF_RESOURCE_ID_CONTEXT_DO_YOU_WANT_TO_ACCEPT_UPDATE   = 19;
     86 static const int PMF_RESOURCE_ID_CONNECTING_TO_UPDATE_SERVICE           = 20;
     87 static const int PMF_RESOURCE_ID_CONTEXT_SYSTEM_UPDATE_COMPLETED        = 21;
     88 static const int PMF_RESOURCE_ID_CONTEXT_CONNECTION_SUCCEEDED           = 22;
     89 static const int PMF_RESOURCE_ID_CONTEXT_PIN_FAILED_TRY_AGAIN           = 23;
     90 static const int PMF_RESOURCE_ID_CONTEXT_PIN_FAILED_CONTACT_CARRIER     = 24;
     91 static const int PMF_RESOURCE_ID_CONTEXT_SYSTEM_UPDATE_FAILED_CONTACT_CARRIER = 25;
     92 static const int PMF_RESOURCE_ID_CONTEXT_CONNECTION_FAILED              = 26;
     93 static const int PMF_RESOURCE_ID_CONTEXT_SYSTEM_UPDATE_CANCELLED        = 27;
     94 static const int PMF_RESOURCE_ID_CONTEXT_PLEASE_SELECT_BROWSER_PROFILE  = 28;
     95 static const int PMF_RESOURCE_ID_CONTEXT_PLEASE_SELECT_MMS_PROFILE      = 29;
     96 static const int PMF_RESOURCE_ID_CONTEXT_AUTH_FAILED_CONTACT_CARRIER    = 30;
     97 static const int PMF_RESOURCE_ID_CONTEXT_NWNOT_AVAILABLE                = 31;
     98 static const int PMF_RESOURCE_ID_CONTEXT_CONNECT_ERROR                  = 32;
     99 static const int PMF_RESOURCE_ID_CONTEXT_SW_UPDATE                      = 33;
    100 static const int PMF_RESOURCE_ID_CONTEXT_CONNECTING                     = 34;
    101 
    102 class DMServiceAlert
    103 {
    104 public:
    105 
    106     /**
    107      * Constructor.
    108      */
    109     DMServiceAlert();
    110 
    111     /**
    112      * Destructor
    113      */
    114     ~DMServiceAlert();
    115 
    116     /**
    117      * Display a text message alert.
    118      *
    119      * \param[in] minDisplayTime minimum display time, in seconds.
    120      * \param[in] msg message to display
    121      * \return SYNCML_DM_STATUS_T::SUCCESS on success; otherwise returns error code.
    122      */
    123     SYNCML_DM_RET_STATUS_T showDisplayAlert(INT32 minDisplayTime, const DMString& msg,
    124             INT32 title = DM_SERVICE_ALERT_TITLE_NULL, INT32 icon = DM_SERVICE_ALERT_ICON_GENERIC);
    125 
    126     /**
    127      * Display a confirm alert message box; user can confirm or cancel the action.
    128      *
    129      * \param[in] maxDisplayTime maximum display time (for timeout), in seconds.
    130      * \param[in] msg message to display
    131      * \param[in] defaultResponse default user action when timeout
    132      * \param[out] response user's action will be returned here.
    133      * \return SYNCML_DM_STATUS_T::SUCCESS on success; otherwise returns error code.
    134      */
    135     SYNCML_DM_RET_STATUS_T showConfirmAlert(INT32 maxDisplayTime, const DMString& msg,
    136             XPL_DM_ALERT_RES_T defaultResponse, XPL_DM_ALERT_RES_T* response,
    137             INT32 title = DM_SERVICE_ALERT_TITLE_NULL, INT32 icon = DM_SERVICE_ALERT_ICON_GENERIC);
    138 
    139     /**
    140      * Display a text input message box for user to enter input.
    141      *
    142      * \param[in] maxDisplayTime maximum display time (for timeout), in seconds.
    143      * \param[in] msg message to display
    144      * \param[in] defaultResponse default user action when timeout
    145      * \param[in] maxLength length allowed in user input
    146      * \param[in] inputType data format as specified in DM_ALERT_INPUT_T
    147      * \param[in] echoType whether to echo user input (hidden for password)
    148      * \param[out] response hold user's response action and input data.
    149      * \return SYNCML_DM_STATUS_T::SUCCESS on success; otherwise returns error code.
    150      */
    151     SYNCML_DM_RET_STATUS_T showTextInputAlert(INT32 maxDisplayTime, const DMString& msg,
    152             const DMString& defaultResponse, INT32 maxLength, XPL_DM_ALERT_INPUT_T inputType,
    153             XPL_DM_ALERT_ECHO_T echoType, XPL_DM_ALERT_TEXTINPUT_RES_T* response,
    154             INT32 title = DM_SERVICE_ALERT_TITLE_NULL, INT32 icon = DM_SERVICE_ALERT_ICON_GENERIC);
    155 
    156     /**
    157      * Display a single choice message box for user to select one entry.
    158      *
    159      * \param[in] maxDisplayTime maximum display time (for timeout), in seconds.
    160      * \param[in] msg message to display
    161      * \param[in] choices a string vector to hold text for each choice
    162      * \param[in] defaultResponse default user action when timeout
    163      * \param[out] response hold user's response action and selected choice.
    164      * \return SYNCML_DM_STATUS_T::SUCCESS on success; otherwise returns error code.
    165      */
    166     SYNCML_DM_RET_STATUS_T showSingleChoiceAlert(INT32 maxDisplayTime, const DMString& msg,
    167             const DMStringVector& choices, INT32 defaultResponse,
    168             XPL_DM_ALERT_SCHOICE_RES_T* response, INT32 title = DM_SERVICE_ALERT_TITLE_NULL,
    169             INT32 icon = DM_SERVICE_ALERT_ICON_GENERIC);
    170 
    171     /**
    172      * Display a multiple choice message box for user to select zero to many entries.
    173      *
    174      * \param[in] maxDisplayTime maximum display time (for timeout), in seconds.
    175      * \param[in] msg message to display
    176      * \param[in] choices a string vector to hold text for each choice
    177      * \param[in] defaultResponses holds default responses in an array of string representation of
    178      * selected indexes (starting from 1)
    179      * \param[out] response hold user's response action and selected choice.
    180      * \return SYNCML_DM_STATUS_T::SUCCESS on success; otherwise returns error code.
    181      */
    182     SYNCML_DM_RET_STATUS_T showMultipleChoiceAlert(INT32 maxDisplayTime, const DMString& msg,
    183             const DMStringVector& choices, const DMStringVector& defaultResponses,
    184             XPL_DM_ALERT_MCHOICE_RES_T* response, INT32 title = DM_SERVICE_ALERT_TITLE_NULL,
    185             INT32 icon = DM_SERVICE_ALERT_ICON_GENERIC);
    186 
    187 private:
    188 
    189     JNIEnv*    m_jDmEnv;
    190     jclass     m_jDmAlertCls;
    191     jobject    m_jDmAlertObj;
    192     jmethodID  m_jDmAlertMID;
    193 
    194     bool isJvmNull() {
    195         return (m_jDmEnv == NULL || m_jDmAlertCls == NULL || m_jDmAlertObj == NULL);
    196     }
    197 };
    198 
    199 #endif /* DMSERVICEALERT_H */
    200