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

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


package com.tencent.mtt.browser.notification;

import MTT.HotWordInfo;
import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.text.TextUtils;
import com.tencent.common.task.TaskManager;
import com.tencent.common.task.TaskObserverBase;
import com.tencent.common.utils.FileUtils;
import com.tencent.common.utils.StringUtils;
import com.tencent.mtt.ContextHolder;
import com.tencent.mtt.base.task.PictureTask;
import com.tencent.mtt.base.task.Task;
import com.tencent.mtt.browser.hotword.facade.IHotwordService;
import com.tencent.mtt.browser.hotword.facade.IOnHotwordUpdate;
import com.tencent.mtt.browser.notification.facade.INotificationService;
import com.tencent.mtt.browser.notification.weather.ResidentNotificationReceiver;
import com.tencent.mtt.log.utils.CollectionUtil;
import com.tencent.mtt.multiproc.QBSharedPreferences;
import com.tencent.mtt.operation.event.EventLog;
import com.tencent.mtt.qbcontext.core.QBContext;
import com.tencent.mtt.setting.MultiProcessPublicSettingManager;
import java.io.File;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.concurrent.CopyOnWriteArrayList;

public class ResidentHotWordDataManager implements IOnHotwordUpdate {

    static Bitmap f43233b;

    static Bitmap f43234c;

    static Bitmap f43235d;

    static final String f43232a = FileUtils.e() + "/notification";
    private static HotWordInfo i = null;
    static boolean e = true;
    static boolean f = false;
    public static boolean g = false;
    public static boolean h = false;
    private static ResidentHotWordDataManager j = null;

    private ResidentHotWordDataManager() {
        IHotwordService iHotwordService;
        if (!ResidentNotificationReceiver.c() || (iHotwordService = (IHotwordService) QBContext.getInstance().getService(IHotwordService.class)) == null) {
            return;
        }
        iHotwordService.requestHotword(true);
    }

    public static HotWordInfo a(Context context, boolean z) {
        ArrayList<HotWordInfo> arrayList;
        IHotwordService iHotwordService = (IHotwordService) QBContext.getInstance().getService(IHotwordService.class);
        if (iHotwordService != null) {
            arrayList = iHotwordService.getHotWords();
            a(arrayList);
            if (CollectionUtil.a(arrayList)) {
                iHotwordService.requestHotword(true);
                i = e();
                return i;
            }
            iHotwordService.requestHotword(z);
        } else {
            arrayList = null;
        }
        if (arrayList != null && arrayList.size() > 0) {
            long b2 = b(context);
            int f2 = f();
            int c2 = c(context) % arrayList.size();
            i = arrayList.get(c2);
            if (i != null && (z || b2 == -1 || System.currentTimeMillis() - b2 > f2 * 60 * 1000)) {
                int size = (c2 + 1) % arrayList.size();
                i = arrayList.get(size);
                HotWordInfo hotWordInfo = i;
                if (hotWordInfo != null) {
                    b(hotWordInfo);
                    a(context, System.currentTimeMillis());
                    a(context, size);
                    a(i);
                }
                return i;
            }
        }
        return i;
    }

    public static Bitmap a(HotWordInfo hotWordInfo, String str, byte b2) {
        Bitmap b3 = ResidentNotificatoinUtils.b(str);
        if (b3 == null) {
            File a2 = ResidentNotificatoinUtils.a(str);
            if (b2 == 0 && g) {
                b(hotWordInfo, str, a2);
            } else if (b2 == 1 && h) {
                a(hotWordInfo, str, a2);
            }
        }
        return b3;
    }

    public static Bitmap a(final String str) {
        if (TextUtils.isEmpty(str)) {
            return null;
        }
        Bitmap b2 = ResidentNotificatoinUtils.b(str);
        if (b2 != null) {
            return b2;
        }
        final File a2 = ResidentNotificatoinUtils.a(str);
        PictureTask pictureTask = new PictureTask(str, new TaskObserverBase() {
            @Override
            public void onTaskCompleted(Task task) {
                PictureTask pictureTask2;
                byte[] a3;
                if (task == null || (a3 = (pictureTask2 = (PictureTask) task).a()) == null) {
                    return;
                }
                FileUtils.a(a2, a3);
                if (TextUtils.equals(str, pictureTask2.getTaskUrl())) {
                    ResidentHotWordDataManager.f43235d = ResidentNotificatoinUtils.b(str);
                    if (ResidentHotWordDataManager.f43235d != null) {
                        ((INotificationService) QBContext.getInstance().getService(INotificationService.class)).show(ContextHolder.getAppContext(), false);
                    }
                }
            }
        }, false, null, (byte) 0, "externalentrance");
        pictureTask.setConnectionClose();
        TaskManager.a().a((Task) pictureTask);
        return null;
    }

