From: Rafal Walczyna Date: Mon, 4 Jun 2018 12:14:29 +0000 (+0200) Subject: [sound] Fix double firing of SoundModeChangeCallback X-Git-Tag: submit/tizen/20180612.064221~1^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=cb2b27a4ceb2b2dd28fd85d33e1a3f6a02dd2bee;p=platform%2Fcore%2Fapi%2Fwebapi-plugins.git [sound] Fix double firing of SoundModeChangeCallback Because of native functions logic callback was firing twice, sometimes with wrong (transitional) value [verification] TCT Auto + Manual 100% passrate Change-Id: I18bab460ecc16e39817318d76461ebe63a65d0bf Signed-off-by: Rafal Walczyna --- diff --git a/src/sound/sound_api.js b/src/sound/sound_api.js index 10cfc851..0eb82444 100644 --- a/src/sound/sound_api.js +++ b/src/sound/sound_api.js @@ -136,9 +136,22 @@ SoundManager.prototype.getVolume = function(type) { }; var _soundModeChangeListener; +var _currentSoundMode; +var _isFirstSoundModeChange = true; +// Native side sometimes fires sound change callback two times in a row +// with different values of sound mode. One of this value is only transitional +// value caused by hazard of two values which should change simultaneously. +// By waiting whether second callback would fire we bypass this problem. function _soundModeChangeListenerCallback(result) { - native_.callIfPossible(_soundModeChangeListener, native_.getResultObject(result)); + _currentSoundMode = result; + if (_isFirstSoundModeChange) { + _isFirstSoundModeChange = false; + setTimeout(function () { + _isFirstSoundModeChange = true; + native_.callIfPossible(_soundModeChangeListener, native_.getResultObject(_currentSoundMode)); + }, 100); + } } SoundManager.prototype.setSoundModeChangeListener = function(callback) { diff --git a/src/sound/sound_instance.cc b/src/sound/sound_instance.cc index 89e0b868..c45e7d67 100644 --- a/src/sound/sound_instance.cc +++ b/src/sound/sound_instance.cc @@ -132,6 +132,11 @@ void SoundInstance::SoundManagerUnsetSoundModeChangeListener(const picojson::val void SoundInstance::OnSoundModeChange(const std::string& newmode) { ScopeLogger(); + if (current_sound_mode == newmode) { + LoggerD("New sound mode equals to current sound mode"); + return; + } + current_sound_mode = newmode; picojson::value event = picojson::value(picojson::object()); picojson::object& obj = event.get(); picojson::value result = picojson::value(newmode); diff --git a/src/sound/sound_instance.h b/src/sound/sound_instance.h index 32a4c004..a800cf3b 100644 --- a/src/sound/sound_instance.h +++ b/src/sound/sound_instance.h @@ -45,6 +45,9 @@ class SoundInstance : public common::ParsedInstance, public SoundManagerSoundMod void OnSoundModeChange(const std::string& newmode); SoundManager manager_; + + // It is used in OnSoundModeChange function to prevent double firing of callback + std::string current_sound_mode; }; } // namespace sound