Skip to content
This repository was archived by the owner on Aug 27, 2024. It is now read-only.

Commit c999be7

Browse files
committed
[CP] Change Class PortManager to be inheritable and declare SetPortProperty as virtual function.
By default, port property is set through drm ioctl call. On Android, port property is set by Hardware Composer. On ClearLinux, port property is set by IAS. Hence, use polymorphism to override SetPortProperty to enhance code readability. [Internal] Platforms: All OS: Linux Feature impact: HDCP Related-to: VSMGWL-21388 Resolves: Klockwork: PASS Change-Id: I21e592e11fd80d72733b6c47921cc5ffb632760f Signed-off-by: Yu Shiqiang <shiqiang.yu@intel.com>
1 parent ed29b22 commit c999be7

File tree

2 files changed

+157
-10
lines changed

2 files changed

+157
-10
lines changed

daemon/portmanager.cpp

Lines changed: 101 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,11 @@ int32_t PortManagerInit(HdcpDaemon& socket)
303303
return EEXIST;
304304
}
305305

306+
#ifdef ANDROID
307+
portMgr = new (std::nothrow) PortManagerHWComposer(socket);
308+
#else
306309
portMgr = new (std::nothrow) PortManager(socket);
310+
#endif
307311
if (nullptr == portMgr)
308312
{
309313
HDCP_ASSERTMESSAGE("Failed to allocate the port manager!");
@@ -857,16 +861,16 @@ int32_t PortManager::DisablePort(const uint32_t portId, const uint32_t appId)
857861
if (SUCCESS != ret)
858862
{
859863
HDCP_ASSERTMESSAGE(
860-
"Failed to enable port with id %d, set property faild",
864+
"Failed to disable port with id %d, set property faild",
861865
portId);
862866
return EBUSY;
863867
}
864868

865-
// Check whether Content Protection property is CP_OFF or not
869+
// Check whether Content Protection property is CP_OFF or not
866870
drmObject->CpTypeAtomicBegin();
867871
uint8_t cpType = CP_TYPE_INVALID;
868872
ret = GetProtectionInfo(drmObject, &cpValue, &cpType);
869-
if (SUCCESS != ret)
873+
if (SUCCESS != ret)
870874
{
871875
drmObject->CpTypeAtomicEnd();
872876
HDCP_ASSERTMESSAGE("Failed to get protection info");
@@ -1144,7 +1148,7 @@ int32_t PortManager::SetPortProperty(
11441148
int32_t propId,
11451149
int32_t size,
11461150
const uint8_t *value,
1147-
const uint32_t numRetry)
1151+
uint32_t numRetry)
11481152
{
11491153
HDCP_FUNCTION_ENTER;
11501154

@@ -1348,3 +1352,96 @@ DrmObject *PortManager::GetDrmObjectByDrmId(const uint32_t drmId)
13481352
return nullptr;
13491353
}
13501354

1355+
#ifdef ANDROID
1356+
PortManagerHWComposer::PortManagerHWComposer(HdcpDaemon& daemonSocket) :
1357+
PortManager(daemonSocket)
1358+
{
1359+
HDCP_FUNCTION_ENTER;
1360+
1361+
HDCP_FUNCTION_EXIT(SUCCESS);
1362+
}
1363+
1364+
int32_t PortManagerHWComposer::SetPortProperty(
1365+
int32_t drmId,
1366+
int32_t propId,
1367+
int32_t size,
1368+
const uint8_t *value,
1369+
uint32_t numRetry)
1370+
{
1371+
HDCP_FUNCTION_ENTER;
1372+
1373+
int32_t ret = EINVAL;
1374+
1375+
DrmObject *drmObject = GetDrmObjectByDrmId(drmId);
1376+
if (nullptr == drmObject)
1377+
{
1378+
HDCP_ASSERTMESSAGE("Port drm object found to be nullptr");
1379+
return ENOENT;
1380+
}
1381+
1382+
if (nullptr == value)
1383+
{
1384+
HDCP_ASSERTMESSAGE("Prop value found to be nullptr");
1385+
return ENOENT;
1386+
}
1387+
1388+
uint8_t propValue = *value;
1389+
1390+
android::ProcessState::initWithDriver(BINDER_IPC);
1391+
1392+
// Connect to HWC service
1393+
HWCSHANDLE hwcs = HwcService_Connect();
1394+
if (nullptr == hwcs)
1395+
{
1396+
HDCP_ASSERTMESSAGE("Could not connect to hwcservice");
1397+
return EINVAL;
1398+
}
1399+
1400+
while (numRetry--)
1401+
{
1402+
if (propId == drmObject->GetPropertyId(CONTENT_PROTECTION) &&
1403+
propValue == CP_OFF)
1404+
{
1405+
HDCP_NORMALMESSAGE("Set content protection property (off) via HWC");
1406+
ret = HwcService_Video_DisableHDCPSession_ForDisplay(hwcs, drmId);
1407+
}
1408+
else if (propId == drmObject->GetPropertyId(CONTENT_PROTECTION))
1409+
{
1410+
HDCP_NORMALMESSAGE("Set content protection property (on) via HWC");
1411+
ret = HwcService_Video_EnableHDCPSession_ForDisplay(hwcs, drmId,
1412+
(EHwcsContentType)propValue);
1413+
}
1414+
else if (propId == drmObject->GetPropertyId(CP_CONTENT_TYPE))
1415+
{
1416+
// This is only for HDCP2.2
1417+
HDCP_NORMALMESSAGE("Set content type property via HWC");
1418+
ret = HwcService_Video_EnableHDCPSession_ForDisplay(hwcs, drmId,
1419+
(EHwcsContentType)propValue);
1420+
}
1421+
else if(propId == drmObject->GetPropertyId(CP_SRM))
1422+
{
1423+
HDCP_NORMALMESSAGE("Set SRM for Display");
1424+
ret = HwcService_Video_SetHDCPSRM_ForDisplay(hwcs, drmId,
1425+
(const int8_t *)&value, size);
1426+
}
1427+
else
1428+
{
1429+
HDCP_ASSERTMESSAGE("Property id not supported");
1430+
ret = EINVAL;
1431+
}
1432+
1433+
if (SUCCESS == ret)
1434+
break;
1435+
}
1436+
1437+
HwcService_Disconnect(hwcs);
1438+
1439+
if (SUCCESS != ret)
1440+
{
1441+
HDCP_ASSERTMESSAGE("Failed to set port property via HWC");
1442+
}
1443+
1444+
HDCP_FUNCTION_EXIT(ret);
1445+
return ret;
1446+
}
1447+
#endif

daemon/portmanager.h

Lines changed: 56 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,16 @@
3535
#include "hdcpapi.h"
3636
#include "port.h"
3737

38+
#ifdef ANDROID
39+
#include <hwcserviceapi.h>
40+
#include <log/log.h>
41+
#include <binder/IServiceManager.h>
42+
#include <binder/ProcessState.h>
43+
#include <iservice.h>
44+
45+
#define BINDER_IPC "/dev/vndbinder"
46+
#endif
47+
3848
#define THREAD_STARTUP_BACKOFF_DELAY_US 100
3949
#define AUTH_CHECK_DELAY_MS 1000
4050
#define INTEGRITY_CHECK_DELAY_MS 500
@@ -109,14 +119,14 @@ class PortManager
109119
PortManager(HdcpDaemon& daemonSocket);
110120

111121
///////////////////////////////////////////////////////////////////////////
112-
/// \brief Destructor for PortManager
122+
/// \brief Virtual destructor for PortManager
113123
///
114124
/// \return nothing -- It's a destructor
115125
///
116126
/// This will cleanup any ports currently in the port list
117127
/// Any dynamic memory controlled by the PortManager should be released
118128
///////////////////////////////////////////////////////////////////////////
119-
~PortManager(void);
129+
virtual ~PortManager(void);
120130

121131
///////////////////////////////////////////////////////////////////////////
122132
/// \brief Checks if the portmanager was successfully created
@@ -215,7 +225,7 @@ class PortManager
215225
void DisableAllPorts();
216226

217227
// Declare private functions
218-
private:
228+
protected:
219229

220230
///////////////////////////////////////////////////////////////////////////
221231
/// \brief Get DrmObject by port Id
@@ -247,7 +257,10 @@ class PortManager
247257
uint8_t *cpType);
248258

