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 <utils/RefBase.h>
19 #include <binder/IInterface.h>
20 #include <binder/Parcel.h>
21
22 #include <media/IResourceManagerClient.h>
23
24 namespace android {
25
26 enum {
27 RECLAIM_RESOURCE = IBinder::FIRST_CALL_TRANSACTION,
28 GET_NAME,
29 };
30
31 class BpResourceManagerClient: public BpInterface<IResourceManagerClient>
32 {
33 public:
BpResourceManagerClient(const sp<IBinder> & impl)34 BpResourceManagerClient(const sp<IBinder> &impl)
35 : BpInterface<IResourceManagerClient>(impl)
36 {
37 }
38
reclaimResource()39 virtual bool reclaimResource() {
40 Parcel data, reply;
41 data.writeInterfaceToken(IResourceManagerClient::getInterfaceDescriptor());
42
43 bool ret = false;
44 status_t status = remote()->transact(RECLAIM_RESOURCE, data, &reply);
45 if (status == NO_ERROR) {
46 ret = (bool)reply.readInt32();
47 }
48 return ret;
49 }
50
getName()51 virtual String8 getName() {
52 Parcel data, reply;
53 data.writeInterfaceToken(IResourceManagerClient::getInterfaceDescriptor());
54
55 String8 ret;
56 status_t status = remote()->transact(GET_NAME, data, &reply);
57 if (status == NO_ERROR) {
58 ret = reply.readString8();
59 }
60 return ret;
61 }
62
63 };
64
65 IMPLEMENT_META_INTERFACE(ResourceManagerClient, "android.media.IResourceManagerClient");
66
67 // ----------------------------------------------------------------------
68
onTransact(uint32_t code,const Parcel & data,Parcel * reply,uint32_t flags)69 status_t BnResourceManagerClient::onTransact(
70 uint32_t code, const Parcel &data, Parcel *reply, uint32_t flags)
71 {
72 switch (code) {
73 case RECLAIM_RESOURCE: {
74 CHECK_INTERFACE(IResourceManagerClient, data, reply);
75 bool ret = reclaimResource();
76 reply->writeInt32(ret);
77 return NO_ERROR;
78 } break;
79 case GET_NAME: {
80 CHECK_INTERFACE(IResourceManagerClient, data, reply);
81 String8 ret = getName();
82 reply->writeString8(ret);
83 return NO_ERROR;
84 } break;
85 default:
86 return BBinder::onTransact(code, data, reply, flags);
87 }
88 }
89
90 }; // namespace android
91