FM: synchronize sleep timer thread
wait until previous thread completes its execution
before starting new.
start thread when thread sate is NEW.
CRs-Fixed: 2505592
Change-Id: If3e2ef12c2ea71a6a24837322758a3d175c4a63d
diff --git a/fmapp2/src/com/caf/fmradio/FMRadio.java b/fmapp2/src/com/caf/fmradio/FMRadio.java
index 54baa12..b378ba1 100644
--- a/fmapp2/src/com/caf/fmradio/FMRadio.java
+++ b/fmapp2/src/com/caf/fmradio/FMRadio.java
@@ -495,6 +495,11 @@
if (isSleepTimerActive()) {
Log.d(LOGTAG, "FMRadio: Sleep Timer active");
mSleepUpdateHandlerThread.interrupt();
+ try {
+ mSleepUpdateHandlerThread.join();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
}
mRadioTextScroller.stopScroll();
mERadioTextScroller.stopScroll();
@@ -535,6 +540,11 @@
mService.cancelDelayedStop(FMRadioService.STOP_SERVICE);
if(null != mSleepUpdateHandlerThread) {
mSleepUpdateHandlerThread.interrupt();
+ try {
+ mSleepUpdateHandlerThread.join();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
}
} catch (Exception e) {
e.printStackTrace();
@@ -2310,7 +2320,7 @@
"SleepUpdateThread");
}
/* If the thread state is "new" then the thread has not yet started */
- if(mSleepUpdateHandlerThread.getState() != Thread.State.TERMINATED && isFmOn()) {
+ if(mSleepUpdateHandlerThread.getState() == Thread.State.NEW && isFmOn()) {
try {
if((mService != null) &&
!mService.isSleepTimerActive()) {
@@ -2320,10 +2330,6 @@
FMRadioService.STOP_SERVICE);
}
}
- if (mSleepUpdateHandlerThread.getState() == Thread.State.TERMINATED) {
- mSleepUpdateHandlerThread = new Thread(null, doSleepProcessing,
- "SleepUpdateThread");
- }
mSleepUpdateHandlerThread.start();
}catch(Exception e) {
e.printStackTrace();
@@ -2343,6 +2349,11 @@
if(null != mSleepUpdateHandlerThread) {
mSleepUpdateHandlerThread.interrupt();
+ try {
+ mSleepUpdateHandlerThread.join();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
}
if(null != mSleepMsgTV) {
mSleepMsgTV.setVisibility(View.INVISIBLE);