android 开启6g热点,设定的band值为5,最终写入文件的band值却为7.

packages/apps/Settings/src/com/android/settings/wifi/tether/WifiTetherApBandPreferenceController.java

这个类在开启热点的界面负责设置热点的频段。

在解决一个热点的问题时,发现设置6G热点的时候明明设置的值为5 ,在保存到xml文件的时候就变为了7.   导致获取频段值时没有对应上。

在开启热点的界面里,选择频段时。会先将热点的配置保存在一个xml文件里面。开启热点时,会直接拿取配置文件的值进行开启热点。

这个配置文件在手机的  data/misc/apexdata/com.android.wifi/     下。里面有两个配置文件,一个是wifi的,一个是热点的。

设置的方法为     wifiManager.setSoftApConfiguration()

这个的实现是在packages/modules/Wifi/service/java/com/android/server/wifi/WifiServiceImpl.java

@Override
    public boolean setSoftApConfiguration(
            @NonNull SoftApConfiguration softApConfig, @NonNull String packageName) {
        int uid = Binder.getCallingUid();
        mWifiPermissionsUtil.checkPackage(uid, packageName);
        boolean privileged = mWifiPermissionsUtil.checkNetworkSettingsPermission(uid);
        if (!mWifiPermissionsUtil.checkConfigOverridePermission(uid)
                && !privileged) {
            // random apps should not be allowed to read the user specified config
            throw new SecurityException("App not allowed to read or update stored WiFi Ap config "
                    + "(uid = " + uid + ")");
        }
        mLog.info("setSoftApConfiguration uid=%").c(uid).flush();
        if (softApConfig == null) return false;
        if (WifiApConfigStore.validateApWifiConfiguration(softApConfig, privileged, mContext)) {
            mWifiApConfigStore.setApConfiguration(softApConfig);
            // Send the message for AP config update after the save is done.
            mActiveModeWarden.updateSoftApConfiguration(softApConfig);
            return true;
        } else {
            Log.e(TAG, "Invalid SoftAp Configuration");
            return false;
        }
    }

看这个  mWifiApConfigStore.setApConfiguration(softApConfig);

packages/modules/Wifi/service/java/com/android/server/wifi/WifiApConfigStore.java

public synchronized void setApConfiguration(SoftApConfiguration config) {
        SoftApConfiguration newConfig = config == null ? getDefaultApConfiguration()
                : new SoftApConfiguration.Builder(sanitizePersistentApConfig(config))
                        .setUserConfiguration(true).build();
        persistConfigAndTriggerBackupManagerProxy(
                updatePersistentRandomizedMacAddress(newConfig));
    }

关注   sanitizePersistentApConfig(config)

