[MOD][HOW-TO] Add Flashlight quick toggle [4.3|4.4]

CNexus

Senior Member
May 17, 2012
9,009
13,993
263
~/android
@CNexus

I tried to follow this guide to add this toggle to my Note 3. But, well, I am stuck at the first step itself.
I decompiled my systemUI to find that there is no com folder in there.
Am I doing something wrong? Or is the Note 3 systemUI.apk inherently different?

View attachment 2603376
Did you check the "original" folder? Otherwise, try just using apktool directly without a wrapper program like the AdvancedApkTool you seem to be using
 

manufan721

Senior Member
Mar 18, 2012
2,337
3,181
0
@CNexus

I tried to follow this guide to add this toggle to my Note 3. But, well, I am stuck at the first step itself.
I decompiled my systemUI to find that there is no com folder in there.
Am I doing something wrong? Or is the Note 3 systemUI.apk inherently different?

View attachment 2603376
Did you baksmali? Its in smali files, not in root of apk..

Sent from my SGH-T889 using xda app-developers app
 

CNexus

Senior Member
May 17, 2012
9,009
13,993
263
~/android
Sorry. I misunderstood thinking they ment how to go straight to whatever the assistive light widget goes to rather than have the toggle turn on the widget.
I think I got it, and with no complicated procedures/modifications to the existing code...

Inside SecHardwareInterface, there are predefined methods for setting the torch brightness...so just invoking that with the toggle value should do the trick


Will updated tomorrow after I test it
 

FeralFire

Senior Member
Jan 18, 2012
512
232
0
Did you check the "original" folder? Otherwise, try just using apktool directly without a wrapper program like the AdvancedApkTool you seem to be using
Did you baksmali? Its in smali files, not in root of apk..

Sent from my SGH-T889 using xda app-developers app

Thanks for the replies. Reading your suggestion, I just remembered that I had been trying to mod an odexed APK.
My bad.
Will try it again when I get home.



Edit:
My FlashlightQuickSettingButton.smali does not contain comments as to which constructor corresponds to what. Any advise?


Code:
.class public Lcom/android/systemui/statusbar/policy/quicksetting/FlashlightQuickSettingButton;
.super Lcom/android/systemui/statusbar/policy/quicksetting/QuickSettingButton;
.source "FlashlightQuickSettingButton.java"

# interfaces
.implements Lcom/android/systemui/statusbar/policy/quicksetting/QuickSettingButton$Listener;


# static fields
.field private static final TW_TAG:Ljava/lang/String; = "STATUSBAR-FlashlightQuickSettingButton"


# instance fields
.field private mContext:Landroid/content/Context;

.field private mFlashlight:Z


# direct methods
.method public constructor <init>(Landroid/content/Context;)V
    .locals 9

    const/4 v6, 0x0

    const/4 v2, 0x0

    const v3, 0x0

    const v4, 0x0

    const v5, 0x0

    move-object v0, p0

    move-object v1, p1

    move v7, v6

    move v8, v6

    invoke-direct/range {v0 .. v8}, Lcom/android/systemui/statusbar/policy/quicksetting/QuickSettingButton;-><init>(Landroid/content/Context;Landroid/util/AttributeSet;IIIIII)V

    iput-object p1, p0, Lcom/android/systemui/statusbar/policy/quicksetting/FlashlightQuickSettingButton;->mContext:Landroid/content/Context;

    invoke-virtual {p0, p0}, Lcom/android/systemui/statusbar/policy/quicksetting/FlashlightQuickSettingButton;->setListener(Lcom/android/systemui/statusbar/policy/quicksetting/QuickSettingButton$Listener;)V

    return-void
.end method


# virtual methods
.method public deinit()V
    .locals 1

    return-void
.end method

.method public init()V
    .locals 4

    iget-object v1, p0, Lcom/android/systemui/statusbar/policy/quicksetting/FlashlightQuickSettingButton;->mContext:Landroid/content/Context;

    const/4 v1, 0x1

    iput-boolean v1, p0, Lcom/android/systemui/statusbar/policy/quicksetting/FlashlightQuickSettingButton;->mFlashlight:Z

    iget-boolean v1, p0, Lcom/android/systemui/statusbar/policy/quicksetting/FlashlightQuickSettingButton;->mFlashlight:Z

    if-eqz v1, :cond_0

    const/4 v1, 0x2

    :goto_0
    invoke-virtual {p0, v1}, Lcom/android/systemui/statusbar/policy/quicksetting/FlashlightQuickSettingButton;->setActivateStatus(I)V

    return-void

    :cond_0
    const/4 v1, 0x1

    goto :goto_0
.end method

.method public onClick(Z)V
    .locals 6

    const/4 v2, 0x1

    if-nez p1, :cond_1

    move v1, v2

    :goto_0
    iget-boolean v3, p0, Lcom/android/systemui/statusbar/policy/quicksetting/FlashlightQuickSettingButton;->mFlashlight:Z

    if-eq v1, v3, :cond_0

    iput-boolean v1, p0, Lcom/android/systemui/statusbar/policy/quicksetting/FlashlightQuickSettingButton;->mFlashlight: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/systemui/statusbar/policy/quicksetting/FlashlightQuickSettingButton;->mContext:Landroid/content/Context;

    invoke-virtual {v1, v0}, Landroid/content/Context;->sendBroadcast(Landroid/content/Intent;)V

    if-eqz p1, :cond_2

    invoke-virtual {p0, v2}, Lcom/android/systemui/statusbar/policy/quicksetting/FlashlightQuickSettingButton;->setActivateStatus(I)V

    :cond_0
    :goto_1
    return-void

    :cond_1
    const/4 v1, 0x0

    goto :goto_0

    :cond_2
    const/4 v2, 0x2

    invoke-virtual {p0, v2}, Lcom/android/systemui/statusbar/policy/quicksetting/FlashlightQuickSettingButton;->setActivateStatus(I)V

    goto :goto_1
.end method

.method public onLongClick()V
    .locals 0

    return-void
.end method
 
Last edited:

CNexus

Senior Member
May 17, 2012
9,009
13,993
263
~/android
Thanks for the replies. Reading your suggestion, I just remembered that I had been trying to mod an odexed APK.
My bad.
Will try it again when I get home.



Edit:
My FlashlightQuickSettingButton.smali does not contain comments as to which constructor corresponds to what. Any advise?
const v3: string text id
const v4: on drawable id
const v5: off drawable id
 

CNexus

Senior Member
May 17, 2012
9,009
13,993
263
~/android
Ok here it is

Replace the onClick method of the FlashlightQuickSettingButton.smali with the following, then you don't need an external app

Code:
.method public onClick(Z)V
    .locals 5
    .parameter "paramBoolean"

    .prologue
    .line 29
    const/4 v2, 0x0

    .line 30
    .local v2, localIntent:Landroid/content/Intent;
    const/4 v1, 0x0

    .line 32
    .local v1, bc:Ljava/lang/String;
    const/4 v0, 0x2

    .line 34
    .local v0, activateStatus:I
    iget v3, p0, Lcom/android/systemui/statusbar/policy/quicksetting/FlashlightQuickSettingButton;->mFlashlight:I

    add-int/lit8 v3, v3, 0x1

    iput v3, p0, Lcom/android/systemui/statusbar/policy/quicksetting/FlashlightQuickSettingButton;->mFlashlight:I

    .line 36
    iget v3, p0, Lcom/android/systemui/statusbar/policy/quicksetting/FlashlightQuickSettingButton;->mFlashlight:I

    rem-int/lit8 v3, v3, 0x2

    iput v3, p0, Lcom/android/systemui/statusbar/policy/quicksetting/FlashlightQuickSettingButton;->mFlashlight:I

    .line 38
    iget v3, p0, Lcom/android/systemui/statusbar/policy/quicksetting/FlashlightQuickSettingButton;->mFlashlight:I

    const/4 v4, 0x1

    if-ne v3, v4, :cond_0

    .line 39
    const-string v1, "com.sec.samsung.torchwidget.torch_on_3"

    .line 40
    const/4 v0, 0x1

    .line 45
    :goto_0
    invoke-virtual {p0, v0}, Lcom/android/systemui/statusbar/policy/quicksetting/FlashlightQuickSettingButton;->setActivateStatus(I)V

    .line 47
    new-instance v2, Landroid/content/Intent;

    .end local v2           #localIntent:Landroid/content/Intent;
    invoke-direct {v2, v1}, Landroid/content/Intent;->(Ljava/lang/String;)V

    .line 49
    .restart local v2       #localIntent:Landroid/content/Intent;
    iget-object v3, p0, Lcom/android/systemui/statusbar/policy/quicksetting/FlashlightQuickSettingButton;->mContext:Landroid/content/Context;

    invoke-virtual {v3, v2}, Landroid/content/Context;->sendBroadcast(Landroid/content/Intent;)V

    .line 53
    return-void

    .line 42
    :cond_0
    const-string v1, "com.sec.samsung.torchwidget.torch_off"

    goto :goto_0
