fm/fmapp2/src/com/caf/fmradio/FMRadioService.java
private boolean fmOn() {
      boolean bStatus=false;
      mWakeLock.acquire(10*1000);
      if ( TelephonyManager.CALL_STATE_IDLE != getCallState() ) {
         return bStatus;
      }

      if(mReceiver == null)
      {
         try {
            mReceiver = new FmReceiver(FMRADIO_DEVICE_FD_STRING, fmCallbacks);
         }
         catch (InstantiationException e)
         {
            throw new RuntimeException("FmReceiver service not available!");
         }
      }

      if (mReceiver != null)
      {
         if (isFmOn())
         {
            /* FM Is already on,*/
            bStatus = true;
            Log.d(LOGTAG, "mReceiver.already enabled");
         }
         else
         {
            // This sets up the FM radio device
            FmConfig config = FmSharedPreferences.getFMConfiguration();
            Log.d(LOGTAG, "fmOn: RadioBand   :"+ config.getRadioBand());
            Log.d(LOGTAG, "fmOn: Emphasis    :"+ config.getEmphasis());
            Log.d(LOGTAG, "fmOn: ChSpacing   :"+ config.getChSpacing());
            Log.d(LOGTAG, "fmOn: RdsStd      :"+ config.getRdsStd());
            Log.d(LOGTAG, "fmOn: LowerLimit  :"+ config.getLowerLimit());
            Log.d(LOGTAG, "fmOn: UpperLimit  :"+ config.getUpperLimit());
            bStatus = mReceiver.enable(FmSharedPreferences.getFMConfiguration());
            if (isSpeakerEnabled()) {
                setAudioPath(false);
            } else {
                setAudioPath(true);
            }
            Log.d(LOGTAG, "mReceiver.enable done, Status :" +  bStatus);
         }

         if (bStatus == true)
         {
            /* Put the hardware into normal mode */
            bStatus = setLowPowerMode(false);
            Log.d(LOGTAG, "setLowPowerMode done, Status :" +  bStatus);


            AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
            if( (audioManager != null) &&(false == mPlaybackInProgress) )
            {
               Log.d(LOGTAG, "mAudioManager.setFmRadioOn = true \n" );
               //audioManager.setParameters("FMRadioOn="+mAudioDevice);
               int state =  getCallState();
               if ( TelephonyManager.CALL_STATE_IDLE != getCallState() )
               {
                 fmActionOnCallState(state);
               } else {
                   startFM(); // enable FM Audio only when Call is IDLE
               }
               Log.d(LOGTAG, "mAudioManager.setFmRadioOn done \n" );
            }
            if (mReceiver != null) {
                bStatus = mReceiver.registerRdsGroupProcessing(FmReceiver.FM_RX_RDS_GRP_RT_EBL|
                                                           FmReceiver.FM_RX_RDS_GRP_PS_EBL|
                                                           FmReceiver.FM_RX_RDS_GRP_AF_EBL|
                                                           FmReceiver.FM_RX_RDS_GRP_PS_SIMPLE_EBL);
                Log.d(LOGTAG, "registerRdsGroupProcessing done, Status :" +  bStatus);
            }
            bStatus = enableAutoAF(FmSharedPreferences.getAutoAFSwitch());
            Log.d(LOGTAG, "enableAutoAF done, Status :" +  bStatus);

            /* There is no internal Antenna*/
            bStatus = mReceiver.setInternalAntenna(false);
            Log.d(LOGTAG, "setInternalAntenna done, Status :" +  bStatus);

            /* Read back to verify the internal Antenna mode*/
            readInternalAntennaAvailable();

            startNotification();
            bStatus = true;
         }
         else
         {
            mReceiver = null; // as enable failed no need to disable
                              // failure of enable can be because handle
                              // already open which gets effected if
                              // we disable
            stop();
         }
      }
      return(bStatus);
   }
/*
   * Turn ON FM: Powers up FM hardware, and initializes the FM module
   *                                                                                 .
   * @return true if fm Enable api was invoked successfully, false if the api failed.
   */
