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 public class Test1999 { 21 22 public static class Transform { getGreeting()23 public String getGreeting() { 24 return "Hi"; 25 } 26 } 27 28 public static class SubTransform extends Transform { 29 private int count = 0; sayHi()30 public void sayHi() { 31 System.out.println(getGreeting() + "(SubTransform called " + (++count) + " times)"); 32 } 33 } 34 35 /** 36 * base64 encoded class/dex file for 37 * public static class Transform { 38 * private int count; 39 * public String getGreeting() { 40 * return "Hello (Transform called " + incrCount() + " times)"; 41 * } 42 * protected int incrCount() { 43 * return ++count; 44 * } 45 * } 46 */ 47 private static final byte[] DEX_BYTES = Base64.getDecoder().decode( 48 "ZGV4CjAzNQAwwbMpPdPdWkU+6UJnvqa7v4VBdcuq2vkMBQAAcAAAAHhWNBIAAAAAAAAAAEgEAAAa" + 49 "AAAAcAAAAAkAAADYAAAABQAAAPwAAAABAAAAOAEAAAgAAABAAQAAAQAAAIABAABsAwAAoAEAADoC" + 50 "AABDAgAASwIAAGUCAABoAgAAawIAAG8CAABzAgAAjQIAAJ0CAADBAgAA4QIAAPUCAAAJAwAAJAMA" + 51 "ADMDAAA+AwAAQQMAAE4DAABWAwAAXQMAAGoDAAB1AwAAewMAAIUDAACMAwAAAwAAAAcAAAAIAAAA" + 52 "CQAAAAoAAAALAAAADAAAAA0AAAAQAAAAAwAAAAAAAAAAAAAABAAAAAYAAAAAAAAABQAAAAcAAAAs" + 53 "AgAABgAAAAcAAAA0AgAAEAAAAAgAAAAAAAAAAQAAABMAAAABAAQAA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AAQEAAAKBAAALAQA" + 67 "AAAAAAAAAAAAAAAAABAAAAAAAAAAAQAAAAAAAAABAAAAGgAAAHAAAAACAAAACQAAANgAAAADAAAA" + 68 "BQAAAPwAAAAEAAAAAQAAADgBAAAFAAAACAAAAEABAAAGAAAAAQAAAIABAAABIAAAAwAAAKABAAAD" + 69 "IAAAAwAAACACAAABEAAAAgAAACwCAAACIAAAGgAAADoCAAAEIAAAAgAAAAQEAAAAIAAAAQAAABME" + 70 "AAADEAAAAgAAACgEAAAGIAAAAQAAADgEAAAAEAAAAQAAAEgEAAA="); 71 72 run()73 public static void run() { 74 Redefinition.setTestConfiguration(Redefinition.Config.COMMON_REDEFINE); 75 doTest(new SubTransform()); 76 } 77 doTest(SubTransform t)78 public static void doTest(SubTransform t) { 79 t.sayHi(); 80 t.sayHi(); 81 t.sayHi(); 82 Redefinition.doCommonStructuralClassRedefinition(Transform.class, DEX_BYTES); 83 t.sayHi(); 84 } 85 } 86