update:2020.12.25

fix:新后台对接完成
add:
This commit is contained in:
2020-12-25 11:09:47 +08:00
parent 4d1eafae8c
commit 79ea8888c1
80 changed files with 3636 additions and 12151 deletions

View File

@@ -1,389 +0,0 @@
package com.info.sn;
import android.annotation.SuppressLint;
import android.app.ActivityManager;
import android.app.AlertDialog;
import android.app.Application;
import android.app.usage.UsageStats;
import android.app.usage.UsageStatsManager;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.os.Environment;
import android.os.Handler;
import android.os.Looper;
import android.provider.Settings;
import android.util.Log;
import android.view.View;
import android.view.WindowManager;
import android.widget.Toast;
import com.alibaba.fastjson.JSON;
import com.arialyy.annotations.Download;
import com.arialyy.aria.core.Aria;
import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.core.task.DownloadTask;
import com.blankj.utilcode.util.ToastUtils;
import com.info.sn.jpush.LocalBroadcastManager;
import com.info.sn.jpush.TagAliasOperatorHelper;
import com.info.sn.network.UrlPath;
import com.info.sn.network.api.HTTPInterface;
import com.info.sn.service.MyDownloadService;
import com.info.sn.utils.ApkUtils;
import com.info.sn.utils.LogUtils;
import com.info.sn.utils.SPUtils;
import com.info.sn.utils.ToastUtil;
import com.info.sn.utils.Utils;
import com.info.sn.view.CustomDialog;
import com.info.sn.view.InfoDialog;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.callback.StringCallback;
import com.lzy.okgo.model.Response;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.File;
import java.net.URI;
import java.util.List;
import java.util.SortedMap;
import java.util.TreeMap;
import java.util.concurrent.TimeUnit;
import cn.jpush.android.api.CustomMessage;
import cn.jpush.android.api.JPushInterface;
import cn.jpush.android.api.JPushMessage;
import rx.Observable;
import rx.functions.Action1;
//import com.blankj.utilcode.util.NetworkUtils;
//public class MyApplication extends Application implements NetworkUtils.OnNetworkStatusChangedListener {
public class MyApplication extends Application {
public static Context context;
private static MyApplication app;
@Override
public void onCreate() {
super.onCreate();
app = this;
ToastUtil.init(this);
context = getApplicationContext();
ToastUtil.init(this);
OkGo.getInstance().init(this);
// NetworkUtils.registerNetworkStatusChangedListener(this);
Aria.init(this);
Aria.download(this).resumeAllTask();
if (!BuildConfig.DEBUG) {
catchException();
}
}
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();
}
}
}
});
}
// protected void attachBaseContext(Context newBase) {
// super.attachBaseContext(newBase);
// MultiDex.install(this);
// }
@Override
public void onTerminate() {
super.onTerminate();
// NetworkUtils.unregisterNetworkStatusChangedListener(this);
}
public static MyApplication getInstance() {
return app;
}
public static Context getAppContext() {
if (context == null) {
context = getAppContext();
}
return context;
}
// public void onTagOperatorResult(JPushMessage jPushMessage) {
// if (jPushMessage == null) {
// return;
// }
// String s = "tags:\t";
// int errorCode = jPushMessage.getErrorCode();
// switch (errorCode) {
// case 0:
// Log.e("jiguangInterface", s + "Tag绑定成功");
// break;
// case 6001:
// Log.e("jiguangInterface", s + "无效的设置");
// break;
// case 6005:
// Log.e("jiguangInterface", s + "某一个 tag 字符串不合法");
// ToastUtil.show("设备标签不合法,联系管理员修改\t" + "code:6005");
// break;
// case 6006:
// Log.e("jiguangInterface", s + "某一个 tag 超长");
// ToastUtil.show("设备标签过长,联系管理员修改\t" + "code:6006");
// break;
// case 6007:
// Log.e("jiguangInterface", s + "tags 数量超出限制");
// ToastUtil.show("设备标签数量超出限制,联系管理员修改\t" + "code:6007");
// break;
// case 6008:
// Log.e("jiguangInterface", s + "tag 超出总长度限制");
// ToastUtil.show("设备标签超出总长度限制,联系管理员修改\t" + "code:6008");
// break;
// case 6011:
// Log.e("jiguangInterface", s + "短时间内操作过于频繁");
// break;
// case 6013:
// Log.e("jiguangInterface", s + "用户设备时间轴异常");
// ToastUtil.show("用户设备时间轴异常,修改后重新登陆\t" + "code:6013");
// break;
// case 6018:
// Log.e("jiguangInterface", s + "Tags 过多");
// ToastUtil.show("设备标签数量超出限制,联系管理员修改\t" + "code:6018");
// break;
// case 6021:
// Log.e("jiguangInterface", s + "tags 操作正在进行中");
// break;
//
// //需要重新设置
// case 6002:
// Log.e("jiguangInterface", s + "设置超时,请重试");
// setJpushTags();
// break;
// case 6014:
// Log.e("jiguangInterface", s + "服务器繁忙,建议重试");
// setJpushTags();
// break;
// case 6020:
// Log.e("jiguangInterface", s + "建议过一段时间再设置");
// setJpushTags();
// break;
// case 6024:
// Log.e("jiguangInterface", s + "服务器内部错误");
// setJpushTags();
// break;
// }
// }
// public static void setJpushTags() {
// Log.e("jiguangInterface", "10s后重新设置tags");
// Observable.timer(10000, TimeUnit.MILLISECONDS)
// .observeOn(rx.android.schedulers.AndroidSchedulers.mainThread())
// .subscribe(new Action1<Long>() {
// @Override
// public void call(Long aLong) {
// HTTPInterface.setJpushTags(context);
// }
// });
// }
public void onAliasOperatorResult(JPushMessage jPushMessage) {
if (jPushMessage == null) {
return;
}
String s = "alias:\t";
int errorCode = jPushMessage.getErrorCode();
switch (errorCode) {
case 0:
Log.e("jiguangInterface", s + "Alias绑定成功");
break;
case 6001:
Log.e("jiguangInterface", s + "无效的设置");
break;
case 6011:
Log.e("jiguangInterface", s + "短时间内操作过于频繁");
break;
case 6013:
Log.e("jiguangInterface", s + "用户设备时间轴异常");
ToastUtil.show("用户设备时间轴异常,修改后重新登陆\t" + s + "code:6013");
break;
case 6022:
Log.e("jiguangInterface", s + "alias 操作正在进行中");
break;
//需要重新设置
case 6002:
Log.e("jiguangInterface", s + "设置超时,请重试");
setJpushAlias();
break;
case 6014:
Log.e("jiguangInterface", s + "服务器繁忙,建议重试");
setJpushAlias();
break;
case 6020:
Log.e("jiguangInterface", s + "建议过一段时间再设置");
setJpushAlias();
break;
case 6024:
Log.e("jiguangInterface", s + "服务器内部错误");
setJpushAlias();
break;
case 6017:
case 6027:
Log.e("jiguangInterface", s + "别名绑定的设备数超过限制");
clean();
setJpushAlias();
break;
}
}
public static void setJpushAlias() {
Log.e("jiguangInterface", "10s后重新设置alias");
Observable.timer(10000, TimeUnit.MILLISECONDS)
.observeOn(rx.android.schedulers.AndroidSchedulers.mainThread())
.subscribe(new Action1<Long>() {
@Override
public void call(Long aLong) {
JPushInterface.setAlias(context, TagAliasOperatorHelper.sequence++, Utils.getSerial());
}
});
}
public void clean() {
//alias的绑定的设备超过10个但是alias应该是一个设备对应一个在重置设备后jpush的regid会变动所以需要清除
//https://docs.jiguang.cn/jpush/server/push/rest_api_v3_device/#_5
// HTTPInterface.cleanJpushAlias(Utils.getSerial());
}
synchronized public void manageCustomMessage(CustomMessage customMessage) {
String sn_id = (String) SPUtils.get(context, "sn_id", "-1");
String member_id = (String) SPUtils.get(context, "member_id", "-1");
if (customMessage == null) {
LogUtils.e("jiguang", "customMessage is NULL");
} else {
String MESSAGE = customMessage.message;
//MESSAGE用作判断
String TITLE = customMessage.title;
String CONTENT_TYPE = customMessage.contentType;
String EXTRA = customMessage.extra;
LogUtils.e("EXTRA", EXTRA);
// switch (MESSAGE) {
// case JIGUANG_GET_DRIVELINE:
// HTTPInterface.getDriveState(member_id, sn_id);
// break;
// case JIGUANG_GET_STARTTIME:
// sendStartTime(EXTRA);
// break;
// case JIGUANG_USB_STATE:
// setUsbState(EXTRA);
// break;
// case JIGUANG_TFCARD_STATE:
// setTfcardState(EXTRA);
// break;
// case JIGUANG_BLUETOOTH_STATE:
// setBluetoothState(EXTRA);
// break;
// case JIGUANG_BROWSER_URLPATH:
// setBrowserUrlpath(EXTRA);
// break;
// case JIGUANG_APP_NETWORKSTATE:
// setAppNetworkstate(EXTRA);
// break;
// case JIGUANG_APP_LOCKEDSTATE:
// setAppLockedstate(EXTRA);
// break;
// case JIGUANG_FORCE_INSTALLAPK:
// intallApk(EXTRA);
// break;
// case JIGUANG_FORCE_UNINSTALLAPK:
// unintallApk(EXTRA);
// break;
// case JIGUANG_BIND_DEVIVES:
// bindService(EXTRA);
// break;
// case JIGUANG_TFMEDIA:
//
// break;
// case JIGUANG_CAMRERA:
// break;
// case JIGUANG_PHONE:
// break;
// }
}
}
synchronized private void defaults(String jsonArray) {
if (jsonArray.length() > 0) {
try {
JSONObject extra = new JSONObject(jsonArray);
String packageName = extra.getString("package");
int is_network = extra.getInt("is_network");
} catch (JSONException e) {
e.printStackTrace();
LogUtils.e("defaults", e.getMessage());
}
} else {
ToastUtil.debugShow("defaults jsonArray is NULL");
}
}
//USB数据功能管控
//仅充电usb_charge
//MTP模式usb_mtp
//Midi模式usb_midi
// @Override
// public void onDisconnected() {
// LogUtils.e("onDisconnected", "网络断开");
// }
//
// @Override
// public void onConnected(NetworkUtils.NetworkType networkType) {
// Aria.download(this).resumeAllTask();
// LogUtils.e("onConnected", "网络连接");
//
// }
}

View File

@@ -1,7 +1,4 @@
package com.info.sn;
import androidx.appcompat.app.AppCompatActivity;
import androidx.constraintlayout.widget.ConstraintLayout;
package com.info.sn.activity;
import android.app.AlertDialog;
import android.content.BroadcastReceiver;
@@ -9,7 +6,7 @@ import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.ActivityInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.graphics.Bitmap;
@@ -26,8 +23,11 @@ import android.view.View;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
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;
@@ -36,29 +36,47 @@ import com.amap.api.location.AMapLocationQualityReport;
import com.hjq.permissions.OnPermission;
import com.hjq.permissions.Permission;
import com.hjq.permissions.XXPermissions;
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;
import com.info.sn.jpush.ExampleUtil;
import com.info.sn.jpush.LocalBroadcastManager;
import com.info.sn.jpush.TagAliasOperatorHelper;
import com.info.sn.network.api.HTTPInterface;
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;
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;
import com.info.sn.utils.Utils;
import com.info.sn.utils.amapUtils;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.callback.FileCallback;
import com.lzy.okgo.model.Progress;
import com.lzy.okgo.model.Response;
import java.io.File;
import java.util.List;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import cn.jpush.android.api.JPushInterface;
import io.reactivex.Observable;
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;
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;
@@ -69,8 +87,8 @@ import static com.info.sn.jpush.TagAliasOperatorHelper.ACTION_SET;
import static com.info.sn.jpush.TagAliasOperatorHelper.TagAliasBean;
import static com.info.sn.jpush.TagAliasOperatorHelper.sequence;
public class MainActivity extends CheckPermissionsActivity implements AMapLocationListener {
AMapLocationClient locationClient = null;
public class MainActivity extends CheckPermissionsActivity implements AMapLocationListener, CustomAdapt {
private static final String TAG = "MainActivity";
public static final String REFRESHACTION = BuildConfig.APPLICATION_ID + ".REFRESH";
public static boolean isForeground = false;
@@ -87,23 +105,12 @@ public class MainActivity extends CheckPermissionsActivity implements AMapLocati
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
locationClient = new AMapLocationClient(this);
AMapLocationClientOption option = new AMapLocationClientOption();
option.setLocationPurpose(AMapLocationClientOption.AMapLocationPurpose.SignIn);
option.setLocationMode(AMapLocationClientOption.AMapLocationMode.Hight_Accuracy);
option.setNeedAddress(true);
locationClient.setLocationOption(option);
//设置定位模式为AMapLocationMode.Hight_Accuracy高精度模式
//设置定位监听
locationClient.setLocationListener(this);
locationClient.startLocation();
// if (getRequestedOrientation() != ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE) {
// setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
// }
starService();
initAmap();
PackageManager pm = getPackageManager();
//后台为0可能传过来null
pm.setApplicationEnabledSetting("com.info.sn", PackageManager.COMPONENT_ENABLED_STATE_DEFAULT, 0);
requestPermission();
registerMessageReceiver(); // used for receive msg
registerRefreshReceiver();
@@ -118,13 +125,81 @@ public class MainActivity extends CheckPermissionsActivity implements AMapLocati
}
initView();
initData();
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);
// HTTPInterface.checkDevicesInfo(handler);
checkDevicesInfo();
// 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);
delay(MainActivity.this);
// HTTPInterface.get_settings(MainActivity.this);
}
private void initAmap() {
AMapLocationClient aMapLocationClient = MyApplication.getLocationClient();
aMapLocationClient.setLocationListener(new AMapLocationListener() {
@Override
public void onLocationChanged(AMapLocation aMapLocation) {
StringBuffer sb = new StringBuffer();
//errCode等于0代表定位成功其他的为定位失败具体的可以参照官网定位错误码说明
if (aMapLocation.getErrorCode() == 0) {
sb.append(aMapLocation.getAddress() + "\n");
SPUtils.put(MainActivity.this, "AmapAddress", aMapLocation.getAddress());
SPUtils.put(MainActivity.this, "longitude", aMapLocation.getLongitude());
SPUtils.put(MainActivity.this, "latitude", aMapLocation.getLatitude());
} else {
//定位失败
sb.append("定位失败" + "\n");
SPUtils.put(MainActivity.this, "AmapError", aMapLocation.getErrorInfo());
}
HTTPInterface.updateAdminInfo(MainActivity.this);
}
});
aMapLocationClient.stopLocation();
aMapLocationClient.startLocation();
}
private void delay(final Context context) {
Observable.timer(10000, TimeUnit.MILLISECONDS)
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Observer<Long>() {
@Override
public void onSubscribe(@NonNull Disposable d) {
}
@Override
public void onNext(@NonNull Long aLong) {
HTTPInterface.setBrowser(context);
HTTPInterface.getBrowserLabel(context);
getSystemSettings(context);
getForceInstall(context);
HTTPInterface.getAppStart(context);
HTTPInterface.getAppJump(context);
}
@Override
public void onError(@NonNull Throwable e) {
Log.e("delay", "onError: " + e.getMessage());
}
@Override
public void onComplete() {
Log.e("delay", "onComplete: ");
}
});
}
private void starService() {
startService(new Intent(this, GuardService.class));
startService(new Intent(this, StepService.class));
startService(new Intent(this, InitJpushServer.class));
startService(new Intent(this, MyDownloadService.class));
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
@@ -209,11 +284,39 @@ public class MainActivity extends CheckPermissionsActivity implements AMapLocati
@Override
public void onReceive(Context context, Intent intent) {
if (REFRESHACTION.equals(intent.getAction())) {
HTTPInterface.checkDevicesInfo(handler);
// HTTPInterface.checkDevicesInfo(handler);
checkDevicesInfo();
}
}
}
@Override
protected void onResume() {
super.onResume();
Log.e(TAG, "onResume: ");
checkDevicesInfo();
}
@Override
public boolean isBaseOnWidth() {
if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
return true;
} else if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
return false;
} else {
return false;
}
}
@Override
public float getSizeInDp() {
return 360;
}
private void initView() {
tv_note = findViewById(R.id.tv_note);
imageView = findViewById(R.id.imageView);
@@ -252,7 +355,7 @@ public class MainActivity extends CheckPermissionsActivity implements AMapLocati
if (mHits[0] >= (SystemClock.uptimeMillis() - DURATION)) {
mHits = new long[COUNTS];//重新初始化数组
ToastUtil.show("正在检查更新");
HTTPInterface.checkUpdateByself(handler, this.getPackageName(), String.valueOf(BuildConfig.VERSION_CODE));
// HTTPInterface.checkUpdateByself(handler, this.getPackageName(), String.valueOf(BuildConfig.VERSION_CODE));
}
}
@@ -267,11 +370,149 @@ public class MainActivity extends CheckPermissionsActivity implements AMapLocati
break;
case 2:
setImageAndText(imageView, "未经验证的设备,请联系客服");
break;
}
}
private void checkDevicesInfo() {
SNInfo snInfo = NetWorkManager.getsnInfoControl();
snInfo.getsninfo(Utils.getSerial())
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Observer<BaseResponse<UserInfo>>() {
@Override
public void onSubscribe(@NonNull Disposable d) {
}
@Override
public void onNext(@NonNull BaseResponse<UserInfo> userInfoBaseResponse) {
int code = userInfoBaseResponse.code;
if (code == 200) {
UserInfo userInfo = userInfoBaseResponse.data;
SPUtils.put(MainActivity.this, "isLogined", 1);
SPUtils.put(MainActivity.this, "member_id", userInfo.getMember_id());
SPUtils.put(MainActivity.this, "sn_id", userInfo.getId());
setImageAndText(imageView, "设备已绑定");
setUserInfo(userInfo);
} else if (code == -200) {
SPUtils.put(MainActivity.this, "isLogined", 0);
setImageAndText(imageView, "设备未绑定");
setUserInfo();
} else if (code == -250) {
SPUtils.put(MainActivity.this, "isLogined", 2);
setImageAndText(imageView, "未经验证的设备,请联系客服");
}
}
@Override
public void onError(@NonNull Throwable e) {
Log.e(TAG, "onError: " + e.getMessage());
}
@Override
public void onComplete() {
}
});
}
private void getSystemSettings(final Context context) {
Setting setting = NetWorkManager.getsettingControl();
setting.getSetting(Utils.getSerial())
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Observer<BaseResponse<SystemSettings>>() {
@Override
public void onSubscribe(@NonNull Disposable d) {
}
@Override
public void onNext(@NonNull BaseResponse<SystemSettings> systemSettingsBaseResponse) {
int code = systemSettingsBaseResponse.code;
if (code == 200) {
SystemSettings settings = systemSettingsBaseResponse.data;
Utils.setSystemSetting(context, settings.toString());
}
}
@Override
public void onError(@NonNull Throwable e) {
Log.e(TAG, "onError: " + e.getMessage());
}
@Override
public void onComplete() {
}
});
}
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
public boolean onKeyDown(int keyCode, KeyEvent event) {
@@ -299,8 +540,8 @@ public class MainActivity extends CheckPermissionsActivity implements AMapLocati
private void setUserInfo(UserInfo userInfo) {
String name = userInfo.getSn_name();
String school = userInfo.getSn_school();
String grade = userInfo.getSn_grade();
String school = userInfo.getSchool();
String grade = userInfo.getGrade();
if (name == null || name.equals("")) {
tv_username.setText("未设置");
} else {
@@ -319,10 +560,9 @@ public class MainActivity extends CheckPermissionsActivity implements AMapLocati
}
private void setUserInfo() {
tv_username.setText("未设置");
tv_school.setText("未设置");
tv_grade.setText("未设置");
tv_grade.setText("未设置");
tv_username.setText("");
tv_school.setText("");
tv_grade.setText("");
}
private String getGrade(String grade) {
@@ -432,43 +672,7 @@ public class MainActivity extends CheckPermissionsActivity implements AMapLocati
ad.setCanceledOnTouchOutside(false); //点击外面区域不会让dialog消失
ad.show();
} else {
OkGo.<File>get(url)
.execute(new FileCallback("Sninfo/" + url.substring(url.lastIndexOf("/") + 1)) {
@Override
public void onSuccess(final Response<File> response) {
// Settings.System.putString(getApplicationContext().getContentResolver(), "qch_app_forbid", "com.baidu.video");
// ApkUtils.installApkInSilence(response.body().getAbsolutePath(), Launcher.this.getPackageName());
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this)
.setTitle("软件更新")
.setIcon(R.mipmap.ic_launcher)
.setCancelable(false)
.setMessage("发现新版本,点击确定更新\n" + "更新内容:" + bundle.getString("content"))
.setPositiveButton("确定", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
ApkUtils.installApk(MainActivity.this, response.body());
dialogInterface.dismiss();
}
});
AlertDialog ad = builder.create();
ad.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
ad.setCanceledOnTouchOutside(false); //点击外面区域不会让dialog消失
ad.show();
Log.e("getFile", "download file successful,now installing");
}
@Override
public void onError(Response<File> response) {
super.onError(response);
Log.e("getFile", "File download Failure" + response.getException());
}
@Override
public void downloadProgress(Progress progress) {
super.downloadProgress(progress);
Log.e("getFile", "已下载:" + progress.currentSize + ",总大小:" + progress.totalSize + ",进度:" + progress.fraction + ",当前网速:" + progress.speed);
}
});
}
}

