Skip to content

Commit

Permalink
Merge pull request #48 from m1ga/master
Browse files Browse the repository at this point in the history
feat(android): Use reason (+ subtitle and text) and cancelTitle
  • Loading branch information
hansemannn authored Apr 11, 2022
2 parents 58f7667 + c364aab commit a925024
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 10 deletions.
6 changes: 4 additions & 2 deletions android/src/ti/identity/FingerPrintHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,10 @@ public void startListening(KrollFunction callback, KrollObject obj)
mSelfCancelled = false;

final BiometricPrompt.PromptInfo.Builder promptInfo = new BiometricPrompt.PromptInfo.Builder();
promptInfo.setTitle("Scan Fingerprint");
promptInfo.setNegativeButtonText("Cancel");
promptInfo.setTitle(TitaniumIdentityModule.reason);
promptInfo.setDescription(TitaniumIdentityModule.reasonText);
promptInfo.setSubtitle(TitaniumIdentityModule.reasonSubtitle);
promptInfo.setNegativeButtonText(TitaniumIdentityModule.negativeButtonText);

final Executor executor = Executors.newSingleThreadExecutor();
final BiometricPrompt prompt =
Expand Down
6 changes: 4 additions & 2 deletions android/src/ti/identity/KeychainItemProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,10 @@ public void onAuthenticationFailed()
};

final BiometricPrompt.PromptInfo.Builder promptInfo = new BiometricPrompt.PromptInfo.Builder();
promptInfo.setTitle("Scan Fingerprint");
promptInfo.setNegativeButtonText("Cancel");
promptInfo.setTitle(TitaniumIdentityModule.reason);
promptInfo.setSubtitle(TitaniumIdentityModule.reasonSubtitle);
promptInfo.setDescription(TitaniumIdentityModule.reasonText);
promptInfo.setNegativeButtonText(TitaniumIdentityModule.negativeButtonText);
biometricPromptInfo = promptInfo.build();
}

Expand Down
21 changes: 21 additions & 0 deletions android/src/ti/identity/TitaniumIdentityModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ public class TitaniumIdentityModule extends KrollModule
public static final int PERMISSION_CODE_FINGERPRINT = 99;

public static final String PROPERTY_AUTHENTICATION_POLICY = "authenticationPolicy";
public static final String PROPERTY_REASON = "reason";
public static final String PROPERTY_REASON_SUBTITLE = "reasonSubtitle";
public static final String PROPERTY_REASON_TEXT = "reasonText";
public static final String PROPERTY_CANCEL_TITLE = "cancelTitle";

@Kroll.constant
public static final int SUCCESS = 0;
Expand Down Expand Up @@ -87,6 +91,10 @@ public class TitaniumIdentityModule extends KrollModule
private Throwable fingerprintHelperException;

private static int authenticationPolicy = AUTHENTICATION_POLICY_BIOMETRICS;
public static String reason = "Biometric authentication";
public static String reasonSubtitle = "";
public static String reasonText = "";
public static String negativeButtonText = "Cancel";

public TitaniumIdentityModule()
{
Expand Down Expand Up @@ -138,6 +146,19 @@ public void authenticate(HashMap params)
if (params == null || mfingerprintHelper == null) {
return;
}
if (params.containsKey(PROPERTY_REASON)) {
reason = TiConvert.toString(params.get(PROPERTY_REASON), reason);
}
if (params.containsKey(PROPERTY_REASON_TEXT)) {
reasonText = TiConvert.toString(params.get(PROPERTY_REASON_TEXT), "");
}
if (params.containsKey(PROPERTY_REASON_SUBTITLE)) {
reasonSubtitle = TiConvert.toString(params.get(PROPERTY_REASON_SUBTITLE), "");
}
if (params.containsKey(PROPERTY_CANCEL_TITLE)) {
negativeButtonText = TiConvert.toString(params.get(PROPERTY_CANCEL_TITLE), negativeButtonText);
}

if (params.containsKey("callback")) {
Object callback = params.get("callback");
if (callback instanceof KrollFunction) {
Expand Down
23 changes: 17 additions & 6 deletions apidoc/Identity.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ description: |
authPhrase = 'Touch ID';
}
```
## Face ID Requirements (iOS only)
For Face ID to work properly, you need to add a **`<key>`** item to the
Expand Down Expand Up @@ -550,11 +549,23 @@ properties:
- name: reason
optional: false
summary: |
Note: This property is iOS only!
Message displayed in the authentication dialog describing why the
application is requesting authentication.
application is requesting authentication. Android: The title of the dialog.
type: String

- name: reasonSubtitle
optional: true
summary: |
Subtitle of the authentication dialog (2nd line).
type: String
platforms: [android]

- name: reasonText
optional: true
summary: |
Text of the authentication dialog (3rd line).
type: String
platforms: [android]

- name: allowableReuseDuration
summary: |
Expand Down Expand Up @@ -591,12 +602,12 @@ properties:

- name: cancelTitle
summary: |
Note: This property is iOS only!
Allows cancel button title customization. A default localized title "Cancel"
is used when this property is not defined or is set to empty string.
Android: The default value will be "Cancel".
type: String
since: "6.1.0"
platforms: [android, iphone, ipad]
osver: {ios: {min: "10.0"}}

- name: keepAlive
Expand Down

0 comments on commit a925024

Please sign in to comment.