Android Question Licensing library issues

Jack Cole

Well-Known Member
Licensed User
Longtime User
This is not currently an issue as much as a curiosity and perhaps something that will help others. I have been struggling for several days to get the licensing library to work correctly. It works correctly on the first / second times the app is launched. After that, it sticks with a cached licensed response. It doesn't matter if you set the testing response in the console to "not licensed."

I resolved this by setting the salt parameter to a random value (see below).

[CODE lang="b4x" highlight="12,13"]'this was written by Erel in a different context
Sub GenerateRandomString (Length As Int) As String
Dim su As StringUtils
Dim bytes(Length) As Byte
Private secureRandom1 As SecureRandom
secureRandom1.GetRandomBytes(bytes)
Return su.EncodeBase64(bytes).SubString2(0, Length)
End Sub

Sub CheckLicense
Dim bc As BCrypt
Dim hash As String = bc.hashpw(GenerateRandomString(10),bc.gensalt)
lc.Initialize("lc", GetDeviceId, publicKey, hash.GetBytes("UTF8"))
' lc.SetVariableAndValue("test2", "abd")
lc.CheckAccess
End Sub[/CODE]

The tutorial for the licensing library says:

The Salt parameter should be an array of bytes with some random values (the values should be the same on each run).

I interpreted that to mean that you just don't change the value from that random string in your code from one run to the next. Here is the original:

[CODE lang="b4x" highlight="4"]Sub Activity_Create(FirstTime As Boolean)
Dim lc As LicenseChecker
Dim p As PhoneId
lc.Initialize("lc", p.GetDeviceId, publicKey, "kljdflkf".GetBytes("UTF8"))
lc.SetVariableAndValue("test_1", "some secret value")
lc.CheckAccess
End Sub[/CODE]

Anyway, my new code works, and responds to the changes to the status in the Play Console. Sorry if I have misunderstood something.

Thanks,
Jack
 
That part is expected with normal operation, but not with the testing responses. It is only supposed to cache for 1 minute. As far as I can tell, it never stops using the cached response when I use the original code. When I use the code as I changed it, it works as expected.
 
Upvote 0
To expand further, it also does not work correctly with the Play Pass program. With this program, an app previously licensed, can become not licensed if they no longer subscribe to Play Pass. Because the library uses a cached response for "licensed" indefinitely, it never shows as being no longer licensed.
 
Upvote 0
Back
Top