19

I am using YuvImage to compress the android.hardware.Camera feed to jpeg. Since then, I keep seeing skia onFlyCompress messages in logcat, which completely pollutes it. Is there any way to disable this message? I know I can filter the logcat output but that means doing it everywhere all the time, which is not a fix but a workaround. I simply don't want those messages printed at all

Guillaume
  • 2,912
  • 3
  • 35
  • 59

2 Answers2

1

You may can (i am not sure) subclass the class YuvImage which prints log and override the method of that class which prints the log and simply copy all code of that method but the Log.d() or Log.v() or Log.w() , ... code to the overridden method.

Look at the following answer too:

How do I enable/disable log levels in Android?

ygngy
  • 3,630
  • 2
  • 18
  • 29
  • 2
    `android.util.Log` is a final class and can't be overridden. Anyway the called methods are static and therefore overriding won't help. – Robert Apr 14 '18 at 12:50
  • @Robert there is no need to override `android.util.Log` or its methods .However if called method of `YuvImage` is static you may can copy codes to your class and change them as you want. you need to have source codes in this way – ygngy Apr 14 '18 at 13:26
  • Right, I misinterpreted your answer. – Robert Apr 14 '18 at 18:57
1

Short answer

Try accomplishing your goal with method hooking.

You can hook android.util.log methods using XPosed Framework on ROOTed devices.

Detailed methods

  1. Use XPosed Framework to hook the android.util.Log's methods.
  2. In the hooking method, check if the message contains skia onFlyCompress.
  3. If then call setResult(null); to prevent it from printing out the log message.

Though these methods can only be used on rooted devices, but I hope my answer help at least some users that can use rooted devices.

(Hmm, because no customers will have to block the log messages, so all you need to do is to just root your local device only and install the auto-filtering app that uses XPosed framework.)

To see an example of blocking a method from executing rest of its code: This answer(especially the last paragraph) contains some examples to use Xposed framework. As you can see, the codes are very short(no longer than 40 lines.)

I will implement some codes if needed/seen potentially useful.

Sample code snippet

As someone upvoted mine, I assume that someone liked my suggestions. So I post some codes.

import android.util.*;
import de.robv.android.xposed.*;
import de.robv.android.xposed.callbacks.XC_LoadPackage.*;

import static de.robv.android.xposed.XposedHelpers.findAndHookMethod;

public class LogFilterApp implements IXposedHookLoadPackage
{

    private String TAG="LogFilter";
     public void handleLoadPackage(final LoadPackageParam lpparam) throws Throwable
{
    XposedBridge.log("Package name: " + lpparam.packageName);

            try
            {
                    findAndHookMethod("android.util.Log", lpparam.classLoader, "i", String.class, String.class, new XC_MethodHook()
                    {
                        @Override
                        protected void beforeHookedMethod(MethodHookParam param) throws Throwable
                        {
                            //do something before
                            if(((String)(param.args[1])).indexOf("skia onFlyCompress")>=0)
                                                          { 
                                                          param.setResult(null);
                                                           }
                        }
                    });
            }
            catch (XposedHelpers.ClassNotFoundError e)
            {
                XposedBridge.log("ClassNotFoundError");
            }
            catch (NoSuchMethodError e)
            {
                XposedBridge.log("NoSuchMethodError");
            }
        }
     }
   }
}

Code reference: this XDA thread

Install XPosed Framework

XPosed Dev tutorial

KYHSGeekCode
  • 1,068
  • 2
  • 12
  • 30
  • The Windows related part at the beginning is a bit misleading - I would remove it because it diverts the readers attention from the Xposed idea - which is quite good. Especially because the problem is only relevant on the used debugging device. – Robert Apr 14 '18 at 18:55
  • @Robert You are definitely right. Thank you for your recommendation. – KYHSGeekCode Apr 15 '18 at 00:40
  • @Robert Applied your suggestions. – KYHSGeekCode Apr 15 '18 at 09:05