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 28 public abstract class TlvEncoder { 29 /** 30 * Get the appropriate TlvEncoder implementation, based upon the {@code protocolName}. 31 */ getEncoder(String protocolName, UwbInjector uwbInjector)32 public static TlvEncoder getEncoder(String protocolName, UwbInjector uwbInjector) { 33 if (protocolName.equals(FiraParams.PROTOCOL_NAME)) { 34 return new FiraEncoder(uwbInjector); 35 } 36 if (protocolName.equals(CccParams.PROTOCOL_NAME)) { 37 return new CccEncoder(uwbInjector); 38 } 39 if (protocolName.equals(AliroParams.PROTOCOL_NAME)) { 40 return new AliroEncoder(uwbInjector); 41 } 42 if (protocolName.equals(RadarParams.PROTOCOL_NAME)) { 43 return new RadarEncoder(); 44 } 45 return null; 46 } 47 48 /** 49 * Convert the given {@code Params} into a TLV representation (that can be sent to the UWBS). 50 */ getTlvBuffer(Params param, ProtocolVersion protocolVersion)51 public abstract TlvBuffer getTlvBuffer(Params param, ProtocolVersion protocolVersion); 52 } 53