From a6447461967a2643fa9fb352e12a51f32cb73667 Mon Sep 17 00:00:00 2001 From: chiragmaniar Date: Fri, 6 Oct 2017 20:03:06 +0530 Subject: [PATCH] initial commit --- FingerprintAuthentication/.gitignore | 9 + FingerprintAuthentication/.idea/compiler.xml | 22 +++ .../.idea/copyright/profiles_settings.xml | 3 + FingerprintAuthentication/.idea/gradle.xml | 18 ++ FingerprintAuthentication/.idea/misc.xml | 46 +++++ FingerprintAuthentication/.idea/modules.xml | 9 + FingerprintAuthentication/app/.gitignore | 1 + FingerprintAuthentication/app/build.gradle | 30 +++ .../app/proguard-rules.pro | 25 +++ .../ExampleInstrumentedTest.java | 26 +++ .../app/src/main/AndroidManifest.xml | 22 +++ .../FingerprintHandler.java | 53 ++++++ .../MainActivity.java | 174 ++++++++++++++++++ .../app/src/main/res/layout/activity_main.xml | 34 ++++ .../src/main/res/mipmap-hdpi/ic_launcher.png | Bin 0 -> 3418 bytes .../res/mipmap-hdpi/ic_launcher_round.png | Bin 0 -> 4208 bytes .../src/main/res/mipmap-mdpi/ic_launcher.png | Bin 0 -> 2206 bytes .../res/mipmap-mdpi/ic_launcher_round.png | Bin 0 -> 2555 bytes .../src/main/res/mipmap-xhdpi/ic_launcher.png | Bin 0 -> 4842 bytes .../res/mipmap-xhdpi/ic_launcher_round.png | Bin 0 -> 6114 bytes .../main/res/mipmap-xxhdpi/ic_launcher.png | Bin 0 -> 7718 bytes .../res/mipmap-xxhdpi/ic_launcher_round.png | Bin 0 -> 10056 bytes .../main/res/mipmap-xxxhdpi/ic_launcher.png | Bin 0 -> 10486 bytes .../res/mipmap-xxxhdpi/ic_launcher_round.png | Bin 0 -> 14696 bytes .../app/src/main/res/values/colors.xml | 6 + .../app/src/main/res/values/dimens.xml | 5 + .../app/src/main/res/values/ids.xml | 5 + .../app/src/main/res/values/strings.xml | 4 + .../app/src/main/res/values/styles.xml | 11 ++ .../ExampleUnitTest.java | 17 ++ FingerprintAuthentication/build.gradle | 23 +++ FingerprintAuthentication/gradle.properties | 17 ++ .../gradle/wrapper/gradle-wrapper.jar | Bin 0 -> 53636 bytes .../gradle/wrapper/gradle-wrapper.properties | 6 + FingerprintAuthentication/gradlew | 160 ++++++++++++++++ FingerprintAuthentication/gradlew.bat | 90 +++++++++ FingerprintAuthentication/settings.gradle | 1 + GeoFence/.gitignore | 9 + GeoFence/.idea/compiler.xml | 22 +++ .../.idea/copyright/profiles_settings.xml | 3 + GeoFence/.idea/gradle.xml | 18 ++ GeoFence/.idea/misc.xml | 46 +++++ GeoFence/.idea/modules.xml | 9 + GeoFence/.idea/runConfigurations.xml | 12 ++ GeoFence/app/.gitignore | 1 + GeoFence/app/build.gradle | 32 ++++ GeoFence/app/proguard-rules.pro | 25 +++ .../geofence/ExampleInstrumentedTest.java | 26 +++ GeoFence/app/src/main/AndroidManifest.xml | 26 +++ .../com/example/dhruv/geofence/Constants.java | 27 +++ .../GeofenceTransitionsIntentService.java | 77 ++++++++ .../example/dhruv/geofence/MainActivity.java | 144 +++++++++++++++ .../app/src/main/res/layout/activity_main.xml | 17 ++ .../src/main/res/mipmap-hdpi/ic_launcher.png | Bin 0 -> 3418 bytes .../res/mipmap-hdpi/ic_launcher_round.png | Bin 0 -> 4208 bytes .../src/main/res/mipmap-mdpi/ic_launcher.png | Bin 0 -> 2206 bytes .../res/mipmap-mdpi/ic_launcher_round.png | Bin 0 -> 2555 bytes .../src/main/res/mipmap-xhdpi/ic_launcher.png | Bin 0 -> 4842 bytes .../res/mipmap-xhdpi/ic_launcher_round.png | Bin 0 -> 6114 bytes .../main/res/mipmap-xxhdpi/ic_launcher.png | Bin 0 -> 7718 bytes .../res/mipmap-xxhdpi/ic_launcher_round.png | Bin 0 -> 10056 bytes .../main/res/mipmap-xxxhdpi/ic_launcher.png | Bin 0 -> 10486 bytes .../res/mipmap-xxxhdpi/ic_launcher_round.png | Bin 0 -> 14696 bytes GeoFence/app/src/main/res/values/colors.xml | 6 + GeoFence/app/src/main/res/values/strings.xml | 3 + GeoFence/app/src/main/res/values/styles.xml | 11 ++ .../dhruv/geofence/ExampleUnitTest.java | 17 ++ GeoFence/build.gradle | 23 +++ GeoFence/gradle.properties | 17 ++ GeoFence/gradle/wrapper/gradle-wrapper.jar | Bin 0 -> 53636 bytes .../gradle/wrapper/gradle-wrapper.properties | 6 + GeoFence/gradlew | 160 ++++++++++++++++ GeoFence/gradlew.bat | 90 +++++++++ GeoFence/settings.gradle | 1 + test1.tar.gz | Bin 0 -> 20985878 bytes test1/.gitignore | 9 + test1/.idea/compiler.xml | 22 +++ test1/.idea/copyright/profiles_settings.xml | 3 + test1/.idea/gradle.xml | 18 ++ test1/.idea/misc.xml | 62 +++++++ test1/.idea/modules.xml | 9 + test1/.idea/runConfigurations.xml | 12 ++ test1/app/.gitignore | 1 + test1/app/build.gradle | 30 +++ test1/app/proguard-rules.pro | 25 +++ .../test1/ExampleInstrumentedTest.java | 26 +++ test1/app/src/main/AndroidManifest.xml | 27 +++ .../lokhandmanav/test1/MainActivity.java | 103 +++++++++++ .../app/src/main/res/layout/activity_main.xml | 46 +++++ .../src/main/res/mipmap-hdpi/ic_launcher.png | Bin 0 -> 3418 bytes .../res/mipmap-hdpi/ic_launcher_round.png | Bin 0 -> 4208 bytes .../src/main/res/mipmap-mdpi/ic_launcher.png | Bin 0 -> 2206 bytes .../res/mipmap-mdpi/ic_launcher_round.png | Bin 0 -> 2555 bytes .../src/main/res/mipmap-xhdpi/ic_launcher.png | Bin 0 -> 4842 bytes .../res/mipmap-xhdpi/ic_launcher_round.png | Bin 0 -> 6114 bytes .../main/res/mipmap-xxhdpi/ic_launcher.png | Bin 0 -> 7718 bytes .../res/mipmap-xxhdpi/ic_launcher_round.png | Bin 0 -> 10056 bytes .../main/res/mipmap-xxxhdpi/ic_launcher.png | Bin 0 -> 10486 bytes .../res/mipmap-xxxhdpi/ic_launcher_round.png | Bin 0 -> 14696 bytes test1/app/src/main/res/values/colors.xml | 6 + test1/app/src/main/res/values/strings.xml | 9 + test1/app/src/main/res/values/styles.xml | 11 ++ .../lokhandmanav/test1/ExampleUnitTest.java | 17 ++ test1/build.gradle | 23 +++ test1/gradle.properties | 17 ++ test1/gradle/wrapper/gradle-wrapper.jar | Bin 0 -> 53636 bytes .../gradle/wrapper/gradle-wrapper.properties | 6 + test1/gradlew | 160 ++++++++++++++++ test1/gradlew.bat | 90 +++++++++ test1/settings.gradle | 1 + 110 files changed, 2378 insertions(+) create mode 100644 FingerprintAuthentication/.gitignore create mode 100644 FingerprintAuthentication/.idea/compiler.xml create mode 100644 FingerprintAuthentication/.idea/copyright/profiles_settings.xml create mode 100644 FingerprintAuthentication/.idea/gradle.xml create mode 100644 FingerprintAuthentication/.idea/misc.xml create mode 100644 FingerprintAuthentication/.idea/modules.xml create mode 100644 FingerprintAuthentication/app/.gitignore create mode 100644 FingerprintAuthentication/app/build.gradle create mode 100644 FingerprintAuthentication/app/proguard-rules.pro create mode 100644 FingerprintAuthentication/app/src/androidTest/java/com/example/dhruv/fingerprintauthentication/ExampleInstrumentedTest.java create mode 100644 FingerprintAuthentication/app/src/main/AndroidManifest.xml create mode 100644 FingerprintAuthentication/app/src/main/java/com/example/dhruv/fingerprintauthentication/FingerprintHandler.java create mode 100644 FingerprintAuthentication/app/src/main/java/com/example/dhruv/fingerprintauthentication/MainActivity.java create mode 100644 FingerprintAuthentication/app/src/main/res/layout/activity_main.xml create mode 100644 FingerprintAuthentication/app/src/main/res/mipmap-hdpi/ic_launcher.png create mode 100644 FingerprintAuthentication/app/src/main/res/mipmap-hdpi/ic_launcher_round.png create mode 100644 FingerprintAuthentication/app/src/main/res/mipmap-mdpi/ic_launcher.png create mode 100644 FingerprintAuthentication/app/src/main/res/mipmap-mdpi/ic_launcher_round.png create mode 100644 FingerprintAuthentication/app/src/main/res/mipmap-xhdpi/ic_launcher.png create mode 100644 FingerprintAuthentication/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png create mode 100644 FingerprintAuthentication/app/src/main/res/mipmap-xxhdpi/ic_launcher.png create mode 100644 FingerprintAuthentication/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png create mode 100644 FingerprintAuthentication/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png create mode 100644 FingerprintAuthentication/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png create mode 100644 FingerprintAuthentication/app/src/main/res/values/colors.xml create mode 100644 FingerprintAuthentication/app/src/main/res/values/dimens.xml create mode 100644 FingerprintAuthentication/app/src/main/res/values/ids.xml create mode 100644 FingerprintAuthentication/app/src/main/res/values/strings.xml create mode 100644 FingerprintAuthentication/app/src/main/res/values/styles.xml create mode 100644 FingerprintAuthentication/app/src/test/java/com/example/dhruv/fingerprintauthentication/ExampleUnitTest.java create mode 100644 FingerprintAuthentication/build.gradle create mode 100644 FingerprintAuthentication/gradle.properties create mode 100644 FingerprintAuthentication/gradle/wrapper/gradle-wrapper.jar create mode 100644 FingerprintAuthentication/gradle/wrapper/gradle-wrapper.properties create mode 100644 FingerprintAuthentication/gradlew create mode 100755 FingerprintAuthentication/gradlew.bat create mode 100644 FingerprintAuthentication/settings.gradle create mode 100644 GeoFence/.gitignore create mode 100644 GeoFence/.idea/compiler.xml create mode 100644 GeoFence/.idea/copyright/profiles_settings.xml create mode 100644 GeoFence/.idea/gradle.xml create mode 100644 GeoFence/.idea/misc.xml create mode 100644 GeoFence/.idea/modules.xml create mode 100644 GeoFence/.idea/runConfigurations.xml create mode 100644 GeoFence/app/.gitignore create mode 100644 GeoFence/app/build.gradle create mode 100644 GeoFence/app/proguard-rules.pro create mode 100644 GeoFence/app/src/androidTest/java/com/example/dhruv/geofence/ExampleInstrumentedTest.java create mode 100644 GeoFence/app/src/main/AndroidManifest.xml create mode 100644 GeoFence/app/src/main/java/com/example/dhruv/geofence/Constants.java create mode 100644 GeoFence/app/src/main/java/com/example/dhruv/geofence/GeofenceTransitionsIntentService.java create mode 100644 GeoFence/app/src/main/java/com/example/dhruv/geofence/MainActivity.java create mode 100644 GeoFence/app/src/main/res/layout/activity_main.xml create mode 100644 GeoFence/app/src/main/res/mipmap-hdpi/ic_launcher.png create mode 100644 GeoFence/app/src/main/res/mipmap-hdpi/ic_launcher_round.png create mode 100644 GeoFence/app/src/main/res/mipmap-mdpi/ic_launcher.png create mode 100644 GeoFence/app/src/main/res/mipmap-mdpi/ic_launcher_round.png create mode 100644 GeoFence/app/src/main/res/mipmap-xhdpi/ic_launcher.png create mode 100644 GeoFence/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png create mode 100644 GeoFence/app/src/main/res/mipmap-xxhdpi/ic_launcher.png create mode 100644 GeoFence/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png create mode 100644 GeoFence/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png create mode 100644 GeoFence/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png create mode 100644 GeoFence/app/src/main/res/values/colors.xml create mode 100644 GeoFence/app/src/main/res/values/strings.xml create mode 100644 GeoFence/app/src/main/res/values/styles.xml create mode 100644 GeoFence/app/src/test/java/com/example/dhruv/geofence/ExampleUnitTest.java create mode 100644 GeoFence/build.gradle create mode 100644 GeoFence/gradle.properties create mode 100644 GeoFence/gradle/wrapper/gradle-wrapper.jar create mode 100644 GeoFence/gradle/wrapper/gradle-wrapper.properties create mode 100644 GeoFence/gradlew create mode 100755 GeoFence/gradlew.bat create mode 100644 GeoFence/settings.gradle create mode 100644 test1.tar.gz create mode 100644 test1/.gitignore create mode 100644 test1/.idea/compiler.xml create mode 100644 test1/.idea/copyright/profiles_settings.xml create mode 100644 test1/.idea/gradle.xml create mode 100644 test1/.idea/misc.xml create mode 100644 test1/.idea/modules.xml create mode 100644 test1/.idea/runConfigurations.xml create mode 100644 test1/app/.gitignore create mode 100644 test1/app/build.gradle create mode 100644 test1/app/proguard-rules.pro create mode 100644 test1/app/src/androidTest/java/com/example/lokhandmanav/test1/ExampleInstrumentedTest.java create mode 100644 test1/app/src/main/AndroidManifest.xml create mode 100644 test1/app/src/main/java/com/example/lokhandmanav/test1/MainActivity.java create mode 100644 test1/app/src/main/res/layout/activity_main.xml create mode 100644 test1/app/src/main/res/mipmap-hdpi/ic_launcher.png create mode 100644 test1/app/src/main/res/mipmap-hdpi/ic_launcher_round.png create mode 100644 test1/app/src/main/res/mipmap-mdpi/ic_launcher.png create mode 100644 test1/app/src/main/res/mipmap-mdpi/ic_launcher_round.png create mode 100644 test1/app/src/main/res/mipmap-xhdpi/ic_launcher.png create mode 100644 test1/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png create mode 100644 test1/app/src/main/res/mipmap-xxhdpi/ic_launcher.png create mode 100644 test1/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png create mode 100644 test1/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png create mode 100644 test1/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png create mode 100644 test1/app/src/main/res/values/colors.xml create mode 100644 test1/app/src/main/res/values/strings.xml create mode 100644 test1/app/src/main/res/values/styles.xml create mode 100644 test1/app/src/test/java/com/example/lokhandmanav/test1/ExampleUnitTest.java create mode 100644 test1/build.gradle create mode 100644 test1/gradle.properties create mode 100644 test1/gradle/wrapper/gradle-wrapper.jar create mode 100644 test1/gradle/wrapper/gradle-wrapper.properties create mode 100755 test1/gradlew create mode 100644 test1/gradlew.bat create mode 100644 test1/settings.gradle diff --git a/FingerprintAuthentication/.gitignore b/FingerprintAuthentication/.gitignore new file mode 100644 index 0000000..a4c7838 --- /dev/null +++ b/FingerprintAuthentication/.gitignore @@ -0,0 +1,9 @@ +*.iml +.gradle +/local.properties +/.idea/workspace.xml +/.idea/libraries +.DS_Store +/build +/captures +.externalNativeBuild diff --git a/FingerprintAuthentication/.idea/compiler.xml b/FingerprintAuthentication/.idea/compiler.xml new file mode 100644 index 0000000..96cc43e --- /dev/null +++ b/FingerprintAuthentication/.idea/compiler.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/FingerprintAuthentication/.idea/copyright/profiles_settings.xml b/FingerprintAuthentication/.idea/copyright/profiles_settings.xml new file mode 100644 index 0000000..c7d1c5a --- /dev/null +++ b/FingerprintAuthentication/.idea/copyright/profiles_settings.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/FingerprintAuthentication/.idea/gradle.xml b/FingerprintAuthentication/.idea/gradle.xml new file mode 100644 index 0000000..7ac24c7 --- /dev/null +++ b/FingerprintAuthentication/.idea/gradle.xml @@ -0,0 +1,18 @@ + + + + + + \ No newline at end of file diff --git a/FingerprintAuthentication/.idea/misc.xml b/FingerprintAuthentication/.idea/misc.xml new file mode 100644 index 0000000..5d19981 --- /dev/null +++ b/FingerprintAuthentication/.idea/misc.xml @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/FingerprintAuthentication/.idea/modules.xml b/FingerprintAuthentication/.idea/modules.xml new file mode 100644 index 0000000..5e30b25 --- /dev/null +++ b/FingerprintAuthentication/.idea/modules.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/FingerprintAuthentication/app/.gitignore b/FingerprintAuthentication/app/.gitignore new file mode 100644 index 0000000..3543521 --- /dev/null +++ b/FingerprintAuthentication/app/.gitignore @@ -0,0 +1 @@ +/build diff --git a/FingerprintAuthentication/app/build.gradle b/FingerprintAuthentication/app/build.gradle new file mode 100644 index 0000000..74b0670 --- /dev/null +++ b/FingerprintAuthentication/app/build.gradle @@ -0,0 +1,30 @@ +apply plugin: 'com.android.application' + +android { + compileSdkVersion 25 + buildToolsVersion "26.0.2" + defaultConfig { + applicationId "com.example.dhruv.fingerprintauthentication" + minSdkVersion 23 + targetSdkVersion 25 + versionCode 1 + versionName "1.0" + testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" + } + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + } +} + +dependencies { + compile fileTree(dir: 'libs', include: ['*.jar']) + androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { + exclude group: 'com.android.support', module: 'support-annotations' + }) + compile 'com.android.support:appcompat-v7:25.3.1' + compile 'com.android.support.constraint:constraint-layout:1.0.2' + testCompile 'junit:junit:4.12' +} diff --git a/FingerprintAuthentication/app/proguard-rules.pro b/FingerprintAuthentication/app/proguard-rules.pro new file mode 100644 index 0000000..775e288 --- /dev/null +++ b/FingerprintAuthentication/app/proguard-rules.pro @@ -0,0 +1,25 @@ +# Add project specific ProGuard rules here. +# By default, the flags in this file are appended to flags specified +# in C:\Users\Dhruv\AppData\Local\Android\Sdk/tools/proguard/proguard-android.txt +# You can edit the include path and order by changing the proguardFiles +# directive in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# Add any project specific keep options here: + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile diff --git a/FingerprintAuthentication/app/src/androidTest/java/com/example/dhruv/fingerprintauthentication/ExampleInstrumentedTest.java b/FingerprintAuthentication/app/src/androidTest/java/com/example/dhruv/fingerprintauthentication/ExampleInstrumentedTest.java new file mode 100644 index 0000000..e78e68f --- /dev/null +++ b/FingerprintAuthentication/app/src/androidTest/java/com/example/dhruv/fingerprintauthentication/ExampleInstrumentedTest.java @@ -0,0 +1,26 @@ +package com.example.dhruv.fingerprintauthentication; + +import android.content.Context; +import android.support.test.InstrumentationRegistry; +import android.support.test.runner.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import static org.junit.Assert.*; + +/** + * Instrumentation test, which will execute on an Android device. + * + * @see Testing documentation + */ +@RunWith(AndroidJUnit4.class) +public class ExampleInstrumentedTest { + @Test + public void useAppContext() throws Exception { + // Context of the app under test. + Context appContext = InstrumentationRegistry.getTargetContext(); + + assertEquals("com.example.dhruv.fingerprintauthentication", appContext.getPackageName()); + } +} diff --git a/FingerprintAuthentication/app/src/main/AndroidManifest.xml b/FingerprintAuthentication/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..0f3e2e8 --- /dev/null +++ b/FingerprintAuthentication/app/src/main/AndroidManifest.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/FingerprintAuthentication/app/src/main/java/com/example/dhruv/fingerprintauthentication/FingerprintHandler.java b/FingerprintAuthentication/app/src/main/java/com/example/dhruv/fingerprintauthentication/FingerprintHandler.java new file mode 100644 index 0000000..a00d3a5 --- /dev/null +++ b/FingerprintAuthentication/app/src/main/java/com/example/dhruv/fingerprintauthentication/FingerprintHandler.java @@ -0,0 +1,53 @@ +package com.example.dhruv.fingerprintauthentication; + +import android.hardware.fingerprint.FingerprintManager; +import android.os.Build; +import android.os.CancellationSignal; +import android.support.annotation.RequiresApi; +import android.widget.TextView; + + +@RequiresApi(api = Build.VERSION_CODES.M) +public class FingerprintHandler extends FingerprintManager.AuthenticationCallback { + + private TextView tv; + + + public FingerprintHandler(TextView tv) { + this.tv = tv; + } + + public void doAuth(FingerprintManager manager, FingerprintManager.CryptoObject obj) { + CancellationSignal signal = new CancellationSignal(); + + try { + manager.authenticate(obj, signal, 0, this, null); + } + catch(SecurityException sce) {} + } + + @Override + public void onAuthenticationError(int errorCode, CharSequence errString) { + super.onAuthenticationError(errorCode, errString); + tv.setText("Auth Error"); + } + + @Override + public void onAuthenticationHelp(int helpCode, CharSequence helpString) { + super.onAuthenticationHelp(helpCode, helpString); + + } + + @Override + public void onAuthenticationSucceeded(FingerprintManager.AuthenticationResult result) { + super.onAuthenticationSucceeded(result); + tv.setText("Auth Success"); + } + + @Override + public void onAuthenticationFailed() { + super.onAuthenticationFailed(); + } + + +} \ No newline at end of file diff --git a/FingerprintAuthentication/app/src/main/java/com/example/dhruv/fingerprintauthentication/MainActivity.java b/FingerprintAuthentication/app/src/main/java/com/example/dhruv/fingerprintauthentication/MainActivity.java new file mode 100644 index 0000000..fc2c89f --- /dev/null +++ b/FingerprintAuthentication/app/src/main/java/com/example/dhruv/fingerprintauthentication/MainActivity.java @@ -0,0 +1,174 @@ +package com.example.dhruv.fingerprintauthentication; + +import android.app.KeyguardManager; +import android.hardware.fingerprint.FingerprintManager; +import android.security.keystore.KeyGenParameterSpec; +import android.security.keystore.KeyGenParameterSpec.Builder; +import android.security.keystore.KeyProperties; +import android.support.v7.app.AppCompatActivity; +import android.os.Bundle; +import android.view.View; +import android.widget.Button; +import android.widget.TextView; + +import java.io.IOException; +import java.security.InvalidAlgorithmParameterException; +import java.security.InvalidKeyException; +import java.security.KeyStore; +import java.security.KeyStoreException; +import java.security.NoSuchAlgorithmException; +import java.security.NoSuchProviderException; +import java.security.UnrecoverableKeyException; +import java.security.cert.CertificateException; + +import javax.crypto.Cipher; +import javax.crypto.KeyGenerator; +import javax.crypto.NoSuchPaddingException; +import javax.crypto.SecretKey; + +public class MainActivity extends AppCompatActivity { + + private TextView message; + private static final String KEY_NAME = "SwA"; + + private KeyStore keyStore; + private KeyGenerator keyGenerator; + private FingerprintManager.CryptoObject cryptoObject; + + private FingerprintManager fingerprintManager; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + + message = (TextView) findViewById(R.id.fingerStatus); + Button btn = (Button) findViewById(R.id.authBtn); + + final FingerprintHandler fph = new FingerprintHandler(message); + + if (!checkFinger()) { + btn.setEnabled(false); + } + else { + // We are ready to set up the cipher and the key + try { + generateKey(); + Cipher cipher = generateCipher(); + cryptoObject = + new FingerprintManager.CryptoObject(cipher); + + } + catch(FingerprintException fpe) { + // Handle exception + btn.setEnabled(false); + } + } + + btn.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + message.setText("Swipe your finger"); + fph.doAuth(fingerprintManager, cryptoObject); + } + }); + } + + + private boolean checkFinger() { + + // Keyguard Manager + KeyguardManager keyguardManager = (KeyguardManager) getSystemService(KEYGUARD_SERVICE); + + // Fingerprint Manager + fingerprintManager = (FingerprintManager) getSystemService(FINGERPRINT_SERVICE); + + try { + // Check if the fingerprint sensor is present + if (!fingerprintManager.isHardwareDetected()) { + message.setText("Fingerprint authentication not supported"); + return false; + } + + if (!fingerprintManager.hasEnrolledFingerprints()) { + message.setText("No fingerprint configured."); + return false; + } + + if (!keyguardManager.isKeyguardSecure()) { + message.setText("Secure lock screen not enabled"); + return false; + } + + } + catch(SecurityException se) { + se.printStackTrace(); + } + + + return true; + + } + + private void generateKey() throws FingerprintException { + try { + // Get the reference to the key store + keyStore = KeyStore.getInstance("AndroidKeyStore"); + + // Key generator to generate the key + keyGenerator = KeyGenerator.getInstance(KeyProperties.KEY_ALGORITHM_AES, "AndroidKeyStore"); + + keyStore.load(null); + keyGenerator.init( new + KeyGenParameterSpec.Builder(KEY_NAME, + KeyProperties.PURPOSE_ENCRYPT | + KeyProperties.PURPOSE_DECRYPT) + .setBlockModes(KeyProperties.BLOCK_MODE_CBC) + .setUserAuthenticationRequired(true) + .setEncryptionPaddings( + KeyProperties.ENCRYPTION_PADDING_PKCS7) + .build()); + + keyGenerator.generateKey(); + + } + catch(KeyStoreException + | NoSuchAlgorithmException + | NoSuchProviderException + | InvalidAlgorithmParameterException + | CertificateException + | IOException exc) { + exc.printStackTrace(); + throw new FingerprintException(exc); + } + + + } + + private Cipher generateCipher() throws FingerprintException { + try { + Cipher cipher = Cipher.getInstance(KeyProperties.KEY_ALGORITHM_AES + "/" + + KeyProperties.BLOCK_MODE_CBC + "/" + + KeyProperties.ENCRYPTION_PADDING_PKCS7); + SecretKey key = (SecretKey) keyStore.getKey(KEY_NAME, + null); + cipher.init(Cipher.ENCRYPT_MODE, key); + return cipher; + } + catch (NoSuchAlgorithmException + | NoSuchPaddingException + | InvalidKeyException + | UnrecoverableKeyException + | KeyStoreException exc) { + exc.printStackTrace(); + throw new FingerprintException(exc); + } + } + + private class FingerprintException extends Exception { + + public FingerprintException(Exception e) { + super(e); + } + } +} \ No newline at end of file diff --git a/FingerprintAuthentication/app/src/main/res/layout/activity_main.xml b/FingerprintAuthentication/app/src/main/res/layout/activity_main.xml new file mode 100644 index 0000000..4992756 --- /dev/null +++ b/FingerprintAuthentication/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,34 @@ + + + + + + + + +