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