249259
///////////////////////////////////////////////////////////////////////////
250-
/// \brief Set Port Property
260+
/// \brief Virtual function set port property. By default, port property is
261+
/// set through drm ioctl call. On ClearLinux, port property is set
262+
/// through IAS. On Andorid, port property is set through Hardware
263+
/// Composer.
251264
///
252265
/// \param[in] drmId, Id of the drm object
253266
/// \param[in] propertyId, Id of property
@@ -256,7 +269,7 @@ class PortManager
256269
/// \param[in] numRetry, the retry times
257270
/// \return int32_t Function return status
258271
///////////////////////////////////////////////////////////////////////////
259-
int32_t SetPortProperty(
272+
virtual int32_t SetPortProperty(
260273
int32_t drmId,
261274
int32_t propertyId,
262275
int32_t size,
@@ -278,10 +291,47 @@ class PortManager
278291
/// \return int32_t Function return status
279292
///////////////////////////////////////////////////////////////////////////
280293
int32_t InitDrmObjects();
281-
294+
282295
static void SigCatcher(int sig);
283296
};
284297

298+
#ifdef ANDROID
299+
class PortManagerHWComposer : public PortManager
300+
{
301+
public:
302+
303+
///////////////////////////////////////////////////////////////////////////
304+
/// \brief Constructor for the PortManagerHWComposer class,
305+
/// this is for Android platform.
306+
///
307+
/// \return Nothing
308+
///
309+
/// Callers must check the newly created manager against IsValid.
310+
///////////////////////////////////////////////////////////////////////////
311+
PortManagerHWComposer(HdcpDaemon& daemonSocket);
312+
313+
///////////////////////////////////////////////////////////////////////////
314+
/// \brief Virtual function set port property. By default, port property is
315+
/// set through drm ioctl call. On ClearLinux, port property is set
316+
/// through IAS. On Andorid, port property is set through Hardware
317+
/// Composer.
318+
///
319+
/// \param[in] drmId, Id of the drm object
320+
/// \param[in] propertyId, Id of property
321+
/// \param[in] size, Length of value, it's an array
322+
/// \param[in] value, Pointer of the array
323+
/// \param[in] numRetry, the retry times
324+
/// \return int32_t Function return status
325+
///////////////////////////////////////////////////////////////////////////
326+
virtual int32_t SetPortProperty(
327+
int32_t drmId,
328+
int32_t propertyId,
329+
int32_t size,
330+
const uint8_t *value,
331+
uint32_t numRetry);
332+
};
333+
#endif
334+
285335
///////////////////////////////////////////////////////////////////////////////
286336
/// \brief Create the local instance of the PortManager
287337
///

0 commit comments

Comments
 (0)