Skip to content
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

Android Support #53

Merged
merged 14 commits into from
Dec 3, 2017
Merged

Android Support #53

merged 14 commits into from
Dec 3, 2017

Conversation

zibs
Copy link
Collaborator

@zibs zibs commented Sep 19, 2017

This PR adds support for using Fingerprint Authentication on Android.

It keeps the interface mostly the same, aside from allowing the user to pass in a config object to change the title and color of the pop-up requesting authentication.

The error handling is not as robust as iOS, but future PRs would be welcome to improve this.

Readme will be updated with an image showing it working on Android shortly.

I've tested this by creating a new project with react-native init for "react-native": "0.48.1", and it seems to be working for both iOS and Android.

thanks to @sunto for doing the bulk of the work!

Test Plan:

  • - iOS still works as expected. (no changes were made to any iOS code, so this should be fine)
  • - Android auth works when isSupported is true
  • - Calling authenticate when isSupported is false doesn't die.
  • - Calling isSupported when Android has no fingerprint reader works
  • - If auth is supported but no fingerprints are enrolled on phone, Android doesn't die.
  • - If not config object is passed into Android, it defaults to the default config.
  • - If config object is passed into Android, it uses the default config.
  • - Android auth works 🎉

Eli Zibin added 5 commits September 14, 2017 10:48
Allows for config object to specify title and color of the Fingerprint dialog.
Keeps interface mostly the exact same (except for iOS specific error messages).

Documentation/README updates to follow in next commits.
@naoufal
Copy link
Owner

naoufal commented Sep 20, 2017

👏This is awesome — Great work guys!

🌴On vacation right now, but will try and get to this within a week. Otherwise, I'll see if I can get someone what to help with the review.

@zibs
Copy link
Collaborator Author

zibs commented Sep 22, 2017

Sounds good, no rush 👍 - enjoy vacay - I'll do some additional testing this weekend and Sunny will too.

README.md Outdated

