导航菜单

页面标题

页面副标题

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

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

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


package com.iflytek.mdmservice.service;

import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.Service;
import android.content.Intent;
import android.os.Build;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.IBinder;
import android.text.TextUtils;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.iflytek.mdmcommon.LogUtil;
import com.iflytek.mdmcommon.Utils;
import com.iflytek.mdmlibrary.MdmSdk;
import com.iflytek.mdmservice.MDMApp;
import com.iflytek.mdmservice.R$drawable;
import com.iflytek.mdmservice.db.entity.AppInfo;
import com.iflytek.mdmservice.db.entity.TeaCtrlAppPolicy;
import com.iflytek.mdmservice.db.impl.TeaCtrlAppPolicyDaoImpl;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Iterator;
import java.util.List;

public class AppUsePeriodCtrlService extends Service {

    private static final HandlerThread f441b;

    private static final Handler f442c;

    private final String[] f443a = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};

    static {
        HandlerThread handlerThread = new HandlerThread("app-ctrl");
        f441b = handlerThread;
        handlerThread.start();
        f442c = new Handler(f441b.getLooper());
    }

    private boolean a(String str, List<TeaCtrlAppPolicy> list, long j, int i) {
        boolean z = false;
        if (list == null || list.isEmpty()) {
            return false;
        }
        try {
            boolean z2 = false;
            boolean z3 = false;
            for (TeaCtrlAppPolicy teaCtrlAppPolicy : list) {
                try {
                    if (TextUtils.equals(str, teaCtrlAppPolicy.getAppPackage())) {
                        if (com.iflytek.mdmservice.o.d.e.a(teaCtrlAppPolicy.getDisableCycle(), i)) {
                            for (String str2 : teaCtrlAppPolicy.getDisableTime().split(";")) {
                                String[] split = str2.split("-");
                                long d = com.iflytek.mdmservice.o.d.e.d(split[0]);
                                long d2 = com.iflytek.mdmservice.o.d.e.d(split[1]) + 59000;
                                if (j >= d && j <= d2) {
                                    z2 = true;
                                    z3 = true;
                                    break;
                                }
                            }
                        }
                        z3 = true;
                    }
                    if (z3) {
                        return z2;
                    }
                } catch (Exception e) {
                    e = e;
                    z = z2;
                    LogUtil.c("AppUsePeriodCtrlService", "asAppInTeaPolicyNow err:" + e.getMessage());
                    return z;
                }
            }
            return z2;
        } catch (Exception e2) {
            e = e2;
        }
    }

    public static Handler b() {
        return f442c;
    }

    private void d() {
        f442c.post(new Runnable() {
            @Override
            public final void run() {
                AppUsePeriodCtrlService.this.c();
            }
        });
    }

    public void c() {
        boolean z;
        try {
            List<AppInfo> l = MDMApp.k().getAppInfoDao().queryBuilder().l();
            try {
                if (l != null && !l.isEmpty()) {
                    List<TeaCtrlAppPolicy> allPolicies = new TeaCtrlAppPolicyDaoImpl(MDMApp.j()).getAllPolicies();
                    Calendar calendar = Calendar.getInstance();
                    int i = calendar.get(7);
                    long timeInMillis = calendar.getTimeInMillis();
                    ArrayList arrayList = new ArrayList();
                    ArrayList arrayList2 = new ArrayList();
                    Iterator<AppInfo> it = l.iterator();
                    while (it.hasNext()) {
                        AppInfo next = it.next();
                        if (!"com.android.iflylauncher3".equals(next.getPackageName()) && !"com.iflytek.mdmservice".equals(next.getPackageName()) && !"com.iflytek.iflylogin".equals(next.getPackageName()) && !"com.iflytek.mdmstore".equals(next.getPackageName())) {
                            if (!"com.iflytek.mdmadmin".equals(next.getPackageName())) {
                                String usingTimeLimit = next.getUsingTimeLimit();
                                if (Utils.isJson(usingTimeLimit) || "{}".equals(usingTimeLimit)) {
                                    Iterator<AppInfo> it2 = it;
                                    if (a(next.getPackageName(), allPolicies, timeInMillis, i)) {
                                        LogUtil.c("AppUsePeriodCtrlService", next.getPackageName() + "在教师管控禁用时段内,不用执行下面可用时段的判断逻辑");
                                    } else {
                                        JSONArray jSONArray = JSON.parseObject(usingTimeLimit).getJSONArray(this.f443a[i - 1]);
                                        if (jSONArray != null && jSONArray.size() != 0) {
                                            int i2 = 0;
                                            while (true) {
                                                if (i2 >= jSONArray.size()) {
                                                    z = false;
                                                    break;
                                                }
                                                String string = jSONArray.getString(i2);
                                                if (com.iflytek.mdmservice.utils.f.c(string)) {
                                                    LogUtil.d("app_period_ctrl", String.format("当前时间处于%s 应用的可用时间段(%s)内", next.getPackageName(), string));
                                                    z = true;
                                                    break;
                                                }
                                                i2++;
                                            }
                                            if (!z) {
                                                LogUtil.d("app_period_ctrl", String.format("当前应用 %s 今天的可用时间段为 %s,当前时间【不在】可用时间段内", next.getPackageName(), jSONArray.toJSONString()));
                                            }
                                            if (z) {
                                                arrayList2.add(next.getPackageName());
                                            } else {
                                                arrayList.add(next.getPackageName());
                                            }
                                        }
                                        LogUtil.d("app_period_ctrl", String.format("应用 %s 当前无可用时间段,即将冻结", next.getPackageName()));
                                        arrayList.add(next.getPackageName());
                                    }
                                    it = it2;
                                } else {
                                    LogUtil.d("app_period_ctrl", String.format("应用 %s 管控时段参数格式错误", next.getPackageName()));
                                }
                            }
                        }
                    }
                    MdmSdk.addDisallowedRunningApp(arrayList);
                    MdmSdk.removeDisallowedRunningApp(arrayList2);
                    return;
                }
                LogUtil.d("app_period_ctrl", "未获取到应用数据");
            } catch (Exception unused) {
                LogUtil.d("AppInfo数据表读取失败");
            }
        } catch (Exception unused2) {
        }
    }

    @Override
    public IBinder onBind(Intent intent) {
        return null;
    }

    @Override
    public void onCreate() {
        super.onCreate();
        if (Build.VERSION.SDK_INT >= 26) {
            String packageName = getPackageName();
            NotificationManager notificationManager = (NotificationManager) getSystemService(com.igexin.push.core.b.l);
            NotificationChannel notificationChannel = new NotificationChannel(packageName, "主服务", 4);
            notificationChannel.enableLights(true);
            notificationChannel.setLightColor(-65536);
            notificationChannel.setShowBadge(true);
            notificationChannel.setDescription("管控平台正在后台运行,请勿停用此服务!");
            notificationChannel.setLockscreenVisibility(-1);
            notificationManager.createNotificationChannel(notificationChannel);
            startForeground(1112, new Notification.Builder(this, packageName).setContentTitle("正在进行设备管控1").setContentText("管控平台正在后台运行,请勿停用此服务!").setWhen(System.currentTimeMillis()).setSmallIcon(R$drawable.ic_notification_mdm).build());
        }
    }

    @Override
    public int onStartCommand(Intent intent, int i, int i2) {
        if (Build.VERSION.SDK_INT >= 26) {
            String packageName = getPackageName();
            NotificationManager notificationManager = (NotificationManager) getSystemService(com.igexin.push.core.b.l);
            NotificationChannel notificationChannel = new NotificationChannel(packageName, "主服务", 4);
            notificationChannel.enableLights(true);
            notificationChannel.setLightColor(-65536);
            notificationChannel.setShowBadge(true);
            notificationChannel.setDescription("管控平台正在后台运行,请勿停用此服务!");
            notificationChannel.setLockscreenVisibility(-1);
            notificationManager.createNotificationChannel(notificationChannel);
            startForeground(1112, new Notification.Builder(this, packageName).setContentTitle("正在进行设备管控").setContentText("管控平台正在后台运行,请勿停用此服务!").setWhen(System.currentTimeMillis()).setSmallIcon(R$drawable.ic_notification_mdm).build());
        }
        LogUtil.d("app_period_ctrl", "AppUsePeriodCtrlService 响应定时任务 ");
        d();
        return super.onStartCommand(intent, i, i2);
    }
}