Skip to content

Commit

Permalink
Merge feature branch
Browse files Browse the repository at this point in the history
  • Loading branch information
jamorham committed May 22, 2024
1 parent c967ee7 commit 91887d7
Show file tree
Hide file tree
Showing 32 changed files with 645 additions and 90 deletions.
6 changes: 6 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,12 @@
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/provider_paths" />
</provider>
<provider
android:name=".receiver.InfoContentProvider"
android:authorities="${applicationId}.contentprovider"
android:enabled="true"
android:exported="true">
</provider>

<activity
android:name=".Home"
Expand Down
10 changes: 7 additions & 3 deletions app/src/main/java/com/eveningoutpost/dexdrip/GcmActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import com.eveningoutpost.dexdrip.utils.CipherUtils;
import com.eveningoutpost.dexdrip.utils.DisplayQRCode;
import com.eveningoutpost.dexdrip.utils.SdcardImportExport;
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;
Expand Down Expand Up @@ -864,9 +865,11 @@ public void onReceive(Context context, Intent intent) {
xdrip.getAppContext().startService(intent);
} else {
cease_all_activity = true;
final String msg = "ERROR: Connecting to Google Services - check google login or reboot?";
JoH.static_toast_long(msg);
Home.toaststaticnext(msg);
if (!BlueJayEntry.isNative()) {
final String msg = "ERROR: Connecting to Google Services - check google login or reboot?";
JoH.static_toast_long(msg);
Home.toaststaticnext(msg);
}
}
}

