Skip to content

Fingerprint

Fingerprint usage

The fingerprint usage contains 3 screens: Enable screen, Authentication screen, Authentication error screen. You only have to use FingerprintActivity and the library detects that if there any added fingerprints or not and launches the right screen.

Fingerprint Activity

The FingerprintActivity can be started with standard startActivityResult method of the Activity and you can configure it via the Fingerprintsettings class.

The layout of the Fingerprint Authentication

It contains the following elements:

  • a headline label
  • the detailed Fingerprint text
  • a Fingerprint image
  • Error message label
  • Fallback button

All the mentioned labels can be customized via the Settings configuration, that is you can overwrite them via the corresponding set methods of the FingerprintSettings class, the error message label is hidden by default. The FingerprintSettings class can be instantiated with default constructor. The set methods should be called before calling the saveToIntent method, which saves the configuration into an Intent. Finally, this intent should be used when starting the FingerprintActivity via the startActivityForResult method.

Furthermore, the screen is extended to support fallback to passcode. In this case, the layout contains a fallback button (labelled as Fallback button), allowing the user to fallback to use passcode. This is a disabled button by default and will be enabled only if the fingerprint passcode screen is configured explicitly to enable it.

The layout of the Enable Fingerprint screen

It contains the following elements:

  • a headline label
  • the detailed Fingerprint text
  • Error message label
  • Enable fingerprint button

The EnableFingerprintActivity automatically launched if the user use Fingerprint authentication but there is no added fingerprint on the device or the device is not secure, where the user can meet the requirments.

All the mentioned labels can be customized via the Settings configuration, that is you can overwrite them via the corresponding set methods of the EnableFingerprintsettings class, the error message label is hidden by default. The EnableFingerprintsettings class can be instantiated with default constructor. The set methods should be called before calling the saveToIntent method, which saves the configuration into an Intent. Finally this intent should be used when starting the FingerprintActivity via the startActivityForResult method.

When the user push the enable fingerprint button the default android settings screen appears where a fingerprint can be added.

The error message is hidden by default, the library makes it visible when the user navigate back from the settings screen and the user does not added a fingerprint or the device is not secured.

The layout of the Authentication error screen

It contains the following elements:

  • a headline label
  • the detailed Fingerprint text
  • Reset button

Due to the android security system the fingerprint sensor is blocked after 5 unsuccesful attempts, the FingerprintErrorActivity automatically appears in this case, where the user gets some feedback and could reset the passcode.

All the mentioned labels can be customized via the Settings configuration, that is you can overwrite them via the corresponding set methods of the EnableFingerprintsettings class, the error message label is hidden by default. The EnableFingerprintsettings class can be instantiated with default constructor. The set methods should be called before calling the saveToIntent method, which saves the configuration into an Intent. Finally, this intent should be used when starting the FingerprintActivity via the startActivityForResult method.

Customizing the Fingerprint Authentication Screen

You can use the FingerprintSettings object for customize the labels of the fingerprint authentication screen. The following options are available:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
public String getHeadlineLabel() {
    return headlineLabel;
}

public void setHeadlineLabel(String headlineLabel) {
    this.headlineLabel = headlineLabel;
}

public String getDetailLabel() {
    return detailLabel;
}

public void setDetailLabel(String detailLabel) {
    this.detailLabel = detailLabel;
}

public String getFallbackButtonTitle() {
    return fallbackButtonTitle;
}

public void setFallbackButtonTitle(String fallbackButtonTitle) {
    this.fallbackButtonTitle = fallbackButtonTitle;
}

public boolean isFallbackButtonEnabled() {
    return fallbackButtonEnabled;
}

public void setFallbackButtonEnabled(boolean fallbackButtonEnabled) {
    this.fallbackButtonEnabled = fallbackButtonEnabled;
}

Customizing the Enable Fingerprint Screen

You can use the EnableFingerprintSettings object for customize the labels of the fingerprint authentication screen. The following options are available:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
 public String getEnableHeadlineLabel() {
     return enableHeadlineLabel;
 }

 public void setEnableHeadlineLabel(String headlineLabel) {
     this.enableHeadlineLabel = headlineLabel;
 }

 public String getEnableDetailLabel() {
     return enableDetailLabel;
 }

 public void setEnableDetailLabel(String detailLabel) {
     this.enableDetailLabel = detailLabel;
 }

 public String getEnableMoreDetailLabel() {
     return enableMoreDetailLabel;
 }

 public void setEnableMoreDetailLabel(String moreDetailLabel) {
     this.enableMoreDetailLabel = moreDetailLabel;
 }

 public String getEnableButtonTitle() {
     return enableButtonTitle;
 }

 public void setEnableButtonTitle(String enableButtonTitle) {
     this.enableButtonTitle = enableButtonTitle;
 }

