OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.base; | 5 package org.chromium.base; |
6 | 6 |
| 7 import org.chromium.base.JniRegistrationType.JniRegistrationTypeEnum; |
7 import org.chromium.base.annotations.CalledByNative; | 8 import org.chromium.base.annotations.CalledByNative; |
8 import org.chromium.base.annotations.MainDex; | 9 import org.chromium.base.annotations.MainDex; |
9 | 10 |
10 /** | 11 /** |
11 * This class provides JNI-related methods to the native library. | 12 * This class provides JNI-related methods to the native library. |
12 */ | 13 */ |
13 @MainDex | 14 @MainDex |
14 public class JNIUtils { | 15 public class JNIUtils { |
| 16 @JniRegistrationTypeEnum |
| 17 private static int sJniRegistrationType = JniRegistrationType.ALL_JNI_REGIST
RATION; |
| 18 |
15 /** | 19 /** |
16 * This returns a ClassLoader that is capable of loading Chromium Java code.
Such a ClassLoader | 20 * This returns a ClassLoader that is capable of loading Chromium Java code.
Such a ClassLoader |
17 * is needed for the few cases where the JNI mechanism is unable to automati
cally determine the | 21 * is needed for the few cases where the JNI mechanism is unable to automati
cally determine the |
18 * appropriate ClassLoader instance. | 22 * appropriate ClassLoader instance. |
19 */ | 23 */ |
20 @CalledByNative | 24 @CalledByNative |
21 public static Object getClassLoader() { | 25 public static Object getClassLoader() { |
22 return JNIUtils.class.getClassLoader(); | 26 return JNIUtils.class.getClassLoader(); |
23 } | 27 } |
| 28 |
| 29 /** |
| 30 * @return the type of JNI registration to perform when the native libraries
are loaded. |
| 31 */ |
| 32 @JniRegistrationTypeEnum |
| 33 @CalledByNative |
| 34 public static int getJniRegistrationType() { |
| 35 return sJniRegistrationType; |
| 36 } |
| 37 |
| 38 /** |
| 39 * Set the JNI registration type so that native side can register the correc
t JNI methods. |
| 40 * Must be called before the native library is loaded. |
| 41 * @param jniRegistrationType the type of JNI registration to perform when l
oading native |
| 42 * libraries. |
| 43 */ |
| 44 public static void setJniRegistrationType(@JniRegistrationTypeEnum int jniRe
gistrationType) { |
| 45 sJniRegistrationType = jniRegistrationType; |
| 46 } |
24 } | 47 } |
OLD | NEW |