    public static ResidentHotWordDataManager a() {
        if (j == null) {
            j = new ResidentHotWordDataManager();
            j.b();
        }
        return j;
    }

    private static void a(HotWordInfo hotWordInfo) {
        if (hotWordInfo == null) {
            return;
        }
        boolean z = false;
        SharedPreferences sharedPreferences = QBSharedPreferences.getSharedPreferences(ContextHolder.getAppContext(), "residentNotification", 4, false, true);
        String string = sharedPreferences.getString("festivalbg", "");
        int i2 = sharedPreferences.getInt("effectivetime", 0);
        if (!StringUtils.b(string)) {
            if (ResidentNotification.a(i2)) {
                hotWordInfo.sBackgroundUrl = string;
                if (z && !StringUtils.b(hotWordInfo.sBackgroundUrl) && ResidentNotification.a(hotWordInfo.iEffective_Time) && hotWordInfo.iConfType == 1) {
                    SharedPreferences.Editor edit = sharedPreferences.edit();
                    edit.putString("festivalbg", hotWordInfo.sBackgroundUrl);
                    edit.putInt("effectivetime", hotWordInfo.iEffective_Time);
                    edit.commit();
                }
                EventLog.a("通知栏", "", "检查背景", "festivalBg :" + string + "\r\neffectivetime :" + i2 + "\r\n", "normanchen", 1);
                g = true;
                h = true;
            }
            SharedPreferences.Editor edit2 = sharedPreferences.edit();
            edit2.putString("festivalbg", "");
            edit2.putInt("effectivetime", 0);
            edit2.commit();
        }
        z = true;
        if (z) {
            SharedPreferences.Editor edit3 = sharedPreferences.edit();
            edit3.putString("festivalbg", hotWordInfo.sBackgroundUrl);
            edit3.putInt("effectivetime", hotWordInfo.iEffective_Time);
            edit3.commit();
        }
        EventLog.a("通知栏", "", "检查背景", "festivalBg :" + string + "\r\neffectivetime :" + i2 + "\r\n", "normanchen", 1);
        g = true;
        h = true;
    }

    private static void a(final HotWordInfo hotWordInfo, final String str, final File file) {
        PictureTask pictureTask = new PictureTask(str, new TaskObserverBase() {
            @Override
            public void onTaskCompleted(Task task) {
                PictureTask pictureTask2;
                byte[] a2;
                if (task == null || (a2 = (pictureTask2 = (PictureTask) task).a()) == null) {
                    return;
                }
                FileUtils.a(file, a2);
                HotWordInfo hotWordInfo2 = hotWordInfo;
                if (hotWordInfo2 == null || TextUtils.isEmpty(hotWordInfo2.sBackgroundUrl) || !hotWordInfo.sBackgroundUrl.equalsIgnoreCase(pictureTask2.getTaskUrl())) {
                    return;
                }
                ResidentHotWordDataManager.f43234c = ResidentNotificatoinUtils.b(str);
                if (ResidentHotWordDataManager.f43234c != null) {
                    ((INotificationService) QBContext.getInstance().getService(INotificationService.class)).show(ContextHolder.getAppContext(), false);
                }
            }
        }, false, null, (byte) 0, "externalentrance");
        h = false;
        pictureTask.setConnectionClose();
        TaskManager.a().a((Task) pictureTask);
    }

    public static void a(Context context) {
        try {
            NetworkInfo d2 = d(context);
            if (d2 == null) {
                return;
            }
            boolean a2 = i != null ? a(false) : false;
            if (d2.getType() != 1 || a2) {
                return;
            }
            ((INotificationService) QBContext.getInstance().getService(INotificationService.class)).show(ContextHolder.getAppContext(), true);
        } catch (Exception unused) {
        }
    }

