VIVEPORT Android Licensing

Viveport offers a network-based licensing service that lets your application obtain licensing status for the current user at run time. Your application can determine whether the current user is licensed to use your application.

 

 

 

Requirements

1.       The Viveport client is installed on user’s device and the device is running Android 5.0 (API level 21) or higher.

2.       User needs to have an HTC Account and sign in.

3.       User’s device can access the DRM server over the network.

 

 

 

Licensing Overview

The Viveport Android application licensing is composed of drmlib, drm_service and drm_server. You only need to add drmlib to your application. The drmlib is an Android aar library that handles all of the verifications and communication with the drm_service, and drm_service handles communication with drm_server.

 

The drmlib binds drm_service to get signed license data for current user from drm_server, then checks the license signature and validity for your application. The drmlib has license caching when there is no network connectivity. The drm_service is provided by Viveport client and user must install Viveport client to get license from drm_server.

 

To ensure the security of license data, the licensing server generates a RSA key pair for your application when you add your application to Viveport developer console (https://developer.viveport.com/console). The RSA key pair is shared exclusively between you and the drm_server. The server retains the private key internally and exposes the public key to you. You must embed the public key in your application source code. The drm_server uses private key to sign license data for your application. When your application receives a signed license data, drmlib uses the embedded public key to verify the license data.

 

drm_chart

 

 

 

Test ID and Test Key

You can use the Test ID and Test Key to verify the drmlib integration.All users will be allowed to use your application if you integrate the drmlib correctly.

 


ViveportID
= "bd67b286-aafc-449d-8896-bb7e9b351876"

ViveportKey = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDFypCg0OHfBC+VZLSWPbNSgDo9qg/yQORDwGy1rKIboMj3IXn4Zy6h6bgn8k
iMY7VI0lPwIj9lijT3ZxkzuTsI5GsK//Y1bqeTol4OUFR+47gj+TUuekAS2WMtglKox+/7mO6CA1gV+jZrAKo6YSVmPd+oFsgisRcqEgNh5MIURQIDAQAB"

 

 

 

 

Adding Licensing to Your Application

The following steps use Android Studio. You can refer to the drmsample source code and copy the Snippets to your source code.

 

1.       Add your application to Viveport developer console (https://developer.viveport.com/console) and get the ViveportID & ViveportKey of your application.

 

2.       Copy “drmsample\libs\drmlib.aar” to “your_project\libs\”

 

3.       Add drmlib dependency to “build.gradle” file.


        repositories { flatDir {dirs
'libs'} }

        dependencies { compile(name: 'drmlib', ext: 'aar') }

 

 

4.       Import drmlib classes to your java file.


        import
com.htc.store.licensing.LicenseChecker;

        import com.htc.store.licensing.LicenseCheckerCallback;

 

 

5.       Implement your LicenseCheckerCallback class. Please notice that the LicenseCheckerCallback methods will be invoked from a background thread. You can create a Handler in the UI thread and have your callback methods post to the Handler if necessary.

The LicenseCheckerCallback has 3 callback methods.


allow(): User is licensed to use your application.

 

deny(int denyCode): You can check the denyCode and do the appropriate action.


DENY_NOT_LICENSED: User is not licensed to use your application.


DENY_RETRY: Your application cannot get license response data from drm_service. It was probably due to network or server problem, so we should give the user a chance to retry.


DENY_NOT_SIGN_IN: User did not add or sign in to HTC Account.


DENY_NO_SERVICE: Cannot bind DRM Service. Viveport client is not installed

 

applicationError(int errorCode): Error in application code. Please examine the errorCode and fix the error.

 

ERROR_INVALID_PUBLIC_KEY: Invalid public key.

 

ERROR_INVALID_APP_ID: Cannot find this application in Viveport.

 

Example:


        private class
MyLicenseCheckerCallback implements LicenseCheckerCallback {

 

                public void allow() {

                    log("allow"); // Should allow user’s access.

                }

 

                public void deny(int denyCode)

                {

                    switch (denyCode)

                    {

                        case DENY_NOT_LICENSED:

                            log("not licensed");

                            break;

 

                        case DENY_RETRY:

                            log("please retry");

                            break;

 

                        case DENY_NOT_SIGN_IN:

                            log("please sign in");

                            break;

 

                        case DENY_NO_SERVICE:

                            log("please install Viveport");

                            break;

 

                    }

                }

 

                public void applicationError(int errorCode) {

                    // Please examine the error code and fix the error.

                    log("application_error: " + errorCode);

                }

    }

 

 

6.  Declare ViveportID, ViveportKey, LicenseChecker and your LicenseCheckerCallback object in your MainActivity class.

 


        private
static final String sViveportID = "your-viveport-id";

        private static final String sViveportKey = "your-viveport-key";

 

        private LicenseCheckerCallback mLicenseCheckerCallback = new MyLicenseCheckerCallback();

        private LicenseChecker mChecker;

 

 

7. Create LicenseChecker object in MainActivity.onCreate()

 


        mChecker
= new LicenseChecker( this, sViveportID , sViveportKey);

 

 

8. Destroy LicenseChecker object in MainActivity.onDestroy()

 


        mChecker
.onDestroy();

 

 

9. Now you can check if the license is valid.

 


        mChecker
.checkAccess(mLicenseCheckerCallback);

 

 

10. Obfuscating your code makes it more difficult to decompile and remove the license check. You can use ProGuard or a similar program to do the job.

 

 

 

Adding Licensing to Unity Project

1.    Add your application to Viveport developer console (https://developer.viveport.com/console) and get the ViveportID & ViveportKey of your application.

2.    Open Your Unity project and import “Viveport_Android_DRM.unitypackage” to it. (from Unity Editor > Assets > Import Package > Custom Package)

 

3.    Refer to the “Assets\Viveport_Android_DRM\MyLicenseChecker.cs” to implement your licensing script.

 

4.    Embed your ViveportID & ViveportKey to your licensing script.


(Compatible with Unity 5.3+)

 

 

 

Adding Licensing to Unreal Project

1.    Add your application to Viveport developer console (https://developer.viveport.com/console) and get the ViveportID & ViveportKey of your application.

2.    Copy “AndroidDRM_unreal\Plugins\ViveportLicenseChecker\” to your Unreal project “Plugins\” directory

3.    Close and reopen Unreal editor.

4.    Refer to the “AndroidDRM_unreal\MyLicenseCheckerExample\*” to implement your licensing cpp code.


(Compatible with Unreal 4.13+)

 

 

 

Support

If you have problems, please go to the developer community (https://developer.viveport.com).