update:2020.12.26

fix:增加强制应用禁止删除
add:
This commit is contained in:
2020-12-26 18:18:38 +08:00
parent 79ea8888c1
commit e17935ad76
11 changed files with 285 additions and 119 deletions

View File

@@ -86,6 +86,8 @@
<action android:name="android.intent.action.DATE_CHANGED" />
<action android:name="android.intent.action.TIME_TICK" />
<action android:name="android.intent.action.USER_PRESENT" />
<action android:name="android.intent.action.SCREEN_ON" />
<action android:name="android.intent.action.SCREEN_OFF" />
</intent-filter>
</receiver>
<receiver

View File

@@ -6,11 +6,9 @@ import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.graphics.Bitmap;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
@@ -26,11 +24,8 @@ import android.widget.TextView;
import androidx.constraintlayout.widget.ConstraintLayout;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.amap.api.location.AMapLocation;
import com.amap.api.location.AMapLocationClient;
import com.amap.api.location.AMapLocationClientOption;
import com.amap.api.location.AMapLocationListener;
import com.amap.api.location.AMapLocationQualityReport;
import com.hjq.permissions.OnPermission;
@@ -40,7 +35,6 @@ import com.info.sn.BuildConfig;
import com.info.sn.R;
import com.info.sn.base.CheckPermissionsActivity;
import com.info.sn.base.MyApplication;
import com.info.sn.bean.AppInfo;
import com.info.sn.bean.BaseResponse;
import com.info.sn.bean.SystemSettings;
import com.info.sn.bean.UserInfo;
@@ -49,7 +43,6 @@ import com.info.sn.jpush.LocalBroadcastManager;
import com.info.sn.jpush.TagAliasOperatorHelper;
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.SNInfo;
import com.info.sn.network.api.Setting;
import com.info.sn.service.GuardService;
@@ -57,7 +50,6 @@ import com.info.sn.service.InitJpushServer;
import com.info.sn.service.MyDownloadService;
import com.info.sn.service.StepService;
import com.info.sn.utils.ApkUtils;
import com.info.sn.utils.FileUtils;
import com.info.sn.utils.LogUtils;
import com.info.sn.utils.SPUtils;
import com.info.sn.utils.ToastUtil;
@@ -76,7 +68,6 @@ import io.reactivex.annotations.NonNull;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;
import me.jessyan.autosize.internal.CustomAdapt;
import retrofit2.http.HTTP;
import static com.info.sn.jpush.TagAliasOperatorHelper.ACTION_ADD;
import static com.info.sn.jpush.TagAliasOperatorHelper.ACTION_CHECK;
@@ -171,10 +162,11 @@ public class MainActivity extends CheckPermissionsActivity implements AMapLocati
@Override
public void onNext(@NonNull Long aLong) {
HTTPInterface.getAllappPackage(MainActivity.this);
HTTPInterface.setBrowser(context);
HTTPInterface.getBrowserLabel(context);
getSystemSettings(context);
getForceInstall(context);
HTTPInterface.getForceInstall(context);
HTTPInterface.getAppStart(context);
HTTPInterface.getAppJump(context);
}
@@ -291,8 +283,6 @@ public class MainActivity extends CheckPermissionsActivity implements AMapLocati
}
@Override
protected void onResume() {
super.onResume();
@@ -450,68 +440,7 @@ public class MainActivity extends CheckPermissionsActivity implements AMapLocati
}
private void getForceInstall(final Context context) {
ForceInstall forceInstall = NetWorkManager.getForceInstallControl();
forceInstall.getForceInstall(Utils.getSerial())
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Observer<BaseResponse<List<AppInfo>>>() {
@Override
public void onSubscribe(@NonNull Disposable d) {
}
@Override
public void onNext(@NonNull BaseResponse<List<AppInfo>> listBaseResponse) {
int code = listBaseResponse.code;
if (code == 200) {
List<AppInfo> appInfos = listBaseResponse.data;
if (null != appInfos && appInfos.size() != 0) {
getForceInstallState(context, appInfos);
}
}
}
@Override
public void onError(@NonNull Throwable e) {
Log.e("getForceInstall", "onError: " + e.getMessage());
}
@Override
public void onComplete() {
}
});
}
private void getForceInstallState(Context context, List<AppInfo> list) {
if (null != list && list.size() != 0) {
PackageManager pm = context.getPackageManager();
for (AppInfo appInfo : list) {
PackageInfo info = null;
try {
info = pm.getPackageInfo(appInfo.getApp_package(), 0);
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
if (null != info) {
long appVersionCode;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
appVersionCode = info.getLongVersionCode();
} else {
appVersionCode = info.versionCode;
}
if (appVersionCode < appInfo.getApp_version_code()) {
JSONObject jsonObject = (JSONObject) JSON.toJSON(appInfo);
FileUtils.ariaDownload(context, appInfo.getApp_url(), jsonObject);
}
} else {
JSONObject jsonObject = (JSONObject) JSON.toJSON(appInfo);
FileUtils.ariaDownload(context, appInfo.getApp_url(), jsonObject);
}
}
}
}
@Override

