blob: 43d6e9ed070194015d12863c75f8bb4419bddfb2 [file] [log] [blame]
Alex Light460d1b42017-01-10 15:37:17 +00001/*
2 * Copyright (C) 2017 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
Alex Light0e692732017-01-10 15:00:05 -080017import java.util.ArrayList;
Alex Light460d1b42017-01-10 15:37:17 +000018public class Main {
19
20 public static void main(String[] args) {
21 System.loadLibrary(args[1]);
22 NewName.doTest(new Transform());
23 DifferentAccess.doTest(new Transform());
24 NewInterface.doTest(new Transform2());
25 MissingInterface.doTest(new Transform2());
26 ReorderInterface.doTest(new Transform2());
Alex Light0e692732017-01-10 15:00:05 -080027 MultiRedef.doTest(new Transform(), new Transform2());
Alex Light6ac57502017-01-19 15:05:06 -080028 MultiRetrans.doTest(new Transform(), new Transform2());
Alex Light460d1b42017-01-10 15:37:17 +000029 }
30
31 // Transforms the class. This throws an exception if something goes wrong.
32 public static native void doCommonClassRedefinition(Class<?> target,
33 byte[] classfile,
34 byte[] dexfile) throws Exception;
Alex Light0e692732017-01-10 15:00:05 -080035
36 public static void doMultiClassRedefinition(CommonClassDefinition... defs) throws Exception {
37 ArrayList<Class<?>> classes = new ArrayList<>();
38 ArrayList<byte[]> class_files = new ArrayList<>();
39 ArrayList<byte[]> dex_files = new ArrayList<>();
40
41 for (CommonClassDefinition d : defs) {
42 classes.add(d.target);
43 class_files.add(d.class_file_bytes);
44 dex_files.add(d.dex_file_bytes);
45 }
46 doCommonMultiClassRedefinition(classes.toArray(new Class<?>[0]),
47 class_files.toArray(new byte[0][]),
48 dex_files.toArray(new byte[0][]));
49 }
50
Alex Light6ac57502017-01-19 15:05:06 -080051 public static void addMultiTransformationResults(CommonClassDefinition... defs) throws Exception {
52 for (CommonClassDefinition d : defs) {
53 addCommonTransformationResult(d.target.getCanonicalName(),
54 d.class_file_bytes,
55 d.dex_file_bytes);
56 }
57 }
58
Alex Light0e692732017-01-10 15:00:05 -080059 public static native void doCommonMultiClassRedefinition(Class<?>[] targets,
60 byte[][] classfiles,
61 byte[][] dexfiles) throws Exception;
Alex Light6ac57502017-01-19 15:05:06 -080062 public static native void doCommonClassRetransformation(Class<?>... target) throws Exception;
63 public static native void enableCommonRetransformation(boolean enable);
64 public static native void addCommonTransformationResult(String target_name,
65 byte[] class_bytes,
66 byte[] dex_bytes);
Alex Light460d1b42017-01-10 15:37:17 +000067}