package tg;

import ch.j;
import com.adobe.marketing.mobile.internal.util.i;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import wg.i0;
import wg.t;

/* loaded from: classes4.dex */
class d {
    private boolean a(String str) {
        return !j.a(str);
    }

    private File e(String str) {
        return new File(d(str).getPath() + File.separator + "rules.zip");
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public boolean b(String str) {
        if (!a(str)) {
            return false;
        }
        File d10 = d(str);
        if (d10.exists() || d10.mkdirs()) {
            return true;
        }
        t.a("MobileCore", "RulesZipProcessingHelper", "Cannot access application cache directory to create temp dir.", new Object[0]);
        return false;
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public void c(String str) {
        if (a(str)) {
            com.adobe.marketing.mobile.internal.util.c.b(d(str), true);
        }
    }

    File d(String str) {
        String c10 = i.c(str);
        StringBuilder sb2 = new StringBuilder();
        sb2.append(i0.f().e().c().getPath());
        String str2 = File.separator;
        sb2.append(str2);
        sb2.append("aepsdktmp");
        sb2.append(str2);
        sb2.append(c10);
        return new File(sb2.toString());
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public boolean f(String str, InputStream inputStream) {
        if (!a(str)) {
            return false;
        }
        if (com.adobe.marketing.mobile.internal.util.c.h(e(str), inputStream, false)) {
            return true;
        }
        t.a("MobileCore", "RulesZipProcessingHelper", "Cannot read response content into temp dir.", new Object[0]);
        return false;
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public String g(String str) {
        if (!a(str)) {
            return null;
        }
        File d10 = d(str);
        if (!com.adobe.marketing.mobile.internal.util.c.c(e(str), d10.getPath())) {
            t.a("MobileCore", "RulesZipProcessingHelper", "Failed to extract rules response zip into temp dir.", new Object[0]);
            return null;
        }
        File file = new File(d10.getPath() + File.separator + "rules.json");
        if (!file.exists()) {
            t.a("MobileCore", "RulesZipProcessingHelper", "Extract rules directory does not contain a rules.json file.", new Object[0]);
            return null;
        }
        try {
            FileInputStream fileInputStream = new FileInputStream(file);
            try {
                String a10 = ch.i.a(fileInputStream);
                if (a10 != null) {
                    fileInputStream.close();
                    return a10;
                }
                t.a("MobileCore", "RulesZipProcessingHelper", "Null content from rules.json file.", new Object[0]);
                fileInputStream.close();
                return null;
            } finally {
            }
        } catch (IOException unused) {
            t.a("MobileCore", "RulesZipProcessingHelper", "Exception while processing rules from source %s", str);
            return null;
        }
    }
}
