version:1.9
fix: add:接口缓存
This commit is contained in:
@@ -1,10 +1,7 @@
|
||||
package com.uiui.sn.activity.main;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.provider.Settings;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
@@ -12,18 +9,14 @@ import com.alibaba.fastjson.JSONObject;
|
||||
import com.trello.rxlifecycle4.RxLifecycle;
|
||||
import com.trello.rxlifecycle4.android.ActivityEvent;
|
||||
import com.uiui.sn.bean.AppInfo;
|
||||
import com.uiui.sn.bean.AppletQRCode;
|
||||
import com.uiui.sn.bean.BaseResponse;
|
||||
import com.uiui.sn.bean.SnInfo;
|
||||
import com.uiui.sn.config.CommonConfig;
|
||||
import com.uiui.sn.network.HTTPInterface;
|
||||
import com.uiui.sn.network.NetInterfaceManager;
|
||||
import com.uiui.sn.utils.ApkUtils;
|
||||
import com.uiui.sn.utils.CXAESUtil;
|
||||
import com.uiui.sn.utils.JGYUtils;
|
||||
import com.uiui.sn.utils.SPUtils;
|
||||
import com.uiui.sn.utils.Utils;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
||||
import io.reactivex.rxjava3.core.Observer;
|
||||
@@ -66,7 +59,7 @@ public class MainAPresenter implements MainAContact.Presenter {
|
||||
@Override
|
||||
public void getSnInfo() {
|
||||
NetInterfaceManager.getInstance()
|
||||
.getSnInfo(lifecycle, new NetInterfaceManager.ObserverCallback() {
|
||||
.getSnInfo(true, getLifecycle(), new NetInterfaceManager.ObserverCallback() {
|
||||
@Override
|
||||
public void onSubscribe(Disposable d) {
|
||||
|
||||
@@ -92,36 +85,15 @@ public class MainAPresenter implements MainAContact.Presenter {
|
||||
@Override
|
||||
public void getAppletQRCode() {
|
||||
NetInterfaceManager.getInstance()
|
||||
.getQRCodeApiControl()
|
||||
.compose(RxLifecycle.bindUntilEvent(lifecycle, ActivityEvent.DESTROY))
|
||||
.subscribe(new Observer<BaseResponse>() {
|
||||
.getQRCodeURL(true, getLifecycle(), new NetInterfaceManager.onNextCallback() {
|
||||
@Override
|
||||
public void onSubscribe(Disposable d) {
|
||||
Log.e("getAppletQRCode", "onSubscribe: ");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(BaseResponse baseResponse) {
|
||||
Log.e("getAppletQRCode", "onNext: ");
|
||||
if (baseResponse.code == 200) {
|
||||
JSONObject jsonObject = (JSONObject) JSON.toJSON(baseResponse.data);
|
||||
String url = jsonObject.getString("file");
|
||||
mView.setAppletQRCode(url);
|
||||
} else {
|
||||
mView.setAppletQRCode("");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
Log.e("getAppletQRCode", "onError: " + e.getMessage());
|
||||
mView.setAppletQRCode("");
|
||||
onComplete();
|
||||
public void onNext(Object o) {
|
||||
mView.setAppletQRCode((String) o);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
Log.e("getAppletQRCode", "onComplete: ");
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -143,7 +115,7 @@ public class MainAPresenter implements MainAContact.Presenter {
|
||||
public void getForceInstall() {
|
||||
NetInterfaceManager.getInstance()
|
||||
.getForceInstallControl()
|
||||
.compose(RxLifecycle.bindUntilEvent(lifecycle, ActivityEvent.DESTROY))
|
||||
.compose(RxLifecycle.bindUntilEvent(getLifecycle(), ActivityEvent.DESTROY))
|
||||
.subscribe(new Observer<BaseResponse<List<AppInfo>>>() {
|
||||
@Override
|
||||
public void onSubscribe(Disposable d) {
|
||||
@@ -157,7 +129,7 @@ public class MainAPresenter implements MainAContact.Presenter {
|
||||
if (code == 200) {
|
||||
List<AppInfo> appInfos = listBaseResponse.data;
|
||||
if (null != appInfos && appInfos.size() != 0) {
|
||||
HTTPInterface.getForceInstallState(mContext, appInfos);
|
||||
NetInterfaceManager.getInstance().getForceInstallState(appInfos);
|
||||
}
|
||||
} else {
|
||||
boolean qch_force_app = JGYUtils.putString(mContext.getContentResolver(), "qch_force_app", "invalid");
|
||||
|
||||
@@ -120,6 +120,9 @@ public class MainActivity extends BaseActivity implements MainAContact.MainView,
|
||||
}
|
||||
JGYUtils.getInstance().wakeUpAppstore();
|
||||
JGYUtils.getInstance().wakeUpUpdateTools();
|
||||
|
||||
Utils.getBattery(this);
|
||||
Utils.getBatterymAh(this);
|
||||
}
|
||||
|
||||
private TimeTask task;
|
||||
|
||||
@@ -20,7 +20,6 @@ import com.uiui.sn.manager.ControlPanelManager;
|
||||
import com.uiui.sn.network.NetInterfaceManager;
|
||||
import com.uiui.sn.manager.ControlManager;
|
||||
import com.uiui.sn.manager.DeviceManager;
|
||||
import com.uiui.sn.network.HTTPInterface;
|
||||
import com.uiui.sn.network.UrlAddress;
|
||||
import com.uiui.sn.rlog.LogDBManager;
|
||||
import com.uiui.sn.utils.AppUsedTimeUtils;
|
||||
|
||||
@@ -1,9 +1,15 @@
|
||||
package com.uiui.sn.bean;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonParser;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class AppInfo implements Serializable {
|
||||
private static final long serialVersionUID = 423463220624853188L;
|
||||
|
||||
private int app_id;
|
||||
private String app_name;
|
||||
private String app_package;
|
||||
@@ -220,4 +226,10 @@ public class AppInfo implements Serializable {
|
||||
public void setApp_md5(String app_md5) {
|
||||
this.app_md5 = app_md5;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public String toString() {
|
||||
return JsonParser.parseString(new Gson().toJson(this)).getAsJsonObject().toString();
|
||||
}
|
||||
}
|
||||
|
||||
16
app/src/main/java/com/uiui/sn/bean/AppletQRCode.java
Normal file
16
app/src/main/java/com/uiui/sn/bean/AppletQRCode.java
Normal file
@@ -0,0 +1,16 @@
|
||||
package com.uiui.sn.bean;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class AppletQRCode implements Serializable {
|
||||
private static final long serialVersionUID = -8881030834624940282L;
|
||||
String file;
|
||||
|
||||
public String getFile() {
|
||||
return file;
|
||||
}
|
||||
|
||||
public void setFile(String file) {
|
||||
this.file = file;
|
||||
}
|
||||
}
|
||||
17
app/src/main/java/com/uiui/sn/bean/BatchID.java
Normal file
17
app/src/main/java/com/uiui/sn/bean/BatchID.java
Normal file
@@ -0,0 +1,17 @@
|
||||
package com.uiui.sn.bean;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class BatchID implements Serializable {
|
||||
private static final long serialVersionUID = -2320968190625923242L;
|
||||
|
||||
String batch_id;
|
||||
|
||||
public String getBatch_id() {
|
||||
return batch_id;
|
||||
}
|
||||
|
||||
public void setBatch_id(String batch_id) {
|
||||
this.batch_id = batch_id;
|
||||
}
|
||||
}
|
||||
52
app/src/main/java/com/uiui/sn/bean/CloudLessonSetting.java
Normal file
52
app/src/main/java/com/uiui/sn/bean/CloudLessonSetting.java
Normal file
@@ -0,0 +1,52 @@
|
||||
package com.uiui.sn.bean;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class CloudLessonSetting implements Serializable {
|
||||
private static final long serialVersionUID = 4065637781427268046L;
|
||||
int id;
|
||||
String is_lesson;
|
||||
String start_time;
|
||||
String end_time;
|
||||
String is_monitor;
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getIs_lesson() {
|
||||
return is_lesson;
|
||||
}
|
||||
|
||||
public void setIs_lesson(String is_lesson) {
|
||||
this.is_lesson = is_lesson;
|
||||
}
|
||||
|
||||
public String getStart_time() {
|
||||
return start_time;
|
||||
}
|
||||
|
||||
public void setStart_time(String start_time) {
|
||||
this.start_time = start_time;
|
||||
}
|
||||
|
||||
public String getEnd_time() {
|
||||
return end_time;
|
||||
}
|
||||
|
||||
public void setEnd_time(String end_time) {
|
||||
this.end_time = end_time;
|
||||
}
|
||||
|
||||
public String getIs_monitor() {
|
||||
return is_monitor;
|
||||
}
|
||||
|
||||
public void setIs_monitor(String is_monitor) {
|
||||
this.is_monitor = is_monitor;
|
||||
}
|
||||
}
|
||||
@@ -9,10 +9,8 @@ public class CommonConfig {
|
||||
public final static String ONLY_SHORTCUT_LIST = "only_jgy_shortcut_list";
|
||||
/*底层白名单*/
|
||||
public final static String QCH_APP_FORBID = "qch_app_forbid";
|
||||
/*所有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 = "DEVICES_TAG";
|
||||
|
||||
public static String isLogined = "isLogined";
|
||||
public static String AES_KEY = "0123456789ABCDEF";
|
||||
|
||||
461
app/src/main/java/com/uiui/sn/disklrucache/CacheHelper.java
Normal file
461
app/src/main/java/com/uiui/sn/disklrucache/CacheHelper.java
Normal file
@@ -0,0 +1,461 @@
|
||||
package com.uiui.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) {
|
||||
Log.e(TAG, "put: " + key);
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,427 @@
|
||||
package com.uiui.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);
|
||||
}
|
||||
|
||||
}
|
||||
101
app/src/main/java/com/uiui/sn/disklrucache/Utils.java
Normal file
101
app/src/main/java/com/uiui/sn/disklrucache/Utils.java
Normal file
@@ -0,0 +1,101 @@
|
||||
package com.uiui.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);
|
||||
}
|
||||
}
|
||||
@@ -79,47 +79,6 @@ public class AppletQRCodeFragment extends Fragment {
|
||||
}
|
||||
|
||||
private void getQRCodeURL() {
|
||||
NetInterfaceManager.getInstance()
|
||||
.getQRCodeApiControl()
|
||||
.subscribe(new Observer<BaseResponse>() {
|
||||
@Override
|
||||
public void onSubscribe(Disposable d) {
|
||||
Log.e("getQRCodeURL", "onSubscribe: ");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(BaseResponse baseResponse) {
|
||||
Log.e("getQRCodeURL", "onNext: ");
|
||||
if (baseResponse.code == 200) {
|
||||
JSONObject jsonObject = (JSONObject) JSON.toJSON(baseResponse.data);
|
||||
String url = jsonObject.getString("file");
|
||||
if (!TextUtils.isEmpty(url)) {
|
||||
if (getActivity() != null && !getActivity().isDestroyed()) {
|
||||
Glide.with(qr_code)
|
||||
.load(url)
|
||||
.dontAnimate()
|
||||
.placeholder(getActivity().getDrawable(R.drawable.applet_qrcode))
|
||||
.into(qr_code);
|
||||
}
|
||||
} else {
|
||||
qr_code.setImageDrawable(getActivity().getDrawable(R.drawable.applet_qrcode));
|
||||
}
|
||||
} else {
|
||||
qr_code.setImageDrawable(getActivity().getDrawable(R.drawable.applet_qrcode));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
Log.e("getQRCodeURL", "onError: " + e.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
Log.e("getQRCodeURL", "onComplete: ");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -10,6 +10,15 @@ import com.uiui.sn.utils.TimeUtils;
|
||||
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,55 @@ 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 nowTime = System.currentTimeMillis();
|
||||
long lastTime = mMMKV.decodeLong(key, 0);
|
||||
long intervalTime = getConnectModeTime(connectMode);
|
||||
//防止一分钟内重复请求
|
||||
return nowTime - lastTime > intervalTime && nowTime - lastTime > ONE_MINUTES_TIME;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @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 +129,6 @@ public class ConnectManager {
|
||||
long time = mMMKV.decodeLong(WiFiAlias, 0);
|
||||
return !TimeUtils.isTodayTime(time);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
12
app/src/main/java/com/uiui/sn/manager/ConnectMode.java
Normal file
12
app/src/main/java/com/uiui/sn/manager/ConnectMode.java
Normal file
@@ -0,0 +1,12 @@
|
||||
package com.uiui.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
File diff suppressed because it is too large
Load Diff
@@ -46,7 +46,7 @@ public class UrlAddress {
|
||||
//获取屏幕管控
|
||||
public final static String GET_SCREEN_LOCK = "sn/getScreenshot";
|
||||
//获取时间管控
|
||||
public final static String GET_TIME_CONTROL = "sn/getTimeControl";
|
||||
public final static String GET_TIME_CONTROL = "sn/getTimeControlControl";
|
||||
//获取用户头像和信息
|
||||
public static final String GET_USER_AVATAR_INFO = "sn/getUserAvatarInfo";
|
||||
//获取小程序二维码
|
||||
@@ -57,6 +57,8 @@ public class UrlAddress {
|
||||
public static final String UPLOAD_CONTROL_SCREENSHOT = "sn/uploadControlScreenshot";
|
||||
//获取应用白名单
|
||||
public static final String GET_APP_AND_WHITE = "getAppAndWhite";
|
||||
//获取是否为网课模式
|
||||
public static final String GET_CLOUD_LESSON_SETTING ="Control/getCloudLessonSetting";
|
||||
|
||||
|
||||
/*获取公网IP*/
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.uiui.sn.network.api;
|
||||
|
||||
import com.uiui.sn.bean.BaseResponse;
|
||||
import com.uiui.sn.bean.CloudLessonSetting;
|
||||
import com.uiui.sn.network.UrlAddress;
|
||||
|
||||
import io.reactivex.rxjava3.core.Observable;
|
||||
import retrofit2.http.GET;
|
||||
import retrofit2.http.Query;
|
||||
|
||||
public interface CloudLessonSettingApi {
|
||||
@GET(UrlAddress.GET_CLOUD_LESSON_SETTING)
|
||||
Observable<BaseResponse<CloudLessonSetting>> getCloudLessonSetting(
|
||||
@Query("sn") String sn
|
||||
);
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.uiui.sn.network.api;
|
||||
|
||||
import com.uiui.sn.bean.BaseResponse;
|
||||
import com.uiui.sn.bean.BatchID;
|
||||
import com.uiui.sn.network.UrlAddress;
|
||||
|
||||
import io.reactivex.rxjava3.core.Observable;
|
||||
@@ -9,7 +10,7 @@ import retrofit2.http.Query;
|
||||
|
||||
public interface GetBatchApi {
|
||||
@GET(UrlAddress.GET_BATCH)
|
||||
Observable<BaseResponse> getBatch(
|
||||
Observable<BaseResponse<BatchID>> getBatch(
|
||||
@Query("sn") String sn
|
||||
);
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.uiui.sn.network.api;
|
||||
|
||||
import com.uiui.sn.bean.AppletQRCode;
|
||||
import com.uiui.sn.bean.BaseResponse;
|
||||
import com.uiui.sn.network.UrlAddress;
|
||||
|
||||
@@ -8,5 +9,5 @@ import retrofit2.http.GET;
|
||||
|
||||
public interface QRCodeApi {
|
||||
@GET(UrlAddress.GET_APPLET_QRCODE)
|
||||
Observable<BaseResponse> getQRCodeApi();
|
||||
Observable<BaseResponse<AppletQRCode>> getQRCodeApi();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,276 @@
|
||||
package com.uiui.sn.network.interceptor;
|
||||
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.blankj.utilcode.util.LogUtils;
|
||||
import com.uiui.sn.disklrucache.DiskLruCacheHelper;
|
||||
import com.uiui.sn.utils.JGYUtils;
|
||||
|
||||
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(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]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
package com.uiui.sn.network.interceptor;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
|
||||
import com.uiui.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;
|
||||
import okio.Buffer;
|
||||
|
||||
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" + bodyToString(request));
|
||||
//下面这行写了不会抛出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" + bodyToString(request));
|
||||
// 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" + bodyToString(request));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static String bodyToString(final Request request){
|
||||
try {
|
||||
final Request copy = request.newBuilder().build();
|
||||
final Buffer buffer = new Buffer();
|
||||
copy.body().writeTo(buffer);
|
||||
return buffer.readUtf8();
|
||||
} catch ( Exception e) {
|
||||
return "-";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -8,7 +8,6 @@ import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import com.uiui.sn.config.CommonConfig;
|
||||
import com.uiui.sn.network.HTTPInterface;
|
||||
import com.uiui.sn.network.NetInterfaceManager;
|
||||
import com.uiui.sn.utils.ApkUtils;
|
||||
import com.uiui.sn.utils.CacheUtils;
|
||||
@@ -87,7 +86,7 @@ public class APKinstallReceiver extends BroadcastReceiver {
|
||||
|
||||
private static void sendAppInfo() {
|
||||
Observable.create((ObservableEmitter<String> emitter) -> newAppListener = emitter::onNext)
|
||||
.throttleLast(5, TimeUnit.SECONDS)
|
||||
.throttleLast(5, TimeUnit.MINUTES)
|
||||
.subscribe(new Observer<String>() {
|
||||
@Override
|
||||
public void onSubscribe(Disposable d) {
|
||||
@@ -100,9 +99,9 @@ public class APKinstallReceiver extends BroadcastReceiver {
|
||||
int isLogined = (int) SPUtils.get(mContext, CommonConfig.isLogined, 2);
|
||||
if (isLogined == 2) return;
|
||||
NetInterfaceManager.getInstance().SendAppInstallInfo();
|
||||
HTTPInterface.getForceInstall(mContext);
|
||||
HTTPInterface.getAllappPackage(mContext);
|
||||
HTTPInterface.getAppInside(mContext);
|
||||
NetInterfaceManager.getInstance().getForceInstall();
|
||||
NetInterfaceManager.getInstance().getAllappPackage();
|
||||
NetInterfaceManager.getInstance().getAppInside();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -9,7 +9,7 @@ import com.amap.api.location.AMapLocation;
|
||||
import com.amap.api.location.AMapLocationClient;
|
||||
import com.amap.api.location.AMapLocationListener;
|
||||
import com.uiui.sn.manager.AmapManager;
|
||||
import com.uiui.sn.network.HTTPInterface;
|
||||
import com.uiui.sn.network.NetInterfaceManager;
|
||||
import com.uiui.sn.service.ControlPanelService;
|
||||
import com.uiui.sn.service.GuardService;
|
||||
import com.uiui.sn.service.main.MainService;
|
||||
@@ -57,7 +57,7 @@ public class BootReceiver extends BroadcastReceiver {
|
||||
@Override
|
||||
public void onLocationChanged(AMapLocation aMapLocation) {
|
||||
Log.e(TAG, "onLocationChanged: ");
|
||||
HTTPInterface.updateAdminInfo(context);
|
||||
NetInterfaceManager.getInstance().updateAdminInfo();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -34,7 +34,6 @@ import com.uiui.sn.manager.ControlManager;
|
||||
import com.uiui.sn.manager.ControlPanelManager;
|
||||
import com.uiui.sn.manager.DeviceManager;
|
||||
import com.uiui.sn.network.NetInterfaceManager;
|
||||
import com.uiui.sn.network.HTTPInterface;
|
||||
import com.uiui.sn.service.main.MainService;
|
||||
import com.uiui.sn.service.ManagerService;
|
||||
import com.uiui.sn.utils.ApkUtils;
|
||||
@@ -233,14 +232,12 @@ public class MyJPushReceiver extends BroadcastReceiver {
|
||||
String title = bundle.getString(JPushInterface.EXTRA_TITLE);
|
||||
String type = bundle.getString(JPushInterface.EXTRA_CONTENT_TYPE);
|
||||
String extras = bundle.getString(JPushInterface.EXTRA_EXTRA);
|
||||
// HTTPInterface.checkDevicesInfo(context);
|
||||
Log.e(TAG, "processCustomMessage: " + extras);
|
||||
switch (message) {
|
||||
default:
|
||||
break;
|
||||
case JIGUANG_GET_DRIVELINE:
|
||||
ToastUtil.debugShow("收到推送消息: 获取在线信息");
|
||||
// HTTPInterface.getDriveState(member_id, sn_id);
|
||||
break;
|
||||
case JIGUANG_GET_STARTTIME:
|
||||
ToastUtil.debugShow("收到推送消息: 获取运行应用");
|
||||
@@ -269,7 +266,7 @@ public class MyJPushReceiver extends BroadcastReceiver {
|
||||
Handler.getMain().postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
HTTPInterface.setBrowserWhiteList(context);
|
||||
NetInterfaceManager.getInstance().setBrowserWhiteList();
|
||||
}
|
||||
}, 2000);
|
||||
break;
|
||||
@@ -279,7 +276,7 @@ public class MyJPushReceiver extends BroadcastReceiver {
|
||||
Handler.getMain().postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
HTTPInterface.getAppInside(context);
|
||||
NetInterfaceManager.getInstance().getAppInside();
|
||||
}
|
||||
}, 2000);
|
||||
break;
|
||||
@@ -289,8 +286,8 @@ public class MyJPushReceiver extends BroadcastReceiver {
|
||||
break;
|
||||
case JIGUANG_FORCE_INSTALLAPK:
|
||||
ToastUtil.debugShow("收到推送消息: 强制安装应用");
|
||||
HTTPInterface.getAllappPackage(context);
|
||||
HTTPInterface.getForceInstall(context);
|
||||
NetInterfaceManager.getInstance().getAllappPackage();
|
||||
NetInterfaceManager.getInstance().getForceInstall();
|
||||
// intallApk(context, extras);
|
||||
break;
|
||||
case JIGUANG_FORCE_UNINSTALLAPK:
|
||||
@@ -320,7 +317,7 @@ public class MyJPushReceiver extends BroadcastReceiver {
|
||||
break;
|
||||
case JIGUANG_APP_WEBSITE:
|
||||
ToastUtil.debugShow("收到推送消息: app内部网址管控");
|
||||
// HTTPInterface.getAppJump(context);
|
||||
// NetInterfaceManager.getInstance().getAppJump(context);
|
||||
break;
|
||||
case JIGUANG_REBOOT_DEVICES:
|
||||
ToastUtil.debugShow("收到推送消息: 重启");
|
||||
@@ -328,7 +325,7 @@ public class MyJPushReceiver extends BroadcastReceiver {
|
||||
break;
|
||||
case JIGUANG_APP_NET_AUTO:
|
||||
ToastUtil.debugShow("收到推送消息: APP联网自启管控");
|
||||
Handler.getMain().postDelayed(() -> HTTPInterface.getAllappPackage(context), 2000);
|
||||
Handler.getMain().postDelayed(() -> NetInterfaceManager.getInstance().getAllappPackage(), 2000);
|
||||
break;
|
||||
case JIGUANG_BROWSER_LABEL:
|
||||
ToastUtil.debugShow("收到推送消息: 浏览器书签");
|
||||
@@ -341,8 +338,8 @@ public class MyJPushReceiver extends BroadcastReceiver {
|
||||
Handler.getMain().postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
HTTPInterface.getBrowserWhiteList(context);
|
||||
HTTPInterface.getBrowserLabel(context);
|
||||
NetInterfaceManager.getInstance().getBrowserWhiteList();
|
||||
NetInterfaceManager.getInstance().getBrowserLabel();
|
||||
}
|
||||
}, 2000);
|
||||
break;
|
||||
@@ -364,7 +361,7 @@ public class MyJPushReceiver extends BroadcastReceiver {
|
||||
break;
|
||||
case JIGUANG_APP_SETTING:
|
||||
ToastUtil.debugShow("收到推送消息: 获取app管控设置");
|
||||
Handler.getMain().postDelayed(() -> HTTPInterface.getAllappPackage(context), 2000);
|
||||
Handler.getMain().postDelayed(() -> NetInterfaceManager.getInstance().getAllappPackage(), 2000);
|
||||
break;
|
||||
case JIGUANG_FORCE_KILL:
|
||||
ToastUtil.debugShow("收到推送消息: 强制停止应用");
|
||||
@@ -563,10 +560,10 @@ public class MyJPushReceiver extends BroadcastReceiver {
|
||||
}
|
||||
|
||||
synchronized private void sendStartTime(Context context, String jsonString) {
|
||||
HTTPInterface.updateAdminInfo(context);
|
||||
HTTPInterface.sendRunningApp(context);
|
||||
NetInterfaceManager.getInstance().updateAdminInfo();
|
||||
NetInterfaceManager.getInstance().sendRunningApp();
|
||||
if (JGYUtils.getInstance().isScreenOn()) {
|
||||
HTTPInterface.screenshot(context);
|
||||
NetInterfaceManager.getInstance().screenshot();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -696,7 +693,7 @@ public class MyJPushReceiver extends BroadcastReceiver {
|
||||
if (TextUtils.isEmpty(jsonString)) {
|
||||
return;
|
||||
}
|
||||
// HTTPInterface.getAllAppPackageName(context);
|
||||
// NetInterfaceManager.getInstance().getAllAppPackageName(context);
|
||||
JSONObject extra = JSON.parseObject(jsonString);
|
||||
final String packages = extra.getString("package");
|
||||
ToastUtil.debugShow("收到应用安装消息:包名" + packages);
|
||||
@@ -729,7 +726,7 @@ public class MyJPushReceiver extends BroadcastReceiver {
|
||||
ToastUtil.debugShow("收到应用卸载消息:包名" + packageName);
|
||||
if (!"".equals(packageName) && !packageName.equals(context.getApplicationContext().getPackageName())) {
|
||||
if (!ApkUtils.isAvailable(context.getApplicationContext(), packageName)) {
|
||||
// HTTPInterface.setAppuninstallInfo(sn_id, packageName);
|
||||
// NetInterfaceManager.getInstance().setAppuninstallInfo(sn_id, packageName);
|
||||
} else {
|
||||
ApkUtils.uninstallApp(context, packageName);
|
||||
}
|
||||
@@ -868,7 +865,7 @@ public class MyJPushReceiver extends BroadcastReceiver {
|
||||
}
|
||||
|
||||
private void setPhone(Context context, String jsonString) {
|
||||
HTTPInterface.getSystemSettings();
|
||||
NetInterfaceManager.getInstance().getSystemSettings();
|
||||
}
|
||||
|
||||
@SuppressLint("NewApi")
|
||||
@@ -876,7 +873,7 @@ public class MyJPushReceiver extends BroadcastReceiver {
|
||||
JSONObject jsonObject = JSON.parseObject(jsonString);
|
||||
String is_upgrade = jsonObject.getString("is_upgrade");
|
||||
String packageName = jsonObject.getString("package");
|
||||
String nowApplist = JGYUtils.getString(context.getContentResolver(), CommonConfig.QCH_APP_FORBID);
|
||||
String nowApplist = JGYUtils.getString(context.getContentResolver(), CommonConfig.QCH_APP_FORBID);
|
||||
List<String> applist = new ArrayList<>(Arrays.asList(nowApplist.split(",")));
|
||||
if ("0".equals(is_upgrade)) {
|
||||
if (applist.contains(packageName)) {
|
||||
@@ -889,8 +886,8 @@ public class MyJPushReceiver extends BroadcastReceiver {
|
||||
applist.add(packageName);
|
||||
}
|
||||
}
|
||||
JGYUtils.putString(context.getContentResolver(), CommonConfig.QCH_APP_FORBID, String.join(",", applist));
|
||||
Log.e("setAppUpdate", JGYUtils.getString(context.getContentResolver(), CommonConfig.QCH_APP_FORBID));
|
||||
JGYUtils.putString(context.getContentResolver(), CommonConfig.QCH_APP_FORBID, String.join(",", applist));
|
||||
Log.e("setAppUpdate", JGYUtils.getString(context.getContentResolver(), CommonConfig.QCH_APP_FORBID));
|
||||
}
|
||||
|
||||
private void setLock_screen(Context context, String jsonString) {
|
||||
@@ -1034,7 +1031,7 @@ public class MyJPushReceiver extends BroadcastReceiver {
|
||||
}
|
||||
|
||||
private void timeControl(Context context, String jsonString) {
|
||||
HTTPInterface.getTimeControl(context);
|
||||
NetInterfaceManager.getInstance().getTimeControl();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1108,7 +1105,7 @@ public class MyJPushReceiver extends BroadcastReceiver {
|
||||
}
|
||||
|
||||
private void hideDesktopIcon() {
|
||||
HTTPInterface.getSystemSettings();
|
||||
NetInterfaceManager.getInstance().getSystemSettings();
|
||||
}
|
||||
|
||||
private void searchTopic(Context context, String jsonString) {
|
||||
|
||||
@@ -10,25 +10,17 @@ import android.util.Log;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.amap.api.location.AMapLocation;
|
||||
import com.amap.api.location.AMapLocationClient;
|
||||
import com.amap.api.location.AMapLocationListener;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.trello.rxlifecycle4.RxLifecycle;
|
||||
import com.trello.rxlifecycle4.android.ActivityEvent;
|
||||
import com.uiui.sn.bean.AppInfo;
|
||||
import com.uiui.sn.bean.AppStart;
|
||||
import com.uiui.sn.bean.BaseResponse;
|
||||
import com.uiui.sn.bean.Label;
|
||||
import com.uiui.sn.bean.UserAvatarInfo;
|
||||
import com.uiui.sn.bean.SnInfo;
|
||||
import com.uiui.sn.bean.browser.BrowserApiData;
|
||||
import com.uiui.sn.bean.browser.BrowserBean;
|
||||
import com.uiui.sn.config.CommonConfig;
|
||||
import com.uiui.sn.manager.AmapManager;
|
||||
import com.uiui.sn.manager.ControlManager;
|
||||
import com.uiui.sn.network.HTTPInterface;
|
||||
import com.uiui.sn.network.NetInterfaceManager;
|
||||
import com.uiui.sn.service.ManagerService;
|
||||
import com.uiui.sn.utils.ApkUtils;
|
||||
@@ -87,7 +79,7 @@ public class MainSPresenter implements MainSContact.Presenter {
|
||||
@Override
|
||||
public void getSnInfo() {
|
||||
NetInterfaceManager.getInstance()
|
||||
.getSnInfo(lifecycle, new NetInterfaceManager.ObserverCallback() {
|
||||
.getSnInfo(true, getLifecycle(), new NetInterfaceManager.ObserverCallback() {
|
||||
@Override
|
||||
public void onSubscribe(Disposable d) {
|
||||
|
||||
@@ -118,7 +110,12 @@ public class MainSPresenter implements MainSContact.Presenter {
|
||||
|
||||
@Override
|
||||
public void checkUpdate() {
|
||||
mView.checkUpdateFinish();
|
||||
NetInterfaceManager.getInstance().checkAllAppUpdate(true, getLifecycle(), new NetInterfaceManager.onCompleteCallback() {
|
||||
@Override
|
||||
public void onComplete() {
|
||||
mView.checkUpdateFinish();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -126,7 +123,7 @@ public class MainSPresenter implements MainSContact.Presenter {
|
||||
public void getAllApp() {
|
||||
NetInterfaceManager.getInstance()
|
||||
.getQueryAllAppControl()
|
||||
.compose(RxLifecycle.bindUntilEvent(lifecycle, ActivityEvent.DESTROY))
|
||||
.compose(RxLifecycle.bindUntilEvent(getLifecycle(), ActivityEvent.DESTROY))
|
||||
.subscribe(new Observer<BaseResponse<List<AppInfo>>>() {
|
||||
@Override
|
||||
public void onSubscribe(Disposable d) {
|
||||
@@ -150,7 +147,7 @@ public class MainSPresenter implements MainSContact.Presenter {
|
||||
Settings.System.putString(mContext.getContentResolver(), CommonConfig.ONLY_SHORTCUT_LIST, allPkgString);
|
||||
Log.e("getAllApp", "onNext: " + allPkgString);
|
||||
ApkUtils.writeAppPackageList(mContext, allPkgString);
|
||||
HTTPInterface.getAppStart(mContext, appInfoList);
|
||||
NetInterfaceManager.getInstance().getAppStart(appInfoList);
|
||||
}
|
||||
JGYUtils.getInstance().deleteOtherApp();
|
||||
}
|
||||
@@ -174,7 +171,7 @@ public class MainSPresenter implements MainSContact.Presenter {
|
||||
public void getAppInside() {
|
||||
NetInterfaceManager.getInstance()
|
||||
.getAppInsideControl()
|
||||
.compose(RxLifecycle.bindUntilEvent(lifecycle, ActivityEvent.DESTROY))
|
||||
.compose(RxLifecycle.bindUntilEvent(getLifecycle(), ActivityEvent.DESTROY))
|
||||
.subscribe(new Observer<BaseResponse>() {
|
||||
@Override
|
||||
public void onSubscribe(Disposable d) {
|
||||
@@ -215,7 +212,7 @@ public class MainSPresenter implements MainSContact.Presenter {
|
||||
public void getForceInstall() {
|
||||
NetInterfaceManager.getInstance()
|
||||
.getForceInstallControl()
|
||||
.compose(RxLifecycle.bindUntilEvent(lifecycle, ActivityEvent.DESTROY))
|
||||
.compose(RxLifecycle.bindUntilEvent(getLifecycle(), ActivityEvent.DESTROY))
|
||||
.subscribe(new Observer<BaseResponse<List<AppInfo>>>() {
|
||||
@Override
|
||||
public void onSubscribe(Disposable d) {
|
||||
@@ -229,7 +226,7 @@ public class MainSPresenter implements MainSContact.Presenter {
|
||||
if (code == 200) {
|
||||
List<AppInfo> appInfos = listBaseResponse.data;
|
||||
if (null != appInfos && appInfos.size() != 0) {
|
||||
HTTPInterface.getForceInstallState(mContext, appInfos);
|
||||
NetInterfaceManager.getInstance().getForceInstallState(appInfos);
|
||||
}
|
||||
} else {
|
||||
boolean qch_force_app = JGYUtils.putString(mContext.getContentResolver(), "qch_force_app", "invalid");
|
||||
@@ -255,7 +252,7 @@ public class MainSPresenter implements MainSContact.Presenter {
|
||||
public void getSystemSettings() {
|
||||
NetInterfaceManager.getInstance()
|
||||
.getsettingControl()
|
||||
.compose(RxLifecycle.bindUntilEvent(lifecycle, ActivityEvent.DESTROY))
|
||||
.compose(RxLifecycle.bindUntilEvent(getLifecycle(), ActivityEvent.DESTROY))
|
||||
.subscribe(new Observer<BaseResponse>() {
|
||||
@Override
|
||||
public void onSubscribe(Disposable d) {
|
||||
@@ -296,7 +293,7 @@ public class MainSPresenter implements MainSContact.Presenter {
|
||||
@Override
|
||||
public void getBrowserLabel() {
|
||||
NetInterfaceManager.getInstance().getLabelControl()
|
||||
.compose(RxLifecycle.bindUntilEvent(lifecycle, ActivityEvent.DESTROY))
|
||||
.compose(RxLifecycle.bindUntilEvent(getLifecycle(), ActivityEvent.DESTROY))
|
||||
.subscribe(new Observer<BaseResponse<Label>>() {
|
||||
@Override
|
||||
public void onSubscribe(Disposable d) {
|
||||
@@ -373,7 +370,7 @@ public class MainSPresenter implements MainSContact.Presenter {
|
||||
@Override
|
||||
public void getBrowserWhiteList() {
|
||||
NetInterfaceManager.getInstance().getBrowserControl()
|
||||
.compose(RxLifecycle.bindUntilEvent(lifecycle, ActivityEvent.DESTROY))
|
||||
.compose(RxLifecycle.bindUntilEvent(getLifecycle(), ActivityEvent.DESTROY))
|
||||
.subscribe(new Observer<BaseResponse<BrowserApiData>>() {
|
||||
@Override
|
||||
public void onSubscribe(Disposable d) {
|
||||
@@ -427,7 +424,7 @@ public class MainSPresenter implements MainSContact.Presenter {
|
||||
public void getAppStart() {
|
||||
NetInterfaceManager.getInstance()
|
||||
.getAppStartControl()
|
||||
.compose(RxLifecycle.bindUntilEvent(lifecycle, ActivityEvent.DESTROY))
|
||||
.compose(RxLifecycle.bindUntilEvent(getLifecycle(), ActivityEvent.DESTROY))
|
||||
.subscribe(new Observer<BaseResponse<List<AppStart>>>() {
|
||||
@Override
|
||||
public void onSubscribe(Disposable d) {
|
||||
@@ -440,9 +437,9 @@ public class MainSPresenter implements MainSContact.Presenter {
|
||||
int code = listBaseResponse.code;
|
||||
if (code == 200) {
|
||||
List<AppStart> list = listBaseResponse.data;
|
||||
HTTPInterface.setAppState(mContext, list);
|
||||
NetInterfaceManager.getInstance().setAppState(list);
|
||||
} else {
|
||||
HTTPInterface.setInvalid(mContext);
|
||||
NetInterfaceManager.getInstance().setInvalid();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -463,17 +460,17 @@ public class MainSPresenter implements MainSContact.Presenter {
|
||||
@Override
|
||||
public void getTimeControl() {
|
||||
NetInterfaceManager.getInstance()
|
||||
.getTimeControl()
|
||||
.compose(RxLifecycle.bindUntilEvent(lifecycle, ActivityEvent.DESTROY))
|
||||
.getTimeControlObservable()
|
||||
.compose(RxLifecycle.bindUntilEvent(getLifecycle(), ActivityEvent.DESTROY))
|
||||
.subscribe(new Observer<BaseResponse>() {
|
||||
@Override
|
||||
public void onSubscribe(Disposable d) {
|
||||
Log.e("getTimeControl", "onSubscribe: ");
|
||||
Log.e("getTimeControlControl", "onSubscribe: ");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(BaseResponse baseResponse) {
|
||||
Log.e("getTimeControl", "onNext: ");
|
||||
Log.e("getTimeControlControl", "onNext: ");
|
||||
int code = baseResponse.code;
|
||||
if (code == 200) {
|
||||
JSONObject jsonObject = (JSONObject) JSON.toJSON(baseResponse.data);
|
||||
@@ -486,32 +483,32 @@ public class MainSPresenter implements MainSContact.Presenter {
|
||||
TimeUtils.ContralTime workingTime = TimeUtils.String2WorkingTime(mContext, work_start_time + "-" + work_end_time);
|
||||
TimeUtils.ContralTime weekTime = TimeUtils.String2WeekTime(mContext, rest_start_time + "-" + rest_end_time);
|
||||
if (null != workingTime) {
|
||||
Log.e("getTimeControl", "200:" + workingTime.toString());
|
||||
Log.e("getTimeControlControl", "200:" + workingTime.toString());
|
||||
}
|
||||
if (null != weekTime) {
|
||||
Log.e("getTimeControl", "200:" + weekTime.toString());
|
||||
Log.e("getTimeControlControl", "200:" + weekTime.toString());
|
||||
}
|
||||
} else {
|
||||
TimeUtils.setEmpty(mContext);
|
||||
TimeUtils.ContralTime workingTime = TimeUtils.getWorkingDayContralTime(mContext);
|
||||
if (null != workingTime) {
|
||||
Log.e("getTimeControl", workingTime.toString());
|
||||
Log.e("getTimeControlControl", workingTime.toString());
|
||||
}
|
||||
TimeUtils.ContralTime weekTime = TimeUtils.getWeekDayContralTime(mContext);
|
||||
if (null != weekTime) {
|
||||
Log.e("getTimeControl", weekTime.toString());
|
||||
Log.e("getTimeControlControl", weekTime.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
Log.e("getTimeControl", "onError: " + e.getMessage());
|
||||
Log.e("getTimeControlControl", "onError: " + e.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
Log.e("getTimeControl", "onComplete: ");
|
||||
Log.e("getTimeControlControl", "onComplete: ");
|
||||
Intent intent = new Intent();
|
||||
intent.setAction(ManagerService.ACTION_UPDATE);
|
||||
mContext.sendBroadcast(intent);
|
||||
@@ -527,7 +524,7 @@ public class MainSPresenter implements MainSContact.Presenter {
|
||||
.getScreenshot(Utils.getSerial())
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.compose(RxLifecycle.bindUntilEvent(lifecycle, ActivityEvent.DESTROY))
|
||||
.compose(RxLifecycle.bindUntilEvent(getLifecycle(), ActivityEvent.DESTROY))
|
||||
.subscribe(new Observer<BaseResponse>() {
|
||||
|
||||
@Override
|
||||
|
||||
@@ -107,7 +107,7 @@ public class MainService extends Service implements MainSContact.MainView, Netwo
|
||||
start.onstar(WiFiAlias);
|
||||
}
|
||||
}
|
||||
NetInterfaceManager.getInstance().checkAllAppUpdate();
|
||||
mPresenter.checkUpdate();
|
||||
TimeTask task = new TimeTask();
|
||||
task.execute("ntp.aliyun.com");
|
||||
}
|
||||
@@ -124,22 +124,7 @@ public class MainService extends Service implements MainSContact.MainView, Netwo
|
||||
AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
|
||||
am.setTime(aLong);
|
||||
tPushInit();
|
||||
NetInterfaceManager.getInstance().setPushTags(lifecycleSubject, new NetInterfaceManager.ObserverCallback() {
|
||||
@Override
|
||||
public void onSubscribe(Disposable d) {
|
||||
Log.e("TimeTask", "onSubscribe: ");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(BaseResponse response) {
|
||||
Log.e("TimeTask", "onNext: ");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
Log.e("TimeTask", "onError: " + e.getMessage());
|
||||
}
|
||||
|
||||
NetInterfaceManager.getInstance().setPushTags(true, lifecycleSubject, new NetInterfaceManager.onCompleteCallback() {
|
||||
@Override
|
||||
public void onComplete() {
|
||||
Log.e("TimeTask", "onComplete: ");
|
||||
@@ -351,7 +336,7 @@ public class MainService extends Service implements MainSContact.MainView, Netwo
|
||||
@Override
|
||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||
Log.e(TAG, "onStartCommand: " + System.currentTimeMillis());
|
||||
NetInterfaceManager.getInstance().checkAllAppUpdate();
|
||||
mPresenter.checkUpdate();
|
||||
return START_STICKY;
|
||||
}
|
||||
|
||||
|
||||
@@ -40,7 +40,6 @@ import com.uiui.sn.dialog.CustomDialog;
|
||||
import com.uiui.sn.manager.ControlManager;
|
||||
import com.uiui.sn.manager.ControlPanelManager;
|
||||
import com.uiui.sn.manager.DeviceManager;
|
||||
import com.uiui.sn.network.HTTPInterface;
|
||||
import com.uiui.sn.network.NetInterfaceManager;
|
||||
import com.uiui.sn.receiver.BootReceiver;
|
||||
import com.uiui.sn.service.ManagerService;
|
||||
@@ -475,7 +474,7 @@ public class MessageReceiver extends XGPushBaseReceiver {
|
||||
switch (title) {
|
||||
case JIGUANG_GET_DRIVELINE:
|
||||
ToastUtil.debugShow("收到推送消息: 获取在线信息");
|
||||
// HTTPInterface.getDriveState(member_id, sn_id);
|
||||
// NetInterfaceManager.getInstance().getDriveState(member_id, sn_id);
|
||||
break;
|
||||
case JIGUANG_GET_STARTTIME:
|
||||
ToastUtil.debugShow("收到推送消息: 获取运行应用");
|
||||
@@ -504,7 +503,7 @@ public class MessageReceiver extends XGPushBaseReceiver {
|
||||
Handler.getMain().postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
HTTPInterface.setBrowserWhiteList(context);
|
||||
NetInterfaceManager.getInstance().setBrowserWhiteList();
|
||||
}
|
||||
}, 2000);
|
||||
break;
|
||||
@@ -514,7 +513,7 @@ public class MessageReceiver extends XGPushBaseReceiver {
|
||||
Handler.getMain().postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
HTTPInterface.getAppInside(context);
|
||||
NetInterfaceManager.getInstance().getAppInside();
|
||||
}
|
||||
}, 2000);
|
||||
break;
|
||||
@@ -524,8 +523,8 @@ public class MessageReceiver extends XGPushBaseReceiver {
|
||||
break;
|
||||
case JIGUANG_FORCE_INSTALLAPK:
|
||||
ToastUtil.debugShow("收到推送消息: 强制安装应用");
|
||||
HTTPInterface.getAllappPackage(context);
|
||||
HTTPInterface.getForceInstall(context);
|
||||
NetInterfaceManager.getInstance().getAllappPackage();
|
||||
NetInterfaceManager.getInstance().getForceInstall();
|
||||
// intallApk(context, extras);
|
||||
break;
|
||||
case JIGUANG_FORCE_UNINSTALLAPK:
|
||||
@@ -555,7 +554,7 @@ public class MessageReceiver extends XGPushBaseReceiver {
|
||||
break;
|
||||
case JIGUANG_APP_WEBSITE:
|
||||
ToastUtil.debugShow("收到推送消息: app内部网址管控");
|
||||
// HTTPInterface.getAppJump(context);
|
||||
// NetInterfaceManager.getInstance().getAppJump(context);
|
||||
break;
|
||||
case JIGUANG_REBOOT_DEVICES:
|
||||
ToastUtil.debugShow("收到推送消息: 重启");
|
||||
@@ -563,7 +562,7 @@ public class MessageReceiver extends XGPushBaseReceiver {
|
||||
break;
|
||||
case JIGUANG_APP_NET_AUTO:
|
||||
ToastUtil.debugShow("收到推送消息: APP联网自启管控");
|
||||
Handler.getMain().postDelayed(() -> HTTPInterface.getAllappPackage(context), 2000);
|
||||
Handler.getMain().postDelayed(() -> NetInterfaceManager.getInstance().getAllappPackage(), 2000);
|
||||
break;
|
||||
case JIGUANG_BROWSER_LABEL:
|
||||
ToastUtil.debugShow("收到推送消息: 浏览器书签");
|
||||
@@ -576,8 +575,8 @@ public class MessageReceiver extends XGPushBaseReceiver {
|
||||
Handler.getMain().postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
HTTPInterface.getBrowserWhiteList(context);
|
||||
HTTPInterface.getBrowserLabel(context);
|
||||
NetInterfaceManager.getInstance().getBrowserWhiteList();
|
||||
NetInterfaceManager.getInstance().getBrowserLabel();
|
||||
}
|
||||
}, 2000);
|
||||
break;
|
||||
@@ -599,7 +598,7 @@ public class MessageReceiver extends XGPushBaseReceiver {
|
||||
break;
|
||||
case JIGUANG_APP_SETTING:
|
||||
ToastUtil.debugShow("收到推送消息: 获取app管控设置");
|
||||
Handler.getMain().postDelayed(() -> HTTPInterface.getAllappPackage(context), 2000);
|
||||
Handler.getMain().postDelayed(() -> NetInterfaceManager.getInstance().getAllappPackage(), 2000);
|
||||
break;
|
||||
case JIGUANG_FORCE_KILL:
|
||||
ToastUtil.debugShow("收到推送消息: 强制停止应用");
|
||||
@@ -800,10 +799,10 @@ public class MessageReceiver extends XGPushBaseReceiver {
|
||||
}
|
||||
|
||||
synchronized private void sendStartTime(Context context, String jsonString) {
|
||||
HTTPInterface.updateAdminInfo(context);
|
||||
HTTPInterface.sendRunningApp(context);
|
||||
NetInterfaceManager.getInstance().updateAdminInfo();
|
||||
NetInterfaceManager.getInstance().sendRunningApp();
|
||||
if (JGYUtils.getInstance().isScreenOn()) {
|
||||
HTTPInterface.screenshot(context);
|
||||
NetInterfaceManager.getInstance().screenshot();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -933,7 +932,7 @@ public class MessageReceiver extends XGPushBaseReceiver {
|
||||
if (TextUtils.isEmpty(jsonString)) {
|
||||
return;
|
||||
}
|
||||
// HTTPInterface.getAllAppPackageName(context);
|
||||
// NetInterfaceManager.getInstance().getAllAppPackageName(context);
|
||||
JSONObject extra = JSON.parseObject(jsonString);
|
||||
final String packages = extra.getString("package");
|
||||
ToastUtil.debugShow("收到应用安装消息:包名" + packages);
|
||||
@@ -966,7 +965,7 @@ public class MessageReceiver extends XGPushBaseReceiver {
|
||||
ToastUtil.debugShow("收到应用卸载消息:包名" + packageName);
|
||||
if (!"".equals(packageName) && !packageName.equals(context.getApplicationContext().getPackageName())) {
|
||||
if (!ApkUtils.isAvailable(context.getApplicationContext(), packageName)) {
|
||||
// HTTPInterface.setAppuninstallInfo(sn_id, packageName);
|
||||
// NetInterfaceManager.getInstance().setAppuninstallInfo(sn_id, packageName);
|
||||
} else {
|
||||
ApkUtils.uninstallApp(context, packageName);
|
||||
}
|
||||
@@ -1105,7 +1104,7 @@ public class MessageReceiver extends XGPushBaseReceiver {
|
||||
}
|
||||
|
||||
private void setPhone(String jsonString) {
|
||||
HTTPInterface.getSystemSettings();
|
||||
NetInterfaceManager.getInstance().getSystemSettings();
|
||||
}
|
||||
|
||||
@SuppressLint("NewApi")
|
||||
@@ -1271,7 +1270,7 @@ public class MessageReceiver extends XGPushBaseReceiver {
|
||||
}
|
||||
|
||||
private void timeControl(Context context, String jsonString) {
|
||||
HTTPInterface.getTimeControl(context);
|
||||
NetInterfaceManager.getInstance().getTimeControl();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1345,7 +1344,7 @@ public class MessageReceiver extends XGPushBaseReceiver {
|
||||
}
|
||||
|
||||
private void hideDesktopIcon() {
|
||||
HTTPInterface.getSystemSettings();
|
||||
NetInterfaceManager.getInstance().getSystemSettings();
|
||||
}
|
||||
|
||||
private void searchTopic(Context context, String jsonString) {
|
||||
|
||||
@@ -4,9 +4,8 @@ import android.content.Context;
|
||||
import android.os.Environment;
|
||||
import android.util.Log;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.arialyy.aria.core.Aria;
|
||||
import com.blankj.utilcode.util.PathUtils;
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
@@ -54,9 +53,15 @@ public class FileUtils {
|
||||
return bigInt.toString(32);
|
||||
}
|
||||
|
||||
public static void ariaDownload(Context context, String url, JSONObject jsonObject) {
|
||||
public static void ariaDownload(Context context, String url, JsonObject jsonObject) {
|
||||
String fileName = getFileNamefromURL(url);
|
||||
String urlMD5 = jsonObject.getString("MD5");
|
||||
String urlMD5 = "";
|
||||
if (jsonObject.get("MD5")!=null){
|
||||
urlMD5 = jsonObject.get("MD5").getAsString();
|
||||
}else if (jsonObject.get("app_md5")!=null){
|
||||
urlMD5 = jsonObject.get("app_md5").getAsString();
|
||||
}
|
||||
|
||||
Log.e("ariaDownload", "urlMD5=" + urlMD5);
|
||||
File file = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS) + "/jgy/" + fileName);
|
||||
if (file.exists() && !file.isDirectory()) {
|
||||
@@ -73,7 +78,7 @@ public class FileUtils {
|
||||
.load(url) //读取下载地址
|
||||
.setFilePath(JGYUtils.getInstance().getDownLoadPath() + fileName)
|
||||
.ignoreFilePathOccupy()
|
||||
.setExtendField(jsonObject.toJSONString())
|
||||
.setExtendField(jsonObject.toString())
|
||||
.create(); //启动下载}
|
||||
// }
|
||||
}
|
||||
@@ -82,7 +87,7 @@ public class FileUtils {
|
||||
.load(url) //读取下载地址
|
||||
.setFilePath(JGYUtils.getInstance().getDownLoadPath() + fileName)
|
||||
.ignoreFilePathOccupy()
|
||||
.setExtendField(jsonObject.toJSONString())
|
||||
.setExtendField(jsonObject.toString())
|
||||
.create(); //启动下载}
|
||||
}
|
||||
}
|
||||
|
||||
29
app/src/main/java/com/uiui/sn/utils/GsonUtils.java
Normal file
29
app/src/main/java/com/uiui/sn/utils/GsonUtils.java
Normal file
@@ -0,0 +1,29 @@
|
||||
package com.uiui.sn.utils;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
|
||||
public class GsonUtils {
|
||||
public static JsonObject getJsonObject(String jsonString) {
|
||||
JsonObject jsonObject = JsonParser.parseString(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);
|
||||
}
|
||||
}
|
||||
@@ -60,6 +60,7 @@ public class JGYUtils {
|
||||
private static JGYUtils sInstance;
|
||||
private Context mContext;
|
||||
private ContentResolver resolver;
|
||||
|
||||
public static int MTKPlatform = 1;
|
||||
public static int ZhanruiPlatform = 2;
|
||||
public static int UnknowPlatform = 0;
|
||||
@@ -966,4 +967,21 @@ public class JGYUtils {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,7 +60,6 @@ import com.uiui.sn.Statistics.AppInformation;
|
||||
import com.uiui.sn.Statistics.StatisticsInfo;
|
||||
import com.uiui.sn.bean.AppUsed;
|
||||
import com.uiui.sn.config.CommonConfig;
|
||||
import com.uiui.sn.network.HTTPInterface;
|
||||
import com.uiui.sn.network.NetInterfaceManager;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
@@ -1008,6 +1007,20 @@ public class Utils {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static void getBatterymAh(Context context) {
|
||||
Object mPowerProfile;
|
||||
double batteryCapacity = 0; //电池的容量mAh
|
||||
final String POWER_PROFILE_CLASS = "com.android.internal.os.PowerProfile";
|
||||
try {
|
||||
mPowerProfile = Class.forName(POWER_PROFILE_CLASS).getConstructor(Context.class).newInstance(context);
|
||||
batteryCapacity = (double) Class.forName(POWER_PROFILE_CLASS).getMethod("getBatteryCapacity").invoke(mPowerProfile);
|
||||
Log.e("getBattery", "battery mAh: " + batteryCapacity);
|
||||
} catch (Exception e) {
|
||||
Log.e("getBattery", "get batteryCapacity mAh error:" + batteryCapacity);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
synchronized private static int getBatteryLevel(Context mContext) {
|
||||
if (Build.VERSION.SDK_INT >= 21)
|
||||
return ((BatteryManager) mContext.getSystemService(Context.BATTERY_SERVICE)).getIntProperty(4);
|
||||
@@ -1015,6 +1028,19 @@ public class Utils {
|
||||
return intent.getIntExtra("level", -1) * 100 / intent.getIntExtra("scale", -1);
|
||||
}
|
||||
|
||||
public static int getBatteryPercentage(Context context) {
|
||||
|
||||
IntentFilter iFilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
|
||||
Intent batteryStatus = context.registerReceiver(null, iFilter);
|
||||
|
||||
int level = batteryStatus != null ? batteryStatus.getIntExtra(BatteryManager.EXTRA_LEVEL, -1) : -1;
|
||||
int scale = batteryStatus != null ? batteryStatus.getIntExtra(BatteryManager.EXTRA_SCALE, -1) : -1;
|
||||
|
||||
float batteryPct = level / (float) scale;
|
||||
|
||||
return (int) (batteryPct * 100);
|
||||
}
|
||||
|
||||
public static int getIsCharging(Context context) {
|
||||
IntentFilter ifilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
|
||||
Intent batteryStatus = context.registerReceiver(null, ifilter);
|
||||
|
||||
Reference in New Issue
Block a user