version:mtk 3.9
fix:优化解锁设置默认桌面 update:上传增加电池信息
This commit is contained in:
@@ -399,6 +399,7 @@ public class CheckNetPresenter implements CheckNetContact.Presenter {
|
||||
|
||||
@Override
|
||||
public void getDefaultDesktop() {
|
||||
Log.e(TAG, "getDefaultDesktop: ");
|
||||
if (JGYUtils.isOfficialVersion() || JGYUtils.getInstance().getDeviceIsLocked()) {
|
||||
mNetInterfaceManager.getAppLimit(true, getLifecycle(), new NetInterfaceManager.onCompleteCallback() {
|
||||
@Override
|
||||
@@ -408,12 +409,17 @@ public class CheckNetPresenter implements CheckNetContact.Presenter {
|
||||
});
|
||||
mView.getDefaultDesktopFinish();
|
||||
} else {
|
||||
mNetInterfaceManager.getDefaultDesktop(true, getLifecycle(), new NetInterfaceManager.onCompleteCallback() {
|
||||
@Override
|
||||
public void onComplete() {
|
||||
mView.getDefaultDesktopFinish();
|
||||
}
|
||||
});
|
||||
int aihuaUnlock = Settings.System.getInt(mContext.getContentResolver(), CommonConfig.AIHUA_UNLOCK, 0);
|
||||
if (JGYUtils.getInstance().isAihuaFramwwork() && aihuaUnlock == 1) {
|
||||
mView.getDefaultDesktopFinish();
|
||||
} else {
|
||||
mNetInterfaceManager.getDefaultDesktop(true, getLifecycle(), new NetInterfaceManager.onCompleteCallback() {
|
||||
@Override
|
||||
public void onComplete() {
|
||||
mView.getDefaultDesktopFinish();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
125
app/src/main/java/com/aoleyun/sn/bean/BatteryInfo.java
Normal file
125
app/src/main/java/com/aoleyun/sn/bean/BatteryInfo.java
Normal file
@@ -0,0 +1,125 @@
|
||||
package com.aoleyun.sn.bean;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class BatteryInfo implements Serializable {
|
||||
private static final long serialVersionUID = 7615775335930367771L;
|
||||
|
||||
String battery_quantity;
|
||||
String battery_temperature;
|
||||
String battery_voltage;
|
||||
String charge_current;
|
||||
String charge_voltage;
|
||||
String battery_status;
|
||||
String charge_type;
|
||||
String charge_current_max;
|
||||
String charge_voltage_max;
|
||||
String battery_health;
|
||||
String quantity_max;
|
||||
String battery_desc;
|
||||
String charge_speed;
|
||||
|
||||
public String getBattery_quantity() {
|
||||
return battery_quantity;
|
||||
}
|
||||
|
||||
public void setBattery_quantity(String battery_quantity) {
|
||||
this.battery_quantity = battery_quantity;
|
||||
}
|
||||
|
||||
public String getBattery_temperature() {
|
||||
return battery_temperature;
|
||||
}
|
||||
|
||||
public void setBattery_temperature(String battery_temperature) {
|
||||
this.battery_temperature = battery_temperature;
|
||||
}
|
||||
|
||||
public String getBattery_voltage() {
|
||||
return battery_voltage;
|
||||
}
|
||||
|
||||
public void setBattery_voltage(String battery_voltage) {
|
||||
this.battery_voltage = battery_voltage;
|
||||
}
|
||||
|
||||
public String getCharge_current() {
|
||||
return charge_current;
|
||||
}
|
||||
|
||||
public void setCharge_current(String charge_current) {
|
||||
this.charge_current = charge_current;
|
||||
}
|
||||
|
||||
public String getCharge_voltage() {
|
||||
return charge_voltage;
|
||||
}
|
||||
|
||||
public void setCharge_voltage(String charge_voltage) {
|
||||
this.charge_voltage = charge_voltage;
|
||||
}
|
||||
|
||||
public String getBattery_status() {
|
||||
return battery_status;
|
||||
}
|
||||
|
||||
public void setBattery_status(String battery_status) {
|
||||
this.battery_status = battery_status;
|
||||
}
|
||||
|
||||
public String getCharge_type() {
|
||||
return charge_type;
|
||||
}
|
||||
|
||||
public void setCharge_type(String charge_type) {
|
||||
this.charge_type = charge_type;
|
||||
}
|
||||
|
||||
public String getCharge_current_max() {
|
||||
return charge_current_max;
|
||||
}
|
||||
|
||||
public void setCharge_current_max(String charge_current_max) {
|
||||
this.charge_current_max = charge_current_max;
|
||||
}
|
||||
|
||||
public String getCharge_voltage_max() {
|
||||
return charge_voltage_max;
|
||||
}
|
||||
|
||||
public void setCharge_voltage_max(String charge_voltage_max) {
|
||||
this.charge_voltage_max = charge_voltage_max;
|
||||
}
|
||||
|
||||
public String getBattery_health() {
|
||||
return battery_health;
|
||||
}
|
||||
|
||||
public void setBattery_health(String battery_health) {
|
||||
this.battery_health = battery_health;
|
||||
}
|
||||
|
||||
public String getQuantity_max() {
|
||||
return quantity_max;
|
||||
}
|
||||
|
||||
public void setQuantity_max(String quantity_max) {
|
||||
this.quantity_max = quantity_max;
|
||||
}
|
||||
|
||||
public String getBattery_desc() {
|
||||
return battery_desc;
|
||||
}
|
||||
|
||||
public void setBattery_desc(String battery_desc) {
|
||||
this.battery_desc = battery_desc;
|
||||
}
|
||||
|
||||
public String getCharge_speed() {
|
||||
return charge_speed;
|
||||
}
|
||||
|
||||
public void setCharge_speed(String charge_speed) {
|
||||
this.charge_speed = charge_speed;
|
||||
}
|
||||
}
|
||||
@@ -34,12 +34,14 @@ public class CacheHelper {
|
||||
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 MAX_COUNT = 1024 * 1024 * 1024;
|
||||
private static final int DEFAULT_APP_VERSION = 1;
|
||||
|
||||
private DiskLruCache mDiskLruCache;
|
||||
private Context mContext;
|
||||
|
||||
public CacheHelper(Context context) {
|
||||
this.mContext = context;
|
||||
mDiskLruCache = generateCache(context, DIR_NAME, MAX_COUNT);
|
||||
}
|
||||
|
||||
@@ -106,6 +108,7 @@ public class CacheHelper {
|
||||
public void put(String key, String value) {
|
||||
Log.e(TAG, "put: " + key);
|
||||
mMMKV.encode(key, System.currentTimeMillis());
|
||||
mMMKV.encode(key + "_mmkv", value);
|
||||
|
||||
DiskLruCache.Editor edit = null;
|
||||
BufferedWriter bw = null;
|
||||
@@ -147,7 +150,7 @@ public class CacheHelper {
|
||||
//write READ
|
||||
inputStream = get(key);
|
||||
if (inputStream == null) {
|
||||
return null;
|
||||
return mMMKV.decodeString(key + "_mmkv", null);
|
||||
}
|
||||
StringBuilder sb = new StringBuilder();
|
||||
int len = 0;
|
||||
@@ -161,11 +164,13 @@ public class CacheHelper {
|
||||
return sb.toString();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
Log.e(TAG, "getAsString: " + e.getMessage());
|
||||
if (inputStream != null) {
|
||||
try {
|
||||
inputStream.close();
|
||||
} catch (IOException e1) {
|
||||
e1.printStackTrace();
|
||||
Log.e(TAG, "getAsString: " + e1.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -379,6 +384,7 @@ public class CacheHelper {
|
||||
|
||||
public void delete() throws IOException {
|
||||
mDiskLruCache.delete();
|
||||
mMMKV.clearAll();
|
||||
}
|
||||
|
||||
public void flush() throws IOException {
|
||||
@@ -422,6 +428,7 @@ public class CacheHelper {
|
||||
return edit;
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
Log.e(TAG, "editor: " + e.getMessage());
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
@@ -40,7 +40,6 @@ public class ConnectManager {
|
||||
throw new RuntimeException("Context is NULL");
|
||||
}
|
||||
this.mContext = context;
|
||||
|
||||
}
|
||||
|
||||
public static void init(Context context) {
|
||||
@@ -103,13 +102,16 @@ public class ConnectManager {
|
||||
return false;
|
||||
}
|
||||
long nowTime = System.currentTimeMillis();
|
||||
long lastTime = mMMKV.decodeLong(key, 0);
|
||||
long lastTime = mMMKV.decodeLong(key);
|
||||
// long lastTime = (long) SPUtils.get(mContext, key, 0L);
|
||||
Log.e(TAG, "isNeedConnect: key = " + key + "\ttime = " + lastTime);
|
||||
long intervalTime = getConnectModeTime(connectMode);
|
||||
//防止一分钟内重复请求
|
||||
return nowTime - lastTime > intervalTime && nowTime - lastTime > ONE_MINUTES_TIME;
|
||||
boolean refresh = nowTime - lastTime > intervalTime && nowTime - lastTime > ONE_MINUTES_TIME;
|
||||
Log.e(TAG, "isNeedConnect: " + refresh);
|
||||
return refresh;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return 重启后是否连接
|
||||
*/
|
||||
|
||||
@@ -22,6 +22,7 @@ import com.aoleyun.sn.bean.AppUpdateInfo;
|
||||
import com.aoleyun.sn.bean.Appground;
|
||||
import com.aoleyun.sn.bean.BaseResponse;
|
||||
import com.aoleyun.sn.bean.Batch;
|
||||
import com.aoleyun.sn.bean.BatteryInfo;
|
||||
import com.aoleyun.sn.bean.BrowserBookmarks;
|
||||
import com.aoleyun.sn.bean.BrowserData;
|
||||
import com.aoleyun.sn.bean.CustomROMApp;
|
||||
@@ -61,6 +62,7 @@ import com.aoleyun.sn.network.api.get.SnTimeControlApi;
|
||||
import com.aoleyun.sn.network.api.get.TopAppControlApi;
|
||||
import com.aoleyun.sn.network.api.post.AppLimitApi;
|
||||
import com.aoleyun.sn.network.api.post.AppinsideWebApi;
|
||||
import com.aoleyun.sn.network.api.post.BatteryInfoApi;
|
||||
import com.aoleyun.sn.network.api.post.BrowserBookmarksApi;
|
||||
import com.aoleyun.sn.network.api.post.BrowserListApi;
|
||||
import com.aoleyun.sn.network.api.post.CheckUpdateApi;
|
||||
@@ -656,6 +658,10 @@ public class NetInterfaceManager {
|
||||
return mRetrofit.create(GetUploadIsLogApi.class);
|
||||
}
|
||||
|
||||
public BatteryInfoApi getBatteryInfoApi() {
|
||||
return mRetrofit.create(BatteryInfoApi.class);
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
* execution
|
||||
@@ -1954,7 +1960,7 @@ public class NetInterfaceManager {
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置推送得标签
|
||||
* 设置推送的标签
|
||||
*
|
||||
* @param lifecycle
|
||||
* @param callback
|
||||
@@ -3433,4 +3439,51 @@ public class NetInterfaceManager {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void sendBatteryInfo(BatteryInfo info) {
|
||||
if (info == null) {
|
||||
Log.e(TAG, "sendBatteryInfo: " + "BatteryInfo is NULL");
|
||||
return;
|
||||
}
|
||||
getBatteryInfoApi()
|
||||
.sendBatteryInfo(Utils.getSerial(), HTTP_KEY,
|
||||
info.getBattery_quantity(),
|
||||
info.getBattery_temperature(),
|
||||
info.getBattery_voltage(),
|
||||
info.getCharge_current(),
|
||||
info.getCharge_voltage(),
|
||||
info.getBattery_status(),
|
||||
info.getCharge_type(),
|
||||
info.getCharge_current_max(),
|
||||
info.getCharge_voltage_max(),
|
||||
info.getBattery_health(),
|
||||
info.getQuantity_max(),
|
||||
info.getBattery_desc(),
|
||||
info.getCharge_speed()
|
||||
)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Observer<BaseResponse>() {
|
||||
@Override
|
||||
public void onSubscribe(@NonNull Disposable d) {
|
||||
Log.e("sendBatteryInfo", "onSubscribe: ");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(@NonNull BaseResponse baseResponse) {
|
||||
Log.e("sendBatteryInfo", "onNext: " + baseResponse);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(@NonNull Throwable e) {
|
||||
Log.e("sendBatteryInfo", "onError: ");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
Log.e("sendBatteryInfo", "onComplete: ");
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,6 +66,8 @@ public class UrlAddress {
|
||||
public static final String GET_LOCK_STATE = "Application/getLockState";
|
||||
/*获取霸屏状态*/
|
||||
public static final String GET_LOCK_SCREEN_STATE = "Sn/getSnScreen";
|
||||
/*上传电池信息*/
|
||||
public static final String SEND_BATTERY_INFO = "And/sn/updateBatteryInfo";
|
||||
|
||||
/**
|
||||
* 系统策略相关
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
package com.aoleyun.sn.network.api.post;
|
||||
|
||||
import com.aoleyun.sn.bean.BaseResponse;
|
||||
import com.aoleyun.sn.network.UrlAddress;
|
||||
|
||||
import io.reactivex.rxjava3.core.Observable;
|
||||
import retrofit2.http.Field;
|
||||
import retrofit2.http.FormUrlEncoded;
|
||||
import retrofit2.http.POST;
|
||||
|
||||
public interface BatteryInfoApi {
|
||||
@FormUrlEncoded
|
||||
@POST(UrlAddress.SEND_BATTERY_INFO)
|
||||
Observable<BaseResponse> sendBatteryInfo(
|
||||
@Field("sn") String sn,
|
||||
@Field("key") String key,
|
||||
@Field("battery_quantity") String battery_quantity,
|
||||
@Field("battery_temperature") String battery_temperature,
|
||||
@Field("battery_voltage") String battery_voltage,
|
||||
@Field("charge_current") String charge_current,
|
||||
@Field("charge_voltage") String charge_voltage,
|
||||
@Field("battery_status") String battery_status,
|
||||
@Field("charge_type") String charge_type,
|
||||
@Field("charge_current_max") String charge_current_max,
|
||||
@Field("charge_voltage_max") String charge_voltage_max,
|
||||
@Field("battery_health") String battery_health,
|
||||
@Field("quantity_max") String quantity_max,
|
||||
@Field("battery_desc") String battery_desc,
|
||||
@Field("charge_speed") String charge_speed
|
||||
);
|
||||
}
|
||||
@@ -13,9 +13,14 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
import okhttp3.Interceptor;
|
||||
import okhttp3.Protocol;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.RequestBody;
|
||||
import okhttp3.Response;
|
||||
import okhttp3.ResponseBody;
|
||||
import okio.Buffer;
|
||||
|
||||
/**
|
||||
* v1.0 2022-07-15 16:16:52
|
||||
*/
|
||||
public class RepeatRequestInterceptor implements Interceptor {
|
||||
private static final String TAG = RepeatRequestInterceptor.class.getSimpleName();
|
||||
|
||||
@@ -26,8 +31,18 @@ public class RepeatRequestInterceptor implements Interceptor {
|
||||
@Override
|
||||
public Response intercept(@NotNull Chain chain) throws IOException {
|
||||
Request request = chain.request();
|
||||
Response response = chain.proceed(request);
|
||||
ResponseBody responseBody = response.body();
|
||||
|
||||
//会消费请求,导致请求多次
|
||||
String content = responseBody.string();
|
||||
// Response copy = response.newBuilder().body(responseBody).build();
|
||||
ResponseBody copy = ResponseBody.create(responseBody.contentType(), content);
|
||||
if (BuildConfig.DEBUG) {
|
||||
Log.e(TAG, "请求体返回:| Response: " + request.url().encodedPath() + "\t body: " + content);
|
||||
}
|
||||
//相同的请求
|
||||
String requestKey = MD5Util.getUpperMD5Str(request.method() + request.url().toString() + request.body());
|
||||
String requestKey = MD5Util.getUpperMD5Str(request.method() + request.url().toString() + requestBodyToString(request.body()));
|
||||
long time = System.currentTimeMillis();//请求时间
|
||||
try {
|
||||
if (requestIdsMap.size() > 0 && requestIdsMap.containsKey(requestKey)) {
|
||||
@@ -43,7 +58,7 @@ public class RepeatRequestInterceptor implements Interceptor {
|
||||
log("注册请求:", requestKey, request);
|
||||
// RepeatRequestInterceptor.Builder builder = request.newBuilder();
|
||||
// builder.addHeader("header", jsonObject.toString());
|
||||
return chain.proceed(request);
|
||||
return response.newBuilder().body(copy).build();
|
||||
} catch (IOException e) {
|
||||
Log.e(TAG, "intercept: " + e.getMessage());
|
||||
throw e;
|
||||
@@ -59,7 +74,7 @@ public class RepeatRequestInterceptor implements Interceptor {
|
||||
if (BuildConfig.DEBUG) {
|
||||
Log.e("REPEAT-REQUEST", action + requestKey + " Method @" + request.method() + " --- " + " URL = " + request.url().encodedPath() + "\t" + bodyToString(request));
|
||||
} else {
|
||||
Log.e("REPEAT-REQUEST", action + requestKey + " Method @" + request.method() + " --- " + " URL = " + request.url().encodedPath());
|
||||
Log.e("REPEAT-REQUEST", action + requestKey + " Method @" + request.method());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,10 +83,25 @@ public class RepeatRequestInterceptor implements Interceptor {
|
||||
final Request copy = request.newBuilder().build();
|
||||
final Buffer buffer = new Buffer();
|
||||
copy.body().writeTo(buffer);
|
||||
if (buffer.size() > 4096) {
|
||||
return "-too long";
|
||||
}
|
||||
return buffer.readUtf8();
|
||||
} catch (Exception e) {
|
||||
return "-";
|
||||
}
|
||||
}
|
||||
|
||||
private static String requestBodyToString(RequestBody body) {
|
||||
try {
|
||||
final Buffer buffer = new Buffer();
|
||||
body.writeTo(buffer);
|
||||
if (buffer.size() > 4096) {
|
||||
return "-too long";
|
||||
}
|
||||
return buffer.readUtf8();
|
||||
} catch (Exception e) {
|
||||
return "-";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import android.util.Log;
|
||||
|
||||
import com.aoleyun.sn.SystemInfoInterface;
|
||||
import com.aoleyun.sn.comm.PackageNames;
|
||||
import com.aoleyun.sn.utils.CacheUtils;
|
||||
import com.aoleyun.sn.utils.ForegroundAppUtil;
|
||||
import com.aoleyun.sn.utils.JGYUtils;
|
||||
import com.aoleyun.sn.utils.SPUtils;
|
||||
@@ -71,11 +72,22 @@ public class RemoteService extends Service {
|
||||
|
||||
@Override
|
||||
public void setDefaultDesktop(String pkg) throws RemoteException {
|
||||
JGYUtils.getInstance().setDefaultDesktop(pkg);
|
||||
Log.e(TAG, "setDefaultDesktop: " + "pkg = " + pkg);
|
||||
SPUtils.put(RemoteService.this, "default_launcher", pkg);
|
||||
JGYUtils.getInstance().setDefaultDesktop(pkg);
|
||||
if (PackageNames.DESKTOP.equals(pkg)) {
|
||||
// JGYUtils.getInstance().killPackage(PackageNames.DESKTOP);
|
||||
try {
|
||||
new CacheUtils().cleanApplicationUserData(RemoteService.this, PackageNames.DESKTOP);
|
||||
new CacheUtils().cleanApplicationUserData(RemoteService.this, PackageNames.APPSTORE);
|
||||
new CacheUtils().cleanApplicationUserData(RemoteService.this, "com.aoleyunos.dop2");
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "onReceive: " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
JGYUtils.getInstance().killPackage("com.aoleyunos.dop2");
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -251,6 +251,7 @@ public class MainSPresenter implements MainSContact.Presenter {
|
||||
|
||||
@Override
|
||||
public void getDefaultDesktop() {
|
||||
Log.e(TAG, "getDefaultDesktop: " );
|
||||
if (JGYUtils.isOfficialVersion() || !JGYUtils.getInstance().getDeviceIsLocked()) {
|
||||
mView.getDefaultDesktopFinish();
|
||||
} else {
|
||||
|
||||
@@ -22,8 +22,8 @@ import android.widget.Toast;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.aoleyun.sn.R;
|
||||
import com.aoleyun.sn.base.BaseApplication;
|
||||
import com.aoleyun.sn.bean.BaseResponse;
|
||||
import com.aoleyun.sn.bean.BatteryInfo;
|
||||
import com.aoleyun.sn.bean.DownloadInfo;
|
||||
import com.aoleyun.sn.bean.RemoteDebug;
|
||||
import com.aoleyun.sn.bean.ScreenLockState;
|
||||
@@ -39,6 +39,7 @@ import com.aoleyun.sn.service.main.MainService;
|
||||
import com.aoleyun.sn.tpush.common.NotificationService;
|
||||
import com.aoleyun.sn.tpush.po.XGNotification;
|
||||
import com.aoleyun.sn.utils.ApkUtils;
|
||||
import com.aoleyun.sn.utils.BatteryUtils;
|
||||
import com.aoleyun.sn.utils.CacheUtils;
|
||||
import com.aoleyun.sn.utils.CmdUtil;
|
||||
import com.aoleyun.sn.utils.ForegroundAppUtil;
|
||||
@@ -170,6 +171,8 @@ public class MessageReceiver extends XGPushBaseReceiver {
|
||||
/*添加wifi*/
|
||||
private final String UPDATE_WIFI_PW = "38";
|
||||
/*远程关机*/
|
||||
private final String DEVICES_SHUTDOWN_NOW = "40";
|
||||
/*远程定时关机*/
|
||||
private final String DEVICES_POWEROFF = "41";
|
||||
/*远程log*/
|
||||
private final String SN_RUN_LOG = "43";
|
||||
@@ -179,6 +182,9 @@ public class MessageReceiver extends XGPushBaseReceiver {
|
||||
private final String CLEAN_MEMORY = "47";
|
||||
/*运行日志设置*/
|
||||
private final String SN_LOG_SETTING = "48";
|
||||
/*上传电池信息*/
|
||||
private final String INFO_BATTERY_INFO = "53";
|
||||
|
||||
|
||||
private Context mContext;
|
||||
private ContentResolver mResolver;
|
||||
@@ -457,8 +463,6 @@ public class MessageReceiver extends XGPushBaseReceiver {
|
||||
}
|
||||
|
||||
switch (title) {
|
||||
default:
|
||||
break;
|
||||
case MSG_DELETE:
|
||||
ToastUtil.betaShow("收到管控:应用删除");
|
||||
if (!TextUtils.isEmpty(extras)) {
|
||||
@@ -610,6 +614,7 @@ public class MessageReceiver extends XGPushBaseReceiver {
|
||||
break;
|
||||
case GET_DEVICES_INFO:
|
||||
ToastUtil.betaShow("收到管控:获取设备信息");
|
||||
getBatteryInfo(context);
|
||||
if (MainService.mPresenter != null) {
|
||||
MainService.mPresenter.getLockedState("XGPush");
|
||||
MainService.mPresenter.sendMACAddress();
|
||||
@@ -779,6 +784,9 @@ public class MessageReceiver extends XGPushBaseReceiver {
|
||||
case UPDATE_WIFI_PW:
|
||||
NetInterfaceManager.getInstance().getWiFiPasswd();
|
||||
break;
|
||||
case DEVICES_SHUTDOWN_NOW:
|
||||
JGYUtils.getInstance().shutdown();
|
||||
break;
|
||||
case DEVICES_POWEROFF:
|
||||
NetInterfaceManager.getInstance().getPoweroffTime();
|
||||
break;
|
||||
@@ -794,6 +802,10 @@ public class MessageReceiver extends XGPushBaseReceiver {
|
||||
case SN_LOG_SETTING:
|
||||
senSNLogFile(extras);
|
||||
break;
|
||||
case INFO_BATTERY_INFO:
|
||||
getBatteryInfo(context);
|
||||
break;
|
||||
default:
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1393,4 +1405,15 @@ public class MessageReceiver extends XGPushBaseReceiver {
|
||||
}
|
||||
}
|
||||
|
||||
private void getBatteryInfo(Context context) {
|
||||
IntentFilter filter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
|
||||
Intent receiver = context.registerReceiver(null, filter);
|
||||
String jsonString = BatteryUtils.getBatteryJson(context, receiver).toString();
|
||||
Gson gson = new Gson();
|
||||
Type type = new TypeToken<BatteryInfo>() {
|
||||
}.getType();
|
||||
BatteryInfo batteryInfo = gson.fromJson(jsonString, type);
|
||||
NetInterfaceManager.getInstance().sendBatteryInfo(batteryInfo);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
336
app/src/main/java/com/aoleyun/sn/utils/BatteryUtils.java
Normal file
336
app/src/main/java/com/aoleyun/sn/utils/BatteryUtils.java
Normal file
@@ -0,0 +1,336 @@
|
||||
package com.aoleyun.sn.utils;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
|
||||
import com.aoleyun.sn.R;
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
|
||||
import static android.os.BatteryManager.BATTERY_HEALTH_COLD;
|
||||
import static android.os.BatteryManager.BATTERY_HEALTH_DEAD;
|
||||
import static android.os.BatteryManager.BATTERY_HEALTH_GOOD;
|
||||
import static android.os.BatteryManager.BATTERY_HEALTH_OVERHEAT;
|
||||
import static android.os.BatteryManager.BATTERY_HEALTH_OVER_VOLTAGE;
|
||||
import static android.os.BatteryManager.BATTERY_HEALTH_UNKNOWN;
|
||||
import static android.os.BatteryManager.BATTERY_HEALTH_UNSPECIFIED_FAILURE;
|
||||
import static android.os.BatteryManager.BATTERY_PLUGGED_AC;
|
||||
import static android.os.BatteryManager.BATTERY_PLUGGED_ANY;
|
||||
import static android.os.BatteryManager.BATTERY_PLUGGED_USB;
|
||||
import static android.os.BatteryManager.BATTERY_PLUGGED_WIRELESS;
|
||||
import static android.os.BatteryManager.BATTERY_STATUS_CHARGING;
|
||||
import static android.os.BatteryManager.BATTERY_STATUS_DISCHARGING;
|
||||
import static android.os.BatteryManager.BATTERY_STATUS_FULL;
|
||||
import static android.os.BatteryManager.BATTERY_STATUS_NOT_CHARGING;
|
||||
import static android.os.BatteryManager.BATTERY_STATUS_UNKNOWN;
|
||||
import static android.os.BatteryManager.EXTRA_HEALTH;
|
||||
import static android.os.BatteryManager.EXTRA_LEVEL;
|
||||
import static android.os.BatteryManager.EXTRA_MAX_CHARGING_CURRENT;
|
||||
import static android.os.BatteryManager.EXTRA_MAX_CHARGING_VOLTAGE;
|
||||
import static android.os.BatteryManager.EXTRA_PLUGGED;
|
||||
import static android.os.BatteryManager.EXTRA_SCALE;
|
||||
import static android.os.BatteryManager.EXTRA_STATUS;
|
||||
import static android.os.BatteryManager.EXTRA_TECHNOLOGY;
|
||||
import static android.os.BatteryManager.EXTRA_TEMPERATURE;
|
||||
import static android.os.BatteryManager.EXTRA_VOLTAGE;
|
||||
|
||||
public class BatteryUtils {
|
||||
|
||||
private static final int DEFAULT_CHARGING_VOLTAGE_MICRO_VOLT = 5000000;
|
||||
|
||||
public static String getBatteryStatus(Context context, Intent intent) {
|
||||
int status = intent.getIntExtra(EXTRA_STATUS, BATTERY_STATUS_UNKNOWN);
|
||||
int plugged = intent.getIntExtra(EXTRA_PLUGGED, BATTERY_PLUGGED_ANY);
|
||||
int level = intent.getIntExtra(EXTRA_LEVEL, 0);
|
||||
int scale = intent.getIntExtra(EXTRA_SCALE, 0);
|
||||
int health = intent.getIntExtra(EXTRA_HEALTH, BATTERY_HEALTH_UNKNOWN);
|
||||
|
||||
int maxChargingMicroAmp = intent.getIntExtra(EXTRA_MAX_CHARGING_CURRENT, -1);
|
||||
int maxChargingMicroVolt = intent.getIntExtra(EXTRA_MAX_CHARGING_VOLTAGE, -1);
|
||||
int batteryVolt = intent.getIntExtra(EXTRA_VOLTAGE, -1);
|
||||
int temperature = intent.getIntExtra(EXTRA_TEMPERATURE, -1);
|
||||
String batteryTechnologyDescript = intent.getStringExtra(EXTRA_TECHNOLOGY);
|
||||
|
||||
final int maxChargingMicroWatt;
|
||||
|
||||
if (maxChargingMicroVolt <= 0) {
|
||||
maxChargingMicroVolt = DEFAULT_CHARGING_VOLTAGE_MICRO_VOLT;
|
||||
}
|
||||
if (maxChargingMicroAmp > 0) {
|
||||
// Calculating muW = muA * muV / (10^6 mu^2 / mu); splitting up the divisor
|
||||
// to maintain precision equally on both factors.
|
||||
maxChargingMicroWatt = (maxChargingMicroAmp / 1000)
|
||||
* (maxChargingMicroVolt / 1000);
|
||||
} else {
|
||||
maxChargingMicroWatt = -1;
|
||||
}
|
||||
|
||||
String statusStr = getStatus(context, status);
|
||||
String healthStr = getHealth(context, health);
|
||||
String pluggedStr = getPlugged(context, plugged);
|
||||
String levelStr = getLevel(level);
|
||||
String scaleStr = getLevel(scale);
|
||||
String temperatureStr = getTemperature(temperature);
|
||||
String batteryVoltStr = getBatteryVolt(batteryVolt);
|
||||
String maxChargingMicroAmpStr = getMaxChargingMicroAmp(maxChargingMicroAmp);
|
||||
String maxChargingMicroVoltStr = getMaxChargingMicroVolt(maxChargingMicroVolt);
|
||||
|
||||
int currentChargingCurrent = getCurrentChargingCurrent();
|
||||
String currentChargingCurrentStr = getCurrentChargingCurrentStr(currentChargingCurrent);
|
||||
int currentChargingVoltage = getCurrentChargingVoltage();
|
||||
String currentChargingVoltageStr = getCurrentChargingVoltageStr(currentChargingVoltage);
|
||||
|
||||
|
||||
String result = "\n" + context.getString(R.string.battery_current_level) + levelStr
|
||||
+ "\n" + context.getString(R.string.battery_current_temperature) + temperatureStr
|
||||
+ "\n" + context.getString(R.string.battery_current_volt) + batteryVoltStr
|
||||
+ "\n" + context.getString(R.string.battery_current_charging_current) + currentChargingCurrentStr
|
||||
+ "\n" + context.getString(R.string.battery_current_charging_voltage) + currentChargingVoltageStr
|
||||
+ "\n" + context.getString(R.string.battery_status_titls) + statusStr
|
||||
+ "\n" + context.getString(R.string.battery_plugged_titls) + pluggedStr
|
||||
+ "\n" + context.getString(R.string.battery_max_charging_current) + maxChargingMicroAmpStr
|
||||
+ "\n" + context.getString(R.string.battery_max_charging_voltage) + maxChargingMicroVoltStr
|
||||
+ "\n" + context.getString(R.string.battery_health_titls) + healthStr
|
||||
+ "\n" + context.getString(R.string.battery_max_level) + scaleStr
|
||||
+ "\n" + context.getString(R.string.battery_technology_describing) + batteryTechnologyDescript
|
||||
+ "\n充电速度 = " + maxChargingMicroWatt
|
||||
+ "\n";
|
||||
return result;
|
||||
}
|
||||
|
||||
public static JsonObject getBatteryJson(Context context, Intent intent) {
|
||||
int status = intent.getIntExtra(EXTRA_STATUS, BATTERY_STATUS_UNKNOWN);
|
||||
int plugged = intent.getIntExtra(EXTRA_PLUGGED, BATTERY_PLUGGED_ANY);
|
||||
int level = intent.getIntExtra(EXTRA_LEVEL, 0);
|
||||
int scale = intent.getIntExtra(EXTRA_SCALE, 0);
|
||||
int health = intent.getIntExtra(EXTRA_HEALTH, BATTERY_HEALTH_UNKNOWN);
|
||||
|
||||
int maxChargingMicroAmp = intent.getIntExtra(EXTRA_MAX_CHARGING_CURRENT, -1);
|
||||
int maxChargingMicroVolt = intent.getIntExtra(EXTRA_MAX_CHARGING_VOLTAGE, -1);
|
||||
int batteryVolt = intent.getIntExtra(EXTRA_VOLTAGE, -1);
|
||||
int temperature = intent.getIntExtra(EXTRA_TEMPERATURE, -1);
|
||||
String batteryTechnologyDescript = intent.getStringExtra(EXTRA_TECHNOLOGY);
|
||||
|
||||
final int maxChargingMicroWatt;
|
||||
|
||||
if (maxChargingMicroVolt <= 0) {
|
||||
maxChargingMicroVolt = DEFAULT_CHARGING_VOLTAGE_MICRO_VOLT;
|
||||
}
|
||||
if (maxChargingMicroAmp > 0) {
|
||||
// Calculating muW = muA * muV / (10^6 mu^2 / mu); splitting up the divisor
|
||||
// to maintain precision equally on both factors.
|
||||
maxChargingMicroWatt = (maxChargingMicroAmp / 1000)
|
||||
* (maxChargingMicroVolt / 1000);
|
||||
} else {
|
||||
maxChargingMicroWatt = -1;
|
||||
}
|
||||
|
||||
String statusStr = getStatus(context, status);
|
||||
String healthStr = getHealth(context, health);
|
||||
String pluggedStr = getPlugged(context, plugged);
|
||||
String levelStr = getLevel(level);
|
||||
String scaleStr = getLevel(scale);
|
||||
String temperatureStr = getTemperature(temperature);
|
||||
String batteryVoltStr = getBatteryVolt(batteryVolt);
|
||||
String maxChargingMicroAmpStr = getMaxChargingMicroAmp(maxChargingMicroAmp);
|
||||
String maxChargingMicroVoltStr = getMaxChargingMicroVolt(maxChargingMicroVolt);
|
||||
|
||||
int currentChargingCurrent = getCurrentChargingCurrent();
|
||||
String currentChargingCurrentStr = getCurrentChargingCurrentStr(currentChargingCurrent);
|
||||
int currentChargingVoltage = getCurrentChargingVoltage();
|
||||
String currentChargingVoltageStr = getCurrentChargingVoltageStr(currentChargingVoltage);
|
||||
|
||||
JsonObject jsonObject = new JsonObject();
|
||||
jsonObject.addProperty("battery_quantity", levelStr);
|
||||
jsonObject.addProperty("battery_temperature", temperatureStr);
|
||||
jsonObject.addProperty("battery_voltage", batteryVoltStr);
|
||||
jsonObject.addProperty("charge_current", currentChargingCurrentStr);
|
||||
jsonObject.addProperty("charge_voltage", currentChargingVoltageStr);
|
||||
jsonObject.addProperty("battery_status", statusStr);
|
||||
jsonObject.addProperty("charge_type", pluggedStr);
|
||||
jsonObject.addProperty("charge_current_max", maxChargingMicroAmpStr);
|
||||
jsonObject.addProperty("charge_voltage_max", maxChargingMicroVoltStr);
|
||||
jsonObject.addProperty("battery_health", healthStr);
|
||||
jsonObject.addProperty("quantity_max", scaleStr);
|
||||
jsonObject.addProperty("battery_desc", batteryTechnologyDescript);
|
||||
jsonObject.addProperty("charge_speed", maxChargingMicroWatt);
|
||||
return jsonObject;
|
||||
}
|
||||
|
||||
|
||||
private static String getCurrentChargingVoltageStr(int currentChargingVoltage) {
|
||||
return String.format("%.3f V", currentChargingVoltage / 1000000.0);
|
||||
}
|
||||
|
||||
private static String getCurrentChargingCurrentStr(int currentChargingCurrent) {
|
||||
return String.format("%.3f A", currentChargingCurrent / 1000.0);
|
||||
}
|
||||
|
||||
/**
|
||||
* 当前充电电流 mA
|
||||
* <p>
|
||||
* adb shell "cat /sys/class/power_supply/battery/BatteryAverageCurrent"
|
||||
*/
|
||||
private static int getCurrentChargingCurrent() {
|
||||
int result = 0;
|
||||
BufferedReader br = null;
|
||||
try {
|
||||
String line;
|
||||
br = new BufferedReader(new FileReader("/sys/class/power_supply/battery/BatteryAverageCurrent"));
|
||||
if ((line = br.readLine()) != null) {
|
||||
result = Integer.parseInt(line);
|
||||
}
|
||||
|
||||
br.close();
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
if (br != null) {
|
||||
try {
|
||||
br.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 当前充电电压 uV
|
||||
* <p>
|
||||
* adb shell "cat /sys/class/power_supply/battery/batt_vol"
|
||||
*/
|
||||
private static int getCurrentChargingVoltage() {
|
||||
int result = 0;
|
||||
BufferedReader br = null;
|
||||
try {
|
||||
String line;
|
||||
br = new BufferedReader(new FileReader("/sys/class/power_supply/battery/batt_vol"));
|
||||
if ((line = br.readLine()) != null) {
|
||||
result = Integer.parseInt(line);
|
||||
}
|
||||
|
||||
br.close();
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
if (br != null) {
|
||||
try {
|
||||
br.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private static String getMaxChargingMicroVolt(int maxChargingMicroVolt) {
|
||||
return String.format("%.1f V", maxChargingMicroVolt / 1000000.0);
|
||||
}
|
||||
|
||||
private static String getMaxChargingMicroAmp(int maxChargingMicroAmp) {
|
||||
return String.format("%.1f A", maxChargingMicroAmp / 1000000.0);
|
||||
}
|
||||
|
||||
private static String getBatteryVolt(int batteryVolt) {
|
||||
return String.format("%.3f V", batteryVolt / 1000.0);
|
||||
}
|
||||
|
||||
|
||||
private static String getTemperature(int temperature) {
|
||||
return String.format("%.1f ℃", temperature / 10.0);
|
||||
}
|
||||
|
||||
private static String getLevel(int level) {
|
||||
return String.format("%d %%", level);
|
||||
}
|
||||
|
||||
private static String getPlugged(Context context, int plugged) {
|
||||
String result = context.getString(R.string.battery_plugged_any);
|
||||
|
||||
switch (plugged) {
|
||||
case BATTERY_PLUGGED_ANY:
|
||||
break;
|
||||
case BATTERY_PLUGGED_AC:
|
||||
result = context.getString(R.string.battery_plugged_ac);
|
||||
break;
|
||||
case BATTERY_PLUGGED_USB:
|
||||
result = context.getString(R.string.battery_plugged_usb);
|
||||
break;
|
||||
case BATTERY_PLUGGED_WIRELESS:
|
||||
result = context.getString(R.string.battery_plugged_wireless);
|
||||
break;
|
||||
default:
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
private static String getHealth(Context context, int health) {
|
||||
String result = context.getString(R.string.battery_health_unknow);
|
||||
|
||||
switch (health) {
|
||||
case BATTERY_HEALTH_UNKNOWN:
|
||||
break;
|
||||
case BATTERY_HEALTH_GOOD:
|
||||
result = context.getString(R.string.battery_health_good);
|
||||
break;
|
||||
case BATTERY_HEALTH_OVERHEAT:
|
||||
result = context.getString(R.string.battery_health_overheat);
|
||||
break;
|
||||
case BATTERY_HEALTH_DEAD:
|
||||
result = context.getString(R.string.battery_health_dead);
|
||||
break;
|
||||
case BATTERY_HEALTH_UNSPECIFIED_FAILURE:
|
||||
result = context.getString(R.string.battery_health_unspecified_failure);
|
||||
break;
|
||||
case BATTERY_HEALTH_OVER_VOLTAGE:
|
||||
result = context.getString(R.string.battery_health_over_voltage);
|
||||
break;
|
||||
case BATTERY_HEALTH_COLD:
|
||||
result = context.getString(R.string.battery_health_cold);
|
||||
break;
|
||||
default:
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
private static String getStatus(Context context, int status) {
|
||||
String result = context.getString(R.string.battery_status_unknown);
|
||||
|
||||
switch (status) {
|
||||
case BATTERY_STATUS_FULL:
|
||||
result = context.getString(R.string.battery_status_full);
|
||||
break;
|
||||
case BATTERY_STATUS_NOT_CHARGING:
|
||||
result = context.getString(R.string.battery_status_not_charging);
|
||||
break;
|
||||
case BATTERY_STATUS_DISCHARGING:
|
||||
result = context.getString(R.string.battery_status_discharging);
|
||||
break;
|
||||
case BATTERY_STATUS_CHARGING:
|
||||
result = context.getString(R.string.battery_status_charging);
|
||||
break;
|
||||
case BATTERY_STATUS_UNKNOWN:
|
||||
break;
|
||||
default:
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -2109,7 +2109,7 @@ public class JGYUtils {
|
||||
} else {
|
||||
//爱华设置,暂时屏蔽
|
||||
// setDefaultLauncher(mContext, pkg, className);
|
||||
Log.e(TAG, "setDefaultDesktop: setDefaultLauncher");
|
||||
Log.e(TAG, "setDefaultDesktop: setDefaultLauncher: " + pkg);
|
||||
}
|
||||
// String oldDesktop = (String) SPUtils.get(mContext, "default_launcher", "");
|
||||
// if (Objects.equals(oldDesktop, pkg)) {
|
||||
|
||||
Reference in New Issue
Block a user