update:2020.5.11

fix:优化app内部网页管控
add:
This commit is contained in:
2020-05-11 18:34:39 +08:00
parent fbe3acd02b
commit eaa86225aa
11 changed files with 263 additions and 109 deletions

View File

@@ -5,6 +5,7 @@ import android.content.Context;
import android.content.Intent;
import android.content.res.Configuration;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.support.multidex.MultiDexApplication;
import android.util.Log;
@@ -63,7 +64,9 @@ import uk.co.chrisjenx.calligraphy.CalligraphyConfig;
* Created by Administrator on 2016/2/17 0017.
*/
public class MyApplication extends MultiDexApplication implements Thread.UncaughtExceptionHandler {
//public class MyApplication extends MultiDexApplication implements Thread.UncaughtExceptionHandler {
public class MyApplication extends MultiDexApplication {
public static String userName = null;
private static final String TAG = "--MyApplication--";
public static Context context;
@@ -117,7 +120,7 @@ public class MyApplication extends MultiDexApplication implements Thread.Uncaugh
JPushInterface.init(this);
context = getApplicationContext();
Thread.setDefaultUncaughtExceptionHandler(this);
// Thread.setDefaultUncaughtExceptionHandler(this);
mDateFormat = new SimpleDateFormat("HH:mm");
initOKHttp();
@@ -132,6 +135,7 @@ public class MyApplication extends MultiDexApplication implements Thread.Uncaugh
NetStateChangeReceiver.registerReceiver(this);
ToastUtil.init(this);
catchException();
}
@@ -437,26 +441,51 @@ public class MyApplication extends MultiDexApplication implements Thread.Uncaugh
}
@Override
public void uncaughtException(Thread thread, Throwable ex) {
Log.e(TAG, ex.getMessage(), new Exception(ex));
Utils.showToast(this, "程序出现异常,即将退出。。。");
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
e.printStackTrace();
}
Intent i = getBaseContext().getPackageManager()
.getLaunchIntentForPackage(getBaseContext().getPackageName());
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(i);
//退出程序
android.os.Process.killProcess(android.os.Process.myPid());
System.exit(1);
private void catchException() {
Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
@Override
public void uncaughtException(Thread t, Throwable e) {
Log.d("捕获异常子线程:", Thread.currentThread().getName() +
"在:" + e.getStackTrace()[0].getClassName());
}
}
);
//下面是新增方法!
new Handler(Looper.getMainLooper()).post(new Runnable() {
@Override
public void run() {
while (true) {
try {
Looper.loop(); //会先执行这个方法,然后在执行下面的异常捕获方法!
} catch (Exception e) {
Log.d("捕获异常主线程:", Thread.currentThread().getName() + "在:" + e.getStackTrace()[0].getClassName());
e.printStackTrace();
}
}
}
});
}
// @Override
// public void uncaughtException(Thread thread, Throwable ex) {
//// Log.e(TAG, ex.getMessage(), new Exception(ex));
//// Utils.showToast(this, "程序出现异常,即将退出。。。");
//// try {
//// Thread.sleep(3000);
//// } catch (InterruptedException e) {
//// e.printStackTrace();
//// }
//// Intent i = getBaseContext().getPackageManager()
//// .getLaunchIntentForPackage(getBaseContext().getPackageName());
//// i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
//// startActivity(i);
//// //退出程序
//// android.os.Process.killProcess(android.os.Process.myPid());
//// System.exit(1);
//
// }
@Override
public void onTerminate() {
super.onTerminate();
@@ -464,7 +493,7 @@ public class MyApplication extends MultiDexApplication implements Thread.Uncaugh
NetStateChangeReceiver.unregisterReceiver(this);
}
// static List<FileData> fileList = new ArrayList<>();
// static List<FileData> fileList = new ArrayList<>();
//
//
// static String packageName = "";
@@ -524,7 +553,7 @@ public class MyApplication extends MultiDexApplication implements Thread.Uncaugh
//
// }
// }
boolean isForecDownload = false;
boolean isForecDownload = false;
public boolean isDownloading() {
return isForecDownload;

View File

@@ -488,8 +488,12 @@ public class MainActivity extends AppCompatActivity implements NetStateChangeObs
locked = true;
Settings.System.putInt(getApplicationContext().getContentResolver(), "qch_unlock_ipad", 0);
Log.e("ttlocked2", "qch_unlock_ipad---------" + locked);
String ss = Settings.System.getString(getApplicationContext().getContentResolver(), "DeselectBrowserArray");
Log.e("ttlocked2", "DeselectBrowserArray---------" + ss);
String a = Settings.System.getString(getApplicationContext().getContentResolver(), "DeselectBrowserArray");
Log.e("ttlocked2", "DeselectBrowserArray---------" + a);
String b = Settings.System.getString(getApplicationContext().getContentResolver(), "qch_webblack_url");
Log.e("ttlocked2", "qch_webblack_url---------" + b);
lazyLoading();
}
}
@@ -510,12 +514,14 @@ public class MainActivity extends AppCompatActivity implements NetStateChangeObs
.subscribe(new Action1<Long>() {
@Override
public void call(Long aLong) {
getDeselectBrowerID();//浏览器网址管控
// getDeselectBrowerID();//浏览器网址管控
HTTPInterface.setBrowserList(MainActivity.this);//浏览器网址管控
HTTPInterface.setHomepagtag(mContext);//设置主页和标签
HTTPInterface.setAppinsideWeb(MainActivity.this);//app内部网页管控
getDeselectID();//ID管控
getAppLimitApi();//写入可被安装的包名
getAppInfo();//上传APP信息
getSystemSetting();//设置系统管控
HTTPInterface.setAppinsideWeb(MainActivity.this);//app内部网页管控
getNetAndLaunchSetting();//联网管控
// Aria.download(this).removeAllTask(true);
getForceDownload();//强制下载apk
@@ -639,7 +645,7 @@ public class MainActivity extends AppCompatActivity implements NetStateChangeObs
@Override
public void onError(Throwable e) {
Utils.showToast(getApplicationContext(), "网络出错!");
// Utils.showToast(getApplicationContext(), "网络出错!");
Log.e("mjsheng", "brankPicApi---error----" + e.getMessage());
}

View File

@@ -7,12 +7,14 @@ import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.provider.Settings;
import android.support.annotation.RequiresApi;
import android.util.Log;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONException;
import com.alibaba.fastjson.JSONObject;
import com.blankj.utilcode.util.LogUtils;
import com.lzy.okgo.OkGo;
@@ -339,7 +341,7 @@ public class HTTPInterface {
});
}
synchronized public static void setHomepagtag(Context context) {
synchronized public static void setHomepagtag(final Context context) {
OkGo.post(Configure.SET_HOMEPAG_TAG)
.params("key", Configure.HTTP_KEY)
.params("sn", Utils.getSerial())
@@ -353,23 +355,44 @@ public class HTTPInterface {
if (code == 200) {
String data = jsonObject.getString("data");
JSONObject jsondata = JSON.parseObject(data);
String homepag = jsondata.getString("homepage");
String labelpage = jsondata.getString("labelpage");
//主页
String homepagURL = jsondata.getString("homepage");
Intent homepag = new Intent("qch_app_brower_homepage");
if (homepagURL != null && !homepagURL.equals("")) {
homepag.putExtra("homepage", homepagURL);
} else {
homepag.putExtra("homepage", " ");
}
context.sendBroadcast(homepag);
//书签
String labelpage = jsondata.getString("labelpage");
Intent websiteBookMark = new Intent("qch_app_brower_website");
if (labelpage != null && !labelpage.equals("")) {
websiteBookMark.putExtra("websiteBookMark", labelpage);
} else {
websiteBookMark.putExtra("websiteBookMark", " ");
}
context.sendBroadcast(websiteBookMark);
} else {
ToastUtil.show(msg);
Intent intent1 = new Intent("qch_app_brower_homepage");
intent1.putExtra("homepage", " ");
context.sendBroadcast(intent1);
Intent intent2 = new Intent("qch_app_brower_website");
intent2.putExtra("websiteBookMark", " ");
context.sendBroadcast(intent2);
}
} catch (Exception e) {
Log.e("fht", e.getMessage());
ToastUtil.show("数据错误");
// ToastUtil.show("数据错误");
}
}
@Override
public void onError(Call call, Response response, Exception e) {
super.onError(call, response, e);
ToastUtil.show("网络连接失败");
// ToastUtil.show("网络连接失败");
}
});
}
@@ -390,44 +413,114 @@ public class HTTPInterface {
List<Appground> appgrounds = JSON.parseArray(data, Appground.class);
if (appgrounds != null && appgrounds.size() > 0) {
String strings = "";
String packageList = "";
String packageList = "";//单条管控名单
for (Appground appground : appgrounds) {
packageList += appground.getPackages() + ",";
strings += appground.toString() + ";";
if (appground.getAddress().equals("")) {
packageList += appground.getPackages() + ",";
} else {
strings += appground.toString() + ";";
}
}
if (packageList.length() > 0) {
//app内所有的网页禁止
packageList = packageList.substring(0, packageList.length() - 1);
//去掉多余的,
Log.e("setAppinsideWeb ", "packageList:" + packageList);
Intent qch_app_website = new Intent("qch_app_website");
qch_app_website.putExtra("package_name", packageList);
context.sendBroadcast(qch_app_website);
} else {
sendAllweb(context);
}
if (strings.length() > 0) {
//app内单个网页地址禁止打开
strings = strings.substring(0, strings.length() - 1);
//去掉多余的;
Log.e("setAppinsideWeb ", "strings:" + strings);
Intent intent = new Intent("qch_app_inside_website");
intent.putExtra("websitelist", strings);
context.sendBroadcast(intent);
} else {
sendwebUrl(context);
}
//app内所有的网页禁止
packageList = packageList.substring(0, packageList.length() - 1);
//去掉多余的,
Log.e("setAppinsideWeb ", "packageList:" + packageList);
Intent qch_app_website = new Intent("qch_app_website");
qch_app_website.putExtra("package_name", packageList);
context.sendBroadcast(qch_app_website);
//app内单个网页地址禁止打开
strings = strings.substring(0, strings.length() - 1);
//去掉多余的;
Log.e("setAppinsideWeb ", "strings:" + strings);
Intent intent = new Intent("qch_app_inside_website");
intent.putExtra("websitelist", strings);
context.sendBroadcast(intent);
}
} else if (code == 400) {
//列表为空的情况
Intent intent = new Intent("qch_app_website");
intent.putExtra("package_name", "Invalid");
context.sendBroadcast(intent);
sendAllweb(context);
sendwebUrl(context);
// ToastUtil.show(msg);
Log.e("fht", msg);
}
} catch (Exception e) {
Log.e("setAppinsideWeb", e.getMessage());
ToastUtil.show("数据错误");
// ToastUtil.show("数据错误");
}
}
@Override
public void onError(Call call, Response response, Exception e) {
super.onError(call, response, e);
ToastUtil.show("网络连接失败");
// ToastUtil.show("网络连接失败");
}
});
}
private static void sendAllweb(Context context) {
Intent intent = new Intent("qch_app_website");
intent.putExtra("package_name", "Invalid");
context.sendBroadcast(intent);
}
private static void sendwebUrl(Context context) {
Intent intent = new Intent("qch_app_inside_website");
intent.putExtra("websitelist", "Invalid");
context.sendBroadcast(intent);
}
//设置浏览器黑白名单
synchronized public static void setBrowserList(final Context context) {
OkGo.post(Configure.SET_BROWSER_LIST)
.params("key", Configure.HTTP_KEY)
.params("sn", Utils.getSerial())
.execute(new StringCallback() {
@Override
public void onSuccess(String s, Call call, Response response) {
try {
JSONObject jsonObject = JSON.parseObject(s);
int code = jsonObject.getInteger("code");
String msg = jsonObject.getString("msg");
if (code == 200) {
JSONObject data = JSON.parseObject(jsonObject.getString("data"));
String white = data.getString("white");
if (white != null && !white.equals("")) {
boolean whiteList = Settings.System.putString(context.getContentResolver(), "DeselectBrowserArray", white);
Log.e("SystemSetting", "setBrowserList---------" + whiteList);
} else {
Settings.System.putString(context.getContentResolver(), "DeselectBrowserArray", " ");
}
String black = data.getString("black");
if (black != null && !black.equals("")) {
boolean blackList = Settings.System.putString(context.getContentResolver(), "qch_webblack_url", black);
Log.e("SystemSetting", "setBrowserList---------" + blackList);
} else {
Settings.System.putString(context.getContentResolver(), "qch_webblack_url", " ");
}
} else {
Log.e("fht", msg);
}
} catch (JSONException e) {
Log.e("fht", e.getMessage());
}
}
@Override
public void onError(Call call, Response response, Exception e) {
super.onError(call, response, e);
}
});
}
}

