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

JNIEXPORT jlong JNICALL Java_com_example_demoactivity_inActivity_DeviceSerialNumber
  (JNIEnv *env, jclass cls, jbyteArray ppDeviceSN, jintArray lpDeviceSNLen)
  {
	unsigned char *SN;
	unsigned char *SNLen;
	
	//unsigned char m[]="28377463";
	//unsigned char *string=m;
	jboolean result;
	SN=(unsigned char *)env->GetByteArrayElements(ppDeviceSN,&result);
	SNLen=(unsigned char *)env->GetIntArrayElements(lpDeviceSNLen,&result);
	
	
	char tempSN[100];
	long tempSNLen = 0;
	long ret;
	ret = GetDeviceSerialNumber(tempSN, &tempSNLen);
	__android_log_print(ANDROID_LOG_INFO, "ProjectName", "ret= %04x", ret);
	
	
	__android_log_print(ANDROID_LOG_INFO, "ProjectName", "tempSN= %s", tempSN);

	strcpy((char *)SN,tempSN);
	SNLen[0]=tempSNLen;
	
	env->ReleaseIntArrayElements(lpDeviceSNLen,(jint*)SNLen,0);
	env->ReleaseByteArrayElements(ppDeviceSN,(jbyte*)SN,0);
  return 0;
  }
  
  
  JNIEXPORT jlong JNICALL Java_com_example_demoactivity_inActivity_RandomNumber
  (JNIEnv *env, jclass cls, jlong a,jintArray randomLen, jbyteArray random)
  {
  
	unsigned char string[10];
	unsigned char *random_Len;
	unsigned char *randomC;
	char temp[33];
	memset(temp, 0x00, 33);
	jboolean result;
	randomC=(unsigned char *)env->GetByteArrayElements(random,&result);
	random_Len=(unsigned char *)env->GetIntArrayElements(randomLen,&result);
	
	int temprandomLen;
	char temprandom[100];
	long ret;
	temprandomLen=(int)a;

	ret=GetRandomNumber(temprandomLen,temprandom);
	strcpy((char *)randomC,temprandom);
	*random_Len=temprandomLen;
	
	
	env->ReleaseIntArrayElements(randomLen,(jint*)random_Len,0);
	env->ReleaseByteArrayElements(random,(jbyte*)randomC,0);
	
	return 0;
  }