package o;

import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.database.sqlite.SQLiteAccessPermException;
import android.database.sqlite.SQLiteCantOpenDatabaseException;
import android.database.sqlite.SQLiteConstraintException;
import android.database.sqlite.SQLiteDatabaseCorruptException;
import android.database.sqlite.SQLiteDatabaseLockedException;
import android.database.sqlite.SQLiteDiskIOException;
import android.database.sqlite.SQLiteException;
import android.database.sqlite.SQLiteTableLockedException;
import android.os.Build;
import android.text.TextUtils;
import androidx.work.impl.utils.ForceStopRunnable$BroadcastReceiver;
import java.util.concurrent.TimeUnit;

/* compiled from: r8-map-id-3b7cc9102578c509342fa2f0fabed2bfc72239cd258d579fc679bfcbc198b048 */
/* loaded from: classes.dex */
public final class TA implements Runnable {
    public static final long p;
    public final Context l;
    public final C2651um0 m;
    public final C2132pG n;

    /* renamed from: o, reason: collision with root package name */
    public int f338o = 0;

    static {
        C0669Zu.l("ForceStopRunnable");
        p = TimeUnit.DAYS.toMillis(3650L);
    }

    public TA(Context context, C2651um0 c2651um0) {
        this.l = context.getApplicationContext();
        this.m = c2651um0;
        this.n = c2651um0.q;
    }

    public static void b(Context context) {
        AlarmManager alarmManager = (AlarmManager) context.getSystemService("alarm");
        int i = Build.VERSION.SDK_INT >= 31 ? 167772160 : 134217728;
        Intent intent = new Intent();
        intent.setComponent(new ComponentName(context, (Class<?>) ForceStopRunnable$BroadcastReceiver.class));
        intent.setAction("ACTION_FORCE_STOP_RESCHEDULE");
        PendingIntent broadcast = PendingIntent.getBroadcast(context, -1, intent, i);
        long jCurrentTimeMillis = System.currentTimeMillis() + p;
        if (alarmManager != null) {
            alarmManager.setExact(0, jCurrentTimeMillis, broadcast);
        }
    }

    /* JADX WARN: Finally extract failed */
    /* JADX WARN: Removed duplicated region for block: B:133:? A[RETURN, SYNTHETIC] */
    /* JADX WARN: Removed duplicated region for block: B:98:0x0210  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    public final void a() {
        /*
            Method dump skipped, instructions count: 610
            To view this dump add '--comments-level debug' option
        */
        throw new UnsupportedOperationException("Method not decompiled: o.TA.a():void");
    }

    @Override // java.lang.Runnable
    public final void run() {
        boolean zA;
        C2651um0 c2651um0 = this.m;
        try {
            c2651um0.l.getClass();
            boolean zIsEmpty = TextUtils.isEmpty(null);
            Context context = this.l;
            if (zIsEmpty) {
                C0669Zu.e().getClass();
                zA = true;
            } else {
                zA = WY.a(context);
                C0669Zu.e().getClass();
            }
            if (!zA) {
                return;
            }
            while (true) {
                try {
                    IJ.x(context);
                    C0669Zu.e().getClass();
                    try {
                        a();
                        return;
                    } catch (SQLiteAccessPermException | SQLiteCantOpenDatabaseException | SQLiteConstraintException | SQLiteDatabaseCorruptException | SQLiteDatabaseLockedException | SQLiteDiskIOException | SQLiteTableLockedException e) {
                        int i = this.f338o + 1;
                        this.f338o = i;
                        if (i >= 3) {
                            String str = As0.J(context) ? "The file system on the device is in a bad state. WorkManager cannot access the app's internal data store." : "WorkManager can't be accessed from direct boot, because credential encrypted storage isn't accessible.\nDon't access or initialise WorkManager from directAware components. See https://developer.android.com/training/articles/direct-boot";
                            C0669Zu.e().getClass();
                            IllegalStateException illegalStateException = new IllegalStateException(str, e);
                            c2651um0.l.getClass();
                            throw illegalStateException;
                        }
                        C0669Zu.e().getClass();
                        try {
                            Thread.sleep(this.f338o * 300);
                        } catch (InterruptedException unused) {
                        }
                    }
                } catch (SQLiteException e2) {
                    C0669Zu.e().getClass();
                    IllegalStateException illegalStateException2 = new IllegalStateException("Unexpected SQLite exception during migrations", e2);
                    c2651um0.l.getClass();
                    throw illegalStateException2;
                }
            }
        } finally {
            c2651um0.I();
        }
    }
}
