aboutsummaryrefslogtreecommitdiff
path: root/tests/java/src/android/aidl/service/TestServiceServer.java
blob: 7843d9ce509b6a752ecc2b488dadfec614341f78 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
/*
 * Copyright (C) 2021, The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.aidl.service;

import android.aidl.fixedsizearray.FixedSizeArrayExample.IRepeatFixedSizeArray;
import android.aidl.fixedsizearray.FixedSizeArrayExample.IntParcelable;
import android.aidl.tests.BackendType;
import android.aidl.tests.BadParcelable;
import android.aidl.tests.ByteEnum;
import android.aidl.tests.CircularParcelable;
import android.aidl.tests.ConstantExpressionEnum;
import android.aidl.tests.GenericStructuredParcelable;
import android.aidl.tests.ICircular;
import android.aidl.tests.ICppJavaTests;
import android.aidl.tests.INamedCallback;
import android.aidl.tests.INewName;
import android.aidl.tests.IOldName;
import android.aidl.tests.ITestService;
import android.aidl.tests.IntEnum;
import android.aidl.tests.LongEnum;
import android.aidl.tests.RecursiveList;
import android.aidl.tests.SimpleParcelable;
import android.aidl.tests.StructuredParcelable;
import android.aidl.tests.Union;
import android.aidl.tests.extension.ExtendableParcelable;
import android.aidl.tests.extension.MyExt;
import android.aidl.tests.nested.INestedService;
import android.aidl.tests.nested.ParcelableWithNested;
import android.aidl.versioned.tests.BazUnion;
import android.aidl.versioned.tests.Foo;
import android.aidl.versioned.tests.IFooInterface;
import android.os.Binder;
import android.os.IBinder;
import android.os.Parcel;
import android.os.ParcelFileDescriptor;
import android.os.PersistableBundle;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.ServiceSpecificException;
import android.util.Log;
import java.io.FileDescriptor;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;

public class TestServiceServer extends ITestService.Stub {
  public static void main(String[] args) {
    // b/235006086: test with debug stack trace parceling feature
    // which has been broken in the past. This does mean that we
    // lose Java coverage for when this is false, but we do have
    // other tests which cover this including CtsNdkBinderTestCases
    // and other language-specific exception/Status unit tests.
    Parcel.setStackTraceParceling(true);

    TestServiceServer myServer = new TestServiceServer();
    ServiceManager.addService(ITestService.class.getName(), myServer);

    FooInterface foo = new FooInterface();
    ServiceManager.addService(IFooInterface.class.getName(), foo);

    NestedService nested = new NestedService();
    ServiceManager.addService(INestedService.class.getName(), nested);

    FixedSizeArrayService fixedSize = new FixedSizeArrayService();
    ServiceManager.addService(IRepeatFixedSizeArray.DESCRIPTOR, fixedSize);

    Binder.joinThreadPool();
  }

  private static class FooInterface extends IFooInterface.Stub {
    @Override
    public void originalApi() {}
    @Override
    public String acceptUnionAndReturnString(BazUnion b) {
      if (b.getTag() == BazUnion.intNum) {
        return "" + b.getIntNum();
      }
      throw new IllegalArgumentException();
    }
    @Override
    public int returnsLengthOfFooArray(Foo[] foos) {
      return foos.length;
    }
    @Override
    public int ignoreParcelablesAndRepeatInt(Foo inFoo, Foo inoutFoo, Foo outFoo, int value) {
      return value;
    }
    @Override
    public final int getInterfaceVersion() {
      return super.VERSION;
    }
    @Override
    public final String getInterfaceHash() {
      return super.HASH;
    }
  }

  private static class NestedService extends INestedService.Stub {
    @Override
    public final Result flipStatus(ParcelableWithNested p) {
      Result result = new Result();
      if (p.status == ParcelableWithNested.Status.OK) {
        result.status = ParcelableWithNested.Status.NOT_OK;
      } else {
        result.status = ParcelableWithNested.Status.OK;
      }
      return result;
    }
    @Override
    public final void flipStatusWithCallback(byte st, ICallback cb) throws RemoteException {
      if (st == ParcelableWithNested.Status.OK) {
        cb.done(ParcelableWithNested.Status.NOT_OK);
      } else {
        cb.done(ParcelableWithNested.Status.OK);
      }
    }
  }

  @Override
  public boolean onTransact(int code, Parcel data, Parcel reply, int flags) throws RemoteException {
    // UnimplementedMethod
    if (code == 1)
      return false;
    return super.onTransact(code, data, reply, flags);
  }

  @Override
  public int UnimplementedMethod(int arg) throws RemoteException {
    throw new UnsupportedOperationException();
  }
  @Override
  public void TestOneway() throws RemoteException {
    throw new RemoteException();
  }
  @Override
  public void Deprecated() throws RemoteException {}
  @Override
  public boolean RepeatBoolean(boolean token) throws RemoteException {
    return token;
  }
  @Override
  public byte RepeatByte(byte token) throws RemoteException {
    return token;
  }
  @Override
  public char RepeatChar(char token) throws RemoteException {
    return token;
  }
  @Override
  public int RepeatInt(int token) throws RemoteException {
    return token;
  }
  @Override
  public long RepeatLong(long token) throws RemoteException {
    return token;
  }
  @Override
  public float RepeatFloat(float token) throws RemoteException {
    return token;
  }
  @Override
  public double RepeatDouble(double token) throws RemoteException {
    return token;
  }
  @Override
  public String RepeatString(String token) throws RemoteException {
    return token;
  }
  @Override
  public byte RepeatByteEnum(byte token) throws RemoteException {
    return token;
  }
  @Override
  public int RepeatIntEnum(int token) throws RemoteException {
    return token;
  }
  @Override
  public long RepeatLongEnum(long token) throws RemoteException {
    return token;
  }
  @Override
  public boolean[] ReverseBoolean(boolean[] input, boolean[] repeated) throws RemoteException {
    boolean[] reversed = new boolean[input.length];
    for (int i = 0; i < input.length; i++) {
      repeated[i] = input[i];
      reversed[i] = input[input.length - i - 1];
    }
    return reversed;
  }
  @Override
  public byte[] ReverseByte(byte[] input, byte[] repeated) throws RemoteException {
    byte[] reversed = new byte[input.length];
    for (int i = 0; i < input.length; i++) {
      repeated[i] = input[i];
      reversed[i] = input[input.length - i - 1];
    }
    return reversed;
  }
  @Override
  public char[] ReverseChar(char[] input, char[] repeated) throws RemoteException {
    char[] reversed = new char[input.length];
    for (int i = 0; i < input.length; i++) {
      repeated[i] = input[i];
      reversed[i] = input[input.length - i - 1];
    }
    return reversed;
  }
  @Override
  public int[] ReverseInt(int[] input, int[] repeated) throws RemoteException {
    int[] reversed = new int[input.length];
    for (int i = 0; i < input.length; i++) {
      repeated[i] = input[i];
      reversed[i] = input[input.length - i - 1];
    }
    return reversed;
  }
  @Override
  public long[] ReverseLong(long[] input, long[] repeated) throws RemoteException {
    long[] reversed = new long[input.length];
    for (int i = 0; i < input.length; i++) {
      repeated[i] = input[i];
      reversed[i] = input[input.length - i - 1];
    }
    return reversed;
  }
  @Override
  public float[] ReverseFloat(float[] input, float[] repeated) throws RemoteException {
    float[] reversed = new float[input.length];
    for (int i = 0; i < input.length; i++) {
      repeated[i] = input[i];
      reversed[i] = input[input.length - i - 1];
    }
    return reversed;
  }
  @Override
  public double[] ReverseDouble(double[] input, double[] repeated) throws RemoteException {
    double[] reversed = new double[input.length];
    for (int i = 0; i < input.length; i++) {
      repeated[i] = input[i];
      reversed[i] = input[input.length - i - 1];
    }
    return reversed;
  }
  @Override
  public String[] ReverseString(String[] input, String[] repeated) throws RemoteException {
    String[] reversed = new String[input.length];
    for (int i = 0; i < input.length; i++) {
      repeated[i] = input[i];
      reversed[i] = input[input.length - i - 1];
    }
    return reversed;
  }
  @Override
  public byte[] ReverseByteEnum(byte[] input, byte[] repeated) throws RemoteException {
    byte[] reversed = new byte[input.length];
    for (int i = 0; i < input.length; i++) {
      repeated[i] = input[i];
      reversed[i] = input[input.length - i - 1];
    }
    return reversed;
  }
  @Override
  public int[] ReverseIntEnum(int[] input, int[] repeated) throws RemoteException {
    int[] reversed = new int[input.length];
    for (int i = 0; i < input.length; i++) {
      repeated[i] = input[i];
      reversed[i] = input[input.length - i - 1];
    }
    return reversed;
  }
  @Override
  public long[] ReverseLongEnum(long[] input, long[] repeated) throws RemoteException {
    long[] reversed = new long[input.length];
    for (int i = 0; i < input.length; i++) {
      repeated[i] = input[i];
      reversed[i] = input[input.length - i - 1];
    }
    return reversed;
  }

  private static class MyNamedCallback extends INamedCallback.Stub {
    public MyNamedCallback(String name) { mName = name; }
    @Override
    public String GetName() {
      return mName;
    }
    private String mName;
  }

  private HashMap<String, MyNamedCallback> mNamedCallbacks = new HashMap<>();

  @Override
  public INamedCallback GetOtherTestService(String name) throws RemoteException {
    synchronized (mNamedCallbacks) {
      if (!mNamedCallbacks.containsKey(name)) {
        mNamedCallbacks.put(name, new MyNamedCallback(name));
      }
      return mNamedCallbacks.get(name);
    }
  }
  @Override
  public boolean SetOtherTestService(String name, INamedCallback service) throws RemoteException {
    synchronized (mNamedCallbacks) {
      if (mNamedCallbacks.containsKey(name) && mNamedCallbacks.get(name) == service) {
        return true;
      }
      try {
        // This restricts the client to only setting services that it gets from this server.
        mNamedCallbacks.put(name, (MyNamedCallback) service);
      } catch (Exception e) {
        Log.i("TestServiceServer", "Failed to cast service");
      }
      return false;
    }
  }
  @Override
  public boolean VerifyName(INamedCallback service, String name) throws RemoteException {
    return name.equals(service.GetName());
  }
  @Override
  public INamedCallback[] GetInterfaceArray(String[] names) throws RemoteException {
    return GetNullableInterfaceArray(names);
  }
  @Override
  public boolean VerifyNamesWithInterfaceArray(INamedCallback[] services, String[] names)
      throws RemoteException {
    return VerifyNamesWithNullableInterfaceArray(services, names);
  }
  @Override
  public INamedCallback[] GetNullableInterfaceArray(String[] names) throws RemoteException {
    if (names == null)
      return null;
    INamedCallback[] services = new INamedCallback[names.length];
    for (int i = 0; i < names.length; i++) {
      if (names[i] == null) {
        services[i] = null;
      } else {
        services[i] = GetOtherTestService(names[i]);
      }
    }
    return services;
  }
  @Override
  public boolean VerifyNamesWithNullableInterfaceArray(INamedCallback[] services, String[] names)
      throws RemoteException {
    if (services != null && names != null) {
      for (int i = 0; i < names.length; i++) {
        if (services[i] != null && names[i] != null) {
          if (!VerifyName(services[i], names[i])) {
            return false;
          }
        } else if (services[i] != null || names[i] != null) {
          return false;
        }
      }
      return true;
    } else if (services != null || names != null) {
      return false;
    } else {
      return true;
    }
  }
  @Override
  public List<INamedCallback> GetInterfaceList(String[] names) throws RemoteException {
    INamedCallback[] services = GetNullableInterfaceArray(names);
    return services == null ? null : Arrays.asList(services);
  }
  @Override
  public boolean VerifyNamesWithInterfaceList(List<INamedCallback> services, String[] names)
      throws RemoteException {
    return VerifyNamesWithNullableInterfaceArray(
        services == null ? null : services.toArray(new INamedCallback[0]), names);
  }
  @Override
  public List<String> ReverseStringList(List<String> input, List<String> repeated)
      throws RemoteException {
    ArrayList<String> reversed = new ArrayList<String>();
    for (String a : input) {
      repeated.add(a);
      reversed.add(0, a);
    }
    return reversed;
  }
  @Override
  public ParcelFileDescriptor RepeatParcelFileDescriptor(ParcelFileDescriptor read)
      throws RemoteException {
    return read;
  }
  @Override
  public ParcelFileDescriptor[] ReverseParcelFileDescriptorArray(
      ParcelFileDescriptor[] input, ParcelFileDescriptor[] repeated) throws RemoteException {
    ParcelFileDescriptor[] reversed = new ParcelFileDescriptor[input.length];
    for (int i = 0; i < input.length; i++) {
      repeated[i] = input[i];
      try {
        // extra dup, because of PARCELABLE_WRITE_RETURN_VALUE
        reversed[i] = input[input.length - i - 1].dup();
      } catch (IOException e) {
        throw new RuntimeException(e);
      }
    }
    return reversed;
  }
  @Override
  public void ThrowServiceException(int code) throws RemoteException {
    Log.i("TestServiceServer", "Throwing service specific exception " + code);
    throw new ServiceSpecificException(code);
  }
  @Override
  public int[] RepeatNullableIntArray(int[] input) throws RemoteException {
    return input;
  }
  @Override
  public byte[] RepeatNullableByteEnumArray(byte[] input) throws RemoteException {
    return input;
  }
  @Override
  public int[] RepeatNullableIntEnumArray(int[] input) throws RemoteException {
    return input;
  }
  @Override
  public long[] RepeatNullableLongEnumArray(long[] input) throws RemoteException {
    return input;
  }
  @Override
  public String RepeatNullableString(String input) throws RemoteException {
    return input;
  }
  @Override
  public List<String> RepeatNullableStringList(List<String> input) throws RemoteException {
    return input;
  }
  @Override
  public ITestService.Empty RepeatNullableParcelable(ITestService.Empty input)
      throws RemoteException {
    return input;
  }
  @Override
  public List<ITestService.Empty> RepeatNullableParcelableList(List<ITestService.Empty> input)
      throws RemoteException {
    return input;
  }
  @Override
  public ITestService.Empty[] RepeatNullableParcelableArray(ITestService.Empty[] input)
      throws RemoteException {
    return input;
  }
  @Override
  public void TakesAnIBinder(IBinder input) throws RemoteException {
    // do nothing
  }
  @Override
  public void TakesANullableIBinder(IBinder input) throws RemoteException {
    // do nothing
  }
  @Override
  public void TakesAnIBinderList(List<IBinder> input) throws RemoteException {
    // do nothing
  }
  @Override
  public void TakesANullableIBinderList(List<IBinder> input) throws RemoteException {
    // do nothing
  }

  @Override
  public String RepeatUtf8CppString(String token) throws RemoteException {
    return token;
  }
  @Override
  public String RepeatNullableUtf8CppString(String token) throws RemoteException {
    return token;
  }
  @Override
  public String[] ReverseUtf8CppString(String[] input, String[] repeated) throws RemoteException {
    String[] reversed = new String[input.length];
    for (int i = 0; i < input.length; i++) {
      repeated[i] = input[i];
      reversed[i] = input[input.length - i - 1];
    }
    return reversed;
  }
  @Override
  public String[] ReverseNullableUtf8CppString(String[] input, String[] repeated)
      throws RemoteException {
    if (input == null)
      return null;

    String[] reversed = new String[input.length];
    for (int i = 0; i < input.length; i++) {
      repeated[i] = input[i];
      reversed[i] = input[input.length - i - 1];
    }
    return reversed;
  }
  @Override
  public List<String> ReverseUtf8CppStringList(List<String> input, List<String> repeated)
      throws RemoteException {
    // note - cannot clear 'repeated' here, we can only change its length
    if (input == null)
      return null;

    ArrayList<String> reversed = new ArrayList<String>();
    for (String a : input) {
      repeated.add(a);
      reversed.add(0, a);
    }
    return reversed;
  }
  @Override
  public INamedCallback GetCallback(boolean return_null) throws RemoteException {
    if (return_null)
      return null;
    return new MyNamedCallback("a callback named GetCallback");
  }
  @Override
  public void FillOutStructuredParcelable(StructuredParcelable parcelable) throws RemoteException {
    parcelable.shouldBeJerry = "Jerry";
    parcelable.shouldContainThreeFs = new int[] {parcelable.f, parcelable.f, parcelable.f};
    parcelable.shouldBeByteBar = ByteEnum.BAR;
    parcelable.shouldBeIntBar = IntEnum.BAR;
    parcelable.shouldBeLongBar = LongEnum.BAR;
    parcelable.shouldContainTwoByteFoos = new byte[] {ByteEnum.FOO, ByteEnum.FOO};
    parcelable.shouldContainTwoIntFoos = new int[] {IntEnum.FOO, IntEnum.FOO};
    parcelable.shouldContainTwoLongFoos = new long[] {LongEnum.FOO, LongEnum.FOO};

    parcelable.const_exprs_1 = ConstantExpressionEnum.decInt32_1;
    parcelable.const_exprs_2 = ConstantExpressionEnum.decInt32_2;
    parcelable.const_exprs_3 = ConstantExpressionEnum.decInt64_1;
    parcelable.const_exprs_4 = ConstantExpressionEnum.decInt64_2;
    parcelable.const_exprs_5 = ConstantExpressionEnum.decInt64_3;
    parcelable.const_exprs_6 = ConstantExpressionEnum.decInt64_4;
    parcelable.const_exprs_7 = ConstantExpressionEnum.hexInt32_1;
    parcelable.const_exprs_8 = ConstantExpressionEnum.hexInt32_2;
    parcelable.const_exprs_9 = ConstantExpressionEnum.hexInt32_3;
    parcelable.const_exprs_10 = ConstantExpressionEnum.hexInt64_1;

    parcelable.shouldSetBit0AndBit2 = StructuredParcelable.BIT0 | StructuredParcelable.BIT2;

    parcelable.u = Union.ns(new int[] {1, 2, 3});
    parcelable.shouldBeConstS1 = Union.s(Union.S1);
  }
  @Override
  public void RepeatExtendableParcelable(ExtendableParcelable ep, ExtendableParcelable ep2)
      throws RemoteException {
    ep2.a = ep.a;
    ep2.b = ep.b;
    // no way to copy currently w/o unparceling
    ep2.ext.setParcelable(ep.ext.getParcelable(MyExt.class));
    ep2.c = ep.c;
    ep2.ext2.setParcelable(null);
  }
  @Override
  public RecursiveList ReverseList(RecursiveList list) throws RemoteException {
    RecursiveList reversed = null;
    while (list != null) {
      RecursiveList next = list.next;
      list.next = reversed;
      reversed = list;
      list = next;
    }
    return reversed;
  }
  @Override
  public IBinder[] ReverseIBinderArray(IBinder[] input, IBinder[] repeated) {
    IBinder[] reversed = new IBinder[input.length];
    for (int i = 0; i < input.length; i++) {
      repeated[i] = input[i];
      reversed[i] = input[input.length - i - 1];
    }
    return reversed;
  }
  @Override
  public IBinder[] ReverseNullableIBinderArray(IBinder[] input, IBinder[] repeated) {
    IBinder[] reversed = new IBinder[input.length];
    for (int i = 0; i < input.length; i++) {
      repeated[i] = input[i];
      reversed[i] = input[input.length - i - 1];
    }
    return reversed;
  }
  private static class MyOldName extends IOldName.Stub {
    @Override
    public String RealName() {
      return "OldName";
    }
  }

  @Override
  public IOldName GetOldNameInterface() throws RemoteException {
    return new MyOldName();
  }

  private static class MyNewName extends INewName.Stub {
    @Override
    public String RealName() {
      return "NewName";
    }
  }

  @Override
  public INewName GetNewNameInterface() throws RemoteException {
    return new MyNewName();
  }

  @Override
  public int[] GetUnionTags(Union[] input) throws RemoteException {
    int[] tags = new int[input.length];
    for (int i = 0; i < input.length; i++) {
      tags[i] = input[i].getTag();
    }
    return tags;
  }

  class MyCppJavaTests extends ICppJavaTests.Stub {
    @Override
    public BadParcelable RepeatBadParcelable(BadParcelable input) throws RemoteException {
      return input;
    }
    @Override
    public SimpleParcelable RepeatSimpleParcelable(SimpleParcelable input, SimpleParcelable repeat)
        throws RemoteException {
      repeat.set(input.getName(), input.getNumber());
      return input;
    }
    @Override
    public GenericStructuredParcelable<Integer, StructuredParcelable, Integer>
    RepeatGenericParcelable(
        GenericStructuredParcelable<Integer, StructuredParcelable, Integer> input,
        GenericStructuredParcelable<Integer, StructuredParcelable, Integer> repeat)
        throws RemoteException {
      repeat.a = input.a;
      repeat.b = input.b;
      return input;
    }
    @Override
    public PersistableBundle RepeatPersistableBundle(PersistableBundle input)
        throws RemoteException {
      return input;
    }
    @Override
    public SimpleParcelable[] ReverseSimpleParcelables(
        SimpleParcelable[] input, SimpleParcelable[] repeated) throws RemoteException {
      SimpleParcelable[] reversed = new SimpleParcelable[input.length];
      for (int i = 0; i < input.length; i++) {
        repeated[i] = input[i];
        reversed[i] = input[input.length - i - 1];
      }
      return reversed;
    }
    @Override
    public PersistableBundle[] ReversePersistableBundles(
        PersistableBundle[] input, PersistableBundle[] repeated) throws RemoteException {
      PersistableBundle[] reversed = new PersistableBundle[input.length];
      for (int i = 0; i < input.length; i++) {
        repeated[i] = input[i];
        reversed[i] = input[input.length - i - 1];
      }
      return reversed;
    }
    @Override
    public Union ReverseUnion(Union input, Union repeated) throws RemoteException {
      int[] repeatedArray = new int[input.getNs().length];
      int[] reversedArray = ReverseInt(input.getNs(), repeatedArray);
      repeated.setNs(repeatedArray);
      return Union.ns(reversedArray);
    }
    @Override
    public List<IBinder> ReverseNamedCallbackList(List<IBinder> input, List<IBinder> repeated)
        throws RemoteException {
      ArrayList<IBinder> reversed = new ArrayList<IBinder>();
      for (IBinder a : input) {
        repeated.add(a);
        reversed.add(0, a);
      }
      return reversed;
    }
    @Override
    public FileDescriptor RepeatFileDescriptor(FileDescriptor read) throws RemoteException {
      return read;
    }
    @Override
    public FileDescriptor[] ReverseFileDescriptorArray(
        FileDescriptor[] input, FileDescriptor[] repeated) throws RemoteException {
      FileDescriptor[] reversed = new FileDescriptor[input.length];
      for (int i = 0; i < input.length; i++) {
        repeated[i] = input[i];
        reversed[i] = input[input.length - i - 1];
      }
      return reversed;
    }
  }

  public static class FixedSizeArrayService extends IRepeatFixedSizeArray.Stub {
    @Override
    public byte[] RepeatBytes(byte[] input, byte[] repeated) throws RemoteException {
      for (int i = 0; i < input.length; i++) {
        repeated[i] = input[i];
      }
      return input;
    }
    @Override
    public int[] RepeatInts(int[] input, int[] repeated) throws RemoteException {
      for (int i = 0; i < input.length; i++) {
        repeated[i] = input[i];
      }
      return input;
    }
    @Override
    public IBinder[] RepeatBinders(IBinder[] input, IBinder[] repeated) throws RemoteException {
      for (int i = 0; i < input.length; i++) {
        repeated[i] = input[i];
      }
      return input;
    }
    @Override
    public IntParcelable[] RepeatParcelables(IntParcelable[] input, IntParcelable[] repeated)
        throws RemoteException {
      for (int i = 0; i < input.length; i++) {
        repeated[i] = input[i];
      }
      return input;
    }
    @Override
    public byte[][] Repeat2dBytes(byte[][] input, byte[][] repeated) throws RemoteException {
      for (int i = 0; i < input.length; i++) {
        for (int j = 0; j < input[i].length; j++) {
          repeated[i][j] = input[i][j];
        }
      }
      return input;
    }
    @Override
    public int[][] Repeat2dInts(int[][] input, int[][] repeated) throws RemoteException {
      for (int i = 0; i < input.length; i++) {
        for (int j = 0; j < input[i].length; j++) {
          repeated[i][j] = input[i][j];
        }
      }
      return input;
    }
    @Override
    public IBinder[][] Repeat2dBinders(IBinder[][] input, IBinder[][] repeated)
        throws RemoteException {
      for (int i = 0; i < input.length; i++) {
        for (int j = 0; j < input[i].length; j++) {
          repeated[i][j] = input[i][j];
        }
      }
      return input;
    }
    @Override
    public IntParcelable[][] Repeat2dParcelables(
        IntParcelable[][] input, IntParcelable[][] repeated) throws RemoteException {
      for (int i = 0; i < input.length; i++) {
        for (int j = 0; j < input[i].length; j++) {
          repeated[i][j] = input[i][j];
        }
      }
      return input;
    }
  }

  @Override
  public IBinder GetCppJavaTests() throws RemoteException {
    return new MyCppJavaTests();
  }
  @Override
  public byte getBackendType() throws RemoteException {
    return BackendType.JAVA;
  }

  private static class MyCircular extends ICircular.Stub {
    private ITestService mSrv;

    MyCircular(ITestService srv) { mSrv = srv; }

    @Override
    public ITestService GetTestService() {
      return mSrv;
    }
  }

  @Override
  public ICircular GetCircular(CircularParcelable cp) throws RemoteException {
    cp.testService = this;
    return new MyCircular(this);
  }
}