From: inkyun.kil Date: Thu, 16 Mar 2017 02:08:19 +0000 (+0900) Subject: Add new apis for getting information of recent applications. X-Git-Tag: submit/trunk/20170823.075128~121^2~69 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=5d9dad300adcaf66b4ab3896fc4e2be25abfe347;p=platform%2Fcore%2Fcsapi%2Ftizenfx.git Add new apis for getting information of recent applications. Change-Id: Id72a7dc9089feeed0c57193b772bbac8b10f8474 Signed-off-by: inkyun.kil --- diff --git a/Tizen.Applications/Interop/Interop.Libraries.cs b/Tizen.Applications/Interop/Interop.Libraries.cs index ecf4b10..b1463d7 100755 --- a/Tizen.Applications/Interop/Interop.Libraries.cs +++ b/Tizen.Applications/Interop/Interop.Libraries.cs @@ -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"; diff --git a/Tizen.Applications/Tizen.Applications.csproj b/Tizen.Applications/Tizen.Applications.csproj index f74d4a0..201adcf 100755 --- a/Tizen.Applications/Tizen.Applications.csproj +++ b/Tizen.Applications/Tizen.Applications.csproj @@ -62,6 +62,8 @@ + + diff --git a/src/Tizen.Applications.Common/Interop/Interop.ApplicationManager.cs b/src/Tizen.Applications.Common/Interop/Interop.ApplicationManager.cs index d93378a..e114c1b 100755 --- a/src/Tizen.Applications.Common/Interop/Interop.ApplicationManager.cs +++ b/src/Tizen.Applications.Common/Interop/Interop.ApplicationManager.cs @@ -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); } } diff --git a/src/Tizen.Applications.Common/Interop/Interop.Libraries.cs b/src/Tizen.Applications.Common/Interop/Interop.Libraries.cs index 5caecca..e9a8f47 100755 --- a/src/Tizen.Applications.Common/Interop/Interop.Libraries.cs +++ b/src/Tizen.Applications.Common/Interop/Interop.Libraries.cs @@ -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"; } diff --git a/src/Tizen.Applications.Common/Tizen.Applications.Common.csproj b/src/Tizen.Applications.Common/Tizen.Applications.Common.csproj old mode 100644 new mode 100755 index 2a69bc6..c2880a2 --- a/src/Tizen.Applications.Common/Tizen.Applications.Common.csproj +++ b/src/Tizen.Applications.Common/Tizen.Applications.Common.csproj @@ -60,6 +60,8 @@ + + diff --git a/src/Tizen.Applications.Common/Tizen.Applications/ApplicationManager.cs b/src/Tizen.Applications.Common/Tizen.Applications/ApplicationManager.cs old mode 100644 new mode 100755 index ea2dd74..c99c04d --- a/src/Tizen.Applications.Common/Tizen.Applications/ApplicationManager.cs +++ b/src/Tizen.Applications.Common/Tizen.Applications/ApplicationManager.cs @@ -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; } } + + /// + /// Gets the information of the recent applications. + /// + /// Returns a dictionary containing all recent application info. + /// Thrown when failed because of invalid operation + public static IEnumerable GetRecentApplications() + { + Interop.ApplicationManager.ErrorCode err = Interop.ApplicationManager.ErrorCode.None; + + List result = new List(); + 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 index 0000000..418cef1 --- /dev/null +++ b/src/Tizen.Applications.Common/Tizen.Applications/RecentApplicationControl.cs @@ -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 +{ + /// + /// This class provides methods and properties to get information of recent application. + /// + public class RecentApplicationControl + { + private const string LogTag = "Tizen.Applications"; + + private readonly string _pkgId; + + internal RecentApplicationControl(String pkgId) + { + _pkgId = pkgId; + } + + /// + /// Deletes the application from recent application list. + /// + 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."); + } + } + + /// + /// Delete all recent applicationsfrom recent application list. + /// + 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 index 0000000..8812e4f --- /dev/null +++ b/src/Tizen.Applications.Common/Tizen.Applications/RecentApplicationInfo.cs @@ -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 +{ + /// + /// This class provides methods and properties to get information of recent application. + /// + public class RecentApplicationInfo : ApplicationInfo + { + private const string LogTag = "Tizen.Applications"; + + /// + /// Gets the instance id. + /// + public string InstanceId { get; private set; } + + /// + /// Gets the instance Name. + /// + public string InstanceName { get; private set; } + + /// + /// Gets the arguements. + /// + public string Arg { get; private set; } + + /// + /// Gets the uri. + /// + public string Uri { get; private set; } + + /// + /// Gets the launchTime. + /// + public DateTime LaunchTime { get; private set; } + + /// + /// Gets the recent application controller. + /// + 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)); + } + } +}