Remove All Ads from XDA

[Q] Extract live wallpaper

54 posts
Thanks Meter: 19
Post Reply Email Thread
Does anyone know where I can find code handling the current live wallpaper engine / view? I am trying to extract the live wallpaper for further processing (e.g. blurring).
I already found an entrance point: If the LWP used the standard supplied by the base class android.service.wallpaper.WallpaperService.Engine i can hook into lockCanvas and unlockCanvas to grab the image. But most LWPs do not use this, so I need another (more general) solution.
I thought about hooking all subclasses of android.service.wallpaper.WallpaperService, but AFAIK that's not possible without loading every single class and check if it's a subclass.
Any ideas?

Implementation for reference:
public class Hook implements IXposedHookLoadPackage {

    public void handleLoadPackage(XC_LoadPackage.LoadPackageParam loadPackageParam) throws Throwable {
        final Class<?> engingeClass = findClass("android.service.wallpaper.WallpaperService.Engine", loadPackageParam.classLoader);
        final String packageName = loadPackageParam.packageName;
        final Class<?> surfaceHolderClass = findClass("",loadPackageParam.classLoader);

        findAndHookMethod(engingeClass, "getSurfaceHolder", new XC_MethodHook() {
            private boolean isFirstCall = true;

            protected void afterHookedMethod(MethodHookParam param) throws Throwable {
                Field field = findField(param.thisObject.getClass(), "this$0");
                WallpaperService service = (WallpaperService) field.get(param.thisObject);
                WallpaperManager wallpaperManager = WallpaperManager.getInstance(service);
                if (isFirstCall && wallpaperManager.getWallpaperInfo().getPackageName().equals(packageName)) {
                    isFirstCall = false;
                    XposedBridge.log("Got context. Set up hooks...");

    Bitmap bitmap;
    Canvas internalCanvas;
    Canvas originalCanvas;

    private void hook(Class<?> clazz, final Context context) {
        hookAllMethods(clazz, "lockCanvas", new XC_MethodHook() {
            protected void afterHookedMethod(MethodHookParam param) throws Throwable {
                originalCanvas = (Canvas) param.getResult();
                bitmap = Bitmap.createBitmap(originalCanvas.getWidth(),originalCanvas.getHeight(), Bitmap.Config.ARGB_8888);
                internalCanvas = new Canvas(bitmap);
                XposedBridge.log("Locked Canvas");
        findAndHookMethod(clazz, "unlockCanvasAndPost", Canvas.class, new XC_MethodHook() {
            protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
                param.args[0] = originalCanvas;
                Intent intent = new Intent("com.faendir.lwpextractor.WALLPAPER_CHANGE");
                ByteArrayOutputStream bs = new ByteArrayOutputStream();
                context.sendBroadcast(intent, "com.faendir.lwpextractor.RECEIVE_WALLPAPER_CHANGE");
                XposedBridge.log("Unlocked Canvas");
1st December 2015, 05:08 PM |#2  
OP Member
Thanks Meter: 19
7th December 2015, 01:44 PM |#3  
OP Member
Thanks Meter: 19
7th December 2015, 08:15 PM |#4  
Senior Member
Flag Idaho
Thanks Meter: 161
Try asking in the Xposed Development forum, that's a better place for code-related questions.
The Following User Says Thank You to Spott07 For This Useful Post: [ View ] Gift Spott07 Ad-Free
Post Reply Subscribe to Thread

live wallpaper, lwp, xposed

Guest Quick Reply (no urls or BBcode)
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes