22
22
public class LocalAuthPlugin implements MethodCallHandler {
23
23
private final Registrar registrar ;
24
24
private final AtomicBoolean authInProgress = new AtomicBoolean (false );
25
+ private AuthenticationHelper authenticationHelper ;
25
26
26
27
/** Plugin registration. */
27
28
public static void registerWith (Registrar registrar ) {
@@ -37,7 +38,7 @@ private LocalAuthPlugin(Registrar registrar) {
37
38
@ Override
38
39
public void onMethodCall (MethodCall call , final Result result ) {
39
40
if (call .method .equals ("authenticateWithBiometrics" )) {
40
- if (! authInProgress .compareAndSet ( false , true )) {
41
+ if (authInProgress .get ( )) {
41
42
// Apps should not invoke another authentication request while one is in progress,
42
43
// so we classify this as an error condition. If we ever find a legitimate use case for
43
44
// this, we can try to cancel the ongoing auth and start a new one but for now, not worth
@@ -59,7 +60,8 @@ public void onMethodCall(MethodCall call, final Result result) {
59
60
null );
60
61
return ;
61
62
}
62
- AuthenticationHelper authenticationHelper =
63
+ authInProgress .set (true );
64
+ authenticationHelper =
63
65
new AuthenticationHelper (
64
66
(FragmentActivity ) activity ,
65
67
call ,
@@ -112,8 +114,27 @@ public void onError(String code, String error) {
112
114
} catch (Exception e ) {
113
115
result .error ("no_biometrics_available" , e .getMessage (), null );
114
116
}
117
+ } else if (call .method .equals (("stopAuthentication" ))) {
118
+ stopAuthentication (result );
115
119
} else {
116
120
result .notImplemented ();
117
121
}
118
122
}
123
+
124
+ /*
125
+ Stops the authentication if in progress.
126
+ */
127
+ private void stopAuthentication (Result result ) {
128
+ try {
129
+ if (authenticationHelper != null && authInProgress .get ()) {
130
+ authenticationHelper .stopAuthentication ();
131
+ authenticationHelper = null ;
132
+ result .success (true );
133
+ return ;
134
+ }
135
+ result .success (false );
136
+ } catch (Exception e ) {
137
+ result .success (false );
138
+ }
139
+ }
119
140
}
0 commit comments