blob: d45a141c2cbf77967e56f962bf68d02ad0549138 [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>
Naseer Ahmed843b7992018-03-27 19:53:30 -040028#include <cutils/android_filesystem_config.h>
Saurabh Shah56f610d2012-08-07 15:27:06 -070029#include <utils/Errors.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 ||
Namit Solanki03d56792016-11-02 15:53:43 +053096 callerUid == AID_SYSTEM ||
97 callerUid == AID_MEDIA_CODEC);
Saurabh Shah56f610d2012-08-07 15:27:06 -070098
Naseer Ahmed7a7b66d2014-07-23 17:56:26 -040099 if (code == CONNECT_HWC_CLIENT) {
Naseer Ahmed4957c522013-11-12 18:07:15 -0500100 CHECK_INTERFACE(IQService, data, reply);
101 if(callerUid != AID_GRAPHICS) {
Manoj Kumar AVM9c0bf732016-05-02 20:26:56 -0700102 ALOGE("display.qservice CONNECT_HWC_CLIENT access denied: pid=%d uid=%d",
103 callerPid, callerUid);
Naseer Ahmed4957c522013-11-12 18:07:15 -0500104 return PERMISSION_DENIED;
105 }
106 sp<IQClient> client =
107 interface_cast<IQClient>(data.readStrongBinder());
108 connect(client);
109 return NO_ERROR;
Naseer Ahmed7a7b66d2014-07-23 17:56:26 -0400110 } else if(code == CONNECT_HDMI_CLIENT) {
111 CHECK_INTERFACE(IQService, data, reply);
112 if(callerUid != AID_SYSTEM && callerUid != AID_ROOT) {
Manoj Kumar AVM9c0bf732016-05-02 20:26:56 -0700113 ALOGE("display.qservice CONNECT_HDMI_CLIENT access denied: pid=%d uid=%d",
114 callerPid, callerUid);
Naseer Ahmed7a7b66d2014-07-23 17:56:26 -0400115 return PERMISSION_DENIED;
116 }
117 sp<IQHDMIClient> client =
118 interface_cast<IQHDMIClient>(data.readStrongBinder());
119 connect(client);
120 return NO_ERROR;
Naseer Ahmed4957c522013-11-12 18:07:15 -0500121 } else if (code > COMMAND_LIST_START && code < COMMAND_LIST_END) {
122 if(!permission) {
Manoj Kumar AVM9c0bf732016-05-02 20:26:56 -0700123 ALOGE("display.qservice access denied: command=%d pid=%d uid=%d",
124 code, callerPid, callerUid);
Naseer Ahmed58780b92013-07-29 17:41:40 -0400125 return PERMISSION_DENIED;
126 }
127 CHECK_INTERFACE(IQService, data, reply);
Naseer Ahmed4957c522013-11-12 18:07:15 -0500128 dispatch(code, &data, reply);
129 return NO_ERROR;
130 } else {
131 return BBinder::onTransact(code, data, reply, flags);
Saurabh Shah56f610d2012-08-07 15:27:06 -0700132 }
133}
134
Saurabh Shah56f610d2012-08-07 15:27:06 -0700135}; // namespace qService