version:beta
fix: update:增加一些电量设置
This commit is contained in:
@@ -9,6 +9,7 @@ import android.content.IntentFilter;
|
||||
import android.content.ServiceConnection;
|
||||
import android.os.BatteryManager;
|
||||
import android.os.Build;
|
||||
import android.os.Environment;
|
||||
import android.os.IBinder;
|
||||
import android.os.SystemClock;
|
||||
import android.provider.Settings;
|
||||
@@ -22,6 +23,7 @@ import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.aoleyun.sn.BuildConfig;
|
||||
import com.aoleyun.sn.KeepAliveConnection;
|
||||
import com.aoleyun.sn.R;
|
||||
import com.aoleyun.sn.bean.BaseResponse;
|
||||
import com.aoleyun.sn.comm.CommonConfig;
|
||||
import com.aoleyun.sn.comm.PackageNames;
|
||||
@@ -33,9 +35,11 @@ import com.aoleyun.sn.receiver.NewAppReceiver;
|
||||
import com.aoleyun.sn.rlog.LogDBManager;
|
||||
import com.aoleyun.sn.service.main.MainService;
|
||||
import com.aoleyun.sn.utils.ApkUtils;
|
||||
import com.aoleyun.sn.utils.CmdUtil;
|
||||
import com.aoleyun.sn.utils.JGYUtils;
|
||||
import com.aoleyun.sn.utils.SPUtils;
|
||||
import com.aoleyun.sn.utils.ServiceAliveUtils;
|
||||
import com.aoleyun.sn.utils.TimeUtils;
|
||||
import com.aoleyun.sn.utils.ToastUtil;
|
||||
import com.aoleyun.sn.utils.Utils;
|
||||
import com.aoleyun.sn.utils.XAPKUtils;
|
||||
@@ -44,10 +48,16 @@ import com.arialyy.aria.core.Aria;
|
||||
import com.arialyy.aria.core.task.DownloadTask;
|
||||
import com.baidu.location.LocationClient;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.rxjava3.annotations.NonNull;
|
||||
import io.reactivex.rxjava3.core.Observable;
|
||||
import io.reactivex.rxjava3.core.ObservableEmitter;
|
||||
import io.reactivex.rxjava3.core.ObservableOnSubscribe;
|
||||
@@ -59,6 +69,33 @@ import retrofit2.Retrofit;
|
||||
import retrofit2.adapter.rxjava3.RxJava3CallAdapterFactory;
|
||||
import retrofit2.converter.gson.GsonConverterFactory;
|
||||
|
||||
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;
|
||||
|
||||
|
||||
/**
|
||||
* 守护进程 双进程通讯
|
||||
@@ -335,8 +372,7 @@ public class GuardService extends Service {
|
||||
|
||||
/**
|
||||
* @param status
|
||||
* @param time
|
||||
* 和锁屏状态无关,记录设备使用时长的
|
||||
* @param time 和锁屏状态无关,记录设备使用时长的
|
||||
*/
|
||||
private void getLockState(String status, String time) {
|
||||
if (JGYUtils.isOfficialVersion()) {
|
||||
@@ -408,11 +444,12 @@ public class GuardService extends Service {
|
||||
if (elec == 50) {
|
||||
start.onstar(SystemClock.elapsedRealtime());
|
||||
}
|
||||
writeLog2File("batteryInfo.txt", recordBatteryInfo(intent));
|
||||
dumpBatterystats();
|
||||
} else {
|
||||
if (Intent.ACTION_POWER_CONNECTED.equals(action)) {
|
||||
LogDBManager.getInstance().creatOtherLog(LogDBManager.LOG_EVENT_BATTERY,
|
||||
"开始充电", "electricity: " + JGYUtils.getInstance().getBatteryLevel() + "%");
|
||||
|
||||
}
|
||||
if (Intent.ACTION_POWER_DISCONNECTED.equals(action)) {
|
||||
LogDBManager.getInstance().creatOtherLog(LogDBManager.LOG_EVENT_BATTERY,
|
||||
@@ -426,7 +463,7 @@ public class GuardService extends Service {
|
||||
LogDBManager.getInstance().creatOtherLog(LogDBManager.LOG_EVENT_BATTERY,
|
||||
"电量充足", "electricity: " + JGYUtils.getInstance().getBatteryLevel() + "%");
|
||||
}
|
||||
|
||||
recordBattery("电量充足\t" + "electricity: " + JGYUtils.getInstance().getBatteryLevel() + "%");
|
||||
setDefaultUSBStatus();
|
||||
Log.e(TAG, action);
|
||||
start.onstar(SystemClock.elapsedRealtime());
|
||||
@@ -434,6 +471,310 @@ public class GuardService extends Service {
|
||||
}
|
||||
}
|
||||
|
||||
private void recordBattery(String s) {
|
||||
Log.e(TAG, "recordBattery: " + writeLog2File("battery.txt", s));
|
||||
}
|
||||
|
||||
private void dumpBatterystats() {
|
||||
Observable.create(new ObservableOnSubscribe<StringBuffer>() {
|
||||
@Override
|
||||
public void subscribe(@NonNull ObservableEmitter<StringBuffer> emitter) throws Throwable {
|
||||
StringBuffer shellExec = CmdUtil.shellExec(" dumpsys batterystats");
|
||||
emitter.onNext(shellExec);
|
||||
}
|
||||
}).subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Observer<StringBuffer>() {
|
||||
@Override
|
||||
public void onSubscribe(@NonNull Disposable d) {
|
||||
Log.e("debugTest", "onSubscribe: ");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(StringBuffer result) {
|
||||
Log.e("debugTest", "onNext: " + result.toString());
|
||||
Log.e("debugTest", "writeLog2File: " + writeLog2File(result));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(@NonNull Throwable e) {
|
||||
Log.e("debugTest", "onError: " + e.getMessage());
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
Log.e("debugTest", "onComplete: ");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static final int DEFAULT_CHARGING_VOLTAGE_MICRO_VOLT = 5000000;
|
||||
|
||||
private String recordBatteryInfo(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(status);
|
||||
String healthStr = getHealth(health);
|
||||
String pluggedStr = getPlugged(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" + getString(R.string.battery_current_level) + levelStr
|
||||
+ "\n" + getString(R.string.battery_current_temperature) + temperatureStr
|
||||
+ "\n" + getString(R.string.battery_current_volt) + batteryVoltStr
|
||||
+ "\n" + getString(R.string.battery_current_charging_current) + currentChargingCurrentStr
|
||||
+ "\n" + getString(R.string.battery_current_charging_voltage) + currentChargingVoltageStr
|
||||
+ "\n" + getString(R.string.battery_status_titls) + statusStr
|
||||
+ "\n" + getString(R.string.battery_plugged_titls) + pluggedStr
|
||||
+ "\n" + getString(R.string.battery_max_charging_current) + maxChargingMicroAmpStr
|
||||
+ "\n" + getString(R.string.battery_max_charging_voltage) + maxChargingMicroVoltStr
|
||||
+ "\n" + getString(R.string.battery_health_titls) + healthStr
|
||||
+ "\n" + getString(R.string.battery_max_level) + scaleStr
|
||||
+ "\n" + getString(R.string.battery_technology_describing) + batteryTechnologyDescript
|
||||
+ "\n充电速度 = " + maxChargingMicroWatt
|
||||
+ "\n";
|
||||
return result;
|
||||
}
|
||||
|
||||
private String getCurrentChargingVoltageStr(int currentChargingVoltage) {
|
||||
return String.format("%.3f V", currentChargingVoltage / 1000000.0);
|
||||
}
|
||||
|
||||
private String getCurrentChargingCurrentStr(int currentChargingCurrent) {
|
||||
return String.format("%.3f A", currentChargingCurrent / 1000.0);
|
||||
}
|
||||
|
||||
/**
|
||||
* 当前充电电流 mA
|
||||
* <p>
|
||||
* adb shell "cat /sys/class/power_supply/battery/BatteryAverageCurrent"
|
||||
*/
|
||||
private 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 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 String getMaxChargingMicroVolt(int maxChargingMicroVolt) {
|
||||
return String.format("%.1f V", maxChargingMicroVolt / 1000000.0);
|
||||
}
|
||||
|
||||
private String getMaxChargingMicroAmp(int maxChargingMicroAmp) {
|
||||
return String.format("%.1f A", maxChargingMicroAmp / 1000000.0);
|
||||
}
|
||||
|
||||
private String getBatteryVolt(int batteryVolt) {
|
||||
return String.format("%.3f V", batteryVolt / 1000.0);
|
||||
}
|
||||
|
||||
|
||||
private String getTemperature(int temperature) {
|
||||
return String.format("%.1f ℃", temperature / 10.0);
|
||||
}
|
||||
|
||||
private String getLevel(int level) {
|
||||
return String.format("%d %%", level);
|
||||
}
|
||||
|
||||
private String getPlugged(int plugged) {
|
||||
String result = getString(R.string.battery_plugged_any);
|
||||
|
||||
switch (plugged) {
|
||||
case BATTERY_PLUGGED_ANY:
|
||||
break;
|
||||
case BATTERY_PLUGGED_AC:
|
||||
result = getString(R.string.battery_plugged_ac);
|
||||
break;
|
||||
case BATTERY_PLUGGED_USB:
|
||||
result = getString(R.string.battery_plugged_usb);
|
||||
break;
|
||||
case BATTERY_PLUGGED_WIRELESS:
|
||||
result = getString(R.string.battery_plugged_wireless);
|
||||
break;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
private String getHealth(int health) {
|
||||
String result = getString(R.string.battery_health_unknow);
|
||||
|
||||
switch (health) {
|
||||
case BATTERY_HEALTH_UNKNOWN:
|
||||
break;
|
||||
case BATTERY_HEALTH_GOOD:
|
||||
result = getString(R.string.battery_health_good);
|
||||
break;
|
||||
case BATTERY_HEALTH_OVERHEAT:
|
||||
result = getString(R.string.battery_health_overheat);
|
||||
break;
|
||||
case BATTERY_HEALTH_DEAD:
|
||||
result = getString(R.string.battery_health_dead);
|
||||
break;
|
||||
case BATTERY_HEALTH_UNSPECIFIED_FAILURE:
|
||||
result = getString(R.string.battery_health_unspecified_failure);
|
||||
break;
|
||||
case BATTERY_HEALTH_OVER_VOLTAGE:
|
||||
result = getString(R.string.battery_health_over_voltage);
|
||||
break;
|
||||
case BATTERY_HEALTH_COLD:
|
||||
result = getString(R.string.battery_health_cold);
|
||||
break;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
private String getStatus(int status) {
|
||||
String result = getString(R.string.battery_status_unknown);
|
||||
|
||||
switch (status) {
|
||||
case BATTERY_STATUS_FULL:
|
||||
result = getString(R.string.battery_status_full);
|
||||
break;
|
||||
case BATTERY_STATUS_NOT_CHARGING:
|
||||
result = getString(R.string.battery_status_not_charging);
|
||||
break;
|
||||
case BATTERY_STATUS_DISCHARGING:
|
||||
result = getString(R.string.battery_status_discharging);
|
||||
break;
|
||||
case BATTERY_STATUS_CHARGING:
|
||||
result = getString(R.string.battery_status_charging);
|
||||
break;
|
||||
case BATTERY_STATUS_UNKNOWN:
|
||||
break;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private boolean writeLog2File(StringBuffer stringBuffer) {
|
||||
String path = Environment.getExternalStorageDirectory() + File.separator + "aoleyun";
|
||||
File file = new File(path);
|
||||
if (!file.exists()) {
|
||||
file.mkdirs();
|
||||
}
|
||||
try {
|
||||
FileWriter fw = new FileWriter(path + File.separator + "log.txt", true);
|
||||
fw.write(TimeUtils.transferLongToDate(System.currentTimeMillis()) + "\n" + stringBuffer.toString() + "\n");
|
||||
fw.close();
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private boolean writeLog2File(String fileName, String string) {
|
||||
String path = Environment.getExternalStorageDirectory() + File.separator + "aoleyun";
|
||||
File file = new File(path);
|
||||
if (!file.exists()) {
|
||||
file.mkdirs();
|
||||
}
|
||||
try {
|
||||
FileWriter fw = new FileWriter(path + File.separator + fileName, true);
|
||||
fw.write(TimeUtils.transferLongToDate(System.currentTimeMillis()) + "\n" + string + "\n");
|
||||
fw.close();
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private void setDefaultUSBStatus() {
|
||||
String setting_usb = Settings.System.getString(getContentResolver(), "aole_usb_choose");
|
||||
Log.e("setDefaultUSBStatus", "setting_usb---------" + setting_usb);
|
||||
|
||||
Reference in New Issue
Block a user