137 lines
4.9 KiB
Java
137 lines
4.9 KiB
Java
package com.info.sn.receiver;
|
|
|
|
import android.annotation.SuppressLint;
|
|
import android.content.BroadcastReceiver;
|
|
import android.content.ComponentName;
|
|
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.JSONArray;
|
|
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;
|
|
import io.reactivex.ObservableOnSubscribe;
|
|
import io.reactivex.Observer;
|
|
import io.reactivex.android.schedulers.AndroidSchedulers;
|
|
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;
|
|
|
|
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();
|
|
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);
|
|
//启动应用市场
|
|
if ("com.jgyapp.market".equals(packageName)) {
|
|
Intent bootIntent = new Intent(BootReceiver.BOOT_COMPLETED);
|
|
bootIntent.setComponent(new ComponentName("com.jgyapp.market", "com.jgyapp.market.receiver.BootReceiver"));
|
|
context.sendBroadcast(bootIntent);
|
|
} else if ("com.uiuios.updatetools".equals(packageName)) {
|
|
//启动升级组件
|
|
Intent bootIntent = new Intent(BootReceiver.BOOT_COMPLETED);
|
|
bootIntent.setComponent(new ComponentName("com.uiuios.updatetools", "com.uiuios.updatetools.receiver.BootReceiver"));
|
|
context.sendBroadcast(bootIntent);
|
|
}
|
|
Intent bootIntent = new Intent(BootReceiver.BOOT_COMPLETED);
|
|
bootIntent.setComponent(new ComponentName("com.appstore.uiui", "com.appstore.uiui.receiver.BootReceiver"));
|
|
context.sendBroadcast(bootIntent);
|
|
newAppListener.setNewAppListener(packageName);
|
|
}
|
|
|
|
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);
|
|
HTTPInterface.getAppInside(mContext);
|
|
}
|
|
|
|
@Override
|
|
public void onError(Throwable e) {
|
|
|
|
}
|
|
|
|
@Override
|
|
public void onComplete() {
|
|
Log.e(TAG, "onComplete: ");
|
|
}
|
|
});
|
|
}
|
|
}
|