[core] Fix modules' log
This commit is contained in:
parent
85e6b88bf5
commit
346a1d0d75
|
|
@ -16,4 +16,6 @@ interface ILSPApplicationService {
|
|||
String getPrefsPath(String packageName) = 7;
|
||||
|
||||
String getCachePath(String fileName) = 8;
|
||||
|
||||
ParcelFileDescriptor getModuleLogger() = 9;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,25 +26,23 @@
|
|||
#include <fcntl.h>
|
||||
|
||||
namespace lspd {
|
||||
LSP_DEF_NATIVE_METHOD(void, Logger, nativeLog, jstring jstr) {
|
||||
// TODO: get log path
|
||||
// static int fd = open(ConfigManager::GetModulesLogPath().c_str(), O_APPEND | O_WRONLY);
|
||||
// if (fd < 0) {
|
||||
// LOGD("Logger fail: %s", strerror(errno));
|
||||
// return;
|
||||
// }
|
||||
// JUTFString str(env, jstr);
|
||||
// int res = write(fd, str.get(), std::strlen(str.get()));
|
||||
// if (res < 0) {
|
||||
// LOGD("Logger fail: %s", strerror(errno));
|
||||
// }
|
||||
LSP_DEF_NATIVE_METHOD(void, ModuleLogger, nativeLog, int fd, jstring jstr) {
|
||||
if (fd < 0) {
|
||||
LOGE("fd is -1");
|
||||
return;
|
||||
}
|
||||
JUTFString str(env, jstr);
|
||||
int res = write(fd, str.get(), std::strlen(str.get()));
|
||||
if (res < 0) {
|
||||
LOGD("Logger fail: %s", strerror(errno));
|
||||
}
|
||||
}
|
||||
|
||||
static JNINativeMethod gMethods[] = {
|
||||
LSP_NATIVE_METHOD(Logger, nativeLog, "(Ljava/lang/String;)V")
|
||||
LSP_NATIVE_METHOD(ModuleLogger, nativeLog, "(ILjava/lang/String;)V")
|
||||
};
|
||||
|
||||
void RegisterLogger(JNIEnv *env) {
|
||||
REGISTER_LSP_NATIVE_METHODS(Logger);
|
||||
REGISTER_LSP_NATIVE_METHODS(ModuleLogger);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ import de.robv.android.xposed.callbacks.XC_LoadPackage;
|
|||
import de.robv.android.xposed.callbacks.XCallback;
|
||||
import external.com.android.dx.DexMaker;
|
||||
import external.com.android.dx.TypeId;
|
||||
import io.github.lsposed.lspd.nativebridge.Logger;
|
||||
import io.github.lsposed.lspd.nativebridge.ModuleLogger;
|
||||
|
||||
import static de.robv.android.xposed.XposedHelpers.getIntField;
|
||||
import static de.robv.android.xposed.XposedHelpers.setObjectField;
|
||||
|
|
@ -171,7 +171,7 @@ public final class XposedBridge {
|
|||
*/
|
||||
public synchronized static void log(String text) {
|
||||
Log.i(TAG, text);
|
||||
Logger.log(text);
|
||||
ModuleLogger.log(text);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -185,7 +185,7 @@ public final class XposedBridge {
|
|||
public synchronized static void log(Throwable t) {
|
||||
String logStr = Log.getStackTraceString(t);
|
||||
Log.e(TAG, logStr);
|
||||
Logger.log(logStr);
|
||||
ModuleLogger.log(logStr);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -1,10 +1,12 @@
|
|||
package io.github.lsposed.lspd.config;
|
||||
|
||||
import android.os.IBinder;
|
||||
import android.os.ParcelFileDescriptor;
|
||||
import android.os.RemoteException;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import io.github.lsposed.lspd.service.ConfigManager;
|
||||
import io.github.lsposed.lspd.service.ILSPApplicationService;
|
||||
import io.github.lsposed.lspd.util.Utils;
|
||||
|
||||
|
|
@ -117,6 +119,15 @@ public class LSPApplicationServiceClient implements ILSPApplicationService {
|
|||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ParcelFileDescriptor getModuleLogger() {
|
||||
try {
|
||||
return service.getModuleLogger();
|
||||
} catch (RemoteException | NullPointerException ignored) {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBinder asBinder() {
|
||||
return serviceBinder;
|
||||
|
|
|
|||
|
|
@ -20,21 +20,33 @@
|
|||
|
||||
package io.github.lsposed.lspd.nativebridge;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
|
||||
import android.app.ActivityThread;
|
||||
import android.app.AndroidAppHelper;
|
||||
import android.os.ParcelFileDescriptor;
|
||||
import android.os.Process;
|
||||
|
||||
public class Logger {
|
||||
static SimpleDateFormat logDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.sss", Locale.getDefault());
|
||||
import io.github.lsposed.lspd.util.Utils;
|
||||
|
||||
public static native void nativeLog(String str);
|
||||
public class ModuleLogger {
|
||||
static SimpleDateFormat logDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.sss", Locale.getDefault());
|
||||
static int fd = -1;
|
||||
|
||||
public static void initLogger(ParcelFileDescriptor fileDescriptor) {
|
||||
if (fd == -1 && fileDescriptor!= null) {
|
||||
fd = fileDescriptor.getFd();
|
||||
}
|
||||
}
|
||||
|
||||
private static native void nativeLog(int fd, String logStr);
|
||||
|
||||
public static void log(String str) {
|
||||
if (fd == -1) {
|
||||
Utils.logE("Logger is not initialized");
|
||||
return;
|
||||
};
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(logDateFormat.format(new Date()));
|
||||
sb.append(' ');
|
||||
|
|
@ -49,6 +61,6 @@ public class Logger {
|
|||
sb.append("LSPosedBridge: ");
|
||||
sb.append(str);
|
||||
sb.append('\n');
|
||||
nativeLog(sb.toString());
|
||||
nativeLog(fd, sb.toString());
|
||||
}
|
||||
}
|
||||
|
|
@ -25,10 +25,12 @@ import android.os.Environment;
|
|||
import java.io.File;
|
||||
|
||||
import io.github.lsposed.lspd.deopt.PrebuiltMethodsDeopter;
|
||||
import io.github.lsposed.lspd.nativebridge.ModuleLogger;
|
||||
import io.github.lsposed.lspd.util.Utils;
|
||||
|
||||
import de.robv.android.xposed.SELinuxHelper;
|
||||
import de.robv.android.xposed.XposedInit;
|
||||
|
||||
import static io.github.lsposed.lspd.config.LSPApplicationServiceClient.serviceClient;
|
||||
|
||||
public class NormalProxy extends BaseProxy {
|
||||
|
||||
|
|
@ -47,6 +49,8 @@ public class NormalProxy extends BaseProxy {
|
|||
|
||||
|
||||
private void forkPostCommon(boolean isSystem, String appDataDir, String niceName) {
|
||||
// init logger
|
||||
ModuleLogger.initLogger(serviceClient.getModuleLogger());
|
||||
SELinuxHelper.initOnce();
|
||||
mRouter.initResourcesHook();
|
||||
mRouter.prepare(isSystem);
|
||||
|
|
|
|||
|
|
@ -273,7 +273,7 @@ public class BridgeService {
|
|||
try {
|
||||
ILSPosedService service = ILSPosedService.Stub.asInterface(binder);
|
||||
ILSPApplicationService applicationService = service.requestApplicationService(Process.myUid(), Process.myPid());
|
||||
if (applicationService != null) applicationService.asBinder();
|
||||
if (applicationService != null) return applicationService.asBinder();
|
||||
} catch (Throwable e) {
|
||||
Log.e(TAG, Log.getStackTraceString(e));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -367,9 +367,9 @@ public class ConfigManager {
|
|||
return variant;
|
||||
}
|
||||
|
||||
public ParcelFileDescriptor getModulesLog() {
|
||||
public ParcelFileDescriptor getModulesLog(int mode) {
|
||||
try {
|
||||
return ParcelFileDescriptor.open(modulesLogPath, ParcelFileDescriptor.MODE_READ_ONLY);
|
||||
return ParcelFileDescriptor.open(modulesLogPath, mode | ParcelFileDescriptor.MODE_CREATE);
|
||||
} catch (FileNotFoundException e) {
|
||||
Log.e(TAG, Log.getStackTraceString(e));
|
||||
return null;
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package io.github.lsposed.lspd.service;
|
|||
|
||||
import android.os.Binder;
|
||||
import android.os.IBinder;
|
||||
import android.os.ParcelFileDescriptor;
|
||||
import android.os.RemoteException;
|
||||
import android.util.Log;
|
||||
import android.util.Pair;
|
||||
|
|
@ -64,6 +65,12 @@ public class LSPApplicationService extends ILSPApplicationService.Stub {
|
|||
return ConfigManager.getInstance().getCachePath(fileName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ParcelFileDescriptor getModuleLogger() throws RemoteException {
|
||||
ensureRegistered();
|
||||
return ConfigManager.getInstance().getModulesLog(ParcelFileDescriptor.MODE_WRITE_ONLY | ParcelFileDescriptor.MODE_APPEND);
|
||||
}
|
||||
|
||||
// TODO: check if module
|
||||
@Override
|
||||
public IBinder requestModuleBinder() throws RemoteException {
|
||||
|
|
|
|||
|
|
@ -111,7 +111,7 @@ public class LSPManagerService extends ILSPManagerService.Stub {
|
|||
|
||||
@Override
|
||||
public ParcelFileDescriptor getModulesLog() {
|
||||
return ConfigManager.getInstance().getModulesLog();
|
||||
return ConfigManager.getInstance().getModulesLog(ParcelFileDescriptor.MODE_READ_ONLY);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -144,15 +144,16 @@ fi
|
|||
|
||||
chcon -R u:object_r:system_file:s0 "${MODDIR}"
|
||||
chcon -R u:object_r:system_file:s0 "/data/adb/lspd"
|
||||
rm -rf ${LOG_PATH}.old
|
||||
mv ${LOG_PATH} ${LOG_PATH}.old
|
||||
mkdir -p ${LOG_PATH}
|
||||
chcon -R u:object_r:magisk_file:s0 ${LOG_PATH}
|
||||
|
||||
if [[ ! -z "${MISC_PATH}" ]]; then
|
||||
mkdir -p "${BASE_PATH}/cache"
|
||||
chcon -R u:object_r:magisk_file:s0 "${BASE_PATH}"
|
||||
chmod 771 "${BASE_PATH}"
|
||||
chmod 777 "${BASE_PATH}/cache"
|
||||
rm -rf ${LOG_PATH}.old
|
||||
mv ${LOG_PATH} ${LOG_PATH}.old
|
||||
mkdir -p ${LOG_PATH}
|
||||
print_log_head "${LOG_PATH}/modules.log"
|
||||
# start_verbose_log_catcher
|
||||
start_log_catcher all "LSPosed:V XSharedPreferences:V LSPosed-Bridge:V LSPosedManager:V *:F" true ${LOG_VERBOSE}
|
||||
|
|
|
|||
Loading…
Reference in New Issue