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

Search This thread

CNexus

Senior Member
May 17, 2012
9,010
14,000
~/android
Google Pixel 7
Hey guys! Today I'll be showing you how to add the Flashlight toggle to your quick toggles:

i4gop5j.png

UPDATE: Once you have completed the mod below, you (and your users) can enable the flashlight toggle by flashing the zip HERE. It uses busybox and an included binary to add the toggle to notification_panel_active_app_list, so it will work with all devices that this mod applies to. Again, feel free to share this but give credits where due!

Items you will need
  1. SystemUI.apk from the rom you are modding
  2. SecSettings.apk from the rom you are modding
  3. Notepad++ or another text editor of your choice (NOT regular Notepad, it messes up the encoding)
  4. apktool or baksmali+smali or VTS, etc


Now before we get started, download the attachment with the files you will need for this mod (attached to this post...make sure you grab the right version for the system you are modifying)




Now lets get started!


[size=+1]Step 1: Modding SystemUI.apk[/size]
  1. Decompile SystemUI.apk and navigate to com/android/systemui/statusbar/policy/quicksetting in your file browser
  2. Copy and paste FlashlightQuickSettingButton.smali from inside the zip you downloaded (flashlight_files.zip/SystemUI/FlashlightQuickSettingButton.smali) into this folder
  3. Navigate to SystemUI/res/drawable-xhdpi (or SystemUI/res/drawable-xxhdpi depending on your device)
  4. Copy and paste the two pngs (tw_quick_panel_icon_flashlight_off.png and tw_quick_panel_icon_flashlight_on.png) from the SystemUI folder of the attachment into the decompiled drawable folder you opened above
  5. Now navigate to SystemUI/res/values and open the strings.xml with your text editor
  6. Search for "quickpanel_flashlight_text". If it does not exist anywhere in the file, add this to the bottom of your strings.xml file:
    PHP:
    <string name="quickpanel_flashlight_text">Flashlight</string>
  7. That's it or SystemUI! Now recompile SystemUI.apk and move on to step 2. At this point, the toggle will show up in the full toggles view (when you add ";Flashlight" to the CscFeature... or to the notification_panel_active_app_list in /data/data/com.android.providers.settings/settings.db) in the status bar, but Settings will FC if you try to go into edit mode/rearrange toggles mode
 

Attachments

  • flashlight_files_jb43.zip
    5.7 KB · Views: 2,363
  • flashlight_files_kk44.zip
    5.8 KB · Views: 5,337
Last edited:

CNexus

Senior Member
May 17, 2012
9,010
14,000
~/android
Google Pixel 7
[SIZE=+1]Step 2: Modding SecSettings.apk[/SIZE]
  1. Decompile SecSettings and navigate to com/android/settings
  2. Open NotificationPanelMenu.smali and search for the method ".method private makeConvertPanelName"
  3. Make sure that the following lines are present somewhere in the makeConvertPanelName method. Notice that they are NOT the same, but indeed very similar.
    Code:
    iget-object v0, p0, Lcom/android/settings/NotificationPanelMenu;->mConvertPanelItemstring:Ljava/util/HashMap;
    const-string v1, "Flashlight"
    const-string v2, "notification_panel_flashlight"
    invoke-virtual {v0, v1, v2}, Ljava/util/HashMap;->put(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
    
    [B]AND[/B]
    
    iget-object v0, p0, Lcom/android/settings/NotificationPanelMenu;->mConvertPanelItemstring:Ljava/util/HashMap;
    const-string v1, "notification_panel_flashlight"
    const-string v2, "Flashlight"
    invoke-virtual {v0, v1, v2}, Ljava/util/HashMap;->put(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;

    If the 8 lines above are not anywhere in the
    Code:
    makeConvertPanelName
    method, then add them to the end of the method before the
    Code:
    return-void
  4. Now save the file and close it and navigate to SecSettings/res/values/strings.xml
  5. Add the following line to your strings.xml if it does not already exist (yes, it has the same name as the image. That's supposed to happen so don't worry)
    PHP:
    <string name="notification_panel_flashlight">Flashlight</string>
  6. Save and close strings.xml and navigate to SecSettings/res/drawable-xhdpi or drawable-xxhdpi depending on your device
  7. Extract the notification_panel_flashlight.png from attachment.zip/SecSettings and copy it into the drawable folder from above
  8. Finally, recompile SecSettings with your modifications


Now for the final step, take your modified SecSettings.apk, SystemUI.apk and add them to the /system/app folder of your rom and you are good to go!

Congratulations, you just added the Flashlight toggle to your rom. Enjoy :D:D

AzsLTFa.png
ENxGR0l.png

Note: Devs are free to use this mod in their rom. Just make sure you give credits where they are due :)
If you have any issues, I'd be more than happy to help :good:


Thanks to:
Samsung for the AT&T base code this was pulled from!
Rompnit for finding the at&t code and the first part of the mod!
Google for the wonderful logcat tool built into Android that allowed me to figure out the second part of the mod!!
 
Last edited:

xdapowerapps

Senior Member
Jul 16, 2008
639
241
Thank you bro! Just wish we had a simple flashable mod or xposed mod but since these are based off unique res, it is not possible (well somewhat, but it can be too buggy). Sucks we have to go through this. Lazy ass me lol.

Sent from my SGH-M919 using XDA Premium 4 mobile app
 
  • Like
Reactions: thanassi44

JoshBeach

Inactive Recognized Developer
Dec 19, 2007
4,692
31,810
Upstate NY
Hey guys! Today I'll be showing you how to add the Flashlight toggle to your quick toggles:

i4gop5j.png






[SIZE=+1]Now before we get started, download the attachment with the files you will need for this mod (attached to this post...scroll down)[/size]



Now lets get started!

Great Job OP... ;)

