光速虚拟机 v3.8.2版本的 MD5 值为:68970fb34f75fa0f2632de9e93032f55

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


package com.vphonegaga.titan.module.update;

import android.content.Context;
import android.net.Uri;
import android.text.TextUtils;
import android.util.Log;
import android.util.SparseArray;
import android.view.View;
import com.common.utils.DeviceUtil;
import com.common.utils.FileUtil;
import com.common.utils.GeneralUtil;
import com.common.utils.IntentUtil;
import com.common.utils.NetworkUtil;
import com.common.utils.PathUtil;
import com.common.utils.ResourceUtil;
import com.common.utils.SystemUtil;
import com.common.utils.XmlUtil;
import com.liulishuo.filedownloader.BaseDownloadTask;
import com.vphonegaga.titan.MyApp;
import com.vphonegaga.titan.R;
import com.vphonegaga.titan.module.BaseModule;
import com.vphonegaga.titan.module.ReportModule;
import com.vphonegaga.titan.module.update.UpdateDownloadDialog;
import com.vphonegaga.titan.module.update.UpdateXmlNode;
import com.vphonegaga.titan.roles.ConfigMgr;
import com.xuexiang.xupdate.utils.ApkInstallUtils;
import io.reactivex.Observable;
import io.reactivex.ObservableEmitter;
import io.reactivex.ObservableOnSubscribe;
import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Consumer;
import io.reactivex.schedulers.Schedulers;
import java.io.File;
import java.io.IOException;
import net.lingala.zip4j.util.InternalZipConstants;
import org.xmlpull.v1.XmlPullParserException;
public class AppUpdateModule extends BaseModule {
    static final boolean $assertionsDisabled = false;
    private static final String DEBUG_UPDATE_XML_URL = "http://test.app.gsxnj.cn/vphonegaga/update.xml";
    private static final String PREFERENCE_UPDATE_FILE_PATH = "updateFilePath";
    private static final String PREFERENCE_UPDATE_FROM_VERSION = "updateFromVersion";
    private static final String PREFERENCE_UPDATE_LAST_REMINDER_STARTUP_NUMBER = "updateLastReminderStartupNumber";
    private static final String PREFERENCE_UPDATE_LAST_REMINDER_TIME = "updateLastReminderTime";
    private static final String PREFERENCE_UPDATE_RULE_ID = "updateRuleId";
    private static final String PREFERENCE_UPDATE_TARGET_VERSION = "targetVersion";
    private static final String RELEASE_UPDATE_XML_URL = "https://app.gsxnj.cn/vphonegaga/update.xml";
    private static final String TAG = "Titan.AppUpdateModule";
    private static AppUpdateModule sInstance;
    private UpdateDownloadDialog<UpdateXmlNode> mAppUpdateDialog;
    private Context mAsyncContext;
    private Context mSyncContext;
    private UpdateXmlNode mHitRuleNode = null;
    private long mDownloadConsumeTime = 0;
    private long mDownloadedSize = 0;
    BaseDownloadTask mCurrentDownloadtask = null;
    private boolean mUpdateStop = true;
    private boolean mIsSyncUpdate = false;
    private boolean mIsUpdateOnStartup = false;
    private SparseArray<String> mMarketNames = null;
    private long mLastReminderTime = ((Long) ConfigMgr.getGlobal(PREFERENCE_UPDATE_LAST_REMINDER_TIME, 0L)).longValue();
    private long mLastReminderStartupNumber = ((Long) ConfigMgr.getGlobal(PREFERENCE_UPDATE_LAST_REMINDER_STARTUP_NUMBER, 0L)).longValue();

    public class AnonymousClass6 implements UpdateDownloadDialog.UpdateDialogEventListener<UpdateXmlNode> {
        AnonymousClass6() {
        }

        @Override
        public void onClick(View view, UpdateDownloadDialog updateDownloadDialog, UpdateXmlNode updateXmlNode) {
            boolean z = true;
            switch (view.getId()) {
                case R.id.update_download_dialog_button_cancel:
                    ReportModule.getInstance().recordUpdateProcess(7, "1");
                    AppUpdateModule.this.cancelUpdate();
                    AppUpdateModule appUpdateModule = AppUpdateModule.this;
                    appUpdateModule.finishUpdate((appUpdateModule.mIsUpdateOnStartup && updateXmlNode.isForceUpdate()) ? false : false);
                    return;
                case R.id.update_download_dialog_button_confirm:
                default:
                    if (MyApp.isDebugMode()) {
                        Log.d(AppUpdateModule.TAG, "Resource id is illegal");
                        return;
                    }
                    return;
                case R.id.update_download_dialog_button_ignore:
                    ReportModule.getInstance().recordUpdateProcess(3, "1");
                    AppUpdateModule appUpdateModule2 = AppUpdateModule.this;
                    appUpdateModule2.finishUpdate((appUpdateModule2.mIsUpdateOnStartup && updateXmlNode.isForceUpdate()) ? false : false);
                    return;
                case R.id.update_download_dialog_button_update:
                    AppUpdateModule.this.onUserChooseUpdate(updateDownloadDialog, updateXmlNode);
                    return;
            }
        }

        @Override
        public void onDownloadComplete(UpdateDownloadDialog updateDownloadDialog, final UpdateXmlNode updateXmlNode, final BaseDownloadTask baseDownloadTask) {
            Observable.create(new ObservableOnSubscribe<String>() {
                @Override
                public void subscribe(ObservableEmitter<String> observableEmitter) {
                    ReportModule.getInstance().recordUpdateProcess(7, "0");
                    AppUpdateModule.this.onDownloadStop();
                    if (AppUpdateModule.this.dealWithNewApk(updateXmlNode, baseDownloadTask, true)) {
                        AppUpdateModule.this.finishUpdate(updateXmlNode.isForceUpdate());
                    } else {
                        observableEmitter.onNext(ResourceUtil.getString(R.string.update_check_failed));
                        ReportModule.getInstance().recordUpdateProcess(4, "1");
                        ReportModule.getInstance().reportUpdateProcess();
                    }
                    observableEmitter.onComplete();
                }
            }).subscribeOn(Schedulers.newThread()).observeOn(AndroidSchedulers.mainThread()).doOnNext(new Consumer<String>() {
                @Override
                public void accept(String str) {
                    AppUpdateModule.this.mAppUpdateDialog.showMessage(str, new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {
                            AppUpdateModule.this.finishUpdate(updateXmlNode.isForceUpdate());
                        }
                    });
                }
            }).subscribe();
        }