    private static void a(Context context, int i2) {
        try {
            SharedPreferences.Editor edit = QBSharedPreferences.getSharedPreferences(context, "residentNotification", 4, false, true).edit();
            edit.putInt("weatherHotwordIndex", i2);
            edit.commit();
        } catch (Exception unused) {
        }
    }

    private static void a(Context context, long j2) {
        try {
            SharedPreferences.Editor edit = QBSharedPreferences.getSharedPreferences(context, "residentNotification", 4, false, true).edit();
            edit.putLong("hotwordRefreshTime", j2);
            edit.commit();
        } catch (Exception unused) {
        }
    }

    private static void a(ArrayList<HotWordInfo> arrayList) {
        if (CollectionUtil.a(arrayList)) {
            return;
        }
        ArrayList arrayList2 = new ArrayList();
        Iterator<HotWordInfo> it = arrayList.iterator();
        while (it.hasNext()) {
            HotWordInfo next = it.next();
            if (next != null && next.iShowEndTime > 0 && System.currentTimeMillis() > next.iShowEndTime * 1000) {
                arrayList2.add(next);
            }
        }
        if (CollectionUtil.a(arrayList2)) {
            return;
        }
        arrayList.removeAll(arrayList2);
    }

    private static boolean a(boolean z) {
        if (!TextUtils.isEmpty(i.sIconUrl) && f43233b == null) {
            g = true;
            HotWordInfo hotWordInfo = i;
            f43233b = a(hotWordInfo, hotWordInfo.sIconUrl, (byte) 0);
            if (f43233b != null) {
                z = true;
            }
        }
        if (!TextUtils.isEmpty(i.sBackgroundUrl) && (f43234c == null || e)) {
            e = false;
            HotWordInfo hotWordInfo2 = i;
            f43234c = a(hotWordInfo2, hotWordInfo2.sBackgroundUrl, (byte) 1);
            if (f43234c != null) {
                z = true;
            }
        }
        if (z) {
            ((INotificationService) QBContext.getInstance().getService(INotificationService.class)).show(ContextHolder.getAppContext(), true);
        }
        return z;
    }

    private static long b(Context context) {
        return QBSharedPreferences.getSharedPreferences(context, "residentNotification", 4, false, true).getLong("hotwordRefreshTime", -1L);
    }

    private static void b(HotWordInfo hotWordInfo) {
        if (hotWordInfo == null) {
            return;
        }
        int i2 = hotWordInfo.iNotify_Time;
        if (i2 < 1) {
            i2 = 1;
        }
        MultiProcessPublicSettingManager.a().setInt("hotword_refresh_period", i2);
    }

    private static void b(final HotWordInfo hotWordInfo, final String str, final File file) {
        PictureTask pictureTask = new PictureTask(str, new TaskObserverBase() {
            @Override
            public void onTaskCompleted(Task task) {
                PictureTask pictureTask2;
                byte[] a2;
                if (task == null || (a2 = (pictureTask2 = (PictureTask) task).a()) == null) {
                    return;
                }
                FileUtils.a(file, a2);
                HotWordInfo hotWordInfo2 = hotWordInfo;
                if (hotWordInfo2 == null || !TextUtils.equals(hotWordInfo2.sIconUrl, pictureTask2.getTaskUrl())) {
                    return;
                }
                ResidentHotWordDataManager.f43233b = ResidentNotificatoinUtils.b(str);
                if (ResidentHotWordDataManager.f43233b != null) {
                    ((INotificationService) QBContext.getInstance().getService(INotificationService.class)).show(ContextHolder.getAppContext(), false);
                }
            }
        }, false, null, (byte) 0, "externalentrance");
        g = false;
        pictureTask.setConnectionClose();
        TaskManager.a().a((Task) pictureTask);
    }

    private static int c(Context context) {
        return QBSharedPreferences.getSharedPreferences(context, "residentNotification", 4, false, true).getInt("weatherHotwordIndex", 0);
    }

    public static void c() {
        File[] listFiles;
        File file = new File(f43232a);
        if (!file.exists() || (listFiles = file.listFiles()) == null || listFiles.length <= 0) {
            return;
        }
        for (File file2 : listFiles) {
            file2.delete();
        }
    }

