PromptInfo.java 4.56 KB
Newer Older
Chok's avatar
Chok committed
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
package de.niklasmerz.cordova.biometric;

import android.os.Bundle;

import org.json.JSONArray;

class PromptInfo {

    private static final String DISABLE_BACKUP = "disableBackup";
    private static final String TITLE = "title";
    private static final String SUBTITLE = "subtitle";
    private static final String DESCRIPTION = "description";
    private static final String FALLBACK_BUTTON_TITLE = "fallbackButtonTitle";
    private static final String CANCEL_BUTTON_TITLE = "cancelButtonTitle";
    private static final String CONFIRMATION_REQUIRED = "confirmationRequired";
    private static final String INVALIDATE_ON_ENROLLMENT = "invalidateOnEnrollment";
    private static final String SECRET = "secret";
    private static final String BIOMETRIC_ACTIVITY_TYPE = "biometricActivityType";

    static final String SECRET_EXTRA = "secret";

    private Bundle bundle = new Bundle();

    Bundle getBundle() {
        return bundle;
    }

    String getTitle() {
        return bundle.getString(TITLE);
    }

    String getSubtitle() {
        return bundle.getString(SUBTITLE);
    }

    String getDescription() {
        return bundle.getString(DESCRIPTION);
    }

    boolean isDeviceCredentialAllowed() {
        return !bundle.getBoolean(DISABLE_BACKUP);
    }

    String getFallbackButtonTitle() {
        return bundle.getString(FALLBACK_BUTTON_TITLE);
    }

    String getCancelButtonTitle() {
        return bundle.getString(CANCEL_BUTTON_TITLE);
    }

    boolean getConfirmationRequired() {
        return bundle.getBoolean(CONFIRMATION_REQUIRED);
    }

    String getSecret() {
        return bundle.getString(SECRET);
    }

    boolean invalidateOnEnrollment() {
        return bundle.getBoolean(INVALIDATE_ON_ENROLLMENT);
    }

    BiometricActivityType getType() {
        return BiometricActivityType.fromValue(bundle.getInt(BIOMETRIC_ACTIVITY_TYPE));
    }

    public static final class Builder {
        private static final String TAG = "PromptInfo.Builder";
        private Bundle bundle;
        private boolean disableBackup = false;
        private String title;
        private String subtitle = null;
        private String description = null;
        private String fallbackButtonTitle = "Use backup";
        private String cancelButtonTitle = "Cancel";
        private boolean confirmationRequired = true;
        private boolean invalidateOnEnrollment = false;
        private String secret = null;
        private BiometricActivityType type = null;

        Builder(String applicationLabel) {
            if (applicationLabel == null) {
                title = "Biometric Sign On";
            } else {
                title = applicationLabel + " Biometric Sign On";
            }
        }

        Builder(Bundle bundle) {
            this.bundle = bundle;
        }

        public PromptInfo build() {
            PromptInfo promptInfo = new PromptInfo();

            if (this.bundle != null) {
                promptInfo.bundle = bundle;
                return promptInfo;
            }

            Bundle bundle = new Bundle();
            bundle.putString(SUBTITLE, this.subtitle);
            bundle.putString(TITLE, this.title);
            bundle.putString(DESCRIPTION, this.description);
            bundle.putString(FALLBACK_BUTTON_TITLE, this.fallbackButtonTitle);
            bundle.putString(CANCEL_BUTTON_TITLE, this.cancelButtonTitle);
            bundle.putString(SECRET, this.secret);
            bundle.putBoolean(DISABLE_BACKUP, this.disableBackup);
            bundle.putBoolean(CONFIRMATION_REQUIRED, this.confirmationRequired);
            bundle.putBoolean(INVALIDATE_ON_ENROLLMENT, this.invalidateOnEnrollment);
            bundle.putInt(BIOMETRIC_ACTIVITY_TYPE, this.type.getValue());
            promptInfo.bundle = bundle;

            return promptInfo;
        }

        void parseArgs(JSONArray jsonArgs, BiometricActivityType type) {
            this.type = type;

            Args args = new Args(jsonArgs);
            disableBackup = args.getBoolean(DISABLE_BACKUP, disableBackup);
            title = args.getString(TITLE, title);
            subtitle = args.getString(SUBTITLE, subtitle);
            description = args.getString(DESCRIPTION, description);
            fallbackButtonTitle = args.getString(FALLBACK_BUTTON_TITLE, "Use Backup");
            cancelButtonTitle = args.getString(CANCEL_BUTTON_TITLE, "Cancel");
            confirmationRequired = args.getBoolean(CONFIRMATION_REQUIRED, confirmationRequired);
            invalidateOnEnrollment = args.getBoolean(INVALIDATE_ON_ENROLLMENT, false);
            secret = args.getString(SECRET, null);
        }
    }
}