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 com.android.server.uwb.UwbInjector; 20 21 import com.google.uwb.support.aliro.AliroParams; 22 import com.google.uwb.support.base.Params; 23 import com.google.uwb.support.base.ProtocolVersion; 24 import com.google.uwb.support.ccc.CccParams; 25 import com.google.uwb.support.fira.FiraParams; 26 import com.google.uwb.support.radar.RadarParams; 27 import com.google.uwb.support.rftest.RfTestParams; 28 29 public abstract class TlvEncoder { 30 /** 31 * Get the appropriate TlvEncoder implementation, based upon the {@code protocolName}. 32 */ getEncoder(String protocolName, UwbInjector uwbInjector)33 public static TlvEncoder getEncoder(String protocolName, UwbInjector uwbInjector) { 34 if (protocolName.equals(FiraParams.PROTOCOL_NAME)) { 35 return new FiraEncoder(uwbInjector); 36 } 37 if (protocolName.equals(CccParams.PROTOCOL_NAME)) { 38 return new CccEncoder(uwbInjector); 39 } 40 if (protocolName.equals(AliroParams.PROTOCOL_NAME)) { 41 return new AliroEncoder(uwbInjector); 42 } 43 if (protocolName.equals(RadarParams.PROTOCOL_NAME)) { 44 return new RadarEncoder(); 45 } 46 if (protocolName.equals(RfTestParams.PROTOCOL_NAME)) { 47 return new RfTestEncoder(); 48 } 49 return null; 50 } 51 52 /** 53 * Convert the given {@code Params} into a TLV representation (that can be sent to the UWBS). 54 */ getTlvBuffer(Params param, ProtocolVersion protocolVersion)55 public abstract TlvBuffer getTlvBuffer(Params param, ProtocolVersion protocolVersion); 56 } 57