Skip to content

Commit

Permalink
Merge pull request #1949 from nightscout/dev
Browse files Browse the repository at this point in the history
3.1.0.2
  • Loading branch information
MilosKozak committed Jul 22, 2022
2 parents 6552e7d + 6b26e52 commit f8acbad
Show file tree
Hide file tree
Showing 12 changed files with 57 additions and 33 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,6 @@ app/.classpath
app/.settings/org.eclipse.buildship.core.prefs
wear/.classpath
wear/.settings/org.eclipse.buildship.core.prefs
app/nsclient/*
app/nsclient2/*
app/pumpcontrol/*
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ android {
defaultConfig {
multiDexEnabled true
versionCode 1500
version "3.1.0.1"
version "3.1.0.2"
buildConfigField "String", "VERSION", '"' + version + '"'
buildConfigField "String", "BUILDVERSION", '"' + generateGitBuild() + '-' + generateDate() + '"'
buildConfigField "String", "REMOTE", '"' + generateGitRemote() + '"'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import android.bluetooth.BluetoothManager
import android.content.Context
import android.content.Intent
import android.content.pm.PackageManager
import android.os.Build
import android.provider.Settings
import androidx.annotation.StringRes
import androidx.appcompat.app.AppCompatActivity
Expand Down Expand Up @@ -113,7 +114,7 @@ class ImportExportPrefsImpl @Inject constructor(
val n1 = Settings.System.getString(context.contentResolver, "bluetooth_name")
val n2 = Settings.Secure.getString(context.contentResolver, "bluetooth_name")
val n3 = try {
if (ActivityCompat.checkSelfPermission(context, Manifest.permission.BLUETOOTH_CONNECT) == PackageManager.PERMISSION_GRANTED) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.S || ActivityCompat.checkSelfPermission(context, Manifest.permission.BLUETOOTH_CONNECT) == PackageManager.PERMISSION_GRANTED) {
(context.getSystemService(Context.BLUETOOTH_SERVICE) as BluetoothManager?)?.adapter?.name
} else null
} catch (e: Exception){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.Manifest
import android.bluetooth.BluetoothManager
import android.content.Context
import android.content.pm.PackageManager
import android.os.Build
import android.widget.LinearLayout
import androidx.core.app.ActivityCompat
import com.google.common.base.Optional
Expand Down Expand Up @@ -77,7 +78,7 @@ class TriggerBTDevice(injector: HasAndroidInjector) : Trigger(injector) {
// Get the list of paired BT devices to use in dropdown menu
private fun devicesPaired(): ArrayList<CharSequence> {
val s = ArrayList<CharSequence>()
if (ActivityCompat.checkSelfPermission(context, Manifest.permission.BLUETOOTH_CONNECT) == PackageManager.PERMISSION_GRANTED) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.S || ActivityCompat.checkSelfPermission(context, Manifest.permission.BLUETOOTH_CONNECT) == PackageManager.PERMISSION_GRANTED) {
(context.getSystemService(Context.BLUETOOTH_SERVICE) as BluetoothManager?)?.adapter?.bondedDevices?.forEach { s.add(it.name) }
} else {
ToastUtils.errorToast(context, context.getString(R.string.needconnectpermission))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import kotlin.jvm.JvmOverloads
import android.bluetooth.BluetoothManager
import android.content.Context
import android.content.pm.PackageManager
import android.os.Build
import android.util.AttributeSet
import androidx.core.app.ActivityCompat
import androidx.preference.ListPreference
Expand All @@ -15,7 +16,7 @@ import java.util.*
class BluetoothDevicePreference @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) : ListPreference(context, attrs) {

init {
if (ActivityCompat.checkSelfPermission(context, Manifest.permission.BLUETOOTH_CONNECT) == PackageManager.PERMISSION_GRANTED) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.S || ActivityCompat.checkSelfPermission(context, Manifest.permission.BLUETOOTH_CONNECT) == PackageManager.PERMISSION_GRANTED) {
val devices = Vector<CharSequence>()
(context.getSystemService(Context.BLUETOOTH_SERVICE) as BluetoothManager?)?.adapter?.let { bta ->
for (dev in bta.bondedDevices)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.IBinder;
import android.os.SystemClock;

Expand Down Expand Up @@ -195,7 +196,7 @@ public void stopConnecting() {

protected void getBTSocketForSelectedPump() {
mDevName = sp.getString(R.string.key_danar_bt_name, "");
if (ActivityCompat.checkSelfPermission(context, Manifest.permission.BLUETOOTH_CONNECT) == PackageManager.PERMISSION_GRANTED) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.S || ActivityCompat.checkSelfPermission(context, Manifest.permission.BLUETOOTH_CONNECT) == PackageManager.PERMISSION_GRANTED) {
BluetoothAdapter bluetoothAdapter = ((BluetoothManager) context.getSystemService(Context.BLUETOOTH_SERVICE)).getAdapter();

if (bluetoothAdapter != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import android.bluetooth.le.ScanResult
import android.content.Context
import android.content.pm.ActivityInfo
import android.content.pm.PackageManager
import android.os.Build
import android.os.Bundle
import android.os.Handler
import android.os.Looper
Expand Down Expand Up @@ -60,7 +61,7 @@ class BLEScanActivity : NoSplashAppCompatActivity() {
override fun onResume() {
super.onResume()

if (ActivityCompat.checkSelfPermission(context, Manifest.permission.BLUETOOTH_CONNECT) == PackageManager.PERMISSION_GRANTED) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.S || ActivityCompat.checkSelfPermission(context, Manifest.permission.BLUETOOTH_CONNECT) == PackageManager.PERMISSION_GRANTED) {
if (bluetoothAdapter?.isEnabled != true) bluetoothAdapter?.enable()
startScan()
} else {
Expand All @@ -74,7 +75,7 @@ class BLEScanActivity : NoSplashAppCompatActivity() {
}

private fun startScan() =
if (ActivityCompat.checkSelfPermission(context, Manifest.permission.BLUETOOTH_SCAN) == PackageManager.PERMISSION_GRANTED) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.S || ActivityCompat.checkSelfPermission(context, Manifest.permission.BLUETOOTH_SCAN) == PackageManager.PERMISSION_GRANTED) {
try {
bluetoothLeScanner?.startScan(mBleScanCallback)
} catch (ignore: IllegalStateException) {
Expand All @@ -84,7 +85,7 @@ class BLEScanActivity : NoSplashAppCompatActivity() {
}

private fun stopScan() =
if (ActivityCompat.checkSelfPermission(context, Manifest.permission.BLUETOOTH_SCAN) == PackageManager.PERMISSION_GRANTED) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.S || ActivityCompat.checkSelfPermission(context, Manifest.permission.BLUETOOTH_SCAN) == PackageManager.PERMISSION_GRANTED) {
try {
bluetoothLeScanner?.stopScan(mBleScanCallback)
} catch (ignore: IllegalStateException) {
Expand Down Expand Up @@ -147,7 +148,7 @@ class BLEScanActivity : NoSplashAppCompatActivity() {
override fun onClick(v: View) {
sp.putString(R.string.key_danars_address, item.device.address)
sp.putString(R.string.key_danars_name, name.text.toString())
if (ActivityCompat.checkSelfPermission(context, Manifest.permission.BLUETOOTH_CONNECT) == PackageManager.PERMISSION_GRANTED) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.S || ActivityCompat.checkSelfPermission(context, Manifest.permission.BLUETOOTH_CONNECT) == PackageManager.PERMISSION_GRANTED) {
item.device.createBond()
rxBus.send(EventDanaRSDeviceChange())
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import android.bluetooth.*
import android.content.Context
import android.content.Intent
import android.content.pm.PackageManager
import android.os.Build
import android.os.SystemClock
import android.util.Base64
import androidx.core.app.ActivityCompat
Expand Down Expand Up @@ -94,7 +95,9 @@ class BLEComm @Inject internal constructor(

@Synchronized
fun connect(from: String, address: String?): Boolean {
if (ActivityCompat.checkSelfPermission(context, Manifest.permission.BLUETOOTH_CONNECT) != PackageManager.PERMISSION_GRANTED) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S &&
ActivityCompat.checkSelfPermission(context, Manifest.permission.BLUETOOTH_CONNECT) != PackageManager.PERMISSION_GRANTED
) {
ToastUtils.errorToast(context, context.getString(info.nightscout.androidaps.core.R.string.needconnectpermission))
aapsLogger.error(LTag.PUMPBTCOMM, "missing permission: $from")
return false
Expand All @@ -116,7 +119,7 @@ class BLEComm @Inject internal constructor(
return false
}
if (device.bondState == BluetoothDevice.BOND_NONE) {
if (ActivityCompat.checkSelfPermission(context, Manifest.permission.BLUETOOTH_CONNECT) == PackageManager.PERMISSION_GRANTED) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.S || ActivityCompat.checkSelfPermission(context, Manifest.permission.BLUETOOTH_CONNECT) == PackageManager.PERMISSION_GRANTED) {
device.createBond()
SystemClock.sleep(10000)
}
Expand All @@ -142,7 +145,9 @@ class BLEComm @Inject internal constructor(

@Synchronized
fun disconnect(from: String) {
if (ActivityCompat.checkSelfPermission(context, Manifest.permission.BLUETOOTH_CONNECT) != PackageManager.PERMISSION_GRANTED) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S &&
ActivityCompat.checkSelfPermission(context, Manifest.permission.BLUETOOTH_CONNECT) != PackageManager.PERMISSION_GRANTED
) {
aapsLogger.error(LTag.PUMPBTCOMM, "missing permission: $from")
return
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import android.bluetooth.le.ScanSettings
import android.content.Context
import android.content.pm.ActivityInfo
import android.content.pm.PackageManager
import android.os.Build
import android.os.Bundle
import android.os.Handler
import android.os.Looper
Expand Down Expand Up @@ -64,7 +65,7 @@ class DiaconnG8BLEScanActivity : NoSplashAppCompatActivity() {
override fun onResume() {
super.onResume()

if (ActivityCompat.checkSelfPermission(context, Manifest.permission.BLUETOOTH_SCAN) == PackageManager.PERMISSION_GRANTED) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.S || ActivityCompat.checkSelfPermission(context, Manifest.permission.BLUETOOTH_SCAN) == PackageManager.PERMISSION_GRANTED) {
bluetoothAdapter?.let { bluetoothAdapter ->
if (!bluetoothAdapter.isEnabled) bluetoothAdapter.enable()
bluetoothLeScanner = bluetoothAdapter.bluetoothLeScanner
Expand All @@ -77,7 +78,7 @@ class DiaconnG8BLEScanActivity : NoSplashAppCompatActivity() {

override fun onPause() {
super.onPause()
if (ActivityCompat.checkSelfPermission(context, Manifest.permission.BLUETOOTH_SCAN) == PackageManager.PERMISSION_GRANTED) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.S || ActivityCompat.checkSelfPermission(context, Manifest.permission.BLUETOOTH_SCAN) == PackageManager.PERMISSION_GRANTED) {
stopScan()
}
}
Expand Down Expand Up @@ -107,7 +108,9 @@ class DiaconnG8BLEScanActivity : NoSplashAppCompatActivity() {
} // ignore BT not on

private fun addBleDevice(device: BluetoothDevice?) {
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.BLUETOOTH_CONNECT) != PackageManager.PERMISSION_GRANTED) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S &&
ActivityCompat.checkSelfPermission(this, Manifest.permission.BLUETOOTH_CONNECT) != PackageManager.PERMISSION_GRANTED
) {
ToastUtils.errorToast(context, context.getString(info.nightscout.androidaps.core.R.string.needconnectpermission))
return
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import android.annotation.SuppressLint
import android.bluetooth.*
import android.content.Context
import android.content.pm.PackageManager
import android.os.Build
import android.os.SystemClock
import androidx.core.app.ActivityCompat
import dagger.android.HasAndroidInjector
Expand Down Expand Up @@ -35,9 +36,10 @@ class BLECommonService @Inject internal constructor(
private val diaconnG8ResponseMessageHashTable: DiaconnG8ResponseMessageHashTable,
private val diaconnG8SettingResponseMessageHashTable: DiaconnG8SettingResponseMessageHashTable,
private val diaconnG8Pump: DiaconnG8Pump,
){
) {

companion object {

private const val WRITE_DELAY_MILLIS: Long = 50
private const val INDICATION_UUID = "6e400003-b5a3-f393-e0a9-e50e24dcca9e"
private const val WRITE_UUID = "6e400002-b5a3-f393-e0a9-e50e24dcca9e"
Expand All @@ -57,7 +59,7 @@ class BLECommonService @Inject internal constructor(
private var uartIndicate: BluetoothGattCharacteristic? = null
private var uartWrite: BluetoothGattCharacteristic? = null

private var mSequence : Int = 0
private var mSequence: Int = 0

private fun getMsgSequence(): Int {
val seq = mSequence % 255
Expand All @@ -70,7 +72,9 @@ class BLECommonService @Inject internal constructor(

@Synchronized
fun connect(from: String, address: String?): Boolean {
if (ActivityCompat.checkSelfPermission(context, Manifest.permission.BLUETOOTH_CONNECT) != PackageManager.PERMISSION_GRANTED) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S &&
ActivityCompat.checkSelfPermission(context, Manifest.permission.BLUETOOTH_CONNECT) != PackageManager.PERMISSION_GRANTED
) {
ToastUtils.errorToast(context, context.getString(info.nightscout.androidaps.core.R.string.needconnectpermission))
aapsLogger.error(LTag.PUMPBTCOMM, "missing permission: $from")
return false
Expand Down Expand Up @@ -107,7 +111,9 @@ class BLECommonService @Inject internal constructor(

@Synchronized
fun disconnect(from: String) {
if (ActivityCompat.checkSelfPermission(context, Manifest.permission.BLUETOOTH_CONNECT) != PackageManager.PERMISSION_GRANTED) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S &&
ActivityCompat.checkSelfPermission(context, Manifest.permission.BLUETOOTH_CONNECT) != PackageManager.PERMISSION_GRANTED
) {
aapsLogger.error(LTag.PUMPBTCOMM, "missing permission: $from")
return
}
Expand Down Expand Up @@ -156,7 +162,7 @@ class BLECommonService @Inject internal constructor(
override fun onCharacteristicChanged(gatt: BluetoothGatt, characteristic: BluetoothGattCharacteristic) {
aapsLogger.debug(LTag.PUMPBTCOMM, "(응답) onCharacteristicChanged: " + DiaconnG8Packet.toHex(characteristic.value))
// 대량로그응답 처리.
if(characteristic.value[1] == 0xb2.toByte()) {
if (characteristic.value[1] == 0xb2.toByte()) {
aapsLogger.debug(LTag.PUMPBTCOMM, "(대량 로그 처리 응답) onCharacteristicChanged: " + DiaconnG8Packet.toHex(characteristic.value))
val message = BigLogInquireResponsePacket(injector)
message.handleMessage(characteristic.value)
Expand Down Expand Up @@ -269,7 +275,7 @@ class BLECommonService @Inject internal constructor(
writeCharacteristicNoResponse(uartWriteBTGattChar, bytes)
// 요청 큐에 요청할 바이트 정보 담기.
synchronized(mSendQueue) {
if(mSendQueue.size > 10) mSendQueue.clear()
if (mSendQueue.size > 10) mSendQueue.clear()
mSendQueue.add(bytes)
}
aapsLogger.debug(LTag.PUMPBTCOMM, "sendMessage() after mSendQueue.size :: ${mSendQueue.size}")
Expand Down Expand Up @@ -301,29 +307,29 @@ class BLECommonService @Inject internal constructor(
aapsLogger.debug(LTag.PUMPBTCOMM, "receivedCommand :: $receivedCommand")

// 응답메시지가 조회응답인지. 설정응답인지 구분해야됨.
var message:DiaconnG8Packet? = null
var message: DiaconnG8Packet? = null
// 요청시퀀스와 응답의 시퀀스가 동일한 경우에만 처리.
// 펌프로부터 받은 보고응답의 경우 처리
if(receivedType == 3) {
if (receivedType == 3) {
message = diaconnG8ResponseMessageHashTable.findMessage(receivedCommand)
// injection Blocked Report
if(message is InjectionBlockReportPacket ) {
if (message is InjectionBlockReportPacket) {
message.handleMessage(data)
diaconnG8Pump.bolusBlocked = true
ErrorHelperActivity.runAlarm(context, rh.gs(R.string.injectionblocked), rh.gs(R.string.injectionblocked), R.raw.boluserror )
ErrorHelperActivity.runAlarm(context, rh.gs(R.string.injectionblocked), rh.gs(R.string.injectionblocked), R.raw.boluserror)
return
}
// battery warning report
if(message is BatteryWarningReportPacket ) {
if (message is BatteryWarningReportPacket) {
message.handleMessage(data)
ErrorHelperActivity.runAlarm(context, rh.gs(R.string.needbatteryreplace), rh.gs(R.string.batterywarning), R.raw.boluserror )
ErrorHelperActivity.runAlarm(context, rh.gs(R.string.needbatteryreplace), rh.gs(R.string.batterywarning), R.raw.boluserror)
return
}

// insulin lack warning report
if(message is InsulinLackReportPacket ) {
if (message is InsulinLackReportPacket) {
message.handleMessage(data)
ErrorHelperActivity.runAlarm(context, rh.gs(R.string.needinsullinreplace), rh.gs(R.string.insulinlackwarning), R.raw.boluserror )
ErrorHelperActivity.runAlarm(context, rh.gs(R.string.needinsullinreplace), rh.gs(R.string.insulinlackwarning), R.raw.boluserror)
return
}

Expand All @@ -332,7 +338,7 @@ class BLECommonService @Inject internal constructor(
synchronized(mSendQueue) {
val sendQueueSize = mSendQueue.size
if (sendQueueSize > 0) {
for (i in sendQueueSize-1 downTo 0 ) {
for (i in sendQueueSize - 1 downTo 0) {
val sendQueueSeq = DiaconnG8Packet(injector).getSeq(mSendQueue[i])
val sendQueueType = DiaconnG8Packet(injector).getType(mSendQueue[i])
if (sendQueueSeq == receivedSeq) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Binder;
import android.os.Build;
import android.os.IBinder;
import android.os.PowerManager;

Expand Down Expand Up @@ -261,7 +262,7 @@ public synchronized InsightState getState() {
@Override
public synchronized void onCreate() {
super.onCreate();
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.BLUETOOTH_CONNECT) == PackageManager.PERMISSION_GRANTED) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.S || ActivityCompat.checkSelfPermission(this, Manifest.permission.BLUETOOTH_CONNECT) == PackageManager.PERMISSION_GRANTED) {
bluetoothAdapter = ((BluetoothManager) getApplicationContext().getSystemService(Context.BLUETOOTH_SERVICE)).getAdapter();
pairingDataStorage = new PairingDataStorage(this);
state = pairingDataStorage.isPaired() ? InsightState.DISCONNECTED : InsightState.NOT_PAIRED;
Expand Down

0 comments on commit f8acbad

Please sign in to comment.