[Notification] Add PairingType for do not disturb app (#6391)
authorsukhyungkang <35091460+sukhyungkang@users.noreply.github.com>
Mon, 7 Oct 2024 00:48:31 +0000 (09:48 +0900)
committerGitHub <noreply@github.com>
Mon, 7 Oct 2024 00:48:31 +0000 (09:48 +0900)
Signed-off-by: SukhyungKang <shine.kang@samsung.com>
Co-authored-by: pjh9216 <jh9216.park@samsung.com>
src/Tizen.Applications.Notification/Interop/Interop.Notification.cs
src/Tizen.Applications.Notification/Tizen.Applications.Notifications/Notification.cs
src/Tizen.Applications.Notification/Tizen.Applications.Notifications/NotificationBinder.cs
src/Tizen.Applications.Notification/Tizen.Applications.Notifications/NotificationManager.cs

index 44e6f7e6e19b82e3146b64f1d350c790e279fa3f..46988c4ce1df3205fba4b110fea52162ea1ea74b 100644 (file)
@@ -238,6 +238,21 @@ internal static partial class Interop
         [DllImport(Libraries.Notification, EntryPoint = "notification_get_check_box")]
         internal static extern NotificationError GetCheckBox(NotificationSafeHandle handle, out bool flag, out bool checkedValue);
 
+        /* apis for do not disturb app */
+        internal delegate void DisturbCallback(IntPtr userData);
+
+        [DllImport(Libraries.Notification, EntryPoint = "notification_register_do_not_disturb_app")]
+        internal static extern NotificationError RegisterDndApp(DisturbCallback cb, IntPtr userData);
+
+        [DllImport(Libraries.Notification, EntryPoint = "notification_unregister_do_not_disturb_app")]
+        internal static extern NotificationError UnRegisterDndApp();
+
+        [DllImport(Libraries.Notification, EntryPoint = "notification_set_pairing_type")]
+        internal static extern NotificationError SetPairingType(NotificationSafeHandle handle, bool pairing);
+
+        [DllImport(Libraries.Notification, EntryPoint = "notification_get_pairing_type")]
+        internal static extern NotificationError GetPairingType(NotificationSafeHandle handle, out bool pairing);
+
         internal static NotificationError GetText(NotificationSafeHandle handle, NotificationText type, out string text)
         {
             NotificationError ret;
index 019ea0a9a7e7e918a52dfbe0155e4b8ae6765b2f..e5b573b2bd0dbf89325165f8e6f840a79c6222c0 100755 (executable)
@@ -212,6 +212,9 @@ namespace Tizen.Applications.Notifications
         [EditorBrowsable(EditorBrowsableState.Never)]
         public bool CheckedValue { get; set; } = false;
 
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public bool PairingType { get; set; } = false;
+
         /// <summary>
         /// Gets or sets NotificationSafeHandle.
         /// </summary>
index b847e6917a30bc9e5f5ae0ed0066cc988a2d06ab..750914b164ed2cf3084bdb9edda7f743706734e7 100755 (executable)
@@ -62,6 +62,11 @@ namespace Tizen.Applications.Notifications
             {
                 Interop.Notification.SetCheckBox(notification.Handle, notification.CheckBox, notification.CheckedValue);
             }
+
+            if (notification.PairingType == true)
+            {
+                Interop.Notification.SetPairingType(notification.Handle, notification.PairingType);
+            }
         }
 
         internal static void BindSafeHandle(Notification notification)
@@ -91,6 +96,7 @@ namespace Tizen.Applications.Notifications
             BindSafeHandleTag(notification);
             BindSafeHandleAction(notification);
             BindSafeHandleCheckBox(notification);
+            BindSafeHandlePairingType(notification);
         }
 
         private static void BindNotificationSafeHandle(Notification notification)
@@ -250,5 +256,18 @@ namespace Tizen.Applications.Notifications
             notification.CheckBox = checkbox;
             notification.CheckedValue = checkedValue;
         }
+
+        private static void BindSafeHandlePairingType(Notification notification)
+        {
+            NotificationError ret;
+            bool pairingType= false;
+
+            ret = Interop.Notification.GetPairingType(notification.Handle, out pairingType);
+            if (ret != NotificationError.None) {
+                Log.Error(Notification.LogTag, "Failed to get paring type info");
+            }
+
+            notification.PairingType = pairingType;
+        }
     }
 }
index aadca4ec6b983a9cda91d82f6f5ec8e7c8f83fc1..2474f7b97a091d1e03ab00ee1f18c8ab02ce30ac 100644 (file)
@@ -29,6 +29,10 @@ namespace Tizen.Applications.Notifications
 
         private static Interop.Notification.ResponseEventCallback responseEventCallback;
 
+        // for disturb app
+        private static event EventHandler ResponseDisturbHandler;
+        private static Interop.Notification.DisturbCallback disturbCallback;
+
         private static void ResponseEventCallback(IntPtr ptr, int type, IntPtr userData)
         {
             IntPtr cloned;
@@ -48,6 +52,12 @@ namespace Tizen.Applications.Notifications
             ResponseEventHandler?.Invoke(null, eventArgs);
         }
 
+        // for disturb app
+        private static void DisturbCallback(IntPtr userData)
+        {
+            ResponseDisturbHandler?.Invoke(null, EventArgs.Empty);
+        }
+
         /// <summary> 
         /// The event handler for receiving a response event from the notification viewers
         /// </summary>
@@ -559,5 +569,56 @@ namespace Tizen.Applications.Notifications
 
             return notification;
         }
+
+        /// <summary>
+        /// The event handler to get
+        /// </summary>
+        /// <since_tizen> 12 </since_tizen>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public static event EventHandler DisturbReceived
+        {
+            add
+            {
+                if (disturbCallback == null)
+                {
+                    disturbCallback = new Interop.Notification.DisturbCallback(DisturbCallback);
+                }
+
+                ResponseDisturbHandler += value;
+            }
+
+            remove
+            {
+                if (ResponseDisturbHandler != null && ResponseDisturbHandler.GetInvocationList().Length > 0)
+                {
+                    NotificationError ret = Interop.Notification.UnRegisterDndApp();
+                    if (ret != NotificationError.None)
+                    {
+                        throw NotificationErrorFactory.GetException(ret, "register do not disturb app failed");
+                    }
+
+                    ResponseDisturbHandler -= value;
+                }
+            }
+        }
+
+        /// <summary>
+        /// Register do not disturb app
+        /// </summary>
+        /// <since_tizen> 12 </since_tizen>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public static void RegisterDoNotDisturbApp()
+        {
+            if (ResponseDisturbHandler != null && ResponseDisturbHandler.GetInvocationList().Length > 0)
+            {
+                NotificationError ret = Interop.Notification.RegisterDndApp(disturbCallback, IntPtr.Zero);
+                if (ret != NotificationError.None)
+                {
+                    throw NotificationErrorFactory.GetException(ret, "register do not disturb app failed");
+                }
+            } else {
+                throw NotificationErrorFactory.GetException(NotificationError.InvalidOperation, "Disturb callback not exist");
+            }
+        }
     }
 }