1 /* 2 * Copyright (C) 2016 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 package art; 18 19 import java.util.Base64; 20 21 public class Test1997 { 22 23 public static class SuperTransform { 24 // We will be shadowing this function. sayHi()25 public static void sayHi() { 26 System.out.println("Hello!"); 27 } 28 } 29 30 // The class we will be transforming. 31 public static class Transform extends SuperTransform { sayHiTwice()32 public static void sayHiTwice() { 33 Transform.sayHi(); 34 Transform.sayHi(); 35 } 36 } 37 38 // public static class Transform extends SuperTransform { 39 // public static void sayHiTwice() { 40 // Transform.sayHi(); 41 // Transform.sayHi(); 42 // } 43 // public static void sayHi() { 44 // System.out.println("Hello World!"); 45 // } 46 // } 47 private static final byte[] DEX_BYTES = 48 Base64.getDecoder() 49 .decode( 50 "ZGV4CjAzNQA9wdy7Lgbrv+sD+wixborREr0maZCK5yqABAAAcAAAAHhWNBIAAAAAAAAAALwDAAAW" 51 + "AAAAcAAAAAkAAADIAAAAAgAAAOwAAAABAAAABAEAAAUAAAAMAQAAAQAAADQBAAAsAwAAVAEAAMIB" 52 + "AADKAQAA2AEAAPcBAAARAgAAIQIAAEUCAABlAgAAfAIAAJACAACkAgAAswIAAL4CAADBAgAAxQIA" 53 + "ANICAADYAgAA3QIAAOYCAADtAgAA+QIAAAADAAACAAAAAwAAAAQAAAAFAAAABgAAAAcAAAAIAAAA" 54 + "CQAAAAwAAAAMAAAACAAAAAAAAAANAAAACAAAALwBAAAHAAUAEAAAAAAAAAAAAAAAAQAAAAAAAAAB" 55 + "AAAAEgAAAAEAAAATAAAABQABABEAAAABAAAAAQAAAAAAAA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AABUAQAAAyAAAAMAAACqAQAAARAAAAEAAAC8AQAAAiAA" 69 + "ABYAAADCAQAABCAAAAIAAAB4AwAAACAAAAEAAACHAwAAAxAAAAIAAACcAwAABiAAAAEAAACsAwAA" 70 + "ABAAAAEAAAC8AwAA"); 71 run()72 public static void run() throws Exception { 73 Redefinition.setTestConfiguration(Redefinition.Config.COMMON_REDEFINE); 74 doTest(); 75 } 76 doTest()77 public static void doTest() throws Exception { 78 Transform.sayHiTwice(); 79 Transform.sayHi(); 80 Redefinition.doCommonStructuralClassRedefinition(Transform.class, DEX_BYTES); 81 Transform.sayHiTwice(); 82 Transform.sayHi(); 83 } 84 } 85