[Verizon Samsung Galaxy S 4] DerekZ10:
EDIT: 11/15/2014

This post features version 2.x.x. It is a complete rewrite using Android Studio because importing the project from Eclipse didn't go too well.

For information on version 1.x.x , go to post #28

Downloads for both versions are at the bottom of this page.

-------------------------------------------------------------------------------------------------------------------------------------------------------------------

ZTORCH Features:

The goal of ZTorch is to be a extremely quick and lightweight app that does one thing and does it well without extra bloat or ridiculous permissions. ZTorch can vary the brightness of your phones LED and allow you to set brightness levels higher than possible anywhere else.

The Galaxy S4 is capable of 16 different levels of brightness (0-15). Compared to other Apps:

The stock "Assistive Light" that is featured with the phone only sets the level to 1.

The brightest AppStore Apps, such as TeslaLED, are able to set the brightness to a little less than half brightness, level 6.

Typically, flashlight apps take about a second to switch on the LED

ZTorch can adjust the LED in mere milliseconds.

ZTorch stays on when the screen is off and doesn't flicker when the screen switches off.

ZTorch works with the camera. Ever wanted to use the flashlight LED while recording a video or taking a picture? Now you can.

-------------------------------------------------------------------------------------------------------------------------------------------------------------------

ZTorch should work across all phones with root if the proper system file is on the phone. ZTorch scans for the following binaries below. If your device isn't supported and you know the path to the proper file, you can set that path in the apps preferences. This app has only ever been tested on the Galaxy S4, if you try it on a different phone, PLEASE let me know how it is!

"/sys/class/camera/flash/rear_flash", - For Galaxy s4
"/sys/class/camera/rear/rear_flash", - For Galaxy Note and maybe s3
"/sys/class/leds/flashlight/brightness," - HTC devices
"/sys/devices/platform/flashlight.0/leds/flashlight/brightness" - HTC devices
" /sys/class/leds/spotlight/brightness" - Motorolla Droid Devices
"/sys/class/leds/torch-flash/flash_light" - Motorolla Droid 2

-------------------------------------------------------------------------------------------------------------------------------------------------------------------

Screenshots from ZTORCH-beta-2.0.0.26.apk:

Main Activity as popup with widget shown in background.

Notification:

-------------------------------------------------------------------------------------------------------------------------------------------------------------------

Permissions:

ACCESS_SUPERUSER - To set the LED

RECEIVE_BOOT_COMPLETED - Sets LED to 0, allows for persistent notification, notification on bootup.

-------------------------------------------------------------------------------------------------------------------------------------------------------------------

Version Information:

Download attached at bottom of post.

LATEST: Version 2.0.3.50: (Feb 24, 2015)

Notification now appears on boot if that setting is enabled

Separated BootReceiver from main broadcast receiver so disabling the boot receiver won't break the rest of the app.

Notification icon changed to support Lollipop.

Renamed some app refs.

Somehow cut 50kb from the app, it's now 100.6Kb. Considering the Icons take up 89.5Kb I'm kinda amazed.

I haven't got around to making an actual Settings activity. So features are the same from prior version.

Version 1.2.2: (Mar 3, 2014)

All the features work but is less refined.

Version 1.3.0: (June 16,2014)

Added TorchPlayer to act similar to PWM. All Features work.

Version 1.4.0 (June 20,2014)

Switching speed was the priority in this version; the brightness can be changed in <3ms. I abandoned the very comprehensive and powerful Stericson RootTools library in favor of a purpose built class that toggles the flashlight. Warning: The notification doesn't work on API-19 Android 4.4+. Clicking it does nothing. I need to build a new version sometime.

For more info on version 1.x.x such as the screenshots, see post #28

ZTORCH-beta-2.0.0.28: (November 15,2014)

Beta version does not yet have a settings or preference activity implemented as well as other nonessentials. To change settings in this version, see below. Changes include:

Entirely new MainActivity that's now in a Popup window

Entirely New and Fully Working Notification

