[Galaxy Note GT-N7000 Themes and Apps] majdinj:
This mod will make you able to have torch flash light while you are on LockScreen by long pressing on the home button...!!!​

Actual mod was done by RobbieHood and eybee1970

Needed tools:

1) Backsmali/Smali program from here

2) Notepad++ program from here

3) WinRAR or 7-zip archiver

The procedure:

- Backsmali android.policy.jar

- Navigate to classout/com/android/internal/policy/impl/ folder

- We will be working on 3 smali files:

KeyguardViewMediator$4.smali

- Search for "packed-switch" and add the blue line just above "return-void":

.line 1255
iget v2, p1, Landroid/os/Message;->what:I

packed-switch v2, :pswitch_data_72

.line 1298
:goto_7
[B][COLOR="Blue"]:pswitch_7[/COLOR][/B]
return-void

.line 1257

- Search for ":catchall" and add these lines above it:

.line 1295
monitor-exit v1

goto :goto_[B][COLOR="Red"]7[/COLOR][/B]

[B][COLOR="Blue"] :pswitch_6e
iget-object v2, p0, Lcom/android/internal/policy/impl/KeyguardViewMediator$4;->this$0:Lcom/android/internal/policy/impl/KeyguardViewMediator;

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

if-eqz v3, :cond_majdi

move v3, v0

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

goto :goto_[COLOR="Red"]7[/COLOR]

:cond_majdi
move v3, v1

goto :goto_nj[/COLOR][/B]

:catchall_7b
move-exception v0

monitor-exit v1

- Search for "nop" and another "nop" line bellow it (don't forget to leave empty line in between):

.line 1255
nop

[B][COLOR="Blue"]nop[/COLOR][/B]

- Now go to the end of smali and add these switches above ".end packed-switch" line:

:pswitch_data_72
.packed-switch 0x1
:pswitch_8
:pswitch_10
:pswitch_16
:pswitch_1c
:pswitch_22
:pswitch_28
:pswitch_2e
:pswitch_38
:pswitch_40
:pswitch_4c
:pswitch_52
:pswitch_58
:pswitch_64
[B][COLOR="Blue"]:pswitch_7
:pswitch_7
:pswitch_7
:pswitch_7
:pswitch_7
:pswitch_7
:pswitch_6e[/COLOR][/B]
.end packed-switch
.end method

Save changes...

KeyguardViewMediator.smali

- Search for ".field private static final SET_HIDDEN:I = 0xc" and add this line bellow it (the blue one):

.field private static final SET_HIDDEN:I = 0xc

[B][COLOR="Blue"].field private static final SET_TORCH:I = 0x14[/COLOR][/B]

.field private static final SHOW:I = 0x2

- Search for ".field private mTelephonyManager:Landroid/telephony/TelephonyManager;" and add thses lines bellow it (the blue ones):

.field private mTelephonyManager:Landroid/telephony/TelephonyManager;

[B][COLOR="Blue"].field private mTorchEnabled:Z

.field private mTorchStateChanged:Z[/COLOR][/B]

.field private mUnlockSoundId:I

- Search for this method ".method public constructor <init>(Landroid/content/Context;Lcom/android/internal/policy/impl/PhoneWindowManager;Landroid/os/LocalPowerManager;)V" and add these lines (the blue ones):

.method public constructor <init>(Landroid/content/Context;Lcom/android/internal/policy/impl/PhoneWindowManager;Landroid/os/LocalPowerManager;)V
.registers 15
.parameter "context"
.parameter "callback"
.parameter "powerManager"

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

.line 188
[B][COLOR="Blue"]const/4 v0, 0x1

iput-boolean v0, p0, Lcom/android/internal/policy/impl/KeyguardViewMediator;->mTorchEnabled:Z[/COLOR][/B]

const/4 v0, 0x1

- Search for "const-string v0, "power"" and add these lines above it (the blue lines):

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

.line 312
[B][COLOR="Blue"]const/4 v0, 0x0

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

const/4 v0, 0x0

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

const-string v0, "power"

- Search for this method ".method static synthetic access$300(Lcom/android/internal/policy/impl/KeyguardViewMediator;I)V" and add this new method above it:

.method static synthetic access$2300(Lcom/android/internal/policy/impl/KeyguardViewMediator;Z)V
.registers 2
.parameter "x0"
.parameter "x1"

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

return-void
.end method

[B][COLOR="Blue"].method static synthetic access$[COLOR="Red"]2400[/COLOR](Lcom/android/internal/policy/impl/KeyguardViewMediator;Z)V
.registers 2

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

return-void
.end method[/COLOR][/B]

.method static synthetic access$300(Lcom/android/internal/policy/impl/KeyguardViewMediator;I)V

- Search for the method ".method private handleHide()V" and add this line at end of this method (the blue one) just after "monitor-exit p0":

.method private handleHide()V
..
..
..
.line 1449
monitor-exit p0

[B][COLOR="Blue"]invoke-direct {p0}, Lcom/android/internal/policy/impl/KeyguardViewMediator;->resetTorchState()V[/COLOR][/B]

goto :goto_18

:catchall_45
move-exception v0

monitor-exit p0
:try_end_47
.catchall {:try_start_1 .. :try_end_47} :catchall_45

throw v0
.end method

.method private handleKeyguardDone(Z)V

- Search for the method ".method private handleNotifyScreenOff()V" and add this line (the blue one) just above "return-void":

.method private handleNotifyScreenOff()V
.registers 3

.prologue
.line 1597
monitor-enter p0

.line 1598
:try_start_1
const-string v0, "KeyguardViewMediator"

const-string v1, "handleNotifyScreenOff"

invoke-static {v0, v1}, Landroid/util/Log;->d(Ljava/lang/String;Ljava/lang/String;)I

.line 1599
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 1600
monitor-exit p0

.line 1601
[B][COLOR="Blue"]invoke-direct {p0}, Lcom/android/internal/policy/impl/KeyguardViewMediator;->resetTorchState()V[/COLOR][/B]

return-void

- Search for the method ".method private handleSetHidden(Z)V" and add this line (the blue one) above the defined condition in the method:

.method private handleSetHidden(Z)V
.registers 3
.parameter "isHidden"

.prologue
.line 688
monitor-enter p0

.line 689
:try_start_1
iget-boolean v0, p0, Lcom/android/internal/policy/impl/KeyguardViewMediator;->mHidden:Z

if-eq v0, p1, :cond_10

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

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

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

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

.line 695
[B][COLOR="Blue"]invoke-direct {p0}, Lcom/android/internal/policy/impl/KeyguardViewMediator;->resetTorchState()V[/COLOR][/B]

:cond_10
monitor-exit p0

- Search for the method ".method private handleShow()V" and add the following new method above it:

[B][COLOR="Blue"].method private handleSetTorch(Z)V
.registers 8

const/4 v5, 0x0

const/4 v4, 0x1

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

if-nez v1, :cond_majdi

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

const/4 v1, 0x1

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

:cond_[COLOR="Red"]b[/COLOR]
:goto_[COLOR="Red"]b[/COLOR]
return-void

:cond_majdi
iget-boolean v1, p0, Lcom/android/internal/policy/impl/KeyguardViewMediator;->mTorchEnabled:Z

if-eq v1, p1, :cond_[COLOR="Red"]b[/COLOR]

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

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

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;

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_maj
.catch Ljava/lang/Exception; {:try_start_2 .. :try_end_maj} :catch_jdi

goto :goto_[COLOR="Red"]b[/COLOR]

:catch_jdi
move-exception v1

goto :goto_[COLOR="Red"]b[/COLOR]
.end method[/COLOR][/B]

.method private handleShow()V

- Search for method ".method private handleShow()V", then search bellow for "Landroid/os/PowerManager$WakeLock;->release()V" and add these lines bellow it (the blue ones):

.method private handleShow()V
.registers 3

.prologue
.line 1400
monitor-enter p0

.line 1401
:try_start_1
const-string v0, "KeyguardViewMediator"
...
...
...
invoke-virtual {v0}, Landroid/os/PowerManager$WakeLock;->release()V

.line 1419
[B][COLOR="Blue"]const/4 v0, 0x1

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

monitor-exit p0

- Search for the method ".method private resetStateLocked()V" and add these lines (the blue ones) at the end before "return-void" line:

.method private resetStateLocked()V
.registers 4
...
...
invoke-virtual {v1, v0}, Landroid/os/Handler;->sendMessage(Landroid/os/Message;)Z

.line 809
[B][COLOR="Blue"]return-void
.end method

.method private resetTorchState()V
.registers 2

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

if-eqz v0, :cond_[COLOR="Red"]8[/COLOR]

const/4 v0, 0x0

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

:cond_[COLOR="Red"]8[/COLOR][/COLOR][/B]
return-void
.end method

- Search for the method ".method public verifyUnlock(Landroid/view/WindowManagerPolicy$OnKeyguardExitResult;)V" and add this new method above it (the blue lines):

[B][COLOR="Blue"].method public setTorch(Z)V
.registers 7

const/16 v4, 0x14

const/4 v3, 0x0

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

if-eqz v1, :cond_newa

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

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

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

if-eqz p1, :cond_newb

const/4 v2, 0x1

:goto_[COLOR="Red"]11[/COLOR]
invoke-virtual {v1, v4, v2, v3}, Landroid/os/Handler;->obtainMessage(III)Landroid/os/Message;

move-result-object v0

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

:cond_newa
return-void

:cond_newb
move v2, v3

goto :goto_[COLOR="Red"]11[/COLOR]
.end method[/COLOR][/B]

.method public verifyUnlock(Landroid/view/WindowManagerPolicy$OnKeyguardExitResult;)V

Save changes..

PhoneWindowManager.smali

All changes here, will be in this method ".method public interceptKeyBeforeDispatching(Landroid/view/WindowManagerPolicy$WindowState;Landroid/view/KeyEvent;I)J"; so it is better to know from which part of smali this method starts and ends in order to not touch other methods!!

- First search for the method ".method public interceptKeyBeforeDispatching(Landroid/view/WindowManagerPolicy$WindowState;Landroid/view/KeyEvent;I)J",

- Search for "Lcom/android/internal/policy/impl/PhoneWindowManager;->mHomePressed:Z" and add these lines bellow it (the blue ones):

.method public interceptKeyBeforeDispatching(Landroid/view/WindowManagerPolicy$WindowState;Landroid/view/KeyEvent;I)J
.registers 56
...
...
...
...
.line 3364
:cond_2ba
if-nez v15, :cond_[B][COLOR="Red"]38c[/COLOR][/B]

.line 3365
move-object/from16 v0, p0

iget-boolean v0, v0, Lcom/android/internal/policy/impl/PhoneWindowManager;->mHomePressed:Z

[B][COLOR="Blue"]if-eqz v0, :cond_[COLOR="Red"]38c[/COLOR]

const/16 v3, 0x0[/COLOR][/B]

move/from16 v20, v0

- Search for this portion (you can search down for ".catch Landroid/os/RemoteException" to locate this portion) and add this line (the blue one):

.line 3373
invoke-interface/range {v44 .. v44}, Lcom/android/internal/statusbar/IStatusBarService;->cancelPreloadRecentApps()V
:try_end_2dd
.catch Landroid/os/RemoteException; {:try_start_2d4 .. :try_end_2dd} :catch_329

.line 3381
.end local v44 #statusbar:Lcom/android/internal/statusbar/IStatusBarService;
:cond_2dd
:goto_2dd
const/4 v3, 0x0

move-object/from16 v0, p0

iput-boolean v3, v0, Lcom/android/internal/policy/impl/PhoneWindowManager;->mHomePressed:Z

[B][COLOR="Blue"]invoke-virtual/range {p0 .. p0}, Lcom/android/internal/policy/impl/PhoneWindowManager;->launchHomeFromHotKey()V[/COLOR][/B]

.line 3382
if-nez v36, :cond_32c

- Search down for "Lcom/android/internal/policy/impl/PhoneWindowManager$HomeKeyDoubleClickConcept;->setHomeDownEventSent()V" and add this new code after defined condition:

.line 3470
move-object/from16 v0, p0

iget-object v3, v0, Lcom/android/internal/policy/impl/PhoneWindowManager;->mHomeKeyDoubleClickConcept:Lcom/android/internal/policy/impl/PhoneWindowManager$HomeKeyDoubleClickConcept;

invoke-virtual {v3}, Lcom/android/internal/policy/impl/PhoneWindowManager$HomeKeyDoubleClickConcept;->setHomeDownEventSent()V

.line 3473
:cond_3a6
[B][COLOR="Blue"]new-instance v0, Ljava/io/File;

const-string v1, "/sdcard/Android"

invoke-direct {v0, v1}, Ljava/io/File;-><init>(Ljava/lang/String;)V

invoke-virtual {v0}, Ljava/io/File;->exists()Z

move-result v0

if-eqz v0, :cond_majdi

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 v3, v0

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

move-result v3

if-eqz v3, :cond_majdi

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 v3, v0

move-object/from16 v0, v3

move v1, v15

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

rem-int/lit8 v3, v41, 0xf

if-nez v3, :cond_majdi

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 v3, v0

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

:cond_majdi[/COLOR][/B]
const-wide/16 v3, 0x0

goto/16 :goto_8f

- Search down for "const/16 v3, 0xbb" (v3 may differ according to ROM) and do the following editing:

before:

.line 3635
:cond_[B][COLOR="Red"]536[/COLOR][/B] [B][COLOR="Green"]<-- we need to copy bellow condition over it[/COLOR][/B]
const/16 v3, 0xbb

move/from16 v0, v32

if-ne v0, v3, :cond_[B][COLOR="Red"]56f[/COLOR][/B] [B][COLOR="Green"]<-- we need to define new condition[/COLOR][/B]

.line 3637
move-object/from16 v0, p0

after:

.line 3635
:cond_[B][COLOR="Blue"]56f[/COLOR][/B]
const/16 v3, 0xbb

move/from16 v0, v32

if-ne v0, v3, :cond_[B][COLOR="Blue"]nj[/COLOR][/B]

.line 3637
move-object/from16 v0, p0

- Now we need to redefine mentioned cond_56f (it could be differ according to ROM),

search UP

for ".catch Landroid/content/ActivityNotFoundException;" and modify the IF-NE condition bellow it:

before:

.catch Landroid/content/ActivityNotFoundException; {:try_start_4fd .. :try_end_506} :catch_705

.line 3839
.end local v43 #shortcutIntent:Landroid/content/Intent;
:cond_506
:goto_506
const-wide/16 v3, -0x1

goto/16 :goto_8f

.line 3621
.end local v31 #kcm:Landroid/view/KeyCharacterMap;
:cond_50a
const/16 v3, 0x54

move/from16 v0, v32

if-ne v0, v3, [B][COLOR="Red"]:cond_536[/COLOR] [COLOR="Green"]<-- redefine this condition[/COLOR][/B]

.line 3622
if-eqz v15, :cond_522

after:

.catch Landroid/content/ActivityNotFoundException; {:try_start_4fd .. :try_end_506} :catch_705

.line 3839
.end local v43 #shortcutIntent:Landroid/content/Intent;
:cond_506
:goto_506
const-wide/16 v3, -0x1

goto/16 :goto_8f

.line 3621
.end local v31 #kcm:Landroid/view/KeyCharacterMap;
:cond_50a
const/16 v3, 0x54

move/from16 v0, v32

if-ne v0, v3, [B][COLOR="Blue"]:cond_56f[/COLOR][/B]

.line 3622
if-eqz v15, :cond_522

- Search down for "const/16 v3, 0xdb" (v3 may differ according to ROM) and change the condition value above it to the new condition from above mentioned edited code:

before:

.line 3654
.end local v16 #e:Landroid/os/RemoteException;
[B][COLOR="Red"]:cond_56f[/COLOR] [COLOR="Green"]<-- change it to the new condition[/COLOR][/B]
const/16 v3, 0xdb

move/from16 v0, v32

if-ne v0, v3, :cond_5a4

after:

.line 3654
.end local v16 #e:Landroid/os/RemoteException;
[B][COLOR="Blue"]:cond_nj[/COLOR][/B]
const/16 v3, 0xdb

move/from16 v0, v32

if-ne v0, v3, :cond_5a4

Save changes...

Now backsmali classsout folder to get new classes.dex file. Now Open android.policy.jar by WinRAR or 7-zip and drag and drop the new classes.dex file inside it; then push it to your device framework folder and fix permissions to chmod 644.

Download Torch.apk from attachment bellow and push it to your device app folder and fix permissions to chmod 644 as well... and viola.. lockscreen the device and do long pressing on home button to have torch flash light..:laugh:

If you could manage to shorten this tutorial by omitting unnecessary steps, then share your experience here please