1 /* 2 * Copyright (C) 2021 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.SUPPORTED_POWER_STATS_QUERY; 20 21 import com.google.uwb.support.base.Params; 22 import com.google.uwb.support.ccc.CccParams; 23 import com.google.uwb.support.ccc.CccSpecificationParams; 24 import com.google.uwb.support.fira.FiraParams; 25 import com.google.uwb.support.fira.FiraSpecificationParams; 26 import com.google.uwb.support.generic.GenericSpecificationParams; 27 28 public class GenericDecoder extends TlvDecoder { 29 @Override getParams(TlvDecoderBuffer tlvs, Class<T> paramType)30 public <T extends Params> T getParams(TlvDecoderBuffer tlvs, Class<T> paramType) { 31 if (GenericSpecificationParams.class.equals(paramType)) { 32 return (T) getSpecificationParamsFromTlvBuffer(tlvs); 33 } 34 return null; 35 } 36 getSpecificationParamsFromTlvBuffer(TlvDecoderBuffer tlvs)37 private GenericSpecificationParams getSpecificationParamsFromTlvBuffer(TlvDecoderBuffer tlvs) { 38 GenericSpecificationParams.Builder builder = new GenericSpecificationParams.Builder(); 39 FiraSpecificationParams firaSpecificationParams = 40 TlvDecoder.getDecoder(FiraParams.PROTOCOL_NAME).getParams( 41 tlvs, FiraSpecificationParams.class); 42 builder.setFiraSpecificationParams(firaSpecificationParams); 43 CccSpecificationParams cccSpecificationParams = 44 TlvDecoder.getDecoder(CccParams.PROTOCOL_NAME).getParams( 45 tlvs, CccSpecificationParams.class); 46 builder.setCccSpecificationParams(cccSpecificationParams); 47 try { 48 byte supported_power_stats_query = tlvs.getByte(SUPPORTED_POWER_STATS_QUERY); 49 if (supported_power_stats_query != 0) { 50 builder.hasPowerStatsSupport(true); 51 } 52 } catch (IllegalArgumentException e) { 53 // Do nothing. By default, hasPowerStatsSupport() returns false. 54 } 55 return builder.build(); 56 } 57 } 58