On android you will need to add
```xml
<uses-permission android:name="android.permission.USE_FINGERPRINT" />

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you do not need it. You already add this permission to the manifest library so it will get merged with your manifest (app).

return false;
}

if (ActivityCompat.checkSelfPermission(getReactApplicationContext(),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You do not need this block, see USE_FINGERPRINT. This is a normal permission so user cannot disable it.

super.onCreate(savedInstanceState);

// Do not create a new Fragment when the Activity is re-created such as orientation changes.
setRetainInstance(true);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is considered a bad practice. You should only retain a fragment for a dialog that returns no view, so onCreateView should return null. Anyway you already use a DialogFragment (they don't leak on rotation), and RN in manifest also says that do not destroy the activity so you do not need this line.

setRetainInstance(true);
setStyle(DialogFragment.STYLE_NORMAL, android.R.style.Theme_Material_Light_Dialog);

// dialogCallback = null;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Forgotten comment?


// Do not create a new Fragment when the Activity is re-created such as orientation changes.
setRetainInstance(true);
setStyle(DialogFragment.STYLE_NORMAL, android.R.style.Theme_Material_Light_Dialog);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to set style here explicitly? Can we get the default style? Maybe be able to override it with custom style?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes sense, we should probably do something like the following in the TouchID.android.js
DEFAULT_CONFIG = { title: 'Authentication Required', color: '#1306ff', style: 'STYLE_NORMAL' };

&& mFingerprintManager.hasEnrolledFingerprints()
&& (ActivityCompat.checkSelfPermission(appContext,
Manifest.permission.USE_FINGERPRINT) ==
PackageManager.PERMISSION_GRANTED);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same permission comment as before, also, this function seems a duplicated from FingerprintAuthModule.java ?


if (ActivityCompat.checkSelfPermission(appContext,
Manifest.permission.USE_FINGERPRINT) !=
PackageManager.PERMISSION_GRANTED) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not needed.

See: https://developer.android.com/training/permissions/requesting.html

Normal permissions do not directly risk the user's privacy. If your app lists a normal permission in its manifest, the system grants the permission automatically.

android:layout_width="49dp"
android:layout_height="49dp"
android:layout_marginLeft="25dp"
android:src="@drawable/ic_fp_40px"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would not generate a png for this icon but you can generate the xml with Android Studio. Then will look good anywhere.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical" android:layout_width="match_parent"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file seems it just needs to run 'Reformat' through Android Studio.


defaultConfig {
minSdkVersion 16
targetSdkVersion 22

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would bump minSdkVersion and targetSdkVersion up. FingerPrint works only on Android 23 and above, right? So it does not make really sense we say 16.

@ferrannp
Copy link

@zibs could you update the index.android.js into the examples folder? I actually try it and it works so good so far :). Just added some comments into the PR.

@naoufal maybe you want to change the lib name ! And support face id for iOS in the future ;) Just saying.

@wireforce
Copy link

Maybe rename to react-native-biometric-auth ? :)

@zibs
Copy link
Collaborator Author

zibs commented Sep 30, 2017

@ferrannp Thanks so much for the review! Will take a look at get these updates to you shortly.

@naoufal
Copy link
Owner

naoufal commented Oct 2, 2017

@zibs I dig it, picked up https://www.npmjs.com/package/react-native-biometric-auth. Will add you and @sunto to the package.

@GantMan
Copy link

GantMan commented Oct 18, 2017

Excited to see this land!

@zibs
Copy link
Collaborator Author

zibs commented Oct 18, 2017

landing shortly...thanks for the nudge @GantMan 🥇

@harrisrobin
Copy link

@zibs we're super excited to see this land! Great work guys :)

@tactico
Copy link

tactico commented Oct 30, 2017

@zibs Also looking forward to this!

@ben-snaize
Copy link

Is it in yet? Hyped for this!

@zibs
Copy link
Collaborator Author

zibs commented Nov 3, 2017

Sorry for delay all - just got one or two last things to update here and we should be good!

@tactico
Copy link

tactico commented Nov 3, 2017

I could not wait and implemented your branch and started testing. One comment would be to synchronize the error codes with the iOS version, for example in the IOS version I get an error of the form "LAErrorUserCancel" and the same error in this branch comes through as "Touch ID Error"

@zibs
Copy link
Collaborator Author

zibs commented Nov 3, 2017

@tactico Feel free to make a PR! The errors are handled fundamentally different on iOS and Android, which is why I haven't gone down that path yet. Definitely could be somewhat integrated eventually though!

@naoufal
Copy link
Owner

naoufal commented Nov 6, 2017 via email

@tactico
Copy link

tactico commented Nov 7, 2017

I probably will not be able to get to it for about a week, major release of our product scheduled for this Friday!

@tactico
Copy link

tactico commented Nov 14, 2017

Sorry noufal, got pulled into another project so likely will not be able to do this anytime soon. My apologies...

@zibs
Copy link
Collaborator Author

zibs commented Nov 21, 2017

@naoufal Hey Naoufal, sorry for dropping the ball and taking so long on this one. I've just pushed a number of commits that addressed most of the issues in the review. There is one missing about passing in a custom style theme thing, but I think that can wait until later!

I just went through and tested on a brand new react native project created with react-native init - I wasn't able to run the example cause the yarn.lock is pointing to netflix artifacts 🎥 . But I added the example code I used in my test run and it should be all good!

Let me know if you have any suggestions!

@naoufal
Copy link
Owner

naoufal commented Nov 21, 2017

No worries at all! This is great work that a bunch of people will benefit from, I'd say you're doing the total opposite of dropping the ball! 🍻

Sorry about the netflix artifacts -- I'll fix that!

I'll take a look tonight/tomorrow evening and try and get us setup for a merge this weekend.

@naoufal
Copy link
Owner

naoufal commented Dec 3, 2017

@zibs updated the yarn.lock. Also merged the FaceID PR so you'll need to update the README. Once that's done hit the merge button!

And I'll bake this into the next release 🎉

@zibs zibs merged commit 6e47184 into naoufal:master Dec 3, 2017
},

authenticate(reason, config) {
DEFAULT_CONFIG = { title: 'Authentication Required', color: '#1306ff' };
Copy link

@fretman92 fretman92 Jun 11, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do you not declare the DEFAULT_CONFIG variable here?
It causes error in strict mode.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants