TikTok.apk(点击下载) / AppLogNetworkClient.java


package com.ss.android.ugc.aweme.statistic;

import X.AbstractC09140Yl;
import X.AbstractC09210Ys;
import X.AbstractC09220Yt;
import X.AbstractC09260Yx;
import X.AbstractC09270Yy;
import X.AbstractC09280Yz;
import X.AbstractFutureC10390bM;
import X.AnonymousClass0N5;
import X.AnonymousClass0NG;
import X.AnonymousClass0Z3;
import X.AnonymousClass0Z6;
import X.AnonymousClass0ZB;
import X.AnonymousClass0ZI;
import X.AnonymousClass0ZQ;
import X.C10810c2;
import X.C11210cg;
import X.C28561Bd;
import X.C39884FlR;
import android.net.Uri;
import android.util.Pair;
import com.bytedance.covode.number.Covode;
import com.bytedance.ies.ugc.aweme.network.RetrofitFactory;
import com.bytedance.retrofit2.mime.TypedByteArray;
import com.bytedance.retrofit2.mime.TypedInput;
import com.bytedance.retrofit2.mime.TypedOutput;
import com.ss.android.common.util.NetworkUtils;
import com.swift.sandhook.utils.FileUtils;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutionException;

public final class AppLogNetworkClient extends AnonymousClass0NG {
    public volatile AppLogGetApi LIZIZ;
    public volatile AppLogPostApi LIZJ;
    public final int LIZLLL = FileUtils.FileMode.MODE_ISGID;

    public interface AppLogGetApi {
        static {
            Covode.recordClassIndex(103066);
        }

        @AbstractC09280Yz
        AbstractFutureC10390bM<String> getResponse(@AbstractC09210Ys String str);
    }

    public interface AppLogPostApi {
        static {
            Covode.recordClassIndex(103067);
        }

        @AnonymousClass0ZB
        AbstractFutureC10390bM<String> doPost(@AbstractC09210Ys String str, @AbstractC09220Yt TypedOutput typedOutput, @AnonymousClass0Z6 int i2, @AnonymousClass0Z3 List<AnonymousClass0ZQ> list);

        @AbstractC09270Yy
        @AnonymousClass0ZB
        AbstractFutureC10390bM<String> getResponse(@AbstractC09210Ys String str, @AbstractC09260Yx Map<String, String> map, @AnonymousClass0Z6 int i2);

        @AnonymousClass0ZB
        AnonymousClass0ZI<TypedInput> postDataStream(@AnonymousClass0Z6 int i2, @AbstractC09210Ys String str, @AbstractC09220Yt TypedOutput typedOutput, @AnonymousClass0Z3 List<AnonymousClass0ZQ> list, @AbstractC09140Yl boolean z);
    }

    static {
        Covode.recordClassIndex(103065);
    }

    public static List<AnonymousClass0ZQ> LIZ(Map<String, String> map) {
        if (map == null) {
            return null;
        }
        ArrayList arrayList = new ArrayList();
        for (Map.Entry<String, String> entry : map.entrySet()) {
            arrayList.add(new AnonymousClass0ZQ(entry.getKey(), entry.getValue()));
        }
        return arrayList;
    }

    private AppLogPostApi LIZIZ() {
        if (this.LIZJ == null) {
            this.LIZJ = (AppLogPostApi) RetrofitFactory.LIZ().LIZIZ(C10810c2.LJ).LIZJ().LIZ(AppLogPostApi.class);
        }
        return this.LIZJ;
    }

    @Override // X.AnonymousClass0NG
    public final String LIZ(String str, List<Pair<String, String>> list, Map<String, String> map) {
        if (str == null) {
            return null;
        }
        HashMap hashMap = new HashMap();
        for (Pair<String, String> pair : list) {
            hashMap.put(pair.first, pair.second);
        }
        C11210cg.LIZIZ(hashMap, true);
        try {
            return LIZIZ().getResponse(str, hashMap, 204800).get();
        } catch (ExecutionException e) {
            if (e.getCause() instanceof C28561Bd) {
                throw new AnonymousClass0N5(((C28561Bd) e.getCause()).getStatusCode(), e.getMessage());
            } else if (e.getCause() instanceof C39884FlR) {
                C39884FlR flR = (C39884FlR) e.getCause();
                throw new AnonymousClass0N5(flR.getStatusCode(), flR.getMessage());
            } else {
                throw new AnonymousClass0N5(0, e.getMessage());
            }
        } catch (Exception e2) {
            throw new AnonymousClass0N5(0, e2.getMessage());
        }
    }

    @Override // X.AnonymousClass0NG
    public final String LIZ(String str, Map<String, String> map) {
        if (str == null) {
            return null;
        }
        try {
            if (this.LIZIZ == null) {
                this.LIZIZ = (AppLogGetApi) RetrofitFactory.LIZ().LIZIZ(C10810c2.LJ).LIZJ().LIZ(AppLogGetApi.class);
            }
            return this.LIZIZ.getResponse(str).get();
        } catch (ExecutionException e) {
            if (e.getCause() instanceof C28561Bd) {
                throw new AnonymousClass0N5(((C28561Bd) e.getCause()).getStatusCode(), e.getMessage());
            }
            throw new AnonymousClass0N5(0, e.getMessage());
        } catch (Exception e2) {
            throw new AnonymousClass0N5(0, e2.getMessage());
        }
    }

    @Override // X.AnonymousClass0NG
    public final String LIZ(String str, byte[] bArr, Map<String, String> map) {
        String filterUrl = NetworkUtils.filterUrl(str);
        if (filterUrl == null) {
            return null;
        }
        if (map != null) {
            try {
                String str2 = map.get("Content-Encoding");
                String str3 = map.get("Content-Type");
                ArrayList arrayList = new ArrayList();
                if (str2 != null) {
                    arrayList.add(new AnonymousClass0ZQ("Content-Encoding", str2));
                }
                if (str3 != null && str3.length() > 0) {
                    arrayList.add(new AnonymousClass0ZQ("Content-Type", str3));
                }
                for (Map.Entry<String, String> entry : map.entrySet()) {
                    arrayList.add(new AnonymousClass0ZQ(entry.getKey(), entry.getValue()));
                }
                return LIZIZ().doPost(filterUrl, new TypedByteArray(str3, bArr, new String[0]), 204800, arrayList).get();
            } catch (ExecutionException e) {
                if (e.getCause() instanceof C28561Bd) {
                    throw new AnonymousClass0N5(((C28561Bd) e.getCause()).getStatusCode(), e.getMessage());
                } else if (e.getCause() instanceof C39884FlR) {
                    C39884FlR flR = (C39884FlR) e.getCause();
                    throw new AnonymousClass0N5(flR.getStatusCode(), flR.getMessage());
                } else {
                    throw new AnonymousClass0N5(0, e.getMessage());
                }
            } catch (Exception e2) {
                throw new AnonymousClass0N5(0, e2.getMessage());
            }
        } else {
            return LIZIZ().doPost(filterUrl, new TypedByteArray(null, bArr, new String[0]), 204800, null).get();
        }
    }

    /* JADX WARNING: Removed duplicated region for block: B:45:0x00e6 A[Catch:{ all -> 0x0105 }] */
    /* JADX WARNING: Removed duplicated region for block: B:47:0x00f9 A[Catch:{ all -> 0x0105 }] */
    /* JADX WARNING: Removed duplicated region for block: B:53:0x010c A[SYNTHETIC, Splitter:B:53:0x010c] */
    /* JADX WARNING: Removed duplicated region for block: B:58:0x0116 A[SYNTHETIC, Splitter:B:58:0x0116] */
    @Override // X.AnonymousClass0NG
    public final byte[] LIZIZ(String str, byte[] bArr, Map<String, String> map) {
        Throwable th;
        ByteArrayOutputStream byteArrayOutputStream;
        Exception e;
        InputStream inputStream = null;
        try {
            Uri parse = Uri.parse(str);
            StringBuilder sb = new StringBuilder();
            String scheme = parse.getScheme();
            String host = parse.getHost();
            int port = parse.getPort();
            if (host != null) {
                if (scheme != null) {
                    sb.append(scheme);
                    sb.append("://");
                }
                sb.append(host);
                if (port > 0) {
                    sb.append(':');
                    sb.append(port);
                }
            }
            String sb2 = sb.toString();
            String path = parse.getPath();
            String query = parse.getQuery();
            if (query != null) {
                path = path + "?" + query;
            }
            Pair pair = new Pair(sb2, path);
            Object obj = pair.first;
            map.remove("Content-Type");
            List<AnonymousClass0ZQ> LIZ = LIZ(map);
            InputStream in = ((AppLogPostApi) RetrofitFactory.LIZ().LIZIZ("https://log-va.tiktokv.com/service/2/log_settings/").LIZJ().LIZ(AppLogPostApi.class)).postDataStream(-1, (String) pair.second, new TypedByteArray(map.get("Content-Type"), bArr, new String[0]), LIZ, false).execute().LIZIZ.in();
            try {
                byteArrayOutputStream = new ByteArrayOutputStream();
                try {
                    byte[] bArr2 = new byte[FileUtils.FileMode.MODE_ISGID];
                    while (true) {
                        int read = in.read(bArr2);
                        if (read == -1) {
                            break;
                        }
                        byteArrayOutputStream.write(bArr2, 0, read);
                    }
                    byte[] byteArray = byteArrayOutputStream.toByteArray();
                    if (in != null) {
                        try {
                            in.close();
                        } catch (IOException e2) {
                            e2.printStackTrace();
                        }
                    }
                    try {
                        byteArrayOutputStream.close();
                    } catch (IOException e3) {
                        e3.printStackTrace();
                    }
                    return byteArray;
                } catch (Exception e4) {
                    e = e4;
                    inputStream = in;
                    try {
                        if (e instanceof C28561Bd) {
                        }
                    } catch (Throwable th2) {
                        th = th2;
                        if (inputStream != null) {
                            try {
                                inputStream.close();
                            } catch (IOException e5) {
                                e5.printStackTrace();
                            }
                        }
                        if (byteArrayOutputStream != null) {
                            try {
                                byteArrayOutputStream.close();
                            } catch (IOException e6) {
                                e6.printStackTrace();
                            }
                        }
                        throw th;
                    }
                } catch (Throwable th3) {
                    th = th3;
                    inputStream = in;
                    if (inputStream != null) {
                    }
                    if (byteArrayOutputStream != null) {
                    }
                    throw th;
                }
            } catch (Exception e7) {
                e = e7;
                byteArrayOutputStream = null;
                inputStream = in;
                if (e instanceof C28561Bd) {
                }
            } catch (Throwable th4) {
                th = th4;
                byteArrayOutputStream = null;
                inputStream = in;
                if (inputStream != null) {
                }
                if (byteArrayOutputStream != null) {
                }
                throw th;
            }
        } catch (Exception e8) {
            e = e8;
            byteArrayOutputStream = null;
            if (e instanceof C28561Bd) {
                throw new AnonymousClass0N5(((C28561Bd) e).getStatusCode(), e.getMessage());
            }
            throw new AnonymousClass0N5(0, e.getMessage());
        } catch (Throwable th5) {
            th = th5;
            byteArrayOutputStream = null;
            if (inputStream != null) {
            }
            if (byteArrayOutputStream != null) {
            }
            throw th;
        }
    }
}