1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
|
/*
* Copyright (C) 2007 The Android Open Source Project
*
* 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.
*/
package android.drm.mobile1;
import java.io.*;
import java.util.*;
/**
* This class provides interfaces to access the DRM right manager.
*/
public class DrmRightsManager {
/**
* The "application/vnd.oma.drm.rights+xml" mime type.
*/
public static final String DRM_MIMETYPE_RIGHTS_XML_STRING = "application/vnd.oma.drm.rights+xml";
/**
* The "application/vnd.oma.drm.rights+wbxml" mime type.
*/
public static final String DRM_MIMETYPE_RIGHTS_WBXML_STRING = "application/vnd.oma.drm.rights+wbxml";
/**
* The id of "application/vnd.oma.drm.rights+xml" mime type.
*/
private static final int DRM_MIMETYPE_RIGHTS_XML = 3;
/**
* The id of "application/vnd.oma.drm.rights+wbxml" mime type.
*/
private static final int DRM_MIMETYPE_RIGHTS_WBXML = 4;
/**
* The id of "application/vnd.oma.drm.message" mime type.
*/
private static final int DRM_MIMETYPE_MESSAGE = 1;
/**
* Successful operation.
*/
private static final int JNI_DRM_SUCCESS = 0;
/**
* General failure.
*/
private static final int JNI_DRM_FAILURE = -1;
/**
* The instance of the rights manager.
*/
private static DrmRightsManager singleton = null;
/**
* Construct a DrmRightsManager
*/
protected DrmRightsManager() {
}
/**
* Get the DrmRightsManager instance.
*
* @return the instance of DrmRightsManager.
*/
public static synchronized DrmRightsManager getInstance() {
if (singleton == null) {
singleton = new DrmRightsManager();
}
return singleton;
}
/**
* Install one DRM rights and return one instance of DrmRights.
*
* @param rightsData raw rights data.
* @param mimeTypeStr the mime type of the rights object.
*
* @return the instance of the installed DrmRights.
*/
public synchronized DrmRights installRights(InputStream rightsData, int len, String mimeTypeStr) throws DrmException, IOException {
int mimeType = 0;
if (DRM_MIMETYPE_RIGHTS_XML_STRING.equals(mimeTypeStr))
mimeType = DRM_MIMETYPE_RIGHTS_XML;
else if (DRM_MIMETYPE_RIGHTS_WBXML_STRING.equals(mimeTypeStr))
mimeType = DRM_MIMETYPE_RIGHTS_WBXML;
else if (DrmRawContent.DRM_MIMETYPE_MESSAGE_STRING.equals(mimeTypeStr))
mimeType = DRM_MIMETYPE_MESSAGE;
else
throw new IllegalArgumentException("mimeType must be DRM_MIMETYPE_RIGHTS_XML or DRM_MIMETYPE_RIGHTS_WBXML or DRM_MIMETYPE_MESSAGE");
if (len <= 0)
return null;
DrmRights rights = new DrmRights();
/* call native method to install this rights object. */
int res = nativeInstallDrmRights(rightsData, len, mimeType, rights);
if (JNI_DRM_FAILURE == res)
throw new DrmException("nativeInstallDrmRights() returned JNI_DRM_FAILURE");
return rights;
}
/**
* Query DRM rights of specified DRM raw content.
*
* @param content raw content object.
*
* @return the instance of DrmRights, or null if there is no rights.
*/
public synchronized DrmRights queryRights(DrmRawContent content) {
DrmRights rights = new DrmRights();
/* call native method to query the rights */
int res = nativeQueryRights(content, rights);
if (JNI_DRM_FAILURE == res)
return null;
return rights;
}
/**
* Get the list of all DRM rights saved in local client.
*
* @return the list of all the rights object.
*/
public synchronized List getRightsList() {
List rightsList = new ArrayList();
/* call native method to get how many rights object in current agent */
int num = nativeGetNumOfRights();
if (JNI_DRM_FAILURE == num)
return null;
if (num > 0) {
DrmRights[] rightsArray = new DrmRights[num];
int i;
for (i = 0; i < num; i++)
rightsArray[i] = new DrmRights();
/* call native method to get all the rights information */
num = nativeGetRightsList(rightsArray, num);
if (JNI_DRM_FAILURE == num)
return null;
/* add all rights informations to ArrayList */
for (i = 0; i < num; i++)
rightsList.add(rightsArray[i]);
}
return rightsList;
}
/**
* Delete the specified DRM rights object.
*
* @param rights the specified rights object to be deleted.
*/
public synchronized void deleteRights(DrmRights rights) {
/* call native method to delete the specified rights object */
int res = nativeDeleteRights(rights);
if (JNI_DRM_FAILURE == res)
return;
}
/**
* native method: install rights object to local client.
*
* @param data input DRM rights object data to be installed.
* @param len the length of the data.
* @param mimeType the mime type of this DRM rights object. the value of this field includes:
* #DRM_MIMETYPE_RIGHTS_XML
* #DRM_MIMETYPE_RIGHTS_WBXML
* @parma rights the instance of DRMRights to be filled.
*
* @return #JNI_DRM_SUCCESS if succeed.
* #JNI_DRM_FAILURE if fail.
*/
private native int nativeInstallDrmRights(InputStream data, int len, int mimeType, DrmRights rights);
/**
* native method: query the given DRM content's rights object.
*
* @param content the given DRM content.
* @param rights the instance of rights to set if have.
*
* @return #JNI_DRM_SUCCESS if succeed.
* #JNI_DRM_FAILURE if fail.
*/
private native int nativeQueryRights(DrmRawContent content, DrmRights rights);
/**
* native method: get how many rights object in current DRM agent.
*
* @return the number of the rights object.
* #JNI_DRM_FAILURE if fail.
*/
private native int nativeGetNumOfRights();
/**
* native method: get all the rights object in current local agent.
*
* @param rights the array instance of rights object.
* @param numRights how many rights can be saved.
*
* @return the number of the rights object has been gotten.
* #JNI_DRM_FAILURE if fail.
*/
private native int nativeGetRightsList(DrmRights[] rights, int numRights);
/**
* native method: delete a specified rights object.
*
* @param rights the specified rights object to be deleted.
*
* @return #JNI_DRM_SUCCESS if succeed.
* #JNI_DRM_FAILURE if fail.
*/
private native int nativeDeleteRights(DrmRights rights);
/**
* Load the shared library to link the native methods.
*/
static {
try {
System.loadLibrary("drm1_jni");
}
catch (UnsatisfiedLinkError ule) {
System.err.println("WARNING: Could not load libdrm1_jni.so");
}
}
}
|