• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 android.util.Log;
22 
23 import com.google.uwb.support.base.Params;
24 import com.google.uwb.support.ccc.CccParams;
25 import com.google.uwb.support.ccc.CccSpecificationParams;
26 import com.google.uwb.support.fira.FiraParams;
27 import com.google.uwb.support.fira.FiraSpecificationParams;
28 import com.google.uwb.support.generic.GenericSpecificationParams;
29 
30 public class GenericDecoder extends TlvDecoder {
31     private static final String TAG = "GenericDecoder";
32 
33     @Override
getParams(TlvDecoderBuffer tlvs, Class<T> paramType)34     public <T extends Params> T getParams(TlvDecoderBuffer tlvs, Class<T> paramType) {
35         if (GenericSpecificationParams.class.equals(paramType)) {
36             return (T) getSpecificationParamsFromTlvBuffer(tlvs);
37         }
38         return null;
39     }
40 
getSpecificationParamsFromTlvBuffer(TlvDecoderBuffer tlvs)41     private GenericSpecificationParams getSpecificationParamsFromTlvBuffer(TlvDecoderBuffer tlvs) {
42         GenericSpecificationParams.Builder builder = new GenericSpecificationParams.Builder();
43         try {
44             FiraSpecificationParams firaSpecificationParams =
45                     TlvDecoder.getDecoder(FiraParams.PROTOCOL_NAME).getParams(
46                             tlvs, FiraSpecificationParams.class);
47             builder.setFiraSpecificationParams(firaSpecificationParams);
48         } catch (IllegalArgumentException e) {
49             Log.e(TAG, "Failed to decode FIRA capabilities", e);
50         }
51         try {
52             CccSpecificationParams cccSpecificationParams =
53                     TlvDecoder.getDecoder(CccParams.PROTOCOL_NAME).getParams(
54                             tlvs, CccSpecificationParams.class);
55             builder.setCccSpecificationParams(cccSpecificationParams);
56         } catch (IllegalArgumentException e) {
57             Log.e(TAG, "Failed to decode CCC capabilities", e);
58         }
59         try {
60             byte supported_power_stats_query = tlvs.getByte(SUPPORTED_POWER_STATS_QUERY);
61             if (supported_power_stats_query != 0) {
62                 builder.hasPowerStatsSupport(true);
63             }
64         } catch (IllegalArgumentException e) {
65             // Do nothing. By default, hasPowerStatsSupport() returns false.
66         }
67         return builder.build();
68     }
69 }
70