Snaptube v4.40.0.4401610版本的 MD5 值为:ca2b95dcff63007195db02a6c93091b9

以下内容为反编译后的 AvocarrotLogger.java 源代码,内容仅作参考


package com.avocarrot.androidsdk.logging;

import android.os.Handler;
import android.os.Looper;
import android.text.TextUtils;
import android.util.Log;
import com.avocarrot.androidsdk.Avocarrot;
import com.avocarrot.androidsdk.DeviceInfo;
import com.avocarrot.androidsdk.DynamicConfiguration;
import com.mobi.sdk.Cboolean;
import com.mobvista.msdk.base.common.CommonConst;
import io.fabric.sdk.android.services.common.CommonUtils;
import io.fabric.sdk.android.services.settings.SettingsJsonConstants;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import net.pubnative.library.request.PubnativeRequest;
import org.json.JSONException;
import org.json.JSONObject;
public class AvocarrotLogger {
    static Integer timeout;
    private static String SERVER_LOGGER = "https://sdklogs.avocarrot.com";
    private static final Handler handler = new Handler(Looper.getMainLooper());
    static ExecutorService executorService = Executors.newSingleThreadExecutor();
    protected static boolean isLocalLoggerEnabled = false;
    protected static Levels userLevel = null;
    protected static JSONObject extraInfo = new JSONObject();
    static List<String> pendingEvents = new ArrayList();
    static Runnable batchEvents = new Runnable() {
        @Override
        public void run() {
            AvocarrotLogger.executorService.submit(AvocarrotLogger.sendEvents);
        }
    };
    static Runnable sendEvents = new Runnable() {
        @Override
        public void run() {
            if (AvocarrotLogger.pendingEvents.size() > 0) {
                AvocarrotLogger.pendingEvents.clear();
                AvocarrotLogger.sendEventToServer(AvocarrotLogger.SERVER_LOGGER, "[" + TextUtils.join(",", AvocarrotLogger.pendingEvents) + "]");
                AvocarrotLogger.handler.postDelayed(AvocarrotLogger.batchEvents, AvocarrotLogger.timeout.intValue());
            }
        }
    };

    public static void addExtraInfo(String str, String str2) {
        try {
            extraInfo.put(str, str2);
        } catch (JSONException e) {
        }
    }

    public static void addAdInfo(String str) {
        addExtraInfo("adId", str);
    }

    public static void addPlacementInfo(String str) {
        addExtraInfo("placement", str);
    }

    public static void disable() {
        isLocalLoggerEnabled = false;
    }

    public static void enableWithLevel(String str) {
        if (str.equals("ERROR") || str.equals("WARN") || str.equals("INFO") || str.equals("DEBUG")) {
            userLevel = Levels.valueOf(str);
        } else {
            userLevel = Levels.valueOf("ALL");
        }
        isLocalLoggerEnabled = true;
    }

    public static void AvocarrotLog(Levels levels, String str) {
        AvocarrotLog(levels, str, null, new String[0]);
    }

    public static void AvocarrotLog(Levels levels, String str, Throwable th, String... strArr) {
        AvocarrotLog(false, levels, str, th, strArr);
    }

    public static void AvocarrotLog(boolean z, Levels levels, String str, Throwable th, String... strArr) {
        if (!TextUtils.isEmpty(str)) {
            if (timeout == null) {
                timeout = DynamicConfiguration.getIntFallbackToDefault(DynamicConfiguration.GENERAL, DynamicConfiguration.Settings.loggerBatchTimeout);
                if (timeout == null) {
                    timeout = 1000;
                }
            }
            AvocarrotLogger avocarrotLogger = new AvocarrotLogger();
            if (!z) {
                avocarrotLogger.logToLogCat(levels, str, th);
            }
            avocarrotLogger.logToServer(levels, str, th, strArr);
        }
    }

    void logToLogCat(Levels levels, String str, Throwable th) {
        if (isLocalLoggerEnabled && levels.compareTo(userLevel) >= 0) {
            if (th != null) {
                str = str + ": " + th.toString();
            }
            switch (levels) {
                case ERROR:
                    Log.e("Avocarrot", "[ERROR]: " + str);
                    return;
                case WARN:
                    Log.w("Avocarrot", "[WARN]:  " + str);
                    return;
                case INFO:
                    Log.i("Avocarrot", "[INFO]:  " + str);
                    return;
                case DEBUG:
                    return;
                default:
                    Log.d("Avocarrot", "[ALL]:   " + str);
                    return;
            }
        }
    }

