update:2021.01.27
fix:修复应用安装信息上传 add:时间管控,顶部app管控
This commit is contained in:
@@ -1,25 +1,39 @@
|
||||
package com.info.sn.service;
|
||||
|
||||
import android.app.Service;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.PixelFormat;
|
||||
import android.os.Build;
|
||||
import android.os.IBinder;
|
||||
import android.provider.Settings;
|
||||
import android.text.TextUtils;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.Button;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.info.sn.KeepAliveConnection;
|
||||
import com.info.sn.activity.MainActivity;
|
||||
import com.info.sn.bean.AppInfo;
|
||||
import com.info.sn.R;
|
||||
import com.info.sn.bean.BaseResponse;
|
||||
import com.info.sn.network.HTTPInterface;
|
||||
import com.info.sn.network.NetWorkManager;
|
||||
import com.info.sn.network.api.ForceInstall;
|
||||
import com.info.sn.network.api.ScreenLock;
|
||||
import com.info.sn.utils.ApkUtils;
|
||||
import com.info.sn.utils.ForegroundAppUtil;
|
||||
import com.info.sn.utils.TimeUtils;
|
||||
import com.info.sn.utils.Utils;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import io.reactivex.Observer;
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.annotations.NonNull;
|
||||
import io.reactivex.disposables.Disposable;
|
||||
import io.reactivex.schedulers.Schedulers;
|
||||
|
||||
@@ -40,6 +54,19 @@ public class InitJpushServer extends Service {
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
registReceiver();
|
||||
registerTimeReceiver();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
if (null != mTimeChangedReceiver) {
|
||||
unregisterReceiver(mTimeChangedReceiver);
|
||||
}
|
||||
if (null != lockScreenReceiver) {
|
||||
unregisterReceiver(lockScreenReceiver);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -48,9 +75,234 @@ public class InitJpushServer extends Service {
|
||||
HTTPInterface.getAllappPackage(InitJpushServer.this);
|
||||
HTTPInterface.getForceInstall(InitJpushServer.this);
|
||||
HTTPInterface.checkUpdate(InitJpushServer.this);
|
||||
HTTPInterface.checkUpdate(InitJpushServer.this,"com.appstore.uiui");
|
||||
HTTPInterface.checkUpdate(InitJpushServer.this, "com.appstore.uiui");
|
||||
getScreenLockState();
|
||||
HTTPInterface.getTimeControl(InitJpushServer.this);
|
||||
return START_STICKY;
|
||||
}
|
||||
|
||||
private void getScreenLockState() {
|
||||
ScreenLock getScreenLock = NetWorkManager.getScreenLockControl();
|
||||
getScreenLock.getScreenshot(Utils.getSerial())
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Observer<BaseResponse>() {
|
||||
@Override
|
||||
public void onSubscribe(Disposable d) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(BaseResponse baseResponse) {
|
||||
int code = baseResponse.code;
|
||||
if (code == 200) {
|
||||
JSONObject jsonObject = (JSONObject) JSON.toJSON(baseResponse.data);
|
||||
int is_screen_lock = jsonObject.getInteger("is_screen_lock");
|
||||
if (is_screen_lock == 1) {
|
||||
if (!timelocked) {
|
||||
showFloatingWindow("屏幕已锁定");
|
||||
}
|
||||
screenlocked = true;
|
||||
} else {
|
||||
if (!timelocked) {
|
||||
hideFloatingWindow();
|
||||
}
|
||||
screenlocked = false;
|
||||
}
|
||||
} else {
|
||||
if (!timelocked) {
|
||||
hideFloatingWindow();
|
||||
}
|
||||
screenlocked = false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
private static WindowManager windowManager;
|
||||
private View topView;
|
||||
boolean screenlocked = false;
|
||||
boolean timelocked = false;
|
||||
|
||||
private void showFloatingWindow(String name) {
|
||||
if (Settings.canDrawOverlays(this)) {
|
||||
// 获取WindowManager服务
|
||||
if (null == windowManager) {
|
||||
windowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
|
||||
}
|
||||
DisplayMetrics dm = new DisplayMetrics();
|
||||
windowManager.getDefaultDisplay().getRealMetrics(dm);
|
||||
int width = dm.widthPixels; // 屏幕宽度(像素)
|
||||
int height = dm.heightPixels; // 屏幕高度(像素)
|
||||
// 新建悬浮窗控件
|
||||
final Button button = new Button(getApplicationContext());
|
||||
button.setText("霸屏测试");
|
||||
button.setAlpha(0.9f);
|
||||
button.setBackgroundColor(Color.WHITE);
|
||||
button.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
// windowManager.removeView(button);
|
||||
}
|
||||
});
|
||||
if (null == topView) {
|
||||
topView = LayoutInflater.from(getApplicationContext()).inflate(R.layout.activity_top, null);
|
||||
TextView textView = topView.findViewById(R.id.textView);
|
||||
textView.setText(name);
|
||||
} else {
|
||||
if (topView.getTag().equals("added")) {
|
||||
TextView textView = topView.findViewById(R.id.textView);
|
||||
textView.setText(name);
|
||||
return;
|
||||
}
|
||||
}
|
||||
// topView.setAlpha(0.8f);
|
||||
// 设置LayoutParam
|
||||
WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams();
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
layoutParams.type = WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY;
|
||||
} else {
|
||||
layoutParams.type = WindowManager.LayoutParams.TYPE_PHONE;
|
||||
}
|
||||
layoutParams.flags = WindowManager.LayoutParams.FLAG_BLUR_BEHIND;
|
||||
layoutParams.format = PixelFormat.RGBA_8888;
|
||||
layoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
|
||||
layoutParams.height = WindowManager.LayoutParams.MATCH_PARENT;
|
||||
layoutParams.x = 0;
|
||||
layoutParams.y = 0;
|
||||
|
||||
// 将悬浮窗控件添加到WindowManager
|
||||
windowManager.addView(topView, layoutParams);
|
||||
topView.setTag("added");
|
||||
}
|
||||
}
|
||||
|
||||
private void hideFloatingWindow() {
|
||||
if (null == windowManager) {
|
||||
return;
|
||||
}
|
||||
if (null != topView) {
|
||||
windowManager.removeView(topView);
|
||||
topView = null;
|
||||
}
|
||||
}
|
||||
|
||||
private LockScreenReceiver lockScreenReceiver;
|
||||
|
||||
private void registReceiver() {
|
||||
if (null == lockScreenReceiver) {
|
||||
lockScreenReceiver = new LockScreenReceiver();
|
||||
IntentFilter filter = new IntentFilter();
|
||||
filter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY);
|
||||
filter.addAction(LockScreenReceiver.ACTION_LOCK);
|
||||
filter.addAction(LockScreenReceiver.ACTION_UNLOCK);
|
||||
registerReceiver(lockScreenReceiver, filter);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class LockScreenReceiver extends BroadcastReceiver {
|
||||
public static final String ACTION_LOCK = "LockScreenReceiver_lockscreen";
|
||||
public static final String ACTION_UNLOCK = "LockScreenReceiver_unlockscreen";
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
String action = intent.getAction();
|
||||
if (TextUtils.isEmpty(action)) {
|
||||
getScreenLockState();
|
||||
return;
|
||||
}
|
||||
if (ACTION_LOCK.equals(action)) {
|
||||
// String name = intent.getStringExtra("name");
|
||||
String name = "屏幕已锁定";
|
||||
if (!timelocked) {
|
||||
showFloatingWindow(name);
|
||||
}
|
||||
screenlocked = true;
|
||||
} else if (ACTION_UNLOCK.equals(action)) {
|
||||
if (!timelocked) {
|
||||
hideFloatingWindow();
|
||||
}
|
||||
screenlocked = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private TimeChangedReceiver mTimeChangedReceiver;
|
||||
|
||||
//监听时间和日期变化
|
||||
public void registerTimeReceiver() {
|
||||
mTimeChangedReceiver = new TimeChangedReceiver();
|
||||
IntentFilter filter = new IntentFilter();
|
||||
filter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY);
|
||||
filter.addAction(Intent.ACTION_DATE_CHANGED);
|
||||
filter.addAction(Intent.ACTION_TIME_CHANGED);
|
||||
filter.addAction(Intent.ACTION_TIMEZONE_CHANGED);
|
||||
filter.addAction(Intent.ACTION_TIME_TICK);
|
||||
filter.addAction(TimeChangedReceiver.ACTION_UPDATE);
|
||||
registerReceiver(mTimeChangedReceiver, filter);
|
||||
}
|
||||
|
||||
public class TimeChangedReceiver extends BroadcastReceiver {
|
||||
public static final String ACTION_UPDATE = "TimeChangedReceiver_update";
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
if (Intent.ACTION_DATE_CHANGED.equals(intent.getAction())) {
|
||||
Log.e("fht", "TimeChangedReceiver:" + "data changed");
|
||||
} else if (Intent.ACTION_TIME_CHANGED.equals(intent.getAction())) {
|
||||
Log.e("fht", "TimeChangedReceiver:" + "time changed");
|
||||
} else if (Intent.ACTION_TIMEZONE_CHANGED.equals(intent.getAction())) {
|
||||
Log.e("fht", "TimeChangedReceiver:" + "timezone changed");
|
||||
} else if (Intent.ACTION_TIME_TICK.equals(intent.getAction())) {
|
||||
Log.e("fht", "TimeChangedReceiver:" + "time tick");
|
||||
} else if (ACTION_UPDATE.equals(intent.getAction())) {
|
||||
Log.e("fht", "TimeChangedReceiver:" + "date update");
|
||||
}
|
||||
long nowTime = System.currentTimeMillis();
|
||||
TimeUtils.ContralTime contralTime = TimeUtils.getDefaltContralTime(InitJpushServer.this);
|
||||
if (null != contralTime) {
|
||||
if (contralTime.inControlTime(nowTime)) {
|
||||
if (!screenlocked) {
|
||||
showFloatingWindow("管控时间:" + contralTime.toString());
|
||||
} else {
|
||||
TextView textView = topView.findViewById(R.id.textView);
|
||||
textView.setText("管控时间:" + contralTime.toString());
|
||||
}
|
||||
timelocked = true;
|
||||
} else {
|
||||
getScreenLockState();
|
||||
if (!screenlocked) {
|
||||
hideFloatingWindow();
|
||||
}
|
||||
timelocked = false;
|
||||
}
|
||||
} else {
|
||||
if (!screenlocked) {
|
||||
hideFloatingWindow();
|
||||
}
|
||||
getScreenLockState();
|
||||
timelocked = false;
|
||||
}
|
||||
// String packages = ForegroundAppUtil.getForegroundPackageName(context);
|
||||
// if (!packages.equals("com.estrongs.android.pop")) {
|
||||
// ApkUtils.openApp(context, "com.estrongs.android.pop");
|
||||
// }
|
||||
// Log.e("TimeChangedReceiver", "packages:" + packages);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user