导航菜单

页面标题

页面副标题

Baubap v3.9.7 - WebContentUtils.java 源代码

正在查看: Baubap v3.9.7 应用的 WebContentUtils.java JAVA 源代码文件

本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。


package com.braze.support;

import android.content.Context;
import b2.o;
import com.braze.Constants;
import com.braze.support.BrazeLogger;
import h40.q;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.Locale;
import java.util.Map;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import kotlin.jvm.internal.x;

public final class WebContentUtils {
    public static final String ASSET_LOADER_DUMMY_DOMAIN = "iamcache.braze";
    public static final String HTML_INAPP_MESSAGES_FOLDER = "braze-html-inapp-messages";
    public static final WebContentUtils INSTANCE = new WebContentUtils();
    private static final String ZIP_EXTENSION = ".zip";

    public static final class a extends kotlin.jvm.internal.l implements y30.a {
        public static final a b = new a();

        public a() {
            super(0);
        }

        public final String invoke() {
            return "Remote zip url is empty. No local URL will be created.";
        }
    }

    public static final class b extends kotlin.jvm.internal.l implements y30.a {
        final String b;
        final String c;

        public b(String str, String str2) {
            super(0);
            this.b = str;
            this.c = str2;
        }

        public final String invoke() {
            return "Starting download of url: " + this.b + " to " + this.c;
        }
    }

    public static final class c extends kotlin.jvm.internal.l implements y30.a {
        final String b;

        public c(String str) {
            super(0);
            this.b = str;
        }

        public final String invoke() {
            return "Could not download zip file to local storage. " + this.b;
        }
    }

    public static final class d extends kotlin.jvm.internal.l implements y30.a {
        final String b;
        final String c;

        public d(String str, String str2) {
            super(0);
            this.b = str;
            this.c = str2;
        }

        public final String invoke() {
            return "Html content zip downloaded. " + this.b + " to " + this.c;
        }
    }

    public static final class e extends kotlin.jvm.internal.l implements y30.a {
        public static final e b = new e();

        public e() {
            super(0);
        }

        public final String invoke() {
            return "Error during the zip unpack.";
        }
    }

    public static final class f extends kotlin.jvm.internal.l implements y30.a {
        final String b;

        public f(String str) {
            super(0);
            this.b = str;
        }

        public final String invoke() {
            return o.r(new StringBuilder("Html content zip unpacked to to "), this.b, '.');
        }
    }

    public static final class g extends kotlin.jvm.internal.l implements y30.a {
        final String b;

        public g(String str) {
            super(0);
            this.b = str;
        }

        public final String invoke() {
            return "Cannot find local asset file at path: " + this.b;
        }
    }

    public static final class h extends kotlin.jvm.internal.l implements y30.a {
        final String b;
        final String c;

        public h(String str, String str2) {
            super(0);
            this.b = str;
            this.c = str2;
        }

        public final String invoke() {
            StringBuilder sb = new StringBuilder("Replacing remote url \"");
            sb.append(this.b);
            sb.append("\" with local uri \"");
            return o.r(sb, this.c, '\"');
        }
    }

    public static final class i extends kotlin.jvm.internal.l implements y30.a {
        public static final i b = new i();

        public i() {
            super(0);
        }

        public final String invoke() {
            return "Unpack directory is blank. Zip file not unpacked.";
        }
    }

    public static final class j extends kotlin.jvm.internal.l implements y30.a {
        final x b;

        public j(x xVar) {
            super(0);
            this.b = xVar;
        }

        public final String invoke() {
            return "Error creating parent directory " + ((String) this.b.b);
        }
    }

    public static final class k extends kotlin.jvm.internal.l implements y30.a {
        final x b;

        public k(x xVar) {
            super(0);
            this.b = xVar;
        }

        public final String invoke() {
            return "Error unpacking zipEntry " + ((String) this.b.b);
        }
    }

    public static final class l extends kotlin.jvm.internal.l implements y30.a {
        final File b;
        final String c;

        public l(File file, String str) {
            super(0);
            this.b = file;
            this.c = str;
        }

        public final String invoke() {
            StringBuilder sb = new StringBuilder("Error during unpack of zip file ");
            sb.append(this.b.getAbsolutePath());
            sb.append(" to ");
            return o.r(sb, this.c, '.');
        }
    }

    private WebContentUtils() {
    }

    public static final File getHtmlInAppMessageAssetCacheDirectory(Context context) {
        xu.b.y(context, "context");
        return new File(context.getCacheDir().getPath() + "/braze-html-inapp-messages");
    }

    public static final String getLocalHtmlUrlFromRemoteUrl(File file, String str) {
        xu.b.y(file, "localDirectory");
        xu.b.y(str, "remoteZipUrl");
        if (q.R(str)) {
            BrazeLogger.brazelog$default(BrazeLogger.INSTANCE, INSTANCE, BrazeLogger.Priority.W, (Throwable) null, a.b, 2, (Object) null);
            return null;
        }
        String absolutePath = file.getAbsolutePath();
        String valueOf = String.valueOf(IntentUtils.getRequestCode());
        String str2 = absolutePath + '/' + valueOf;
        BrazeLogger brazeLogger = BrazeLogger.INSTANCE;
        WebContentUtils webContentUtils = INSTANCE;
        BrazeLogger.brazelog$default(brazeLogger, webContentUtils, (BrazeLogger.Priority) null, (Throwable) null, new b(str, str2), 3, (Object) null);
        try {
            File file2 = (File) BrazeFileUtils.downloadFileToPath(str2, str, valueOf, ZIP_EXTENSION).b;
            BrazeLogger.brazelog$default(brazeLogger, webContentUtils, (BrazeLogger.Priority) null, (Throwable) null, new d(str, str2), 3, (Object) null);
            if (unpackZipIntoDirectory(str2, file2)) {
                BrazeLogger.brazelog$default(brazeLogger, webContentUtils, (BrazeLogger.Priority) null, (Throwable) null, new f(str2), 3, (Object) null);
                return str2;
            }
            BrazeLogger.brazelog$default(brazeLogger, webContentUtils, BrazeLogger.Priority.W, (Throwable) null, e.b, 2, (Object) null);
            BrazeFileUtils.deleteFileOrDirectory(new File(str2));
            return null;
        } catch (Exception e2) {
            BrazeLogger.INSTANCE.brazelog(INSTANCE, BrazeLogger.Priority.E, e2, new c(str));
            BrazeFileUtils.deleteFileOrDirectory(new File(str2));
            return null;
        }
    }

