QQ浏览器 v12.2.3.7053版本的 MD5 值为:8285ab3059e5c8b521a264dfbc5c3685

以下内容为反编译后的 SkinWebCacheManager.java 源代码,内容仅作参考


package com.tencent.mtt.external.setting.manager;

import android.os.Handler;
import android.os.Looper;
import android.text.TextUtils;
import android.webkit.WebResourceResponse;
import com.tencent.common.task.TaskManager;
import com.tencent.common.utils.FileUtils;
import com.tencent.map.geolocation.util.DateUtils;
import com.tencent.mtt.ContextHolder;
import com.tencent.mtt.base.task.PictureTask;
import com.tencent.mtt.base.task.Task;
import com.tencent.mtt.base.task.TaskObserver;
import com.tencent.mtt.browser.db.pub.SkinBeanDao;
import com.tencent.mtt.setting.PublicSettingManager;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;

public final class SkinWebCacheManager implements TaskObserver {

    private static SkinWebCacheManager f59745c;

    final HashMap<String, String> f59746a = new HashMap<>();

    ArrayList<SkinWebListener> f59747b = new ArrayList<>();

    public interface SkinWebListener {
        void f();
    }

    public class SkinWebTask extends PictureTask {
        public SkinWebTask(String str, TaskObserver taskObserver) {
            super(str, taskObserver, false, null, (byte) 0, SkinBeanDao.TABLENAME);
        }
    }

    private SkinWebCacheManager() {
        d();
    }

    public static SkinWebCacheManager a() {
        if (f59745c == null) {
            f59745c = new SkinWebCacheManager();
        }
        return f59745c;
    }

    private void a(String str, byte[] bArr) {
        String replace = str.substring(str.lastIndexOf("/") + 1).replace("?", "");
        if (TextUtils.isEmpty(replace)) {
            return;
        }
        File file = new File(b(), replace);
        if (file.exists()) {
            file.delete();
        }
        FileUtils.a(file, bArr);
        synchronized (this.f59746a) {
            if (!this.f59746a.containsKey(str)) {
                this.f59746a.put(str, replace);
                b(str + "@@" + replace);
            }
        }
    }

    public static File b() {
        return FileUtils.a(FileUtils.a(FileUtils.a(ContextHolder.getAppContext()), "data"), "skinweb_6");
    }

    private void b(String str) {
        try {
            PrintWriter printWriter = new PrintWriter(new FileOutputStream(new File(b(), ".skin_web_map_6.dat"), true));
            printWriter.println(str);
            printWriter.flush();
            printWriter.close();
        } catch (FileNotFoundException unused) {
        }
    }

    private boolean c(String str) {
        if (TextUtils.isEmpty(str)) {
            return false;
        }
        return str.startsWith("http://theme.html5.qq.com") || str.startsWith("http://res.rom.qq.com");
    }

    private void d() {
        File file = new File(b(), ".skin_web_map_6.dat");
        if (file.exists()) {
            BufferedReader bufferedReader = null;
            try {
                try {
                    BufferedReader bufferedReader2 = new BufferedReader(new InputStreamReader(new FileInputStream(file.getPath()), "UTF-8"));
                    while (true) {
                        try {
                            String readLine = bufferedReader2.readLine();
                            if (readLine == null) {
                                break;
                            }
                            int indexOf = readLine.indexOf("@@");
                            if (indexOf != -1) {
                                synchronized (this.f59746a) {
                                    this.f59746a.put(readLine.substring(0, indexOf), readLine.substring(indexOf + 2));
                                }
                            }
                        } catch (IOException unused) {
                            bufferedReader = bufferedReader2;
                            if (bufferedReader != null) {
                                bufferedReader.close();
                            }
                            return;
                        } catch (Throwable th) {
                            th = th;
                            bufferedReader = bufferedReader2;
                            if (bufferedReader != null) {
                                try {
                                    bufferedReader.close();
                                } catch (IOException unused2) {
                                }
                            }
                            throw th;
                        }
                    }
                    bufferedReader2.close();
                } catch (IOException unused3) {
                }
            } catch (IOException unused4) {
            } catch (Throwable th2) {
                th = th2;
            }
        }
    }

    private void d(String str) {
        if (e(str)) {
            TaskManager.a().a((Task) new SkinWebTask(str, this));
        }
    }

    private boolean e(String str) {
        return true;
    }

    public WebResourceResponse a(String str) {
        String str2;
        InputStream open;
        WebResourceResponse webResourceResponse = null;
        if (str.endsWith(".jpg") || str.endsWith(".png") || str.contains("report") || c(str)) {
            return null;
        }
        synchronized (this.f59746a) {
            str2 = this.f59746a.get(str);
        }
        if (TextUtils.isEmpty(str2)) {
            d(str);
            return null;
        }
        try {
            File file = new File(b(), str2);
            if (file.exists()) {
                open = FileUtils.i(file);
            } else {
                open = FileUtils.g().open("skin/cache/" + str2);
            }
            if (open == null) {
                return null;
            }
            WebResourceResponse webResourceResponse2 = new WebResourceResponse(null, null, open);
            try {
                if (str2.contains(".js") || str2.contains(".css") ? System.currentTimeMillis() - file.lastModified() > DateUtils.ONE_HOUR : System.currentTimeMillis() - file.lastModified() > 43200000) {
                    d(str);
                }
                return webResourceResponse2;
            } catch (IOException unused) {
                webResourceResponse = webResourceResponse2;
                synchronized (this.f59746a) {
                    this.f59746a.remove(str);
                }
                return webResourceResponse;
            }
        } catch (IOException unused2) {
        }
    }

    public void a(final SkinWebListener skinWebListener) {
        new Handler(Looper.getMainLooper()).postDelayed(new Runnable() {
            @Override
            public void run() {
                if (skinWebListener == null || SkinWebCacheManager.this.f59747b.size() <= 0 || !SkinWebCacheManager.this.f59747b.contains(skinWebListener)) {
                    return;
                }
                SkinWebCacheManager.this.f59747b.remove(skinWebListener);
            }
        }, 100L);
    }

    public void c() {
        synchronized (this.f59746a) {
            this.f59746a.clear();
        }
        File b2 = b();
        if (b2 == null || !b2.exists()) {
            return;
        }
        try {
            FileUtils.a(b2);
        } catch (IOException unused) {
        }
    }

    @Override
    public void onTaskCompleted(Task task) {
        byte[] a2;
        if (!(task instanceof SkinWebTask) || (a2 = ((SkinWebTask) task).a()) == null || a2.length <= 0) {
            return;
        }
        a().a(task.getTaskUrl(), a2);
        if (!TextUtils.isEmpty(task.getTaskUrl()) && task.getTaskUrl().equals("http://mdc.imtt.qq.com/skin/getSkinData?tid=0&from=0&to=2") && PublicSettingManager.a().getBoolean("key_skin_web_first_flag", true)) {
            PublicSettingManager.a().setBoolean("key_skin_web_first_flag", false);
            Iterator<SkinWebListener> it = this.f59747b.iterator();
            while (it.hasNext()) {
                SkinWebListener next = it.next();
                if (next != null) {
                    next.f();
                }
            }
        }
    }

    @Override
    public void onTaskCreated(Task task) {
    }

    @Override
    public void onTaskExtEvent(Task task) {
    }

    @Override
    public void onTaskFailed(Task task) {
    }

    @Override
    public void onTaskProgress(Task task) {
    }

    @Override
    public void onTaskStarted(Task task) {
    }
}