Attend XDA's Second Annual Developer Conference, XDA:DevCon 2014!
5,810,803 Members 36,995 Now Online
XDA Developers Android and Mobile Development Forum

[MOD][GUIDE][JB 4.1.2][MULTI-THREAD/NATIVE] Lockscreen Blur Effect/MULTITHREAD

Tip us?
 
BOOTMGR
Old
(Last edited by BOOTMGR; 26th May 2014 at 12:04 PM.)
#1  
BOOTMGR's Avatar
Recognized Contributor - OP
Thanks Meter 1,556
Posts: 675
Join Date: Aug 2010
Location: Ahmedabad
Angry [MOD][GUIDE][JB 4.1.2][MULTI-THREAD/NATIVE] Lockscreen Blur Effect/MULTITHREAD


Lockscreen Blur Effect

EDIT : Updated guide with Native function. Now it is ~60% faster

I wanna share this mod with you which i made for my HarshJelly ROM. Before starting guide let's see what it does. Actually idea came from GravityBox Module.

What it does : It'll simply blur the background activity which you left before locking device (something like iOS 7's notification bar). Here are some caps to make it more clear.



Yeah this mod is compatible with all Lockscreens (AOSP, Sammy's circle lockscreen, pattern etc). I tested this mod on my SGSA running stock TW 4.1.2. Since all TW roms are almost same, it should work on all TW 4.1.2 ROMs.

Before starting tutorial, let me clear one thing that i won't respond to posts without full log. If you found any difficulty, feel free to ask me but please keep in mind above sentence.

What is required?
  • android.policy.jar
  • Apktool
  • Notepad++

So, let's begin...

Quote:
  • Decompile android.policy.jar
  • Navigate to : com\android\internal\policy\impl\sec
  • Download attached file, extract it and put WallpaperWidget$1.smali to above folder.
  • In the same folder, open WallpaperWidget.smali
  • before #instance field add following code
    Code:
    # static fields
    .field static mutex_acquired:Z
  • Search for .field private mEnhancedWallpaper:Lcom/android/internal/policy/impl/sec/EnhancedWallpaperWidget; and add this below it
    Code:
    .field private mHandler:Landroid/os/Handler;
  • Search for iput-boolean v2, p0, Lcom/android/internal/policy/impl/sec/WallpaperWidget;->mIsLiveWallpaper:Z and add this below
    Code:
    new-instance v0, Landroid/os/Handler;
    
        invoke-direct {v0}, Landroid/os/Handler;-><init>()V
    
        iput-object v0, p0, Lcom/android/internal/policy/impl/sec/WallpaperWidget;->mHandler:Landroid/os/Handler;
  • after # direct methods add following code
    Code:
    .method static constructor <clinit>()V
        .locals 1
    
        const-string v0, "harsh"
    
        invoke-static {v0}, Ljava/lang/System;->loadLibrary(Ljava/lang/String;)V
    
        const/4 v0, 0x1
    
        sput-boolean v0, Lcom/android/internal/policy/impl/sec/WallpaperWidget;->mutex_acquired:Z
    
        return-void
    .end method
  • Now search for .method public constructor <init>(Landroid/content/Context;Landroid/content/res/ConfigurationV and replace whole method with following :
    Code:
    .method public constructor <init>(Landroid/content/Context;Landroid/content/res/Configuration;)V
        .locals 5
    
        const/4 v4, 0x0
    
        const/4 v3, -0x1
    
        const/4 v2, 0x1
    
        invoke-direct {p0, p1}, Landroid/widget/FrameLayout;-><init>(Landroid/content/Context;)V
    
        const-string v0, "WallpaperWidget"
    
        iput-object v0, p0, Lcom/android/internal/policy/impl/sec/WallpaperWidget;->TAG:Ljava/lang/String;
    
        iput-boolean v2, p0, Lcom/android/internal/policy/impl/sec/WallpaperWidget;->mIsLiveWallpaper:Z
    
        new-instance v0, Landroid/os/Handler;
    
        invoke-direct {v0}, Landroid/os/Handler;-><init>()V
    
        iput-object v0, p0, Lcom/android/internal/policy/impl/sec/WallpaperWidget;->mHandler:Landroid/os/Handler;
    
        const/4 v0, 0x0
    
        iput-object v0, p0, Lcom/android/internal/policy/impl/sec/WallpaperWidget;->mLockScreenWallpaperImage:Landroid/widget/ImageView;
    
        const-string v0, "/data/data/com.sec.android.gallery3d/lockscreen_wallpaper.jpg"
    
        iput-object v0, p0, Lcom/android/internal/policy/impl/sec/WallpaperWidget;->PORTRAIT_WALLPAPER_IMAGE_PATH:Ljava/lang/String;
    
        iput-object p1, p0, Lcom/android/internal/policy/impl/sec/WallpaperWidget;->mContext:Landroid/content/Context;
    
        invoke-virtual {p1}, Landroid/content/Context;->getContentResolver()Landroid/content/ContentResolver;
    
        move-result-object v0
    
        const-string v1, "lockscreen_wallpaper"
    
        invoke-static {v0, v1, v2}, Landroid/provider/Settings$System;->getInt(Landroid/content/ContentResolver;Ljava/lang/String;I)I
    
        move-result v0
    
        if-ne v0, v2, :cond_0
    
        iput-boolean v4, p0, Lcom/android/internal/policy/impl/sec/WallpaperWidget;->mIsLiveWallpaper:Z
    
        :cond_0
        iget-boolean v0, p0, Lcom/android/internal/policy/impl/sec/WallpaperWidget;->mIsLiveWallpaper:Z
    
        if-eqz v0, :cond_1
    
        :goto_0
        return-void
    
        :cond_1
        new-instance v0, Landroid/widget/ImageView;
    
        invoke-direct {v0, p1}, Landroid/widget/ImageView;-><init>(Landroid/content/Context;)V
    
        iput-object v0, p0, Lcom/android/internal/policy/impl/sec/WallpaperWidget;->mLockScreenWallpaperImage:Landroid/widget/ImageView;
    
        iget-object v0, p0, Lcom/android/internal/policy/impl/sec/WallpaperWidget;->mLockScreenWallpaperImage:Landroid/widget/ImageView;
    
        sget-object v1, Landroid/widget/ImageView$ScaleType;->CENTER_CROP:Landroid/widget/ImageView$ScaleType;
    
        invoke-virtual {v0, v1}, Landroid/widget/ImageView;->setScaleType(Landroid/widget/ImageView$ScaleType;)V
    
        iget-object v0, p0, Lcom/android/internal/policy/impl/sec/WallpaperWidget;->mLockScreenWallpaperImage:Landroid/widget/ImageView;
    
        invoke-virtual {p0, v0, v3, v3}, Lcom/android/internal/policy/impl/sec/WallpaperWidget;->addView(Landroid/view/View;II)V
    	
        invoke-direct {p0}, Lcom/android/internal/policy/impl/sec/WallpaperWidget;->BlurImage()V
    
        goto :goto_0
    .end method
    
    .method private BlurImage()V
        .locals 2
    
        new-instance v0, Ljava/lang/Thread;
    
        new-instance v1, Lcom/android/internal/policy/impl/sec/WallpaperWidget$1;
    
        invoke-direct {v1, p0}, Lcom/android/internal/policy/impl/sec/WallpaperWidget$1;-><init>(Lcom/android/internal/policy/impl/sec/WallpaperWidget;)V
    
        invoke-direct {v0, v1}, Ljava/lang/Thread;-><init>(Ljava/lang/Runnable;)V
    
        invoke-virtual {v0}, Ljava/lang/Thread;->start()V
    
        return-void
    .end method
    
    .method static synthetic access$0(Lcom/android/internal/policy/impl/sec/WallpaperWidget;Landroid/graphics/Bitmap;Landroid/graphics/Bitmap;I)V
        .locals 0
    
        invoke-direct {p0, p1, p2, p3}, Lcom/android/internal/policy/impl/sec/WallpaperWidget;->blurImage(Landroid/graphics/Bitmap;Landroid/graphics/Bitmap;I)V
    
        return-void
    .end method
    
    .method static synthetic access$1(Lcom/android/internal/policy/impl/sec/WallpaperWidget;)Landroid/os/Handler;
        .locals 1
    
        iget-object v0, p0, Lcom/android/internal/policy/impl/sec/WallpaperWidget;->mHandler:Landroid/os/Handler;
    
        return-object v0
    .end method
    
    .method private native blurImage(Landroid/graphics/Bitmap;Landroid/graphics/Bitmap;I)V
    .end method
  • Now search for # virtual methods and add this code after it
    Code:
    .method public updateWallpaper()V
        .locals 3
    
        const-string v1, "/data/data/com.sec.android.gallery3d/lockscreen_wallpaper.jpg"
    
        iput-object v1, p0, Lcom/android/internal/policy/impl/sec/WallpaperWidget;->mWallpaperPath:Ljava/lang/String;
    
        new-instance v0, Landroid/graphics/drawable/BitmapDrawable;
    
        invoke-virtual {p0}, Lcom/android/internal/policy/impl/sec/WallpaperWidget;->getResources()Landroid/content/res/Resources;
    
        move-result-object v1
    
        iget-object v2, p0, Lcom/android/internal/policy/impl/sec/WallpaperWidget;->mWallpaperPath:Ljava/lang/String;
    
        invoke-direct {v0, v1, v2}, Landroid/graphics/drawable/BitmapDrawable;-><init>(Landroid/content/res/Resources;Ljava/lang/String;)V
    
        iget-object v1, p0, Lcom/android/internal/policy/impl/sec/WallpaperWidget;->mLockScreenWallpaperImage:Landroid/widget/ImageView;
    
        invoke-virtual {v1, v0}, Landroid/widget/ImageView;->setImageDrawable(Landroid/graphics/drawable/Drawable;)V
    
        return-void
    .end method
  • Follow xperiacle's guide for TRANSPARENT STATUSBAR on lockscreen http://forum.xda-developers.com/show....php?t=2384892 (this is required, don't worry, it won't make it transparent)
  • From the extracted files, push libharsh.so to /system/lib/libharsh.so and chmod it to 644 (rw-r--r--)
  • Make sure that /data/data/com.sec.android.gallery3d/lockscreen_wallpaper.png & /data/data/com.sec.android.gallery3d/lockscreen_wallpaper.jpg file exists before you reboot your device. If it doesn't then put any valid png file there with name lockscreen_wallpaper.png/lockscreen_wallpaper.jpg and chmod it to 777
  • We're done compile it and push it to device
  • To add toggle for it, read here
What we're doing here?
Basically we are taking screenshot when device is getting locked and then we apply blur effect and sets it as wallpaper.
I know there are many way's to do it but i've preferred hacking WallpaperWidget's constructor. You can go for another way if you want.
Another thing to tell is that it depend on you device that how much time it'll require to do this process. On my device it nearly take 2 seconds (it depends on background). Multithreading can also be used. Read second post for more info and other tweaks., By default we're using Multi threading :P

Attached Files
File Type: zip files.zip - [Click for QR Code] (10.4 KB, 191 views)
The world aint all sunshine and rainbows, its a very mean and nasty place and I dont care how tough you are, it will beat you to your knees and keep you there permanently if you let it.
You, me, or nobody, is gonna hit as hard as life; but it aint about how hard you hit, its about how hard you can get hit and keep moving forward, how much you can take and keep moving forward.
Thats how winning is done...
Donate me some "Thanks" if i've helped you...
The Following 29 Users Say Thank You to BOOTMGR For This Useful Post: [ Click to Expand ]
 
BOOTMGR
Old
(Last edited by BOOTMGR; 26th May 2014 at 12:13 PM.)
#2  
BOOTMGR's Avatar
Recognized Contributor - OP
Thanks Meter 1,556
Posts: 675
Join Date: Aug 2010
Location: Ahmedabad
Thumbs up Tips, Tricks & FAQs

Quote:
Bugs & Remedies :
  • If multithreading is not enabled & device is woke up suddenly after locking then sometimes device stays unlocked for a moment --> Enabled multithreading or don't wake up device soon after locking it
  • When mutithreading is enabled & device is suddenly woke up (soon after locking), it shows older image --> Disable mutithreading or don't wake up device soon after locking it
All bug are solved..:P


As this tutorial is written for 4.1.2 (API 16), we don't have native image processing support (which came in API 17).This is the reason why it takes long time to blur image. As told above, i' trying to implement native method for blurring image anybody interested in it can help me.


Quote:
Tweaks :
  • Blur Radius : (Value in Hex)
    Code:
    .local v4, out:Landroid/graphics/Bitmap;
        const/16 v5, 0x19
    (lower radius --> better performance)
  • JPEG Quility: (Value in Hex)
    Code:
    .local v1, bytes:Ljava/io/ByteArrayOutputStream;
        sget-object v5, Landroid/graphics/Bitmap$CompressFormat;->JPEG:Landroid/graphics/Bitmap$CompressFormat;
    
        const/16 v6, 0x64
    Lower Quality --> better performance, weird colors
Quote:
Changelog:
  • 26th May 2014 --> Solved bug with delay while locking, Uses Multi Threading by default
  • xth February 2014 --> Native function Implementation (x > 6 :P)
  • 6th February 2014 --> Initial Release
The world aint all sunshine and rainbows, its a very mean and nasty place and I dont care how tough you are, it will beat you to your knees and keep you there permanently if you let it.
You, me, or nobody, is gonna hit as hard as life; but it aint about how hard you hit, its about how hard you can get hit and keep moving forward, how much you can take and keep moving forward.
Thats how winning is done...
Donate me some "Thanks" if i've helped you...
The Following 13 Users Say Thank You to BOOTMGR For This Useful Post: [ Click to Expand ]
 
arneldna
Old
#3  
arneldna's Avatar
Senior Member
Thanks Meter 152
Posts: 327
Join Date: Dec 2012
Location: Mumbai
Thumbs up GReat Work!!!!!!

Amazing Job, Harsh as usual you surprise us every time....Man keep it UP!!

Thankz a Ton..!
The Following 2 Users Say Thank You to arneldna For This Useful Post: [ Click to Expand ]
 
mjz2cool
Old
#4  
mjz2cool's Avatar
Senior Member
Thanks Meter 91
Posts: 817
Join Date: Jun 2010
Location: hardenberg
when i use this, can i still use normal wallpapers if i want? or does that need a toggle or something like that?
Phones used: Samsung sgh-something (with the antenna and color led ), Nokia 6320i, Nokia N70, Samsung Omnia I900, Samsung Chat 335, Samsung Galaxy Y, Samsung Galaxy Young (S6310N), Samsung Galaxy S Advance.
Current phone: Nokia Lumia 520 with Windows Phone 8.1, hoping there will be more app development (missing official snapchat, and a few more).
Helemaal uit nederland
 
Sami Kabir
Old
#5  
Sami Kabir's Avatar
Senior Member
Thanks Meter 849
Posts: 1,805
Join Date: Oct 2012
Location: Al Manama

 
DONATE TO ME
Quote:
Originally Posted by mjz2cool View Post
when i use this, can i still use normal wallpapers if i want? or does that need a toggle or something like that?
+1

@BOOTMGR, Please make a short tutorial (if possible) for setting up a Toggle to switch it on or off from the Settings app

► Phone: Samsung Galaxy S Advance (GT-i9070)
► ROM: Sami OS 1.2 ► Kernel: CoCore E Refresh (r09)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
My Website | Follow me on Twitter | Follow me on Instagram
 
BOOTMGR
Old
#6  
BOOTMGR's Avatar
Recognized Contributor - OP
Thanks Meter 1,556
Posts: 675
Join Date: Aug 2010
Location: Ahmedabad
Updated thread with new implementation. Now we are using Native function to blur image which is ~60% faster than previous implementation. Follow tutorial again if you've already done so.




Quote:
Originally Posted by mjz2cool View Post
when i use this, can i still use normal wallpapers if i want? or does that need a toggle or something like that?
Quote:
Originally Posted by Sami Kabir View Post
+1

@BOOTMGR, Please make a short tutorial (if possible) for setting up a Toggle to switch it on or off from the Settings app
Adding toggle in secsetting is easy but only reason behind not providing it is that some people would have enabled AOSP lockscreen in that case method will be slightly different. But you can follow this tutorial to add toggle for it using build.prop



How to add Toggle :
Quote:
  • Follow main tutorial
  • Inside WallpaperWidget.smali, search for invoke-direct {p0}, Lcom/android/internal/policy/impl/sec/WallpaperWidget;->BlurImage()V and add following code above it
    Code:
    const-string v0, "ro.harsh.blurlockscreen"
    
        invoke-static {v0, v2}, Landroid/os/SystemProperties;->getBoolean(Ljava/lang/String;Z)Z
    
        move-result v0
    
        if-eqz v0, :cond_2
  • Search below for .end method (2 - 3 lines down) and add this below it
    Code:
    :cond_2
        invoke-direct {p0}, Lcom/android/internal/policy/impl/sec/WallpaperWidget;->setLockScreenWallpaper()V
    
        goto :goto_0
  • That's all. Compile it.
Now you can toggle its state by adding ro.harsh.blurlockscreen=true or ro.harsh.blurlockscreen=false
You can also type in terminal setprop ro.harsh.blurlockscreen true/false to toggle state on the fly.
The world aint all sunshine and rainbows, its a very mean and nasty place and I dont care how tough you are, it will beat you to your knees and keep you there permanently if you let it.
You, me, or nobody, is gonna hit as hard as life; but it aint about how hard you hit, its about how hard you can get hit and keep moving forward, how much you can take and keep moving forward.
Thats how winning is done...
Donate me some "Thanks" if i've helped you...
The Following 7 Users Say Thank You to BOOTMGR For This Useful Post: [ Click to Expand ]
 
Force
Old
#7  
Senior Member
Thanks Meter 321
Posts: 908
Join Date: Feb 2012
Location: Bucharest
off topic: You keep doing stock jb more and more better
Device: Samsung Galaxy S Advance GT-I9070
Rom: Sami OS 1.2 (Thank you @Sami Kabir)
Kernel: Cocore Kernel 8.2 (Thank you @cocafe)

My review about Sami OS :
 

Sami OS - Beautiful.Clean.Smooth.

Check Sami OS here.


Read here my review:
http://forum.xda-developers.com/show...&postcount=396

PS: If you didn't tried Sami OS until now,you should do it.

Press "THANKS" if i helped you
 
rajeev994
Old
#8  
Member
Thanks Meter 13
Posts: 39
Join Date: Jul 2013
Location: Delhi
I'm Sorry But i'm Naive I cannot Follow this tutorial Can you Make a Flashable zip Plz Plz Plz Plz Plzzzzzzzzzzzzzzzzzzzzz
 
shut_down
Old
#9  
shut_down's Avatar
Senior Member
Thanks Meter 3,376
Posts: 7,479
Join Date: Sep 2010
Location: Belgrade
Quote:
Originally Posted by rajeev994 View Post
I'm Sorry But i'm Naive I cannot Follow this tutorial Can you Make a Flashable zip Plz Plz Plz Plz Plzzzzzzzzzzzzzzzzzzzzz
He did on his ROM.
 
rajeev994
Old
#10  
Member
Thanks Meter 13
Posts: 39
Join Date: Jul 2013
Location: Delhi
Quote:
Originally Posted by shut_down View Post
He did on his ROM.
No he did not I'm using his harshjelly
Even if he did can you tell me how to do that

Sent from my GT-I9070 using Tapatalk 4

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes