package com.ss.android.ugc.aweme.services;

import X.0HH;
import X.2HN;
import X.AnonymousClass8BD;
import X.C403195y;
import X.C51029ef;
import X.M12;
import android.net.Uri;
import android.os.Handler;
import android.os.Looper;
import android.text.TextUtils;
import com.bytedance.covode.number.Covode;
import com.ss.android.agilelogger.ALog;
import java.util.List;
import org.json.JSONObject;

public abstract class AbsApiMonitorService {
    public static final Companion Companion = new Companion((2HN) null);
    public final Handler handler = new Handler(Looper.getMainLooper());

    static {
        Covode.recordClassIndex(105000);
    }

    public static final class Companion {
        static {
            Covode.recordClassIndex(105001);
        }

        public Companion() {
        }

        public /* synthetic */ Companion(2HN r1) {
            this();
        }
    }

    public final void addALog(String str, C51029ef<?> r6) {
        M12.LIZ(str, r6);
        try {
            List<AnonymousClass8BD> list = r6.LIZ.LIZLLL;
            M12.LIZ(str);
            Uri parse = Uri.parse(str);
            if (TextUtils.isEmpty(parse.getQueryParameter("device_id"))) {
                return;
            }
            if (!TextUtils.isEmpty(parse.getQueryParameter("aid"))) {
                if (list != null) {
                    ALog.d("API_URL_HEADER", "URL: " + str + "\r\nHEADER" + list.toString());
                }
            }
        } catch (NoSuchMethodError e) {
            e.printStackTrace();
        }
    }

    public final void apiMonitor(String str, String str2, String str3) {
        M12.LIZ(str, str3);
        Uri parse = Uri.parse(str);
        if (parse != null) {
            try {
                JSONObject jSONObject = new JSONObject();
                jSONObject.put("url", str);
                jSONObject.put("path", parse.getPath());
                jSONObject.put("host", parse.getHost());
                jSONObject.put("body", str3);
                jSONObject.put("requestid", str2);
                jSONObject.put("debug", false);
                C403195y.LIZIZ("api_error_service_log", "", jSONObject);
            } catch (Exception e) {
                0HH.LIZ(e);
            }
        }
    }
}
