j.java 源代码


package com.apm.insight.b;

import android.os.Looper;
import android.text.TextUtils;
import android.util.Log;
import android.util.Printer;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;

public final class j {

    private static int f6378a = 5;

    private static b f6379b;

    private static a f6380c;

    private static boolean f6381d;

    private static Printer f6382e;

    public interface a {
        void a(long j6);
    }

    static class b implements Printer {

        List<Printer> f6383a = new ArrayList();

        List<Printer> f6384b = new ArrayList();

        List<Printer> f6385c = new ArrayList();

        boolean f6386d = false;

        boolean f6387e = false;

        b() {
        }

        @Override
        public void println(String str) {
            long j6;
            if (TextUtils.isEmpty(str)) {
                return;
            }
            if (j.f6380c != null) {
                j6 = System.currentTimeMillis();
            } else {
                j6 = 0;
            }
            if (str.charAt(0) == '>' && this.f6387e) {
                for (Printer printer : this.f6385c) {
                    if (!this.f6383a.contains(printer)) {
                        this.f6383a.add(printer);
                    }
                }
                this.f6385c.clear();
                this.f6387e = false;
            }
            if (this.f6383a.size() > j.f6378a) {
                Log.e("LooperPrinterUtils", "wrapper contains too many printer,please check if the useless printer have been removed");
            }
            for (Printer printer2 : this.f6383a) {
                if (printer2 != null) {
                    printer2.println(str);
                }
            }
            if (str.charAt(0) == '<' && this.f6386d) {
                for (Printer printer3 : this.f6384b) {
                    this.f6383a.remove(printer3);
                    this.f6385c.remove(printer3);
                }
                this.f6384b.clear();
                this.f6386d = false;
            }
            if (j.f6380c != null && j6 > 0) {
                j.f6380c.a(System.currentTimeMillis() - j6);
            }
        }
    }

    public static void a() {
        if (f6381d) {
            return;
        }
        f6381d = true;
        f6379b = new b();
        Printer d6 = d();
        f6382e = d6;
        if (d6 != null) {
            f6379b.f6383a.add(d6);
        }
        Looper.getMainLooper().setMessageLogging(f6379b);
    }

    private static Printer d() {
        try {
            Field declaredField = Class.forName("android.os.Looper").getDeclaredField("mLogging");
            declaredField.setAccessible(true);
            return (Printer) declaredField.get(Looper.getMainLooper());
        } catch (Exception unused) {
            return null;
        }
    }

    public static void a(Printer printer) {
        if (printer == null || f6379b.f6385c.contains(printer)) {
            return;
        }
        f6379b.f6385c.add(printer);
        f6379b.f6387e = true;
    }
}