1 /*
2  * Copyright (C) 2015, 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 
17 #include "tests/test_data.h"
18 
19 namespace android {
20 namespace aidl {
21 namespace test_data {
22 namespace example_interface {
23 
24 const char kCanonicalName[] = "android.test.IExampleInterface";
25 
26 const char kJavaOutputPath[] = "some/path/to/output.java";
27 
28 const char* kImportedParcelables[] = {
29   "android.foo.ExampleParcelable",
30   nullptr,
31 };
32 
33 const char* kImportedInterfaces[] = {
34   "android.bar.IAuxInterface",
35   "android.test.IAuxInterface2",
36   nullptr,
37 };
38 
39 const char kInterfaceDefinition[] = R"(
40 package android.test;
41 
42 import android.foo.ExampleParcelable;
43 import android.test.CompoundParcelable;
44 import android.bar.IAuxInterface;
45 import android.test.IAuxInterface2;
46 
47 interface IExampleInterface {
48     const int EXAMPLE_CONSTANT = 3;
49     boolean isEnabled();
50     int getState();
51     String getAddress();
52 
53     /* Test long comment */
54     ExampleParcelable[] getParcelables();
55 
56     // Test short comment
57     boolean setScanMode(int mode, int duration);
58 
59     /* Test long comment */
60     // And short comment
61     void registerBinder(IAuxInterface foo);
62     IExampleInterface getRecursiveBinder();
63 
64     int takesAnInterface(in IAuxInterface2 arg);
65     int takesAParcelable(in CompoundParcelable.Subclass1 arg,
66                          inout CompoundParcelable.Subclass2 arg2);
67 }
68 )";
69 
70 const char kExpectedJavaDepsOutput[] =
71 R"(some/path/to/output.java : \
72   android/test/IExampleInterface.aidl \
73   ./android/foo/ExampleParcelable.aidl \
74   ./android/test/CompoundParcelable.aidl \
75   ./android/bar/IAuxInterface.aidl \
76   ./android/test/IAuxInterface2.aidl
77 
78 android/test/IExampleInterface.aidl :
79 ./android/foo/ExampleParcelable.aidl :
80 ./android/test/CompoundParcelable.aidl :
81 ./android/bar/IAuxInterface.aidl :
82 ./android/test/IAuxInterface2.aidl :
83 )";
84 
85 const char kExpectedJavaOutput[] =
86 R"(/*
87  * This file is auto-generated.  DO NOT MODIFY.
88  * Original file: android/test/IExampleInterface.aidl
89  */
90 package android.test;
91 public interface IExampleInterface extends android.os.IInterface
92 {
93 /** Local-side IPC implementation stub class. */
94 public static abstract class Stub extends android.os.Binder implements android.test.IExampleInterface
95 {
96 private static final java.lang.String DESCRIPTOR = "android.test.IExampleInterface";
97 /** Construct the stub at attach it to the interface. */
98 public Stub()
99 {
100 this.attachInterface(this, DESCRIPTOR);
101 }
102 /**
103  * Cast an IBinder object into an android.test.IExampleInterface interface,
104  * generating a proxy if needed.
105  */
106 public static android.test.IExampleInterface asInterface(android.os.IBinder obj)
107 {
108 if ((obj==null)) {
109 return null;
110 }
111 android.os.IInterface iin = obj.queryLocalInterface(DESCRIPTOR);
112 if (((iin!=null)&&(iin instanceof android.test.IExampleInterface))) {
113 return ((android.test.IExampleInterface)iin);
114 }
115 return new android.test.IExampleInterface.Stub.Proxy(obj);
116 }
117 @Override public android.os.IBinder asBinder()
118 {
119 return this;
120 }
121 @Override public boolean onTransact(int code, android.os.Parcel data, android.os.Parcel reply, int flags) throws android.os.RemoteException
122 {
123 switch (code)
124 {
125 case INTERFACE_TRANSACTION:
126 {
127 reply.writeString(DESCRIPTOR);
128 return true;
129 }
130 case TRANSACTION_isEnabled:
131 {
132 data.enforceInterface(DESCRIPTOR);
133 boolean _result = this.isEnabled();
134 reply.writeNoException();
135 reply.writeInt(((_result)?(1):(0)));
136 return true;
137 }
138 case TRANSACTION_getState:
139 {
140 data.enforceInterface(DESCRIPTOR);
141 int _result = this.getState();
142 reply.writeNoException();
143 reply.writeInt(_result);
144 return true;
145 }
146 case TRANSACTION_getAddress:
147 {
148 data.enforceInterface(DESCRIPTOR);
149 java.lang.String _result = this.getAddress();
150 reply.writeNoException();
151 reply.writeString(_result);
152 return true;
153 }
154 case TRANSACTION_getParcelables:
155 {
156 data.enforceInterface(DESCRIPTOR);
157 android.foo.ExampleParcelable[] _result = this.getParcelables();
158 reply.writeNoException();
159 reply.writeTypedArray(_result, android.os.Parcelable.PARCELABLE_WRITE_RETURN_VALUE);
160 return true;
161 }
162 case TRANSACTION_setScanMode:
163 {
164 data.enforceInterface(DESCRIPTOR);
165 int _arg0;
166 _arg0 = data.readInt();
167 int _arg1;
168 _arg1 = data.readInt();
169 boolean _result = this.setScanMode(_arg0, _arg1);
170 reply.writeNoException();
171 reply.writeInt(((_result)?(1):(0)));
172 return true;
173 }
174 case TRANSACTION_registerBinder:
175 {
176 data.enforceInterface(DESCRIPTOR);
177 android.bar.IAuxInterface _arg0;
178 _arg0 = android.bar.IAuxInterface.Stub.asInterface(data.readStrongBinder());
179 this.registerBinder(_arg0);
180 reply.writeNoException();
181 return true;
182 }
183 case TRANSACTION_getRecursiveBinder:
184 {
185 data.enforceInterface(DESCRIPTOR);
186 android.test.IExampleInterface _result = this.getRecursiveBinder();
187 reply.writeNoException();
188 reply.writeStrongBinder((((_result!=null))?(_result.asBinder()):(null)));
189 return true;
190 }
191 case TRANSACTION_takesAnInterface:
192 {
193 data.enforceInterface(DESCRIPTOR);
194 android.test.IAuxInterface2 _arg0;
195 _arg0 = android.test.IAuxInterface2.Stub.asInterface(data.readStrongBinder());
196 int _result = this.takesAnInterface(_arg0);
197 reply.writeNoException();
198 reply.writeInt(_result);
199 return true;
200 }
201 case TRANSACTION_takesAParcelable:
202 {
203 data.enforceInterface(DESCRIPTOR);
204 android.test.CompoundParcelable.Subclass1 _arg0;
205 if ((0!=data.readInt())) {
206 _arg0 = android.test.CompoundParcelable.Subclass1.CREATOR.createFromParcel(data);
207 }
208 else {
209 _arg0 = null;
210 }
211 android.test.CompoundParcelable.Subclass2 _arg1;
212 if ((0!=data.readInt())) {
213 _arg1 = android.test.CompoundParcelable.Subclass2.CREATOR.createFromParcel(data);
214 }
215 else {
216 _arg1 = null;
217 }
218 int _result = this.takesAParcelable(_arg0, _arg1);
219 reply.writeNoException();
220 reply.writeInt(_result);
221 if ((_arg1!=null)) {
222 reply.writeInt(1);
223 _arg1.writeToParcel(reply, android.os.Parcelable.PARCELABLE_WRITE_RETURN_VALUE);
224 }
225 else {
226 reply.writeInt(0);
227 }
228 return true;
229 }
230 }
231 return super.onTransact(code, data, reply, flags);
232 }
233 private static class Proxy implements android.test.IExampleInterface
234 {
235 private android.os.IBinder mRemote;
236 Proxy(android.os.IBinder remote)
237 {
238 mRemote = remote;
239 }
240 @Override public android.os.IBinder asBinder()
241 {
242 return mRemote;
243 }
244 public java.lang.String getInterfaceDescriptor()
245 {
246 return DESCRIPTOR;
247 }
248 @Override public boolean isEnabled() throws android.os.RemoteException
249 {
250 android.os.Parcel _data = android.os.Parcel.obtain();
251 android.os.Parcel _reply = android.os.Parcel.obtain();
252 boolean _result;
253 try {
254 _data.writeInterfaceToken(DESCRIPTOR);
255 mRemote.transact(Stub.TRANSACTION_isEnabled, _data, _reply, 0);
256 _reply.readException();
257 _result = (0!=_reply.readInt());
258 }
259 finally {
260 _reply.recycle();
261 _data.recycle();
262 }
263 return _result;
264 }
265 @Override public int getState() throws android.os.RemoteException
266 {
267 android.os.Parcel _data = android.os.Parcel.obtain();
268 android.os.Parcel _reply = android.os.Parcel.obtain();
269 int _result;
270 try {
271 _data.writeInterfaceToken(DESCRIPTOR);
272 mRemote.transact(Stub.TRANSACTION_getState, _data, _reply, 0);
273 _reply.readException();
274 _result = _reply.readInt();
275 }
276 finally {
277 _reply.recycle();
278 _data.recycle();
279 }
280 return _result;
281 }
282 @Override public java.lang.String getAddress() throws android.os.RemoteException
283 {
284 android.os.Parcel _data = android.os.Parcel.obtain();
285 android.os.Parcel _reply = android.os.Parcel.obtain();
286 java.lang.String _result;
287 try {
288 _data.writeInterfaceToken(DESCRIPTOR);
289 mRemote.transact(Stub.TRANSACTION_getAddress, _data, _reply, 0);
290 _reply.readException();
291 _result = _reply.readString();
292 }
293 finally {
294 _reply.recycle();
295 _data.recycle();
296 }
297 return _result;
298 }
299 /* Test long comment */
300 @Override public android.foo.ExampleParcelable[] getParcelables() throws android.os.RemoteException
301 {
302 android.os.Parcel _data = android.os.Parcel.obtain();
303 android.os.Parcel _reply = android.os.Parcel.obtain();
304 android.foo.ExampleParcelable[] _result;
305 try {
306 _data.writeInterfaceToken(DESCRIPTOR);
307 mRemote.transact(Stub.TRANSACTION_getParcelables, _data, _reply, 0);
308 _reply.readException();
309 _result = _reply.createTypedArray(android.foo.ExampleParcelable.CREATOR);
310 }
311 finally {
312 _reply.recycle();
313 _data.recycle();
314 }
315 return _result;
316 }
317 // Test short comment
318 
319 @Override public boolean setScanMode(int mode, int duration) throws android.os.RemoteException
320 {
321 android.os.Parcel _data = android.os.Parcel.obtain();
322 android.os.Parcel _reply = android.os.Parcel.obtain();
323 boolean _result;
324 try {
325 _data.writeInterfaceToken(DESCRIPTOR);
326 _data.writeInt(mode);
327 _data.writeInt(duration);
328 mRemote.transact(Stub.TRANSACTION_setScanMode, _data, _reply, 0);
329 _reply.readException();
330 _result = (0!=_reply.readInt());
331 }
332 finally {
333 _reply.recycle();
334 _data.recycle();
335 }
336 return _result;
337 }
338 /* Test long comment */// And short comment
339 
340 @Override public void registerBinder(android.bar.IAuxInterface foo) throws android.os.RemoteException
341 {
342 android.os.Parcel _data = android.os.Parcel.obtain();
343 android.os.Parcel _reply = android.os.Parcel.obtain();
344 try {
345 _data.writeInterfaceToken(DESCRIPTOR);
346 _data.writeStrongBinder((((foo!=null))?(foo.asBinder()):(null)));
347 mRemote.transact(Stub.TRANSACTION_registerBinder, _data, _reply, 0);
348 _reply.readException();
349 }
350 finally {
351 _reply.recycle();
352 _data.recycle();
353 }
354 }
355 @Override public android.test.IExampleInterface getRecursiveBinder() throws android.os.RemoteException
356 {
357 android.os.Parcel _data = android.os.Parcel.obtain();
358 android.os.Parcel _reply = android.os.Parcel.obtain();
359 android.test.IExampleInterface _result;
360 try {
361 _data.writeInterfaceToken(DESCRIPTOR);
362 mRemote.transact(Stub.TRANSACTION_getRecursiveBinder, _data, _reply, 0);
363 _reply.readException();
364 _result = android.test.IExampleInterface.Stub.asInterface(_reply.readStrongBinder());
365 }
366 finally {
367 _reply.recycle();
368 _data.recycle();
369 }
370 return _result;
371 }
372 @Override public int takesAnInterface(android.test.IAuxInterface2 arg) throws android.os.RemoteException
373 {
374 android.os.Parcel _data = android.os.Parcel.obtain();
375 android.os.Parcel _reply = android.os.Parcel.obtain();
376 int _result;
377 try {
378 _data.writeInterfaceToken(DESCRIPTOR);
379 _data.writeStrongBinder((((arg!=null))?(arg.asBinder()):(null)));
380 mRemote.transact(Stub.TRANSACTION_takesAnInterface, _data, _reply, 0);
381 _reply.readException();
382 _result = _reply.readInt();
383 }
384 finally {
385 _reply.recycle();
386 _data.recycle();
387 }
388 return _result;
389 }
390 @Override public int takesAParcelable(android.test.CompoundParcelable.Subclass1 arg, android.test.CompoundParcelable.Subclass2 arg2) throws android.os.RemoteException
391 {
392 android.os.Parcel _data = android.os.Parcel.obtain();
393 android.os.Parcel _reply = android.os.Parcel.obtain();
394 int _result;
395 try {
396 _data.writeInterfaceToken(DESCRIPTOR);
397 if ((arg!=null)) {
398 _data.writeInt(1);
399 arg.writeToParcel(_data, 0);
400 }
401 else {
402 _data.writeInt(0);
403 }
404 if ((arg2!=null)) {
405 _data.writeInt(1);
406 arg2.writeToParcel(_data, 0);
407 }
408 else {
409 _data.writeInt(0);
410 }
411 mRemote.transact(Stub.TRANSACTION_takesAParcelable, _data, _reply, 0);
412 _reply.readException();
413 _result = _reply.readInt();
414 if ((0!=_reply.readInt())) {
415 arg2.readFromParcel(_reply);
416 }
417 }
418 finally {
419 _reply.recycle();
420 _data.recycle();
421 }
422 return _result;
423 }
424 }
425 static final int TRANSACTION_isEnabled = (android.os.IBinder.FIRST_CALL_TRANSACTION + 0);
426 static final int TRANSACTION_getState = (android.os.IBinder.FIRST_CALL_TRANSACTION + 1);
427 static final int TRANSACTION_getAddress = (android.os.IBinder.FIRST_CALL_TRANSACTION + 2);
428 static final int TRANSACTION_getParcelables = (android.os.IBinder.FIRST_CALL_TRANSACTION + 3);
429 static final int TRANSACTION_setScanMode = (android.os.IBinder.FIRST_CALL_TRANSACTION + 4);
430 static final int TRANSACTION_registerBinder = (android.os.IBinder.FIRST_CALL_TRANSACTION + 5);
431 static final int TRANSACTION_getRecursiveBinder = (android.os.IBinder.FIRST_CALL_TRANSACTION + 6);
432 static final int TRANSACTION_takesAnInterface = (android.os.IBinder.FIRST_CALL_TRANSACTION + 7);
433 static final int TRANSACTION_takesAParcelable = (android.os.IBinder.FIRST_CALL_TRANSACTION + 8);
434 }
435 public static final int EXAMPLE_CONSTANT = 3;
436 public boolean isEnabled() throws android.os.RemoteException;
437 public int getState() throws android.os.RemoteException;
438 public java.lang.String getAddress() throws android.os.RemoteException;
439 /* Test long comment */
440 public android.foo.ExampleParcelable[] getParcelables() throws android.os.RemoteException;
441 // Test short comment
442 
443 public boolean setScanMode(int mode, int duration) throws android.os.RemoteException;
444 /* Test long comment */// And short comment
445 
446 public void registerBinder(android.bar.IAuxInterface foo) throws android.os.RemoteException;
447 public android.test.IExampleInterface getRecursiveBinder() throws android.os.RemoteException;
448 public int takesAnInterface(android.test.IAuxInterface2 arg) throws android.os.RemoteException;
449 public int takesAParcelable(android.test.CompoundParcelable.Subclass1 arg, android.test.CompoundParcelable.Subclass2 arg2) throws android.os.RemoteException;
450 }
451 )";
452 
453 }  // namespace example_interface
454 }  // namespace test_data
455 }  // namespace aidl
456 }  // namespace android
457