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.google.uwb.support.fira;
18 
19 import static java.util.Objects.requireNonNull;
20 
21 import android.os.PersistableBundle;
22 import android.uwb.UwbManager;
23 
24 import androidx.annotation.NonNull;
25 
26 import com.google.uwb.support.base.FlagEnum;
27 
28 import java.util.ArrayList;
29 import java.util.Collection;
30 import java.util.EnumSet;
31 import java.util.List;
32 
33 /**
34  * Defines parameters for FIRA capability.
35  *
36  * <p>This is returned as a bundle from the service API {@link UwbManager#getSpecificationInfo}.
37  */
38 public class FiraSpecificationParams extends FiraParams {
39     private static final int BUNDLE_VERSION_1 = 1;
40     private static final int BUNDLE_VERSION_2 = 2;
41     private static final int BUNDLE_VERSION_CURRENT = BUNDLE_VERSION_2;
42 
43     private final FiraProtocolVersion mMinPhyVersionSupported;
44     private final FiraProtocolVersion mMaxPhyVersionSupported;
45     private final FiraProtocolVersion mMinMacVersionSupported;
46     private final FiraProtocolVersion mMaxMacVersionSupported;
47 
48     private final List<Integer> mSupportedChannels;
49 
50     private final EnumSet<AoaCapabilityFlag> mAoaCapabilities;
51 
52     private final EnumSet<DeviceRoleCapabilityFlag> mDeviceRoleCapabilities;
53 
54     private final boolean mHasBlockStridingSupport;
55 
56     private final boolean mHasHoppingPreferenceSupport;
57 
58     private final boolean mHasExtendedMacAddressSupport;
59 
60     private final boolean mHasNonDeferredModeSupport;
61 
62     private final boolean mHasInitiationTimeSupport;
63 
64     private final boolean mHasRssiReportingSupport;
65 
66     private final boolean mHasDiagnosticsSupport;
67 
68     private final int mMinRangingInterval;
69 
70     private final int mMinSlotDurationUs;
71 
72     private final int mMaxRangingSessionNumber;
73 
74     private final EnumSet<MultiNodeCapabilityFlag> mMultiNodeCapabilities;
75 
76     private final EnumSet<RangingTimeStructCapabilitiesFlag> mRangingTimeStructCapabilities;
77 
78     private final EnumSet<SchedulingModeCapabilitiesFlag> mSchedulingModeCapabilities;
79 
80     private final EnumSet<CcConstraintLengthCapabilitiesFlag> mCcConstraintLengthCapabilities;
81 
82     private final EnumSet<PrfCapabilityFlag> mPrfCapabilities;
83 
84     private final EnumSet<RangingRoundCapabilityFlag> mRangingRoundCapabilities;
85 
86     private final EnumSet<RframeCapabilityFlag> mRframeCapabilities;
87 
88     private final EnumSet<StsCapabilityFlag> mStsCapabilities;
89 
90     private final EnumSet<PsduDataRateCapabilityFlag> mPsduDataRateCapabilities;
91 
92     private final EnumSet<BprfParameterSetCapabilityFlag> mBprfParameterSetCapabilities;
93 
94     private final EnumSet<HprfParameterSetCapabilityFlag> mHprfParameterSetCapabilities;
95 
96     private final Integer mMaxMessageSize;
97 
98     private final Integer mMaxDataPacketPayloadSize;
99 
100     private final EnumSet<RangeDataNtfConfigCapabilityFlag> mRangeDataNtfConfigCapabilities;
101 
102     private final int mDeviceType;
103 
104     private final boolean mSuspendRangingSupport;
105 
106     private final int mSessionKeyLength;
107 
108     private final int mDtTagMaxActiveRr;
109 
110     private final boolean mHasBackgroundRangingSupport;
111 
112     private final boolean mHasDtTagBlockSkippingSupport;
113 
114     private final boolean mHasPsduLengthSupport;
115 
116     private final int mUciVersion;
117 
118     private static final String KEY_MIN_PHY_VERSION = "min_phy_version";
119     private static final String KEY_MAX_PHY_VERSION = "max_phy_version";
120     private static final String KEY_MIN_MAC_VERSION = "min_mac_version";
121     private static final String KEY_MAX_MAC_VERSION = "max_mac_version";
122 
123     private static final String KEY_SUPPORTED_CHANNELS = "channels";
124     private static final String KEY_AOA_CAPABILITIES = "aoa_capabilities";
125     private static final String KEY_DEVICE_ROLE_CAPABILITIES = "device_role_capabilities";
126     private static final String KEY_BLOCK_STRIDING_SUPPORT = "block_striding";
127     private static final String KEY_HOPPING_PREFERENCE_SUPPORT = "hopping_preference";
128     private static final String KEY_EXTENDED_MAC_ADDRESS_SUPPORT = "extended_mac_address";
129     private static final String KEY_NON_DEFERRED_MODE_SUPPORT = "non_deferred_mode";
130     private static final String KEY_INITIATION_TIME_SUPPORT = "initiation_time";
131     private static final String KEY_RSSI_REPORTING_SUPPORT = "rssi_reporting";
132     private static final String KEY_DIAGNOSTICS_SUPPORT = "diagnostics";
133     private static final String KEY_MIN_RANGING_INTERVAL = "min_ranging_interval";
134     private static final String KEY_MIN_SLOT_DURATION = "min_slot_duration";
135     private static final String KEY_MAX_RANGING_SESSION_NUMBER = "max_ranging_session_number";
136     private static final String KEY_MULTI_NODE_CAPABILITIES = "multi_node_capabilities";
137     private static final String KEY_RANGING_TIME_STRUCT_CAPABILITIES =
138             "ranging_time_struct_capabilities";
139     private static final String KEY_SCHEDULING_MODE_CAPABILITIES = "scheduling_mode_capabilities";
140     private static final String KEY_CC_CONSTRAINT_LENGTH_CAPABILITIES =
141             "cc_constraint_length_capabilities";
142     private static final String KEY_PRF_CAPABILITIES = "prf_capabilities";
143     private static final String KEY_RANGING_ROUND_CAPABILITIES =
144             "ranging_round_capabilities";
145     private static final String KEY_RFRAME_CAPABILITIES = "rframe_capabilities";
146     private static final String KEY_STS_CAPABILITIES = "sts_capabilities";
147     private static final String KEY_PSDU_DATA_RATE_CAPABILITIES = "psdu_data_rate_capabilities";
148     private static final String KEY_BPRF_PARAMETER_SET_CAPABILITIES =
149             "bprf_parameter_set_capabilities";
150     private static final String KEY_HPRF_PARAMETER_SET_CAPABILITIES =
151             "hprf_parameter_set_capabilities";
152     private static final String KEY_MAX_MESSAGE_SIZE = "max_message_size";
153     private static final String KEY_MAX_DATA_PACKET_PAYLOAD_SIZE = "max_data_packet_payload_size";
154     private static final String KEY_RANGE_DATA_NTF_CONFIG_CAPABILITIES =
155             "range_data_ntf_config_capabilities";
156     private static final String KEY_DEVICE_TYPE =
157             "device_type";
158     private static final String KEY_SUSPEND_RANGING_SUPPORT =
159             "suspend_ranging_support";
160     private static final String KEY_SESSION_KEY_LENGTH =
161             "session_key_length";
162     public static final String DT_TAG_MAX_ACTIVE_RR = "dt_tag_max_active_rr";
163 
164     public static final String KEY_BACKGROUND_RANGING_SUPPORT = "background_ranging_support";
165 
166     public static final String KEY_DT_TAG_BLOCK_SKIPPING_SUPPORT = "dt_tag_block_skipping";
167 
168     public static final String KEY_PSDU_LENGTH_SUPPORT = "psdu_length_support";
169 
170     public static final String KEY_UCI_VERSION = "uci_version";
171 
172     public static final int DEFAULT_MAX_RANGING_SESSIONS_NUMBER = 5;
173 
FiraSpecificationParams( FiraProtocolVersion minPhyVersionSupported, FiraProtocolVersion maxPhyVersionSupported, FiraProtocolVersion minMacVersionSupported, FiraProtocolVersion maxMacVersionSupported, List<Integer> supportedChannels, EnumSet<AoaCapabilityFlag> aoaCapabilities, EnumSet<DeviceRoleCapabilityFlag> deviceRoleCapabilities, boolean hasBlockStridingSupport, boolean hasHoppingPreferenceSupport, boolean hasExtendedMacAddressSupport, boolean hasNonDeferredModeSupport, boolean hasInitiationTimeSupport, boolean hasRssiReportingSupport, boolean hasDiagnosticsSupport, int minRangingInterval, int minSlotDurationUs, int maxRangingSessionNumber, EnumSet<MultiNodeCapabilityFlag> multiNodeCapabilities, EnumSet<RangingTimeStructCapabilitiesFlag> rangingTimeStructCapabilities, EnumSet<SchedulingModeCapabilitiesFlag> schedulingModeCapabilities, EnumSet<CcConstraintLengthCapabilitiesFlag> ccConstraintLengthCapabilities, EnumSet<PrfCapabilityFlag> prfCapabilities, EnumSet<RangingRoundCapabilityFlag> rangingRoundCapabilities, EnumSet<RframeCapabilityFlag> rframeCapabilities, EnumSet<StsCapabilityFlag> stsCapabilities, EnumSet<PsduDataRateCapabilityFlag> psduDataRateCapabilities, EnumSet<BprfParameterSetCapabilityFlag> bprfParameterSetCapabilities, EnumSet<HprfParameterSetCapabilityFlag> hprfParameterSetCapabilities, Integer maxMessageSize, Integer maxDataPacketPayloadSize, EnumSet<RangeDataNtfConfigCapabilityFlag> rangeDataNtfConfigCapabilities, int deviceType, boolean suspendRangingSupport, int sessionKeyLength, int dtTagMaxActiveRr, boolean hasBackgroundRangingSupport, boolean hasDtTagBlockSkippingSupport, boolean hasPsduLengthSupport, int uciVersion)174     private FiraSpecificationParams(
175             FiraProtocolVersion minPhyVersionSupported,
176             FiraProtocolVersion maxPhyVersionSupported,
177             FiraProtocolVersion minMacVersionSupported,
178             FiraProtocolVersion maxMacVersionSupported,
179             List<Integer> supportedChannels,
180             EnumSet<AoaCapabilityFlag> aoaCapabilities,
181             EnumSet<DeviceRoleCapabilityFlag> deviceRoleCapabilities,
182             boolean hasBlockStridingSupport,
183             boolean hasHoppingPreferenceSupport,
184             boolean hasExtendedMacAddressSupport,
185             boolean hasNonDeferredModeSupport,
186             boolean hasInitiationTimeSupport,
187             boolean hasRssiReportingSupport,
188             boolean hasDiagnosticsSupport,
189             int minRangingInterval,
190             int minSlotDurationUs,
191             int maxRangingSessionNumber,
192             EnumSet<MultiNodeCapabilityFlag> multiNodeCapabilities,
193             EnumSet<RangingTimeStructCapabilitiesFlag> rangingTimeStructCapabilities,
194             EnumSet<SchedulingModeCapabilitiesFlag> schedulingModeCapabilities,
195             EnumSet<CcConstraintLengthCapabilitiesFlag> ccConstraintLengthCapabilities,
196             EnumSet<PrfCapabilityFlag> prfCapabilities,
197             EnumSet<RangingRoundCapabilityFlag> rangingRoundCapabilities,
198             EnumSet<RframeCapabilityFlag> rframeCapabilities,
199             EnumSet<StsCapabilityFlag> stsCapabilities,
200             EnumSet<PsduDataRateCapabilityFlag> psduDataRateCapabilities,
201             EnumSet<BprfParameterSetCapabilityFlag> bprfParameterSetCapabilities,
202             EnumSet<HprfParameterSetCapabilityFlag> hprfParameterSetCapabilities,
203             Integer maxMessageSize,
204             Integer maxDataPacketPayloadSize,
205             EnumSet<RangeDataNtfConfigCapabilityFlag> rangeDataNtfConfigCapabilities,
206             int deviceType, boolean suspendRangingSupport, int sessionKeyLength,
207             int dtTagMaxActiveRr, boolean hasBackgroundRangingSupport,
208             boolean hasDtTagBlockSkippingSupport, boolean hasPsduLengthSupport,
209             int uciVersion) {
210         mMinPhyVersionSupported = minPhyVersionSupported;
211         mMaxPhyVersionSupported = maxPhyVersionSupported;
212         mMinMacVersionSupported = minMacVersionSupported;
213         mMaxMacVersionSupported = maxMacVersionSupported;
214         mSupportedChannels = supportedChannels;
215         mAoaCapabilities = aoaCapabilities;
216         mDeviceRoleCapabilities = deviceRoleCapabilities;
217         mHasBlockStridingSupport = hasBlockStridingSupport;
218         mHasHoppingPreferenceSupport = hasHoppingPreferenceSupport;
219         mHasExtendedMacAddressSupport = hasExtendedMacAddressSupport;
220         mHasNonDeferredModeSupport = hasNonDeferredModeSupport;
221         mHasInitiationTimeSupport = hasInitiationTimeSupport;
222         mHasRssiReportingSupport = hasRssiReportingSupport;
223         mHasDiagnosticsSupport = hasDiagnosticsSupport;
224         mMinRangingInterval = minRangingInterval;
225         mMinSlotDurationUs = minSlotDurationUs;
226         mMaxRangingSessionNumber = maxRangingSessionNumber;
227         mMultiNodeCapabilities = multiNodeCapabilities;
228         mRangingTimeStructCapabilities = rangingTimeStructCapabilities;
229         mSchedulingModeCapabilities = schedulingModeCapabilities;
230         mCcConstraintLengthCapabilities = ccConstraintLengthCapabilities;
231         mPrfCapabilities = prfCapabilities;
232         mRangingRoundCapabilities = rangingRoundCapabilities;
233         mRframeCapabilities = rframeCapabilities;
234         mStsCapabilities = stsCapabilities;
235         mPsduDataRateCapabilities = psduDataRateCapabilities;
236         mBprfParameterSetCapabilities = bprfParameterSetCapabilities;
237         mHprfParameterSetCapabilities = hprfParameterSetCapabilities;
238         mMaxMessageSize = maxMessageSize;
239         mMaxDataPacketPayloadSize = maxDataPacketPayloadSize;
240         mRangeDataNtfConfigCapabilities = rangeDataNtfConfigCapabilities;
241         mDeviceType = deviceType;
242         mSuspendRangingSupport = suspendRangingSupport;
243         mSessionKeyLength = sessionKeyLength;
244         mDtTagMaxActiveRr = dtTagMaxActiveRr;
245         mHasBackgroundRangingSupport = hasBackgroundRangingSupport;
246         mHasDtTagBlockSkippingSupport = hasDtTagBlockSkippingSupport;
247         mHasPsduLengthSupport = hasPsduLengthSupport;
248         mUciVersion = uciVersion;
249     }
250 
251     @Override
getBundleVersion()252     protected int getBundleVersion() {
253         return BUNDLE_VERSION_CURRENT;
254     }
255 
getMinPhyVersionSupported()256     public FiraProtocolVersion getMinPhyVersionSupported() {
257         return mMinPhyVersionSupported;
258     }
259 
getMaxPhyVersionSupported()260     public FiraProtocolVersion getMaxPhyVersionSupported() {
261         return mMaxPhyVersionSupported;
262     }
263 
getMinMacVersionSupported()264     public FiraProtocolVersion getMinMacVersionSupported() {
265         return mMinMacVersionSupported;
266     }
267 
getMaxMacVersionSupported()268     public FiraProtocolVersion getMaxMacVersionSupported() {
269         return mMaxMacVersionSupported;
270     }
271 
getSupportedChannels()272     public List<Integer> getSupportedChannels() {
273         return mSupportedChannels;
274     }
275 
getAoaCapabilities()276     public EnumSet<AoaCapabilityFlag> getAoaCapabilities() {
277         return mAoaCapabilities;
278     }
279 
getDeviceRoleCapabilities()280     public EnumSet<DeviceRoleCapabilityFlag> getDeviceRoleCapabilities() {
281         return mDeviceRoleCapabilities;
282     }
283 
hasBlockStridingSupport()284     public boolean hasBlockStridingSupport() {
285         return mHasBlockStridingSupport;
286     }
287 
hasHoppingPreferenceSupport()288     public boolean hasHoppingPreferenceSupport() {
289         return mHasHoppingPreferenceSupport;
290     }
291 
hasExtendedMacAddressSupport()292     public boolean hasExtendedMacAddressSupport() {
293         return mHasExtendedMacAddressSupport;
294     }
295 
hasNonDeferredModeSupport()296     public boolean hasNonDeferredModeSupport() {
297         return mHasNonDeferredModeSupport;
298     }
299 
hasInitiationTimeSupport()300     public boolean hasInitiationTimeSupport() {
301         return mHasInitiationTimeSupport;
302     }
303 
304     /** get a boolean whether rssi reporting is supported. */
hasRssiReportingSupport()305     public boolean hasRssiReportingSupport() {
306         return mHasRssiReportingSupport;
307     }
308 
309     /** get a boolean whether diagnostics is supported. */
hasDiagnosticsSupport()310     public boolean hasDiagnosticsSupport() {
311         return mHasDiagnosticsSupport;
312     }
313 
getMinRangingInterval()314     public int getMinRangingInterval() {
315         return mMinRangingInterval;
316     }
317 
getMinSlotDurationUs()318     public int getMinSlotDurationUs() {
319         return mMinSlotDurationUs;
320     }
321 
getMaxRangingSessionNumber()322     public int getMaxRangingSessionNumber() {
323         return mMaxRangingSessionNumber;
324     }
325 
getMultiNodeCapabilities()326     public EnumSet<MultiNodeCapabilityFlag> getMultiNodeCapabilities() {
327         return mMultiNodeCapabilities;
328     }
329 
getRangingTimeStructCapabilities()330     public EnumSet<RangingTimeStructCapabilitiesFlag> getRangingTimeStructCapabilities() {
331         return mRangingTimeStructCapabilities;
332     }
333 
getSchedulingModeCapabilities()334     public EnumSet<SchedulingModeCapabilitiesFlag> getSchedulingModeCapabilities() {
335         return mSchedulingModeCapabilities;
336     }
337 
getCcConstraintLengthCapabilities()338     public EnumSet<CcConstraintLengthCapabilitiesFlag> getCcConstraintLengthCapabilities() {
339         return mCcConstraintLengthCapabilities;
340     }
341 
getPrfCapabilities()342     public EnumSet<PrfCapabilityFlag> getPrfCapabilities() {
343         return mPrfCapabilities;
344     }
345 
getRangingRoundCapabilities()346     public EnumSet<RangingRoundCapabilityFlag> getRangingRoundCapabilities() {
347         return mRangingRoundCapabilities;
348     }
349 
getRframeCapabilities()350     public EnumSet<RframeCapabilityFlag> getRframeCapabilities() {
351         return mRframeCapabilities;
352     }
353 
getStsCapabilities()354     public EnumSet<StsCapabilityFlag> getStsCapabilities() {
355         return mStsCapabilities;
356     }
357 
getPsduDataRateCapabilities()358     public EnumSet<PsduDataRateCapabilityFlag> getPsduDataRateCapabilities() {
359         return mPsduDataRateCapabilities;
360     }
361 
getBprfParameterSetCapabilities()362     public EnumSet<BprfParameterSetCapabilityFlag> getBprfParameterSetCapabilities() {
363         return mBprfParameterSetCapabilities;
364     }
365 
getHprfParameterSetCapabilities()366     public EnumSet<HprfParameterSetCapabilityFlag> getHprfParameterSetCapabilities() {
367         return mHprfParameterSetCapabilities;
368     }
369 
getRangeDataNtfConfigCapabilities()370     public EnumSet<RangeDataNtfConfigCapabilityFlag> getRangeDataNtfConfigCapabilities() {
371         return mRangeDataNtfConfigCapabilities;
372     }
373 
getMaxMessageSize()374     public Integer getMaxMessageSize() {
375         return mMaxMessageSize;
376     }
377 
getMaxDataPacketPayloadSize()378     public Integer getMaxDataPacketPayloadSize() {
379         return mMaxDataPacketPayloadSize;
380     }
381 
getDeviceType()382     public int getDeviceType() {
383         return mDeviceType;
384     }
385 
hasSuspendRangingSupport()386     public boolean hasSuspendRangingSupport() {
387         return mSuspendRangingSupport;
388     }
389 
getSessionKeyLength()390     public int getSessionKeyLength() {
391         return mSessionKeyLength;
392     }
393 
getDtTagMaxActiveRr()394     public int getDtTagMaxActiveRr() {
395         return mDtTagMaxActiveRr;
396     }
397 
hasBackgroundRangingSupport()398     public boolean hasBackgroundRangingSupport() {
399         return mHasBackgroundRangingSupport;
400     }
401 
hasDtTagBlockSkippingSupport()402     public boolean hasDtTagBlockSkippingSupport() {
403         return mHasDtTagBlockSkippingSupport;
404     }
405 
hasPsduLengthSupport()406     public boolean hasPsduLengthSupport() {
407         return mHasPsduLengthSupport;
408     }
409 
getUciVersionSupported()410     public int getUciVersionSupported() {
411         return mUciVersion;
412     }
413 
toIntArray(List<Integer> data)414     private static int[] toIntArray(List<Integer> data) {
415         int[] res = new int[data.size()];
416         for (int i = 0; i < data.size(); i++) {
417             res[i] = data.get(i);
418         }
419         return res;
420     }
421 
422     @Override
toBundle()423     public PersistableBundle toBundle() {
424         PersistableBundle bundle = super.toBundle();
425         bundle.putString(KEY_MIN_PHY_VERSION, mMinPhyVersionSupported.toString());
426         bundle.putString(KEY_MAX_PHY_VERSION, mMaxPhyVersionSupported.toString());
427         bundle.putString(KEY_MIN_MAC_VERSION, mMinMacVersionSupported.toString());
428         bundle.putString(KEY_MAX_MAC_VERSION, mMaxMacVersionSupported.toString());
429         bundle.putIntArray(KEY_SUPPORTED_CHANNELS, toIntArray(mSupportedChannels));
430         bundle.putInt(KEY_AOA_CAPABILITIES, FlagEnum.toInt(mAoaCapabilities));
431         bundle.putInt(KEY_DEVICE_ROLE_CAPABILITIES, FlagEnum.toInt(mDeviceRoleCapabilities));
432         bundle.putBoolean(KEY_BLOCK_STRIDING_SUPPORT, mHasBlockStridingSupport);
433         bundle.putBoolean(KEY_HOPPING_PREFERENCE_SUPPORT, mHasHoppingPreferenceSupport);
434         bundle.putBoolean(KEY_EXTENDED_MAC_ADDRESS_SUPPORT, mHasExtendedMacAddressSupport);
435         bundle.putBoolean(KEY_NON_DEFERRED_MODE_SUPPORT, mHasNonDeferredModeSupport);
436         bundle.putBoolean(KEY_INITIATION_TIME_SUPPORT, mHasInitiationTimeSupport);
437         bundle.putBoolean(KEY_RSSI_REPORTING_SUPPORT, mHasRssiReportingSupport);
438         bundle.putBoolean(KEY_DIAGNOSTICS_SUPPORT, mHasDiagnosticsSupport);
439         bundle.putInt(KEY_MIN_RANGING_INTERVAL, mMinRangingInterval);
440         bundle.putInt(KEY_MIN_SLOT_DURATION, mMinSlotDurationUs);
441         bundle.putInt(KEY_MAX_RANGING_SESSION_NUMBER, mMaxRangingSessionNumber);
442         bundle.putInt(KEY_MULTI_NODE_CAPABILITIES, FlagEnum.toInt(mMultiNodeCapabilities));
443         bundle.putInt(KEY_RANGING_TIME_STRUCT_CAPABILITIES,
444                 FlagEnum.toInt(mRangingTimeStructCapabilities));
445         bundle.putInt(KEY_SCHEDULING_MODE_CAPABILITIES,
446                 FlagEnum.toInt(mSchedulingModeCapabilities));
447         bundle.putInt(KEY_CC_CONSTRAINT_LENGTH_CAPABILITIES,
448                 FlagEnum.toInt(mCcConstraintLengthCapabilities));
449         bundle.putInt(KEY_PRF_CAPABILITIES, FlagEnum.toInt(mPrfCapabilities));
450         bundle.putInt(KEY_RANGING_ROUND_CAPABILITIES, FlagEnum.toInt(mRangingRoundCapabilities));
451         bundle.putInt(KEY_RFRAME_CAPABILITIES, FlagEnum.toInt(mRframeCapabilities));
452         bundle.putInt(KEY_STS_CAPABILITIES, FlagEnum.toInt(mStsCapabilities));
453         bundle.putInt(KEY_PSDU_DATA_RATE_CAPABILITIES, FlagEnum.toInt(mPsduDataRateCapabilities));
454         bundle.putInt(KEY_BPRF_PARAMETER_SET_CAPABILITIES,
455                 FlagEnum.toInt(mBprfParameterSetCapabilities));
456         bundle.putLong(KEY_HPRF_PARAMETER_SET_CAPABILITIES,
457                 FlagEnum.toLong(mHprfParameterSetCapabilities));
458         bundle.putInt(KEY_MAX_MESSAGE_SIZE, mMaxMessageSize);
459         bundle.putInt(KEY_MAX_DATA_PACKET_PAYLOAD_SIZE, mMaxDataPacketPayloadSize);
460         bundle.putInt(KEY_RANGE_DATA_NTF_CONFIG_CAPABILITIES,
461                 FlagEnum.toInt(mRangeDataNtfConfigCapabilities));
462         bundle.putInt(KEY_DEVICE_TYPE, mDeviceType);
463         bundle.putBoolean(KEY_SUSPEND_RANGING_SUPPORT, mSuspendRangingSupport);
464         bundle.putInt(KEY_SESSION_KEY_LENGTH, mSessionKeyLength);
465         bundle.putInt(DT_TAG_MAX_ACTIVE_RR, mDtTagMaxActiveRr);
466         bundle.putBoolean(KEY_BACKGROUND_RANGING_SUPPORT, mHasBackgroundRangingSupport);
467         bundle.putBoolean(KEY_DT_TAG_BLOCK_SKIPPING_SUPPORT, mHasDtTagBlockSkippingSupport);
468         bundle.putBoolean(KEY_PSDU_LENGTH_SUPPORT, mHasPsduLengthSupport);
469         bundle.putInt(KEY_UCI_VERSION, mUciVersion);
470         return bundle;
471     }
472 
fromBundle(PersistableBundle bundle)473     public static FiraSpecificationParams fromBundle(PersistableBundle bundle) {
474         if (!isCorrectProtocol(bundle)) {
475             throw new IllegalArgumentException("Invalid protocol");
476         }
477 
478         switch (getBundleVersion(bundle)) {
479             case BUNDLE_VERSION_1:
480                 return parseVersion1(bundle).build();
481             case BUNDLE_VERSION_2:
482                 return parseVersion2(bundle).build();
483             default:
484                 throw new IllegalArgumentException("Invalid bundle version");
485         }
486     }
487 
toIntList(int[] data)488     private static List<Integer> toIntList(int[] data) {
489         List<Integer> res = new ArrayList<>();
490         for (int datum : data) {
491             res.add(datum);
492         }
493         return res;
494     }
495 
parseVersion2(PersistableBundle bundle)496     private static FiraSpecificationParams.Builder parseVersion2(PersistableBundle bundle) {
497         FiraSpecificationParams.Builder builder = parseVersion1(bundle);
498         builder.setDeviceType(bundle.getInt(KEY_DEVICE_TYPE));
499         builder.setSuspendRangingSupport(bundle.getBoolean(KEY_SUSPEND_RANGING_SUPPORT));
500         builder.setSessionKeyLength(bundle.getInt(KEY_SESSION_KEY_LENGTH));
501         builder.setDtTagMaxActiveRr(bundle.getInt(DT_TAG_MAX_ACTIVE_RR, 0));
502         builder.setBackgroundRangingSupport(bundle.getBoolean(KEY_BACKGROUND_RANGING_SUPPORT));
503         builder.setDtTagBlockSkippingSupport(bundle.getBoolean(KEY_DT_TAG_BLOCK_SKIPPING_SUPPORT));
504         builder.setPsduLengthSupport(bundle.getBoolean(KEY_PSDU_LENGTH_SUPPORT));
505         builder.setUciVersionSupported(bundle.getInt(KEY_UCI_VERSION, 1));
506         return builder;
507     }
508 
parseVersion1(PersistableBundle bundle)509     private static FiraSpecificationParams.Builder parseVersion1(PersistableBundle bundle) {
510         FiraSpecificationParams.Builder builder = new FiraSpecificationParams.Builder();
511         List<Integer> supportedChannels =
512                 toIntList(requireNonNull(bundle.getIntArray(KEY_SUPPORTED_CHANNELS)));
513         builder.setMinPhyVersionSupported(
514                         FiraProtocolVersion.fromString(bundle.getString(KEY_MIN_PHY_VERSION)))
515                 .setMaxPhyVersionSupported(
516                         FiraProtocolVersion.fromString(bundle.getString(KEY_MAX_PHY_VERSION)))
517                 .setMinMacVersionSupported(
518                         FiraProtocolVersion.fromString(bundle.getString(KEY_MIN_MAC_VERSION)))
519                 .setMaxMacVersionSupported(
520                         FiraProtocolVersion.fromString(bundle.getString(KEY_MAX_MAC_VERSION)))
521                 .setSupportedChannels(supportedChannels)
522                 .setAoaCapabilities(
523                         FlagEnum.toEnumSet(
524                                 bundle.getInt(KEY_AOA_CAPABILITIES), AoaCapabilityFlag.values()))
525                 .setDeviceRoleCapabilities(
526                         FlagEnum.toEnumSet(
527                                 bundle.getInt(KEY_DEVICE_ROLE_CAPABILITIES),
528                                 DeviceRoleCapabilityFlag.values()))
529                 .hasBlockStridingSupport(bundle.getBoolean(KEY_BLOCK_STRIDING_SUPPORT))
530                 .hasHoppingPreferenceSupport(bundle.getBoolean(KEY_HOPPING_PREFERENCE_SUPPORT))
531                 .hasExtendedMacAddressSupport(bundle.getBoolean(KEY_EXTENDED_MAC_ADDRESS_SUPPORT))
532                 .hasNonDeferredModeSupport(bundle.getBoolean(KEY_NON_DEFERRED_MODE_SUPPORT))
533                 .hasInitiationTimeSupport(bundle.getBoolean(KEY_INITIATION_TIME_SUPPORT))
534                 .setMinRangingIntervalSupported(bundle.getInt(KEY_MIN_RANGING_INTERVAL, -1))
535                 .setMinSlotDurationSupportedUs(bundle.getInt(KEY_MIN_SLOT_DURATION, -1))
536                 .setMultiNodeCapabilities(
537                         FlagEnum.toEnumSet(
538                                 bundle.getInt(KEY_MULTI_NODE_CAPABILITIES),
539                                 MultiNodeCapabilityFlag.values()))
540                 .setRangingTimeStructCapabilities(
541                         FlagEnum.toEnumSet(
542                                 bundle.getInt(KEY_RANGING_TIME_STRUCT_CAPABILITIES),
543                                 RangingTimeStructCapabilitiesFlag.values()))
544                 .setSchedulingModeCapabilities(
545                         FlagEnum.toEnumSet(
546                                 bundle.getInt(KEY_SCHEDULING_MODE_CAPABILITIES),
547                                 SchedulingModeCapabilitiesFlag.values()))
548                 .setCcConstraintLengthCapabilities(
549                         FlagEnum.toEnumSet(
550                                 bundle.getInt(KEY_CC_CONSTRAINT_LENGTH_CAPABILITIES),
551                                 CcConstraintLengthCapabilitiesFlag.values()))
552                 .setPrfCapabilities(
553                         FlagEnum.toEnumSet(
554                                 bundle.getInt(KEY_PRF_CAPABILITIES), PrfCapabilityFlag.values()))
555                 .setRangingRoundCapabilities(
556                         FlagEnum.toEnumSet(
557                                 bundle.getInt(KEY_RANGING_ROUND_CAPABILITIES),
558                                 RangingRoundCapabilityFlag.values()))
559                 .setRframeCapabilities(
560                         FlagEnum.toEnumSet(
561                                 bundle.getInt(KEY_RFRAME_CAPABILITIES),
562                                 RframeCapabilityFlag.values()))
563                 .setStsCapabilities(
564                         FlagEnum.toEnumSet(
565                                 bundle.getInt(KEY_STS_CAPABILITIES), StsCapabilityFlag.values()))
566                 .setPsduDataRateCapabilities(
567                         FlagEnum.toEnumSet(
568                                 bundle.getInt(KEY_PSDU_DATA_RATE_CAPABILITIES),
569                                 PsduDataRateCapabilityFlag.values()))
570                 .setBprfParameterSetCapabilities(
571                         FlagEnum.toEnumSet(
572                                 bundle.getInt(KEY_BPRF_PARAMETER_SET_CAPABILITIES),
573                                 BprfParameterSetCapabilityFlag.values()))
574                 .setMaxMessageSize(bundle.getInt(KEY_MAX_MESSAGE_SIZE))
575                 .setMaxDataPacketPayloadSize(bundle.getInt(KEY_MAX_DATA_PACKET_PAYLOAD_SIZE))
576                 .setHprfParameterSetCapabilities(
577                         FlagEnum.longToEnumSet(
578                                 bundle.getLong(KEY_HPRF_PARAMETER_SET_CAPABILITIES),
579                                 HprfParameterSetCapabilityFlag.values()));
580         // Newer params need to be backward compatible with existing devices.
581         if (bundle.containsKey(KEY_RANGE_DATA_NTF_CONFIG_CAPABILITIES)) {
582             builder.setRangeDataNtfConfigCapabilities(
583                     FlagEnum.toEnumSet(
584                             bundle.getInt(KEY_RANGE_DATA_NTF_CONFIG_CAPABILITIES),
585                             RangeDataNtfConfigCapabilityFlag.values()));
586         }
587         if (bundle.containsKey(KEY_RSSI_REPORTING_SUPPORT)) {
588             builder.hasRssiReportingSupport(bundle.getBoolean(KEY_RSSI_REPORTING_SUPPORT));
589         }
590         if (bundle.containsKey(KEY_DIAGNOSTICS_SUPPORT)) {
591             builder.hasDiagnosticsSupport(bundle.getBoolean(KEY_DIAGNOSTICS_SUPPORT));
592         }
593         if (bundle.containsKey(KEY_MAX_RANGING_SESSION_NUMBER)) {
594             builder.setMaxRangingSessionNumberSupported(
595                     bundle.getInt(KEY_MAX_RANGING_SESSION_NUMBER));
596         }
597         return builder;
598     }
599 
600     /** Builder */
601     public static class Builder {
602         // Set all default protocol version to FiRa 1.1
603         private FiraProtocolVersion mMinPhyVersionSupported = new FiraProtocolVersion(1, 1);
604         private FiraProtocolVersion mMaxPhyVersionSupported = new FiraProtocolVersion(1, 1);
605         private FiraProtocolVersion mMinMacVersionSupported = new FiraProtocolVersion(1, 1);
606         private FiraProtocolVersion mMaxMacVersionSupported = new FiraProtocolVersion(1, 1);
607 
608         private List<Integer> mSupportedChannels = new ArrayList<>();
609 
610         private EnumSet<AoaCapabilityFlag> mAoaCapabilities =
611                 EnumSet.noneOf(AoaCapabilityFlag.class);
612 
613         // Controller-intiator, Cotrolee-responder are mandatory.
614         private EnumSet<DeviceRoleCapabilityFlag> mDeviceRoleCapabilities =
615                 EnumSet.of(
616                         DeviceRoleCapabilityFlag.HAS_CONTROLLER_INITIATOR_SUPPORT,
617                         DeviceRoleCapabilityFlag.HAS_CONTROLEE_RESPONDER_SUPPORT);
618 
619         // Enable/Disable ntf config is mandatory.
620         private EnumSet<RangeDataNtfConfigCapabilityFlag> mRangeDataNtfConfigCapabilities =
621                 EnumSet.noneOf(RangeDataNtfConfigCapabilityFlag.class);
622 
623         private boolean mHasBlockStridingSupport = false;
624 
625         private boolean mHasHoppingPreferenceSupport = false;
626 
627         private boolean mHasExtendedMacAddressSupport = false;
628 
629         private boolean mHasNonDeferredModeSupport = false;
630 
631         private boolean mHasInitiationTimeSupport = false;
632 
633         private boolean mHasRssiReportingSupport = false;
634 
635         private boolean mHasDiagnosticsSupport = false;
636 
637         private int mMinRangingInterval = -1;
638 
639         private int mMinSlotDurationUs = -1;
640 
641         private int mMaxRangingSessionNumber = DEFAULT_MAX_RANGING_SESSIONS_NUMBER;
642 
643         private int mUciVersion = 1;
644 
645         // Unicast support is mandatory
646         private EnumSet<MultiNodeCapabilityFlag> mMultiNodeCapabilities =
647                 EnumSet.of(MultiNodeCapabilityFlag.HAS_UNICAST_SUPPORT);
648 
649         private EnumSet<RangingTimeStructCapabilitiesFlag> mRangingTimeStructCapabilities =
650                 EnumSet.of(
651                         RangingTimeStructCapabilitiesFlag.HAS_INTERVAL_BASED_SCHEDULING_SUPPORT,
652                         RangingTimeStructCapabilitiesFlag.HAS_BLOCK_BASED_SCHEDULING_SUPPORT);
653 
654         private EnumSet<SchedulingModeCapabilitiesFlag> mSchedulingModeCapabilities =
655                 EnumSet.of(
656                         SchedulingModeCapabilitiesFlag.HAS_CONTENTION_BASED_RANGING_SUPPORT,
657                         SchedulingModeCapabilitiesFlag.HAS_TIME_SCHEDULED_RANGING_SUPPORT);
658 
659         private EnumSet<CcConstraintLengthCapabilitiesFlag> mCcConstraintLengthCapabilities =
660                 EnumSet.of(
661                         CcConstraintLengthCapabilitiesFlag.HAS_CONSTRAINT_LENGTH_3_SUPPORT,
662                         CcConstraintLengthCapabilitiesFlag.HAS_CONSTRAINT_LENGTH_7_SUPPORT);
663 
664         // BPRF mode is mandatory
665         private EnumSet<PrfCapabilityFlag> mPrfCapabilities =
666                 EnumSet.of(PrfCapabilityFlag.HAS_BPRF_SUPPORT);
667 
668         // DS-TWR is mandatory
669         private EnumSet<RangingRoundCapabilityFlag> mRangingRoundCapabilities =
670                 EnumSet.of(RangingRoundCapabilityFlag.HAS_DS_TWR_SUPPORT);
671 
672         // SP3 RFrame is mandatory
673         private EnumSet<RframeCapabilityFlag> mRframeCapabilities =
674                 EnumSet.of(RframeCapabilityFlag.HAS_SP3_RFRAME_SUPPORT);
675 
676         // STATIC STS is mandatory
677         private EnumSet<StsCapabilityFlag> mStsCapabilities =
678                 EnumSet.of(StsCapabilityFlag.HAS_STATIC_STS_SUPPORT);
679 
680         // 6.81Mb/s PSDU data rate is mandatory
681         private EnumSet<PsduDataRateCapabilityFlag> mPsduDataRateCapabilities =
682                 EnumSet.of(PsduDataRateCapabilityFlag.HAS_6M81_SUPPORT);
683 
684         private EnumSet<BprfParameterSetCapabilityFlag> mBprfParameterSetCapabilities =
685                 EnumSet.noneOf(BprfParameterSetCapabilityFlag.class);
686 
687         private EnumSet<HprfParameterSetCapabilityFlag> mHprfParameterSetCapabilities =
688                 EnumSet.noneOf(HprfParameterSetCapabilityFlag.class);
689 
690         private Integer mMaxMessageSize = 0;
691 
692         private Integer mMaxDataPacketPayloadSize = 0;
693 
694         // Default to Controlee
695         private int mDeviceType = RANGING_DEVICE_TYPE_CONTROLEE;
696 
697         // Default to no suspend ranging support
698         private boolean mSuspendRangingSupport = false;
699 
700         // Default to 256 bits key length not supported
701         private int mSessionKeyLength = 0;
702 
703         //Default to 0 i.e., DT tag role not supported.
704         private int mDtTagMaxActiveRr = 0;
705 
706         //Default is false. i.e., no background ranging support.
707         private boolean mHasBackgroundRangingSupport = false;
708 
709         // DT_TAG_BLOCK_SKIPPING.
710         private boolean mHasDtTagBlockSkippingSupport = false;
711 
712         // PSDU_LENGTH_SUPPORT.
713         private boolean mHasPsduLengthSupport = false;
714 
setMinPhyVersionSupported( FiraProtocolVersion version)715         public FiraSpecificationParams.Builder setMinPhyVersionSupported(
716                 FiraProtocolVersion version) {
717             mMinPhyVersionSupported = version;
718             return this;
719         }
720 
setMaxPhyVersionSupported( FiraProtocolVersion version)721         public FiraSpecificationParams.Builder setMaxPhyVersionSupported(
722                 FiraProtocolVersion version) {
723             mMaxPhyVersionSupported = version;
724             return this;
725         }
726 
setMinMacVersionSupported( FiraProtocolVersion version)727         public FiraSpecificationParams.Builder setMinMacVersionSupported(
728                 FiraProtocolVersion version) {
729             mMinMacVersionSupported = version;
730             return this;
731         }
732 
setMaxMacVersionSupported( FiraProtocolVersion version)733         public FiraSpecificationParams.Builder setMaxMacVersionSupported(
734                 FiraProtocolVersion version) {
735             mMaxMacVersionSupported = version;
736             return this;
737         }
738 
setSupportedChannels( List<Integer> supportedChannels)739         public FiraSpecificationParams.Builder setSupportedChannels(
740                 List<Integer> supportedChannels) {
741             mSupportedChannels = List.copyOf(supportedChannels);
742             return this;
743         }
744 
setAoaCapabilities( Collection<AoaCapabilityFlag> aoaCapabilities)745         public FiraSpecificationParams.Builder setAoaCapabilities(
746                 Collection<AoaCapabilityFlag> aoaCapabilities) {
747             mAoaCapabilities.addAll(aoaCapabilities);
748             return this;
749         }
750 
setDeviceRoleCapabilities( Collection<DeviceRoleCapabilityFlag> deviceRoleCapabilities)751         public FiraSpecificationParams.Builder setDeviceRoleCapabilities(
752                 Collection<DeviceRoleCapabilityFlag> deviceRoleCapabilities) {
753             mDeviceRoleCapabilities.addAll(deviceRoleCapabilities);
754             return this;
755         }
756 
hasBlockStridingSupport(boolean value)757         public FiraSpecificationParams.Builder hasBlockStridingSupport(boolean value) {
758             mHasBlockStridingSupport = value;
759             return this;
760         }
761 
hasHoppingPreferenceSupport(boolean value)762         public FiraSpecificationParams.Builder hasHoppingPreferenceSupport(boolean value) {
763             mHasHoppingPreferenceSupport = value;
764             return this;
765         }
766 
hasExtendedMacAddressSupport(boolean value)767         public FiraSpecificationParams.Builder hasExtendedMacAddressSupport(boolean value) {
768             mHasExtendedMacAddressSupport = value;
769             return this;
770         }
771 
hasNonDeferredModeSupport(boolean value)772         public FiraSpecificationParams.Builder hasNonDeferredModeSupport(boolean value) {
773             mHasNonDeferredModeSupport = value;
774             return this;
775         }
776 
hasInitiationTimeSupport(boolean value)777         public FiraSpecificationParams.Builder hasInitiationTimeSupport(boolean value) {
778             mHasInitiationTimeSupport = value;
779             return this;
780         }
781 
782         /** Set whether rssi reporting is supported. */
hasRssiReportingSupport(boolean value)783         public FiraSpecificationParams.Builder hasRssiReportingSupport(boolean value) {
784             mHasRssiReportingSupport = value;
785             return this;
786         }
787 
788         /** Set whether diagnostics is supported. */
hasDiagnosticsSupport(boolean value)789         public FiraSpecificationParams.Builder hasDiagnosticsSupport(boolean value) {
790             mHasDiagnosticsSupport = value;
791             return this;
792         }
793 
794         /**
795          * Set minimum supported ranging interval
796          * @param value : minimum ranging interval supported
797          * @return FiraSpecificationParams builder
798          */
setMinRangingIntervalSupported(int value)799         public FiraSpecificationParams.Builder setMinRangingIntervalSupported(int value) {
800             mMinRangingInterval = value;
801             return this;
802         }
803 
804         /**
805          * Set minimum supported slot duration in microsecond
806          * @param value : minimum slot duration supported in microsecond
807          * @return FiraSpecificationParams builder
808          */
setMinSlotDurationSupportedUs(int value)809         public FiraSpecificationParams.Builder setMinSlotDurationSupportedUs(int value) {
810             mMinSlotDurationUs = value;
811             return this;
812         }
813 
814         /**
815          * Set maximum supported ranging session number
816          * @param value : maximum ranging session number supported
817          * @return FiraSpecificationParams builder
818          */
setMaxRangingSessionNumberSupported(int value)819         public FiraSpecificationParams.Builder setMaxRangingSessionNumberSupported(int value) {
820             mMaxRangingSessionNumber = value;
821             return this;
822         }
823 
setMultiNodeCapabilities( Collection<MultiNodeCapabilityFlag> multiNodeCapabilities)824         public FiraSpecificationParams.Builder setMultiNodeCapabilities(
825                 Collection<MultiNodeCapabilityFlag> multiNodeCapabilities) {
826             mMultiNodeCapabilities.addAll(multiNodeCapabilities);
827             return this;
828         }
829 
setRangingTimeStructCapabilities( Collection<RangingTimeStructCapabilitiesFlag> rangingTimeStructCapabilities)830         public FiraSpecificationParams.Builder setRangingTimeStructCapabilities(
831                 Collection<RangingTimeStructCapabilitiesFlag> rangingTimeStructCapabilities) {
832             mRangingTimeStructCapabilities.addAll(rangingTimeStructCapabilities);
833             return this;
834         }
835 
setSchedulingModeCapabilities( Collection<SchedulingModeCapabilitiesFlag> schedulingModeCapabilities)836         public FiraSpecificationParams.Builder setSchedulingModeCapabilities(
837                 Collection<SchedulingModeCapabilitiesFlag> schedulingModeCapabilities) {
838             mSchedulingModeCapabilities.addAll(schedulingModeCapabilities);
839             return this;
840         }
841 
setCcConstraintLengthCapabilities( Collection<CcConstraintLengthCapabilitiesFlag> ccConstraintLengthCapabilities)842         public FiraSpecificationParams.Builder setCcConstraintLengthCapabilities(
843                 Collection<CcConstraintLengthCapabilitiesFlag> ccConstraintLengthCapabilities) {
844             mCcConstraintLengthCapabilities.addAll(ccConstraintLengthCapabilities);
845             return this;
846         }
847 
setPrfCapabilities( Collection<PrfCapabilityFlag> prfCapabilities)848         public FiraSpecificationParams.Builder setPrfCapabilities(
849                 Collection<PrfCapabilityFlag> prfCapabilities) {
850             mPrfCapabilities.addAll(prfCapabilities);
851             return this;
852         }
853 
setRangingRoundCapabilities( Collection<RangingRoundCapabilityFlag> rangingRoundCapabilities)854         public FiraSpecificationParams.Builder setRangingRoundCapabilities(
855                 Collection<RangingRoundCapabilityFlag> rangingRoundCapabilities) {
856             mRangingRoundCapabilities.addAll(rangingRoundCapabilities);
857             return this;
858         }
859 
setRframeCapabilities( Collection<RframeCapabilityFlag> rframeCapabilities)860         public FiraSpecificationParams.Builder setRframeCapabilities(
861                 Collection<RframeCapabilityFlag> rframeCapabilities) {
862             mRframeCapabilities.addAll(rframeCapabilities);
863             return this;
864         }
865 
setStsCapabilities( Collection<StsCapabilityFlag> stsCapabilities)866         public FiraSpecificationParams.Builder setStsCapabilities(
867                 Collection<StsCapabilityFlag> stsCapabilities) {
868             mStsCapabilities.addAll(stsCapabilities);
869             return this;
870         }
871 
setPsduDataRateCapabilities( Collection<PsduDataRateCapabilityFlag> psduDataRateCapabilities)872         public FiraSpecificationParams.Builder setPsduDataRateCapabilities(
873                 Collection<PsduDataRateCapabilityFlag> psduDataRateCapabilities) {
874             mPsduDataRateCapabilities.addAll(psduDataRateCapabilities);
875             return this;
876         }
877 
setBprfParameterSetCapabilities( Collection<BprfParameterSetCapabilityFlag> bprfParameterSetCapabilities)878         public FiraSpecificationParams.Builder setBprfParameterSetCapabilities(
879                 Collection<BprfParameterSetCapabilityFlag> bprfParameterSetCapabilities) {
880             mBprfParameterSetCapabilities.addAll(bprfParameterSetCapabilities);
881             return this;
882         }
883 
setHprfParameterSetCapabilities( Collection<HprfParameterSetCapabilityFlag> hprfParameterSetCapabilities)884         public FiraSpecificationParams.Builder setHprfParameterSetCapabilities(
885                 Collection<HprfParameterSetCapabilityFlag> hprfParameterSetCapabilities) {
886             mHprfParameterSetCapabilities.addAll(hprfParameterSetCapabilities);
887             return this;
888         }
889 
setRangeDataNtfConfigCapabilities( Collection<RangeDataNtfConfigCapabilityFlag> rangeDataNtfConfigCapabilities)890         public FiraSpecificationParams.Builder setRangeDataNtfConfigCapabilities(
891                 Collection<RangeDataNtfConfigCapabilityFlag> rangeDataNtfConfigCapabilities) {
892             mRangeDataNtfConfigCapabilities.addAll(rangeDataNtfConfigCapabilities);
893             return this;
894         }
895 
setMaxMessageSize(Integer value)896         public FiraSpecificationParams.Builder setMaxMessageSize(Integer value) {
897             mMaxMessageSize = value;
898             return this;
899         }
900 
setMaxDataPacketPayloadSize(Integer value)901         public FiraSpecificationParams.Builder setMaxDataPacketPayloadSize(Integer value) {
902             mMaxDataPacketPayloadSize = value;
903             return this;
904         }
905 
setDeviceType(Integer value)906         public FiraSpecificationParams.Builder setDeviceType(Integer value) {
907             mDeviceType = value;
908             return this;
909 
910         }
911 
setSuspendRangingSupport(Boolean value)912         public FiraSpecificationParams.Builder setSuspendRangingSupport(Boolean value) {
913             mSuspendRangingSupport = value;
914             return this;
915         }
916 
setSessionKeyLength(Integer value)917         public FiraSpecificationParams.Builder setSessionKeyLength(Integer value) {
918             mSessionKeyLength = value;
919             return this;
920         }
921 
setDtTagMaxActiveRr(int value)922         public FiraSpecificationParams.Builder setDtTagMaxActiveRr(int value) {
923             mDtTagMaxActiveRr = value;
924             return this;
925         }
926 
setBackgroundRangingSupport(boolean value)927         public FiraSpecificationParams.Builder setBackgroundRangingSupport(boolean value) {
928             mHasBackgroundRangingSupport = value;
929             return this;
930         }
931 
setDtTagBlockSkippingSupport(boolean value)932         public FiraSpecificationParams.Builder setDtTagBlockSkippingSupport(boolean value) {
933             mHasDtTagBlockSkippingSupport = value;
934             return this;
935         }
936 
setPsduLengthSupport(boolean value)937         public FiraSpecificationParams.Builder setPsduLengthSupport(boolean value) {
938             mHasPsduLengthSupport = value;
939             return this;
940         }
941 
setUciVersionSupported( int uciVersion)942         public FiraSpecificationParams.Builder setUciVersionSupported(
943                 int uciVersion) {
944             mUciVersion = uciVersion;
945             return this;
946         }
947 
Builder()948         public Builder() {}
949 
Builder(@onNull FiraSpecificationParams params)950         public Builder(@NonNull FiraSpecificationParams params) {
951             mMinPhyVersionSupported = params.mMinPhyVersionSupported;
952             mMaxPhyVersionSupported = params.mMaxPhyVersionSupported;
953             mMinMacVersionSupported = params.mMinMacVersionSupported;
954             mMaxMacVersionSupported = params.mMaxMacVersionSupported;
955             mSupportedChannels = params.mSupportedChannels;
956             mAoaCapabilities = params.mAoaCapabilities;
957             mDeviceRoleCapabilities = params.mDeviceRoleCapabilities;
958             mHasBlockStridingSupport = params.mHasBlockStridingSupport;
959             mHasHoppingPreferenceSupport = params.mHasHoppingPreferenceSupport;
960             mHasExtendedMacAddressSupport = params.mHasExtendedMacAddressSupport;
961             mHasNonDeferredModeSupport = params.mHasNonDeferredModeSupport;
962             mHasInitiationTimeSupport = params.mHasInitiationTimeSupport;
963             mHasRssiReportingSupport = params.mHasRssiReportingSupport;
964             mHasDiagnosticsSupport = params.mHasDiagnosticsSupport;
965             mMinRangingInterval = params.mMinRangingInterval;
966             mMinSlotDurationUs = params.mMinSlotDurationUs;
967             mMaxRangingSessionNumber = params.mMaxRangingSessionNumber;
968             mMultiNodeCapabilities = params.mMultiNodeCapabilities;
969             mRangingTimeStructCapabilities = params.mRangingTimeStructCapabilities;
970             mSchedulingModeCapabilities = params.mSchedulingModeCapabilities;
971             mCcConstraintLengthCapabilities = params.mCcConstraintLengthCapabilities;
972             mPrfCapabilities = params.mPrfCapabilities;
973             mRangingRoundCapabilities = params.mRangingRoundCapabilities;
974             mRframeCapabilities = params.mRframeCapabilities;
975             mStsCapabilities = params.mStsCapabilities;
976             mPsduDataRateCapabilities = params.mPsduDataRateCapabilities;
977             mBprfParameterSetCapabilities = params.mBprfParameterSetCapabilities;
978             mHprfParameterSetCapabilities = params.mHprfParameterSetCapabilities;
979             mMaxMessageSize = params.mMaxMessageSize;
980             mMaxDataPacketPayloadSize = params.mMaxDataPacketPayloadSize;
981             mRangeDataNtfConfigCapabilities = params.mRangeDataNtfConfigCapabilities;
982             mDeviceType = params.mDeviceType;
983             mSuspendRangingSupport = params.mSuspendRangingSupport;
984             mSessionKeyLength = params.mSessionKeyLength;
985             mDtTagMaxActiveRr = params.mDtTagMaxActiveRr;
986             mHasBackgroundRangingSupport = params.mHasBackgroundRangingSupport;
987             mHasDtTagBlockSkippingSupport = params.mHasDtTagBlockSkippingSupport;
988             mHasPsduLengthSupport = params.mHasPsduLengthSupport;
989         }
990 
build()991         public FiraSpecificationParams build() {
992             return new FiraSpecificationParams(
993                     mMinPhyVersionSupported,
994                     mMaxPhyVersionSupported,
995                     mMinMacVersionSupported,
996                     mMaxMacVersionSupported,
997                     mSupportedChannels,
998                     mAoaCapabilities,
999                     mDeviceRoleCapabilities,
1000                     mHasBlockStridingSupport,
1001                     mHasHoppingPreferenceSupport,
1002                     mHasExtendedMacAddressSupport,
1003                     mHasNonDeferredModeSupport,
1004                     mHasInitiationTimeSupport,
1005                     mHasRssiReportingSupport,
1006                     mHasDiagnosticsSupport,
1007                     mMinRangingInterval,
1008                     mMinSlotDurationUs,
1009                     mMaxRangingSessionNumber,
1010                     mMultiNodeCapabilities,
1011                     mRangingTimeStructCapabilities,
1012                     mSchedulingModeCapabilities,
1013                     mCcConstraintLengthCapabilities,
1014                     mPrfCapabilities,
1015                     mRangingRoundCapabilities,
1016                     mRframeCapabilities,
1017                     mStsCapabilities,
1018                     mPsduDataRateCapabilities,
1019                     mBprfParameterSetCapabilities,
1020                     mHprfParameterSetCapabilities,
1021                     mMaxMessageSize,
1022                     mMaxDataPacketPayloadSize,
1023                     mRangeDataNtfConfigCapabilities,
1024                     mDeviceType,
1025                     mSuspendRangingSupport,
1026                     mSessionKeyLength,
1027                     mDtTagMaxActiveRr,
1028                     mHasBackgroundRangingSupport,
1029                     mHasDtTagBlockSkippingSupport,
1030                     mHasPsduLengthSupport,
1031                     mUciVersion);
1032         }
1033     }
1034 }
1035