Home | History | Annotate | Download | only in libmedia
      1 /*
      2 **
      3 ** Copyright 2015, The Android Open Source Project
      4 **
      5 ** Licensed under the Apache License, Version 2.0 (the "License");
      6 ** you may not use this file except in compliance with the License.
      7 ** You may obtain a copy of the License at
      8 **
      9 **     http://www.apache.org/licenses/LICENSE-2.0
     10 **
     11 ** Unless required by applicable law or agreed to in writing, software
     12 ** distributed under the License is distributed on an "AS IS" BASIS,
     13 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     14 ** See the License for the specific language governing permissions and
     15 ** limitations under the License.
     16 */
     17 
     18 #include <stdint.h>
     19 #include <sys/types.h>
     20 
     21 #include <binder/Parcel.h>
     22 #include <binder/IMemory.h>
     23 #include <media/ICrypto.h>
     24 #include <media/IDrm.h>
     25 #include <media/IMediaDrmService.h>
     26 
     27 #include <utils/Errors.h>  // for status_t
     28 #include <utils/String8.h>
     29 
     30 namespace android {
     31 
     32 enum {
     33     MAKE_CRYPTO = IBinder::FIRST_CALL_TRANSACTION,
     34     MAKE_DRM,
     35 };
     36 
     37 class BpMediaDrmService: public BpInterface<IMediaDrmService>
     38 {
     39 public:
     40     BpMediaDrmService(const sp<IBinder>& impl)
     41         : BpInterface<IMediaDrmService>(impl)
     42     {
     43     }
     44 
     45     virtual sp<ICrypto> makeCrypto() {
     46         Parcel data, reply;
     47         data.writeInterfaceToken(IMediaDrmService::getInterfaceDescriptor());
     48         remote()->transact(MAKE_CRYPTO, data, &reply);
     49         return interface_cast<ICrypto>(reply.readStrongBinder());
     50     }
     51 
     52     virtual sp<IDrm> makeDrm() {
     53         Parcel data, reply;
     54         data.writeInterfaceToken(IMediaDrmService::getInterfaceDescriptor());
     55         remote()->transact(MAKE_DRM, data, &reply);
     56         return interface_cast<IDrm>(reply.readStrongBinder());
     57     }
     58 
     59 };
     60 
     61 IMPLEMENT_META_INTERFACE(MediaDrmService, "android.media.IMediaDrmService");
     62 
     63 // ----------------------------------------------------------------------
     64 
     65 status_t BnMediaDrmService::onTransact(
     66     uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
     67 {
     68     switch (code) {
     69         case MAKE_CRYPTO: {
     70             CHECK_INTERFACE(IMediaDrmService, data, reply);
     71             sp<ICrypto> crypto = makeCrypto();
     72             reply->writeStrongBinder(IInterface::asBinder(crypto));
     73             return NO_ERROR;
     74         } break;
     75         case MAKE_DRM: {
     76             CHECK_INTERFACE(IMediaDrmService, data, reply);
     77             sp<IDrm> drm = makeDrm();
     78             reply->writeStrongBinder(IInterface::asBinder(drm));
     79             return NO_ERROR;
     80         } break;
     81         default:
     82             return BBinder::onTransact(code, data, reply, flags);
     83     }
     84 }
     85 
     86 // ----------------------------------------------------------------------------
     87 
     88 } // namespace android
     89