diff --git a/app/src/main/java/com/hippo/ehviewer/ui/SetSecurityActivity.java b/app/src/main/java/com/hippo/ehviewer/ui/SetSecurityActivity.java index e17ca11a0..648be9d2a 100755 --- a/app/src/main/java/com/hippo/ehviewer/ui/SetSecurityActivity.java +++ b/app/src/main/java/com/hippo/ehviewer/ui/SetSecurityActivity.java @@ -60,11 +60,17 @@ protected void onCreate(@Nullable Bundle savedInstanceState) { if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) { FingerprintManager fingerprintManager = getSystemService(FingerprintManager.class); - // The line below prevents the false positive inspection from Android Studio - // noinspection ResourceType - if (fingerprintManager.hasEnrolledFingerprints()) { - mFingerprint.setVisibility(View.VISIBLE); - mFingerprint.setChecked(Settings.getEnableFingerprint()); + try { + // The line below prevents the false positive inspection from Android Studio + // noinspection ResourceType + if (fingerprintManager.isHardwareDetected() && + fingerprintManager.hasEnrolledFingerprints()) { + mFingerprint.setVisibility(View.VISIBLE); + mFingerprint.setChecked(Settings.getEnableFingerprint()); + } + } catch (SecurityException e) { + // empty + // Some Samsung devices throw this on hasEnrolledFingerprints(). } } diff --git a/app/src/main/java/com/hippo/ehviewer/ui/scene/SecurityScene.java b/app/src/main/java/com/hippo/ehviewer/ui/scene/SecurityScene.java index 57ce348cd..2f0cb7a39 100755 --- a/app/src/main/java/com/hippo/ehviewer/ui/scene/SecurityScene.java +++ b/app/src/main/java/com/hippo/ehviewer/ui/scene/SecurityScene.java @@ -28,6 +28,7 @@ import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; +import android.widget.TextView; import com.hippo.ehviewer.R; import com.hippo.ehviewer.Settings; @@ -47,6 +48,7 @@ public class SecurityScene extends SolidScene implements private static final int MAX_RETRY_TIMES = 5; private static final long ERROR_TIMEOUT_MILLIS = 1200; + private static final long UNRECOVERABLE_ERROR_TIMEOUT_MILLIS = ERROR_TIMEOUT_MILLIS * 2; private static final long SUCCESS_DELAY_MILLIS = 100; private static final String KEY_RETRY_TIMES = "retry_times"; @@ -54,6 +56,7 @@ public class SecurityScene extends SolidScene implements @Nullable private LockPatternView mPatternView; private ImageView mFingerprintIcon; + private TextView mFingerprintText; private SensorManager mSensorManager; private Sensor mAccelerometer; @@ -111,7 +114,8 @@ public void onResume() { mSensorManager.registerListener(mShakeDetector, mAccelerometer, SensorManager.SENSOR_DELAY_UI); } - if (isFingerprintAuthAvailable()) { + // Redundant SDK version checking prevents false positive inspection + if (isFingerprintAuthAvailable() && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { mFingerprintCancellationSignal = new CancellationSignal(); // The line below prevents the false positive inspection from Android Studio // noinspection ResourceType @@ -119,6 +123,8 @@ public void onResume() { new FingerprintManager.AuthenticationCallback() { @Override public void onAuthenticationError(int errMsgId, CharSequence errString) { + mFingerprintText.setText(errString); + mFingerprintText.setVisibility(View.VISIBLE); fingerprintError(true); } @@ -151,7 +157,9 @@ public void onPause() { if (null != mShakeDetector) { mSensorManager.unregisterListener(mShakeDetector); } - if (isFingerprintAuthAvailable() && mFingerprintCancellationSignal != null) { + // Redundant SDK version checking prevents false positive inspection + if (isFingerprintAuthAvailable() && mFingerprintCancellationSignal != null + && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { mFingerprintCancellationSignal.cancel(); mFingerprintCancellationSignal = null; } @@ -173,9 +181,11 @@ public View onCreateView2(LayoutInflater inflater, mPatternView.setOnPatternListener(this); mFingerprintIcon = (ImageView) ViewUtils.$$(view, R.id.fingerprint_icon); + mFingerprintText = (TextView) ViewUtils.$$(view, R.id.fingerprint_text); if (Settings.getEnableFingerprint() && isFingerprintAuthAvailable()) { mFingerprintIcon.setVisibility(View.VISIBLE); mFingerprintIcon.setImageResource(R.drawable.ic_fp_40px); + mFingerprintText.setVisibility(View.INVISIBLE); } return view; } @@ -234,11 +244,16 @@ public void onShake(int count) { private boolean isFingerprintAuthAvailable() { // The line below prevents the false positive inspection from Android Studio // noinspection ResourceType - return Build.VERSION.SDK_INT >= Build.VERSION_CODES.M - && Settings.getEnableFingerprint() - && mFingerprintManager != null - && mFingerprintManager.isHardwareDetected() - && mFingerprintManager.hasEnrolledFingerprints(); + try { + return Build.VERSION.SDK_INT >= Build.VERSION_CODES.M + && Settings.getEnableFingerprint() + && mFingerprintManager != null + && mFingerprintManager.isHardwareDetected() + && mFingerprintManager.hasEnrolledFingerprints(); + } catch (SecurityException e) { + // Some Samsung devices throw this on hasEnrolledFingerprints(). + return false; + } } private Runnable mResetFingerprintRunnable = new Runnable() { @@ -246,6 +261,8 @@ private boolean isFingerprintAuthAvailable() { public void run() { if (mFingerprintIcon != null) mFingerprintIcon.setImageResource(R.drawable.ic_fp_40px); + if (mFingerprintText != null) + mFingerprintText.setVisibility(View.INVISIBLE); } }; @@ -257,9 +274,12 @@ private void fingerprintError(boolean unrecoverable) { mFingerprintIcon.postDelayed(new Runnable() { @Override public void run() { - mFingerprintIcon.setVisibility(View.INVISIBLE); + if (mFingerprintIcon != null) + mFingerprintIcon.setVisibility(View.INVISIBLE); + if (mFingerprintText != null) + mFingerprintText.setVisibility(View.INVISIBLE); } - }, ERROR_TIMEOUT_MILLIS); + }, UNRECOVERABLE_ERROR_TIMEOUT_MILLIS); } else { mFingerprintIcon.postDelayed(mResetFingerprintRunnable, ERROR_TIMEOUT_MILLIS); } diff --git a/app/src/main/res/layout/scene_security.xml b/app/src/main/res/layout/scene_security.xml index f18817944..ccfda09ca 100755 --- a/app/src/main/res/layout/scene_security.xml +++ b/app/src/main/res/layout/scene_security.xml @@ -27,7 +27,7 @@ android:layout_gravity="center" android:layout_margin="32dp" app:maxWidth="320dp" - app:maxHeight="360dp"> + app:maxHeight="380dp"> + + diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml old mode 100644 new mode 100755 index 5bb42c6ac..00ed85a7e --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -114,4 +114,7 @@ @color/colorPrimary @color/red_500 + + @color/red_500 +