From b85d7bd980533f60e44a862a8001f13ac2cf95d8 Mon Sep 17 00:00:00 2001 From: kilig Date: Wed, 20 Nov 2024 16:53:48 +0900 Subject: [PATCH] [Applications.Alarm] Add an internal API (#6447) Adds: - AlarmManager.CreateAlarmForServiceApp() Signed-off-by: inkyun.kil Co-authored-by: hjhun <36876573+hjhun@users.noreply.github.com> --- .../Interop/Interop.Alarm.cs | 9 ++ .../Tizen.Applications/AlarmManager.cs | 114 ++++++++++++++++++ 2 files changed, 123 insertions(+) diff --git a/src/Tizen.Applications.Alarm/Interop/Interop.Alarm.cs b/src/Tizen.Applications.Alarm/Interop/Interop.Alarm.cs index 85f7fb66c..a7adbf724 100755 --- a/src/Tizen.Applications.Alarm/Interop/Interop.Alarm.cs +++ b/src/Tizen.Applications.Alarm/Interop/Interop.Alarm.cs @@ -54,6 +54,15 @@ internal static partial class Interop [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); diff --git a/src/Tizen.Applications.Alarm/Tizen.Applications/AlarmManager.cs b/src/Tizen.Applications.Alarm/Tizen.Applications/AlarmManager.cs index cf856ec8f..007949e2f 100755 --- a/src/Tizen.Applications.Alarm/Tizen.Applications/AlarmManager.cs +++ b/src/Tizen.Applications.Alarm/Tizen.Applications/AlarmManager.cs @@ -18,6 +18,7 @@ namespace Tizen.Applications { using System; using System.Collections.Generic; + using System.ComponentModel; using System.Runtime.InteropServices; using Tizen.Applications.Notifications; @@ -439,6 +440,119 @@ namespace Tizen.Applications return CreateAlarm(delay, (int)standardPeriod, notification); } + /// + /// Sets an alarm to be triggered after a specific time. + /// The alarm will go off delay seconds later. + /// + /// The amount of time before the execution (in seconds). + /// The destination AppControl to perform a specific task when the alarm is triggered. + /// An alarm instance is created with the set param values. + /// + /// This operation only allows service application which has Background Category to set an exact alarm. + /// + /// Thrown in case of an invalid parameter. + /// Thrown in case of a permission denied. + /// Thrown in case of any internal error. + /// http://tizen.org/privilege/alarm.set + /// http://tizen.org/privilege/appmanager.launch + /// 12 + [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; + } + + /// + /// Sets an alarm to be triggered at a specific time. + /// The date describes the time of the first occurrence. + /// + /// The first active alarm time. + /// The destination AppControl to perform specific work when the alarm is triggered. + /// An alarm instance is created with the set param values. + /// + /// This operation only allows service application which has Background Category to set an exact alarm. + /// + /// Thrown in case of an invalid parameter. + /// Thrown in case of a permission denied. + /// Thrown in case of any internal error. + /// http://tizen.org/privilege/alarm.set + /// http://tizen.org/privilege/appmanager.launch + /// 12 + [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; + } + + /// + /// 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. + /// + /// The first active alarm time. + /// The amount of time between subsequent alarms (in seconds). + /// The destination AppControl is used to perform a specific task when the alarm is triggered. + /// An alarm instance is created with the set param values. + /// + /// 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. + /// + /// Thrown in case of an invalid parameter. + /// Thrown in case of a permission denied. + /// Thrown in case of any internal error. + /// http://tizen.org/privilege/alarm.set + /// http://tizen.org/privilege/appmanager.launch + /// 12 + [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; + } + /// /// Cancels all scheduled alarms that are registered by the application that calls this API. /// -- 2.34.1