正在查看: xDrip+ v04633772025.07.16 应用的 HeadsetStateReceiver.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
正在查看: xDrip+ v04633772025.07.16 应用的 HeadsetStateReceiver.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
package com.eveningoutpost.dexdrip.utils;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothProfile;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import com.eveningoutpost.dexdrip.Home;
import com.eveningoutpost.dexdrip.models.JoH;
import com.eveningoutpost.dexdrip.models.UserError;
import com.eveningoutpost.dexdrip.ui.activities.SelectAudioDevice;
import com.eveningoutpost.dexdrip.utilitymodels.Inevitable;
import com.eveningoutpost.dexdrip.utilitymodels.PersistentStore;
import com.eveningoutpost.dexdrip.utilitymodels.SpeechUtil;
import com.eveningoutpost.dexdrip.utilitymodels.VehicleMode;
import com.eveningoutpost.dexdrip.xdrip;
import java.util.Iterator;
public class HeadsetStateReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if ("android.bluetooth.headset.profile.action.CONNECTION_STATE_CHANGED".equals(action)) {
BluetoothDevice bluetoothDevice = (BluetoothDevice) intent.getParcelableExtra("android.bluetooth.device.extra.DEVICE");
if (bluetoothDevice != null && bluetoothDevice.getAddress() != null) {
int intExtra = intent.getIntExtra("android.bluetooth.profile.extra.STATE", -1);
int intExtra2 = intent.getIntExtra("android.bluetooth.profile.extra.PREVIOUS_STATE", -1);
StringBuilder sb = new StringBuilder();
sb.append(bluetoothDevice.getName());
sb.append("\n");
sb.append(bluetoothDevice.getAddress());
sb.append(" ");
sb.append(bluetoothDevice.getBluetoothClass() != null ? bluetoothDevice.getBluetoothClass() : "<unknown class>");
String sb2 = sb.toString();
if (intExtra == 2 && intExtra2 != 2) {
PersistentStore.setString("bluetooth-last-audio-connected-mac", bluetoothDevice.getAddress());
PersistentStore.setString("bluetooth-last-audio-connected-name", bluetoothDevice.getName());
UserError.Log.uel("BluetoothHeadset", "Bluetooth Audio connected: " + sb2);
processDevice(bluetoothDevice.getAddress(), true);
return;
}
if (intExtra != 0 || intExtra2 == 0) {
return;
}
UserError.Log.uel("BluetoothHeadset", "Bluetooth Audio disconnected: " + sb2);
processDevice(bluetoothDevice.getAddress(), false);
return;
}
UserError.Log.d("BluetoothHeadset", "Device was null in intent!");
return;
}
if ("android.bluetooth.headset.profile.action.AUDIO_STATE_CHANGED".equals(action)) {
UserError.Log.e("BluetoothHeadset", "audio state changed: " + intent.getIntExtra("android.bluetooth.profile.extra.STATE", -1));
return;
}
if ("android.bluetooth.headset.action.VENDOR_SPECIFIC_HEADSET_EVENT".equals(action)) {
UserError.Log.e("BluetoothHeadset", "Vendor specific command event received");
}
}
public static void processDevice(String str, boolean z) {
if (VehicleMode.isEnabled() && VehicleMode.viaCarAudio() && SelectAudioDevice.getAudioMac().equals(str)) {
VehicleMode.setVehicleModeActive(z);
StringBuilder sb = new StringBuilder();
sb.append("Vehicle mode: ");
sb.append(z ? "Enabled" : "Disabled");
UserError.Log.ueh("BluetoothHeadset", sb.toString());
if (z) {
Inevitable.task("xdrip-vehicle-mode", 10000L, new Runnable() {
@Override
public final void run() {
HeadsetStateReceiver.audioNotification();
}
});
}
Home.staticRefreshBGChartsOnIdle();
}
}
public static void audioNotification() {
if (VehicleMode.isVehicleModeActive()) {
if (VehicleMode.shouldUseSpeech()) {
SpeechUtil.say(" X Drip ... ", 500L);
} else if (VehicleMode.shouldPlaySound()) {
JoH.playResourceAudio(2131689966);
}
}
}
public static String getLastConnectedMac() {
return PersistentStore.getString("bluetooth-last-audio-connected-mac");
}
public static String getLastConnectedName() {
return PersistentStore.getString("bluetooth-last-audio-connected-name");
}
public static void reprocessConnectionIfAlreadyConnected(final String str) {
VehicleMode.setVehicleModeActive(false);
areWeConnectedToMac(str, new Runnable() {
@Override
public final void run() {
HeadsetStateReceiver.processDevice(str, true);
}
});
}
private static void areWeConnectedToMac(final String str, final Runnable runnable) {
if (BluetoothAdapter.getDefaultAdapter().getProfileConnectionState(1) != 2) {
return;
}
BluetoothAdapter.getDefaultAdapter().getProfileProxy(xdrip.getAppContext(), new BluetoothProfile.ServiceListener() {
@Override
public void onServiceDisconnected(int i) {
}
@Override
public void onServiceConnected(int i, BluetoothProfile bluetoothProfile) {
Runnable runnable2;
Iterator<BluetoothDevice> it = bluetoothProfile.getConnectedDevices().iterator();
while (true) {
if (!it.hasNext()) {
break;
}
BluetoothDevice next = it.next();
if (next.getAddress().equals(str)) {
boolean z = bluetoothProfile.getConnectionState(next) == 2;
StringBuilder sb = new StringBuilder();
sb.append("Found: ");
sb.append(next.getName());
sb.append(" ");
sb.append(next.getAddress());
sb.append(" ");
sb.append(z ? "Connected" : "Not connected");
UserError.Log.uel("BluetoothHeadset", sb.toString());
if (z && (runnable2 = runnable) != null) {
runnable2.run();
}
}
}
BluetoothAdapter.getDefaultAdapter().closeProfileProxy(i, bluetoothProfile);
}
}, 1);
}
}