    private static NetworkInfo d(Context context) {
        ConnectivityManager connectivityManager;
        if (context == null || (connectivityManager = (ConnectivityManager) context.getSystemService("connectivity")) == null) {
            return null;
        }
        try {
            return connectivityManager.getActiveNetworkInfo();
        } catch (Exception unused) {
            return null;
        }
    }

    public static HotWordInfo e() {
        HotWordInfo hotWordInfo = new HotWordInfo();
        hotWordInfo.sHotWordName = "今日全网热议";
        hotWordInfo.sHotWordUrl = "https://so.html5.qq.com/page/real/search_result?q=热搜榜&jump_from=096&entryScene=096";
        return hotWordInfo;
    }

    private static int f() {
        int i2 = MultiProcessPublicSettingManager.a().getInt("hotword_refresh_period", 10);
        if (i2 < 1) {
            return 1;
        }
        return i2;
    }

    @Override
    public void a(int i2) {
        if (i2 != 12) {
            return;
        }
        c();
        Context appContext = ContextHolder.getAppContext();
        a(appContext, -1L);
        f = true;
        e = true;
        SharedPreferences.Editor edit = QBSharedPreferences.getSharedPreferences(appContext, "residentNotification", 4, false, true).edit();
        edit.putInt("weatherHotwordIndex", 0);
        edit.putString("festivalbg", "");
        edit.putInt("effectivetime", 0);
        edit.commit();
        IHotwordService iHotwordService = (IHotwordService) QBContext.getInstance().getService(IHotwordService.class);
        if (iHotwordService != null) {
            ArrayList<HotWordInfo> hotWords = iHotwordService.getHotWords();
            a(hotWords);
            if (hotWords == null || hotWords.size() <= 0) {
                EventLog.a("通知栏", "", "热词更新(无热词)", "没有热词", "normanchen", 1, 1);
                return;
            }
            b(hotWords.get(0));
            f = true;
            StringBuilder sb = new StringBuilder();
            Iterator<HotWordInfo> it = hotWords.iterator();
            while (it.hasNext()) {
                HotWordInfo next = it.next();
                if (next != null) {
                    sb.append("------------\r\n");
                    sb.append("热词:");
                    sb.append(next.sHotWordName);
                    sb.append("\r\n");
                    sb.append("运营类型:");
                    sb.append(next.iConfType);
                    sb.append("\r\n");
                    sb.append("热词Url:");
                    sb.append(next.sHotWordUrl);
                    sb.append("\r\n");
                    sb.append("背景url:");
                    sb.append(next.sBackgroundUrl);
                    sb.append("\r\n");
                    sb.append("icon图片url:");
                    sb.append(next.sIconUrl);
                    sb.append("\r\n");
                }
            }
            EventLog.a("通知栏", "", "热词更新(" + hotWords.size() + ")", sb.toString(), "normanchen", 2, 2);
        }
    }

    public void b() {
        IHotwordService iHotwordService = (IHotwordService) QBContext.getInstance().getService(IHotwordService.class);
        if (iHotwordService != null) {
            CopyOnWriteArrayList<IOnHotwordUpdate> hotworListener = iHotwordService.getHotworListener();
            if (hotworListener != null) {
                Iterator<IOnHotwordUpdate> it = hotworListener.iterator();
                while (it.hasNext()) {
                    IOnHotwordUpdate next = it.next();
                    if (next instanceof ResidentHotWordDataManager) {
                        hotworListener.remove(next);
                    }
                }
            }
            iHotwordService.setHotworListener(this);
        }
    }

    @Override
    public void b(int i2) {
    }

    public void d() {
        CopyOnWriteArrayList<IOnHotwordUpdate> hotworListener;
        IHotwordService iHotwordService = (IHotwordService) QBContext.getInstance().getService(IHotwordService.class);
        if (iHotwordService == null || (hotworListener = iHotwordService.getHotworListener()) == null) {
            return;
        }
        Iterator<IOnHotwordUpdate> it = hotworListener.iterator();
        while (it.hasNext()) {
            IOnHotwordUpdate next = it.next();
            if (next instanceof ResidentHotWordDataManager) {
                hotworListener.remove(next);
            }
        }
    }
}