[MOD][GUIDE] Lockscreen torch

Search This thread

Didact74

Senior Member
Sep 2, 2010
609
1,877
Lake Shore, MD
I built this guide for the VW GS3 but I have to assume its extremely close for the Sprint varient as well.

The lockscreen torch will allow you to quickly turn on your flashlight from the lockscreen. Simply hold the home button in for torch, let it go and it will turn off. It is meant to function this way so you dont accidentally turn it on in your pocket or something and forget about it. Not sure who originally wrote the MOD but I have spent some time re-writing it to fit the GS3 based on a dozen or so other tutorials.

After reboot, it will take about 20 seconds before the MOD will engage. Then it will work at will as long as you are on the lockscreen.

I will include the three files that are being modified in the zip below so you can use them in your compare tool.

DEVs if you want to use this in your ROM feel free, just shoot me some credit and some thanks!

Hit the Thanks Button!

Here is the guide.....



First you will need to download the torch file below and drop it in /system/app. This will be in the zip file with the smali files.

We will be working with three smali files inside of android.policy.jar.

Navigate to smali/com/android/internal/policy/impl/KeyguardViewMediator$2.smali

Find the following code and add the part in RED
Code:
    packed-switch v2, :pswitch_data_0

    .line 1172
    :goto_0
   [COLOR="Red"][B] :pswitch_0
[/B][/COLOR]    return-void

Find the 13 : pswitch_ lines and increase them by 1. For example
Code:
:pswitch_0 becomes :pswitch_1
:pswitch_1 becomes :pswitch_2
:pswitch_2 becomes :pswitch_3
:pswitch_3 becomes :pswitch_4
:pswitch_4 becomes :pswitch_5
:pswitch_5 becomes :pswitch_6
:pswitch_6 becomes :pswitch_7
:pswitch_7 becomes :pswitch_8
:pswitch_8 becomes :pswitch_9
:pswitch_9 becomes :pswitch_a
:pswitch_a becomes :pswitch_b
:pswitch_b becomes :pswitch_c
:pswitch_c becomes :pswitch_d

Find the following code
Code:
invoke-static {v0}, Lcom/android/internal/policy/impl/KeyguardViewMediator;->access$300(Lcom/android/internal/policy/impl/KeyguardViewMediator;)V

    .line 1169
    monitor-exit v1

    goto :goto_0

Add the following directly after
Code:
.line 974
    :pswitch_e
    iget-object v2, p0, Lcom/android/internal/policy/impl/KeyguardViewMediator$2;->this$0:Lcom/android/internal/policy/impl/KeyguardViewMediator;

    iget v3, p1, Landroid/os/Message;->arg1:I

    if-eqz v3, :cond_2

    move v3, v0

    :goto_3
    #calls: Lcom/android/internal/policy/impl/KeyguardViewMediator;->handleSetTorch(Z)V
    invoke-static {v2, v3}, Lcom/android/internal/policy/impl/KeyguardViewMediator;->access$1900(Lcom/android/internal/policy/impl/KeyguardViewMediator;Z)V

    goto :goto_0

    :cond_2
    move v3, v1

    goto :goto_3

Find the "nop' at the end and add another one right below it
Code:
throw v0

    .line 1129
    nop

    nop

Find the stack of : pswitch_ lines at the end of the smali and delete : pswitch_0
Then add the following so the entire stack will end up looking like this
Code:
.packed-switch 0x1

        :pswitch_1
        :pswitch_2
        :pswitch_3
        :pswitch_4
        :pswitch_5
        :pswitch_6
        :pswitch_7
        :pswitch_8
        :pswitch_9
        :pswitch_a
        :pswitch_b
        :pswitch_c
        :pswitch_d
        :pswitch_0
        :pswitch_0
        :pswitch_0
        :pswitch_0
        :pswitch_0
        :pswitch_0
        :pswitch_e
    .end packed-switch
.end method

Thats it for KeyguardViewMediator$2.smali. Save and close the file.

Navigate to smali/com/android/internal/policy/impl/KeyguardViewMediator.smali

Find the following code
Code:
.field private static final SET_HIDDEN:I = 0xc

Add this right after
Code:
[hide]
.field private static final SET_TORCH:I = 0x14

Find the following code
Code:
.field private mTelephonyManager:Landroid/telephony/TelephonyManager;

Add this right after
Code:
.field private mTorchEnabled:Z

.field private mTorchStateChanged:Z

Find the following code
Code:
const/4 v10, 0x0

    const/4 v9, 0x1

    .line 301
    invoke-direct {p0}, Ljava/lang/Object;-><init>()V

Add this after
Code:
iput-boolean v9, p0, Lcom/android/internal/policy/impl/KeyguardViewMediator;->mTorchEnabled:Z

