Skip to content

Commit

Permalink
Merge branch 'master' into bugfix/Xiaomi_MissedReadings
Browse files Browse the repository at this point in the history
# Conflicts (solved):
#	app/src/main/java/com/eveningoutpost/dexdrip/services/Ob1G5CollectionService.java
#	app/src/main/res/values/strings.xml
  • Loading branch information
NiK27711 committed Dec 31, 2024
2 parents 472ad96 + 8ed51e7 commit ac9a8a9
Show file tree
Hide file tree
Showing 101 changed files with 4,014 additions and 1,001 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -285,9 +285,9 @@ dependencies {
// implementation 'com.google.android.gms:play-services-maps:15.0.0'
implementation 'com.google.android.gms:play-services-wearable:15.0.0'
implementation 'com.google.android.gms:play-services-location:15.0.0'
implementation "com.google.android.gms:play-services-gcm:15.0.0"
implementation "androidx.work:work-runtime:2.9.1"
implementation "com.google.android.gms:play-services-oss-licenses:15.0.0"

implementation "com.google.protobuf:protobuf-java:4.27.2"
implementation 'com.squareup.wire:wire-runtime:2.2.0'
implementation 'com.squareup.okhttp:okhttp:2.7.5'
implementation 'com.squareup.okhttp3:okhttp:3.12.13'
Expand Down
Binary file added app/libs/xdrip-cloud-1.0-SNAPSHOT.jar
Binary file not shown.
4 changes: 3 additions & 1 deletion app/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -147,4 +147,6 @@

-keep class com.newrelic.** { *; }
-dontwarn com.newrelic.**
-keepattributes Exceptions, Signature, InnerClasses, LineNumberTable
-keepattributes Exceptions, Signature, InnerClasses, LineNumberTable

-keep class com.eveningoutpost.dexdrip.cgm.carelinkfollow.message.*
17 changes: 9 additions & 8 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@
android:theme="@style/AppTheme"
tools:replace="android:appComponentFactory"
android:appComponentFactory="android.support.v4.app.CoreComponentFactory"
android:requestLegacyExternalStorage="true"
android:usesCleartextTraffic="true">
<activity
android:name=".HealthPrivacy"
Expand Down Expand Up @@ -637,14 +638,6 @@
android:enabled="true"
android:exported="true"></receiver>

<service
android:name=".TaskService"
android:exported="true"
android:permission="com.google.android.gms.permission.BIND_NETWORK_TASK_SERVICE">
<intent-filter>
<action android:name="com.google.android.gms.gcm.ACTION_TASK_READY" />
</intent-filter>
</service>
<service
android:name=".services.AlwaysOnDisplayService"
android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE">
Expand Down Expand Up @@ -704,6 +697,12 @@
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".utilitymodels.SaveLogs"
android:configChanges="orientation|screenSize"
android:label="@string/title_activity_save_logs"
android:noHistory="true">
</activity>
<activity android:name=".deposit.DepositActivity" />
<activity android:name=".utils.AndroidBarcode" />
<activity
Expand Down Expand Up @@ -821,6 +820,8 @@
<meta-data
android:name="com.sec.android.multiwindow.MINIMUM_SIZE_H"
android:value="598.0dip" />
<meta-data android:name="delivery_metrics_exported_to_big_query_enabled"
android:value="false"/>

<activity android:name=".utilitymodels.XDripDreamSettingsActivity" />

Expand Down
27 changes: 20 additions & 7 deletions app/src/main/java/com/eveningoutpost/dexdrip/EventLogActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import com.eveningoutpost.dexdrip.utilitymodels.Inevitable;
import com.eveningoutpost.dexdrip.utilitymodels.PersistentStore;
import com.eveningoutpost.dexdrip.utilitymodels.Pref;
import com.eveningoutpost.dexdrip.utilitymodels.SaveLogs;
import com.eveningoutpost.dexdrip.utilitymodels.SendFeedBack;
import com.eveningoutpost.dexdrip.databinding.ActivityEventLogBinding;
import com.eveningoutpost.dexdrip.ui.helpers.BitmapUtil;
Expand All @@ -50,6 +51,7 @@
import me.tatarka.bindingcollectionadapter2.collections.MergeObservableList;

import static com.eveningoutpost.dexdrip.Home.startWatchUpdaterService;
import static com.eveningoutpost.dexdrip.utils.DexCollectionType.getBestCollectorHardwareName;

/*
* New style event log viewer
Expand All @@ -65,6 +67,7 @@ public class EventLogActivity extends BaseAppCompatActivity {
private static final String TAG = EventLogActivity.class.getSimpleName();
private static final String PREF_SEVERITY_SELECTION = "event-log-severity-enabled-";
private static final String PREF_LAST_SEARCH = "event-log-last-search-";
private static int MAX_LOG_PACKAGE_SIZE = 200000;

static {
severitiesList.add(1);
Expand Down Expand Up @@ -291,20 +294,32 @@ private void updateToTopButtonVisibility(boolean force) {
}
}

// prepare current visible logs for upload
public synchronized void uploadEventLogs(View v) {
public synchronized void uploadEventLogs(View v) { // Send events log to JamOrHam
startActivity(new Intent(getApplicationContext(), SendFeedBack.class).putExtra("generic_text", packLogs()));
}

public synchronized void saveEventLog(View v) { // Save events log in mobile storage
startActivity(new Intent(getApplicationContext(), SaveLogs.class).putExtra("generic_text", packLogs()));
}

private String packLogs() { // Prepare current visible logs for upload or local save
final StringBuilder builder = new StringBuilder(50000);
builder.append("The following logs will be sent to the developers: \n\nPlease also include your email address or we will not know who they are from!\n\nFilter: "
builder.append("\n"
+ (model.allSeveritiesEnabled() ? "ALL" : model.whichSeveritiesEnabled()) + (model.getCurrentFilter() != "" ? " Search: " + model.getCurrentFilter() : "") + "\n\n");
for (UserError item : model.visible) {
builder.append(item.toString());
builder.append("\n");
if (builder.length() > 200000) {
if (builder.length() > MAX_LOG_PACKAGE_SIZE) {
JoH.static_toast_long(this, "Could not package up all logs, using most recent");
builder.append("\n\nOnly the most recent logs have been included to limit the file size.\n");
break;
}
}
startActivity(new Intent(getApplicationContext(), SendFeedBack.class).putExtra("generic_text", builder.toString()));

builder.insert(0, JoH.getDeviceDetails() + "\n" + JoH.getVersionDetails() + "\n" + getBestCollectorHardwareName() + "\n===\n" + "\nLog data:\n"); // Adds device, version and collector details before the log.
builder.append("\n\nCaptured: " + JoH.dateTimeText(JoH.tsl())); // Adds date and time of capture after the log.

return builder.toString();
}

// View model container - accessible binding methods must be declared public
Expand Down Expand Up @@ -636,5 +651,3 @@ public void onBindBinding(ViewDataBinding binding, int bindingVariable, @LayoutR
}
}



32 changes: 21 additions & 11 deletions app/src/main/java/com/eveningoutpost/dexdrip/GcmActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import android.widget.Toast;

import com.eveningoutpost.dexdrip.cloud.jamcm.JamCm;
import com.eveningoutpost.dexdrip.models.BgReading;
import com.eveningoutpost.dexdrip.models.BloodTest;
import com.eveningoutpost.dexdrip.models.Calibration;
Expand All @@ -37,7 +38,6 @@
import com.eveningoutpost.dexdrip.watch.thinjam.BlueJayEntry;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GoogleApiAvailability;
import com.google.android.gms.gcm.GoogleCloudMessaging;
import com.google.common.primitives.Bytes;
import com.google.firebase.messaging.FirebaseMessaging;
import com.google.firebase.messaging.RemoteMessage;
Expand Down Expand Up @@ -76,7 +76,7 @@ public class GcmActivity extends FauxActivity {
private static long last_rlcl_request = 0;
private static long cool_down_till = 0;
public static AtomicInteger msgId = new AtomicInteger(1);
public static String token = null;
public static volatile String token = null;
public static String senderid = null;
public static final List<GCM_data> gcm_queue = new ArrayList<>();
private static final Object queue_lock = new Object();
Expand Down Expand Up @@ -216,7 +216,9 @@ private static void queueCheckOld(Context context, boolean recursive) {
try {
Log.i(TAG, "Resending unacknowledged queue item: " + datum.bundle.getString("action") + datum.bundle.getString("payload"));
datum.resent++;
GoogleCloudMessaging.getInstance(context).send(senderid + "@gcm.googleapis.com", Integer.toString(msgId.incrementAndGet()), datum.bundle);
// GoogleCloudMessaging.getInstance(context).send(senderid + "@gcm.googleapis.com", Integer.toString(msgId.incrementAndGet()), datum.bundle);
datum.bundle.putBoolean("resend-from-queue", true);
JamCm.sendMessageBackground(datum.bundle);
} catch (Exception e) {
Log.e(TAG, "Got exception during resend: " + e.toString());
}
Expand Down Expand Up @@ -609,9 +611,9 @@ static void requestSensorBatteryUpdate() {
}

public static void requestSensorCalibrationsUpdate() {
if (Home.get_follower() && JoH.pratelimit("SensorCalibrationsUpdateRequest", 300)) {
if (Home.get_follower() && JoH.pratelimit("SensorCalibrationsUpdateRequest", 1200)) {
Log.d(TAG, "Requesting Sensor and calibrations Update");
GcmActivity.sendMessage("sensor_calibrations_update", "");
GcmActivity.sendMessage("sencalup", "");
}
}

Expand Down Expand Up @@ -650,7 +652,7 @@ public static void push_external_status_update(long timestamp, String statusLine
}
}

static String myIdentity() {
public static String myIdentity() {
// TODO prefs override possible
return GoogleDriveInterface.getDriveIdentityString();
}
Expand Down Expand Up @@ -735,6 +737,11 @@ private static synchronized String sendMessageNow(String identity, String action
return "";
}

if (action.length() > 15) {
UserError.Log.e(TAG, "Cannot send invalid action: " + action);
return "";
}

final Bundle data = new Bundle();
data.putString("action", action);
data.putString("identity", identity);
Expand Down Expand Up @@ -762,19 +769,20 @@ private static synchronized String sendMessageNow(String identity, String action
Log.e(TAG, "Queue size exceeded");
Home.toaststaticnext("Maximum Sync Queue size Exceeded!");
}
final GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(xdrip.getAppContext());
// final GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(xdrip.getAppContext());
if (token == null) {
Log.e(TAG, "GCM token is null - cannot sendMessage");
return "";
}
String messageid = Integer.toString(msgId.incrementAndGet());
gcm.send(senderid + "@gcm.googleapis.com", messageid, data);
// gcm.send(senderid + "@gcm.googleapis.com", messageid, data);
if (last_ack == -1) last_ack = JoH.tsl();
last_send_previous = last_send;
last_send = JoH.tsl();
JamCm.sendMessageBackground(data);
msg = "Sent message OK " + messageid;
DesertSync.fromGCM(data);
} catch (IOException ex) {
} catch (Exception ex) {
msg = "Error :" + ex.getMessage();
}
Log.d(TAG, "Return msg in SendMessage: " + msg);
Expand All @@ -793,7 +801,9 @@ private static boolean shouldAddQueue(final Bundle data) {
case "bfr":
case "nscu":
case "nscusensor-expiry":
case "nscus-expiry":
case "esup":
case "sencalup":
synchronized (queue_lock) {
for (GCM_data qdata : gcm_queue) {
try {
Expand All @@ -813,7 +823,7 @@ private static boolean shouldAddQueue(final Bundle data) {
}
}

private static void fmSend(Bundle data) {
/* private static void fmSend(Bundle data) {
final FirebaseMessaging fm = FirebaseMessaging.getInstance();
if (senderid != null) {
fm.send(new RemoteMessage.Builder(senderid + "@gcm.googleapis.com")
Expand All @@ -823,7 +833,7 @@ private static void fmSend(Bundle data) {
} else {
Log.wtf(TAG, "senderid is null");
}
}
}*/

private void tryGCMcreate() {
Log.d(TAG, "try GCMcreate");
Expand Down
39 changes: 29 additions & 10 deletions app/src/main/java/com/eveningoutpost/dexdrip/GcmListenerSvc.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import android.os.PowerManager;
import android.util.Base64;

import com.eveningoutpost.dexdrip.cloud.jamcm.JamCm;
import com.eveningoutpost.dexdrip.models.BgReading;
import com.eveningoutpost.dexdrip.models.BloodTest;
import com.eveningoutpost.dexdrip.models.Calibration;
Expand Down Expand Up @@ -54,8 +55,10 @@
import java.util.List;
import java.util.Map;

import static com.eveningoutpost.dexdrip.GcmActivity.cease_all_activity;
import static com.eveningoutpost.dexdrip.models.JoH.isAnyNetworkConnected;
import static com.eveningoutpost.dexdrip.models.JoH.showNotification;
import static com.eveningoutpost.dexdrip.models.JoH.tsl;

public class GcmListenerSvc extends JamListenerSvc {

Expand All @@ -65,7 +68,7 @@ public class GcmListenerSvc extends JamListenerSvc {
private static byte[] staticKey;

public static int lastMessageMinutesAgo() {
return (int) ((JoH.tsl() - GcmListenerSvc.lastMessageReceived) / 60000);
return (int) ((tsl() - GcmListenerSvc.lastMessageReceived) / 60000);
}

// data for MegaStatus
Expand Down Expand Up @@ -127,7 +130,7 @@ public void onMessageReceived(RemoteMessage rmessage) {
final PowerManager.WakeLock wl = JoH.getWakeLock("xdrip-onMsgRec", 120000);
try {
if (rmessage == null) return;
if (GcmActivity.cease_all_activity) return;
if (cease_all_activity) return;
String from = rmessage.getFrom();

final Bundle data = new Bundle();
Expand Down Expand Up @@ -167,8 +170,7 @@ public void onMessageReceived(RemoteMessage rmessage) {
String xfrom = data.getString("xfrom");
String payload = data.getString("datum", data.getString("payload"));
String action = data.getString("action");

if ((xfrom != null) && (xfrom.equals(GcmActivity.token))) {
if ((xfrom != null) && (xfrom.equals(GcmActivity.token) || xfrom.equals(JamCm.getId()))) {
GcmActivity.queueAction(action + payload);
return;
}
Expand Down Expand Up @@ -250,7 +252,7 @@ public void onMessageReceived(RemoteMessage rmessage) {
}

Log.i(TAG, "Got action: " + action + " with payload: " + payload);
lastMessageReceived = JoH.tsl();
lastMessageReceived = tsl();


// new treatment
Expand Down Expand Up @@ -291,7 +293,7 @@ public void onMessageReceived(RemoteMessage rmessage) {
message_array[2] = Long.toString(Long.parseLong(message_array[2]) + timediff);
}
Log.i(TAG, "Processing remote CAL " + message_array[1] + " age: " + message_array[2]);
calintent.putExtra("timestamp", JoH.tsl());
calintent.putExtra("timestamp", tsl());
calintent.putExtra("bg_string", message_array[1]);
calintent.putExtra("bg_age", message_array[2]);
calintent.putExtra("cal_source", "gcm cal packet");
Expand All @@ -318,7 +320,7 @@ public void onMessageReceived(RemoteMessage rmessage) {
bg_age += timediff;
}
Log.i(TAG, "Processing remote CAL " + newCalibration.bgValue + " age: " + bg_age);
calintent.putExtra("timestamp", JoH.tsl());
calintent.putExtra("timestamp", tsl());
calintent.putExtra("bg_string", "" + (Pref.getString("units", "mgdl").equals("mgdl") ? newCalibration.bgValue : newCalibration.bgValue * Constants.MGDL_TO_MMOLL));
calintent.putExtra("bg_age", "" + bg_age);
calintent.putExtra("cal_source", "gcm cal2 packet");
Expand Down Expand Up @@ -434,7 +436,7 @@ public void onMessageReceived(RemoteMessage rmessage) {
if (ii.length > 1) sender_ssid = JoH.base64decode(ii[1]);
}
if (!Pref.getBooleanDefaultFalse("remote_snoozes_wifi_match") || JoH.getWifiFuzzyMatch(sender_ssid, JoH.getWifiSSID())) {
if (Math.abs(JoH.tsl() - snoozed_time) < 300000) {
if (Math.abs(tsl() - snoozed_time) < 300000) {
if (JoH.pratelimit("received-remote-snooze", 30)) {
AlertPlayer.getPlayer().Snooze(xdrip.getAppContext(), -1, false);
UserError.Log.ueh(TAG, "Accepted remote snooze");
Expand Down Expand Up @@ -508,7 +510,7 @@ public void run() {
} else {
Log.e(TAG, "Received sensorupdate packets but we are not set as a follower");
}
} else if (action.equals("sensor_calibrations_update")) {
} else if (action.equals("sencalup")) {
if (Home.get_master()) {
Log.i(TAG, "Received request for sensor calibration update");
GcmActivity.syncSensor(Sensor.currentSensor(), false);
Expand Down Expand Up @@ -563,7 +565,24 @@ public void run() {
} else if (action.equals("libreBlock") || action.equals("libreBlck")) {
HandleLibreBlock(payload);
} else {
Log.e(TAG, "Received message action we don't know about: " + action);
switch (action) {
case "cease0":
case "cease1":
case "cease2":
case "cease3":
case "cease4":
case "cease5":
case "cease6":
case "cease7":
case "cease8":
case "cease9":
cease_all_activity = true;
Log.wtf(TAG, "Server requested to cease all activity for reason: " + action);
break;
default:
Log.e(TAG, "Received message action we don't know about: " + action);
break;
}
}
} else {
// direct downstream message.
Expand Down
Loading

0 comments on commit ac9a8a9

Please sign in to comment.