1 /*
2  * Copyright 2016 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 #include "IMediaResourceMonitor.h"
18 #include <binder/Parcel.h>
19 #include <utils/Errors.h>
20 #include <sys/types.h>
21 
22 namespace android {
23 
24 // ----------------------------------------------------------------------
25 
26 class BpMediaResourceMonitor : public BpInterface<IMediaResourceMonitor> {
27 public:
BpMediaResourceMonitor(const sp<IBinder> & impl)28     explicit BpMediaResourceMonitor(const sp<IBinder>& impl)
29         : BpInterface<IMediaResourceMonitor>(impl) {}
30 
notifyResourceGranted(int32_t pid,const int32_t type)31     virtual void notifyResourceGranted(/*in*/ int32_t pid, /*in*/ const int32_t type)
32     {
33         Parcel data, reply;
34         data.writeInterfaceToken(IMediaResourceMonitor::getInterfaceDescriptor());
35         data.writeInt32(pid);
36         data.writeInt32(type);
37         remote()->transact(NOTIFY_RESOURCE_GRANTED, data, &reply, IBinder::FLAG_ONEWAY);
38     }
39 };
40 
41 IMPLEMENT_META_INTERFACE(MediaResourceMonitor, "android.media.IMediaResourceMonitor")
42 
43 // ----------------------------------------------------------------------
44 
45 // NOLINTNEXTLINE(google-default-arguments)
onTransact(uint32_t code,const Parcel & data,Parcel * reply,uint32_t flags)46 status_t BnMediaResourceMonitor::onTransact( uint32_t code, const Parcel& data, Parcel* reply,
47         uint32_t flags) {
48     switch(code) {
49         case NOTIFY_RESOURCE_GRANTED: {
50             CHECK_INTERFACE(IMediaResourceMonitor, data, reply);
51             int32_t pid = data.readInt32();
52             const int32_t type = data.readInt32();
53             notifyResourceGranted(/*in*/ pid, /*in*/ type);
54             return NO_ERROR;
55         } break;
56         default:
57             return BBinder::onTransact(code, data, reply, flags);
58     }
59 }
60 
61 // ----------------------------------------------------------------------
62 
63 } // namespace android
64