Skip to content

Commit

Permalink
[Applications.Alarm] Add an internal API
Browse files Browse the repository at this point in the history
Adds:
 - AlarmManager.CreateAlarmForServiceApp()

Signed-off-by: inkyun.kil <[email protected]>
  • Loading branch information
kilig committed Nov 20, 2024
1 parent 8f4beb0 commit defbef7
Show file tree
Hide file tree
Showing 2 changed files with 123 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/Tizen.Applications.Alarm/Interop/Interop.Alarm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,15 @@ internal struct DateTime
[DllImport(Libraries.Alarm, EntryPoint = "alarm_schedule_with_recurrence_week_flag")]
internal static extern int CreateAlarmRecurWeek(SafeAppControlHandle appControl, ref DateTime date, int week, out int alarmId);

[DllImport(Libraries.Alarm, EntryPoint = "alarm_schedule_service_with_recurrence_seconds")]
internal static extern int CreateAlarmRecurForService(SafeAppControlHandle appControl, ref DateTime date, int period, out int alarmId);

[DllImport(Libraries.Alarm, EntryPoint = "alarm_schedule_service_once_after_delay")]
internal static extern int CreateAlarmOnceAfterDelayForService(SafeAppControlHandle appControl, int delay, out int alarmId);

[DllImport(Libraries.Alarm, EntryPoint = "alarm_schedule_service_once_at_date")]
internal static extern int CreateAlarmOnceAtDateForService(SafeAppControlHandle appControl, ref DateTime date, out int alarmId);

[DllImport(Libraries.Alarm, EntryPoint = "alarm_get_scheduled_recurrence_week_flag")]
internal static extern int GetAlarmWeekFlag(int alarmId, out int weekFlag);

Expand Down
114 changes: 114 additions & 0 deletions src/Tizen.Applications.Alarm/Tizen.Applications/AlarmManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ namespace Tizen.Applications
{
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Runtime.InteropServices;
using Tizen.Applications.Notifications;

Expand Down Expand Up @@ -438,6 +439,119 @@ public static Alarm CreateAlarm(int delay, AlarmStandardPeriod standardPeriod, N
return CreateAlarm(delay, (int)standardPeriod, notification);
}

/// <summary>
/// Sets an alarm to be triggered after a specific time.
/// The alarm will go off delay seconds later.
/// </summary>
/// <param name="delay"> The amount of time before the execution (in seconds). </param>
/// <param name="appControl"> The destination AppControl to perform a specific task when the alarm is triggered. </param>
/// <returns> An alarm instance is created with the set param values.</returns>
/// <remarks>
/// This operation only allows service application which has Background Category to set an exact alarm.
/// </remarks>
/// <exception cref="ArgumentException">Thrown in case of an invalid parameter.</exception>
/// <exception cref="UnauthorizedAccessException">Thrown in case of a permission denied.</exception>
/// <exception cref="InvalidOperationException">Thrown in case of any internal error.</exception>
/// <privilege>http://tizen.org/privilege/alarm.set</privilege>
/// <privilege>http://tizen.org/privilege/appmanager.launch</privilege>
/// <since_tizen> 12 </since_tizen>
[EditorBrowsable(EditorBrowsableState.Never)]
public static Alarm CreateAlarmForServiceApp(int delay, AppControl appControl)
{
if (appControl == null)
{
throw AlarmErrorFactory.GetException(AlarmError.InvalidParameter, "AppControl should be not null");
}

Alarm alarm = null;
int alarmId;
AlarmError ret = (AlarmError)Interop.Alarm.CreateAlarmOnceAfterDelayForService(appControl.SafeAppControlHandle, delay, out alarmId);
alarm = new Alarm(alarmId);
if (ret != AlarmError.None)
{
throw AlarmErrorFactory.GetException(ret, "Failed to create Alarm");
}

return alarm;
}

/// <summary>
/// Sets an alarm to be triggered at a specific time.
/// The date describes the time of the first occurrence.
/// </summary>
/// <param name="value"> The first active alarm time. </param>
/// <param name="appControl"> The destination AppControl to perform specific work when the alarm is triggered. </param>
/// <returns> An alarm instance is created with the set param values.</returns>
/// <remarks>
/// This operation only allows service application which has Background Category to set an exact alarm.
/// </remarks>
/// <exception cref="ArgumentException">Thrown in case of an invalid parameter.</exception>
/// <exception cref="UnauthorizedAccessException">Thrown in case of a permission denied.</exception>
/// <exception cref="InvalidOperationException">Thrown in case of any internal error.</exception>
/// <privilege>http://tizen.org/privilege/alarm.set</privilege>
/// <privilege>http://tizen.org/privilege/appmanager.launch</privilege>
/// <since_tizen> 12 </since_tizen>
[EditorBrowsable(EditorBrowsableState.Never)]
public static Alarm CreateAlarmForServiceApp(DateTime value, AppControl appControl)
{
if (appControl == null)
{
throw AlarmErrorFactory.GetException(AlarmError.InvalidParameter, "AppControl should be not null");
}

Alarm alarm = null;
int alarmId;
Interop.Alarm.DateTime time = ConvertDateTimeToStruct(value);
AlarmError ret = (AlarmError)Interop.Alarm.CreateAlarmOnceAtDateForService(appControl.SafeAppControlHandle, ref time, out alarmId);
alarm = new Alarm(alarmId);
if (ret != AlarmError.None)
{
throw AlarmErrorFactory.GetException(ret, "Failed to create Alarm");
}

return alarm;
}

/// <summary>
/// Sets an alarm to be triggered at a specific time.
/// The alarm will first go off at a specific time and then will go off every certain amount of time defined using period seconds.
/// </summary>
/// <param name="value"> The first active alarm time. </param>
/// <param name="period"> The amount of time between subsequent alarms (in seconds).</param>
/// <param name="appControl"> The destination AppControl is used to perform a specific task when the alarm is triggered. </param>
/// <returns> An alarm instance is created with the set param values.</returns>
/// <remarks>
/// This operation only allows service application which has Background Category to set an exact alarm.
/// This API can have a significant impact on power usage when the device is in idle state, so apps that use it may greatly increase battery consumption.
/// Therefore, caution should be taken when using this API.
/// </remarks>
/// <exception cref="ArgumentException">Thrown in case of an invalid parameter.</exception>
/// <exception cref="UnauthorizedAccessException">Thrown in case of a permission denied.</exception>
/// <exception cref="InvalidOperationException">Thrown in case of any internal error.</exception>
/// <privilege>http://tizen.org/privilege/alarm.set</privilege>
/// <privilege>http://tizen.org/privilege/appmanager.launch</privilege>
/// <since_tizen> 12 </since_tizen>
[EditorBrowsable(EditorBrowsableState.Never)]
public static Alarm CreateAlarmForServiceApp(DateTime value, int period, AppControl appControl)
{
if (appControl == null)
{
throw AlarmErrorFactory.GetException(AlarmError.InvalidParameter, "AppControl should be not null");
}

Alarm alarm = null;
int alarmId;
Interop.Alarm.DateTime time = ConvertDateTimeToStruct(value);
AlarmError ret = (AlarmError)Interop.Alarm.CreateAlarmRecurForService(appControl.SafeAppControlHandle, ref time, period, out alarmId);
alarm = new Alarm(alarmId);
if (ret != AlarmError.None)
{
throw AlarmErrorFactory.GetException(ret, "Failed to create Alarm");
}

return alarm;
}

/// <summary>
/// Cancels all scheduled alarms that are registered by the application that calls this API.
/// </summary>
Expand Down

0 comments on commit defbef7

Please sign in to comment.