Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Torch fixes #77

Open
wants to merge 3 commits into
base: android-9.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ tags
*.img
*.zip
.vscode
.venv
5 changes: 5 additions & 0 deletions Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,15 @@ endif
ifeq ($(PB_DISABLE_DEFAULT_TREBLE_COMP),true)
LOCAL_CFLAGS += -DPB_DISABLE_DEFAULT_TREBLE_COMP=$(PB_DISABLE_DEFAULT_TREBLE_COMP)
endif

ifneq ($(PB_TORCH_MAX_BRIGHTNESS),)
LOCAL_CFLAGS += -DPB_MAX_BRIGHT_VALUE=\"$(PB_TORCH_BRIGHTNESS_MAX)\"
endif

ifneq ($(PB_TORCH_PATH),)
LOCAL_CFLAGS += -DPB_TORCH_PATH=\"$(PB_TORCH_PATH)\"
endif

LOCAL_SRC_FILES := \
twrp.cpp \
fixContexts.cpp \
Expand Down
1 change: 1 addition & 0 deletions data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -835,6 +835,7 @@ void DataManager::SetDefaultValues()
mData.SetValue("pb_torch_on", "0");
mData.SetValue("pb_include_logs_after_flash", "0");
mData.SetValue("pb_include_dmesg_logging", "0");
mData.SetValue("pb_torch_theme_support", "0");
#ifdef PB_MAX_BRIGHT_VALUE
mConst.SetValue("pb_torch_brightness_slider", "0");
#endif
Expand Down
3 changes: 0 additions & 3 deletions gui/Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,6 @@ endif
ifeq ($(TW_SCREEN_BLANK_ON_BOOT), true)
LOCAL_CFLAGS += -DTW_SCREEN_BLANK_ON_BOOT
endif
ifneq ($(PB_TORCH_PATH),)
LOCAL_CFLAGS += -DPB_TORCH_PATH=\"$(PB_TORCH_PATH)\"
endif
ifneq ($(PB_TORCH_MAX_BRIGHTNESS),)
LOCAL_CFLAGS += -DPB_MAX_BRIGHT_VALUE=$(PB_TORCH_MAX_BRIGHTNESS)
endif
Expand Down
58 changes: 12 additions & 46 deletions gui/action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ pid_t sideload_child_pid;
extern std::vector<users_struct> Users_List;
extern GUITerminal* term;

// PB Flashlight Paths
extern std::string pb_torch_flashpath;
extern std::string pb_torch_switchpath;

static void *ActionThread_work_wrapper(void *data);

class ActionThread
Expand Down Expand Up @@ -2449,51 +2453,16 @@ int GUIAction::repack(std::string arg __unused)

