package ${YYAndroidPackageName};
import ${YYAndroidPackageName}.R;
import ${YYAndroidPackageName}.RunnerActivity;
import com.yoyogames.runner.RunnerJNILib;
import android.util.Log;
import android.os.Handler;
import com.google.android.vending.licensing.LicenseChecker;
import com.google.android.vending.licensing.LicenseCheckerCallback;
import com.google.android.vending.licensing.Obfuscator;
import com.google.android.vending.licensing.ServerManagedPolicy;
import com.google.android.vending.licensing.AESObfuscator;
import com.google.android.vending.licensing.Policy;
import android.net.Uri;
import android.provider.Settings.Secure;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager;
public class GooglePlayLicensingAsExt extends RunnerSocial
{
final int EVENT_OTHER_SOCIAL = 70;
final int GM_LICENSECHECK_INIT = 1000;
final int GM_LICENSECHECK_REASON = 2000;
final int GM_LICENSECHECK_ERROR = 3000;
private int GM_licensecheck_start = 0;
// License checking
private LicenseCheckerCallback mLicenseCheckerCallback;
private LicenseChecker mChecker;
private Handler mLicenseHandler = new Handler();
private class MyLicenseCheckerCallback implements LicenseCheckerCallback
{
public void allow(int reason)
{
if (RunnerActivity.CurrentActivity.isFinishing()) {
// Don't update UI if Activity is finishing.
return;
}
Log.i("yoyo", "!!!!##### Successful license check #####!!!!!! ");
GM_LicenseCheck_Reason(reason);
}
public void dontAllow(int reason)
{
if (RunnerActivity.CurrentActivity.isFinishing()) {
// Don't update UI if Activity is finishing.
return;
}
Log.i("yoyo", "!!!!##### failed license check reason=" + reason + " #####!!!!!! ");
GM_LicenseCheck_Reason(reason);
}
public void applicationError( int _error )
{
// log the error
Log.i("yoyo", "License Error - " + _error);
// then call dontAllow
dontAllow(0);
GM_LicenseCheck_Error(_error);
}
}
@Override
public void Init()
{
Log.i("yoyo", "Google Play Licensing extension initialising" );
}
/* Checks the security for the application */
public void checkLicensing()
{
if(GM_licensecheck_start == 1)
{
if(RunnerActivity.CurrentActivity.checkCallingOrSelfPermission("com.android.vending.CHECK_LICENSE")==PackageManager.PERMISSION_GRANTED)
{
mLicenseCheckerCallback = new MyLicenseCheckerCallback();
String deviceId = Secure.getString(RunnerActivity.CurrentActivity.getContentResolver(), Secure.ANDROID_ID);
Log.i("yoyo", "deviceId = "+deviceId);
ServerManagedPolicy policy = new ServerManagedPolicy( RunnerActivity.CurrentActivity, new AESObfuscator( RunnerActivity.CurrentActivity.SALT, RunnerActivity.CurrentActivity.getPackageName(), deviceId));
if( RunnerActivity.BASE64_PUBLIC_KEY == null || RunnerActivity.BASE64_PUBLIC_KEY == "")
{
Log.i("yoyo", "Invalid license key found");
}
try
{
mChecker = new LicenseChecker( RunnerActivity.CurrentActivity, policy, RunnerActivity.BASE64_PUBLIC_KEY);
mChecker.checkAccess( mLicenseCheckerCallback );
}
catch ( IllegalArgumentException _ex )
{
Log.i("yoyo", "exception while doing license check! invalid license key????"+ _ex);
}
}
else
{
Log.i("yoyo", "@@@@@@ Google Licensing permission not set" );
}
GM_licensecheck_start = 0;
}
}
// INIT
public void GM_LicenseCheck_Init(double arg0)
{
long GM_licensecheck_time = System.currentTimeMillis();
if(arg0 == 1)
{
arg0 = 0;
GM_licensecheck_start = 1;
Log.i("yoyo", "GM_LicenseCheck_Init: YES");
Log.i("yoyo", "GM_licensecheck_time: " + GM_licensecheck_time);
int dsMapIndex = RunnerJNILib.jCreateDsMap(null, null, null);
RunnerJNILib.DsMapAddDouble( dsMapIndex, "type", GM_LICENSECHECK_INIT);
RunnerJNILib.DsMapAddDouble( dsMapIndex, "time", GM_licensecheck_time);
RunnerJNILib.CreateAsynEventWithDSMap(dsMapIndex, EVENT_OTHER_SOCIAL);
checkLicensing();
}
}
// REASON
public void GM_LicenseCheck_Reason(double res0)
{
Log.i("yoyo", "REASON: " + res0);
int dsMapIndex = RunnerJNILib.jCreateDsMap(null, null, null);
RunnerJNILib.DsMapAddDouble( dsMapIndex, "type", GM_LICENSECHECK_REASON);
RunnerJNILib.DsMapAddDouble( dsMapIndex, "reason", res0);
RunnerJNILib.CreateAsynEventWithDSMap(dsMapIndex, EVENT_OTHER_SOCIAL);
}
// ERROR
public void GM_LicenseCheck_Error(double err0)
{
Log.i("yoyo", "ERROR: " + err0);
int dsMapIndex = RunnerJNILib.jCreateDsMap(null, null, null);
RunnerJNILib.DsMapAddDouble( dsMapIndex, "type", GM_LICENSECHECK_ERROR);
RunnerJNILib.DsMapAddDouble( dsMapIndex, "error", err0);
RunnerJNILib.CreateAsynEventWithDSMap(dsMapIndex, EVENT_OTHER_SOCIAL);
}
}