[FMRadio] Check radio state before scan. 61/88761/2
authorTomasz Marciniak <t.marciniak@samsung.com>
Tue, 20 Sep 2016 12:21:23 +0000 (14:21 +0200)
committerTomasz Marciniak <t.marciniak@samsung.com>
Tue, 20 Sep 2016 12:32:21 +0000 (14:32 +0200)
[Verification] Code compiles. TCT pass rate 100%
This change makes web api less dependent on
native api returned value.

Change-Id: Id51451fd0fdf80c3ed34b03da8fb530b2a592c20
Signed-off-by: Tomasz Marciniak <t.marciniak@samsung.com>
src/radio/radio_manager.cc

index 84931ed..a6871a8 100755 (executable)
@@ -436,10 +436,25 @@ void FMRadioManager::SeekDown(double callback_id) {
 void FMRadioManager::ScanStart(double callback_id) {
   LoggerD("Enter");
 
+  radio_state_e state;
+  auto err = radio_get_state(radio_instance_, &state);
+  if (RADIO_ERROR_NONE != err) {
+    LoggerE("radio_get_state() failed: %d", err);
+    PostResultFailure(callback_id, GetPlatformResult("radio_get_state", err));
+    return;
+  }
+
+  if (RADIO_STATE_READY != state) {
+    LoggerE("Incorrect radio state");
+    PostResultFailure(callback_id,
+                      GetPlatformResult("Incorrect radio state", RADIO_ERROR_INVALID_STATE));
+    return;
+  }
+
   RadioScanData* user_data = new RadioScanData(*this);
   user_data->callback_id_ = callback_id;
 
-  auto err = radio_set_scan_completed_cb(radio_instance_, ScanCompleteCallback,
+  err = radio_set_scan_completed_cb(radio_instance_, ScanCompleteCallback,
                                          user_data);
   if (RADIO_ERROR_NONE != err) {
     PostResultFailure(callback_id,