为什么Android的LVL会锁定我自己的应用程序?

时间:2012-06-29 14:30:14

标签: android android-lvl

我最近在我的应用程序中添加了Android的LVL复制保护,至少可以说结果不稳定。

我在开发人员控制台中手动设置的每个测试响应似乎都按预期工作。但是,当我设置“正常响应”时,就是故障开始的地方。星期三,我首次上传了这个应用程序,在它上市后不久,就按照预期报告了许可。

然而,昨天下午没有任何警告,我的应用程序突然告诉我,我没有注意到。到目前为止,我没有对开发人员的控制台或代码进行任何更改。在发现这个之后,我立即取消发布,直到找到解决方案。我已经尝试清除应用的缓存和Google Play的缓存。

所以,我不知道我在这里做错了什么。我通过APK在Eclipse手机上安装了我自己的应用程序,而不是从市场上购买我自己的应用程序。要对LVL进行实时测试,我是否必须实际购买自己的应用程序,或者上传到开发人员的页面是否足够?我的LVL代码实际上是示例页面的副本,我在版本中尝试在进一步优化它之前尝试工作。我在这里发布了一些可识别的信息。

public class Main extends Activity {
private static final byte[] SALT = { <salt> };
private static final String B64 = "<base 64 key>";
private dbHelper db = new dbHelper(this);
private int requestCode;

LicenseCheckerCallback mLCC;
    LicenseChecker mC;
Handler mH;

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    checkL();
}

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (resultCode == 1) {
        startActivity(new Intent(Main.this, MainProfiler.class)); //callback for profile setup
        finish();
    }
}

protected void checkL() {
    String a = Settings.Secure.getString(getContentResolver(), Settings.Secure.ANDROID_ID); 
    mH = new Handler();
    mLCC = new settingsResolved();
    mC = new LicenseChecker(
            this, 
            new ServerManagedPolicy(this, new AESObfuscator(SALT, getPackageName(), a)),
            B64);
    mC.checkAccess(mLCC);
}

protected class settingsResolved implements LicenseCheckerCallback {
    @Override
    public void allow(int reason) {
        //the application is licensed properly
        if (isFinishing()) {
            // Don't update UI if Activity is finishing.
            return;
        }
        //authorize access
        startFromCallback();
    }

    @Override
    public void dontAllow(int reason) {
        //the application is not licensed properly
        Log.e("Main", "LVL Failed!");
        if (isFinishing()) {
            // Don't update UI if Activity is finishing.
            return;
        }
        failFromCallback(reason);
    }

    @Override
    public void applicationError(int errorCode) {
        //an error occurred
        Log.e("Main", "LVL Error!");
        if (isFinishing()) {
            // Don't update UI if Activity is finishing.
            return;
        }
        errorFromCallback(errorCode);
    }
}

private void startProcedure() {
    if (db.getRunOnce()) { //this is the first run
        Intent i = new Intent(Main.this, ProfileSetup.class);
        i.putExtra("NewProfile", true);
        startActivityForResult(i, requestCode);
    } else { //this is not the first run
        startActivity(new Intent(Main.this, MainProfiler.class));
        finish();
    }
}

private void failureState(int reason) {
    AlertDialog.Builder adb = new AlertDialog.Builder(this);
    adb.setTitle("LVL Error");
    adb.setCancelable(false);
    adb.setMessage(<license refused message>));
    adb.setPositiveButton("Exit", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            finish();
        }
    }); 
    if (reason != Policy.NOT_LICENSED) {// not NOT_LICENSED, meaning the error is not due to a licensing issue
        adb.setNegativeButton("Check Again", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                checkL();
            }
        });
    } else {
        adb.setNegativeButton("Google Play", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                Intent i = new Intent(Intent.ACTION_VIEW);
                i.setData(Uri.parse("market://details?id=<package name>"));
                startActivity(i);
                finish();
            }
        });
    }
    adb.create().show();
}

private void applicationError(int errorCode) {
    AlertDialog.Builder adb = new AlertDialog.Builder(this);
    adb.setTitle("LVL Error");
    adb.setCancelable(false);
    adb.setMessage(<application error message>);
    adb.setPositiveButton("Exit", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            finish();
        }
    }); 
    adb.create().show();
}

private void startFromCallback() {
    mH.post(new Runnable() {
        public void run() {
            Log.i("LVL", "License Pass!");
            startProcedure();
        }
    });
}

private void failFromCallback(final int reason) {
    mH.post(new Runnable() {
        public void run() {
            failureState(reason);
        }
    }); 
}

private void errorFromCallback(final int errorCode) {
    mH.post(new Runnable() {
        public void run() {
            applicationError(errorCode);
        }
    }); 
}

@Override
protected void onDestroy() {
    super.onDestroy();
    if (mC != null) {
        mC.onDestroy();
    }
}

}

1 个答案:

答案 0 :(得分:0)

是。设置“正常响应”时,您的测试帐户需要通过Google Play购买该应用。对我来说,我只是为测试帐户设置了“LICENSED”的响应。我太便宜了,不能买我自己的应用程序; - )