1 // Copyright 2019 The Chromium Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 package org.jni_zero; 6 7 import org.chromium.build.BuildConfig; 8 9 /** 10 * Exposes native library loading status. 11 */ 12 public class NativeLibraryLoadedStatus { 13 /** 14 * Interface for querying native method availability. 15 */ 16 public interface NativeLibraryLoadedStatusProvider { areNativeMethodsReady()17 boolean areNativeMethodsReady(); 18 } 19 20 private static NativeLibraryLoadedStatusProvider sProvider; 21 22 public static class NativeNotLoadedException extends RuntimeException { NativeNotLoadedException(String s)23 public NativeNotLoadedException(String s) { 24 super(s); 25 } 26 } 27 checkLoaded()28 public static void checkLoaded() { 29 if (sProvider == null) return; 30 31 if (!sProvider.areNativeMethodsReady()) { 32 throw new NativeNotLoadedException( 33 "Native method called before the native library was ready."); 34 } 35 } 36 setProvider(NativeLibraryLoadedStatusProvider statusProvider)37 public static void setProvider(NativeLibraryLoadedStatusProvider statusProvider) { 38 sProvider = statusProvider; 39 } 40 getProviderForTesting()41 public static NativeLibraryLoadedStatusProvider getProviderForTesting() { 42 return sProvider; 43 } 44 } 45