1 /* 2 * Copyright (C) 2021 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 package android.binder.cts; 17 18 /** 19 * Manual implementation of AIDL service. Warning: it is strongly recommended to use AIDL directly. 20 * This interface does not do any type checking or handle errors. 21 */ 22 public interface ILegacyBinder extends android.os.IInterface { 23 public static class Stub extends android.os.Binder implements ILegacyBinder { Stub()24 public Stub() { 25 super(DESCRIPTOR); 26 this.attachInterface(this, DESCRIPTOR); 27 } asInterface(android.os.IBinder obj)28 public static ILegacyBinder asInterface(android.os.IBinder obj) { 29 if (obj == null) { 30 return null; 31 } 32 android.os.IInterface iin = obj.queryLocalInterface(DESCRIPTOR); 33 if (((iin != null) && (iin instanceof ILegacyBinder))) { 34 return ((ILegacyBinder) iin); 35 } 36 return new ILegacyBinder.Stub.Proxy(obj); 37 } 38 @Override RepeatInt(int in)39 public int RepeatInt(int in) throws android.os.RemoteException { 40 return in; 41 } 42 @Override asBinder()43 public android.os.IBinder asBinder() { 44 return this; 45 } 46 @Override onTransact(int code, android.os.Parcel data, android.os.Parcel reply, int flags)47 public boolean onTransact(int code, android.os.Parcel data, android.os.Parcel reply, int flags) 48 throws android.os.RemoteException { 49 switch (code) { 50 case TRANSACTION_RepeatInt: { 51 reply.writeInt(RepeatInt(data.readInt())); 52 return true; 53 } 54 default: { 55 return super.onTransact(code, data, reply, flags); 56 } 57 } 58 } 59 private static class Proxy implements ILegacyBinder { 60 private android.os.IBinder mRemote; Proxy(android.os.IBinder remote)61 Proxy(android.os.IBinder remote) { 62 mRemote = remote; 63 } 64 @Override asBinder()65 public android.os.IBinder asBinder() { 66 return mRemote; 67 } getInterfaceDescriptor()68 public String getInterfaceDescriptor() { 69 return DESCRIPTOR; 70 } 71 @Override RepeatInt(int in)72 public int RepeatInt(int in) throws android.os.RemoteException { 73 android.os.Parcel data = android.os.Parcel.obtain(); 74 android.os.Parcel reply = android.os.Parcel.obtain(); 75 try { 76 data.writeInt(in); 77 mRemote.transact(Stub.TRANSACTION_RepeatInt, data, reply, 0); 78 return reply.readInt(); 79 } finally { 80 reply.recycle(); 81 data.recycle(); 82 } 83 } 84 } 85 static final int TRANSACTION_RepeatInt = (android.os.IBinder.FIRST_CALL_TRANSACTION + 0); 86 } 87 public static final String DESCRIPTOR = "LegacyBinder"; RepeatInt(int in)88 public int RepeatInt(int in) throws android.os.RemoteException; 89 } 90