33import android .annotation .SuppressLint ;
44import android .app .Activity ;
55
6+ import androidx .annotation .NonNull ;
7+
68import com .facebook .react .bridge .Promise ;
79import com .facebook .react .bridge .ReactApplicationContext ;
810import com .facebook .react .bridge .ReactContextBaseJavaModule ;
1719import com .onfido .android .sdk .capture .OnfidoConfig ;
1820import com .onfido .android .sdk .capture .OnfidoFactory ;
1921import com .onfido .android .sdk .capture .OnfidoTheme ;
22+ import com .onfido .android .sdk .capture .analytics .OnfidoAnalyticsEvent ;
23+ import com .onfido .android .sdk .capture .analytics .OnfidoAnalyticsEventListener ;
2024import com .onfido .android .sdk .capture .config .BiometricTokenCallback ;
2125import com .onfido .android .sdk .capture .config .MediaCallback ;
2226import com .onfido .android .sdk .capture .errors .EnterpriseFeatureNotEnabledException ;
3842// Analytics to be re-added once payloads are harmonised across platforms
3943enum CallbackType {
4044 MEDIA ,
41- BIOMETRIC_TOKEN
45+ BIOMETRIC_TOKEN ,
46+ ANALYTICS
4247}
4348
4449public class OnfidoSdkModule extends ReactContextBaseJavaModule {
@@ -89,16 +94,14 @@ public void start(final ReadableMap config, final Promise promise) {
8994 try {
9095 sdkToken = getSdkTokenFromConfig (config );
9196 } catch (Exception e ) {
92- currentPromise .reject ("config_error" , e );
93- currentPromise = null ;
94- return ;
97+ reject ("config_error" , e );
98+ return ;
9599 }
96100
97101 Activity currentActivity = getCurrentActivityInParentClass ();
98102 if (currentActivity == null ) {
99- currentPromise .reject ("error" , new Exception ("Android activity does not exist" ));
100- currentPromise = null ;
101- return ;
103+ reject ("error" , new Exception ("Android activity does not exist" ));
104+ return ;
102105 }
103106
104107 try {
@@ -110,25 +113,26 @@ public void start(final ReadableMap config, final Promise promise) {
110113 defaultSDKConfiguration (config , currentActivity , sdkToken );
111114 }
112115 } catch (final EnterpriseFeaturesInvalidLogoCobrandingException e ) {
113- currentPromise .reject ("error" , new EnterpriseFeaturesInvalidLogoCobrandingException ());
114- currentPromise = null ;
116+ reject ("error" , new EnterpriseFeaturesInvalidLogoCobrandingException ());
115117 } catch (final EnterpriseFeatureNotEnabledException e ) {
116- currentPromise .reject ("error" , e );
117- currentPromise = null ;
118+ reject ("error" , e );
118119 } catch (final Exception e ) {
119- currentPromise .reject ("error" , new Exception (e .getMessage (), e ));
120- currentPromise = null ;
120+ reject ("error" , new Exception (e .getMessage (), e ));
121121 }
122122
123123 } catch (final Exception e ) {
124124 e .printStackTrace ();
125125 // Wrap all unexpected exceptions.
126- currentPromise .reject ("error" , new Exception ("Unexpected error starting Onfido page" , e ));
127- currentPromise = null ;
126+ reject ("error" , new Exception ("Unexpected error starting Onfido page" , e ));
128127 }
129128 }
130129
131- @ SuppressLint ("UnsafeOptInUsageError" )
130+ private void reject (String config_error , Exception e ) {
131+ currentPromise .reject (config_error , e );
132+ currentPromise = null ;
133+ }
134+
135+ @ SuppressLint ("UnsafeOptInUsageError" )
132136 private void workflowSDKConfiguration (final ReadableMap config , Activity currentActivity , String sdkToken ) throws Exception {
133137 final String workflowRunId = getWorkflowRunIdFromConfig (config );
134138
@@ -149,6 +153,10 @@ private void workflowSDKConfiguration(final ReadableMap config, Activity current
149153 onfidoConfigBuilder .withBiometricTokenCallback (addBiometricTokenCallback ());
150154 }
151155
156+ if (callbackTypeList .contains (CallbackType .ANALYTICS )) {
157+ onfidoConfigBuilder .withAnalyticsEventListener (new AnalyticsCallbackBridge (getReactApplicationContext ()));
158+ }
159+
152160 OnfidoTheme onfidoTheme = getThemeFromConfig (config );
153161 if (onfidoTheme != null ) {
154162 onfidoConfigBuilder .withTheme (onfidoTheme );
@@ -182,6 +190,10 @@ private void defaultSDKConfiguration(final ReadableMap config, Activity currentA
182190 onfidoConfigBuilder .withMediaCallback (addMediaCallback ());
183191 }
184192
193+ if (callbackTypeList .contains (CallbackType .ANALYTICS )) {
194+ onfidoConfigBuilder .withAnalyticsEventListener (new AnalyticsCallbackBridge (getReactApplicationContext ()));
195+ }
196+
185197 NFCOptions nfcOption = getNFCOptionFromConfig (config );
186198 onfidoConfigBuilder .withNFC (nfcOption );
187199
@@ -215,9 +227,8 @@ private EnterpriseFeatures.Builder getEnterpriseFeatures(final ReadableMap confi
215227 currentActivity .getApplicationContext ().getPackageName ()
216228 );
217229 if (cobrandLogoLight == 0 || cobrandLogoDark == 0 ) {
218- currentPromise .reject ("error" , new Exception ("Cobrand logos were not found" ));
219- currentPromise = null ;
220- return null ;
230+ reject ("error" , new Exception ("Cobrand logos were not found" ));
231+ return null ;
221232 }
222233 enterpriseFeaturesBuilder .withCobrandingLogo (cobrandLogoLight , cobrandLogoDark );
223234 hasSetEnterpriseFeatures = true ;
@@ -532,6 +543,11 @@ public void withBiometricTokenCallback() {
532543 callbackTypeList .add (CallbackType .BIOMETRIC_TOKEN );
533544 }
534545
546+ @ ReactMethod
547+ public void withAnalyticsCallback () {
548+ callbackTypeList .add (CallbackType .ANALYTICS );
549+ }
550+
535551 @ ReactMethod
536552 public void provideBiometricToken (String biometricToken ) {
537553 biometricTokenCallback .provideToken (biometricToken );
0 commit comments