[Applications.Alarm] Add an internal API (#6447)
authorkilig <inkyun.kil@samsung.com>
Wed, 20 Nov 2024 07:53:48 +0000 (16:53 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Wed, 27 Nov 2024 05:00:21 +0000 (14:00 +0900)
Adds:
 - AlarmManager.CreateAlarmForServiceApp()

Signed-off-by: inkyun.kil <inkyun.kil@samsung.com>
Co-authored-by: hjhun <36876573+hjhun@users.noreply.github.com>
src/Tizen.Applications.Alarm/Interop/Interop.Alarm.cs
src/Tizen.Applications.Alarm/Tizen.Applications/AlarmManager.cs

index 85f7fb66c121bc3ef580a4cebfaa9b73b76a32e5..a7adbf724f631e171783cfc80d02e4496bcb219b 100755 (executable)
@@ -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);
 
index cf856ec8f46c73256ea862d8b2d78fbbd79b5fd1..007949e2f98f61436be9b72505cb1e6f2e0160bc 100755 (executable)
@@ -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);
         }
 
+        /// <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>