Expand Down Expand Up @@ -998,6 +1001,7 @@ static Boolean checkPlayServices(Context context, Activity activity) {
if (resultCode != ConnectionResult.SUCCESS) {
try {
if (apiAvailability.isUserResolvableError(resultCode)) {
if (resultCode == 3 && BlueJayEntry.isNative()) return false;
if (activity != null) {
apiAvailability.getErrorDialog(activity, resultCode, PLAY_SERVICES_RESOLUTION_REQUEST)
.show();
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/com/eveningoutpost/dexdrip/Home.java
Original file line number Diff line number Diff line change
Expand Up @@ -2252,7 +2252,7 @@ public void toggleStepsVisibility(View v) {
}

public void sourceWizardButtonClick(View v) {
SourceWizard.start(this, true);
SourceWizard.start(Home.this, true);
}

private long whichTimeLocked() {
Expand Down Expand Up @@ -2647,7 +2647,7 @@ private void updateCurrentBgInfoCommon(DexCollectionType collector, TextView not
final AlertDialog.Builder builder = new AlertDialog.Builder(this);
final Context context = this;
builder.setTitle(getString(R.string.start_sensor) + "?");
builder.setMessage(String.format(gs(R.string.start_sensor_confirmation), DexCollectionType.getDexCollectionType().toString()));
builder.setMessage(String.format(gs(R.string.start_sensor_confirmation), DexCollectionType.getBestCollectorHardwareName()));
builder.setNegativeButton(gs(R.string.change_settings), (dialog, which) -> {
dialog.dismiss();
startActivity(new Intent(context, Preferences.class).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.eveningoutpost.dexdrip.models.JoH;
import com.eveningoutpost.dexdrip.models.LibreBlock;
import com.eveningoutpost.dexdrip.models.UserError;
import com.eveningoutpost.dexdrip.receiver.InfoContentProvider;
import com.eveningoutpost.dexdrip.sharemodels.BgUploader;
import com.eveningoutpost.dexdrip.sharemodels.models.ShareUploadPayload;
import com.eveningoutpost.dexdrip.utilitymodels.Inevitable;
Expand Down Expand Up @@ -58,6 +59,7 @@ public static void newBgReading(BgReading bgReading, boolean is_follower) {
sendToBlueJay();
sendToRemoteBlueJay();
Notifications.start();
InfoContentProvider.ping("bg");
uploadToShare(bgReading, is_follower);
textToSpeech(bgReading, null);
LibreBlock.UpdateBgVal(bgReading.timestamp, bgReading.calculated_value);
Expand Down Expand Up @@ -87,6 +89,7 @@ public static void newExternalStatus(boolean receivedLocally) {
GcmActivity.push_external_status_update(JoH.tsl(), statusLine);

}
InfoContentProvider.ping("status");
}

}
Expand Down
25 changes: 15 additions & 10 deletions app/src/main/java/com/eveningoutpost/dexdrip/StartNewSensor.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,22 @@ public class StartNewSensor extends ActivityWithMenu {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (!Sensor.isActive()) {
JoH.fixActionBar(this);
setContentView(R.layout.activity_start_new_sensor);
button = (Button) findViewById(R.id.startNewSensor);
//dp = (DatePicker)findViewById(R.id.datePicker);
//tp = (TimePicker)findViewById(R.id.timePicker);
addListenerOnButton();
} else {
Intent intent = new Intent(this, StopSensor.class);
startActivity(intent);
if (DexCollectionType.getBestCollectorHardwareName().equals("G7")) {
JoH.static_toast_long(getString(R.string.g7_should_start_automatically));
finish();
} else {
if (!Sensor.isActive()) {
JoH.fixActionBar(this);
setContentView(R.layout.activity_start_new_sensor);
button = (Button) findViewById(R.id.startNewSensor);
//dp = (DatePicker)findViewById(R.id.datePicker);
//tp = (TimePicker)findViewById(R.id.timePicker);
addListenerOnButton();
} else {
Intent intent = new Intent(this, StopSensor.class);
startActivity(intent);
finish();
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import com.eveningoutpost.dexdrip.models.JoH;
import com.eveningoutpost.dexdrip.models.UserError;
import com.eveningoutpost.dexdrip.R;
import com.eveningoutpost.dexdrip.receiver.InfoContentProvider;
import com.eveningoutpost.dexdrip.utilitymodels.Inevitable;
import com.eveningoutpost.dexdrip.utilitymodels.PrefsViewImpl;
import com.eveningoutpost.dexdrip.databinding.ActivityBackupPickerBinding;
Expand Down Expand Up @@ -212,6 +213,7 @@ private synchronized void restoreNowReal() {
if (metaData.exception != null) {
status(getString(R.string.error_exclamation) + " " + metaData.exception);
}
InfoContentProvider.ping("pref");
} finally {
idle.set(true);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.eveningoutpost.dexdrip.g5model;

import com.eveningoutpost.dexdrip.models.JoH;
import com.eveningoutpost.dexdrip.services.G5CollectionService;

import lombok.NoArgsConstructor;
Expand Down Expand Up @@ -50,4 +51,9 @@ public Integer getPredictedGlucose() {
return null; // stub
}

public long getRealTimestamp() {
return JoH.tsl(); // default behavior is received now
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ public static void store(final String transmitterId, final long when) {
UserError.Log.d(TAG, "Sync time updated to: " + JoH.dateTimeText(when));
}

public static void store(final String transmitterId, final long when, final long last_conection_time, final long last_glucose_processed) {
final long latency = (last_glucose_processed - last_conection_time);
UserError.Log.d(TAG, "Update time from glucose rx glucose: " + JoH.dateTimeText(when) + " latency:" + latency + " ms");
if (latency < 8000) { // roughly half preempt
store(transmitterId, when);
} else {
UserError.Log.e(TAG, "Refusing to update stored timestamp due to excessive processing latency: " + latency + "ms");
}
}

public static void clear(final String transmitterId) {
if (PersistentStore.getLong(DEX_SYNC_STORE + transmitterId) > 0) {
UserError.Log.e(TAG, "Clearing stored timing sync information for: " + transmitterId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ public Long getRealSessionStartTime() {
return null;
}

@Override
public long getRealTimestamp() {
return JoH.tsl() - (age * Constants.SECOND_IN_MS);
}

public String getRealSessionStartTimeString() {
val t = getRealSessionStartTime();
if (t != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@
import static com.eveningoutpost.dexdrip.services.Ob1G5CollectionService.STATE.SCAN;
import static com.eveningoutpost.dexdrip.services.Ob1G5CollectionService.android_wear;
import static com.eveningoutpost.dexdrip.services.Ob1G5CollectionService.getTransmitterID;
import static com.eveningoutpost.dexdrip.services.Ob1G5CollectionService.ignoreBonding;
import static com.eveningoutpost.dexdrip.services.Ob1G5CollectionService.immediateBonding;
import static com.eveningoutpost.dexdrip.services.Ob1G5CollectionService.onlyUsingNativeMode;
import static com.eveningoutpost.dexdrip.services.Ob1G5CollectionService.resetSomeInternalState;
import static com.eveningoutpost.dexdrip.services.Ob1G5CollectionService.wear_broadcast;
Expand Down Expand Up @@ -133,13 +135,15 @@ public class Ob1G5StateMachine {
private static final int OLDEST_RAW = 300 * 24 * 60 * 60; // 300 days

public static long maxBackfillPeriod_MS = 0;

public static long maxBackfillPeriod_MS() {
maxBackfillPeriod_MS = MAX_BACKFILL_PERIOD_MS;
if (shortTxId()) { // If using G7
maxBackfillPeriod_MS = MAX_BACKFILL_PERIOD_MS2;
}
return maxBackfillPeriod_MS;
}

public static int backfillCheckLarge() {
return (int) (maxBackfillPeriod_MS() / DEXCOM_PERIOD);
}
Expand Down Expand Up @@ -272,7 +276,7 @@ public static boolean doCheckAuth2(final Ob1G5CollectionService parent, final Rx
connection.setupNotification(ExtraData)
.timeout(15, TimeUnit.SECONDS) // WARN
.doOnNext(notificationObservable -> {
UserError.Log.d(TAG,"Extra data notifications enabled");
UserError.Log.d(TAG, "Extra data notifications enabled");
connection.setupIndication(Authentication)
.timeout(15, TimeUnit.SECONDS) // WARN
.doOnNext(notificationObservable2 -> doNext(parent, connection))
Expand All @@ -289,14 +293,14 @@ public static boolean doCheckAuth2(final Ob1G5CollectionService parent, final Rx
doNext(parent, connection);
}
} catch (Exception e) {
UserError.Log.e(TAG,"Got exception in plugin: " + e);
UserError.Log.e(TAG, "Got exception in plugin: " + e);
parent.lastSensorStatus = e.getMessage();
if (e instanceof InvalidParameterException) {
parent.resetSomeInternalState();
} else if (e instanceof SecurityException) {
parent.logFailure();
parent.clearPersistStore();
parent.changeState(SCAN);
parent.logFailure();
parent.clearPersistStore();
parent.changeState(SCAN);
} else {
e.printStackTrace();
}
Expand All @@ -323,7 +327,7 @@ public static boolean doCheckAuth2(final Ob1G5CollectionService parent, final Rx
private static void handleAuthenticationWrite(final Ob1G5CollectionService parent, final RxBleConnection connection) {
final int specifiedSlot = Pref.getBooleanDefaultFalse("engineering_mode") ? Pref.getStringToInt("dex_specified_slot", -1) : -1;
final AuthRequestTxMessage authRequest = (specifiedSlot == -1) ? new AuthRequestTxMessage(getTokenSize(), usingAlt())
: new AuthRequestTxMessage(getTokenSize(), specifiedSlot);
: new AuthRequestTxMessage(getTokenSize(), specifiedSlot);
lastAuthPacket = authRequest;
UserError.Log.i(TAG, "AuthRequestTX: " + bytesToHex(authRequest.byteSequence));

Expand Down Expand Up @@ -882,7 +886,7 @@ public static boolean doGetData(Ob1G5CollectionService parent, RxBleConnection c
} else {
parent.msg("Invalid Glucose");
}
break;
break;


case CalibrateRxMessage:
Expand Down Expand Up @@ -1108,15 +1112,15 @@ private static void backFillIfNeeded(Ob1G5CollectionService parent, RxBleConnect

UserError.Log.d(TAG, "Requesting backfill between: " + JoH.dateTimeText(startTime) + " " + JoH.dateTimeText(endTime));

if (!shortTxId()) {
enqueueUniqueCommand(
BackFillTxMessage.get(getTransmitterID(), startTime, endTime),
"Get backfill since: " + JoH.hourMinuteString(startTime));
} else {
enqueueUniqueCommand(
BackFillTxMessage2.get(getTransmitterID(), startTime, endTime),
"Get backfill2 since: " + JoH.hourMinuteString(startTime));
}
if (!shortTxId()) {
enqueueUniqueCommand(
BackFillTxMessage.get(getTransmitterID(), startTime, endTime),
"Get backfill since: " + JoH.hourMinuteString(startTime));
} else {
enqueueUniqueCommand(
BackFillTxMessage2.get(getTransmitterID(), startTime, endTime),
"Get backfill2 since: " + JoH.hourMinuteString(startTime));
}
} else {
nextBackFillCheckSize = BACKFILL_CHECK_SMALL;
}
Expand Down Expand Up @@ -1563,8 +1567,9 @@ private static void processGlucoseRxMessage(Ob1G5CollectionService parent, final
DexTimeKeeper.updateAge(getTransmitterID(), glucose.timestamp);
if (glucose.usable() || (glucose.insufficient() && Pref.getBoolean("ob1_g5_use_insufficiently_calibrated", true))) {
UserError.Log.d(TAG, "Got usable glucose data from transmitter!!");
final long rxtimestamp = tsl();
final long rxtimestamp = glucose.getRealTimestamp();
checkAndActivateSensor();
DexSyncKeeper.store(getTransmitterID(), rxtimestamp, parent.static_last_connected, lastGlucosePacket);
final BgReading bgReading = BgReading.bgReadingInsertFromG5(glucose.glucose, rxtimestamp);
if (bgReading != null) {
try {
Expand All @@ -1590,7 +1595,7 @@ private static void processGlucoseRxMessage(Ob1G5CollectionService parent, final
if (glucose.getPredictedGlucose() != null) {
// not really supported on wear yet
if (!android_wear) {
Prediction.create(tsl(), glucose.getPredictedGlucose(), "EGlucoseRx").save();
Prediction.create(rxtimestamp, glucose.getPredictedGlucose(), "EGlucoseRx").save();
}
}

Expand Down Expand Up @@ -1981,7 +1986,8 @@ private static synchronized byte[] calculateChallengeHash(final byte[] challenge
@SuppressLint("GetInstance") final Cipher aesCipher = Cipher.getInstance("AES/ECB/PKCS7Padding");
aesCipher.init(Cipher.ENCRYPT_MODE, secretKeySpec);
return Arrays.copyOfRange(aesCipher.doFinal(plainText, 0, plainText.length), 0, 8);
} catch (NoSuchAlgorithmException | NoSuchPaddingException | IllegalBlockSizeException | BadPaddingException | InvalidKeyException e) {
} catch (NoSuchAlgorithmException | NoSuchPaddingException | IllegalBlockSizeException |
BadPaddingException | InvalidKeyException e) {
UserError.Log.wtf(TAG, "System Encryption problem: " + e);
return null;
}
Expand Down Expand Up @@ -2106,7 +2112,7 @@ private static boolean getEGlucose(final Ob1G5CollectionService parent) {

public static boolean usingAlt() {
return (android_wear && !Pref.getBooleanDefaultFalse("only_ever_use_wear_collector"))
|| WholeHouse.isLive();
|| (immediateBonding() && !ignoreBonding()) || WholeHouse.isLive();
}

private static class OperationSuccess extends RuntimeException {
Expand Down
11 changes: 11 additions & 0 deletions app/src/main/java/com/eveningoutpost/dexdrip/models/JoH.java
Original file line number Diff line number Diff line change
Expand Up @@ -1881,6 +1881,17 @@ public static byte[] splitBytes(final byte[] source, final int start, final int
return newBytes;
}

public static byte[] joinBytes(final byte[] first, final byte[] second) {
if (first == null || second == null) {
throw new IllegalArgumentException("Input arrays cannot be null");
}
final int totalLength = first.length + second.length;
final byte[] result = new byte[totalLength];
System.arraycopy(first, 0, result, 0, first.length);
System.arraycopy(second, 0, result, first.length, second.length);
return result;
}


public static long checksum(byte[] bytes) {
if (bytes == null) return 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.activeandroid.annotation.Table;
import com.activeandroid.query.Delete;
import com.activeandroid.query.Select;
import com.eveningoutpost.dexdrip.receiver.InfoContentProvider;
import com.eveningoutpost.dexdrip.utilitymodels.Constants;
import com.eveningoutpost.dexdrip.utilitymodels.Pref;
import com.google.gson.annotations.Expose;
Expand All @@ -17,7 +18,6 @@
import java.util.Hashtable;
import java.util.List;

//import com.bugfender.sdk.Bugfender;

/**
* Created by Emma Black on 8/3/15.
Expand Down Expand Up @@ -236,6 +236,15 @@ public static List<UserError> bySeverityOlderThanID(long id, Integer[] levels, i
}


public static UserError newestBySeverity(int level) {
return new Select()
.from(UserError.class)
.where("severity == "+level)
.orderBy("timestamp desc")
.limit(1)
.executeSingle();
}

public static UserError getForTimestamp(UserError error) {
try {
return new Select()
Expand Down Expand Up @@ -331,6 +340,7 @@ public static void uel(String tag, String b) {
public static void ueh(String tag, String b) {
android.util.Log.i(tag, b);
UserError.UserEventHigh(tag, b);
InfoContentProvider.ping("info");
}

public static void d(String tag, String b) {
Expand Down
Loading

0 comments on commit 91887d7

Please sign in to comment.