package com.tencent.mm.bf;

import com.tencent.matrix.trace.core.AppMethodBeat;
import com.tencent.mm.audio.b.g;
import com.tencent.mm.ba.n;
import com.tencent.mm.model.r;
import com.tencent.mm.sdk.platformtools.ab;
import com.tencent.mm.sdk.platformtools.ah;
import com.tencent.mm.sdk.platformtools.at;
import com.tencent.mm.sdk.platformtools.bo;
import com.tencent.mm.sdk.platformtools.br;
import com.tencent.mm.storage.ad;
import com.tencent.mm.vfs.e;
import com.tencent.ttpic.cache.VideoMemoryManager;
import com.tencent.ytcommon.BuildConfig;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Random;

public class d$a {
    public int dtS = 0;
    public String fQE = "BeiJing;GuangZhou;ShangHai;";
    public int fQF = 0;
    public int fQG = 2;
    public int fQH = 2;
    public int fQI = 2;
    public int fQJ = VideoMemoryManager.VIDEO_CACHE_MEM_CACHE_REMAIN_SIZE;
    public int fQK = 10240000;
    public int fQL = 100;
    public int fQM = 100;
    public int fQN = 100;
    private Random fQO = new Random();
    public List<String> fQP = null;

    public d$a() {
        AppMethodBeat.i(116543);
        AppMethodBeat.o(116543);
    }

    public final boolean ajT() {
        String str;
        AppMethodBeat.i(116544);
        ad Zd = r.Zd();
        String str2 = "upload";
        if ("  getRegionCode ".concat(String.valueOf(Zd)) != null) {
            str = Zd.dui;
        } else {
            str = BuildConfig.FLAVOR;
        }
        ab.d(str2, str);
        str = Zd.dui;
        if (str != null && str.length() > 0 && this.fQP != null && this.fQP.size() > 0) {
            String[] split = str.split("_");
            if (split != null && split.length > 0) {
                int i = 0;
                while (i < split.length) {
                    if (split[i] != null && split[i].length() > 0) {
                        for (String str3 : this.fQP) {
                            if (str3.trim().toLowerCase().equals(split[i].trim().toLowerCase())) {
                                ab.d("upload", "isInRegion");
                                AppMethodBeat.o(116544);
                                return true;
                            }
                        }
                        continue;
                    }
                    i++;
                }
            }
        }
        AppMethodBeat.o(116544);
        return false;
    }

    public final int ajU() {
        switch (d.chatType) {
            case 0:
                return this.fQG;
            case 1:
                return this.fQH;
            case 2:
                return this.fQI;
            default:
                return this.fQG;
        }
    }

    private int ajV() {
        switch (d.chatType) {
            case 0:
                return this.fQL;
            case 1:
                return this.fQM;
            case 2:
                return this.fQN;
            default:
                return this.fQL;
        }
    }

    public final boolean ajW() {
        AppMethodBeat.i(116545);
        if (1 == g.x("EnableSpeexVoiceUpload", 0)) {
            AppMethodBeat.o(116545);
            return true;
        }
        ab.d("upload", "type " + d.chatType);
        int ajV = ajV();
        int ajU = ajU();
        com.tencent.mm.kernel.g.RQ();
        Integer valueOf = Integer.valueOf(bo.h((Integer) com.tencent.mm.kernel.g.RP().Ry().get(16646145, null)));
        ab.d("upload", "daycount " + ajV() + "  count " + valueOf + " rate " + ajU);
        if (valueOf.intValue() > ajV) {
            AppMethodBeat.o(116545);
            return false;
        } else if (ajU == 0) {
            AppMethodBeat.o(116545);
            return false;
        } else if (at.isWifi(ah.getContext())) {
            com.tencent.mm.kernel.g.RQ();
            boolean z = this.dtS == 0 ? true : this.dtS == bo.a((Integer) com.tencent.mm.kernel.g.RP().Ry().get(12290, null), 0);
            ab.d("upload", "fitSex " + this.dtS + " " + z + " " + this.dtS);
            if (!z) {
                AppMethodBeat.o(116545);
                return false;
            } else if (ajT()) {
                int nextInt = this.fQO.nextInt(ajU);
                ab.d("upload", "luck ".concat(String.valueOf(nextInt)));
                if (nextInt == ajU / 2) {
                    AppMethodBeat.o(116545);
                    return true;
                }
                AppMethodBeat.o(116545);
                return false;
            } else {
                AppMethodBeat.o(116545);
                return false;
            }
        } else {
            AppMethodBeat.o(116545);
            return false;
        }
    }

