Java Code Examples for com.eveningoutpost.dexdrip.Models.UserError

The following examples show how to use com.eveningoutpost.dexdrip.Models.UserError. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
public synchronized void changeState(final String new_state) {
    final String state = I.state;
    if (state == null) return;
    if ((state.equals(new_state)) && !state.equals(INIT) && !state.equals(SLEEP)) {
        if (!state.equals(CLOSE)) {
            UserError.Log.d(TAG, "Already in state: " + new_state.toUpperCase() + " changing to CLOSE");
            UserError.Log.d(TAG, JoH.backTrace());
            changeState(CLOSE);
        }
    } else {
        if ((state.equals(CLOSED) || state.equals(CLOSE)) && new_state.equals(CLOSE)) {
            UserError.Log.d(TAG, "Not closing as already closed");
        } else {
            UserError.Log.d(TAG, "Changing state from: " + state.toUpperCase() + " to " + new_state.toUpperCase());
            I.state = new_state;
            background_automata(I.backgroundStepDelay);
        }
    }
}
 
Example 2
Source Project: xDrip   Source File: TidepoolCallback.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onResponse(Call<T> call, Response<T> response) {
    if (response.isSuccessful() && response.body() != null) {
        UserError.Log.d(TidepoolUploader.TAG, name + " success");
        session.populateBody(response.body());
        session.populateHeaders(response.headers());
        if (onSuccess != null) {
            onSuccess.run();
        }
    } else {
        final String msg = name + " was not successful: " + response.code() + " " + response.message();
        UserError.Log.e(TidepoolUploader.TAG, msg);
        status(msg);
        if (onFailure != null) {
            onFailure.run();
        }
    }
}
 
Example 3
Source Project: xDrip   Source File: PebbleWatchSync.java    License: GNU General Public License v3.0 6 votes vote down vote up
private void check_and_enable_bluetooth() {
    if (Build.VERSION.SDK_INT > 17) {
        try {
            final BluetoothManager bluetooth_manager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE);
            if (!bluetooth_manager.getAdapter().isEnabled()) {
                if (Pref.getBoolean("automatically_turn_bluetooth_on", true)) {
                    JoH.setBluetoothEnabled(getApplicationContext(), true);
                    //Toast.makeText(this, "Trying to turn Bluetooth on", Toast.LENGTH_LONG).show();
                    //} else {
                    //Toast.makeText(this, "Please turn Bluetooth on!", Toast.LENGTH_LONG).show();
                }
            }
        } catch (Exception e) {
            UserError.Log.e(TAG, "Error checking/enabling bluetooth: " + e);
        }
    }
}
 
Example 4
Source Project: xDrip   Source File: XbridgePlus.java    License: GNU General Public License v3.0 6 votes vote down vote up
private static void process15minData(byte[] buffer, int src_offset, int min_offset, int count) {
    long timestamp = JoH.tsl();
    for (int i = src_offset; i < (src_offset + (count * 2)); i = i + 2) {
        double val = LIBRE_MULTIPLIER * (unsignedBytesToInt(buffer[i], buffer[i + 1]) & 0xFFF);
        UserError.Log.d(TAG, "Received 15 min value: " + JoH.qs(val, 4) + " for minute: " + min_offset);

        final long this_timestamp = timestamp - (min_offset * Constants.MINUTE_IN_MS);
        // TODO we may want to use getForPreciseTimestamp instead..
        if (BgReading.readingNearTimeStamp(this_timestamp) == null) {
            UserError.Log.d(TAG, "Creating a new reading at: " + JoH.dateTimeText(this_timestamp));
            BgReading.create(val, val, xdrip.getAppContext(), this_timestamp, min_offset != 0);
        } else {
            UserError.Log.d(TAG, "Already a reading for minute offset: " + min_offset);
        }

        min_offset++;
    }
}
 
Example 5
Source Project: xDrip-plus   Source File: BlueJayService.java    License: GNU General Public License v3.0 6 votes vote down vote up
public void getStatus3() {
    if (BlueJayInfo.getInfo(I.address).buildNumber >= 2092) {
        new QueueMe().setBytes(new byte[]{OPCODE_GET_STATUS_3})
                .setDescription("Get Status 3")
                .expireInSeconds(30)
                .setProcessor(new ReplyProcessor(I.connection) {
                    @Override
                    public void process(byte[] bytes) {
                        UserError.Log.d(TAG, "Status 3 Process callback: " + JoH.bytesToHex(bytes));
                        BlueJayInfo.getInfo(I.address).parseStatus3(bytes);
                        UserError.Log.d(TAG, BlueJayInfo.getInfo(I.address).toS());
                    }
                })
                .queueUnique();
    }
}
 
Example 6
Source Project: xDrip   Source File: PendiqService.java    License: GNU General Public License v3.0 6 votes vote down vote up
public synchronized void changeState(STATE new_state) {
    if (state == null) return;
    if ((state == new_state) && (state != INIT)) {
        if (state != CLOSE) {
            UserError.Log.d(TAG, "Already in state: " + new_state + " changing to CLOSE");
            changeState(CLOSE);
        }
    } else {
        if ((state == CLOSED || state == CLOSE) && new_state == CLOSE) {
            UserError.Log.d(TAG, "Not closing as already closed");
        } else {
            UserError.Log.d(TAG, "Changing state from: " + state + " to " + new_state);
            state = new_state;
            background_automata();
        }
    }
}
 
Example 7
private static void interpretRatio(Context context) {
    final long requested = getInternalPrefsLong(REQUESTED);
    final long received = getInternalPrefsLong(RECEIVED);

    if (requested > 0) {
        Log.d(TAG, "Requested: " + requested + " Received: " + received);
        if (requested == 10) {
            if (received < 4) {
                UserError.Log.ueh(TAG, "Issuing full screen wakeup as req: " + getInternalPrefsLong(REQUESTED) + " rec: " + getInternalPrefsLong(RECEIVED));
                Home.startHomeWithExtra(context, Home.HOME_FULL_WAKEUP, "1");
            }
        } else if (requested == 15) {
            if ((received < 4) && (!PowerStateReceiver.is_power_connected())) {
           disableMotionTrackingDueToErrors(context);
            }
        }

        if (requested > 20) {
            evaluateRequestReceivedCounters(false,context);
            resetRequestedReceivedCounters();
        }
    }
}
 
Example 8
Source Project: xDrip-plus   Source File: SMS.java    License: GNU General Public License v3.0 6 votes vote down vote up
public static boolean sendSMS(String destination, String message) {
    try {

        // TODO TRACK PARTS ON SEND INTENTS
        final SmsManager smsManager = SmsManager.getDefault();
        if (message.length() > 160) {
            final ArrayList<String> messageParts = smsManager.divideMessage(message);
            smsManager.sendMultipartTextMessage(destination, null, messageParts, null, null);
        } else {
            smsManager.sendTextMessage(destination, null, message, null, null);
        }
        return true;
    } catch (SecurityException e) {
        UserError.Log.wtf(TAG, "Error sending SMS! no permission? " + e);
        // warn user? disable feature?
    }
    return false;
}
 
Example 9
Source Project: xDrip-plus   Source File: BitmapTools.java    License: GNU General Public License v3.0 6 votes vote down vote up
public static Wrapper loadPNGBytesToRGB565(final byte[] pngBytes) {
    if (pngBytes == null || pngBytes.length == 0) return null;
    try {
        val options = new BitmapFactory.Options();
        options.inPreferredConfig = Bitmap.Config.RGB_565;
        final Bitmap bitmap = BitmapFactory.decodeByteArray(pngBytes, 0, pngBytes.length, options);

        val buffer = ByteBuffer.allocate(bitmap.getByteCount());
        val width = bitmap.getWidth();
        val height = bitmap.getHeight();
        bitmap.copyPixelsToBuffer(buffer);
        bitmap.recycle();
        return new Wrapper(TJ_BitmapType.RGB565, width, height, byteSwapRGB565(buffer.array()));
    } catch (Exception e) {
        UserError.Log.e(TAG, "loadPNGBytesToRGB565: exception " + e);
        return null;
    }
}
 
Example 10
Source Project: xDrip   Source File: UploadChunk.java    License: GNU General Public License v3.0 6 votes vote down vote up
public static String get(final long start, final long end) {

        UserError.Log.uel(TAG, "Syncing data between: " + dateTimeText(start) + " -> " + dateTimeText(end));
        if (end <= start) {
            UserError.Log.e(TAG, "End is <= start: " + dateTimeText(start) + " " + dateTimeText(end));
            return null;
        }
        if (end - start > MAX_UPLOAD_SIZE) {
            UserError.Log.e(TAG, "More than max range - rejecting");
            return null;
        }

        final List<BaseElement> records = new LinkedList<>();

        if (!Pref.getBooleanDefaultFalse("tidepool_no_treatments")) {
            records.addAll(getTreatments(start, end));
        }
        records.addAll(getBloodTests(start, end));
        records.addAll(getBasals(start, end));
        records.addAll(getBgReadings(start, end));

        return JoH.defaultGsonInstance().toJson(records);
    }
 
Example 11
Source Project: xDrip-plus   Source File: EmergencyAssist.java    License: GNU General Public License v3.0 6 votes vote down vote up
public static boolean isEnabled(Reason reason) {
    if (!isEnabled()) return false;
    switch (reason) {

        case DID_NOT_ACKNOWLEDGE_LOW_ALERT:
            return Pref.getBooleanDefaultFalse("emergency_assist_low_alert");
        case DID_NOT_ACKNOWLEDGE_HIGH_ALERT:
            return Pref.getBooleanDefaultFalse("emergency_assist_high_alert");
        case DEVICE_INACTIVITY:
            return Pref.getBooleanDefaultFalse("emergency_assist_inactivity");

        case EXTENDED_MISSED_READINGS:
        case REQUESTED_ASSISTANCE:
        case TESTING_FEATURE:
        case UNSPECIFIED:
        default:
            UserError.Log.e(TAG, "Unknown reason in isEnabled: " + reason);
            return false;
    }
}
 
Example 12
Source Project: xDrip   Source File: BuggySamsung.java    License: GNU General Public License v3.0 6 votes vote down vote up
public long evaluate(final long wakeup_time) {
    if (wakeup_time > 0) {
        final long wakeup_jitter = msSince(wakeup_time);
        //UserError.Log.e(TAG, "debug jitter: " + wakeup_jitter);
        if (wakeup_jitter < 0) {
            UserError.Log.e(TAG, "Woke up Early..");
        } else {
            if (wakeup_jitter > 1000) {
                UserError.Log.d(TAG, "Wake up, time jitter: " + JoH.niceTimeScalar(wakeup_jitter));
                if ((wakeup_jitter > TOLERABLE_JITTER) && (!buggy_samsung) && isSamsung()) {
                    UserError.Log.wtf(TAG, "Enabled Buggy Samsung workaround due to jitter of: " + JoH.niceTimeScalar(wakeup_jitter));
                    buggy_samsung = true;
                    PersistentStore.incrementLong(BUGGY_SAMSUNG_ENABLED);
                    max_wakeup_jitter = 0;
                } else {
                    max_wakeup_jitter = Math.max(max_wakeup_jitter, wakeup_jitter);
                    checkWasBuggy();
                }
            }
        }
        return wakeup_jitter;
    }
    return 0; // no wakeup time specified

}
 
Example 13
private static void set() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
        if (TimeRangeUtils.areWeInTimePeriod("number_wall")) {
            final BestGlucose.DisplayGlucose dg = BestGlucose.getDisplayGlucose();
            if (dg != null && !dg.isReallyStale()) {
                final Bitmap bitmap = NumberGraphic.getLockScreenBitmap(dg.unitized, dg.delta_arrow, dg.isStale());
                setBitmap(bitmap);
            } else {
                // data too stale
                setBitmap(null);
            }
        } else {
            // not time now
            setBitmap(null);
        }
    } else {
        if (JoH.ratelimit("lockscreen-wallpaper", 3600)) {
            UserError.Log.e(TAG, "Insufficient android version to set lockscreen image");
        }
    } // if sufficient android version
}
 
Example 14
Source Project: xDrip   Source File: AuthReqTx.java    License: GNU General Public License v3.0 6 votes vote down vote up
public static AuthReqTx getNextAuthPacket(final byte[] packet) {
    if (packet == null || packet.length == 0) {
        return new AuthReqTx(Hello, null);
    } else {
        if (packet.length >= 10) {
            final byte state = packet[1];
            if (state == Hello2U2.value) {
                final byte[] challengeFromDevice = Arrays.copyOfRange(packet, 2, 10);
                final byte[] challengeReply = calculateChallengeReply(challengeFromDevice);
                UserError.Log.d(TAG, "Device challenge: " + JoH.bytesToHex(challengeFromDevice) + " our reply: " + JoH.bytesToHex(challengeReply));
                return challengeReply != null ? new AuthReqTx(ThePassWordIs, challengeReply) : null;
            }
        }
    }

    // unknown state??
    return null;
}
 
Example 15
Source Project: xDrip-plus   Source File: Ob1G5StateMachine.java    License: GNU General Public License v3.0 6 votes vote down vote up
private static void processBacksies(List<BackFillStream.Backsie> backsies) {
    boolean changed = false;
    for (BackFillStream.Backsie backsie : backsies) {
        final long time = DexTimeKeeper.fromDexTime(getTransmitterID(), backsie.getDextime());

        final long since = JoH.msSince(time);
        if ((since > HOUR_IN_MS * 6) || (since < 0)) {
            UserError.Log.wtf(TAG, "Backfill timestamp unrealistic: " + JoH.dateTimeText(time) + " (ignored)");
        } else {
            if (BgReading.getForPreciseTimestamp(time, Constants.MINUTE_IN_MS * 4) == null) {
                final BgReading bgr = BgReading.bgReadingInsertFromG5(backsie.getGlucose(), time, "Backfill");
                lastGlucoseBgReading = bgr;
                UserError.Log.d(TAG, "Adding backfilled reading: " + JoH.dateTimeText(time) + " " + BgGraphBuilder.unitized_string_static(backsie.getGlucose()));
                changed = true;
            }
            UserError.Log.d(TAG, "Backsie: " + JoH.dateTimeText(time) + " " + BgGraphBuilder.unitized_string_static(backsie.getGlucose()));
        }
    }
    if (changed) {
        updateStreamedTillTimeForBackfill();
    }
}
 
Example 16
Source Project: xDrip-plus   Source File: BlueJayService.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Override
public void process(byte[] bytes) {
    if (isAuthRequiredPacket(bytes)) {
        // handle setTag on either inner or outer
        UserError.Log.d(TAG, "Authentication is required");
        if (getTag() != null) {
            authenticate((QueueMe) getTag());
        } else {
            if (secondary.getTag() != null) {
                authenticate((QueueMe) secondary.getTag());
            } else {
                UserError.Log.d(TAG, "AuthReplyProcessor: neither inner or outer contain reference tag for packet");
            }
        }
    } else {
        UserError.Log.d(TAG, "Authentication is not required");
        secondary.process(bytes);
    }
}
 
Example 17
private void tryLoadingSavedMAC() {
    if ((transmitterMAC == null) || (!transmitterIDmatchingMAC.equals(transmitterID))) {
        if (transmitterID != null) {
            final String this_mac = PersistentStore.getString(OB1G5_MACSTORE + transmitterID);
            if (this_mac.length() == 17) {
                UserError.Log.d(TAG, "Loaded stored MAC for: " + transmitterID + " " + this_mac);
                transmitterMAC = this_mac;
                transmitterIDmatchingMAC = transmitterID;
            } else {
                UserError.Log.d(TAG, "Did not find any saved MAC for: " + transmitterID);
            }
        } else {
            UserError.Log.e(TAG, "Could not load saved mac as transmitter id isn't set!");
        }
    } else {
        UserError.Log.d(TAG, "MAC for transmitter id already populated: " + transmitterID + " " + transmitterMAC);
    }
}
 