private SoftApConfiguration sanitizePersistentApConfig(SoftApConfiguration config) {
        SoftApConfiguration.Builder convertedConfigBuilder =
                new SoftApConfiguration.Builder(config);
        int[] bands = config.getBands();
        SparseIntArray newChannels = new SparseIntArray();
        // The bands length should always 1 in R. Adding SdkLevel.isAtLeastS for lint check only.
        for (int i = 0; i < bands.length; i++) {
            int channel = SdkLevel.isAtLeastS()
                    ? config.getChannels().valueAt(i) : config.getChannel();
            int newBand = bands[i];
            if (channel == 0 && mIsAutoAppendLowerBandEnabled
                    && ApConfigUtil.isBandSupported(newBand, mContext)) {
                // some countries are unable to support 5GHz only operation, always allow for 2GHz
                // when config doesn't force channel
                if ((newBand & SoftApConfiguration.BAND_2GHZ) == 0) {
                    newBand = ApConfigUtil.append24GToBandIf24GSupported(newBand, mContext);
                }
                // If the 6G configuration doesn't includes 5G band (2.4G have appended because
                // countries reason), it will cause that driver can't switch channel from 6G to
                // 5G/2.4G when coexistence happened (For instance: wifi connected to 2.4G or 5G
                // channel). Always append 5G into band configuration when configured band includes
                // 6G.
                if ((newBand & SoftApConfiguration.BAND_6GHZ) != 0
                        && (newBand & SoftApConfiguration.BAND_5GHZ) == 0) {
                    newBand = ApConfigUtil.append5GToBandIf5GSupported(newBand, mContext);
                }
            }
            newChannels.put(newBand, channel);
        }
        if (SdkLevel.isAtLeastS()) {
            convertedConfigBuilder.setChannels(newChannels);
        } else if (bands.length > 0 && newChannels.valueAt(0) == 0) {
            convertedConfigBuilder.setBand(newChannels.keyAt(0));
        }
        return convertedConfigBuilder.build();

看这个

if ((newBand & SoftApConfiguration.BAND_6GHZ) != 0
&& (newBand & SoftApConfiguration.BAND_5GHZ) == 0) {
newBand = ApConfigUtil.append5GToBandIf5GSupported(newBand, mContext);
}

packages/modules/Wifi/service/java/com/android/server/wifi/util/ApConfigUtil.java

public static @BandType int append5GToBandIf5GSupported(@BandType int targetBand,
            Context context) {
        if (isBandSupported(SoftApConfiguration.BAND_5GHZ, context)) {
            return targetBand | SoftApConfiguration.BAND_5GHZ;
        }
        return targetBand;
    }

这个方法里面会将传入的5  加上  2  就变为了  7

至于原因上面也做出了解释。

如果6G配置不包括5G频段(由于国家原因,附加了2.4G),则会导致共存时驱动器无法将信道从6G切换到5G/2.4G(例如:连接到2.4G或5G信道的wifi)。当配置的频段包括6G时,始终将5G附加到频段配置中。

觉得有用的话就点个赞吧!!谢谢大家。

  • 3
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
GDAL的Java API中,band.ReadRaster()方法是用来读取一个数据集中的指定波段的像素的方法。该方法的参数包括起始行、起始列、读取的行数、读取的列数以及一个数据缓冲区。读取到的像素会被存储到这个数据缓冲区中。这个方法的返回值为一个布尔,表示读取是否成功。 具体来说,该方法的语法为: ``` public boolean ReadRaster(int xoff, int yoff, int xsize, int ysize, int buf_xsize, int buf_ysize, int buf_type, byte[] buffer, int buf_pixel_space, int buf_line_space) ``` 其中,各参数的含义如下: - xoff:起始列的位置(从0开始) - yoff:起始行的位置(从0开始) - xsize:读取的列数 - ysize:读取的行数 - buf_xsize:缓冲区的列数 - buf_ysize:缓冲区的行数 - buf_type:缓冲区中像素的数据类型,可以是以下类型之一: - DataType.GDT_Byte - DataType.GDT_Int16 - DataType.GDT_UInt16 - DataType.GDT_Int32 - DataType.GDT_UInt32 - DataType.GDT_Float32 - DataType.GDT_Float64 - buffer:用于存储读取到的像素的缓冲区 - buf_pixel_space:缓冲区中相邻像素之间的字节数 - buf_line_space:缓冲区中相邻行之间的字节数 例如,下面的代码片段演示了如何使用band.ReadRaster()方法读取第一个波段中的所有像素: ```java import org.gdal.gdal.Band; import org.gdal.gdal.Dataset; import org.gdal.gdal.gdal; import org.gdal.gdalconst.gdalconst; public class ReadRasterExample { public static void main(String[] args) { // 注册GDAL驱动程序 gdal.AllRegister(); // 打开数据集 Dataset dataset = gdal.Open("path/to/dataset.tif", gdalconst.GA_ReadOnly); // 获取第一个波段 Band band = dataset.GetRasterBand(1); // 读取所有像素 int width = dataset.getRasterXSize(); int height = dataset.getRasterYSize(); byte[] buffer = new byte[width * height]; band.ReadRaster(0, 0, width, height, width, height, gdalconst.GDT_Byte, buffer, 0, 0); // 输出像素 for (int i = 0; i < buffer.length; i++) { System.out.print(buffer[i] + " "); } } } ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值