From 552bdb764ece01f57e1f174432a69f0af3b2c141 Mon Sep 17 00:00:00 2001 From: huangcm <1263938474@qq.com> Date: Sat, 26 Apr 2025 01:27:44 +0000 Subject: [PATCH] fix(DeviceTest): fix Ethernet Test pro --- android/vendor/aw/public/package/apk/DeviceTest_V1/assets/DeviceTestConfig_kickpi-k5c.xml | 10 ++-- android/vendor/aw/public/package/apk/DeviceTest_V1/src/com/DeviceTest/EthernetTestActivity.java | 105 ++++++++++++++++++++++++++++++++++++++++++++++++++++ android/vendor/aw/public/package/apk/DeviceTest_V1/src/com/DeviceTest/USBDeviceTestActivity.java | 2 + android/device/softwinner/ceres-c3/ceres_c3.mk | 2 4 files changed, 112 insertions(+), 7 deletions(-) diff --git a/android/device/softwinner/ceres-c3/ceres_c3.mk b/android/device/softwinner/ceres-c3/ceres_c3.mk index 97ac18c..89217da 100755 --- a/android/device/softwinner/ceres-c3/ceres_c3.mk +++ b/android/device/softwinner/ceres-c3/ceres_c3.mk @@ -233,7 +233,7 @@ $(LOCAL_PATH)/media/bootanimation.zip:system/media/bootanimation.zip PRODUCT_COPY_FILES += \ - vendor/aw/public/package/apk/DeviceTest_V1/assets/DeviceTestConfig_K5C.xml:vendor/etc/DeviceTestConfig.xml + vendor/aw/public/package/apk/DeviceTest_V1/assets/DeviceTestConfig_$(DTS_NAME).xml:vendor/etc/DeviceTestConfig.xml # preferred activity PRODUCT_COPY_FILES += \ diff --git a/android/vendor/aw/public/package/apk/DeviceTest_V1/assets/DeviceTestConfig_K5C.xml b/android/vendor/aw/public/package/apk/DeviceTest_V1/assets/DeviceTestConfig_kickpi-k5c.xml similarity index 89% rename from android/vendor/aw/public/package/apk/DeviceTest_V1/assets/DeviceTestConfig_K5C.xml rename to android/vendor/aw/public/package/apk/DeviceTest_V1/assets/DeviceTestConfig_kickpi-k5c.xml index 6157447..4a0efdc 100755 --- a/android/vendor/aw/public/package/apk/DeviceTest_V1/assets/DeviceTestConfig_K5C.xml +++ b/android/vendor/aw/public/package/apk/DeviceTest_V1/assets/DeviceTestConfig_kickpi-k5c.xml @@ -15,19 +15,19 @@ <TestCase class_name="WifiTestActivity" test_group="TEST ALL" first_test="yc">Wifi</TestCase> <TestCase class_name="BluetoothTestActivity" test_group="TEST ALL">Bluetooth</TestCase> - <!-- <TestCase class_name="SdCardTestActivity" test_group="TEST ALL" first_test="yc">SD Card</TestCase> --> + <TestCase class_name="SdCardTestActivity" test_group="TEST ALL" first_test="yc">SD Card</TestCase> <!-- <TestCase class_name="PCIETestActivity" test_group="TEST ALL">PCIE</TestCase> --> <!-- <TestCase class_name="SATATestActivity" test_group="TEST ALL">SATA</TestCase> --> <!-- <TestCase class_name="Ethernet2TestActivity" test_group="TEST ALL">Ethernet0</TestCase> --> - <!-- <TestCase class_name="EthernetTestActivity" test_group="TEST ALL">Ethernet1</TestCase> --> - <!-- <TestCase class_name="MobileNetTestActivity" test_group="TEST ALL">MobileNet</TestCase> --> + <TestCase class_name="EthernetTestActivity" test_group="TEST ALL">Ethernet</TestCase> + <TestCase class_name="MobileNetTestActivity" test_group="TEST ALL">MobileNet</TestCase> <TestCase class_name="InfomationActivity" test_group="TEST ALL" first_test="yc">DDR/eMMC</TestCase> <TestCase class_name="TouchTestActivity" test_group="TEST ALL">Touch</TestCase> <TestCase class_name="SpeakerTestActivity" test_group="TEST ALL" first_test="yc">Speaker</TestCase> <!-- <TestCase class_name="PhoneMicTestActivity" test_group="TEST ALL" first_test="yc">MIC</TestCase> --> - <!-- <TestCase class_name="USBDeviceTestActivity" test_group="TEST ALL">USB Device</TestCase> --> - <!-- <TestCase class_name="RTCTestActivity" test_group="TEST ALL">RTC</TestCase> --> + <TestCase class_name="USBDeviceTestActivity" test_group="TEST ALL">USB Device</TestCase> + <TestCase class_name="RTCTestActivity" test_group="TEST ALL">RTC</TestCase> <!-- <TestCase class_name="CameraBackTestActivity" test_group="TEST ALL" first_test="yc">Camera_only</TestCase> --> <!-- <TestCase class_name="RtcTestActivity" test_group="TEST ALL">RTC</TestCase> --> <!-- TestCase class_name="GpsLocationTestActivity" test_group="TEST 2">GPS Location</TestCase> --> diff --git a/android/vendor/aw/public/package/apk/DeviceTest_V1/src/com/DeviceTest/EthernetTestActivity.java b/android/vendor/aw/public/package/apk/DeviceTest_V1/src/com/DeviceTest/EthernetTestActivity.java index f95745e..5de99e4 100755 --- a/android/vendor/aw/public/package/apk/DeviceTest_V1/src/com/DeviceTest/EthernetTestActivity.java +++ b/android/vendor/aw/public/package/apk/DeviceTest_V1/src/com/DeviceTest/EthernetTestActivity.java @@ -40,6 +40,8 @@ import java.net.URL; import java.net.URLConnection; import java.util.ArrayList; +import java.net.Inet4Address; +import android.net.RouteInfo; import static android.view.WindowManager.LayoutParams.FLAG_FULLSCREEN; import static android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON; @@ -71,6 +73,7 @@ private boolean mReadyToGetEthInfo; private boolean mStop; + private ConnectivityManager mConnectivityManager; private EthernetManager mEthManager; private BroadcastReceiver mReceiver; private String mIfaceName; @@ -151,6 +154,8 @@ ControlButtonUtil.initControlButtonView(this); findViewById(R.id.btn_Pass).setVisibility(View.INVISIBLE); findViewById(R.id.btn_Fail).setVisibility(View.INVISIBLE); + + mConnectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); mEthManager = (EthernetManager) getSystemService(Context.ETHERNET_SERVICE); if (null == mEthManager) { @@ -242,12 +247,110 @@ } IpAssignment mode = ipConfiguration.getIpAssignment(); if (mode == IpAssignment.DHCP || mode == IpAssignment.UNASSIGNED) { - getEthInfoFromDhcp(); + getEthInfoFromDhcp_V1(); } else if (mode == IpAssignment.STATIC) { getEthInfoFromStaticIp(); } } + public static String intToNetmask(int prefixLength) { + if (prefixLength < 0 || prefixLength > 32) { + throw new IllegalArgumentException("Prefix length must be between 0 and 32"); + } + StringBuilder netmask = new StringBuilder(); + int[] parts = new int[4]; + // 计算每一部分的值 + for (int i = 0; i < 4; i++) { + if (prefixLength >= 8) { + parts[i] = 255; + prefixLength -= 8; + } else if (prefixLength > 0) { + parts[i] = 256 - (1 << (8 - prefixLength)); + prefixLength = 0; + } else { + parts[i] = 0; + } + } + // 构建点分十进制字符串 + for (int i = 0; i < 4; i++) { + netmask.append(parts[i]); + if (i < 3) { + netmask.append("."); + } + } + return netmask.toString(); + } + + private void getEthInfoFromDhcp_V1() { + int network = ConnectivityManager.TYPE_ETHERNET; + String mMacPreference = mConnectivityManager.getNetworkInfo(network).getExtraInfo(); + + final LinkProperties linkProperties = mConnectivityManager.getLinkProperties(network); + for (LinkAddress linkAddress : linkProperties.getLinkAddresses()) { //set ipaddress. + if (linkAddress.getAddress() instanceof Inet4Address) { + String mgetHostAddress = linkAddress.getAddress().getHostAddress(); + String netMask = intToNetmask(linkAddress.getPrefixLength()); + Log.v(TAG, "mgetHostAddress " + mgetHostAddress); + Log.v(TAG, "netMask " + netMask); + mEthIpAddress = mgetHostAddress; + mEthNetmask = netMask; + break; + } + } + + String dns1 = null; + String dns2 = null; + int dnsCount = 0; + for (InetAddress inetAddress:linkProperties.getDnsServers()) { + if (0 == dnsCount) { + dns1 = inetAddress.getHostAddress().toString(); + if (inetAddress instanceof Inet4Address) { + dns1 = inetAddress.getHostAddress().toString(); + } else { + dns1 = "0.0.0.0"; + } + } + if (1 == dnsCount) { + dns2 = inetAddress.getHostAddress().toString(); + if (inetAddress instanceof Inet4Address) { + dns2 = inetAddress.getHostAddress().toString(); + } else { + dns2 = "0.0.0.0"; + } + } + dnsCount++; + } + + mEthdns1 = dns1; + if (dnsCount > 1) { + mEthdns2 = dns2; + } else { + dns2 = "0.0.0.0"; + mEthdns2 = dns2; + } + + String Route = null; + for (RouteInfo route:linkProperties.getRoutes()) { + if (route.isIPv4Default()) { + Route = route.getGateway().toString(); + break; + } + } + if (Route != null) { + String[] RouteStr = Route.split("/"); + mEthGateway = RouteStr[1]; + } else { + mEthGateway = "0.0.0.0"; + } + Log.v(TAG, "mIfaceName " + mIfaceName); + Log.v(TAG, "mEthIpAddress " + mEthIpAddress); + Log.v(TAG, "mEthNetmask " + mEthNetmask); + Log.v(TAG, "mEthGateway " + mEthGateway); + Log.v(TAG, "mEthdns1 " + mEthdns1); + Log.v(TAG, "mEthdns2 " + mEthdns2); + + } + public void getEthInfoFromDhcp() throws Exception { boolean isSdkAfterO = Build.VERSION.SDK_INT >= ConfigUtil.ANDROID_SDK_VERSION_P; String tempIpInfo; diff --git a/android/vendor/aw/public/package/apk/DeviceTest_V1/src/com/DeviceTest/USBDeviceTestActivity.java b/android/vendor/aw/public/package/apk/DeviceTest_V1/src/com/DeviceTest/USBDeviceTestActivity.java index f13cc6c..de1ca6e 100755 --- a/android/vendor/aw/public/package/apk/DeviceTest_V1/src/com/DeviceTest/USBDeviceTestActivity.java +++ b/android/vendor/aw/public/package/apk/DeviceTest_V1/src/com/DeviceTest/USBDeviceTestActivity.java @@ -151,6 +151,8 @@ } } + // for k5c + usbNum = usbNum - 2; return usbNum; } -- Gitblit v1.6.2