diff options
author | Junghyun Yeon <jungh.yeon@samsung.com> | 2017-03-06 17:55:36 +0900 |
---|---|---|
committer | Junghyun Yeon <jungh.yeon@samsung.com> | 2017-03-16 01:35:33 -0700 |
commit | e3873396ce2b60000e102713f6f767214ebb35eb (patch) | |
tree | 16e6cdd8b8851949f94bfd5914b222899e48d948 | |
parent | a1e092665f5e042583f06b9d350106f8686e2ae5 (diff) | |
download | application-e3873396ce2b60000e102713f6f767214ebb35eb.tar.gz application-e3873396ce2b60000e102713f6f767214ebb35eb.tar.bz2 application-e3873396ce2b60000e102713f6f767214ebb35eb.zip |
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 <jungh.yeon@samsung.com>
Change-Id: I96e977b47bd612f8d8f902b9d4c273990c0608cd
-rw-r--r--[-rwxr-xr-x] | Tizen.Applications.PackageManager/Interop/Interop.Package.cs | 4 | ||||
-rw-r--r--[-rwxr-xr-x] | Tizen.Applications.PackageManager/Interop/Interop.PackageManager.cs | 37 | ||||
-rw-r--r--[-rwxr-xr-x] | Tizen.Applications.PackageManager/Tizen.Applications.PackageManager.csproj | 3 | ||||
-rw-r--r-- | Tizen.Applications.PackageManager/Tizen.Applications/CertCompareResultType.cs | 47 | ||||
-rw-r--r--[-rwxr-xr-x] | Tizen.Applications.PackageManager/Tizen.Applications/Package.cs | 19 | ||||
-rw-r--r-- | Tizen.Applications.PackageManager/Tizen.Applications/PackageDrm.cs | 77 | ||||
-rw-r--r-- | Tizen.Applications.PackageManager/Tizen.Applications/PackageManager.cs | 145 | ||||
-rw-r--r-- | Tizen.Applications.PackageManager/Tizen.Applications/PermissionType.cs | 39 | ||||
-rwxr-xr-x | Tizen.Applications/Tizen.Applications.csproj | 3 |
9 files changed, 374 insertions, 0 deletions
diff --git a/Tizen.Applications.PackageManager/Interop/Interop.Package.cs b/Tizen.Applications.PackageManager/Interop/Interop.Package.cs index c749aab..2d86f5d 100755..100644 --- a/Tizen.Applications.PackageManager/Interop/Interop.Package.cs +++ b/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/Tizen.Applications.PackageManager/Interop/Interop.PackageManager.cs b/Tizen.Applications.PackageManager/Interop/Interop.PackageManager.cs index 961d24d..3d2e2bc 100755..100644 --- a/Tizen.Applications.PackageManager/Interop/Interop.PackageManager.cs +++ b/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/Tizen.Applications.PackageManager/Tizen.Applications.PackageManager.csproj b/Tizen.Applications.PackageManager/Tizen.Applications.PackageManager.csproj index a81f65f..4fa2cb5 100755..100644 --- a/Tizen.Applications.PackageManager/Tizen.Applications.PackageManager.csproj +++ b/Tizen.Applications.PackageManager/Tizen.Applications.PackageManager.csproj @@ -49,7 +49,9 @@ <Compile Include="Interop\Interop.PackageManager.cs" /> <Compile Include="Interop\Interop.Libraries.cs" /> <Compile Include="Properties\AssemblyInfo.cs" /> + <Compile Include="Tizen.Applications\CertCompareResultType.cs" /> <Compile Include="Tizen.Applications\CertificateType.cs" /> + <Compile Include="Tizen.Applications\PackageDrm.cs" /> <Compile Include="Tizen.Applications\PackageEventState.cs" /> <Compile Include="Tizen.Applications\Package.cs" /> <Compile Include="Tizen.Applications\PackageCertificate.cs" /> @@ -58,6 +60,7 @@ <Compile Include="Tizen.Applications\PackageManagerEventArgs.cs" /> <Compile Include="Tizen.Applications\PackageSizeInformation.cs" /> <Compile Include="Tizen.Applications\PackageType.cs" /> + <Compile Include="Tizen.Applications\PermissionType.cs" /> <Compile Include="Tizen.Applications\SafePackageManagerHandle.cs" /> <Compile Include="Tizen.Applications\StorageType.cs" /> </ItemGroup> diff --git a/Tizen.Applications.PackageManager/Tizen.Applications/CertCompareResultType.cs b/Tizen.Applications.PackageManager/Tizen.Applications/CertCompareResultType.cs new file mode 100644 index 0000000..cd1512b --- /dev/null +++ b/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 +{ + /// <summary> + /// Enumeration for certificate compare result type. + /// </summary> + public enum CertCompareResultType + { + /// <summary> + /// Certificates are matched. + /// </summary> + Match = Interop.PackageManager.CertCompareResultType.Match, + /// <summary> + /// Certificates are not matched. + /// </summary> + Mismatch = Interop.PackageManager.CertCompareResultType.Mismatch, + /// <summary> + /// First package doesn't have certificate. + /// </summary> + LhsNoCert = Interop.PackageManager.CertCompareResultType.LhsNoCert, + /// <summary> + /// Second package doesn't have certificate. + /// </summary> + RhsNoCert = Interop.PackageManager.CertCompareResultType.RhsNoCert, + /// <summary> + /// Certificates of both packages are not exist. + /// </summary> + BothNoCert = Interop.PackageManager.CertCompareResultType.BothNoCert + } +} diff --git a/Tizen.Applications.PackageManager/Tizen.Applications/Package.cs b/Tizen.Applications.PackageManager/Tizen.Applications/Package.cs index 9049e71..44f3cc5 100755..100644 --- a/Tizen.Applications.PackageManager/Tizen.Applications/Package.cs +++ b/Tizen.Applications.PackageManager/Tizen.Applications/Package.cs @@ -205,6 +205,25 @@ namespace Tizen.Applications return await tcs.Task.ConfigureAwait(false); } + /// <summary> + /// Compare certificate information with given package id. + /// </summary> + /// <param name="packageId">Id of the package</param> + /// <returns>Certificate comparison result</returns> + /// <exception cref="ArgumentException">Thrown when failed when input package ID is invalid</exception> + /// <exception cref="System.IO.IOException">Thrown when method failed due to internal IO error</exception> + 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/Tizen.Applications.PackageManager/Tizen.Applications/PackageDrm.cs b/Tizen.Applications.PackageManager/Tizen.Applications/PackageDrm.cs new file mode 100644 index 0000000..cb45bbb --- /dev/null +++ b/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 +{ + /// <summary> + /// This class provide methods and properties for DRM operation + /// </summary> + 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; + } + + /// <summary> + /// Returns response data + /// </summary> + /// <returns>Returns response data which is given when GenerateLicenseRequest has invoked</returns> + public string ResponseData { get { return _responseData; } } + + /// <summary> + /// Returns request data + /// </summary> + /// <returns>Returns request data which is generated when GenerateLicenseRequest has invoked</returns> + public string RequestData { get { return _requestData; } } + + /// <summary> + /// Returns license URL + /// </summary> + /// <returns>Returns license URL which is generated when GenerateLicenseRequest has invoked</returns> + 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/Tizen.Applications.PackageManager/Tizen.Applications/PackageManager.cs b/Tizen.Applications.PackageManager/Tizen.Applications/PackageManager.cs index a4be778..2fc3b0a 100644 --- a/Tizen.Applications.PackageManager/Tizen.Applications/PackageManager.cs +++ b/Tizen.Applications.PackageManager/Tizen.Applications/PackageManager.cs @@ -434,6 +434,151 @@ namespace Tizen.Applications return result; } + /// <summary> + /// Gets permission type of package which has given application id + /// </summary> + /// <param name="applicationId">Id of the application</param> + /// <returns>Returns permission type.</returns> + /// <privilege>http://tizen.org/privilege/packagemanager.info</privilege> + /// <exception cref="ArgumentException">Thrown when failed when input package ID is invalid</exception> + /// <exception cref="UnauthorizedAccessException">Thrown when app does not have privilege to access this method</exception> + 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; + } + + /// <summary> + /// Gets package's preload attribute which contain given applicion id + /// </summary> + /// <param name="applicationId">Id of the application</param> + /// <returns>Returns true if package is preloaded. Otherwise return false.</returns> + /// <privilege>http://tizen.org/privilege/packagemanager.info</privilege> + /// <exception cref="ArgumentException">Thrown when failed when input package ID is invalid</exception> + /// <exception cref="UnauthorizedAccessException">Thrown when app does not have privilege to access this method</exception> + 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; + } + + /// <summary> + /// Compare certificate of two packages + /// </summary> + /// <param name="lhsPackageId">package id to compare</param> + /// <param name="rhsPackageId">package id to be compared</param> + /// <returns>Returns certificate comparison result.</returns> + /// <exception cref="ArgumentException">Thrown when failed when input package ID is invalid</exception> + /// <exception cref="System.IO.IOException">Thrown when method failed due to internal IO error</exception> + 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; + } + + /// <summary> + /// Compare certificate of two packages which contain each given application id + /// </summary> + /// <param name="lhsApplicationId">application id to compare</param> + /// <param name="rhsApplicationId">application id to be compared</param> + /// <returns>Returns certificate comparison result.</returns> + /// <exception cref="ArgumentException">Thrown when failed when input package ID is invalid</exception> + /// <exception cref="System.IO.IOException">Thrown when method failed due to internal IO error</exception> + 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; + } + + /// <summary> + /// Drm nested class. This class has the PackageManager's drm related methods. + /// </summary> + public static class Drm + { + /// <summary> + /// Generates request for getting license + /// </summary> + /// <param name="responseData">Response data string of the purchase request</param> + /// <returns>Returns package drm information of given response data which contains require data and license url</returns> + /// <privilege>http://tizen.org/privilege/packagemanager.admin</privilege> + /// <exception cref="ArgumentException">Thrown when failed when input package ID is invalid</exception> + /// <exception cref="OutOfMemoryException">Thrown when there is not enough memory to continue the execution of the method</exception> + /// <exception cref="UnauthorizedAccessException">Thrown when app does not have privilege to access this method</exception> + /// <exception cref="SystemException">Thrown when method failed due to internal system error</exception> + public static PackageDrm GenerateLicenseRequest(string responseData) + { + return PackageDrm.GenerateLicenseRequest(responseData); + + } + + /// <summary> + /// Registers encrypted license + /// </summary> + /// <param name="responseData">The response data string of the rights request</param> + /// <returns>Returns true if succeed. Otherwise return false</returns> + /// <privilege>http://tizen.org/privilege/packagemanager.admin</privilege> + /// <exception cref="ArgumentException">Thrown when failed when input package ID is invalid</exception> + /// <exception cref="OutOfMemoryException">Thrown when there is not enough memory to continue the execution of the method</exception> + /// <exception cref="UnauthorizedAccessException">Thrown when app does not have privilege to access this method</exception> + /// <exception cref="SystemException">Thrown when method failed due to internal system error</exception> + 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; + } + + /// <summary> + /// Decrypts contents which is encrypted + /// </summary> + /// <param name="drmFilePath">Drm file path</param> + /// <param name="decryptedFilePath">Decrypted file path</param> + /// <returns>Returns true if succeed. Otherwise return false</returns> + /// <privilege>http://tizen.org/privilege/packagemanager.admin</privilege> + /// <exception cref="ArgumentException">Thrown when failed when input package ID is invalid</exception> + /// <exception cref="OutOfMemoryException">Thrown when there is not enough memory to continue the execution of the method</exception> + /// <exception cref="UnauthorizedAccessException">Thrown when app does not have privilege to access this method</exception> + /// <exception cref="SystemException">Thrown when method failed due to internal system error</exception> + 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/Tizen.Applications.PackageManager/Tizen.Applications/PermissionType.cs b/Tizen.Applications.PackageManager/Tizen.Applications/PermissionType.cs new file mode 100644 index 0000000..c4a4e2f --- /dev/null +++ b/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 +{ + /// <summary> + /// Enumeration for permission type. + /// </summary> + public enum PermissionType + { + /// <summary> + /// Permission is normal + /// </summary> + Normal, + /// <summary> + /// Permission is signature + /// </summary> + Signature, + /// <summary> + /// Permission is privilege + /// </summary> + Privilege + } +} 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 @@ <Compile Include="../Tizen.Applications.Service/Tizen.Applications/ServiceApplication.cs" /> <Compile Include="../Tizen.Applications.Service/Tizen.Applications.CoreBackend/ServiceCoreBackend.cs" /> <Compile Include="../Tizen.Applications.PackageManager/Tizen.Applications/StorageType.cs" /> + <Compile Include="../Tizen.Applications.PackageManager/Tizen.Applications/CertCompareResultType.cs" /> + <Compile Include="../Tizen.Applications.PackageManager/Tizen.Applications/PermissionType.cs" /> + <Compile Include="../Tizen.Applications.PackageManager/Tizen.Applications/PackageDrm.cs" /> <Compile Include="../Tizen.Applications.Common/Tizen.Applications/TizenSynchronizationContext.cs" /> <Compile Include="../Tizen.Applications.UI/Tizen.Applications.CoreBackend/UICoreBackend.cs" /> <Compile Include="../Tizen.Applications.Common/Tizen.Applications/DeviceOrientationEventArgs.cs" /> |