Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c7b3ccc5 authored by Takeshi Aimi's avatar Takeshi Aimi
Browse files

Update of DRM framework

 - Overload openDecryptSession() with uri parameter
   in order to accept URI of DRM content,
   Following API is added,
       DecryptHandle*openDecryptSession(const char* uri);.
 - Unify texisting three event types of processDrmInfo()
   so that caller of DRM framework does not have to handle many event types.
 - Let DrmManagerService call load/unload plugins API so that
   client of DRM framework does not have to manage plug-in load/unload.
 - Trivial fix in DrmManagerClient.java is also incorporated.

Changes are made by Sony Corporation.

Change-Id: If62b47fa0360718fdc943e6e6143671d7db26adc
parent 5b4d0e84
Loading
Loading
Loading
Loading
+17 −115
Original line number Diff line number Diff line
@@ -55656,29 +55656,7 @@
 type="int"
 transient="false"
 volatile="false"
 value="2012"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="TYPE_FINALIZE_FAILED"
 type="int"
 transient="false"
 volatile="false"
 value="2010"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="TYPE_INITIALIZE_FAILED"
 type="int"
 transient="false"
 volatile="false"
 value="2009"
 value="2008"
 static="true"
 final="true"
 deprecated="not deprecated"
@@ -55718,7 +55696,7 @@
 visibility="public"
>
</field>
<field name="TYPE_REGISTRATION_FAILED"
<field name="TYPE_PROCESS_DRM_INFO_FAILED"
 type="int"
 transient="false"
 volatile="false"
@@ -55733,18 +55711,7 @@
 type="int"
 transient="false"
 volatile="false"
 value="2011"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="TYPE_RIGHTS_ACQUISITION_FAILED"
 type="int"
 transient="false"
 volatile="false"
 value="2008"
 value="2007"
 static="true"
 final="true"
 deprecated="not deprecated"
@@ -55773,17 +55740,6 @@
 visibility="public"
>
</field>
<field name="TYPE_UNREGISTRATION_FAILED"
 type="int"
 transient="false"
 volatile="false"
 value="2007"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
</class>
<class name="DrmEvent"
 extends="java.lang.Object"
@@ -55863,28 +55819,6 @@
>
</field>
<field name="TYPE_ALL_RIGHTS_REMOVED"
 type="int"
 transient="false"
 volatile="false"
 value="1006"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="TYPE_DRM_INFO_ACQUIRED"
 type="int"
 transient="false"
 volatile="false"
 value="1007"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="TYPE_FINALIZED"
 type="int"
 transient="false"
 volatile="false"
@@ -55895,7 +55829,7 @@
 visibility="public"
>
</field>
<field name="TYPE_INITIALIZED"
<field name="TYPE_DRM_INFO_ACQUIRED"
 type="int"
 transient="false"
 volatile="false"
@@ -55906,7 +55840,7 @@
 visibility="public"
>
</field>
<field name="TYPE_REGISTERED"
<field name="TYPE_DRM_INFO_PROCESSED"
 type="int"
 transient="false"
 volatile="false"
@@ -55917,28 +55851,6 @@
 visibility="public"
>
</field>
<field name="TYPE_RIGHTS_ACQUIRED"
 type="int"
 transient="false"
 volatile="false"
 value="1005"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="TYPE_UNREGISTERED"
 type="int"
 transient="false"
 volatile="false"
 value="1004"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
</class>
<class name="DrmInfo"
 extends="java.lang.Object"
@@ -56314,6 +56226,8 @@
>
<parameter name="_statusCode" type="int">
</parameter>
<parameter name="_infoType" type="int">
</parameter>
<parameter name="_data" type="android.drm.ProcessedData">
</parameter>
<parameter name="_mimeType" type="java.lang.String">
@@ -56351,6 +56265,16 @@
 visibility="public"
>
</field>
<field name="infoType"
 type="int"
 transient="false"
 volatile="false"
 static="false"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="mimeType"
 type="java.lang.String"
 transient="false"
@@ -56614,17 +56538,6 @@
<parameter name="uri" type="android.net.Uri">
</parameter>
</method>
<method name="loadPlugIns"
 return="int"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
</method>
<method name="openConvertSession"
 return="int"
 abstract="false"
@@ -56746,17 +56659,6 @@
<parameter name="infoListener" type="android.drm.DrmManagerClient.OnInfoListener">
</parameter>
</method>
<method name="unloadPlugIns"
 return="int"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
