package ai.advance.core;

import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.text.TextUtils;
import androidx.core.app.JobIntentService;
import com.facebook.GraphRequest;
import java.io.File;
import java.util.Locale;
import org.json.JSONArray;
import org.json.JSONObject;
import K.K.K.ʬ.C2367;
import K.K.K.ʬ.C2369;
import K.K.K.ῲ.C2372;

public abstract class LServiceParent extends JobIntentService {

    /* renamed from: 㳳  reason: contains not printable characters */
    public static boolean f37 = true;

    @Override // androidx.core.app.JobIntentService
    public void onDestroy() {
        m31();
        super.onDestroy();
    }

    /* renamed from: ඓ  reason: contains not printable characters */
    public abstract void m31();

    /* renamed from: ᨨ  reason: contains not printable characters */
    public void m32() {
    }

    /* renamed from: ῲ  reason: contains not printable characters */
    public final void m33(Intent intent) {
        String stringExtra = intent.getStringExtra("eventInfo");
        if (C2367.m6265(stringExtra)) {
            JSONArray r0 = m40();
            JSONObject jSONObject = new JSONObject();
            try {
                jSONObject.putOpt("log", new JSONObject(stringExtra));
            } catch (Exception unused) {
            }
            if (r0 != null && r0.length() > 0) {
                try {
                    jSONObject.putOpt("pictures", r0);
                } catch (Exception unused2) {
                }
            }
            m41();
            C2369.m6327(this, System.currentTimeMillis() + m34(), jSONObject.toString());
        }
    }

    /* renamed from: ⁱ  reason: contains not printable characters */
    public abstract String m34();

    /* renamed from: K  reason: contains not printable characters */
    public abstract String m35(String str, String str2);

    /* renamed from: K  reason: contains not printable characters */
    public abstract String m36(String str, String str2, String str3, String str4, long j, long j2);

    @Override // androidx.core.app.JobIntentService
    /* renamed from: K  reason: contains not printable characters */
    public void m37(Intent intent) {
        try {
            m33(intent);
            File[] listFiles = getFilesDir().listFiles();
            for (File file : listFiles) {
                if (file != null && file.exists()) {
                    String name = file.getName();
                    if (name.endsWith(m34())) {
                        m38(name);
                    }
                }
            }
        } catch (Exception unused) {
        }
    }

    /* renamed from: K  reason: contains not printable characters */
    public void m38(String str) {
        String r4 = C2369.m6354(this, str);
        if (C2367.m6265(r4)) {
            try {
                JSONObject jSONObject = new JSONObject(r4);
                m32();
                JSONObject optJSONObject = jSONObject.optJSONObject("log");
                if (jSONObject.has("pictures") && f37) {
                    JSONArray optJSONArray = jSONObject.optJSONArray("pictures");
                    String r7 = m35(optJSONArray.toString(), Locale.getDefault().toString());
                    if (TextUtils.isEmpty(r7)) {
                        r7 = m35(optJSONArray.toString(), Locale.getDefault().toString());
                    }
                    if (C2367.m6265(r7)) {
                        C2372 r6 = C2367.m6264(r7, C2372.class);
                        if (r6.f8209) {
                            String str2 = r6.f8215;
                            if (C2367.m6265(str2)) {
                                Object optString = new JSONObject(str2).optString("fileId");
                                JSONObject optJSONObject2 = optJSONObject.optJSONObject(GraphRequest.DEBUG_SEVERITY_INFO);
                                JSONObject optJSONObject3 = optJSONObject2.optJSONObject("detail");
                                optJSONObject3.putOpt("picture_file_id", optString);
                                optJSONObject2.putOpt("detail", optJSONObject3);
                                optJSONObject.putOpt(GraphRequest.DEBUG_SEVERITY_INFO, optJSONObject2);
                                jSONObject.putOpt("log", optJSONObject);
                            }
                        }
                    }
                    jSONObject.remove("pictures");
                    C2369.m6327(this, str, jSONObject.toString());
                }
                if (m39(optJSONObject)) {
                    getApplicationContext().deleteFile(str);
                }
            } catch (Exception unused) {
            }
        }
    }

    /* renamed from: 㴹  reason: contains not printable characters */
    public abstract JSONArray m40();

    /* renamed from: 㿎  reason: contains not printable characters */
    public void m41() {
    }

    /* renamed from: K  reason: contains not printable characters */
    public boolean m39(JSONObject jSONObject) {
        String optString = jSONObject.optString("bizType");
        String optString2 = jSONObject.optString(GraphRequest.DEBUG_SEVERITY_INFO);
        String optString3 = jSONObject.optString("eventType");
        long optLong = jSONObject.optLong("eventTimestamp", 0);
        long optLong2 = jSONObject.optLong("eventCostInMilliSeconds", 0);
        long j = optLong2 == 0 ? 1 : optLong2;
        String r0 = m36(Locale.getDefault().toString(), optString, optString2, optString3, optLong, j);
        if (TextUtils.isEmpty(r0)) {
            r0 = m36(Locale.getDefault().toString(), optString, optString2, optString3, optLong, j);
        }
        return C2367.m6264(r0, C2372.class).f8209;
    }

    /* renamed from: K  reason: contains not printable characters */
    public static void m30(Context context, Class cls, int i, String str) {
        try {
            Intent intent = new Intent(context, cls);
            intent.putExtra("eventInfo", str);
            if (Build.VERSION.SDK_INT >= 26) {
                JobIntentService.m581(context, new ComponentName(context, cls), i, intent);
            } else {
                context.startService(intent);
            }
        } catch (Exception unused) {
        }
    }
}
