package com.weibo.ssosdk; import android.text.TextUtils; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.UnsupportedEncodingException; import java.net.HttpURLConnection; import java.net.URL; import java.net.URLEncoder; import java.util.concurrent.Executors; import java.util.concurrent.locks.ReentrantLock; import org.json.JSONObject; public class WeiboSsoSdk { /* renamed from: e reason: collision with root package name */ public static final String f42462e = "https://login.sina.com.cn/visitor/signin"; /* renamed from: f reason: collision with root package name */ public static final int f42463f = 1; /* renamed from: g reason: collision with root package name */ public static final int f42464g = 2; /* renamed from: h reason: collision with root package name */ public static final String f42465h = "2.0"; /* renamed from: i reason: collision with root package name */ public static final String f42466i = "WeiboSsoSdk"; /* renamed from: j reason: collision with root package name */ public static final int f42467j = 1; /* renamed from: k reason: collision with root package name */ public static final String f42468k = "weibo_sso_sdk_aid"; /* renamed from: l reason: collision with root package name */ public static final String f42469l = "weibo_sso_sdk_init"; /* renamed from: m reason: collision with root package name */ public static WeiboSsoSdk f42470m; /* renamed from: n reason: collision with root package name */ public static ms.f f42471n; /* renamed from: a reason: collision with root package name */ public volatile ReentrantLock f42472a = new ReentrantLock(true); /* renamed from: b reason: collision with root package name */ public boolean f42473b = true; /* renamed from: c reason: collision with root package name */ public h f42474c; /* renamed from: d reason: collision with root package name */ public int f42475d; public class a implements Runnable { public a() { } public void run() { String str; while (true) { try { Thread.sleep(86400000); if (WeiboSsoSdk.this.f42474c == null || TextUtils.isEmpty(WeiboSsoSdk.this.f42474c.b())) { str = WeiboSsoSdk.this.p(); } else { str = WeiboSsoSdk.this.f42474c.b(); } WeiboSsoSdk.n().s(str, 2); } catch (Exception unused) { } } } } public class b implements Runnable { public b() { } public void run() { String str; try { Thread.sleep(60000); if (WeiboSsoSdk.this.f42473b) { if (WeiboSsoSdk.this.f42474c == null || TextUtils.isEmpty(WeiboSsoSdk.this.f42474c.b())) { str = WeiboSsoSdk.this.p(); } else { str = WeiboSsoSdk.this.f42474c.b(); } WeiboSsoSdk.this.s(str, 2); } } catch (Exception unused) { } } } public class c implements Runnable { public c() { } public void run() { String str; if (WeiboSsoSdk.this.f42474c == null || TextUtils.isEmpty(WeiboSsoSdk.this.f42474c.b())) { str = WeiboSsoSdk.this.p(); } else { str = WeiboSsoSdk.this.f42474c.b(); } try { WeiboSsoSdk.this.s(str, 2); } catch (Exception unused) { } } } public class d implements Runnable { public d() { } public void run() { try { WeiboSsoSdk.this.s("", 1); } catch (Exception unused) { } } } public class e implements Runnable { /* renamed from: a reason: collision with root package name */ public final /* synthetic */ a f42480a; public e(a aVar) { this.f42480a = aVar; } public void run() { try { WeiboSsoSdk.this.s("", 1); } catch (Exception unused) { } if (WeiboSsoSdk.this.f42474c == null) { WeiboSsoSdk.this.f42474c = new h(); } this.f42480a.handler(WeiboSsoSdk.this.f42474c); } } public class f implements Runnable { public f() { } public void run() { try { WeiboSsoSdk.this.s("", 1); } catch (Exception unused) { } } } public class g implements Runnable { /* renamed from: a reason: collision with root package name */ public final /* synthetic */ ms.a f42483a; public g(ms.a aVar) { this.f42483a = aVar; } public void run() { try { WeiboSsoSdk.this.s("", 1); } catch (Exception unused) { } if (WeiboSsoSdk.this.f42474c == null) { WeiboSsoSdk.this.f42474c = new h(); } this.f42483a.a(WeiboSsoSdk.this.f42474c.b()); } } public static final class h { /* renamed from: a reason: collision with root package name */ public String f42485a = ""; /* renamed from: b reason: collision with root package name */ public String f42486b = ""; public static h d(String str) { h hVar = new h(); try { JSONObject jSONObject = new JSONObject(str); String optString = jSONObject.optString("retcode", ""); JSONObject jSONObject2 = jSONObject.getJSONObject("data"); if (!optString.equals("20000000") || jSONObject2 == null) { throw new Exception("error: " + optString + " msg:" + jSONObject.optString("msg", "")); } hVar.f42485a = jSONObject2.optString("aid", ""); hVar.f42486b = jSONObject2.optString("sub", ""); return hVar; } catch (Exception e10) { throw e10; } } public final h a() { h hVar = new h(); hVar.f42485a = this.f42485a; hVar.f42486b = this.f42486b; return hVar; } public final String b() { return this.f42485a; } public final String c() { return this.f42486b; } } static { System.loadLibrary("sharewind"); } public WeiboSsoSdk() { ms.f fVar = f42471n; if (fVar == null || !fVar.z()) { throw new Exception("config error"); } this.f42475d = 0; new Thread(new a()).start(); new Thread(new b()).start(); } public static void a(String str) { } public static void b(String str) { } public static synchronized WeiboSsoSdk n() { WeiboSsoSdk weiboSsoSdk; synchronized (WeiboSsoSdk.class) { if (f42470m == null) { f42470m = new WeiboSsoSdk(); } weiboSsoSdk = f42470m; } return weiboSsoSdk; } public static synchronized boolean o(ms.f fVar) { synchronized (WeiboSsoSdk.class) { if (fVar == null) { return false; } if (!fVar.z()) { return false; } if (f42471n != null) { return false; } ms.f fVar2 = (ms.f) fVar.clone(); f42471n = fVar2; ms.d.G(fVar2.c()); return true; } } private native String riseWind(String str, String str2, String str3, String str4, String str5, String str6, String str7, String str8, String str9, String str10, int i10, int i11, int i12); /* JADX WARNING: Removed duplicated region for block: B:24:0x002a A[SYNTHETIC, Splitter:B:24:0x002a] */ /* JADX WARNING: Removed duplicated region for block: B:30:0x0030 A[SYNTHETIC, Splitter:B:30:0x0030] */ /* JADX WARNING: Removed duplicated region for block: B:37:0x0037 A[DONT_GENERATE] */ public final synchronized void h(String str) { Throwable th2; if (!TextUtils.isEmpty(str)) { FileOutputStream fileOutputStream = null; try { FileOutputStream fileOutputStream2 = new FileOutputStream(l(1)); try { fileOutputStream2.write(str.getBytes()); try { fileOutputStream2.close(); } catch (IOException unused) { } } catch (Exception unused2) { fileOutputStream = fileOutputStream2; if (fileOutputStream == null) { } } catch (Throwable th3) { th2 = th3; fileOutputStream = fileOutputStream2; if (fileOutputStream != null) { } throw th2; } } catch (Exception unused3) { if (fileOutputStream == null) { try { fileOutputStream.close(); } catch (IOException unused4) { } } } catch (Throwable th4) { th2 = th4; if (fileOutputStream != null) { try { fileOutputStream.close(); } catch (IOException unused5) { } } throw th2; } } } public final String i(String str) { try { HttpURLConnection httpURLConnection = (HttpURLConnection) new URL(f42462e).openConnection(); httpURLConnection.setRequestMethod("POST"); httpURLConnection.setReadTimeout(3000); httpURLConnection.setConnectTimeout(1000); httpURLConnection.setDoOutput(true); httpURLConnection.setDoInput(true); httpURLConnection.setUseCaches(false); OutputStream outputStream = httpURLConnection.getOutputStream(); outputStream.write(str.getBytes()); outputStream.flush(); if (httpURLConnection.getResponseCode() != 200) { return null; } InputStream inputStream = httpURLConnection.getInputStream(); ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); byte[] bArr = new byte[1024]; while (true) { int read = inputStream.read(bArr); if (read != -1) { byteArrayOutputStream.write(bArr, 0, read); } else { inputStream.close(); byteArrayOutputStream.close(); return new String(byteArrayOutputStream.toByteArray()); } } } catch (Exception unused) { return null; } } public String j() { String p10 = p(); if (!TextUtils.isEmpty(p10)) { return p10; } h hVar = this.f42474c; if (hVar == null || TextUtils.isEmpty(hVar.b())) { Thread thread = new Thread(new f()); thread.start(); thread.join(3000); h hVar2 = this.f42474c; if (hVar2 == null || TextUtils.isEmpty(hVar2.b())) { throw new Exception("visitor login failed"); } } return this.f42474c.b(); } public void k(ms.a aVar) { String p10 = p(); if (!TextUtils.isEmpty(p10)) { aVar.a(p10); } h hVar = this.f42474c; if (hVar == null || TextUtils.isEmpty(hVar.b())) { Executors.newSingleThreadExecutor().execute(new g(aVar)); } else { aVar.a(this.f42474c.b()); } } public final File l(int i10) { return new File(f42471n.c().getFilesDir(), f42468k.concat(String.valueOf(i10))); } public final File m() { return new File(f42471n.c().getFilesDir(), f42469l); } /* JADX WARNING: Removed duplicated region for block: B:15:0x0025 A[SYNTHETIC, Splitter:B:15:0x0025] */ /* JADX WARNING: Removed duplicated region for block: B:21:0x002b A[SYNTHETIC, Splitter:B:21:0x002b] */ /* JADX WARNING: Removed duplicated region for block: B:26:? A[RETURN, SYNTHETIC] */ public final String p() { Throwable th2; FileInputStream fileInputStream = null; try { FileInputStream fileInputStream2 = new FileInputStream(l(1)); try { byte[] bArr = new byte[fileInputStream2.available()]; fileInputStream2.read(bArr); String str = new String(bArr); try { fileInputStream2.close(); } catch (IOException unused) { } return str; } catch (Exception unused2) { fileInputStream = fileInputStream2; if (fileInputStream != null) { } } catch (Throwable th3) { th2 = th3; fileInputStream = fileInputStream2; if (fileInputStream != null) { } throw th2; } } catch (Exception unused3) { if (fileInputStream != null) { return ""; } try { fileInputStream.close(); return ""; } catch (IOException unused4) { return ""; } } catch (Throwable th4) { th2 = th4; if (fileInputStream != null) { try { fileInputStream.close(); } catch (IOException unused5) { } } throw th2; } } /* JADX WARNING: Removed duplicated region for block: B:13:0x0023 A[SYNTHETIC, Splitter:B:13:0x0023] */ /* JADX WARNING: Removed duplicated region for block: B:21:0x002a A[SYNTHETIC, Splitter:B:21:0x002a] */ public final String q() { FileInputStream fileInputStream; Throwable th2; try { fileInputStream = new FileInputStream(m()); try { byte[] bArr = new byte[fileInputStream.available()]; fileInputStream.read(bArr); String str = new String(bArr); try { fileInputStream.close(); } catch (IOException unused) { } return str; } catch (Exception unused2) { if (fileInputStream != null) { try { fileInputStream.close(); } catch (IOException unused3) { } } return null; } catch (Throwable th3) { th2 = th3; if (fileInputStream != null) { try { fileInputStream.close(); } catch (IOException unused4) { } } throw th2; } } catch (Exception unused5) { fileInputStream = null; if (fileInputStream != null) { } return null; } catch (Throwable th4) { fileInputStream = null; th2 = th4; if (fileInputStream != null) { } throw th2; } } /* JADX WARNING: Removed duplicated region for block: B:24:0x0029 A[SYNTHETIC, Splitter:B:24:0x0029] */ /* JADX WARNING: Removed duplicated region for block: B:30:0x002f A[SYNTHETIC, Splitter:B:30:0x002f] */ /* JADX WARNING: Removed duplicated region for block: B:37:0x0036 A[DONT_GENERATE] */ public final synchronized void r(String str) { Throwable th2; if (!TextUtils.isEmpty(str)) { FileOutputStream fileOutputStream = null; try { FileOutputStream fileOutputStream2 = new FileOutputStream(m()); try { fileOutputStream2.write(str.getBytes()); try { fileOutputStream2.close(); } catch (IOException unused) { } } catch (Exception unused2) { fileOutputStream = fileOutputStream2; if (fileOutputStream == null) { } } catch (Throwable th3) { th2 = th3; fileOutputStream = fileOutputStream2; if (fileOutputStream != null) { } throw th2; } } catch (Exception unused3) { if (fileOutputStream == null) { try { fileOutputStream.close(); } catch (IOException unused4) { } } } catch (Throwable th4) { th2 = th4; if (fileOutputStream != null) { try { fileOutputStream.close(); } catch (IOException unused5) { } } throw th2; } } } /* JADX DEBUG: Multi-variable search result rejected for r16v0, resolved type: com.weibo.ssosdk.WeiboSsoSdk */ /* JADX WARN: Multi-variable type inference failed */ /* JADX WARN: Type inference failed for: r14v0, types: [boolean, int] */ /* JADX WARNING: Unknown variable types count: 1 */ public final void s(String str, int i10) { String str2; if (!TextUtils.isEmpty(f42471n.b(false))) { if (!this.f42472a.tryLock()) { this.f42472a.lock(); this.f42472a.unlock(); return; } ?? k10 = f42471n.k(); boolean f10 = f42471n.f(); this.f42473b = false; String u10 = ms.d.u(f42471n.c(), k10 == true ? 1 : 0, f10 ? 1 : 0); try { str2 = URLEncoder.encode(str, "utf-8"); } catch (UnsupportedEncodingException unused) { str2 = ""; } String i11 = i(riseWind(f42471n.b(true), f42471n.c().getPackageName(), str2, u10, f42471n.e(true), f42471n.g(true), f42471n.m(true), f42471n.j(true), f42471n.i(true), f42471n.d(true), i10, this.f42475d, k10)); this.f42475d++; if (i11 != null) { try { h d10 = h.d(i11); if (d10 != null && !TextUtils.isEmpty(d10.b())) { h(d10.b()); } if (i10 == 1) { this.f42474c = d10; } this.f42472a.unlock(); } catch (Exception e10) { this.f42472a.unlock(); throw e10; } } else { this.f42472a.unlock(); throw new Exception("network error."); } } } public void t(String str) { if (!TextUtils.isEmpty(str)) { f42471n.v(str); String c10 = this.f42474c.c(); if (TextUtils.isEmpty(c10) || !c10.equals(str)) { new Thread(new c()).start(); } } } public h u() { h hVar = this.f42474c; if (hVar == null || TextUtils.isEmpty(hVar.b()) || TextUtils.isEmpty(this.f42474c.c())) { Thread thread = new Thread(new d()); thread.start(); thread.join(3000); h hVar2 = this.f42474c; if (hVar2 == null || TextUtils.isEmpty(hVar2.b()) || TextUtils.isEmpty(this.f42474c.c())) { throw new Exception("visitor login failed"); } } return this.f42474c; } public void v(a aVar) { h hVar = this.f42474c; if (hVar == null || TextUtils.isEmpty(hVar.b()) || TextUtils.isEmpty(this.f42474c.c())) { Executors.newSingleThreadExecutor().execute(new e(aVar)); } else { aVar.handler(this.f42474c); } } }