Add new APIs
authorHwankyu Jhun <h.jhun@samsung.com>
Mon, 13 Mar 2017 06:52:42 +0000 (15:52 +0900)
committerHwanKyu Jhun <h.jhun@samsung.com>
Thu, 16 Mar 2017 04:37:54 +0000 (21:37 -0700)
- 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>
Tizen.Applications/Tizen.Applications.csproj
src/Tizen.Applications.Common/Interop/Interop.ApplicationManager.cs [changed mode: 0644->0755]
src/Tizen.Applications.Common/Tizen.Applications.Common.csproj [changed mode: 0755->0644]
src/Tizen.Applications.Common/Tizen.Applications/ApplicationDisabledEventArgs.cs [new file with mode: 0644]
src/Tizen.Applications.Common/Tizen.Applications/ApplicationEnabledEventArgs.cs [new file with mode: 0644]
src/Tizen.Applications.Common/Tizen.Applications/ApplicationEventState.cs [new file with mode: 0644]
src/Tizen.Applications.Common/Tizen.Applications/ApplicationInfo.cs [changed mode: 0644->0755]
src/Tizen.Applications.Common/Tizen.Applications/ApplicationManager.cs

index 99239ad..54d8a39 100644 (file)
@@ -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" />
old mode 100644 (file)
new mode 100755 (executable)
index de4f638..4d45cdb
@@ -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)
old mode 100755 (executable)
new mode 100644 (file)
index 2278de1..eca4af7
@@ -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/src/Tizen.Applications.Common/Tizen.Applications/ApplicationDisabledEventArgs.cs b/src/Tizen.Applications.Common/Tizen.Applications/ApplicationDisabledEventArgs.cs
new file mode 100644 (file)
index 0000000..5b185d3
--- /dev/null
@@ -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/src/Tizen.Applications.Common/Tizen.Applications/ApplicationEnabledEventArgs.cs b/src/Tizen.Applications.Common/Tizen.Applications/ApplicationEnabledEventArgs.cs
new file mode 100644 (file)
index 0000000..fa72e8a
--- /dev/null
@@ -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/src/Tizen.Applications.Common/Tizen.Applications/ApplicationEventState.cs b/src/Tizen.Applications.Common/Tizen.Applications/ApplicationEventState.cs
new file mode 100644 (file)
index 0000000..8ef9597
--- /dev/null
@@ -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
+    }
+}
+
index e049a35..0c08a2f 100644 (file)
@@ -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