• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 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.nearby.common.bluetooth.fastpair;
18 
19 import static com.android.server.nearby.common.bluetooth.fastpair.BluetoothUuids.get16BitUuid;
20 
21 import androidx.annotation.Nullable;
22 
23 import com.android.server.nearby.common.bluetooth.fastpair.Constants.FastPairService.FirmwareVersionCharacteristic;
24 
25 import com.google.common.collect.ImmutableSet;
26 import com.google.common.primitives.Shorts;
27 
28 import java.nio.ByteOrder;
29 import java.util.Arrays;
30 import java.util.Objects;
31 
32 /**
33  * Preferences that tweak the Fast Pairing process: timeouts, number of retries... All preferences
34  * have default values which should be reasonable for all clients.
35  */
36 public class Preferences {
37 
38     private final int mGattOperationTimeoutSeconds;
39     private final int mGattConnectionTimeoutSeconds;
40     private final int mBluetoothToggleTimeoutSeconds;
41     private final int mBluetoothToggleSleepSeconds;
42     private final int mClassicDiscoveryTimeoutSeconds;
43     private final int mNumDiscoverAttempts;
44     private final int mDiscoveryRetrySleepSeconds;
45     private final boolean mIgnoreDiscoveryError;
46     private final int mSdpTimeoutSeconds;
47     private final int mNumSdpAttempts;
48     private final int mNumCreateBondAttempts;
49     private final int mNumConnectAttempts;
50     private final int mNumWriteAccountKeyAttempts;
51     private final boolean mToggleBluetoothOnFailure;
52     private final boolean mBluetoothStateUsesPolling;
53     private final int mBluetoothStatePollingMillis;
54     private final int mNumAttempts;
55     private final boolean mEnableBrEdrHandover;
56     private final short mBrHandoverDataCharacteristicId;
57     private final short mBluetoothSigDataCharacteristicId;
58     private final short mFirmwareVersionCharacteristicId;
59     private final short mBrTransportBlockDataDescriptorId;
60     private final boolean mWaitForUuidsAfterBonding;
61     private final boolean mReceiveUuidsAndBondedEventBeforeClose;
62     private final int mRemoveBondTimeoutSeconds;
63     private final int mRemoveBondSleepMillis;
64     private final int mCreateBondTimeoutSeconds;
65     private final int mHidCreateBondTimeoutSeconds;
66     private final int mProxyTimeoutSeconds;
67     private final boolean mRejectPhonebookAccess;
68     private final boolean mRejectMessageAccess;
69     private final boolean mRejectSimAccess;
70     private final int mWriteAccountKeySleepMillis;
71     private final boolean mSkipDisconnectingGattBeforeWritingAccountKey;
72     private final boolean mMoreEventLogForQuality;
73     private final boolean mRetryGattConnectionAndSecretHandshake;
74     private final long mGattConnectShortTimeoutMs;
75     private final long mGattConnectLongTimeoutMs;
76     private final long mGattConnectShortTimeoutRetryMaxSpentTimeMs;
77     private final long mAddressRotateRetryMaxSpentTimeMs;
78     private final long mPairingRetryDelayMs;
79     private final long mSecretHandshakeShortTimeoutMs;
80     private final long mSecretHandshakeLongTimeoutMs;
81     private final long mSecretHandshakeShortTimeoutRetryMaxSpentTimeMs;
82     private final long mSecretHandshakeLongTimeoutRetryMaxSpentTimeMs;
83     private final long mSecretHandshakeRetryAttempts;
84     private final long mSecretHandshakeRetryGattConnectionMaxSpentTimeMs;
85     private final long mSignalLostRetryMaxSpentTimeMs;
86     private final ImmutableSet<Integer> mGattConnectionAndSecretHandshakeNoRetryGattError;
87     private final boolean mRetrySecretHandshakeTimeout;
88     private final boolean mLogUserManualRetry;
89     private final int mPairFailureCounts;
90     private final String mCachedDeviceAddress;
91     private final String mPossibleCachedDeviceAddress;
92     private final int mSameModelIdPairedDeviceCount;
93     private final boolean mIsDeviceFinishCheckAddressFromCache;
94     private final boolean mLogPairWithCachedModelId;
95     private final boolean mDirectConnectProfileIfModelIdInCache;
96     private final boolean mAcceptPasskey;
97     private final byte[] mSupportedProfileUuids;
98     private final boolean mProviderInitiatesBondingIfSupported;
99     private final boolean mAttemptDirectConnectionWhenPreviouslyBonded;
100     private final boolean mAutomaticallyReconnectGattWhenNeeded;
101     private final boolean mSkipConnectingProfiles;
102     private final boolean mIgnoreUuidTimeoutAfterBonded;
103     private final boolean mSpecifyCreateBondTransportType;
104     private final int mCreateBondTransportType;
105     private final boolean mIncreaseIntentFilterPriority;
106     private final boolean mEvaluatePerformance;
107     private final Preferences.ExtraLoggingInformation mExtraLoggingInformation;
108     private final boolean mEnableNamingCharacteristic;
109     private final boolean mEnableFirmwareVersionCharacteristic;
110     private final boolean mKeepSameAccountKeyWrite;
111     private final boolean mIsRetroactivePairing;
112     private final int mNumSdpAttemptsAfterBonded;
113     private final boolean mSupportHidDevice;
114     private final boolean mEnablePairingWhileDirectlyConnecting;
115     private final boolean mAcceptConsentForFastPairOne;
116     private final int mGattConnectRetryTimeoutMillis;
117     private final boolean mEnable128BitCustomGattCharacteristicsId;
118     private final boolean mEnableSendExceptionStepToValidator;
119     private final boolean mEnableAdditionalDataTypeWhenActionOverBle;
120     private final boolean mCheckBondStateWhenSkipConnectingProfiles;
121     private final boolean mHandlePasskeyConfirmationByUi;
122     private final boolean mEnablePairFlowShowUiWithoutProfileConnection;
123 
Preferences( int gattOperationTimeoutSeconds, int gattConnectionTimeoutSeconds, int bluetoothToggleTimeoutSeconds, int bluetoothToggleSleepSeconds, int classicDiscoveryTimeoutSeconds, int numDiscoverAttempts, int discoveryRetrySleepSeconds, boolean ignoreDiscoveryError, int sdpTimeoutSeconds, int numSdpAttempts, int numCreateBondAttempts, int numConnectAttempts, int numWriteAccountKeyAttempts, boolean toggleBluetoothOnFailure, boolean bluetoothStateUsesPolling, int bluetoothStatePollingMillis, int numAttempts, boolean enableBrEdrHandover, short brHandoverDataCharacteristicId, short bluetoothSigDataCharacteristicId, short firmwareVersionCharacteristicId, short brTransportBlockDataDescriptorId, boolean waitForUuidsAfterBonding, boolean receiveUuidsAndBondedEventBeforeClose, int removeBondTimeoutSeconds, int removeBondSleepMillis, int createBondTimeoutSeconds, int hidCreateBondTimeoutSeconds, int proxyTimeoutSeconds, boolean rejectPhonebookAccess, boolean rejectMessageAccess, boolean rejectSimAccess, int writeAccountKeySleepMillis, boolean skipDisconnectingGattBeforeWritingAccountKey, boolean moreEventLogForQuality, boolean retryGattConnectionAndSecretHandshake, long gattConnectShortTimeoutMs, long gattConnectLongTimeoutMs, long gattConnectShortTimeoutRetryMaxSpentTimeMs, long addressRotateRetryMaxSpentTimeMs, long pairingRetryDelayMs, long secretHandshakeShortTimeoutMs, long secretHandshakeLongTimeoutMs, long secretHandshakeShortTimeoutRetryMaxSpentTimeMs, long secretHandshakeLongTimeoutRetryMaxSpentTimeMs, long secretHandshakeRetryAttempts, long secretHandshakeRetryGattConnectionMaxSpentTimeMs, long signalLostRetryMaxSpentTimeMs, ImmutableSet<Integer> gattConnectionAndSecretHandshakeNoRetryGattError, boolean retrySecretHandshakeTimeout, boolean logUserManualRetry, int pairFailureCounts, String cachedDeviceAddress, String possibleCachedDeviceAddress, int sameModelIdPairedDeviceCount, boolean isDeviceFinishCheckAddressFromCache, boolean logPairWithCachedModelId, boolean directConnectProfileIfModelIdInCache, boolean acceptPasskey, byte[] supportedProfileUuids, boolean providerInitiatesBondingIfSupported, boolean attemptDirectConnectionWhenPreviouslyBonded, boolean automaticallyReconnectGattWhenNeeded, boolean skipConnectingProfiles, boolean ignoreUuidTimeoutAfterBonded, boolean specifyCreateBondTransportType, int createBondTransportType, boolean increaseIntentFilterPriority, boolean evaluatePerformance, @Nullable Preferences.ExtraLoggingInformation extraLoggingInformation, boolean enableNamingCharacteristic, boolean enableFirmwareVersionCharacteristic, boolean keepSameAccountKeyWrite, boolean isRetroactivePairing, int numSdpAttemptsAfterBonded, boolean supportHidDevice, boolean enablePairingWhileDirectlyConnecting, boolean acceptConsentForFastPairOne, int gattConnectRetryTimeoutMillis, boolean enable128BitCustomGattCharacteristicsId, boolean enableSendExceptionStepToValidator, boolean enableAdditionalDataTypeWhenActionOverBle, boolean checkBondStateWhenSkipConnectingProfiles, boolean handlePasskeyConfirmationByUi, boolean enablePairFlowShowUiWithoutProfileConnection)124     private Preferences(
125             int gattOperationTimeoutSeconds,
126             int gattConnectionTimeoutSeconds,
127             int bluetoothToggleTimeoutSeconds,
128             int bluetoothToggleSleepSeconds,
129             int classicDiscoveryTimeoutSeconds,
130             int numDiscoverAttempts,
131             int discoveryRetrySleepSeconds,
132             boolean ignoreDiscoveryError,
133             int sdpTimeoutSeconds,
134             int numSdpAttempts,
135             int numCreateBondAttempts,
136             int numConnectAttempts,
137             int numWriteAccountKeyAttempts,
138             boolean toggleBluetoothOnFailure,
139             boolean bluetoothStateUsesPolling,
140             int bluetoothStatePollingMillis,
141             int numAttempts,
142             boolean enableBrEdrHandover,
143             short brHandoverDataCharacteristicId,
144             short bluetoothSigDataCharacteristicId,
145             short firmwareVersionCharacteristicId,
146             short brTransportBlockDataDescriptorId,
147             boolean waitForUuidsAfterBonding,
148             boolean receiveUuidsAndBondedEventBeforeClose,
149             int removeBondTimeoutSeconds,
150             int removeBondSleepMillis,
151             int createBondTimeoutSeconds,
152             int hidCreateBondTimeoutSeconds,
153             int proxyTimeoutSeconds,
154             boolean rejectPhonebookAccess,
155             boolean rejectMessageAccess,
156             boolean rejectSimAccess,
157             int writeAccountKeySleepMillis,
158             boolean skipDisconnectingGattBeforeWritingAccountKey,
159             boolean moreEventLogForQuality,
160             boolean retryGattConnectionAndSecretHandshake,
161             long gattConnectShortTimeoutMs,
162             long gattConnectLongTimeoutMs,
163             long gattConnectShortTimeoutRetryMaxSpentTimeMs,
164             long addressRotateRetryMaxSpentTimeMs,
165             long pairingRetryDelayMs,
166             long secretHandshakeShortTimeoutMs,
167             long secretHandshakeLongTimeoutMs,
168             long secretHandshakeShortTimeoutRetryMaxSpentTimeMs,
169             long secretHandshakeLongTimeoutRetryMaxSpentTimeMs,
170             long secretHandshakeRetryAttempts,
171             long secretHandshakeRetryGattConnectionMaxSpentTimeMs,
172             long signalLostRetryMaxSpentTimeMs,
173             ImmutableSet<Integer> gattConnectionAndSecretHandshakeNoRetryGattError,
174             boolean retrySecretHandshakeTimeout,
175             boolean logUserManualRetry,
176             int pairFailureCounts,
177             String cachedDeviceAddress,
178             String possibleCachedDeviceAddress,
179             int sameModelIdPairedDeviceCount,
180             boolean isDeviceFinishCheckAddressFromCache,
181             boolean logPairWithCachedModelId,
182             boolean directConnectProfileIfModelIdInCache,
183             boolean acceptPasskey,
184             byte[] supportedProfileUuids,
185             boolean providerInitiatesBondingIfSupported,
186             boolean attemptDirectConnectionWhenPreviouslyBonded,
187             boolean automaticallyReconnectGattWhenNeeded,
188             boolean skipConnectingProfiles,
189             boolean ignoreUuidTimeoutAfterBonded,
190             boolean specifyCreateBondTransportType,
191             int createBondTransportType,
192             boolean increaseIntentFilterPriority,
193             boolean evaluatePerformance,
194             @Nullable Preferences.ExtraLoggingInformation extraLoggingInformation,
195             boolean enableNamingCharacteristic,
196             boolean enableFirmwareVersionCharacteristic,
197             boolean keepSameAccountKeyWrite,
198             boolean isRetroactivePairing,
199             int numSdpAttemptsAfterBonded,
200             boolean supportHidDevice,
201             boolean enablePairingWhileDirectlyConnecting,
202             boolean acceptConsentForFastPairOne,
203             int gattConnectRetryTimeoutMillis,
204             boolean enable128BitCustomGattCharacteristicsId,
205             boolean enableSendExceptionStepToValidator,
206             boolean enableAdditionalDataTypeWhenActionOverBle,
207             boolean checkBondStateWhenSkipConnectingProfiles,
208             boolean handlePasskeyConfirmationByUi,
209             boolean enablePairFlowShowUiWithoutProfileConnection) {
210         this.mGattOperationTimeoutSeconds = gattOperationTimeoutSeconds;
211         this.mGattConnectionTimeoutSeconds = gattConnectionTimeoutSeconds;
212         this.mBluetoothToggleTimeoutSeconds = bluetoothToggleTimeoutSeconds;
213         this.mBluetoothToggleSleepSeconds = bluetoothToggleSleepSeconds;
214         this.mClassicDiscoveryTimeoutSeconds = classicDiscoveryTimeoutSeconds;
215         this.mNumDiscoverAttempts = numDiscoverAttempts;
216         this.mDiscoveryRetrySleepSeconds = discoveryRetrySleepSeconds;
217         this.mIgnoreDiscoveryError = ignoreDiscoveryError;
218         this.mSdpTimeoutSeconds = sdpTimeoutSeconds;
219         this.mNumSdpAttempts = numSdpAttempts;
220         this.mNumCreateBondAttempts = numCreateBondAttempts;
221         this.mNumConnectAttempts = numConnectAttempts;
222         this.mNumWriteAccountKeyAttempts = numWriteAccountKeyAttempts;
223         this.mToggleBluetoothOnFailure = toggleBluetoothOnFailure;
224         this.mBluetoothStateUsesPolling = bluetoothStateUsesPolling;
225         this.mBluetoothStatePollingMillis = bluetoothStatePollingMillis;
226         this.mNumAttempts = numAttempts;
227         this.mEnableBrEdrHandover = enableBrEdrHandover;
228         this.mBrHandoverDataCharacteristicId = brHandoverDataCharacteristicId;
229         this.mBluetoothSigDataCharacteristicId = bluetoothSigDataCharacteristicId;
230         this.mFirmwareVersionCharacteristicId = firmwareVersionCharacteristicId;
231         this.mBrTransportBlockDataDescriptorId = brTransportBlockDataDescriptorId;
232         this.mWaitForUuidsAfterBonding = waitForUuidsAfterBonding;
233         this.mReceiveUuidsAndBondedEventBeforeClose = receiveUuidsAndBondedEventBeforeClose;
234         this.mRemoveBondTimeoutSeconds = removeBondTimeoutSeconds;
235         this.mRemoveBondSleepMillis = removeBondSleepMillis;
236         this.mCreateBondTimeoutSeconds = createBondTimeoutSeconds;
237         this.mHidCreateBondTimeoutSeconds = hidCreateBondTimeoutSeconds;
238         this.mProxyTimeoutSeconds = proxyTimeoutSeconds;
239         this.mRejectPhonebookAccess = rejectPhonebookAccess;
240         this.mRejectMessageAccess = rejectMessageAccess;
241         this.mRejectSimAccess = rejectSimAccess;
242         this.mWriteAccountKeySleepMillis = writeAccountKeySleepMillis;
243         this.mSkipDisconnectingGattBeforeWritingAccountKey =
244                 skipDisconnectingGattBeforeWritingAccountKey;
245         this.mMoreEventLogForQuality = moreEventLogForQuality;
246         this.mRetryGattConnectionAndSecretHandshake = retryGattConnectionAndSecretHandshake;
247         this.mGattConnectShortTimeoutMs = gattConnectShortTimeoutMs;
248         this.mGattConnectLongTimeoutMs = gattConnectLongTimeoutMs;
249         this.mGattConnectShortTimeoutRetryMaxSpentTimeMs =
250                 gattConnectShortTimeoutRetryMaxSpentTimeMs;
251         this.mAddressRotateRetryMaxSpentTimeMs = addressRotateRetryMaxSpentTimeMs;
252         this.mPairingRetryDelayMs = pairingRetryDelayMs;
253         this.mSecretHandshakeShortTimeoutMs = secretHandshakeShortTimeoutMs;
254         this.mSecretHandshakeLongTimeoutMs = secretHandshakeLongTimeoutMs;
255         this.mSecretHandshakeShortTimeoutRetryMaxSpentTimeMs =
256                 secretHandshakeShortTimeoutRetryMaxSpentTimeMs;
257         this.mSecretHandshakeLongTimeoutRetryMaxSpentTimeMs =
258                 secretHandshakeLongTimeoutRetryMaxSpentTimeMs;
259         this.mSecretHandshakeRetryAttempts = secretHandshakeRetryAttempts;
260         this.mSecretHandshakeRetryGattConnectionMaxSpentTimeMs =
261                 secretHandshakeRetryGattConnectionMaxSpentTimeMs;
262         this.mSignalLostRetryMaxSpentTimeMs = signalLostRetryMaxSpentTimeMs;
263         this.mGattConnectionAndSecretHandshakeNoRetryGattError =
264                 gattConnectionAndSecretHandshakeNoRetryGattError;
265         this.mRetrySecretHandshakeTimeout = retrySecretHandshakeTimeout;
266         this.mLogUserManualRetry = logUserManualRetry;
267         this.mPairFailureCounts = pairFailureCounts;
268         this.mCachedDeviceAddress = cachedDeviceAddress;
269         this.mPossibleCachedDeviceAddress = possibleCachedDeviceAddress;
270         this.mSameModelIdPairedDeviceCount = sameModelIdPairedDeviceCount;
271         this.mIsDeviceFinishCheckAddressFromCache = isDeviceFinishCheckAddressFromCache;
272         this.mLogPairWithCachedModelId = logPairWithCachedModelId;
273         this.mDirectConnectProfileIfModelIdInCache = directConnectProfileIfModelIdInCache;
274         this.mAcceptPasskey = acceptPasskey;
275         this.mSupportedProfileUuids = supportedProfileUuids;
276         this.mProviderInitiatesBondingIfSupported = providerInitiatesBondingIfSupported;
277         this.mAttemptDirectConnectionWhenPreviouslyBonded =
278                 attemptDirectConnectionWhenPreviouslyBonded;
279         this.mAutomaticallyReconnectGattWhenNeeded = automaticallyReconnectGattWhenNeeded;
280         this.mSkipConnectingProfiles = skipConnectingProfiles;
281         this.mIgnoreUuidTimeoutAfterBonded = ignoreUuidTimeoutAfterBonded;
282         this.mSpecifyCreateBondTransportType = specifyCreateBondTransportType;
283         this.mCreateBondTransportType = createBondTransportType;
284         this.mIncreaseIntentFilterPriority = increaseIntentFilterPriority;
285         this.mEvaluatePerformance = evaluatePerformance;
286         this.mExtraLoggingInformation = extraLoggingInformation;
287         this.mEnableNamingCharacteristic = enableNamingCharacteristic;
288         this.mEnableFirmwareVersionCharacteristic = enableFirmwareVersionCharacteristic;
289         this.mKeepSameAccountKeyWrite = keepSameAccountKeyWrite;
290         this.mIsRetroactivePairing = isRetroactivePairing;
291         this.mNumSdpAttemptsAfterBonded = numSdpAttemptsAfterBonded;
292         this.mSupportHidDevice = supportHidDevice;
293         this.mEnablePairingWhileDirectlyConnecting = enablePairingWhileDirectlyConnecting;
294         this.mAcceptConsentForFastPairOne = acceptConsentForFastPairOne;
295         this.mGattConnectRetryTimeoutMillis = gattConnectRetryTimeoutMillis;
296         this.mEnable128BitCustomGattCharacteristicsId = enable128BitCustomGattCharacteristicsId;
297         this.mEnableSendExceptionStepToValidator = enableSendExceptionStepToValidator;
298         this.mEnableAdditionalDataTypeWhenActionOverBle = enableAdditionalDataTypeWhenActionOverBle;
299         this.mCheckBondStateWhenSkipConnectingProfiles = checkBondStateWhenSkipConnectingProfiles;
300         this.mHandlePasskeyConfirmationByUi = handlePasskeyConfirmationByUi;
301         this.mEnablePairFlowShowUiWithoutProfileConnection =
302                 enablePairFlowShowUiWithoutProfileConnection;
303     }
304 
305     /**
306      * Timeout for each GATT operation (not for the whole pairing process).
307      */
getGattOperationTimeoutSeconds()308     public int getGattOperationTimeoutSeconds() {
309         return mGattOperationTimeoutSeconds;
310     }
311 
312     /**
313      * Timeout for Gatt connection operation.
314      */
getGattConnectionTimeoutSeconds()315     public int getGattConnectionTimeoutSeconds() {
316         return mGattConnectionTimeoutSeconds;
317     }
318 
319     /**
320      * Timeout for Bluetooth toggle.
321      */
getBluetoothToggleTimeoutSeconds()322     public int getBluetoothToggleTimeoutSeconds() {
323         return mBluetoothToggleTimeoutSeconds;
324     }
325 
326     /**
327      * Sleep time for Bluetooth toggle.
328      */
getBluetoothToggleSleepSeconds()329     public int getBluetoothToggleSleepSeconds() {
330         return mBluetoothToggleSleepSeconds;
331     }
332 
333     /**
334      * Timeout for classic discovery.
335      */
getClassicDiscoveryTimeoutSeconds()336     public int getClassicDiscoveryTimeoutSeconds() {
337         return mClassicDiscoveryTimeoutSeconds;
338     }
339 
340     /**
341      * Number of discovery attempts allowed.
342      */
getNumDiscoverAttempts()343     public int getNumDiscoverAttempts() {
344         return mNumDiscoverAttempts;
345     }
346 
347     /**
348      * Sleep time between discovery retry.
349      */
getDiscoveryRetrySleepSeconds()350     public int getDiscoveryRetrySleepSeconds() {
351         return mDiscoveryRetrySleepSeconds;
352     }
353 
354     /**
355      * Whether to ignore error incurred during discovery.
356      */
getIgnoreDiscoveryError()357     public boolean getIgnoreDiscoveryError() {
358         return mIgnoreDiscoveryError;
359     }
360 
361     /**
362      * Timeout for Sdp.
363      */
getSdpTimeoutSeconds()364     public int getSdpTimeoutSeconds() {
365         return mSdpTimeoutSeconds;
366     }
367 
368     /**
369      * Number of Sdp attempts allowed.
370      */
getNumSdpAttempts()371     public int getNumSdpAttempts() {
372         return mNumSdpAttempts;
373     }
374 
375     /**
376      * Number of create bond attempts allowed.
377      */
getNumCreateBondAttempts()378     public int getNumCreateBondAttempts() {
379         return mNumCreateBondAttempts;
380     }
381 
382     /**
383      * Number of connect attempts allowed.
384      */
getNumConnectAttempts()385     public int getNumConnectAttempts() {
386         return mNumConnectAttempts;
387     }
388 
389     /**
390      * Number of write account key attempts allowed.
391      */
getNumWriteAccountKeyAttempts()392     public int getNumWriteAccountKeyAttempts() {
393         return mNumWriteAccountKeyAttempts;
394     }
395 
396     /**
397      * Returns whether it is OK toggle bluetooth to retry upon failure.
398      */
getToggleBluetoothOnFailure()399     public boolean getToggleBluetoothOnFailure() {
400         return mToggleBluetoothOnFailure;
401     }
402 
403     /**
404      * Whether to get Bluetooth state using polling.
405      */
getBluetoothStateUsesPolling()406     public boolean getBluetoothStateUsesPolling() {
407         return mBluetoothStateUsesPolling;
408     }
409 
410     /**
411      * Polling time when retrieving Bluetooth state.
412      */
getBluetoothStatePollingMillis()413     public int getBluetoothStatePollingMillis() {
414         return mBluetoothStatePollingMillis;
415     }
416 
417     /**
418      * The number of times to attempt a generic operation, before giving up.
419      */
getNumAttempts()420     public int getNumAttempts() {
421         return mNumAttempts;
422     }
423 
424     /**
425      * Returns whether BrEdr handover is enabled.
426      */
getEnableBrEdrHandover()427     public boolean getEnableBrEdrHandover() {
428         return mEnableBrEdrHandover;
429     }
430 
431     /**
432      * Returns characteristic Id for Br Handover data.
433      */
getBrHandoverDataCharacteristicId()434     public short getBrHandoverDataCharacteristicId() {
435         return mBrHandoverDataCharacteristicId;
436     }
437 
438     /**
439      * Returns characteristic Id for Bluethoth Sig data.
440      */
getBluetoothSigDataCharacteristicId()441     public short getBluetoothSigDataCharacteristicId() {
442         return mBluetoothSigDataCharacteristicId;
443     }
444 
445     /**
446      * Returns characteristic Id for Firmware version.
447      */
getFirmwareVersionCharacteristicId()448     public short getFirmwareVersionCharacteristicId() {
449         return mFirmwareVersionCharacteristicId;
450     }
451 
452     /**
453      * Returns descripter Id for Br transport block data.
454      */
getBrTransportBlockDataDescriptorId()455     public short getBrTransportBlockDataDescriptorId() {
456         return mBrTransportBlockDataDescriptorId;
457     }
458 
459     /**
460      * Whether to wait for Uuids after bonding.
461      */
getWaitForUuidsAfterBonding()462     public boolean getWaitForUuidsAfterBonding() {
463         return mWaitForUuidsAfterBonding;
464     }
465 
466     /**
467      * Whether to get received Uuids and bonded events before close.
468      */
getReceiveUuidsAndBondedEventBeforeClose()469     public boolean getReceiveUuidsAndBondedEventBeforeClose() {
470         return mReceiveUuidsAndBondedEventBeforeClose;
471     }
472 
473     /**
474      * Timeout for remove bond operation.
475      */
getRemoveBondTimeoutSeconds()476     public int getRemoveBondTimeoutSeconds() {
477         return mRemoveBondTimeoutSeconds;
478     }
479 
480     /**
481      * Sleep time for remove bond operation.
482      */
getRemoveBondSleepMillis()483     public int getRemoveBondSleepMillis() {
484         return mRemoveBondSleepMillis;
485     }
486 
487     /**
488      * This almost always succeeds (or fails) in 2-10 seconds (Taimen running O -> Nexus 6P sim).
489      */
getCreateBondTimeoutSeconds()490     public int getCreateBondTimeoutSeconds() {
491         return mCreateBondTimeoutSeconds;
492     }
493 
494     /**
495      * Timeout for creating bond with Hid devices.
496      */
getHidCreateBondTimeoutSeconds()497     public int getHidCreateBondTimeoutSeconds() {
498         return mHidCreateBondTimeoutSeconds;
499     }
500 
501     /**
502      * Timeout for get proxy operation.
503      */
getProxyTimeoutSeconds()504     public int getProxyTimeoutSeconds() {
505         return mProxyTimeoutSeconds;
506     }
507 
508     /**
509      * Whether to reject phone book access.
510      */
getRejectPhonebookAccess()511     public boolean getRejectPhonebookAccess() {
512         return mRejectPhonebookAccess;
513     }
514 
515     /**
516      * Whether to reject message access.
517      */
getRejectMessageAccess()518     public boolean getRejectMessageAccess() {
519         return mRejectMessageAccess;
520     }
521 
522     /**
523      * Whether to reject sim access.
524      */
getRejectSimAccess()525     public boolean getRejectSimAccess() {
526         return mRejectSimAccess;
527     }
528 
529     /**
530      * Sleep time for write account key operation.
531      */
getWriteAccountKeySleepMillis()532     public int getWriteAccountKeySleepMillis() {
533         return mWriteAccountKeySleepMillis;
534     }
535 
536     /**
537      * Whether to skip disconneting gatt before writing account key.
538      */
getSkipDisconnectingGattBeforeWritingAccountKey()539     public boolean getSkipDisconnectingGattBeforeWritingAccountKey() {
540         return mSkipDisconnectingGattBeforeWritingAccountKey;
541     }
542 
543     /**
544      * Whether to get more event log for quality improvement.
545      */
getMoreEventLogForQuality()546     public boolean getMoreEventLogForQuality() {
547         return mMoreEventLogForQuality;
548     }
549 
550     /**
551      * Whether to retry gatt connection and secrete handshake.
552      */
getRetryGattConnectionAndSecretHandshake()553     public boolean getRetryGattConnectionAndSecretHandshake() {
554         return mRetryGattConnectionAndSecretHandshake;
555     }
556 
557     /**
558      * Short Gatt connection timeoout.
559      */
getGattConnectShortTimeoutMs()560     public long getGattConnectShortTimeoutMs() {
561         return mGattConnectShortTimeoutMs;
562     }
563 
564     /**
565      * Long Gatt connection timeout.
566      */
getGattConnectLongTimeoutMs()567     public long getGattConnectLongTimeoutMs() {
568         return mGattConnectLongTimeoutMs;
569     }
570 
571     /**
572      * Short Timeout for Gatt connection, including retry.
573      */
getGattConnectShortTimeoutRetryMaxSpentTimeMs()574     public long getGattConnectShortTimeoutRetryMaxSpentTimeMs() {
575         return mGattConnectShortTimeoutRetryMaxSpentTimeMs;
576     }
577 
578     /**
579      * Timeout for address rotation, including retry.
580      */
getAddressRotateRetryMaxSpentTimeMs()581     public long getAddressRotateRetryMaxSpentTimeMs() {
582         return mAddressRotateRetryMaxSpentTimeMs;
583     }
584 
585     /**
586      * Returns pairing retry delay time.
587      */
getPairingRetryDelayMs()588     public long getPairingRetryDelayMs() {
589         return mPairingRetryDelayMs;
590     }
591 
592     /**
593      * Short timeout for secrete handshake.
594      */
getSecretHandshakeShortTimeoutMs()595     public long getSecretHandshakeShortTimeoutMs() {
596         return mSecretHandshakeShortTimeoutMs;
597     }
598 
599     /**
600      * Long timeout for secret handshake.
601      */
getSecretHandshakeLongTimeoutMs()602     public long getSecretHandshakeLongTimeoutMs() {
603         return mSecretHandshakeLongTimeoutMs;
604     }
605 
606     /**
607      * Short timeout for secret handshake, including retry.
608      */
getSecretHandshakeShortTimeoutRetryMaxSpentTimeMs()609     public long getSecretHandshakeShortTimeoutRetryMaxSpentTimeMs() {
610         return mSecretHandshakeShortTimeoutRetryMaxSpentTimeMs;
611     }
612 
613     /**
614      * Long timeout for secret handshake, including retry.
615      */
getSecretHandshakeLongTimeoutRetryMaxSpentTimeMs()616     public long getSecretHandshakeLongTimeoutRetryMaxSpentTimeMs() {
617         return mSecretHandshakeLongTimeoutRetryMaxSpentTimeMs;
618     }
619 
620     /**
621      * Number of secrete handshake retry allowed.
622      */
getSecretHandshakeRetryAttempts()623     public long getSecretHandshakeRetryAttempts() {
624         return mSecretHandshakeRetryAttempts;
625     }
626 
627     /**
628      * Timeout for secrete handshake and gatt connection, including retry.
629      */
getSecretHandshakeRetryGattConnectionMaxSpentTimeMs()630     public long getSecretHandshakeRetryGattConnectionMaxSpentTimeMs() {
631         return mSecretHandshakeRetryGattConnectionMaxSpentTimeMs;
632     }
633 
634     /**
635      * Timeout for signal lost handling, including retry.
636      */
getSignalLostRetryMaxSpentTimeMs()637     public long getSignalLostRetryMaxSpentTimeMs() {
638         return mSignalLostRetryMaxSpentTimeMs;
639     }
640 
641     /**
642      * Returns error for gatt connection and secrete handshake, without retry.
643      */
getGattConnectionAndSecretHandshakeNoRetryGattError()644     public ImmutableSet<Integer> getGattConnectionAndSecretHandshakeNoRetryGattError() {
645         return mGattConnectionAndSecretHandshakeNoRetryGattError;
646     }
647 
648     /**
649      * Whether to retry upon secrete handshake timeout.
650      */
getRetrySecretHandshakeTimeout()651     public boolean getRetrySecretHandshakeTimeout() {
652         return mRetrySecretHandshakeTimeout;
653     }
654 
655     /**
656      * Wehther to log user manual retry.
657      */
getLogUserManualRetry()658     public boolean getLogUserManualRetry() {
659         return mLogUserManualRetry;
660     }
661 
662     /**
663      * Returns number of pairing failure counts.
664      */
getPairFailureCounts()665     public int getPairFailureCounts() {
666         return mPairFailureCounts;
667     }
668 
669     /**
670      * Returns cached device address.
671      */
getCachedDeviceAddress()672     public String getCachedDeviceAddress() {
673         return mCachedDeviceAddress;
674     }
675 
676     /**
677      * Returns possible cached device address.
678      */
getPossibleCachedDeviceAddress()679     public String getPossibleCachedDeviceAddress() {
680         return mPossibleCachedDeviceAddress;
681     }
682 
683     /**
684      * Returns count of paired devices from the same model Id.
685      */
getSameModelIdPairedDeviceCount()686     public int getSameModelIdPairedDeviceCount() {
687         return mSameModelIdPairedDeviceCount;
688     }
689 
690     /**
691      * Whether the bonded device address is in the Cache .
692      */
getIsDeviceFinishCheckAddressFromCache()693     public boolean getIsDeviceFinishCheckAddressFromCache() {
694         return mIsDeviceFinishCheckAddressFromCache;
695     }
696 
697     /**
698      * Whether to log pairing info when cached model Id is hit.
699      */
getLogPairWithCachedModelId()700     public boolean getLogPairWithCachedModelId() {
701         return mLogPairWithCachedModelId;
702     }
703 
704     /**
705      * Whether to directly connnect to a profile of a device, whose model Id is in cache.
706      */
getDirectConnectProfileIfModelIdInCache()707     public boolean getDirectConnectProfileIfModelIdInCache() {
708         return mDirectConnectProfileIfModelIdInCache;
709     }
710 
711     /**
712      * Whether to auto-accept
713      * {@link android.bluetooth.BluetoothDevice#PAIRING_VARIANT_PASSKEY_CONFIRMATION}.
714      * Only the Fast Pair Simulator (which runs on an Android device) sends this. Since real
715      * Bluetooth headphones don't have displays, they use secure simple pairing (no pin code
716      * confirmation; we get no pairing request broadcast at all). So we may want to turn this off in
717      * prod.
718      */
getAcceptPasskey()719     public boolean getAcceptPasskey() {
720         return mAcceptPasskey;
721     }
722 
723     /**
724      * Returns Uuids for supported profiles.
725      */
726     @SuppressWarnings("mutable")
getSupportedProfileUuids()727     public byte[] getSupportedProfileUuids() {
728         return mSupportedProfileUuids;
729     }
730 
731     /**
732      * If true, after the Key-based Pairing BLE handshake, we wait for the headphones to send a
733      * pairing request to us; if false, we send the request to them.
734      */
getProviderInitiatesBondingIfSupported()735     public boolean getProviderInitiatesBondingIfSupported() {
736         return mProviderInitiatesBondingIfSupported;
737     }
738 
739     /**
740      * If true, the first step will be attempting to connect directly to our supported profiles when
741      * a device has previously been bonded. This will help with performance on subsequent bondings
742      * and help to increase reliability in some cases.
743      */
getAttemptDirectConnectionWhenPreviouslyBonded()744     public boolean getAttemptDirectConnectionWhenPreviouslyBonded() {
745         return mAttemptDirectConnectionWhenPreviouslyBonded;
746     }
747 
748     /**
749      * If true, closed Gatt connections will be reopened when they are needed again. Otherwise, they
750      * will remain closed until they are explicitly reopened.
751      */
getAutomaticallyReconnectGattWhenNeeded()752     public boolean getAutomaticallyReconnectGattWhenNeeded() {
753         return mAutomaticallyReconnectGattWhenNeeded;
754     }
755 
756     /**
757      * If true, we'll finish the pairing process after we've created a bond instead of after
758      * connecting a profile.
759      */
getSkipConnectingProfiles()760     public boolean getSkipConnectingProfiles() {
761         return mSkipConnectingProfiles;
762     }
763 
764     /**
765      * If true, continues the pairing process if we've timed out due to not receiving UUIDs from the
766      * headset. We can still attempt to connect to A2DP afterwards. If false, Fast Pair will fail
767      * after this step since we're expecting to receive the UUIDs.
768      */
getIgnoreUuidTimeoutAfterBonded()769     public boolean getIgnoreUuidTimeoutAfterBonded() {
770         return mIgnoreUuidTimeoutAfterBonded;
771     }
772 
773     /**
774      * If true, a specific transport type will be included in the create bond request, which will be
775      * used for dual mode devices. Otherwise, we'll use the platform defined default which is
776      * BluetoothDevice.TRANSPORT_AUTO. See {@link #getCreateBondTransportType()}.
777      */
getSpecifyCreateBondTransportType()778     public boolean getSpecifyCreateBondTransportType() {
779         return mSpecifyCreateBondTransportType;
780     }
781 
782     /**
783      * The transport type to use when creating a bond when
784      * {@link #getSpecifyCreateBondTransportType() is true. This should be one of
785      * BluetoothDevice.TRANSPORT_AUTO, BluetoothDevice.TRANSPORT_BREDR,
786      * or BluetoothDevice.TRANSPORT_LE.
787      */
getCreateBondTransportType()788     public int getCreateBondTransportType() {
789         return mCreateBondTransportType;
790     }
791 
792     /**
793      * Whether to increase intent filter priority.
794      */
getIncreaseIntentFilterPriority()795     public boolean getIncreaseIntentFilterPriority() {
796         return mIncreaseIntentFilterPriority;
797     }
798 
799     /**
800      * Whether to evaluate performance.
801      */
getEvaluatePerformance()802     public boolean getEvaluatePerformance() {
803         return mEvaluatePerformance;
804     }
805 
806     /**
807      * Returns extra logging information.
808      */
809     @Nullable
getExtraLoggingInformation()810     public ExtraLoggingInformation getExtraLoggingInformation() {
811         return mExtraLoggingInformation;
812     }
813 
814     /**
815      * Whether to enable naming characteristic.
816      */
getEnableNamingCharacteristic()817     public boolean getEnableNamingCharacteristic() {
818         return mEnableNamingCharacteristic;
819     }
820 
821     /**
822      * Whether to enable firmware version characteristic.
823      */
getEnableFirmwareVersionCharacteristic()824     public boolean getEnableFirmwareVersionCharacteristic() {
825         return mEnableFirmwareVersionCharacteristic;
826     }
827 
828     /**
829      * If true, even Fast Pair identifies a provider have paired with the account, still writes the
830      * identified account key to the provider.
831      */
getKeepSameAccountKeyWrite()832     public boolean getKeepSameAccountKeyWrite() {
833         return mKeepSameAccountKeyWrite;
834     }
835 
836     /**
837      * If true, run retroactive pairing.
838      */
getIsRetroactivePairing()839     public boolean getIsRetroactivePairing() {
840         return mIsRetroactivePairing;
841     }
842 
843     /**
844      * If it's larger than 0, {@link android.bluetooth.BluetoothDevice#fetchUuidsWithSdp} would be
845      * triggered with number of attempts after device is bonded and no profiles were automatically
846      * discovered".
847      */
getNumSdpAttemptsAfterBonded()848     public int getNumSdpAttemptsAfterBonded() {
849         return mNumSdpAttemptsAfterBonded;
850     }
851 
852     /**
853      * If true, supports HID device for fastpair.
854      */
getSupportHidDevice()855     public boolean getSupportHidDevice() {
856         return mSupportHidDevice;
857     }
858 
859     /**
860      * If true, we'll enable the pairing behavior to handle the state transition from BOND_BONDED to
861      * BOND_BONDING when directly connecting profiles.
862      */
getEnablePairingWhileDirectlyConnecting()863     public boolean getEnablePairingWhileDirectlyConnecting() {
864         return mEnablePairingWhileDirectlyConnecting;
865     }
866 
867     /**
868      * If true, we will accept the user confirmation when bonding with FastPair 1.0 devices.
869      */
getAcceptConsentForFastPairOne()870     public boolean getAcceptConsentForFastPairOne() {
871         return mAcceptConsentForFastPairOne;
872     }
873 
874     /**
875      * If it's larger than 0, we will retry connecting GATT within the timeout.
876      */
getGattConnectRetryTimeoutMillis()877     public int getGattConnectRetryTimeoutMillis() {
878         return mGattConnectRetryTimeoutMillis;
879     }
880 
881     /**
882      * If true, then uses the new custom GATT characteristics {go/fastpair-128bit-gatt}.
883      */
getEnable128BitCustomGattCharacteristicsId()884     public boolean getEnable128BitCustomGattCharacteristicsId() {
885         return mEnable128BitCustomGattCharacteristicsId;
886     }
887 
888     /**
889      * If true, then sends the internal pair step or Exception to Validator by Intent.
890      */
getEnableSendExceptionStepToValidator()891     public boolean getEnableSendExceptionStepToValidator() {
892         return mEnableSendExceptionStepToValidator;
893     }
894 
895     /**
896      * If true, then adds the additional data type in the handshake packet when action over BLE.
897      */
getEnableAdditionalDataTypeWhenActionOverBle()898     public boolean getEnableAdditionalDataTypeWhenActionOverBle() {
899         return mEnableAdditionalDataTypeWhenActionOverBle;
900     }
901 
902     /**
903      * If true, then checks the bond state when skips connecting profiles in the pairing shortcut.
904      */
getCheckBondStateWhenSkipConnectingProfiles()905     public boolean getCheckBondStateWhenSkipConnectingProfiles() {
906         return mCheckBondStateWhenSkipConnectingProfiles;
907     }
908 
909     /**
910      * If true, the passkey confirmation will be handled by the half-sheet UI.
911      */
getHandlePasskeyConfirmationByUi()912     public boolean getHandlePasskeyConfirmationByUi() {
913         return mHandlePasskeyConfirmationByUi;
914     }
915 
916     /**
917      * If true, then use pair flow to show ui when pairing is finished without connecting profile.
918      */
getEnablePairFlowShowUiWithoutProfileConnection()919     public boolean getEnablePairFlowShowUiWithoutProfileConnection() {
920         return mEnablePairFlowShowUiWithoutProfileConnection;
921     }
922 
923     @Override
toString()924     public String toString() {
925         return "Preferences{"
926                 + "gattOperationTimeoutSeconds=" + mGattOperationTimeoutSeconds + ", "
927                 + "gattConnectionTimeoutSeconds=" + mGattConnectionTimeoutSeconds + ", "
928                 + "bluetoothToggleTimeoutSeconds=" + mBluetoothToggleTimeoutSeconds + ", "
929                 + "bluetoothToggleSleepSeconds=" + mBluetoothToggleSleepSeconds + ", "
930                 + "classicDiscoveryTimeoutSeconds=" + mClassicDiscoveryTimeoutSeconds + ", "
931                 + "numDiscoverAttempts=" + mNumDiscoverAttempts + ", "
932                 + "discoveryRetrySleepSeconds=" + mDiscoveryRetrySleepSeconds + ", "
933                 + "ignoreDiscoveryError=" + mIgnoreDiscoveryError + ", "
934                 + "sdpTimeoutSeconds=" + mSdpTimeoutSeconds + ", "
935                 + "numSdpAttempts=" + mNumSdpAttempts + ", "
936                 + "numCreateBondAttempts=" + mNumCreateBondAttempts + ", "
937                 + "numConnectAttempts=" + mNumConnectAttempts + ", "
938                 + "numWriteAccountKeyAttempts=" + mNumWriteAccountKeyAttempts + ", "
939                 + "toggleBluetoothOnFailure=" + mToggleBluetoothOnFailure + ", "
940                 + "bluetoothStateUsesPolling=" + mBluetoothStateUsesPolling + ", "
941                 + "bluetoothStatePollingMillis=" + mBluetoothStatePollingMillis + ", "
942                 + "numAttempts=" + mNumAttempts + ", "
943                 + "enableBrEdrHandover=" + mEnableBrEdrHandover + ", "
944                 + "brHandoverDataCharacteristicId=" + mBrHandoverDataCharacteristicId + ", "
945                 + "bluetoothSigDataCharacteristicId=" + mBluetoothSigDataCharacteristicId + ", "
946                 + "firmwareVersionCharacteristicId=" + mFirmwareVersionCharacteristicId + ", "
947                 + "brTransportBlockDataDescriptorId=" + mBrTransportBlockDataDescriptorId + ", "
948                 + "waitForUuidsAfterBonding=" + mWaitForUuidsAfterBonding + ", "
949                 + "receiveUuidsAndBondedEventBeforeClose=" + mReceiveUuidsAndBondedEventBeforeClose
950                 + ", "
951                 + "removeBondTimeoutSeconds=" + mRemoveBondTimeoutSeconds + ", "
952                 + "removeBondSleepMillis=" + mRemoveBondSleepMillis + ", "
953                 + "createBondTimeoutSeconds=" + mCreateBondTimeoutSeconds + ", "
954                 + "hidCreateBondTimeoutSeconds=" + mHidCreateBondTimeoutSeconds + ", "
955                 + "proxyTimeoutSeconds=" + mProxyTimeoutSeconds + ", "
956                 + "rejectPhonebookAccess=" + mRejectPhonebookAccess + ", "
957                 + "rejectMessageAccess=" + mRejectMessageAccess + ", "
958                 + "rejectSimAccess=" + mRejectSimAccess + ", "
959                 + "writeAccountKeySleepMillis=" + mWriteAccountKeySleepMillis + ", "
960                 + "skipDisconnectingGattBeforeWritingAccountKey="
961                 + mSkipDisconnectingGattBeforeWritingAccountKey + ", "
962                 + "moreEventLogForQuality=" + mMoreEventLogForQuality + ", "
963                 + "retryGattConnectionAndSecretHandshake=" + mRetryGattConnectionAndSecretHandshake
964                 + ", "
965                 + "gattConnectShortTimeoutMs=" + mGattConnectShortTimeoutMs + ", "
966                 + "gattConnectLongTimeoutMs=" + mGattConnectLongTimeoutMs + ", "
967                 + "gattConnectShortTimeoutRetryMaxSpentTimeMs="
968                 + mGattConnectShortTimeoutRetryMaxSpentTimeMs + ", "
969                 + "addressRotateRetryMaxSpentTimeMs=" + mAddressRotateRetryMaxSpentTimeMs + ", "
970                 + "pairingRetryDelayMs=" + mPairingRetryDelayMs + ", "
971                 + "secretHandshakeShortTimeoutMs=" + mSecretHandshakeShortTimeoutMs + ", "
972                 + "secretHandshakeLongTimeoutMs=" + mSecretHandshakeLongTimeoutMs + ", "
973                 + "secretHandshakeShortTimeoutRetryMaxSpentTimeMs="
974                 + mSecretHandshakeShortTimeoutRetryMaxSpentTimeMs + ", "
975                 + "secretHandshakeLongTimeoutRetryMaxSpentTimeMs="
976                 + mSecretHandshakeLongTimeoutRetryMaxSpentTimeMs + ", "
977                 + "secretHandshakeRetryAttempts=" + mSecretHandshakeRetryAttempts + ", "
978                 + "secretHandshakeRetryGattConnectionMaxSpentTimeMs="
979                 + mSecretHandshakeRetryGattConnectionMaxSpentTimeMs + ", "
980                 + "signalLostRetryMaxSpentTimeMs=" + mSignalLostRetryMaxSpentTimeMs + ", "
981                 + "gattConnectionAndSecretHandshakeNoRetryGattError="
982                 + mGattConnectionAndSecretHandshakeNoRetryGattError + ", "
983                 + "retrySecretHandshakeTimeout=" + mRetrySecretHandshakeTimeout + ", "
984                 + "logUserManualRetry=" + mLogUserManualRetry + ", "
985                 + "pairFailureCounts=" + mPairFailureCounts + ", "
986                 + "cachedDeviceAddress=" + mCachedDeviceAddress + ", "
987                 + "possibleCachedDeviceAddress=" + mPossibleCachedDeviceAddress + ", "
988                 + "sameModelIdPairedDeviceCount=" + mSameModelIdPairedDeviceCount + ", "
989                 + "isDeviceFinishCheckAddressFromCache=" + mIsDeviceFinishCheckAddressFromCache
990                 + ", "
991                 + "logPairWithCachedModelId=" + mLogPairWithCachedModelId + ", "
992                 + "directConnectProfileIfModelIdInCache=" + mDirectConnectProfileIfModelIdInCache
993                 + ", "
994                 + "acceptPasskey=" + mAcceptPasskey + ", "
995                 + "supportedProfileUuids=" + Arrays.toString(mSupportedProfileUuids) + ", "
996                 + "providerInitiatesBondingIfSupported=" + mProviderInitiatesBondingIfSupported
997                 + ", "
998                 + "attemptDirectConnectionWhenPreviouslyBonded="
999                 + mAttemptDirectConnectionWhenPreviouslyBonded + ", "
1000                 + "automaticallyReconnectGattWhenNeeded=" + mAutomaticallyReconnectGattWhenNeeded
1001                 + ", "
1002                 + "skipConnectingProfiles=" + mSkipConnectingProfiles + ", "
1003                 + "ignoreUuidTimeoutAfterBonded=" + mIgnoreUuidTimeoutAfterBonded + ", "
1004                 + "specifyCreateBondTransportType=" + mSpecifyCreateBondTransportType + ", "
1005                 + "createBondTransportType=" + mCreateBondTransportType + ", "
1006                 + "increaseIntentFilterPriority=" + mIncreaseIntentFilterPriority + ", "
1007                 + "evaluatePerformance=" + mEvaluatePerformance + ", "
1008                 + "extraLoggingInformation=" + mExtraLoggingInformation + ", "
1009                 + "enableNamingCharacteristic=" + mEnableNamingCharacteristic + ", "
1010                 + "enableFirmwareVersionCharacteristic=" + mEnableFirmwareVersionCharacteristic
1011                 + ", "
1012                 + "keepSameAccountKeyWrite=" + mKeepSameAccountKeyWrite + ", "
1013                 + "isRetroactivePairing=" + mIsRetroactivePairing + ", "
1014                 + "numSdpAttemptsAfterBonded=" + mNumSdpAttemptsAfterBonded + ", "
1015                 + "supportHidDevice=" + mSupportHidDevice + ", "
1016                 + "enablePairingWhileDirectlyConnecting=" + mEnablePairingWhileDirectlyConnecting
1017                 + ", "
1018                 + "acceptConsentForFastPairOne=" + mAcceptConsentForFastPairOne + ", "
1019                 + "gattConnectRetryTimeoutMillis=" + mGattConnectRetryTimeoutMillis + ", "
1020                 + "enable128BitCustomGattCharacteristicsId="
1021                 + mEnable128BitCustomGattCharacteristicsId + ", "
1022                 + "enableSendExceptionStepToValidator=" + mEnableSendExceptionStepToValidator + ", "
1023                 + "enableAdditionalDataTypeWhenActionOverBle="
1024                 + mEnableAdditionalDataTypeWhenActionOverBle + ", "
1025                 + "checkBondStateWhenSkipConnectingProfiles="
1026                 + mCheckBondStateWhenSkipConnectingProfiles + ", "
1027                 + "handlePasskeyConfirmationByUi=" + mHandlePasskeyConfirmationByUi + ", "
1028                 + "enablePairFlowShowUiWithoutProfileConnection="
1029                 + mEnablePairFlowShowUiWithoutProfileConnection
1030                 + "}";
1031     }
1032 
1033     /**
1034      * Converts an instance to a builder.
1035      */
toBuilder()1036     public Builder toBuilder() {
1037         return new Preferences.Builder(this);
1038     }
1039 
1040     /**
1041      * Constructs a builder.
1042      */
builder()1043     public static Builder builder() {
1044         return new Preferences.Builder()
1045                 .setGattOperationTimeoutSeconds(10)
1046                 .setGattConnectionTimeoutSeconds(15)
1047                 .setBluetoothToggleTimeoutSeconds(10)
1048                 .setBluetoothToggleSleepSeconds(2)
1049                 .setClassicDiscoveryTimeoutSeconds(13)
1050                 .setNumDiscoverAttempts(3)
1051                 .setDiscoveryRetrySleepSeconds(1)
1052                 .setIgnoreDiscoveryError(true)
1053                 .setSdpTimeoutSeconds(10)
1054                 .setNumSdpAttempts(0)
1055                 .setNumCreateBondAttempts(3)
1056                 .setNumConnectAttempts(2)
1057                 .setNumWriteAccountKeyAttempts(3)
1058                 .setToggleBluetoothOnFailure(false)
1059                 .setBluetoothStateUsesPolling(true)
1060                 .setBluetoothStatePollingMillis(1000)
1061                 .setNumAttempts(2)
1062                 .setEnableBrEdrHandover(false)
1063                 .setBrHandoverDataCharacteristicId(get16BitUuid(
1064                         Constants.TransportDiscoveryService.BrHandoverDataCharacteristic.ID))
1065                 .setBluetoothSigDataCharacteristicId(get16BitUuid(
1066                         Constants.TransportDiscoveryService.BluetoothSigDataCharacteristic.ID))
1067                 .setFirmwareVersionCharacteristicId(get16BitUuid(FirmwareVersionCharacteristic.ID))
1068                 .setBrTransportBlockDataDescriptorId(
1069                         get16BitUuid(
1070                                 Constants.TransportDiscoveryService.BluetoothSigDataCharacteristic
1071                                         .BrTransportBlockDataDescriptor.ID))
1072                 .setWaitForUuidsAfterBonding(true)
1073                 .setReceiveUuidsAndBondedEventBeforeClose(true)
1074                 .setRemoveBondTimeoutSeconds(5)
1075                 .setRemoveBondSleepMillis(1000)
1076                 .setCreateBondTimeoutSeconds(15)
1077                 .setHidCreateBondTimeoutSeconds(40)
1078                 .setProxyTimeoutSeconds(2)
1079                 .setRejectPhonebookAccess(false)
1080                 .setRejectMessageAccess(false)
1081                 .setRejectSimAccess(false)
1082                 .setAcceptPasskey(true)
1083                 .setSupportedProfileUuids(Constants.getSupportedProfiles())
1084                 .setWriteAccountKeySleepMillis(2000)
1085                 .setProviderInitiatesBondingIfSupported(false)
1086                 .setAttemptDirectConnectionWhenPreviouslyBonded(true)
1087                 .setAutomaticallyReconnectGattWhenNeeded(true)
1088                 .setSkipDisconnectingGattBeforeWritingAccountKey(true)
1089                 .setSkipConnectingProfiles(false)
1090                 .setIgnoreUuidTimeoutAfterBonded(true)
1091                 .setSpecifyCreateBondTransportType(false)
1092                 .setCreateBondTransportType(0 /*BluetoothDevice.TRANSPORT_AUTO*/)
1093                 .setIncreaseIntentFilterPriority(true)
1094                 .setEvaluatePerformance(true)
1095                 .setKeepSameAccountKeyWrite(true)
1096                 .setEnableNamingCharacteristic(true)
1097                 .setEnableFirmwareVersionCharacteristic(true)
1098                 .setIsRetroactivePairing(false)
1099                 .setNumSdpAttemptsAfterBonded(1)
1100                 .setSupportHidDevice(false)
1101                 .setEnablePairingWhileDirectlyConnecting(true)
1102                 .setAcceptConsentForFastPairOne(true)
1103                 .setGattConnectRetryTimeoutMillis(18000)
1104                 .setEnable128BitCustomGattCharacteristicsId(true)
1105                 .setEnableSendExceptionStepToValidator(true)
1106                 .setEnableAdditionalDataTypeWhenActionOverBle(true)
1107                 .setCheckBondStateWhenSkipConnectingProfiles(true)
1108                 .setHandlePasskeyConfirmationByUi(false)
1109                 .setMoreEventLogForQuality(true)
1110                 .setRetryGattConnectionAndSecretHandshake(true)
1111                 .setGattConnectShortTimeoutMs(7000)
1112                 .setGattConnectLongTimeoutMs(15000)
1113                 .setGattConnectShortTimeoutRetryMaxSpentTimeMs(10000)
1114                 .setAddressRotateRetryMaxSpentTimeMs(15000)
1115                 .setPairingRetryDelayMs(100)
1116                 .setSecretHandshakeShortTimeoutMs(3000)
1117                 .setSecretHandshakeLongTimeoutMs(10000)
1118                 .setSecretHandshakeShortTimeoutRetryMaxSpentTimeMs(5000)
1119                 .setSecretHandshakeLongTimeoutRetryMaxSpentTimeMs(7000)
1120                 .setSecretHandshakeRetryAttempts(3)
1121                 .setSecretHandshakeRetryGattConnectionMaxSpentTimeMs(15000)
1122                 .setSignalLostRetryMaxSpentTimeMs(15000)
1123                 .setGattConnectionAndSecretHandshakeNoRetryGattError(ImmutableSet.of(257))
1124                 .setRetrySecretHandshakeTimeout(false)
1125                 .setLogUserManualRetry(true)
1126                 .setPairFailureCounts(0)
1127                 .setEnablePairFlowShowUiWithoutProfileConnection(true)
1128                 .setPairFailureCounts(0)
1129                 .setLogPairWithCachedModelId(true)
1130                 .setDirectConnectProfileIfModelIdInCache(true)
1131                 .setCachedDeviceAddress("")
1132                 .setPossibleCachedDeviceAddress("")
1133                 .setSameModelIdPairedDeviceCount(0)
1134                 .setIsDeviceFinishCheckAddressFromCache(true);
1135     }
1136 
1137     /**
1138      * Preferences builder.
1139      */
1140     public static class Builder {
1141 
1142         private int mGattOperationTimeoutSeconds;
1143         private int mGattConnectionTimeoutSeconds;
1144         private int mBluetoothToggleTimeoutSeconds;
1145         private int mBluetoothToggleSleepSeconds;
1146         private int mClassicDiscoveryTimeoutSeconds;
1147         private int mNumDiscoverAttempts;
1148         private int mDiscoveryRetrySleepSeconds;
1149         private boolean mIgnoreDiscoveryError;
1150         private int mSdpTimeoutSeconds;
1151         private int mNumSdpAttempts;
1152         private int mNumCreateBondAttempts;
1153         private int mNumConnectAttempts;
1154         private int mNumWriteAccountKeyAttempts;
1155         private boolean mToggleBluetoothOnFailure;
1156         private boolean mBluetoothStateUsesPolling;
1157         private int mBluetoothStatePollingMillis;
1158         private int mNumAttempts;
1159         private boolean mEnableBrEdrHandover;
1160         private short mBrHandoverDataCharacteristicId;
1161         private short mBluetoothSigDataCharacteristicId;
1162         private short mFirmwareVersionCharacteristicId;
1163         private short mBrTransportBlockDataDescriptorId;
1164         private boolean mWaitForUuidsAfterBonding;
1165         private boolean mReceiveUuidsAndBondedEventBeforeClose;
1166         private int mRemoveBondTimeoutSeconds;
1167         private int mRemoveBondSleepMillis;
1168         private int mCreateBondTimeoutSeconds;
1169         private int mHidCreateBondTimeoutSeconds;
1170         private int mProxyTimeoutSeconds;
1171         private boolean mRejectPhonebookAccess;
1172         private boolean mRejectMessageAccess;
1173         private boolean mRejectSimAccess;
1174         private int mWriteAccountKeySleepMillis;
1175         private boolean mSkipDisconnectingGattBeforeWritingAccountKey;
1176         private boolean mMoreEventLogForQuality;
1177         private boolean mRetryGattConnectionAndSecretHandshake;
1178         private long mGattConnectShortTimeoutMs;
1179         private long mGattConnectLongTimeoutMs;
1180         private long mGattConnectShortTimeoutRetryMaxSpentTimeMs;
1181         private long mAddressRotateRetryMaxSpentTimeMs;
1182         private long mPairingRetryDelayMs;
1183         private long mSecretHandshakeShortTimeoutMs;
1184         private long mSecretHandshakeLongTimeoutMs;
1185         private long mSecretHandshakeShortTimeoutRetryMaxSpentTimeMs;
1186         private long mSecretHandshakeLongTimeoutRetryMaxSpentTimeMs;
1187         private long mSecretHandshakeRetryAttempts;
1188         private long mSecretHandshakeRetryGattConnectionMaxSpentTimeMs;
1189         private long mSignalLostRetryMaxSpentTimeMs;
1190         private ImmutableSet<Integer> mGattConnectionAndSecretHandshakeNoRetryGattError;
1191         private boolean mRetrySecretHandshakeTimeout;
1192         private boolean mLogUserManualRetry;
1193         private int mPairFailureCounts;
1194         private String mCachedDeviceAddress;
1195         private String mPossibleCachedDeviceAddress;
1196         private int mSameModelIdPairedDeviceCount;
1197         private boolean mIsDeviceFinishCheckAddressFromCache;
1198         private boolean mLogPairWithCachedModelId;
1199         private boolean mDirectConnectProfileIfModelIdInCache;
1200         private boolean mAcceptPasskey;
1201         private byte[] mSupportedProfileUuids;
1202         private boolean mProviderInitiatesBondingIfSupported;
1203         private boolean mAttemptDirectConnectionWhenPreviouslyBonded;
1204         private boolean mAutomaticallyReconnectGattWhenNeeded;
1205         private boolean mSkipConnectingProfiles;
1206         private boolean mIgnoreUuidTimeoutAfterBonded;
1207         private boolean mSpecifyCreateBondTransportType;
1208         private int mCreateBondTransportType;
1209         private boolean mIncreaseIntentFilterPriority;
1210         private boolean mEvaluatePerformance;
1211         private Preferences.ExtraLoggingInformation mExtraLoggingInformation;
1212         private boolean mEnableNamingCharacteristic;
1213         private boolean mEnableFirmwareVersionCharacteristic;
1214         private boolean mKeepSameAccountKeyWrite;
1215         private boolean mIsRetroactivePairing;
1216         private int mNumSdpAttemptsAfterBonded;
1217         private boolean mSupportHidDevice;
1218         private boolean mEnablePairingWhileDirectlyConnecting;
1219         private boolean mAcceptConsentForFastPairOne;
1220         private int mGattConnectRetryTimeoutMillis;
1221         private boolean mEnable128BitCustomGattCharacteristicsId;
1222         private boolean mEnableSendExceptionStepToValidator;
1223         private boolean mEnableAdditionalDataTypeWhenActionOverBle;
1224         private boolean mCheckBondStateWhenSkipConnectingProfiles;
1225         private boolean mHandlePasskeyConfirmationByUi;
1226         private boolean mEnablePairFlowShowUiWithoutProfileConnection;
1227 
Builder()1228         private Builder() {
1229         }
1230 
Builder(Preferences source)1231         private Builder(Preferences source) {
1232             this.mGattOperationTimeoutSeconds = source.getGattOperationTimeoutSeconds();
1233             this.mGattConnectionTimeoutSeconds = source.getGattConnectionTimeoutSeconds();
1234             this.mBluetoothToggleTimeoutSeconds = source.getBluetoothToggleTimeoutSeconds();
1235             this.mBluetoothToggleSleepSeconds = source.getBluetoothToggleSleepSeconds();
1236             this.mClassicDiscoveryTimeoutSeconds = source.getClassicDiscoveryTimeoutSeconds();
1237             this.mNumDiscoverAttempts = source.getNumDiscoverAttempts();
1238             this.mDiscoveryRetrySleepSeconds = source.getDiscoveryRetrySleepSeconds();
1239             this.mIgnoreDiscoveryError = source.getIgnoreDiscoveryError();
1240             this.mSdpTimeoutSeconds = source.getSdpTimeoutSeconds();
1241             this.mNumSdpAttempts = source.getNumSdpAttempts();
1242             this.mNumCreateBondAttempts = source.getNumCreateBondAttempts();
1243             this.mNumConnectAttempts = source.getNumConnectAttempts();
1244             this.mNumWriteAccountKeyAttempts = source.getNumWriteAccountKeyAttempts();
1245             this.mToggleBluetoothOnFailure = source.getToggleBluetoothOnFailure();
1246             this.mBluetoothStateUsesPolling = source.getBluetoothStateUsesPolling();
1247             this.mBluetoothStatePollingMillis = source.getBluetoothStatePollingMillis();
1248             this.mNumAttempts = source.getNumAttempts();
1249             this.mEnableBrEdrHandover = source.getEnableBrEdrHandover();
1250             this.mBrHandoverDataCharacteristicId = source.getBrHandoverDataCharacteristicId();
1251             this.mBluetoothSigDataCharacteristicId = source.getBluetoothSigDataCharacteristicId();
1252             this.mFirmwareVersionCharacteristicId = source.getFirmwareVersionCharacteristicId();
1253             this.mBrTransportBlockDataDescriptorId = source.getBrTransportBlockDataDescriptorId();
1254             this.mWaitForUuidsAfterBonding = source.getWaitForUuidsAfterBonding();
1255             this.mReceiveUuidsAndBondedEventBeforeClose = source
1256                     .getReceiveUuidsAndBondedEventBeforeClose();
1257             this.mRemoveBondTimeoutSeconds = source.getRemoveBondTimeoutSeconds();
1258             this.mRemoveBondSleepMillis = source.getRemoveBondSleepMillis();
1259             this.mCreateBondTimeoutSeconds = source.getCreateBondTimeoutSeconds();
1260             this.mHidCreateBondTimeoutSeconds = source.getHidCreateBondTimeoutSeconds();
1261             this.mProxyTimeoutSeconds = source.getProxyTimeoutSeconds();
1262             this.mRejectPhonebookAccess = source.getRejectPhonebookAccess();
1263             this.mRejectMessageAccess = source.getRejectMessageAccess();
1264             this.mRejectSimAccess = source.getRejectSimAccess();
1265             this.mWriteAccountKeySleepMillis = source.getWriteAccountKeySleepMillis();
1266             this.mSkipDisconnectingGattBeforeWritingAccountKey = source
1267                     .getSkipDisconnectingGattBeforeWritingAccountKey();
1268             this.mMoreEventLogForQuality = source.getMoreEventLogForQuality();
1269             this.mRetryGattConnectionAndSecretHandshake = source
1270                     .getRetryGattConnectionAndSecretHandshake();
1271             this.mGattConnectShortTimeoutMs = source.getGattConnectShortTimeoutMs();
1272             this.mGattConnectLongTimeoutMs = source.getGattConnectLongTimeoutMs();
1273             this.mGattConnectShortTimeoutRetryMaxSpentTimeMs = source
1274                     .getGattConnectShortTimeoutRetryMaxSpentTimeMs();
1275             this.mAddressRotateRetryMaxSpentTimeMs = source.getAddressRotateRetryMaxSpentTimeMs();
1276             this.mPairingRetryDelayMs = source.getPairingRetryDelayMs();
1277             this.mSecretHandshakeShortTimeoutMs = source.getSecretHandshakeShortTimeoutMs();
1278             this.mSecretHandshakeLongTimeoutMs = source.getSecretHandshakeLongTimeoutMs();
1279             this.mSecretHandshakeShortTimeoutRetryMaxSpentTimeMs = source
1280                     .getSecretHandshakeShortTimeoutRetryMaxSpentTimeMs();
1281             this.mSecretHandshakeLongTimeoutRetryMaxSpentTimeMs = source
1282                     .getSecretHandshakeLongTimeoutRetryMaxSpentTimeMs();
1283             this.mSecretHandshakeRetryAttempts = source.getSecretHandshakeRetryAttempts();
1284             this.mSecretHandshakeRetryGattConnectionMaxSpentTimeMs = source
1285                     .getSecretHandshakeRetryGattConnectionMaxSpentTimeMs();
1286             this.mSignalLostRetryMaxSpentTimeMs = source.getSignalLostRetryMaxSpentTimeMs();
1287             this.mGattConnectionAndSecretHandshakeNoRetryGattError = source
1288                     .getGattConnectionAndSecretHandshakeNoRetryGattError();
1289             this.mRetrySecretHandshakeTimeout = source.getRetrySecretHandshakeTimeout();
1290             this.mLogUserManualRetry = source.getLogUserManualRetry();
1291             this.mPairFailureCounts = source.getPairFailureCounts();
1292             this.mCachedDeviceAddress = source.getCachedDeviceAddress();
1293             this.mPossibleCachedDeviceAddress = source.getPossibleCachedDeviceAddress();
1294             this.mSameModelIdPairedDeviceCount = source.getSameModelIdPairedDeviceCount();
1295             this.mIsDeviceFinishCheckAddressFromCache = source
1296                     .getIsDeviceFinishCheckAddressFromCache();
1297             this.mLogPairWithCachedModelId = source.getLogPairWithCachedModelId();
1298             this.mDirectConnectProfileIfModelIdInCache = source
1299                     .getDirectConnectProfileIfModelIdInCache();
1300             this.mAcceptPasskey = source.getAcceptPasskey();
1301             this.mSupportedProfileUuids = source.getSupportedProfileUuids();
1302             this.mProviderInitiatesBondingIfSupported = source
1303                     .getProviderInitiatesBondingIfSupported();
1304             this.mAttemptDirectConnectionWhenPreviouslyBonded = source
1305                     .getAttemptDirectConnectionWhenPreviouslyBonded();
1306             this.mAutomaticallyReconnectGattWhenNeeded = source
1307                     .getAutomaticallyReconnectGattWhenNeeded();
1308             this.mSkipConnectingProfiles = source.getSkipConnectingProfiles();
1309             this.mIgnoreUuidTimeoutAfterBonded = source.getIgnoreUuidTimeoutAfterBonded();
1310             this.mSpecifyCreateBondTransportType = source.getSpecifyCreateBondTransportType();
1311             this.mCreateBondTransportType = source.getCreateBondTransportType();
1312             this.mIncreaseIntentFilterPriority = source.getIncreaseIntentFilterPriority();
1313             this.mEvaluatePerformance = source.getEvaluatePerformance();
1314             this.mExtraLoggingInformation = source.getExtraLoggingInformation();
1315             this.mEnableNamingCharacteristic = source.getEnableNamingCharacteristic();
1316             this.mEnableFirmwareVersionCharacteristic = source
1317                     .getEnableFirmwareVersionCharacteristic();
1318             this.mKeepSameAccountKeyWrite = source.getKeepSameAccountKeyWrite();
1319             this.mIsRetroactivePairing = source.getIsRetroactivePairing();
1320             this.mNumSdpAttemptsAfterBonded = source.getNumSdpAttemptsAfterBonded();
1321             this.mSupportHidDevice = source.getSupportHidDevice();
1322             this.mEnablePairingWhileDirectlyConnecting = source
1323                     .getEnablePairingWhileDirectlyConnecting();
1324             this.mAcceptConsentForFastPairOne = source.getAcceptConsentForFastPairOne();
1325             this.mGattConnectRetryTimeoutMillis = source.getGattConnectRetryTimeoutMillis();
1326             this.mEnable128BitCustomGattCharacteristicsId = source
1327                     .getEnable128BitCustomGattCharacteristicsId();
1328             this.mEnableSendExceptionStepToValidator = source
1329                     .getEnableSendExceptionStepToValidator();
1330             this.mEnableAdditionalDataTypeWhenActionOverBle = source
1331                     .getEnableAdditionalDataTypeWhenActionOverBle();
1332             this.mCheckBondStateWhenSkipConnectingProfiles = source
1333                     .getCheckBondStateWhenSkipConnectingProfiles();
1334             this.mHandlePasskeyConfirmationByUi = source.getHandlePasskeyConfirmationByUi();
1335             this.mEnablePairFlowShowUiWithoutProfileConnection = source
1336                     .getEnablePairFlowShowUiWithoutProfileConnection();
1337         }
1338 
1339         /**
1340          * Set gatt operation timeout.
1341          */
setGattOperationTimeoutSeconds(int value)1342         public Builder setGattOperationTimeoutSeconds(int value) {
1343             this.mGattOperationTimeoutSeconds = value;
1344             return this;
1345         }
1346 
1347         /**
1348          * Set gatt connection timeout.
1349          */
setGattConnectionTimeoutSeconds(int value)1350         public Builder setGattConnectionTimeoutSeconds(int value) {
1351             this.mGattConnectionTimeoutSeconds = value;
1352             return this;
1353         }
1354 
1355         /**
1356          * Set bluetooth toggle timeout.
1357          */
setBluetoothToggleTimeoutSeconds(int value)1358         public Builder setBluetoothToggleTimeoutSeconds(int value) {
1359             this.mBluetoothToggleTimeoutSeconds = value;
1360             return this;
1361         }
1362 
1363         /**
1364          * Set bluetooth toggle sleep time.
1365          */
setBluetoothToggleSleepSeconds(int value)1366         public Builder setBluetoothToggleSleepSeconds(int value) {
1367             this.mBluetoothToggleSleepSeconds = value;
1368             return this;
1369         }
1370 
1371         /**
1372          * Set classic discovery timeout.
1373          */
setClassicDiscoveryTimeoutSeconds(int value)1374         public Builder setClassicDiscoveryTimeoutSeconds(int value) {
1375             this.mClassicDiscoveryTimeoutSeconds = value;
1376             return this;
1377         }
1378 
1379         /**
1380          * Set number of discover attempts allowed.
1381          */
setNumDiscoverAttempts(int value)1382         public Builder setNumDiscoverAttempts(int value) {
1383             this.mNumDiscoverAttempts = value;
1384             return this;
1385         }
1386 
1387         /**
1388          * Set discovery retry sleep time.
1389          */
setDiscoveryRetrySleepSeconds(int value)1390         public Builder setDiscoveryRetrySleepSeconds(int value) {
1391             this.mDiscoveryRetrySleepSeconds = value;
1392             return this;
1393         }
1394 
1395         /**
1396          * Set whether to ignore discovery error.
1397          */
setIgnoreDiscoveryError(boolean value)1398         public Builder setIgnoreDiscoveryError(boolean value) {
1399             this.mIgnoreDiscoveryError = value;
1400             return this;
1401         }
1402 
1403         /**
1404          * Set sdp timeout.
1405          */
setSdpTimeoutSeconds(int value)1406         public Builder setSdpTimeoutSeconds(int value) {
1407             this.mSdpTimeoutSeconds = value;
1408             return this;
1409         }
1410 
1411         /**
1412          * Set number of sdp attempts allowed.
1413          */
setNumSdpAttempts(int value)1414         public Builder setNumSdpAttempts(int value) {
1415             this.mNumSdpAttempts = value;
1416             return this;
1417         }
1418 
1419         /**
1420          * Set number of allowed attempts to create bond.
1421          */
setNumCreateBondAttempts(int value)1422         public Builder setNumCreateBondAttempts(int value) {
1423             this.mNumCreateBondAttempts = value;
1424             return this;
1425         }
1426 
1427         /**
1428          * Set number of connect attempts allowed.
1429          */
setNumConnectAttempts(int value)1430         public Builder setNumConnectAttempts(int value) {
1431             this.mNumConnectAttempts = value;
1432             return this;
1433         }
1434 
1435         /**
1436          * Set number of write account key attempts allowed.
1437          */
setNumWriteAccountKeyAttempts(int value)1438         public Builder setNumWriteAccountKeyAttempts(int value) {
1439             this.mNumWriteAccountKeyAttempts = value;
1440             return this;
1441         }
1442 
1443         /**
1444          * Set whether to retry by bluetooth toggle on failure.
1445          */
setToggleBluetoothOnFailure(boolean value)1446         public Builder setToggleBluetoothOnFailure(boolean value) {
1447             this.mToggleBluetoothOnFailure = value;
1448             return this;
1449         }
1450 
1451         /**
1452          * Set whether to use polling to set bluetooth status.
1453          */
setBluetoothStateUsesPolling(boolean value)1454         public Builder setBluetoothStateUsesPolling(boolean value) {
1455             this.mBluetoothStateUsesPolling = value;
1456             return this;
1457         }
1458 
1459         /**
1460          * Set Bluetooth state polling timeout.
1461          */
setBluetoothStatePollingMillis(int value)1462         public Builder setBluetoothStatePollingMillis(int value) {
1463             this.mBluetoothStatePollingMillis = value;
1464             return this;
1465         }
1466 
1467         /**
1468          * Set number of attempts.
1469          */
setNumAttempts(int value)1470         public Builder setNumAttempts(int value) {
1471             this.mNumAttempts = value;
1472             return this;
1473         }
1474 
1475         /**
1476          * Set whether to enable BrEdr handover.
1477          */
setEnableBrEdrHandover(boolean value)1478         public Builder setEnableBrEdrHandover(boolean value) {
1479             this.mEnableBrEdrHandover = value;
1480             return this;
1481         }
1482 
1483         /**
1484          * Set Br handover data characteristic Id.
1485          */
setBrHandoverDataCharacteristicId(short value)1486         public Builder setBrHandoverDataCharacteristicId(short value) {
1487             this.mBrHandoverDataCharacteristicId = value;
1488             return this;
1489         }
1490 
1491         /**
1492          * Set Bluetooth Sig data characteristic Id.
1493          */
setBluetoothSigDataCharacteristicId(short value)1494         public Builder setBluetoothSigDataCharacteristicId(short value) {
1495             this.mBluetoothSigDataCharacteristicId = value;
1496             return this;
1497         }
1498 
1499         /**
1500          * Set Firmware version characteristic id.
1501          */
setFirmwareVersionCharacteristicId(short value)1502         public Builder setFirmwareVersionCharacteristicId(short value) {
1503             this.mFirmwareVersionCharacteristicId = value;
1504             return this;
1505         }
1506 
1507         /**
1508          * Set Br transport block data descriptor id.
1509          */
setBrTransportBlockDataDescriptorId(short value)1510         public Builder setBrTransportBlockDataDescriptorId(short value) {
1511             this.mBrTransportBlockDataDescriptorId = value;
1512             return this;
1513         }
1514 
1515         /**
1516          * Set whether to wait for Uuids after bonding.
1517          */
setWaitForUuidsAfterBonding(boolean value)1518         public Builder setWaitForUuidsAfterBonding(boolean value) {
1519             this.mWaitForUuidsAfterBonding = value;
1520             return this;
1521         }
1522 
1523         /**
1524          * Set whether to receive Uuids and bonded event before close.
1525          */
setReceiveUuidsAndBondedEventBeforeClose(boolean value)1526         public Builder setReceiveUuidsAndBondedEventBeforeClose(boolean value) {
1527             this.mReceiveUuidsAndBondedEventBeforeClose = value;
1528             return this;
1529         }
1530 
1531         /**
1532          * Set remove bond timeout.
1533          */
setRemoveBondTimeoutSeconds(int value)1534         public Builder setRemoveBondTimeoutSeconds(int value) {
1535             this.mRemoveBondTimeoutSeconds = value;
1536             return this;
1537         }
1538 
1539         /**
1540          * Set remove bound sleep time.
1541          */
setRemoveBondSleepMillis(int value)1542         public Builder setRemoveBondSleepMillis(int value) {
1543             this.mRemoveBondSleepMillis = value;
1544             return this;
1545         }
1546 
1547         /**
1548          * Set create bond timeout.
1549          */
setCreateBondTimeoutSeconds(int value)1550         public Builder setCreateBondTimeoutSeconds(int value) {
1551             this.mCreateBondTimeoutSeconds = value;
1552             return this;
1553         }
1554 
1555         /**
1556          * Set Hid create bond timeout.
1557          */
setHidCreateBondTimeoutSeconds(int value)1558         public Builder setHidCreateBondTimeoutSeconds(int value) {
1559             this.mHidCreateBondTimeoutSeconds = value;
1560             return this;
1561         }
1562 
1563         /**
1564          * Set proxy timeout.
1565          */
setProxyTimeoutSeconds(int value)1566         public Builder setProxyTimeoutSeconds(int value) {
1567             this.mProxyTimeoutSeconds = value;
1568             return this;
1569         }
1570 
1571         /**
1572          * Set whether to reject phone book access.
1573          */
setRejectPhonebookAccess(boolean value)1574         public Builder setRejectPhonebookAccess(boolean value) {
1575             this.mRejectPhonebookAccess = value;
1576             return this;
1577         }
1578 
1579         /**
1580          * Set whether to reject message access.
1581          */
setRejectMessageAccess(boolean value)1582         public Builder setRejectMessageAccess(boolean value) {
1583             this.mRejectMessageAccess = value;
1584             return this;
1585         }
1586 
1587         /**
1588          * Set whether to reject slim access.
1589          */
setRejectSimAccess(boolean value)1590         public Builder setRejectSimAccess(boolean value) {
1591             this.mRejectSimAccess = value;
1592             return this;
1593         }
1594 
1595         /**
1596          * Set whether to accept passkey.
1597          */
setAcceptPasskey(boolean value)1598         public Builder setAcceptPasskey(boolean value) {
1599             this.mAcceptPasskey = value;
1600             return this;
1601         }
1602 
1603         /**
1604          * Set supported profile Uuids.
1605          */
setSupportedProfileUuids(byte[] value)1606         public Builder setSupportedProfileUuids(byte[] value) {
1607             this.mSupportedProfileUuids = value;
1608             return this;
1609         }
1610 
1611         /**
1612          * Set whether to collect more event log for quality.
1613          */
setMoreEventLogForQuality(boolean value)1614         public Builder setMoreEventLogForQuality(boolean value) {
1615             this.mMoreEventLogForQuality = value;
1616             return this;
1617         }
1618 
1619         /**
1620          * Set supported profile Uuids.
1621          */
setSupportedProfileUuids(short... uuids)1622         public Builder setSupportedProfileUuids(short... uuids) {
1623             return setSupportedProfileUuids(Bytes.toBytes(ByteOrder.BIG_ENDIAN, uuids));
1624         }
1625 
1626         /**
1627          * Set write account key sleep time.
1628          */
setWriteAccountKeySleepMillis(int value)1629         public Builder setWriteAccountKeySleepMillis(int value) {
1630             this.mWriteAccountKeySleepMillis = value;
1631             return this;
1632         }
1633 
1634         /**
1635          * Set whether to do provider initialized bonding if supported.
1636          */
setProviderInitiatesBondingIfSupported(boolean value)1637         public Builder setProviderInitiatesBondingIfSupported(boolean value) {
1638             this.mProviderInitiatesBondingIfSupported = value;
1639             return this;
1640         }
1641 
1642         /**
1643          * Set whether to try direct connection when the device is previously bonded.
1644          */
setAttemptDirectConnectionWhenPreviouslyBonded(boolean value)1645         public Builder setAttemptDirectConnectionWhenPreviouslyBonded(boolean value) {
1646             this.mAttemptDirectConnectionWhenPreviouslyBonded = value;
1647             return this;
1648         }
1649 
1650         /**
1651          * Set whether to automatically reconnect gatt when needed.
1652          */
setAutomaticallyReconnectGattWhenNeeded(boolean value)1653         public Builder setAutomaticallyReconnectGattWhenNeeded(boolean value) {
1654             this.mAutomaticallyReconnectGattWhenNeeded = value;
1655             return this;
1656         }
1657 
1658         /**
1659          * Set whether to skip disconnecting gatt before writing account key.
1660          */
setSkipDisconnectingGattBeforeWritingAccountKey(boolean value)1661         public Builder setSkipDisconnectingGattBeforeWritingAccountKey(boolean value) {
1662             this.mSkipDisconnectingGattBeforeWritingAccountKey = value;
1663             return this;
1664         }
1665 
1666         /**
1667          * Set whether to skip connecting profiles.
1668          */
setSkipConnectingProfiles(boolean value)1669         public Builder setSkipConnectingProfiles(boolean value) {
1670             this.mSkipConnectingProfiles = value;
1671             return this;
1672         }
1673 
1674         /**
1675          * Set whether to ignore Uuid timeout after bonded.
1676          */
setIgnoreUuidTimeoutAfterBonded(boolean value)1677         public Builder setIgnoreUuidTimeoutAfterBonded(boolean value) {
1678             this.mIgnoreUuidTimeoutAfterBonded = value;
1679             return this;
1680         }
1681 
1682         /**
1683          * Set whether to include transport type in create bound request.
1684          */
setSpecifyCreateBondTransportType(boolean value)1685         public Builder setSpecifyCreateBondTransportType(boolean value) {
1686             this.mSpecifyCreateBondTransportType = value;
1687             return this;
1688         }
1689 
1690         /**
1691          * Set transport type used in create bond request.
1692          */
setCreateBondTransportType(int value)1693         public Builder setCreateBondTransportType(int value) {
1694             this.mCreateBondTransportType = value;
1695             return this;
1696         }
1697 
1698         /**
1699          * Set whether to increase intent filter priority.
1700          */
setIncreaseIntentFilterPriority(boolean value)1701         public Builder setIncreaseIntentFilterPriority(boolean value) {
1702             this.mIncreaseIntentFilterPriority = value;
1703             return this;
1704         }
1705 
1706         /**
1707          * Set whether to evaluate performance.
1708          */
setEvaluatePerformance(boolean value)1709         public Builder setEvaluatePerformance(boolean value) {
1710             this.mEvaluatePerformance = value;
1711             return this;
1712         }
1713 
1714         /**
1715          * Set extra logging info.
1716          */
setExtraLoggingInformation(ExtraLoggingInformation value)1717         public Builder setExtraLoggingInformation(ExtraLoggingInformation value) {
1718             this.mExtraLoggingInformation = value;
1719             return this;
1720         }
1721 
1722         /**
1723          * Set whether to enable naming characteristic.
1724          */
setEnableNamingCharacteristic(boolean value)1725         public Builder setEnableNamingCharacteristic(boolean value) {
1726             this.mEnableNamingCharacteristic = value;
1727             return this;
1728         }
1729 
1730         /**
1731          * Set whether to keep writing the account key to the provider, that has already paired with
1732          * the account.
1733          */
setKeepSameAccountKeyWrite(boolean value)1734         public Builder setKeepSameAccountKeyWrite(boolean value) {
1735             this.mKeepSameAccountKeyWrite = value;
1736             return this;
1737         }
1738 
1739         /**
1740          * Set whether to enable firmware version characteristic.
1741          */
setEnableFirmwareVersionCharacteristic(boolean value)1742         public Builder setEnableFirmwareVersionCharacteristic(boolean value) {
1743             this.mEnableFirmwareVersionCharacteristic = value;
1744             return this;
1745         }
1746 
1747         /**
1748          * Set whether it is retroactive pairing.
1749          */
setIsRetroactivePairing(boolean value)1750         public Builder setIsRetroactivePairing(boolean value) {
1751             this.mIsRetroactivePairing = value;
1752             return this;
1753         }
1754 
1755         /**
1756          * Set number of allowed sdp attempts after bonded.
1757          */
setNumSdpAttemptsAfterBonded(int value)1758         public Builder setNumSdpAttemptsAfterBonded(int value) {
1759             this.mNumSdpAttemptsAfterBonded = value;
1760             return this;
1761         }
1762 
1763         /**
1764          * Set whether to support Hid device.
1765          */
setSupportHidDevice(boolean value)1766         public Builder setSupportHidDevice(boolean value) {
1767             this.mSupportHidDevice = value;
1768             return this;
1769         }
1770 
1771         /**
1772          * Set wehther to enable the pairing behavior to handle the state transition from
1773          * BOND_BONDED to BOND_BONDING when directly connecting profiles.
1774          */
setEnablePairingWhileDirectlyConnecting(boolean value)1775         public Builder setEnablePairingWhileDirectlyConnecting(boolean value) {
1776             this.mEnablePairingWhileDirectlyConnecting = value;
1777             return this;
1778         }
1779 
1780         /**
1781          * Set whether to accept consent for fast pair one.
1782          */
setAcceptConsentForFastPairOne(boolean value)1783         public Builder setAcceptConsentForFastPairOne(boolean value) {
1784             this.mAcceptConsentForFastPairOne = value;
1785             return this;
1786         }
1787 
1788         /**
1789          * Set Gatt connect retry timeout.
1790          */
setGattConnectRetryTimeoutMillis(int value)1791         public Builder setGattConnectRetryTimeoutMillis(int value) {
1792             this.mGattConnectRetryTimeoutMillis = value;
1793             return this;
1794         }
1795 
1796         /**
1797          * Set whether to enable 128 bit custom gatt characteristic Id.
1798          */
setEnable128BitCustomGattCharacteristicsId(boolean value)1799         public Builder setEnable128BitCustomGattCharacteristicsId(boolean value) {
1800             this.mEnable128BitCustomGattCharacteristicsId = value;
1801             return this;
1802         }
1803 
1804         /**
1805          * Set whether to send exception step to validator.
1806          */
setEnableSendExceptionStepToValidator(boolean value)1807         public Builder setEnableSendExceptionStepToValidator(boolean value) {
1808             this.mEnableSendExceptionStepToValidator = value;
1809             return this;
1810         }
1811 
1812         /**
1813          * Set wehther to add the additional data type in the handshake when action over BLE.
1814          */
setEnableAdditionalDataTypeWhenActionOverBle(boolean value)1815         public Builder setEnableAdditionalDataTypeWhenActionOverBle(boolean value) {
1816             this.mEnableAdditionalDataTypeWhenActionOverBle = value;
1817             return this;
1818         }
1819 
1820         /**
1821          * Set whether to check bond state when skip connecting profiles.
1822          */
setCheckBondStateWhenSkipConnectingProfiles(boolean value)1823         public Builder setCheckBondStateWhenSkipConnectingProfiles(boolean value) {
1824             this.mCheckBondStateWhenSkipConnectingProfiles = value;
1825             return this;
1826         }
1827 
1828         /**
1829          * Set whether to handle passkey confirmation by UI.
1830          */
setHandlePasskeyConfirmationByUi(boolean value)1831         public Builder setHandlePasskeyConfirmationByUi(boolean value) {
1832             this.mHandlePasskeyConfirmationByUi = value;
1833             return this;
1834         }
1835 
1836         /**
1837          * Set wehther to retry gatt connection and secret handshake.
1838          */
setRetryGattConnectionAndSecretHandshake(boolean value)1839         public Builder setRetryGattConnectionAndSecretHandshake(boolean value) {
1840             this.mRetryGattConnectionAndSecretHandshake = value;
1841             return this;
1842         }
1843 
1844         /**
1845          * Set gatt connect short timeout.
1846          */
setGattConnectShortTimeoutMs(long value)1847         public Builder setGattConnectShortTimeoutMs(long value) {
1848             this.mGattConnectShortTimeoutMs = value;
1849             return this;
1850         }
1851 
1852         /**
1853          * Set gatt connect long timeout.
1854          */
setGattConnectLongTimeoutMs(long value)1855         public Builder setGattConnectLongTimeoutMs(long value) {
1856             this.mGattConnectLongTimeoutMs = value;
1857             return this;
1858         }
1859 
1860         /**
1861          * Set gatt connection short timoutout, including retry.
1862          */
setGattConnectShortTimeoutRetryMaxSpentTimeMs(long value)1863         public Builder setGattConnectShortTimeoutRetryMaxSpentTimeMs(long value) {
1864             this.mGattConnectShortTimeoutRetryMaxSpentTimeMs = value;
1865             return this;
1866         }
1867 
1868         /**
1869          * Set address rotate timeout, including retry.
1870          */
setAddressRotateRetryMaxSpentTimeMs(long value)1871         public Builder setAddressRotateRetryMaxSpentTimeMs(long value) {
1872             this.mAddressRotateRetryMaxSpentTimeMs = value;
1873             return this;
1874         }
1875 
1876         /**
1877          * Set pairing retry delay time.
1878          */
setPairingRetryDelayMs(long value)1879         public Builder setPairingRetryDelayMs(long value) {
1880             this.mPairingRetryDelayMs = value;
1881             return this;
1882         }
1883 
1884         /**
1885          * Set secret handshake short timeout.
1886          */
setSecretHandshakeShortTimeoutMs(long value)1887         public Builder setSecretHandshakeShortTimeoutMs(long value) {
1888             this.mSecretHandshakeShortTimeoutMs = value;
1889             return this;
1890         }
1891 
1892         /**
1893          * Set secret handshake long timeout.
1894          */
setSecretHandshakeLongTimeoutMs(long value)1895         public Builder setSecretHandshakeLongTimeoutMs(long value) {
1896             this.mSecretHandshakeLongTimeoutMs = value;
1897             return this;
1898         }
1899 
1900         /**
1901          * Set secret handshake short timeout retry max spent time.
1902          */
setSecretHandshakeShortTimeoutRetryMaxSpentTimeMs(long value)1903         public Builder setSecretHandshakeShortTimeoutRetryMaxSpentTimeMs(long value) {
1904             this.mSecretHandshakeShortTimeoutRetryMaxSpentTimeMs = value;
1905             return this;
1906         }
1907 
1908         /**
1909          * Set secret handshake long timeout retry max spent time.
1910          */
setSecretHandshakeLongTimeoutRetryMaxSpentTimeMs(long value)1911         public Builder setSecretHandshakeLongTimeoutRetryMaxSpentTimeMs(long value) {
1912             this.mSecretHandshakeLongTimeoutRetryMaxSpentTimeMs = value;
1913             return this;
1914         }
1915 
1916         /**
1917          * Set secret handshake retry attempts allowed.
1918          */
setSecretHandshakeRetryAttempts(long value)1919         public Builder setSecretHandshakeRetryAttempts(long value) {
1920             this.mSecretHandshakeRetryAttempts = value;
1921             return this;
1922         }
1923 
1924         /**
1925          * Set secret handshake retry gatt connection max spent time.
1926          */
setSecretHandshakeRetryGattConnectionMaxSpentTimeMs(long value)1927         public Builder setSecretHandshakeRetryGattConnectionMaxSpentTimeMs(long value) {
1928             this.mSecretHandshakeRetryGattConnectionMaxSpentTimeMs = value;
1929             return this;
1930         }
1931 
1932         /**
1933          * Set signal loss retry max spent time.
1934          */
setSignalLostRetryMaxSpentTimeMs(long value)1935         public Builder setSignalLostRetryMaxSpentTimeMs(long value) {
1936             this.mSignalLostRetryMaxSpentTimeMs = value;
1937             return this;
1938         }
1939 
1940         /**
1941          * Set gatt connection and secret handshake no retry gatt error.
1942          */
setGattConnectionAndSecretHandshakeNoRetryGattError( ImmutableSet<Integer> value)1943         public Builder setGattConnectionAndSecretHandshakeNoRetryGattError(
1944                 ImmutableSet<Integer> value) {
1945             this.mGattConnectionAndSecretHandshakeNoRetryGattError = value;
1946             return this;
1947         }
1948 
1949         /**
1950          * Set retry secret handshake timeout.
1951          */
setRetrySecretHandshakeTimeout(boolean value)1952         public Builder setRetrySecretHandshakeTimeout(boolean value) {
1953             this.mRetrySecretHandshakeTimeout = value;
1954             return this;
1955         }
1956 
1957         /**
1958          * Set whether to log user manual retry.
1959          */
setLogUserManualRetry(boolean value)1960         public Builder setLogUserManualRetry(boolean value) {
1961             this.mLogUserManualRetry = value;
1962             return this;
1963         }
1964 
1965         /**
1966          * Set pair falure counts.
1967          */
setPairFailureCounts(int counts)1968         public Builder setPairFailureCounts(int counts) {
1969             this.mPairFailureCounts = counts;
1970             return this;
1971         }
1972 
1973         /**
1974          * Set whether to use pair flow to show ui when pairing is finished without connecting
1975          * profile..
1976          */
setEnablePairFlowShowUiWithoutProfileConnection(boolean value)1977         public Builder setEnablePairFlowShowUiWithoutProfileConnection(boolean value) {
1978             this.mEnablePairFlowShowUiWithoutProfileConnection = value;
1979             return this;
1980         }
1981 
1982         /**
1983          * Set whether to log pairing with cached module Id.
1984          */
setLogPairWithCachedModelId(boolean value)1985         public Builder setLogPairWithCachedModelId(boolean value) {
1986             this.mLogPairWithCachedModelId = value;
1987             return this;
1988         }
1989 
1990         /**
1991          * Set possible cached device address.
1992          */
setPossibleCachedDeviceAddress(String value)1993         public Builder setPossibleCachedDeviceAddress(String value) {
1994             this.mPossibleCachedDeviceAddress = value;
1995             return this;
1996         }
1997 
1998         /**
1999          * Set paired device count from the same module Id.
2000          */
setSameModelIdPairedDeviceCount(int value)2001         public Builder setSameModelIdPairedDeviceCount(int value) {
2002             this.mSameModelIdPairedDeviceCount = value;
2003             return this;
2004         }
2005 
2006         /**
2007          * Set whether the bonded device address is from cache.
2008          */
setIsDeviceFinishCheckAddressFromCache(boolean value)2009         public Builder setIsDeviceFinishCheckAddressFromCache(boolean value) {
2010             this.mIsDeviceFinishCheckAddressFromCache = value;
2011             return this;
2012         }
2013 
2014         /**
2015          * Set whether to directly connect profile if modelId is in cache.
2016          */
setDirectConnectProfileIfModelIdInCache(boolean value)2017         public Builder setDirectConnectProfileIfModelIdInCache(boolean value) {
2018             this.mDirectConnectProfileIfModelIdInCache = value;
2019             return this;
2020         }
2021 
2022         /**
2023          * Set cached device address.
2024          */
setCachedDeviceAddress(String value)2025         public Builder setCachedDeviceAddress(String value) {
2026             this.mCachedDeviceAddress = value;
2027             return this;
2028         }
2029 
2030         /**
2031          * Builds a Preferences instance.
2032          */
build()2033         public Preferences build() {
2034             return new Preferences(
2035                     this.mGattOperationTimeoutSeconds,
2036                     this.mGattConnectionTimeoutSeconds,
2037                     this.mBluetoothToggleTimeoutSeconds,
2038                     this.mBluetoothToggleSleepSeconds,
2039                     this.mClassicDiscoveryTimeoutSeconds,
2040                     this.mNumDiscoverAttempts,
2041                     this.mDiscoveryRetrySleepSeconds,
2042                     this.mIgnoreDiscoveryError,
2043                     this.mSdpTimeoutSeconds,
2044                     this.mNumSdpAttempts,
2045                     this.mNumCreateBondAttempts,
2046                     this.mNumConnectAttempts,
2047                     this.mNumWriteAccountKeyAttempts,
2048                     this.mToggleBluetoothOnFailure,
2049                     this.mBluetoothStateUsesPolling,
2050                     this.mBluetoothStatePollingMillis,
2051                     this.mNumAttempts,
2052                     this.mEnableBrEdrHandover,
2053                     this.mBrHandoverDataCharacteristicId,
2054                     this.mBluetoothSigDataCharacteristicId,
2055                     this.mFirmwareVersionCharacteristicId,
2056                     this.mBrTransportBlockDataDescriptorId,
2057                     this.mWaitForUuidsAfterBonding,
2058                     this.mReceiveUuidsAndBondedEventBeforeClose,
2059                     this.mRemoveBondTimeoutSeconds,
2060                     this.mRemoveBondSleepMillis,
2061                     this.mCreateBondTimeoutSeconds,
2062                     this.mHidCreateBondTimeoutSeconds,
2063                     this.mProxyTimeoutSeconds,
2064                     this.mRejectPhonebookAccess,
2065                     this.mRejectMessageAccess,
2066                     this.mRejectSimAccess,
2067                     this.mWriteAccountKeySleepMillis,
2068                     this.mSkipDisconnectingGattBeforeWritingAccountKey,
2069                     this.mMoreEventLogForQuality,
2070                     this.mRetryGattConnectionAndSecretHandshake,
2071                     this.mGattConnectShortTimeoutMs,
2072                     this.mGattConnectLongTimeoutMs,
2073                     this.mGattConnectShortTimeoutRetryMaxSpentTimeMs,
2074                     this.mAddressRotateRetryMaxSpentTimeMs,
2075                     this.mPairingRetryDelayMs,
2076                     this.mSecretHandshakeShortTimeoutMs,
2077                     this.mSecretHandshakeLongTimeoutMs,
2078                     this.mSecretHandshakeShortTimeoutRetryMaxSpentTimeMs,
2079                     this.mSecretHandshakeLongTimeoutRetryMaxSpentTimeMs,
2080                     this.mSecretHandshakeRetryAttempts,
2081                     this.mSecretHandshakeRetryGattConnectionMaxSpentTimeMs,
2082                     this.mSignalLostRetryMaxSpentTimeMs,
2083                     this.mGattConnectionAndSecretHandshakeNoRetryGattError,
2084                     this.mRetrySecretHandshakeTimeout,
2085                     this.mLogUserManualRetry,
2086                     this.mPairFailureCounts,
2087                     this.mCachedDeviceAddress,
2088                     this.mPossibleCachedDeviceAddress,
2089                     this.mSameModelIdPairedDeviceCount,
2090                     this.mIsDeviceFinishCheckAddressFromCache,
2091                     this.mLogPairWithCachedModelId,
2092                     this.mDirectConnectProfileIfModelIdInCache,
2093                     this.mAcceptPasskey,
2094                     this.mSupportedProfileUuids,
2095                     this.mProviderInitiatesBondingIfSupported,
2096                     this.mAttemptDirectConnectionWhenPreviouslyBonded,
2097                     this.mAutomaticallyReconnectGattWhenNeeded,
2098                     this.mSkipConnectingProfiles,
2099                     this.mIgnoreUuidTimeoutAfterBonded,
2100                     this.mSpecifyCreateBondTransportType,
2101                     this.mCreateBondTransportType,
2102                     this.mIncreaseIntentFilterPriority,
2103                     this.mEvaluatePerformance,
2104                     this.mExtraLoggingInformation,
2105                     this.mEnableNamingCharacteristic,
2106                     this.mEnableFirmwareVersionCharacteristic,
2107                     this.mKeepSameAccountKeyWrite,
2108                     this.mIsRetroactivePairing,
2109                     this.mNumSdpAttemptsAfterBonded,
2110                     this.mSupportHidDevice,
2111                     this.mEnablePairingWhileDirectlyConnecting,
2112                     this.mAcceptConsentForFastPairOne,
2113                     this.mGattConnectRetryTimeoutMillis,
2114                     this.mEnable128BitCustomGattCharacteristicsId,
2115                     this.mEnableSendExceptionStepToValidator,
2116                     this.mEnableAdditionalDataTypeWhenActionOverBle,
2117                     this.mCheckBondStateWhenSkipConnectingProfiles,
2118                     this.mHandlePasskeyConfirmationByUi,
2119                     this.mEnablePairFlowShowUiWithoutProfileConnection);
2120         }
2121     }
2122 
2123     /**
2124      * Whether a given Uuid is supported.
2125      */
isSupportedProfile(short profileUuid)2126     public boolean isSupportedProfile(short profileUuid) {
2127         return Constants.PROFILES.containsKey(profileUuid)
2128                 && Shorts.contains(
2129                 Bytes.toShorts(ByteOrder.BIG_ENDIAN, getSupportedProfileUuids()), profileUuid);
2130     }
2131 
2132     /**
2133      * Information that will be used for logging.
2134      */
2135     public static class ExtraLoggingInformation {
2136 
2137         private final String mModelId;
2138 
ExtraLoggingInformation(String modelId)2139         private ExtraLoggingInformation(String modelId) {
2140             this.mModelId = modelId;
2141         }
2142 
2143         /**
2144          * Returns model Id.
2145          */
getModelId()2146         public String getModelId() {
2147             return mModelId;
2148         }
2149 
2150         /**
2151          * Converts an instance to a builder.
2152          */
toBuilder()2153         public Builder toBuilder() {
2154             return new Builder(this);
2155         }
2156 
2157         /**
2158          * Creates a builder for ExtraLoggingInformation.
2159          */
builder()2160         public static Builder builder() {
2161             return new ExtraLoggingInformation.Builder();
2162         }
2163 
2164         @Override
toString()2165         public String toString() {
2166             return "ExtraLoggingInformation{" + "modelId=" + mModelId + "}";
2167         }
2168 
2169         @Override
equals(@ullable Object o)2170         public boolean equals(@Nullable Object o) {
2171             if (o == this) {
2172                 return true;
2173             }
2174             if (o instanceof ExtraLoggingInformation) {
2175                 Preferences.ExtraLoggingInformation that = (Preferences.ExtraLoggingInformation) o;
2176                 return this.mModelId.equals(that.getModelId());
2177             }
2178             return false;
2179         }
2180 
2181         @Override
hashCode()2182         public int hashCode() {
2183             return Objects.hash(mModelId);
2184         }
2185 
2186         /**
2187          * Extra logging information builder.
2188          */
2189         public static class Builder {
2190 
2191             private String mModelId;
2192 
Builder()2193             private Builder() {
2194             }
2195 
Builder(ExtraLoggingInformation source)2196             private Builder(ExtraLoggingInformation source) {
2197                 this.mModelId = source.getModelId();
2198             }
2199 
2200             /**
2201              * Set model ID.
2202              */
setModelId(String modelId)2203             public Builder setModelId(String modelId) {
2204                 this.mModelId = modelId;
2205                 return this;
2206             }
2207 
2208             /**
2209              * Builds extra logging information.
2210              */
build()2211             public ExtraLoggingInformation build() {
2212                 return new ExtraLoggingInformation(mModelId);
2213             }
2214         }
2215     }
2216 }
2217