Skip to content

Commit

Permalink
[Applications.Service] Modify ServiceCoreBackend for TimeZone Event (S…
Browse files Browse the repository at this point in the history
…amsung#5534)

This patch registers and unregister the time zone changed event.

Signed-off-by: Hwankyu Jhun <[email protected]>
  • Loading branch information
hjhun authored Sep 7, 2023
1 parent 7ee3366 commit bf08de3
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@ internal class ServiceCoreBackend : DefaultCoreBackend
private IntPtr _localeChangedEventHandle = IntPtr.Zero;
private IntPtr _regionChangedEventHandle = IntPtr.Zero;
private IntPtr _deviceOrientationChangedEventHandle = IntPtr.Zero;
private IntPtr _timeZoneChangedEventHandle = IntPtr.Zero;
private bool _disposedValue = false;
private Interop.Service.AppEventCallback _onLowMemoryNative;
private Interop.Service.AppEventCallback _onLowBatteryNative;
private Interop.Service.AppEventCallback _onLocaleChangedNative;
private Interop.Service.AppEventCallback _onRegionChangedNative;
private Interop.Service.AppEventCallback _onDeviceOrientationChangedNative;
private Interop.Service.AppEventCallback _onTimeZoneChangedNative;

public ServiceCoreBackend()
{
Expand All @@ -46,6 +48,7 @@ public ServiceCoreBackend()
_onLocaleChangedNative = new Interop.Service.AppEventCallback(OnLocaleChangedNative);
_onRegionChangedNative = new Interop.Service.AppEventCallback(OnRegionChangedNative);
_onDeviceOrientationChangedNative = new Interop.Service.AppEventCallback(OnDeviceOrientationChangedNative);
_onTimeZoneChangedNative = new Interop.Service.AppEventCallback(OnTimeZoneChangedNative);
}

public override void Exit()
Expand Down Expand Up @@ -87,6 +90,12 @@ public override void Run(string[] args)
Log.Error(LogTag, "Failed to add event handler for DeviceOrientationChanged event. Err = " + err);
}

err = Interop.Service.AddEventHandler(out _timeZoneChangedEventHandle, AppEventType.TimeZoneChanged, _onTimeZoneChangedNative, IntPtr.Zero);
if (err != ErrorCode.None)
{
Log.Error(LogTag, "Failed to add event handler for TimeZoneChanged event. Err = " + err);
}

err = Interop.Service.Main(args.Length, args, ref _callbacks, IntPtr.Zero);
if (err != ErrorCode.None)
{
Expand All @@ -107,14 +116,17 @@ protected override void Dispose(bool disposing)
{
Interop.Service.RemoveEventHandler(_lowMemoryEventHandle);
}

if (_lowBatteryEventHandle != IntPtr.Zero)
{
Interop.Service.RemoveEventHandler(_lowBatteryEventHandle);
}

if (_localeChangedEventHandle != IntPtr.Zero)
{
Interop.Service.RemoveEventHandler(_localeChangedEventHandle);
}

if (_regionChangedEventHandle != IntPtr.Zero)
{
Interop.Service.RemoveEventHandler(_regionChangedEventHandle);
Expand All @@ -125,6 +137,11 @@ protected override void Dispose(bool disposing)
Interop.Service.RemoveEventHandler(_deviceOrientationChangedEventHandle);
}

if (_timeZoneChangedEventHandle != IntPtr.Zero)
{
Interop.Service.RemoveEventHandler(_timeZoneChangedEventHandle);
}

_disposedValue = true;
}
}
Expand Down Expand Up @@ -154,10 +171,11 @@ private void OnAppControlNative(IntPtr appControlHandle, IntPtr data)
{
// Create a SafeAppControlHandle but the ownsHandle is false,
// because the appControlHandle will be closed by native appfw after this method automatically.
SafeAppControlHandle safeHandle = new SafeAppControlHandle(appControlHandle, false);

var handler = Handlers[EventType.AppControlReceived] as Action<AppControlReceivedEventArgs>;
handler?.Invoke(new AppControlReceivedEventArgs(new ReceivedAppControl(safeHandle)));
using (SafeAppControlHandle safeHandle = new SafeAppControlHandle(appControlHandle, false))
{
var handler = Handlers[EventType.AppControlReceived] as Action<AppControlReceivedEventArgs>;
handler?.Invoke(new AppControlReceivedEventArgs(new ReceivedAppControl(safeHandle)));
}
}
}

Expand Down Expand Up @@ -186,5 +204,9 @@ protected override void OnDeviceOrientationChangedNative(IntPtr infoHandle, IntP
base.OnDeviceOrientationChangedNative(infoHandle, data);
}

protected override void OnTimeZoneChangedNative(IntPtr infoHandle, IntPtr data)
{
base.OnTimeZoneChangedNative(infoHandle, data);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ public class ServiceApplication : CoreApplication
/// Initializes the ServiceApplication class.
/// </summary>
/// <since_tizen> 3 </since_tizen>
#pragma warning disable CA2000
public ServiceApplication() : base(new ServiceCoreBackend())
#pragma warning restore CA2000
{
}

Expand Down

0 comments on commit bf08de3

Please sign in to comment.