1*795d594fSAndroid Build Coastguard Worker /* 2*795d594fSAndroid Build Coastguard Worker * Copyright (C) 2017 The Android Open Source Project 3*795d594fSAndroid Build Coastguard Worker * 4*795d594fSAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License"); 5*795d594fSAndroid Build Coastguard Worker * you may not use this file except in compliance with the License. 6*795d594fSAndroid Build Coastguard Worker * You may obtain a copy of the License at 7*795d594fSAndroid Build Coastguard Worker * 8*795d594fSAndroid Build Coastguard Worker * http://www.apache.org/licenses/LICENSE-2.0 9*795d594fSAndroid Build Coastguard Worker * 10*795d594fSAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software 11*795d594fSAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS, 12*795d594fSAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13*795d594fSAndroid Build Coastguard Worker * See the License for the specific language governing permissions and 14*795d594fSAndroid Build Coastguard Worker * limitations under the License. 15*795d594fSAndroid Build Coastguard Worker */ 16*795d594fSAndroid Build Coastguard Worker 17*795d594fSAndroid Build Coastguard Worker public class Main { 18*795d594fSAndroid Build Coastguard Worker public static String TEST_NAME = "158-app-image-class-table"; 19*795d594fSAndroid Build Coastguard Worker main(String[] args)20*795d594fSAndroid Build Coastguard Worker public static void main(String[] args) { 21*795d594fSAndroid Build Coastguard Worker try { 22*795d594fSAndroid Build Coastguard Worker Class<?> class_loader_class = Class.forName("dalvik.system.PathClassLoader"); 23*795d594fSAndroid Build Coastguard Worker System.loadLibrary(args[0]); 24*795d594fSAndroid Build Coastguard Worker } catch (ClassNotFoundException e) { 25*795d594fSAndroid Build Coastguard Worker usingRI = true; 26*795d594fSAndroid Build Coastguard Worker // Add expected JNI_OnLoad log line to match expected-stdout.txt. 27*795d594fSAndroid Build Coastguard Worker System.out.println("JNI_OnLoad called"); 28*795d594fSAndroid Build Coastguard Worker } 29*795d594fSAndroid Build Coastguard Worker try { 30*795d594fSAndroid Build Coastguard Worker // Resolve but do not initialize TestImplementation. During the resolution, 31*795d594fSAndroid Build Coastguard Worker // we see the Cloneable in the dex cache, so we do not try to look it up 32*795d594fSAndroid Build Coastguard Worker // or resolve it. 33*795d594fSAndroid Build Coastguard Worker Class<?> timpl = 34*795d594fSAndroid Build Coastguard Worker Class.forName("TestImplementation", false, Main.class.getClassLoader()); 35*795d594fSAndroid Build Coastguard Worker // Clear the dex cache resolved types to force a proper lookup the next time 36*795d594fSAndroid Build Coastguard Worker // we need to find TestInterface. 37*795d594fSAndroid Build Coastguard Worker clearResolvedTypes(timpl); 38*795d594fSAndroid Build Coastguard Worker // Force intialization of TestImplementation. This expects the interface type 39*795d594fSAndroid Build Coastguard Worker // to be resolved and found through simple lookup. 40*795d594fSAndroid Build Coastguard Worker timpl.newInstance(); 41*795d594fSAndroid Build Coastguard Worker } catch (Throwable t) { 42*795d594fSAndroid Build Coastguard Worker t.printStackTrace(System.out); 43*795d594fSAndroid Build Coastguard Worker } 44*795d594fSAndroid Build Coastguard Worker } 45*795d594fSAndroid Build Coastguard Worker clearResolvedTypes(Class<?> c)46*795d594fSAndroid Build Coastguard Worker public static void clearResolvedTypes(Class<?> c) { 47*795d594fSAndroid Build Coastguard Worker if (!usingRI) { 48*795d594fSAndroid Build Coastguard Worker nativeClearResolvedTypes(c); 49*795d594fSAndroid Build Coastguard Worker } 50*795d594fSAndroid Build Coastguard Worker } 51*795d594fSAndroid Build Coastguard Worker 52*795d594fSAndroid Build Coastguard Worker private static boolean usingRI = false; 53*795d594fSAndroid Build Coastguard Worker nativeClearResolvedTypes(Class<?> c)54*795d594fSAndroid Build Coastguard Worker public static native void nativeClearResolvedTypes(Class<?> c); 55*795d594fSAndroid Build Coastguard Worker } 56