|
|
|
@ -1,20 +1,25 @@ |
|
|
|
import 'dart:io'; |
|
|
|
import 'dart:async'; |
|
|
|
|
|
|
|
import 'package:app_settings/app_settings.dart'; |
|
|
|
import 'package:voitrans/data/models/appconfig_model.dart'; |
|
|
|
import '/data/models/appconfig.dart'; |
|
|
|
import '/data/models/user_Info.dart'; |
|
|
|
import '/data/services/network/api.dart'; |
|
|
|
import 'package:flutter/material.dart'; |
|
|
|
import 'package:flutter_screenutil/flutter_screenutil.dart'; |
|
|
|
import 'package:get/get.dart'; |
|
|
|
import 'dart:async'; |
|
|
|
import 'package:permission_handler/permission_handler.dart'; |
|
|
|
import 'package:url_launcher/url_launcher.dart'; |
|
|
|
import 'package:get_storage/get_storage.dart'; |
|
|
|
import 'package:device_info_plus/device_info_plus.dart'; |
|
|
|
|
|
|
|
import '../../../routes/app_routes.dart'; |
|
|
|
import '../../../core/utils/logger.dart'; |
|
|
|
import 'dart:io'; |
|
|
|
import '/data/models/appconfig.dart'; |
|
|
|
import '/data/models/user_Info.dart'; |
|
|
|
import '/data/services/network/api.dart'; |
|
|
|
import '../../../data/services/bluetooth_manager.dart'; |
|
|
|
import '../../../data/services/ble_manager.dart'; |
|
|
|
import '../../../core/utils/permission_util.dart'; |
|
|
|
import '../../../data/services/version_update_service.dart'; |
|
|
|
|
|
|
|
/// 配对状态枚举 - 简化版本 |
|
|
|
enum PairingState { |
|
|
|
@ -48,6 +53,7 @@ enum ErrorType { |
|
|
|
class PairingController extends GetxController with WidgetsBindingObserver { |
|
|
|
static const String _tag = 'PairingCtrl'; |
|
|
|
static PairingController get to => Get.find(); |
|
|
|
final _storage = GetStorage(); |
|
|
|
|
|
|
|
// ========== 状态管理 ========== |
|
|
|
final _currentState = PairingState.idle.obs; |
|
|
|
@ -96,6 +102,12 @@ class PairingController extends GetxController with WidgetsBindingObserver { |
|
|
|
// Public getter for view access |
|
|
|
BluetoothDevice? get currentDevice => _currentClassicDevice; |
|
|
|
|
|
|
|
//华为设备权限检查标记 |
|
|
|
bool isHuaweiHasChecked = false; |
|
|
|
// 缓存的设备品牌信息 |
|
|
|
final versionService = Get.find<VersionUpdateService>(); |
|
|
|
bool isHuaweiDevice = false; |
|
|
|
|
|
|
|
@override |
|
|
|
void onInit() { |
|
|
|
super.onInit(); |
|
|
|
@ -106,6 +118,8 @@ class PairingController extends GetxController with WidgetsBindingObserver { |
|
|
|
WidgetsBinding.instance.addObserver(this); |
|
|
|
Logger.i(_tag, '应用生命周期监听器注册完成'); |
|
|
|
|
|
|
|
isHuaweiDevice = _isHuaweiDevice(); |
|
|
|
|
|
|
|
// 确保服务已初始化 |
|
|
|
_bluetoothManager = Get.find<BluetoothManager>(); |
|
|
|
_bleManager = Get.find<BleManager>(); |
|
|
|
@ -113,6 +127,11 @@ class PairingController extends GetxController with WidgetsBindingObserver { |
|
|
|
// 集中设置所有监听器 |
|
|
|
_setupAllListeners(); |
|
|
|
|
|
|
|
if (isHuaweiDevice) { |
|
|
|
//检查华为设备是否检查权限检查过 |
|
|
|
isHuaweiHasChecked = _storage.read('isHuaweiHasChecked') ?? false; |
|
|
|
} |
|
|
|
|
|
|
|
// 开始初始状态检查 |
|
|
|
// 延迟稍长时间,确保BluetoothManager有足够时间获取已连接设备 |
|
|
|
Future.delayed(const Duration(milliseconds: 300), () { |
|
|
|
@ -548,8 +567,20 @@ class PairingController extends GetxController with WidgetsBindingObserver { |
|
|
|
return _bluetoothManager.bluetoothState != 'off'; |
|
|
|
} |
|
|
|
|
|
|
|
/// 检查是否为华为设备 |
|
|
|
bool _isHuaweiDevice() { |
|
|
|
final deviceBrand = versionService.cachedDeviceBrand; |
|
|
|
return deviceBrand.isNotEmpty && |
|
|
|
(deviceBrand.contains('huawei') || deviceBrand.contains('华为')); |
|
|
|
} |
|
|
|
|
|
|
|
/// 检查权限 |
|
|
|
Future<bool> _checkPermissions() async { |
|
|
|
//如果是华为设备,且已经检查过,直接返回false |
|
|
|
if (isHuaweiDevice && isHuaweiHasChecked) { |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
// Android权限检查 |
|
|
|
if (Platform.isAndroid) { |
|
|
|
Logger.i(_tag, '开始检查Android权限'); |
|
|
|
@ -575,6 +606,9 @@ class PairingController extends GetxController with WidgetsBindingObserver { |
|
|
|
permanentDenialText: 'locationPermanentDenial'.tr, |
|
|
|
); |
|
|
|
|
|
|
|
if (isHuaweiDevice) { |
|
|
|
_storage.write('isHuaweiHasChecked', true); |
|
|
|
} |
|
|
|
return bluetoothScanGranted && bluetoothConnectGranted && locationGranted; |
|
|
|
} |
|
|
|
return true; |
|
|
|
|