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 18 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
8 changes: 4 additions & 4 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("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 @@ -105,6 +105,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 +115,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,12 +81,18 @@ 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
}
}
}
Expand All @@ -112,10 +119,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 +206,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 @@ -391,7 +392,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
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,31 @@ import android.util.Log
object InternalNotifier {
private const val LOG_ID = "GDH.InternalNotifier"
private var notifiers = mutableMapOf<NotifierInterface, MutableSet<NotifySource>?>()
private var timeNotifierCount = 0
private var obsoleteNotifierCount = 0
val hasTimeNotifier: Boolean get() = timeNotifierCount>0
val hasObsoleteNotifier: Boolean get() = obsoleteNotifierCount>0

fun addNotifier(context: Context, notifier: NotifierInterface, sourceFilter: MutableSet<NotifySource>)
{
val timeChanged = hasSource(notifier, NotifySource.TIME_VALUE) != sourceFilter.contains(NotifySource.TIME_VALUE) ||
hasSource(notifier, NotifySource.OBSOLETE_VALUE) != sourceFilter.contains(NotifySource.OBSOLETE_VALUE)
Log.i(LOG_ID, "add notifier " + notifier.toString() + " - filter: " + sourceFilter.toString() )
notifiers[notifier] = sourceFilter
Log.d(LOG_ID, "notifier size: " + notifiers.size.toString() )
notify(context, NotifySource.NOTIFIER_CHANGE, null)
if(timeChanged)
checkTimeNotifierChanged(context)

}
fun remNotifier(context: Context, notifier: NotifierInterface)
{
Log.i(LOG_ID, "rem notifier " + notifier.toString() )
val timeChanged = hasSource(notifier, NotifySource.TIME_VALUE) ||
hasSource(notifier, NotifySource.OBSOLETE_VALUE)
notifiers.remove(notifier)
Log.d(LOG_ID, "notifier size: " + notifiers.size.toString() )
notify(context, NotifySource.NOTIFIER_CHANGE, null)
if(timeChanged)
checkTimeNotifierChanged(context)
}

fun hasNotifier(notifier: NotifierInterface): Boolean {
Expand All @@ -28,11 +40,11 @@ object InternalNotifier {

fun notify(context: Context, notifySource: NotifySource, extras: Bundle?)
{
Log.d(LOG_ID, "Sending new data to " + notifiers.size.toString() + " notifier(s).")
Log.d(LOG_ID, "Sending new data from " + notifySource.toString() + " to " + getNotifierCount(notifySource) + " notifier(s).")
notifiers.forEach{
try {
if (it.value == null || it.value!!.contains(notifySource)) {
Log.d(LOG_ID, "Sending new data from " + notifySource.toString() + " to " + it.toString())
Log.v(LOG_ID, "Sending new data from " + notifySource.toString() + " to " + it.toString())
it.key.OnNotifyData(context, notifySource, extras)
}
} catch (exc: Exception) {
Expand All @@ -50,4 +62,33 @@ object InternalNotifier {
}
return count
}

private fun checkTimeNotifierChanged(context: Context) {
var trigger = false
val newTimeCount = getNotifierCount(NotifySource.TIME_VALUE)
if(timeNotifierCount != newTimeCount) {
Log.d(LOG_ID, "Time notifier have changed from $timeNotifierCount to $newTimeCount")
val curCount = timeNotifierCount
timeNotifierCount = newTimeCount
if(curCount == 0 || newTimeCount == 0)
trigger = true
}
val newObsoleteCount = getNotifierCount(NotifySource.TIME_VALUE)
if(obsoleteNotifierCount != newObsoleteCount) {
Log.d(LOG_ID, "Obsolete notifier have changed from $obsoleteNotifierCount to $newObsoleteCount")
val curCount = obsoleteNotifierCount
obsoleteNotifierCount = newObsoleteCount
if(curCount == 0 || newObsoleteCount == 0)
trigger = true
}
if(trigger)
notify(context, NotifySource.TIME_NOTIFIER_CHANGE, null)
}

private fun hasSource(notifier: NotifierInterface, notifySource: NotifySource): Boolean {
if(hasNotifier(notifier)) {
return notifiers[notifier]!!.contains(notifySource)
}
return false
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ enum class NotifySource {
TIME_VALUE,
SOURCE_SETTINGS,
SOURCE_STATE_CHANGE,
NOTIFIER_CHANGE,
TIME_NOTIFIER_CHANGE,
IOB_COB_CHANGE,
LOGCAT_REQUEST;
IOB_COB_TIME,
LOGCAT_REQUEST,
PATIENT_DATA_CHANGED;
}
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,11 @@ abstract class DataSourceTask(private val enabledKey: String, protected val sour
}

fun setState(state: SourceState, error: String = "", code: Int = -1) {
Log.v(LOG_ID,"Set state for source " + source + ": " + state + " - " + error + " (" + code + ")")
if(state == SourceState.NONE) {
Log.v(LOG_ID,"Set state for source " + source + ": " + state + " - " + error + " (" + code + ")")
} else {
Log.w(LOG_ID,"Set state for source " + source + ": " + state + " - " + error + " (" + code + ")")
}
lastErrorCode = code
lastState = state

Expand Down
Loading