diff --git a/fmapp2/src/com/caf/fmradio/FMRadioService.java b/fmapp2/src/com/caf/fmradio/FMRadioService.java
index 86e4094..f3b657b 100644
--- a/fmapp2/src/com/caf/fmradio/FMRadioService.java
+++ b/fmapp2/src/com/caf/fmradio/FMRadioService.java
@@ -50,6 +50,7 @@
 import android.media.AudioManager.OnAudioFocusChangeListener;
 import android.media.AudioSystem;
 import android.media.MediaRecorder;
+import android.media.AudioDeviceAttributes;
 import android.media.AudioDevicePort;
 import android.media.AudioDevicePortConfig;
 import android.media.AudioFormat;
@@ -217,10 +218,13 @@
    private boolean mIsSSRInProgressFromActivity = false;
    private int mKeyActionDownCount = 0;
 
+   private Thread mRecordSinkThread = null;
    private AudioTrack mAudioTrack = null;
+   private boolean mIsRecordSink = false;
    private static final int AUDIO_FRAMES_COUNT_TO_IGNORE = 3;
    private Object mEventWaitLock = new Object();
    private boolean mIsFMDeviceLoopbackActive = false;
+   private Object mRecordSinkLock = new Object();
    private File mStoragePath = null;
    private static final int FM_OFF_FROM_APPLICATION = 1;
    private static final int FM_OFF_FROM_ANTENNA = 2;
@@ -239,6 +243,20 @@
    private AudioFocusRequest mGainFocusReq;
    private PhoneStateCallback mPhoneStateCallback;
 
+   private AudioRoutingListener mRoutingListener =  null;
+   private int mCurrentDevice = AudioDeviceInfo.TYPE_UNKNOWN; // current output device
+   private boolean mUseAudioSession = false;
+
+   private static final int AUDIO_SAMPLE_RATE = 44100;
+   private static final int AUDIO_CHANNEL_CONFIG =
+           AudioFormat.CHANNEL_CONFIGURATION_STEREO;
+   private static final int AUDIO_ENCODING_FORMAT =
+           AudioFormat.ENCODING_PCM_16BIT;
+   private static final int FM_RECORD_BUF_SIZE =
+           AudioRecord.getMinBufferSize(AUDIO_SAMPLE_RATE,
+                   AUDIO_CHANNEL_CONFIG, AUDIO_ENCODING_FORMAT);
+   private AudioRecord mAudioRecord = null;
+
    public FMRadioService() {
    }
 
@@ -286,6 +304,10 @@
       mA2dpDeviceSupportInHal = valueStr.contains("=true");
       Log.d(LOGTAG, " is A2DP device Supported In HAL"+mA2dpDeviceSupportInHal);
 
+      mUseAudioSession = SystemProperties.getBoolean("ro.vendor.fm.use_audio_session", false);
+      if (mUseAudioSession) {
+          mRoutingListener = new AudioRoutingListener();
+      }
       mGainFocusReq = requestAudioFocus();
       AudioManager mAudioManager =
           (AudioManager) getSystemService(Context.AUDIO_SERVICE);
@@ -377,6 +399,162 @@
       super.onDestroy();
    }
 
+    private synchronized void createRecordSessions() {
+        if (mAudioRecord != null) {
+            mAudioRecord.stop();
+        }
+        if (mAudioTrack != null) {
+            mAudioTrack.stop();
+        }
+
+        mAudioRecord = new AudioRecord(MediaRecorder.AudioSource.RADIO_TUNER,
+                AUDIO_SAMPLE_RATE, AUDIO_CHANNEL_CONFIG,
+                AUDIO_ENCODING_FORMAT, FM_RECORD_BUF_SIZE);
+
+        mAudioTrack = new AudioTrack.Builder()
+                .setAudioFormat(new AudioFormat.Builder()
+                        .setEncoding(AUDIO_ENCODING_FORMAT)
+                        .setSampleRate(AUDIO_SAMPLE_RATE)
+                        .setChannelIndexMask(AUDIO_CHANNEL_CONFIG)
+                        .build())
+                .setBufferSizeInBytes(FM_RECORD_BUF_SIZE)
+                .build();
+        Log.d(LOGTAG, " adding RoutingChangedListener() ");
+        mAudioTrack.addOnRoutingChangedListener(mRoutingListener, null);
+
+        if (mMuted) {
+            mAudioTrack.setVolume(0.0f);
+        }
+    }
+
+    private synchronized void startRecordSink() {
+        Log.d(LOGTAG, "startRecordSink " + AudioSystem.getForceUse(AudioSystem.FOR_MEDIA));
+
+        mIsRecordSink = true;
+        createRecordSinkThread();
+    }
+
+    private synchronized void createRecordSinkThread() {
+        if (mRecordSinkThread == null) {
+            mRecordSinkThread = new RecordSinkThread();
+            mRecordSinkThread.start();
+            Log.d(LOGTAG, "mRecordSinkThread started");
+            try {
+                synchronized (mRecordSinkLock) {
+                    Log.d(LOGTAG, "waiting for play to complete");
+                    mRecordSinkLock.wait();
+                }
+            } catch (InterruptedException e) {
+                e.printStackTrace();
+            }
+            enableSlimbus(ENABLE_SLIMBUS_DATA_PORT);
+        }
+    }
+
+    private synchronized void exitRecordSinkThread() {
+        if (isRecordSinking()) {
+            Log.d(LOGTAG, "stopRecordSink");
+            mAudioTrack.setPreferredDevice(null);
+            mIsRecordSink = false;
+        } else {
+            Log.d(LOGTAG, "exitRecordSinkThread called mRecordSinkThread not running");
+            return;
+        }
+        try {
+            Log.d(LOGTAG, "stopRecordSink waiting to join mRecordSinkThread");
+            mRecordSinkThread.join();
+        } catch (InterruptedException e) {
+            Log.d(LOGTAG, "Exceprion while mRecordSinkThread join");
+        }
+        mRecordSinkThread = null;
+        mAudioTrack = null;
+        mAudioRecord = null;
+        Log.d(LOGTAG, "exitRecordSinkThread completed");
+    }
+
+    private boolean isRecordSinking() {
+        return mIsRecordSink;
+    }
+
+    class RecordSinkThread extends Thread {
+        private int mCurrentFrame = 0;
+
+        private boolean isAudioFrameNeedIgnore() {
+            return mCurrentFrame < AUDIO_FRAMES_COUNT_TO_IGNORE;
+        }
+
+        @Override
+        public void run() {
+            try {
+                Log.d(LOGTAG, "RecordSinkThread: run started ");
+                byte[] buffer = new byte[FM_RECORD_BUF_SIZE];
+                while (isRecordSinking()) {
+                    // Speaker mode or BT a2dp mode will come here and keep reading and writing.
+                    // If we want FM sound output from speaker or BT a2dp, we must record data
+                    // to AudioRecrd and write data to AudioTrack.
+                    if (mAudioRecord.getRecordingState() == AudioRecord.RECORDSTATE_STOPPED) {
+                        mAudioRecord.startRecording();
+                        Log.d(LOGTAG, "RecordSinkThread: mAudioRecord.startRecording started");
+                    }
+
+                    if (mAudioTrack.getPlayState() == AudioTrack.PLAYSTATE_STOPPED) {
+                        Log.d(LOGTAG, "RecordSinkThread: mAudioTrack.play executed");
+                        mAudioTrack.play();
+                        Log.d(LOGTAG, "RecordSinkThread: mAudioTrack.play completed");
+                        synchronized (mRecordSinkLock) {
+                            mRecordSinkLock.notify();
+                        }
+                    }
+                    int size = mAudioRecord.read(buffer, 0, FM_RECORD_BUF_SIZE);
+                    // check whether need to ignore first 3 frames audio data from AudioRecord
+                    // to avoid pop noise.
+                    if (isAudioFrameNeedIgnore()) {
+                        mCurrentFrame += 1;
+                        continue;
+                    }
+                    if (size <= 0) {
+                        Log.e(LOGTAG, "RecordSinkThread read data from AudioRecord "
+                                + "error size: " + size);
+                        continue;
+                    }
+                    byte[] tmpBuf = new byte[size];
+                    System.arraycopy(buffer, 0, tmpBuf, 0, size);
+                    // Check again to avoid noises, because RecordSink may be changed
+                    // while AudioRecord is reading.
+                    if (isRecordSinking()) {
+                        mAudioTrack.write(tmpBuf, 0, tmpBuf.length);
+                    } else {
+                        mCurrentFrame = 0;
+                        Log.d(LOGTAG,
+                                "RecordSinkThread: stopRecordSink called stopping mAudioTrack and"
+                                        + " mAudioRecord ");
+                        break;
+                    }
+                }
+            } catch (Exception e) {
+                Log.d(LOGTAG, "RecordSinkThread.run, thread is interrupted, need exit thread");
+            } finally {
+                Log.d(LOGTAG,
+                        "RecordSinkThread: stopRecordSink called stopping mAudioTrack and "
+                                + "mAudioRecord ");
+                if (mAudioRecord.getRecordingState() == AudioRecord.RECORDSTATE_RECORDING) {
+                    Log.d(LOGTAG, "RecordSinkThread: mAudioRecord.stop()");
+                    mAudioRecord.stop();
+                    Log.d(LOGTAG, "RecordSinkThread: mAudioRecord.stop() completed");
+                    mAudioRecord.release();
+                    Log.d(LOGTAG, "RecordSinkThread: mAudioRecord.release() completed");
+                }
+                if (mAudioTrack.getPlayState() == AudioTrack.PLAYSTATE_PLAYING) {
+                    Log.d(LOGTAG, "RecordSinkThread: mAudioTrack.stop();");
+                    mAudioTrack.stop();
+                    Log.d(LOGTAG, "RecordSinkThread:mAudioTrack.stop() completed");
+                    mAudioTrack.release();
+                    Log.d(LOGTAG, "RecordSinkThread: mAudioTrack.release() completed");
+                }
+            }
+        }
+    }
+
     private void setFMVolume(int mCurrentVolumeIndex) {
        AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
        float decibels = audioManager.getStreamVolumeDb(AudioManager.STREAM_MUSIC,
@@ -450,6 +628,79 @@
         return true;
     }
 
+    private boolean configureFMDeviceLoopback_O(boolean enable) {
+        boolean success = true;
+        int status = AudioSystem.SUCCESS;
+
+        Log.d(LOGTAG, "configureFMDeviceLoopback enable:" + enable +
+                " DeviceLoopbackActive:" + mIsFMDeviceLoopbackActive);
+        if (enable && !mIsFMDeviceLoopbackActive) {
+            status = AudioSystem.getDeviceConnectionState(AudioSystem.DEVICE_OUT_FM, "");
+            Log.d(LOGTAG, " FM hardwareLoopback Status = " + status);
+            if (status == AudioSystem.DEVICE_STATE_AVAILABLE) {
+                // This case usually happens, when FM is force killed through settings app
+                // and we don't get chance to disable Hardware LoopBack.
+                Log.d(LOGTAG, " FM HardwareLoopBack Active, disable it first");
+                AudioSystem.setDeviceConnectionState(
+                        new AudioDeviceAttributes(AudioSystem.DEVICE_OUT_FM, ""),
+                        AudioSystem.DEVICE_STATE_UNAVAILABLE,
+                        AudioSystem.AUDIO_FORMAT_DEFAULT);
+                mCurrentDevice = AudioDeviceInfo.TYPE_WIRED_HEADSET;
+            }
+            status = AudioSystem.setDeviceConnectionState(
+                    new AudioDeviceAttributes(AudioSystem.DEVICE_OUT_FM, ""),
+                    AudioSystem.DEVICE_STATE_AVAILABLE,
+                    AudioSystem.AUDIO_FORMAT_DEFAULT);
+            if (status != AudioSystem.SUCCESS) {
+                success = false;
+                Log.e(LOGTAG, "configureFMDeviceLoopback failed! status:" + status);
+                AudioSystem.setDeviceConnectionState(
+                        new AudioDeviceAttributes(AudioSystem.DEVICE_OUT_FM, ""),
+                        AudioSystem.DEVICE_STATE_UNAVAILABLE,
+                        AudioSystem.AUDIO_FORMAT_DEFAULT);
+                mCurrentDevice = AudioDeviceInfo.TYPE_UNKNOWN;
+            } else {
+                mIsFMDeviceLoopbackActive = true;
+            }
+        } else if (!enable && mIsFMDeviceLoopbackActive) {
+            AudioSystem.setDeviceConnectionState(
+                    new AudioDeviceAttributes(AudioSystem.DEVICE_OUT_FM, ""),
+                    AudioSystem.DEVICE_STATE_UNAVAILABLE,
+                    AudioSystem.AUDIO_FORMAT_DEFAULT);
+            mIsFMDeviceLoopbackActive = false;
+            mCurrentDevice = AudioDeviceInfo.TYPE_UNKNOWN;
+        }
+
+        return success;
+    }
+
+    private synchronized void configureAudioDataPath(boolean enable) {
+        Log.d(LOGTAG, "configureAudioDataPath:" + enable +
+                " mA2dpConnected:" + mA2dpConnected +
+                " isRecordSinking" + isRecordSinking() +
+                " mSpeakerPhoneOn:" + mSpeakerPhoneOn +
+                " mIsFMDeviceLoopbackActive:" + mIsFMDeviceLoopbackActive);
+
+        if (enable) {
+            Log.d(LOGTAG, "Start Hardware loop back for audio");
+            if (mStoppedOnFocusLoss) {
+                Log.d(LOGTAG, "FM does not have audio focus, not enabling " +
+                        "audio path");
+                return;
+            }
+            if (!mIsFMDeviceLoopbackActive && !mA2dpConnected && !mSpeakerPhoneOn) {
+                // not on BT and device loop is also not active
+                enableSlimbus(ENABLE_SLIMBUS_DATA_PORT);
+                exitRecordSinkThread();
+                configureFMDeviceLoopback_O(true);
+            }
+        } else {
+            //inform audio to disbale fm audio
+            configureFMDeviceLoopback_O(false);
+            exitRecordSinkThread();
+        }
+    }
+
     private void setCurrentFMVolume() {
         if(isFmOn()) {
             AudioManager maudioManager =
@@ -1094,6 +1345,9 @@
        if (mStoppedOnFactoryReset) {
            mStoppedOnFactoryReset = false;
            mSpeakerPhoneOn = false;
+           if (mUseAudioSession) {
+               configureAudioDataPath(true);
+           }
        // In FM stop, the audio route is set to default audio device
        }
        String temp = mSpeakerPhoneOn ? "Speaker" : "WiredHeadset";
@@ -1103,7 +1357,11 @@
        } else {
            mAudioDevice = AudioDeviceInfo.TYPE_WIRED_HEADPHONES;
        }
-       configureFMDeviceLoopback(true);
+       if (mUseAudioSession) {
+           startApplicationLoopBack(mAudioDevice);
+       } else {
+           configureFMDeviceLoopback(true);
+       }
        try {
            if ((mServiceInUse) && (mCallbacks != null))
                mCallbacks.onFmAudioPathStarted();
@@ -1114,7 +1372,11 @@
 
    private void stopFM() {
        Log.d(LOGTAG, "In stopFM");
-       configureFMDeviceLoopback(false);
+       if (mUseAudioSession) {
+           configureAudioDataPath(false);
+       } else {
+           configureFMDeviceLoopback(false);
+       }
        mPlaybackInProgress = false;
        try {
            if ((mServiceInUse) && (mCallbacks != null))
@@ -1127,7 +1389,11 @@
    private void resetFM(){
        Log.d(LOGTAG, "resetFM");
        mPlaybackInProgress = false;
-       configureFMDeviceLoopback(false);
+       if (mUseAudioSession) {
+           configureAudioDataPath(false);
+       } else {
+           configureFMDeviceLoopback(false);
+       }
    }
 
    private boolean getRecordServiceStatus() {
@@ -1556,6 +1822,20 @@
       }
  };
 
+   private class AudioRoutingListener implements AudioRouting.OnRoutingChangedListener {
+       public void onRoutingChanged(AudioRouting audioRouting) {
+           Log.d(LOGTAG, " onRoutingChanged  + currdevice " + mCurrentDevice);
+           AudioDeviceInfo routedDevice = audioRouting.getRoutedDevice();
+           // if routing is nowhere, we get routedDevice as null
+           if (routedDevice != null) {
+               Log.d(LOGTAG, " Audio Routed to device id " + routedDevice.getType());
+               if (routedDevice.getType() != mCurrentDevice) {
+                   startApplicationLoopBack(mCurrentDevice);
+               }
+           }
+       }
+   }
+
    private Handler mDelayedStopHandler = new Handler() {
       @Override
       public void handleMessage(Message msg) {
@@ -2510,11 +2790,15 @@
            mAudioDevice = AudioDeviceInfo.TYPE_BUILTIN_SPEAKER;
            outputDevice = "Speaker";
        }
-       mAudioDeviceType = mAudioDevice | AudioSystem.DEVICE_OUT_FM;
-       AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
-       String keyValPairs = new String("fm_routing="+mAudioDeviceType);
-       Log.d(LOGTAG, "keyValPairs = "+keyValPairs);
-       audioManager.setParameters(keyValPairs);
+       if (mUseAudioSession) {
+           startApplicationLoopBack(mAudioDevice);
+       } else {
+           mAudioDeviceType = mAudioDevice | AudioSystem.DEVICE_OUT_FM;
+           AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
+           String keyValPairs = new String("fm_routing="+mAudioDeviceType);
+           Log.d(LOGTAG, "keyValPairs = "+keyValPairs);
+           audioManager.setParameters(keyValPairs);
+       }
        enableSlimbus(ENABLE_SLIMBUS_DATA_PORT);
    }
   /*
@@ -3936,4 +4220,47 @@
            //TODO unregister the fm service here.
        }
    }
+
+    private void startApplicationLoopBack(int deviceType) {
+        // stop existing playback path before starting new one
+        Log.d(LOGTAG, "startApplicationLoopBack for device " + deviceType);
+
+        AudioDeviceInfo outputDevice = null;
+        AudioDeviceInfo[] deviceList = mAudioManager.getDevices(AudioManager.GET_DEVICES_OUTPUTS);
+        for (AudioDeviceInfo audioDeviceInfo : deviceList) {
+            Log.d(LOGTAG, "startApplicationLoopBack dev_type " + audioDeviceInfo.getType());
+            if (AudioDeviceInfo.TYPE_WIRED_HEADSET == deviceType
+                    || AudioDeviceInfo.TYPE_WIRED_HEADPHONES == deviceType) {
+                if (audioDeviceInfo.getType() == AudioDeviceInfo.TYPE_WIRED_HEADSET ||
+                        audioDeviceInfo.getType() == AudioDeviceInfo.TYPE_WIRED_HEADPHONES) {
+                    outputDevice = audioDeviceInfo;
+                    Log.d(LOGTAG, "startApplicationLoopBack found_dev "
+                            + audioDeviceInfo.getType());
+                    break;
+                }
+            } else if (audioDeviceInfo.getType() == deviceType) {
+                outputDevice = audioDeviceInfo;
+                Log.d(LOGTAG, "startApplicationLoopBack found_dev " + audioDeviceInfo.getType());
+                break;
+            }
+        }
+        if (outputDevice == null) {
+            Log.d(LOGTAG, "no output device" + deviceType + " found");
+            return;
+        }
+        if (mIsFMDeviceLoopbackActive) {
+            enableSlimbus(DISABLE_SLIMBUS_DATA_PORT);
+            configureFMDeviceLoopback_O(false);
+        }
+        if (!isRecordSinking()) {
+            createRecordSessions();
+            Log.d(LOGTAG, "creating AudioTrack session");
+        }
+        mCurrentDevice = outputDevice.getType();
+        mAudioTrack.setPreferredDevice(outputDevice);
+        Log.d(LOGTAG, "PreferredDevice is set to " + outputDevice.getType());
+        if (!isRecordSinking()) {
+            startRecordSink();
+        }
+    }
 }