    public static d$a ajX() {
        AppMethodBeat.i(116546);
        ab.d("upload", "parseFromFile");
        String str = n.aiu() + com.tencent.mm.ba.r.aix().cx(1, 9);
        int asZ = (int) e.asZ(str);
        if (asZ == -1) {
            ab.e("upload", "read file failed " + asZ + str);
            AppMethodBeat.o(116546);
            return null;
        }
        byte[] e = e.e(str, 0, asZ);
        if (e == null) {
            ab.e("upload", "read file failed " + asZ + str);
            AppMethodBeat.o(116546);
            return null;
        }
        str = new String(e);
        if (bo.isNullOrNil(str)) {
            AppMethodBeat.o(116546);
            return null;
        }
        String substring;
        asZ = str.indexOf(60);
        if (asZ > 0) {
            substring = str.substring(asZ);
        } else {
            substring = str;
        }
        int hashCode = substring.hashCode();
        d$a d_a = (d$a) d.ajS().get(Integer.valueOf(hashCode));
        if (d_a != null) {
            AppMethodBeat.o(116546);
            return d_a;
        }
        Map z = br.z(substring, "Config");
        if (z == null) {
            ab.e("upload", "parse msg failed");
            AppMethodBeat.o(116546);
            return null;
        }
        try {
            d$a d_a2 = new d$a();
            int i = 0;
            while (true) {
                str = (String) z.get(".Config.Item" + (i == 0 ? BuildConfig.FLAVOR : Integer.valueOf(i)) + ".$key");
                ab.d("upload", "key ".concat(String.valueOf(str)));
                if (str != null) {
                    StringBuilder stringBuilder;
                    Object obj;
                    if (str.equals("region")) {
                        d_a2.fQE = (String) z.get(".Config.Item" + (i == 0 ? BuildConfig.FLAVOR : Integer.valueOf(i)));
                        if (d_a2.fQE != null && d_a2.fQE.length() > 0) {
                            String[] split = d_a2.fQE.split(";");
                            d_a2.fQP = new ArrayList();
                            if (split != null && split.length > 0) {
                                int i2 = 0;
                                while (i2 < split.length) {
                                    if (split[i2] != null && split[i2].length() > 0) {
                                        d_a2.fQP.add(split[i2]);
                                    }
                                    i2++;
                                }
                            }
                        }
                    } else if (str.equals("sex")) {
                        stringBuilder = new StringBuilder(".Config.Item");
                        if (i == 0) {
                            obj = BuildConfig.FLAVOR;
                        } else {
                            obj = Integer.valueOf(i);
                        }
                        d_a2.dtS = bo.getInt((String) z.get(stringBuilder.append(obj).toString()), 0);
                    } else if (str.equals("rate")) {
                        stringBuilder = new StringBuilder(".Config.Item");
                        if (i == 0) {
                            obj = BuildConfig.FLAVOR;
                        } else {
                            obj = Integer.valueOf(i);
                        }
                        d_a2.fQF = bo.getInt((String) z.get(stringBuilder.append(obj).toString()), 0);
                    } else if (str.equals("minsize")) {
                        d_a2.fQJ = bo.getInt((String) z.get(".Config.Item" + (i == 0 ? BuildConfig.FLAVOR : Integer.valueOf(i))), 0);
                    } else if (str.equals("maxsize")) {
                        d_a2.fQK = bo.getInt((String) z.get(".Config.Item" + (i == 0 ? BuildConfig.FLAVOR : Integer.valueOf(i))), 0);
                    } else if (str.equals("daycount_single")) {
                        d_a2.fQL = bo.getInt((String) z.get(".Config.Item" + (i == 0 ? BuildConfig.FLAVOR : Integer.valueOf(i))), 0);
                    } else if (str.equals("daycount_chatroom")) {
                        d_a2.fQM = bo.getInt((String) z.get(".Config.Item" + (i == 0 ? BuildConfig.FLAVOR : Integer.valueOf(i))), 0);
                    } else if (str.equals("daycount_app")) {
                        d_a2.fQN = bo.getInt((String) z.get(".Config.Item" + (i == 0 ? BuildConfig.FLAVOR : Integer.valueOf(i))), 0);
                    } else if (str.equals("rate_single")) {
                        d_a2.fQG = bo.getInt((String) z.get(".Config.Item" + (i == 0 ? BuildConfig.FLAVOR : Integer.valueOf(i))), 0);
                    } else if (str.equals("rate_chatroom")) {
                        d_a2.fQH = bo.getInt((String) z.get(".Config.Item" + (i == 0 ? BuildConfig.FLAVOR : Integer.valueOf(i))), 0);
                    } else if (str.equals("rate_app")) {
                        d_a2.fQI = bo.getInt((String) z.get(".Config.Item" + (i == 0 ? BuildConfig.FLAVOR : Integer.valueOf(i))), 0);
                    }
                    i++;
                } else {
                    ab.d("upload", "sex " + d_a2.dtS);
                    ab.d("upload", "rate_single " + d_a2.fQG);
                    ab.d("upload", "rate_chatroom " + d_a2.fQH);
                    ab.d("upload", "rate_app " + d_a2.fQI);
                    ab.d("upload", "rate " + d_a2.fQF);
                    ab.d("upload", "minsize " + d_a2.fQJ);
                    ab.d("upload", "maxsize " + d_a2.fQK);
                    ab.d("upload", "daycount_single " + d_a2.fQL);
                    ab.d("upload", "daycount_chatroom " + d_a2.fQM);
                    ab.d("upload", "daycount_app " + d_a2.fQN);
                    ab.d("upload", "region " + d_a2.fQE);
                    d.ajS().k(Integer.valueOf(hashCode), d_a2);
                    AppMethodBeat.o(116546);
                    return d_a2;
                }
            }
        } catch (Exception e2) {
            ab.e("upload", "exception:%s", new Object[]{bo.l(e2)});
            AppMethodBeat.o(116546);
            return null;
        }
    }
}
