导航菜单

页面标题

页面副标题

Oolka v2.4.42 - f.java 源代码

正在查看: Oolka v2.4.42 应用的 f.java JAVA 源代码文件

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


package io.sentry.cache;

import io.sentry.Hint;
import io.sentry.ILogger;
import io.sentry.SentryItemType;
import io.sentry.SentryLevel;
import io.sentry.SentryOptions;
import io.sentry.Session;
import io.sentry.UncaughtExceptionHandlerIntegration;
import io.sentry.d4;
import io.sentry.f3;
import io.sentry.h3;
import io.sentry.transport.NoOpEnvelopeCache;
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.FilenameFilter;
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.NotNull;

public class f extends c implements g {
    public final CountDownLatch f;

    @NotNull
    public final Map<h3, String> g;

    public f(@NotNull SentryOptions sentryOptions, @NotNull String str, int i) {
        super(sentryOptions, str, i);
        this.g = new WeakHashMap();
        this.f = new CountDownLatch(1);
    }

    @NotNull
    public static g G(@NotNull SentryOptions sentryOptions) {
        String cacheDirPath = sentryOptions.getCacheDirPath();
        int maxCacheItems = sentryOptions.getMaxCacheItems();
        if (cacheDirPath != null) {
            return new f(sentryOptions, cacheDirPath, maxCacheItems);
        }
        sentryOptions.getLogger().c(SentryLevel.WARNING, "cacheDirPath is null, returning NoOpEnvelopeCache", new Object[0]);
        return NoOpEnvelopeCache.h();
    }

    @NotNull
    public static File I(@NotNull String str) {
        return new File(str, "session.json");
    }

    @NotNull
    public static File K(@NotNull String str) {
        return new File(str, "previous_session.json");
    }

    public static boolean L(File file, String str) {
        return str.endsWith(".envelope");
    }

    @NotNull
    public final File[] F() {
        File[] listFiles;
        return (!n() || (listFiles = this.c.listFiles(new FilenameFilter() {
            @Override
            public final boolean accept(File file, String str) {
                boolean L;
                L = f.L(file, str);
                return L;
            }
        })) == null) ? new File[0] : listFiles;
    }

    public void H() {
        this.f.countDown();
    }

    @NotNull
    public final synchronized File J(@NotNull h3 h3Var) {
        String str;
        if (this.g.containsKey(h3Var)) {
            str = this.g.get(h3Var);
        } else {
            String str2 = UUID.randomUUID() + ".envelope";
            this.g.put(h3Var, str2);
            str = str2;
        }
        return new File(this.c.getAbsolutePath(), str);
    }

    @Override
    public void M(@NotNull h3 h3Var) {
        io.sentry.util.j.c(h3Var, "Envelope is required.");
        File J = J(h3Var);
        if (!J.exists()) {
            this.a.getLogger().c(SentryLevel.DEBUG, "Envelope was not cached: %s", J.getAbsolutePath());
            return;
        }
        this.a.getLogger().c(SentryLevel.DEBUG, "Discarding envelope from cache: %s", J.getAbsolutePath());
        if (J.delete()) {
            return;
        }
        this.a.getLogger().c(SentryLevel.ERROR, "Failed to delete envelope: %s", J.getAbsolutePath());
    }

