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