Example 18
Source Project: xDrip   Source File: HeartRateService.java    License: GNU General Public License v3.0 6 votes vote down vote up
private boolean checkSensorPermissions() {//KS
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) return true;
    mSensorPermissionApproved =
            ActivityCompat.checkSelfPermission(
                    getApplicationContext(),
                    Manifest.permission.BODY_SENSORS) == PackageManager.PERMISSION_GRANTED;
    UserError.Log.d(TAG, "checkSensorPermission  mSensorPermissionApproved:" + mSensorPermissionApproved);

    // Display Activity to get user permission
    if (!mSensorPermissionApproved) {
        if (JoH.ratelimit("sensor_permission", 20)) {
            Intent permissionIntent = new Intent(getApplicationContext(), SensorPermissionActivity.class);
            permissionIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(permissionIntent);
        }
    }

    return mSensorPermissionApproved;
}
 
Example 19
private void handleWakeup() {
    if (always_scan) {
        UserError.Log.d(TAG, "Always scan mode");
        changeState(SCAN);
    } else {
        if (connectFailures > 0 || (!use_auto_connect && connectNowFailures > 0)) {
            always_scan = true;
            UserError.Log.e(TAG, "Switching to scan always mode due to connect failures metric: " + connectFailures);
            changeState(SCAN);
        } else if (use_auto_connect && (connectNowFailures > 1) && (connectFailures < 0)) {
            UserError.Log.d(TAG, "Avoiding power connect due to failure metric: " + connectNowFailures + " " + connectFailures);
            changeState(CONNECT);
        } else {
            changeState(CONNECT_NOW);
        }
    }
}
 
Example 20
Source Project: xDrip-plus   Source File: BlueJay.java    License: GNU General Public License v3.0 5 votes vote down vote up
public static void storeAuthKey(String mac, final String key) {
    mac = JoH.macFormat(mac);
    UserError.Log.d(TAG, "STORE AUTH: " + mac + " " + key);
    if (mac != null && mac.length() == 17
            && key != null && key.length() == 32) {
        Pref.setString(PREF_BLUEJAY_AUTH + mac.toUpperCase(), key);
    } else {
        UserError.Log.e(TAG, "Cannot store auth key as may be invalid");
    }
}
 
Example 21
Source Project: xDrip-plus   Source File: InPenService.java    License: GNU General Public License v3.0 5 votes vote down vote up
private boolean checkMissingIndex() {
    final long missingIndex = PenData.getMissingIndex(I.address);
    if (missingIndex != -1) {
        UserError.Log.d(TAG, "Index: " + missingIndex + " is missing");
        getRecords((int) missingIndex, (int) missingIndex);
        return true;
    }
    return false;
}
 
Example 22
Source Project: xDrip   Source File: ListenerService.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onChannelClosed(final Channel channel, final int closeReason, final int appSpecificErrorCode) {
    logChannelCloseReason("Whole Channel", channel, closeReason, appSpecificErrorCode);
    // TODO counter for failures??
    if ((closeReason == CLOSE_REASON_LOCAL_CLOSE || closeReason == CLOSE_REASON_REMOTE_CLOSE) && reRequestDownloadApkCounter < 30 && apkBytesRead < 1 && appSpecificErrorCode == 0) {
        UserError.Log.d(TAG,"Requesting to download again");
        reRequestDownloadApkCounter++;
        Inevitable.task("re-request apk download on close", 16000, VersionFixer::downloadApk);
    }
}
 
Example 23
Source Project: xDrip   Source File: Inevitable.java    License: GNU General Public License v3.0 5 votes vote down vote up
public boolean poll() {
    final long till = JoH.msTill(when);
    if (till < 1) {
        if (d) UserError.Log.d(TAG, "Executing task! " + this.id);
        tasks.remove(this.id); // early remove to allow overlapping scheduling
        what.run();
        return true;
    } else if (till > MAX_QUEUE_TIME) {
        UserError.Log.wtf(TAG, "Task: " + this.id + " In queue too long: " + till);
        tasks.remove(this.id);
        return true;
    }
    return false;
}
 
Example 24
Source Project: xDrip-plus   Source File: BaseCallback.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onFailure(Call<T> call, Throwable t) {
    final String msg = name + " Failed: " + t;
    UserError.Log.e(TAG, msg);
    status(msg);
    if (onFailure != null) {
        onFailure.run();
    }
}
 
