Android 的代理混淆文档资源

发布于 2025-01-07 09:34:09 字数 1266 浏览 0 评论 0原文

在我看来,关于 Android 上的代理主题有很多令人困惑的资源。

首先,似乎 Proxy 类 的所有方法都是声明已弃用,建议:

“使用标准 java vm 代理值来查找主机、端口和 排除列表。此调用忽略排除列表。”

官方 java vm proxy值可以通过以下方式访问:

System.getProperty("http.proxyHost")
System.getProperty("http.proxyPort")
System.getProperty("http.nonProxyHosts")

这似乎可以通过 代理选择器但

在真实设备或模拟器上尝试后,在查看隐藏的 Android 源代码后,这些值似乎总是空的。 .grepcode.com/java/ext/com.google.android/android-apps/2.3.7_r1/com/android/settings/ProxySelector.java#ProxySelector.saveToDb%28%29" rel="noreferrer">ProxySelector 活动,似乎代理通过以下方式保存到系统的安全设置中:

Settings.Secure.putString(res, Settings.Secure.HTTP_PROXY, hostname);

并且只有操作系统提供商签名的应用程序才能写入安全设置。仅在读取模式下通过以下方式访问这些设置:

Settings.Secure.getString(getApplicationContext().getContentResolver(),Settings.Secure.HTTP_PROXY);

有人可以澄清这是否是正确的读取方式:如何将代理设置访问到 Android? (至少看起来有效)。如果这是正确的解释,为什么文档中充满了错误?

It seems to me that there is a lot of confusing resources regarding the proxy topic on Android.

First of all, it seems that all the methods of the Proxy class are declared deprecated and it's suggested to:

"Use standard java vm proxy values to find the host, port and
exclusion list. This call ignores the exclusion list."

The official java vm proxy values can be accessed in the following way:

System.getProperty("http.proxyHost")
System.getProperty("http.proxyPort")
System.getProperty("http.nonProxyHosts")

This could seem confirmed by the documentation of the ProxySelector class.

But trying on a real device or an emulator, these values seems to me always empty. After looking to the Android source code of the hidden ProxySelector activity, it seems that the proxy is saved into the secure settings of the system in the following way:

Settings.Secure.putString(res, Settings.Secure.HTTP_PROXY, hostname);

And only an application signed by the OS provider can write to the secure settings. Developers can access these settings only in read mode in the following way:

Settings.Secure.getString(getApplicationContext().getContentResolver(),Settings.Secure.HTTP_PROXY);

Someone can clarify if this is the correct reading of how can be access the proxy settings into Android? (At least it seems to work). If this is the correct intepretation, why the documentation is so full of errors?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

冷夜 2025-01-14 09:34:09

要获取代理值,按照您所做的那样访问系统属性应该可行;没有必要访问安全设置。如果您无法使用系统属性读取通过普通设备 UI 进行的代理设置,则存在问题。代理根据网络类型而定,因此 APN 和 WiFi 将具有单独的代理设置。

For getting proxy values, accessing the System properties as you have done should work; it should not be necessary to access secure settings. If you cannot use the System properties to read proxy settings that were made through the normal device UI, then there is a problem. Proxies are per network type, so the APN and WiFi will have separate proxy settings.

慈悲佛祖 2025-01-14 09:34:09

我不知道这是否是访问代理设置的“正确”方式,但这是您访问系统“安全设置”的正确且唯一的方式。

也许这个也很有趣,看起来它让事情变得更容易,特别是如果有是Wifi代理(Android支持这样的东西吗?)。至少对于不同的 Android 版本来说它看起来是很棒的抽象。

I don't know if it's the "right" way to access the proxy settings but it's the right and only way you should access the system "secure settings".

Maybe this is also interesting, looks like it makes things easier, especially if there are Wifi proxys (does Android support something like this?). At least it looks like great abstraction for the various android versions.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文