#include<stdio.h>
#include<stdlib.h>
#include "com_example_demoactivity_PinActivity.h"
#include <Library/UniMate_Android.h>
#include <android/log.h>


JNIEXPORT jlong JNICALL Java_com_example_demoactivity_PinActivity_VerifyPwd
  (JNIEnv *env, jclass cls, jbyteArray OldPwd, jint OldPwdLen)
  {
	unsigned char *Old_Pwd;
	
	jboolean result;
	Old_Pwd=(unsigned char *)env->GetByteArrayElements(OldPwd,&result);
	int OldPwd_Len=OldPwdLen;
	Old_Pwd[OldPwd_Len]=0x00;
	
	__android_log_print(ANDROID_LOG_INFO, "ProjectName", "Old_Pwd= %s", Old_Pwd);

	long ret;
	ret=VerifyPassword((char *)Old_Pwd);
	__android_log_print(ANDROID_LOG_INFO, "ProjectName", "ret= %04x", ret);
	if(ret!=0)
	{
		return 1;
	}
	
	env->ReleaseByteArrayElements(OldPwd,(jbyte*)Old_Pwd,0);
	
	return 0;
  }

  
  
JNIEXPORT jlong JNICALL Java_com_example_demoactivity_PinActivity_ChangePwd
  (JNIEnv *env, jclass cls, jbyteArray OldPassword, jint OldPasswordLen, jbyteArray NewPassword, jint NewPasswordLen)
  {

	unsigned char *Old_Password;
	unsigned char *New_Password;
	
	jboolean result;
  
	Old_Password=(unsigned char *)env->GetByteArrayElements(OldPassword,&result);
	New_Password=(unsigned char *)env->GetByteArrayElements(NewPassword,&result);
	int NewPassword_Len=NewPasswordLen;
	int OldPassword_Len=OldPasswordLen;
	Old_Password[OldPassword_Len]=0x00;
	New_Password[NewPassword_Len]=0x00;
	
	__android_log_print(ANDROID_LOG_INFO, "ProjectName", "Old_Password= %s", Old_Password);
	__android_log_print(ANDROID_LOG_INFO, "ProjectName", "New_Password= %s", New_Password);
	long ret;
	
	ret=ChangePassword(NULL,0,(char *)Old_Password,(char *)New_Password);
	__android_log_print(ANDROID_LOG_INFO, "ProjectName", "ret= %04x", ret);
	if(ret!=0)
	{
		return 1;
	}
	
	env->ReleaseByteArrayElements(OldPassword,(jbyte*)Old_Password,0);
	env->ReleaseByteArrayElements(NewPassword,(jbyte*)New_Password,0);
	
	return 0;
  }
  
  
  
JNIEXPORT jlong JNICALL Java_com_example_demoactivity_PinActivity_ResetPwd
  (JNIEnv *env, jclass cls, jbyteArray NewPwd, jint NewPwdLen)
  {
	unsigned char *New_Pwd;
	
	jboolean result;
	 
	 New_Pwd=(unsigned char *)env->GetByteArrayElements(NewPwd,&result);
	 int NewPwd_Len=NewPwdLen;
	 New_Pwd[NewPwd_Len]=0x00;
	 __android_log_print(ANDROID_LOG_INFO, "ProjectName", "New_Pwd= %s", New_Pwd);
	 long ret;
	 ret=ResetPassword((char *)New_Pwd);
	 __android_log_print(ANDROID_LOG_INFO, "ProjectName", "ret= %04x", ret);
	if(ret!=0)
	 {
		return 1;
	 }
	
	env->ReleaseByteArrayElements(NewPwd,(jbyte*)New_Pwd,0);
	
	 
  
	return 0;
  }