4

I looked around online and saw some other posts complaining about how the Android licensing (LVL) library is slow, but no solutions. On an HTC Thunderbolt (brand new phone) it delays the startup time of a test app by 3-5+ seconds.

Does anyone have any experience or ideas on calling this library asynchronously? Other solutions? I am just using the sample code provided basically. The really annoying part is that the whole app is frozen while this simple license check occurs, it's really bad.

Thanks!

JasonMArcher
  • 14,195
  • 22
  • 56
  • 52
  • 2
    Here is the trick, run the LVL in another thread and do not wait for it to finish before starting your game. Then, if it fails, look into blocking access to content. Or is that what you are doing already? – Robert Massaioli Aug 21 '11 at 07:13
  • For those of us who are nitwits in Java and only copy-paste it... how would you kick off the LVL verification in another thread? – Wytze Jul 18 '12 at 13:29
  • Indeed, very slow (even in 2018...). And I have another problem: when the app is launched for the first time, I get systematically error 291 (Error_Contacting_Server). I have to launch doCheck a second time to get the proper ok response after 5 seconds... Do you have this 291 error on first launch ? – toto_tata Mar 23 '18 at 10:36

3 Answers3

0

Nitwit figured it out: the licenseCheck is asynchronous.

So just fire it, then open the app with your next few lines of code, and when the response arrives, that will interrupt the app (i.e. if you set up for there to be a dialog if the license is not valid, then your app will start to load and then the dialog appears and this blocks everything).

Make sure to include finish() in the follow-up of all code that follows on a "don't allow" situation.

Great results: the app loses four or five seconds in load time.

Wytze
  • 7,844
  • 8
  • 49
  • 62
0

I might be wrong but I have the feeling that the LVL server is very slow and buggy when used in debug mode, that is to say when I install the app on my device directly with Android Studio and test the LVL implementation by changing the response in the Google Play Console. Indeed, it is in this case the sandbox servers which are used, not the Google Play production servers.

So, to have quick and proper responses for the LVL implementation, I upload a test apk (with toasts to see the LVL responses) to the Google Play Console in beta test channel. Then, I download the apk from Google Play thanks to the Google Play beta test URL. The LVL responses are much faster and reliable.

Please tell me if you confirm this observation.

toto_tata
  • 14,526
  • 27
  • 108
  • 198
-1

Implement LicenseCheckerCallback in your Activity and call it like this:

mLicenseChecker = new LicenseChecker(this, new MyPolicy(this, new AESObfuscator(getSalt(), getPackageName(), getDeviceId())), PUBLIC_KEY);
mLicenseChecker.checkAccess(new MyCheckerCallback());
mHandler = new Handler();

Then post to the handler if the license is invalid: In MyCheckerCallback:

public void dontAllow() {
    if (isFinishing()) {
        return; //don't update UI when app is finishing
    }
    mHandler.post(new Runnable() {
    public void run() {
        //show toast message stating license is invalid
        //redirect user to Market
        //call finish()
        }
    });
}
CrackerJack9
  • 3,650
  • 1
  • 27
  • 48
  • This won't help. It's the call AESObfuscator() that's so slow. The suggestion above to call it in another thread will speed things up. – Barry Fruitman Nov 11 '11 at 16:06
  • @Barry Fruitman It doesn't speed it up by calling it in another thread...it just prevents the rest of the app from waiting for it. I never said to run it asynchronously...but I've never seen it take a noticeable amount time to load either. Do you have any metrics for instantiating `AESObfuscator`? Which device(s)? – CrackerJack9 Nov 11 '11 at 21:25
  • I'm experiencing the same delay (3-5 seconds or more) to check the license, and I tracked down the delay to the AESObfuscator constructor. Search for "AESObfuscator" or "slow LicenseChecker" here on stackoverflow and you'll see similar complaints. Initiating the license check in Activity.onCreate() will freeze the app for a few seconds, which is why I and the above commenter recommend forking a new thread. http://stackoverflow.com/questions/4629603/licensechecker-is-slow-in-emulator – Barry Fruitman Nov 11 '11 at 21:57
  • @Barry Fruitman where did I say to instantiate it in `onCreate()`? – CrackerJack9 Nov 14 '11 at 16:27