blob: db5d682b02fab7ab976f468edb51c62d15be7b12 [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>
33
Steven Moreland14ee6742016-10-18 12:58:28 -070034#include <android-base/logging.h>
Steven Moreland5bdfa702017-04-18 23:20:39 -070035#include <hidl-hash/Hash.h>
Iliyan Malcheva72e0d22016-09-09 11:03:08 -070036#include <hidl-util/Formatter.h>
Yifan Hong10fe0b52016-10-19 14:20:17 -070037#include <hidl-util/StringHelper.h>
Zhuoyao Zhang864c7712016-08-16 15:35:28 -070038
Andreas Huberc9410c72016-07-28 12:18:40 -070039namespace android {
40
Steven Morelandb8e15a52017-02-13 19:35:40 -080041#define B_PACK_CHARS(c1, c2, c3, c4) \
42 ((((c1)<<24)) | (((c2)<<16)) | (((c3)<<8)) | (c4))
43
Yifan Hong10fe0b52016-10-19 14:20:17 -070044/* It is very important that these values NEVER change. These values
45 * must remain unchanged over the lifetime of android. This is
46 * because the framework on a device will be updated independently of
47 * the hals on a device. If the hals are compiled with one set of
48 * transaction values, and the framework with another, then the
49 * interface between them will be destroyed, and the device will not
50 * work.
51 */
52enum {
Yifan Hong10fe0b52016-10-19 14:20:17 -070053 /////////////////// User defined transactions
54 FIRST_CALL_TRANSACTION = 0x00000001,
Steven Morelandb8e15a52017-02-13 19:35:40 -080055 LAST_CALL_TRANSACTION = 0x0effffff,
Yifan Hong10fe0b52016-10-19 14:20:17 -070056 /////////////////// HIDL reserved
Steven Morelandb8e15a52017-02-13 19:35:40 -080057 FIRST_HIDL_TRANSACTION = 0x0f000000,
58 HIDL_PING_TRANSACTION = B_PACK_CHARS(0x0f, 'P', 'N', 'G'),
59 HIDL_DESCRIPTOR_CHAIN_TRANSACTION = B_PACK_CHARS(0x0f, 'C', 'H', 'N'),
60 HIDL_GET_DESCRIPTOR_TRANSACTION = B_PACK_CHARS(0x0f, 'D', 'S', 'C'),
61 HIDL_SYSPROPS_CHANGED_TRANSACTION = B_PACK_CHARS(0x0f, 'S', 'Y', 'S'),
62 HIDL_LINK_TO_DEATH_TRANSACTION = B_PACK_CHARS(0x0f, 'L', 'T', 'D'),
63 HIDL_UNLINK_TO_DEATH_TRANSACTION = B_PACK_CHARS(0x0f, 'U', 'T', 'D'),
64 HIDL_SET_HAL_INSTRUMENTATION_TRANSACTION = B_PACK_CHARS(0x0f, 'I', 'N', 'T'),
65 HIDL_GET_REF_INFO_TRANSACTION = B_PACK_CHARS(0x0f, 'R', 'E', 'F'),
66 HIDL_DEBUG_TRANSACTION = B_PACK_CHARS(0x0f, 'D', 'B', 'G'),
Yifan Hong30b5d1f2017-04-03 12:19:25 -070067 HIDL_HASH_CHAIN_TRANSACTION = B_PACK_CHARS(0x0f, 'H', 'S', 'H'),
Steven Morelandb8e15a52017-02-13 19:35:40 -080068 LAST_HIDL_TRANSACTION = 0x0fffffff,
Yifan Hong10fe0b52016-10-19 14:20:17 -070069};
70
Timur Iskhakovcb0ba522017-07-17 20:01:37 -070071Interface::Interface(const char* localName, const Location& location, Scope* parent,
Timur Iskhakov505316c2017-08-05 03:38:59 +000072 const Reference<Interface>& superType)
73 : Scope(localName, location, parent),
74 mSuperType(superType),
75 mIsJavaCompatibleInProgress(false) {}
Martijn Coenenaf712c02016-11-16 15:26:27 +010076
Steven Moreland30bb6a82016-11-30 09:18:34 -080077std::string Interface::typeName() const {
78 return "interface " + localName();
79}
80
Steven Moreland424a9482017-02-13 19:20:40 -080081bool Interface::fillPingMethod(Method *method) const {
82 if (method->name() != "ping") {
83 return false;
84 }
85
86 method->fillImplementation(
87 HIDL_PING_TRANSACTION,
88 {
Steven Moreland937408a2017-03-20 09:54:18 -070089 {IMPL_INTERFACE,
Steven Moreland424a9482017-02-13 19:20:40 -080090 [](auto &out) {
91 out << "return ::android::hardware::Void();\n";
92 }
93 },
94 {IMPL_STUB_IMPL,
95 [](auto &out) {
96 out << "return ::android::hardware::Void();\n";
97 }
98 }
99 }, /*cppImpl*/
100 {
Steven Moreland937408a2017-03-20 09:54:18 -0700101 {IMPL_INTERFACE,
Yi Kongc8ff4672017-04-30 23:46:56 -0700102 [](auto &out) {
Steven Moreland424a9482017-02-13 19:20:40 -0800103 out << "return;\n";
104 }
105 },
106 {IMPL_STUB, nullptr /* don't generate code */}
107 } /*javaImpl*/
108 );
109
110 return true;
111}
112
Yifan Hongffa91392017-01-31 13:41:23 -0800113bool Interface::fillLinkToDeathMethod(Method *method) const {
114 if (method->name() != "linkToDeath") {
115 return false;
116 }
Martijn Coenen115d4282016-12-19 05:14:04 +0100117
Yifan Hongffa91392017-01-31 13:41:23 -0800118 method->fillImplementation(
Martijn Coenen115d4282016-12-19 05:14:04 +0100119 HIDL_LINK_TO_DEATH_TRANSACTION,
120 {
Steven Moreland937408a2017-03-20 09:54:18 -0700121 {IMPL_INTERFACE,
Martijn Coenen115d4282016-12-19 05:14:04 +0100122 [](auto &out) {
123 out << "(void)cookie;\n"
124 << "return (recipient != nullptr);\n";
125 }
126 },
127 {IMPL_PROXY,
128 [](auto &out) {
Martijn Coenenfa55d6e2016-12-20 06:08:31 +0100129 out << "::android::hardware::ProcessState::self()->startThreadPool();\n";
Martijn Coenen115d4282016-12-19 05:14:04 +0100130 out << "::android::hardware::hidl_binder_death_recipient *binder_recipient"
131 << " = new ::android::hardware::hidl_binder_death_recipient(recipient, cookie, this);\n"
132 << "std::unique_lock<std::mutex> lock(_hidl_mMutex);\n"
133 << "_hidl_mDeathRecipients.push_back(binder_recipient);\n"
134 << "return (remote()->linkToDeath(binder_recipient)"
135 << " == ::android::OK);\n";
136 }
137 },
Martijn Coenen8d12b502016-12-27 14:30:27 +0100138 {IMPL_STUB, nullptr}
Martijn Coenen115d4282016-12-19 05:14:04 +0100139 }, /*cppImpl*/
140 {
Steven Moreland937408a2017-03-20 09:54:18 -0700141 {IMPL_INTERFACE,
Yi Kongc8ff4672017-04-30 23:46:56 -0700142 [](auto &out) {
Martijn Coenen115d4282016-12-19 05:14:04 +0100143 out << "return true;";
144 }
145 },
146 {IMPL_PROXY,
Yi Kongc8ff4672017-04-30 23:46:56 -0700147 [](auto &out) {
Martijn Coenen8d12b502016-12-27 14:30:27 +0100148 out << "return mRemote.linkToDeath(recipient, cookie);\n";
Martijn Coenen115d4282016-12-19 05:14:04 +0100149 }
150 },
Martijn Coenen8d12b502016-12-27 14:30:27 +0100151 {IMPL_STUB, nullptr}
Martijn Coenen115d4282016-12-19 05:14:04 +0100152 } /*javaImpl*/
153 );
Yifan Hongffa91392017-01-31 13:41:23 -0800154 return true;
Martijn Coenen115d4282016-12-19 05:14:04 +0100155}
156
Yifan Hongffa91392017-01-31 13:41:23 -0800157bool Interface::fillUnlinkToDeathMethod(Method *method) const {
158 if (method->name() != "unlinkToDeath") {
159 return false;
160 }
Martijn Coenen115d4282016-12-19 05:14:04 +0100161
Yifan Hongffa91392017-01-31 13:41:23 -0800162 method->fillImplementation(
Martijn Coenen115d4282016-12-19 05:14:04 +0100163 HIDL_UNLINK_TO_DEATH_TRANSACTION,
164 {
Steven Moreland937408a2017-03-20 09:54:18 -0700165 {IMPL_INTERFACE,
Martijn Coenen115d4282016-12-19 05:14:04 +0100166 [](auto &out) {
167 out << "return (recipient != nullptr);\n";
168 }
169 },
170 {IMPL_PROXY,
171 [](auto &out) {
172 out << "std::unique_lock<std::mutex> lock(_hidl_mMutex);\n"
173 << "for (auto it = _hidl_mDeathRecipients.begin();"
174 << "it != _hidl_mDeathRecipients.end();"
175 << "++it) {\n";
176 out.indent([&] {
177 out.sIf("(*it)->getRecipient() == recipient", [&] {
178 out << "::android::status_t status = remote()->unlinkToDeath(*it);\n"
179 << "_hidl_mDeathRecipients.erase(it);\n"
180 << "return status == ::android::OK;\n";
181 });
182 });
183 out << "}\n";
184 out << "return false;\n";
185 }
186 },
Martijn Coenen8d12b502016-12-27 14:30:27 +0100187 {IMPL_STUB, nullptr /* don't generate code */}
Martijn Coenen115d4282016-12-19 05:14:04 +0100188 }, /*cppImpl*/
189 {
Steven Moreland937408a2017-03-20 09:54:18 -0700190 {IMPL_INTERFACE,
Yi Kongc8ff4672017-04-30 23:46:56 -0700191 [](auto &out) {
Martijn Coenen8d12b502016-12-27 14:30:27 +0100192 out << "return true;\n";
Martijn Coenen115d4282016-12-19 05:14:04 +0100193 }
194 },
195 {IMPL_PROXY,
Yi Kongc8ff4672017-04-30 23:46:56 -0700196 [](auto &out) {
Martijn Coenen8d12b502016-12-27 14:30:27 +0100197 out << "return mRemote.unlinkToDeath(recipient);\n";
Martijn Coenen115d4282016-12-19 05:14:04 +0100198 }
199 },
Martijn Coenen8d12b502016-12-27 14:30:27 +0100200 {IMPL_STUB, nullptr /* don't generate code */}
Martijn Coenen115d4282016-12-19 05:14:04 +0100201 } /*javaImpl*/
202 );
Yifan Hongffa91392017-01-31 13:41:23 -0800203 return true;
Martijn Coenen115d4282016-12-19 05:14:04 +0100204}
Yifan Hongffa91392017-01-31 13:41:23 -0800205bool Interface::fillSyspropsChangedMethod(Method *method) const {
206 if (method->name() != "notifySyspropsChanged") {
207 return false;
208 }
209
210 method->fillImplementation(
Martijn Coenenaf712c02016-11-16 15:26:27 +0100211 HIDL_SYSPROPS_CHANGED_TRANSACTION,
Yi Kongc8ff4672017-04-30 23:46:56 -0700212 { { IMPL_INTERFACE, [](auto &out) {
Martijn Coenenaf712c02016-11-16 15:26:27 +0100213 out << "::android::report_sysprop_change();\n";
214 out << "return ::android::hardware::Void();";
Martijn Coenen115d4282016-12-19 05:14:04 +0100215 } } }, /*cppImpl */
Steven Moreland937408a2017-03-20 09:54:18 -0700216 { { IMPL_INTERFACE, [](auto &out) { /* javaImpl */
Sundong Ahnc1432c92017-07-13 23:58:27 +0900217 out << "android.os.HwBinder.reportSyspropChanged();";
Martijn Coenen115d4282016-12-19 05:14:04 +0100218 } } } /*javaImpl */
Martijn Coenenaf712c02016-11-16 15:26:27 +0100219 );
Yifan Hongffa91392017-01-31 13:41:23 -0800220 return true;
Andreas Huberc9410c72016-07-28 12:18:40 -0700221}
222
Yifan Hongffa91392017-01-31 13:41:23 -0800223bool Interface::fillSetHALInstrumentationMethod(Method *method) const {
224 if (method->name() != "setHALInstrumentation") {
225 return false;
226 }
227
228 method->fillImplementation(
Zhuoyao Zhangdd85c5c2017-01-03 17:30:24 -0800229 HIDL_SET_HAL_INSTRUMENTATION_TRANSACTION,
230 {
Steven Moreland937408a2017-03-20 09:54:18 -0700231 {IMPL_INTERFACE,
Yi Kongc8ff4672017-04-30 23:46:56 -0700232 [](auto &out) {
Zhuoyao Zhangdd85c5c2017-01-03 17:30:24 -0800233 // do nothing for base class.
234 out << "return ::android::hardware::Void();\n";
235 }
236 },
Zhuoyao Zhangdd85c5c2017-01-03 17:30:24 -0800237 {IMPL_STUB,
238 [](auto &out) {
239 out << "configureInstrumentation();\n";
240 }
241 },
242 {IMPL_PASSTHROUGH,
243 [](auto &out) {
244 out << "configureInstrumentation();\n";
245 out << "return ::android::hardware::Void();\n";
246 }
247 },
248 }, /*cppImpl */
Steven Moreland937408a2017-03-20 09:54:18 -0700249 { { IMPL_INTERFACE, [](auto & /*out*/) { /* javaImpl */
Zhuoyao Zhangdd85c5c2017-01-03 17:30:24 -0800250 // Not support for Java Impl for now.
251 } } } /*javaImpl */
252 );
Yifan Hongffa91392017-01-31 13:41:23 -0800253 return true;
Zhuoyao Zhangdd85c5c2017-01-03 17:30:24 -0800254}
255
Yifan Hongffa91392017-01-31 13:41:23 -0800256bool Interface::fillDescriptorChainMethod(Method *method) const {
257 if (method->name() != "interfaceChain") {
258 return false;
259 }
Yifan Hong10fe0b52016-10-19 14:20:17 -0700260
Yifan Hongffa91392017-01-31 13:41:23 -0800261 method->fillImplementation(
Yifan Hong10fe0b52016-10-19 14:20:17 -0700262 HIDL_DESCRIPTOR_CHAIN_TRANSACTION,
Steven Moreland937408a2017-03-20 09:54:18 -0700263 { { IMPL_INTERFACE, [this](auto &out) {
Yifan Hong10fe0b52016-10-19 14:20:17 -0700264 std::vector<const Interface *> chain = typeChain();
Yifan Hong03935122016-12-19 11:10:40 -0800265 out << "_hidl_cb(";
266 out.block([&] {
267 for (const Interface *iface : chain) {
268 out << iface->fullName() << "::descriptor,\n";
269 }
270 });
271 out << ");\n";
Yifan Hong10fe0b52016-10-19 14:20:17 -0700272 out << "return ::android::hardware::Void();";
Martijn Coenen115d4282016-12-19 05:14:04 +0100273 } } }, /* cppImpl */
Steven Moreland937408a2017-03-20 09:54:18 -0700274 { { IMPL_INTERFACE, [this](auto &out) {
Yifan Hong10fe0b52016-10-19 14:20:17 -0700275 std::vector<const Interface *> chain = typeChain();
Yifan Hong1af73532016-11-09 14:32:58 -0800276 out << "return new java.util.ArrayList<String>(java.util.Arrays.asList(\n";
Yifan Hong10fe0b52016-10-19 14:20:17 -0700277 out.indent(); out.indent();
278 for (size_t i = 0; i < chain.size(); ++i) {
279 if (i != 0)
280 out << ",\n";
Steven Morelandd39133b2016-11-11 12:30:08 -0800281 out << chain[i]->fullJavaName() << ".kInterfaceName";
Yifan Hong10fe0b52016-10-19 14:20:17 -0700282 }
283 out << "));";
284 out.unindent(); out.unindent();
Yifan Hongffa91392017-01-31 13:41:23 -0800285 } } } /* javaImpl */
Martijn Coenen115d4282016-12-19 05:14:04 +0100286 );
Yifan Hongffa91392017-01-31 13:41:23 -0800287 return true;
Yifan Hong10fe0b52016-10-19 14:20:17 -0700288}
289
Yifan Hong30b5d1f2017-04-03 12:19:25 -0700290static void emitDigestChain(
Timur Iskhakov7296af12017-08-09 21:52:48 +0000291 Formatter& out, const std::string& prefix, const std::vector<const Interface*>& chain,
292 std::function<std::string(std::unique_ptr<ConstantExpression>)> byteToString) {
Yifan Hong30b5d1f2017-04-03 12:19:25 -0700293 out.join(chain.begin(), chain.end(), ",\n", [&] (const auto &iface) {
Steven Moreland0e4be1e2017-04-18 19:50:29 -0700294 const Hash &hash = Hash::getHash(iface->location().begin().filename());
Yifan Hong30b5d1f2017-04-03 12:19:25 -0700295 out << prefix;
296 out << "{";
Steven Moreland0e4be1e2017-04-18 19:50:29 -0700297 out.join(hash.raw().begin(), hash.raw().end(), ",", [&](const auto &e) {
Yifan Hong30b5d1f2017-04-03 12:19:25 -0700298 // Use ConstantExpression::cppValue / javaValue
299 // because Java used signed byte for uint8_t.
300 out << byteToString(ConstantExpression::ValueOf(ScalarType::Kind::KIND_UINT8, e));
301 });
302 out << "} /* ";
Steven Moreland0e4be1e2017-04-18 19:50:29 -0700303 out << hash.hexString();
Yifan Hong30b5d1f2017-04-03 12:19:25 -0700304 out << " */";
305 });
306}
307
308bool Interface::fillHashChainMethod(Method *method) const {
309 if (method->name() != "getHashChain") {
310 return false;
311 }
312 const VectorType *chainType = static_cast<const VectorType *>(&method->results()[0]->type());
313 const ArrayType *digestType = static_cast<const ArrayType *>(chainType->getElementType());
314
315 method->fillImplementation(
316 HIDL_HASH_CHAIN_TRANSACTION,
317 { { IMPL_INTERFACE, [this, digestType](auto &out) {
318 std::vector<const Interface *> chain = typeChain();
319 out << "_hidl_cb(";
320 out.block([&] {
Timur Iskhakov7296af12017-08-09 21:52:48 +0000321 emitDigestChain(out, "(" + digestType->getInternalDataCppType() + ")", chain,
322 [](const auto& e) { return e->cppValue(); });
Yifan Hong30b5d1f2017-04-03 12:19:25 -0700323 });
324 out << ");\n";
325 out << "return ::android::hardware::Void();\n";
326 } } }, /* cppImpl */
327 { { IMPL_INTERFACE, [this, digestType, chainType](auto &out) {
328 std::vector<const Interface *> chain = typeChain();
329 out << "return new "
330 << chainType->getJavaType(false /* forInitializer */)
331 << "(java.util.Arrays.asList(\n";
332 out.indent(2, [&] {
333 // No need for dimensions when elements are explicitly provided.
334 emitDigestChain(out, "new " + digestType->getJavaType(false /* forInitializer */),
Timur Iskhakov7296af12017-08-09 21:52:48 +0000335 chain, [](const auto& e) { return e->javaValue(); });
Yifan Hong30b5d1f2017-04-03 12:19:25 -0700336 });
337 out << "));\n";
338 } } } /* javaImpl */
339 );
340 return true;
341}
342
Yifan Hongffa91392017-01-31 13:41:23 -0800343bool Interface::fillGetDescriptorMethod(Method *method) const {
344 if (method->name() != "interfaceDescriptor") {
345 return false;
346 }
Yifan Hongc75fd472017-01-11 12:37:31 -0800347
Yifan Hongffa91392017-01-31 13:41:23 -0800348 method->fillImplementation(
Yifan Hongc75fd472017-01-11 12:37:31 -0800349 HIDL_GET_DESCRIPTOR_TRANSACTION,
Steven Moreland937408a2017-03-20 09:54:18 -0700350 { { IMPL_INTERFACE, [this](auto &out) {
Yifan Hongc75fd472017-01-11 12:37:31 -0800351 out << "_hidl_cb("
352 << fullName()
353 << "::descriptor);\n"
354 << "return ::android::hardware::Void();";
355 } } }, /* cppImpl */
Steven Moreland937408a2017-03-20 09:54:18 -0700356 { { IMPL_INTERFACE, [this](auto &out) {
Yifan Hongc75fd472017-01-11 12:37:31 -0800357 out << "return "
358 << fullJavaName()
359 << ".kInterfaceName;\n";
Yifan Hongffa91392017-01-31 13:41:23 -0800360 } } } /* javaImpl */
Yifan Hongc75fd472017-01-11 12:37:31 -0800361 );
Yifan Hongffa91392017-01-31 13:41:23 -0800362 return true;
Yifan Hongc75fd472017-01-11 12:37:31 -0800363}
Yifan Hong10fe0b52016-10-19 14:20:17 -0700364
Yifan Hongbcffce22017-02-01 15:52:06 -0800365bool Interface::fillGetDebugInfoMethod(Method *method) const {
366 if (method->name() != "getDebugInfo") {
Yifan Hongcd2ae452017-01-31 14:33:40 -0800367 return false;
368 }
369
Yifan Hongdf1ea3f2017-03-02 17:02:10 -0800370 static const std::string sArch =
371 "#if defined(__LP64__)\n"
372 "::android::hidl::base::V1_0::DebugInfo::Architecture::IS_64BIT\n"
373 "#else\n"
374 "::android::hidl::base::V1_0::DebugInfo::Architecture::IS_32BIT\n"
375 "#endif\n";
376
Yifan Hongcd2ae452017-01-31 14:33:40 -0800377 method->fillImplementation(
378 HIDL_GET_REF_INFO_TRANSACTION,
379 {
Steven Moreland937408a2017-03-20 09:54:18 -0700380 {IMPL_INTERFACE,
Yi Kongc8ff4672017-04-30 23:46:56 -0700381 [](auto &out) {
Yifan Hongbcffce22017-02-01 15:52:06 -0800382 // getDebugInfo returns N/A for local objects.
Yifan Hongdf1ea3f2017-03-02 17:02:10 -0800383 out << "_hidl_cb({ -1 /* pid */, 0 /* ptr */, \n"
384 << sArch
385 << "});\n"
Yifan Hongcd2ae452017-01-31 14:33:40 -0800386 << "return ::android::hardware::Void();";
387 }
388 },
389 {IMPL_STUB_IMPL,
Yi Kongc8ff4672017-04-30 23:46:56 -0700390 [](auto &out) {
Yifan Hong2e036c92017-03-07 13:18:12 -0800391 out << "_hidl_cb(";
392 out.block([&] {
393 out << "::android::hardware::details::debuggable()"
394 << "? getpid() : -1 /* pid */,\n"
395 << "::android::hardware::details::debuggable()"
396 << "? reinterpret_cast<uint64_t>(this) : 0 /* ptr */,\n"
397 << sArch << "\n";
398 });
399 out << ");\n"
Yifan Hongcd2ae452017-01-31 14:33:40 -0800400 << "return ::android::hardware::Void();";
401 }
402 }
403 }, /* cppImpl */
Yi Kongc8ff4672017-04-30 23:46:56 -0700404 { { IMPL_INTERFACE, [method](auto &out) {
Yifan Hongcd2ae452017-01-31 14:33:40 -0800405 const Type &refInfo = method->results().front()->type();
406 out << refInfo.getJavaType(false /* forInitializer */) << " info = new "
407 << refInfo.getJavaType(true /* forInitializer */) << "();\n"
Yifan Hongbcffce22017-02-01 15:52:06 -0800408 // TODO(b/34777099): PID for java.
409 << "info.pid = -1;\n"
410 << "info.ptr = 0;\n"
Yifan Hongdf1ea3f2017-03-02 17:02:10 -0800411 << "info.arch = android.hidl.base.V1_0.DebugInfo.Architecture.UNKNOWN;"
Yifan Hongcd2ae452017-01-31 14:33:40 -0800412 << "return info;";
413 } } } /* javaImpl */
414 );
415
416 return true;
417}
418
Andreas Huber37065d62017-02-07 14:36:54 -0800419bool Interface::fillDebugMethod(Method *method) const {
420 if (method->name() != "debug") {
421 return false;
422 }
423
424 method->fillImplementation(
425 HIDL_DEBUG_TRANSACTION,
426 {
Steven Moreland937408a2017-03-20 09:54:18 -0700427 {IMPL_INTERFACE,
Yi Kongc8ff4672017-04-30 23:46:56 -0700428 [](auto &out) {
Andreas Huber37065d62017-02-07 14:36:54 -0800429 out << "(void)fd;\n"
430 << "(void)options;\n"
431 << "return ::android::hardware::Void();";
432 }
433 },
434 }, /* cppImpl */
435 {
436 /* unused, as the debug method is hidden from Java */
437 } /* javaImpl */
438 );
439
440 return true;
441}
442
Yifan Hongffa91392017-01-31 13:41:23 -0800443static std::map<std::string, Method *> gAllReservedMethods;
444
Steven Moreland14ee6742016-10-18 12:58:28 -0700445bool Interface::addMethod(Method *method) {
Yifan Hongc8934042016-11-17 17:10:52 -0800446 if (isIBase()) {
Yifan Hongffa91392017-01-31 13:41:23 -0800447 if (!gAllReservedMethods.emplace(method->name(), method).second) {
448 LOG(ERROR) << "ERROR: hidl-gen encountered duplicated reserved method "
449 << method->name();
450 return false;
451 }
452 // will add it in addAllReservedMethods
Yifan Hongc8934042016-11-17 17:10:52 -0800453 return true;
454 }
455
Yifan Hong10fe0b52016-10-19 14:20:17 -0700456 CHECK(!method->isHidlReserved());
Steven Moreland14ee6742016-10-18 12:58:28 -0700457 if (lookupMethod(method->name()) != nullptr) {
458 LOG(ERROR) << "Redefinition of method " << method->name();
459 return false;
460 }
Yifan Hong10fe0b52016-10-19 14:20:17 -0700461 size_t serial = FIRST_CALL_TRANSACTION;
Steven Moreland14ee6742016-10-18 12:58:28 -0700462
Yifan Hong10fe0b52016-10-19 14:20:17 -0700463 serial += userDefinedMethods().size();
Steven Morelandef1a9fe2016-10-06 17:19:09 -0700464
Timur Iskhakov505316c2017-08-05 03:38:59 +0000465 const Interface* ancestor = superType();
Steven Morelandef1a9fe2016-10-06 17:19:09 -0700466 while (ancestor != nullptr) {
Yifan Hong10fe0b52016-10-19 14:20:17 -0700467 serial += ancestor->userDefinedMethods().size();
Steven Morelandef1a9fe2016-10-06 17:19:09 -0700468 ancestor = ancestor->superType();
469 }
470
Yifan Hong10fe0b52016-10-19 14:20:17 -0700471 CHECK(serial <= LAST_CALL_TRANSACTION) << "More than "
472 << LAST_CALL_TRANSACTION << " methods are not allowed.";
Steven Morelandef1a9fe2016-10-06 17:19:09 -0700473 method->setSerialId(serial);
Yifan Hong10fe0b52016-10-19 14:20:17 -0700474 mUserMethods.push_back(method);
Steven Moreland14ee6742016-10-18 12:58:28 -0700475
476 return true;
Andreas Huberc9410c72016-07-28 12:18:40 -0700477}
478
Yifan Hongffa91392017-01-31 13:41:23 -0800479bool Interface::addAllReservedMethods() {
480 // use a sorted map to insert them in serial ID order.
481 std::map<int32_t, Method *> reservedMethodsById;
482 for (const auto &pair : gAllReservedMethods) {
483 Method *method = pair.second->copySignature();
Steven Moreland424a9482017-02-13 19:20:40 -0800484 bool fillSuccess = fillPingMethod(method)
485 || fillDescriptorChainMethod(method)
Yifan Hongffa91392017-01-31 13:41:23 -0800486 || fillGetDescriptorMethod(method)
Yifan Hong30b5d1f2017-04-03 12:19:25 -0700487 || fillHashChainMethod(method)
Yifan Hongffa91392017-01-31 13:41:23 -0800488 || fillSyspropsChangedMethod(method)
489 || fillLinkToDeathMethod(method)
490 || fillUnlinkToDeathMethod(method)
Yifan Hongcd2ae452017-01-31 14:33:40 -0800491 || fillSetHALInstrumentationMethod(method)
Andreas Huber37065d62017-02-07 14:36:54 -0800492 || fillGetDebugInfoMethod(method)
493 || fillDebugMethod(method);
494
Yifan Hongffa91392017-01-31 13:41:23 -0800495 if (!fillSuccess) {
496 LOG(ERROR) << "ERROR: hidl-gen does not recognize a reserved method "
497 << method->name();
498 return false;
499 }
500 if (!reservedMethodsById.emplace(method->getSerialId(), method).second) {
501 LOG(ERROR) << "ERROR: hidl-gen uses duplicated serial id for "
502 << method->name() << " and "
503 << reservedMethodsById[method->getSerialId()]->name()
504 << ", serialId = " << method->getSerialId();
505 return false;
506 }
507 }
508 for (const auto &pair : reservedMethodsById) {
509 this->mReservedMethods.push_back(pair.second);
510 }
511 return true;
512}
Yifan Hong10fe0b52016-10-19 14:20:17 -0700513
Timur Iskhakov505316c2017-08-05 03:38:59 +0000514const Interface* Interface::superType() const {
515 return isIBase() ? nullptr : mSuperType;
Andreas Huberc9410c72016-07-28 12:18:40 -0700516}
517
Yifan Hong10fe0b52016-10-19 14:20:17 -0700518std::vector<const Interface *> Interface::typeChain() const {
519 std::vector<const Interface *> v;
520 const Interface *iface = this;
521 while (iface != nullptr) {
522 v.push_back(iface);
Timur Iskhakov505316c2017-08-05 03:38:59 +0000523 iface = iface->superType();
Yifan Hong10fe0b52016-10-19 14:20:17 -0700524 }
525 return v;
526}
527
Yifan Hongfe95aa22016-10-19 17:26:45 -0700528std::vector<const Interface *> Interface::superTypeChain() const {
Timur Iskhakov505316c2017-08-05 03:38:59 +0000529 return isIBase() ? std::vector<const Interface*>() : superType()->typeChain();
Yifan Hongfe95aa22016-10-19 17:26:45 -0700530}
531
Martijn Coenenb40ef022017-01-02 15:21:46 +0100532bool Interface::isElidableType() const {
533 return true;
534}
535
Andreas Hubera2723d22016-07-29 15:36:07 -0700536bool Interface::isInterface() const {
537 return true;
538}
539
Andreas Huber295ad302016-08-16 11:35:00 -0700540bool Interface::isBinder() const {
541 return true;
542}
543
Yifan Hong10fe0b52016-10-19 14:20:17 -0700544const std::vector<Method *> &Interface::userDefinedMethods() const {
545 return mUserMethods;
546}
547
548const std::vector<Method *> &Interface::hidlReservedMethods() const {
549 return mReservedMethods;
550}
551
552std::vector<Method *> Interface::methods() const {
553 std::vector<Method *> v(mUserMethods);
554 v.insert(v.end(), mReservedMethods.begin(), mReservedMethods.end());
555 return v;
556}
557
558std::vector<InterfaceAndMethod> Interface::allMethodsFromRoot() const {
559 std::vector<InterfaceAndMethod> v;
560 std::vector<const Interface *> chain = typeChain();
561 for (auto it = chain.rbegin(); it != chain.rend(); ++it) {
562 const Interface *iface = *it;
563 for (Method *userMethod : iface->userDefinedMethods()) {
564 v.push_back(InterfaceAndMethod(iface, userMethod));
565 }
566 }
567 for (Method *reservedMethod : hidlReservedMethods()) {
Yifan Hongc8934042016-11-17 17:10:52 -0800568 v.push_back(InterfaceAndMethod(
569 *chain.rbegin(), // IBase
570 reservedMethod));
Yifan Hong10fe0b52016-10-19 14:20:17 -0700571 }
572 return v;
Andreas Huber881227d2016-08-02 14:20:21 -0700573}
574
Timur Iskhakovf1b902d2017-08-13 20:14:31 -0700575std::vector<InterfaceAndMethod> Interface::allSuperMethodsFromRoot() const {
576 return isIBase() ? std::vector<InterfaceAndMethod>() : superType()->allMethodsFromRoot();
577}
578
Steven Moreland14ee6742016-10-18 12:58:28 -0700579Method *Interface::lookupMethod(std::string name) const {
Yifan Hong10fe0b52016-10-19 14:20:17 -0700580 for (const auto &tuple : allMethodsFromRoot()) {
581 Method *method = tuple.method();
582 if (method->name() == name) {
583 return method;
Steven Moreland14ee6742016-10-18 12:58:28 -0700584 }
Steven Moreland14ee6742016-10-18 12:58:28 -0700585 }
586
587 return nullptr;
588}
589
Steven Moreland40786312016-08-16 10:29:40 -0700590std::string Interface::getBaseName() const {
Jayant Chowdhary3f32c1f2016-09-15 16:53:56 -0700591 return fqName().getInterfaceBaseName();
Steven Moreland40786312016-08-16 10:29:40 -0700592}
593
Yifan Hongeefe4f22017-01-04 15:32:42 -0800594std::string Interface::getProxyName() const {
595 return fqName().getInterfaceProxyName();
596}
597
598std::string Interface::getStubName() const {
599 return fqName().getInterfaceStubName();
600}
601
602std::string Interface::getHwName() const {
603 return fqName().getInterfaceHwName();
604}
605
606std::string Interface::getPassthroughName() const {
607 return fqName().getInterfacePassthroughName();
608}
609
Yifan Hong51a65092017-01-04 15:41:44 -0800610FQName Interface::getProxyFqName() const {
Yifan Hongeefe4f22017-01-04 15:32:42 -0800611 return fqName().getInterfaceProxyFqName();
Yifan Hong158655a2016-11-08 12:34:07 -0800612}
613
Yifan Hong51a65092017-01-04 15:41:44 -0800614FQName Interface::getStubFqName() const {
Yifan Hongeefe4f22017-01-04 15:32:42 -0800615 return fqName().getInterfaceStubFqName();
Yifan Hong158655a2016-11-08 12:34:07 -0800616}
617
Yifan Hong51a65092017-01-04 15:41:44 -0800618FQName Interface::getPassthroughFqName() const {
Yifan Hongeefe4f22017-01-04 15:32:42 -0800619 return fqName().getInterfacePassthroughFqName();
Yifan Hong158655a2016-11-08 12:34:07 -0800620}
621
Steven Moreland979e0992016-09-07 09:18:08 -0700622std::string Interface::getCppType(StorageMode mode,
Steven Moreland979e0992016-09-07 09:18:08 -0700623 bool specifyNamespaces) const {
Steven Moreland979e0992016-09-07 09:18:08 -0700624 const std::string base =
625 std::string(specifyNamespaces ? "::android::" : "")
626 + "sp<"
Steven Morelande30ee9b2017-05-09 13:31:01 -0700627 + fullName()
Steven Moreland979e0992016-09-07 09:18:08 -0700628 + ">";
Andreas Huber881227d2016-08-02 14:20:21 -0700629
630 switch (mode) {
631 case StorageMode_Stack:
632 case StorageMode_Result:
633 return base;
634
635 case StorageMode_Argument:
636 return "const " + base + "&";
637 }
638}
639
Yifan Hong4ed13472016-11-02 10:44:11 -0700640std::string Interface::getJavaType(bool /* forInitializer */) const {
Andreas Huber2831d512016-08-15 09:33:47 -0700641 return fullJavaName();
642}
643
Zhuoyao Zhanga588b232016-11-10 14:37:35 -0800644std::string Interface::getVtsType() const {
645 if (StringHelper::EndsWith(localName(), "Callback")) {
646 return "TYPE_HIDL_CALLBACK";
647 } else {
648 return "TYPE_HIDL_INTERFACE";
649 }
650}
651
Andreas Huber881227d2016-08-02 14:20:21 -0700652void Interface::emitReaderWriter(
653 Formatter &out,
654 const std::string &name,
655 const std::string &parcelObj,
656 bool parcelObjIsPointer,
657 bool isReader,
658 ErrorMode mode) const {
659 const std::string parcelObjDeref =
660 parcelObj + (parcelObjIsPointer ? "->" : ".");
661
662 if (isReader) {
Andreas Hubere7ff2282016-08-16 13:50:03 -0700663 out << "{\n";
664 out.indent();
665
Iliyan Malchev549e2592016-08-10 08:59:12 -0700666 const std::string binderName = "_hidl_" + name + "_binder";
Andreas Huber881227d2016-08-02 14:20:21 -0700667
Andreas Huber8a82ff72016-08-04 10:29:39 -0700668 out << "::android::sp<::android::hardware::IBinder> "
Andreas Huber881227d2016-08-02 14:20:21 -0700669 << binderName << ";\n";
670
Iliyan Malchev549e2592016-08-10 08:59:12 -0700671 out << "_hidl_err = ";
Andreas Huber881227d2016-08-02 14:20:21 -0700672 out << parcelObjDeref
673 << "readNullableStrongBinder(&"
674 << binderName
675 << ");\n";
676
677 handleError(out, mode);
678
679 out << name
680 << " = "
Martijn Coenena63e0ad2016-12-07 17:29:00 +0100681 << "::android::hardware::fromBinder<"
682 << fqName().cppName()
683 << ","
Yifan Hong51a65092017-01-04 15:41:44 -0800684 << getProxyFqName().cppName()
Martijn Coenena63e0ad2016-12-07 17:29:00 +0100685 << ","
Yifan Hong51a65092017-01-04 15:41:44 -0800686 << getStubFqName().cppName()
Martijn Coenena63e0ad2016-12-07 17:29:00 +0100687 << ">("
Andreas Huber881227d2016-08-02 14:20:21 -0700688 << binderName
689 << ");\n";
Andreas Hubere7ff2282016-08-16 13:50:03 -0700690
691 out.unindent();
692 out << "}\n\n";
Andreas Huber881227d2016-08-02 14:20:21 -0700693 } else {
Martijn Coenene1638232016-10-26 12:51:34 +0200694 out << "if (" << name << " == nullptr) {\n";
695 out.indent();
696 out << "_hidl_err = ";
697 out << parcelObjDeref
698 << "writeStrongBinder(nullptr);\n";
699 out.unindent();
700 out << "} else {\n";
701 out.indent();
Yifan Hong158655a2016-11-08 12:34:07 -0800702 out << "::android::sp<::android::hardware::IBinder> _hidl_binder = "
703 << "::android::hardware::toBinder<\n";
Yifan Hong33223ca2016-12-13 15:07:35 -0800704 out.indent(2, [&] {
Martijn Coenena63e0ad2016-12-07 17:29:00 +0100705 out << fqName().cppName()
Yifan Hong158655a2016-11-08 12:34:07 -0800706 << ">("
707 << name
708 << ");\n";
709 });
710 out << "if (_hidl_binder.get() != nullptr) {\n";
Yifan Hong33223ca2016-12-13 15:07:35 -0800711 out.indent([&] {
Yifan Hong158655a2016-11-08 12:34:07 -0800712 out << "_hidl_err = "
713 << parcelObjDeref
714 << "writeStrongBinder(_hidl_binder);\n";
715 });
716 out << "} else {\n";
Yifan Hong33223ca2016-12-13 15:07:35 -0800717 out.indent([&] {
Yifan Hong158655a2016-11-08 12:34:07 -0800718 out << "_hidl_err = ::android::UNKNOWN_ERROR;\n";
719 });
720 out << "}\n";
Martijn Coenene1638232016-10-26 12:51:34 +0200721 out.unindent();
722 out << "}\n";
Steven Moreland40786312016-08-16 10:29:40 -0700723
Andreas Huber881227d2016-08-02 14:20:21 -0700724 handleError(out, mode);
725 }
726}
727
Yifan Hongf5cc2f72017-01-04 18:02:34 -0800728status_t Interface::emitGlobalTypeDeclarations(Formatter &out) const {
729 status_t status = Scope::emitGlobalTypeDeclarations(out);
730 if (status != OK) {
731 return status;
732 }
Steven Moreland3d98bc42017-06-23 21:36:41 +0000733 out << "std::string toString("
Yifan Hongf5cc2f72017-01-04 18:02:34 -0800734 << getCppArgumentType()
Steven Moreland3d98bc42017-06-23 21:36:41 +0000735 << ");\n";
Yifan Hongf5cc2f72017-01-04 18:02:34 -0800736 return OK;
737}
738
739
740status_t Interface::emitTypeDefinitions(
741 Formatter &out, const std::string prefix) const {
742 std::string space = prefix.empty() ? "" : (prefix + "::");
743 status_t err = Scope::emitTypeDefinitions(out, space + localName());
744 if (err != OK) {
745 return err;
746 }
747
Steven Moreland3d98bc42017-06-23 21:36:41 +0000748 out << "std::string toString("
749 << getCppArgumentType()
750 << " o) ";
751
752 out.block([&] {
753 out << "std::string os = \"[class or subclass of \";\n"
754 << "os += " << fullName() << "::descriptor;\n"
755 << "os += \"]\";\n"
756 << "os += o->isRemote() ? \"@remote\" : \"@local\";\n"
757 << "return os;\n";
758 }).endl().endl();
759
Yifan Hongf5cc2f72017-01-04 18:02:34 -0800760 return OK;
761}
762
Andreas Huber2831d512016-08-15 09:33:47 -0700763void Interface::emitJavaReaderWriter(
764 Formatter &out,
765 const std::string &parcelObj,
766 const std::string &argName,
767 bool isReader) const {
768 if (isReader) {
769 out << fullJavaName()
770 << ".asInterface("
771 << parcelObj
772 << ".readStrongBinder());\n";
773 } else {
774 out << parcelObj
775 << ".writeStrongBinder("
776 << argName
777 << " == null ? null : "
778 << argName
779 << ".asBinder());\n";
780 }
781}
782
Zhuoyao Zhang864c7712016-08-16 15:35:28 -0700783status_t Interface::emitVtsAttributeDeclaration(Formatter &out) const {
784 for (const auto &type : getSubTypes()) {
Zhuoyao Zhangc5ea9f52016-10-06 15:05:39 -0700785 // Skip for TypeDef as it is just an alias of a defined type.
786 if (type->isTypeDef()) {
787 continue;
788 }
Zhuoyao Zhang864c7712016-08-16 15:35:28 -0700789 out << "attribute: {\n";
790 out.indent();
791 status_t status = type->emitVtsTypeDeclarations(out);
792 if (status != OK) {
793 return status;
794 }
795 out.unindent();
796 out << "}\n\n";
797 }
798 return OK;
799}
800
801status_t Interface::emitVtsMethodDeclaration(Formatter &out) const {
Yifan Hong10fe0b52016-10-19 14:20:17 -0700802 for (const auto &method : methods()) {
Steven Morelandcea24782016-11-07 11:40:48 -0800803 if (method->isHidlReserved()) {
804 continue;
805 }
806
Zhuoyao Zhang864c7712016-08-16 15:35:28 -0700807 out << "api: {\n";
808 out.indent();
809 out << "name: \"" << method->name() << "\"\n";
810 // Generate declaration for each return value.
811 for (const auto &result : method->results()) {
812 out << "return_type_hidl: {\n";
813 out.indent();
814 status_t status = result->type().emitVtsAttributeType(out);
815 if (status != OK) {
816 return status;
817 }
818 out.unindent();
819 out << "}\n";
820 }
821 // Generate declaration for each input argument
822 for (const auto &arg : method->args()) {
823 out << "arg: {\n";
824 out.indent();
825 status_t status = arg->type().emitVtsAttributeType(out);
826 if (status != OK) {
827 return status;
828 }
829 out.unindent();
830 out << "}\n";
831 }
832 // Generate declaration for each annotation.
Steven Morelandd537ab02016-09-12 10:32:01 -0700833 for (const auto &annotation : method->annotations()) {
Zhuoyao Zhang864c7712016-08-16 15:35:28 -0700834 out << "callflow: {\n";
835 out.indent();
Steven Morelandd537ab02016-09-12 10:32:01 -0700836 std::string name = annotation->name();
Zhuoyao Zhang864c7712016-08-16 15:35:28 -0700837 if (name == "entry") {
838 out << "entry: true\n";
839 } else if (name == "exit") {
840 out << "exit: true\n";
841 } else if (name == "callflow") {
Steven Morelandd537ab02016-09-12 10:32:01 -0700842 const AnnotationParam *param =
843 annotation->getParam("next");
844 if (param != nullptr) {
Timur Iskhakov7a85dc22017-08-10 19:06:41 -0700845 for (const auto& value : param->getValues()) {
Steven Morelandd537ab02016-09-12 10:32:01 -0700846 out << "next: " << value << "\n";
847 }
Zhuoyao Zhang864c7712016-08-16 15:35:28 -0700848 }
849 } else {
Keun Soo Yima5a57e92017-02-04 11:32:06 -0800850 std::cerr << "Unrecognized annotation '"
Zhuoyao Zhang864c7712016-08-16 15:35:28 -0700851 << name << "' for method: " << method->name()
Keun Soo Yima5a57e92017-02-04 11:32:06 -0800852 << ". A VTS annotation should be one of: "
853 << "entry, exit, callflow. \n";
Zhuoyao Zhang864c7712016-08-16 15:35:28 -0700854 }
855 out.unindent();
856 out << "}\n";
857 }
858 out.unindent();
859 out << "}\n\n";
860 }
861 return OK;
862}
863
864status_t Interface::emitVtsAttributeType(Formatter &out) const {
Zhuoyao Zhanga588b232016-11-10 14:37:35 -0800865 out << "type: " << getVtsType() << "\n"
Zhuoyao Zhang5158db42016-08-10 10:25:20 -0700866 << "predefined_type: \""
Zhuoyao Zhangc4e10602017-01-27 16:48:05 -0800867 << fullName()
868 << "\"\n";
Zhuoyao Zhang5158db42016-08-10 10:25:20 -0700869 return OK;
870}
871
Steven Moreland69e7c702016-09-09 11:16:32 -0700872bool Interface::hasOnewayMethods() const {
Yifan Hong10fe0b52016-10-19 14:20:17 -0700873 for (auto const &method : methods()) {
Steven Moreland69e7c702016-09-09 11:16:32 -0700874 if (method->isOneway()) {
875 return true;
876 }
877 }
878
879 const Interface* superClass = superType();
880
881 if (superClass != nullptr) {
882 return superClass->hasOnewayMethods();
883 }
884
885 return false;
886}
887
Andreas Huber70a59e12016-08-16 12:57:01 -0700888bool Interface::isJavaCompatible() const {
Andreas Huberea081b32016-08-17 15:57:47 -0700889 if (mIsJavaCompatibleInProgress) {
890 // We're currently trying to determine if this Interface is
891 // java-compatible and something is referencing this interface through
892 // one of its methods. Assume we'll ultimately succeed, if we were wrong
893 // the original invocation of Interface::isJavaCompatible() will then
894 // return the correct "false" result.
895 return true;
896 }
897
Timur Iskhakov505316c2017-08-05 03:38:59 +0000898 if (superType() != nullptr && !superType()->isJavaCompatible()) {
Andreas Huber0fa9e392016-08-31 09:05:44 -0700899 mIsJavaCompatibleInProgress = false;
900 return false;
901 }
902
Andreas Huberea081b32016-08-17 15:57:47 -0700903 mIsJavaCompatibleInProgress = true;
904
Andreas Huber70a59e12016-08-16 12:57:01 -0700905 if (!Scope::isJavaCompatible()) {
Andreas Huberea081b32016-08-17 15:57:47 -0700906 mIsJavaCompatibleInProgress = false;
Andreas Huber70a59e12016-08-16 12:57:01 -0700907 return false;
908 }
909
Yifan Hong10fe0b52016-10-19 14:20:17 -0700910 for (const auto &method : methods()) {
Andreas Huber70a59e12016-08-16 12:57:01 -0700911 if (!method->isJavaCompatible()) {
Andreas Huberea081b32016-08-17 15:57:47 -0700912 mIsJavaCompatibleInProgress = false;
Andreas Huber70a59e12016-08-16 12:57:01 -0700913 return false;
914 }
915 }
916
Andreas Huberea081b32016-08-17 15:57:47 -0700917 mIsJavaCompatibleInProgress = false;
918
Andreas Huber70a59e12016-08-16 12:57:01 -0700919 return true;
920}
921
Andreas Huberc9410c72016-07-28 12:18:40 -0700922} // namespace android
923