From e404dc94e03a28113a2bc8ef29a0ee22aabddd5f Mon Sep 17 00:00:00 2001 From: akash1-kumar <115205462+akash1-kumar@users.noreply.github.com> Date: Mon, 3 Apr 2023 09:28:01 +0530 Subject: [PATCH] Add new cache APIs (#5088) * Add new APIs for cache. Signed-off-by: Akash Kumar * Add new APIs for cache. Signed-off-by: Akash Kumar * Change methods to C# properties for set/get APIs. Signed-off-by: Akash Kumar * Add class 'CacheManager' for managing cache properties. Signed-off-by: Akash Kumar * Update documentation: Add '' tag Signed-off-by: Akash Kumar --------- Signed-off-by: Akash Kumar --- .../Interop/Interop.Download.cs | 20 +++ .../Tizen.Content.Download/CacheManager.cs | 166 ++++++++++++++++++ .../Tizen.Content.Download/Request.cs | 33 ++++ 3 files changed, 219 insertions(+) create mode 100644 src/Tizen.Content.Download/Tizen.Content.Download/CacheManager.cs diff --git a/src/Tizen.Content.Download/Interop/Interop.Download.cs b/src/Tizen.Content.Download/Interop/Interop.Download.cs index 839ee635e..c4433c414 100755 --- a/src/Tizen.Content.Download/Interop/Interop.Download.cs +++ b/src/Tizen.Content.Download/Interop/Interop.Download.cs @@ -106,5 +106,25 @@ internal static partial class Interop internal static extern int SetNotificationAppControl(int requestId, int appControlType, SafeAppControlHandle handle); [DllImport(Libraries.Download, EntryPoint = "download_get_notification_app_control")] internal static extern int GetNotificationAppControl(int requestId, int appControlType, out SafeAppControlHandle handle); + [DllImport(Libraries.Download, EntryPoint = "download_set_cache")] + internal static extern int SetDownloadCache(int downloadId, bool enable); + [DllImport(Libraries.Download, EntryPoint = "download_get_cache")] + internal static extern int GetDownloadCache(int downloadId, out bool enable); + [DllImport(Libraries.Download, EntryPoint = "download_reset_cache")] + internal static extern int ResetDownloadCache(); + [DllImport(Libraries.Download, EntryPoint = "download_set_cache_max_size")] + internal static extern int SetDownloadCacheMaxSize(uint maxSize); + [DllImport(Libraries.Download, EntryPoint = "download_get_cache_max_size")] + internal static extern int GetDownloadCacheMaxSize(out uint maxSize); + [DllImport(Libraries.Download, EntryPoint = "download_reset_all_cache")] + internal static extern int ResetAllDownloadCache(); + [DllImport(Libraries.Download, EntryPoint = "download_set_cache_path")] + internal static extern int SetDownloadCachePath(string cachePath); + [DllImport(Libraries.Download, EntryPoint = "download_get_cache_path")] + internal static extern int GetDownloadCachePath(out string cachePath); + [DllImport(Libraries.Download, EntryPoint = "download_set_cache_lifecycle")] + internal static extern int SetDownloadCacheLifeCycle(uint time); + [DllImport(Libraries.Download, EntryPoint = "download_get_cache_lifecycle")] + internal static extern int GetDownloadCacheLifeCycle(out uint time); } } diff --git a/src/Tizen.Content.Download/Tizen.Content.Download/CacheManager.cs b/src/Tizen.Content.Download/Tizen.Content.Download/CacheManager.cs new file mode 100644 index 000000000..2a0731991 --- /dev/null +++ b/src/Tizen.Content.Download/Tizen.Content.Download/CacheManager.cs @@ -0,0 +1,166 @@ +/* +* Copyright (c) 2023 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.ComponentModel; + +namespace Tizen.Content.Download +{ + /// + /// The CacheManager class provides the functions to manage cache properties. + /// + /// 11 + static class CacheManager + { + + /// + /// Clears per app download cache. + /// + /// 11 + /// http://tizen.org/privilege/download + /// http://tizen.org/feature/download + /// Thrown when it is failed due to an invalid operation. + /// Thrown when a permission is denied. + /// Thrown when not supported. + static public void ResetCache() + { + int ret = Interop.Download.ResetDownloadCache(); + if (ret != (int)DownloadError.None) + { + DownloadErrorFactory.ThrowException(ret, "Failed to reset cache"); + } + } + + /// + /// Total maximum cache size considering all apps. + /// + /// 11 + /// http://tizen.org/privilege/download + /// http://tizen.org/feature/download + /// Thrown when it is failed due to setting an invalid value. + /// Thrown when it is failed due to an invalid operation. + /// Thrown when a permission is denied. + /// Thrown when not supported. + [EditorBrowsable(EditorBrowsableState.Never)] + static public uint MaxCacheSize + { + get + { + uint maxCacheSize; + int ret = Interop.Download.GetDownloadCacheMaxSize(out maxCacheSize); + if (ret != (int)DownloadError.None) + { + DownloadErrorFactory.ThrowException(ret, "Failed to get max size of cache"); + } + return maxCacheSize; + } + set + { + int ret = Interop.Download.SetDownloadCacheMaxSize(value); + if (ret != (int)DownloadError.None) + { + DownloadErrorFactory.ThrowException(ret, "Failed to set cache max size"); + } + } + } + + /// + /// Clears all system download cache. + /// + /// 11 + /// http://tizen.org/privilege/download + /// http://tizen.org/feature/download + /// Thrown when it is failed due to an invalid operation. + /// Thrown when a permission is denied. + /// Thrown when not supported. + [EditorBrowsable(EditorBrowsableState.Never)] + static public void ResetAllCache() + { + int ret = Interop.Download.ResetAllDownloadCache(); + if (ret != (int)DownloadError.None) + { + DownloadErrorFactory.ThrowException(ret, "Failed to reset all cache"); + } + } + + /// + /// Path of the cache stored. + /// + /// 11 + /// http://tizen.org/privilege/download + /// http://tizen.org/feature/download + /// Thrown when it is failed due to setting an invalid value. + /// Thrown when it is failed due to an invalid operation. + /// Thrown when a permission is denied. + /// Thrown when not supported. + [EditorBrowsable(EditorBrowsableState.Never)] + static public string CachePath + { + get + { + string cachePath; + int ret = Interop.Download.GetDownloadCachePath(out cachePath); + if (ret != (int)DownloadError.None) + { + DownloadErrorFactory.ThrowException(ret, "Failed to get cache path"); + } + return cachePath; + } + set + { + int ret = Interop.Download.SetDownloadCachePath(value); + if (ret != (int)DownloadError.None) + { + DownloadErrorFactory.ThrowException(ret, "Failed to set cache path"); + } + } + } + + /// + /// Life cycle of the cache in seconds. + /// + /// 11 + /// http://tizen.org/privilege/download + /// http://tizen.org/feature/download + /// The time after which the stored cache will be invalid/stale. + /// Thrown when it is failed due to setting an invalid value. + /// Thrown when it is failed due to an invalid operation. + /// Thrown when a permission is denied. + /// Thrown when not supported. + [EditorBrowsable(EditorBrowsableState.Never)] + static public uint CacheLifeCycle + { + get + { + uint lifeCycle; + int ret = Interop.Download.GetDownloadCacheLifeCycle(out lifeCycle); + if (ret != (int)DownloadError.None) + { + DownloadErrorFactory.ThrowException(ret, "Failed to get cache life cycle."); + } + return lifeCycle; + } + set + { + int ret = Interop.Download.SetDownloadCacheLifeCycle(value); + if (ret != (int)DownloadError.None) + { + DownloadErrorFactory.ThrowException(ret, "Failed to set cache life cycle."); + } + } + } + } +} diff --git a/src/Tizen.Content.Download/Tizen.Content.Download/Request.cs b/src/Tizen.Content.Download/Tizen.Content.Download/Request.cs index bd484be39..25e282804 100755 --- a/src/Tizen.Content.Download/Tizen.Content.Download/Request.cs +++ b/src/Tizen.Content.Download/Tizen.Content.Download/Request.cs @@ -17,6 +17,7 @@ using System; using System.Collections.Generic; using System.Runtime.InteropServices; +using System.ComponentModel; namespace Tizen.Content.Download { @@ -843,6 +844,38 @@ namespace Tizen.Content.Download DownloadErrorFactory.ThrowException(ret, "Unsetting ProgressChanged callback failed"); } } + + /// + /// Enabled state of the cache feature. + /// + /// 11 + /// http://tizen.org/privilege/download + /// http://tizen.org/feature/download + /// Thrown when it is failed due to setting an invalid value. + /// Thrown when it is failed due to an invalid operation. + /// Thrown when a permission is denied. + /// Thrown when not supported. + public bool UsesCache + { + get + { + bool enable; + int ret = Interop.Download.GetDownloadCache(_downloadId, out enable); + if (ret != (int)DownloadError.None) + { + DownloadErrorFactory.ThrowException(ret, "Failed to get enabled state of cache"); + } + return enable; + } + set + { + int ret = Interop.Download.SetDownloadCache(_downloadId, value); + if (ret != (int)DownloadError.None) + { + DownloadErrorFactory.ThrowException(ret, "Failed to set enabled state of download cache"); + } + } + } } } -- 2.34.1