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