为什么ping只能在某些设备上运行而不能在其他设备上运行? [英] Why does ping works on some devices and not others?

查看:102
本文介绍了为什么ping只能在某些设备上运行而不能在其他设备上运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序中包含以下代码...

I have the following code in my app...

Runtime runtime = Runtime.getRuntime();
Process process = runtime.exec("/system/bin/ping -c 1 8.8.8.8");
return process.waitFor();

...,我发现它在某些设备(例如,摩托罗拉G)上可以正常工作(返回0),但在其他设备(例如Galaxy S3)上却不可以工作(返回2).我已经检查了Galaxy S3设备,它肯定有一个"/system/bin/ping"文件,当然,我已经确保它确实已连接到互联网.

... and I'm seeing that it works (returns 0) on some devices (e.g. Motorola G) but doesn't work (returns 2) on other devices (e.g. Galaxy S3). I've checked the Galaxy S3 device and it definitely has a "/system/bin/ping" file and of course I've made sure that it is indeed connected to the internet.

任何人都知道为什么该命令在某些设备上可能不起作用的原因……以及如何使该命令起作用?

Anyone have any ideas why the command might not work on some devices... and what I can do to get it to work?

推荐答案

为每个OEM(原始设备制造商)实施ping的方式可能有所不同.这不仅限于ping.例如,尝试在adb shell上的旧Samsung设备(S3)和较新的设备(Motorola G)上运行linux du命令.

The way ping is implemented for every OEM (Original Equipment Manufacturer) may be different. This is not only limited to ping. For example, try running the linux du command on old Samsung devices (S3) and newer devices (Motorola G) on adb shell.

S3确实支持du,但是它不带某些参数,例如-m(以兆字节显示),而较新的设备(例如Moto G或什至三星设备(过去的Galaxy S5))都支持du.尝试在S3的adb shell上运行ping -c 1 8.8.8.8,您会注意到这不是Java代码,而是OEM.

The S3 does support du, but it does not take some parameters such as -m (display in megabytes), while newer devices such as Moto G or even Samsung devices (past Galaxy S5) does support it. Try running ping -c 1 8.8.8.8 on adb shell within S3, and you'll note that it's not your Java code, it's the OEM.

同样,根据Android版本和设备的不同,甚至连dumpsys之类的命令也具有不同格式的输出.因此,最好是使用一种完全不同的方法来尝试使用Android中提供的API对所需IP进行ping操作,而不是使用具有每个OEM支持的参数不同的进程.

Again, even commands such as dumpsys have differently formatted output depending on Android Version and device. Because of this, it would be best if you can use a completely different method to try pinging the desired IP using APIs provided in Android instead of using a process with parameters that might be differently supported per OEM.

每个设备的权限也可能不同.

It can also be that the permissions are different per device.

在应用程序中运行流程时,仅授予该应用程序对该流程的有限权限.因此,如果ping需要root级别的权限(在特定设备上),这也可能是ping不起作用的原因.最终由OEM决定他们如何定制Android.

When you run a process within your app, you only are granting the app's limited permissions to the process. So if ping requires root level permission (on the specific device), that may also be the reason why it does not work. It is ultimately up to the OEM of how they customized Android.

来源:我在OEM部门工作.

Source: I work at an OEM.

这篇关于为什么ping只能在某些设备上运行而不能在其他设备上运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