⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 appmemmgr.c

📁 MTK手机平台的MMI部分的源代码
💻 C
📖 第 1 页 / 共 5 页
字号:
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/    
    if (g_mmi_frm_appmem_prompt_screen->num_app == 0)
    {
        return;
    }
    
    MMI_ASSERT(g_mmi_frm_appmem_prompt_screen && 
               item_index < g_mmi_frm_appmem_prompt_screen->num_app);
    
    if (!g_mmi_frm_appmem_prompt_screen->applist[item_index].is_stopping)
    {
        ChangeLeftSoftkey(STR_ID_APPMEM_STOP, 0);
        SetLeftSoftkeyFunction(mmi_frm_appmem_prompt_screen_stop_highlighted, KEY_EVENT_UP);
    }
    else
    {
        ChangeLeftSoftkey(STR_ID_APPMEM_WAIT, 0);
        SetLeftSoftkeyFunction(mmi_frm_appmem_prompt_screen_wait_highlighted, KEY_EVENT_UP);
    }
}


/*****************************************************************************
 * FUNCTION
 *  mmi_frm_appmem_exit_prompt_screen
 * DESCRIPTION
 *  Exit function of prompt screen 
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
static void mmi_frm_appmem_exit_prompt_screen(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    history h;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/    
    if (g_mmi_frm_appmem_prompt.keep_prompt_screen_in_history)
    {
        h.scrnID = SCR_APPMEM_STOP_PROMPT;
        h.entryFuncPtr = mmi_frm_appmem_entry_prompt_screen;
        pfnUnicodeStrcpy((S8*) h.inputBuffer, (S8*) L"");
        GetCategoryHistory(h.guiBuffer);
    
        AddHistory(h);
    }

    OslMfree(g_mmi_frm_appmem_prompt_screen);
    g_mmi_frm_appmem_prompt_screen = NULL;
}


/*****************************************************************************
 * FUNCTION
 *  mmi_frm_appmem_entry_prompt_screen
 * DESCRIPTION
 *  Entry function of prompt screen to stop other applications
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
static void mmi_frm_appmem_entry_prompt_screen(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    U8 *guiBuffer;
    S32 info_box_height;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    MMI_ASSERT(g_mmi_frm_appmem_prompt_screen == NULL);
    
    if (mmi_frm_appmem_check_enough_memory() && 
        !is_redrawing_old_screens())    /* not redrawn by small screen */
    {
        DisplayPopupCallBack(
            (U8*) GetString(STR_ID_APPMEM_NOTIFY_STARTING_NEW), 
            IMG_GLOBAL_INFO, 
            0, 
            UI_POPUP_NOTIFYDURATION_TIME_2000, 
            SUCCESS_TONE, 
            mmi_frm_appmem_invoke_release_mem_success_callback);
    }
    else
    {
        EntryNewScreen(SCR_APPMEM_STOP_PROMPT, mmi_frm_appmem_exit_prompt_screen, NULL, NULL);     

        guiBuffer = GetCurrGuiBuffer(SCR_APPMEM_STOP_PROMPT);

        g_mmi_frm_appmem_prompt_screen = 
            (mmi_frm_appmem_prompt_screen_struct*) OslMalloc(sizeof(mmi_frm_appmem_prompt_screen_struct));

        g_mmi_frm_appmem_prompt_screen->num_app = 
            (S32) applib_mem_ap_get_current_usage(
                    g_mmi_frm_appmem_prompt_screen->applist,
                    MMI_FRM_APPMEM_MAX_APP_PROMPTED);

        info_box_height = mmi_frm_appmem_prompt_screen_init_info();        

        RegisterHighlightHandler(mmi_frm_appmem_prompt_screen_highlight_hdlr);
        
        ShowCategory211Screen(
            STR_ID_APPMEM_OUT_OF_MEMORY,
            0, 
            STR_ID_APPMEM_STOP,
            0, 
            STR_GLOBAL_BACK, 
            0, 
            g_mmi_frm_appmem_prompt_screen->num_app, 
            mmi_frm_appmem_prompt_screen_get_item, 
            NULL, 
            mmi_frm_appmem_prompt_screen_draw_info,
            mmi_frm_appmem_prompt_screen_hide_info,
            info_box_height,            /* Info box height */
            0,                          /* Background image of info box */
            0,                          /* Highlight item index */
            guiBuffer);

       SetRightSoftkeyFunction(GoBackHistory, KEY_EVENT_UP);
    }
}


/*****************************************************************************
 * FUNCTION
 *  mmi_frm_appmem_invoke_release_mem_success_callback
 * DESCRIPTION
 *  Invoke the calling application there is enough memory
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
static void mmi_frm_appmem_invoke_release_mem_success_callback(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    MMI_ASSERT(mmi_frm_appmem_check_enough_memory());
#ifndef MMI_ON_WIN32
	 MMI_ASSERT(mmiapi_is_MMI_task());
#endif
    
    DeleteScreenIfPresent(SCR_APPMEM_STOP_PROMPT);
    DeleteScreenIfPresent(SCR_APPMEM_STOP_PROGRESSING);

    /* Enter another screen by registered callback function */
    g_mmi_frm_appmem_prompt.keep_prompt_screen_in_history = MMI_FALSE;
    g_mmi_frm_appmem_prompt.success_callback();

    /* The callback function must enter new MMI screen */
    MMI_ASSERT(!mmi_frm_appmem_is_in_prompt_screens() &&
               !mmi_frm_appmem_is_prompt_screens_in_history());
}