</method>
<field name="ERROR_NONE"
 type="int"
 transient="false"
+5 −0
Original line number Diff line number Diff line
@@ -120,6 +120,11 @@ status_t DrmEngineBase::openDecryptSession(
    return onOpenDecryptSession(uniqueId, decryptHandle, fd, offset, length);
}

status_t DrmEngineBase::openDecryptSession(
    int uniqueId, DecryptHandle* decryptHandle, const char* uri) {
    return onOpenDecryptSession(uniqueId, decryptHandle, uri);
}

status_t DrmEngineBase::closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle) {
    return onCloseDecryptSession(uniqueId, decryptHandle);
}
+2 −1
Original line number Diff line number Diff line
@@ -19,8 +19,9 @@
using namespace android;

DrmInfoStatus::DrmInfoStatus(
    int _statusCode, const DrmBuffer* _drmBuffer, const String8& _mimeType) :
    int _statusCode, int _infoType, const DrmBuffer* _drmBuffer, const String8& _mimeType) :
    statusCode(_statusCode),
    infoType(_infoType),
    drmBuffer(_drmBuffer),
    mimeType(_mimeType) {

+68 −51
Original line number Diff line number Diff line
@@ -53,27 +53,18 @@ void BpDrmManagerService::removeUniqueId(int uniqueId) {
    remote()->transact(REMOVE_UNIQUEID, data, &reply);
}

status_t BpDrmManagerService::loadPlugIns(int uniqueId) {
    LOGV("load plugins");
void BpDrmManagerService::addClient(int uniqueId) {
    Parcel data, reply;

    data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor());
    data.writeInt32(uniqueId);

    remote()->transact(LOAD_PLUGINS, data, &reply);
    return reply.readInt32();
    remote()->transact(ADD_CLIENT, data, &reply);
}

status_t BpDrmManagerService::loadPlugIns(int uniqueId, const String8& plugInDirPath) {
    LOGV("load plugins from path");
void BpDrmManagerService::removeClient(int uniqueId) {
    Parcel data, reply;

    data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor());
    data.writeInt32(uniqueId);
    data.writeString8(plugInDirPath);

    remote()->transact(LOAD_PLUGINS_FROM_PATH, data, &reply);
    return reply.readInt32();
    remote()->transact(REMOVE_CLIENT, data, &reply);
}

status_t BpDrmManagerService::setDrmServiceListener(
@@ -88,17 +79,6 @@ status_t BpDrmManagerService::setDrmServiceListener(
    return reply.readInt32();
}

status_t BpDrmManagerService::unloadPlugIns(int uniqueId) {
    LOGV("unload plugins");
    Parcel data, reply;

    data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor());
    data.writeInt32(uniqueId);

    remote()->transact(UNLOAD_PLUGINS, data, &reply);
    return reply.readInt32();
}

status_t BpDrmManagerService::installDrmEngine(int uniqueId, const String8& drmEngineFile) {
    LOGV("Install DRM Engine");
    Parcel data, reply;
@@ -191,6 +171,7 @@ DrmInfoStatus* BpDrmManagerService::processDrmInfo(int uniqueId, const DrmInfo*
    if (0 != reply.dataAvail()) {
        //Filling DRM Info Status
        const int statusCode = reply.readInt32();
        const int infoType = reply.readInt32();
        const String8 mimeType = reply.readString8();

        DrmBuffer* drmBuffer = NULL;
@@ -203,7 +184,7 @@ DrmInfoStatus* BpDrmManagerService::processDrmInfo(int uniqueId, const DrmInfo*
            }
            drmBuffer = new DrmBuffer(data, bufferSize);
        }
        drmInfoStatus = new DrmInfoStatus(statusCode, drmBuffer, mimeType);
        drmInfoStatus = new DrmInfoStatus(statusCode, infoType, drmBuffer, mimeType);
    }
    return drmInfoStatus;
}
@@ -538,8 +519,7 @@ DecryptHandle* BpDrmManagerService::openDecryptSession(
    LOGV("Entering BpDrmManagerService::openDecryptSession");
    Parcel data, reply;

    const String16 interfaceDescriptor = IDrmManagerService::getInterfaceDescriptor();
    data.writeInterfaceToken(interfaceDescriptor);
    data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor());
    data.writeInt32(uniqueId);
    data.writeFileDescriptor(fd);
    data.writeInt32(offset);
@@ -565,6 +545,34 @@ DecryptHandle* BpDrmManagerService::openDecryptSession(
    return handle;
}

DecryptHandle* BpDrmManagerService::openDecryptSession(int uniqueId, const char* uri) {
    LOGV("Entering BpDrmManagerService::openDecryptSession");
    Parcel data, reply;

    data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor());
    data.writeInt32(uniqueId);
    data.writeString8(String8(uri));

    remote()->transact(OPEN_DECRYPT_SESSION_FROM_URI, data, &reply);

    DecryptHandle* handle = NULL;
    if (0 != reply.dataAvail()) {
        handle = new DecryptHandle();
        handle->decryptId = reply.readInt32();
        handle->mimeType = reply.readString8();
        handle->decryptApiType = reply.readInt32();
        handle->status = reply.readInt32();
        handle->decryptInfo = NULL;
        if (0 != reply.dataAvail()) {
            handle->decryptInfo = new DecryptInfo();
            handle->decryptInfo->decryptBufferLength = reply.readInt32();
        }
    } else {
        LOGE("no decryptHandle is generated in service side");
    }
    return handle;
}

