Release 4.0.0-preview1-00051
[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 provide methods and properties for DRM operation
26     /// </summary>
27     public class PackageDrm
28     {
29         private string _responseData;
30         private string _requestData;
31         private string _licenseUrl;
32         private PackageDrm(string responseData, string requestData, string licenseUrl)
33         {
34             _responseData = responseData;
35             _requestData = requestData;
36             _licenseUrl = licenseUrl;
37         }
38
39         /// <summary>
40         /// Returns response data
41         /// </summary>
42         /// <returns>Returns response data which is given when GenerateLicenseRequest has invoked</returns>
43         public string ResponseData { get { return _responseData; } }
44
45         /// <summary>
46         /// Returns request data
47         /// </summary>
48         /// <returns>Returns request data which is generated when GenerateLicenseRequest has invoked</returns>
49         public string RequestData { get { return _requestData; } }
50
51         /// <summary>
52         /// Returns license URL
53         /// </summary>
54         /// <returns>Returns license URL which is generated when GenerateLicenseRequest has invoked</returns>
55         public string LicenseUrl { get { return _licenseUrl; } }
56
57         internal static PackageDrm CreateDrmRequest(string responseData, string requestData, string licenseUrl)
58         {
59             PackageDrm packageDrm = new PackageDrm(responseData, requestData, licenseUrl);
60             return packageDrm;
61         }
62
63         internal static PackageDrm GenerateLicenseRequest(string responseData)
64         {
65             string requestData;
66             string licenseUrl;
67             Interop.PackageManager.ErrorCode err = Interop.PackageManager.PackageManagerDrmGenerateLicenseRequest(responseData, out requestData, out licenseUrl);
68             if (err != Interop.PackageManager.ErrorCode.None)
69             {
70                 throw PackageManagerErrorFactory.GetException(err, "Failed to generate license request");
71             }
72
73             PackageDrm packageDrm = CreateDrmRequest(responseData, requestData, licenseUrl);
74             return packageDrm;
75         }
76     }
77 }