导航菜单

页面标题

页面副标题

管控平台 v5.2.3.0. - UDPService.java 源代码

正在查看: 管控平台 v5.2.3.0. 应用的 UDPService.java JAVA 源代码文件

本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。


package com.iflytek.mdmservice.service;

import android.app.DownloadManager;
import android.app.IntentService;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.database.Cursor;
import android.text.TextUtils;
import com.alibaba.fastjson.JSON;
import com.iflytek.mdmcommon.LogUtil;
import com.iflytek.mdmcommon.NetUtil;
import com.iflytek.mdmservice.MDMApp;
import com.iflytek.mdmservice.db.AppInfoManager;
import com.iflytek.mdmservice.db.UdpDownloadTaskManager;
import com.iflytek.mdmservice.db.entity.AppInfo;
import com.iflytek.mdmservice.db.entity.DeviceInfo;
import com.iflytek.mdmservice.db.entity.UdpDownloadTask;
import com.iflytek.mdmservice.model.UDPApps;
import com.igexin.sdk.PushConsts;
import java.io.File;
import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.SocketException;
import java.util.HashMap;
import java.util.List;
import net.sqlcipher.BuildConfig;

public class UDPService extends IntentService {

    DatagramSocket f515a;

    DownloadManager f516b;

    public UDPService() {
        super("UDPService");
        this.f515a = null;
    }

    private String a(List<String> list) {
        if (list == null || list.isEmpty()) {
            return BuildConfig.FLAVOR;
        }
        if (!NetUtil.isWifiConnected(MDMApp.j())) {
            return list.get(0);
        }
        for (String str : list) {
            String ipByUrl = NetUtil.getIpByUrl(str);
            if (NetUtil.isIP(ipByUrl) && NetUtil.isSameLan(MDMApp.j(), NetUtil.ipToInt(ipByUrl))) {
                return str;
            }
        }
        return list.get(0);
    }

    private void b(String str) {
        UDPApps uDPApps;
        if (TextUtils.isEmpty(str) || (uDPApps = (UDPApps) JSON.parseObject(str, UDPApps.class)) == null || uDPApps.getStu() == null || uDPApps.getStu().size() <= 0) {
            return;
        }
        List<UDPApps.UDPAppInfo> stu = uDPApps.getStu();
        List<AppInfo> appInfos = AppInfoManager.getInstance().getAppInfos();
        HashMap hashMap = new HashMap();
        for (AppInfo appInfo : appInfos) {
            hashMap.put(appInfo.getPackageName(), appInfo);
        }
        for (UDPApps.UDPAppInfo uDPAppInfo : stu) {
            PackageInfo packageInfo = null;
            try {
                packageInfo = getPackageManager().getPackageInfo(uDPAppInfo.getPackageName(), 0);
            } catch (PackageManager.NameNotFoundException e) {
                LogUtil.e(e.getMessage());
            }
            if (packageInfo == null || uDPAppInfo.getVersion() > packageInfo.versionCode) {
                AppInfo appInfo2 = (AppInfo) hashMap.get(uDPAppInfo.getPackageName());
                if (appInfo2 == null) {
                    LogUtil.c("udpservicedownload", "不在白名单中");
                } else if (!appInfo2.getIsLimitVersion().equals("1") || appInfo2.getVersionCode() >= uDPAppInfo.getVersion()) {
                    c(uDPAppInfo);
                } else {
                    LogUtil.c("udpservicedownload", "限制版本为" + appInfo2.getVersionCode());
                    LogUtil.c("udpservicedownload", "此版本为" + uDPAppInfo.getVersion());
                }
            } else {
                LogUtil.c("udpservicedownload", "已安装");
            }
        }
    }

