@ -2,11 +2,11 @@ package com.gmeremit.online.gmeremittance_native.transactionpasspromt.view;
import android.annotation.SuppressLint ;
import android.app.Activity ;
import android.content.Context ;
import android.content.Intent ;
import android.content.pm.ActivityInfo ;
import android.graphics.Rect ;
import android.graphics.drawable.AnimatedVectorDrawable ;
import android.graphics.drawable.Drawable ;
import android.os.Build ;
import android.os.Bundle ;
import android.os.CountDownTimer ;
@ -29,6 +29,7 @@ import android.widget.ImageView;
import android.widget.RelativeLayout ;
import android.widget.TextView ;
import com.gmeremit.online.gmeremittance_native.GmeApplication ;
import com.gmeremit.online.gmeremittance_native.R ;
import com.gmeremit.online.gmeremittance_native.base.BaseActivity ;
import com.gmeremit.online.gmeremittance_native.customwidgets.GmeErrorTextView ;
@ -38,12 +39,21 @@ import com.gmeremit.online.gmeremittance_native.utils.security.SecurityUtils;
import com.gmeremit.online.gmeremittance_native.utils.security.securitykeypad.SecurityKeyboardManager ;
import com.gmeremit.online.gmeremittance_native.utils.security.securitykeypad.SecurityKeyboardView ;
import com.gmeremit.online.gmeremittance_native.utils.security.securitykeypad.SecurityKeypadRequestParamBuilder ;
import com.mtramin.rxfingerprint.RxFingerprint ;
import com.mtramin.rxfingerprint.data.FingerprintDecryptionResult ;
import com.mtramin.rxfingerprint.data.FingerprintEncryptionResult ;
import com.softsecurity.transkey.TransKeyActivity ;
import java.util.Locale ;
import butterknife.BindView ;
import butterknife.ButterKnife ;
import io.reactivex.Observable ;
import io.reactivex.ObservableSource ;
import io.reactivex.Observer ;
import io.reactivex.disposables.Disposable ;
import io.reactivex.functions.Function ;
import io.reactivex.observers.DisposableObserver ;
public class TransactionPasswordPromptActivity extends BaseActivity implements SecurityKeyboardView . SecurityKeyboardFocusStateListener , TransactionPasswordPromptV2PresenterInterface . TransactionPasswordPromptV2ContractInterface , View . OnClickListener {
@ -91,6 +101,9 @@ public class TransactionPasswordPromptActivity extends BaseActivity implements S
private CountDownTimer countDownTimer ;
private AnimatedVectorDrawable fingerPrintAVD ;
private AnimatedVectorDrawableCompat fingerPrintAVDCompat ;
private Disposable fingerPrintReaderSubs ;
String TAG = "FingerPrintObserver" ;
@Override
protected void onCreate ( Bundle savedInstanceState ) {
@ -169,14 +182,14 @@ public class TransactionPasswordPromptActivity extends BaseActivity implements S
}
private void setupFingerPrintIconIfRequired ( ) {
/ / TODO if biometric is on
if ( SecurityUtils . doesAppHasBiometricFeature ( this ) & & presenter . checkIfUserHasEnabledBiometricAuth ( ) ) {
if ( presenter . checkIfUserHasEnabledBiometricAuth ( ) ) {
orTextView . setVisibility ( View . VISIBLE ) ;
if ( Build . VERSION . SDK_INT > = Build . VERSION_CODES . LOLLIPOP ) {
fingerPrintAVD = ( AnimatedVectorDrawable ) ContextCompat . getDrawable ( this , R . drawable . avd_fingerprint_off_to_on ) ;
} else {
fingerPrintAVDCompat = ( AnimatedVectorDrawableCompat ) ContextCompat . getDrawable ( this , R . drawable . avd_fingerprint_off_to_on ) ;
}
} else {
passwordPromptImageView . setBackgroundResource ( R . drawable . ic_penny_test_pending ) ;
}
@ -222,6 +235,8 @@ public class TransactionPasswordPromptActivity extends BaseActivity implements S
securityKeyboardView . setSecurityKeyboardFocusStateListener ( this ) ;
if ( checkIfRequiredOTPScreen ( ) )
resendRequest . setOnClickListener ( this ) ;
else if ( presenter . checkIfUserHasEnabledBiometricAuth ( ) )
fingerPrintReaderSubs = startObservingFingerPrintScanner ( ) ;
}
@Override
@ -230,35 +245,63 @@ public class TransactionPasswordPromptActivity extends BaseActivity implements S
securityKeyboardView . setSecurityKeyboardFocusStateListener ( null ) ;
if ( checkIfRequiredOTPScreen ( ) )
resendRequest . setOnClickListener ( null ) ;
if ( fingerPrintReaderSubs ! = null & & ! fingerPrintReaderSubs . isDisposed ( ) )
fingerPrintReaderSubs . dispose ( ) ;
}
@Override
protected void onResume ( ) {
super . onResume ( ) ;
new Handler ( ) . postDelayed ( this : : animateFingerPrintAppearAnimationIfRequired , 400 ) ;
animateFingerPrintAppearAnimationIfRequired ( true ) ;
}
@Override
protected void onPause ( ) {
super . onPause ( ) ;
if ( ! checkIfRequiredOTPScreen ( ) & & SecurityUtils . doesAppHasBiometricFeature ( this ) & & presenter . checkIfUserHasEnabledBiometricAuth ( ) )
new Handler ( ) . postDelayed ( ( ) - > passwordPromptImageView . setImageDrawable ( null ) , 200 ) ;
animateFingerPrintAppearAnimationIfRequired ( false ) ;
}
@SuppressLint ( "NewApi" )
private void animateFingerPrintAppearAnimationIfRequired ( ) {
if ( ! checkIfRequiredOTPScreen ( ) ) {
if ( fingerPrintAVD ! = null & & ! fingerPrintAVD . isRunning ( ) ) {
passwordPromptImageView . setImageDrawable ( fingerPrintAVD ) ;
fingerPrintAVD . start ( ) ;
} else if ( fingerPrintAVDCompat ! = null & & ! fingerPrintAVDCompat . isRunning ( ) ) {
passwordPromptImageView . setImageDrawable ( fingerPrintAVDCompat ) ;
fingerPrintAVDCompat . start ( ) ;
}
private void animateFingerPrintAppearAnimationIfRequired ( boolean action ) {
if ( ! checkIfRequiredOTPScreen ( ) & & presenter . checkIfUserHasEnabledBiometricAuth ( ) & & action ) {
new Handler ( ) . postDelayed ( ( ) - > {
if ( fingerPrintAVD ! = null & & ! fingerPrintAVD . isRunning ( ) ) {
passwordPromptImageView . setImageDrawable ( fingerPrintAVD ) ;
fingerPrintAVD . start ( ) ;
} else if ( fingerPrintAVDCompat ! = null & & ! fingerPrintAVDCompat . isRunning ( ) ) {
passwordPromptImageView . setImageDrawable ( fingerPrintAVDCompat ) ;
fingerPrintAVDCompat . start ( ) ;
}
} , 400 ) ;
} else {
new Handler ( ) . postDelayed ( ( ) - > {
passwordPromptImageView . setImageDrawable ( null ) ;
} , 200 ) ;
}
}
private Disposable startObservingFingerPrintScanner ( ) {
return SecurityUtils . decryptSecret ( this , presenter . getSecretKey ( ) )
. flatMap ( authentication - > {
Log . d ( TAG , authentication . getResult ( ) . toString ( ) ) ;
switch ( authentication . getResult ( ) ) {
case FAILED :
return io . reactivex . Observable . error ( new SecurityUtils . FailedFingerPrintException ( authentication . getMessage ( ) ) ) ;
case HELP :
return io . reactivex . Observable . error ( new SecurityUtils . SensorNotReadyException ( authentication . getMessage ( ) ) ) ;
case AUTHENTICATED :
return Observable . just ( authentication ) ;
default :
return io . reactivex . Observable . error ( new Throwable ( authentication . getMessage ( ) ) ) ;
}
} )
. subscribeWith ( new FingerPrintScannerObserver ( ) ) ;
}
@Override
public void onSecurityViewRecievedFocus ( ) {
if ( securityKeyboardManager ! = null & & ! securityKeyboardManager . isKeyboardVisible ( ) )
@ -338,6 +381,13 @@ public class TransactionPasswordPromptActivity extends BaseActivity implements S
}
}
@Override
public Context getContext ( ) {
return this ;
}
@Override
public void onBackPressed ( ) {
@ -416,4 +466,26 @@ public class TransactionPasswordPromptActivity extends BaseActivity implements S
}
class FingerPrintScannerObserver extends DisposableObserver < FingerprintDecryptionResult > {
@Override
public void onNext ( FingerprintDecryptionResult fingerprintAuthenticationResult ) {
Intent returnIntent = new Intent ( ) ;
returnIntent . putExtra ( TRANSACTION_PWD_ENC_DATA , fingerprintAuthenticationResult . getDecrypted ( ) ) ;
setResult ( Activity . RESULT_OK , returnIntent ) ;
finish ( ) ;
}
@Override
public void onError ( Throwable e ) {
}
@Override
public void onComplete ( ) {
}
}
}