Post Reply

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

4th February 2014, 06:43 AM   |  #1  
BOOTMGR's Avatar
OP Recognized Contributor
Flag Ahmedabad
Thanks Meter: 1,556
 
675 posts
Join Date:Joined: Aug 2010
More

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, 203 views)
Last edited by BOOTMGR; 26th May 2014 at 12:04 PM.
The Following 29 Users Say Thank You to BOOTMGR For This Useful Post: [ View ]
4th February 2014, 06:44 AM   |  #2  
BOOTMGR's Avatar
OP Recognized Contributor
Flag Ahmedabad
Thanks Meter: 1,556
 
675 posts
Join Date:Joined: Aug 2010
More
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

Last edited by BOOTMGR; 26th May 2014 at 12:13 PM.
The Following 13 Users Say Thank You to BOOTMGR For This Useful Post: [ View ]
4th February 2014, 07:01 AM   |  #3  
arneldna's Avatar
Senior Member
Flag Mumbai
Thanks Meter: 152
 
327 posts
Join Date:Joined: Dec 2012
More
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: [ View ]
4th February 2014, 01:28 PM   |  #4  
mjz2cool's Avatar
Senior Member
Flag hardenberg
Thanks Meter: 91
 
817 posts
Join Date:Joined: Jun 2010
More
when i use this, can i still use normal wallpapers if i want? or does that need a toggle or something like that?
5th February 2014, 08:59 AM   |  #5  
Sami Kabir's Avatar
Senior Member
Flag Zinj
Thanks Meter: 858
 
1,813 posts
Join Date:Joined: Oct 2012
Donate to Me
More
Quote:
Originally Posted by mjz2cool

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
6th February 2014, 07:10 AM   |  #6  
BOOTMGR's Avatar
OP Recognized Contributor
Flag Ahmedabad
Thanks Meter: 1,556
 
675 posts
Join Date:Joined: Aug 2010
More
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

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

+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 Following 7 Users Say Thank You to BOOTMGR For This Useful Post: [ View ]
6th February 2014, 02:45 PM   |  #7  
Senior Member
Flag Bucharest
Thanks Meter: 329
 
935 posts
Join Date:Joined: Feb 2012
More
off topic: You keep doing stock jb more and more better
7th February 2014, 01:13 PM   |  #8  
Member
Delhi
Thanks Meter: 13
 
39 posts
Join Date:Joined: Jul 2013
More
I'm Sorry But i'm Naive I cannot Follow this tutorial Can you Make a Flashable zip Plz Plz Plz Plz Plzzzzzzzzzzzzzzzzzzzzz
7th February 2014, 06:01 PM   |  #9  
shut_down's Avatar
Senior Member
Flag Belgrade
Thanks Meter: 3,399
 
7,515 posts
Join Date:Joined: Sep 2010
More
Quote:
Originally Posted by rajeev994

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.
7th February 2014, 06:11 PM   |  #10  
Member
Delhi
Thanks Meter: 13
 
39 posts
Join Date:Joined: Jul 2013
More
Quote:
Originally Posted by shut_down

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

Post Reply Subscribe to Thread
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Top Threads in Galaxy S Advance I9070 Themes and Apps by ThreadRank