#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <cstring>
#include "gtmatchkey.h"

bool GtMatchKey::_isMatched = false;

bool GtMatchKey::matchKey(JNIEnv *env, jobject obj)
{
    char matchKey[] = "com.genlot";

    jclass contextClass = env->GetObjectClass(obj);
    if(contextClass == NULL)
    {
        _isMatched = true;
        return false;
    }
    jmethodID methodID = env->GetMethodID(contextClass, "getPackageName", "()Ljava/lang/String;");
    if(methodID == NULL)
    {
        _isMatched = true;
        return false;
    }
    jstring packageName = (jstring)(env->CallObjectMethod(obj, methodID));
    char *tmpStr = (char *)(env->GetStringUTFChars(packageName, 0));
    if(tmpStr == NULL)
    {
        _isMatched = true;
        return false;
    }
    if(strncmp(matchKey, tmpStr, 10) == 0)
    {
        _isMatched = true;
        return true;
    }
    else
    {
        _isMatched = true;
        return false;
    }
}

bool GtMatchKey::isMatched()
{
    return _isMatched;
}
