Skip to content

Commit 4e197ea

Browse files
Gloria WangAndroid Git Automerger
authored andcommitted
am e15a73e: Merge "Bug fixes in OMA DRM v1 Forward Lock Agent"
* commit 'e15a73ee4c9a28d89888095c7649a70c116ee160': Bug fixes in OMA DRM v1 Forward Lock Agent
2 parents b9e8b25 + e15a73e commit 4e197ea

File tree

6 files changed

+257
-183
lines changed

6 files changed

+257
-183
lines changed

drm/libdrmframework/plugins/common/util/include/SessionMap.h

Lines changed: 136 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -13,141 +13,175 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
1716
#ifndef __SESSIONMAP_H__
1817
#define __SESSIONMAP_H__
1918

2019
#include <utils/KeyedVector.h>
20+
#include <utils/threads.h>
2121

2222
namespace android {
2323

2424
/**
25-
* A wrapper template class for handling DRM Engine sessions.
25+
* A thread safe wrapper template class for session handlings for Drm Engines. It wraps a
26+
* pointer type over KeyedVector. It keeps pointer as data in the vector and free up memory
27+
* allocated pointer can be of any type of structure/class meant for keeping session data.
28+
* so session object here means pointer to the session data.
2629
*/
27-
template <typename NODE>
30+
template <typename TValue>
2831
class SessionMap {
2932

3033
public:
31-
KeyedVector<int, NODE> map;
32-
3334
SessionMap() {}
3435

3536
virtual ~SessionMap() {
37+
Mutex::Autolock lock(mLock);
3638
destroyMap();
3739
}
3840

39-
/**
40-
* Adds a new value in the session map table. It expects memory to be allocated already
41-
* for the session object
42-
*
43-
* @param key - key or Session ID
44-
* @param value - session object to add
45-
*
46-
* @return boolean result of adding value. returns false if key is already exist.
47-
*/
48-
bool addValue(int key, NODE value) {
49-
bool result = false;
50-
51-
if (!isCreated(key)) {
52-
map.add(key, value);
53-
result = true;
41+
/**
42+
* Adds a new value in the session map table. It expects memory to be allocated already
43+
* for the session object
44+
*
45+
* @param key - key or Session ID
46+
* @param value - session object to add
47+
*
48+
* @return boolean result of adding value. returns false if key is already exist.
49+
*/
50+
bool addValue(int key, TValue value) {
51+
Mutex::Autolock lock(mLock);
52+
if (!isCreatedInternal(key)) {
53+
map.add(key, value);
54+
return true;
55+
}
56+
return false;
5457
}
5558

56-
return result;
57-
}
58-
59-
60-
/**
61-
* returns the session object by the key
62-
*
63-
* @param key - key or Session ID
64-
*
65-
* @return session object as per the key
66-
*/
67-
NODE getValue(int key) {
68-
NODE value = NULL;
69-
70-
if (isCreated(key)) {
71-
value = (NODE) map.valueFor(key);
59+
/**
60+
* returns the session object by the key
61+
*
62+
* @param key - key or Session ID
63+
*
64+
* @return session object as per the key
65+
*/
66+
TValue getValue(int key) {
67+
Mutex::Autolock lock(mLock);
68+
return getValueInternal(key);
7269
}
7370

74-
return value;
75-
}
76-
77-
/**
78-
* returns the number of objects in the session map table
79-
*
80-
* @return count of number of session objects.
81-
*/
82-
int getSize() {
83-
return map.size();
84-
}
85-
86-
/**
87-
* returns the session object by the index in the session map table
88-
*
89-
* @param index - index of the value required
90-
*
91-
* @return session object as per the index
92-
*/
93-
NODE getValueAt(unsigned int index) {
94-
NODE value = NULL;
71+
/**
72+
* returns the number of objects in the session map table
73+
*
74+
* @return count of number of session objects.
75+
*/
76+
int getSize() {
77+
Mutex::Autolock lock(mLock);
78+
return map.size();
79+
}
9580

96-
if (map.size() > index) {
97-
value = map.valueAt(index);
81+
/**
82+
* returns the session object by the index in the session map table
83+
*
84+
* @param index - index of the value required
85+
*
86+
* @return session object as per the index
87+
*/
88+
TValue getValueAt(unsigned int index) {
89+
TValue value = NULL;
90+
Mutex::Autolock lock(mLock);
91+
92+
if (map.size() > index) {
93+
value = map.valueAt(index);
94+
}
95+
return value;
9896
}
9997

100-
return value;
101-
}
98+
/**
99+
* deletes the object from session map. It also frees up memory for the session object.
100+
*
101+
* @param key - key of the value to be deleted
102+
*
103+
*/
104+
void removeValue(int key) {
105+
Mutex::Autolock lock(mLock);
106+
deleteValue(getValueInternal(key));
107+
map.removeItem(key);
108+
}
102109

103-
/**
104-
* deletes the object from session map. It also frees up memory for the session object.
105-
*
106-
* @param key - key of the value to be deleted
107-
*
108-
*/
109-
void removeValue(int key) {
110-
deleteValue(getValue(key));
111-
map.removeItem(key);
112-
}
110+
/**
111+
* decides if session is already created.
112+
*
113+
* @param key - key of the value for the session
114+
*
115+
* @return boolean result of whether session is created
116+
*/
117+
bool isCreated(int key) {
118+
Mutex::Autolock lock(mLock);
119+
return isCreatedInternal(key);
120+
}
113121

114-
/**
115-
* decides if session is already created.
116-
*
117-
* @param key - key of the value for the session
118-
*
119-
* @return boolean result of whether session is created
120-
*/
121-
bool isCreated(int key) {
122-
return (0 <= map.indexOfKey(key));
123-
}
122+
SessionMap<TValue> & operator=(const SessionMap<TValue> & objectCopy) {
123+
Mutex::Autolock lock(mLock);
124124

125-
/**
126-
* empty the entire session table. It releases all the memory for session objects.
127-
*/
128-
void destroyMap() {
129-
int size = map.size();
130-
int i = 0;
125+
destroyMap();
126+
map = objectCopy.map;
127+
return *this;
128+
}
131129

132-
for (i = 0; i < size; i++) {
133-
deleteValue(map.valueAt(i));
130+
private:
131+
KeyedVector<int, TValue> map;
132+
Mutex mLock;
133+
134+
/**
135+
* free up the memory for the session object.
136+
* Make sure if any reference to the session object anywhere, otherwise it will be a
137+
* dangle pointer after this call.
138+
*
139+
* @param value - session object to free
140+
*
141+
*/
142+
void deleteValue(TValue value) {
143+
delete value;
134144
}
135145

136-
map.clear();
137-
}
146+
/**
147+
* free up the memory for the entire map.
148+
* free up any resources in the sessions before calling this funtion.
149+
*
150+
*/
151+
void destroyMap() {
152+
int size = map.size();
153+
154+
for (int i = 0; i < size; i++) {
155+
deleteValue(map.valueAt(i));
156+
}
157+
map.clear();
158+
}
138159

139-
/**
140-
* free up the memory for the session object.
141-
* Make sure if any reference to the session object anywhere, otherwise it will be a
142-
* dangle pointer after this call.
143-
*
144-
* @param value - session object to free
145-
*
146-
*/
147-
void deleteValue(NODE value) {
148-
delete value;
149-
}
160+
/**
161+
* decides if session is already created.
162+
*
163+
* @param key - key of the value for the session
164+
*
165+
* @return boolean result of whether session is created
166+
*/
167+
bool isCreatedInternal(int key) {
168+
return(0 <= map.indexOfKey(key));
169+
}
150170

171+
/**
172+
* returns the session object by the key
173+
*
174+
* @param key - key or Session ID
175+
*
176+
* @return session object as per the key
177+
*/
178+
TValue getValueInternal(int key) {
179+
TValue value = NULL;
180+
if (isCreatedInternal(key)) {
181+
value = (TValue) map.valueFor(key);
182+
}
183+
return value;
184+
}
151185
};
152186

153187
};

drm/libdrmframework/plugins/common/util/src/MimeTypeUtil.cpp

Lines changed: 37 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@ namespace android {
2222
#undef LOG_TAG
2323
#define LOG_TAG "MimeTypeUtil"
2424

25+
#ifdef DRM_OMA_FL_ENGINE_DEBUG
26+
#define LOG_NDEBUG 0
27+
#define LOG_DEBUG(...) LOGD(__VA_ARGS__)
28+
#else
29+
#define LOG_DEBUG(...)
30+
#endif
31+
2532
enum {
2633
MIMETYPE_AUDIO = 0,
2734
MIMETYPE_APPLICATION = 1,
@@ -59,6 +66,7 @@ static const char mime_group_audio[] = "audio/";
5966
static const char mime_group_application[] = "application/";
6067
static const char mime_group_image[] = "image/";
6168
static const char mime_group_video[] = "video/";
69+
static const char mime_type_unsupported[] = "unsupported/drm.mimetype";
6270

6371
static struct MimeGroup mimeGroup[] = {
6472
{MIMETYPE_AUDIO, mime_group_audio, sizeof(mime_group_audio)-1},
@@ -107,48 +115,52 @@ static struct MimeTypeList mimeTypeList[] = {
107115
* replacement mimetype otherwise the original mimetype
108116
* is returned.
109117
*
118+
* If the mimetype is of unsupported group i.e. application/*
119+
* then "unsupported/drm.mimetype" will be returned.
120+
*
110121
* @param mimeType - mimetype in lower case to convert.
111122
*
112-
* @return mimetype or null.
123+
* @return mimetype or "unsupported/drm.mimetype".
113124
*/
114125
String8 MimeTypeUtil::convertMimeType(String8& mimeType) {
115126
String8 result = mimeType;
116-
const char* pTmp;
117127
const char* pMimeType;
118128
struct MimeGroup* pGroup;
119129
struct MimeTypeList* pMimeItem;
120130
int len;
121-
122131
pMimeType = mimeType.string();
123132
if (NULL != pMimeType) {
124-
/* Check which group the mimetype is */
125-
pGroup = mimeGroup;
126-
127-
while (MIMETYPE_LAST != pGroup->type) {
128-
if (0 == strncmp(pMimeType, pGroup->pGroup, pGroup->size)) {
129-
break;
133+
if ((0 == strncmp(pMimeType, mime_group_audio, (sizeof mime_group_audio) - 1)) ||
134+
(0 == strncmp(pMimeType, mime_group_video, (sizeof mime_group_video) - 1))) {
135+
/* Check which group the mimetype is */
136+
pGroup = mimeGroup;
137+
while (MIMETYPE_LAST != pGroup->type) {
138+
if (0 == strncmp(pMimeType, pGroup->pGroup, pGroup->size)) {
139+
break;
140+
}
141+
pGroup++;
130142
}
131-
pGroup++;
132-
}
133-
134-
/* Go through the mimetype list. Only check items of the correct group */
135-
if (MIMETYPE_LAST != pGroup->type) {
136-
pMimeItem = mimeTypeList;
137-
len = strlen (pMimeType+pGroup->size);
138143

139-
while (MIMETYPE_LAST != pMimeItem->type) {
140-
if ((len == pMimeItem->size) &&
141-
(0 == strcmp(pMimeType+pGroup->size, pMimeItem->pMimeExt))) {
142-
result = String8(pMimeItem->pMimeType);
143-
break;
144+
/* Go through the mimetype list. Only check items of the correct group */
145+
if (MIMETYPE_LAST != pGroup->type) {
146+
pMimeItem = mimeTypeList;
147+
len = strlen (pMimeType+pGroup->size);
148+
while (MIMETYPE_LAST != pMimeItem->type) {
149+
if ((pGroup->type == pMimeItem->type) &&
150+
(len == pMimeItem->size) &&
151+
(0 == strcmp(pMimeType+pGroup->size, pMimeItem->pMimeExt))) {
152+
result = String8(pMimeItem->pMimeType);
153+
break;
154+
}
155+
pMimeItem++;
144156
}
145-
pMimeItem++;
146157
}
158+
} else {
159+
result = String8(mime_type_unsupported);
147160
}
148-
LOGI("convertMimeType got mimetype %s, converted into mimetype %s",
149-
pMimeType, result.string());
161+
LOG_DEBUG("convertMimeType got mimetype %s, converted into mimetype %s",
162+
pMimeType, result.string());
150163
}
151-
152164
return result;
153165
}
154166
};

drm/libdrmframework/plugins/forward-lock/FwdLockEngine/Android.mk

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ LOCAL_PATH := $(call my-dir)
1717

1818
include $(CLEAR_VARS)
1919

20+
# The flag below turns on local debug printouts
21+
#LOCAL_CFLAGS += -DDRM_OMA_FL_ENGINE_DEBUG
22+
2023
base := frameworks/base
2124

2225
# Determine whether the DRM framework uses 64-bit data types for file offsets and do the same.

0 commit comments

Comments
 (0)