• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 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.binder.cts;
18 
19 import android.os.Binder;
20 import android.os.IBinder;
21 import android.os.ParcelFileDescriptor;
22 import android.os.RemoteException;
23 
24 import test_package.IEmpty;
25 import test_package.ITest;
26 import test_package.RegularPolygon;
27 import test_package.Foo;
28 import test_package.Bar;
29 
30 import java.util.concurrent.CountDownLatch;
31 import java.io.FileDescriptor;
32 import java.io.PrintWriter;
33 
34 public class TestImpl extends ITest.Stub {
35   @Override
getInterfaceVersion()36   public int getInterfaceVersion() { return TestImpl.VERSION; }
37 
38   @Override
dump(FileDescriptor fd, PrintWriter pw, String[] args)39   protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
40     for (String arg : args) {
41       pw.print(arg);
42     }
43   }
44 
45   @Override
GetName()46   public String GetName() {
47     return "JAVA";
48   }
49 
50   @Override
TestVoidReturn()51   public void TestVoidReturn() {}
52 
53   @Override
TestOneway()54   public void TestOneway() {}
55 
56   @Override
GiveMeMyCallingPid()57   public int GiveMeMyCallingPid() {
58     return Binder.getCallingPid();
59   }
60 
61   @Override
GiveMeMyCallingUid()62   public int GiveMeMyCallingUid() {
63     return Binder.getCallingUid();
64   }
65 
66   private CountDownLatch mCachedLatch = new CountDownLatch(1);
67   private int mCachedPid = -1;
68   private int mCachedUid = -1;
69 
waitForCachedOnewayInfo()70   private void waitForCachedOnewayInfo() {
71     try {
72       mCachedLatch.await();
73     } catch (InterruptedException e) {
74       // This thread is never expected to be interrupted during this test. This will be
75       // converted to a RemoteException on the other side and cause the test to fail.
76 
77       throw new RuntimeException(e.toString());
78     }
79   }
80 
81   @Override
CacheCallingInfoFromOneway()82   public void CacheCallingInfoFromOneway() {
83     mCachedLatch.countDown();
84     mCachedPid = Binder.getCallingPid();
85     mCachedUid = Binder.getCallingUid();
86   }
87 
88   @Override
GiveMeMyCallingPidFromOneway()89   public int GiveMeMyCallingPidFromOneway() {
90     waitForCachedOnewayInfo();
91     return mCachedPid;
92   }
93 
94   @Override
GiveMeMyCallingUidFromOneway()95   public int GiveMeMyCallingUidFromOneway() {
96     waitForCachedOnewayInfo();
97     return mCachedUid;
98   }
99 
100   @Override
RepeatInt(int in_value)101   public int RepeatInt(int in_value) {
102     return in_value;
103   }
104 
105   @Override
RepeatLong(long in_value)106   public long RepeatLong(long in_value) {
107     return in_value;
108   }
109 
110   @Override
RepeatFloat(float in_value)111   public float RepeatFloat(float in_value) {
112     return in_value;
113   }
114 
115   @Override
RepeatDouble(double in_value)116   public double RepeatDouble(double in_value) {
117     return in_value;
118   }
119 
120   @Override
RepeatBoolean(boolean in_value)121   public boolean RepeatBoolean(boolean in_value) {
122     return in_value;
123   }
124 
125   @Override
RepeatChar(char in_value)126   public char RepeatChar(char in_value) {
127     return in_value;
128   }
129 
130   @Override
RepeatByte(byte in_value)131   public byte RepeatByte(byte in_value) {
132     return in_value;
133   }
134 
135   @Override
RepeatBinder(IBinder in_value)136   public IBinder RepeatBinder(IBinder in_value) {
137     return in_value;
138   }
139 
140   @Override
RepeatNullableBinder(IBinder in_value)141   public IBinder RepeatNullableBinder(IBinder in_value) {
142     return in_value;
143   }
144 
145   @Override
RepeatInterface(IEmpty in_value)146   public IEmpty RepeatInterface(IEmpty in_value) {
147     return in_value;
148   }
149 
150   @Override
RepeatNullableInterface(IEmpty in_value)151   public IEmpty RepeatNullableInterface(IEmpty in_value) {
152     return in_value;
153   }
154 
155   @Override
RepeatFd(ParcelFileDescriptor in_value)156   public ParcelFileDescriptor RepeatFd(ParcelFileDescriptor in_value) {
157     return in_value;
158   }
159 
160   @Override
RepeatNullableFd(ParcelFileDescriptor in_value)161   public ParcelFileDescriptor RepeatNullableFd(ParcelFileDescriptor in_value) {
162     return in_value;
163   }
164 
165   @Override
RepeatString(String in_value)166   public String RepeatString(String in_value) {
167     return in_value;
168   }
169 
170   @Override
RepeatNullableString(String in_value)171   public String RepeatNullableString(String in_value) {
172     return in_value;
173   }
174 
175   @Override
RepeatPolygon(RegularPolygon in_value)176   public RegularPolygon RepeatPolygon(RegularPolygon in_value) {
177     return in_value;
178   }
179 
180   @Override
RenamePolygon(RegularPolygon value, String name)181   public void RenamePolygon(RegularPolygon value, String name) {
182     value.name = name;
183   }
184 
185   @Override
RepeatBooleanArray(boolean[] in_value, boolean[] repeated)186   public boolean[] RepeatBooleanArray(boolean[] in_value, boolean[] repeated) {
187     System.arraycopy(in_value, 0, repeated, 0, in_value.length);
188     return in_value;
189   }
190 
191   @Override
RepeatByteArray(byte[] in_value, byte[] repeated)192   public byte[] RepeatByteArray(byte[] in_value, byte[] repeated) {
193     System.arraycopy(in_value, 0, repeated, 0, in_value.length);
194     return in_value;
195   }
196 
197   @Override
RepeatCharArray(char[] in_value, char[] repeated)198   public char[] RepeatCharArray(char[] in_value, char[] repeated) {
199     System.arraycopy(in_value, 0, repeated, 0, in_value.length);
200     return in_value;
201   }
202 
203   @Override
RepeatIntArray(int[] in_value, int[] repeated)204   public int[] RepeatIntArray(int[] in_value, int[] repeated) {
205     System.arraycopy(in_value, 0, repeated, 0, in_value.length);
206     return in_value;
207   }
208 
209   @Override
RepeatLongArray(long[] in_value, long[] repeated)210   public long[] RepeatLongArray(long[] in_value, long[] repeated) {
211     System.arraycopy(in_value, 0, repeated, 0, in_value.length);
212     return in_value;
213   }
214 
215   @Override
RepeatFloatArray(float[] in_value, float[] repeated)216   public float[] RepeatFloatArray(float[] in_value, float[] repeated) {
217     System.arraycopy(in_value, 0, repeated, 0, in_value.length);
218     return in_value;
219   }
220 
221   @Override
RepeatDoubleArray(double[] in_value, double[] repeated)222   public double[] RepeatDoubleArray(double[] in_value, double[] repeated) {
223     System.arraycopy(in_value, 0, repeated, 0, in_value.length);
224     return in_value;
225   }
226 
227   @Override
RepeatStringArray(String[] in_value, String[] repeated)228   public String[] RepeatStringArray(String[] in_value, String[] repeated) {
229     System.arraycopy(in_value, 0, repeated, 0, in_value.length);
230     return in_value;
231   }
232 
233   @Override
RepeatRegularPolygonArray(RegularPolygon[] in_value, RegularPolygon[] repeated)234   public RegularPolygon[] RepeatRegularPolygonArray(RegularPolygon[] in_value, RegularPolygon[] repeated) {
235     System.arraycopy(in_value, 0, repeated, 0, in_value.length);
236     return in_value;
237   }
238 
239   @Override
RepeatNullableBooleanArray(boolean[] in_value)240   public boolean[] RepeatNullableBooleanArray(boolean[] in_value) {
241     return in_value;
242   }
243 
244   @Override
RepeatNullableByteArray(byte[] in_value)245   public byte[] RepeatNullableByteArray(byte[] in_value) {
246     return in_value;
247   }
248 
249   @Override
RepeatNullableCharArray(char[] in_value)250   public char[] RepeatNullableCharArray(char[] in_value) {
251     return in_value;
252   }
253 
254   @Override
RepeatNullableIntArray(int[] in_value)255   public int[] RepeatNullableIntArray(int[] in_value) {
256     return in_value;
257   }
258 
259   @Override
RepeatNullableLongArray(long[] in_value)260   public long[] RepeatNullableLongArray(long[] in_value) {
261     return in_value;
262   }
263 
264   @Override
RepeatNullableFloatArray(float[] in_value)265   public float[] RepeatNullableFloatArray(float[] in_value) {
266     return in_value;
267   }
268 
269   @Override
RepeatNullableDoubleArray(double[] in_value)270   public double[] RepeatNullableDoubleArray(double[] in_value) {
271     return in_value;
272   }
273 
274   @Override
RepeatNullableStringArray(String[] in_value)275   public String[] RepeatNullableStringArray(String[] in_value) {
276     return in_value;
277   }
278 
279   @Override
DoubleRepeatNullableStringArray(String[] in_value, String[] repeated)280   public String[] DoubleRepeatNullableStringArray(String[] in_value, String[] repeated) {
281     if (in_value == null) {
282       return null; // can't do anything to repeated
283     }
284 
285     System.arraycopy(in_value, 0, repeated, 0, in_value.length);
286     return in_value;
287   }
288 
289   @Override
NewMethodThatReturns10()290   public int NewMethodThatReturns10() {
291     return 10;
292   }
293 
294   @Override
repeatFoo(Foo inFoo)295   public Foo repeatFoo(Foo inFoo) {
296     return inFoo;
297   }
298 
299   @Override
renameFoo(Foo foo, String name)300   public void renameFoo(Foo foo, String name) {
301     foo.a = name;
302   }
303 
304   @Override
renameBar(Foo foo, String name)305   public void renameBar(Foo foo, String name) {
306     if (foo.d == null) {
307       foo.d = new Bar();
308     }
309     foo.d.a = name;
310   }
311 
312   @Override
getF(Foo foo)313   public int getF(Foo foo) {
314     return foo.f;
315   }
316 
317 }
318