Skip to content

Support SystemSound.play() #84

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 2 additions & 16 deletions shell/platform/tizen/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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",
Expand All @@ -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) {
Expand Down
89 changes: 59 additions & 30 deletions shell/platform/tizen/channels/platform_channel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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: "
Expand All @@ -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<int>(result_code));
"Enter FeedbackManager::GetErrorMessage(): result_code: [%d], "
"method_name: (%s), args: (%s)",
static_cast<int>(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()");

Expand All @@ -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<int>(type), static_cast<int>(pattern));

if (ResultCode::kOk != initialization_status_) {
FT_LOGE("Cannot run Vibrate(): initialization_status_: [%d]",
FT_LOGE("Cannot run Play(): initialization_status_: [%d]",
static_cast<int>(initialization_status_));
return initialization_status_;
}

auto ret =
feedback_play_type(FEEDBACK_TYPE_VIBRATION, FEEDBACK_PATTERN_SIP);
auto ret = feedback_play_type(static_cast<feedback_type_e>(type),
static_cast<feedback_pattern_e>(pattern));
if (FEEDBACK_ERROR_NONE == ret) {
FT_LOGD("feedback_play_type() succeeded");
return ResultCode::kOk;
Expand Down Expand Up @@ -163,8 +177,6 @@ class FeedbackManager {
}

ResultCode initialization_status_ = ResultCode::kUnknownError;

#endif // defined(MOBILE_PROFILE) || defined(WEARABLE_PROFILE)
};

} // namespace
Expand All @@ -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
Expand All @@ -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;
Expand All @@ -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") {
Expand Down