1c0d5f1f8405de861ed6f1725f26cd6601e7103abJeff Tinker/*
2c0d5f1f8405de861ed6f1725f26cd6601e7103abJeff Tinker**
3c0d5f1f8405de861ed6f1725f26cd6601e7103abJeff Tinker** Copyright 2013, The Android Open Source Project
4c0d5f1f8405de861ed6f1725f26cd6601e7103abJeff Tinker**
5c0d5f1f8405de861ed6f1725f26cd6601e7103abJeff Tinker** Licensed under the Apache License, Version 2.0 (the "License");
6c0d5f1f8405de861ed6f1725f26cd6601e7103abJeff Tinker** you may not use this file except in compliance with the License.
7c0d5f1f8405de861ed6f1725f26cd6601e7103abJeff Tinker** You may obtain a copy of the License at
8c0d5f1f8405de861ed6f1725f26cd6601e7103abJeff Tinker**
9c0d5f1f8405de861ed6f1725f26cd6601e7103abJeff Tinker**     http://www.apache.org/licenses/LICENSE-2.0
10c0d5f1f8405de861ed6f1725f26cd6601e7103abJeff Tinker**
11c0d5f1f8405de861ed6f1725f26cd6601e7103abJeff Tinker** Unless required by applicable law or agreed to in writing, software
12c0d5f1f8405de861ed6f1725f26cd6601e7103abJeff Tinker** distributed under the License is distributed on an "AS IS" BASIS,
13c0d5f1f8405de861ed6f1725f26cd6601e7103abJeff Tinker** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14c0d5f1f8405de861ed6f1725f26cd6601e7103abJeff Tinker** See the License for the specific language governing permissions and
15c0d5f1f8405de861ed6f1725f26cd6601e7103abJeff Tinker** limitations under the License.
16c0d5f1f8405de861ed6f1725f26cd6601e7103abJeff Tinker*/
17c0d5f1f8405de861ed6f1725f26cd6601e7103abJeff Tinker
18c0d5f1f8405de861ed6f1725f26cd6601e7103abJeff Tinker//#define LOG_NDEBUG 0
19c0d5f1f8405de861ed6f1725f26cd6601e7103abJeff Tinker#define LOG_TAG "IDrmClient"
20c0d5f1f8405de861ed6f1725f26cd6601e7103abJeff Tinker#include <utils/Log.h>
21c0d5f1f8405de861ed6f1725f26cd6601e7103abJeff Tinker
22c0d5f1f8405de861ed6f1725f26cd6601e7103abJeff Tinker#include <utils/RefBase.h>
23c0d5f1f8405de861ed6f1725f26cd6601e7103abJeff Tinker#include <binder/IInterface.h>
24c0d5f1f8405de861ed6f1725f26cd6601e7103abJeff Tinker#include <binder/Parcel.h>
25c0d5f1f8405de861ed6f1725f26cd6601e7103abJeff Tinker
26c0d5f1f8405de861ed6f1725f26cd6601e7103abJeff Tinker#include <media/IMediaPlayerClient.h>
27c0d5f1f8405de861ed6f1725f26cd6601e7103abJeff Tinker#include <media/IDrmClient.h>
28c0d5f1f8405de861ed6f1725f26cd6601e7103abJeff Tinker
29c0d5f1f8405de861ed6f1725f26cd6601e7103abJeff Tinkernamespace android {
30c0d5f1f8405de861ed6f1725f26cd6601e7103abJeff Tinker
31c0d5f1f8405de861ed6f1725f26cd6601e7103abJeff Tinkerenum {
32c0d5f1f8405de861ed6f1725f26cd6601e7103abJeff Tinker    NOTIFY = IBinder::FIRST_CALL_TRANSACTION,
33c0d5f1f8405de861ed6f1725f26cd6601e7103abJeff Tinker};
34c0d5f1f8405de861ed6f1725f26cd6601e7103abJeff Tinker
35c0d5f1f8405de861ed6f1725f26cd6601e7103abJeff Tinkerclass BpDrmClient: public BpInterface<IDrmClient>
36c0d5f1f8405de861ed6f1725f26cd6601e7103abJeff Tinker{
37c0d5f1f8405de861ed6f1725f26cd6601e7103abJeff Tinkerpublic:
38c0d5f1f8405de861ed6f1725f26cd6601e7103abJeff Tinker    BpDrmClient(const sp<IBinder>& impl)
39c0d5f1f8405de861ed6f1725f26cd6601e7103abJeff Tinker        : BpInterface<IDrmClient>(impl)
40c0d5f1f8405de861ed6f1725f26cd6601e7103abJeff Tinker    {
41c0d5f1f8405de861ed6f1725f26cd6601e7103abJeff Tinker    }
42c0d5f1f8405de861ed6f1725f26cd6601e7103abJeff Tinker
43c0d5f1f8405de861ed6f1725f26cd6601e7103abJeff Tinker    virtual void notify(DrmPlugin::EventType eventType, int extra, const Parcel *obj)
44c0d5f1f8405de861ed6f1725f26cd6601e7103abJeff Tinker    {
45c0d5f1f8405de861ed6f1725f26cd6601e7103abJeff Tinker        Parcel data, reply;
46c0d5f1f8405de861ed6f1725f26cd6601e7103abJeff Tinker        data.writeInterfaceToken(IDrmClient::getInterfaceDescriptor());
47c0d5f1f8405de861ed6f1725f26cd6601e7103abJeff Tinker        data.writeInt32((int)eventType);
48c0d5f1f8405de861ed6f1725f26cd6601e7103abJeff Tinker        data.writeInt32(extra);
49c0d5f1f8405de861ed6f1725f26cd6601e7103abJeff Tinker        if (obj && obj->dataSize() > 0) {
50c0d5f1f8405de861ed6f1725f26cd6601e7103abJeff Tinker            data.appendFrom(const_cast<Parcel *>(obj), 0, obj->dataSize());
51c0d5f1f8405de861ed6f1725f26cd6601e7103abJeff Tinker        }
52c0d5f1f8405de861ed6f1725f26cd6601e7103abJeff Tinker        remote()->transact(NOTIFY, data, &reply, IBinder::FLAG_ONEWAY);
53c0d5f1f8405de861ed6f1725f26cd6601e7103abJeff Tinker    }
54c0d5f1f8405de861ed6f1725f26cd6601e7103abJeff Tinker};
55c0d5f1f8405de861ed6f1725f26cd6601e7103abJeff Tinker
56c0d5f1f8405de861ed6f1725f26cd6601e7103abJeff TinkerIMPLEMENT_META_INTERFACE(DrmClient, "android.media.IDrmClient");
57c0d5f1f8405de861ed6f1725f26cd6601e7103abJeff Tinker
58c0d5f1f8405de861ed6f1725f26cd6601e7103abJeff Tinker// ----------------------------------------------------------------------
59c0d5f1f8405de861ed6f1725f26cd6601e7103abJeff Tinker
60c0d5f1f8405de861ed6f1725f26cd6601e7103abJeff Tinkerstatus_t BnDrmClient::onTransact(
61c0d5f1f8405de861ed6f1725f26cd6601e7103abJeff Tinker    uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
62c0d5f1f8405de861ed6f1725f26cd6601e7103abJeff Tinker{
63c0d5f1f8405de861ed6f1725f26cd6601e7103abJeff Tinker    switch (code) {
64c0d5f1f8405de861ed6f1725f26cd6601e7103abJeff Tinker        case NOTIFY: {
65c0d5f1f8405de861ed6f1725f26cd6601e7103abJeff Tinker            CHECK_INTERFACE(IDrmClient, data, reply);
66c0d5f1f8405de861ed6f1725f26cd6601e7103abJeff Tinker            int eventType = data.readInt32();
67c0d5f1f8405de861ed6f1725f26cd6601e7103abJeff Tinker            int extra = data.readInt32();
68c0d5f1f8405de861ed6f1725f26cd6601e7103abJeff Tinker            Parcel obj;
69c0d5f1f8405de861ed6f1725f26cd6601e7103abJeff Tinker            if (data.dataAvail() > 0) {
70c0d5f1f8405de861ed6f1725f26cd6601e7103abJeff Tinker                obj.appendFrom(const_cast<Parcel *>(&data), data.dataPosition(), data.dataAvail());
71c0d5f1f8405de861ed6f1725f26cd6601e7103abJeff Tinker            }
72c0d5f1f8405de861ed6f1725f26cd6601e7103abJeff Tinker
73c0d5f1f8405de861ed6f1725f26cd6601e7103abJeff Tinker            notify((DrmPlugin::EventType)eventType, extra, &obj);
74c0d5f1f8405de861ed6f1725f26cd6601e7103abJeff Tinker            return NO_ERROR;
75c0d5f1f8405de861ed6f1725f26cd6601e7103abJeff Tinker        } break;
76c0d5f1f8405de861ed6f1725f26cd6601e7103abJeff Tinker        default:
77c0d5f1f8405de861ed6f1725f26cd6601e7103abJeff Tinker            return BBinder::onTransact(code, data, reply, flags);
78c0d5f1f8405de861ed6f1725f26cd6601e7103abJeff Tinker    }
79c0d5f1f8405de861ed6f1725f26cd6601e7103abJeff Tinker}
80c0d5f1f8405de861ed6f1725f26cd6601e7103abJeff Tinker
81c0d5f1f8405de861ed6f1725f26cd6601e7103abJeff Tinker}; // namespace android
82