Allow to de-activate log watchlog (#20)
Requested by #14, a switch is added to the release version. Patch of msvamp rejected in original repository mywalk added ui interface Co-authored-by: mywalk <66966897+mywalkb@users.noreply.github.com>
This commit is contained in:
parent
e28e194682
commit
b317b48e9a
|
|
@ -178,6 +178,25 @@ public class ConfigManager {
|
|||
}
|
||||
}
|
||||
|
||||
public static boolean isLogWatchdogEnabled() {
|
||||
try {
|
||||
return LSPManagerServiceHolder.getService().isLogWatchdogEnabled();
|
||||
} catch (RemoteException e) {
|
||||
Log.e(App.TAG, Log.getStackTraceString(e));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean setLogWatchdog(boolean enabled) {
|
||||
try {
|
||||
LSPManagerServiceHolder.getService().setLogWatchdog(enabled);
|
||||
return true;
|
||||
} catch (RemoteException e) {
|
||||
Log.e(App.TAG, Log.getStackTraceString(e));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static ParcelFileDescriptor getLog(boolean verbose) {
|
||||
try {
|
||||
return verbose ? LSPManagerServiceHolder.getService().getVerboseLog() : LSPManagerServiceHolder.getService().getModulesLog();
|
||||
|
|
|
|||
|
|
@ -160,6 +160,13 @@ public class SettingsFragment extends BaseFragment {
|
|||
prefVerboseLogs.setOnPreferenceChangeListener((preference, newValue) -> ConfigManager.setVerboseLogEnabled(!(boolean) newValue));
|
||||
}
|
||||
|
||||
MaterialSwitchPreference prefEnableLog = findPreference("enable_log_watchdog");
|
||||
if (prefEnableLog != null) {
|
||||
prefEnableLog.setEnabled(!BuildConfig.DEBUG && installed);
|
||||
prefEnableLog.setChecked(!installed || ConfigManager.isLogWatchdogEnabled());
|
||||
prefEnableLog.setOnPreferenceChangeListener((preference, newValue) -> ConfigManager.setLogWatchdog((boolean) newValue));
|
||||
}
|
||||
|
||||
MaterialSwitchPreference prefDexObfuscate = findPreference("enable_dex_obfuscate");
|
||||
if (prefDexObfuscate != null) {
|
||||
prefDexObfuscate.setEnabled(installed);
|
||||
|
|
|
|||
|
|
@ -175,6 +175,8 @@
|
|||
<string name="settings_group_framework">Framework</string>
|
||||
<string name="settings_disable_verbose_log">Disable verbose logs</string>
|
||||
<string name="settings_disable_verbose_log_summary">Report issues request to include verbose logs</string>
|
||||
<string name="settings_enable_log_watchdog">Enable log watchdog</string>
|
||||
<string name="settings_enable_log_watchdog_summary">Log watchdog of LSPosed modifies system properties, which could be exploited to detect LSPosed</string>
|
||||
<string name="pure_black_dark_theme">Black dark theme</string>
|
||||
<string name="pure_black_dark_theme_summary">Use the pure black theme if dark theme is enabled</string>
|
||||
<string name="settings_group_theme">Theme</string>
|
||||
|
|
|
|||
|
|
@ -91,6 +91,14 @@
|
|||
android:summary="@string/settings_disable_verbose_log_summary"
|
||||
android:title="@string/settings_disable_verbose_log" />
|
||||
|
||||
<rikka.material.preference.MaterialSwitchPreference
|
||||
android:defaultValue="true"
|
||||
android:icon="@drawable/ic_outline_assignment_24"
|
||||
android:key="enable_log_watchdog"
|
||||
android:persistent="false"
|
||||
android:summary="@string/settings_enable_log_watchdog_summary"
|
||||
android:title="@string/settings_enable_log_watchdog" />
|
||||
|
||||
<rikka.material.preference.MaterialSwitchPreference
|
||||
android:defaultValue="true"
|
||||
android:icon="@drawable/ic_outline_shield_24"
|
||||
|
|
|
|||
|
|
@ -99,6 +99,7 @@ public class ConfigManager {
|
|||
private final SQLiteDatabase db = openDb();
|
||||
|
||||
private boolean verboseLog = true;
|
||||
private boolean logWatchdog = true;
|
||||
private boolean dexObfuscate = true;
|
||||
private boolean enableStatusNotification = true;
|
||||
private Path miscPath = null;
|
||||
|
|
@ -270,6 +271,9 @@ public class ConfigManager {
|
|||
Object bool = config.get("enable_verbose_log");
|
||||
verboseLog = bool == null || (boolean) bool;
|
||||
|
||||
bool = config.get("enable_log_watchdog");
|
||||
logWatchdog = bool == null || (boolean) bool;
|
||||
|
||||
bool = config.get("enable_dex_obfuscate");
|
||||
dexObfuscate = bool == null || (boolean) bool;
|
||||
|
||||
|
|
@ -1048,6 +1052,21 @@ public class ConfigManager {
|
|||
return BuildConfig.DEBUG || verboseLog;
|
||||
}
|
||||
|
||||
public void setLogWatchdog(boolean on) {
|
||||
var logcatService = ServiceManager.getLogcatService();
|
||||
if (on) {
|
||||
logcatService.enableWatchdog();
|
||||
} else {
|
||||
logcatService.disableWatchdog();
|
||||
}
|
||||
updateModulePrefs("lspd", 0, "config", "enable_log_watchdog", on);
|
||||
logWatchdog = on;
|
||||
}
|
||||
|
||||
public boolean isLogWatchdogEnabled() {
|
||||
return logWatchdog;
|
||||
}
|
||||
|
||||
public void setDexObfuscate(boolean on) {
|
||||
updateModulePrefs("lspd", 0, "config", "enable_dex_obfuscate", on);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -546,4 +546,14 @@ public class LSPManagerService extends ILSPManagerService.Stub {
|
|||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLogWatchdog(boolean enabled) {
|
||||
ConfigManager.getInstance().setLogWatchdog(enabled);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLogWatchdogEnabled() {
|
||||
return ConfigManager.getInstance().isLogWatchdogEnabled();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -182,6 +182,14 @@ public class LogcatService implements Runnable {
|
|||
Log.i(TAG, "!!stop_verbose!!");
|
||||
}
|
||||
|
||||
public void enableWatchdog() {
|
||||
Log.i(TAG, "!!start_watchdog!!");
|
||||
}
|
||||
|
||||
public void disableWatchdog() {
|
||||
Log.i(TAG, "!!stop_watchdog!!");
|
||||
}
|
||||
|
||||
public void refresh(boolean isVerboseLog) {
|
||||
if (isVerboseLog) {
|
||||
Log.i(TAG, "!!refresh_verbose!!");
|
||||
|
|
|
|||
|
|
@ -115,6 +115,15 @@ public class ServiceManager {
|
|||
logcatService = new LogcatService();
|
||||
logcatService.start();
|
||||
|
||||
// get config before package service is started
|
||||
// otherwise getInstance will trigger module/scope cache
|
||||
var configManager = ConfigManager.getInstance();
|
||||
// --- DO NOT call ConfigManager.getInstance later!!! ---
|
||||
|
||||
// Unblock log watchdog before starting anything else
|
||||
if (configManager.isLogWatchdogEnabled())
|
||||
logcatService.enableWatchdog();
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R)
|
||||
permissionManagerWorkaround();
|
||||
|
||||
|
|
@ -133,11 +142,6 @@ public class ServiceManager {
|
|||
|
||||
systemServerService.putBinderForSystemServer();
|
||||
|
||||
// get config before package service is started
|
||||
// otherwise getInstance will trigger module/scope cache
|
||||
var configManager = ConfigManager.getInstance();
|
||||
// --- DO NOT call ConfigManager.getInstance later!!! ---
|
||||
|
||||
ActivityThread.systemMain();
|
||||
|
||||
DdmHandleAppName.setAppName("org.lsposed.daemon", 0);
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
#include <string>
|
||||
#include <android/log.h>
|
||||
#include <array>
|
||||
#include <atomic>
|
||||
#include <cinttypes>
|
||||
#include <chrono>
|
||||
#include <thread>
|
||||
|
|
@ -129,6 +130,7 @@ private:
|
|||
pid_t my_pid_ = getpid();
|
||||
|
||||
bool verbose_ = true;
|
||||
std::atomic<bool> enable_watchdog = std::atomic<bool>(false);
|
||||
};
|
||||
|
||||
size_t Logcat::PrintLogLine(const AndroidLogEntry &entry, FILE *out) {
|
||||
|
|
@ -241,6 +243,12 @@ void Logcat::ProcessBuffer(struct log_msg *buf) {
|
|||
RefreshFd(false);
|
||||
} else if (msg == "!!refresh_verbose!!"sv) {
|
||||
RefreshFd(true);
|
||||
} else if (msg == "!!start_watchdog!!"sv) {
|
||||
enable_watchdog = true;
|
||||
enable_watchdog.notify_one();
|
||||
} else if (msg == "!!stop_watchdog!!"sv) {
|
||||
enable_watchdog = false;
|
||||
enable_watchdog.notify_one();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -253,6 +261,7 @@ void Logcat::EnsureLogWatchDog() {
|
|||
constexpr static size_t kErr = -1;
|
||||
std::thread watch_dog([this] {
|
||||
while (true) {
|
||||
enable_watchdog.wait(false);
|
||||
auto logd_size = GetByteProp(kLogdSizeProp);
|
||||
auto logd_tag = GetStrProp(kLogdTagProp);
|
||||
auto logd_main_size = GetByteProp(kLogdMainSizeProp);
|
||||
|
|
@ -277,8 +286,9 @@ void Logcat::EnsureLogWatchDog() {
|
|||
}, &serial);
|
||||
}
|
||||
if (!__system_property_wait(pi, serial, &serial, nullptr)) break;
|
||||
if (pi != nullptr) Log("\nResetting log settings\n");
|
||||
else std::this_thread::sleep_for(1s);
|
||||
if (pi != nullptr) {
|
||||
if (enable_watchdog) Log("\nResetting log settings\n");
|
||||
} else std::this_thread::sleep_for(1s);
|
||||
// log tag prop was not found; to avoid frequently trigger wait, sleep for a while
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -87,4 +87,8 @@ interface ILSPManagerService {
|
|||
boolean enableStatusNotification() = 47;
|
||||
|
||||
void setEnableStatusNotification(boolean enable) = 48;
|
||||
|
||||
void setLogWatchdog(boolean enable) = 49;
|
||||
|
||||
boolean isLogWatchdogEnabled() = 50;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue