| Christopher Wiley | 3a9da17 | 2016-01-29 11:10:49 -0800 | [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 | |
| Jiyong Park | 309668e | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 17 | #include "aidl.h" |
| Jiyong Park | 1d2df7d | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 18 | #include "aidl_to_java.h" |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 19 | #include "generate_java.h" |
| Jiyong Park | 1d2df7d | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 20 | #include "options.h" |
| 21 | #include "type_java.h" |
| Christopher Wiley | f690be5 | 2015-09-14 15:19:10 -0700 | [diff] [blame] | 22 | |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 23 | #include <stdio.h> |
| 24 | #include <stdlib.h> |
| 25 | #include <string.h> |
| 26 | |
| Andreas Gampe | e9c816e | 2018-03-14 09:05:48 -0700 | [diff] [blame] | 27 | #include <algorithm> |
| 28 | #include <unordered_set> |
| Jiyong Park | 1d2df7d | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 29 | #include <utility> |
| 30 | #include <vector> |
| Andreas Gampe | e9c816e | 2018-03-14 09:05:48 -0700 | [diff] [blame] | 31 | |
| Elliott Hughes | 0a62067 | 2015-12-04 13:53:18 -0800 | [diff] [blame] | 32 | #include <android-base/macros.h> |
| Andreas Gampe | 7d7fa60 | 2017-11-22 10:50:03 -0800 | [diff] [blame] | 33 | #include <android-base/stringprintf.h> |
| Christopher Wiley | 8b2d3ee | 2015-09-23 15:43:01 -0700 | [diff] [blame] | 34 | |
| Jiyong Park | 75e1a74 | 2018-07-04 12:31:23 +0900 | [diff] [blame] | 35 | using android::base::Join; |
| Andreas Gampe | 7d7fa60 | 2017-11-22 10:50:03 -0800 | [diff] [blame] | 36 | using android::base::StringPrintf; |
| Jiyong Park | 1d2df7d | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 37 | |
| Jiyong Park | 75e1a74 | 2018-07-04 12:31:23 +0900 | [diff] [blame] | 38 | using std::string; |
| 39 | using std::unique_ptr; |
| 40 | using std::vector; |
| Andreas Gampe | 7d7fa60 | 2017-11-22 10:50:03 -0800 | [diff] [blame] | 41 | |
| Christopher Wiley | fdeb0f4 | 2015-09-11 15:38:22 -0700 | [diff] [blame] | 42 | namespace android { |
| 43 | namespace aidl { |
| Christopher Wiley | db154a5 | 2015-09-28 16:32:25 -0700 | [diff] [blame] | 44 | namespace java { |
| Christopher Wiley | fdeb0f4 | 2015-09-11 15:38:22 -0700 | [diff] [blame] | 45 | |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 46 | // ================================================= |
| Jiyong Park | 2c44f07 | 2018-07-30 21:52:21 +0900 | [diff] [blame] | 47 | class VariableFactory { |
| 48 | public: |
| 49 | using Variable = ::android::aidl::java::Variable; |
| 50 | using Type = ::android::aidl::java::Type; |
| 51 | |
| 52 | explicit VariableFactory(const std::string& base) : base_(base), index_(0) {} |
| 53 | Variable* Get(const Type* type) { |
| Jeongik Cha | dc77c1b | 2019-02-12 16:13:25 +0900 | [diff] [blame] | 54 | Variable* v = new Variable(type->JavaType(), StringPrintf("%s%d", base_.c_str(), index_)); |
| Jiyong Park | 2c44f07 | 2018-07-30 21:52:21 +0900 | [diff] [blame] | 55 | vars_.push_back(v); |
| 56 | index_++; |
| 57 | return v; |
| 58 | } |
| 59 | |
| 60 | Variable* Get(int index) { return vars_[index]; } |
| 61 | |
| 62 | private: |
| 63 | std::vector<Variable*> vars_; |
| 64 | std::string base_; |
| 65 | int index_; |
| 66 | |
| 67 | DISALLOW_COPY_AND_ASSIGN(VariableFactory); |
| 68 | }; |
| 69 | |
| 70 | // ================================================= |
| Christopher Wiley | 67502f1 | 2016-01-29 10:57:00 -0800 | [diff] [blame] | 71 | class StubClass : public Class { |
| 72 | public: |
| Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 73 | StubClass(const Type* type, const InterfaceType* interfaceType, JavaTypeNamespace* types, |
| 74 | const Options& options); |
| Yi Kong | de13891 | 2019-03-30 01:38:17 -0700 | [diff] [blame] | 75 | ~StubClass() override = default; |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 76 | |
| Christopher Wiley | 67502f1 | 2016-01-29 10:57:00 -0800 | [diff] [blame] | 77 | Variable* transact_code; |
| 78 | Variable* transact_data; |
| 79 | Variable* transact_reply; |
| 80 | Variable* transact_flags; |
| 81 | SwitchStatement* transact_switch; |
| Andreas Gampe | 7fab0d1 | 2017-11-22 17:50:17 -0800 | [diff] [blame] | 82 | StatementBlock* transact_statements; |
| Olivier Gaillard | 1140140 | 2018-07-05 15:01:34 +0100 | [diff] [blame] | 83 | SwitchStatement* code_to_method_name_switch; |
| Christopher Wiley | 8b2d3ee | 2015-09-23 15:43:01 -0700 | [diff] [blame] | 84 | |
| Andreas Gampe | 1b865af | 2017-11-22 11:31:47 -0800 | [diff] [blame] | 85 | // Where onTransact cases should be generated as separate methods. |
| 86 | bool transact_outline; |
| Andreas Gampe | e9c816e | 2018-03-14 09:05:48 -0700 | [diff] [blame] | 87 | // Specific methods that should be outlined when transact_outline is true. |
| 88 | std::unordered_set<const AidlMethod*> outline_methods; |
| 89 | // Number of all methods. |
| 90 | size_t all_method_count; |
| Andreas Gampe | 1b865af | 2017-11-22 11:31:47 -0800 | [diff] [blame] | 91 | |
| Andreas Gampe | a8a66fe | 2017-11-22 12:17:00 -0800 | [diff] [blame] | 92 | // Finish generation. This will add a default case to the switch. |
| 93 | void finish(); |
| 94 | |
| Andreas Gampe | e9c816e | 2018-03-14 09:05:48 -0700 | [diff] [blame] | 95 | Expression* get_transact_descriptor(const JavaTypeNamespace* types, |
| 96 | const AidlMethod* method); |
| Andreas Gampe | 7fab0d1 | 2017-11-22 17:50:17 -0800 | [diff] [blame] | 97 | |
| Christopher Wiley | 67502f1 | 2016-01-29 10:57:00 -0800 | [diff] [blame] | 98 | private: |
| 99 | void make_as_interface(const InterfaceType* interfaceType, |
| 100 | JavaTypeNamespace* types); |
| 101 | |
| Andreas Gampe | 7fab0d1 | 2017-11-22 17:50:17 -0800 | [diff] [blame] | 102 | Variable* transact_descriptor; |
| Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 103 | const Options& options_; |
| Andreas Gampe | 7fab0d1 | 2017-11-22 17:50:17 -0800 | [diff] [blame] | 104 | |
| Christopher Wiley | 67502f1 | 2016-01-29 10:57:00 -0800 | [diff] [blame] | 105 | DISALLOW_COPY_AND_ASSIGN(StubClass); |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 106 | }; |
| 107 | |
| Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 108 | StubClass::StubClass(const Type* type, const InterfaceType* interfaceType, JavaTypeNamespace* types, |
| 109 | const Options& options) |
| Olivier Gaillard | 1140140 | 2018-07-05 15:01:34 +0100 | [diff] [blame] | 110 | : Class(), options_(options) { |
| Andreas Gampe | 7fab0d1 | 2017-11-22 17:50:17 -0800 | [diff] [blame] | 111 | transact_descriptor = nullptr; |
| Andreas Gampe | 1b865af | 2017-11-22 11:31:47 -0800 | [diff] [blame] | 112 | transact_outline = false; |
| Andreas Gampe | e9c816e | 2018-03-14 09:05:48 -0700 | [diff] [blame] | 113 | all_method_count = 0; // Will be set when outlining may be enabled. |
| Andreas Gampe | 7fab0d1 | 2017-11-22 17:50:17 -0800 | [diff] [blame] | 114 | |
| Christopher Wiley | 67502f1 | 2016-01-29 10:57:00 -0800 | [diff] [blame] | 115 | this->comment = "/** Local-side IPC implementation stub class. */"; |
| 116 | this->modifiers = PUBLIC | ABSTRACT | STATIC; |
| 117 | this->what = Class::CLASS; |
| Jeongik Cha | aabc144 | 2019-02-12 17:44:48 +0900 | [diff] [blame] | 118 | this->type = type->JavaType(); |
| 119 | this->extends = types->BinderNativeType()->JavaType(); |
| 120 | this->interfaces.push_back(interfaceType->JavaType()); |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 121 | |
| Christopher Wiley | 67502f1 | 2016-01-29 10:57:00 -0800 | [diff] [blame] | 122 | // descriptor |
| Jeongik Cha | dc77c1b | 2019-02-12 16:13:25 +0900 | [diff] [blame] | 123 | Field* descriptor = new Field(STATIC | FINAL | PRIVATE, |
| 124 | new Variable(types->StringType()->JavaType(), "DESCRIPTOR")); |
| Christopher Wiley | d21bfee | 2016-01-29 15:11:38 -0800 | [diff] [blame] | 125 | descriptor->value = "\"" + interfaceType->JavaType() + "\""; |
| Christopher Wiley | 67502f1 | 2016-01-29 10:57:00 -0800 | [diff] [blame] | 126 | this->elements.push_back(descriptor); |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 127 | |
| Christopher Wiley | 67502f1 | 2016-01-29 10:57:00 -0800 | [diff] [blame] | 128 | // ctor |
| 129 | Method* ctor = new Method; |
| 130 | ctor->modifiers = PUBLIC; |
| 131 | ctor->comment = |
| 132 | "/** Construct the stub at attach it to the " |
| 133 | "interface. */"; |
| 134 | ctor->name = "Stub"; |
| 135 | ctor->statements = new StatementBlock; |
| 136 | MethodCall* attach = |
| 137 | new MethodCall(THIS_VALUE, "attachInterface", 2, THIS_VALUE, |
| 138 | new LiteralExpression("DESCRIPTOR")); |
| 139 | ctor->statements->Add(attach); |
| 140 | this->elements.push_back(ctor); |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 141 | |
| Christopher Wiley | 67502f1 | 2016-01-29 10:57:00 -0800 | [diff] [blame] | 142 | // asInterface |
| 143 | make_as_interface(interfaceType, types); |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 144 | |
| Christopher Wiley | 67502f1 | 2016-01-29 10:57:00 -0800 | [diff] [blame] | 145 | // asBinder |
| 146 | Method* asBinder = new Method; |
| 147 | asBinder->modifiers = PUBLIC | OVERRIDE; |
| Jeongik Cha | 6cadc21 | 2019-02-12 18:16:03 +0900 | [diff] [blame] | 148 | asBinder->returnType = types->IBinderType()->JavaType(); |
| Christopher Wiley | 67502f1 | 2016-01-29 10:57:00 -0800 | [diff] [blame] | 149 | asBinder->name = "asBinder"; |
| 150 | asBinder->statements = new StatementBlock; |
| 151 | asBinder->statements->Add(new ReturnStatement(THIS_VALUE)); |
| 152 | this->elements.push_back(asBinder); |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 153 | |
| Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 154 | if (options_.GenTransactionNames()) { |
| Olivier Gaillard | 83d7cd3 | 2018-07-30 16:20:57 +0100 | [diff] [blame] | 155 | // getDefaultTransactionName |
| 156 | Method* getDefaultTransactionName = new Method; |
| Jiyong Park | cd3c04b | 2019-04-10 03:08:41 +0900 | [diff] [blame] | 157 | getDefaultTransactionName->comment = "/** @hide */"; |
| Olivier Gaillard | 83d7cd3 | 2018-07-30 16:20:57 +0100 | [diff] [blame] | 158 | getDefaultTransactionName->modifiers = PUBLIC | STATIC; |
| Jeongik Cha | 6cadc21 | 2019-02-12 18:16:03 +0900 | [diff] [blame] | 159 | getDefaultTransactionName->returnType = types->StringType()->JavaType(); |
| Olivier Gaillard | 83d7cd3 | 2018-07-30 16:20:57 +0100 | [diff] [blame] | 160 | getDefaultTransactionName->name = "getDefaultTransactionName"; |
| Jeongik Cha | dc77c1b | 2019-02-12 16:13:25 +0900 | [diff] [blame] | 161 | Variable* code = new Variable(types->IntType()->JavaType(), "transactionCode"); |
| Olivier Gaillard | 83d7cd3 | 2018-07-30 16:20:57 +0100 | [diff] [blame] | 162 | getDefaultTransactionName->parameters.push_back(code); |
| 163 | getDefaultTransactionName->statements = new StatementBlock; |
| 164 | this->code_to_method_name_switch = new SwitchStatement(code); |
| 165 | getDefaultTransactionName->statements->Add(this->code_to_method_name_switch); |
| 166 | this->elements.push_back(getDefaultTransactionName); |
| 167 | |
| 168 | // getTransactionName |
| Olivier Gaillard | 1140140 | 2018-07-05 15:01:34 +0100 | [diff] [blame] | 169 | Method* getTransactionName = new Method; |
| Jiyong Park | cd3c04b | 2019-04-10 03:08:41 +0900 | [diff] [blame] | 170 | getTransactionName->comment = "/** @hide */"; |
| Olivier Gaillard | 1140140 | 2018-07-05 15:01:34 +0100 | [diff] [blame] | 171 | getTransactionName->modifiers = PUBLIC; |
| Jeongik Cha | 6cadc21 | 2019-02-12 18:16:03 +0900 | [diff] [blame] | 172 | getTransactionName->returnType = types->StringType()->JavaType(); |
| Olivier Gaillard | 1140140 | 2018-07-05 15:01:34 +0100 | [diff] [blame] | 173 | getTransactionName->name = "getTransactionName"; |
| Jeongik Cha | dc77c1b | 2019-02-12 16:13:25 +0900 | [diff] [blame] | 174 | Variable* code2 = new Variable(types->IntType()->JavaType(), "transactionCode"); |
| Olivier Gaillard | 83d7cd3 | 2018-07-30 16:20:57 +0100 | [diff] [blame] | 175 | getTransactionName->parameters.push_back(code2); |
| Olivier Gaillard | 1140140 | 2018-07-05 15:01:34 +0100 | [diff] [blame] | 176 | getTransactionName->statements = new StatementBlock; |
| Olivier Gaillard | 83d7cd3 | 2018-07-30 16:20:57 +0100 | [diff] [blame] | 177 | getTransactionName->statements->Add( |
| 178 | new ReturnStatement(new MethodCall(THIS_VALUE, "getDefaultTransactionName", 1, code2))); |
| Olivier Gaillard | 1140140 | 2018-07-05 15:01:34 +0100 | [diff] [blame] | 179 | this->elements.push_back(getTransactionName); |
| 180 | } |
| 181 | |
| Christopher Wiley | 67502f1 | 2016-01-29 10:57:00 -0800 | [diff] [blame] | 182 | // onTransact |
| Jeongik Cha | dc77c1b | 2019-02-12 16:13:25 +0900 | [diff] [blame] | 183 | this->transact_code = new Variable(types->IntType()->JavaType(), "code"); |
| 184 | this->transact_data = new Variable(types->ParcelType()->JavaType(), "data"); |
| 185 | this->transact_reply = new Variable(types->ParcelType()->JavaType(), "reply"); |
| 186 | this->transact_flags = new Variable(types->IntType()->JavaType(), "flags"); |
| Christopher Wiley | 67502f1 | 2016-01-29 10:57:00 -0800 | [diff] [blame] | 187 | Method* onTransact = new Method; |
| 188 | onTransact->modifiers = PUBLIC | OVERRIDE; |
| Jeongik Cha | 6cadc21 | 2019-02-12 18:16:03 +0900 | [diff] [blame] | 189 | onTransact->returnType = types->BoolType()->JavaType(); |
| Christopher Wiley | 67502f1 | 2016-01-29 10:57:00 -0800 | [diff] [blame] | 190 | onTransact->name = "onTransact"; |
| 191 | onTransact->parameters.push_back(this->transact_code); |
| 192 | onTransact->parameters.push_back(this->transact_data); |
| 193 | onTransact->parameters.push_back(this->transact_reply); |
| 194 | onTransact->parameters.push_back(this->transact_flags); |
| 195 | onTransact->statements = new StatementBlock; |
| Andreas Gampe | 7fab0d1 | 2017-11-22 17:50:17 -0800 | [diff] [blame] | 196 | transact_statements = onTransact->statements; |
| Jeongik Cha | 6cadc21 | 2019-02-12 18:16:03 +0900 | [diff] [blame] | 197 | onTransact->exceptions.push_back(types->RemoteExceptionType()->JavaType()); |
| Christopher Wiley | 67502f1 | 2016-01-29 10:57:00 -0800 | [diff] [blame] | 198 | this->elements.push_back(onTransact); |
| 199 | this->transact_switch = new SwitchStatement(this->transact_code); |
| Andreas Gampe | a8a66fe | 2017-11-22 12:17:00 -0800 | [diff] [blame] | 200 | } |
| 201 | |
| 202 | void StubClass::finish() { |
| 203 | Case* default_case = new Case; |
| 204 | |
| Christopher Wiley | 67502f1 | 2016-01-29 10:57:00 -0800 | [diff] [blame] | 205 | MethodCall* superCall = new MethodCall( |
| Andreas Gampe | a8a66fe | 2017-11-22 12:17:00 -0800 | [diff] [blame] | 206 | SUPER_VALUE, "onTransact", 4, this->transact_code, this->transact_data, |
| 207 | this->transact_reply, this->transact_flags); |
| 208 | default_case->statements->Add(new ReturnStatement(superCall)); |
| 209 | transact_switch->cases.push_back(default_case); |
| Andreas Gampe | 7fab0d1 | 2017-11-22 17:50:17 -0800 | [diff] [blame] | 210 | |
| 211 | transact_statements->Add(this->transact_switch); |
| Olivier Gaillard | 1140140 | 2018-07-05 15:01:34 +0100 | [diff] [blame] | 212 | |
| 213 | // getTransactionName |
| Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 214 | if (options_.GenTransactionNames()) { |
| Olivier Gaillard | 1140140 | 2018-07-05 15:01:34 +0100 | [diff] [blame] | 215 | // Some transaction codes are common, e.g. INTERFACE_TRANSACTION or DUMP_TRANSACTION. |
| 216 | // Common transaction codes will not be resolved to a string by getTransactionName. The method |
| 217 | // will return NULL in this case. |
| 218 | Case* code_switch_default_case = new Case; |
| 219 | code_switch_default_case->statements->Add(new ReturnStatement(NULL_VALUE)); |
| 220 | this->code_to_method_name_switch->cases.push_back(code_switch_default_case); |
| 221 | } |
| Andreas Gampe | 7fab0d1 | 2017-11-22 17:50:17 -0800 | [diff] [blame] | 222 | } |
| 223 | |
| Andreas Gampe | e9c816e | 2018-03-14 09:05:48 -0700 | [diff] [blame] | 224 | // The the expression for the interface's descriptor to be used when |
| 225 | // generating code for the given method. Null is acceptable for method |
| 226 | // and stands for synthetic cases. |
| 227 | Expression* StubClass::get_transact_descriptor(const JavaTypeNamespace* types, |
| 228 | const AidlMethod* method) { |
| Andreas Gampe | 1b865af | 2017-11-22 11:31:47 -0800 | [diff] [blame] | 229 | if (transact_outline) { |
| Andreas Gampe | e9c816e | 2018-03-14 09:05:48 -0700 | [diff] [blame] | 230 | if (method != nullptr) { |
| 231 | // When outlining, each outlined method needs its own literal. |
| 232 | if (outline_methods.count(method) != 0) { |
| 233 | return new LiteralExpression("DESCRIPTOR"); |
| 234 | } |
| 235 | } else { |
| 236 | // Synthetic case. A small number is assumed. Use its own descriptor |
| 237 | // if there are only synthetic cases. |
| 238 | if (outline_methods.size() == all_method_count) { |
| 239 | return new LiteralExpression("DESCRIPTOR"); |
| 240 | } |
| 241 | } |
| Andreas Gampe | 1b865af | 2017-11-22 11:31:47 -0800 | [diff] [blame] | 242 | } |
| 243 | |
| Andreas Gampe | e9c816e | 2018-03-14 09:05:48 -0700 | [diff] [blame] | 244 | // When not outlining, store the descriptor literal into a local variable, in |
| 245 | // an effort to save const-string instructions in each switch case. |
| Andreas Gampe | 7fab0d1 | 2017-11-22 17:50:17 -0800 | [diff] [blame] | 246 | if (transact_descriptor == nullptr) { |
| Jeongik Cha | dc77c1b | 2019-02-12 16:13:25 +0900 | [diff] [blame] | 247 | transact_descriptor = new Variable(types->StringType()->JavaType(), "descriptor"); |
| Andreas Gampe | 7fab0d1 | 2017-11-22 17:50:17 -0800 | [diff] [blame] | 248 | transact_statements->Add( |
| 249 | new VariableDeclaration(transact_descriptor, |
| 250 | new LiteralExpression("DESCRIPTOR"))); |
| 251 | } |
| 252 | return transact_descriptor; |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 253 | } |
| 254 | |
| Christopher Wiley | 67502f1 | 2016-01-29 10:57:00 -0800 | [diff] [blame] | 255 | void StubClass::make_as_interface(const InterfaceType* interfaceType, |
| 256 | JavaTypeNamespace* types) { |
| Jeongik Cha | dc77c1b | 2019-02-12 16:13:25 +0900 | [diff] [blame] | 257 | Variable* obj = new Variable(types->IBinderType()->JavaType(), "obj"); |
| Christopher Wiley | 67502f1 | 2016-01-29 10:57:00 -0800 | [diff] [blame] | 258 | |
| 259 | Method* m = new Method; |
| 260 | m->comment = "/**\n * Cast an IBinder object into an "; |
| Christopher Wiley | d21bfee | 2016-01-29 15:11:38 -0800 | [diff] [blame] | 261 | m->comment += interfaceType->JavaType(); |
| Christopher Wiley | 67502f1 | 2016-01-29 10:57:00 -0800 | [diff] [blame] | 262 | m->comment += " interface,\n"; |
| 263 | m->comment += " * generating a proxy if needed.\n */"; |
| 264 | m->modifiers = PUBLIC | STATIC; |
| Jeongik Cha | 6cadc21 | 2019-02-12 18:16:03 +0900 | [diff] [blame] | 265 | m->returnType = interfaceType->JavaType(); |
| Christopher Wiley | 67502f1 | 2016-01-29 10:57:00 -0800 | [diff] [blame] | 266 | m->name = "asInterface"; |
| 267 | m->parameters.push_back(obj); |
| 268 | m->statements = new StatementBlock; |
| 269 | |
| 270 | IfStatement* ifstatement = new IfStatement(); |
| 271 | ifstatement->expression = new Comparison(obj, "==", NULL_VALUE); |
| 272 | ifstatement->statements = new StatementBlock; |
| 273 | ifstatement->statements->Add(new ReturnStatement(NULL_VALUE)); |
| 274 | m->statements->Add(ifstatement); |
| 275 | |
| 276 | // IInterface iin = obj.queryLocalInterface(DESCRIPTOR) |
| 277 | MethodCall* queryLocalInterface = new MethodCall(obj, "queryLocalInterface"); |
| 278 | queryLocalInterface->arguments.push_back(new LiteralExpression("DESCRIPTOR")); |
| George Burgess IV | 478cec3 | 2019-03-19 17:54:47 -0700 | [diff] [blame] | 279 | IInterfaceType iinType(types); |
| 280 | Variable* iin = new Variable(iinType.JavaType(), "iin"); |
| Jeongik Cha | 9a7f21f | 2019-02-13 14:42:47 +0900 | [diff] [blame] | 281 | VariableDeclaration* iinVd = new VariableDeclaration(iin, queryLocalInterface); |
| Christopher Wiley | 67502f1 | 2016-01-29 10:57:00 -0800 | [diff] [blame] | 282 | m->statements->Add(iinVd); |
| 283 | |
| 284 | // Ensure the instance type of the local object is as expected. |
| 285 | // One scenario where this is needed is if another package (with a |
| 286 | // different class loader) runs in the same process as the service. |
| 287 | |
| 288 | // if (iin != null && iin instanceof <interfaceType>) return (<interfaceType>) |
| 289 | // iin; |
| 290 | Comparison* iinNotNull = new Comparison(iin, "!=", NULL_VALUE); |
| 291 | Comparison* instOfCheck = |
| 292 | new Comparison(iin, " instanceof ", |
| Christopher Wiley | d21bfee | 2016-01-29 15:11:38 -0800 | [diff] [blame] | 293 | new LiteralExpression(interfaceType->JavaType())); |
| Christopher Wiley | 67502f1 | 2016-01-29 10:57:00 -0800 | [diff] [blame] | 294 | IfStatement* instOfStatement = new IfStatement(); |
| 295 | instOfStatement->expression = new Comparison(iinNotNull, "&&", instOfCheck); |
| 296 | instOfStatement->statements = new StatementBlock; |
| Jeongik Cha | 9a7f21f | 2019-02-13 14:42:47 +0900 | [diff] [blame] | 297 | instOfStatement->statements->Add(new ReturnStatement(new Cast(interfaceType->JavaType(), iin))); |
| Christopher Wiley | 67502f1 | 2016-01-29 10:57:00 -0800 | [diff] [blame] | 298 | m->statements->Add(instOfStatement); |
| 299 | |
| Jeongik Cha | 9a7f21f | 2019-02-13 14:42:47 +0900 | [diff] [blame] | 300 | NewExpression* ne = new NewExpression(interfaceType->GetProxy()->InstantiableName()); |
| Christopher Wiley | 67502f1 | 2016-01-29 10:57:00 -0800 | [diff] [blame] | 301 | ne->arguments.push_back(obj); |
| 302 | m->statements->Add(new ReturnStatement(ne)); |
| 303 | |
| 304 | this->elements.push_back(m); |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 305 | } |
| 306 | |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 307 | // ================================================= |
| Christopher Wiley | 67502f1 | 2016-01-29 10:57:00 -0800 | [diff] [blame] | 308 | class ProxyClass : public Class { |
| 309 | public: |
| Jiyong Park | 309668e | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 310 | ProxyClass(const JavaTypeNamespace* types, const Type* type, const InterfaceType* interfaceType, |
| 311 | const Options& options); |
| Yi Kong | de13891 | 2019-03-30 01:38:17 -0700 | [diff] [blame] | 312 | ~ProxyClass() override; |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 313 | |
| Christopher Wiley | 67502f1 | 2016-01-29 10:57:00 -0800 | [diff] [blame] | 314 | Variable* mRemote; |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 315 | }; |
| 316 | |
| Christopher Wiley | 67502f1 | 2016-01-29 10:57:00 -0800 | [diff] [blame] | 317 | ProxyClass::ProxyClass(const JavaTypeNamespace* types, const Type* type, |
| Jiyong Park | 309668e | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 318 | const InterfaceType* interfaceType, const Options& options) |
| Christopher Wiley | 67502f1 | 2016-01-29 10:57:00 -0800 | [diff] [blame] | 319 | : Class() { |
| 320 | this->modifiers = PRIVATE | STATIC; |
| 321 | this->what = Class::CLASS; |
| Jeongik Cha | aabc144 | 2019-02-12 17:44:48 +0900 | [diff] [blame] | 322 | this->type = type->JavaType(); |
| 323 | this->interfaces.push_back(interfaceType->JavaType()); |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 324 | |
| Christopher Wiley | 67502f1 | 2016-01-29 10:57:00 -0800 | [diff] [blame] | 325 | // IBinder mRemote |
| Jeongik Cha | dc77c1b | 2019-02-12 16:13:25 +0900 | [diff] [blame] | 326 | mRemote = new Variable(types->IBinderType()->JavaType(), "mRemote"); |
| Christopher Wiley | 67502f1 | 2016-01-29 10:57:00 -0800 | [diff] [blame] | 327 | this->elements.push_back(new Field(PRIVATE, mRemote)); |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 328 | |
| Christopher Wiley | 67502f1 | 2016-01-29 10:57:00 -0800 | [diff] [blame] | 329 | // Proxy() |
| Jeongik Cha | dc77c1b | 2019-02-12 16:13:25 +0900 | [diff] [blame] | 330 | Variable* remote = new Variable(types->IBinderType()->JavaType(), "remote"); |
| Christopher Wiley | 67502f1 | 2016-01-29 10:57:00 -0800 | [diff] [blame] | 331 | Method* ctor = new Method; |
| 332 | ctor->name = "Proxy"; |
| 333 | ctor->statements = new StatementBlock; |
| 334 | ctor->parameters.push_back(remote); |
| 335 | ctor->statements->Add(new Assignment(mRemote, remote)); |
| 336 | this->elements.push_back(ctor); |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 337 | |
| Jiyong Park | 309668e | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 338 | if (options.Version() > 0) { |
| 339 | std::ostringstream code; |
| 340 | code << "private int mCachedVersion = -1;\n"; |
| 341 | this->elements.emplace_back(new LiteralClassElement(code.str())); |
| 342 | } |
| 343 | |
| Christopher Wiley | 67502f1 | 2016-01-29 10:57:00 -0800 | [diff] [blame] | 344 | // IBinder asBinder() |
| 345 | Method* asBinder = new Method; |
| 346 | asBinder->modifiers = PUBLIC | OVERRIDE; |
| Jeongik Cha | 6cadc21 | 2019-02-12 18:16:03 +0900 | [diff] [blame] | 347 | asBinder->returnType = types->IBinderType()->JavaType(); |
| Christopher Wiley | 67502f1 | 2016-01-29 10:57:00 -0800 | [diff] [blame] | 348 | asBinder->name = "asBinder"; |
| 349 | asBinder->statements = new StatementBlock; |
| 350 | asBinder->statements->Add(new ReturnStatement(mRemote)); |
| 351 | this->elements.push_back(asBinder); |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 352 | } |
| 353 | |
| Christopher Wiley | 67502f1 | 2016-01-29 10:57:00 -0800 | [diff] [blame] | 354 | ProxyClass::~ProxyClass() {} |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 355 | |
| 356 | // ================================================= |
| Christopher Wiley | 67502f1 | 2016-01-29 10:57:00 -0800 | [diff] [blame] | 357 | static void generate_new_array(const Type* t, StatementBlock* addTo, |
| 358 | Variable* v, Variable* parcel, |
| 359 | JavaTypeNamespace* types) { |
| Jeongik Cha | dc77c1b | 2019-02-12 16:13:25 +0900 | [diff] [blame] | 360 | Variable* len = new Variable(types->IntType()->JavaType(), v->name + "_length"); |
| Christopher Wiley | 67502f1 | 2016-01-29 10:57:00 -0800 | [diff] [blame] | 361 | addTo->Add(new VariableDeclaration(len, new MethodCall(parcel, "readInt"))); |
| 362 | IfStatement* lencheck = new IfStatement(); |
| 363 | lencheck->expression = new Comparison(len, "<", new LiteralExpression("0")); |
| 364 | lencheck->statements->Add(new Assignment(v, NULL_VALUE)); |
| 365 | lencheck->elseif = new IfStatement(); |
| Jeongik Cha | 9a7f21f | 2019-02-13 14:42:47 +0900 | [diff] [blame] | 366 | lencheck->elseif->statements->Add(new Assignment(v, new NewArrayExpression(t->JavaType(), len))); |
| Christopher Wiley | 67502f1 | 2016-01-29 10:57:00 -0800 | [diff] [blame] | 367 | addTo->Add(lencheck); |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 368 | } |
| 369 | |
| Jiyong Park | 1d2df7d | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 370 | static void generate_write_to_parcel(const AidlTypeSpecifier& type, StatementBlock* addTo, |
| 371 | Variable* v, Variable* parcel, bool is_return_value, |
| 372 | const AidlTypenames& typenames) { |
| 373 | string code; |
| 374 | CodeWriterPtr writer = CodeWriter::ForString(&code); |
| 375 | CodeGeneratorContext context{ |
| 376 | .writer = *(writer.get()), |
| 377 | .typenames = typenames, |
| 378 | .type = type, |
| 379 | .var = v->name, |
| 380 | .parcel = parcel->name, |
| 381 | .is_return_value = is_return_value, |
| 382 | }; |
| 383 | WriteToParcelFor(context); |
| 384 | writer->Close(); |
| 385 | addTo->Add(new LiteralStatement(code)); |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 386 | } |
| 387 | |
| Steven Moreland | 693640b | 2018-07-19 13:46:27 -0700 | [diff] [blame] | 388 | static void generate_int_constant(Class* interface, const std::string& name, |
| 389 | const std::string& value) { |
| Jeongik Cha | de157cc | 2019-02-12 12:41:27 +0900 | [diff] [blame] | 390 | auto code = StringPrintf("public static final int %s = %s;\n", name.c_str(), value.c_str()); |
| 391 | interface->elements.push_back(new LiteralClassElement(code)); |
| Christopher Wiley | 69b44cf | 2016-05-03 13:43:33 -0700 | [diff] [blame] | 392 | } |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 393 | |
| Steven Moreland | 693640b | 2018-07-19 13:46:27 -0700 | [diff] [blame] | 394 | static void generate_string_constant(Class* interface, const std::string& name, |
| 395 | const std::string& value) { |
| Jeongik Cha | de157cc | 2019-02-12 12:41:27 +0900 | [diff] [blame] | 396 | auto code = StringPrintf("public static final String %s = %s;\n", name.c_str(), value.c_str()); |
| 397 | interface->elements.push_back(new LiteralClassElement(code)); |
| Casey Dahlin | d40e2fe | 2015-11-24 14:06:52 -0800 | [diff] [blame] | 398 | } |
| 399 | |
| Andreas Gampe | 7d7fa60 | 2017-11-22 10:50:03 -0800 | [diff] [blame] | 400 | static std::unique_ptr<Method> generate_interface_method( |
| 401 | const AidlMethod& method, JavaTypeNamespace* types) { |
| 402 | std::unique_ptr<Method> decl(new Method); |
| Christopher Wiley | 67502f1 | 2016-01-29 10:57:00 -0800 | [diff] [blame] | 403 | decl->comment = method.GetComments(); |
| 404 | decl->modifiers = PUBLIC; |
| Jeongik Cha | 6cadc21 | 2019-02-12 18:16:03 +0900 | [diff] [blame] | 405 | decl->returnType = method.GetType().GetLanguageType<Type>()->JavaType(); |
| Christopher Wiley | 67502f1 | 2016-01-29 10:57:00 -0800 | [diff] [blame] | 406 | decl->returnTypeDimension = method.GetType().IsArray() ? 1 : 0; |
| 407 | decl->name = method.GetName(); |
| Jiyong Park | a6605ab | 2018-11-11 14:30:21 +0900 | [diff] [blame] | 408 | decl->annotations = generate_java_annotations(method.GetType()); |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 409 | |
| Christopher Wiley | 67502f1 | 2016-01-29 10:57:00 -0800 | [diff] [blame] | 410 | for (const std::unique_ptr<AidlArgument>& arg : method.GetArguments()) { |
| Jeongik Cha | dc77c1b | 2019-02-12 16:13:25 +0900 | [diff] [blame] | 411 | decl->parameters.push_back(new Variable(arg->GetType().GetLanguageType<Type>()->JavaType(), |
| 412 | arg->GetName(), arg->GetType().IsArray() ? 1 : 0)); |
| Christopher Wiley | 67502f1 | 2016-01-29 10:57:00 -0800 | [diff] [blame] | 413 | } |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 414 | |
| Jeongik Cha | 6cadc21 | 2019-02-12 18:16:03 +0900 | [diff] [blame] | 415 | decl->exceptions.push_back(types->RemoteExceptionType()->JavaType()); |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 416 | |
| Andreas Gampe | 7d7fa60 | 2017-11-22 10:50:03 -0800 | [diff] [blame] | 417 | return decl; |
| 418 | } |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 419 | |
| Jiyong Park | fbbfa93 | 2018-07-30 21:44:10 +0900 | [diff] [blame] | 420 | static void generate_stub_code(const AidlInterface& iface, const AidlMethod& method, bool oneway, |
| 421 | Variable* transact_data, Variable* transact_reply, |
| 422 | JavaTypeNamespace* types, StatementBlock* statements, |
| 423 | StubClass* stubClass, const Options& options) { |
| Martijn Coenen | f1b5078 | 2018-02-21 21:06:23 +0100 | [diff] [blame] | 424 | TryStatement* tryStatement = nullptr; |
| 425 | FinallyStatement* finallyStatement = nullptr; |
| Christopher Wiley | 67502f1 | 2016-01-29 10:57:00 -0800 | [diff] [blame] | 426 | MethodCall* realCall = new MethodCall(THIS_VALUE, method.GetName()); |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 427 | |
| Christopher Wiley | 67502f1 | 2016-01-29 10:57:00 -0800 | [diff] [blame] | 428 | // interface token validation is the very first thing we do |
| Andreas Gampe | 7d7fa60 | 2017-11-22 10:50:03 -0800 | [diff] [blame] | 429 | statements->Add(new MethodCall(transact_data, |
| 430 | "enforceInterface", 1, |
| Andreas Gampe | e9c816e | 2018-03-14 09:05:48 -0700 | [diff] [blame] | 431 | stubClass->get_transact_descriptor(types, |
| 432 | &method))); |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 433 | |
| Christopher Wiley | 67502f1 | 2016-01-29 10:57:00 -0800 | [diff] [blame] | 434 | // args |
| Christopher Wiley | 67502f1 | 2016-01-29 10:57:00 -0800 | [diff] [blame] | 435 | VariableFactory stubArgs("_arg"); |
| Andreas Gampe | 7d7fa60 | 2017-11-22 10:50:03 -0800 | [diff] [blame] | 436 | { |
| Jiyong Park | 1d2df7d | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 437 | // keep this across different args in order to create the classloader |
| 438 | // at most once. |
| 439 | bool is_classloader_created = false; |
| Andreas Gampe | 7d7fa60 | 2017-11-22 10:50:03 -0800 | [diff] [blame] | 440 | for (const std::unique_ptr<AidlArgument>& arg : method.GetArguments()) { |
| 441 | const Type* t = arg->GetType().GetLanguageType<Type>(); |
| 442 | Variable* v = stubArgs.Get(t); |
| 443 | v->dimension = arg->GetType().IsArray() ? 1 : 0; |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 444 | |
| Andreas Gampe | 7d7fa60 | 2017-11-22 10:50:03 -0800 | [diff] [blame] | 445 | statements->Add(new VariableDeclaration(v)); |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 446 | |
| Andreas Gampe | 7d7fa60 | 2017-11-22 10:50:03 -0800 | [diff] [blame] | 447 | if (arg->GetDirection() & AidlArgument::IN_DIR) { |
| Jiyong Park | 1d2df7d | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 448 | string code; |
| 449 | CodeWriterPtr writer = CodeWriter::ForString(&code); |
| 450 | CodeGeneratorContext context{.writer = *(writer.get()), |
| 451 | .typenames = types->typenames_, |
| 452 | .type = arg->GetType(), |
| 453 | .var = v->name, |
| 454 | .parcel = transact_data->name, |
| 455 | .is_classloader_created = &is_classloader_created}; |
| 456 | CreateFromParcelFor(context); |
| 457 | writer->Close(); |
| 458 | statements->Add(new LiteralStatement(code)); |
| Christopher Wiley | 67502f1 | 2016-01-29 10:57:00 -0800 | [diff] [blame] | 459 | } else { |
| Andreas Gampe | 7d7fa60 | 2017-11-22 10:50:03 -0800 | [diff] [blame] | 460 | if (!arg->GetType().IsArray()) { |
| Jeongik Cha | 9a7f21f | 2019-02-13 14:42:47 +0900 | [diff] [blame] | 461 | statements->Add(new Assignment(v, new NewExpression(t->InstantiableName()))); |
| Andreas Gampe | 7d7fa60 | 2017-11-22 10:50:03 -0800 | [diff] [blame] | 462 | } else { |
| Jeongik Cha | dc77c1b | 2019-02-12 16:13:25 +0900 | [diff] [blame] | 463 | generate_new_array(t, statements, v, transact_data, types); |
| Andreas Gampe | 7d7fa60 | 2017-11-22 10:50:03 -0800 | [diff] [blame] | 464 | } |
| Christopher Wiley | 67502f1 | 2016-01-29 10:57:00 -0800 | [diff] [blame] | 465 | } |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 466 | |
| Andreas Gampe | 7d7fa60 | 2017-11-22 10:50:03 -0800 | [diff] [blame] | 467 | realCall->arguments.push_back(v); |
| 468 | } |
| Christopher Wiley | 67502f1 | 2016-01-29 10:57:00 -0800 | [diff] [blame] | 469 | } |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 470 | |
| Jiyong Park | fbbfa93 | 2018-07-30 21:44:10 +0900 | [diff] [blame] | 471 | if (options.GenTraces()) { |
| Martijn Coenen | f1b5078 | 2018-02-21 21:06:23 +0100 | [diff] [blame] | 472 | // try and finally, but only when generating trace code |
| 473 | tryStatement = new TryStatement(); |
| 474 | finallyStatement = new FinallyStatement(); |
| 475 | |
| 476 | tryStatement->statements->Add(new MethodCall( |
| 477 | new LiteralExpression("android.os.Trace"), "traceBegin", 2, |
| 478 | new LiteralExpression("android.os.Trace.TRACE_TAG_AIDL"), |
| 479 | new StringLiteralExpression(iface.GetName() + "::" |
| 480 | + method.GetName() + "::server"))); |
| 481 | |
| 482 | finallyStatement->statements->Add(new MethodCall( |
| 483 | new LiteralExpression("android.os.Trace"), "traceEnd", 1, |
| 484 | new LiteralExpression("android.os.Trace.TRACE_TAG_AIDL"))); |
| 485 | } |
| 486 | |
| Christopher Wiley | 67502f1 | 2016-01-29 10:57:00 -0800 | [diff] [blame] | 487 | // the real call |
| Christopher Wiley | 67502f1 | 2016-01-29 10:57:00 -0800 | [diff] [blame] | 488 | if (method.GetType().GetName() == "void") { |
| Jiyong Park | fbbfa93 | 2018-07-30 21:44:10 +0900 | [diff] [blame] | 489 | if (options.GenTraces()) { |
| Martijn Coenen | f1b5078 | 2018-02-21 21:06:23 +0100 | [diff] [blame] | 490 | statements->Add(tryStatement); |
| 491 | tryStatement->statements->Add(realCall); |
| 492 | statements->Add(finallyStatement); |
| 493 | } else { |
| 494 | statements->Add(realCall); |
| 495 | } |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 496 | |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 497 | if (!oneway) { |
| Christopher Wiley | 67502f1 | 2016-01-29 10:57:00 -0800 | [diff] [blame] | 498 | // report that there were no exceptions |
| 499 | MethodCall* ex = |
| Andreas Gampe | 7d7fa60 | 2017-11-22 10:50:03 -0800 | [diff] [blame] | 500 | new MethodCall(transact_reply, "writeNoException", 0); |
| 501 | statements->Add(ex); |
| Christopher Wiley | 67502f1 | 2016-01-29 10:57:00 -0800 | [diff] [blame] | 502 | } |
| 503 | } else { |
| Jeongik Cha | dc77c1b | 2019-02-12 16:13:25 +0900 | [diff] [blame] | 504 | Variable* _result = new Variable(method.GetType().GetLanguageType<Type>()->JavaType(), |
| 505 | "_result", method.GetType().IsArray() ? 1 : 0); |
| Jiyong Park | fbbfa93 | 2018-07-30 21:44:10 +0900 | [diff] [blame] | 506 | if (options.GenTraces()) { |
| Martijn Coenen | f1b5078 | 2018-02-21 21:06:23 +0100 | [diff] [blame] | 507 | statements->Add(new VariableDeclaration(_result)); |
| 508 | statements->Add(tryStatement); |
| 509 | tryStatement->statements->Add(new Assignment(_result, realCall)); |
| 510 | statements->Add(finallyStatement); |
| 511 | } else { |
| 512 | statements->Add(new VariableDeclaration(_result, realCall)); |
| 513 | } |
| Christopher Wiley | 67502f1 | 2016-01-29 10:57:00 -0800 | [diff] [blame] | 514 | |
| 515 | if (!oneway) { |
| 516 | // report that there were no exceptions |
| 517 | MethodCall* ex = |
| Andreas Gampe | 7d7fa60 | 2017-11-22 10:50:03 -0800 | [diff] [blame] | 518 | new MethodCall(transact_reply, "writeNoException", 0); |
| 519 | statements->Add(ex); |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 520 | } |
| 521 | |
| Christopher Wiley | 67502f1 | 2016-01-29 10:57:00 -0800 | [diff] [blame] | 522 | // marshall the return value |
| Jiyong Park | 1d2df7d | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 523 | generate_write_to_parcel(method.GetType(), statements, _result, transact_reply, true, |
| 524 | types->typenames_); |
| Christopher Wiley | 67502f1 | 2016-01-29 10:57:00 -0800 | [diff] [blame] | 525 | } |
| 526 | |
| 527 | // out parameters |
| Andreas Gampe | 7d7fa60 | 2017-11-22 10:50:03 -0800 | [diff] [blame] | 528 | int i = 0; |
| Christopher Wiley | 67502f1 | 2016-01-29 10:57:00 -0800 | [diff] [blame] | 529 | for (const std::unique_ptr<AidlArgument>& arg : method.GetArguments()) { |
| Christopher Wiley | 67502f1 | 2016-01-29 10:57:00 -0800 | [diff] [blame] | 530 | Variable* v = stubArgs.Get(i++); |
| 531 | |
| 532 | if (arg->GetDirection() & AidlArgument::OUT_DIR) { |
| Jiyong Park | 1d2df7d | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 533 | generate_write_to_parcel(arg->GetType(), statements, v, transact_reply, true, |
| 534 | types->typenames_); |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 535 | } |
| Christopher Wiley | 67502f1 | 2016-01-29 10:57:00 -0800 | [diff] [blame] | 536 | } |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 537 | |
| Christopher Wiley | 67502f1 | 2016-01-29 10:57:00 -0800 | [diff] [blame] | 538 | // return true |
| Andreas Gampe | 7d7fa60 | 2017-11-22 10:50:03 -0800 | [diff] [blame] | 539 | statements->Add(new ReturnStatement(TRUE_VALUE)); |
| 540 | } |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 541 | |
| Jiyong Park | fbbfa93 | 2018-07-30 21:44:10 +0900 | [diff] [blame] | 542 | static void generate_stub_case(const AidlInterface& iface, const AidlMethod& method, |
| 543 | const std::string& transactCodeName, bool oneway, |
| 544 | StubClass* stubClass, JavaTypeNamespace* types, |
| 545 | const Options& options) { |
| Andreas Gampe | 7d7fa60 | 2017-11-22 10:50:03 -0800 | [diff] [blame] | 546 | Case* c = new Case(transactCodeName); |
| 547 | |
| Jiyong Park | fbbfa93 | 2018-07-30 21:44:10 +0900 | [diff] [blame] | 548 | generate_stub_code(iface, method, oneway, stubClass->transact_data, stubClass->transact_reply, |
| 549 | types, c->statements, stubClass, options); |
| Andreas Gampe | 7d7fa60 | 2017-11-22 10:50:03 -0800 | [diff] [blame] | 550 | |
| 551 | stubClass->transact_switch->cases.push_back(c); |
| 552 | } |
| 553 | |
| Jiyong Park | fbbfa93 | 2018-07-30 21:44:10 +0900 | [diff] [blame] | 554 | static void generate_stub_case_outline(const AidlInterface& iface, const AidlMethod& method, |
| 555 | const std::string& transactCodeName, bool oneway, |
| 556 | StubClass* stubClass, JavaTypeNamespace* types, |
| 557 | const Options& options) { |
| Andreas Gampe | 1b865af | 2017-11-22 11:31:47 -0800 | [diff] [blame] | 558 | std::string outline_name = "onTransact$" + method.GetName() + "$"; |
| 559 | // Generate an "outlined" method with the actual code. |
| 560 | { |
| Jeongik Cha | dc77c1b | 2019-02-12 16:13:25 +0900 | [diff] [blame] | 561 | Variable* transact_data = new Variable(types->ParcelType()->JavaType(), "data"); |
| 562 | Variable* transact_reply = new Variable(types->ParcelType()->JavaType(), "reply"); |
| Andreas Gampe | 1b865af | 2017-11-22 11:31:47 -0800 | [diff] [blame] | 563 | Method* onTransact_case = new Method; |
| 564 | onTransact_case->modifiers = PRIVATE; |
| Jeongik Cha | 6cadc21 | 2019-02-12 18:16:03 +0900 | [diff] [blame] | 565 | onTransact_case->returnType = types->BoolType()->JavaType(); |
| Andreas Gampe | 1b865af | 2017-11-22 11:31:47 -0800 | [diff] [blame] | 566 | onTransact_case->name = outline_name; |
| 567 | onTransact_case->parameters.push_back(transact_data); |
| 568 | onTransact_case->parameters.push_back(transact_reply); |
| 569 | onTransact_case->statements = new StatementBlock; |
| Jeongik Cha | 6cadc21 | 2019-02-12 18:16:03 +0900 | [diff] [blame] | 570 | onTransact_case->exceptions.push_back(types->RemoteExceptionType()->JavaType()); |
| Andreas Gampe | 1b865af | 2017-11-22 11:31:47 -0800 | [diff] [blame] | 571 | stubClass->elements.push_back(onTransact_case); |
| 572 | |
| Jiyong Park | fbbfa93 | 2018-07-30 21:44:10 +0900 | [diff] [blame] | 573 | generate_stub_code(iface, method, oneway, transact_data, transact_reply, types, |
| 574 | onTransact_case->statements, stubClass, options); |
| Andreas Gampe | 1b865af | 2017-11-22 11:31:47 -0800 | [diff] [blame] | 575 | } |
| 576 | |
| 577 | // Generate the case dispatch. |
| 578 | { |
| 579 | Case* c = new Case(transactCodeName); |
| 580 | |
| 581 | MethodCall* helper_call = new MethodCall(THIS_VALUE, |
| 582 | outline_name, |
| 583 | 2, |
| 584 | stubClass->transact_data, |
| 585 | stubClass->transact_reply); |
| 586 | c->statements->Add(new ReturnStatement(helper_call)); |
| 587 | |
| 588 | stubClass->transact_switch->cases.push_back(c); |
| 589 | } |
| 590 | } |
| 591 | |
| Andreas Gampe | 7d7fa60 | 2017-11-22 10:50:03 -0800 | [diff] [blame] | 592 | static std::unique_ptr<Method> generate_proxy_method( |
| Jiyong Park | fbbfa93 | 2018-07-30 21:44:10 +0900 | [diff] [blame] | 593 | const AidlInterface& iface, const AidlMethod& method, const std::string& transactCodeName, |
| 594 | bool oneway, ProxyClass* proxyClass, JavaTypeNamespace* types, const Options& options) { |
| Andreas Gampe | 7d7fa60 | 2017-11-22 10:50:03 -0800 | [diff] [blame] | 595 | std::unique_ptr<Method> proxy(new Method); |
| Christopher Wiley | 67502f1 | 2016-01-29 10:57:00 -0800 | [diff] [blame] | 596 | proxy->comment = method.GetComments(); |
| 597 | proxy->modifiers = PUBLIC | OVERRIDE; |
| Jeongik Cha | 6cadc21 | 2019-02-12 18:16:03 +0900 | [diff] [blame] | 598 | proxy->returnType = method.GetType().GetLanguageType<Type>()->JavaType(); |
| Christopher Wiley | 67502f1 | 2016-01-29 10:57:00 -0800 | [diff] [blame] | 599 | proxy->returnTypeDimension = method.GetType().IsArray() ? 1 : 0; |
| 600 | proxy->name = method.GetName(); |
| 601 | proxy->statements = new StatementBlock; |
| 602 | for (const std::unique_ptr<AidlArgument>& arg : method.GetArguments()) { |
| Jeongik Cha | dc77c1b | 2019-02-12 16:13:25 +0900 | [diff] [blame] | 603 | proxy->parameters.push_back(new Variable(arg->GetType().GetLanguageType<Type>()->JavaType(), |
| 604 | arg->GetName(), arg->GetType().IsArray() ? 1 : 0)); |
| Christopher Wiley | 67502f1 | 2016-01-29 10:57:00 -0800 | [diff] [blame] | 605 | } |
| Jeongik Cha | 6cadc21 | 2019-02-12 18:16:03 +0900 | [diff] [blame] | 606 | proxy->exceptions.push_back(types->RemoteExceptionType()->JavaType()); |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 607 | |
| Christopher Wiley | 67502f1 | 2016-01-29 10:57:00 -0800 | [diff] [blame] | 608 | // the parcels |
| Jeongik Cha | dc77c1b | 2019-02-12 16:13:25 +0900 | [diff] [blame] | 609 | Variable* _data = new Variable(types->ParcelType()->JavaType(), "_data"); |
| Jeongik Cha | 439f2c4 | 2019-02-13 12:38:30 +0900 | [diff] [blame] | 610 | proxy->statements->Add( |
| 611 | new VariableDeclaration(_data, new MethodCall(types->ParcelType()->JavaType(), "obtain"))); |
| Yi Kong | 894d6ba | 2018-07-24 11:27:38 -0700 | [diff] [blame] | 612 | Variable* _reply = nullptr; |
| Christopher Wiley | 67502f1 | 2016-01-29 10:57:00 -0800 | [diff] [blame] | 613 | if (!oneway) { |
| Jeongik Cha | dc77c1b | 2019-02-12 16:13:25 +0900 | [diff] [blame] | 614 | _reply = new Variable(types->ParcelType()->JavaType(), "_reply"); |
| Jeongik Cha | 439f2c4 | 2019-02-13 12:38:30 +0900 | [diff] [blame] | 615 | proxy->statements->Add( |
| 616 | new VariableDeclaration(_reply, new MethodCall(types->ParcelType()->JavaType(), "obtain"))); |
| Christopher Wiley | 67502f1 | 2016-01-29 10:57:00 -0800 | [diff] [blame] | 617 | } |
| 618 | |
| 619 | // the return value |
| Yi Kong | 894d6ba | 2018-07-24 11:27:38 -0700 | [diff] [blame] | 620 | Variable* _result = nullptr; |
| Christopher Wiley | 67502f1 | 2016-01-29 10:57:00 -0800 | [diff] [blame] | 621 | if (method.GetType().GetName() != "void") { |
| Jeongik Cha | 6cadc21 | 2019-02-12 18:16:03 +0900 | [diff] [blame] | 622 | _result = new Variable(*proxy->returnType, "_result", method.GetType().IsArray() ? 1 : 0); |
| Christopher Wiley | 67502f1 | 2016-01-29 10:57:00 -0800 | [diff] [blame] | 623 | proxy->statements->Add(new VariableDeclaration(_result)); |
| 624 | } |
| 625 | |
| 626 | // try and finally |
| 627 | TryStatement* tryStatement = new TryStatement(); |
| 628 | proxy->statements->Add(tryStatement); |
| 629 | FinallyStatement* finallyStatement = new FinallyStatement(); |
| 630 | proxy->statements->Add(finallyStatement); |
| 631 | |
| Jiyong Park | fbbfa93 | 2018-07-30 21:44:10 +0900 | [diff] [blame] | 632 | if (options.GenTraces()) { |
| Martijn Coenen | f1b5078 | 2018-02-21 21:06:23 +0100 | [diff] [blame] | 633 | tryStatement->statements->Add(new MethodCall( |
| 634 | new LiteralExpression("android.os.Trace"), "traceBegin", 2, |
| 635 | new LiteralExpression("android.os.Trace.TRACE_TAG_AIDL"), |
| 636 | new StringLiteralExpression(iface.GetName() + "::" + |
| 637 | method.GetName() + "::client"))); |
| 638 | } |
| 639 | |
| Christopher Wiley | 67502f1 | 2016-01-29 10:57:00 -0800 | [diff] [blame] | 640 | // the interface identifier token: the DESCRIPTOR constant, marshalled as a |
| 641 | // string |
| 642 | tryStatement->statements->Add(new MethodCall( |
| 643 | _data, "writeInterfaceToken", 1, new LiteralExpression("DESCRIPTOR"))); |
| 644 | |
| 645 | // the parameters |
| 646 | for (const std::unique_ptr<AidlArgument>& arg : method.GetArguments()) { |
| 647 | const Type* t = arg->GetType().GetLanguageType<Type>(); |
| Jeongik Cha | dc77c1b | 2019-02-12 16:13:25 +0900 | [diff] [blame] | 648 | Variable* v = new Variable(t->JavaType(), arg->GetName(), arg->GetType().IsArray() ? 1 : 0); |
| Christopher Wiley | 67502f1 | 2016-01-29 10:57:00 -0800 | [diff] [blame] | 649 | AidlArgument::Direction dir = arg->GetDirection(); |
| 650 | if (dir == AidlArgument::OUT_DIR && arg->GetType().IsArray()) { |
| 651 | IfStatement* checklen = new IfStatement(); |
| 652 | checklen->expression = new Comparison(v, "==", NULL_VALUE); |
| 653 | checklen->statements->Add( |
| 654 | new MethodCall(_data, "writeInt", 1, new LiteralExpression("-1"))); |
| 655 | checklen->elseif = new IfStatement(); |
| 656 | checklen->elseif->statements->Add( |
| 657 | new MethodCall(_data, "writeInt", 1, new FieldVariable(v, "length"))); |
| 658 | tryStatement->statements->Add(checklen); |
| 659 | } else if (dir & AidlArgument::IN_DIR) { |
| Jiyong Park | 1d2df7d | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 660 | generate_write_to_parcel(arg->GetType(), tryStatement->statements, v, _data, false, |
| 661 | types->typenames_); |
| Christopher Wiley | 5f84852 | 2016-03-01 16:29:41 -0800 | [diff] [blame] | 662 | } else { |
| 663 | delete v; |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 664 | } |
| Christopher Wiley | 67502f1 | 2016-01-29 10:57:00 -0800 | [diff] [blame] | 665 | } |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 666 | |
| Christopher Wiley | 67502f1 | 2016-01-29 10:57:00 -0800 | [diff] [blame] | 667 | // the transact call |
| Jiyong Park | 75e1a74 | 2018-07-04 12:31:23 +0900 | [diff] [blame] | 668 | unique_ptr<MethodCall> call(new MethodCall( |
| 669 | proxyClass->mRemote, "transact", 4, new LiteralExpression("Stub." + transactCodeName), _data, |
| Christopher Wiley | 67502f1 | 2016-01-29 10:57:00 -0800 | [diff] [blame] | 670 | _reply ? _reply : NULL_VALUE, |
| Jiyong Park | 75e1a74 | 2018-07-04 12:31:23 +0900 | [diff] [blame] | 671 | new LiteralExpression(oneway ? "android.os.IBinder.FLAG_ONEWAY" : "0"))); |
| Jeongik Cha | dc77c1b | 2019-02-12 16:13:25 +0900 | [diff] [blame] | 672 | unique_ptr<Variable> _status(new Variable(types->BoolType()->JavaType(), "_status")); |
| Jiyong Park | 75e1a74 | 2018-07-04 12:31:23 +0900 | [diff] [blame] | 673 | tryStatement->statements->Add(new VariableDeclaration(_status.release(), call.release())); |
| 674 | |
| 675 | // If the transaction returns false, which means UNKNOWN_TRANSACTION, fall |
| 676 | // back to the local method in the default impl, if set before. |
| 677 | vector<string> arg_names; |
| 678 | for (const auto& arg : method.GetArguments()) { |
| 679 | arg_names.emplace_back(arg->GetName()); |
| 680 | } |
| 681 | bool has_return_type = method.GetType().GetName() != "void"; |
| 682 | tryStatement->statements->Add(new LiteralStatement( |
| 683 | android::base::StringPrintf(has_return_type ? "if (!_status && getDefaultImpl() != null) {\n" |
| 684 | " return getDefaultImpl().%s(%s);\n" |
| 685 | "}\n" |
| 686 | : "if (!_status && getDefaultImpl() != null) {\n" |
| 687 | " getDefaultImpl().%s(%s);\n" |
| 688 | " return;\n" |
| 689 | "}\n", |
| 690 | method.GetName().c_str(), Join(arg_names, ", ").c_str()))); |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 691 | |
| Christopher Wiley | 67502f1 | 2016-01-29 10:57:00 -0800 | [diff] [blame] | 692 | // throw back exceptions. |
| 693 | if (_reply) { |
| 694 | MethodCall* ex = new MethodCall(_reply, "readException", 0); |
| 695 | tryStatement->statements->Add(ex); |
| 696 | } |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 697 | |
| Christopher Wiley | 67502f1 | 2016-01-29 10:57:00 -0800 | [diff] [blame] | 698 | // returning and cleanup |
| Yi Kong | 894d6ba | 2018-07-24 11:27:38 -0700 | [diff] [blame] | 699 | if (_reply != nullptr) { |
| Jiyong Park | 1d2df7d | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 700 | // keep this across return value and arguments in order to create the |
| 701 | // classloader at most once. |
| 702 | bool is_classloader_created = false; |
| Yi Kong | 894d6ba | 2018-07-24 11:27:38 -0700 | [diff] [blame] | 703 | if (_result != nullptr) { |
| Jiyong Park | 1d2df7d | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 704 | string code; |
| 705 | CodeWriterPtr writer = CodeWriter::ForString(&code); |
| 706 | CodeGeneratorContext context{.writer = *(writer.get()), |
| 707 | .typenames = types->typenames_, |
| 708 | .type = method.GetType(), |
| 709 | .var = _result->name, |
| 710 | .parcel = _reply->name, |
| 711 | .is_classloader_created = &is_classloader_created}; |
| 712 | CreateFromParcelFor(context); |
| 713 | writer->Close(); |
| 714 | tryStatement->statements->Add(new LiteralStatement(code)); |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 715 | } |
| Christopher Wiley | 67502f1 | 2016-01-29 10:57:00 -0800 | [diff] [blame] | 716 | |
| 717 | // the out/inout parameters |
| 718 | for (const std::unique_ptr<AidlArgument>& arg : method.GetArguments()) { |
| Christopher Wiley | 67502f1 | 2016-01-29 10:57:00 -0800 | [diff] [blame] | 719 | if (arg->GetDirection() & AidlArgument::OUT_DIR) { |
| Jiyong Park | 1d2df7d | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 720 | string code; |
| 721 | CodeWriterPtr writer = CodeWriter::ForString(&code); |
| 722 | CodeGeneratorContext context{.writer = *(writer.get()), |
| 723 | .typenames = types->typenames_, |
| 724 | .type = arg->GetType(), |
| 725 | .var = arg->GetName(), |
| 726 | .parcel = _reply->name, |
| 727 | .is_classloader_created = &is_classloader_created}; |
| 728 | ReadFromParcelFor(context); |
| 729 | writer->Close(); |
| 730 | tryStatement->statements->Add(new LiteralStatement(code)); |
| Christopher Wiley | 67502f1 | 2016-01-29 10:57:00 -0800 | [diff] [blame] | 731 | } |
| 732 | } |
| 733 | |
| 734 | finallyStatement->statements->Add(new MethodCall(_reply, "recycle")); |
| 735 | } |
| 736 | finallyStatement->statements->Add(new MethodCall(_data, "recycle")); |
| 737 | |
| Jiyong Park | fbbfa93 | 2018-07-30 21:44:10 +0900 | [diff] [blame] | 738 | if (options.GenTraces()) { |
| Martijn Coenen | f1b5078 | 2018-02-21 21:06:23 +0100 | [diff] [blame] | 739 | finallyStatement->statements->Add(new MethodCall( |
| 740 | new LiteralExpression("android.os.Trace"), "traceEnd", 1, |
| 741 | new LiteralExpression("android.os.Trace.TRACE_TAG_AIDL"))); |
| 742 | } |
| 743 | |
| Yi Kong | 894d6ba | 2018-07-24 11:27:38 -0700 | [diff] [blame] | 744 | if (_result != nullptr) { |
| Christopher Wiley | 67502f1 | 2016-01-29 10:57:00 -0800 | [diff] [blame] | 745 | proxy->statements->Add(new ReturnStatement(_result)); |
| 746 | } |
| Andreas Gampe | 7d7fa60 | 2017-11-22 10:50:03 -0800 | [diff] [blame] | 747 | |
| 748 | return proxy; |
| 749 | } |
| 750 | |
| Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 751 | static void generate_methods(const AidlInterface& iface, const AidlMethod& method, Class* interface, |
| 752 | StubClass* stubClass, ProxyClass* proxyClass, int index, |
| 753 | JavaTypeNamespace* types, const Options& options) { |
| Steven Moreland | acd5347 | 2018-12-14 10:17:26 -0800 | [diff] [blame] | 754 | const bool oneway = method.IsOneway(); |
| Andreas Gampe | 7d7fa60 | 2017-11-22 10:50:03 -0800 | [diff] [blame] | 755 | |
| 756 | // == the TRANSACT_ constant ============================================= |
| 757 | string transactCodeName = "TRANSACTION_"; |
| 758 | transactCodeName += method.GetName(); |
| 759 | |
| Jeongik Cha | dc77c1b | 2019-02-12 16:13:25 +0900 | [diff] [blame] | 760 | Field* transactCode = |
| 761 | new Field(STATIC | FINAL, new Variable(types->IntType()->JavaType(), transactCodeName)); |
| Andreas Gampe | 7d7fa60 | 2017-11-22 10:50:03 -0800 | [diff] [blame] | 762 | transactCode->value = |
| 763 | StringPrintf("(android.os.IBinder.FIRST_CALL_TRANSACTION + %d)", index); |
| 764 | stubClass->elements.push_back(transactCode); |
| 765 | |
| Olivier Gaillard | 1140140 | 2018-07-05 15:01:34 +0100 | [diff] [blame] | 766 | // getTransactionName |
| Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 767 | if (options.GenTransactionNames()) { |
| Olivier Gaillard | 1140140 | 2018-07-05 15:01:34 +0100 | [diff] [blame] | 768 | Case* c = new Case(transactCodeName); |
| 769 | c->statements->Add(new ReturnStatement(new StringLiteralExpression(method.GetName()))); |
| 770 | stubClass->code_to_method_name_switch->cases.push_back(c); |
| 771 | } |
| 772 | |
| Andreas Gampe | 7d7fa60 | 2017-11-22 10:50:03 -0800 | [diff] [blame] | 773 | // == the declaration in the interface =================================== |
| Jiyong Park | 309668e | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 774 | ClassElement* decl; |
| 775 | if (method.IsUserDefined()) { |
| 776 | decl = generate_interface_method(method, types).release(); |
| 777 | } else { |
| 778 | if (method.GetName() == kGetInterfaceVersion && options.Version() > 0) { |
| 779 | std::ostringstream code; |
| 780 | code << "public int " << kGetInterfaceVersion << "() " |
| 781 | << "throws android.os.RemoteException;\n"; |
| 782 | decl = new LiteralClassElement(code.str()); |
| 783 | } |
| 784 | } |
| Andreas Gampe | 7d7fa60 | 2017-11-22 10:50:03 -0800 | [diff] [blame] | 785 | interface->elements.push_back(decl); |
| 786 | |
| 787 | // == the stub method ==================================================== |
| Jiyong Park | 309668e | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 788 | if (method.IsUserDefined()) { |
| 789 | bool outline_stub = |
| 790 | stubClass->transact_outline && stubClass->outline_methods.count(&method) != 0; |
| 791 | if (outline_stub) { |
| 792 | generate_stub_case_outline(iface, method, transactCodeName, oneway, stubClass, types, |
| 793 | options); |
| 794 | } else { |
| 795 | generate_stub_case(iface, method, transactCodeName, oneway, stubClass, types, options); |
| 796 | } |
| Andreas Gampe | 1b865af | 2017-11-22 11:31:47 -0800 | [diff] [blame] | 797 | } else { |
| Jiyong Park | 309668e | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 798 | if (method.GetName() == kGetInterfaceVersion && options.Version() > 0) { |
| 799 | Case* c = new Case(transactCodeName); |
| 800 | std::ostringstream code; |
| Jiyong Park | 965c5b9 | 2018-11-21 13:37:15 +0900 | [diff] [blame] | 801 | code << "data.enforceInterface(descriptor);\n" |
| 802 | << "reply.writeNoException();\n" |
| 803 | << "reply.writeInt(" << kGetInterfaceVersion << "());\n" |
| Jiyong Park | 309668e | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 804 | << "return true;\n"; |
| 805 | c->statements->Add(new LiteralStatement(code.str())); |
| 806 | stubClass->transact_switch->cases.push_back(c); |
| 807 | } |
| Andreas Gampe | 1b865af | 2017-11-22 11:31:47 -0800 | [diff] [blame] | 808 | } |
| Andreas Gampe | 7d7fa60 | 2017-11-22 10:50:03 -0800 | [diff] [blame] | 809 | |
| 810 | // == the proxy method =================================================== |
| Jiyong Park | 309668e | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 811 | ClassElement* proxy = nullptr; |
| 812 | if (method.IsUserDefined()) { |
| 813 | proxy = |
| 814 | generate_proxy_method(iface, method, transactCodeName, oneway, proxyClass, types, options) |
| 815 | .release(); |
| 816 | |
| 817 | } else { |
| 818 | if (method.GetName() == kGetInterfaceVersion && options.Version() > 0) { |
| 819 | std::ostringstream code; |
| 820 | code << "@Override\n" |
| 821 | << "public int " << kGetInterfaceVersion << "()" |
| 822 | << " throws " |
| 823 | << "android.os.RemoteException {\n" |
| 824 | << " if (mCachedVersion == -1) {\n" |
| 825 | << " android.os.Parcel data = android.os.Parcel.obtain();\n" |
| 826 | << " android.os.Parcel reply = android.os.Parcel.obtain();\n" |
| 827 | << " try {\n" |
| Jiyong Park | 965c5b9 | 2018-11-21 13:37:15 +0900 | [diff] [blame] | 828 | << " data.writeInterfaceToken(DESCRIPTOR);\n" |
| Jiyong Park | 309668e | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 829 | << " mRemote.transact(Stub." << transactCodeName << ", " |
| 830 | << "data, reply, 0);\n" |
| Jeongik Cha | e58e2ae | 2019-05-20 18:45:05 +0900 | [diff] [blame] | 831 | << " reply.readException();\n" |
| Jiyong Park | 309668e | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 832 | << " mCachedVersion = reply.readInt();\n" |
| 833 | << " } finally {\n" |
| 834 | << " reply.recycle();\n" |
| 835 | << " data.recycle();\n" |
| 836 | << " }\n" |
| 837 | << " }\n" |
| 838 | << " return mCachedVersion;\n" |
| 839 | << "}\n"; |
| 840 | proxy = new LiteralClassElement(code.str()); |
| 841 | } |
| 842 | } |
| 843 | if (proxy != nullptr) { |
| 844 | proxyClass->elements.push_back(proxy); |
| 845 | } |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 846 | } |
| 847 | |
| Christopher Wiley | 67502f1 | 2016-01-29 10:57:00 -0800 | [diff] [blame] | 848 | static void generate_interface_descriptors(StubClass* stub, ProxyClass* proxy, |
| 849 | const JavaTypeNamespace* types) { |
| 850 | // the interface descriptor transaction handler |
| 851 | Case* c = new Case("INTERFACE_TRANSACTION"); |
| 852 | c->statements->Add(new MethodCall(stub->transact_reply, "writeString", 1, |
| Andreas Gampe | e9c816e | 2018-03-14 09:05:48 -0700 | [diff] [blame] | 853 | stub->get_transact_descriptor(types, |
| 854 | nullptr))); |
| Christopher Wiley | 67502f1 | 2016-01-29 10:57:00 -0800 | [diff] [blame] | 855 | c->statements->Add(new ReturnStatement(TRUE_VALUE)); |
| 856 | stub->transact_switch->cases.push_back(c); |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 857 | |
| Christopher Wiley | 67502f1 | 2016-01-29 10:57:00 -0800 | [diff] [blame] | 858 | // and the proxy-side method returning the descriptor directly |
| 859 | Method* getDesc = new Method; |
| 860 | getDesc->modifiers = PUBLIC; |
| Jeongik Cha | 6cadc21 | 2019-02-12 18:16:03 +0900 | [diff] [blame] | 861 | getDesc->returnType = types->StringType()->JavaType(); |
| Christopher Wiley | 67502f1 | 2016-01-29 10:57:00 -0800 | [diff] [blame] | 862 | getDesc->returnTypeDimension = 0; |
| 863 | getDesc->name = "getInterfaceDescriptor"; |
| 864 | getDesc->statements = new StatementBlock; |
| 865 | getDesc->statements->Add( |
| 866 | new ReturnStatement(new LiteralExpression("DESCRIPTOR"))); |
| 867 | proxy->elements.push_back(getDesc); |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 868 | } |
| 869 | |
| Andreas Gampe | e9c816e | 2018-03-14 09:05:48 -0700 | [diff] [blame] | 870 | // Check whether (some) methods in this interface should be "outlined," that |
| 871 | // is, have specific onTransact methods for certain cases. Set up StubClass |
| 872 | // metadata accordingly. |
| 873 | // |
| 874 | // Outlining will be enabled if the interface has more than outline_threshold |
| 875 | // methods. In that case, the methods are sorted by number of arguments |
| 876 | // (so that more "complex" methods come later), and the first non_outline_count |
| 877 | // number of methods not outlined (are kept in the onTransact() method). |
| 878 | // |
| 879 | // Requirements: non_outline_count <= outline_threshold. |
| 880 | static void compute_outline_methods(const AidlInterface* iface, |
| 881 | StubClass* stub, |
| 882 | size_t outline_threshold, |
| 883 | size_t non_outline_count) { |
| 884 | CHECK_LE(non_outline_count, outline_threshold); |
| 885 | // We'll outline (create sub methods) if there are more than min_methods |
| 886 | // cases. |
| 887 | stub->transact_outline = iface->GetMethods().size() > outline_threshold; |
| 888 | if (stub->transact_outline) { |
| 889 | stub->all_method_count = iface->GetMethods().size(); |
| 890 | std::vector<const AidlMethod*> methods; |
| 891 | methods.reserve(iface->GetMethods().size()); |
| 892 | for (const std::unique_ptr<AidlMethod>& ptr : iface->GetMethods()) { |
| 893 | methods.push_back(ptr.get()); |
| 894 | } |
| 895 | |
| 896 | std::stable_sort( |
| 897 | methods.begin(), |
| 898 | methods.end(), |
| 899 | [](const AidlMethod* m1, const AidlMethod* m2) { |
| 900 | return m1->GetArguments().size() < m2->GetArguments().size(); |
| 901 | }); |
| 902 | |
| 903 | stub->outline_methods.insert(methods.begin() + non_outline_count, |
| 904 | methods.end()); |
| 905 | } |
| 906 | } |
| 907 | |
| Jiyong Park | 75e1a74 | 2018-07-04 12:31:23 +0900 | [diff] [blame] | 908 | static unique_ptr<ClassElement> generate_default_impl_method(const AidlMethod& method) { |
| 909 | unique_ptr<Method> default_method(new Method); |
| 910 | default_method->comment = method.GetComments(); |
| 911 | default_method->modifiers = PUBLIC | OVERRIDE; |
| Jeongik Cha | 6cadc21 | 2019-02-12 18:16:03 +0900 | [diff] [blame] | 912 | default_method->returnType = method.GetType().GetLanguageType<Type>()->JavaType(); |
| Jiyong Park | 75e1a74 | 2018-07-04 12:31:23 +0900 | [diff] [blame] | 913 | default_method->returnTypeDimension = method.GetType().IsArray() ? 1 : 0; |
| 914 | default_method->name = method.GetName(); |
| 915 | default_method->statements = new StatementBlock; |
| 916 | for (const auto& arg : method.GetArguments()) { |
| Jeongik Cha | dc77c1b | 2019-02-12 16:13:25 +0900 | [diff] [blame] | 917 | default_method->parameters.push_back( |
| 918 | new Variable(arg->GetType().GetLanguageType<Type>()->JavaType(), arg->GetName(), |
| 919 | arg->GetType().IsArray() ? 1 : 0)); |
| Jiyong Park | 75e1a74 | 2018-07-04 12:31:23 +0900 | [diff] [blame] | 920 | } |
| Jeongik Cha | 6cadc21 | 2019-02-12 18:16:03 +0900 | [diff] [blame] | 921 | default_method->exceptions.push_back(method.GetType() |
| 922 | .GetLanguageType<Type>() |
| 923 | ->GetTypeNamespace() |
| 924 | ->RemoteExceptionType() |
| 925 | ->JavaType()); |
| Jiyong Park | 75e1a74 | 2018-07-04 12:31:23 +0900 | [diff] [blame] | 926 | |
| 927 | if (method.GetType().GetName() != "void") { |
| Jiyong Park | 1d2df7d | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 928 | const string& defaultValue = DefaultJavaValueOf(method.GetType()); |
| Jiyong Park | 75e1a74 | 2018-07-04 12:31:23 +0900 | [diff] [blame] | 929 | default_method->statements->Add( |
| 930 | new LiteralStatement(StringPrintf("return %s;\n", defaultValue.c_str()))); |
| 931 | } |
| 932 | return default_method; |
| 933 | } |
| 934 | |
| Jiyong Park | 309668e | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 935 | static unique_ptr<Class> generate_default_impl_class(const AidlInterface& iface, |
| 936 | const Options& options) { |
| Jiyong Park | 75e1a74 | 2018-07-04 12:31:23 +0900 | [diff] [blame] | 937 | unique_ptr<Class> default_class(new Class); |
| 938 | default_class->comment = "/** Default implementation for " + iface.GetName() + ". */"; |
| 939 | default_class->modifiers = PUBLIC | STATIC; |
| 940 | default_class->what = Class::CLASS; |
| Jeongik Cha | aabc144 | 2019-02-12 17:44:48 +0900 | [diff] [blame] | 941 | default_class->type = iface.GetLanguageType<InterfaceType>()->GetDefaultImpl()->JavaType(); |
| 942 | default_class->interfaces.emplace_back(iface.GetLanguageType<InterfaceType>()->JavaType()); |
| Jiyong Park | 75e1a74 | 2018-07-04 12:31:23 +0900 | [diff] [blame] | 943 | |
| 944 | for (const auto& m : iface.GetMethods()) { |
| Jiyong Park | 309668e | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 945 | if (m->IsUserDefined()) { |
| 946 | default_class->elements.emplace_back(generate_default_impl_method(*(m.get())).release()); |
| 947 | } else { |
| 948 | if (m->GetName() == kGetInterfaceVersion && options.Version() > 0) { |
| Jiyong Park | a2f9ca3 | 2018-08-01 21:04:11 +0900 | [diff] [blame] | 949 | // This is called only when the remote side is not implementing this |
| 950 | // method, which is impossible in normal case, because this method is |
| 951 | // automatically declared in the interface class and not implementing |
| 952 | // it in the remote side is causing compilation error. But if the remote |
| 953 | // side somehow managed to not implement it, that's an error and we |
| 954 | // report the case by returning -1 here. |
| Jiyong Park | 309668e | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 955 | std::ostringstream code; |
| 956 | code << "@Override\n" |
| 957 | << "public int " << kGetInterfaceVersion << "() {\n" |
| Jiyong Park | a2f9ca3 | 2018-08-01 21:04:11 +0900 | [diff] [blame] | 958 | << " return -1;\n" |
| Jiyong Park | 309668e | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 959 | << "}\n"; |
| 960 | default_class->elements.emplace_back(new LiteralClassElement(code.str())); |
| 961 | } |
| 962 | } |
| Jiyong Park | 75e1a74 | 2018-07-04 12:31:23 +0900 | [diff] [blame] | 963 | } |
| 964 | |
| 965 | default_class->elements.emplace_back( |
| 966 | new LiteralClassElement("@Override\n" |
| 967 | "public android.os.IBinder asBinder() {\n" |
| 968 | " return null;\n" |
| 969 | "}\n")); |
| 970 | |
| 971 | return default_class; |
| 972 | } |
| 973 | |
| Jiyong Park | 74595c1 | 2018-07-23 15:22:50 +0900 | [diff] [blame] | 974 | Class* generate_binder_interface_class(const AidlInterface* iface, JavaTypeNamespace* types, |
| 975 | const Options& options) { |
| Christopher Wiley | 67502f1 | 2016-01-29 10:57:00 -0800 | [diff] [blame] | 976 | const InterfaceType* interfaceType = iface->GetLanguageType<InterfaceType>(); |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 977 | |
| Christopher Wiley | 67502f1 | 2016-01-29 10:57:00 -0800 | [diff] [blame] | 978 | // the interface class |
| 979 | Class* interface = new Class; |
| 980 | interface->comment = iface->GetComments(); |
| 981 | interface->modifiers = PUBLIC; |
| 982 | interface->what = Class::INTERFACE; |
| Jeongik Cha | aabc144 | 2019-02-12 17:44:48 +0900 | [diff] [blame] | 983 | interface->type = interfaceType->JavaType(); |
| 984 | interface->interfaces.push_back(types->IInterfaceType()->JavaType()); |
| Jiyong Park | a6605ab | 2018-11-11 14:30:21 +0900 | [diff] [blame] | 985 | interface->annotations = generate_java_annotations(*iface); |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 986 | |
| Jiyong Park | 309668e | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 987 | if (options.Version()) { |
| 988 | std::ostringstream code; |
| 989 | code << "/**\n" |
| 990 | << " * The version of this interface that the caller is built against.\n" |
| 991 | << " * This might be different from what {@link #getInterfaceVersion()\n" |
| 992 | << " * getInterfaceVersion} returns as that is the version of the interface\n" |
| 993 | << " * that the remote object is implementing.\n" |
| 994 | << " */\n" |
| 995 | << "public static final int VERSION = " << options.Version() << ";\n"; |
| 996 | interface->elements.emplace_back(new LiteralClassElement(code.str())); |
| 997 | } |
| 998 | |
| Jiyong Park | 75e1a74 | 2018-07-04 12:31:23 +0900 | [diff] [blame] | 999 | // the default impl class |
| Jiyong Park | 309668e | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 1000 | Class* default_impl = generate_default_impl_class(*iface, options).release(); |
| 1001 | interface->elements.emplace_back(default_impl); |
| Jiyong Park | 75e1a74 | 2018-07-04 12:31:23 +0900 | [diff] [blame] | 1002 | |
| Christopher Wiley | 67502f1 | 2016-01-29 10:57:00 -0800 | [diff] [blame] | 1003 | // the stub inner class |
| 1004 | StubClass* stub = |
| Olivier Gaillard | 1140140 | 2018-07-05 15:01:34 +0100 | [diff] [blame] | 1005 | new StubClass(interfaceType->GetStub(), interfaceType, types, options); |
| Christopher Wiley | 67502f1 | 2016-01-29 10:57:00 -0800 | [diff] [blame] | 1006 | interface->elements.push_back(stub); |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 1007 | |
| Andreas Gampe | e9c816e | 2018-03-14 09:05:48 -0700 | [diff] [blame] | 1008 | compute_outline_methods(iface, |
| 1009 | stub, |
| 1010 | options.onTransact_outline_threshold_, |
| 1011 | options.onTransact_non_outline_count_); |
| Andreas Gampe | 1b865af | 2017-11-22 11:31:47 -0800 | [diff] [blame] | 1012 | |
| Christopher Wiley | 67502f1 | 2016-01-29 10:57:00 -0800 | [diff] [blame] | 1013 | // the proxy inner class |
| Jiyong Park | 309668e | 2018-07-28 16:55:44 +0900 | [diff] [blame] | 1014 | ProxyClass* proxy = new ProxyClass(types, interfaceType->GetProxy(), interfaceType, options); |
| Christopher Wiley | 67502f1 | 2016-01-29 10:57:00 -0800 | [diff] [blame] | 1015 | stub->elements.push_back(proxy); |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 1016 | |
| Christopher Wiley | 67502f1 | 2016-01-29 10:57:00 -0800 | [diff] [blame] | 1017 | // stub and proxy support for getInterfaceDescriptor() |
| 1018 | generate_interface_descriptors(stub, proxy, types); |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 1019 | |
| Christopher Wiley | 67502f1 | 2016-01-29 10:57:00 -0800 | [diff] [blame] | 1020 | // all the declared constants of the interface |
| Steven Moreland | 693640b | 2018-07-19 13:46:27 -0700 | [diff] [blame] | 1021 | for (const auto& constant : iface->GetConstantDeclarations()) { |
| 1022 | const AidlConstantValue& value = constant->GetValue(); |
| 1023 | |
| 1024 | switch (value.GetType()) { |
| 1025 | case AidlConstantValue::Type::STRING: { |
| Steven Moreland | 860b194 | 2018-08-16 14:59:28 -0700 | [diff] [blame] | 1026 | generate_string_constant(interface, constant->GetName(), |
| 1027 | constant->ValueString(ConstantValueDecorator)); |
| Steven Moreland | 693640b | 2018-07-19 13:46:27 -0700 | [diff] [blame] | 1028 | break; |
| 1029 | } |
| Steven Moreland | 2529432 | 2018-08-07 18:13:55 -0700 | [diff] [blame] | 1030 | case AidlConstantValue::Type::INTEGRAL: |
| 1031 | case AidlConstantValue::Type::HEXIDECIMAL: { |
| Steven Moreland | 860b194 | 2018-08-16 14:59:28 -0700 | [diff] [blame] | 1032 | generate_int_constant(interface, constant->GetName(), |
| 1033 | constant->ValueString(ConstantValueDecorator)); |
| Steven Moreland | 693640b | 2018-07-19 13:46:27 -0700 | [diff] [blame] | 1034 | break; |
| 1035 | } |
| 1036 | default: { |
| 1037 | LOG(FATAL) << "Unrecognized constant type: " << static_cast<int>(value.GetType()); |
| 1038 | } |
| 1039 | } |
| Christopher Wiley | 67502f1 | 2016-01-29 10:57:00 -0800 | [diff] [blame] | 1040 | } |
| Casey Dahlin | d40e2fe | 2015-11-24 14:06:52 -0800 | [diff] [blame] | 1041 | |
| Christopher Wiley | 67502f1 | 2016-01-29 10:57:00 -0800 | [diff] [blame] | 1042 | // all the declared methods of the interface |
| Andreas Gampe | 1b865af | 2017-11-22 11:31:47 -0800 | [diff] [blame] | 1043 | |
| Christopher Wiley | 67502f1 | 2016-01-29 10:57:00 -0800 | [diff] [blame] | 1044 | for (const auto& item : iface->GetMethods()) { |
| Martijn Coenen | f1b5078 | 2018-02-21 21:06:23 +0100 | [diff] [blame] | 1045 | generate_methods(*iface, |
| 1046 | *item, |
| Andreas Gampe | 1b865af | 2017-11-22 11:31:47 -0800 | [diff] [blame] | 1047 | interface, |
| 1048 | stub, |
| 1049 | proxy, |
| 1050 | item->GetId(), |
| Olivier Gaillard | 1140140 | 2018-07-05 15:01:34 +0100 | [diff] [blame] | 1051 | types, |
| 1052 | options); |
| Christopher Wiley | 67502f1 | 2016-01-29 10:57:00 -0800 | [diff] [blame] | 1053 | } |
| Jiyong Park | 75e1a74 | 2018-07-04 12:31:23 +0900 | [diff] [blame] | 1054 | |
| 1055 | // additional static methods for the default impl set/get to the |
| 1056 | // stub class. Can't add them to the interface as the generated java files |
| 1057 | // may be compiled with Java < 1.7 where static interface method isn't |
| 1058 | // supported. |
| 1059 | // TODO(b/111417145) make this conditional depending on the Java language |
| 1060 | // version requested |
| 1061 | const string i_name = interfaceType->JavaType(); |
| 1062 | stub->elements.emplace_back(new LiteralClassElement( |
| 1063 | StringPrintf("public static boolean setDefaultImpl(%s impl) {\n" |
| 1064 | " if (Stub.Proxy.sDefaultImpl == null && impl != null) {\n" |
| 1065 | " Stub.Proxy.sDefaultImpl = impl;\n" |
| 1066 | " return true;\n" |
| 1067 | " }\n" |
| 1068 | " return false;\n" |
| 1069 | "}\n", |
| 1070 | i_name.c_str()))); |
| 1071 | stub->elements.emplace_back( |
| 1072 | new LiteralClassElement(StringPrintf("public static %s getDefaultImpl() {\n" |
| 1073 | " return Stub.Proxy.sDefaultImpl;\n" |
| 1074 | "}\n", |
| 1075 | i_name.c_str()))); |
| 1076 | |
| 1077 | // the static field is defined in the proxy class, not in the interface class |
| 1078 | // because all fields in an interface class are by default final. |
| 1079 | proxy->elements.emplace_back(new LiteralClassElement( |
| Jiyong Park | 47fb0d6 | 2018-11-17 10:12:15 +0900 | [diff] [blame] | 1080 | StringPrintf("public static %s sDefaultImpl;\n", i_name.c_str()))); |
| Jiyong Park | 75e1a74 | 2018-07-04 12:31:23 +0900 | [diff] [blame] | 1081 | |
| Andreas Gampe | a8a66fe | 2017-11-22 12:17:00 -0800 | [diff] [blame] | 1082 | stub->finish(); |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 1083 | |
| Christopher Wiley | 67502f1 | 2016-01-29 10:57:00 -0800 | [diff] [blame] | 1084 | return interface; |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 1085 | } |
| 1086 | |
| Christopher Wiley | db154a5 | 2015-09-28 16:32:25 -0700 | [diff] [blame] | 1087 | } // namespace java |
| Christopher Wiley | fdeb0f4 | 2015-09-11 15:38:22 -0700 | [diff] [blame] | 1088 | } // namespace android |
| 1089 | } // namespace aidl |