• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.chromium.base;
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 
checkLoaded()22     public static void checkLoaded() {
23         // Necessary to make sure all of these calls are stripped in release builds.
24         if (!BuildConfig.ENABLE_ASSERTS) return;
25 
26         if (sProvider == null) return;
27 
28         if (!sProvider.areNativeMethodsReady()) {
29             throw new JniException(
30                     String.format("Native method called before the native library was ready."));
31         }
32     }
33 
setProvider(NativeLibraryLoadedStatusProvider statusProvider)34     public static void setProvider(NativeLibraryLoadedStatusProvider statusProvider) {
35         sProvider = statusProvider;
36     }
37 
getProviderForTesting()38     public static NativeLibraryLoadedStatusProvider getProviderForTesting() {
39         return sProvider;
40     }
41 }
42