.end method
 
Last edited:

CNexus

Senior Member
May 17, 2012
9,009
13,993
263
~/android
Where is the onClick method? Is it in the FlashlightQuickSettingButton.smali?

Edit: I flashed the new zip from the OP and the toggle acts the same way as before, with the slight lag... :eek:
The zip in the OP only makes the toggle show up if you've implemented it. It doesn't actually do anything else, or flash already modified files

And yes, replace the onClick method of the FlashlightQuickSettingButton.smali with the code above
 

metalfan78

Senior Member
Jan 30, 2010
5,009
2,476
0
Littleton, CO
I'm working on the SystemUI part right now and after I make the edits and add the files I get this error when I recompile, not sure what it means. Any help would be appreciated.


C:\apktool>apktool b SystemUI
I: Checking whether sources has changed...
I: Smaling...
[139,54] no viable alternative at input '('
Exception in thread "main" brut.androlib.AndrolibException: Could not smali file
: [email protected]
at brut.androlib.src.DexFileBuilder.addSmaliFile(DexFileBuilder.java:45)

at brut.androlib.src.DexFileBuilder.addSmaliFile(DexFileBuilder.java:33)

at brut.androlib.src.SmaliBuilder.buildFile(SmaliBuilder.java:66)
at brut.androlib.src.SmaliBuilder.build(SmaliBuilder.java:50)
at brut.androlib.src.SmaliBuilder.build(SmaliBuilder.java:37)
at brut.androlib.Androlib.buildSourcesSmali(Androlib.java:256)
at brut.androlib.Androlib.buildSources(Androlib.java:213)
at brut.androlib.Androlib.build(Androlib.java:204)
at brut.androlib.Androlib.build(Androlib.java:176)
at brut.apktool.Main.cmdBuild(Main.java:218)
at brut.apktool.Main.main(Main.java:74)

C:\apktool>

---------- Post added at 07:25 AM ---------- Previous post was at 06:47 AM ----------

Also, when I compiled SecSettings my new one is about 20 mb smaller than original. That doesn't seem right to me.
 

Ohh_Trenton

Senior Member
May 18, 2010
1,185
2,985
0
▂ ▃ ▅ ▆ █
I'm working on the SystemUI part right now and after I make the edits and add the files I get this error when I recompile, not sure what it means. Any help would be appreciated.


C:\apktool>apktool b SystemUI
I: Checking whether sources has changed...
I: Smaling...
[139,54] no viable alternative at input '('
Exception in thread "main" brut.androlib.AndrolibException: Could not smali file
: [email protected]
at brut.androlib.src.DexFileBuilder.addSmaliFile(DexFileBuilder.java:45)

at brut.androlib.src.DexFileBuilder.addSmaliFile(DexFileBuilder.java:33)

at brut.androlib.src.SmaliBuilder.buildFile(SmaliBuilder.java:66)
at brut.androlib.src.SmaliBuilder.build(SmaliBuilder.java:50)
at brut.androlib.src.SmaliBuilder.build(SmaliBuilder.java:37)
at brut.androlib.Androlib.buildSourcesSmali(Androlib.java:256)
at brut.androlib.Androlib.buildSources(Androlib.java:213)
at brut.androlib.Androlib.build(Androlib.java:204)
at brut.androlib.Androlib.build(Androlib.java:176)
at brut.apktool.Main.cmdBuild(Main.java:218)
at brut.apktool.Main.main(Main.java:74)

