| 1 |
/* |
| 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 |
|
| 17 |
import art.Redefinition; |
| 18 |
import java.util.Arrays; |
| 19 |
|
| 20 |
public class Main { |
| 21 |
|
| 22 |
public static void main(String[] args) { |
| 23 |
Verification.doTest(new Transform()); |
| 24 |
NewName.doTest(new Transform()); |
| 25 |
DifferentAccess.doTest(new Transform()); |
| 26 |
NewInterface.doTest(new Transform2()); |
| 27 |
MissingInterface.doTest(new Transform2()); |
| 28 |
ReorderInterface.doTest(new Transform2()); |
| 29 |
MultiRedef.doTest(new Transform(), new Transform2()); |
| 30 |
MultiRetrans.doTest(new Transform(), new Transform2()); |
| 31 |
NewMethod.doTest(new Transform()); |
| 32 |
MissingMethod.doTest(new Transform3()); |
| 33 |
MethodChange.doTest(new Transform()); |
| 34 |
NewField.doTest(new Transform()); |
| 35 |
MissingField.doTest(new Transform4("there")); |
| 36 |
FieldChange.doTest(new Transform4("there again")); |
| 37 |
Unmodifiable.doTest(new Transform[] { new Transform(), }); |
| 38 |
Undefault.doTest(new Transform5()); |
| 39 |
} |
| 40 |
|
| 41 |
// TODO Replace this shim with a better re-write of this test. |
| 42 |
private static Redefinition.CommonClassDefinition mapCCD(CommonClassDefinition d) { |
| 43 |
return new Redefinition.CommonClassDefinition(d.target, d.class_file_bytes, d.dex_file_bytes); |
| 44 |
} |
| 45 |
|
| 46 |
private static Redefinition.CommonClassDefinition[] toCCDA(CommonClassDefinition[] ds) { |
| 47 |
return Arrays.stream(ds).map(Main::mapCCD).toArray(Redefinition.CommonClassDefinition[]::new); |
| 48 |
} |
| 49 |
|
| 50 |
public static void doCommonClassRedefinition(Class<?> target, |
| 51 |
byte[] classfile, |
| 52 |
byte[] dexfile) throws Exception { |
| 53 |
Redefinition.doCommonClassRedefinition(target, classfile, dexfile); |
| 54 |
} |
| 55 |
public static void doMultiClassRedefinition(CommonClassDefinition... defs) throws Exception { |
| 56 |
Redefinition.doMultiClassRedefinition(toCCDA(defs)); |
| 57 |
} |
| 58 |
public static void addMultiTransformationResults(CommonClassDefinition... defs) throws Exception { |
| 59 |
Redefinition.addMultiTransformationResults(toCCDA(defs)); |
| 60 |
} |
| 61 |
public static void doCommonMultiClassRedefinition(Class<?>[] targets, |
| 62 |
byte[][] classfiles, |
| 63 |
byte[][] dexfiles) throws Exception { |
| 64 |
Redefinition.doCommonMultiClassRedefinition(targets, classfiles, dexfiles); |
| 65 |
} |
| 66 |
public static void doCommonClassRetransformation(Class<?>... target) throws Exception { |
| 67 |
Redefinition.doCommonClassRetransformation(target); |
| 68 |
} |
| 69 |
public static void enableCommonRetransformation(boolean enable) { |
| 70 |
Redefinition.enableCommonRetransformation(enable); |
| 71 |
} |
| 72 |
public static void addCommonTransformationResult(String target_name, |
| 73 |
byte[] class_bytes, |
| 74 |
byte[] dex_bytes) { |
| 75 |
Redefinition.addCommonTransformationResult(target_name, class_bytes, dex_bytes); |
| 76 |
} |
| 77 |
} |