Started working on authentication methods

pull/41/head
Michael Schättgen 8 years ago committed by Alexander Bakker
parent c79c9f84dc
commit f1b499f101

@ -39,5 +39,6 @@ dependencies {
compile 'com.android.support:support-v4:25.0.0'
compile 'com.android.support:recyclerview-v7:25.0.0'
compile 'com.yarolegovich:lovely-dialog:1.0.4'
compile 'com.mattprecious.swirl:swirl:1.0.0'
testCompile 'junit:junit:4.12'
}

@ -33,9 +33,9 @@
android:label="@string/title_activity_intro"
android:theme="@style/Theme.Intro">
</activity>
<activity android:name=".PreferencesActivity"
>
<activity android:name=".PreferencesActivity">
</activity>
<activity android:name=".SetPasswordActivity">
</activity>
</application>
</manifest>
</manifest>

@ -0,0 +1,55 @@
package me.impy.aegis;
import android.hardware.fingerprint.FingerprintManager;
import android.os.Build;
import android.support.annotation.RequiresApi;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.RadioButton;
import com.mattprecious.swirl.SwirlView;
import javax.crypto.Cipher;
import agency.tango.materialintroscreen.SlideFragment;
import me.impy.aegis.finger.FingerprintAuthenticationDialogFragment;
public class CustomAuthenticatedSlide extends SlideFragment {
private CheckBox checkBox;
private RadioButton passwordRadioButton;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
final View view = inflater.inflate(R.layout.fragment_authenticated_slide, container, false);
return view;
}
@Override
public int backgroundColor() {
return R.color.colorHeaderSuccess;
}
@Override
public int buttonsColor() {
return R.color.colorAccent;
}
@Override
public boolean canMoveFurther() {
return true; //checkBox.isChecked();
}
public void onAuthenticated(FingerprintAuthenticationDialogFragment.Action action, FingerprintManager.CryptoObject obj) {
}
@Override
public String cantMoveFurtherErrorMessage() {
return "Ja bijna vriend";
//return getString(R.string.error_message);
}
}

@ -0,0 +1,89 @@
package me.impy.aegis;
import android.app.Activity;
import android.content.Intent;
import android.hardware.fingerprint.FingerprintManager;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.RequiresApi;
import android.app.DialogFragment;
import android.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import com.mattprecious.swirl.SwirlView;
import agency.tango.materialintroscreen.SlideFragment;
import me.impy.aegis.finger.FingerprintAuthenticationDialogFragment;
import me.impy.aegis.finger.SetFingerprintAuthenticationDialog;
public class CustomAuthenticationSlide extends SlideFragment implements SetFingerprintAuthenticationDialog.InterfaceCommunicator{
private CheckBox checkBox;
private RadioButton fingerprintRadioButton;
private RadioGroup authenticationMethodRadioGroup;
public static final int DIALOG_FRAGMENT = 1;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
final View view = inflater.inflate(R.layout.fragment_authentication_slide, container, false);
final CustomAuthenticationSlide caller = this;
fingerprintRadioButton = (RadioButton) view.findViewById(R.id.rb_fingerprint);
fingerprintRadioButton.setOnClickListener(new View.OnClickListener() {
@RequiresApi(api = Build.VERSION_CODES.M)
@Override
public void onClick(View view) {
SetFingerprintAuthenticationDialog fragment = new SetFingerprintAuthenticationDialog();
//fragment.setCryptoObject(new FingerprintManager.CryptoObject(cipher));
fragment.setStage(SetFingerprintAuthenticationDialog.Stage.FINGERPRINT);
fragment.setCaller(caller);
//fragment.setAction(action);
fragment.show(getActivity().getFragmentManager(), "dialog");
}
});
authenticationMethodRadioGroup = (RadioGroup) view.findViewById(R.id.rg_authenticationMethod);
return view;
}
@Override
public int backgroundColor() {
return R.color.colorHeaderSuccess;
}
@Override
public int buttonsColor() {
return R.color.colorAccent;
}
@Override
public boolean canMoveFurther() {
return authenticationMethodRadioGroup.getCheckedRadioButtonId() != -1;
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
}
@Override
public String cantMoveFurtherErrorMessage() {
return "Please select an authentication method";
//return getString(R.string.error_message);
}
@Override
public void sendRequestCode(int code) {
if (code == 1) {
} else if (code == 0){
authenticationMethodRadioGroup.clearCheck();
}
}
}

@ -39,6 +39,9 @@ public class IntroActivity extends MaterialIntroActivity {
}
}, "Permission granted"));
addSlide(new CustomAuthenticationSlide());
addSlide(new CustomAuthenticatedSlide());
}
@Override

@ -0,0 +1,13 @@
package me.impy.aegis;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class SetPasswordActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_set_password);
}
}

