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

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.  * Filename:
  37.  * ---------
  38.  *   IdleScreenSaver.c
  39.  *
  40.  * Project:
  41.  * --------
  42.  *   MAUI
  43.  *
  44.  * Description:
  45.  * ------------
  46.  *   Screensaver
  47.  *
  48.  * Author:
  49.  * -------
  50.  * -------
  51.  *
  52.  *==============================================================================
  53.  *             HISTORY
  54.  * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!! 
  55.  *------------------------------------------------------------------------------
  56.  * removed!
  57.  *
  58.  * removed!
  59.  * removed!
  60.  * removed!
  61.  *
  62.  * removed!
  63.  * removed!
  64.  * removed!
  65.  *
  66.  * removed!
  67.  * removed!
  68.  * removed!
  69.  *
  70.  * removed!
  71.  * removed!
  72.  * removed!
  73.  *
  74.  * removed!
  75.  * removed!
  76.  * removed!
  77.  *
  78.  * removed!
  79.  * removed!
  80.  * removed!
  81.  *
  82.  * removed!
  83.  * removed!
  84.  * removed!
  85.  *
  86.  * removed!
  87.  * removed!
  88.  * removed!
  89.  *
  90.  * removed!
  91.  * removed!
  92.  * removed!
  93.  *
  94.  * removed!
  95.  * removed!
  96.  * removed!
  97.  *
  98.  * removed!
  99.  * removed!
  100.  * removed!
  101.  *
  102.  * removed!
  103.  * removed!
  104.  * removed!
  105.  *
  106.  * removed!
  107.  * removed!
  108.  * removed!
  109.  *
  110.  * removed!
  111.  * removed!
  112.  * removed!
  113.  *
  114.  * removed!
  115.  * removed!
  116.  * removed!
  117.  *
  118.  * removed!
  119.  * removed!
  120.  * removed!
  121.  *
  122.  * removed!
  123.  * removed!
  124.  * removed!
  125.  *
  126.  * removed!
  127.  * removed!
  128.  * removed!
  129.  *
  130.  * removed!
  131.  * removed!
  132.  * removed!
  133.  *
  134.  * removed!
  135.  * removed!
  136.  * removed!
  137.  *
  138.  * removed!
  139.  * removed!
  140.  * removed!
  141.  *
  142.  * removed!
  143.  * removed!
  144.  * removed!
  145.  *
  146.  * removed!
  147.  * removed!
  148.  * removed!
  149.  *
  150.  *------------------------------------------------------------------------------
  151.  * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!! 
  152.  *============================================================================== 
  153.  *******************************************************************************/
  154. /****************************************************************************
  155. * Include Files                                                                
  156. *****************************************************************************/
  157. #include "stdC.h"
  158. #include "MMI_Features.h"
  159. #include "L4Dr.h"
  160. #include "L4Dr1.h"
  161. #include "MiscFunctions.h"
  162. #include "KeyBrd.h"
  163. #include "DebugInitDef.h"
  164. #include "CustDataRes.h"
  165. #include "GlobalConstants.h"
  166. #include "HistoryGprot.h"
  167. #include "DateTimeGprot.h"
  168. #include "CommonScreens.h"
  169. #include "wgui_categories.h"
  170. #include "wgui_categories_multimedia.h"
  171. #include "wgui_categories_idlescreen.h"
  172. #include "wgui_softkeys.h"
  173. #include "IdleAppDef.h"
  174. #include "IdleAppProt.h"
  175. #include "Globaldefs.h"
  176. #include "SettingProfile.h"
  177. #include "SimDetectionGexdcl.h"
  178. #include "SimDetectionGprot.h"
  179. #include "FontRes.h"
  180. #include "SettingGprots.h"
  181. #include "audioinc.h"
  182. #include "gpioInc.h"
  183. #include "SettingProfile.h"
  184. #include "SubLCDHistoryGprot.h"
  185. #include "WPSSProtos.h"
  186. #include "NVRAMType.h"
  187. #include "NVRAMProt.h"
  188. #include "NVRAMEnum.h"
  189. #include "DownloadDefs.h"
  190. #include "QuickAccessMenuItemProt.h"
  191. #include "mdi_datatype.h"
  192. #include "mdi_audio.h"
  193. #include "PhoneSetupGprots.h"
  194. #include "SettingDefs.h"        /* ST_NOTIFYDURATION define */
  195. #include "SettingProfile.h"     /* SUCCESS_TONE define */
  196. #include "GlobalScrEnum.h"      /* GLOBAL_SCR_DUMMY */
  197. #include "Fat_fs.h"
  198. #include "FileSystemDef.h"      /* file function */
  199. #include "FileManagerGProt.h"   /* file path / file error */
  200. #include "FileManagerDef.h"     /* error string id */
  201. #include "StatusIconRes.h"
  202. #include "EventsGprot.h"
  203. #include "TimerEvents.h"
  204. #ifdef __DRM_SUPPORT__
  205. #include "Drm_gprot.h"  /* DRM support */
  206. #endif 
  207. #ifdef MMI_ON_HARDWARE_P
  208. #include "mmi_trc.h"
  209. #include "custom_util.h"
  210. #endif /* MMI_ON_HARDWARE_P */ 
  211. #ifdef __MMI_TOUCH_SCREEN__
  212. #include "TouchScreenGProt.h"
  213. #include "wgui_touch_screen.h"
  214. #endif /* __MMI_TOUCH_SCREEN__ */ 
  215. /****************************************************************************
  216. * Global Variable                                                           
  217. *****************************************************************************/
  218. static BOOL g_scrsvr_is_image;
  219. extern U8 screen_saver_type;
  220. extern idle_context_struct g_idle_context;
  221. #ifndef __MMI_GPIO_DISABLE_SLEEP_MODE__
  222. extern BOOL gIsInSleepMode;
  223. #endif 
  224. /****************************************************************************
  225. * Global Function                                                           
  226. *****************************************************************************/
  227. extern BOOL IsClamClose(void);
  228. /*****************************************************************************
  229. * Local Function 
  230. *****************************************************************************/
  231. #ifdef __MMI_LCD_PARTIAL_ON__
  232. /*****************************************************************************
  233.  * FUNCTION
  234.  *  LeavePartialOnScreenSaverIfOk
  235.  * DESCRIPTION
  236.  *  
  237.  * PARAMETERS
  238.  *  void
  239.  * RETURNS
  240.  *  void
  241.  *****************************************************************************/
  242. void LeavePartialOnScreenSaverIfOk(void)
  243. {
  244.     /*----------------------------------------------------------------*/
  245.     /* Local Variables                                                */
  246.     /*----------------------------------------------------------------*/
  247.     /*----------------------------------------------------------------*/
  248.     /* Code Body                                                      */
  249.     /*----------------------------------------------------------------*/
  250.     if (GetExitScrnID() == SCREEN_SAVER_PARTIAL_ON_ID)
  251.     {
  252.         GoBackHistory();
  253.     }
  254. }
  255. /*****************************************************************************
  256.  * FUNCTION
  257.  *  EnterPartialOnScreenSaverIfOk
  258.  * DESCRIPTION
  259.  *  
  260.  * PARAMETERS
  261.  *  void
  262.  * RETURNS
  263.  *  void
  264.  *****************************************************************************/
  265. void EnterPartialOnScreenSaverIfOk(void)
  266. {
  267.     /*----------------------------------------------------------------*/
  268.     /* Local Variables                                                */
  269.     /*----------------------------------------------------------------*/
  270.     /*----------------------------------------------------------------*/
  271.     /* Code Body                                                      */
  272.     /*----------------------------------------------------------------*/
  273.     if (GetExitScrnID() != SCREEN_SAVER_PARTIAL_ON_ID)
  274.     {
  275.         EntryPartialOnScreenSaver();
  276.     }
  277. }
  278. /*****************************************************************************
  279.  * FUNCTION
  280.  *  RedrawPartialOnScreenSaverIfOk
  281.  * DESCRIPTION
  282.  *  
  283.  * PARAMETERS
  284.  *  void
  285.  * RETURNS
  286.  *  void
  287.  *****************************************************************************/
  288. void RedrawPartialOnScreenSaverIfOk(void)
  289. {
  290.     /*----------------------------------------------------------------*/
  291.     /* Local Variables                                                */
  292.     /*----------------------------------------------------------------*/
  293.     /*----------------------------------------------------------------*/
  294.     /* Code Body                                                      */
  295.     /*----------------------------------------------------------------*/
  296.     if (GetExitScrnID() == SCREEN_SAVER_PARTIAL_ON_ID)
  297.     {
  298.         UI_time t;
  299.         GetDateTime(&t);
  300.         Category161ChangeTime(&t);
  301.         RedrawCategory161Screen();
  302.     }
  303. }
  304. /*****************************************************************************
  305.  * FUNCTION
  306.  *  PartialOnScreenSaverGoBack
  307.  * DESCRIPTION
  308.  *  
  309.  * PARAMETERS
  310.  *  void
  311.  * RETURNS
  312.  *  void
  313.  *****************************************************************************/
  314. static void PartialOnScreenSaverGoBack(void)
  315. {
  316.     /*----------------------------------------------------------------*/
  317.     /* Local Variables                                                */
  318.     /*----------------------------------------------------------------*/
  319.     U16 keycode, keytype;
  320.     /*----------------------------------------------------------------*/
  321.     /* Code Body                                                      */
  322.     /*----------------------------------------------------------------*/
  323.     GetkeyInfo(&keycode, &keytype);
  324.     /* Flush key queue */
  325.     ClearKeyEvents();
  326.     GoBackHistory();
  327.     /* Tricky. Check if the previous screen is keypad locked         */
  328.     /* We can not use g_keylock_context.gKeyPadLockFlag nor g_idle_context.IsRSKPressOnScreenSaver    */
  329.     /* because partial-on screen saver can display on screens other than idle screen. */
  330. #if defined(__MMI_TOUCH_SCREEN__) && (!defined(__MMI_TOUCH_SCREEN_WITH_NUMERIC_KEY__) || defined(__MMI_SLIDE__)) //KP Jerry add "!defined(__MMI_TOUCH_SCREEN_WITH_NUMERIC_KEY__)" on 2007-3-26
  331.     if (keycode == KEY_SEND && GetKeyHandler(keycode, keytype) == EntryScrAfterPessingRSK)
  332.     {
  333.         EntryScrAfterPessingRSK();
  334.     }
  335. #else /* __MMI_TOUCH_SCREEN__ && !__MMI_TOUCH_SCREEN_WITH_NUMERIC_KEY__ */ //KP Jerry add "!__MMI_TOUCH_SCREEN_WITH_NUMERIC_KEY__" on 2007-3-26 
  336. #if defined(__MMI_KEYPAD_LOCK_PATTERN_1__) || defined(__MMI_KEYPAD_LOCK_PATTERN_3__) || defined(__MMI_KEYPAD_LOCK_PATTERN_4__)    //KP Jerry add "__MMI_KEYPAD_LOCK_PATTERN_3__" on 2007-3-27
  337.     if ((get_softkey_function(KEY_EVENT_DOWN, MMI_RIGHT_SOFTKEY) == EntryScrAfterPessingRSK) && (keycode == KEY_RSK))
  338.     {
  339.         EntryScrAfterPessingRSK();
  340.     }
  341. #endif /* __MMI_KEYPAD_LOCK_PATTERN_1__ || __MMI_KEYPAD_LOCK_PATTERN_3__ || __MMI_KEYPAD_LOCK_PATTERN_4__ */      //KP Jerry add "__MMI_KEYPAD_LOCK_PATTERN_3__" on 2007-3-27
  342. #ifdef __MMI_KEYPAD_LOCK_PATTERN_2__
  343.     if ((get_softkey_function(KEY_EVENT_DOWN, MMI_LEFT_SOFTKEY) == EntryScrAfterPessingRSK) && (keycode == KEY_LSK))
  344.     {
  345.         EntryScrAfterPessingRSK();
  346.     }
  347. #endif /* __MMI_KEYPAD_LOCK_PATTERN_2__ */ 
  348. #endif /* __MMI_TOUCH_SCREEN__ && !__MMI_TOUCH_SCREEN_WITH_NUMERIC_KEY__ */ //KP Jerry add "!__MMI_TOUCH_SCREEN_WITH_NUMERIC_KEY__" on 2007-3-26 
  349. }
  350. /*****************************************************************************
  351.  * FUNCTION
  352.  *  ExitPartialOnScreenSaver
  353.  * DESCRIPTION
  354.  *  
  355.  * PARAMETERS
  356.  *  void
  357.  * RETURNS
  358.  *  void
  359.  *****************************************************************************/
  360. static void ExitPartialOnScreenSaver(void)
  361. {
  362.     /*----------------------------------------------------------------*/
  363.     /* Local Variables                                                */
  364.     /*----------------------------------------------------------------*/
  365.     /*----------------------------------------------------------------*/
  366.     /* Code Body                                                      */
  367.     /*----------------------------------------------------------------*/
  368.     /* Tricky. We need at least one dummy exit handler. Otherwise, ExitCategoryFunction wont be invoked. */
  369.     g_idle_context.ScreenSaverRunFlag = 0;
  370.     /* leave_full_screen(); //Already invoked in UI_common_screen_exit() */
  371. }
  372. /*****************************************************************************
  373.  * FUNCTION
  374.  *  EntryPartialOnScreenSaver
  375.  * DESCRIPTION
  376.  *  
  377.  * PARAMETERS
  378.  *  void
  379.  * RETURNS
  380.  *  void
  381.  *****************************************************************************/
  382. void EntryPartialOnScreenSaver(void)
  383. {
  384.     /*----------------------------------------------------------------*/
  385.     /* Local Variables                                                */
  386.     /*----------------------------------------------------------------*/
  387.     UI_time t;
  388.     /*----------------------------------------------------------------*/
  389.     /* Code Body                                                      */
  390.     /*----------------------------------------------------------------*/
  391. #ifndef __MMI_SLIDE__
  392.     if (IsClamClose())
  393.     {
  394.         return;
  395.     }
  396. #endif /* __MMI_SLIDE__ */ 
  397.     if (GetActiveScreenId() == IDLE_SCREEN_ID)
  398.     {
  399.         g_idle_context.ScreenSaverRunFlag = 1;
  400.     }
  401. #if 0
  402. #if !defined(__MMI_GPIO_DISABLE_SLEEP_MODE__)
  403. /* under construction !*/
  404. /* under construction !*/
  405. /* under construction !*/
  406. /* under construction !*/
  407. /* under construction !*/
  408. /* under construction !*/
  409. #endif
  410. #endif /* 0 */ /* #if 0 */
  411.     EntryNewScreen(SCREEN_SAVER_PARTIAL_ON_ID, ExitPartialOnScreenSaver, NULL, NULL);
  412.     entry_full_screen();
  413.     SetGroupKeyHandler(PartialOnScreenSaverGoBack, (PU16) PresentAllKeys, TOTAL_KEYS, KEY_EVENT_DOWN);
  414.     GetDateTime(&t);
  415.     ShowCategory161Screen(&t);
  416. }
  417. #endif /* __MMI_LCD_PARTIAL_ON__ */ 
  418. /*****************************************************************************
  419.  * FUNCTION
  420.  *  mmi_scrsvr_play_video_callback
  421.  * DESCRIPTION
  422.  *  Play screen saver video result callback function
  423.  * PARAMETERS
  424.  *  result      [IN]        
  425.  * RETURNS
  426.  *  void
  427.  *****************************************************************************/
  428. void mmi_scrsvr_play_video_callback(MDI_RESULT result)
  429. {
  430.     /*----------------------------------------------------------------*/
  431.     /* Local Variables                                                */
  432.     /*----------------------------------------------------------------*/
  433.     /*----------------------------------------------------------------*/
  434.     /* Code Body                                                      */
  435.     /*----------------------------------------------------------------*/
  436.     /* treat as gif animation */
  437.     if (result < 0)
  438.     {
  439.         g_idle_context.ScreenSaverRunFlag = 0;  /* FALSE */
  440.         TurnOnBacklight(1);                     /* 1 means restart timer backlight */
  441.         PhnsetScreenSaverBadFileCallBack();     /* reset as default */
  442.     }
  443. }
  444. /*****************************************************************************
  445.  * FUNCTION
  446.  *  mmi_scrsvr_lcd_sleepin_handler
  447.  * DESCRIPTION
  448.  *  Screen saver lcd sleep in handler (sleep in means turn off)
  449.  * PARAMETERS
  450.  *  void
  451.  * RETURNS
  452.  *  void
  453.  *****************************************************************************/
  454. void mmi_scrsvr_lcd_sleepin_handler(void)
  455. {
  456.     /*----------------------------------------------------------------*/
  457.     /* Local Variables                                                */
  458.     /*----------------------------------------------------------------*/
  459.     /*----------------------------------------------------------------*/
  460.     /* Code Body                                                      */
  461.     /*----------------------------------------------------------------*/
  462.     if (g_idle_context.ScreenSaverRunFlag == 1) /* == TRUE */
  463.     {
  464.         g_idle_context.IsScrSvrSleepIn = 1; /* TRUE */
  465.         /* force to enter a dummy screen - which will exit screensaver's screen */
  466.         EntryNewScreen(IDLE_SCREEN_DUMMY_ID, NULL, NULL, NULL);
  467.         /* entry full screen - force mainlcd status bar not update */
  468.         entry_full_screen();
  469.         /* clear full screen as black */
  470.         gdi_layer_clear(GDI_COLOR_BLACK);
  471.         /* force sub to play timer */
  472.         ShowSubLCDScreen(ShowIdleAppSubLcd);
  473.     }
  474. }
  475. /*****************************************************************************
  476.  * FUNCTION
  477.  *  mmi_scrsvr_lcd_sleepout_handler
  478.  * DESCRIPTION
  479.  *  Screen saver lcd sleep out handler (sleep out means turn on)
  480.  * PARAMETERS
  481.  *  void
  482.  * RETURNS
  483.  *  void
  484.  *****************************************************************************/
  485. void mmi_scrsvr_lcd_sleepout_handler(void)
  486. {
  487.     /*----------------------------------------------------------------*/
  488.     /* Local Variables                                                */
  489.     /*----------------------------------------------------------------*/
  490.     /*----------------------------------------------------------------*/
  491.     /* Code Body                                                      */
  492.     /*----------------------------------------------------------------*/
  493.     /* Check if it is in dummy screen */
  494.     /* This function may be called by alarm or other interupt when they try to turn on backlight */
  495.     /* when lcd is already sleep out, so add this protection             */
  496.     if (GetExitScrnID() != IDLE_SCREEN_DUMMY_ID)
  497.     {
  498.         /* stop keypad lock timer if alarm interrupts when LCD backlight is off */
  499.         PRINT_INFORMATION(("[Keypad Lock] ExitIdleScreen: Timer %d Stop", g_idle_context.AutoLockTimeOut));
  500.         StopTimer(IDLE_APP_AUTO_LOCK_TIMER_ID);
  501.         return;
  502.     }
  503.     if (g_idle_context.IsScrSvrSleepIn == 1)    /* == TRUE */
  504.     {
  505.         g_idle_context.IsScrSvrSleepIn = 0;
  506.         EntryIdleSetScreenSaver();
  507.     }
  508. }
  509. #ifdef __MMI_TOUCH_SCREEN__
  510. /*****************************************************************************
  511.  * FUNCTION
  512.  *  mmi_scrsvr_pen_up_handler
  513.  * DESCRIPTION
  514.  *  Screen saver pen up handler
  515.  * PARAMETERS
  516.  *  point       [IN]        
  517.  * RETURNS
  518.  *  void
  519.  *****************************************************************************/
  520. void mmi_scrsvr_pen_up_handler(mmi_pen_point_struct point)
  521. {
  522.     /*----------------------------------------------------------------*/
  523.     /* Local Variables                                                */
  524.     /*----------------------------------------------------------------*/
  525.     /*----------------------------------------------------------------*/
  526.     /* Code Body                                                      */
  527.     /*----------------------------------------------------------------*/
  528.     DisplayIdleScreen();
  529. }
  530. #endif /* __MMI_TOUCH_SCREEN__ */ 
  531. /*****************************************************************************
  532.  * FUNCTION
  533.  *  EntryIdleSetScreenSaver
  534.  * DESCRIPTION
  535.  *  Enter screen saver from idle screenScreen saver pen up handler
  536.  * PARAMETERS
  537.  *  void
  538.  * RETURNS
  539.  *  void
  540.  *****************************************************************************/
  541. void EntryIdleSetScreenSaver(void)
  542. {
  543.     /*----------------------------------------------------------------*/
  544.     /* Local Variables                                                */
  545.     /*----------------------------------------------------------------*/
  546.     U16 cur_screensaver;
  547.     U8 *guiBuffer;
  548.     U16 res_type;
  549.     PS8 filename_ptr = NULL;
  550.     FS_HANDLE fs_handle;
  551.     /*----------------------------------------------------------------*/
  552.     /* Code Body                                                      */
  553.     /*----------------------------------------------------------------*/
  554.     PRINT_INFORMATION(("Screen Saver Timeout"));
  555.     /* if clam is close then want try to enter screen saver, do not enter */
  556. #ifndef __MMI_SLIDE__
  557.     if (IsClamClose())
  558.     {
  559.         return;
  560.     }
  561. #endif /* __MMI_SLIDE__ */ 
  562.     g_idle_context.ScreenSaverRunFlag = 1;
  563. #if !defined(__MMI_GPIO_DISABLE_SLEEP_MODE__)
  564.     if (gIsInSleepMode)
  565.     {
  566.         mmi_scrsvr_lcd_sleepin_handler();
  567.         g_idle_context.ScreenSaverRunFlag = 0;
  568.         return;
  569.     }
  570. #endif /* !defined(__MMI_GPIO_DISABLE_SLEEP_MODE__) */ 
  571.     EntryNewScreen(IDLE_SCREEN_SCREENSAVER_ID, ExitScreenSaver, NULL, NULL);
  572.     guiBuffer = GetCurrGuiBuffer(IDLE_SCREEN_SCREENSAVER_ID);
  573.     g_idle_context.IsRSKPressOnScreenSaver = 0;
  574.     PhnsetGetCurScrSvr(&cur_screensaver);
  575.     if (PhnsetIsScrSvrAnalogClock())
  576.     {
  577.         screen_saver_type = ANALOG_SCREEN_SAVER;
  578.         ShowCategory131Screen(cur_screensaver, NULL);
  579.     }
  580.     else if (PhnsetIsScrSvrDigitalClock())
  581.     {
  582.         screen_saver_type = DIGITAL_SCREEN_SAVER;
  583.         ShowCategory131Screen(cur_screensaver, NULL);
  584.     }
  585. #ifdef __MMI_THEMES_V2_SUPPORT__
  586.     else if (PhnsetIsScrSvrCurrentTheme())
  587.     {
  588.         ShowCategory166Screen(cur_screensaver, filename_ptr, NULL);
  589.     }
  590. #endif /* __MMI_THEMES_V2_SUPPORT__ */ 
  591.     else
  592.     {
  593.         /* play image or video */
  594.       /*******************************************/
  595.         /* Get animation resource from phone setup */
  596.       /*******************************************/
  597.         if (cur_screensaver == 0xff)    /* invalid format */
  598.         {
  599.             /* reset as default */
  600.             PhnsetScreenSaverBadFileCallBack();
  601.             return;
  602.         }
  603.     #if defined(__MMI_FILE_MANAGER__)
  604.         else if (cur_screensaver == 0x00 || /* source from file */
  605.                  cur_screensaver == 0x01)   /* short file name */
  606.         {
  607.             PS8 error;
  608.             cur_screensaver = 0x00;
  609.             /* filename buffer is allocated in phnset */
  610.             filename_ptr = PhnsetGetCurScrSvrFileName();
  611.             if (!mmi_fmgr_util_file_limit_check(FMGR_LIMIT_SCREEN_SAVER, filename_ptr, &error))
  612.             {
  613.                 /* limit check failed */
  614.                 /* reset to default */
  615.                 PhnsetScreenSaverBadFileCallBack();
  616.                 return;
  617.             }
  618.         }
  619.     #endif /* __MMI_FILE_MANAGER__ */
  620.         else
  621.         {
  622.             /* source from intenal resource */
  623.             filename_ptr = NULL;
  624.         }
  625.       /*******************************************/
  626.         /* Check if is image or video              */
  627.       /*******************************************/
  628. #if defined(__MMI_FILE_MANAGER__)
  629.         /* get file resource type */
  630.         if (filename_ptr != NULL)
  631.         {
  632.             /* source from file */
  633.             res_type = mmi_fmgr_get_file_group(filename_ptr);
  634.             if (res_type == FMGR_GROUP_IMAGE)
  635.             {
  636.                 g_scrsvr_is_image = TRUE;
  637.             }
  638.             else if (res_type == FMGR_GROUP_VIDEO)
  639.             {
  640.                 g_scrsvr_is_image = FALSE;
  641.             }
  642.         #ifdef __MMI_SWFLASH__
  643.             else if (res_type == FMGR_GROUP_SWFLASH)
  644.             {
  645.                 g_scrsvr_is_image = TRUE;
  646.             }
  647.         #endif /* __MMI_SWFLASH__ */
  648.             else
  649.             {
  650.                 /* unsupported file format ext */
  651.                 /* reset as default */
  652.                 PhnsetScreenSaverBadFileCallBack();
  653.                 return;
  654.             }
  655.             
  656.         #ifdef __DRM_SUPPORT__
  657.             {
  658.             
  659.                 MMI_BOOL is_permitted = MMI_FALSE;
  660.                 /* DRM permission check */
  661.                 if ((fs_handle = DRM_open_file((PU16) filename_ptr, FS_READ_ONLY, DRM_PERMISSION_NONE)) >= FS_NO_ERROR)
  662.                 {
  663.                     if (res_type == FMGR_GROUP_IMAGE && DRM_validate_permission(fs_handle, DRM_PERMISSION_DISPLAY))
  664.                     {
  665.                         DRM_consume_rights(fs_handle, DRM_PERMISSION_DISPLAY);
  666.                         is_permitted = MMI_TRUE;
  667.                     }
  668.                 #ifdef __MMI_SWFLASH__
  669.                     else if (res_type == FMGR_GROUP_SWFLASH && DRM_validate_permission(fs_handle, DRM_PERMISSION_DISPLAY))
  670.                     {
  671.                         DRM_consume_rights(fs_handle, DRM_PERMISSION_DISPLAY);
  672.                         is_permitted = MMI_TRUE;
  673.                     }
  674.                 #endif                        
  675.                     else if (res_type == FMGR_GROUP_VIDEO && DRM_validate_permission(fs_handle, DRM_PERMISSION_PLAY))
  676.                     {
  677.                         DRM_consume_rights(fs_handle, DRM_PERMISSION_PLAY);
  678.                         is_permitted = MMI_TRUE;
  679.                     }
  680.                     DRM_close_file(fs_handle);
  681.                 }
  682.                 else if (fs_handle < FS_NO_ERROR)   /* file open error but not DRM related problem */
  683.                 {
  684.                     /* To determine DRM right or image problem */
  685.                     fs_handle = FS_Open((U16*) filename_ptr, FS_READ_ONLY);
  686.                     if (fs_handle >= FS_NO_ERROR)
  687.                     {
  688.                         is_permitted = MMI_FALSE;   /* DRM right problem */
  689.                         FS_Close(fs_handle);
  690.                     }
  691.                     else
  692.                     {
  693.                         is_permitted = MMI_TRUE;    /* image problem */
  694.                     }
  695.             
  696.                 }
  697.             
  698.                 /* if not permitted */
  699.                 if (!is_permitted)
  700.                 {
  701.             
  702.                     PhnsetRstScrSvrDefault();
  703.             
  704.                     /* no permission to display */
  705.                     DisplayPopup((PU8) GetString(STR_GLOBAL_DRM_PROHIBITED), IMG_GLOBAL_ERROR, 0, 1000, ERROR_TONE);
  706.                     DeleteNHistory(1);
  707.                     return;
  708.                 }
  709.             }
  710.         #else /* __DRM_SUPPORT__ */ 
  711.             fs_handle = FS_Open((U16*) filename_ptr, FS_READ_ONLY);
  712.         
  713.             if (fs_handle < FS_NO_ERROR)
  714.             {
  715.                 /* open file failed */
  716.                 /* reset as default */
  717.                 PhnsetScreenSaverBadFileCallBack();
  718.                 return;
  719.             }
  720.             else
  721.             {
  722.                 /* open file successful */
  723.                 FS_Close(fs_handle);
  724.             }
  725.         #endif /* __DRM_SUPPORT__ */ 
  726.             
  727.         }
  728. #endif /* __MMI_FILE_MANAGER__ */
  729.         /* check internal resource type */
  730.         if (filename_ptr == NULL)
  731.         {
  732.             res_type = PhnsetGetDisplayType(cur_screensaver);
  733.             if (res_type == PHNSET_TYPE_DISP_IMAGE)
  734.             {
  735.                 g_scrsvr_is_image = TRUE;
  736.                 res_type = FMGR_GROUP_IMAGE;
  737.             }
  738.             else if (res_type == PHNSET_TYPE_DISP_VIDEO)
  739.             {
  740.                 g_scrsvr_is_image = FALSE;
  741.                 res_type = FMGR_GROUP_VIDEO;
  742.             }
  743.         #ifdef __MMI_SWFLASH__
  744.             else if (res_type == PHNSET_TYPE_DISP_SWFLASH)
  745.             {
  746.                 g_scrsvr_is_image = FALSE;
  747.                 res_type = FMGR_GROUP_SWFLASH;
  748.             }
  749.         #endif /* __MMI_SWFLASH__ */
  750.             else
  751.             {
  752.                 MMI_ASSERT(0);
  753.             }
  754.         }
  755.       /*******************************************/
  756.         /* Start to play                           */
  757.       /*******************************************/
  758.         if (res_type == FMGR_GROUP_IMAGE)
  759.         {
  760.             /* Play GIF animation or still image */
  761.             ShowCategory166Screen(cur_screensaver, filename_ptr, NULL);
  762.         }
  763.         else if (res_type == FMGR_GROUP_VIDEO)
  764.         {
  765.             /* Play video clip */
  766.         #if defined(__MMI_VIDEO_PLAYER__)
  767.             /* entry video play full screen */
  768.             ShowCategory224Screen(
  769.                 cur_screensaver,                /* video id */
  770.                 filename_ptr,                   /* filename */
  771.                 0,                              /* repeat_count *//* 0 means infinite */
  772.                 MMI_TRUE,                       /* is_visaul_update */
  773.                 MMI_FALSE,                      /* is_play_audio */
  774.                 MMI_FALSE,                      /* is_lcd_no_sleep *//* need sleep in */
  775.                 GDI_COLOR_BLACK,                /* bg_color */
  776.                 mmi_scrsvr_play_video_callback, /* (*play_finish_callback)(S16) */
  777.                 NULL);                          /* gui_buffer */
  778.             /* category 224 will stop lcd sleep mechansim, we must let MMI can sleep in */
  779.         #else /* defined(__MMI_VIDEO_PLAYER__) */ 
  780.             MMI_ASSERT(0);
  781.         #endif /* defined(__MMI_VIDEO_PLAYER__) */ 
  782.         }
  783.     #ifdef __MMI_SWFLASH__
  784.         else if (res_type == FMGR_GROUP_SWFLASH)
  785.         {
  786.             ShowCategory229Screen(
  787.                 0,                      /* title_str */
  788.                 0,            /* title_icon */
  789.                 0,                      /* lsk_str */
  790.                 0,                      /* lsk_icon */
  791.                 0,                    /* rsk_str */
  792.                 0,                    /* rsk_icon */
  793.                 cur_screensaver,                        /* resource_id */
  794.                 filename_ptr,                               /* resource_filename */
  795.                 1,                                  /* repeat_count */
  796.                 0,                          /* is_play_audio */
  797.                 0,                          /* is_vibrate_on */
  798.                 0,                          /* is_interaction_on */
  799.                 0,                           /* is_lcd_no_sleep */
  800.                 MMI_TRUE,                          /* is_full_screen */
  801.                 GDI_COLOR_WHITE,                    /* bg_color */
  802.                 PhnsetWpSsPlayCallBack,
  803.                 guiBuffer);
  804.             
  805.         }
  806.     #endif
  807.     }
  808.     SetGroupKeyHandler(
  809.         IdleScreenSaverGroupKeyHandler,
  810.         (PU16) PresentAllKeys /* ScreenSaverLocks */ ,
  811.         (U8) TOTAL_KEYS /* MAX_KEYS - 3 */ ,
  812.         KEY_EVENT_DOWN);
  813. #ifdef __MMI_TOUCH_SCREEN__
  814.     wgui_register_pen_up_handler(mmi_scrsvr_pen_up_handler);
  815.     wgui_register_pen_down_handler(mmi_pen_dummy_hdlr);
  816.     wgui_register_pen_move_handler(mmi_pen_dummy_hdlr);
  817.     wgui_register_pen_abort_handler(mmi_pen_dummy_hdlr);
  818.     wgui_register_pen_repeat_handler(mmi_pen_dummy_hdlr);
  819.     wgui_register_pen_long_tap_handler(mmi_pen_dummy_hdlr);
  820. #endif /* __MMI_TOUCH_SCREEN__ */ 
  821.     /* keypad lock key handler */
  822.     if (g_keylock_context.gKeyPadLockFlag != 0) /*  If KeyPad Locked */
  823.     {
  824.     #if defined(__MMI_TOUCH_SCREEN__) && (!defined(__MMI_TOUCH_SCREEN_WITH_NUMERIC_KEY__) || defined(__MMI_SLIDE__))     //KP Jerry add "!defined(__MMI_TOUCH_SCREEN_WITH_NUMERIC_KEY__)" on 2007-3-26
  825.         SetKeyHandler(IdleRSKPressOnScreenSaver, KEY_SEND, KEY_EVENT_DOWN);
  826.     #else /* __MMI_TOUCH_SCREEN__ && !__MMI_TOUCH_SCREEN_WITH_NUMERIC_KEY__ */ //KP Jerry add "!__MMI_TOUCH_SCREEN_WITH_NUMERIC_KEY__" on 2007-3-26 
  827.     #if defined(__MMI_KEYPAD_LOCK_PATTERN_1__) || defined(__MMI_KEYPAD_LOCK_PATTERN_3__) || defined(__MMI_KEYPAD_LOCK_PATTERN_4__)    //KP Jerry add "__MMI_KEYPAD_LOCK_PATTERN_3__" on 2007-3-27
  828.         SetKeyHandler(IdleRSKPressOnScreenSaver, KEY_RSK, KEY_EVENT_DOWN);
  829.     #endif 
  830.     #ifdef __MMI_KEYPAD_LOCK_PATTERN_2__
  831.         SetKeyHandler(IdleRSKPressOnScreenSaver, KEY_LSK, KEY_EVENT_DOWN);
  832.     #endif 
  833.     #endif /* __MMI_TOUCH_SCREEN__ && !__MMI_TOUCH_SCREEN_WITH_NUMERIC_KEY__ */ //KP Jerry add "!__MMI_TOUCH_SCREEN_WITH_NUMERIC_KEY__" on 2007-3-26 
  834.     }
  835. }
  836. /*****************************************************************************
  837.  * FUNCTION
  838.  *  ExitScreenSaver
  839.  * DESCRIPTION
  840.  *  Exit function for screen saver.
  841.  * PARAMETERS
  842.  *  void
  843.  * RETURNS
  844.  *  void
  845.  *****************************************************************************/
  846. void ExitScreenSaver(void)
  847. {
  848.     /*----------------------------------------------------------------*/
  849.     /* Local Variables                                                */
  850.     /*----------------------------------------------------------------*/
  851.     /*----------------------------------------------------------------*/
  852.     /* Code Body                                                      */
  853.     /*----------------------------------------------------------------*/
  854.     g_idle_context.ScreenSaverRunFlag = 0;
  855.     if (!g_idle_context.IsScrSvrSleepIn)
  856.     {
  857.         StopTimer(IDLE_APP_AUTO_LOCK_TIMER_ID); /* diamond, 2006/02/07 Keypad lock timer should be stopped because screensaver may be interrupted by a call */
  858.     }
  859. }
  860. /*****************************************************************************
  861.  * FUNCTION
  862.  *  IdleScreenSaverGroupKeyHandler
  863.  * DESCRIPTION
  864.  *  Group key handler fn for screen saver keys.
  865.  * PARAMETERS
  866.  *  void
  867.  * RETURNS
  868.  *  void
  869.  *****************************************************************************/
  870. void IdleScreenSaverGroupKeyHandler(void)
  871. {
  872.     /*----------------------------------------------------------------*/
  873.     /* Local Variables                                                */
  874.     /*----------------------------------------------------------------*/
  875.     /*----------------------------------------------------------------*/
  876.     /* Code Body                                                      */
  877.     /*----------------------------------------------------------------*/
  878.     DisplayIdleScreen();
  879. }
  880. /*****************************************************************************
  881.  * FUNCTION
  882.  *  IdleRSKPressOnScreenSaver
  883.  * DESCRIPTION
  884.  *  This function tells if RSk has been pressed on idle screen.
  885.  * PARAMETERS
  886.  *  void
  887.  * RETURNS
  888.  *  void
  889.  *****************************************************************************/
  890. void IdleRSKPressOnScreenSaver(void)
  891. {
  892.     /*----------------------------------------------------------------*/
  893.     /* Local Variables                                                */
  894.     /*----------------------------------------------------------------*/
  895.     /*----------------------------------------------------------------*/
  896.     /* Code Body                                                      */
  897.     /*----------------------------------------------------------------*/
  898.     g_idle_context.IsRSKPressOnScreenSaver = 1;
  899.     EntryIdleScreen();
  900. }