Initial commit
This commit is contained in:
14
sources/com/afunx/ble/blelitelib/BuildConfig.java
Normal file
14
sources/com/afunx/ble/blelitelib/BuildConfig.java
Normal file
@@ -0,0 +1,14 @@
|
||||
package com.afunx.ble.blelitelib;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public final class BuildConfig {
|
||||
|
||||
@Deprecated
|
||||
public static final String APPLICATION_ID = "com.afunx.ble.blelitelib";
|
||||
public static final String BUILD_TYPE = "release";
|
||||
public static final boolean DEBUG = false;
|
||||
public static final String FLAVOR = "";
|
||||
public static final String LIBRARY_PACKAGE_NAME = "com.afunx.ble.blelitelib";
|
||||
public static final int VERSION_CODE = 1;
|
||||
public static final String VERSION_NAME = "1.0";
|
||||
}
|
254
sources/com/afunx/ble/blelitelib/R.java
Normal file
254
sources/com/afunx/ble/blelitelib/R.java
Normal file
@@ -0,0 +1,254 @@
|
||||
package com.afunx.ble.blelitelib;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public final class R {
|
||||
|
||||
public static final class attr {
|
||||
public static final int alpha = 0x7f040028;
|
||||
public static final int coordinatorLayoutStyle = 0x7f0400c5;
|
||||
public static final int font = 0x7f0400fb;
|
||||
public static final int fontProviderAuthority = 0x7f0400fd;
|
||||
public static final int fontProviderCerts = 0x7f0400fe;
|
||||
public static final int fontProviderFetchStrategy = 0x7f0400ff;
|
||||
public static final int fontProviderFetchTimeout = 0x7f040100;
|
||||
public static final int fontProviderPackage = 0x7f040101;
|
||||
public static final int fontProviderQuery = 0x7f040102;
|
||||
public static final int fontStyle = 0x7f040103;
|
||||
public static final int fontVariationSettings = 0x7f040104;
|
||||
public static final int fontWeight = 0x7f040105;
|
||||
public static final int keylines = 0x7f04013e;
|
||||
public static final int layout_anchor = 0x7f040159;
|
||||
public static final int layout_anchorGravity = 0x7f04015a;
|
||||
public static final int layout_behavior = 0x7f04015b;
|
||||
public static final int layout_dodgeInsetEdges = 0x7f040187;
|
||||
public static final int layout_insetEdge = 0x7f040190;
|
||||
public static final int layout_keyline = 0x7f040191;
|
||||
public static final int statusBarBackground = 0x7f04020c;
|
||||
public static final int ttcIndex = 0x7f040278;
|
||||
|
||||
private attr() {
|
||||
}
|
||||
}
|
||||
|
||||
public static final class color {
|
||||
public static final int notification_action_color_filter = 0x7f060116;
|
||||
public static final int notification_icon_bg_color = 0x7f060117;
|
||||
public static final int notification_material_background_media_default_color = 0x7f060118;
|
||||
public static final int primary_text_default_material_dark = 0x7f06011e;
|
||||
public static final int ripple_material_light = 0x7f06012a;
|
||||
public static final int secondary_text_default_material_dark = 0x7f06012b;
|
||||
public static final int secondary_text_default_material_light = 0x7f06012c;
|
||||
|
||||
private color() {
|
||||
}
|
||||
}
|
||||
|
||||
public static final class dimen {
|
||||
public static final int compat_button_inset_horizontal_material = 0x7f07013f;
|
||||
public static final int compat_button_inset_vertical_material = 0x7f070140;
|
||||
public static final int compat_button_padding_horizontal_material = 0x7f070141;
|
||||
public static final int compat_button_padding_vertical_material = 0x7f070142;
|
||||
public static final int compat_control_corner_material = 0x7f070143;
|
||||
public static final int compat_notification_large_icon_max_height = 0x7f070144;
|
||||
public static final int compat_notification_large_icon_max_width = 0x7f070145;
|
||||
public static final int notification_action_icon_size = 0x7f071aaa;
|
||||
public static final int notification_action_text_size = 0x7f071aab;
|
||||
public static final int notification_big_circle_margin = 0x7f071aac;
|
||||
public static final int notification_content_margin_start = 0x7f071aad;
|
||||
public static final int notification_large_icon_height = 0x7f071aae;
|
||||
public static final int notification_large_icon_width = 0x7f071aaf;
|
||||
public static final int notification_main_column_padding_top = 0x7f071ab0;
|
||||
public static final int notification_media_narrow_margin = 0x7f071ab1;
|
||||
public static final int notification_right_icon_size = 0x7f071ab2;
|
||||
public static final int notification_right_side_padding_top = 0x7f071ab3;
|
||||
public static final int notification_small_icon_background_padding = 0x7f071ab4;
|
||||
public static final int notification_small_icon_size_as_large = 0x7f071ab5;
|
||||
public static final int notification_subtext_size = 0x7f071ab6;
|
||||
public static final int notification_top_pad = 0x7f071ab7;
|
||||
public static final int notification_top_pad_large_text = 0x7f071ab8;
|
||||
public static final int subtitle_corner_radius = 0x7f071b5f;
|
||||
public static final int subtitle_outline_width = 0x7f071b60;
|
||||
public static final int subtitle_shadow_offset = 0x7f071b61;
|
||||
public static final int subtitle_shadow_radius = 0x7f071b62;
|
||||
|
||||
private dimen() {
|
||||
}
|
||||
}
|
||||
|
||||
public static final class drawable {
|
||||
public static final int notification_action_background = 0x7f080330;
|
||||
public static final int notification_bg = 0x7f080331;
|
||||
public static final int notification_bg_low = 0x7f080332;
|
||||
public static final int notification_bg_low_normal = 0x7f080333;
|
||||
public static final int notification_bg_low_pressed = 0x7f080334;
|
||||
public static final int notification_bg_normal = 0x7f080335;
|
||||
public static final int notification_bg_normal_pressed = 0x7f080336;
|
||||
public static final int notification_icon_background = 0x7f080337;
|
||||
public static final int notification_template_icon_bg = 0x7f080338;
|
||||
public static final int notification_template_icon_low_bg = 0x7f080339;
|
||||
public static final int notification_tile_bg = 0x7f08033a;
|
||||
public static final int notify_panel_notification_icon_bg = 0x7f08033b;
|
||||
|
||||
private drawable() {
|
||||
}
|
||||
}
|
||||
|
||||
public static final class id {
|
||||
public static final int action0 = 0x7f09000c;
|
||||
public static final int action_container = 0x7f090017;
|
||||
public static final int action_divider = 0x7f090019;
|
||||
public static final int action_image = 0x7f09001a;
|
||||
public static final int action_text = 0x7f090020;
|
||||
public static final int actions = 0x7f090021;
|
||||
public static final int async = 0x7f090046;
|
||||
public static final int blocking = 0x7f090057;
|
||||
public static final int bottom = 0x7f09005c;
|
||||
public static final int cancel_action = 0x7f090093;
|
||||
public static final int chronometer = 0x7f0900c4;
|
||||
public static final int end = 0x7f090137;
|
||||
public static final int end_padder = 0x7f090138;
|
||||
public static final int forever = 0x7f090184;
|
||||
public static final int icon = 0x7f0901bd;
|
||||
public static final int icon_group = 0x7f0901be;
|
||||
public static final int info = 0x7f0902cb;
|
||||
public static final int italic = 0x7f0902d4;
|
||||
public static final int left = 0x7f09032f;
|
||||
public static final int line1 = 0x7f09033f;
|
||||
public static final int line3 = 0x7f090340;
|
||||
public static final int media_actions = 0x7f090382;
|
||||
public static final int none = 0x7f0903a9;
|
||||
public static final int normal = 0x7f0903aa;
|
||||
public static final int notification_background = 0x7f0903ab;
|
||||
public static final int notification_main_column = 0x7f0903ac;
|
||||
public static final int notification_main_column_container = 0x7f0903ad;
|
||||
public static final int right = 0x7f090419;
|
||||
public static final int right_icon = 0x7f09041c;
|
||||
public static final int right_side = 0x7f09041d;
|
||||
public static final int start = 0x7f0904dc;
|
||||
public static final int status_bar_latest_event_content = 0x7f0904e0;
|
||||
public static final int tag_transition_group = 0x7f0904f8;
|
||||
public static final int tag_unhandled_key_event_manager = 0x7f0904f9;
|
||||
public static final int tag_unhandled_key_listeners = 0x7f0904fa;
|
||||
public static final int text = 0x7f090501;
|
||||
public static final int text2 = 0x7f090502;
|
||||
public static final int time = 0x7f09050f;
|
||||
public static final int title = 0x7f090513;
|
||||
public static final int top = 0x7f090520;
|
||||
|
||||
private id() {
|
||||
}
|
||||
}
|
||||
|
||||
public static final class integer {
|
||||
public static final int cancel_button_image_alpha = 0x7f0a0004;
|
||||
public static final int status_bar_notification_info_maxnum = 0x7f0a0011;
|
||||
|
||||
private integer() {
|
||||
}
|
||||
}
|
||||
|
||||
public static final class layout {
|
||||
public static final int notification_action = 0x7f0c01a8;
|
||||
public static final int notification_action_tombstone = 0x7f0c01a9;
|
||||
public static final int notification_media_action = 0x7f0c01aa;
|
||||
public static final int notification_media_cancel_action = 0x7f0c01ab;
|
||||
public static final int notification_template_big_media = 0x7f0c01ac;
|
||||
public static final int notification_template_big_media_custom = 0x7f0c01ad;
|
||||
public static final int notification_template_big_media_narrow = 0x7f0c01ae;
|
||||
public static final int notification_template_big_media_narrow_custom = 0x7f0c01af;
|
||||
public static final int notification_template_custom_big = 0x7f0c01b0;
|
||||
public static final int notification_template_icon_group = 0x7f0c01b1;
|
||||
public static final int notification_template_lines_media = 0x7f0c01b2;
|
||||
public static final int notification_template_media = 0x7f0c01b3;
|
||||
public static final int notification_template_media_custom = 0x7f0c01b4;
|
||||
public static final int notification_template_part_chronometer = 0x7f0c01b5;
|
||||
public static final int notification_template_part_time = 0x7f0c01b6;
|
||||
|
||||
private layout() {
|
||||
}
|
||||
}
|
||||
|
||||
public static final class string {
|
||||
public static final int status_bar_notification_info_overflow = 0x7f110427;
|
||||
|
||||
private string() {
|
||||
}
|
||||
}
|
||||
|
||||
public static final class style {
|
||||
public static final int TextAppearance_Compat_Notification = 0x7f12013b;
|
||||
public static final int TextAppearance_Compat_Notification_Info = 0x7f12013c;
|
||||
public static final int TextAppearance_Compat_Notification_Info_Media = 0x7f12013d;
|
||||
public static final int TextAppearance_Compat_Notification_Line2 = 0x7f12013e;
|
||||
public static final int TextAppearance_Compat_Notification_Line2_Media = 0x7f12013f;
|
||||
public static final int TextAppearance_Compat_Notification_Media = 0x7f120140;
|
||||
public static final int TextAppearance_Compat_Notification_Time = 0x7f120141;
|
||||
public static final int TextAppearance_Compat_Notification_Time_Media = 0x7f120142;
|
||||
public static final int TextAppearance_Compat_Notification_Title = 0x7f120143;
|
||||
public static final int TextAppearance_Compat_Notification_Title_Media = 0x7f120144;
|
||||
public static final int Widget_Compat_NotificationActionContainer = 0x7f1201ee;
|
||||
public static final int Widget_Compat_NotificationActionText = 0x7f1201ef;
|
||||
public static final int Widget_Support_CoordinatorLayout = 0x7f12021e;
|
||||
|
||||
private style() {
|
||||
}
|
||||
}
|
||||
|
||||
public static final class styleable {
|
||||
public static final int ColorStateListItem_alpha = 0x00000002;
|
||||
public static final int ColorStateListItem_android_alpha = 0x00000001;
|
||||
public static final int ColorStateListItem_android_color = 0x00000000;
|
||||
public static final int CoordinatorLayout_Layout_android_layout_gravity = 0x00000000;
|
||||
public static final int CoordinatorLayout_Layout_layout_anchor = 0x00000001;
|
||||
public static final int CoordinatorLayout_Layout_layout_anchorGravity = 0x00000002;
|
||||
public static final int CoordinatorLayout_Layout_layout_behavior = 0x00000003;
|
||||
public static final int CoordinatorLayout_Layout_layout_dodgeInsetEdges = 0x00000004;
|
||||
public static final int CoordinatorLayout_Layout_layout_insetEdge = 0x00000005;
|
||||
public static final int CoordinatorLayout_Layout_layout_keyline = 0x00000006;
|
||||
public static final int CoordinatorLayout_keylines = 0x00000000;
|
||||
public static final int CoordinatorLayout_statusBarBackground = 0x00000001;
|
||||
public static final int FontFamilyFont_android_font = 0x00000000;
|
||||
public static final int FontFamilyFont_android_fontStyle = 0x00000002;
|
||||
public static final int FontFamilyFont_android_fontVariationSettings = 0x00000004;
|
||||
public static final int FontFamilyFont_android_fontWeight = 0x00000001;
|
||||
public static final int FontFamilyFont_android_ttcIndex = 0x00000003;
|
||||
public static final int FontFamilyFont_font = 0x00000005;
|
||||
public static final int FontFamilyFont_fontStyle = 0x00000006;
|
||||
public static final int FontFamilyFont_fontVariationSettings = 0x00000007;
|
||||
public static final int FontFamilyFont_fontWeight = 0x00000008;
|
||||
public static final int FontFamilyFont_ttcIndex = 0x00000009;
|
||||
public static final int FontFamily_fontProviderAuthority = 0x00000000;
|
||||
public static final int FontFamily_fontProviderCerts = 0x00000001;
|
||||
public static final int FontFamily_fontProviderFetchStrategy = 0x00000002;
|
||||
public static final int FontFamily_fontProviderFetchTimeout = 0x00000003;
|
||||
public static final int FontFamily_fontProviderPackage = 0x00000004;
|
||||
public static final int FontFamily_fontProviderQuery = 0x00000005;
|
||||
public static final int GradientColorItem_android_color = 0x00000000;
|
||||
public static final int GradientColorItem_android_offset = 0x00000001;
|
||||
public static final int GradientColor_android_centerColor = 0x00000007;
|
||||
public static final int GradientColor_android_centerX = 0x00000003;
|
||||
public static final int GradientColor_android_centerY = 0x00000004;
|
||||
public static final int GradientColor_android_endColor = 0x00000001;
|
||||
public static final int GradientColor_android_endX = 0x0000000a;
|
||||
public static final int GradientColor_android_endY = 0x0000000b;
|
||||
public static final int GradientColor_android_gradientRadius = 0x00000005;
|
||||
public static final int GradientColor_android_startColor = 0x00000000;
|
||||
public static final int GradientColor_android_startX = 0x00000008;
|
||||
public static final int GradientColor_android_startY = 0x00000009;
|
||||
public static final int GradientColor_android_tileMode = 0x00000006;
|
||||
public static final int GradientColor_android_type = 0x00000002;
|
||||
public static final int[] ColorStateListItem = {android.R.attr.color, android.R.attr.alpha, com.ubt.jimu.R.attr.alpha};
|
||||
public static final int[] CoordinatorLayout = {com.ubt.jimu.R.attr.keylines, com.ubt.jimu.R.attr.statusBarBackground};
|
||||
public static final int[] CoordinatorLayout_Layout = {android.R.attr.layout_gravity, com.ubt.jimu.R.attr.layout_anchor, com.ubt.jimu.R.attr.layout_anchorGravity, com.ubt.jimu.R.attr.layout_behavior, com.ubt.jimu.R.attr.layout_dodgeInsetEdges, com.ubt.jimu.R.attr.layout_insetEdge, com.ubt.jimu.R.attr.layout_keyline};
|
||||
public static final int[] FontFamily = {com.ubt.jimu.R.attr.fontProviderAuthority, com.ubt.jimu.R.attr.fontProviderCerts, com.ubt.jimu.R.attr.fontProviderFetchStrategy, com.ubt.jimu.R.attr.fontProviderFetchTimeout, com.ubt.jimu.R.attr.fontProviderPackage, com.ubt.jimu.R.attr.fontProviderQuery};
|
||||
public static final int[] FontFamilyFont = {android.R.attr.font, android.R.attr.fontWeight, android.R.attr.fontStyle, android.R.attr.ttcIndex, android.R.attr.fontVariationSettings, com.ubt.jimu.R.attr.font, com.ubt.jimu.R.attr.fontStyle, com.ubt.jimu.R.attr.fontVariationSettings, com.ubt.jimu.R.attr.fontWeight, com.ubt.jimu.R.attr.ttcIndex};
|
||||
public static final int[] GradientColor = {android.R.attr.startColor, android.R.attr.endColor, android.R.attr.type, android.R.attr.centerX, android.R.attr.centerY, android.R.attr.gradientRadius, android.R.attr.tileMode, android.R.attr.centerColor, android.R.attr.startX, android.R.attr.startY, android.R.attr.endX, android.R.attr.endY};
|
||||
public static final int[] GradientColorItem = {android.R.attr.color, android.R.attr.offset};
|
||||
|
||||
private styleable() {
|
||||
}
|
||||
}
|
||||
|
||||
private R() {
|
||||
}
|
||||
}
|
117
sources/com/afunx/ble/blelitelib/connector/BleConnectCompat.java
Normal file
117
sources/com/afunx/ble/blelitelib/connector/BleConnectCompat.java
Normal file
@@ -0,0 +1,117 @@
|
||||
package com.afunx.ble.blelitelib.connector;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.bluetooth.BluetoothAdapter;
|
||||
import android.bluetooth.BluetoothDevice;
|
||||
import android.bluetooth.BluetoothGatt;
|
||||
import android.bluetooth.BluetoothGattCallback;
|
||||
import android.content.Context;
|
||||
import android.os.Build;
|
||||
import com.afunx.ble.blelitelib.log.BleLiteLog;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public class BleConnectCompat {
|
||||
private static final String TAG = "BleConnectCompat";
|
||||
private final Context context;
|
||||
|
||||
public BleConnectCompat(Context context) {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
private BluetoothGatt connectGattCompat(BluetoothGattCallback bluetoothGattCallback, BluetoothDevice bluetoothDevice, boolean z) {
|
||||
BleLiteLog.v(TAG, "Connecting without reflection");
|
||||
return Build.VERSION.SDK_INT >= 23 ? bluetoothDevice.connectGatt(this.context, z, bluetoothGattCallback, 2) : bluetoothDevice.connectGatt(this.context, z, bluetoothGattCallback);
|
||||
}
|
||||
|
||||
private boolean connectUsingReflection(BluetoothGatt bluetoothGatt, BluetoothGattCallback bluetoothGattCallback, boolean z) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException, NoSuchFieldException {
|
||||
BleLiteLog.v(TAG, "Connecting using reflection");
|
||||
setAutoConnectValue(bluetoothGatt, z);
|
||||
Method declaredMethod = bluetoothGatt.getClass().getDeclaredMethod("connect", Boolean.class, BluetoothGattCallback.class);
|
||||
declaredMethod.setAccessible(true);
|
||||
return ((Boolean) declaredMethod.invoke(bluetoothGatt, true, bluetoothGattCallback)).booleanValue();
|
||||
}
|
||||
|
||||
private BluetoothGatt connectUsingReflectionx(BluetoothDevice bluetoothDevice, BluetoothGattCallback bluetoothGattCallback, boolean z) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException, NoSuchFieldException {
|
||||
BleLiteLog.v(TAG, "Connecting using reflection");
|
||||
Method declaredMethod = bluetoothDevice.getClass().getDeclaredMethod("connectGatt", Context.class, Boolean.TYPE, BluetoothGattCallback.class, Integer.TYPE);
|
||||
declaredMethod.setAccessible(true);
|
||||
return (BluetoothGatt) declaredMethod.invoke(bluetoothDevice, this.context, true, bluetoothGattCallback, 2);
|
||||
}
|
||||
|
||||
@TargetApi(23)
|
||||
private BluetoothGatt createBluetoothGatt(Object obj, BluetoothDevice bluetoothDevice) throws IllegalAccessException, InvocationTargetException, InstantiationException {
|
||||
Constructor<?> constructor = BluetoothGatt.class.getDeclaredConstructors()[0];
|
||||
constructor.setAccessible(true);
|
||||
BleLiteLog.v(TAG, "Found constructor with args count = \" + bluetoothGattConstructor.getParameterTypes().length");
|
||||
return constructor.getParameterTypes().length == 4 ? (BluetoothGatt) constructor.newInstance(this.context, obj, bluetoothDevice, 2) : (BluetoothGatt) constructor.newInstance(this.context, obj, bluetoothDevice);
|
||||
}
|
||||
|
||||
private Object getIBluetoothGatt(Object obj) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
|
||||
if (obj == null) {
|
||||
return null;
|
||||
}
|
||||
return getMethodFromClass(obj.getClass(), "getBluetoothGatt").invoke(obj, new Object[0]);
|
||||
}
|
||||
|
||||
private Object getIBluetoothManager() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
|
||||
BluetoothAdapter defaultAdapter = BluetoothAdapter.getDefaultAdapter();
|
||||
if (defaultAdapter == null) {
|
||||
return null;
|
||||
}
|
||||
return getMethodFromClass(defaultAdapter.getClass(), "getBluetoothManager").invoke(defaultAdapter, new Object[0]);
|
||||
}
|
||||
|
||||
private Method getMethodFromClass(Class<?> cls, String str) throws NoSuchMethodException {
|
||||
Method declaredMethod = cls.getDeclaredMethod(str, new Class[0]);
|
||||
declaredMethod.setAccessible(true);
|
||||
return declaredMethod;
|
||||
}
|
||||
|
||||
private void setAutoConnectValue(BluetoothGatt bluetoothGatt, boolean z) throws NoSuchFieldException, IllegalAccessException {
|
||||
Field declaredField = bluetoothGatt.getClass().getDeclaredField("mAutoConnect");
|
||||
declaredField.setAccessible(true);
|
||||
declaredField.setBoolean(bluetoothGatt, z);
|
||||
}
|
||||
|
||||
public BluetoothGatt connectGatt(BluetoothDevice bluetoothDevice, boolean z, BluetoothGattCallback bluetoothGattCallback) {
|
||||
int i;
|
||||
if (bluetoothDevice == null) {
|
||||
return null;
|
||||
}
|
||||
if (Build.VERSION.SDK_INT >= 24 || !z) {
|
||||
return connectGattCompat(bluetoothGattCallback, bluetoothDevice, false);
|
||||
}
|
||||
String str = Build.PRODUCT;
|
||||
if (str != null && str.toUpperCase().contains("LenovoTB3".toUpperCase()) && (i = Build.VERSION.SDK_INT) >= 21 && i < 23) {
|
||||
return connectGattCompat(bluetoothGattCallback, bluetoothDevice, false);
|
||||
}
|
||||
try {
|
||||
BleLiteLog.v(TAG, "Trying to connectGatt using reflection.");
|
||||
if (Build.VERSION.SDK_INT >= 21 && Build.VERSION.SDK_INT < 23) {
|
||||
return connectUsingReflectionx(bluetoothDevice, bluetoothGattCallback, z);
|
||||
}
|
||||
Object iBluetoothGatt = getIBluetoothGatt(getIBluetoothManager());
|
||||
if (iBluetoothGatt == null) {
|
||||
BleLiteLog.v(TAG, "Couldn't get iBluetoothGatt object");
|
||||
return connectGattCompat(bluetoothGattCallback, bluetoothDevice, true);
|
||||
}
|
||||
BluetoothGatt createBluetoothGatt = createBluetoothGatt(iBluetoothGatt, bluetoothDevice);
|
||||
if (createBluetoothGatt == null) {
|
||||
BleLiteLog.v(TAG, "Couldn't create BluetoothGatt object");
|
||||
return connectGattCompat(bluetoothGattCallback, bluetoothDevice, true);
|
||||
}
|
||||
if (!connectUsingReflection(createBluetoothGatt, bluetoothGattCallback, true)) {
|
||||
BleLiteLog.v(TAG, "Connection using reflection failed, closing gatt");
|
||||
createBluetoothGatt.close();
|
||||
}
|
||||
return createBluetoothGatt;
|
||||
} catch (IllegalAccessException | IllegalArgumentException | InstantiationException | NoSuchFieldException | NoSuchMethodException | InvocationTargetException unused) {
|
||||
BleLiteLog.v(TAG, "Error during reflection");
|
||||
return connectGattCompat(bluetoothGattCallback, bluetoothDevice, true);
|
||||
}
|
||||
}
|
||||
}
|
85
sources/com/afunx/ble/blelitelib/connector/BleConnector.java
Normal file
85
sources/com/afunx/ble/blelitelib/connector/BleConnector.java
Normal file
@@ -0,0 +1,85 @@
|
||||
package com.afunx.ble.blelitelib.connector;
|
||||
|
||||
import android.bluetooth.BluetoothDevice;
|
||||
import android.bluetooth.BluetoothGatt;
|
||||
import android.bluetooth.BluetoothGattCallback;
|
||||
import android.content.Context;
|
||||
import com.afunx.ble.blelitelib.log.BleLiteLog;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public class BleConnector {
|
||||
private static final String TAG = "BleConnector";
|
||||
private final Context mAppContext;
|
||||
private final BluetoothDevice mBluetoothDevice;
|
||||
private BluetoothGatt mBluetoothGatt;
|
||||
private final BluetoothGattCallback mBluetoothGattCallback;
|
||||
private volatile boolean mIsClosed;
|
||||
|
||||
public synchronized void close() {
|
||||
if (!this.mIsClosed) {
|
||||
this.mIsClosed = true;
|
||||
if (this.mBluetoothGatt != null) {
|
||||
BleLiteLog.i(TAG, "close()");
|
||||
this.mBluetoothGatt.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void connect() {
|
||||
if (this.mIsClosed) {
|
||||
BleLiteLog.w(TAG, "connect() has been closed already, do nothing");
|
||||
return;
|
||||
}
|
||||
if (this.mBluetoothGatt == null) {
|
||||
BleLiteLog.i(TAG, "connect() connect...");
|
||||
this.mBluetoothGatt = new BleConnectCompat(this.mAppContext).connectGatt(this.mBluetoothDevice, false, this.mBluetoothGattCallback);
|
||||
} else {
|
||||
BleLiteLog.i(TAG, "connect() reconnect...");
|
||||
this.mBluetoothGatt.connect();
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized BluetoothGatt getBluetoothGatt() {
|
||||
if (this.mIsClosed) {
|
||||
BleLiteLog.w(TAG, "getBluetoothGatt() has been closed already, return null");
|
||||
return null;
|
||||
}
|
||||
return this.mBluetoothGatt;
|
||||
}
|
||||
|
||||
public static final class Builder {
|
||||
private BluetoothDevice mBluetoothDevice;
|
||||
private BluetoothGatt mBluetoothGatt;
|
||||
private BluetoothGattCallback mBluetoothGattCallback;
|
||||
private Context mContext;
|
||||
|
||||
public Builder build(Context context, BluetoothDevice bluetoothDevice) {
|
||||
this.mContext = context;
|
||||
this.mBluetoothDevice = bluetoothDevice;
|
||||
return this;
|
||||
}
|
||||
|
||||
public BleConnector create() {
|
||||
return new BleConnector(this.mContext, this.mBluetoothDevice, this.mBluetoothGatt, this.mBluetoothGattCallback);
|
||||
}
|
||||
|
||||
public Builder setGattCallback(BluetoothGattCallback bluetoothGattCallback) {
|
||||
this.mBluetoothGattCallback = bluetoothGattCallback;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder build(Context context, BluetoothDevice bluetoothDevice, BluetoothGatt bluetoothGatt) {
|
||||
this.mContext = context;
|
||||
this.mBluetoothDevice = bluetoothDevice;
|
||||
this.mBluetoothGatt = bluetoothGatt;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
private BleConnector(Context context, BluetoothDevice bluetoothDevice, BluetoothGatt bluetoothGatt, BluetoothGattCallback bluetoothGattCallback) {
|
||||
this.mAppContext = context.getApplicationContext();
|
||||
this.mBluetoothDevice = bluetoothDevice;
|
||||
this.mBluetoothGatt = bluetoothGatt;
|
||||
this.mBluetoothGattCallback = bluetoothGattCallback;
|
||||
}
|
||||
}
|
53
sources/com/afunx/ble/blelitelib/log/BleLiteLog.java
Normal file
53
sources/com/afunx/ble/blelitelib/log/BleLiteLog.java
Normal file
@@ -0,0 +1,53 @@
|
||||
package com.afunx.ble.blelitelib.log;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public class BleLiteLog {
|
||||
private static final String TAG = "BleLiteLog";
|
||||
private static final boolean sBleLiteLogTag = true;
|
||||
private static final boolean sDebug = true;
|
||||
|
||||
private BleLiteLog() {
|
||||
}
|
||||
|
||||
public static int d(String str, String str2) {
|
||||
return Log.d(TAG, str + ": " + str2);
|
||||
}
|
||||
|
||||
public static int e(String str, String str2) {
|
||||
return Log.e(TAG, str + ": " + str2);
|
||||
}
|
||||
|
||||
public static int i(String str, String str2) {
|
||||
return Log.i(TAG, str + ": " + str2);
|
||||
}
|
||||
|
||||
public static int v(String str, String str2) {
|
||||
return Log.v(TAG, str + ": " + str2);
|
||||
}
|
||||
|
||||
public static int w(String str, String str2) {
|
||||
return Log.w(TAG, str + ": " + str2);
|
||||
}
|
||||
|
||||
public static int d(String str, String str2, Throwable th) {
|
||||
return Log.d(TAG, str + ": " + str2, th);
|
||||
}
|
||||
|
||||
public static int e(String str, String str2, Throwable th) {
|
||||
return Log.e(TAG, str + ": " + str2, th);
|
||||
}
|
||||
|
||||
public static int i(String str, String str2, Throwable th) {
|
||||
return Log.i(TAG, str + ": " + str2, th);
|
||||
}
|
||||
|
||||
public static int v(String str, String str2, Throwable th) {
|
||||
return Log.v(TAG, str + ": " + str2, th);
|
||||
}
|
||||
|
||||
public static int w(String str, String str2, Throwable th) {
|
||||
return Log.w(TAG, str + ": " + str2, th);
|
||||
}
|
||||
}
|
31
sources/com/afunx/ble/blelitelib/log/BleLogImpl.java
Normal file
31
sources/com/afunx/ble/blelitelib/log/BleLogImpl.java
Normal file
@@ -0,0 +1,31 @@
|
||||
package com.afunx.ble.blelitelib.log;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public class BleLogImpl implements IBleLog {
|
||||
@Override // com.afunx.ble.blelitelib.log.IBleLog
|
||||
public int d(String str, String str2) {
|
||||
return Log.d(str, str2);
|
||||
}
|
||||
|
||||
@Override // com.afunx.ble.blelitelib.log.IBleLog
|
||||
public int e(String str, String str2) {
|
||||
return Log.e(str, str2);
|
||||
}
|
||||
|
||||
@Override // com.afunx.ble.blelitelib.log.IBleLog
|
||||
public int i(String str, String str2) {
|
||||
return Log.i(str, str2);
|
||||
}
|
||||
|
||||
@Override // com.afunx.ble.blelitelib.log.IBleLog
|
||||
public int v(String str, String str2) {
|
||||
return Log.v(str, str2);
|
||||
}
|
||||
|
||||
@Override // com.afunx.ble.blelitelib.log.IBleLog
|
||||
public int w(String str, String str2) {
|
||||
return Log.w(str, str2);
|
||||
}
|
||||
}
|
14
sources/com/afunx/ble/blelitelib/log/IBleLog.java
Normal file
14
sources/com/afunx/ble/blelitelib/log/IBleLog.java
Normal file
@@ -0,0 +1,14 @@
|
||||
package com.afunx.ble.blelitelib.log;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public interface IBleLog {
|
||||
int d(String str, String str2);
|
||||
|
||||
int e(String str, String str2);
|
||||
|
||||
int i(String str, String str2);
|
||||
|
||||
int v(String str, String str2);
|
||||
|
||||
int w(String str, String str2);
|
||||
}
|
@@ -0,0 +1,41 @@
|
||||
package com.afunx.ble.blelitelib.operation;
|
||||
|
||||
import android.bluetooth.BluetoothGatt;
|
||||
import com.afunx.ble.blelitelib.log.BleLiteLog;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public class BleCloseOperation extends BleOperationAbs {
|
||||
private static final String TAG = "BleCloseOperation";
|
||||
private final BluetoothGatt mBluetoothGatt;
|
||||
private boolean mIsClosed = false;
|
||||
|
||||
private BleCloseOperation(BluetoothGatt bluetoothGatt) {
|
||||
this.mBluetoothGatt = bluetoothGatt;
|
||||
}
|
||||
|
||||
public static BleCloseOperation createInstance(BluetoothGatt bluetoothGatt) {
|
||||
return new BleCloseOperation(bluetoothGatt);
|
||||
}
|
||||
|
||||
@Override // com.afunx.ble.blelitelib.operation.BleOperationAbs
|
||||
protected void clearConcurrentOperation() {
|
||||
}
|
||||
|
||||
@Override // com.afunx.ble.blelitelib.operation.BleOperation
|
||||
public int getOperatcionCode() {
|
||||
return 2;
|
||||
}
|
||||
|
||||
@Override // com.afunx.ble.blelitelib.operation.BleOperation, java.lang.Runnable
|
||||
public void run() {
|
||||
if (this.mIsClosed) {
|
||||
BleLiteLog.w(TAG, "it is closed already");
|
||||
return;
|
||||
}
|
||||
this.mIsClosed = true;
|
||||
BluetoothGatt bluetoothGatt = this.mBluetoothGatt;
|
||||
if (bluetoothGatt != null) {
|
||||
bluetoothGatt.close();
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,44 @@
|
||||
package com.afunx.ble.blelitelib.operation;
|
||||
|
||||
import android.bluetooth.BluetoothDevice;
|
||||
import android.bluetooth.BluetoothGattCallback;
|
||||
import android.content.Context;
|
||||
import com.afunx.ble.blelitelib.connector.BleConnector;
|
||||
import com.afunx.ble.blelitelib.utils.BleUtils;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public class BleConnectOperation extends BleOperationAbs {
|
||||
private final Context mAppContext;
|
||||
private final String mBleAddr;
|
||||
private final BluetoothGattCallback mBluetoothGattCallback;
|
||||
|
||||
private BleConnectOperation(Context context, String str, BluetoothGattCallback bluetoothGattCallback) {
|
||||
this.mAppContext = context.getApplicationContext();
|
||||
this.mBleAddr = str;
|
||||
this.mBluetoothGattCallback = bluetoothGattCallback;
|
||||
}
|
||||
|
||||
public static BleConnectOperation createInstance(Context context, String str, BluetoothGattCallback bluetoothGattCallback) {
|
||||
return new BleConnectOperation(context, str, bluetoothGattCallback);
|
||||
}
|
||||
|
||||
@Override // com.afunx.ble.blelitelib.operation.BleOperationAbs
|
||||
protected void clearConcurrentOperation() {
|
||||
}
|
||||
|
||||
@Override // com.afunx.ble.blelitelib.operation.BleOperation
|
||||
public int getOperatcionCode() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override // com.afunx.ble.blelitelib.operation.BleOperation, java.lang.Runnable
|
||||
public void run() {
|
||||
BluetoothDevice remoteDevice = BleUtils.getRemoteDevice(this.mBleAddr);
|
||||
BleConnector connector = getConnector();
|
||||
if (connector == null) {
|
||||
connector = new BleConnector.Builder().build(this.mAppContext, remoteDevice).setGattCallback(this.mBluetoothGattCallback).create();
|
||||
setConnector(connector);
|
||||
}
|
||||
connector.connect();
|
||||
}
|
||||
}
|
@@ -0,0 +1,30 @@
|
||||
package com.afunx.ble.blelitelib.operation;
|
||||
|
||||
import android.bluetooth.BluetoothGatt;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public class BleDiscoverServiceOperation extends BleOperationAbs {
|
||||
private final BluetoothGatt mBluetoothGatt;
|
||||
|
||||
private BleDiscoverServiceOperation(BluetoothGatt bluetoothGatt) {
|
||||
this.mBluetoothGatt = bluetoothGatt;
|
||||
}
|
||||
|
||||
public static BleDiscoverServiceOperation createInstance(BluetoothGatt bluetoothGatt) {
|
||||
return new BleDiscoverServiceOperation(bluetoothGatt);
|
||||
}
|
||||
|
||||
@Override // com.afunx.ble.blelitelib.operation.BleOperationAbs
|
||||
protected void clearConcurrentOperation() {
|
||||
}
|
||||
|
||||
@Override // com.afunx.ble.blelitelib.operation.BleOperation
|
||||
public int getOperatcionCode() {
|
||||
return 3;
|
||||
}
|
||||
|
||||
@Override // com.afunx.ble.blelitelib.operation.BleOperation, java.lang.Runnable
|
||||
public void run() {
|
||||
this.mBluetoothGatt.discoverServices();
|
||||
}
|
||||
}
|
@@ -0,0 +1,5 @@
|
||||
package com.afunx.ble.blelitelib.operation;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public interface BleInterruptable {
|
||||
}
|
22
sources/com/afunx/ble/blelitelib/operation/BleOperation.java
Normal file
22
sources/com/afunx/ble/blelitelib/operation/BleOperation.java
Normal file
@@ -0,0 +1,22 @@
|
||||
package com.afunx.ble.blelitelib.operation;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public interface BleOperation extends Runnable {
|
||||
public static final int BLE_CLOSE = 2;
|
||||
public static final int BLE_CONNECT = 1;
|
||||
public static final int BLE_DISCOVER_SERVICE = 3;
|
||||
public static final int BLE_READ_CHARACTERISTIC = 4;
|
||||
public static final int BLE_REQUEST_MTU = 5;
|
||||
public static final int BLE_WRITE_CHARACTERISITC_NO_RESPONSE_PACKET = 10;
|
||||
public static final int BLE_WRITE_CHARACTERISITC_NO_RESPONSE_PACKET2 = 11;
|
||||
public static final int BLE_WRITE_CHARACTERISTIC = 6;
|
||||
public static final int BLE_WRITE_CHARACTERISTIC_NO_RESPONSE = 8;
|
||||
public static final int BLE_WRITE_CHARACTERISTIC_NO_RESPONSE_20 = 9;
|
||||
public static final int BLE_WRITE_CHARACTERISTIC_NO_RESPONSE_INTERRUPT = 12;
|
||||
public static final int BLE_WRITE_DESCRIPTOR = 7;
|
||||
|
||||
int getOperatcionCode();
|
||||
|
||||
@Override // java.lang.Runnable
|
||||
void run();
|
||||
}
|
156
sources/com/afunx/ble/blelitelib/operation/BleOperationAbs.java
Normal file
156
sources/com/afunx/ble/blelitelib/operation/BleOperationAbs.java
Normal file
@@ -0,0 +1,156 @@
|
||||
package com.afunx.ble.blelitelib.operation;
|
||||
|
||||
import android.bluetooth.BluetoothGattCallback;
|
||||
import android.os.Looper;
|
||||
import android.util.LongSparseArray;
|
||||
import android.util.SparseArray;
|
||||
import com.afunx.ble.blelitelib.connector.BleConnector;
|
||||
import com.afunx.ble.blelitelib.log.BleLiteLog;
|
||||
import com.afunx.ble.blelitelib.proxy.BleGattClientProxy;
|
||||
import com.afunx.ble.blelitelib.threadpool.BleThreadpool;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public abstract class BleOperationAbs<T> implements BleOperation {
|
||||
private static final String TAG = "BleOperationAbs";
|
||||
private BluetoothGattCallback mBluetoothGattCallback;
|
||||
private BleConnector mConnector;
|
||||
private BleGattClientProxy mOwner;
|
||||
private T mResult;
|
||||
private static final BleThreadpool sThreadpool = BleThreadpool.getInstance();
|
||||
private static final SparseArray<Future<?>> mInterruptableTasks = new SparseArray<>();
|
||||
private final LongSparseArray<Runnable> mRunnables = new LongSparseArray<>();
|
||||
private final BleOperationLock mLock = new BleOperationLock();
|
||||
|
||||
private void clearBleOperationAbs() {
|
||||
this.mRunnables.clear();
|
||||
this.mResult = null;
|
||||
this.mOwner = null;
|
||||
this.mConnector = null;
|
||||
this.mBluetoothGattCallback = null;
|
||||
}
|
||||
|
||||
private Runnable getRunnable(long j, boolean z) {
|
||||
Runnable runnable;
|
||||
synchronized (this.mRunnables) {
|
||||
runnable = this.mRunnables.get(j);
|
||||
if (z) {
|
||||
this.mRunnables.remove(j);
|
||||
}
|
||||
}
|
||||
return runnable;
|
||||
}
|
||||
|
||||
public final void clear() {
|
||||
BleLiteLog.v(TAG, "clear() called by " + this);
|
||||
clearConcurrentOperation();
|
||||
clearBleOperationAbs();
|
||||
}
|
||||
|
||||
protected abstract void clearConcurrentOperation();
|
||||
|
||||
public final void doRunnableAsync(long j, boolean z) {
|
||||
Runnable runnable = getRunnable(j, z);
|
||||
if (runnable != null) {
|
||||
sThreadpool.submit(runnable);
|
||||
}
|
||||
}
|
||||
|
||||
public final void doRunnableSelfAsync(boolean z) {
|
||||
if (!z) {
|
||||
sThreadpool.submit(this);
|
||||
} else {
|
||||
if (Looper.getMainLooper() == Looper.myLooper()) {
|
||||
throw new IllegalStateException("It can't be called in UI Main Thread.");
|
||||
}
|
||||
sThreadpool.submitInMain(this);
|
||||
}
|
||||
}
|
||||
|
||||
public final void doRunnableSelfAsyncInterruptable(int i) {
|
||||
if (Looper.getMainLooper() == Looper.myLooper()) {
|
||||
throw new IllegalStateException("It can't be called in UI Main Thread.");
|
||||
}
|
||||
if (!(this instanceof BleInterruptable)) {
|
||||
throw new IllegalArgumentException("Only BleInterruptable could call the method.");
|
||||
}
|
||||
synchronized (mInterruptableTasks) {
|
||||
Future<?> future = mInterruptableTasks.get(i);
|
||||
if (future != null) {
|
||||
future.cancel(true);
|
||||
}
|
||||
mInterruptableTasks.put(i, sThreadpool.submit(this));
|
||||
}
|
||||
}
|
||||
|
||||
public final void doRunnableUIAsync(long j, boolean z) {
|
||||
Runnable runnable = getRunnable(j, z);
|
||||
if (runnable != null) {
|
||||
sThreadpool.submitInMain(runnable);
|
||||
}
|
||||
}
|
||||
|
||||
public final BluetoothGattCallback getBluetoothGattCallback() {
|
||||
return this.mBluetoothGattCallback;
|
||||
}
|
||||
|
||||
public final BleConnector getConnector() {
|
||||
return this.mConnector;
|
||||
}
|
||||
|
||||
public final BleGattClientProxy getOwner() {
|
||||
return this.mOwner;
|
||||
}
|
||||
|
||||
public final T getResult() {
|
||||
return this.mResult;
|
||||
}
|
||||
|
||||
public final boolean isNotified() {
|
||||
return this.mLock.isNotified();
|
||||
}
|
||||
|
||||
public final void notifyLock() {
|
||||
this.mLock.notifyLock();
|
||||
}
|
||||
|
||||
public final void putRunnable(long j, Runnable runnable) {
|
||||
synchronized (this.mRunnables) {
|
||||
this.mRunnables.put(j, runnable);
|
||||
}
|
||||
}
|
||||
|
||||
public final void removeRunnable(long j) {
|
||||
synchronized (this.mRunnables) {
|
||||
this.mRunnables.remove(j);
|
||||
}
|
||||
}
|
||||
|
||||
public final void setBluetoothGattCallback(BluetoothGattCallback bluetoothGattCallback) {
|
||||
this.mBluetoothGattCallback = bluetoothGattCallback;
|
||||
}
|
||||
|
||||
public final void setConnector(BleConnector bleConnector) {
|
||||
this.mConnector = bleConnector;
|
||||
}
|
||||
|
||||
public final void setOwner(BleGattClientProxy bleGattClientProxy) {
|
||||
this.mOwner = bleGattClientProxy;
|
||||
}
|
||||
|
||||
public final void setResult(T t) {
|
||||
this.mResult = t;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return String.format("[%s-%d-%04x]", getClass().getSimpleName(), Integer.valueOf(hashCode()), Long.valueOf(getOperatcionCode()));
|
||||
}
|
||||
|
||||
public final void waitLock(long j) {
|
||||
this.mLock.waitLock(j);
|
||||
}
|
||||
|
||||
public final Runnable getRunnable(long j) {
|
||||
return getRunnable(j, false);
|
||||
}
|
||||
}
|
@@ -0,0 +1,28 @@
|
||||
package com.afunx.ble.blelitelib.operation;
|
||||
|
||||
import java.util.concurrent.Semaphore;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public class BleOperationLock {
|
||||
private final Semaphore mSemaphore = new Semaphore(0);
|
||||
private volatile boolean mIsNotified = false;
|
||||
|
||||
boolean isNotified() {
|
||||
return this.mIsNotified;
|
||||
}
|
||||
|
||||
void notifyLock() {
|
||||
this.mIsNotified = true;
|
||||
this.mSemaphore.release();
|
||||
}
|
||||
|
||||
void waitLock(long j) {
|
||||
try {
|
||||
this.mSemaphore.tryAcquire(1, j, TimeUnit.MILLISECONDS);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,33 @@
|
||||
package com.afunx.ble.blelitelib.operation;
|
||||
|
||||
import android.bluetooth.BluetoothGatt;
|
||||
import android.bluetooth.BluetoothGattCharacteristic;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public class BleReadCharacteristicOperation extends BleOperationAbs<byte[]> {
|
||||
private final BluetoothGatt mBluetoothGatt;
|
||||
private final BluetoothGattCharacteristic mGattCharacteristic;
|
||||
|
||||
private BleReadCharacteristicOperation(BluetoothGatt bluetoothGatt, BluetoothGattCharacteristic bluetoothGattCharacteristic) {
|
||||
this.mBluetoothGatt = bluetoothGatt;
|
||||
this.mGattCharacteristic = bluetoothGattCharacteristic;
|
||||
}
|
||||
|
||||
public static BleReadCharacteristicOperation createInstance(BluetoothGatt bluetoothGatt, BluetoothGattCharacteristic bluetoothGattCharacteristic) {
|
||||
return new BleReadCharacteristicOperation(bluetoothGatt, bluetoothGattCharacteristic);
|
||||
}
|
||||
|
||||
@Override // com.afunx.ble.blelitelib.operation.BleOperationAbs
|
||||
protected void clearConcurrentOperation() {
|
||||
}
|
||||
|
||||
@Override // com.afunx.ble.blelitelib.operation.BleOperation
|
||||
public int getOperatcionCode() {
|
||||
return 4;
|
||||
}
|
||||
|
||||
@Override // com.afunx.ble.blelitelib.operation.BleOperation, java.lang.Runnable
|
||||
public void run() {
|
||||
this.mBluetoothGatt.readCharacteristic(this.mGattCharacteristic);
|
||||
}
|
||||
}
|
@@ -0,0 +1,34 @@
|
||||
package com.afunx.ble.blelitelib.operation;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.bluetooth.BluetoothGatt;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public class BleRequestMtuOperation extends BleOperationAbs {
|
||||
private final BluetoothGatt mBluetoothGatt;
|
||||
private final int mMTU;
|
||||
|
||||
private BleRequestMtuOperation(BluetoothGatt bluetoothGatt, int i) {
|
||||
this.mBluetoothGatt = bluetoothGatt;
|
||||
this.mMTU = i;
|
||||
}
|
||||
|
||||
public static BleRequestMtuOperation createInstance(BluetoothGatt bluetoothGatt, int i) {
|
||||
return new BleRequestMtuOperation(bluetoothGatt, i);
|
||||
}
|
||||
|
||||
@Override // com.afunx.ble.blelitelib.operation.BleOperationAbs
|
||||
protected void clearConcurrentOperation() {
|
||||
}
|
||||
|
||||
@Override // com.afunx.ble.blelitelib.operation.BleOperation
|
||||
public int getOperatcionCode() {
|
||||
return 5;
|
||||
}
|
||||
|
||||
@Override // com.afunx.ble.blelitelib.operation.BleOperation, java.lang.Runnable
|
||||
@TargetApi(21)
|
||||
public void run() {
|
||||
this.mBluetoothGatt.requestMtu(this.mMTU);
|
||||
}
|
||||
}
|
@@ -0,0 +1,64 @@
|
||||
package com.afunx.ble.blelitelib.operation;
|
||||
|
||||
import android.bluetooth.BluetoothGatt;
|
||||
import android.bluetooth.BluetoothGattCharacteristic;
|
||||
import com.afunx.ble.blelitelib.log.BleLiteLog;
|
||||
import com.afunx.ble.blelitelib.utils.HexUtils;
|
||||
import java.util.Arrays;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public class BleWriteCharacterisitcNoResponsePacketOperation extends BleOperationAbs {
|
||||
private static final String TAG = "BleWriteCharacterisitcNoResponsePacketOperation";
|
||||
private final BluetoothGatt mBluetoothGatt;
|
||||
private final BluetoothGattCharacteristic mCharacteristic;
|
||||
private final byte[] mMsg;
|
||||
private final int mPacketInterval;
|
||||
private final int mPacketSize;
|
||||
|
||||
private BleWriteCharacterisitcNoResponsePacketOperation(BluetoothGatt bluetoothGatt, BluetoothGattCharacteristic bluetoothGattCharacteristic, byte[] bArr, int i, int i2) {
|
||||
this.mBluetoothGatt = bluetoothGatt;
|
||||
this.mCharacteristic = bluetoothGattCharacteristic;
|
||||
this.mMsg = bArr;
|
||||
this.mPacketSize = i;
|
||||
this.mPacketInterval = i2;
|
||||
}
|
||||
|
||||
public static BleWriteCharacterisitcNoResponsePacketOperation createInstance(BluetoothGatt bluetoothGatt, BluetoothGattCharacteristic bluetoothGattCharacteristic, byte[] bArr, int i, int i2) {
|
||||
return new BleWriteCharacterisitcNoResponsePacketOperation(bluetoothGatt, bluetoothGattCharacteristic, bArr, i, i2);
|
||||
}
|
||||
|
||||
@Override // com.afunx.ble.blelitelib.operation.BleOperationAbs
|
||||
protected void clearConcurrentOperation() {
|
||||
}
|
||||
|
||||
@Override // com.afunx.ble.blelitelib.operation.BleOperation
|
||||
public int getOperatcionCode() {
|
||||
return 10;
|
||||
}
|
||||
|
||||
@Override // com.afunx.ble.blelitelib.operation.BleOperation, java.lang.Runnable
|
||||
public void run() {
|
||||
this.mCharacteristic.setWriteType(1);
|
||||
int i = this.mPacketSize;
|
||||
int i2 = this.mPacketInterval;
|
||||
int length = this.mMsg.length;
|
||||
int i3 = 0;
|
||||
while (i3 < length) {
|
||||
int i4 = i3 + i;
|
||||
int i5 = i4 <= length ? i : length - i3;
|
||||
byte[] copyOfRange = Arrays.copyOfRange(this.mMsg, i3, i3 + i5);
|
||||
this.mCharacteristic.setValue(copyOfRange);
|
||||
this.mBluetoothGatt.writeCharacteristic(this.mCharacteristic);
|
||||
BleLiteLog.i(TAG, "writeCharacteristic() " + HexUtils.bytes2HexStringWithSpace(copyOfRange, 0, i5));
|
||||
if (i2 > 0) {
|
||||
try {
|
||||
Thread.sleep(i2);
|
||||
} catch (InterruptedException unused) {
|
||||
Thread.currentThread().interrupt();
|
||||
return;
|
||||
}
|
||||
}
|
||||
i3 = i4;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,102 @@
|
||||
package com.afunx.ble.blelitelib.operation;
|
||||
|
||||
import android.bluetooth.BluetoothGatt;
|
||||
import android.bluetooth.BluetoothGattCharacteristic;
|
||||
import com.afunx.ble.blelitelib.log.BleLiteLog;
|
||||
import com.afunx.ble.blelitelib.utils.HexUtils;
|
||||
import java.util.Arrays;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public class BleWriteCharacterisitcNoResponsePacketOperation2 extends BleOperationAbs {
|
||||
private static final int PACKET_SIZE = 20;
|
||||
private static final String TAG = "BleWriteCharacterisitcNoResponsePacketOperation2";
|
||||
private final BluetoothGatt mBluetoothGatt;
|
||||
private final BluetoothGattCharacteristic mCharacteristic;
|
||||
private final byte[] mMsg;
|
||||
private static int[] PACKET_INTERVALS = {5, 5, 5, 35};
|
||||
private static final AtomicInteger mAutoId = new AtomicInteger(0);
|
||||
private static volatile long lastTimestamp = 0;
|
||||
|
||||
private BleWriteCharacterisitcNoResponsePacketOperation2(BluetoothGatt bluetoothGatt, BluetoothGattCharacteristic bluetoothGattCharacteristic, byte[] bArr) {
|
||||
this.mBluetoothGatt = bluetoothGatt;
|
||||
this.mCharacteristic = bluetoothGattCharacteristic;
|
||||
this.mMsg = bArr;
|
||||
}
|
||||
|
||||
public static BleWriteCharacterisitcNoResponsePacketOperation2 createInstance(BluetoothGatt bluetoothGatt, BluetoothGattCharacteristic bluetoothGattCharacteristic, byte[] bArr) {
|
||||
return new BleWriteCharacterisitcNoResponsePacketOperation2(bluetoothGatt, bluetoothGattCharacteristic, bArr);
|
||||
}
|
||||
|
||||
public static void setPacketIntervals(int[] iArr) {
|
||||
PACKET_INTERVALS = iArr;
|
||||
}
|
||||
|
||||
private static void sleep() {
|
||||
int currentTimeMillis;
|
||||
synchronized (BleWriteCharacterisitcNoResponsePacketOperation2.class) {
|
||||
int andAdd = mAutoId.getAndAdd(1) % PACKET_INTERVALS.length;
|
||||
if (lastTimestamp == 0) {
|
||||
currentTimeMillis = 0;
|
||||
} else {
|
||||
currentTimeMillis = PACKET_INTERVALS[andAdd] - ((int) (System.currentTimeMillis() - lastTimestamp));
|
||||
}
|
||||
if (currentTimeMillis > 0) {
|
||||
try {
|
||||
BleWriteCharacterisitcNoResponsePacketOperation2.class.wait(currentTimeMillis);
|
||||
} catch (InterruptedException unused) {
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static synchronized void updateLastTimestamp() {
|
||||
synchronized (BleWriteCharacterisitcNoResponsePacketOperation2.class) {
|
||||
lastTimestamp = System.currentTimeMillis();
|
||||
}
|
||||
}
|
||||
|
||||
@Override // com.afunx.ble.blelitelib.operation.BleOperationAbs
|
||||
protected void clearConcurrentOperation() {
|
||||
}
|
||||
|
||||
@Override // com.afunx.ble.blelitelib.operation.BleOperation
|
||||
public int getOperatcionCode() {
|
||||
return 11;
|
||||
}
|
||||
|
||||
@Override // com.afunx.ble.blelitelib.operation.BleOperation, java.lang.Runnable
|
||||
public void run() {
|
||||
int length = this.mMsg.length;
|
||||
this.mCharacteristic.setWriteType(1);
|
||||
int i = 0;
|
||||
int i2 = 0;
|
||||
while (i < length) {
|
||||
sleep();
|
||||
int i3 = i + 20 <= length ? 20 : length - i;
|
||||
byte[] copyOfRange = Arrays.copyOfRange(this.mMsg, i, i + i3);
|
||||
this.mCharacteristic.setValue(copyOfRange);
|
||||
boolean writeCharacteristic = this.mBluetoothGatt.writeCharacteristic(this.mCharacteristic);
|
||||
if (writeCharacteristic) {
|
||||
i2 = 0;
|
||||
} else {
|
||||
i2++;
|
||||
if (i2 > 3) {
|
||||
BleLiteLog.e(TAG, "writeCharacteristic() fail");
|
||||
return;
|
||||
}
|
||||
i -= i3;
|
||||
try {
|
||||
Thread.sleep(50L);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
}
|
||||
BleLiteLog.i(TAG, "writeCharacteristic() " + HexUtils.bytes2HexStringWithSpace(copyOfRange, 0, i3) + ", isWriteSuc: " + writeCharacteristic);
|
||||
updateLastTimestamp();
|
||||
i += i3;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,59 @@
|
||||
package com.afunx.ble.blelitelib.operation;
|
||||
|
||||
import android.bluetooth.BluetoothGatt;
|
||||
import android.bluetooth.BluetoothGattCharacteristic;
|
||||
import android.util.Log;
|
||||
import com.afunx.ble.blelitelib.log.BleLiteLog;
|
||||
import com.afunx.ble.blelitelib.utils.HexUtils;
|
||||
import java.util.Arrays;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public class BleWriteCharacteristicNoResponse20Operation extends BleOperationAbs {
|
||||
private static final String TAG = "BleWriteCharacteristicNoResponse20Operation";
|
||||
private static final int TWEENTY = 20;
|
||||
private final BluetoothGatt mBluetoothGatt;
|
||||
private final BluetoothGattCharacteristic mCharacteristic;
|
||||
private final byte[] mMsg;
|
||||
|
||||
private BleWriteCharacteristicNoResponse20Operation(BluetoothGatt bluetoothGatt, BluetoothGattCharacteristic bluetoothGattCharacteristic, byte[] bArr) {
|
||||
this.mBluetoothGatt = bluetoothGatt;
|
||||
this.mCharacteristic = bluetoothGattCharacteristic;
|
||||
this.mMsg = bArr;
|
||||
Log.e("NoResponse20Operation", "msg: " + HexUtils.bytes2HexStringWithSpace(bArr));
|
||||
}
|
||||
|
||||
public static BleWriteCharacteristicNoResponse20Operation createInstance(BluetoothGatt bluetoothGatt, BluetoothGattCharacteristic bluetoothGattCharacteristic, byte[] bArr) {
|
||||
return new BleWriteCharacteristicNoResponse20Operation(bluetoothGatt, bluetoothGattCharacteristic, bArr);
|
||||
}
|
||||
|
||||
@Override // com.afunx.ble.blelitelib.operation.BleOperationAbs
|
||||
protected void clearConcurrentOperation() {
|
||||
}
|
||||
|
||||
@Override // com.afunx.ble.blelitelib.operation.BleOperation
|
||||
public int getOperatcionCode() {
|
||||
return 9;
|
||||
}
|
||||
|
||||
@Override // com.afunx.ble.blelitelib.operation.BleOperation, java.lang.Runnable
|
||||
public void run() {
|
||||
this.mCharacteristic.setWriteType(1);
|
||||
int length = this.mMsg.length;
|
||||
int i = 0;
|
||||
while (i < length) {
|
||||
int i2 = i + 20;
|
||||
int i3 = i2 <= length ? 20 : length - i;
|
||||
byte[] copyOfRange = Arrays.copyOfRange(this.mMsg, i, i + i3);
|
||||
this.mCharacteristic.setValue(copyOfRange);
|
||||
this.mBluetoothGatt.writeCharacteristic(this.mCharacteristic);
|
||||
BleLiteLog.i(TAG, "writeCharacteristic() " + HexUtils.bytes2HexStringWithSpace(copyOfRange, 0, i3));
|
||||
try {
|
||||
Thread.sleep(2L);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
i = i2;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,192 @@
|
||||
package com.afunx.ble.blelitelib.operation;
|
||||
|
||||
import android.bluetooth.BluetoothGatt;
|
||||
import android.bluetooth.BluetoothGattCharacteristic;
|
||||
import com.afunx.ble.blelitelib.log.BleLiteLog;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public class BleWriteCharacteristicNoResponseInterruptOperation extends BleOperationAbs implements BleInterruptable {
|
||||
private static final int PACKET_SIZE = 20;
|
||||
private static final String TAG = "BleWriteCharacteristicNoResponseInterruptOperation";
|
||||
private final BluetoothGatt mBluetoothGatt;
|
||||
private final BluetoothGattCharacteristic mCharacteristic;
|
||||
private final byte[] mMsg;
|
||||
private static int[] PACKET_INTERVALS = {5, 5, 5, 35};
|
||||
private static final AtomicInteger mAutoId = new AtomicInteger(0);
|
||||
private static volatile long lastTimestamp = 0;
|
||||
private static final Map<UUID, byte[][]> mBufferMap = new HashMap();
|
||||
|
||||
private BleWriteCharacteristicNoResponseInterruptOperation(BluetoothGatt bluetoothGatt, BluetoothGattCharacteristic bluetoothGattCharacteristic, byte[] bArr) {
|
||||
this.mBluetoothGatt = bluetoothGatt;
|
||||
this.mCharacteristic = bluetoothGattCharacteristic;
|
||||
this.mMsg = bArr;
|
||||
}
|
||||
|
||||
public static BleWriteCharacteristicNoResponseInterruptOperation createInstance(BluetoothGatt bluetoothGatt, BluetoothGattCharacteristic bluetoothGattCharacteristic, byte[] bArr) {
|
||||
return new BleWriteCharacteristicNoResponseInterruptOperation(bluetoothGatt, bluetoothGattCharacteristic, bArr);
|
||||
}
|
||||
|
||||
private static byte[][] getBuffer20(UUID uuid, int i) {
|
||||
byte[][] bArr = mBufferMap.get(uuid);
|
||||
if (bArr == null) {
|
||||
bArr = new byte[i][];
|
||||
int i2 = 0;
|
||||
while (i2 < bArr.length) {
|
||||
int i3 = i2 + 1;
|
||||
bArr[i2] = new byte[i3];
|
||||
i2 = i3;
|
||||
}
|
||||
mBufferMap.put(uuid, bArr);
|
||||
}
|
||||
return bArr;
|
||||
}
|
||||
|
||||
private static byte[] getSendMessage(UUID uuid, int i, byte[] bArr, int i2, int i3) {
|
||||
byte[][] buffer20 = getBuffer20(uuid, i);
|
||||
int i4 = i3 - 1;
|
||||
System.arraycopy(bArr, i2, buffer20[i4], 0, i3);
|
||||
return buffer20[i4];
|
||||
}
|
||||
|
||||
private static boolean sleep() {
|
||||
synchronized (BleWriteCharacteristicNoResponseInterruptOperation.class) {
|
||||
int currentTimeMillis = PACKET_INTERVALS[mAutoId.getAndAdd(1) % PACKET_INTERVALS.length] - ((int) (System.currentTimeMillis() - lastTimestamp));
|
||||
if (currentTimeMillis <= 0) {
|
||||
return Thread.interrupted();
|
||||
}
|
||||
try {
|
||||
BleWriteCharacteristicNoResponseInterruptOperation.class.wait(currentTimeMillis);
|
||||
return false;
|
||||
} catch (InterruptedException unused) {
|
||||
BleLiteLog.e(TAG, "sleep() is interrupted, return true");
|
||||
Thread.currentThread().interrupt();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static synchronized void updateLastTimestamp() {
|
||||
synchronized (BleWriteCharacteristicNoResponseInterruptOperation.class) {
|
||||
lastTimestamp = System.currentTimeMillis();
|
||||
}
|
||||
}
|
||||
|
||||
@Override // com.afunx.ble.blelitelib.operation.BleOperationAbs
|
||||
protected void clearConcurrentOperation() {
|
||||
}
|
||||
|
||||
@Override // com.afunx.ble.blelitelib.operation.BleOperation
|
||||
public int getOperatcionCode() {
|
||||
return 12;
|
||||
}
|
||||
|
||||
/* JADX WARN: Code restructure failed: missing block: B:34:0x0019, code lost:
|
||||
|
||||
com.afunx.ble.blelitelib.operation.BleWriteCharacteristicNoResponseInterruptOperation.mAutoId.wait(50);
|
||||
*/
|
||||
@Override // com.afunx.ble.blelitelib.operation.BleOperation, java.lang.Runnable
|
||||
/*
|
||||
Code decompiled incorrectly, please refer to instructions dump.
|
||||
To view partially-correct code enable 'Show inconsistent code' option in preferences
|
||||
*/
|
||||
public void run() {
|
||||
/*
|
||||
r12 = this;
|
||||
byte[] r0 = r12.mMsg
|
||||
int r0 = r0.length
|
||||
java.util.concurrent.atomic.AtomicInteger r1 = com.afunx.ble.blelitelib.operation.BleWriteCharacteristicNoResponseInterruptOperation.mAutoId
|
||||
monitor-enter(r1)
|
||||
android.bluetooth.BluetoothGattCharacteristic r2 = r12.mCharacteristic // Catch: java.lang.Throwable -> La4
|
||||
r3 = 1
|
||||
r2.setWriteType(r3) // Catch: java.lang.Throwable -> La4
|
||||
r2 = 0
|
||||
r4 = 0
|
||||
r5 = 0
|
||||
Lf:
|
||||
if (r4 >= r0) goto La2
|
||||
boolean r6 = sleep() // Catch: java.lang.Throwable -> La4
|
||||
r7 = 50
|
||||
if (r6 == 0) goto L2e
|
||||
java.util.concurrent.atomic.AtomicInteger r0 = com.afunx.ble.blelitelib.operation.BleWriteCharacteristicNoResponseInterruptOperation.mAutoId // Catch: java.lang.InterruptedException -> L1f java.lang.Throwable -> La4
|
||||
r0.wait(r7) // Catch: java.lang.InterruptedException -> L1f java.lang.Throwable -> La4
|
||||
goto L2a
|
||||
L1f:
|
||||
r0 = move-exception
|
||||
r0.printStackTrace() // Catch: java.lang.Throwable -> La4
|
||||
java.lang.Thread r0 = java.lang.Thread.currentThread() // Catch: java.lang.Throwable -> La4
|
||||
r0.interrupt() // Catch: java.lang.Throwable -> La4
|
||||
L2a:
|
||||
updateLastTimestamp() // Catch: java.lang.Throwable -> La4
|
||||
goto La2
|
||||
L2e:
|
||||
int r6 = r4 + 20
|
||||
r9 = 20
|
||||
if (r6 > r0) goto L37
|
||||
r6 = 20
|
||||
goto L39
|
||||
L37:
|
||||
int r6 = r0 - r4
|
||||
L39:
|
||||
android.bluetooth.BluetoothGattCharacteristic r10 = r12.mCharacteristic // Catch: java.lang.Throwable -> La4
|
||||
java.util.UUID r10 = r10.getUuid() // Catch: java.lang.Throwable -> La4
|
||||
byte[] r11 = r12.mMsg // Catch: java.lang.Throwable -> La4
|
||||
byte[] r9 = getSendMessage(r10, r9, r11, r4, r6) // Catch: java.lang.Throwable -> La4
|
||||
android.bluetooth.BluetoothGattCharacteristic r10 = r12.mCharacteristic // Catch: java.lang.Throwable -> La4
|
||||
r10.setValue(r9) // Catch: java.lang.Throwable -> La4
|
||||
android.bluetooth.BluetoothGatt r10 = r12.mBluetoothGatt // Catch: java.lang.Throwable -> La4
|
||||
android.bluetooth.BluetoothGattCharacteristic r11 = r12.mCharacteristic // Catch: java.lang.Throwable -> La4
|
||||
boolean r10 = r10.writeCharacteristic(r11) // Catch: java.lang.Throwable -> La4
|
||||
if (r10 == 0) goto L56
|
||||
r5 = 0
|
||||
goto L69
|
||||
L56:
|
||||
int r5 = r5 + r3
|
||||
r11 = 3
|
||||
if (r5 <= r11) goto L63
|
||||
java.lang.String r0 = "BleWriteCharacteristicNoResponseInterruptOperation"
|
||||
java.lang.String r2 = "writeCharacteristic() fail"
|
||||
com.afunx.ble.blelitelib.log.BleLiteLog.e(r0, r2) // Catch: java.lang.Throwable -> La4
|
||||
monitor-exit(r1) // Catch: java.lang.Throwable -> La4
|
||||
return
|
||||
L63:
|
||||
int r4 = r4 - r6
|
||||
java.util.concurrent.atomic.AtomicInteger r11 = com.afunx.ble.blelitelib.operation.BleWriteCharacteristicNoResponseInterruptOperation.mAutoId // Catch: java.lang.InterruptedException -> L91 java.lang.Throwable -> La4
|
||||
r11.wait(r7) // Catch: java.lang.InterruptedException -> L91 java.lang.Throwable -> La4
|
||||
L69:
|
||||
java.lang.String r7 = "BleWriteCharacteristicNoResponseInterruptOperation"
|
||||
java.lang.StringBuilder r8 = new java.lang.StringBuilder // Catch: java.lang.Throwable -> La4
|
||||
r8.<init>() // Catch: java.lang.Throwable -> La4
|
||||
java.lang.String r11 = "writeCharacteristic() "
|
||||
r8.append(r11) // Catch: java.lang.Throwable -> La4
|
||||
java.lang.String r9 = com.afunx.ble.blelitelib.utils.HexUtils.bytes2HexStringWithSpace(r9, r2, r6) // Catch: java.lang.Throwable -> La4
|
||||
r8.append(r9) // Catch: java.lang.Throwable -> La4
|
||||
java.lang.String r9 = ", isWriteSuc: "
|
||||
r8.append(r9) // Catch: java.lang.Throwable -> La4
|
||||
r8.append(r10) // Catch: java.lang.Throwable -> La4
|
||||
java.lang.String r8 = r8.toString() // Catch: java.lang.Throwable -> La4
|
||||
com.afunx.ble.blelitelib.log.BleLiteLog.i(r7, r8) // Catch: java.lang.Throwable -> La4
|
||||
updateLastTimestamp() // Catch: java.lang.Throwable -> La4
|
||||
int r4 = r4 + r6
|
||||
goto Lf
|
||||
L91:
|
||||
java.lang.String r0 = "BleWriteCharacteristicNoResponseInterruptOperation"
|
||||
java.lang.String r2 = "sleep() is interrupted, break"
|
||||
com.afunx.ble.blelitelib.log.BleLiteLog.e(r0, r2) // Catch: java.lang.Throwable -> La4
|
||||
updateLastTimestamp() // Catch: java.lang.Throwable -> La4
|
||||
java.lang.Thread r0 = java.lang.Thread.currentThread() // Catch: java.lang.Throwable -> La4
|
||||
r0.interrupt() // Catch: java.lang.Throwable -> La4
|
||||
La2:
|
||||
monitor-exit(r1) // Catch: java.lang.Throwable -> La4
|
||||
return
|
||||
La4:
|
||||
r0 = move-exception
|
||||
monitor-exit(r1) // Catch: java.lang.Throwable -> La4
|
||||
throw r0
|
||||
*/
|
||||
throw new UnsupportedOperationException("Method not decompiled: com.afunx.ble.blelitelib.operation.BleWriteCharacteristicNoResponseInterruptOperation.run():void");
|
||||
}
|
||||
}
|
@@ -0,0 +1,54 @@
|
||||
package com.afunx.ble.blelitelib.operation;
|
||||
|
||||
import android.bluetooth.BluetoothGatt;
|
||||
import android.bluetooth.BluetoothGattCharacteristic;
|
||||
import com.afunx.ble.blelitelib.log.BleLiteLog;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public class BleWriteCharacteristicNoResponseOperation extends BleOperationAbs {
|
||||
private static final String TAG = "BleWriteCharacteristicNoResponseOperation";
|
||||
private final BluetoothGatt mBluetoothGatt;
|
||||
private final BluetoothGattCharacteristic mCharacteristic;
|
||||
private final byte[] mMsg;
|
||||
|
||||
private BleWriteCharacteristicNoResponseOperation(BluetoothGatt bluetoothGatt, BluetoothGattCharacteristic bluetoothGattCharacteristic, byte[] bArr) {
|
||||
this.mBluetoothGatt = bluetoothGatt;
|
||||
this.mCharacteristic = bluetoothGattCharacteristic;
|
||||
this.mMsg = bArr;
|
||||
}
|
||||
|
||||
public static BleWriteCharacteristicNoResponseOperation createInstance(BluetoothGatt bluetoothGatt, BluetoothGattCharacteristic bluetoothGattCharacteristic, byte[] bArr) {
|
||||
return new BleWriteCharacteristicNoResponseOperation(bluetoothGatt, bluetoothGattCharacteristic, bArr);
|
||||
}
|
||||
|
||||
@Override // com.afunx.ble.blelitelib.operation.BleOperationAbs
|
||||
protected void clearConcurrentOperation() {
|
||||
}
|
||||
|
||||
@Override // com.afunx.ble.blelitelib.operation.BleOperation
|
||||
public int getOperatcionCode() {
|
||||
return 8;
|
||||
}
|
||||
|
||||
@Override // com.afunx.ble.blelitelib.operation.BleOperation, java.lang.Runnable
|
||||
public void run() {
|
||||
this.mCharacteristic.setValue(this.mMsg);
|
||||
this.mCharacteristic.setWriteType(1);
|
||||
boolean z = false;
|
||||
for (int i = 0; !z && i < 3; i++) {
|
||||
if (i > 0) {
|
||||
try {
|
||||
Thread.sleep(50L);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
}
|
||||
z = this.mBluetoothGatt.writeCharacteristic(this.mCharacteristic);
|
||||
}
|
||||
if (z) {
|
||||
return;
|
||||
}
|
||||
BleLiteLog.e(TAG, "writeCharacteristic() fail");
|
||||
}
|
||||
}
|
@@ -0,0 +1,36 @@
|
||||
package com.afunx.ble.blelitelib.operation;
|
||||
|
||||
import android.bluetooth.BluetoothGatt;
|
||||
import android.bluetooth.BluetoothGattCharacteristic;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public class BleWriteCharacteristicOperation extends BleOperationAbs {
|
||||
private final BluetoothGatt mBluetoothGatt;
|
||||
private final BluetoothGattCharacteristic mCharacteristic;
|
||||
private final byte[] mMsg;
|
||||
|
||||
private BleWriteCharacteristicOperation(BluetoothGatt bluetoothGatt, BluetoothGattCharacteristic bluetoothGattCharacteristic, byte[] bArr) {
|
||||
this.mBluetoothGatt = bluetoothGatt;
|
||||
this.mCharacteristic = bluetoothGattCharacteristic;
|
||||
this.mMsg = bArr;
|
||||
}
|
||||
|
||||
public static BleWriteCharacteristicOperation createInstance(BluetoothGatt bluetoothGatt, BluetoothGattCharacteristic bluetoothGattCharacteristic, byte[] bArr) {
|
||||
return new BleWriteCharacteristicOperation(bluetoothGatt, bluetoothGattCharacteristic, bArr);
|
||||
}
|
||||
|
||||
@Override // com.afunx.ble.blelitelib.operation.BleOperationAbs
|
||||
protected void clearConcurrentOperation() {
|
||||
}
|
||||
|
||||
@Override // com.afunx.ble.blelitelib.operation.BleOperation
|
||||
public int getOperatcionCode() {
|
||||
return 6;
|
||||
}
|
||||
|
||||
@Override // com.afunx.ble.blelitelib.operation.BleOperation, java.lang.Runnable
|
||||
public void run() {
|
||||
this.mCharacteristic.setValue(this.mMsg);
|
||||
this.mBluetoothGatt.writeCharacteristic(this.mCharacteristic);
|
||||
}
|
||||
}
|
@@ -0,0 +1,36 @@
|
||||
package com.afunx.ble.blelitelib.operation;
|
||||
|
||||
import android.bluetooth.BluetoothGatt;
|
||||
import android.bluetooth.BluetoothGattDescriptor;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public class BleWriteDescriptorOperation extends BleOperationAbs {
|
||||
private final BluetoothGatt mBluetoothGatt;
|
||||
private final BluetoothGattDescriptor mDescriptor;
|
||||
private final byte[] mMsg;
|
||||
|
||||
private BleWriteDescriptorOperation(BluetoothGatt bluetoothGatt, BluetoothGattDescriptor bluetoothGattDescriptor, byte[] bArr) {
|
||||
this.mBluetoothGatt = bluetoothGatt;
|
||||
this.mDescriptor = bluetoothGattDescriptor;
|
||||
this.mMsg = bArr;
|
||||
}
|
||||
|
||||
public static BleWriteDescriptorOperation createInstance(BluetoothGatt bluetoothGatt, BluetoothGattDescriptor bluetoothGattDescriptor, byte[] bArr) {
|
||||
return new BleWriteDescriptorOperation(bluetoothGatt, bluetoothGattDescriptor, bArr);
|
||||
}
|
||||
|
||||
@Override // com.afunx.ble.blelitelib.operation.BleOperationAbs
|
||||
protected void clearConcurrentOperation() {
|
||||
}
|
||||
|
||||
@Override // com.afunx.ble.blelitelib.operation.BleOperation
|
||||
public int getOperatcionCode() {
|
||||
return 7;
|
||||
}
|
||||
|
||||
@Override // com.afunx.ble.blelitelib.operation.BleOperation, java.lang.Runnable
|
||||
public void run() {
|
||||
this.mDescriptor.setValue(this.mMsg);
|
||||
this.mBluetoothGatt.writeDescriptor(this.mDescriptor);
|
||||
}
|
||||
}
|
@@ -0,0 +1,48 @@
|
||||
package com.afunx.ble.blelitelib.proxy;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.bluetooth.BluetoothGattCharacteristic;
|
||||
import android.bluetooth.BluetoothGattService;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public interface BleGattClientProxy {
|
||||
|
||||
public interface OnCharacteristicNotificationListener {
|
||||
void onCharacteristicNotification(byte[] bArr);
|
||||
}
|
||||
|
||||
void close();
|
||||
|
||||
boolean connect(String str, long j);
|
||||
|
||||
BluetoothGattCharacteristic discoverCharacteristic(BluetoothGattService bluetoothGattService, UUID uuid);
|
||||
|
||||
BluetoothGattService discoverService(UUID uuid, long j);
|
||||
|
||||
List<BluetoothGattService> discoverServices(long j);
|
||||
|
||||
byte[] readCharacteristic(BluetoothGattCharacteristic bluetoothGattCharacteristic, long j);
|
||||
|
||||
boolean registerCharacteristicNotification(BluetoothGattCharacteristic bluetoothGattCharacteristic, OnCharacteristicNotificationListener onCharacteristicNotificationListener);
|
||||
|
||||
@TargetApi(21)
|
||||
boolean requestMtu(int i, long j);
|
||||
|
||||
void setDisconnectCallback(Runnable runnable, long j);
|
||||
|
||||
void unregisterCharacteristicNotification(UUID uuid);
|
||||
|
||||
boolean writeCharacterisitcNoResponse2(BluetoothGattCharacteristic bluetoothGattCharacteristic, byte[] bArr);
|
||||
|
||||
boolean writeCharacteristic(BluetoothGattCharacteristic bluetoothGattCharacteristic, byte[] bArr, long j);
|
||||
|
||||
boolean writeCharacteristicNoResponse(BluetoothGattCharacteristic bluetoothGattCharacteristic, byte[] bArr, long j);
|
||||
|
||||
boolean writeCharacteristicNoResponse20(BluetoothGattCharacteristic bluetoothGattCharacteristic, byte[] bArr);
|
||||
|
||||
boolean writeCharacteristicNoResponsePacket(BluetoothGattCharacteristic bluetoothGattCharacteristic, byte[] bArr, int i, int i2);
|
||||
|
||||
boolean writeCharacteristicNoResponsePreemptible(BluetoothGattCharacteristic bluetoothGattCharacteristic, byte[] bArr);
|
||||
}
|
@@ -0,0 +1,613 @@
|
||||
package com.afunx.ble.blelitelib.proxy;
|
||||
|
||||
import android.bluetooth.BluetoothGatt;
|
||||
import android.bluetooth.BluetoothGattCallback;
|
||||
import android.bluetooth.BluetoothGattCharacteristic;
|
||||
import android.bluetooth.BluetoothGattDescriptor;
|
||||
import android.bluetooth.BluetoothGattService;
|
||||
import android.content.Context;
|
||||
import android.os.Build;
|
||||
import android.util.Log;
|
||||
import android.util.LongSparseArray;
|
||||
import com.afunx.ble.blelitelib.connector.BleConnector;
|
||||
import com.afunx.ble.blelitelib.log.BleLiteLog;
|
||||
import com.afunx.ble.blelitelib.operation.BleCloseOperation;
|
||||
import com.afunx.ble.blelitelib.operation.BleConnectOperation;
|
||||
import com.afunx.ble.blelitelib.operation.BleDiscoverServiceOperation;
|
||||
import com.afunx.ble.blelitelib.operation.BleOperation;
|
||||
import com.afunx.ble.blelitelib.operation.BleReadCharacteristicOperation;
|
||||
import com.afunx.ble.blelitelib.operation.BleRequestMtuOperation;
|
||||
import com.afunx.ble.blelitelib.operation.BleWriteCharacterisitcNoResponsePacketOperation;
|
||||
import com.afunx.ble.blelitelib.operation.BleWriteCharacterisitcNoResponsePacketOperation2;
|
||||
import com.afunx.ble.blelitelib.operation.BleWriteCharacteristicNoResponse20Operation;
|
||||
import com.afunx.ble.blelitelib.operation.BleWriteCharacteristicNoResponseInterruptOperation;
|
||||
import com.afunx.ble.blelitelib.operation.BleWriteCharacteristicNoResponseOperation;
|
||||
import com.afunx.ble.blelitelib.operation.BleWriteCharacteristicOperation;
|
||||
import com.afunx.ble.blelitelib.operation.BleWriteDescriptorOperation;
|
||||
import com.afunx.ble.blelitelib.proxy.BleGattClientProxy;
|
||||
import com.afunx.ble.blelitelib.proxy.scheme.BleGattReconnectScheme;
|
||||
import com.afunx.ble.blelitelib.proxy.scheme.BleGattReconnectSchemeDefaultImpl;
|
||||
import com.afunx.ble.blelitelib.threadpool.BleThreadpool;
|
||||
import com.afunx.ble.blelitelib.utils.BleGattStateParser;
|
||||
import com.afunx.ble.blelitelib.utils.BleGattStatusParser;
|
||||
import com.afunx.ble.blelitelib.utils.BleUuidUtils;
|
||||
import com.afunx.ble.blelitelib.utils.HexUtils;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public class BleGattClientProxyImpl implements BleGattClientProxy {
|
||||
private static final String TAG = "BleGattClientProxyImpl";
|
||||
private static final String UUID_CLIENT_CHARACTERISTIC_CONFIG_DESCRIPTOR = "00002902-0000-1000-8000-00805f9b34fb";
|
||||
private static final String VERSION = "v0.9.5";
|
||||
private final Context mAppContext;
|
||||
private BleConnector mBleConnector;
|
||||
private volatile boolean mIsClosed = false;
|
||||
private final LongSparseArray<BleOperation> mOperations = new LongSparseArray<>();
|
||||
private final LongSparseArray<BleGattClientProxy.OnCharacteristicNotificationListener> mListeners = new LongSparseArray<>();
|
||||
private final BleGattReconnectScheme mReconnectScheme = new BleGattReconnectSchemeDefaultImpl();
|
||||
private final Object mLock4Connect = new Object();
|
||||
private final Object mLock4Close = new Object();
|
||||
private BluetoothGattCallback mBluetoothGattCallback = new BluetoothGattCallback() { // from class: com.afunx.ble.blelitelib.proxy.BleGattClientProxyImpl.1
|
||||
@Override // android.bluetooth.BluetoothGattCallback
|
||||
public void onCharacteristicChanged(BluetoothGatt bluetoothGatt, BluetoothGattCharacteristic bluetoothGattCharacteristic) {
|
||||
UUID uuid = bluetoothGattCharacteristic.getUuid();
|
||||
byte[] value = bluetoothGattCharacteristic.getValue();
|
||||
BleLiteLog.i(BleGattClientProxyImpl.TAG, "onCharacteristicChanged() characteristic uuid: " + uuid + " msg: " + HexUtils.bytes2HexStringWithSpace(value));
|
||||
BleGattClientProxy.OnCharacteristicNotificationListener listener = BleGattClientProxyImpl.this.getListener(uuid);
|
||||
if (listener != null) {
|
||||
listener.onCharacteristicNotification(value);
|
||||
}
|
||||
}
|
||||
|
||||
@Override // android.bluetooth.BluetoothGattCallback
|
||||
public void onCharacteristicRead(BluetoothGatt bluetoothGatt, BluetoothGattCharacteristic bluetoothGattCharacteristic, int i) {
|
||||
BleLiteLog.i(BleGattClientProxyImpl.TAG, "onCharacteristicRead() characteristic uuid: " + bluetoothGattCharacteristic.getUuid() + ", status: " + BleGattStatusParser.parse(i));
|
||||
BleReadCharacteristicOperation readCharacteristicOperation = BleGattClientProxyImpl.this.getReadCharacteristicOperation();
|
||||
if (i != 0 || readCharacteristicOperation == null) {
|
||||
return;
|
||||
}
|
||||
readCharacteristicOperation.setResult(bluetoothGattCharacteristic.getValue());
|
||||
readCharacteristicOperation.notifyLock();
|
||||
}
|
||||
|
||||
@Override // android.bluetooth.BluetoothGattCallback
|
||||
public void onCharacteristicWrite(BluetoothGatt bluetoothGatt, BluetoothGattCharacteristic bluetoothGattCharacteristic, int i) {
|
||||
BleLiteLog.i(BleGattClientProxyImpl.TAG, "onCharacteristicWrite() characteristic uuid: " + bluetoothGattCharacteristic.getUuid() + ", status: " + BleGattStatusParser.parse(i));
|
||||
BleWriteCharacteristicOperation writeCharacteristicOperation = BleGattClientProxyImpl.this.getWriteCharacteristicOperation();
|
||||
if (i != 0 || writeCharacteristicOperation == null) {
|
||||
return;
|
||||
}
|
||||
writeCharacteristicOperation.notifyLock();
|
||||
}
|
||||
|
||||
@Override // android.bluetooth.BluetoothGattCallback
|
||||
public void onConnectionStateChange(BluetoothGatt bluetoothGatt, int i, int i2) {
|
||||
BleLiteLog.i(BleGattClientProxyImpl.TAG, "onConnectionStateChange() status: " + BleGattStatusParser.parse(i) + ", newState: " + BleGattStateParser.parse(i2));
|
||||
BleConnectOperation connectOperation = BleGattClientProxyImpl.this.getConnectOperation();
|
||||
if (i2 != 0) {
|
||||
if (i2 == 1 || i2 != 2) {
|
||||
return;
|
||||
}
|
||||
BleGattClientProxyImpl.this.mReconnectScheme.clearRetryCount();
|
||||
if (connectOperation != null) {
|
||||
connectOperation.notifyLock();
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
synchronized (BleGattClientProxyImpl.this.mLock4Close) {
|
||||
if (!BleGattClientProxyImpl.this.mIsClosed) {
|
||||
if (!BleGattClientProxyImpl.this.mReconnectScheme.tryAgain()) {
|
||||
BleLiteLog.w(BleGattClientProxyImpl.TAG, "onConnectionStateChange() stop reconnect");
|
||||
return;
|
||||
}
|
||||
if (i == 8) {
|
||||
BleGattClientProxyImpl.this.mReconnectScheme.callDisconnectCallbackInstantly();
|
||||
BleGattClientProxyImpl.this.__close();
|
||||
} else {
|
||||
final long sleepTimestamp = BleGattClientProxyImpl.this.mReconnectScheme.getSleepTimestamp(BleGattClientProxyImpl.this.mReconnectScheme.addAndGetRetryCount());
|
||||
BleThreadpool.getInstance().submit(new Runnable() { // from class: com.afunx.ble.blelitelib.proxy.BleGattClientProxyImpl.1.1
|
||||
@Override // java.lang.Runnable
|
||||
public void run() {
|
||||
try {
|
||||
Thread.sleep(sleepTimestamp);
|
||||
} catch (InterruptedException unused) {
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
BleConnectOperation connectOperation2 = BleGattClientProxyImpl.this.getConnectOperation();
|
||||
if (connectOperation2 == null) {
|
||||
BleLiteLog.i(BleGattClientProxyImpl.TAG, "onConnectionStateChange() connectOperation is null");
|
||||
} else {
|
||||
BleLiteLog.i(BleGattClientProxyImpl.TAG, "onConnectionStateChange() reconnect...");
|
||||
connectOperation2.doRunnableSelfAsync(true);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override // android.bluetooth.BluetoothGattCallback
|
||||
public void onDescriptorWrite(BluetoothGatt bluetoothGatt, BluetoothGattDescriptor bluetoothGattDescriptor, int i) {
|
||||
BleLiteLog.i(BleGattClientProxyImpl.TAG, "onDescriptorWrite() characteristic uuid: " + bluetoothGattDescriptor.getUuid());
|
||||
BleWriteDescriptorOperation writeDescriptorOperation = BleGattClientProxyImpl.this.getWriteDescriptorOperation();
|
||||
if (i != 0 || writeDescriptorOperation == null) {
|
||||
return;
|
||||
}
|
||||
writeDescriptorOperation.notifyLock();
|
||||
}
|
||||
|
||||
@Override // android.bluetooth.BluetoothGattCallback
|
||||
public void onMtuChanged(BluetoothGatt bluetoothGatt, int i, int i2) {
|
||||
BleLiteLog.i(BleGattClientProxyImpl.TAG, "onMtuChanged() mtu: " + i + ", status: " + BleGattStatusParser.parse(i2));
|
||||
BleRequestMtuOperation requestMtuOperation = BleGattClientProxyImpl.this.getRequestMtuOperation();
|
||||
if (i2 != 0 || requestMtuOperation == null) {
|
||||
return;
|
||||
}
|
||||
requestMtuOperation.notifyLock();
|
||||
}
|
||||
|
||||
@Override // android.bluetooth.BluetoothGattCallback
|
||||
public void onServicesDiscovered(BluetoothGatt bluetoothGatt, int i) {
|
||||
BleLiteLog.i(BleGattClientProxyImpl.TAG, "onServicesDiscovered() status: " + BleGattStatusParser.parse(i));
|
||||
BleDiscoverServiceOperation discoverServiceOperation = BleGattClientProxyImpl.this.getDiscoverServiceOperation();
|
||||
if (i != 0 || discoverServiceOperation == null) {
|
||||
return;
|
||||
}
|
||||
discoverServiceOperation.notifyLock();
|
||||
}
|
||||
};
|
||||
|
||||
public BleGattClientProxyImpl(Context context) {
|
||||
Log.i(TAG, "blelitelib version: v0.9.5");
|
||||
this.mAppContext = context.getApplicationContext();
|
||||
}
|
||||
|
||||
/* JADX INFO: Access modifiers changed from: private */
|
||||
public void __close() {
|
||||
if (this.mIsClosed) {
|
||||
BleLiteLog.i(TAG, "__close() it is closed already");
|
||||
return;
|
||||
}
|
||||
this.mIsClosed = true;
|
||||
BleLiteLog.i(TAG, "__close() closing");
|
||||
unregister(1L);
|
||||
unregister(3L);
|
||||
unregister(5L);
|
||||
unregister(4L);
|
||||
unregister(6L);
|
||||
BluetoothGatt bluetoothGatt = getBluetoothGatt();
|
||||
if (bluetoothGatt == null) {
|
||||
BleLiteLog.i(TAG, "__close() bluetoothGatt is null");
|
||||
}
|
||||
BleCloseOperation.createInstance(bluetoothGatt).run();
|
||||
BleLiteLog.i(TAG, "__close() closed");
|
||||
}
|
||||
|
||||
private boolean __connect(String str, long j) {
|
||||
synchronized (this.mLock4Close) {
|
||||
this.mIsClosed = false;
|
||||
}
|
||||
this.mReconnectScheme.clearRetryCount();
|
||||
Context context = this.mAppContext;
|
||||
BleConnectOperation connectOperation = getConnectOperation();
|
||||
if (connectOperation == null) {
|
||||
connectOperation = BleConnectOperation.createInstance(context, str, this.mBluetoothGattCallback);
|
||||
register(connectOperation);
|
||||
} else {
|
||||
BleLiteLog.w(TAG, "__connect() close old connection, it should't appear frequently.");
|
||||
__close();
|
||||
}
|
||||
long currentTimeMillis = System.currentTimeMillis();
|
||||
connectOperation.doRunnableSelfAsync(true);
|
||||
connectOperation.waitLock(j);
|
||||
long currentTimeMillis2 = System.currentTimeMillis() - currentTimeMillis;
|
||||
setBleConnector(connectOperation.getConnector());
|
||||
boolean isNotified = connectOperation.isNotified();
|
||||
BleLiteLog.i(TAG, "__connect() suc: " + isNotified + ", consume: " + currentTimeMillis2 + " ms");
|
||||
if (!isNotified) {
|
||||
close();
|
||||
}
|
||||
return isNotified;
|
||||
}
|
||||
|
||||
private BluetoothGattCharacteristic __discoverCharacteristic(BluetoothGattService bluetoothGattService, UUID uuid) {
|
||||
BluetoothGattCharacteristic characteristic = bluetoothGattService.getCharacteristic(uuid);
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("__discoverCharacteristic() gattService uuid: ");
|
||||
sb.append(bluetoothGattService.getUuid());
|
||||
sb.append(", characteristic uuid: ");
|
||||
sb.append(uuid);
|
||||
sb.append(", gattCharacteristic is ");
|
||||
sb.append(characteristic != null ? "found" : "missed");
|
||||
BleLiteLog.i(TAG, sb.toString());
|
||||
return characteristic;
|
||||
}
|
||||
|
||||
private boolean __discoverService(BluetoothGatt bluetoothGatt, long j) {
|
||||
if (bluetoothGatt == null) {
|
||||
BleLiteLog.w(TAG, "__discoverService() fail for bluetoothGatt is null");
|
||||
return false;
|
||||
}
|
||||
BleDiscoverServiceOperation createInstance = BleDiscoverServiceOperation.createInstance(bluetoothGatt);
|
||||
register(createInstance);
|
||||
long currentTimeMillis = System.currentTimeMillis();
|
||||
createInstance.doRunnableSelfAsync(true);
|
||||
createInstance.waitLock(j);
|
||||
long currentTimeMillis2 = System.currentTimeMillis() - currentTimeMillis;
|
||||
boolean isNotified = createInstance.isNotified();
|
||||
BleLiteLog.i(TAG, "__discoverService() discover services suc: " + isNotified + ", consume: " + currentTimeMillis2 + " ms");
|
||||
return isNotified;
|
||||
}
|
||||
|
||||
private List<BluetoothGattService> __discoverServices(long j) {
|
||||
BluetoothGatt bluetoothGatt = getBluetoothGatt();
|
||||
if (bluetoothGatt == null) {
|
||||
BleLiteLog.w(TAG, "__discoverServices() fail for bluetoothGatt is null");
|
||||
return null;
|
||||
}
|
||||
if (__discoverService(bluetoothGatt, j)) {
|
||||
return bluetoothGatt.getServices();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private byte[] __readCharacteristic(BluetoothGattCharacteristic bluetoothGattCharacteristic, long j) {
|
||||
BluetoothGatt bluetoothGatt = getBluetoothGatt();
|
||||
if (bluetoothGatt == null) {
|
||||
BleLiteLog.w(TAG, "__readCharacteristic() fail for bluetoothGatt is null");
|
||||
return null;
|
||||
}
|
||||
BleReadCharacteristicOperation createInstance = BleReadCharacteristicOperation.createInstance(bluetoothGatt, bluetoothGattCharacteristic);
|
||||
register(createInstance);
|
||||
long currentTimeMillis = System.currentTimeMillis();
|
||||
createInstance.doRunnableSelfAsync(false);
|
||||
createInstance.waitLock(j);
|
||||
long currentTimeMillis2 = System.currentTimeMillis() - currentTimeMillis;
|
||||
byte[] result = createInstance.isNotified() ? createInstance.getResult() : null;
|
||||
BleLiteLog.i(TAG, "__readCharacteristic() gattCharacteristic's uuid: " + bluetoothGattCharacteristic.getUuid() + ", consume: " + currentTimeMillis2 + " ms, msg: " + HexUtils.bytes2HexStringWithSpace(result));
|
||||
return result;
|
||||
}
|
||||
|
||||
private boolean __registerCharacteristicNotification(BluetoothGattCharacteristic bluetoothGattCharacteristic, BleGattClientProxy.OnCharacteristicNotificationListener onCharacteristicNotificationListener) {
|
||||
BluetoothGatt bluetoothGatt = getBluetoothGatt();
|
||||
if (bluetoothGatt == null) {
|
||||
BleLiteLog.w(TAG, "__registerCharacteristicNotification() fail for bluetoothGatt is null");
|
||||
return false;
|
||||
}
|
||||
if (bluetoothGattCharacteristic == null) {
|
||||
BleLiteLog.e(TAG, "__registerCharacteristicNotification() fail for characteristic is null");
|
||||
return false;
|
||||
}
|
||||
boolean characteristicNotification = bluetoothGatt.setCharacteristicNotification(bluetoothGattCharacteristic, true);
|
||||
if (characteristicNotification) {
|
||||
registerListener(bluetoothGattCharacteristic.getUuid(), onCharacteristicNotificationListener);
|
||||
}
|
||||
BleLiteLog.i(TAG, "__registerCharacteristicNotification() characteristic's uuid: " + bluetoothGattCharacteristic.getUuid() + ", register suc: " + characteristicNotification);
|
||||
BluetoothGattDescriptor descriptor = bluetoothGattCharacteristic.getDescriptor(BleUuidUtils.str2uuid(UUID_CLIENT_CHARACTERISTIC_CONFIG_DESCRIPTOR));
|
||||
return descriptor != null ? __writeDescriptor(descriptor, BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE, 2000L) : characteristicNotification;
|
||||
}
|
||||
|
||||
private boolean __requestMtu(int i, long j) {
|
||||
if (Build.VERSION.SDK_INT < 21) {
|
||||
BleLiteLog.w(TAG, "__requestMtu() fail for android version is to low(lower than 5.0 LOLLIPOP)");
|
||||
return false;
|
||||
}
|
||||
BluetoothGatt bluetoothGatt = getBluetoothGatt();
|
||||
if (bluetoothGatt == null) {
|
||||
BleLiteLog.w(TAG, "__requestMtu() fail for bluetoothGatt is null");
|
||||
return false;
|
||||
}
|
||||
BleRequestMtuOperation createInstance = BleRequestMtuOperation.createInstance(bluetoothGatt, i);
|
||||
register(createInstance);
|
||||
long currentTimeMillis = System.currentTimeMillis();
|
||||
createInstance.doRunnableSelfAsync(false);
|
||||
createInstance.waitLock(j);
|
||||
long currentTimeMillis2 = System.currentTimeMillis() - currentTimeMillis;
|
||||
boolean isNotified = createInstance.isNotified();
|
||||
BleLiteLog.i(TAG, "__requestMtu() mtu: " + i + " suc: " + isNotified + ", consume: " + currentTimeMillis2 + " ms");
|
||||
return isNotified;
|
||||
}
|
||||
|
||||
private void __unregisterCharacteristicNotification(UUID uuid) {
|
||||
unregisterListener(uuid);
|
||||
}
|
||||
|
||||
private boolean __writeCharacterisitcNoResponsePacket2(BluetoothGattCharacteristic bluetoothGattCharacteristic, byte[] bArr) {
|
||||
BluetoothGatt bluetoothGatt = getBluetoothGatt();
|
||||
if (bluetoothGatt == null) {
|
||||
BleLiteLog.w(TAG, "__writeCharacterisitcNoResponsePacket2() fail for bluetoothGatt is null");
|
||||
return false;
|
||||
}
|
||||
BleWriteCharacterisitcNoResponsePacketOperation2.createInstance(bluetoothGatt, bluetoothGattCharacteristic, bArr).doRunnableSelfAsync(false);
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean __writeCharacteristic(BluetoothGattCharacteristic bluetoothGattCharacteristic, byte[] bArr, long j) {
|
||||
BluetoothGatt bluetoothGatt = getBluetoothGatt();
|
||||
if (bluetoothGatt == null) {
|
||||
BleLiteLog.w(TAG, "__writeCharacteristic() fail for bluetoothGatt is null");
|
||||
return false;
|
||||
}
|
||||
BleWriteCharacteristicOperation createInstance = BleWriteCharacteristicOperation.createInstance(bluetoothGatt, bluetoothGattCharacteristic, bArr);
|
||||
register(createInstance);
|
||||
long currentTimeMillis = System.currentTimeMillis();
|
||||
createInstance.doRunnableSelfAsync(false);
|
||||
createInstance.waitLock(j);
|
||||
long currentTimeMillis2 = System.currentTimeMillis() - currentTimeMillis;
|
||||
boolean isNotified = createInstance.isNotified();
|
||||
BleLiteLog.i(TAG, "__writeCharacteristic() msg: " + HexUtils.bytes2HexStringWithSpace(bArr) + " suc: " + isNotified + ", consume: " + currentTimeMillis2 + " ms");
|
||||
return isNotified;
|
||||
}
|
||||
|
||||
private boolean __writeCharacteristicNoResponse(BluetoothGattCharacteristic bluetoothGattCharacteristic, byte[] bArr, long j) {
|
||||
BluetoothGatt bluetoothGatt = getBluetoothGatt();
|
||||
if (bluetoothGatt == null) {
|
||||
BleLiteLog.w(TAG, "__writeCharacteristicNoResponse() fail for bluetoothGatt is null");
|
||||
return false;
|
||||
}
|
||||
BleWriteCharacteristicNoResponseOperation.createInstance(bluetoothGatt, bluetoothGattCharacteristic, bArr).doRunnableSelfAsync(false);
|
||||
if (j > 0) {
|
||||
try {
|
||||
Thread.sleep(j);
|
||||
} catch (InterruptedException unused) {
|
||||
Thread.currentThread().interrupt();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
BleLiteLog.i(TAG, "__writeCharacteristicNoResponse() msg: " + HexUtils.bytes2HexStringWithSpace(bArr) + " suc: true, interval: " + j + " ms");
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean __writeCharacteristicNoResponse20(BluetoothGattCharacteristic bluetoothGattCharacteristic, byte[] bArr) {
|
||||
BluetoothGatt bluetoothGatt = getBluetoothGatt();
|
||||
if (bluetoothGatt == null) {
|
||||
BleLiteLog.w(TAG, "__writeCharacteristicNoResponse20() fail for bluetoothGatt is null");
|
||||
return false;
|
||||
}
|
||||
BleWriteCharacteristicNoResponse20Operation.createInstance(bluetoothGatt, bluetoothGattCharacteristic, bArr).doRunnableSelfAsync(false);
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean __writeCharacteristicNoResponsePacket(BluetoothGattCharacteristic bluetoothGattCharacteristic, byte[] bArr, int i, int i2) {
|
||||
BluetoothGatt bluetoothGatt = getBluetoothGatt();
|
||||
if (bluetoothGatt == null) {
|
||||
BleLiteLog.w(TAG, "__writeCharacteristicNoResponsePacket() fail for bluetoothGatt is null");
|
||||
return false;
|
||||
}
|
||||
BleWriteCharacterisitcNoResponsePacketOperation.createInstance(bluetoothGatt, bluetoothGattCharacteristic, bArr, i, i2).doRunnableSelfAsync(false);
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean __writeCharacteristicNoResponsePreemptible(BluetoothGattCharacteristic bluetoothGattCharacteristic, byte[] bArr) {
|
||||
BluetoothGatt bluetoothGatt = getBluetoothGatt();
|
||||
if (bluetoothGatt == null) {
|
||||
BleLiteLog.w(TAG, "__writeCharacteristicNoResponsePreemptible() fail for bluetoothGatt is null");
|
||||
return false;
|
||||
}
|
||||
BleWriteCharacteristicNoResponseInterruptOperation createInstance = BleWriteCharacteristicNoResponseInterruptOperation.createInstance(bluetoothGatt, bluetoothGattCharacteristic, bArr);
|
||||
createInstance.doRunnableSelfAsyncInterruptable(createInstance.getOperatcionCode());
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean __writeDescriptor(BluetoothGattDescriptor bluetoothGattDescriptor, byte[] bArr, long j) {
|
||||
BluetoothGatt bluetoothGatt = getBluetoothGatt();
|
||||
if (bluetoothGatt == null) {
|
||||
BleLiteLog.w(TAG, "__writeDescriptor() fail for bluetoothGatt is null");
|
||||
return false;
|
||||
}
|
||||
BleWriteDescriptorOperation createInstance = BleWriteDescriptorOperation.createInstance(bluetoothGatt, bluetoothGattDescriptor, bArr);
|
||||
register(createInstance);
|
||||
long currentTimeMillis = System.currentTimeMillis();
|
||||
createInstance.doRunnableSelfAsync(false);
|
||||
createInstance.waitLock(j);
|
||||
long currentTimeMillis2 = System.currentTimeMillis() - currentTimeMillis;
|
||||
boolean isNotified = createInstance.isNotified();
|
||||
BleLiteLog.i(TAG, "__writeDescriptor() msg: " + HexUtils.bytes2HexStringWithSpace(bArr) + " suc: " + isNotified + ", consume: " + currentTimeMillis2 + " ms");
|
||||
return isNotified;
|
||||
}
|
||||
|
||||
private BluetoothGatt getBluetoothGatt() {
|
||||
BleConnector bleConnector = this.mBleConnector;
|
||||
if (bleConnector != null) {
|
||||
return bleConnector.getBluetoothGatt();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/* JADX INFO: Access modifiers changed from: private */
|
||||
public BleConnectOperation getConnectOperation() {
|
||||
BleOperation bleOperation = this.mOperations.get(1L);
|
||||
if (bleOperation != null) {
|
||||
return (BleConnectOperation) bleOperation;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/* JADX INFO: Access modifiers changed from: private */
|
||||
public BleDiscoverServiceOperation getDiscoverServiceOperation() {
|
||||
BleOperation bleOperation = this.mOperations.get(3L);
|
||||
if (bleOperation != null) {
|
||||
return (BleDiscoverServiceOperation) bleOperation;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/* JADX INFO: Access modifiers changed from: private */
|
||||
public BleGattClientProxy.OnCharacteristicNotificationListener getListener(UUID uuid) {
|
||||
return this.mListeners.get(BleUuidUtils.uuid2int(uuid));
|
||||
}
|
||||
|
||||
/* JADX INFO: Access modifiers changed from: private */
|
||||
public BleReadCharacteristicOperation getReadCharacteristicOperation() {
|
||||
BleOperation bleOperation = this.mOperations.get(4L);
|
||||
if (bleOperation != null) {
|
||||
return (BleReadCharacteristicOperation) bleOperation;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/* JADX INFO: Access modifiers changed from: private */
|
||||
public BleRequestMtuOperation getRequestMtuOperation() {
|
||||
BleOperation bleOperation = this.mOperations.get(5L);
|
||||
if (bleOperation != null) {
|
||||
return (BleRequestMtuOperation) bleOperation;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/* JADX INFO: Access modifiers changed from: private */
|
||||
public BleWriteCharacteristicOperation getWriteCharacteristicOperation() {
|
||||
BleOperation bleOperation = this.mOperations.get(6L);
|
||||
if (bleOperation != null) {
|
||||
return (BleWriteCharacteristicOperation) bleOperation;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/* JADX INFO: Access modifiers changed from: private */
|
||||
public BleWriteDescriptorOperation getWriteDescriptorOperation() {
|
||||
BleOperation bleOperation = this.mOperations.get(7L);
|
||||
if (bleOperation != null) {
|
||||
return (BleWriteDescriptorOperation) bleOperation;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void register(BleOperation bleOperation) {
|
||||
BleLiteLog.d(TAG, "register() operation: " + bleOperation);
|
||||
this.mOperations.put((long) bleOperation.getOperatcionCode(), bleOperation);
|
||||
}
|
||||
|
||||
private void registerListener(UUID uuid, BleGattClientProxy.OnCharacteristicNotificationListener onCharacteristicNotificationListener) {
|
||||
long uuid2int = BleUuidUtils.uuid2int(uuid);
|
||||
BleLiteLog.d(TAG, "registerListener() uuid: " + uuid + ", key: " + uuid2int);
|
||||
this.mListeners.put(uuid2int, onCharacteristicNotificationListener);
|
||||
}
|
||||
|
||||
private void setBleConnector(BleConnector bleConnector) {
|
||||
this.mBleConnector = bleConnector;
|
||||
}
|
||||
|
||||
private void unregister(long j) {
|
||||
BleLiteLog.d(TAG, "unregister() operationCode: " + j);
|
||||
this.mOperations.remove(j);
|
||||
}
|
||||
|
||||
private void unregisterListener(UUID uuid) {
|
||||
long uuid2int = BleUuidUtils.uuid2int(uuid);
|
||||
BleLiteLog.d(TAG, "unregisterListener() uuid: " + uuid + ", key: " + uuid2int);
|
||||
this.mListeners.remove(uuid2int);
|
||||
}
|
||||
|
||||
@Override // com.afunx.ble.blelitelib.proxy.BleGattClientProxy
|
||||
public void close() {
|
||||
synchronized (this.mLock4Close) {
|
||||
__close();
|
||||
}
|
||||
}
|
||||
|
||||
@Override // com.afunx.ble.blelitelib.proxy.BleGattClientProxy
|
||||
public boolean connect(String str, long j) {
|
||||
boolean __connect;
|
||||
synchronized (this.mLock4Connect) {
|
||||
__connect = __connect(str, j);
|
||||
}
|
||||
return __connect;
|
||||
}
|
||||
|
||||
@Override // com.afunx.ble.blelitelib.proxy.BleGattClientProxy
|
||||
public BluetoothGattCharacteristic discoverCharacteristic(BluetoothGattService bluetoothGattService, UUID uuid) {
|
||||
return __discoverCharacteristic(bluetoothGattService, uuid);
|
||||
}
|
||||
|
||||
@Override // com.afunx.ble.blelitelib.proxy.BleGattClientProxy
|
||||
public BluetoothGattService discoverService(UUID uuid, long j) {
|
||||
return __discoverService(uuid, j);
|
||||
}
|
||||
|
||||
@Override // com.afunx.ble.blelitelib.proxy.BleGattClientProxy
|
||||
public List<BluetoothGattService> discoverServices(long j) {
|
||||
return __discoverServices(j);
|
||||
}
|
||||
|
||||
@Override // com.afunx.ble.blelitelib.proxy.BleGattClientProxy
|
||||
public byte[] readCharacteristic(BluetoothGattCharacteristic bluetoothGattCharacteristic, long j) {
|
||||
return __readCharacteristic(bluetoothGattCharacteristic, j);
|
||||
}
|
||||
|
||||
@Override // com.afunx.ble.blelitelib.proxy.BleGattClientProxy
|
||||
public boolean registerCharacteristicNotification(BluetoothGattCharacteristic bluetoothGattCharacteristic, BleGattClientProxy.OnCharacteristicNotificationListener onCharacteristicNotificationListener) {
|
||||
return __registerCharacteristicNotification(bluetoothGattCharacteristic, onCharacteristicNotificationListener);
|
||||
}
|
||||
|
||||
@Override // com.afunx.ble.blelitelib.proxy.BleGattClientProxy
|
||||
public boolean requestMtu(int i, long j) {
|
||||
return __requestMtu(i, j);
|
||||
}
|
||||
|
||||
@Override // com.afunx.ble.blelitelib.proxy.BleGattClientProxy
|
||||
public void setDisconnectCallback(Runnable runnable, long j) {
|
||||
this.mReconnectScheme.setDisconnectCallback(runnable, j);
|
||||
}
|
||||
|
||||
@Override // com.afunx.ble.blelitelib.proxy.BleGattClientProxy
|
||||
public void unregisterCharacteristicNotification(UUID uuid) {
|
||||
__unregisterCharacteristicNotification(uuid);
|
||||
}
|
||||
|
||||
@Override // com.afunx.ble.blelitelib.proxy.BleGattClientProxy
|
||||
public boolean writeCharacterisitcNoResponse2(BluetoothGattCharacteristic bluetoothGattCharacteristic, byte[] bArr) {
|
||||
return __writeCharacterisitcNoResponsePacket2(bluetoothGattCharacteristic, bArr);
|
||||
}
|
||||
|
||||
@Override // com.afunx.ble.blelitelib.proxy.BleGattClientProxy
|
||||
public boolean writeCharacteristic(BluetoothGattCharacteristic bluetoothGattCharacteristic, byte[] bArr, long j) {
|
||||
return __writeCharacteristic(bluetoothGattCharacteristic, bArr, j);
|
||||
}
|
||||
|
||||
@Override // com.afunx.ble.blelitelib.proxy.BleGattClientProxy
|
||||
public boolean writeCharacteristicNoResponse(BluetoothGattCharacteristic bluetoothGattCharacteristic, byte[] bArr, long j) {
|
||||
return __writeCharacteristicNoResponse(bluetoothGattCharacteristic, bArr, j);
|
||||
}
|
||||
|
||||
@Override // com.afunx.ble.blelitelib.proxy.BleGattClientProxy
|
||||
public boolean writeCharacteristicNoResponse20(BluetoothGattCharacteristic bluetoothGattCharacteristic, byte[] bArr) {
|
||||
return __writeCharacteristicNoResponse20(bluetoothGattCharacteristic, bArr);
|
||||
}
|
||||
|
||||
@Override // com.afunx.ble.blelitelib.proxy.BleGattClientProxy
|
||||
public boolean writeCharacteristicNoResponsePacket(BluetoothGattCharacteristic bluetoothGattCharacteristic, byte[] bArr, int i, int i2) {
|
||||
return __writeCharacteristicNoResponsePacket(bluetoothGattCharacteristic, bArr, i, i2);
|
||||
}
|
||||
|
||||
@Override // com.afunx.ble.blelitelib.proxy.BleGattClientProxy
|
||||
public boolean writeCharacteristicNoResponsePreemptible(BluetoothGattCharacteristic bluetoothGattCharacteristic, byte[] bArr) {
|
||||
return __writeCharacteristicNoResponsePreemptible(bluetoothGattCharacteristic, bArr);
|
||||
}
|
||||
|
||||
private BluetoothGattService __discoverService(UUID uuid, long j) {
|
||||
BluetoothGatt bluetoothGatt = getBluetoothGatt();
|
||||
if (bluetoothGatt == null) {
|
||||
BleLiteLog.w(TAG, "__discoverService() fail for bluetoothGatt is null");
|
||||
return null;
|
||||
}
|
||||
BluetoothGattService service = bluetoothGatt.getService(uuid);
|
||||
if (service != null) {
|
||||
BleLiteLog.i(TAG, "__discoverService() uuid: " + uuid + ", gattService is exist already");
|
||||
return service;
|
||||
}
|
||||
if (__discoverService(bluetoothGatt, j)) {
|
||||
service = bluetoothGatt.getService(uuid);
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("__discoverService() uuid: ");
|
||||
sb.append(uuid);
|
||||
sb.append(", gattService is ");
|
||||
sb.append(service != null ? "found" : "missed");
|
||||
BleLiteLog.i(TAG, sb.toString());
|
||||
}
|
||||
return service;
|
||||
}
|
||||
}
|
@@ -0,0 +1,16 @@
|
||||
package com.afunx.ble.blelitelib.proxy.scheme;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public interface BleGattReconnectScheme {
|
||||
int addAndGetRetryCount();
|
||||
|
||||
void callDisconnectCallbackInstantly();
|
||||
|
||||
void clearRetryCount();
|
||||
|
||||
long getSleepTimestamp(int i);
|
||||
|
||||
void setDisconnectCallback(Runnable runnable, long j);
|
||||
|
||||
boolean tryAgain();
|
||||
}
|
@@ -0,0 +1,95 @@
|
||||
package com.afunx.ble.blelitelib.proxy.scheme;
|
||||
|
||||
import com.afunx.ble.blelitelib.log.BleLiteLog;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public class BleGattReconnectSchemeDefaultImpl implements BleGattReconnectScheme {
|
||||
private static final String TAG = "BleGattReconnectSchemeDefaultImpl";
|
||||
private Runnable mDisconnectedCallback;
|
||||
private final AtomicInteger mCount = new AtomicInteger();
|
||||
private final Timer mTimer = new Timer();
|
||||
private TimerTask mTimerTask = null;
|
||||
private volatile long mTimeoutMilli = 0;
|
||||
private volatile boolean mTryAgain = true;
|
||||
|
||||
private synchronized void addTimerTask(long j) {
|
||||
BleLiteLog.i(TAG, "addTimerTask() delayMilli: " + j);
|
||||
this.mTimerTask = new TimerTask() { // from class: com.afunx.ble.blelitelib.proxy.scheme.BleGattReconnectSchemeDefaultImpl.1
|
||||
@Override // java.util.TimerTask, java.lang.Runnable
|
||||
public void run() {
|
||||
BleLiteLog.i(BleGattReconnectSchemeDefaultImpl.TAG, "addTimerTask() run()");
|
||||
BleGattReconnectSchemeDefaultImpl.this.mTryAgain = false;
|
||||
if (BleGattReconnectSchemeDefaultImpl.this.mDisconnectedCallback != null) {
|
||||
BleGattReconnectSchemeDefaultImpl.this.mDisconnectedCallback.run();
|
||||
}
|
||||
}
|
||||
};
|
||||
this.mTimer.schedule(this.mTimerTask, j);
|
||||
}
|
||||
|
||||
private synchronized boolean removeTimerTask() {
|
||||
BleLiteLog.i(TAG, "removeTimerTask()");
|
||||
if (this.mTimerTask == null) {
|
||||
this.mTryAgain = true;
|
||||
BleLiteLog.i(TAG, "removeTimerTask() mTryAgain = true");
|
||||
return false;
|
||||
}
|
||||
BleLiteLog.i(TAG, "removeTimerTask() cancel()");
|
||||
boolean cancel = this.mTimerTask.cancel();
|
||||
this.mTimerTask = null;
|
||||
return cancel;
|
||||
}
|
||||
|
||||
@Override // com.afunx.ble.blelitelib.proxy.scheme.BleGattReconnectScheme
|
||||
public int addAndGetRetryCount() {
|
||||
return this.mCount.addAndGet(1);
|
||||
}
|
||||
|
||||
@Override // com.afunx.ble.blelitelib.proxy.scheme.BleGattReconnectScheme
|
||||
public synchronized void callDisconnectCallbackInstantly() {
|
||||
BleLiteLog.i(TAG, "callDisconnectCallbackInstantly()");
|
||||
if (this.mTimerTask == null) {
|
||||
BleLiteLog.i(TAG, "callDisconnectCallbackInstantly() run()");
|
||||
if (this.mDisconnectedCallback != null) {
|
||||
this.mDisconnectedCallback.run();
|
||||
}
|
||||
} else if (removeTimerTask()) {
|
||||
BleLiteLog.i(TAG, "callDisconnectCallbackInstantly() run() for cancelled already");
|
||||
if (this.mDisconnectedCallback != null) {
|
||||
this.mDisconnectedCallback.run();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override // com.afunx.ble.blelitelib.proxy.scheme.BleGattReconnectScheme
|
||||
public void clearRetryCount() {
|
||||
removeTimerTask();
|
||||
this.mCount.set(0);
|
||||
}
|
||||
|
||||
@Override // com.afunx.ble.blelitelib.proxy.scheme.BleGattReconnectScheme
|
||||
public synchronized long getSleepTimestamp(int i) {
|
||||
BleLiteLog.i(TAG, "getSleepTimestamp() retryCount: " + i + ", mDisconnectedCallback: " + this.mDisconnectedCallback);
|
||||
if (i == 1 && this.mDisconnectedCallback != null) {
|
||||
addTimerTask(this.mTimeoutMilli);
|
||||
}
|
||||
return (2 << (i - 1)) * 1000;
|
||||
}
|
||||
|
||||
@Override // com.afunx.ble.blelitelib.proxy.scheme.BleGattReconnectScheme
|
||||
public synchronized void setDisconnectCallback(Runnable runnable, long j) {
|
||||
if (j < 0) {
|
||||
throw new IllegalArgumentException("timeoutMilli should >= 0");
|
||||
}
|
||||
this.mTimeoutMilli = j;
|
||||
this.mDisconnectedCallback = runnable;
|
||||
}
|
||||
|
||||
@Override // com.afunx.ble.blelitelib.proxy.scheme.BleGattReconnectScheme
|
||||
public boolean tryAgain() {
|
||||
return this.mTryAgain;
|
||||
}
|
||||
}
|
74
sources/com/afunx/ble/blelitelib/scanner/BleScanner.java
Normal file
74
sources/com/afunx/ble/blelitelib/scanner/BleScanner.java
Normal file
@@ -0,0 +1,74 @@
|
||||
package com.afunx.ble.blelitelib.scanner;
|
||||
|
||||
import android.bluetooth.BluetoothAdapter;
|
||||
import android.bluetooth.le.BluetoothLeScanner;
|
||||
import android.bluetooth.le.ScanCallback;
|
||||
import android.util.Log;
|
||||
import java.util.UUID;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public class BleScanner {
|
||||
private static final String TAG = "BlueScanner";
|
||||
|
||||
private static BluetoothAdapter getAdapter() {
|
||||
return BluetoothAdapter.getDefaultAdapter();
|
||||
}
|
||||
|
||||
public static boolean startLeScan(UUID[] uuidArr, BluetoothAdapter.LeScanCallback leScanCallback) {
|
||||
BluetoothAdapter adapter = getAdapter();
|
||||
if (adapter != null) {
|
||||
return adapter.startLeScan(uuidArr, leScanCallback);
|
||||
}
|
||||
Log.e(TAG, "This hardware not support bluetooth!");
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean startScan(ScanCallback scanCallback) {
|
||||
BluetoothAdapter adapter = getAdapter();
|
||||
if (adapter == null) {
|
||||
Log.e(TAG, "This hardware not support bluetooth!");
|
||||
return false;
|
||||
}
|
||||
BluetoothLeScanner bluetoothLeScanner = adapter.getBluetoothLeScanner();
|
||||
if (bluetoothLeScanner == null) {
|
||||
Log.e(TAG, "The bluetooth is disabled!");
|
||||
return false;
|
||||
}
|
||||
bluetoothLeScanner.startScan(scanCallback);
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean stopLeScan(BluetoothAdapter.LeScanCallback leScanCallback) {
|
||||
BluetoothAdapter adapter = getAdapter();
|
||||
if (adapter == null) {
|
||||
Log.e(TAG, "This hardware not support bluetooth!");
|
||||
return false;
|
||||
}
|
||||
adapter.stopLeScan(leScanCallback);
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean stopScan(ScanCallback scanCallback) {
|
||||
BluetoothAdapter adapter = getAdapter();
|
||||
if (adapter == null) {
|
||||
Log.e(TAG, "This hardware not support bluetooth!");
|
||||
return false;
|
||||
}
|
||||
BluetoothLeScanner bluetoothLeScanner = adapter.getBluetoothLeScanner();
|
||||
if (bluetoothLeScanner == null) {
|
||||
Log.e(TAG, "The bluetooth is disabled!");
|
||||
return false;
|
||||
}
|
||||
bluetoothLeScanner.stopScan(scanCallback);
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean startLeScan(BluetoothAdapter.LeScanCallback leScanCallback) {
|
||||
BluetoothAdapter adapter = getAdapter();
|
||||
if (adapter == null) {
|
||||
Log.e(TAG, "This hardware not support bluetooth!");
|
||||
return false;
|
||||
}
|
||||
return adapter.startLeScan(leScanCallback);
|
||||
}
|
||||
}
|
@@ -0,0 +1,47 @@
|
||||
package com.afunx.ble.blelitelib.threadpool;
|
||||
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public class BleThreadpool {
|
||||
private static BleThreadpool instance = new BleThreadpool();
|
||||
private Handler mMainHandler = new Handler(Looper.getMainLooper());
|
||||
private ExecutorService mExecutor = Executors.newCachedThreadPool();
|
||||
|
||||
private BleThreadpool() {
|
||||
}
|
||||
|
||||
public static BleThreadpool getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
public void shutdown() {
|
||||
this.mExecutor.shutdown();
|
||||
}
|
||||
|
||||
public List<Runnable> shutdownNow() {
|
||||
return this.mExecutor.shutdownNow();
|
||||
}
|
||||
|
||||
public <T> Future<T> submit(Callable<T> callable) {
|
||||
return this.mExecutor.submit(callable);
|
||||
}
|
||||
|
||||
public void submitInMain(Runnable runnable) {
|
||||
if (Looper.myLooper() == Looper.getMainLooper()) {
|
||||
runnable.run();
|
||||
} else {
|
||||
this.mMainHandler.post(runnable);
|
||||
}
|
||||
}
|
||||
|
||||
public Future<?> submit(Runnable runnable) {
|
||||
return this.mExecutor.submit(runnable);
|
||||
}
|
||||
}
|
@@ -0,0 +1,8 @@
|
||||
package com.afunx.ble.blelitelib.utils;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public class BleGattStateParser {
|
||||
public static String parse(int i) {
|
||||
return i != 0 ? i != 1 ? i != 2 ? i != 3 ? String.format("UNKNOWN (0x%04x)", Integer.valueOf(i & 65535)) : "STATE DISCONNECTING" : "STATE CONNECTED" : "STATE CONNECTING" : "STATE DISCONNECTED";
|
||||
}
|
||||
}
|
@@ -0,0 +1,83 @@
|
||||
package com.afunx.ble.blelitelib.utils;
|
||||
|
||||
import com.twitter.sdk.android.core.TwitterAuthConfig;
|
||||
import com.ubtrobot.jimu.robotapi.PeripheralType;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public class BleGattStatusParser {
|
||||
public static String parse(int i) {
|
||||
switch (i) {
|
||||
case 0:
|
||||
return "GATT SUCCESS";
|
||||
case 1:
|
||||
return "GATT INVALID HANDLE";
|
||||
case 2:
|
||||
return "GATT READ NOT PERMIT";
|
||||
case 3:
|
||||
return "GATT WRITE NOT PERMIT";
|
||||
case 4:
|
||||
return "GATT INVALID PDU";
|
||||
case 5:
|
||||
return "GATT INSUF AUTHENTICATION";
|
||||
case 6:
|
||||
return "GATT REQ NOT SUPPORTED";
|
||||
case 7:
|
||||
return "GATT INVALID OFFSET";
|
||||
case 8:
|
||||
return "GATT INSUF AUTHORIZATION";
|
||||
case 9:
|
||||
return "GATT PREPARE Q FULL";
|
||||
case 10:
|
||||
return "GATT NOT FOUND";
|
||||
case 11:
|
||||
return "GATT NOT LONG";
|
||||
case 12:
|
||||
return "GATT INSUF KEY SIZE";
|
||||
case 13:
|
||||
return "GATT INVALID ATTR LEN";
|
||||
case 14:
|
||||
return "GATT ERR UNLIKELY";
|
||||
case 15:
|
||||
return "GATT INSUF ENCRYPTION";
|
||||
case 16:
|
||||
return "GATT UNSUPPORT GRP TYPE";
|
||||
case 17:
|
||||
return "GATT INSUF RESOURCE";
|
||||
default:
|
||||
switch (i) {
|
||||
case PeripheralType.SERVO /* 128 */:
|
||||
return "GATT NO RESOURCES";
|
||||
case 129:
|
||||
return "GATT INTERNAL ERROR";
|
||||
case 130:
|
||||
return "GATT WRONG STATE";
|
||||
case 131:
|
||||
return "GATT DB FULL";
|
||||
case 132:
|
||||
return "GATT BUSY";
|
||||
case 133:
|
||||
return "GATT ERROR";
|
||||
case 134:
|
||||
return "GATT CMD STARTED";
|
||||
case 135:
|
||||
return "GATT ILLEGAL PARAMETER";
|
||||
case 136:
|
||||
return "GATT PENDING";
|
||||
case 137:
|
||||
return "GATT AUTH FAIL";
|
||||
case 138:
|
||||
return "GATT MORE";
|
||||
case 139:
|
||||
return "GATT INVALID CFG";
|
||||
case TwitterAuthConfig.DEFAULT_AUTH_REQUEST_CODE /* 140 */:
|
||||
return "GATT SERVICE STARTED";
|
||||
case 141:
|
||||
return "GATT ENCRYPED NO MITM";
|
||||
case 142:
|
||||
return "GATT NOT ENCRYPTED";
|
||||
default:
|
||||
return String.format("UNKNOWN (0x%04x)", Integer.valueOf(i & 65535));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
29
sources/com/afunx/ble/blelitelib/utils/BleUtils.java
Normal file
29
sources/com/afunx/ble/blelitelib/utils/BleUtils.java
Normal file
@@ -0,0 +1,29 @@
|
||||
package com.afunx.ble.blelitelib.utils;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.bluetooth.BluetoothAdapter;
|
||||
import android.bluetooth.BluetoothDevice;
|
||||
import android.content.Intent;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public class BleUtils {
|
||||
public static boolean disableBluetooth() {
|
||||
return BluetoothAdapter.getDefaultAdapter().disable();
|
||||
}
|
||||
|
||||
public static boolean enableBluetooth() {
|
||||
return BluetoothAdapter.getDefaultAdapter().enable();
|
||||
}
|
||||
|
||||
public static BluetoothDevice getRemoteDevice(String str) {
|
||||
return BluetoothAdapter.getDefaultAdapter().getRemoteDevice(str);
|
||||
}
|
||||
|
||||
public static boolean isBluetoothEnabled() {
|
||||
return BluetoothAdapter.getDefaultAdapter().isEnabled();
|
||||
}
|
||||
|
||||
public static void tryEnableBluetooth(Activity activity, int i) {
|
||||
activity.startActivityForResult(new Intent("android.bluetooth.adapter.action.REQUEST_ENABLE"), i);
|
||||
}
|
||||
}
|
62
sources/com/afunx/ble/blelitelib/utils/BleUuidUtils.java
Normal file
62
sources/com/afunx/ble/blelitelib/utils/BleUuidUtils.java
Normal file
@@ -0,0 +1,62 @@
|
||||
package com.afunx.ble.blelitelib.utils;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public class BleUuidUtils {
|
||||
private static String MAGIC_HEAD_STR = "0000";
|
||||
private static String MAGIC_TAIL_STR = "49535343";
|
||||
private static final int UUID_LENGTH = 36;
|
||||
|
||||
public static String int2str(int i) {
|
||||
if (i < 0 || i > 65535) {
|
||||
throw new IllegalArgumentException("uuid int range is [0x0000,0xffff]");
|
||||
}
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(MAGIC_HEAD_STR);
|
||||
String hexString = Integer.toHexString(i);
|
||||
for (int i2 = 0; i2 < 4 - hexString.length(); i2++) {
|
||||
sb.append("0");
|
||||
}
|
||||
sb.append(hexString);
|
||||
sb.append(MAGIC_TAIL_STR);
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public static UUID int2uuid(int i) {
|
||||
return UUID.fromString(int2str(i));
|
||||
}
|
||||
|
||||
public static void setMagicHeadStr(String str) {
|
||||
if (str.length() != MAGIC_HEAD_STR.length()) {
|
||||
throw new IllegalArgumentException("magicHeadStr length is invalid");
|
||||
}
|
||||
MAGIC_HEAD_STR = str;
|
||||
}
|
||||
|
||||
public static void setMagicTailStr(String str) {
|
||||
if (str.length() != MAGIC_TAIL_STR.length()) {
|
||||
throw new IllegalArgumentException("magicTailStr length is invalid");
|
||||
}
|
||||
MAGIC_TAIL_STR = str;
|
||||
}
|
||||
|
||||
public static int str2int(String str) {
|
||||
if (str != null && str.length() == 36 && str.startsWith(MAGIC_TAIL_STR)) {
|
||||
return Integer.parseInt(str.substring(4, 8), 16);
|
||||
}
|
||||
throw new IllegalArgumentException("invalid uuid string");
|
||||
}
|
||||
|
||||
public static UUID str2uuid(String str) {
|
||||
return UUID.fromString(str);
|
||||
}
|
||||
|
||||
public static int uuid2int(UUID uuid) {
|
||||
return str2int(uuid.toString());
|
||||
}
|
||||
|
||||
public static String uuid2str(UUID uuid) {
|
||||
return uuid.toString();
|
||||
}
|
||||
}
|
49
sources/com/afunx/ble/blelitelib/utils/HexUtils.java
Normal file
49
sources/com/afunx/ble/blelitelib/utils/HexUtils.java
Normal file
@@ -0,0 +1,49 @@
|
||||
package com.afunx.ble.blelitelib.utils;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public class HexUtils {
|
||||
private static final char[] hexDigits = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
|
||||
|
||||
public static String bytes2HexString(byte[] bArr) {
|
||||
if (bArr == null) {
|
||||
return null;
|
||||
}
|
||||
return bArr.length == 0 ? "" : bytes2HexString(bArr, 0, bArr.length);
|
||||
}
|
||||
|
||||
public static String bytes2HexStringWithSpace(byte[] bArr) {
|
||||
if (bArr == null) {
|
||||
return null;
|
||||
}
|
||||
return bArr.length == 0 ? "" : bytes2HexStringWithSpace(bArr, 0, bArr.length);
|
||||
}
|
||||
|
||||
public static String bytes2HexString(byte[] bArr, int i, int i2) {
|
||||
if (bArr == null || i < 0 || i2 <= 0 || i2 - i > bArr.length) {
|
||||
return null;
|
||||
}
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i3 = 0; i3 < i2; i3++) {
|
||||
int i4 = i3 + i;
|
||||
sb.append(hexDigits[(bArr[i4] >>> 4) & 15]);
|
||||
sb.append(hexDigits[bArr[i4] & 15]);
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public static String bytes2HexStringWithSpace(byte[] bArr, int i, int i2) {
|
||||
if (bArr == null || i < 0 || i2 <= 0 || i2 - i > bArr.length) {
|
||||
return null;
|
||||
}
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i3 = 0; i3 < i2; i3++) {
|
||||
int i4 = i3 + i;
|
||||
sb.append(hexDigits[(bArr[i4] >>> 4) & 15]);
|
||||
sb.append(hexDigits[bArr[i4] & 15]);
|
||||
if (i3 != i2 - 1) {
|
||||
sb.append(" ");
|
||||
}
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user