Skip to content
Snippets Groups Projects
Commit b76653ce authored by Kamal Negi's avatar Kamal Negi
Browse files

FMStats: Don't run runnable in context of handler

In search staion test, we get tune status event for every station
found and fetch the parameter values for that station. For that we post
runnable to handler to execute. On event received, we also send message to
process message handler and not able to process message as runnable is
already waiting and this leads to ANR. So now on tune complete, we
create thread for the runnable instead of handler.

Change-Id: I48795102965ff70a8a80180b6e2f9d253db99eef
parent 3724882c
Branches
No related tags found
No related merge requests found
......@@ -276,6 +276,7 @@ public class FMStats extends Activity {
private Thread mRecordUpdateHandlerThread = null;
private Thread mRunTestThread = null;
private Thread mTuneCompleteThread = null;
boolean mRecording = false;
......@@ -465,11 +466,9 @@ public class FMStats extends Activity {
if (lastCmdSent == CMD_STNPARAM_SINR)
nSINR = msg.arg1;
}
if (mRunTestThread != null) {
synchronized (obj) {
obj.notify();
}
}
lastCmdSent = 0;
break;
case GET_STATION_DBG_PARAM:
......@@ -484,11 +483,9 @@ public class FMStats extends Activity {
if (lastCmdSent == CMD_STNDBGPARAM_INFDETOUT)
nIntDet = msg.arg1;
}
if (mRunTestThread != null) {
synchronized (obj) {
obj.notify();
}
}
break;
default:
Log.e(LOGTAG, "mCallbackHandler:Default");
......@@ -535,9 +532,6 @@ public class FMStats extends Activity {
if(mUIUpdateHandlerHandler != null) {
mUIUpdateHandlerHandler.removeCallbacksAndMessages(null);
}
if(mHandler != null) {
mHandler.removeCallbacksAndMessages(null);
}
unRegisterBroadcastReceiver(mBandSweepDelayExprdListener);
unRegisterBroadcastReceiver(mBandSweepDwellExprdListener);
if(null != mFileCursor ) {
......@@ -563,6 +557,28 @@ public class FMStats extends Activity {
}
};
private Runnable mTuneComplete = new Runnable(){
public void run(){
if((null != mMultiUpdateThread) &&(null != mSync))
{
synchronized(mSync){
mSync.notify();
}
}
if((mTestSelected == SEARCH_TEST) && (mService != null)) {
/* On every Tune Complete generate the result for the current
Frequency*/
Message updateUI = new Message();
updateUI.what = STATUS_UPDATE;
int freq = FmSharedPreferences.getTunedFrequency();
updateUI.obj = (Object)GetFMStatsForFreq(freq);
if (updateUI.obj == null)
updateUI.what = STATUS_DONE;
mUIUpdateHandlerHandler.sendMessage(updateUI);
}
}
};
private View.OnClickListener mOnRunListener = new View.OnClickListener() {
public void onClick(View v) {
Log.d(LOGTAG, "mTestRunning=" + mTestRunning);
......@@ -3515,8 +3531,21 @@ public class FMStats extends Activity {
public void onTuneStatusChanged()
{
Log.d(LOGTAG, "mServiceCallbacks.onTuneStatusChanged :" + mTestRunning);
if (mTestRunning)
mHandler.post(mTuneComplete);
if (mTestRunning) {
if ((mTuneCompleteThread == null) || (mTuneCompleteThread.getState() == Thread.State.TERMINATED)) {
mTuneCompleteThread = new Thread(mTuneComplete,
"mTuneCompleteThread");
} else {
Log.e(LOGTAG, "mTuneCompleteThread is already running");
return;
}
if (mTuneCompleteThread != null) {
mTuneCompleteThread.start();
} else {
Log.e(LOGTAG, "mTuneCompleteThread: new thread create failed");
return;
}
}
}
public void onProgramServiceChanged()
......@@ -3737,30 +3766,6 @@ public class FMStats extends Activity {
mCallbackHandler.obtainMessage(GET_STATION_DBG_PARAM, val, status).sendToTarget();
}
};
/* Radio Vars */
private Handler mHandler = new Handler();
private Runnable mTuneComplete = new Runnable(){
public void run(){
if((null != mMultiUpdateThread) &&(null != mSync))
{
synchronized(mSync){
mSync.notify();
}
}
if((mTestSelected == SEARCH_TEST) && (mService != null)) {
/* On every Tune Complete generate the result for the current
Frequency*/
Message updateUI = new Message();
updateUI.what = STATUS_UPDATE;
int freq = FmSharedPreferences.getTunedFrequency();
updateUI.obj = (Object)GetFMStatsForFreq(freq);
if (updateUI.obj == null)
updateUI.what = STATUS_DONE;
mUIUpdateHandlerHandler.sendMessage(updateUI);
}
}
};
private void stopCurTest() {
if (mRunTestThread != null) {
......@@ -3779,7 +3784,8 @@ public class FMStats extends Activity {
mMultiUpdateThread.interrupt();
break;
case SEARCH_TEST:
mHandler.removeCallbacks(mTuneComplete);
if (mTuneCompleteThread != null)
mTuneCompleteThread.interrupt();
if (mService != null) {
try {
Message updateStop = new Message();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment