blob: 6545427dfe98d55843c569725ffb47b1911ea8f3 [file] [log] [blame]
Saurabh Shah56f610d2012-08-07 15:27:06 -07001/*
2 * Copyright (C) 2010 The Android Open Source Project
Arun Kumar K.Rf15adc02014-01-21 21:26:25 -08003 * Copyright (C) 2012-2014, The Linux Foundation. All rights reserved.
Saurabh Shah56f610d2012-08-07 15:27:06 -07004 *
5 * Not a Contribution, Apache license notifications and license are
6 * retained for attribution purposes only.
7
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 */
20
21#include <fcntl.h>
22#include <stdint.h>
23#include <sys/types.h>
24#include <binder/Parcel.h>
25#include <binder/IBinder.h>
26#include <binder/IInterface.h>
27#include <binder/IPCThreadState.h>
28#include <utils/Errors.h>
Naseer Ahmed52fc4cd2012-09-24 13:38:00 -040029#include <private/android_filesystem_config.h>
Saurabh Shah56f610d2012-08-07 15:27:06 -070030#include <IQService.h>
31
Naseer Ahmed4957c522013-11-12 18:07:15 -050032#define QSERVICE_DEBUG 0
33
Saurabh Shah56f610d2012-08-07 15:27:06 -070034using namespace android;
Saurabh Shah86c17292013-02-08 15:24:13 -080035using namespace qClient;
Saurabh Shah56f610d2012-08-07 15:27:06 -070036
37// ---------------------------------------------------------------------------
38
39namespace qService {
40
41class BpQService : public BpInterface<IQService>
42{
43public:
44 BpQService(const sp<IBinder>& impl)
45 : BpInterface<IQService>(impl) {}
46
Saurabh Shah86c17292013-02-08 15:24:13 -080047 virtual void connect(const sp<IQClient>& client) {
Naseer Ahmed7a7b66d2014-07-23 17:56:26 -040048 ALOGD_IF(QSERVICE_DEBUG, "%s: connect HWC client", __FUNCTION__);
Saurabh Shah86c17292013-02-08 15:24:13 -080049 Parcel data, reply;
50 data.writeInterfaceToken(IQService::getInterfaceDescriptor());
Ajay Dudani6c515122015-04-08 19:29:29 -070051 data.writeStrongBinder(IInterface::asBinder(client));
Naseer Ahmed7a7b66d2014-07-23 17:56:26 -040052 remote()->transact(CONNECT_HWC_CLIENT, data, &reply);
Saurabh Shah86c17292013-02-08 15:24:13 -080053 }
Jeykumar Sankaran9f59a762013-02-28 10:45:56 -080054
Naseer Ahmed7a7b66d2014-07-23 17:56:26 -040055 virtual void connect(const sp<IQHDMIClient>& client) {
56 ALOGD_IF(QSERVICE_DEBUG, "%s: connect HDMI client", __FUNCTION__);
57 Parcel data, reply;
58 data.writeInterfaceToken(IQService::getInterfaceDescriptor());
Ajay Dudani6c515122015-04-08 19:29:29 -070059 data.writeStrongBinder(IInterface::asBinder(client));
Naseer Ahmed7a7b66d2014-07-23 17:56:26 -040060 remote()->transact(CONNECT_HDMI_CLIENT, data, &reply);
61 }
62
63
Naseer Ahmed4957c522013-11-12 18:07:15 -050064 virtual android::status_t dispatch(uint32_t command, const Parcel* inParcel,
65 Parcel* outParcel) {
66 ALOGD_IF(QSERVICE_DEBUG, "%s: dispatch in:%p", __FUNCTION__, inParcel);
Arun Kumar K.Rf15adc02014-01-21 21:26:25 -080067 status_t err = (status_t) android::FAILED_TRANSACTION;
Naseer Ahmed4957c522013-11-12 18:07:15 -050068 Parcel data;
69 Parcel *reply = outParcel;
Jeykumar Sankaran9f59a762013-02-28 10:45:56 -080070 data.writeInterfaceToken(IQService::getInterfaceDescriptor());
Naseer Ahmed4957c522013-11-12 18:07:15 -050071 if (inParcel && inParcel->dataSize() > 0)
72 data.appendFrom(inParcel, 0, inParcel->dataSize());
73 err = remote()->transact(command, data, reply);
74 return err;
Naseer Ahmed58780b92013-07-29 17:41:40 -040075 }
Saurabh Shah56f610d2012-08-07 15:27:06 -070076};
77
78IMPLEMENT_META_INTERFACE(QService, "android.display.IQService");
79
80// ----------------------------------------------------------------------
81
Saurabh Shah56f610d2012-08-07 15:27:06 -070082status_t BnQService::onTransact(
83 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
84{
Naseer Ahmed4957c522013-11-12 18:07:15 -050085 ALOGD_IF(QSERVICE_DEBUG, "%s: code: %d", __FUNCTION__, code);
86 // IPC should be from certain processes only
Saurabh Shah56f610d2012-08-07 15:27:06 -070087 IPCThreadState* ipc = IPCThreadState::self();
88 const int callerPid = ipc->getCallingPid();
Naseer Ahmed52fc4cd2012-09-24 13:38:00 -040089 const int callerUid = ipc->getCallingUid();
Naseer Ahmed52fc4cd2012-09-24 13:38:00 -040090
Naseer Ahmed4957c522013-11-12 18:07:15 -050091 const bool permission = (callerUid == AID_MEDIA ||
92 callerUid == AID_GRAPHICS ||
93 callerUid == AID_ROOT ||
94 callerUid == AID_SYSTEM);
Saurabh Shah56f610d2012-08-07 15:27:06 -070095
Naseer Ahmed7a7b66d2014-07-23 17:56:26 -040096 if (code == CONNECT_HWC_CLIENT) {
Naseer Ahmed4957c522013-11-12 18:07:15 -050097 CHECK_INTERFACE(IQService, data, reply);
98 if(callerUid != AID_GRAPHICS) {
Manoj Kumar AVM9c0bf732016-05-02 20:26:56 -070099 ALOGE("display.qservice CONNECT_HWC_CLIENT access denied: pid=%d uid=%d",
100 callerPid, callerUid);
Naseer Ahmed4957c522013-11-12 18:07:15 -0500101 return PERMISSION_DENIED;
102 }
103 sp<IQClient> client =
104 interface_cast<IQClient>(data.readStrongBinder());
105 connect(client);
106 return NO_ERROR;
Naseer Ahmed7a7b66d2014-07-23 17:56:26 -0400107 } else if(code == CONNECT_HDMI_CLIENT) {
108 CHECK_INTERFACE(IQService, data, reply);
109 if(callerUid != AID_SYSTEM && callerUid != AID_ROOT) {
Manoj Kumar AVM9c0bf732016-05-02 20:26:56 -0700110 ALOGE("display.qservice CONNECT_HDMI_CLIENT access denied: pid=%d uid=%d",
111 callerPid, callerUid);
Naseer Ahmed7a7b66d2014-07-23 17:56:26 -0400112 return PERMISSION_DENIED;
113 }
114 sp<IQHDMIClient> client =
115 interface_cast<IQHDMIClient>(data.readStrongBinder());
116 connect(client);
117 return NO_ERROR;
Naseer Ahmed4957c522013-11-12 18:07:15 -0500118 } else if (code > COMMAND_LIST_START && code < COMMAND_LIST_END) {
119 if(!permission) {
Manoj Kumar AVM9c0bf732016-05-02 20:26:56 -0700120 ALOGE("display.qservice access denied: command=%d pid=%d uid=%d",
121 code, callerPid, callerUid);
Naseer Ahmed58780b92013-07-29 17:41:40 -0400122 return PERMISSION_DENIED;
123 }
124 CHECK_INTERFACE(IQService, data, reply);
Naseer Ahmed4957c522013-11-12 18:07:15 -0500125 dispatch(code, &data, reply);
126 return NO_ERROR;
127 } else {
128 return BBinder::onTransact(code, data, reply, flags);
Saurabh Shah56f610d2012-08-07 15:27:06 -0700129 }
130}
131
Saurabh Shah56f610d2012-08-07 15:27:06 -0700132}; // namespace qService