aboutsummaryrefslogtreecommitdiff
path: root/security
diff options
context:
space:
mode:
Diffstat (limited to 'security')
-rw-r--r--security/FingerprintDialog/Application/src/main/Android.mk26
-rw-r--r--security/FingerprintDialog/Application/src/main/AndroidManifest.xml7
-rw-r--r--security/FingerprintDialog/Application/src/main/java/com/example/android/fingerprintdialog/FingerprintAuthenticationDialogFragment.java16
-rw-r--r--security/FingerprintDialog/Application/src/main/java/com/example/android/fingerprintdialog/FingerprintModule.java107
-rw-r--r--security/FingerprintDialog/Application/src/main/java/com/example/android/fingerprintdialog/FingerprintUiHelper.java40
-rw-r--r--security/FingerprintDialog/Application/src/main/java/com/example/android/fingerprintdialog/InjectedApplication.java59
-rw-r--r--security/FingerprintDialog/Application/src/main/java/com/example/android/fingerprintdialog/MainActivity.java76
-rw-r--r--security/FingerprintDialog/Application/src/main/res/values/strings.xml6
-rw-r--r--security/FingerprintDialog/Application/src/test/java/com/example/android/fingerprintdialog/FingerprintUiHelperTest.java111
-rw-r--r--security/FingerprintDialog/template-params.xml9
10 files changed, 103 insertions, 354 deletions
diff --git a/security/FingerprintDialog/Application/src/main/Android.mk b/security/FingerprintDialog/Application/src/main/Android.mk
new file mode 100644
index 00000000..1f694d87
--- /dev/null
+++ b/security/FingerprintDialog/Application/src/main/Android.mk
@@ -0,0 +1,26 @@
+# Copyright (C) 2016 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.
+
+LOCAL_PATH:= $(call my-dir)
+include $(CLEAR_VARS)
+LOCAL_STATIC_JAVA_LIBRARIES := android-support-v7-appcompat
+LOCAL_MODULE_TAGS := samples
+LOCAL_SRC_FILES := $(call all-subdir-java-files)
+LOCAL_PACKAGE_NAME := FingerprintDialog
+LOCAL_RESOURCE_DIR := $(LOCAL_PATH)/res \
+ frameworks/support/v7/appcompat/res
+LOCAL_AAPT_FLAGS := --auto-add-overlay \
+ --extra-packages android.support.v7.appcompat
+
+include $(BUILD_PACKAGE)
diff --git a/security/FingerprintDialog/Application/src/main/AndroidManifest.xml b/security/FingerprintDialog/Application/src/main/AndroidManifest.xml
index 3b19fbec..77d99497 100644
--- a/security/FingerprintDialog/Application/src/main/AndroidManifest.xml
+++ b/security/FingerprintDialog/Application/src/main/AndroidManifest.xml
@@ -22,14 +22,13 @@
<uses-permission android:name="android.permission.USE_FINGERPRINT"/>
<application
- android:name=".InjectedApplication"
android:allowBackup="true"
- android:label="@string/app_name"
+ android:label="@string/application_name"
android:icon="@mipmap/ic_launcher"
- android:theme="@style/AppTheme">
+ android:theme="@style/Theme.AppCompat.Light">
<activity android:name=".MainActivity"
- android:label="@string/app_name">
+ android:label="@string/application_name">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
diff --git a/security/FingerprintDialog/Application/src/main/java/com/example/android/fingerprintdialog/FingerprintAuthenticationDialogFragment.java b/security/FingerprintDialog/Application/src/main/java/com/example/android/fingerprintdialog/FingerprintAuthenticationDialogFragment.java
index b17ebb0b..cb240dba 100644
--- a/security/FingerprintDialog/Application/src/main/java/com/example/android/fingerprintdialog/FingerprintAuthenticationDialogFragment.java
+++ b/security/FingerprintDialog/Application/src/main/java/com/example/android/fingerprintdialog/FingerprintAuthenticationDialogFragment.java
@@ -21,6 +21,7 @@ import android.app.DialogFragment;
import android.content.SharedPreferences;
import android.hardware.fingerprint.FingerprintManager;
import android.os.Bundle;
+import android.preference.PreferenceManager;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
@@ -33,8 +34,6 @@ import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
-import javax.inject.Inject;
-
/**
* A dialog which uses fingerprint APIs to authenticate the user, and falls back to password
* authentication if fingerprint is not available.
@@ -57,12 +56,8 @@ public class FingerprintAuthenticationDialogFragment extends DialogFragment
private FingerprintUiHelper mFingerprintUiHelper;
private MainActivity mActivity;
- @Inject FingerprintUiHelper.FingerprintUiHelperBuilder mFingerprintUiHelperBuilder;
- @Inject InputMethodManager mInputMethodManager;
- @Inject SharedPreferences mSharedPreferences;
-
- @Inject
- public FingerprintAuthenticationDialogFragment() {}
+ private InputMethodManager mInputMethodManager;
+ private SharedPreferences mSharedPreferences;
@Override
public void onCreate(Bundle savedInstanceState) {
@@ -106,7 +101,8 @@ public class FingerprintAuthenticationDialogFragment extends DialogFragment
v.findViewById(R.id.use_fingerprint_in_future_check);
mNewFingerprintEnrolledTextView = (TextView)
v.findViewById(R.id.new_fingerprint_enrolled_description);
- mFingerprintUiHelper = mFingerprintUiHelperBuilder.build(
+ mFingerprintUiHelper = new FingerprintUiHelper(
+ mActivity.getSystemService(FingerprintManager.class),
(ImageView) v.findViewById(R.id.fingerprint_icon),
(TextView) v.findViewById(R.id.fingerprint_status), this);
updateStage();
@@ -141,6 +137,8 @@ public class FingerprintAuthenticationDialogFragment extends DialogFragment
public void onAttach(Activity activity) {
super.onAttach(activity);
mActivity = (MainActivity) activity;
+ mInputMethodManager = mActivity.getSystemService(InputMethodManager.class);
+ mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(mActivity);
}
/**
diff --git a/security/FingerprintDialog/Application/src/main/java/com/example/android/fingerprintdialog/FingerprintModule.java b/security/FingerprintDialog/Application/src/main/java/com/example/android/fingerprintdialog/FingerprintModule.java
deleted file mode 100644
index 964e1f6d..00000000
--- a/security/FingerprintDialog/Application/src/main/java/com/example/android/fingerprintdialog/FingerprintModule.java
+++ /dev/null
@@ -1,107 +0,0 @@
-/*
- * 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
- */
-
-package com.example.android.fingerprintdialog;
-
-import android.app.KeyguardManager;
-import android.content.Context;
-import android.content.SharedPreferences;
-import android.hardware.fingerprint.FingerprintManager;
-import android.preference.PreferenceManager;
-import android.security.keystore.KeyProperties;
-import android.view.inputmethod.InputMethodManager;
-
-import java.security.KeyStore;
-import java.security.KeyStoreException;
-import java.security.NoSuchAlgorithmException;
-import java.security.NoSuchProviderException;
-
-import javax.crypto.Cipher;
-import javax.crypto.KeyGenerator;
-import javax.crypto.NoSuchPaddingException;
-
-import dagger.Module;
-import dagger.Provides;
-
-/**
- * Dagger module for Fingerprint APIs.
- */
-@Module(
- library = true,
- injects = {MainActivity.class}
-)
-public class FingerprintModule {
-
- private final Context mContext;
-
- public FingerprintModule(Context context) {
- mContext = context;
- }
-
- @Provides
- public Context providesContext() {
- return mContext;
- }
-
- @Provides
- public FingerprintManager providesFingerprintManager(Context context) {
- return context.getSystemService(FingerprintManager.class);
- }
-
- @Provides
- public KeyguardManager providesKeyguardManager(Context context) {
- return context.getSystemService(KeyguardManager.class);
- }
-
- @Provides
- public KeyStore providesKeystore() {
- try {
- return KeyStore.getInstance("AndroidKeyStore");
- } catch (KeyStoreException e) {
- throw new RuntimeException("Failed to get an instance of KeyStore", e);
- }
- }
-
- @Provides
- public KeyGenerator providesKeyGenerator() {
- try {
- return KeyGenerator.getInstance(KeyProperties.KEY_ALGORITHM_AES, "AndroidKeyStore");
- } catch (NoSuchAlgorithmException | NoSuchProviderException e) {
- throw new RuntimeException("Failed to get an instance of KeyGenerator", e);
- }
- }
-
- @Provides
- public Cipher providesCipher(KeyStore keyStore) {
- try {
- return Cipher.getInstance(KeyProperties.KEY_ALGORITHM_AES + "/"
- + KeyProperties.BLOCK_MODE_CBC + "/"
- + KeyProperties.ENCRYPTION_PADDING_PKCS7);
- } catch (NoSuchAlgorithmException | NoSuchPaddingException e) {
- throw new RuntimeException("Failed to get an instance of Cipher", e);
- }
- }
-
- @Provides
- public InputMethodManager providesInputMethodManager(Context context) {
- return (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
- }
-
- @Provides
- public SharedPreferences providesSharedPreferences(Context context) {
- return PreferenceManager.getDefaultSharedPreferences(context);
- }
-}
diff --git a/security/FingerprintDialog/Application/src/main/java/com/example/android/fingerprintdialog/FingerprintUiHelper.java b/security/FingerprintDialog/Application/src/main/java/com/example/android/fingerprintdialog/FingerprintUiHelper.java
index 92fcdb1d..be81646d 100644
--- a/security/FingerprintDialog/Application/src/main/java/com/example/android/fingerprintdialog/FingerprintUiHelper.java
+++ b/security/FingerprintDialog/Application/src/main/java/com/example/android/fingerprintdialog/FingerprintUiHelper.java
@@ -16,22 +16,18 @@
package com.example.android.fingerprintdialog;
-import com.google.common.annotations.VisibleForTesting;
-
import android.hardware.fingerprint.FingerprintManager;
import android.os.CancellationSignal;
import android.widget.ImageView;
import android.widget.TextView;
-import javax.inject.Inject;
-
/**
* Small helper class to manage text/icon around fingerprint authentication UI.
*/
public class FingerprintUiHelper extends FingerprintManager.AuthenticationCallback {
- @VisibleForTesting static final long ERROR_TIMEOUT_MILLIS = 1600;
- @VisibleForTesting static final long SUCCESS_DELAY_MILLIS = 1300;
+ private static final long ERROR_TIMEOUT_MILLIS = 1600;
+ private static final long SUCCESS_DELAY_MILLIS = 1300;
private final FingerprintManager mFingerprintManager;
private final ImageView mIcon;
@@ -39,31 +35,12 @@ public class FingerprintUiHelper extends FingerprintManager.AuthenticationCallba
private final Callback mCallback;
private CancellationSignal mCancellationSignal;
- @VisibleForTesting boolean mSelfCancelled;
-
- /**
- * Builder class for {@link FingerprintUiHelper} in which injected fields from Dagger
- * holds its fields and takes other arguments in the {@link #build} method.
- */
- public static class FingerprintUiHelperBuilder {
- private final FingerprintManager mFingerPrintManager;
-
- @Inject
- public FingerprintUiHelperBuilder(FingerprintManager fingerprintManager) {
- mFingerPrintManager = fingerprintManager;
- }
-
- public FingerprintUiHelper build(ImageView icon, TextView errorTextView, Callback callback) {
- return new FingerprintUiHelper(mFingerPrintManager, icon, errorTextView,
- callback);
- }
- }
+ private boolean mSelfCancelled;
/**
- * Constructor for {@link FingerprintUiHelper}. This method is expected to be called from
- * only the {@link FingerprintUiHelperBuilder} class.
+ * Constructor for {@link FingerprintUiHelper}.
*/
- private FingerprintUiHelper(FingerprintManager fingerprintManager,
+ FingerprintUiHelper(FingerprintManager fingerprintManager,
ImageView icon, TextView errorTextView, Callback callback) {
mFingerprintManager = fingerprintManager;
mIcon = icon;
@@ -72,6 +49,8 @@ public class FingerprintUiHelper extends FingerprintManager.AuthenticationCallba
}
public boolean isFingerprintAuthAvailable() {
+ // The line below prevents the false positive inspection from Android Studio
+ // noinspection ResourceType
return mFingerprintManager.isHardwareDetected()
&& mFingerprintManager.hasEnrolledFingerprints();
}
@@ -82,6 +61,8 @@ public class FingerprintUiHelper extends FingerprintManager.AuthenticationCallba
}
mCancellationSignal = new CancellationSignal();
mSelfCancelled = false;
+ // The line below prevents the false positive inspection from Android Studio
+ // noinspection ResourceType
mFingerprintManager
.authenticate(cryptoObject, mCancellationSignal, 0 /* flags */, this, null);
mIcon.setImageResource(R.drawable.ic_fp_40px);
@@ -144,8 +125,7 @@ public class FingerprintUiHelper extends FingerprintManager.AuthenticationCallba
mErrorTextView.postDelayed(mResetErrorTextRunnable, ERROR_TIMEOUT_MILLIS);
}
- @VisibleForTesting
- Runnable mResetErrorTextRunnable = new Runnable() {
+ private Runnable mResetErrorTextRunnable = new Runnable() {
@Override
public void run() {
mErrorTextView.setTextColor(
diff --git a/security/FingerprintDialog/Application/src/main/java/com/example/android/fingerprintdialog/InjectedApplication.java b/security/FingerprintDialog/Application/src/main/java/com/example/android/fingerprintdialog/InjectedApplication.java
deleted file mode 100644
index b7075a96..00000000
--- a/security/FingerprintDialog/Application/src/main/java/com/example/android/fingerprintdialog/InjectedApplication.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * 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
- */
-
-package com.example.android.fingerprintdialog;
-
-import android.app.Application;
-import android.util.Log;
-
-import dagger.ObjectGraph;
-
-/**
- * The Application class of the sample which holds the ObjectGraph in Dagger and enables
- * dependency injection.
- */
-public class InjectedApplication extends Application {
-
- private static final String TAG = InjectedApplication.class.getSimpleName();
-
- private ObjectGraph mObjectGraph;
-
- @Override
- public void onCreate() {
- super.onCreate();
-
- initObjectGraph(new FingerprintModule(this));
- }
-
- /**
- * Initialize the Dagger module. Passing null or mock modules can be used for testing.
- *
- * @param module for Dagger
- */
- public void initObjectGraph(Object module) {
- mObjectGraph = module != null ? ObjectGraph.create(module) : null;
- }
-
- public void inject(Object object) {
- if (mObjectGraph == null) {
- // This usually happens during tests.
- Log.i(TAG, "Object graph is not initialized.");
- return;
- }
- mObjectGraph.inject(object);
- }
-
-}
diff --git a/security/FingerprintDialog/Application/src/main/java/com/example/android/fingerprintdialog/MainActivity.java b/security/FingerprintDialog/Application/src/main/java/com/example/android/fingerprintdialog/MainActivity.java
index 7caf9e69..77c87886 100644
--- a/security/FingerprintDialog/Application/src/main/java/com/example/android/fingerprintdialog/MainActivity.java
+++ b/security/FingerprintDialog/Application/src/main/java/com/example/android/fingerprintdialog/MainActivity.java
@@ -22,6 +22,7 @@ import android.content.Intent;
import android.content.SharedPreferences;
import android.hardware.fingerprint.FingerprintManager;
import android.os.Bundle;
+import android.preference.PreferenceManager;
import android.security.keystore.KeyGenParameterSpec;
import android.security.keystore.KeyPermanentlyInvalidatedException;
import android.security.keystore.KeyProperties;
@@ -40,6 +41,7 @@ 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;
@@ -47,8 +49,8 @@ import javax.crypto.BadPaddingException;
import javax.crypto.Cipher;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.KeyGenerator;
+import javax.crypto.NoSuchPaddingException;
import javax.crypto.SecretKey;
-import javax.inject.Inject;
/**
* Main entry point for the sample, showing a backpack and "Purchase" button.
@@ -62,22 +64,40 @@ public class MainActivity extends Activity {
/** Alias for our key in the Android Key Store */
private static final String KEY_NAME = "my_key";
- @Inject KeyguardManager mKeyguardManager;
- @Inject FingerprintManager mFingerprintManager;
- @Inject FingerprintAuthenticationDialogFragment mFragment;
- @Inject KeyStore mKeyStore;
- @Inject KeyGenerator mKeyGenerator;
- @Inject Cipher mCipher;
- @Inject SharedPreferences mSharedPreferences;
+ private KeyStore mKeyStore;
+ private KeyGenerator mKeyGenerator;
+ private Cipher mCipher;
+ private SharedPreferences mSharedPreferences;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- ((InjectedApplication) getApplication()).inject(this);
-
setContentView(R.layout.activity_main);
+
+ try {
+ mKeyStore = KeyStore.getInstance("AndroidKeyStore");
+ } catch (KeyStoreException e) {
+ throw new RuntimeException("Failed to get an instance of KeyStore", e);
+ }
+ try {
+ mKeyGenerator = KeyGenerator
+ .getInstance(KeyProperties.KEY_ALGORITHM_AES, "AndroidKeyStore");
+ } catch (NoSuchAlgorithmException | NoSuchProviderException e) {
+ throw new RuntimeException("Failed to get an instance of KeyGenerator", e);
+ }
+ try {
+ mCipher = Cipher.getInstance(KeyProperties.KEY_ALGORITHM_AES + "/"
+ + KeyProperties.BLOCK_MODE_CBC + "/"
+ + KeyProperties.ENCRYPTION_PADDING_PKCS7);
+ } catch (NoSuchAlgorithmException | NoSuchPaddingException e) {
+ throw new RuntimeException("Failed to get an instance of Cipher", e);
+ }
+ mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
+
+ KeyguardManager keyguardManager = getSystemService(KeyguardManager.class);
+ FingerprintManager fingerprintManager = getSystemService(FingerprintManager.class);
Button purchaseButton = (Button) findViewById(R.id.purchase_button);
- if (!mKeyguardManager.isKeyguardSecure()) {
+ if (!keyguardManager.isKeyguardSecure()) {
// Show a message that the user hasn't set up a fingerprint or lock screen.
Toast.makeText(this,
"Secure lock screen hasn't set up.\n"
@@ -87,8 +107,11 @@ public class MainActivity extends Activity {
return;
}
- //noinspection ResourceType
- if (!mFingerprintManager.hasEnrolledFingerprints()) {
+ // Now the protection level of USE_FINGERPRINT permission is normal instead of dangerous.
+ // See http://developer.android.com/reference/android/Manifest.permission.html#USE_FINGERPRINT
+ // The line below prevents the false positive inspection from Android Studio
+ // noinspection ResourceType
+ if (!fingerprintManager.hasEnrolledFingerprints()) {
purchaseButton.setEnabled(false);
// This happens when no fingerprints are registered.
Toast.makeText(this,
@@ -107,30 +130,33 @@ public class MainActivity extends Activity {
// Set up the crypto object for later. The object will be authenticated by use
// of the fingerprint.
if (initCipher()) {
-
- // Show the fingerprint dialog. The user has the option to use the fingerprint with
- // crypto, or you can fall back to using a server-side verified password.
- mFragment.setCryptoObject(new FingerprintManager.CryptoObject(mCipher));
+ // Show the fingerprint dialog. The user has the option to use the fingerprint
+ // with crypto, or you can fall back to using a server-side verified password.
+ FingerprintAuthenticationDialogFragment fragment
+ = new FingerprintAuthenticationDialogFragment();
+ fragment.setCryptoObject(new FingerprintManager.CryptoObject(mCipher));
boolean useFingerprintPreference = mSharedPreferences
.getBoolean(getString(R.string.use_fingerprint_to_authenticate_key),
true);
if (useFingerprintPreference) {
- mFragment.setStage(
+ fragment.setStage(
FingerprintAuthenticationDialogFragment.Stage.FINGERPRINT);
} else {
- mFragment.setStage(
+ fragment.setStage(
FingerprintAuthenticationDialogFragment.Stage.PASSWORD);
}
- mFragment.show(getFragmentManager(), DIALOG_FRAGMENT_TAG);
+ fragment.show(getFragmentManager(), DIALOG_FRAGMENT_TAG);
} else {
// This happens if the lock screen has been disabled or or a fingerprint got
// enrolled. Thus show the dialog to authenticate with their password first
// and ask the user if they want to authenticate with fingerprints in the
// future
- mFragment.setCryptoObject(new FingerprintManager.CryptoObject(mCipher));
- mFragment.setStage(
+ FingerprintAuthenticationDialogFragment fragment
+ = new FingerprintAuthenticationDialogFragment();
+ fragment.setCryptoObject(new FingerprintManager.CryptoObject(mCipher));
+ fragment.setStage(
FingerprintAuthenticationDialogFragment.Stage.NEW_FINGERPRINT_ENROLLED);
- mFragment.show(getFragmentManager(), DIALOG_FRAGMENT_TAG);
+ fragment.show(getFragmentManager(), DIALOG_FRAGMENT_TAG);
}
}
});
@@ -210,8 +236,8 @@ public class MainActivity extends Activity {
KeyProperties.PURPOSE_ENCRYPT |
KeyProperties.PURPOSE_DECRYPT)
.setBlockModes(KeyProperties.BLOCK_MODE_CBC)
- // Require the user to authenticate with a fingerprint to authorize every use
- // of the key
+ // Require the user to authenticate with a fingerprint to authorize every use
+ // of the key
.setUserAuthenticationRequired(true)
.setEncryptionPaddings(KeyProperties.ENCRYPTION_PADDING_PKCS7)
.build());
diff --git a/security/FingerprintDialog/Application/src/main/res/values/strings.xml b/security/FingerprintDialog/Application/src/main/res/values/strings.xml
index 9f5a6fd1..77d1176e 100644
--- a/security/FingerprintDialog/Application/src/main/res/values/strings.xml
+++ b/security/FingerprintDialog/Application/src/main/res/values/strings.xml
@@ -15,6 +15,12 @@
~ limitations under the License
-->
<resources>
+ <!--
+ The similar strings app_name is added in the Application/template directory, but depending
+ on the template directory makes it hard for the sample buildable with Android.mk.
+ Thus defining the application_name with different name from the template.
+ -->
+ <string name="application_name">FingerprintDialog</string>
<string name="action_settings">Settings</string>
<string name="cancel">Cancel</string>
<string name="use_password">Use password</string>
diff --git a/security/FingerprintDialog/Application/src/test/java/com/example/android/fingerprintdialog/FingerprintUiHelperTest.java b/security/FingerprintDialog/Application/src/test/java/com/example/android/fingerprintdialog/FingerprintUiHelperTest.java
deleted file mode 100644
index da9b2a33..00000000
--- a/security/FingerprintDialog/Application/src/test/java/com/example/android/fingerprintdialog/FingerprintUiHelperTest.java
+++ /dev/null
@@ -1,111 +0,0 @@
-package com.example.android.fingerprintdialog;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.ArgumentCaptor;
-import org.mockito.Captor;
-import org.mockito.InjectMocks;
-import org.mockito.Mock;
-import org.mockito.runners.MockitoJUnitRunner;
-
-import android.content.res.Resources;
-import android.hardware.fingerprint.FingerprintManager;
-import android.os.CancellationSignal;
-import android.os.Handler;
-import android.widget.ImageView;
-import android.widget.TextView;
-
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.eq;
-import static org.mockito.Matchers.isA;
-import static org.mockito.Mockito.never;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-/**
- * Unit tests for {@link FingerprintUiHelper}.
- */
-@RunWith(MockitoJUnitRunner.class)
-public class FingerprintUiHelperTest {
-
- private static final int ERROR_MSG_ID = 1;
- private static final CharSequence ERR_STRING = "ERROR_STRING";
- private static final int HINT_COLOR = 10;
-
- @Mock private FingerprintManager mockFingerprintManager;
- @Mock private ImageView mockIcon;
- @Mock private TextView mockTextView;
- @Mock private FingerprintUiHelper.Callback mockCallback;
- @Mock private FingerprintManager.CryptoObject mockCryptoObject;
- @Mock private Resources mockResources;
-
- @Captor private ArgumentCaptor<Runnable> mRunnableArgumentCaptor;
-
- @InjectMocks private FingerprintUiHelper.FingerprintUiHelperBuilder mockBuilder;
-
- private FingerprintUiHelper mFingerprintUiHelper;
-
- @Before
- public void setUp() {
- mFingerprintUiHelper = mockBuilder.build(mockIcon, mockTextView, mockCallback);
-
- when(mockFingerprintManager.isHardwareDetected()).thenReturn(true);
- when(mockFingerprintManager.hasEnrolledFingerprints()).thenReturn(true);
- when(mockTextView.getResources()).thenReturn(mockResources);
- when(mockResources.getColor(R.color.hint_color, null)).thenReturn(HINT_COLOR);
- }
-
- @Test
- public void testStartListening_fingerprintAuthAvailable() {
- mFingerprintUiHelper.startListening(mockCryptoObject);
-
- verify(mockFingerprintManager).authenticate(eq(mockCryptoObject),
- isA(CancellationSignal.class), eq(0), eq(mFingerprintUiHelper),
- any(Handler.class));
- verify(mockIcon).setImageResource(R.drawable.ic_fp_40px);
- }
-
- @Test
- public void testStartListening_fingerprintAuthNotAvailable() {
- when(mockFingerprintManager.isHardwareDetected()).thenReturn(false);
-
- mFingerprintUiHelper.startListening(mockCryptoObject);
-
- verify(mockFingerprintManager, never()).authenticate(
- any(FingerprintManager.CryptoObject.class), any(CancellationSignal.class), eq(0),
- any(FingerprintUiHelper.class), any(Handler.class));
- }
-
- @Test
- public void testOnAuthenticationError() {
- mFingerprintUiHelper.mSelfCancelled = false;
-
- mFingerprintUiHelper.onAuthenticationError(ERROR_MSG_ID, ERR_STRING);
-
- verify(mockIcon).setImageResource(R.drawable.ic_fingerprint_error);
- verify(mockTextView).removeCallbacks(mFingerprintUiHelper.mResetErrorTextRunnable);
- verify(mockTextView).postDelayed(mFingerprintUiHelper.mResetErrorTextRunnable,
- FingerprintUiHelper.ERROR_TIMEOUT_MILLIS);
- verify(mockIcon).postDelayed(mRunnableArgumentCaptor.capture(),
- eq(FingerprintUiHelper.ERROR_TIMEOUT_MILLIS));
-
- mRunnableArgumentCaptor.getValue().run();
-
- verify(mockCallback).onError();
- }
-
- @Test
- public void testOnAuthenticationSucceeded() {
- mFingerprintUiHelper.onAuthenticationSucceeded(null);
-
- verify(mockIcon).setImageResource(R.drawable.ic_fingerprint_success);
- verify(mockTextView).removeCallbacks(mFingerprintUiHelper.mResetErrorTextRunnable);
- verify(mockIcon).postDelayed(mRunnableArgumentCaptor.capture(),
- eq(FingerprintUiHelper.SUCCESS_DELAY_MILLIS));
-
- mRunnableArgumentCaptor.getValue().run();
-
- verify(mockCallback).onAuthenticated();
- }
-}
diff --git a/security/FingerprintDialog/template-params.xml b/security/FingerprintDialog/template-params.xml
index 33db81c3..cb1d2767 100644
--- a/security/FingerprintDialog/template-params.xml
+++ b/security/FingerprintDialog/template-params.xml
@@ -28,15 +28,6 @@
<targetSdkVersion>23</targetSdkVersion>
<compileSdkVersion>23</compileSdkVersion>
- <dependency>com.squareup.dagger:dagger:1.2.2</dependency>
- <dependency>com.squareup.dagger:dagger-compiler:1.2.2</dependency>
-
- <!-- TODO(thagikura) These dependencies should be created as testCompile instead of compile but
- the template system doesn't allow androidTestCompile dependencies. Change it once fixed.
- -->
- <dependency>junit:junit:4.12</dependency>
- <dependency>org.mockito:mockito-core:1.10.19</dependency>
-
<strings>
<intro>
<![CDATA[