简体   繁体   English

Android 服务上的 Delphi 网络共享

[英]Delphi Tethering on Android Service

I'm testing tethering on Delphi.我正在 Delphi 上测试网络共享。

Everything works well in Windows 10 applications (both standard application and service).一切都在 Windows 10 应用程序(标准应用程序和服务)中运行良好。 Everything is also fine in the standard android app.在标准的 android 应用程序中一切都很好。

Problems are in Android service.问题出在 Android 服务中。 I can connect from external client to tethering in android service, receive and send resources and etc. But the following methods and events are not working: connection from client out (AutoConnect), OnEndManagersDiscovery, OnEndProfileDiscovery, OnNewManager does not fire and etc..我可以从外部客户端连接到 android 服务中的网络共享、接收和发送资源等。但以下方法和事件不起作用:从客户端输出(自动连接)、OnEndManagersDiscovery、OnEndProfileDiscovery、OnNewManager 不触发等。

I couldn't figure out any reason why this was happening ...我无法弄清楚发生这种情况的任何原因......

Anybody have any idea where the bug could be?任何人都知道错误可能在哪里?

I was unable to do so, so I examined the source code of System.Tether.Manager (the same goes for System.Tether.AppProfile) in detail, and most likely I found the cause of the problem.我无法这样做,所以我详细检查了 System.Tether.Manager 的源代码(System.Tether.AppProfile 也是如此),很可能我找到了问题的原因。

When the TetheringManager.DiscoverManagers command is executed, no event occurs, but if the TetheringManager.RemoteManagers statement is executed after this command, all surrounding devices are listed.当执行TetheringManager.DiscoverManagers 命令时,没有事件发生,但如果在该命令之后执行TetheringManager.RemoteManagers 语句,则会列出所有周围的设备。

The problem is that the library uses the TThread.Synchronize function to synchronize events.问题是该库使用 TThread.Synchronize 函数来同步事件。 This feature requires a main UI thread for its functionality.此功能需要一个主 UI 线程来实现其功能。 This functionality does not have an android service.此功能没有 android 服务。 Therefore, the event update fails every time (for example, onEndManagersDiscovery).因此,事件更新每次都会失败(例如,onEndManagersDiscovery)。 The library is not intended for use in the android service.该库不适用于 android 服务。

procedure TTetheringManager.DoEndManagersDiscovery(const ARemoteManagers: TTetheringManagerInfoList);
begin
  RegisterManagers(ARemoteManagers);
  if Assigned(FOnEndManagersDiscovery) then
  begin
    if SynchronizeEvents then
      TThread.Synchronize(nil,
        procedure
        begin
          FOnEndManagersDiscovery(Self, ARemoteManagers);
        end)
    else
      FOnEndManagersDiscovery(Self, ARemoteManagers);
  end
end;

Interestingly, for example, the OnRequestStorage event works because it uses directly FOnRequestStorage(Self, AStorage) instead of TThread.Synchronize to update the event.有趣的是,例如 OnRequestStorage 事件之所以起作用,是因为它直接使用 FOnRequestStorage(Self, AStorage) 而不是 TThread.Synchronize 来更新事件。

procedure TTetheringManager.DoRequestStorage(var AStorage: TTetheringCustomStorage);
begin
  AStorage := nil;
  if Assigned(FOnRequestStorage) then
    FOnRequestStorage(Self, AStorage);
end;

Update : Now I have found that the easiest way to solve this problem will be to disable SynchroniyeEvents for booth TetheringManager and TetheringAppProfile.更新现在我发现解决这个问题的最简单方法是禁用 TetheringManager 和 TetheringAppProfile 的 SynchroniyeEvents。

if you do an AutoConnect without a timeout than the Event for EndofAutoConnect is fired!如果您在没有超时的情况下执行自动连接,则会触发 EndofAutoConnect 事件! found that today ...发现今天...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM