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 import java.lang.annotation.Annotation; 18 import java.lang.reflect.InvocationHandler; 19 import java.lang.reflect.InvocationTargetException; 20 import java.lang.reflect.Constructor; 21 import java.lang.reflect.Field; 22 import java.lang.reflect.Method; 23 import java.lang.reflect.Proxy; 24 import java.util.Arrays; 25 import java.util.Comparator; 26 27 /** 28 * Test invoking a proxy method from native code. 29 */ 30 31 interface NativeInterface { callback()32 public void callback(); 33 } 34 35 public class NativeProxy { 36 main(String[] args)37 public static void main(String[] args) { 38 System.loadLibrary(args[0]); 39 40 try { 41 NativeInterface inf = (NativeInterface)Proxy.newProxyInstance( 42 NativeProxy.class.getClassLoader(), 43 new Class<?>[] { NativeInterface.class }, 44 new NativeInvocationHandler()); 45 46 nativeCall(inf); 47 } catch (Exception exc) { 48 throw new RuntimeException(exc); 49 } 50 } 51 52 public static class NativeInvocationHandler implements InvocationHandler { invoke(final Object proxy, final Method method, final Object[] args)53 public Object invoke(final Object proxy, 54 final Method method, 55 final Object[] args) throws Throwable { 56 System.out.println(method.getName()); 57 return null; 58 } 59 } 60 nativeCall(NativeInterface inf)61 public static native void nativeCall(NativeInterface inf); 62 } 63