Sent from my SM-N900P using XDA Premium 4 mobile app
 
  • Like
Reactions: howdyace

baseballfanz

Senior Member
Oct 19, 2010
6,829
1,702
Sugar Land TX
Samsung Galaxy A52 5G
I've gotten as far as step 10

Code:
Now navigate to com/android/systemui/statusbar/policy/quicksetting and open FlashlightQuickSettingButton.smali with your text editor

but can't find FlashlightQuickSettingButton.smali there. Using AndroidMultitool. Will try again with different decompiled app.:good:
 

MetalMan2

Senior Member
May 25, 2012
145
39
I've gotten as far as step 10

Code:
Now navigate to com/android/systemui/statusbar/policy/quicksetting and open FlashlightQuickSettingButton.smali with your text editor

but can't find FlashlightQuickSettingButton.smali there. Using AndroidMultitool. Will try again with different decompiled app.:good:

You added that file into that folder in step 2.
 
  • Like
Reactions: erikalin and CNexus

CNexus

Senior Member
May 17, 2012
9,010
14,000
~/android
Google Pixel 7
I've gotten as far as step 10

Code:
Now navigate to com/android/systemui/statusbar/policy/quicksetting and open FlashlightQuickSettingButton.smali with your text editor

but can't find FlashlightQuickSettingButton.smali there. Using AndroidMultitool. Will try again with different decompiled app.:good:



See below. You either skipped a step or misread it or something


You added that file into that folder in step 2.
 
  • Like
Reactions: notmyepic

smaw51

Senior Member
Nov 22, 2010
885
431
Tempe
  • Like
Reactions: jlyle

