Swiggy v4.51.1版本的 MD5 值为:5af7ec91512a0a8c1510e3f8bac20b8b

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


package in.swiggy.android.web.utility;

import android.content.Context;
import android.content.SharedPreferences;
import android.os.StatFs;
import com.newrelic.agent.android.NewRelic;
import com.newrelic.agent.android.instrumentation.Instrumented;
import com.newrelic.agent.android.instrumentation.JSONArrayInstrumentation;
import com.newrelic.agent.android.instrumentation.JSONObjectInstrumentation;
import in.swiggy.android.commons.extension.KotlinExtensionsKt;
import in.swiggy.android.commons.utils.x;
import in.swiggy.android.web.FileDownloadManager;
import in.swiggy.android.web.tejas.resources.WebResourceManager;
import java.io.File;
import java.io.FileWriter;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import kotlin.collections.j0;
import kotlin.collections.r;
import kotlin.jvm.internal.DefaultConstructorMarker;
import kotlin.text.q;
import okio.BufferedSource;
import okio.h0;
import okio.i0;
import okio.t0;
import org.apache.pdfbox.pdmodel.documentinterchange.taggedpdf.PDLayoutAttributeObject;
import org.json.JSONArray;
import org.json.JSONObject;
@Instrumented
public final class j {
    public static final a g = new a(null);
    private final Context a;
    private final WebResourceManager b;
    private final FileDownloadManager c;
    private final m d;
    private final SharedPreferences e;
    private final in.swiggy.android.analytics.newrelic.a f;

    public static final class a {
        public a(DefaultConstructorMarker defaultConstructorMarker) {
            this();
        }

        private a() {
        }
    }

    public j(Context context, WebResourceManager webResourceManager, FileDownloadManager fileDownloadManager, m webResourceMappingUtility, SharedPreferences sharedPreferences, in.swiggy.android.analytics.newrelic.a newRelicUtils) {
        kotlin.jvm.internal.o.k(context, "context");
        kotlin.jvm.internal.o.k(webResourceManager, "webResourceManager");
        kotlin.jvm.internal.o.k(fileDownloadManager, "fileDownloadManager");
        kotlin.jvm.internal.o.k(webResourceMappingUtility, "webResourceMappingUtility");
        kotlin.jvm.internal.o.k(sharedPreferences, "sharedPreferences");
        kotlin.jvm.internal.o.k(newRelicUtils, "newRelicUtils");
        this.a = context;
        this.b = webResourceManager;
        this.c = fileDownloadManager;
        this.d = webResourceMappingUtility;
        this.e = sharedPreferences;
        this.f = newRelicUtils;
    }

    private final void a(in.swiggy.android.web.tejas.resources.l lVar) {
        if (this.d.x()) {
            try {
                String h = this.d.h();
                if (h != null) {
                    File file = new File(h + "/assetUrlTemp");
                    if (file.exists()) {
                        file.delete();
                    }
                    String i = this.d.i();
                    if (i != null) {
                        File file2 = new File(i);
                        JSONArray jSONArray = new JSONArray();
                        for (in.swiggy.android.web.tejas.resources.c cVar : lVar.a()) {
                            jSONArray.put(cVar.a());
                        }
                        FileWriter fileWriter = new FileWriter(file);
                        fileWriter.write(JSONArrayInstrumentation.toString(jSONArray));
                        fileWriter.flush();
                        fileWriter.close();
                        file.renameTo(file2);
                    }
                }
            } catch (Throwable th) {
                x.i("WebResourceDownloadUtility", th);
            }
        }
    }

    private final void b(List<in.swiggy.android.web.tejas.resources.b> list) {
        try {
            String h = this.d.h();
            if (h != null) {
                File file = new File(h + "/mappingTemp");
                if (file.exists()) {
                    file.delete();
                }
                String r = this.d.r();
                if (r != null) {
                    File file2 = new File(r);
                    JSONObject jSONObject = new JSONObject();
                    for (in.swiggy.android.web.tejas.resources.b bVar : list) {
                        String b = bVar.b();
                        if (b != null) {
                            jSONObject.put(b, KotlinExtensionsKt.c(bVar));
                        }
                    }
                    FileWriter fileWriter = new FileWriter(file);
                    fileWriter.write(JSONObjectInstrumentation.toString(jSONObject));
                    fileWriter.flush();
                    fileWriter.close();
                    file.renameTo(file2);
                }
            }
        } catch (Throwable th) {
            x.i("WebResourceDownloadUtility", th);
        }
    }

