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

MTK

开发平台:

C/C++

  1. /* under construction !*/
  2. /* under construction !*/
  3. /* under construction !*/
  4. /* under construction !*/
  5. /* under construction !*/
  6. /* under construction !*/
  7. #endif /* 0 */ 
  8.     /*----------------------------------------------------------------*/
  9.     /* Code Body                                                      */
  10.     /*----------------------------------------------------------------*/
  11.     /* PMT SHARIQ DLT_PATCH 20060814 END */
  12. }
  13. /*****************************************************************************
  14.  * FUNCTION
  15.  *  ThemeManagerResetAlarmTone
  16.  * DESCRIPTION
  17.  *  
  18.  * PARAMETERS
  19.  *  void
  20.  * RETURNS
  21.  *  void
  22.  *****************************************************************************/
  23. void ThemeManagerResetAlarmTone(void)
  24. {
  25.     /*----------------------------------------------------------------*/
  26.     /* Local Variables                                                */
  27.     /*----------------------------------------------------------------*/
  28.     U8 flag = 0, i;
  29.     S16 error;
  30.     /*----------------------------------------------------------------*/
  31.     /* Code Body                                                      */
  32.     /*----------------------------------------------------------------*/
  33.     for (i = 0; i < MAX_ELEMENTS; ++i)
  34.     {
  35.         if (gprofiles[i].toneSetup.alarmTone == CURRENT_THEME_ALARM_EXPIRY_TONE)
  36.         {
  37.             flag = 1;
  38.             gprofiles[i].toneSetup.alarmTone = MIDI_2;
  39.         }
  40.     }
  41. #ifdef __MMI_ALM_AUDIO_OPTIONS__
  42.     for (i = 0; i < NUM_OF_ALM; ++i)
  43.     {
  44.         if (g_alm_cntx.AlmList[i].AudioOptionValue == CURRENT_THEME_ALARM_EXPIRY_TONE)
  45.         {
  46.             g_alm_cntx.AlmList[i].AudioOption = ALM_AUDIO_OPTIONS_TONE;
  47.             g_alm_cntx.AlmList[i].AudioOptionValue = (U16) (gstartMidiId + 1);
  48.         }
  49.     }
  50.     AlmWriteToNvram();
  51. #endif /* __MMI_ALM_AUDIO_OPTIONS__ */ 
  52.     if (flag)
  53.     {
  54.         WriteRecord(NVRAM_EF_PROFILES_LID, 1, &gprofiles[0], NVRAM_PROFILES_RECORD_SIZE, &error);
  55.         memcpy(&gcurrentprofile, &gprofiles[gactivatedprofile], sizeof(PROFILE));
  56.     }
  57. }
  58. #endif /* __MMI_DOWNLOADABLE_THEMES_SUPPORT__ */ 
  59. /*****************************************************************************
  60.  * FUNCTION
  61.  *  set_lcdbacklighttimer
  62.  * DESCRIPTION
  63.  *  Setting lcdbacklight timer value
  64.  * PARAMETERS
  65.  *  void
  66.  * RETURNS
  67.  *  void
  68.  *****************************************************************************/
  69. U8 set_lcdbacklighttimer(void)
  70. {
  71.     /*----------------------------------------------------------------*/
  72.     /* Local Variables                                                */
  73.     /*----------------------------------------------------------------*/
  74.     S16 error = 0;
  75.     U16 j = 1;
  76.     /*----------------------------------------------------------------*/
  77.     /* Code Body                                                      */
  78.     /*----------------------------------------------------------------*/
  79.     gprofiles[gprofileId].light.timer.setsec = gSec;
  80.     if (WriteRecord(
  81.             NVRAM_EF_PROFILES_LID,
  82.             j,
  83.             &gprofiles[0],
  84.             NVRAM_PROFILES_RECORD_SIZE,
  85.             &error) < NVRAM_PROFILES_RECORD_SIZE)
  86.     {
  87.         PRINT_INFORMATION(("## ERROR: set_lcdbacklighttimer: WriteRecord " "to NVRAM failed (ecode%d)n", (int)error));
  88.         return ((U8) error);
  89.     }
  90.     if (gactivatedprofile == gprofileId)
  91.     {
  92.         memcpy(&gcurrentprofile, &gprofiles[gprofileId], sizeof(PROFILE));
  93.     }
  94.     return gSec;
  95. }
  96. /*****************************************************************************
  97.  * FUNCTION
  98.  *  SetProfileDefault
  99.  * DESCRIPTION
  100.  *  SetProfileDefault
  101.  * PARAMETERS
  102.  *  void
  103.  * RETURNS
  104.  *  void
  105.  *****************************************************************************/
  106. pBOOL SetProfileDefault(void)
  107. {
  108.     /*----------------------------------------------------------------*/
  109.     /* Local Variables                                                */
  110.     /*----------------------------------------------------------------*/
  111.     S16 error;
  112.     /*----------------------------------------------------------------*/
  113.     /* Code Body                                                      */
  114.     /*----------------------------------------------------------------*/
  115.     if (gprofileheadset != 1)
  116.     {
  117.         PRINT_INFORMATION_2((MMI_TRACE_G7_MISC, "=== SetProfileDefault(): Headset mode. ===n"));
  118.         ReadRecord(
  119.             NVRAM_EF_PROFILES_LID,
  120.             2,
  121.             &gprofiles[0],
  122.             MAX_ELEMENTS * sizeof(PROFILE) /* NVRAM_PROFILES_RECORD_SIZE */ ,
  123.             &error);
  124.         gactivatedprofile = 0;
  125.         memcpy(&gcurrentprofile, &gprofiles[gactivatedprofile], sizeof(PROFILE));
  126.         showAlertStatusIcons(); /* function to show status icon on ilde screen */
  127.         WriteRecord(NVRAM_EF_PROFILES_LID, 1, &gprofiles[0], NVRAM_PROFILES_RECORD_SIZE, &error);
  128.         WriteValue(NVRAM_PROFILES_ACTIVATED, &gactivatedprofile, DS_BYTE, &error);
  129.         /*          
  130.          * #ifdef __MMI_AUDIO_PLAYER__
  131.          * mmi_audply_save_volume( gactivatedprofile );
  132.          * #endif // __MMI_AUDIO_PLAYER__
  133.          * 
  134.          * SetRingerVolume(GetRingVolumeLevel());
  135.          */
  136.         mdi_audio_set_volume_no_apply(MDI_VOLUME_MEDIA, GetRingVolumeLevel());
  137.         SetKeyPadVolume(GetKeypadVolumeLevel());
  138.         change_font();
  139.         if (error == NVRAM_WRITE_SUCCESS)
  140.         {
  141.             return TRUE;
  142.         }
  143.         else
  144.         {
  145.             return FALSE;
  146.         }
  147.     }
  148.     else
  149.     {
  150.         PRINT_INFORMATION_2((MMI_TRACE_G7_MISC, "=== SetProfileDefault(): Not Headset mode. ===n"));
  151.         ReadRecord(
  152.             NVRAM_EF_PROFILES_LID,
  153.             2,
  154.             &gprofiles[0],
  155.             MAX_ELEMENTS * sizeof(PROFILE) /* NVRAM_PROFILES_RECORD_SIZE */ ,
  156.             &error);
  157.         memcpy(&gcurrentprofile, &gprofiles[gactivatedprofile], sizeof(PROFILE));
  158.         showAlertStatusIcons(); /* function to show status icon on ilde screen */
  159.         WriteRecord(NVRAM_EF_PROFILES_LID, 1, &gprofiles[0], NVRAM_PROFILES_RECORD_SIZE, &error);
  160.         WriteValue(NVRAM_PROFILES_ACTIVATED, &gactivatedprofile, DS_BYTE, &error);
  161.         /*          
  162.          * #ifdef __MMI_AUDIO_PLAYER__
  163.          * mmi_audply_save_volume( gactivatedprofile );
  164.          * #endif // __MMI_AUDIO_PLAYER__
  165.          * 
  166.          * SetRingerVolume(GetRingVolumeLevel());
  167.          */
  168.         mdi_audio_set_volume_no_apply(MDI_VOLUME_MEDIA, GetRingVolumeLevel());
  169.         SetKeyPadVolume(GetKeypadVolumeLevel());
  170.         change_font();
  171.         if (error == NVRAM_WRITE_SUCCESS)
  172.         {
  173.             return TRUE;
  174.         }
  175.         else
  176.         {
  177.             return FALSE;
  178.         }
  179.     }
  180. }
  181. /*****************************************************************************
  182.  * FUNCTION
  183.  *  SetExtraTone
  184.  * DESCRIPTION
  185.  *  
  186.  * PARAMETERS
  187.  *  extraTone       [IN]        
  188.  * RETURNS
  189.  *  void
  190.  *****************************************************************************/
  191. S16 SetExtraTone(EXTRA_TONE extraTone)
  192. {
  193.     /*----------------------------------------------------------------*/
  194.     /* Local Variables                                                */
  195.     /*----------------------------------------------------------------*/
  196.     S16 error = 0;
  197.     U16 j = 1;
  198.     /*----------------------------------------------------------------*/
  199.     /* Code Body                                                      */
  200.     /*----------------------------------------------------------------*/
  201.     gprofiles[gprofileId].extraTone.warningTone = extraTone.warningTone;
  202.     gprofiles[gprofileId].extraTone.errorTone = extraTone.errorTone;
  203. #ifndef __MMI_CONNECT_NOTICE__
  204.     gprofiles[gprofileId].extraTone.connectTone = extraTone.connectTone;
  205. #endif 
  206.     gprofiles[gprofileId].extraTone.campOnTone = extraTone.campOnTone;
  207.     if (WriteRecord(
  208.             NVRAM_EF_PROFILES_LID,
  209.             j,
  210.             &gprofiles[0],
  211.             NVRAM_PROFILES_RECORD_SIZE,
  212.             &error) < NVRAM_PROFILES_RECORD_SIZE)
  213.     {
  214.         PRINT_INFORMATION(("## ERROR: SetWarningToneType: WriteRecord " "to NVRAM failed (ecode%d)n", (int)error));
  215.         return error;
  216.     }
  217.     if (gactivatedprofile == gprofileId)
  218.     {
  219.         memcpy(&gcurrentprofile, &gprofiles[gprofileId], sizeof(PROFILE));
  220.     }
  221.     return 0;
  222. }
  223. /*****************************************************************************
  224.  * FUNCTION
  225.  *  playRequestedTone
  226.  * DESCRIPTION
  227.  *  API to all applications to play tone.
  228.  * PARAMETERS
  229.  *  playtone        [IN]        
  230.  * RETURNS
  231.  *  void
  232.  *****************************************************************************/
  233. void playRequestedTone(ALL_TONE_ENUM playtone)
  234. {
  235.     /*----------------------------------------------------------------*/
  236.     /* Local Variables                                                */
  237.     /*----------------------------------------------------------------*/
  238.     BOOL done = FALSE;
  239.     BOOL DataCallOnly = FALSE;    
  240.     /*----------------------------------------------------------------*/
  241.     /* Code Body                                                      */
  242.     /*----------------------------------------------------------------*/
  243.     switch (playtone)
  244.     {
  245.         case CONGESTION_TONE:
  246.             AudioPlayReq(TONE_CONGESTION_GSM, DEVICE_AUDIO_PLAY_ONCE);
  247.             done = TRUE;
  248.             break;
  249.         case AUTH_FAIL_TONE:
  250.             AudioPlayReq(TONE_AUTH_ERROR, DEVICE_AUDIO_PLAY_ONCE);
  251.             done = TRUE;
  252.             break;
  253.         case NUM_UNOBTAIN_TONE:
  254.             AudioPlayReq(TONE_NUM_UNOBTAIN, DEVICE_AUDIO_PLAY_ONCE);
  255.             done = TRUE;
  256.             break;
  257.         case CALL_DROP_TONE:
  258.             AudioPlayReq(TONE_RADIO_NA, DEVICE_AUDIO_PLAY_ONCE);
  259.             done = TRUE;
  260.             break;
  261.     }
  262.     if (done)
  263.     {
  264.         SetPlayReqToneFlag(TRUE);
  265.         return;
  266.     }
  267.     if (IsWapCallPresent() && GetTotalCallCount()==1)
  268.     {
  269.         DataCallOnly = TRUE ;
  270.     }
  271.     
  272.     if (!isInCall() || DataCallOnly)
  273.     {
  274.         SetPlayReqToneFlag(TRUE);
  275.         switch (playtone)
  276.         {
  277.             case ERROR_TONE:
  278.                 if (gcurrentprofile.extraTone.errorTone == 1)
  279.                 {
  280.                     AudioPlayReq(TONE_ERROR1, DEVICE_AUDIO_PLAY_ONCE);
  281.                 }
  282.                 break;
  283.             case CONNECT_TONE:
  284.             #ifndef __MMI_CONNECT_NOTICE__
  285.                 if (gcurrentprofile.extraTone.connectTone == 1)
  286.             #endif 
  287.                     AudioPlayReq(TONE_CALL_CONNECT, DEVICE_AUDIO_PLAY_ONCE);
  288.                 break;
  289.             case CAMP_ON_TONE:
  290.                 if (gcurrentprofile.extraTone.campOnTone == 1)
  291.                 {
  292.                     AudioPlayReq(SOUND_3, DEVICE_AUDIO_PLAY_ONCE);
  293.                 }
  294.                 break;
  295.             case WARNING_TONE:
  296.                 if (gcurrentprofile.extraTone.warningTone == 1)
  297.                 {
  298.                     AudioPlayReq(TONE_WARNING1, DEVICE_AUDIO_PLAY_ONCE);
  299.                 }
  300.                 break;
  301.           /**************************************************************************************/
  302.           /***** Shall not come to here, Play ring tone in StartRingTone() use AudioPlayToneWithCallBack()  *****/
  303.             case INCOMING_CALL_TONE:
  304.                 if (gactivatedprofile != MMI_PROFILE_SILENT)
  305.                 {
  306.                     AudioPlayReq(gcurrentprofile.toneSetup.ringTone, (U8) GetRingTypeEnum());
  307.                 }
  308.                 break;
  309.           /**************************************************************************************/
  310.             case ALARM_TONE:
  311.                 /* PMT PANKAJ START: Added for providing support for FM Radio as alarm audio. */
  312.             #ifdef __MMI_ALM_CUSTOMIZE_TONE__
  313.                 if (g_alm_frm_cntx.CurrAlmIndex >= ALM_ALM_START && g_alm_frm_cntx.CurrAlmIndex < ALM_SPOF_START)
  314.                 {
  315.                     AudioPlayToneWithCallBack(
  316.                         g_alm_cntx.AlmList[g_alm_frm_cntx.CurrAlmIndex - ALM_ALM_START].AudioOptionValue,
  317.                         DEVICE_AUDIO_PLAY_CRESCENDO,
  318.                         ALARM_TONE);
  319.                 }
  320.                 else
  321.                 {
  322.                     AudioPlayToneWithCallBack(
  323.                         gcurrentprofile.toneSetup.alarmTone,
  324.                         DEVICE_AUDIO_PLAY_CRESCENDO,
  325.                         ALARM_TONE);
  326.                 }
  327.             #else /* __MMI_ALM_CUSTOMIZE_TONE__ */ 
  328.                 AudioPlayToneWithCallBack(gcurrentprofile.toneSetup.alarmTone, DEVICE_AUDIO_PLAY_CRESCENDO, ALARM_TONE);
  329.             #endif /* __MMI_ALM_CUSTOMIZE_TONE__ */ 
  330.                 /* PMT PANKAJ END */
  331.                 break;
  332.             case POWER_ON_TONE:
  333.                 if (gcurrentprofile.toneSetup.powerOnTone != POWERON_SILENT)
  334.                 {
  335. //KP Jerry modify for changing the style of message tone list on 2007-4-10 start
  336.           #ifdef __MMI_TONE_LIST_STYLE_CHANGED__
  337.                      AudioPlayToneWithCallBack(
  338.                          gcurrentprofile.toneSetup.powerOnTone,
  339.                          DEVICE_AUDIO_PLAY_ONCE,
  340.                          POWER_ON_TONE);
  341.           #else
  342.                     AudioPlayReq(gcurrentprofile.toneSetup.powerOnTone, DEVICE_AUDIO_PLAY_ONCE);
  343.           #endif
  344. //KP Jerry modify for changing the style of message tone list on 2007-4-10 end
  345.                 }
  346.                 break;
  347.             case POWER_OFF_TONE:
  348.                 if (gcurrentprofile.toneSetup.powerOffTone != POWEROFF_SILENT)
  349.                 {
  350. //KP Jerry modify for changing the style of message tone list on 2007-4-10 start
  351.           #ifdef __MMI_TONE_LIST_STYLE_CHANGED__
  352.                      AudioPlayToneWithCallBack(
  353.                          gcurrentprofile.toneSetup.powerOffTone,
  354.                          DEVICE_AUDIO_PLAY_ONCE,
  355.                          POWER_OFF_TONE);
  356.           #else
  357.                     AudioPlayReq(gcurrentprofile.toneSetup.powerOffTone, DEVICE_AUDIO_PLAY_ONCE);
  358.           #endif
  359. //KP Jerry modify for changing the style of message tone list on 2007-4-10 end
  360.                 }
  361.                 break;
  362.             #ifdef __MMI_CLAMSHELL__
  363.             case COVER_OPEN_TONE:
  364.                 if (gcurrentprofile.toneSetup.coverOpenTone != COVER_OPEN_SILENT)
  365.                 {
  366. //KP Jerry modify for changing the style of message tone list on 2007-4-10 start
  367.           #ifdef __MMI_TONE_LIST_STYLE_CHANGED__
  368.                      AudioPlayToneWithCallBack(
  369.                          gcurrentprofile.toneSetup.coverOpenTone,
  370.                          DEVICE_AUDIO_PLAY_ONCE,
  371.                          COVER_OPEN_TONE);
  372.           #else
  373.                     AudioPlayReq(gcurrentprofile.toneSetup.coverOpenTone, DEVICE_AUDIO_PLAY_ONCE);
  374.           #endif
  375. //KP Jerry modify for changing the style of message tone list on 2007-4-10 end
  376.                 }
  377.                 break;
  378.             case COVER_CLOSE_TONE:
  379.                 if (gcurrentprofile.toneSetup.coverCloseTone != COVER_CLOSE_SILENT)
  380.                 {
  381. //KP Jerry modify for changing the style of message tone list on 2007-4-10 start
  382.           #ifdef __MMI_TONE_LIST_STYLE_CHANGED__
  383.                      AudioPlayToneWithCallBack(
  384.                          gcurrentprofile.toneSetup.coverCloseTone,
  385.                          DEVICE_AUDIO_PLAY_ONCE,
  386.                          COVER_CLOSE_TONE);
  387.           #else
  388.                     AudioPlayReq(gcurrentprofile.toneSetup.coverCloseTone, DEVICE_AUDIO_PLAY_ONCE);
  389.           #endif
  390. //KP Jerry modify for changing the style of message tone list on 2007-4-10 end
  391.                 }
  392.                 break;
  393.             #endif /* __MMI_CLAMSHELL__ */ 
  394.             case MESSAGE_TONE:
  395.                 if (gcurrentprofile.toneSetup.messageTone != MESSAGE_SILENT)
  396.                 {
  397.                     /* AudioPlayReq(gcurrentprofile.toneSetup.messageTone,DEVICE_AUDIO_PLAY_ONCE); */
  398. //KP Jerry add for changing the style of message tone list on 2007-4-10 start
  399.           #ifdef __MMI_TONE_LIST_STYLE_CHANGED__
  400.                      AudioPlayToneWithCallBack(
  401.                          gcurrentprofile.toneSetup.messageTone,
  402.                          DEVICE_AUDIO_PLAY_ONCE,
  403.                          MESSAGE_TONE);
  404.           #else
  405.                      AudioPlayToneWithCallBack(
  406.                          gcurrentprofile.toneSetup.messageTone,
  407.                          DEVICE_AUDIO_PLAY_ONCE,
  408.                          ALARM_TONE);
  409.           #endif
  410. //KP Jerry add for changing the style of message tone list on 2007-4-10 end
  411.                 }
  412.                 break;
  413.             case SUCCESS_TONE:
  414.                 break;
  415.             case SAVE_TONE:
  416.                 //MTK Brian added for disable save tone */
  417.                 //AudioPlayReq(        TONE_GENERAL_BEEP,DEVICE_AUDIO_PLAY_ONCE);      
  418.                 break;
  419.             case EMPTY_LIST_TONE:
  420.                 /* AudioPlayReq(        TONE_GENERAL_BEEP,DEVICE_AUDIO_PLAY_ONCE); */
  421.                 if (gcurrentprofile.extraTone.warningTone == 1)
  422.                 {
  423.                     AudioPlayReq(TONE_WARNING1, DEVICE_AUDIO_PLAY_ONCE);
  424.                 }
  425.                 break;
  426.             case GENERAL_TONE:
  427.                 if (gcurrentprofile.extraTone.warningTone == 1)
  428.                 {
  429.                     AudioPlayReq(TONE_GENERAL_BEEP, DEVICE_AUDIO_PLAY_ONCE);
  430.                 }
  431.                 break;
  432.             case AUX_TONE:
  433.                 if (gcurrentprofile.extraTone.warningTone == 1)
  434.                 {
  435.                     AudioPlayReq(TONE_AUX_IND, DEVICE_AUDIO_PLAY_ONCE);
  436.                 }
  437.                 break;
  438.                 /* Brian added for battery indication, 2003/11/17 */
  439.             case BATTERY_LOW_TONE:
  440.                 if (gcurrentprofile.extraTone.warningTone == 1)
  441.                 {
  442.                     AudioPlayReq(TONE_BATTERY_LOW, DEVICE_AUDIO_PLAY_ONCE);
  443.                 }
  444.                 break;
  445.             case BATTERY_WARNING_TONE:
  446.                 if (gcurrentprofile.extraTone.warningTone == 1)
  447.                 {
  448.                     AudioPlayReq(TONE_BATTERY_WARNING, DEVICE_AUDIO_PLAY_ONCE);
  449.                 }
  450.                 break;
  451.             case WARNING_TONE_IN_CALL:
  452.                 if (gcurrentprofile.extraTone.warningTone == 1)
  453.                 {
  454.                     AudioPlayReq(TONE_WARNING2, DEVICE_AUDIO_PLAY_ONCE);
  455.                 }
  456.                 break;
  457.             case ERROR_TONE_IN_CALL:
  458.                 if (gcurrentprofile.extraTone.errorTone == 1)
  459.                 {
  460.                     AudioPlayReq(TONE_ERROR2, DEVICE_AUDIO_PLAY_ONCE);
  461.                 }
  462.                 break;
  463.         }
  464.     }
  465.     else    /* No active call, No on hold call */
  466.     {
  467.         switch (playtone)
  468.         {
  469.                 /* Robin 0719 */
  470.                 /* Shall play power off tone no matter in call or not */
  471.                 /* See CANNON+ SCR 3573, CSD connection, long press END key won't will power off first, then drop call */
  472.             case POWER_OFF_TONE:
  473.             {
  474.                 if (gcurrentprofile.toneSetup.powerOffTone != POWEROFF_SILENT)
  475.                 {
  476.                     AudioPlayReq(gcurrentprofile.toneSetup.powerOffTone, DEVICE_AUDIO_PLAY_ONCE);
  477.                 }
  478.                 break;
  479.             }
  480.             case SMS_IN_CALL_TONE:
  481.             {
  482.                 if (gcurrentprofile.toneSetup.messageTone != MESSAGE_SILENT)
  483.                 {
  484.                     SetPlayReqToneFlag(TRUE);
  485.                     AudioPlayReq(TONE_MT_SMS_IN_CALL, DEVICE_AUDIO_PLAY_ONCE);
  486.                 }
  487.                 break;
  488.             }
  489.             case WARNING_TONE_IN_CALL:
  490.             {
  491.                 if (gcurrentprofile.extraTone.warningTone == 1)
  492.                 {
  493.                     AudioPlayReq(TONE_WARNING2, DEVICE_AUDIO_PLAY_ONCE);
  494.                 }
  495.                 break;
  496.             }
  497.             case ERROR_TONE_IN_CALL:
  498.             {
  499.                 if (gcurrentprofile.extraTone.errorTone == 1)
  500.                 {
  501.                     AudioPlayReq(TONE_ERROR2, DEVICE_AUDIO_PLAY_ONCE);
  502.                 }
  503.                 break;
  504.             }
  505.             case CONNECT_TONE_IN_CALL:
  506.             {
  507.                 /* MTK Brian added for AUX TONE and Connect tone, 2003/11/19 */
  508.                 if (gcurrentprofile.extraTone.connectTone == 1)
  509.                 {
  510.                     AudioPlayReq(TONE_CALL_CONNECT, DEVICE_AUDIO_PLAY_ONCE);
  511.                 }
  512.                 break;
  513.             }
  514.             case SUCCESS_TONE_IN_CALL:
  515.             {
  516.                 break;
  517.             }
  518.                 /* MTK Brian added for battery indication, 2003/11/17 */
  519.             case BATTERY_LOW_TONE:
  520.             {
  521.                 if (gcurrentprofile.extraTone.warningTone == 1)
  522.                 {
  523.                     AudioPlayReq(TONE_WARNING2, DEVICE_AUDIO_PLAY_ONCE);
  524.                 }
  525.                 break;
  526.             }
  527.             case BATTERY_WARNING_TONE:
  528.             {
  529.                 if (gcurrentprofile.extraTone.warningTone == 1)
  530.                 {
  531.                     AudioPlayReq(TONE_WARNING2, DEVICE_AUDIO_PLAY_ONCE);
  532.                 }
  533.                 break;
  534.             }
  535.                 /* MTK Brian added for AUX TONE and Connect tone, 2003/11/19 */
  536.             case AUX_TONE:
  537.             {
  538.                 if (gcurrentprofile.extraTone.warningTone == 1)
  539.                 {
  540.                     AudioPlayReq(TONE_WARNING2, DEVICE_AUDIO_PLAY_ONCE);
  541.                 }
  542.                 break;
  543.             }
  544.             case CONNECT_TONE:
  545.             {
  546.             #ifndef __MMI_CONNECT_NOTICE__
  547.                 if (gcurrentprofile.extraTone.connectTone == 1)
  548.             #endif 
  549.                     AudioPlayReq(TONE_CALL_CONNECT, DEVICE_AUDIO_PLAY_ONCE);
  550.                 break;
  551.             }
  552.             case CALL_REMINDER_TONE:
  553.             case CCBS_TONE:
  554.             {
  555.                 AudioPlayReq(TONE_WARNING2, DEVICE_AUDIO_PLAY_ONCE);
  556.                 break;
  557.             }
  558.         }
  559.     }
  560. }
  561. /*****************************************************************************
  562.  * FUNCTION
  563.  *  stopRequestedTone
  564.  * DESCRIPTION
  565.  *  eneral API to all applications to stop tone.
  566.  * PARAMETERS
  567.  *  playtone        [IN]        
  568.  * RETURNS
  569.  *  void
  570.  *****************************************************************************/
  571. void stopRequestedTone(ALL_TONE_ENUM playtone)
  572. {
  573.     /*----------------------------------------------------------------*/
  574.     /* Local Variables                                                */
  575.     /*----------------------------------------------------------------*/
  576.     /*----------------------------------------------------------------*/
  577.     /* Code Body                                                      */
  578.     /*----------------------------------------------------------------*/
  579.     //if (GetPlayReqToneFlag() == TRUE)     //KP disable for avoid clam-open tone can not stop on 2007-4-28
  580.     {
  581.         SetPlayReqToneFlag(FALSE);
  582.         switch (playtone)
  583.         {
  584.             case ERROR_TONE:
  585.                 if (gcurrentprofile.extraTone.errorTone == 1)
  586.                 {
  587.                     AudioStopReq(TONE_ERROR1);
  588.                 }
  589.                 break;
  590.             case CONNECT_TONE:
  591.                 if (gcurrentprofile.extraTone.connectTone == 1)
  592.                 {
  593.                     AudioStopReq(TONE_CALL_CONNECT);
  594.                 }
  595.                 break;
  596.             case CAMP_ON_TONE:
  597.                 if (gcurrentprofile.extraTone.campOnTone == 1)
  598.                 {
  599.                     AudioStopReq(SOUND_3);
  600.                 }
  601.                 break;
  602.             case WARNING_TONE:
  603.                 if (gcurrentprofile.extraTone.warningTone == 1)
  604.                 {
  605.                     AudioStopReq(TONE_WARNING1);
  606.                 }
  607.                 break;
  608.             case INCOMING_CALL_TONE:
  609.                 if (gactivatedprofile != MMI_PROFILE_SILENT)
  610.                 {
  611.                     AudioStopReq(gcurrentprofile.toneSetup.ringTone);
  612.                 }
  613.                 break;
  614.             case ALARM_TONE:
  615.                 //MTK Brian modified to play alarm tone in all profiels, 2003/11/16
  616.                 //if(!IsSilentModeActivated())
  617.                 //AudioStopReq( gcurrentprofile.toneSetup.alarmTone);
  618.                 mdi_audio_stop_all();
  619.                 break;
  620.             case POWER_ON_TONE:
  621.                 if (gcurrentprofile.toneSetup.powerOnTone != POWERON_SILENT)
  622.                 {
  623.                     AudioStopReq(gcurrentprofile.toneSetup.powerOnTone);
  624.                 }
  625.                 break;
  626.             case POWER_OFF_TONE:
  627.                 if (gcurrentprofile.toneSetup.powerOffTone != POWEROFF_SILENT)
  628.                 {
  629.                     AudioStopReq(gcurrentprofile.toneSetup.powerOffTone);
  630.                 }
  631.                 break;
  632.                 /* MTK brian added to wrap cover open/close tone setup, 2003/10/18 */
  633.             #ifdef __MMI_CLAMSHELL__
  634.             case COVER_OPEN_TONE:
  635.                 if (gcurrentprofile.toneSetup.coverOpenTone != COVER_OPEN_SILENT)
  636.                 {
  637.                     AudioStopReq(gcurrentprofile.toneSetup.coverOpenTone);
  638.                 }
  639.                 break;
  640.             case COVER_CLOSE_TONE:
  641.                 if (gcurrentprofile.toneSetup.coverCloseTone != COVER_CLOSE_SILENT)
  642.                 {
  643.                     AudioStopReq(gcurrentprofile.toneSetup.coverCloseTone);
  644.                 }
  645.                 break;
  646.             #endif /* __MMI_CLAMSHELL__ */ 
  647.                 /* MTK end */
  648.             case MESSAGE_TONE:
  649.                 if (gcurrentprofile.toneSetup.messageTone != MESSAGE_SILENT)
  650.                 {
  651.                     AudioStopReq(gcurrentprofile.toneSetup.messageTone);
  652.                 }
  653.                 break;
  654.             case SUCCESS_TONE:
  655.                 break;
  656.             case SAVE_TONE:
  657.                 if (gactivatedprofile != MMI_PROFILE_SILENT)
  658.                 {
  659.                     AudioStopReq(TONE_GENERAL_BEEP);
  660.                 }
  661.                 break;
  662.             case EMPTY_LIST_TONE:
  663.                 if (gcurrentprofile.extraTone.warningTone == 1)
  664.                 {
  665.                     AudioStopReq(TONE_WARNING1);
  666.                 }
  667.                 break;
  668.             case GENERAL_TONE:
  669.                 if (gactivatedprofile != MMI_PROFILE_SILENT)
  670.                 {
  671.                     AudioStopReq(TONE_GENERAL_BEEP);
  672.                 }
  673.                 break;
  674.             case SMS_IN_CALL_TONE:
  675.                 AudioStopReq(TONE_MT_SMS_IN_CALL);
  676.                 break;
  677.                 /* MTK Brian added for battery indication, 2003/11/17 */
  678.             case BATTERY_LOW_TONE:
  679.                 AudioStopReq(TONE_BATTERY_LOW);
  680.                 break;
  681.             case BATTERY_WARNING_TONE:
  682.                 AudioStopReq(TONE_BATTERY_WARNING);
  683.                 break;
  684.             case CONGESTION_TONE:
  685.                 AudioStopReq(TONE_CONGESTION_GSM);
  686.                 break;
  687.             case AUTH_FAIL_TONE:
  688.                 AudioStopReq(TONE_AUTH_ERROR);
  689.                 break;
  690.             case NUM_UNOBTAIN_TONE:
  691.                 AudioStopReq(TONE_NUM_UNOBTAIN);
  692.                 break;
  693.             case CALL_DROP_TONE:
  694.                 AudioStopReq(TONE_RADIO_NA);
  695.                 break;
  696.         }
  697.     }
  698. }
  699. /*****************************************************************************
  700.  * FUNCTION
  701.  *  SetPlayReqToneFlag
  702.  * DESCRIPTION
  703.  *  
  704.  * PARAMETERS
  705.  *  flag        [IN]        
  706.  * RETURNS
  707.  *  void
  708.  *****************************************************************************/
  709. void SetPlayReqToneFlag(pBOOL flag)
  710. {
  711.     /*----------------------------------------------------------------*/
  712.     /* Local Variables                                                */
  713.     /*----------------------------------------------------------------*/
  714.     /*----------------------------------------------------------------*/
  715.     /* Code Body                                                      */
  716.     /*----------------------------------------------------------------*/
  717.     gPlayReqToneFlag = flag;
  718. }
  719. /*****************************************************************************
  720.  * FUNCTION
  721.  *  GetPlayReqToneFlag
  722.  * DESCRIPTION
  723.  *  
  724.  * PARAMETERS
  725.  *  void
  726.  * RETURNS
  727.  *  void
  728.  *****************************************************************************/
  729. pBOOL GetPlayReqToneFlag(void)
  730. {
  731.     /*----------------------------------------------------------------*/
  732.     /* Local Variables                                                */
  733.     /*----------------------------------------------------------------*/
  734.     /*----------------------------------------------------------------*/
  735.     /* Code Body                                                      */
  736.     /*----------------------------------------------------------------*/
  737.     return gPlayReqToneFlag;
  738. }
  739. /*****************************************************************************
  740.  * FUNCTION
  741.  *  UpdateDeleteDownloadedRingTone
  742.  * DESCRIPTION
  743.  *  set default tone when selected downloaded Ring tone is deleted.
  744.  * PARAMETERS
  745.  *  ToneId      [IN]        
  746.  * RETURNS
  747.  *  void
  748.  *****************************************************************************/
  749. void UpdateDeleteDownloadedRingTone(U16 ToneId)
  750. {
  751.     /*----------------------------------------------------------------*/
  752.     /* Local Variables                                                */
  753.     /*----------------------------------------------------------------*/
  754.     /*----------------------------------------------------------------*/
  755.     /* Code Body                                                      */
  756.     /*----------------------------------------------------------------*/
  757.     if (gcurrentprofile.toneSetup.ringTone == ToneId)
  758.     {
  759.         SetRingToneID(gstartMidiId);
  760.     }
  761. }
  762. /*****************************************************************************
  763.  * FUNCTION
  764.  *  UpdateDeleteExtMldToneSetup
  765.  * DESCRIPTION
  766.  *  set default tone when selected extented Melody Ring tone is deleted.
  767.  * PARAMETERS
  768.  *  ToneId      [IN]        
  769.  * RETURNS
  770.  *  void
  771.  *****************************************************************************/
  772. #ifdef __MMI_PROFILE_EXTMELODY_SUPPORT__
  773. void UpdateDeleteExtMldToneSetup(U16 ToneId)
  774. {
  775.     /*----------------------------------------------------------------*/
  776.     /* Local Variables                                                */
  777.     /*----------------------------------------------------------------*/
  778.     U8 i, dirtyFlag = 0;
  779.     S16 error = 0;
  780.     /*----------------------------------------------------------------*/
  781.     /* Code Body                                                      */
  782.     /*----------------------------------------------------------------*/
  783.     /* Update alarm ring tone list */
  784. #if defined(__MMI_ALM_AUDIO_OPTIONS__) && defined(__MMI_ALM_CUSTOMIZE_TONE__)
  785.     mmi_alm_tone_setup_delete_ext_melody(ToneId);
  786. #endif 
  787.     for (i = 0; i < MAX_ELEMENTS; i++)
  788.     {
  789.         if (gprofiles[i].toneSetup.ringTone == ToneId)
  790.         {
  791.             gprofiles[i].toneSetup.ringTone = gstartMidiId;
  792.             dirtyFlag = 1;
  793.         }
  794.         if (gprofiles[i].toneSetup.alarmTone == ToneId)
  795.         {
  796.             gprofiles[i].toneSetup.alarmTone = gstartMidiId + 1;
  797.             dirtyFlag = 1;
  798.         }
  799.     }
  800.     if (dirtyFlag == 1)
  801.         if (WriteRecord(
  802.                 NVRAM_EF_PROFILES_LID,
  803.                 1,
  804.                 &gprofiles[0],
  805.                 NVRAM_PROFILES_RECORD_SIZE,
  806.                 &error) < NVRAM_PROFILES_RECORD_SIZE)
  807.         {
  808.             PRINT_INFORMATION(("## ERROR: SetRingToneID: WriteRecord " "to NVRAM failed (ecode%d)n", (int)error));
  809.             return;
  810.         }
  811.     if (gactivatedprofile == gprofileId)
  812.     {
  813.         memcpy(&gcurrentprofile, &gprofiles[gprofileId], sizeof(PROFILE));
  814.     }
  815. }
  816. //KP Jerry add for changing the style of message tone list on 2007-4-10 start
  817. #ifdef __MMI_TONE_LIST_STYLE_CHANGED__
  818. /*****************************************************************************
  819.  * FUNCTION
  820.  *  UpdateDeleteExtMldToneSetup
  821.  * DESCRIPTION
  822.  *  set default tone when selected extented Melody MS tone is deleted.
  823.  * PARAMETERS
  824.  *  ToneId      [IN]        
  825.  * RETURNS
  826.  *  void
  827.  *****************************************************************************/
  828. void UpdateDeleteExtMSMldToneSetup(U16 ToneId)
  829. {
  830.     /*----------------------------------------------------------------*/
  831.     /* Local Variables                                                */
  832.     /*----------------------------------------------------------------*/
  833.     U8 i, dirtyFlag = 0;
  834.     S16 error = 0;
  835.     /*----------------------------------------------------------------*/
  836.     /* Code Body                                                      */
  837.     /*----------------------------------------------------------------*/
  838.     /* Update alarm ring tone list */
  839.     for (i = 0; i < MAX_ELEMENTS; i++)
  840.     {
  841.         if(gprofiles[i].toneSetup.messageTone == ToneId) //(gprofiles[i].toneSetup.messageTone < gstartMiscToneId || gprofiles[i].toneSetup.messageTone >(gstartMiscToneId + 10 )) //Old:  (gprofiles[i].toneSetup.messageTone == ToneId) #KP Joey modified on 2007-04-09
  842.         {
  843.             gprofiles[i].toneSetup.messageTone = gstartMiscToneId + 4;//Joey added for returning to silence on 2007-4-07 ;
  844.             dirtyFlag = 1;
  845.         }
  846.        if (gprofiles[i].toneSetup.powerOffTone == ToneId)
  847.         {
  848.             gprofiles[i].toneSetup.powerOffTone = gstartGeneralToneId + 1;
  849.             dirtyFlag = 1;
  850.         }
  851.         if (gprofiles[i].toneSetup.powerOnTone == ToneId)
  852.         {
  853.             gprofiles[i].toneSetup.powerOnTone = gstartGeneralToneId;
  854.             dirtyFlag = 1;
  855.         }
  856.        if (gprofiles[i].toneSetup.coverOpenTone== ToneId)
  857.         {
  858.             gprofiles[i].toneSetup.coverOpenTone = gstartGeneralToneId + 2;
  859.             dirtyFlag = 1;
  860.         }
  861.        if (gprofiles[i].toneSetup.coverCloseTone== ToneId)
  862.         {
  863.             gprofiles[i].toneSetup.coverCloseTone = gstartGeneralToneId + 3;
  864.             dirtyFlag = 1;
  865.         }
  866.     }
  867.     if (dirtyFlag == 1)
  868.         if (WriteRecord(
  869.                 NVRAM_EF_PROFILES_LID,
  870.                 1,
  871.                 &gprofiles[0],
  872.                 NVRAM_PROFILES_RECORD_SIZE,
  873.                 &error) < NVRAM_PROFILES_RECORD_SIZE)
  874.         {
  875.             PRINT_INFORMATION(("## ERROR: SetRingToneID: WriteRecord " "to NVRAM failed (ecode%d)n", (int)error));
  876.             return;
  877.         }
  878.     if (gactivatedprofile == gprofileId)
  879.     {
  880.         memcpy(&gcurrentprofile, &gprofiles[gprofileId], sizeof(PROFILE));
  881.     }
  882. }
  883. #endif
  884. //KP Jerry add for changing the style of message tone list on 2007-4-10 end
  885. #endif /* __MMI_PROFILE_EXTMELODY_SUPPORT__ */ 
  886. /*****************************************************************************
  887.  * FUNCTION
  888.  *  UpdateDeleteDownloadedAlarmTone
  889.  * DESCRIPTION
  890.  *  set default tone when selected downloaded alarm tone is deleted.
  891.  * PARAMETERS
  892.  *  ToneId      [IN]        
  893.  * RETURNS
  894.  *  void
  895.  *****************************************************************************/
  896. void UpdateDeleteDownloadedAlarmTone(U16 ToneId)
  897. {
  898.     /*----------------------------------------------------------------*/
  899.     /* Local Variables                                                */
  900.     /*----------------------------------------------------------------*/
  901.     /*----------------------------------------------------------------*/
  902.     /* Code Body                                                      */
  903.     /*----------------------------------------------------------------*/
  904.     if (gcurrentprofile.toneSetup.alarmTone == ToneId)
  905.     {
  906.         TONE_SETUP tonesetup;
  907.         tonesetup.alarmTone = gstartMidiId + 1;
  908.         SetAlarmToneID(tonesetup.alarmTone);
  909.     }
  910. }
  911. /*****************************************************************************
  912.  * FUNCTION
  913.  *  SetCurrentProfileAsActivatedProfile
  914.  * DESCRIPTION
  915.  *  Sets Current Profile As Activated Profile
  916.  * PARAMETERS
  917.  *  void
  918.  * RETURNS
  919.  *  void
  920.  *****************************************************************************/
  921. void SetCurrentProfileAsActivatedProfile(void)
  922. {
  923.     /*----------------------------------------------------------------*/
  924.     /* Local Variables                                                */
  925.     /*----------------------------------------------------------------*/
  926.     /*----------------------------------------------------------------*/
  927.     /* Code Body                                                      */
  928.     /*----------------------------------------------------------------*/
  929.     gprofileId = gactivatedprofile;
  930. }
  931. /*****************************************************************************
  932.  * FUNCTION
  933.  *  IsHeadsetModeActivated
  934.  * DESCRIPTION
  935.  *  Tells if headset mode is activated
  936.  * PARAMETERS
  937.  *  void
  938.  * RETURNS
  939.  * BOOL
  940.  *****************************************************************************/
  941. BOOL IsHeadsetModeActivated(void)
  942. {
  943.     /*----------------------------------------------------------------*/
  944.     /* Local Variables                                                */
  945.     /*----------------------------------------------------------------*/
  946.     /*----------------------------------------------------------------*/
  947.     /* Code Body                                                      */
  948.     /*----------------------------------------------------------------*/
  949.     if (gactivatedprofile == MMI_PROFILE_HEADSET)
  950.     {
  951.         return TRUE;
  952.     }
  953.     else
  954.     {
  955.         return FALSE;
  956.     }
  957. }
  958. /*****************************************************************************
  959.  * FUNCTION
  960.  *  IsSilentModeActivated
  961.  * DESCRIPTION
  962.  *  Tells if silent mode is activated
  963.  * PARAMETERS
  964.  *  void
  965.  * RETURNS
  966.  *  pBOOL
  967.  *****************************************************************************/
  968. pBOOL IsSilentModeActivated(void)
  969. {
  970.     /*----------------------------------------------------------------*/
  971.     /* Local Variables                                                */
  972.     /*----------------------------------------------------------------*/
  973.     /*----------------------------------------------------------------*/
  974.     /* Code Body                                                      */
  975.     /*----------------------------------------------------------------*/
  976.     if (gactivatedprofile == MMI_PROFILE_SILENT)
  977.     {
  978.         return TRUE;
  979.     }
  980.     else
  981.     {
  982.         return FALSE;
  983.     }
  984. }
  985. /*****************************************************************************
  986.  * FUNCTION
  987.  *  IsMeetingModeActivated
  988.  * DESCRIPTION
  989.  *  Tells if meeting mode is activated
  990.  * PARAMETERS
  991.  *  void
  992.  * RETURNS
  993.  * BOOL
  994.  *  
  995.  *****************************************************************************/
  996. BOOL IsMeetingModeActivated(void)
  997. {
  998.     /*----------------------------------------------------------------*/
  999.     /* Local Variables                                                */
  1000.     /*----------------------------------------------------------------*/
  1001.     /*----------------------------------------------------------------*/
  1002.     /* Code Body                                                      */
  1003.     /*----------------------------------------------------------------*/
  1004.     if (gactivatedprofile == MMI_PROFILE_MEETING)
  1005.     {
  1006.         return TRUE;
  1007.     }
  1008.     else
  1009.     {
  1010.         return FALSE;
  1011.     }
  1012. }
  1013. /* MTK robin 1119, AT command set wallpaper and profile */
  1014. /*****************************************************************************
  1015.  * FUNCTION
  1016.  *  AtSetProfileTone
  1017.  * DESCRIPTION
  1018.  *  
  1019.  * PARAMETERS
  1020.  *  profileID       [IN]        
  1021.  *  tone_type       [IN]        
  1022.  *  tone_idx        [IN]        
  1023.  * RETURNS
  1024.  *  
  1025.  *****************************************************************************/
  1026. BOOL AtSetProfileTone(U8 profileID, PROFILE_TONE_TYPE_ENUM tone_type, U8 tone_idx)
  1027. {
  1028.     /*----------------------------------------------------------------*/
  1029.     /* Local Variables                                                */
  1030.     /*----------------------------------------------------------------*/
  1031.     S16 error = 0;
  1032.     U16 j = 1;
  1033.     /*----------------------------------------------------------------*/
  1034.     /* Code Body                                                      */
  1035.     /*----------------------------------------------------------------*/
  1036.     if (profileID >= MAX_PROFILE_NUM || tone_type >= TONE_MAX_TONE_TYPE || tone_idx > 10)
  1037.     {
  1038.         return MMI_FALSE;
  1039.     }
  1040.     switch (tone_type)
  1041.     {
  1042.         case TONE_POWERONTONE:
  1043.             if (tone_idx == 0)
  1044.             {
  1045.                 gprofiles[profileID].toneSetup.powerOnTone = POWERON_SILENT;
  1046.             }
  1047.             else
  1048.             {
  1049.                 gprofiles[profileID].toneSetup.powerOnTone = gstartGeneralToneId + tone_idx - 1;
  1050.             }
  1051.             break;
  1052.         default:
  1053.             return MMI_FALSE;
  1054.     }
  1055.     if (WriteRecord(NVRAM_EF_PROFILES_LID, j, &gprofiles[0], NVRAM_PROFILES_RECORD_SIZE, &error) <
  1056.         NVRAM_PROFILES_RECORD_SIZE)
  1057.     {
  1058.         PRINT_INFORMATION(("## ERROR: SetPowerOnToneType: WriteRecord " "to NVRAM failed (ecode%d)n", (int)error));
  1059.         return MMI_FALSE;
  1060.     }
  1061.     if (gactivatedprofile == gprofileId)
  1062.     {
  1063.         memcpy(&gcurrentprofile, &gprofiles[gprofileId], sizeof(PROFILE));
  1064.     }
  1065.     return MMI_TRUE;
  1066. }
  1067. /* MTK end */
  1068. //KP Jerry add on 2007-4-1 start
  1069. #ifdef __MMI_PROFILE_POWER_SAVING__
  1070. /*****************************************************************************
  1071.  * FUNCTION
  1072.  *  mmi_profiles_power_saving_activate_profile
  1073.  * DESCRIPTION
  1074.  *  Activating Headset profile
  1075.  * PARAMETERS
  1076.  *  void
  1077.  * RETURNS
  1078.  *  void
  1079.  *****************************************************************************/
  1080. void mmi_profiles_power_saving_activate_profile(void)
  1081. {
  1082.     /*----------------------------------------------------------------*/
  1083.     /* Local Variables                                                */
  1084.     /*----------------------------------------------------------------*/
  1085.     S16 error = 0;
  1086.     /*----------------------------------------------------------------*/
  1087.     /* Code Body                                                      */
  1088.     /*----------------------------------------------------------------*/
  1089.     ClearKeyEvents();
  1090.     PRINT_INFORMATION(("mmi_profiles_power_saving_activate_profile: gactivatedprofile =%d, glastactivatedprofile = %dn",
  1091.                        gactivatedprofile, glastactivatedprofile));
  1092.     /* MTK Modified, Robin 1017, prevent activated profile and last actived profile become same one */
  1093. #ifdef __MMI_BT_PROFILE__
  1094.     if (gactivatedprofile != MMI_PROFILE_SILENT && gactivatedprofile != MMI_PROFILE_HEADSET &&
  1095.         gactivatedprofile != MMI_PROFILE_BT && gactivatedprofile != MMI_PROFILE_POWER_SAVING)
  1096. #else /* __MMI_BT_PROFILE__ */ 
  1097.     if (gactivatedprofile != MMI_PROFILE_SILENT && gactivatedprofile != MMI_PROFILE_HEADSET && 
  1098.  gactivatedprofile != MMI_PROFILE_POWER_SAVING)
  1099. #endif /* __MMI_BT_PROFILE__ */ 
  1100.         glastactivatedprofile = gactivatedprofile;
  1101.     gactivatedprofile = MMI_PROFILE_POWER_SAVING;
  1102.     memcpy(&gcurrentprofile, &gprofiles[gactivatedprofile], sizeof(PROFILE));
  1103.     WriteValue(NVRAM_PROFILES_LASTACTIVATED, &glastactivatedprofile, DS_BYTE, &error);
  1104.     WriteValue(NVRAM_PROFILES_ACTIVATED, &gactivatedprofile, DS_BYTE, &error);
  1105.     showAlertStatusIcons();
  1106.     change_font();
  1107.     /* SetRingerVolume(GetRingVolumeLevel()); */
  1108.     mdi_audio_set_volume_no_apply(MDI_VOLUME_MEDIA, GetRingVolumeLevel());
  1109.     SetKeyPadVolume(GetKeypadVolumeLevel());
  1110.     mdi_audio_set_mic_volume();
  1111.     ActivateProfile();
  1112.     DisplayPopup((U8*) GetString(STR_POWER_SAVING_ACTIVATE_MESSAGE), IMG_GLOBAL_ACTIVATED, 1, 2000, (U8) SUCCESS_TONE);
  1113. }
  1114. /*****************************************************************************
  1115.  * FUNCTION
  1116.  *  mmi_profiles_power_saving_deactivate_profile
  1117.  * DESCRIPTION
  1118.  *  Deactivate Headset profile
  1119.  * PARAMETERS
  1120.  *  void
  1121.  * RETURNS
  1122.  *  void
  1123.  *****************************************************************************/
  1124. void mmi_profiles_power_saving_deactivate_profile(void)
  1125. {
  1126.     /*----------------------------------------------------------------*/
  1127.     /* Local Variables                                                */
  1128.     /*----------------------------------------------------------------*/
  1129.     S16 error = 0;
  1130.     /*----------------------------------------------------------------*/
  1131.     /* Code Body                                                      */
  1132.     /*----------------------------------------------------------------*/
  1133.     PRINT_INFORMATION(("mmi_profiles_headset_deactivate_profile: gactivatedprofile =%d, glastactivatedprofile = %dn",
  1134.                        gactivatedprofile, glastactivatedprofile));
  1135.     ReadValue(NVRAM_PROFILES_LASTACTIVATED, &glastactivatedprofile, DS_BYTE, &error);
  1136. #ifdef __MMI_BT_PROFILE__
  1137. #endif 
  1138.     gactivatedprofile = glastactivatedprofile;
  1139.     WriteValue(NVRAM_PROFILES_ACTIVATED, &gactivatedprofile, DS_BYTE, &error);
  1140.     //ReadValue(NVRAM_PROFILES_ACTIVATED, &gactivatedprofile, DS_BYTE, &error);
  1141.     memcpy(&gcurrentprofile, &gprofiles[gactivatedprofile], sizeof(PROFILE));
  1142.     showAlertStatusIcons();
  1143.     change_font();
  1144.     /* SetRingerVolume(GetRingVolumeLevel()); */
  1145.     mdi_audio_set_volume_no_apply(MDI_VOLUME_MEDIA, GetRingVolumeLevel());
  1146.     SetKeyPadVolume(GetKeypadVolumeLevel());
  1147.     mdi_audio_set_mic_volume();
  1148.     ActivateProfile();
  1149.     switch (gactivatedprofile)
  1150.         {
  1151.             case MMI_PROFILE_GENERAL:
  1152.                 DisplayPopup(
  1153.                     (U8*) GetString(STR_GENERAL_RESTORED_MESSAGE),
  1154.                     IMG_GLOBAL_ACTIVATED,
  1155.                     1,
  1156.                     2000,
  1157.                     (U8) SUCCESS_TONE);
  1158.                 break;
  1159.             case MMI_PROFILE_MEETING:
  1160.                 DisplayPopup(
  1161.                     (U8*) GetString(STR_MEETING_RESTORED_MESSAGE),
  1162.                     IMG_GLOBAL_ACTIVATED,
  1163.                     1,
  1164.                     2000,
  1165.                     (U8) SUCCESS_TONE);
  1166.                 break;
  1167.             case MMI_PROFILE_OUTDOOR:
  1168.                 DisplayPopup(
  1169.                     (U8*) GetString(STR_OUTDOOR_RESTORED_MESSAGE),
  1170.                     IMG_GLOBAL_ACTIVATED,
  1171.                     1,
  1172.                     2000,
  1173.                     (U8) SUCCESS_TONE);
  1174.                 break;
  1175.             case MMI_PROFILE_INDOOR:
  1176.                 DisplayPopup(
  1177.                     (U8*) GetString(STR_INDOOR_RESTORED_MESSAGE),
  1178.                     IMG_GLOBAL_ACTIVATED,
  1179.                     1,
  1180.                     2000,
  1181.                     (U8) SUCCESS_TONE);
  1182.                 break;
  1183.             case MMI_PROFILE_HEADSET:
  1184.                 /* DisplayPopup((U8*)GetString(STR_HEADSET_RESTORED_MESSAGE),IMG_GLOBAL_ACTIVATED,1,2000,(U8)SUCCESS_TONE); */
  1185.                 break;
  1186. #ifdef __MMI_PROFILE_POWER_SAVING__
  1187.             case MMI_PROFILE_POWER_SAVING:
  1188.                 DisplayPopup(
  1189.                     (U8*) GetString(STR_POWER_SAVING_RESTORED_MESSAGE),
  1190.                     IMG_GLOBAL_ACTIVATED,
  1191.                     1,
  1192.                     2000,
  1193.                     (U8) SUCCESS_TONE);
  1194.                 break;
  1195. #endif
  1196.         #ifdef __MMI_BT_PROFILE__
  1197.             case MMI_PROFILE_BT:
  1198.         #endif 
  1199.                 break;
  1200.         }
  1201. }
  1202. #endif
  1203. //KP Jerry add on 2007-4-1 end
  1204. /*****************************************************************************
  1205.  * FUNCTION
  1206.  *  mmi_profiles_headset_activate_profile
  1207.  * DESCRIPTION
  1208.  *  Activating Headset profile
  1209.  * PARAMETERS
  1210.  *  void
  1211.  * RETURNS
  1212.  *  void
  1213.  *****************************************************************************/
  1214. void mmi_profiles_headset_activate_profile(void)
  1215. {
  1216.     /*----------------------------------------------------------------*/
  1217.     /* Local Variables                                                */
  1218.     /*----------------------------------------------------------------*/
  1219.     S16 error = 0;
  1220.     /*----------------------------------------------------------------*/
  1221.     /* Code Body                                                      */
  1222.     /*----------------------------------------------------------------*/
  1223.     PRINT_INFORMATION(("mmi_profiles_headset_activate_profile: gactivatedprofile =%d, glastactivatedprofile = %dn",
  1224.                        gactivatedprofile, glastactivatedprofile));
  1225.     gprofileheadset = 1;
  1226.     /* MTK Modified, Robin 1017, prevent activated profile and last actived profile become same one */
  1227. //KP Jerry modify on 2007-4-3 start
  1228. #ifdef __MMI_PROFILE_POWER_SAVING__
  1229. #ifdef __MMI_BT_PROFILE__
  1230.     if (gactivatedprofile != MMI_PROFILE_SILENT && gactivatedprofile != MMI_PROFILE_HEADSET &&
  1231.         gactivatedprofile != MMI_PROFILE_BT && gactivatedprofile != MMI_PROFILE_POWER_SAVING)
  1232. #else /* __MMI_BT_PROFILE__ */ 
  1233.     if (gactivatedprofile != MMI_PROFILE_SILENT && gactivatedprofile != MMI_PROFILE_HEADSET && gactivatedprofile != MMI_PROFILE_POWER_SAVING)
  1234. #endif /* __MMI_BT_PROFILE__ */ 
  1235. #else/*!__MMI_PROFILE_POWER_SAVING__*/
  1236. #ifdef __MMI_BT_PROFILE__
  1237.     if (gactivatedprofile != MMI_PROFILE_SILENT && gactivatedprofile != MMI_PROFILE_HEADSET &&
  1238.         gactivatedprofile != MMI_PROFILE_BT)
  1239. #else /* __MMI_BT_PROFILE__ */ 
  1240.     if (gactivatedprofile != MMI_PROFILE_SILENT && gactivatedprofile != MMI_PROFILE_HEADSET)
  1241. #endif /* __MMI_BT_PROFILE__ */ 
  1242. #endif/*__MMI_PROFILE_POWER_SAVING__*/
  1243. //KP Jerry modify on 2007-4-3 end
  1244.         glastactivatedprofile = gactivatedprofile;
  1245.     gactivatedprofile = MMI_PROFILE_HEADSET;
  1246.     memcpy(&gcurrentprofile, &gprofiles[gactivatedprofile], sizeof(PROFILE));
  1247.     WriteValue(NVRAM_PROFILES_LASTACTIVATED, &glastactivatedprofile, DS_BYTE, &error);
  1248.     showAlertStatusIcons();
  1249.     change_font();
  1250.     /* SetRingerVolume(GetRingVolumeLevel()); */
  1251.     mdi_audio_set_volume_no_apply(MDI_VOLUME_MEDIA, GetRingVolumeLevel());
  1252.     SetKeyPadVolume(GetKeypadVolumeLevel());
  1253.     mdi_audio_set_mic_volume();
  1254.     if (gloudSpeaker == 1)
  1255.     {
  1256.         gloudSpeaker = 0;
  1257.         SetLSpkNowOff(TRUE);
  1258.     }
  1259. //KP Jerry add on 2007-03-31 start
  1260. #ifdef __MMI_PROFILE_POWER_SAVING__
  1261.     ProfileResetBackLightSetting();
  1262.     ProfilesResetKeyBacklight();
  1263.     SetGPIOLevelReq(GPIO_DEV_LED_MAINLCD, LED_LIGHT_LEVEL5);
  1264. #endif
  1265. //KP Jerry add on 2007-03-31 end
  1266. }
  1267. /*****************************************************************************
  1268.  * FUNCTION
  1269.  *  mmi_profiles_headset_deactivate_profile
  1270.  * DESCRIPTION
  1271.  *  Deactivate Headset profile
  1272.  * PARAMETERS
  1273.  *  void
  1274.  * RETURNS
  1275.  *  void
  1276.  *****************************************************************************/
  1277. void mmi_profiles_headset_deactivate_profile(void)
  1278. {
  1279.     /*----------------------------------------------------------------*/
  1280.     /* Local Variables                                                */
  1281.     /*----------------------------------------------------------------*/
  1282.     S16 error = 0;
  1283.     /*----------------------------------------------------------------*/
  1284.     /* Code Body                                                      */
  1285.     /*----------------------------------------------------------------*/
  1286.     PRINT_INFORMATION(("mmi_profiles_headset_deactivate_profile: gactivatedprofile =%d, glastactivatedprofile = %dn",
  1287.                        gactivatedprofile, glastactivatedprofile));
  1288.     gprofileheadset = 0;
  1289.     ReadValue(NVRAM_PROFILES_LASTACTIVATED, &glastactivatedprofile, DS_BYTE, &error);
  1290. #ifdef __MMI_BT_PROFILE__
  1291. #endif 
  1292.     ReadValue(NVRAM_PROFILES_ACTIVATED, &gactivatedprofile, DS_BYTE, &error);
  1293.     memcpy(&gcurrentprofile, &gprofiles[gactivatedprofile], sizeof(PROFILE));
  1294.     showAlertStatusIcons();
  1295.     change_font();
  1296.     /* SetRingerVolume(GetRingVolumeLevel()); */
  1297.     mdi_audio_set_volume_no_apply(MDI_VOLUME_MEDIA, GetRingVolumeLevel());
  1298.     SetKeyPadVolume(GetKeypadVolumeLevel());
  1299.     mdi_audio_set_mic_volume();
  1300. //KP Jerry add on 2007-03-31 start
  1301. #ifdef __MMI_PROFILE_POWER_SAVING__
  1302.     ProfileResetBackLightSetting();
  1303.     ProfilesResetKeyBacklight();
  1304.     SetGPIOLevelReq(GPIO_DEV_LED_MAINLCD, LED_LIGHT_LEVEL5);
  1305. #endif
  1306. //KP Jerry add on 2007-03-31 end
  1307. }
  1308. /*****************************************************************************
  1309.  * FUNCTION
  1310.  *  mmi_profiles_earphone_plug_in_callback
  1311.  * DESCRIPTION
  1312.  *  invoke it when plug in earphone
  1313.  * PARAMETERS
  1314.  *  void
  1315.  * RETURNS
  1316.  *  void
  1317.  *****************************************************************************/
  1318. void mmi_profiles_earphone_plug_in_callback(void)
  1319. {
  1320.     /*----------------------------------------------------------------*/
  1321.     /* Local Variables                                                */
  1322.     /*----------------------------------------------------------------*/
  1323.     /*----------------------------------------------------------------*/
  1324.     /* Code Body                                                      */
  1325.     /*----------------------------------------------------------------*/
  1326.     if (mmi_bootup_is_in_power_on_period() == MMI_FALSE)
  1327.     {
  1328.         PRINT_INFORMATION(("mmi_profiles_earphone_plug_in_callback: gactivatedprofile =%dn", gactivatedprofile));
  1329.         mdi_audio_set_audio_mode(AUD_MODE_HEADSET);
  1330.         SetModeSpeechVolume();
  1331.     #ifdef __MMI_BT_PROFILE__
  1332.         if (gactivatedprofile == MMI_PROFILE_BT)
  1333.         {
  1334.         #ifdef __MMI_HFP_SUPPORT__
  1335.             mmi_profiles_bt_disconnect_req(MMI_PROFILES_BT_HFP_SCO);
  1336.         #endif 
  1337.         #if defined(__MMI_BT_BCHS_SUPPORT__)&& defined(__MMI_A2DP_SUPPORT__)
  1338.             mdi_audio_bt_a2dp_turn_off();
  1339.         #endif 
  1340.         }
  1341.     #endif /* __MMI_BT_PROFILE__ */ 
  1342.         mmi_profiles_headset_activate_profile();
  1343.     #if defined(__MMI_FM_RADIO__) && defined(__MMI_FM_RADIO_BIND_EARPHONE__)
  1344.         mmi_fmrdo_power_on_main_screen(TRUE);
  1345.     #endif 
  1346.     }
  1347.     else
  1348.     {
  1349.         mdi_audio_set_audio_mode(AUD_MODE_HEADSET);
  1350.     }
  1351. }
  1352. /*****************************************************************************
  1353.  * FUNCTION
  1354.  *  mmi_profiles_earphone_plug_out_callback
  1355.  * DESCRIPTION
  1356.  *  invoke it when plug out earphone
  1357.  * PARAMETERS
  1358.  *  void
  1359.  * RETURNS
  1360.  *  void
  1361.  *****************************************************************************/
  1362. void mmi_profiles_earphone_plug_out_callback(void)
  1363. {
  1364.     /*----------------------------------------------------------------*/
  1365.     /* Local Variables                                                */
  1366.     /*----------------------------------------------------------------*/
  1367.     /*----------------------------------------------------------------*/
  1368.     /* Code Body                                                      */
  1369.     /*----------------------------------------------------------------*/
  1370.     if (mmi_bootup_is_in_power_on_period() == MMI_FALSE)
  1371.     {
  1372.         PRINT_INFORMATION(("mmi_profiles_earphone_plug_out_callback: gactivatedprofile =%dn", gactivatedprofile));
  1373.     #if defined(__MMI_FM_RADIO__) && defined(__MMI_FM_RADIO_BIND_EARPHONE__)
  1374.         mmi_fmrdo_power_on(FALSE);
  1375.     #endif 
  1376.     #ifdef __MMI_BT_PROFILE__
  1377.     #if 0 /* If in bluetooth profile, try to connect SCO back if in call */
  1378. /* under construction !*/
  1379. /* under construction !*/
  1380. /* under construction !*/
  1381. /* under construction !*/
  1382. /* under construction !*/
  1383. /* under construction !*/
  1384. /* under construction !*/
  1385. /* under construction !*/
  1386. /* under construction !*/
  1387.     #endif
  1388.     #ifdef __MMI_HFP_SUPPORT__
  1389.         if (mmi_profiles_bt_is_connected(MMI_PROFILES_BT_HFP_ACL))
  1390.         {
  1391.             mmi_profiles_bt_activate_profile();
  1392.             /* Always connect if Audio via SCO is on */
  1393.         #if !defined(__MMI_BT_AUDIO_VIA_SCO__)
  1394.             if (g_mmi_profiles_bt_in_call && (g_mmi_profiles_bt_always_use_in_call || mmi_bt_is_aud2hf()))
  1395.         #endif
  1396.             {
  1397.                 mmi_profiles_bt_connect_req(MMI_PROFILES_BT_HFP_SCO);
  1398.             }
  1399.         }
  1400.     #endif /* __MMI_HFP_SUPPORT__ */ 
  1401.     #if defined(__MMI_BT_BCHS_SUPPORT__) && defined(__MMI_A2DP_SUPPORT__)
  1402.         if (mmi_profiles_bt_is_connected(MMI_PROFILES_BT_A2DP_SIG))
  1403.         {
  1404.             if (gactivatedprofile != MMI_PROFILE_BT)
  1405.             {
  1406.                 mmi_profiles_bt_activate_profile();
  1407.             }
  1408.             if (!g_mmi_profiles_bt_in_call)
  1409.             {
  1410.                 mdi_audio_bt_a2dp_turn_on();
  1411.             #if defined(__MMI_AUDIO_PLAYER__) && defined(__MMI_AUDIO_SPECTRUM_DISPLAY__) && defined(__MMI_A2DP_PROHIBIT_AUDIO_SPECTRUM_DISPLAY__)
  1412.                 mmi_audply_disable_spectrum_display();
  1413.             #endif 
  1414.             }
  1415.         }
  1416.     #endif /* __MMI_BT_BCHS_SUPPORT__ && __MMI_A2DP_SUPPORT__ */ 
  1417.     #endif /* __MMI_BT_PROFILE__ */ 
  1418.         if (mdi_audio_get_audio_mode() != AUD_MODE_LOUDSPK)
  1419.         {
  1420.             mdi_audio_set_audio_mode(AUD_MODE_NORMAL);
  1421.             SetModeSpeechVolume();
  1422.         }
  1423.         if (gactivatedprofile == MMI_PROFILE_HEADSET)
  1424.         {
  1425.             mmi_profiles_headset_deactivate_profile();
  1426.         }
  1427.     }
  1428.     else
  1429.     {
  1430.         mdi_audio_set_audio_mode(AUD_MODE_NORMAL);
  1431.     }
  1432. }
  1433. #ifdef __MMI_BT_PROFILE__
  1434. /*****************************************************************************
  1435.  * FUNCTION
  1436.  *  mmi_profiles_bt_allow_popup
  1437.  * DESCRIPTION
  1438.  *  check is it allowed to popup
  1439.  * PARAMETERS
  1440.  *  void
  1441.  * RETURNS
  1442.  * BOOL
  1443.  *****************************************************************************/
  1444. BOOL mmi_profiles_bt_allow_popup(void)
  1445. {
  1446.     /*----------------------------------------------------------------*/
  1447.     /* Local Variables                                                */
  1448.     /*----------------------------------------------------------------*/
  1449.     /*----------------------------------------------------------------*/
  1450.     /* Code Body                                                      */
  1451.     /*----------------------------------------------------------------*/
  1452.     return g_mmi_profiles_bt_in_call;
  1453. }
  1454. /*****************************************************************************
  1455.  * FUNCTION
  1456.  *  mmi_profiles_bt_connect_sco
  1457.  * DESCRIPTION
  1458.  *  connect sco link
  1459.  * PARAMETERS
  1460.  *  callback        [IN]        )(void)
  1461.  * RETURNS
  1462.  * BOOL
  1463.  *****************************************************************************/
  1464. BOOL mmi_profiles_bt_connect_sco(void (*callback) (void))
  1465. {
  1466.     /*----------------------------------------------------------------*/
  1467.     /* Local Variables                                                */
  1468.     /*----------------------------------------------------------------*/
  1469.     BOOL connect = FALSE;
  1470.     S32 connect_id;
  1471.     /*----------------------------------------------------------------*/
  1472.     /* Code Body                                                      */
  1473.     /*----------------------------------------------------------------*/
  1474. #ifdef __MMI_HFP_SUPPORT__
  1475.     PRINT_INFORMATION( ("mmi_profiles_bt_connect_sco: Allow SCO=[%d], BT Inquery=[%d]n", g_mmi_profiles_bt_allow_sco, g_mmi_profiles_bt_inquerying) );
  1476.     
  1477.     if(g_mmi_profiles_bt_allow_sco &&
  1478.        !g_mmi_profiles_bt_inquerying &&
  1479.        gactivatedprofile == MMI_PROFILE_BT )
  1480.     {
  1481.      if( mmi_bt_is_hs_connected() )
  1482.      {
  1483.      connect_id = mmi_bt_get_active_signal_connection_id( MMI_BT_HFG_PROFILE_UUID );
  1484.      ASSERT( connect_id >= 0 );
  1485.      connect = mdi_audio_bt_open_stream( BT_HFP, (U16)connect_id );
  1486.      if( connect )
  1487.      {
  1488.      mmi_profiles_bt_connect_sco_app_callback = callback;
  1489.      }
  1490.         #ifdef __MMI_BT_AUDIO_VIA_SCO__
  1491.             /* Already Connected, start a timeout timer */
  1492.             else if(g_mmi_profiles_bt_sco_timeout && 
  1493.                     mmi_profiles_bt_is_connected(MMI_PROFILES_BT_HFP_SCO))
  1494.             {
  1495.                 StartTimer(BT_SCO_CONNECT_TIMER, BT_SCO_CONNECT_TIMEOUT_DURATION, mmi_profiles_bt_sco_timeout);
  1496.             }
  1497.         #endif /* __MMI_BT_AUDIO_VIA_SCO__ */
  1498.      }
  1499.      g_mmi_profiles_bt_app_in_use = TRUE;
  1500.     }
  1501. #endif /* __MMI_HFP_SUPPORT__ */ 
  1502.     return connect;
  1503. }
  1504. /*****************************************************************************
  1505.  * FUNCTION
  1506.  *  mmi_profiles_bt_disconnect_sco
  1507.  * DESCRIPTION
  1508.  *  disconnect sco link
  1509.  * PARAMETERS
  1510.  *  void
  1511.  * RETURNS
  1512.  * BOOL
  1513.  *****************************************************************************/
  1514. BOOL mmi_profiles_bt_disconnect_sco(void)
  1515. {
  1516.     /*----------------------------------------------------------------*/
  1517.     /* Local Variables                                                */
  1518.     /*----------------------------------------------------------------*/
  1519.     BOOL disconnect = FALSE;
  1520.     /*----------------------------------------------------------------*/
  1521.     /* Code Body                                                      */
  1522.     /*----------------------------------------------------------------*/
  1523. #ifdef __MMI_HFP_SUPPORT__
  1524.     PRINT_INFORMATION( ("mmi_profiles_bt_disconnect_sco: in_call=%d, always_use=%d, aud2hf=%dn",
  1525.         g_mmi_profiles_bt_in_call,g_mmi_profiles_bt_always_use_in_call,mmi_bt_is_aud2hf()) );
  1526.     if (!g_mmi_profiles_bt_in_call || !(g_mmi_profiles_bt_always_use_in_call || mmi_bt_is_aud2hf()))
  1527.     {
  1528.         disconnect = mdi_audio_bt_is_stream_open(BT_HFP);
  1529.         mdi_audio_bt_close_stream(BT_HFP);
  1530.         mmi_profiles_bt_connect_sco_app_callback = NULL;
  1531.     }
  1532.     g_mmi_profiles_bt_app_in_use = FALSE;
  1533. #endif /* __MMI_HFP_SUPPORT__ */ 
  1534.     return disconnect;
  1535. }
  1536. /*****************************************************************************
  1537.  * FUNCTION
  1538.  *  mmi_profiles_bt_deactivate_cnf_hdlr
  1539.  * DESCRIPTION
  1540.  *  the cnf handler for bt a2dp deactivate req
  1541.  * PARAMETERS
  1542.  *  void
  1543.  * RETURNS
  1544.  *  void
  1545.  *****************************************************************************/
  1546. void mmi_profiles_bt_deactivate_cnf_hdlr(void)
  1547. {
  1548.     if (g_mmi_profiles_bt_reset_pending != 0)
  1549.     {
  1550.         g_mmi_profiles_bt_reset_pending &= 0x0D;
  1551.         if (g_mmi_profiles_bt_reset_pending == 0)
  1552.         {
  1553.             mmi_bt_panic_ind_post_process();
  1554.         }
  1555.     }
  1556. }
  1557. /*****************************************************************************
  1558.  * FUNCTION
  1559.  *  mmi_profiles_bt_reset
  1560.  * DESCRIPTION
  1561.  *  to reset bt profile
  1562.  * PARAMETERS
  1563.  *  void
  1564.  * RETURNS
  1565.  *  void
  1566.  *****************************************************************************/
  1567. void mmi_profiles_bt_reset(void)
  1568. {
  1569.     /*----------------------------------------------------------------*/
  1570.     /* Local Variables                                                */
  1571.     /*----------------------------------------------------------------*/
  1572.     /*----------------------------------------------------------------*/
  1573.     /* Code Body                                                      */
  1574.     /*----------------------------------------------------------------*/
  1575.     PRINT_INFORMATION(("mmi_profiles_bt_reset: reset_pending = %dn", g_mmi_profiles_bt_reset_pending));
  1576. #if defined(__MMI_BT_BCHS_SUPPORT__) && defined(__MMI_A2DP_SUPPORT__)
  1577.     if (mmi_profiles_bt_is_connected(MMI_PROFILES_BT_A2DP_STR))
  1578.     {
  1579.         g_mmi_profiles_bt_reset_pending |= 2;
  1580.         mmi_profiles_bt_disconnect_req(MMI_PROFILES_BT_A2DP_STR);
  1581.     }
  1582. #endif /* __MMI_BT_BCHS_SUPPORT__ && __MMI_A2DP_SUPPORT__ */
  1583. #if defined(__BTMTK__) && defined(__MMI_A2DP_SUPPORT__) && defined(__MMI_AUDIO_PLAYER__)
  1584.     mmi_audply_bt_power_off_callback(TRUE);
  1585.     mmi_bt_a2dp_deactivate_req();
  1586.     g_mmi_profiles_bt_reset_pending |= 2;
  1587. #endif
  1588. #ifdef __MMI_HFP_SUPPORT__
  1589.     if (mmi_profiles_bt_is_connected(MMI_PROFILES_BT_HFP_SCO))
  1590.     {
  1591.         g_mmi_profiles_bt_reset_pending |= 1;
  1592.         mmi_profiles_bt_disconnect_req(MMI_PROFILES_BT_HFP_SCO);
  1593.     }
  1594.     mmi_profiles_bt_connect_sco_app_callback = NULL;
  1595. #endif /* __MMI_HFP_SUPPORT__ */ 
  1596.     if (gactivatedprofile == MMI_PROFILE_BT)
  1597.     {
  1598.         if (mmi_gpio_is_earphone_plug_in())
  1599.         {
  1600.             mdi_audio_set_audio_mode(AUD_MODE_HEADSET);
  1601.             mmi_profiles_headset_activate_profile();
  1602.         }
  1603.         else
  1604.         {
  1605.             mmi_profiles_bt_deactivate_profile();
  1606.         }
  1607.     }
  1608.     if (g_mmi_profiles_bt_reset_pending == 0)
  1609.     {
  1610.         mmi_bt_panic_ind_post_process();
  1611.     }
  1612. }
  1613. /*****************************************************************************
  1614.  * FUNCTION
  1615.  *  mmi_profiles_bt_is_activated
  1616.  * DESCRIPTION
  1617.  *  to check if bt profile is activated
  1618.  * PARAMETERS
  1619.  *  void
  1620.  * RETURNS
  1621.  * BOOL
  1622.  *****************************************************************************/
  1623. BOOL mmi_profiles_bt_is_activated(void)
  1624. {
  1625.     /*----------------------------------------------------------------*/
  1626.     /* Local Variables                                                */
  1627.     /*----------------------------------------------------------------*/
  1628.     /*----------------------------------------------------------------*/
  1629.     /* Code Body                                                      */
  1630.     /*----------------------------------------------------------------*/
  1631.     return (gactivatedprofile == MMI_PROFILE_BT);
  1632. }
  1633. /*****************************************************************************
  1634.  * FUNCTION
  1635.  *  mmi_profiles_bt_open_stream_callback
  1636.  * DESCRIPTION
  1637.  *  a callback function for open bt stream cnf
  1638.  * PARAMETERS
  1639.  *  profile     [IN]        
  1640.  *  result      [IN]        
  1641.  * RETURNS
  1642.  *  void
  1643.  *****************************************************************************/
  1644. void mmi_profiles_bt_open_stream_callback(U8 profile, mdi_result result)
  1645. {
  1646.     /*----------------------------------------------------------------*/
  1647.     /* Local Variables                                                */
  1648.     /*----------------------------------------------------------------*/
  1649.     U16 res;
  1650.     /*----------------------------------------------------------------*/
  1651.     /* Code Body                                                      */
  1652.     /*----------------------------------------------------------------*/
  1653.     PRINT_INFORMATION(("mmi_profiles_bt_open_stream_callback: profile =%d, result = %dn", profile, result));
  1654.     if (result == MDI_AUDIO_SUCCESS)
  1655.     {
  1656.         res = MMI_PROFILES_BT_OK;
  1657.     }
  1658.     else if (result == MDI_AUDIO_BUSY)
  1659.     {
  1660.         res = MMI_PROFILES_BT_BUSY;
  1661.     }
  1662.     else
  1663.     {
  1664.         res = MMI_PROFILES_BT_FAIL;
  1665.     }
  1666.     switch (profile)
  1667.     {
  1668.     #ifdef __MMI_HFP_SUPPORT__
  1669.         case BT_HFP:
  1670.             mmi_profiles_bt_connect_callback(MMI_PROFILES_BT_HFP_SCO, MMI_PROFILES_BT_RSP, res);
  1671.             if( result == MDI_AUDIO_SUCCESS )
  1672.             {
  1673. #ifdef __MMI_BT_MTK_SUPPORT__
  1674. mmi_bth_sco_connect_ind_hdler(mmi_bt_get_active_signal_connection_id(MMI_BT_HFG_PROFILE_UUID));
  1675. #else
  1676.                 mmi_bchs_sco_connect_ind_hdler(mmi_bt_get_active_signal_connection_id(MMI_BT_HFG_PROFILE_UUID));
  1677. #endif
  1678.     #ifdef __MMI_BT_AUDIO_VIA_SCO__
  1679.                 PRINT_INFORMATION( ("Start SCO timer: flag = [%d]n",g_mmi_profiles_bt_sco_timeout) );
  1680.          if(g_mmi_profiles_bt_sco_timeout)
  1681.          {
  1682.                     StopTimer(BT_SCO_CONNECT_TIMER);
  1683.                     StartTimer(BT_SCO_CONNECT_TIMER, BT_SCO_CONNECT_TIMEOUT_DURATION, mmi_profiles_bt_sco_timeout);
  1684.                 }
  1685.     #endif /* #ifdef __MMI_BT_AUDIO_VIA_SCO__ */
  1686. }
  1687. else
  1688. {
  1689. #ifdef __MMI_BT_MTK_SUPPORT__
  1690. mmi_bth_sco_connect_cnf_hdler(1, mmi_bt_get_active_signal_connection_id(MMI_BT_HFG_PROFILE_UUID));
  1691. #else
  1692. mmi_bchs_sco_connect_cnf_hdler(1, mmi_bt_get_active_signal_connection_id(MMI_BT_HFG_PROFILE_UUID));
  1693. #endif
  1694. }
  1695.             if (mmi_profiles_bt_connect_sco_app_callback != NULL)
  1696.             {
  1697.                 mmi_profiles_bt_connect_sco_app_callback();
  1698.             }
  1699.             break;
  1700.     #endif /* __MMI_HFP_SUPPORT__ */ 
  1701.     #if defined(__MMI_BT_BCHS_SUPPORT__) && defined(__MMI_A2DP_SUPPORT__)
  1702.         case BT_A2DP:
  1703.             mmi_profiles_bt_connect_callback(MMI_PROFILES_BT_A2DP_STR, MMI_PROFILES_BT_RSP, res);
  1704.             break;
  1705.     #endif /* __MMI_BT_BCHS_SUPPORT__ && __MMI_A2DP_SUPPORT__ */ 
  1706.     }
  1707. }
  1708. /*****************************************************************************
  1709.  * FUNCTION
  1710.  *  mmi_profiles_bt_close_stream_callback
  1711.  * DESCRIPTION
  1712.  *  a callback function for close bt stream cnf
  1713.  * PARAMETERS
  1714.  *  profile     [IN]        
  1715.  *  result      [IN]        
  1716.  * RETURNS
  1717.  *  void
  1718.  *****************************************************************************/
  1719. void mmi_profiles_bt_close_stream_callback(U8 profile, mdi_result result)
  1720. {
  1721.     /*----------------------------------------------------------------*/
  1722.     /* Local Variables                                                */
  1723.     /*----------------------------------------------------------------*/
  1724. #if defined(__MMI_BT_AUDIO_VIA_SCO__) || defined(__MMI_BT_FM_VIA_SCO__)
  1725.     void (*inquery_callback) (void);
  1726. #endif    
  1727.     
  1728.     /*----------------------------------------------------------------*/
  1729.     /* Code Body                                                      */
  1730.     /*----------------------------------------------------------------*/
  1731.     PRINT_INFORMATION(("mmi_profiles_bt_close_stream_callback: profile =%d, result = %dn", profile, result));
  1732.     switch (profile)
  1733.     {
  1734.     #ifdef __MMI_HFP_SUPPORT__
  1735.         case BT_HFP:
  1736.             mmi_profiles_bt_disconnect_callback(MMI_PROFILES_BT_HFP_SCO, MMI_PROFILES_BT_RSP, MMI_PROFILES_BT_OK);
  1737.     #ifdef __MMI_BT_MTK_SUPPORT__
  1738.      mmi_bth_sco_disconnect_ind_hdler(mmi_bt_get_active_signal_connection_id(MMI_BT_HFG_PROFILE_UUID));
  1739.     #else
  1740.             mmi_bchs_sco_disconnect_ind_hdler(mmi_bt_get_active_signal_connection_id(MMI_BT_HFG_PROFILE_UUID));
  1741.     #endif 
  1742.     #if defined(__MMI_BT_AUDIO_VIA_SCO__) || defined(__MMI_BT_FM_VIA_SCO__)
  1743.             /* Callback inquery function because the SCO disconnect is called by BT inquery */
  1744.             if(g_mmi_profiles_bt_inquery_callback)
  1745.             {
  1746.                 inquery_callback = g_mmi_profiles_bt_inquery_callback;
  1747.                 g_mmi_profiles_bt_inquery_callback = NULL;                
  1748.                 inquery_callback();
  1749.             }
  1750.     #endif
  1751.             break;
  1752.     #endif /* __MMI_HFP_SUPPORT__ */ 
  1753.     #if defined(__MMI_BT_BCHS_SUPPORT__) && defined(__MMI_A2DP_SUPPORT__)
  1754.         case BT_A2DP:
  1755.             mmi_profiles_bt_disconnect_callback(MMI_PROFILES_BT_A2DP_STR, MMI_PROFILES_BT_RSP, MMI_PROFILES_BT_OK);
  1756.             break;
  1757.     #endif /* __MMI_BT_BCHS_SUPPORT__ && __MMI_A2DP_SUPPORT__ */ 
  1758.     }
  1759. }
  1760. /*****************************************************************************
  1761.  * FUNCTION
  1762.  *  mmi_profiles_bt_is_connected
  1763.  * DESCRIPTION
  1764.  *  to check if bt is connected
  1765.  * PARAMETERS
  1766.  *  connect_type        [IN]        
  1767.  * RETURNS
  1768.  * BOOL
  1769.  *****************************************************************************/
  1770. BOOL mmi_profiles_bt_is_connected(U8 connect_type)
  1771. {
  1772.     /*----------------------------------------------------------------*/
  1773.     /* Local Variables                                                */
  1774.     /*----------------------------------------------------------------*/
  1775.     BOOL bt_connect = FALSE;
  1776.     /*----------------------------------------------------------------*/
  1777.     /* Code Body                                                      */
  1778.     /*----------------------------------------------------------------*/
  1779.     switch (connect_type)
  1780.     {
  1781.     #ifdef __MMI_HFP_SUPPORT__
  1782.         case MMI_PROFILES_BT_HFP_ACL:
  1783.             bt_connect = (BOOL) mmi_bt_is_hs_connected();
  1784.             break;
  1785.         case MMI_PROFILES_BT_HFP_SCO:
  1786.             bt_connect = mdi_audio_bt_is_stream_open(BT_HFP);
  1787.             break;
  1788.     #endif /* __MMI_HFP_SUPPORT__ */ 
  1789.     #if defined(__MMI_BT_BCHS_SUPPORT__) && defined(__MMI_A2DP_SUPPORT__)
  1790.         case MMI_PROFILES_BT_A2DP_SIG:
  1791.             bt_connect = (mmi_bt_get_active_signal_connection_id(MMI_BT_ADVANCED_AUDIO_PROFILE_UUID) >= 0);
  1792.             break;
  1793.         case MMI_PROFILES_BT_A2DP_STR:
  1794.             bt_connect = mdi_audio_bt_is_stream_open(BT_A2DP);
  1795.             break;
  1796.     #endif /* __MMI_BT_BCHS_SUPPORT__ && __MMI_A2DP_SUPPORT__ */ 
  1797.         default:
  1798.             ASSERT(0);
  1799.     }
  1800.     PRINT_INFORMATION(("mmi_profiles_bt_is_connected: connect_type =%d, bt_connect = %dn", connect_type, bt_connect));
  1801.     return bt_connect;
  1802. }
  1803. /*****************************************************************************
  1804.  * FUNCTION
  1805.  *  mmi_profiles_bt_connect_req
  1806.  * DESCRIPTION
  1807.  *  bt connect request
  1808.  * PARAMETERS
  1809.  *  connect_type        [IN]        
  1810.  * RETURNS
  1811.  *  void
  1812.  *****************************************************************************/
  1813. void mmi_profiles_bt_connect_req(U8 connect_type)
  1814. {
  1815.     /*----------------------------------------------------------------*/
  1816.     /* Local Variables                                                */
  1817.     /*----------------------------------------------------------------*/
  1818.     S32 connect_id;
  1819.     /*----------------------------------------------------------------*/
  1820.     /* Code Body                                                      */
  1821.     /*----------------------------------------------------------------*/
  1822.     PRINT_INFORMATION(("mmi_profiles_bt_connect_req: connect_type =[%d], Allow SCO=[%d], BT Inquery=[%d]n", 
  1823.                         connect_type, g_mmi_profiles_bt_allow_sco, g_mmi_profiles_bt_inquerying));
  1824.     switch (connect_type)
  1825.     {
  1826.     #ifdef __MMI_HFP_SUPPORT__
  1827.         case MMI_PROFILES_BT_HFP_SCO:
  1828.             if(g_mmi_profiles_bt_allow_sco && !g_mmi_profiles_bt_inquerying)
  1829.             {
  1830.                 connect_id = mmi_bt_get_active_signal_connection_id(MMI_BT_HFG_PROFILE_UUID);
  1831.                 ASSERT(connect_id >= 0);
  1832.                 mdi_audio_bt_open_stream(BT_HFP, (U16) connect_id);
  1833.             }
  1834.             break;
  1835.     #endif /* __MMI_HFP_SUPPORT__ */ 
  1836.     #if defined(__MMI_BT_BCHS_SUPPORT__) && defined(__MMI_A2DP_SUPPORT__)
  1837.         case MMI_PROFILES_BT_A2DP_STR:
  1838.             connect_id = mmi_bt_get_active_signal_connection_id(MMI_BT_ADVANCED_AUDIO_PROFILE_UUID);
  1839.             ASSERT(connect_id >= 0);
  1840.             mdi_audio_bt_open_stream(BT_A2DP, (U16) connect_id);
  1841.             break;
  1842.     #endif /* __MMI_BT_BCHS_SUPPORT__ && __MMI_A2DP_SUPPORT__ */ 
  1843.         default:
  1844.             ASSERT(0);
  1845.     }
  1846. }
  1847. /*****************************************************************************
  1848.  * FUNCTION
  1849.  *  mmi_profiles_bt_disconnect_req
  1850.  * DESCRIPTION
  1851.  *  bt disconnect request
  1852.  * PARAMETERS
  1853.  *  connect_type        [IN]        
  1854.  * RETURNS
  1855.  *  void
  1856.  *****************************************************************************/
  1857. void mmi_profiles_bt_disconnect_req(U8 connect_type)
  1858. {
  1859.     /*----------------------------------------------------------------*/
  1860.     /* Local Variables                                                */
  1861.     /*----------------------------------------------------------------*/
  1862. #if defined(__MMI_BT_BCHS_SUPPORT__) && defined(__MMI_A2DP_SUPPORT__)
  1863.     S32 connect_id;
  1864. #endif    
  1865.     /*----------------------------------------------------------------*/
  1866.     /* Code Body                                                      */
  1867.     /*----------------------------------------------------------------*/
  1868.     PRINT_INFORMATION(("mmi_profiles_bt_disconnect_req: connect_type =%dn", connect_type));
  1869.     switch (connect_type)
  1870.     {
  1871.     #ifdef __MMI_HFP_SUPPORT__
  1872.         case MMI_PROFILES_BT_HFP_SCO:
  1873.             mdi_audio_bt_close_stream(BT_HFP);
  1874.             mmi_profiles_bt_connect_sco_app_callback = NULL;
  1875.             break;
  1876.     #endif /* __MMI_HFP_SUPPORT__ */ 
  1877.     #if defined(__MMI_BT_BCHS_SUPPORT__) && defined(__MMI_A2DP_SUPPORT__)
  1878.         case MMI_PROFILES_BT_A2DP_SIG:
  1879.             connect_id = mmi_bt_get_active_signal_connection_id(MMI_BT_ADVANCED_AUDIO_PROFILE_UUID);
  1880.             if (connect_id >= 0)
  1881.             {
  1882.                 if (a2dp_signal_disconnecting)
  1883.                     return;
  1884.                 a2dp_signal_disconnecting = TRUE;
  1885.                 mmi_bchs_a2dp_disconnect_req( (U32)connect_id );
  1886.             }
  1887.             break;
  1888.         case MMI_PROFILES_BT_A2DP_STR:
  1889.             mdi_audio_bt_close_stream(BT_A2DP);
  1890.             break;
  1891.     #endif /* __MMI_BT_BCHS_SUPPORT__ && __MMI_A2DP_SUPPORT__ */ 
  1892.         default:
  1893.             ASSERT(0);
  1894.     }
  1895. }
  1896. /*****************************************************************************
  1897.  * FUNCTION
  1898.  *  mmi_profiles_bt_call_start_callback
  1899.  * DESCRIPTION
  1900.  *  the call back function for call start
  1901.  * PARAMETERS
  1902.  *  void
  1903.  *  BOOL(?)     [IN]        Turn on
  1904.  * RETURNS
  1905.  *  void
  1906.  *****************************************************************************/
  1907. void mmi_profiles_bt_call_start_callback(void)
  1908. {
  1909.     /*----------------------------------------------------------------*/
  1910.     /* Local Variables                                                */
  1911.     /*----------------------------------------------------------------*/
  1912.     BOOL speech_on = mdi_audio_is_speech_mode();
  1913.     /*----------------------------------------------------------------*/
  1914.     /* Code Body                                                      */
  1915.     /*----------------------------------------------------------------*/
  1916.     PRINT_INFORMATION(("mmi_profiles_bt_call_start_callback: in_call=%d,speech_on=%dn", g_mmi_profiles_bt_in_call,
  1917.                        speech_on));
  1918.     if (!g_mmi_profiles_bt_in_call)
  1919.     {
  1920.         if (gactivatedprofile == MMI_PROFILE_BT)
  1921.         {
  1922. #if defined(__MMI_BT_BCHS_SUPPORT__) && defined(__MMI_A2DP_SUPPORT__)
  1923.             if (mmi_profiles_bt_is_connected(MMI_PROFILES_BT_A2DP_SIG))
  1924.             {
  1925.                 mdi_audio_bt_a2dp_turn_off();
  1926.             }
  1927. #endif /* __MMI_BT_BCHS_SUPPORT__ && __MMI_A2DP_SUPPORT__ */
  1928.         #ifdef __MMI_HFP_SUPPORT__
  1929.             if (mmi_profiles_bt_is_connected(MMI_PROFILES_BT_HFP_ACL))
  1930.             {
  1931.                 if (g_mmi_profiles_bt_always_use_in_call || mmi_bt_is_aud2hf())
  1932.                 {
  1933.                     mmi_profiles_bt_connect_req(MMI_PROFILES_BT_HFP_SCO);
  1934.                 #ifdef __MMI_BT_AUDIO_VIA_SCO__
  1935.                     /* Stop SCO timeout timer during call */
  1936.                     StopTimer(BT_SCO_CONNECT_TIMER);
  1937.                 #endif /* #ifdef __MMI_BT_AUDIO_VIA_SCO__ */
  1938.                 }
  1939.             }
  1940.         #endif /* __MMI_HFP_SUPPORT__ */  
  1941.         }
  1942.         g_mmi_profiles_bt_in_call = TRUE;
  1943.     }
  1944. }
  1945. /*****************************************************************************
  1946.  * FUNCTION
  1947.  *  mmi_profiles_bt_call_end_callback
  1948.  * DESCRIPTION
  1949.  *  the call back function for call end
  1950.  * PARAMETERS
  1951.  *  void
  1952.  * RETURNS
  1953.  *  void
  1954.  *****************************************************************************/
  1955. void mmi_profiles_bt_call_end_callback(void)
  1956. {
  1957.     /*----------------------------------------------------------------*/
  1958.     /* Local Variables                                                */
  1959.     /*----------------------------------------------------------------*/
  1960.     BOOL speech_on = mdi_audio_is_speech_mode();
  1961.     /*----------------------------------------------------------------*/
  1962.     /* Code Body                                                      */
  1963.     /*----------------------------------------------------------------*/
  1964.     PRINT_INFORMATION(("mmi_profiles_bt_call_end_callback: in_call=%d, speech_on=%dn", g_mmi_profiles_bt_in_call,
  1965.                        speech_on));
  1966.     if (g_mmi_profiles_bt_in_call)
  1967.     {
  1968.         if (gactivatedprofile == MMI_PROFILE_BT)
  1969.         {
  1970.         #ifdef __MMI_HFP_SUPPORT__
  1971.             if (mmi_profiles_bt_is_connected(MMI_PROFILES_BT_HFP_ACL))
  1972.             {
  1973.                 /* Disconnect later if support audio via BT SCO */
  1974.                 #ifdef __MMI_BT_AUDIO_VIA_SCO__
  1975.                     if(g_mmi_profiles_bt_sco_timeout)
  1976.                     {
  1977.                         StartTimer(BT_SCO_CONNECT_TIMER, BT_SCO_CONNECT_TIMEOUT_DURATION, mmi_profiles_bt_sco_timeout);
  1978.                     }
  1979.                 #else
  1980.                     mmi_profiles_bt_disconnect_req(MMI_PROFILES_BT_HFP_SCO);
  1981.                 #endif
  1982.             }
  1983.         #endif /* __MMI_HFP_SUPPORT__ */ 
  1984.         #if defined(__MMI_BT_BCHS_SUPPORT__) && defined(__MMI_A2DP_SUPPORT__)
  1985.             if (mmi_profiles_bt_is_connected(MMI_PROFILES_BT_A2DP_SIG))
  1986.             {
  1987.                 mdi_audio_bt_a2dp_turn_on();
  1988.             #if defined(__MMI_AUDIO_PLAYER__) && defined(__MMI_AUDIO_SPECTRUM_DISPLAY__) && defined(__MMI_A2DP_PROHIBIT_AUDIO_SPECTRUM_DISPLAY__)
  1989.                 mmi_audply_disable_spectrum_display();
  1990.             #endif 
  1991.             }
  1992.         #endif /* __MMI_BT_BCHS_SUPPORT__ && __MMI_A2DP_SUPPORT__ */ 
  1993.         }
  1994.         g_mmi_profiles_bt_in_call = FALSE;
  1995.     #ifdef __MMI_HFP_SUPPORT__
  1996.         g_mmi_profiles_bt_always_use_in_call = FALSE;
  1997.     #endif 
  1998.     }
  1999. }
  2000. /*****************************************************************************
  2001.  * FUNCTION
  2002.  *  mmi_profiles_bt_connect_callback
  2003.  * DESCRIPTION
  2004.  *  the call back function for bt connect indication
  2005.  * PARAMETERS
  2006.  *  connect_type        [IN]        
  2007.  *  callback_type       [IN]        
  2008.  *  result              [IN]        
  2009.  * RETURNS
  2010.  *  void
  2011.  *****************************************************************************/
  2012. void mmi_profiles_bt_connect_callback(U8 connect_type, U8 callback_type, U16 result)
  2013. {
  2014.     /*----------------------------------------------------------------*/
  2015.     /* Local Variables                                                */
  2016.     /*----------------------------------------------------------------*/
  2017.     /*----------------------------------------------------------------*/
  2018.     /* Code Body                                                      */
  2019.     /*----------------------------------------------------------------*/
  2020.     PRINT_INFORMATION(("mmi_profiles_bt_connect_callback: connect_type =%d, callback_type = %d, result = %dn",
  2021.                        connect_type, callback_type, result));
  2022.     switch (connect_type)
  2023.     {
  2024.     #ifdef __MMI_HFP_SUPPORT__
  2025.         case MMI_PROFILES_BT_HFP_ACL:
  2026.             if (callback_type == MMI_PROFILES_BT_IND || callback_type == MMI_PROFILES_BT_RSP)
  2027.             {
  2028.                 if (result == MMI_PROFILES_BT_OK)
  2029.                 {
  2030.                     if (gactivatedprofile != MMI_PROFILE_BT)
  2031.                     {
  2032.                     #if defined(__MMI_BT_BCHS_SUPPORT__) && defined(__MMI_A2DP_SUPPORT__)
  2033.                         if (mmi_profiles_bt_is_connected(MMI_PROFILES_BT_A2DP_SIG) && !g_mmi_profiles_bt_in_call)
  2034.                         {
  2035.                             mdi_audio_bt_a2dp_turn_on();
  2036.                         #if defined(__MMI_AUDIO_PLAYER__) && defined(__MMI_AUDIO_SPECTRUM_DISPLAY__) && defined(__MMI_A2DP_PROHIBIT_AUDIO_SPECTRUM_DISPLAY__)
  2037.                             mmi_audply_disable_spectrum_display();
  2038.                         #endif 
  2039.                         }
  2040.                     #endif /* __MMI_BT_BCHS_SUPPORT__ && __MMI_A2DP_SUPPORT__ */ 
  2041.                         mmi_profiles_bt_activate_profile();
  2042.                     }
  2043.                     
  2044.                     /* Always connect if Audio via SCO is on. But need to check FM radio if FM via SCO on  */
  2045.             #if !defined(__MMI_BT_AUDIO_VIA_SCO__)
  2046.                 #ifdef __MMI_BT_FM_VIA_SCO__
  2047.                     if ( (g_mmi_profiles_bt_in_call && (g_mmi_profiles_bt_always_use_in_call || mmi_bt_is_aud2hf()))
  2048.                         || mdi_audio_is_playing(MDI_AUDIO_PLAY_FM_RADIO) )
  2049.                 #else
  2050.                     if (g_mmi_profiles_bt_in_call && (g_mmi_profiles_bt_always_use_in_call || mmi_bt_is_aud2hf()))
  2051.                 #endif
  2052.             #endif
  2053.                     {
  2054.                         mmi_profiles_bt_connect_req(MMI_PROFILES_BT_HFP_SCO);
  2055.                     }
  2056.                 }
  2057.             }
  2058.             break;
  2059.         case MMI_PROFILES_BT_HFP_SCO:
  2060.             if (callback_type == MMI_PROFILES_BT_IND || callback_type == MMI_PROFILES_BT_RSP)
  2061.             {
  2062.                 if (result == MMI_PROFILES_BT_OK)
  2063.                 {
  2064.                     /* add a condition check for SCO, if it's not allowed, then disconnect it */
  2065.             #if !defined(__MMI_BT_AUDIO_VIA_SCO__)
  2066.                 #ifdef __MMI_BT_FM_VIA_SCO__
  2067.                     if( !g_mmi_profiles_bt_app_in_use && !g_mmi_profiles_bt_in_call && !mmi_bt_is_doing_far_end_loopback_test()
  2068.                         && !mdi_audio_is_playing(MDI_AUDIO_PLAY_FM_RADIO) )
  2069.                 #else
  2070.                     if( !g_mmi_profiles_bt_app_in_use && !g_mmi_profiles_bt_in_call && !mmi_bt_is_doing_far_end_loopback_test())
  2071.                 #endif            
  2072.                     {
  2073.                         mmi_profiles_bt_disconnect_req( MMI_PROFILES_BT_HFP_SCO );
  2074.                         return;
  2075.                     }
  2076.             #endif /* #if !defined(__MMI_BT_AUDIO_VIA_SCO__) */
  2077.                 
  2078.                     if (gactivatedprofile != MMI_PROFILE_BT)
  2079.                         mmi_profiles_bt_activate_profile();
  2080.                     if (g_mmi_profiles_bt_in_call)
  2081.                     {
  2082.                         g_mmi_profiles_bt_always_use_in_call = TRUE;
  2083.                     }
  2084.                 }
  2085.             }
  2086.             break;
  2087.     #endif /* __MMI_HFP_SUPPORT__ */ 
  2088.     #if defined(__MMI_BT_BCHS_SUPPORT__) && defined(__MMI_A2DP_SUPPORT__)
  2089.         case MMI_PROFILES_BT_A2DP_SIG:
  2090.             if (callback_type == MMI_PROFILES_BT_IND || callback_type == MMI_PROFILES_BT_RSP)
  2091.             {
  2092.                 if (result == MMI_PROFILES_BT_OK)
  2093.                 {
  2094.                     mmi_profiles_bt_connect_req(MMI_PROFILES_BT_A2DP_STR);
  2095.                 }
  2096.             }
  2097.             break;
  2098.         case MMI_PROFILES_BT_A2DP_STR:
  2099.             if (callback_type == MMI_PROFILES_BT_IND || callback_type == MMI_PROFILES_BT_RSP)
  2100.             {
  2101.                 if (result == MMI_PROFILES_BT_OK)
  2102.                 {
  2103.                     if (!g_mmi_profiles_bt_in_call)
  2104.                     {
  2105.                         mdi_audio_bt_a2dp_turn_on();
  2106.                     #if defined(__MMI_AUDIO_PLAYER__) && defined(__MMI_AUDIO_SPECTRUM_DISPLAY__) && defined(__MMI_A2DP_PROHIBIT_AUDIO_SPECTRUM_DISPLAY__)
  2107.                         mmi_audply_disable_spectrum_display();
  2108.                     #endif 
  2109.                     }
  2110.                     if (gactivatedprofile != MMI_PROFILE_BT)
  2111.                         mmi_profiles_bt_activate_profile();
  2112.                 }
  2113.                 else if (result != MMI_PROFILES_BT_BUSY)
  2114.                 {
  2115.                     if (mmi_profiles_bt_is_connected(MMI_PROFILES_BT_A2DP_SIG))
  2116.                     {
  2117.                         mmi_profiles_bt_disconnect_req(MMI_PROFILES_BT_A2DP_SIG);
  2118.                     }
  2119.                 }
  2120.             }
  2121.             break;
  2122.     #endif /* __MMI_BT_BCHS_SUPPORT__ && __MMI_A2DP_SUPPORT__ */ 
  2123.         default:
  2124.             ASSERT(0);
  2125.     }
  2126. }
  2127. /*****************************************************************************
  2128.  * FUNCTION
  2129.  *  mmi_profiles_bt_disconnect_callback
  2130.  * DESCRIPTION
  2131.  *  the call back function for bt disconnect indication
  2132.  * PARAMETERS
  2133.  *  connect_type        [IN]        
  2134.  *  callback_type       [IN]        
  2135.  *  result              [IN]        
  2136.  * RETURNS
  2137.  *  void
  2138.  *****************************************************************************/
  2139. void mmi_profiles_bt_disconnect_callback(U8 connect_type, U8 callback_type, U16 result)
  2140. {
  2141.     /*----------------------------------------------------------------*/
  2142.     /* Local Variables                                                */
  2143.     /*----------------------------------------------------------------*/
  2144.     /*----------------------------------------------------------------*/
  2145.     /* Code Body                                                      */
  2146.     /*----------------------------------------------------------------*/
  2147.     PRINT_INFORMATION(("mmi_profiles_bt_disconnect_callback: connect_type =%d, callback_type = %d, result = %dn",
  2148.                        connect_type, callback_type, result));
  2149.     switch (connect_type)
  2150.     {
  2151.     #ifdef __MMI_HFP_SUPPORT__
  2152.         case MMI_PROFILES_BT_HFP_ACL:
  2153.             if (callback_type == MMI_PROFILES_BT_IND || callback_type == MMI_PROFILES_BT_RSP)
  2154.             {
  2155.                 mmi_profiles_bt_disconnect_req(MMI_PROFILES_BT_HFP_SCO);
  2156.                 if (gactivatedprofile == MMI_PROFILE_BT)
  2157.                 {
  2158.                 #if defined(__MMI_BT_BCHS_SUPPORT__) && defined(__MMI_A2DP_SUPPORT__)
  2159.                     if (mmi_profiles_bt_is_connected(MMI_PROFILES_BT_A2DP_SIG))
  2160.                     {
  2161.                         return;
  2162.                     }
  2163.                 #endif /* __MMI_BT_BCHS_SUPPORT__ && __MMI_A2DP_SUPPORT__ */ 
  2164.                     if (mmi_gpio_is_earphone_plug_in())
  2165.                     {
  2166.                         mdi_audio_set_audio_mode(AUD_MODE_HEADSET);
  2167.                         mmi_profiles_headset_activate_profile();
  2168.                     }
  2169.                     else
  2170.                     {
  2171.                         mmi_profiles_bt_deactivate_profile();
  2172.                     }
  2173.                 }
  2174.             }
  2175.             break;
  2176.         case MMI_PROFILES_BT_HFP_SCO:
  2177.             if (callback_type == MMI_PROFILES_BT_IND || callback_type == MMI_PROFILES_BT_RSP)
  2178.             {
  2179.                 if (g_mmi_profiles_bt_reset_pending != 0)
  2180.                 {
  2181.                     g_mmi_profiles_bt_reset_pending &= 0x0E;
  2182.                     if (g_mmi_profiles_bt_reset_pending == 0)
  2183.                     {
  2184.                         mmi_bt_panic_ind_post_process();
  2185.                     }
  2186.                 }
  2187.                 else
  2188.                 {
  2189.     #if defined(__MMI_BT_BCHS_SUPPORT__) && defined(__MMI_A2DP_SUPPORT__)
  2190.                     if( gactivatedprofile == MMI_PROFILE_BT )
  2191.                     {
  2192.                         if( mmi_profiles_bt_is_connected( MMI_PROFILES_BT_A2DP_SIG ) )
  2193.                         {
  2194.                             if( !g_mmi_profiles_bt_app_in_use && !g_mmi_profiles_bt_in_call )
  2195.                             {
  2196.                                 mdi_audio_bt_a2dp_turn_on();
  2197.     #if defined( __MMI_AUDIO_PLAYER__ ) && defined( __MMI_AUDIO_SPECTRUM_DISPLAY__ ) && defined( __MMI_A2DP_PROHIBIT_AUDIO_SPECTRUM_DISPLAY__ )
  2198.                                 mmi_audply_disable_spectrum_display();
  2199.     #endif
  2200.                             }
  2201.                         }
  2202.                     }
  2203.     #endif // __MMI_BT_BCHS_SUPPORT__ && __MMI_A2DP_SUPPORT__
  2204.                 }
  2205.             }
  2206.             break;
  2207.     #endif /* __MMI_HFP_SUPPORT__ */ 
  2208.     #if defined(__MMI_BT_BCHS_SUPPORT__) && defined(__MMI_A2DP_SUPPORT__)
  2209.         case MMI_PROFILES_BT_A2DP_SIG:
  2210.             if (callback_type == MMI_PROFILES_BT_IND || callback_type == MMI_PROFILES_BT_RSP)
  2211.             {
  2212.                 a2dp_signal_disconnecting = FALSE;
  2213.                 mmi_profiles_bt_disconnect_req(MMI_PROFILES_BT_A2DP_STR);
  2214.                 if (gactivatedprofile == MMI_PROFILE_BT)
  2215.                 {
  2216.                 #ifdef __MMI_HFP_SUPPORT__
  2217.                     if (mmi_profiles_bt_is_connected(MMI_PROFILES_BT_HFP_ACL))
  2218.                     {
  2219.                         return;
  2220.                     }
  2221.                 #endif /* __MMI_HFP_SUPPORT__ */ 
  2222.                     if (mmi_gpio_is_earphone_plug_in())
  2223.                     {
  2224.                         mdi_audio_set_audio_mode(AUD_MODE_HEADSET);
  2225.                         mmi_profiles_headset_activate_profile();
  2226.                     }
  2227.                     else
  2228.                     {
  2229.                         mmi_profiles_bt_deactivate_profile();
  2230.                     }
  2231.                 }
  2232.             }
  2233.             break;
  2234.         case MMI_PROFILES_BT_A2DP_STR:
  2235.             if (callback_type == MMI_PROFILES_BT_IND || callback_type == MMI_PROFILES_BT_RSP)
  2236.             {
  2237. if( mmi_profiles_bt_is_connected( MMI_PROFILES_BT_A2DP_SIG ) )
  2238. {
  2239. mmi_profiles_bt_disconnect_req( MMI_PROFILES_BT_A2DP_SIG );
  2240. }
  2241.                 if (gactivatedprofile == MMI_PROFILE_BT)
  2242.                 {
  2243.                 #ifdef __MMI_HFP_SUPPORT__
  2244.                     if (!g_mmi_profiles_bt_in_call || !mmi_profiles_bt_is_connected(MMI_PROFILES_BT_HFP_SCO))
  2245.                 #endif 
  2246.                     {
  2247.                         if (mmi_gpio_is_earphone_plug_in())
  2248.                         {
  2249.                             mdi_audio_set_audio_mode(AUD_MODE_HEADSET);
  2250.                             mmi_profiles_headset_activate_profile();
  2251.                         }
  2252.                     }
  2253.                     mdi_audio_bt_a2dp_turn_off();
  2254.                 }
  2255.                 if (g_mmi_profiles_bt_reset_pending != 0)
  2256.                 {
  2257.                     g_mmi_profiles_bt_reset_pending &= 0x0D;
  2258.                     if (g_mmi_profiles_bt_reset_pending == 0)
  2259.                     {
  2260.                         mmi_bt_panic_ind_post_process();
  2261.                     }
  2262.                 }
  2263.                 else
  2264.                 {
  2265.                     mmi_bt_profile_callback_before_release_connection(
  2266.                         0,
  2267.                         0,
  2268.                         0,
  2269.                         MMI_BT_ADVANCED_AUDIO_PROFILE_UUID,
  2270.                         0xFFFFFFFF);
  2271.                 }
  2272.             }
  2273.             break;
  2274.     #endif /* __MMI_BT_BCHS_SUPPORT__ && __MMI_A2DP_SUPPORT__ */ 
  2275.         default:
  2276.             ASSERT(0);
  2277.     }
  2278. }
  2279. /*****************************************************************************
  2280.  * FUNCTION
  2281.  *  mmi_profiles_bt_activate_profile
  2282.  * DESCRIPTION
  2283.  *  activate BT profile
  2284.  * PARAMETERS
  2285.  *  void
  2286.  * RETURNS
  2287.  *  void
  2288.  *****************************************************************************/
  2289. void mmi_profiles_bt_activate_profile(void)
  2290. {
  2291.     /*----------------------------------------------------------------*/
  2292.     /* Local Variables                                                */
  2293.     /*----------------------------------------------------------------*/
  2294.     S16 error = 0;
  2295.     /*----------------------------------------------------------------*/
  2296.     /* Code Body                                                      */
  2297.     /*----------------------------------------------------------------*/
  2298.     PRINT_INFORMATION(("mmi_profiles_bt_activate_profile: gactivatedprofile =%d, glastactivatedprofile = %dn",
  2299.                        gactivatedprofile, glastactivatedprofile));
  2300. gprofileheadset = 0;
  2301. //KP Jerry modify on 2007-4-3 start
  2302. #ifdef __MMI_PROFILE_POWER_SAVING__
  2303.     if (gactivatedprofile != MMI_PROFILE_SILENT && gactivatedprofile != MMI_PROFILE_HEADSET &&
  2304.         gactivatedprofile != MMI_PROFILE_BT && gactivatedprofile != MMI_PROFILE_POWER_SAVING)
  2305. #else/*!__MMI_PROFILE_POWER_SAVING__*/
  2306.     if (gactivatedprofile != MMI_PROFILE_SILENT && gactivatedprofile != MMI_PROFILE_HEADSET &&
  2307.         gactivatedprofile != MMI_PROFILE_BT)
  2308. #endif/*__MMI_PROFILE_POWER_SAVING__*/
  2309. //KP Jerry modify on 2007-4-3 end        
  2310.     {
  2311.         glastactivatedprofile = gactivatedprofile;
  2312.     }
  2313.     gactivatedprofile = MMI_PROFILE_BT;
  2314.     memcpy(&gcurrentprofile, &gprofiles[gactivatedprofile], sizeof(PROFILE));
  2315.     WriteValue(NVRAM_PROFILES_LASTACTIVATED, &glastactivatedprofile, DS_BYTE, &error);
  2316.     showAlertStatusIcons();
  2317.     change_font();
  2318.     mdi_audio_set_volume_no_apply(MDI_VOLUME_MEDIA, GetRingVolumeLevel());
  2319.     SetKeyPadVolume(GetKeypadVolumeLevel());
  2320.     mdi_audio_set_mic_volume();
  2321. //KP Jerry add on 2007-03-31 start
  2322. #ifdef __MMI_PROFILE_POWER_SAVING__
  2323.     ProfileResetBackLightSetting();
  2324.     ProfilesResetKeyBacklight();
  2325.     SetGPIOLevelReq(GPIO_DEV_LED_MAINLCD, LED_LIGHT_LEVEL5);
  2326. #endif
  2327. //KP Jerry add on 2007-03-31 end
  2328. }
  2329. /*****************************************************************************
  2330.  * FUNCTION
  2331.  *  mmi_profiles_bt_deactivate_profile
  2332.  * DESCRIPTION
  2333.  *  deactivate BT profile
  2334.  * PARAMETERS
  2335.  *  void
  2336.  * RETURNS
  2337.  *  void
  2338.  *****************************************************************************/
  2339. void mmi_profiles_bt_deactivate_profile(void)
  2340. {
  2341.     /*----------------------------------------------------------------*/
  2342.     /* Local Variables                                                */
  2343.     /*----------------------------------------------------------------*/
  2344.     S16 error = 0;
  2345.     /*----------------------------------------------------------------*/
  2346.     /* Code Body                                                      */
  2347.     /*----------------------------------------------------------------*/
  2348.     PRINT_INFORMATION(("mmi_profiles_bt_deactivate_profile: gactivatedprofile =%d, glastactivatedprofile = %dn",
  2349.                        gactivatedprofile, glastactivatedprofile));
  2350.     ReadValue(NVRAM_PROFILES_ACTIVATED, &gactivatedprofile, DS_BYTE, &error);
  2351.     memcpy(&gcurrentprofile, &gprofiles[gactivatedprofile], sizeof(PROFILE));
  2352.     showAlertStatusIcons();
  2353.     change_font();
  2354.     mdi_audio_set_volume_no_apply(MDI_VOLUME_MEDIA, GetRingVolumeLevel());
  2355.     SetKeyPadVolume(GetKeypadVolumeLevel());
  2356.     mdi_audio_set_mic_volume();
  2357. //KP Jerry add on 2007-03-31 start
  2358. #ifdef __MMI_PROFILE_POWER_SAVING__
  2359.     ProfileResetBackLightSetting();
  2360.     ProfilesResetKeyBacklight();
  2361.     SetGPIOLevelReq(GPIO_DEV_LED_MAINLCD, LED_LIGHT_LEVEL5);
  2362. #endif
  2363. //KP Jerry add on 2007-03-31 end
  2364. }
  2365. #if defined(__MMI_BT_AUDIO_VIA_SCO__) || defined(__MMI_BT_FM_VIA_SCO__)
  2366. /*****************************************************************************
  2367.  * FUNCTION
  2368.  *  mmi_profiles_bt_disable_sco_timeout
  2369.  * DESCRIPTION
  2370.  *  
  2371.  * PARAMETERS
  2372.  *  void
  2373.  * RETURNS
  2374.  *  void
  2375.  *****************************************************************************/
  2376. void mmi_profiles_bt_disable_sco_timeout(void)
  2377. {
  2378.     /*----------------------------------------------------------------*/
  2379.     /* Local Variables                                                */
  2380.     /*----------------------------------------------------------------*/
  2381.     /*----------------------------------------------------------------*/
  2382.     /* Code Body                                                      */
  2383.     /*----------------------------------------------------------------*/
  2384.     PRINT_INFORMATION(("mmi_profiles_bt_disable_sco_timeoutn"));
  2385.     
  2386.     StopTimer(BT_SCO_CONNECT_TIMER);
  2387.     g_mmi_profiles_bt_sco_timeout = MMI_FALSE;
  2388. }
  2389. /*****************************************************************************
  2390.  * FUNCTION
  2391.  *  mmi_profiles_bt_enable_sco_timeout
  2392.  * DESCRIPTION
  2393.  *  
  2394.  * PARAMETERS
  2395.  *  void
  2396.  * RETURNS
  2397.  *  void
  2398.  *****************************************************************************/
  2399. void mmi_profiles_bt_enable_sco_timeout(void)
  2400. {
  2401.     /*----------------------------------------------------------------*/
  2402.     /* Local Variables                                                */
  2403.     /*----------------------------------------------------------------*/
  2404.     /*----------------------------------------------------------------*/
  2405.     /* Code Body                                                      */
  2406.     /*----------------------------------------------------------------*/
  2407.     PRINT_INFORMATION(("mmi_profiles_bt_enable_sco_timeoutn"));
  2408.     g_mmi_profiles_bt_sco_timeout = MMI_TRUE;
  2409.     if(mmi_profiles_bt_is_connected(MMI_PROFILES_BT_HFP_SCO))
  2410.     {
  2411.         StartTimer(BT_SCO_CONNECT_TIMER, BT_SCO_CONNECT_TIMEOUT_DURATION, mmi_profiles_bt_sco_timeout);
  2412.     }
  2413. }
  2414. /*****************************************************************************
  2415.  * FUNCTION
  2416.  *  mmi_profiles_bt_disable_sco_connection
  2417.  * DESCRIPTION
  2418.  *  
  2419.  * PARAMETERS
  2420.  *  void
  2421.  * RETURNS
  2422.  *  void
  2423.  *****************************************************************************/
  2424. void mmi_profiles_bt_disable_sco_connection(void)
  2425. {
  2426.     /*----------------------------------------------------------------*/
  2427.     /* Local Variables                                                */
  2428.     /*----------------------------------------------------------------*/
  2429.     /*----------------------------------------------------------------*/
  2430.     /* Code Body                                                      */
  2431.     /*----------------------------------------------------------------*/
  2432.     PRINT_INFORMATION(("mmi_profiles_bt_disable_sco_connectionn"));
  2433.     
  2434.     StopTimer(BT_SCO_CONNECT_TIMER);
  2435.     //g_mmi_profiles_bt_sco_timeout = MMI_FALSE;
  2436.     g_mmi_profiles_bt_allow_sco = MMI_FALSE;
  2437.     mmi_profiles_bt_disconnect_sco();
  2438. }
  2439. /*****************************************************************************
  2440.  * FUNCTION
  2441.  *  mmi_profiles_bt_enable_sco_connection
  2442.  * DESCRIPTION
  2443.  *  
  2444.  * PARAMETERS
  2445.  *  void
  2446.  * RETURNS
  2447.  *  void
  2448.  *****************************************************************************/
  2449. void mmi_profiles_bt_enable_sco_connection(void)
  2450. {
  2451.     /*----------------------------------------------------------------*/
  2452.     /* Local Variables                                                */
  2453.     /*----------------------------------------------------------------*/
  2454.     /*----------------------------------------------------------------*/
  2455.     /* Code Body                                                      */
  2456.     /*----------------------------------------------------------------*/
  2457.     PRINT_INFORMATION(("mmi_profiles_bt_enable_sco_timeoutn"));
  2458.     //g_mmi_profiles_bt_sco_timeout = MMI_TRUE;
  2459.     g_mmi_profiles_bt_allow_sco = MMI_TRUE;
  2460.     mmi_profiles_bt_connect_sco(NULL);
  2461. }
  2462. /*****************************************************************************
  2463.  * FUNCTION
  2464.  *  mmi_profiles_bt_sco_timeout
  2465.  * DESCRIPTION
  2466.  *  
  2467.  * PARAMETERS
  2468.  *  void
  2469.  * RETURNS
  2470.  *  void
  2471.  *****************************************************************************/
  2472. void mmi_profiles_bt_sco_timeout(void)
  2473. {
  2474.     /*----------------------------------------------------------------*/
  2475.     /* Local Variables                                                */
  2476.     /*----------------------------------------------------------------*/
  2477.     /*----------------------------------------------------------------*/
  2478.     /* Code Body                                                      */
  2479.     /*----------------------------------------------------------------*/
  2480.     PRINT_INFORMATION(("mmi_profiles_bt_sco_timeout: SCO connected =%d, bt_in_call=%dn", mmi_profiles_bt_is_connected(MMI_PROFILES_BT_HFP_SCO), g_mmi_profiles_bt_in_call));
  2481.     
  2482.     if(mmi_profiles_bt_is_connected(MMI_PROFILES_BT_HFP_SCO))
  2483.     {
  2484.         /* If audio/video is not playing or not in call */
  2485.         if(!g_mmi_profiles_bt_in_call
  2486.             && mdi_audio_is_idle()
  2487.             && !mdi_video_is_playing()
  2488.             && !mdi_video_is_recording()
  2489.         #if defined(BGSND_ENABLE)
  2490.             && !mdi_audio_snd_is_playing()
  2491.         #endif            
  2492.             )
  2493.         {
  2494.             mmi_profiles_bt_disconnect_sco();
  2495.         }
  2496.         /* still using audio resource, disconnect later */
  2497.         else if(g_mmi_profiles_bt_sco_timeout && !g_mmi_profiles_bt_in_call)
  2498.         {
  2499.             StartTimer(BT_SCO_CONNECT_TIMER, BT_SCO_CONNECT_TIMEOUT_DURATION, mmi_profiles_bt_sco_timeout);
  2500.         }
  2501.     }
  2502. }
  2503.                 
  2504. /*****************************************************************************
  2505.  * FUNCTION
  2506.  *  mmi_profiles_bt_inquery_start_callback
  2507.  * DESCRIPTION
  2508.  *  Callback function for BT inquery
  2509.  * PARAMETERS
  2510.  *  void
  2511.  * RETURNS
  2512.  *  void
  2513.  *****************************************************************************/
  2514. void mmi_profiles_bt_inquery_start_callback(void (*callback) (void))
  2515. {
  2516.     /*----------------------------------------------------------------*/
  2517.     /* Local Variables                                                */
  2518.     /*----------------------------------------------------------------*/
  2519.     U8 sco_status;
  2520.     
  2521.     /*----------------------------------------------------------------*/
  2522.     /* Code Body                                                      */
  2523.     /*----------------------------------------------------------------*/
  2524.     sco_status = mdi_audio_bt_get_stream_status(BT_HFP);
  2525.     g_mmi_profiles_bt_inquery_callback = NULL;
  2526.     
  2527.     PRINT_INFORMATION(("mmi_profiles_bt_inquery_start_callback: SCO status = [%d]", sco_status));
  2528.     switch(sco_status)
  2529.     {
  2530.         case MDI_AUDIO_BT_STATE_IDLE:
  2531.             callback();        
  2532.             break;
  2533.             
  2534.         case MDI_AUDIO_BT_STATE_WAIT_CLOSE:
  2535.             g_mmi_profiles_bt_inquery_callback = callback;
  2536.             break;
  2537.             
  2538.         case MDI_AUDIO_BT_STATE_OPEN:
  2539.         case MDI_AUDIO_BT_STATE_WAIT_OPEN:
  2540.             StopTimer(BT_SCO_CONNECT_TIMER);
  2541.             g_mmi_profiles_bt_inquery_callback = callback;    
  2542.             g_mmi_profiles_bt_inquerying = MMI_TRUE;
  2543.             mdi_audio_suspend_background_play();
  2544.             mmi_profiles_bt_disconnect_sco();
  2545.             break;
  2546.         default:
  2547.             ASSERT(0);
  2548.             break;
  2549.     }
  2550. }
  2551. /*****************************************************************************
  2552.  * FUNCTION
  2553.  *  mmi_profiles_bt_inquery_stop_callback
  2554.  * DESCRIPTION
  2555.  *  Callback function for BT inquery
  2556.  * PARAMETERS
  2557.  *  void
  2558.  * RETURNS
  2559.  *  void
  2560.  *****************************************************************************/
  2561. void mmi_profiles_bt_inquery_stop_callback(void)
  2562. {
  2563.     /*----------------------------------------------------------------*/
  2564.     /* Local Variables                                                */
  2565.     /*----------------------------------------------------------------*/
  2566.     /*----------------------------------------------------------------*/
  2567.     /* Code Body                                                      */
  2568.     /*----------------------------------------------------------------*/
  2569.     PRINT_INFORMATION(("mmi_profiles_bt_inquery_stop_callback"));
  2570.     g_mmi_profiles_bt_inquery_callback = NULL;
  2571.     /* Connect SCO after background play resume */
  2572.     g_mmi_profiles_bt_inquerying = MMI_FALSE;
  2573.     
  2574.     mdi_audio_resume_background_play();
  2575. }
  2576. #endif /* #if defined(__MMI_BT_AUDIO_VIA_SCO__) || defined(__MMI_BT_FM_VIA_SCO__) */
  2577. #endif /* __MMI_BT_PROFILE__ */