/*****************************************************************************
 * FUNCTION
 *  mmi_frm_appmem_stop_finished_handler
 * DESCRIPTION
 *  Callback handler when an application finished stop operation
 * PARAMETERS
 *  app_id      [IN]    ID of the application to be stopped
 *  string_id   [IN]    Name of the application to be stopped
 *  result      [IN]    whether the stop operation suceeds or not
 * RETURNS
 *  void
 *****************************************************************************/
static void mmi_frm_appmem_stop_finished_handler(kal_uint32 app_id, kal_uint32 string_id, kal_bool result)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (mmi_frm_appmem_is_in_prompt_screens() ||
        g_mmi_frm_appmem_prompt.stop_state == MMI_FRM_APPMEM_STOP_STATE_WAITING) /* In confirm screen */
    {
        U8 *msg;
        U16 icon;
        U8 tone;
        FuncPtr callback;
        if (mmi_frm_appmem_check_enough_memory())
        {
            msg = (U8*) GetString(STR_ID_APPMEM_NOTIFY_STARTING_NEW);
            icon = IMG_GLOBAL_INFO;
            tone = SUCCESS_TONE;        
            callback = mmi_frm_appmem_invoke_release_mem_success_callback;
        }
        else if (result) 
        {
            msg = (U8*) GetString(STR_ID_APPMEM_NOTIFY_STOPPED);
            icon = IMG_GLOBAL_INFO;
            tone = SUCCESS_TONE;
            callback = mmi_frm_appmem_jump_to_prompt_screen;
        }
        else
        {
            msg = (U8*) GetString(STR_ID_APPMEM_NOTIFY_STOP_FAILED);
            icon = IMG_GLOBAL_WARNING;
            tone = ERROR_TONE;
            callback = mmi_frm_appmem_jump_to_prompt_screen;
        }
    
        DisplayPopupCallBack(msg, icon, 0, UI_POPUP_NOTIFYDURATION_TIME_2000, tone, callback);

        if (g_mmi_frm_appmem_prompt.stop_state == MMI_FRM_APPMEM_STOP_STATE_WAITING)
        {
            g_mmi_frm_appmem_prompt.stop_state = MMI_FRM_APPMEM_STOP_STATE_FINISHED;
        }
    }
    else 
    {
        /* 
         * 1. If prompt screen is in history - it will be processed after goback to prompt screen 
         * 2. If prompt screen is not in history - silently ignore the result 
         *    (Maybe it goes back to idle screen)
         */
    }
}


/*****************************************************************************              
 * Extern Global Variable                                                                    
 *****************************************************************************/

/*****************************************************************************              
 * Extern Global Function                                                                    
 *****************************************************************************/


/*****************************************************************************
 * FUNCTION
 *  mmi_frm_appmem_prompt_to_release_mem
 * DESCRIPTION
 *  Show "out-of-memory" screen and prompt user to stop other applications in order 
 *  to release more memory.
 *
 *  Remark: 
 *  1. This function is not suggested to be used in "interrupt screens" 
 *     (e.g. MT call or USB plug-in indication)
 *     Otherwise, it might re-enter the prompt screen and confuse user.
 *  2. 'success_callback' needs to enter a new MMI screen!
 *  3. There is no "failure callback" due to complex interaction of MMI screens.
 *     Applications that use this function should never adopt any explicit or 
 *     implicit "waiting" state for the result.
 *
 *     For example, user may press End key in the "out-of-memory" screen and
 *     try to enter the application again. 
 *
 *  Warning: This function can only be used in MMI task.
 * PARAMETERS
 *  app_name            [IN]    String ID of the application 
 *  app_icon            [IN]    Image ID of the application 
 *  required_size       [IN]    Minimum required memory for the application
 *  success_callback    [IN]    Callback function when getting memory successfully 
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_frm_appmem_prompt_to_release_mem(
        MMI_ID_TYPE app_name, 
        MMI_ID_TYPE app_icon, 
        U32 required_size,
        void (*success_callback)(void))
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    MMI_ASSERT(required_size <= applib_mem_ap_get_pool_size());

    /* Avoid reentrance of the prompt screen.
       Application developers should be careful on designing the screen flow */
    MMI_ASSERT(!mmi_frm_appmem_is_in_prompt_screens() && 
               !mmi_frm_appmem_is_prompt_screens_in_history());

    /* Note the context g_mmi_frm_appmem_prompt is not reset  */
    g_mmi_frm_appmem_prompt.app_name = app_name;
    g_mmi_frm_appmem_prompt.app_icon = app_icon;
    g_mmi_frm_appmem_prompt.required_size = required_size;
    g_mmi_frm_appmem_prompt.require_full_pool = MMI_FALSE;    
    g_mmi_frm_appmem_prompt.stop_state = MMI_FRM_APPMEM_STOP_STATE_IGNORE;
    g_mmi_frm_appmem_prompt.keep_prompt_screen_in_history = MMI_TRUE;
    g_mmi_frm_appmem_prompt.success_callback = success_callback;

    mmi_frm_appmem_entry_prompt_screen();
}


/*****************************************************************************
 * FUNCTION
 *  mmi_frm_appmem_prompt_to_release_full_pool
 * DESCRIPTION
 *  Show "out-of-memory" screen and prompt user to stop other applications in order 
 *  to release more memory.
 *  
 *  This function is similar to mmi_frm_appmem_prompt_to_release_mem
 *  but it requires the whole pool.
 *
 *  Warning: This function can only be used in MMI task.
 * PARAMETERS
 *  app_name            [IN]    String ID of the application 
 *  app_icon            [IN]    Image ID of the application 
 *  success_callback    [IN]    Callback function when getting memory successfully 
 * RETURNS
 *  void

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -