From 009cbe1b82751bbd6b8c54b5c0526926a6ef0ddc Mon Sep 17 00:00:00 2001 From: liwei1dao Date: Sat, 10 Jan 2026 19:25:47 +0800 Subject: [PATCH] =?UTF-8?q?feat(location=5Fservice):=20=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E7=B3=BB=E7=BB=9F=E4=BD=8D=E7=BD=AE=E6=9C=8D=E5=8A=A1=E7=8A=B6?= =?UTF-8?q?=E6=80=81=E6=A3=80=E6=9F=A5=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 添加检查系统位置服务是否开启的功能,并在定位前进行校验 修改定位函数名以更准确描述功能 修复中断响应逻辑,优先停止TTS 更新Azure语音识别支持的语言列表 配置gradle构建参数以支持旧版打包方式 --- android/app/build.gradle.kts | 7 ++++++ android/app/src/main/AndroidManifest.xml | 1 + .../agent_service/AgentService.kt | 3 ++- .../azure_speech/AzureAsrHelper.kt | 2 +- .../chat_api/SystemFunctionHandler.kt | 4 ++-- .../location_service/LocationService.kt | 23 +++++++++++++++++++ .../location_service/LocationServicePlugin.kt | 14 ++++++++++- .../lib/location_service.dart | 17 +++++++++++++- 8 files changed, 65 insertions(+), 6 deletions(-) diff --git a/android/app/build.gradle.kts b/android/app/build.gradle.kts index 1813b0c5a..16798fdab 100644 --- a/android/app/build.gradle.kts +++ b/android/app/build.gradle.kts @@ -55,6 +55,9 @@ android { excludes.add("META-INF/notice.txt") excludes.add("META-INF/*.kotlin_module") } + jniLibs { + useLegacyPackaging = true + } } defaultConfig { @@ -83,6 +86,8 @@ android { storePassword = keystoreProperties.getProperty("storePassword") enableV1Signing = true enableV2Signing = true + enableV3Signing = false + enableV4Signing = false } getByName("debug") { // debug 使用与 release 相同的签名配置 @@ -92,6 +97,8 @@ android { storePassword = keystoreProperties.getProperty("storePassword") enableV1Signing = true enableV2Signing = true + enableV3Signing = false + enableV4Signing = false } } diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index 4e946db0e..7400593aa 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -72,6 +72,7 @@ android:networkSecurityConfig="@xml/network_security_config" android:usesCleartextTraffic="true" + android:extractNativeLibs="true" android:enableOnBackInvokedCallback="true" tools:replace="android:label"> diff --git a/local_plugins/agent_service/android/src/main/kotlin/com/yunqiinnovation/agent_service/AgentService.kt b/local_plugins/agent_service/android/src/main/kotlin/com/yunqiinnovation/agent_service/AgentService.kt index e7c4fc3bb..864cd0f5a 100644 --- a/local_plugins/agent_service/android/src/main/kotlin/com/yunqiinnovation/agent_service/AgentService.kt +++ b/local_plugins/agent_service/android/src/main/kotlin/com/yunqiinnovation/agent_service/AgentService.kt @@ -746,7 +746,8 @@ object AgentService : CoroutineScope { // 执行打断 lastInterruptTime = currentTime - interruptCurrentResponse() + stopTts() + // interruptCurrentResponse() } } } diff --git a/local_plugins/azure_speech/android/src/main/kotlin/com/yunqiinnovation/azure_speech/AzureAsrHelper.kt b/local_plugins/azure_speech/android/src/main/kotlin/com/yunqiinnovation/azure_speech/AzureAsrHelper.kt index ee0cbd907..8a4fbd717 100644 --- a/local_plugins/azure_speech/android/src/main/kotlin/com/yunqiinnovation/azure_speech/AzureAsrHelper.kt +++ b/local_plugins/azure_speech/android/src/main/kotlin/com/yunqiinnovation/azure_speech/AzureAsrHelper.kt @@ -130,7 +130,7 @@ class AzureAsrHelper(private val context: Context) { val xunfeiConfigReady = this.xunfeiAppId.isNotBlank() && this.xunfeiAccessKeyId.isNotBlank() && this.xunfeiAccessKeySecret.isNotBlank() - this.useXunfei = supportedLanguages.all { it == "zh-CN" || it == "en-US" } && xunfeiConfigReady + this.useXunfei = supportedLanguages.all { it == "zh-CN" || it == "en-US" || it == "zh-HK"|| it == "en-TW" } && xunfeiConfigReady // 根据支持的语言数量决定是否启用自动语言检测 this.isAutoDetectLanguage = supportedLanguages.size >= 2 diff --git a/local_plugins/chat_api/android/src/main/kotlin/com/yunqiinnovation/chat_api/SystemFunctionHandler.kt b/local_plugins/chat_api/android/src/main/kotlin/com/yunqiinnovation/chat_api/SystemFunctionHandler.kt index bb16bc993..0eb96287f 100644 --- a/local_plugins/chat_api/android/src/main/kotlin/com/yunqiinnovation/chat_api/SystemFunctionHandler.kt +++ b/local_plugins/chat_api/android/src/main/kotlin/com/yunqiinnovation/chat_api/SystemFunctionHandler.kt @@ -152,8 +152,8 @@ class SystemFunctionHandler(private val context: Context? = null) { // 注册获取当前位置函数 client.registerLocalFunction( - name = "get_current_location", - description = "获取当前地理位置", + name = "get_user_current_location", + description = "获取用户当前地理位置", parameters = mapOf( "type" to "object", "properties" to emptyMap(), diff --git a/local_plugins/location_service/android/src/main/kotlin/com/yunqiinnovation/location_service/LocationService.kt b/local_plugins/location_service/android/src/main/kotlin/com/yunqiinnovation/location_service/LocationService.kt index 5e051d418..3c3b0b3bc 100644 --- a/local_plugins/location_service/android/src/main/kotlin/com/yunqiinnovation/location_service/LocationService.kt +++ b/local_plugins/location_service/android/src/main/kotlin/com/yunqiinnovation/location_service/LocationService.kt @@ -5,6 +5,7 @@ import android.app.Activity import android.app.ActivityManager import android.content.Context import android.content.pm.PackageManager +import android.location.LocationManager import android.os.Build import android.os.Handler import android.os.Looper @@ -150,6 +151,10 @@ object LocationService { callback.onLocationError(-2, "后台定位权限需要打开始终定位权限才可,请打开app重新设置权限后再使用") return } + if (!isLocationServiceEnabled(ctx)) { + callback.onLocationError(-6, "定位服务未开启,请在系统设置中打开位置服务开关") + return + } if (!initialized) { callback.onLocationError(-3, "定位服务未初始化") return @@ -287,6 +292,24 @@ object LocationService { return 0 } + /** + * 检查系统位置服务开关状态 + * @param context 应用上下文 + * @return true:位置服务已开启;false:位置服务关闭或检测失败 + * @throws 无显式抛出异常(内部捕获并记录日志) + */ + fun isLocationServiceEnabled(context: Context): Boolean { + try { + val lm = context.getSystemService(Context.LOCATION_SERVICE) as? LocationManager + val gpsOn = lm?.isProviderEnabled(LocationManager.GPS_PROVIDER) == true + val networkOn = lm?.isProviderEnabled(LocationManager.NETWORK_PROVIDER) == true + return gpsOn || networkOn + } catch (e: Exception) { + Log.e(TAG, "检测位置服务开关失败: ${e.message}", e) + return false + } + } + private fun hasForegroundLocationPermission(context: Context): Boolean { return ContextCompat.checkSelfPermission( context, diff --git a/local_plugins/location_service/android/src/main/kotlin/com/yunqiinnovation/location_service/LocationServicePlugin.kt b/local_plugins/location_service/android/src/main/kotlin/com/yunqiinnovation/location_service/LocationServicePlugin.kt index 21bd7184f..87e88edac 100644 --- a/local_plugins/location_service/android/src/main/kotlin/com/yunqiinnovation/location_service/LocationServicePlugin.kt +++ b/local_plugins/location_service/android/src/main/kotlin/com/yunqiinnovation/location_service/LocationServicePlugin.kt @@ -25,7 +25,19 @@ class LocationServicePlugin: FlutterPlugin, MethodCallHandler { override fun onMethodCall(call: MethodCall, result: MethodChannel.Result) { Log.d(TAG, "Method call: ${call.method}") - + when (call.method) { + "isLocationServiceEnabled" -> { + try { + val enabled = LocationService.isLocationServiceEnabled(context) + result.success(enabled) + } catch (e: Exception) { + result.error("CHECK_SERVICE_FAILED", e.message, null) + } + } + else -> { + result.notImplemented() + } + } } override fun onDetachedFromEngine(binding: FlutterPlugin.FlutterPluginBinding) { diff --git a/local_plugins/location_service/lib/location_service.dart b/local_plugins/location_service/lib/location_service.dart index 1e83bc0d0..07466b799 100644 --- a/local_plugins/location_service/lib/location_service.dart +++ b/local_plugins/location_service/lib/location_service.dart @@ -12,7 +12,7 @@ class LocationService { ); // 内部构造函数 - LocationService._internal() {} + LocationService._internal(); /// 检查定位权限 Future> checkPermission() async { @@ -40,6 +40,21 @@ class LocationService { } } + /// 检查系统位置服务是否开启 + /// 参数:无 + /// 返回值:true 表示已开启;false 表示未开启或检测失败 + /// 异常:抛出 Exception,表示方法通道调用失败或平台异常 + Future isLocationServiceEnabled() async { + try { + final enabled = await _methodChannel.invokeMethod( + 'isLocationServiceEnabled', + ); + return enabled ?? false; + } catch (e) { + throw Exception('检查位置服务失败: $e'); + } + } + /// 获取当前位置(按需获取) Future> location() async { try {