2

我正在做一个使用 tun 作为 Android 上的虚拟网络设备的网络应用程序。我关闭了其他可用接口,例如 eth0(用于 WLAN)和 rmnet0(用于 3G/GPRS),但保持 tun0 设备处于活动状态并在路由表中添加规则

ip route add default dev tun0

所以我可以将所有互联网传输重定向到 tun 设备(我在这里所做的与 OpenVPN 相同)。然后我在ping其他IP时看到了数据传输。浏览器和其他一些应用程序工作正常。

但是一些安卓应用在访问网络之前会通过 ConnectivityManager 来检查 Connectivity。由于我关闭了 WIFI 和 3G/GPRS,ConnectivityManager 认为没有连接,这些应用程序将不再访问网络。

所以我的问题是:

如何欺骗android ConnectiviyManager,让它相信仍然有可用的连接(对于任何类型)?

4

1 回答 1

0

I don't think you can do this, and you wouldn't want to, it's a system-wide service. Imagine if your app relied on internet connectivity, but some malicious app was able to tell you there was and make your app unable to complete it's actions. It could cause a serious problem.

If your app needs to believe there is a connection in some states, I suggest you interface the connectivity / network classes, you can read the true state but then return whichever value you deem fit to your app

于 2014-01-27T21:14:53.600 回答