@@ -40,6 +40,17 @@ class FeedbackManager {
4040 kUnknownError
4141 };
4242
43+ enum class FeedbackPattern {
44+ kClick = FEEDBACK_PATTERN_TAP,
45+ kAlert = FEEDBACK_PATTERN_GENERAL,
46+ kSip = FEEDBACK_PATTERN_SIP
47+ };
48+
49+ enum class FeedbackType {
50+ kVibration = FEEDBACK_TYPE_VIBRATION,
51+ kSound = FEEDBACK_TYPE_SOUND
52+ };
53+
4354 static std::string GetVibrateVariantName (const char * haptic_feedback_type) {
4455 FT_LOGD (
4556 " Enter FeedbackManager::GetVibrateVariantName(): haptic_feedback_type: "
@@ -60,30 +71,32 @@ class FeedbackManager {
6071 std::string{haptic_feedback_type + kPrefixToRemoveLen };
6172 }
6273
63- static std::string GetErrorMessage (const std::string& method_name,
64- ResultCode result_code) {
74+ static std::string GetErrorMessage (ResultCode result_code,
75+ const std::string& method_name,
76+ const std::string& args = " " ) {
6577 FT_LOGD (
66- " Enter FeedbackManager::GetErrorMessage(): method_name: (%s), "
67- " result_code: [%d]" ,
68- method_name.c_str (), static_cast <int >(result_code));
78+ " Enter FeedbackManager::GetErrorMessage(): result_code: [%d], "
79+ " method_name: (%s), args: (%s)" ,
80+ static_cast <int >(result_code), method_name.c_str (), args.c_str ());
81+
82+ const auto method_name_with_args = method_name + " (" + args + " )" ;
6983
7084 switch (result_code) {
7185 case ResultCode::kNotSupportedError :
72- return method_name + " () is not supported" ;
86+ return method_name_with_args + " is not supported" ;
7387 case ResultCode::kPermissionDeniedError :
74- return std::string{" No permission to run " } + method_name +
75- " () . Add "
88+ return std::string{" No permission to run " } + method_name_with_args +
89+ " . Add "
7690 " \" http://tizen.org/privilege/feedback\" privilege to "
7791 " tizen-manifest.xml "
7892 " to use this method" ;
7993 case ResultCode::kUnknownError :
8094 default :
81- return std::string{" An unknown error on " } + method_name + " () call" ;
95+ return std::string{" An unknown error on " } + method_name_with_args +
96+ " call" ;
8297 }
8398 }
8499
85- #if defined(MOBILE_PROFILE) || defined(WEARABLE_PROFILE)
86-
87100 static FeedbackManager& GetInstance () {
88101 FT_LOGD (" Enter FeedbackManager::GetInstance()" );
89102
@@ -94,17 +107,18 @@ class FeedbackManager {
94107 FeedbackManager (const FeedbackManager&) = delete ;
95108 FeedbackManager& operator =(const FeedbackManager&) = delete ;
96109
97- ResultCode Vibrate () {
98- FT_LOGD (" Enter FeedbackManager::Vibrate()" );
110+ ResultCode Play (FeedbackType type, FeedbackPattern pattern) {
111+ FT_LOGD (" Enter FeedbackManager::Play(): type: [%d], pattern: [%d]" ,
112+ static_cast <int >(type), static_cast <int >(pattern));
99113
100114 if (ResultCode::kOk != initialization_status_) {
101- FT_LOGE (" Cannot run Vibrate (): initialization_status_: [%d]" ,
115+ FT_LOGE (" Cannot run Play (): initialization_status_: [%d]" ,
102116 static_cast <int >(initialization_status_));
103117 return initialization_status_;
104118 }
105119
106- auto ret =
107- feedback_play_type (FEEDBACK_TYPE_VIBRATION, FEEDBACK_PATTERN_SIP );
120+ auto ret = feedback_play_type ( static_cast <feedback_type_e>(type),
121+ static_cast <feedback_pattern_e>(pattern) );
108122 if (FEEDBACK_ERROR_NONE == ret) {
109123 FT_LOGD (" feedback_play_type() succeeded" );
110124 return ResultCode::kOk ;
@@ -163,8 +177,6 @@ class FeedbackManager {
163177 }
164178
165179 ResultCode initialization_status_ = ResultCode::kUnknownError ;
166-
167- #endif // defined(MOBILE_PROFILE) || defined(WEARABLE_PROFILE)
168180};
169181
170182} // namespace
@@ -178,13 +190,32 @@ void PlatformChannel::HandleMethodCall(
178190 ui_app_exit ();
179191 result->Success ();
180192 } else if (method == " SystemSound.play" ) {
181- result->NotImplemented ();
193+ FT_LOGD (" SystemSound.play() call received" );
194+
195+ const std::string pattern_str = call.arguments ()[0 ].GetString ();
196+
197+ const FeedbackManager::FeedbackPattern pattern =
198+ (pattern_str == " SystemSoundType.click" )
199+ ? FeedbackManager::FeedbackPattern::kClick
200+ : FeedbackManager::FeedbackPattern::kAlert ;
201+
202+ auto ret = FeedbackManager::GetInstance ().Play (
203+ FeedbackManager::FeedbackType::kSound , pattern);
204+ if (FeedbackManager::ResultCode::kOk == ret) {
205+ result->Success ();
206+ return ;
207+ }
208+
209+ const auto error_cause =
210+ FeedbackManager::GetErrorMessage (ret, " SystemSound.play" , pattern_str);
211+ const std::string error_message = " Could not play sound" ;
212+ FT_LOGE (" %s: %s" , error_cause.c_str (), error_message.c_str ());
213+
214+ result->Error (error_cause, error_message);
215+
182216 } else if (method == " HapticFeedback.vibrate" ) {
183217 FT_LOGD (" HapticFeedback.vibrate() call received" );
184218
185- const std::string error_message = " Could not vibrate" ;
186-
187- #if defined(MOBILE_PROFILE) || defined(WEARABLE_PROFILE)
188219 /*
189220 * We use a single type of vibration (FEEDBACK_PATTERN_SIP) to implement
190221 * HapticFeedback's vibrate, lightImpact, mediumImpact, heavyImpact
@@ -194,7 +225,9 @@ void PlatformChannel::HandleMethodCall(
194225 * calls.
195226 */
196227
197- auto ret = FeedbackManager::GetInstance ().Vibrate ();
228+ auto ret = FeedbackManager::GetInstance ().Play (
229+ FeedbackManager::FeedbackType::kVibration ,
230+ FeedbackManager::FeedbackPattern::kSip );
198231 if (FeedbackManager::ResultCode::kOk == ret) {
199232 result->Success ();
200233 return ;
@@ -203,14 +236,10 @@ void PlatformChannel::HandleMethodCall(
203236 const auto vibrate_variant_name =
204237 FeedbackManager::GetVibrateVariantName (call.arguments ()[0 ].GetString ());
205238 const auto error_cause =
206- FeedbackManager::GetErrorMessage (vibrate_variant_name, ret);
239+ FeedbackManager::GetErrorMessage (ret, vibrate_variant_name);
240+ const std::string error_message = " Could not vibrate" ;
241+
207242 FT_LOGE (" %s: %s" , error_cause.c_str (), error_message.c_str ());
208- #else
209- const auto vibrate_variant_name =
210- FeedbackManager::GetVibrateVariantName (call.arguments ()[0 ].GetString ());
211- const auto error_cause = FeedbackManager::GetErrorMessage (
212- vibrate_variant_name, FeedbackManager::ResultCode::kNotSupportedError );
213- #endif // defined(MOBILE_PROFILE) || defined(WEARABLE_PROFILE)
214243
215244 result->Error (error_cause, error_message);
216245 } else if (method == " Clipboard.getData" ) {
0 commit comments