Andreas Huber | 1aec397 | 2016-08-26 09:26:32 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 17 | #include "Interface.h" |
| 18 | |
Zhuoyao Zhang | ba7e6e9 | 2016-08-10 12:19:02 -0700 | [diff] [blame] | 19 | #include "Annotation.h" |
Yifan Hong | 30b5d1f | 2017-04-03 12:19:25 -0700 | [diff] [blame] | 20 | #include "ArrayType.h" |
| 21 | #include "ConstantExpression.h" |
Martijn Coenen | 115d428 | 2016-12-19 05:14:04 +0100 | [diff] [blame] | 22 | #include "DeathRecipientType.h" |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 23 | #include "Method.h" |
Martijn Coenen | 115d428 | 2016-12-19 05:14:04 +0100 | [diff] [blame] | 24 | #include "ScalarType.h" |
Yifan Hong | 10fe0b5 | 2016-10-19 14:20:17 -0700 | [diff] [blame] | 25 | #include "StringType.h" |
| 26 | #include "VectorType.h" |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 27 | |
Yifan Hong | 30b5d1f | 2017-04-03 12:19:25 -0700 | [diff] [blame] | 28 | #include <unistd.h> |
| 29 | |
Yifan Hong | 30b5d1f | 2017-04-03 12:19:25 -0700 | [diff] [blame] | 30 | #include <iostream> |
Timur Iskhakov | 7296af1 | 2017-08-09 21:52:48 +0000 | [diff] [blame] | 31 | #include <memory> |
Yifan Hong | 30b5d1f | 2017-04-03 12:19:25 -0700 | [diff] [blame] | 32 | #include <sstream> |
Timur Iskhakov | cec46c4 | 2017-08-09 00:22:02 -0700 | [diff] [blame] | 33 | #include <unordered_map> |
Yifan Hong | 30b5d1f | 2017-04-03 12:19:25 -0700 | [diff] [blame] | 34 | |
Steven Moreland | 14ee674 | 2016-10-18 12:58:28 -0700 | [diff] [blame] | 35 | #include <android-base/logging.h> |
Steven Moreland | 5bdfa70 | 2017-04-18 23:20:39 -0700 | [diff] [blame] | 36 | #include <hidl-hash/Hash.h> |
Iliyan Malchev | a72e0d2 | 2016-09-09 11:03:08 -0700 | [diff] [blame] | 37 | #include <hidl-util/Formatter.h> |
Yifan Hong | 10fe0b5 | 2016-10-19 14:20:17 -0700 | [diff] [blame] | 38 | #include <hidl-util/StringHelper.h> |
Zhuoyao Zhang | 864c771 | 2016-08-16 15:35:28 -0700 | [diff] [blame] | 39 | |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 40 | namespace android { |
| 41 | |
Steven Moreland | b8e15a5 | 2017-02-13 19:35:40 -0800 | [diff] [blame] | 42 | #define B_PACK_CHARS(c1, c2, c3, c4) \ |
| 43 | ((((c1)<<24)) | (((c2)<<16)) | (((c3)<<8)) | (c4)) |
| 44 | |
Yifan Hong | 10fe0b5 | 2016-10-19 14:20:17 -0700 | [diff] [blame] | 45 | /* It is very important that these values NEVER change. These values |
| 46 | * must remain unchanged over the lifetime of android. This is |
| 47 | * because the framework on a device will be updated independently of |
| 48 | * the hals on a device. If the hals are compiled with one set of |
| 49 | * transaction values, and the framework with another, then the |
| 50 | * interface between them will be destroyed, and the device will not |
| 51 | * work. |
| 52 | */ |
| 53 | enum { |
Yifan Hong | 10fe0b5 | 2016-10-19 14:20:17 -0700 | [diff] [blame] | 54 | /////////////////// User defined transactions |
| 55 | FIRST_CALL_TRANSACTION = 0x00000001, |
Steven Moreland | b8e15a5 | 2017-02-13 19:35:40 -0800 | [diff] [blame] | 56 | LAST_CALL_TRANSACTION = 0x0effffff, |
Yifan Hong | 10fe0b5 | 2016-10-19 14:20:17 -0700 | [diff] [blame] | 57 | /////////////////// HIDL reserved |
Steven Moreland | b8e15a5 | 2017-02-13 19:35:40 -0800 | [diff] [blame] | 58 | FIRST_HIDL_TRANSACTION = 0x0f000000, |
| 59 | HIDL_PING_TRANSACTION = B_PACK_CHARS(0x0f, 'P', 'N', 'G'), |
| 60 | HIDL_DESCRIPTOR_CHAIN_TRANSACTION = B_PACK_CHARS(0x0f, 'C', 'H', 'N'), |
| 61 | HIDL_GET_DESCRIPTOR_TRANSACTION = B_PACK_CHARS(0x0f, 'D', 'S', 'C'), |
| 62 | HIDL_SYSPROPS_CHANGED_TRANSACTION = B_PACK_CHARS(0x0f, 'S', 'Y', 'S'), |
| 63 | HIDL_LINK_TO_DEATH_TRANSACTION = B_PACK_CHARS(0x0f, 'L', 'T', 'D'), |
| 64 | HIDL_UNLINK_TO_DEATH_TRANSACTION = B_PACK_CHARS(0x0f, 'U', 'T', 'D'), |
| 65 | HIDL_SET_HAL_INSTRUMENTATION_TRANSACTION = B_PACK_CHARS(0x0f, 'I', 'N', 'T'), |
| 66 | HIDL_GET_REF_INFO_TRANSACTION = B_PACK_CHARS(0x0f, 'R', 'E', 'F'), |
| 67 | HIDL_DEBUG_TRANSACTION = B_PACK_CHARS(0x0f, 'D', 'B', 'G'), |
Yifan Hong | 30b5d1f | 2017-04-03 12:19:25 -0700 | [diff] [blame] | 68 | HIDL_HASH_CHAIN_TRANSACTION = B_PACK_CHARS(0x0f, 'H', 'S', 'H'), |
Steven Moreland | b8e15a5 | 2017-02-13 19:35:40 -0800 | [diff] [blame] | 69 | LAST_HIDL_TRANSACTION = 0x0fffffff, |
Yifan Hong | 10fe0b5 | 2016-10-19 14:20:17 -0700 | [diff] [blame] | 70 | }; |
| 71 | |
Timur Iskhakov | 565b013 | 2017-09-06 18:07:11 -0700 | [diff] [blame] | 72 | Interface::Interface(const char* localName, const FQName& fullName, const Location& location, |
| 73 | Scope* parent, const Reference<Type>& superType) |
Timur Iskhakov | 5dc72fe | 2017-09-07 23:13:44 -0700 | [diff] [blame] | 74 | : Scope(localName, fullName, location, parent), mSuperType(superType) {} |
Martijn Coenen | af712c0 | 2016-11-16 15:26:27 +0100 | [diff] [blame] | 75 | |
Steven Moreland | 30bb6a8 | 2016-11-30 09:18:34 -0800 | [diff] [blame] | 76 | std::string Interface::typeName() const { |
| 77 | return "interface " + localName(); |
| 78 | } |
| 79 | |
Steven Moreland | 424a948 | 2017-02-13 19:20:40 -0800 | [diff] [blame] | 80 | bool Interface::fillPingMethod(Method *method) const { |
| 81 | if (method->name() != "ping") { |
| 82 | return false; |
| 83 | } |
| 84 | |
| 85 | method->fillImplementation( |
| 86 | HIDL_PING_TRANSACTION, |
| 87 | { |
Steven Moreland | 937408a | 2017-03-20 09:54:18 -0700 | [diff] [blame] | 88 | {IMPL_INTERFACE, |
Steven Moreland | 424a948 | 2017-02-13 19:20:40 -0800 | [diff] [blame] | 89 | [](auto &out) { |
| 90 | out << "return ::android::hardware::Void();\n"; |
| 91 | } |
| 92 | }, |
| 93 | {IMPL_STUB_IMPL, |
| 94 | [](auto &out) { |
| 95 | out << "return ::android::hardware::Void();\n"; |
| 96 | } |
| 97 | } |
| 98 | }, /*cppImpl*/ |
| 99 | { |
Steven Moreland | 937408a | 2017-03-20 09:54:18 -0700 | [diff] [blame] | 100 | {IMPL_INTERFACE, |
Yi Kong | c8ff467 | 2017-04-30 23:46:56 -0700 | [diff] [blame] | 101 | [](auto &out) { |
Steven Moreland | 424a948 | 2017-02-13 19:20:40 -0800 | [diff] [blame] | 102 | out << "return;\n"; |
| 103 | } |
| 104 | }, |
| 105 | {IMPL_STUB, nullptr /* don't generate code */} |
| 106 | } /*javaImpl*/ |
| 107 | ); |
| 108 | |
| 109 | return true; |
| 110 | } |
| 111 | |
Yifan Hong | ffa9139 | 2017-01-31 13:41:23 -0800 | [diff] [blame] | 112 | bool Interface::fillLinkToDeathMethod(Method *method) const { |
| 113 | if (method->name() != "linkToDeath") { |
| 114 | return false; |
| 115 | } |
Martijn Coenen | 115d428 | 2016-12-19 05:14:04 +0100 | [diff] [blame] | 116 | |
Yifan Hong | ffa9139 | 2017-01-31 13:41:23 -0800 | [diff] [blame] | 117 | method->fillImplementation( |
Martijn Coenen | 115d428 | 2016-12-19 05:14:04 +0100 | [diff] [blame] | 118 | HIDL_LINK_TO_DEATH_TRANSACTION, |
| 119 | { |
Steven Moreland | 937408a | 2017-03-20 09:54:18 -0700 | [diff] [blame] | 120 | {IMPL_INTERFACE, |
Martijn Coenen | 115d428 | 2016-12-19 05:14:04 +0100 | [diff] [blame] | 121 | [](auto &out) { |
| 122 | out << "(void)cookie;\n" |
| 123 | << "return (recipient != nullptr);\n"; |
| 124 | } |
| 125 | }, |
| 126 | {IMPL_PROXY, |
| 127 | [](auto &out) { |
Martijn Coenen | fa55d6e | 2016-12-20 06:08:31 +0100 | [diff] [blame] | 128 | out << "::android::hardware::ProcessState::self()->startThreadPool();\n"; |
Martijn Coenen | 115d428 | 2016-12-19 05:14:04 +0100 | [diff] [blame] | 129 | out << "::android::hardware::hidl_binder_death_recipient *binder_recipient" |
| 130 | << " = new ::android::hardware::hidl_binder_death_recipient(recipient, cookie, this);\n" |
| 131 | << "std::unique_lock<std::mutex> lock(_hidl_mMutex);\n" |
| 132 | << "_hidl_mDeathRecipients.push_back(binder_recipient);\n" |
| 133 | << "return (remote()->linkToDeath(binder_recipient)" |
| 134 | << " == ::android::OK);\n"; |
| 135 | } |
| 136 | }, |
Martijn Coenen | 8d12b50 | 2016-12-27 14:30:27 +0100 | [diff] [blame] | 137 | {IMPL_STUB, nullptr} |
Martijn Coenen | 115d428 | 2016-12-19 05:14:04 +0100 | [diff] [blame] | 138 | }, /*cppImpl*/ |
| 139 | { |
Steven Moreland | 937408a | 2017-03-20 09:54:18 -0700 | [diff] [blame] | 140 | {IMPL_INTERFACE, |
Yi Kong | c8ff467 | 2017-04-30 23:46:56 -0700 | [diff] [blame] | 141 | [](auto &out) { |
Martijn Coenen | 115d428 | 2016-12-19 05:14:04 +0100 | [diff] [blame] | 142 | out << "return true;"; |
| 143 | } |
| 144 | }, |
| 145 | {IMPL_PROXY, |
Yi Kong | c8ff467 | 2017-04-30 23:46:56 -0700 | [diff] [blame] | 146 | [](auto &out) { |
Martijn Coenen | 8d12b50 | 2016-12-27 14:30:27 +0100 | [diff] [blame] | 147 | out << "return mRemote.linkToDeath(recipient, cookie);\n"; |
Martijn Coenen | 115d428 | 2016-12-19 05:14:04 +0100 | [diff] [blame] | 148 | } |
| 149 | }, |
Martijn Coenen | 8d12b50 | 2016-12-27 14:30:27 +0100 | [diff] [blame] | 150 | {IMPL_STUB, nullptr} |
Martijn Coenen | 115d428 | 2016-12-19 05:14:04 +0100 | [diff] [blame] | 151 | } /*javaImpl*/ |
| 152 | ); |
Yifan Hong | ffa9139 | 2017-01-31 13:41:23 -0800 | [diff] [blame] | 153 | return true; |
Martijn Coenen | 115d428 | 2016-12-19 05:14:04 +0100 | [diff] [blame] | 154 | } |
| 155 | |
Yifan Hong | ffa9139 | 2017-01-31 13:41:23 -0800 | [diff] [blame] | 156 | bool Interface::fillUnlinkToDeathMethod(Method *method) const { |
| 157 | if (method->name() != "unlinkToDeath") { |
| 158 | return false; |
| 159 | } |
Martijn Coenen | 115d428 | 2016-12-19 05:14:04 +0100 | [diff] [blame] | 160 | |
Yifan Hong | ffa9139 | 2017-01-31 13:41:23 -0800 | [diff] [blame] | 161 | method->fillImplementation( |
Martijn Coenen | 115d428 | 2016-12-19 05:14:04 +0100 | [diff] [blame] | 162 | HIDL_UNLINK_TO_DEATH_TRANSACTION, |
| 163 | { |
Steven Moreland | 937408a | 2017-03-20 09:54:18 -0700 | [diff] [blame] | 164 | {IMPL_INTERFACE, |
Martijn Coenen | 115d428 | 2016-12-19 05:14:04 +0100 | [diff] [blame] | 165 | [](auto &out) { |
| 166 | out << "return (recipient != nullptr);\n"; |
| 167 | } |
| 168 | }, |
| 169 | {IMPL_PROXY, |
| 170 | [](auto &out) { |
| 171 | out << "std::unique_lock<std::mutex> lock(_hidl_mMutex);\n" |
| 172 | << "for (auto it = _hidl_mDeathRecipients.begin();" |
| 173 | << "it != _hidl_mDeathRecipients.end();" |
| 174 | << "++it) {\n"; |
| 175 | out.indent([&] { |
| 176 | out.sIf("(*it)->getRecipient() == recipient", [&] { |
| 177 | out << "::android::status_t status = remote()->unlinkToDeath(*it);\n" |
| 178 | << "_hidl_mDeathRecipients.erase(it);\n" |
| 179 | << "return status == ::android::OK;\n"; |
| 180 | }); |
| 181 | }); |
| 182 | out << "}\n"; |
| 183 | out << "return false;\n"; |
| 184 | } |
| 185 | }, |
Martijn Coenen | 8d12b50 | 2016-12-27 14:30:27 +0100 | [diff] [blame] | 186 | {IMPL_STUB, nullptr /* don't generate code */} |
Martijn Coenen | 115d428 | 2016-12-19 05:14:04 +0100 | [diff] [blame] | 187 | }, /*cppImpl*/ |
| 188 | { |
Steven Moreland | 937408a | 2017-03-20 09:54:18 -0700 | [diff] [blame] | 189 | {IMPL_INTERFACE, |
Yi Kong | c8ff467 | 2017-04-30 23:46:56 -0700 | [diff] [blame] | 190 | [](auto &out) { |
Martijn Coenen | 8d12b50 | 2016-12-27 14:30:27 +0100 | [diff] [blame] | 191 | out << "return true;\n"; |
Martijn Coenen | 115d428 | 2016-12-19 05:14:04 +0100 | [diff] [blame] | 192 | } |
| 193 | }, |
| 194 | {IMPL_PROXY, |
Yi Kong | c8ff467 | 2017-04-30 23:46:56 -0700 | [diff] [blame] | 195 | [](auto &out) { |
Martijn Coenen | 8d12b50 | 2016-12-27 14:30:27 +0100 | [diff] [blame] | 196 | out << "return mRemote.unlinkToDeath(recipient);\n"; |
Martijn Coenen | 115d428 | 2016-12-19 05:14:04 +0100 | [diff] [blame] | 197 | } |
| 198 | }, |
Martijn Coenen | 8d12b50 | 2016-12-27 14:30:27 +0100 | [diff] [blame] | 199 | {IMPL_STUB, nullptr /* don't generate code */} |
Martijn Coenen | 115d428 | 2016-12-19 05:14:04 +0100 | [diff] [blame] | 200 | } /*javaImpl*/ |
| 201 | ); |
Yifan Hong | ffa9139 | 2017-01-31 13:41:23 -0800 | [diff] [blame] | 202 | return true; |
Martijn Coenen | 115d428 | 2016-12-19 05:14:04 +0100 | [diff] [blame] | 203 | } |
Yifan Hong | ffa9139 | 2017-01-31 13:41:23 -0800 | [diff] [blame] | 204 | bool Interface::fillSyspropsChangedMethod(Method *method) const { |
| 205 | if (method->name() != "notifySyspropsChanged") { |
| 206 | return false; |
| 207 | } |
| 208 | |
| 209 | method->fillImplementation( |
Martijn Coenen | af712c0 | 2016-11-16 15:26:27 +0100 | [diff] [blame] | 210 | HIDL_SYSPROPS_CHANGED_TRANSACTION, |
Yi Kong | c8ff467 | 2017-04-30 23:46:56 -0700 | [diff] [blame] | 211 | { { IMPL_INTERFACE, [](auto &out) { |
Martijn Coenen | af712c0 | 2016-11-16 15:26:27 +0100 | [diff] [blame] | 212 | out << "::android::report_sysprop_change();\n"; |
| 213 | out << "return ::android::hardware::Void();"; |
Martijn Coenen | 115d428 | 2016-12-19 05:14:04 +0100 | [diff] [blame] | 214 | } } }, /*cppImpl */ |
Steven Moreland | 937408a | 2017-03-20 09:54:18 -0700 | [diff] [blame] | 215 | { { IMPL_INTERFACE, [](auto &out) { /* javaImpl */ |
Sundong Ahn | c1432c9 | 2017-07-13 23:58:27 +0900 | [diff] [blame] | 216 | out << "android.os.HwBinder.reportSyspropChanged();"; |
Martijn Coenen | 115d428 | 2016-12-19 05:14:04 +0100 | [diff] [blame] | 217 | } } } /*javaImpl */ |
Martijn Coenen | af712c0 | 2016-11-16 15:26:27 +0100 | [diff] [blame] | 218 | ); |
Yifan Hong | ffa9139 | 2017-01-31 13:41:23 -0800 | [diff] [blame] | 219 | return true; |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 220 | } |
| 221 | |
Yifan Hong | ffa9139 | 2017-01-31 13:41:23 -0800 | [diff] [blame] | 222 | bool Interface::fillSetHALInstrumentationMethod(Method *method) const { |
| 223 | if (method->name() != "setHALInstrumentation") { |
| 224 | return false; |
| 225 | } |
| 226 | |
| 227 | method->fillImplementation( |
Zhuoyao Zhang | dd85c5c | 2017-01-03 17:30:24 -0800 | [diff] [blame] | 228 | HIDL_SET_HAL_INSTRUMENTATION_TRANSACTION, |
| 229 | { |
Steven Moreland | 937408a | 2017-03-20 09:54:18 -0700 | [diff] [blame] | 230 | {IMPL_INTERFACE, |
Yi Kong | c8ff467 | 2017-04-30 23:46:56 -0700 | [diff] [blame] | 231 | [](auto &out) { |
Zhuoyao Zhang | dd85c5c | 2017-01-03 17:30:24 -0800 | [diff] [blame] | 232 | // do nothing for base class. |
| 233 | out << "return ::android::hardware::Void();\n"; |
| 234 | } |
| 235 | }, |
Zhuoyao Zhang | dd85c5c | 2017-01-03 17:30:24 -0800 | [diff] [blame] | 236 | {IMPL_STUB, |
| 237 | [](auto &out) { |
| 238 | out << "configureInstrumentation();\n"; |
| 239 | } |
| 240 | }, |
| 241 | {IMPL_PASSTHROUGH, |
| 242 | [](auto &out) { |
| 243 | out << "configureInstrumentation();\n"; |
| 244 | out << "return ::android::hardware::Void();\n"; |
| 245 | } |
| 246 | }, |
| 247 | }, /*cppImpl */ |
Steven Moreland | 937408a | 2017-03-20 09:54:18 -0700 | [diff] [blame] | 248 | { { IMPL_INTERFACE, [](auto & /*out*/) { /* javaImpl */ |
Zhuoyao Zhang | dd85c5c | 2017-01-03 17:30:24 -0800 | [diff] [blame] | 249 | // Not support for Java Impl for now. |
| 250 | } } } /*javaImpl */ |
| 251 | ); |
Yifan Hong | ffa9139 | 2017-01-31 13:41:23 -0800 | [diff] [blame] | 252 | return true; |
Zhuoyao Zhang | dd85c5c | 2017-01-03 17:30:24 -0800 | [diff] [blame] | 253 | } |
| 254 | |
Yifan Hong | ffa9139 | 2017-01-31 13:41:23 -0800 | [diff] [blame] | 255 | bool Interface::fillDescriptorChainMethod(Method *method) const { |
| 256 | if (method->name() != "interfaceChain") { |
| 257 | return false; |
| 258 | } |
Yifan Hong | 10fe0b5 | 2016-10-19 14:20:17 -0700 | [diff] [blame] | 259 | |
Yifan Hong | ffa9139 | 2017-01-31 13:41:23 -0800 | [diff] [blame] | 260 | method->fillImplementation( |
Yifan Hong | 10fe0b5 | 2016-10-19 14:20:17 -0700 | [diff] [blame] | 261 | HIDL_DESCRIPTOR_CHAIN_TRANSACTION, |
Steven Moreland | 937408a | 2017-03-20 09:54:18 -0700 | [diff] [blame] | 262 | { { IMPL_INTERFACE, [this](auto &out) { |
Yifan Hong | 10fe0b5 | 2016-10-19 14:20:17 -0700 | [diff] [blame] | 263 | std::vector<const Interface *> chain = typeChain(); |
Yifan Hong | 0393512 | 2016-12-19 11:10:40 -0800 | [diff] [blame] | 264 | out << "_hidl_cb("; |
| 265 | out.block([&] { |
| 266 | for (const Interface *iface : chain) { |
| 267 | out << iface->fullName() << "::descriptor,\n"; |
| 268 | } |
| 269 | }); |
| 270 | out << ");\n"; |
Yifan Hong | 10fe0b5 | 2016-10-19 14:20:17 -0700 | [diff] [blame] | 271 | out << "return ::android::hardware::Void();"; |
Martijn Coenen | 115d428 | 2016-12-19 05:14:04 +0100 | [diff] [blame] | 272 | } } }, /* cppImpl */ |
Steven Moreland | 937408a | 2017-03-20 09:54:18 -0700 | [diff] [blame] | 273 | { { IMPL_INTERFACE, [this](auto &out) { |
Yifan Hong | 10fe0b5 | 2016-10-19 14:20:17 -0700 | [diff] [blame] | 274 | std::vector<const Interface *> chain = typeChain(); |
Yifan Hong | 1af7353 | 2016-11-09 14:32:58 -0800 | [diff] [blame] | 275 | out << "return new java.util.ArrayList<String>(java.util.Arrays.asList(\n"; |
Yifan Hong | 10fe0b5 | 2016-10-19 14:20:17 -0700 | [diff] [blame] | 276 | out.indent(); out.indent(); |
| 277 | for (size_t i = 0; i < chain.size(); ++i) { |
| 278 | if (i != 0) |
| 279 | out << ",\n"; |
Steven Moreland | d39133b | 2016-11-11 12:30:08 -0800 | [diff] [blame] | 280 | out << chain[i]->fullJavaName() << ".kInterfaceName"; |
Yifan Hong | 10fe0b5 | 2016-10-19 14:20:17 -0700 | [diff] [blame] | 281 | } |
| 282 | out << "));"; |
| 283 | out.unindent(); out.unindent(); |
Yifan Hong | ffa9139 | 2017-01-31 13:41:23 -0800 | [diff] [blame] | 284 | } } } /* javaImpl */ |
Martijn Coenen | 115d428 | 2016-12-19 05:14:04 +0100 | [diff] [blame] | 285 | ); |
Yifan Hong | ffa9139 | 2017-01-31 13:41:23 -0800 | [diff] [blame] | 286 | return true; |
Yifan Hong | 10fe0b5 | 2016-10-19 14:20:17 -0700 | [diff] [blame] | 287 | } |
| 288 | |
Yifan Hong | 30b5d1f | 2017-04-03 12:19:25 -0700 | [diff] [blame] | 289 | static void emitDigestChain( |
Timur Iskhakov | 7296af1 | 2017-08-09 21:52:48 +0000 | [diff] [blame] | 290 | Formatter& out, const std::string& prefix, const std::vector<const Interface*>& chain, |
| 291 | std::function<std::string(std::unique_ptr<ConstantExpression>)> byteToString) { |
Yifan Hong | 30b5d1f | 2017-04-03 12:19:25 -0700 | [diff] [blame] | 292 | out.join(chain.begin(), chain.end(), ",\n", [&] (const auto &iface) { |
Steven Moreland | 0e4be1e | 2017-04-18 19:50:29 -0700 | [diff] [blame] | 293 | const Hash &hash = Hash::getHash(iface->location().begin().filename()); |
Yifan Hong | 30b5d1f | 2017-04-03 12:19:25 -0700 | [diff] [blame] | 294 | out << prefix; |
| 295 | out << "{"; |
Steven Moreland | 0e4be1e | 2017-04-18 19:50:29 -0700 | [diff] [blame] | 296 | out.join(hash.raw().begin(), hash.raw().end(), ",", [&](const auto &e) { |
Yifan Hong | 30b5d1f | 2017-04-03 12:19:25 -0700 | [diff] [blame] | 297 | // Use ConstantExpression::cppValue / javaValue |
| 298 | // because Java used signed byte for uint8_t. |
| 299 | out << byteToString(ConstantExpression::ValueOf(ScalarType::Kind::KIND_UINT8, e)); |
| 300 | }); |
| 301 | out << "} /* "; |
Steven Moreland | 0e4be1e | 2017-04-18 19:50:29 -0700 | [diff] [blame] | 302 | out << hash.hexString(); |
Yifan Hong | 30b5d1f | 2017-04-03 12:19:25 -0700 | [diff] [blame] | 303 | out << " */"; |
| 304 | }); |
| 305 | } |
| 306 | |
| 307 | bool Interface::fillHashChainMethod(Method *method) const { |
| 308 | if (method->name() != "getHashChain") { |
| 309 | return false; |
| 310 | } |
| 311 | const VectorType *chainType = static_cast<const VectorType *>(&method->results()[0]->type()); |
| 312 | const ArrayType *digestType = static_cast<const ArrayType *>(chainType->getElementType()); |
| 313 | |
| 314 | method->fillImplementation( |
| 315 | HIDL_HASH_CHAIN_TRANSACTION, |
| 316 | { { IMPL_INTERFACE, [this, digestType](auto &out) { |
| 317 | std::vector<const Interface *> chain = typeChain(); |
| 318 | out << "_hidl_cb("; |
| 319 | out.block([&] { |
Timur Iskhakov | 7296af1 | 2017-08-09 21:52:48 +0000 | [diff] [blame] | 320 | emitDigestChain(out, "(" + digestType->getInternalDataCppType() + ")", chain, |
| 321 | [](const auto& e) { return e->cppValue(); }); |
Yifan Hong | 30b5d1f | 2017-04-03 12:19:25 -0700 | [diff] [blame] | 322 | }); |
| 323 | out << ");\n"; |
| 324 | out << "return ::android::hardware::Void();\n"; |
| 325 | } } }, /* cppImpl */ |
| 326 | { { IMPL_INTERFACE, [this, digestType, chainType](auto &out) { |
| 327 | std::vector<const Interface *> chain = typeChain(); |
| 328 | out << "return new " |
| 329 | << chainType->getJavaType(false /* forInitializer */) |
| 330 | << "(java.util.Arrays.asList(\n"; |
| 331 | out.indent(2, [&] { |
| 332 | // No need for dimensions when elements are explicitly provided. |
| 333 | emitDigestChain(out, "new " + digestType->getJavaType(false /* forInitializer */), |
Timur Iskhakov | 7296af1 | 2017-08-09 21:52:48 +0000 | [diff] [blame] | 334 | chain, [](const auto& e) { return e->javaValue(); }); |
Yifan Hong | 30b5d1f | 2017-04-03 12:19:25 -0700 | [diff] [blame] | 335 | }); |
| 336 | out << "));\n"; |
| 337 | } } } /* javaImpl */ |
| 338 | ); |
| 339 | return true; |
| 340 | } |
| 341 | |
Yifan Hong | ffa9139 | 2017-01-31 13:41:23 -0800 | [diff] [blame] | 342 | bool Interface::fillGetDescriptorMethod(Method *method) const { |
| 343 | if (method->name() != "interfaceDescriptor") { |
| 344 | return false; |
| 345 | } |
Yifan Hong | c75fd47 | 2017-01-11 12:37:31 -0800 | [diff] [blame] | 346 | |
Yifan Hong | ffa9139 | 2017-01-31 13:41:23 -0800 | [diff] [blame] | 347 | method->fillImplementation( |
Yifan Hong | c75fd47 | 2017-01-11 12:37:31 -0800 | [diff] [blame] | 348 | HIDL_GET_DESCRIPTOR_TRANSACTION, |
Steven Moreland | 937408a | 2017-03-20 09:54:18 -0700 | [diff] [blame] | 349 | { { IMPL_INTERFACE, [this](auto &out) { |
Yifan Hong | c75fd47 | 2017-01-11 12:37:31 -0800 | [diff] [blame] | 350 | out << "_hidl_cb(" |
| 351 | << fullName() |
| 352 | << "::descriptor);\n" |
| 353 | << "return ::android::hardware::Void();"; |
| 354 | } } }, /* cppImpl */ |
Steven Moreland | 937408a | 2017-03-20 09:54:18 -0700 | [diff] [blame] | 355 | { { IMPL_INTERFACE, [this](auto &out) { |
Yifan Hong | c75fd47 | 2017-01-11 12:37:31 -0800 | [diff] [blame] | 356 | out << "return " |
| 357 | << fullJavaName() |
| 358 | << ".kInterfaceName;\n"; |
Yifan Hong | ffa9139 | 2017-01-31 13:41:23 -0800 | [diff] [blame] | 359 | } } } /* javaImpl */ |
Yifan Hong | c75fd47 | 2017-01-11 12:37:31 -0800 | [diff] [blame] | 360 | ); |
Yifan Hong | ffa9139 | 2017-01-31 13:41:23 -0800 | [diff] [blame] | 361 | return true; |
Yifan Hong | c75fd47 | 2017-01-11 12:37:31 -0800 | [diff] [blame] | 362 | } |
Yifan Hong | 10fe0b5 | 2016-10-19 14:20:17 -0700 | [diff] [blame] | 363 | |
Yifan Hong | bcffce2 | 2017-02-01 15:52:06 -0800 | [diff] [blame] | 364 | bool Interface::fillGetDebugInfoMethod(Method *method) const { |
| 365 | if (method->name() != "getDebugInfo") { |
Yifan Hong | cd2ae45 | 2017-01-31 14:33:40 -0800 | [diff] [blame] | 366 | return false; |
| 367 | } |
| 368 | |
Yifan Hong | df1ea3f | 2017-03-02 17:02:10 -0800 | [diff] [blame] | 369 | static const std::string sArch = |
| 370 | "#if defined(__LP64__)\n" |
| 371 | "::android::hidl::base::V1_0::DebugInfo::Architecture::IS_64BIT\n" |
| 372 | "#else\n" |
| 373 | "::android::hidl::base::V1_0::DebugInfo::Architecture::IS_32BIT\n" |
| 374 | "#endif\n"; |
| 375 | |
Yifan Hong | cd2ae45 | 2017-01-31 14:33:40 -0800 | [diff] [blame] | 376 | method->fillImplementation( |
| 377 | HIDL_GET_REF_INFO_TRANSACTION, |
| 378 | { |
Steven Moreland | 937408a | 2017-03-20 09:54:18 -0700 | [diff] [blame] | 379 | {IMPL_INTERFACE, |
Yi Kong | c8ff467 | 2017-04-30 23:46:56 -0700 | [diff] [blame] | 380 | [](auto &out) { |
Yifan Hong | bcffce2 | 2017-02-01 15:52:06 -0800 | [diff] [blame] | 381 | // getDebugInfo returns N/A for local objects. |
Yifan Hong | df1ea3f | 2017-03-02 17:02:10 -0800 | [diff] [blame] | 382 | out << "_hidl_cb({ -1 /* pid */, 0 /* ptr */, \n" |
| 383 | << sArch |
| 384 | << "});\n" |
Yifan Hong | cd2ae45 | 2017-01-31 14:33:40 -0800 | [diff] [blame] | 385 | << "return ::android::hardware::Void();"; |
| 386 | } |
| 387 | }, |
| 388 | {IMPL_STUB_IMPL, |
Yi Kong | c8ff467 | 2017-04-30 23:46:56 -0700 | [diff] [blame] | 389 | [](auto &out) { |
Yifan Hong | 2e036c9 | 2017-03-07 13:18:12 -0800 | [diff] [blame] | 390 | out << "_hidl_cb("; |
| 391 | out.block([&] { |
| 392 | out << "::android::hardware::details::debuggable()" |
| 393 | << "? getpid() : -1 /* pid */,\n" |
| 394 | << "::android::hardware::details::debuggable()" |
| 395 | << "? reinterpret_cast<uint64_t>(this) : 0 /* ptr */,\n" |
| 396 | << sArch << "\n"; |
| 397 | }); |
| 398 | out << ");\n" |
Yifan Hong | cd2ae45 | 2017-01-31 14:33:40 -0800 | [diff] [blame] | 399 | << "return ::android::hardware::Void();"; |
| 400 | } |
| 401 | } |
| 402 | }, /* cppImpl */ |
Yi Kong | c8ff467 | 2017-04-30 23:46:56 -0700 | [diff] [blame] | 403 | { { IMPL_INTERFACE, [method](auto &out) { |
Yifan Hong | cd2ae45 | 2017-01-31 14:33:40 -0800 | [diff] [blame] | 404 | const Type &refInfo = method->results().front()->type(); |
| 405 | out << refInfo.getJavaType(false /* forInitializer */) << " info = new " |
| 406 | << refInfo.getJavaType(true /* forInitializer */) << "();\n" |
Yifan Hong | bcffce2 | 2017-02-01 15:52:06 -0800 | [diff] [blame] | 407 | // TODO(b/34777099): PID for java. |
| 408 | << "info.pid = -1;\n" |
| 409 | << "info.ptr = 0;\n" |
Yifan Hong | df1ea3f | 2017-03-02 17:02:10 -0800 | [diff] [blame] | 410 | << "info.arch = android.hidl.base.V1_0.DebugInfo.Architecture.UNKNOWN;" |
Yifan Hong | cd2ae45 | 2017-01-31 14:33:40 -0800 | [diff] [blame] | 411 | << "return info;"; |
| 412 | } } } /* javaImpl */ |
| 413 | ); |
| 414 | |
| 415 | return true; |
| 416 | } |
| 417 | |
Andreas Huber | 37065d6 | 2017-02-07 14:36:54 -0800 | [diff] [blame] | 418 | bool Interface::fillDebugMethod(Method *method) const { |
| 419 | if (method->name() != "debug") { |
| 420 | return false; |
| 421 | } |
| 422 | |
| 423 | method->fillImplementation( |
| 424 | HIDL_DEBUG_TRANSACTION, |
| 425 | { |
Steven Moreland | 937408a | 2017-03-20 09:54:18 -0700 | [diff] [blame] | 426 | {IMPL_INTERFACE, |
Yi Kong | c8ff467 | 2017-04-30 23:46:56 -0700 | [diff] [blame] | 427 | [](auto &out) { |
Andreas Huber | 37065d6 | 2017-02-07 14:36:54 -0800 | [diff] [blame] | 428 | out << "(void)fd;\n" |
| 429 | << "(void)options;\n" |
| 430 | << "return ::android::hardware::Void();"; |
| 431 | } |
| 432 | }, |
| 433 | }, /* cppImpl */ |
| 434 | { |
| 435 | /* unused, as the debug method is hidden from Java */ |
| 436 | } /* javaImpl */ |
| 437 | ); |
| 438 | |
| 439 | return true; |
| 440 | } |
| 441 | |
Yifan Hong | ffa9139 | 2017-01-31 13:41:23 -0800 | [diff] [blame] | 442 | static std::map<std::string, Method *> gAllReservedMethods; |
| 443 | |
Steven Moreland | 14ee674 | 2016-10-18 12:58:28 -0700 | [diff] [blame] | 444 | bool Interface::addMethod(Method *method) { |
Yifan Hong | c893404 | 2016-11-17 17:10:52 -0800 | [diff] [blame] | 445 | if (isIBase()) { |
Yifan Hong | ffa9139 | 2017-01-31 13:41:23 -0800 | [diff] [blame] | 446 | if (!gAllReservedMethods.emplace(method->name(), method).second) { |
Steven Moreland | cbff561 | 2017-10-11 17:01:54 -0700 | [diff] [blame] | 447 | std::cerr << "ERROR: hidl-gen encountered duplicated reserved method " << method->name() |
| 448 | << std::endl; |
Yifan Hong | ffa9139 | 2017-01-31 13:41:23 -0800 | [diff] [blame] | 449 | return false; |
| 450 | } |
| 451 | // will add it in addAllReservedMethods |
Yifan Hong | c893404 | 2016-11-17 17:10:52 -0800 | [diff] [blame] | 452 | return true; |
| 453 | } |
| 454 | |
Yifan Hong | 10fe0b5 | 2016-10-19 14:20:17 -0700 | [diff] [blame] | 455 | CHECK(!method->isHidlReserved()); |
Yifan Hong | 10fe0b5 | 2016-10-19 14:20:17 -0700 | [diff] [blame] | 456 | mUserMethods.push_back(method); |
Steven Moreland | 14ee674 | 2016-10-18 12:58:28 -0700 | [diff] [blame] | 457 | |
| 458 | return true; |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 459 | } |
| 460 | |
Timur Iskhakov | b58f418 | 2017-08-29 15:19:24 -0700 | [diff] [blame] | 461 | std::vector<const Reference<Type>*> Interface::getReferences() const { |
| 462 | std::vector<const Reference<Type>*> ret; |
Timur Iskhakov | 33431e6 | 2017-08-21 17:31:23 -0700 | [diff] [blame] | 463 | |
Timur Iskhakov | 82c048e | 2017-09-09 01:20:53 -0700 | [diff] [blame] | 464 | if (!isIBase()) { |
Timur Iskhakov | b58f418 | 2017-08-29 15:19:24 -0700 | [diff] [blame] | 465 | ret.push_back(&mSuperType); |
Timur Iskhakov | 33431e6 | 2017-08-21 17:31:23 -0700 | [diff] [blame] | 466 | } |
| 467 | |
| 468 | for (const auto* method : methods()) { |
| 469 | const auto& references = method->getReferences(); |
| 470 | ret.insert(ret.end(), references.begin(), references.end()); |
| 471 | } |
| 472 | |
| 473 | return ret; |
| 474 | } |
| 475 | |
Timur Iskhakov | b58f418 | 2017-08-29 15:19:24 -0700 | [diff] [blame] | 476 | std::vector<const ConstantExpression*> Interface::getConstantExpressions() const { |
| 477 | std::vector<const ConstantExpression*> ret; |
Timur Iskhakov | 891a866 | 2017-08-25 21:53:48 -0700 | [diff] [blame] | 478 | for (const auto* method : methods()) { |
| 479 | const auto& retMethod = method->getConstantExpressions(); |
| 480 | ret.insert(ret.end(), retMethod.begin(), retMethod.end()); |
| 481 | } |
| 482 | return ret; |
| 483 | } |
| 484 | |
Timur Iskhakov | b58f418 | 2017-08-29 15:19:24 -0700 | [diff] [blame] | 485 | std::vector<const Reference<Type>*> Interface::getStrongReferences() const { |
Timur Iskhakov | 40731af | 2017-08-24 14:18:35 -0700 | [diff] [blame] | 486 | // Interface is a special case as a reference: |
| 487 | // its definiton must be completed for extension but |
| 488 | // not necessary for other references. |
Timur Iskhakov | 40731af | 2017-08-24 14:18:35 -0700 | [diff] [blame] | 489 | |
Timur Iskhakov | b58f418 | 2017-08-29 15:19:24 -0700 | [diff] [blame] | 490 | std::vector<const Reference<Type>*> ret; |
Timur Iskhakov | 82c048e | 2017-09-09 01:20:53 -0700 | [diff] [blame] | 491 | if (!isIBase()) { |
Timur Iskhakov | b58f418 | 2017-08-29 15:19:24 -0700 | [diff] [blame] | 492 | ret.push_back(&mSuperType); |
Timur Iskhakov | 40731af | 2017-08-24 14:18:35 -0700 | [diff] [blame] | 493 | } |
Timur Iskhakov | ff5e64a | 2017-09-11 14:56:18 -0700 | [diff] [blame] | 494 | |
| 495 | for (const auto* method : methods()) { |
| 496 | const auto& references = method->getStrongReferences(); |
| 497 | ret.insert(ret.end(), references.begin(), references.end()); |
| 498 | } |
| 499 | |
Timur Iskhakov | 40731af | 2017-08-24 14:18:35 -0700 | [diff] [blame] | 500 | return ret; |
| 501 | } |
| 502 | |
Timur Iskhakov | cec46c4 | 2017-08-09 00:22:02 -0700 | [diff] [blame] | 503 | status_t Interface::resolveInheritance() { |
| 504 | size_t serial = FIRST_CALL_TRANSACTION; |
| 505 | for (const auto* ancestor : superTypeChain()) { |
| 506 | serial += ancestor->mUserMethods.size(); |
| 507 | } |
| 508 | |
| 509 | for (Method* method : mUserMethods) { |
| 510 | if (serial > LAST_CALL_TRANSACTION) { |
| 511 | std::cerr << "ERROR: More than " << LAST_CALL_TRANSACTION |
| 512 | << " methods (including super and reserved) are not allowed at " << location() |
Steven Moreland | cbff561 | 2017-10-11 17:01:54 -0700 | [diff] [blame] | 513 | << std::endl; |
Timur Iskhakov | cec46c4 | 2017-08-09 00:22:02 -0700 | [diff] [blame] | 514 | return UNKNOWN_ERROR; |
| 515 | } |
| 516 | |
| 517 | method->setSerialId(serial); |
| 518 | serial++; |
| 519 | } |
| 520 | |
| 521 | return Scope::resolveInheritance(); |
| 522 | } |
| 523 | |
Timur Iskhakov | cec46c4 | 2017-08-09 00:22:02 -0700 | [diff] [blame] | 524 | status_t Interface::validate() const { |
| 525 | CHECK(isIBase() == mSuperType.isEmptyReference()); |
| 526 | |
Timur Iskhakov | 0344e61 | 2017-08-25 12:57:09 -0700 | [diff] [blame] | 527 | if (!isIBase() && !mSuperType->isInterface()) { |
Steven Moreland | cbff561 | 2017-10-11 17:01:54 -0700 | [diff] [blame] | 528 | std::cerr << "ERROR: You can only extend interfaces at " << mSuperType.location() |
| 529 | << std::endl; |
Timur Iskhakov | 0344e61 | 2017-08-25 12:57:09 -0700 | [diff] [blame] | 530 | return UNKNOWN_ERROR; |
| 531 | } |
| 532 | |
Timur Iskhakov | cec46c4 | 2017-08-09 00:22:02 -0700 | [diff] [blame] | 533 | status_t err = validateUniqueNames(); |
| 534 | if (err != OK) return err; |
| 535 | |
| 536 | return Scope::validate(); |
| 537 | } |
| 538 | |
| 539 | status_t Interface::validateUniqueNames() const { |
| 540 | std::unordered_map<std::string, const Interface*> registeredMethodNames; |
| 541 | for (auto const& tuple : allSuperMethodsFromRoot()) { |
| 542 | // No need to check super method uniqueness |
| 543 | registeredMethodNames[tuple.method()->name()] = tuple.interface(); |
| 544 | } |
| 545 | |
| 546 | for (const Method* method : mUserMethods) { |
| 547 | auto registered = registeredMethodNames.find(method->name()); |
| 548 | |
| 549 | if (registered != registeredMethodNames.end()) { |
| 550 | const Interface* definedInType = registered->second; |
| 551 | |
| 552 | if (definedInType == this) { |
| 553 | // Defined in this interface |
| 554 | std::cerr << "ERROR: Redefinition of method '" << method->name() << "'"; |
| 555 | } else if (definedInType->isIBase()) { |
| 556 | // Defined in IBase |
| 557 | std::cerr << "ERROR: Redefinition of reserved method '" << method->name() << "'"; |
| 558 | } else { |
| 559 | // Defined in super not IBase |
| 560 | std::cerr << "ERROR: Redefinition of method '" << method->name() |
Timur Iskhakov | 4c9c20b | 2017-09-13 21:16:59 -0700 | [diff] [blame] | 561 | << "' defined in interface '" << definedInType->fullName() << "'"; |
Timur Iskhakov | cec46c4 | 2017-08-09 00:22:02 -0700 | [diff] [blame] | 562 | } |
Steven Moreland | cbff561 | 2017-10-11 17:01:54 -0700 | [diff] [blame] | 563 | std::cerr << " at " << method->location() << std::endl; |
Timur Iskhakov | cec46c4 | 2017-08-09 00:22:02 -0700 | [diff] [blame] | 564 | return UNKNOWN_ERROR; |
| 565 | } |
| 566 | |
| 567 | registeredMethodNames[method->name()] = this; |
| 568 | } |
| 569 | |
| 570 | return OK; |
| 571 | } |
| 572 | |
Yifan Hong | ffa9139 | 2017-01-31 13:41:23 -0800 | [diff] [blame] | 573 | bool Interface::addAllReservedMethods() { |
| 574 | // use a sorted map to insert them in serial ID order. |
| 575 | std::map<int32_t, Method *> reservedMethodsById; |
| 576 | for (const auto &pair : gAllReservedMethods) { |
| 577 | Method *method = pair.second->copySignature(); |
Steven Moreland | 424a948 | 2017-02-13 19:20:40 -0800 | [diff] [blame] | 578 | bool fillSuccess = fillPingMethod(method) |
| 579 | || fillDescriptorChainMethod(method) |
Yifan Hong | ffa9139 | 2017-01-31 13:41:23 -0800 | [diff] [blame] | 580 | || fillGetDescriptorMethod(method) |
Yifan Hong | 30b5d1f | 2017-04-03 12:19:25 -0700 | [diff] [blame] | 581 | || fillHashChainMethod(method) |
Yifan Hong | ffa9139 | 2017-01-31 13:41:23 -0800 | [diff] [blame] | 582 | || fillSyspropsChangedMethod(method) |
| 583 | || fillLinkToDeathMethod(method) |
| 584 | || fillUnlinkToDeathMethod(method) |
Yifan Hong | cd2ae45 | 2017-01-31 14:33:40 -0800 | [diff] [blame] | 585 | || fillSetHALInstrumentationMethod(method) |
Andreas Huber | 37065d6 | 2017-02-07 14:36:54 -0800 | [diff] [blame] | 586 | || fillGetDebugInfoMethod(method) |
| 587 | || fillDebugMethod(method); |
| 588 | |
Yifan Hong | ffa9139 | 2017-01-31 13:41:23 -0800 | [diff] [blame] | 589 | if (!fillSuccess) { |
Steven Moreland | cbff561 | 2017-10-11 17:01:54 -0700 | [diff] [blame] | 590 | std::cerr << "ERROR: hidl-gen does not recognize a reserved method " << method->name() |
| 591 | << std::endl; |
Yifan Hong | ffa9139 | 2017-01-31 13:41:23 -0800 | [diff] [blame] | 592 | return false; |
| 593 | } |
| 594 | if (!reservedMethodsById.emplace(method->getSerialId(), method).second) { |
Steven Moreland | cbff561 | 2017-10-11 17:01:54 -0700 | [diff] [blame] | 595 | std::cerr << "ERROR: hidl-gen uses duplicated serial id for " << method->name() |
| 596 | << " and " << reservedMethodsById[method->getSerialId()]->name() |
| 597 | << ", serialId = " << method->getSerialId() << std::endl; |
Yifan Hong | ffa9139 | 2017-01-31 13:41:23 -0800 | [diff] [blame] | 598 | return false; |
| 599 | } |
| 600 | } |
| 601 | for (const auto &pair : reservedMethodsById) { |
| 602 | this->mReservedMethods.push_back(pair.second); |
| 603 | } |
| 604 | return true; |
| 605 | } |
Yifan Hong | 10fe0b5 | 2016-10-19 14:20:17 -0700 | [diff] [blame] | 606 | |
Timur Iskhakov | 505316c | 2017-08-05 03:38:59 +0000 | [diff] [blame] | 607 | const Interface* Interface::superType() const { |
Timur Iskhakov | 0344e61 | 2017-08-25 12:57:09 -0700 | [diff] [blame] | 608 | if (isIBase()) return nullptr; |
| 609 | if (!mSuperType->isInterface()) { |
| 610 | // This is actually an error |
| 611 | // that would be caught in validate |
| 612 | return nullptr; |
| 613 | } |
Timur Iskhakov | 24e605b | 2017-08-30 14:02:55 -0700 | [diff] [blame] | 614 | return static_cast<const Interface*>(mSuperType.get()); |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 615 | } |
| 616 | |
Yifan Hong | 10fe0b5 | 2016-10-19 14:20:17 -0700 | [diff] [blame] | 617 | std::vector<const Interface *> Interface::typeChain() const { |
| 618 | std::vector<const Interface *> v; |
| 619 | const Interface *iface = this; |
| 620 | while (iface != nullptr) { |
| 621 | v.push_back(iface); |
Timur Iskhakov | 505316c | 2017-08-05 03:38:59 +0000 | [diff] [blame] | 622 | iface = iface->superType(); |
Yifan Hong | 10fe0b5 | 2016-10-19 14:20:17 -0700 | [diff] [blame] | 623 | } |
| 624 | return v; |
| 625 | } |
| 626 | |
Yifan Hong | fe95aa2 | 2016-10-19 17:26:45 -0700 | [diff] [blame] | 627 | std::vector<const Interface *> Interface::superTypeChain() const { |
Timur Iskhakov | 505316c | 2017-08-05 03:38:59 +0000 | [diff] [blame] | 628 | return isIBase() ? std::vector<const Interface*>() : superType()->typeChain(); |
Yifan Hong | fe95aa2 | 2016-10-19 17:26:45 -0700 | [diff] [blame] | 629 | } |
| 630 | |
Martijn Coenen | b40ef02 | 2017-01-02 15:21:46 +0100 | [diff] [blame] | 631 | bool Interface::isElidableType() const { |
| 632 | return true; |
| 633 | } |
| 634 | |
Andreas Huber | a2723d2 | 2016-07-29 15:36:07 -0700 | [diff] [blame] | 635 | bool Interface::isInterface() const { |
| 636 | return true; |
| 637 | } |
| 638 | |
Andreas Huber | 295ad30 | 2016-08-16 11:35:00 -0700 | [diff] [blame] | 639 | bool Interface::isBinder() const { |
| 640 | return true; |
| 641 | } |
| 642 | |
Yifan Hong | 10fe0b5 | 2016-10-19 14:20:17 -0700 | [diff] [blame] | 643 | const std::vector<Method *> &Interface::userDefinedMethods() const { |
| 644 | return mUserMethods; |
| 645 | } |
| 646 | |
| 647 | const std::vector<Method *> &Interface::hidlReservedMethods() const { |
| 648 | return mReservedMethods; |
| 649 | } |
| 650 | |
| 651 | std::vector<Method *> Interface::methods() const { |
| 652 | std::vector<Method *> v(mUserMethods); |
| 653 | v.insert(v.end(), mReservedMethods.begin(), mReservedMethods.end()); |
| 654 | return v; |
| 655 | } |
| 656 | |
| 657 | std::vector<InterfaceAndMethod> Interface::allMethodsFromRoot() const { |
| 658 | std::vector<InterfaceAndMethod> v; |
| 659 | std::vector<const Interface *> chain = typeChain(); |
| 660 | for (auto it = chain.rbegin(); it != chain.rend(); ++it) { |
| 661 | const Interface *iface = *it; |
| 662 | for (Method *userMethod : iface->userDefinedMethods()) { |
| 663 | v.push_back(InterfaceAndMethod(iface, userMethod)); |
| 664 | } |
| 665 | } |
| 666 | for (Method *reservedMethod : hidlReservedMethods()) { |
Yifan Hong | c893404 | 2016-11-17 17:10:52 -0800 | [diff] [blame] | 667 | v.push_back(InterfaceAndMethod( |
| 668 | *chain.rbegin(), // IBase |
| 669 | reservedMethod)); |
Yifan Hong | 10fe0b5 | 2016-10-19 14:20:17 -0700 | [diff] [blame] | 670 | } |
| 671 | return v; |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 672 | } |
| 673 | |
Timur Iskhakov | f1b902d | 2017-08-13 20:14:31 -0700 | [diff] [blame] | 674 | std::vector<InterfaceAndMethod> Interface::allSuperMethodsFromRoot() const { |
| 675 | return isIBase() ? std::vector<InterfaceAndMethod>() : superType()->allMethodsFromRoot(); |
| 676 | } |
| 677 | |
Steven Moreland | 4078631 | 2016-08-16 10:29:40 -0700 | [diff] [blame] | 678 | std::string Interface::getBaseName() const { |
Jayant Chowdhary | 3f32c1f | 2016-09-15 16:53:56 -0700 | [diff] [blame] | 679 | return fqName().getInterfaceBaseName(); |
Steven Moreland | 4078631 | 2016-08-16 10:29:40 -0700 | [diff] [blame] | 680 | } |
| 681 | |
Steven Moreland | 9a6da7a | 2017-09-15 16:21:24 -0700 | [diff] [blame] | 682 | std::string Interface::getAdapterName() const { |
| 683 | return fqName().getInterfaceAdapterName(); |
| 684 | } |
| 685 | |
Yifan Hong | eefe4f2 | 2017-01-04 15:32:42 -0800 | [diff] [blame] | 686 | std::string Interface::getProxyName() const { |
| 687 | return fqName().getInterfaceProxyName(); |
| 688 | } |
| 689 | |
| 690 | std::string Interface::getStubName() const { |
| 691 | return fqName().getInterfaceStubName(); |
| 692 | } |
| 693 | |
| 694 | std::string Interface::getHwName() const { |
| 695 | return fqName().getInterfaceHwName(); |
| 696 | } |
| 697 | |
| 698 | std::string Interface::getPassthroughName() const { |
| 699 | return fqName().getInterfacePassthroughName(); |
| 700 | } |
| 701 | |
Yifan Hong | 51a6509 | 2017-01-04 15:41:44 -0800 | [diff] [blame] | 702 | FQName Interface::getProxyFqName() const { |
Yifan Hong | eefe4f2 | 2017-01-04 15:32:42 -0800 | [diff] [blame] | 703 | return fqName().getInterfaceProxyFqName(); |
Yifan Hong | 158655a | 2016-11-08 12:34:07 -0800 | [diff] [blame] | 704 | } |
| 705 | |
Yifan Hong | 51a6509 | 2017-01-04 15:41:44 -0800 | [diff] [blame] | 706 | FQName Interface::getStubFqName() const { |
Yifan Hong | eefe4f2 | 2017-01-04 15:32:42 -0800 | [diff] [blame] | 707 | return fqName().getInterfaceStubFqName(); |
Yifan Hong | 158655a | 2016-11-08 12:34:07 -0800 | [diff] [blame] | 708 | } |
| 709 | |
Yifan Hong | 51a6509 | 2017-01-04 15:41:44 -0800 | [diff] [blame] | 710 | FQName Interface::getPassthroughFqName() const { |
Yifan Hong | eefe4f2 | 2017-01-04 15:32:42 -0800 | [diff] [blame] | 711 | return fqName().getInterfacePassthroughFqName(); |
Yifan Hong | 158655a | 2016-11-08 12:34:07 -0800 | [diff] [blame] | 712 | } |
| 713 | |
Steven Moreland | 979e099 | 2016-09-07 09:18:08 -0700 | [diff] [blame] | 714 | std::string Interface::getCppType(StorageMode mode, |
Steven Moreland | 979e099 | 2016-09-07 09:18:08 -0700 | [diff] [blame] | 715 | bool specifyNamespaces) const { |
Steven Moreland | 979e099 | 2016-09-07 09:18:08 -0700 | [diff] [blame] | 716 | const std::string base = |
| 717 | std::string(specifyNamespaces ? "::android::" : "") |
| 718 | + "sp<" |
Steven Moreland | e30ee9b | 2017-05-09 13:31:01 -0700 | [diff] [blame] | 719 | + fullName() |
Steven Moreland | 979e099 | 2016-09-07 09:18:08 -0700 | [diff] [blame] | 720 | + ">"; |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 721 | |
| 722 | switch (mode) { |
| 723 | case StorageMode_Stack: |
| 724 | case StorageMode_Result: |
| 725 | return base; |
| 726 | |
| 727 | case StorageMode_Argument: |
| 728 | return "const " + base + "&"; |
| 729 | } |
| 730 | } |
| 731 | |
Yifan Hong | 4ed1347 | 2016-11-02 10:44:11 -0700 | [diff] [blame] | 732 | std::string Interface::getJavaType(bool /* forInitializer */) const { |
Andreas Huber | 2831d51 | 2016-08-15 09:33:47 -0700 | [diff] [blame] | 733 | return fullJavaName(); |
| 734 | } |
| 735 | |
Zhuoyao Zhang | a588b23 | 2016-11-10 14:37:35 -0800 | [diff] [blame] | 736 | std::string Interface::getVtsType() const { |
| 737 | if (StringHelper::EndsWith(localName(), "Callback")) { |
| 738 | return "TYPE_HIDL_CALLBACK"; |
| 739 | } else { |
| 740 | return "TYPE_HIDL_INTERFACE"; |
| 741 | } |
| 742 | } |
| 743 | |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 744 | void Interface::emitReaderWriter( |
| 745 | Formatter &out, |
| 746 | const std::string &name, |
| 747 | const std::string &parcelObj, |
| 748 | bool parcelObjIsPointer, |
| 749 | bool isReader, |
| 750 | ErrorMode mode) const { |
| 751 | const std::string parcelObjDeref = |
| 752 | parcelObj + (parcelObjIsPointer ? "->" : "."); |
| 753 | |
| 754 | if (isReader) { |
Andreas Huber | e7ff228 | 2016-08-16 13:50:03 -0700 | [diff] [blame] | 755 | out << "{\n"; |
| 756 | out.indent(); |
| 757 | |
Iliyan Malchev | 549e259 | 2016-08-10 08:59:12 -0700 | [diff] [blame] | 758 | const std::string binderName = "_hidl_" + name + "_binder"; |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 759 | |
Andreas Huber | 8a82ff7 | 2016-08-04 10:29:39 -0700 | [diff] [blame] | 760 | out << "::android::sp<::android::hardware::IBinder> " |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 761 | << binderName << ";\n"; |
| 762 | |
Iliyan Malchev | 549e259 | 2016-08-10 08:59:12 -0700 | [diff] [blame] | 763 | out << "_hidl_err = "; |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 764 | out << parcelObjDeref |
| 765 | << "readNullableStrongBinder(&" |
| 766 | << binderName |
| 767 | << ");\n"; |
| 768 | |
| 769 | handleError(out, mode); |
| 770 | |
| 771 | out << name |
| 772 | << " = " |
Martijn Coenen | a63e0ad | 2016-12-07 17:29:00 +0100 | [diff] [blame] | 773 | << "::android::hardware::fromBinder<" |
| 774 | << fqName().cppName() |
| 775 | << "," |
Yifan Hong | 51a6509 | 2017-01-04 15:41:44 -0800 | [diff] [blame] | 776 | << getProxyFqName().cppName() |
Martijn Coenen | a63e0ad | 2016-12-07 17:29:00 +0100 | [diff] [blame] | 777 | << "," |
Yifan Hong | 51a6509 | 2017-01-04 15:41:44 -0800 | [diff] [blame] | 778 | << getStubFqName().cppName() |
Martijn Coenen | a63e0ad | 2016-12-07 17:29:00 +0100 | [diff] [blame] | 779 | << ">(" |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 780 | << binderName |
| 781 | << ");\n"; |
Andreas Huber | e7ff228 | 2016-08-16 13:50:03 -0700 | [diff] [blame] | 782 | |
| 783 | out.unindent(); |
| 784 | out << "}\n\n"; |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 785 | } else { |
Martijn Coenen | e163823 | 2016-10-26 12:51:34 +0200 | [diff] [blame] | 786 | out << "if (" << name << " == nullptr) {\n"; |
| 787 | out.indent(); |
| 788 | out << "_hidl_err = "; |
| 789 | out << parcelObjDeref |
| 790 | << "writeStrongBinder(nullptr);\n"; |
| 791 | out.unindent(); |
| 792 | out << "} else {\n"; |
| 793 | out.indent(); |
Yifan Hong | 158655a | 2016-11-08 12:34:07 -0800 | [diff] [blame] | 794 | out << "::android::sp<::android::hardware::IBinder> _hidl_binder = " |
| 795 | << "::android::hardware::toBinder<\n"; |
Yifan Hong | 33223ca | 2016-12-13 15:07:35 -0800 | [diff] [blame] | 796 | out.indent(2, [&] { |
Martijn Coenen | a63e0ad | 2016-12-07 17:29:00 +0100 | [diff] [blame] | 797 | out << fqName().cppName() |
Yifan Hong | 158655a | 2016-11-08 12:34:07 -0800 | [diff] [blame] | 798 | << ">(" |
| 799 | << name |
| 800 | << ");\n"; |
| 801 | }); |
| 802 | out << "if (_hidl_binder.get() != nullptr) {\n"; |
Yifan Hong | 33223ca | 2016-12-13 15:07:35 -0800 | [diff] [blame] | 803 | out.indent([&] { |
Yifan Hong | 158655a | 2016-11-08 12:34:07 -0800 | [diff] [blame] | 804 | out << "_hidl_err = " |
| 805 | << parcelObjDeref |
| 806 | << "writeStrongBinder(_hidl_binder);\n"; |
| 807 | }); |
| 808 | out << "} else {\n"; |
Yifan Hong | 33223ca | 2016-12-13 15:07:35 -0800 | [diff] [blame] | 809 | out.indent([&] { |
Yifan Hong | 158655a | 2016-11-08 12:34:07 -0800 | [diff] [blame] | 810 | out << "_hidl_err = ::android::UNKNOWN_ERROR;\n"; |
| 811 | }); |
| 812 | out << "}\n"; |
Martijn Coenen | e163823 | 2016-10-26 12:51:34 +0200 | [diff] [blame] | 813 | out.unindent(); |
| 814 | out << "}\n"; |
Steven Moreland | 4078631 | 2016-08-16 10:29:40 -0700 | [diff] [blame] | 815 | |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 816 | handleError(out, mode); |
| 817 | } |
| 818 | } |
| 819 | |
Yifan Hong | f5cc2f7 | 2017-01-04 18:02:34 -0800 | [diff] [blame] | 820 | status_t Interface::emitGlobalTypeDeclarations(Formatter &out) const { |
| 821 | status_t status = Scope::emitGlobalTypeDeclarations(out); |
| 822 | if (status != OK) { |
| 823 | return status; |
| 824 | } |
Steven Moreland | bf71421 | 2017-10-27 18:29:01 -0700 | [diff] [blame] | 825 | |
| 826 | // TODO(b/65200821): remove these ifndefs |
| 827 | out << "#ifdef REALLY_IS_HIDL_INTERNAL_LIB" << gCurrentCompileName << "\n"; |
Steven Moreland | 3d98bc4 | 2017-06-23 21:36:41 +0000 | [diff] [blame] | 828 | out << "std::string toString(" |
Yifan Hong | f5cc2f7 | 2017-01-04 18:02:34 -0800 | [diff] [blame] | 829 | << getCppArgumentType() |
Steven Moreland | 3d98bc4 | 2017-06-23 21:36:41 +0000 | [diff] [blame] | 830 | << ");\n"; |
Steven Moreland | bf71421 | 2017-10-27 18:29:01 -0700 | [diff] [blame] | 831 | out << "#else\n"; |
| 832 | out << "static inline std::string toString(" << getCppArgumentType() << " o) "; |
| 833 | |
| 834 | out.block([&] { |
| 835 | out << "std::string os = \"[class or subclass of \";\n" |
| 836 | << "os += " << fullName() << "::descriptor;\n" |
| 837 | << "os += \"]\";\n" |
| 838 | << "os += o->isRemote() ? \"@remote\" : \"@local\";\n" |
| 839 | << "return os;\n"; |
| 840 | }).endl().endl(); |
| 841 | out << "#endif // REALLY_IS_HIDL_INTERNAL_LIB\n"; |
| 842 | |
Yifan Hong | f5cc2f7 | 2017-01-04 18:02:34 -0800 | [diff] [blame] | 843 | return OK; |
| 844 | } |
| 845 | |
Chih-Hung Hsieh | 8c90cc5 | 2017-08-03 14:51:13 -0700 | [diff] [blame] | 846 | status_t Interface::emitTypeDefinitions(Formatter& out, const std::string& prefix) const { |
Yifan Hong | f5cc2f7 | 2017-01-04 18:02:34 -0800 | [diff] [blame] | 847 | std::string space = prefix.empty() ? "" : (prefix + "::"); |
| 848 | status_t err = Scope::emitTypeDefinitions(out, space + localName()); |
| 849 | if (err != OK) { |
| 850 | return err; |
| 851 | } |
| 852 | |
Steven Moreland | bf71421 | 2017-10-27 18:29:01 -0700 | [diff] [blame] | 853 | // TODO(b/65200821): remove toString from .cpp once all prebuilts are rebuilt |
Steven Moreland | 3d98bc4 | 2017-06-23 21:36:41 +0000 | [diff] [blame] | 854 | out << "std::string toString(" |
| 855 | << getCppArgumentType() |
| 856 | << " o) "; |
| 857 | |
| 858 | out.block([&] { |
| 859 | out << "std::string os = \"[class or subclass of \";\n" |
| 860 | << "os += " << fullName() << "::descriptor;\n" |
| 861 | << "os += \"]\";\n" |
| 862 | << "os += o->isRemote() ? \"@remote\" : \"@local\";\n" |
| 863 | << "return os;\n"; |
| 864 | }).endl().endl(); |
| 865 | |
Yifan Hong | f5cc2f7 | 2017-01-04 18:02:34 -0800 | [diff] [blame] | 866 | return OK; |
| 867 | } |
| 868 | |
Andreas Huber | 2831d51 | 2016-08-15 09:33:47 -0700 | [diff] [blame] | 869 | void Interface::emitJavaReaderWriter( |
| 870 | Formatter &out, |
| 871 | const std::string &parcelObj, |
| 872 | const std::string &argName, |
| 873 | bool isReader) const { |
| 874 | if (isReader) { |
| 875 | out << fullJavaName() |
| 876 | << ".asInterface(" |
| 877 | << parcelObj |
| 878 | << ".readStrongBinder());\n"; |
| 879 | } else { |
| 880 | out << parcelObj |
| 881 | << ".writeStrongBinder(" |
| 882 | << argName |
| 883 | << " == null ? null : " |
| 884 | << argName |
| 885 | << ".asBinder());\n"; |
| 886 | } |
| 887 | } |
| 888 | |
Zhuoyao Zhang | 864c771 | 2016-08-16 15:35:28 -0700 | [diff] [blame] | 889 | status_t Interface::emitVtsAttributeDeclaration(Formatter &out) const { |
| 890 | for (const auto &type : getSubTypes()) { |
Zhuoyao Zhang | c5ea9f5 | 2016-10-06 15:05:39 -0700 | [diff] [blame] | 891 | // Skip for TypeDef as it is just an alias of a defined type. |
| 892 | if (type->isTypeDef()) { |
| 893 | continue; |
| 894 | } |
Zhuoyao Zhang | 864c771 | 2016-08-16 15:35:28 -0700 | [diff] [blame] | 895 | out << "attribute: {\n"; |
| 896 | out.indent(); |
| 897 | status_t status = type->emitVtsTypeDeclarations(out); |
| 898 | if (status != OK) { |
| 899 | return status; |
| 900 | } |
| 901 | out.unindent(); |
| 902 | out << "}\n\n"; |
| 903 | } |
| 904 | return OK; |
| 905 | } |
| 906 | |
| 907 | status_t Interface::emitVtsMethodDeclaration(Formatter &out) const { |
Yifan Hong | 10fe0b5 | 2016-10-19 14:20:17 -0700 | [diff] [blame] | 908 | for (const auto &method : methods()) { |
Steven Moreland | cea2478 | 2016-11-07 11:40:48 -0800 | [diff] [blame] | 909 | if (method->isHidlReserved()) { |
| 910 | continue; |
| 911 | } |
| 912 | |
Zhuoyao Zhang | 864c771 | 2016-08-16 15:35:28 -0700 | [diff] [blame] | 913 | out << "api: {\n"; |
| 914 | out.indent(); |
| 915 | out << "name: \"" << method->name() << "\"\n"; |
| 916 | // Generate declaration for each return value. |
| 917 | for (const auto &result : method->results()) { |
| 918 | out << "return_type_hidl: {\n"; |
| 919 | out.indent(); |
| 920 | status_t status = result->type().emitVtsAttributeType(out); |
| 921 | if (status != OK) { |
| 922 | return status; |
| 923 | } |
| 924 | out.unindent(); |
| 925 | out << "}\n"; |
| 926 | } |
| 927 | // Generate declaration for each input argument |
| 928 | for (const auto &arg : method->args()) { |
| 929 | out << "arg: {\n"; |
| 930 | out.indent(); |
| 931 | status_t status = arg->type().emitVtsAttributeType(out); |
| 932 | if (status != OK) { |
| 933 | return status; |
| 934 | } |
| 935 | out.unindent(); |
| 936 | out << "}\n"; |
| 937 | } |
| 938 | // Generate declaration for each annotation. |
Steven Moreland | d537ab0 | 2016-09-12 10:32:01 -0700 | [diff] [blame] | 939 | for (const auto &annotation : method->annotations()) { |
Zhuoyao Zhang | 864c771 | 2016-08-16 15:35:28 -0700 | [diff] [blame] | 940 | out << "callflow: {\n"; |
| 941 | out.indent(); |
Steven Moreland | d537ab0 | 2016-09-12 10:32:01 -0700 | [diff] [blame] | 942 | std::string name = annotation->name(); |
Zhuoyao Zhang | 864c771 | 2016-08-16 15:35:28 -0700 | [diff] [blame] | 943 | if (name == "entry") { |
| 944 | out << "entry: true\n"; |
| 945 | } else if (name == "exit") { |
| 946 | out << "exit: true\n"; |
| 947 | } else if (name == "callflow") { |
Steven Moreland | d537ab0 | 2016-09-12 10:32:01 -0700 | [diff] [blame] | 948 | const AnnotationParam *param = |
| 949 | annotation->getParam("next"); |
| 950 | if (param != nullptr) { |
Timur Iskhakov | 7a85dc2 | 2017-08-10 19:06:41 -0700 | [diff] [blame] | 951 | for (const auto& value : param->getValues()) { |
Steven Moreland | d537ab0 | 2016-09-12 10:32:01 -0700 | [diff] [blame] | 952 | out << "next: " << value << "\n"; |
| 953 | } |
Zhuoyao Zhang | 864c771 | 2016-08-16 15:35:28 -0700 | [diff] [blame] | 954 | } |
| 955 | } else { |
Steven Moreland | cbff561 | 2017-10-11 17:01:54 -0700 | [diff] [blame] | 956 | std::cerr << "ERROR: Unrecognized annotation '" << name |
| 957 | << "' for method: " << method->name() |
Keun Soo Yim | a5a57e9 | 2017-02-04 11:32:06 -0800 | [diff] [blame] | 958 | << ". A VTS annotation should be one of: " |
Steven Moreland | cbff561 | 2017-10-11 17:01:54 -0700 | [diff] [blame] | 959 | << "entry, exit, callflow." << std::endl; |
| 960 | return UNKNOWN_ERROR; |
Zhuoyao Zhang | 864c771 | 2016-08-16 15:35:28 -0700 | [diff] [blame] | 961 | } |
| 962 | out.unindent(); |
| 963 | out << "}\n"; |
| 964 | } |
| 965 | out.unindent(); |
| 966 | out << "}\n\n"; |
| 967 | } |
| 968 | return OK; |
| 969 | } |
| 970 | |
| 971 | status_t Interface::emitVtsAttributeType(Formatter &out) const { |
Zhuoyao Zhang | a588b23 | 2016-11-10 14:37:35 -0800 | [diff] [blame] | 972 | out << "type: " << getVtsType() << "\n" |
Zhuoyao Zhang | 5158db4 | 2016-08-10 10:25:20 -0700 | [diff] [blame] | 973 | << "predefined_type: \"" |
Zhuoyao Zhang | c4e1060 | 2017-01-27 16:48:05 -0800 | [diff] [blame] | 974 | << fullName() |
| 975 | << "\"\n"; |
Zhuoyao Zhang | 5158db4 | 2016-08-10 10:25:20 -0700 | [diff] [blame] | 976 | return OK; |
| 977 | } |
| 978 | |
Steven Moreland | 69e7c70 | 2016-09-09 11:16:32 -0700 | [diff] [blame] | 979 | bool Interface::hasOnewayMethods() const { |
Yifan Hong | 10fe0b5 | 2016-10-19 14:20:17 -0700 | [diff] [blame] | 980 | for (auto const &method : methods()) { |
Steven Moreland | 69e7c70 | 2016-09-09 11:16:32 -0700 | [diff] [blame] | 981 | if (method->isOneway()) { |
| 982 | return true; |
| 983 | } |
| 984 | } |
| 985 | |
| 986 | const Interface* superClass = superType(); |
| 987 | |
| 988 | if (superClass != nullptr) { |
| 989 | return superClass->hasOnewayMethods(); |
| 990 | } |
| 991 | |
| 992 | return false; |
| 993 | } |
| 994 | |
Timur Iskhakov | 5dc72fe | 2017-09-07 23:13:44 -0700 | [diff] [blame] | 995 | bool Interface::deepIsJavaCompatible(std::unordered_set<const Type*>* visited) const { |
| 996 | if (superType() != nullptr && !superType()->isJavaCompatible(visited)) { |
Andreas Huber | 0fa9e39 | 2016-08-31 09:05:44 -0700 | [diff] [blame] | 997 | return false; |
| 998 | } |
| 999 | |
Timur Iskhakov | 5dc72fe | 2017-09-07 23:13:44 -0700 | [diff] [blame] | 1000 | for (const auto* method : methods()) { |
| 1001 | if (!method->deepIsJavaCompatible(visited)) { |
Andreas Huber | 70a59e1 | 2016-08-16 12:57:01 -0700 | [diff] [blame] | 1002 | return false; |
| 1003 | } |
| 1004 | } |
| 1005 | |
Timur Iskhakov | 5dc72fe | 2017-09-07 23:13:44 -0700 | [diff] [blame] | 1006 | return Scope::isJavaCompatible(visited); |
Andreas Huber | 70a59e1 | 2016-08-16 12:57:01 -0700 | [diff] [blame] | 1007 | } |
| 1008 | |
Timur Iskhakov | ff5e64a | 2017-09-11 14:56:18 -0700 | [diff] [blame] | 1009 | bool Interface::isNeverStrongReference() const { |
| 1010 | return true; |
| 1011 | } |
| 1012 | |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 1013 | } // namespace android |
| 1014 | |