Add new property to get app state
authorHwankyu Jhun <h.jhun@samsung.com>
Wed, 8 Feb 2017 04:59:51 +0000 (13:59 +0900)
committerHwanKyu Jhun <h.jhun@samsung.com>
Wed, 22 Feb 2017 05:42:33 +0000 (21:42 -0800)
Change-Id: I379eadf81c9666726e7bb762b8b3d128d31aa873
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
src/Tizen.Applications.Common/Interop/Interop.ApplicationManager.cs [changed mode: 0755->0644]
src/Tizen.Applications.Common/Tizen.Applications/ApplicationInfo.cs [changed mode: 0755->0644]

old mode 100755 (executable)
new mode 100644 (file)
index ec2d291..a2637fd
@@ -129,6 +129,10 @@ internal static partial class Interop
         internal static extern ErrorCode AppContextGetPid(IntPtr handle, out int processId);
         //int app_context_get_pid (app_context_h app_context, pid_t *pid)
 
+        [DllImport(Libraries.AppManager, EntryPoint = "app_context_get_app_state")]
+        internal static extern ErrorCode AppContextGetAppState(IntPtr handle, out int state);
+        //int app_context_get_app_state (app_context_h app_context, app_state_e *state)
+
         [DllImport(Libraries.AppManager, EntryPoint = "app_context_is_terminated")]
         internal static extern ErrorCode AppContextIsTerminated(IntPtr handle, out bool terminated);
         //int app_context_is_terminated (app_context_h app_context, bool *terminated);
old mode 100755 (executable)
new mode 100644 (file)
index 31e9774..1c4858c
@@ -52,6 +52,37 @@ namespace Tizen.Applications
             Dispose(false);
         }
 
+        /// <summary>
+        /// Enumeration for the Application State.
+        /// </summary>
+        public enum AppState
+        {
+            /// <summary>
+            /// The undefined state
+            /// </summary>
+            Undefined = 0,
+
+            /// <summary>
+            /// The UI application is running in the foreground.
+            /// </summary>
+            Foreground,
+
+            /// <summary>
+            /// The UI application is running in the background.
+            /// </summary>
+            Background,
+
+            /// <summary>
+            /// The Service application is running.
+            /// </summary>
+            Service,
+
+            /// <summary>
+            /// The application is terminated.
+            /// </summary>
+            Terminated,
+        }
+
         /// <summary>
         /// Gets the application id.
         /// </summary>
@@ -409,6 +440,39 @@ namespace Tizen.Applications
             return label;
         }
 
+        /// <summary>
+        /// Gets the state of the application.
+        /// </summary>
+        public AppState State
+        {
+            get
+            {
+                int value = 0;
+                IntPtr contextHandle = IntPtr.Zero;
+                try
+                {
+                    err = Interop.ApplicationManager.AppManagerGetAppContext(ApplicationId, out contextHandle);
+                    if (err != Interop.ApplicationManager.ErrorCode.None)
+                    {
+                        Log.Warn(LogTag, "Failed to get the context handle. err = " + err);
+                    }
+                    err = Interop.ApplicationManager.AppContextGetAppState(contextHandle, out value);
+                    if (err != Interop.ApplicationManager.ErrorCode.None)
+                    {
+                        Log.Warn(LogTag, "Failed to get the app state. err = " + err);
+                    }
+                }
+                finally
+                {
+                    if (contextHandle != IntPtr.Zero)
+                    {
+                        Interop.ApplicationManager.AppContextDestroy(contextHandle);
+                    }
+                }
+                return (AppState)value;
+            }
+        }
+
         private IntPtr GetInfoHandle()
         {
             if (_infoHandle == IntPtr.Zero)