@ -0,0 +1,172 @@
package me.impy.aegis.finger;
/*
* Copyright (C) 2015 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License
*/
import android.app.Activity;
import android.app.DialogFragment;
import android.content.Context;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.hardware.fingerprint.FingerprintManager;
import android.os.Build;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.annotation.RequiresApi;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import me.impy.aegis.CustomAuthenticationSlide;
import me.impy.aegis.IntroActivity;
import me.impy.aegis.MainActivity;
import me.impy.aegis.R;
/**
* A dialog which uses fingerprint APIs to authenticate the user, and falls back to password
* authentication if fingerprint is not available.
*/
@RequiresApi(api = Build.VERSION_CODES.M)
public class SetFingerprintAuthenticationDialog extends DialogFragment implements FingerprintUiHelper.Callback {
private Button mCancelButton;
private Button mSecondDialogButton;
private View mFingerprintContent;
private View mBackupContent;
private EditText mPassword;
private CheckBox mUseFingerprintFutureCheckBox;
private TextView mPasswordDescriptionTextView;
private TextView mNewFingerprintEnrolledTextView;
private Stage mStage = Stage.FINGERPRINT;
private Action mAction;
private FingerprintManager.CryptoObject mCryptoObject;
private FingerprintUiHelper mFingerprintUiHelper;
private IntroActivity mIntroActivity;
public InterfaceCommunicator interfaceCommunicator;
private InputMethodManager mInputMethodManager;
private SharedPreferences mSharedPreferences;
private CustomAuthenticationSlide customAuthenticationSlide;
public void setCaller(CustomAuthenticationSlide customAuthenticationSlide)
{
this.customAuthenticationSlide = customAuthenticationSlide;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setRetainInstance(true);
setStyle(DialogFragment.STYLE_NORMAL, android.R.style.Theme_Material_Light_Dialog);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
getDialog().setTitle(getString(R.string.sign_in));
View v = inflater.inflate(R.layout.fingerprint_dialog_container, container, false);
mCancelButton = (Button) v.findViewById(R.id.cancel_button);
mCancelButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
customAuthenticationSlide.sendRequestCode(0);
dismiss();
}
});
mFingerprintContent = v.findViewById(R.id.fingerprint_container);
mFingerprintUiHelper = new FingerprintUiHelper(
mIntroActivity.getSystemService(FingerprintManager.class),
(ImageView) v.findViewById(R.id.fingerprint_icon),
(TextView) v.findViewById(R.id.fingerprint_status), this);
return v;
}
@Override
public void onResume() {
super.onResume();
if (mStage == Stage.FINGERPRINT) {
mFingerprintUiHelper.startListening(mCryptoObject);
}
}
public void setStage(Stage stage) {
mStage = stage;
}
public void setAction(Action action) { mAction = action; }
@Override
public void onPause() {
super.onPause();
mFingerprintUiHelper.stopListening();
}
@Override
public void onDismiss(DialogInterface dialog) {
super.onDismiss(dialog);
customAuthenticationSlide.sendRequestCode(0);
}
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
mIntroActivity = (IntroActivity) activity;
}
@Override
public void onAuthenticated() {
// Callback from FingerprintUiHelper. Let the activity know that authentication was
// successful.
customAuthenticationSlide.sendRequestCode(1);
dismiss();
}
@Override
public void onError() {
customAuthenticationSlide.sendRequestCode(0);
}
public interface InterfaceCommunicator {
void sendRequestCode(int code);
}
/**
* Enumeration to indicate which authentication method the user is trying to authenticate with.
*/
public enum Stage {
FINGERPRINT,
NEW_FINGERPRINT_ENROLLED,
PASSWORD
}
public enum Action {
LOAD,
SAVE
}
}

@ -0,0 +1,61 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_set_password"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="me.impy.aegis.SetPasswordActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true"
android:id="@+id/textView4"
android:text="@string/set_password"/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:ems="10"
android:id="@+id/editText2"
android:layout_below="@+id/textView3"
android:layout_alignParentStart="true"
android:layout_marginTop="10dp"
android:layout_alignParentEnd="true"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textView3"
android:text="@string/set_password_confirm"
android:layout_marginTop="74dp"
android:layout_below="@+id/textView4"
/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:ems="10"
android:id="@+id/editText"
android:layout_marginTop="8dp"
android:layout_below="@+id/textView4"
android:layout_alignParentStart="true"
android:layout_alignParentEnd="true"/>
<Button
android:text="Continue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/button"
android:layout_below="@+id/editText2"
android:layout_alignParentEnd="true"
android:layout_marginTop="26dp"/>
</RelativeLayout>

