From c27ded1ffb33ca3c3fdc8f0078cf341ea93dbaa5 Mon Sep 17 00:00:00 2001 From: ilho159kim Date: Tue, 25 Apr 2023 11:06:28 +0900 Subject: [PATCH] [Application.Common][TCSACR-536]Add APIs for getting path related resource control (#5126) * [Application.Common][TCSACR-536]Add APIs for getting path related resource control - DirectoryInfo.GetResControlAllowedResource() - DirectoryInfo.GetResControlGlobalResource() Signed-off-by: ilho kim * Adjust review ResControl -> ResourceControl res_type -> resourceType Fix ambiguous description Signed-off-by: ilho kim --------- Signed-off-by: ilho kim Co-authored-by: pjh9216 --- .../Interop/Interop.AppCommon.cs | 16 +++++ .../Tizen.Applications/DirectoryInfo.cs | 71 ++++++++++++++++++++++ 2 files changed, 87 insertions(+) diff --git a/src/Tizen.Applications.Common/Interop/Interop.AppCommon.cs b/src/Tizen.Applications.Common/Interop/Interop.AppCommon.cs index 7d0362e..a117c30 100644 --- a/src/Tizen.Applications.Common/Interop/Interop.AppCommon.cs +++ b/src/Tizen.Applications.Common/Interop/Interop.AppCommon.cs @@ -32,6 +32,16 @@ internal static partial class Interop Binary } + internal enum AppCommonErrorCode + { + None = Tizen.Internals.Errors.ErrorCode.None, + InvalidParameter = Tizen.Internals.Errors.ErrorCode.InvalidParameter, + OutOfMemory = Tizen.Internals.Errors.ErrorCode.OutOfMemory, + InvalidContext = -0x01100000 | 0x01, + NoSuchFile = Tizen.Internals.Errors.ErrorCode.NoSuchFile, + PermissionDenied = Tizen.Internals.Errors.ErrorCode.PermissionDenied, + } + [DllImport(Libraries.AppCommon, EntryPoint = "app_get_id")] internal static extern ErrorCode AppGetId(out string appId); @@ -94,6 +104,12 @@ internal static partial class Interop [DllImport(Libraries.AppCommon, EntryPoint = "app_event_get_suspended_state")] internal static extern ErrorCode AppEventGetSuspendedState(IntPtr handle, out SuspendedState state); + + [DllImport(Libraries.AppCommon, EntryPoint = "app_get_res_control_allowed_resource_path")] + internal static extern AppCommonErrorCode AppGetResControlAllowedResourcePath(string applicationId, out string path); + + [DllImport(Libraries.AppCommon, EntryPoint = "app_get_res_control_global_resource_path")] + internal static extern AppCommonErrorCode AppGetResControlGlobalResourcePath(string applicationId, out string path); } } diff --git a/src/Tizen.Applications.Common/Tizen.Applications/DirectoryInfo.cs b/src/Tizen.Applications.Common/Tizen.Applications/DirectoryInfo.cs index cceaba4..e165f4f 100644 --- a/src/Tizen.Applications.Common/Tizen.Applications/DirectoryInfo.cs +++ b/src/Tizen.Applications.Common/Tizen.Applications/DirectoryInfo.cs @@ -14,6 +14,9 @@ * limitations under the License. */ +using System.IO; +using System; + namespace Tizen.Applications { /// @@ -180,5 +183,73 @@ namespace Tizen.Applications return _expansionPackageResourcePath; } } + + /// + /// Gets the absolute path to the application's resource control directory, which is used to share the allowed resources of the resource packages. + /// + /// The resource type defined in the resource package + /// The absolute path to the application's resource control directory, which is used to share the allowed resources of the resource packages. + /// Thrown in case of an invalid parameter. + /// Thrown in case of out of memory. + /// Thrown in case of nonexistence of resource. + /// Thrown in case of any internal error. + /// 11 + public string GetResourceControlAllowedResource(string resourceType) + { + string path = string.Empty; + Interop.AppCommon.AppCommonErrorCode err = Interop.AppCommon.AppGetResControlAllowedResourcePath(resourceType, out path); + if (err != Interop.AppCommon.AppCommonErrorCode.None) + { + switch (err) + { + case Interop.AppCommon.AppCommonErrorCode.InvalidParameter: + throw new ArgumentException("Invalid Arguments"); + case Interop.AppCommon.AppCommonErrorCode.OutOfMemory: + throw new OutOfMemoryException("Out of memory"); + case Interop.AppCommon.AppCommonErrorCode.InvalidContext: + throw new InvalidOperationException("Invalid app context"); + case Interop.AppCommon.AppCommonErrorCode.PermissionDenied: + throw new DirectoryNotFoundException(String.Format("Allowed Resource about {0} is not Found", resourceType)); + default: + throw new InvalidOperationException("Invalid Operation"); + } + } + + return path; + } + + /// + /// Gets the absolute path to the application's resource control directory, which is used to share the global resources of the resource packages. + /// + /// The resource type defined in the resource package + /// The absolute path to the application's resource control directory, which is used to share the global resources of the resource packages. + /// Thrown in case of an invalid parameter. + /// Thrown in case of out of memory. + /// Thrown in case of nonexistence of resource. + /// Thrown in case of any internal error. + /// 11 + public string GetResourceControlGlobalResource(string resourceType) + { + string path = string.Empty; + Interop.AppCommon.AppCommonErrorCode err = Interop.AppCommon.AppGetResControlGlobalResourcePath(resourceType, out path); + if (err != Interop.AppCommon.AppCommonErrorCode.None) + { + switch (err) + { + case Interop.AppCommon.AppCommonErrorCode.InvalidParameter: + throw new ArgumentException("Invalid Arguments"); + case Interop.AppCommon.AppCommonErrorCode.OutOfMemory: + throw new OutOfMemoryException("Out of memory"); + case Interop.AppCommon.AppCommonErrorCode.InvalidContext: + throw new InvalidOperationException("Invalid app context"); + case Interop.AppCommon.AppCommonErrorCode.PermissionDenied: + throw new DirectoryNotFoundException(String.Format("Allowed Resource about {0} is not Found", resourceType)); + default: + throw new InvalidOperationException("Invalid Operation"); + } + } + + return path; + } } } -- 2.7.4