0

Has anybody had success integrating the Licensing Verification Library (LVL) with a Live Wallpaper? If it were just running an Activity, it'd be crystal clear to just extend my Activity from the Licensing Activity, which in turn extends Activity. But Live Wallpapers are a Service, and I'm not sure how the two are intended to interact.

I'm using code derived from this: http://www.droidforums.net/forum/android-app-developers/69899-market-license-easy-implementation-protect-your-apps.html which seems to be the code that nearly everything I can find on the web refers to.

I notice that wallpaper settings are an activity, and I have those working properly, but for some reason I can't grok the Licensing stuff...

JasonMArcher
  • 14,195
  • 22
  • 56
  • 52
dan
  • 3
  • 2

3 Answers3

2

It's actually really quite simple, you don't need to use any Activity class to implement licensing into a WallpaperService.

Make sure you've followed the directions carefully at http://developer.android.com/guide/publishing/licensing.html

Here's how I did it:

Your extended Engine class should include something similar to the following... (code not essential to your question has been removed)

class startYourEngines extends Engine {     

    public startYourEngines() {
        super();
        licenseStatus(); //custom license check method (for modularity)            
        //the rest of your engine would go here
    }

    public void onDestroy() {
        super.onDestroy();
        licenseChecker.onDestroy(); //we call this to close IPC connections
    }

//prep work
    private static final String BASE64_PUBLIC_KEY = //OMITTED//;
    private LicenseCheckerCallback licenseCallback;
    private LicenseChecker licenseChecker;  
    private byte[] salt = "rAnd0mStr!ng".getBytes();
    private AESObfuscator aes;
    private String deviceId;

//our custom license check method       
    private void licenseStatus() {
        deviceId = Secure.getString(getContentResolver(), Secure.ANDROID_ID);
        aes = new AESObfuscator(salt, getPackageName(), deviceId);
        licenseCallback = new licenseVerification();    
        licenseChecker = new LicenseChecker(context, new ServerManagedPolicy(context, aes), BASE64_PUBLIC_KEY);
        licenseChecker.checkAccess(licenseCallback);
    }

//our callback method
    private class licenseVerification implements LicenseCheckerCallback {
        @Override
        public void allow() {
             //allow full app use
        }

        @Override
        public void dontAllow() {
             //prevent or limit app use
        }
        @Override
        public void applicationError(ApplicationErrorCode errorCode) {
             //error handling here
        }

    }
}

Licensing on the Android platform was created with versatility in mind. Just be sure to read through the documentation, and you shouldn't have any issues.

arkon
  • 2,209
  • 3
  • 27
  • 36
  • Problem is that this works asynchronously and usually when checking for license, you want to receive a response (even at the expense of blocking your thread) so that you can decide whether to allow or deny a feature from a user. Do you have a solution for that ? – Muzikant Jun 17 '11 at 05:29
  • @Muzikant, not for a live wallpaper. You typically want to treat the user as "innocent until proven guilty", so show the wallpaper as normal and check the license many times until you are sure that it shuld be enabled or disabled. – Adam Nybäck Apr 10 '13 at 15:58
  • @Adam Nybäck agree with your comment – Muzikant Apr 10 '13 at 16:54
1

I have only written applications that start activities, but looking at my source code, it seems that the only reason that you would have to have an Activity do the license check is to show dialogs.

In all of the examples available on line, the LicenseCheckerCallback implementation always shows a dialog in the allow() and dontAllow() methods. Why not just show a toast in dontAllow() and exit your wallpaper service (call stopSelf(YourService.this))?

Let me know if you want more information, because I dont think you are limited to only using an activity for license checking. As an aside, make sure that you dont keep whole strings, etc in your app or in the preferences. Anyone with root access can access your preferences and if your app is decompiled, your strings are visible...

ekawas
  • 6,594
  • 3
  • 27
  • 39
  • Thanks very much for this. I think I was just staring at the issue too long that my brain refused to think outside the Activity box. I just implemented LicenseCheckerCallback within my service that extends GLWallpaperService. So far so good. I've still got to actually verify that it's sending and receiving the correct messages from the licensing server, but your suggestion got me over my primary obstacle. – dan Mar 18 '11 at 18:32
  • I'm not sure if this would be more appropriate under a second question, but stopSelf() in my WallpaperService doesn't actually seem to be stopping the wallpaper. – dan Mar 18 '11 at 20:15
  • Hi Dan, I haven't actually written a wallpaper service before, so I am not sure of the correct method to stop one. Does a stopService() call work for you instead? – ekawas Mar 19 '11 at 14:27
  • ekawas, I discovered the source of my problem. I was calling checkLicense() in my WallpaperService's onCreate(). I was also checking the result and calling stopSelf() in that same onCreate. I imagine the result was the stopSelf() was telling the service to stop, followed immediately by the onCreate() function completing and then creating the Service. Since the create came after the stop, the stop was effectively ignored. – dan Mar 22 '11 at 00:56
0

I think I've actually got it working now. I'm extending LicenseCheckActivity to my own Activity class that I'm calling in the manifest file with the usual MAIN action and LAUNCH category. I instantiate my class, do the license check, and then either allow the wallpaper to function or not based on that result (though the best way to do that is still something I need to sort out).

It almost seems too easy that I think I must be missing something. I'd appreciate anybody with experience with selling a licensed live wallpaper on the Android Market to share whatever wisdom they care to.

dan
  • 3
  • 2
  • would that work? couldnt someone just update the manifest so that the license activity isnt called at all? – ekawas Mar 18 '11 at 13:08
  • I'm guessing then perhaps I ought to have the license check Activity set a SharedPreference variable and then have the wallpaper Service either start or shutdown based on that Preference? – dan Mar 18 '11 at 13:48
  • Again a preference is something they could change. sorry to be the harbinger of despair... I think rather than commenting, I will see if I can provide a solution. – ekawas Mar 18 '11 at 14:29