diff --git a/app/app.iml b/app/app.iml index 64d6745fc2dd8b8b59b04183e473bbb26bc61ebd..5fefeca364786c6e7aba1a2bd685e6b58b440429 100644 --- a/app/app.iml +++ b/app/app.iml @@ -67,14 +67,6 @@ <sourceFolder url="file://$MODULE_DIR$/src/main/jni" isTestSource="false" /> <sourceFolder url="file://$MODULE_DIR$/src/main/rs" isTestSource="false" /> <sourceFolder url="file://$MODULE_DIR$/src/main/shaders" isTestSource="false" /> - <sourceFolder url="file://$MODULE_DIR$/src/androidTest/res" type="java-test-resource" /> - <sourceFolder url="file://$MODULE_DIR$/src/androidTest/resources" type="java-test-resource" /> - <sourceFolder url="file://$MODULE_DIR$/src/androidTest/assets" type="java-test-resource" /> - <sourceFolder url="file://$MODULE_DIR$/src/androidTest/aidl" isTestSource="true" /> - <sourceFolder url="file://$MODULE_DIR$/src/androidTest/java" isTestSource="true" /> - <sourceFolder url="file://$MODULE_DIR$/src/androidTest/jni" isTestSource="true" /> - <sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" /> - <sourceFolder url="file://$MODULE_DIR$/src/androidTest/shaders" isTestSource="true" /> <sourceFolder url="file://$MODULE_DIR$/src/test/res" type="java-test-resource" /> <sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" /> <sourceFolder url="file://$MODULE_DIR$/src/test/assets" type="java-test-resource" /> @@ -83,6 +75,14 @@ <sourceFolder url="file://$MODULE_DIR$/src/test/jni" isTestSource="true" /> <sourceFolder url="file://$MODULE_DIR$/src/test/rs" isTestSource="true" /> <sourceFolder url="file://$MODULE_DIR$/src/test/shaders" isTestSource="true" /> + <sourceFolder url="file://$MODULE_DIR$/src/androidTest/res" type="java-test-resource" /> + <sourceFolder url="file://$MODULE_DIR$/src/androidTest/resources" type="java-test-resource" /> + <sourceFolder url="file://$MODULE_DIR$/src/androidTest/assets" type="java-test-resource" /> + <sourceFolder url="file://$MODULE_DIR$/src/androidTest/aidl" isTestSource="true" /> + <sourceFolder url="file://$MODULE_DIR$/src/androidTest/java" isTestSource="true" /> + <sourceFolder url="file://$MODULE_DIR$/src/androidTest/jni" isTestSource="true" /> + <sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" /> + <sourceFolder url="file://$MODULE_DIR$/src/androidTest/shaders" isTestSource="true" /> <excludeFolder url="file://$MODULE_DIR$/build/intermediates/assets" /> <excludeFolder url="file://$MODULE_DIR$/build/intermediates/blame" /> <excludeFolder url="file://$MODULE_DIR$/build/intermediates/builds" /> @@ -118,6 +118,7 @@ <excludeFolder url="file://$MODULE_DIR$/build/intermediates/instant-run-support" /> <excludeFolder url="file://$MODULE_DIR$/build/intermediates/jniLibs" /> <excludeFolder url="file://$MODULE_DIR$/build/intermediates/manifests" /> + <excludeFolder url="file://$MODULE_DIR$/build/intermediates/pre-dexed" /> <excludeFolder url="file://$MODULE_DIR$/build/intermediates/reload-dex" /> <excludeFolder url="file://$MODULE_DIR$/build/intermediates/res" /> <excludeFolder url="file://$MODULE_DIR$/build/intermediates/restart-dex" /> diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 998174b79466a2a7935483368e68b0820721f3da..7b0921ff8d90402ed79bb5f245a2348993ece359 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -26,6 +26,9 @@ android:supportsRtl="true" android:theme="@style/AppTheme"> + <!-- allow to disable battery optimization --> + <uses-permission-sdk-23 android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" /> + <!-- I have set screenOrientation to "portrait" to avoid the restart of AsyncTasks when you rotate the phone --> <activity android:name=".medtronic.MainActivity" diff --git a/app/src/main/java/info/nightscout/android/medtronic/MainActivity.java b/app/src/main/java/info/nightscout/android/medtronic/MainActivity.java index 8a381cf5a2df9916dad207c79da47fe2d8bde3cc..fa3d8d1baf70915b2d2b733f02f3655cf7cfa0f1 100644 --- a/app/src/main/java/info/nightscout/android/medtronic/MainActivity.java +++ b/app/src/main/java/info/nightscout/android/medtronic/MainActivity.java @@ -3,6 +3,7 @@ package info.nightscout.android.medtronic; import android.app.AlarmManager; import android.app.NotificationManager; import android.app.PendingIntent; +import android.content.ActivityNotFoundException; import android.content.BroadcastReceiver; import android.content.Context; import android.content.DialogInterface; @@ -12,10 +13,14 @@ import android.content.SharedPreferences; import android.content.SharedPreferences.OnSharedPreferenceChangeListener; import android.hardware.usb.UsbDevice; import android.hardware.usb.UsbManager; +import android.net.Uri; import android.os.BatteryManager; +import android.os.Build; import android.os.Bundle; import android.os.Handler; +import android.os.PowerManager; import android.preference.PreferenceManager; +import android.provider.Settings; import android.support.v4.app.TaskStackBuilder; import android.support.v4.content.LocalBroadcastManager; import android.support.v7.app.AlertDialog; @@ -106,6 +111,29 @@ public class MainActivity extends AppCompatActivity implements OnSharedPreferenc stopCgmService(); } + // Disable battery optimization to avoid missing values on 6.0+ + // taken from https://github.com/NightscoutFoundation/xDrip/blob/master/app/src/main/java/com/eveningoutpost/dexdrip/Home.java#L277L298 + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + final String packageName = getPackageName(); + //Log.d(TAG, "Maybe ignoring battery optimization"); + final PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); + if (!pm.isIgnoringBatteryOptimizations(packageName) && + !prefs.getBoolean("requested_ignore_battery_optimizations", false)) { + Log.d(TAG, "Requesting ignore battery optimization"); + try { + // ignoring battery optimizations required for constant connection + // to peripheral device - eg CGM transmitter. + final Intent intent = new Intent(); + intent.setAction(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS); + intent.setData(Uri.parse("package:" + packageName)); + startActivity(intent); + } catch (ActivityNotFoundException e) { + Log.d(TAG, "Device does not appear to support battery optimization whitelisting!"); + } + } + } + LocalBroadcastManager.getInstance(this).registerReceiver( statusMessageReceiver, new IntentFilter(MedtronicCnlIntentService.Constants.ACTION_STATUS_MESSAGE)); diff --git a/app/src/main/res/xml-v23/preferences.xml b/app/src/main/res/xml-v23/preferences.xml new file mode 100644 index 0000000000000000000000000000000000000000..5dd097201e3b445dd0e5f8d8d1167e2780637a0a --- /dev/null +++ b/app/src/main/res/xml-v23/preferences.xml @@ -0,0 +1,97 @@ +<?xml version="1.0" encoding="utf-8"?> +<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"> + <PreferenceCategory android:title="Monitor"> + <info.nightscout.android.utils.CustomSwitchPreference + android:disableDependentsState="false" + android:key="mmolxl" + android:summaryOff="Values are shown and set in mg/dL" + android:summaryOn="Values are shown and set in mmol/L" + android:switchTextOff="mg/dL" + android:switchTextOn="mmol/L" + android:title="BG Unit"/> + <info.nightscout.android.utils.CustomSwitchPreference + android:defaultValue="false" + android:dependency="mmolxl" + android:key="mmolDecimals" + android:summaryOff="1 decimal value will be shown" + android:summaryOn="2 decimal values will be shown" + android:switchTextOff="1" + android:switchTextOn="2" + android:title="Decimals"/> + </PreferenceCategory> + <PreferenceCategory android:title="Device setting"> + <info.nightscout.android.utils.CustomSwitchPreference + android:disableDependentsState="false" + android:key="requested_ignore_battery_optimizations" + android:summaryOff="Request to ignore battery optimization" + android:summaryOn="Don't request to ignore battery optimization" + android:switchTextOff="off" + android:switchTextOn="on" + android:title="Disable to ignore battery optimization"/> + </PreferenceCategory> + <PreferenceCategory android:title="Sharing"> + <CheckBoxPreference + android:disableDependentsState="false" + android:key="@string/preference_enable_rest_upload" + android:summary="Enable upload of data to Nightscout" + android:title="REST API Upload"/> + <EditTextPreference + android:defaultValue="https://YOUR.NIGHTSCOUT.SITE" + android:dependency="@string/preference_enable_rest_upload" + android:dialogMessage="The hostname of your Nightscout site" + android:dialogTitle="Enter Nightscout URL" + android:key="@string/preference_nightscout_url" + android:title="Nightscout URL"/> + <info.nightscout.android.utils.ValidatingEditTextPreference + android:defaultValue="YOURAPISECRET" + android:dependency="@string/preference_enable_rest_upload" + android:dialogMessage="Your Nightscout API secret" + android:dialogTitle="Enter your Nightscout API secret" + android:key="@string/preference_api_secret" + android:title="API Secret"/> + <CheckBoxPreference + android:key="@string/preference_enable_xdrip_plus" + android:summary="Enable local broadcast of data to xDrip+" + android:title="Send to xDrip+"/> + </PreferenceCategory> + <PreferenceCategory android:title="Disclaimer"> + <SwitchPreference + android:disableDependentsState="false" + android:key="@string/preference_eula_accepted" + android:summaryOff="Nightscout should not be used to make medical decisions. There is no support or any warranty of any kind. The quality and performance of the project is with you. This is a project that was created and is supported completely by volunteers" + android:summaryOn="Nightscout should not be used to make medical decisions. There is no support or any warranty of any kind. The quality and performance of the project is with you. This is a project that was created and is supported completely by volunteers" + android:switchTextOff="NO" + android:switchTextOn="YES" + android:title="I UNDERSTAND"/> + </PreferenceCategory> + <PreferenceCategory android:title="App Version"> + <Preference + android:key="version" + android:title="@string/versionName" /> + </PreferenceCategory> + <PreferenceCategory android:title="Debug"> + <SwitchPreference + android:defaultValue="true" + android:key="@string/preferences_enable_crashlytics" + android:summary="Send crash errors to developer" + android:title="Crash Reporting" /> + <SwitchPreference + android:defaultValue="true" + android:key="@string/preferences_enable_answers" + android:summary="Sends usage data to the developer to help develop a better app." + android:title="Share usage data" /> + <SwitchPreference + android:defaultValue="false" + android:key="@string/preferences_enable_remote_logcat" + android:summary="Allow the developer to debug your app. Only enable if asked to by the support team." + android:title="Remote Debugging" /> + <ListPreference + android:defaultValue="1" + android:disableDependentsState="false" + android:entries="@array/levelList" + android:entryValues="@array/calib_types_values" + android:key="logLevel" + android:summary="Select item from array" + android:title="Logging Level" /> + </PreferenceCategory> +</PreferenceScreen> \ No newline at end of file