From 4b44dadddf1ee63734a3afc57b3005c3dd09a03b Mon Sep 17 00:00:00 2001
From: Rupesh Tatiya <rtatiya@codeaurora.org>
Date: Thu, 29 Oct 2015 16:18:01 +0530
Subject: [PATCH] Do not stop FM Radio Service during unbind using stopSelf.

During Unbind, do not kill FM Radio service. The service might restart
again and it will end up getting Media Button events starving other
eligible applications. Use explicit stopService call in FM Radio. This
calls Destroy callback resulting in proper clean up of FM Radio Service.

CRs-Fixed: 932236
Change-Id: Idf3d768e66bd4bafc7d1ef40aefa15982454889c
---
 fmapp2/src/com/caf/fmradio/FMRadio.java        | 2 ++
 fmapp2/src/com/caf/fmradio/FMRadioService.java | 7 -------
 2 files changed, 2 insertions(+), 7 deletions(-)

diff --git a/fmapp2/src/com/caf/fmradio/FMRadio.java b/fmapp2/src/com/caf/fmradio/FMRadio.java
index 20270e3..45b68bc 100644
--- a/fmapp2/src/com/caf/fmradio/FMRadio.java
+++ b/fmapp2/src/com/caf/fmradio/FMRadio.java
@@ -2999,6 +2999,8 @@ public class FMRadio extends Activity
          return;
       }
       context.unbindService(sb);
+      Log.e(LOGTAG, "stop FM radio service");
+      context.stopService(new Intent(context, FMRadioService.class));
       if (sConnectionMap.isEmpty()) {
          // presumably there is nobody interested in the service at this point,
          // so don't hang on to the ServiceConnection
diff --git a/fmapp2/src/com/caf/fmradio/FMRadioService.java b/fmapp2/src/com/caf/fmradio/FMRadioService.java
index 56d9aa6..b9adc42 100644
--- a/fmapp2/src/com/caf/fmradio/FMRadioService.java
+++ b/fmapp2/src/com/caf/fmradio/FMRadioService.java
@@ -941,13 +941,6 @@ public class FMRadioService extends Service
       /* Application/UI is not attached, so go into lower power mode */
       unregisterCallbacks();
       setLowPowerMode(true);
-      if (isFmOn())
-      {
-         // something is currently playing, or will be playing once
-         // an in-progress call ends, so don't stop the service now.
-         return true;
-      }
-      stopSelf(mServiceStartId);
       return true;
    }
 
-- 
GitLab