Licensing checker longevity of the “activated” status. How frequent is too much for the user?

StackOverflow https://stackoverflow.com/questions/4242716

  •  27-09-2019
  •  | 
  •  

Question

My app is a kind of a pocket guide with some data for the whole year. I'm assuming users will use the program at least once with Internet access to activate the license. Or at least that's my understanding of how the Android licensing system works. I'm using ServerManagedPolicy.

Does it check periodically for the license? Is there any way that I can control this? I don't want my users to be in the middle of nowhere, with an app already and previously activated and suddenly after 1 week, 1 month, 1 year etc. the app starts limiting the usability of the app itself because the license couldn't be verified again. My app is going to be used in remote places with erratic net access (can't be taken for granted all the time) by people who will live there for weeks, maybe months.

I feel I should at least warn them that they will be asked every X weeks to do that. Is the license system even that draconian?

I know I can handle the errors with the ERROR_CONTACTING_SERVER flag, on the applicationError void of LicenseCheckerCallback. Is the "VT" response always the same (can't test this on a test account/my account)? I was just curious about how you guys treat this situation on your own real life apps. Am I missing something here? For some reason I'm feeling I am. Is there any "catch"?

// EDITED:

Here is the code I'm trying right now:

// ServerManagedPolicy.java
private void setValidityTimestamp(String validityTimestamp) {
    Long lValidityTimestamp;
    try {
        lValidityTimestamp = Long.parseLong(validityTimestamp);
    } catch (NumberFormatException e) {
        // No response or not parsable, expire in one minute.
        Log.w(TAG, "License validity timestamp (VT) missing, caching for a minute");
        lValidityTimestamp = System.currentTimeMillis() + MILLIS_PER_MINUTE;
        validityTimestamp = Long.toString(lValidityTimestamp);
    }
    // added by me--->

    private static long maxLicense = 1000 * 3600 * 24 * 30; // ~ roughly 30 days
    private static long minLicense = 1000 * 3600 * 24 * 3;  // ~ roughly 3 days

    long lMax = System.currentTimeMillis() + maxLicense;
    long lMin = System.currentTimeMillis() + minLicense;
    if ((lValidityTimestamp > lMin) && (lValidityTimestamp < lMax)) {
        validityTimestamp = Long.toString(lMax);
    }

    // <--- added by me

    mValidityTimestamp = lValidityTimestamp;
    mPreferences.putString(PREF_VALIDITY_TIMESTAMP, validityTimestamp);
}
Was it helpful?

Solution

Just my two cents, you can define a period of time you would like to check (lets say 3 days). Check for the license after 3 days, if there is no internet, continue letting the user use it for lets say another week max or else the app will not be full functioned. Or just keep it full functioned until there is a connection again, then you can check and reset your time stamp. The license checker will only check when you tell it to.

I can clarify if need be!

Good luck

OTHER TIPS

David, the short answer is it is up to you.

Taken directly from the developer document. "For example, the server provides recommended values for the application's license validity period, retry grace period, and maximum allowable retry count, among others."

Depending how you choose to implement the policy, your choosing the answer to your own question.

Even with the ServerManagedPolicy, your app will only check for a license when you call "checkAccess()" as described in the checking access section of the licensing doc. If that call is never made, your app will continue to work indefinitely - As such, if you can detect that your users are in a situation where they legitimately cannot ping the server for license information, you can wrap the "checkAccess" call in a condition for that.

Further down the page there's information on setting up test accounts to verify LVL functionality. I highly recommend making good use of that testing functionality.

I got the answer to this very simply. Connect a real device via USB to your computer. Edit your LVL library source code in ServerManagedPolicy.java and add in a log statement for the lValidityTimestamp variable using DateFormat.getDateTimeInstance(DateFormat.MEDIUM,DateFormat.MEDIUM). Then uninstall your application to clear out any previous license cache timestamp, reinstall, and run your app. This contacts the server and then your logging statement reveals the answer. In my testing, the VT comes back to be exactly 1 day from now (when the license is checkes).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top