更换包名
This commit is contained in:
121
app/src/main/java/com/fuying/sn/receiver/APKinstallReceiver.java
Normal file
121
app/src/main/java/com/fuying/sn/receiver/APKinstallReceiver.java
Normal file
@@ -0,0 +1,121 @@
|
||||
package com.fuying.sn.receiver;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import com.fuying.sn.config.CommonConfig;
|
||||
import com.fuying.sn.manager.ControlManager;
|
||||
import com.fuying.sn.network.NetInterfaceManager;
|
||||
import com.fuying.sn.utils.ApkUtils;
|
||||
import com.fuying.sn.utils.CacheUtils;
|
||||
import com.fuying.sn.utils.JGYUtils;
|
||||
import com.fuying.sn.utils.SPUtils;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import io.reactivex.rxjava3.core.Observable;
|
||||
import io.reactivex.rxjava3.core.ObservableEmitter;
|
||||
import io.reactivex.rxjava3.core.Observer;
|
||||
import io.reactivex.rxjava3.disposables.Disposable;
|
||||
|
||||
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;
|
||||
// an Intent broadcast.
|
||||
String action = intent.getAction();
|
||||
ApkUtils.addShortcut(context);
|
||||
JGYUtils.getInstance().cleanLauncherCache();
|
||||
ControlManager.getInstance().setDefaultApp();
|
||||
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 (JGYUtils.PACKAGE_APPSTORE.equals(packageName)) {
|
||||
//启动应用市场
|
||||
JGYUtils.getInstance().wakeUpDeviceInfo();
|
||||
} else if (JGYUtils.PACKAGE_UPDATETOOLS.equals(packageName)) {
|
||||
//启动升级组件
|
||||
JGYUtils.getInstance().wakeUpUpdateTools();
|
||||
}
|
||||
}
|
||||
|
||||
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(3, TimeUnit.MINUTES)
|
||||
.subscribe(new Observer<String>() {
|
||||
@Override
|
||||
public void onSubscribe(Disposable d) {
|
||||
Log.e("sendAppInfo", "onSubscribe: ");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(String s) {
|
||||
Log.e("sendAppInfo", "onNext: " + s);
|
||||
int isLogined = (int) SPUtils.get(mContext, CommonConfig.isLogined, 2);
|
||||
if (isLogined == 2) return;
|
||||
NetInterfaceManager.getInstance().SendAppInstallInfo();
|
||||
NetInterfaceManager.getInstance().getForceInstall();
|
||||
NetInterfaceManager.getInstance().getAllappPackage();
|
||||
NetInterfaceManager.getInstance().getAppInside();
|
||||
NetInterfaceManager.getInstance().getOverallApp();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
Log.e("sendAppInfo", "onError: " + e.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
Log.e("sendAppInfo", "onComplete: ");
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
63
app/src/main/java/com/fuying/sn/receiver/BootReceiver.java
Normal file
63
app/src/main/java/com/fuying/sn/receiver/BootReceiver.java
Normal file
@@ -0,0 +1,63 @@
|
||||
package com.fuying.sn.receiver;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.util.Log;
|
||||
|
||||
import com.baidu.location.BDAbstractLocationListener;
|
||||
import com.baidu.location.BDLocation;
|
||||
import com.baidu.location.LocationClient;
|
||||
import com.fuying.sn.manager.AmapManager;
|
||||
import com.fuying.sn.network.NetInterfaceManager;
|
||||
import com.fuying.sn.service.ControlPanelService;
|
||||
import com.fuying.sn.service.GuardService;
|
||||
import com.fuying.sn.service.main.MainService;
|
||||
import com.fuying.sn.service.ManagerService;
|
||||
import com.fuying.sn.service.DownloadService;
|
||||
import com.fuying.sn.service.StepService;
|
||||
|
||||
|
||||
public class BootReceiver extends BroadcastReceiver {
|
||||
private static String TAG = BootReceiver.class.getSimpleName();
|
||||
public static final String BOOT_COMPLETED = "zuoyeos.action.BOOT_COMPLETED";
|
||||
public static final String SOS = "zuoyeos.action.SOS";
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
String action = intent.getAction();
|
||||
Log.e("SNBootReceiver", action);
|
||||
if (Intent.ACTION_BOOT_COMPLETED.equals(action)
|
||||
|| Intent.ACTION_BATTERY_CHANGED.equals(action)
|
||||
|| Intent.ACTION_BATTERY_LOW.equals(action)
|
||||
|| Intent.ACTION_BATTERY_OKAY.equals(action)
|
||||
|| Intent.ACTION_POWER_CONNECTED.equals(action)
|
||||
|| Intent.ACTION_POWER_DISCONNECTED.equals(action)
|
||||
|| Intent.ACTION_DATE_CHANGED.equals(action)
|
||||
|| Intent.ACTION_TIME_TICK.equals(action)
|
||||
|| Intent.ACTION_USER_PRESENT.equals(action)
|
||||
|| Intent.ACTION_SCREEN_ON.equals(action)
|
||||
|| Intent.ACTION_SCREEN_OFF.equals(action)
|
||||
|| BOOT_COMPLETED.equals(action)
|
||||
|| "android.intent.action.BATTERY_LEVEL_CHANGED".equals(action)
|
||||
) {
|
||||
context.startService(new Intent(context, MainService.class));
|
||||
context.startService(new Intent(context, GuardService.class));
|
||||
context.startService(new Intent(context, StepService.class));
|
||||
context.startService(new Intent(context, DownloadService.class));
|
||||
context.startService(new Intent(context, ManagerService.class));
|
||||
context.startService(new Intent(context, ControlPanelService.class));
|
||||
} else if (SOS.equals(action)) {
|
||||
LocationClient locationClient = AmapManager.getInstance().getLocationClient();
|
||||
locationClient.stop();
|
||||
locationClient.start();
|
||||
locationClient.registerLocationListener(new BDAbstractLocationListener() {
|
||||
@Override
|
||||
public void onReceiveLocation(BDLocation bdLocation) {
|
||||
Log.e(TAG, "onReceiveLocation: ");
|
||||
NetInterfaceManager.getInstance().updateAdminInfo();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package com.fuying.sn.receiver;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageInstaller;
|
||||
import android.os.Build;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.RequiresApi;
|
||||
|
||||
public class InstallResultReceiver extends BroadcastReceiver {
|
||||
private static final String TAG = "InstallResultReceiver";
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
// an Intent broadcast.
|
||||
//throw new UnsupportedOperationException("Not yet implemented");
|
||||
|
||||
|
||||
if (intent != null) {
|
||||
final int status = intent.getIntExtra(PackageInstaller.EXTRA_STATUS,
|
||||
PackageInstaller.STATUS_FAILURE);
|
||||
if (status == PackageInstaller.STATUS_SUCCESS) {
|
||||
// success
|
||||
String PACKAGE_NAME = intent.getStringExtra("android.content.pm.extra.PACKAGE_NAME");
|
||||
|
||||
Log.e(TAG, "APP Install Success!");
|
||||
} else {
|
||||
String msg = intent.getStringExtra(PackageInstaller.EXTRA_STATUS_MESSAGE);
|
||||
}
|
||||
}
|
||||
// String s = intent.getAction();
|
||||
// Log.e("fht", s);
|
||||
// Bundle extras = intent.getExtras();
|
||||
// Set<String> ks = extras.keySet();
|
||||
// Iterator<String> iterator = ks.iterator();
|
||||
// while (iterator.hasNext()) {
|
||||
// Log.d("KEY", iterator.next());
|
||||
// }
|
||||
String STATUS = intent.getStringExtra(PackageInstaller.EXTRA_STATUS);
|
||||
String PACKAGE_NAME = intent.getStringExtra(PackageInstaller.EXTRA_PACKAGE_NAME);
|
||||
String SESSION_ID = intent.getStringExtra(PackageInstaller.EXTRA_SESSION_ID);
|
||||
String STATUS_MESSAGE = intent.getStringExtra(PackageInstaller.EXTRA_STATUS_MESSAGE);
|
||||
String LEGACY_STATUS = intent.getStringExtra("android.content.pm.extra.LEGACY_STATUS");
|
||||
// Log.e("fht", STATUS);
|
||||
// Log.e("fht", PACKAGE_NAME);
|
||||
// Log.e("fht", SESSION_ID);
|
||||
// Log.e("fht", LEGACY_STATUS);
|
||||
// Log.e("fht", STATUS_MESSAGE);
|
||||
if (STATUS_MESSAGE != null && "INSTALL_SUCCEEDED".equals(STATUS_MESSAGE)) {
|
||||
// ToastUtil.show(PACKAGE_NAME + "安装成功");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user