package com.shizhuang.duapp.hybrid; import a.f; import android.net.Uri; import android.os.Bundle; import android.os.Looper; import android.text.TextUtils; import androidx.annotation.Nullable; import com.google.gson.internal.LinkedTreeMap; import com.meituan.robust.ChangeQuickRedirect; import com.meituan.robust.PatchProxy; import com.meituan.robust.PatchProxyResult; import com.meizu.cloud.pushsdk.constants.PushConstants; import com.shizhuang.duapp.common.helper.net.oss.OkHttpUtil; import com.shizhuang.duapp.hybrid.model.HtmlCacheModel; import com.shizhuang.duapp.hybrid.model.HtmlConfigModel; import com.shizhuang.duapp.hybrid.model.HtmlConfigResponse; import com.shizhuang.duapp.hybrid.model.HtmlPreloadModel; import com.shizhuang.duapp.hybrid.model.HtmlRequestItem; import com.shizhuang.duapp.hybrid.model.PreLoadAdvModel; import com.shizhuang.duapp.hybrid.request.HtmlInfo; import com.shizhuang.duapp.hybrid.request.ProgramsInfo; import com.shizhuang.duapp.hybrid.utils.DataGsonUtil; import com.shizhuang.duapp.hybrid.utils.FileUtil; import com.shizhuang.duapp.hybrid.utils.HeaderUtil; import com.shizhuang.duapp.hybrid.utils.StringUtil; import com.shizhuang.duapp.libs.bpm.BM; import com.shizhuang.duapp.modules.pay.R$styleable; import com.tencent.mmkv.MMKV; import df.i0; import fd.q; import gn1.a; import java.io.ByteArrayInputStream; import java.io.File; import java.io.IOException; import java.net.URLDecoder; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Queue; import java.util.Random; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.ScheduledFuture; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; import ji.b; import nd.e; import o5.i; import okhttp3.Call; import okhttp3.Callback; import okhttp3.Headers; import okhttp3.HttpUrl; import okhttp3.Request; import okhttp3.Response; import okhttp3.ResponseBody; import rd.k; import u.w; public class HtmlCacheManager { public static final Integer GET_PRELOAD_HTML_FAILED = 3; public static final Integer GET_PRELOAD_HTML_SUCCESS = 1; public static final Integer GET_PRELOAD_HTML_TIMEOUT = 2; private static final Long HOUR_MS = 3600000L; public static String TAG = "HtmlCacheManager"; public static ChangeQuickRedirect changeQuickRedirect; public static boolean concurrentLoad = false; private static volatile HtmlCacheManager mInstance; public static AtomicInteger semaphore = null; private Boolean cacheHtml = null; private final Runnable checkExpireRunnable = new Runnable() { /* class com.shizhuang.duapp.hybrid.HtmlCacheManager.AnonymousClass4 */ public static ChangeQuickRedirect changeQuickRedirect; public void run() { if (!PatchProxy.proxy(new Object[0], this, changeQuickRedirect, false, 17782, new Class[0], Void.TYPE).isSupported) { HtmlCacheManager.this.checkExpire(); } } }; private List<String> cleanHtmlWhitePage = new ArrayList(); private long defaultxpireTime = 300000; private final Queue<String> dnsList = new LinkedList(); public boolean dnsRequested = false; private long expireTime = 604800000; public ConcurrentHashMap<String, LinkedBlockingQueue<byte[]>> fetchingMap = new ConcurrentHashMap<>(); public ConcurrentHashMap<String, HashMap<String, String>> headersMap = new ConcurrentHashMap<>(); private ScheduledFuture hostKeepAliveTaskFuture = null; public final ConcurrentHashMap<String, HtmlCacheModel> htmlCachedMap = new ConcurrentHashMap<>(); private Boolean isPreloadOnRouter; private boolean mOnAppBackground; private List<PreLoadAdvModel> mPreLoadAdvModels = new ArrayList(); private final LinkedList<String> pendingTask = new LinkedList<>(); private final ConcurrentHashMap<String, PendingDownloadTask> pendingTaskMap = new ConcurrentHashMap<>(); public ConcurrentHashMap<String, HtmlPreloadModel> preloadRecordMap = new ConcurrentHashMap<>(); private long preloadTimeout = 2000; private int programLoadStatus; private ProgramsInfo programsInfo; public class DownLoadHtmlTask implements Runnable { public static ChangeQuickRedirect changeQuickRedirect; private final int requestType; private final String url; public DownLoadHtmlTask(String str, int i) { this.url = str; this.requestType = i; } private boolean isUrlValid(String str) { PatchProxyResult proxy = PatchProxy.proxy(new Object[]{str}, this, changeQuickRedirect, false, 17789, new Class[]{String.class}, Boolean.TYPE); if (proxy.isSupported) { return ((Boolean) proxy.result).booleanValue(); } try { HttpUrl.get(str); return true; } catch (Throwable th2) { HashMap hashMap = new HashMap(); hashMap.put("err_msg", th2.toString()); hashMap.put(PushConstants.WEB_URL, str); BM.app().j("h5").c("preload_url_illegal", hashMap); return false; } } public void run() { if (!PatchProxy.proxy(new Object[0], this, changeQuickRedirect, false, 17788, new Class[0], Void.TYPE).isSupported && !HtmlCacheManager.this.isBlackPage(this.url) && isUrlValid(this.url)) { HtmlCacheManager.this.doCacheHtml(this.url, this.requestType); } } } public class PendingDownloadTask implements Runnable { public static ChangeQuickRedirect changeQuickRedirect; private final HtmlInfo info; private final int requestType; public final String url; public PendingDownloadTask(String str, int i, HtmlInfo htmlInfo) { this.url = str; this.requestType = i; this.info = htmlInfo; } public void run() { if (!PatchProxy.proxy(new Object[0], this, changeQuickRedirect, false, 17790, new Class[0], Void.TYPE).isSupported) { HtmlCacheManager.this.download(this.info, this.requestType); } } } private HtmlCacheManager() { init(); } private void addPendingTask(PendingDownloadTask pendingDownloadTask) { if (!PatchProxy.proxy(new Object[]{pendingDownloadTask}, this, changeQuickRedirect, false, 17739, new Class[]{PendingDownloadTask.class}, Void.TYPE).isSupported) { synchronized (this.pendingTask) { this.pendingTask.addFirst(pendingDownloadTask.url); } this.pendingTaskMap.put(pendingDownloadTask.url, pendingDownloadTask); } } private void adjustPendingTask(String str) { if (!PatchProxy.proxy(new Object[]{str}, this, changeQuickRedirect, false, 17740, new Class[]{String.class}, Void.TYPE).isSupported) { synchronized (this.pendingTask) { if (this.pendingTask.remove(str)) { this.pendingTask.addFirst(str); } } } } private void deleteCacheNotInWhiteList(String str) { if (!PatchProxy.proxy(new Object[]{str}, this, changeQuickRedirect, false, 17723, new Class[]{String.class}, Void.TYPE).isSupported && htmlIsAvailable(str)) { HtmlCacheModel htmlCacheModel = this.htmlCachedMap.get(getMd5Str(getRealUrl(str))); if (htmlCacheModel != null) { deleteDiskCache(htmlCacheModel); } a.h(TAG).d("缓存有效但不在白名单内,删除缓存 urlKey=%s", getMd5Str(getRealUrl(str))); } } private void deleteDiskCache(final HtmlCacheModel htmlCacheModel) { if (!PatchProxy.proxy(new Object[]{htmlCacheModel}, this, changeQuickRedirect, false, 17752, new Class[]{HtmlCacheModel.class}, Void.TYPE).isSupported) { this.htmlCachedMap.remove(htmlCacheModel.getFileName()); HybridWorkHandler.getHandler().post(new Runnable() { /* class com.shizhuang.duapp.hybrid.HtmlCacheManager.AnonymousClass5 */ public static ChangeQuickRedirect changeQuickRedirect; public void run() { if (!PatchProxy.proxy(new Object[0], this, changeQuickRedirect, false, 17783, new Class[0], Void.TYPE).isSupported) { a.b h12 = a.h(HtmlCacheManager.TAG); StringBuilder h13 = f.h("deleteDiskCache expire url = "); h13.append(htmlCacheModel.getUrl()); h12.h(h13.toString(), new Object[0]); String path = htmlCacheModel.getPath(); if (!TextUtils.isEmpty(path)) { FileUtil.deleteFileSafely(new File(path)); } } } }); } } public static String getHostPathUrl(String str) { PatchProxyResult proxy = PatchProxy.proxy(new Object[]{str}, null, changeQuickRedirect, true, 17766, new Class[]{String.class}, String.class); if (proxy.isSupported) { return (String) proxy.result; } if (TextUtils.isEmpty(str)) { return ""; } return str.split("\\?")[0].split("&")[0]; } private HtmlCacheModel getHtmlCacheModelByHtmlConfigModel(String str) { PatchProxyResult proxy = PatchProxy.proxy(new Object[]{str}, this, changeQuickRedirect, false, 17748, new Class[]{String.class}, HtmlCacheModel.class); if (proxy.isSupported) { return (HtmlCacheModel) proxy.result; } if (!this.htmlCachedMap.isEmpty() && !TextUtils.isEmpty(str)) { for (HtmlCacheModel htmlCacheModel : this.htmlCachedMap.values()) { if (!TextUtils.isEmpty(htmlCacheModel.getUrl()) && htmlCacheModel.getUrl().contains(str)) { return htmlCacheModel; } } } return null; } public static HtmlCacheManager getInstance() { PatchProxyResult proxy = PatchProxy.proxy(new Object[0], null, changeQuickRedirect, true, 17714, new Class[0], HtmlCacheManager.class); if (proxy.isSupported) { return (HtmlCacheManager) proxy.result; } if (mInstance == null) { synchronized (HtmlCacheManager.class) { if (mInstance == null) { mInstance = new HtmlCacheManager(); } } } return mInstance; } private String getMd5Str(String str) { PatchProxyResult proxy = PatchProxy.proxy(new Object[]{str}, this, changeQuickRedirect, false, 17757, new Class[]{String.class}, String.class); return proxy.isSupported ? (String) proxy.result : StringUtil.getMD5(str); } private int getPermits() { PatchProxyResult proxy = PatchProxy.proxy(new Object[0], this, changeQuickRedirect, false, 17719, new Class[0], Integer.TYPE); if (proxy.isSupported) { return ((Integer) proxy.result).intValue(); } int i = this.programsInfo.maxConcurrentCount; if (i == 0) { return 2; } return i; } private String getPointPageType(String str) { PatchProxyResult proxy = PatchProxy.proxy(new Object[]{str}, this, changeQuickRedirect, false, 17737, new Class[]{String.class}, String.class); if (proxy.isSupported) { return (String) proxy.result; } String[] split = str.split("&"); for (String str2 : split) { if (str2.startsWith("pointPageType")) { String[] split2 = str2.split("="); if (split2.length > 1) { return split2[1]; } } } return ""; } public static String getRealUrl(String str) { PatchProxyResult proxy = PatchProxy.proxy(new Object[]{str}, null, changeQuickRedirect, true, 17765, new Class[]{String.class}, String.class); if (proxy.isSupported) { return (String) proxy.result; } if (TextUtils.isEmpty(str)) { return ""; } if (!str.contains("?")) { return str.split("&")[0]; } return str.contains("&pointPageType") ? str.substring(0, str.indexOf("&pointPageType")) : str; } private void init() { if (!PatchProxy.proxy(new Object[0], this, changeQuickRedirect, false, 17713, new Class[0], Void.TYPE).isSupported) { initHtmlConfig(); } } private void initHtmlConfig() { LinkedTreeMap linkedTreeMap; if (!PatchProxy.proxy(new Object[0], this, changeQuickRedirect, false, 17745, new Class[0], Void.TYPE).isSupported) { String string = MMKV.defaultMMKV(2, null).getString("HTML_CONFIG_KEY", ""); if (!TextUtils.isEmpty(string) && (linkedTreeMap = (LinkedTreeMap) e.h(string, e.l(String.class, HtmlCacheModel.class))) != null) { this.htmlCachedMap.putAll(linkedTreeMap); } updateConfigs(); } } private boolean isCacheHtml() { PatchProxyResult proxy = PatchProxy.proxy(new Object[0], this, changeQuickRedirect, false, 17763, new Class[0], Boolean.TYPE); if (proxy.isSupported) { return ((Boolean) proxy.result).booleanValue(); } return true; } private boolean isPreloadOnRouter() { PatchProxyResult proxy = PatchProxy.proxy(new Object[0], this, changeQuickRedirect, false, 17731, new Class[0], Boolean.TYPE); if (proxy.isSupported) { return ((Boolean) proxy.result).booleanValue(); } Boolean bool = this.isPreloadOnRouter; if (bool != null) { return bool.booleanValue(); } if (!DuHybrid.hasInstance()) { return false; } float floatValue = ((Float) DuHybrid.getInstance().getRemoteConfig("preload_on_router_range2", Float.TYPE, Float.valueOf((float) i.f36333a))).floatValue(); this.isPreloadOnRouter = Boolean.valueOf(new Random().nextFloat() < floatValue); a.h(TAG).a("preload_on_router_range ::: %s isPreloadOnRouter ::: %s", Float.valueOf(floatValue), this.isPreloadOnRouter); return this.isPreloadOnRouter.booleanValue(); } /* access modifiers changed from: private */ public /* synthetic */ boolean lambda$null$0() { PatchProxyResult proxy = PatchProxy.proxy(new Object[0], this, changeQuickRedirect, false, 17775, new Class[0], Boolean.TYPE); if (proxy.isSupported) { return ((Boolean) proxy.result).booleanValue(); } try { if (this.dnsList.size() > 0) { final String poll = this.dnsList.poll(); q.a(new Runnable() { /* class com.shizhuang.duapp.hybrid.HtmlCacheManager.AnonymousClass1 */ public static ChangeQuickRedirect changeQuickRedirect; public void run() { if (!PatchProxy.proxy(new Object[0], this, changeQuickRedirect, false, 17776, new Class[0], Void.TYPE).isSupported) { HtmlCacheManager.this.getWebDataAsyn(poll, null, null, true); } } }); } } catch (Exception e) { e.printStackTrace(); } return !this.dnsList.isEmpty(); } /* access modifiers changed from: private */ public static /* synthetic */ int lambda$setPreLoadAdvData$2(PreLoadAdvModel preLoadAdvModel, PreLoadAdvModel preLoadAdvModel2) { PatchProxyResult proxy = PatchProxy.proxy(new Object[]{preLoadAdvModel, preLoadAdvModel2}, null, changeQuickRedirect, true, 17773, new Class[]{PreLoadAdvModel.class, PreLoadAdvModel.class}, Integer.TYPE); return proxy.isSupported ? ((Integer) proxy.result).intValue() : (int) (preLoadAdvModel.effectiveTime - preLoadAdvModel2.effectiveTime); } /* access modifiers changed from: private */ public /* synthetic */ void lambda$setProgramsInfo$1() { if (!PatchProxy.proxy(new Object[0], this, changeQuickRedirect, false, 17774, new Class[0], Void.TYPE).isSupported) { Looper.myQueue().addIdleHandler(new b(this)); } } private void makeHostSocketAlwaysAlive(ProgramsInfo.KeepConnectionHostConfig keepConnectionHostConfig) { ScheduledFuture<?> scheduledFuture; if (!PatchProxy.proxy(new Object[]{keepConnectionHostConfig}, this, changeQuickRedirect, false, 17769, new Class[]{ProgramsInfo.KeepConnectionHostConfig.class}, Void.TYPE).isSupported && keepConnectionHostConfig != null && keepConnectionHostConfig.getHosts() != null && keepConnectionHostConfig.getHosts().size() != 0) { ScheduledFuture scheduledFuture2 = this.hostKeepAliveTaskFuture; if (scheduledFuture2 != null && !scheduledFuture2.isCancelled()) { this.hostKeepAliveTaskFuture.cancel(false); } final ArrayList arrayList = new ArrayList(keepConnectionHostConfig.getHosts()); AnonymousClass8 r112 = new Runnable() { /* class com.shizhuang.duapp.hybrid.HtmlCacheManager.AnonymousClass8 */ public static ChangeQuickRedirect changeQuickRedirect; public void run() { if (!PatchProxy.proxy(new Object[0], this, changeQuickRedirect, false, 17787, new Class[0], Void.TYPE).isSupported) { Iterator it2 = arrayList.iterator(); while (it2.hasNext()) { HtmlCacheManager.this.getWebDataAsyn((String) it2.next(), null, null, true); } } } }; long max = Math.max(60000L, keepConnectionHostConfig.getWorkInterval()); TimeUnit timeUnit = TimeUnit.MILLISECONDS; ChangeQuickRedirect changeQuickRedirect2 = q.changeQuickRedirect; Object[] objArr = {r112, new Long(0), new Long(max), timeUnit}; ChangeQuickRedirect changeQuickRedirect3 = q.changeQuickRedirect; Class cls = Long.TYPE; PatchProxyResult proxy = PatchProxy.proxy(objArr, null, changeQuickRedirect3, true, 4225, new Class[]{Runnable.class, cls, cls, TimeUnit.class}, ScheduledFuture.class); if (proxy.isSupported) { scheduledFuture = (ScheduledFuture) proxy.result; } else if (q.b) { scheduledFuture = q.n(r112, 0, max, timeUnit); } else { try { scheduledFuture = new p4.e(1, q.j(), "com.shizhuang.duapp.common.helper.DuThreadPool", true).scheduleAtFixedRate(r112, 0, max, timeUnit); } catch (Exception e) { e.printStackTrace(); scheduledFuture = null; } } this.hostKeepAliveTaskFuture = scheduledFuture; } } private void preLoadAdvHtml() { List<PreLoadAdvModel> list; if (!(PatchProxy.proxy(new Object[0], this, changeQuickRedirect, false, 17716, new Class[0], Void.TYPE).isSupported || (list = this.mPreLoadAdvModels) == null || list.size() == 0)) { for (PreLoadAdvModel preLoadAdvModel : this.mPreLoadAdvModels) { if (preLoadAdvModel != null) { String str = preLoadAdvModel.routerUrl; if (!TextUtils.isEmpty(str) && str.contains("/router/web/BrowserPage")) { try { String decode = URLDecoder.decode(str.replace("https://m.poizon.com/router/web/BrowserPage?loadUrl=", ""), "utf-8"); if (!decode.contains("router/product/BoutiqueRecommendDetailPage")) { forceLoadHtml(decode, preLoadAdvModel.effectiveTime, this.mOnAppBackground); } else { return; } } catch (Exception e) { e.printStackTrace(); } } else { return; } } } } } private void preLoadRecallHtml() { if (!PatchProxy.proxy(new Object[0], this, changeQuickRedirect, false, 17717, new Class[0], Void.TYPE).isSupported) { ProgramsInfo programsInfo2 = getProgramsInfo(); this.programsInfo = programsInfo2; if (!(programsInfo2 == null || programsInfo2.getRecallPages() == null || this.programsInfo.getRecallPages().size() < 1)) { for (String str : this.programsInfo.getRecallPages()) { if (htmlIsAvailable(str)) { a.h(TAG).a("缓存有效 urlKey=%s", getMd5Str(getRealUrl(str))); } else { q.a(new DownLoadHtmlTask(str, 4)); } } } } } private void tracePreAndUpdate(Integer num, Integer num2, String str, Integer num3) { if (!PatchProxy.proxy(new Object[]{num, num2, str, num3}, this, changeQuickRedirect, false, 17736, new Class[]{Integer.class, Integer.class, String.class, Integer.class}, Void.TYPE).isSupported) { try { String decode = URLDecoder.decode(str, "utf-8"); String pointPageType = getPointPageType(decode); HashMap hashMap = new HashMap(); hashMap.put(PushConstants.WEB_URL, getRealUrl(decode)); hashMap.put("type", String.valueOf(num3)); hashMap.put("point_page_type", pointPageType); hashMap.put("point_entry_position", String.valueOf(num2)); hashMap.put("point_entry_source_type", String.valueOf(num)); BM.app().j("h5").c("preload_request", hashMap); } catch (Exception e) { e.printStackTrace(); } } } private void updateConfigs() { String str; if (!PatchProxy.proxy(new Object[0], this, changeQuickRedirect, false, 17746, new Class[0], Void.TYPE).isSupported) { String f = qc.f.f(); if (f.endsWith("/")) { str = a40.f.g(f, "api/v1/app/wireless-platform/offline-resource/page-info"); } else { str = a40.f.g(f, "/api/v1/app/wireless-platform/offline-resource/page-info"); } Set<String> keySet = this.htmlCachedMap.keySet(); HashSet hashSet = new HashSet(); ArrayList arrayList = new ArrayList(); for (String str2 : keySet) { HtmlCacheModel htmlCacheModel = this.htmlCachedMap.get(str2); if (htmlCacheModel != null && !TextUtils.isEmpty(htmlCacheModel.getUrl())) { hashSet.add(htmlCacheModel.getUrl()); } } Iterator it2 = hashSet.iterator(); while (it2.hasNext()) { arrayList.add(new HtmlRequestItem(getHostPathUrl((String) it2.next()))); } HashMap hashMap = new HashMap(); hashMap.put("pageList", arrayList); OkHttpUtil.b().c(str, hashMap, new OkHttpUtil.NetCall() { /* class com.shizhuang.duapp.hybrid.HtmlCacheManager.AnonymousClass3 */ public static ChangeQuickRedirect changeQuickRedirect; @Override // com.shizhuang.duapp.common.helper.net.oss.OkHttpUtil.NetCall public void failed(Call call, IOException iOException) { boolean z = PatchProxy.proxy(new Object[]{call, iOException}, this, changeQuickRedirect, false, 17781, new Class[]{Call.class, IOException.class}, Void.TYPE).isSupported; } @Override // com.shizhuang.duapp.common.helper.net.oss.OkHttpUtil.NetCall public void success(Call call, @Nullable Response response) throws IOException { HtmlConfigModel htmlConfigModel; if (!PatchProxy.proxy(new Object[]{call, response}, this, changeQuickRedirect, false, 17780, new Class[]{Call.class, Response.class}, Void.TYPE).isSupported && response != null && response.isSuccessful() && response.body() != null) { HtmlConfigResponse htmlConfigResponse = null; try { htmlConfigResponse = (HtmlConfigResponse) e.f(response.body().string(), HtmlConfigResponse.class); } catch (Throwable th2) { th2.printStackTrace(); } if (htmlConfigResponse != null && htmlConfigResponse.code == 200 && (htmlConfigModel = htmlConfigResponse.data) != null) { HtmlCacheManager.this.updatePage(htmlConfigModel); } } } }); } } private boolean validateInPreLoadWhiteHost(String str) { ProgramsInfo.PreloadConfig preloadConfig; PatchProxyResult proxy = PatchProxy.proxy(new Object[]{str}, this, changeQuickRedirect, false, 17724, new Class[]{String.class}, Boolean.TYPE); if (proxy.isSupported) { return ((Boolean) proxy.result).booleanValue(); } ProgramsInfo programsInfo2 = getProgramsInfo(); this.programsInfo = programsInfo2; if (programsInfo2 == null || (preloadConfig = programsInfo2.preloadConfig) == null || preloadConfig.inBlackList(str)) { return false; } if (this.programsInfo.preloadConfig.inWhiteHost(str)) { return true; } a.h(TAG).d("不在白名单内不下载HTML,urlKey=%s", getMd5Str(getRealUrl(str))); deleteCacheNotInWhiteList(str); return false; } private boolean validateInPreLoadWhitePage(String str) { PatchProxyResult proxy = PatchProxy.proxy(new Object[]{str}, this, changeQuickRedirect, false, 17722, new Class[]{String.class}, Boolean.TYPE); if (proxy.isSupported) { return ((Boolean) proxy.result).booleanValue(); } if (this.programsInfo.inPreLoadWhitePage(str)) { return true; } a.h(TAG).d("不在白名单内不下载HTML,urlKey=%s", getMd5Str(getRealUrl(str))); deleteCacheNotInWhiteList(str); return false; } @Deprecated public void cacheHtml(int i, int i3, String str) { } public void cacheToDisk(HtmlInfo htmlInfo, final HtmlCacheModel htmlCacheModel) { if (!PatchProxy.proxy(new Object[]{htmlInfo, htmlCacheModel}, this, changeQuickRedirect, false, 17753, new Class[]{HtmlInfo.class, HtmlCacheModel.class}, Void.TYPE).isSupported) { final File file = new File(htmlInfo.path); if (file.exists() && !file.isDirectory()) { file.delete(); } HybridWorkHandler.getHandler().post(new Runnable() { /* class com.shizhuang.duapp.hybrid.HtmlCacheManager.AnonymousClass6 */ public static ChangeQuickRedirect changeQuickRedirect; public void run() { if (!PatchProxy.proxy(new Object[0], this, changeQuickRedirect, false, 17784, new Class[0], Void.TYPE).isSupported) { FileUtil.writeFileFromIS(file, new ByteArrayInputStream(htmlCacheModel.getFileData()), false); HtmlCacheManager.this.saveHtmlConfig(); } } }); } } public void checkExpire() { if (!PatchProxy.proxy(new Object[0], this, changeQuickRedirect, false, 17751, new Class[0], Void.TYPE).isSupported) { a.h(TAG).a("HtmlCacheManager checkExpire() --start", new Object[0]); if (!this.htmlCachedMap.isEmpty()) { long j = Long.MAX_VALUE; for (String str : this.htmlCachedMap.keySet()) { HtmlCacheModel htmlCacheModel = this.htmlCachedMap.get(str); if (htmlCacheModel != null) { if (htmlCacheModel.expireTime < System.currentTimeMillis()) { deleteDiskCache(htmlCacheModel); } else { j = Math.min(j, htmlCacheModel.expireTime); } } } long currentTimeMillis = j - System.currentTimeMillis(); if (currentTimeMillis <= 0) { currentTimeMillis = 60000; } saveHtmlConfig(); HybridWorkHandler.getHandler().removeCallbacks(this.checkExpireRunnable); HybridWorkHandler.getHandler().postDelayed(this.checkExpireRunnable, currentTimeMillis); } } } public void clearMemoryCache() { if (!PatchProxy.proxy(new Object[0], this, changeQuickRedirect, false, 17720, new Class[0], Void.TYPE).isSupported) { this.htmlCachedMap.clear(); } } public void doCacheHtml(String str, int i) { AtomicInteger atomicInteger; if (!PatchProxy.proxy(new Object[]{str, new Integer(i)}, this, changeQuickRedirect, false, 17738, new Class[]{String.class, Integer.TYPE}, Void.TYPE).isSupported && HybridPathManager.installed() && !TextUtils.isEmpty(str)) { String trim = str.trim(); HtmlInfo htmlInfo = new HtmlInfo(); htmlInfo.originalUrl = trim; String realUrl = getRealUrl(trim); htmlInfo.downloadUrl = realUrl; if (!TextUtils.isEmpty(realUrl)) { htmlInfo.name = getMd5Str(htmlInfo.downloadUrl); htmlInfo.path = HybridPathManager.require().getTargetOfflineHtmlDir().getAbsolutePath() + "/" + htmlInfo.name; if ((i == 4 || i == 1) && (atomicInteger = semaphore) != null && atomicInteger.get() >= getPermits()) { addPendingTask(new PendingDownloadTask(trim, i, htmlInfo)); return; } a.h(TAG).d("当前线程:=%s,requestType=%d,获取许可证成功 urlKey=%s", Thread.currentThread().getName(), Integer.valueOf(i), getMd5Str(getRealUrl(trim))); semaphore.incrementAndGet(); download(htmlInfo, i); } } } public void doNextTask() { String poll; if (!PatchProxy.proxy(new Object[0], this, changeQuickRedirect, false, 17742, new Class[0], Void.TYPE).isSupported) { synchronized (this.pendingTask) { poll = this.pendingTask.poll(); } PendingDownloadTask pendingDownloadTask = null; if (poll != null) { pendingDownloadTask = this.pendingTaskMap.remove(poll); } if (pendingDownloadTask == null) { semaphore.decrementAndGet(); } else { q.a(pendingDownloadTask); } } } public void download(final HtmlInfo htmlInfo, final int i) { if (!PatchProxy.proxy(new Object[]{htmlInfo, new Integer(i)}, this, changeQuickRedirect, false, 17741, new Class[]{HtmlInfo.class, Integer.TYPE}, Void.TYPE).isSupported) { final long currentTimeMillis = System.currentTimeMillis(); a.h(TAG).a("HtmlCacheManager doCacheHtml(): url=%s", htmlInfo.downloadUrl); this.fetchingMap.put(htmlInfo.downloadUrl, new LinkedBlockingQueue<>(16)); HashMap hashMap = new HashMap(HeaderUtil.getRiskHeaders()); ConcurrentHashMap<String, HtmlPreloadModel> concurrentHashMap = this.preloadRecordMap; String str = htmlInfo.downloadUrl; concurrentHashMap.put(str, new HtmlPreloadModel(str)); if (i == 3) { hashMap.put("requestType", "concurrent"); } hashMap.put("traceid", HeaderUtil.getTraceId(htmlInfo.originalUrl)); if (!HeaderUtil.isLogin()) { hashMap.put("visitorid", HeaderUtil.getVisitorId()); } HtmlCacheModel htmlCacheModel = this.htmlCachedMap.get(htmlInfo.name); if (!(htmlCacheModel == null || htmlCacheModel.getHeaderMap() == null)) { hashMap.put("If-None-Match", htmlCacheModel.getHeaderMap().get("ETag") != null ? htmlCacheModel.getHeaderMap().get("ETag") : ""); } getWebDataAsyn(htmlInfo.downloadUrl, new OkHttpUtil.NetCall() { /* class com.shizhuang.duapp.hybrid.HtmlCacheManager.AnonymousClass2 */ public static ChangeQuickRedirect changeQuickRedirect; private void onComplete(IOException iOException) { if (!PatchProxy.proxy(new Object[]{iOException}, this, changeQuickRedirect, false, 17779, new Class[]{IOException.class}, Void.TYPE).isSupported) { int i = i; if ((i == 4 || i == 1) && HtmlCacheManager.semaphore != null) { a.h(HtmlCacheManager.TAG).d("当前线程:=%s,requestType=%d,释放许可证成功 urlKey=%s", Thread.currentThread().getName(), Integer.valueOf(i), htmlInfo.name); HtmlCacheManager.this.doNextTask(); } HtmlPreloadModel htmlPreloadModel = HtmlCacheManager.this.preloadRecordMap.get(htmlInfo.downloadUrl); if (htmlPreloadModel != null) { htmlPreloadModel.setCostTime(Long.valueOf(System.currentTimeMillis() - currentTimeMillis)); if (iOException != null) { htmlPreloadModel.setErrMsg(iOException.getMessage()); htmlPreloadModel.setStatus(HtmlCacheManager.GET_PRELOAD_HTML_FAILED); } else { htmlPreloadModel.setStatus(HtmlCacheManager.GET_PRELOAD_HTML_SUCCESS); } HtmlCacheManager.this.traceDownLoadHtml(htmlPreloadModel); } HtmlCacheManager.this.fetchingMap.remove(htmlInfo.downloadUrl); a.h(HtmlCacheManager.TAG).a("HtmlCacheManager doCacheHtml() onComplete(): HtmlPreloadModel=%s", e.n(htmlPreloadModel)); } } @Override // com.shizhuang.duapp.common.helper.net.oss.OkHttpUtil.NetCall public void failed(Call call, IOException iOException) { if (!PatchProxy.proxy(new Object[]{call, iOException}, this, changeQuickRedirect, false, 17778, new Class[]{Call.class, IOException.class}, Void.TYPE).isSupported) { onComplete(iOException); } } @Override // com.shizhuang.duapp.common.helper.net.oss.OkHttpUtil.NetCall public void success(Call call, @Nullable Response response) { if (!PatchProxy.proxy(new Object[]{call, response}, this, changeQuickRedirect, false, 17777, new Class[]{Call.class, Response.class}, Void.TYPE).isSupported) { HtmlPreloadModel htmlPreloadModel = HtmlCacheManager.this.preloadRecordMap.get(htmlInfo.downloadUrl); if (!(response == null || htmlPreloadModel == null)) { htmlPreloadModel.setHttpCode(Integer.valueOf(response.code())); } if (response == null || !response.isSuccessful()) { if (response == null || response.code() != 304) { failed(call, new IOException("response == null || !response.isSuccessful()")); } else { onComplete(null); } if (response != null) { try { if (response.body() != null) { response.body().close(); } } catch (Throwable unused) { } } } else if (response.body() == null) { failed(call, new IOException("response.body() == null")); } else { try { byte[] bytes = response.body().bytes(); HtmlCacheManager htmlCacheManager = HtmlCacheManager.this; htmlCacheManager.headersMap.put(htmlInfo.name, htmlCacheManager.headersToMap(response.headers())); HtmlCacheModel htmlCacheModel = HtmlCacheManager.this.getHtmlCacheModel(htmlInfo.downloadUrl); htmlCacheModel.setFileData(bytes); htmlCacheModel.setHeaderMap(HtmlCacheManager.this.headersToMap(response.headers())); HtmlCacheManager.this.htmlCachedMap.put(htmlInfo.name, htmlCacheModel); LinkedBlockingQueue<byte[]> linkedBlockingQueue = HtmlCacheManager.this.fetchingMap.get(htmlInfo.downloadUrl); a.h(HtmlCacheManager.TAG).a("HtmlCacheManager doCacheHtml() success(): data.length=%s", Integer.valueOf(bytes.length)); if (linkedBlockingQueue != null) { linkedBlockingQueue.offer(bytes); } onComplete(null); HtmlCacheManager.this.cacheToDisk(htmlInfo, htmlCacheModel); HtmlCacheEnhancer.getInstance().preloadHtmlResource(i, htmlCacheModel); } catch (IOException e) { failed(call, e); e.printStackTrace(); } } } } }, hashMap, false); } } public void forceLoadHtml(String str, long j, boolean z) { if (!PatchProxy.proxy(new Object[]{str, new Long(j), new Byte(z ? (byte) 1 : 0)}, this, changeQuickRedirect, false, 17721, new Class[]{String.class, Long.TYPE, Boolean.TYPE}, Void.TYPE).isSupported) { ProgramsInfo programsInfo2 = getProgramsInfo(); this.programsInfo = programsInfo2; if (programsInfo2 != null && programsInfo2.preLoadAd != 0 && validateInPreLoadWhitePage(str)) { if ((j * 1000) - System.currentTimeMillis() < HOUR_MS.longValue() * ((long) this.programsInfo.maxPreLoadTime)) { if (htmlIsAvailable(str)) { a.h(TAG).d("缓存有效 urlKey=%s", getMd5Str(getRealUrl(str))); return; } q.a(new DownLoadHtmlTask(str, 4)); tracePreAndUpdate(null, null, str, Integer.valueOf(z ? R$styleable.AppCompatTheme_textAppearanceListItem : 100)); } } } } public Long getDuration(String str) { PatchProxyResult proxy = PatchProxy.proxy(new Object[]{str}, this, changeQuickRedirect, false, 17762, new Class[]{String.class}, Long.class); if (proxy.isSupported) { return (Long) proxy.result; } HtmlPreloadModel htmlPreloadModel = this.preloadRecordMap.get(getRealUrl(str)); if (htmlPreloadModel == null) { return null; } return htmlPreloadModel.getCostTime(); } public HashMap<String, String> getHeaderMap(String str) { PatchProxyResult proxy = PatchProxy.proxy(new Object[]{str}, this, changeQuickRedirect, false, 17767, new Class[]{String.class}, HashMap.class); if (proxy.isSupported) { return (HashMap) proxy.result; } HashMap<String, String> hashMap = this.headersMap.get(str); return hashMap == null ? new HashMap<>() : hashMap; } public HtmlCacheModel getHtmlCacheModel(String str) { PatchProxyResult proxy = PatchProxy.proxy(new Object[]{str}, this, changeQuickRedirect, false, 17747, new Class[]{String.class}, HtmlCacheModel.class); if (proxy.isSupported) { return (HtmlCacheModel) proxy.result; } HtmlCacheModel htmlCacheModel = new HtmlCacheModel(); htmlCacheModel.setUrl(str); long currentTimeMillis = System.currentTimeMillis(); htmlCacheModel.cacheTime = currentTimeMillis; htmlCacheModel.expireTime = this.defaultxpireTime + currentTimeMillis; ProgramsInfo programsInfo2 = this.programsInfo; if (programsInfo2 != null) { htmlCacheModel.expireTime = programsInfo2.getExpireTimeByUrl(str) + currentTimeMillis; } htmlCacheModel.modifyTime = htmlCacheModel.cacheTime; return htmlCacheModel; } public byte[] getHtmlData(String str) { PatchProxyResult proxy = PatchProxy.proxy(new Object[]{str}, this, changeQuickRedirect, false, 17756, new Class[]{String.class}, byte[].class); if (proxy.isSupported) { return (byte[]) proxy.result; } String md5Str = getMd5Str(getRealUrl(str)); if (this.htmlCachedMap.containsKey(md5Str)) { a.h(TAG).a("HtmlCacheManager getHtmlData() 从htmlCachedMap获取", new Object[0]); HtmlCacheModel htmlCacheModel = this.htmlCachedMap.get(md5Str); if (htmlCacheModel != null) { return htmlCacheModel.getFileData(); } } if (htmlIsFetching(str)) { try { LinkedBlockingQueue<byte[]> linkedBlockingQueue = this.fetchingMap.get(str); if (linkedBlockingQueue != null) { long currentTimeMillis = System.currentTimeMillis(); a.h(TAG).a("HtmlCacheManager getHtmlData() 阻塞获取正在请求的数据-等待", new Object[0]); byte[] poll = linkedBlockingQueue.poll(this.preloadTimeout, TimeUnit.MILLISECONDS); a.h(TAG).a("HtmlCacheManager getHtmlData() 阻塞获取正在请求的数据-已获取, 阻塞时间:%s", Long.valueOf(System.currentTimeMillis() - currentTimeMillis)); if (poll != null) { return poll; } HtmlPreloadModel htmlPreloadModel = this.preloadRecordMap.get(str); if (htmlPreloadModel != null) { htmlPreloadModel.setStatus(GET_PRELOAD_HTML_TIMEOUT); a.h(TAG).a("HtmlCacheManager getHtmlData() 阻塞超时---超时时间:%s", Long.valueOf(this.preloadTimeout)); } } } catch (Exception e) { e.printStackTrace(); } } HtmlCacheModel htmlCacheModel2 = this.htmlCachedMap.get(md5Str); if (htmlCacheModel2 != null) { a.h(TAG).a("HtmlCacheManager getHtmlData() 二次从htmlCachedMap获取", new Object[0]); return htmlCacheModel2.getFileData(); } a.h(TAG).a("HtmlCacheManager getHtmlData() 获取 null ", new Object[0]); return null; } public HtmlPreloadModel getPreloadRecord(String str) { PatchProxyResult proxy = PatchProxy.proxy(new Object[]{str}, this, changeQuickRedirect, false, 17711, new Class[]{String.class}, HtmlPreloadModel.class); if (proxy.isSupported) { return (HtmlPreloadModel) proxy.result; } return this.preloadRecordMap.get(getRealUrl(str)); } public int getProgramLoadStatus() { PatchProxyResult proxy = PatchProxy.proxy(new Object[0], this, changeQuickRedirect, false, 17733, new Class[0], Integer.TYPE); return proxy.isSupported ? ((Integer) proxy.result).intValue() : this.programLoadStatus; } public ProgramsInfo getProgramsInfo() { PatchProxyResult proxy = PatchProxy.proxy(new Object[0], this, changeQuickRedirect, false, 17718, new Class[0], ProgramsInfo.class); if (proxy.isSupported) { return (ProgramsInfo) proxy.result; } if (this.programsInfo == null) { String string = MMKV.defaultMMKV(2, null).getString("programInfo", ""); if (!TextUtils.isEmpty(string)) { this.programsInfo = (ProgramsInfo) DataGsonUtil.stringToData(string, ProgramsInfo.class); } } if (semaphore == null && this.programsInfo != null) { semaphore = new AtomicInteger(); } return this.programsInfo; } public void getWebDataAsyn(String str, final OkHttpUtil.NetCall netCall, Map<String, String> map, boolean z) { if (!PatchProxy.proxy(new Object[]{str, netCall, map, new Byte(z ? (byte) 1 : 0)}, this, changeQuickRedirect, false, 17768, new Class[]{String.class, OkHttpUtil.NetCall.class, Map.class, Boolean.TYPE}, Void.TYPE).isSupported) { try { Request.Builder builder = new Request.Builder(); if (map != null && !map.isEmpty()) { for (Map.Entry<String, String> entry : map.entrySet()) { builder.addHeader(entry.getKey(), entry.getValue()); } } if (z) { builder.head(); } else { builder.get(); } k.e().k().newCall(builder.url(str).build()).enqueue(new Callback() { /* class com.shizhuang.duapp.hybrid.HtmlCacheManager.AnonymousClass7 */ public static ChangeQuickRedirect changeQuickRedirect; @Override // okhttp3.Callback public void onFailure(Call call, IOException iOException) { OkHttpUtil.NetCall netCall; if (!PatchProxy.proxy(new Object[]{call, iOException}, this, changeQuickRedirect, false, 17785, new Class[]{Call.class, IOException.class}, Void.TYPE).isSupported && (netCall = netCall) != null) { netCall.failed(call, iOException); } } @Override // okhttp3.Callback public void onResponse(Call call, Response response) throws IOException { if (!PatchProxy.proxy(new Object[]{call, response}, this, changeQuickRedirect, false, 17786, new Class[]{Call.class, Response.class}, Void.TYPE).isSupported) { OkHttpUtil.NetCall netCall = netCall; if (netCall != null) { netCall.success(call, response); return; } try { ResponseBody body = response.body(); if (body != null) { body.close(); } } catch (Exception unused) { } } } }); } catch (Throwable th2) { HashMap hashMap = new HashMap(); hashMap.put("err_msg", th2.toString()); hashMap.put(PushConstants.WEB_URL, str); BM.app().j("h5").c("preload_url_exception", hashMap); } } } public HashMap<String, String> headersToMap(Headers headers) { PatchProxyResult proxy = PatchProxy.proxy(new Object[]{headers}, this, changeQuickRedirect, false, 17755, new Class[]{Headers.class}, HashMap.class); if (proxy.isSupported) { return (HashMap) proxy.result; } HashMap<String, String> hashMap = new HashMap<>(); try { for (String str : headers.names()) { if ("ETag".equalsIgnoreCase(str)) { hashMap.put("ETag", headers.get(str)); } else { hashMap.put(str, headers.get(str)); } } } catch (Exception e) { e.printStackTrace(); } return hashMap; } public boolean htmlIsAvailable(String str) { boolean z = true; PatchProxyResult proxy = PatchProxy.proxy(new Object[]{str}, this, changeQuickRedirect, false, 17761, new Class[]{String.class}, Boolean.TYPE); if (proxy.isSupported) { return ((Boolean) proxy.result).booleanValue(); } HtmlCacheModel htmlCacheModel = this.htmlCachedMap.get(getMd5Str(getRealUrl(str))); if (htmlCacheModel == null) { return false; } long j = htmlCacheModel.cacheTime; long j12 = this.defaultxpireTime + j; ProgramsInfo programsInfo2 = this.programsInfo; if (programsInfo2 != null) { j12 = programsInfo2.getExpireTimeByUrl(str) + j; } if (System.currentTimeMillis() >= j12) { z = false; } if (!z) { deleteDiskCache(htmlCacheModel); } return z; } public boolean htmlIsFetching(String str) { PatchProxyResult proxy = PatchProxy.proxy(new Object[]{str}, this, changeQuickRedirect, false, 17760, new Class[]{String.class}, Boolean.TYPE); if (proxy.isSupported) { return ((Boolean) proxy.result).booleanValue(); } return this.fetchingMap.containsKey(getRealUrl(str)); } public boolean htmlIsPending(String str) { PatchProxyResult proxy = PatchProxy.proxy(new Object[]{str}, this, changeQuickRedirect, false, 17759, new Class[]{String.class}, Boolean.TYPE); return proxy.isSupported ? ((Boolean) proxy.result).booleanValue() : this.pendingTaskMap.containsKey(str); } public boolean isBlackPage(String str) { PatchProxyResult proxy = PatchProxy.proxy(new Object[]{str}, this, changeQuickRedirect, false, 17743, new Class[]{String.class}, Boolean.TYPE); if (proxy.isSupported) { return ((Boolean) proxy.result).booleanValue(); } ProgramsInfo programsInfo2 = getProgramsInfo(); this.programsInfo = programsInfo2; if (programsInfo2 == null) { return true; } if (!programsInfo2.inBlackPageList(str)) { return false; } HtmlCacheModel htmlCacheModel = this.htmlCachedMap.get(getMd5Str(getRealUrl(str))); if (htmlCacheModel != null) { deleteDiskCache(htmlCacheModel); } return true; } public boolean isConcurrentLoad(String str) { PatchProxyResult proxy = PatchProxy.proxy(new Object[]{str}, this, changeQuickRedirect, false, 17734, new Class[]{String.class}, Boolean.TYPE); if (proxy.isSupported) { return ((Boolean) proxy.result).booleanValue(); } if (this.programsInfo == null || TextUtils.isEmpty(str)) { return false; } if (!this.programsInfo.concurrent()) { a.h(TAG).a("concurrent开关关闭", new Object[0]); return false; } else if (this.programsInfo.inPreRequestDomain(str)) { return true; } else { a.h(TAG).a("不在白名单中", new Object[0]); return false; } } public boolean isHtmlCached(String str) { HtmlCacheModel htmlCacheModel; PatchProxyResult proxy = PatchProxy.proxy(new Object[]{str}, this, changeQuickRedirect, false, 17758, new Class[]{String.class}, Boolean.TYPE); if (proxy.isSupported) { return ((Boolean) proxy.result).booleanValue(); } try { if (TextUtils.isEmpty(str)) { return false; } String realUrl = getRealUrl(str); if (TextUtils.isEmpty(realUrl)) { return false; } String md5Str = getMd5Str(realUrl); if (!this.htmlCachedMap.containsKey(md5Str) || (htmlCacheModel = this.htmlCachedMap.get(md5Str)) == null || htmlCacheModel.getFileData() == null) { return false; } return true; } catch (Exception e) { e.printStackTrace(); } return false; } public boolean isLoadLocalHtml(String str) { PatchProxyResult proxy = PatchProxy.proxy(new Object[]{str}, this, changeQuickRedirect, false, 17764, new Class[]{String.class}, Boolean.TYPE); if (proxy.isSupported) { return ((Boolean) proxy.result).booleanValue(); } if (TextUtils.isEmpty(str)) { return false; } return this.htmlCachedMap.containsKey(getMd5Str(getRealUrl(str))); } public void loginStatusChanged(boolean z) { boolean z4; if (!PatchProxy.proxy(new Object[]{new Byte(z ? (byte) 1 : 0)}, this, changeQuickRedirect, false, 17750, new Class[]{Boolean.TYPE}, Void.TYPE).isSupported) { a.h(TAG).a("HtmlCacheManager loginStatusChanged() --isLogin=%s", Boolean.valueOf(z)); if (!this.htmlCachedMap.isEmpty()) { for (String str : this.htmlCachedMap.keySet()) { HtmlCacheModel htmlCacheModel = this.htmlCachedMap.get(str); if (htmlCacheModel != null && !TextUtils.isEmpty(htmlCacheModel.getUrl())) { Iterator<String> it2 = this.cleanHtmlWhitePage.iterator(); while (true) { if (!it2.hasNext()) { z4 = false; break; } if (htmlCacheModel.getUrl().contains(it2.next())) { z4 = true; break; } } if (!z4) { deleteDiskCache(htmlCacheModel); } } } } } } public void preloadHtml(int i, String str, int i3, String str2) { Object[] objArr = {new Integer(i), str, new Integer(i3), str2}; ChangeQuickRedirect changeQuickRedirect2 = changeQuickRedirect; Class cls = Integer.TYPE; if (!PatchProxy.proxy(objArr, this, changeQuickRedirect2, false, 17725, new Class[]{cls, String.class, cls, String.class}, Void.TYPE).isSupported) { ProgramsInfo programsInfo2 = getProgramsInfo(); this.programsInfo = programsInfo2; if (programsInfo2 != null && programsInfo2.preloadConfig != null) { HtmlCacheEnhancer.getInstance().preRender(i, str, i3, str2); if (!this.programsInfo.preloadConfig.needCache(i, str, i3, str2)) { a.h(TAG).a("preloadHtml preLoadPage.needCache=%s", "false"); } else if (isCacheHtml() && !htmlIsAvailable(str2) && !htmlIsFetching(str2)) { if (htmlIsPending(str2)) { adjustPendingTask(str2); return; } a.h(TAG).d("preload html=%s", str2); q.a(new DownLoadHtmlTask(str2, 1)); tracePreAndUpdate(Integer.valueOf(i), Integer.valueOf(i3), str2, 201); } } } } public long preloadHtmlForBrowserPage(String str) { PatchProxyResult proxy = PatchProxy.proxy(new Object[]{str}, this, changeQuickRedirect, false, 17729, new Class[]{String.class}, Long.TYPE); if (proxy.isSupported) { return ((Long) proxy.result).longValue(); } if (TextUtils.isEmpty(str)) { return 0; } try { if (!isPreloadOnRouter()) { return 0; } preloadHtml(str); return System.currentTimeMillis(); } catch (Throwable th2) { th2.printStackTrace(); return 0; } } public Bundle preloadHtmlForOther(String str, Uri uri, Bundle bundle) { PatchProxyResult proxy = PatchProxy.proxy(new Object[]{str, uri, bundle}, this, changeQuickRedirect, false, 17730, new Class[]{String.class, Uri.class, Bundle.class}, Bundle.class); if (proxy.isSupported) { return (Bundle) proxy.result; } if (!"/web/BrowserPage".equals(str)) { return bundle; } try { if (!isPreloadOnRouter()) { return bundle; } String queryParameter = uri.getQueryParameter("loadUrl"); if (TextUtils.isEmpty(queryParameter)) { return bundle; } if (bundle == null) { bundle = new Bundle(); } bundle.putLong("routerPreloadStartTime", System.currentTimeMillis()); preloadHtml(queryParameter); return bundle; } catch (Throwable th2) { th2.printStackTrace(); } } public void preloadHtmlWithVisibleLoad(String str) { if (!PatchProxy.proxy(new Object[]{str}, this, changeQuickRedirect, false, 17726, new Class[]{String.class}, Void.TYPE).isSupported) { ProgramsInfo programsInfo2 = getProgramsInfo(); this.programsInfo = programsInfo2; if (programsInfo2 != null && programsInfo2.preloadConfig != null && validateInPreLoadWhiteHost(str) && isCacheHtml() && !htmlIsAvailable(str) && !htmlIsFetching(str)) { if (htmlIsPending(str)) { adjustPendingTask(str); return; } a.h(TAG).d("preload html=%s", str); q.a(new DownLoadHtmlTask(str, 1)); tracePreAndUpdate(9, 0, str, 201); } } } public HtmlPreloadModel removePreloadRecord(String str) { PatchProxyResult proxy = PatchProxy.proxy(new Object[]{str}, this, changeQuickRedirect, false, 17712, new Class[]{String.class}, HtmlPreloadModel.class); if (proxy.isSupported) { return (HtmlPreloadModel) proxy.result; } return this.preloadRecordMap.remove(getRealUrl(str)); } public void saveHtmlConfig() { if (!PatchProxy.proxy(new Object[0], this, changeQuickRedirect, false, 17744, new Class[0], Void.TYPE).isSupported) { MMKV.defaultMMKV(2, null).putString("HTML_CONFIG_KEY", e.n(this.htmlCachedMap)); } } public void setCacheHtml(boolean z) { if (!PatchProxy.proxy(new Object[]{new Byte(z ? (byte) 1 : 0)}, this, changeQuickRedirect, false, 17754, new Class[]{Boolean.TYPE}, Void.TYPE).isSupported) { MMKV.defaultMMKV(2, null).putBoolean("CACHE_HTML_KEY", z); this.cacheHtml = Boolean.valueOf(z); } } public void setPreLoadAdvData(List<PreLoadAdvModel> list, boolean z) { if (!PatchProxy.proxy(new Object[]{list, new Byte(z ? (byte) 1 : 0)}, this, changeQuickRedirect, false, 17771, new Class[]{List.class, Boolean.TYPE}, Void.TYPE).isSupported) { this.mOnAppBackground = z; if (!(list == null || list.size() == 0)) { Collections.sort(list, i0.d); for (PreLoadAdvModel preLoadAdvModel : list) { if (preLoadAdvModel != null && System.currentTimeMillis() - (preLoadAdvModel.expiryTime * 1000) <= 0 && !this.mPreLoadAdvModels.contains(preLoadAdvModel)) { this.mPreLoadAdvModels.add(preLoadAdvModel); } } } } } public void setPreloadTimeout(Long l) { if (!PatchProxy.proxy(new Object[]{l}, this, changeQuickRedirect, false, 17710, new Class[]{Long.class}, Void.TYPE).isSupported) { this.preloadTimeout = l.longValue(); } } public void setProgramLoadStatus(int i) { if (!PatchProxy.proxy(new Object[]{new Integer(i)}, this, changeQuickRedirect, false, 17732, new Class[]{Integer.TYPE}, Void.TYPE).isSupported && this.programLoadStatus != 2) { this.programLoadStatus = i; } } public void setProgramsInfo(ProgramsInfo programsInfo2) { if (!PatchProxy.proxy(new Object[]{programsInfo2}, this, changeQuickRedirect, false, 17715, new Class[]{ProgramsInfo.class}, Void.TYPE).isSupported && programsInfo2 != null) { this.programsInfo = programsInfo2; this.expireTime = programsInfo2.getExpireTime(); this.defaultxpireTime = programsInfo2.getDefaultExpireTime(); this.preloadTimeout = programsInfo2.getPreRequestTimeout(); concurrentLoad = programsInfo2.concurrent(); this.cleanHtmlWhitePage.clear(); if (programsInfo2.getCleanHtmlWhitePage() != null) { this.cleanHtmlWhitePage.addAll(programsInfo2.getCleanHtmlWhitePage()); } MMKV.defaultMMKV(2, null).putString("programInfo", DataGsonUtil.dataToJsonString(programsInfo2)); preLoadAdvHtml(); preLoadRecallHtml(); if (programsInfo2.getKeepConnectionHostConfig() == null || programsInfo2.getKeepConnectionHostConfig().getEnable() != 1) { ScheduledFuture scheduledFuture = this.hostKeepAliveTaskFuture; if (scheduledFuture != null && !scheduledFuture.isCancelled()) { this.hostKeepAliveTaskFuture.cancel(false); } if (!this.dnsRequested) { synchronized (this.dnsList) { this.dnsList.clear(); if (programsInfo2.getH5HostList() != null && programsInfo2.getH5HostList().size() > 0) { this.dnsRequested = true; this.dnsList.addAll(programsInfo2.getH5HostList()); q.c(new w(this, 9)); } } return; } return; } makeHostSocketAlwaysAlive(programsInfo2.getKeepConnectionHostConfig()); } } public void traceDownLoadHtml(HtmlPreloadModel htmlPreloadModel) { if (!PatchProxy.proxy(new Object[]{htmlPreloadModel}, this, changeQuickRedirect, false, 17770, new Class[]{HtmlPreloadModel.class}, Void.TYPE).isSupported && htmlPreloadModel != null) { HashMap hashMap = new HashMap(); hashMap.put(PushConstants.WEB_URL, htmlPreloadModel.getUrl()); hashMap.put("cost_time", htmlPreloadModel.getCostTime() + ""); hashMap.put("status", htmlPreloadModel.getStatus() + ""); hashMap.put("http_code", htmlPreloadModel.getHttpCode() + ""); hashMap.put("err_msg", htmlPreloadModel.getErrMsg()); BM.app().j("h5").c("download_html", hashMap); } } public void tracePreload(Integer num, Integer num2, String str, Integer num3, boolean z) { if (!PatchProxy.proxy(new Object[]{num, num2, str, num3, new Byte(z ? (byte) 1 : 0)}, this, changeQuickRedirect, false, 17735, new Class[]{Integer.class, Integer.class, String.class, Integer.class, Boolean.TYPE}, Void.TYPE).isSupported) { try { if (DuHybrid.hasInstance() && z) { if (num == null) { if (TextUtils.isEmpty(str)) { return; } if (str.contains("/router/web/BrowserPage")) { try { String decode = URLDecoder.decode(str.replace("https://m.poizon.com/router/web/BrowserPage?loadUrl=", ""), "utf-8"); if (!decode.contains("router/product/BoutiqueRecommendDetailPage")) { tracePreAndUpdate(num, num2, decode, num3); } } catch (Exception e) { e.printStackTrace(); } } } } } catch (Exception e6) { e6.printStackTrace(); } } } public void updateHTMLCache(String str) { if (!PatchProxy.proxy(new Object[]{str}, this, changeQuickRedirect, false, 17772, new Class[]{String.class}, Void.TYPE).isSupported && !TextUtils.isEmpty(str)) { ProgramsInfo programsInfo2 = getProgramsInfo(); this.programsInfo = programsInfo2; if (programsInfo2 != null) { HtmlCacheEnhancer.getInstance().preRender(str); ProgramsInfo programsInfo3 = this.programsInfo; if (programsInfo3.updatePage == 1) { if (programsInfo3.inPreLoadWhitePage(str) || this.programsInfo.inPreRequestDomain(str)) { if (this.htmlCachedMap.get(getMd5Str(getRealUrl(str))) != null) { q.a(new DownLoadHtmlTask(str, 1)); tracePreAndUpdate(null, null, str, 200); } } } } } } public void updatePage(HtmlConfigModel htmlConfigModel) { List<HtmlCacheModel> list; if (!PatchProxy.proxy(new Object[]{htmlConfigModel}, this, changeQuickRedirect, false, 17749, new Class[]{HtmlConfigModel.class}, Void.TYPE).isSupported && htmlConfigModel != null && (list = htmlConfigModel.pageList) != null && !list.isEmpty()) { for (HtmlCacheModel htmlCacheModel : htmlConfigModel.pageList) { HtmlCacheModel htmlCacheModelByHtmlConfigModel = getHtmlCacheModelByHtmlConfigModel(htmlCacheModel.getUrl()); if (htmlCacheModelByHtmlConfigModel != null && htmlCacheModelByHtmlConfigModel.modifyTime < htmlCacheModel.modifyTime) { deleteDiskCache(htmlCacheModelByHtmlConfigModel); } } checkExpire(); } } public void preloadHtml(String str) { if (!PatchProxy.proxy(new Object[]{str}, this, changeQuickRedirect, false, 17727, new Class[]{String.class}, Void.TYPE).isSupported) { ProgramsInfo programsInfo2 = getProgramsInfo(); this.programsInfo = programsInfo2; if (programsInfo2 == null || !isConcurrentLoad(str)) { return; } if (TextUtils.isEmpty(str) || htmlIsAvailable(str) || htmlIsFetching(str)) { a.h(TAG).a("HtmlCacheManager preloadHtml(): TextUtils.isEmpty(url) || htmlIsAvailable(url) || htmlIsFetching(url)", new Object[0]); } else { q.a(new DownLoadHtmlTask(str, 3)); } } } public Bundle preloadHtml(String str, Uri uri, Bundle bundle) { PatchProxyResult proxy = PatchProxy.proxy(new Object[]{str, uri, bundle}, this, changeQuickRedirect, false, 17728, new Class[]{String.class, Uri.class, Bundle.class}, Bundle.class); if (proxy.isSupported) { return (Bundle) proxy.result; } if (!"/web/BrowserPage".equals(str)) { return bundle; } try { String queryParameter = uri.getQueryParameter("loadUrl"); if (TextUtils.isEmpty(queryParameter)) { return bundle; } if (bundle == null) { bundle = new Bundle(); } bundle.putLong("routerPreloadStartTime", System.currentTimeMillis()); preloadHtml(queryParameter); return bundle; } catch (Throwable th2) { th2.printStackTrace(); } } }