Find the following code
Code:
    iput-object v0, p0, Lcom/android/internal/policy/impl/KeyguardViewMediator;->mHandler:Landroid/os/Handler;

    .line 302
    iput-object p1, p0, Lcom/android/internal/policy/impl/KeyguardViewMediator;->mContext:Landroid/content/Context;

    .line 304
    iput-object p3, p0, Lcom/android/internal/policy/impl/KeyguardViewMediator;->mRealPowerManager:Landroid/os/LocalPowerManager;

Add this after
Code:
    iput-boolean v10, p0, Lcom/android/internal/policy/impl/KeyguardViewMediator;->mTorchEnabled:Z

    .line 1188
    iput-boolean v10, p0, Lcom/android/internal/policy/impl/KeyguardViewMediator;->mTorchStateChanged:Z

Find this method
Code:
.method static synthetic access$200(Lcom/android/internal/policy/impl/KeyguardViewMediator;)V

Add this entire NEW method RIGHT BEFORE it.
Code:
.method static synthetic access$1900(Lcom/android/internal/policy/impl/KeyguardViewMediator;Z)V
    .locals 0
    .parameter "x0"
    .parameter "x1"

    .prologue
    invoke-direct {p0, p1}, Lcom/android/internal/policy/impl/KeyguardViewMediator;->handleSetTorch(Z)V

    return-void
.end method

Find the following code
Code:
const/4 v0, 0x1

    invoke-direct {p0, v0}, Lcom/android/internal/policy/impl/KeyguardViewMediator;->adjustLocked(Z)V

    .line 1315
    monitor-exit p0

Add this right after
Code:
invoke-direct {p0}, Lcom/android/internal/policy/impl/KeyguardViewMediator;->resetTorchState()V

Find the following code
Code:
.line 1496
    iget-object v0, p0, Lcom/android/internal/policy/impl/KeyguardViewMediator;->mKeyguardViewManager:Lcom/android/internal/policy/impl/KeyguardViewManager;

    invoke-virtual {v0}, Lcom/android/internal/policy/impl/KeyguardViewManager;->onScreenTurnedOff()V

    .line 1497
    monitor-exit p0

Add this directly after
Code:
invoke-direct {p0}, Lcom/android/internal/policy/impl/KeyguardViewMediator;->resetTorchState()V

Find the following code
Code:
iput-boolean p1, p0, Lcom/android/internal/policy/impl/KeyguardViewMediator;->mHidden:Z

    .line 611
    invoke-direct {p0}, Lcom/android/internal/policy/impl/KeyguardViewMediator;->adjustUserActivityLocked()V

    .line 612
    invoke-direct {p0}, Lcom/android/internal/policy/impl/KeyguardViewMediator;->adjustStatusBarLocked()V

Add this directly after
Code:
invoke-direct {p0}, Lcom/android/internal/policy/impl/KeyguardViewMediator;->resetTorchState()V

Find the following code
Code:
:try_end_0
    .catchall {:try_start_0 .. :try_end_0} :catchall_0

    throw v0
.end method

Add this ENTIRE NEW METHOD directly after
Code:
.method private handleSetTorch(Z)V
    .locals 6
    .parameter "enable"

    .prologue
    const/4 v5, 0x0

    const/4 v4, 0x1

    .line 504
    :try_start_0
    iget-boolean v1, p0, Lcom/android/internal/policy/impl/KeyguardViewMediator;->mTorchStateChanged:Z

    if-nez v1, :cond_1

    .line 505
    iput-boolean v1, p0, Lcom/android/internal/policy/impl/KeyguardViewMediator;->mTorchEnabled:Z

    .line 506
    const/4 v1, 0x1

    iput-boolean v1, p0, Lcom/android/internal/policy/impl/KeyguardViewMediator;->mTorchStateChanged:Z

    .line 515
    :cond_0
    :goto_0
    return-void

    .line 507
    :cond_1
    iget-boolean v1, p0, Lcom/android/internal/policy/impl/KeyguardViewMediator;->mTorchEnabled:Z

    if-eq v1, p1, :cond_0

    .line 508
    iput-boolean p1, p0, Lcom/android/internal/policy/impl/KeyguardViewMediator;->mTorchEnabled:Z

    .line 509
    new-instance v0, Landroid/content/Intent;

    const-string v1, "net.cactii.flash2.TOGGLE_FLASHLIGHT"

    invoke-direct {v0, v1}, Landroid/content/Intent;-><init>(Ljava/lang/String;)V

    .line 510
    .local v0, intent:Landroid/content/Intent;
    const-string v1, "net.cactii.flash2.EXTRA_DISABLE_NOTIFICATION"

    const/4 v2, 0x1

    invoke-virtual {v0, v1, v2}, Landroid/content/Intent;->putExtra(Ljava/lang/String;Z)Landroid/content/Intent;

    .line 511
    iget-object v1, p0, Lcom/android/internal/policy/impl/KeyguardViewMediator;->mContext:Landroid/content/Context;

    invoke-virtual {v1, v0}, Landroid/content/Context;->sendBroadcast(Landroid/content/Intent;)V
    :try_end_0
    .catch Ljava/lang/Exception; {:try_start_0 .. :try_end_0} :catch_0

    goto :goto_0

    .line 514
    .end local v0           #intent:Landroid/content/Intent;
    :catch_0
    move-exception v1

    goto :goto_0