Top Liked Posts

  • There are no posts matching your filters.
  • 98
    Hey guys! Today I'll be showing you how to add the Flashlight toggle to your quick toggles:

    i4gop5j.png

    UPDATE: Once you have completed the mod below, you (and your users) can enable the flashlight toggle by flashing the zip HERE. It uses busybox and an included binary to add the toggle to notification_panel_active_app_list, so it will work with all devices that this mod applies to. Again, feel free to share this but give credits where due!

    Items you will need
    1. SystemUI.apk from the rom you are modding
    2. SecSettings.apk from the rom you are modding
    3. Notepad++ or another text editor of your choice (NOT regular Notepad, it messes up the encoding)
    4. apktool or baksmali+smali or VTS, etc


    Now before we get started, download the attachment with the files you will need for this mod (attached to this post...make sure you grab the right version for the system you are modifying)




    Now lets get started!


    [size=+1]Step 1: Modding SystemUI.apk[/size]
    1. Decompile SystemUI.apk and navigate to com/android/systemui/statusbar/policy/quicksetting in your file browser
    2. Copy and paste FlashlightQuickSettingButton.smali from inside the zip you downloaded (flashlight_files.zip/SystemUI/FlashlightQuickSettingButton.smali) into this folder
    3. Navigate to SystemUI/res/drawable-xhdpi (or SystemUI/res/drawable-xxhdpi depending on your device)
    4. Copy and paste the two pngs (tw_quick_panel_icon_flashlight_off.png and tw_quick_panel_icon_flashlight_on.png) from the SystemUI folder of the attachment into the decompiled drawable folder you opened above
    5. Now navigate to SystemUI/res/values and open the strings.xml with your text editor
    6. Search for "quickpanel_flashlight_text". If it does not exist anywhere in the file, add this to the bottom of your strings.xml file:
      PHP:
      <string name="quickpanel_flashlight_text">Flashlight</string>
    7. That's it or SystemUI! Now recompile SystemUI.apk and move on to step 2. At this point, the toggle will show up in the full toggles view (when you add ";Flashlight" to the CscFeature... or to the notification_panel_active_app_list in /data/data/com.android.providers.settings/settings.db) in the status bar, but Settings will FC if you try to go into edit mode/rearrange toggles mode
    74
    [SIZE=+1]Step 2: Modding SecSettings.apk[/SIZE]
    1. Decompile SecSettings and navigate to com/android/settings
    2. Open NotificationPanelMenu.smali and search for the method ".method private makeConvertPanelName"
    3. Make sure that the following lines are present somewhere in the makeConvertPanelName method. Notice that they are NOT the same, but indeed very similar.
      Code:
      iget-object v0, p0, Lcom/android/settings/NotificationPanelMenu;->mConvertPanelItemstring:Ljava/util/HashMap;
      const-string v1, "Flashlight"
      const-string v2, "notification_panel_flashlight"
      invoke-virtual {v0, v1, v2}, Ljava/util/HashMap;->put(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
      
      [B]AND[/B]
      
      iget-object v0, p0, Lcom/android/settings/NotificationPanelMenu;->mConvertPanelItemstring:Ljava/util/HashMap;
      const-string v1, "notification_panel_flashlight"
      const-string v2, "Flashlight"
      invoke-virtual {v0, v1, v2}, Ljava/util/HashMap;->put(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;

      If the 8 lines above are not anywhere in the
      Code:
      makeConvertPanelName
      method, then add them to the end of the method before the
      Code:
      return-void
    4. Now save the file and close it and navigate to SecSettings/res/values/strings.xml
    5. Add the following line to your strings.xml if it does not already exist (yes, it has the same name as the image. That's supposed to happen so don't worry)
      PHP:
      <string name="notification_panel_flashlight">Flashlight</string>
    6. Save and close strings.xml and navigate to SecSettings/res/drawable-xhdpi or drawable-xxhdpi depending on your device
    7. Extract the notification_panel_flashlight.png from attachment.zip/SecSettings and copy it into the drawable folder from above
    8. Finally, recompile SecSettings with your modifications


    Now for the final step, take your modified SecSettings.apk, SystemUI.apk and add them to the /system/app folder of your rom and you are good to go!

    Congratulations, you just added the Flashlight toggle to your rom. Enjoy :D:D

    AzsLTFa.png
    ENxGR0l.png

    Note: Devs are free to use this mod in their rom. Just make sure you give credits where they are due :)
    If you have any issues, I'd be more than happy to help :good:


    Thanks to:
    Samsung for the AT&T base code this was pulled from!
    Rompnit for finding the at&t code and the first part of the mod!
    Google for the wonderful logcat tool built into Android that allowed me to figure out the second part of the mod!!
    9
    @Chad The Pathfinder @vesatile1
    Here is a new smali for SystemUI that is working for me on 4.4.2.
    Give it a try and let me know how it works for you. I fought with this bad boy for quite a while. :rolleyes:

    Instructions:
    This smali requires you to compile then decompile your completed SystemUI (then compile one last time once the values are correct) to input the appropriate values for the public construct. I added fields to each line for which public values to look for. You can leave those comment lines in, they will be ignored when you compile the smali.
    Code:
    .method public constructor <init>(Landroid/content/Context;)V
        .locals 8
    
        const v2, 0x7f0b0211  [COLOR="Blue"]## quickpanel_flashlight_text[/COLOR]
    
        const v1, 0x7f0b0211  [COLOR="Blue"]## quickpanel_flashlight_text[/COLOR]
    
        const/4 v5, 0x0
    
        const/4 v0, 0x0
    
        sget-boolean v3, Lcom/android/systemui/statusbar/Feature;->mIsTablet:Z
    
        invoke-direct {p0, p1, v0, v3}, Lcom/android/systemui/statusbar/policy/quicksetting/QuickSettingButton;-><init>(Landroid/content/Context;Landroid/util/AttributeSet;Z)V
    
        sget-boolean v0, Lcom/android/systemui/statusbar/Feature;->mIsPhone:Z
    
        if-eqz v0, :cond_0
    
        const v3, 0x7f020355  [COLOR="Blue"]## tw_quick_panel_icon_flashlight_on[/COLOR]
    
        const v4, 0x7f020354  [COLOR="Blue"]## tw_quick_panel_icon_flashlight_off[/COLOR]
    
        move-object v0, p0
    
        move v6, v5
    
        move v7, v5
    
        invoke-virtual/range {v0 .. v7}, Lcom/android/systemui/statusbar/policy/quicksetting/FlashlightQuickSettingButton;->initLayout(IIIIIII)V
    
        iput-object p1, p0, Lcom/android/systemui/statusbar/policy/quicksetting/FlashlightQuickSettingButton;->mContext:Landroid/content/Context;
    
        :goto_0
        invoke-virtual {p0, p0}, Lcom/android/systemui/statusbar/policy/quicksetting/FlashlightQuickSettingButton;->setListener(Lcom/android/systemui/statusbar/policy/quicksetting/QuickSettingButton$Listener;)V
    
        return-void
    
        :cond_0
        const v0, 0x7f020354  [COLOR="Blue"]## tw_quick_panel_icon_flashlight_off
    [/COLOR]
        invoke-virtual {p0, v1, v2, v0}, Lcom/android/systemui/statusbar/policy/quicksetting/FlashlightQuickSettingButton;->initLayout(III)V
    
        goto :goto_0
    .end method

    Also see this post:
    http://xdaforums.com/showpost.php?p=53122589&postcount=321
    9
    MOD UPDATED
    ==============
    - 4.3 and 4.4 zips added
    - No need to write down ANY id's anymore. I've made it so that the id's get looked up on the fly by name, so just make sure you don't rename the drawables/string names as per this guide
    - Flashlight is super fast now, no need to use an external app
    8
    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