/* ** ** Copyright 2008, 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. */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include // for status_t #include namespace android { using android::content::AttributionSourceState; enum { CREATE = IBinder::FIRST_CALL_TRANSACTION, CREATE_MEDIA_RECORDER, CREATE_METADATA_RETRIEVER, ADD_BATTERY_DATA, PULL_BATTERY_DATA, LISTEN_FOR_REMOTE_DISPLAY, GET_CODEC_LIST, }; class BpMediaPlayerService: public BpInterface { public: explicit BpMediaPlayerService(const sp& impl) : BpInterface(impl) { } virtual sp createMetadataRetriever() { Parcel data, reply; data.writeInterfaceToken(IMediaPlayerService::getInterfaceDescriptor()); remote()->transact(CREATE_METADATA_RETRIEVER, data, &reply); return interface_cast(reply.readStrongBinder()); } virtual sp create( const sp& client, audio_session_t audioSessionId, const AttributionSourceState& attributionSource) { Parcel data, reply; data.writeInterfaceToken(IMediaPlayerService::getInterfaceDescriptor()); data.writeStrongBinder(IInterface::asBinder(client)); data.writeInt32(audioSessionId); data.writeParcelable(attributionSource); remote()->transact(CREATE, data, &reply); return interface_cast(reply.readStrongBinder()); } virtual sp createMediaRecorder(const AttributionSourceState& attributionSource) { Parcel data, reply; data.writeInterfaceToken(IMediaPlayerService::getInterfaceDescriptor()); data.writeParcelable(attributionSource); remote()->transact(CREATE_MEDIA_RECORDER, data, &reply); return interface_cast(reply.readStrongBinder()); } virtual void addBatteryData(uint32_t params) { Parcel data, reply; data.writeInterfaceToken(IMediaPlayerService::getInterfaceDescriptor()); data.writeInt32(params); remote()->transact(ADD_BATTERY_DATA, data, &reply); } virtual status_t pullBatteryData(Parcel* reply) { Parcel data; data.writeInterfaceToken(IMediaPlayerService::getInterfaceDescriptor()); return remote()->transact(PULL_BATTERY_DATA, data, reply); } virtual sp listenForRemoteDisplay(const String16 &opPackageName, const sp& client, const String8& iface) { Parcel data, reply; data.writeInterfaceToken(IMediaPlayerService::getInterfaceDescriptor()); data.writeString16(opPackageName); data.writeStrongBinder(IInterface::asBinder(client)); data.writeString8(iface); remote()->transact(LISTEN_FOR_REMOTE_DISPLAY, data, &reply); return interface_cast(reply.readStrongBinder()); } virtual sp getCodecList() const { Parcel data, reply; data.writeInterfaceToken(IMediaPlayerService::getInterfaceDescriptor()); remote()->transact(GET_CODEC_LIST, data, &reply); return interface_cast(reply.readStrongBinder()); } }; IMPLEMENT_META_INTERFACE(MediaPlayerService, "android.media.IMediaPlayerService"); // ---------------------------------------------------------------------- status_t BnMediaPlayerService::onTransact( uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) { switch (code) { case CREATE: { CHECK_INTERFACE(IMediaPlayerService, data, reply); sp client = interface_cast(data.readStrongBinder()); audio_session_t audioSessionId = (audio_session_t) data.readInt32(); AttributionSourceState attributionSource; status_t status = data.readParcelable(&attributionSource); if (status != NO_ERROR) { return status; } sp player = create(client, audioSessionId, attributionSource); reply->writeStrongBinder(IInterface::asBinder(player)); return NO_ERROR; } break; case CREATE_MEDIA_RECORDER: { CHECK_INTERFACE(IMediaPlayerService, data, reply); AttributionSourceState attributionSource; status_t status = data.readParcelable(&attributionSource); if (status != NO_ERROR) { return status; } sp recorder = createMediaRecorder(attributionSource); reply->writeStrongBinder(IInterface::asBinder(recorder)); return NO_ERROR; } break; case CREATE_METADATA_RETRIEVER: { CHECK_INTERFACE(IMediaPlayerService, data, reply); sp retriever = createMetadataRetriever(); reply->writeStrongBinder(IInterface::asBinder(retriever)); return NO_ERROR; } break; case ADD_BATTERY_DATA: { CHECK_INTERFACE(IMediaPlayerService, data, reply); uint32_t params = data.readInt32(); addBatteryData(params); return NO_ERROR; } break; case PULL_BATTERY_DATA: { CHECK_INTERFACE(IMediaPlayerService, data, reply); pullBatteryData(reply); return NO_ERROR; } break; case LISTEN_FOR_REMOTE_DISPLAY: { CHECK_INTERFACE(IMediaPlayerService, data, reply); const String16 opPackageName = data.readString16(); sp client( interface_cast(data.readStrongBinder())); if (client == NULL) { reply->writeStrongBinder(NULL); return NO_ERROR; } String8 iface(data.readString8()); sp display(listenForRemoteDisplay(opPackageName, client, iface)); reply->writeStrongBinder(IInterface::asBinder(display)); return NO_ERROR; } break; case GET_CODEC_LIST: { CHECK_INTERFACE(IMediaPlayerService, data, reply); sp mcl = getCodecList(); reply->writeStrongBinder(IInterface::asBinder(mcl)); return NO_ERROR; } break; default: return BBinder::onTransact(code, data, reply, flags); } } // ---------------------------------------------------------------------------- } // namespace android