Example 25
Source Project: xDrip   Source File: G5CollectionService.java    License: GNU General Public License v3.0 5 votes vote down vote up
public static boolean setStoredFirmwareBytes(String transmitterId, byte[] data, boolean from_bluetooth) {
    if (from_bluetooth) UserError.Log.e(TAG, "Store: VersionRX dbg: " + JoH.bytesToHex(data));
    if (transmitterId.length() != 6) return false;
    if (data.length < 10) return false;
    if (JoH.ratelimit("store-firmware-bytes", 60)) {
        PersistentStore.setBytes("g5-firmware-" + transmitterId, data);
    }
    return true;
}
 
Example 26
Source Project: xDrip-plus   Source File: WebServiceSteps.java    License: GNU General Public License v3.0 5 votes vote down vote up
public WebResponse request(String query) {

        query = stripFirstComponent(query);

        List<String> components = getUrlComponents(query);

        if (components.size() > 0) {
            UserError.Log.d(TAG, "Processing " + query);
            switch (components.get(0)) {

                case "set":
                    if (components.size() == 2) {
                        // sets pebble movement data for steps NOW, must be current step counter reading only
                        try {
                            int data = Integer.parseInt(components.get(1));
                            final StepCounter pm = StepCounter.createEfficientRecord(JoH.tsl(), data);
                            return webOk("Updated step counter: " + data);
                        } catch (NumberFormatException e) {
                            return webError("Couldn't parse Set value: " + components.get(1));
                        }
                    } else {
                        return webError("Incorrect parameters for Set", 400);
                    }
                    //break;
                default:
                    return webError("Unknown steps command: " + components.get(0));
            }

        } else {
            return webError("No steps command specified", 404);
        }
    }
 
Example 27
Source Project: xDrip   Source File: AuthReqTx.java    License: GNU General Public License v3.0 5 votes vote down vote up
public static byte[] ecbEncrypt(final byte[] keyBytes, final byte[] clearBytes) {
    try {
        final SecretKeySpec newKey = new SecretKeySpec(keyBytes, "AES");
        @SuppressLint("GetInstance") final Cipher cipher = Cipher.getInstance("AES/ECB/NoPadding");
        cipher.init(Cipher.ENCRYPT_MODE, newKey);
        return cipher.doFinal(clearBytes);
    } catch (Exception e) {
        UserError.Log.e(TAG, "Error during encryption: " + e.toString());
        return null;
    }
}
 
Example 28
Source Project: xDrip   Source File: Ob1G5CollectionService.java    License: GNU General Public License v3.0 5 votes vote down vote up
private boolean isScanMatch(final String this_address, final String historical_address, final String this_name, final String search_name) {
    boolean result = this_address.equalsIgnoreCase(historical_address) || (this_name != null && this_name.equalsIgnoreCase(search_name));
    if (result) {
        if (historical_address.length() == this_address.length()
                && !this_address.equalsIgnoreCase(historical_address)) {
            if (JoH.ratelimit("ob1-address-change-error", 30)) {
                UserError.Log.wtf(TAG, "Bluetooth device: " + search_name + " apparently changed from mac: " + historical_address + " to: " + this_address + " :: There appears to be confusion between devices - ignoring this scan result");
            }
            result = false;
        }
    }
    return result;
}
 
Example 29
Source Project: xDrip-plus   Source File: Amazfitservice.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onDestroy() {

    if (transporter != null) {
        transporter.disconnectTransportService();
    }
    UserError.Log.e("Amazfitservice", "killing service ");

    super.onDestroy();
}
 
Example 30
Source Project: xDrip-plus   Source File: BgReadingTable.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onResume() {
    UserError.Log.d(TAG, "onResume");
    super.onResume();
    //mNavigationDrawerFragment = (NavigationDrawerFragment) getFragmentManager().findFragmentById(R.id.navigation_drawer);
    //mNavigationDrawerFragment.setUp(R.id.navigation_drawer, (DrawerLayout) findViewById(R.id.drawer_layout), menu_name, this);

    getData();
}