From: Junghyun Yeon Date: Mon, 6 Mar 2017 08:55:36 +0000 (+0900) Subject: Add missing APIs X-Git-Tag: submit/trunk/20170823.075128~121^2~82 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=3e2c764a1dbd9c343d5349fd52f12c9c60010072;p=platform%2Fcore%2Fcsapi%2Ftizenfx.git Add missing APIs - Package certificate-related APIs PackageManager.CompareCertInfo PackageManager.CompareCertInfoByApplicationId Package.CompareCertInfo - Package DRM-related APIs PackageManager.drm.GenerateLicenseRequest PackageManager.drm.RegisterLicense PackageManager.drm.DrcryptPackage PackageDrm.GetRequestData PackageDrm.GetLicenseUrl - Other package-related APIs PackageManager.GetPermissionTypeByApplicationId PackageManager.IsPreloadPackageByApplicationId Signed-off-by: Junghyun Yeon Change-Id: I96e977b47bd612f8d8f902b9d4c273990c0608cd --- diff --git a/Tizen.Applications/Tizen.Applications.csproj b/Tizen.Applications/Tizen.Applications.csproj index 1365fb4..62b1fba 100755 --- a/Tizen.Applications/Tizen.Applications.csproj +++ b/Tizen.Applications/Tizen.Applications.csproj @@ -124,6 +124,9 @@ + + + diff --git a/src/Tizen.Applications.PackageManager/Interop/Interop.Package.cs b/src/Tizen.Applications.PackageManager/Interop/Interop.Package.cs old mode 100755 new mode 100644 index c749aab..2d86f5d --- a/src/Tizen.Applications.PackageManager/Interop/Interop.Package.cs +++ b/src/Tizen.Applications.PackageManager/Interop/Interop.Package.cs @@ -19,6 +19,7 @@ using System.Runtime.InteropServices; using ErrorCode = Interop.PackageManager.ErrorCode; using StorageType = Interop.PackageManager.StorageType; +using CertCompareResultType = Interop.PackageManager.CertCompareResultType; internal static partial class Interop { @@ -104,5 +105,8 @@ internal static partial class Interop [DllImport(Libraries.PackageManager, EntryPoint = "package_info_is_accessible")] internal static extern ErrorCode PackageInfoIsAccessible(IntPtr handle, out bool accessible); + + [DllImport(Libraries.PackageManager, EntryPoint = "package_manager_compare_package_cert_info")] + internal static extern ErrorCode PackageCompareCertInfo(string lhsPackageId, string rhsPackageId, out CertCompareResultType result); } } diff --git a/src/Tizen.Applications.PackageManager/Interop/Interop.PackageManager.cs b/src/Tizen.Applications.PackageManager/Interop/Interop.PackageManager.cs old mode 100755 new mode 100644 index 961d24d..3d2e2bc --- a/src/Tizen.Applications.PackageManager/Interop/Interop.PackageManager.cs +++ b/src/Tizen.Applications.PackageManager/Interop/Interop.PackageManager.cs @@ -71,6 +71,22 @@ internal static partial class Interop Update = 2 } + internal enum CertCompareResultType + { + Match = 0, + Mismatch, + LhsNoCert, + RhsNoCert, + BothNoCert + } + + internal enum PackageManagerPermissionType + { + Normal = 0, + Signature, + Privilege + } + // Any change here might require changes in Tizen.Applications.StorageType enum internal enum StorageType { @@ -164,5 +180,26 @@ internal static partial class Interop [DllImport(Libraries.PackageManager, EntryPoint = "package_manager_request_move")] internal static extern ErrorCode PackageManagerRequestMove(IntPtr request, string name, StorageType moveToStorageType); + + [DllImport(Libraries.PackageManager, EntryPoint = "package_manager_compare_package_cert_info")] + internal static extern ErrorCode PackageManagerCompareCertInfo(string lhsPackageId, string rhsPackageId, out CertCompareResultType CompareResult); + + [DllImport(Libraries.PackageManager, EntryPoint = "package_manager_compare_app_cert_info")] + internal static extern ErrorCode PackageManagerCompareCertInfoByApplicationId(string lhsPackageId, string rhsPackageId, out CertCompareResultType CompareResult); + + [DllImport(Libraries.PackageManager, EntryPoint = "package_manager_is_preload_package_by_app_id")] + internal static extern ErrorCode PackageManagerIsPreloadPackageByApplicationId(string ApplicationId, out bool IsPreload); + + [DllImport(Libraries.PackageManager, EntryPoint = "package_manager_get_permission_type")] + internal static extern ErrorCode PackageManagerGetPermissionType(string ApplicationId, out PackageManagerPermissionType PermissionType); + + [DllImport(Libraries.PackageManager, EntryPoint = "package_manager_drm_generate_license_request")] + internal static extern ErrorCode PackageManagerDrmGenerateLicenseRequest(string responseData, out string requestData, out string licenseUrl); + + [DllImport(Libraries.PackageManager, EntryPoint = "package_manager_drm_register_license")] + internal static extern ErrorCode PackageManagerDrmRegisterLicense(string responseData); + + [DllImport(Libraries.PackageManager, EntryPoint = "package_manager_drm_decrypt_package")] + internal static extern ErrorCode PackageManagerDrmDecryptPackage(string drmFilePath, string decryptedFilePath); } } diff --git a/src/Tizen.Applications.PackageManager/Tizen.Applications.PackageManager.csproj b/src/Tizen.Applications.PackageManager/Tizen.Applications.PackageManager.csproj old mode 100755 new mode 100644 index a81f65f..4fa2cb5 --- a/src/Tizen.Applications.PackageManager/Tizen.Applications.PackageManager.csproj +++ b/src/Tizen.Applications.PackageManager/Tizen.Applications.PackageManager.csproj @@ -49,7 +49,9 @@ + + @@ -58,6 +60,7 @@ + diff --git a/src/Tizen.Applications.PackageManager/Tizen.Applications/CertCompareResultType.cs b/src/Tizen.Applications.PackageManager/Tizen.Applications/CertCompareResultType.cs new file mode 100644 index 0000000..cd1512b --- /dev/null +++ b/src/Tizen.Applications.PackageManager/Tizen.Applications/CertCompareResultType.cs @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2017 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; + +namespace Tizen.Applications +{ + /// + /// Enumeration for certificate compare result type. + /// + public enum CertCompareResultType + { + /// + /// Certificates are matched. + /// + Match = Interop.PackageManager.CertCompareResultType.Match, + /// + /// Certificates are not matched. + /// + Mismatch = Interop.PackageManager.CertCompareResultType.Mismatch, + /// + /// First package doesn't have certificate. + /// + LhsNoCert = Interop.PackageManager.CertCompareResultType.LhsNoCert, + /// + /// Second package doesn't have certificate. + /// + RhsNoCert = Interop.PackageManager.CertCompareResultType.RhsNoCert, + /// + /// Certificates of both packages are not exist. + /// + BothNoCert = Interop.PackageManager.CertCompareResultType.BothNoCert + } +} diff --git a/src/Tizen.Applications.PackageManager/Tizen.Applications/Package.cs b/src/Tizen.Applications.PackageManager/Tizen.Applications/Package.cs old mode 100755 new mode 100644 index 9049e71..44f3cc5 --- a/src/Tizen.Applications.PackageManager/Tizen.Applications/Package.cs +++ b/src/Tizen.Applications.PackageManager/Tizen.Applications/Package.cs @@ -205,6 +205,25 @@ namespace Tizen.Applications return await tcs.Task.ConfigureAwait(false); } + /// + /// Compare certificate information with given package id. + /// + /// Id of the package + /// Certificate comparison result + /// Thrown when failed when input package ID is invalid + /// Thrown when method failed due to internal IO error + public CertCompareResultType CompareCertInfo(string packageId) + { + Interop.PackageManager.CertCompareResultType compareResult; + Interop.PackageManager.ErrorCode err = Interop.PackageManager.PackageManagerCompareCertInfo(Id, packageId, out compareResult); + if (err != Interop.PackageManager.ErrorCode.None) + { + throw PackageManagerErrorFactory.GetException(err, "Failed to compare package cert info"); + } + + return (CertCompareResultType)compareResult; + } + // This method assumes that given arguments are already validated and have valid values. internal static Package CreatePackage(IntPtr handle, string pkgId) { diff --git a/src/Tizen.Applications.PackageManager/Tizen.Applications/PackageDrm.cs b/src/Tizen.Applications.PackageManager/Tizen.Applications/PackageDrm.cs new file mode 100644 index 0000000..cb45bbb --- /dev/null +++ b/src/Tizen.Applications.PackageManager/Tizen.Applications/PackageDrm.cs @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2017 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; +using System.Threading.Tasks; + +namespace Tizen.Applications +{ + /// + /// This class provide methods and properties for DRM operation + /// + public class PackageDrm + { + private string _responseData; + private string _requestData; + private string _licenseUrl; + private PackageDrm(string responseData, string requestData, string licenseUrl) + { + _responseData = responseData; + _requestData = requestData; + _licenseUrl = licenseUrl; + } + + /// + /// Returns response data + /// + /// Returns response data which is given when GenerateLicenseRequest has invoked + public string ResponseData { get { return _responseData; } } + + /// + /// Returns request data + /// + /// Returns request data which is generated when GenerateLicenseRequest has invoked + public string RequestData { get { return _requestData; } } + + /// + /// Returns license URL + /// + /// Returns license URL which is generated when GenerateLicenseRequest has invoked + public string LicenseUrl { get { return _licenseUrl; } } + + internal static PackageDrm CreateDrmRequest(string responseData, string requestData, string licenseUrl) + { + PackageDrm packageDrm = new PackageDrm(responseData, requestData, licenseUrl); + return packageDrm; + } + + internal static PackageDrm GenerateLicenseRequest(string responseData) + { + string requestData; + string licenseUrl; + Interop.PackageManager.ErrorCode err = Interop.PackageManager.PackageManagerDrmGenerateLicenseRequest(responseData, out requestData, out licenseUrl); + if (err != Interop.PackageManager.ErrorCode.None) + { + throw PackageManagerErrorFactory.GetException(err, "Failed to generate license request"); + } + + PackageDrm packageDrm = CreateDrmRequest(responseData, requestData, licenseUrl); + return packageDrm; + } + } +} diff --git a/src/Tizen.Applications.PackageManager/Tizen.Applications/PackageManager.cs b/src/Tizen.Applications.PackageManager/Tizen.Applications/PackageManager.cs index a4be778..2fc3b0a 100644 --- a/src/Tizen.Applications.PackageManager/Tizen.Applications/PackageManager.cs +++ b/src/Tizen.Applications.PackageManager/Tizen.Applications/PackageManager.cs @@ -434,6 +434,151 @@ namespace Tizen.Applications return result; } + /// + /// Gets permission type of package which has given application id + /// + /// Id of the application + /// Returns permission type. + /// http://tizen.org/privilege/packagemanager.info + /// Thrown when failed when input package ID is invalid + /// Thrown when app does not have privilege to access this method + public static PermissionType GetPermissionTypeByApplicationId(string applicationId) + { + Interop.PackageManager.PackageManagerPermissionType permissionType; + Interop.PackageManager.ErrorCode err = Interop.PackageManager.PackageManagerGetPermissionType(applicationId, out permissionType); + if (err != Interop.PackageManager.ErrorCode.None) + { + throw PackageManagerErrorFactory.GetException(err, "Failed to get permission type."); + } + + return (PermissionType)permissionType; + } + + /// + /// Gets package's preload attribute which contain given applicion id + /// + /// Id of the application + /// Returns true if package is preloaded. Otherwise return false. + /// http://tizen.org/privilege/packagemanager.info + /// Thrown when failed when input package ID is invalid + /// Thrown when app does not have privilege to access this method + public static bool IsPreloadPackageByApplicationId(string applicationId) + { + bool isPreloadPackage; + Interop.PackageManager.ErrorCode err = Interop.PackageManager.PackageManagerIsPreloadPackageByApplicationId(applicationId, out isPreloadPackage); + if (err != Interop.PackageManager.ErrorCode.None) + { + throw PackageManagerErrorFactory.GetException(err, "Failed to get preload info"); + } + + return isPreloadPackage; + } + + /// + /// Compare certificate of two packages + /// + /// package id to compare + /// package id to be compared + /// Returns certificate comparison result. + /// Thrown when failed when input package ID is invalid + /// Thrown when method failed due to internal IO error + public static CertCompareResultType CompareCertInfo(string lhsPackageId, string rhsPackageId) + { + Interop.PackageManager.CertCompareResultType compareResult; + Interop.PackageManager.ErrorCode err = Interop.PackageManager.PackageManagerCompareCertInfo(lhsPackageId, rhsPackageId, out compareResult); + if (err != Interop.PackageManager.ErrorCode.None) + { + throw PackageManagerErrorFactory.GetException(err, "Failed to compare cert info"); + } + + return (CertCompareResultType)compareResult; + } + + /// + /// Compare certificate of two packages which contain each given application id + /// + /// application id to compare + /// application id to be compared + /// Returns certificate comparison result. + /// Thrown when failed when input package ID is invalid + /// Thrown when method failed due to internal IO error + public static CertCompareResultType CompareCertInfoByApplicationId(string lhsApplicationId, string rhsApplicationId) + { + Interop.PackageManager.CertCompareResultType compareResult; + Interop.PackageManager.ErrorCode err = Interop.PackageManager.PackageManagerCompareCertInfoByApplicationId(lhsApplicationId, rhsApplicationId, out compareResult); + if (err != Interop.PackageManager.ErrorCode.None) + { + throw PackageManagerErrorFactory.GetException(err, "Failed to compare cert info by application id"); + } + + return (CertCompareResultType)compareResult; + } + + /// + /// Drm nested class. This class has the PackageManager's drm related methods. + /// + public static class Drm + { + /// + /// Generates request for getting license + /// + /// Response data string of the purchase request + /// Returns package drm information of given response data which contains require data and license url + /// http://tizen.org/privilege/packagemanager.admin + /// Thrown when failed when input package ID is invalid + /// Thrown when there is not enough memory to continue the execution of the method + /// Thrown when app does not have privilege to access this method + /// Thrown when method failed due to internal system error + public static PackageDrm GenerateLicenseRequest(string responseData) + { + return PackageDrm.GenerateLicenseRequest(responseData); + + } + + /// + /// Registers encrypted license + /// + /// The response data string of the rights request + /// Returns true if succeed. Otherwise return false + /// http://tizen.org/privilege/packagemanager.admin + /// Thrown when failed when input package ID is invalid + /// Thrown when there is not enough memory to continue the execution of the method + /// Thrown when app does not have privilege to access this method + /// Thrown when method failed due to internal system error + public static bool RegisterLicense(string responseData) + { + Interop.PackageManager.ErrorCode err = Interop.PackageManager.PackageManagerDrmRegisterLicense(responseData); + if (err != Interop.PackageManager.ErrorCode.None) + { + throw PackageManagerErrorFactory.GetException(err, "Failed to register drm license"); + } + + return true; + } + + /// + /// Decrypts contents which is encrypted + /// + /// Drm file path + /// Decrypted file path + /// Returns true if succeed. Otherwise return false + /// http://tizen.org/privilege/packagemanager.admin + /// Thrown when failed when input package ID is invalid + /// Thrown when there is not enough memory to continue the execution of the method + /// Thrown when app does not have privilege to access this method + /// Thrown when method failed due to internal system error + public static bool DecryptPackage(string drmFilePath, string decryptedFilePath) + { + Interop.PackageManager.ErrorCode err = Interop.PackageManager.PackageManagerDrmDecryptPackage(drmFilePath, decryptedFilePath); + if (err != Interop.PackageManager.ErrorCode.None) + { + throw PackageManagerErrorFactory.GetException(err, "Failed to decrypt drm package"); + } + + return true; + } + } + private static void SetPackageManagerEventStatus() { if (Handle.IsInvalid) return; diff --git a/src/Tizen.Applications.PackageManager/Tizen.Applications/PermissionType.cs b/src/Tizen.Applications.PackageManager/Tizen.Applications/PermissionType.cs new file mode 100644 index 0000000..c4a4e2f --- /dev/null +++ b/src/Tizen.Applications.PackageManager/Tizen.Applications/PermissionType.cs @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2017 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; + +namespace Tizen.Applications +{ + /// + /// Enumeration for permission type. + /// + public enum PermissionType + { + /// + /// Permission is normal + /// + Normal, + /// + /// Permission is signature + /// + Signature, + /// + /// Permission is privilege + /// + Privilege + } +}