BootupFlow.c 31.4 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937
/*****************************************************************************
*  Copyright Statement:
*  --------------------
*  This software is protected by Copyright and the information contained
*  herein is confidential. The software may not be copied and the information
*  contained herein may not be used or disclosed except with the written
*  permission of MediaTek Inc. (C) 2005
*
*  BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
*  THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
*  RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
*  AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
*  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
*  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
*  NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
*  SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
*  SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
*  THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
*  NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
*  SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
*
*  BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
*  LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
*  AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
*  OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
*  MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
*
*  THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
*  WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
*  LAWS PRINCIPLES.  ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
*  RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
*  THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
*
*****************************************************************************/
/*****************************************************************************
 *
 * Filename:
 * ---------
 *  BootupFlow.c
 *
 * Project:
 * --------
 *  MAUI
 *
 * Description:
 * ------------
 *  Bootup flow control
 *
 * Author:
 * -------
 * -------
 *
 *============================================================================
 *             HISTORY
 * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
 *------------------------------------------------------------------------------
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 *------------------------------------------------------------------------------
 * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
 *============================================================================
 ****************************************************************************/

/****************************************************************************
 * Include
 ****************************************************************************/

#include "BootupSrvIprot.h"
#include "ProcedureGprot.h"
#include "ShutdownSrvGprot.h"
#include "BootupAppProt.h"
#include "GpioSrvGprot.h" /* srv_vibrator_play_once */
#include "ProcedureConfig.h"
#include "MMI_features.h"
#include "MMIDataType.h"
#include "kal_general_types.h"
#include "BootupSrvGprot.h"
#include "kal_public_api.h"
#include "DebugInitDef_Int.h"
#include "MMI_common_app_trc.h"
#include "kal_trace.h"
#include "mmi_common_app_trc.h"
#include "mmi_frm_timer_gprot.h"
#include "mmi_frm_scenario_gprot.h"
#include "mmi_rp_app_bootup_def.h"
#include "mmi_frm_events_gprot.h"
#include "wgui_categories.h"
#include "BootupScrUtil.h"
#include "GlobalResDef.h"
#include "BootupAppGprot.h"
#include "string.h"
#include "mmi_cb_mgr_gprot.h"
#include "custom_led_patterns.h"
#include "gpiosrvgprot.h"
#include "IdleGprot.h"


/****************************************************************************
 * Constants
 ****************************************************************************/

#define MMI_BOOTUP_WAITING_TIMEOUT_VALUE 2000 /* ms */


/****************************************************************************
 * Flow configurations
 ****************************************************************************/

/*
 * Configuration dependency:
 *
 * EARLY_INIT   -> DISK_CHECK
 *              -> ANIMATION
 *              -> PEN CALIBRATION
 *              -> Any UI screens
 * INIT_SIM_MODULE   -> MODE_DECISION    -> PROTOCOL     -> SECURITY
 */

/* ------ Waiting for events ------ */

static mmi_frm_proc_result_enum mmi_bootup_start_events_timer(
                                    void *arg,
                                    const mmi_frm_proc_id_info_struct id_info);

static mmi_frm_proc_ctrl_enum mmi_bootup_events_stop_on_timeout(
    void *user_data,
    const mmi_frm_proc_set_status_struct *info);

MMI_FRM_PROC_CON_DECLARE_BEGIN(g_bootup_waiting_con_proc)
    MMI_FRM_PROC_CON_ENTRY(MMI_FRM_PROC_ID_BOOTUP_WAITING_TIMER, mmi_bootup_start_events_timer, NULL)
    MMI_FRM_PROC_CON_ENTRY(MMI_FRM_PROC_ID_BOOTUP_WAIT_FOR_GPIO, mmi_bootup_wait_for_gpio, NULL)
MMI_FRM_PROC_CON_DECLARE_END(g_bootup_waiting_con_proc, mmi_bootup_events_stop_on_timeout, NULL)


/* ------ Animation ------ */

MMI_FRM_PROC_CON_DECLARE_BEGIN(g_bootup_animation_phase)
#if (defined (__MOD_RAC__) && defined (__MMI_TELEPHONY_SUPPORT__))
    MMI_FRM_PROC_CON_ENTRY(MMI_FRM_PROC_ID_BOOTUP_PROTOCOL, mmi_bootup_boot_protocol, NULL)
#endif /* __MOD_RAC__ */
    MMI_FRM_PROC_CON_ENTRY(MMI_FRM_PROC_ID_BOOTUP_ANIMATION, mmi_bootup_play_animation, NULL)
    /*
     * NORMAL_INIT should be the last entry, because:
     * 1. It is a time-consuming blocking function. As we call it, following procedures should be
     *    delayed to it completes
     * 2. Apps in NORMAL_INIT may determines the state set in boot_protocol()
     */
    MMI_FRM_PROC_CON_ENTRY(MMI_FRM_PROC_ID_BOOTUP_NORMAL_INIT, mmi_bootup_normal_init, NULL)
MMI_FRM_PROC_CON_DECLARE_END(g_bootup_animation_phase, mmi_bootup_ani_notify_completion_info, NULL)


/* ------ Main flow ------ */

static mmi_frm_proc_result_enum mmi_bootup_flow_early_init(
                                    void *arg,
                                    const mmi_frm_proc_id_info_struct id_info);

static mmi_frm_proc_result_enum mmi_bootup_flow_disable_interrupt(
                                    void *arg,
                                    const mmi_frm_proc_id_info_struct id_info);

static mmi_frm_proc_result_enum mmi_bootup_flow_enable_interrupt(
                                    void *arg,
                                    const mmi_frm_proc_id_info_struct id_info);

static const mmi_frm_proc_struct g_mmi_bootup_main_flow[] =
{
    { MMI_FRM_PROC_ID_BOOTUP_WAIT_FOR_EVENTS, mmi_frm_proc_con_create_and_execute, (void*)&(g_bootup_waiting_con_proc) },
    { MMI_FRM_PROC_ID_BOOTUP_EARLY_INIT, mmi_bootup_flow_early_init, NULL },
    { MMI_FRM_PROC_ID_BOOTUP_DISABLE_INTERRUPT, mmi_bootup_flow_disable_interrupt, NULL },
#if (MMI_MAX_SIM_NUM >= 2)
    { MMI_FRM_PROC_ID_BOOTUP_INIT_SIM, mmi_bootup_flow_init_sim_module, NULL },
#endif
#ifdef __MMI_TELEPHONY_SUPPORT__
    { MMI_FRM_PROC_ID_BOOTUP_MODE_DECISION, mmi_bootup_decide_mode, NULL },
#endif    
    { MMI_FRM_PROC_ID_BOOTUP_ANI_PHASE, mmi_frm_proc_con_create_and_execute, (void*)&(g_bootup_animation_phase) },
    { MMI_FRM_PROC_ID_BOOTUP_ENABLE_INTERRUPT, mmi_bootup_flow_enable_interrupt, NULL },
#ifdef __MMI_TOUCH_SCREEN__
    { MMI_FRM_PROC_ID_BOOTUP_PEN_CALIBRATION, mmi_bootup_flow_pen_calibration, NULL },
#endif
    { MMI_FRM_PROC_ID_BOOTUP_BATTERY_CHECK, mmi_bootup_flow_battery_check, NULL },
#ifdef __MMI_TELEPHONY_SUPPORT__
    { MMI_FRM_PROC_ID_BOOTUP_SECURITY, mmi_bootup_flow_security, NULL },
#endif    
#ifdef __GADGET_SUPPORT__
    { MMI_FRM_PROC_ID_BOOTUP_PREINSTALL_WIDGET, mmi_wgtmgr_preinstall_widget, NULL },
#endif
#if (defined (__MMI_BT_DIALER_SUPPORT__) && !defined(__MMI_BTD_BOX_UI_STYLE__))
    { MMI_FRM_PROC_ID_BOOTUP_FTU, mmi_bootup_flow_ftu, NULL }
#endif
};


/****************************************************************************
 * Typedef
 ****************************************************************************/

typedef struct
{
    mmi_frm_proc_struct *main_flow;

    struct
    {
        MMI_BOOL timeout;
        mmi_frm_proc_id_info_struct id_info;
    } events_timer;

    struct
    {
        mmi_frm_proc_id_info_struct id_info;
    } disk_check;

    struct
    {
        S8 disabled_count;
    } interrupt;
} mmi_bootup_flow_cntx_struct;


/****************************************************************************
 * Global variables
 ****************************************************************************/

static mmi_bootup_flow_cntx_struct g_mmi_bootup_flow_cntx;


/****************************************************************************
 * Local functions
 ****************************************************************************/

static void mmi_bootup_events_timer_timeout(void);
static mmi_ret mmi_bootup_flow_completed(mmi_event_struct *evt);
static void mmi_bootup_disk_check_completed(void *user_data, S32 error_code);
static mmi_frm_proc_ctrl_enum mmi_bootup_flow_stop_check(
    void *user_data,
    const mmi_frm_proc_set_status_struct *set_status);


/*****************************************************************************
 * FUNCTION
 *  mmi_bootup_flow_start
 * DESCRIPTION
 *  Start booting flow.
 *  This function is the handler of EVT_ID_BOOTUP_START.
 * PARAMETERS
 *  evt     [IN] srv_bootup_start_evt_struct*
 * RETURNS
 *  Always MMI_RET_OK
 *****************************************************************************/
mmi_ret mmi_bootup_flow_start(mmi_event_struct *evt)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    MMI_ASSERT(evt->evt_id == EVT_ID_SRV_BOOTUP_START);

    MMI_TRACE(MMI_BOOTUP_TRC_GROUP, TRC_MMI_BOOTUP_FLOW_START);

    g_mmi_bootup_flow_cntx.interrupt.disabled_count = 0;

    g_mmi_bootup_flow_cntx.main_flow = mmi_frm_proc_seq_create(
        mmi_frm_proc_allocate_id(),
        g_mmi_bootup_main_flow,
        sizeof(g_mmi_bootup_main_flow) / sizeof(g_mmi_bootup_main_flow[0]));

    mmi_frm_proc_seq_set_status_callback(
        g_mmi_bootup_flow_cntx.main_flow,
        mmi_bootup_flow_stop_check,
        &(g_mmi_bootup_flow_cntx));

    mmi_frm_proc_post_complete_execute(
        MMI_FRM_PROC_ID_BOOTUP_MAIN,
        mmi_bootup_flow_completed,
        &(g_mmi_bootup_flow_cntx),
        g_mmi_bootup_flow_cntx.main_flow);

    return MMI_RET_OK;
}


/*****************************************************************************
 * FUNCTION
 *  mmi_bootup_events_all_completed_or_timeout
 * DESCRIPTION
 *  The complete condition of event waiting.
 *  Waiting for all events until timeout.
 * PARAMETERS
 *  user_data   [IN] Not used
 *  info        [IN] Information of completion.
 * RETURNS
 *  MMI_FRM_PROC_CTRL_STOP if timeout
 *****************************************************************************/
static mmi_frm_proc_ctrl_enum mmi_bootup_events_stop_on_timeout(
    void *user_data,
    const mmi_frm_proc_set_status_struct *info)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (info->n_completed >= (info->n_total_procs - 1) ||
        g_mmi_bootup_flow_cntx.events_timer.timeout)
    {
        return MMI_FRM_PROC_CTRL_STOP;
    }

    return MMI_FRM_PROC_CTRL_CONTINUE;
}


/*****************************************************************************
 * FUNCTION
 *  mmi_bootup_start_events_timer
 * DESCRIPTION
 *  Start the timer of event waiting.
 * PARAMETERS
 *  arg         [IN] Not used
 *  if_info     [IN] To be carried back to mmi_frm_proc_notify_completed()
 * RETURNS
 *  MMI_FRM_PROC_RESULT_NOTIFY_LATER
 *****************************************************************************/
static mmi_frm_proc_result_enum mmi_bootup_start_events_timer(
    void *arg,
    const mmi_frm_proc_id_info_struct id_info)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    g_mmi_bootup_flow_cntx.events_timer.timeout = MMI_FALSE;
    g_mmi_bootup_flow_cntx.events_timer.id_info = id_info;

    StartTimer(BOOTUP_WAITING_EVENT_TIMER, MMI_BOOTUP_WAITING_TIMEOUT_VALUE, mmi_bootup_events_timer_timeout);

    return MMI_FRM_PROC_RESULT_NOTIFY_LATER;
}


