1 /* 2 * Copyright (C) 2023 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.server.uwb.params; 18 19 import static com.android.server.uwb.config.CapabilityParam.RADAR_SUPPORT; 20 import static com.android.server.uwb.config.CapabilityParam.RADAR_SWEEP_SAMPLES_SUPPORTED; 21 22 import com.google.uwb.support.base.Params; 23 import com.google.uwb.support.base.ProtocolVersion; 24 import com.google.uwb.support.radar.RadarParams; 25 import com.google.uwb.support.radar.RadarSpecificationParams; 26 27 /** Radar decoder */ 28 public class RadarDecoder extends TlvDecoder { 29 @Override getParams(TlvDecoderBuffer tlvs, Class<T> paramsType, ProtocolVersion protocolVersion)30 public <T extends Params> T getParams(TlvDecoderBuffer tlvs, Class<T> paramsType, 31 ProtocolVersion protocolVersion) 32 throws IllegalArgumentException { 33 if (RadarSpecificationParams.class.equals(paramsType)) { 34 return (T) getRadarSpecificationParamsFromTlvBuffer(tlvs); 35 } 36 return null; 37 } 38 isBitSet(int flags, int mask)39 private static boolean isBitSet(int flags, int mask) { 40 return (flags & mask) != 0; 41 } 42 getRadarSpecificationParamsFromTlvBuffer( TlvDecoderBuffer tlvs)43 private RadarSpecificationParams getRadarSpecificationParamsFromTlvBuffer( 44 TlvDecoderBuffer tlvs) { 45 RadarSpecificationParams.Builder builder = new RadarSpecificationParams.Builder(); 46 47 byte radarCapabilities = tlvs.getByte(RADAR_SUPPORT); 48 if (isBitSet(radarCapabilities, RADAR_SWEEP_SAMPLES_SUPPORTED)) { 49 builder.addRadarCapability( 50 RadarParams.RadarCapabilityFlag.HAS_RADAR_SWEEP_SAMPLES_SUPPORT); 51 } 52 return builder.build(); 53 } 54 } 55