    public static final String replacePrefetchedUrlsWithLocalAssets(String str, Map<String, String> map) {
        xu.b.y(str, "originalString");
        xu.b.y(map, "remoteToLocalAssetMap");
        for (Map.Entry<String, String> entry : map.entrySet()) {
            String value = entry.getValue();
            if (new File(value).exists()) {
                String key = entry.getKey();
                if (q.E(value, Constants.TRIGGERS_ASSETS_FOLDER, false)) {
                    String p = o.p("https://iamcache.braze/ab_triggers", (String) q.j0(value, new String[]{Constants.TRIGGERS_ASSETS_FOLDER}, 0, 6).get(1));
                    if (q.E(str, key, false)) {
                        BrazeLogger.brazelog$default(BrazeLogger.INSTANCE, INSTANCE, (BrazeLogger.Priority) null, (Throwable) null, new h(key, p), 3, (Object) null);
                        str = q.f0(str, key, p);
                    }
                }
            } else {
                BrazeLogger.brazelog$default(BrazeLogger.INSTANCE, INSTANCE, BrazeLogger.Priority.W, (Throwable) null, new g(value), 2, (Object) null);
            }
        }
        return str;
    }

    public static final boolean unpackZipIntoDirectory(String str, File file) {
        xu.b.y(str, "unpackDirectory");
        xu.b.y(file, "zipFile");
        if (q.R(str)) {
            BrazeLogger.brazelog$default(BrazeLogger.INSTANCE, INSTANCE, BrazeLogger.Priority.I, (Throwable) null, i.b, 2, (Object) null);
            return false;
        }
        new File(str).mkdirs();
        try {
            x xVar = new x();
            ZipInputStream zipInputStream = new ZipInputStream(new FileInputStream(file));
            try {
                for (ZipEntry nextEntry = zipInputStream.getNextEntry(); nextEntry != null; nextEntry = zipInputStream.getNextEntry()) {
                    String name = nextEntry.getName();
                    xu.b.x(name, "zipEntry.name");
                    xVar.b = name;
                    Locale locale = Locale.US;
                    xu.b.x(locale, "US");
                    String lowerCase = name.toLowerCase(locale);
                    xu.b.x(lowerCase, "this as java.lang.String).toLowerCase(locale)");
                    if (!q.l0(lowerCase, "__macosx", false)) {
                        try {
                            String validateChildFileExistsUnderParent = validateChildFileExistsUnderParent(str, str + '/' + ((String) xVar.b));
                            if (nextEntry.isDirectory()) {
                                new File(validateChildFileExistsUnderParent).mkdirs();
                            } else {
                                try {
                                    File parentFile = new File(validateChildFileExistsUnderParent).getParentFile();
                                    if (parentFile != null) {
                                        parentFile.mkdirs();
                                    }
                                } catch (Exception e2) {
                                    BrazeLogger.INSTANCE.brazelog(INSTANCE, BrazeLogger.Priority.E, e2, new j(xVar));
                                }
                                BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(new FileOutputStream(validateChildFileExistsUnderParent));
                                try {
                                    ea.f.R(zipInputStream, bufferedOutputStream);
                                    yu.d.c(bufferedOutputStream, null);
                                } catch (Throwable th) {
                                    try {
                                        throw th;
                                    } catch (Throwable th2) {
                                        yu.d.c(bufferedOutputStream, th);
                                        throw th2;
                                    }
                                }
                            }
                        } catch (Exception e3) {
                            BrazeLogger.INSTANCE.brazelog(INSTANCE, BrazeLogger.Priority.E, e3, new k(xVar));
                        }
                    }
                    zipInputStream.closeEntry();
                }
                yu.d.c(zipInputStream, null);
                return true;
            } finally {
            }
        } catch (Throwable th3) {
            BrazeLogger.INSTANCE.brazelog(INSTANCE, BrazeLogger.Priority.E, th3, new l(file, str));
            return false;
        }
    }

    public static final String validateChildFileExistsUnderParent(String str, String str2) {
        xu.b.y(str, "intendedParentDirectory");
        xu.b.y(str2, "childFilePath");
        String canonicalPath = new File(str).getCanonicalPath();
        String canonicalPath2 = new File(str2).getCanonicalPath();
        xu.b.x(canonicalPath2, "childFileCanonicalPath");
        xu.b.x(canonicalPath, "parentCanonicalPath");
        if (q.l0(canonicalPath2, canonicalPath, false)) {
            return canonicalPath2;
        }
        StringBuilder E = d10.a.E("Invalid file with original path: ", str2, " with canonical path: ", canonicalPath2, " does not exist under intended parent with  path: ");
        E.append(str);
        E.append(" and canonical path: ");
        E.append(canonicalPath);
        throw new IllegalStateException(E.toString());
    }
}