fix:优化请求次数
update:
This commit is contained in:
2022-04-02 18:37:49 +08:00
parent 62de0cac3f
commit 683f31087f
86 changed files with 3489 additions and 3860 deletions

View File

@@ -31,7 +31,7 @@ android {
defaultConfig {
applicationId "com.aoleyun.sn"
//There are no CERT files because If the mini sdk version is 23+, the AGP will ignore the V1 scheme signature.
minSdkVersion 22
minSdkVersion 24
targetSdkVersion 29
multiDexEnabled true
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
@@ -61,8 +61,8 @@ android {
//新平台正式
cube {
flavorDimensions "default"
versionCode 26
versionName "3.5"
versionCode 27
versionName "3.6"
/*********************************极光推送************************************/
manifestPlaceholders = [
XG_ACCESS_ID : "1500026372",
@@ -246,10 +246,10 @@ dependencies {
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
//BindView
implementation 'com.jakewharton:butterknife:10.1.0'
annotationProcessor 'com.jakewharton:butterknife-compiler:10.1.0'
implementation 'com.jakewharton:butterknife:10.2.3'
annotationProcessor 'com.jakewharton:butterknife-compiler:10.2.3'
//OkHttp
implementation 'com.squareup.okhttp3:okhttp:4.9.1'
implementation 'com.squareup.okhttp3:okhttp:4.9.3'
//Retrofit
implementation 'com.squareup.retrofit2:retrofit:2.9.0'
implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
@@ -273,7 +273,8 @@ dependencies {
annotationProcessor 'com.github.bumptech.glide:compiler:4.13.1'
// debugImplementation because LeakCanary should only run in debug builds.
debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.8.1'
//磁盘缓存
implementation 'com.jakewharton:disklrucache:2.0.2'
//fastjson
implementation 'com.alibaba:fastjson:1.2.79'
//极光推送
@@ -284,7 +285,7 @@ dependencies {
//MMKV
implementation 'com.tencent:mmkv-static:1.2.12'
//腾讯移动推送 TPNS
implementation 'com.tencent.tpns:tpns:1.3.1.1-release'
implementation 'com.tencent.tpns:tpns:1.3.2.0-release'
// //RxHttp
// implementation 'com.github.liujingxing.rxhttp:rxhttp:2.6.5'
// //implementation 'com.squareup.okhttp3:okhttp:4.9.1' //rxhttp v2.2.2版本起需要手动依赖okhttp

View File

@@ -20,6 +20,7 @@ public class CheckNetContact {
void getEBagCode();
//设置极光推送平台标签
void setJpushPlatformTags(int platform);
//获取应用市场更新
void checkStoreUpdate();
//获取设备信息更新
@@ -30,8 +31,10 @@ public class CheckNetContact {
void checkNotifyUpdate();
//获取浏览器升级
void checkBrowserUpdate();
//获取测试应用更新
void checkTestUpdate();
//开始
//2.获取设备锁定状态
void getLockedState();

View File

@@ -3,36 +3,26 @@ package com.aoleyun.sn.activity.main;
import android.graphics.Bitmap;
import android.view.View;
import com.aoleyun.sn.bean.StudentsInfo;
import com.google.gson.JsonObject;
import com.aoleyun.sn.base.BasePresenter;
import com.aoleyun.sn.base.BaseView;
public class MainAContact {
public interface Presenter extends BasePresenter<MainView> {
/*获取学生信息*/
void getStudesInfo();
/*获取设备锁定状态*/
void getLockedState();
/*获取学生信息*/
void getStudesInfo(boolean refresh);
/*手动获取设备信息更新*/
void buttonCheckUpdate(View view);
}
public interface MainView extends BaseView {
/*设置账户类型*/
void settradeType(int tradeType);
/*设置批次信息*/
void setBatchText(String text, int visibility);
/*设置班级信息*/
void setClassText(String text, int visibility);
/*设置学号信息*/
void setNumberText(String text, int visibility);
/*设置姓名信息*/
void setNameText(String text, int visibility);
/*设置头像*/
void setHead(String url);
/*获取设备锁定状态*/
void setLockedState(boolean loocked);
/*获取学生信息*/
void setStudesInfo(StudentsInfo studesInfo);
/*手动获取设备信息更新*/
void buttonCheckUpdateFinish(boolean update, JsonObject jsonObject);
}

View File

@@ -4,25 +4,29 @@ import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.provider.Settings;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import com.aoleyun.sn.BuildConfig;
import com.aoleyun.sn.bean.AppUpdateInfo;
import com.aoleyun.sn.bean.BaseResponse;
import com.aoleyun.sn.bean.StudentsInfo;
import com.aoleyun.sn.comm.CommonConfig;
import com.aoleyun.sn.comm.JGYActions;
import com.aoleyun.sn.disklrucache.CacheHelper;
import com.aoleyun.sn.manager.ConnectManager;
import com.aoleyun.sn.manager.ConnectMode;
import com.aoleyun.sn.network.NetInterfaceManager;
import com.aoleyun.sn.utils.GsonUtils;
import com.aoleyun.sn.utils.JGYUtils;
import com.aoleyun.sn.utils.SPUtils;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.tencent.mmkv.MMKV;
import com.google.gson.reflect.TypeToken;
import com.trello.rxlifecycle4.RxLifecycle;
import com.trello.rxlifecycle4.android.ActivityEvent;
import java.lang.reflect.Type;
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
import io.reactivex.rxjava3.annotations.NonNull;
import io.reactivex.rxjava3.core.Observer;
@@ -39,20 +43,9 @@ public class MainAPresenter implements MainAContact.Presenter {
private static final String TAG = MainAPresenter.class.getSimpleName();
private MainAContact.MainView mView;
private Context mContext;
private MMKV mMMKV = MMKV.defaultMMKV();
public static final String GET_SETTING_FINISH_TIME = "GET_SETTING_FINISH_TIME";
//是否有接口请求成功
public boolean requestSucceeded = false;
private final String DEFAULT_INFO = "暂无信息";
private final int OK = 200;
private static final long ONE_MINUTE_TIME = 60 * 1000;
private static final long TEN_MINUTE_TIME = ONE_MINUTE_TIME * 10;
private final static int NOTFOUND = -300;
private BehaviorSubject<ActivityEvent> lifecycle;
public void setLifecycle(BehaviorSubject<ActivityEvent> lifecycle) {
@@ -78,146 +71,21 @@ public class MainAPresenter implements MainAContact.Presenter {
this.mView = null;
}
private native String getAeskey();
private static final String GET_STUDES_INFO_TIME = "getStudesInfo_key";
@Override
public void getLockedState() {
int locked = Settings.System.getInt(mContext.getContentResolver(), JGYActions.ACTION_QCH_UNLOCK_IPAD, JGYActions.FRAME_CODE_LOCKED);
Log.e("getLockedState", "locked: " + locked);
mView.setLockedState(locked == JGYActions.FRAME_CODE_LOCKED);
}
/**
* 通过sn获取用户信息
*/
@Override
public void getStudesInfo() {
setState();
long lastTime = mMMKV.decodeLong(GET_STUDES_INFO_TIME, 0);
if (System.currentTimeMillis() - TEN_MINUTE_TIME < lastTime) {
return;
}
NetInterfaceManager.getInstance()
.getStudesInfoObservable()
.compose(RxLifecycle.bindUntilEvent(lifecycle, ActivityEvent.DESTROY))
.subscribe(new Observer<BaseResponse<StudentsInfo>>() {
@Override
public void onSubscribe(@NonNull Disposable d) {
Log.e(TAG + ":" + "getStudesInfo", "onSubscribe: ");
}
@Override
public void onNext(@NonNull BaseResponse<StudentsInfo> studentsInfoBaseResponse) {
mMMKV.encode(GET_STUDES_INFO_TIME, System.currentTimeMillis());
requestSucceeded = true;
Log.e(TAG + ":" + "getStudesInfo", "onNext: " + studentsInfoBaseResponse.data);
if (studentsInfoBaseResponse.code == OK) {
int trade_type = studentsInfoBaseResponse.data.getTrade_type();
mView.settradeType(trade_type);
String sno = studentsInfoBaseResponse.data.getSno();
String realname = studentsInfoBaseResponse.data.getRealname();
String classes = studentsInfoBaseResponse.data.getClasses();
String batch = studentsInfoBaseResponse.data.getBatch();
String head_img = studentsInfoBaseResponse.data.getHead_img();
if (TextUtils.isEmpty(sno)) {
mView.setNumberText("", View.GONE);
SPUtils.put(mContext, CommonConfig.STUDENT_ID, DEFAULT_INFO);
} else {
mView.setNumberText(sno, View.VISIBLE);
SPUtils.put(mContext, CommonConfig.STUDENT_ID, sno);
}
if (TextUtils.isEmpty(realname)) {
mView.setNameText("", View.GONE);
SPUtils.put(mContext, CommonConfig.REALNAME, DEFAULT_INFO);
} else {
mView.setNameText(realname, View.VISIBLE);
SPUtils.put(mContext, CommonConfig.REALNAME, realname);
}
if (TextUtils.isEmpty(classes)) {
mView.setClassText("", View.GONE);
SPUtils.put(mContext, CommonConfig.CLASS_NAME, DEFAULT_INFO);
} else {
mView.setClassText(classes, View.VISIBLE);
SPUtils.put(mContext, CommonConfig.CLASS_NAME, classes);
}
if (TextUtils.isEmpty(batch)) {
mView.setBatchText("", View.GONE);
SPUtils.put(mContext, CommonConfig.BATCH_NAME, DEFAULT_INFO);
} else {
mView.setBatchText(batch, View.VISIBLE);
SPUtils.put(mContext, CommonConfig.BATCH_NAME, batch);
}
if (TextUtils.isEmpty(head_img)) {
mView.setHead("");
SPUtils.put(mContext, CommonConfig.HEAD_IMG, "");
} else {
mView.setHead(head_img);
SPUtils.put(mContext, CommonConfig.HEAD_IMG, head_img);
}
SPUtils.put(mContext, CommonConfig.ADMIN_ID, studentsInfoBaseResponse.data.getAdmin_id());
} else {
Log.e(TAG + ":" + "getStudesInfo", "onNext: " + studentsInfoBaseResponse.toString());
}
}
@Override
public void onError(@NonNull Throwable e) {
Log.e(TAG + ":" + "getStudesInfo", "onError: " + e.getMessage());
setState();
onComplete();
}
@Override
public void onComplete() {
//如果是解锁状态就隐藏,锁定就显示缓存
if (Settings.System.getInt(mContext.getContentResolver(), JGYActions.ACTION_QCH_UNLOCK_IPAD, 0) == 1) {
mView.setNumberText("", View.GONE);
mView.setNameText("", View.GONE);
mView.setClassText("", View.GONE);
mView.setBatchText("", View.GONE);
}
Log.e(TAG + ":" + "getStudesInfo", "onComplete: ");
}
});
public void getStudesInfo(boolean refresh) {
NetInterfaceManager.getInstance().getStudesInfo(false, getLifecycle(), studentsInfo -> mView.setStudesInfo(studentsInfo));
}
private void setState() {
String batch = (String) SPUtils.get(mContext, CommonConfig.BATCH_NAME, DEFAULT_INFO);
if (TextUtils.isEmpty(batch) || batch.equalsIgnoreCase(DEFAULT_INFO)) {
mView.setBatchText("", View.GONE);
} else {
mView.setBatchText(batch, View.VISIBLE);
}
String classes = (String) SPUtils.get(mContext, CommonConfig.CLASS_NAME, DEFAULT_INFO);
if (TextUtils.isEmpty(classes) || classes.equalsIgnoreCase(DEFAULT_INFO)) {
mView.setClassText("", View.GONE);
} else {
mView.setClassText(classes, View.VISIBLE);
}
String sno = (String) SPUtils.get(mContext, CommonConfig.STUDENT_ID, DEFAULT_INFO);
if (TextUtils.isEmpty(sno) || sno.equalsIgnoreCase(DEFAULT_INFO)) {
mView.setNumberText("", View.GONE);
} else {
mView.setNumberText(sno, View.VISIBLE);
}
String realname = (String) SPUtils.get(mContext, CommonConfig.REALNAME, DEFAULT_INFO);
if (TextUtils.isEmpty(realname) || realname.equalsIgnoreCase(DEFAULT_INFO)) {
mView.setNameText("", View.GONE);
} else {
mView.setNameText(realname, View.VISIBLE);
}
String head_img = (String) SPUtils.get(mContext, CommonConfig.HEAD_IMG, DEFAULT_INFO);
if (TextUtils.isEmpty(head_img) || head_img.equalsIgnoreCase(DEFAULT_INFO)) {
mView.setHead("");
} else {
mView.setHead(head_img);
}
}
@Override
public void getLockedState() {
int locked = Settings.System.getInt(mContext.getContentResolver(), JGYActions.ACTION_QCH_UNLOCK_IPAD, JGYActions.FRAME_CODE_LOCKED);
Log.e(TAG + ":" + "getLockedState", "locked: " + locked);
mView.setLockedState(locked == JGYActions.FRAME_CODE_LOCKED);
}
@Override
public void buttonCheckUpdate(View view) {
@@ -231,17 +99,16 @@ public class MainAPresenter implements MainAContact.Presenter {
JGYUtils.getInstance().checkAppPlatform())
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.compose(RxLifecycle.bindUntilEvent(lifecycle, ActivityEvent.DESTROY))
.subscribe(new Observer<BaseResponse>() {
.compose(RxLifecycle.bindUntilEvent(getLifecycle(), ActivityEvent.DESTROY))
.subscribe(new Observer<BaseResponse<AppUpdateInfo>>() {
@Override
public void onSubscribe(@NonNull Disposable d) {
Log.e(TAG + ":" + "checkUpdateInfo", "onSubscribe: ");
Log.e("checkUpdateInfo", "onSubscribe: ");
}
@Override
public void onNext(@NonNull BaseResponse response) {
requestSucceeded = true;
Log.e(TAG + ":" + "checkUpdateInfo", "onNext: " + response);
public void onNext(@NonNull BaseResponse<AppUpdateInfo> response) {
Log.e("checkUpdateInfo", "onNext: " + response);
if (response.code == OK) {
JsonObject jsonObject = JsonParser.parseString(new Gson().toJson(response.data)).getAsJsonObject();
long versionCode = jsonObject.get("version_code").getAsLong();
@@ -264,13 +131,13 @@ public class MainAPresenter implements MainAContact.Presenter {
@Override
public void onError(@NonNull Throwable e) {
Log.e(TAG + ":" + "checkUpdateInfo", "onError: " + e.getMessage());
Log.e("checkUpdateInfo", "onError: " + e.getMessage());
onComplete();
}
@Override
public void onComplete() {
Log.e(TAG + ":" + "checkUpdateInfo", "onComplete: ");
Log.e("checkUpdateInfo", "onComplete: ");
}
});
}

View File

@@ -20,8 +20,11 @@ import com.aoleyun.sn.BuildConfig;
import com.aoleyun.sn.R;
import com.aoleyun.sn.activity.requestlog.RequestLogActivity;
import com.aoleyun.sn.base.BaseActivity;
import com.aoleyun.sn.bean.StudentsInfo;
import com.aoleyun.sn.comm.CommonConfig;
import com.aoleyun.sn.service.main.MainService;
import com.aoleyun.sn.utils.JGYUtils;
import com.aoleyun.sn.utils.SPUtils;
import com.aoleyun.sn.utils.SaveListUtils;
import com.aoleyun.sn.utils.SysSettingUtils;
import com.aoleyun.sn.utils.ToastUtil;
@@ -29,6 +32,7 @@ import com.aoleyun.sn.utils.Utils;
import com.blankj.utilcode.util.NetworkUtils;
import com.bumptech.glide.Glide;
import com.google.gson.JsonObject;
import com.tencent.mmkv.MMKV;
import java.util.concurrent.TimeUnit;
@@ -113,6 +117,7 @@ public class MainActivity extends BaseActivity implements MainAContact.MainView,
}
private MainAPresenter mMainAPresenter;
private MMKV mMMKV = MMKV.defaultMMKV();
private boolean updateApp = false;
@@ -124,9 +129,7 @@ public class MainActivity extends BaseActivity implements MainAContact.MainView,
@Override
public void onConnected(NetworkUtils.NetworkType networkType) {
Log.e("OnNetworkStatusChanged", "onConnected: ");
timeMillis = SystemClock.elapsedRealtime();
//直接获取数据
mMainAPresenter.getLockedState();
Utils.getPublicIP(this);
}
@Override
@@ -140,9 +143,8 @@ public class MainActivity extends BaseActivity implements MainAContact.MainView,
mMainAPresenter = new MainAPresenter(this);
mMainAPresenter.attachView(this);
mMainAPresenter.setLifecycle(lifecycleSubject);
JGYUtils.startServices(MainActivity.this);
Log.e(TAG, "initView: " + "start request");
NetworkUtils.registerNetworkStatusChangedListener(this);
JGYUtils.startServices(MainActivity.this);
getDevicesInfo();
setStoreUpdateListener(bt_checkupdate);
}
@@ -238,61 +240,11 @@ public class MainActivity extends BaseActivity implements MainAContact.MainView,
}
}
//执行所有接口耗时
long timeMillis;
@Override
public void initData() {
Log.e("getMacAddress", Utils.getAndroid10MAC(this));
timeMillis = SystemClock.elapsedRealtime();
Utils.getPublicIP(this);
startService(new Intent(MainActivity.this, MainService.class));
mMainAPresenter.getLockedState();
mMainAPresenter.getStudesInfo();
}
@Override
public void settradeType(int tradeType) {
if (tradeType == 1) {
tv_class_name.setText("班级");
tv_number_name.setText("学号");
} else if (tradeType == 2) {
tv_class_name.setText("部门");
tv_number_name.setText("工号");
}
}
@Override
public void setBatchText(String text, int visibility) {
tv_batch.setText(text);
tv_batch.setVisibility(visibility);
}
@Override
public void setClassText(String text, int visibility) {
tv_class.setText(text);
layout_class.setVisibility(visibility);
}
@Override
public void setNumberText(String text, int visibility) {
tv_number.setText(text);
layout_number.setVisibility(visibility);
}
@Override
public void setNameText(String text, int visibility) {
tv_name.setText(text);
layout_name.setVisibility(visibility);
}
@Override
public void setHead(String url) {
if (TextUtils.isEmpty(url)) {
Glide.with(head).load(getDrawable(R.drawable.head)).into(head);
} else {
Glide.with(head).load(url).into(head);
}
}
/**
@@ -305,13 +257,97 @@ public class MainActivity extends BaseActivity implements MainAContact.MainView,
iv_locked.setVisibility(View.VISIBLE);
iv_locked.setImageDrawable(getDrawable(R.drawable.locked));
SaveListUtils.getList();
mMainAPresenter.getStudesInfo(false);
} else {
iv_locked.setVisibility(View.VISIBLE);
iv_locked.setImageDrawable(getDrawable(R.drawable.unlock));
setNumberText("", View.GONE);
setNameText("", View.GONE);
setClassText("", View.GONE);
setBatchText("", View.GONE);
SysSettingUtils.setEnableSetting(this);
}
}
@Override
public void setStudesInfo(StudentsInfo studesInfo) {
if (studesInfo == null) {
return;
}
int trade_type = studesInfo.getTrade_type();
String sno = studesInfo.getSno();
String realname = studesInfo.getRealname();
String classes = studesInfo.getClasses();
String batch = studesInfo.getBatch();
String head_img = studesInfo.getHead_img();
settradeType(trade_type);
if (TextUtils.isEmpty(sno)) {
setNumberText("", View.GONE);
} else {
setNumberText(sno, View.VISIBLE);
}
if (TextUtils.isEmpty(realname)) {
setNameText("", View.GONE);
} else {
setNameText(realname, View.VISIBLE);
}
if (TextUtils.isEmpty(classes)) {
setClassText("", View.GONE);
} else {
setClassText(classes, View.VISIBLE);
}
if (TextUtils.isEmpty(batch)) {
setBatchText("", View.GONE);
} else {
setBatchText(batch, View.VISIBLE);
}
if (TextUtils.isEmpty(head_img)) {
setHead("");
} else {
setHead(head_img);
}
SPUtils.put(this, CommonConfig.ADMIN_ID, studesInfo.getAdmin_id());
}
public void settradeType(int tradeType) {
if (tradeType == 1) {
tv_class_name.setText("班级");
tv_number_name.setText("学号");
} else if (tradeType == 2) {
tv_class_name.setText("部门");
tv_number_name.setText("工号");
}
}
public void setBatchText(String text, int visibility) {
tv_batch.setText(text);
tv_batch.setVisibility(visibility);
}
public void setClassText(String text, int visibility) {
tv_class.setText(text);
layout_class.setVisibility(visibility);
}
public void setNumberText(String text, int visibility) {
tv_number.setText(text);
layout_number.setVisibility(visibility);
}
public void setNameText(String text, int visibility) {
tv_name.setText(text);
layout_name.setVisibility(visibility);
}
public void setHead(String url) {
if (TextUtils.isEmpty(url)) {
Glide.with(head).load(getDrawable(R.drawable.head)).into(head);
} else {
Glide.with(head).load(url).into(head);
}
}
@SuppressLint("CheckResult")
@Override
public void buttonCheckUpdateFinish(boolean update, JsonObject jsonObject) {

View File

@@ -183,8 +183,6 @@ public class BaseApplication extends MultiDexApplication {
Log.e("TPush", "注册失败,错误码:" + errCode + ",错误信息:" + msg);
}
});
}
private static void initAliasObservable() {
@@ -378,14 +376,6 @@ public class BaseApplication extends MultiDexApplication {
});
}
// public void onTagOperatorResult(JPushMessage jPushMessage) {
// if (jPushMessage == null) {
// return;
// }
// int errorCode = jPushMessage.getErrorCode();
// onTagResult.onResult(errorCode);
// }
public static void setJpushTags() {
Log.e(TAG, "30s后重新设置tags");
// HTTPInterface.setPushTags(context);

View File

@@ -2,34 +2,67 @@ package com.aoleyun.sn.bean;
import com.google.gson.Gson;
import com.google.gson.JsonParser;
import com.google.gson.annotations.SerializedName;
import java.io.Serializable;
/**
* Created by Administrator on 2017/1/10.
*/
public class AppUpdateInfo implements Serializable {
private static final long serialVersionUID = 8448660007210869129L;
private String packageName;
private String version;
int id;
String url;
long version_code;
String app_name;
@SerializedName("package")
String packages;
String app_md5;
public String getPackageName() {
return packageName;
public int getId() {
return id;
}
public void setPackageName(String packageName) {
this.packageName = packageName;
public void setId(int id) {
this.id = id;
}
public String getVersion() {
return version;
public String getUrl() {
return url;
}
public void setVersion(String version) {
this.version = version;
public void setUrl(String url) {
this.url = url;
}
public long getVersion_code() {
return version_code;
}
public void setVersion_code(long version_code) {
this.version_code = version_code;
}
public String getApp_name() {
return app_name;
}
public void setApp_name(String app_name) {
this.app_name = app_name;
}
public String getPackages() {
return packages;
}
public void setPackages(String packages) {
this.packages = packages;
}
public String getApp_md5() {
return app_md5;
}
public void setApp_md5(String app_md5) {
this.app_md5 = app_md5;
}
@Override

View File

@@ -0,0 +1,35 @@
package com.aoleyun.sn.bean;
import java.io.Serializable;
public class ScreenLockState implements Serializable {
private static final long serialVersionUID = -622786258211262376L;
int is_screen_lock;
String lock_content;
String name;
public int getIs_screen_lock() {
return is_screen_lock;
}
public void setIs_screen_lock(int is_screen_lock) {
this.is_screen_lock = is_screen_lock;
}
public String getLock_content() {
return lock_content;
}
public void setLock_content(String lock_content) {
this.lock_content = lock_content;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}

View File

@@ -19,7 +19,9 @@ public class CommonConfig {
/*首次启动app*/
public final static String FIRST_STARTUP = "app_first_startup";
/**设备是否首次启动*/
/**
* 设备是否首次启动
*/
public final static String DEVICES_FRIST_START = "DEVICES_FRIST_START";
/*保存的应用版本号*/
@@ -36,5 +38,13 @@ public class CommonConfig {
public final static String JGY_FIRST_CONNECT = "first_connect";
/*定时上传log*/
public final static String UPLOAD_LOG_TYPE = "is_log_type";
/*所有app更新*/
public final static String ALL_APP_UPDATE = "AllAppUpdate";
/*上次检查更新时间*/
public final static String LAST_CHECK_ALL_UPDATE_TIME = "lastCheckAllUpdateTime";
/*获取设备的标签*/
public final static String DEVICES_TAG = "Aoleyun_devices_tag";
/*上次获取标签的时间*/
public final static String GET_DEVICES_TAG_LASTTIME = "Aoleyun_devices_tag_last_time";
}

View File

@@ -0,0 +1,460 @@
package com.aoleyun.sn.disklrucache;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
import android.os.Environment;
import android.util.Log;
import com.jakewharton.disklrucache.DiskLruCache;
import com.tencent.mmkv.MMKV;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.BufferedWriter;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.Serializable;
/**
* 磁盘缓存帮助类
*/
public class CacheHelper {
private static final String TAG = "DiskLruCacheHelper";
private MMKV mMMKV = MMKV.defaultMMKV();
private static final String DIR_NAME = "diskCache";
private static final int MAX_COUNT = 5 * 1024 * 1024;
private static final int DEFAULT_APP_VERSION = 1;
private DiskLruCache mDiskLruCache;
public CacheHelper(Context context) {
mDiskLruCache = generateCache(context, DIR_NAME, MAX_COUNT);
}
public CacheHelper(Context context, String dirName) {
mDiskLruCache = generateCache(context, dirName, MAX_COUNT);
}
public CacheHelper(Context context, String dirName, int maxCount) {
mDiskLruCache = generateCache(context, dirName, maxCount);
}
//custom cache dir
public CacheHelper(File dir) {
mDiskLruCache = generateCache(null, dir, MAX_COUNT);
}
public CacheHelper(Context context, File dir) {
mDiskLruCache = generateCache(context, dir, MAX_COUNT);
}
public CacheHelper(Context context, File dir, int maxCount) {
mDiskLruCache = generateCache(context, dir, maxCount);
}
private DiskLruCache generateCache(Context context, File dir, int maxCount) {
if (!dir.exists() || !dir.isDirectory()) {
throw new IllegalArgumentException(
dir + " is not a directory or does not exists. ");
}
int appVersion = context == null ? DEFAULT_APP_VERSION : Utils.getAppVersion(context);
DiskLruCache diskLruCache = null;
try {
diskLruCache = DiskLruCache.open(
dir,
appVersion,
DEFAULT_APP_VERSION,
maxCount);
} catch (IOException e) {
e.printStackTrace();
}
return diskLruCache;
}
private DiskLruCache generateCache(Context context, String dirName, int maxCount) {
DiskLruCache diskLruCache = null;
try {
diskLruCache = DiskLruCache.open(
getDiskCacheDir(context, dirName),
Utils.getAppVersion(context),
DEFAULT_APP_VERSION,
maxCount);
} catch (IOException e) {
e.printStackTrace();
}
return diskLruCache;
}
// =======================================
// ============== String 数据 读写 =============
// =======================================
public void put(String key, String value) {
mMMKV.encode(key, System.currentTimeMillis());
DiskLruCache.Editor edit = null;
BufferedWriter bw = null;
try {
edit = editor(key);
if (edit == null) {
return;
}
OutputStream os = edit.newOutputStream(0);
bw = new BufferedWriter(new OutputStreamWriter(os));
bw.write(value);
edit.commit();//write CLEAN
} catch (IOException e) {
e.printStackTrace();
try {
//s
edit.abort();//write REMOVE
} catch (IOException e1) {
e1.printStackTrace();
}
} finally {
try {
if (bw != null) {
bw.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
public String getAsString(String key) {
Log.e(TAG, "getAsString: " + key);
InputStream inputStream = null;
try {
//write READ
inputStream = get(key);
if (inputStream == null) {
return null;
}
StringBuilder sb = new StringBuilder();
int len = 0;
byte[] buf = new byte[128];
while ((len = inputStream.read(buf)) != -1) {
sb.append(new String(buf, 0, len));
}
return sb.toString();
} catch (IOException e) {
e.printStackTrace();
if (inputStream != null) {
try {
inputStream.close();
} catch (IOException e1) {
e1.printStackTrace();
}
}
}
return null;
}
public void put(String key, JSONObject jsonObject) {
put(key, jsonObject.toString());
}
public JSONObject getAsJson(String key) {
String val = getAsString(key);
try {
if (val != null) {
return new JSONObject(val);
}
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
// =======================================
// ============ JSONArray 数据 读写 =============
// =======================================
public void put(String key, JSONArray jsonArray) {
put(key, jsonArray.toString());
}
public JSONArray getAsJSONArray(String key) {
String JSONString = getAsString(key);
try {
JSONArray obj = new JSONArray(JSONString);
return obj;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
// =======================================
// ============== byte 数据 读写 =============
// =======================================
/**
* 保存 byte数据 到 缓存中
*
* @param key 保存的key
* @param value 保存的数据
*/
public void put(String key, byte[] value) {
OutputStream out = null;
DiskLruCache.Editor editor = null;
try {
editor = editor(key);
if (editor == null) {
return;
}
out = editor.newOutputStream(0);
out.write(value);
out.flush();
editor.commit();//write CLEAN
} catch (Exception e) {
e.printStackTrace();
try {
editor.abort();//write REMOVE
} catch (IOException e1) {
e1.printStackTrace();
}
} finally {
if (out != null) {
try {
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
public byte[] getAsBytes(String key) {
byte[] res = null;
InputStream is = get(key);
if (is == null) {
return null;
}
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
byte[] buf = new byte[256];
int len = 0;
while ((len = is.read(buf)) != -1) {
baos.write(buf, 0, len);
}
res = baos.toByteArray();
} catch (IOException e) {
e.printStackTrace();
}
return res;
}
// =======================================
// ============== 序列化 数据 读写 =============
// =======================================
public void put(String key, Serializable value) {
DiskLruCache.Editor editor = editor(key);
ObjectOutputStream oos = null;
if (editor == null) {
return;
}
try {
OutputStream os = editor.newOutputStream(0);
oos = new ObjectOutputStream(os);
oos.writeObject(value);
oos.flush();
editor.commit();
} catch (IOException e) {
e.printStackTrace();
try {
editor.abort();
} catch (IOException e1) {
e1.printStackTrace();
}
} finally {
try {
if (oos != null) {
oos.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
public <T> T getAsSerializable(String key) {
T t = null;
InputStream is = get(key);
ObjectInputStream ois = null;
if (is == null) {
return null;
}
try {
ois = new ObjectInputStream(is);
t = (T) ois.readObject();
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (ois != null) {
ois.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
return t;
}
// =======================================
// ============== bitmap 数据 读写 =============
// =======================================
public void put(String key, Bitmap bitmap) {
put(key, Utils.bitmap2Bytes(bitmap));
}
public Bitmap getAsBitmap(String key) {
byte[] bytes = getAsBytes(key);
if (bytes == null) {
return null;
}
return Utils.bytes2Bitmap(bytes);
}
// =======================================
// ============= drawable 数据 读写 =============
// =======================================
public void put(String key, Drawable value) {
put(key, Utils.drawable2Bitmap(value));
}
public Drawable getAsDrawable(String key) {
byte[] bytes = getAsBytes(key);
if (bytes == null) {
return null;
}
return Utils.bitmap2Drawable(Utils.bytes2Bitmap(bytes));
}
// =======================================
// ============= other methods =============
// =======================================
public boolean remove(String key) {
try {
key = Utils.hashKeyForDisk(key);
return mDiskLruCache.remove(key);
} catch (IOException e) {
e.printStackTrace();
}
return false;
}
public void close() throws IOException {
mDiskLruCache.close();
}
public void delete() throws IOException {
mDiskLruCache.delete();
}
public void flush() throws IOException {
mDiskLruCache.flush();
}
public boolean isClosed() {
return mDiskLruCache.isClosed();
}
public long size() {
return mDiskLruCache.size();
}
public void setMaxSize(long maxSize) {
mDiskLruCache.setMaxSize(maxSize);
}
public File getDirectory() {
return mDiskLruCache.getDirectory();
}
public long getMaxSize() {
return mDiskLruCache.getMaxSize();
}
// =======================================
// ===遇到文件比较大的,可以直接通过流读写 =====
// =======================================
//basic editor
public DiskLruCache.Editor editor(String key) {
try {
key = Utils.hashKeyForDisk(key);
//wirte DIRTY
DiskLruCache.Editor edit = mDiskLruCache.edit(key);
//edit maybe null :the entry is editing
if (edit == null) {
Log.w(TAG, "the entry spcified key:" + key + " is editing by other . ");
}
return edit;
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
//basic get
public InputStream get(String key) {
try {
DiskLruCache.Snapshot snapshot = mDiskLruCache.get(Utils.hashKeyForDisk(key));
if (snapshot == null) //not find entry , or entry.readable = false
{
Log.e(TAG, "not find entry , or entry.readable = false");
return null;
}
//write READ
return snapshot.getInputStream(0);
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
// =======================================
// ============== 序列化 数据 读写 =============
// =======================================
private File getDiskCacheDir(Context context, String uniqueName) {
String cachePath;
if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())
|| !Environment.isExternalStorageRemovable()) {
cachePath = context.getExternalCacheDir().getPath();
} else {
cachePath = context.getCacheDir().getPath();
}
return new File(cachePath + File.separator + uniqueName);
}
}

View File

@@ -0,0 +1,428 @@
package com.aoleyun.sn.disklrucache;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
import android.os.Environment;
import android.util.Log;
import com.jakewharton.disklrucache.DiskLruCache;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.BufferedWriter;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.Serializable;
/**
* 磁盘缓存帮助类
*/
public class DiskLruCacheHelper {
private static final String DIR_NAME = "diskCache";
private static final int MAX_COUNT = 5 * 1024 * 1024;
private static final int DEFAULT_APP_VERSION = 1;
private static final String TAG = "DiskLruCacheHelper";
private DiskLruCache mDiskLruCache;
public DiskLruCacheHelper(Context context) throws IOException {
mDiskLruCache = generateCache(context, DIR_NAME, MAX_COUNT);
}
public DiskLruCacheHelper(Context context, String dirName) throws IOException {
mDiskLruCache = generateCache(context, dirName, MAX_COUNT);
}
public DiskLruCacheHelper(Context context, String dirName, int maxCount) throws IOException {
mDiskLruCache = generateCache(context, dirName, maxCount);
}
//custom cache dir
public DiskLruCacheHelper(File dir) throws IOException {
mDiskLruCache = generateCache(null, dir, MAX_COUNT);
}
public DiskLruCacheHelper(Context context, File dir) throws IOException {
mDiskLruCache = generateCache(context, dir, MAX_COUNT);
}
public DiskLruCacheHelper(Context context, File dir, int maxCount) throws IOException {
mDiskLruCache = generateCache(context, dir, maxCount);
}
private DiskLruCache generateCache(Context context, File dir, int maxCount) throws IOException {
if (!dir.exists() || !dir.isDirectory()) {
throw new IllegalArgumentException(
dir + " is not a directory or does not exists. ");
}
int appVersion = context == null ? DEFAULT_APP_VERSION : Utils.getAppVersion(context);
DiskLruCache diskLruCache = DiskLruCache.open(
dir,
appVersion,
DEFAULT_APP_VERSION,
maxCount);
return diskLruCache;
}
private DiskLruCache generateCache(Context context, String dirName, int maxCount) throws IOException {
DiskLruCache diskLruCache = DiskLruCache.open(
getDiskCacheDir(context, dirName),
Utils.getAppVersion(context),
DEFAULT_APP_VERSION,
maxCount);
return diskLruCache;
}
// =======================================
// ============== String 数据 读写 =============
// =======================================
public void put(String key, String value) {
DiskLruCache.Editor edit = null;
BufferedWriter bw = null;
try {
edit = editor(key);
if (edit == null) return;
OutputStream os = edit.newOutputStream(0);
bw = new BufferedWriter(new OutputStreamWriter(os));
bw.write(value);
edit.commit();//write CLEAN
} catch (IOException e) {
e.printStackTrace();
try {
//s
edit.abort();//write REMOVE
} catch (IOException e1) {
e1.printStackTrace();
}
} finally {
try {
if (bw != null)
bw.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
public String getAsString(String key) {
InputStream inputStream = null;
try {
//write READ
inputStream = get(key);
if (inputStream == null) return null;
StringBuilder sb = new StringBuilder();
int len = 0;
byte[] buf = new byte[128];
while ((len = inputStream.read(buf)) != -1) {
sb.append(new String(buf, 0, len));
}
return sb.toString();
} catch (IOException e) {
e.printStackTrace();
if (inputStream != null)
try {
inputStream.close();
} catch (IOException e1) {
e1.printStackTrace();
}
}
return null;
}
public void put(String key, JSONObject jsonObject) {
put(key, jsonObject.toString());
}
public JSONObject getAsJson(String key) {
String val = getAsString(key);
try {
if (val != null)
return new JSONObject(val);
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
// =======================================
// ============ JSONArray 数据 读写 =============
// =======================================
public void put(String key, JSONArray jsonArray) {
put(key, jsonArray.toString());
}
public JSONArray getAsJSONArray(String key) {
String JSONString = getAsString(key);
try {
JSONArray obj = new JSONArray(JSONString);
return obj;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
// =======================================
// ============== byte 数据 读写 =============
// =======================================
/**
* 保存 byte数据 到 缓存中
*
* @param key 保存的key
* @param value 保存的数据
*/
public void put(String key, byte[] value) {
OutputStream out = null;
DiskLruCache.Editor editor = null;
try {
editor = editor(key);
if (editor == null) {
return;
}
out = editor.newOutputStream(0);
out.write(value);
out.flush();
editor.commit();//write CLEAN
} catch (Exception e) {
e.printStackTrace();
try {
editor.abort();//write REMOVE
} catch (IOException e1) {
e1.printStackTrace();
}
} finally {
if (out != null) {
try {
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
public byte[] getAsBytes(String key) {
byte[] res = null;
InputStream is = get(key);
if (is == null) return null;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
byte[] buf = new byte[256];
int len = 0;
while ((len = is.read(buf)) != -1) {
baos.write(buf, 0, len);
}
res = baos.toByteArray();
} catch (IOException e) {
e.printStackTrace();
}
return res;
}
// =======================================
// ============== 序列化 数据 读写 =============
// =======================================
public void put(String key, Serializable value) {
DiskLruCache.Editor editor = editor(key);
ObjectOutputStream oos = null;
if (editor == null) return;
try {
OutputStream os = editor.newOutputStream(0);
oos = new ObjectOutputStream(os);
oos.writeObject(value);
oos.flush();
editor.commit();
} catch (IOException e) {
e.printStackTrace();
try {
editor.abort();
} catch (IOException e1) {
e1.printStackTrace();
}
} finally {
try {
if (oos != null)
oos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
public <T> T getAsSerializable(String key) {
T t = null;
InputStream is = get(key);
ObjectInputStream ois = null;
if (is == null) return null;
try {
ois = new ObjectInputStream(is);
t = (T) ois.readObject();
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (ois != null)
ois.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return t;
}
// =======================================
// ============== bitmap 数据 读写 =============
// =======================================
public void put(String key, Bitmap bitmap) {
put(key, Utils.bitmap2Bytes(bitmap));
}
public Bitmap getAsBitmap(String key) {
byte[] bytes = getAsBytes(key);
if (bytes == null) return null;
return Utils.bytes2Bitmap(bytes);
}
// =======================================
// ============= drawable 数据 读写 =============
// =======================================
public void put(String key, Drawable value) {
put(key, Utils.drawable2Bitmap(value));
}
public Drawable getAsDrawable(String key) {
byte[] bytes = getAsBytes(key);
if (bytes == null) {
return null;
}
return Utils.bitmap2Drawable(Utils.bytes2Bitmap(bytes));
}
// =======================================
// ============= other methods =============
// =======================================
public boolean remove(String key) {
try {
key = Utils.hashKeyForDisk(key);
return mDiskLruCache.remove(key);
} catch (IOException e) {
e.printStackTrace();
}
return false;
}
public void close() throws IOException {
mDiskLruCache.close();
}
public void delete() throws IOException {
mDiskLruCache.delete();
}
public void flush() throws IOException {
mDiskLruCache.flush();
}
public boolean isClosed() {
return mDiskLruCache.isClosed();
}
public long size() {
return mDiskLruCache.size();
}
public void setMaxSize(long maxSize) {
mDiskLruCache.setMaxSize(maxSize);
}
public File getDirectory() {
return mDiskLruCache.getDirectory();
}
public long getMaxSize() {
return mDiskLruCache.getMaxSize();
}
// =======================================
// ===遇到文件比较大的,可以直接通过流读写 =====
// =======================================
//basic editor
public DiskLruCache.Editor editor(String key) {
try {
key = Utils.hashKeyForDisk(key);
//wirte DIRTY
DiskLruCache.Editor edit = mDiskLruCache.edit(key);
//edit maybe null :the entry is editing
if (edit == null) {
Log.w(TAG, "the entry spcified key:" + key + " is editing by other . ");
}
return edit;
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
//basic get
public InputStream get(String key) {
try {
DiskLruCache.Snapshot snapshot = mDiskLruCache.get(Utils.hashKeyForDisk(key));
if (snapshot == null) //not find entry , or entry.readable = false
{
Log.e(TAG, "not find entry , or entry.readable = false");
return null;
}
//write READ
return snapshot.getInputStream(0);
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
// =======================================
// ============== 序列化 数据 读写 =============
// =======================================
private File getDiskCacheDir(Context context, String uniqueName) {
String cachePath;
if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())
|| !Environment.isExternalStorageRemovable()) {
cachePath = context.getExternalCacheDir().getPath();
} else {
cachePath = context.getCacheDir().getPath();
}
return new File(cachePath + File.separator + uniqueName);
}
}

View File

@@ -0,0 +1,101 @@
package com.aoleyun.sn.disklrucache;
import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.PixelFormat;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import java.io.ByteArrayOutputStream;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
public class Utils {
public static int getAppVersion(Context context) {
try {
PackageInfo info = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
return info.versionCode;
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
return 1;
}
public static String hashKeyForDisk(String key) {
String cacheKey;
try {
final MessageDigest mDigest = MessageDigest.getInstance("MD5");
mDigest.update(key.getBytes());
cacheKey = bytesToHexString(mDigest.digest());
} catch (NoSuchAlgorithmException e) {
cacheKey = String.valueOf(key.hashCode());
}
return cacheKey;
}
public static String bytesToHexString(byte[] bytes) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < bytes.length; i++) {
String hex = Integer.toHexString(0xFF & bytes[i]);
if (hex.length() == 1) {
sb.append('0');
}
sb.append(hex);
}
return sb.toString();
}
public static byte[] bitmap2Bytes(Bitmap bm) {
if (bm == null) {
return null;
}
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bm.compress(Bitmap.CompressFormat.PNG, 100, baos);
return baos.toByteArray();
}
public static Bitmap bytes2Bitmap(byte[] bytes) {
return BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
}
/**
* Drawable → Bitmap
*/
public static Bitmap drawable2Bitmap(Drawable drawable) {
if (drawable == null) {
return null;
}
// 取 drawable 的长宽
int w = drawable.getIntrinsicWidth();
int h = drawable.getIntrinsicHeight();
// 取 drawable 的颜色格式
Bitmap.Config config = drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888 : Bitmap.Config.RGB_565;
// 建立对应 bitmap
Bitmap bitmap = Bitmap.createBitmap(w, h, config);
// 建立对应 bitmap 的画布
Canvas canvas = new Canvas(bitmap);
drawable.setBounds(0, 0, w, h);
// 把 drawable 内容画到画布中
drawable.draw(canvas);
return bitmap;
}
/*
* Bitmap → Drawable
*/
@SuppressWarnings("deprecation")
public static Drawable bitmap2Drawable(Bitmap bm) {
if (bm == null) {
return null;
}
BitmapDrawable bd = new BitmapDrawable(bm);
bd.setTargetDensity(bm.getDensity());
return new BitmapDrawable(bm);
}
}

View File

@@ -1,940 +1,13 @@
package com.aoleyun.sn.jpush;
import android.annotation.SuppressLint;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.ContextWrapper;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.os.BatteryManager;
import android.os.Build;
import android.provider.Settings;
import android.text.TextUtils;
import android.util.Log;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.aoleyun.sn.R;
import com.aoleyun.sn.bean.BaseResponse;
import com.aoleyun.sn.bean.RemoteDebug;
import com.aoleyun.sn.comm.CommonConfig;
import com.aoleyun.sn.comm.JGYActions;
import com.aoleyun.sn.network.HTTPInterface;
import com.aoleyun.sn.network.NetInterfaceManager;
import com.aoleyun.sn.service.main.MainService;
import com.aoleyun.sn.utils.ApkUtils;
import com.aoleyun.sn.utils.CacheUtils;
import com.aoleyun.sn.utils.CmdUtil;
import com.aoleyun.sn.utils.ForegroundAppUtil;
import com.aoleyun.sn.utils.JGYUtils;
import com.aoleyun.sn.utils.MySQLData;
import com.aoleyun.sn.utils.SPUtils;
import com.aoleyun.sn.utils.SaveListUtils;
import com.aoleyun.sn.utils.ServiceAliveUtils;
import com.aoleyun.sn.utils.Utils;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import java.io.File;
import java.lang.reflect.Type;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
import io.reactivex.rxjava3.core.Observable;
import io.reactivex.rxjava3.core.ObservableEmitter;
import io.reactivex.rxjava3.core.ObservableOnSubscribe;
import io.reactivex.rxjava3.core.Observer;
import io.reactivex.rxjava3.disposables.Disposable;
import io.reactivex.rxjava3.schedulers.Schedulers;
import okhttp3.MediaType;
import okhttp3.MultipartBody;
import okhttp3.RequestBody;
import okhttp3.ResponseBody;
public class MyJPushReceiver extends BroadcastReceiver {
private static final String TAG = MyJPushReceiver.class.getSimpleName();
//删除应用
private final String MSG_DELETE = "1";
//系统设置管控
private final String MSG_SETTING = "2";
//浏览器网址管控
private final String MSG_BROWSER = "4";
//app id管控
private final String MSG_APPID = "5";
//应用联网管控
private final String MSG_NET_CONTROL = "6";
//APP自启联网滑动管控
private final String MSG_POWER_ON = "7";
//重置
private final String MSG_RESET = "8";
//强制安装
private final String MSG_INSTALL = "9";
//解锁
private final String MSG_LOCK = "10";
//旧版相机管控
private final String MSG_CAMERA = "11";
private final String MSG_ONEPACKAGES = "12";
//app使用时间
private final String GET_APP_USEDTIME = "13";
//强制下载
private final String GET_FORCEDOWNLOADURL = "14";
//主页和书签管控
private final String SET_HOMEPAG_TAG = "15";
//app内网页管控
private final String APP_WEBSITE = "16";
//禁止app升级
private final String DISABLE_APPUPDATE = "17";
//隐藏桌面图标
private final String HIDE_DESKTOP_ICON = "18";
//禁止滑动
private final String DISABLE_APP_SLIDE = "19";
//更新引用白名单
private final String UPDATE_INFO = "20";
//截图
private final String SN_SCREENSHOT = "21";
//重启
private final String DEVICES_REBOOT = "22";
//获取设备详细信息
private final String GET_DEVICES_INFO = "23";
//霸屏
private final String LOCK_SCREEN = "24";
//取消霸屏
private final String UNLOCK_SCREEN = "25";
//结束进程
private final String KILL_SERVER = "26";
//时间管控
private final String TIME_CONTROL = "27";
//app霸屏
private final String TOP_APP = "28";
//开机动画
private final String LOGO_IMG = "29";
//默认应用
private final String DEFAULTP_APP = "30";
//发出声音
private final String PLAY_SOUND = "31";
//清除app数据
private final String CLEAN_APP_CACHE = "32";
//开发人员选项
private final String DEVELOPER_OPTIONS = "33";
//全局更新
private final String GLOBAL_UPDATE = "34";
//电子书包激活码
private final String EBAG_CODE = "35";
//更新白名单
private final String UPDATE_WHITELIST = "36";
//更换批次不恢复出厂
private final String UPDATE_BATCH = "37";
//添加wifi
private final String UPDATE_WIFI_PW = "38";
//远程关机
private final String DEVICES_POWEROFF = "41";
//远程log
private final String SN_RUN_LOG = "43";
//自定义指令
private final String CUSTOM_ORDER = "44";
private Context mContext;
private int changeNum(int paramInt) {
return paramInt == 0 ? 1 : 0;
}
@Override
public void onReceive(Context context, Intent intent) {
mContext = context;
// Bundle bundle = intent.getExtras();
// if (JPushInterface.ACTION_REGISTRATION_ID.equals(intent.getAction())) {
// String regId = bundle.getString(JPushInterface.EXTRA_REGISTRATION_ID);
// Log.e(TAG, "[MyReceiver] 接收Registration Id : " + regId);
// //send the Registration Id to your server...
// } else if (JPushInterface.ACTION_MESSAGE_RECEIVED.equals(intent.getAction())) {
// // ToastTool.show("[MyReceiver] 接收到推送下来的自定义消息: " + bundle.getString(JPushInterface.EXTRA_MESSAGE)
// // + "---" + bundle.getString(JPushInterface.EXTRA_TITLE) + "---" + bundle.getString(JPushInterface.EXTRA_CONTENT_TYPE)
// // + "---" + bundle.getString(JPushInterface.EXTRA_EXTRA) + "----" + bundle.getString("package_name"));
// // Log.e(TAG, "[MyReceiver] 接收到推送下来的自定义消息: " + bundle.getString(JPushInterface.EXTRA_MESSAGE)
// // + "---" + bundle.getString(JPushInterface.EXTRA_TITLE) + "---" + bundle.getString(JPushInterface.EXTRA_CONTENT_TYPE)
// // + "---" + bundle.getString(JPushInterface.EXTRA_EXTRA) + "----" + bundle.getString("package_name"));
// processCustomMessage(context, bundle);//屏蔽推送
// } else if (JPushInterface.ACTION_NOTIFICATION_RECEIVED.equals(intent.getAction())) {
// Log.e(TAG, "[MyReceiver] 接收到推送下来的通知" + bundle.getString(JPushInterface.EXTRA_EXTRA));
// // doDownloadAndInstall(bundle.getString(JPushInterface.EXTRA_EXTRA));
// // Log.e(getBatteryLevel()+"-0-iweroiwerewefeerer-----------");
// int notifactionId = bundle.getInt(JPushInterface.EXTRA_NOTIFICATION_ID);
// Log.e(TAG, "[MyReceiver] 接收到推送下来的通知的ID: " + notifactionId);
// } else if (JPushInterface.ACTION_NOTIFICATION_OPENED.equals(intent.getAction())) {
// Log.e(TAG, "[MyReceiver] 用户点击打开了通知");
// } else if (JPushInterface.ACTION_RICHPUSH_CALLBACK.equals(intent.getAction())) {
// Log.e(TAG, "[MyReceiver] 用户收到到RICH PUSH CALLBACK: " + bundle.getString(JPushInterface.EXTRA_EXTRA));
// //在这里根据 JPushInterface.EXTRA_EXTRA 的内容处理代码比如打开新的Activity 打开一个网页等..
// } else if (JPushInterface.ACTION_CONNECTION_CHANGE.equals(intent.getAction())) {
// boolean connected = intent.getBooleanExtra(JPushInterface.EXTRA_CONNECTION_CHANGE, false);
// Log.i(TAG, "[MyReceiver]" + intent.getAction() + " connected state change to " + connected);
// } else {
// Log.e(TAG, "[MyReceiver] Unhandled intent - " + intent.getAction());
// }
}
// private void processCustomMessage(final Context context, Bundle bundle) {
//// 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);
//// String package_name = bundle.getString("package_name");
//
// Log.e(TAG, "message::" + message + "--type::" + type + "--title::" + title + "--extras::" + extras);
// switch (message) {
// default:
// break;
// case MSG_DELETE:
// ToastUtil.betaShow("收到管控:应用删除");
// if (!TextUtils.isEmpty(title)) {
// if (SaveListUtils.getlist().contains(title)) {
// SaveListUtils.getlist().remove(title);
// }
// SaveListUtils.sendForceAPP(mContext);
// ApkUtils.UninstallAPP(mContext, title);
// }
// HTTPInterface.getAppLimit(context);
// HTTPInterface.getNetAndLaunchSetting(mContext);
// break;
// case MSG_SETTING:
// ToastUtil.betaShow("收到管控:系统设置");
// if (!TextUtils.isEmpty(extras)) {
// JGYUtils.getInstance().SettingSysData(extras);
// }
// break;
// case MSG_BROWSER:
// ToastUtil.betaShow("收到管控:浏览器网址管控");
// getDeselectBrowerID();
// break;
// case MSG_APPID:
// ToastUtil.betaShow("收到管控APP ID管控");
// getDeselectID();
// break;
// case MSG_NET_CONTROL:
// ToastUtil.betaShow("收到管控:应用联网管控");
// settingNetControl(extras);
// break;
// case MSG_POWER_ON:
// ToastUtil.betaShow("收到管控:应用自启管控");
// settingPowerOn(extras);
// break;
// case MSG_RESET:
// ToastUtil.betaShow("收到管控:设备重置");
// Utils.doMasterClear(mContext);
// break;
// case MSG_INSTALL:
// ToastUtil.betaShow("收到管控:应用安装");
// HTTPInterface.getAppLimit(context);
// doDownloadAndInstall(extras);
// HTTPInterface.setHideDesktopIcon(mContext);
// break;
// case MSG_LOCK:
// ToastUtil.betaShow("收到管控:设备锁定");
// settingLock(extras);
// break;
// case MSG_CAMERA:
// ToastUtil.betaShow("收到管控:相机管控");
// settingCamera(extras);
// break;
// case MSG_ONEPACKAGES:
// ToastUtil.betaShow("收到管控:");
// if (BaseApplication.getInstance().isFinished()) {
// settingOneNet(extras);
// }
// break;
// case GET_APP_USEDTIME:
// ToastUtil.betaShow("收到管控:获取应用使用时间");
// JSONObject jsonObject = JSON.parseObject(extras);
// String random = jsonObject.getString("random");
// String sendType = jsonObject.getString("type");
// BaseApplication.sendAppUsedTime(random, sendType);
// break;
// case GET_FORCEDOWNLOADURL:
// ToastUtil.betaShow("收到管控:应用强制安装");
// File file = new File(JGYUtils.getInstance().getDownLoadPath());
// if (!file.exists()) {
// file.mkdirs();
// }
// if (TextUtils.isEmpty(extras)) {
// Log.e(TAG, "settingNetControl extras is null");
// return;
// }
// JSONObject extra = JSON.parseObject(extras);
// String app_name = extra.getString("app_name");
// String app_package = extra.getString("package");
// String url = extra.getString("url");
// int versionCode = extra.getInteger("version_code");
// String app_id = extra.getString("app_id");
// JSONObject packageObj = new JSONObject();
// packageObj.put("app_name", app_name);
// packageObj.put("app_package", app_package);
// packageObj.put("app_id", app_id);
// Utils.ariaDownload(mContext, url, packageObj);
// break;
// case SET_HOMEPAG_TAG:
// Handler.getMain().postDelayed(new Runnable() {
// @Override
// public void run() {
// try {
// new CacheUtils().cleanApplicationUserData(mContext, "com.android.browser");
// } catch (Exception e) {
// e.printStackTrace();
// Log.e(TAG, "setHomepagtag: " + e.getMessage());
// }
// setHomepagtag(extras);
// ToastUtil.betaShow("收到管控:浏览器主页书签设置");
// }
// }, 2000);
//
// break;
// case APP_WEBSITE:
// ToastUtil.betaShow("收到管控APP内部网页管控");
// setAPPinsideWebsite(extras);
// break;
// case DISABLE_APPUPDATE:
// ToastUtil.betaShow("收到管控:应用禁止更新设置");
// setDisableUpdateList(extras);
// break;
// case HIDE_DESKTOP_ICON:
// ToastUtil.betaShow("收到管控:隐藏应用设置");
// Handler.getMain().postDelayed(() -> {
// //后台发送时数据库未改变,有时候可能获取到的数据时上一次的
// Log.e(TAG, "run: HIDE_DESKTOP_ICON ");
// HTTPInterface.setHideDesktopIcon(context);
// }, 2000);
// break;
// case DISABLE_APP_SLIDE:
// ToastUtil.betaShow("收到管控:应用滑动设置");
// setDisableSlideList(extras);
// break;
// case UPDATE_INFO:
// ToastUtil.betaShow("收到管控:更新白名单");
// HTTPInterface.getAppLimit(context);
// break;
// case SN_SCREENSHOT:
// ToastUtil.betaShow("收到管控:设备截图");
// screenshot(extras);
// break;
// case DEVICES_REBOOT:
// ToastUtil.betaShow("收到管控:设备重启");
// Utils.rebootDevices(mContext);
// break;
// case GET_DEVICES_INFO:
// ToastUtil.betaShow("收到管控:获取设备信息");
// if (MainService.mPresenter != null) {
// MainService.mPresenter.getLockedState();
// MainService.mPresenter.sendMACAddress();
// Log.e(TAG, "mPresenter: " + "getLockedState");
// } else {
// Log.e(TAG, "mPresenter is NULL");
// }
// AMapLocationClient aMapLocationClient = AmapManager.getInstance().getLocationClient();
// aMapLocationClient.stopLocation();
// aMapLocationClient.startLocation();
// aMapLocationClient.setLocationListener(new AMapLocationListener() {
// @Override
// public void onLocationChanged(AMapLocation aMapLocation) {
// StringBuilder sb = new StringBuilder();
// //errCode等于0代表定位成功其他的为定位失败具体的可以参照官网定位错误码说明
// if (aMapLocation.getErrorCode() == 0) {
// Log.e(TAG, "onLocationChanged: " + "定位成功");
// Log.e(TAG, "onLocationChanged: " + aMapLocation.getAddress());
// sb.append(aMapLocation.getAddress()).append("\n");
// SPUtils.put(mContext, "AmapAddress", aMapLocation.getAddress());
// SPUtils.put(mContext, "longitude", aMapLocation.getLongitude());
// SPUtils.put(mContext, "latitude", aMapLocation.getLatitude());
// } else {
// //定位失败
// sb.append("定位失败" + "\n");
// SPUtils.put(mContext, "AmapError", String.valueOf(aMapLocation.getErrorCode()));
// }
// Log.e(TAG, (String) SPUtils.get(mContext, "AmapAddress", "-"));
// Log.e(TAG, (String) SPUtils.get(mContext, "AmapError", "-"));
// Log.e(TAG, "amap: " + sb.toString());
// HTTPInterface.updateDeviceInfo(mContext);
// }
// });
// break;
// case LOCK_SCREEN:
// ToastUtil.betaShow("收到管控:屏幕锁定");
// JSONObject lockJSONObject = JSON.parseObject(extras);
// String name = lockJSONObject.getString("name");
// setLock_screen(1, context, name);
// break;
// case UNLOCK_SCREEN:
// ToastUtil.betaShow("收到管控:屏幕解锁");
// setLock_screen(0, context, "");
// break;
// case KILL_SERVER:
// ToastUtil.betaShow("收到管控:停止应用");
// JSONObject killJSONObject = JSON.parseObject(extras);
// String packages = killJSONObject.getString("package_name");
// JGYUtils.getInstance().killBackgroundProcesses(context, packages);
// break;
// case TIME_CONTROL:
// ToastUtil.betaShow("收到管控:使用时间管控");
// getTimeControl(context, extras);
// break;
// case TOP_APP:
// ToastUtil.betaShow("收到管控:应用霸屏");
// getTopApp(context, extras);
// break;
// case LOGO_IMG:
// ToastUtil.betaShow("收到管控:开机动画设置");
// setBootanimation(context, extras);
// Log.e(TAG, "processCustomMessage: " + extras);
// break;
// case DEFAULTP_APP:
// ToastUtil.betaShow("收到管控:");
// setDefalutApp(context, extras);
// break;
// case PLAY_SOUND:
// ToastUtil.betaShow("收到管控:查找设备");
// playSound(context, extras);
// break;
// case CLEAN_APP_CACHE:
// ToastUtil.betaShow("收到管控:应用缓存清除");
// cleanCache(context, extras);
// break;
// case DEVELOPER_OPTIONS:
// ToastUtil.betaShow("收到管控:开发人员选项管控");
// setDeveloperoptions(extras);
// break;
// case GLOBAL_UPDATE:
// ToastUtil.betaShow("收到管控:全局更新");
// GlobalUpdate(extras);
// break;
// case EBAG_CODE:
// ToastUtil.betaShow("收到管控:电子书包激活码");
// setEbagCode(extras);
// JGYUtils.getInstance().killBackgroundProcesses(context, "com.jxw.launcher");
// break;
// case UPDATE_WHITELIST:
// ToastUtil.betaShow("收到管控:更新白名单");
// HTTPInterface.getAppLimit(mContext);
// break;
// case UPDATE_BATCH:
// ToastUtil.betaShow("收到管控:更换批次不恢复出厂设置");
// Aria.download(this).removeAllTask(true);
// try {
// new CacheUtils().cleanApplicationUserData(mContext, "com.android.browser");
// } catch (Exception e) {
// e.printStackTrace();
// Log.e(TAG, "setHomepagtag: " + e.getMessage());
// }
// if (MainService.mPresenter != null) {
// MainService.mPresenter.getLockedState();
// Log.e("getLockedState", "mPresenter: " + "getLockedState");
// } else {
// Log.e("getLockedState", "mPresenter is NULL");
// }
// break;
// case UPDATE_WIFI_PW:
// HTTPInterface.getWiFiPasswd(context);
// break;
// case DEVICES_POWEROFF:
// HTTPInterface.getPoweroffTime();
// break;
// case SN_RUN_LOG:
// recordLog(context, extras);
// break;
// case CUSTOM_ORDER:
// customOrder(context, extras);
// break;
// }
//
// }
private void setLock_screen(int state, Context context, String name) {
if (ServiceAliveUtils.isServiceAlive(context)) {
context.startService(new Intent(context, MainService.class));
}
Intent intent = new Intent();
intent.putExtra("name", name);
if (state == 1) {
intent.setAction(MainService.LockScreenReceiver.action_lock);
} else if (state == 0) {
intent.setAction(MainService.LockScreenReceiver.action_unlock);
}
context.sendBroadcast(intent);
}
private void doDownloadAndInstall(String jsonString) {
File file = new File(JGYUtils.getInstance().getDownLoadPath());
if (!file.exists()) {
file.mkdirs();
}
if (TextUtils.isEmpty(jsonString)) {
Log.e(TAG, "doDownloadAndInstall: extras is null");
return;
}
JSONObject jSONObject = JSON.parseObject(jsonString);
String app_name = jSONObject.getString("app_name");
String app_package = jSONObject.getString("bg");
String app_url = jSONObject.getString("app_url");
int app_version_code = jSONObject.getInteger("app_version_code");
String app_id = jSONObject.getString("app_id");
String MD5 = jSONObject.getString("app_md5");
JSONObject packageObj = new JSONObject();
packageObj.put("app_name", app_name);
packageObj.put("app_package", app_package);
packageObj.put("app_id", app_id);
packageObj.put("MD5", MD5);
Log.e(TAG, "doDownloadAndInstall: app_package:" + app_package);
Log.e(TAG, "doDownloadAndInstall: app_url:" + app_url);
SaveListUtils.addList(app_package);
SaveListUtils.sendForceAPP(mContext);
PackageManager pm = mContext.getPackageManager();
PackageInfo packageInfo = null;
try {
packageInfo = pm.getPackageInfo(app_package, 0);
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
if (packageInfo == null) {
Log.e(TAG, "doDownloadAndInstall: " + app_package + "未安装");
if (!SaveListUtils.isDownLoading(app_url)) {
Log.e(TAG, "doDownloadAndInstall: " + app_package + "开始下载");
Utils.ariaDownload(mContext, app_url, packageObj);
}
} else {
long appVersionCode;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
appVersionCode = packageInfo.getLongVersionCode();
} else {
appVersionCode = packageInfo.versionCode;
}
if (app_version_code > appVersionCode) {
if (!SaveListUtils.isDownLoading(app_url)) {
Utils.ariaDownload(mContext, app_url, packageObj);
}
} else {
Log.e(TAG, "doDownloadAndInstall: " + app_package + "已安装最新版");
}
}
}
private int getBatteryLevel() {
if (Build.VERSION.SDK_INT >= 21) {
return ((BatteryManager) this.mContext.getSystemService(Context.BATTERY_SERVICE)).getIntProperty(4);
}
Intent intent = (new ContextWrapper(this.mContext)).registerReceiver(null, new IntentFilter("android.intent.action.BATTERY_CHANGED"));
return intent.getIntExtra("level", -1) * 100 / intent.getIntExtra("scale", -1);
}
private void getDeselectBrowerID() {
HTTPInterface.setBrowserBlackList(mContext);//浏览器网址管控
}
private void getDeselectID() {
NetInterfaceManager.getInstance().getDeselectIDApi()
.getDeselectIDApi(NetInterfaceManager.HTTP_KEY,
Utils.getSerial())
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Observer<ResponseBody>() {
@Override
public void onSubscribe(Disposable param1Disposable) {
Log.e("getDeselectID", "onSubscribe: ");
}
@Override
public void onNext(ResponseBody param1ResponseBody) {
String ids = "";
String packages = "";
try {
String responString = param1ResponseBody.string();
Log.e("getDeselectID", "onNext: " + responString);
JSONObject jSONObject = JSON.parseObject(responString);
int code = jSONObject.getInteger("code");
if (code == 200) {
ids = jSONObject.getJSONObject("data").getString("ids");
packages = jSONObject.getJSONObject("data").getString("package");
}
} catch (Exception e) {
Log.e("getDeselectID", "onNext: Exception: " + e.getMessage());
e.printStackTrace();
}
JGYUtils.getInstance().writeDeselectIDtoSystem(ids, packages);
}
@Override
public void onError(Throwable param1Throwable) {
Log.e("getDeselectID", "onError: " + param1Throwable.getMessage());
}
@Override
public void onComplete() {
Log.e("getDeselectID", "onComplete: ");
}
});
}
private void setDisableSlideList(String s) {
JSONObject jSONObject = JSON.parseObject(s);
Log.e("setDisableSlideList", "jSONObject::" + jSONObject.toString());
String strban = jSONObject.getString("ban");
String strnot = jSONObject.getString("not");
String qch_disable_slide = Settings.System.getString(mContext.getApplicationContext().getContentResolver(), "qch_disable_slide");
Log.e("fht", "qch_disable_slide::" + qch_disable_slide);
if (!TextUtils.isEmpty(strban)) {
Settings.System.putString(mContext.getContentResolver(), "qch_disable_slide", strban);
Log.e("fht", "sendban::" + strban);
} else {
Settings.System.putString(mContext.getContentResolver(), "qch_disable_slide", "Invalid");
}
Log.e("fht", "qch_disable_slide::" + Settings.System.getString(mContext.getApplicationContext().getContentResolver(), "qch_disable_slide"));
}
private void setDisableUpdateList(String s) {
Log.e("setDisableUpdateList", s);
JSONObject jsonObject = JSON.parseObject(s);
String ban = jsonObject.getString("ban");
String not = jsonObject.getString("not");
String[] banList = ban.split(",");
String[] notList = not.split(",");
boolean b = Utils.writeDisableUpdateList(mContext, banList, notList);
HTTPInterface.getAppLimit(mContext);
}
private void settingCamera(String s) {
if (TextUtils.isEmpty(s)) {
Intent intent = new Intent("qch_camera_forbid").setPackage("com.android.settings");
intent.putExtra("camera_package_name", "close");
this.mContext.sendBroadcast(intent);
Log.e(TAG, "settingNetControl extras is null");
return;
}
JSONObject jSONObject = JSON.parseObject(s);
String s1 = jSONObject.getString("ban");
// String str = jSONObject.optString("not");
Log.e("settingCamera", "ban::" + s1);
// Log.e("settingCamera", "not::" + str);
if ("0".equals(s1)) {
Intent intent2 = new Intent("qch_camera_forbid").setPackage("com.android.settings");
// intent2.putExtra("camera_package_name", s1);
this.mContext.sendBroadcast(intent2);
} else {
Intent intent1 = new Intent("qch_camera_open").setPackage("com.android.settings");
// intent1.putExtra("camera_package_name", str);
this.mContext.sendBroadcast(intent1);
}
}
private void settingOneNet(String s) {
if (TextUtils.isEmpty(s)) {
Log.e(TAG, "settingNetControl extras is null");
// return;
}
JSONObject jSONObject = JSON.parseObject(s);
Log.e("settingOneNet", "jSONObject::" + jSONObject.toString());
String packages = jSONObject.getString("package");
String status = jSONObject.getString("status");
}
private void settingNetControl(String s) {
if (TextUtils.isEmpty(s)) {
Log.e(TAG, "settingNetControl extras is null");
}
JSONObject jSONObject = JSON.parseObject(s);
Log.e("settingNetControl", "jSONObject::" + jSONObject.toString());
String disallow = jSONObject.getString("ban");
String allow = jSONObject.getString("not");
HashSet<String> disallowApp = new HashSet<>(Arrays.asList(disallow.split(",")));
JGYUtils.setAppNetwork(mContext, disallowApp);
}
private void settingPowerOn(String s) {
if (TextUtils.isEmpty(s)) {
Log.e(TAG, "settingPowerOn extras is null");
return;
}
JSONObject jSONObject = JSON.parseObject(s);
String ban = jSONObject.getString("ban");
String not = jSONObject.getString("not");
Log.e(TAG, "settingPowerOn qch_app_power_on = " + not);
if (TextUtils.isEmpty(not)) {
//当 qch_app_power_on 的值为空时,会造成系统所有应用断网
Settings.System.putString(mContext.getContentResolver(), "qch_app_power_on", "Invalid");
} else {
Settings.System.putString(mContext.getContentResolver(), "qch_app_power_on", not);
}
}
private void writeDeselectBrowserIDtoSystem(String s) {
boolean bool = Settings.System.putString(this.mContext.getContentResolver(), "DeselectBrowserArray", s);
Log.e("SystemSetting", "DeselectBrowserArray---------" + s);
Log.e("SystemSetting", "DeselectBrowserArray---------" + bool);
}
private void setHomepagtag(String s) {
HTTPInterface.getHomePageBookmarks(mContext, null);
}
private void setAPPinsideWebsite(String s) {
//禁止app内部网页访问包名用,隔开
HTTPInterface.getAppinsideWeb(mContext, new HTTPInterface.GetAppinsideWebCallback() {
@Override
public void onComplete() {
Log.e(TAG, "ononComplete: setAPPinsideWebsite");
}
});
}
/**
* 锁定设备
*
* @param s
*/
public void settingLock(String s) {
if (TextUtils.isEmpty(s)) {
Log.e(TAG, "settingLock extras is null");
return;
}
JSONObject jSONObject = JSON.parseObject(s);
int i = changeNum(jSONObject.getIntValue("lock"));
Settings.System.putInt(this.mContext.getContentResolver(), JGYActions.ACTION_QCH_UNLOCK_IPAD, i);
Log.e("SystemSetting", "qch_unlock_ipad---------" + i);
if (getBatteryLevel() >= CommonConfig.MIN_POWER) {
Utils.doMasterClear(mContext);
} else {
MySQLData.SetBooleanData(mContext, CommonConfig.IS_RESET, true);
}
}
private void getTimeControl(Context context, String extras) {
HTTPInterface.getSnTimeControl(context);
}
private void getTopApp(Context context, String extras) {
JSONObject jsonObject = JSON.parseObject(extras);
String packageName = jsonObject.getString("app_package");
if (TextUtils.isEmpty(packageName)) {
SPUtils.put(context, ForegroundAppUtil.TOPAPP_KEY, "");
ForegroundAppUtil.setTopAppClass(context, "");
} else {
SPUtils.put(context, ForegroundAppUtil.TOPAPP_KEY, packageName);
ForegroundAppUtil.setTopAppClass(context, packageName);
ForegroundAppUtil.openTopApp(context);
}
}
private void setBootanimation(Context context, String extras) {
JSONObject jsonObject = JSONObject.parseObject(extras);
int type = jsonObject.getInteger("type");
if (type == 1) {
String file_url = jsonObject.getString("file_url");
String file_md5 = jsonObject.getString("file_md5");
JGYUtils.getInstance().checkBootFile(file_url, file_md5);
} else {
JGYUtils.getInstance().removeBootanimation();
}
}
private void setDefalutApp(Context context, String extras) {
if (TextUtils.isEmpty(extras)) {
JGYUtils.getInstance().setDefaultDesktop("");
} else {
JSONObject jsonObject = JSON.parseObject(extras);
String default_launcher = jsonObject.getString("default_launcher");
if (TextUtils.isEmpty(default_launcher)) {
JGYUtils.getInstance().setDefaultDesktop("");
SPUtils.put(context, "default_launcher", "");
} else {
JGYUtils.getInstance().setDefaultDesktop(default_launcher);
SPUtils.put(context, "default_launcher", default_launcher);
}
}
}
private void playSound(Context context, String extras) {
JSONObject jsonObject = JSONObject.parseObject(extras);
defaultCallMediaPlayer(context);
}
/**
* 播放系统默认来电铃声
*
* @return MediaPlayer对象
* @throws Exception
*/
MediaPlayer mediaPlayer;
public void defaultCallMediaPlayer(Context context) {
if (mediaPlayer != null) {
mediaPlayer.stop();
mediaPlayer.release();
}
mediaPlayer = MediaPlayer.create(context, R.raw.test);
try {
// mediaPlayer.prepare();
mediaPlayer.setLooping(false);
int duration = mediaPlayer.getDuration() / 1000;
Log.e(TAG, "defaultCallMediaPlayer: " + "duration: " + duration);
int loop = 0;
if (duration <= 1) {
loop = 30;
} else {
loop = (30 / duration);
}
final int[] soundCount = {0};
int finalLoop = loop;
mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mediaPlayer) {
if (soundCount[0] <= finalLoop) {
setMaxVolume(context);
mediaPlayer.start();
soundCount[0] += 1;
Log.e(TAG, "onCompletion: " + "loop: " + finalLoop);
Log.e(TAG, "onCompletion: " + "soundCount: " + soundCount[0]);
} else {
mediaPlayer.stop();
mediaPlayer.release();
Log.e(TAG, "onCompletion: " + "loop: " + finalLoop);
Log.e(TAG, "onCompletion: " + "soundCount: " + soundCount[0]);
}
}
});
mediaPlayer.setLooping(false);
setMaxVolume(context);
mediaPlayer.start();
} catch (Exception e) {
e.printStackTrace();
Log.e(TAG, "defaultCallMediaPlayer: " + e.getMessage());
}
}
private void setMaxVolume(Context context) {
AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
int ringMax = audioManager.getStreamMaxVolume(AudioManager.STREAM_RING);
int musicMax = audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
int voiceMax = audioManager.getStreamMaxVolume(AudioManager.STREAM_VOICE_CALL);
audioManager.setStreamVolume(AudioManager.STREAM_RING, ringMax, 0);
audioManager.setStreamVolume(AudioManager.STREAM_VOICE_CALL, voiceMax, 0);
audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, musicMax, 0); //音乐音量
audioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
audioManager.setSpeakerphoneOn(true);
}
private void cleanCache(Context context, String extras) {
JSONObject jsonObject = JSONObject.parseObject(extras);
String packageName = jsonObject.getString("app_package");
if (TextUtils.isEmpty(packageName)) {
Log.e(TAG, "cleanCache: " + "package is empty");
} else {
try {
if (new CacheUtils().cleanApplicationUserData(context, packageName)) {
Log.e(TAG, "cleanCache: " + packageName + " success");
} else {
Log.e(TAG, "cleanCache: " + packageName + " failed");
}
} catch (Exception e) {
e.printStackTrace();
Log.e(TAG, "cleanCache: " + e.getMessage());
}
}
}
private void setDeveloperoptions(String extras) {
JSONObject jsonObject = JSONObject.parseObject(extras);
int is_developer = jsonObject.getInteger("is_developer");
Log.e(TAG + ":" + "getDeveloper", "onNext: " + is_developer);
Log.e(TAG, "setDeveloperoptions: " + is_developer);
JGYUtils.getInstance().setDeveloperOptions(is_developer == 0 ? 1 : 0);
}
private void GlobalUpdate(String jsonString) {
if (TextUtils.isEmpty(jsonString)) {
throw new RuntimeException();
}
JSONObject jsonObject = JSON.parseObject(jsonString);
String platform = jsonObject.getString("platform");
if (JGYUtils.getInstance().isSamePlatform(platform)) {
checkAPPInstall(jsonObject);
} else {
Log.e(TAG, "GlobalUpdate: " + "应用与app平台不符合");
}
}
@SuppressLint("NewApi")
private void checkAPPInstall(JSONObject jsonObject) {
long version_code = jsonObject.getLong("app_version_code");
PackageManager pm = mContext.getPackageManager();
PackageInfo packageInfo = null;
try {
packageInfo = pm.getPackageInfo(jsonObject.getString("app_package"), 0);
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
if (packageInfo == null || packageInfo.getLongVersionCode() < version_code) {
Utils.ariaDownload(mContext, jsonObject.getString("app_url"), jsonObject);
} else {
Log.e(TAG, "checkAPPInstall: " + "已经是最新版");
}
}
private void setEbagCode(String jsonString) {
JSONObject jsonObject = JSON.parseObject(jsonString);
String ebagCode = jsonObject.getString("ebagCode");
if (TextUtils.isEmpty(ebagCode)) {
Log.e(TAG, "setEbagCode: " + "ebagCode is empty");
} else {
SPUtils.put(mContext, "ebagCode", ebagCode);
}
}
private void recordLog(Context context, String jsonString) {
HTTPInterface.getRunLog(context);
}
private static final int ACTION_PULL = 1;
private static final int ACTION_DELETE = 2;
private static final int ACTION_UPGRADE = 3;
private void customOrder(Context context, String jsonString) {
Gson gson = new Gson();
Type type = new TypeToken<RemoteDebug>() {
}.getType();
RemoteDebug remoteDebug = gson.fromJson(jsonString, type);
if (remoteDebug != null) {
String pkg = remoteDebug.getApp_package();
String content = remoteDebug.getContent();
switch (remoteDebug.getType()) {
case ACTION_PULL:
Log.e(TAG, "customOrder: 唤起");
ApkUtils.openPackage(context, pkg);
break;
case ACTION_DELETE:
Log.e(TAG, "customOrder: 删除");
ApkUtils.UninstallAPP(context, pkg);
break;
case ACTION_UPGRADE:
Log.e(TAG, "customOrder: 更新");
HTTPInterface.getForceDownload(context);
break;
default:
break;
}
}
}
}

View File

@@ -70,6 +70,7 @@ public class AmapManager {
SPUtils.put(mContext, "AmapAddress", aMapLocation.getAddress());
SPUtils.put(mContext, "longitude", aMapLocation.getLongitude());
SPUtils.put(mContext, "latitude", aMapLocation.getLatitude());
SPUtils.put(mContext, "AmapError", "");
} else {
//定位失败
sb.append("定位失败" + "\n");

View File

@@ -10,6 +10,15 @@ import com.tencent.mmkv.MMKV;
public class ConnectManager {
private static final String TAG = ConnectManager.class.getSimpleName();
public static final long ONE_MINUTES_TIME = 60 * 1000;
public static final long FIFTEEN_MINUTES_TIME = ONE_MINUTES_TIME * 15;
public static final long HALF_HOUR_TIME = FIFTEEN_MINUTES_TIME * 2;
public static final long ONE_HOUR_TIME = HALF_HOUR_TIME * 2;
public static final long SIX_HOUR_TIME = ONE_HOUR_TIME * 6;
public static final long HALF_DAY_TIME = SIX_HOUR_TIME * 2;
public static final long ONE_DAY_TIME = HALF_DAY_TIME * 2;
/*重启后连接成功的时间*/
public static final String REBOOT_LAST_ONNECT_TIME = "reboot_last_connect_time";
/*WiFi连接后连接成功的时间*/
@@ -45,13 +54,53 @@ public class ConnectManager {
return sInstance;
}
public long getConnectModeTime(ConnectMode connectMode) {
long time = 0;
switch (connectMode) {
case DEFAULT:
time = 0;
break;
case ONE_MINUTE:
time = ONE_MINUTES_TIME;
break;
case FIFTEEN_MINUTES:
time = FIFTEEN_MINUTES_TIME;
break;
case HALF_HOUR:
time = HALF_HOUR_TIME;
break;
case ONE_HOUR:
time = ONE_HOUR_TIME;
break;
case SIX_HOUR:
time = SIX_HOUR_TIME;
break;
case HALF_DAY:
time = HALF_DAY_TIME;
break;
case ONE_DAY:
time = ONE_DAY_TIME;
break;
default:
}
return time;
}
public boolean isNeedConnect(String key, ConnectMode connectMode) {
long lastTime = mMMKV.decodeLong(key);
long intervalTime = getConnectModeTime(connectMode);
return System.currentTimeMillis() - lastTime > intervalTime;
}
/**
* @return 今天重启后是否连接
* @return 重启后是否连接
*/
public boolean isRebootFistConnect() {
long time = mMMKV.decodeLong(REBOOT_LAST_ONNECT_TIME, 0);
return !TimeUtils.isTodayTime(time);
long rebootTime = mMMKV.decodeLong(REBOOT_LAST_ONNECT_TIME, 0);
//只在开机后15内连接其他情况为service重启
long time = System.currentTimeMillis() - rebootTime;
return time < 15 * 1000;
}
/**
@@ -78,4 +127,6 @@ public class ConnectManager {
long time = mMMKV.decodeLong(WiFiAlias, 0);
return !TimeUtils.isTodayTime(time);
}
}

View File

@@ -0,0 +1,12 @@
package com.aoleyun.sn.manager;
public enum ConnectMode {
DEFAULT,
ONE_MINUTE,
FIFTEEN_MINUTES,
HALF_HOUR,
ONE_HOUR,
SIX_HOUR,
HALF_DAY,
ONE_DAY,
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,84 @@
package com.aoleyun.sn.network;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
public class NetStateUtils {
/**
* 判断网络连接状态
*
* @param context
* @return true网络已链接 false网络已断开连接
*/
public static boolean isNetworkConnected(Context context) {
if (context != null) {
ConnectivityManager mConnectivityManager = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo mNetworkInfo = mConnectivityManager
.getActiveNetworkInfo();
if (mNetworkInfo != null) {
return mNetworkInfo.isAvailable();
}
}
return false;
}
/**
* 判断wifi状态
*
* @param context
* @return true是wifi情况 false非wifi情况
*/
public static boolean isWifiConnected(Context context) {
if (context != null) {
ConnectivityManager mConnectivityManager = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo mWiFiNetworkInfo = mConnectivityManager
.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
if (mWiFiNetworkInfo != null) {
return mWiFiNetworkInfo.isAvailable();
}
}
return false;
}
/**
* 判断移动网络
*
* @param context
* @return true是移动网络情况 false非移动网络情况
*/
public static boolean isMobileConnected(Context context) {
if (context != null) {
ConnectivityManager mConnectivityManager = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo mMobileNetworkInfo = mConnectivityManager
.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
if (mMobileNetworkInfo != null) {
return mMobileNetworkInfo.isAvailable();
}
}
return false;
}
/**
* 获取连接类型
*
* @param context
* @return
*/
public static int getConnectedType(Context context) {
if (context != null) {
ConnectivityManager mConnectivityManager = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo mNetworkInfo = mConnectivityManager
.getActiveNetworkInfo();
if (mNetworkInfo != null && mNetworkInfo.isAvailable()) {
return mNetworkInfo.getType();
}
}
return -1;
}
}

View File

@@ -1,15 +1,9 @@
package com.aoleyun.sn.network;
import com.aoleyun.sn.BuildConfig;
/**
* @author Administrator
*/
public class UrlAddress {
/*根网址*/
public static final String HTTP_TAG_HEAD_NEW = BuildConfig.ROOT_URL;
/*app下载完成发送下载次数*/
public static final String SEND_DOWNLOAD_FILE_INFO = "app/downloadApp";
/*获取系统默认程序*/
@@ -36,8 +30,6 @@ public class UrlAddress {
public static final String CHECK_UPDATE = "Silent/silent";
/*获取设备标签*/
public static final String GET_DEVICES_TAGS = "Sn/getSnTag";
/*删除Aliases*/
public static final String DELETE_GEDEVICE_ALIAS = "Sn/deleteAliases";
/*浏览器书签主页设置*/
public static final String SET_HOMEPAG_TAG = "Label";
/*app内部网页管控*/
@@ -78,7 +70,6 @@ public class UrlAddress {
public static final String GET_ALL_APP = "recommend/index";
/*获取电子书包激活码*/
public static final String GET_EBAG_CODE = "And/getEbagCode";
/*恢复出厂设置次数*/
public static final String SEND_RESTORE_TIMES = "And/restore";
/*获取远程关机时间*/
@@ -99,4 +90,9 @@ public class UrlAddress {
public static final String DELETE_JPUSH_ALIAS = "https://device.jpush.cn/v3/aliases/";
/*删除tags*/
public static final String DELETE_JPUSH_TAG = "https://device.jpush.cn/v3/tags/";
@Deprecated
/*删除Aliases*/
public static final String DELETE_GEDEVICE_ALIAS = "Sn/deleteAliases";
}

View File

@@ -1,4 +1,4 @@
package com.aoleyun.sn.network.api;
package com.aoleyun.sn.network.api.get;
import com.aoleyun.sn.bean.BaseResponse;
import com.aoleyun.sn.bean.ForceDownloadData;

View File

@@ -1,4 +1,4 @@
package com.aoleyun.sn.network.api;
package com.aoleyun.sn.network.api.get;
import com.aoleyun.sn.bean.BaseResponse;
import com.aoleyun.sn.bean.DefaultApp;

View File

@@ -1,4 +1,4 @@
package com.aoleyun.sn.network.api;
package com.aoleyun.sn.network.api.get;
import com.aoleyun.sn.network.UrlAddress;

View File

@@ -1,4 +1,4 @@
package com.aoleyun.sn.network.api;
package com.aoleyun.sn.network.api.get;
import com.aoleyun.sn.bean.BaseResponse;
import com.aoleyun.sn.network.UrlAddress;

View File

@@ -1,4 +1,4 @@
package com.aoleyun.sn.network.api;
package com.aoleyun.sn.network.api.get;
import com.aoleyun.sn.bean.BaseResponse;
import com.aoleyun.sn.network.UrlAddress;

View File

@@ -1,4 +1,4 @@
package com.aoleyun.sn.network.api;
package com.aoleyun.sn.network.api.get;
import com.aoleyun.sn.bean.BaseResponse;
import com.aoleyun.sn.network.UrlAddress;

View File

@@ -1,4 +1,4 @@
package com.aoleyun.sn.network.api;
package com.aoleyun.sn.network.api.get;
import com.aoleyun.sn.bean.BaseResponse;
import com.aoleyun.sn.bean.SnRunLog;

View File

@@ -1,4 +1,4 @@
package com.aoleyun.sn.network.api;
package com.aoleyun.sn.network.api.get;
import com.aoleyun.sn.bean.BaseResponse;

View File

@@ -1,4 +1,4 @@
package com.aoleyun.sn.network.api;
package com.aoleyun.sn.network.api.get;
import com.aoleyun.sn.bean.BaseResponse;
import com.aoleyun.sn.bean.LogoImg;

View File

@@ -1,6 +1,7 @@
package com.aoleyun.sn.network.api;
package com.aoleyun.sn.network.api.get;
import com.aoleyun.sn.bean.BaseResponse;
import com.aoleyun.sn.bean.ScreenLockState;
import com.aoleyun.sn.network.UrlAddress;
import io.reactivex.rxjava3.core.Observable;
@@ -9,7 +10,7 @@ import retrofit2.http.Query;
public interface ScreenLockStateApi {
@GET(UrlAddress.GET_LOCK_SCREEN_STATE)
Observable<BaseResponse> getScreenLockState(
Observable<BaseResponse<ScreenLockState>> getScreenLockState(
@Query("sn") String sn
);
}

View File

@@ -1,4 +1,4 @@
package com.aoleyun.sn.network.api;
package com.aoleyun.sn.network.api.get;
import com.aoleyun.sn.bean.BaseResponse;
import com.aoleyun.sn.network.UrlAddress;

View File

@@ -1,4 +1,4 @@
package com.aoleyun.sn.network.api;
package com.aoleyun.sn.network.api.get;
import com.aoleyun.sn.bean.BaseResponse;
import com.aoleyun.sn.network.UrlAddress;

View File

@@ -1,4 +1,4 @@
package com.aoleyun.sn.network.api;
package com.aoleyun.sn.network.api.post;
import com.aoleyun.sn.bean.BaseResponse;
import com.aoleyun.sn.network.UrlAddress;

View File

@@ -1,4 +1,4 @@
package com.aoleyun.sn.network.api;
package com.aoleyun.sn.network.api.post;
import com.aoleyun.sn.bean.Appground;

View File

@@ -1,4 +1,4 @@
package com.aoleyun.sn.network.api;
package com.aoleyun.sn.network.api.post;
import com.aoleyun.sn.bean.BaseResponse;
import com.aoleyun.sn.bean.BrowserBookmarks;

View File

@@ -1,4 +1,4 @@
package com.aoleyun.sn.network.api;
package com.aoleyun.sn.network.api.post;
import com.aoleyun.sn.bean.BaseResponse;
import com.aoleyun.sn.bean.BrowserData;

View File

@@ -1,5 +1,6 @@
package com.aoleyun.sn.network.api;
package com.aoleyun.sn.network.api.post;
import com.aoleyun.sn.bean.AppUpdateInfo;
import com.aoleyun.sn.bean.BaseResponse;
import com.aoleyun.sn.network.UrlAddress;
@@ -12,7 +13,7 @@ public interface CheckUpdateApi {
@FormUrlEncoded
@POST(UrlAddress.CHECK_UPDATE)
//1MTK平台 2展锐平台
Observable<BaseResponse> getUpdate(
Observable<BaseResponse<AppUpdateInfo>> getUpdate(
@Field("package") String packages,
@Field("type") int type
);

View File

@@ -1,4 +1,4 @@
package com.aoleyun.sn.network.api;
package com.aoleyun.sn.network.api.post;
import com.aoleyun.sn.bean.BaseResponse;
import com.aoleyun.sn.network.UrlAddress;

View File

@@ -1,4 +1,4 @@
package com.aoleyun.sn.network.api;
package com.aoleyun.sn.network.api.post;
import com.aoleyun.sn.network.UrlAddress;

View File

@@ -1,4 +1,4 @@
package com.aoleyun.sn.network.api;
package com.aoleyun.sn.network.api.post;
import com.aoleyun.sn.bean.BaseResponse;
import com.aoleyun.sn.network.UrlAddress;

View File

@@ -1,4 +1,4 @@
package com.aoleyun.sn.network.api;
package com.aoleyun.sn.network.api.post;
import com.aoleyun.sn.bean.BaseResponse;
import com.aoleyun.sn.network.UrlAddress;

View File

@@ -1,4 +1,4 @@
package com.aoleyun.sn.network.api;
package com.aoleyun.sn.network.api.post;
import com.aoleyun.sn.bean.ForceDownloadBean;
import com.aoleyun.sn.network.UrlAddress;

View File

@@ -1,4 +1,4 @@
package com.aoleyun.sn.network.api;
package com.aoleyun.sn.network.api.post;
import com.aoleyun.sn.bean.AppListInfo;
import com.aoleyun.sn.bean.BaseResponse;

View File

@@ -1,4 +1,4 @@
package com.aoleyun.sn.network.api;
package com.aoleyun.sn.network.api.post;
import com.aoleyun.sn.bean.BaseResponse;
import com.aoleyun.sn.network.UrlAddress;

View File

@@ -1,4 +1,4 @@
package com.aoleyun.sn.network.api;
package com.aoleyun.sn.network.api.post;
import com.aoleyun.sn.network.UrlAddress;

View File

@@ -1,4 +1,4 @@
package com.aoleyun.sn.network.api;
package com.aoleyun.sn.network.api.post;
import com.aoleyun.sn.bean.BaseResponse;
import com.aoleyun.sn.network.UrlAddress;

View File

@@ -1,4 +1,4 @@
package com.aoleyun.sn.network.api;
package com.aoleyun.sn.network.api.post;
import com.aoleyun.sn.network.UrlAddress;

View File

@@ -1,4 +1,4 @@
package com.aoleyun.sn.network.api;
package com.aoleyun.sn.network.api.post;
import com.aoleyun.sn.bean.BaseResponse;
import com.aoleyun.sn.bean.PoweroffBean;

View File

@@ -1,4 +1,4 @@
package com.aoleyun.sn.network.api;
package com.aoleyun.sn.network.api.post;
import com.aoleyun.sn.bean.BaseResponse;
import com.aoleyun.sn.bean.SnRunLog;

View File

@@ -1,4 +1,4 @@
package com.aoleyun.sn.network.api;
package com.aoleyun.sn.network.api.post;
import com.aoleyun.sn.bean.BaseResponse;
import com.aoleyun.sn.bean.SnRunLog;

View File

@@ -1,4 +1,4 @@
package com.aoleyun.sn.network.api;
package com.aoleyun.sn.network.api.post;
import com.aoleyun.sn.bean.BaseResponse;
import com.aoleyun.sn.network.UrlAddress;

View File

@@ -1,4 +1,4 @@
package com.aoleyun.sn.network.api;
package com.aoleyun.sn.network.api.post;
import com.aoleyun.sn.bean.NetAndLaunchBean;
import com.aoleyun.sn.network.UrlAddress;

View File

@@ -1,4 +1,4 @@
package com.aoleyun.sn.network.api;
package com.aoleyun.sn.network.api.post;
import com.aoleyun.sn.bean.BaseResponse;

View File

@@ -1,4 +1,4 @@
package com.aoleyun.sn.network.api;
package com.aoleyun.sn.network.api.post;
import com.aoleyun.sn.bean.BaseResponse;
import com.aoleyun.sn.network.UrlAddress;

View File

@@ -1,4 +1,4 @@
package com.aoleyun.sn.network.api;
package com.aoleyun.sn.network.api.post;
import com.aoleyun.sn.bean.BaseResponse;
import com.aoleyun.sn.network.UrlAddress;

View File

@@ -1,4 +1,4 @@
package com.aoleyun.sn.network.api;
package com.aoleyun.sn.network.api.post;
import com.aoleyun.sn.bean.BaseResponse;
import com.aoleyun.sn.network.UrlAddress;

View File

@@ -1,4 +1,4 @@
package com.aoleyun.sn.network.api;
package com.aoleyun.sn.network.api.post;
import com.aoleyun.sn.BuildConfig;
import com.aoleyun.sn.bean.BaseResponse;

View File

@@ -1,4 +1,4 @@
package com.aoleyun.sn.network.api;
package com.aoleyun.sn.network.api.post;
import com.aoleyun.sn.bean.BaseResponse;
import com.aoleyun.sn.network.UrlAddress;

View File

@@ -1,4 +1,4 @@
package com.aoleyun.sn.network.api;
package com.aoleyun.sn.network.api.post;
import com.aoleyun.sn.bean.BaseResponse;
import com.aoleyun.sn.bean.StudentsInfo;
@@ -9,7 +9,7 @@ import retrofit2.http.Field;
import retrofit2.http.FormUrlEncoded;
import retrofit2.http.POST;
public interface StudentsInfosApi {
public interface StudentsInfoApi {
@FormUrlEncoded
@POST(UrlAddress.GET_STUDENTS_INFO)
Observable<BaseResponse<StudentsInfo>> getStudentsInfo(

View File

@@ -1,4 +1,4 @@
package com.aoleyun.sn.network.api;
package com.aoleyun.sn.network.api.post;
import com.aoleyun.sn.network.UrlAddress;

View File

@@ -1,4 +1,4 @@
package com.aoleyun.sn.network.api;
package com.aoleyun.sn.network.api.post;
import com.aoleyun.sn.bean.BaseResponse;
import com.aoleyun.sn.network.UrlAddress;

View File

@@ -1,4 +1,4 @@
package com.aoleyun.sn.network.api;
package com.aoleyun.sn.network.api.post;
import com.aoleyun.sn.bean.BaseResponse;
import com.aoleyun.sn.network.UrlAddress;

View File

@@ -0,0 +1,278 @@
package com.aoleyun.sn.network.interceptor;
import android.text.TextUtils;
import com.aoleyun.sn.BuildConfig;
import com.aoleyun.sn.disklrucache.DiskLruCacheHelper;
import com.aoleyun.sn.utils.JGYUtils;
import com.blankj.utilcode.util.LogUtils;
import java.io.IOException;
import java.nio.charset.Charset;
import okhttp3.Interceptor;
import okhttp3.MediaType;
import okhttp3.Protocol;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
import okhttp3.ResponseBody;
import okhttp3.internal.http.HttpHeaders;
import okio.Buffer;
import okio.BufferedSource;
import static okhttp3.internal.Util.closeQuietly;
public class PostCacheInterceptor implements Interceptor {
final DiskLruCacheHelper cache;
public PostCacheInterceptor(DiskLruCacheHelper cache) {
this.cache = cache;
}
private final int REQUEST_URL = 0;
private final int REQUEST_METHOD = 1;
private final int REQUESTCONTENTTYPE = 2;
private final int PROTOCAL = 3;
private final int CODE = 4;
private final int MESSAGE = 5;
private final int REPONSE_BODY = 6;
private final int MEDIA_TYPE = 7;
private final int SETN_REQUEST_AT_MILLIS = 8;
private final int RECEIVE_REPONSE_AT_MILLIS = 9;
private final int CACHE_LENGTH = 10;
@Override
public Response intercept(Interceptor.Chain chain) throws IOException {
if (!isNeedCache(chain.request().url().toString())) {
return chain.proceed(chain.request());
}
//获取缓存
String key = createKey(chain.request());
LogUtils.d("cache key: " + key);
Response cacheResponse = null;
String cacheRes = cache != null&&key!=null
? cache.getAsString(key)
: null;
if (!TextUtils.isEmpty(cacheRes)) {
LogUtils.d("cacheRes: " + cacheRes);
cacheResponse = combineCacheToResponse(cacheRes);
}
//没有网络连接的时候读取缓存
if (!JGYUtils.getInstance().isNetworkConnected()) {
LogUtils.d("no network connected jujge cache available");
if (cacheResponse != null) {
LogUtils.d("no network connected, return cache " + cacheResponse);
return cacheResponse;
}
}
LogUtils.d("waiting for network response...");
//获取网络响应
Request netWorkRequest = chain.request();
Response networkResponse = null;
try {
networkResponse = chain.proceed(netWorkRequest);
} finally {
if (networkResponse == null) {
LogUtils.d("close cache response...");
if (cacheResponse!=null&&HttpHeaders.hasBody(cacheResponse)){
closeQuietly(cacheResponse.body());
}
return chain.proceed(netWorkRequest);
}
}
LogUtils.d("prepare update cache response...");
//更新缓存
if (cacheResponse != null) {
Response response = null;
response = networkResponse.newBuilder()
.request(new Request.Builder()
.method("GET", null)
.url(netWorkRequest.url())
.headers(netWorkRequest.headers())
.tag(netWorkRequest.tag())
.build())
.build();
LogUtils.d("update cache response");
if (key!=null){
cache.put(key, createCache(response));
}
if (cacheResponse!=null&&HttpHeaders.hasBody(cacheResponse)){
closeQuietly(cacheResponse.body());
}
return networkResponse;
}
Request newRequest = new Request.Builder()
.method("GET", null)
.url(netWorkRequest.url())
.headers(netWorkRequest.headers())
.tag(netWorkRequest.tag())
.build();
Response newResponse = networkResponse.newBuilder()
.request(newRequest)
.build();
LogUtils.d("init cache response");
//放入缓存
if (cache != null) {
LogUtils.d("url: " + netWorkRequest.url().toString());
if (HttpHeaders.hasBody(newResponse)) {
try {
LogUtils.d("chain request url: " + newResponse.request().url());
if (key!=null){
cache.put(key, createCache(newResponse));
LogUtils.d("put cache response key: " + key);
}
// String resp1 = cache.getAsString(key);
// LogUtils.d("resp1: " + resp1);
return networkResponse;
} catch (Exception e) {
LogUtils.d("put cache exception: " + e);
}finally {
if (cacheResponse != null && HttpHeaders.hasBody(cacheResponse)) {
closeQuietly(cacheResponse.body());
}
}
}
}
return networkResponse;
}
private String createKey(Request request) {
RequestBody requestBody = request.body();
Charset charset = Charset.forName("UTF-8");
String url = request.url().toString();
StringBuilder sb = new StringBuilder();
sb.append(url + "&");
MediaType type = requestBody.contentType();
if (type != null) {
charset = type.charset() == null ? charset : type.charset();
}
Buffer buffer = new Buffer();
try {
requestBody.writeTo(buffer);
sb.append(buffer.readString(charset));
} catch (Exception e) {
LogUtils.d("read request error: " + e);
} finally {
buffer.close();
}
// if (url.startsWith(BuildConfig.ROOT_URL + "your own url")) {
// return //这里可以根据url来定制化key
// }
return sb.toString();
}
//根据键返回索引
private int[] getIndexofKeyValue(String str, String originStr) {
int[] indexs = new int[2];
indexs[0] = originStr.indexOf(str);
indexs[1] = originStr.indexOf("&", indexs[0]) >= 0 ? originStr.indexOf("&", indexs[0]) : originStr.length();
LogUtils.d("index0: " + indexs[0] + " index1: " + indexs[1]);
return indexs;
}
private boolean isNeedCache(String url) {
//这里可以根据Url来判断是否需要缓存
return true;
}
private Response combineCacheToResponse(String cache) {
String[] caches = cache.split("&#&#");
if (caches == null || caches.length <= 0) {
return null;
}
Request request = new Request.Builder()
.url(caches[REQUEST_URL])
.method(caches[REQUEST_METHOD], null)
.build();
Response.Builder builder = new Response.Builder();
try {
builder.protocol(Protocol.get(caches[PROTOCAL]));
} catch (IOException e) {
e.printStackTrace();
}
return builder.message(caches[MESSAGE])
.code(Integer.valueOf(caches[CODE]))
.request(request)
.receivedResponseAtMillis(Long.valueOf(caches[RECEIVE_REPONSE_AT_MILLIS]))
.sentRequestAtMillis(Long.valueOf(caches[SETN_REQUEST_AT_MILLIS]))
.body(ResponseBody.create(MediaType.parse(caches[MEDIA_TYPE]), caches[REPONSE_BODY]))
.build();
}
private String createCache(Response response) {
String[] caches = new String[CACHE_LENGTH];
caches[REQUEST_URL] = response.request().url().toString();
caches[REQUEST_METHOD] = response.request().method();
if (response.request().body() != null && response.request().body().contentType() != null) {
caches[REQUESTCONTENTTYPE] = response.request().body().contentType().toString();
} else {
caches[REQUESTCONTENTTYPE] = "application/x-www-form-urlencoded";
}
caches[PROTOCAL] = response.protocol().toString();
caches[CODE] = response.code() + "";
caches[MESSAGE] = response.message();
if (response.body() != null && response.body().contentType() != null) {
caches[MEDIA_TYPE] = response.body().contentType().toString();
} else {
caches[MEDIA_TYPE] = "application/x-www-form-urlencoded";
}
caches[SETN_REQUEST_AT_MILLIS] = response.sentRequestAtMillis() + "";
caches[RECEIVE_REPONSE_AT_MILLIS] = response.receivedResponseAtMillis() + "";
if (HttpHeaders.hasBody(response)) {
BufferedSource source = response.body().source();
Buffer buffer = null;
try {
source.request(Long.MAX_VALUE);
buffer = source.buffer();
Charset charset = response.body().contentType().charset();
if (charset == null) {
charset = Charset.forName("UTF-8");
}
caches[REPONSE_BODY] = buffer.clone().readString(charset);
} catch (IOException e) {
e.printStackTrace();
}finally {
// closeQuietly(response.body());
}
}
String cache = "";
for (String str : caches) {
cache += str + "&#&#";
}
return cache;
}
static boolean isEndToEnd(String fieldName) {
return !"Connection".equalsIgnoreCase(fieldName)
&& !"Keep-Alive".equalsIgnoreCase(fieldName)
&& !"Proxy-Authenticate".equalsIgnoreCase(fieldName)
&& !"Proxy-Authorization".equalsIgnoreCase(fieldName)
&& !"TE".equalsIgnoreCase(fieldName)
&& !"Trailers".equalsIgnoreCase(fieldName)
&& !"Transfer-Encoding".equalsIgnoreCase(fieldName)
&& !"Upgrade".equalsIgnoreCase(fieldName);
}
private String subString(String str, int[] index) {
if (index == null || index.length < 2) {
return null;
}
if (index[0] < 0 || index[1] < 0) {
return null;
}
return str.substring(index[0], index[1]);
}
}

View File

@@ -0,0 +1,55 @@
package com.aoleyun.sn.network.interceptor;
import android.util.Log;
import com.aoleyun.sn.utils.MD5Util;
import org.jetbrains.annotations.NotNull;
import java.io.IOException;
import java.util.concurrent.ConcurrentHashMap;
import okhttp3.Interceptor;
import okhttp3.Protocol;
import okhttp3.Request;
import okhttp3.Response;
public class RepeatRequestInterceptor implements Interceptor {
private static final String TAG = RepeatRequestInterceptor.class.getSimpleName();
private final ConcurrentHashMap<String, Long> requestIdsMap = new ConcurrentHashMap<>();
public static final String REPEAT_REQUEST_PROTOCOL = "OKHTTP_REPEAT_REQUEST_PROTOCOL";
@NotNull
@Override
public Response intercept(@NotNull Chain chain) throws IOException {
Request request = chain.request();
//相同的请求
String requestKey = MD5Util.getUpperMD5Str(request.method() + request.url().toString() + request.body());
long time = System.currentTimeMillis();//请求时间
try {
if (requestIdsMap.size() > 0 && requestIdsMap.containsKey(requestKey)) {
Log.e("REPEAT-REQUEST", "重复请求:" + requestKey + " Method @" + request.method() + " --- " + " URL = " + request.url() + "\t" + request.body());
//下面这行写了不会抛出onerror
// chain.call().cancel();
return new Response.Builder()
.protocol(Protocol.get(REPEAT_REQUEST_PROTOCOL))
.request(request) //multi thread
.build();
}
requestIdsMap.put(requestKey, time);
Log.e("REPEAT-REQUEST", "注册请求:" + requestKey + " Method @" + request.method() + " --- " + " URL = " + request.url() + "\t" + request.body());
// RepeatRequestInterceptor.Builder builder = request.newBuilder();
// builder.addHeader("header", jsonObject.toString());
return chain.proceed(request);
} catch (IOException e) {
Log.e(TAG, "intercept: " + e.getMessage());
throw e;
} finally {
if (requestIdsMap.containsKey(requestKey) && requestIdsMap.containsValue(time)) {//请求任务完成删除map中的数据
requestIdsMap.remove(requestKey);
Log.e("REPEAT-REQUEST", "移除请求:" + requestKey + " Method @" + request.method() + " --- " + " URL = " + request.url() + "\t" + request.body());
}
}
}
}

View File

@@ -3,18 +3,18 @@ package com.aoleyun.sn.receiver;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.SystemClock;
import android.util.Log;
import com.aoleyun.sn.activity.checknet.CheckNetActivity;
import com.aoleyun.sn.comm.CommonConfig;
import com.aoleyun.sn.manager.ConnectManager;
import com.aoleyun.sn.rlog.LogDBManager;
import com.aoleyun.sn.service.main.MainService;
import com.aoleyun.sn.utils.BootManager;
import com.aoleyun.sn.utils.JGYUtils;
import com.aoleyun.sn.utils.SPUtils;
import com.aoleyun.sn.utils.TimeUtils;
import com.aoleyun.sn.utils.Utils;
import com.tencent.mmkv.MMKV;
import java.util.concurrent.TimeUnit;
@@ -76,6 +76,7 @@ public class BootReceiver extends BroadcastReceiver {
default:
break;
case Intent.ACTION_BOOT_COMPLETED:
MMKV.defaultMMKV().encode(ConnectManager.REBOOT_LAST_ONNECT_TIME, System.currentTimeMillis());
if ((int) SPUtils.get(context, CommonConfig.FIRST_STARTUP, 0) == 0) {
LogDBManager.getInstance().creatRebootLog("首次启动", TimeUtils.transferLongToDate(System.currentTimeMillis()));
SPUtils.put(context, CommonConfig.FIRST_STARTUP, 1);
@@ -90,7 +91,6 @@ public class BootReceiver extends BroadcastReceiver {
break;
case BOOT_COMPLETED:
new BootManager(context).start();
// start.onstar(SystemClock.elapsedRealtime());
case Intent.ACTION_BATTERY_CHANGED:
case Intent.ACTION_BATTERY_LOW:
case Intent.ACTION_BATTERY_OKAY:

View File

@@ -55,7 +55,7 @@ public class NewAppReceiver extends BroadcastReceiver {
state = "安装了:";
break;
case Intent.ACTION_PACKAGE_REPLACED:
cleanLauncher3Cache();
JGYUtils.getInstance().cleanLauncher3Cache();
state = "重装了:";
break;
case Intent.ACTION_PACKAGE_REMOVED:
@@ -77,15 +77,6 @@ public class NewAppReceiver extends BroadcastReceiver {
newAppListener.setNewAppListener(packageName);
}
private void cleanLauncher3Cache() {
try {
new CacheUtils().cleanApplicationUserData(mContext, "com.android.launcher3");
} catch (Exception e) {
Log.e(TAG, "onReceive: " + e.getMessage());
e.printStackTrace();
}
}
public interface NewAppListener {
void setNewAppListener(String packageName);
}
@@ -127,10 +118,6 @@ public class NewAppReceiver extends BroadcastReceiver {
}
});
//HTTPInterface.getNetAndLaunchSetting(mContext);
HTTPInterface.getAppLimit(mContext);
// HTTPInterface.getAppinsideWeb(mContext, () -> Log.e(TAG, "onNext: setAPPinsideWebsite"));
String oldDesktop = (String) SPUtils.get(mContext, "default_launcher", "");
if (s.equals(oldDesktop)) {
ApkUtils.openPackage(mContext, s);

View File

@@ -29,7 +29,7 @@ import com.aoleyun.sn.comm.CommonConfig;
import com.aoleyun.sn.comm.PackageNames;
import com.aoleyun.sn.manager.AmapManager;
import com.aoleyun.sn.network.NetInterfaceManager;
import com.aoleyun.sn.network.api.SendScreenStatusApi;
import com.aoleyun.sn.network.api.post.SendScreenStatusApi;
import com.aoleyun.sn.receiver.BootReceiver;
import com.aoleyun.sn.receiver.NewAppReceiver;
import com.aoleyun.sn.rlog.LogDBManager;

View File

@@ -19,7 +19,7 @@ public class MainSContact {
/*是否第一次联网*/
void getFirstConnect();
/*获取学生信息*/
void getStudesInfo();
void getStudesInfo(boolean refresh);
/*分支3 上传信息*/
/*发送mac地址*/
@@ -31,15 +31,8 @@ public class MainSContact {
/*分支4 获取应用*/
/*获取设备信息更新*/
void checkInfoUpdate();
/*获取应用市场更新*/
void checkStoreUpdate();
/*获取桌面升级*/
void checkDesktopUpdate();
/*获取通知升级*/
void checkNotifyUpdate();
/*获取浏览器升级*/
void checkBrowserUpdate();
void checkAoleyunUpdate();
/*获取测试应用更新*/
void checkTestUpdate();
/*获取强制下载apk*/
@@ -111,15 +104,8 @@ public class MainSContact {
void sendInstalledFinish();
/*获取设备信息更新*/
void checkInfoUpdateFinish();
/*获取应用市场更新*/
void checkStoreUpdateFinish();
/*获取桌面升级*/
void checkDesktopUpdateFinish();
/*获取通知升级*/
void checkNotifyUpdateFinish();
/*获取浏览器升级*/
void checkBrowserUpdateFinish();
void checkAoleyunUpdateFinish();
/*获取测试应用更新*/
void checkTestUpdateFinish();
/*获取强制下载apk结束*/

View File

@@ -36,7 +36,6 @@ import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.aoleyun.sn.BuildConfig;
import com.aoleyun.sn.R;
import com.aoleyun.sn.activity.SplashActivity;
import com.aoleyun.sn.activity.checknet.CheckNetActivity;
import com.aoleyun.sn.activity.main.MainAPresenter;
import com.aoleyun.sn.bean.BaseResponse;
@@ -119,7 +118,7 @@ public class MainService extends Service implements MainSContact.MainView, Netwo
}
}
if (!checkAoleyunApp()) {
mPresenter.checkInfoUpdate();
mPresenter.checkAoleyunUpdate();
}
TimeTask task = new TimeTask();
task.execute("ntp.aliyun.com");
@@ -189,11 +188,8 @@ public class MainService extends Service implements MainSContact.MainView, Netwo
Log.e("TPush", "注册失败,错误码:" + errCode + ",错误信息:" + msg);
}
});
}
private final BehaviorSubject<ActivityEvent> lifecycleSubject = BehaviorSubject.create();
@Override
@@ -303,6 +299,9 @@ public class MainService extends Service implements MainSContact.MainView, Netwo
@Override
public void onNext(String string) {
connectKey = string;
if (!connectKey.equals(ConnectManager.REBOOT_LAST_ONNECT_TIME)) {
mMMKV.encode(connectKey, System.currentTimeMillis());
}
Log.e("timeObserver", "onNext: " + string);
mPresenter.getLockedState(string);
}
@@ -339,6 +338,7 @@ public class MainService extends Service implements MainSContact.MainView, Netwo
TimeTask task = new TimeTask();
task.execute("ntp.aliyun.com");
//根据要求卸载这两个应用
ApkUtils.UninstallAPP(this, "com.joytv.live");
ApkUtils.UninstallAPP(this, "com.tencent.android.qqdownloader");
@@ -370,9 +370,9 @@ public class MainService extends Service implements MainSContact.MainView, Netwo
e.printStackTrace();
}
} else {
// if (ConnectManager.getInstance().isRebootFistConnect()) {
start.onstar(ConnectManager.REBOOT_LAST_ONNECT_TIME);
// }
if (ConnectManager.getInstance().isRebootFistConnect()) {
start.onstar(ConnectManager.REBOOT_LAST_ONNECT_TIME);
}
}
SPUtils.put(this, CommonConfig.SN_VERSIONCODE, BuildConfig.VERSION_CODE);
registerReceivers();
@@ -389,7 +389,7 @@ public class MainService extends Service implements MainSContact.MainView, Netwo
public int onStartCommand(Intent intent, int flags, int startId) {
JGYUtils.getInstance().wakeUpAppstore();
if (!checkAoleyunApp()) {
mPresenter.checkInfoUpdate();
mPresenter.checkAoleyunUpdate();
}
return START_STICKY;
}
@@ -397,12 +397,13 @@ public class MainService extends Service implements MainSContact.MainView, Netwo
@Override
public void onDestroy() {
super.onDestroy();
lifecycleSubject.onNext(ActivityEvent.DESTROY);
unRegisterReceivers();
NetworkUtils.unregisterNetworkStatusChangedListener(this);
lifecycleSubject.onNext(ActivityEvent.DESTROY);
mPresenter.detachView();
}
// TODO: 2022/3/31 暂时不检测版本
private boolean checkAoleyunApp() {
if (!ApkUtils.isAvailable(this, PackageNames.APPSTORE)) return false;
if (!ApkUtils.isAvailable(this, PackageNames.DESKTOP)) return false;
@@ -856,7 +857,7 @@ public class MainService extends Service implements MainSContact.MainView, Netwo
} else {
}
mPresenter.getStudesInfo();
mPresenter.getStudesInfo(true);
}
@Override
@@ -865,7 +866,6 @@ public class MainService extends Service implements MainSContact.MainView, Netwo
mPresenter.sendMACAddress();
}
@Override
public void sendMACFinish() {
mPresenter.updateDeviceInfo();
@@ -879,32 +879,11 @@ public class MainService extends Service implements MainSContact.MainView, Netwo
@Override
public void sendInstalledFinish() {
Log.e(TAG, "sendInstalledFinish: ");
mPresenter.checkInfoUpdate();
}
@Override
public void checkInfoUpdateFinish() {
mPresenter.checkStoreUpdate();
mPresenter.checkAoleyunUpdate();
}
@Override
public void checkStoreUpdateFinish() {
mPresenter.checkDesktopUpdate();
}
@Override
public void checkDesktopUpdateFinish() {
mPresenter.checkNotifyUpdate();
}
@Override
public void checkNotifyUpdateFinish() {
mPresenter.checkBrowserUpdate();
}
@Override
public void checkBrowserUpdateFinish() {
public void checkAoleyunUpdateFinish() {
mPresenter.checkTestUpdate();
}
@@ -928,7 +907,6 @@ public class MainService extends Service implements MainSContact.MainView, Netwo
Log.e(TAG, "setLogoImgFinish: ");
}
@Override
public void getDeveloperFinish() {
mPresenter.getSystemSettingBegin();
@@ -1011,7 +989,6 @@ public class MainService extends Service implements MainSContact.MainView, Netwo
@Override
public void setWiFiPasswd() {
mMMKV.encode(MainAPresenter.GET_SETTING_FINISH_TIME, System.currentTimeMillis());
mPresenter.getScreenLockState();
}
@@ -1033,6 +1010,4 @@ public class MainService extends Service implements MainSContact.MainView, Netwo
SPUtils.put(this, "screen_tips", "");
}
}
}

View File

@@ -27,13 +27,10 @@ import com.aoleyun.sn.R;
import com.aoleyun.sn.base.BaseApplication;
import com.aoleyun.sn.bean.BaseResponse;
import com.aoleyun.sn.bean.RemoteDebug;
import com.aoleyun.sn.bean.SnRunLog;
import com.aoleyun.sn.comm.CommonConfig;
import com.aoleyun.sn.comm.JGYActions;
import com.aoleyun.sn.manager.AmapManager;
import com.aoleyun.sn.network.HTTPInterface;
import com.aoleyun.sn.network.NetInterfaceManager;
import com.aoleyun.sn.rlog.LogDBManager;
import com.aoleyun.sn.service.main.MainService;
import com.aoleyun.sn.tpush.common.NotificationService;
import com.aoleyun.sn.tpush.po.XGNotification;
@@ -124,7 +121,7 @@ public class MessageReceiver extends XGPushBaseReceiver {
private final String HIDE_DESKTOP_ICON = "18";
/*禁止滑动*/
private final String DISABLE_APP_SLIDE = "19";
/*更新用白名单*/
/*更新用白名单*/
private final String UPDATE_INFO = "20";
/*截图*/
private final String SN_SCREENSHOT = "21";
@@ -462,8 +459,7 @@ public class MessageReceiver extends XGPushBaseReceiver {
SaveListUtils.sendForceAPP(mContext);
ApkUtils.UninstallAPP(mContext, pkg);
}
HTTPInterface.getAppLimit(mContext);
HTTPInterface.getNetAndLaunchSetting(mContext);
NetInterfaceManager.getInstance().getNetAndLaunchSetting();
break;
case MSG_SETTING:
ToastUtil.betaShow("收到管控:系统设置");
@@ -493,9 +489,8 @@ public class MessageReceiver extends XGPushBaseReceiver {
break;
case MSG_INSTALL:
ToastUtil.betaShow("收到管控:应用安装");
HTTPInterface.getAppLimit(mContext);
doDownloadAndInstall(extras);
HTTPInterface.setHideDesktopIcon(mContext);
NetInterfaceManager.getInstance().setHideDesktopIcon();
break;
case MSG_LOCK:
ToastUtil.betaShow("收到管控:设备锁定");
@@ -569,7 +564,7 @@ public class MessageReceiver extends XGPushBaseReceiver {
Handler.getMain().postDelayed(() -> {
//后台发送时数据库未改变,有时候可能获取到的数据时上一次的
Log.e(TAG, "run: HIDE_DESKTOP_ICON ");
HTTPInterface.setHideDesktopIcon(mContext);
NetInterfaceManager.getInstance().setHideDesktopIcon();
}, 2000);
break;
case DISABLE_APP_SLIDE:
@@ -578,7 +573,7 @@ public class MessageReceiver extends XGPushBaseReceiver {
break;
case UPDATE_INFO:
ToastUtil.betaShow("收到管控:更新白名单");
HTTPInterface.getAppLimit(mContext);
NetInterfaceManager.getInstance().getAppLimit();
break;
case SN_SCREENSHOT:
ToastUtil.betaShow("收到管控:设备截图");
@@ -701,7 +696,7 @@ public class MessageReceiver extends XGPushBaseReceiver {
break;
case UPDATE_WHITELIST:
ToastUtil.betaShow("收到管控:更新白名单");
HTTPInterface.getAppLimit(mContext);
NetInterfaceManager.getInstance().getAppLimit();
break;
case UPDATE_BATCH:
ToastUtil.betaShow("收到管控:更换批次不恢复出厂设置");
@@ -720,10 +715,10 @@ public class MessageReceiver extends XGPushBaseReceiver {
}
break;
case UPDATE_WIFI_PW:
HTTPInterface.getWiFiPasswd();
NetInterfaceManager.getInstance().getWiFiPasswd();
break;
case DEVICES_POWEROFF:
HTTPInterface.getPoweroffTime();
NetInterfaceManager.getInstance().getPoweroffTime();
break;
case SN_RUN_LOG:
recordLog(extras);
@@ -817,7 +812,7 @@ public class MessageReceiver extends XGPushBaseReceiver {
}
private void getDeselectBrowerID() {
HTTPInterface.setBrowserBlackList(mContext);//浏览器网址管控
NetInterfaceManager.getInstance().setBrowserBlackList();//浏览器网址管控
}
private void getDeselectID() {
@@ -890,7 +885,6 @@ public class MessageReceiver extends XGPushBaseReceiver {
String[] banList = ban.split(",");
String[] notList = not.split(",");
boolean b = Utils.writeDisableUpdateList(mContext, banList, notList);
HTTPInterface.getAppLimit(mContext);
}
private void settingCamera(String s) {
@@ -966,12 +960,32 @@ public class MessageReceiver extends XGPushBaseReceiver {
}
private void setHomepagtag() {
HTTPInterface.getHomePageBookmarks(mContext, null);
NetInterfaceManager.getInstance().getHomePageBookmarks(new NetInterfaceManager.BookmarksCallback() {
@Override
public void onSubscribe() {
}
@Override
public void onNext() {
}
@Override
public void onError(Throwable e) {
}
@Override
public void onComplete() {
}
});
}
private void setAPPinsideWebsite(String s) {
//禁止app内部网页访问包名用,隔开
HTTPInterface.getAppinsideWeb(mContext, new HTTPInterface.GetAppinsideWebCallback() {
NetInterfaceManager.getInstance().getAppinsideWeb(new NetInterfaceManager.GetAppinsideWebCallback() {
@Override
public void onComplete() {
Log.e(TAG, "ononComplete: setAPPinsideWebsite");
@@ -1096,7 +1110,7 @@ public class MessageReceiver extends XGPushBaseReceiver {
}
private void getTimeControl(String extras) {
HTTPInterface.getSnTimeControl(mContext);
NetInterfaceManager.getInstance().getSnTimeControl();
}
private void getTopApp(String extras) {
@@ -1280,7 +1294,7 @@ public class MessageReceiver extends XGPushBaseReceiver {
}
private void recordLog(String jsonString) {
HTTPInterface.getRunLog(mContext);
NetInterfaceManager.getInstance().getRunLog();
}
private static final int ACTION_PULL = 1;
@@ -1306,7 +1320,7 @@ public class MessageReceiver extends XGPushBaseReceiver {
break;
case ACTION_UPGRADE:
Log.e(TAG, "customOrder: 更新");
HTTPInterface.getForceDownload(mContext);
NetInterfaceManager.getInstance().getForceDownload();
break;
default:
break;

View File

@@ -589,7 +589,6 @@ public class ApkUtils {
Log.e("UninstallAPP", "onComplete: ");
}
});
}

View File

@@ -1,149 +0,0 @@
package com.aoleyun.sn.utils;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.pm.ResolveInfo;
import com.aoleyun.sn.bean.AppUpdateInfo;
import com.aoleyun.sn.bean.LocalAppInfo;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
public class AppsManagerUtils {
public static AppUpdateInfo getUpAppsByPackageName(Context context, String packageName) {
PackageManager pm = context.getPackageManager();
AppUpdateInfo appInfo = new AppUpdateInfo();
try {
PackageInfo packinfo = pm.getPackageInfo(packageName, 0);
appInfo.setPackageName(packageName);
appInfo.setVersion(packinfo.versionName);
if (packinfo.versionName == null || packinfo.versionName.equals("")) {
appInfo.setVersion(packinfo.versionCode + "");
}
} catch (NameNotFoundException e) {
e.printStackTrace();
}
return appInfo;
}
public static LocalAppInfo getAppsByPackageName(Context context, String packageName) {
PackageManager pm = context.getPackageManager();
List<LocalAppInfo> appInfos = new ArrayList<LocalAppInfo>();
Intent intent = new Intent(Intent.ACTION_MAIN, null);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
// 通过查询获得所有ResolveInfo对象.
List<ResolveInfo> infos = pm.queryIntentActivities(intent, 0);
for (ResolveInfo info : infos) {
// 不列出系统应用
String pkg = info.activityInfo.packageName;
if (pkg.equals(packageName)) {
extractedAppInfo(pm, appInfos, info);
}
}
return appInfos.size() == 0 ? null : appInfos.get(0);
}
public static List<AppUpdateInfo> getUpadteApps(Context context) {
PackageManager pm = context.getPackageManager();
List<AppUpdateInfo> appInfos = new ArrayList<AppUpdateInfo>();
Intent intent = new Intent(Intent.ACTION_MAIN, null);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
// 通过查询获得所有ResolveInfo对象.
List<ResolveInfo> infos = pm.queryIntentActivities(intent, 0);
for (ResolveInfo info : infos) {
// 不列出系统应用
String pkg = info.activityInfo.packageName;
if (!isSystemApp(context, pkg)) {
PackageInfo packageInfo = null;
AppUpdateInfo appInfo = new AppUpdateInfo();
appInfo.setPackageName(info.activityInfo.packageName);
try {
packageInfo = pm.getPackageInfo(info.activityInfo.packageName, 0);
appInfo.setVersion(packageInfo.versionName);
if (packageInfo.versionName == null || packageInfo.versionName.equals("")) {
appInfo.setVersion(packageInfo.versionCode + "");
}
} catch (NameNotFoundException e) {
e.printStackTrace();
}
appInfos.add(appInfo);
}
}
return appInfos;
}
public static List<LocalAppInfo> getUserApps(Context context) {
PackageManager pm = context.getPackageManager();
List<LocalAppInfo> appInfos = new ArrayList<LocalAppInfo>();
Intent intent = new Intent(Intent.ACTION_MAIN, null);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
// 通过查询获得所有ResolveInfo对象.
List<ResolveInfo> infos = pm.queryIntentActivities(intent, 0);
for (ResolveInfo info : infos) {
// 不列出系统应用
String pkg = info.activityInfo.packageName;
if (!isSystemApp(context, pkg)) {
extractedAppInfo(pm, appInfos, info);
}
}
return appInfos;
}
private static void extractedAppInfo(PackageManager pm,
List<LocalAppInfo> appInfos, ResolveInfo info) {
PackageInfo packageInfo = null;
LocalAppInfo appInfo = new LocalAppInfo();
appInfo.setIcon(info.activityInfo.loadIcon(pm));
appInfo.setAppName(info.activityInfo.loadLabel(pm).toString());
appInfo.setPackageName(info.activityInfo.packageName);
try {
packageInfo = pm.getPackageInfo(info.activityInfo.packageName, 0);
appInfo.setVersion(packageInfo.versionName);
if (packageInfo.versionName == null || packageInfo.versionName.equals("")) {
appInfo.setVersion(packageInfo.versionCode + "");
}
String appInstallDir = info.activityInfo.applicationInfo.publicSourceDir;
int size = Integer.valueOf((int) new File(appInstallDir).length());
appInfo.setSize(size);
} catch (NameNotFoundException e) {
e.printStackTrace();
}
appInfos.add(appInfo);
}
public static boolean isSystemApp(Context context, String pkg) {
try {
PackageInfo packageInfo = context.getPackageManager().getPackageInfo(pkg, 0);
int mask = ApplicationInfo.FLAG_SYSTEM | ApplicationInfo.FLAG_UPDATED_SYSTEM_APP;
if ((packageInfo.applicationInfo.flags & mask) == 0) {
if (pkg.equals(context.getPackageName())) {
return true;
} else {
//第三方应用
return false;
}
} else {
//系统应用
return true;
}
} catch (NameNotFoundException e) {
e.printStackTrace();
return true;
}
}
}

View File

@@ -132,5 +132,7 @@ public class CacheUtils {
}
}
}

View File

@@ -0,0 +1,30 @@
package com.aoleyun.sn.utils;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.google.gson.reflect.TypeToken;
import java.io.Serializable;
import java.lang.reflect.Type;
import static com.google.gson.JsonParser.parseString;
public class GsonUtils {
public static JsonObject getJsonObject(String jsonString) {
JsonObject jsonObject = parseString(new Gson().toJson(jsonString)).getAsJsonObject();
return jsonObject;
}
// TODO: 2022/3/31 暂时没有实现
public static <E> E getJsonFromType(String jsonString) {
Gson gson = new Gson();
Type Type = new TypeToken<E>() {
}.getType();
E e = gson.fromJson(jsonString, Type);
return e;
}
public static String toJsonString(Object o) {
return new Gson().toJson(o);
}
}

View File

@@ -1058,7 +1058,7 @@ public class JGYUtils {
if (packageInfo == null || packageInfo.versionCode < versionCode) {
Utils.ariaDownload(mContext, url, object);
} else {
Log.e("installAPK", "已是最新版本");
Log.e("installAPK", app_name + ": 已是最新版本");
}
}
@@ -1584,17 +1584,17 @@ public class JGYUtils {
}
public interface GetAppPlatformCallback {
void AppPlatform(int platform);
void getAppPlatform(int platform);
}
public void getAppPlatform(GetAppPlatformCallback getAppPlatformCallback) {
String platform = BuildConfig.platform;
if ("MTK".equalsIgnoreCase(platform)) {
getAppPlatformCallback.AppPlatform(MTKPlatform);
getAppPlatformCallback.getAppPlatform(MTKPlatform);
} else if ("ZhanRui".equalsIgnoreCase(platform)) {
getAppPlatformCallback.AppPlatform(ZhanruiPlatform);
getAppPlatformCallback.getAppPlatform(ZhanruiPlatform);
} else {
getAppPlatformCallback.AppPlatform(UnknowPlatform);
getAppPlatformCallback.getAppPlatform(UnknowPlatform);
}
}
@@ -1960,4 +1960,41 @@ public class JGYUtils {
bootIntent.setComponent(new ComponentName(PACKAGE_APPSTORE, CLASS_APPSTORE));
mContext.sendBroadcast(bootIntent);
}
/**
* 判断网络连接状态
*
* @return true网络已链接 false网络已断开连接
*/
public boolean isNetworkConnected() {
if (mContext != null) {
ConnectivityManager mConnectivityManager = (ConnectivityManager) mContext
.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo mNetworkInfo = mConnectivityManager
.getActiveNetworkInfo();
if (mNetworkInfo != null) {
return mNetworkInfo.isAvailable();
}
}
return false;
}
public void cleanLauncher3Cache() {
try {
new CacheUtils().cleanApplicationUserData(mContext, "com.android.launcher3");
} catch (Exception e) {
Log.e(TAG, "onReceive: " + e.getMessage());
e.printStackTrace();
}
}
public void cleanAoleLauncher3Cache() {
try {
new CacheUtils().cleanApplicationUserData(mContext, "com.aoleyun.os");
} catch (Exception e) {
Log.e(TAG, "onReceive: " + e.getMessage());
e.printStackTrace();
}
}
}

View File

@@ -54,6 +54,7 @@ import com.aoleyun.sn.R;
import com.aoleyun.sn.base.BaseApplication;
import com.aoleyun.sn.comm.CommonConfig;
import com.aoleyun.sn.network.HTTPInterface;
import com.aoleyun.sn.network.NetInterfaceManager;
import com.arialyy.aria.core.Aria;
import com.blankj.utilcode.util.FileUtils;
import com.google.zxing.BarcodeFormat;
@@ -424,8 +425,8 @@ public class Utils {
// 卸载app
public static void unInstallAPP(Context context, String packageName) {
if (!TextUtils.isEmpty(packageName) && !AppsManagerUtils.isSystemApp(context, packageName)) {
if (AppsManagerUtils.isSystemApp(context, packageName)) {
if (!TextUtils.isEmpty(packageName) && !ApkUtils.isSystemApp(context, packageName)) {
if (ApkUtils.isSystemApp(context, packageName)) {
Toast.makeText(BaseApplication.getAppContext(), R.string.system_unistall_error, Toast.LENGTH_SHORT).show();
} else {
Uri packageURI = Uri.parse("package:" + packageName);
@@ -1546,7 +1547,7 @@ public class Utils {
* @param context
*/
public static void getPublicIP(Context context) {
HTTPInterface.getPublicIP(context, new HTTPInterface.PublicIP() {
NetInterfaceManager.getPublicIP(context, new NetInterfaceManager.PublicIP() {
@Override
public void set(String ip) {
SPUtils.put(context, "PublicIP", ip);

View File

@@ -20,7 +20,7 @@
android:id="@+id/back"
android:layout_width="@dimen/dp_16"
android:layout_height="@dimen/dp_16"
android:layout_marginLeft="@dimen/dp_8"
android:layout_marginLeft="@dimen/dp_16"
android:adjustViewBounds="true"
android:scaleType="centerCrop"
android:src="@drawable/back"

View File

@@ -21,7 +21,7 @@
android:id="@+id/back"
android:layout_width="@dimen/dp_16"
android:layout_height="@dimen/dp_16"
android:layout_marginLeft="@dimen/dp_8"
android:layout_marginLeft="@dimen/dp_16"
android:adjustViewBounds="true"
android:scaleType="centerCrop"
android:src="@drawable/back"

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.2 KiB

After

Width:  |  Height:  |  Size: 5.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.2 KiB

After

Width:  |  Height:  |  Size: 5.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.2 KiB

After

Width:  |  Height:  |  Size: 5.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.2 KiB

After

Width:  |  Height:  |  Size: 5.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.2 KiB

After

Width:  |  Height:  |  Size: 5.3 KiB

View File

@@ -2,46 +2,7 @@
<resources xmlns:tools="http://schemas.android.com/tools" xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
<string name="app_name">我的设备</string>
<string name="txt_parent_1">账户管理</string>
<string name="txt_parent_2">护眼设置</string>
<string name="txt_parent_3">学习日志</string>
<string name="txt_parent_4">系统切换</string>
<string name="txt_parent_5">系统升级</string>
<string name="txt_parent_6">充电保护</string>
<string name="txt_parent_7">系统设置</string>
<string name="txt_parent_8">家长信箱</string>
<string name="txt_parent_9">家长应用</string>
<string name="editview_input">0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ</string>
<string name="time_control_use" tools:ignore="UnusedResources">每天可使用时间</string>
<!-- search -->
<string name="search_edit">请输入应用名称或关键字</string>
<string name="search_history">搜索历史</string>
<!-- top page -->
<string name="app_detail_introduction">详细介绍</string>
<string name="app_detail_comments">评论</string>
<string name="app_detail_recommend">相关推荐</string>
<string name="give_comments">添加一个评论</string>
<string name="anonymity_text">匿名</string>
<string name="comments_btn_text">评论</string>
<!-- app manage -->
<string name="view_holder">1</string>
<string name="open_text">打开</string>
<string name="update_text">更新</string>
<string name="download_btn_update">更新</string>
<string name="download_start_text">下载</string>
<string name="download_continue_text">继续</string>
<string name="download_paused_text">暂停</string>
<string name="download_install_text">安装中</string>
<string name="download_install_wait">待安装</string>
<string name="download_wait_text">排队中</string>
<string name="default_info">暂无信息</string>
<string name="unistall_error">卸载失败!</string>
<string name="system_unistall_error">系统应用无法卸载!</string>
@@ -51,6 +12,7 @@
<string name="txt_parent_10">退出系统</string>
<string name="update_info_0">当前版本号:</string>
<string name="time_control_rest_long" tools:ignore="UnusedResources">each rest how long</string>
@@ -58,31 +20,16 @@
<string name="bb_love_game" tools:ignore="UnusedResources">宝宝爱游戏</string>
<string name="total_time" tools:ignore="UnusedResources">使用总时长</string>
<string name="use_times" tools:ignore="UnusedResources">使用次数</string>
<!-- app store -->
<string name="zh_account">未登录</string>
<string name="zg_password" tools:ignore="UnusedResources">密\t码:</string>
<string name="zg_name_note">宝宝昵称</string>
<string name="image_null">null</string>
<string name="download_delect_text">删除</string>
<string name="app_update_time_text_format"><xliff:g id="date">%1$s</xliff:g> 次下载</string>
<string name="app_detail_comments_text_format">评论<xliff:g id="num">%1$s</xliff:g></string>
<string name="app_comment_time_format">"yyyy年MM月dd日"</string>
<string name="comment_content_empty">请填写评论内容!</string>
<string name="comment_star_empty">请填写星级!</string>
<string name="cleaned">清理垃圾 (<xliff:g id="memory">%1$s</xliff:g>)</string>
<string name="sample_device_admin">为亲子互动提供锁屏功能,请务必激活</string>
@@ -99,6 +46,7 @@
<string name="about_copyright">深圳市七彩宏云智能设备有限公司版权所有\n
www.jiaoguanyi.com\n
粤ICP备17133107号</string>
<string-array name="packageName">
<item>http://p18.qhimg.com/dr/72__/t0111cb71dabfd83b21.png</item>
<item>http://p18.qhimg.com/dr/72__/t01a16bcd9acd07d029.png</item>