[Android Themes] :
[How-To] Lockscreen Custom Background Settings for JB 4.2 [Dev // Seniors & Users]

Hello Everyone,

This is a thread showing "how-to" for Lock-screen background/wallpaper change option and function in settings. All credits goes to our legendary Sir @Adi Aisiteru Reborn.

Let's move ahead with the guide:-

First decompile your android.policy.jar and go to android.policy.jar.out/smali\com\android\internal\policy\impl\keyguard\ and open "KeyGaurdHostView.smali"

Find this:-

.method private updateSecurityView(Landroid/view/View;)V

just above it paste this:-

.method private updateBackground()V
.locals 10

.prologue
.line 337
invoke-virtual {p0}, Lcom/android/internal/policy/impl/keyguard/KeyguardHostView;->getContext()Landroid/content/Context;

move-result-object v7

invoke-virtual {v7}, Landroid/content/Context;->getContentResolver()Landroid/content/ContentResolver;

move-result-object v7

const-string v8, "lockscreen_background"

const/4 v9, -0x2

invoke-static {v7, v8, v9}, Landroid/provider/Settings$System;->getStringForUser(Landroid/content/ContentResolver;Ljava/lang/String;I)Ljava/lang/String;

move-result-object v2

.line 340
.local v2, background:Ljava/lang/String;
if-nez v2, :cond_1

.line 365
:cond_0
:goto_0
return-void

.line 344
:cond_1
const/4 v0, 0x0

.line 345
.local v0, back:Landroid/graphics/drawable/Drawable;
invoke-virtual {v2}, Ljava/lang/String;->isEmpty()Z

move-result v7

if-nez v7, :cond_2

.line 347
:try_start_0
new-instance v1, Landroid/graphics/drawable/ColorDrawable;

invoke-static {v2}, Ljava/lang/Integer;->parseInt(Ljava/lang/String;)I

move-result v7

invoke-direct {v1, v7}, Landroid/graphics/drawable/ColorDrawable;-><init>(I)V
:try_end_0
.catch Ljava/lang/NumberFormatException; {:try_start_0 .. :try_end_0} :catch_0

.end local v0 #back:Landroid/graphics/drawable/Drawable;
.local v1, back:Landroid/graphics/drawable/Drawable;
move-object v0, v1

.line 361
.end local v1 #back:Landroid/graphics/drawable/Drawable;
.restart local v0 #back:Landroid/graphics/drawable/Drawable;
:goto_1
if-eqz v0, :cond_0

.line 362
const/high16 v7, 0x7000

sget-object v8, Landroid/graphics/PorterDuff$Mode;->SRC_ATOP:Landroid/graphics/PorterDuff$Mode;

invoke-virtual {v0, v7, v8}, Landroid/graphics/drawable/Drawable;->setColorFilter(ILandroid/graphics/PorterDuff$Mode;)V

.line 363
invoke-virtual {p0, v0}, Lcom/android/internal/policy/impl/keyguard/KeyguardHostView;->setBackground(Landroid/graphics/drawable/Drawable;)V

goto :goto_0

.line 348
:catch_0
move-exception v4

.line 349
.local v4, e:Ljava/lang/NumberFormatException;
const-string v7, "KeyguardHostView"

new-instance v8, Ljava/lang/StringBuilder;

invoke-direct {v8}, Ljava/lang/StringBuilder;-><init>()V

const-string v9, "Invalid background color "

invoke-virtual {v8, v9}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

move-result-object v8

invoke-virtual {v8, v2}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

move-result-object v8

invoke-virtual {v8}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

move-result-object v8

invoke-static {v7, v8}, Landroid/util/Log;->e(Ljava/lang/String;Ljava/lang/String;)I

goto :goto_1

.line 353
.end local v4 #e:Ljava/lang/NumberFormatException;
:cond_2
:try_start_1
invoke-virtual {p0}, Lcom/android/internal/policy/impl/keyguard/KeyguardHostView;->getContext()Landroid/content/Context;

move-result-object v7

const-string v8, "com.android.settings"

const/4 v9, 0x0

invoke-virtual {v7, v8, v9}, Landroid/content/Context;->createPackageContext(Ljava/lang/String;I)Landroid/content/Context;

move-result-object v5

.line 354
.local v5, settingsContext:Landroid/content/Context;
new-instance v7, Ljava/lang/StringBuilder;

invoke-direct {v7}, Ljava/lang/StringBuilder;-><init>()V

invoke-virtual {v5}, Landroid/content/Context;->getFilesDir()Ljava/io/File;

move-result-object v8

invoke-virtual {v7, v8}, Ljava/lang/StringBuilder;->append(Ljava/lang/Object;)Ljava/lang/StringBuilder;

move-result-object v7

const-string v8, "/lockwallpaper"

invoke-virtual {v7, v8}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

move-result-object v7

invoke-virtual {v7}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

move-result-object v6

.line 355
.local v6, wallpaperFile:Ljava/lang/String;
invoke-static {v6}, Landroid/graphics/BitmapFactory;->decodeFile(Ljava/lang/String;)Landroid/graphics/Bitmap;

move-result-object v3

.line 356
.local v3, backgroundBitmap:Landroid/graphics/Bitmap;
new-instance v1, Landroid/graphics/drawable/BitmapDrawable;

invoke-virtual {p0}, Lcom/android/internal/policy/impl/keyguard/KeyguardHostView;->getContext()Landroid/content/Context;

move-result-object v7

invoke-virtual {v7}, Landroid/content/Context;->getResources()Landroid/content/res/Resources;

move-result-object v7

invoke-direct {v1, v7, v3}, Landroid/graphics/drawable/BitmapDrawable;-><init>(Landroid/content/res/Resources;Landroid/graphics/Bitmap;)V
:try_end_1
.catch Landroid/content/pm/PackageManager$NameNotFoundException; {:try_start_1 .. :try_end_1} :catch_1

.end local v0 #back:Landroid/graphics/drawable/Drawable;
.restart local v1 #back:Landroid/graphics/drawable/Drawable;
move-object v0, v1

.line 359
.end local v1 #back:Landroid/graphics/drawable/Drawable;
.restart local v0 #back:Landroid/graphics/drawable/Drawable;
goto :goto_1

.line 357
.end local v3 #backgroundBitmap:Landroid/graphics/Bitmap;
.end local v5 #settingsContext:Landroid/content/Context;
.end local v6 #wallpaperFile:Ljava/lang/String;
:catch_1
move-exception v7

goto :goto_1
.end method

Now Find this line :-

invoke-direct {p0}, Lcom/android/internal/policy/impl/keyguard/KeyguardHostView;->addDefaultWidgets()V

Just Above this line, add this-

.line 301
:cond_[COLOR=Red]2[/COLOR]
invoke-direct {p0}, Lcom/android/internal/policy/impl/keyguard/KeyguardHostView;->updateBackground()V

(Please make sure you have to get correct condition number. You have to understand yourself or better please add the KeygaurdHostView.smali here, so that I can mod it in my free time).

Done and now recompile android.policy.jar and keep aside.

Now Decompile Settings.apk. and extract the file attached in the post.

Go to Settings.apk/res/xml/ and open "display_settings.xml" and paste this line:-

<PreferenceScreen android:id="@id/lockscreen_background" android:title="@string/lockscreen_background_title" android:summary="@string/lock_panel_bond" android:fragment="com.android.settings.cyanogenmod.LockscreenInterface" />

Now open values folder and open "strings.xml"

And add this-

<string name="lockscreen_widgets_category_title">Widgets</string>
<string name="lockscreen_maximize_widgets_title">Maximize widgets</string>
<string name="lockscreen_maximize_widgets_summary">Show widgets maximized and the unlock minimized when the screen is turned on</string>
<string name="lockscreen_enable_widgets_title">Widget pager</string>
<string name="lockscreen_enable_widgets_summary">Allow multiple widget pages to be added and selected</string>
<string name="lockscreen_enable_camera_title">Camera widget</string>
<string name="lockscreen_enable_camera_summary">Show the camera widget to the right of the unlock screen</string>
<string name="lockscreen_music_controls_title">Music controls</string>
<string name="lockscreen_music_controls_summary">Show player controls while music is playing</string>
<string name="lockscreen_custom_background_title">Background</string>
<string name="lockscreen_custom_background_dialog_title">Choose color</string>
<string name="lockscreen_background_result_successful">Background changed successfully</string>
<string name="lockscreen_background_result_not_successful">Background could not be changed</string>
<string name="lockscreen_background_color_fill">Color fill</string>
<string name="lockscreen_background_custom_image">Custom image</string>
<string name="lockscreen_background_default_wallpaper">Default wallpaper</string>
<string name="lockscreen_background_title">Lockscreen Background</string>
<string name="lock_panel_bond">Change Your Lockscreen Background</string>

Now Save it and Open "ids.xml" and paste this at the bottom of the file.

<item type="id" name="lockscreen_background">false</item>

Now Open "arrays.xml" and paste this at the bottom:-

<string-array name="lockscreen_background_entries">
<item>@string/lockscreen_background_color_fill</item>
<item>@string/lockscreen_background_custom_image</item>
<item>@string/lockscreen_background_default_wallpaper</item>
</string-array>
<string-array name="lockscreen_background_values">
<item>0</item>
<item>1</item>
<item>2</item>
</string-array>
<string-array name="lockscreen_battery_status_entries">
<item>@string/lockscreen_battery_status_charging</item>
<item>@string/lockscreen_battery_status_alwayson</item>
</string-array>
<string-array name="lockscreen_battery_status_values">
<item>0</item>
<item>1</item>
</string-array>

Now recompile Settings and then decompile the newly made settings to get the IDs in public.xml.

Now comes the main part where you have to find the IDs in the files you just pasted in your decompiled settings and start changing those with your new IDs.

First open smali/com/android/settings/cyanogenmod/LockscreenInterface.smali

Line 120: const v14, 0x7f0c09f7 -[B]<public type="string" name="lockscreen_custom_background_dialog_title"

[/B] Line 126: const v14, 0x7f0c0089 -[B]<public type="string" name="ok"[/B]

Line 138: const v14, 0x7f0c0355 -[B]<public type="string" name="cancel"[/B]

Line 485: const v0, 0x7f0c09fc -[B]<public type="string" name="lockscreen_background_default_wallpaper"[/B]

Line 522: const v0, 0x7f0c09fb -[B]<public type="string" name="lockscreen_background_custom_image"[/B]

Line 537: const v0, 0x7f0c09fa -[B]<public type="string" name="lockscreen_background_color_fill"[/B]

Line 666: const v0, 0x7f0c09f8 -[B]<public type="string" name="lockscreen_background_result_successful"[/B]

Line 727: const v0, 0x7f0c09f9 -[B]<public type="string" name="lockscreen_background_result_not_successful"[/B]

Line 748: const v4, 0x7f060057 - [B]<public type="xml" name="lockscreen_interface_settings"[/B]

The line numbers mentioned here are the actual line number where the ID is.

Now recompile back your Settings.apk and make a flashable zip of both of your modded files and flash through recovery.

Please do let me know if something wrong his happening. This is only for Dev and for users who earlier have done other MODs, but not for newbies.

Screenshots of results are attached below.

Do give your feedback and suggestions about the guide for improvements. Special Thanks to Dev Brother [MENTION=4915946]Akhilendra Gadde[/MENTION] for finding my missing lines from my original files. Don't forget to thank him few post below.