FacePro.apk(点击下载) / b.java


package com.tencent.liteav.txcvodplayer.a;

import android.content.Context;
import android.content.SharedPreferences;
import com.huawei.hms.support.hianalytics.HiAnalyticsConstant;
import com.meizu.cloud.pushsdk.constants.PushConstants;
import com.tencent.flutter.tim_ui_kit_push_plugin.common.Extras;
import com.tencent.liteav.base.util.CommonUtil;
import com.tencent.liteav.base.util.LiteavLog;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.net.ssl.HttpsURLConnection;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

public class b {

    /* renamed from: d  reason: collision with root package name */
    private static volatile b f9029d;

    /* renamed from: a  reason: collision with root package name */
    private Context f9030a;

    /* renamed from: b  reason: collision with root package name */
    private Map<String, List<C0139b>> f9031b = new HashMap();

    /* renamed from: c  reason: collision with root package name */
    private Map<String, Long> f9032c = new HashMap();

    /* access modifiers changed from: package-private */
    public static class a extends C0139b {

        /* renamed from: a  reason: collision with root package name */
        int f9035a = 60;

        /* renamed from: b  reason: collision with root package name */
        boolean f9036b = false;

        /* renamed from: c  reason: collision with root package name */
        long f9037c = 0;

        public a(int i10, boolean z10, long j10, String str) {
            super(str, "40305");
            this.f9035a = i10;
            this.f9036b = z10;
            this.f9037c = j10;
        }

        public a(String str) {
            try {
                JSONObject jSONObject = new JSONObject(str);
                this.f9035a = jSONObject.optInt("SengmentDuration", 60);
                this.f9036b = jSONObject.optBoolean("ReportSwitch", false);
                this.f9037c = jSONObject.optLong("ExpireTime", (System.currentTimeMillis() / 1000) + 3600);
                this.f9038d = jSONObject.optString(HiAnalyticsConstant.HaKey.BI_KEY_APPID, "");
                this.f9039e = jSONObject.optString("eventid", "");
            } catch (JSONException e10) {
                LiteavLog.i("TXCVodPlayReportControl", "parseFromString: " + e10.toString());
                this.f9035a = 60;
                this.f9036b = false;
                this.f9037c = 0;
                this.f9038d = "";
                this.f9039e = "40305";
            }
        }

        private JSONObject a() {
            JSONObject jSONObject = new JSONObject();
            try {
                jSONObject.put("SengmentDuration", this.f9035a);
                jSONObject.put("ReportSwitch", this.f9036b);
                jSONObject.put("ExpireTime", this.f9037c);
                jSONObject.put(HiAnalyticsConstant.HaKey.BI_KEY_APPID, this.f9038d);
                jSONObject.put("eventid", this.f9039e);
            } catch (JSONException e10) {
                LiteavLog.e("TXCVodPlayReportControl", "toJsonObject jsonexception: " + e10.toString());
            }
            return jSONObject;
        }

        public final String toString() {
            return a().toString();
        }
    }

    /* access modifiers changed from: package-private */
    /* renamed from: com.tencent.liteav.txcvodplayer.a.b$b  reason: collision with other inner class name */
    public static class C0139b {

        /* renamed from: d  reason: collision with root package name */
        protected String f9038d = "";

        /* renamed from: e  reason: collision with root package name */
        protected String f9039e = "";

        public C0139b() {
        }

        public C0139b(String str, String str2) {
            this.f9038d = str;
            this.f9039e = str2;
        }
    }

    private b(Context context) {
        this.f9030a = context.getApplicationContext();
        a();
    }

    public static b a(Context context) {
        if (f9029d == null) {
            synchronized (b.class) {
                if (f9029d == null) {
                    f9029d = new b(context);
                }
            }
        }
        return f9029d;
    }

