Update v1.2.2版本的 MD5 值为:87ab33f0c8bd4c1dd345062aa2794e73

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


package com.luxcine.luxcine_ota;

import android.app.AlertDialog;
import android.app.Service;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Build;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.os.Handler;
import android.os.IBinder;
import android.os.Message;
import android.os.RecoverySystem;
import android.os.SystemProperties;
import android.util.Log;
import android.util.Xml;
import android.view.KeyEvent;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.ProgressBar;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
import cn.bmob.v3.BmobQuery;
import cn.bmob.v3.exception.BmobException;
import cn.bmob.v3.listener.FindListener;
import cn.bmob.v3.listener.SaveListener;
import cn.bmob.v3.listener.UpdateListener;
import com.luxcine.luxcine_ota.download.DownLoadObserver;
import com.luxcine.luxcine_ota.download.DownloadInfo;
import com.luxcine.luxcine_ota.download.DownloadManager;
import com.luxcine.luxcine_ota.upload.Device;
import com.luxcine.luxcine_ota.utils.Data;
import com.luxcine.luxcine_ota.utils.MD5;
import com.luxcine.luxcine_ota.utils.ReadTxt;
import java.io.File;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import org.xmlpull.v1.XmlPullParser;
public class MainActivity extends AppCompatActivity {
    private static final String BASE_URL_UPDATE_CN = "http://120.24.53.73:80/otaupdate/xml/";
    private static final String BASE_URL_UPDATE_HK = "http://www.chasecolor.com:8080/otaupdate/xml/";
    private static final int DOWNLOAD_FIALED = 2;
    private static final String FILE_NAME = "/data/data/com.luxcine.luxcine_ota/update.zip";
    private static final String FILE_PATH = "/data/data/com.luxcine.luxcine_ota/";
    private static final int INSTALL_TOKEN = 1;
    private static final int RESULT = 0;
    private static final int RESULT_UPDATE = 1;
    private static final String TAG = "MainActivity";
    private static final int UI_CALIBRATION = 5;
    private static final int UI_UPDATE = 3;
    private static final int VERIFICATION_FIALED = 4;
    private static Button btnUpdate;
    private static CountDownTimer countDownTimer;
    private static SharedPreferences.Editor editor;
    private static Handler handler = new Handler() {
        @Override
        public void handleMessage(Message message) {
            switch (message.what) {
                case 0:
                    MainActivity.tvNewVersion.setText(MyApplication.getContext().getResources().getString(R.string.already_new));
                    MainActivity.btnUpdate.setVisibility(8);
                    return;
                case 1:
                    TextView textView = MainActivity.tvNewVersion;
                    textView.setText(MyApplication.getContext().getResources().getString(R.string.new_version) + MainActivity.newVersion);
                    MainActivity.btnUpdate.setVisibility(0);
                    return;
                case 2:
                    MainActivity.btnUpdate.setVisibility(0);
                    MainActivity.btnUpdate.requestFocus();
                    MainActivity.tvFailed.setVisibility(0);
                    MainActivity.tvProgesss.setVisibility(8);
                    MainActivity.progressBar.setVisibility(8);
                    MainActivity.tvFailed.setText(MyApplication.getContext().getResources().getString(R.string.download_failed));
                    return;
                case 3:
                    if (MainActivity.btnUpdate.getVisibility() == 0) {
                        MainActivity.btnUpdate.setVisibility(8);
                    }
                    MainActivity.tvProgesss.setVisibility(0);
                    MainActivity.progressBar.setVisibility(0);
                    TextView textView2 = MainActivity.tvProgesss;
                    textView2.setText(MyApplication.getContext().getResources().getString(R.string.downloading) + MainActivity.progess + "%");
                    MainActivity.progressBar.setProgress(MainActivity.progess);
                    return;
                case 4:
                    MainActivity.btnUpdate.setVisibility(0);
                    MainActivity.btnUpdate.requestFocus();
                    MainActivity.tvFailed.setVisibility(0);
                    MainActivity.tvProgesss.setVisibility(8);
                    MainActivity.progressBar.setVisibility(8);
                    MainActivity.tvFailed.setText(MyApplication.getContext().getResources().getString(R.string.verification_failed));
                    return;
                case 5:
                    MainActivity.tvProgesss.setText(MyApplication.getContext().getResources().getString(R.string.calibration));
                    return;
                default:
                    return;
            }
        }
    };
    private static AlertDialog mDialog;
    private static String maxMd5;
    private static int maxVersion;
    private static String md5;
    private static String md5Url;
    private static String minMd5;
    private static int minVersion;
    private static int newVersion;
    private static int progess;
    private static ProgressBar progressBar;
    private static SharedPreferences sp;
    private static TextView tvFailed;
    private static TextView tvNewVersion;
    private static TextView tvProgesss;
    private static TextView tvSecond;
    private static String updateUrl;
    private String BASE_URL_UPDATE;
    private String device;
    private List<Data> list;
    private String logo;
    private String maxStoragemem;
    private String maxUrl;
    private String minStoragemem;
    private String minUrl;
    private String mode;
    private NetReciver netReceiver;
    private String productModel;
    private String storagemem;
    private String strUrl;
    private TextView tvOldVersion;
    private TextView tvVersion;
    private String usid = "";
    private int version = 0;
    private String launcher = "";
    private int startDownload = 0;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
        SharedPreferences sharedPreferences = getSharedPreferences("luxicne_ota", 0);
        sp = sharedPreferences;
        editor = sharedPreferences.edit();
        this.startDownload = sp.getInt("startDownload", 0);
        boolean isFileExists = fileIsExists(FILE_NAME);
        Log.e(TAG, "onCreate: -------文件存在:" + isFileExists + ",startDownload:" + this.startDownload);
        int i = this.startDownload;
        if (i == 2 || (i == 0 && isFileExists)) {
            deleteLocal(FILE_NAME);
        }
        this.netReceiver = new NetReciver();
        IntentFilter intentFilter = new IntentFilter("android.net.conn.CONNECTIVITY_CHANGE");
        registerReceiver(this.netReceiver, intentFilter);
        if (Build.VERSION.SDK_INT >= 23) {
            String[] permissions = {"android.permission.WRITE_EXTERNAL_STORAGE", "android.permission.READ_EXTERNAL_STORAGE"};
            for (String str : permissions) {
                if (checkSelfPermission(str) != 0) {
                    requestPermissions(permissions, 101);
                    try {
                        Thread.sleep(1000L);
                        return;
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                        return;
                    }
                }
            }
        }
        new InstallFactoryTest().versionComparison();
        this.usid = SystemProperties.get("ro.serialno", "marconi");
        String device = new GetDevice().getDevice();
        this.device = device;
        if (device.equals("LPHC") || this.device.equals("LYH1") || this.device.equals("LSHA") || this.device.equals("LHHX") || this.device.equals("LPHQ") || this.device.equals("LSHM") || this.device.equals("LPHW") || this.device.equals("LPHH")) {
            this.launcher = new GetLauncher().getLauncher();
            Log.e(TAG, "onCreate:------------ " + this.launcher);
        } else {
            this.launcher = initLauncher();
        }
        if (this.launcher.equals("dbos")) {
            this.BASE_URL_UPDATE = BASE_URL_UPDATE_CN;
        } else if (this.launcher.equals("atv")) {
            this.BASE_URL_UPDATE = BASE_URL_UPDATE_HK;
        }
        if (this.device.equals("LPHC") || this.device.equals("LYH1") || this.device.equals("LSHA") || this.device.equals("LHHX") || this.device.equals("LPHQ") || this.device.equals("LSHM") || this.device.equals("LPHW") || this.device.equals("LPHH")) {
            this.logo = SystemProperties.get("tv.boot.logo", "normal");
            this.version = Integer.parseInt(SystemProperties.get("ro.product.builddate", ""));
            this.tvOldVersion.setText(getResources().getString(R.string.current_version) + this.version);
        } else if (this.usid.contains("rk3328")) {
            this.productModel = SystemProperties.get("ro.product.name", "marconi");
            this.logo = "normal";
            this.version = Integer.parseInt(SystemProperties.get("ro.build.datename", ""));
            this.BASE_URL_UPDATE = BASE_URL_UPDATE_HK;
        } else {
            this.usid = SystemProperties.get("ro.serialno", "marconi");
            this.version = Integer.parseInt(SystemProperties.get("ro.build.version.incremental", ""));
            this.productModel = SystemProperties.get("ro.product.name", "marconi");
            this.logo = SystemProperties.get("tv.boot.logo", "normal");
            this.tvOldVersion.setText(getResources().getString(R.string.current_version) + this.version);
        }
        Log.e(TAG, "onCreate:------device:" + this.device + "," + this.launcher + "," + this.usid + "," + this.productModel + "," + this.logo + "," + this.version);
        if (this.device.equals("LPHC") || this.device.equals("LYH1") || this.device.equals("LSHA") || this.device.equals("LHHX") || this.device.equals("LPHQ") || this.device.equals("LSHM") || this.device.equals("LPHW") || this.device.equals("LPHH")) {
            this.mode = this.device;
            this.logo = SystemProperties.get("tv.boot.logo", "normal");
        } else if (this.usid.contains("rk3328")) {
            this.mode = "rk3328";
        } else if (this.usid.contains("rk3399")) {
            this.mode = "rk3399";
        } else {
            String substring = this.usid.substring(3, 5);
            this.usid = substring;
            if (substring.contains("Q7") || this.usid.contains("C7")) {
                this.mode = "c7";
            } else if (this.usid.contains("RT")) {
                this.mode = "rt1";
            } else if (this.usid.contains("WT")) {
                this.mode = "wt1";
            } else {
                this.mode = "z4";
            }
            if (this.productModel.equals("Ray-Smart") && this.logo.equals("")) {
                this.logo = "rombica";
            }
        }
        if ((this.mode + "_" + this.productModel + "_" + this.logo).equals("c7_marconi_artill_dolby")) {
            new InstallHBO().versionComparison();
        } else {
            if ((this.mode + "_" + this.productModel + "_" + this.logo).equals("z4_marconi_atv_blitzwoif")) {
                new InstallBlitzwoif().versionComparison();
            } else {
                if ((this.mode + "_" + this.productModel + "_" + this.logo).equals("c7_marconi_artill")) {
                    new InstallArtill().versionComparison();
                }
            }
        }
        if (this.device.equals("LPHC") || this.device.equals("LYH1") || this.device.equals("LSHA") || this.device.equals("LHHX") || this.device.equals("LPHQ") || this.device.equals("LSHM") || this.device.equals("LPHW") || this.device.equals("LPHH")) {
            this.strUrl = this.BASE_URL_UPDATE + "update/" + this.mode + "_" + this.launcher + "_" + this.logo + ".xml";
        } else {
            if ((this.mode + "_" + this.productModel + "_" + this.logo).equals("c7_marconi_artill_dolby")) {
                this.strUrl = this.BASE_URL_UPDATE + "update/" + this.mode + "_" + this.productModel + "_" + this.logo + "_test.xml";
            } else {
                if ((this.mode + "_" + this.productModel + "_" + this.logo).equals("z4_marconi_atv_blitzwoif")) {
                    this.strUrl = this.BASE_URL_UPDATE + "update/" + this.mode + "_" + this.productModel + "_" + this.logo + "_test.xml";
                } else {
                    if ((this.mode + "_" + this.productModel + "_" + this.logo).equals("c7_marconi_artill")) {
                        this.strUrl = this.BASE_URL_UPDATE + "update/" + this.mode + "_" + this.productModel + "_" + this.logo + "_test.xml";
                    } else {
                        this.strUrl = this.BASE_URL_UPDATE + "update/" + this.mode + "_" + this.productModel + "_" + this.logo + ".xml";
                    }
                }
            }
        }
        Log.e(TAG, "onCreate: ------读取文件:" + this.strUrl);
        getVersionCode();
    }

    @Override
    public void onDestroy() {
        unregisterReceiver(this.netReceiver);
        CountDownTimer countDownTimer2 = countDownTimer;
        if (countDownTimer2 != null) {
            countDownTimer2.cancel();
            countDownTimer = null;
        }
        super.onDestroy();
    }

    class NetReciver extends BroadcastReceiver {
        private static final String TAG = "NetBroadCastReciver";

        NetReciver() {
        }

        @Override
        public void onReceive(Context context, Intent intent) {
            if ("android.net.conn.CONNECTIVITY_CHANGE".equals(intent.getAction())) {
                ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService("connectivity");
                NetworkInfo info = (NetworkInfo) intent.getParcelableExtra("networkInfo");
                if (NetworkInfo.State.CONNECTED == info.getState()) {
                    Log.e(TAG, "onReceive: ---网络链接成功-----");
                    MainActivity.this.getVersionInfo();
                    return;
                }
                Log.e(TAG, "onReceive: ----网络链接失败------");
            }
        }
    }

    public void initView() {
        this.tvVersion = (TextView) findViewById(R.id.tv_version);
        this.tvOldVersion = (TextView) findViewById(R.id.tv_old_version);
        tvNewVersion = (TextView) findViewById(R.id.tv_new_version);
        btnUpdate = (Button) findViewById(R.id.btn_update);
        tvFailed = (TextView) findViewById(R.id.tv_failed);
        tvProgesss = (TextView) findViewById(R.id.tv_progesss);
        progressBar = (ProgressBar) findViewById(R.id.progesss);
        TextView textView = this.tvOldVersion;
        textView.setText(getResources().getString(R.string.current_version) + this.version);
        btnUpdate.requestFocus();
        btnUpdate.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                MainActivity.btnUpdate.setVisibility(8);
                MainActivity.tvFailed.setVisibility(8);
                MainActivity.tvProgesss.setVisibility(0);
                MainActivity.progressBar.setVisibility(0);
                Log.e(MainActivity.TAG, "onClick: ----------------");
                Intent intent = new Intent(MainActivity.this, DownloadService.class);
                MainActivity.this.startService(intent);
            }
        });
    }

    public void getVersionInfo() {
        Thread thread = new Thread() {
            @Override
            public void run() {
                String path = MainActivity.this.strUrl;
                try {
                    URL url = new URL(path);
                    HttpURLConnection conn = (HttpURLConnection) url.openConnection();
                    conn.setRequestMethod("GET");
                    conn.setConnectTimeout(5000);
                    conn.setReadTimeout(5000);
                    if (conn.getResponseCode() == 200) {
                        InputStream is = conn.getInputStream();
                        MainActivity.this.parseXmlInfo(is);
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        };
        thread.start();
    }

    public void parseXmlInfo(InputStream is) {
        String str;
        int min;
        List<Data> list;
        XmlPullParser xParser = Xml.newPullParser();
        try {
            xParser.setInput(is, "utf-8");
            Data data = null;
            for (int eventType = xParser.getEventType(); eventType != 1; eventType = xParser.next()) {
                switch (eventType) {
                    case 2:
                        if ("update".equals(xParser.getName())) {
                            this.list = new ArrayList();
                            break;
                        } else if ("version".equals(xParser.getName())) {
                            data = new Data();
                            break;
                        } else if ("date".equals(xParser.getName())) {
                            String date = xParser.nextText();
                            data.setDate(date);
                            break;
                        } else if ("url".equals(xParser.getName())) {
                            String url = xParser.nextText();
                            data.setUrl(url);
                            break;
                        } else if ("md5".equals(xParser.getName())) {
                            String md52 = xParser.nextText();
                            data.setMd5(md52);
                            break;
                        } else {
                            if ("storagemem".equals(xParser.getName())) {
                                String storagemem = xParser.nextText();
                                data.setStoragemem(storagemem);
                            } else if ("describe".equals(xParser.getName())) {
                                String describe = xParser.nextText();
                                data.setDescribe(describe);
                                break;
                            }
                            break;
                        }
                    case 3:
                        try {
                            if ("version".equals(xParser.getName())) {
                                this.list.add(data);
                                break;
                            }
                        } catch (Exception e) {
                            e = e;
                            str = TAG;
                            e.printStackTrace();
                            Log.e(str, "parseXmlInfo: --------e:" + e.toString());
                        }
                        break;
                }
            }
            Log.e(TAG, "parseXmlInfo: ---------版本条数:" + this.list.size());
            if (this.list.size() <= 0) {
                handler.sendEmptyMessage(0);
            }
            List<Data> list2 = this.list;
            int max = Integer.parseInt(list2.get(list2.size() - 1).getDate());
            int min2 = Integer.parseInt(this.list.get(0).getDate());
            for (int i = 0; i < this.list.size(); i++) {
                Log.e(TAG, "parseXmlInfo: -----所有版本:" + this.list.get(i).getDate());
            }
            Log.e(TAG, "parseXmlInfo: ----------最小版本:" + min2 + ",最新版本:" + max);
            int i2 = this.version;
            try {
                if (i2 < min2) {
                    min = min2;
                    newVersion = Integer.parseInt(this.list.get(0).getDate());
                    if (!this.device.equals("LPHC") && !this.device.equals("LYH1") && !this.device.equals("LSHA") && !this.device.equals("LHHX") && !this.device.equals("LPHQ") && !this.device.equals("LSHM") && !this.device.equals("LPHW") && !this.device.equals("LPHH")) {
                        updateUrl = this.BASE_URL_UPDATE + "download/zip/" + this.mode + "_" + this.productModel + "_" + this.logo + "/" + newVersion + "/" + this.version + "/update.zip";
                        md5Url = this.BASE_URL_UPDATE + "download/zip/" + this.mode + "_" + this.productModel + "_" + this.logo + "/" + newVersion + "/" + this.version + "/md5.txt";
                    }
                    updateUrl = this.BASE_URL_UPDATE + "download/zip/" + this.mode + "_" + this.launcher + "_" + this.logo + "/" + newVersion + "/" + this.version + "/update.zip";
                    md5Url = this.BASE_URL_UPDATE + "download/zip/" + this.mode + "_" + this.launcher + "_" + this.logo + "/" + newVersion + "/" + this.version + "/md5.txt";
                } else {
                    min = min2;
                    if (i2 < max) {
                        newVersion = Integer.parseInt(this.list.get(list.size() - 1).getDate());
                        if (!this.device.equals("LPHC") && !this.device.equals("LYH1") && !this.device.equals("LSHA") && !this.device.equals("LHHX") && !this.device.equals("LPHQ") && !this.device.equals("LSHM") && !this.device.equals("LPHH")) {
                            updateUrl = this.BASE_URL_UPDATE + "download/zip/" + this.mode + "_" + this.productModel + "_" + this.logo + "/" + newVersion + "/" + this.version + "/update.zip";
                            md5Url = this.BASE_URL_UPDATE + "download/zip/" + this.mode + "_" + this.productModel + "_" + this.logo + "/" + newVersion + "/" + this.version + "/md5.txt";
                        }
                        updateUrl = this.BASE_URL_UPDATE + "download/zip/" + this.mode + "_" + this.launcher + "_" + this.logo + "/" + newVersion + "/" + this.version + "/update.zip";
                        md5Url = this.BASE_URL_UPDATE + "download/zip/" + this.mode + "_" + this.launcher + "_" + this.logo + "/" + newVersion + "/" + this.version + "/md5.txt";
                    } else if (i2 >= max) {
                        List<Data> list3 = this.list;
                        newVersion = Integer.parseInt(list3.get(list3.size() - 1).getDate());
                    }
                }
                String str2 = "parseXmlInfo: --本地版本:" + this.version + ",最小版本:" + min + ",最新版本:" + newVersion + ",md5:" + md5 + ",storagemem:" + this.storagemem + ", updateUrl: " + updateUrl;
                str = TAG;
                try {
                    Log.e(str, str2);
                    Log.e(str, "parseXmlInfo: -----md5Url:" + md5Url);
                    String str3 = md5Url;
                    if (str3 != "" && str3 != null) {
                        md5 = ReadTxt.readTxt(str3);
                        Log.e(str, "parseXmlInfo: -------md5:" + md5);
                    }
                    if (this.version < newVersion) {
                        if (!(this.mode + "_" + this.productModel + "_" + this.logo).equals("c7_marconi_artill_dolby")) {
                            if (!(this.mode + "_" + this.productModel + "_" + this.logo).equals("z4_marconi_atv_blitzwoif")) {
                                if (!(this.mode + "_" + this.productModel + "_" + this.logo).equals("c7_marconi_artill")) {
                                    handler.sendEmptyMessage(1);
                                    return;
                                }
                            }
                        }
                        String sn = sp.getString("sn", "");
                        String str4 = SystemProperties.get("ro.serialno", "marconi");
                        this.usid = str4;
                        if (sn.equals(str4)) {
                            handler.sendEmptyMessage(1);
                        } else {
                            handler.sendEmptyMessage(0);
                        }
                        return;
                    }
                    handler.sendEmptyMessage(0);
                } catch (Exception e2) {
                    e = e2;
                    e.printStackTrace();
                    Log.e(str, "parseXmlInfo: --------e:" + e.toString());
                }
            } catch (Exception e3) {
                e = e3;
                str = TAG;
            }
        } catch (Exception e4) {
            e = e4;
            str = TAG;
        }
    }

    public static class DownloadService extends Service {
        @Override
        public IBinder onBind(Intent intent) {
            return null;
        }

        @Override
        public void onCreate() {
            super.onCreate();
            Log.e(MainActivity.TAG, "onCreate: ---------------DownloadService");
            download();
        }

        public void download() {
            Log.e(MainActivity.TAG, "download: -------parseXmlInfo------updateUrl:" + MainActivity.updateUrl + ",md5Url:" + MainActivity.md5Url);
            DownloadManager.getInstance().download(MainActivity.updateUrl, new DownLoadObserver() {
                @Override
                public void onNext(DownloadInfo value) {
                    super.onNext(value);
                    long p1 = value.getProgress();
                    long t1 = value.getTotal();
                    int p = (int) Math.floor(((p1 * 1.0d) / t1) * 100.0d);
                    int unused = MainActivity.progess = p;
                    MainActivity.handler.sendEmptyMessage(3);
                    if (p == 10 || p == 30 || p == 60 || p == 90) {
                        Log.e(MainActivity.TAG, "onNext: ----111--" + value.getProgress() + "," + value.getTotal() + "," + p + "%");
                    }
                    if (p == 100) {
                        MainActivity.handler.sendEmptyMessage(5);
                    }
                    MainActivity.editor.putInt("startDownload", 1);
                    MainActivity.editor.commit();
                }

                @Override
                public void onError(Throwable e) {
                    super.onError(e);
                    Log.e(MainActivity.TAG, "onError: -------" + e.toString());
                    DownloadManager.getInstance().cancel(MainActivity.updateUrl);
                    DownloadService.this.stopService(new Intent(MyApplication.getContext(), DownloadService.class));
                    MainActivity.handler.sendEmptyMessage(2);
                }

                @Override
                public void onComplete() {
                    if (this.downloadInfo != null) {
                        Log.e(MainActivity.TAG, "onComplete: --parseXmlInfo---下载完成:" + this.downloadInfo.getFileName() + "-DownloadComplete");
                        MainActivity.editor.putInt("startDownload", 2);
                        MainActivity.editor.commit();
                        String md5Download = MD5.getMD5(MainActivity.FILE_NAME);
                        Log.e(MainActivity.TAG, "onComplete: ------parseXmlInfo---md5:" + MainActivity.md5 + ",md5Download:" + md5Download);
                        if (MainActivity.md5 != "" && MainActivity.md5 != null && md5Download != null && md5Download != "" && MainActivity.md5.equalsIgnoreCase(md5Download)) {
                            String usid = SystemProperties.get("ro.board.platform", "marconi");
                            new GetDevice().getDevice();
                            if (!usid.contains("rk3328")) {
                                MainActivity.equalSN();
                                return;
                            } else {
                                MainActivity.update();
                                return;
                            }
                        }
                        MainActivity.deleteLocal(MainActivity.FILE_NAME);
                        DownloadManager.getInstance().cancel(MainActivity.updateUrl);
                        DownloadService.this.stopService(new Intent(MyApplication.getContext(), DownloadService.class));
                        MainActivity.handler.sendEmptyMessage(4);
                        Log.e(MainActivity.TAG, "onComplete: -----parseXmlInfo---校验失败---");
                    }
                }
            });
        }
    }

    public static void update() {
        try {
            RecoverySystem.verifyPackage(new File(FILE_NAME), new RecoverySystem.ProgressListener() {
                @Override
                public void onProgress(int progress) {
                    Log.e(MainActivity.TAG, "progress --------签名: " + progress);
                }
            }, null);
            RecoverySystem.installPackage(MyApplication.getContext(), new File(FILE_NAME));
        } catch (Exception e) {
            e.printStackTrace();
            Log.e(TAG, "onPostExecute: ----" + e.toString());
        }
    }

    private String getVersionCode() {
        String versionCode = null;
        try {
            versionCode = MyApplication.getContext().getPackageManager().getPackageInfo(MyApplication.getContext().getPackageName(), 0).versionName;
            TextView textView = this.tvVersion;
            textView.setText("version:" + versionCode);
            return versionCode;
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
            return versionCode;
        }
    }

    private static void powerOffDialog() {
        View view = View.inflate(MyApplication.getContext(), R.layout.dialog_power_off, null);
        AlertDialog.Builder builder = new AlertDialog.Builder(MyApplication.getContext());
        tvSecond = (TextView) view.findViewById(R.id.tv_second);
        builder.setView(view);
        AlertDialog create = builder.create();
        mDialog = create;
        Window window = create.getWindow();
        window.getDecorView().setPadding(0, 0, 0, 0);
        WindowManager.LayoutParams layoutParams = window.getAttributes();
        mDialog.getWindow().setDimAmount(0.7f);
        layoutParams.gravity = 17;
        layoutParams.width = -1;
        layoutParams.height = -1;
        window.setAttributes(layoutParams);
        window.getDecorView().setBackgroundColor(0);
        mDialog.getWindow().setType(2003);
        mDialog.show();
        mDialog.setOnKeyListener(new DialogInterface.OnKeyListener() {
            @Override
            public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
                if (keyCode == 3 || keyCode == 4 || keyCode == 82 || keyCode == 132 || keyCode == 135) {
                    return true;
                }
                return false;
            }
        });
    }

    private static void countDown() {
        if (countDownTimer == null) {
            countDownTimer = new CountDownTimer(11000L, 1000L) {
                @Override
                public void onTick(long millisUntilFinished) {
                    TextView textView = MainActivity.tvSecond;
                    textView.setText("" + (millisUntilFinished / 1000));
                }

                @Override
                public void onFinish() {
                    if (MainActivity.countDownTimer != null) {
                        MainActivity.countDownTimer.cancel();
                        CountDownTimer unused = MainActivity.countDownTimer = null;
                    }
                    if (MainActivity.mDialog.isShowing()) {
                        MainActivity.mDialog.dismiss();
                        AlertDialog unused2 = MainActivity.mDialog = null;
                    }
                }
            }.start();
        }
    }

    public String initLauncher() {
        PackageManager packageManager = MyApplication.getContext().getPackageManager();
        Intent intent = new Intent();
        intent.setAction("android.intent.action.MAIN");
        intent.addCategory("android.intent.category.LAUNCHER");
        List<ResolveInfo> ResolveInfos = packageManager.queryIntentActivities(intent, 0);
        for (ResolveInfo ri : ResolveInfos) {
            String packageName = ri.activityInfo.packageName;
            if (packageName.equals("com.google.android.youtube.tv")) {
                this.launcher = "atv";
            } else if (packageName.equals("com.dangbei.leard.leradlauncher.common") || packageName.equals("com.dangbei.mimir.lightos.home")) {
                this.launcher = "dbos";
            }
        }
        return this.launcher;
    }

    @Override
    public boolean dispatchKeyEvent(KeyEvent event) {
        if (mDialog == null) {
            btnUpdate.requestFocus();
        }
        return super.dispatchKeyEvent(event);
    }

    private static boolean fileIsExists(String filePath) {
        try {
            File f = new File(filePath);
            if (!f.exists()) {
                return false;
            }
            return true;
        } catch (Exception e) {
            return false;
        }
    }

    public static boolean deleteLocal(String path) {
        if (path != null) {
            File file = new File(path);
            if (file.exists()) {
                if (file.delete()) {
                    Log.e(TAG, "deleteLocal: ----parseXmlInfo--delete  success---------");
                    return true;
                }
                Log.e(TAG, "deleteLocal: ----parseXmlInfo--delete  failed---------");
                deleteLocal(path);
                return false;
            }
        }
        return true;
    }

    public static void equalSN() {
        final String usid;
        String device1 = new GetDevice().getDevice();
        if (device1.equals("LPHC") || device1.equals("LYH1") || device1.equals("LSHA") || device1.equals("LHHX") || device1.equals("LPHQ") || device1.equals("LSHM")) {
            usid = new GetUsid().getUsid();
        } else {
            usid = SystemProperties.get("ro.serialno", "marconi");
        }
        BmobQuery<Device> bmobQuery = new BmobQuery<>();
        bmobQuery.addWhereEqualTo("sn", usid);
        bmobQuery.findObjects(new FindListener<Device>() {
            @Override
            public void done(List<Device> object, BmobException e) {
                if (e == null) {
                    if (object.size() > 0) {
                        for (int i = 0; i < object.size(); i++) {
                            String sn = object.get(i).getSn();
                            String objectId = object.get(i).getObjectId();
                            Log.e(MainActivity.TAG, "done: --------查询成功:" + sn + "--" + objectId);
                            if (sn.equals(usid)) {
                                MainActivity.modify(objectId);
                            }
                        }
                        return;
                    }
                    MainActivity.uploadBmob();
                    return;
                }
                Log.e(MainActivity.TAG, "done: ------查询失败:" + e.getMessage() + "," + e.getErrorCode());
            }
        });
    }

    public static void modify(String objectId) {
        final String usid;
        String oldVersion;
        String device1 = new GetDevice().getDevice();
        if (device1.equals("LPHC") || device1.equals("LYH1") || device1.equals("LSHA") || device1.equals("LHHX") || device1.equals("LPHQ") || device1.equals("LSHM")) {
            usid = new GetUsid().getUsid();
            oldVersion = SystemProperties.get("ro.product.builddate", "");
        } else {
            usid = SystemProperties.get("ro.serialno", "marconi");
            oldVersion = SystemProperties.get("ro.build.version.incremental", "");
        }
        Device device = new Device();
        device.setOldVersion(oldVersion);
        device.update(objectId, new UpdateListener() {
            @Override
            public void done(BmobException e) {
                if (e == null) {
                    Log.e(MainActivity.TAG, "done: ---更新成功版本:" + usid);
                    MainActivity.update();
                    return;
                }
                Log.e(MainActivity.TAG, "done: ---------- 更新版本失败:" + usid);
            }
        });
    }

    public static void uploadBmob() {
        String oldVersion;
        String device1 = new GetDevice().getDevice();
        if (device1.equals("LPHC") || device1.equals("LYH1") || device1.equals("LSHA") || device1.equals("LHHX") || device1.equals("LPHQ") || device1.equals("LSHM")) {
            new GetUsid().getUsid();
            oldVersion = SystemProperties.get("ro.product.builddate", "");
        } else {
            SystemProperties.get("ro.serialno", "marconi");
            oldVersion = SystemProperties.get("ro.build.version.incremental", "");
        }
        Device device = new Device();
        device.setOldVersion(oldVersion);
        device.save(new SaveListener<String>() {
            @Override
            public void done(String s, BmobException e) {
                if (e == null) {
                    Log.e(MainActivity.TAG, "------上传版本成功:" + s);
                    MainActivity.update();
                    return;
                }
                Log.e(MainActivity.TAG, "-----上传版本失败:" + e.getMessage());
            }
        });
    }
}