Skip to content

Commit

Permalink
[Packagemanager] Fix SetPackageManagerEventStatus (Samsung#5928)
Browse files Browse the repository at this point in the history
Since native API internally unregister event and register event
so fix it to actually set event only when necessary

Signed-off-by: Ilho Kim <[email protected]>
  • Loading branch information
ilho159kim authored Jan 31, 2024
1 parent 0ec95f9 commit 2bd4062
Showing 1 changed file with 8 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public static class PackageManager

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;
Expand Down Expand Up @@ -1396,6 +1397,9 @@ private static void RegisterPackageManagerEventIfNeeded()
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)
Expand All @@ -1407,8 +1411,11 @@ private static void RegisterPackageManagerEventIfNeeded()
}
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));
throw PackageManagerErrorFactory.GetException(err, "Failed to register package manager event.");
} else {
s_registered_eventStatus = s_eventStatus;
}
}

Expand Down Expand Up @@ -1467,6 +1474,7 @@ private static void UnregisterPackageManagerEventIfNeeded()
{
throw PackageManagerErrorFactory.GetException(err, "Failed to unregister package manager event event.");
}
s_registered_eventStatus = Interop.PackageManager.EventStatus.All;
}
}
}
Expand Down

0 comments on commit 2bd4062

Please sign in to comment.