翰林优商.apk(点击下载) / f.java


package com.qq.e.comm.managers.setting;

import android.content.Context;
import android.text.TextUtils;
import android.util.Base64;
import android.util.Pair;
import com.qq.e.comm.util.GDTLogger;
import com.qq.e.comm.util.Md5Util;
import com.qq.e.comm.util.StringUtil;
import com.qq.e.comm.util.SystemUtil;
import java.io.File;
import java.io.FileWriter;
import java.util.Objects;

/* access modifiers changed from: package-private */
public class f {

    /* access modifiers changed from: package-private */
    public static class b<T> {
        private final String a;
        private final T b;

        private b(String str, T t) {
            this.a = str;
            this.b = t;
        }

        public T a() {
            return this.b;
        }

        public String b() {
            return this.a;
        }
    }

    static b<a> a(Context context) {
        Pair<String, String> a2 = a(context, "devCloudSetting");
        if (a2 == null) {
            return null;
        }
        return new b<>((String) a2.first, new a((String) a2.second));
    }

    static boolean a(Context context, String str, String str2) {
        return a(context, "devCloudSetting", str, str2);
    }

    static b<d> b(Context context) {
        Pair<String, String> a2 = a(context, "placementCloudSetting");
        if (a2 == null) {
            return null;
        }
        return new b<>((String) a2.first, new d((String) a2.second));
    }

    static boolean b(Context context, String str, String str2) {
        return a(context, "placementCloudSetting", str, str2);
    }

    /* JADX WARNING: Removed duplicated region for block: B:30:0x0072 A[SYNTHETIC, Splitter:B:30:0x0072] */
    /* JADX WARNING: Removed duplicated region for block: B:33:0x0077 A[Catch:{ Exception -> 0x007a }] */
    /* JADX WARNING: Removed duplicated region for block: B:38:0x007e A[SYNTHETIC, Splitter:B:38:0x007e] */
    /* JADX WARNING: Removed duplicated region for block: B:41:0x0083 A[Catch:{ Exception -> 0x0086 }] */
    private static boolean b(Context context, String str, String str2, String str3) {
        FileWriter fileWriter;
        Throwable th;
        File dir = context.getDir(SystemUtil.buildNewPathByProcessName("e_qq_com_setting"), 0);
        if (!dir.exists()) {
            dir.mkdirs();
        }
        File file = new File(dir, str + ".cfg");
        File file2 = new File(dir, str + ".sig");
        FileWriter fileWriter2 = null;
        try {
            FileWriter fileWriter3 = new FileWriter(file);
            try {
                fileWriter3.write(str3);
                fileWriter = new FileWriter(file2);
                try {
                    fileWriter.write(str2);
                    try {
                        fileWriter3.close();
                        fileWriter.close();
                    } catch (Exception unused) {
                    }
                    return true;
                } catch (Exception unused2) {
                    fileWriter2 = fileWriter3;
                    try {
                        file.delete();
                        file2.delete();
                        if (fileWriter2 != null) {
                            try {
                                fileWriter2.close();
                            } catch (Exception unused3) {
                                return false;
                            }
                        }
                        if (fileWriter != null) {
                            fileWriter.close();
                        }
                        return false;
                    } catch (Throwable th2) {
                        th = th2;
                        if (fileWriter2 != null) {
                        }
                        if (fileWriter != null) {
                        }
                        throw th;
                    }
                } catch (Throwable th3) {
                    th = th3;
                    fileWriter2 = fileWriter3;
                    if (fileWriter2 != null) {
                        try {
                            fileWriter2.close();
                        } catch (Exception unused4) {
                            throw th;
                        }
                    }
                    if (fileWriter != null) {
                        fileWriter.close();
                    }
                    throw th;
                }
            } catch (Exception unused5) {
                fileWriter = null;
                fileWriter2 = fileWriter3;
                file.delete();
                file2.delete();
                if (fileWriter2 != null) {
                }
                if (fileWriter != null) {
                }
                return false;
            } catch (Throwable th4) {
                fileWriter = null;
                fileWriter2 = fileWriter3;
                th = th4;
                if (fileWriter2 != null) {
                }
                if (fileWriter != null) {
                }
                throw th;
            }
        } catch (Exception unused6) {
            fileWriter = null;
            file.delete();
            file2.delete();
            if (fileWriter2 != null) {
            }
            if (fileWriter != null) {
            }
            return false;
        } catch (Throwable th5) {
            th = th5;
            fileWriter = null;
            if (fileWriter2 != null) {
            }
            if (fileWriter != null) {
            }
            throw th;
        }
    }

    static b<e> c(Context context) {
        Pair<String, String> a2 = a(context, "sdkCloudSetting");
        if (a2 == null) {
            return null;
        }
        return new b<>((String) a2.first, new e((String) a2.second));
    }

    static boolean c(Context context, String str, String str2) {
        return a(context, "sdkCloudSetting", str, str2);
    }

    private static Pair<String, String> a(Context context, String str) {
        File dir = context.getDir(SystemUtil.buildNewPathByProcessName("e_qq_com_setting"), 0);
        if (!dir.exists()) {
            return null;
        }
        File file = new File(dir, str + ".sig");
        File file2 = new File(dir, str + ".cfg");
        if (file.exists() && file2.exists()) {
            try {
                String readAll = StringUtil.readAll(file);
                String readAll2 = StringUtil.readAll(file2);
                if (!TextUtils.isEmpty(readAll) && !TextUtils.isEmpty(readAll2)) {
                    com.qq.e.comm.util.a a2 = com.qq.e.comm.util.a.a();
                    Objects.requireNonNull(a2);
                    if (a2.a(readAll, Md5Util.encode(readAll2))) {
                        return new Pair<>(readAll, new String(Base64.decode(readAll2, 0), "UTF-8"));
                    }
                }
                GDTLogger.d("verify " + str + " setting fail");
            } catch (Exception unused) {
                GDTLogger.d("exception while loading local " + str);
            }
        }
        return null;
    }

    private static final boolean a(Context context, String str, String str2, String str3) {
        if (StringUtil.isEmpty(str2) || StringUtil.isEmpty(str3)) {
            GDTLogger.d(String.format("Fail to update Cloud setting due to sig or setting is empty,name=%s\tsig=%s\tsetting=%s", str, str2, str3));
            return false;
        }
        com.qq.e.comm.util.a a2 = com.qq.e.comm.util.a.a();
        Objects.requireNonNull(a2);
        if (a2.a(str2, Md5Util.encode(str3))) {
            return b(context, str, str2, str3);
        }
        GDTLogger.d(String.format("Fail to update Cloud setting due to sig verify fail,name=%s\tsig=%s\tsetting=%s", str, str2, str3));
        return false;
    }
}