status_t BpDrmManagerService::closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle) {
    LOGV("closeDecryptSession");
    Parcel data, reply;
@@ -746,25 +754,19 @@ status_t BnDrmManagerService::onTransact(
        return DRM_NO_ERROR;
    }

    case LOAD_PLUGINS:
    case ADD_CLIENT:
    {
        LOGV("BnDrmManagerService::onTransact :LOAD_PLUGINS");
        LOGV("BnDrmManagerService::onTransact :ADD_CLIENT");
        CHECK_INTERFACE(IDrmManagerService, data, reply);

        status_t status = loadPlugIns(data.readInt32());

        reply->writeInt32(status);
        addClient(data.readInt32());
        return DRM_NO_ERROR;
    }

    case LOAD_PLUGINS_FROM_PATH:
    case REMOVE_CLIENT:
    {
        LOGV("BnDrmManagerService::onTransact :LOAD_PLUGINS_FROM_PATH");
        LOGV("BnDrmManagerService::onTransact :REMOVE_CLIENT");
        CHECK_INTERFACE(IDrmManagerService, data, reply);

        status_t status = loadPlugIns(data.readInt32(), data.readString8());

        reply->writeInt32(status);
        removeClient(data.readInt32());
        return DRM_NO_ERROR;
    }

@@ -783,18 +785,6 @@ status_t BnDrmManagerService::onTransact(
        return DRM_NO_ERROR;
    }

    case UNLOAD_PLUGINS:
    {
        LOGV("BnDrmManagerService::onTransact :UNLOAD_PLUGINS");
        CHECK_INTERFACE(IDrmManagerService, data, reply);

        const int uniqueId = data.readInt32();
        status_t status = unloadPlugIns(uniqueId);

        reply->writeInt32(status);
        return DRM_NO_ERROR;
    }

    case INSTALL_DRM_ENGINE:
    {
        LOGV("BnDrmManagerService::onTransact :INSTALL_DRM_ENGINE");
@@ -881,6 +871,7 @@ status_t BnDrmManagerService::onTransact(
        if (NULL != drmInfoStatus) {
            //Filling DRM Info Status contents
            reply->writeInt32(drmInfoStatus->statusCode);
            reply->writeInt32(drmInfoStatus->infoType);
            reply->writeString8(drmInfoStatus->mimeType);

            if (NULL != drmInfoStatus->drmBuffer) {
@@ -1239,6 +1230,32 @@ status_t BnDrmManagerService::onTransact(
        return DRM_NO_ERROR;
    }

    case OPEN_DECRYPT_SESSION_FROM_URI:
    {
        LOGV("BnDrmManagerService::onTransact :OPEN_DECRYPT_SESSION_FROM_URI");
        CHECK_INTERFACE(IDrmManagerService, data, reply);

        const int uniqueId = data.readInt32();
        const String8 uri = data.readString8();

        DecryptHandle* handle = openDecryptSession(uniqueId, uri.string());

        if (NULL != handle) {
            reply->writeInt32(handle->decryptId);
            reply->writeString8(handle->mimeType);
            reply->writeInt32(handle->decryptApiType);
            reply->writeInt32(handle->status);
            if (NULL != handle->decryptInfo) {
                reply->writeInt32(handle->decryptInfo->decryptBufferLength);
                delete handle->decryptInfo; handle->decryptInfo = NULL;
            }
        } else {
            LOGE("NULL decryptHandle is returned");
        }
        delete handle; handle = NULL;
        return DRM_NO_ERROR;
    }

    case CLOSE_DECRYPT_SESSION:
    {
        LOGV("BnDrmManagerService::onTransact :CLOSE_DECRYPT_SESSION");
+62 −46
Original line number Diff line number Diff line
@@ -85,22 +85,31 @@ void DrmManager::removeUniqueId(int uniqueId) {
    }
}

status_t DrmManager::loadPlugIns(int uniqueId) {
status_t DrmManager::loadPlugIns() {
    String8 pluginDirPath("/system/lib/drm/plugins/native");
    return loadPlugIns(uniqueId, pluginDirPath);
    return loadPlugIns(pluginDirPath);
}

status_t DrmManager::loadPlugIns(int uniqueId, const String8& plugInDirPath) {
status_t DrmManager::loadPlugIns(const String8& plugInDirPath) {
    if (mSupportInfoToPlugInIdMap.isEmpty()) {
        mPlugInManager.loadPlugIns(plugInDirPath);

        initializePlugIns(uniqueId);

        populate(uniqueId);
    } else {
        initializePlugIns(uniqueId);
        Vector<String8> plugInPathList = mPlugInManager.getPlugInIdList();
        for (unsigned int i = 0; i < plugInPathList.size(); ++i) {
            String8 plugInPath = plugInPathList[i];
            DrmSupportInfo* info = mPlugInManager.getPlugIn(plugInPath).getSupportInfo(0);
            if (NULL != info) {
                mSupportInfoToPlugInIdMap.add(*info, plugInPath);
            }
        }
    }
    return DRM_NO_ERROR;
}

status_t DrmManager::unloadPlugIns() {
    mConvertSessionMap.clear();
    mDecryptSessionMap.clear();
    mPlugInManager.unloadPlugIns();
    mSupportInfoToPlugInIdMap.clear();
    return DRM_NO_ERROR;
}

@@ -111,21 +120,23 @@ status_t DrmManager::setDrmServiceListener(
    return DRM_NO_ERROR;
}

status_t DrmManager::unloadPlugIns(int uniqueId) {
void DrmManager::addClient(int uniqueId) {
    if (!mSupportInfoToPlugInIdMap.isEmpty()) {
        Vector<String8> plugInIdList = mPlugInManager.getPlugInIdList();

        for (unsigned int index = 0; index < plugInIdList.size(); index++) {
            IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(plugInIdList.itemAt(index));
        rDrmEngine.terminate(uniqueId);
            rDrmEngine.initialize(uniqueId);
            rDrmEngine.setOnInfoListener(uniqueId, this);
        }
    }
}

    if (0 >= mUniqueIdVector.size()) {
        mConvertSessionMap.clear();
        mDecryptSessionMap.clear();
        mSupportInfoToPlugInIdMap.clear();
        mPlugInManager.unloadPlugIns();
void DrmManager::removeClient(int uniqueId) {
    Vector<String8> plugInIdList = mPlugInManager.getPlugInIdList();
    for (unsigned int index = 0; index < plugInIdList.size(); index++) {
        IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(plugInIdList.itemAt(index));
        rDrmEngine.terminate(uniqueId);
    }
    return DRM_NO_ERROR;
}

DrmConstraints* DrmManager::getConstraints(int uniqueId, const String8* path, const int action) {
@@ -144,7 +155,7 @@ status_t DrmManager::installDrmEngine(int uniqueId, const String8& absolutePath)
    rDrmEngine.initialize(uniqueId);
    rDrmEngine.setOnInfoListener(uniqueId, this);

    DrmSupportInfo* info = rDrmEngine.getSupportInfo(uniqueId);
    DrmSupportInfo* info = rDrmEngine.getSupportInfo(0);
    mSupportInfoToPlugInIdMap.add(*info, absolutePath);

    return DRM_NO_ERROR;
@@ -154,7 +165,7 @@ bool DrmManager::canHandle(int uniqueId, const String8& path, const String8& mim
    const String8 plugInId = getSupportedPlugInId(mimeType);
    bool result = (EMPTY_STRING != plugInId) ? true : false;

    if (NULL != path) {
    if (0 < path.length()) {
        if (result) {
            IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(plugInId);
            result = rDrmEngine.canHandle(uniqueId, path);
@@ -340,7 +351,7 @@ status_t DrmManager::getAllSupportInfo(
        for (int i = 0; i < size; ++i) {
            String8 plugInPath = plugInPathList[i];
            DrmSupportInfo* drmSupportInfo
                = mPlugInManager.getPlugIn(plugInPath).getSupportInfo(uniqueId);
                = mPlugInManager.getPlugIn(plugInPath).getSupportInfo(0);
            if (NULL != drmSupportInfo) {
                drmSupportInfoList.add(*drmSupportInfo);
                delete drmSupportInfo; drmSupportInfo = NULL;
@@ -360,12 +371,12 @@ status_t DrmManager::getAllSupportInfo(
}

DecryptHandle* DrmManager::openDecryptSession(int uniqueId, int fd, int offset, int length) {
    Mutex::Autolock _l(mDecryptLock);
    status_t result = DRM_ERROR_CANNOT_HANDLE;
    Vector<String8> plugInIdList = mPlugInManager.getPlugInIdList();

    DecryptHandle* handle = new DecryptHandle();
    if (NULL != handle) {
        Mutex::Autolock _l(mDecryptLock);
        handle->decryptId = mDecryptSessionId + 1;

        for (unsigned int index = 0; index < plugInIdList.size(); index++) {
@@ -380,16 +391,43 @@ DecryptHandle* DrmManager::openDecryptSession(int uniqueId, int fd, int offset,
            }
        }
    }

    if (DRM_NO_ERROR != result) {
        delete handle; handle = NULL;
        LOGE("DrmManager::openDecryptSession: no capable plug-in found");
    }
    return handle;
}

DecryptHandle* DrmManager::openDecryptSession(int uniqueId, const char* uri) {
    Mutex::Autolock _l(mDecryptLock);
    status_t result = DRM_ERROR_CANNOT_HANDLE;
    Vector<String8> plugInIdList = mPlugInManager.getPlugInIdList();

    DecryptHandle* handle = new DecryptHandle();
    if (NULL != handle) {
        handle->decryptId = mDecryptSessionId + 1;

        for (unsigned int index = 0; index < plugInIdList.size(); index++) {
            String8 plugInId = plugInIdList.itemAt(index);
            IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(plugInId);
            result = rDrmEngine.openDecryptSession(uniqueId, handle, uri);

            if (DRM_NO_ERROR == result) {
                ++mDecryptSessionId;
                mDecryptSessionMap.add(mDecryptSessionId, &rDrmEngine);
                break;
            }
        }
    }
    if (DRM_NO_ERROR != result) {
        delete handle; handle = NULL;
        LOGE("DrmManager::openDecryptSession: no capable plug-in found");
    }
    return handle;
}

status_t DrmManager::closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle) {
    Mutex::Autolock _l(mDecryptLock);
    status_t result = DRM_ERROR_UNKNOWN;
    if (mDecryptSessionMap.indexOfKey(decryptHandle->decryptId) != NAME_NOT_FOUND) {
        IDrmEngine* drmEngine = mDecryptSessionMap.valueFor(decryptHandle->decryptId);
@@ -443,28 +481,6 @@ ssize_t DrmManager::pread(int uniqueId, DecryptHandle* decryptHandle,
    return result;
}

void DrmManager::initializePlugIns(int uniqueId) {
    Vector<String8> plugInIdList = mPlugInManager.getPlugInIdList();

    for (unsigned int index = 0; index < plugInIdList.size(); index++) {
        IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(plugInIdList.itemAt(index));
        rDrmEngine.initialize(uniqueId);
        rDrmEngine.setOnInfoListener(uniqueId, this);
    }
}

void DrmManager::populate(int uniqueId) {
    Vector<String8> plugInPathList = mPlugInManager.getPlugInIdList();

    for (unsigned int i = 0; i < plugInPathList.size(); ++i) {
        String8 plugInPath = plugInPathList[i];
        DrmSupportInfo* info = mPlugInManager.getPlugIn(plugInPath).getSupportInfo(uniqueId);
        if (NULL != info) {
            mSupportInfoToPlugInIdMap.add(*info, plugInPath);
        }
    }
}

String8 DrmManager::getSupportedPlugInId(
            int uniqueId, const String8& path, const String8& mimeType) {
    String8 plugInId("");
Loading