    public final void O(@NotNull Hint hint) {
        Date date;
        Object g = io.sentry.util.f.g(hint);
        if (g instanceof io.sentry.hints.a) {
            File K = K(this.c.getAbsolutePath());
            if (!K.exists()) {
                this.a.getLogger().c(SentryLevel.DEBUG, "No previous session file to end.", new Object[0]);
                return;
            }
            ILogger logger = this.a.getLogger();
            SentryLevel sentryLevel = SentryLevel.WARNING;
            logger.c(sentryLevel, "Previous session is not ended, we'd need to end it.", new Object[0]);
            try {
                BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(new FileInputStream(K), c.e));
                try {
                    Session session = (Session) this.b.a().c(bufferedReader, Session.class);
                    if (session != null) {
                        io.sentry.hints.a aVar = (io.sentry.hints.a) g;
                        Long e = aVar.e();
                        if (e != null) {
                            date = io.sentry.e.d(e.longValue());
                            Date k = session.k();
                            if (k == null || date.before(k)) {
                                this.a.getLogger().c(sentryLevel, "Abnormal exit happened before previous session start, not ending the session.", new Object[0]);
                                bufferedReader.close();
                                return;
                            }
                        } else {
                            date = null;
                        }
                        session.q(Session.a.Abnormal, null, true, aVar.h());
                        session.d(date);
                        T(K, session);
                    }
                    bufferedReader.close();
                } finally {
                }
            } catch (Throwable th) {
                this.a.getLogger().b(SentryLevel.ERROR, "Error processing previous session.", th);
            }
        }
    }

    public final void P(@NotNull File file, @NotNull h3 h3Var) {
        Iterable<d4> c = h3Var.c();
        if (!c.iterator().hasNext()) {
            this.a.getLogger().c(SentryLevel.INFO, "Current envelope %s is empty", file.getAbsolutePath());
            return;
        }
        d4 next = c.iterator().next();
        if (!SentryItemType.Session.equals(next.G().b())) {
            this.a.getLogger().c(SentryLevel.INFO, "Current envelope has a different envelope type %s", next.G().b());
            return;
        }
        try {
            BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(new ByteArrayInputStream(next.E()), c.e));
            try {
                Session session = (Session) this.b.a().c(bufferedReader, Session.class);
                if (session == null) {
                    this.a.getLogger().c(SentryLevel.ERROR, "Item of type %s returned null by the parser.", next.G().b());
                } else {
                    T(file, session);
                }
                bufferedReader.close();
            } finally {
            }
        } catch (Throwable th) {
            this.a.getLogger().b(SentryLevel.ERROR, "Item failed to process.", th);
        }
    }

    public void P1(@NotNull h3 h3Var, @NotNull Hint hint) {
        io.sentry.util.j.c(h3Var, "Envelope is required.");
        B(F());
        File I = I(this.c.getAbsolutePath());
        File K = K(this.c.getAbsolutePath());
        if (io.sentry.util.f.h(hint, io.sentry.hints.l.class) && !I.delete()) {
            this.a.getLogger().c(SentryLevel.WARNING, "Current envelope doesn't exist.", new Object[0]);
        }
        if (io.sentry.util.f.h(hint, io.sentry.hints.a.class)) {
            O(hint);
        }
        if (io.sentry.util.f.h(hint, io.sentry.hints.m.class)) {
            if (I.exists()) {
                this.a.getLogger().c(SentryLevel.WARNING, "Current session is not ended, we'd need to end it.", new Object[0]);
                try {
                    BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(new FileInputStream(I), c.e));
                    try {
                        Session session = (Session) this.b.a().c(bufferedReader, Session.class);
                        if (session != null) {
                            T(K, session);
                        }
                        bufferedReader.close();
                    } finally {
                    }
                } catch (Throwable th) {
                    this.a.getLogger().b(SentryLevel.ERROR, "Error processing session.", th);
                }
            }
            P(I, h3Var);
            boolean exists = new File(this.a.getCacheDirPath(), ".sentry-native/last_crash").exists();
            if (!exists) {
                File file = new File(this.a.getCacheDirPath(), "last_crash");
                if (file.exists()) {
                    this.a.getLogger().c(SentryLevel.INFO, "Crash marker file exists, crashedLastRun will return true.", new Object[0]);
                    if (!file.delete()) {
                        this.a.getLogger().c(SentryLevel.ERROR, "Failed to delete the crash marker file. %s.", file.getAbsolutePath());
                    }
                    exists = true;
                }
            }
            f3.a().c(exists);
            H();
        }
        File J = J(h3Var);
        if (J.exists()) {
            this.a.getLogger().c(SentryLevel.WARNING, "Not adding Envelope to offline storage because it already exists: %s", J.getAbsolutePath());
            return;
        }
        this.a.getLogger().c(SentryLevel.DEBUG, "Adding Envelope to offline storage: %s", J.getAbsolutePath());
        S(J, h3Var);
        if (io.sentry.util.f.h(hint, UncaughtExceptionHandlerIntegration.a.class)) {
            R();
        }
    }

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

    public final void R() {
        try {
            FileOutputStream fileOutputStream = new FileOutputStream(new File(this.a.getCacheDirPath(), "last_crash"));
            try {
                fileOutputStream.write(io.sentry.e.g(io.sentry.e.c()).getBytes(c.e));
                fileOutputStream.flush();
                fileOutputStream.close();
            } finally {
            }
        } catch (Throwable th) {
            this.a.getLogger().b(SentryLevel.ERROR, "Error writing the crash marker file to the disk", th);
        }
    }

    public final void S(@NotNull File file, @NotNull h3 h3Var) {
        if (file.exists()) {
            this.a.getLogger().c(SentryLevel.DEBUG, "Overwriting envelope to offline storage: %s", file.getAbsolutePath());
            if (!file.delete()) {
                this.a.getLogger().c(SentryLevel.ERROR, "Failed to delete: %s", file.getAbsolutePath());
            }
        }
        try {
            FileOutputStream fileOutputStream = new FileOutputStream(file);
            try {
                this.b.a().b(h3Var, fileOutputStream);
                fileOutputStream.close();
            } finally {
            }
        } catch (Throwable th) {
            this.a.getLogger().a(SentryLevel.ERROR, th, "Error writing Envelope %s to offline storage", file.getAbsolutePath());
        }
    }

    public final void T(@NotNull File file, @NotNull Session session) {
        if (file.exists()) {
            this.a.getLogger().c(SentryLevel.DEBUG, "Overwriting session to offline storage: %s", session.j());
            if (!file.delete()) {
                this.a.getLogger().c(SentryLevel.ERROR, "Failed to delete: %s", file.getAbsolutePath());
            }
        }
        try {
            FileOutputStream fileOutputStream = new FileOutputStream(file);
            try {
                BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(fileOutputStream, c.e));
                try {
                    this.b.a().a(session, bufferedWriter);
                    bufferedWriter.close();
                    fileOutputStream.close();
                } finally {
                }
            } finally {
            }
        } catch (Throwable th) {
            this.a.getLogger().a(SentryLevel.ERROR, th, "Error writing Session to offline storage: %s", session.j());
        }
    }

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