blob: e1c5219c3f2e4b9dd996a7ccb9aae6bda8ecef7f [file] [log] [blame]
Saurabh Shah56f610d2012-08-07 15:27:06 -07001/*
2 * Copyright (C) 2010 The Android Open Source Project
Naseer Ahmedce077232016-03-14 19:58:14 -04003 * Copyright (C) 2012-2016, 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 ||
Naseer Ahmedce077232016-03-14 19:58:14 -040094 callerUid == AID_CAMERASERVER ||
Ramkumar Radhakrishnan9d68cdf2016-06-02 19:14:57 -070095 callerUid == AID_AUDIO ||
Naseer Ahmed4957c522013-11-12 18:07:15 -050096 callerUid == AID_SYSTEM);
Saurabh Shah56f610d2012-08-07 15:27:06 -070097
Naseer Ahmed7a7b66d2014-07-23 17:56:26 -040098 if (code == CONNECT_HWC_CLIENT) {
Naseer Ahmed4957c522013-11-12 18:07:15 -050099 CHECK_INTERFACE(IQService, data, reply);
100 if(callerUid != AID_GRAPHICS) {
Manoj Kumar AVM9c0bf732016-05-02 20:26:56 -0700101 ALOGE("display.qservice CONNECT_HWC_CLIENT access denied: pid=%d uid=%d",
102 callerPid, callerUid);
Naseer Ahmed4957c522013-11-12 18:07:15 -0500103 return PERMISSION_DENIED;
104 }
105 sp<IQClient> client =
106 interface_cast<IQClient>(data.readStrongBinder());
107 connect(client);
108 return NO_ERROR;
Naseer Ahmed7a7b66d2014-07-23 17:56:26 -0400109 } else if(code == CONNECT_HDMI_CLIENT) {
110 CHECK_INTERFACE(IQService, data, reply);
111 if(callerUid != AID_SYSTEM && callerUid != AID_ROOT) {
Manoj Kumar AVM9c0bf732016-05-02 20:26:56 -0700112 ALOGE("display.qservice CONNECT_HDMI_CLIENT access denied: pid=%d uid=%d",
113 callerPid, callerUid);
Naseer Ahmed7a7b66d2014-07-23 17:56:26 -0400114 return PERMISSION_DENIED;
115 }
116 sp<IQHDMIClient> client =
117 interface_cast<IQHDMIClient>(data.readStrongBinder());
118 connect(client);
119 return NO_ERROR;
Naseer Ahmed4957c522013-11-12 18:07:15 -0500120 } else if (code > COMMAND_LIST_START && code < COMMAND_LIST_END) {
121 if(!permission) {
Manoj Kumar AVM9c0bf732016-05-02 20:26:56 -0700122 ALOGE("display.qservice access denied: command=%d pid=%d uid=%d",
123 code, callerPid, callerUid);
Naseer Ahmed58780b92013-07-29 17:41:40 -0400124 return PERMISSION_DENIED;
125 }
126 CHECK_INTERFACE(IQService, data, reply);
Naseer Ahmed4957c522013-11-12 18:07:15 -0500127 dispatch(code, &data, reply);
128 return NO_ERROR;
129 } else {
130 return BBinder::onTransact(code, data, reply, flags);
Saurabh Shah56f610d2012-08-07 15:27:06 -0700131 }
132}
133
Saurabh Shah56f610d2012-08-07 15:27:06 -0700134}; // namespace qService