/*****************************************************************************
 * FUNCTION
 *  mmi_bootup_events_timer_timeout
 * DESCRIPTION
 *  Timeout callback of event timer
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
static void mmi_bootup_events_timer_timeout(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    MMI_TRACE(MMI_BOOTUP_TRC_GROUP, TRC_MMI_BOOTUP_EVENT_TIMER_TIMEOUT);
    
    g_mmi_bootup_flow_cntx.events_timer.timeout = MMI_TRUE;
    mmi_frm_proc_notify_completed(g_mmi_bootup_flow_cntx.events_timer.id_info);
}


/*****************************************************************************
 * FUNCTION
 *  mmi_bootup_entry_dummy_base_screen
 * DESCRIPTION
 *  Put a dummy base screen in history.
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
static void mmi_bootup_entry_dummy_base_screen(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (!mmi_frm_scrn_enter(
        GRP_ID_BOOTUP,
        SCR_ID_BOOTUP_BASE,
        NULL,
        mmi_bootup_entry_dummy_base_screen,
        MMI_FRM_FULL_SCRN))
    {
        return;
    }

    ShowCategoryDummyScreen();

    mmi_frm_scrn_set_key_proc(GRP_ID_BOOTUP, SCR_ID_BOOTUP_BASE, mmi_bootup_block_all_keys);
}


/*****************************************************************************
 * FUNCTION
 *  mmi_bootup_flow_early_init
 * DESCRIPTION
 *  Early initialize & disk check.
 * PARAMETERS
 *  arg         [IN] Unused
 *  id_info     [IN] To be carried back to mmi_frm_proc_notify_completed()
 * RETURNS
 *  void
 *****************************************************************************/
static mmi_frm_proc_result_enum mmi_bootup_flow_early_init(
                                    void *arg,
                                    const mmi_frm_proc_id_info_struct id_info)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    MMI_TRACE(MMI_BOOTUP_TRC_GROUP, TRC_MMI_BOOTUP_FLOW_EARLY_INIT);
    
    StopTimer(BOOTUP_WAITING_EVENT_TIMER);

#ifdef __MMI_POWER_ON_OFF_MUTE__
    srv_vibrator_play_once();
#endif
    
    mmi_bootup_early_init();

    mmi_frm_group_create(GRP_ID_ROOT, GRP_ID_BOOTUP, NULL, NULL);
    mmi_frm_group_enter(GRP_ID_BOOTUP, MMI_FRM_NODE_NONE_FLAG);
    /*
     * Put a dummy base screen on bottom, so that history manipulation
     * can be performed normally.
     */
    mmi_bootup_entry_dummy_base_screen();
    mmi_frm_scrn_set_leave_proc(GRP_ID_BOOTUP, SCR_ID_BOOTUP_BASE, mmi_bootup_block_scr_deleting);

#if defined(__MMI_SUBLCD__)
    /* Display the bootup animation on the sub-LCD screen. */
    ForceSubLCDScreen(mmi_bootup_sublcd_entry);
#endif /* #if defined(__MMI_SUBLCD__) */

    /* Disk check */
    g_mmi_bootup_flow_cntx.disk_check.id_info = id_info;
    mmi_bootup_check_disk(
        GRP_ID_BOOTUP,
        mmi_bootup_disk_check_completed,
        &(g_mmi_bootup_flow_cntx.disk_check.id_info));

    return MMI_FRM_PROC_RESULT_NOTIFY_LATER;
}


/*****************************************************************************
 * FUNCTION
 *  mmi_bootup_disk_check_completed
 * DESCRIPTION
 *  The completed callback of disk check.
 * PARAMETERS
 *  user_data   [IN] Unused
 *  error_code  [IN] Error code from file system while checking disk
 * RETURNS
 *  void
 *****************************************************************************/
static void mmi_bootup_disk_check_completed(void *user_data, S32 error_code)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    MMI_TRACE(MMI_BOOTUP_TRC_GROUP, TRC_MMI_BOOTUP_DISK_CHECK_COMPLETED, error_code);
    
    mmi_frm_proc_notify_completed(
        g_mmi_bootup_flow_cntx.disk_check.id_info);
}


/*****************************************************************************
 * FUNCTION
 *  mmi_bootup_emit_interruptible_event
 * DESCRIPTION
 *  Emit interruptable_changed event.
 * PARAMETERS
 *  post_event      [IN] Emit event by post mechanism
 * RETURNS
 *  void
 *****************************************************************************/
static void mmi_bootup_emit_interruptible_event(MMI_BOOL post_event)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    mmi_bootup_interruptible_changed_evt_struct changed_evt;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    
    MMI_FRM_INIT_EVENT(&changed_evt, EVT_ID_MMI_BOOTUP_INTERRUPTIBLE_CHANGED);
    
    changed_evt.is_interruptible = mmi_bootup_is_interruptible();

    MMI_TRACE(MMI_BOOTUP_TRC_GROUP, TRC_MMI_BOOTUP_EMIT_INTERRUPTIBLE_EVENT,
        changed_evt.is_interruptible, post_event);
    
    if (post_event)
    {
        MMI_FRM_CB_EMIT_POST_EVENT(&changed_evt);
    }
    else
    {
        MMI_FRM_CB_EMIT_EVENT(&changed_evt);
    }
}


