0

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

我在开发人员控制台中手动设置的每个测试响应似乎都按预期工作。但是,当我设置“正常响应”时,问题就出现了。周三,我第一次上传了这个应用程序,在它上市后不久,它按预期报告了 LICENSED。

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

所以,我不知道我在这里做错了什么。我通过 Eclipse 中的 APK 在手机上安装了自己的应用程序,而不是从市场上购买自己的应用程序。要进行 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();
    }
}

}

4

1 回答 1

0

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

于 2012-06-29T14:54:18.433 回答