专业密钥的许可证检查

发布于 2024-12-13 19:25:27 字数 986 浏览 5 评论 0原文

因此,我想制作一个加载了完整功能的免费应用程序。在应用程序检测到许可的专业版密钥之前,专业版功能将被禁用。当然,我想让专业密钥使用 LVL 检查其许可证。虽然到目前为止我知道如何正确做事,但我不知道如何使专业版密钥与应用程序进行通信以启用专业版功能。

这是主要的应用程序代码(com.test.mainapp):

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    context = getApplicationContext();

    final PackageManager pacman = getPackageManager();
    final int signatureMatch = pacman.checkSignatures(getPackageName(),
            "com.test.mainapp_key");

    if (signatureMatch == PackageManager.SIGNATURE_MATCH) {
        Toast.makeText(context, "Pro key detected!", Toast.LENGTH_SHORT)
                .show();
    } else {
        Toast.makeText(context, "Free version", Toast.LENGTH_SHORT).show();
    }
}

虽然这可以阻止其他人为我的应用程序制作假密钥,但他们仍然可以在线与其他人共享密钥应用程序并且它会起作用。因为我们无法从另一个应用程序进行 LVL 检查,所以我希望许可证密钥应用程序检查它自己的许可证,如果正确,只有这样用户才能获得专业功能。我怎样才能让许可证密钥应用程序和主应用程序像这样相互通信?

例如,我想要实现的功能就像 Titanium Backup 所做的那样。

So I would like to make a free app with full functionality loaded in. The pro functionality will be disabled until the app detects a licensed pro key. And of course I would like to have the pro key check it's licence using LVL. While I know how to do things right until this point, I don't know how to make the pro key communicate with the app that it should enable the pro functionality.

Here's the main app code (com.test.mainapp):

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    context = getApplicationContext();

    final PackageManager pacman = getPackageManager();
    final int signatureMatch = pacman.checkSignatures(getPackageName(),
            "com.test.mainapp_key");

    if (signatureMatch == PackageManager.SIGNATURE_MATCH) {
        Toast.makeText(context, "Pro key detected!", Toast.LENGTH_SHORT)
                .show();
    } else {
        Toast.makeText(context, "Free version", Toast.LENGTH_SHORT).show();
    }
}

While this stops others making fake keys for my app, they still can share the key app online to others and it will work. Because we can't do the LVL check from another application, I would want the licence key app check it's own licence and if it's correct, only then the user gets the pro functionality. How can I have the licence key app and the main app communicate to each other like this?

The functionality I'm trying to get here is like Titanium Backup does, for example.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

稚然 2024-12-20 19:25:27

您可以在主应用程序和关键应用程序之间发送意图。如果您在密钥应用程序中使用 LVL,则回调示例如下:

private class MyLicenseCheckerCallback implements LicenseCheckerCallback {
    public void allow() {
        Log.i("Key", "License Accepted");
        Intent i = new Intent();
        i.setAction("intent.to.call.on.success");
        i.putExtra("licenseresult", 0);
        c.sendBroadcast(i);
        mChecker.onDestroy();
    }

    public void dontAllow() {
        Log.e("Key", "License Denied");
        Intent i = new Intent();
        i.setAction("intent.to.call.on.failure");
        i.putExtra("licenseresult", 1);
        c.sendBroadcast(i);
        mChecker.onDestroy();
    }

    public void applicationError(ApplicationErrorCode errorCode) {
        Log.i("Key", "LR Error");
        Intent i = new Intent();
        i.setAction("intent.to.call.on.error");
        i.putExtra("licenseresult", 2);
        c.sendBroadcast(i);
        mChecker.onDestroy();
    }
}

您将在两个应用程序中设置广播接收器以启动许可证检查并处理结果。例如,

public class License extends BroadcastReceiver {

@Override
public void onReceive(Context context, Intent intent) {

    if (intent.getAction().equals("intent.called.to.initiate.request")) {
                // Initiate the license request here (possibly using a service)
        return;
    }
}

} 

您应该使用基于证书的权限来限制对意图的访问,以防止其他应用程序能够发送欺骗性的“许可证成功”意图。

http://developer.android.com/reference/android/content/BroadcastReceiver.html#Permissions< /a>

简短版本。

在清单中定义权限

< permission android:name="my.package.LicenseCheck" android:protectionLevel="signature"/> 

在接收者声明中使用权限:

<receiver android:name="name.of.your.receiver" android:permission="my.package.LicenseCheck"> 
<intent-filter>
    <action android:name="name.of.intent"/>
</intent-filter>
</receiver>

You can send intents between the main app and the key app. If you are using LVL in the key app then an example callback would be:

private class MyLicenseCheckerCallback implements LicenseCheckerCallback {
    public void allow() {
        Log.i("Key", "License Accepted");
        Intent i = new Intent();
        i.setAction("intent.to.call.on.success");
        i.putExtra("licenseresult", 0);
        c.sendBroadcast(i);
        mChecker.onDestroy();
    }

    public void dontAllow() {
        Log.e("Key", "License Denied");
        Intent i = new Intent();
        i.setAction("intent.to.call.on.failure");
        i.putExtra("licenseresult", 1);
        c.sendBroadcast(i);
        mChecker.onDestroy();
    }

    public void applicationError(ApplicationErrorCode errorCode) {
        Log.i("Key", "LR Error");
        Intent i = new Intent();
        i.setAction("intent.to.call.on.error");
        i.putExtra("licenseresult", 2);
        c.sendBroadcast(i);
        mChecker.onDestroy();
    }
}

You would set up broadcast receivers in both apps to initiate the license check and handle the result. e.g.

public class License extends BroadcastReceiver {

@Override
public void onReceive(Context context, Intent intent) {

    if (intent.getAction().equals("intent.called.to.initiate.request")) {
                // Initiate the license request here (possibly using a service)
        return;
    }
}

} 

You should limit access to the intents using certificate based permissions to prevent other apps being able to send spoofed "License Success" intents.

http://developer.android.com/reference/android/content/BroadcastReceiver.html#Permissions

Short version.

Define permission in manifest

< permission android:name="my.package.LicenseCheck" android:protectionLevel="signature"/> 

Use Permission in receiver declaration:

<receiver android:name="name.of.your.receiver" android:permission="my.package.LicenseCheck"> 
<intent-filter>
    <action android:name="name.of.intent"/>
</intent-filter>
</receiver>
寄意 2024-12-20 19:25:27

@MainApp

<permission android:name="myapp.permission.RESPOND" protectionLevel="signature" />

<receiver android:name=".receiver.WhichHandlesValidationResponse" android:permisssion="myapp.permission.RESPOND">
    <intent-filter>
            <action android:name="myapp.action.VALIDATION_RESPONSE" />
    </intent-filter>
</receiver>

@KeyApp

<uses-permission android:name="myapp.permission.RESPOND" />

创建 LvlValidationHandler.class,其中包含:

Intent i = new Intent("myapp.action.VALIDATION_RESPONSE");
sendBroadcast(i);

@MainApp

<permission android:name="myapp.permission.RESPOND" protectionLevel="signature" />

<receiver android:name=".receiver.WhichHandlesValidationResponse" android:permisssion="myapp.permission.RESPOND">
    <intent-filter>
            <action android:name="myapp.action.VALIDATION_RESPONSE" />
    </intent-filter>
</receiver>

@KeyApp

<uses-permission android:name="myapp.permission.RESPOND" />

Create LvlValidationHandler.class that contains:

Intent i = new Intent("myapp.action.VALIDATION_RESPONSE");
sendBroadcast(i);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文