[[["易于理解","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"]],["最后更新时间 (UTC):2025-03-26。"],[],[],null,["# Wi-Fi Aware\n\nThe\n[Wi-Fi Aware](https://developer.android.com/guide/topics/connectivity/wifi-aware.html)\nfeature added in Android 8.0 enables supporting devices to discover, connect,\nand range (added in Android 9) to one another directly\nusing the Wi-Fi Aware protocol without internet or cellular network access. This\nfeature, built upon the [Wi-Fi Alliance](https://www.wi-fi.org/)\n(WFA)\n[Wi-Fi Aware specification](https://www.wi-fi.org/discover-wi-fi/wi-fi-aware)\n(versions 2.0, 3.0, 3.1 and 4.0), allows easy sharing of high-throughput data\namong trusted devices and apps that are otherwise off-network.\n\nExamples and source\n-------------------\n\nTo use this feature, device manufacturers should implement the Wi-Fi Vendor HAL.\nIn Android 14 and higher,\nthe Vendor HAL interface is defined using AIDL.\nFor Android 13 and lower,\nthe Vendor HAL interface is defined using HIDL.\n\nFollow the Wi-Fi interface to employ the Wi-Fi Aware feature.\nDepending on which interface is implemented, this is either:\n\n- AIDL: `hardware/interfaces/wifi/aidl`\n- HIDL: `hardware/interfaces/wifi/1.2` or later\n\nYou can refer to the legacy Wi-Fi HAL to see how it correlates with the\nAIDL and HIDL interfaces:\n[hardware/libhardware_legacy/+/android16-release/include/hardware_legacy/wifi_nan.h](https://android.googlesource.com/platform/hardware/libhardware_legacy/+/android16-release/include/hardware_legacy/wifi_nan.h).\n\nImplementation\n--------------\n\nDevice manufacturers need to provide both framework and HAL/firmware support:\n\n- Framework:\n - AOSP code\n - Enable Aware: Requires both a feature flag and a build flag\n- Wi-Fi Aware (NAN) HAL support (which implies firmware support)\n\nTo implement this feature, device manufacturers implement the Wi-Fi interface\nand enable two feature flags:\n\n- In `BoardConfig.mk` or `BoardConfig-common.mk` located in\n `device/\u003coem\u003e/\u003cdevice\u003e`, add the following flag:\n\n WIFI_HIDL_FEATURE_AWARE := true\n\n- In `device.mk` located in `device/\u003coem\u003e/\u003cdevice\u003e`, modify the\n `PRODUCT_COPY_FILES` environment variable to include support for the Wi-Fi\n Aware feature:\n\n PRODUCT_COPY_FILES +=\n frameworks/native/data/etc/android.hardware.wifi.aware.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.wifi.aware.xml\n\nWi-Fi Aware includes ranging to peer devices using the IEEE 802.11mc protocol,\nalso known as Round Trip Time (RTT). This sub-feature of Wi-Fi Aware is\nconditional on the device supporting the Wi-Fi RTT feature, that is, it requires\nthe device to support both Wi-Fi Aware and Wi-Fi RTT. For more details, see\n[Wi-Fi RTT](/docs/core/connect/wifi-rtt).\n\nOtherwise, everything required for this feature is included in AOSP.\n\nThe `WIFI_HIDL_FEATURE_AWARE` flag is ignored if the\n`WIFI_HAL_INTERFACE_COMBINATIONS`\nflag is specified. For more information, see\n[Wi-Fi multi-interface concurrency](/docs/core/connect/wifi-hal#wi-fi_multi-interface_concurrency).\n\nMAC randomization\n-----------------\n\nAndroid requires the MAC address of the Wi-Fi Aware discovery (NMI) and data\ninterfaces (NDPs) to be randomized and not be identical to the true MAC address\nof the device. The MAC addresses must be:\n\n- Randomized whenever Wi-Fi Aware is enabled or re-enabled.\n- When Wi-Fi Aware is enabled, the MAC address must be randomized at a regular\n interval configured by the\n `NanConfigRequest.macAddressRandomizationIntervalSec` parameter. This\n is configured by the framework by default to be 30 minutes.\n\n | **Note:** Per the Wi-Fi Aware spec, randomization may be suspended while an NDP is configured. Suspension does not imply that the factory MAC address is used (it must never be used for Wi-Fi Aware), but that the MAC address is re-randomized less frequently than otherwise required.\n\nSuspend and resume\n------------------\n\nIn Android 14 and higher, Wi-Fi Aware supports the\nability for privileged apps to suspend and resume active discovery sessions\n(including all data paths associated with those sessions). Supporting this\nability lets devices resume discovery sessions faster and use less power because\ndiscovery sessions can be suspended.\n\nIf a device supports this suspend and resume ability, the firmware suspends\nthe Wi-Fi Aware session when a privileged app suspends the discovery session.\nWhen a discovery session is in a suspended state, the device doesn't transmit\nor receive any frames for that session including any active NDPs in that\nsession. If all discovery sessions are suspended, the device doesn't transmit\nor receive any Wi-Fi Aware frames.\n\nWhen a privileged app resumes a suspended discovery session, the framework\nreturns the session to its previous state, including all associated NDP\nsessions. Resuming a suspended discovery session is faster than bringing up\nWi-Fi Aware and creating a new discovery session.\n\nTo support the ability to suspend and resume discovery sessions, device\nmanufacturers must provide HAL and firmware support. For details, see\n[`IWifiNanIface.java`](https://android.googlesource.com/platform/packages/modules/Wifi/+/refs/heads/android16-release/service/java/com/android/server/wifi/hal/IWifiNanIface.java).\n\nDevice manufacturers can use out-of-band communications (for example, BLE) to\nsynchronize suspend and resume on multiple devices.\n| **Note:** As per the Wi-Fi Aware specification, if a NAN device transmits an unaligned schedule attribute that indicates it's not available in specified unaligned windows (ULWs) on any band or channel, other NAN devices receiving such unaligned schedule attributes must not transmit any frames to the NAN device during the specified ULWs.\n\nValidation\n----------\n\nAndroid provides a set of unit tests,\n[Compatibility Test Suite (CTS)](/docs/compatibility/cts) tests, and\n[CTS Verifier](/docs/compatibility/cts/verifier) tests to validate the Wi-Fi\nAware feature. Wi-Fi Aware can also be tested using the\n[Vendor Test Suite (VTS)](/docs/core/tests/vts).\n\n### Unit tests\n\nThe Wi-Fi Aware package tests are executed using:\n\nService tests: \n\n atest com.android.server.wifi.aware\n\nManager tests: \n\n atest android.net.wifi.aware\n\n### Compatibility Test Suite (CTS) tests\n\nUse CTS tests to validate the Wi-Fi Aware feature. CTS detects when the feature\nis enabled and automatically includes the associated tests.\n\nThe CTS tests can be triggered using: \n\n atest SingleDeviceTest\n\n### CTS Verifier tests\n\nCTS Verifier tests validate Wi-Fi Aware behavior using two devices: a test\ndevice and a *known good* device. To run the tests, open CTS Verifier and\nnavigate to the section titled Wi-Fi Aware Tests."]]