From: snickersun Date: Mon, 30 Nov 2020 03:01:17 +0000 (+0800) Subject: release L02protocolV2 V719 X-Git-Url: http://git.snicker.com.cn/sitemap.xml?a=commitdiff_plain;h=e247e034e1a52869e0cdb4a0e42f8be37f78382b;p=protocol_srv.git release L02protocolV2 V719 修复bug,低电15%、5%确定报警,10%暂时没有报警了, --- diff --git a/app/release/ICSer_V718_2011290637_release.apk b/app/release/ICSer_V719_2011301058_release.apk similarity index 78% rename from app/release/ICSer_V718_2011290637_release.apk rename to app/release/ICSer_V719_2011301058_release.apk index e58d7ebf..61e2dc15 100644 Binary files a/app/release/ICSer_V718_2011290637_release.apk and b/app/release/ICSer_V719_2011301058_release.apk differ diff --git a/app/release/output.json b/app/release/output.json index e81ce3e8..518fc2dc 100644 --- a/app/release/output.json +++ b/app/release/output.json @@ -1 +1 @@ -[{"outputType":{"type":"APK"},"apkData":{"type":"MAIN","splits":[],"versionCode":718,"versionName":"2011290637","enabled":true,"outputFile":"ICSer_V718_2011290637_release.apk","fullName":"release","baseName":"release"},"path":"ICSer_V718_2011290637_release.apk","properties":{}}] \ No newline at end of file +[{"outputType":{"type":"APK"},"apkData":{"type":"MAIN","splits":[],"versionCode":719,"versionName":"2011301058","enabled":true,"outputFile":"ICSer_V719_2011301058_release.apk","fullName":"release","baseName":"release"},"path":"ICSer_V719_2011301058_release.apk","properties":{}}] \ No newline at end of file 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 c328fc23..28c6d6f8 100644 --- a/app/src/main/java/com/enqualcomm/support/utils/BatteryUtil.java +++ b/app/src/main/java/com/enqualcomm/support/utils/BatteryUtil.java @@ -1,284 +1,300 @@ -package com.enqualcomm.support.utils; - -import android.content.BroadcastReceiver; -import android.content.Context; -import android.content.ContextWrapper; -import android.content.Intent; -import android.content.IntentFilter; -import android.os.BatteryManager; -import android.os.Build; -import android.os.Handler; -import android.os.Message; -import android.os.PowerManager; - -import com.enqualcomm.support.Config; -import com.enqualcomm.support.CoreService; -import com.enqualcomm.support.LocationClient; -import com.enqualcomm.support.service.AntiMonitorService; -import com.enqualcomm.support.service.AudioService; -import com.enqualcomm.support.service.Deliver; -import com.ic.protocols.protocolAPIHelper; -import com.enqualcomm.support.bean.Runtime; - -//import static android.content.Context.BATTERY_SERVICE; -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_LEVEL; -import static android.os.BatteryManager.EXTRA_SCALE; -import static android.os.BatteryManager.EXTRA_STATUS; -import static android.os.BatteryManager.EXTRA_VOLTAGE; -import static com.enqualcomm.support.Constants.ACTION_BATTERYLOW; -import static com.enqualcomm.support.Constants.KEY_BATTERY_EVENT; - -public class BatteryUtil { - private BroadcastReceiver batteryChangedReceiver = new BroadcastReceiver() { - public void onReceive(Context param1Context, Intent intent) { - if (Intent.ACTION_BATTERY_CHANGED.equals(intent.getAction())) { - int extra_status = intent.getIntExtra(EXTRA_STATUS , BATTERY_STATUS_UNKNOWN ); - StringBuilder msg=new StringBuilder("EXTRA_STATUS = "); - switch (extra_status){ - case BATTERY_STATUS_CHARGING: - msg.append("BATTERY_STATUS_CHARGING "); - break; - case BATTERY_STATUS_UNKNOWN: - msg.append("BATTERY_STATUS_UNKNOWN "); - break; - case BATTERY_STATUS_DISCHARGING: - msg.append("BATTERY_STATUS_DISCHARGING "); - break; - case BATTERY_STATUS_FULL: - msg.append("BATTERY_STATUS_FULL "); - if (Config.isL03Tracker){ - LedUtil.setRedLedOn(false); - LedUtil.setBlueLedOn(true); - } - break; - case BATTERY_STATUS_NOT_CHARGING: - msg.append("BATTERY_STATUS_NOT_CHARGING "); - break; - - } - msg.append("; "); - if (extra_status == BATTERY_STATUS_CHARGING) { - if(mRuntime.getBatterychanging()==false){ - ICLogger.i("Send BatteryCharging event!"); - connection.send(protocolAPIHelper.getChargingMSG(1)); - } - mRuntime.setBatterychanging(true); - mRuntime.setBatteryLow(false); - } else { - if(mRuntime.getBatterychanging()==true){ - //send - ICLogger.i("Send no BatteryCharging event!"); - connection.send(protocolAPIHelper.getChargingMSG(0)); - } - mRuntime.setBatterychanging(false); - } - int batLevel = intent.getIntExtra(EXTRA_LEVEL, 0) * 100 / intent.getIntExtra(EXTRA_SCALE, 100); - // 当前电池电压 - int batteryVolt = intent.getIntExtra(EXTRA_VOLTAGE, -1); - mRuntime.setBatteryVoltage(batteryVolt); - msg.append("BatteryLevel "+batLevel + " BatteryVotage "+batteryVolt+"; "); - if (Config.LOG_TOFILE)ICLogger.logToFile("Battery",msg.toString()); - ICLogger.i(msg.toString()); - if (batLevel >= 100) { - mRuntime.setBattery(String.format("%03d",100)); - mRuntime.setBattery(100); - mRuntime.setHaveBatteryChange(false); - mRuntime.setBatteryLow(false); - } else if (batLevel<100 && batLevel >= 25) { - mRuntime.setBattery(String.format("%03d",batLevel)); - mRuntime.setBattery(batLevel); - mRuntime.setHaveBatteryChange(false); - mRuntime.setBatteryLow(false); - } else if (batLevel<25 && batLevel > 15) { - mRuntime.setBattery(String.format("%03d",batLevel)); - mRuntime.setBattery(batLevel); - mRuntime.setHaveBatteryChange(true); - - } else if (batLevel<=15 && batLevel > 5) { - - - if (Config.LOG_TOFILE) ICLogger.logToFile("Battery","BatteryLow less than 15%!"); - checkAndSendBatteryEvent(param1Context,mRuntime); - mRuntime.setBattery(String.format("%03d",batLevel)); - mRuntime.setBattery(batLevel); - mRuntime.setHaveBatteryChange(true); - mRuntime.setBatteryLow(true); - } else { - - if (Config.LOG_TOFILE) ICLogger.logToFile("Battery","BatteryLow less than 5% !"); - checkAndSendBatteryEvent(param1Context,mRuntime); - mRuntime.setBattery(String.format("%03d",batLevel)); - mRuntime.setBattery(batLevel); - mRuntime.setHaveBatteryChange(true); - mRuntime.setBatteryLow(true); - } - - }else if (Intent.ACTION_BATTERY_LOW.equals(intent.getAction())) { - // mRuntime.setBatteryLow(true); - // if (Config.LOG_TOFILE) ICLogger.logToFile("Battery","BatteryLow !"); - // mRuntime.setAlarmType(false,mRuntime.getBatteryLow(),false,false); - //trigger AP10 报警定位 - // connection.send(protocolAPIHelper.genStringMessage("AP10",protocolAPIHelper.getWarningMSG(mRuntime))); - - }else if (Intent.ACTION_BATTERY_OKAY.equals(intent.getAction())){ - ICLogger.i("Battery OKAY !"); - if (Config.LOG_TOFILE) ICLogger.logToFile("Battery","Battery OKAY !"); - send_batterylow_event_broadcast(param1Context,0); - }else if (Intent.ACTION_POWER_CONNECTED.equals(intent.getAction())){ - ICLogger.i("ACTION_POWER_CONNECTED !"); - mRuntime.setPowerConnected(true); - if (Config.LOG_TOFILE) ICLogger.logToFile("Battery","ACTION_POWER_CONNECTED!"); - if (Config.isL03Tracker){ - LedUtil.setRedLedOn(true); - } - - }else if (Intent.ACTION_POWER_DISCONNECTED.equals(intent.getAction())){ - ICLogger.i("ACTION_POWER_DISCONNECTED!"); - mRuntime.setPowerConnected(false); - if (Config.LOG_TOFILE) ICLogger.logToFile("Battery","ACTION_POWER_DISCONNECTED !"); - - if (Config.isL03Tracker){ - LedUtil.setRedLedOn(false); - } - } - } - }; - private Handler mHandler=null; - PowerManager.WakeLock mWakeLock = null; - - private static void play_waning_notify(Context context){ - AudioService.getInstance().play(context.getAssets(), "warning.mp3"); - } - - public static void checkAndSendBatteryEvent(Context context, Runtime runtime){ - - //没有充电,上次电池level > 15% , 上次电池并且不是 低电状态,则报警 - if (runtime.isPowerConnected()==false && runtime.getBatterylevel()<= 10 && runtime.getBatterylevel()> 5 && runtime.getBatteryLow()==false) { - Intent intent=new Intent(); - intent.setAction(ACTION_BATTERYLOW); - intent.putExtra(KEY_BATTERY_EVENT,1); - context.sendBroadcast(intent); - play_waning_notify(context); - runtime.setAlarmType(Runtime.AlarmType.ALARM_LOWBATTERY); - //trigger AP10 报警定位 -// Deliver.sendLocationMSG(protocolAPIHelper.getWarningMSG(runtime)); - ICLogger.i("triggerSOSLocationProcess "); - LocationClient.getInstance().triggerSOSLocationProcess(); - }else if (runtime.isPowerConnected()==false && runtime.getBatterylevel()<= 5 ) { - //没有充电,上次电池level > 15% , 上次电池并且不是 电池低电状态,则报警 - Intent intent=new Intent(); - intent.setAction(ACTION_BATTERYLOW); - intent.putExtra(KEY_BATTERY_EVENT,1); - context.sendBroadcast(intent); - play_waning_notify(context); - runtime.setAlarmType(Runtime.AlarmType.ALARM_LOWBATTERY); - //trigger AP10 报警定位 -// Deliver.sendLocationMSG( protocolAPIHelper.getWarningMSG(runtime)); - ICLogger.i("triggerSOSLocationProcess "); - LocationClient.getInstance().triggerSOSLocationProcess(); - } - } - private void send_batterylow_event_broadcast(Context context,int batlow){ - mHandler.post(new Runnable() { - @Override - public void run() { - Intent intent=new Intent(); - intent.setAction(ACTION_BATTERYLOW); - intent.putExtra(KEY_BATTERY_EVENT,batlow); - context.sendBroadcast(intent); - } - }); - } - private StringBuffer mBuffer; - - Runtime mRuntime; - Connection connection; - public BatteryUtil(Runtime paramRuntime,Connection _connection) { - this.mRuntime = paramRuntime; - connection = _connection; - - if (mHandler==null) { - mHandler = new Handler() { - public void handleMessage(Message msg) { - super.handleMessage(msg); - if (msg.what == 100) { - if (mWakeLock != null && mWakeLock.isHeld()) { - mWakeLock.release(); - } - }else if (msg.what == 200){ - AudioService.getInstance().stop(); - } - } - }; - } - if (mWakeLock==null) { - 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() { - IntentFilter intentFilter = new IntentFilter(); - intentFilter.addAction(Intent.ACTION_BATTERY_CHANGED); - intentFilter.addAction(Intent.ACTION_BATTERY_LOW); - intentFilter.addAction(Intent.ACTION_BATTERY_OKAY); - intentFilter.addAction(Intent.ACTION_POWER_CONNECTED); - intentFilter.addAction(Intent.ACTION_POWER_DISCONNECTED); - (this.mRuntime.getContextProxy()).context.registerReceiver(this.batteryChangedReceiver, intentFilter); - } - - 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); - - if( batLevel>15) { - - - }else if (batLevel<=15 && batLevel > 5) { - if (Config.LOG_TOFILE) ICLogger.logToFile("Battery","BatteryLow less than 15%!"); - checkAndSendBatteryEvent(context,mRuntime); - mRuntime.setBattery(String.format("%03d",batLevel)); - mRuntime.setBattery(batLevel); - mRuntime.setHaveBatteryChange(true); - mRuntime.setBatteryLow(true); - } else { - if (Config.LOG_TOFILE) ICLogger.logToFile("Battery","BatteryLow less than 5% !"); - checkAndSendBatteryEvent(context,mRuntime); - mRuntime.setBattery(String.format("%03d",batLevel)); - mRuntime.setBattery(batLevel); - mRuntime.setHaveBatteryChange(true); - mRuntime.setBatteryLow(true); - } - return batLevel; - } - - - public boolean isPowerConnected(Context context){ - - IntentFilter ifilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED); - Intent batteryStatus = context.registerReceiver(null, ifilter); -//你可以读到充电状态,如果在充电,可以读到是usb还是交流电 - -// 是否在充电 - int status = batteryStatus.getIntExtra(EXTRA_STATUS, -1); - boolean isCharging = (status == BATTERY_STATUS_CHARGING) ;//|| status == BatteryManager.BATTERY_STATUS_FULL; - boolean isCharging2 = batteryStatus.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1) != 0; - ICLogger.d("isCharging = " +isCharging+" isCharging2 "+ isCharging2 ); - return isCharging2; - } - - public void unregisterBroadReceiver() { (this.mRuntime.getContextProxy()).context.unregisterReceiver(this.batteryChangedReceiver); } -} - - +package com.enqualcomm.support.utils; + +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.ContextWrapper; +import android.content.Intent; +import android.content.IntentFilter; +import android.os.BatteryManager; +import android.os.Build; +import android.os.Handler; +import android.os.Message; +import android.os.PowerManager; + +import com.enqualcomm.support.Config; +import com.enqualcomm.support.CoreService; +import com.enqualcomm.support.LocationClient; +import com.enqualcomm.support.service.AntiMonitorService; +import com.enqualcomm.support.service.AudioService; +import com.enqualcomm.support.service.Deliver; +import com.ic.protocols.protocolAPIHelper; +import com.enqualcomm.support.bean.Runtime; + +//import static android.content.Context.BATTERY_SERVICE; +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_LEVEL; +import static android.os.BatteryManager.EXTRA_SCALE; +import static android.os.BatteryManager.EXTRA_STATUS; +import static android.os.BatteryManager.EXTRA_VOLTAGE; +import static com.enqualcomm.support.Constants.ACTION_BATTERYLOW; +import static com.enqualcomm.support.Constants.KEY_BATTERY_EVENT; + +public class BatteryUtil { + private BroadcastReceiver batteryChangedReceiver = new BroadcastReceiver() { + public void onReceive(Context param1Context, Intent intent) { + if (Intent.ACTION_BATTERY_CHANGED.equals(intent.getAction())) { + int extra_status = intent.getIntExtra(EXTRA_STATUS , BATTERY_STATUS_UNKNOWN ); + StringBuilder msg=new StringBuilder("EXTRA_STATUS = "); + switch (extra_status){ + case BATTERY_STATUS_CHARGING: + msg.append("BATTERY_STATUS_CHARGING "); + break; + case BATTERY_STATUS_UNKNOWN: + msg.append("BATTERY_STATUS_UNKNOWN "); + break; + case BATTERY_STATUS_DISCHARGING: + msg.append("BATTERY_STATUS_DISCHARGING "); + break; + case BATTERY_STATUS_FULL: + msg.append("BATTERY_STATUS_FULL "); + if (Config.isL03Tracker){ + LedUtil.setRedLedOn(false); + LedUtil.setBlueLedOn(true); + } + break; + case BATTERY_STATUS_NOT_CHARGING: + msg.append("BATTERY_STATUS_NOT_CHARGING "); + break; + + } + msg.append("; "); + if (extra_status == BATTERY_STATUS_CHARGING) { + if(mRuntime.getBatterychanging()==false){ + ICLogger.i("Send BatteryCharging event!"); + connection.send(protocolAPIHelper.getChargingMSG(1)); + } + mRuntime.setBatterychanging(true); + mRuntime.setBatteryLow(false); + } else { + if(mRuntime.getBatterychanging()==true){ + //send + ICLogger.i("Send no BatteryCharging event!"); + connection.send(protocolAPIHelper.getChargingMSG(0)); + } + mRuntime.setBatterychanging(false); + } + int batLevel = intent.getIntExtra(EXTRA_LEVEL, 0) * 100 / intent.getIntExtra(EXTRA_SCALE, 100); + // 当前电池电压 + int batteryVolt = intent.getIntExtra(EXTRA_VOLTAGE, -1); + mRuntime.setBatteryVoltage(batteryVolt); + msg.append("BatteryLevel "+batLevel + " BatteryVotage "+batteryVolt+"; "); + if (Config.LOG_TOFILE)ICLogger.logToFile("Battery",msg.toString()); + ICLogger.i(msg.toString()); + if (batLevel >= 100) { + mRuntime.setBattery(String.format("%03d",100)); + mRuntime.setBattery(100); + mRuntime.setHaveBatteryChange(false); + mRuntime.setBatteryLow(false); + } else if (batLevel<100 && batLevel >= 25) { + mRuntime.setBattery(String.format("%03d",batLevel)); + mRuntime.setBattery(batLevel); + mRuntime.setHaveBatteryChange(false); + mRuntime.setBatteryLow(false); + } else if (batLevel<25 && batLevel > 15) { + mRuntime.setBattery(String.format("%03d",batLevel)); + mRuntime.setBattery(batLevel); + mRuntime.setHaveBatteryChange(true); + } else if (batLevel<=15 && batLevel > 10) { + if (Config.LOG_TOFILE) ICLogger.logToFile("Battery","BatteryLow less than 15%!"); + checkAndSendBatteryEvent(param1Context,mRuntime); + mRuntime.setBattery(String.format("%03d",batLevel)); + mRuntime.setBattery(batLevel); + mRuntime.setHaveBatteryChange(true); + mRuntime.setBatteryLow(true); + } else if (batLevel<=10 && batLevel > 5) { + if (Config.LOG_TOFILE) ICLogger.logToFile("Battery","BatteryLow less than 10%!"); + checkAndSendBatteryEvent(param1Context,mRuntime); + mRuntime.setBattery(String.format("%03d",batLevel)); + mRuntime.setBattery(batLevel); + mRuntime.setHaveBatteryChange(true); + mRuntime.setBatteryLow(true); + } else { + + if (Config.LOG_TOFILE) ICLogger.logToFile("Battery","BatteryLow less than 5% !"); + checkAndSendBatteryEvent(param1Context,mRuntime); + mRuntime.setBattery(String.format("%03d",batLevel)); + mRuntime.setBattery(batLevel); + mRuntime.setHaveBatteryChange(true); + mRuntime.setBatteryLow(true); + } + + }else if (Intent.ACTION_BATTERY_LOW.equals(intent.getAction())) { + // mRuntime.setBatteryLow(true); + // if (Config.LOG_TOFILE) ICLogger.logToFile("Battery","BatteryLow !"); + // mRuntime.setAlarmType(false,mRuntime.getBatteryLow(),false,false); + //trigger AP10 报警定位 + // connection.send(protocolAPIHelper.genStringMessage("AP10",protocolAPIHelper.getWarningMSG(mRuntime))); + + }else if (Intent.ACTION_BATTERY_OKAY.equals(intent.getAction())){ + ICLogger.i("Battery OKAY !"); + if (Config.LOG_TOFILE) ICLogger.logToFile("Battery","Battery OKAY !"); + send_batterylow_event_broadcast(param1Context,0); + }else if (Intent.ACTION_POWER_CONNECTED.equals(intent.getAction())){ + ICLogger.i("ACTION_POWER_CONNECTED !"); + mRuntime.setPowerConnected(true); + if (Config.LOG_TOFILE) ICLogger.logToFile("Battery","ACTION_POWER_CONNECTED!"); + if (Config.isL03Tracker){ + LedUtil.setRedLedOn(true); + } + + }else if (Intent.ACTION_POWER_DISCONNECTED.equals(intent.getAction())){ + ICLogger.i("ACTION_POWER_DISCONNECTED!"); + mRuntime.setPowerConnected(false); + if (Config.LOG_TOFILE) ICLogger.logToFile("Battery","ACTION_POWER_DISCONNECTED !"); + + if (Config.isL03Tracker){ + LedUtil.setRedLedOn(false); + } + } + } + }; + private Handler mHandler=null; + PowerManager.WakeLock mWakeLock = null; + + private static void play_waning_notify(Context context){ + AudioService.getInstance().play(context.getAssets(), "warning.mp3"); + } + + public static void checkAndSendBatteryEvent(Context context, Runtime runtime){ + + //没有充电,上次电池level > 15% , 上次电池并且不是 低电状态,则报警 + if (runtime.isPowerConnected()==false && runtime.getBatterylevel()<= 15 && runtime.getBatterylevel()> 10 && runtime.getBatteryLow()==false) { + Intent intent = new Intent(); + intent.setAction(ACTION_BATTERYLOW); + intent.putExtra(KEY_BATTERY_EVENT, 1); + context.sendBroadcast(intent); + play_waning_notify(context); + runtime.setAlarmType(Runtime.AlarmType.ALARM_LOWBATTERY); + //trigger AP10 报警定位 +// Deliver.sendLocationMSG(protocolAPIHelper.getWarningMSG(runtime)); + ICLogger.i("triggerSOSLocationProcess "); + LocationClient.getInstance().triggerSOSLocationProcess(); + }else if (runtime.isPowerConnected()==false && runtime.getBatterylevel()<= 10 && runtime.getBatterylevel()> 5 && runtime.getBatteryLow()==false) { + //百分之10以内的还不能正常报数,需要后面再优化 + Intent intent=new Intent(); + intent.setAction(ACTION_BATTERYLOW); + intent.putExtra(KEY_BATTERY_EVENT,1); + context.sendBroadcast(intent); + play_waning_notify(context); + runtime.setAlarmType(Runtime.AlarmType.ALARM_LOWBATTERY); + //trigger AP10 报警定位 +// Deliver.sendLocationMSG(protocolAPIHelper.getWarningMSG(runtime)); + ICLogger.i("triggerSOSLocationProcess "); + LocationClient.getInstance().triggerSOSLocationProcess(); + }else if (runtime.isPowerConnected()==false && runtime.getBatterylevel()<= 5 ) { + //没有充电,上次电池level > 15% , 上次电池并且不是 电池低电状态,则报警 + Intent intent=new Intent(); + intent.setAction(ACTION_BATTERYLOW); + intent.putExtra(KEY_BATTERY_EVENT,1); + context.sendBroadcast(intent); + play_waning_notify(context); + runtime.setAlarmType(Runtime.AlarmType.ALARM_LOWBATTERY); + //trigger AP10 报警定位 +// Deliver.sendLocationMSG( protocolAPIHelper.getWarningMSG(runtime)); + ICLogger.i("triggerSOSLocationProcess "); + LocationClient.getInstance().triggerSOSLocationProcess(); + } + } + private void send_batterylow_event_broadcast(Context context,int batlow){ + mHandler.post(new Runnable() { + @Override + public void run() { + Intent intent=new Intent(); + intent.setAction(ACTION_BATTERYLOW); + intent.putExtra(KEY_BATTERY_EVENT,batlow); + context.sendBroadcast(intent); + } + }); + } + private StringBuffer mBuffer; + + Runtime mRuntime; + Connection connection; + public BatteryUtil(Runtime paramRuntime,Connection _connection) { + this.mRuntime = paramRuntime; + connection = _connection; + + if (mHandler==null) { + mHandler = new Handler() { + public void handleMessage(Message msg) { + super.handleMessage(msg); + if (msg.what == 100) { + if (mWakeLock != null && mWakeLock.isHeld()) { + mWakeLock.release(); + } + }else if (msg.what == 200){ + AudioService.getInstance().stop(); + } + } + }; + } + if (mWakeLock==null) { + 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() { + IntentFilter intentFilter = new IntentFilter(); + intentFilter.addAction(Intent.ACTION_BATTERY_CHANGED); + intentFilter.addAction(Intent.ACTION_BATTERY_LOW); + intentFilter.addAction(Intent.ACTION_BATTERY_OKAY); + intentFilter.addAction(Intent.ACTION_POWER_CONNECTED); + intentFilter.addAction(Intent.ACTION_POWER_DISCONNECTED); + (this.mRuntime.getContextProxy()).context.registerReceiver(this.batteryChangedReceiver, intentFilter); + } + + 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); + + if( batLevel>15) { + + + }else if (batLevel<=15 && batLevel > 5) { + if (Config.LOG_TOFILE) ICLogger.logToFile("Battery","BatteryLow less than 15%!"); + checkAndSendBatteryEvent(context,mRuntime); + mRuntime.setBattery(String.format("%03d",batLevel)); + mRuntime.setBattery(batLevel); + mRuntime.setHaveBatteryChange(true); + mRuntime.setBatteryLow(true); + } else { + if (Config.LOG_TOFILE) ICLogger.logToFile("Battery","BatteryLow less than 5% !"); + checkAndSendBatteryEvent(context,mRuntime); + mRuntime.setBattery(String.format("%03d",batLevel)); + mRuntime.setBattery(batLevel); + mRuntime.setHaveBatteryChange(true); + mRuntime.setBatteryLow(true); + } + return batLevel; + } + + + public boolean isPowerConnected(Context context){ + + IntentFilter ifilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED); + Intent batteryStatus = context.registerReceiver(null, ifilter); +//你可以读到充电状态,如果在充电,可以读到是usb还是交流电 + +// 是否在充电 + int status = batteryStatus.getIntExtra(EXTRA_STATUS, -1); + boolean isCharging = (status == BATTERY_STATUS_CHARGING) ;//|| status == BatteryManager.BATTERY_STATUS_FULL; + boolean isCharging2 = batteryStatus.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1) != 0; + ICLogger.d("isCharging = " +isCharging+" isCharging2 "+ isCharging2 ); + return isCharging2; + } + + public void unregisterBroadReceiver() { (this.mRuntime.getContextProxy()).context.unregisterReceiver(this.batteryChangedReceiver); } +} + + diff --git a/app/version_code.properties b/app/version_code.properties index ba028fe7..950e6f53 100644 --- a/app/version_code.properties +++ b/app/version_code.properties @@ -1,2 +1,2 @@ -#Sun Nov 29 06:37:00 CST 2020 -VERSION_CODE=718 +#Mon Nov 30 10:58:29 CST 2020 +VERSION_CODE=719