【发布时间】:2018-05-21 20:21:52
【问题描述】:
我正在设计的应用程序使用 VpnService 以及 VpnService.Builder 类来生成 VPN,以阻止来自特定应用程序的流量。根据 developer.android.com 上的文档,在调用 Builder.AddAllowedApplication 或 Builder.AddDisallowedApplication 之前,应允许所有应用程序通过 VPN。
当我的 VPN 服务启动时,由于某种原因,所有应用程序都被禁止使用,这很奇怪。一旦我与 VPN 断开连接,所有应用程序就会再次可用。我需要允许所有,除非另有说明(这是文档所说的应该发生的)。我通过调用以下命令启动 VPN:
private string _sTag = typeof(VpnService).Name;
private VpnServiceBinder _objBinder;
private ParcelFileDescriptor _objVpnInterface = null;
private PendingIntent _objPendingIntent = null;
...
if (_objVpnInterface == null)
{
Builder objVpnBuilder = new Builder(this);
objVpnBuilder.AddAddress("10.0.0.2", 32);
objVpnBuilder.AddRoute("0.0.0.0", 0);
// Form the interface
_objVpnInterface = objVpnBuilder.SetSession("Squelch").SetConfigureIntent(_objPendingIntent).Establish();
// Disallow instagram as a test
objVpnBuilder.AddDisallowedApplication("com.instagram.android");
// Set flag
_bVpnIsRunning = true;
}
所以在上面的例子中,instagram 应该是唯一被阻止的应用程序,但所有流量似乎都被阻止(无法使用 chrome 应用程序、facebook 等)。在这方面我有什么遗漏吗?我应该在建立接口之前/之后指定一些东西吗?任何帮助或指导将不胜感激!
注意:如果重要的话,我的目标是 android 6.0 及更高版本。如果需要,我可以提供更多来源。
【问题讨论】:
标签: c# android xamarin xamarin.android