导航菜单

页面标题

页面副标题

Housing v14.7.8 - e.java 源代码

正在查看: Housing v14.7.8 应用的 e.java JAVA 源代码文件

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


package io.sentry.cache;

import io.sentry.UncaughtExceptionHandlerIntegration;
import io.sentry.a0;
import io.sentry.b4;
import io.sentry.c4;
import io.sentry.h4;
import io.sentry.hints.l;
import io.sentry.hints.n;
import io.sentry.k0;
import io.sentry.k3;
import io.sentry.n3;
import io.sentry.s4;
import io.sentry.t3;
import io.sentry.util.k;
import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.Map;
import java.util.UUID;
import java.util.WeakHashMap;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import org.jetbrains.annotations.ApiStatus$Internal;
import org.jetbrains.annotations.NotNull;

@ApiStatus$Internal
public class e extends b implements f {
    public static final String CRASH_MARKER_FILE = "last_crash";
    public static final String NATIVE_CRASH_MARKER_FILE = ".sentry-native/last_crash";
    public static final String PREFIX_CURRENT_SESSION_FILE = "session";
    public static final String PREFIX_PREVIOUS_SESSION_FILE = "previous_session";
    public static final String STARTUP_CRASH_MARKER_FILE = "startup_crash";
    public static final String SUFFIX_ENVELOPE_FILE = ".envelope";
    static final String SUFFIX_SESSION_FILE = ".json";

    @NotNull
    private final Map<n3, String> fileNameMap;
    private final CountDownLatch previousSessionLatch;

    public e(@NotNull h4 h4Var, @NotNull String str, int i) {
        super(h4Var, str, i);
        this.fileNameMap = new WeakHashMap();
        this.previousSessionLatch = new CountDownLatch(1);
    }

    public final File[] g() {
        if (this.directory.isDirectory() && this.directory.canWrite() && this.directory.canRead()) {
            File[] listFiles = this.directory.listFiles(new d());
            if (listFiles != null) {
                return listFiles;
            }
        } else {
            this.options.getLogger().c(c4.ERROR, "The directory for caching files is inaccessible.: %s", this.directory.getAbsolutePath());
        }
        return new File[0];
    }

    public final void h() {
        this.previousSessionLatch.countDown();
    }

    @Override
    public final Iterator<n3> iterator() {
        File[] g = g();
        ArrayList arrayList = new ArrayList(g.length);
        for (File file : g) {
            try {
                BufferedInputStream bufferedInputStream = new BufferedInputStream(new FileInputStream(file));
                try {
                    arrayList.add(this.serializer.a(bufferedInputStream));
                    bufferedInputStream.close();
                } catch (Throwable th) {
                    try {
                        bufferedInputStream.close();
                    } catch (Throwable th2) {
                        th.addSuppressed(th2);
                    }
                    throw th;
                }
            } catch (FileNotFoundException unused) {
                this.options.getLogger().c(c4.DEBUG, "Envelope file '%s' disappeared while converting all cached files to envelopes.", file.getAbsolutePath());
            } catch (IOException e) {
                this.options.getLogger().b(c4.ERROR, "Error while reading cached envelope from file " + file.getAbsolutePath(), e);
            }
        }
        return arrayList.iterator();
    }

    public final synchronized File k(n3 n3Var) {
        String str;
        try {
            if (this.fileNameMap.containsKey(n3Var)) {
                str = this.fileNameMap.get(n3Var);
            } else {
                String str2 = UUID.randomUUID() + SUFFIX_ENVELOPE_FILE;
                this.fileNameMap.put(n3Var, str2);
                str = str2;
            }
        } catch (Throwable th) {
            throw th;
        }
        return new File(this.directory.getAbsolutePath(), str);
    }

    public final boolean l() {
        try {
            return this.previousSessionLatch.await(this.options.getSessionFlushTimeoutMillis(), TimeUnit.MILLISECONDS);
        } catch (InterruptedException unused) {
            Thread.currentThread().interrupt();
            this.options.getLogger().c(c4.DEBUG, "Timed out waiting for previous session to flush.", new Object[0]);
            return false;
        }
    }

