正在查看: xDrip+ v04633772025.07.16 应用的 PebbleWatchSync.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
正在查看: xDrip+ v04633772025.07.16 应用的 PebbleWatchSync.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
package com.eveningoutpost.dexdrip.utilitymodels.pebble;
import android.bluetooth.BluetoothManager;
import android.content.Context;
import android.content.Intent;
import android.os.IBinder;
import android.os.PowerManager;
import com.eveningoutpost.dexdrip.importedlibraries.usbserial.driver.UsbId;
import com.eveningoutpost.dexdrip.models.HeartRate;
import com.eveningoutpost.dexdrip.models.JoH;
import com.eveningoutpost.dexdrip.models.StepCounter;
import com.eveningoutpost.dexdrip.models.UserError;
import com.eveningoutpost.dexdrip.utilitymodels.AlertPlayer;
import com.eveningoutpost.dexdrip.utilitymodels.BgGraphBuilder;
import com.eveningoutpost.dexdrip.utilitymodels.BroadcastSnooze;
import com.eveningoutpost.dexdrip.utilitymodels.Pref;
import com.eveningoutpost.dexdrip.utils.framework.ForegroundService;
import com.eveningoutpost.dexdrip.xdrip;
import com.getpebble.android.kit.PebbleKit;
import com.getpebble.android.kit.util.PebbleDictionary;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.UUID;
public class PebbleWatchSync extends ForegroundService {
public static final UUID PEBBLEAPP_UUID = UUID.fromString("79f8ecb3-7214-4bfc-b996-cb95148ee6d3");
public static final UUID PEBBLE_CONTROL_APP_UUID = UUID.fromString("aa14a012-96c8-4ce6-9466-4bfdf0d5a74e");
private static final String TAG = PebbleWatchSync.class.getSimpleName();
private static BgGraphBuilder bgGraphBuilder;
private static Context context;
public static int lastTransactionId;
private static Map<PebbleDisplayType, PebbleDisplayInterface> pebbleDisplays;
private UUID currentWatchFaceUUID;
private long last_heartrate_timestamp = 0;
private long last_movement_timestamp = 0;
public static void setPebbleType(int i) {
PebbleUtil.pebbleDisplayType = PebbleUtil.getPebbleDisplayType(i);
}
@Override
public void onCreate() {
super.onCreate();
context = getApplicationContext();
bgGraphBuilder = new BgGraphBuilder(context);
initPebbleDisplays();
PebbleUtil.pebbleDisplayType = getCurrentBroadcastToPebbleSetting();
UserError.Log.d(TAG, "onCreate for: " + PebbleUtil.pebbleDisplayType.toString());
this.currentWatchFaceUUID = getActivePebbleDisplay().watchfaceUUID();
init();
}
private void initPebbleDisplays() {
if (pebbleDisplays == null) {
HashMap hashMap = new HashMap();
pebbleDisplays = hashMap;
hashMap.put(PebbleDisplayType.None, new PebbleDisplayDummy());
pebbleDisplays.put(PebbleDisplayType.Standard, new PebbleDisplayStandard());
pebbleDisplays.put(PebbleDisplayType.Trend, new PebbleDisplayTrendOld());
pebbleDisplays.put(PebbleDisplayType.TrendClassic, new PebbleDisplayTrendOld());
pebbleDisplays.put(PebbleDisplayType.TrendClay, new PebbleDisplayTrend());
}
Iterator<PebbleDisplayInterface> it = pebbleDisplays.values().iterator();
while (it.hasNext()) {
it.next().initDisplay(context, this, bgGraphBuilder);
}
}
public PebbleDisplayInterface getActivePebbleDisplay() {
return pebbleDisplays.get(PebbleUtil.pebbleDisplayType);
}
public static PebbleDisplayType getCurrentBroadcastToPebbleSetting() {
return PebbleUtil.getPebbleDisplayType(PebbleUtil.getCurrentPebbleSyncType());
}
private void check_and_enable_bluetooth() {
try {
if (((BluetoothManager) getSystemService("bluetooth")).getAdapter().isEnabled() || !Pref.getBoolean("automatically_turn_bluetooth_on", true)) {
return;
}
JoH.setBluetoothEnabled(getApplicationContext(), true);
} catch (Exception e) {
UserError.Log.e(TAG, "Error checking/enabling bluetooth: " + e);
}
}
@Override
public int onStartCommand(Intent intent, int i, int i2) {
if (getCurrentBroadcastToPebbleSetting() == PebbleDisplayType.None) {
stopSelf();
return 2;
}
PowerManager.WakeLock wakeLock = JoH.getWakeLock("pebble_service_start", UsbId.SILABS_CP2102);
try {
UserError.Log.i(TAG, "STARTING SERVICE PebbleWatchSync");
check_and_enable_bluetooth();
getActivePebbleDisplay().startDeviceCommand();
JoH.releaseWakeLock(wakeLock);
return 1;
} catch (Throwable th) {
JoH.releaseWakeLock(wakeLock);
throw th;
}
}
@Override
public void onDestroy() {
UserError.Log.d(TAG, "onDestroy called");
super.onDestroy();
}
@Override
public IBinder onBind(Intent intent) {
throw new UnsupportedOperationException("Not yet implemented");
}
protected void init() {
String str = TAG;
UserError.Log.i(str, "Initialising...");
UserError.Log.i(str, "configuring PebbleDataReceiver for: " + this.currentWatchFaceUUID.toString());
PebbleKit.registerReceivedDataHandler(context, new PebbleKit.PebbleDataReceiver(this.currentWatchFaceUUID) {
@Override
public void receiveData(Context context2, int i, PebbleDictionary pebbleDictionary) {
PebbleWatchSync.this.getActivePebbleDisplay().receiveData(i, pebbleDictionary);
}
});
PebbleKit.registerReceivedAckHandler(context, new PebbleKit.PebbleAckReceiver(this.currentWatchFaceUUID) {
@Override
public void receiveAck(Context context2, int i) {
PebbleWatchSync.this.getActivePebbleDisplay().receiveAck(i);
}
});
PebbleKit.registerReceivedNackHandler(context, new PebbleKit.PebbleNackReceiver(this.currentWatchFaceUUID) {
@Override
public void receiveNack(Context context2, int i) {
PebbleWatchSync.this.getActivePebbleDisplay().receiveNack(i);
}
});
PebbleKit.registerDataLogReceiver(context, new PebbleKit.PebbleDataLogReceiver(this.currentWatchFaceUUID) {
@Override
public void onFinishSession(Context context2, UUID uuid, Long l, Long l2) {
}
@Override
public void receiveData(Context context2, UUID uuid, Long l, Long l2, int i) {
}
@Override
public void receiveData(Context context2, UUID uuid, Long l, Long l2, byte[] bArr) {
}
@Override
public void receiveData(Context context2, UUID uuid, Long l, Long l2, Long l3) {
UserError.Log.d(PebbleWatchSync.TAG, "receiveLogData: uuid:" + uuid + " started: " + JoH.dateTimeText(l.longValue() * 1000) + " tag:" + l2 + " data: " + l3);
if (Pref.getBoolean("use_pebble_health", true)) {
if (l2 == null || l3 == null) {
UserError.Log.e(PebbleWatchSync.TAG, "Got null Long in receive data");
return;
}
int longValue = ((int) l2.longValue()) & (-9);
if (longValue == 101) {
if (l3.longValue() > 1478197375) {
if (PebbleWatchSync.this.last_heartrate_timestamp > 0) {
UserError.Log.e(PebbleWatchSync.TAG, "Out of sequence heartrate timestamp received!");
}
PebbleWatchSync.this.last_heartrate_timestamp = l3.longValue();
return;
}
if (l3.longValue() > 0) {
if (PebbleWatchSync.this.last_heartrate_timestamp <= 0) {
UserError.Log.e(PebbleWatchSync.TAG, "Out of sequence heartrate value received!");
return;
}
HeartRate heartRate = new HeartRate();
heartRate.timestamp = PebbleWatchSync.this.last_heartrate_timestamp * 1000;
heartRate.bpm = (int) l3.longValue();
UserError.Log.d(PebbleWatchSync.TAG, "Saving HeartRate: " + heartRate.toS());
heartRate.saveit();
PebbleWatchSync.this.last_heartrate_timestamp = 0L;
return;
}
return;
}
if (longValue != 103) {
UserError.Log.e(PebbleWatchSync.TAG, "Unknown pebble data log type received: " + longValue);
return;
}
if (l3.longValue() > 1478197375) {
if (PebbleWatchSync.this.last_movement_timestamp > 0) {
UserError.Log.e(PebbleWatchSync.TAG, "Out of sequence movement timestamp received!");
}
PebbleWatchSync.this.last_movement_timestamp = l3.longValue();
return;
}
if (l3.longValue() > 0) {
if (PebbleWatchSync.this.last_movement_timestamp > 0) {
StepCounter createEfficientRecord = StepCounter.createEfficientRecord(PebbleWatchSync.this.last_movement_timestamp * 1000, (int) l3.longValue());
UserError.Log.d(PebbleWatchSync.TAG, "Saving Movement: " + createEfficientRecord.toS());
PebbleWatchSync.this.last_movement_timestamp = 0L;
return;
}
UserError.Log.e(PebbleWatchSync.TAG, "Out of sequence movement value received!");
}
}
}
});
PebbleKit.registerReceivedDataHandler(context, new PebbleKit.PebbleDataReceiver(PEBBLE_CONTROL_APP_UUID) {
@Override
public void receiveData(Context context2, int i, PebbleDictionary pebbleDictionary) {
PebbleWatchSync.this.getActivePebbleDisplay().receiveAppData(i, pebbleDictionary);
}
});
}
public static void receiveAppData(int i, PebbleDictionary pebbleDictionary) {
UserError.Log.d(TAG, "receiveAppData: transactionId is " + String.valueOf(i));
AlertPlayer.getPlayer().Snooze(xdrip.getAppContext(), -1);
PebbleKit.sendAckToPebble(xdrip.getAppContext(), i);
BroadcastSnooze.send();
JoH.static_toast_long("Alarm snoozed by pebble");
}
}