version:1.6.1
fix:休息日管控完善 add:
This commit is contained in:
@@ -1,22 +1,27 @@
|
||||
package com.info.sn.receiver;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.os.Build;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.info.sn.bean.AppUploadInfo;
|
||||
import com.info.sn.bean.zuoye.AppUploadInfo;
|
||||
import com.info.sn.network.HTTPInterface;
|
||||
import com.info.sn.utils.ApkUtils;
|
||||
import com.info.sn.utils.CacheUtils;
|
||||
import com.info.sn.utils.JGYUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import io.reactivex.Observable;
|
||||
import io.reactivex.ObservableEmitter;
|
||||
@@ -27,65 +32,89 @@ import io.reactivex.disposables.Disposable;
|
||||
import io.reactivex.schedulers.Schedulers;
|
||||
|
||||
public class APKinstallReceiver extends BroadcastReceiver {
|
||||
private static String TAG = APKinstallReceiver.class.getSimpleName();
|
||||
@SuppressLint("StaticFieldLeak")
|
||||
private static Context mContext;
|
||||
private static NewAppListener newAppListener;
|
||||
|
||||
private String TAG = APKinstallReceiver.class.getSimpleName();
|
||||
static {
|
||||
sendAppInfo();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReceive(final Context context, Intent intent) {
|
||||
mContext = context;
|
||||
// TODO: This method is called when the BroadcastReceiver is receiving
|
||||
// an Intent broadcast.
|
||||
String action = intent.getAction();
|
||||
if (action.equals(Intent.ACTION_PACKAGE_ADDED)
|
||||
|| action.equals(Intent.ACTION_PACKAGE_REPLACED)
|
||||
|| action.equals(Intent.ACTION_PACKAGE_REMOVED)) {
|
||||
String packageName = intent.getDataString().replace("package:", "");
|
||||
Observable.create(new ObservableOnSubscribe<List<AppUploadInfo>>() {
|
||||
@Override
|
||||
public void subscribe(ObservableEmitter<List<AppUploadInfo>> emitter) throws Exception {
|
||||
PackageManager pm = context.getPackageManager();
|
||||
List<PackageInfo> list = pm.getInstalledPackages(0);
|
||||
List<AppUploadInfo> uploadInfos = new ArrayList<>();
|
||||
for (PackageInfo info : list) {
|
||||
if ((info.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 1) {
|
||||
continue;
|
||||
}
|
||||
AppUploadInfo uploadInfo = new AppUploadInfo();
|
||||
uploadInfo.setApp_package(info.packageName);
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
||||
uploadInfo.setApp_version_code(info.getLongVersionCode());
|
||||
} else {
|
||||
uploadInfo.setApp_version_code(info.versionCode);
|
||||
}
|
||||
uploadInfos.add(uploadInfo);
|
||||
}
|
||||
emitter.onNext(uploadInfos);
|
||||
}
|
||||
})
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Observer<List<AppUploadInfo>>() {
|
||||
@Override
|
||||
public void onSubscribe(Disposable d) {
|
||||
ApkUtils.addShortcut(context);
|
||||
JGYUtils.getInstance().cleanLauncherCache();
|
||||
Log.e(TAG, "onReceive: " + "action = " + action);
|
||||
String state;
|
||||
if (TextUtils.isEmpty(action)) {
|
||||
Log.e(TAG, "onReceive: " + "action is empty ");
|
||||
return;
|
||||
}
|
||||
String packageName = intent.getDataString().replace("package:", "");
|
||||
switch (action) {
|
||||
case Intent.ACTION_PACKAGE_ADDED:
|
||||
state = "安装了:";
|
||||
break;
|
||||
case Intent.ACTION_PACKAGE_REPLACED:
|
||||
cleanLauncher3Cache();
|
||||
state = "重装了:";
|
||||
break;
|
||||
case Intent.ACTION_PACKAGE_REMOVED:
|
||||
state = "卸载了:";
|
||||
break;
|
||||
default:
|
||||
state = "未知:";
|
||||
break;
|
||||
}
|
||||
Log.e(TAG, "sendAppInfo: " + state + packageName);
|
||||
newAppListener.setNewAppListener(packageName);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(List<AppUploadInfo> appUploadInfos) {
|
||||
String json = JSONArray.toJSONString(appUploadInfos);
|
||||
Log.e(TAG, "onNext: " + json);
|
||||
HTTPInterface.SendAppInstall(json);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
|
||||
}
|
||||
});
|
||||
private void cleanLauncher3Cache() {
|
||||
try {
|
||||
new CacheUtils().cleanApplicationUserData(mContext, "com.android.launcher3");
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "onReceive: " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public interface NewAppListener {
|
||||
void setNewAppListener(String packageName);
|
||||
}
|
||||
|
||||
private static void sendAppInfo() {
|
||||
Observable.create((ObservableEmitter<String> emitter) -> newAppListener = emitter::onNext)
|
||||
.throttleLast(5, TimeUnit.SECONDS)
|
||||
.subscribe(new Observer<String>() {
|
||||
@Override
|
||||
public void onSubscribe(Disposable d) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(String s) {
|
||||
HTTPInterface.getAPPinfo(mContext);
|
||||
HTTPInterface.getForceInstall(mContext);
|
||||
HTTPInterface.getAllappPackage(mContext);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
Log.e(TAG, "onComplete: ");
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user