protected override void OnResume()
{
base.OnResume();
- DisplayTimeoutService.Instance.IsTimeoutBlocked = true;
+ ScreenTimeoutService.Instance.IsTimeoutBlocked = true;
}
protected override void OnPause()
{
base.OnResume();
- DisplayTimeoutService.Instance.IsTimeoutBlocked = false;
+ ScreenTimeoutService.Instance.IsTimeoutBlocked = false;
}
}
}
+++ /dev/null
-namespace Fitness.Services
-{
- public sealed class DisplayTimeoutService
- {
- private const string VconfKey = "db/setting/lcd_backlight_normal";
- private const int AlwaysOnValue = 0;
-
- private static DisplayTimeoutService instance;
-
- private bool isTimeoutBlocked;
- private int systemValue;
-
- private DisplayTimeoutService()
- {
- }
-
- public static DisplayTimeoutService Instance
- {
- get
- {
- if (instance is null)
- {
- instance = new DisplayTimeoutService();
- }
-
- return instance;
- }
- }
-
- public bool IsTimeoutBlocked
- {
- get => isTimeoutBlocked;
- set
- {
- if (value == isTimeoutBlocked)
- {
- return;
- }
-
- if (value)
- {
- systemValue = Vconf.GetInt(VconfKey);
- Vconf.SetInt(VconfKey, AlwaysOnValue);
- }
- else
- {
- Vconf.SetInt(VconfKey, systemValue);
- }
-
- isTimeoutBlocked = value;
- }
- }
- }
-}
namespace Fitness.Services.Interoperability
{
- /// <summary>
- /// Interop.
- /// </summary>
internal static partial class Interop
{
- /// <summary>
- /// Vconf.
- /// </summary>
internal static partial class Vconf
{
private const string LIBRARYVCONF = "libvconf.so.0";
- /// <summary>
- /// VconfGetBool.
- /// </summary>
- /// <param name="key">key.</param>
- /// <param name="val">value.</param>
- /// <returns>int.</returns>
- [DllImport(LIBRARYVCONF, EntryPoint = "vconf_get_bool")]
- internal static extern int VconfGetBool(string key, out bool val);
-
- /// <summary>
- /// VconfSetBool.
- /// </summary>
- /// <param name="key">key.</param>
- /// <param name="intval">value.</param>
- /// <returns>int.</returns>
- [DllImport(LIBRARYVCONF, EntryPoint = "vconf_set_bool")]
- internal static extern int VconfSetBool(string key, bool intval);
-
- /// <summary>
- /// VconfGetInt.
- /// </summary>
- /// <param name="key">key.</param>
- /// <param name="val">value.</param>
- /// <returns>int.</returns>
[DllImport(LIBRARYVCONF, EntryPoint = "vconf_get_int")]
internal static extern int VconfGetInt(string key, out int val);
- /// <summary>
- /// VconfSetInt.
- /// </summary>
- /// <param name="key">key.</param>
- /// <param name="intval">value.</param>
- /// <returns>int.</returns>
[DllImport(LIBRARYVCONF, EntryPoint = "vconf_set_int")]
internal static extern int VconfSetInt(string key, int intval);
-
- /// <summary>
- /// VconfGetStr.
- /// </summary>
- /// <param name="key">key.</param>
- /// <returns>string.</returns>
- [DllImport(LIBRARYVCONF, EntryPoint = "vconf_get_str")]
- internal static extern string VconfGetStr(string key);
-
- /// <summary>
- /// VconfSetStr.
- /// </summary>
- /// <param name="key">key.</param>
- /// <param name="value">value.</param>
- /// <returns>int.</returns>
- [DllImport(LIBRARYVCONF, EntryPoint = "vconf_set_str")]
- internal static extern int VconfSetStr(string key, string value);
-
- /// <summary>
- /// VconfNotifyKeyChanged.
- /// </summary>
- /// <param name="key">key.</param>
- /// <param name="callback">callback.</param>
- /// <param name="userData">userData.</param>
- [DllImport(LIBRARYVCONF, EntryPoint = "vconf_notify_key_changed")]
- internal static extern void VconfNotifyKeyChanged(string key, NotificationCallback callback, IntPtr userData);
-
- /// <summary>
- /// VconfIgnoreKeyChanged.
- /// </summary>
- /// <param name="key">key.</param>
- /// <param name="callback">callback.</param>
- [DllImport(LIBRARYVCONF, EntryPoint = "vconf_ignore_key_changed")]
- internal static extern void VconfIgnoreKeyChanged(string key, NotificationCallback callback);
}
}
}
--- /dev/null
+namespace Fitness.Services
+{
+ public sealed class ScreenTimeoutService
+ {
+ private const string VconfKey = "db/setting/lcd_backlight_normal";
+ private const int AlwaysOnValue = 0;
+
+ private static ScreenTimeoutService instance;
+
+ private bool isTimeoutBlocked;
+ private int systemValue;
+
+ private ScreenTimeoutService()
+ {
+ }
+
+ public static ScreenTimeoutService Instance
+ {
+ get
+ {
+ if (instance is null)
+ {
+ instance = new ScreenTimeoutService();
+ }
+
+ return instance;
+ }
+ }
+
+ public bool IsTimeoutBlocked
+ {
+ get => isTimeoutBlocked;
+ set
+ {
+ if (value == isTimeoutBlocked)
+ {
+ return;
+ }
+
+ if (value)
+ {
+ systemValue = Vconf.GetInt(VconfKey);
+ Vconf.SetInt(VconfKey, AlwaysOnValue);
+ }
+ else
+ {
+ Vconf.SetInt(VconfKey, systemValue);
+ }
+
+ isTimeoutBlocked = value;
+ }
+ }
+ }
+}
/// </summary>
public static class Vconf
{
- private static readonly List<NotificationCallback> Callbacks = new List<NotificationCallback>();
-
- /// <summary>
- /// Delegate for notification callbacks.
- /// </summary>
- /// <param name="node">Pointer to event node.</param>
- /// <param name="userData">Pointer to event user data.</param>
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- public delegate void NotificationCallback(IntPtr node, IntPtr userData);
-
- /// <summary>
- /// Gets a boolean value from Vconf.
- /// </summary>
- /// <param name="key">The key in Vconf.</param>
- /// <returns>A value assigned to the specified key.</returns>
- public static bool GetBool(string key)
- {
- int errorCode = VconfGetBool(key, out bool value);
- if (errorCode != 0)
- {
- throw ExceptionFactory.GetException(errorCode);
- }
-
- return value;
- }
-
- /// <summary>
- /// Sets a boolean value in Vconf.
- /// </summary>
- /// <param name="key">The key in Vconf.</param>
- /// <param name="value">The value to be set.</param>
- public static void SetBool(string key, bool value)
- {
- int errorCode = VconfSetBool(key, value);
- if (errorCode != 0)
- {
- throw ExceptionFactory.GetException(errorCode);
- }
- }
-
/// <summary>
/// Gets an integer value from Vconf.
/// </summary>
throw ExceptionFactory.GetException(errorCode);
}
}
-
- /// <summary>
- /// Gets a string value from Vconf.
- /// </summary>
- /// <param name="key">The key in Vconf.</param>
- /// <returns>A value assigned to the specified key.</returns>
- public static string GetString(string key)
- {
- return VconfGetStr(key);
- }
-
- /// <summary>
- /// Sets a string value in Vconf.
- /// </summary>
- /// <param name="key">The key in Vconf.</param>
- /// <param name="value">The value to be set.</param>
- public static void SetString(string key, string value)
- {
- int errorCode = VconfSetStr(key, value);
- if (errorCode != 0)
- {
- throw ExceptionFactory.GetException(errorCode);
- }
- }
-
- /// <summary>
- /// Registers a callback to a KeyChanged event.
- /// </summary>
- /// <param name="key">The key to be observed for changes.</param>
- /// <param name="callback">The callback to be registered.</param>
- /// <param name="userData">Additional data.</param>
- public static void NotifyKeyChanged(string key, NotificationCallback callback, IntPtr? userData = null)
- {
- Callbacks.Add(callback);
- VconfNotifyKeyChanged(key, callback, userData ?? IntPtr.Zero);
- }
-
- /// <summary>
- /// Unregisters a callback from a KeyChanged event.
- /// </summary>
- /// <param name="key">The key that was observed for changes.</param>
- /// <param name="callback">The callback to be unregistered.</param>
- public static void IgnoreKeyChanged(string key, NotificationCallback callback)
- {
- VconfIgnoreKeyChanged(key, callback);
- Callbacks.Remove(callback);
- }
}
}