    private static String a(List<C0139b> list) {
        if (list == null) {
            return "";
        }
        JSONArray jSONArray = new JSONArray();
        int i10 = 0;
        for (C0139b bVar : list) {
            JSONObject jSONObject = new JSONObject();
            if ("40305".equals(bVar.f9039e)) {
                a aVar = (a) bVar;
                try {
                    jSONObject.put(HiAnalyticsConstant.HaKey.BI_KEY_APPID, aVar.f9038d);
                    jSONObject.put("eventid", aVar.f9039e);
                    jSONObject.put("40305", aVar.toString());
                } catch (JSONException e10) {
                    LiteavLog.e("TXCVodPlayReportControl", "controlDataListToString jsonObject.put:" + e10.toString());
                }
            }
            int i11 = i10 + 1;
            try {
                jSONArray.put(i10, jSONObject);
            } catch (JSONException e11) {
                LiteavLog.e("TXCVodPlayReportControl", "jsonArray.put: " + e11.toString());
            }
            i10 = i11;
        }
        return jSONArray.toString();
    }

    private void a() {
        SharedPreferences sharedPreferences = this.f9030a.getSharedPreferences("vod_report_config", 0);
        if (sharedPreferences != null) {
            String string = sharedPreferences.getString("value", "");
            if (!string.isEmpty()) {
                try {
                    synchronized (this) {
                        JSONArray jSONArray = new JSONArray(string);
                        for (int i10 = 0; i10 < jSONArray.length(); i10++) {
                            List<C0139b> e10 = e(jSONArray.optString(i10));
                            if (e10.size() > 0) {
                                this.f9031b.put(e10.get(0).f9038d, e10);
                            }
                        }
                    }
                } catch (JSONException e11) {
                    LiteavLog.e("TXCVodPlayReportControl", e11.toString());
                }
            }
        }
    }

    static /* synthetic */ void a(b bVar) {
        SharedPreferences.Editor edit;
        synchronized (bVar) {
            int i10 = 0;
            SharedPreferences sharedPreferences = bVar.f9030a.getSharedPreferences("vod_report_config", 0);
            if (!(sharedPreferences == null || (edit = sharedPreferences.edit()) == null || bVar.f9031b.size() <= 0)) {
                JSONArray jSONArray = new JSONArray();
                for (Map.Entry<String, List<C0139b>> entry : bVar.f9031b.entrySet()) {
                    int i11 = i10 + 1;
                    try {
                        jSONArray.put(i10, a(entry.getValue()));
                    } catch (JSONException e10) {
                        LiteavLog.e("TXCVodPlayReportControl", e10.toString());
                    }
                    i10 = i11;
                }
                edit.putString("value", jSONArray.toString());
                edit.apply();
            }
        }
    }

