blob: b425da87b5a895d5268773b9ed4648b17a0982a7 [file] [log] [blame]
Andreas Gampee8067322015-09-08 17:42:59 -07001/*
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
17import java.lang.annotation.Annotation;
18import java.lang.reflect.InvocationHandler;
19import java.lang.reflect.InvocationTargetException;
20import java.lang.reflect.Constructor;
21import java.lang.reflect.Field;
22import java.lang.reflect.Method;
23import java.lang.reflect.Proxy;
24import java.util.Arrays;
25import java.util.Comparator;
26
27/**
28 * Test invoking a proxy method from native code.
29 */
30
31interface NativeInterface {
32 public void callback();
33}
34
35public class NativeProxy {
36
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 {
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
61 public static native void nativeCall(NativeInterface inf);
62}