[Applications.UI] Modify UICoreBackend for time zone event (#5542)
authorhjhun <36876573+hjhun@users.noreply.github.com>
Fri, 8 Sep 2023 08:09:54 +0000 (17:09 +0900)
committerGitHub <noreply@github.com>
Fri, 8 Sep 2023 08:09:54 +0000 (17:09 +0900)
This patch registers and unregister the time zone changed event.

Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
src/Tizen.Applications.UI/Tizen.Applications.CoreBackend/UICoreBackend.cs
src/Tizen.Applications.UI/Tizen.Applications/CoreUIApplication.cs

index 933a4e0..c8f02bd 100755 (executable)
@@ -28,12 +28,14 @@ namespace Tizen.Applications.CoreBackend
         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.Application.AppEventCallback _onLowMemoryNative;
         private Interop.Application.AppEventCallback _onLowBatteryNative;
         private Interop.Application.AppEventCallback _onLocaleChangedNative;
         private Interop.Application.AppEventCallback _onRegionChangedNative;
         private Interop.Application.AppEventCallback _onDeviceOrientationChangedNative;
+        private Interop.Application.AppEventCallback _onTimeZoneChangedNative;
 
         public UICoreBackend()
         {
@@ -48,6 +50,7 @@ namespace Tizen.Applications.CoreBackend
             _onLocaleChangedNative = new Interop.Application.AppEventCallback(OnLocaleChangedNative);
             _onRegionChangedNative = new Interop.Application.AppEventCallback(OnRegionChangedNative);
             _onDeviceOrientationChangedNative = new Interop.Application.AppEventCallback(OnDeviceOrientationChangedNative);
+            _onTimeZoneChangedNative = new Interop.Application.AppEventCallback(OnTimeZoneChangedNative);
         }
 
         public override void Exit()
@@ -89,6 +92,12 @@ namespace Tizen.Applications.CoreBackend
                 Log.Error(LogTag, "Failed to add event handler for DeviceOrientationChanged event. Err = " + err);
             }
 
+            err = Interop.Application.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.Application.Main(args.Length, args, ref _callbacks, IntPtr.Zero);
             if (err != ErrorCode.None)
             {
@@ -125,6 +134,10 @@ namespace Tizen.Applications.CoreBackend
                 {
                     Interop.Application.RemoveEventHandler(_deviceOrientationChangedEventHandle);
                 }
+                if (_timeZoneChangedEventHandle != IntPtr.Zero)
+                {
+                    Interop.Application.RemoveEventHandler(_timeZoneChangedEventHandle);
+                }
 
                 _disposedValue = true;
             }
@@ -161,8 +174,7 @@ namespace Tizen.Applications.CoreBackend
             {
                 // 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);
-
+                using SafeAppControlHandle safeHandle = new SafeAppControlHandle(appControlHandle, false);
                 var handler = Handlers[EventType.AppControlReceived] as Action<AppControlReceivedEventArgs>;
                 handler?.Invoke(new AppControlReceivedEventArgs(new ReceivedAppControl(safeHandle)));
             }
@@ -210,5 +222,10 @@ namespace Tizen.Applications.CoreBackend
         {
             base.OnDeviceOrientationChangedNative(infoHandle, data);
         }
+
+        protected override void OnTimeZoneChangedNative(IntPtr infoHandle, IntPtr data)
+        {
+            base.OnTimeZoneChangedNative(infoHandle, data);
+        }
     }
 }
index 6002da2..7fb0608 100755 (executable)
@@ -35,7 +35,9 @@ namespace Tizen.Applications
         /// The default backend for the UI application will be used.
         /// </remarks>
         /// <since_tizen> 3 </since_tizen>
+#pragma warning disable CA2000
         public CoreUIApplication() : base(new UICoreBackend())
+#pragma warning restore CA2000
         {
         }