-
Notifications
You must be signed in to change notification settings - Fork 277
Fix uigadget api14 #7654
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: API14
Are you sure you want to change the base?
Fix uigadget api14 #7654
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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); | ||
| } | ||
|
Comment on lines
+72
to
+81
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If 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);
}
else
{
Log.Error("Failed to get CoreApplication instance. Event handlers will not be registered.");
} |
||
|
|
||
| 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; | ||
| } | ||
|
|
||
| /// <summary> | ||
|
|
@@ -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); | ||
| } | ||
|
Comment on lines
668
to
671
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For consistency and improved robustness, consider catching all exceptions here instead of using a specific filter. Logging the full exception object catch (Exception e)
{
Log.Error("Exception occurs while adding gadget info. packageId: " + pkg + ", " + e);
} |
||
| } | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The exception filter here is quite restrictive. To ensure the robustness intended by this pull request and prevent
TypeInitializationException, it is safer to catch all exceptions during gadget info registration, consistent with the implementation inNUIGadgetManager.cs. Additionally, logging the full exception objecteinstead of juste.Messageprovides the stack trace, which is essential for debugging.