-
-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tech5 Integration - Enrollment updates #2701
Changes from 8 commits
df52ded
35902ce
e437a58
07aae64
770a917
8562c78
752c3cb
4a79c49
8072f09
b01cf21
7cbaa5d
c19496b
73d6a98
9d5df75
9371986
1786eb2
756586f
2128bd8
e81b21b
118435a
1d1d439
7fcc0a3
891b338
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package org.commcare.commcaresupportlibrary; | ||
|
||
import android.util.Base64; | ||
|
||
import com.google.gson.Gson; | ||
import com.google.gson.JsonSyntaxException; | ||
import com.google.gson.reflect.TypeToken; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class BiometricUtils { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. code formatting is off in the class. |
||
|
||
public enum BiometricIdentifier { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. potentially worth to put into a separate file of it's own. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
RIGHT_THUMB, RIGHT_INDEX_FINGER, RIGHT_MIDDLE_FINGER, RIGHT_RING_FINGER, RIGHT_PINKY_FINGER, | ||
LEFT_THUMB, LEFT_INDEX_FINGER, LEFT_MIDDLE_FINGER, LEFT_RING_FINGER, LEFT_PINKY_FINGER, | ||
FACE, UNKNOWN, INVALID | ||
} | ||
|
||
/** | ||
* This method converts the biometrics templates into a Base64 encoded String to send back to | ||
* CommCare, as part of the response of the callout | ||
* @param templates Map containing biometric templates | ||
* @return Base64 encoded string | ||
*/ | ||
public static String convertMapTemplatesToBase64String(Map<BiometricUtils.BiometricIdentifier, | ||
byte[]> templates){ | ||
// In order to reduce the size of the templates, we are converting each byte array into a | ||
// Base64 encoded String | ||
Map<Integer, String> templatesBase64Encoded = new HashMap<>(templates.size()); | ||
for (Map.Entry<BiometricUtils.BiometricIdentifier, byte[]> template : templates.entrySet()) { | ||
templatesBase64Encoded.put(template.getKey().ordinal(), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. any reason we are double encoding templates, here and then later again at the end of this method ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is because There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am struggling to understand how will this gets used in the form. With current design, Seems like we are going to store into form the whole There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @shubham1g5 the principle here is to use CC just to store the biometric templates and in the most simple way, so in a case property. any biometric operations will be preceded by the retrieval and restoration of the templates to their original format. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I meant why not store individiual templates in separate fields in form like here ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's more to avoid having to handle different form questions and case properties, when there is no apparent advantage to doing that. From my understanding, we are not doing anything with the biometric templates in CC. But I think that for the sake of standartization we could adopt the same pattern, but I wonder if you see any other gains from this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we store it together and an app is capturing multiple templates, how will they separate this data out in future without writing a script ? I think storing them seprately makes any future data management on those templates much simpler for project teams. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. bee8e72b93a3b35d429a6ebc260b5df36b1bfa35 |
||
Base64.encodeToString(template.getValue(), Base64.DEFAULT)); | ||
} | ||
String templatesInJson = new Gson().toJson(templatesBase64Encoded); | ||
return Base64.encodeToString(templatesInJson.getBytes(), Base64.DEFAULT); | ||
} | ||
|
||
/** | ||
* This method converts the Base64 encoded biometric templates to its original form | ||
* @param base64EncodedTemplates String containing Base64 encoded biometric templates | ||
* @return Map containing biometric templates | ||
*/ | ||
public static Map<BiometricUtils.BiometricIdentifier, byte[]> convertBase64StringTemplatesToMap(String base64EncodedTemplates){ | ||
if (base64EncodedTemplates == null || base64EncodedTemplates.isEmpty()) { | ||
return null; | ||
} | ||
|
||
Map<Integer, String> templatesBase64Encoded = null; | ||
try { | ||
String templatesInJson = new String(Base64.decode(base64EncodedTemplates.getBytes(), | ||
Base64.DEFAULT)); | ||
templatesBase64Encoded = new Gson().fromJson(templatesInJson, | ||
(new TypeToken<HashMap<Integer, String>>() {}.getType())); | ||
} | ||
catch(IllegalArgumentException | UnsupportedOperationException | JsonSyntaxException e){ | ||
return null; | ||
} | ||
|
||
Map<BiometricUtils.BiometricIdentifier, byte[]> templates | ||
= new HashMap<>(templatesBase64Encoded.size()); | ||
for (Map.Entry<Integer, String> template : templatesBase64Encoded.entrySet()) { | ||
templates.put(BiometricIdentifier.values()[template.getKey()], | ||
Base64.decode(template.getValue(), Base64.DEFAULT)); | ||
} | ||
return templates; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we still need this ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good catch, it's not needed.