Post Reply

[MOD][GUIDE] Lockscreen torch

OP Didact74

17th October 2012, 04:22 PM   |  #1  
Didact74's Avatar
OP Recognized Developer / Recognized Contributor
Flag Lake Shore, MD
Thanks Meter: 1,852
 
609 posts
Join Date:Joined: Sep 2010
Donate to Me
More
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
    :pswitch_0
    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:
.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.




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

Enjoy and hit the Thanks Button!
Attached Files
File Type: zip Torch_files.zip - [Click for QR Code] (188.9 KB, 629 views)
The Following 22 Users Say Thank You to Didact74 For This Useful Post: [ View ]
17th October 2012, 04:30 PM   |  #2  
Humzaman's Avatar
Senior Member
Flag Dallas
Thanks Meter: 440
 
701 posts
Join Date:Joined: Aug 2012
More
So many smilies...

Sent from my SPH-L710 running FreeGS3 v1.0.0 Jellybean
Attached Thumbnails
Click image for larger version

Name:	uploadfromtaptalk1350487831648.jpg
Views:	1948
Size:	65.0 KB
ID:	1408995  
17th October 2012, 04:51 PM   |  #3  
Tornadobarrage's Avatar
Senior Member
Flag New York
Thanks Meter: 9
 
155 posts
Join Date:Joined: Jun 2010
More
Can I flash this on the leaked jelly bean touch wiz?
17th October 2012, 07:01 PM   |  #4  
Didact74's Avatar
OP Recognized Developer / Recognized Contributor
Flag Lake Shore, MD
Thanks Meter: 1,852
 
609 posts
Join Date:Joined: Sep 2010
Donate to Me
More
Quote:
Originally Posted by Humzaman

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.

Quote:
Originally Posted by Tornadobarrage

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.
17th October 2012, 08:54 PM   |  #5  
irock1985's Avatar
Senior Member
Flag SoCal
Thanks Meter: 188
 
718 posts
Join Date:Joined: Jun 2010
More
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
17th October 2012, 10:53 PM   |  #6  
InfiniteReality's Avatar
Senior Member
Flag Lake Charles, LA
Thanks Meter: 43
 
228 posts
Join Date:Joined: Jan 2008
I agree, that is the most missed mod of MIUI for me... Just so convenient to have such easy access to the flashlight!
7th November 2012, 08:06 PM   |  #7  
Senior Member
Thanks Meter: 26
 
126 posts
Join Date:Joined: Feb 2010
I'd love this on Fre3 2.2.

Sent from my SPH-L710 using xda premium
7th November 2012, 09:05 PM   |  #8  
Humzaman's Avatar
Senior Member
Flag Dallas
Thanks Meter: 440
 
701 posts
Join Date:Joined: Aug 2012
More
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
3rd January 2013, 06:04 PM   |  #9  
Senior Member
Marlboro, NJ
Thanks Meter: 119
 
228 posts
Join Date:Joined: Jan 2011
More
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
3rd January 2013, 06:44 PM   |  #10  
razzack3000's Avatar
Member
Thanks Meter: 6
 
63 posts
Join Date:Joined: Jul 2012
Quote:
Originally Posted by Humzaman

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 ----------

Quote:
Originally Posted by Humzaman

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

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

Advanced Search
Display Modes


Top Threads in Sprint Galaxy S III Android Development by ThreadRank