Saurabh Shah | 56f610d | 2012-08-07 15:27:06 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 The Android Open Source Project |
Naseer Ahmed | ce07723 | 2016-03-14 19:58:14 -0400 | [diff] [blame] | 3 | * Copyright (C) 2012-2016, The Linux Foundation. All rights reserved. |
Saurabh Shah | 56f610d | 2012-08-07 15:27:06 -0700 | [diff] [blame] | 4 | * |
| 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 Radhakrishnan | 56d883b | 2020-03-25 16:47:55 -0700 | [diff] [blame] | 28 | #ifndef TRUSTED_VM |
Naseer Ahmed | 843b799 | 2018-03-27 19:53:30 -0400 | [diff] [blame] | 29 | #include <cutils/android_filesystem_config.h> |
Ramkumar Radhakrishnan | 56d883b | 2020-03-25 16:47:55 -0700 | [diff] [blame] | 30 | #else |
| 31 | #include <private/android_filesystem_config.h> |
| 32 | #endif |
Saurabh Shah | 56f610d | 2012-08-07 15:27:06 -0700 | [diff] [blame] | 33 | #include <utils/Errors.h> |
Saurabh Shah | 56f610d | 2012-08-07 15:27:06 -0700 | [diff] [blame] | 34 | #include <IQService.h> |
| 35 | |
Naseer Ahmed | 4957c52 | 2013-11-12 18:07:15 -0500 | [diff] [blame] | 36 | #define QSERVICE_DEBUG 0 |
| 37 | |
Saurabh Shah | 56f610d | 2012-08-07 15:27:06 -0700 | [diff] [blame] | 38 | using namespace android; |
Saurabh Shah | 86c1729 | 2013-02-08 15:24:13 -0800 | [diff] [blame] | 39 | using namespace qClient; |
Saurabh Shah | 56f610d | 2012-08-07 15:27:06 -0700 | [diff] [blame] | 40 | |
| 41 | // --------------------------------------------------------------------------- |
| 42 | |
| 43 | namespace qService { |
| 44 | |
| 45 | class BpQService : public BpInterface<IQService> |
| 46 | { |
| 47 | public: |
| 48 | BpQService(const sp<IBinder>& impl) |
| 49 | : BpInterface<IQService>(impl) {} |
| 50 | |
Saurabh Shah | 86c1729 | 2013-02-08 15:24:13 -0800 | [diff] [blame] | 51 | virtual void connect(const sp<IQClient>& client) { |
Naseer Ahmed | 7a7b66d | 2014-07-23 17:56:26 -0400 | [diff] [blame] | 52 | ALOGD_IF(QSERVICE_DEBUG, "%s: connect HWC client", __FUNCTION__); |
Saurabh Shah | 86c1729 | 2013-02-08 15:24:13 -0800 | [diff] [blame] | 53 | Parcel data, reply; |
| 54 | data.writeInterfaceToken(IQService::getInterfaceDescriptor()); |
Ajay Dudani | 6c51512 | 2015-04-08 19:29:29 -0700 | [diff] [blame] | 55 | data.writeStrongBinder(IInterface::asBinder(client)); |
Naseer Ahmed | 7a7b66d | 2014-07-23 17:56:26 -0400 | [diff] [blame] | 56 | remote()->transact(CONNECT_HWC_CLIENT, data, &reply); |
Saurabh Shah | 86c1729 | 2013-02-08 15:24:13 -0800 | [diff] [blame] | 57 | } |
Jeykumar Sankaran | 9f59a76 | 2013-02-28 10:45:56 -0800 | [diff] [blame] | 58 | |
Naseer Ahmed | 7a7b66d | 2014-07-23 17:56:26 -0400 | [diff] [blame] | 59 | 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 Dudani | 6c51512 | 2015-04-08 19:29:29 -0700 | [diff] [blame] | 63 | data.writeStrongBinder(IInterface::asBinder(client)); |
Naseer Ahmed | 7a7b66d | 2014-07-23 17:56:26 -0400 | [diff] [blame] | 64 | remote()->transact(CONNECT_HDMI_CLIENT, data, &reply); |
| 65 | } |
| 66 | |
| 67 | |
Naseer Ahmed | 4957c52 | 2013-11-12 18:07:15 -0500 | [diff] [blame] | 68 | 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.R | f15adc0 | 2014-01-21 21:26:25 -0800 | [diff] [blame] | 71 | status_t err = (status_t) android::FAILED_TRANSACTION; |
Naseer Ahmed | 4957c52 | 2013-11-12 18:07:15 -0500 | [diff] [blame] | 72 | Parcel data; |
| 73 | Parcel *reply = outParcel; |
Jeykumar Sankaran | 9f59a76 | 2013-02-28 10:45:56 -0800 | [diff] [blame] | 74 | data.writeInterfaceToken(IQService::getInterfaceDescriptor()); |
Naseer Ahmed | 4957c52 | 2013-11-12 18:07:15 -0500 | [diff] [blame] | 75 | if (inParcel && inParcel->dataSize() > 0) |
| 76 | data.appendFrom(inParcel, 0, inParcel->dataSize()); |
| 77 | err = remote()->transact(command, data, reply); |
| 78 | return err; |
Naseer Ahmed | 58780b9 | 2013-07-29 17:41:40 -0400 | [diff] [blame] | 79 | } |
Saurabh Shah | 56f610d | 2012-08-07 15:27:06 -0700 | [diff] [blame] | 80 | }; |
| 81 | |
| 82 | IMPLEMENT_META_INTERFACE(QService, "android.display.IQService"); |
| 83 | |
| 84 | // ---------------------------------------------------------------------- |
| 85 | |
Saurabh Shah | 56f610d | 2012-08-07 15:27:06 -0700 | [diff] [blame] | 86 | status_t BnQService::onTransact( |
| 87 | uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) |
| 88 | { |
Naseer Ahmed | 4957c52 | 2013-11-12 18:07:15 -0500 | [diff] [blame] | 89 | ALOGD_IF(QSERVICE_DEBUG, "%s: code: %d", __FUNCTION__, code); |
| 90 | // IPC should be from certain processes only |
Saurabh Shah | 56f610d | 2012-08-07 15:27:06 -0700 | [diff] [blame] | 91 | IPCThreadState* ipc = IPCThreadState::self(); |
| 92 | const int callerPid = ipc->getCallingPid(); |
Naseer Ahmed | 52fc4cd | 2012-09-24 13:38:00 -0400 | [diff] [blame] | 93 | const int callerUid = ipc->getCallingUid(); |
Naseer Ahmed | 52fc4cd | 2012-09-24 13:38:00 -0400 | [diff] [blame] | 94 | |
Naseer Ahmed | 4957c52 | 2013-11-12 18:07:15 -0500 | [diff] [blame] | 95 | const bool permission = (callerUid == AID_MEDIA || |
| 96 | callerUid == AID_GRAPHICS || |
| 97 | callerUid == AID_ROOT || |
Naseer Ahmed | ce07723 | 2016-03-14 19:58:14 -0400 | [diff] [blame] | 98 | callerUid == AID_CAMERASERVER || |
Ramkumar Radhakrishnan | 9d68cdf | 2016-06-02 19:14:57 -0700 | [diff] [blame] | 99 | callerUid == AID_AUDIO || |
Namit Solanki | 03d5679 | 2016-11-02 15:53:43 +0530 | [diff] [blame] | 100 | callerUid == AID_SYSTEM || |
| 101 | callerUid == AID_MEDIA_CODEC); |
Saurabh Shah | 56f610d | 2012-08-07 15:27:06 -0700 | [diff] [blame] | 102 | |
Naseer Ahmed | 7a7b66d | 2014-07-23 17:56:26 -0400 | [diff] [blame] | 103 | if (code == CONNECT_HWC_CLIENT) { |
Naseer Ahmed | 4957c52 | 2013-11-12 18:07:15 -0500 | [diff] [blame] | 104 | CHECK_INTERFACE(IQService, data, reply); |
| 105 | if(callerUid != AID_GRAPHICS) { |
Manoj Kumar AVM | 9c0bf73 | 2016-05-02 20:26:56 -0700 | [diff] [blame] | 106 | ALOGE("display.qservice CONNECT_HWC_CLIENT access denied: pid=%d uid=%d", |
| 107 | callerPid, callerUid); |
Naseer Ahmed | 4957c52 | 2013-11-12 18:07:15 -0500 | [diff] [blame] | 108 | return PERMISSION_DENIED; |
| 109 | } |
| 110 | sp<IQClient> client = |
| 111 | interface_cast<IQClient>(data.readStrongBinder()); |
| 112 | connect(client); |
| 113 | return NO_ERROR; |
Naseer Ahmed | 7a7b66d | 2014-07-23 17:56:26 -0400 | [diff] [blame] | 114 | } else if(code == CONNECT_HDMI_CLIENT) { |
| 115 | CHECK_INTERFACE(IQService, data, reply); |
| 116 | if(callerUid != AID_SYSTEM && callerUid != AID_ROOT) { |
Manoj Kumar AVM | 9c0bf73 | 2016-05-02 20:26:56 -0700 | [diff] [blame] | 117 | ALOGE("display.qservice CONNECT_HDMI_CLIENT access denied: pid=%d uid=%d", |
| 118 | callerPid, callerUid); |
Naseer Ahmed | 7a7b66d | 2014-07-23 17:56:26 -0400 | [diff] [blame] | 119 | return PERMISSION_DENIED; |
| 120 | } |
| 121 | sp<IQHDMIClient> client = |
| 122 | interface_cast<IQHDMIClient>(data.readStrongBinder()); |
| 123 | connect(client); |
| 124 | return NO_ERROR; |
Naseer Ahmed | 4957c52 | 2013-11-12 18:07:15 -0500 | [diff] [blame] | 125 | } else if (code > COMMAND_LIST_START && code < COMMAND_LIST_END) { |
| 126 | if(!permission) { |
Manoj Kumar AVM | 9c0bf73 | 2016-05-02 20:26:56 -0700 | [diff] [blame] | 127 | ALOGE("display.qservice access denied: command=%d pid=%d uid=%d", |
| 128 | code, callerPid, callerUid); |
Naseer Ahmed | 58780b9 | 2013-07-29 17:41:40 -0400 | [diff] [blame] | 129 | return PERMISSION_DENIED; |
| 130 | } |
| 131 | CHECK_INTERFACE(IQService, data, reply); |
Naseer Ahmed | 4957c52 | 2013-11-12 18:07:15 -0500 | [diff] [blame] | 132 | dispatch(code, &data, reply); |
| 133 | return NO_ERROR; |
| 134 | } else { |
| 135 | return BBinder::onTransact(code, data, reply, flags); |
Saurabh Shah | 56f610d | 2012-08-07 15:27:06 -0700 | [diff] [blame] | 136 | } |
| 137 | } |
| 138 | |
Saurabh Shah | 56f610d | 2012-08-07 15:27:06 -0700 | [diff] [blame] | 139 | }; // namespace qService |