View File

@@ -0,0 +1,147 @@
package com.info.sn.base;
import android.app.Application;
import android.content.Context;
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
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.arialyy.aria.core.Aria;
import com.info.sn.BuildConfig;
import com.info.sn.activity.MainActivity;
import com.info.sn.network.HTTPInterface;
import com.info.sn.utils.LogUtils;
import com.info.sn.utils.SPUtils;
import com.info.sn.utils.ToastUtil;
import org.json.JSONException;
import org.json.JSONObject;
//import com.blankj.utilcode.util.NetworkUtils;
//public class MyApplication extends Application implements NetworkUtils.OnNetworkStatusChangedListener {
public class MyApplication extends Application {
public static Context context;
private static MyApplication app;
private static AMapLocationClient locationClient = null;
@Override
public void onCreate() {
super.onCreate();
app = this;
if (!BuildConfig.DEBUG) {
catchException();
}
ToastUtil.init(this);
context = getApplicationContext();
Aria.init(this);
Aria.download(this).resumeAllTask();
}
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();
}
}
}
});
}
// protected void attachBaseContext(Context newBase) {
// super.attachBaseContext(newBase);
// MultiDex.install(this);
// }
@Override
public void onTerminate() {
super.onTerminate();
//销毁时需要销毁定位client
if (null != locationClient) {
locationClient.onDestroy();
}
}
public static MyApplication getInstance() {
return app;
}
public static Context getAppContext() {
if (context == null) {
context = getAppContext();
}
return context;
}
public static AMapLocationClient getLocationClient() {
if (null == locationClient) {
initAmap();
}
return locationClient;
}
private static void initAmap() {
locationClient = new AMapLocationClient(context);
AMapLocationClientOption option = new AMapLocationClientOption();
option.setLocationPurpose(AMapLocationClientOption.AMapLocationPurpose.SignIn);
option.setLocationMode(AMapLocationClientOption.AMapLocationMode.Hight_Accuracy);
option.setNeedAddress(true);
//获取一次定位结果:
//该方法默认为false。
option.setOnceLocation(true);
//获取最近3s内精度最高的一次定位结果
//设置setOnceLocationLatest(boolean b)接口为true启动定位时SDK会返回最近3s内精度最高的一次定位结果。
// 如果设置其为truesetOnceLocation(boolean b)接口也会被设置为true反之不会默认为false。
option.setOnceLocationLatest(true);
locationClient.setLocationOption(option);
//设置定位模式为AMapLocationMode.Hight_Accuracy高精度模式。
//设置定位监听
locationClient.setLocationListener(new AMapLocationListener() {
@Override
public void onLocationChanged(AMapLocation aMapLocation) {
StringBuffer sb = new StringBuffer();
//errCode等于0代表定位成功其他的为定位失败具体的可以参照官网定位错误码说明
if (aMapLocation.getErrorCode() == 0) {
sb.append(aMapLocation.getAddress() + "\n");
SPUtils.put(context, "AmapAddress", aMapLocation.getAddress());
SPUtils.put(context, "longitude", aMapLocation.getLongitude());
SPUtils.put(context, "latitude", aMapLocation.getLatitude());
} else {
//定位失败
sb.append("定位失败" + "\n");
SPUtils.put(context, "AmapError", aMapLocation.getErrorInfo());
}
// Log.e("AmapAddress", (String) SPUtils.get(context, "AmapAddress", ""));
// Log.e("AmapError", (String) SPUtils.get(context, "AmapError", ""));
Log.e("addr", sb.toString());
HTTPInterface.updateAdminInfo(context);
}
});
//设置场景模式后最好调用一次stop再调用start以保证场景模式生效
locationClient.stopLocation();
locationClient.startLocation();
}
}

View File

@@ -0,0 +1,223 @@
package com.info.sn.bean;
import java.io.Serializable;
public class AppInfo implements Serializable {
private static final long serialVersionUID = 423463220624853188L;
private int app_id;
private String app_name;
private String app_package;
private String app_version_name;
private int app_version_code;
private long app_size;
private String app_desc;
private String app_url;
private String app_img;
private String app_preview1;
private String app_preview2;
private String app_preview3;
private String app_developer;
private String app_downloads;
private double app_score;
private int app_category;
private int app_subject;
private int app_type;
private int app_status;
private int is_delete;
private int is_update;
private int is_silent;
private String app_md5;
private String createtime;
public int getApp_id() {
return app_id;
}
public void setApp_id(int app_id) {
this.app_id = app_id;
}
public String getApp_name() {
return app_name;
}
public void setApp_name(String app_name) {
this.app_name = app_name;
}
public String getApp_package() {
return app_package;
}
public void setApp_package(String app_package) {
this.app_package = app_package;
}
public String getApp_version_name() {
return app_version_name;
}
public void setApp_version_name(String app_version_name) {
this.app_version_name = app_version_name;
}
public int getApp_version_code() {
return app_version_code;
}
public void setApp_version_code(int app_version_code) {
this.app_version_code = app_version_code;
}
public long getApp_size() {
return app_size;
}
public void setApp_size(long app_size) {
this.app_size = app_size;
}
public String getApp_desc() {
return app_desc;
}
public void setApp_desc(String app_desc) {
this.app_desc = app_desc;
}
public String getApp_url() {
return app_url;
}
public void setApp_url(String app_url) {
this.app_url = app_url;
}
public String getApp_img() {
return app_img;
}
public void setApp_img(String app_img) {
this.app_img = app_img;
}
public String getApp_preview1() {
return app_preview1;
}
public void setApp_preview1(String app_preview1) {
this.app_preview1 = app_preview1;
}
public String getApp_preview2() {
return app_preview2;
}
public void setApp_preview2(String app_preview2) {
this.app_preview2 = app_preview2;
}
public String getApp_preview3() {
return app_preview3;
}
public void setApp_preview3(String app_preview3) {
this.app_preview3 = app_preview3;
}
public String getApp_developer() {
return app_developer;
}
public void setApp_developer(String app_developer) {
this.app_developer = app_developer;
}
public String getApp_downloads() {
return app_downloads;
}
public void setApp_downloads(String app_downloads) {
this.app_downloads = app_downloads;
}
public double getApp_score() {
return app_score;
}
public void setApp_score(double app_score) {
this.app_score = app_score;
}
public int getApp_category() {
return app_category;
}
public void setApp_category(int app_category) {
this.app_category = app_category;
}
public int getApp_subject() {
return app_subject;
}
public void setApp_subject(int app_subject) {
this.app_subject = app_subject;
}
public int getApp_type() {
return app_type;
}
public void setApp_type(int app_type) {
this.app_type = app_type;
}
public int getApp_status() {
return app_status;
}
public void setApp_status(int app_status) {
this.app_status = app_status;
}
public int getIs_delete() {
return is_delete;
}
public void setIs_delete(int is_delete) {
this.is_delete = is_delete;
}
public int getIs_update() {
return is_update;
}
public void setIs_update(int is_update) {
this.is_update = is_update;
}
public int getIs_silent() {
return is_silent;
}
public void setIs_silent(int is_silent) {
this.is_silent = is_silent;
}
public String getCreatetime() {
return createtime;
}
public void setCreatetime(String createtime) {
this.createtime = createtime;
}
public String getApp_md5() {
return app_md5;
}
public void setApp_md5(String app_md5) {
this.app_md5 = app_md5;
}
}

View File