/*****************************************************************************
 * FUNCTION
 *  mmi_bootup_disable_interrupt
 * DESCRIPTION
 *  Disable interrupt
 * PARAMETERS
 *  post_event      [IN] Emit event by post mechanism
 * RETURNS
 *  void
 *****************************************************************************/
// slim_static
static void mmi_bootup_disable_interrupt(MMI_BOOL post_event)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    g_mmi_bootup_flow_cntx.interrupt.disabled_count++;
    
    if (g_mmi_bootup_flow_cntx.interrupt.disabled_count == 1)
    {
        mmi_bootup_emit_interruptible_event(post_event);
    }
}


/*****************************************************************************
 * FUNCTION
 *  mmi_bootup_enable_interrupt
 * DESCRIPTION
 *  Enable interrupt. Enable/disable maintains a counter of disables.
 * PARAMETERS
 *  post_event      [IN] Emit event by post mechanism
 * RETURNS
 *  void
 *****************************************************************************/
// slim_static
static void mmi_bootup_enable_interrupt(MMI_BOOL post_event)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    g_mmi_bootup_flow_cntx.interrupt.disabled_count--;
    
    if (g_mmi_bootup_flow_cntx.interrupt.disabled_count == 0)
    {
        mmi_bootup_emit_interruptible_event(post_event);
    }
}


/*****************************************************************************
 * FUNCTION
 *  mmi_bootup_set_scenario_for_interrupt
 * DESCRIPTION
 *  Set framework scenario to launch deferred interrupts.
 * PARAMETERS
 *  evt     [IN] 
 * RETURNS
 *  void
 *****************************************************************************/
mmi_ret mmi_bootup_set_scenario_for_interrupt(mmi_event_struct *evt)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    mmi_bootup_interruptible_changed_evt_struct *changed_evt;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    changed_evt = (mmi_bootup_interruptible_changed_evt_struct*)evt;

    if (!changed_evt->is_interruptible)
    {
        mmi_frm_start_scenario(MMI_SCENARIO_ID_HIGHEST_SCRN);
    }
    else
    {
        mmi_frm_end_scenario(MMI_SCENARIO_ID_HIGHEST_SCRN);
    }

    return MMI_RET_OK;
}


/*****************************************************************************
 * FUNCTION
 *  mmi_bootup_flow_disable_interrupt
 * DESCRIPTION
 *  Disable interrupt in bootup flow.
 * PARAMETERS
 *  arg         [IN] Unused
 *  id_info     [IN] Unused
 * RETURNS
 *  void
 *****************************************************************************/
static mmi_frm_proc_result_enum mmi_bootup_flow_disable_interrupt(
                                    void *arg,
                                    const mmi_frm_proc_id_info_struct id_info)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    
    /*
     * Disallow all interrupts until animation completed
     */
    mmi_bootup_disable_interrupt(MMI_FALSE);

    return MMI_FRM_PROC_RESULT_COMPLETED;
}


/*****************************************************************************
 * FUNCTION
 *  mmi_bootup_flow_enable_interrupt
 * DESCRIPTION
 *  Enable interrupt in bootup flow.
 * PARAMETERS
 *  arg         [IN] Unused
 *  id_info     [IN] Unused
 * RETURNS
 *  void
 *****************************************************************************/
static mmi_frm_proc_result_enum mmi_bootup_flow_enable_interrupt(
                                    void *arg,
                                    const mmi_frm_proc_id_info_struct id_info)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/

    /*
     * As this event emitted, some screen may be triggered.
     * In order to avoid interrupt our control flow, emit as post
     * event here.
     */
    mmi_bootup_enable_interrupt(MMI_TRUE);

    return MMI_FRM_PROC_RESULT_COMPLETED;
}


/*****************************************************************************
 * FUNCTION
 *  mmi_bootup_is_interruptible
 * DESCRIPTION
 *  Query if current screen is interruptable. Unly ultra-high priority events
 *  can interrupt booting screens; such as incoming call.
 * PARAMETERS
 *  arg         [IN] Unused
 *  id_info     [IN] Unused
 * RETURNS
 *  void
 *****************************************************************************/
MMI_BOOL mmi_bootup_is_interruptible(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (g_mmi_bootup_flow_cntx.interrupt.disabled_count == 0)
		return MMI_TRUE;
	else
		return MMI_FALSE;
}


