ShutdownApp.c
上传用户:lqx1163
上传日期:2014-08-13
资源大小:9183k
文件大小:51k
源码类别:

MTK

开发平台:

C/C++

  1. /*****************************************************************************
  2. *  Copyright Statement:
  3. *  --------------------
  4. *  This software is protected by Copyright and the information contained
  5. *  herein is confidential. The software may not be copied and the information
  6. *  contained herein may not be used or disclosed except with the written
  7. *  permission of MediaTek Inc. (C) 2005
  8. *
  9. *  BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
  10. *  THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
  11. *  RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
  12. *  AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
  13. *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
  14. *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
  15. *  NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
  16. *  SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
  17. *  SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
  18. *  THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
  19. *  NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
  20. *  SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
  21. *
  22. *  BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
  23. *  LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
  24. *  AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
  25. *  OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
  26. *  MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE. 
  27. *
  28. *  THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
  29. *  WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
  30. *  LAWS PRINCIPLES.  ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
  31. *  RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
  32. *  THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
  33. *
  34. *****************************************************************************/
  35. /*****************************************************************************
  36.  *
  37.  * Filename:
  38.  * ---------
  39.  *   ShutdownApp.c
  40.  *
  41.  * Project:
  42.  * --------
  43.  *   MAUI
  44.  *
  45.  * Description:
  46.  * ------------
  47.  *   This file is intends for shutdowns whole system operation
  48.  *
  49.  * Author:
  50.  * -------
  51.  * -------
  52.  *
  53.  *============================================================================
  54.  *             HISTORY
  55.  * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
  56.  *------------------------------------------------------------------------------
  57.  * removed!
  58.  *
  59.  * removed!
  60.  * removed!
  61.  * removed!
  62.  *
  63.  * removed!
  64.  * removed!
  65.  * removed!
  66.  *
  67.  * removed!
  68.  * removed!
  69.  * removed!
  70.  *
  71.  * removed!
  72.  * removed!
  73.  * removed!
  74.  *
  75.  * removed!
  76.  * removed!
  77.  * removed!
  78.  *
  79.  * removed!
  80.  * removed!
  81.  * removed!
  82.  *
  83.  * removed!
  84.  * removed!
  85.  * removed!
  86.  *
  87.  * removed!
  88.  * removed!
  89.  * removed!
  90.  *
  91.  * removed!
  92.  * removed!
  93.  * removed!
  94.  *
  95.  * removed!
  96.  * removed!
  97.  * removed!
  98.  *
  99.  * removed!
  100.  * removed!
  101.  * removed!
  102.  *
  103.  * removed!
  104.  * removed!
  105.  * removed!
  106.  *
  107.  * removed!
  108.  * removed!
  109.  * removed!
  110.  *
  111.  * removed!
  112.  * removed!
  113.  * removed!
  114.  *
  115.  * removed!
  116.  * removed!
  117.  * removed!
  118.  *
  119.  * removed!
  120.  * removed!
  121.  * removed!
  122.  *
  123.  * removed!
  124.  * removed!
  125.  * removed!
  126.  *
  127.  * removed!
  128.  * removed!
  129.  * removed!
  130.  *
  131.  * removed!
  132.  * removed!
  133.  * removed!
  134.  *
  135.  * removed!
  136.  * removed!
  137.  * removed!
  138.  *
  139.  * removed!
  140.  * removed!
  141.  * removed!
  142.  *
  143.  * removed!
  144.  * removed!
  145.  * removed!
  146.  *
  147.  * removed!
  148.  * removed!
  149.  * removed!
  150.  *
  151.  * removed!
  152.  * removed!
  153.  * removed!
  154.  *
  155.  * removed!
  156.  * removed!
  157.  * removed!
  158.  *
  159.  * removed!
  160.  * removed!
  161.  * removed!
  162.  *
  163.  * removed!
  164.  * removed!
  165.  * removed!
  166.  *
  167.  * removed!
  168.  * removed!
  169.  * removed!
  170.  *
  171.  * removed!
  172.  * removed!
  173.  * removed!
  174.  *
  175.  *------------------------------------------------------------------------------
  176.  * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
  177.  *============================================================================
  178.  ****************************************************************************/
  179. /****************************************************************************
  180. * Include Files                                                                
  181. *****************************************************************************/
  182. #include "MMI_features.h"
  183. #include "StdC.h"
  184. #include "L4Dr.h"
  185. #include "L4Dr1.h"
  186. #include "BuildCfg.h"
  187. #include "FrameworkStruct.h"
  188. #include "DebugInitDef.h"
  189. #include "AllAppGprot.h"
  190. #include "gdi_include.h"
  191. #include "wgui_categories.h"
  192. #include "TimerEvents.h"
  193. #include "EventsGprot.h"
  194. #include "AudioInc.h"
  195. #include "ProtocolEvents.h"
  196. #include "MainMenuDef.h"
  197. #include "DebugInitDef.h"
  198. #include "SettingProfile.h"
  199. #include "ProfileGprots.h"
  200. #include "ProfilesGexdcl.h"
  201. #include "KeyBrd.h"
  202. #include "gpioInc.h"
  203. #include "Globaldefs.h"
  204. #include "AlarmFrameworkProt.h"
  205. #include "Bootup.h"
  206. #include "mdi_datatype.h"
  207. #include "mdi_audio.h"
  208. #include "GlobalScrEnum.h"
  209. #include "MessagesExDcl.h"      /* extern void DeInitMessagesApp (void) */
  210. #include "CallManagementGprot.h"        /* extern void DeInitCM(void) */
  211. #include "wgui_categories_multimedia.h"
  212. #include "Fat_fs.h"
  213. #include "FileSystemDef.h"      /* file function */
  214. #include "FileManagerGProt.h"   /* file path, file error */
  215. #include "FileManagerDef.h"     /* error string id */
  216. #include "FileMgr.h"
  217. #include "WPSSProtos.h" /* phone setup interface */
  218. #include "DebugInitDef.h"       /* MMI_ASSERT */
  219. #include "NVRAMType.h"  /* NVRAM data type */
  220. #include "NVRAMProt.h"  /* NVRAM access fucntions */
  221. #include "NVRAMEnum.h"  /* NVRAM ID define */
  222. #include "SubLCDHistoryGprot.h" /* extern void ForceSubLCDScreen(void) */
  223. #include "SimDetectionDef.h"
  224. #include "SimDetectionGexdcl.h"
  225. #ifdef __MMI_TVOUT__
  226. #include "mdi_datatype.h"
  227. #include "mdi_tv.h"
  228. #endif /* __MMI_TVOUT__ */ 
  229. #ifdef MMI_ON_HARDWARE_P
  230. #include "lcd_sw.h"
  231. #include "lcd_if.h"
  232. #endif /* MMI_ON_HARDWARE_P */ 
  233. #ifdef __DRM_SUPPORT__
  234. #include "Drm_gprot.h"  /* DRM support */
  235. #endif 
  236. #ifdef __MMI_VOIP__
  237. #include "VoIPGProt.h"
  238. #endif
  239. //KP Jerry add on 2007-4-6 start
  240. #ifdef __MMI_CSTAR__
  241. #include "cstarime.h"
  242. #endif
  243. //KP Jerry add on 2007-4-6 end
  244. /***************************************************************************** 
  245. * Define
  246. *****************************************************************************/
  247. static void mmi_shutdown_speech_off_for_outstanding_call(void);
  248. #ifdef __MMI_BT_SUPPORT__
  249. extern void mmi_bt_host_device_power_off_pre_process(void);
  250. #endif 
  251. //KP Jerry add on 2007-3-8 start
  252. #if defined(__MMI_CSTAR__)
  253. extern void ExitCstarInputMethod(void);
  254. #endif
  255. //KP Jerry add on 2007-3-8 end
  256. /***************************************************************************** 
  257. * Typedef 
  258. *****************************************************************************/
  259. typedef struct _shutdown_callback_info
  260. {
  261.     FuncPtr shutdown_callback_f;
  262.     U8 shutdown_callback_t;
  263. } SHUTDOWNCALLBACKINFO;
  264. /*****************************************************************************
  265. * Global Variabl                                                          
  266. *****************************************************************************/
  267. #ifdef MMI_ON_WIN32
  268. extern BOOL using_dll_ui;
  269. #endif 
  270. /*****************************************************************************
  271. * Global Function                                                           
  272. *****************************************************************************/
  273. extern void QuitSystemOperation(void);      /* system shutdown operation */
  274. extern void ShutdownSystemOperation(void);  /* kill all the object */
  275. extern void CallBackPowerOffAnimationComplete(GDI_RESULT ret);
  276. extern void DeInitApps(void);
  277. extern void DeInitAllApplications(void);
  278. extern void DeInitInsertApp(void);
  279. extern void SPOFDeInit(void);
  280. extern void KillWindowObject(void);         /* kill all semaphore and thread objects */
  281. extern U16 KillObjects(void);               /* kill windows object */
  282. extern void DeInitTimers(void);             /* stop all timers */
  283. #ifdef __MMI_TODOLIST__
  284. extern void DeInitToDoListApp(void);
  285. #endif 
  286. /***************************************************************************** 
  287. * Local Variable
  288. *****************************************************************************/
  289. //static U8     gNetworkDeattachRspFlag = 0;
  290. //static U8     gWapPowerOffRspFlag = 0;
  291. //static U8     gShutDownAudioPlayFinishRspFlag = 0;
  292. //static U8     gPowerOffPeriod = 0;
  293. static pBOOL g_shutdown_is_terminate_diplay;
  294. static pBOOL g_shutdown_is_successful_play = MMI_TRUE;
  295. static pBOOL g_shutdown_is_image;
  296. static pBOOL g_shutdown_is_still_image = MMI_FALSE;
  297. #ifdef MMI_ON_WIN32
  298. BOOL flagMMIStart = MMI_FALSE;
  299. #endif 
  300. /*****************************************************************************
  301. * Local Function 
  302. *****************************************************************************/
  303. /* void mmi_shutdown_froce_terminate_display(void); */
  304. void SystemShutdownTimeout(void);
  305. #ifdef __MMI_WLAN_FEATURES__
  306. static void mmi_shutdown_wifi_req(void);
  307. #endif
  308. static SHUTDOWNCALLBACKINFO mmi_shutdown_callbacks[] = 
  309. {
  310.     /* callback_timing = 0 : execute the callback before shutdown processes */
  311.     /* callback_timing = 1 : execute the callback before quit system operation */
  312.     {mmi_shutdown_speech_off_for_outstanding_call, 0},
  313. #ifdef __MMI_BT_SUPPORT__
  314.     {mmi_bt_host_device_power_off_pre_process, 0},
  315. #endif
  316. #ifdef __MMI_VOIP__
  317.     {mmi_voip_deinit, 0},
  318. #endif
  319. #ifdef __MMI_WLAN_FEATURES__
  320.     {mmi_shutdown_wifi_req, 0},
  321. #endif
  322.     {NULL, 0}   /* dummy one, please add callbacks before this entity */
  323. };
  324. /*****************************************************************************
  325.  * FUNCTION
  326.  *  mmi_shutdown_exe_callback
  327.  * DESCRIPTION
  328.  *  Execute callbacks before shutdown
  329.  * PARAMETERS
  330.  *  t_flag      [IN]        
  331.  * RETURNS
  332.  *  void
  333.  *****************************************************************************/
  334. void mmi_shutdown_exe_callback(U8 t_flag)
  335. {
  336.     /*----------------------------------------------------------------*/
  337.     /* Local Variables                                                */
  338.     /*----------------------------------------------------------------*/
  339.     U8 i;
  340.     /*----------------------------------------------------------------*/
  341.     /* Code Body                                                      */
  342.     /*----------------------------------------------------------------*/
  343.     for (i = 0; mmi_shutdown_callbacks[i].shutdown_callback_f != NULL; i++)
  344.     {
  345.         if (mmi_shutdown_callbacks[i].shutdown_callback_f != NULL &&
  346.             mmi_shutdown_callbacks[i].shutdown_callback_t == t_flag)
  347.         {
  348.             PRINT_INFORMATION_2((MMI_TRACE_G7_MISC, "[Shutdown] Execute shutdown callback %d", i + 1));
  349.             (*mmi_shutdown_callbacks[i].shutdown_callback_f) ();
  350.             mmi_shutdown_callbacks[i].shutdown_callback_f = NULL;
  351.         }
  352.     }
  353. }
  354. /*****************************************************************************
  355.  * FUNCTION
  356.  *  NwPlmnSetRSP
  357.  * DESCRIPTION
  358.  *  response handling of network deregister req
  359.  * PARAMETERS
  360.  *  info        [?]     
  361.  * RETURNS
  362.  *  void
  363.  *****************************************************************************/
  364. void NwPlmnSetRSP(void *info)
  365. {
  366. #ifdef MMI_ON_HARDWARE_P
  367.     /*----------------------------------------------------------------*/
  368.     /* Local Variables                                                */
  369.     /*----------------------------------------------------------------*/
  370.     mmi_nw_pwroff_detach_rsp_struct *p = (mmi_nw_pwroff_detach_rsp_struct*) info;
  371.     /*----------------------------------------------------------------*/
  372.     /* Code Body                                                      */
  373.     /*----------------------------------------------------------------*/
  374.     if (p->result.flag == L4C_OK)
  375.     {
  376.         PRINT_INFORMATION_2((MMI_TRACE_G7_MISC, "[NwPlmnSetRSP] Shutdown Proc: DeAttach Rsp Back"));
  377.         /* gNetworkDeattachRspFlag=1; */
  378.         g_pwr_context.PowerOffMMIStatus |= 0x01;
  379.         if (g_shutdown_is_still_image && g_shutdown_is_successful_play)
  380.         {
  381.             CallBackPowerOffAnimationComplete(GDI_GIF_LAST_FRAME);
  382.         }
  383.     }
  384.     else
  385.     {
  386.         PRINT_INFORMATION_2((MMI_TRACE_G7_MISC, "[NwPlmnSetRSP] Shutdown Proc: DeAttach Rsp Fail"));
  387.     }
  388. #endif /* MMI_ON_HARDWARE_P */ 
  389. }
  390. /*****************************************************************************
  391.  * FUNCTION
  392.  *  RequestRacDetach
  393.  * DESCRIPTION
  394.  *  request to deregister network
  395.  * PARAMETERS
  396.  *  void
  397.  * RETURNS
  398.  *  void
  399.  *****************************************************************************/
  400. static void RequestRacDetach()
  401. {
  402. #ifdef MMI_ON_HARDWARE_P
  403.     /*----------------------------------------------------------------*/
  404.     /* Local Variables                                                */
  405.     /*----------------------------------------------------------------*/
  406.     MYQUEUE Message;
  407.     /*----------------------------------------------------------------*/
  408.     /* Code Body                                                      */
  409.     /*----------------------------------------------------------------*/
  410.     SetProtocolEventHandler(NwPlmnSetRSP, MSG_ID_MMI_NW_PWROFF_DETACH_RSP);
  411.     Message.oslSrcId = MOD_MMI;
  412.     Message.oslDestId = MOD_L4C;
  413.     Message.oslMsgId = MSG_ID_MMI_NW_PWROFF_DETACH_REQ;
  414.     Message.oslDataPtr = (oslParaType*) NULL;
  415.     Message.oslPeerBuffPtr = NULL;
  416.     OslMsgSendExtQueue(&Message);
  417. #endif /* MMI_ON_HARDWARE_P */ 
  418. }
  419. /* MTK justin WAP poweroff support */
  420. #ifdef WAP_SUPPORT
  421. /*****************************************************************************
  422.  * FUNCTION
  423.  *  WapBrowserPoweroffRsp
  424.  * DESCRIPTION
  425.  *  After the WAP browser is shutdown, deregister network
  426.  * PARAMETERS
  427.  *  inMsg       [?]     
  428.  * RETURNS
  429.  *  void
  430.  *****************************************************************************/
  431. static void WapBrowserPoweroffRsp(void *inMsg)
  432. {
  433.     /*----------------------------------------------------------------*/
  434.     /* Local Variables                                                */
  435.     /*----------------------------------------------------------------*/
  436.     /*----------------------------------------------------------------*/
  437.     /* Code Body                                                      */
  438.     /*----------------------------------------------------------------*/
  439.     PRINT_INFORMATION_2((MMI_TRACE_G7_MISC, "[WapBrowserPoweroffRsp] Shutdown Proc: WAP Back"));
  440.     /* gWapPowerOffRspFlag = 1; */
  441.     g_pwr_context.PowerOffMMIStatus |= 0x02;
  442. }
  443. /*****************************************************************************
  444.  * FUNCTION
  445.  *  RequestWapShutdown
  446.  * DESCRIPTION
  447.  *  After the WAP browser is shutdown, deregister network
  448.  *  
  449.  *  This is used to shutdowns whole system opeartion
  450.  * PARAMETERS
  451.  *  void
  452.  * RETURNS
  453.  *  void
  454.  *****************************************************************************/
  455. static void RequestWapShutdown()
  456. {
  457.     /*----------------------------------------------------------------*/
  458.     /* Local Variables                                                */
  459.     /*----------------------------------------------------------------*/
  460.     MYQUEUE Message;
  461.     /*----------------------------------------------------------------*/
  462.     /* Code Body                                                      */
  463.     /*----------------------------------------------------------------*/
  464.     SetProtocolEventHandler(WapBrowserPoweroffRsp, MSG_ID_WAP_BROWSER_POWEROFF_RSP);
  465.     Message.oslSrcId = MOD_MMI;
  466.     Message.oslDestId = MOD_WAP;
  467.     Message.oslMsgId = MSG_ID_WAP_BROWSER_POWEROFF_REQ;
  468.     Message.oslDataPtr = (oslParaType*) NULL;
  469.     Message.oslPeerBuffPtr = NULL;
  470.     OslMsgSendExtQueue(&Message);
  471.     /* The WAP browser should send back MSG_ID_WAP_BROWSER_POWEROFF_RSP in limited time. */
  472. }
  473. #endif /* WAP_SUPPORT */ 
  474. /* MTK justin end */
  475. /*****************************************************************************
  476.  * FUNCTION
  477.  *  ShutDownAudioFinishRes
  478.  * DESCRIPTION
  479.  *  handler fn for power off tone finish  ind
  480.  * PARAMETERS
  481.  *  info        [?]     
  482.  * RETURNS
  483.  *  void
  484.  *****************************************************************************/
  485. U8 ShutDownAudioFinishRes(void *info)
  486. {
  487. #ifdef MMI_ON_HARDWARE_P
  488.     /*----------------------------------------------------------------*/
  489.     /* Local Variables                                                */
  490.     /*----------------------------------------------------------------*/
  491.     /*----------------------------------------------------------------*/
  492.     /* Code Body                                                      */
  493.     /*----------------------------------------------------------------*/
  494.     PRINT_INFORMATION_2((MMI_TRACE_G7_MISC, "[ShutDownAudioFinishRes] Shutdown Proc: Audio Back"));
  495.     /* gShutDownAudioPlayFinishRspFlag = 1; */
  496.     g_pwr_context.PowerOffMMIStatus |= 0x04;
  497. #endif /* MMI_ON_HARDWARE_P */ 
  498.     if (g_shutdown_is_still_image && g_shutdown_is_successful_play)
  499.     {
  500.         CallBackPowerOffAnimationComplete(GDI_GIF_LAST_FRAME);
  501.     }
  502.     return MMI_FALSE;   /* ?? */
  503. }
  504. /*****************************************************************************
  505.  * FUNCTION
  506.  *  mmi_shutdown_play_video_callback
  507.  * DESCRIPTION
  508.  *  Play shutdown video result callback function
  509.  * PARAMETERS
  510.  *  result      [IN]        Of playing video
  511.  * RETURNS
  512.  *  void
  513.  *****************************************************************************/
  514. void mmi_shutdown_play_video_callback(MDI_RESULT result)
  515. {
  516.     /*----------------------------------------------------------------*/
  517.     /* Local Variables                                                */
  518.     /*----------------------------------------------------------------*/
  519.     /*----------------------------------------------------------------*/
  520.     /* Code Body                                                      */
  521.     /*----------------------------------------------------------------*/
  522.     if (g_shutdown_is_terminate_diplay)
  523.     {
  524.         return; /* means already terminated by time out, shall skip this callback */
  525.     }
  526.     /* treat as gif animation */
  527.     /* change to GIF's return */
  528.     g_pwr_context.PowerOffMMIStatus |= 0x04;
  529.     if (result < 0)
  530.     {
  531.         /* failed to play video */
  532.         g_shutdown_is_successful_play = MMI_FALSE;
  533.         /* failed to play video, and force to shutdown */
  534.         /* gShutDownAudioPlayFinishRspFlag = 1; */
  535.         CallBackPowerOffAnimationComplete(result);
  536.     }
  537.     else
  538.     {
  539.         /* play video successfully */
  540.         /* g_shutdown_is_successful_play = MMI_TRUE; */
  541.         /* notify successful play once */
  542.         /* gShutDownAudioPlayFinishRspFlag = 1; */
  543.         CallBackPowerOffAnimationComplete(GDI_GIF_LAST_FRAME);
  544.     }
  545. }
  546. /*****************************************************************************
  547.  * FUNCTION
  548.  *  mmi_shutdown_show_image_callback
  549.  * DESCRIPTION
  550.  *  Show power off image result callback function
  551.  * PARAMETERS
  552.  *  result      [IN]        Of showing image
  553.  * RETURNS
  554.  *  void
  555.  *****************************************************************************/
  556. void mmi_shutdown_show_image_callback(GDI_RESULT result)
  557. {
  558.     /*----------------------------------------------------------------*/
  559.     /* Local Variables                                                */
  560.     /*----------------------------------------------------------------*/
  561.     /*----------------------------------------------------------------*/
  562.     /* Code Body                                                      */
  563.     /*----------------------------------------------------------------*/
  564.     if (g_shutdown_is_terminate_diplay)
  565.     {
  566.         return; /* means already terminated by time out, shall skip this callback */
  567.     }
  568.     if (result < 0)
  569.     {
  570.         /* failed to play video */
  571.         g_shutdown_is_successful_play = MMI_FALSE;
  572.         /* failed to play video, and force to shutdown */
  573.         CallBackPowerOffAnimationComplete(result);
  574.     }
  575.     else if (result == GDI_IMAGE_IS_STILL_IMAGE)
  576.     {
  577.         /* g_shutdown_is_successful_play = MMI_TRUE; */
  578.         g_shutdown_is_still_image = MMI_TRUE;
  579.         CallBackPowerOffAnimationComplete(result);
  580.     }
  581.     else
  582.     {
  583.         /* play finish successfully */
  584.         /* g_shutdown_is_successful_play = MMI_TRUE; */
  585.         CallBackPowerOffAnimationComplete(result);
  586.     }
  587. }
  588. /**************************************************************
  589.    FUNCTION NAME     : mmi_shutdown_froce_terminate_display
  590.    PURPOSE        : Force terminate shutdown display
  591.    INPUT PARAMETERS  : nil
  592.    OUTPUT PARAMETERS : nil
  593.    RETURNS        : void
  594. **************************************************************/
  595. /*
  596.  * void mmi_shutdown_froce_terminate_display(void)
  597.  * {
  598.  * // if can successful play once (can loop), do not need force teminate
  599.  * if(!g_shutdown_is_successful_play)
  600.  * {
  601.  * g_shutdown_is_terminate_diplay   = MMI_TRUE;
  602.  * g_shutdown_is_successful_play = MMI_TRUE;
  603.  * 
  604.  * CallBackPowerOffAnimationComplete(-1);
  605.  * }
  606.  * }
  607.  */
  608. /*****************************************************************************
  609.  * FUNCTION
  610.  *  mmi_shutdown_stop_animation
  611.  * DESCRIPTION
  612.  *  Stop power off animation screen when ready to shutdown
  613.  *  
  614.  *  When ready to enter power on screen, it will enter goto_opening_screen(),
  615.  *  in this function, it will call InitAllApplications(), there are NVRAM access
  616.  *  in this function, which will cause NVRAM & timer interlace problem.
  617.  *  
  618.  *  We have to stop all animation timer when we are sure poweron procdure success.
  619.  *  We may call this function in mmi_ready_to_idle_screen_ind.
  620.  * PARAMETERS
  621.  *  void
  622.  * RETURNS
  623.  *  void
  624.  *****************************************************************************/
  625. void mmi_shutdown_stop_animation(void)
  626. {
  627.     /*----------------------------------------------------------------*/
  628.     /* Local Variables                                                */
  629.     /*----------------------------------------------------------------*/
  630.     U8 pwroff_flag;
  631.     S16 error;
  632.     /*----------------------------------------------------------------*/
  633.     /* Code Body                                                      */
  634.     /*----------------------------------------------------------------*/
  635.     /* stop force teminate timer */
  636.     /* gui_cancel_timer(mmi_shutdown_froce_terminate_display); */
  637.     if (g_shutdown_is_image)
  638.     {
  639.         /* stop image playing */
  640.         StopCategory166Animation();
  641.     }
  642.     else
  643.     {
  644.     #if defined(__MMI_VIDEO_PLAYER__)
  645.         /* stop video playing */
  646.         StopCategory224Video();
  647.     #endif /* defined(__MMI_VIDEO_PLAYER__) */ 
  648.     }
  649.     /* write proper value to NVRAM */
  650.     if (!g_shutdown_is_successful_play)
  651.     {
  652.     #ifdef __MMI_POWER_ON_OFF_DISPLAY__
  653.         /* restore default */
  654.         PhnsetRstPwrOffDisplayDefault();
  655.     #endif /* __MMI_POWER_ON_OFF_DISPLAY__ */ 
  656.     }
  657.     pwroff_flag = PWROFF_DISPLAY_SUCCESS;
  658.     WriteValue(NVRAM_POWER_OFF_DISPLAY_SUCCESS, &pwroff_flag, DS_SHORT, &error);
  659. }
  660. /*****************************************************************************
  661.  * FUNCTION
  662.  *  mmi_shutdown_entry_animation_screen
  663.  * DESCRIPTION
  664.  *  Start play power off animation (GIF animation, still image, or video clip)
  665.  * PARAMETERS
  666.  *  void
  667.  * RETURNS
  668.  *  void
  669.  *****************************************************************************/
  670. void mmi_shutdown_entry_animation_screen(void)
  671. {
  672.     /*----------------------------------------------------------------*/
  673.     /* Local Variables                                                */
  674.     /*----------------------------------------------------------------*/
  675.     U16 disp_id;
  676.     PS8 filename_ptr = NULL;
  677.     FS_HANDLE fs_handle;
  678.     U16 res_type;
  679.     S16 error;
  680.     U8 pwroff_flag;
  681.     U8 pwron_flag;
  682.     /* U16          force_stop_time; */
  683. #if defined(__MMI_VIDEO_PLAYER__)
  684.     BOOL play_audio;
  685. #endif 
  686.     /*----------------------------------------------------------------*/
  687.     /* Code Body                                                      */
  688.     /*----------------------------------------------------------------*/
  689.     /* g_shutdown_is_successful_play = MMI_FALSE; */
  690.     g_shutdown_is_image = MMI_TRUE;
  691.     TurnOnBacklight(0);
  692.     /* 1. If shutdown while power on display is playing, we still dont know it will play successfully or not, so set the flag to 0xff, let it check next time */
  693.     ReadValue(NVRAM_POWER_ON_DISPLAY_SUCCESS, &pwron_flag, DS_SHORT, &error);
  694.     if (pwron_flag == PWRON_DISPLAY_PLAYING)
  695.     {
  696.         pwron_flag = PWRON_DISPLAY_SUCCESS;
  697.         WriteValue(NVRAM_POWER_ON_DISPLAY_SUCCESS, &pwron_flag, DS_SHORT, &error);
  698.     }
  699.     /* 2. This timer is used to avoid gif/video play too long, will force to enter idle */
  700.     /*
  701.      * ReadValue(NVRAM_POWER_OFF_FORCE_STOP_TIME, &force_stop_time, DS_SHORT, &error);
  702.      * if(force_stop_time == 0xffff)
  703.      * {
  704.      * // not set in NVRAM, use defulat 15 sec limit
  705.      * force_stop_time = 15000;
  706.      * }
  707.      * 
  708.      * gui_start_timer(force_stop_time, mmi_shutdown_froce_terminate_display);
  709.      */
  710.     g_shutdown_is_terminate_diplay = MMI_FALSE;
  711.     /* 3. Valid power off display restoration checking */
  712.     ReadValue(NVRAM_POWER_OFF_DISPLAY_SUCCESS, &pwroff_flag, DS_SHORT, &error);
  713. #ifdef __MMI_POWER_ON_OFF_DISPLAY__
  714.     if (pwron_flag == PWRON_DISPLAY_FAILED)
  715.     {
  716.         /* If not 0xff, means something wrong happened during playing power off display, we will restore power off display to default settings */
  717.         PhnsetRstPwrOffDisplayDefault();
  718.     }
  719. #endif /* __MMI_POWER_ON_OFF_DISPLAY__ */ 
  720.     /* 4. Set the flag to 0x01 , if play successfully to end, will reset back to 0xff */
  721.     pwroff_flag = PWROFF_DISPLAY_PLAYING;
  722.     WriteValue(NVRAM_POWER_OFF_DISPLAY_SUCCESS, &pwroff_flag, DS_SHORT, &error);
  723.     /* 5. Get animation resource from phone setup */
  724. #ifdef __MMI_POWER_ON_OFF_DISPLAY__
  725.     PhnsetGetPwrOffDisp(&disp_id);
  726.     if (disp_id == 0xff)    /* invalid format */
  727.     {
  728.         PhnsetRstPwrOffDisplayDefault();    /* reset as default */
  729.         PhnsetGetPwrOffDisp(&disp_id);      /* this id must be a valid id */
  730.     }
  731.     else if (disp_id == 0x00 || disp_id == 0x01)    /* 0x00: source from file, 0x01: short file name */
  732.     {
  733.         PS8 error;
  734.         disp_id = 0x00;
  735.         filename_ptr = PhnsetGetPwrOffFileName();   /* filename buffer is allocated in phnset */
  736.         if (!mmi_fmgr_util_file_limit_check(FMGR_LIMIT_POWER_ON_OFF_DSPL, filename_ptr, &error))
  737.         {
  738.             /* limit check failed */
  739.             /* reset to default */
  740.             PhnsetRstPwrOffDisplayDefault();
  741.             /* this id must be a valid id */
  742.             PhnsetGetPwrOffDisp(&disp_id);
  743.             filename_ptr = NULL;
  744.         }
  745.     }
  746.     else    /* source from intenal resource */
  747.     {
  748.         filename_ptr = NULL;
  749.     }
  750.     /* 6. Check if is image or video */
  751.     if (filename_ptr != NULL)   /* get file resource type */
  752.     {
  753.         res_type = mmi_fmgr_get_file_group(filename_ptr);   /* source from file */
  754.         if (res_type == FMGR_GROUP_IMAGE)
  755.         {
  756.             g_shutdown_is_image = MMI_TRUE;
  757.         }
  758.         else if (res_type == FMGR_GROUP_VIDEO)
  759.         {
  760.             g_shutdown_is_image = MMI_FALSE;
  761.         }
  762.     #ifdef __MMI_SWFLASH__
  763.         else if (res_type == FMGR_GROUP_SWFLASH)
  764.         {
  765.             g_shutdown_is_image = TRUE;
  766.         }
  767.     #endif /* __MMI_SWFLASH__ */
  768.         else
  769.         {
  770.             PhnsetRstPwrOffDisplayDefault();    /* unsupported file format ext and restore default */
  771.             PhnsetGetPwrOffDisp(&disp_id);      /* this id must be a valid id */
  772.             filename_ptr = NULL;
  773.         }
  774.     #ifdef __DRM_SUPPORT__
  775.         /* DRM permission check */
  776.         if ((fs_handle = DRM_open_file((PU16) filename_ptr, FS_READ_ONLY, DRM_PERMISSION_NONE)) >= FS_NO_ERROR)
  777.         {
  778.             if (res_type == FMGR_GROUP_IMAGE && DRM_validate_permission(fs_handle, DRM_PERMISSION_DISPLAY))
  779.             {
  780.                 DRM_consume_rights(fs_handle, DRM_PERMISSION_DISPLAY);
  781.             }
  782.         #ifdef __MMI_SWFLASH__
  783.             else if (res_type == FMGR_GROUP_SWFLASH && DRM_validate_permission(fs_handle, DRM_PERMISSION_DISPLAY))
  784.             {
  785.                 DRM_consume_rights(fs_handle, DRM_PERMISSION_DISPLAY);
  786.             }
  787.         #endif /* __MMI_SWFLASH__ */
  788.             else if (res_type == FMGR_GROUP_VIDEO && DRM_validate_permission(fs_handle, DRM_PERMISSION_PLAY))
  789.             {
  790.                 DRM_consume_rights(fs_handle, DRM_PERMISSION_PLAY);
  791.             }
  792.             DRM_close_file(fs_handle);
  793.         }
  794.     #else /* __DRM_SUPPORT__ */ 
  795.         fs_handle = FS_Open((U16*) filename_ptr, FS_READ_ONLY);
  796.     #endif /* __DRM_SUPPORT__ */ 
  797.         if (fs_handle < FS_NO_ERROR)
  798.         {
  799.             PhnsetRstPwrOffDisplayDefault();    /* open file failed and reset as default */
  800.             PhnsetGetPwrOffDisp(&disp_id);      /* this id must be a valid id */
  801.             filename_ptr = NULL;
  802.         }
  803.         else
  804.         {
  805.             FS_Close(fs_handle);    /* open file successful */
  806.         }
  807.         
  808.     }
  809.     /* 7. Check internal resource type */
  810.     if (filename_ptr == NULL)
  811.     {
  812.         res_type = PhnsetGetDisplayType(disp_id);
  813.         if (res_type == PHNSET_TYPE_DISP_IMAGE)
  814.         {
  815.             g_shutdown_is_image = MMI_TRUE;
  816.             res_type = FMGR_GROUP_IMAGE;
  817.         }
  818.         else if (res_type == PHNSET_TYPE_DISP_VIDEO)
  819.         {
  820.             g_shutdown_is_image = MMI_FALSE;
  821.             res_type = FMGR_GROUP_VIDEO;
  822.         }
  823.     #ifdef __MMI_SWFLASH__
  824.         else if (res_type == PHNSET_TYPE_DISP_SWFLASH)
  825.         {
  826.             g_shutdown_is_image = TRUE;
  827.             res_type = FMGR_GROUP_SWFLASH;
  828.         }
  829.     #endif /* __MMI_SWFLASH__ */
  830.         else
  831.         {
  832.             MMI_ASSERT(0);
  833.         }
  834.     }
  835. #else /* __MMI_POWER_ON_OFF_DISPLAY__ */ 
  836.     /* 7. Play from internal build in resource */
  837.     g_shutdown_is_image = MMI_TRUE;
  838.     disp_id = IMG_ID_PHNSET_OFF_ANIMATION_DEFAULT;  /* Cylen 0926, customize display char */
  839.     filename_ptr = NULL;
  840. #endif /* __MMI_POWER_ON_OFF_DISPLAY__ */ 
  841.     /* 8. Start to play */
  842.     if (res_type == FMGR_GROUP_IMAGE)
  843.     {
  844.         ShowCategory166Screen(disp_id, filename_ptr, mmi_shutdown_show_image_callback);
  845.         ShowCategory313Screen(IMG_SUBLCD_SYSTEM_SHUTDOWN, NULL);
  846.         /* play power off tone */
  847.         if (gcurrentprofile.toneSetup.powerOffTone != POWEROFF_SILENT)
  848.         {
  849.             playRequestedTone(POWER_OFF_TONE);
  850.             /* Shall set interrupt event handler */
  851.             /* mdi will register event handler itself, shall not preempt it */
  852.             SetInterruptEventHandler(ShutDownAudioFinishRes, NULL, PRT_L4AUD_AUDIO_PLAY_FINISH_IND);
  853.         }
  854.         else
  855.         {
  856.             /* gShutDownAudioPlayFinishRspFlag = 1; */
  857.             g_pwr_context.PowerOffMMIStatus |= 0x04;
  858.             PRINT_INFORMATION_2((MMI_TRACE_G7_MISC, "[ShutdownSystemOperation] Shutdown Proc: Audio Back"));
  859.         }
  860.     }
  861.     else if (res_type == FMGR_GROUP_VIDEO)
  862.     {
  863.     #if defined(__MMI_VIDEO_PLAYER__)
  864.         /* check silent mode */
  865.         play_audio = (gcurrentprofile.toneSetup.powerOffTone != POWEROFF_SILENT) ? MMI_TRUE : MMI_FALSE;
  866.         /* set volume as ring tone volume */
  867.         mdi_audio_set_volume(MDI_VOLUME_MEDIA, GetRingVolumeLevel());
  868.         /* entry video play screen */
  869.         ShowCategory224Screen(
  870.             disp_id,                            /* video id */
  871.             filename_ptr,                       /* filename */
  872.             0,                                  /* repeat_count, 0 means infinite */
  873.             MMI_TRUE,                           /* is_visaul_update */
  874.             play_audio,                         /* is_play_audio */
  875.             MMI_FALSE,                          /* is_lcd_sleep, already in non sleep mode */
  876.             GDI_COLOR_BLACK,                    /* bg_color */
  877.             mmi_shutdown_play_video_callback,   /* (*play_finish_callback)(S16) */
  878.             NULL);                              /* gui_buffer */
  879.     #else /* defined(__MMI_VIDEO_PLAYER__) */ 
  880.         MMI_ASSERT(0);
  881.     #endif /* defined(__MMI_VIDEO_PLAYER__) */ 
  882.     }
  883. #ifdef __MMI_SWFLASH__
  884.     else if (res_type == FMGR_GROUP_SWFLASH)
  885.     {
  886.         ShowCategory229Screen(
  887.             0,                      /* title_str */
  888.             0,            /* title_icon */
  889.             0,                      /* lsk_str */
  890.             0,                      /* lsk_icon */
  891.             0,                    /* rsk_str */
  892.             0,                    /* rsk_icon */
  893.             disp_id,                        /* resource_id */
  894.             filename_ptr,                               /* resource_filename */
  895.             1,                                  /* repeat_count */
  896.             MMI_TRUE,                          /* is_play_audio */
  897.             0,                          /* is_vibrate_on */
  898.             0,                          /* is_interaction_on */
  899.             0,                           /* is_lcd_no_sleep */
  900.             MMI_TRUE,                          /* is_full_screen */
  901.             GDI_COLOR_WHITE,                    /* bg_color */
  902.             mmi_shutdown_show_image_callback,
  903.             NULL);
  904.         
  905.     }
  906. #endif  /* __MMI_SWFLASH__ */
  907. }
  908. /*****************************************************************************
  909.  * FUNCTION
  910.  *  ShutdownSystemOperation
  911.  * DESCRIPTION
  912.  *  Shutdowns whole system opeartion
  913.  *  
  914.  *  This is used to shutdowns whole system opeartion
  915.  * PARAMETERS
  916.  *  void
  917.  * RETURNS
  918.  *  void
  919.  *****************************************************************************/
  920. void ShutdownSystemOperation(void)
  921. {
  922.     /*----------------------------------------------------------------*/
  923.     /* Local Variables                                                */
  924.     /*----------------------------------------------------------------*/
  925.     /*----------------------------------------------------------------*/
  926.     /* Code Body                                                      */
  927.     /*----------------------------------------------------------------*/
  928.     /* gPowerOffPeriod = 1; */
  929. #ifdef MMI_ON_WIN32
  930.     g_pwr_context.PowerOffMMIStatus = 0x0F;
  931. #else 
  932.     g_pwr_context.PowerOffMMIStatus = MMI_POWER_OFF_ANIMATION;
  933. #endif 
  934. #ifdef MMI_ON_WIN32
  935.     if (!flagMMIStart)
  936.     {
  937.         if (using_dll_ui != MMI_TRUE)
  938.         {
  939.             exit(0);
  940.         }
  941.         else
  942.         {
  943.             return;
  944.         }
  945.     }
  946. #endif /* MMI_ON_WIN32 */ 
  947.     /* exit poweroff anmation screen by enter a dummy screen */
  948.     EntryNewScreen(GLOBAL_SCR_DUMMY, NULL, NULL, NULL);
  949.     PRINT_INFORMATION(("File: [%s]  Line: [%d] <<it shutdowns whole system opeartion>>n", __FILE__, __LINE__));
  950. //KP Jerry add on 2007-3-8 start
  951.     #if defined(__MMI_CSTAR__)
  952.     ExitCstarInputMethod();
  953.     #endif
  954. //KP Jerry add on 2007-3-8 end
  955.     mmi_shutdown_exe_callback(0);   /* execute callbacks from other app */
  956.     TurnOnBacklight(0);                     /* turn on backlight for power off animation */
  957.     StopTimer(TIMER_REAL_TIME_CLOCK);       /* stops one sec timer */
  958.     mdi_audio_suspend_background_play();    /* stop background music */
  959.     DeInitFramework();                      /* clear history, key, timer, protocol, hardware events & other objects */
  960.     ClearAllProtocolEventHandler();         /* clear registered handlers */
  961.     DeInitTimers();                         /* stop all timers */
  962.     DeInitApps();                           /* deinit applications */
  963.     AlmDeInit();                            /* deinit alarm */
  964.     terminate_UI_demo();                    /* temporary: should be done in a more formal manner */
  965. #ifdef __MMI_BT_PROFILE__
  966.     mdi_audio_bt_hfp_turn_off();            /* Switch path back to phone then before disconnect SCO*/
  967.     mdi_audio_bt_close_stream(BT_HFP);    
  968. #endif 
  969.     mmi_shutdown_entry_animation_screen();  /* dispalay shutdown animation screen */
  970.     StartLEDPatternPowerOff();              /* play LED pattern for shutdown */
  971.     PRINT_INFORMATION_2((MMI_TRACE_G7_MISC, "[ShutdownSystemOperation] ShutDown Proc: Start! "));
  972.     RequestRacDetach();                         /* detach network */
  973. #ifdef WAP_SUPPORT
  974.     RequestWapShutdown();                       /* detach wap */
  975. #else 
  976.     g_pwr_context.PowerOffMMIStatus |= 0x02;    /* gWapPowerOffRspFlag = 1; */
  977. #endif 
  978.     /* start a timer to force shutdown if there is no detach response from RAC/L4C */
  979.     StartTimer(SYSTEM_SHUTDOWN, POWER_OFF_TIMER_STAGE_1, SystemShutdownTimeout);
  980. }
  981. /*****************************************************************************
  982.  * FUNCTION
  983.  *  SystemShutdownTimeout
  984.  * DESCRIPTION
  985.  *  Call back fn on timeout of timer SYSTEM_SHUTDOWN
  986.  * PARAMETERS
  987.  *  void
  988.  * RETURNS
  989.  *  void
  990.  *****************************************************************************/
  991. void SystemShutdownTimeout(void)
  992. {
  993.     /*----------------------------------------------------------------*/
  994.     /* Local Variables                                                */
  995.     /*----------------------------------------------------------------*/
  996.     /*----------------------------------------------------------------*/
  997.     /* Code Body                                                      */
  998.     /*----------------------------------------------------------------*/
  999.     StopTimer(SYSTEM_SHUTDOWN);
  1000.     //gNetworkDeattachRspFlag=1;
  1001.     //gShutDownAudioPlayFinishRspFlag = 1;
  1002.     //gWapPowerOffRspFlag = 1;
  1003.     g_pwr_context.PowerOffMMIStatus = 0x0F; /* MMI_POWER_OFF_QUIT; */
  1004.     PRINT_INFORMATION_2((MMI_TRACE_G7_MISC, "[SystemShutdownTimeout] ShutDown Proc: Timeout! "));
  1005.     /* start a new timer to quit system operation */
  1006.     StartTimer(SYSTEM_SHUTDOWN, POWER_OFF_TIMER_STAGE_2, QuitSystemOperation);  /* Robin 1217, Guard Timer */
  1007. #ifdef MMI_ON_WIN32
  1008.     QuitSystemOperation();
  1009. #endif 
  1010. }
  1011. /*****************************************************************************
  1012.  * FUNCTION
  1013.  *  PowerOffRsp
  1014.  * DESCRIPTION
  1015.  *  Res handling of Power Off req.
  1016.  * PARAMETERS
  1017.  *  info        [?]     
  1018.  * RETURNS
  1019.  *  void
  1020.  *****************************************************************************/
  1021. void PowerOffRsp(void *info)
  1022. {
  1023.     /*----------------------------------------------------------------*/
  1024.     /* Local Variables                                                */
  1025.     /*----------------------------------------------------------------*/
  1026.     /*----------------------------------------------------------------*/
  1027.     /* Code Body                                                      */
  1028.     /*----------------------------------------------------------------*/
  1029.     KeyPadLCDBackLightStop();
  1030. #ifdef MMI_ON_HARDWARE_P
  1031.     {
  1032.         mmi_eq_power_off_rsp_struct *p = (mmi_eq_power_off_rsp_struct*) info;
  1033.         if (p->result == MMI_TRUE)
  1034.         {
  1035.             PRINT_INFORMATION(("@@@@@ ShutDown Process Success!!!!!  @@@@@"));
  1036.         }
  1037.         else
  1038.         {
  1039.             PRINT_INFORMATION(("@@@@@ ShutDown Process Failure!!!!!  @@@@@"));
  1040.         }
  1041.     }
  1042. #endif /* MMI_ON_HARDWARE_P */ 
  1043. }
  1044. /*****************************************************************************
  1045.  * FUNCTION
  1046.  *  QuitSystemOperation
  1047.  * DESCRIPTION
  1048.  *  Send req to L4 to power off the device.
  1049.  * PARAMETERS
  1050.  *  void
  1051.  * RETURNS
  1052.  *  void
  1053.  *****************************************************************************/
  1054. void QuitSystemOperation(void)
  1055. {
  1056.     /*----------------------------------------------------------------*/
  1057.     /* Local Variables                                                */
  1058.     /*----------------------------------------------------------------*/
  1059. #ifdef MMI_ON_HARDWARE_P
  1060.     MYQUEUE Message;
  1061. #else 
  1062.     extern HINSTANCE hinstLib;
  1063. #endif 
  1064.     /*----------------------------------------------------------------*/
  1065.     /* Code Body                                                      */
  1066.     /*----------------------------------------------------------------*/
  1067.     g_shutdown_is_terminate_diplay = MMI_TRUE;
  1068.     SetGPIOLevelReq(GPIO_DEV_LED_MAINLCD, LED_LIGHT_LEVEL0);    /* turn off backlight to prevent blank screen */
  1069. #ifdef __MMI_TVOUT__
  1070.     if (mdi_tvout_is_enable())
  1071.     {
  1072.         mdi_tvout_stop();
  1073.     }
  1074. #endif /* __MMI_TVOUT__ */ 
  1075.     mmi_shutdown_stop_animation();  /* stop shut down animations */
  1076.     /* exit poweroff anmation screen by enter a dummy screen */
  1077.     EntryNewScreen(GLOBAL_SCR_DUMMY, NULL, NULL, NULL);
  1078.     /* stop music again, cause ExitCategoryVdoplyScreen will resume it */
  1079.     mdi_audio_suspend_background_play();
  1080.     /* gPowerOffPeriod = 1; */
  1081.     g_pwr_context.PowerOffMMIStatus = MMI_POWER_OFF_QUIT;
  1082.     PRINT_INFORMATION_2((MMI_TRACE_G7_MISC, "[QuitSystemOperation] ShutDown Proc: Poweroff! "));
  1083.     StopTimer(SYSTEM_SHUTDOWN); /* stops shutdown timer */
  1084.     mmi_shutdown_exe_callback(1);   /* execute callbacks from other app */
  1085. #ifdef MMI_ON_WIN32
  1086.     /* Problem: MMI queue's CS is empty. Solution: did not kill it too early, and let Windows handle them. */
  1087.     // KillObjects();                  /* kill all the semaphore and thread objects */
  1088.     KillWindowObject();             /* kill windown object */
  1089. #else /* MMI_ON_WIN32 */ 
  1090.     StopLEDPatternPowerOff();       /* stop LCD pattern for shutdown */
  1091.     lcd_power_on(MAIN_LCD, 0);      /* power off lcd */
  1092. #ifdef __MMI_SUBLCD__
  1093.     lcd_power_on(SUB_LCD, 0);       /* power off sub-lcd */
  1094. #endif 
  1095. #ifndef __MTK_TARGET__
  1096.     exit(0);
  1097. #endif 
  1098.     SetProtocolEventHandler(PowerOffRsp, PRT_POWER_OFF_RSP);
  1099.     Message.oslSrcId = MOD_MMI;
  1100.     Message.oslDestId = MOD_L4C;
  1101.     Message.oslMsgId = PRT_POWER_OFF_REQ;
  1102.     Message.oslDataPtr = NULL;
  1103.     Message.oslPeerBuffPtr = NULL;
  1104.     OslMsgSendExtQueue(&Message);   /* message for power off device */
  1105. #endif /* MMI_ON_WIN32 */ 
  1106.     OslDumpDataInFile();
  1107. #ifndef MMI_ON_HARDWARE_P
  1108.     FreeLibrary(hinstLib);
  1109. #endif 
  1110. }
  1111. /*****************************************************************************
  1112.  * FUNCTION
  1113.  *  CallBackPowerOffAnimationComplete
  1114.  * DESCRIPTION
  1115.  *  Call back fn for Power off animation.
  1116.  * PARAMETERS
  1117.  *  ret     [IN]        
  1118.  * RETURNS
  1119.  *  void
  1120.  *****************************************************************************/
  1121. void CallBackPowerOffAnimationComplete(GDI_RESULT ret)
  1122. {
  1123.     /*----------------------------------------------------------------*/
  1124.     /* Local Variables                                                */
  1125.     /*----------------------------------------------------------------*/
  1126.     /*----------------------------------------------------------------*/
  1127.     /* Code Body                                                      */
  1128.     /*----------------------------------------------------------------*/
  1129.     PRINT_INFORMATION_2((MMI_TRACE_G7_MISC, "[CallBackPwrOffAniCmplte] Shutdown Proc: Animation CallBack"));
  1130.     if (ret < 0)
  1131.     {
  1132.         /* broken animation image */
  1133.         QuitSystemOperation();
  1134.         return;
  1135.     }
  1136.     /* if(gNetworkDeattachRspFlag && gShutDownAudioPlayFinishRspFlag && gWapPowerOffRspFlag ) */
  1137.     if (g_pwr_context.PowerOffMMIStatus == 0x0F)
  1138.     {
  1139.         /* if receive all detach flags, start to quit system operation */
  1140.         /* else, wait stage 2 timer expires to quit system operation */
  1141.         //gNetworkDeattachRspFlag=0;
  1142.         //gShutDownAudioPlayFinishRspFlag = 0;
  1143.         //gWapPowerOffRspFlag = 0;
  1144.         QuitSystemOperation();
  1145.     }
  1146. }
  1147. /*****************************************************************************
  1148.  * FUNCTION
  1149.  *  mmi_shutdown_is_in_power_off_period
  1150.  * DESCRIPTION
  1151.  *  
  1152.  * PARAMETERS
  1153.  *  void
  1154.  * RETURNS
  1155.  *  
  1156.  *****************************************************************************/
  1157. pBOOL mmi_shutdown_is_in_power_off_period(void)
  1158. {
  1159.     /*----------------------------------------------------------------*/
  1160.     /* Local Variables                                                */
  1161.     /*----------------------------------------------------------------*/
  1162.     /*----------------------------------------------------------------*/
  1163.     /* Code Body                                                      */
  1164.     /*----------------------------------------------------------------*/
  1165.     if (g_pwr_context.PowerOffMMIStatus > MMI_POWER_OFF_DEFAULT)
  1166.     {
  1167.         return MMI_TRUE;
  1168.     }
  1169.     else
  1170.     {
  1171.         return MMI_FALSE;
  1172.     }
  1173. }
  1174. /*****************************************************************************
  1175.  * FUNCTION
  1176.  *  DeInitAllApplications
  1177.  * DESCRIPTION
  1178.  *  De-initialization
  1179.  *  
  1180.  *  This is used to De-initialize all applications
  1181.  * PARAMETERS
  1182.  *  void
  1183.  * RETURNS
  1184.  *  void
  1185.  *****************************************************************************/
  1186. void DeInitAllApplications(void)
  1187. {
  1188.     /*----------------------------------------------------------------*/
  1189.     /* Local Variables                                                */
  1190.     /*----------------------------------------------------------------*/
  1191.     /*----------------------------------------------------------------*/
  1192.     /* Code Body                                                      */
  1193.     /*----------------------------------------------------------------*/
  1194.     SPOFDeInit();           /* deinit schedule power on/off */
  1195.     DeInitMessagesApp();    /* deinit message application */
  1196. #ifdef __MMI_TODOLIST__
  1197.     DeInitToDoListApp();    /* deinit to do list */
  1198. #endif 
  1199.     DeInitCM();             /* deinit call management */
  1200. }
  1201. /*****************************************************************************
  1202.  * FUNCTION
  1203.  *  DeInitInsertSimApp
  1204.  * DESCRIPTION
  1205.  *  DeInitialization
  1206.  *  
  1207.  *  This is used to De-initialize applications when no SIM is present
  1208.  * PARAMETERS
  1209.  *  void
  1210.  * RETURNS
  1211.  *  void
  1212.  *****************************************************************************/
  1213. void DeInitInsertSimApp(void)
  1214. {
  1215.     /*----------------------------------------------------------------*/
  1216.     /* Local Variables                                                */
  1217.     /*----------------------------------------------------------------*/
  1218.     /*----------------------------------------------------------------*/
  1219.     /* Code Body                                                      */
  1220.     /*----------------------------------------------------------------*/
  1221. #ifdef __MMI_TODOLIST__
  1222.     DeInitToDoListApp();    /* deinit to do list */
  1223. #endif 
  1224. }
  1225. /*****************************************************************************
  1226.  * FUNCTION
  1227.  *  DeInitApps
  1228.  * DESCRIPTION
  1229.  *  DeInitialization
  1230.  * PARAMETERS
  1231.  *  void
  1232.  * RETURNS
  1233.  *  void
  1234.  *****************************************************************************/
  1235. void DeInitApps(void)
  1236. {
  1237.     /*----------------------------------------------------------------*/
  1238.     /* Local Variables                                                */
  1239.     /*----------------------------------------------------------------*/
  1240.     extern U8 gInitAllAppFlag;
  1241.     extern U8 gInsertSimAppFlag;
  1242.     /*----------------------------------------------------------------*/
  1243.     /* Code Body                                                      */
  1244.     /*----------------------------------------------------------------*/
  1245.     if (gInitAllAppFlag)
  1246.     {
  1247.         DeInitAllApplications();
  1248.     }
  1249.     else if (gInsertSimAppFlag)
  1250.     {
  1251.         DeInitInsertSimApp();
  1252.     }
  1253. }
  1254. /*****************************************************************************
  1255.  * FUNCTION
  1256.  *  DeInitTimers
  1257.  * DESCRIPTION
  1258.  *  DeInitialization
  1259.  * PARAMETERS
  1260.  *  void
  1261.  * RETURNS
  1262.  *  void
  1263.  *****************************************************************************/
  1264. void DeInitTimers(void)
  1265. {
  1266.     /*----------------------------------------------------------------*/
  1267.     /* Local Variables                                                */
  1268.     /*----------------------------------------------------------------*/
  1269.     U16 timer_id;
  1270.     /*----------------------------------------------------------------*/
  1271.     /* Code Body                                                      */
  1272.     /*----------------------------------------------------------------*/
  1273.     /* stop all timers no matter it is running or not */
  1274.     for (timer_id = 0; timer_id < MAX_TIMERS; timer_id++)
  1275.     {
  1276.         StopTimer(timer_id);
  1277.     }
  1278. }
  1279. /*****************************************************************************
  1280.  * FUNCTION
  1281.  *  mmi_shutdown_speech_off_for_outstanding_call
  1282.  * DESCRIPTION
  1283.  *  Shutdown callback to check if there is a call in shutdown period
  1284.  * PARAMETERS
  1285.  *  void
  1286.  * RETURNS
  1287.  *  void
  1288.  *****************************************************************************/
  1289. static void mmi_shutdown_speech_off_for_outstanding_call(void)
  1290. {
  1291.     if (isInCall())
  1292.     {
  1293.         if (mdi_audio_speech_get_app_id() == MDI_AUDIO_SPEECH_APP_ID_GSM)
  1294.         {
  1295.             mdi_audio_speech_codec_stop();
  1296.             mdi_audio_speech_session_stop(MDI_AUDIO_SPEECH_APP_ID_GSM);
  1297.         }
  1298.         else if (mdi_audio_speech_get_app_id() == MDI_AUDIO_SPEECH_APP_ID_WCDMA)
  1299.         {
  1300.             mdi_audio_speech_codec_stop();
  1301.             mdi_audio_speech_session_stop(MDI_AUDIO_SPEECH_APP_ID_WCDMA);
  1302.         }        
  1303.     }
  1304. }
  1305. #ifdef __MMI_WLAN_FEATURES__
  1306. /*****************************************************************************
  1307.  * FUNCTION
  1308.  *  mmi_shutdown_wifi_req
  1309.  * DESCRIPTION
  1310.  *  shutdown wifi the module
  1311.  * PARAMETERS
  1312.  *  void
  1313.  * RETURNS
  1314.  *  void
  1315.  *****************************************************************************/
  1316. static void mmi_shutdown_wifi_req(void)
  1317. {
  1318.     /*----------------------------------------------------------------*/
  1319.     /* Code Body                                                      */
  1320.     /*----------------------------------------------------------------*/
  1321.     MYQUEUE Message;
  1322.     /*----------------------------------------------------------------*/
  1323.     /* Code Body                                                      */
  1324.     /*----------------------------------------------------------------*/
  1325.     Message.oslSrcId = MOD_MMI;
  1326.     Message.oslDestId = MOD_WNDRV;
  1327.     Message.oslMsgId = MSG_ID_WNDRV_MMI_POWEROFF_REQ;
  1328.     Message.oslDataPtr = (oslParaType*) NULL;
  1329.     Message.oslPeerBuffPtr = NULL;
  1330.     OslMsgSendExtQueue(&Message);
  1331. }
  1332. #if 0
  1333. /* under construction !*/
  1334. /* under construction !*/
  1335. /* under construction !*/
  1336. /* under construction !*/
  1337. /* under construction !*/
  1338. /* under construction !*/
  1339. /* under construction !*/
  1340. /* under construction !*/
  1341. /* under construction !*/
  1342. /* under construction !*/
  1343. /* under construction !*/
  1344. /* under construction !*/
  1345. /* under construction !*/
  1346. /* under construction !*/
  1347. /* under construction !*/
  1348. /* under construction !*/
  1349. /* under construction !*/
  1350. /* under construction !*/
  1351. /* under construction !*/
  1352. /* under construction !*/
  1353. #endif /* 0 */
  1354. #endif /* __MMI_WLAN_FEATURES__ */