导航菜单

页面标题

页面副标题

Empower MX v1.29.4.340 - f.java 源代码

正在查看: Empower MX v1.29.4.340 应用的 f.java JAVA 源代码文件

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


package io.sentry.cache;

import io.sentry.A2;
import io.sentry.AbstractC1725b3;
import io.sentry.AbstractC1767m;
import io.sentry.B2;
import io.sentry.C1801s2;
import io.sentry.I;
import io.sentry.InterfaceC1736e0;
import io.sentry.InterfaceC1740f0;
import io.sentry.L2;
import io.sentry.T;
import io.sentry.UncaughtExceptionHandlerIntegration;
import io.sentry.V1;
import io.sentry.Y1;
import io.sentry.d3;
import io.sentry.transport.s;
import io.sentry.util.C1813a;
import io.sentry.util.v;
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.WeakHashMap;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

public class f extends c implements g {
    private final CountDownLatch F;
    private final Map G;
    protected final C1813a H;

    public f(L2 l2, String str, int i) {
        super(l2, str, i);
        this.G = new WeakHashMap();
        this.H = new C1813a();
        this.F = new CountDownLatch(1);
    }

    private File[] E() {
        File[] listFiles;
        return (!h() || (listFiles = this.i.listFiles(new FilenameFilter() {
            @Override
            public final boolean accept(File file, String str) {
                boolean Q;
                Q = f.Q(file, str);
                return Q;
            }
        })) == null) ? new File[0] : listFiles;
    }

    public static g I(L2 l2) {
        String cacheDirPath = l2.getCacheDirPath();
        int maxCacheItems = l2.getMaxCacheItems();
        if (cacheDirPath != null) {
            return new f(l2, cacheDirPath, maxCacheItems);
        }
        l2.getLogger().c(B2.WARNING, "cacheDirPath is null, returning NoOpEnvelopeCache", new Object[0]);
        return s.c();
    }

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

    private File L(Y1 y1) {
        String str;
        InterfaceC1736e0 a = this.H.a();
        try {
            if (this.G.containsKey(y1)) {
                str = (String) this.G.get(y1);
            } else {
                String str2 = AbstractC1725b3.a() + ".envelope";
                this.G.put(y1, str2);
                str = str2;
            }
            File file = new File(this.i.getAbsolutePath(), str);
            if (a != null) {
                a.close();
            }
            return file;
        } catch (Throwable th) {
            if (a != null) {
                try {
                    a.close();
                } catch (Throwable th2) {
                    th.addSuppressed(th2);
                }
            }
            throw th;
        }
    }

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

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

