Reputation: 6731
I'm implementing the licensing in my App but I didn't found an official list of response codes.
The piece of script that return the code (int policyReason
) is this:
private class MyLicenseCheckerCallback implements LicenseCheckerCallback {
public void allow(int policyReason) {
if (isFinishing()) {
// Don't update UI if Activity is finishing.
return;
}
// Should allow user access.
displayResult(getString(R.string.allow));
}
public void dontAllow(int policyReason) {
if (isFinishing()) {
// Don't update UI if Activity is finishing.
return;
}
displayResult(getString(R.string.dont_allow));
// Should not allow access. In most cases, the app should assume
// the user has access unless it encounters this. If it does,
// the app should inform the user of their unlicensed ways
// and then either shut down the app or limit the user to a
// restricted set of features.
// In this example, we show a dialog that takes the user to a deep
// link returned by the license checker.
// If the reason for the lack of license is that the service is
// unavailable or there is another problem, we display a
// retry button on the dialog and a different message.
displayDialog(policyReason == Policy.RETRY);
}
public void applicationError(int errorCode) {
if (isFinishing()) {
// Don't update UI if Activity is finishing.
return;
}
// This is a polite way of saying the developer made a mistake
// while setting up or calling the license checker library.
// Please examine the error code and fix the error.
String result = String.format(getString(R.string.application_error), errorCode);
displayResult(result);
}
}
I found these here (unofficial, the link provided points to an official documentation without int codes):
Response Code Value Licensed 256 Not_licensed 561 Error_Server_Failure 291 Error_Contacting_Server 291 Error_Not_Market_Managed 3 Error_Invalid_Package_Name 1 Error_Non_Matching_UID 2
and these here (unofficial, without link to a official documentation with int codes):
LICENSED = Hex: 0x0100, Decimal: 256 NOT_LICENSED = Hex: 0x0231, Decimal: 561 RETRY = Hex: 0x0123, Decimal: 291 LICENSED_OLD_KEY = Hex: 0x2, Decimal: 2 ERROR_NOT_MARKET_MANAGED = Hex: 0x3, Decimal: 3 ERROR_SERVER_FAILURE = Hex: 0x4, Decimal: 4 ERROR_OVER_QUOTA = Hex: 0x5, Decimal: 5 ERROR_CONTACTING_SERVER = Hex: 0x101, Decimal: 257 ERROR_INVALID_PACKAGE_NAME = Hex: 0x102, Decimal: 258 ERROR_NON_MATCHING_UID = Hex: 0x103, Decimal: 259
But in the official documentation for the LicenseValidator
class there are these:
// 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;
(edit) For example, policyReason
may returns 291
and 256
but these aren't in LicenseValidator
(0x101
= 257
, 0x102 =
258,
0x103=
259`).
Where I can find an official documentation that contains the list of int's response codes to rely on?
I already searched in the lvl-library
module but without success.
(edit2) Thanks to @Mir Milad Hosseiny's answer now I know precisely where to find these int codes. But now I have a doubt: why does allow should return RETRY or NOT_LICENSED and dontAllow RETRY and LICENSED? Because of their names they shoudn't return nothing than respectively LICENSED and NOT_LICENSED/RETRY. I must know how to properly handle the case when the user did download my App from Google Play. I asked a dedicated question about that here.
Thanks a lot!
Upvotes: 1
Views: 253
Reputation: 2857
Take a look at Licensing Reference official page on the Android Developers website.
Update
There are 3 callback methods on the LicenseCheckerCallback class.
1. public void allow(int reason)
@param reason Policy.LICENSED or Policy.RETRY typically. (although in theory the policy can return Policy.NOT_LICENSED here as well)
2. public void dontAllow(int reason)
@param reason Policy.NOT_LICENSED or Policy.RETRY. (although in theory the policy can return Policy.LICENSED here as well --- perhaps the call to the LVL took too long, for example)
3. public void applicationError(int errorCode)
Error in application code. Caller did not call or set up license checker correctly. Should be considered fatal.
For first and second methods, input value reason
is one of the Policy.LICENSED
, Policy.NOT_LICENSED
and Policy.RETRY
values which are available on Policy class source code as below:
/**
* LICENSED means that the server returned back a valid license response
*/
public static final int LICENSED = 0x0100;
/**
* NOT_LICENSED means that the server returned back a valid license response
* that indicated that the user definitively is not licensed
*/
public static final int NOT_LICENSED = 0x0231;
/**
* RETRY means that the license response was unable to be determined ---
* perhaps as a result of faulty networking
*/
public static final int RETRY = 0x0123;
For the third method, error codes are available on LicenseCheckerCallback class source code as below:
/** Application error codes. */
public static final int ERROR_INVALID_PACKAGE_NAME = 1;
public static final int ERROR_NON_MATCHING_UID = 2;
public static final int ERROR_NOT_MARKET_MANAGED = 3;
public static final int ERROR_CHECK_IN_PROGRESS = 4;
public static final int ERROR_INVALID_PUBLIC_KEY = 5;
public static final int ERROR_MISSING_PERMISSION = 6;
Also, You can check LicenseValidator and LicenseChecker classes source code to check passed input values to these 3 methods are consistent with their documentations.
Upvotes: 1