View File

@@ -40,8 +40,10 @@ public class Network {
// public static final String ROOT_URL = "http://www.as.xueshibao.com.cn/api/"; 弃用
// public static final String ROOT_URL = "https://www.jiaoguanyi.com/api/";//正式 弃用
// public static final String ROOT_URL = "https://partner.jiaoguanyi.com/api/";//正式
public static final String ROOT_URL = "http://www.jiaoguanyi.cn/api/";//测试
// public static final String WebsocketURL = "ws://47.107.133.19:1234";
public static final String ROOT_URL = "http://www.jiaoguanyi.cn/api/";//测试
public static final String WebsocketURL = "ws://47.107.133.19:2345";
private static UploadAppInfoApi uploadAppInfoApi;
private static DeselectIDApi deselectIDApi;
@@ -216,6 +218,7 @@ public class Network {
Log.e("mjsheng", "systemSettingApi");
return updateApi;
}
public static NetAndLaunchApi getNetAndLaunchApi() {
if (netAndLaunchApi == null) {
Retrofit retrofit = new Retrofit.Builder()
@@ -229,6 +232,7 @@ public class Network {
Log.e("mjsheng", "netAndLaunchApi");
return netAndLaunchApi;
}
public static ForceDownloadApi getForceDownloadApi() {
if (forceDownloadApi == null) {
Retrofit retrofit = new Retrofit.Builder()

View File

@@ -19,4 +19,5 @@ public class UrlPath {
//获取当前最顶层应用和电量
public final static String SEND_DRIVE_STATE = HOMEPATHRUL + "Online/online";
}

View File

@@ -24,6 +24,7 @@ import com.mjsheng.myappstore.MyApplication;
import com.mjsheng.myappstore.comm.CommonDatas;
import com.mjsheng.myappstore.network.HTTPInterface;
import com.mjsheng.myappstore.network.Network;
import com.mjsheng.myappstore.server.InitJpushServer;
import com.mjsheng.myappstore.utils.ApkUtils;
import com.mjsheng.myappstore.utils.MySQLData;
import com.mjsheng.myappstore.utils.SaveListUtils;
@@ -363,40 +364,42 @@ public class MyJPushReceiver extends BroadcastReceiver {
}
private void getDeselectBrowerID() {
Network.getDeselectBrowserIDApi().getDeselectBrowserIDApi("YTM3YTAxNTJmMmZmNzkyM2E2YzIwZjlhZTc0NzNmMGI=", Utils.getSerial()).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Observer<ResponseBody>() {
public void onComplete() {
Log.e("mjsheng", "getDeselectBrowerID---onComplete");
}
HTTPInterface.setBrowserList(mContext);//浏览器网址管控
public void onError(Throwable param1Throwable) {
Log.e("mjsheng", "getDeselectBrowerID=onError:");
}
public void onNext(ResponseBody param1ResponseBody) {
try {
String str1;
String str2 = param1ResponseBody.string();
Log.e("mjsheng", "DeselectBrowserIDApi::" + str2);
JSONObject jSONObject = new JSONObject(str2);
switch (Integer.valueOf(jSONObject.optInt("code")).intValue()) {
case 200:
str1 = jSONObject.getJSONObject("data").optString("ids");
writeDeselectBrowserIDtoSystem(str1);
return;
}
Log.e("mjsheng", "getDeselectBrowerID---code is -200");
return;
} catch (Exception e) {
Log.e("mjsheng", "getDeselectBrowerID---wroing----" + e.getMessage());
e.printStackTrace();
return;
}
}
public void onSubscribe(Disposable param1Disposable) {
Log.e("mjsheng", "getDeselectBrowerID---onSubscribe");
}
});
// Network.getDeselectBrowserIDApi().getDeselectBrowserIDApi("YTM3YTAxNTJmMmZmNzkyM2E2YzIwZjlhZTc0NzNmMGI=", Utils.getSerial()).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Observer<ResponseBody>() {
// public void onComplete() {
// Log.e("mjsheng", "getDeselectBrowerID---onComplete");
// }
//
// public void onError(Throwable param1Throwable) {
// Log.e("mjsheng", "getDeselectBrowerID=onError:");
// }
//
// public void onNext(ResponseBody param1ResponseBody) {
// try {
// String str1;
// String str2 = param1ResponseBody.string();
// Log.e("mjsheng", "DeselectBrowserIDApi::" + str2);
// JSONObject jSONObject = new JSONObject(str2);
// switch (Integer.valueOf(jSONObject.optInt("code")).intValue()) {
// case 200:
// str1 = jSONObject.getJSONObject("data").optString("ids");
// writeDeselectBrowserIDtoSystem(str1);
// return;
// }
// Log.e("mjsheng", "getDeselectBrowerID---code is -200");
// return;
// } catch (Exception e) {
// Log.e("mjsheng", "getDeselectBrowerID---wroing----" + e.getMessage());
// e.printStackTrace();
// return;
// }
// }
//
// public void onSubscribe(Disposable param1Disposable) {
// Log.e("mjsheng", "getDeselectBrowerID---onSubscribe");
// }
// });
}
@@ -708,7 +711,7 @@ public class MyJPushReceiver extends BroadcastReceiver {
private void setHomepagtag(String s) {
//设置主页和标签
HTTPInterface.setHomepagtag(mContext);
HTTPInterface.setHomepagtag(mContext);//设置主页和标签
// if (TextUtils.isEmpty(s)) {
// Log.e("mjsheng", "setHomepagtag extras is null");
@@ -730,7 +733,7 @@ public class MyJPushReceiver extends BroadcastReceiver {
private void setAPPinsideWebsite(String s) {
//禁止app内部网页访问包名用,隔开
HTTPInterface.setAppinsideWeb(mContext);
HTTPInterface.setAppinsideWeb(mContext);//app内部网页管控
// if (TextUtils.isEmpty(s)) {
// Log.e("mjsheng", "setAPPinsideWebsite extras is null");
//

View File

@@ -22,6 +22,7 @@ import com.lzy.okgo.OkGo;
import com.lzy.okgo.callback.StringCallback;
import com.mjsheng.myappstore.BuildConfig;
import com.mjsheng.myappstore.MyApplication;
import com.mjsheng.myappstore.activity.MainActivity;
import com.mjsheng.myappstore.bean.ForceDownloadBean;
import com.mjsheng.myappstore.bean.ForceDownloadData;
import com.mjsheng.myappstore.bean.NetAndLaunchBean;
@@ -692,13 +693,16 @@ public class InitJpushServer extends Service {
Log.e("jpttlocked2", "DeselectBrowserArray---------" + ss);
getAppLimitApi();
getDeselectID();
getDeselectBrowerID();
// getDeselectBrowerID();
getNetAndLaunchSetting();
// Aria.download(this).removeAllTask(true);
getForceDownload();
getSystemSetting();//从后台获取功能状态
resetDevice();
HTTPInterface.setAppinsideWeb(InitJpushServer.this);
HTTPInterface.setBrowserList(InitJpushServer.this);//浏览器网址管控
HTTPInterface.setAppinsideWeb(InitJpushServer.this);//app内部网页管控
HTTPInterface.setHomepagtag(InitJpushServer.this);//设置主页和标签
}
}
}

View File

@@ -24,6 +24,7 @@ import com.mjsheng.myappstore.KeepAliveConnection;
import com.mjsheng.myappstore.MyApplication;
import com.mjsheng.myappstore.bean.AppDateInfo;
import com.mjsheng.myappstore.bean.FileData;
import com.mjsheng.myappstore.network.Network;
import com.mjsheng.myappstore.utils.ApkUtils;
import com.mjsheng.myappstore.utils.ServiceAliveUtils;
import com.mjsheng.myappstore.utils.Utils;
@@ -110,7 +111,7 @@ public class StepService extends Service {
* 初始化websocket连接
*/
private void initSocketClient() {
URI uri = URI.create("ws://47.107.133.19:1234");
URI uri = URI.create(Network.WebsocketURL);
// URI uri = URI.create("ws://echo.websocket.org");
// URI uri = URI.create("ws://123.207.136.134:9010/ajaxchattest");
client = new JWebSocketClient(uri) {

View File

@@ -193,8 +193,8 @@ public class Configure {
public static final String DELETE_GEDEVICE_ALIAS = HTTP_TAG_HEAD_NEW + "Sn/deleteAliases";
//浏览器书签主页设置
public static final String SET_HOMEPAG_TAG = HTTP_TAG_HEAD_NEW + "Label";
//
public static final String SET_APPINSIDEWEB= HTTP_TAG_HEAD_NEW + "Appground";
//app内部网页管控
public static final String SET_APPINSIDEWEB = HTTP_TAG_HEAD_NEW + "Appground";
//浏览器黑白名单地址
public static final String SET_BROWSER_LIST = HTTP_TAG_HEAD_NEW + "browser";
}

View File

@@ -685,11 +685,24 @@ public class Utils {
*
* @return
*/
@SuppressLint("MissingPermission")
public static String getSerial() {
return Build.SERIAL;
// return "QNS3AI000111";
// return "QNW8WJ900002";
String serial = "unknow";
try {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {//9.0+
serial = Build.getSerial();
} else if (Build.VERSION.SDK_INT > Build.VERSION_CODES.N) {//8.0+
serial = Build.SERIAL;
} else {//8.0-
Class<?> c = Class.forName("android.os.SystemProperties");
Method get = c.getMethod("get", String.class);
serial = (String) get.invoke(c, "ro.serialno");
}
} catch (Exception e) {
e.printStackTrace();
Log.e("e", "读取设备序列号异常:" + e.toString());
}
return serial;
}
public static final long A_GB = 1073741824;