.end method

Find the following code
Code:
:goto_1
    :try_start_2
    iget-object v0, p0, Lcom/android/internal/policy/impl/KeyguardViewMediator;->mShowKeyguardWakeLock:Landroid/os/PowerManager$WakeLock;

    invoke-virtual {v0}, Landroid/os/PowerManager$WakeLock;->release()V

Add the following after
Code:
.line 995
    const/4 v0, 0x1

    iput-boolean v0, p0, Lcom/android/internal/policy/impl/KeyguardViewMediator;->mTorchStateChanged:Z

Find the following code
Code:
iget-object v1, p0, Lcom/android/internal/policy/impl/KeyguardViewMediator;->mHandler:Landroid/os/Handler;

    invoke-virtual {v1, v0}, Landroid/os/Handler;->sendMessage(Landroid/os/Message;)Z

    .line 752
    return-void
.end method

Add this ENTIRE NEW METHOD after
Code:
.method private resetTorchState()V
    .locals 1

    .prologue
    .line 1193
    iget-boolean v0, p0, Lcom/android/internal/policy/impl/KeyguardViewMediator;->mTorchStateChanged:Z

    if-eqz v0, :cond_0

    .line 1194
    const/4 v0, 0x0

    invoke-direct {p0, v0}, Lcom/android/internal/policy/impl/KeyguardViewMediator;->handleSetTorch(Z)V

    .line 1196
    :cond_0
    return-void
.end method

Find the following code
Code:
:try_end_3
    .catchall {:try_start_3 .. :try_end_3} :catchall_0

    goto :goto_1
.end method

Add this ENTIRE NEW METHOD after
Code:
.method public setTorch(Z)V
    .locals 5
    .parameter "enable"

    .prologue
    const/16 v4, 0x14

    const/4 v3, 0x0

    .line 1155
    iget-boolean v1, p0, Lcom/android/internal/policy/impl/KeyguardViewMediator;->mScreenOn:Z

    if-eqz v1, :cond_0

    .line 1157
    iget-object v1, p0, Lcom/android/internal/policy/impl/KeyguardViewMediator;->mHandler:Landroid/os/Handler;

    invoke-virtual {v1, v4}, Landroid/os/Handler;->removeMessages(I)V

    .line 1158
    iget-object v1, p0, Lcom/android/internal/policy/impl/KeyguardViewMediator;->mHandler:Landroid/os/Handler;

    if-eqz p1, :cond_1

    const/4 v2, 0x1

    :goto_0
    invoke-virtual {v1, v4, v2, v3}, Landroid/os/Handler;->obtainMessage(III)Landroid/os/Message;

    move-result-object v0

    .line 1159
    .local v0, msg:Landroid/os/Message;
    iget-object v1, p0, Lcom/android/internal/policy/impl/KeyguardViewMediator;->mHandler:Landroid/os/Handler;

    invoke-virtual {v1, v0}, Landroid/os/Handler;->sendMessage(Landroid/os/Message;)Z

    .line 1161
    .end local v0           #msg:Landroid/os/Message;
    :cond_0
    return-void

    :cond_1
    move v2, v3

    .line 1158
    goto :goto_0
.end method

Thats it for KeyguardViewMediator.smali. Save the file and close.

Navigate to smali/com/android/internal/policy/impl/PhoneWindowManager.smali

Find the following code
Code:
const/16 v41, 0x3

    move/from16 v0, v22

    move/from16 v1, v41

Change the next line to the following
Code:
if-ne v0, v1, :cond_2b

Find the following code
Code:
invoke-static/range {v41 .. v42}, Landroid/util/safelog/Log;->i(Ljava/lang/String;Ljava/lang/String;)I

    goto :goto_a

    :cond_20

Change the next line to the following
Code:
if-eqz v4, :cond_26

Find the following code
Code:
const/16 v41, 0x7d9

    move/from16 v0, v38

    move/from16 v1, v41

Change the next line to the following
Code:
if-ne v0, v1, :cond_23