@ -0,0 +1,75 @@
<?xml version="1.0" encoding="utf-8"?>
<agency.tango.materialintroscreen.parallax.ParallaxLinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorPrimary"
android:orientation="vertical"
android:paddingTop="30dp">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="32dp">
<TextView
android:text="@string/authentication_method_set_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="24sp"
android:textColor="@color/primary_text_inverted"
android:id="@+id/textView2" />
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="12dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true"
android:id="@+id/textView4"
android:text="@string/set_password"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:ems="10"
android:id="@+id/editText2"
android:layout_below="@+id/textView3"
android:layout_alignParentStart="true"
android:layout_marginTop="10dp"
android:layout_alignParentEnd="true"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/textView3"
android:text="@string/set_password_confirm"
android:layout_marginTop="20dp"
android:layout_below="@+id/textView4"
/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:ems="10"
android:id="@+id/editText"
android:layout_marginTop="8dp"
android:layout_below="@+id/textView4"
android:layout_alignParentStart="true"
android:layout_alignParentEnd="true"/>
</LinearLayout>
</LinearLayout>
</agency.tango.materialintroscreen.parallax.ParallaxLinearLayout>

@ -0,0 +1,99 @@
<?xml version="1.0" encoding="utf-8"?>
<agency.tango.materialintroscreen.parallax.ParallaxLinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorHeaderSuccess"
android:orientation="vertical"
android:paddingBottom="164dp"
android:paddingTop="30dp">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="32dp">
<TextView
android:text="@string/choose_authentication_method"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="24sp"
android:textColor="@color/primary_text_inverted"
android:id="@+id/textView2" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_marginTop="12dp">
<RadioGroup
android:layout_width="match_parent"
android:id="@+id/rg_authenticationMethod"
android:layout_height="187dp">
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="16sp"
android:id="@+id/radioButton"
android:text="@string/authentication_method_none"/>
<TextView
android:text="@string/authentication_method_none_description"
android:layout_width="match_parent"
android:textColor="@color/secondary_text_inverted"
android:layout_marginTop="-5dp"
android:layout_height="wrap_content"
android:layout_marginStart="32dp"
/>
<RadioButton
android:text="@string/authentication_method_password"
android:layout_width="match_parent"
android:textSize="16sp"
android:layout_height="wrap_content"
android:id="@+id/rb_password"/>
<TextView
android:text="@string/authentication_method_password_description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="-5dp"
android:textColor="@color/secondary_text_inverted"
android:layout_marginStart="32dp"
/>
<RadioButton
android:text="@string/authentication_method_fingerprint"
android:layout_width="match_parent"
android:textSize="16sp"
android:layout_height="wrap_content"
android:id="@+id/rb_fingerprint"/>
<TextView
android:text="@string/authentication_method_fingerprint_description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="-5dp"
android:textColor="@color/secondary_text_inverted"
android:layout_marginStart="32dp"
/>
</RadioGroup>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="1">
</LinearLayout>
</LinearLayout>
</agency.tango.materialintroscreen.parallax.ParallaxLinearLayout>

@ -30,5 +30,21 @@
<string name="new_fingerprint_enrolled_description">A new fingerprint was added to this device, so your password is required.</string>
<string name="use_fingerprint_in_future">Use fingerprint in the future</string>
<string name="use_fingerprint_to_authenticate_title">Use fingerprint to authenticate</string>
<string name="use_fingerprint_to_authenticate_key" >use_fingerprint_to_authenticate_key</string>
<string name="use_fingerprint_to_authenticate_key">use_fingerprint_to_authenticate_key</string>
<string name="choose_authentication_method">Authentication</string>
<string name="authentication_method_none">None</string>
<string name="authentication_method_none_description">This provides no security at all, use at your own risk</string>
<string name="authentication_method_password">Password</string>
<string name="authentication_method_password_description">This allows you to use a password in order to open the app</string>
<string name="authentication_method_fingerprint">Fingerprint</string>
<string name="authentication_method_fingerprint_description">This allows you to use the fingerprints registered on this device to open the app</string>
<string name="authentication_method_set_password">Password</string>
<string name="set_password">Please enter a password</string>
<string name="set_password_confirm">Please confirm the password</string>
<string-array name="authentication_methods">
<item>None</item>
<item>Password</item>
<item>Fingerprint</item>
</string-array>
</resources>

@ -3,6 +3,8 @@
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="swirl_ridgeColor">?android:attr/textColorSecondary</item>
<item name="swirl_errorColor">?android:attr/colorAccent</item>
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
@ -37,7 +39,8 @@
<style name="AppTheme.Default">
<item name="android:windowBackground">@color/background</item>
<item name="swirl_ridgeColor">?android:attr/textColorSecondary</item>
<item name="swirl_errorColor">?android:attr/colorAccent</item>
<item name="android:textColorPrimary">@color/primary_text</item>
<item name="android:textColorSecondary">@color/secondary_text</item>
<item name="primaryText">@color/primary_text</item>

Loading…
Cancel
Save