Add new apis for getting information of recent applications.
authorinkyun.kil <inkyun.kil@samsung.com>
Thu, 16 Mar 2017 02:08:19 +0000 (11:08 +0900)
committerInkyun Kil <inkyun.kil@samsung.com>
Wed, 22 Mar 2017 00:56:49 +0000 (17:56 -0700)
Change-Id: Id72a7dc9089feeed0c57193b772bbac8b10f8474
Signed-off-by: inkyun.kil <inkyun.kil@samsung.com>
Tizen.Applications/Interop/Interop.Libraries.cs
Tizen.Applications/Tizen.Applications.csproj
src/Tizen.Applications.Common/Interop/Interop.ApplicationManager.cs
src/Tizen.Applications.Common/Interop/Interop.Libraries.cs
src/Tizen.Applications.Common/Tizen.Applications.Common.csproj [changed mode: 0644->0755]
src/Tizen.Applications.Common/Tizen.Applications/ApplicationManager.cs [changed mode: 0644->0755]
src/Tizen.Applications.Common/Tizen.Applications/RecentApplicationControl.cs [new file with mode: 0755]
src/Tizen.Applications.Common/Tizen.Applications/RecentApplicationInfo.cs [new file with mode: 0755]

index ecf4b10..b1463d7 100755 (executable)
@@ -29,6 +29,7 @@ internal static partial class Interop
         public const string Bundle = "libbundle.so.0";
         public const string Glib = "libglib-2.0.so.0";
         public const string Libc = "libc.so.6";
+        public const string Rua =  "librua.so.0";
         public const string Notification = "libnotification.so.0";
         public const string Preference = "libcapi-appfw-preference.so.0";
         public const string Alarm = "libcapi-appfw-alarm.so.0";
index f74d4a0..201adcf 100755 (executable)
@@ -62,6 +62,8 @@
     <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" />
+    <Compile Include="../Tizen.Applications.Common/Tizen.Applications/RecentApplicationInfo.cs" />
+    <Compile Include="../Tizen.Applications.Common/Tizen.Applications/RecentApplicationControl.cs" />
     <Compile Include="../Tizen.Applications.Common/Tizen.Applications/ApplicationLaunchedEventArgs.cs" />
     <Compile Include="../Tizen.Applications.Common/Tizen.Applications/ApplicationManager.cs" />
     <Compile Include="../Tizen.Applications.Common/Tizen.Applications/ApplicationRunningContext.cs" />
index d93378a..e114c1b 100755 (executable)
@@ -305,5 +305,43 @@ internal static partial class Interop
         [DllImport(Libraries.AppManager, EntryPoint = "app_info_metadata_filter_foreach")]
         internal static extern ErrorCode AppInfoMetadataFilterForeach(IntPtr handle, AppInfoFilterCallback callback, IntPtr userData);
         //int app_info_metadata_filter_foreach (app_info_metadata_filter_h handle, app_info_filter_cb callback, void *user_data)
+
+        [StructLayout(LayoutKind.Sequential)]
+        internal struct RuaRec
+        {
+            internal int id;
+            internal IntPtr pkgName;
+            internal IntPtr appPath;
+            internal IntPtr arg;
+            internal long launchTime;
+            internal IntPtr instanceId;
+            internal IntPtr instanceName;
+            internal IntPtr icon;
+            internal IntPtr uri;
+        };
+
+        [DllImport(Libraries.Rua, EntryPoint = "rua_history_get_rec")]
+        internal static extern ErrorCode RuaHistoryGetRecord(out RuaRec record, IntPtr table, int nRows, int nCols, int row);
+        //int rua_history_get_rec(struct rua_rec *rec, char** table, int nrows, int ncols, int row);
+
+        [DllImport(Libraries.Rua, EntryPoint = "rua_history_load_db")]
+        internal static extern ErrorCode RuaHistoryLoadDb(out IntPtr table, out int nRows, out int nCols);
+        //int rua_history_load_db(char*** table, int *nrows, int *ncols);
+
+        [DllImport(Libraries.Rua, EntryPoint = "rua_history_unload_db")]
+        internal static extern ErrorCode RuaHistoryUnLoadDb(ref IntPtr table);
+        //int rua_history_unload_db(char*** table);
+
+        [DllImport(Libraries.Rua, EntryPoint = "rua_delete_history_with_pkgname")]
+        internal static extern ErrorCode RuaDeleteHistoryWithPkgname(string pkgName);
+        //int rua_delete_history_with_pkgname(char* pkg_name);
+
+        [DllImport(Libraries.Rua, EntryPoint = "rua_delete_history_with_apppath")]
+        internal static extern ErrorCode RuaDeleteHistoryWithApppath(string appPath);
+        //int rua_delete_history_with_apppath(char* app_path);
+
+        [DllImport(Libraries.Rua, EntryPoint = "rua_clear_history")]
+        internal static extern ErrorCode RuaClearHistory();
+        //int rua_clear_history(void);
     }
 }
index 5caecca..e9a8f47 100755 (executable)
@@ -23,6 +23,7 @@ internal static partial class Interop
         public const string AppEvent = "libcapi-appfw-event.so.0";
         public const string AppManager = "libcapi-appfw-app-manager.so.0";
         public const string Bundle = "libbundle.so.0";
+        public const string Rua = "librua.so.0";
         public const string Glib = "libglib-2.0.so.0";
         public const string Libc = "libc.so.6";
     }
old mode 100644 (file)
new mode 100755 (executable)
index 2a69bc6..c2880a2
@@ -60,6 +60,8 @@
     <Compile Include="Tizen.Applications\ApplicationDisabledEventArgs.cs" />
     <Compile Include="Tizen.Applications\ApplicationEventState.cs" />
     <Compile Include="Tizen.Applications\ApplicationRunningContext.cs" />
+    <Compile Include="Tizen.Applications\RecentApplicationControl.cs" />
+    <Compile Include="Tizen.Applications\RecentApplicationInfo.cs" />
     <Compile Include="Tizen.Applications\ApplicationInfo.cs" />
     <Compile Include="Tizen.Applications\ApplicationManager.cs" />
     <Compile Include="Tizen.Applications\ApplicationInfoFilter.cs" />
old mode 100644 (file)
new mode 100755 (executable)
index ea2dd74..c99c04d
@@ -16,6 +16,7 @@
 
 using System;
 using System.Collections.Generic;
+using System.Runtime.InteropServices;
 using System.Threading.Tasks;
 
 namespace Tizen.Applications
@@ -399,6 +400,48 @@ namespace Tizen.Applications
                 _eventHandle = IntPtr.Zero;
             }
         }
+
+        /// <summary>
+        /// Gets the information of the recent applications.
+        /// </summary>
+        /// <returns>Returns a dictionary containing all recent application info.</returns>
+        /// <exception cref="InvalidOperationException">Thrown when failed because of invalid operation</exception>
+        public static IEnumerable<RecentApplicationInfo> GetRecentApplications()
+        {
+            Interop.ApplicationManager.ErrorCode err = Interop.ApplicationManager.ErrorCode.None;
+
+            List<RecentApplicationInfo> result = new List<RecentApplicationInfo>();
+            IntPtr table;
+            int nrows, ncols;
+
+            err = Interop.ApplicationManager.RuaHistoryLoadDb(out table, out nrows, out ncols);
+            if (err != Interop.ApplicationManager.ErrorCode.None)
+            {
+                throw ApplicationManagerErrorFactory.GetException(err, "Failed to load a table for the recent application list.");
+            }
+
+            for (int row = 0; row < nrows; ++row)
+            {
+                Interop.ApplicationManager.RuaRec record;
+
+                err = Interop.ApplicationManager.RuaHistoryGetRecord(out record, table, nrows, ncols, row);
+                if (err != Interop.ApplicationManager.ErrorCode.None)
+                {
+                    throw ApplicationManagerErrorFactory.GetException(err, "Failed to get record.");
+                }
+
+                RecentApplicationInfo info = new RecentApplicationInfo(record);
+                result.Add(info);
+            }
+
+            err = Interop.ApplicationManager.RuaHistoryUnLoadDb(ref table);
+            if (err != Interop.ApplicationManager.ErrorCode.None)
+            {
+                throw ApplicationManagerErrorFactory.GetException(err, "Failed to unload a table for the recent application list.");
+            }
+
+            return result;
+        }
     }
 
     internal static class FilterExtension
