diff options
author | Ayaz Ahmad <aahmad@codeaurora.org> | 2013-09-05 16:53:09 +0530 |
---|---|---|
committer | Ayaz Ahmad <aahmad@codeaurora.org> | 2013-09-13 12:09:17 +0530 |
commit | 5d19b1bbc9102c472fc62914ae08339a45ae1b51 (patch) | |
tree | ccd06d38b31beadbba872e5b90266d95eb616e37 /FMRecord | |
parent | cd4bbb4f8e74be388a7d99dea1ca58c87ca19193 (diff) | |
download | android_hardware_qcom_fm-5d19b1bbc9102c472fc62914ae08339a45ae1b51.tar.gz android_hardware_qcom_fm-5d19b1bbc9102c472fc62914ae08339a45ae1b51.tar.bz2 android_hardware_qcom_fm-5d19b1bbc9102c472fc62914ae08339a45ae1b51.zip |
fm: Check FM process status while recording
FM recording does not stop after clearing app data
of FM package. When recording starts check repeatedly
client status which requested for recording.
Change-Id: Ibd33ef18c306f64848e84caf98ce4058f3312414
CRs-Fixed: 535211
Diffstat (limited to 'FMRecord')
-rw-r--r-- | FMRecord/src/com/codeaurora/fmrecording/FMRecordingService.java | 74 |
1 files changed, 72 insertions, 2 deletions
diff --git a/FMRecord/src/com/codeaurora/fmrecording/FMRecordingService.java b/FMRecord/src/com/codeaurora/fmrecording/FMRecordingService.java index 39db48a..e542512 100644 --- a/FMRecord/src/com/codeaurora/fmrecording/FMRecordingService.java +++ b/FMRecord/src/com/codeaurora/fmrecording/FMRecordingService.java @@ -64,6 +64,9 @@ import android.R.layout; import android.R.drawable; import android.content.ComponentName; import android.content.res.Resources; +import android.os.Process; +import android.app.ActivityManager; +import android.app.ActivityManager.RunningAppProcessInfo; public class FMRecordingService extends Service { private static final String TAG = "FMRecordingService"; @@ -86,6 +89,10 @@ public class FMRecordingService extends Service { static final int START = 1; static final int STOP = 0; private int mRecordDuration = -1; + private Thread mStatusCheckThread = null; + private int clientPid = -1; + private String clientProcessName = ""; + public void onCreate() { super.onCreate(); @@ -319,6 +326,7 @@ public class FMRecordingService extends Service { sendRecordingStatusIntent(STOP); saveFile(); stopForeground(true); + stopClientStatusCheck(); } private void saveFile() { @@ -464,11 +472,15 @@ public class FMRecordingService extends Service { Log.d(TAG, " action = " +action); if (action.equals(ACTION_FM_RECORDING)) { int state = intent.getIntExtra("state", STOP); - Log.d(TAG, "ACTION_FM_RECORDING Intent received" +state); + Log.d(TAG, "ACTION_FM_RECORDING Intent received" + state); if (state == START) { Log.d(TAG, "Recording start"); mRecordDuration = intent.getIntExtra("record_duration", mRecordDuration); - startRecord(); + if(startRecord()) { + clientProcessName = intent.getStringExtra("process_name"); + clientPid = intent.getIntExtra("process_id", -1); + startClientStatusCheck(); + } } else if (state == STOP) { Log.d(TAG, "Stop recording"); stopRecord(); @@ -482,4 +494,62 @@ public class FMRecordingService extends Service { } } + private boolean getClientStatus(int pid, String processName) { + boolean status = false; + ActivityManager actvityManager = + (ActivityManager)this.getSystemService( + this.ACTIVITY_SERVICE); + + List<RunningAppProcessInfo> procInfos = + actvityManager.getRunningAppProcesses(); + + for(RunningAppProcessInfo procInfo : procInfos) { + if ((pid == procInfo.pid) + && + (procInfo.processName.equals(processName))) { + status = true; + break; + } + } + procInfos.clear(); + return status; + } + + private Runnable clientStatusCheckThread = new Runnable() { + @Override + public void run() { + while(!Thread.currentThread().isInterrupted()) { + try { + if(!getClientStatus(clientPid, clientProcessName)) { + stopRecord(); + break; + }; + Thread.sleep(500); + }catch(Exception e) { + Log.d(TAG, "Client status check thread interrupted"); + break; + } + } + } + }; + + private void startClientStatusCheck() { + if((mStatusCheckThread == null) || + (mStatusCheckThread.getState() == Thread.State.TERMINATED)) { + mStatusCheckThread = new Thread(null, + clientStatusCheckThread, + "GetClientStatus"); + } + if((mStatusCheckThread != null) && + (mStatusCheckThread.getState() == Thread.State.NEW)) { + mStatusCheckThread.start(); + } + } + + private void stopClientStatusCheck() { + if(mStatusCheckThread != null) { + mStatusCheckThread.interrupt(); + } + } + } |