C:\apktool>

---------- Post added at 07:25 AM ---------- Previous post was at 06:47 AM ----------

Also, when I compiled SecSettings my new one is about 20 mb smaller than original. That doesn't seem right to me.
Try to replace your flashlightquicksettingbutton onclick method with this one and see if it works

Code:
.method public onClick(Z)V
    .locals 6

    const/4 v2, 0x1

    if-nez p1, :cond_2

    move v1, v2

    :goto_0
    iget-boolean v3, p0, Lcom/android/systemui/statusbar/policy/quicksetting/FlashlightQuickSettingButton;->mFlashlight:Z

    if-eq v1, v3, :cond_0

    iput-boolean v1, p0, Lcom/android/systemui/statusbar/policy/quicksetting/FlashlightQuickSettingButton;->mFlashlight: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/systemui/statusbar/policy/quicksetting/FlashlightQuickSettingButton;->mContext:Landroid/content/Context;

    invoke-virtual {v1, v0}, Landroid/content/Context;->sendBroadcast(Landroid/content/Intent;)V

    if-eqz p1, :cond_3

    invoke-virtual {p0, v2}, Lcom/android/systemui/statusbar/policy/quicksetting/FlashlightQuickSettingButton;->setActivateStatus(I)V

    :cond_0
    :goto_1
    iget-object v1, p0, Lcom/android/systemui/statusbar/policy/quicksetting/QuickSettingButton;->mContext:Landroid/content/Context;

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

    move-result-object v1

    const-string v2, "collapse_panel"

    const/4 v3, 0x0

    invoke-static {v1, v2, v3}, Landroid/provider/Settings$System;->getInt(Landroid/content/ContentResolver;Ljava/lang/String;I)I

    move-result v1

    if-eqz v1, :cond_1

    iget-object v1, p0, Lcom/android/systemui/statusbar/policy/quicksetting/QuickSettingButton;->mContext:Landroid/content/Context;

    const-string v2, "statusbar"

    invoke-virtual {v1, v2}, Landroid/content/Context;->getSystemService(Ljava/lang/String;)Ljava/lang/Object;

    move-result-object v3

    check-cast v3, Landroid/app/StatusBarManager;

    invoke-virtual {v3}, Landroid/app/StatusBarManager;->collapsePanels()V

    :cond_1
    return-void

    :cond_2
    const/4 v1, 0x0

    goto :goto_0

    :cond_3
    const/4 v2, 0x2

    invoke-virtual {p0, v2}, Lcom/android/systemui/statusbar/policy/quicksetting/FlashlightQuickSettingButton;->setActivateStatus(I)V

    goto :goto_1
.end method

.method public onLongClick()V
    .locals 0

    return-void
.end method
I had the same error as you but I replaced it with this one and it works. Just keep in mind to replace those Ids

# text id
const v3, 0x0

# on image id
const v4, 0x0

# off off id
const v5, 0x0

With your own IDS from step 11.
 
  • Like
Reactions: metalfan78

metalfan78

Senior Member
Jan 30, 2010
5,009
2,476
0
Littleton, CO
I tried your method, and apktool threw a bunch of errors about system bar notification and system bar settings view. So I decided to decompile and the recompile without making any changes and I got the same errors. I'm not sure what the problem is, because SecSettings compiled fine.
 

Ohh_Trenton

Senior Member
May 18, 2010
1,185
2,985
0
▂ ▃ ▅ ▆ █

metalfan78

Senior Member
Jan 30, 2010
5,009
2,476
0
Littleton, CO
Small issue, when I edit the buttons in settings, the flashlight button is labeled 'flashlight' but in the pulldown it looks like this. And also if I want to bake it into my rom do I just add the tools folder from the enable zip to system?


---------- Post added at 08:00 AM ---------- Previous post was at 07:27 AM ----------

Did I use a wrong id for that?
 
Last edited:
Our Apps
Get our official app!
The best way to access XDA on your phone
Nav Gestures
Add swipe gestures to any Android
One Handed Mode
Eases uses one hand with your phone