ตั้งแต่วันที่ 27 มีนาคม 2025 เป็นต้นไป เราขอแนะนำให้ใช้ android-latest-release
แทน aosp-main
เพื่อสร้างและมีส่วนร่วมใน AOSP โปรดดูข้อมูลเพิ่มเติมที่หัวข้อการเปลี่ยนแปลงใน AOSP
ภาพรวมสถิติอินเทอร์เฟซเครือข่าย
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
ใน Android 4.0 ระบบจะบันทึกสถิติที่อินเทอร์เฟซเครือข่าย Linux รายงานไว้เมื่อเวลาผ่านไป และใช้เพื่อบังคับใช้ขีดจำกัดโควต้าเครือข่าย แสดงผลแผนภูมิที่ผู้ใช้มองเห็น และอื่นๆ
โปรแกรมควบคุมอุปกรณ์เครือข่ายแต่ละรายการ (รวมถึง Wi-Fi) ต้องเป็นไปตามวงจรของอุปกรณ์เคอร์เนลมาตรฐาน และแสดงสถิติที่ถูกต้องผ่าน dev_get_stats()
โดยเฉพาะอย่างยิ่ง สถิติที่แสดงผลต้องเพิ่มขึ้นอย่างสม่ำเสมอขณะที่อินเทอร์เฟซทำงานอยู่ โปรแกรมควบคุมจะรีเซ็ตสถิติได้ก็ต่อเมื่อ unregister_netdev()
หรือรายการที่เทียบเท่าซึ่งสร้างเหตุการณ์ NETDEV_UNREGISTER
สําหรับการเรียกกลับที่ลงทะเบียนด้วย register_netdevice_notifier()
/
register_inetaddr_notifier()
/ register_inet6addr_notifier()
เสร็จสมบูรณ์แล้วเท่านั้น
โดยปกติแล้วผู้ให้บริการเครือข่ายมือถือจะวัดปริมาณการใช้อินเทอร์เน็ตที่ชั้นอินเทอร์เน็ต (IP) เพื่อให้สอดคล้องกับแนวทางนี้ใน Android 4.0 เราอาศัยข้อเท็จจริงที่ว่า
สำหรับอุปกรณ์เคอร์เนลที่เราสนใจ rx_bytes
และ tx_bytes
ค่าที่ dev_get_stats()
แสดงผลจะแสดงข้อมูลที่โอนในเลเยอร์อินเทอร์เน็ต (IP
) ไบต์อย่างตรงที่สุด แต่เราเข้าใจว่าอุปกรณ์อื่นๆ อาจไม่เป็นไปตามนี้ ขณะนี้ฟีเจอร์นี้ใช้ลักษณะเฉพาะนี้ ไดรเวอร์ใหม่ควรมีพร็อพเพอร์ตี้ดังกล่าวด้วย และค่า dev_get_stats()
ต้องไม่มีค่าใช้จ่ายเพิ่มเติมในการเข้ารหัสของเลเยอร์เครือข่ายที่ต่ำกว่า (เช่น ส่วนหัวอีเทอร์เน็ต) และไม่ควรรวมการรับส่งข้อมูลอื่นๆ (เช่น ARP) เว้นแต่จะมีค่าเล็กน้อย
เฟรมเวิร์ก Android จะรวบรวมสถิติจากอินเทอร์เฟซเครือข่ายที่เชื่อมโยงกับ NetworkStateTracker
ใน ConnectivityService
เท่านั้น ซึ่งช่วยให้เฟรมเวิร์กระบุอินเทอร์เฟซเครือข่ายแต่ละรายการได้อย่างแน่ชัด รวมถึงประเภท (เช่น TYPE_MOBILE
หรือ TYPE_WIFI
) และข้อมูลประจำตัวของผู้สมัครใช้บริการ (เช่น IMSI) อินเทอร์เฟซเครือข่ายทั้งหมดที่ใช้เพื่อกำหนดเส้นทางข้อมูลควรแสดงด้วย NetworkStateTracker
เพื่อให้สามารถพิจารณาสถิติได้อย่างถูกต้อง
ตัวอย่างเนื้อหาและโค้ดในหน้าเว็บนี้ขึ้นอยู่กับใบอนุญาตที่อธิบายไว้ในใบอนุญาตการใช้เนื้อหา Java และ OpenJDK เป็นเครื่องหมายการค้าหรือเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-03-26 UTC
[[["เข้าใจง่าย","easyToUnderstand","thumb-up"],["แก้ปัญหาของฉันได้","solvedMyProblem","thumb-up"],["อื่นๆ","otherUp","thumb-up"]],[["ไม่มีข้อมูลที่ฉันต้องการ","missingTheInformationINeed","thumb-down"],["ซับซ้อนเกินไป/มีหลายขั้นตอนมากเกินไป","tooComplicatedTooManySteps","thumb-down"],["ล้าสมัย","outOfDate","thumb-down"],["ปัญหาเกี่ยวกับการแปล","translationIssue","thumb-down"],["ตัวอย่าง/ปัญหาเกี่ยวกับโค้ด","samplesCodeIssue","thumb-down"],["อื่นๆ","otherDown","thumb-down"]],["อัปเดตล่าสุด 2025-03-26 UTC"],[],[],null,["# Network interface statistics overview\n\nIn Android 4.0, statistics reported by Linux network interfaces are\nrecorded over time, and are used to enforce network quota limits,\nrender user-visible charts, and more.\n\nEach network device driver (Wi-Fi included) must follow the standard\nkernel device lifecycle, and return correct statistics through\n`dev_get_stats()`. In particular, statistics returned must remain\nstrictly monotonic while the interface is active. Drivers may reset\nstatistics only after successfully completing an `unregister_netdev()`\nor the equivalent that generates a `NETDEV_UNREGISTER` event for\ncallbacks registered with `register_netdevice_notifier()` /\n`register_inetaddr_notifier()` / `register_inet6addr_notifier()`.\n\nMobile operators typically measure data usage at the Internet layer\n(IP). To match this approach in Android 4.0, we rely on the fact that\nfor the kernel devices we care about the `rx_bytes` and `tx_bytes`\nvalues returned by `dev_get_stats()` return exactly the Internet layer\n(`IP`) bytes transferred. But we understand that for other devices it\nmight not be the case. For now, the feature relies on this\npeculiarity. New drivers should have that property also, and the\n`dev_get_stats()` values must not include any encapsulation overhead\nof lower network layers (such as Ethernet headers), and should\npreferably not include other traffic (such as ARP) unless it is\nnegligible.\n\nThe Android framework only collects statistics from network interfaces\nassociated with a `NetworkStateTracker` in `ConnectivityService`. This\nenables the framework to concretely identify each network interface,\nincluding its type (such as `TYPE_MOBILE` or `TYPE_WIFI`) and\nsubscriber identity (such as IMSI). All network interfaces used to\nroute data should be represented by a `NetworkStateTracker` so that\nstatistics can be accounted correctly."]]