[Packagemanager] Fix SetPackageManagerEventStatus (#5929)
authorilho159kim <ilho159.kim@samsung.com>
Wed, 31 Jan 2024 09:45:41 +0000 (18:45 +0900)
committerGitHub <noreply@github.com>
Wed, 31 Jan 2024 09:45:41 +0000 (18:45 +0900)
Since native API internally unregister event and register event
so fix it to actually set event only when necessary

Signed-off-by: Ilho Kim <ilho159.kim@samsung.com>
src/Tizen.Applications.PackageManager/Tizen.Applications/PackageManager.cs

index 7305e44..f94744a 100755 (executable)
@@ -36,6 +36,7 @@ namespace Tizen.Applications
 
         private static SafePackageManagerHandle s_handle = new SafePackageManagerHandle();
         private static Interop.PackageManager.EventStatus s_eventStatus = Interop.PackageManager.EventStatus.All;
+        private static Interop.PackageManager.EventStatus s_registered_eventStatus = Interop.PackageManager.EventStatus.All;
         private static event EventHandler<PackageManagerEventArgs> s_installEventHandler;
         private static event EventHandler<PackageManagerEventArgs> s_uninstallEventHandler;
         private static event EventHandler<PackageManagerEventArgs> s_updateEventHandler;
@@ -1298,6 +1299,9 @@ namespace Tizen.Applications
             if (s_installEventHandler != null && s_uninstallEventHandler != null && s_updateEventHandler != null && s_moveEventHandler != null && s_clearDataEventHandler != null)
                 return;
 
+            if ((s_registered_eventStatus & s_eventStatus) == s_eventStatus)
+                return;
+
             var err = Interop.PackageManager.ErrorCode.None;
 
             if (!Handle.IsInvalid)
@@ -1309,7 +1313,10 @@ namespace Tizen.Applications
             }
             if (err != Interop.PackageManager.ErrorCode.None)
             {
+                s_registered_eventStatus = Interop.PackageManager.EventStatus.All;
                 Log.Warn(LogTag, string.Format("Failed to register callback for package manager event. err = {0}", err));
+            } else {
+                s_registered_eventStatus = s_eventStatus;
             }
         }
 
@@ -1368,6 +1375,7 @@ namespace Tizen.Applications
                 {
                     throw PackageManagerErrorFactory.GetException(err, "Failed to unregister package manager event event.");
                 }
+                s_registered_eventStatus = Interop.PackageManager.EventStatus.All;
             }
         }
     }