    /* JADX WARNING: Removed duplicated region for block: B:50:0x014e A[SYNTHETIC, Splitter:B:50:0x014e] */
    /* JADX WARNING: Removed duplicated region for block: B:55:0x0157 A[SYNTHETIC, Splitter:B:55:0x0157] */
    /* JADX WARNING: Removed duplicated region for block: B:67:? A[RETURN, SYNTHETIC] */
    static /* synthetic */ void a(b bVar, String str) {
        URL url;
        HttpsURLConnection httpsURLConnection;
        Throwable th2;
        IOException e10;
        BufferedReader bufferedReader = null;
        try {
            String str2 = "https://vodreport.qcloud.com/describeControlInfos/v1/" + str + "?sdkVersion=" + CommonUtil.getSDKVersionStr();
            LiteavLog.i("TXCVodPlayReportControl", "makeUrl: ".concat(String.valueOf(str2)));
            url = new URL(str2);
        } catch (MalformedURLException e11) {
            LiteavLog.i("TXCVodPlayReportControl", "URL :" + e11.toString());
            url = null;
        }
        if (url != null) {
            try {
                httpsURLConnection = (HttpsURLConnection) url.openConnection();
            } catch (IOException e12) {
                LiteavLog.i("TXCVodPlayReportControl", "openConnection :" + e12.toString());
                httpsURLConnection = null;
            }
            if (httpsURLConnection != null) {
                try {
                    httpsURLConnection.setConnectTimeout(8000);
                    httpsURLConnection.setReadTimeout(8000);
                    httpsURLConnection.setRequestProperty("Accept-Encoding", "identity");
                    httpsURLConnection.setInstanceFollowRedirects(true);
                    httpsURLConnection.connect();
                    int responseCode = httpsURLConnection.getResponseCode();
                    LiteavLog.i("TXCVodPlayReportControl", "request report control response code : ".concat(String.valueOf(responseCode)));
                    if (200 == responseCode) {
                        BufferedReader bufferedReader2 = new BufferedReader(new InputStreamReader(httpsURLConnection.getInputStream()));
                        try {
                            StringBuilder sb2 = new StringBuilder();
                            while (true) {
                                String readLine = bufferedReader2.readLine();
                                if (readLine == null) {
                                    break;
                                }
                                sb2.append(readLine);
                            }
                            String sb3 = sb2.toString();
                            if (sb3 == null || sb3.isEmpty()) {
                                LiteavLog.i("TXCVodPlayReportControl", "response msg is empty");
                            } else {
                                try {
                                    JSONObject jSONObject = new JSONObject(sb3);
                                    int i10 = jSONObject.getInt(PushConstants.BASIC_PUSH_STATUS_CODE);
                                    LiteavLog.i("TXCVodPlayReportControl", "code = " + i10 + " ,message = " + jSONObject.optString("message") + " , requestID= " + jSONObject.optString("requestId"));
                                    if (i10 == 0 && jSONObject.getInt("version") == 1) {
                                        bVar.a(jSONObject);
                                    }
                                } catch (JSONException e13) {
                                    LiteavLog.e("TXCVodPlayReportControl", "parseJson err: " + e13.toString());
                                }
                            }
                            bufferedReader = bufferedReader2;
                        } catch (IOException e14) {
                            e10 = e14;
                            bufferedReader = bufferedReader2;
                            try {
                                LiteavLog.i("TXCVodPlayReportControl", "connect or read: " + e10.toString());
                                httpsURLConnection.disconnect();
                                if (bufferedReader == null) {
                                }
                            } catch (Throwable th3) {
                                th2 = th3;
                                httpsURLConnection.disconnect();
                                if (bufferedReader != null) {
                                    try {
                                        bufferedReader.close();
                                    } catch (IOException unused) {
                                    }
                                }
                                throw th2;
                            }
                        } catch (Throwable th4) {
                            th2 = th4;
                            bufferedReader = bufferedReader2;
                            httpsURLConnection.disconnect();
                            if (bufferedReader != null) {
                            }
                            throw th2;
                        }
                    }
                    httpsURLConnection.disconnect();
                    if (bufferedReader != null) {
                        try {
                            bufferedReader.close();
                        } catch (IOException unused2) {
                        }
                    }
                } catch (IOException e15) {
                    e10 = e15;
                    LiteavLog.i("TXCVodPlayReportControl", "connect or read: " + e10.toString());
                    httpsURLConnection.disconnect();
                    if (bufferedReader == null) {
                        try {
                            bufferedReader.close();
                        } catch (IOException unused3) {
                        }
                    }
                }
            }
        }
    }

    private void a(String str, long j10) {
        synchronized (this) {
            this.f9032c.put(str, Long.valueOf(j10));
            LiteavLog.i("TXCVodPlayReportControl", "SetReportExpireTime in mem appid= " + str + " , time=" + j10);
        }
    }

