Home | History | Annotate | Download | only in clearkey
      1 /*
      2  * Copyright (C) 2014 The Android Open Source Project
      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 //#define LOG_NDEBUG 0
     18 #define LOG_TAG "ClearKeyCryptoPlugin"
     19 #include <utils/Log.h>
     20 
     21 #include <media/stagefright/MediaErrors.h>
     22 #include <utils/StrongPointer.h>
     23 
     24 #include "DrmPlugin.h"
     25 
     26 #include "Session.h"
     27 
     28 namespace clearkeydrm {
     29 
     30 using android::sp;
     31 
     32 status_t DrmPlugin::openSession(Vector<uint8_t>& sessionId) {
     33     sp<Session> session = mSessionLibrary->createSession();
     34     sessionId = session->sessionId();
     35     return android::OK;
     36 }
     37 
     38 status_t DrmPlugin::closeSession(const Vector<uint8_t>& sessionId) {
     39     sp<Session> session = mSessionLibrary->findSession(sessionId);
     40     if (session.get()) {
     41         mSessionLibrary->destroySession(session);
     42     }
     43     return android::OK;
     44 }
     45 
     46 status_t DrmPlugin::getKeyRequest(
     47         const Vector<uint8_t>& scope,
     48         const Vector<uint8_t>& initData,
     49         const String8& mimeType,
     50         KeyType keyType,
     51         const KeyedVector<String8, String8>& optionalParameters,
     52         Vector<uint8_t>& request,
     53         String8& defaultUrl,
     54         DrmPlugin::KeyRequestType *keyRequestType) {
     55     UNUSED(optionalParameters);
     56     if (keyType != kKeyType_Streaming) {
     57         return android::ERROR_DRM_CANNOT_HANDLE;
     58     }
     59     *keyRequestType = DrmPlugin::kKeyRequestType_Initial;
     60     defaultUrl.clear();
     61     sp<Session> session = mSessionLibrary->findSession(scope);
     62     if (!session.get()) {
     63         return android::ERROR_DRM_SESSION_NOT_OPENED;
     64     }
     65     return session->getKeyRequest(initData, mimeType, &request);
     66 }
     67 
     68 status_t DrmPlugin::provideKeyResponse(
     69         const Vector<uint8_t>& scope,
     70         const Vector<uint8_t>& response,
     71         Vector<uint8_t>& keySetId) {
     72     sp<Session> session = mSessionLibrary->findSession(scope);
     73     if (!session.get()) {
     74         return android::ERROR_DRM_SESSION_NOT_OPENED;
     75     }
     76     status_t res = session->provideKeyResponse(response);
     77     if (res == android::OK) {
     78         keySetId.clear();
     79     }
     80     return res;
     81 }
     82 
     83 status_t DrmPlugin::getPropertyString(
     84         const String8& name, String8& value) const {
     85     if (name == "vendor") {
     86         value = "Google";
     87     } else if (name == "version") {
     88         value = "1.0";
     89     } else if (name == "description") {
     90         value = "ClearKey CDM";
     91     } else if (name == "algorithms") {
     92         value = "";
     93     } else {
     94         ALOGE("App requested unknown string property %s", name.string());
     95         return android::ERROR_DRM_CANNOT_HANDLE;
     96     }
     97     return android::OK;
     98 }
     99 
    100 }  // namespace clearkeydrm
    101