1
1
package org .linusu ;
2
2
3
- import java .security .NoSuchAlgorithmException ;
4
- import java .security .SecureRandom ;
5
-
6
- import android .util .Base64 ;
7
-
8
3
import com .facebook .react .bridge .ReactApplicationContext ;
9
4
import com .facebook .react .bridge .ReactContextBaseJavaModule ;
10
5
import com .facebook .react .bridge .ReactMethod ;
11
- import com .facebook .react .bridge .Callback ;
12
6
13
7
public class RNGetRandomValuesModule extends ReactContextBaseJavaModule {
14
-
15
- private final ReactApplicationContext reactContext ;
8
+ private native void nativeInstall (long jsiPtr , String docDir );
16
9
17
10
public RNGetRandomValuesModule (ReactApplicationContext reactContext ) {
18
11
super (reactContext );
19
- this .reactContext = reactContext ;
20
12
}
21
13
22
14
@ Override
@@ -25,12 +17,18 @@ public String getName() {
25
17
}
26
18
27
19
@ ReactMethod (isBlockingSynchronousMethod = true )
28
- public String getRandomBase64 (int byteLength ) throws NoSuchAlgorithmException {
29
- byte [] data = new byte [byteLength ];
30
- SecureRandom random = new SecureRandom ();
31
-
32
- random .nextBytes (data );
33
-
34
- return Base64 .encodeToString (data , Base64 .NO_WRAP );
20
+ public boolean install () {
21
+ try {
22
+ System .loadLibrary ("reactnativegetrandomvalues" );
23
+
24
+ ReactApplicationContext context = getReactApplicationContext ();
25
+ nativeInstall (
26
+ context .getJavaScriptContextHolder ().get (),
27
+ context .getFilesDir ().getAbsolutePath ()
28
+ );
29
+ return true ;
30
+ } catch (Exception exception ) {
31
+ return false ;
32
+ }
35
33
}
36
34
}
0 commit comments