Widget now fills the entire 1x1 grid. (Let me know if there's problems, I set the left and right margins to -23dp to do this)

Added Warn feature and Torch Fireball icon for when the brightness is higher than the Warn value.

Slider no longer lags while trying to effectively "make a strobe light" by not sending broadcasts, updating views, or saving the brightness until after you take your finger off.

Slider changes color based on level.

ZTORCH-beta-2.0.0.33optimized: Technically should be: 2.0.2.33(November 16,2014)

Changes:

Adds RECEIVE_BOOT_COMPLETE permission.

Ongoing Notification is available in AppPrefs.xml

TapGuard enabled by default. (Widget ignores first tap to prevent accidental taps)

ZTORCH-optimizedbeta-2.0.3.41: (November 17,2014)

Changes:

New Notification AppPrefs.

ongoingNotif (Can't swipe away, Persistent).

onPriority and offPriority (levels: -2, -1, 0, 1, 2 where 2 is PRIORITY_MAX)

Shell Command Text and Toggle Button updated instantly while slider moves.

ZTorchReceiver enables you to send commands from other apps such as Tasker. Available broadcasts listed further down.

Fixed Force Close if the Main Toggle button is pressed and root was denied or the device is unsupported. (Not like you can use the app like this anyway, but still)

-------------------------------------------------------------------------------------------------------------------------------------------------------------------

BETA Version Settings

I'm still trying to figure out how android implements preferences and preference fragments. So in the beta, there is none! To change a setting, get a file browser with root access such as ES File Explorer, then navigate to the location below and edit the file "LEDPrefs.xml"

/data/data/derekziemba.ztorch/shared_prefs/

Additionally there is another file, "AppPrefs.xml" where you will find app specific settings and be able to configure the Notification.

"LEDPrefs.xml" will look like this on ZTORCH-beta-2.0.0.28. Later versions will be slightly different. I recommend uninstalling the app before installing a new beta.

default - The value the torch will turn on at when Toggled or Enabled.

inc - increment. Value the notifications "+" and "-" will increase or decrease by and the Widget will increase at if multitap = true;

multitap - If true, on successive widget taps the brightness will increase by the inc value. If false, brightness will toggle to default value;

wait - For multitap and tapguard. Time in milliseconds between successive widget taps to increase brightness. If more time than this has passed, the LED will shut off.

tapguard - To prevent accidental widget taps turning on the LED. If true, the widget ignores the first tap and waits for a second tap, unless the LED is already on.

min - just leave at 0, this is the "off" value, it is here in case some phones are reversed

max - maximum value on slider and the max value you can increment to. Only the first 3 digits of this will ever be used, giving a max possible value of 999.

warn - value at which the torch turns from yellow to a fireball and the slider begins changing colors from blue to yellow to red.

lvl - Current Brightness. There is no way to retrieve the current LED level, so the last value is stored here

sys - the system binary that controls the LED;

mask - bitmask. The brightness level is bitwise AND'ed with this value before executing the shell command to prevent invalid values. If you need help configuring this, use windows calculator and set it to programmer mode on Integer then click the bits you want to use, then use the integer value given.

"AppPrefs.xml" settings:

enableTorchOnAppLaunch - If true, opening the app will automatically set the brightness to the default value listed in "LEDPrefs.xml". Default is "false"

persistentNotif - If true, the notification will be persistent and it cannot be swiped away. Default is "false"

showNotifOnBootComplete - Posts the notification when BOOT_COMPLETE is received for easy access. Use with persistentNotif to prevent swiping away. Default is "true"

Notification Priorities. There are 5: MIN(-2), LOW(-1), DEFAULT(0), HIGH(1), and MAX(2). More info here: http://developer.android.com/design/patterns/notifications.html#guidelines

notifPriorityTorchON - Notification Priority when the LED is on. Default is "2"

notifPriorityTorchOFF - Notification Priority when the LED is off. Default is "-1". Versions before 2.0.3.41 including 1.x.x are hardcoded at "-2"

Important:

Before changing any settings, be sure to kill ZTorch with a task manager. Otherwise the settings will not take effect and they will be overwritten when the app gets sent to the background.

If you mess up the settings ZTorch will force close on launch. Delete the XML file to restore defaults.

Strobe Light:

You can get some pretty cool stobbing effects by changing the "mask" and "max" settings.

If you set the "max" value to something like 200 with the mask set to 15 (0000-1111), when sliding the slidebar from 0 to 200, the actual brightness set will repeat 0-15 over and over.

-------------------------------------------------------------------------------------------------------------------------------------------------------------------

Setting Brightness from other apps such as Tasker, using ZTorch's BroadcastReceiver

I still have to test if this works, but in theory it should. The ZTorchReceiver supports the actions below.

"derekziemba.ztorch.UPDATE_LEVEL"; //Service will check for extra Integer under the key "lvl" and set that brightness if it is valid.
"derekziemba.ztorch.WIDGET_TAP"; //Behave as if the widget was just tapped. MultiTap, TapGuard, and Wait apply.
"derekziemba.ztorch.STEP_UP"; //Increment Brightness by increment value
"derekziemba.ztorch.STEP_DOWN"; //Decrement Brightness by increment value
"derekziemba.ztorch.INCREASE"; //Increase Brightness by 1
"derekziemba.ztorch.DECREASE"; //Decrease Brightness by 1
"derekziemba.ztorch.ENABLE"; //Turn on torch at default level
"derekziemba.ztorch.DISABLE"; //Turn off torch
"derekziemba.ztorch.TOGGLE"; //Toggle the torch opposite its current state.
---------------------------------Internal---------------------------
"derekziemba.ztorch.UPDATE_FROM_MAIN"; //From main activity, prevents service from broadcasting UPDATE_FROM_SERVICE and cause an endless loop. Contains extra Integer under key "lvl"
"derekziemba.ztorch.UPDATE_FROM_SERVICE"; //Sent from the Service to Main, this one is Unregistered when Main is not visible. It is still sent by the service.

-------------------------------------------------------------------------------------------------------------------------------------------------------------------

Important Note Regarding Brightness:

For default settings I have the max LED value set to 13 because I've experienced flicker. Values higher than 10 change the color of the slider to red and the widget and notification flame from yellow to fireball. Flicker occurs when your battery voltage is to low to support the current level of brightness.

To avoid LED flicker:

>3800+mV or ~50% is needed for Levels >=13.

> 3750mV or ~30% is needed for Levels > 9.

> 3600mV or ~10% is needed for Levels > 7.

I have used my app to work several hours in an attic at brightness 11. I used my phone because it's actually significantly brighter than every flashlight I own. That includes a flashlight with a 6V cell, a 3 LED headlamp, and a 4 battery AAA LED flashlight. My only light that beat it was my spotlight, but the spotlight's beam is too focused whereas the phone lights up everything.

-------------------------------------------------------------------------------------------------------------------------------------------------------------------

Note: Android displays the build version as 1 higher than the file name. So Android will show version 2.0.3.41 as 2.0.3.42. This is caused by some Gradle Build Config bug.