    private void S(I i) {
        Date date;
        Object g = io.sentry.util.m.g(i);
        if (g instanceof io.sentry.hints.a) {
            File O = O(this.i.getAbsolutePath());
            if (!O.exists()) {
                this.d.getLogger().c(B2.DEBUG, "No previous session file to end.", new Object[0]);
                return;
            }
            T logger = this.d.getLogger();
            B2 b2 = B2.WARNING;
            logger.c(b2, "Previous session is not ended, we'd need to end it.", new Object[0]);
            try {
                BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(new FileInputStream(O), c.w));
                try {
                    d3 d3Var = (d3) ((InterfaceC1740f0) this.e.a()).c(bufferedReader, d3.class);
                    if (d3Var != null) {
                        io.sentry.hints.a aVar = (io.sentry.hints.a) g;
                        Long c = aVar.c();
                        if (c != null) {
                            date = AbstractC1767m.d(c.longValue());
                            Date k = d3Var.k();
                            if (k != null) {
                                if (date.before(k)) {
                                }
                            }
                            this.d.getLogger().c(b2, "Abnormal exit happened before previous session start, not ending the session.", new Object[0]);
                            bufferedReader.close();
                            return;
                        }
                        date = null;
                        d3Var.q(d3.b.Abnormal, null, true, aVar.g());
                        d3Var.d(date);
                        a0(O, d3Var);
                    }
                    bufferedReader.close();
                } finally {
                }
            } catch (Throwable th) {
                this.d.getLogger().b(B2.ERROR, "Error processing previous session.", th);
            }
        }
    }

    private void T(File file, Y1 y1) {
        Iterable c = y1.c();
        if (!c.iterator().hasNext()) {
            this.d.getLogger().c(B2.INFO, "Current envelope %s is empty", file.getAbsolutePath());
            return;
        }
        C1801s2 c1801s2 = (C1801s2) c.iterator().next();
        if (!A2.Session.equals(c1801s2.B().b())) {
            this.d.getLogger().c(B2.INFO, "Current envelope has a different envelope type %s", c1801s2.B().b());
            return;
        }
        try {
            BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(new ByteArrayInputStream(c1801s2.A()), c.w));
            try {
                d3 d3Var = (d3) ((InterfaceC1740f0) this.e.a()).c(bufferedReader, d3.class);
                if (d3Var == null) {
                    this.d.getLogger().c(B2.ERROR, "Item of type %s returned null by the parser.", c1801s2.B().b());
                } else {
                    a0(file, d3Var);
                }
                bufferedReader.close();
            } finally {
            }
        } catch (Throwable th) {
            this.d.getLogger().b(B2.ERROR, "Item failed to process.", th);
        }
    }

    private void Y() {
        try {
            FileOutputStream fileOutputStream = new FileOutputStream(new File(this.d.getCacheDirPath(), "last_crash"));
            try {
                fileOutputStream.write(AbstractC1767m.g(AbstractC1767m.c()).getBytes(c.w));
                fileOutputStream.flush();
                fileOutputStream.close();
            } finally {
            }
        } catch (Throwable th) {
            this.d.getLogger().b(B2.ERROR, "Error writing the crash marker file to the disk", th);
        }
    }

    private void Z(File file, Y1 y1) {
        if (file.exists()) {
            this.d.getLogger().c(B2.DEBUG, "Overwriting envelope to offline storage: %s", file.getAbsolutePath());
            if (!file.delete()) {
                this.d.getLogger().c(B2.ERROR, "Failed to delete: %s", file.getAbsolutePath());
            }
        }
        try {
            FileOutputStream fileOutputStream = new FileOutputStream(file);
            try {
                ((InterfaceC1740f0) this.e.a()).b(y1, fileOutputStream);
                fileOutputStream.close();
            } finally {
            }
        } catch (Throwable th) {
            this.d.getLogger().a(B2.ERROR, th, "Error writing Envelope %s to offline storage", file.getAbsolutePath());
        }
    }

    private void a0(File file, d3 d3Var) {
        if (file.exists()) {
            this.d.getLogger().c(B2.DEBUG, "Overwriting session to offline storage: %s", d3Var.j());
            if (!file.delete()) {
                this.d.getLogger().c(B2.ERROR, "Failed to delete: %s", file.getAbsolutePath());
            }
        }
        try {
            FileOutputStream fileOutputStream = new FileOutputStream(file);
            try {
                BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(fileOutputStream, c.w));
                try {
                    ((InterfaceC1740f0) this.e.a()).a(d3Var, bufferedWriter);
                    bufferedWriter.close();
                    fileOutputStream.close();
                } finally {
                }
            } finally {
            }
        } catch (Throwable th) {
            this.d.getLogger().a(B2.ERROR, th, "Error writing Session to offline storage: %s", d3Var.j());
        }
    }

    @Override
    public void D(Y1 y1) {
        v.c(y1, "Envelope is required.");
        File L = L(y1);
        if (!L.exists()) {
            this.d.getLogger().c(B2.DEBUG, "Envelope was not cached: %s", L.getAbsolutePath());
            return;
        }
        this.d.getLogger().c(B2.DEBUG, "Discarding envelope from cache: %s", L.getAbsolutePath());
        if (L.delete()) {
            return;
        }
        this.d.getLogger().c(B2.ERROR, "Failed to delete envelope: %s", L.getAbsolutePath());
    }

    public void J() {
        this.F.countDown();
    }

    public void M(Y1 y1, I i) {
        v.c(y1, "Envelope is required.");
        z(E());
        File K = K(this.i.getAbsolutePath());
        File O = O(this.i.getAbsolutePath());
        if (io.sentry.util.m.h(i, io.sentry.hints.l.class) && !K.delete()) {
            this.d.getLogger().c(B2.WARNING, "Current envelope doesn't exist.", new Object[0]);
        }
        if (io.sentry.util.m.h(i, io.sentry.hints.a.class)) {
            S(i);
        }
        if (io.sentry.util.m.h(i, io.sentry.hints.n.class)) {
            if (K.exists()) {
                this.d.getLogger().c(B2.WARNING, "Current session is not ended, we'd need to end it.", new Object[0]);
                try {
                    BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(new FileInputStream(K), c.w));
                    try {
                        d3 d3Var = (d3) ((InterfaceC1740f0) this.e.a()).c(bufferedReader, d3.class);
                        if (d3Var != null) {
                            a0(O, d3Var);
                        }
                        bufferedReader.close();
                    } finally {
                    }
                } catch (Throwable th) {
                    this.d.getLogger().b(B2.ERROR, "Error processing session.", th);
                }
            }
            T(K, y1);
            boolean exists = new File(this.d.getCacheDirPath(), ".sentry-native/last_crash").exists();
            if (!exists) {
                File file = new File(this.d.getCacheDirPath(), "last_crash");
                if (file.exists()) {
                    this.d.getLogger().c(B2.INFO, "Crash marker file exists, crashedLastRun will return true.", new Object[0]);
                    if (!file.delete()) {
                        this.d.getLogger().c(B2.ERROR, "Failed to delete the crash marker file. %s.", file.getAbsolutePath());
                    }
                    exists = true;
                }
            }
            V1.a().b(exists);
            J();
        }
        File L = L(y1);
        if (L.exists()) {
            this.d.getLogger().c(B2.WARNING, "Not adding Envelope to offline storage because it already exists: %s", L.getAbsolutePath());
            return;
        }
        this.d.getLogger().c(B2.DEBUG, "Adding Envelope to offline storage: %s", L.getAbsolutePath());
        Z(L, y1);
        if (io.sentry.util.m.h(i, UncaughtExceptionHandlerIntegration.a.class)) {
            Y();
        }
    }

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

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