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" |
Martijn Coenen | 115d428 | 2016-12-19 05:14:04 +0100 | [diff] [blame] | 20 | #include "DeathRecipientType.h" |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 21 | #include "Method.h" |
Martijn Coenen | 115d428 | 2016-12-19 05:14:04 +0100 | [diff] [blame] | 22 | #include "ScalarType.h" |
Yifan Hong | 10fe0b5 | 2016-10-19 14:20:17 -0700 | [diff] [blame] | 23 | #include "StringType.h" |
| 24 | #include "VectorType.h" |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 25 | |
Steven Moreland | 14ee674 | 2016-10-18 12:58:28 -0700 | [diff] [blame] | 26 | #include <android-base/logging.h> |
Iliyan Malchev | a72e0d2 | 2016-09-09 11:03:08 -0700 | [diff] [blame] | 27 | #include <hidl-util/Formatter.h> |
Yifan Hong | 10fe0b5 | 2016-10-19 14:20:17 -0700 | [diff] [blame] | 28 | #include <hidl-util/StringHelper.h> |
Zhuoyao Zhang | 864c771 | 2016-08-16 15:35:28 -0700 | [diff] [blame] | 29 | #include <iostream> |
Yifan Hong | 10fe0b5 | 2016-10-19 14:20:17 -0700 | [diff] [blame] | 30 | #include <sstream> |
Zhuoyao Zhang | 864c771 | 2016-08-16 15:35:28 -0700 | [diff] [blame] | 31 | |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 32 | namespace android { |
| 33 | |
Yifan Hong | 10fe0b5 | 2016-10-19 14:20:17 -0700 | [diff] [blame] | 34 | /* It is very important that these values NEVER change. These values |
| 35 | * must remain unchanged over the lifetime of android. This is |
| 36 | * because the framework on a device will be updated independently of |
| 37 | * the hals on a device. If the hals are compiled with one set of |
| 38 | * transaction values, and the framework with another, then the |
| 39 | * interface between them will be destroyed, and the device will not |
| 40 | * work. |
| 41 | */ |
| 42 | enum { |
| 43 | // These values are defined in hardware::IBinder. |
| 44 | /////////////////// User defined transactions |
| 45 | FIRST_CALL_TRANSACTION = 0x00000001, |
| 46 | LAST_CALL_TRANSACTION = 0x00efffff, |
| 47 | /////////////////// HIDL reserved |
| 48 | FIRST_HIDL_TRANSACTION = 0x00f00000, |
| 49 | HIDL_DESCRIPTOR_CHAIN_TRANSACTION = FIRST_HIDL_TRANSACTION, |
Yifan Hong | c75fd47 | 2017-01-11 12:37:31 -0800 | [diff] [blame] | 50 | HIDL_GET_DESCRIPTOR_TRANSACTION, |
Martijn Coenen | af712c0 | 2016-11-16 15:26:27 +0100 | [diff] [blame] | 51 | HIDL_SYSPROPS_CHANGED_TRANSACTION, |
Martijn Coenen | 115d428 | 2016-12-19 05:14:04 +0100 | [diff] [blame] | 52 | HIDL_LINK_TO_DEATH_TRANSACTION, |
| 53 | HIDL_UNLINK_TO_DEATH_TRANSACTION, |
Zhuoyao Zhang | dd85c5c | 2017-01-03 17:30:24 -0800 | [diff] [blame] | 54 | HIDL_SET_HAL_INSTRUMENTATION_TRANSACTION, |
Yifan Hong | 10fe0b5 | 2016-10-19 14:20:17 -0700 | [diff] [blame] | 55 | LAST_HIDL_TRANSACTION = 0x00ffffff, |
| 56 | }; |
| 57 | |
Yifan Hong | a4b53d0 | 2016-10-31 17:29:10 -0700 | [diff] [blame] | 58 | Interface::Interface(const char *localName, const Location &location, Interface *super) |
| 59 | : Scope(localName, location), |
Andreas Huber | 9ed827c | 2016-08-22 12:31:13 -0700 | [diff] [blame] | 60 | mSuperType(super), |
Andreas Huber | ea081b3 | 2016-08-17 15:57:47 -0700 | [diff] [blame] | 61 | mIsJavaCompatibleInProgress(false) { |
Martijn Coenen | af712c0 | 2016-11-16 15:26:27 +0100 | [diff] [blame] | 62 | } |
| 63 | |
Steven Moreland | 30bb6a8 | 2016-11-30 09:18:34 -0800 | [diff] [blame] | 64 | std::string Interface::typeName() const { |
| 65 | return "interface " + localName(); |
| 66 | } |
| 67 | |
Yifan Hong | ffa9139 | 2017-01-31 13:41:23 -0800 | [diff] [blame^] | 68 | bool Interface::fillLinkToDeathMethod(Method *method) const { |
| 69 | if (method->name() != "linkToDeath") { |
| 70 | return false; |
| 71 | } |
Martijn Coenen | 115d428 | 2016-12-19 05:14:04 +0100 | [diff] [blame] | 72 | |
Yifan Hong | ffa9139 | 2017-01-31 13:41:23 -0800 | [diff] [blame^] | 73 | method->fillImplementation( |
Martijn Coenen | 115d428 | 2016-12-19 05:14:04 +0100 | [diff] [blame] | 74 | HIDL_LINK_TO_DEATH_TRANSACTION, |
| 75 | { |
| 76 | {IMPL_HEADER, |
| 77 | [](auto &out) { |
| 78 | out << "(void)cookie;\n" |
| 79 | << "return (recipient != nullptr);\n"; |
| 80 | } |
| 81 | }, |
| 82 | {IMPL_PROXY, |
| 83 | [](auto &out) { |
Martijn Coenen | fa55d6e | 2016-12-20 06:08:31 +0100 | [diff] [blame] | 84 | out << "::android::hardware::ProcessState::self()->startThreadPool();\n"; |
Martijn Coenen | 115d428 | 2016-12-19 05:14:04 +0100 | [diff] [blame] | 85 | out << "::android::hardware::hidl_binder_death_recipient *binder_recipient" |
| 86 | << " = new ::android::hardware::hidl_binder_death_recipient(recipient, cookie, this);\n" |
| 87 | << "std::unique_lock<std::mutex> lock(_hidl_mMutex);\n" |
| 88 | << "_hidl_mDeathRecipients.push_back(binder_recipient);\n" |
| 89 | << "return (remote()->linkToDeath(binder_recipient)" |
| 90 | << " == ::android::OK);\n"; |
| 91 | } |
| 92 | }, |
Martijn Coenen | 8d12b50 | 2016-12-27 14:30:27 +0100 | [diff] [blame] | 93 | {IMPL_STUB, nullptr} |
Martijn Coenen | 115d428 | 2016-12-19 05:14:04 +0100 | [diff] [blame] | 94 | }, /*cppImpl*/ |
| 95 | { |
| 96 | {IMPL_HEADER, |
| 97 | [this](auto &out) { |
| 98 | out << "return true;"; |
| 99 | } |
| 100 | }, |
| 101 | {IMPL_PROXY, |
| 102 | [this](auto &out) { |
Martijn Coenen | 8d12b50 | 2016-12-27 14:30:27 +0100 | [diff] [blame] | 103 | out << "return mRemote.linkToDeath(recipient, cookie);\n"; |
Martijn Coenen | 115d428 | 2016-12-19 05:14:04 +0100 | [diff] [blame] | 104 | } |
| 105 | }, |
Martijn Coenen | 8d12b50 | 2016-12-27 14:30:27 +0100 | [diff] [blame] | 106 | {IMPL_STUB, nullptr} |
Martijn Coenen | 115d428 | 2016-12-19 05:14:04 +0100 | [diff] [blame] | 107 | } /*javaImpl*/ |
| 108 | ); |
Yifan Hong | ffa9139 | 2017-01-31 13:41:23 -0800 | [diff] [blame^] | 109 | return true; |
Martijn Coenen | 115d428 | 2016-12-19 05:14:04 +0100 | [diff] [blame] | 110 | } |
| 111 | |
Yifan Hong | ffa9139 | 2017-01-31 13:41:23 -0800 | [diff] [blame^] | 112 | bool Interface::fillUnlinkToDeathMethod(Method *method) const { |
| 113 | if (method->name() != "unlinkToDeath") { |
| 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_UNLINK_TO_DEATH_TRANSACTION, |
| 119 | { |
| 120 | {IMPL_HEADER, |
| 121 | [](auto &out) { |
| 122 | out << "return (recipient != nullptr);\n"; |
| 123 | } |
| 124 | }, |
| 125 | {IMPL_PROXY, |
| 126 | [](auto &out) { |
| 127 | out << "std::unique_lock<std::mutex> lock(_hidl_mMutex);\n" |
| 128 | << "for (auto it = _hidl_mDeathRecipients.begin();" |
| 129 | << "it != _hidl_mDeathRecipients.end();" |
| 130 | << "++it) {\n"; |
| 131 | out.indent([&] { |
| 132 | out.sIf("(*it)->getRecipient() == recipient", [&] { |
| 133 | out << "::android::status_t status = remote()->unlinkToDeath(*it);\n" |
| 134 | << "_hidl_mDeathRecipients.erase(it);\n" |
| 135 | << "return status == ::android::OK;\n"; |
| 136 | }); |
| 137 | }); |
| 138 | out << "}\n"; |
| 139 | out << "return false;\n"; |
| 140 | } |
| 141 | }, |
Martijn Coenen | 8d12b50 | 2016-12-27 14:30:27 +0100 | [diff] [blame] | 142 | {IMPL_STUB, nullptr /* don't generate code */} |
Martijn Coenen | 115d428 | 2016-12-19 05:14:04 +0100 | [diff] [blame] | 143 | }, /*cppImpl*/ |
| 144 | { |
| 145 | {IMPL_HEADER, |
| 146 | [this](auto &out) { |
Martijn Coenen | 8d12b50 | 2016-12-27 14:30:27 +0100 | [diff] [blame] | 147 | out << "return true;\n"; |
Martijn Coenen | 115d428 | 2016-12-19 05:14:04 +0100 | [diff] [blame] | 148 | } |
| 149 | }, |
| 150 | {IMPL_PROXY, |
| 151 | [this](auto &out) { |
Martijn Coenen | 8d12b50 | 2016-12-27 14:30:27 +0100 | [diff] [blame] | 152 | out << "return mRemote.unlinkToDeath(recipient);\n"; |
Martijn Coenen | 115d428 | 2016-12-19 05:14:04 +0100 | [diff] [blame] | 153 | } |
| 154 | }, |
Martijn Coenen | 8d12b50 | 2016-12-27 14:30:27 +0100 | [diff] [blame] | 155 | {IMPL_STUB, nullptr /* don't generate code */} |
Martijn Coenen | 115d428 | 2016-12-19 05:14:04 +0100 | [diff] [blame] | 156 | } /*javaImpl*/ |
| 157 | ); |
Yifan Hong | ffa9139 | 2017-01-31 13:41:23 -0800 | [diff] [blame^] | 158 | return true; |
Martijn Coenen | 115d428 | 2016-12-19 05:14:04 +0100 | [diff] [blame] | 159 | } |
Yifan Hong | ffa9139 | 2017-01-31 13:41:23 -0800 | [diff] [blame^] | 160 | bool Interface::fillSyspropsChangedMethod(Method *method) const { |
| 161 | if (method->name() != "notifySyspropsChanged") { |
| 162 | return false; |
| 163 | } |
| 164 | |
| 165 | method->fillImplementation( |
Martijn Coenen | af712c0 | 2016-11-16 15:26:27 +0100 | [diff] [blame] | 166 | HIDL_SYSPROPS_CHANGED_TRANSACTION, |
Martijn Coenen | 115d428 | 2016-12-19 05:14:04 +0100 | [diff] [blame] | 167 | { { IMPL_HEADER, [this](auto &out) { |
Martijn Coenen | af712c0 | 2016-11-16 15:26:27 +0100 | [diff] [blame] | 168 | out << "::android::report_sysprop_change();\n"; |
| 169 | out << "return ::android::hardware::Void();"; |
Martijn Coenen | 115d428 | 2016-12-19 05:14:04 +0100 | [diff] [blame] | 170 | } } }, /*cppImpl */ |
| 171 | { { IMPL_HEADER, [](auto &out) { /* javaImpl */ |
Martijn Coenen | af712c0 | 2016-11-16 15:26:27 +0100 | [diff] [blame] | 172 | out << "android.os.SystemProperties.reportSyspropChanged();"; |
Martijn Coenen | 115d428 | 2016-12-19 05:14:04 +0100 | [diff] [blame] | 173 | } } } /*javaImpl */ |
Martijn Coenen | af712c0 | 2016-11-16 15:26:27 +0100 | [diff] [blame] | 174 | ); |
Yifan Hong | ffa9139 | 2017-01-31 13:41:23 -0800 | [diff] [blame^] | 175 | return true; |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 176 | } |
| 177 | |
Yifan Hong | ffa9139 | 2017-01-31 13:41:23 -0800 | [diff] [blame^] | 178 | bool Interface::fillSetHALInstrumentationMethod(Method *method) const { |
| 179 | if (method->name() != "setHALInstrumentation") { |
| 180 | return false; |
| 181 | } |
| 182 | |
| 183 | method->fillImplementation( |
Zhuoyao Zhang | dd85c5c | 2017-01-03 17:30:24 -0800 | [diff] [blame] | 184 | HIDL_SET_HAL_INSTRUMENTATION_TRANSACTION, |
| 185 | { |
| 186 | {IMPL_HEADER, |
| 187 | [this](auto &out) { |
| 188 | // do nothing for base class. |
| 189 | out << "return ::android::hardware::Void();\n"; |
| 190 | } |
| 191 | }, |
Zhuoyao Zhang | dd85c5c | 2017-01-03 17:30:24 -0800 | [diff] [blame] | 192 | {IMPL_STUB, |
| 193 | [](auto &out) { |
| 194 | out << "configureInstrumentation();\n"; |
| 195 | } |
| 196 | }, |
| 197 | {IMPL_PASSTHROUGH, |
| 198 | [](auto &out) { |
| 199 | out << "configureInstrumentation();\n"; |
| 200 | out << "return ::android::hardware::Void();\n"; |
| 201 | } |
| 202 | }, |
| 203 | }, /*cppImpl */ |
| 204 | { { IMPL_HEADER, [](auto & /*out*/) { /* javaImpl */ |
| 205 | // Not support for Java Impl for now. |
| 206 | } } } /*javaImpl */ |
| 207 | ); |
Yifan Hong | ffa9139 | 2017-01-31 13:41:23 -0800 | [diff] [blame^] | 208 | return true; |
Zhuoyao Zhang | dd85c5c | 2017-01-03 17:30:24 -0800 | [diff] [blame] | 209 | } |
| 210 | |
Yifan Hong | ffa9139 | 2017-01-31 13:41:23 -0800 | [diff] [blame^] | 211 | bool Interface::fillDescriptorChainMethod(Method *method) const { |
| 212 | if (method->name() != "interfaceChain") { |
| 213 | return false; |
| 214 | } |
Yifan Hong | 10fe0b5 | 2016-10-19 14:20:17 -0700 | [diff] [blame] | 215 | |
Yifan Hong | ffa9139 | 2017-01-31 13:41:23 -0800 | [diff] [blame^] | 216 | method->fillImplementation( |
Yifan Hong | 10fe0b5 | 2016-10-19 14:20:17 -0700 | [diff] [blame] | 217 | HIDL_DESCRIPTOR_CHAIN_TRANSACTION, |
Martijn Coenen | 115d428 | 2016-12-19 05:14:04 +0100 | [diff] [blame] | 218 | { { IMPL_HEADER, [this](auto &out) { |
Yifan Hong | 10fe0b5 | 2016-10-19 14:20:17 -0700 | [diff] [blame] | 219 | std::vector<const Interface *> chain = typeChain(); |
Yifan Hong | 0393512 | 2016-12-19 11:10:40 -0800 | [diff] [blame] | 220 | out << "_hidl_cb("; |
| 221 | out.block([&] { |
| 222 | for (const Interface *iface : chain) { |
| 223 | out << iface->fullName() << "::descriptor,\n"; |
| 224 | } |
| 225 | }); |
| 226 | out << ");\n"; |
Yifan Hong | 10fe0b5 | 2016-10-19 14:20:17 -0700 | [diff] [blame] | 227 | out << "return ::android::hardware::Void();"; |
Martijn Coenen | 115d428 | 2016-12-19 05:14:04 +0100 | [diff] [blame] | 228 | } } }, /* cppImpl */ |
| 229 | { { IMPL_HEADER, [this](auto &out) { |
Yifan Hong | 10fe0b5 | 2016-10-19 14:20:17 -0700 | [diff] [blame] | 230 | std::vector<const Interface *> chain = typeChain(); |
Yifan Hong | 1af7353 | 2016-11-09 14:32:58 -0800 | [diff] [blame] | 231 | out << "return new java.util.ArrayList<String>(java.util.Arrays.asList(\n"; |
Yifan Hong | 10fe0b5 | 2016-10-19 14:20:17 -0700 | [diff] [blame] | 232 | out.indent(); out.indent(); |
| 233 | for (size_t i = 0; i < chain.size(); ++i) { |
| 234 | if (i != 0) |
| 235 | out << ",\n"; |
Steven Moreland | d39133b | 2016-11-11 12:30:08 -0800 | [diff] [blame] | 236 | out << chain[i]->fullJavaName() << ".kInterfaceName"; |
Yifan Hong | 10fe0b5 | 2016-10-19 14:20:17 -0700 | [diff] [blame] | 237 | } |
| 238 | out << "));"; |
| 239 | out.unindent(); out.unindent(); |
Yifan Hong | ffa9139 | 2017-01-31 13:41:23 -0800 | [diff] [blame^] | 240 | } } } /* javaImpl */ |
Martijn Coenen | 115d428 | 2016-12-19 05:14:04 +0100 | [diff] [blame] | 241 | ); |
Yifan Hong | ffa9139 | 2017-01-31 13:41:23 -0800 | [diff] [blame^] | 242 | return true; |
Yifan Hong | 10fe0b5 | 2016-10-19 14:20:17 -0700 | [diff] [blame] | 243 | } |
| 244 | |
Yifan Hong | ffa9139 | 2017-01-31 13:41:23 -0800 | [diff] [blame^] | 245 | bool Interface::fillGetDescriptorMethod(Method *method) const { |
| 246 | if (method->name() != "interfaceDescriptor") { |
| 247 | return false; |
| 248 | } |
Yifan Hong | c75fd47 | 2017-01-11 12:37:31 -0800 | [diff] [blame] | 249 | |
Yifan Hong | ffa9139 | 2017-01-31 13:41:23 -0800 | [diff] [blame^] | 250 | method->fillImplementation( |
Yifan Hong | c75fd47 | 2017-01-11 12:37:31 -0800 | [diff] [blame] | 251 | HIDL_GET_DESCRIPTOR_TRANSACTION, |
| 252 | { { IMPL_HEADER, [this](auto &out) { |
| 253 | out << "_hidl_cb(" |
| 254 | << fullName() |
| 255 | << "::descriptor);\n" |
| 256 | << "return ::android::hardware::Void();"; |
| 257 | } } }, /* cppImpl */ |
| 258 | { { IMPL_HEADER, [this](auto &out) { |
| 259 | out << "return " |
| 260 | << fullJavaName() |
| 261 | << ".kInterfaceName;\n"; |
Yifan Hong | ffa9139 | 2017-01-31 13:41:23 -0800 | [diff] [blame^] | 262 | } } } /* javaImpl */ |
Yifan Hong | c75fd47 | 2017-01-11 12:37:31 -0800 | [diff] [blame] | 263 | ); |
Yifan Hong | ffa9139 | 2017-01-31 13:41:23 -0800 | [diff] [blame^] | 264 | return true; |
Yifan Hong | c75fd47 | 2017-01-11 12:37:31 -0800 | [diff] [blame] | 265 | } |
Yifan Hong | 10fe0b5 | 2016-10-19 14:20:17 -0700 | [diff] [blame] | 266 | |
Yifan Hong | ffa9139 | 2017-01-31 13:41:23 -0800 | [diff] [blame^] | 267 | static std::map<std::string, Method *> gAllReservedMethods; |
| 268 | |
Steven Moreland | 14ee674 | 2016-10-18 12:58:28 -0700 | [diff] [blame] | 269 | bool Interface::addMethod(Method *method) { |
Yifan Hong | c893404 | 2016-11-17 17:10:52 -0800 | [diff] [blame] | 270 | if (isIBase()) { |
Yifan Hong | ffa9139 | 2017-01-31 13:41:23 -0800 | [diff] [blame^] | 271 | if (!gAllReservedMethods.emplace(method->name(), method).second) { |
| 272 | LOG(ERROR) << "ERROR: hidl-gen encountered duplicated reserved method " |
| 273 | << method->name(); |
| 274 | return false; |
| 275 | } |
| 276 | // will add it in addAllReservedMethods |
Yifan Hong | c893404 | 2016-11-17 17:10:52 -0800 | [diff] [blame] | 277 | return true; |
| 278 | } |
| 279 | |
Yifan Hong | 10fe0b5 | 2016-10-19 14:20:17 -0700 | [diff] [blame] | 280 | CHECK(!method->isHidlReserved()); |
Steven Moreland | 14ee674 | 2016-10-18 12:58:28 -0700 | [diff] [blame] | 281 | if (lookupMethod(method->name()) != nullptr) { |
| 282 | LOG(ERROR) << "Redefinition of method " << method->name(); |
| 283 | return false; |
| 284 | } |
Yifan Hong | 10fe0b5 | 2016-10-19 14:20:17 -0700 | [diff] [blame] | 285 | size_t serial = FIRST_CALL_TRANSACTION; |
Steven Moreland | 14ee674 | 2016-10-18 12:58:28 -0700 | [diff] [blame] | 286 | |
Yifan Hong | 10fe0b5 | 2016-10-19 14:20:17 -0700 | [diff] [blame] | 287 | serial += userDefinedMethods().size(); |
Steven Moreland | ef1a9fe | 2016-10-06 17:19:09 -0700 | [diff] [blame] | 288 | |
Yifan Hong | 10fe0b5 | 2016-10-19 14:20:17 -0700 | [diff] [blame] | 289 | const Interface *ancestor = mSuperType; |
Steven Moreland | ef1a9fe | 2016-10-06 17:19:09 -0700 | [diff] [blame] | 290 | while (ancestor != nullptr) { |
Yifan Hong | 10fe0b5 | 2016-10-19 14:20:17 -0700 | [diff] [blame] | 291 | serial += ancestor->userDefinedMethods().size(); |
Steven Moreland | ef1a9fe | 2016-10-06 17:19:09 -0700 | [diff] [blame] | 292 | ancestor = ancestor->superType(); |
| 293 | } |
| 294 | |
Yifan Hong | 10fe0b5 | 2016-10-19 14:20:17 -0700 | [diff] [blame] | 295 | CHECK(serial <= LAST_CALL_TRANSACTION) << "More than " |
| 296 | << LAST_CALL_TRANSACTION << " methods are not allowed."; |
Steven Moreland | ef1a9fe | 2016-10-06 17:19:09 -0700 | [diff] [blame] | 297 | method->setSerialId(serial); |
Yifan Hong | 10fe0b5 | 2016-10-19 14:20:17 -0700 | [diff] [blame] | 298 | mUserMethods.push_back(method); |
Steven Moreland | 14ee674 | 2016-10-18 12:58:28 -0700 | [diff] [blame] | 299 | |
| 300 | return true; |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 301 | } |
| 302 | |
Yifan Hong | ffa9139 | 2017-01-31 13:41:23 -0800 | [diff] [blame^] | 303 | bool Interface::addAllReservedMethods() { |
| 304 | // use a sorted map to insert them in serial ID order. |
| 305 | std::map<int32_t, Method *> reservedMethodsById; |
| 306 | for (const auto &pair : gAllReservedMethods) { |
| 307 | Method *method = pair.second->copySignature(); |
| 308 | bool fillSuccess = fillDescriptorChainMethod(method) |
| 309 | || fillGetDescriptorMethod(method) |
| 310 | || fillSyspropsChangedMethod(method) |
| 311 | || fillLinkToDeathMethod(method) |
| 312 | || fillUnlinkToDeathMethod(method) |
| 313 | || fillSetHALInstrumentationMethod(method); |
| 314 | if (!fillSuccess) { |
| 315 | LOG(ERROR) << "ERROR: hidl-gen does not recognize a reserved method " |
| 316 | << method->name(); |
| 317 | return false; |
| 318 | } |
| 319 | if (!reservedMethodsById.emplace(method->getSerialId(), method).second) { |
| 320 | LOG(ERROR) << "ERROR: hidl-gen uses duplicated serial id for " |
| 321 | << method->name() << " and " |
| 322 | << reservedMethodsById[method->getSerialId()]->name() |
| 323 | << ", serialId = " << method->getSerialId(); |
| 324 | return false; |
| 325 | } |
| 326 | } |
| 327 | for (const auto &pair : reservedMethodsById) { |
| 328 | this->mReservedMethods.push_back(pair.second); |
| 329 | } |
| 330 | return true; |
| 331 | } |
Yifan Hong | 10fe0b5 | 2016-10-19 14:20:17 -0700 | [diff] [blame] | 332 | |
Andreas Huber | 6cb08cf | 2016-08-03 15:44:51 -0700 | [diff] [blame] | 333 | const Interface *Interface::superType() const { |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 334 | return mSuperType; |
| 335 | } |
| 336 | |
Yifan Hong | 10fe0b5 | 2016-10-19 14:20:17 -0700 | [diff] [blame] | 337 | std::vector<const Interface *> Interface::typeChain() const { |
| 338 | std::vector<const Interface *> v; |
| 339 | const Interface *iface = this; |
| 340 | while (iface != nullptr) { |
| 341 | v.push_back(iface); |
| 342 | iface = iface->mSuperType; |
| 343 | } |
| 344 | return v; |
| 345 | } |
| 346 | |
Yifan Hong | fe95aa2 | 2016-10-19 17:26:45 -0700 | [diff] [blame] | 347 | std::vector<const Interface *> Interface::superTypeChain() const { |
| 348 | return superType()->typeChain(); // should work even if superType is nullptr |
| 349 | } |
| 350 | |
Martijn Coenen | b40ef02 | 2017-01-02 15:21:46 +0100 | [diff] [blame] | 351 | bool Interface::isElidableType() const { |
| 352 | return true; |
| 353 | } |
| 354 | |
Andreas Huber | a2723d2 | 2016-07-29 15:36:07 -0700 | [diff] [blame] | 355 | bool Interface::isInterface() const { |
| 356 | return true; |
| 357 | } |
| 358 | |
Andreas Huber | 295ad30 | 2016-08-16 11:35:00 -0700 | [diff] [blame] | 359 | bool Interface::isBinder() const { |
| 360 | return true; |
| 361 | } |
| 362 | |
Yifan Hong | 10fe0b5 | 2016-10-19 14:20:17 -0700 | [diff] [blame] | 363 | const std::vector<Method *> &Interface::userDefinedMethods() const { |
| 364 | return mUserMethods; |
| 365 | } |
| 366 | |
| 367 | const std::vector<Method *> &Interface::hidlReservedMethods() const { |
| 368 | return mReservedMethods; |
| 369 | } |
| 370 | |
| 371 | std::vector<Method *> Interface::methods() const { |
| 372 | std::vector<Method *> v(mUserMethods); |
| 373 | v.insert(v.end(), mReservedMethods.begin(), mReservedMethods.end()); |
| 374 | return v; |
| 375 | } |
| 376 | |
| 377 | std::vector<InterfaceAndMethod> Interface::allMethodsFromRoot() const { |
| 378 | std::vector<InterfaceAndMethod> v; |
| 379 | std::vector<const Interface *> chain = typeChain(); |
| 380 | for (auto it = chain.rbegin(); it != chain.rend(); ++it) { |
| 381 | const Interface *iface = *it; |
| 382 | for (Method *userMethod : iface->userDefinedMethods()) { |
| 383 | v.push_back(InterfaceAndMethod(iface, userMethod)); |
| 384 | } |
| 385 | } |
| 386 | for (Method *reservedMethod : hidlReservedMethods()) { |
Yifan Hong | c893404 | 2016-11-17 17:10:52 -0800 | [diff] [blame] | 387 | v.push_back(InterfaceAndMethod( |
| 388 | *chain.rbegin(), // IBase |
| 389 | reservedMethod)); |
Yifan Hong | 10fe0b5 | 2016-10-19 14:20:17 -0700 | [diff] [blame] | 390 | } |
| 391 | return v; |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 392 | } |
| 393 | |
Steven Moreland | 14ee674 | 2016-10-18 12:58:28 -0700 | [diff] [blame] | 394 | Method *Interface::lookupMethod(std::string name) const { |
Yifan Hong | 10fe0b5 | 2016-10-19 14:20:17 -0700 | [diff] [blame] | 395 | for (const auto &tuple : allMethodsFromRoot()) { |
| 396 | Method *method = tuple.method(); |
| 397 | if (method->name() == name) { |
| 398 | return method; |
Steven Moreland | 14ee674 | 2016-10-18 12:58:28 -0700 | [diff] [blame] | 399 | } |
Steven Moreland | 14ee674 | 2016-10-18 12:58:28 -0700 | [diff] [blame] | 400 | } |
| 401 | |
| 402 | return nullptr; |
| 403 | } |
| 404 | |
Steven Moreland | 4078631 | 2016-08-16 10:29:40 -0700 | [diff] [blame] | 405 | std::string Interface::getBaseName() const { |
Jayant Chowdhary | 3f32c1f | 2016-09-15 16:53:56 -0700 | [diff] [blame] | 406 | return fqName().getInterfaceBaseName(); |
Steven Moreland | 4078631 | 2016-08-16 10:29:40 -0700 | [diff] [blame] | 407 | } |
| 408 | |
Yifan Hong | eefe4f2 | 2017-01-04 15:32:42 -0800 | [diff] [blame] | 409 | std::string Interface::getProxyName() const { |
| 410 | return fqName().getInterfaceProxyName(); |
| 411 | } |
| 412 | |
| 413 | std::string Interface::getStubName() const { |
| 414 | return fqName().getInterfaceStubName(); |
| 415 | } |
| 416 | |
| 417 | std::string Interface::getHwName() const { |
| 418 | return fqName().getInterfaceHwName(); |
| 419 | } |
| 420 | |
| 421 | std::string Interface::getPassthroughName() const { |
| 422 | return fqName().getInterfacePassthroughName(); |
| 423 | } |
| 424 | |
Yifan Hong | 51a6509 | 2017-01-04 15:41:44 -0800 | [diff] [blame] | 425 | FQName Interface::getProxyFqName() const { |
Yifan Hong | eefe4f2 | 2017-01-04 15:32:42 -0800 | [diff] [blame] | 426 | return fqName().getInterfaceProxyFqName(); |
Yifan Hong | 158655a | 2016-11-08 12:34:07 -0800 | [diff] [blame] | 427 | } |
| 428 | |
Yifan Hong | 51a6509 | 2017-01-04 15:41:44 -0800 | [diff] [blame] | 429 | FQName Interface::getStubFqName() const { |
Yifan Hong | eefe4f2 | 2017-01-04 15:32:42 -0800 | [diff] [blame] | 430 | return fqName().getInterfaceStubFqName(); |
Yifan Hong | 158655a | 2016-11-08 12:34:07 -0800 | [diff] [blame] | 431 | } |
| 432 | |
Yifan Hong | 51a6509 | 2017-01-04 15:41:44 -0800 | [diff] [blame] | 433 | FQName Interface::getPassthroughFqName() const { |
Yifan Hong | eefe4f2 | 2017-01-04 15:32:42 -0800 | [diff] [blame] | 434 | return fqName().getInterfacePassthroughFqName(); |
Yifan Hong | 158655a | 2016-11-08 12:34:07 -0800 | [diff] [blame] | 435 | } |
| 436 | |
Steven Moreland | 979e099 | 2016-09-07 09:18:08 -0700 | [diff] [blame] | 437 | std::string Interface::getCppType(StorageMode mode, |
Steven Moreland | 979e099 | 2016-09-07 09:18:08 -0700 | [diff] [blame] | 438 | bool specifyNamespaces) const { |
Steven Moreland | 979e099 | 2016-09-07 09:18:08 -0700 | [diff] [blame] | 439 | const std::string base = |
| 440 | std::string(specifyNamespaces ? "::android::" : "") |
| 441 | + "sp<" |
| 442 | + (specifyNamespaces ? fullName() : partialCppName()) |
| 443 | + ">"; |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 444 | |
| 445 | switch (mode) { |
| 446 | case StorageMode_Stack: |
| 447 | case StorageMode_Result: |
| 448 | return base; |
| 449 | |
| 450 | case StorageMode_Argument: |
| 451 | return "const " + base + "&"; |
| 452 | } |
| 453 | } |
| 454 | |
Yifan Hong | 4ed1347 | 2016-11-02 10:44:11 -0700 | [diff] [blame] | 455 | std::string Interface::getJavaType(bool /* forInitializer */) const { |
Andreas Huber | 2831d51 | 2016-08-15 09:33:47 -0700 | [diff] [blame] | 456 | return fullJavaName(); |
| 457 | } |
| 458 | |
Zhuoyao Zhang | a588b23 | 2016-11-10 14:37:35 -0800 | [diff] [blame] | 459 | std::string Interface::getVtsType() const { |
| 460 | if (StringHelper::EndsWith(localName(), "Callback")) { |
| 461 | return "TYPE_HIDL_CALLBACK"; |
| 462 | } else { |
| 463 | return "TYPE_HIDL_INTERFACE"; |
| 464 | } |
| 465 | } |
| 466 | |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 467 | void Interface::emitReaderWriter( |
| 468 | Formatter &out, |
| 469 | const std::string &name, |
| 470 | const std::string &parcelObj, |
| 471 | bool parcelObjIsPointer, |
| 472 | bool isReader, |
| 473 | ErrorMode mode) const { |
| 474 | const std::string parcelObjDeref = |
| 475 | parcelObj + (parcelObjIsPointer ? "->" : "."); |
| 476 | |
| 477 | if (isReader) { |
Andreas Huber | e7ff228 | 2016-08-16 13:50:03 -0700 | [diff] [blame] | 478 | out << "{\n"; |
| 479 | out.indent(); |
| 480 | |
Iliyan Malchev | 549e259 | 2016-08-10 08:59:12 -0700 | [diff] [blame] | 481 | const std::string binderName = "_hidl_" + name + "_binder"; |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 482 | |
Andreas Huber | 8a82ff7 | 2016-08-04 10:29:39 -0700 | [diff] [blame] | 483 | out << "::android::sp<::android::hardware::IBinder> " |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 484 | << binderName << ";\n"; |
| 485 | |
Iliyan Malchev | 549e259 | 2016-08-10 08:59:12 -0700 | [diff] [blame] | 486 | out << "_hidl_err = "; |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 487 | out << parcelObjDeref |
| 488 | << "readNullableStrongBinder(&" |
| 489 | << binderName |
| 490 | << ");\n"; |
| 491 | |
| 492 | handleError(out, mode); |
| 493 | |
| 494 | out << name |
| 495 | << " = " |
Martijn Coenen | a63e0ad | 2016-12-07 17:29:00 +0100 | [diff] [blame] | 496 | << "::android::hardware::fromBinder<" |
| 497 | << fqName().cppName() |
| 498 | << "," |
Yifan Hong | 51a6509 | 2017-01-04 15:41:44 -0800 | [diff] [blame] | 499 | << getProxyFqName().cppName() |
Martijn Coenen | a63e0ad | 2016-12-07 17:29:00 +0100 | [diff] [blame] | 500 | << "," |
Yifan Hong | 51a6509 | 2017-01-04 15:41:44 -0800 | [diff] [blame] | 501 | << getStubFqName().cppName() |
Martijn Coenen | a63e0ad | 2016-12-07 17:29:00 +0100 | [diff] [blame] | 502 | << ">(" |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 503 | << binderName |
| 504 | << ");\n"; |
Andreas Huber | e7ff228 | 2016-08-16 13:50:03 -0700 | [diff] [blame] | 505 | |
| 506 | out.unindent(); |
| 507 | out << "}\n\n"; |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 508 | } else { |
Martijn Coenen | e163823 | 2016-10-26 12:51:34 +0200 | [diff] [blame] | 509 | out << "if (" << name << " == nullptr) {\n"; |
| 510 | out.indent(); |
| 511 | out << "_hidl_err = "; |
| 512 | out << parcelObjDeref |
| 513 | << "writeStrongBinder(nullptr);\n"; |
| 514 | out.unindent(); |
| 515 | out << "} else {\n"; |
| 516 | out.indent(); |
Yifan Hong | 158655a | 2016-11-08 12:34:07 -0800 | [diff] [blame] | 517 | out << "::android::sp<::android::hardware::IBinder> _hidl_binder = " |
| 518 | << "::android::hardware::toBinder<\n"; |
Yifan Hong | 33223ca | 2016-12-13 15:07:35 -0800 | [diff] [blame] | 519 | out.indent(2, [&] { |
Martijn Coenen | a63e0ad | 2016-12-07 17:29:00 +0100 | [diff] [blame] | 520 | out << fqName().cppName() |
Yifan Hong | 158655a | 2016-11-08 12:34:07 -0800 | [diff] [blame] | 521 | << ", " |
Yifan Hong | 51a6509 | 2017-01-04 15:41:44 -0800 | [diff] [blame] | 522 | << getProxyFqName().cppName() |
Yifan Hong | 158655a | 2016-11-08 12:34:07 -0800 | [diff] [blame] | 523 | << ">(" |
| 524 | << name |
| 525 | << ");\n"; |
| 526 | }); |
| 527 | out << "if (_hidl_binder.get() != nullptr) {\n"; |
Yifan Hong | 33223ca | 2016-12-13 15:07:35 -0800 | [diff] [blame] | 528 | out.indent([&] { |
Yifan Hong | 158655a | 2016-11-08 12:34:07 -0800 | [diff] [blame] | 529 | out << "_hidl_err = " |
| 530 | << parcelObjDeref |
| 531 | << "writeStrongBinder(_hidl_binder);\n"; |
| 532 | }); |
| 533 | out << "} else {\n"; |
Yifan Hong | 33223ca | 2016-12-13 15:07:35 -0800 | [diff] [blame] | 534 | out.indent([&] { |
Yifan Hong | 158655a | 2016-11-08 12:34:07 -0800 | [diff] [blame] | 535 | out << "_hidl_err = ::android::UNKNOWN_ERROR;\n"; |
| 536 | }); |
| 537 | out << "}\n"; |
Martijn Coenen | e163823 | 2016-10-26 12:51:34 +0200 | [diff] [blame] | 538 | out.unindent(); |
| 539 | out << "}\n"; |
Steven Moreland | 4078631 | 2016-08-16 10:29:40 -0700 | [diff] [blame] | 540 | |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 541 | handleError(out, mode); |
| 542 | } |
| 543 | } |
| 544 | |
Yifan Hong | f5cc2f7 | 2017-01-04 18:02:34 -0800 | [diff] [blame] | 545 | status_t Interface::emitGlobalTypeDeclarations(Formatter &out) const { |
| 546 | status_t status = Scope::emitGlobalTypeDeclarations(out); |
| 547 | if (status != OK) { |
| 548 | return status; |
| 549 | } |
| 550 | out << "std::string toString(" |
| 551 | << getCppArgumentType() |
| 552 | << ");\n"; |
| 553 | return OK; |
| 554 | } |
| 555 | |
| 556 | |
| 557 | status_t Interface::emitTypeDefinitions( |
| 558 | Formatter &out, const std::string prefix) const { |
| 559 | std::string space = prefix.empty() ? "" : (prefix + "::"); |
| 560 | status_t err = Scope::emitTypeDefinitions(out, space + localName()); |
| 561 | if (err != OK) { |
| 562 | return err; |
| 563 | } |
| 564 | |
| 565 | out << "std::string toString(" |
| 566 | << getCppArgumentType() |
| 567 | << " o) "; |
| 568 | |
| 569 | out.block([&] { |
| 570 | out << "std::string os;\nbool ok = false;\n"; |
| 571 | // TODO b/34136228 use interfaceDescriptor instead |
| 572 | out << "auto ret = o->interfaceChain([&os, &ok] (const auto &chain) "; |
| 573 | out.block([&] { |
| 574 | out.sIf("chain.size() >= 1", [&] { |
| 575 | out << "os += chain[0].c_str();\n" |
| 576 | << "ok = true;\n"; |
| 577 | }).endl(); |
| 578 | }); |
| 579 | out << ");\n"; |
| 580 | out.sIf("!ret.isOk() || !ok", [&] { |
| 581 | out << "os += \"[class or subclass of \";\n" |
| 582 | << "os += " << fullName() << "::descriptor;\n" |
| 583 | << "os += \"]\";\n"; |
| 584 | }).endl(); |
| 585 | out << "os += o->isRemote() ? \"@remote\" : \"@local\";\n" |
| 586 | << "return os;\n"; |
| 587 | }).endl().endl(); |
| 588 | |
| 589 | return OK; |
| 590 | } |
| 591 | |
Andreas Huber | 2831d51 | 2016-08-15 09:33:47 -0700 | [diff] [blame] | 592 | void Interface::emitJavaReaderWriter( |
| 593 | Formatter &out, |
| 594 | const std::string &parcelObj, |
| 595 | const std::string &argName, |
| 596 | bool isReader) const { |
| 597 | if (isReader) { |
| 598 | out << fullJavaName() |
| 599 | << ".asInterface(" |
| 600 | << parcelObj |
| 601 | << ".readStrongBinder());\n"; |
| 602 | } else { |
| 603 | out << parcelObj |
| 604 | << ".writeStrongBinder(" |
| 605 | << argName |
| 606 | << " == null ? null : " |
| 607 | << argName |
| 608 | << ".asBinder());\n"; |
| 609 | } |
| 610 | } |
| 611 | |
Zhuoyao Zhang | 864c771 | 2016-08-16 15:35:28 -0700 | [diff] [blame] | 612 | status_t Interface::emitVtsAttributeDeclaration(Formatter &out) const { |
| 613 | for (const auto &type : getSubTypes()) { |
Zhuoyao Zhang | c5ea9f5 | 2016-10-06 15:05:39 -0700 | [diff] [blame] | 614 | // Skip for TypeDef as it is just an alias of a defined type. |
| 615 | if (type->isTypeDef()) { |
| 616 | continue; |
| 617 | } |
Zhuoyao Zhang | 864c771 | 2016-08-16 15:35:28 -0700 | [diff] [blame] | 618 | out << "attribute: {\n"; |
| 619 | out.indent(); |
| 620 | status_t status = type->emitVtsTypeDeclarations(out); |
| 621 | if (status != OK) { |
| 622 | return status; |
| 623 | } |
| 624 | out.unindent(); |
| 625 | out << "}\n\n"; |
| 626 | } |
| 627 | return OK; |
| 628 | } |
| 629 | |
| 630 | status_t Interface::emitVtsMethodDeclaration(Formatter &out) const { |
Yifan Hong | 10fe0b5 | 2016-10-19 14:20:17 -0700 | [diff] [blame] | 631 | for (const auto &method : methods()) { |
Steven Moreland | cea2478 | 2016-11-07 11:40:48 -0800 | [diff] [blame] | 632 | if (method->isHidlReserved()) { |
| 633 | continue; |
| 634 | } |
| 635 | |
Zhuoyao Zhang | 864c771 | 2016-08-16 15:35:28 -0700 | [diff] [blame] | 636 | out << "api: {\n"; |
| 637 | out.indent(); |
| 638 | out << "name: \"" << method->name() << "\"\n"; |
| 639 | // Generate declaration for each return value. |
| 640 | for (const auto &result : method->results()) { |
| 641 | out << "return_type_hidl: {\n"; |
| 642 | out.indent(); |
| 643 | status_t status = result->type().emitVtsAttributeType(out); |
| 644 | if (status != OK) { |
| 645 | return status; |
| 646 | } |
| 647 | out.unindent(); |
| 648 | out << "}\n"; |
| 649 | } |
| 650 | // Generate declaration for each input argument |
| 651 | for (const auto &arg : method->args()) { |
| 652 | out << "arg: {\n"; |
| 653 | out.indent(); |
| 654 | status_t status = arg->type().emitVtsAttributeType(out); |
| 655 | if (status != OK) { |
| 656 | return status; |
| 657 | } |
| 658 | out.unindent(); |
| 659 | out << "}\n"; |
| 660 | } |
| 661 | // Generate declaration for each annotation. |
Steven Moreland | d537ab0 | 2016-09-12 10:32:01 -0700 | [diff] [blame] | 662 | for (const auto &annotation : method->annotations()) { |
Zhuoyao Zhang | 864c771 | 2016-08-16 15:35:28 -0700 | [diff] [blame] | 663 | out << "callflow: {\n"; |
| 664 | out.indent(); |
Steven Moreland | d537ab0 | 2016-09-12 10:32:01 -0700 | [diff] [blame] | 665 | std::string name = annotation->name(); |
Zhuoyao Zhang | 864c771 | 2016-08-16 15:35:28 -0700 | [diff] [blame] | 666 | if (name == "entry") { |
| 667 | out << "entry: true\n"; |
| 668 | } else if (name == "exit") { |
| 669 | out << "exit: true\n"; |
| 670 | } else if (name == "callflow") { |
Steven Moreland | d537ab0 | 2016-09-12 10:32:01 -0700 | [diff] [blame] | 671 | const AnnotationParam *param = |
| 672 | annotation->getParam("next"); |
| 673 | if (param != nullptr) { |
| 674 | for (auto value : *param->getValues()) { |
| 675 | out << "next: " << value << "\n"; |
| 676 | } |
Zhuoyao Zhang | 864c771 | 2016-08-16 15:35:28 -0700 | [diff] [blame] | 677 | } |
| 678 | } else { |
| 679 | std::cerr << "Invalid annotation '" |
| 680 | << name << "' for method: " << method->name() |
| 681 | << ". Should be one of: entry, exit, callflow. \n"; |
| 682 | return UNKNOWN_ERROR; |
| 683 | } |
| 684 | out.unindent(); |
| 685 | out << "}\n"; |
| 686 | } |
| 687 | out.unindent(); |
| 688 | out << "}\n\n"; |
| 689 | } |
| 690 | return OK; |
| 691 | } |
| 692 | |
| 693 | status_t Interface::emitVtsAttributeType(Formatter &out) const { |
Zhuoyao Zhang | a588b23 | 2016-11-10 14:37:35 -0800 | [diff] [blame] | 694 | out << "type: " << getVtsType() << "\n" |
Zhuoyao Zhang | 5158db4 | 2016-08-10 10:25:20 -0700 | [diff] [blame] | 695 | << "predefined_type: \"" |
| 696 | << localName() |
Zhuoyao Zhang | 1993352 | 2016-08-29 15:06:38 -0700 | [diff] [blame] | 697 | << "\"\n" |
Zhuoyao Zhang | a588b23 | 2016-11-10 14:37:35 -0800 | [diff] [blame] | 698 | << "is_callback: " |
| 699 | << (StringHelper::EndsWith(localName(), "Callback") ? "true" : "false") |
| 700 | << "\n"; |
Zhuoyao Zhang | 5158db4 | 2016-08-10 10:25:20 -0700 | [diff] [blame] | 701 | return OK; |
| 702 | } |
| 703 | |
Steven Moreland | 69e7c70 | 2016-09-09 11:16:32 -0700 | [diff] [blame] | 704 | bool Interface::hasOnewayMethods() const { |
Yifan Hong | 10fe0b5 | 2016-10-19 14:20:17 -0700 | [diff] [blame] | 705 | for (auto const &method : methods()) { |
Steven Moreland | 69e7c70 | 2016-09-09 11:16:32 -0700 | [diff] [blame] | 706 | if (method->isOneway()) { |
| 707 | return true; |
| 708 | } |
| 709 | } |
| 710 | |
| 711 | const Interface* superClass = superType(); |
| 712 | |
| 713 | if (superClass != nullptr) { |
| 714 | return superClass->hasOnewayMethods(); |
| 715 | } |
| 716 | |
| 717 | return false; |
| 718 | } |
| 719 | |
Andreas Huber | 70a59e1 | 2016-08-16 12:57:01 -0700 | [diff] [blame] | 720 | bool Interface::isJavaCompatible() const { |
Andreas Huber | ea081b3 | 2016-08-17 15:57:47 -0700 | [diff] [blame] | 721 | if (mIsJavaCompatibleInProgress) { |
| 722 | // We're currently trying to determine if this Interface is |
| 723 | // java-compatible and something is referencing this interface through |
| 724 | // one of its methods. Assume we'll ultimately succeed, if we were wrong |
| 725 | // the original invocation of Interface::isJavaCompatible() will then |
| 726 | // return the correct "false" result. |
| 727 | return true; |
| 728 | } |
| 729 | |
Andreas Huber | 0fa9e39 | 2016-08-31 09:05:44 -0700 | [diff] [blame] | 730 | if (mSuperType != nullptr && !mSuperType->isJavaCompatible()) { |
| 731 | mIsJavaCompatibleInProgress = false; |
| 732 | return false; |
| 733 | } |
| 734 | |
Andreas Huber | ea081b3 | 2016-08-17 15:57:47 -0700 | [diff] [blame] | 735 | mIsJavaCompatibleInProgress = true; |
| 736 | |
Andreas Huber | 70a59e1 | 2016-08-16 12:57:01 -0700 | [diff] [blame] | 737 | if (!Scope::isJavaCompatible()) { |
Andreas Huber | ea081b3 | 2016-08-17 15:57:47 -0700 | [diff] [blame] | 738 | mIsJavaCompatibleInProgress = false; |
Andreas Huber | 70a59e1 | 2016-08-16 12:57:01 -0700 | [diff] [blame] | 739 | return false; |
| 740 | } |
| 741 | |
Yifan Hong | 10fe0b5 | 2016-10-19 14:20:17 -0700 | [diff] [blame] | 742 | for (const auto &method : methods()) { |
Andreas Huber | 70a59e1 | 2016-08-16 12:57:01 -0700 | [diff] [blame] | 743 | if (!method->isJavaCompatible()) { |
Andreas Huber | ea081b3 | 2016-08-17 15:57:47 -0700 | [diff] [blame] | 744 | mIsJavaCompatibleInProgress = false; |
Andreas Huber | 70a59e1 | 2016-08-16 12:57:01 -0700 | [diff] [blame] | 745 | return false; |
| 746 | } |
| 747 | } |
| 748 | |
Andreas Huber | ea081b3 | 2016-08-17 15:57:47 -0700 | [diff] [blame] | 749 | mIsJavaCompatibleInProgress = false; |
| 750 | |
Andreas Huber | 70a59e1 | 2016-08-16 12:57:01 -0700 | [diff] [blame] | 751 | return true; |
| 752 | } |
| 753 | |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 754 | } // namespace android |
| 755 | |