diff --git a/core/src/main/java/de/robv/android/xposed/XSharedPreferences.java b/core/src/main/java/de/robv/android/xposed/XSharedPreferences.java index c88b63894ac..3f645932c70 100644 --- a/core/src/main/java/de/robv/android/xposed/XSharedPreferences.java +++ b/core/src/main/java/de/robv/android/xposed/XSharedPreferences.java @@ -27,12 +27,12 @@ import android.content.SharedPreferences; import android.os.Environment; import android.preference.PreferenceManager; -import android.util.Log; import com.android.internal.util.XmlUtils; import org.lsposed.lspd.core.BuildConfig; import org.lsposed.lspd.util.MetaDataReader; +import org.lsposed.lspd.util.Utils.Log; import org.xmlpull.v1.XmlPullParserException; import java.io.File; diff --git a/core/src/main/java/de/robv/android/xposed/XposedInit.java b/core/src/main/java/de/robv/android/xposed/XposedInit.java index 6cd49140e91..97436936c55 100644 --- a/core/src/main/java/de/robv/android/xposed/XposedInit.java +++ b/core/src/main/java/de/robv/android/xposed/XposedInit.java @@ -39,13 +39,13 @@ import android.os.IBinder; import android.os.Process; import android.util.ArrayMap; -import android.util.Log; import org.lsposed.lspd.impl.LSPosedContext; import org.lsposed.lspd.models.PreLoadedApk; import org.lsposed.lspd.nativebridge.NativeAPI; import org.lsposed.lspd.nativebridge.ResourcesHook; import org.lsposed.lspd.util.LspModuleClassLoader; +import org.lsposed.lspd.util.Utils.Log; import java.io.File; import java.lang.ref.WeakReference; diff --git a/core/src/main/java/org/lsposed/lspd/core/ApplicationServiceClient.java b/core/src/main/java/org/lsposed/lspd/core/ApplicationServiceClient.java index 6cb0286875e..6eb01d0b3dc 100644 --- a/core/src/main/java/org/lsposed/lspd/core/ApplicationServiceClient.java +++ b/core/src/main/java/org/lsposed/lspd/core/ApplicationServiceClient.java @@ -57,6 +57,15 @@ synchronized static void Init(ILSPApplicationService service, String niceName) { } } + @Override + public boolean isLogMuted() { + try { + return service.isLogMuted(); + } catch (RemoteException | NullPointerException ignored) { + } + return false; + } + @Override public List getLegacyModulesList() { try { diff --git a/core/src/main/java/org/lsposed/lspd/hooker/CrashDumpHooker.java b/core/src/main/java/org/lsposed/lspd/hooker/CrashDumpHooker.java index bb01539fa7b..ea94b132caa 100644 --- a/core/src/main/java/org/lsposed/lspd/hooker/CrashDumpHooker.java +++ b/core/src/main/java/org/lsposed/lspd/hooker/CrashDumpHooker.java @@ -1,8 +1,7 @@ package org.lsposed.lspd.hooker; -import android.util.Log; - import org.lsposed.lspd.impl.LSPosedBridge; +import org.lsposed.lspd.util.Utils.Log; import io.github.libxposed.api.XposedInterface; import io.github.libxposed.api.annotations.BeforeInvocation; diff --git a/core/src/main/java/org/lsposed/lspd/hooker/LoadedApkCtorHooker.java b/core/src/main/java/org/lsposed/lspd/hooker/LoadedApkCtorHooker.java index 2ddbff32a87..e84e3d1d659 100644 --- a/core/src/main/java/org/lsposed/lspd/hooker/LoadedApkCtorHooker.java +++ b/core/src/main/java/org/lsposed/lspd/hooker/LoadedApkCtorHooker.java @@ -22,9 +22,9 @@ import android.app.LoadedApk; import android.content.res.XResources; -import android.util.Log; import org.lsposed.lspd.util.Hookers; +import org.lsposed.lspd.util.Utils.Log; import de.robv.android.xposed.XposedHelpers; import de.robv.android.xposed.XposedInit; diff --git a/core/src/main/java/org/lsposed/lspd/impl/LSPosedBridge.java b/core/src/main/java/org/lsposed/lspd/impl/LSPosedBridge.java index b47d274d749..27c7ce8cea2 100644 --- a/core/src/main/java/org/lsposed/lspd/impl/LSPosedBridge.java +++ b/core/src/main/java/org/lsposed/lspd/impl/LSPosedBridge.java @@ -1,10 +1,9 @@ package org.lsposed.lspd.impl; -import android.util.Log; - import androidx.annotation.NonNull; import org.lsposed.lspd.nativebridge.HookBridge; +import org.lsposed.lspd.util.Utils.Log; import java.lang.reflect.Executable; import java.lang.reflect.InvocationTargetException; diff --git a/core/src/main/java/org/lsposed/lspd/impl/LSPosedContext.java b/core/src/main/java/org/lsposed/lspd/impl/LSPosedContext.java index fdf8d5619c8..9c6b196342b 100644 --- a/core/src/main/java/org/lsposed/lspd/impl/LSPosedContext.java +++ b/core/src/main/java/org/lsposed/lspd/impl/LSPosedContext.java @@ -8,7 +8,6 @@ import android.os.ParcelFileDescriptor; import android.os.Process; import android.os.RemoteException; -import android.util.Log; import androidx.annotation.NonNull; import androidx.annotation.Nullable; @@ -20,6 +19,7 @@ import org.lsposed.lspd.nativebridge.NativeAPI; import org.lsposed.lspd.service.ILSPInjectedModuleService; import org.lsposed.lspd.util.LspModuleClassLoader; +import org.lsposed.lspd.util.Utils.Log; import java.io.File; import java.io.FileNotFoundException; diff --git a/core/src/main/java/org/lsposed/lspd/util/LspModuleClassLoader.java b/core/src/main/java/org/lsposed/lspd/util/LspModuleClassLoader.java index 49def72b85c..56f60b7e623 100644 --- a/core/src/main/java/org/lsposed/lspd/util/LspModuleClassLoader.java +++ b/core/src/main/java/org/lsposed/lspd/util/LspModuleClassLoader.java @@ -7,7 +7,6 @@ import android.system.ErrnoException; import android.system.Os; import android.system.OsConstants; -import android.util.Log; import androidx.annotation.NonNull; import androidx.annotation.RequiresApi; @@ -25,6 +24,8 @@ import java.util.jar.JarFile; import java.util.zip.ZipEntry; +import org.lsposed.lspd.util.Utils.Log; + import hidden.ByteBufferDexClassLoader; import sun.misc.CompoundEnumeration; diff --git a/daemon/src/main/java/org/lsposed/lspd/service/LSPApplicationService.java b/daemon/src/main/java/org/lsposed/lspd/service/LSPApplicationService.java index 40cf3316f30..259980267b1 100644 --- a/daemon/src/main/java/org/lsposed/lspd/service/LSPApplicationService.java +++ b/daemon/src/main/java/org/lsposed/lspd/service/LSPApplicationService.java @@ -126,6 +126,11 @@ private List getAllModulesList() throws RemoteException { return ConfigManager.getInstance().getModulesForProcess(processInfo.processName, processInfo.uid); } + @Override + public boolean isLogMuted() throws RemoteException { + return !ServiceManager.getManagerService().isVerboseLog(); + } + @Override public List getLegacyModulesList() throws RemoteException { return getAllModulesList().stream().filter(m -> m.file.legacy).collect(Collectors.toList()); diff --git a/magisk-loader/src/main/java/org/lsposed/lspd/core/Main.java b/magisk-loader/src/main/java/org/lsposed/lspd/core/Main.java index 0da9f9dc0c7..d908f12c99a 100644 --- a/magisk-loader/src/main/java/org/lsposed/lspd/core/Main.java +++ b/magisk-loader/src/main/java/org/lsposed/lspd/core/Main.java @@ -19,6 +19,8 @@ package org.lsposed.lspd.core; +import static org.lsposed.lspd.core.ApplicationServiceClient.serviceClient; + import android.os.IBinder; import android.os.Process; @@ -34,11 +36,20 @@ public static void forkCommon(boolean isSystem, String niceName, String appDir, if (isSystem) { ParasiticManagerSystemHooker.start(); } + Startup.initXposed(isSystem, niceName, appDir, ILSPApplicationService.Stub.asInterface(binder)); + + try { + Utils.Log.muted = serviceClient.isLogMuted(); + } catch (Throwable t) { + Utils.logE("failed to configure logs", t); + } + if (niceName.equals(BuildConfig.DEFAULT_MANAGER_PACKAGE_NAME) && ParasiticManagerHooker.start()) { Utils.logI("Loaded manager, skipping next steps"); return; } + Utils.logI("Loading xposed for " + niceName + "/" + Process.myUid()); Startup.bootstrapXposed(); } diff --git a/magisk-loader/src/main/java/org/lsposed/lspd/service/BridgeService.java b/magisk-loader/src/main/java/org/lsposed/lspd/service/BridgeService.java index 9391d886534..873196a5360 100644 --- a/magisk-loader/src/main/java/org/lsposed/lspd/service/BridgeService.java +++ b/magisk-loader/src/main/java/org/lsposed/lspd/service/BridgeService.java @@ -29,12 +29,12 @@ import android.os.IBinder; import android.os.Parcel; import android.os.RemoteException; -import android.util.Log; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import org.lsposed.lspd.BuildConfig; +import org.lsposed.lspd.util.Utils.Log; public class BridgeService { private static final int TRANSACTION_CODE = ('_' << 24) | ('L' << 16) | ('S' << 8) | 'P'; diff --git a/magisk-loader/src/main/java/org/lsposed/lspd/util/ParasiticManagerSystemHooker.java b/magisk-loader/src/main/java/org/lsposed/lspd/util/ParasiticManagerSystemHooker.java index 1b2df4ae321..578627a8599 100644 --- a/magisk-loader/src/main/java/org/lsposed/lspd/util/ParasiticManagerSystemHooker.java +++ b/magisk-loader/src/main/java/org/lsposed/lspd/util/ParasiticManagerSystemHooker.java @@ -5,16 +5,17 @@ import android.content.Intent; import android.content.pm.ActivityInfo; import android.content.pm.ResolveInfo; -import android.util.Log; import org.lsposed.lspd.hooker.HandleSystemServerProcessHooker; import org.lsposed.lspd.impl.LSPosedHelper; import org.lsposed.lspd.service.BridgeService; +import org.lsposed.lspd.util.Utils; import io.github.libxposed.api.XposedInterface; import io.github.libxposed.api.annotations.AfterInvocation; import io.github.libxposed.api.annotations.XposedHooker; + public class ParasiticManagerSystemHooker implements HandleSystemServerProcessHooker.Callback { public static void start() { HandleSystemServerProcessHooker.callback = new ParasiticManagerSystemHooker(); @@ -78,9 +79,9 @@ public void onSystemServerLoaded(ClassLoader classLoader) { HookBridge.deoptimizeMethod(method); } LSPosedHelper.hookAllMethods(Hooker2.class, Class.forName("com.android.server.wm.ActivityStarter", false, classLoader), "execute");*/ - Log.d("LSPosed", "hooked activity starter"); + Utils.logD("hooked activity starter"); } catch (Throwable e) { - Log.e("LSPosed", "onSystemServerLoaded: ", e); + Utils.logE("onSystemServerLoaded: ", e); } } } diff --git a/services/daemon-service/src/main/aidl/org/lsposed/lspd/service/ILSPApplicationService.aidl b/services/daemon-service/src/main/aidl/org/lsposed/lspd/service/ILSPApplicationService.aidl index 4f01ab0eb94..b85b6ed2130 100644 --- a/services/daemon-service/src/main/aidl/org/lsposed/lspd/service/ILSPApplicationService.aidl +++ b/services/daemon-service/src/main/aidl/org/lsposed/lspd/service/ILSPApplicationService.aidl @@ -3,6 +3,8 @@ package org.lsposed.lspd.service; import org.lsposed.lspd.models.Module; interface ILSPApplicationService { + boolean isLogMuted(); + List getLegacyModulesList(); List getModulesList(); diff --git a/services/daemon-service/src/main/java/org/lsposed/lspd/util/Utils.java b/services/daemon-service/src/main/java/org/lsposed/lspd/util/Utils.java index 2be5970dda5..d978d17144b 100644 --- a/services/daemon-service/src/main/java/org/lsposed/lspd/util/Utils.java +++ b/services/daemon-service/src/main/java/org/lsposed/lspd/util/Utils.java @@ -22,7 +22,6 @@ import android.os.SystemProperties; import android.text.TextUtils; -import android.util.Log; import java.time.ZoneId; import java.time.ZoneOffset; @@ -34,6 +33,61 @@ public class Utils { public static final boolean isMIUI = !TextUtils.isEmpty(SystemProperties.get("ro.miui.ui.version.name")); public static final boolean isLENOVO = !TextUtils.isEmpty(SystemProperties.get("ro.lenovo.region")); + public class Log { + public static boolean muted = false; + + public static String getStackTraceString(Throwable tr) { + return android.util.Log.getStackTraceString(tr); + } + + public static void d(String tag, String msg) { + if (muted) return; + android.util.Log.d(tag, msg); + } + + public static void d(String tag, String msg, Throwable tr) { + android.util.Log.d(tag, msg, tr); + } + + public static void v(String tag, String msg) { + if (muted) return; + android.util.Log.v(tag, msg); + } + + public static void v(String tag, String msg, Throwable tr) { + android.util.Log.v(tag, msg, tr); + } + + public static void i(String tag, String msg) { + if (muted) return; + android.util.Log.i(tag, msg); + } + + public static void i(String tag, String msg, Throwable tr) { + android.util.Log.i(tag, msg, tr); + } + + public static void w(String tag, String msg) { + if (muted) return; + android.util.Log.w(tag, msg); + } + + public static void w(String tag, String msg, Throwable tr) { + if (muted) return; + android.util.Log.w(tag, msg, tr); + } + + public static void e(String tag, String msg) { + android.util.Log.e(tag, msg); + } + + public static void e(String tag, String msg, Throwable tr) { + android.util.Log.e(tag, msg, tr); + } + + + } + public static void logD(Object msg) { Log.d(LOG_TAG, msg.toString()); }