blob: 10fb89dc527c8bed228af98bb3e4d360b24958c3 [file] [log] [blame]
Andreas Huber1aec3972016-08-26 09:26:32 -07001/*
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 Huberc9410c72016-07-28 12:18:40 -070017#include "Interface.h"
18
Zhuoyao Zhangba7e6e92016-08-10 12:19:02 -070019#include "Annotation.h"
Yifan Hong30b5d1f2017-04-03 12:19:25 -070020#include "ArrayType.h"
21#include "ConstantExpression.h"
Martijn Coenen115d4282016-12-19 05:14:04 +010022#include "DeathRecipientType.h"
Andreas Huberc9410c72016-07-28 12:18:40 -070023#include "Method.h"
Martijn Coenen115d4282016-12-19 05:14:04 +010024#include "ScalarType.h"
Yifan Hong10fe0b52016-10-19 14:20:17 -070025#include "StringType.h"
26#include "VectorType.h"
Andreas Huberc9410c72016-07-28 12:18:40 -070027
Yifan Hong30b5d1f2017-04-03 12:19:25 -070028#include <unistd.h>
29
Yifan Hong30b5d1f2017-04-03 12:19:25 -070030#include <iostream>
Timur Iskhakov7296af12017-08-09 21:52:48 +000031#include <memory>
Yifan Hong30b5d1f2017-04-03 12:19:25 -070032#include <sstream>
Timur Iskhakovcec46c42017-08-09 00:22:02 -070033#include <unordered_map>
Yifan Hong30b5d1f2017-04-03 12:19:25 -070034
Steven Moreland14ee6742016-10-18 12:58:28 -070035#include <android-base/logging.h>
Steven Moreland5bdfa702017-04-18 23:20:39 -070036#include <hidl-hash/Hash.h>
Iliyan Malcheva72e0d22016-09-09 11:03:08 -070037#include <hidl-util/Formatter.h>
Yifan Hong10fe0b52016-10-19 14:20:17 -070038#include <hidl-util/StringHelper.h>
Zhuoyao Zhang864c7712016-08-16 15:35:28 -070039
Andreas Huberc9410c72016-07-28 12:18:40 -070040namespace android {
41
Steven Morelandb8e15a52017-02-13 19:35:40 -080042#define B_PACK_CHARS(c1, c2, c3, c4) \
43 ((((c1)<<24)) | (((c2)<<16)) | (((c3)<<8)) | (c4))
44
Yifan Hong10fe0b52016-10-19 14:20:17 -070045/* 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 */
53enum {
Yifan Hong10fe0b52016-10-19 14:20:17 -070054 /////////////////// User defined transactions
55 FIRST_CALL_TRANSACTION = 0x00000001,
Steven Morelandb8e15a52017-02-13 19:35:40 -080056 LAST_CALL_TRANSACTION = 0x0effffff,
Yifan Hong10fe0b52016-10-19 14:20:17 -070057 /////////////////// HIDL reserved
Steven Morelandb8e15a52017-02-13 19:35:40 -080058 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 Hong30b5d1f2017-04-03 12:19:25 -070068 HIDL_HASH_CHAIN_TRANSACTION = B_PACK_CHARS(0x0f, 'H', 'S', 'H'),
Steven Morelandb8e15a52017-02-13 19:35:40 -080069 LAST_HIDL_TRANSACTION = 0x0fffffff,
Yifan Hong10fe0b52016-10-19 14:20:17 -070070};
71
Timur Iskhakovcb0ba522017-07-17 20:01:37 -070072Interface::Interface(const char* localName, const Location& location, Scope* parent,
Timur Iskhakov0344e612017-08-25 12:57:09 -070073 const Reference<Type>& superType)
Timur Iskhakov505316c2017-08-05 03:38:59 +000074 : Scope(localName, location, parent),
75 mSuperType(superType),
76 mIsJavaCompatibleInProgress(false) {}
Martijn Coenenaf712c02016-11-16 15:26:27 +010077
Steven Moreland30bb6a82016-11-30 09:18:34 -080078std::string Interface::typeName() const {
79 return "interface " + localName();
80}
81
Steven Moreland424a9482017-02-13 19:20:40 -080082bool Interface::fillPingMethod(Method *method) const {
83 if (method->name() != "ping") {
84 return false;
85 }
86
87 method->fillImplementation(
88 HIDL_PING_TRANSACTION,
89 {
Steven Moreland937408a2017-03-20 09:54:18 -070090 {IMPL_INTERFACE,
Steven Moreland424a9482017-02-13 19:20:40 -080091 [](auto &out) {
92 out << "return ::android::hardware::Void();\n";
93 }
94 },
95 {IMPL_STUB_IMPL,
96 [](auto &out) {
97 out << "return ::android::hardware::Void();\n";
98 }
99 }
100 }, /*cppImpl*/
101 {
Steven Moreland937408a2017-03-20 09:54:18 -0700102 {IMPL_INTERFACE,
Yi Kongc8ff4672017-04-30 23:46:56 -0700103 [](auto &out) {
Steven Moreland424a9482017-02-13 19:20:40 -0800104 out << "return;\n";
105 }
106 },
107 {IMPL_STUB, nullptr /* don't generate code */}
108 } /*javaImpl*/
109 );
110
111 return true;
112}
113
Yifan Hongffa91392017-01-31 13:41:23 -0800114bool Interface::fillLinkToDeathMethod(Method *method) const {
115 if (method->name() != "linkToDeath") {
116 return false;
117 }
Martijn Coenen115d4282016-12-19 05:14:04 +0100118
Yifan Hongffa91392017-01-31 13:41:23 -0800119 method->fillImplementation(
Martijn Coenen115d4282016-12-19 05:14:04 +0100120 HIDL_LINK_TO_DEATH_TRANSACTION,
121 {
Steven Moreland937408a2017-03-20 09:54:18 -0700122 {IMPL_INTERFACE,
Martijn Coenen115d4282016-12-19 05:14:04 +0100123 [](auto &out) {
124 out << "(void)cookie;\n"
125 << "return (recipient != nullptr);\n";
126 }
127 },
128 {IMPL_PROXY,
129 [](auto &out) {
Martijn Coenenfa55d6e2016-12-20 06:08:31 +0100130 out << "::android::hardware::ProcessState::self()->startThreadPool();\n";
Martijn Coenen115d4282016-12-19 05:14:04 +0100131 out << "::android::hardware::hidl_binder_death_recipient *binder_recipient"
132 << " = new ::android::hardware::hidl_binder_death_recipient(recipient, cookie, this);\n"
133 << "std::unique_lock<std::mutex> lock(_hidl_mMutex);\n"
134 << "_hidl_mDeathRecipients.push_back(binder_recipient);\n"
135 << "return (remote()->linkToDeath(binder_recipient)"
136 << " == ::android::OK);\n";
137 }
138 },
Martijn Coenen8d12b502016-12-27 14:30:27 +0100139 {IMPL_STUB, nullptr}
Martijn Coenen115d4282016-12-19 05:14:04 +0100140 }, /*cppImpl*/
141 {
Steven Moreland937408a2017-03-20 09:54:18 -0700142 {IMPL_INTERFACE,
Yi Kongc8ff4672017-04-30 23:46:56 -0700143 [](auto &out) {
Martijn Coenen115d4282016-12-19 05:14:04 +0100144 out << "return true;";
145 }
146 },
147 {IMPL_PROXY,
Yi Kongc8ff4672017-04-30 23:46:56 -0700148 [](auto &out) {
Martijn Coenen8d12b502016-12-27 14:30:27 +0100149 out << "return mRemote.linkToDeath(recipient, cookie);\n";
Martijn Coenen115d4282016-12-19 05:14:04 +0100150 }
151 },
Martijn Coenen8d12b502016-12-27 14:30:27 +0100152 {IMPL_STUB, nullptr}
Martijn Coenen115d4282016-12-19 05:14:04 +0100153 } /*javaImpl*/
154 );
Yifan Hongffa91392017-01-31 13:41:23 -0800155 return true;
Martijn Coenen115d4282016-12-19 05:14:04 +0100156}
157
Yifan Hongffa91392017-01-31 13:41:23 -0800158bool Interface::fillUnlinkToDeathMethod(Method *method) const {
159 if (method->name() != "unlinkToDeath") {
160 return false;
161 }
Martijn Coenen115d4282016-12-19 05:14:04 +0100162
Yifan Hongffa91392017-01-31 13:41:23 -0800163 method->fillImplementation(
Martijn Coenen115d4282016-12-19 05:14:04 +0100164 HIDL_UNLINK_TO_DEATH_TRANSACTION,
165 {
Steven Moreland937408a2017-03-20 09:54:18 -0700166 {IMPL_INTERFACE,
Martijn Coenen115d4282016-12-19 05:14:04 +0100167 [](auto &out) {
168 out << "return (recipient != nullptr);\n";
169 }
170 },
171 {IMPL_PROXY,
172 [](auto &out) {
173 out << "std::unique_lock<std::mutex> lock(_hidl_mMutex);\n"
174 << "for (auto it = _hidl_mDeathRecipients.begin();"
175 << "it != _hidl_mDeathRecipients.end();"
176 << "++it) {\n";
177 out.indent([&] {
178 out.sIf("(*it)->getRecipient() == recipient", [&] {
179 out << "::android::status_t status = remote()->unlinkToDeath(*it);\n"
180 << "_hidl_mDeathRecipients.erase(it);\n"
181 << "return status == ::android::OK;\n";
182 });
183 });
184 out << "}\n";
185 out << "return false;\n";
186 }
187 },
Martijn Coenen8d12b502016-12-27 14:30:27 +0100188 {IMPL_STUB, nullptr /* don't generate code */}
Martijn Coenen115d4282016-12-19 05:14:04 +0100189 }, /*cppImpl*/
190 {
Steven Moreland937408a2017-03-20 09:54:18 -0700191 {IMPL_INTERFACE,
Yi Kongc8ff4672017-04-30 23:46:56 -0700192 [](auto &out) {
Martijn Coenen8d12b502016-12-27 14:30:27 +0100193 out << "return true;\n";
Martijn Coenen115d4282016-12-19 05:14:04 +0100194 }
195 },
196 {IMPL_PROXY,
Yi Kongc8ff4672017-04-30 23:46:56 -0700197 [](auto &out) {
Martijn Coenen8d12b502016-12-27 14:30:27 +0100198 out << "return mRemote.unlinkToDeath(recipient);\n";
Martijn Coenen115d4282016-12-19 05:14:04 +0100199 }
200 },
Martijn Coenen8d12b502016-12-27 14:30:27 +0100201 {IMPL_STUB, nullptr /* don't generate code */}
Martijn Coenen115d4282016-12-19 05:14:04 +0100202 } /*javaImpl*/
203 );
Yifan Hongffa91392017-01-31 13:41:23 -0800204 return true;
Martijn Coenen115d4282016-12-19 05:14:04 +0100205}
Yifan Hongffa91392017-01-31 13:41:23 -0800206bool Interface::fillSyspropsChangedMethod(Method *method) const {
207 if (method->name() != "notifySyspropsChanged") {
208 return false;
209 }
210
211 method->fillImplementation(
Martijn Coenenaf712c02016-11-16 15:26:27 +0100212 HIDL_SYSPROPS_CHANGED_TRANSACTION,
Yi Kongc8ff4672017-04-30 23:46:56 -0700213 { { IMPL_INTERFACE, [](auto &out) {
Martijn Coenenaf712c02016-11-16 15:26:27 +0100214 out << "::android::report_sysprop_change();\n";
215 out << "return ::android::hardware::Void();";
Martijn Coenen115d4282016-12-19 05:14:04 +0100216 } } }, /*cppImpl */
Steven Moreland937408a2017-03-20 09:54:18 -0700217 { { IMPL_INTERFACE, [](auto &out) { /* javaImpl */
Sundong Ahnc1432c92017-07-13 23:58:27 +0900218 out << "android.os.HwBinder.reportSyspropChanged();";
Martijn Coenen115d4282016-12-19 05:14:04 +0100219 } } } /*javaImpl */
Martijn Coenenaf712c02016-11-16 15:26:27 +0100220 );
Yifan Hongffa91392017-01-31 13:41:23 -0800221 return true;
Andreas Huberc9410c72016-07-28 12:18:40 -0700222}
223
Yifan Hongffa91392017-01-31 13:41:23 -0800224bool Interface::fillSetHALInstrumentationMethod(Method *method) const {
225 if (method->name() != "setHALInstrumentation") {
226 return false;
227 }
228
229 method->fillImplementation(
Zhuoyao Zhangdd85c5c2017-01-03 17:30:24 -0800230 HIDL_SET_HAL_INSTRUMENTATION_TRANSACTION,
231 {
Steven Moreland937408a2017-03-20 09:54:18 -0700232 {IMPL_INTERFACE,
Yi Kongc8ff4672017-04-30 23:46:56 -0700233 [](auto &out) {
Zhuoyao Zhangdd85c5c2017-01-03 17:30:24 -0800234 // do nothing for base class.
235 out << "return ::android::hardware::Void();\n";
236 }
237 },
Zhuoyao Zhangdd85c5c2017-01-03 17:30:24 -0800238 {IMPL_STUB,
239 [](auto &out) {
240 out << "configureInstrumentation();\n";
241 }
242 },
243 {IMPL_PASSTHROUGH,
244 [](auto &out) {
245 out << "configureInstrumentation();\n";
246 out << "return ::android::hardware::Void();\n";
247 }
248 },
249 }, /*cppImpl */
Steven Moreland937408a2017-03-20 09:54:18 -0700250 { { IMPL_INTERFACE, [](auto & /*out*/) { /* javaImpl */
Zhuoyao Zhangdd85c5c2017-01-03 17:30:24 -0800251 // Not support for Java Impl for now.
252 } } } /*javaImpl */
253 );
Yifan Hongffa91392017-01-31 13:41:23 -0800254 return true;
Zhuoyao Zhangdd85c5c2017-01-03 17:30:24 -0800255}
256
Yifan Hongffa91392017-01-31 13:41:23 -0800257bool Interface::fillDescriptorChainMethod(Method *method) const {
258 if (method->name() != "interfaceChain") {
259 return false;
260 }
Yifan Hong10fe0b52016-10-19 14:20:17 -0700261
Yifan Hongffa91392017-01-31 13:41:23 -0800262 method->fillImplementation(
Yifan Hong10fe0b52016-10-19 14:20:17 -0700263 HIDL_DESCRIPTOR_CHAIN_TRANSACTION,
Steven Moreland937408a2017-03-20 09:54:18 -0700264 { { IMPL_INTERFACE, [this](auto &out) {
Yifan Hong10fe0b52016-10-19 14:20:17 -0700265 std::vector<const Interface *> chain = typeChain();
Yifan Hong03935122016-12-19 11:10:40 -0800266 out << "_hidl_cb(";
267 out.block([&] {
268 for (const Interface *iface : chain) {
269 out << iface->fullName() << "::descriptor,\n";
270 }
271 });
272 out << ");\n";
Yifan Hong10fe0b52016-10-19 14:20:17 -0700273 out << "return ::android::hardware::Void();";
Martijn Coenen115d4282016-12-19 05:14:04 +0100274 } } }, /* cppImpl */
Steven Moreland937408a2017-03-20 09:54:18 -0700275 { { IMPL_INTERFACE, [this](auto &out) {
Yifan Hong10fe0b52016-10-19 14:20:17 -0700276 std::vector<const Interface *> chain = typeChain();
Yifan Hong1af73532016-11-09 14:32:58 -0800277 out << "return new java.util.ArrayList<String>(java.util.Arrays.asList(\n";
Yifan Hong10fe0b52016-10-19 14:20:17 -0700278 out.indent(); out.indent();
279 for (size_t i = 0; i < chain.size(); ++i) {
280 if (i != 0)
281 out << ",\n";
Steven Morelandd39133b2016-11-11 12:30:08 -0800282 out << chain[i]->fullJavaName() << ".kInterfaceName";
Yifan Hong10fe0b52016-10-19 14:20:17 -0700283 }
284 out << "));";
285 out.unindent(); out.unindent();
Yifan Hongffa91392017-01-31 13:41:23 -0800286 } } } /* javaImpl */
Martijn Coenen115d4282016-12-19 05:14:04 +0100287 );
Yifan Hongffa91392017-01-31 13:41:23 -0800288 return true;
Yifan Hong10fe0b52016-10-19 14:20:17 -0700289}
290
Yifan Hong30b5d1f2017-04-03 12:19:25 -0700291static void emitDigestChain(
Timur Iskhakov7296af12017-08-09 21:52:48 +0000292 Formatter& out, const std::string& prefix, const std::vector<const Interface*>& chain,
293 std::function<std::string(std::unique_ptr<ConstantExpression>)> byteToString) {
Yifan Hong30b5d1f2017-04-03 12:19:25 -0700294 out.join(chain.begin(), chain.end(), ",\n", [&] (const auto &iface) {
Steven Moreland0e4be1e2017-04-18 19:50:29 -0700295 const Hash &hash = Hash::getHash(iface->location().begin().filename());
Yifan Hong30b5d1f2017-04-03 12:19:25 -0700296 out << prefix;
297 out << "{";
Steven Moreland0e4be1e2017-04-18 19:50:29 -0700298 out.join(hash.raw().begin(), hash.raw().end(), ",", [&](const auto &e) {
Yifan Hong30b5d1f2017-04-03 12:19:25 -0700299 // Use ConstantExpression::cppValue / javaValue
300 // because Java used signed byte for uint8_t.
301 out << byteToString(ConstantExpression::ValueOf(ScalarType::Kind::KIND_UINT8, e));
302 });
303 out << "} /* ";
Steven Moreland0e4be1e2017-04-18 19:50:29 -0700304 out << hash.hexString();
Yifan Hong30b5d1f2017-04-03 12:19:25 -0700305 out << " */";
306 });
307}
308
309bool Interface::fillHashChainMethod(Method *method) const {
310 if (method->name() != "getHashChain") {
311 return false;
312 }
313 const VectorType *chainType = static_cast<const VectorType *>(&method->results()[0]->type());
314 const ArrayType *digestType = static_cast<const ArrayType *>(chainType->getElementType());
315
316 method->fillImplementation(
317 HIDL_HASH_CHAIN_TRANSACTION,
318 { { IMPL_INTERFACE, [this, digestType](auto &out) {
319 std::vector<const Interface *> chain = typeChain();
320 out << "_hidl_cb(";
321 out.block([&] {
Timur Iskhakov7296af12017-08-09 21:52:48 +0000322 emitDigestChain(out, "(" + digestType->getInternalDataCppType() + ")", chain,
323 [](const auto& e) { return e->cppValue(); });
Yifan Hong30b5d1f2017-04-03 12:19:25 -0700324 });
325 out << ");\n";
326 out << "return ::android::hardware::Void();\n";
327 } } }, /* cppImpl */
328 { { IMPL_INTERFACE, [this, digestType, chainType](auto &out) {
329 std::vector<const Interface *> chain = typeChain();
330 out << "return new "
331 << chainType->getJavaType(false /* forInitializer */)
332 << "(java.util.Arrays.asList(\n";
333 out.indent(2, [&] {
334 // No need for dimensions when elements are explicitly provided.
335 emitDigestChain(out, "new " + digestType->getJavaType(false /* forInitializer */),
Timur Iskhakov7296af12017-08-09 21:52:48 +0000336 chain, [](const auto& e) { return e->javaValue(); });
Yifan Hong30b5d1f2017-04-03 12:19:25 -0700337 });
338 out << "));\n";
339 } } } /* javaImpl */
340 );
341 return true;
342}
343
Yifan Hongffa91392017-01-31 13:41:23 -0800344bool Interface::fillGetDescriptorMethod(Method *method) const {
345 if (method->name() != "interfaceDescriptor") {
346 return false;
347 }
Yifan Hongc75fd472017-01-11 12:37:31 -0800348
Yifan Hongffa91392017-01-31 13:41:23 -0800349 method->fillImplementation(
Yifan Hongc75fd472017-01-11 12:37:31 -0800350 HIDL_GET_DESCRIPTOR_TRANSACTION,
Steven Moreland937408a2017-03-20 09:54:18 -0700351 { { IMPL_INTERFACE, [this](auto &out) {
Yifan Hongc75fd472017-01-11 12:37:31 -0800352 out << "_hidl_cb("
353 << fullName()
354 << "::descriptor);\n"
355 << "return ::android::hardware::Void();";
356 } } }, /* cppImpl */
Steven Moreland937408a2017-03-20 09:54:18 -0700357 { { IMPL_INTERFACE, [this](auto &out) {
Yifan Hongc75fd472017-01-11 12:37:31 -0800358 out << "return "
359 << fullJavaName()
360 << ".kInterfaceName;\n";
Yifan Hongffa91392017-01-31 13:41:23 -0800361 } } } /* javaImpl */
Yifan Hongc75fd472017-01-11 12:37:31 -0800362 );
Yifan Hongffa91392017-01-31 13:41:23 -0800363 return true;
Yifan Hongc75fd472017-01-11 12:37:31 -0800364}
Yifan Hong10fe0b52016-10-19 14:20:17 -0700365
Yifan Hongbcffce22017-02-01 15:52:06 -0800366bool Interface::fillGetDebugInfoMethod(Method *method) const {
367 if (method->name() != "getDebugInfo") {
Yifan Hongcd2ae452017-01-31 14:33:40 -0800368 return false;
369 }
370
Yifan Hongdf1ea3f2017-03-02 17:02:10 -0800371 static const std::string sArch =
372 "#if defined(__LP64__)\n"
373 "::android::hidl::base::V1_0::DebugInfo::Architecture::IS_64BIT\n"
374 "#else\n"
375 "::android::hidl::base::V1_0::DebugInfo::Architecture::IS_32BIT\n"
376 "#endif\n";
377
Yifan Hongcd2ae452017-01-31 14:33:40 -0800378 method->fillImplementation(
379 HIDL_GET_REF_INFO_TRANSACTION,
380 {
Steven Moreland937408a2017-03-20 09:54:18 -0700381 {IMPL_INTERFACE,
Yi Kongc8ff4672017-04-30 23:46:56 -0700382 [](auto &out) {
Yifan Hongbcffce22017-02-01 15:52:06 -0800383 // getDebugInfo returns N/A for local objects.
Yifan Hongdf1ea3f2017-03-02 17:02:10 -0800384 out << "_hidl_cb({ -1 /* pid */, 0 /* ptr */, \n"
385 << sArch
386 << "});\n"
Yifan Hongcd2ae452017-01-31 14:33:40 -0800387 << "return ::android::hardware::Void();";
388 }
389 },
390 {IMPL_STUB_IMPL,
Yi Kongc8ff4672017-04-30 23:46:56 -0700391 [](auto &out) {
Yifan Hong2e036c92017-03-07 13:18:12 -0800392 out << "_hidl_cb(";
393 out.block([&] {
394 out << "::android::hardware::details::debuggable()"
395 << "? getpid() : -1 /* pid */,\n"
396 << "::android::hardware::details::debuggable()"
397 << "? reinterpret_cast<uint64_t>(this) : 0 /* ptr */,\n"
398 << sArch << "\n";
399 });
400 out << ");\n"
Yifan Hongcd2ae452017-01-31 14:33:40 -0800401 << "return ::android::hardware::Void();";
402 }
403 }
404 }, /* cppImpl */
Yi Kongc8ff4672017-04-30 23:46:56 -0700405 { { IMPL_INTERFACE, [method](auto &out) {
Yifan Hongcd2ae452017-01-31 14:33:40 -0800406 const Type &refInfo = method->results().front()->type();
407 out << refInfo.getJavaType(false /* forInitializer */) << " info = new "
408 << refInfo.getJavaType(true /* forInitializer */) << "();\n"
Yifan Hongbcffce22017-02-01 15:52:06 -0800409 // TODO(b/34777099): PID for java.
410 << "info.pid = -1;\n"
411 << "info.ptr = 0;\n"
Yifan Hongdf1ea3f2017-03-02 17:02:10 -0800412 << "info.arch = android.hidl.base.V1_0.DebugInfo.Architecture.UNKNOWN;"
Yifan Hongcd2ae452017-01-31 14:33:40 -0800413 << "return info;";
414 } } } /* javaImpl */
415 );
416
417 return true;
418}
419
Andreas Huber37065d62017-02-07 14:36:54 -0800420bool Interface::fillDebugMethod(Method *method) const {
421 if (method->name() != "debug") {
422 return false;
423 }
424
425 method->fillImplementation(
426 HIDL_DEBUG_TRANSACTION,
427 {
Steven Moreland937408a2017-03-20 09:54:18 -0700428 {IMPL_INTERFACE,
Yi Kongc8ff4672017-04-30 23:46:56 -0700429 [](auto &out) {
Andreas Huber37065d62017-02-07 14:36:54 -0800430 out << "(void)fd;\n"
431 << "(void)options;\n"
432 << "return ::android::hardware::Void();";
433 }
434 },
435 }, /* cppImpl */
436 {
437 /* unused, as the debug method is hidden from Java */
438 } /* javaImpl */
439 );
440
441 return true;
442}
443
Yifan Hongffa91392017-01-31 13:41:23 -0800444static std::map<std::string, Method *> gAllReservedMethods;
445
Steven Moreland14ee6742016-10-18 12:58:28 -0700446bool Interface::addMethod(Method *method) {
Yifan Hongc8934042016-11-17 17:10:52 -0800447 if (isIBase()) {
Yifan Hongffa91392017-01-31 13:41:23 -0800448 if (!gAllReservedMethods.emplace(method->name(), method).second) {
449 LOG(ERROR) << "ERROR: hidl-gen encountered duplicated reserved method "
450 << method->name();
451 return false;
452 }
453 // will add it in addAllReservedMethods
Yifan Hongc8934042016-11-17 17:10:52 -0800454 return true;
455 }
456
Yifan Hong10fe0b52016-10-19 14:20:17 -0700457 CHECK(!method->isHidlReserved());
Yifan Hong10fe0b52016-10-19 14:20:17 -0700458 mUserMethods.push_back(method);
Steven Moreland14ee6742016-10-18 12:58:28 -0700459
460 return true;
Andreas Huberc9410c72016-07-28 12:18:40 -0700461}
462
Timur Iskhakov33431e62017-08-21 17:31:23 -0700463std::vector<Reference<Type>> Interface::getReferences() const {
464 std::vector<Reference<Type>> ret;
465
466 if (superType() != nullptr) {
467 ret.push_back(mSuperType);
468 }
469
470 for (const auto* method : methods()) {
471 const auto& references = method->getReferences();
472 ret.insert(ret.end(), references.begin(), references.end());
473 }
474
475 return ret;
476}
477
Timur Iskhakov891a8662017-08-25 21:53:48 -0700478std::vector<ConstantExpression*> Interface::getConstantExpressions() const {
479 std::vector<ConstantExpression*> ret;
480 for (const auto* method : methods()) {
481 const auto& retMethod = method->getConstantExpressions();
482 ret.insert(ret.end(), retMethod.begin(), retMethod.end());
483 }
484 return ret;
485}
486
Timur Iskhakovcec46c42017-08-09 00:22:02 -0700487status_t Interface::resolveInheritance() {
488 size_t serial = FIRST_CALL_TRANSACTION;
489 for (const auto* ancestor : superTypeChain()) {
490 serial += ancestor->mUserMethods.size();
491 }
492
493 for (Method* method : mUserMethods) {
494 if (serial > LAST_CALL_TRANSACTION) {
495 std::cerr << "ERROR: More than " << LAST_CALL_TRANSACTION
496 << " methods (including super and reserved) are not allowed at " << location()
497 << "\n";
498 return UNKNOWN_ERROR;
499 }
500
501 method->setSerialId(serial);
502 serial++;
503 }
504
505 return Scope::resolveInheritance();
506}
507
Timur Iskhakovcec46c42017-08-09 00:22:02 -0700508status_t Interface::validate() const {
509 CHECK(isIBase() == mSuperType.isEmptyReference());
510
Timur Iskhakov0344e612017-08-25 12:57:09 -0700511 if (!isIBase() && !mSuperType->isInterface()) {
512 std::cerr << "ERROR: You can only extend interfaces at " << mSuperType.location() << "\n";
513 return UNKNOWN_ERROR;
514 }
515
Timur Iskhakovcec46c42017-08-09 00:22:02 -0700516 status_t err = validateUniqueNames();
517 if (err != OK) return err;
518
519 return Scope::validate();
520}
521
522status_t Interface::validateUniqueNames() const {
523 std::unordered_map<std::string, const Interface*> registeredMethodNames;
524 for (auto const& tuple : allSuperMethodsFromRoot()) {
525 // No need to check super method uniqueness
526 registeredMethodNames[tuple.method()->name()] = tuple.interface();
527 }
528
529 for (const Method* method : mUserMethods) {
530 auto registered = registeredMethodNames.find(method->name());
531
532 if (registered != registeredMethodNames.end()) {
533 const Interface* definedInType = registered->second;
534
535 if (definedInType == this) {
536 // Defined in this interface
537 std::cerr << "ERROR: Redefinition of method '" << method->name() << "'";
538 } else if (definedInType->isIBase()) {
539 // Defined in IBase
540 std::cerr << "ERROR: Redefinition of reserved method '" << method->name() << "'";
541 } else {
542 // Defined in super not IBase
543 std::cerr << "ERROR: Redefinition of method '" << method->name()
544 << "'' defined in interface '" << definedInType->fullName() << "'";
545 }
546 std::cerr << " at " << method->location() << "\n";
547 return UNKNOWN_ERROR;
548 }
549
550 registeredMethodNames[method->name()] = this;
551 }
552
553 return OK;
554}
555
Yifan Hongffa91392017-01-31 13:41:23 -0800556bool Interface::addAllReservedMethods() {
557 // use a sorted map to insert them in serial ID order.
558 std::map<int32_t, Method *> reservedMethodsById;
559 for (const auto &pair : gAllReservedMethods) {
560 Method *method = pair.second->copySignature();
Steven Moreland424a9482017-02-13 19:20:40 -0800561 bool fillSuccess = fillPingMethod(method)
562 || fillDescriptorChainMethod(method)
Yifan Hongffa91392017-01-31 13:41:23 -0800563 || fillGetDescriptorMethod(method)
Yifan Hong30b5d1f2017-04-03 12:19:25 -0700564 || fillHashChainMethod(method)
Yifan Hongffa91392017-01-31 13:41:23 -0800565 || fillSyspropsChangedMethod(method)
566 || fillLinkToDeathMethod(method)
567 || fillUnlinkToDeathMethod(method)
Yifan Hongcd2ae452017-01-31 14:33:40 -0800568 || fillSetHALInstrumentationMethod(method)
Andreas Huber37065d62017-02-07 14:36:54 -0800569 || fillGetDebugInfoMethod(method)
570 || fillDebugMethod(method);
571
Yifan Hongffa91392017-01-31 13:41:23 -0800572 if (!fillSuccess) {
573 LOG(ERROR) << "ERROR: hidl-gen does not recognize a reserved method "
574 << method->name();
575 return false;
576 }
577 if (!reservedMethodsById.emplace(method->getSerialId(), method).second) {
578 LOG(ERROR) << "ERROR: hidl-gen uses duplicated serial id for "
579 << method->name() << " and "
580 << reservedMethodsById[method->getSerialId()]->name()
581 << ", serialId = " << method->getSerialId();
582 return false;
583 }
584 }
585 for (const auto &pair : reservedMethodsById) {
586 this->mReservedMethods.push_back(pair.second);
587 }
588 return true;
589}
Yifan Hong10fe0b52016-10-19 14:20:17 -0700590
Timur Iskhakov505316c2017-08-05 03:38:59 +0000591const Interface* Interface::superType() const {
Timur Iskhakov0344e612017-08-25 12:57:09 -0700592 if (isIBase()) return nullptr;
593 if (!mSuperType->isInterface()) {
594 // This is actually an error
595 // that would be caught in validate
596 return nullptr;
597 }
598 return static_cast<Interface*>(mSuperType.get());
Andreas Huberc9410c72016-07-28 12:18:40 -0700599}
600
Yifan Hong10fe0b52016-10-19 14:20:17 -0700601std::vector<const Interface *> Interface::typeChain() const {
602 std::vector<const Interface *> v;
603 const Interface *iface = this;
604 while (iface != nullptr) {
605 v.push_back(iface);
Timur Iskhakov505316c2017-08-05 03:38:59 +0000606 iface = iface->superType();
Yifan Hong10fe0b52016-10-19 14:20:17 -0700607 }
608 return v;
609}
610
Yifan Hongfe95aa22016-10-19 17:26:45 -0700611std::vector<const Interface *> Interface::superTypeChain() const {
Timur Iskhakov505316c2017-08-05 03:38:59 +0000612 return isIBase() ? std::vector<const Interface*>() : superType()->typeChain();
Yifan Hongfe95aa22016-10-19 17:26:45 -0700613}
614
Martijn Coenenb40ef022017-01-02 15:21:46 +0100615bool Interface::isElidableType() const {
616 return true;
617}
618
Andreas Hubera2723d22016-07-29 15:36:07 -0700619bool Interface::isInterface() const {
620 return true;
621}
622
Andreas Huber295ad302016-08-16 11:35:00 -0700623bool Interface::isBinder() const {
624 return true;
625}
626
Yifan Hong10fe0b52016-10-19 14:20:17 -0700627const std::vector<Method *> &Interface::userDefinedMethods() const {
628 return mUserMethods;
629}
630
631const std::vector<Method *> &Interface::hidlReservedMethods() const {
632 return mReservedMethods;
633}
634
635std::vector<Method *> Interface::methods() const {
636 std::vector<Method *> v(mUserMethods);
637 v.insert(v.end(), mReservedMethods.begin(), mReservedMethods.end());
638 return v;
639}
640
641std::vector<InterfaceAndMethod> Interface::allMethodsFromRoot() const {
642 std::vector<InterfaceAndMethod> v;
643 std::vector<const Interface *> chain = typeChain();
644 for (auto it = chain.rbegin(); it != chain.rend(); ++it) {
645 const Interface *iface = *it;
646 for (Method *userMethod : iface->userDefinedMethods()) {
647 v.push_back(InterfaceAndMethod(iface, userMethod));
648 }
649 }
650 for (Method *reservedMethod : hidlReservedMethods()) {
Yifan Hongc8934042016-11-17 17:10:52 -0800651 v.push_back(InterfaceAndMethod(
652 *chain.rbegin(), // IBase
653 reservedMethod));
Yifan Hong10fe0b52016-10-19 14:20:17 -0700654 }
655 return v;
Andreas Huber881227d2016-08-02 14:20:21 -0700656}
657
Timur Iskhakovf1b902d2017-08-13 20:14:31 -0700658std::vector<InterfaceAndMethod> Interface::allSuperMethodsFromRoot() const {
659 return isIBase() ? std::vector<InterfaceAndMethod>() : superType()->allMethodsFromRoot();
660}
661
Steven Moreland40786312016-08-16 10:29:40 -0700662std::string Interface::getBaseName() const {
Jayant Chowdhary3f32c1f2016-09-15 16:53:56 -0700663 return fqName().getInterfaceBaseName();
Steven Moreland40786312016-08-16 10:29:40 -0700664}
665
Yifan Hongeefe4f22017-01-04 15:32:42 -0800666std::string Interface::getProxyName() const {
667 return fqName().getInterfaceProxyName();
668}
669
670std::string Interface::getStubName() const {
671 return fqName().getInterfaceStubName();
672}
673
674std::string Interface::getHwName() const {
675 return fqName().getInterfaceHwName();
676}
677
678std::string Interface::getPassthroughName() const {
679 return fqName().getInterfacePassthroughName();
680}
681
Yifan Hong51a65092017-01-04 15:41:44 -0800682FQName Interface::getProxyFqName() const {
Yifan Hongeefe4f22017-01-04 15:32:42 -0800683 return fqName().getInterfaceProxyFqName();
Yifan Hong158655a2016-11-08 12:34:07 -0800684}
685
Yifan Hong51a65092017-01-04 15:41:44 -0800686FQName Interface::getStubFqName() const {
Yifan Hongeefe4f22017-01-04 15:32:42 -0800687 return fqName().getInterfaceStubFqName();
Yifan Hong158655a2016-11-08 12:34:07 -0800688}
689
Yifan Hong51a65092017-01-04 15:41:44 -0800690FQName Interface::getPassthroughFqName() const {
Yifan Hongeefe4f22017-01-04 15:32:42 -0800691 return fqName().getInterfacePassthroughFqName();
Yifan Hong158655a2016-11-08 12:34:07 -0800692}
693
Steven Moreland979e0992016-09-07 09:18:08 -0700694std::string Interface::getCppType(StorageMode mode,
Steven Moreland979e0992016-09-07 09:18:08 -0700695 bool specifyNamespaces) const {
Steven Moreland979e0992016-09-07 09:18:08 -0700696 const std::string base =
697 std::string(specifyNamespaces ? "::android::" : "")
698 + "sp<"
Steven Morelande30ee9b2017-05-09 13:31:01 -0700699 + fullName()
Steven Moreland979e0992016-09-07 09:18:08 -0700700 + ">";
Andreas Huber881227d2016-08-02 14:20:21 -0700701
702 switch (mode) {
703 case StorageMode_Stack:
704 case StorageMode_Result:
705 return base;
706
707 case StorageMode_Argument:
708 return "const " + base + "&";
709 }
710}
711
Yifan Hong4ed13472016-11-02 10:44:11 -0700712std::string Interface::getJavaType(bool /* forInitializer */) const {
Andreas Huber2831d512016-08-15 09:33:47 -0700713 return fullJavaName();
714}
715
Zhuoyao Zhanga588b232016-11-10 14:37:35 -0800716std::string Interface::getVtsType() const {
717 if (StringHelper::EndsWith(localName(), "Callback")) {
718 return "TYPE_HIDL_CALLBACK";
719 } else {
720 return "TYPE_HIDL_INTERFACE";
721 }
722}
723
Andreas Huber881227d2016-08-02 14:20:21 -0700724void Interface::emitReaderWriter(
725 Formatter &out,
726 const std::string &name,
727 const std::string &parcelObj,
728 bool parcelObjIsPointer,
729 bool isReader,
730 ErrorMode mode) const {
731 const std::string parcelObjDeref =
732 parcelObj + (parcelObjIsPointer ? "->" : ".");
733
734 if (isReader) {
Andreas Hubere7ff2282016-08-16 13:50:03 -0700735 out << "{\n";
736 out.indent();
737
Iliyan Malchev549e2592016-08-10 08:59:12 -0700738 const std::string binderName = "_hidl_" + name + "_binder";
Andreas Huber881227d2016-08-02 14:20:21 -0700739
Andreas Huber8a82ff72016-08-04 10:29:39 -0700740 out << "::android::sp<::android::hardware::IBinder> "
Andreas Huber881227d2016-08-02 14:20:21 -0700741 << binderName << ";\n";
742
Iliyan Malchev549e2592016-08-10 08:59:12 -0700743 out << "_hidl_err = ";
Andreas Huber881227d2016-08-02 14:20:21 -0700744 out << parcelObjDeref
745 << "readNullableStrongBinder(&"
746 << binderName
747 << ");\n";
748
749 handleError(out, mode);
750
751 out << name
752 << " = "
Martijn Coenena63e0ad2016-12-07 17:29:00 +0100753 << "::android::hardware::fromBinder<"
754 << fqName().cppName()
755 << ","
Yifan Hong51a65092017-01-04 15:41:44 -0800756 << getProxyFqName().cppName()
Martijn Coenena63e0ad2016-12-07 17:29:00 +0100757 << ","
Yifan Hong51a65092017-01-04 15:41:44 -0800758 << getStubFqName().cppName()
Martijn Coenena63e0ad2016-12-07 17:29:00 +0100759 << ">("
Andreas Huber881227d2016-08-02 14:20:21 -0700760 << binderName
761 << ");\n";
Andreas Hubere7ff2282016-08-16 13:50:03 -0700762
763 out.unindent();
764 out << "}\n\n";
Andreas Huber881227d2016-08-02 14:20:21 -0700765 } else {
Martijn Coenene1638232016-10-26 12:51:34 +0200766 out << "if (" << name << " == nullptr) {\n";
767 out.indent();
768 out << "_hidl_err = ";
769 out << parcelObjDeref
770 << "writeStrongBinder(nullptr);\n";
771 out.unindent();
772 out << "} else {\n";
773 out.indent();
Yifan Hong158655a2016-11-08 12:34:07 -0800774 out << "::android::sp<::android::hardware::IBinder> _hidl_binder = "
775 << "::android::hardware::toBinder<\n";
Yifan Hong33223ca2016-12-13 15:07:35 -0800776 out.indent(2, [&] {
Martijn Coenena63e0ad2016-12-07 17:29:00 +0100777 out << fqName().cppName()
Yifan Hong158655a2016-11-08 12:34:07 -0800778 << ">("
779 << name
780 << ");\n";
781 });
782 out << "if (_hidl_binder.get() != nullptr) {\n";
Yifan Hong33223ca2016-12-13 15:07:35 -0800783 out.indent([&] {
Yifan Hong158655a2016-11-08 12:34:07 -0800784 out << "_hidl_err = "
785 << parcelObjDeref
786 << "writeStrongBinder(_hidl_binder);\n";
787 });
788 out << "} else {\n";
Yifan Hong33223ca2016-12-13 15:07:35 -0800789 out.indent([&] {
Yifan Hong158655a2016-11-08 12:34:07 -0800790 out << "_hidl_err = ::android::UNKNOWN_ERROR;\n";
791 });
792 out << "}\n";
Martijn Coenene1638232016-10-26 12:51:34 +0200793 out.unindent();
794 out << "}\n";
Steven Moreland40786312016-08-16 10:29:40 -0700795
Andreas Huber881227d2016-08-02 14:20:21 -0700796 handleError(out, mode);
797 }
798}
799
Yifan Hongf5cc2f72017-01-04 18:02:34 -0800800status_t Interface::emitGlobalTypeDeclarations(Formatter &out) const {
801 status_t status = Scope::emitGlobalTypeDeclarations(out);
802 if (status != OK) {
803 return status;
804 }
Steven Moreland3d98bc42017-06-23 21:36:41 +0000805 out << "std::string toString("
Yifan Hongf5cc2f72017-01-04 18:02:34 -0800806 << getCppArgumentType()
Steven Moreland3d98bc42017-06-23 21:36:41 +0000807 << ");\n";
Yifan Hongf5cc2f72017-01-04 18:02:34 -0800808 return OK;
809}
810
Chih-Hung Hsieh8c90cc52017-08-03 14:51:13 -0700811status_t Interface::emitTypeDefinitions(Formatter& out, const std::string& prefix) const {
Yifan Hongf5cc2f72017-01-04 18:02:34 -0800812 std::string space = prefix.empty() ? "" : (prefix + "::");
813 status_t err = Scope::emitTypeDefinitions(out, space + localName());
814 if (err != OK) {
815 return err;
816 }
817
Steven Moreland3d98bc42017-06-23 21:36:41 +0000818 out << "std::string toString("
819 << getCppArgumentType()
820 << " o) ";
821
822 out.block([&] {
823 out << "std::string os = \"[class or subclass of \";\n"
824 << "os += " << fullName() << "::descriptor;\n"
825 << "os += \"]\";\n"
826 << "os += o->isRemote() ? \"@remote\" : \"@local\";\n"
827 << "return os;\n";
828 }).endl().endl();
829
Yifan Hongf5cc2f72017-01-04 18:02:34 -0800830 return OK;
831}
832
Andreas Huber2831d512016-08-15 09:33:47 -0700833void Interface::emitJavaReaderWriter(
834 Formatter &out,
835 const std::string &parcelObj,
836 const std::string &argName,
837 bool isReader) const {
838 if (isReader) {
839 out << fullJavaName()
840 << ".asInterface("
841 << parcelObj
842 << ".readStrongBinder());\n";
843 } else {
844 out << parcelObj
845 << ".writeStrongBinder("
846 << argName
847 << " == null ? null : "
848 << argName
849 << ".asBinder());\n";
850 }
851}
852
Zhuoyao Zhang864c7712016-08-16 15:35:28 -0700853status_t Interface::emitVtsAttributeDeclaration(Formatter &out) const {
854 for (const auto &type : getSubTypes()) {
Zhuoyao Zhangc5ea9f52016-10-06 15:05:39 -0700855 // Skip for TypeDef as it is just an alias of a defined type.
856 if (type->isTypeDef()) {
857 continue;
858 }
Zhuoyao Zhang864c7712016-08-16 15:35:28 -0700859 out << "attribute: {\n";
860 out.indent();
861 status_t status = type->emitVtsTypeDeclarations(out);
862 if (status != OK) {
863 return status;
864 }
865 out.unindent();
866 out << "}\n\n";
867 }
868 return OK;
869}
870
871status_t Interface::emitVtsMethodDeclaration(Formatter &out) const {
Yifan Hong10fe0b52016-10-19 14:20:17 -0700872 for (const auto &method : methods()) {
Steven Morelandcea24782016-11-07 11:40:48 -0800873 if (method->isHidlReserved()) {
874 continue;
875 }
876
Zhuoyao Zhang864c7712016-08-16 15:35:28 -0700877 out << "api: {\n";
878 out.indent();
879 out << "name: \"" << method->name() << "\"\n";
880 // Generate declaration for each return value.
881 for (const auto &result : method->results()) {
882 out << "return_type_hidl: {\n";
883 out.indent();
884 status_t status = result->type().emitVtsAttributeType(out);
885 if (status != OK) {
886 return status;
887 }
888 out.unindent();
889 out << "}\n";
890 }
891 // Generate declaration for each input argument
892 for (const auto &arg : method->args()) {
893 out << "arg: {\n";
894 out.indent();
895 status_t status = arg->type().emitVtsAttributeType(out);
896 if (status != OK) {
897 return status;
898 }
899 out.unindent();
900 out << "}\n";
901 }
902 // Generate declaration for each annotation.
Steven Morelandd537ab02016-09-12 10:32:01 -0700903 for (const auto &annotation : method->annotations()) {
Zhuoyao Zhang864c7712016-08-16 15:35:28 -0700904 out << "callflow: {\n";
905 out.indent();
Steven Morelandd537ab02016-09-12 10:32:01 -0700906 std::string name = annotation->name();
Zhuoyao Zhang864c7712016-08-16 15:35:28 -0700907 if (name == "entry") {
908 out << "entry: true\n";
909 } else if (name == "exit") {
910 out << "exit: true\n";
911 } else if (name == "callflow") {
Steven Morelandd537ab02016-09-12 10:32:01 -0700912 const AnnotationParam *param =
913 annotation->getParam("next");
914 if (param != nullptr) {
Timur Iskhakov7a85dc22017-08-10 19:06:41 -0700915 for (const auto& value : param->getValues()) {
Steven Morelandd537ab02016-09-12 10:32:01 -0700916 out << "next: " << value << "\n";
917 }
Zhuoyao Zhang864c7712016-08-16 15:35:28 -0700918 }
919 } else {
Keun Soo Yima5a57e92017-02-04 11:32:06 -0800920 std::cerr << "Unrecognized annotation '"
Zhuoyao Zhang864c7712016-08-16 15:35:28 -0700921 << name << "' for method: " << method->name()
Keun Soo Yima5a57e92017-02-04 11:32:06 -0800922 << ". A VTS annotation should be one of: "
923 << "entry, exit, callflow. \n";
Zhuoyao Zhang864c7712016-08-16 15:35:28 -0700924 }
925 out.unindent();
926 out << "}\n";
927 }
928 out.unindent();
929 out << "}\n\n";
930 }
931 return OK;
932}
933
934status_t Interface::emitVtsAttributeType(Formatter &out) const {
Zhuoyao Zhanga588b232016-11-10 14:37:35 -0800935 out << "type: " << getVtsType() << "\n"
Zhuoyao Zhang5158db42016-08-10 10:25:20 -0700936 << "predefined_type: \""
Zhuoyao Zhangc4e10602017-01-27 16:48:05 -0800937 << fullName()
938 << "\"\n";
Zhuoyao Zhang5158db42016-08-10 10:25:20 -0700939 return OK;
940}
941
Steven Moreland69e7c702016-09-09 11:16:32 -0700942bool Interface::hasOnewayMethods() const {
Yifan Hong10fe0b52016-10-19 14:20:17 -0700943 for (auto const &method : methods()) {
Steven Moreland69e7c702016-09-09 11:16:32 -0700944 if (method->isOneway()) {
945 return true;
946 }
947 }
948
949 const Interface* superClass = superType();
950
951 if (superClass != nullptr) {
952 return superClass->hasOnewayMethods();
953 }
954
955 return false;
956}
957
Andreas Huber70a59e12016-08-16 12:57:01 -0700958bool Interface::isJavaCompatible() const {
Andreas Huberea081b32016-08-17 15:57:47 -0700959 if (mIsJavaCompatibleInProgress) {
960 // We're currently trying to determine if this Interface is
961 // java-compatible and something is referencing this interface through
962 // one of its methods. Assume we'll ultimately succeed, if we were wrong
963 // the original invocation of Interface::isJavaCompatible() will then
964 // return the correct "false" result.
965 return true;
966 }
967
Timur Iskhakov505316c2017-08-05 03:38:59 +0000968 if (superType() != nullptr && !superType()->isJavaCompatible()) {
Andreas Huber0fa9e392016-08-31 09:05:44 -0700969 mIsJavaCompatibleInProgress = false;
970 return false;
971 }
972
Andreas Huberea081b32016-08-17 15:57:47 -0700973 mIsJavaCompatibleInProgress = true;
974
Andreas Huber70a59e12016-08-16 12:57:01 -0700975 if (!Scope::isJavaCompatible()) {
Andreas Huberea081b32016-08-17 15:57:47 -0700976 mIsJavaCompatibleInProgress = false;
Andreas Huber70a59e12016-08-16 12:57:01 -0700977 return false;
978 }
979
Yifan Hong10fe0b52016-10-19 14:20:17 -0700980 for (const auto &method : methods()) {
Andreas Huber70a59e12016-08-16 12:57:01 -0700981 if (!method->isJavaCompatible()) {
Andreas Huberea081b32016-08-17 15:57:47 -0700982 mIsJavaCompatibleInProgress = false;
Andreas Huber70a59e12016-08-16 12:57:01 -0700983 return false;
984 }
985 }
986
Andreas Huberea081b32016-08-17 15:57:47 -0700987 mIsJavaCompatibleInProgress = false;
988
Andreas Huber70a59e12016-08-16 12:57:01 -0700989 return true;
990}
991
Andreas Huberc9410c72016-07-28 12:18:40 -0700992} // namespace android
993