    @Override
    public final void m(n3 n3Var) {
        k.b(n3Var, "Envelope is required.");
        File k = k(n3Var);
        if (!k.exists()) {
            this.options.getLogger().c(c4.DEBUG, "Envelope was not cached: %s", k.getAbsolutePath());
            return;
        }
        this.options.getLogger().c(c4.DEBUG, "Discarding envelope from cache: %s", k.getAbsolutePath());
        if (k.delete()) {
            return;
        }
        this.options.getLogger().c(c4.ERROR, "Failed to delete envelope: %s", k.getAbsolutePath());
    }

    public final void n(File file, s4 s4Var) {
        if (file.exists()) {
            this.options.getLogger().c(c4.DEBUG, "Overwriting session to offline storage: %s", s4Var.g());
            if (!file.delete()) {
                this.options.getLogger().c(c4.ERROR, "Failed to delete: %s", file.getAbsolutePath());
            }
        }
        try {
            FileOutputStream fileOutputStream = new FileOutputStream(file);
            try {
                BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(fileOutputStream, b.UTF_8));
                try {
                    this.serializer.e(s4Var, bufferedWriter);
                    bufferedWriter.close();
                    fileOutputStream.close();
                } finally {
                }
            } finally {
            }
        } catch (Throwable th) {
            this.options.getLogger().a(c4.ERROR, th, "Error writing Session to offline storage: %s", s4Var.g());
        }
    }

    public void q0(n3 n3Var, a0 a0Var) {
        FileOutputStream fileOutputStream;
        BufferedReader bufferedReader;
        Date date;
        k.b(n3Var, "Envelope is required.");
        f(g());
        File file = new File(this.directory.getAbsolutePath(), "session.json");
        File file2 = new File(this.directory.getAbsolutePath(), "previous_session.json");
        if (io.sentry.util.d.b(a0Var, l.class) && !file.delete()) {
            this.options.getLogger().c(c4.WARNING, "Current envelope doesn't exist.", new Object[0]);
        }
        boolean z = true;
        if (io.sentry.hints.a.class.isInstance(a0Var.c())) {
            Object c = a0Var.c();
            if (c instanceof io.sentry.hints.a) {
                File file3 = new File(this.directory.getAbsolutePath(), "previous_session.json");
                if (file3.exists()) {
                    k0 logger = this.options.getLogger();
                    c4 c4Var = c4.WARNING;
                    logger.c(c4Var, "Previous session is not ended, we'd need to end it.", new Object[0]);
                    try {
                        bufferedReader = new BufferedReader(new InputStreamReader(new FileInputStream(file3), b.UTF_8));
                        try {
                            s4 s4Var = (s4) this.serializer.d(bufferedReader, s4.class);
                            if (s4Var != null) {
                                io.sentry.hints.a aVar = (io.sentry.hints.a) c;
                                Long d = aVar.d();
                                if (d != null) {
                                    date = io.sentry.j.b(d.longValue());
                                    Date h = s4Var.h();
                                    if (h != null) {
                                        if (date.before(h)) {
                                        }
                                    }
                                    this.options.getLogger().c(c4Var, "Abnormal exit happened before previous session start, not ending the session.", new Object[0]);
                                } else {
                                    date = null;
                                }
                                s4Var.m(s4.b.Abnormal, null, true, aVar.g());
                                s4Var.b(date);
                                n(file3, s4Var);
                            }
                            bufferedReader.close();
                        } finally {
                        }
                    } catch (Throwable th) {
                        this.options.getLogger().b(c4.ERROR, "Error processing previous session.", th);
                    }
                } else {
                    this.options.getLogger().c(c4.DEBUG, "No previous session file to end.", new Object[0]);
                }
            }
        }
        if (n.class.isInstance(a0Var.c())) {
            if (file.exists()) {
                this.options.getLogger().c(c4.WARNING, "Current session is not ended, we'd need to end it.", new Object[0]);
                try {
                    bufferedReader = new BufferedReader(new InputStreamReader(new FileInputStream(file), b.UTF_8));
                    try {
                        s4 s4Var2 = (s4) this.serializer.d(bufferedReader, s4.class);
                        if (s4Var2 != null) {
                            n(file2, s4Var2);
                        }
                        bufferedReader.close();
                    } finally {
                        try {
                            bufferedReader.close();
                            throw th;
                        } catch (Throwable th2) {
                            th.addSuppressed(th2);
                        }
                    }
                } catch (Throwable th3) {
                    this.options.getLogger().b(c4.ERROR, "Error processing session.", th3);
                }
            }
            Iterable b = n3Var.b();
            if (b.iterator().hasNext()) {
                t3 t3Var = (t3) b.iterator().next();
                if (b4.Session.equals(t3Var.k().b())) {
                    try {
                        BufferedReader bufferedReader2 = new BufferedReader(new InputStreamReader(new ByteArrayInputStream(t3Var.i()), b.UTF_8));
                        try {
                            s4 s4Var3 = (s4) this.serializer.d(bufferedReader2, s4.class);
                            if (s4Var3 == null) {
                                this.options.getLogger().c(c4.ERROR, "Item of type %s returned null by the parser.", t3Var.k().b());
                            } else {
                                n(file, s4Var3);
                            }
                            bufferedReader2.close();
                        } finally {
                            try {
                                bufferedReader2.close();
                                throw th;
                            } catch (Throwable th4) {
                                th.addSuppressed(th4);
                            }
                        }
                    } catch (Throwable th5) {
                        this.options.getLogger().b(c4.ERROR, "Item failed to process.", th5);
                    }
                } else {
                    this.options.getLogger().c(c4.INFO, "Current envelope has a different envelope type %s", t3Var.k().b());
                }
            } else {
                this.options.getLogger().c(c4.INFO, "Current envelope %s is empty", file.getAbsolutePath());
            }
            boolean exists = new File(this.options.getCacheDirPath(), NATIVE_CRASH_MARKER_FILE).exists();
            if (!exists) {
                File file4 = new File(this.options.getCacheDirPath(), CRASH_MARKER_FILE);
                if (file4.exists()) {
                    this.options.getLogger().c(c4.INFO, "Crash marker file exists, crashedLastRun will return true.", new Object[0]);
                    if (!file4.delete()) {
                        this.options.getLogger().c(c4.ERROR, "Failed to delete the crash marker file. %s.", file4.getAbsolutePath());
                    }
                    k3.a().c(z);
                    h();
                }
            }
            z = exists;
            k3.a().c(z);
            h();
        }
        File k = k(n3Var);
        if (k.exists()) {
            this.options.getLogger().c(c4.WARNING, "Not adding Envelope to offline storage because it already exists: %s", k.getAbsolutePath());
            return;
        }
        k0 logger2 = this.options.getLogger();
        c4 c4Var2 = c4.DEBUG;
        logger2.c(c4Var2, "Adding Envelope to offline storage: %s", k.getAbsolutePath());
        if (k.exists()) {
            this.options.getLogger().c(c4Var2, "Overwriting envelope to offline storage: %s", k.getAbsolutePath());
            if (!k.delete()) {
                this.options.getLogger().c(c4.ERROR, "Failed to delete: %s", k.getAbsolutePath());
            }
        }
        try {
            fileOutputStream = new FileOutputStream(k);
            try {
                this.serializer.c(n3Var, fileOutputStream);
                fileOutputStream.close();
            } finally {
                try {
                    fileOutputStream.close();
                    throw th;
                } catch (Throwable th6) {
                    th.addSuppressed(th6);
                }
            }
        } catch (Throwable th7) {
            this.options.getLogger().a(c4.ERROR, th7, "Error writing Envelope %s to offline storage", k.getAbsolutePath());
        }
        if (!UncaughtExceptionHandlerIntegration.a.class.isInstance(a0Var.c())) {
            return;
        }
        try {
            fileOutputStream = new FileOutputStream(new File(this.options.getCacheDirPath(), CRASH_MARKER_FILE));
            try {
                fileOutputStream.write(io.sentry.j.e(io.sentry.j.a()).getBytes(b.UTF_8));
                fileOutputStream.flush();
                fileOutputStream.close();
            } finally {
            }
        } catch (Throwable th8) {
            this.options.getLogger().b(c4.ERROR, "Error writing the crash marker file to the disk", th8);
        }
    }
}