    private void a(JSONObject jSONObject) {
        JSONArray optJSONArray = jSONObject.optJSONArray("controlInfos");
        int optInt = jSONObject.optInt(Extras.APP_ID);
        if (optInt == 0) {
            LiteavLog.i("TXCVodPlayReportControl", "response appid is zero!");
        } else if (optJSONArray != null && optJSONArray.length() != 0) {
            ArrayList arrayList = new ArrayList();
            for (int i10 = 0; i10 < optJSONArray.length(); i10++) {
                JSONObject optJSONObject = optJSONArray.optJSONObject(i10);
                if (optJSONObject != null && "40305".equals(optJSONObject.optString("eventId"))) {
                    long optLong = optJSONObject.optLong("expireTime", 0);
                    if (optLong > System.currentTimeMillis() / 1000) {
                        String optString = optJSONObject.optString("switch");
                        int optInt2 = optJSONObject.optInt("frequency", 60);
                        arrayList.add(new a(optInt2 < 60 ? 60 : optInt2, "on".equalsIgnoreCase(optString), optLong, String.valueOf(optInt)));
                    }
                }
            }
            synchronized (this) {
                if (arrayList.size() != 0) {
                    this.f9031b.put(String.valueOf(optInt), arrayList);
                    this.f9032c.remove(Integer.valueOf(optInt));
                }
            }
        }
    }

    private long d(String str) {
        if (str == null || str.isEmpty()) {
            return (System.currentTimeMillis() / 1000) + 3600;
        }
        synchronized (this) {
            if (this.f9032c.containsKey(str)) {
                return this.f9032c.get(str).longValue();
            }
            List<C0139b> list = this.f9031b.get(str);
            if (list != null) {
                for (C0139b bVar : list) {
                    if ("40305".equals(bVar.f9039e) && str.equalsIgnoreCase(bVar.f9038d)) {
                        return ((a) bVar).f9037c;
                    }
                }
            }
            return 0;
        }
    }

    private static List<C0139b> e(String str) {
        ArrayList arrayList = new ArrayList();
        try {
            JSONArray jSONArray = new JSONArray(str);
            for (int i10 = 0; i10 < jSONArray.length(); i10++) {
                JSONObject optJSONObject = jSONArray.optJSONObject(i10);
                if (optJSONObject != null) {
                    optJSONObject.optString(HiAnalyticsConstant.HaKey.BI_KEY_APPID, "");
                    if (optJSONObject.optString("eventid", "").equalsIgnoreCase("40305")) {
                        String optString = optJSONObject.optString("40305", "");
                        if (!optString.isEmpty()) {
                            arrayList.add(new a(optString));
                        }
                    }
                }
            }
        } catch (JSONException e10) {
            LiteavLog.e("TXCVodPlayReportControl", "controlDataListParseFormString :" + e10.toString());
        }
        return arrayList;
    }

    public final int a(String str) {
        if (str == null || str.isEmpty()) {
            return 60;
        }
        synchronized (this) {
            List<C0139b> list = this.f9031b.get(str);
            if (list != null) {
                for (C0139b bVar : list) {
                    if (bVar != null && "40305".equals(bVar.f9039e) && str.equalsIgnoreCase(bVar.f9038d)) {
                        a aVar = (a) bVar;
                        if (aVar.f9037c > System.currentTimeMillis() / 1000) {
                            return aVar.f9035a;
                        }
                    }
                }
            }
            return 60;
        }
    }

    public final boolean b(String str) {
        if (str == null || str.isEmpty()) {
            return false;
        }
        synchronized (this) {
            List<C0139b> list = this.f9031b.get(str);
            if (list != null) {
                for (C0139b bVar : list) {
                    if (bVar != null && "40305".equals(bVar.f9039e) && str.equalsIgnoreCase(bVar.f9038d)) {
                        a aVar = (a) bVar;
                        if (aVar.f9037c > System.currentTimeMillis() / 1000) {
                            return aVar.f9036b;
                        }
                    }
                }
            }
            return false;
        }
    }

    public final void c(final String str) {
        if (str != null && !str.isEmpty()) {
            synchronized (this) {
                if (d(str) < System.currentTimeMillis() / 1000) {
                    LiteavLog.i("TXCVodPlayReportControl", "RequestReportControl");
                    a(str, (System.currentTimeMillis() / 1000) + 3600);
                    new Thread(new Runnable() {
                        /* class com.tencent.liteav.txcvodplayer.a.b.AnonymousClass1 */

                        public final void run() {
                            b.a(b.this, str);
                            b.a(b.this);
                        }
                    }, "report_control").start();
                }
            }
        }
    }
}