    void logToServer(Levels levels, String str, Throwable th, String... strArr) {
        Levels levels2;
        try {
            String string = DynamicConfiguration.getString(DynamicConfiguration.GENERAL, DynamicConfiguration.Settings.logger);
            if (TextUtils.isEmpty(string)) {
                string = DynamicConfiguration.getDefaultString(DynamicConfiguration.Settings.logger);
            }
            try {
                levels2 = Levels.valueOf(string.toUpperCase());
            } catch (Exception e) {
                levels2 = null;
            }
            if (levels2 != null && levels.compareTo(levels2) >= 0) {
                HashMap hashMap = new HashMap();
                hashMap.put("level", levels.toString());
                hashMap.put(SettingsJsonConstants.PROMPT_MESSAGE_KEY, str);
                hashMap.put("stacktrace", Log.getStackTraceString(th));
                hashMap.put("timestamp", Long.toString(System.currentTimeMillis()));
                Iterator<String> keys = extraInfo.keys();
                while (keys.hasNext()) {
                    String next = keys.next();
                    hashMap.put(next, extraInfo.optString(next));
                }
                Avocarrot avocarrot = Avocarrot.getInstance();
                if (avocarrot != null) {
                    hashMap.put("apiKey", avocarrot.getApiKey());
                    hashMap.put("sandbox", avocarrot.isInSandbox() ? "TRUE" : "FALSE");
                    hashMap.put(CommonUtils.SDK, Avocarrot.getSDKVersion());
                    DeviceInfo deviceInfo = avocarrot.getDeviceInfo();
                    if (deviceInfo != null) {
                        hashMap.put("buildVersion", deviceInfo.getDeviceManufacturer());
                        hashMap.put("deviceModel", deviceInfo.getDeviceModel());
                        hashMap.put(CommonConst.KEY_REPORT_PLATFORM, deviceInfo.getPlatform());
                        hashMap.put(PubnativeRequest.Parameters.OS, deviceInfo.getOSVersion());
                        hashMap.put("package", deviceInfo.getPackageName());
                        hashMap.put("appName", deviceInfo.getAppName());
                        hashMap.put("appVersion", deviceInfo.getVersionName());
                        hashMap.put(Cboolean.f8789while, deviceInfo.getUUID());
                        hashMap.put("carrier", deviceInfo.getCarrier());
                        hashMap.put(CommonConst.KEY_REPORT_LANGUAGE, deviceInfo.getLanguage());
                        hashMap.put("mcc", deviceInfo.getMCC());
                        hashMap.put("mnc", deviceInfo.getMNC());
                        hashMap.put("connectionType", deviceInfo.getOpenRTBConnectionType());
                        hashMap.put(CommonConst.KEY_REPORT_ORIENTATION, deviceInfo.getOrientation());
                        hashMap.put("simCountryIso", deviceInfo.getSimCountryIso());
                    }
                }
                if (strArr != null) {
                    int length = strArr.length;
                    for (int i = 0; i < length; i += 2) {
                        if (i + 1 < length) {
                            hashMap.put(strArr[i], strArr[i + 1]);
                        } else {
                            hashMap.put("extra", strArr[i]);
                        }
                    }
                }
                sendEventToServer(new JSONObject(hashMap));
            }
        } catch (Exception e2) {
            logToLogCat(Levels.INFO, "Could not propagate event to remote endpoint", e2);
        }
    }

    void sendEventToServer(JSONObject jSONObject) {
        pendingEvents.add(jSONObject.toString());
        handler.removeCallbacks(batchEvents);
        handler.postDelayed(batchEvents, timeout.intValue());
    }

    static void sendEventToServer(String str, String str2) {
        try {
            HttpURLConnection httpURLConnection = (HttpURLConnection) new URL(str).openConnection();
            try {
                Integer num = DynamicConfiguration.getInt(DynamicConfiguration.GENERAL, DynamicConfiguration.Settings.loggerReqTimeout);
                if (num != null) {
                    httpURLConnection.setConnectTimeout(num.intValue());
                    httpURLConnection.setReadTimeout(num.intValue());
                }
                httpURLConnection.setRequestProperty("Content-Type", "application/json");
                httpURLConnection.setDoOutput(true);
                httpURLConnection.setRequestMethod("POST");
                OutputStreamWriter outputStreamWriter = new OutputStreamWriter(httpURLConnection.getOutputStream());
                outputStreamWriter.write(str2);
                outputStreamWriter.flush();
                outputStreamWriter.close();
                httpURLConnection.getResponseCode();
                httpURLConnection.disconnect();
            } catch (Exception e) {
                httpURLConnection.disconnect();
            } catch (Throwable th) {
                httpURLConnection.disconnect();
                throw th;
            }
        } catch (Exception e2) {
        }
    }

    public enum Levels {
        DEBUG("DEBUG"),
        ALL("ALL"),
        INFO("INFO"),
        WARN("WARN"),
        ERROR("ERROR");
        
        private String text;

        Levels(String str) {
            this.text = str;
        }
    }
}