Customizing the Authentication Error Screen

You can use the FingerprintErrorSettings object for customize the labels of the fingerprint authentication screen. The following options are available:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
 public String getFingerprintErrorHeadlineLabel() {
     return fingerprintErrorHeadlineLabel;
 }

 public void setFingerprintErrorHeadlineLabel(String headlineLabel) {
     this.fingerprintErrorHeadlineLabel = headlineLabel;
 }

 public String getFingerprintErrorDetailLabel() {
     return fingerprintErrorDetailLabel;
 }

 public void setFingerprintErrorDetailLabel(String detailLabel) {
     this.fingerprintErrorDetailLabel = detailLabel;
 }

 public String getFingerprintErrorResetButtonTitle() {
     return fingerprintErrorResetButtonTitle;
 }

 public void setFingerprintErrorResetButtonTitle(String fingerprintErrorResetButtonTitle) {
     this.fingerprintErrorResetButtonTitle = fingerprintErrorResetButtonTitle;
 }

 public boolean isFingerprintErrorResetEnabled() {
     return fingerprintErrorResetEnabled;
 }

 public void setFingerprintErrorResetEnabled(boolean fingerprintErrorResetEnabled) {
     this.fingerprintErrorResetEnabled = fingerprintErrorResetEnabled;
 }

Implementation of the callback methods

The implementation of these methods will be executed on a dedicated background thread of the caller activity, more precisely the background thread of the headless fragment of the caller activity. This fragment is handed over to the method as parameter. You can access the caller activity via the getActivity() method of this fragment. Please note that the result of the getActivity call might be null value if there is no active activity in the background, for example due to an ongoing change orientation process.

The callback method waits for response synchronously, so if you need asynchronous communication, then you must wait on this thread until the async response arrives. You are allowed block the thread because you are on a dedicated background thread.

As a consequence, you have to be prepared to handle the interrupted flag of the thread. For example: if the user taps on the back button, or if the system destroys the caller fragment, then this thread will be interrupted. If the execution of your callback method was successfully interrupted, that is the normal processing was not completed, then you should throw InterruptedException from your implementation to indicate that the processing was cancelled.

The fingerprint authentication receives the cipher through the getCipher callback. The application developer must create the cipher, this cipher is used by the device sensor for authenticating. The authenticated cipher passed back to the application with the startDone callback.

The fallback callback as the name suggests it provide that the user could use passcode if the fingerprint authentication did not succeed.

With the reset callback the user can reset the passcode.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
 public class FingerprintActionHandlerImpl implements FingerprintActionHandler {
     KeyHandler keyHandler;
     @Override
     public Cipher getCipher(Fragment fragment) throws InterruptedException, FingerprintException {
         try {
             ((DemoApplication) fragment.getActivity().getApplication()).delay();
             keyHandler = new KeyHandler();
             keyHandler.getInstanceOfCipher();
             keyHandler.initKeyGenerator();
             keyHandler.loadKeyStore();
             if (KeyHandler.passcodeInputMode == PasscodeInputMode.CREATE) {
                 keyHandler.generateKey();
                 keyHandler.initCipherInEncryptMode();
                 keyHandler.saveIVToPref();
             } else {
                 keyHandler.loadIVFromPref();
                 keyHandler.setSecretKey();
                 keyHandler.initCipherInDecryptMode();
             }

             return keyHandler.cipher;

Add Fingerprint authentication screen activity to your manifest file

The FingerprintActivity should be added to the AndroidManifest.xml file in an activity xml tag. It is required to specify also the "action_handler" meta-data tag.

1
2
3
4
5
6
7
8
    <activity
        android:name="com.sap.cloud.mobile.onboarding.fingerprint.FingerprinActivity"
        android:label="@string/app_name"
        android:theme="@style/Theme.AppCompat.Light.NoActionBar"
      <meta-data
          android:name="action_handler"
          android:value="com.sap.cloud.mobile.fiori.demo.onboarding.FingerprintActionHandlerImpl"/>
    </activity>