5

I want to cater for LICENSE_OLD_KEY in my android license policy. I was going to modify the ServerManagedPolicy as it doesn't cater for this, as far as I can tell, it just seems to look for Policy.LICENSED or Policy.NOT_LICENSED in processServerResponse method:

public void processServerResponse(int response, ResponseData rawData) {

    // Update retry counter
    if (response != Policy.RETRY) {
        setRetryCount(0);
    } else {
        setRetryCount(mRetryCount + 1);
    }

    if (response == Policy.LICENSED) {
        // Update server policy data
        Map<String, String> extras = decodeExtras(rawData.extra);
        mLastResponse = response;
        setValidityTimestamp(extras.get("VT"));
        setRetryUntil(extras.get("GT"));
        setMaxRetries(extras.get("GR"));
    } else if (response == Policy.NOT_LICENSED) {
        // Clear out stale policy data
        setValidityTimestamp(DEFAULT_VALIDITY_TIMESTAMP);
        setRetryUntil(DEFAULT_RETRY_UNTIL);
        setMaxRetries(DEFAULT_MAX_RETRIES);
    }

    setLastResponse(response);
    mPreferences.commit();
}

I'd like to know what the response code is for LICENSE_OLD_KEY because that doesn't exist in Policy:

public static final int LICENSED = 0x0100;
public static final int NOT_LICENSED = 0x0231;
public static final int RETRY = 0x0123;

I had a look here, but I can't find anywhere that lists the name and values.

I can see that there are a list of server response codes in LicenseValidator but they don't match up to those in Policy:

    // Server response codes.
private static final int LICENSED = 0x0;
private static final int NOT_LICENSED = 0x1;
private static final int LICENSED_OLD_KEY = 0x2;
private static final int ERROR_NOT_MARKET_MANAGED = 0x3;
private static final int ERROR_SERVER_FAILURE = 0x4;
private static final int ERROR_OVER_QUOTA = 0x5;

private static final int ERROR_CONTACTING_SERVER = 0x101;
private static final int ERROR_INVALID_PACKAGE_NAME = 0x102;
private static final int ERROR_NON_MATCHING_UID = 0x103;
CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
James
  • 248
  • 2
  • 12
  • Doesn't seem to be much on the internet when googling for LICENSE_OLD_KEY. Perhaps we don't need to cater for LICENSE_OLD_KEY any more? Anyone know?? I wish the android documentation was kept up to date... – James Sep 06 '12 at 13:30

2 Answers2

5

Giving it some thought I decided to try displaying the reason codes returned by the Google Play server on my phone, using AlertDialog's. Here is what I found:

Selecting LICENSED, in the Developer console profile, returned the number 256, as per Policy.LICENSED.

Selecting NOT_LICENSED returned the number 561, again as per Policy.NOT_LICENSED.

Finally selecting LICENSED_OLD_KEY returned the number 256, which is the same as Policy.LICENSED.

So it would seem that LICENSED_OLD_KEY is no longer used, or rather there is no distinction between LICENSED and LICENSED_OLD_KEY. Which is a bit confusing given the information that google provide in their documentation here.

Just to note, I did try uninstalling my app and selecting the different options in the developer console a few times, but it always resulted in the same answer!

James
  • 248
  • 2
  • 12
0

The code you're looking at is only a reference implementation. It can't know how you would want to deal with a LICENSED_OLD_KEY situation in detail. The documentation suggests you might want to limit access to the current app, or to your server data from the current app, and ask the user to update and use the latest version. There's nothing much a reference implementation can provide to enable you to deal with all these situations. You can and should modify the code to treat LICENSED_OLD_KEY separately.

There's no indication for LICENSED_OLD_KEY "not being used anymore" because it's still handled as a server response in LicenseValidator.java and "OLD_KEY" refers to an older version of your app, not an older version of Google Play server handling.

class stacker
  • 5,357
  • 2
  • 32
  • 65