blob: 67ca1e15d60d7de2f0096be450fb8b0a35644dda [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) {
Alex Light460d1b42017-01-10 15:37:17 +000021 NewName.doTest(new Transform());
22 DifferentAccess.doTest(new Transform());
23 NewInterface.doTest(new Transform2());
24 MissingInterface.doTest(new Transform2());
25 ReorderInterface.doTest(new Transform2());
Alex Light0e692732017-01-10 15:00:05 -080026 MultiRedef.doTest(new Transform(), new Transform2());
Alex Light6ac57502017-01-19 15:05:06 -080027 MultiRetrans.doTest(new Transform(), new Transform2());
Alex Light460d1b42017-01-10 15:37:17 +000028 }
29
30 // Transforms the class. This throws an exception if something goes wrong.
31 public static native void doCommonClassRedefinition(Class<?> target,
32 byte[] classfile,
33 byte[] dexfile) throws Exception;
Alex Light0e692732017-01-10 15:00:05 -080034
35 public static void doMultiClassRedefinition(CommonClassDefinition... defs) throws Exception {
36 ArrayList<Class<?>> classes = new ArrayList<>();
37 ArrayList<byte[]> class_files = new ArrayList<>();
38 ArrayList<byte[]> dex_files = new ArrayList<>();
39
40 for (CommonClassDefinition d : defs) {
41 classes.add(d.target);
42 class_files.add(d.class_file_bytes);
43 dex_files.add(d.dex_file_bytes);
44 }
45 doCommonMultiClassRedefinition(classes.toArray(new Class<?>[0]),
46 class_files.toArray(new byte[0][]),
47 dex_files.toArray(new byte[0][]));
48 }
49
Alex Light6ac57502017-01-19 15:05:06 -080050 public static void addMultiTransformationResults(CommonClassDefinition... defs) throws Exception {
51 for (CommonClassDefinition d : defs) {
52 addCommonTransformationResult(d.target.getCanonicalName(),
53 d.class_file_bytes,
54 d.dex_file_bytes);
55 }
56 }
57
Alex Light0e692732017-01-10 15:00:05 -080058 public static native void doCommonMultiClassRedefinition(Class<?>[] targets,
59 byte[][] classfiles,
60 byte[][] dexfiles) throws Exception;
Alex Light6ac57502017-01-19 15:05:06 -080061 public static native void doCommonClassRetransformation(Class<?>... target) throws Exception;
62 public static native void enableCommonRetransformation(boolean enable);
63 public static native void addCommonTransformationResult(String target_name,
64 byte[] class_bytes,
65 byte[] dex_bytes);
Alex Light460d1b42017-01-10 15:37:17 +000066}