Directly after that last change in code, add the following
Code:
:cond_21
    move-object/from16 v0, p0

    iget-object v0, v0, Lcom/android/internal/policy/impl/PhoneWindowManager;->mKeyguardMediator:Lcom/android/internal/policy/impl/KeyguardViewMediator;

    move-object/from16 v41, v0

    invoke-virtual/range {v41 .. v41}, Lcom/android/internal/policy/impl/KeyguardViewMediator;->isShowingAndNotHidden()Z

    move-result v41

    if-eqz v41, :cond_22

    .line 1275
    move-object/from16 v0, p0

    iget-object v0, v0, Lcom/android/internal/policy/impl/PhoneWindowManager;->mKeyguardMediator:Lcom/android/internal/policy/impl/KeyguardViewMediator;

    move-object/from16 v41, v0

    move-object/from16 v0, v41

    move v1, v8

    invoke-virtual {v0, v1}, Lcom/android/internal/policy/impl/KeyguardViewMediator;->setTorch(Z)V

    .line 1276
    rem-int/lit8 v41, v31, 0xf

    if-nez v41, :cond_22

    .line 1277
    move-object/from16 v0, p0

    iget-object v0, v0, Lcom/android/internal/policy/impl/PhoneWindowManager;->mKeyguardMediator:Lcom/android/internal/policy/impl/KeyguardViewMediator;

    move-object/from16 v41, v0

    invoke-virtual/range {v41 .. v41}, Lcom/android/internal/policy/impl/KeyguardViewMediator;->pokeWakelock()V

    :cond_22

Here is a sort of tricky part. Starting right after the above code change you need to comb the rest of this entire method for all references to ":cond_X" and increment them by one. THERE ARE A LOT! Take your time and find them all. For example

Code:
:cond_23 becomes :cond_24
:cond_29 becomes :cond_2a
:cond_3f becomes :cond_40
....etc.  MAKE SURE YOU FIND THEM ALL!  The last one you change should be :cond_47.

[/hide]

Thats it. Save all fines, recompile and push to /system/framework.

Enjoy and hit the Thanks Button!
 

Attachments

  • Torch_files.zip
    188.9 KB · Views: 662

Humzaman

Senior Member
Aug 21, 2012
701
439
27
Dallas
So many smilies...

Sent from my SPH-L710 running FreeGS3 v1.0.0 Jellybean
 

Attachments

  • uploadfromtaptalk1350487831648.jpg
    uploadfromtaptalk1350487831648.jpg
    65 KB · Views: 1,988

Didact74

Senior Member
Sep 2, 2010
609
1,877
Lake Shore, MD
So many smilies...

Sent from my SPH-L710 running FreeGS3 v1.0.0 Jellybean

Turn off the code in your settings or just know that the smilies are semicolons followed by a lower case P.

Can I flash this on the leaked jelly bean touch wiz?

This is not a flashable zip. It's just the files needed to compare and build the mod. It will work with JB and modifying the code I have attached a little.
 

irock1985

Senior Member
Jun 11, 2010
828
206
SoCal
Hope to see this on all roms soon... I love this feature on MIUI and would love to see it on TW
Maybe we could even get it like MIUI to where as if you press the power button with the light on it will stay on
 

Humzaman

Senior Member
Aug 21, 2012
701
439
27
Dallas
Yo Didact, just wondering... do you play Halo? Or read the books?

_____________________________________________________
Sent from my SPH-L710 running FreeGS3 v1.0.0
"Wake me... when you need me." -Master Chief John 117
 

geekasso

Senior Member
Jan 4, 2011
274
126
USA
Samsung Galaxy S22 Ultra
This is probably a noob question, but I am trying to use your guide for the Samsung Note II and the android.policy.jar does not contain the smali files. I cannot find the smali files anywhere as a matter of fact. Also to push them back to framework, do I just copy them via recovery using the updater-script or do they get injected into the jar file?

PS: I opened the android.policy.jar with winrar
 

razzack3000

Senior Member
Jul 27, 2012
88
11
Yo Didact, just wondering... do you play Halo? Or read the books?

_____________________________________________________
Sent from my SPH-L710 running FreeGS3 v1.0.0
"Wake me... when you need me." -Master Chief John 117

I do..

Sent from my SPH-L710 using xda premium

---------- Post added at 07:44 PM ---------- Previous post was at 07:41 PM ----------

Yo Didact, just wondering... do you play Halo? Or read the books?

_____________________________________________________
Sent from my SPH-L710 running FreeGS3 v1.0.0
"Wake me... when you need me." -Master Chief John 117

I just beat the campaign legendary solo with 5 skulls

Sent from my SPH-L710 using xda premium
 

geekasso

Senior Member
Jan 4, 2011
274
126
USA
Samsung Galaxy S22 Ultra
OK, so I got the smali files extracted. When I merge them with the android.policy.jar from note II, i get the optimizing apps screen followed by a reboot. I suspect the smali files in your ZIP may be specific to GS3.

Question: If I follow the guide to make the changes to the smali files directly from the Note II's android.policy.jar instead of using your files to merge, should that work or are these changes specific to the GS3?

Thanks!
 

evolutioncsr

Senior Member
Apr 12, 2008
531
859
Arlington, TX
Red Magic 6S Pro
OK, so I got the smali files extracted. When I merge them with the android.policy.jar from note II, i get the optimizing apps screen followed by a reboot. I suspect the smali files in your ZIP may be specific to GS3.

