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

Strip most logs in the release version #101

Merged
merged 3 commits into from
Nov 25, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/de/robv/android/xposed/XposedInit.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Module> getLegacyModulesList() {
try {
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 1 addition & 2 deletions core/src/main/java/org/lsposed/lspd/impl/LSPosedBridge.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@ private List<Module> getAllModulesList() throws RemoteException {
return ConfigManager.getInstance().getModulesForProcess(processInfo.processName, processInfo.uid);
}

@Override
public boolean isLogMuted() throws RemoteException {
return !ServiceManager.getManagerService().isVerboseLog();
}

@Override
public List<Module> getLegacyModulesList() throws RemoteException {
return getAllModulesList().stream().filter(m -> m.file.legacy).collect(Collectors.toList());
Expand Down
11 changes: 11 additions & 0 deletions magisk-loader/src/main/java/org/lsposed/lspd/core/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package org.lsposed.lspd.service;
import org.lsposed.lspd.models.Module;

interface ILSPApplicationService {
boolean isLogMuted();

List<Module> getLegacyModulesList();

List<Module> getModulesList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

import android.os.SystemProperties;
import android.text.TextUtils;
import android.util.Log;

import java.time.ZoneId;
import java.time.ZoneOffset;
Expand All @@ -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());
}
Expand Down