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 package android.aidl.tests;
18 
19 import android.aidl.tests.ByteEnum;
20 import android.aidl.tests.INamedCallback;
21 import android.aidl.tests.IntEnum;
22 import android.aidl.tests.LongEnum;
23 import android.aidl.tests.SimpleParcelable;
24 import android.aidl.tests.StructuredParcelable;
25 import android.os.PersistableBundle;
26 
27 interface ITestService {
28   // Test that constants are accessible
29   const int TEST_CONSTANT = 42;
30   const int TEST_CONSTANT2 = -42;
31   const int TEST_CONSTANT3 = +42;
32   const int TEST_CONSTANT4 = +4;
33   const int TEST_CONSTANT5 = -4;
34   const int TEST_CONSTANT6 = -0;
35   const int TEST_CONSTANT7 = +0;
36   const int TEST_CONSTANT8 = 0;
37   const int TEST_CONSTANT9 = 0x56;
38   const int TEST_CONSTANT10 = 0xa5;
39   const int TEST_CONSTANT11 = 0xFA;
40   const int TEST_CONSTANT12 = 0xffffffff;
41 
42   const String STRING_TEST_CONSTANT = "foo";
43   const String STRING_TEST_CONSTANT2 = "bar";
44 
45   const @utf8InCpp String STRING_TEST_CONSTANT_UTF8 = "baz";
46 
47   // Test that primitives work as parameters and return types.
RepeatBoolean(boolean token)48   boolean RepeatBoolean(boolean token);
RepeatByte(byte token)49   byte RepeatByte(byte token);
RepeatChar(char token)50   char RepeatChar(char token);
RepeatInt(int token)51   int RepeatInt(int token);
RepeatLong(long token)52   long RepeatLong(long token);
RepeatFloat(float token)53   float RepeatFloat(float token);
RepeatDouble(double token)54   double RepeatDouble(double token);
RepeatString(String token)55   String RepeatString(String token);
RepeatByteEnum(ByteEnum token)56   ByteEnum RepeatByteEnum(ByteEnum token);
RepeatIntEnum(IntEnum token)57   IntEnum RepeatIntEnum(IntEnum token);
RepeatLongEnum(LongEnum token)58   LongEnum RepeatLongEnum(LongEnum token);
59 
RepeatSimpleParcelable(in SimpleParcelable input, out SimpleParcelable repeat)60   SimpleParcelable RepeatSimpleParcelable(in SimpleParcelable input,
61                                           out SimpleParcelable repeat);
RepeatPersistableBundle(in PersistableBundle input)62   PersistableBundle RepeatPersistableBundle(in PersistableBundle input);
63 
64   // Test that arrays work as parameters and return types.
ReverseBoolean(in boolean[] input, out boolean[] repeated)65   boolean[]   ReverseBoolean  (in boolean[]   input, out boolean[]   repeated);
ReverseByte(in byte[] input, out byte[] repeated)66   byte[]      ReverseByte     (in byte[]      input, out byte[]      repeated);
ReverseChar(in char[] input, out char[] repeated)67   char[]      ReverseChar     (in char[]      input, out char[]      repeated);
ReverseInt(in int[] input, out int[] repeated)68   int[]       ReverseInt      (in int[]       input, out int[]       repeated);
ReverseLong(in long[] input, out long[] repeated)69   long[]      ReverseLong     (in long[]      input, out long[]      repeated);
ReverseFloat(in float[] input, out float[] repeated)70   float[]     ReverseFloat    (in float[]     input, out float[]     repeated);
ReverseDouble(in double[] input, out double[] repeated)71   double[]    ReverseDouble   (in double[]    input, out double[]    repeated);
ReverseString(in String[] input, out String[] repeated)72   String[]    ReverseString   (in String[]    input, out String[]    repeated);
ReverseByteEnum(in ByteEnum[] input, out ByteEnum[] repeated)73   ByteEnum[]  ReverseByteEnum (in ByteEnum[]  input, out ByteEnum[]  repeated);
ReverseIntEnum(in IntEnum[] input, out IntEnum[] repeated)74   IntEnum[]   ReverseIntEnum  (in IntEnum[]   input, out IntEnum[]   repeated);
ReverseLongEnum(in LongEnum[] input, out LongEnum[] repeated)75   LongEnum[]  ReverseLongEnum (in LongEnum[]  input, out LongEnum[]  repeated);
76 
ReverseSimpleParcelables(in SimpleParcelable[] input, out SimpleParcelable[] repeated)77   SimpleParcelable[]  ReverseSimpleParcelables(in SimpleParcelable[] input,
78                                                out SimpleParcelable[] repeated);
ReversePersistableBundles( in PersistableBundle[] input, out PersistableBundle[] repeated)79   PersistableBundle[] ReversePersistableBundles(
80       in PersistableBundle[] input, out PersistableBundle[] repeated);
81 
82   // Test that clients can send and receive Binders.
GetOtherTestService(String name)83   INamedCallback GetOtherTestService(String name);
VerifyName(INamedCallback service, String name)84   boolean VerifyName(INamedCallback service, String name);
85 
86   // Test that List<T> types work correctly.
ReverseStringList(in List<String> input, out List<String> repeated)87   List<String> ReverseStringList(in List<String> input,
88                                  out List<String> repeated);
ReverseNamedCallbackList(in List<IBinder> input, out List<IBinder> repeated)89   List<IBinder> ReverseNamedCallbackList(in List<IBinder> input,
90                                          out List<IBinder> repeated);
91 
RepeatFileDescriptor(in FileDescriptor read)92   FileDescriptor RepeatFileDescriptor(in FileDescriptor read);
ReverseFileDescriptorArray(in FileDescriptor[] input, out FileDescriptor[] repeated)93   FileDescriptor[] ReverseFileDescriptorArray(in FileDescriptor[] input,
94                                               out FileDescriptor[] repeated);
95 
RepeatParcelFileDescriptor(in ParcelFileDescriptor read)96   ParcelFileDescriptor RepeatParcelFileDescriptor(in ParcelFileDescriptor read);
ReverseParcelFileDescriptorArray(in ParcelFileDescriptor[] input, out ParcelFileDescriptor[] repeated)97   ParcelFileDescriptor[] ReverseParcelFileDescriptorArray(in ParcelFileDescriptor[] input,
98                                               out ParcelFileDescriptor[] repeated);
99 
100   // Test that service specific exceptions work correctly.
ThrowServiceException(int code)101   void ThrowServiceException(int code);
102 
103   // Test nullability
RepeatNullableIntArray(in @ullable int[] input)104   @nullable int[] RepeatNullableIntArray(in @nullable int[] input);
RepeatNullableByteEnumArray(in @ullable ByteEnum[] input)105   @nullable ByteEnum[] RepeatNullableByteEnumArray(in @nullable ByteEnum[] input);
RepeatNullableIntEnumArray(in @ullable IntEnum[] input)106   @nullable IntEnum[] RepeatNullableIntEnumArray(in @nullable IntEnum[] input);
RepeatNullableLongEnumArray(in @ullable LongEnum[] input)107   @nullable LongEnum[] RepeatNullableLongEnumArray(in @nullable LongEnum[] input);
RepeatNullableString(in @ullable String input)108   @nullable String RepeatNullableString(in @nullable String input);
RepeatNullableStringList(in @ullable List<String> input)109   @nullable List<String> RepeatNullableStringList(in @nullable List<String> input);
RepeatNullableParcelable(in @ullable SimpleParcelable input)110   @nullable SimpleParcelable RepeatNullableParcelable(in @nullable SimpleParcelable input);
111 
TakesAnIBinder(in IBinder input)112   void TakesAnIBinder(in IBinder input);
TakesAnIBinderList(in List<IBinder> input)113   void TakesAnIBinderList(in List<IBinder> input);
TakesANullableIBinder(in @ullable IBinder input)114   void TakesANullableIBinder(in @nullable IBinder input);
TakesANullableIBinderList(in @ullable List<IBinder> input)115   void TakesANullableIBinderList(in @nullable List<IBinder> input);
116 
117   // Test utf8 decoding from utf16 wire format
RepeatUtf8CppString(@tf8InCpp String token)118   @utf8InCpp String RepeatUtf8CppString(@utf8InCpp String token);
RepeatNullableUtf8CppString( @ullable @tf8InCpp String token)119   @nullable @utf8InCpp String RepeatNullableUtf8CppString(
120       @nullable @utf8InCpp String token);
121 
ReverseUtf8CppString(in @tf8InCpp String[] input, out @utf8InCpp String[] repeated)122   @utf8InCpp String[]  ReverseUtf8CppString (in @utf8InCpp String[] input,
123                                              out @utf8InCpp String[] repeated);
124 
ReverseNullableUtf8CppString( in @ullable @tf8InCpp String[] input, out @nullable @utf8InCpp String[] repeated)125   @nullable @utf8InCpp String[]  ReverseNullableUtf8CppString (
126       in @nullable @utf8InCpp String[] input,
127       out @nullable @utf8InCpp String[] repeated);
128 
ReverseUtf8CppStringList( in @ullable @tf8InCpp List<String> input, out @nullable @utf8InCpp List<String> repeated)129   @nullable @utf8InCpp List<String> ReverseUtf8CppStringList(
130       in @nullable @utf8InCpp List<String> input,
131       out @nullable @utf8InCpp List<String> repeated);
132 
GetCallback(boolean return_null)133   @nullable INamedCallback GetCallback(boolean return_null);
134 
135   // Since this paracelable has clearly defined default values, it would be
136   // inefficient to use an IPC to fill it out in practice.
FillOutStructuredParcelable(inout StructuredParcelable parcel)137   void FillOutStructuredParcelable(inout StructuredParcelable parcel);
138 
139   // This is to emulate a method that is added after the service is implemented.
140   // So the client cannot assume that call to this method will be successful
141   // or not. However, inside the test environment, we can't build client and
142   // the server with different version of this AIDL file. So, we let the server
143   // to actually implement this, but intercept the dispatch to the method
144   // inside onTransact().
UnimplementedMethod(int arg)145   int UnimplementedMethod(int arg);
146 
147   // All these constant expressions should be equal to 1
148   const int A1 = (~(-1)) == 0;
149   const int A2 = ~~(1 << 31) == (1 << 31);
150   const int A3 = -0x7fffffff < 0;
151   const int A4 = 0x80000000 < 0;
152   const int A5 = 0x7fffffff == 2147483647;
153   const int A6 = (1 << 31) == 0x80000000;
154   const int A7 = (1 + 2) == 3;
155   const int A8 = (8 - 9) == -1;
156   const int A9 = (9 * 9) == 81;
157   const int A10 = (29 / 3) == 9;
158   const int A11 = (29 % 3) == 2;
159   const int A12 = (0xC0010000 | 0xF00D) == (0xC001F00D);
160   const int A13 = (10 | 6) == 14;
161   const int A14 = (10 & 6) == 2;
162   const int A15 = (10 ^ 6) == 12;
163   const int A16 = 6 < 10;
164   const int A17 = (10 < 10) == 0;
165   const int A18 = (6 > 10) == 0;
166   const int A19 = (10 > 10) == 0;
167   const int A20 = 19 >= 10;
168   const int A21 = 10 >= 10;
169   const int A22 = 5 <= 10;
170   const int A23 = (19 <= 10) == 0;
171   const int A24 = 19 != 10;
172   const int A25 = (10 != 10) == 0;
173   const int A26 = (22 << 1) == 44;
174   const int A27 = (11 >> 1) == 5;
175   const int A28 = (1 || 0) == 1;
176   const int A29 = (1 || 1) == 1;
177   const int A30 = (0 || 0) == 0;
178   const int A31 = (0 || 1) == 1;
179   const int A32 = (1 && 0) == 0;
180   const int A33 = (1 && 1) == 1;
181   const int A34 = (0 && 0) == 0;
182   const int A35 = (0 && 1) == 0;
183   const int A36 = 4 == 4;
184   const int A37 = -4 < 0;
185   const int A38 = 0xffffffff == -1;
186   const int A39 = 4 + 1 == 5;
187   const int A40 = 2 + 3 - 4;
188   const int A41 = 2 - 3 + 4 == 3;
189   const int A42 = 1 == 4 == 0;
190   const int A43 = 1 && 1;
191   const int A44 = 1 || 1 && 0;  // && higher than ||
192   const int A45 = 1 < 2;
193   const int A46 = !!((3 != 4 || (2 < 3 <= 3 > 4)) >= 0);
194   const int A47 = !(1 == 7) && ((3 != 4 || (2 < 3 <= 3 > 4)) >= 0);
195   const int A48 = (1 << 2) >= 0;
196   const int A49 = (4 >> 1) == 2;
197   const int A50 = (8 << -1) == 4;
198   const int A51 = (1 << 31 >> 31) == -1;
199   const int A52 = (1 | 16 >> 2) == 5;
200   const int A53 = (0x0f ^ 0x33 & 0x99) == 0x1e; // & higher than ^
201   const int A54 = (~42 & (1 << 3 | 16 >> 2) ^ 7) == 3;
202   const int A55 = (2 + 3 - 4 * -7 / (10 % 3)) - 33 == 0;
203   const int A56 = (2 + (-3&4 / 7)) == 2;
204   const int A57 = (((((1 + 0)))));
205 }
206