Skip to content

Commit 49b9d30

Browse files
committed
GluPro: Add Glucose Profile SmartGuide collector
1 parent d90e442 commit 49b9d30

31 files changed

+1579
-64
lines changed

app/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ dependencies {
249249

250250
implementation project(':localeapi')
251251
implementation project(':libkeks')
252+
implementation project(':libglupro')
252253

253254
// add missing JAXB dependencies for JDK 9+
254255
if (JavaVersion.current().ordinal() >= JavaVersion.VERSION_1_9.ordinal()) {

app/src/main/AndroidManifest.xml

Lines changed: 57 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,17 @@
2121

2222
<uses-permission android:name="android.permission.NFC" />
2323
<uses-permission android:name="com.google.android.permission.PROVIDE_BACKGROUND" />
24+
25+
<!-- Remove library-modified permissions -->
26+
<uses-permission
27+
android:name="android.permission.BLUETOOTH"
28+
tools:node="remove" />
29+
30+
<uses-permission
31+
android:name="android.permission.BLUETOOTH_ADMIN"
32+
tools:node="remove" />
33+
34+
2435
<uses-permission android:name="android.permission.BLUETOOTH" />
2536
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
2637
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
@@ -61,32 +72,41 @@
6172
<uses-permission android:name="android.permission.USE_CREDENTIALS" />
6273
<uses-permission android:name="android.permission.SET_WALLPAPER" />
6374
<uses-permission android:name="android.permission.USE_FULL_SCREEN_INTENT" />
75+
<uses-permission android:name="android.permission.MANAGE_HEALTH_DATA" />
76+
<uses-permission android:name="android.permission.MANAGE_HEALTH_PERMISSIONS" />
77+
<uses-permission android:name="android.permission.health.READ_HEART_RATE" />
78+
<uses-permission android:name="android.permission.health.READ_BLOOD_GLUCOSE" />
79+
<uses-permission android:name="android.permission.health.WRITE_BLOOD_GLUCOSE" />
80+
<uses-permission android:name="android.permission.health.READ_STEPS" />
81+
<uses-permission android:name="android.permission.health.READ_EXERCISE" />
82+
<uses-permission android:name="android.permission.health.READ_TOTAL_CALORIES_BURNED" />
83+
<uses-permission android:name="android.permission.health.READ_WEIGHT" />
84+
<uses-permission android:name="android.permission.health.READ_DISTANCE" />
85+
<uses-permission android:name="android.permission.health.READ_ELEVATION_GAINED" />
86+
<uses-permission android:name="android.permission.health.READ_FLOORS_CLIMBED" />
87+
<uses-permission android:name="android.permission.health.READ_HEART_RATE_VARIABILITY" />
88+
<uses-permission android:name="android.permission.health.READ_HEIGHT" />
89+
<uses-permission android:name="android.permission.health.READ_HYDRATION" />
90+
<uses-permission android:name="android.permission.health.READ_NUTRITION" />
91+
<uses-permission android:name="android.permission.health.WRITE_NUTRITION" />
92+
<uses-permission android:name="android.permission.health.READ_POWER" />
93+
<uses-permission android:name="android.permission.health.READ_RESTING_HEART_RATE" />
94+
<uses-permission android:name="android.permission.health.READ_SLEEP" />
95+
<uses-permission android:name="android.permission.health.READ_SPEED" />
96+
<uses-permission android:name="android.permission.health.READ_WHEELCHAIR_PUSHES" />
97+
<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES" />
98+
99+
100+
<!-- Remove permission added by library -->
101+
<uses-permission
102+
android:name="android.permission.BLUETOOTH_SCAN"
103+
tools:node="remove" />
104+
105+
<!-- Remove permission added by library -->
106+
<uses-permission
107+
android:name="android.permission.BLUETOOTH_CONNECT"
108+
tools:node="remove" />
64109

65-
<uses-permission android:name="android.permission.MANAGE_HEALTH_DATA"/>
66-
<uses-permission android:name="android.permission.MANAGE_HEALTH_PERMISSIONS"/>
67-
68-
<uses-permission android:name="android.permission.health.READ_HEART_RATE"/>
69-
<uses-permission android:name="android.permission.health.READ_BLOOD_GLUCOSE"/>
70-
<uses-permission android:name="android.permission.health.WRITE_BLOOD_GLUCOSE"/>
71-
<uses-permission android:name="android.permission.health.READ_STEPS"/>
72-
<uses-permission android:name="android.permission.health.READ_EXERCISE"/>
73-
<uses-permission android:name="android.permission.health.READ_TOTAL_CALORIES_BURNED"/>
74-
<uses-permission android:name="android.permission.health.READ_WEIGHT"/>
75-
<uses-permission android:name="android.permission.health.READ_DISTANCE"/>
76-
<uses-permission android:name="android.permission.health.READ_ELEVATION_GAINED"/>
77-
<uses-permission android:name="android.permission.health.READ_FLOORS_CLIMBED"/>
78-
<uses-permission android:name="android.permission.health.READ_HEART_RATE_VARIABILITY"/>
79-
<uses-permission android:name="android.permission.health.READ_HEIGHT"/>
80-
<uses-permission android:name="android.permission.health.READ_HYDRATION"/>
81-
<uses-permission android:name="android.permission.health.READ_NUTRITION"/>
82-
<uses-permission android:name="android.permission.health.WRITE_NUTRITION"/>
83-
<uses-permission android:name="android.permission.health.READ_POWER"/>
84-
<uses-permission android:name="android.permission.health.READ_RESTING_HEART_RATE"/>
85-
<uses-permission android:name="android.permission.health.READ_SLEEP"/>
86-
<uses-permission android:name="android.permission.health.READ_SPEED"/>
87-
<uses-permission android:name="android.permission.health.READ_WHEELCHAIR_PUSHES"/>
88-
89-
<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES"/>
90110

91111
<application
92112
android:name=".xdrip"
@@ -108,8 +128,13 @@
108128
<action android:name="androidx.health.ACTION_SHOW_PERMISSIONS_RATIONALE" />
109129
</intent-filter>
110130
</activity>
131+
<activity
132+
android:name=".cgm.glupro.GluProActivity"
133+
android:label="@string/glupro_activity_title"
134+
android:exported="false" />
135+
111136
<activity-alias
112-
android:name="AndroidURationaleActivity"
137+
android:name=".AndroidURationaleActivity"
113138
android:exported="true"
114139
android:targetActivity=".HealthPrivacy">
115140
<intent-filter>
@@ -481,6 +506,11 @@
481506
android:enabled="true"
482507
android:exported="false"
483508
android:foregroundServiceType="connectedDevice|location" />
509+
<service
510+
android:name=".cgm.glupro.GluProService"
511+
android:enabled="true"
512+
android:exported="false"
513+
android:foregroundServiceType="connectedDevice|location" />
484514

485515
<activity
486516
android:name=".ShareTest"
@@ -691,7 +721,6 @@
691721
android:configChanges="orientation|screenSize"
692722
android:exported="false"
693723
android:label="@string/title_activity_display_qrcode"
694-
695724
android:noHistory="true" />
696725
<activity
697726
android:name=".utils.LibreTrendGraph"
@@ -801,6 +830,7 @@
801830
android:name=".MegaStatus"
802831
android:configChanges="orientation|screenSize"
803832
android:label="@string/system_status"
833+
android:launchMode="singleTask"
804834
android:parentActivityName=".Home" />
805835
<activity
806836
android:name=".Reminders"
@@ -887,7 +917,6 @@
887917
android:label="BlueJay Admin"
888918
android:launchMode="singleTask" />
889919

890-
891920
<service
892921
android:name=".watch.thinjam.BlueJayService"
893922
android:foregroundServiceType="connectedDevice|location" />

app/src/main/java/com/eveningoutpost/dexdrip/AddCalibration.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -206,16 +206,18 @@ public void onClick(final View v) {
206206
final double calValue = JoH.tolerantParseDouble(string_value);
207207

208208
if (!Home.get_follower()) {
209+
double bg = calValue;
210+
if (unit.compareTo("mgdl") != 0) {
211+
bg = bg * Constants.MMOLL_TO_MGDL;
212+
}
213+
BloodTest.create(JoH.tsl() - (Constants.SECOND_IN_MS * 30), bg, "Add Calibration");
209214
if (DexCollectionType.hasDexcomRaw() && FirmwareCapability.isTransmitterRawIncapable(getTransmitterID())) { // Firefly only
210-
double bg = calValue;
211-
if (unit.compareTo("mgdl") != 0) {
212-
bg = bg * Constants.MMOLL_TO_MGDL;
213-
}
215+
214216
JoH.clearCache();
215217
final Calibration Calibration = new Calibration();
216218
final Sensor sensor = Sensor.currentSensor();
217219
JoH.static_toast_long("Sending Blood Test to Transmitter");
218-
BloodTest.create(JoH.tsl() - (Constants.SECOND_IN_MS * 30), bg, "Add Calibration");
220+
219221
if (!Pref.getBooleanDefaultFalse("bluetooth_meter_for_calibrations_auto")) {
220222
NativeCalibrationPipe.addCalibration((int) bg, JoH.tsl() - (Constants.SECOND_IN_MS * 30));
221223
}

app/src/main/java/com/eveningoutpost/dexdrip/Home.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import static com.eveningoutpost.dexdrip.utilitymodels.Constants.MINUTE_IN_MS;
1515
import static com.eveningoutpost.dexdrip.utilitymodels.Constants.SECOND_IN_MS;
1616
import static com.eveningoutpost.dexdrip.utils.DexCollectionType.getDexCollectionType;
17+
import static com.eveningoutpost.dexdrip.utils.DexCollectionType.GluPro;
1718
import static com.eveningoutpost.dexdrip.xdrip.gs;
1819

1920
import android.Manifest;
@@ -2524,7 +2525,8 @@ private void updateCurrentBgInfo(final String source) {
25242525
} else if (is_follower || collector.isPassive()) {
25252526
displayCurrentInfo();
25262527
Inevitable.task("home-notifications-start", 5000, Notifications::start);
2527-
} else if (!alreadyDisplayedBgInfoCommon && (DexCollectionType.getDexCollectionType() == DexCollectionType.LibreAlarm || collector == DexCollectionType.Medtrum)) {
2528+
// TODO add dexcollectiontype set handling for these
2529+
} else if (!alreadyDisplayedBgInfoCommon && (DexCollectionType.getDexCollectionType() == DexCollectionType.LibreAlarm || collector == DexCollectionType.Medtrum || collector == GluPro)) {
25282530
updateCurrentBgInfoCommon(collector, notificationText);
25292531
}
25302532
if (collector.equals(DexCollectionType.Disabled)) {
@@ -2739,6 +2741,7 @@ private void updateCurrentBgInfoCommon(DexCollectionType collector, TextView not
27392741
}
27402742

27412743
if (!BgReading.doWeHaveRecentUsableData()) {
2744+
// TODO check null handling?
27422745
long startedAt = Sensor.currentSensor().started_at;
27432746
long computedStartedAt = SensorDays.get().getStart();
27442747
if (computedStartedAt > 0) {
@@ -2765,6 +2768,12 @@ private void updateCurrentBgInfoCommon(DexCollectionType collector, TextView not
27652768
return;
27662769
}
27672770

2771+
// we can't use the Dex related code below so we handle things here
2772+
if (DexCollectionType.getDexCollectionType() == GluPro) {
2773+
displayCurrentInfo();
2774+
return;
2775+
}
2776+
27682777
// TODO this logic needed a rework even a year ago, now its a lot more confused with the additional complexity of native mode
27692778
if (Ob1G5CollectionService.isG5ActiveButUnknownState() && Calibration.latestValid(2).size() < 2) {
27702779
// TODO use format string

app/src/main/java/com/eveningoutpost/dexdrip/MegaStatus.java

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import static com.eveningoutpost.dexdrip.Home.startWatchUpdaterService;
1010
import static com.eveningoutpost.dexdrip.utils.DexCollectionType.DexcomG5;
11+
import static com.eveningoutpost.dexdrip.utils.DexCollectionType.GluPro;
1112
import static com.eveningoutpost.dexdrip.utils.DexCollectionType.Medtrum;
1213
import static com.eveningoutpost.dexdrip.utils.DexCollectionType.NSFollow;
1314
import static com.eveningoutpost.dexdrip.utils.DexCollectionType.SHFollow;
@@ -38,10 +39,12 @@
3839
import android.view.ViewGroup;
3940
import android.view.WindowManager;
4041
import android.widget.BaseAdapter;
42+
import android.widget.Button;
4143
import android.widget.LinearLayout;
4244
import android.widget.ListView;
4345
import android.widget.TextView;
4446

47+
import com.eveningoutpost.dexdrip.cgm.glupro.GluProService;
4548
import com.eveningoutpost.dexdrip.models.DesertSync;
4649
import com.eveningoutpost.dexdrip.models.JoH;
4750
import com.eveningoutpost.dexdrip.models.RollCall;
@@ -134,10 +137,13 @@ private void addAsection(String section, String title) {
134137
private static final String SHARE_FOLLOW = "Dex Share Follow";
135138
private static final String WEB_FOLLOW = "Web Follower";
136139
private static final String CARELINK_FOLLOW = "CareLink Follow";
140+
public static final String GLU_PRO = "Smart Guide";
137141
private static final String XDRIP_LIBRE2 = "Libre2";
138142

143+
139144
static {
140145
sectionAlwaysOn.add(G5_STATUS);
146+
sectionAlwaysOn.add(GLU_PRO);
141147
}
142148

143149
public static PendingIntent getStatusPendingIntent(String section_name) {
@@ -173,6 +179,9 @@ private void populateSectionList() {
173179
} else if (dexCollectionType.equals(Medtrum)) {
174180
addAsection(MEDTRUM_STATUS, "Medtrum A6 Status");
175181
}
182+
if (dexCollectionType.equals(GluPro)) {
183+
addAsection(GLU_PRO, getString(R.string.glupro_status));
184+
}
176185
if (BlueJayEntry.isEnabled()) {
177186
addAsection(BLUEJAY_STATUS, "BlueJay Watch Status");
178187
}
@@ -279,6 +288,9 @@ private static void populate(MegaStatusListAdapter la, String section) {
279288
case CARELINK_FOLLOW:
280289
la.addRows(CareLinkFollowService.megaStatus());
281290
break;
291+
case GLU_PRO:
292+
la.addRows(GluProService.megaStatus());
293+
break;
282294
case XDRIP_LIBRE2:
283295
la.addRows(LibreReceiver.megaStatus());
284296
break;
@@ -621,6 +633,7 @@ static class ViewHolder {
621633
TextView name;
622634
TextView value;
623635
TextView spacer;
636+
Button button;
624637
LinearLayout layout;
625638
}
626639

@@ -680,6 +693,7 @@ public View getView(int i, View view, ViewGroup viewGroup) {
680693
viewHolder = new ViewHolder();
681694
view = mInflator.inflate(R.layout.listitem_megastatus, null);
682695
viewHolder.value = (TextView) view.findViewById(R.id.value);
696+
viewHolder.button = (Button) view.findViewById(R.id.button);
683697
viewHolder.name = (TextView) view.findViewById(R.id.name);
684698
viewHolder.spacer = (TextView) view.findViewById(R.id.spacer);
685699
viewHolder.layout = (LinearLayout) view.findViewById(R.id.device_list_id);
@@ -699,6 +713,7 @@ public View getView(int i, View view, ViewGroup viewGroup) {
699713
viewHolder.spacer.setVisibility(View.VISIBLE);
700714
viewHolder.name.setVisibility(View.VISIBLE);
701715
viewHolder.value.setVisibility(View.VISIBLE);
716+
viewHolder.button.setVisibility(View.GONE);
702717
viewHolder.name.setTextColor(color_store1);
703718
viewHolder.layout.setPadding(padding_store_left_1, padding_store_top_1, padding_store_right_1, padding_store_bottom_1);
704719
viewHolder.name.setGravity(gravity_store_1);
@@ -746,17 +761,38 @@ public boolean onLongClick(View v) {
746761
return true;
747762
}
748763
});*/
749-
view.setOnClickListener(new View.OnClickListener() {
750-
@Override
751-
public void onClick(View v) {
764+
view.setOnClickListener(v -> {
765+
try {
766+
runOnUiThread(row.runnable);
767+
} catch (Exception e) {
768+
//
769+
}
770+
771+
});
772+
773+
} else if ((row.runnable != null) && (row.button_name != null) && (row.button_name.equals("button-press"))) {
774+
runnableView = view; // last one
775+
viewHolder.button.setText(row.value);
776+
viewHolder.value.setVisibility(View.GONE);
777+
viewHolder.button.setVisibility(View.VISIBLE);
778+
viewHolder.button.setOnClickListener(v -> {
752779
try {
753780
runOnUiThread(row.runnable);
754781
} catch (Exception e) {
755782
//
756783
}
784+
});
785+
786+
view.setOnClickListener(v -> {
787+
try {
788+
runOnUiThread(row.runnable);
789+
} catch (Exception e) {
790+
//
791+
}
792+
793+
});
794+
757795

758-
}
759-
});
760796
} else {
761797
view.setLongClickable(false);
762798
}

app/src/main/java/com/eveningoutpost/dexdrip/NavDrawerBuilder.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public NavDrawerBuilder(final Context context) {
6565
this.nav_drawer_intents.add(new Intent(context, CalibrationDataTable.class));
6666
}
6767

68-
if ((prefs.getString("dex_collection_method", "").equals("Follower"))) {
68+
if (DexCollectionType.isAlwaysNativeCal()) {
6969
this.nav_drawer_options.add(context.getString(R.string.add_calibration));
7070
this.nav_drawer_intents.add(new Intent(context, AddCalibration.class));
7171
} else if (!collector.canNotStartStopOrCal()) {
@@ -113,7 +113,7 @@ public NavDrawerBuilder(final Context context) {
113113
}
114114
}
115115

116-
if (DexCollectionType.hasBluetooth() && (DexCollectionType.getDexCollectionType() != DexCollectionType.DexcomG5)) {
116+
if (DexCollectionType.usesBluetoothScan()) {
117117
this.nav_drawer_options.add(context.getString(R.string.bluetooth_scan));
118118
this.nav_drawer_intents.add(new Intent(context, BluetoothScan.class));
119119
}

app/src/main/java/com/eveningoutpost/dexdrip/SystemStatusFragment.java

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -372,18 +372,25 @@ public void setConnectionStatus(String msg) {
372372

373373
private void setConnectionStatus() {
374374
boolean connected = false;
375-
if (mBluetoothManager != null && activeBluetoothDevice != null && (Build.VERSION.SDK_INT >= 18)) {
376-
for (BluetoothDevice bluetoothDevice : mBluetoothManager.getConnectedDevices(BluetoothProfile.GATT)) {
377-
if (bluetoothDevice.getAddress().compareTo(activeBluetoothDevice.address) == 0) {
378-
connected = true;
375+
try {
376+
if (mBluetoothManager != null && activeBluetoothDevice != null && (Build.VERSION.SDK_INT >= 18)) {
377+
for (BluetoothDevice bluetoothDevice : mBluetoothManager.getConnectedDevices(BluetoothProfile.GATT)) {
378+
if (bluetoothDevice.getAddress().compareTo(activeBluetoothDevice.address) == 0) {
379+
connected = true;
380+
}
379381
}
380382
}
383+
384+
if (connected) {
385+
connection_status.setText(safeGetContext().getString(R.string.connected));
386+
} else {
387+
connection_status.setText(safeGetContext().getString(R.string.not_connected));
388+
}
389+
} catch (SecurityException e) {
390+
Log.e(TAG, "Got SecurityException in setConnectionStatus ", e);
391+
connection_status.setText(R.string.need_bluetooth_permission);
381392
}
382-
if (connected) {
383-
connection_status.setText(safeGetContext().getString(R.string.connected));
384-
} else {
385-
connection_status.setText(safeGetContext().getString(R.string.not_connected));
386-
}
393+
387394

388395
String collection_method = prefs.getString("dex_collection_method", "BluetoothWixel");
389396
if (collection_method.compareTo("DexcomG5") == 0) {

app/src/main/java/com/eveningoutpost/dexdrip/calibrations/NativeCalibrationPipe.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.eveningoutpost.dexdrip.calibrations;
22

3+
import com.eveningoutpost.dexdrip.cgm.glupro.GluPro;
34
import com.eveningoutpost.dexdrip.g5model.Ob1G5StateMachine;
45
import com.eveningoutpost.dexdrip.models.JoH;
56
import com.eveningoutpost.dexdrip.models.UserError;
@@ -50,6 +51,7 @@ public static void addCalibration(final int glucose, final long timestamp) {
5051
// Send to potential listeners
5152
Ob1G5StateMachine.addCalibration(glucose, timestamp);
5253
Medtrum.addCalibration(glucose, timestamp);
54+
GluPro.addCalibration(glucose, timestamp);
5355

5456
PersistentStore.setLong("last-calibration-pipe-timestamp", JoH.tsl());
5557

0 commit comments

Comments
 (0)