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

Commit 359ff633 authored by Edwin Wong's avatar Edwin Wong Committed by Android (Google) Code Review
Browse files

Merge "Implement getPropertyByteArray and setPropertyByteArray."

parents c2a1fdd0 10869bee
Loading
Loading
Loading
Loading
+41 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2017 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.
 */

#ifndef CLEARKEY_DRM_PROPERTIES_H_
#define CLEARKEY_DRM_PROPERTIES_H_

#include <utils/String8.h>

namespace clearkeydrm {

static const android::String8 kVendorKey("vendor");
static const android::String8 kVendorValue("Google");
static const android::String8 kVersionKey("version");
static const android::String8 kVersionValue("1.0");
static const android::String8 kPluginDescriptionKey("description");
static const android::String8 kPluginDescriptionValue("ClearKey CDM");
static const android::String8 kAlgorithmsKey("algorithms");
static const android::String8 kAlgorithmsValue("");
static const android::String8 kListenerTestSupportKey("listenerTestSupport");
static const android::String8 kListenerTestSupportValue("true");

static const android::String8 kDeviceIdKey("deviceId");
static const uint8_t kTestDeviceIdData[] =
        {0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7,
         0x8, 0x9, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf};
} // namespace clearkeydrm

#endif // CLEARKEY_DRM_PROPERTIES_H_
+65 −14
Original line number Diff line number Diff line
@@ -22,7 +22,7 @@
#include <utils/StrongPointer.h>

#include "DrmPlugin.h"

#include "ClearKeyDrmProperties.h"
#include "Session.h"

namespace {
@@ -44,7 +44,22 @@ using android::sp;

DrmPlugin::DrmPlugin(SessionLibrary* sessionLibrary)
        : mSessionLibrary(sessionLibrary) {

    mPlayPolicy.clear();
    initProperties();
}

void DrmPlugin::initProperties() {
    mStringProperties.clear();
    mStringProperties.add(kVendorKey, kVendorValue);
    mStringProperties.add(kVersionKey, kVersionValue);
    mStringProperties.add(kPluginDescriptionKey, kPluginDescriptionValue);
    mStringProperties.add(kAlgorithmsKey, kAlgorithmsValue);
    mStringProperties.add(kListenerTestSupportKey, kListenerTestSupportValue);

    Vector<uint8_t> testDeviceId;
    testDeviceId.appendArray(kTestDeviceIdData, sizeof(kTestDeviceIdData) / sizeof(uint8_t));
    mByteArrayProperties.add(kDeviceIdKey, testDeviceId);
}

status_t DrmPlugin::openSession(Vector<uint8_t>& sessionId) {
@@ -122,21 +137,57 @@ status_t DrmPlugin::provideKeyResponse(
    return res;
}

status_t DrmPlugin::getPropertyByteArray(
        const String8& name, Vector<uint8_t>& value) const {
    ssize_t index = mByteArrayProperties.indexOfKey(name);
    if (index < 0) {
        ALOGE("App requested unknown property: %s", name.string());
        return android::BAD_VALUE;
    }
    value = mByteArrayProperties.valueAt(index);
    return android::OK;
}

status_t DrmPlugin::setPropertyByteArray(
        const String8& name, const Vector<uint8_t>& value) {
    if (0 == name.compare(kDeviceIdKey)) {
        ALOGD("Cannot set immutable property: %s", name.string());
        return android::BAD_VALUE;
    }

    ssize_t status = mByteArrayProperties.replaceValueFor(name, value);
    if (status >= 0) {
        return android::OK;
    }
    ALOGE("Failed to set property byte array, key=%s", name.string());
    return android::BAD_VALUE;
}

status_t DrmPlugin::getPropertyString(
        const String8& name, String8& value) const {
    if (name == "vendor") {
        value = "Google";
    } else if (name == "version") {
        value = "1.0";
    } else if (name == "description") {
        value = "ClearKey CDM";
    } else if (name == "algorithms") {
        value = "";
    } else if (name == "listenerTestSupport") {
        value = "true";
    } else {
        ALOGE("App requested unknown string property %s", name.string());
        return android::ERROR_DRM_CANNOT_HANDLE;
    ssize_t index = mStringProperties.indexOfKey(name);
    if (index < 0) {
        ALOGE("App requested unknown property: %s", name.string());
        return android::BAD_VALUE;
    }
    value = mStringProperties.valueAt(index);
    return android::OK;
}

status_t DrmPlugin::setPropertyString(
        const String8& name, const String8& value) {
    String8 immutableKeys;
    immutableKeys.appendFormat("%s,%s,%s,%s",
            kAlgorithmsKey.string(), kPluginDescriptionKey.string(),
            kVendorKey.string(), kVersionKey.string());
    if (immutableKeys.contains(name.string())) {
        ALOGD("Cannot set immutable property: %s", name.string());
        return android::BAD_VALUE;
    }

    if (mStringProperties.add(name, value) < 0) {
        ALOGE("Failed to set property string, key=%s", name.string());
        return android::BAD_VALUE;
    }
    return android::OK;
}
+8 −16
Original line number Diff line number Diff line
@@ -137,25 +137,13 @@ public:
            const String8& name, String8& value) const;

    virtual status_t getPropertyByteArray(
            const String8& name, Vector<uint8_t>& value) const {
        UNUSED(name);
        UNUSED(value);
        return android::ERROR_DRM_CANNOT_HANDLE;
    }
            const String8& name, Vector<uint8_t>& value) const;

    virtual status_t setPropertyString(
            const String8& name, const String8& value) {
        UNUSED(name);
        UNUSED(value);
        return android::ERROR_DRM_CANNOT_HANDLE;
    }
            const String8& name, const String8& value);

    virtual status_t setPropertyByteArray(
            const String8& name, const Vector<uint8_t>& value) {
        UNUSED(name);
        UNUSED(value);
        return android::ERROR_DRM_CANNOT_HANDLE;
    }
            const String8& name, const Vector<uint8_t>& value);

    virtual status_t setCipherAlgorithm(
            const Vector<uint8_t>& sessionId, const String8& algorithm) {
@@ -242,9 +230,13 @@ public:
    }

private:
    void initProperties();
    void setPlayPolicy();

    android::KeyedVector<android::String8, android::String8> mPlayPolicy;
    android::KeyedVector<String8, String8> mPlayPolicy;
    android::KeyedVector<String8, String8> mStringProperties;
    android::KeyedVector<String8, Vector<uint8_t>> mByteArrayProperties;

    SessionLibrary* mSessionLibrary;

    DISALLOW_EVIL_CONSTRUCTORS(DrmPlugin);