SoftApHelper icon indicating copy to clipboard operation
SoftApHelper copied to clipboard

关于隐藏热点类型在Android14上的问题

Open tegzwn opened this issue 1 month ago • 31 comments

设备:Redmi 12 5G 系统:Android14(HyperOS1) 问题: 在使用iOS设备连接Android设备开启的热点后发现iOS设备会在锁屏后一段时间自动断开与热点的链接。 用pc上的软件发现是Android设备将Access Network Type设置成Chargeable public network (2)导致的, 搜索源码后发现在 https://xrefandroid.com/android-14.0.0_r21/xref/hardware/interfaces/wifi/hostapd/aidl/android/hardware/wifi/hostapd/NetworkParams.aidl#42 中开启hostapd时存在

/**
     * Enable the interworking service and set access network type to
     * CHARGEABLE_PUBLIC_NETWORK when set to true.
     */
    boolean isMetered;
    /**
     * Additional vendor specific elements for Beacon and Probe Response frames
     * This parameter can be used to add additional vendor specific element(s) into
     * the end of the Beacon and Probe Response frames. The format for these
     * element(s) is a binary dump of the raw information elements (id+len+payload for
     * one or more elements). Example: byte[]{ 221, 4, 17, 34, 51, 1 }
     */
    byte[] vendorElements;

搜索布尔值 isMetered时发现在 https://xrefandroid.com/android-14.0.0_r21/xref/frameworks/base/packages/SettingsLib/src/com/android/settingslib/wifi/AccessPoint.java#mIsScoredNetworkMetered 中存在

    /**
     * Updates the AccessPoint's metering based on {@link ScoredNetwork#meteredHint}, returning
     * true if the metering changed.
     */
    private boolean updateMetered(WifiNetworkScoreCache scoreCache) {
        boolean oldMetering = mIsScoredNetworkMetered;
        mIsScoredNetworkMetered = false;

        if (isActive() && mInfo != null) {
            NetworkKey key = NetworkKey.createFromWifiInfo(mInfo);
            ScoredNetwork score = scoreCache.getScoredNetwork(key);
            if (score != null) {
                mIsScoredNetworkMetered |= score.meteredHint;
            }
        } else {
            synchronized (mLock) {
                for (ScanResult result : mScanResults) {
                    ScoredNetwork score = scoreCache.getScoredNetwork(result);
                    if (score == null) {
                        continue;
                    }
                    mIsScoredNetworkMetered |= score.meteredHint;
                }
            }
        }
        return oldMetering != mIsScoredNetworkMetered;
    }

    /**
     * Returns if the network should be considered metered.
     */
    public boolean isMetered() {
        return mIsScoredNetworkMetered
                || WifiConfiguration.isMetered(mConfig, mInfo);
    }

导致返回为计费网络,由于我不会写java所以想让作者添加一下这个hook,这样热点就不会使iOS设备断连了。 谢谢作者的辛苦付出!

附图: Image

tegzwn avatar Jan 20 '25 11:01 tegzwn