        @Override
        public void onDownloadError(Throwable th) {
            Log.d(AppUpdateModule.TAG, "Update download Error!");
            AppUpdateModule.this.onDownloadStop();
            th.printStackTrace();
            AppUpdateModule.this.mAppUpdateDialog.showMessage(ResourceUtil.getString(R.string.update_download_failed), new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    AppUpdateModule.this.finishUpdate(false);
                }
            });
            ReportModule.getInstance().recordUpdateProcess(4, "1");
            ReportModule.getInstance().recordUpdateProcess(8, th.getMessage());
            ReportModule.getInstance().reportUpdateProcess();
        }

        @Override
        public void onProgress(int i, int i2) {
            AppUpdateModule.this.mDownloadedSize = i;
        }
    }

    public static class AnonymousClass9 {
        static final int[] $SwitchMap$com$vphonegaga$titan$module$update$UpdateXmlNode$ReminderFrequencyType;

        static {
            int[] iArr = new int[UpdateXmlNode.ReminderFrequencyType.values().length];
            $SwitchMap$com$vphonegaga$titan$module$update$UpdateXmlNode$ReminderFrequencyType = iArr;
            try {
                iArr[UpdateXmlNode.ReminderFrequencyType.everyTime.ordinal()] = 1;
            } catch (NoSuchFieldError unused) {
            }
            try {
                $SwitchMap$com$vphonegaga$titan$module$update$UpdateXmlNode$ReminderFrequencyType[UpdateXmlNode.ReminderFrequencyType.timeInterval.ordinal()] = 2;
            } catch (NoSuchFieldError unused2) {
            }
            try {
                $SwitchMap$com$vphonegaga$titan$module$update$UpdateXmlNode$ReminderFrequencyType[UpdateXmlNode.ReminderFrequencyType.startupNumberInterval.ordinal()] = 3;
            } catch (NoSuchFieldError unused3) {
            }
            try {
                $SwitchMap$com$vphonegaga$titan$module$update$UpdateXmlNode$ReminderFrequencyType[UpdateXmlNode.ReminderFrequencyType.unknown.ordinal()] = 4;
            } catch (NoSuchFieldError unused4) {
            }
        }
    }

    public interface OnCheckUpdateListener {
        void onComplete();

        void onError();
    }

    private AppUpdateModule() {
    }

    public synchronized void cancelUpdate() {
        BaseDownloadTask baseDownloadTask = this.mCurrentDownloadtask;
        if (baseDownloadTask != null) {
            if (!baseDownloadTask.pause()) {
                Log.d(TAG, "Download task pause failed!");
            }
            this.mCurrentDownloadtask = null;
        }
        onDownloadStop();
    }

    private void checkUpdate(final OnCheckUpdateListener onCheckUpdateListener) {
        this.mUpdateStop = false;
        Observable.create(new ObservableOnSubscribe<UpdateXmlNode>() {
            @Override
            public void subscribe(ObservableEmitter<UpdateXmlNode> observableEmitter) {
                AppUpdateModule.this.reportUpdateResult();
                try {
                    if (NetworkUtil.isNetworkAvailable()) {
                        AppUpdateModule.this.parseUpdateXml();
                        observableEmitter.onComplete();
                        return;
                    }
                    Log.d(AppUpdateModule.TAG, "Network isn't available!");
                    OnCheckUpdateListener onCheckUpdateListener2 = onCheckUpdateListener;
                    if (onCheckUpdateListener2 != null) {
                        onCheckUpdateListener2.onError();
                    } else {
                        AppUpdateModule.this.finishUpdate(false);
                    }
                } catch (IOException e) {
                    ReportModule.getInstance().recordUpdateProcess(0, "1");
                    observableEmitter.onError(e);
                } catch (XmlPullParserException e2) {
                    ReportModule.getInstance().recordUpdateProcess(1, "1");
                    observableEmitter.onError(e2);
                }
            }
        }).subscribeOn(Schedulers.newThread()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Observer<UpdateXmlNode>() {
            @Override
            public void onComplete() {
                String str;
                String str2;
                OnCheckUpdateListener onCheckUpdateListener2;
                ReportModule.getInstance().recordUpdateProcess(0, "0");
                ReportModule.getInstance().recordUpdateProcess(1, "0");
                if (AppUpdateModule.this.mHitRuleNode != null) {
                    Log.d(AppUpdateModule.TAG, "[id]: " + AppUpdateModule.this.mHitRuleNode.getId() + " [priority]: " + AppUpdateModule.this.mHitRuleNode.getPriority() + " [version]: " + AppUpdateModule.this.mHitRuleNode.getVersionCode());
                    str = String.valueOf(AppUpdateModule.this.mHitRuleNode.getId());
                    if (!AppUpdateModule.this.mIsSyncUpdate) {
                        if (AppUpdateModule.this.mIsUpdateOnStartup) {
                            AppUpdateModule appUpdateModule = AppUpdateModule.this;
                            appUpdateModule.showUpdateDialogOnStartup(appUpdateModule.mAsyncContext);
                        } else {
                            AppUpdateModule appUpdateModule2 = AppUpdateModule.this;
                            appUpdateModule2.showUpdateDialog(appUpdateModule2.mAsyncContext);
                        }
                    }
                } else {
                    str = "";
                }
                ReportModule.getInstance().recordUpdateProcess(2, str);
                if (AppUpdateModule.this.mIsSyncUpdate && (onCheckUpdateListener2 = onCheckUpdateListener) != null) {
                    onCheckUpdateListener2.onComplete();
                } else if (str.isEmpty() || AppUpdateModule.this.mAppUpdateDialog == null || !AppUpdateModule.this.mAppUpdateDialog.isShowing()) {
                    StringBuilder sb = new StringBuilder();
                    sb.append("This aync update check result: ");
                    if (str.isEmpty()) {
                        str2 = "no update";
                    } else {
                        str2 = "id is " + str;
                    }
                    sb.append(str2);
                    Log.d(AppUpdateModule.TAG, sb.toString());
                    AppUpdateModule.this.finishUpdate(false);
                }
            }

            @Override
            public void onError(Throwable th) {
                OnCheckUpdateListener onCheckUpdateListener2;
                th.printStackTrace();
                if (!AppUpdateModule.this.mIsSyncUpdate || (onCheckUpdateListener2 = onCheckUpdateListener) == null) {
                    AppUpdateModule.this.finishUpdate(false);
                } else {
                    onCheckUpdateListener2.onError();
                }
            }

            @Override
            public void onNext(UpdateXmlNode updateXmlNode) {
            }

            @Override
            public void onSubscribe(Disposable disposable) {
            }
        });
    }

    public boolean checkUpdateRule(UpdateXmlNode updateXmlNode) {
        String str;
        UpdateXmlNode updateXmlNode2 = this.mHitRuleNode;
        boolean z = false;
        if (updateXmlNode2 == null || updateXmlNode2.getPriority() <= updateXmlNode.getPriority()) {
            boolean is64Bit = MyApp.is64Bit();
            boolean ForArm64Rule = updateXmlNode.ForArm64Rule();
            if (ForArm64Rule != is64Bit) {
                StringBuilder sb = new StringBuilder();
                sb.append("Can't match the bit. App is [");
                sb.append(is64Bit ? "64" : "32");
                sb.append("], rule is for [");
                sb.append(ForArm64Rule ? "64" : "32");
                sb.append("]");
                str = sb.toString();
            } else if (grayIsHit(updateXmlNode.getGray())) {
                long targetVersionCodeLow = updateXmlNode.getTargetVersionCodeLow();
                long targetVersionCodeHigh = updateXmlNode.getTargetVersionCodeHigh();
                long versionCode = MyApp.getVersionCode();
                int i = (targetVersionCodeHigh > 0L ? 1 : (targetVersionCodeHigh == 0L ? 0 : -1));
                boolean z2 = i < 0 || targetVersionCodeLow < 0 ? targetVersionCodeLow < 0 ? i < 0 || versionCode <= targetVersionCodeHigh : versionCode >= targetVersionCodeLow : versionCode >= targetVersionCodeLow && versionCode <= targetVersionCodeHigh;
                Log.d(TAG, "Current Version: [" + versionCode + "] Low Version Limit: [" + targetVersionCodeLow + "] High Version Limit: [" + targetVersionCodeHigh + "]");
                if (!z2) {
                    str = "Current version code isn't in target version code range.";
                } else if (updateXmlNode.getVersionCode() <= versionCode) {
                    str = "Version code [" + updateXmlNode.getVersionCode() + "] is less than current version code [" + versionCode + "]";
                } else {
                    if (this.mHitRuleNode == null) {
                        this.mHitRuleNode = new UpdateXmlNode();
                    }
                    this.mHitRuleNode.setXmlNode(updateXmlNode.getXmlNode());
                    str = null;
                    z = true;
                }
            } else {
                str = "The device isn't in the gray range.";
            }
        } else {
            str = "Already hit a higher priority rule with this rule.";
        }
        if (!z) {
            Log.d(TAG, "Don't hit " + updateXmlNode.getId() + ", Cause: " + str);
        }
        return z;
    }

    private void clearLastUpdateInfo() {
        ConfigMgr.delGlobal(PREFERENCE_UPDATE_FROM_VERSION);
        ConfigMgr.delGlobal(PREFERENCE_UPDATE_TARGET_VERSION);
        ConfigMgr.delGlobal(PREFERENCE_UPDATE_RULE_ID);
        ConfigMgr.delGlobal(PREFERENCE_UPDATE_FILE_PATH);
    }

    public boolean dealWithNewApk(UpdateXmlNode updateXmlNode, BaseDownloadTask baseDownloadTask) {
        return dealWithNewApk(updateXmlNode, baseDownloadTask, false);
    }

    public boolean dealWithNewApk(UpdateXmlNode updateXmlNode, BaseDownloadTask baseDownloadTask, boolean z) {
        String path = baseDownloadTask.getPath();
        File file = new File(path);
        String fileMd5 = FileUtil.getFileMd5(file);
        if (fileMd5 == null) {
            Log.d(TAG, "The md5 of download file is illegal.");
        } else {
            synchronized (this) {
                if (!this.mUpdateStop) {
                    Log.d(TAG, "download Size: " + file.length() + " bean file size: " + updateXmlNode.getFileSize());
                    Log.d(TAG, "download file md5: " + fileMd5 + " update file md5: " + updateXmlNode.getMd5());
                    if (updateXmlNode.getFileSize() == file.length() && fileMd5.toUpperCase().equals(updateXmlNode.getMd5().toUpperCase())) {
                        ReportModule.getInstance().recordUpdateProcess(4, "0");
                        ReportModule.getInstance().recordUpdateProcess(7, "");
                        savePreferencesInfo(path);
                        ApkInstallUtils.install(MyApp.getContext(), path);
                        return true;
                    } else if (z) {
                        FileUtil.deleteFile(new File(path));
                    }
                }
            }
        }
        return false;
    }

    public synchronized void finishUpdate(final boolean z) {
        this.mUpdateStop = true;
        this.mSyncContext = null;
        this.mAsyncContext = null;
        this.mIsUpdateOnStartup = false;
        dismissUpdateDialog();
        ReportModule.getInstance().reportUpdateProcess(new ReportModule.ReportListener() {
            @Override
            public void onReportFinish(boolean z2) {
                if (z) {
                    SystemUtil.exitApp();
                }
            }
        });
    }

    public static AppUpdateModule getInstance() {
        if (sInstance == null) {
            synchronized (AppUpdateModule.class) {
                if (sInstance == null) {
                    sInstance = new AppUpdateModule();
                }
            }
        }
        return sInstance;
    }

    private boolean grayIsHit(float f) {
        int parseInt = Integer.parseInt(DeviceUtil.DeviceUuidFactory2.getUuid().substring(0, 2), 16);
        int i = (int) (255.0f * f);
        Log.d(TAG, "Gray: " + f + ", Gray flag: " + parseInt + ", Gray limit: " + i);
        return parseInt <= i;
    }

    public void onDownloadStop() {
        if (0 != this.mDownloadConsumeTime) {
            this.mDownloadConsumeTime = System.currentTimeMillis() - this.mDownloadConsumeTime;
            ReportModule.getInstance().recordUpdateProcess(6, String.valueOf(this.mDownloadConsumeTime));
            this.mDownloadConsumeTime = 0L;
        }
        if (0 != this.mDownloadedSize) {
            ReportModule.getInstance().recordUpdateProcess(5, String.valueOf(this.mDownloadedSize));
            this.mDownloadedSize = 0L;
        }
    }

    public void onUserChooseUpdate(final UpdateDownloadDialog updateDownloadDialog, final UpdateXmlNode updateXmlNode) {
        ReportModule.getInstance().recordUpdateProcess(3, "0");
        if (!updateXmlNode.isStoreUpdate()) {
            Observable.create(new ObservableOnSubscribe<String>() {
                @Override
                public void subscribe(ObservableEmitter<String> observableEmitter) throws Exception {
                    String downloadUrl = updateXmlNode.getDownloadUrl();
                    if (TextUtils.isEmpty(downloadUrl)) {
                        String jumpUrl = updateXmlNode.getJumpUrl();
                        if (TextUtils.isEmpty(jumpUrl)) {
                            observableEmitter.onNext(ResourceUtil.getString(R.string.update_dialog_xml_info_incorrect));
                            return;
                        }
                        IntentUtil.startSystemBrowser(jumpUrl);
                        AppUpdateModule.this.finishUpdate(false);
                        return;
                    }
                    String fileName = updateXmlNode.getFileName();
                    if (TextUtils.isEmpty(fileName)) {
                        NetworkUtil.createDownloadTask(downloadUrl, "App", updateDownloadDialog.getFileDownloadListener()).start();
                    } else {
                        String str = PathUtil.getDiskCatchDir() + InternalZipConstants.ZIP_FILE_SEPARATOR + fileName;
                        if (AppUpdateModule.this.mCurrentDownloadtask != null && AppUpdateModule.this.mCurrentDownloadtask.isRunning()) {
                            AppUpdateModule.this.mCurrentDownloadtask.pause();
                        }
                        AppUpdateModule.this.mCurrentDownloadtask = NetworkUtil.createDownloadTask(downloadUrl, "App", str, updateDownloadDialog.getFileDownloadListener());
                        AppUpdateModule appUpdateModule = AppUpdateModule.this;
                        if (appUpdateModule.dealWithNewApk(appUpdateModule.mHitRuleNode, AppUpdateModule.this.mCurrentDownloadtask)) {
                            Log.d(AppUpdateModule.TAG, "Async check pass.");
                            AppUpdateModule.this.finishUpdate(updateXmlNode.isForceUpdate());
                            return;
                        } else if (AppUpdateModule.this.mUpdateStop) {
                            return;
                        } else {
                            AppUpdateModule.this.mCurrentDownloadtask.start();
                        }
                    }
                    AppUpdateModule.this.mDownloadConsumeTime = System.currentTimeMillis();
                }
            }).subscribeOn(Schedulers.newThread()).observeOn(AndroidSchedulers.mainThread()).doOnNext(new Consumer<String>() {
                @Override
                public void accept(String str) throws Exception {
                    AppUpdateModule.this.mAppUpdateDialog.showMessage(str, new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {
                            AppUpdateModule.this.finishUpdate(false);
                        }
                    });
                }
            }).subscribe();
            return;
        }
        if (this.mMarketNames == null) {
            SparseArray<String> sparseArray = new SparseArray<>();
            this.mMarketNames = sparseArray;
            sparseArray.put(10001, "com.tencent.android.qqdownloader");
            this.mMarketNames.put(10002, "com.huawei.appmarket");
            this.mMarketNames.put(10003, "com.xiaomi.market");
            this.mMarketNames.put(10004, "com.bbk.appstore");
            this.mMarketNames.put(10005, "com.oppo.market");
            this.mMarketNames.put(10006, "com.baidu.appsearch");
        }
        if (!GeneralUtil.goToMarket(this.mMarketNames.get(Integer.parseInt(MyApp.getChannelId())))) {
            GeneralUtil.goToMarket(null);
        }
        finishUpdate(updateXmlNode.isForceUpdate());
    }

    public void parseUpdateXml() throws IOException, XmlPullParserException {
        this.mHitRuleNode = null;
        XmlUtil.parseXml(Uri.parse(MyApp.isDebugMode() ? DEBUG_UPDATE_XML_URL : RELEASE_UPDATE_XML_URL).buildUpon().appendQueryParameter("package", MyApp.getContext().getPackageName()).build().toString(), new XmlUtil.ParseEventListener() {
            private boolean mChannelIsMatch = false;
            private boolean mItemIsMatch = false;
            private boolean mIntoRootTag = false;
            private String mCurrentChannelId = MyApp.getChannelId();
            private UpdateXmlNode mUpdateXmlNode = new UpdateXmlNode();

            @Override
            public boolean onNodeEnd(XmlUtil.XmlNode xmlNode) {
                this.mUpdateXmlNode.setXmlNode(xmlNode);
                if (this.mUpdateXmlNode.isItemNode()) {
                    this.mItemIsMatch = false;
                    return false;
                }
                return this.mUpdateXmlNode.isChannelNode();
            }

            @Override
            public boolean onNodeStart(XmlUtil.XmlNode xmlNode) {
                boolean z;
                this.mUpdateXmlNode.setXmlNode(xmlNode);
                if (this.mIntoRootTag || !this.mUpdateXmlNode.isRootTag()) {
                    if (!this.mItemIsMatch && this.mUpdateXmlNode.isItemNode()) {
                        z = this.mUpdateXmlNode.typeIsApp();
                        this.mItemIsMatch = z;
                    } else if (!this.mChannelIsMatch && this.mUpdateXmlNode.isChannelNode()) {
                        String channelId = this.mUpdateXmlNode.getChannelId();
                        if (!TextUtils.isEmpty(channelId)) {
                            this.mChannelIsMatch = channelId.equals(this.mCurrentChannelId);
                        }
                        z = this.mChannelIsMatch;
                    } else if (this.mUpdateXmlNode.isRuleNode() && AppUpdateModule.this.checkUpdateRule(this.mUpdateXmlNode)) {
                        Log.d(AppUpdateModule.TAG, "[id]: " + this.mUpdateXmlNode.getId() + " has hit!");
                    }
                    return !z;
                }
                this.mIntoRootTag = true;
                return false;
            }
        });
    }

    public void reportUpdateResult() {
        long longValue = ((Long) ConfigMgr.getGlobal(PREFERENCE_UPDATE_TARGET_VERSION, -1L)).longValue();
        long versionCode = MyApp.getVersionCode();
        Log.d(TAG, "[appTargetVersion]: " + longValue + "[currentVersion]: " + versionCode);
        if (longValue > 0 && longValue == versionCode) {
            ReportModule reportModule = ReportModule.getInstance();
            reportModule.recordUpdateResult(0, (String) ConfigMgr.getGlobal(PREFERENCE_UPDATE_FROM_VERSION, ""));
            int intValue = ((Integer) ConfigMgr.getGlobal(PREFERENCE_UPDATE_RULE_ID, -1)).intValue();
            if (intValue >= 0) {
                reportModule.recordUpdateResult(1, String.valueOf(intValue));
            }
            String str = (String) ConfigMgr.getGlobal(PREFERENCE_UPDATE_FILE_PATH, "");
            if (!TextUtils.isEmpty(str)) {
                FileUtil.deleteFile(new File(str));
            }
            Log.d(TAG, "Report update successful info!");
            reportModule.reportUpdateResult();
        }
        clearLastUpdateInfo();
    }

    private void savePreferencesInfo(String str) {
        ConfigMgr.setGlobal(PREFERENCE_UPDATE_FROM_VERSION, MyApp.getVersionName());
        ConfigMgr.setGlobal(PREFERENCE_UPDATE_TARGET_VERSION, Long.valueOf(this.mHitRuleNode.getVersionCode()));
        ConfigMgr.setGlobal(PREFERENCE_UPDATE_RULE_ID, Integer.valueOf(this.mHitRuleNode.getId()));
        ConfigMgr.setGlobal(PREFERENCE_UPDATE_FILE_PATH, str);
    }

    public void showUpdateDialog(Context context) {
        if (this.mAppUpdateDialog == null) {
            UpdateDownloadDialog<UpdateXmlNode> updateDownloadDialog = new UpdateDownloadDialog<>(context, this.mHitRuleNode, this.mIsSyncUpdate);
            this.mAppUpdateDialog = updateDownloadDialog;
            updateDownloadDialog.setEventListener(new AnonymousClass6());
        }
        if (!this.mIsSyncUpdate) {
            String contentText = this.mHitRuleNode.getContentText();
            if (!TextUtils.isEmpty(contentText)) {
                this.mAppUpdateDialog.setUpdateContent(contentText.replace("\\n", "\n"));
            }
        }
        if (this.mAppUpdateDialog.isShowing()) {
            return;
        }
        this.mAppUpdateDialog.show();
    }

    public void showUpdateDialogOnStartup(Context context) {
        if (this.mHitRuleNode == null) {
            if (MyApp.isDebugMode()) {
                throw new RuntimeException("The hit rule node is null! Logical is illegal!");
            }
            Log.d(TAG, "The hit rule node is null! Logical is illegal!");
        }
        if (!this.mHitRuleNode.isReminderOnStartUp()) {
            Log.d(TAG, "Don't reminder update on start up");
            return;
        }
        long currentTimeMillis = System.currentTimeMillis() / 1000;
        boolean z = false;
        int i = AnonymousClass9.$SwitchMap$com$vphonegaga$titan$module$update$UpdateXmlNode$ReminderFrequencyType[this.mHitRuleNode.getReminderFrequencyType().ordinal()];
        if (i != 1) {
            if (i == 2) {
                long j = currentTimeMillis - this.mLastReminderTime;
                Log.d(TAG, "Last reminder time: " + this.mLastReminderTime + " Current time: " + currentTimeMillis + " interval: " + j);
            } else if (i == 3) {
                long appStartNumber = MyApp.getAppStartNumber() - this.mLastReminderStartupNumber;
                Log.d(TAG, "Current startup number: " + MyApp.getAppStartNumber() + ", Last reminder startup number: " + this.mLastReminderStartupNumber + ", startup interval: " + appStartNumber);
            } else if (i != 4) {
                Log.d(TAG, "The reminder frequency type is illegal!");
            } else {
                Log.d(TAG, "unknown");
            }
            if (z) {
                return;
            }
            showUpdateDialog(context);
            this.mLastReminderTime = currentTimeMillis;
            ConfigMgr.setGlobal(PREFERENCE_UPDATE_LAST_REMINDER_TIME, Long.valueOf(currentTimeMillis));
            long appStartNumber2 = MyApp.getAppStartNumber();
            this.mLastReminderStartupNumber = appStartNumber2;
            ConfigMgr.setGlobal(PREFERENCE_UPDATE_LAST_REMINDER_STARTUP_NUMBER, Long.valueOf(appStartNumber2));
            return;
        }
        z = true;
        if (z) {
        }
    }

    public boolean asyncCheckUpdate(Context context, boolean z) {
        synchronized (this) {
            if (this.mUpdateStop) {
                this.mIsUpdateOnStartup = z;
                this.mIsSyncUpdate = false;
                this.mAsyncContext = context;
                checkUpdate(null);
                return true;
            }
            return false;
        }
    }

    public void dismissUpdateDialog() {
        UpdateDownloadDialog<UpdateXmlNode> updateDownloadDialog = this.mAppUpdateDialog;
        if (updateDownloadDialog == null || !updateDownloadDialog.isShowing()) {
            return;
        }
        this.mAppUpdateDialog.dismiss();
        this.mAppUpdateDialog = null;
    }

    public void onAttachedActivityDestroy() {
        cancelUpdate();
        finishUpdate(false);
    }

    public boolean syncCheckUpdate(Context context) {
        synchronized (this) {
            if (this.mUpdateStop) {
                this.mIsUpdateOnStartup = false;
                this.mIsSyncUpdate = true;
                this.mSyncContext = context;
                showUpdateDialog(context);
                checkUpdate(new OnCheckUpdateListener() {
                    @Override
                    public void onComplete() {
                        if (AppUpdateModule.this.mHitRuleNode == null) {
                            AppUpdateModule.this.mAppUpdateDialog.showMessage(ResourceUtil.getString(R.string.update_dialog_check_no_update), new View.OnClickListener() {
                                @Override
                                public void onClick(View view) {
                                    AppUpdateModule.this.finishUpdate(false);
                                }
                            });
                            return;
                        }
                        AppUpdateModule.this.mAppUpdateDialog.setBean(AppUpdateModule.this.mHitRuleNode);
                        String contentText = AppUpdateModule.this.mHitRuleNode.getContentText();
                        if (!TextUtils.isEmpty(contentText)) {
                            AppUpdateModule.this.mAppUpdateDialog.setUpdateContent(contentText.replace("\\n", "\n"));
                        }
                        AppUpdateModule.this.mAppUpdateDialog.onSyncCheckHasUpdate();
                    }

                    @Override
                    public void onError() {
                        AppUpdateModule.this.mAppUpdateDialog.showMessage(ResourceUtil.getString(R.string.update_dialog_check_has_error), new View.OnClickListener() {
                            @Override
                            public void onClick(View view) {
                                AppUpdateModule.this.finishUpdate(false);
                            }
                        });
                    }
                });
                return true;
            }
            return false;
        }
    }
}