package com.xiaomi.push; import android.content.Context; import android.content.SharedPreferences; import com.huawei.hms.framework.common.hianalytics.CrashHianalyticsData; import com.xiaomi.push.ao; import com.xiaomi.push.service.bs; import java.io.File; import java.io.IOException; import java.util.Date; import java.util.HashMap; import java.util.concurrent.ConcurrentLinkedQueue; import org.json.JSONException; import org.json.JSONObject; public class df { private static volatile df a; /* renamed from: a reason: collision with other field name */ private Context f6843a; /* renamed from: a reason: collision with other field name */ private final ConcurrentLinkedQueue<b> f6844a; class a extends b { a() { super(); } @Override // com.xiaomi.push.ao.b, com.xiaomi.push.df.b, com.xiaomi.push.df.b public void b() { df.this.b(); } } /* access modifiers changed from: package-private */ public class b extends ao.b { long a = System.currentTimeMillis(); b() { } @Override // com.xiaomi.push.ao.b public boolean a() { return true; } @Override // com.xiaomi.push.ao.b public void b() { } /* access modifiers changed from: package-private */ @Override // com.xiaomi.push.ao.b /* renamed from: b reason: collision with other method in class */ public final boolean m9221b() { return System.currentTimeMillis() - this.a > 172800000; } } class c extends b { int a; /* renamed from: a reason: collision with other field name */ File f6846a; /* renamed from: a reason: collision with other field name */ String f6847a; /* renamed from: a reason: collision with other field name */ boolean f6848a; String b; /* renamed from: b reason: collision with other field name */ boolean f6849b; c(String str, String str2, File file, boolean z) { super(); this.f6847a = str; this.b = str2; this.f6846a = file; this.f6849b = z; } @Override // com.xiaomi.push.ao.b private boolean c() { int i; int i2 = 0; SharedPreferences sharedPreferences = df.this.f6843a.getSharedPreferences("log.timestamp", 0); String string = sharedPreferences.getString("log.requst", ""); long currentTimeMillis = System.currentTimeMillis(); try { JSONObject jSONObject = new JSONObject(string); currentTimeMillis = jSONObject.getLong(CrashHianalyticsData.TIME); i = jSONObject.getInt("times"); } catch (JSONException unused) { i = 0; } if (System.currentTimeMillis() - currentTimeMillis >= 86400000) { currentTimeMillis = System.currentTimeMillis(); } else if (i > 10) { return false; } else { i2 = i; } JSONObject jSONObject2 = new JSONObject(); try { jSONObject2.put(CrashHianalyticsData.TIME, currentTimeMillis); jSONObject2.put("times", i2 + 1); sharedPreferences.edit().putString("log.requst", jSONObject2.toString()).commit(); } catch (JSONException e) { com.xiaomi.channel.commonutils.logger.b.c("JSONException on put " + e.getMessage()); } return true; } @Override // com.xiaomi.push.ao.b, com.xiaomi.push.df.b public boolean a() { if (!bj.e(df.this.f6843a)) { return this.f6849b && bj.b(df.this.f6843a); } return true; } @Override // com.xiaomi.push.ao.b, com.xiaomi.push.df.b, com.xiaomi.push.df.b public void b() { try { if (c()) { HashMap hashMap = new HashMap(); hashMap.put("uid", bs.m9706a()); hashMap.put("token", this.b); hashMap.put("net", bj.m9153a(df.this.f6843a)); bj.a(this.f6847a, hashMap, this.f6846a, "file"); } this.f6848a = true; } catch (IOException unused) { } } @Override // com.xiaomi.push.ao.b /* renamed from: c reason: collision with other method in class */ public void m9222c() { if (!this.f6848a) { int i = this.a + 1; this.a = i; if (i < 3) { df.this.f6844a.add(this); } } if (this.f6848a || this.a >= 3) { this.f6846a.delete(); } df.this.a((df) ((long) ((1 << this.a) * 1000))); } } private df(Context context) { ConcurrentLinkedQueue<b> concurrentLinkedQueue = new ConcurrentLinkedQueue<>(); this.f6844a = concurrentLinkedQueue; this.f6843a = context; concurrentLinkedQueue.add(new a()); b(0); } public static df a(Context context) { if (a == null) { synchronized (df.class) { if (a == null) { a = new df(context); } } } a.f6843a = context; return a; } /* access modifiers changed from: private */ /* access modifiers changed from: public */ private void a(long j) { b peek = this.f6844a.peek(); if (peek != null && peek.a()) { b(j); } } /* access modifiers changed from: private */ /* access modifiers changed from: public */ private void b() { if (!ad.b() && !ad.m9117a()) { try { File file = new File(this.f6843a.getExternalFilesDir(null) + "/.logcache"); if (file.exists() && file.isDirectory()) { for (File file2 : file.listFiles()) { file2.delete(); } } } catch (NullPointerException unused) { } } } private void b(long j) { if (!this.f6844a.isEmpty()) { gs.a(new dh(this), j); } } private void c() { while (!this.f6844a.isEmpty()) { b peek = this.f6844a.peek(); if (peek != null) { if (peek.m9221b() || this.f6844a.size() > 6) { com.xiaomi.channel.commonutils.logger.b.c("remove Expired task"); this.f6844a.remove(peek); } else { return; } } } } public void a() { c(); a(0); } public void a(String str, String str2, Date date, Date date2, int i, boolean z) { this.f6844a.add(new dg(this, i, date, date2, str, str2, z)); b(0); } }