Simple Licensing for Android applications (JNI)

Source: Internet
Author: User

Recently has been doing a company's Android development framework, including so library, close to the end, the leader asked a demand, the use of the framework of the developers must have our authorization to be able to, but the other release of the app can not be restricted by this authorization-or all applications to authorize it is troublesome.

Analysis:

Since it is restricted to developers, it is necessary to differentiate between the debug version and release version, that is, the framework's authorization limit function is only valid for the debug version, and the release version is not valid, and then need a debug device a unique ID, so that the authorization code is bound to the fixed device, As long as there is a new commissioning equipment to require a new authorization code, the general company is more than 10 devices, the application level is fully acceptable.

Ideas:

Because this framework requires the support of so libraries, validation can be done in the int jni_onload (javavm* JVM, void* reserved) method when the so library is loaded.

With regard to the difference between debug and release versions, the Android system provides a debugable attribute that can be implemented as long as it is run directly or debugged from an integrated environment of eclipse or ADT to determine if it is a debug version;

With regard to the ID of the Android device, Android itself provides several kinds of ID, I end up using the Security class ID, Settings.Secure.getString (contentresolver, Settings.Secure.ANDROID_ID), this ID is automatically generated when the Android device is first launched and may change if the machine is being brushed.

The location of the authorization code is placed in the Androidmanifest application node, add a meta-node, and can customize the name of the information, then now is the preparation is complete.

Realize:

1. The JNI layer int jni_onload (javavm* JVM, void* reserved) completes the validation

2.JNI layer to determine whether the program is the debug version, in order to prevent the Java code is anti-compilation, so get debug properties and judgments are in the JNI layer, you can refer to the Java layer of the following code, the code will be adapted to C + + code:

public Boolean Isdebugmode () {ApplicationInfo info = this.getapplicationinfo (); return (0!= (info.flags) & applicationinfo.flag_debuggable));}

3.JNI layer Gets the unique ID of the Android device, you can refer to the Java code to adapt the code to C + + code :

String id = Settings.Secure.getString (this.mainActivity.getContentResolver (), Settings.Secure.ANDROID_ID);

4. Get the authorization code in meta in manifest, this does not need to be implemented in the JNI layer, can be obtained in the Java layer, and then passed to the JNI layer, the reference is the following Java code:

ApplicationInfo Info=context.getpackagemanager (). Getapplicationinfo (Con.getpackagename (), PackageManager.GET_ Meta_data); String key=info.metadata.getstring ("Permissionkey");


5. The next step is to encrypt the decryption and finally the appropriate add-on shell of the trade-offs, no longer elaborate.


Simple Licensing for Android applications (JNI)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.