package com.baidu.license.util; import android.content.Context; import android.text.TextUtils; import com.ubt.jimu.base.entities.Course; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.text.SimpleDateFormat; import java.util.Locale; import org.json.JSONException; import org.json.JSONObject; /* compiled from: AuthenticationManager.java */ /* loaded from: classes.dex */ public final class oi { private static Context a; private static String b; private static String c; private static C0003oi d; private static oi e; /* compiled from: AuthenticationManager.java */ /* renamed from: com.baidu.license.util.oi$oi, reason: collision with other inner class name */ public static class C0003oi { public String a; public String b; } static { Long.valueOf(0L); e = null; } private oi(String str) { b = str; } public static String a() { return SecretUtil.a().concat("gihBYYM8rBQUNM9RAYjXdFPdeiwTmww+Mw2gSCXDqexH6B+kfIglVjnAHX9UIgPVtu10e4Ls="); } private static void b(String str) { String str2; try { str2 = mas.a(str, a()); } catch (Exception e2) { e2.printStackTrace(); str2 = null; } C0003oi c0003oi = d; String str3 = c0003oi != null ? c0003oi.a : ""; C0003oi c2 = c(str2); if (c2 != null) { d = c2; c2.a = str3; try { Long.valueOf(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault()).parse(c2.b).getTime()); } catch (Exception e3) { e3.printStackTrace(); } } } private static boolean c() { if (d != null) { long currentTimeMillis = System.currentTimeMillis(); long j = 0; try { j = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault()).parse(d.b).getTime(); } catch (Exception e2) { e2.printStackTrace(); } if (j > currentTimeMillis) { return true; } } return false; } private static String d() { try { InputStream open = a.getResources().getAssets().open("player" + a(b) + ".license"); InputStreamReader inputStreamReader = new InputStreamReader(open, "UTF-8"); BufferedReader bufferedReader = new BufferedReader(inputStreamReader); StringBuilder sb = new StringBuilder(); while (true) { String readLine = bufferedReader.readLine(); if (readLine == null) { bufferedReader.close(); inputStreamReader.close(); open.close(); return sb.toString(); } sb.append(readLine + "\n"); } } catch (IOException e2) { e2.printStackTrace(); return ""; } } public static synchronized oi a(Context context, String str) { oi oiVar; synchronized (oi.class) { if (e == null) { e = new oi(str); if (context != null) { a = context; } if (c == null) { c = a(a.getPackageName() + a(b)); } if (d == null) { try { C0003oi c2 = c(mas.a(d(), a())); d = c2; if (c2 != null) { Long.valueOf(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault()).parse(d.b).getTime()); } } catch (Exception e2) { e2.printStackTrace(); } } } oiVar = e; } return oiVar; } private static C0003oi c(String str) { if (TextUtils.isEmpty(str)) { return d; } try { C0003oi c0003oi = new C0003oi(); JSONObject jSONObject = new JSONObject(str); jSONObject.optInt(Course.TYPE_BLOCKLY); c0003oi.a = jSONObject.optString("vc"); jSONObject.optString("ar"); c0003oi.b = jSONObject.optString("expireTime"); jSONObject.optJSONArray("funcCodeList"); return c0003oi; } catch (JSONException e2) { e2.printStackTrace(); return null; } } public static boolean b() { String str; C0003oi c0003oi = d; return (c0003oi == null || (str = c0003oi.a) == null || !c.equals(str)) ? false : true; } public static void a(Context context) { if (c()) { return; } String string = context != null ? context.getSharedPreferences("account_sp", 0).getString("license", "") : ""; if (TextUtils.isEmpty(string)) { return; } b(string); } public static String a(String str) { if (TextUtils.isEmpty(str)) { return ""; } try { String str2 = ""; for (byte b2 : MessageDigest.getInstance("MD5").digest(str.getBytes())) { String hexString = Integer.toHexString(b2 & 255); if (hexString.length() == 1) { hexString = "0".concat(String.valueOf(hexString)); } str2 = str2 + hexString; } return str2.toLowerCase(); } catch (NoSuchAlgorithmException e2) { e2.printStackTrace(); return ""; } } }