|
@@ -1,4 +1,4 @@
|
|
|
-/**
|
|
|
+/*
|
|
|
* Nextcloud Android client application
|
|
|
*
|
|
|
* @author Florian Lentz
|
|
@@ -28,6 +28,7 @@ import android.content.Intent;
|
|
|
import android.content.pm.PackageManager;
|
|
|
import android.content.res.ColorStateList;
|
|
|
import android.graphics.Color;
|
|
|
+import android.graphics.drawable.ColorDrawable;
|
|
|
import android.graphics.drawable.Drawable;
|
|
|
import android.hardware.fingerprint.FingerprintManager;
|
|
|
import android.os.Build;
|
|
@@ -40,6 +41,7 @@ import android.support.annotation.RequiresApi;
|
|
|
import android.support.v4.app.ActivityCompat;
|
|
|
import android.support.v4.graphics.drawable.DrawableCompat;
|
|
|
import android.support.v7.app.AppCompatActivity;
|
|
|
+import android.support.v7.widget.Toolbar;
|
|
|
import android.view.KeyEvent;
|
|
|
import android.widget.ImageView;
|
|
|
import android.widget.TextView;
|
|
@@ -49,6 +51,7 @@ import com.owncloud.android.MainApp;
|
|
|
import com.owncloud.android.R;
|
|
|
import com.owncloud.android.lib.common.utils.Log_OC;
|
|
|
import com.owncloud.android.utils.AnalyticsUtils;
|
|
|
+import com.owncloud.android.utils.DisplayUtils;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
import java.security.InvalidAlgorithmParameterException;
|
|
@@ -68,6 +71,7 @@ import javax.crypto.SecretKey;
|
|
|
/**
|
|
|
* Activity to handle access to the app based on the fingerprint.
|
|
|
*/
|
|
|
+@TargetApi(Build.VERSION_CODES.M)
|
|
|
public class FingerprintActivity extends AppCompatActivity {
|
|
|
|
|
|
private static final String TAG = FingerprintActivity.class.getSimpleName();
|
|
@@ -83,10 +87,6 @@ public class FingerprintActivity extends AppCompatActivity {
|
|
|
private static final String KEY_NAME = "Nextcloud";
|
|
|
private Cipher cipher;
|
|
|
|
|
|
- private FingerprintHandler helper;
|
|
|
-
|
|
|
- private FingerprintManager.CryptoObject cryptoObject;
|
|
|
-
|
|
|
private CancellationSignal cancellationSignal;
|
|
|
|
|
|
/**
|
|
@@ -97,6 +97,14 @@ public class FingerprintActivity extends AppCompatActivity {
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
super.onCreate(savedInstanceState);
|
|
|
setContentView(R.layout.fingerprintlock);
|
|
|
+
|
|
|
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
|
|
+ getWindow().setStatusBarColor(DisplayUtils.primaryDarkColor());
|
|
|
+ }
|
|
|
+
|
|
|
+ Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
|
|
|
+ toolbar.setTitleTextColor(DisplayUtils.fontColor());
|
|
|
+ toolbar.setBackground(new ColorDrawable(DisplayUtils.primaryColor()));
|
|
|
}
|
|
|
|
|
|
private void startFingerprint() {
|
|
@@ -111,13 +119,11 @@ public class FingerprintActivity extends AppCompatActivity {
|
|
|
}
|
|
|
KeyguardManager keyguardManager = (KeyguardManager) getSystemService(KEYGUARD_SERVICE);
|
|
|
|
|
|
- if (!keyguardManager.isKeyguardSecure()) {
|
|
|
- return;
|
|
|
- } else {
|
|
|
+ if (keyguardManager.isKeyguardSecure()) {
|
|
|
generateKey();
|
|
|
|
|
|
if (cipherInit()) {
|
|
|
- cryptoObject = new FingerprintManager.CryptoObject(cipher);
|
|
|
+ FingerprintManager.CryptoObject cryptoObject = new FingerprintManager.CryptoObject(cipher);
|
|
|
FingerprintHandler.Callback callback = new FingerprintHandler.Callback() {
|
|
|
@Override
|
|
|
public void onAuthenticated() {
|
|
@@ -140,7 +146,7 @@ public class FingerprintActivity extends AppCompatActivity {
|
|
|
}
|
|
|
};
|
|
|
|
|
|
- helper = new FingerprintHandler(fingerprintTextView, callback);
|
|
|
+ FingerprintHandler helper = new FingerprintHandler(fingerprintTextView, callback);
|
|
|
cancellationSignal = new CancellationSignal();
|
|
|
if (ActivityCompat.checkSelfPermission(MainApp.getAppContext(), Manifest.permission.USE_FINGERPRINT)
|
|
|
!= PackageManager.PERMISSION_GRANTED) {
|
|
@@ -157,7 +163,7 @@ public class FingerprintActivity extends AppCompatActivity {
|
|
|
AnalyticsUtils.setCurrentScreenName(this, SCREEN_NAME, TAG);
|
|
|
startFingerprint();
|
|
|
ImageView imageView = (ImageView)findViewById(R.id.fingerprinticon);
|
|
|
- imageView.setImageDrawable(getDrawable(R.drawable.ic_fingerprint));
|
|
|
+ imageView.setImageDrawable(DisplayUtils.tintDrawable(R.drawable.ic_fingerprint, DisplayUtils.primaryColor()));
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -174,14 +180,10 @@ public class FingerprintActivity extends AppCompatActivity {
|
|
|
* @return 'True' when the key event was processed by this method.
|
|
|
*/
|
|
|
@Override
|
|
|
- public boolean onKeyDown(int keyCode, KeyEvent event){
|
|
|
- if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount()== 0){
|
|
|
- return true;
|
|
|
- }
|
|
|
- return super.onKeyDown(keyCode, event);
|
|
|
+ public boolean onKeyDown(int keyCode, KeyEvent event) {
|
|
|
+ return keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0 || super.onKeyDown(keyCode, event);
|
|
|
}
|
|
|
|
|
|
- @TargetApi(Build.VERSION_CODES.M)
|
|
|
protected void generateKey() {
|
|
|
try {
|
|
|
keyStore = KeyStore.getInstance(ANDROID_KEY_STORE);
|
|
@@ -192,11 +194,7 @@ public class FingerprintActivity extends AppCompatActivity {
|
|
|
KeyGenerator keyGenerator;
|
|
|
try {
|
|
|
keyGenerator = KeyGenerator.getInstance(KeyProperties.KEY_ALGORITHM_AES, ANDROID_KEY_STORE);
|
|
|
- } catch (NoSuchAlgorithmException | NoSuchProviderException e) {
|
|
|
- return;
|
|
|
- }
|
|
|
|
|
|
- try {
|
|
|
keyStore.load(null);
|
|
|
keyGenerator.init(
|
|
|
new KeyGenParameterSpec.Builder(
|
|
@@ -207,12 +205,12 @@ public class FingerprintActivity extends AppCompatActivity {
|
|
|
.setEncryptionPaddings(KeyProperties.ENCRYPTION_PADDING_PKCS7)
|
|
|
.build());
|
|
|
keyGenerator.generateKey();
|
|
|
- } catch (NoSuchAlgorithmException | InvalidAlgorithmParameterException | CertificateException | IOException e) {
|
|
|
- return;
|
|
|
+ } catch (NoSuchAlgorithmException | InvalidAlgorithmParameterException | CertificateException | IOException |
|
|
|
+ NoSuchProviderException e) {
|
|
|
+ Log_OC.e(TAG, "Exception: " + e.getMessage());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- @TargetApi(Build.VERSION_CODES.M)
|
|
|
public boolean cipherInit() {
|
|
|
try {
|
|
|
cipher = Cipher.getInstance(
|
|
@@ -240,8 +238,8 @@ public class FingerprintActivity extends AppCompatActivity {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private void fingerprintResult(boolean fingerok) {
|
|
|
- if (fingerok) {
|
|
|
+ private void fingerprintResult(boolean fingerOk) {
|
|
|
+ if (fingerOk) {
|
|
|
Intent resultIntent = new Intent();
|
|
|
resultIntent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
|
|
|
resultIntent.putExtra(KEY_CHECK_RESULT, true);
|
|
@@ -304,9 +302,9 @@ class FingerprintHandler extends FingerprintManager.AuthenticationCallback {
|
|
|
private Callback callback;
|
|
|
|
|
|
// Constructor
|
|
|
- FingerprintHandler(TextView mtext, Callback mcallback) {
|
|
|
- text = mtext;
|
|
|
- callback = mcallback;
|
|
|
+ FingerprintHandler(TextView mText, Callback mCallback) {
|
|
|
+ text = mText;
|
|
|
+ callback = mCallback;
|
|
|
}
|
|
|
|
|
|
@Override
|