正在查看: 管控平台 v5.2.3.0. 应用的 AppUsePeriodCtrlByTeaPolicyService.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
正在查看: 管控平台 v5.2.3.0. 应用的 AppUsePeriodCtrlByTeaPolicyService.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
package com.iflytek.mdmservice.service;
import android.app.AlarmManager;
import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.Service;
import android.content.Intent;
import android.os.Build;
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.List;
public class AppUsePeriodCtrlByTeaPolicyService extends Service {
private static final AlarmManager f440a = (AlarmManager) MDMApp.j().getSystemService("alarm");
private boolean a(String str, AppInfo appInfo) {
if (appInfo == null) {
return false;
}
String usingTimeLimit = appInfo.getUsingTimeLimit();
String packageName = appInfo.getPackageName();
if (!Utils.isJson(usingTimeLimit) && !"{}".equals(usingTimeLimit)) {
LogUtil.d("app_period_ctrl", String.format("应用 %s 管控时段参数格式错误", packageName));
return true;
}
JSONArray jSONArray = JSON.parseObject(usingTimeLimit).getJSONArray(str);
if (jSONArray == null || jSONArray.isEmpty()) {
LogUtil.c("TeaCtrlPolicyApp", String.format("应用 %s 当前无可用时间段,即将冻结", packageName));
return false;
}
for (int i = 0; i < jSONArray.size(); i++) {
String string = jSONArray.getString(i);
if (com.iflytek.mdmservice.utils.f.c(string)) {
LogUtil.c("TeaCtrlPolicyApp", String.format("当前时间处于%s 应用的可用时间段(%s)内", packageName, string));
return true;
}
}
return false;
}
private boolean b(String str) {
return "com.android.iflylauncher3".equals(str) || "com.iflytek.mdmservice".equals(str) || "com.iflytek.iflylogin".equals(str) || "com.iflytek.mdmstore".equals(str) || "com.iflytek.mdmadmin".equals(str);
}
private AppInfo c(String str, List<AppInfo> list) {
for (AppInfo appInfo : list) {
if (TextUtils.equals(str, appInfo.getPackageName())) {
return appInfo;
}
}
return null;
}
private long d(TeaCtrlAppPolicy teaCtrlAppPolicy, List<AppInfo> list, List<String> list2, List<String> list3, long j, String str) {
String appPackage = teaCtrlAppPolicy.getAppPackage();
boolean z = false;
long j2 = 0;
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;
long j3 = d - j;
if (j3 <= 0) {
j3 = d2 - j;
}
if (j3 > 0 && (j2 == 0 || j3 < j2)) {
j2 = j3;
}
if (j >= d && j <= d2) {
LogUtil.c("TeaCtrlPolicyApp", appPackage + "触发教师管控应用禁用策略:" + str2);
list2.add(appPackage);
z = true;
}
}
if (!z && a(str, c(appPackage, list))) {
list3.add(appPackage);
}
return j2;
}
private void f() {
AppUsePeriodCtrlService.b().post(new Runnable() {
@Override
public final void run() {
AppUsePeriodCtrlByTeaPolicyService.this.e();
}
});
}
private void g(long j, long j2) {
LogUtil.c("TeaCtrlPolicyApp", "startNextCheckAlert:" + j2);
PendingIntent service = PendingIntent.getService(MDMApp.j(), 0, new Intent(MDMApp.j(), (Class<?>) AppUsePeriodCtrlByTeaPolicyService.class), 134217728);
if (Build.VERSION.SDK_INT < 19) {
f440a.set(0, j2, service);
} else {
f440a.setExact(0, j2, service);
}
}
public void e() {
long j;
try {
List<TeaCtrlAppPolicy> allPolicies = new TeaCtrlAppPolicyDaoImpl(MDMApp.j()).getAllPolicies();
if (allPolicies != null && !allPolicies.isEmpty()) {
List<AppInfo> l = MDMApp.k().getAppInfoDao().queryBuilder().l();
Calendar calendar = Calendar.getInstance();
int i = calendar.get(7);
long timeInMillis = calendar.getTimeInMillis();
String str = com.iflytek.mdmservice.o.a.a.f273a[i - 1];
ArrayList arrayList = new ArrayList();
ArrayList arrayList2 = new ArrayList();
long j2 = 0;
for (TeaCtrlAppPolicy teaCtrlAppPolicy : allPolicies) {
String disableCycle = teaCtrlAppPolicy.getDisableCycle();
if (!b(teaCtrlAppPolicy.getAppPackage()) && com.iflytek.mdmservice.o.d.e.a(disableCycle, i)) {
long d = d(teaCtrlAppPolicy, l, arrayList, arrayList2, timeInMillis, str);
if (d > 0 && (j2 == 0 || d < j2)) {
j2 = d;
}
}
}
if (!arrayList2.isEmpty()) {
MdmSdk.removeDisallowedRunningApp(arrayList2);
}
if (!arrayList.isEmpty()) {
MdmSdk.addDisallowedRunningApp(arrayList);
}
if (j2 == 0) {
Calendar calendar2 = Calendar.getInstance();
calendar2.add(6, 1);
calendar2.set(11, 0);
calendar2.set(12, 0);
calendar2.set(13, 0);
calendar2.set(14, 0);
j = calendar2.getTimeInMillis();
} else {
j = timeInMillis + j2;
}
g(timeInMillis, j);
}
} catch (Exception unused) {
LogUtil.d("AppInfo数据表读取失败");
}
}
@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(1113, 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(1113, new Notification.Builder(this, packageName).setContentTitle("正在进行设备管控").setContentText("管控平台正在后台运行,请勿停用此服务!").setWhen(System.currentTimeMillis()).setSmallIcon(R$drawable.ic_notification_mdm).build());
}
LogUtil.d("TeaCtrlPolicyApp", "AppUsePeriodCtrlByTeaPolicyService 响应定时任务 ");
f();
return super.onStartCommand(intent, i, i2);
}
}