From: TrillGates Date: Mon, 23 Aug 2021 12:10:17 +0000 (+0800) Subject: try to fixed battery low shutdown in first boot. X-Git-Url: http://git.snicker.com.cn/?a=commitdiff_plain;h=5973ce5b4a9744f947e48f9dbdbd379f5606620a;p=icsupport.git try to fixed battery low shutdown in first boot. --- diff --git a/app/src/main/java/com/enqualcomm/support/CoreService.java b/app/src/main/java/com/enqualcomm/support/CoreService.java index 0af15fc1..1b369590 100644 --- a/app/src/main/java/com/enqualcomm/support/CoreService.java +++ b/app/src/main/java/com/enqualcomm/support/CoreService.java @@ -911,16 +911,13 @@ public class CoreService extends Service { batteryUtil = new BatteryUtil(this.runtime, connection); //保证发送心跳时提前获取BatLevel数据 - int batlevel = batteryUtil.getBatteryLevel(this); - runtime.setBattery(String.format("%03d", batlevel)); - runtime.setBattery(batlevel); - ICLogger.i("Battery get from api " + batlevel); - - + int batLevel = batteryUtil.getBatteryLevel(this); + runtime.setBattery(String.format("%03d", batLevel)); + runtime.setBattery(batLevel); + ICLogger.i("Battery get from api " + batLevel); boolean charging = batteryUtil.isPowerConnected(this); runtime.setPowerConnected(charging); ICLogger.i("Charging " + charging); -// LedUtil.setRedLedOn(false); if (Config.isL03Tracker) { if (runtime.isPowerConnected()) { diff --git a/app/src/main/java/com/enqualcomm/support/ICSmsManager.java b/app/src/main/java/com/enqualcomm/support/ICSmsManager.java index a62c2f81..15f63a69 100644 --- a/app/src/main/java/com/enqualcomm/support/ICSmsManager.java +++ b/app/src/main/java/com/enqualcomm/support/ICSmsManager.java @@ -294,11 +294,9 @@ public class ICSmsManager extends BroadcastReceiver { } private static void broadCastStartFotaUpdate(Context context) { - Intent intent = new Intent(); intent.setAction(ACTION_START_FOTA_UPDATE); context.sendBroadcast(intent); - } diff --git a/app/src/main/java/com/enqualcomm/support/bean/Runtime.java b/app/src/main/java/com/enqualcomm/support/bean/Runtime.java index 014b0579..f3048e53 100644 --- a/app/src/main/java/com/enqualcomm/support/bean/Runtime.java +++ b/app/src/main/java/com/enqualcomm/support/bean/Runtime.java @@ -911,10 +911,10 @@ public class Runtime { } - private static int batterylevel = 0; + private static int batteryLevel = 0; - public int getBatterylevel() { - return batterylevel; + public int getBatteryLevel() { + return batteryLevel; } public void setBattery(String paramString) { @@ -922,7 +922,7 @@ public class Runtime { } public void setBattery(int param) { - this.batterylevel = param; + batteryLevel = param; } public void setBatteryLow(boolean paramBoolean) { @@ -930,7 +930,7 @@ public class Runtime { updateFZDDevStatusLowbat(batteryLow); //设置batterylow Alarm } - public void setBatterychanging(boolean paramBoolean) { + public void setBatteryChanging(boolean paramBoolean) { this.batterychanging = paramBoolean; } diff --git a/app/src/main/java/com/enqualcomm/support/utils/BatteryUtil.java b/app/src/main/java/com/enqualcomm/support/utils/BatteryUtil.java index 04689ade..8913b75d 100644 --- a/app/src/main/java/com/enqualcomm/support/utils/BatteryUtil.java +++ b/app/src/main/java/com/enqualcomm/support/utils/BatteryUtil.java @@ -75,7 +75,7 @@ public class BatteryUtil { ICLogger.i("Send BatteryCharging event!"); connection.send(protocolAPIHelper.getChargingMSG(1)); } - mRuntime.setBatterychanging(true); + mRuntime.setBatteryChanging(true); mRuntime.setBatteryLow(false); } else { if (mRuntime.getBatterychanging() == true) { @@ -83,7 +83,7 @@ public class BatteryUtil { ICLogger.i("Send no BatteryCharging event!"); connection.send(protocolAPIHelper.getChargingMSG(0)); } - mRuntime.setBatterychanging(false); + mRuntime.setBatteryChanging(false); } int batLevel = intent.getIntExtra(EXTRA_LEVEL, 0) * 100 / intent.getIntExtra(EXTRA_SCALE, 100); // 当前电池电压 @@ -175,7 +175,11 @@ public class BatteryUtil { public static void checkAndSendBatteryEvent(Context context, Runtime runtime) { //add by TrillGates======start - if (runtime.getBatterylevel() <= 20) { + if (runtime.getBatteryLevel() <= 20) { + //删除原来的,再进行通知 + int delete = runtime.getContextProxy().getResolver().delete(Uri.parse(WarningItemProvider.WARNING_MSG), + "type=?", new String[]{String.valueOf(Constants.WARNING_MSG_TYPE_POWER_LOW)}); + ICLogger.d("delete number ==> " + delete); //保存一份到警告信息中 ContentValues warningMsgValues = new ContentValues(); //设置数据 @@ -187,9 +191,10 @@ public class BatteryUtil { warningMsgValues); } //add by TrillGates======end - ICLogger.d("runtime.getBatterylevel()==> " + runtime.getBatterylevel()); + ICLogger.d("runtime.getBatteryLevel()==> " + runtime.getBatteryLevel()); //没有充电,上次电池level > 15% , 上次电池并且不是 低电状态,则报警 - if (!runtime.isPowerConnected() && runtime.getBatterylevel() <= 15 && runtime.getBatterylevel() > 10 && !runtime.getBatteryLow()) { + if (!runtime.isPowerConnected() && runtime.getBatteryLevel() <= 15 && + runtime.getBatteryLevel() > 10 && !runtime.getBatteryLow()) { Intent intent = new Intent(); intent.setAction(ACTION_BATTERYLOW); intent.putExtra(KEY_BATTERY_EVENT, 1); @@ -200,7 +205,8 @@ public class BatteryUtil { //Deliver.sendLocationMSG(protocolAPIHelper.getWarningMSG(runtime)); ICLogger.i("triggerSOSLocationProcess "); LocationClient.getInstance().triggerSOSLocationProcess(); - } else if (!runtime.isPowerConnected() && runtime.getBatterylevel() <= 10 && runtime.getBatterylevel() > 5 && !runtime.getBatteryLow()) { + } else if (!runtime.isPowerConnected() && runtime.getBatteryLevel() <= 10 + && runtime.getBatteryLevel() > 5 && !runtime.getBatteryLow()) { //百分之10以内的还不能正常报数,需要后面再优化 Intent intent = new Intent(); intent.setAction(ACTION_BATTERYLOW); @@ -212,7 +218,9 @@ public class BatteryUtil { //Deliver.sendLocationMSG(protocolAPIHelper.getWarningMSG(runtime)); ICLogger.i("triggerSOSLocationProcess "); LocationClient.getInstance().triggerSOSLocationProcess(); - } else if (!runtime.isPowerConnected() && runtime.getBatterylevel() <= 5) { + } else if (!runtime.isPowerConnected() + && runtime.getBatteryLevel() <= 5 && + runtime.getBatteryLevel() != 0) { //没有充电,上次电池level > 15% , 上次电池并且不是 电池低电状态,则报警 Intent intent = new Intent(); intent.setAction(ACTION_BATTERYLOW); @@ -270,7 +278,6 @@ public class BatteryUtil { PowerManager mPowerManager = (PowerManager) CoreService.getInstance().getSystemService(Context.POWER_SERVICE); mWakeLock = mPowerManager.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, AntiMonitorService.class.getSimpleName()); } - } public void registerBroadReceiver() { @@ -284,24 +291,17 @@ public class BatteryUtil { } public int getBatteryLevel(Context context) { -// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { -// BatteryManager batteryManager = (BatteryManager)context.getSystemService(BATTERY_SERVICE); -// return batteryManager.getIntProperty(BatteryManager.BATTERY_PROPERTY_CAPACITY); -// } else { Intent intent = new ContextWrapper(context.getApplicationContext()).registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED)); int batLevel = (intent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1) * 100) / intent.getIntExtra(BatteryManager.EXTRA_SCALE, -1); - process_battery_level(context, batLevel); - return batLevel; } public boolean isPowerConnected(Context context) { - - IntentFilter ifilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED); - Intent batteryStatus = context.registerReceiver(null, ifilter); + IntentFilter iFilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED); + Intent batteryStatus = context.registerReceiver(null, iFilter); //你可以读到充电状态,如果在充电,可以读到是usb还是交流电 // 是否在充电 int status = batteryStatus.getIntExtra(EXTRA_STATUS, -1); @@ -310,7 +310,6 @@ public class BatteryUtil { ICLogger.d("isCharging = " + isCharging + " isCharging2 " + isCharging2); return isCharging2; } - public void unregisterBroadReceiver() { (this.mRuntime.getContextProxy()).context.unregisterReceiver(this.batteryChangedReceiver); } diff --git a/app/src/main/java/com/ic/protocols/protocol_gator.java b/app/src/main/java/com/ic/protocols/protocol_gator.java index 4a7c1635..aac9e815 100644 --- a/app/src/main/java/com/ic/protocols/protocol_gator.java +++ b/app/src/main/java/com/ic/protocols/protocol_gator.java @@ -455,14 +455,14 @@ public class protocol_gator { //CC:MCCMNC int batstat = 0; - int batlevel = ds.getBatterylevel(); - if (batlevel > 0 && batlevel <= 15) { + int batLevel = ds.getBatteryLevel(); + if (batLevel > 0 && batLevel <= 15) { batstat = 3; - } else if (batlevel > 15 && batlevel <= 35) { + } else if (batLevel > 15 && batLevel <= 35) { batstat = 4; - } else if (batlevel > 35 && batlevel <= 55) { + } else if (batLevel > 35 && batLevel <= 55) { batstat = 5; - } else if (batlevel > 55 && batlevel <= 85) { + } else if (batLevel > 55 && batLevel <= 85) { batstat = 6; } else { batstat = 7; @@ -973,7 +973,7 @@ public class protocol_gator { //基站接入点:46000024820000DE127 //日期时间:151028,163100 int batstat = 0; - int batlevel = ds.getBatterylevel(); + int batlevel = ds.getBatteryLevel(); if (batlevel > 0 && batlevel <= 15) { batstat = 1; } else if (batlevel > 15 && batlevel <= 35) { @@ -1022,7 +1022,7 @@ public class protocol_gator { StringBuilder sb = new StringBuilder(cmdMap.get(CMD_TYPE.BP30)).append(CMDSPLIT); int batstat = 0; - int batlevel = ds.getBatterylevel(); + int batlevel = ds.getBatteryLevel(); if (batlevel > 0 && batlevel <= 15) { batstat = 1; } else if (batlevel > 15 && batlevel <= 35) { diff --git a/app/src/main/java/com/ic/protocols/protocol_s123.java b/app/src/main/java/com/ic/protocols/protocol_s123.java index 48275756..16eaf2b9 100644 --- a/app/src/main/java/com/ic/protocols/protocol_s123.java +++ b/app/src/main/java/com/ic/protocols/protocol_s123.java @@ -155,7 +155,7 @@ public class protocol_s123 { int heartRate = mRuntime.getHRS().getPPG(); int lowPressure = mRuntime.getHRS().getBPL(); int highPressure = mRuntime.getHRS().getBPH(); - int batteryLev = mRuntime.getBatterylevel(); + int batteryLev = mRuntime.getBatteryLevel(); //定位数据 // String s123GpsData = mRuntime.getS123GpsData(); return genStringMessage(cmdMap.get(CMD_TYPE.APRP), @@ -172,7 +172,7 @@ public class protocol_s123 { .append(CMDSPLIT).append(mRuntime.getS123GpsData()) .append(CMDSPLIT).append("wgs84")//原始经纬度 .append(CMDSPLIT).append(mRuntime.getSignalStrength()) - .append(CMDSPLIT).append(mRuntime.getBatterylevel()) + .append(CMDSPLIT).append(mRuntime.getBatteryLevel()) .append(CMDSPLIT).append(mRuntime.getLBSData()) .append(CMDSPLIT).append(mRuntime.getWifiInfo()) .append(CMDEND).toString()); @@ -899,7 +899,7 @@ public class protocol_s123 { .append(CMDSPLIT).append(mRuntime.getS123GpsData()) .append(CMDSPLIT).append("wgs84")//原始经纬度 .append(CMDSPLIT).append(mRuntime.getSignalStrength()) - .append(CMDSPLIT).append(mRuntime.getBatterylevel()) + .append(CMDSPLIT).append(mRuntime.getBatteryLevel()) .append(CMDSPLIT).append(mRuntime.getLBSData()) .append(CMDSPLIT).append(mRuntime.getWifiInfo()) .append(CMDEND) @@ -964,7 +964,7 @@ public class protocol_s123 { .append(CMDSPLIT).append(ds.getS123GpsData()) .append(CMDSPLIT).append("wgs84")//原始经纬度 .append(CMDSPLIT).append(ds.getSignalStrength()) - .append(CMDSPLIT).append(ds.getBatterylevel()) + .append(CMDSPLIT).append(ds.getBatteryLevel()) .append(CMDSPLIT).append(ds.getLBSData()) .append(CMDSPLIT).append(ds.getWifiInfo()) .append(CMDEND)