From: hjhun <36876573+hjhun@users.noreply.github.com> Date: Wed, 21 Nov 2018 02:24:01 +0000 (+0900) Subject: [Tizen.Applications.Common] Restrict concurrent access (#566) X-Git-Tag: accepted/tizen/5.0/unified/20181121.060520^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=299e4d67f36796ae8713b3e9f391cf341328fb09;p=platform%2Fcore%2Fcsapi%2Ftizenfx.git [Tizen.Applications.Common] Restrict concurrent access (#566) Signed-off-by: Hwankyu Jhun --- diff --git a/src/Tizen.Applications.Common/Tizen.Applications/ApplicationManager.cs b/src/Tizen.Applications.Common/Tizen.Applications/ApplicationManager.cs index 719a5ed..41caa28 100755 --- a/src/Tizen.Applications.Common/Tizen.Applications/ApplicationManager.cs +++ b/src/Tizen.Applications.Common/Tizen.Applications/ApplicationManager.cs @@ -32,10 +32,12 @@ namespace Tizen.Applications private static EventHandler s_launchedHandler; private static EventHandler s_terminatedHandler; private static Interop.ApplicationManager.AppManagerAppContextEventCallback s_applicationChangedEventCallback; - private static EventHandler _enabledHandler; - private static EventHandler _disabledHandler; - private static Interop.ApplicationManager.AppManagerEventCallback _eventCallback; + private static EventHandler s_enabledHandler; + private static EventHandler s_disabledHandler; + private static Interop.ApplicationManager.AppManagerEventCallback s_eventCallback; private static IntPtr _eventHandle = IntPtr.Zero; + private static readonly object s_eventLock = new object(); + private static readonly object s_applicationChangedEventLock = new object(); /// /// Occurs whenever the installed application is enabled. @@ -45,18 +47,25 @@ namespace Tizen.Applications { add { - if (_enabledHandler == null && _disabledHandler == null) + lock (s_eventLock) { - RegisterApplicationEvent(); + if (s_eventCallback == null) + { + RegisterApplicationEvent(); + } + s_enabledHandler += value; } - _enabledHandler += value; } remove { - _enabledHandler -= value; - if (_enabledHandler == null && _disabledHandler == null) + lock (s_eventLock) { - UnRegisterApplicationEvent(); + s_enabledHandler -= value; + if (s_enabledHandler == null && s_disabledHandler == null && s_eventCallback != null) + { + UnRegisterApplicationEvent(); + s_eventCallback = null; + } } } } @@ -69,18 +78,25 @@ namespace Tizen.Applications { add { - if (_disabledHandler == null && _enabledHandler == null) + lock (s_eventLock) { - RegisterApplicationEvent(); + if (s_eventCallback == null) + { + RegisterApplicationEvent(); + } + s_disabledHandler += value; } - _disabledHandler += value; } remove { - _disabledHandler -= value; - if (_disabledHandler == null && _enabledHandler == null) + lock (s_eventLock) { - UnRegisterApplicationEvent(); + s_disabledHandler -= value; + if (s_enabledHandler == null && s_disabledHandler == null && s_eventCallback != null) + { + UnRegisterApplicationEvent(); + s_eventCallback = null; + } } } } @@ -93,18 +109,25 @@ namespace Tizen.Applications { add { - if (s_launchedHandler == null && s_terminatedHandler == null) + lock (s_applicationChangedEventLock) { - RegisterApplicationChangedEvent(); + if (s_applicationChangedEventCallback == null) + { + RegisterApplicationChangedEvent(); + } + s_launchedHandler += value; } - s_launchedHandler += value; } remove { - s_launchedHandler -= value; - if (s_launchedHandler == null && s_terminatedHandler == null) + lock (s_applicationChangedEventLock) { - UnRegisterApplicationChangedEvent(); + s_launchedHandler -= value; + if (s_launchedHandler == null && s_terminatedHandler == null && s_applicationChangedEventCallback != null) + { + UnRegisterApplicationChangedEvent(); + s_applicationChangedEventCallback = null; + } } } } @@ -117,18 +140,25 @@ namespace Tizen.Applications { add { - if (s_launchedHandler == null && s_terminatedHandler == null) + lock (s_applicationChangedEventLock) { - RegisterApplicationChangedEvent(); + if (s_applicationChangedEventCallback == null) + { + RegisterApplicationChangedEvent(); + } + s_terminatedHandler += value; } - s_terminatedHandler += value; } remove { - s_terminatedHandler -= value; - if (s_launchedHandler == null && s_terminatedHandler == null) + lock (s_applicationChangedEventLock) { - UnRegisterApplicationChangedEvent(); + s_terminatedHandler -= value; + if (s_launchedHandler == null && s_terminatedHandler == null && s_applicationChangedEventCallback != null) + { + UnRegisterApplicationChangedEvent(); + s_applicationChangedEventCallback = null; + } } } } @@ -401,18 +431,18 @@ namespace Tizen.Applications throw ApplicationManagerErrorFactory.GetException(err, "Failed to set the application event"); } - _eventCallback = (string appType, string appId, Interop.ApplicationManager.AppManagerEventType eventType, Interop.ApplicationManager.AppManagerEventState eventState, IntPtr eventHandle, IntPtr UserData) => + s_eventCallback = (string appType, string appId, Interop.ApplicationManager.AppManagerEventType eventType, Interop.ApplicationManager.AppManagerEventState eventState, IntPtr eventHandle, IntPtr UserData) => { if (eventType == Interop.ApplicationManager.AppManagerEventType.Enable) { - _enabledHandler?.Invoke(null, new ApplicationEnabledEventArgs(appId, (ApplicationEventState)eventState)); + s_enabledHandler?.Invoke(null, new ApplicationEnabledEventArgs(appId, (ApplicationEventState)eventState)); } else if (eventType == Interop.ApplicationManager.AppManagerEventType.Disable) { - _disabledHandler?.Invoke(null, new ApplicationDisabledEventArgs(appId, (ApplicationEventState)eventState)); + s_disabledHandler?.Invoke(null, new ApplicationDisabledEventArgs(appId, (ApplicationEventState)eventState)); } }; - err = Interop.ApplicationManager.AppManagerSetEventCallback(_eventHandle, _eventCallback, IntPtr.Zero); + err = Interop.ApplicationManager.AppManagerSetEventCallback(_eventHandle, s_eventCallback, IntPtr.Zero); if (err != Interop.ApplicationManager.ErrorCode.None) { Interop.ApplicationManager.AppManagerEventDestroy(_eventHandle);