diff --git a/src/Tizen.Applications.Common/Tizen.Applications/RecentApplicationControl.cs b/src/Tizen.Applications.Common/Tizen.Applications/RecentApplicationControl.cs
new file mode 100755 (executable)
index 0000000..418cef1
--- /dev/null
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 2016 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;
+using System.Collections.Generic;
+using System.Runtime.InteropServices;
+
+namespace Tizen.Applications
+{
+    /// <summary>
+    /// This class provides methods and properties to get information of recent application.
+    /// </summary>
+    public class RecentApplicationControl
+    {
+        private const string LogTag = "Tizen.Applications";
+
+        private readonly string _pkgId;
+
+        internal RecentApplicationControl(String pkgId)
+        {
+            _pkgId = pkgId;
+        }
+
+        /// <summary>
+        /// Deletes the application from recent application list.
+        /// </summary>
+        public void Delete()
+        {
+            Interop.ApplicationManager.ErrorCode err = Interop.ApplicationManager.ErrorCode.None;
+            err = Interop.ApplicationManager.RuaDeleteHistoryWithPkgname(_pkgId);
+            if (err != Interop.ApplicationManager.ErrorCode.None)
+            {
+                throw ApplicationManagerErrorFactory.GetException(err, "Failed to delete application from recent application list.");
+            }
+        }
+
+        /// <summary>
+        /// Delete all recent applicationsfrom recent application list.
+        /// </summary>
+        public static void DeleteAll()
+        {
+            Interop.ApplicationManager.ErrorCode err = Interop.ApplicationManager.ErrorCode.None;
+            err = Interop.ApplicationManager.RuaClearHistory();
+            if (err != Interop.ApplicationManager.ErrorCode.None)
+            {
+                throw ApplicationManagerErrorFactory.GetException(err, "Failed to clear the recent application list.");
+            }
+        }
+    }
+}
diff --git a/src/Tizen.Applications.Common/Tizen.Applications/RecentApplicationInfo.cs b/src/Tizen.Applications.Common/Tizen.Applications/RecentApplicationInfo.cs
new file mode 100755 (executable)
index 0000000..8812e4f
--- /dev/null
@@ -0,0 +1,69 @@
+/*
+ * Copyright (c) 2016 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;
+using System.Runtime.InteropServices;
+
+namespace Tizen.Applications
+{
+    /// <summary>
+    /// This class provides methods and properties to get information of recent application.
+    /// </summary>
+    public class RecentApplicationInfo : ApplicationInfo
+    {
+        private const string LogTag = "Tizen.Applications";
+
+        /// <summary>
+        /// Gets the instance id.
+        /// </summary>
+        public string InstanceId { get; private set; }
+
+        /// <summary>
+        /// Gets the instance Name.
+        /// </summary>
+        public string InstanceName { get; private set; }
+
+        /// <summary>
+        /// Gets the arguements.
+        /// </summary>
+        public string Arg { get; private set; }
+
+        /// <summary>
+        /// Gets the uri.
+        /// </summary>
+        public string Uri { get; private set; }
+
+        /// <summary>
+        /// Gets the launchTime.
+        /// </summary>
+        public DateTime LaunchTime { get; private set; }
+
+        /// <summary>
+        /// Gets the recent application controller.
+        /// </summary>
+        public RecentApplicationControl Controller { get; private set; }
+
+        internal RecentApplicationInfo(Interop.ApplicationManager.RuaRec record) : base(Marshal.PtrToStringAnsi(record.pkgName))
+        {
+            InstanceId = Marshal.PtrToStringAnsi(record.instanceId);
+            InstanceName = Marshal.PtrToStringAnsi(record.instanceName);
+            Arg = Marshal.PtrToStringAnsi(record.arg);
+            Uri = Marshal.PtrToStringAnsi(record.uri);
+            LaunchTime = new DateTime(1970, 1, 1).AddSeconds(record.launchTime);
+            Controller = new RecentApplicationControl(Marshal.PtrToStringAnsi(record.pkgName));
+        }
+    }
+}