Question: If I follow the guide to make the changes to the smali files directly from the Note II's android.policy.jar instead of using your files to merge, should that work or are these changes specific to the GS3?

Thanks!

You can not just make the changes as is directly to the Note or merge it. You can follow the guide to port it to your device but the registers are not the same e.g. iput-boolean v10, p0, could be iput-boolean v7, p0, on your device. Assuming you already know that and how to fix it and are on TW Jellybean this guide should help you port. :good:
 
  • Like
Reactions: geekasso

jim256

Senior Member
Nov 26, 2007
900
21
I've been looking EVERYWHERE for this great feature...Does anyone know if this would work on the Galaxy Note II (AT&T)?

Thank you
 

metalfan78

Senior Member
Jan 30, 2010
5,009
2,476
Littleton, CO
After getting into this a little it's way above my head. There are too many differences between Verizon and Sprint. I get a little lost. Lol
 

metalfan78

Senior Member
Jan 30, 2010
5,009
2,476
Littleton, CO
Thanks CNexus. Hey Didact74, do you think you can hook me up with the changes for MD4? I'd like to diff what I have so I can learn a little more about what I'm doing. Thanks.
 

Top Liked Posts

  • There are no posts matching your filters.
  • 22
    I built this guide for the VW GS3 but I have to assume its extremely close for the Sprint varient as well.

    The lockscreen torch will allow you to quickly turn on your flashlight from the lockscreen. Simply hold the home button in for torch, let it go and it will turn off. It is meant to function this way so you dont accidentally turn it on in your pocket or something and forget about it. Not sure who originally wrote the MOD but I have spent some time re-writing it to fit the GS3 based on a dozen or so other tutorials.

    After reboot, it will take about 20 seconds before the MOD will engage. Then it will work at will as long as you are on the lockscreen.

    I will include the three files that are being modified in the zip below so you can use them in your compare tool.

    DEVs if you want to use this in your ROM feel free, just shoot me some credit and some thanks!

    Hit the Thanks Button!

    Here is the guide.....



    First you will need to download the torch file below and drop it in /system/app. This will be in the zip file with the smali files.

    We will be working with three smali files inside of android.policy.jar.

    Navigate to smali/com/android/internal/policy/impl/KeyguardViewMediator$2.smali

    Find the following code and add the part in RED
    Code:
        packed-switch v2, :pswitch_data_0
    
        .line 1172
        :goto_0
       [COLOR="Red"][B] :pswitch_0
    [/B][/COLOR]    return-void

    Find the 13 : pswitch_ lines and increase them by 1. For example
    Code:
    :pswitch_0 becomes :pswitch_1
    :pswitch_1 becomes :pswitch_2
    :pswitch_2 becomes :pswitch_3
    :pswitch_3 becomes :pswitch_4
    :pswitch_4 becomes :pswitch_5
    :pswitch_5 becomes :pswitch_6
    :pswitch_6 becomes :pswitch_7
    :pswitch_7 becomes :pswitch_8
    :pswitch_8 becomes :pswitch_9
    :pswitch_9 becomes :pswitch_a
    :pswitch_a becomes :pswitch_b
    :pswitch_b becomes :pswitch_c
    :pswitch_c becomes :pswitch_d

    Find the following code
    Code:
    invoke-static {v0}, Lcom/android/internal/policy/impl/KeyguardViewMediator;->access$300(Lcom/android/internal/policy/impl/KeyguardViewMediator;)V
    
        .line 1169
        monitor-exit v1
    
        goto :goto_0

    Add the following directly after
    Code:
    .line 974
        :pswitch_e
        iget-object v2, p0, Lcom/android/internal/policy/impl/KeyguardViewMediator$2;->this$0:Lcom/android/internal/policy/impl/KeyguardViewMediator;
    
        iget v3, p1, Landroid/os/Message;->arg1:I
    
        if-eqz v3, :cond_2
    
        move v3, v0
    
        :goto_3
        #calls: Lcom/android/internal/policy/impl/KeyguardViewMediator;->handleSetTorch(Z)V
        invoke-static {v2, v3}, Lcom/android/internal/policy/impl/KeyguardViewMediator;->access$1900(Lcom/android/internal/policy/impl/KeyguardViewMediator;Z)V
    
        goto :goto_0
    
        :cond_2
        move v3, v1
    
        goto :goto_3

    Find the "nop' at the end and add another one right below it
    Code:
    throw v0
    
        .line 1129
        nop
    
        nop

    Find the stack of : pswitch_ lines at the end of the smali and delete : pswitch_0
    Then add the following so the entire stack will end up looking like this
    Code:
    .packed-switch 0x1
    
            :pswitch_1
            :pswitch_2
            :pswitch_3
            :pswitch_4
            :pswitch_5
            :pswitch_6
            :pswitch_7
            :pswitch_8
            :pswitch_9
            :pswitch_a
            :pswitch_b
            :pswitch_c
            :pswitch_d
            :pswitch_0
            :pswitch_0
            :pswitch_0
            :pswitch_0
            :pswitch_0
            :pswitch_0
            :pswitch_e
        .end packed-switch
    .end method

    Thats it for KeyguardViewMediator$2.smali. Save and close the file.

    Navigate to smali/com/android/internal/policy/impl/KeyguardViewMediator.smali

    Find the following code
    Code:
    .field private static final SET_HIDDEN:I = 0xc

    Add this right after
    Code:
    [hide]
    .field private static final SET_TORCH:I = 0x14

    Find the following code
    Code:
    .field private mTelephonyManager:Landroid/telephony/TelephonyManager;

    Add this right after
    Code:
    .field private mTorchEnabled:Z
    
    .field private mTorchStateChanged:Z

    Find the following code
    Code:
    const/4 v10, 0x0
    
        const/4 v9, 0x1
    
        .line 301
        invoke-direct {p0}, Ljava/lang/Object;-><init>()V

    Add this after
    Code:
    iput-boolean v9, p0, Lcom/android/internal/policy/impl/KeyguardViewMediator;->mTorchEnabled:Z

    Find the following code
    Code:
        iput-object v0, p0, Lcom/android/internal/policy/impl/KeyguardViewMediator;->mHandler:Landroid/os/Handler;
    
        .line 302
        iput-object p1, p0, Lcom/android/internal/policy/impl/KeyguardViewMediator;->mContext:Landroid/content/Context;
    
        .line 304
        iput-object p3, p0, Lcom/android/internal/policy/impl/KeyguardViewMediator;->mRealPowerManager:Landroid/os/LocalPowerManager;

    Add this after
    Code:
        iput-boolean v10, p0, Lcom/android/internal/policy/impl/KeyguardViewMediator;->mTorchEnabled:Z
    
        .line 1188
        iput-boolean v10, p0, Lcom/android/internal/policy/impl/KeyguardViewMediator;->mTorchStateChanged:Z

    Find this method
    Code:
    .method static synthetic access$200(Lcom/android/internal/policy/impl/KeyguardViewMediator;)V

    Add this entire NEW method RIGHT BEFORE it.
    Code:
    .method static synthetic access$1900(Lcom/android/internal/policy/impl/KeyguardViewMediator;Z)V
        .locals 0
        .parameter "x0"
        .parameter "x1"
    
        .prologue
        invoke-direct {p0, p1}, Lcom/android/internal/policy/impl/KeyguardViewMediator;->handleSetTorch(Z)V
    
        return-void
    .end method

    Find the following code
    Code:
    const/4 v0, 0x1
    
        invoke-direct {p0, v0}, Lcom/android/internal/policy/impl/KeyguardViewMediator;->adjustLocked(Z)V
    
        .line 1315
        monitor-exit p0

    Add this right after
    Code:
    invoke-direct {p0}, Lcom/android/internal/policy/impl/KeyguardViewMediator;->resetTorchState()V

    Find the following code
    Code:
    .line 1496
        iget-object v0, p0, Lcom/android/internal/policy/impl/KeyguardViewMediator;->mKeyguardViewManager:Lcom/android/internal/policy/impl/KeyguardViewManager;
    
        invoke-virtual {v0}, Lcom/android/internal/policy/impl/KeyguardViewManager;->onScreenTurnedOff()V
    
        .line 1497
        monitor-exit p0

    Add this directly after
    Code:
    invoke-direct {p0}, Lcom/android/internal/policy/impl/KeyguardViewMediator;->resetTorchState()V

    Find the following code
    Code:
    iput-boolean p1, p0, Lcom/android/internal/policy/impl/KeyguardViewMediator;->mHidden:Z
    
        .line 611
        invoke-direct {p0}, Lcom/android/internal/policy/impl/KeyguardViewMediator;->adjustUserActivityLocked()V
    
        .line 612
        invoke-direct {p0}, Lcom/android/internal/policy/impl/KeyguardViewMediator;->adjustStatusBarLocked()V

    Add this directly after
    Code:
    invoke-direct {p0}, Lcom/android/internal/policy/impl/KeyguardViewMediator;->resetTorchState()V

    Find the following code
    Code:
    :try_end_0
        .catchall {:try_start_0 .. :try_end_0} :catchall_0
    
        throw v0
    .end method

    Add this ENTIRE NEW METHOD directly after
    Code:
    .method private handleSetTorch(Z)V
        .locals 6
        .parameter "enable"
    
        .prologue
        const/4 v5, 0x0
    
        const/4 v4, 0x1
    
        .line 504
        :try_start_0
        iget-boolean v1, p0, Lcom/android/internal/policy/impl/KeyguardViewMediator;->mTorchStateChanged:Z
    
        if-nez v1, :cond_1
    
        .line 505
        iput-boolean v1, p0, Lcom/android/internal/policy/impl/KeyguardViewMediator;->mTorchEnabled:Z
    
        .line 506
        const/4 v1, 0x1
    
        iput-boolean v1, p0, Lcom/android/internal/policy/impl/KeyguardViewMediator;->mTorchStateChanged:Z
    
        .line 515
        :cond_0
        :goto_0
        return-void
    
        .line 507
        :cond_1
        iget-boolean v1, p0, Lcom/android/internal/policy/impl/KeyguardViewMediator;->mTorchEnabled:Z
    
        if-eq v1, p1, :cond_0
    
        .line 508
        iput-boolean p1, p0, Lcom/android/internal/policy/impl/KeyguardViewMediator;->mTorchEnabled:Z
    
        .line 509
        new-instance v0, Landroid/content/Intent;
    
        const-string v1, "net.cactii.flash2.TOGGLE_FLASHLIGHT"
    
        invoke-direct {v0, v1}, Landroid/content/Intent;-><init>(Ljava/lang/String;)V
    
        .line 510
        .local v0, intent:Landroid/content/Intent;
        const-string v1, "net.cactii.flash2.EXTRA_DISABLE_NOTIFICATION"
    
        const/4 v2, 0x1
    
        invoke-virtual {v0, v1, v2}, Landroid/content/Intent;->putExtra(Ljava/lang/String;Z)Landroid/content/Intent;
    
        .line 511
        iget-object v1, p0, Lcom/android/internal/policy/impl/KeyguardViewMediator;->mContext:Landroid/content/Context;
    
        invoke-virtual {v1, v0}, Landroid/content/Context;->sendBroadcast(Landroid/content/Intent;)V
        :try_end_0
        .catch Ljava/lang/Exception; {:try_start_0 .. :try_end_0} :catch_0
    
        goto :goto_0
    
        .line 514
        .end local v0           #intent:Landroid/content/Intent;
        :catch_0
        move-exception v1
    
        goto :goto_0
    .end method

    Find the following code
    Code:
    :goto_1
        :try_start_2
        iget-object v0, p0, Lcom/android/internal/policy/impl/KeyguardViewMediator;->mShowKeyguardWakeLock:Landroid/os/PowerManager$WakeLock;
    
        invoke-virtual {v0}, Landroid/os/PowerManager$WakeLock;->release()V

    Add the following after
    Code:
    .line 995
        const/4 v0, 0x1
    
        iput-boolean v0, p0, Lcom/android/internal/policy/impl/KeyguardViewMediator;->mTorchStateChanged:Z

    Find the following code
    Code:
    iget-object v1, p0, Lcom/android/internal/policy/impl/KeyguardViewMediator;->mHandler:Landroid/os/Handler;
    
        invoke-virtual {v1, v0}, Landroid/os/Handler;->sendMessage(Landroid/os/Message;)Z
    
        .line 752
        return-void
    .end method

    Add this ENTIRE NEW METHOD after
    Code:
    .method private resetTorchState()V
        .locals 1
    
        .prologue
        .line 1193
        iget-boolean v0, p0, Lcom/android/internal/policy/impl/KeyguardViewMediator;->mTorchStateChanged:Z
    
        if-eqz v0, :cond_0
    
        .line 1194
        const/4 v0, 0x0
    
        invoke-direct {p0, v0}, Lcom/android/internal/policy/impl/KeyguardViewMediator;->handleSetTorch(Z)V
    
        .line 1196
        :cond_0
        return-void
    .end method

    Find the following code
    Code:
    :try_end_3
        .catchall {:try_start_3 .. :try_end_3} :catchall_0
    
        goto :goto_1
    .end method

    Add this ENTIRE NEW METHOD after
    Code:
    .method public setTorch(Z)V
        .locals 5
        .parameter "enable"
    
        .prologue
        const/16 v4, 0x14
    
        const/4 v3, 0x0
    
        .line 1155
        iget-boolean v1, p0, Lcom/android/internal/policy/impl/KeyguardViewMediator;->mScreenOn:Z
    
        if-eqz v1, :cond_0
    
        .line 1157
        iget-object v1, p0, Lcom/android/internal/policy/impl/KeyguardViewMediator;->mHandler:Landroid/os/Handler;
    
        invoke-virtual {v1, v4}, Landroid/os/Handler;->removeMessages(I)V
    
        .line 1158
        iget-object v1, p0, Lcom/android/internal/policy/impl/KeyguardViewMediator;->mHandler:Landroid/os/Handler;
    
        if-eqz p1, :cond_1
    
        const/4 v2, 0x1
    
        :goto_0
        invoke-virtual {v1, v4, v2, v3}, Landroid/os/Handler;->obtainMessage(III)Landroid/os/Message;
    
        move-result-object v0
    
        .line 1159
        .local v0, msg:Landroid/os/Message;
        iget-object v1, p0, Lcom/android/internal/policy/impl/KeyguardViewMediator;->mHandler:Landroid/os/Handler;
    
        invoke-virtual {v1, v0}, Landroid/os/Handler;->sendMessage(Landroid/os/Message;)Z
    
        .line 1161
        .end local v0           #msg:Landroid/os/Message;
        :cond_0
        return-void
    
        :cond_1
        move v2, v3
    
        .line 1158
        goto :goto_0
    .end method

    Thats it for KeyguardViewMediator.smali. Save the file and close.

    Navigate to smali/com/android/internal/policy/impl/PhoneWindowManager.smali

    Find the following code
    Code:
    const/16 v41, 0x3
    
        move/from16 v0, v22
    
        move/from16 v1, v41

    Change the next line to the following
    Code:
    if-ne v0, v1, :cond_2b

    Find the following code
    Code:
    invoke-static/range {v41 .. v42}, Landroid/util/safelog/Log;->i(Ljava/lang/String;Ljava/lang/String;)I
    
        goto :goto_a
    
        :cond_20

    Change the next line to the following
    Code:
    if-eqz v4, :cond_26

    Find the following code
    Code:
    const/16 v41, 0x7d9
    
        move/from16 v0, v38
    
        move/from16 v1, v41

    Change the next line to the following
    Code:
    if-ne v0, v1, :cond_23

    Directly after that last change in code, add the following
    Code:
    :cond_21
        move-object/from16 v0, p0
    
        iget-object v0, v0, Lcom/android/internal/policy/impl/PhoneWindowManager;->mKeyguardMediator:Lcom/android/internal/policy/impl/KeyguardViewMediator;
    
        move-object/from16 v41, v0
    
        invoke-virtual/range {v41 .. v41}, Lcom/android/internal/policy/impl/KeyguardViewMediator;->isShowingAndNotHidden()Z
    
        move-result v41
    
        if-eqz v41, :cond_22
    
        .line 1275
        move-object/from16 v0, p0
    
        iget-object v0, v0, Lcom/android/internal/policy/impl/PhoneWindowManager;->mKeyguardMediator:Lcom/android/internal/policy/impl/KeyguardViewMediator;
    
        move-object/from16 v41, v0
    
        move-object/from16 v0, v41
    
        move v1, v8
    
        invoke-virtual {v0, v1}, Lcom/android/internal/policy/impl/KeyguardViewMediator;->setTorch(Z)V
    
        .line 1276
        rem-int/lit8 v41, v31, 0xf
    
        if-nez v41, :cond_22
    
        .line 1277
        move-object/from16 v0, p0
    
        iget-object v0, v0, Lcom/android/internal/policy/impl/PhoneWindowManager;->mKeyguardMediator:Lcom/android/internal/policy/impl/KeyguardViewMediator;
    
        move-object/from16 v41, v0
    
        invoke-virtual/range {v41 .. v41}, Lcom/android/internal/policy/impl/KeyguardViewMediator;->pokeWakelock()V
    
        :cond_22

    Here is a sort of tricky part. Starting right after the above code change you need to comb the rest of this entire method for all references to ":cond_X" and increment them by one. THERE ARE A LOT! Take your time and find them all. For example

    Code:
    :cond_23 becomes :cond_24
    :cond_29 becomes :cond_2a
    :cond_3f becomes :cond_40
    ....etc.  MAKE SURE YOU FIND THEM ALL!  The last one you change should be :cond_47.

    [/hide]

    Thats it. Save all fines, recompile and push to /system/framework.

    Enjoy and hit the Thanks Button!
    3
    It might help if you call them like this
    @rompnit @Didact74
    2
    The new torch mod incorporates the already existing logic and settings built into the rom. There are a few missing pieces on md4 but me7 is ready to go out of the box. Im out of town for a long weekend. I will post up some help when I get back.
    1
    OK, so I got the smali files extracted. When I merge them with the android.policy.jar from note II, i get the optimizing apps screen followed by a reboot. I suspect the smali files in your ZIP may be specific to GS3.

    Question: If I follow the guide to make the changes to the smali files directly from the Note II's android.policy.jar instead of using your files to merge, should that work or are these changes specific to the GS3?

    Thanks!

    You can not just make the changes as is directly to the Note or merge it. You can follow the guide to port it to your device but the registers are not the same e.g. iput-boolean v10, p0, could be iput-boolean v7, p0, on your device. Assuming you already know that and how to fix it and are on TW Jellybean this guide should help you port. :good:
    1
    Thanks Didact74, you are the man! I'm definitely adding this to my rom.

    I just started this mod and on the sprint gs3 the first step is in KeyguardViewMediator$4. I will keep working on this, but I wont have much time today, just thought some people would like to know.