Release 9.0.0.16887
[platform/core/csapi/tizenfx.git] / src / Tizen.Applications.PackageManager / Tizen.Applications / PackageDrm.cs
1 /*
2  * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the License);
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an AS IS BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 using System;
18 using System.Collections.Generic;
19 using System.Runtime.InteropServices;
20 using System.Threading.Tasks;
21
22 namespace Tizen.Applications
23 {
24     /// <summary>
25     /// This class provides the methods and properties for the DRM operation.
26     /// </summary>
27     /// <since_tizen> 4 </since_tizen>
28     public class PackageDrm
29     {
30         private string _responseData;
31         private string _requestData;
32         private string _licenseUrl;
33         private PackageDrm(string responseData, string requestData, string licenseUrl)
34         {
35             _responseData = responseData;
36             _requestData = requestData;
37             _licenseUrl = licenseUrl;
38         }
39
40         /// <summary>
41         /// Returns the response data.
42         /// </summary>
43         /// <returns>Returns the response data which is given when GenerateLicenseRequest has been invoked.</returns>
44         /// <since_tizen> 4 </since_tizen>
45         public string ResponseData { get { return _responseData; } }
46
47         /// <summary>
48         /// Returns the request data.
49         /// </summary>
50         /// <returns>Returns the request data which is generated when GenerateLicenseRequest has been invoked.</returns>
51         /// <since_tizen> 4 </since_tizen>
52         public string RequestData { get { return _requestData; } }
53
54         /// <summary>
55         /// Returns the license URL.
56         /// </summary>
57         /// <returns>Returns the license URL which is generated when GenerateLicenseRequest has been invoked.</returns>
58         /// <since_tizen> 4 </since_tizen>
59         public string LicenseUrl { get { return _licenseUrl; } }
60
61         internal static PackageDrm CreateDrmRequest(string responseData, string requestData, string licenseUrl)
62         {
63             PackageDrm packageDrm = new PackageDrm(responseData, requestData, licenseUrl);
64             return packageDrm;
65         }
66
67         internal static PackageDrm GenerateLicenseRequest(string responseData)
68         {
69             string requestData;
70             string licenseUrl;
71             Interop.PackageManager.ErrorCode err = Interop.PackageManager.PackageManagerDrmGenerateLicenseRequest(responseData, out requestData, out licenseUrl);
72             if (err != Interop.PackageManager.ErrorCode.None)
73             {
74                 throw PackageManagerErrorFactory.GetException(err, "Failed to generate license request");
75             }
76
77             PackageDrm packageDrm = CreateDrmRequest(responseData, requestData, licenseUrl);
78             return packageDrm;
79         }
80     }
81 }