• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2019 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.io.File;
18 import java.lang.reflect.Field;
19 import java.lang.reflect.InvocationHandler;
20 import java.lang.reflect.Method;
21 import java.lang.reflect.Proxy;
22 
23 public class Main {
main(String[] args)24   public static void main(String[] args) throws Exception {
25     System.loadLibrary(args[0]);
26     init();
27     appendToBootClassLoader(DEX_EXTRA, /* isCorePlatform */ false);
28 
29     Class<?> klass = Object.class.getClassLoader().loadClass("MyInterface");
30     Object obj = Proxy.newProxyInstance(
31         klass.getClassLoader(),
32         new Class[] { klass, Cloneable.class },
33         new InvocationHandler() {
34           @Override
35           public Object invoke(Object proxy, Method method, Object[] args) {
36             return null;
37           }
38         });
39 
40     // Print names of declared methods - this should not include "hidden()".
41     for (Method m : obj.getClass().getDeclaredMethods()) {
42       System.out.println(m.getName());
43     }
44 
45     // Do not print names of fields. They do not have a set Java name.
46     if (obj.getClass().getDeclaredFields().length != 2) {
47       throw new Exception("Expected two fields in a proxy class: 'interfaces' and 'throws'");
48     }
49   }
50 
51   private static final String DEX_EXTRA = new File(System.getenv("DEX_LOCATION"),
52       "691-hiddenapi-proxy-ex.jar").getAbsolutePath();
53 
init()54   private static native void init();
appendToBootClassLoader(String dexPath, boolean isCorePlatform)55   private static native void appendToBootClassLoader(String dexPath, boolean isCorePlatform);
56 }
57