From 833970d02cddbdbe5a11f2020163eea4b34483ad Mon Sep 17 00:00:00 2001
From: Kamal Negi <kamaln@codeaurora.org>
Date: Wed, 16 Nov 2016 13:09:12 +0530
Subject: [PATCH] Update FM UI after service bind complete

On activity start, bind service callback can be delayed and is received after
activity life cycle i.e after onResume(). Because of the delay, UI
update won't happen. Hence update FM user interface, i.e. RDS, frequency etc.,
if service callback received or retry once after 100ms.

CRs-Fixed: 1090643
Change-Id: Icef5922c3e3972f5e44cd1d3f873f864785e26be
---
 fmapp2/src/com/caf/fmradio/FMRadio.java | 28 +++++++++++++++++--------
 1 file changed, 19 insertions(+), 9 deletions(-)

diff --git a/fmapp2/src/com/caf/fmradio/FMRadio.java b/fmapp2/src/com/caf/fmradio/FMRadio.java
index 7d357f7..1da839b 100644
--- a/fmapp2/src/com/caf/fmradio/FMRadio.java
+++ b/fmapp2/src/com/caf/fmradio/FMRadio.java
@@ -505,16 +505,25 @@ public class FMRadio extends Activity
 
       super.onResume();
 
-      if (!isAntennaAvailable()) {
+      if (mService == null) {
+          Log.d(LOGTAG,"bind callback has not received yet - wait for 100ms");
+          mHandler.postDelayed(UpdateFm, 100);
           return;
       }
-      // TODO: We should return on exception or continue?
-      try {
-          if (mService != null)
-              mService.registerCallbacks(mServiceCallbacks);
-      } catch (RemoteException e) {
-          e.printStackTrace();
-      }
+     mHandler.post(UpdateFm);
+   }
+   Runnable UpdateFm = new Runnable() {
+       public void run() {
+           // TODO: We should return on exception or continue?
+           if (!isAntennaAvailable()) {
+               return;
+           }
+           try {
+               if (mService != null)
+                   mService.registerCallbacks(mServiceCallbacks);
+           } catch (RemoteException e) {
+               e.printStackTrace();
+           }
 
       if (isSleepTimerActive()) {
           Log.d(LOGTAG, "isSleepTimerActive is true");
@@ -559,7 +568,8 @@ public class FMRadio extends Activity
       mUpdatePickerValue = true;
       updateStationInfoToUI();
       enableRadioOnOffUI();
-   }
+       }
+   };
    private static class LoadedDataAndState {
       public LoadedDataAndState(){};
       public boolean onOrOff;
-- 
GitLab