Skip to content
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

[Notification] Add PairingType for do not disturb app #6391

Merged
merged 2 commits into from
Oct 7, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,21 @@ internal static class Notification
[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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,9 @@ public int Count
[EditorBrowsable(EditorBrowsableState.Never)]
public bool CheckedValue { get; set; } = false;

[EditorBrowsable(EditorBrowsableState.Never)]
public bool PairingType { get; set; } = false;

/// <summary>
/// Gets or sets NotificationSafeHandle.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ internal static void BindObject(Notification notification)
{
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)
Expand Down Expand Up @@ -91,6 +96,7 @@ internal static void BindSafeHandle(Notification notification)
BindSafeHandleTag(notification);
BindSafeHandleAction(notification);
BindSafeHandleCheckBox(notification);
BindSafeHandlePairingType(notification);
}

private static void BindNotificationSafeHandle(Notification notification)
Expand Down Expand Up @@ -250,5 +256,18 @@ private static void BindSafeHandleCheckBox(Notification notification)
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;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ public static class NotificationManager

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;
Expand All @@ -48,6 +52,12 @@ private static void ResponseEventCallback(IntPtr ptr, int type, IntPtr userData)
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>
Expand Down Expand Up @@ -559,5 +569,56 @@ public static Notification MakeNotification(NotificationSafeHandle handle)

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");
}
}
}
}
Loading