diff --git a/src/Tizen.Applications.UIGadget/Tizen.Applications/UIGadgetInfo.cs b/src/Tizen.Applications.UIGadget/Tizen.Applications/UIGadgetInfo.cs index 0c76d05481c..eedddd8e039 100755 --- a/src/Tizen.Applications.UIGadget/Tizen.Applications/UIGadgetInfo.cs +++ b/src/Tizen.Applications.UIGadget/Tizen.Applications/UIGadgetInfo.cs @@ -1,4 +1,4 @@ -/* +/* * Copyright (c) 2025 Samsung Electronics Co., Ltd All Rights Reserved * * Licensed under the Apache License, Version 2.0 (the License); @@ -222,31 +222,45 @@ private static void SetResourceType(UIGadgetInfo info, IntPtr handle) internal static UIGadgetInfo CreateUIGadgetInfo(string packageId) { - Interop.PackageManagerInfo.ErrorCode errorCode = Interop.PackageManagerInfo.PackageInfoGet(packageId, out IntPtr handle); - if (errorCode != Interop.PackageManagerInfo.ErrorCode.None) + IntPtr handle = IntPtr.Zero; + try { - Log.Error("Failed to get package info. error = " + errorCode); - return null; - } + Interop.PackageManagerInfo.ErrorCode errorCode = Interop.PackageManagerInfo.PackageInfoGet(packageId, out handle); + if (errorCode != Interop.PackageManagerInfo.ErrorCode.None) + { + Log.Error("Failed to get package info. packageId: " + packageId + ", error = " + errorCode); + return null; + } - UIGadgetInfo info = new UIGadgetInfo(packageId); + UIGadgetInfo info = new UIGadgetInfo(packageId); - SetResourceType(info, handle); - SetResourceVersion(info, handle); - SetMetadata(info, handle); + SetResourceType(info, handle); + SetResourceVersion(info, handle); + SetMetadata(info, handle); - errorCode = Interop.PackageManagerInfo.PackageInfoDestroy(handle); - if (errorCode != Interop.PackageManagerInfo.ErrorCode.None) + SetExecutableFile(info); + SetResourceFile(info); + SetResourceClassName(info); + SetResourcePath(info); + SetUIGadgetResourcePath(info); + return info; + } + catch (Exception e) { - Log.Warn("Failed to destroy package info. error = " + errorCode); + Log.Error("Exception occurred while creating UIGadgetInfo. packageId: " + packageId + ", exception: " + e); + return null; + } + finally + { + if (handle != IntPtr.Zero) + { + Interop.PackageManagerInfo.ErrorCode errorCode = Interop.PackageManagerInfo.PackageInfoDestroy(handle); + if (errorCode != Interop.PackageManagerInfo.ErrorCode.None) + { + Log.Warn("Failed to destroy package info. error = " + errorCode); + } + } } - - SetExecutableFile(info); - SetResourceFile(info); - SetResourceClassName(info); - SetResourcePath(info); - SetUIGadgetResourcePath(info); - return info; } } } diff --git a/src/Tizen.Applications.UIGadget/Tizen.Applications/UIGadgetManager.cs b/src/Tizen.Applications.UIGadget/Tizen.Applications/UIGadgetManager.cs index 95d3c6e8dfd..b1cf0bac3ed 100755 --- a/src/Tizen.Applications.UIGadget/Tizen.Applications/UIGadgetManager.cs +++ b/src/Tizen.Applications.UIGadget/Tizen.Applications/UIGadgetManager.cs @@ -1,4 +1,4 @@ -/* +/* * Copyright (c) 2025 Samsung Electronics Co., Ltd All Rights Reserved * * Licensed under the Apache License, Version 2.0 (the License); @@ -39,43 +39,53 @@ public static class UIGadgetManager static UIGadgetManager() { - var ptr = Interop.Libc.GetEnvironmentVariable("GADGET_PKGIDS"); - if (ptr != IntPtr.Zero) + try { - var packages = Marshal.PtrToStringAnsi(ptr); - if (!string.IsNullOrWhiteSpace(packages)) + var ptr = Interop.Libc.GetEnvironmentVariable("GADGET_PKGIDS"); + if (ptr != IntPtr.Zero) { - foreach (var pkg in packages.Split(':')) + var packages = Marshal.PtrToStringAnsi(ptr); + if (!string.IsNullOrWhiteSpace(packages)) { - var info = UIGadgetInfo.CreateUIGadgetInfo(pkg); - if (info != null) + foreach (var pkg in packages.Split(':')) { - try - { - _gadgetInfos.TryAdd(info.ResourceType, info); - } - catch (Exception e) when (e is ArgumentNullException || e is OverflowException) + var info = UIGadgetInfo.CreateUIGadgetInfo(pkg); + if (info != null) { - Log.Error("Exception occurs. " + e.Message); + try + { + _gadgetInfos.TryAdd(info.ResourceType, info); + } + catch (Exception e) when (e is ArgumentNullException || e is OverflowException) + { + Log.Error("Exception occurs while adding gadget info. packageId: " + pkg + ", " + e.Message); + } } } } } + else + { + Log.Warn("Failed to get environment variable"); + } + + var app = CoreApplication.Current as CoreApplication; + if (app != null) + { + app.AppControlReceived += (s, e) => HandleAppControl(e); + app.LowMemory += (s, e) => HandleLowMemoryEvent(e); + app.LowBattery += (s, e) => HandleLowBatteryEvent(e); + app.LocaleChanged += (s, e) => HandleLocaleChangedEvent(e); + app.RegionFormatChanged += (s, e) => HandleRegionFormatChangedEvent(e); + app.DeviceOrientationChanged += (s, e) => HandleDeviceOrientationChangedEvent(e); + } + + UIGadgetLifecycleEventBroker.LifecycleChanged += OnUIGadgetLifecycleChanged; } - else + catch (Exception e) { - Log.Warn("Failed to get environment variable"); + Log.Error("Exception occurs in UIGadgetManager static constructor. " + e); } - - var app = (CoreApplication)CoreApplication.Current; - app.AppControlReceived += (s, e) => HandleAppControl(e); - app.LowMemory += (s, e) => HandleLowMemoryEvent(e); - app.LowBattery += (s, e) => HandleLowBatteryEvent(e); - app.LocaleChanged += (s, e) => HandleLocaleChangedEvent(e); - app.RegionFormatChanged += (s, e) => HandleRegionFormatChangedEvent(e); - app.DeviceOrientationChanged += (s, e) => HandleDeviceOrientationChangedEvent(e); - - UIGadgetLifecycleEventBroker.LifecycleChanged += OnUIGadgetLifecycleChanged; } /// @@ -657,7 +667,7 @@ public static void Refresh() } catch (Exception e) when (e is ArgumentNullException || e is OverflowException) { - Log.Error("Exception occurs. " + e.Message); + Log.Error("Exception occurs while adding gadget info. packageId: " + pkg + ", " + e.Message); } } } diff --git a/src/Tizen.NUI.Gadget/Tizen.NUI/NUIGadgetManager.cs b/src/Tizen.NUI.Gadget/Tizen.NUI/NUIGadgetManager.cs index a960980ff37..fcbdf9e5ebb 100755 --- a/src/Tizen.NUI.Gadget/Tizen.NUI/NUIGadgetManager.cs +++ b/src/Tizen.NUI.Gadget/Tizen.NUI/NUIGadgetManager.cs @@ -1,4 +1,4 @@ -/* +/* * Copyright (c) 2023 Samsung Electronics Co., Ltd All Rights Reserved * * Licensed under the Apache License, Version 2.0 (the License); @@ -36,26 +36,37 @@ public static class NUIGadgetManager static NUIGadgetManager() { - LoadGadgetInfos(); - UIGadgetLifecycleEventBroker.LifecycleChanged += OnUIGadgetLifecycleChanged; + try + { + LoadGadgetInfos(); + UIGadgetLifecycleEventBroker.LifecycleChanged += OnUIGadgetLifecycleChanged; + } + catch (Exception e) + { + Log.Error("Exception occurs in NUIGadgetManager static constructor. " + e); + } } private static void LoadGadgetInfos() { - foreach (var info in UIGadgetManager.GetUIGadgetInfos()) + try { - try + foreach (var info in UIGadgetManager.GetUIGadgetInfos()) { - var gadgetInfo = new NUIGadgetInfo(info); - if (gadgetInfo != null) + try { + var gadgetInfo = new NUIGadgetInfo(info); _gadgetInfos.TryAdd(gadgetInfo.ResourceType, gadgetInfo); } + catch (Exception e) + { + Log.Error("Exception occurs while creating NUIGadgetInfo. packageId: " + info.PackageId + ", " + e); + } } - catch (Exception e) when (e is ArgumentNullException || e is OverflowException) - { - Log.Error("Exception occurs. " + e.Message); - } + } + catch (Exception e) + { + Log.Error("Exception occurs in LoadGadgetInfos. " + e); } } @@ -561,10 +572,17 @@ public static void SendMessage(Bundle message) /// 13 public static void Refresh() { - UIGadgetManager.Refresh(); - _gadgetInfos.Clear(); - LoadGadgetInfos(); - Log.Info("# of Gadget after refresh (" + _gadgetInfos.Count + ")"); + try + { + UIGadgetManager.Refresh(); + _gadgetInfos.Clear(); + LoadGadgetInfos(); + Log.Info("# of Gadget after refresh (" + _gadgetInfos.Count + ")"); + } + catch (Exception e) + { + Log.Error("Exception occurs in NUIGadgetManager.Refresh. " + e); + } } } }