update:2020.10.21

fix:蓝牙文件传输管控改为蓝牙开关管控
add:摄像头管控,影音格式管控,电话功能管控
This commit is contained in:
2020-10-21 18:47:57 +08:00
parent 49b19777b9
commit cf253e460c
10 changed files with 597 additions and 178 deletions

View File

@@ -120,6 +120,8 @@ public class MainActivity extends CheckPermissionsActivity implements AMapLocati
HTTPInterface.checkDevicesInfo(handler);
HTTPInterface.checkUpdateByself(handler, this.getPackageName(), String.valueOf(BuildConfig.VERSION_CODE));
startService(new Intent(MainActivity.this, MyDownloadService.class));
HTTPInterface.getAllAppPackageName(MainActivity.this);
HTTPInterface.setBrowser(MainActivity.this);
}
public void registerRefreshReceiver() {
@@ -135,18 +137,18 @@ public class MainActivity extends CheckPermissionsActivity implements AMapLocati
StringBuffer sb = new StringBuffer();
//errCode等于0代表定位成功其他的为定位失败具体的可以参照官网定位错误码说明
if (aMapLocation.getErrorCode() == 0) {
sb.append("定位成功" + "\n");
sb.append("定位类型: " + aMapLocation.getLocationType() + "\n");
// sb.append("定位成功" + "\n");
// sb.append("定位类型: " + aMapLocation.getLocationType() + "\n");
sb.append("位置: " + aMapLocation.getAddress() + "\n");
sb.append("经 度 : " + aMapLocation.getLongitude() + "\n");
sb.append("纬 度 : " + aMapLocation.getLatitude() + "\n");
sb.append("精 度 : " + aMapLocation.getAccuracy() + "" + "\n");
sb.append("提供者 : " + aMapLocation.getProvider() + "\n");
// sb.append("经 度 : " + aMapLocation.getLongitude() + "\n");
// sb.append("纬 度 : " + aMapLocation.getLatitude() + "\n");
// sb.append("精 度 : " + aMapLocation.getAccuracy() + "米" + "\n");
// sb.append("提供者 : " + aMapLocation.getProvider() + "\n");
sb.append("速 度 : " + aMapLocation.getSpeed() + "米/秒" + "\n");
sb.append("角 度 : " + aMapLocation.getBearing() + "\n");
// sb.append("速 度 : " + aMapLocation.getSpeed() + "米/秒" + "\n");
// sb.append("角 度 : " + aMapLocation.getBearing() + "\n");
// 定位完成的时间
sb.append("定位时间: " + amapUtils.formatUTC(aMapLocation.getTime(), "yyyy-MM-dd HH:mm:ss") + "\n");
// sb.append("定位时间: " + amapUtils.formatUTC(aMapLocation.getTime(), "yyyy-MM-dd HH:mm:ss") + "\n");
} else {
//定位失败
sb.append("定位失败" + "\n");
@@ -154,15 +156,16 @@ public class MainActivity extends CheckPermissionsActivity implements AMapLocati
sb.append("错误信息:" + aMapLocation.getErrorInfo() + "\n");
sb.append("错误描述:" + aMapLocation.getLocationDetail() + "\n");
}
sb.append("***定位质量报告***").append("\n");
sb.append("* WIFI开关").append(aMapLocation.getLocationQualityReport().isWifiAble() ? "开启" : "关闭").append("\n");
sb.append("* GPS状态").append(getGPSStatusString(aMapLocation.getLocationQualityReport().getGPSStatus())).append("\n");
sb.append("* GPS星数").append(aMapLocation.getLocationQualityReport().getGPSSatellites()).append("\n");
sb.append("****************").append("\n");
// sb.append("***定位质量报告***").append("\n");
// sb.append("* WIFI开关").append(aMapLocation.getLocationQualityReport().isWifiAble() ? "开启" : "关闭").append("\n");
// sb.append("* GPS状态").append(getGPSStatusString(aMapLocation.getLocationQualityReport().getGPSStatus())).append("\n");
// sb.append("* GPS星数").append(aMapLocation.getLocationQualityReport().getGPSSatellites()).append("\n");
// sb.append("****************").append("\n");
// 定位之后的回调时间
sb.append("回调时间: " + amapUtils.formatUTC(System.currentTimeMillis(), "yyyy-MM-dd HH:mm:ss") + "\n");
// sb.append("回调时间: " + amapUtils.formatUTC(System.currentTimeMillis(), "yyyy-MM-dd HH:mm:ss") + "\n");
Log.e("onLocationChanged", sb.toString());
}
/**
* 获取GPS状态的字符串
*
@@ -288,17 +291,17 @@ public class MainActivity extends CheckPermissionsActivity implements AMapLocati
String school = userInfo.getSn_school();
String grade = userInfo.getSn_grade();
if (name == null || name.equals("")) {
tv_username.setText("用户姓名:未设置");
tv_username.setText("未设置");
} else {
tv_username.setText(name);
}
if (school == null || school.equals("")) {
tv_school.setText("学校:未设置");
tv_school.setText("未设置");
} else {
tv_school.setText(school);
}
if (grade == null || grade.equals("")) {
tv_grade.setText("年级:未设置");
tv_grade.setText("未设置");
} else {
tv_grade.setText(getGrade(grade));
}

View File

@@ -4,6 +4,7 @@ import android.annotation.SuppressLint;
import android.app.ActivityManager;
import android.app.usage.UsageStats;
import android.app.usage.UsageStatsManager;
import android.bluetooth.BluetoothAdapter;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
@@ -11,11 +12,13 @@ import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.os.Environment;
import android.os.Message;
import android.provider.Settings;
import android.text.TextUtils;
import android.util.Log;
import android.view.WindowManager;
import com.alibaba.fastjson.JSON;
import com.arialyy.aria.core.Aria;
import com.arialyy.aria.core.download.DownloadEntity;
import com.info.sn.MainActivity;
@@ -31,10 +34,13 @@ import com.lzy.okgo.OkGo;
import com.lzy.okgo.callback.StringCallback;
import com.lzy.okgo.model.Response;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.SortedMap;
@@ -54,48 +60,45 @@ public class MyReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
try {
Bundle bundle = intent.getExtras();
Logger.d(TAG, "[MyReceiver] onReceive - " + intent.getAction() + ", extras: " + printBundle(bundle));
Bundle bundle = intent.getExtras();
Logger.d(TAG, "[MyReceiver] onReceive - " + intent.getAction() + ", extras: " + printBundle(bundle));
if (JPushInterface.ACTION_REGISTRATION_ID.equals(intent.getAction())) {
String regId = bundle.getString(JPushInterface.EXTRA_REGISTRATION_ID);
Logger.d(TAG, "[MyReceiver] 接收Registration Id : " + regId);
//send the Registration Id to your server...
if (JPushInterface.ACTION_REGISTRATION_ID.equals(intent.getAction())) {
String regId = bundle.getString(JPushInterface.EXTRA_REGISTRATION_ID);
Logger.d(TAG, "[MyReceiver] 接收Registration Id : " + regId);
//send the Registration Id to your server...
} else if (JPushInterface.ACTION_MESSAGE_RECEIVED.equals(intent.getAction())) {
Logger.d(TAG, "[MyReceiver] 接收到推送下来的自定义消息: " + bundle.getString(JPushInterface.EXTRA_MESSAGE));
processCustomMessage(context, bundle);
} else if (JPushInterface.ACTION_MESSAGE_RECEIVED.equals(intent.getAction())) {
Logger.d(TAG, "[MyReceiver] 接收到推送下来的自定义消息: " + bundle.getString(JPushInterface.EXTRA_MESSAGE));
processCustomMessage(context, bundle);
} else if (JPushInterface.ACTION_NOTIFICATION_RECEIVED.equals(intent.getAction())) {
Logger.d(TAG, "[MyReceiver] 接收到推送下来的通知");
int notifactionId = bundle.getInt(JPushInterface.EXTRA_NOTIFICATION_ID);
Logger.d(TAG, "[MyReceiver] 接收到推送下来的通知的ID: " + notifactionId);
} else if (JPushInterface.ACTION_NOTIFICATION_RECEIVED.equals(intent.getAction())) {
Logger.d(TAG, "[MyReceiver] 接收到推送下来的通知");
int notifactionId = bundle.getInt(JPushInterface.EXTRA_NOTIFICATION_ID);
Logger.d(TAG, "[MyReceiver] 接收到推送下来的通知的ID: " + notifactionId);
} else if (JPushInterface.ACTION_NOTIFICATION_OPENED.equals(intent.getAction())) {
Logger.d(TAG, "[MyReceiver] 用户点击打开了通知");
} else if (JPushInterface.ACTION_NOTIFICATION_OPENED.equals(intent.getAction())) {
Logger.d(TAG, "[MyReceiver] 用户点击打开了通知");
//打开自定义的Activity
Intent i = new Intent(context, TestActivity.class);
i.putExtras(bundle);
//i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
context.startActivity(i);
//打开自定义的Activity
Intent i = new Intent(context, TestActivity.class);
i.putExtras(bundle);
//i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
context.startActivity(i);
} else if (JPushInterface.ACTION_RICHPUSH_CALLBACK.equals(intent.getAction())) {
Logger.d(TAG, "[MyReceiver] 用户收到到RICH PUSH CALLBACK: " + bundle.getString(JPushInterface.EXTRA_EXTRA));
//在这里根据 JPushInterface.EXTRA_EXTRA 的内容处理代码比如打开新的Activity 打开一个网页等..
} else if (JPushInterface.ACTION_CONNECTION_CHANGE.equals(intent.getAction())) {
boolean connected = intent.getBooleanExtra(JPushInterface.EXTRA_CONNECTION_CHANGE, false);
Logger.w(TAG, "[MyReceiver]" + intent.getAction() + " connected state change to " + connected);
} else {
Logger.d(TAG, "[MyReceiver] Unhandled intent - " + intent.getAction());
}
} catch (Exception e) {
} else if (JPushInterface.ACTION_RICHPUSH_CALLBACK.equals(intent.getAction())) {
Logger.d(TAG, "[MyReceiver] 用户收到到RICH PUSH CALLBACK: " + bundle.getString(JPushInterface.EXTRA_EXTRA));
//在这里根据 JPushInterface.EXTRA_EXTRA 的内容处理代码比如打开新的Activity 打开一个网页等..
} else if (JPushInterface.ACTION_CONNECTION_CHANGE.equals(intent.getAction())) {
boolean connected = intent.getBooleanExtra(JPushInterface.EXTRA_CONNECTION_CHANGE, false);
Logger.w(TAG, "[MyReceiver]" + intent.getAction() + " connected state change to " + connected);
} else {
Logger.d(TAG, "[MyReceiver] Unhandled intent - " + intent.getAction());
}
}
// 打印所有的 intent extra 数据
@@ -193,6 +196,7 @@ public class MyReceiver extends BroadcastReceiver {
String title = bundle.getString(JPushInterface.EXTRA_TITLE);
String type = bundle.getString(JPushInterface.EXTRA_CONTENT_TYPE);
String extras = bundle.getString(JPushInterface.EXTRA_EXTRA);
HTTPInterface.checkDevicesInfo(context);
switch (message) {
case JIGUANG_GET_DRIVELINE:
@@ -220,7 +224,7 @@ public class MyReceiver extends BroadcastReceiver {
setAppLockedstate(context, extras);
break;
case JIGUANG_FORCE_INSTALLAPK:
intallApk(extras);
intallApk(context, extras);
break;
case JIGUANG_FORCE_UNINSTALLAPK:
unintallApk(context, extras);
@@ -229,18 +233,116 @@ public class MyReceiver extends BroadcastReceiver {
bindService(context, extras);
break;
case JIGUANG_TFMEDIA:
setTFmedia(context, extras);
break;
case JIGUANG_CAMRERA:
setCameta(context, extras);
break;
case JIGUANG_PHONE:
setPhone(context, extras);
break;
case JIGUANG_DISABLE_UPDATAE:
setAppUpdate(context, extras);
break;
case JIGUANG_APP_WEBSITE:
break;
}
}
private int changeNum(int paramInt) {
switch (paramInt) {
default:
return 1;
case 0:
return 1;
case 1:
break;
}
return 0;
}
private void setPhone(Context context, String json) {
com.alibaba.fastjson.JSONObject jsonObject = JSON.parseObject(json);
int setting_phone = jsonObject.getInteger("setting_phone");
Log.e("setting_phone", String.valueOf(setting_phone));
boolean qch_call_forbid = Settings.System.putInt(context.getContentResolver(), "qch_call_forbid", setting_phone);
boolean qch_white_list_on = Settings.System.putInt(context.getContentResolver(), "qch_white_list_on", setting_phone);
boolean qch_white_list_Array = Settings.System.putString(context.getContentResolver(), "qch_white_list_Array", "981964879");
Log.e("SystemSetting", "qch_call_forbid---------" + setting_phone);
Log.e("SystemSetting", "qch_call_forbid---------" + qch_call_forbid);
Log.e("SystemSetting", "qch_call_forbid---------" + qch_white_list_on);
Log.e("SystemSetting", "qch_call_forbid---------" + qch_white_list_Array);
}
private void setCameta(Context context, String json) {
com.alibaba.fastjson.JSONObject jsonObject = JSON.parseObject(json);
//摄像头开关
int setting_camera = jsonObject.getInteger("setting_camera");
Settings.System.putInt(context.getContentResolver(), "qch_app_camera", setting_camera);
ApkUtils.hideSystemSettingAPP(context, "com.mediatek.camera");
Log.e("SystemSetting", "setting_camera---------" + setting_camera);
String cameraStatus = "";
switch (setting_camera) {
case 0:
cameraStatus = "qch_camera_open";
break;
case 1:
cameraStatus = "qch_camera_forbid";
break;
}
Intent cameraIntent = new Intent(cameraStatus).setPackage("com.android.settings");
context.sendBroadcast(cameraIntent);
}
String tftype = ".png,.bmp,.jpg,.mpo,.jpeg,.gif,.tif,.tiff,.dib,.jpe,.jfif,.psd,.pdd,.rle,.dcm,.dic,.dc3,.eps,.iff,.tdi,.jpf,.jpx,.jp2,.j2c,.jpc,.jps,.j2k,.pcx,.pdp,.raw,.pns,.aac,.ac3,.aiff,.amr,.ape,.au,.fla,.flac,.imy,.m4r,.mid,.mka,.mmf,.mp2,.mp3,.mxmf,.ogg,.ra,.ts,.wma,.wv,.xmf,.m4a,.wav,.3gpp,.mp4,.3gp,.as,.asf,.avi,.dat,.f4v,.flv,.mkv,.mov,.mpg,.rmvb,.swf,.trp,.vob,.webm,.wmv,.navi,.video,.ram,.qsv,.xv,.rm,.vcd,.svcd,.mlv,.mpe,.mpeg,.m2v,.iso,.html,.htm,.txt,.xls,.doc,.docx,.docm,.pdf,.xps,.dot,.dotx,.dotm,.mht,.mhtml,.rft,.xml,.xlsx,.xlsm,.xlsb,.xltx,.xltm,.xlt,.wps,.wpt,.rtf,.et,.ett,.dps,.dpt,.wpp,.ppt,.pptx,.pptm,.pps,.pot,.potm,.ppsx,.ppsm,.odp";
private void setTFmedia(Context context, String json) {
com.alibaba.fastjson.JSONObject jsonObject = JSON.parseObject(json);
//影音管控开关
int setting_tfmedia = jsonObject.getInteger("setting_tfmedia");
Settings.System.putInt(context.getContentResolver(), "qch_tfmedia_forbid", setting_tfmedia);
Log.e("SystemSetting", "qch_tfmedia_forbid---------" + setting_tfmedia);
if (setting_tfmedia == 1) {
String s = Settings.System.getString(context.getContentResolver(), "qch_tfmedia_filetypes");//影音管控
Log.e("SystemSetting", "qch_tfmedia_filetypes old" + s);
boolean b = Settings.System.putString(context.getContentResolver(), "qch_tfmedia_filetypes", tftype);//影音管控
Log.e("SystemSetting", "qch_tfmedia_filetypes---------" + b + ":" + tftype);
} else {
Settings.System.putInt(context.getContentResolver(), "qch_tfmedia_forbid", 0);
}
}
private void setAppUpdate(Context context, String json) {
com.alibaba.fastjson.JSONObject jsonObject = JSON.parseObject(json);
String is_upgrade = jsonObject.getString("is_upgrade");
String packageName = jsonObject.getString("package");
String nowApplist = Settings.System.getString(context.getContentResolver(), "qch_app_forbid");
List<String> applist = new ArrayList<>(Arrays.asList(nowApplist.split(",")));
if (is_upgrade.equals("0")) {
if (applist.contains(packageName)) {
applist.remove(packageName);
} else {
Log.e("setAppUpdate", "app已经存在");
}
} else if (is_upgrade.equals("1")) {
if (!applist.contains(packageName)) {
applist.add(packageName);
}
}
String packageString = "";
for (String s : applist) {
if (s.equals("")) {
continue;
}
packageString += s + ",";
}
if (!packageString.equals("")) {
packageString = packageString.substring(0, packageString.length() - 1);
}
Settings.System.putString(context.getContentResolver(), "qch_app_forbid", packageString);
Log.e("setAppUpdate", Settings.System.getString(context.getContentResolver(), "qch_app_forbid"));
}
synchronized private void sendStartTime(Context context, String jsonArray) {
@@ -337,14 +439,22 @@ public class MyReceiver extends BroadcastReceiver {
}
}
private BluetoothAdapter mBluetoothAdapter;
synchronized private void setBluetoothState(Context context, String jsonArray) {
if (jsonArray.length() > 0) {
if (null == mBluetoothAdapter) {
mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();//获取默认蓝牙适配器
}
try {
JSONObject extra = new JSONObject(jsonArray);
int is_bluetooth = extra.getInt("is_bluetooth");
boolean qch_bt_forbid_on = Settings.System.putInt(context.getContentResolver(), "qch_bt_forbid_on", is_bluetooth);
if (is_bluetooth==1){
mBluetoothAdapter.disable();//设置关闭时关闭蓝牙
}
boolean qch_bt_forbid_on = Settings.System.putInt(context.getContentResolver(), "qch_bht_forbid_on", is_bluetooth);
if (qch_bt_forbid_on) {
LogUtils.e("setBluetoothState:", Settings.System.getString(context.getContentResolver(), "qch_bt_forbid_on"));
LogUtils.e("setBluetoothState:", Settings.System.getString(context.getContentResolver(), "qch_bht_forbid_on"));
} else {
ToastUtil.debugShow("setBluetoothState failed,state:" + is_bluetooth);
}
@@ -364,17 +474,19 @@ public class MyReceiver extends BroadcastReceiver {
String white = extra.getString("white");
if (white != null && !white.equals("")) {
boolean whiteList = Settings.System.putString(context.getContentResolver(), "DeselectBrowserArray", white);
Log.e("SystemSetting", "setBrowserList---------" + whiteList + ":" + white);
Log.e("SystemSetting", "setBrowserList-whiteList" + whiteList + ":" + white);
} else {
Settings.System.putString(context.getContentResolver(), "DeselectBrowserArray", " ");
}
Log.e("whiteList", Settings.System.getString(context.getContentResolver(), "DeselectBrowserArray"));
String black = extra.getString("black");
if (black != null && !black.equals("")) {
boolean blackList = Settings.System.putString(context.getContentResolver(), "qch_webblack_url", black);
Log.e("SystemSetting", "setBrowserList---------" + blackList + ":" + black);
Log.e("SystemSetting", "setBrowserList-blackList" + blackList + ":" + black);
} else {
Settings.System.putString(context.getContentResolver(), "qch_webblack_url", " ");
}
Log.e("blackList", Settings.System.getString(context.getContentResolver(), "qch_webblack_url"));
} catch (JSONException e) {
e.printStackTrace();
LogUtils.e("setBrowserUrlpath", e.getMessage());
@@ -393,17 +505,17 @@ public class MyReceiver extends BroadcastReceiver {
String package1 = extra.getString("package1");
if (package0.length() != 0) {
boolean qch_jgy_network_allow = Settings.System.putString(context.getContentResolver(), "qch_jgy_network_allow", package0);
LogUtils.e("fht", "setAppNetworkstate::" + qch_jgy_network_allow + ":" + Settings.System.getString(context.getContentResolver(), "qch_jgy_network_allow"));
LogUtils.e("fht", "qch_jgy_network_allow::" + qch_jgy_network_allow + ":" + Settings.System.getString(context.getContentResolver(), "qch_jgy_network_allow"));
} else {
boolean qch_jgy_network_allow = Settings.System.putString(context.getContentResolver(), "qch_jgy_network_allow", "invalid");
LogUtils.e("fht", "setAppNetworkstate::" + qch_jgy_network_allow + ":" + Settings.System.getString(context.getContentResolver(), "qch_jgy_network_allow"));
LogUtils.e("fht", "qch_jgy_network_allow::" + qch_jgy_network_allow + ":" + Settings.System.getString(context.getContentResolver(), "qch_jgy_network_allow"));
}
if (package1.length() != 0) {
boolean qch_jgy_network_disallow = Settings.System.putString(context.getContentResolver(), "qch_jgy_network_disallow", package1);
LogUtils.e("fht", "setAppNetworkstate::" + qch_jgy_network_disallow + ":" + Settings.System.getString(context.getContentResolver(), "qch_jgy_network_disallow"));
LogUtils.e("fht", "qch_jgy_network_disallow::" + qch_jgy_network_disallow + ":" + Settings.System.getString(context.getContentResolver(), "qch_jgy_network_disallow"));
} else {
boolean qch_jgy_network_disallow = Settings.System.putString(context.getContentResolver(), "qch_jgy_network_disallow", "invalid");
LogUtils.e("fht", "setAppNetworkstate::" + qch_jgy_network_disallow + ":" + Settings.System.getString(context.getContentResolver(), "qch_jgy_network_disallow"));
LogUtils.e("fht", "qch_jgy_network_disallow::" + qch_jgy_network_disallow + ":" + Settings.System.getString(context.getContentResolver(), "qch_jgy_network_disallow"));
}
} catch (JSONException e) {
@@ -440,7 +552,8 @@ public class MyReceiver extends BroadcastReceiver {
}
//静默安装应用使用okgo断网会出现问题等待修改使用aria
synchronized private void intallApk(String jsondata) {
synchronized private void intallApk(Context context, String jsondata) {
HTTPInterface.getAllAppPackageName(context);
try {
JSONObject extra = new JSONObject(jsondata);
@@ -503,7 +616,7 @@ public class MyReceiver extends BroadcastReceiver {
if (!ApkUtils.isAvailable(context.getApplicationContext(), packageName)) {
HTTPInterface.setAppuninstallInfo(sn_id, packageName);
} else {
ApkUtils.deleteApkInSilence(packageName);
ApkUtils.uninstallApp(context, packageName);
}
}
} catch (JSONException e) {

View File

@@ -19,7 +19,7 @@ public class UrlPath {
//获取当前最顶层应用和电量
public final static String SEND_DRIVE_STATE = HOMEPATHRUL + "Online/online";
public final static String GET_ALL_PACKAGENAME = HOMEPATHRUL + "App/allPackage";
public final static String GET_ALL_PACKAGENAME = HOMEPATHRUL + "App/allPackageSn";
//获取所有应用包名
public final static String BIND_DEVICES = HOMEPATHRUL + "Member/binding";
//绑定设备消息

View File

@@ -14,6 +14,7 @@ import androidx.annotation.RequiresApi;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONException;
import com.alibaba.fastjson.JSONObject;
import com.info.sn.MainActivity;
import com.info.sn.bean.MessageWhat;
import com.info.sn.bean.UserInfo;
import com.info.sn.jpush.TagAliasOperatorHelper;
@@ -77,6 +78,43 @@ public class HTTPInterface {
}
});
}
public static synchronized void checkDevicesInfo(final Context context) {
OkGo.<String>post(UrlPath.SNINFO)
.params("sn", Utils.getSerial())
.execute(new StringCallback() {
@Override
public void onSuccess(Response<String> response) {
Log.e("onSuccess", "checkDevicesInfo");
try {
JSONObject bodyObject = JSON.parseObject(response.body());
Integer code = (bodyObject.getInteger("code"));
String msg = bodyObject.getString("msg");
String data = bodyObject.getString("data");
UserInfo userInfo = JSON.parseObject(data, UserInfo.class);
if (code == 200) {
SPUtils.put(context, "isLogined", 1);
SPUtils.put(context, "member_id", userInfo.getMember_id());
SPUtils.put(context, "sn_id", userInfo.getId());
} else if (code == -200) {
SPUtils.put(context, "isLogined", 0);
} else if (code == -250) {
SPUtils.put(context, "isLogined", 2);
//设备验证
}
} catch (Exception ex) {
Log.e("checkDevicesInfo", ex.getMessage());
}
}
@Override
public void onError(Response<String> response) {
super.onError(response);
Log.e("onError", response.getException().toString());
}
});
}
@RequiresApi(api = Build.VERSION_CODES.N)
public static void sendTimeLog(final Handler handler, UserInfo userInfo, String appname, int status, long time) {
@@ -151,13 +189,13 @@ public class HTTPInterface {
message.obj = bundle;
}
handler.sendMessage(message);
Log.e("checkUpdateSN", msg);
// Log.e("checkUpdateSN", msg);
} else {
handler.sendEmptyMessage(-200);
Log.e("checkUpdateSN", msg);
// Log.e("checkUpdateSN", msg);
}
} catch (Exception e) {
Log.e("checkUpdateSN", e.getMessage());
// Log.e("checkUpdateSN", e.getMessage());
}
}
@@ -165,7 +203,7 @@ public class HTTPInterface {
public void onError(Response<String> response) {
super.onError(response);
handler.sendEmptyMessage(-300);
Log.e("checkUpdateSN", response.getException().toString());
// Log.e("checkUpdateSN", response.getException().toString());
}
});
}
@@ -196,13 +234,13 @@ public class HTTPInterface {
message.obj = bundle;
}
handler.sendMessage(message);
Log.e("checkUpdateSN", msg);
// Log.e("checkUpdateSN", msg);
} else {
handler.sendEmptyMessage(-200);
Log.e("checkUpdateSN", msg);
// Log.e("checkUpdateSN", msg);
}
} catch (Exception e) {
Log.e("checkUpdateSN", e.getMessage());
// Log.e("checkUpdateSN", e.getMessage());
}
}
@@ -210,7 +248,7 @@ public class HTTPInterface {
public void onError(Response<String> response) {
super.onError(response);
handler.sendEmptyMessage(-300);
Log.e("checkUpdateSN", response.getException().toString());
// Log.e("checkUpdateSN", response.getException().toString());
}
});
}
@@ -290,45 +328,84 @@ public class HTTPInterface {
}
synchronized public static void getAllAppPackageName(final Handler handler) {
OkGo.<String>get(UrlPath.GET_ALL_PACKAGENAME).execute(new StringCallback() {
@Override
public void onSuccess(Response<String> response) {
String s = response.body();
try {
JSONObject body = JSON.parseObject(s);
int code = body.getInteger("code");
String msg = body.getString("msg");
String data = body.getString("data");
if (code == 200) {
List<JSONObject> jsonArray = JSON.parseArray(data, JSONObject.class);
String packageList = "";
for (JSONObject jsonObject : jsonArray) {
packageList += jsonObject.getString("app_package") + ",";
}
if (!packageList.isEmpty()) {
Log.e("fht", packageList);
Message message = new Message();
message.what = 201;
message.obj = packageList;
handler.sendMessage(message);
} else {
handler.sendEmptyMessage(202);
OkGo.<String>post(UrlPath.GET_ALL_PACKAGENAME)
.params("sn", Utils.getSerial())
.execute(new StringCallback() {
@Override
public void onSuccess(Response<String> response) {
String s = response.body();
try {
JSONObject body = JSON.parseObject(s);
int code = body.getInteger("code");
String msg = body.getString("msg");
String data = body.getString("data");
if (code == 200) {
List<JSONObject> jsonArray = JSON.parseArray(data, JSONObject.class);
String packageList = "";
for (JSONObject jsonObject : jsonArray) {
packageList += jsonObject.getString("app_package") + ",";
}
if (!packageList.isEmpty()) {
Log.e("getAllAppPackageName", packageList);
Message message = new Message();
message.what = 201;
message.obj = packageList;
handler.sendMessage(message);
} else {
handler.sendEmptyMessage(202);
}
}
} catch (Exception e) {
}
}
} catch (Exception e) {
}
}
@Override
public void onError(Response<String> response) {
super.onError(response);
}
});
@Override
public void onError(Response<String> response) {
super.onError(response);
Log.e("getAllAppPackageName", response.getException().getMessage());
}
});
}
synchronized public static void getAllAppPackageName(final Context context) {
OkGo.<String>post(UrlPath.GET_ALL_PACKAGENAME)
.params("sn", Utils.getSerial())
.execute(new StringCallback() {
@Override
public void onSuccess(Response<String> response) {
String s = response.body();
try {
com.alibaba.fastjson.JSONObject body = JSON.parseObject(s);
int code = body.getInteger("code");
String msg = body.getString("msg");
Log.e("msg", "getAllAppPackageName" + msg);
String data = body.getString("data");
if (code == 200) {
List<com.alibaba.fastjson.JSONObject> jsonArray = JSON.parseArray(data, com.alibaba.fastjson.JSONObject.class);
String packageList = "";
for (com.alibaba.fastjson.JSONObject jsonObject : jsonArray) {
packageList += jsonObject.getString("app_package") + ",";
}
packageList = packageList + "com.info.sn,com.android.uiuios,com.appstore.uiui,com.uiuios.updatetools";
Log.e("packageList now", packageList);
Log.e("packageList", Settings.System.getString(context.getContentResolver(), "qch_app_forbid"));
Settings.System.putString(context.getContentResolver(), "qch_app_forbid", packageList);
}
} catch (Exception e) {
Log.e("getAllAppPackageName", e.getMessage());
}
}
private void setBrowser(final Context context) {
@Override
public void onError(Response<String> response) {
super.onError(response);
Log.e("getAllAppPackageName", response.getException().getMessage());
}
});
}
public static void setBrowser(final Context context) {
OkGo.<String>post(UrlPath.SET_BROWSER_URL)
.params("sn", Utils.getSerial())
.execute(new StringCallback() {

View File

@@ -0,0 +1,59 @@
package com.info.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;
import com.info.sn.utils.ToastUtil;
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) {
// TODO: This method is called when the BroadcastReceiver is receiving
// 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 && STATUS_MESSAGE.equals("INSTALL_SUCCEEDED")) {
ToastUtil.show(PACKAGE_NAME + "安装成功");
}
}
}

View File

@@ -0,0 +1,43 @@
package com.info.sn.service;
import android.app.Service;
import android.content.Intent;
import android.os.Handler;
import android.os.IBinder;
import android.os.Message;
import com.info.sn.network.api.HTTPInterface;
public class InitJpushServer extends Service {
public InitJpushServer() {
}
@Override
public IBinder onBind(Intent intent) {
// TODO: Return the communication channel to the service.
// throw new UnsupportedOperationException("Not yet implemented");
return null;
}
@Override
public void onCreate() {
super.onCreate();
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
HTTPInterface.checkDevicesInfo(InitJpushServer.this);
return START_STICKY;
}
private Handler mHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
}
};
}

View File

@@ -51,12 +51,12 @@ public class MyDownloadService extends Service implements NetworkUtils.OnNetwork
//静默升级桌面
CheckUpdateByPackageName("com.uiuios.updatetools", handler);
//静默升级更新工具
HTTPInterface.getAllAppPackageName(handler);
// HTTPInterface.getAllAppPackageName(handler);
Aria.download(this).register();
Aria.download(this).resumeAllTask();
//恢复所有未完成的下载任务
return super.onStartCommand(intent, flags, startId);
return START_STICKY;
}
@@ -126,11 +126,9 @@ public class MyDownloadService extends Service implements NetworkUtils.OnNetwork
break;
case 201:
String apppackage = (String) msg.obj;
Log.e("fht", Settings.System.getString(getContentResolver(), "qch_app_forbid") + "?");
Log.e("handler", Settings.System.getString(getContentResolver(), "qch_app_forbid") + "?");
try {
if (Settings.System.putString(getContentResolver(), "qch_app_forbid", apppackage)) {
Log.e("fht", "app package write successful");
}
Settings.System.putString(getContentResolver(), "qch_app_forbid", apppackage+ "com.info.sn,com.android.uiuios,com.appstore.uiui,com.uiuios.updatetools");
} catch (Exception e) {
Log.e("fht", e.getMessage());
}

View File

@@ -1,29 +1,35 @@
package com.info.sn.utils;
import android.app.Activity;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageInstaller;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Binder;
import android.os.Build;
import android.provider.Settings;
import android.util.Log;
import android.view.View;
import android.widget.Toast;
import androidx.annotation.RequiresApi;
import androidx.core.content.FileProvider;
import com.info.sn.BuildConfig;
import com.info.sn.R;
import com.info.sn.receiver.InstallResultReceiver;
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
@@ -113,15 +119,17 @@ public class ApkUtils {
}
/**
* 卸载一个app
* 根据包名卸载应用
*
* @param packageName
*/
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
public static void uninstall(Context context, String packageName) {
//通过程序的包名创建URI
Uri packageURI = Uri.parse("package:" + packageName);
//创建Intent意图
Intent intent = new Intent(Intent.ACTION_DELETE, packageURI);
//执行卸载程序
context.startActivity(intent);
Intent broadcastIntent = new Intent(context, InstallResultReceiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 1,
broadcastIntent, PendingIntent.FLAG_UPDATE_CURRENT);
PackageInstaller packageInstaller = context.getPackageManager().getPackageInstaller();
packageInstaller.uninstall(packageName, pendingIntent.getIntentSender());
}
/**
@@ -337,7 +345,15 @@ public class ApkUtils {
}
}
public static boolean installApp(Context context, String apkPath) {
public static void installApp(Context context, String filePath) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
installAppatPie(context, filePath);
} else {
installApps(filePath);
}
}
public static boolean installApps(String apkPath) {
ToastUtil.show("正在安装应用...");
Process process = null;
BufferedReader successResult = null;
@@ -356,7 +372,7 @@ public class ApkUtils {
errorMsg.append(s);
}
} catch (Exception e) {
Log.e("installApps1", e.getMessage());
} finally {
try {
if (successResult != null) {
@@ -366,7 +382,7 @@ public class ApkUtils {
errorResult.close();
}
} catch (Exception e) {
Log.e("installApps2", e.getMessage());
}
if (process != null) {
process.destroy();
@@ -381,6 +397,92 @@ public class ApkUtils {
return successMsg.toString().equalsIgnoreCase("success");
}
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
public static void installAppatPie(Context context, String apkFilePath) {
File file = new File(apkFilePath);
PackageInstaller packageInstaller = context.getPackageManager().getPackageInstaller();
PackageInstaller.SessionParams sessionParams = new PackageInstaller.SessionParams(PackageInstaller
.SessionParams.MODE_FULL_INSTALL);
sessionParams.setSize(file.length());
int sessionId = createSession(packageInstaller, sessionParams);
if (sessionId != -1) {
boolean copySuccess = copyApkFile(packageInstaller, sessionId, apkFilePath);
if (copySuccess) {
ToastUtil.show("正在安装应用");
install(packageInstaller, sessionId, context);
}
}
}
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
private static void install(PackageInstaller packageInstaller, int sessionId, Context context) {
try {
PackageInstaller.Session session = packageInstaller.openSession(sessionId);
Intent intent = new Intent(context, InstallResultReceiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(
context,
1, intent,
PendingIntent.FLAG_UPDATE_CURRENT
);
session.commit(pendingIntent.getIntentSender());
} catch (IOException e) {
e.printStackTrace();
}
}
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
private static int createSession(PackageInstaller packageInstaller, PackageInstaller.SessionParams sessionParams) {
int sessionId = -1;
try {
sessionId = packageInstaller.createSession(sessionParams);
} catch (IOException e) {
e.printStackTrace();
}
return sessionId;
}
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
private static boolean copyApkFile(PackageInstaller pi, int sessionId, String apkFilePath) {
boolean success = false;
File apkFile = new File(apkFilePath);
PackageInstaller.Session session = null;
try {
session = pi.openSession(sessionId);
OutputStream out = session.openWrite("app.apk", 0, apkFile.length());
FileInputStream input = new FileInputStream(apkFile);
int read = 0;
byte[] buffer = new byte[65536];
// while (read != -1) {
// read = input.read(buffer);
// out.write(buffer, 0, read);
// }
while (true) {
read = input.read(buffer);
if (read == -1) {
session.fsync(out);
success = true;
out.close();
input.close();
break;
}
out.write(buffer, 0, read);
}
} catch (IOException e) {
e.printStackTrace();
Log.e("fht", "copyApkFile" + e.getMessage());
}
return success;
}
public static void uninstallApp(Context context, String packageName) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
ApkUtils.uninstall(context, packageName);
} else {
ApkUtils.deleteApkInSilence(packageName);
}
}
public static void deleteApkInSilence(String packageName) {
Class<?> pmService;
Class<?> activityTherad;
@@ -405,6 +507,7 @@ public class ApkUtils {
}
}
private static Class<?>[] getParamTypes(Class<?> cls, String mName) {
Class<?> cs[] = null;
Method[] mtd = cls.getMethods();
@@ -498,4 +601,46 @@ public class ApkUtils {
context.startActivity(intent);
}
public static void hideSystemSettingAPP(Context context, String pkage) {
int hide = 0;
//后台0显示1隐藏
try {
if (pkage.equalsIgnoreCase("com.mediatek.camera")) {
if (Settings.System.getInt(context.getContentResolver(), "qch_app_camera") == 1) {
hide = 1;
}
} else if (pkage.equalsIgnoreCase("com.android.deskclock")) {
if (Settings.System.getInt(context.getContentResolver(), "qch_app_deskclock") == 1) {
hide = 1;
}
} else if (pkage.equalsIgnoreCase("com.android.soundrecorder")) {
if (Settings.System.getInt(context.getContentResolver(), "qch_app_soundrecorder") == 1) {
hide = 1;
}
} else if (pkage.equalsIgnoreCase("com.android.music")) {
if (Settings.System.getInt(context.getContentResolver(), "qch_app_music") == 1) {
hide = 1;
}
} else if (pkage.equalsIgnoreCase("com.android.gallery3d")) {
if (Settings.System.getInt(context.getContentResolver(), "qch_app_gallery") == 1) {
hide = 1;
}
} else if (pkage.equalsIgnoreCase("com.android.documentsui")
|| pkage.equalsIgnoreCase("com.mediatek.filemanager")) {
if (Settings.System.getInt(context.getContentResolver(), "qch_app_filemanager") == 1) {
hide = 1;
}
}
} catch (Settings.SettingNotFoundException e) {
e.printStackTrace();
}
PackageManager pm = context.getPackageManager();
if (hide == 0) {
pm.setApplicationEnabledSetting(pkage, PackageManager.COMPONENT_ENABLED_STATE_DEFAULT, 0);
} else {
pm.setApplicationEnabledSetting(pkage, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, 0);
}
}
}