Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vNext #148

Merged
merged 38 commits into from
Apr 18, 2024
Merged

vNext #148

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
c02835d
Upgrade Gradle and Android version
pachi81 Mar 14, 2024
eae60b0
Libre support for multiple patients
pachi81 Mar 17, 2024
ee1a3b0
Reset multiple patients
pachi81 Mar 20, 2024
d4cf6b4
Lockscreen Wallpaper
pachi81 Mar 20, 2024
f6cb7f3
Refactor startForegroundService
pachi81 Mar 20, 2024
f323aa6
Optimize IOB/COB change notification
pachi81 Apr 4, 2024
f7f56f9
Refactor time notifier
pachi81 Apr 4, 2024
80d3415
Upgrade to gradle 8.3.1
pachi81 Apr 5, 2024
bd8a9c2
Reset LibreLink on error
pachi81 Apr 5, 2024
116ad14
Update kotlin to 1.9.23
pachi81 Apr 7, 2024
d95f935
Add portuguese strings
pachi81 Apr 5, 2024
52e5f5b
Fix notification permission and foreground service
pachi81 Apr 7, 2024
891e416
Fix LibreLink region handling
pachi81 Apr 8, 2024
8869c40
LibreLinkUp string updated
pachi81 Apr 8, 2024
b9bffb4
Check connection for remote nighscout
pachi81 Apr 8, 2024
a260ca5
Change debug version
pachi81 Apr 4, 2024
7e6a189
v0.9.12
pachi81 Apr 11, 2024
4785343
Update strings.xml - PL strings translated
froster82 Apr 12, 2024
d0272ab
Update string pt
pachi81 Apr 14, 2024
a6be266
Add floating widget toggle
pachi81 Apr 14, 2024
f01c472
v27
pachi81 Apr 14, 2024
b5b7eae
Update strings.xml
dinizmauricio Apr 14, 2024
81f2723
Merge pull request #150 from dinizmauricio/patch-1
pachi81 Apr 14, 2024
6620434
Update strings.xml
dinizmauricio Apr 14, 2024
1e78626
Bugfixes
pachi81 Apr 15, 2024
1ff5d58
v28
pachi81 Apr 15, 2024
b44aad1
Use relative time as default
pachi81 Apr 15, 2024
996bb95
Setting for colored notification icon
pachi81 Apr 15, 2024
191dacb
Update strings.xml
dinizmauricio Apr 15, 2024
db1f438
Update strings.xml
dinizmauricio Apr 15, 2024
4800c7e
Update strings.xml PL
froster82 Apr 15, 2024
29dc67d
v29
pachi81 Apr 15, 2024
4083397
Update strings.xml small correction to one old string
froster82 Apr 15, 2024
1812003
Improve wear phone check
pachi81 Apr 16, 2024
0ccf593
Fix obsolete time handling
pachi81 Apr 16, 2024
2630246
Try fix play crashes
pachi81 Apr 16, 2024
8535dc6
Update strings.xml PL
froster82 Apr 16, 2024
ba10c7c
change apk name
pachi81 Apr 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/kotlinc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions auto/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ android {
resValue "string", "app_name", "GlucoDataAuto"
}
dev_release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-dev-rules.pro'
versionNameSuffix '-dev'
resValue "string", "app_name", "GlucoDataAuto"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ class GlucoDataServiceAuto: Service() {
Log.d(LOG_ID, "onStartCommand called")
super.onStartCommand(intent, flags, startId)
val isForeground = intent.getBooleanExtra(Constants.SHARED_PREF_FOREGROUND_SERVICE, false)
if (isForeground && !isForegroundService && Utils.checkPermission(this, android.Manifest.permission.POST_NOTIFICATIONS, Build.VERSION_CODES.TIRAMISU)) {
if (isForeground && !isForegroundService) {
Log.i(LOG_ID, "Starting service in foreground!")
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R)
startForeground(NOTIFICATION_ID, getNotification(), ServiceInfo.FOREGROUND_SERVICE_TYPE_DATA_SYNC)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ class MainActivity : AppCompatActivity(), NotifierInterface {
InternalNotifier.addNotifier( this, this, mutableSetOf(
NotifySource.BROADCAST,
NotifySource.IOB_COB_CHANGE,
NotifySource.IOB_COB_TIME,
NotifySource.MESSAGECLIENT,
NotifySource.CAPILITY_INFO,
NotifySource.NODE_BATTERY_LEVEL,
Expand Down
10 changes: 5 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
id 'com.android.application' version '8.1.2' apply false
id 'com.android.library' version '8.1.2' apply false
id 'org.jetbrains.kotlin.android' version '1.8.20' apply false
id 'com.android.application' version '8.3.1' apply false
id 'com.android.library' version '8.3.1' apply false
id 'org.jetbrains.kotlin.android' version '1.9.23' apply false
}

project.ext.set("versionCode", 26)
project.ext.set("versionName", "0.9.11")
project.ext.set("versionCode", 30)
project.ext.set("versionName", "0.9.12")
project.ext.set("compileSdk", 34)
project.ext.set("targetSdk", 33)
project.ext.set("minSdk", 26)
Expand Down
2 changes: 2 additions & 0 deletions common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ android {
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
dev_release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-dev-rules.pro'
}
}
compileOptions {
Expand Down
32 changes: 32 additions & 0 deletions common/proguard-dev-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
-dontwarn **
-keep class **
-keepclassmembers class *{*;}
-keepattributes *

# --------------------------------------------------------------------
# REMOVE all debug log messages
# --------------------------------------------------------------------
-assumenosideeffects class android.util.Log {
public static *** v(...);
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ object Constants {
const val SHARED_PREF_COLOR_OK = "color_ok"
//const val SHARED_PREF_PERMANENT_NOTIFICATION = "permanent_notification"
const val SHARED_PREF_PERMANENT_NOTIFICATION_ICON = "status_bar_notification_icon"
const val SHARED_PREF_PERMANENT_NOTIFICATION_COLORED_ICON = "status_bar_notification_colored_icon"
const val SHARED_PREF_PERMANENT_NOTIFICATION_EMPTY = "permanent_notification_empty"
const val SHARED_PREF_SECOND_PERMANENT_NOTIFICATION = "second_permanent_notification"
const val SHARED_PREF_SECOND_PERMANENT_NOTIFICATION_ICON = "second_status_bar_notification_icon"
Expand Down Expand Up @@ -105,6 +106,7 @@ object Constants {
const val SHARED_PREF_LIBRE_TOKEN="source_libre_token"
const val SHARED_PREF_LIBRE_TOKEN_EXPIRE="source_libre_token_expire"
const val SHARED_PREF_LIBRE_REGION="source_libre_region"
const val SHARED_PREF_LIBRE_PATIENT_ID="source_libre_patient_id"

const val SHARED_PREF_NIGHTSCOUT_ENABLED="src_ns_enabled"
const val SHARED_PREF_NIGHTSCOUT_URL="src_ns_url"
Expand All @@ -114,6 +116,9 @@ object Constants {

const val SHARED_PREF_DUMMY_VALUES = "dummy_values"

const val SHARED_PREF_LOCKSCREEN_WP_ENABLED = "lockscreen_enabled"
const val SHARED_PREF_LOCKSCREEN_WP_Y_POS = "lockscreen_y_pos"

// Android Auto
const val AA_MEDIA_ICON_STYLE_TREND = "trend"
const val AA_MEDIA_ICON_STYLE_GLUCOSE_TREND = "glucose_trend"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import de.michelinside.glucodatahandler.common.tasks.TimeTaskService
import de.michelinside.glucodatahandler.common.utils.GlucoDataUtils
import de.michelinside.glucodatahandler.common.notification.ChannelType
import de.michelinside.glucodatahandler.common.notification.Channels
import de.michelinside.glucodatahandler.common.utils.Utils

enum class AppSource {
NOT_SET,
Expand Down Expand Up @@ -63,8 +62,10 @@ abstract class GlucoDataService(source: AppSource) : WearableListenerService() {
}

fun start(source: AppSource, context: Context, cls: Class<*>, force: Boolean = false) {
if (!running || force) {
if (!running || !foreground) {
Log.v(LOG_ID, "start called (running: $running - foreground: $foreground)")
try {
isRunning = true
appSource = source
val serviceIntent = Intent(
context,
Expand All @@ -80,20 +81,30 @@ abstract class GlucoDataService(source: AppSource) : WearableListenerService() {
// default on wear and phone
true//sharedPref.getBoolean(Constants.SHARED_PREF_FOREGROUND_SERVICE, true)
)
context.startService(serviceIntent)
if (foreground) {
context.startService(serviceIntent)
} else {
Log.v(LOG_ID, "start foreground service")
context.startForegroundService(serviceIntent)
}
} catch (exc: Exception) {
Log.e(
LOG_ID,
"start exception: " + exc.message.toString()
)
isRunning = false
}
}
}

fun checkForConnectedNodes() {
fun checkForConnectedNodes(refreshDataOnly: Boolean = false) {
try {
if (connection!=null)
connection!!.checkForConnectedNodes()
Log.d(LOG_ID, "checkForConnectedNodes called for dataOnly=$refreshDataOnly - connection: ${connection!=null}")
if (connection!=null) {
if(!refreshDataOnly)
connection!!.checkForConnectedNodes()
connection!!.checkForNodesWithoutData()
}
} catch (exc: Exception) {
Log.e(
LOG_ID,
Expand All @@ -112,10 +123,10 @@ abstract class GlucoDataService(source: AppSource) : WearableListenerService() {
@RequiresApi(Build.VERSION_CODES.Q)
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
try {
Log.d(LOG_ID, "onStartCommand called")
Log.v(LOG_ID, "onStartCommand called")
super.onStartCommand(intent, flags, startId)
val isForeground = true // intent?.getBooleanExtra(Constants.SHARED_PREF_FOREGROUND_SERVICE, true) --> always use foreground!!!
if (isForeground && !isForegroundService && Utils.checkPermission(this, android.Manifest.permission.POST_NOTIFICATIONS, Build.VERSION_CODES.TIRAMISU)) {
if (isForeground && !isForegroundService) {
Log.i(LOG_ID, "Starting service in foreground!")
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R)
startForeground(NOTIFICATION_ID, getNotification(), ServiceInfo.FOREGROUND_SERVICE_TYPE_DATA_SYNC)
Expand Down Expand Up @@ -199,6 +210,7 @@ abstract class GlucoDataService(source: AppSource) : WearableListenerService() {
super.onDestroy()
service = null
isRunning = false
isForegroundService = false
} catch (exc: Exception) {
Log.e(LOG_ID, "onDestroy exception: " + exc.toString())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -475,14 +475,23 @@ object ReceiveData: SharedPreferences.OnSharedPreferenceChangeListener {
System.currentTimeMillis()

if(!isIobCob() || (newTime > iobCobTime && (newTime-iobCobTime) > 30000)) {
Log.i(LOG_ID, "Only IOB/COB changed: " + extras.getFloat(IOB, Float.NaN) + "/" + extras.getFloat(COB, Float.NaN))
iob = extras.getFloat(IOB, Float.NaN)
cob = extras.getFloat(COB, Float.NaN)
var iobCobChange = false
if(iob != extras.getFloat(IOB, Float.NaN) || cob != extras.getFloat(COB, Float.NaN)) {
Log.i(LOG_ID, "Only IOB/COB changed: " + extras.getFloat(IOB, Float.NaN) + "/" + extras.getFloat(COB, Float.NaN))
iob = extras.getFloat(IOB, Float.NaN)
cob = extras.getFloat(COB, Float.NaN)
iobCobChange = true
} else {
Log.d(LOG_ID, "Only IOB/COB time changed")
}
iobCobTime = newTime

// do not forward extras as interApp to prevent sending back to source...
val bundle: Bundle? = if(interApp) null else createExtras() // re-create extras to have all changed value inside for sending to receiver
InternalNotifier.notify(context, NotifySource.IOB_COB_CHANGE, bundle)
if(iobCobChange)
InternalNotifier.notify(context, NotifySource.IOB_COB_CHANGE, bundle)
else
InternalNotifier.notify(context, NotifySource.IOB_COB_TIME, bundle)
saveExtras(context)
}
}
Expand Down Expand Up @@ -622,7 +631,7 @@ object ReceiveData: SharedPreferences.OnSharedPreferenceChangeListener {

private fun saveExtras(context: Context) {
try {
Log.d(LOG_ID, "Saving extras")
Log.v(LOG_ID, "Saving extras")
// use own tag to prevent trigger onChange event at every time!
val sharedGlucosePref = context.getSharedPreferences(Constants.GLUCODATA_BROADCAST_ACTION, Context.MODE_PRIVATE)
with(sharedGlucosePref.edit()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package de.michelinside.glucodatahandler.common

import android.content.Context
import android.os.Handler
import android.util.Log
import de.michelinside.glucodatahandler.common.notifier.DataSource
import de.michelinside.glucodatahandler.common.notifier.InternalNotifier
import de.michelinside.glucodatahandler.common.notifier.NotifySource
Expand All @@ -13,6 +14,7 @@ enum class SourceState(val resId: Int) {
ERROR(R.string.source_state_error);
}
object SourceStateData {
private val LOG_ID = "GDH.SourceStateData"

var lastSource: DataSource = DataSource.NONE
var lastState: SourceState = SourceState.NONE
Expand All @@ -27,6 +29,10 @@ object SourceStateData {
lastSource = source
lastState = state

if(state == SourceState.ERROR) {
Log.e(LOG_ID, "Error state for source $source: $error" )
}

if (GlucoDataService.context != null) {
Handler(GlucoDataService.context!!.mainLooper).post {
InternalNotifier.notify(GlucoDataService.context!!, NotifySource.SOURCE_STATE_CHANGE, null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ class WearPhoneConnection : MessageClient.OnMessageReceivedListener, CapabilityC
val filter = mutableSetOf(
NotifySource.BROADCAST,
NotifySource.IOB_COB_CHANGE,
NotifySource.IOB_COB_TIME,
NotifySource.BATTERY_LEVEL) // to trigger re-start for the case of stopped by the system
if (sendSettings) {
filter.add(NotifySource.SETTINGS) // only send setting changes from phone to wear!
Expand Down Expand Up @@ -122,6 +123,19 @@ class WearPhoneConnection : MessageClient.OnMessageReceivedListener, CapabilityC
}
}

fun checkForNodesWithoutData() {
try {
Log.d(LOG_ID, "check for connected nodes without data")
connectedNodes.forEach { node ->
if (!nodeBatteryLevel.containsKey(node.key)) {
sendDataRequest(node.value.id)
}
}
} catch (exc: Exception) {
Log.e(LOG_ID, "checkForNodesWithoutData exception: " + exc.toString())
}
}

private fun setConnectedNodes(nodes: MutableSet<Node>) {
val curNodes = connectedNodes.keys.toSortedSet()
val newNodes = nodes.map { it.id }.toSortedSet()
Expand All @@ -141,13 +155,17 @@ class WearPhoneConnection : MessageClient.OnMessageReceivedListener, CapabilityC
}
}
}
val extras = ReceiveData.createExtras()
InternalNotifier.notify(context, NotifySource.CAPILITY_INFO, ReceiveData.createExtras())
sendMessage(NotifySource.CAPILITY_INFO, extras) // send data request for new node
sendDataRequest()
}
}

fun checkConnectedNode(nodeId: String) {
private fun sendDataRequest(filterReceiverId: String? = null) {
val extras = ReceiveData.createExtras()
InternalNotifier.notify(context, NotifySource.CAPILITY_INFO, ReceiveData.createExtras())
sendMessage(NotifySource.CAPILITY_INFO, extras, filterReceiverId = filterReceiverId) // send data request for new node
}

private fun checkConnectedNode(nodeId: String) {
if (!connectedNodes.containsKey(nodeId)) {
Log.i(LOG_ID, "Node with id " + nodeId + " not yet connected, check connection!")
checkForConnectedNodes()
Expand Down Expand Up @@ -180,10 +198,10 @@ class WearPhoneConnection : MessageClient.OnMessageReceivedListener, CapabilityC
else -> Constants.GLUCODATA_INTENT_MESSAGE_PATH
}

fun sendMessage(dataSource: NotifySource, extras: Bundle?, ignoreReceiverId: String? = null, filterReiverId: String? = null)
fun sendMessage(dataSource: NotifySource, extras: Bundle?, ignoreReceiverId: String? = null, filterReceiverId: String? = null)
{
try {
Log.v(LOG_ID, "sendMessage called for $dataSource filter receiver $filterReiverId ignoring receiver $ignoreReceiverId with extras $extras")
Log.v(LOG_ID, "sendMessage called for $dataSource filter receiver $filterReceiverId ignoring receiver $ignoreReceiverId with extras $extras")
if( nodesConnected && dataSource != NotifySource.NODE_BATTERY_LEVEL ) {
Log.d(LOG_ID, connectedNodes.size.toString() + " nodes found for sending message for " + dataSource.toString())
if (extras != null && dataSource != NotifySource.BATTERY_LEVEL && BatteryReceiver.batteryPercentage > 0) {
Expand All @@ -198,7 +216,7 @@ class WearPhoneConnection : MessageClient.OnMessageReceivedListener, CapabilityC
connectedNodes.forEach { node ->
Thread {
try {
if ((ignoreReceiverId == null && filterReiverId == null) || ignoreReceiverId != node.value.id || filterReiverId == node.value.id) {
if ((ignoreReceiverId == null && filterReceiverId == null) || ignoreReceiverId != node.value.id || filterReceiverId == node.value.id) {
if (dataSource == NotifySource.CAPILITY_INFO)
Thread.sleep(1000) // wait a bit after the connection has changed
sendMessage(node.value, getPath(dataSource), Utils.bundleToBytes(extras), dataSource)
Expand Down Expand Up @@ -391,7 +409,7 @@ class WearPhoneConnection : MessageClient.OnMessageReceivedListener, CapabilityC

override fun OnNotifyData(context: Context, dataSource: NotifySource, extras: Bundle?) {
try {
if (dataSource != NotifySource.IOB_COB_CHANGE || extras != null) { // do not send IOB change without extras
if ((dataSource != NotifySource.IOB_COB_CHANGE && dataSource != NotifySource.IOB_COB_TIME) || extras != null) { // do not send IOB change without extras
Log.d(LOG_ID, "OnNotifyData for source " + dataSource.toString() + " and extras " + extras.toString())
sendMessage(dataSource, extras)
}
Expand Down
Loading