package com.onething.xyvod; import androidx.core.view.accessibility.AccessibilityEventCompat; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.URL; import java.util.Timer; import java.util.TimerTask; import p4.h; public class XYVodSDK { /* renamed from: a reason: collision with root package name */ public static boolean f7264a = true; public static int b = 10000; private static Timer mTimer; public interface DnsResolver { String[] resolveIPs(String str); } public class a extends TimerTask { public void run() { int interval = XYVodSDK.getInterval(); if (interval > 0) { XYVodSDK.f7264a = XYVodSDK.connectLocalServer(); } else { interval = 10000; XYVodSDK.f7264a = true; } if (XYVodSDK.b != interval) { XYVodSDK.stopTimer(); XYVodSDK.b = interval; XYVodSDK.startTimer(); } } } public static String GET_INFO(String str) { try { return getInfoString(str); } catch (Throwable unused) { return ""; } } public static int INIT(String str, String str2, boolean z, int i) { int i3 = -1; if (!z) { try { System.loadLibrary("xyvodsdk"); } catch (Throwable th2) { th2.toString(); return -1; } } if (i >= 0) { try { setLogLevel(i); } catch (Throwable unused) { } } if (str2 != null && !str2.isEmpty()) { setLocalPath(str2); } i3 = init(str); if (i3 == 0) { startTimer(); } return i3; } public static int NETWORK_CHANGED() { try { return networkChanged(-1); } catch (Throwable unused) { return 0; } } public static void OnBackGround() { stopTimer(); } public static void OnResume() { startTimer(); } public static int RELEASE() { f7264a = false; stopTimer(); try { return release(); } catch (Throwable unused) { return -1; } } public static int SET_LOG_ENABLE(int i) { try { return setLogEnable(i); } catch (Throwable unused) { return -1; } } public static String URL_REWRITE(String str, int i) { return URL_REWRITE(str, i, 0); } public static boolean connectLocalServer() { MalformedURLException e; IOException e6; Exception e12; boolean z = true; boolean z4 = false; try { String playUrlRewrite = playUrlRewrite("http://get_sdk_version", 1, 0); String version = getVersion(); if ("http://get_sdk_version".equals(playUrlRewrite)) { return false; } try { HttpURLConnection httpURLConnection = (HttpURLConnection) new URL(playUrlRewrite).openConnection(); httpURLConnection.setRequestMethod("GET"); httpURLConnection.setConnectTimeout(500); httpURLConnection.setReadTimeout(500); if (httpURLConnection.getResponseCode() != 200) { return false; } InputStream inputStream = httpURLConnection.getInputStream(); if (httpURLConnection.getContentLength() > 50 || !read(inputStream).equals(version)) { z = false; } try { inputStream.close(); httpURLConnection.disconnect(); return z; } catch (MalformedURLException e13) { e = e13; z4 = z; e.printStackTrace(); return z4; } catch (IOException e14) { e6 = e14; z4 = z; e6.printStackTrace(); return z4; } catch (Exception e15) { e12 = e15; z4 = z; e12.printStackTrace(); return z4; } } catch (MalformedURLException e16) { e = e16; e.printStackTrace(); return z4; } catch (IOException e17) { e6 = e17; e6.printStackTrace(); return z4; } catch (Exception e18) { e12 = e18; e12.printStackTrace(); return z4; } } catch (Throwable unused) { return false; } } private static native String getInfoString(String str); public static int getInterval() { try { return localTestInterval(); } catch (Throwable unused) { return 0; } } private static native String getVersion(); private static native int init(String str); private static native int isSDKUrl(String str); private static native int localTestInterval(); private static native int networkChanged(int i); private static native String playUrlRewrite(String str, int i, int i3); private static native String playUrlRewriteBack(String str); private static String read(InputStream inputStream) throws Exception { ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); byte[] bArr = new byte[AccessibilityEventCompat.TYPE_TOUCH_EXPLORATION_GESTURE_END]; while (true) { int read = inputStream.read(bArr); if (read != -1) { byteArrayOutputStream.write(bArr, 0, read); } else { inputStream.close(); return byteArrayOutputStream.toString(); } } } public static int refreshDnsResolver(String str) { synchronized (XYVodSDK.class) { } return 0; } private static native int release(); public static native int setCDNIP(String str, String str2); private static native void setLocalPath(String str); private static native int setLogEnable(int i); private static native void setLogLevel(int i); private static native int setLongValue(String str, int i, long j); private static native int setUrlPlayed(String str); public static void startTimer() { if (mTimer == null) { h hVar = new h("com.onething.xyvod.XYVodSDK"); mTimer = hVar; a aVar = new a(); int i = b; hVar.schedule(aVar, (long) i, (long) i); } } private static native int stopTask(String str); public static void stopTimer() { Timer timer = mTimer; if (timer != null) { timer.cancel(); mTimer = null; } } public static String URL_REWRITE(String str, int i, int i3) { if (!f7264a) { return str; } try { String playUrlRewrite = playUrlRewrite(str, i, i3); String str2 = ""; if (str.startsWith("http://")) { str2 = str.substring(7); } else if (str.startsWith("https://")) { str2 = str.substring(8); } if (str2.length() > 0) { int indexOf = str2.indexOf(47); if (indexOf > 0) { str2 = str2.substring(0, indexOf); } refreshDnsResolver(str2); } return playUrlRewrite; } catch (Throwable unused) { return str; } } public static int INIT() { return INIT("", null, false, -1); } }