diff options
author | Hwankyu Jhun <h.jhun@samsung.com> | 2017-03-13 15:52:42 +0900 |
---|---|---|
committer | HwanKyu Jhun <h.jhun@samsung.com> | 2017-03-15 21:37:54 -0700 |
commit | ca407297009b0d5c1f3459fd66084bb7d936621c (patch) | |
tree | 475d4f9175e75120871868505ac9685d36e6ce6c | |
parent | 63c03d6665a955b276c2163eb407adf44048640e (diff) | |
download | application-ca407297009b0d5c1f3459fd66084bb7d936621c.tar.gz application-ca407297009b0d5c1f3459fd66084bb7d936621c.tar.bz2 application-ca407297009b0d5c1f3459fd66084bb7d936621c.zip |
Add new APIs
- Add ApplicationEnabled
- Add ApplicationDisabled
- The event handler is called when the application is enabled or
disabled.
Change-Id: I4da9a6d49660168fcca016a9504ad4be344bdac4
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
-rwxr-xr-x[-rw-r--r--] | Tizen.Applications.Common/Interop/Interop.ApplicationManager.cs | 45 | ||||
-rw-r--r--[-rwxr-xr-x] | Tizen.Applications.Common/Tizen.Applications.Common.csproj | 3 | ||||
-rw-r--r-- | Tizen.Applications.Common/Tizen.Applications/ApplicationDisabledEventArgs.cs | 46 | ||||
-rw-r--r-- | Tizen.Applications.Common/Tizen.Applications/ApplicationEnabledEventArgs.cs | 46 | ||||
-rw-r--r-- | Tizen.Applications.Common/Tizen.Applications/ApplicationEventState.cs | 40 | ||||
-rwxr-xr-x[-rw-r--r--] | Tizen.Applications.Common/Tizen.Applications/ApplicationInfo.cs | 0 | ||||
-rw-r--r-- | Tizen.Applications.Common/Tizen.Applications/ApplicationManager.cs | 99 | ||||
-rw-r--r-- | Tizen.Applications/Tizen.Applications.csproj | 3 |
8 files changed, 280 insertions, 2 deletions
diff --git a/Tizen.Applications.Common/Interop/Interop.ApplicationManager.cs b/Tizen.Applications.Common/Interop/Interop.ApplicationManager.cs index de4f638..4d45cdb 100644..100755 --- a/Tizen.Applications.Common/Interop/Interop.ApplicationManager.cs +++ b/Tizen.Applications.Common/Interop/Interop.ApplicationManager.cs @@ -41,6 +41,31 @@ internal static partial class Interop Terminated = 1 } + internal enum AppManagerEventStatusType + { + All = 0x00, + Enable = 0x01, + Disable = 0x02 + } + + internal enum AppManagerEventType + { + Enable = 0, + Disable = 1 + } + + internal enum AppManagerEventState + { + Started = 0, + Completed = 1, + Failed = 2 + } + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + internal delegate void AppManagerEventCallback(string appType, string appId, AppManagerEventType eventType, AppManagerEventState eventState, IntPtr eventHandle, IntPtr userData); + //void(* app_manager_event_cb)(const char *type, const char *app_id, app_manager_event_type_e event_type, app_manager_event_state_e event_state, app_manager_event_h handle, void *user_data) + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] internal delegate void AppManagerAppContextEventCallback(IntPtr handle, AppContextEvent state, IntPtr userData); //void(* app_manager_app_context_event_cb)(app_context_h app_context, app_context_event_e event, void *user_data) @@ -121,6 +146,26 @@ internal static partial class Interop internal static extern ErrorCode AppManagerGetExternalSharedDataPath(string applicationId, out string path); //int app_manager_get_external_shared_data_path (const char *appid, char **path); + [DllImport(Libraries.AppManager, EntryPoint = "app_manager_event_create")] + internal static extern ErrorCode AppManagerEventCreate(out IntPtr handle); + //int app_manager_event_create (app_manager_event_h *handle); + + [DllImport(Libraries.AppManager, EntryPoint = "app_manager_event_set_status")] + internal static extern ErrorCode AppManagerEventSetStatus(IntPtr handle, AppManagerEventStatusType statusType); + //int app_manager_event_set_status (app_manager_event_h handle, int status_type); + + [DllImport(Libraries.AppManager, EntryPoint = "app_manager_set_event_cb")] + internal static extern ErrorCode AppManagerSetEventCallback(IntPtr handle, AppManagerEventCallback callback, IntPtr userData); + //int app_manager_set_event_cb (app_manager_event_h handle, app_manager_event_cb callback, void *user_data); + + [DllImport(Libraries.AppManager, EntryPoint = "app_manager_unset_event_cb")] + internal static extern ErrorCode AppManagerUnSetEventCallback(IntPtr handle); + //int app_manager_unset_event_cb (app_manager_event_h handle); + + [DllImport(Libraries.AppManager, EntryPoint = "app_manager_event_destroy")] + internal static extern ErrorCode AppManagerEventDestroy(IntPtr handle); + //int app_manager_event_destroy (app_manager_event_h handle); + [DllImport(Libraries.AppManager, EntryPoint = "app_context_destroy")] internal static extern ErrorCode AppContextDestroy(IntPtr handle); //int app_context_destroy(app_context_h app_context) diff --git a/Tizen.Applications.Common/Tizen.Applications.Common.csproj b/Tizen.Applications.Common/Tizen.Applications.Common.csproj index 2278de1..eca4af7 100755..100644 --- a/Tizen.Applications.Common/Tizen.Applications.Common.csproj +++ b/Tizen.Applications.Common/Tizen.Applications.Common.csproj @@ -56,6 +56,9 @@ <Compile Include="Tizen.Applications.CoreBackend\EventType.cs" /> <Compile Include="Tizen.Applications.CoreBackend\DefaultCoreBackend.cs" /> <Compile Include="Tizen.Applications.CoreBackend\ICoreBackend.cs" /> + <Compile Include="Tizen.Applications\ApplicationEnabledEventArgs.cs" /> + <Compile Include="Tizen.Applications\ApplicationDisabledEventArgs.cs" /> + <Compile Include="Tizen.Applications\ApplicationEventState.cs" /> <Compile Include="Tizen.Applications\ApplicationInfo.cs" /> <Compile Include="Tizen.Applications\ApplicationManager.cs" /> <Compile Include="Tizen.Applications\ApplicationInfoFilter.cs" /> diff --git a/Tizen.Applications.Common/Tizen.Applications/ApplicationDisabledEventArgs.cs b/Tizen.Applications.Common/Tizen.Applications/ApplicationDisabledEventArgs.cs new file mode 100644 index 0000000..5b185d3 --- /dev/null +++ b/Tizen.Applications.Common/Tizen.Applications/ApplicationDisabledEventArgs.cs @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +using System; + +namespace Tizen.Applications +{ + /// <summary> + /// Arguments for the event that is raised when the application is disabled. + /// </summary> + public class ApplicationDisabledEventArgs : EventArgs + { + private readonly ApplicationEventState _eventState; + private readonly string _applicationId; + + internal ApplicationDisabledEventArgs(string appId, ApplicationEventState eventState) + { + _applicationId = appId; + _eventState = eventState; + } + + /// <summary> + /// The Id of the application + /// </summary> + public string ApplicationId { get { return _applicationId; } } + + /// <summary> + /// The Event state of the application + /// </summary> + public ApplicationEventState EventState { get { return _eventState; } } + } +} + diff --git a/Tizen.Applications.Common/Tizen.Applications/ApplicationEnabledEventArgs.cs b/Tizen.Applications.Common/Tizen.Applications/ApplicationEnabledEventArgs.cs new file mode 100644 index 0000000..fa72e8a --- /dev/null +++ b/Tizen.Applications.Common/Tizen.Applications/ApplicationEnabledEventArgs.cs @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +using System; + +namespace Tizen.Applications +{ + /// <summary> + /// Arguments for the event that is raised when the application is enabled. + /// </summary> + public class ApplicationEnabledEventArgs : EventArgs + { + private readonly ApplicationEventState _eventState; + private readonly string _applicationId; + + internal ApplicationEnabledEventArgs(string appId, ApplicationEventState eventState) + { + _applicationId = appId; + _eventState = eventState; + } + + /// <summary> + /// The Id of the application + /// </summary> + public string ApplicationId { get { return _applicationId; } } + + /// <summary> + /// The Event state of the application + /// </summary> + public ApplicationEventState EventState { get { return _eventState; } } + } +} + diff --git a/Tizen.Applications.Common/Tizen.Applications/ApplicationEventState.cs b/Tizen.Applications.Common/Tizen.Applications/ApplicationEventState.cs new file mode 100644 index 0000000..8ef9597 --- /dev/null +++ b/Tizen.Applications.Common/Tizen.Applications/ApplicationEventState.cs @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +using System; + +namespace Tizen.Applications +{ + /// <summary> + /// Enumeration of the application event state + /// </summary> + public enum ApplicationEventState + { + /// <summary> + /// Processing Started. + /// </summary> + Started = Interop.ApplicationManager.AppManagerEventState.Started, + /// <summary> + /// Processing Completed. + /// </summary> + Completed = Interop.ApplicationManager.AppManagerEventState.Completed, + /// <summary> + /// Processing Failed. + /// </summary> + Failed = Interop.ApplicationManager.AppManagerEventState.Failed + } +} + diff --git a/Tizen.Applications.Common/Tizen.Applications/ApplicationInfo.cs b/Tizen.Applications.Common/Tizen.Applications/ApplicationInfo.cs index f9230fc..f9230fc 100644..100755 --- a/Tizen.Applications.Common/Tizen.Applications/ApplicationInfo.cs +++ b/Tizen.Applications.Common/Tizen.Applications/ApplicationInfo.cs diff --git a/Tizen.Applications.Common/Tizen.Applications/ApplicationManager.cs b/Tizen.Applications.Common/Tizen.Applications/ApplicationManager.cs index e049a35..0c08a2f 100644 --- a/Tizen.Applications.Common/Tizen.Applications/ApplicationManager.cs +++ b/Tizen.Applications.Common/Tizen.Applications/ApplicationManager.cs @@ -26,11 +26,59 @@ namespace Tizen.Applications public static class ApplicationManager { private const string LogTag = "Tizen.Applications"; - private static EventHandler<ApplicationLaunchedEventArgs> s_launchedHandler; private static EventHandler<ApplicationTerminatedEventArgs> s_terminatedHandler; - private static Interop.ApplicationManager.AppManagerAppContextEventCallback s_applicationChangedEventCallback; + private static EventHandler<ApplicationEnabledEventArgs> _enabledHandler; + private static EventHandler<ApplicationDisabledEventArgs> _disabledHandler; + private static Interop.ApplicationManager.AppManagerEventCallback _eventCallback; + private static IntPtr _eventHandle = IntPtr.Zero; + + /// <summary> + /// Occurs whenever the installed application is enabled. + /// </summary> + public static event EventHandler<ApplicationEnabledEventArgs> ApplicationEnabled + { + add + { + if (_enabledHandler == null && _disabledHandler == null) + { + RegisterApplicationEvent(); + } + _enabledHandler += value; + } + remove + { + _enabledHandler -= value; + if (_enabledHandler == null && _disabledHandler == null) + { + UnRegisterApplicationEvent(); + } + } + } + + /// <summary> + /// Occurs whenever the installed application is disabled. + /// </summary> + public static event EventHandler<ApplicationDisabledEventArgs> ApplicationDisabled + { + add + { + if (_disabledHandler == null && _enabledHandler == null) + { + RegisterApplicationEvent(); + } + _disabledHandler += value; + } + remove + { + _disabledHandler -= value; + if (_disabledHandler == null && _enabledHandler == null) + { + UnRegisterApplicationEvent(); + } + } + } /// <summary> /// Occurs whenever the installed applications get launched. @@ -345,6 +393,53 @@ namespace Tizen.Applications { Interop.ApplicationManager.AppManagerUnSetAppContextEvent(); } + + private static void RegisterApplicationEvent() + { + Interop.ApplicationManager.ErrorCode err = Interop.ApplicationManager.ErrorCode.None; + err = Interop.ApplicationManager.AppManagerEventCreate(out _eventHandle); + if (err != Interop.ApplicationManager.ErrorCode.None) + { + throw ApplicationManagerErrorFactory.GetException(err, "Failed to create the application event handle"); + } + + err = Interop.ApplicationManager.AppManagerEventSetStatus(_eventHandle, Interop.ApplicationManager.AppManagerEventStatusType.All); + if (err != Interop.ApplicationManager.ErrorCode.None) + { + Interop.ApplicationManager.AppManagerEventDestroy(_eventHandle); + _eventHandle = IntPtr.Zero; + 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) => + { + if (eventType == Interop.ApplicationManager.AppManagerEventType.Enable) + { + _enabledHandler?.Invoke(null, new ApplicationEnabledEventArgs(appId, (ApplicationEventState)eventState)); + } + else if (eventType == Interop.ApplicationManager.AppManagerEventType.Disable) + { + _disabledHandler?.Invoke(null, new ApplicationDisabledEventArgs(appId, (ApplicationEventState)eventState)); + } + }; + err = Interop.ApplicationManager.AppManagerSetEventCallback(_eventHandle, _eventCallback, IntPtr.Zero); + if (err != Interop.ApplicationManager.ErrorCode.None) + { + Interop.ApplicationManager.AppManagerEventDestroy(_eventHandle); + _eventHandle = IntPtr.Zero; + throw ApplicationManagerErrorFactory.GetException(err, "Failed to set the application event callback"); + } + } + + private static void UnRegisterApplicationEvent() + { + if (_eventHandle != IntPtr.Zero) + { + Interop.ApplicationManager.AppManagerUnSetEventCallback(_eventHandle); + Interop.ApplicationManager.AppManagerEventDestroy(_eventHandle); + _eventHandle = IntPtr.Zero; + } + } } internal static class FilterExtension diff --git a/Tizen.Applications/Tizen.Applications.csproj b/Tizen.Applications/Tizen.Applications.csproj index 99239ad..54d8a39 100644 --- a/Tizen.Applications/Tizen.Applications.csproj +++ b/Tizen.Applications/Tizen.Applications.csproj @@ -56,6 +56,9 @@ <Compile Include="../Tizen.Applications.Common/Tizen.Applications/AppControlReplyCallback.cs" /> <Compile Include="../Tizen.Applications.Common/Tizen.Applications/AppControlReplyResult.cs" /> <Compile Include="../Tizen.Applications.Common/Tizen.Applications/Application.cs" /> + <Compile Include="../Tizen.Applications.Common/Tizen.Applications/ApplicationDisabledEventArgs.cs" /> + <Compile Include="../Tizen.Applications.Common/Tizen.Applications/ApplicationEnabledEventArgs.cs" /> + <Compile Include="../Tizen.Applications.Common/Tizen.Applications/ApplicationEventState.cs" /> <Compile Include="../Tizen.Applications.Common/Tizen.Applications/ApplicationInfo.cs" /> <Compile Include="../Tizen.Applications.Common/Tizen.Applications/ApplicationInfoFilter.cs" /> <Compile Include="../Tizen.Applications.Common/Tizen.Applications/ApplicationInfoMetadataFilter.cs" /> |