|
@@ -76,12 +76,12 @@ class CoreApiImpl(private val activity: Activity) : CoreApi {
|
|
|
// 事件流处理器实现
|
|
// 事件流处理器实现
|
|
|
private val eventStreamHandler = object : OnEventChangeStreamHandler() {
|
|
private val eventStreamHandler = object : OnEventChangeStreamHandler() {
|
|
|
override fun onListen(p0: Any?, sink: PigeonEventSink<String>) {
|
|
override fun onListen(p0: Any?, sink: PigeonEventSink<String>) {
|
|
|
- Log.d(TAG, "Flutter 开始监听事件变化")
|
|
|
|
|
|
|
+ VLog.d(TAG, "Flutter 开始监听事件变化")
|
|
|
eventSink = sink
|
|
eventSink = sink
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
override fun onCancel(p0: Any?) {
|
|
override fun onCancel(p0: Any?) {
|
|
|
- Log.d(TAG, "Flutter 取消监听事件变化")
|
|
|
|
|
|
|
+ VLog.d(TAG, "Flutter 取消监听事件变化")
|
|
|
eventSink = null
|
|
eventSink = null
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -89,7 +89,7 @@ class CoreApiImpl(private val activity: Activity) : CoreApi {
|
|
|
// 注册事件流处理器
|
|
// 注册事件流处理器
|
|
|
fun registerEventStreamHandler(messenger: BinaryMessenger) {
|
|
fun registerEventStreamHandler(messenger: BinaryMessenger) {
|
|
|
OnEventChangeStreamHandler.register(messenger, eventStreamHandler)
|
|
OnEventChangeStreamHandler.register(messenger, eventStreamHandler)
|
|
|
- Log.d(TAG, "事件流处理器已注册")
|
|
|
|
|
|
|
+ VLog.d(TAG, "事件流处理器已注册")
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 通知 Flutter VPN状态变化
|
|
// 通知 Flutter VPN状态变化
|
|
@@ -131,11 +131,11 @@ class CoreApiImpl(private val activity: Activity) : CoreApi {
|
|
|
try {
|
|
try {
|
|
|
val json = Gson().toJson(message)
|
|
val json = Gson().toJson(message)
|
|
|
sink.success(json)
|
|
sink.success(json)
|
|
|
-// Log.d(TAG, "已通知 Flutter: $json")
|
|
|
|
|
|
|
+// VLog.d(TAG, "已通知 Flutter: $json")
|
|
|
} catch (e: Exception) {
|
|
} catch (e: Exception) {
|
|
|
- Log.e(TAG, "通知 Flutter 失败", e)
|
|
|
|
|
|
|
+ VLog.e(TAG, "通知 Flutter 失败", e)
|
|
|
}
|
|
}
|
|
|
- } ?: Log.w(TAG, "事件流未连接,无法通知 Flutter")
|
|
|
|
|
|
|
+ } ?: VLog.w(TAG, "事件流未连接,无法通知 Flutter")
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -293,16 +293,16 @@ class CoreApiImpl(private val activity: Activity) : CoreApi {
|
|
|
params = params,
|
|
params = params,
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
- Log.i(TAG, "Starting V2Ray with permission check")
|
|
|
|
|
|
|
+ VLog.i(TAG, "Starting V2Ray with permission check")
|
|
|
// 检查VPN权限
|
|
// 检查VPN权限
|
|
|
val intent = VpnService.prepare(activity)
|
|
val intent = VpnService.prepare(activity)
|
|
|
if (intent == null) {
|
|
if (intent == null) {
|
|
|
// 已有VPN权限,直接启动
|
|
// 已有VPN权限,直接启动
|
|
|
- Log.i(TAG, "VPN permission already granted")
|
|
|
|
|
|
|
+ VLog.i(TAG, "VPN permission already granted")
|
|
|
startV2RayService()
|
|
startV2RayService()
|
|
|
} else {
|
|
} else {
|
|
|
// 需要请求VPN权限
|
|
// 需要请求VPN权限
|
|
|
- Log.i(TAG, "Requesting VPN permission")
|
|
|
|
|
|
|
+ VLog.i(TAG, "Requesting VPN permission")
|
|
|
activity.startActivityForResult(intent, REQUEST_VPN_PERMISSION)
|
|
activity.startActivityForResult(intent, REQUEST_VPN_PERMISSION)
|
|
|
}
|
|
}
|
|
|
return true
|
|
return true
|
|
@@ -347,6 +347,21 @@ class CoreApiImpl(private val activity: Activity) : CoreApi {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ override fun openPackage(packageName: String) {
|
|
|
|
|
+ VLog.i(TAG, "openOtherApp called: $packageName")
|
|
|
|
|
+ try {
|
|
|
|
|
+ val intent = activity.packageManager.getLaunchIntentForPackage(packageName)
|
|
|
|
|
+ if (intent != null) {
|
|
|
|
|
+ intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
|
|
|
|
+ activity.startActivity(intent)
|
|
|
|
|
+ } else {
|
|
|
|
|
+ VLog.w(TAG, "无法打开应用: $packageName")
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (e: Exception) {
|
|
|
|
|
+ VLog.e(TAG, "openOtherApp error: ${e.message}")
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
override fun isConnected(): Boolean? {
|
|
override fun isConnected(): Boolean? {
|
|
|
val isRunning = XRayApi.isServiceRunning(activity)
|
|
val isRunning = XRayApi.isServiceRunning(activity)
|
|
|
VLog.i(TAG, "XRayService is running = $isRunning")
|
|
VLog.i(TAG, "XRayService is running = $isRunning")
|
|
@@ -389,6 +404,8 @@ class CoreApiImpl(private val activity: Activity) : CoreApi {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
fun startV2RayService() {
|
|
fun startV2RayService() {
|
|
|
VLog.i(TAG, "============ 开始启动 V2Ray 服务 ============")
|
|
VLog.i(TAG, "============ 开始启动 V2Ray 服务 ============")
|
|
|
|
|
|
|
@@ -457,10 +474,10 @@ class CoreApiImpl(private val activity: Activity) : CoreApi {
|
|
|
fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
|
fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
|
|
if (requestCode == REQUEST_VPN_PERMISSION) {
|
|
if (requestCode == REQUEST_VPN_PERMISSION) {
|
|
|
if (resultCode == Activity.RESULT_OK) {
|
|
if (resultCode == Activity.RESULT_OK) {
|
|
|
- Log.i(TAG, "VPN permission granted, starting V2Ray service")
|
|
|
|
|
|
|
+ VLog.i(TAG, "VPN permission granted, starting V2Ray service")
|
|
|
startV2RayService()
|
|
startV2RayService()
|
|
|
} else {
|
|
} else {
|
|
|
- Log.w(TAG, "VPN permission denied")
|
|
|
|
|
|
|
+ VLog.w(TAG, "VPN permission denied")
|
|
|
notifyVpnStatusChange(VPN_STATE_ERROR, ERROR_PERMISSION_DENIED, "VPN permission denied")
|
|
notifyVpnStatusChange(VPN_STATE_ERROR, ERROR_PERMISSION_DENIED, "VPN permission denied")
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|