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