package com.xiaomi.push; import android.content.ContentValues; import android.content.Context; import android.database.sqlite.SQLiteDatabase; import android.net.ConnectivityManager; import android.net.NetworkInfo; import android.text.TextUtils; import com.umeng.analytics.pro.ak; import com.umeng.analytics.pro.d; import com.xiaomi.channel.commonutils.logger.b; import java.io.UnsupportedEncodingException; import java.util.ArrayList; import java.util.Collections; import java.util.List; public class gu { private static volatile int a = -1; /* renamed from: a reason: collision with other field name */ private static long f7070a = System.currentTimeMillis(); /* renamed from: a reason: collision with other field name */ private static ao f7071a = new ao(true); /* renamed from: a reason: collision with other field name */ private static com.xiaomi.push.providers.a f7072a = null; /* renamed from: a reason: collision with other field name */ private static final Object f7073a = new Object(); /* renamed from: a reason: collision with other field name */ private static String f7074a = ""; /* renamed from: a reason: collision with other field name */ private static List<a> f7075a = Collections.synchronizedList(new ArrayList()); /* access modifiers changed from: package-private */ public static class a { public int a = -1; /* renamed from: a reason: collision with other field name */ public long f7076a = 0; /* renamed from: a reason: collision with other field name */ public String f7077a = ""; public int b = -1; /* renamed from: b reason: collision with other field name */ public long f7078b = 0; /* renamed from: b reason: collision with other field name */ public String f7079b = ""; public a(String str, long j, int i, int i2, String str2, long j2) { this.f7077a = str; this.f7076a = j; this.a = i; this.b = i2; this.f7079b = str2; this.f7078b = j2; } public boolean a(a aVar) { return TextUtils.equals(aVar.f7077a, this.f7077a) && TextUtils.equals(aVar.f7079b, this.f7079b) && aVar.a == this.a && aVar.b == this.b && Math.abs(aVar.f7076a - this.f7076a) <= 5000; } } public static int a(Context context) { if (a == -1) { a = b(context); } return a; } public static int a(String str) { try { return str.getBytes("UTF-8").length; } catch (UnsupportedEncodingException unused) { return str.getBytes().length; } } private static long a(int i, long j, boolean z, long j2, boolean z2) { if (z && z2) { long j3 = f7070a; f7070a = j2; if (j2 - j3 > 30000 && j > 1024) { return j * 2; } } return (j * ((long) (i == 0 ? 13 : 11))) / 10; } /* renamed from: a reason: collision with other method in class */ private static com.xiaomi.push.providers.a m9406a(Context context) { com.xiaomi.push.providers.a aVar = f7072a; if (aVar != null) { return aVar; } com.xiaomi.push.providers.a aVar2 = new com.xiaomi.push.providers.a(context); f7072a = aVar2; return aVar2; } /* renamed from: a reason: collision with other method in class */ private static synchronized String m9407a(Context context) { synchronized (gu.class) { if (TextUtils.isEmpty(f7074a)) { return ""; } return f7074a; } } /* renamed from: a reason: collision with other method in class */ public static void m9408a(Context context) { a = b(context); } private static void a(Context context, String str, long j, boolean z, long j2) { int a2; boolean isEmpty; if (context != null && !TextUtils.isEmpty(str) && "com.xiaomi.xmsf".equals(context.getPackageName()) && !"com.xiaomi.xmsf".equals(str) && -1 != (a2 = a(context))) { synchronized (f7073a) { isEmpty = f7075a.isEmpty(); a(new a(str, j2, a2, z ? 1 : 0, a2 == 0 ? m9407a(context) : "", j)); } if (isEmpty) { f7071a.a(new gv(context), 5000); } } } public static void a(Context context, String str, long j, boolean z, boolean z2, long j2) { a(context, str, a(a(context), j, z, j2, z2), z, j2); } private static void a(a aVar) { for (a aVar2 : f7075a) { if (aVar2.a(aVar)) { aVar2.f7078b += aVar.f7078b; return; } } f7075a.add(aVar); } /* renamed from: a reason: collision with other method in class */ public static synchronized void m9409a(String str) { synchronized (gu.class) { if (!l.m9614d() && !TextUtils.isEmpty(str)) { f7074a = str; } } } private static int b(Context context) { NetworkInfo activeNetworkInfo; try { ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService("connectivity"); if (connectivityManager == null || (activeNetworkInfo = connectivityManager.getActiveNetworkInfo()) == null) { return -1; } return activeNetworkInfo.getType(); } catch (Exception unused) { return -1; } } /* access modifiers changed from: private */ public static void b(Context context, List<a> list) { try { synchronized (com.xiaomi.push.providers.a.f7456a) { SQLiteDatabase writableDatabase = m9406a(context).getWritableDatabase(); writableDatabase.beginTransaction(); try { for (a aVar : list) { ContentValues contentValues = new ContentValues(); contentValues.put("package_name", aVar.f7077a); contentValues.put("message_ts", Long.valueOf(aVar.f7076a)); contentValues.put(ak.T, Integer.valueOf(aVar.a)); contentValues.put("bytes", Long.valueOf(aVar.f7078b)); contentValues.put("rcv", Integer.valueOf(aVar.b)); contentValues.put("imsi", aVar.f7079b); writableDatabase.insert(d.F, null, contentValues); } writableDatabase.setTransactionSuccessful(); } finally { writableDatabase.endTransaction(); } } } catch (Throwable th) { b.a(th); } } }