blob: 3c30dba271382e8c21a573dd26e1e2cc514f5d9d [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>
Ramkumar Radhakrishnan56d883b2020-03-25 16:47:55 -070028#ifndef TRUSTED_VM
Naseer Ahmed843b7992018-03-27 19:53:30 -040029#include <cutils/android_filesystem_config.h>
Ramkumar Radhakrishnan56d883b2020-03-25 16:47:55 -070030#else
31#include <private/android_filesystem_config.h>
32#endif
Saurabh Shah56f610d2012-08-07 15:27:06 -070033#include <utils/Errors.h>
Saurabh Shah56f610d2012-08-07 15:27:06 -070034#include <IQService.h>
35
Naseer Ahmed4957c522013-11-12 18:07:15 -050036#define QSERVICE_DEBUG 0
37
Saurabh Shah56f610d2012-08-07 15:27:06 -070038using namespace android;
Saurabh Shah86c17292013-02-08 15:24:13 -080039using namespace qClient;
Saurabh Shah56f610d2012-08-07 15:27:06 -070040
41// ---------------------------------------------------------------------------
42
43namespace qService {
44
45class BpQService : public BpInterface<IQService>
46{
47public:
48 BpQService(const sp<IBinder>& impl)
49 : BpInterface<IQService>(impl) {}
50
Saurabh Shah86c17292013-02-08 15:24:13 -080051 virtual void connect(const sp<IQClient>& client) {
Naseer Ahmed7a7b66d2014-07-23 17:56:26 -040052 ALOGD_IF(QSERVICE_DEBUG, "%s: connect HWC client", __FUNCTION__);
Saurabh Shah86c17292013-02-08 15:24:13 -080053 Parcel data, reply;
54 data.writeInterfaceToken(IQService::getInterfaceDescriptor());
Ajay Dudani6c515122015-04-08 19:29:29 -070055 data.writeStrongBinder(IInterface::asBinder(client));
Naseer Ahmed7a7b66d2014-07-23 17:56:26 -040056 remote()->transact(CONNECT_HWC_CLIENT, data, &reply);
Saurabh Shah86c17292013-02-08 15:24:13 -080057 }
Jeykumar Sankaran9f59a762013-02-28 10:45:56 -080058
Naseer Ahmed7a7b66d2014-07-23 17:56:26 -040059 virtual void connect(const sp<IQHDMIClient>& client) {
60 ALOGD_IF(QSERVICE_DEBUG, "%s: connect HDMI client", __FUNCTION__);
61 Parcel data, reply;
62 data.writeInterfaceToken(IQService::getInterfaceDescriptor());
Ajay Dudani6c515122015-04-08 19:29:29 -070063 data.writeStrongBinder(IInterface::asBinder(client));
Naseer Ahmed7a7b66d2014-07-23 17:56:26 -040064 remote()->transact(CONNECT_HDMI_CLIENT, data, &reply);
65 }
66
67
Naseer Ahmed4957c522013-11-12 18:07:15 -050068 virtual android::status_t dispatch(uint32_t command, const Parcel* inParcel,
69 Parcel* outParcel) {
70 ALOGD_IF(QSERVICE_DEBUG, "%s: dispatch in:%p", __FUNCTION__, inParcel);
Arun Kumar K.Rf15adc02014-01-21 21:26:25 -080071 status_t err = (status_t) android::FAILED_TRANSACTION;
Naseer Ahmed4957c522013-11-12 18:07:15 -050072 Parcel data;
73 Parcel *reply = outParcel;
Jeykumar Sankaran9f59a762013-02-28 10:45:56 -080074 data.writeInterfaceToken(IQService::getInterfaceDescriptor());
Naseer Ahmed4957c522013-11-12 18:07:15 -050075 if (inParcel && inParcel->dataSize() > 0)
76 data.appendFrom(inParcel, 0, inParcel->dataSize());
77 err = remote()->transact(command, data, reply);
78 return err;
Naseer Ahmed58780b92013-07-29 17:41:40 -040079 }
Saurabh Shah56f610d2012-08-07 15:27:06 -070080};
81
82IMPLEMENT_META_INTERFACE(QService, "android.display.IQService");
83
84// ----------------------------------------------------------------------
85
Saurabh Shah56f610d2012-08-07 15:27:06 -070086status_t BnQService::onTransact(
87 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
88{
Naseer Ahmed4957c522013-11-12 18:07:15 -050089 ALOGD_IF(QSERVICE_DEBUG, "%s: code: %d", __FUNCTION__, code);
90 // IPC should be from certain processes only
Saurabh Shah56f610d2012-08-07 15:27:06 -070091 IPCThreadState* ipc = IPCThreadState::self();
92 const int callerPid = ipc->getCallingPid();
Naseer Ahmed52fc4cd2012-09-24 13:38:00 -040093 const int callerUid = ipc->getCallingUid();
Naseer Ahmed52fc4cd2012-09-24 13:38:00 -040094
Naseer Ahmed4957c522013-11-12 18:07:15 -050095 const bool permission = (callerUid == AID_MEDIA ||
96 callerUid == AID_GRAPHICS ||
97 callerUid == AID_ROOT ||
Naseer Ahmedce077232016-03-14 19:58:14 -040098 callerUid == AID_CAMERASERVER ||
Ramkumar Radhakrishnan9d68cdf2016-06-02 19:14:57 -070099 callerUid == AID_AUDIO ||
Namit Solanki03d56792016-11-02 15:53:43 +0530100 callerUid == AID_SYSTEM ||
101 callerUid == AID_MEDIA_CODEC);
Saurabh Shah56f610d2012-08-07 15:27:06 -0700102
Naseer Ahmed7a7b66d2014-07-23 17:56:26 -0400103 if (code == CONNECT_HWC_CLIENT) {
Naseer Ahmed4957c522013-11-12 18:07:15 -0500104 CHECK_INTERFACE(IQService, data, reply);
105 if(callerUid != AID_GRAPHICS) {
Manoj Kumar AVM9c0bf732016-05-02 20:26:56 -0700106 ALOGE("display.qservice CONNECT_HWC_CLIENT access denied: pid=%d uid=%d",
107 callerPid, callerUid);
Naseer Ahmed4957c522013-11-12 18:07:15 -0500108 return PERMISSION_DENIED;
109 }
110 sp<IQClient> client =
111 interface_cast<IQClient>(data.readStrongBinder());
112 connect(client);
113 return NO_ERROR;
Naseer Ahmed7a7b66d2014-07-23 17:56:26 -0400114 } else if(code == CONNECT_HDMI_CLIENT) {
115 CHECK_INTERFACE(IQService, data, reply);
116 if(callerUid != AID_SYSTEM && callerUid != AID_ROOT) {
Manoj Kumar AVM9c0bf732016-05-02 20:26:56 -0700117 ALOGE("display.qservice CONNECT_HDMI_CLIENT access denied: pid=%d uid=%d",
118 callerPid, callerUid);
Naseer Ahmed7a7b66d2014-07-23 17:56:26 -0400119 return PERMISSION_DENIED;
120 }
121 sp<IQHDMIClient> client =
122 interface_cast<IQHDMIClient>(data.readStrongBinder());
123 connect(client);
124 return NO_ERROR;
Naseer Ahmed4957c522013-11-12 18:07:15 -0500125 } else if (code > COMMAND_LIST_START && code < COMMAND_LIST_END) {
126 if(!permission) {
Manoj Kumar AVM9c0bf732016-05-02 20:26:56 -0700127 ALOGE("display.qservice access denied: command=%d pid=%d uid=%d",
128 code, callerPid, callerUid);
Naseer Ahmed58780b92013-07-29 17:41:40 -0400129 return PERMISSION_DENIED;
130 }
131 CHECK_INTERFACE(IQService, data, reply);
Naseer Ahmed4957c522013-11-12 18:07:15 -0500132 dispatch(code, &data, reply);
133 return NO_ERROR;
134 } else {
135 return BBinder::onTransact(code, data, reply, flags);
Saurabh Shah56f610d2012-08-07 15:27:06 -0700136 }
137}
138
Saurabh Shah56f610d2012-08-07 15:27:06 -0700139}; // namespace qService