    private final in.swiggy.android.web.tejas.resources.k c(String str) {
        String str2;
        String str3;
        int i;
        long j;
        String str4;
        SharedPreferences sharedPreferences = this.e;
        String string = sharedPreferences.getString("android_assets_links_url_v2", "https://asset-caching.swiggy.com/asset-aggregator/main_v2.json");
        if (string == null) {
            str2 = "";
        } else {
            str2 = string;
        }
        String string2 = sharedPreferences.getString("web_assets_version", "");
        if (string2 == null) {
            str3 = "";
        } else {
            str3 = string2;
        }
        try {
            String string3 = sharedPreferences.getString("android_web_resource_download_retry", PDLayoutAttributeObject.GLYPH_ORIENTATION_VERTICAL_ZERO_DEGREES);
            if (string3 == null) {
                string3 = "";
            }
            i = Integer.parseInt(string3);
        } catch (Exception e) {
            x.i("WebResourceDownloadUtility", e);
            i = 0;
        }
        int i2 = i;
        try {
            String string4 = sharedPreferences.getString("android_web_resource_download_delay_in_seconds", PDLayoutAttributeObject.GLYPH_ORIENTATION_VERTICAL_ZERO_DEGREES);
            if (string4 == null) {
                string4 = "";
            }
            j = Long.parseLong(string4);
        } catch (Exception e2) {
            x.i("WebResourceDownloadUtility", e2);
            j = 0;
        }
        long j2 = j;
        String packageName = this.a.getPackageName();
        if (packageName == null) {
            str4 = "";
        } else {
            str4 = packageName;
        }
        return new in.swiggy.android.web.tejas.resources.k(str2, str4, str3, str, i2, j2);
    }

    public static void e(j jVar, String str, int i, Object obj) {
        if ((i & 1) != 0) {
            str = null;
        }
        jVar.d(str);
    }

    private final void f(in.swiggy.android.web.tejas.resources.k kVar) {
        HashMap k;
        if (kVar.g() > 0) {
            k = j0.k(kotlin.o.a("retry_count", Integer.valueOf(kVar.g())), kotlin.o.a("is_count_exhausted", Boolean.valueOf(kVar.c())));
            NewRelic.recordCustomEvent("swiggy_generic_event", "web_asset_download_retry", k);
        }
    }

    private final void g(in.swiggy.android.web.tejas.resources.l lVar) {
        List<in.swiggy.android.web.tejas.resources.c> n;
        List<String> o = this.d.o();
        if (o != null) {
            for (String str : o) {
                m mVar = this.d;
                if (lVar == null || (n = lVar.a()) == null) {
                    n = r.n();
                }
                if (!mVar.z(str, n)) {
                    this.d.d(str);
                }
            }
        }
    }

    private final void h() {
        HashMap hashMap = new HashMap();
        hashMap.put("asset_aggregator_cache_size_in_bytes", Float.valueOf(this.d.k()));
        NewRelic.recordCustomEvent("swiggy_generic_event", "asset_aggregator_success", hashMap);
    }

    public final void d(String str) {
        File file;
        File file2;
        t0 h;
        Map<String, ? extends Object> m;
        String c;
        boolean z;
        if (this.a.getFilesDir() != null) {
            if (this.e.getInt("android_available_disk_space_threshold", 2097152) < new StatFs(this.a.getFilesDir().getPath()).getAvailableBytes()) {
                in.swiggy.android.web.tejas.resources.k c2 = c(str);
                in.swiggy.android.web.tejas.resources.l f = this.b.f(c2);
                f(c2);
                if (!kotlin.jvm.internal.o.f(f.c(), c2.d())) {
                    String j = this.d.j();
                    g(f);
                    boolean z2 = false;
                    if (!f.a().isEmpty()) {
                        if (j != null) {
                            c.a.a(j);
                        }
                        boolean z3 = false;
                        for (in.swiggy.android.web.tejas.resources.c cVar : f.a()) {
                            String m2 = this.d.m(cVar.a());
                            if (m2 != null && (!this.d.g(m2) || (this.d.g(m2) && !this.d.t(m2, cVar.b())))) {
                                try {
                                    file = new File(j + "/temp");
                                    if (file.exists()) {
                                        file.delete();
                                    }
                                    file2 = new File(j + "/" + m2);
                                    BufferedSource c3 = this.c.c(cVar.a()).c();
                                    h = i0.h(file, false, 1, null);
                                    okio.d c4 = h0.c(h);
                                    if (c3 != null) {
                                        c4.K0(c3);
                                        kotlin.io.b.a(c3, null);
                                    }
                                    c4.close();
                                    m = j0.m(kotlin.o.a("url", cVar.a()));
                                    m mVar = this.d;
                                    String path = file.getPath();
                                    kotlin.jvm.internal.o.j(path, "getPath(...)");
                                    c = mVar.c(path);
                                    z = q.z(c, cVar.b(), true);
                                } catch (Throwable th) {
                                    x.i("WebResourceDownloadUtility", th);
                                }
                                if (z) {
                                    file.renameTo(file2);
                                    this.f.b("file_download_successful", m);
                                } else {
                                    m.put("client_checksum", c);
                                    m.put("server_checksum", cVar.b());
                                    this.f.b("file_checksum_mismatched", m);
                                    z3 = true;
                                }
                            }
                        }
                        z2 = z3;
                    }
                    if (!f.b().isEmpty()) {
                        b(f.b());
                    }
                    a(f);
                    if (!z2) {
                        h();
                        this.e.edit().putString("web_assets_version", f.c()).apply();
                        return;
                    }
                    return;
                }
                return;
            }
            NewRelic.recordCustomEvent("swiggy_generic_event", "insufficient_storage", null);
            return;
        }
        NewRelic.recordCustomEvent("swiggy_generic_event", "invalid_storage", null);
    }
}