From 39cc02e4f3988195bac67b8bcc6f7d95a08e05c1 Mon Sep 17 00:00:00 2001
From: Pawel Wasowski
Date: Fri, 7 May 2021 11:37:39 +0200
Subject: [PATCH] [PlatformChannel] Minor refactoring and implementation of
SystemSound.play()
Signed-off-by: Pawel Wasowski
---
shell/platform/tizen/BUILD.gn | 18 +---
.../tizen/channels/platform_channel.cc | 89 ++++++++++++-------
2 files changed, 61 insertions(+), 46 deletions(-)
diff --git a/shell/platform/tizen/BUILD.gn b/shell/platform/tizen/BUILD.gn
index ae49587d59f18..fa7b32d494fe1 100644
--- a/shell/platform/tizen/BUILD.gn
+++ b/shell/platform/tizen/BUILD.gn
@@ -79,8 +79,6 @@ config("tizen_rootstrap_include_dirs") {
template("embedder_for_profile") {
forward_variables_from(invoker, [ "use_evas_gl_renderer" ])
- profile = target_name
-
if (!defined(use_evas_gl_renderer)) {
use_evas_gl_renderer = false
}
@@ -110,6 +108,7 @@ template("embedder_for_profile") {
libs = [
"base-utils-i18n",
"capi-appfw-application",
+ "capi-base-common",
"capi-system-info",
"capi-system-system-settings",
"dlog",
@@ -119,26 +118,13 @@ template("embedder_for_profile") {
"eina",
"evas",
"EGL",
+ "feedback",
"GLESv2",
"tbm",
"tdm-client",
"wayland-client",
]
- if (profile == "mobile") {
- libs += [
- "capi-base-common",
- "feedback",
- ]
- }
-
- if (profile == "wearable") {
- libs += [
- "capi-base-common",
- "feedback",
- ]
- }
-
defines = invoker.defines
if (use_evas_gl_renderer) {
diff --git a/shell/platform/tizen/channels/platform_channel.cc b/shell/platform/tizen/channels/platform_channel.cc
index 172bd4a942610..fccc231b508a9 100644
--- a/shell/platform/tizen/channels/platform_channel.cc
+++ b/shell/platform/tizen/channels/platform_channel.cc
@@ -40,6 +40,17 @@ class FeedbackManager {
kUnknownError
};
+ enum class FeedbackPattern {
+ kClick = FEEDBACK_PATTERN_TAP,
+ kAlert = FEEDBACK_PATTERN_GENERAL,
+ kSip = FEEDBACK_PATTERN_SIP
+ };
+
+ enum class FeedbackType {
+ kVibration = FEEDBACK_TYPE_VIBRATION,
+ kSound = FEEDBACK_TYPE_SOUND
+ };
+
static std::string GetVibrateVariantName(const char* haptic_feedback_type) {
FT_LOGD(
"Enter FeedbackManager::GetVibrateVariantName(): haptic_feedback_type: "
@@ -60,30 +71,32 @@ class FeedbackManager {
std::string{haptic_feedback_type + kPrefixToRemoveLen};
}
- static std::string GetErrorMessage(const std::string& method_name,
- ResultCode result_code) {
+ static std::string GetErrorMessage(ResultCode result_code,
+ const std::string& method_name,
+ const std::string& args = "") {
FT_LOGD(
- "Enter FeedbackManager::GetErrorMessage(): method_name: (%s), "
- "result_code: [%d]",
- method_name.c_str(), static_cast(result_code));
+ "Enter FeedbackManager::GetErrorMessage(): result_code: [%d], "
+ "method_name: (%s), args: (%s)",
+ static_cast(result_code), method_name.c_str(), args.c_str());
+
+ const auto method_name_with_args = method_name + "(" + args + ")";
switch (result_code) {
case ResultCode::kNotSupportedError:
- return method_name + "() is not supported";
+ return method_name_with_args + " is not supported";
case ResultCode::kPermissionDeniedError:
- return std::string{"No permission to run "} + method_name +
- "(). Add "
+ return std::string{"No permission to run "} + method_name_with_args +
+ ". Add "
"\"http://tizen.org/privilege/feedback\" privilege to "
"tizen-manifest.xml "
"to use this method";
case ResultCode::kUnknownError:
default:
- return std::string{"An unknown error on "} + method_name + "() call";
+ return std::string{"An unknown error on "} + method_name_with_args +
+ " call";
}
}
-#if defined(MOBILE_PROFILE) || defined(WEARABLE_PROFILE)
-
static FeedbackManager& GetInstance() {
FT_LOGD("Enter FeedbackManager::GetInstance()");
@@ -94,17 +107,18 @@ class FeedbackManager {
FeedbackManager(const FeedbackManager&) = delete;
FeedbackManager& operator=(const FeedbackManager&) = delete;
- ResultCode Vibrate() {
- FT_LOGD("Enter FeedbackManager::Vibrate()");
+ ResultCode Play(FeedbackType type, FeedbackPattern pattern) {
+ FT_LOGD("Enter FeedbackManager::Play(): type: [%d], pattern: [%d]",
+ static_cast(type), static_cast(pattern));
if (ResultCode::kOk != initialization_status_) {
- FT_LOGE("Cannot run Vibrate(): initialization_status_: [%d]",
+ FT_LOGE("Cannot run Play(): initialization_status_: [%d]",
static_cast(initialization_status_));
return initialization_status_;
}
- auto ret =
- feedback_play_type(FEEDBACK_TYPE_VIBRATION, FEEDBACK_PATTERN_SIP);
+ auto ret = feedback_play_type(static_cast(type),
+ static_cast(pattern));
if (FEEDBACK_ERROR_NONE == ret) {
FT_LOGD("feedback_play_type() succeeded");
return ResultCode::kOk;
@@ -163,8 +177,6 @@ class FeedbackManager {
}
ResultCode initialization_status_ = ResultCode::kUnknownError;
-
-#endif // defined(MOBILE_PROFILE) || defined(WEARABLE_PROFILE)
};
} // namespace
@@ -178,13 +190,32 @@ void PlatformChannel::HandleMethodCall(
ui_app_exit();
result->Success();
} else if (method == "SystemSound.play") {
- result->NotImplemented();
+ FT_LOGD("SystemSound.play() call received");
+
+ const std::string pattern_str = call.arguments()[0].GetString();
+
+ const FeedbackManager::FeedbackPattern pattern =
+ (pattern_str == "SystemSoundType.click")
+ ? FeedbackManager::FeedbackPattern::kClick
+ : FeedbackManager::FeedbackPattern::kAlert;
+
+ auto ret = FeedbackManager::GetInstance().Play(
+ FeedbackManager::FeedbackType::kSound, pattern);
+ if (FeedbackManager::ResultCode::kOk == ret) {
+ result->Success();
+ return;
+ }
+
+ const auto error_cause =
+ FeedbackManager::GetErrorMessage(ret, "SystemSound.play", pattern_str);
+ const std::string error_message = "Could not play sound";
+ FT_LOGE("%s: %s", error_cause.c_str(), error_message.c_str());
+
+ result->Error(error_cause, error_message);
+
} else if (method == "HapticFeedback.vibrate") {
FT_LOGD("HapticFeedback.vibrate() call received");
- const std::string error_message = "Could not vibrate";
-
-#if defined(MOBILE_PROFILE) || defined(WEARABLE_PROFILE)
/*
* We use a single type of vibration (FEEDBACK_PATTERN_SIP) to implement
* HapticFeedback's vibrate, lightImpact, mediumImpact, heavyImpact
@@ -194,7 +225,9 @@ void PlatformChannel::HandleMethodCall(
* calls.
*/
- auto ret = FeedbackManager::GetInstance().Vibrate();
+ auto ret = FeedbackManager::GetInstance().Play(
+ FeedbackManager::FeedbackType::kVibration,
+ FeedbackManager::FeedbackPattern::kSip);
if (FeedbackManager::ResultCode::kOk == ret) {
result->Success();
return;
@@ -203,14 +236,10 @@ void PlatformChannel::HandleMethodCall(
const auto vibrate_variant_name =
FeedbackManager::GetVibrateVariantName(call.arguments()[0].GetString());
const auto error_cause =
- FeedbackManager::GetErrorMessage(vibrate_variant_name, ret);
+ FeedbackManager::GetErrorMessage(ret, vibrate_variant_name);
+ const std::string error_message = "Could not vibrate";
+
FT_LOGE("%s: %s", error_cause.c_str(), error_message.c_str());
-#else
- const auto vibrate_variant_name =
- FeedbackManager::GetVibrateVariantName(call.arguments()[0].GetString());
- const auto error_cause = FeedbackManager::GetErrorMessage(
- vibrate_variant_name, FeedbackManager::ResultCode::kNotSupportedError);
-#endif // defined(MOBILE_PROFILE) || defined(WEARABLE_PROFILE)
result->Error(error_cause, error_message);
} else if (method == "Clipboard.getData") {