package i8; import android.os.Bundle; import android.util.Log; import com.vungle.warren.c0; import com.vungle.warren.model.n; import com.vungle.warren.model.r; import g8.d; import java.io.File; import java.io.IOException; import java.util.Collection; import java.util.HashSet; import java.util.List; import java.util.Locale; /* loaded from: classes2.dex */ public class c implements e { /* renamed from: d, reason: collision with root package name */ static final String f10941d = "i8.c"; /* renamed from: a, reason: collision with root package name */ private final g8.e f10942a; /* renamed from: b, reason: collision with root package name */ private final g8.j f10943b; /* renamed from: c, reason: collision with root package name */ private final com.vungle.warren.c f10944c; c(g8.e eVar, g8.j jVar, com.vungle.warren.c cVar) { this.f10942a = eVar; this.f10943b = jVar; this.f10944c = cVar; } public static g b() { return new g(f10941d).l(0).o(true); } @Override // i8.e public int a(Bundle bundle, h hVar) { if (this.f10942a == null || this.f10943b == null) { return 1; } Log.d(f10941d, "CleanupJob: Current directory snapshot"); com.vungle.warren.utility.j.e(this.f10942a.a()); File[] listFiles = this.f10942a.a().listFiles(); List list = (List) this.f10943b.V(n.class).get(); if (list == null || list.size() == 0) { return 0; } Collection collection = (Collection) this.f10943b.e0().get(); HashSet hashSet = new HashSet(); try { for (n nVar : list) { if (collection == null || collection.isEmpty() || collection.contains(nVar)) { List list2 = (List) this.f10943b.A(nVar.d()).get(); if (list2 != null) { for (String str : list2) { com.vungle.warren.model.c cVar = (com.vungle.warren.model.c) this.f10943b.T(str, com.vungle.warren.model.c.class).get(); if (cVar != null) { if (cVar.s() > System.currentTimeMillis() || cVar.A() == 2) { hashSet.add(cVar.t()); Log.w(f10941d, "setting valid adv " + str + " for placement " + nVar.d()); } else { this.f10943b.u(str); c0.l().w(new r.b().d(h8.c.AD_EXPIRED).a(h8.a.EVENT_ID, str).c()); this.f10944c.W(nVar, nVar.b(), 1000L, false); } } } } } else { Log.d(f10941d, String.format(Locale.ENGLISH, "Placement %s is no longer valid, deleting it and its advertisement", nVar.d())); this.f10943b.s(nVar); } } List list3 = (List) this.f10943b.V(com.vungle.warren.model.c.class).get(); if (list3 != null) { for (com.vungle.warren.model.c cVar2 : list3) { if (cVar2.A() == 2) { hashSet.add(cVar2.t()); Log.d(f10941d, "found adv in viewing state " + cVar2.t()); } else if (!hashSet.contains(cVar2.t())) { Log.e(f10941d, " delete ad " + cVar2.t()); this.f10943b.u(cVar2.t()); } } } if (listFiles != null) { for (File file : listFiles) { if (!hashSet.contains(file.getName())) { Log.v(f10941d, String.format(Locale.ENGLISH, "Deleting assets under directory %s", file.getName())); com.vungle.warren.utility.j.b(file); } } } return 0; } catch (d.a unused) { return 1; } catch (IOException e10) { Log.e(f10941d, "Failed to delete asset directory!", e10); return 1; } } }