From 2ff1b0686b10a671eaf7de22de006997cee096c8 Mon Sep 17 00:00:00 2001 From: Yunhee Seo Date: Tue, 19 Dec 2023 15:50:47 +0900 Subject: [PATCH] [System.Feedback] Add internal API to support sound playing with priority Allows sound feedback pattern playing with priority. This is newly added to System.Feedback. - public enum FeedbackFlag -> It determines the sound play method. - public void PlayTypeWithFlagsInternal(FeedbackType type, String pattern, FeedbackFlag flag) -> It plays sound feedback pattern according to the FeedbackFlag value. Signed-off-by: Yunhee Seo --- src/Tizen.System.Feedback/Feedback/Feedback.cs | 78 ++++++++++++++++++++++ .../Interop/Interop.Feedback.cs | 9 +++ 2 files changed, 87 insertions(+) diff --git a/src/Tizen.System.Feedback/Feedback/Feedback.cs b/src/Tizen.System.Feedback/Feedback/Feedback.cs index 6365ea0..f7361b2 100755 --- a/src/Tizen.System.Feedback/Feedback/Feedback.cs +++ b/src/Tizen.System.Feedback/Feedback/Feedback.cs @@ -23,6 +23,26 @@ using System.Runtime.InteropServices; namespace Tizen.System { /// + /// Enumeration for feedback sound play method.\ + /// Currently, it is used only in the FeedbackType.Sound. + /// + /// 10 + [EditorBrowsable(EditorBrowsableState.Never)] + public enum FeedbackFlag + { + /// + /// Feedback flag none + /// + /// 10 + None = Interop.Feedback.FeedbackFlag.None, + /// + /// Feedback flag for priority-based play + /// + /// 10 + PriorityBasedPlay = Interop.Feedback.FeedbackFlag.PriorityBasedPlay, + } + + /// /// The Feedback API provides functions to control haptic and sound. /// The Feedback API provides the way to play and stop feedback, and get the information whether a specific pattern is supported. /// Below is the supported pattern string: @@ -788,5 +808,63 @@ namespace Tizen.System return themeIds; } + + /// + /// Plays a specific feedback pattern with feedback flag. + /// + /// + /// To play Vibration type, app should have http://tizen.org/privilege/haptic privilege. + /// FeedbackFlag.PriorityBasedPlay does not support playing Vibration pattern, it supports only Sound playing. + /// Thus, Above description corresponds only to FeedbackFlag.None. + /// + /// 10 + /// The feedback type. + /// The feedback pattern string. + /// The feedback flag of sound play method. + /// + /// http://tizen.org/feature/feedback.vibration for FeedbackType.Vibration + /// + /// Thrown when failed because feedback is not initialized. + /// Thrown when failed because of an invalid arguament. + /// Thrown when failed because the device (haptic, sound) or a specific pattern is not supported. + /// Thrown when failed because the access is not granted(No privilege) + /// Thrown when failed because of a system error. + /// http://tizen.org/privilege/haptic + /// + /// + /// Feedback feedback = new Feedback(); + /// feedback.PlayTypeWithFlagsInternal(FeedbackType.Sound, "Tap", FeedbackFlag.PriorityBasedPlay); + /// + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public void PlayTypeWithFlagsInternal(FeedbackType type, String pattern, FeedbackFlag flag) + { + int number; + Interop.Feedback.FeedbackError res; + + if (!Pattern.TryGetValue(pattern, out number)) + throw new ArgumentException($"Not supported pattern string : {pattern}", nameof(pattern)); + + res = (Interop.Feedback.FeedbackError)Interop.Feedback.PlayTypeWithFlagsInternal((Interop.Feedback.FeedbackType)type, + number, (Interop.Feedback.FeedbackFlag)flag); + if (res != Interop.Feedback.FeedbackError.None) + { + Log.Warn(LogTag, string.Format("Failed to play feedback pattern with flag. err = {0}", res)); + switch (res) + { + case Interop.Feedback.FeedbackError.NotInitialized: + throw new Exception("Not initialized"); + case Interop.Feedback.FeedbackError.InvalidParameter: + throw new ArgumentException("Invalid Arguments"); + case Interop.Feedback.FeedbackError.NotSupported: + throw new NotSupportedException("Not supported"); + case Interop.Feedback.FeedbackError.PermissionDenied: + throw new UnauthorizedAccessException("Access is not granted"); + case Interop.Feedback.FeedbackError.OperationFailed: + default: + throw new InvalidOperationException("Failed to play pattern with flag"); + } + } + } } } diff --git a/src/Tizen.System.Feedback/Interop/Interop.Feedback.cs b/src/Tizen.System.Feedback/Interop/Interop.Feedback.cs index 81fbeda..40ab92d 100644 --- a/src/Tizen.System.Feedback/Interop/Interop.Feedback.cs +++ b/src/Tizen.System.Feedback/Interop/Interop.Feedback.cs @@ -38,6 +38,12 @@ internal static partial class Interop Vibration = 2, } + internal enum FeedbackFlag + { + None = 0, + PriorityBasedPlay = 1, + } + [DllImport(Libraries.Feedback, EntryPoint = "feedback_initialize")] internal static extern int Initialize(); @@ -70,5 +76,8 @@ internal static partial class Interop [DllImport(Libraries.Feedback, EntryPoint = "feedback_get_theme_ids_internal", CallingConvention = CallingConvention.Cdecl)] internal static extern int GetThemeIdsInternal(FeedbackType type, out uint coundOfTheme, out IntPtr themeIds); + + [DllImport(Libraries.Feedback, EntryPoint = "feedback_play_type_with_flags_internal", CallingConvention = CallingConvention.Cdecl)] + internal static extern int PlayTypeWithFlagsInternal(FeedbackType type, int pattern, FeedbackFlag flag); } } -- 2.7.4