/*****************************************************************************
 * FUNCTION
 *  mmi_bootup_flow_stop_check
 * DESCRIPTION
 *  Stop the flow if shutdown is launched
 * PARAMETERS
 *  user_data       [IN]
 *  set_status      [IN] Status of procedure set
 * RETURNS
 *  mmi_frm_proc_ctrl_enum
 *****************************************************************************/
static mmi_frm_proc_ctrl_enum mmi_bootup_flow_stop_check(
    void *user_data,
    const mmi_frm_proc_set_status_struct *set_status)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    return (srv_shutdown_is_running() ?
        MMI_FRM_PROC_CTRL_STOP : MMI_FRM_PROC_CTRL_CONTINUE);
}

#ifdef __TOPWELL_MMI_SALE_TRACK_TIMES_CONTINUOUS__
extern void mmi_sts_times_continuous_init(void);
#endif
#ifdef __TOPWELL_MMI_SALE_TRACK3_EXT3__
extern U8  mmi_sale_track_set_opposite_number(void);
#endif
#ifdef __TOPWELL_MMI_POON_PROMPT__  //jgh
extern void mmi_entry_poon_greeting(void);
#endif

#if defined(__TOPWELL_HW_TORCH__)&&defined(__TOPWELL_HW_TORCH_TYPE_SOS__)
extern void mmi_torch_init(void);
#endif

#if defined(__TOPWELL_MMI_KEYPAD_SHAKE__)
extern void initshakestate(void);
#endif
#if defined(__TOPWELL_FEATURE_POWER_SAVE_PROFILES_MODE2__)
extern MMI_BOOL topwell_mmi_is_power_save_prof(void);
extern void topwell_mmi_power_save_active(void);
#endif

#if defined(__TOPWELL_MMI_BATTERY_LOW_ALERT__)
extern void mmi_battery_low_alert_init(void);
#endif

/*****************************************************************************
 * FUNCTION
 *  mmi_bootup_flow_completed
 * DESCRIPTION
 *  Query if current screen is interruptable. Only ultra-high priority events
 *  can interrupt booting screens; such as incoming call.
 * PARAMETERS
 *  evt     [IN] mmi_frm_proc_completed_evt_struct *
 * RETURNS
 *  void
 *****************************************************************************/
static mmi_ret mmi_bootup_flow_completed(mmi_event_struct *evt)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    mmi_frm_proc_seq_destroy(g_mmi_bootup_flow_cntx.main_flow);
    g_mmi_bootup_flow_cntx.main_flow = NULL;

    if (srv_shutdown_is_running())
    {
        return MMI_RET_OK;
    }
#ifdef __TOPWELL_MMI_SALE_TRACK_TIMES_CONTINUOUS__
    mmi_sts_times_continuous_init();
#endif
#ifdef __TOPWELL_MMI_SALE_TRACK3_EXT3__
    mmi_sale_track_set_opposite_number();
#endif
    /*
     * [MAUI_02288699]
     * We should close waiting first, otherwise it may be shown during
     * accessing NVRAM on BEFORE_IDLE event.
     */
    mmi_bootup_waiting_screen_close(GRP_ID_BOOTUP);
    
    mmi_bootup_notify_before_idle();

    mmi_idle_launch(GRP_ID_BOOTUP);

    /* Clear leave proc of the base screen, to allow being closed */
    mmi_frm_scrn_set_leave_proc(GRP_ID_BOOTUP, SCR_ID_BOOTUP_BASE, NULL);
#if defined(__TOPWELL_HW_TORCH__)&&defined(__TOPWELL_HW_TORCH_TYPE_SOS__)
    mmi_torch_init();
#endif

  #ifdef __TOPWELL_MMI_POON_PROMPT__  //jgh
    mmi_entry_poon_greeting();
  #else
    mmi_frm_group_close(GRP_ID_BOOTUP);
  #endif

    /* Change service status first */
    srv_bootup_notify_completed();
    /* Notify application finally */
    mmi_bootup_notify_completed();

#if defined(__TOPWELL_MMI_KEYPAD_SHAKE__)
    initshakestate();
#endif

#if defined(__TOPWELL_FEATURE_POWER_SAVE_PROFILES_MODE2__)
     if(topwell_mmi_is_power_save_prof())
            topwell_mmi_power_save_active();
#endif
#if defined(__TOPWELL_MMI_BATTERY_LOW_ALERT__)
     mmi_battery_low_alert_init();
#endif

    return MMI_RET_OK;
}