From 6850b8915214c3dc33314be7605e20dc735c437a Mon Sep 17 00:00:00 2001 From: snickersun Date: Tue, 1 Dec 2020 02:12:30 +0800 Subject: [PATCH] =?utf8?q?=E8=A7=A3=E5=86=B3=E6=AF=8F=E6=AC=A1=E5=90=AF?= =?utf8?q?=E5=8A=A8=EF=BC=8C=E5=A3=B0=E9=9F=B3=E6=97=A0=E6=B3=95=E6=A0=B9?= =?utf8?q?=E6=8D=AE=E5=AE=A2=E6=88=B7=E8=AE=BE=E7=BD=AE=E8=BF=9B=E8=A1=8C?= =?utf8?q?=E8=AE=B0=E5=BF=86=EF=BC=8C=E5=8F=AA=E8=83=BD=E6=9C=80=E5=A4=A7?= =?utf8?q?=E9=9F=B3=E9=87=8F=E9=97=AE=E9=A2=98=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../com/enqualcomm/support/CoreService.java | 29 ++++++++++++++----- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/com/enqualcomm/support/CoreService.java b/app/src/main/java/com/enqualcomm/support/CoreService.java index 4c747486..1fe12bee 100644 --- a/app/src/main/java/com/enqualcomm/support/CoreService.java +++ b/app/src/main/java/com/enqualcomm/support/CoreService.java @@ -7,6 +7,7 @@ import android.app.Service; import android.content.IClipboard; import android.content.Intent; import android.media.AudioManager; +import android.media.MediaRouter; import android.os.Handler; import android.os.IBinder; @@ -362,15 +363,15 @@ public class CoreService extends Service { Runtime runtime; private BroadcastReceiver screenOnReceiver = new BroadcastReceiver() { - public void onReceive(Context param1Context, Intent param1Intent) { + public void onReceive(Context context, Intent intent) { - if ("android.intent.action.SCREEN_ON".equals(param1Intent.getAction())) { + if ("android.intent.action.SCREEN_ON".equals(intent.getAction())) { StringBuilder var3 = new StringBuilder(); var3.append("screen on wake is_wifi_network_ok="); var3.append(CoreService.is_wifi_network_ok); ICLogger.i(var3.toString()); //检测电池电量 并上报低电报警 - batteryUtil.getBatteryLevel(param1Context); + batteryUtil.getBatteryLevel(context); if (CoreService.is_in_sleep_mode) { /*屏幕亮起时,如果在sleep模式(夜晚的那个睡眠模式,非系统休眠,暂时没实现,还不会跑到这里),则唤醒各个进程*/ @@ -397,7 +398,7 @@ public class CoreService extends Service { // if (!Util.isWifiIsOpen(runtime.getContextProxy().context,runtime)) // Util.turnOnWifiForConnect(runtime.getContextProxy().context, runtime); } - } else if ("android.intent.action.SCREEN_OFF".equals(param1Intent.getAction()) && Util.isWifiIsOpen(runtime.getContextProxy().context,runtime)) { + } else if ("android.intent.action.SCREEN_OFF".equals(intent.getAction()) && Util.isWifiIsOpen(runtime.getContextProxy().context,runtime)) { // CoreService.is_wifi_network_ok = true; if (!runtime.isNoTurnOffWifiOnScreenOff()) { //不关闭wifi when ScreenOff @@ -405,6 +406,16 @@ public class CoreService extends Service { // if (Util.isWifiIsOpen(runtime.getContextProxy().context,runtime)) // Util.turnOffWifiForSleep(runtime.getContextProxy().context, runtime); } + }else if (intent.getAction().equals("android.media.VOLUME_CHANGED_ACTION")) { + int streamType = intent.getIntExtra("android.media.EXTRA_VOLUME_STREAM_TYPE", -1); + ICLogger.i("Volume changed stream type "+streamType); + + int newVolume = intent.getIntExtra("android.media.EXTRA_VOLUME_STREAM_VALUE", 0); + int oldVolume = intent.getIntExtra("android.media.EXTRA_PREV_VOLUME_STREAM_VALUE", 0); + if (newVolume != oldVolume) { + ICLogger.i("Volume changed old "+oldVolume+" new "+newVolume); + Config.setMasterVolume(context,newVolume); + } } } }; @@ -853,6 +864,7 @@ public class CoreService extends Service { intentFilter = new IntentFilter(); intentFilter.addAction("android.intent.action.SCREEN_ON"); intentFilter.addAction("android.intent.action.SCREEN_OFF"); + intentFilter.addAction("android.media.VOLUME_CHANGED_ACTION"); (this.runtime.getContextProxy()).context.registerReceiver(this.screenOnReceiver, intentFilter); //注册接收 AT指令结果返回消息 @@ -940,6 +952,7 @@ public class CoreService extends Service { runtime.bleInfo.bleScanCycle=Config.getBleScanCycle(this); if(Config.BLEScanProtocol==1 && runtime.bleInfo.bleScanCycle>0) { + setBleScanAlarm(runtime.bleInfo.bleScanCycle); } @@ -1353,15 +1366,17 @@ public class CoreService extends Service { } public void setBleScanAlarm(int cycle){ + //只有蓝牙扫描协议1才需要设置周期,蓝牙扫描协议0 为心跳及定位时才进行扫描 if (Config.BLEScanProtocol!=1) { ICLogger.i("BLEScanProtocol!=1 skip setPolingCheckAntiAlarm"); return; } StringBuilder sb=new StringBuilder(); - if (cycle>1) { - AlarmHelper.setRealTimeAlarm(runtime.getContextProxy().context, cycle, ACTION_ALARM_BLE_SCAN); + if (cycle>=15) { + //由于蓝牙扫描一次15秒,所以周期要大于等于15秒 + AlarmHelper.setRealTimeAlarmInMicorSeconds(runtime.getContextProxy().context, cycle*1000, ACTION_ALARM_BLE_SCAN); } - sb.append("setBleScanAlarm " + cycle); + sb.append("setBleScanAlarm " + cycle+" seconds"); locationClient.triggerBLEProcess(); ICLogger.i(sb.toString()); if (Config.LOG_TOFILE)ICLogger.logToFile("alarmCycle",sb.toString()); -- 2.17.1