• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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 dalvik.system.PathClassLoader;
18 
19 public class Main {
20     static String DEX_FILE = System.getenv("DEX_LOCATION") + "/833-background-verification.jar";
21     static String DEX_FILE_EX = System.getenv("DEX_LOCATION") + "/833-background-verification-ex.jar";
22 
main(String[] args)23     public static void main(String[] args) throws Exception {
24       runTest(new UnknownLoader(DEX_FILE_EX));
25       runTest(new PathClassLoader(DEX_FILE_EX, new UnknownLoader(DEX_FILE)));
26     }
27 
runTest(ClassLoader loader)28     public static void runTest(ClassLoader loader) throws Exception {
29       // Use the class that will be verified the last by the background verifier. This maximises our
30       // chance of hitting the race. We load it now so that the background verifier can also load
31       // it.
32       Class<?> clsa = loader.loadClass("Classa");
33       Class<?> cls1 = Class.forName("Class1", true, loader);
34       // Give some time for the background verification to verify "Classa".
35       Thread.sleep(1000);
36       clsa.newInstance();
37     }
38 }
39 
40 class UnknownLoader extends PathClassLoader {
UnknownLoader(String dexFile)41   public UnknownLoader(String dexFile) {
42     super(dexFile, Object.class.getClassLoader());
43   }
44 }
45