    private synchronized void c(UDPApps.UDPAppInfo uDPAppInfo) {
        UdpDownloadTask udpDownloadTask = UdpDownloadTaskManager.getInstance().getUdpDownloadTask(uDPAppInfo.getPackageName(), uDPAppInfo.getVersion());
        if (udpDownloadTask == null) {
            d(uDPAppInfo);
        } else {
            Long downloadId = udpDownloadTask.getDownloadId();
            DownloadManager.Query query = new DownloadManager.Query();
            query.setFilterById(downloadId.longValue());
            Cursor cursor = null;
            try {
                Cursor query2 = this.f516b.query(query);
                if (query2.moveToFirst()) {
                    int i = query2.getInt(query2.getColumnIndex(DeviceInfo.STATUS));
                    String string = query2.getString(query2.getColumnIndex("local_filename"));
                    if (TextUtils.isEmpty(string)) {
                        this.f516b.remove(downloadId.longValue());
                        UdpDownloadTaskManager.getInstance().removeUdpDownloadTask(uDPAppInfo.getPackageName(), uDPAppInfo.getVersion());
                        d(uDPAppInfo);
                    } else if (i == 16) {
                        this.f516b.remove(downloadId.longValue());
                        UdpDownloadTaskManager.getInstance().removeUdpDownloadTask(uDPAppInfo.getPackageName(), uDPAppInfo.getVersion());
                        d(uDPAppInfo);
                    } else if (i == 8) {
                        if (new File(string).exists()) {
                            com.iflytek.mdmservice.utils.s.a(MDMApp.j()).c(udpDownloadTask, string);
                        } else {
                            this.f516b.remove(downloadId.longValue());
                            UdpDownloadTaskManager.getInstance().removeUdpDownloadTask(uDPAppInfo.getPackageName(), uDPAppInfo.getVersion());
                            d(uDPAppInfo);
                        }
                    }
                    LogUtil.c("udpservicedownload", ": status  " + i + " packageName " + udpDownloadTask.getPackageName());
                } else {
                    d(uDPAppInfo);
                }
                if (query2 != null) {
                    query2.close();
                }
            } catch (Throwable th) {
                if (0 != 0) {
                    cursor.close();
                }
                throw th;
            }
        }
    }

    private void d(UDPApps.UDPAppInfo uDPAppInfo) {
        LogUtil.c("udpservicedownload", ": service开始下载 " + uDPAppInfo.toString());
        UdpDownloadTask udpDownloadTask = new UdpDownloadTask();
        udpDownloadTask.setPackageName(uDPAppInfo.getPackageName());
        udpDownloadTask.setVersionCode((long) uDPAppInfo.getVersion());
        udpDownloadTask.setFileName(uDPAppInfo.getPackageName().replace(".", "_") + ".apk");
        udpDownloadTask.setDownloadUrl(a(uDPAppInfo.getUrl()));
        com.iflytek.mdmservice.utils.s.a(MDMApp.j()).b(udpDownloadTask);
    }

    public static void e() {
    }

    @Override
    public void onCreate() {
        super.onCreate();
        this.f516b = (DownloadManager) getSystemService("download");
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        LogUtil.c("udpservicedownload", "onDestroy");
        DatagramSocket datagramSocket = this.f515a;
        if (datagramSocket != null) {
            datagramSocket.close();
            this.f515a = null;
        }
    }

    @Override
    protected void onHandleIntent(Intent intent) {
        DatagramSocket datagramSocket;
        LogUtil.c("udpservicedownload", "start");
        try {
            if (this.f515a != null) {
                LogUtil.c("udpservicedownload", "UDP服务已启动");
                return;
            }
            try {
                try {
                    try {
                        DatagramSocket datagramSocket2 = new DatagramSocket(PushConsts.MIN_OPEN_FEEDBACK_ACTION);
                        this.f515a = datagramSocket2;
                        datagramSocket2.setSoTimeout(31000);
                        if (this.f515a != null) {
                            DatagramPacket datagramPacket = new DatagramPacket(new byte[1048576], 1048576);
                            this.f515a.receive(datagramPacket);
                            byte[] data = datagramPacket.getData();
                            int length = datagramPacket.getLength();
                            String str = new String(data, 0, length);
                            LogUtil.c("udpservicedownload", "json: " + str);
                            LogUtil.c("udpservicedownload", "data.length: " + data.length);
                            LogUtil.c("udpservicedownload", "receivePacket.length: " + length);
                            b(str);
                        }
                        datagramSocket = this.f515a;
                        if (datagramSocket == null) {
                            return;
                        }
                    } catch (IOException e) {
                        LogUtil.e(e.getMessage());
                        datagramSocket = this.f515a;
                        if (datagramSocket == null) {
                            return;
                        }
                    }
                } catch (Exception e2) {
                    LogUtil.e(e2.getMessage());
                    datagramSocket = this.f515a;
                    if (datagramSocket == null) {
                        return;
                    }
                }
            } catch (SocketException e3) {
                LogUtil.e(e3.getMessage());
                datagramSocket = this.f515a;
                if (datagramSocket == null) {
                    return;
                }
            }
            datagramSocket.close();
        } catch (Throwable th) {
            DatagramSocket datagramSocket3 = this.f515a;
            if (datagramSocket3 != null) {
                datagramSocket3.close();
            }
            throw th;
        }
    }
}