int GUIAction::flashlight(std::string arg __unused)
{
int br_value = DataManager::GetIntValue("pb_bright_value");
string str_val, file, flashp1 = "/sys/class/leds", flashp2 = "/flashlight", flashpath;
string bright = "/brightness";
string switch_path = TWFunc::Path_Exists(flashp1 + "/led:switch" + bright) ? (flashp1 + "/led:switch") : (flashp1 + "/led:switch_0");
DIR* d;
struct dirent* de __attribute__((unused));
if (DataManager::GetIntValue("pb_torch_theme_support") == 1) {
string bright = "/brightness";
int br_value = DataManager::GetIntValue("pb_bright_value");
string switch_path = pb_torch_switchpath;
string flashpath = pb_torch_flashpath;
#ifdef PB_MAX_BRIGHT_VALUE
br_value = PB_MAX_BRIGHT_VALUE;
DataManager::SetValue("pb_torch_brightness_slider", "0");
#endif
#ifdef PB_TORCH_PATH
flashpath = PB_TORCH_PATH;
LOGINFO("flashlight: Custom Node located at '%s'\n", flashpath.c_str());
if (TWFunc::Path_Exists(flashpath))
{
d = opendir(flashpath.c_str());
if (d != NULL)
flashpath += bright;
}
#else
flashpath = flashp1 + flashp2 + bright;
if (!TWFunc::Path_Exists(flashpath))
{
d = opendir(flashp1.c_str());
if (d == NULL)
{
LOGINFO("Unable to open '%s'\n", flashp1.c_str());
return 0;
}
while ((de = readdir(d)) != NULL)
{
file = de->d_name;
if(file.find("torch") != string::npos || file.find("torch_"))
{
flashpath = flashp1 + "/" + file + bright;
break;
}
}
closedir (d);
LOGINFO("Detected Node located at '%s'\n", flashpath.c_str());
}
br_value = PB_MAX_BRIGHT_VALUE;
DataManager::SetValue("pb_torch_brightness_slider", "0");
#endif
str_val="";
if (TWFunc::Path_Exists(flashpath)) {
LOGINFO("Flashlight Node Located at '%s'\n", flashpath.c_str());

if (DataManager::GetIntValue("pb_torch_on") == 1)
{
LOGINFO("Flashlight Turning Off\n");
Expand All @@ -2511,9 +2480,6 @@ int GUIAction::flashlight(std::string arg __unused)
TWFunc::write_to_file(switch_path + bright, "1");
DataManager::SetValue("pb_torch_on", "1");
}
} else {
LOGINFO("Incorrect Flashlight Path\n");
DataManager::SetValue("pb_torch_brightness_slider", "0");
}
return 0;
}
Expand Down
15 changes: 12 additions & 3 deletions gui/theme/common/portrait.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4049,7 +4049,10 @@
</slidervalue>

<slidervalue>
<condition var1="pb_torch_brightness_slider" op="!=" var2="0"/>
<conditions>
<condition var1="pb_torch_theme_support" var2="1"/>
<condition var1="pb_torch_brightness_slider" op="!=" var2="0"/>
</conditions>
<placement x="90" y="%row16_y%" w="900"/>
<text>{@sel_br_val=Flashlight Brightness Value: %pb_bright_value%%}</text>
<data variable="pb_bright_value" min="1" max="255"/>
Expand Down Expand Up @@ -4817,15 +4820,21 @@
</image>

<button>
<condition var1="pb_torch_on" var2="0"/>
<conditions>
<condition var1="pb_torch_theme_support" var2="1"/>
<condition var1="pb_torch_on" var2="0"/>
</conditions>
<placement x="%row4_header_y%" y="%row11_y%" />
<!--<highlight color="#1E1E1E30" />-->
<image resource="button_torch_off"/>
<action function="flashlight" />
</button>

<button>
<condition var1="pb_torch_on" var2="1"/>
<conditions>
<condition var1="pb_torch_theme_support" var2="1"/>
<condition var1="pb_torch_on" var2="1"/>
</conditions>
<placement x="%row4_header_y%" y="%row11_y%" />
<!--<highlight color="#1E1E1E30" />-->
<image resource="button_torch_on"/>
Expand Down
1 change: 1 addition & 0 deletions gui/theme/portrait_hdpi/ui.xml
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,7 @@
</button>

<button style="main_button_back2">
<condition var1="pb_torch_theme_support" var2="1"/>
<placement x="380" y="%row24_y%"/>
<highlight color="%highlight_color%"/>
<icon resource="flash"/>
Expand Down
58 changes: 58 additions & 0 deletions twrp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <time.h>
#include <unistd.h>
#include <signal.h>
#include <dirent.h>
#include "gui/twmsg.h"

#include "cutils/properties.h"
Expand Down Expand Up @@ -71,6 +72,10 @@ TWPartitionManager PartitionManager;
int Log_Offset;
bool datamedia;

// PB Flashlight Paths
std::string pb_torch_flashpath;
std::string pb_torch_switchpath;

static void Print_Prop(const char *key, const char *name, void *cookie) {
printf("%s=%s\n", key, name);
}
Expand Down Expand Up @@ -436,6 +441,59 @@ int main(int argc, char **argv) {
PartitionManager.Change_System_Root(false);
}

// Find and Set Flashlight path
string bright = "/brightness";
DIR* d;
struct dirent* de __attribute__((unused));
string file, flashp1 = "/sys/class/leds", flashp2 = "/flashlight", flashpath;
string switch_path = TWFunc::Path_Exists(flashp1 + "/led:switch" + bright) ? (flashp1 + "/led:switch") : (flashp1 + "/led:switch_0");
pb_torch_switchpath = switch_path;

#ifdef PB_TORCH_PATH
flashpath = PB_TORCH_PATH;
LOGINFO("Flashlight: Custom Node located at '%s'\n", flashpath.c_str());
if (TWFunc::Path_Exists(flashpath))
{
d = opendir(flashpath.c_str());
if (d != NULL) {
flashpath += bright;
DataManager::SetValue("pb_torch_theme_support", "1");
}
closedir(d);
}
#else
flashpath = flashp1 + flashp2 + bright;

if (!TWFunc::Path_Exists(flashpath))
{
d = opendir(flashp1.c_str());
if (d == NULL)
{
LOGINFO("Unable to open '%s'\n", flashp1.c_str());
DataManager::SetValue("pb_torch_theme_support", "0");
}
while ((de = readdir(d)) != NULL)
{
file = de->d_name;
if(file.find("torch") != string::npos || file.find("torch_"))
{
flashpath = flashp1 + "/" + file + bright;
break;
}
}
closedir (d);
LOGINFO("Detected Node located at '%s'\n", flashpath.c_str());
}
#endif
if(TWFunc::Path_Exists(flashpath)) {
LOGINFO("Flashlight Node Located at '%s'\n", flashpath.c_str());
DataManager::SetValue("pb_torch_theme_support", "1");
pb_torch_flashpath = flashpath;
} else {
LOGINFO("Incorrect Flashlight Path\n");
DataManager::SetValue("pb_torch_brightness_slider", "0");
}

// Launch the main GUI
gui_start();

Expand Down
3 changes: 3 additions & 0 deletions variables.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <string>

#ifndef _VARIABLES_HEADER_
#define _VARIABLES_HEADER_
Expand Down Expand Up @@ -177,6 +178,8 @@
#define PB_ADVANCED_STOCK_REPLACE "pb_reboot_advanced_stock_recovery_check"
#define PB_DISABLE_REBOOT_OTA "pb_disable_reboot_ota"
#define PB_MOUNT_SYSTEM_AS_ROOT "pb_mount_system_as_root"
#define PB_TORCH_THEME_SUPPORT "pb_torch_theme_support"

#define TRB_EN "0"
#define STD "0"
#define NON_STD "0"
Expand Down