Turn ON FM: Powers up FM hardware, and initializes the FM module
.
@return true if fm Enable api was invoked successfully, false if the api failed.
Turn ON FM : Powers up FM hardware and initializes the FM module . @return true if fm Enable api was invoked successfully false if the api failed .
private boolean fmOn() {
      boolean bStatus=false;
      mWakeLock.acquire(10*1000);
      if ( TelephonyManager.CALL_STATE_IDLE != getCallState() ) {
         return bStatus;
      }
      if(mReceiver == null)
      {
         try {
            mReceiver = new FmReceiver(FMRADIO_DEVICE_FD_STRING, fmCallbacks);
         }
         catch (InstantiationException e)
         {
            throw new RuntimeException("FmReceiver service not available!");
         }
      }
      if (mReceiver != null)
      {
         if (isFmOn())
         {
            /* FM Is already on,*/
            bStatus = true;
            Log.d(LOGTAG, "mReceiver.already enabled");
         }
         else
         {
            FmConfig config = FmSharedPreferences.getFMConfiguration();
            Log.d(LOGTAG, "fmOn: RadioBand   :"+ config.getRadioBand());
            Log.d(LOGTAG, "fmOn: Emphasis    :"+ config.getEmphasis());
            Log.d(LOGTAG, "fmOn: ChSpacing   :"+ config.getChSpacing());
            Log.d(LOGTAG, "fmOn: RdsStd      :"+ config.getRdsStd());
            Log.d(LOGTAG, "fmOn: LowerLimit  :"+ config.getLowerLimit());
            Log.d(LOGTAG, "fmOn: UpperLimit  :"+ config.getUpperLimit());
            bStatus = mReceiver.enable(FmSharedPreferences.getFMConfiguration());
            if (isSpeakerEnabled()) {
                setAudioPath(false);
            } else {
                setAudioPath(true);
            }
            Log.d(LOGTAG, "mReceiver.enable done, Status :" +  bStatus);
         }
         if (bStatus == true)
         {
            /* Put the hardware into normal mode */
            bStatus = setLowPowerMode(false);
            Log.d(LOGTAG, "setLowPowerMode done, Status :" +  bStatus);
            AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
            if( (audioManager != null) &&(false == mPlaybackInProgress) )
            {
               Log.d(LOGTAG, "mAudioManager.setFmRadioOn = true \n" );
               int state =  getCallState();
               if ( TelephonyManager.CALL_STATE_IDLE != getCallState() )
               {
                 fmActionOnCallState(state);
               } else {
                   startFM(); 
               }
               Log.d(LOGTAG, "mAudioManager.setFmRadioOn done \n" );
            }
            if (mReceiver != null) {
                bStatus = mReceiver.registerRdsGroupProcessing(FmReceiver.FM_RX_RDS_GRP_RT_EBL|
                                                           FmReceiver.FM_RX_RDS_GRP_PS_EBL|
                                                           FmReceiver.FM_RX_RDS_GRP_AF_EBL|
                                                           FmReceiver.FM_RX_RDS_GRP_PS_SIMPLE_EBL);
                Log.d(LOGTAG, "registerRdsGroupProcessing done, Status :" +  bStatus);
            }
            bStatus = enableAutoAF(FmSharedPreferences.getAutoAFSwitch());
            Log.d(LOGTAG, "enableAutoAF done, Status :" +  bStatus);
            /* There is no internal Antenna*/
            bStatus = mReceiver.setInternalAntenna(false);
            Log.d(LOGTAG, "setInternalAntenna done, Status :" +  bStatus);
            /* Read back to verify the internal Antenna mode*/
            readInternalAntennaAvailable();
            startNotification();
            bStatus = true;
         }
         else
         {
            mReceiver = null; 
            stop();
         }
      }
      return(bStatus);
   }
private boolean fmOn ( ) { boolean bStatus = false ; mWakeLock . acquire ( 10 * 1000 ) ; if ( TelephonyManager . CALL_STATE_IDLE != getCallState ( ) ) { return bStatus ; } if ( mReceiver == null ) { try { mReceiver = new FmReceiver ( FMRADIO_DEVICE_FD_STRING , fmCallbacks ) ; } catch ( InstantiationException e ) { throw new RuntimeException ( "FmReceiver service not available!" ) ; } } if ( mReceiver != null ) { if ( isFmOn ( ) ) { /* FM Is already on,*/ bStatus = true ; Log . d ( LOGTAG , "mReceiver.already enabled" ) ; } else { FmConfig config = FmSharedPreferences . getFMConfiguration ( ) ; Log . d ( LOGTAG , "fmOn: RadioBand   :" + config . getRadioBand ( ) ) ; Log . d ( LOGTAG , "fmOn: Emphasis    :" + config . getEmphasis ( ) ) ; Log . d ( LOGTAG , "fmOn: ChSpacing   :" + config . getChSpacing ( ) ) ; Log . d ( LOGTAG , "fmOn: RdsStd      :" + config . getRdsStd ( ) ) ; Log . d ( LOGTAG , "fmOn: LowerLimit  :" + config . getLowerLimit ( ) ) ; Log . d ( LOGTAG , "fmOn: UpperLimit  :" + config . getUpperLimit ( ) ) ; bStatus = mReceiver . enable ( FmSharedPreferences . getFMConfiguration ( ) ) ; if ( isSpeakerEnabled ( ) ) { setAudioPath ( false ) ; } else { setAudioPath ( true ) ; } Log . d ( LOGTAG , "mReceiver.enable done, Status :" + bStatus ) ; } if ( bStatus == true ) { /* Put the hardware into normal mode */ bStatus = setLowPowerMode ( false ) ; Log . d ( LOGTAG , "setLowPowerMode done, Status :" + bStatus ) ; AudioManager audioManager = ( AudioManager ) getSystemService ( Context . AUDIO_SERVICE ) ; if ( ( audioManager != null ) && ( false == mPlaybackInProgress ) ) { Log . d ( LOGTAG , "mAudioManager.setFmRadioOn = true \n" ) ; int state = getCallState ( ) ; if ( TelephonyManager . CALL_STATE_IDLE != getCallState ( ) ) { fmActionOnCallState ( state ) ; } else { startFM ( ) ; } Log . d ( LOGTAG , "mAudioManager.setFmRadioOn done \n" ) ; } if ( mReceiver != null ) { bStatus = mReceiver . registerRdsGroupProcessing ( FmReceiver . FM_RX_RDS_GRP_RT_EBL | FmReceiver . FM_RX_RDS_GRP_PS_EBL | FmReceiver . FM_RX_RDS_GRP_AF_EBL | FmReceiver . FM_RX_RDS_GRP_PS_SIMPLE_EBL ) ; Log . d ( LOGTAG , "registerRdsGroupProcessing done, Status :" + bStatus ) ; } bStatus = enableAutoAF ( FmSharedPreferences . getAutoAFSwitch ( ) ) ; Log . d ( LOGTAG , "enableAutoAF done, Status :" + bStatus ) ; /* There is no internal Antenna*/ bStatus = mReceiver . setInternalAntenna ( false ) ; Log . d ( LOGTAG , "setInternalAntenna done, Status :" + bStatus ) ; /* Read back to verify the internal Antenna mode*/ readInternalAntennaAvailable ( ) ; startNotification ( ) ; bStatus = true ; } else { mReceiver = null ; stop ( ) ; } } return ( bStatus ) ; }
Turn ON FM: Powers up FM hardware, and initializes the FM module
                                                                                 .
Turn ON FM : Powers up FM hardware and initializes the FM module .
// This sets up the FM radio device //audioManager.setParameters("FMRadioOn="+mAudioDevice); // enable FM Audio only when Call is IDLE // as enable failed no need to disable // failure of enable can be because handle // already open which gets effected if // we disable