View File

@@ -181,9 +181,8 @@ public class MyReceiver extends BroadcastReceiver {
private static final String JIGUANG_SYSTEM_SETTING = "21";
//系统管控
private static final String JIGUANG_REBOOT_DEVICES = "22";
//重启
//
//send msg to MainActivity
private void processCustomMessage(Context context, Bundle bundle) {
// if (MainActivity.isForeground) {
@@ -263,11 +262,7 @@ public class MyReceiver extends BroadcastReceiver {
HTTPInterface.getAppJump(context);
break;
case JIGUANG_REBOOT_DEVICES:
// Intent intent = new Intent(MainActivity.REFRESHACTION);
// context.sendBroadcast(intent);
if (!BuildConfig.DEBUG) {
Utils.rebootDevices(context);
}
break;
case JIGUANG_APP_NET_AUTO:
HTTPInterface.getAppStart(context);
@@ -654,7 +649,7 @@ public class MyReceiver extends BroadcastReceiver {
synchronized private void unintallApk(Context context, String json) {
int sn_id = (int) SPUtils.get(context, "sn_id", "-1");
int sn_id = (int) SPUtils.get(context, "sn_id", -1);
try {
JSONObject object = new JSONObject(json);

View File

@@ -2,50 +2,41 @@ package com.info.sn.network;
import android.content.Context;
import android.content.Intent;
import android.icu.text.SimpleDateFormat;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.provider.Settings;
import android.text.TextUtils;
import android.util.Log;
import androidx.annotation.RequiresApi;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONException;
import com.alibaba.fastjson.JSONObject;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.info.sn.activity.MainActivity;
import com.info.sn.bean.AppInfo;
import com.info.sn.bean.AppJump;
import com.info.sn.bean.AppStart;
import com.info.sn.bean.BaseResponse;
import com.info.sn.bean.BrowserBean;
import com.info.sn.bean.UserInfo;
import com.info.sn.network.UrlAddress;
import com.info.sn.network.api.APPJump;
import com.info.sn.network.api.AddAppInstall;
import com.info.sn.network.api.Browser;
import com.info.sn.network.api.ForceInstall;
import com.info.sn.network.api.Label;
import com.info.sn.network.api.QueryAllApp;
import com.info.sn.network.api.QuerySnAppStart;
import com.info.sn.network.api.UpdateAdminSn;
import com.info.sn.utils.LogUtils;
import com.info.sn.utils.ApkUtils;
import com.info.sn.utils.FileUtils;
import com.info.sn.utils.SPUtils;
import com.info.sn.utils.ToastUtil;
import com.info.sn.utils.Utils;
import org.w3c.dom.Text;
import java.util.Date;
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.internal.schedulers.NewThreadWorker;
import io.reactivex.schedulers.Schedulers;
public class HTTPInterface {
@@ -163,7 +154,7 @@ public class HTTPInterface {
JsonObject label = jsonObject.getAsJsonArray("label").get(0).getAsJsonObject();
String home_page = label.get("home_page").getAsString();
String label_page = label.get("label_page").getAsString();
Log.e("getBrowserLabel", "onNext: " + home_page);
// Log.e("getBrowserLabel", "onNext: " + home_page);
//主页
Intent homepag = new Intent("qch_app_brower_homepage");
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
@@ -436,9 +427,9 @@ public class HTTPInterface {
jsonObject.put("address", address);
jsonObject.put("longitude", longitude);
jsonObject.put("latitude", latitude);
String a = jsonObject.toString();
String b = Utils.getMachine(context);
String c = Utils.getHardware(context);
// String a = jsonObject.toString();
// String b = Utils.getMachine(context);
// String c = Utils.getHardware(context);
UpdateAdminSn updateAdminSn = NetWorkManager.getUpdateAdminSnControl();
updateAdminSn.sendAdminSn(Utils.getSerial(),
jsonObject.toJSONString(),
@@ -469,6 +460,130 @@ public class HTTPInterface {
});
}
public static void getAllappPackage(final Context context) {
QueryAllApp queryAllApp = NetWorkManager.getQueryAllAppControl();
queryAllApp.getAllApp(Utils.getSerial())
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Observer<BaseResponse<List<AppInfo>>>() {
@Override
public void onSubscribe(@NonNull Disposable d) {
}
@Override
public void onNext(@NonNull BaseResponse<List<AppInfo>> listBaseResponse) {
int code = listBaseResponse.code;
if (code == 200) {
Log.e("getAllappPackage", "onNext: " + listBaseResponse.msg);
List<AppInfo> appInfoList = listBaseResponse.data;
if (null != appInfoList && appInfoList.size() != 0) {
String s = "";
for (AppInfo appInfo : appInfoList) {
s += appInfo.getApp_package() + ",";
}
if (s.endsWith(",")) {
s = s.substring(0, s.length() - 1);
}
ApkUtils.writeAppPackageList(context, s);
} else {
ApkUtils.writeAppPackageList(context, "Invalid");
}
} else {
ApkUtils.writeAppPackageList(context, "Invalid");
}
}
@Override
public void onError(@NonNull Throwable e) {
Log.e("getAllappPackage", "onError: " + e.getMessage());
}
@Override
public void onComplete() {
}
});
}
public static void getForceInstall(final Context context) {
ForceInstall forceInstall = NetWorkManager.getForceInstallControl();
forceInstall.getForceInstall(Utils.getSerial())
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Observer<BaseResponse<List<AppInfo>>>() {
@Override
public void onSubscribe(@NonNull Disposable d) {
}
@Override
public void onNext(@NonNull BaseResponse<List<AppInfo>> listBaseResponse) {
int code = listBaseResponse.code;
if (code == 200) {
List<AppInfo> appInfos = listBaseResponse.data;
if (null != appInfos && appInfos.size() != 0) {
getForceInstallState(context, appInfos);
}
}else {
boolean qch_force_app = Settings.System.putString(context.getContentResolver(), "qch_force_app", "invalid");
Log.e("fht", "qch_force_app:" + qch_force_app + ":" + "invalid");
}
}
@Override
public void onError(@NonNull Throwable e) {
Log.e("getForceInstall", "onError: " + e.getMessage());
}
@Override
public void onComplete() {
}
});
}
private static void getForceInstallState(Context context, List<AppInfo> list) {
if (null != list && list.size() != 0) {
String packageList = "";
PackageManager pm = context.getPackageManager();
for (AppInfo appInfo : list) {
packageList += appInfo.getApp_package() + ",";
PackageInfo info = null;
try {
info = pm.getPackageInfo(appInfo.getApp_package(), 0);
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
if (null != info) {
long appVersionCode;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
appVersionCode = info.getLongVersionCode();
} else {
appVersionCode = info.versionCode;
}
if (appVersionCode < appInfo.getApp_version_code()) {
JSONObject jsonObject = (JSONObject) JSON.toJSON(appInfo);
FileUtils.ariaDownload(context, appInfo.getApp_url(), jsonObject);
}
} else {
JSONObject jsonObject = (JSONObject) JSON.toJSON(appInfo);
FileUtils.ariaDownload(context, appInfo.getApp_url(), jsonObject);
}
}
if (packageList.endsWith(",")) {
packageList = packageList.substring(0, packageList.length() - 1);
boolean qch_force_app = Settings.System.putString(context.getContentResolver(), "qch_force_app", packageList);
Log.e("fht", "qch_force_app:" + qch_force_app + ":" + packageList);
}
} else {
boolean qch_force_app = Settings.System.putString(context.getContentResolver(), "qch_force_app", "invalid");
Log.e("fht", "qch_force_app:" + qch_force_app + ":" + "invalid");
}
}
//获取设备信息接口
// public static synchronized void checkDevicesInfo(final Handler handler) {
// OkGo.<String>get(UrlAddress.SNINFO)

View File

@@ -9,6 +9,7 @@ import com.info.sn.network.api.BindDevices;
import com.info.sn.network.api.Browser;
import com.info.sn.network.api.ForceInstall;
import com.info.sn.network.api.Label;
import com.info.sn.network.api.QueryAllApp;
import com.info.sn.network.api.QuerySnAppStart;
import com.info.sn.network.api.SNInfo;
import com.info.sn.network.api.Setting;
@@ -59,6 +60,8 @@ public class NetWorkManager {
private static QuerySnAppStart appStartControl;
private static APPJump appJumpControl;
private static UpdateAdminSn updateAdminSnControl;
private static QueryAllApp queryAllAppControl;
public static SNInfo getsnInfoControl() {
if (null == snInfoControl) {
@@ -190,6 +193,17 @@ public class NetWorkManager {
}
return updateAdminSnControl;
}
public static QueryAllApp getQueryAllAppControl() {
if (null == queryAllAppControl) {
Retrofit retrofit = new Retrofit.Builder()
.client(client)
.baseUrl(ROOT_URL)
.addConverterFactory(gsonConverterFactory)
.addCallAdapterFactory(rxJavaCallAdapterFactory)
.build();
queryAllAppControl = retrofit.create(QueryAllApp.class);
}
return queryAllAppControl;
}
}

View File

@@ -13,8 +13,8 @@ public class UrlAddress {
//获取当前最顶层应用和电量
public final static String SEND_DRIVE_STATE = ROOT_URL + "Online/online";
public final static String GET_ALL_PACKAGENAME = ROOT_URL + "App/allPackageSn";
//获取所有应用包名
public final static String GET_ALL_PACKAGE = ROOT_URL + "app/queryAllApp";
//获取所有应用
public final static String BIND_DEVICES = ROOT_URL + "sn/bindSn";
//绑定设备消息
public final static String GET_SETTINGS = ROOT_URL + "control/getSetting";

View File

@@ -0,0 +1,18 @@
package com.info.sn.network.api;
import com.info.sn.bean.AppInfo;
import com.info.sn.bean.BaseResponse;
import com.info.sn.network.UrlAddress;
import java.util.List;
import io.reactivex.Observable;
import retrofit2.http.GET;
import retrofit2.http.Query;
public interface QueryAllApp {
@GET(UrlAddress.GET_ALL_PACKAGE)
Observable<BaseResponse<List<AppInfo>>> getAllApp(
@Query("sn") String sn
);
}

View File

@@ -16,19 +16,21 @@ public class BootReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Log.e("SNBootReceiver", intent.getAction());
if (intent.getAction().equals("android.intent.action.BOOT_COMPLETED")
|| intent.getAction().equals("android.intent.action.BATTERY_CHANGED")
|| intent.getAction().equals("android.intent.action.BATTERY_LEVEL_CHANGED")
|| intent.getAction().equals("android.intent.action.BATTERY_LOW")
|| intent.getAction().equals("android.intent.action.BATTERY_OKAY")
|| intent.getAction().equals("android.intent.action.ACTION_POWER_CONNECTED")
|| intent.getAction().equals("android.intent.action.ACTION_POWER_DISCONNECTED")
|| intent.getAction().equals("android.intent.action.DATE_CHANGED")
|| intent.getAction().equals("android.intent.action.TIME_TICK")
|| intent.getAction().equals("android.intent.action.USER_PRESENT")
|| intent.getAction().equals("android.intent.action.ACTION_SCREEN_ON")
|| intent.getAction().equals("android.intent.action.ACTION_SCREEN_OFF")) {
String action = intent.getAction();
Log.e("SNBootReceiver", action);
if (action.equals(Intent.ACTION_BOOT_COMPLETED)
|| action.equals(Intent.ACTION_BATTERY_CHANGED)
|| action.equals(Intent.ACTION_BATTERY_LOW)
|| action.equals(Intent.ACTION_BATTERY_OKAY)
|| action.equals(Intent.ACTION_POWER_CONNECTED)
|| action.equals(Intent.ACTION_POWER_DISCONNECTED)
|| action.equals(Intent.ACTION_DATE_CHANGED)
|| action.equals(Intent.ACTION_TIME_TICK)
|| action.equals(Intent.ACTION_USER_PRESENT)
|| action.equals(Intent.ACTION_SCREEN_ON)
|| action.equals(Intent.ACTION_SCREEN_OFF)
|| action.equals("android.intent.action.BATTERY_LEVEL_CHANGED")
) {
// Intent i = new Intent(context, InitJpushServer.class);
// context.startService(i);
context.startService(new Intent(context, GuardService.class));
@@ -36,6 +38,5 @@ public class BootReceiver extends BroadcastReceiver {
context.startService(new Intent(context, InitJpushServer.class));
context.startService(new Intent(context, MyDownloadService.class));
}
}
}

View File

@@ -1,10 +1,27 @@
package com.info.sn.service;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.os.IBinder;
import android.util.Log;
import com.info.sn.KeepAliveConnection;
import com.info.sn.activity.MainActivity;
import com.info.sn.bean.AppInfo;
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.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;
public class InitJpushServer extends Service {
public InitJpushServer() {
@@ -28,6 +45,10 @@ public class InitJpushServer extends Service {
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
// HTTPInterface.checkDevicesInfo(InitJpushServer.this);
HTTPInterface.getAllappPackage(InitJpushServer.this);
HTTPInterface.getForceInstall(InitJpushServer.this);
return START_STICKY;
}
}

View File

@@ -12,6 +12,7 @@ import android.net.Uri;
import android.os.Binder;
import android.os.Build;
import android.provider.Settings;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
@@ -33,6 +34,7 @@ import java.io.OutputStream;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Enumeration;
import java.util.List;
import java.util.zip.ZipEntry;
@@ -659,4 +661,69 @@ public class ApkUtils {
}
}
public static void addShortcut(Context context, String packageList) {
if (TextUtils.isEmpty(packageList)) {
return;
}
String[] stringList = packageList.split(",");
List<String> packages = new ArrayList<>(Arrays.asList(stringList));
String installedList = "";
for (String s : packages) {
if (s.equals("com.jiaoguanyi.store") || s.equals("com.jiaoguanyi.appstore")) {
continue;
}
if (!ApkUtils.isAvailable(context, s)) {
continue;
}
// ApkUtils.getStartActivityName(context, s);
installedList += s + ",";
Log.e("addShortcut", s);
}
if (installedList.length() != 0) {
installedList = installedList.substring(0, installedList.length() - 1);
} else {
Log.e("addShortcut", installedList);
}
boolean qch_force_app = Settings.System.putString(context.getContentResolver(), "qch_launcher_icon_app", installedList);
// String old = Settings.System.getString(context.getContentResolver(), "qch_launcher_icon_app");
// Log.e("addShortcut", old);
Log.e("addShortcut", "putstring:" + qch_force_app);
}
public static void writeAppPackageList(Context context, String result) {
ApkUtils.addShortcut(context, result);//开机之后添加图标到桌面
String appstore = "com.jiaoguanyi.appstore";
String store = "com.jiaoguanyi.store";
String infosn = "com.info.sn";
String appstoreuiui = "com.appstore.uiui";
String jgy1 = "com.uiuios.jgy1";
String jgy2 = "com.uiuios.jgy2";
if (!TextUtils.isEmpty(result)) {
if (!result.contains(appstore)) {
result = result + "," + appstore;
}
if (!result.contains(store)) {
result = result + "," + store;
}
if (!result.contains(jgy1)) {
result = result + "," + jgy1;
}
if (!result.contains(jgy2)) {
result = result + "," + jgy2;
}
if (!result.contains(infosn)) {
result = result + "," + infosn;
}
if (!result.contains(appstoreuiui)) {
result = result + "," + appstoreuiui;
}
boolean qch_app_forbid = Settings.System.putString(context.getContentResolver(), "qch_app_forbid", result);
Log.e("fht", "qch_app_forbid :" + result + ":" + qch_app_forbid);
} else {
Log.e("fht", "writeAppPackageList is null:");
}
}
}

View File

@@ -1371,6 +1371,10 @@ public class Utils {
}
public static void rebootDevices(Context context) {
if (BuildConfig.DEBUG) {
ToastUtil.show("收到重启设备推送消息");
return;
}
Intent iReboot = new Intent(Intent.ACTION_REBOOT);
iReboot.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(iReboot);