@@ -0,0 +1,34 @@
package com.info.sn.bean;
import androidx.annotation.NonNull;
import java.io.Serializable;
public class AppJump implements Serializable {
private static final long serialVersionUID = -8285407084971138695L;
private String app_package;
private String address;
public String getApp_package() {
return app_package;
}
public void setApp_package(String app_package) {
this.app_package = app_package;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
@NonNull
@Override
public String toString() {
return app_package + "," + address;
}
}

View File

@@ -0,0 +1,52 @@
package com.info.sn.bean;
import java.io.Serializable;
public class AppStart implements Serializable {
private static final long serialVersionUID = -4023020610471228336L;
private String app_package;
private int is_auto;
private int is_network;
private int is_upgrade;
private int is_slide;
public String getApp_package() {
return app_package;
}
public void setApp_package(String app_package) {
this.app_package = app_package;
}
public int getIs_auto() {
return is_auto;
}
public void setIs_auto(int is_auto) {
this.is_auto = is_auto;
}
public int getIs_network() {
return is_network;
}
public void setIs_network(int is_network) {
this.is_network = is_network;
}
public int getIs_upgrade() {
return is_upgrade;
}
public void setIs_upgrade(int is_upgrade) {
this.is_upgrade = is_upgrade;
}
public int getIs_slide() {
return is_slide;
}
public void setIs_slide(int is_slide) {
this.is_slide = is_slide;
}
}

View File

@@ -0,0 +1,25 @@
package com.info.sn.bean;
import androidx.annotation.NonNull;
import java.io.Serializable;
public class BaseResponse<T> implements Serializable {
private static final long serialVersionUID = 5468533687801294972L;
public int code;
public String msg;
public T data;
@NonNull
@Override
public String toString() {
return "{\n" +//
"\tcode=" + code + "\n" +//
"\tmsg='" + msg + "\'\n" +//
"\tdata=" + data + "\n" +//
'}';
}
}

View File

@@ -0,0 +1,25 @@
package com.info.sn.bean;
import java.io.Serializable;
public class BrowserBean implements Serializable {
private static final long serialVersionUID = 606139788929247720L;
private String address;
private int type;
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public int getType() {
return type;
}
public void setType(int type) {
this.type = type;
}
}

View File

@@ -0,0 +1,35 @@
package com.info.sn.bean;
import java.io.Serializable;
public class BrowserLabel implements Serializable {
private static final long serialVersionUID = 8836213741844057940L;
private String home_page;
private String label_page;
private int status;
public String getHome_page() {
return home_page;
}
public void setHome_page(String home_page) {
this.home_page = home_page;
}
public String getLabel_page() {
return label_page;
}
public void setLabel_page(String label_page) {
this.label_page = label_page;
}
public int getStatus() {
return status;
}
public void setStatus(int status) {
this.status = status;
}
}

View File

@@ -1,6 +0,0 @@
package com.info.sn.bean;
public class MessageWhat {
public static int CODE_SUCCESSFUL = 200;
}

View File

@@ -0,0 +1,249 @@
package com.info.sn.bean;
import androidx.annotation.NonNull;
import java.io.Serializable;
public class SystemSettings implements Serializable {
private static final long serialVersionUID = -7763589370400496883L;
private int setting_call;
private int setting_memory;
private String setting_usb;
private int setting_bluetooth;
private int setting_navigation;
private int setting_statusbar;
private int setting_tfmedia;
private String setting_phones;
private int setting_phone;
private int setting_camera;
private String setting_tfmedia_format;
private int setting_clock;
private int setting_recording;
private int setting_music;
private int setting_picture;
private int setting_wallpaper;
private int setting_file;
private int setting_bhtvideo;
private String setting_context;
private int setting_bht;
private int setting_hotspot;
public int getSetting_call() {
return setting_call;
}
public void setSetting_call(int setting_call) {
this.setting_call = setting_call;
}
public int getSetting_memory() {
return setting_memory;
}
public void setSetting_memory(int setting_memory) {
this.setting_memory = setting_memory;
}
public String getSetting_usb() {
return setting_usb;
}
public void setSetting_usb(String setting_usb) {
this.setting_usb = setting_usb;
}
public int getSetting_bluetooth() {
return setting_bluetooth;
}
public void setSetting_bluetooth(int setting_bluetooth) {
this.setting_bluetooth = setting_bluetooth;
}
public int getSetting_navigation() {
return setting_navigation;
}
public void setSetting_navigation(int setting_navigation) {
this.setting_navigation = setting_navigation;
}
public int getSetting_statusbar() {
return setting_statusbar;
}
public void setSetting_statusbar(int setting_statusbar) {
this.setting_statusbar = setting_statusbar;
}
public int getSetting_tfmedia() {
return setting_tfmedia;
}
public void setSetting_tfmedia(int setting_tfmedia) {
this.setting_tfmedia = setting_tfmedia;
}
public String getSetting_phones() {
return setting_phones;
}
public void setSetting_phones(String setting_phones) {
this.setting_phones = setting_phones;
}
public int getSetting_phone() {
return setting_phone;
}
public void setSetting_phone(int setting_phone) {
this.setting_phone = setting_phone;
}
public int getSetting_camera() {
return setting_camera;
}
public void setSetting_camera(int setting_camera) {
this.setting_camera = setting_camera;
}
public String getSetting_tfmedia_format() {
return setting_tfmedia_format;
}
public void setSetting_tfmedia_format(String setting_tfmedia_format) {
this.setting_tfmedia_format = setting_tfmedia_format;
}
public int getSetting_clock() {
return setting_clock;
}
public void setSetting_clock(int setting_clock) {
this.setting_clock = setting_clock;
}
public int getSetting_recording() {
return setting_recording;
}
public void setSetting_recording(int setting_recording) {
this.setting_recording = setting_recording;
}
public int getSetting_music() {
return setting_music;
}
public void setSetting_music(int setting_music) {
this.setting_music = setting_music;
}
public int getSetting_picture() {
return setting_picture;
}
public void setSetting_picture(int setting_picture) {
this.setting_picture = setting_picture;
}
public int getSetting_wallpaper() {
return setting_wallpaper;
}
public void setSetting_wallpaper(int setting_wallpaper) {
this.setting_wallpaper = setting_wallpaper;
}
public int getSetting_file() {
return setting_file;
}
public void setSetting_file(int setting_file) {
this.setting_file = setting_file;
}
public int getSetting_bhtvideo() {
return setting_bhtvideo;
}
public void setSetting_bhtvideo(int setting_bhtvideo) {
this.setting_bhtvideo = setting_bhtvideo;
}
public String getSetting_context() {
return setting_context;
}
public void setSetting_context(String setting_context) {
this.setting_context = setting_context;
}
public int getSetting_bht() {
return setting_bht;
}
public void setSetting_bht(int setting_bht) {
this.setting_bht = setting_bht;
}
public int getSetting_hotspot() {
return setting_hotspot;
}
public void setSetting_hotspot(int setting_hotspot) {
this.setting_hotspot = setting_hotspot;
}
@Override
public String toString() {
final StringBuilder sb = new StringBuilder("{");
sb.append("\"setting_call\":")
.append(setting_call);
sb.append(",\"setting_memory\":")
.append(setting_memory);
sb.append(",\"setting_usb\":\"")
.append(setting_usb).append('\"');
sb.append(",\"setting_bluetooth\":")
.append(setting_bluetooth);
sb.append(",\"setting_navigation\":")
.append(setting_navigation);
sb.append(",\"setting_statusbar\":")
.append(setting_statusbar);
sb.append(",\"setting_tfmedia\":")
.append(setting_tfmedia);
sb.append(",\"setting_phones\":\"")
.append(setting_phones).append('\"');
sb.append(",\"setting_phone\":")
.append(setting_phone);
sb.append(",\"setting_camera\":")
.append(setting_camera);
sb.append(",\"setting_tfmedia_format\":\"")
.append(setting_tfmedia_format).append('\"');
sb.append(",\"setting_clock\":")
.append(setting_clock);
sb.append(",\"setting_recording\":")
.append(setting_recording);
sb.append(",\"setting_music\":")
.append(setting_music);
sb.append(",\"setting_picture\":")
.append(setting_picture);
sb.append(",\"setting_wallpaper\":")
.append(setting_wallpaper);
sb.append(",\"setting_file\":")
.append(setting_file);
sb.append(",\"setting_bhtvideo\":")
.append(setting_bhtvideo);
sb.append(",\"setting_context\":\"")
.append(setting_context).append('\"');
sb.append(",\"setting_bht\":")
.append(setting_bht);
sb.append(",\"setting_hotspot\":")
.append(setting_hotspot);
sb.append('}');
return sb.toString();
}
}

View File

@@ -3,26 +3,28 @@ package com.info.sn.bean;
import java.io.Serializable;
public class UserInfo implements Serializable {
private String id;
private static final long serialVersionUID = -5268233433601073239L;
private int id;
private String sn_value;
private String sn_name;
private String sn_phone;
private String sn_grade;
private String grade;
private String sn_app;
private String sn_area;
private String member_id;
private int admin_id;
private String is_delete;
private String is_reset;
private String is_lock;
private String sn_school;
private String school;
private String createtime;
public String getId() {
public int getId() {
return id;
}
public void setId(String id) {
public void setId(int id) {
this.id = id;
}
@@ -50,12 +52,12 @@ public class UserInfo implements Serializable {
this.sn_phone = sn_phone;
}
public String getSn_grade() {
return sn_grade;
public String getGrade() {
return grade;
}
public void setSn_grade(String sn_grade) {
this.sn_grade = sn_grade;
public void setGrade(String grade) {
this.grade = grade;
}
public String getSn_app() {
@@ -74,12 +76,12 @@ public class UserInfo implements Serializable {
this.sn_area = sn_area;
}
public String getMember_id() {
return member_id;
public int getMember_id() {
return admin_id;
}
public void setMember_id(String member_id) {
this.member_id = member_id;
public void setMember_id(int admin_id) {
this.admin_id = admin_id;
}
public String getIs_delete() {
@@ -114,11 +116,11 @@ public class UserInfo implements Serializable {
this.createtime = createtime;
}
public String getSn_school() {
return sn_school;
public String getSchool() {
return school;
}
public void setSn_school(String sn_school) {
this.sn_school = sn_school;
public void setSchool(String school) {
this.school = school;
}
}

View File

@@ -1,6 +1,9 @@
package com.info.sn.jpush;
import android.app.Application;
import com.info.sn.BuildConfig;
import cn.jpush.android.api.JPushInterface;
/**
@@ -16,7 +19,7 @@ public class ExampleApplication extends Application {
Logger.d(TAG, "[ExampleApplication] onCreate");
super.onCreate();
JPushInterface.setDebugMode(true); // 设置开启日志,发布时请关闭日志
JPushInterface.setDebugMode(BuildConfig.DEBUG); // 设置开启日志,发布时请关闭日志
JPushInterface.init(this); // 初始化 JPush
}
}

View File

@@ -2,7 +2,7 @@ package com.info.sn.jpush;
import android.content.Context;
import com.info.sn.MyApplication;
import com.info.sn.base.MyApplication;
import cn.jpush.android.api.CustomMessage;
import cn.jpush.android.api.JPushMessage;
@@ -29,7 +29,6 @@ public class MyJPushMessageReceiver extends JPushMessageReceiver {
public void onAliasOperatorResult(Context context, JPushMessage jPushMessage) {
TagAliasOperatorHelper.getInstance().onAliasOperatorResult(context, jPushMessage);
super.onAliasOperatorResult(context, jPushMessage);
MyApplication.getInstance().onAliasOperatorResult(jPushMessage);
}
@Override

View File

@@ -11,8 +11,8 @@ import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.os.Environment;
import android.os.Message;
import android.provider.Settings;
import android.text.TextUtils;
import android.util.Log;
@@ -21,20 +21,19 @@ 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;
import com.info.sn.network.UrlPath;
import com.info.sn.network.api.HTTPInterface;
import com.info.sn.BuildConfig;
import com.info.sn.activity.MainActivity;
import com.info.sn.bean.BaseResponse;
import com.info.sn.network.HTTPInterface;
import com.info.sn.network.NetWorkManager;
import com.info.sn.network.api.BindDevices;
import com.info.sn.utils.ApkUtils;
import com.info.sn.utils.LogUtils;
import com.info.sn.utils.SPUtils;
import com.info.sn.utils.ToastUtil;
import com.info.sn.utils.Utils;
import com.info.sn.view.CustomDialog;
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;
@@ -47,6 +46,11 @@ import java.util.SortedMap;
import java.util.TreeMap;
import cn.jpush.android.api.JPushInterface;
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;
/**
* 自定义接收器
@@ -168,7 +172,17 @@ public class MyReceiver extends BroadcastReceiver {
//14.电话管控管控
private static final String JIGUANG_APP_WEBSITE = "16";
//16.app内部网址管控
private static final String JIGUANG_RESET_DEVICES = "17";
//设备恢复出厂设置
private static final String JIGUANG_BROWSER_LABEL = "18";
//浏览器书签
private static final String JIGUANG_APP_NET_AUTO = "19";
//APP联网自启管控
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) {
@@ -190,17 +204,17 @@ public class MyReceiver extends BroadcastReceiver {
// }
// LocalBroadcastManager.getInstance(context).sendBroadcast(msgIntent);
// }
String sn_id = (String) SPUtils.get(context, "sn_id", "-1");
String member_id = (String) SPUtils.get(context, "member_id", "-1");
int sn_id = (int) SPUtils.get(context, "sn_id", -1);
int member_id = (int) SPUtils.get(context, "member_id", -1);
String message = bundle.getString(JPushInterface.EXTRA_MESSAGE);
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);
// HTTPInterface.checkDevicesInfo(context);
switch (message) {
case JIGUANG_GET_DRIVELINE:
HTTPInterface.getDriveState(member_id, sn_id);
// HTTPInterface.getDriveState(member_id, sn_id);
break;
case JIGUANG_GET_STARTTIME:
sendStartTime(context, extras);
@@ -215,7 +229,8 @@ public class MyReceiver extends BroadcastReceiver {
setBluetoothState(context, extras);
break;
case JIGUANG_BROWSER_URLPATH:
setBrowserUrlpath(context, extras);
// setBrowserUrlpath(context, extras);
HTTPInterface.setBrowser(context);
break;
case JIGUANG_APP_NETWORKSTATE:
setAppNetworkstate(context, extras);
@@ -245,7 +260,26 @@ public class MyReceiver extends BroadcastReceiver {
setAppUpdate(context, extras);
break;
case JIGUANG_APP_WEBSITE:
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);
break;
case JIGUANG_BROWSER_LABEL:
HTTPInterface.getBrowserLabel(context);
break;
case JIGUANG_SYSTEM_SETTING:
Utils.setSystemSetting(context, extras);
break;
case JIGUANG_RESET_DEVICES:
Utils.doMasterClear(context);
break;
}
}
@@ -351,7 +385,7 @@ public class MyReceiver extends BroadcastReceiver {
JSONObject extra = new JSONObject(jsonArray);
String random = extra.getString("random");
int battery = getSystemBattery(context);
HTTPInterface.sendStartTime(context, 0, getTaskPackname(context), battery, random);
// HTTPInterface.sendStartTime(context, 0, getTaskPackname(context), battery, random);
} catch (JSONException e) {
e.printStackTrace();
}
@@ -463,7 +497,7 @@ public class MyReceiver extends BroadcastReceiver {
try {
JSONObject extra = new JSONObject(jsonArray);
int is_bluetooth = extra.getInt("is_bluetooth");
if (is_bluetooth==1){
if (is_bluetooth == 1) {
mBluetoothAdapter.disable();//设置关闭时关闭蓝牙
}
boolean qch_bt_forbid_on = Settings.System.putInt(context.getContentResolver(), "qch_bht_forbid_on", is_bluetooth);
@@ -567,7 +601,7 @@ public class MyReceiver extends BroadcastReceiver {
//静默安装应用使用okgo断网会出现问题等待修改使用aria
synchronized private void intallApk(Context context, String jsondata) {
HTTPInterface.getAllAppPackageName(context);
// HTTPInterface.getAllAppPackageName(context);
try {
JSONObject extra = new JSONObject(jsondata);
@@ -620,7 +654,7 @@ public class MyReceiver extends BroadcastReceiver {
synchronized private void unintallApk(Context context, String json) {
String sn_id = (String) SPUtils.get(context, "sn_id", "-1");
int sn_id = (int) SPUtils.get(context, "sn_id", "-1");
try {
JSONObject object = new JSONObject(json);
@@ -628,7 +662,7 @@ public class MyReceiver extends BroadcastReceiver {
ToastUtil.debugShow("收到应用卸载消息:包名" + packageName);
if (!packageName.equals("") && !packageName.equals(context.getApplicationContext().getPackageName())) {
if (!ApkUtils.isAvailable(context.getApplicationContext(), packageName)) {
HTTPInterface.setAppuninstallInfo(sn_id, packageName);
// HTTPInterface.setAppuninstallInfo(sn_id, packageName);
} else {
ApkUtils.uninstallApp(context, packageName);
}
@@ -660,18 +694,33 @@ public class MyReceiver extends BroadcastReceiver {
.setOnClickBottomListener(new CustomDialog.OnClickBottomListener() {
@Override
public void onPositiveClick() {
bind(context, id);
bind(context, id, 1);
dialog.dismiss();
}
@Override
public void onNegtiveClick() {
bind(context, id, 0);
ToastUtil.show("设备取消绑定");
dialog.dismiss();
}
});
dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
dialog.show();
new CountDownTimer(30000, 1000) {
@Override
public void onTick(long l) {
String value = String.valueOf((int) (l / 1000));
dialog.setNegtiveText("拒绝" + "(" + value + ")");
}
@Override
public void onFinish() {
bind(context, id, 0);
dialog.dismiss();
}
}.start();
// AlertDialog.Builder builder = new AlertDialog.Builder(this)
// .setTitle("设备绑定")
// .setIcon(R.mipmap.ic_launcher)
@@ -703,38 +752,72 @@ public class MyReceiver extends BroadcastReceiver {
}
synchronized private void bind(final Context context, String id) {
OkGo.<String>post(UrlPath.BIND_DEVICES)
.params("id", id)
.params("sn", Utils.getSerial())
.execute(new StringCallback() {
@Override
public void onSuccess(Response<String> response) {
String s = response.body();
try {
JSONObject jsonObject = new JSONObject(s);
int code = jsonObject.getInt("code");
String msg = jsonObject.getString("msg");
if (code == 200) {
ToastUtil.show("绑定成功");
} else {
ToastUtil.show(msg);
}
synchronized private void bind(final Context context, String id, int type) {
} catch (JSONException e) {
e.printStackTrace();
BindDevices bindDevices = NetWorkManager.getbindDevicesControl();
bindDevices.getBindDevices(Utils.getSerial(), id, type)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Observer<BaseResponse>() {
@Override
public void onSubscribe(@NonNull Disposable d) {
}
@Override
public void onNext(@NonNull BaseResponse baseResponse) {
int code = baseResponse.code;
String msg = baseResponse.msg;
// Log.e("bind", baseResponse.toString());
if (code == 200) {
ToastUtil.show("绑定成功");
} else if (code == 301) {
ToastUtil.show(msg);
}
Intent intent = new Intent(MainActivity.REFRESHACTION);
context.sendBroadcast(intent);
}
@Override
public void onError(Response<String> response) {
super.onError(response);
Log.e("bind", response.getException().getMessage());
public void onError(@NonNull Throwable e) {
Log.e("bind", e.getMessage());
}
@Override
public void onComplete() {
}
});
// OkGo.<String>get(UrlAddress.BIND_DEVICES)
// .params("id", id)
// .params("sn", Utils.getSerial())
// .params("type",type)
// .execute(new StringCallback() {
// @Override
// public void onSuccess(Response<String> response) {
// String s = response.body();
// try {
// JSONObject jsonObject = new JSONObject(s);
// int code = jsonObject.getInt("code");
// String msg = jsonObject.getString("msg");
// if (code == 200) {
// ToastUtil.show("绑定成功");
// } else if (code==301){
// ToastUtil.show(msg);
// }
//
// } catch (JSONException e) {
// e.printStackTrace();
// }
// Intent intent = new Intent(MainActivity.REFRESHACTION);
// context.sendBroadcast(intent);
// }
//
// @Override
// public void onError(Response<String> response) {
// super.onError(response);
// Log.e("bind", response.getException().getMessage());
// }
//
// });
}

View File

@@ -0,0 +1,922 @@
package com.info.sn.network;
import android.content.Context;
import android.content.Intent;
import android.icu.text.SimpleDateFormat;
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.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.Label;
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.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 {
public static void SendAppInstall(String packageName, int versionCode, int installOrRemove) {
AddAppInstall addAppInstall = NetWorkManager.getAddAppInstallControl();
addAppInstall.installorRemove(
Utils.getSerial(),
packageName,
versionCode,
installOrRemove
).subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Observer<BaseResponse>() {
@Override
public void onSubscribe(@NonNull Disposable d) {
}
@Override
public void onNext(@NonNull BaseResponse baseResponse) {
int code = baseResponse.code;
String msg = baseResponse.msg;
Log.e("SendAppInstall", "onNext: " + "code" + code + ",msg:" + msg);
}
@Override
public void onError(@NonNull Throwable e) {
Log.e("SendAppInstall", "onError: " + e.getMessage());
}
@Override
public void onComplete() {
}
});
}
public static void setBrowser(final Context context) {
Browser browser = NetWorkManager.getBrowserControl();
browser.getBrowser(Utils.getSerial())
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Observer<BaseResponse>() {
@Override
public void onSubscribe(@NonNull Disposable d) {
}
@Override
public void onNext(@NonNull BaseResponse baseResponse) {
int code = baseResponse.code;
if (code == 200) {
JSONObject jsonObject = (JSONObject) JSON.toJSON(baseResponse.data);
List<BrowserBean> white = JSON.parseArray(jsonObject.getString("browser"), BrowserBean.class);
if (null != white && white.size() != 0) {
String s = "";
for (BrowserBean bean : white) {
s += bean.getAddress() + ",";
}
boolean whiteList = Settings.System.putString(context.getContentResolver(), "DeselectBrowserArray", s);
Log.e("setBrowser", "setBrowserList_white:" + whiteList + ":" + white);
} else {
Settings.System.putString(context.getContentResolver(), "DeselectBrowserArray", " ");
}
List<BrowserBean> black = JSON.parseArray(jsonObject.getString("browser_black"), BrowserBean.class);
if (null != black && black.size() != 0) {
String s = "";
for (BrowserBean bean : black) {
s += bean.getAddress() + ",";
}
boolean blackList = Settings.System.putString(context.getContentResolver(), "qch_webblack_url", s);
Log.e("setBrowser", "setBrowserList_black:" + blackList + ":" + black);
} else {
Settings.System.putString(context.getContentResolver(), "qch_webblack_url", " ");
}
}
}
@Override
public void onError(@NonNull Throwable e) {
Log.e("setBrowser", "onError: " + e.getMessage());
}
@Override
public void onComplete() {
}
});
}
public static void getBrowserLabel(final Context context) {
Label label = NetWorkManager.getLabelControl();
label.getLabel(Utils.getSerial())
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Observer<BaseResponse>() {
@Override
public void onSubscribe(@NonNull Disposable d) {
}
@Override
public void onNext(@NonNull BaseResponse listBaseResponse) {
int code = listBaseResponse.code;
if (code == 200) {
Gson gson = new Gson();
String data = gson.toJson(listBaseResponse.data);
JsonObject jsonObject = gson.fromJson(data, JsonObject.class);
if (jsonObject.getAsJsonArray("label").size() == 0) {
return;
}
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);
//主页
Intent homepag = new Intent("qch_app_brower_homepage");
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
homepag.setPackage("com.android.settings")
.setPackage("com.android.browser");
}
if (home_page != null && !home_page.equals("")) {
homepag.putExtra("homepage", home_page);
} else {
homepag.putExtra("homepage", "Invalid");
}
context.sendBroadcast(homepag);
//书签
Intent websiteBookMark = new Intent("qch_app_brower_website");
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
websiteBookMark.setPackage("com.android.settings")
.setPackage("com.android.browser");
}
if (label_page != null && !label_page.equals("")) {
websiteBookMark.putExtra("websiteBookMark", label_page);
} else {
websiteBookMark.putExtra("websiteBookMark", "Invalid");
}
context.sendBroadcast(websiteBookMark);
} else {
Intent intent1 = new Intent("qch_app_brower_homepage");
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
intent1.setPackage("com.android.settings")
.setPackage("com.android.browser");
}
intent1.putExtra("homepage", "Invalid");
context.sendBroadcast(intent1);
Intent intent2 = new Intent("qch_app_brower_website");
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
intent2.setPackage("com.android.settings")
.setPackage("com.android.browser");
}
intent2.putExtra("websiteBookMark", "Invalid");
context.sendBroadcast(intent2);
}
}
@Override
public void onError(@NonNull Throwable e) {
Log.e("getBrowserLabel", "onError: " + e.getMessage());
}
@Override
public void onComplete() {
}
});
}
public static void getAppStart(final Context context) {
final QuerySnAppStart appStart = NetWorkManager.getAppStartControl();
appStart.getAppStatu(Utils.getSerial())
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Observer<BaseResponse<List<AppStart>>>() {
@Override
public void onSubscribe(@NonNull Disposable d) {
}
@Override
public void onNext(@NonNull BaseResponse<List<AppStart>> listBaseResponse) {
int code = listBaseResponse.code;
if (code == 200) {
List<AppStart> list = listBaseResponse.data;
setAotuandNet(context, list);
} else {
setInvalid(context);
}
}
@Override
public void onError(@NonNull Throwable e) {
Log.e("getAppStart", "onError: " + e.getMessage());
}
@Override
public void onComplete() {
}
});
}
private static void setAotuandNet(Context context, List<AppStart> list) {
String auto_allow = "";
String auto_not = "";
String network_allow = "";
String network_not = "";
String upgrade_allow = "";
String upgrade_not = "";
String slide_allow = "";
String slide_not = "";
if (null != list && list.size() != 0) {
for (AppStart app : list) {
int is_auto = app.getIs_auto();
int is_network = app.getIs_network();
int is_upgrade = app.getIs_upgrade();
int is_slide = app.getIs_slide();
String app_package = app.getApp_package();
if (is_auto == 1) {
auto_allow += app_package + ",";
} else {
auto_not += app_package + ",";
}
if (is_network == 1) {
network_allow += app_package + ",";
} else {
network_not += app_package + ",";
}
if (is_upgrade == 1) {
upgrade_allow += app.getApp_package() + ",";
} else {
upgrade_not += app.getApp_package() + ",";
}
if (is_slide == 1) {
slide_allow += app.getApp_package() + ",";
} else {
slide_not += app.getApp_package() + ",";
}
}
if (!TextUtils.isEmpty(auto_allow) && auto_allow.endsWith(",")) {
auto_allow = auto_allow.substring(0, auto_allow.length() - 1);
boolean qch_app_power_on = Settings.System.putString(context.getContentResolver(), "qch_app_power_on", auto_allow);
}
if (!TextUtils.isEmpty(auto_not) && auto_not.endsWith(",")) {
auto_not = auto_not.substring(0, auto_not.length() - 1);
}
if (!TextUtils.isEmpty(network_allow) && network_allow.endsWith(",")) {
network_allow = network_allow.substring(0, network_allow.length() - 1);
Settings.System.putString(context.getContentResolver(), "qch_jgy_network_allow", network_allow);
Log.e("fht", "not::" + network_allow);
}
if (!TextUtils.isEmpty(network_not) && network_not.endsWith(",")) {
network_not = network_not.substring(0, network_not.length() - 1);
Settings.System.putString(context.getContentResolver(), "qch_jgy_network_disallow", network_not);
Log.e("fht", "ban::" + network_not);
}
if (!TextUtils.isEmpty(upgrade_allow) && upgrade_allow.endsWith(",")) {
upgrade_allow = upgrade_allow.substring(0, upgrade_allow.length() - 1);
}
if (!TextUtils.isEmpty(upgrade_not) && upgrade_not.endsWith(",")) {
upgrade_not = upgrade_not.substring(0, upgrade_not.length() - 1);
}
Utils.writeDisableUpdateList(context, upgrade_not.split(","), upgrade_allow.split(","));
if (!TextUtils.isEmpty(slide_allow) && slide_allow.endsWith(",")) {
slide_allow = slide_allow.substring(0, slide_allow.length() - 1);
}
if (!TextUtils.isEmpty(slide_not) && slide_not.endsWith(",")) {
slide_not = slide_not.substring(0, slide_not.length() - 1);
boolean writeSucceed = Settings.System.putString(context.getContentResolver(), "qch_disable_slide", slide_not);
Log.e("fht", "qch_disable_slide=" + writeSucceed + ":" + slide_not);
} else {
boolean writeSucceed = Settings.System.putString(context.getContentResolver(), "qch_disable_slide", "Invalid");
Log.e("fht", "qch_disable_slide ok=" + writeSucceed + ":" + slide_allow);
}
} else {
setInvalid(context);
}
}
private static void setInvalid(Context context) {
boolean qch_app_power_on = Settings.System.putString(context.getContentResolver(), "qch_app_power_on", "Invalid");
boolean qch_jgy_network_allow = Settings.System.putString(context.getContentResolver(), "qch_jgy_network_allow", "Invalid");
boolean qch_jgy_network_disallow = Settings.System.putString(context.getContentResolver(), "qch_jgy_network_disallow", "Invalid");
boolean writeSucceed = Settings.System.putString(context.getContentResolver(), "qch_disable_slide", "Invalid");
}
public static void getAppJump(final Context context) {
APPJump appJump = NetWorkManager.getAppJumpControl();
appJump.getSNJump(Utils.getSerial())
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Observer<BaseResponse<List<AppJump>>>() {
@Override
public void onSubscribe(@NonNull Disposable d) {
}
@Override
public void onNext(@NonNull BaseResponse<List<AppJump>> listBaseResponse) {
int code = listBaseResponse.code;
if (code == 200) {
List<AppJump> list = listBaseResponse.data;
setAPPinsideBrowser(context, list);
} else {
sendAllweb(context);
sendwebUrl(context);
}
}
@Override
public void onError(@NonNull Throwable e) {
Log.e("getAppJump", "onError: " + e.getMessage());
}
@Override
public void onComplete() {
}
});
}
public static void setAPPinsideBrowser(Context context, List<AppJump> list) {
String packageList = "";
String urlList = "";
for (AppJump appJump : list) {
if (TextUtils.isEmpty(appJump.getAddress())) {
packageList += appJump.getApp_package() + ",";
} else {
urlList += appJump.toString() + ";";
}
}
if (!TextUtils.isEmpty(packageList)) {
//app内所有的网页禁止
packageList = packageList.substring(0, packageList.length() - 1);
//去掉多余的,
Log.e("setAppinsideWeb ", "packageList:" + packageList);
Intent qch_app_website = new Intent("qch_app_website")
.setPackage("com.android.settings");
qch_app_website.putExtra("package_name", packageList);
context.sendBroadcast(qch_app_website);
} else {
sendAllweb(context);
}
if (!TextUtils.isEmpty(urlList)) {
//app内单个网页地址禁止打开
urlList = urlList.substring(0, urlList.length() - 1);
//去掉多余的;
Log.e("setAppinsideWeb ", "strings:" + urlList);
Intent intent = new Intent("qch_app_inside_website")
.setPackage("com.android.settings");
intent.putExtra("websitelist", urlList);
context.sendBroadcast(intent);
} else {
sendwebUrl(context);
}
}
private static void sendAllweb(Context context) {
Intent intent = new Intent("qch_app_website")
.setPackage("com.android.settings");
intent.putExtra("package_name", "Invalid");
context.sendBroadcast(intent);
}
private static void sendwebUrl(Context context) {
Intent intent = new Intent("qch_app_inside_website")
.setPackage("com.android.settings");
intent.putExtra("websitelist", "Invalid");
context.sendBroadcast(intent);
}
public static void updateAdminInfo(Context context) {
String address = String.valueOf(SPUtils.get(context, "AmapAddress", "-"));
String longitude = String.valueOf(SPUtils.get(context, "longitude", "0"));
String latitude = String.valueOf(SPUtils.get(context, "latitude", "0"));
JSONObject jsonObject = new JSONObject();
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);
UpdateAdminSn updateAdminSn = NetWorkManager.getUpdateAdminSnControl();
updateAdminSn.sendAdminSn(Utils.getSerial(),
jsonObject.toJSONString(),
Utils.getMachine(context),
Utils.getHardware(context)
).subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Observer<BaseResponse>() {
@Override
public void onSubscribe(@NonNull Disposable d) {
}
@Override
public void onNext(@NonNull BaseResponse baseResponse) {
// Log.e("updateAdminInfo", "onNext: " + baseResponse.toString());
}
@Override
public void onError(@NonNull Throwable e) {
Log.e("updateAdminInfo", "onError: " + e.getMessage());
}
@Override
public void onComplete() {
}
});
}
//获取设备信息接口
// public static synchronized void checkDevicesInfo(final Handler handler) {
// OkGo.<String>get(UrlAddress.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);
// Message message = new Message();
// message.obj = userInfo;
// if (code == 200) {
// message.what = 1;
// handler.sendMessage(message);
// } else if (code == -200) {
// message.what = 0;
// handler.sendMessage(message);
// } else if (code == -250) {
// ToastUtil.show(msg);
// handler.sendEmptyMessage(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());
//
// }
// });
// }
//
// public static synchronized void checkDevicesInfo(final Context context) {
// OkGo.<String>get(UrlAddress.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) {
// SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
// Date date = new Date(System.currentTimeMillis());
// String times = simpleDateFormat.format(date);
// OkGo.<String>post(UrlAddress.APPLOG)
// .params("sn", Utils.getSerial())
// .params("app_name", appname)
// .params("use_time", time)
// .params("status", status)
// .params("createtime", times)
// .execute(new StringCallback() {
// @Override
// public void onSuccess(Response<String> response) {
// Log.e("onSuccess", "sendTimeLog");
// try {
// JSONObject bodyObject = JSON.parseObject(response.body());
// Log.e("onSuccess", bodyObject.toString());
//
// Integer code = (bodyObject.getInteger("code"));
// String msg = bodyObject.getString("msg");
// String data = bodyObject.getString("data");
// UserInfo userInfo = JSON.parseObject(data, UserInfo.class);
// Message message = new Message();
// message.obj = userInfo;
// if (code == 200) {
//
// } else if (code == -200) {
//
// } else if (code == -250) {
//
// }
// } catch (Exception ex) {
// Log.e("checkDevicesInfo", ex.getMessage());
// }
// }
//
// @Override
// public void onError(Response<String> response) {
// super.onError(response);
// Log.e("onError", response.getException().toString());
//
// }
// });
// }
//
// synchronized public static void checkUpdateByPackage(final Handler handler, String packageName, String versionCode) {
// OkGo.<String>post(UrlAddress.GET_APP_UPDATE)
// .params("code", versionCode)
// .params("package", packageName)
// .execute(new StringCallback() {
// @Override
// public void onSuccess(Response<String> response) {
// try {
// JSONObject body = JSON.parseObject(response.body());
// int code = body.getInteger("code");
// String msg = body.getString("msg");
// if (code == 200) {
// Message message = new Message();
// JSONObject data = JSON.parseObject(body.getString("data"));
// if (data != null) {
// String url = data.getString("downloadurl");
// String newversion = data.getString("newversion");
// String content = data.getString("content");
//
// message.what = 200;
// Bundle bundle = new Bundle();
// bundle.putString("url", url);
// bundle.putString("versionCode", newversion);
// bundle.putString("content", content);
// message.obj = bundle;
// }
// handler.sendMessage(message);
//// Log.e("checkUpdateSN", msg);
// } else {
// handler.sendEmptyMessage(-200);
//// Log.e("checkUpdateSN", msg);
// }
// } catch (Exception e) {
//// Log.e("checkUpdateSN", e.getMessage());
// }
// }
//
// @Override
// public void onError(Response<String> response) {
// super.onError(response);
// handler.sendEmptyMessage(-300);
//// Log.e("checkUpdateSN", response.getException().toString());
// }
// });
// }
//
// synchronized public static void checkUpdateByself(final Handler handler, String packageName, String versionCode) {
// OkGo.<String>post(UrlAddress.GET_APP_UPDATE)
// .params("code", versionCode)
// .params("package", packageName)
// .execute(new StringCallback() {
// @Override
// public void onSuccess(Response<String> response) {
// try {
// JSONObject body = JSON.parseObject(response.body());
// int code = body.getInteger("code");
// String msg = body.getString("msg");
// if (code == 200) {
// Message message = new Message();
// JSONObject data = JSON.parseObject(body.getString("data"));
// if (data != null) {
// String url = data.getString("downloadurl");
// String newversion = data.getString("newversion");
// String content = data.getString("content");
// message.what = 300;
// Bundle bundle = new Bundle();
// bundle.putString("url", url);
// bundle.putString("versionCode", newversion);
// bundle.putString("content", content);
// message.obj = bundle;
// }
// handler.sendMessage(message);
//// Log.e("checkUpdateSN", msg);
// } else {
// handler.sendEmptyMessage(-200);
//// Log.e("checkUpdateSN", msg);
// }
// } catch (Exception e) {
//// Log.e("checkUpdateSN", e.getMessage());
// }
// }
//
// @Override
// public void onError(Response<String> response) {
// super.onError(response);
// handler.sendEmptyMessage(-300);
//// Log.e("checkUpdateSN", response.getException().toString());
// }
// });
// }
//
// synchronized public static void setAppuninstallInfo(String sn_id, String packageName) {
// OkGo.<String>post(UrlAddress.SET_APP_UNINSTALL_INFO)
// .params("sn_id", sn_id)
// .params("package", packageName)
// .execute(new StringCallback() {
// @Override
// public void onSuccess(Response<String> response) {
// JSONObject object = JSON.parseObject(response.body());
// int code = object.getInteger("code");
// String msg = object.getString("msg");
// LogUtils.e("setAppinstallInfo", msg);
// if (code == 200) {
//
// } else {
//
// }
// }
//
// @Override
// public void onError(Response<String> response) {
// super.onError(response);
// LogUtils.e("setAppinstallInfo", "onError:" + response.getException());
//
// }
// });
//
// }
//
// synchronized public static void sendStartTime(Context context, long startTime, String packageName, int battery, String random) {
// String sn_id = (String) SPUtils.get(context, "sn_id", "-1");
// String member_id = (String) SPUtils.get(context, "member_id", "-1");
// OkGo.<String>post(UrlAddress.SEND_RUNINGAPPINFO)
// .params("start_time", startTime)
// .params("package", packageName)
// .params("battery", battery)
// .params("member_id", member_id)
// .params("sn_id", sn_id)
// .params("random", random)
// .execute(new StringCallback() {
// @Override
// public void onSuccess(Response<String> response) {
// String body = response.body();
// LogUtils.e("sendStartTime", body);
// }
//
// @Override
// public void onError(Response<String> response) {
// super.onError(response);
// LogUtils.e("sendStartTime", response.getException().toString());
//
// }
// });
// }
//
// synchronized public static void getDriveState(int member_id, int sn_id) {
//
// OkGo.<String>post(UrlAddress.SEND_DRIVE_STATE)
// .params("member_id", member_id)
// .params("sn_id", sn_id)
// .params("status", 1)
// .execute(new StringCallback() {
// @Override
// public void onSuccess(Response<String> response) {
//
// }
//
// @Override
// public void onError(Response<String> response) {
// super.onError(response);
//
// }
// });
// }
//
// synchronized public static void getAllAppPackageName(final Handler handler) {
// OkGo.<String>post(UrlAddress.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) {
//
// }
// }
//
// @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(UrlAddress.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,com.jiaoguanyi.pager2,com.android.uiuios";
// 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);
// } else {
// Settings.System.putString(context.getContentResolver(), "qch_app_forbid", "com.info.sn,com.android.uiuios,com.appstore.uiui,com.uiuios.updatetools,com.jiaoguanyi.pager2,com.android.uiuios");
//
// }
// } catch (Exception e) {
// Log.e("getAllAppPackageName", e.getMessage());
// }
// }
//
// @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(UrlAddress.SET_BROWSER_URL)
// .params("sn", Utils.getSerial())
// .execute(new StringCallback() {
// @Override
// public void onSuccess(Response<String> response) {
// try {
// JSONObject jsonObject = JSON.parseObject(response.body());
// 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 + ":" + white);
// } 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 + ":" + black);
// } else {
// Settings.System.putString(context.getContentResolver(), "qch_webblack_url", " ");
// }
// } else {
// Log.e("fht", "setBrowserList" + msg);
// }
// } catch (JSONException e) {
// Log.e("fht", "setBrowserList" + e.getMessage());
//
// }
// }
// });
// }
//
// public static void get_settings(final Context context) {
// OkGo.<String>get(UrlAddress.GET_SETTINGS)
// .params("sn", Utils.getSerial())
// .execute(new StringCallback() {
// @Override
// public void onSuccess(Response<String> response) {
// JSONObject jsonObject = JSON.parseObject(response.body());
// int code = jsonObject.getInteger("code");
// if (code == 200) {
// String data = jsonObject.getString("data");
// Utils.setSystemSetting(context, data);
// }
// }
//
// @Override
// public void onError(Response<String> response) {
// super.onError(response);
// }
// });
// }
//
//
//
// public static void get_forceinstall(Context context) {
// OkGo.<String>get(UrlAddress.GET_FORCE_INSTALL)
// .params("sn", Utils.getSerial())
// .execute(new StringCallback() {
// @Override
// public void onSuccess(Response<String> response) {
//
// }
//
// @Override
// public void onError(Response<String> response) {
// super.onError(response);
// }
// });
// }
}

View File

@@ -0,0 +1,195 @@
package com.info.sn.network;
import android.os.Environment;
import com.info.sn.network.api.APPJump;
import com.info.sn.network.api.AddAppInstall;
import com.info.sn.network.api.Applog;
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.QuerySnAppStart;
import com.info.sn.network.api.SNInfo;
import com.info.sn.network.api.Setting;
import com.info.sn.network.api.UpdateAdminSn;
import java.io.File;
import java.util.concurrent.TimeUnit;
import okhttp3.Cache;
import okhttp3.OkHttpClient;
import retrofit2.CallAdapter;
import retrofit2.Converter;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;
public class NetWorkManager {
private static final String ROOT_URL = UrlAddress.ROOT_URL;
private static final long cacheSize = 1024 * 1024 * 20;// 缓存文件最大限制大小20M
private static String cacheDirectory = Environment.getExternalStorageDirectory() + "/okttpcaches"; // 设置缓存文件路径
private static Cache cache = new Cache(new File(cacheDirectory), cacheSize); //
private static final OkHttpClient client;
static {
//如果无法生存缓存文件目录,检测权限使用已经加上,检测手机是否把文件读写权限禁止了
OkHttpClient.Builder builder = new OkHttpClient.Builder();
builder.connectTimeout(8, TimeUnit.SECONDS); // 设置连接超时时间
builder.writeTimeout(8, TimeUnit.SECONDS);// 设置写入超时时间
builder.readTimeout(8, TimeUnit.SECONDS);// 设置读取数据超时时间
builder.retryOnConnectionFailure(true);// 设置进行连接失败重试
builder.cache(cache);// 设置缓存
client = builder.build();
}
private static CallAdapter.Factory rxJavaCallAdapterFactory = RxJava2CallAdapterFactory.create();
private static Converter.Factory gsonConverterFactory = GsonConverterFactory.create();
private static SNInfo snInfoControl;
private static Applog applogControl;
private static Setting settingControl;
private static ForceInstall forceInstallControl;
private static BindDevices bindDevicesControl;
private static AddAppInstall addAppInstallControl;
private static Browser browserControl;
private static Label labelControl;
private static QuerySnAppStart appStartControl;
private static APPJump appJumpControl;
private static UpdateAdminSn updateAdminSnControl;
public static SNInfo getsnInfoControl() {
if (null == snInfoControl) {
Retrofit retrofit = new Retrofit.Builder()
.client(client)
.baseUrl(ROOT_URL)
.addConverterFactory(gsonConverterFactory)
.addCallAdapterFactory(rxJavaCallAdapterFactory)
.build();
snInfoControl = retrofit.create(SNInfo.class);
}
return snInfoControl;
}
public static Setting getsettingControl() {
if (null == settingControl) {
Retrofit retrofit = new Retrofit.Builder()
.client(client)
.baseUrl(ROOT_URL)
.addConverterFactory(gsonConverterFactory)
.addCallAdapterFactory(rxJavaCallAdapterFactory)
.build();
settingControl = retrofit.create(Setting.class);
}
return settingControl;
}
public static ForceInstall getForceInstallControl() {
if (null == forceInstallControl) {
Retrofit retrofit = new Retrofit.Builder()
.client(client)
.baseUrl(ROOT_URL)
.addConverterFactory(gsonConverterFactory)
.addCallAdapterFactory(rxJavaCallAdapterFactory)
.build();
forceInstallControl = retrofit.create(ForceInstall.class);
}
return forceInstallControl;
}
public static BindDevices getbindDevicesControl() {
if (null == bindDevicesControl) {
Retrofit retrofit = new Retrofit.Builder()
.client(client)
.baseUrl(ROOT_URL)
.addConverterFactory(gsonConverterFactory)
.addCallAdapterFactory(rxJavaCallAdapterFactory)
.build();
bindDevicesControl = retrofit.create(BindDevices.class);
}
return bindDevicesControl;
}
public static AddAppInstall getAddAppInstallControl() {
if (null == addAppInstallControl) {
Retrofit retrofit = new Retrofit.Builder()
.client(client)
.baseUrl(ROOT_URL)
.addConverterFactory(gsonConverterFactory)
.addCallAdapterFactory(rxJavaCallAdapterFactory)
.build();
addAppInstallControl = retrofit.create(AddAppInstall.class);
}
return addAppInstallControl;
}
public static Browser getBrowserControl() {
if (null == browserControl) {
Retrofit retrofit = new Retrofit.Builder()
.client(client)
.baseUrl(ROOT_URL)
.addConverterFactory(gsonConverterFactory)
.addCallAdapterFactory(rxJavaCallAdapterFactory)
.build();
browserControl = retrofit.create(Browser.class);
}
return browserControl;
}
public static Label getLabelControl() {
if (null == labelControl) {
Retrofit retrofit = new Retrofit.Builder()
.client(client)
.baseUrl(ROOT_URL)
.addConverterFactory(gsonConverterFactory)
.addCallAdapterFactory(rxJavaCallAdapterFactory)
.build();
labelControl = retrofit.create(Label.class);
}
return labelControl;
}
public static QuerySnAppStart getAppStartControl() {
if (null == appStartControl) {
Retrofit retrofit = new Retrofit.Builder()
.client(client)
.baseUrl(ROOT_URL)
.addConverterFactory(gsonConverterFactory)
.addCallAdapterFactory(rxJavaCallAdapterFactory)
.build();
appStartControl = retrofit.create(QuerySnAppStart.class);
}
return appStartControl;
}
public static APPJump getAppJumpControl() {
if (null == appJumpControl) {
Retrofit retrofit = new Retrofit.Builder()
.client(client)
.baseUrl(ROOT_URL)
.addConverterFactory(gsonConverterFactory)
.addCallAdapterFactory(rxJavaCallAdapterFactory)
.build();
appJumpControl = retrofit.create(APPJump.class);
}
return appJumpControl;
}
public static UpdateAdminSn getUpdateAdminSnControl() {
if (null == updateAdminSnControl) {
Retrofit retrofit = new Retrofit.Builder()
.client(client)
.baseUrl(ROOT_URL)
.addConverterFactory(gsonConverterFactory)
.addCallAdapterFactory(rxJavaCallAdapterFactory)
.build();
updateAdminSnControl = retrofit.create(UpdateAdminSn.class);
}
return updateAdminSnControl;
}
}

View File

@@ -0,0 +1,37 @@
package com.info.sn.network;
public class UrlAddress {
public static final String ROOT_URL = "http://homework.uiuios.com/android/";
//主页接口
public static final String SNINFO = ROOT_URL + "sn/getSnInfo";
//设备信息接口
public static final String APPLOG = ROOT_URL + "App/getApplog";
public final static String GET_APP_UPDATE = ROOT_URL + "Update/update";
//根据包名获取更新
public final static String SEND_RUNINGAPPINFO = ROOT_URL + "Monitoring/getAppNow";
//获取当前最顶层应用和电量
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 BIND_DEVICES = ROOT_URL + "sn/bindSn";
//绑定设备消息
public final static String GET_SETTINGS = ROOT_URL + "control/getSetting";
//获取系统设置
public final static String SET_BROWSER_URL = ROOT_URL + "control/getBrowser";
//浏览器网址管控
public final static String SET_BROWSER_Label = ROOT_URL + "control/getLabel";
//浏览器书签管控
public final static String GET_FORCE_INSTALL = ROOT_URL + "app/getForceDownload";
//获取强制下载
public final static String GET_APP_START = ROOT_URL + "sn/querySnAppStart";
//获取app管控
public final static String GET_APP_JUMP = ROOT_URL + "sn/querySnJump";
//发app跳转管控
public final static String SEND_INSTALLEDORREMOVED = ROOT_URL + "app/addAppInstall";
//发送卸载或者安装信息
public final static String UPDATE_SNINFO = ROOT_URL + "sn/updateAdminSn";
//发送卸载或者安装信息
}

View File

@@ -1,28 +0,0 @@
package com.info.sn.network;
public class UrlPath {
public static final String HOMEPATHRUL = "http://homework.tuiinfo.com/api/";
//主页接口
public static final String SNINFO = HOMEPATHRUL + "Member/snInfo";
//设备信息接口
public static final String APPLOG = HOMEPATHRUL + "App/getApplog";
public final static String GET_APP_UPDATE = HOMEPATHRUL + "Update/update";
//根据包名获取更新
public final static String SET_APP_INSTALL_INFO = HOMEPATHRUL + "App/appInstall";
//发送app安装信息
public final static String SET_APP_UNINSTALL_INFO = HOMEPATHRUL + "App/appUnload";
//发送app卸载信息
public final static String SEND_RUNINGAPPINFO = HOMEPATHRUL + "Monitoring/getAppNow";
//获取当前最顶层应用和电量
public final static String SEND_DRIVE_STATE = HOMEPATHRUL + "Online/online";
public final static String GET_ALL_PACKAGENAME = HOMEPATHRUL + "App/allPackageSn";
//获取所有应用包名
public final static String BIND_DEVICES = HOMEPATHRUL + "Member/binding";
//绑定设备消息
public final static String SET_BROWSER_URL = HOMEPATHRUL + "Contorl/snbrower";
//浏览器网址管控
}

View File

@@ -0,0 +1,18 @@
package com.info.sn.network.api;
import com.info.sn.bean.AppJump;
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 APPJump {
@GET(UrlAddress.GET_APP_JUMP)
Observable<BaseResponse<List<AppJump>>> getSNJump(
@Query("sn") String sn
);
}

View File

@@ -0,0 +1,21 @@
package com.info.sn.network.api;
import com.info.sn.bean.BaseResponse;
import com.info.sn.network.UrlAddress;
import io.reactivex.Observable;
import retrofit2.http.Field;
import retrofit2.http.FormUrlEncoded;
import retrofit2.http.POST;
public interface AddAppInstall {
@FormUrlEncoded
@POST(UrlAddress.SEND_INSTALLEDORREMOVED)
Observable<BaseResponse> installorRemove(
@Field("sn") String sn,
@Field("packageName") String packageName,
@Field("versionCode") int versionCode,
@Field("type") int type
);
}

View File

@@ -0,0 +1,20 @@
package com.info.sn.network.api;
import com.info.sn.bean.BaseResponse;
import com.info.sn.network.UrlAddress;
import io.reactivex.Observable;
import retrofit2.http.GET;
import retrofit2.http.Query;
public interface Applog {
@GET(UrlAddress.APPLOG)
Observable<BaseResponse> getApplog(
@Query("sn") String sn,
@Query("app_name") String app_name,
@Query("use_time") String use_time,
@Query("status") String status,
@Query("createtime") String createtime
);
}

View File

@@ -0,0 +1,17 @@
package com.info.sn.network.api;
import com.info.sn.bean.BaseResponse;
import com.info.sn.network.UrlAddress;
import io.reactivex.Observable;
import retrofit2.http.GET;
import retrofit2.http.Query;
public interface BindDevices {
@GET(UrlAddress.BIND_DEVICES)
Observable<BaseResponse> getBindDevices(
@Query("sn") String sn,
@Query("id") String id,
@Query("type") int type
);
}

View File

@@ -0,0 +1,15 @@
package com.info.sn.network.api;
import com.info.sn.bean.BaseResponse;
import com.info.sn.network.UrlAddress;
import io.reactivex.Observable;
import retrofit2.http.GET;
import retrofit2.http.Query;
public interface Browser {
@GET(UrlAddress.SET_BROWSER_URL)
Observable<BaseResponse> getBrowser(
@Query("sn") String sn
);
}

View File

@@ -0,0 +1,19 @@
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 ForceInstall {
@GET(UrlAddress.GET_FORCE_INSTALL)
Observable<BaseResponse<List<AppInfo>>> getForceInstall(
@Query("sn") String sn
);
}

View File

@@ -1,451 +0,0 @@
package com.info.sn.network.api;
import android.content.Context;
import android.icu.text.SimpleDateFormat;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.provider.Settings;
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.info.sn.MainActivity;
import com.info.sn.bean.MessageWhat;
import com.info.sn.bean.UserInfo;
import com.info.sn.jpush.TagAliasOperatorHelper;
import com.info.sn.network.UrlPath;
import com.info.sn.utils.LogUtils;
import com.info.sn.utils.SPUtils;
import com.info.sn.utils.ToastUtil;
import com.info.sn.utils.Utils;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.callback.StringCallback;
import com.lzy.okgo.model.Response;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Random;
import java.util.Set;
import okhttp3.Call;
import okhttp3.internal.Util;
public class HTTPInterface {
//获取设备信息接口
public static synchronized void checkDevicesInfo(final Handler handler) {
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);
Message message = new Message();
message.obj = userInfo;
if (code == 200) {
message.what = 1;
handler.sendMessage(message);
} else if (code == -200) {
message.what = 0;
handler.sendMessage(message);
} else if (code == -250) {
ToastUtil.show(msg);
handler.sendEmptyMessage(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());
}
});
}
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) {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date = new Date(System.currentTimeMillis());
String times = simpleDateFormat.format(date);
OkGo.<String>post(UrlPath.APPLOG)
.params("sn", Utils.getSerial())
.params("app_name", appname)
.params("use_time", time)
.params("status", status)
.params("createtime", times)
.execute(new StringCallback() {
@Override
public void onSuccess(Response<String> response) {
Log.e("onSuccess", "sendTimeLog");
try {
JSONObject bodyObject = JSON.parseObject(response.body());
Log.e("onSuccess", bodyObject.toString());
Integer code = (bodyObject.getInteger("code"));
String msg = bodyObject.getString("msg");
String data = bodyObject.getString("data");
UserInfo userInfo = JSON.parseObject(data, UserInfo.class);
Message message = new Message();
message.obj = userInfo;
if (code == 200) {
} else if (code == -200) {
} else if (code == -250) {
}
} catch (Exception ex) {
Log.e("checkDevicesInfo", ex.getMessage());
}
}
@Override
public void onError(Response<String> response) {
super.onError(response);
Log.e("onError", response.getException().toString());
}
});
}
synchronized public static void checkUpdateByPackage(final Handler handler, String packageName, String versionCode) {
OkGo.<String>post(UrlPath.GET_APP_UPDATE)
.params("code", versionCode)
.params("package", packageName)
.execute(new StringCallback() {
@Override
public void onSuccess(Response<String> response) {
try {
JSONObject body = JSON.parseObject(response.body());
int code = body.getInteger("code");
String msg = body.getString("msg");
if (code == 200) {
Message message = new Message();
JSONObject data = JSON.parseObject(body.getString("data"));
if (data != null) {
String url = data.getString("downloadurl");
String newversion = data.getString("newversion");
String content = data.getString("content");
message.what = 200;
Bundle bundle = new Bundle();
bundle.putString("url", url);
bundle.putString("versionCode", newversion);
bundle.putString("content", content);
message.obj = bundle;
}
handler.sendMessage(message);
// Log.e("checkUpdateSN", msg);
} else {
handler.sendEmptyMessage(-200);
// Log.e("checkUpdateSN", msg);
}
} catch (Exception e) {
// Log.e("checkUpdateSN", e.getMessage());
}
}
@Override
public void onError(Response<String> response) {
super.onError(response);
handler.sendEmptyMessage(-300);
// Log.e("checkUpdateSN", response.getException().toString());
}
});
}
synchronized public static void checkUpdateByself(final Handler handler, String packageName, String versionCode) {
OkGo.<String>post(UrlPath.GET_APP_UPDATE)
.params("code", versionCode)
.params("package", packageName)
.execute(new StringCallback() {
@Override
public void onSuccess(Response<String> response) {
try {
JSONObject body = JSON.parseObject(response.body());
int code = body.getInteger("code");
String msg = body.getString("msg");
if (code == 200) {
Message message = new Message();
JSONObject data = JSON.parseObject(body.getString("data"));
if (data != null) {
String url = data.getString("downloadurl");
String newversion = data.getString("newversion");
String content = data.getString("content");
message.what = 300;
Bundle bundle = new Bundle();
bundle.putString("url", url);
bundle.putString("versionCode", newversion);
bundle.putString("content", content);
message.obj = bundle;
}
handler.sendMessage(message);
// Log.e("checkUpdateSN", msg);
} else {
handler.sendEmptyMessage(-200);
// Log.e("checkUpdateSN", msg);
}
} catch (Exception e) {
// Log.e("checkUpdateSN", e.getMessage());
}
}
@Override
public void onError(Response<String> response) {
super.onError(response);
handler.sendEmptyMessage(-300);
// Log.e("checkUpdateSN", response.getException().toString());
}
});
}
synchronized public static void setAppuninstallInfo(String sn_id, String packageName) {
OkGo.<String>post(UrlPath.SET_APP_UNINSTALL_INFO)
.params("sn_id", sn_id)
.params("package", packageName)
.execute(new StringCallback() {
@Override
public void onSuccess(Response<String> response) {
JSONObject object = JSON.parseObject(response.body());
int code = object.getInteger("code");
String msg = object.getString("msg");
LogUtils.e("setAppinstallInfo", msg);
if (code == MessageWhat.CODE_SUCCESSFUL) {
} else {
}
}
@Override
public void onError(Response<String> response) {
super.onError(response);
LogUtils.e("setAppinstallInfo", "onError:" + response.getException());
}
});
}
synchronized public static void sendStartTime(Context context, long startTime, String packageName, int battery, String random) {
String sn_id = (String) SPUtils.get(context, "sn_id", "-1");
String member_id = (String) SPUtils.get(context, "member_id", "-1");
OkGo.<String>post(UrlPath.SEND_RUNINGAPPINFO)
.params("start_time", startTime)
.params("package", packageName)
.params("battery", battery)
.params("member_id", member_id)
.params("sn_id", sn_id)
.params("random", random)
.execute(new StringCallback() {
@Override
public void onSuccess(Response<String> response) {
String body = response.body();
LogUtils.e("sendStartTime", body);
}
@Override
public void onError(Response<String> response) {
super.onError(response);
LogUtils.e("sendStartTime", response.getException().toString());
}
});
}
synchronized public static void getDriveState(String member_id, String sn_id) {
OkGo.<String>post(UrlPath.SEND_DRIVE_STATE)
.params("member_id", member_id)
.params("sn_id", sn_id)
.params("status", 1)
.execute(new StringCallback() {
@Override
public void onSuccess(Response<String> response) {
}
@Override
public void onError(Response<String> response) {
super.onError(response);
}
});
}
synchronized public static void getAllAppPackageName(final Handler handler) {
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) {
}
}
@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,com.jiaoguanyi.pager2,com.android.uiuios";
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);
}else {
Settings.System.putString(context.getContentResolver(), "qch_app_forbid", "com.info.sn,com.android.uiuios,com.appstore.uiui,com.uiuios.updatetools,com.jiaoguanyi.pager2,com.android.uiuios");
}
} catch (Exception e) {
Log.e("getAllAppPackageName", e.getMessage());
}
}
@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() {
@Override
public void onSuccess(Response<String> response) {
try {
JSONObject jsonObject = JSON.parseObject(response.body());
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 + ":" + white);
} 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 + ":" + black);
} else {
Settings.System.putString(context.getContentResolver(), "qch_webblack_url", " ");
}
} else {
Log.e("fht", "setBrowserList" + msg);
}
} catch (JSONException e) {
Log.e("fht", "setBrowserList" + e.getMessage());
}
}
});
}
}

View File

@@ -0,0 +1,19 @@
package com.info.sn.network.api;
import com.info.sn.bean.BaseResponse;
import com.info.sn.bean.BrowserLabel;
import com.info.sn.network.UrlAddress;
import java.util.List;
import io.reactivex.Observable;
import retrofit2.http.GET;
import retrofit2.http.Query;
public interface Label {
@GET(UrlAddress.SET_BROWSER_Label)
Observable<BaseResponse> getLabel(
@Query("sn") String sn
);
}

View File

@@ -0,0 +1,18 @@
package com.info.sn.network.api;
import com.info.sn.bean.AppStart;
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 QuerySnAppStart {
@GET(UrlAddress.GET_APP_START)
Observable<BaseResponse<List<AppStart>>> getAppStatu(
@Query("sn") String sn
);
}

View File

@@ -0,0 +1,16 @@
package com.info.sn.network.api;
import com.info.sn.bean.BaseResponse;
import com.info.sn.bean.UserInfo;
import com.info.sn.network.UrlAddress;
import io.reactivex.Observable;
import retrofit2.http.GET;
import retrofit2.http.Query;
public interface SNInfo {
@GET(UrlAddress.SNINFO)
Observable<BaseResponse<UserInfo>> getsninfo(
@Query("sn") String sn
);
}

View File

@@ -0,0 +1,16 @@
package com.info.sn.network.api;
import com.info.sn.bean.BaseResponse;
import com.info.sn.bean.SystemSettings;
import com.info.sn.network.UrlAddress;
import io.reactivex.Observable;
import retrofit2.http.GET;
import retrofit2.http.Query;
public interface Setting {
@GET(UrlAddress.GET_SETTINGS)
Observable<BaseResponse<SystemSettings>> getSetting(
@Query("sn") String sn
);
}

View File

@@ -0,0 +1,21 @@
package com.info.sn.network.api;
import com.info.sn.bean.BaseResponse;
import com.info.sn.network.UrlAddress;
import io.reactivex.Observable;
import retrofit2.http.Field;
import retrofit2.http.FormUrlEncoded;
import retrofit2.http.POST;
public interface UpdateAdminSn {
@FormUrlEncoded
@POST(UrlAddress.UPDATE_SNINFO)
Observable<BaseResponse> sendAdminSn(
@Field("sn")String sn,
@Field("address")String address,
@Field("machine")String machine,
@Field("hardware")String hardware
);
}

View File

@@ -4,16 +4,23 @@ import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import com.info.sn.network.HTTPInterface;
import com.info.sn.utils.ApkUtils;
public class APKinstallReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
// TODO: This method is called when the BroadcastReceiver is receiving
// an Intent broadcast.
if (intent.getAction().equals(Intent.ACTION_PACKAGE_ADDED) || intent.getAction().equals(Intent.ACTION_PACKAGE_REPLACED)) {
String action = intent.getAction();
if (action.equals(Intent.ACTION_PACKAGE_ADDED) || action.equals(Intent.ACTION_PACKAGE_REPLACED)) {
String packageName = intent.getDataString().replace("package:", "");
int code = ApkUtils.getAppVersionCode(context,packageName);
HTTPInterface.SendAppInstall(packageName,code ,1);
} else if (action.equals(Intent.ACTION_PACKAGE_REMOVED)) {
String packageName = intent.getDataString().replace("package:", "");
HTTPInterface.SendAppInstall(packageName,0 ,2);
}
}
}

View File

@@ -6,6 +6,7 @@ import android.content.Intent;
import android.util.Log;
import com.info.sn.service.GuardService;
import com.info.sn.service.InitJpushServer;
import com.info.sn.service.MyDownloadService;
import com.info.sn.service.StepService;
@@ -30,8 +31,9 @@ public class BootReceiver extends BroadcastReceiver {
|| intent.getAction().equals("android.intent.action.ACTION_SCREEN_OFF")) {
// Intent i = new Intent(context, InitJpushServer.class);
// context.startService(i);
context.startService(new Intent(context, StepService.class));
context.startService(new Intent(context, GuardService.class));
context.startService(new Intent(context, StepService.class));
context.startService(new Intent(context, InitJpushServer.class));
context.startService(new Intent(context, MyDownloadService.class));
}

View File

@@ -2,11 +2,9 @@ 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;
import com.info.sn.KeepAliveConnection;
public class InitJpushServer extends Service {
public InitJpushServer() {
@@ -17,7 +15,8 @@ public class InitJpushServer extends Service {
public IBinder onBind(Intent intent) {
// TODO: Return the communication channel to the service.
// throw new UnsupportedOperationException("Not yet implemented");
return null;
return new KeepAliveConnection.Stub() {
};
}
@@ -28,16 +27,7 @@ public class InitJpushServer extends Service {
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
HTTPInterface.checkDevicesInfo(InitJpushServer.this);
// HTTPInterface.checkDevicesInfo(InitJpushServer.this);
return START_STICKY;
}
private Handler mHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
}
};
}

View File

@@ -21,27 +21,18 @@ import androidx.annotation.Nullable;
import com.arialyy.annotations.Download;
import com.arialyy.aria.core.Aria;
import com.arialyy.aria.core.task.DownloadTask;
import com.blankj.utilcode.util.NetworkUtils;
import com.blankj.utilcode.util.ToastUtils;
import com.info.sn.BuildConfig;
import com.info.sn.KeepAliveConnection;
import com.info.sn.R;
import com.info.sn.network.api.HTTPInterface;
import com.info.sn.utils.ApkUtils;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.callback.FileCallback;
import com.lzy.okgo.model.Progress;
import com.lzy.okgo.model.Response;
import java.io.File;
import java.lang.ref.WeakReference;
// 下载管理服务
public class MyDownloadService extends Service implements NetworkUtils.OnNetworkStatusChangedListener {
public class MyDownloadService extends Service {
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
flags = START_STICKY;
startService(new Intent(this, StepService.class));
startService(new Intent(this, GuardService.class));
CheckUpdate();
@@ -53,7 +44,6 @@ public class MyDownloadService extends Service implements NetworkUtils.OnNetwork
//静默升级更新工具
// HTTPInterface.getAllAppPackageName(handler);
Aria.download(this).register();
Aria.download(this).resumeAllTask();
//恢复所有未完成的下载任务
return START_STICKY;
@@ -63,27 +53,10 @@ public class MyDownloadService extends Service implements NetworkUtils.OnNetwork
@Override
public void onCreate() {
super.onCreate();
// new Thread(new Runnable() {
// @Override
// public void run() {
// while (true) {
// LogUtils.e("packagename", MyApplication.getTaskPackname());
// LogUtils.e("packagename", String.valueOf(MyApplication.getSystemBattery()));
//// MyApplication.sendStartTime();
// try {
// Thread.sleep(5000);
// } catch (InterruptedException e) {
// e.printStackTrace();
// }
// }
// }
// }).start();
}
synchronized private void CheckUpdate() {
HTTPInterface.checkUpdateByself(handler, this.getPackageName(), String.valueOf(BuildConfig.VERSION_CODE));
// HTTPInterface.checkUpdateByself(handler, this.getPackageName(), String.valueOf(BuildConfig.VERSION_CODE));
}
synchronized private void CheckUpdateByPackageName(String packageName, Handler handlers) {
@@ -95,9 +68,9 @@ public class MyDownloadService extends Service implements NetworkUtils.OnNetwork
e.printStackTrace();
}
if (null != packageInfo) {
HTTPInterface.checkUpdateByPackage(handlers, packageName, String.valueOf(packageInfo.versionCode));
// HTTPInterface.checkUpdateByPackage(handlers, packageName, String.valueOf(packageInfo.versionCode));
} else {
HTTPInterface.checkUpdateByPackage(handlers, packageName, "0");
// HTTPInterface.checkUpdateByPackage(handlers, packageName, "0");
}
}
@@ -109,7 +82,8 @@ public class MyDownloadService extends Service implements NetworkUtils.OnNetwork
@Nullable
@Override
public IBinder onBind(Intent intent) {
return null;
return new KeepAliveConnection.Stub() {
};
}
private Handler handler = new Handler() {
@@ -128,7 +102,7 @@ public class MyDownloadService extends Service implements NetworkUtils.OnNetwork
String apppackage = (String) msg.obj;
Log.e("handler", Settings.System.getString(getContentResolver(), "qch_app_forbid") + "?");
try {
Settings.System.putString(getContentResolver(), "qch_app_forbid", apppackage+ "com.info.sn,com.android.uiuios,com.appstore.uiui,com.uiuios.updatetools");
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());
}
@@ -168,43 +142,7 @@ public class MyDownloadService extends Service implements NetworkUtils.OnNetwork
// ad.setCanceledOnTouchOutside(false); //点击外面区域不会让dialog消失
// ad.show();
} else {
OkGo.<File>get(url)
.execute(new FileCallback("Sninfo/" + url.substring(url.lastIndexOf("/") + 1)) {
@Override
public void onSuccess(final Response<File> response) {
// Settings.System.putString(getApplicationContext().getContentResolver(), "qch_app_forbid", "com.baidu.video");
// ApkUtils.installApkInSilence(response.body().getAbsolutePath(), Launcher.this.getPackageName());
// AlertDialog.Builder builder = new AlertDialog.Builder(MyDownFile download FailureloadService.this)
// .setTitle("软件更新")
// .setIcon(R.mipmap.ic_launcher)
// .setCancelable(false)
// .setMessage("发现新版本,点击确定更新\n" + "更新内容:" + bundle.getString("content"))
// .setPositiveButton("确定", new DialogInterface.OnClickListener() {
// @Override
// public void onClick(DialogInterface dialogInterface, int i) {
ApkUtils.installApp(MyDownloadService.this, response.body().getAbsolutePath());
// dialogInterface.dismiss();
// }
// });
// AlertDialog ad = builder.create();
// ad.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
// ad.setCanceledOnTouchOutside(false); //点击外面区域不会让dialog消失
// ad.show();
Log.e("getFile", "download file successful,now installing");
}
@Override
public void onError(Response<File> response) {
super.onError(response);
Log.e("getFile", "File download Failure" + response.getException());
}
@Override
public void downloadProgress(Progress progress) {
super.downloadProgress(progress);
Log.e("getFile", "已下载:" + progress.currentSize + ",总大小:" + progress.totalSize + ",进度:" + progress.fraction + ",当前网速:" + progress.speed);
}
});
}
}
@@ -233,61 +171,14 @@ public class MyDownloadService extends Service implements NetworkUtils.OnNetwork
ad.setCanceledOnTouchOutside(false); //点击外面区域不会让dialog消失
ad.show();
} else {
OkGo.<File>get(url)
.execute(new FileCallback("Sninfo/" + url.substring(url.lastIndexOf("/") + 1)) {
@Override
public void onSuccess(final Response<File> response) {
// Settings.System.putString(getApplicationContext().getContentResolver(), "qch_app_forbid", "com.baidu.video");
// ApkUtils.installApkInSilence(response.body().getAbsolutePath(), Launcher.this.getPackageName());
AlertDialog.Builder builder = new AlertDialog.Builder(MyDownloadService.this)
.setTitle("软件更新")
.setIcon(R.mipmap.ic_launcher)
.setCancelable(false)
.setMessage("发现新版本,点击确定更新\n" + "更新内容:" + bundle.getString("content"))
.setPositiveButton("确定", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
ApkUtils.installApk(MyDownloadService.this, response.body());
dialogInterface.dismiss();
}
});
AlertDialog ad = builder.create();
ad.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
ad.setCanceledOnTouchOutside(false); //点击外面区域不会让dialog消失
ad.show();
Log.e("getFile", "download file successful,now installing");
}
@Override
public void onError(Response<File> response) {
super.onError(response);
Log.e("getFile", "File download Failure" + response.getException());
}
@Override
public void downloadProgress(Progress progress) {
super.downloadProgress(progress);
Log.e("getFile", "已下载:" + progress.currentSize + ",总大小:" + progress.totalSize + ",进度:" + progress.fraction + ",当前网速:" + progress.speed);
}
});
}
}
@Override
public void onDisconnected() {
}
@Override
public void onConnected(NetworkUtils.NetworkType networkType) {
Aria.download(this).resumeAllTask();
}
//在这里处理任务执行中的状态,如进度进度条的刷新
@Download.onTaskRunning
protected void running(DownloadTask task) {
ToastUtils.showShort("正在下载:" + task.getExtendField() + "-" + task.getPercent() + "%");
Log.e("aria running", "正在下载:" + task.getState() + "--" + task.getPercent() + "--" + task.getExtendField());
}

View File

@@ -20,7 +20,7 @@ import android.util.Log;
import androidx.annotation.Nullable;
import com.info.sn.KeepAliveConnection;
import com.info.sn.network.JWebSocketClient;
import com.info.sn.websocket.JWebSocketClient;
import com.info.sn.utils.LogUtils;
import com.info.sn.utils.ServiceAliveUtils;
import com.info.sn.utils.Utils;
@@ -197,4 +197,10 @@ public class StepService extends Service {
}
}.start();
}
@Override
public void onDestroy() {
super.onDestroy();
closeConnect();
}
}

View File

@@ -38,11 +38,6 @@ import java.util.List;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import rx.Observable;
import rx.Observer;
import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;
public class ApkUtils {
@@ -215,94 +210,94 @@ public class ApkUtils {
}
public static void installRx(final Context context, final String packageName, final String filePath) {
Observable.create(new Observable.OnSubscribe<Integer>() {
@Override
public void call(Subscriber<? super Integer> subscriber) {
File file = new File(filePath);
if (filePath == null || filePath.length() == 0 || file == null) {
Log.e("fanhuitong", "errormesg=========" + " 空啊 ");
subscriber.onNext(0);
return;
}
// String[] args = { "pm", "install", "-r", filePath };
String[] args = {"pm", "install", "-i", "com.colorflykids", "--user", "0", filePath};
// String argss = "pm install -i " + "com.colorflykids" + " --user 0 " + filePath;
Log.e("fanhuitong", "argss====" + args);
ProcessBuilder processBuilder = new ProcessBuilder(args);
Process process = null;
BufferedReader successResult = null;
BufferedReader errorResult = null;
StringBuilder successMsg = new StringBuilder();
StringBuilder errorMsg = new StringBuilder();
try {
process = processBuilder.start();
successResult = new BufferedReader(new InputStreamReader(process.getInputStream()));
errorResult = new BufferedReader(new InputStreamReader(process.getErrorStream()));
String s;
while ((s = successResult.readLine()) != null) {
Log.e("mjhseng", "successResult----------" + s);
successMsg.append(s);
}
while ((s = errorResult.readLine()) != null) {
Log.e("mjhseng", "errorResult----------" + s);
errorMsg.append(s);
}
} catch (IOException e1) {
Log.e("fanhuitong", "IOException e1)----------" + e1.toString());
e1.printStackTrace();
} finally {
try {
if (successResult != null) {
successResult.close();
}
if (errorResult != null) {
errorResult.close();
}
} catch (IOException e1) {
Log.e("fanhuitong", "IOException e11)---------" + e1.toString());
e1.printStackTrace();
}
if (process != null) {
process.destroy();
}
}
if (successMsg.toString().contains("Success") || successMsg.toString().contains("success")) {
subscriber.onNext(2);
} else {
Log.e("fanhuitong", "errormesg=========" + errorMsg.toString());
subscriber.onNext(1);
}
}
}).subscribeOn(Schedulers.newThread())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Observer<Integer>() {
@Override
public void onNext(Integer value) {
if (value == 2) {
//安装成功
ToastUtil.show("安装成功");
Log.e("fanhuitong", "-----------安装成功-----------");
} else {
//安装错误
Log.e("fanhuitong", "------------安装错误-----------");
ToastUtil.show("安装失败");
}
}
@Override
public void onCompleted() {
}
@Override
public void onError(Throwable e) {
//安装错误
}
});
}
// public static void installRx(final Context context, final String packageName, final String filePath) {
//
// Observable.create(new Observable.OnSubscribe<Integer>() {
// @Override
// public void call(Subscriber<? super Integer> subscriber) {
// File file = new File(filePath);
// if (filePath == null || filePath.length() == 0 || file == null) {
// Log.e("fanhuitong", "errormesg=========" + " 空啊 ");
// subscriber.onNext(0);
// return;
// }
// // String[] args = { "pm", "install", "-r", filePath };
// String[] args = {"pm", "install", "-i", "com.colorflykids", "--user", "0", filePath};
// // String argss = "pm install -i " + "com.colorflykids" + " --user 0 " + filePath;
// Log.e("fanhuitong", "argss====" + args);
// ProcessBuilder processBuilder = new ProcessBuilder(args);
// Process process = null;
// BufferedReader successResult = null;
// BufferedReader errorResult = null;
// StringBuilder successMsg = new StringBuilder();
// StringBuilder errorMsg = new StringBuilder();
// try {
// process = processBuilder.start();
// successResult = new BufferedReader(new InputStreamReader(process.getInputStream()));
// errorResult = new BufferedReader(new InputStreamReader(process.getErrorStream()));
// String s;
// while ((s = successResult.readLine()) != null) {
// Log.e("mjhseng", "successResult----------" + s);
// successMsg.append(s);
// }
// while ((s = errorResult.readLine()) != null) {
// Log.e("mjhseng", "errorResult----------" + s);
// errorMsg.append(s);
// }
// } catch (IOException e1) {
// Log.e("fanhuitong", "IOException e1)----------" + e1.toString());
// e1.printStackTrace();
// } finally {
// try {
// if (successResult != null) {
// successResult.close();
// }
// if (errorResult != null) {
// errorResult.close();
// }
// } catch (IOException e1) {
// Log.e("fanhuitong", "IOException e11)---------" + e1.toString());
// e1.printStackTrace();
// }
// if (process != null) {
// process.destroy();
// }
// }
// if (successMsg.toString().contains("Success") || successMsg.toString().contains("success")) {
// subscriber.onNext(2);
// } else {
// Log.e("fanhuitong", "errormesg=========" + errorMsg.toString());
// subscriber.onNext(1);
// }
// }
// }).subscribeOn(Schedulers.newThread())
// .observeOn(AndroidSchedulers.mainThread())
// .subscribe(new Observer<Integer>() {
//
// @Override
// public void onNext(Integer value) {
// if (value == 2) {
// //安装成功
// ToastUtil.show("安装成功");
// Log.e("fanhuitong", "-----------安装成功-----------");
// } else {
// //安装错误
// Log.e("fanhuitong", "------------安装错误-----------");
// ToastUtil.show("安装失败");
// }
// }
//
// @Override
// public void onCompleted() {
//
// }
//
// @Override
// public void onError(Throwable e) {
// //安装错误
// }
// });
// }
// public static void installApp(final String path, final String packageNames){
// File apkFile = new File(path);
@@ -643,4 +638,25 @@ public class ApkUtils {
}
public static int getAppVersionCode(Context context, String packageName) {
PackageManager pm = context.getPackageManager();
PackageInfo info = null;
try {
info = pm.getPackageInfo(packageName, 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;
}
return (int) appVersionCode;
} else {
return 0;
}
}
}

View File

@@ -0,0 +1,88 @@
package com.info.sn.utils;
import android.content.Context;
import android.os.Environment;
import android.util.Log;
import com.alibaba.fastjson.JSONObject;
import com.arialyy.aria.core.Aria;
import java.io.File;
import java.io.FileInputStream;
import java.math.BigInteger;
import java.security.MessageDigest;
public class FileUtils {
public static String getFileNamefromURL(String url) {
int position = url.lastIndexOf("/");
return url.substring(position + 1);
}
public static String getMD5fromFileName(String fileName) {
int position = fileName.lastIndexOf("/");
return fileName.substring(position + 9, fileName.length() - 4);
}
/**
* 获取单个文件的MD5值
*
* @param file 文件
* @return
*/
public static String getFileMD5s(File file) {
if (!file.isFile()) {
return null;
}
MessageDigest digest = null;
FileInputStream in = null;
byte buffer[] = new byte[1024];
int len;
try {
digest = MessageDigest.getInstance("MD5");
in = new FileInputStream(file);
while ((len = in.read(buffer, 0, 1024)) != -1) {
digest.update(buffer, 0, len);
}
in.close();
} catch (Exception e) {
e.printStackTrace();
return null;
}
BigInteger bigInt = new BigInteger(1, digest.digest());
return bigInt.toString(32);
}
public static void ariaDownload(Context context, String url, JSONObject jsonObject) {
String fileName = getFileNamefromURL(url);
String urlMD5 = jsonObject.getString("MD5");
Log.e("ariaDownload", "urlMD5=" + urlMD5);
File file = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS) + "/jgy/" + fileName);
if (file.exists() && !file.isDirectory()) {
String filenameMD5 = getMD5fromFileName(url);
String fileMD5 = getFileMD5s(file);
Log.e("ariaDownload", "filenameMD5=" + filenameMD5);
Log.e("ariaDownload", "fileMD5=" + fileMD5);
//后端还没有完成json字段的MD5暂时用文件名获取
if (fileMD5.equalsIgnoreCase(filenameMD5)) {
ApkUtils.installApp(context, file.getAbsolutePath());
} else {
Aria.download(context)
.load(url) //读取下载地址
.setFilePath(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS) + "/jgy/" + fileName, true)
.setExtendField(jsonObject.toJSONString())
.create(); //启动下载}
// SaveListUtils.addDownLoadList(app_package);
// }
}
} else {
Aria.download(context)
.load(url) //读取下载地址
.setFilePath(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS) + "/jgy/" + fileName, true)
.setExtendField(jsonObject.toJSONString())
.create(); //启动下载}
}
}
}

View File

@@ -4,9 +4,11 @@ import android.util.Log;
import com.info.sn.BuildConfig;
/**
* @author Administrator
*/
public class LogUtils {
static boolean isDebug = BuildConfig.LOG_DEBUG;
// static boolean isDebug = BuildConfig.LOG_DEBUG;
public static void v(String tag, String msg) {
if (isDebug) {

View File

@@ -17,7 +17,7 @@ import java.util.Map;
/**
* 作者 mjsheng
* 日期 2018/10/9 18:41
* 邮箱 278359328@qq.com
* 邮箱 501802639@qq.com
* 来自:
*/
@@ -86,22 +86,23 @@ public class SPUtils {
SharedPreferencesCompat.apply(editor);
}
/**
* 清除所有数据
*/
public static void clear(Context context) {
SharedPreferences sp = context.getSharedPreferences(FILE_NAME,
Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sp.edit();
editor.clear();
SharedPreferencesCompat.apply(editor);
reductFirstEnter(context);
}
// /**
// * 清除所有数据
// */
// public static void clear(Context context) {
// SharedPreferences sp = context.getSharedPreferences(FILE_NAME,
// Context.MODE_PRIVATE);
// SharedPreferences.Editor editor = sp.edit();
// editor.clear();
// SharedPreferencesCompat.apply(editor);
// reductFirstEnter(context);
// }
// //还原状态firstEnter信息
// private static void reductFirstEnter(Context context){
// put(context, CommonDatas.FLAG_FIRST_ENTER,CommonDatas.FLAG_FIRST_ENTER);
// }
//还原状态firstEnter信息
private static void reductFirstEnter(Context context){
put(context, CommonData.FLAG_FIRST_ENTER,CommonData.FLAG_FIRST_ENTER);
}
/**
* 查询某个key是否已经存在

View File

@@ -3,14 +3,14 @@ package com.info.sn.utils;
import android.app.ActivityManager;
import android.content.Context;
import com.info.sn.MyApplication;
import com.info.sn.base.MyApplication;
public class ServiceAliveUtils {
public static boolean isServiceAlice() {
boolean isServiceRunning = false;
ActivityManager manager =
(ActivityManager) MyApplication.getInstance().getAppContext().getSystemService(Context.ACTIVITY_SERVICE);
(ActivityManager) MyApplication.getAppContext().getSystemService(Context.ACTIVITY_SERVICE);
if (manager == null) {
return true;
}

View File

@@ -1,11 +1,15 @@
package com.info.sn.utils;
import android.annotation.SuppressLint;
import android.app.ActivityManager;
import android.app.admin.DevicePolicyManager;
import android.bluetooth.BluetoothAdapter;
import android.content.ActivityNotFoundException;
import android.content.ComponentName;
import android.content.Context;
import android.content.ContextWrapper;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
@@ -24,133 +28,63 @@ import android.net.NetworkInfo;
import android.net.Uri;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.os.BatteryManager;
import android.os.Build;
import android.os.StatFs;
import android.provider.Settings;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.text.format.Formatter;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.Toast;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.EncodeHintType;
import com.google.zxing.WriterException;
import com.google.zxing.common.BitMatrix;
import com.google.zxing.qrcode.QRCodeWriter;
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
import com.info.sn.MyApplication;
import com.info.sn.BuildConfig;
import com.info.sn.R;
import com.info.sn.bean.SystemSettings;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileFilter;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.io.LineNumberReader;
import java.io.Reader;
import java.lang.reflect.Method;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;
import static java.lang.System.getProperty;
public class Utils {
public static final String PACKAGE = "appstore";
public static final String DOWNLOAD_STARTALL_ACTION = PACKAGE + "_startall"; // 开始所有任务
public static final String DOWNLOAD_DELETE_UPDATE_ACTION = PACKAGE + "_download_update_delete"; // 删除应用更新文件
public static final String DOWNLOAD_DELETEALL_ACTION = PACKAGE + "_deleteall_alltask"; // 删除所有任务
public static final String DOWNLOAD_ALLTASK_ACTION = PACKAGE + "_download_alltask"; // 获取所有任务
public static final String DOWNLOAD_START_ACTION = PACKAGE + "_download_start"; // 下载标识
public static final String DOWNLOAD_STOP_ACTION = PACKAGE + "_download_stop"; // 暂停标识
public static final String DOWNLOAD_DELETE_PACKAGENAME_ACTION = PACKAGE + "_download_packagename_delete"; // 删除标识 根据包名
public static final String DOWNLOAD_DELETE_URL_ACTION = PACKAGE + "_download_url_delete"; // 删除标识 根据下载地址
public static final String DOWNLOAD_INITIALIZE_ACTION = PACKAGE + "_download_initialize"; // item初始化状态
public static final String DOWNLOAD_PACKAGENAME_ACTION = PACKAGE + "_download_packagename"; // item初始化状态 包名
public static final String DOWNLOAD_SERVICE_ACTION = PACKAGE + "_download_service"; // 下载状态回调服务
public static final String DOWNLOAD_ALLSERVICE_ACTION = PACKAGE + "_download_allservice"; // 返回所有下载任务
public static final String DOWNLOAD_NEWSERVICE_ACTION = PACKAGE + "_download_newservice"; // 一个新的下载任务
// JPush 推送消息
public static final String MESSAGE_RECEIVED_ACTION = "com.appstore.jpushdemo.MESSAGE_RECEIVED_ACTION";
public static final String KEY_TITLE = "title"; // 消息标题
public static final String KEY_MESSAGE = "message"; // 消息内容
public static final String KEY_EXTRAS = "extras"; // 消息内容类型
public static final String KEY_TYPE = "type"; // 消息内容类型
public static final String ACTION_PACKAGE_REPLACED = PACKAGE + "PACKAGE_REPLACED"; // 替换应用
public static final String ACTION_PACKAGE_REMOVED = PACKAGE + "PACKAGE_REMOVED"; // 卸载应用
public static final String ACTION_PACKAGE_ADDED = PACKAGE + "PACKAGE_ADDED"; // 安装应用
// public static int[] babyImage = {R.drawable.language, R.drawable.habit, R.drawable.knowledge, R.drawable.security, R.drawable.promotion};
// public static int[] childImage = {R.drawable.yuwen, R.drawable.shuxue, R.drawable.yingyu, R.drawable.qingshang, R.drawable.yishu, R.drawable.promotion};
// public static int[] youngImage = {R.drawable.yuwen, R.drawable.shuxue, R.drawable.yingyu, R.drawable.promotion};
// 学习日志上传标识
public static final String APP_LRARNLOG = "com.colorflykids.alarm";
// 学习日志下载标识
public static final String APP_DOWNLOADLEARNLOG = "com.colorflykids.downloadlearnlog";
// 账号注销标识
public static final String APP_USERLOGOUT = "com.colorflykids.userlogout";
public static final String UPDATE_SYSTEMUI = "cn.colorflykids.UPDATE_SYSTEMUI";
public static final int COUNT_ONE_PAGE = 8;
public static final int COUNT_ONE_PAGE2 = 10;
public static final String YOUNGSYSTEM_APP_TONGBU = "com.school.app.syn"; // 小学系统 同步教材app
/**
*
*/
public static final String number[] = {
"1", "2", "3", "4", "5", "6", "7",
"8", "9", "10", "0", "11"};
public static final String STORE = "store";
public static final String CATEGORY_THREE = "3";
public static final String CATEGORY_SIX = "6";
public static final String CATEGORY_UPSIX = "10";
public static final String CLOSE_REST_WINDOW = "colse_rest_window";
public static final String STOP_LOOPING_TIMER = "stop_looping_timer";
public static final String START_LOOPING_TIMER = "start_looping_timer";
public static String DOWNLOADAPP_CALLBACK = "com.colorflykids.downloadapp"; // 子界面下载回调 提示更新UI
public static String MENU_YOUYOU = "youyou";
public static String MENU_LANGUAGE = "语言启蒙";
public static String MENU_HABIT = "行为习惯";
public static String MENU_KNOWLEDGE = "生活认知";
public static String MENU_SECURITY = "安全自理";
public static String MENU_PROMOTION = "入园-综合提升";
public static String MENU_LY = "优优乐园";
public static String MENU_YW = "语文知识";
public static String MENU_SX = "数理逻辑";
public static String MENU_YY = "英语启蒙";
public static String MENU_QS = "情商培养";
public static String MENU_YS = "艺术提升";
public static String MENU_ZH = "学前-综合提升";
public static String MENU_TONGBUJIAOCAI = "同步教材";
public static String MENU_YUWEN = "语文";
public static String MENU_SHUXUE = "数学";
public static String MENU_YINGYU = "英语";
public static String MENU_ZONGHETISHEGN = "小学-综合提升";
public static String[] babySystem = {MENU_LANGUAGE, MENU_HABIT, MENU_KNOWLEDGE, MENU_SECURITY, MENU_PROMOTION};
public static String[] childSystem = {MENU_LY, MENU_YW, MENU_SX, MENU_YY, MENU_QS, MENU_YS, MENU_ZH};
public static String[] youngSystem = {MENU_YUWEN, MENU_SHUXUE, MENU_YINGYU, MENU_ZONGHETISHEGN};
public static String[] sonSystem = {MENU_HABIT, MENU_SECURITY, MENU_LANGUAGE, MENU_KNOWLEDGE, MENU_PROMOTION,
MENU_LY, MENU_YW, MENU_SX, MENU_YY, MENU_QS, MENU_YS, MENU_ZH,
MENU_TONGBUJIAOCAI, MENU_YUWEN, MENU_SHUXUE, MENU_YINGYU, MENU_YINGYU, MENU_ZONGHETISHEGN};
public static String[][] tagList = {babySystem, childSystem, youngSystem};
public static String subcategories[][] = {babySystem, childSystem, youngSystem};
public static String system[] = {"入园系统", "学前系统", "小学系统"};
public static String systemandno[] = {"入园系统", "学前系统", "小学系统", "未分配"};
private static final String TAG = "Utils";
protected static Toast toast = null;
private static String oldMsg;
private static long oneTime = 0;
@@ -299,7 +233,6 @@ public class Utils {
}
private static String getSimSerialNumber(Context context) {
TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
@SuppressLint("MissingPermission") String simSerialNumber = tm.getSimSerialNumber();
@@ -743,9 +676,9 @@ public class Utils {
}
public static String getSn() {
return Build.SERIAL;
}
// public static String getSn() {
// return Build.SERIAL;
// }
public static Bitmap createQRImage(String content, int widthPix, int heightPix) {
try {
@@ -873,5 +806,599 @@ public class Utils {
// return bgBitmap;
}
private static int changeNum(int status) {
return status == 0 ? 1 : 0;
}
public static void setSystemSetting(Context context, String data) {
if (TextUtils.isEmpty(data)) {
return;
}
SystemSettings settings = JSON.parseObject(data, SystemSettings.class);
if (null != settings) {
setPhoneList(context, settings);
setUSBstate(context, settings);
setBluetooth(context, settings);
setHotspot(context, settings);
setBar(context, settings);
setCamera(context, settings);
setTF(context, settings);
setIcon(context, settings);
}
}
private static void setPhoneList(Context mContext, SystemSettings settings) {
//设置电话功能,电话白名单
int setting_call = changeNum(settings.getSetting_call());
boolean qch_call_forbid = Settings.System.putInt(mContext.getContentResolver(), "qch_call_forbid", setting_call);
Log.e("SystemSetting", "qch_call_forbid:" + qch_call_forbid);
int setting_phone = changeNum(settings.getSetting_phone());
boolean qch_white_list_on = Settings.System.putInt(mContext.getContentResolver(), "qch_white_list_on", setting_phone);
Log.e("SystemSetting", "qch_white_list_on:" + qch_white_list_on);
String setting_phones = settings.getSetting_phones();
boolean qch_white_list_Array = Settings.System.putString(mContext.getContentResolver(), "qch_white_list_Array", setting_phones);
Log.e("SystemSetting", "qch_white_list_Array:" + qch_white_list_Array + "=" + setting_phones);
int setting_memory = changeNum(settings.getSetting_memory());
boolean qch_sdcard_forbid_on = Settings.System.putInt(mContext.getContentResolver(), "qch_sdcard_forbid_on", setting_memory);
Log.e("SystemSetting", "qch_sdcard_forbid_on:" + qch_sdcard_forbid_on);
}
private static void setUSBstate(Context mContext, SystemSettings settings) {
//USB数据功能管控
//仅充电usb_charge
//MTP模式usb_mtp
//Midi模式usb_midi
String setting_usb = settings.getSetting_usb();
if (!BuildConfig.DEBUG) {
try {
boolean qch_usb_choose = Settings.System.putString(mContext.getContentResolver(), "qch_usb_choose", setting_usb);
Log.e("SystemSetting", "qch_usb_choose:" + qch_usb_choose);
String usbStatus = "";
switch (setting_usb) {
case "usb_charge":
usbStatus = "qch_action_usb_usb_charge";
break;
case "usb_mtp":
usbStatus = "qch_action_usb_usb_mtp";
break;
case "usb_midi":
usbStatus = "qch_action_usb_usb_midi";
break;
}
Intent usbIntent = new Intent(usbStatus).setPackage("com.android.settings");
mContext.sendBroadcast(usbIntent);
} catch (Exception e) {
Log.e(TAG, "setUSBstate: " + e.getMessage());
}
}
}
private static void setBluetooth(Context mContext, SystemSettings settings) {
try {
//蓝牙开关
int setting_bht = changeNum(settings.getSetting_bht());
//总开关
int setting_bhtvideo = changeNum(settings.getSetting_bhtvideo());
//蓝牙音频开关
int setting_bluetooth = changeNum(settings.getSetting_bluetooth());
//蓝牙传输开关
boolean qch_bht_forbid_on = Settings.System.putInt(mContext.getContentResolver(), "qch_bht_forbid_on", setting_bht);
//写入系统数据库
Log.e("SystemSetting", "qch_bht_forbid_on:" + qch_bht_forbid_on);
BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
if (qch_bht_forbid_on) {
//成功
if (null == mBluetoothAdapter) {
mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
//获取默认蓝牙适配器
}
if (setting_bht == 0) {
//蓝牙总开关开启
String setting_context = settings.getSetting_context();
if (setting_bhtvideo == 0) {
if (null != setting_context && !setting_context.equals("") && !setting_context.equals(" ") && !setting_context.equals("null")) {
Log.e("SystemSetting", "setting_context:" + setting_context);
Settings.System.putString(mContext.getContentResolver(), "qch_bhtvideo_forbid_on", setting_context);
} else {
Settings.System.putString(mContext.getContentResolver(), "qch_bhtvideo_forbid_on", "Empty");
}
} else if (setting_bhtvideo == 1) {
Settings.System.putString(mContext.getContentResolver(), "qch_bhtvideo_forbid_on", "Empty");
}
Settings.System.putInt(mContext.getContentResolver(), "qch_bt_forbid_on", setting_bluetooth);
} else {
mBluetoothAdapter.disable();
//设置关闭时关闭蓝牙
}
}
} catch (Exception e) {
Log.e(TAG, "setBluetooth: " + e.getMessage());
}
}
private static void setHotspot(Context mContext, SystemSettings settings) {
try {
int setting_hotspot = changeNum(settings.getSetting_hotspot());//热点
if (setting_hotspot == 1) {
Intent intent = new Intent();
intent.setAction("qch_hotspot_close");
intent.setPackage("com.android.settings");
mContext.sendStickyBroadcast(intent);
}
boolean qch_hotspot_forbid_on = Settings.System.putInt(mContext.getContentResolver(), "qch_hotspot_forbid_on", setting_hotspot);//写入系统数据库
Log.e("SystemSetting", "qch_hotspot_forbid_on:" + setting_hotspot);
Log.e("SystemSetting", "qch_hotspot_forbid_on:" + qch_hotspot_forbid_on);
} catch (Exception e) {
Log.e(TAG, "setHotspot: " + e.getMessage());
}
}
private static void setBar(Context mContext, SystemSettings settings) {
//系统导航条显示开关
int setting_navigation = changeNum(settings.getSetting_navigation());
boolean qch_hide_navigationBar = Settings.System.putInt(mContext.getContentResolver(), "qch_hide_NavigationBar", setting_navigation);
Log.e("SystemSetting", "qch_hide_navigationBar:" + qch_hide_navigationBar);
String navigationStatus = "";
switch (setting_navigation) {
case 0:
navigationStatus = "qch_show_NavigationBar";
break;
case 1:
navigationStatus = "qch_hide_NavigationBar";
break;
}
Intent navIntent = new Intent(navigationStatus).setPackage("com.android.systemui");
mContext.sendBroadcast(navIntent);
//状态栏显示开关
int setting_statusbar = changeNum(settings.getSetting_statusbar());
int oldNum = Settings.System.getInt(mContext.getContentResolver(), "qch_hide_statusBar", 0);
if (oldNum != setting_statusbar) {
boolean qch_hide_statusBar = Settings.System.putInt(mContext.getContentResolver(), "qch_hide_statusBar", setting_statusbar);
Log.e("SystemSetting", "qch_hide_statusBar:" + qch_hide_statusBar);
String statusbarStatus = "";
switch (setting_statusbar) {
case 0:
statusbarStatus = "qch_show_statusBar";
break;
case 1:
statusbarStatus = "qch_hide_statusBar";
break;
}
Intent statusIntent = new Intent(statusbarStatus).setPackage("com.android.systemui");
mContext.sendBroadcast(statusIntent);
}
}
private static void setCamera(Context mContext, SystemSettings settings) {
try {
//摄像头开关
int setting_camera = changeNum(settings.getSetting_camera());
Settings.System.putInt(mContext.getContentResolver(), "qch_app_camera", setting_camera);
// ApkUtils.hideSystemSettingAPP(mContext, "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");
mContext.sendBroadcast(cameraIntent);
} catch (Exception e) {
Log.e(TAG, "setCamera: " + e.getMessage());
}
}
private static void setTF(Context mContext, SystemSettings settings) {
try {
//tfmedia开关
int setting_tfmedia = changeNum(settings.getSetting_tfmedia());
boolean qch_tfmedia_forbid = Settings.System.putInt(mContext.getContentResolver(),
"qch_tfmedia_forbid", setting_tfmedia);
Log.e("SystemSetting", "setting_tfmedia:" + qch_tfmedia_forbid);
String tfmediaStatus = "";
switch (setting_tfmedia) {
case 0:
tfmediaStatus = "qch_tfmedia_open";
break;
case 1:
tfmediaStatus = "qch_tfmedia_forbid";
break;
}
Intent tfmediaIntent = new Intent(tfmediaStatus).setPackage("com.android.settings");
mContext.sendBroadcast(tfmediaIntent);
if (setting_tfmedia == 1) {
JSONArray jSONArray = null;
jSONArray = JSON.parseArray(settings.getSetting_tfmedia_format());
int i = 0;
StringBuffer stringBuffer = new StringBuffer();
while (!jSONArray.isEmpty()) {
stringBuffer.append(jSONArray.getString(i));
stringBuffer.append(",");
i++;
}
stringBuffer.deleteCharAt(stringBuffer.length() - 1);
Settings.System.putString(mContext.getContentResolver(), "qch_tfmedia_filetypes", stringBuffer.toString());//影音管控
Log.e("SystemSetting", "qch_tfmedia_filetypes---------" + stringBuffer.toString());
} else {
Settings.System.putInt(mContext.getContentResolver(), "qch_tfmedia_forbid", 0);
}
} catch (Exception e) {
Log.e(TAG, "setTF: " + e.getMessage());
}
}
private static void setIcon(Context mContext,SystemSettings settings) {
try {
//added:2019.12.6
//设置5个app的开关
//时钟
int deskclock = changeNum(settings.getSetting_clock());
Settings.System.putInt(mContext.getContentResolver(), "qch_app_deskclock", deskclock);
ApkUtils.hideSystemSettingAPP(mContext, "com.android.deskclock");
Log.e("SystemSetting", "qch_app_deskclock:" + deskclock);
//录音机
int soundrecorder = changeNum(settings.getSetting_recording());
Settings.System.putInt(mContext.getContentResolver(), "qch_app_soundrecorder", soundrecorder);
ApkUtils.hideSystemSettingAPP(mContext, "com.android.soundrecorder");
Log.e("SystemSetting", "qch_app_soundrecorder:" + soundrecorder);
//音乐
int music = changeNum(settings.getSetting_music());
Settings.System.putInt(mContext.getContentResolver(), "qch_app_music", music);
ApkUtils.hideSystemSettingAPP(mContext, "com.android.music");
Log.e("SystemSetting", "qch_app_music:" + music);
//图库
int gallery = changeNum(settings.getSetting_picture());
Settings.System.putInt(mContext.getContentResolver(), "qch_app_gallery", gallery);
ApkUtils.hideSystemSettingAPP(mContext, "com.android.gallery3d");
Log.e("SystemSetting", "qch_app_gallery:" + gallery);
//壁纸
int wallpaper = changeNum(settings.getSetting_wallpaper());
Settings.System.putInt(mContext.getContentResolver(), "qch_app_wallpaper", wallpaper);
Log.e("SystemSetting", "qch_app_wallpaper:" + wallpaper);
//文件管理器
int filemanager = changeNum(settings.getSetting_file());
Settings.System.putInt(mContext.getContentResolver(), "qch_app_filemanager", filemanager);
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
ApkUtils.hideSystemSettingAPP(mContext, "com.mediatek.filemanager");
} else {
ApkUtils.hideSystemSettingAPP(mContext, "com.android.documentsui");
}
Log.e("SystemSetting", "qch_app_filemanager:" + filemanager);
} catch (Exception e) {
Log.e(TAG, "setIcon: " + e.getMessage());
}
}
static synchronized public boolean writeDisableUpdateList(Context context, String[] notList, String[] allowList) {
String now = Settings.System.getString(context.getContentResolver(), "qch_app_forbid");
String[] nowList;
List<String> allList;
if (now == null || now.equalsIgnoreCase("")) {
allList = new ArrayList<>();
} else {
nowList = now.split(",");
allList = new ArrayList<>(Arrays.asList(nowList));//已经写入的列表
}
boolean writeSucceed = false;
if (notList != null && notList.length > 0) {
for (String s : notList) {
if (ApkUtils.isAvailable(context, s)) {
allList.remove(s);
//去掉已经安装的
} else {
if (allList.indexOf(s) == -1) {
allList.add(s);
}
//没有安装就加入进去
//没有加入会导致安装后卸载不能再安装的情况
}
}
}
for (String s : notList) {
if (allList.indexOf(s) == -1) {
allList.add(s);
//没找到元素添加到白名单
}
}
if (allList.size() > 0) {
String list = "";
for (String str : allList) {
list += str + ",";
}
list = list.substring(0, list.length() - 1);
Log.e("fht", list);
writeSucceed = Settings.System.putString(context.getContentResolver(), "qch_app_forbid", list);
Log.e("fht", "qch_app_forbid:" + list);
} else {
writeSucceed = Settings.System.putString(context.getContentResolver(), "qch_app_forbid", "Invalid");
}
return writeSucceed;
/*功能和应用安装白名单一样首先会写入所有的app名单。
*如果已经安装就从白名单删除,没有安装的不用删除
*不然会出现安装不上的情况
*在写入白名单之后和安装完成之后执行
*/
}
public static String getIMEI(Context context) {
String IMEI = "unknow";
String IMEI1, IMEI2, IMEI3;
//获取手机设备号
TelephonyManager TelephonyMgr = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
//8.0及以后版本获取
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
IMEI = TelephonyMgr.getDeviceId();
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
// try {
// Method method = TelephonyMgr.getClass().getMethod("getImei");
// IMEI = (String) method.invoke(TelephonyMgr);
// } catch (Exception e) {
// e.printStackTrace();
// Log.e("getIMEI", e.getMessage());
// }
// IMEI = TelephonyMgr.getDeviceId();
// } else {//9.0到10.0获取
IMEI = Settings.System.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID);
}
Log.e("IMEI:", "IMEI: " + IMEI);
if (null == IMEI) {
return "-";
} else {
return IMEI.toUpperCase();
}
}
public static String getAndroiodScreenProperty(Context context) {
WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
DisplayMetrics dm = new DisplayMetrics();
wm.getDefaultDisplay().getRealMetrics(dm);
int width = dm.widthPixels; // 屏幕宽度(像素)
int height = dm.heightPixels; // 屏幕高度(像素)
float density = dm.density; // 屏幕密度0.75 / 1.0 / 1.5
int densityDpi = dm.densityDpi; // 屏幕密度dpi120 / 160 / 240
// 屏幕宽度算法:屏幕宽度(像素)/屏幕密度
int screenWidth = (int) (width / density); // 屏幕宽度(dp)
int screenHeight = (int) (height / density);// 屏幕高度(dp)
// Log.e("h_bl", "屏幕宽度(像素):" + width);
// Log.e("h_bl", "屏幕高度(像素):" + height);
// Log.e("h_bl", "屏幕密度0.75 / 1.0 / 1.5" + density);
// Log.e("h_bl", "屏幕密度dpi120 / 160 / 240" + densityDpi);
// Log.e("h_bl", "屏幕宽度dp" + screenWidth);
// Log.e("h_bl", "屏幕高度dp" + screenHeight);
return width + "×" + height;
}
public static String getMacAddress() {
List<NetworkInterface> interfaces = null;
try {
interfaces = Collections.list(NetworkInterface.getNetworkInterfaces());
for (NetworkInterface networkInterface : interfaces) {
if (networkInterface != null && TextUtils.isEmpty(networkInterface.getName()) == false) {
if ("wlan0".equalsIgnoreCase(networkInterface.getName())) {
byte[] macBytes = networkInterface.getHardwareAddress();
if (macBytes != null && macBytes.length > 0) {
StringBuilder str = new StringBuilder();
for (byte b : macBytes) {
str.append(String.format("%02X:", b));
}
if (str.length() > 0) {
str.deleteCharAt(str.length() - 1);
}
return str.toString();
}
}
}
}
} catch (SocketException e) {
e.printStackTrace();
}
return "unknown";
}
public static int getBattery(Context context) {
try {
BatteryManager batteryManager = (BatteryManager) context.getSystemService(Context.BATTERY_SERVICE);
return batteryManager.getIntProperty(BatteryManager.BATTERY_PROPERTY_CAPACITY);
} catch (Exception e) {
Log.e("getBattery", "getBattery" + e.getMessage());
}
return 0;
}
synchronized private static int getBatteryLevel(Context mContext) {
if (Build.VERSION.SDK_INT >= 21)
return ((BatteryManager) mContext.getSystemService(Context.BATTERY_SERVICE)).getIntProperty(4);
Intent intent = (new ContextWrapper(mContext)).registerReceiver(null, new IntentFilter("android.intent.action.BATTERY_CHANGED"));
return intent.getIntExtra("level", -1) * 100 / intent.getIntExtra("scale", -1);
}
public static int getIsCharging(Context context) {
IntentFilter ifilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
Intent batteryStatus = context.registerReceiver(null, ifilter);
// Are we charging / charged?
int status = batteryStatus.getIntExtra(BatteryManager.EXTRA_STATUS, -1);
boolean isCharging = status == BatteryManager.BATTERY_STATUS_CHARGING ||
status == BatteryManager.BATTERY_STATUS_FULL;
// How are we charging?
// int chargePlug = batteryStatus.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1);
// boolean usbCharge = chargePlug == BatteryManager.BATTERY_PLUGGED_USB;
// boolean acCharge = chargePlug == BatteryManager.BATTERY_PLUGGED_AC;
if (isCharging) {
return 1;
} else {
return 0;
}
}
/**
* 描述:获取可用内存.
*
* @param context
* @return
*/
public static long getAvailMemory(Context context) {
// 获取android当前可用内存大小
ActivityManager activityManager = (ActivityManager) context
.getSystemService(Context.ACTIVITY_SERVICE);
ActivityManager.MemoryInfo memoryInfo = new ActivityManager.MemoryInfo();
activityManager.getMemoryInfo(memoryInfo);
// 当前系统可用内存 ,将获得的内存大小规格化
return memoryInfo.availMem;
}
/**
* 描述:总内存.
*
* @param context
* @return
*/
public static long getTotalMemory(Context context) {
// 系统内存信息文件
String file = "/proc/meminfo";
String memInfo;
String[] strs;
long memory = 0;
try {
FileReader fileReader = new FileReader(file);
BufferedReader bufferedReader = new BufferedReader(fileReader, 8192);
// 读取meminfo第一行系统内存大小
memInfo = bufferedReader.readLine();
strs = memInfo.split("\\s+");
// for (String str : strs) {
// L.d(AppUtil.class, str + "\t");
// }
// 获得系统总内存单位KB
memory = Integer.valueOf(strs[1]).intValue();
bufferedReader.close();
} catch (Exception e) {
e.printStackTrace();
}
// Byte转位KB或MB
return memory * 1024;
}
public static String getRemnantSize(Context context) {
StatFs sf = new StatFs(context.getCacheDir().getAbsolutePath());
long availableSize = sf.getAvailableBytes();
return Formatter.formatFileSize(context, availableSize);
}
public static String getDataTotalSize(Context context) {
StatFs sf = new StatFs(context.getCacheDir().getAbsolutePath());
long blockSize = sf.getBlockSize();
long totalBlocks = sf.getBlockCount();
return Formatter.formatFileSize(context, blockSize * totalBlocks);
}
private static int getNumCores() {
// Private Class to display only CPU devices in the directory listing
class CpuFilter implements FileFilter {
@Override
public boolean accept(File pathname) {
// Check if filename is "cpu", followed by a single digit number
if (Pattern.matches("cpu[0-9]", pathname.getName())) {
return true;
}
return false;
}
}
try {
// Get directory containing CPU info
File dir = new File("/sys/devices/system/cpu/");
// Filter to only list the devices we care about
File[] files = dir.listFiles(new CpuFilter());
// Return the number of cores (virtual CPU devices)
return files.length;
} catch (Exception e) {
// Default to return 1 core
return 1;
}
}
public static String getMachine(Context context) {
String device = Build.MODEL;//机型
String imei = getIMEI(context);
String system_version = Build.VERSION.RELEASE;
String firmware_version = getProperty("ro.build.display.id", "获取失败");
String rom = getProperty("ro.custom.build.version", "获取失败");
String screen_rate = getAndroiodScreenProperty(context);
JSONObject jsonObject = new JSONObject();
jsonObject.put("device", device);
jsonObject.put("imei", imei);
jsonObject.put("system_version", system_version);
jsonObject.put("firmware_version", firmware_version);
jsonObject.put("rom", rom);
jsonObject.put("screen_rate", screen_rate);
return jsonObject.toJSONString();
}
public static String getHardware(Context context) {
int electric = getBattery(context);
int charging = getIsCharging(context);
String memory = Formatter.formatFileSize(context, getAvailMemory(context)) + "\t 已用" + "/" + "" + Formatter.formatFileSize(context, getTotalMemory(context));
String storage = getRemnantSize(context) + "/" + getDataTotalSize(context);
int CPU = getNumCores();
JSONObject jsonObject = new JSONObject();
jsonObject.put("electric", electric);
jsonObject.put("charging", charging);
jsonObject.put("memory", memory);
jsonObject.put("storage", storage);
jsonObject.put("CPU", CPU + "");
return jsonObject.toJSONString();
}
public static void rebootDevices(Context context) {
Intent iReboot = new Intent(Intent.ACTION_REBOOT);
iReboot.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(iReboot);
}
synchronized public static void doMasterClear(Context context) {
if (BuildConfig.DEBUG) {
ToastUtil.show("收到重置设备推送消息");
return;
}
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.N_MR1) {
Intent intent = new Intent("android.intent.action.FACTORY_RESET");
intent.setPackage("android");
intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
intent.putExtra("android.intent.extra.REASON", "MasterClearConfirm");
intent.putExtra("android.intent.extra.WIPE_EXTERNAL_STORAGE", false);
intent.putExtra("com.android.internal.intent.extra.WIPE_ESIMS", false);
context.sendBroadcast(intent);
} else {
//10.0的不需要最小电量
// if (getBatteryLevel(context) >= CommonDatas.MIN_POWER) {
Intent intent = new Intent("android.intent.action.MASTER_CLEAR");
// intent.setPackage("com.android.settings");
context.sendBroadcast(intent);
// } else {
// MySQLData.SetBooleanData(context, CommonDatas.IS_RESET, true);
// }
}
}
}

View File

@@ -3,6 +3,7 @@ package com.info.sn.view;
import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.os.Bundle;
@@ -14,6 +15,7 @@ import android.widget.ImageView;
import android.widget.TextView;
import com.info.sn.R;
import com.info.sn.activity.MainActivity;
/**
@@ -46,8 +48,11 @@ public class CustomDialog extends Dialog {
*/
private View columnLineView;
private Context mContext;
public CustomDialog(Context context) {
super(context, R.style.CustomDialog);
this.mContext = context;
}
/**
@@ -221,6 +226,11 @@ public class CustomDialog extends Dialog {
return this;
}
public CustomDialog setNegtiveText(String negtive) {
negtiveBn.setText(negtive);
return this;
}
public int getImageResId() {
return imageResId;
}
@@ -239,5 +249,10 @@ public class CustomDialog extends Dialog {
return this;
}
@Override
public void dismiss() {
super.dismiss();
Intent intent = new Intent(mContext, MainActivity.class);
mContext.startActivity(intent);
}
}

View File

@@ -1,4 +1,4 @@
package com.info.sn.network;
package com.info.sn.websocket;
import android.util.Log;