• 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(3)
1046                 .setGattConnectionTimeoutSeconds(15)
1047                 .setBluetoothToggleTimeoutSeconds(10)
1048                 .setBluetoothToggleSleepSeconds(2)
1049                 .setClassicDiscoveryTimeoutSeconds(10)
1050                 .setNumDiscoverAttempts(3)
1051                 .setDiscoveryRetrySleepSeconds(1)
1052                 .setIgnoreDiscoveryError(false)
1053                 .setSdpTimeoutSeconds(10)
1054                 .setNumSdpAttempts(3)
1055                 .setNumCreateBondAttempts(3)
1056                 .setNumConnectAttempts(1)
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(false)
1087                 .setAutomaticallyReconnectGattWhenNeeded(false)
1088                 .setSkipDisconnectingGattBeforeWritingAccountKey(false)
1089                 .setSkipConnectingProfiles(false)
1090                 .setIgnoreUuidTimeoutAfterBonded(false)
1091                 .setSpecifyCreateBondTransportType(false)
1092                 .setCreateBondTransportType(0 /*BluetoothDevice.TRANSPORT_AUTO*/)
1093                 .setIncreaseIntentFilterPriority(true)
1094                 .setEvaluatePerformance(false)
1095                 .setKeepSameAccountKeyWrite(true)
1096                 .setEnableNamingCharacteristic(false)
1097                 .setEnableFirmwareVersionCharacteristic(false)
1098                 .setIsRetroactivePairing(false)
1099                 .setNumSdpAttemptsAfterBonded(1)
1100                 .setSupportHidDevice(false)
1101                 .setEnablePairingWhileDirectlyConnecting(true)
1102                 .setAcceptConsentForFastPairOne(true)
1103                 .setGattConnectRetryTimeoutMillis(0)
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())
1124                 .setRetrySecretHandshakeTimeout(false)
1125                 .setLogUserManualRetry(true)
1126                 .setPairFailureCounts(0)
1127                 .setEnablePairFlowShowUiWithoutProfileConnection(true)
1128                 .setPairFailureCounts(0)
1129                 .setLogPairWithCachedModelId(true)
1130                 .setDirectConnectProfileIfModelIdInCache(false)
1131                 .setCachedDeviceAddress("")
1132                 .setPossibleCachedDeviceAddress("")
1133                 .setSameModelIdPairedDeviceCount(0)
1134                 .setIsDeviceFinishCheckAddressFromCache(true);
1135     }
1136 
1137     /**
1138      * Constructs a builder from GmsLog.
1139      */
1140     // TODO(b/206668142): remove this builder once api is ready.
builderFromGmsLog()1141     public static Builder builderFromGmsLog() {
1142         return new Preferences.Builder()
1143                 .setGattOperationTimeoutSeconds(10)
1144                 .setGattConnectionTimeoutSeconds(15)
1145                 .setBluetoothToggleTimeoutSeconds(10)
1146                 .setBluetoothToggleSleepSeconds(2)
1147                 .setClassicDiscoveryTimeoutSeconds(13)
1148                 .setNumDiscoverAttempts(3)
1149                 .setDiscoveryRetrySleepSeconds(1)
1150                 .setIgnoreDiscoveryError(true)
1151                 .setSdpTimeoutSeconds(10)
1152                 .setNumSdpAttempts(0)
1153                 .setNumCreateBondAttempts(3)
1154                 .setNumConnectAttempts(2)
1155                 .setNumWriteAccountKeyAttempts(3)
1156                 .setToggleBluetoothOnFailure(false)
1157                 .setBluetoothStateUsesPolling(true)
1158                 .setBluetoothStatePollingMillis(1000)
1159                 .setNumAttempts(2)
1160                 .setEnableBrEdrHandover(false)
1161                 .setBrHandoverDataCharacteristicId((short) 11265)
1162                 .setBluetoothSigDataCharacteristicId((short) 11266)
1163                 .setFirmwareVersionCharacteristicId((short) 10790)
1164                 .setBrTransportBlockDataDescriptorId((short) 11267)
1165                 .setWaitForUuidsAfterBonding(true)
1166                 .setReceiveUuidsAndBondedEventBeforeClose(true)
1167                 .setRemoveBondTimeoutSeconds(5)
1168                 .setRemoveBondSleepMillis(1000)
1169                 .setCreateBondTimeoutSeconds(15)
1170                 .setHidCreateBondTimeoutSeconds(40)
1171                 .setProxyTimeoutSeconds(2)
1172                 .setRejectPhonebookAccess(false)
1173                 .setRejectMessageAccess(false)
1174                 .setRejectSimAccess(false)
1175                 .setAcceptPasskey(true)
1176                 .setSupportedProfileUuids(Constants.getSupportedProfiles())
1177                 .setWriteAccountKeySleepMillis(2000)
1178                 .setProviderInitiatesBondingIfSupported(false)
1179                 .setAttemptDirectConnectionWhenPreviouslyBonded(true)
1180                 .setAutomaticallyReconnectGattWhenNeeded(true)
1181                 .setSkipDisconnectingGattBeforeWritingAccountKey(true)
1182                 .setSkipConnectingProfiles(false)
1183                 .setIgnoreUuidTimeoutAfterBonded(true)
1184                 .setSpecifyCreateBondTransportType(false)
1185                 .setCreateBondTransportType(0 /*BluetoothDevice.TRANSPORT_AUTO*/)
1186                 .setIncreaseIntentFilterPriority(true)
1187                 .setEvaluatePerformance(true)
1188                 .setKeepSameAccountKeyWrite(true)
1189                 .setEnableNamingCharacteristic(true)
1190                 .setEnableFirmwareVersionCharacteristic(true)
1191                 .setIsRetroactivePairing(false)
1192                 .setNumSdpAttemptsAfterBonded(1)
1193                 .setSupportHidDevice(false)
1194                 .setEnablePairingWhileDirectlyConnecting(true)
1195                 .setAcceptConsentForFastPairOne(true)
1196                 .setGattConnectRetryTimeoutMillis(18000)
1197                 .setEnable128BitCustomGattCharacteristicsId(true)
1198                 .setEnableSendExceptionStepToValidator(true)
1199                 .setEnableAdditionalDataTypeWhenActionOverBle(true)
1200                 .setCheckBondStateWhenSkipConnectingProfiles(true)
1201                 .setHandlePasskeyConfirmationByUi(false)
1202                 .setMoreEventLogForQuality(true)
1203                 .setRetryGattConnectionAndSecretHandshake(true)
1204                 .setGattConnectShortTimeoutMs(7000)
1205                 .setGattConnectLongTimeoutMs(15000)
1206                 .setGattConnectShortTimeoutRetryMaxSpentTimeMs(10000)
1207                 .setAddressRotateRetryMaxSpentTimeMs(15000)
1208                 .setPairingRetryDelayMs(100)
1209                 .setSecretHandshakeShortTimeoutMs(3000)
1210                 .setSecretHandshakeLongTimeoutMs(10000)
1211                 .setSecretHandshakeShortTimeoutRetryMaxSpentTimeMs(5000)
1212                 .setSecretHandshakeLongTimeoutRetryMaxSpentTimeMs(7000)
1213                 .setSecretHandshakeRetryAttempts(3)
1214                 .setSecretHandshakeRetryGattConnectionMaxSpentTimeMs(15000)
1215                 .setSignalLostRetryMaxSpentTimeMs(15000)
1216                 .setGattConnectionAndSecretHandshakeNoRetryGattError(ImmutableSet.of(257))
1217                 .setRetrySecretHandshakeTimeout(false)
1218                 .setLogUserManualRetry(true)
1219                 .setPairFailureCounts(0)
1220                 .setEnablePairFlowShowUiWithoutProfileConnection(true)
1221                 .setPairFailureCounts(0)
1222                 .setLogPairWithCachedModelId(true)
1223                 .setDirectConnectProfileIfModelIdInCache(true)
1224                 .setCachedDeviceAddress("")
1225                 .setPossibleCachedDeviceAddress("")
1226                 .setSameModelIdPairedDeviceCount(0)
1227                 .setIsDeviceFinishCheckAddressFromCache(true);
1228     }
1229 
1230     /**
1231      * Preferences builder.
1232      */
1233     public static class Builder {
1234 
1235         private int mGattOperationTimeoutSeconds;
1236         private int mGattConnectionTimeoutSeconds;
1237         private int mBluetoothToggleTimeoutSeconds;
1238         private int mBluetoothToggleSleepSeconds;
1239         private int mClassicDiscoveryTimeoutSeconds;
1240         private int mNumDiscoverAttempts;
1241         private int mDiscoveryRetrySleepSeconds;
1242         private boolean mIgnoreDiscoveryError;
1243         private int mSdpTimeoutSeconds;
1244         private int mNumSdpAttempts;
1245         private int mNumCreateBondAttempts;
1246         private int mNumConnectAttempts;
1247         private int mNumWriteAccountKeyAttempts;
1248         private boolean mToggleBluetoothOnFailure;
1249         private boolean mBluetoothStateUsesPolling;
1250         private int mBluetoothStatePollingMillis;
1251         private int mNumAttempts;
1252         private boolean mEnableBrEdrHandover;
1253         private short mBrHandoverDataCharacteristicId;
1254         private short mBluetoothSigDataCharacteristicId;
1255         private short mFirmwareVersionCharacteristicId;
1256         private short mBrTransportBlockDataDescriptorId;
1257         private boolean mWaitForUuidsAfterBonding;
1258         private boolean mReceiveUuidsAndBondedEventBeforeClose;
1259         private int mRemoveBondTimeoutSeconds;
1260         private int mRemoveBondSleepMillis;
1261         private int mCreateBondTimeoutSeconds;
1262         private int mHidCreateBondTimeoutSeconds;
1263         private int mProxyTimeoutSeconds;
1264         private boolean mRejectPhonebookAccess;
1265         private boolean mRejectMessageAccess;
1266         private boolean mRejectSimAccess;
1267         private int mWriteAccountKeySleepMillis;
1268         private boolean mSkipDisconnectingGattBeforeWritingAccountKey;
1269         private boolean mMoreEventLogForQuality;
1270         private boolean mRetryGattConnectionAndSecretHandshake;
1271         private long mGattConnectShortTimeoutMs;
1272         private long mGattConnectLongTimeoutMs;
1273         private long mGattConnectShortTimeoutRetryMaxSpentTimeMs;
1274         private long mAddressRotateRetryMaxSpentTimeMs;
1275         private long mPairingRetryDelayMs;
1276         private long mSecretHandshakeShortTimeoutMs;
1277         private long mSecretHandshakeLongTimeoutMs;
1278         private long mSecretHandshakeShortTimeoutRetryMaxSpentTimeMs;
1279         private long mSecretHandshakeLongTimeoutRetryMaxSpentTimeMs;
1280         private long mSecretHandshakeRetryAttempts;
1281         private long mSecretHandshakeRetryGattConnectionMaxSpentTimeMs;
1282         private long mSignalLostRetryMaxSpentTimeMs;
1283         private ImmutableSet<Integer> mGattConnectionAndSecretHandshakeNoRetryGattError;
1284         private boolean mRetrySecretHandshakeTimeout;
1285         private boolean mLogUserManualRetry;
1286         private int mPairFailureCounts;
1287         private String mCachedDeviceAddress;
1288         private String mPossibleCachedDeviceAddress;
1289         private int mSameModelIdPairedDeviceCount;
1290         private boolean mIsDeviceFinishCheckAddressFromCache;
1291         private boolean mLogPairWithCachedModelId;
1292         private boolean mDirectConnectProfileIfModelIdInCache;
1293         private boolean mAcceptPasskey;
1294         private byte[] mSupportedProfileUuids;
1295         private boolean mProviderInitiatesBondingIfSupported;
1296         private boolean mAttemptDirectConnectionWhenPreviouslyBonded;
1297         private boolean mAutomaticallyReconnectGattWhenNeeded;
1298         private boolean mSkipConnectingProfiles;
1299         private boolean mIgnoreUuidTimeoutAfterBonded;
1300         private boolean mSpecifyCreateBondTransportType;
1301         private int mCreateBondTransportType;
1302         private boolean mIncreaseIntentFilterPriority;
1303         private boolean mEvaluatePerformance;
1304         private Preferences.ExtraLoggingInformation mExtraLoggingInformation;
1305         private boolean mEnableNamingCharacteristic;
1306         private boolean mEnableFirmwareVersionCharacteristic;
1307         private boolean mKeepSameAccountKeyWrite;
1308         private boolean mIsRetroactivePairing;
1309         private int mNumSdpAttemptsAfterBonded;
1310         private boolean mSupportHidDevice;
1311         private boolean mEnablePairingWhileDirectlyConnecting;
1312         private boolean mAcceptConsentForFastPairOne;
1313         private int mGattConnectRetryTimeoutMillis;
1314         private boolean mEnable128BitCustomGattCharacteristicsId;
1315         private boolean mEnableSendExceptionStepToValidator;
1316         private boolean mEnableAdditionalDataTypeWhenActionOverBle;
1317         private boolean mCheckBondStateWhenSkipConnectingProfiles;
1318         private boolean mHandlePasskeyConfirmationByUi;
1319         private boolean mEnablePairFlowShowUiWithoutProfileConnection;
1320 
Builder()1321         private Builder() {
1322         }
1323 
Builder(Preferences source)1324         private Builder(Preferences source) {
1325             this.mGattOperationTimeoutSeconds = source.getGattOperationTimeoutSeconds();
1326             this.mGattConnectionTimeoutSeconds = source.getGattConnectionTimeoutSeconds();
1327             this.mBluetoothToggleTimeoutSeconds = source.getBluetoothToggleTimeoutSeconds();
1328             this.mBluetoothToggleSleepSeconds = source.getBluetoothToggleSleepSeconds();
1329             this.mClassicDiscoveryTimeoutSeconds = source.getClassicDiscoveryTimeoutSeconds();
1330             this.mNumDiscoverAttempts = source.getNumDiscoverAttempts();
1331             this.mDiscoveryRetrySleepSeconds = source.getDiscoveryRetrySleepSeconds();
1332             this.mIgnoreDiscoveryError = source.getIgnoreDiscoveryError();
1333             this.mSdpTimeoutSeconds = source.getSdpTimeoutSeconds();
1334             this.mNumSdpAttempts = source.getNumSdpAttempts();
1335             this.mNumCreateBondAttempts = source.getNumCreateBondAttempts();
1336             this.mNumConnectAttempts = source.getNumConnectAttempts();
1337             this.mNumWriteAccountKeyAttempts = source.getNumWriteAccountKeyAttempts();
1338             this.mToggleBluetoothOnFailure = source.getToggleBluetoothOnFailure();
1339             this.mBluetoothStateUsesPolling = source.getBluetoothStateUsesPolling();
1340             this.mBluetoothStatePollingMillis = source.getBluetoothStatePollingMillis();
1341             this.mNumAttempts = source.getNumAttempts();
1342             this.mEnableBrEdrHandover = source.getEnableBrEdrHandover();
1343             this.mBrHandoverDataCharacteristicId = source.getBrHandoverDataCharacteristicId();
1344             this.mBluetoothSigDataCharacteristicId = source.getBluetoothSigDataCharacteristicId();
1345             this.mFirmwareVersionCharacteristicId = source.getFirmwareVersionCharacteristicId();
1346             this.mBrTransportBlockDataDescriptorId = source.getBrTransportBlockDataDescriptorId();
1347             this.mWaitForUuidsAfterBonding = source.getWaitForUuidsAfterBonding();
1348             this.mReceiveUuidsAndBondedEventBeforeClose = source
1349                     .getReceiveUuidsAndBondedEventBeforeClose();
1350             this.mRemoveBondTimeoutSeconds = source.getRemoveBondTimeoutSeconds();
1351             this.mRemoveBondSleepMillis = source.getRemoveBondSleepMillis();
1352             this.mCreateBondTimeoutSeconds = source.getCreateBondTimeoutSeconds();
1353             this.mHidCreateBondTimeoutSeconds = source.getHidCreateBondTimeoutSeconds();
1354             this.mProxyTimeoutSeconds = source.getProxyTimeoutSeconds();
1355             this.mRejectPhonebookAccess = source.getRejectPhonebookAccess();
1356             this.mRejectMessageAccess = source.getRejectMessageAccess();
1357             this.mRejectSimAccess = source.getRejectSimAccess();
1358             this.mWriteAccountKeySleepMillis = source.getWriteAccountKeySleepMillis();
1359             this.mSkipDisconnectingGattBeforeWritingAccountKey = source
1360                     .getSkipDisconnectingGattBeforeWritingAccountKey();
1361             this.mMoreEventLogForQuality = source.getMoreEventLogForQuality();
1362             this.mRetryGattConnectionAndSecretHandshake = source
1363                     .getRetryGattConnectionAndSecretHandshake();
1364             this.mGattConnectShortTimeoutMs = source.getGattConnectShortTimeoutMs();
1365             this.mGattConnectLongTimeoutMs = source.getGattConnectLongTimeoutMs();
1366             this.mGattConnectShortTimeoutRetryMaxSpentTimeMs = source
1367                     .getGattConnectShortTimeoutRetryMaxSpentTimeMs();
1368             this.mAddressRotateRetryMaxSpentTimeMs = source.getAddressRotateRetryMaxSpentTimeMs();
1369             this.mPairingRetryDelayMs = source.getPairingRetryDelayMs();
1370             this.mSecretHandshakeShortTimeoutMs = source.getSecretHandshakeShortTimeoutMs();
1371             this.mSecretHandshakeLongTimeoutMs = source.getSecretHandshakeLongTimeoutMs();
1372             this.mSecretHandshakeShortTimeoutRetryMaxSpentTimeMs = source
1373                     .getSecretHandshakeShortTimeoutRetryMaxSpentTimeMs();
1374             this.mSecretHandshakeLongTimeoutRetryMaxSpentTimeMs = source
1375                     .getSecretHandshakeLongTimeoutRetryMaxSpentTimeMs();
1376             this.mSecretHandshakeRetryAttempts = source.getSecretHandshakeRetryAttempts();
1377             this.mSecretHandshakeRetryGattConnectionMaxSpentTimeMs = source
1378                     .getSecretHandshakeRetryGattConnectionMaxSpentTimeMs();
1379             this.mSignalLostRetryMaxSpentTimeMs = source.getSignalLostRetryMaxSpentTimeMs();
1380             this.mGattConnectionAndSecretHandshakeNoRetryGattError = source
1381                     .getGattConnectionAndSecretHandshakeNoRetryGattError();
1382             this.mRetrySecretHandshakeTimeout = source.getRetrySecretHandshakeTimeout();
1383             this.mLogUserManualRetry = source.getLogUserManualRetry();
1384             this.mPairFailureCounts = source.getPairFailureCounts();
1385             this.mCachedDeviceAddress = source.getCachedDeviceAddress();
1386             this.mPossibleCachedDeviceAddress = source.getPossibleCachedDeviceAddress();
1387             this.mSameModelIdPairedDeviceCount = source.getSameModelIdPairedDeviceCount();
1388             this.mIsDeviceFinishCheckAddressFromCache = source
1389                     .getIsDeviceFinishCheckAddressFromCache();
1390             this.mLogPairWithCachedModelId = source.getLogPairWithCachedModelId();
1391             this.mDirectConnectProfileIfModelIdInCache = source
1392                     .getDirectConnectProfileIfModelIdInCache();
1393             this.mAcceptPasskey = source.getAcceptPasskey();
1394             this.mSupportedProfileUuids = source.getSupportedProfileUuids();
1395             this.mProviderInitiatesBondingIfSupported = source
1396                     .getProviderInitiatesBondingIfSupported();
1397             this.mAttemptDirectConnectionWhenPreviouslyBonded = source
1398                     .getAttemptDirectConnectionWhenPreviouslyBonded();
1399             this.mAutomaticallyReconnectGattWhenNeeded = source
1400                     .getAutomaticallyReconnectGattWhenNeeded();
1401             this.mSkipConnectingProfiles = source.getSkipConnectingProfiles();
1402             this.mIgnoreUuidTimeoutAfterBonded = source.getIgnoreUuidTimeoutAfterBonded();
1403             this.mSpecifyCreateBondTransportType = source.getSpecifyCreateBondTransportType();
1404             this.mCreateBondTransportType = source.getCreateBondTransportType();
1405             this.mIncreaseIntentFilterPriority = source.getIncreaseIntentFilterPriority();
1406             this.mEvaluatePerformance = source.getEvaluatePerformance();
1407             this.mExtraLoggingInformation = source.getExtraLoggingInformation();
1408             this.mEnableNamingCharacteristic = source.getEnableNamingCharacteristic();
1409             this.mEnableFirmwareVersionCharacteristic = source
1410                     .getEnableFirmwareVersionCharacteristic();
1411             this.mKeepSameAccountKeyWrite = source.getKeepSameAccountKeyWrite();
1412             this.mIsRetroactivePairing = source.getIsRetroactivePairing();
1413             this.mNumSdpAttemptsAfterBonded = source.getNumSdpAttemptsAfterBonded();
1414             this.mSupportHidDevice = source.getSupportHidDevice();
1415             this.mEnablePairingWhileDirectlyConnecting = source
1416                     .getEnablePairingWhileDirectlyConnecting();
1417             this.mAcceptConsentForFastPairOne = source.getAcceptConsentForFastPairOne();
1418             this.mGattConnectRetryTimeoutMillis = source.getGattConnectRetryTimeoutMillis();
1419             this.mEnable128BitCustomGattCharacteristicsId = source
1420                     .getEnable128BitCustomGattCharacteristicsId();
1421             this.mEnableSendExceptionStepToValidator = source
1422                     .getEnableSendExceptionStepToValidator();
1423             this.mEnableAdditionalDataTypeWhenActionOverBle = source
1424                     .getEnableAdditionalDataTypeWhenActionOverBle();
1425             this.mCheckBondStateWhenSkipConnectingProfiles = source
1426                     .getCheckBondStateWhenSkipConnectingProfiles();
1427             this.mHandlePasskeyConfirmationByUi = source.getHandlePasskeyConfirmationByUi();
1428             this.mEnablePairFlowShowUiWithoutProfileConnection = source
1429                     .getEnablePairFlowShowUiWithoutProfileConnection();
1430         }
1431 
1432         /**
1433          * Set gatt operation timeout.
1434          */
setGattOperationTimeoutSeconds(int value)1435         public Builder setGattOperationTimeoutSeconds(int value) {
1436             this.mGattOperationTimeoutSeconds = value;
1437             return this;
1438         }
1439 
1440         /**
1441          * Set gatt connection timeout.
1442          */
setGattConnectionTimeoutSeconds(int value)1443         public Builder setGattConnectionTimeoutSeconds(int value) {
1444             this.mGattConnectionTimeoutSeconds = value;
1445             return this;
1446         }
1447 
1448         /**
1449          * Set bluetooth toggle timeout.
1450          */
setBluetoothToggleTimeoutSeconds(int value)1451         public Builder setBluetoothToggleTimeoutSeconds(int value) {
1452             this.mBluetoothToggleTimeoutSeconds = value;
1453             return this;
1454         }
1455 
1456         /**
1457          * Set bluetooth toggle sleep time.
1458          */
setBluetoothToggleSleepSeconds(int value)1459         public Builder setBluetoothToggleSleepSeconds(int value) {
1460             this.mBluetoothToggleSleepSeconds = value;
1461             return this;
1462         }
1463 
1464         /**
1465          * Set classic discovery timeout.
1466          */
setClassicDiscoveryTimeoutSeconds(int value)1467         public Builder setClassicDiscoveryTimeoutSeconds(int value) {
1468             this.mClassicDiscoveryTimeoutSeconds = value;
1469             return this;
1470         }
1471 
1472         /**
1473          * Set number of discover attempts allowed.
1474          */
setNumDiscoverAttempts(int value)1475         public Builder setNumDiscoverAttempts(int value) {
1476             this.mNumDiscoverAttempts = value;
1477             return this;
1478         }
1479 
1480         /**
1481          * Set discovery retry sleep time.
1482          */
setDiscoveryRetrySleepSeconds(int value)1483         public Builder setDiscoveryRetrySleepSeconds(int value) {
1484             this.mDiscoveryRetrySleepSeconds = value;
1485             return this;
1486         }
1487 
1488         /**
1489          * Set whether to ignore discovery error.
1490          */
setIgnoreDiscoveryError(boolean value)1491         public Builder setIgnoreDiscoveryError(boolean value) {
1492             this.mIgnoreDiscoveryError = value;
1493             return this;
1494         }
1495 
1496         /**
1497          * Set sdp timeout.
1498          */
setSdpTimeoutSeconds(int value)1499         public Builder setSdpTimeoutSeconds(int value) {
1500             this.mSdpTimeoutSeconds = value;
1501             return this;
1502         }
1503 
1504         /**
1505          * Set number of sdp attempts allowed.
1506          */
setNumSdpAttempts(int value)1507         public Builder setNumSdpAttempts(int value) {
1508             this.mNumSdpAttempts = value;
1509             return this;
1510         }
1511 
1512         /**
1513          * Set number of allowed attempts to create bond.
1514          */
setNumCreateBondAttempts(int value)1515         public Builder setNumCreateBondAttempts(int value) {
1516             this.mNumCreateBondAttempts = value;
1517             return this;
1518         }
1519 
1520         /**
1521          * Set number of connect attempts allowed.
1522          */
setNumConnectAttempts(int value)1523         public Builder setNumConnectAttempts(int value) {
1524             this.mNumConnectAttempts = value;
1525             return this;
1526         }
1527 
1528         /**
1529          * Set number of write account key attempts allowed.
1530          */
setNumWriteAccountKeyAttempts(int value)1531         public Builder setNumWriteAccountKeyAttempts(int value) {
1532             this.mNumWriteAccountKeyAttempts = value;
1533             return this;
1534         }
1535 
1536         /**
1537          * Set whether to retry by bluetooth toggle on failure.
1538          */
setToggleBluetoothOnFailure(boolean value)1539         public Builder setToggleBluetoothOnFailure(boolean value) {
1540             this.mToggleBluetoothOnFailure = value;
1541             return this;
1542         }
1543 
1544         /**
1545          * Set whether to use polling to set bluetooth status.
1546          */
setBluetoothStateUsesPolling(boolean value)1547         public Builder setBluetoothStateUsesPolling(boolean value) {
1548             this.mBluetoothStateUsesPolling = value;
1549             return this;
1550         }
1551 
1552         /**
1553          * Set Bluetooth state polling timeout.
1554          */
setBluetoothStatePollingMillis(int value)1555         public Builder setBluetoothStatePollingMillis(int value) {
1556             this.mBluetoothStatePollingMillis = value;
1557             return this;
1558         }
1559 
1560         /**
1561          * Set number of attempts.
1562          */
setNumAttempts(int value)1563         public Builder setNumAttempts(int value) {
1564             this.mNumAttempts = value;
1565             return this;
1566         }
1567 
1568         /**
1569          * Set whether to enable BrEdr handover.
1570          */
setEnableBrEdrHandover(boolean value)1571         public Builder setEnableBrEdrHandover(boolean value) {
1572             this.mEnableBrEdrHandover = value;
1573             return this;
1574         }
1575 
1576         /**
1577          * Set Br handover data characteristic Id.
1578          */
setBrHandoverDataCharacteristicId(short value)1579         public Builder setBrHandoverDataCharacteristicId(short value) {
1580             this.mBrHandoverDataCharacteristicId = value;
1581             return this;
1582         }
1583 
1584         /**
1585          * Set Bluetooth Sig data characteristic Id.
1586          */
setBluetoothSigDataCharacteristicId(short value)1587         public Builder setBluetoothSigDataCharacteristicId(short value) {
1588             this.mBluetoothSigDataCharacteristicId = value;
1589             return this;
1590         }
1591 
1592         /**
1593          * Set Firmware version characteristic id.
1594          */
setFirmwareVersionCharacteristicId(short value)1595         public Builder setFirmwareVersionCharacteristicId(short value) {
1596             this.mFirmwareVersionCharacteristicId = value;
1597             return this;
1598         }
1599 
1600         /**
1601          * Set Br transport block data descriptor id.
1602          */
setBrTransportBlockDataDescriptorId(short value)1603         public Builder setBrTransportBlockDataDescriptorId(short value) {
1604             this.mBrTransportBlockDataDescriptorId = value;
1605             return this;
1606         }
1607 
1608         /**
1609          * Set whether to wait for Uuids after bonding.
1610          */
setWaitForUuidsAfterBonding(boolean value)1611         public Builder setWaitForUuidsAfterBonding(boolean value) {
1612             this.mWaitForUuidsAfterBonding = value;
1613             return this;
1614         }
1615 
1616         /**
1617          * Set whether to receive Uuids and bonded event before close.
1618          */
setReceiveUuidsAndBondedEventBeforeClose(boolean value)1619         public Builder setReceiveUuidsAndBondedEventBeforeClose(boolean value) {
1620             this.mReceiveUuidsAndBondedEventBeforeClose = value;
1621             return this;
1622         }
1623 
1624         /**
1625          * Set remove bond timeout.
1626          */
setRemoveBondTimeoutSeconds(int value)1627         public Builder setRemoveBondTimeoutSeconds(int value) {
1628             this.mRemoveBondTimeoutSeconds = value;
1629             return this;
1630         }
1631 
1632         /**
1633          * Set remove bound sleep time.
1634          */
setRemoveBondSleepMillis(int value)1635         public Builder setRemoveBondSleepMillis(int value) {
1636             this.mRemoveBondSleepMillis = value;
1637             return this;
1638         }
1639 
1640         /**
1641          * Set create bond timeout.
1642          */
setCreateBondTimeoutSeconds(int value)1643         public Builder setCreateBondTimeoutSeconds(int value) {
1644             this.mCreateBondTimeoutSeconds = value;
1645             return this;
1646         }
1647 
1648         /**
1649          * Set Hid create bond timeout.
1650          */
setHidCreateBondTimeoutSeconds(int value)1651         public Builder setHidCreateBondTimeoutSeconds(int value) {
1652             this.mHidCreateBondTimeoutSeconds = value;
1653             return this;
1654         }
1655 
1656         /**
1657          * Set proxy timeout.
1658          */
setProxyTimeoutSeconds(int value)1659         public Builder setProxyTimeoutSeconds(int value) {
1660             this.mProxyTimeoutSeconds = value;
1661             return this;
1662         }
1663 
1664         /**
1665          * Set whether to reject phone book access.
1666          */
setRejectPhonebookAccess(boolean value)1667         public Builder setRejectPhonebookAccess(boolean value) {
1668             this.mRejectPhonebookAccess = value;
1669             return this;
1670         }
1671 
1672         /**
1673          * Set whether to reject message access.
1674          */
setRejectMessageAccess(boolean value)1675         public Builder setRejectMessageAccess(boolean value) {
1676             this.mRejectMessageAccess = value;
1677             return this;
1678         }
1679 
1680         /**
1681          * Set whether to reject slim access.
1682          */
setRejectSimAccess(boolean value)1683         public Builder setRejectSimAccess(boolean value) {
1684             this.mRejectSimAccess = value;
1685             return this;
1686         }
1687 
1688         /**
1689          * Set whether to accept passkey.
1690          */
setAcceptPasskey(boolean value)1691         public Builder setAcceptPasskey(boolean value) {
1692             this.mAcceptPasskey = value;
1693             return this;
1694         }
1695 
1696         /**
1697          * Set supported profile Uuids.
1698          */
setSupportedProfileUuids(byte[] value)1699         public Builder setSupportedProfileUuids(byte[] value) {
1700             this.mSupportedProfileUuids = value;
1701             return this;
1702         }
1703 
1704         /**
1705          * Set whether to collect more event log for quality.
1706          */
setMoreEventLogForQuality(boolean value)1707         public Builder setMoreEventLogForQuality(boolean value) {
1708             this.mMoreEventLogForQuality = value;
1709             return this;
1710         }
1711 
1712         /**
1713          * Set supported profile Uuids.
1714          */
setSupportedProfileUuids(short... uuids)1715         public Builder setSupportedProfileUuids(short... uuids) {
1716             return setSupportedProfileUuids(Bytes.toBytes(ByteOrder.BIG_ENDIAN, uuids));
1717         }
1718 
1719         /**
1720          * Set write account key sleep time.
1721          */
setWriteAccountKeySleepMillis(int value)1722         public Builder setWriteAccountKeySleepMillis(int value) {
1723             this.mWriteAccountKeySleepMillis = value;
1724             return this;
1725         }
1726 
1727         /**
1728          * Set whether to do provider initialized bonding if supported.
1729          */
setProviderInitiatesBondingIfSupported(boolean value)1730         public Builder setProviderInitiatesBondingIfSupported(boolean value) {
1731             this.mProviderInitiatesBondingIfSupported = value;
1732             return this;
1733         }
1734 
1735         /**
1736          * Set whether to try direct connection when the device is previously bonded.
1737          */
setAttemptDirectConnectionWhenPreviouslyBonded(boolean value)1738         public Builder setAttemptDirectConnectionWhenPreviouslyBonded(boolean value) {
1739             this.mAttemptDirectConnectionWhenPreviouslyBonded = value;
1740             return this;
1741         }
1742 
1743         /**
1744          * Set whether to automatically reconnect gatt when needed.
1745          */
setAutomaticallyReconnectGattWhenNeeded(boolean value)1746         public Builder setAutomaticallyReconnectGattWhenNeeded(boolean value) {
1747             this.mAutomaticallyReconnectGattWhenNeeded = value;
1748             return this;
1749         }
1750 
1751         /**
1752          * Set whether to skip disconnecting gatt before writing account key.
1753          */
setSkipDisconnectingGattBeforeWritingAccountKey(boolean value)1754         public Builder setSkipDisconnectingGattBeforeWritingAccountKey(boolean value) {
1755             this.mSkipDisconnectingGattBeforeWritingAccountKey = value;
1756             return this;
1757         }
1758 
1759         /**
1760          * Set whether to skip connecting profiles.
1761          */
setSkipConnectingProfiles(boolean value)1762         public Builder setSkipConnectingProfiles(boolean value) {
1763             this.mSkipConnectingProfiles = value;
1764             return this;
1765         }
1766 
1767         /**
1768          * Set whether to ignore Uuid timeout after bonded.
1769          */
setIgnoreUuidTimeoutAfterBonded(boolean value)1770         public Builder setIgnoreUuidTimeoutAfterBonded(boolean value) {
1771             this.mIgnoreUuidTimeoutAfterBonded = value;
1772             return this;
1773         }
1774 
1775         /**
1776          * Set whether to include transport type in create bound request.
1777          */
setSpecifyCreateBondTransportType(boolean value)1778         public Builder setSpecifyCreateBondTransportType(boolean value) {
1779             this.mSpecifyCreateBondTransportType = value;
1780             return this;
1781         }
1782 
1783         /**
1784          * Set transport type used in create bond request.
1785          */
setCreateBondTransportType(int value)1786         public Builder setCreateBondTransportType(int value) {
1787             this.mCreateBondTransportType = value;
1788             return this;
1789         }
1790 
1791         /**
1792          * Set whether to increase intent filter priority.
1793          */
setIncreaseIntentFilterPriority(boolean value)1794         public Builder setIncreaseIntentFilterPriority(boolean value) {
1795             this.mIncreaseIntentFilterPriority = value;
1796             return this;
1797         }
1798 
1799         /**
1800          * Set whether to evaluate performance.
1801          */
setEvaluatePerformance(boolean value)1802         public Builder setEvaluatePerformance(boolean value) {
1803             this.mEvaluatePerformance = value;
1804             return this;
1805         }
1806 
1807         /**
1808          * Set extra logging info.
1809          */
setExtraLoggingInformation(ExtraLoggingInformation value)1810         public Builder setExtraLoggingInformation(ExtraLoggingInformation value) {
1811             this.mExtraLoggingInformation = value;
1812             return this;
1813         }
1814 
1815         /**
1816          * Set whether to enable naming characteristic.
1817          */
setEnableNamingCharacteristic(boolean value)1818         public Builder setEnableNamingCharacteristic(boolean value) {
1819             this.mEnableNamingCharacteristic = value;
1820             return this;
1821         }
1822 
1823         /**
1824          * Set whether to keep writing the account key to the provider, that has already paired with
1825          * the account.
1826          */
setKeepSameAccountKeyWrite(boolean value)1827         public Builder setKeepSameAccountKeyWrite(boolean value) {
1828             this.mKeepSameAccountKeyWrite = value;
1829             return this;
1830         }
1831 
1832         /**
1833          * Set whether to enable firmware version characteristic.
1834          */
setEnableFirmwareVersionCharacteristic(boolean value)1835         public Builder setEnableFirmwareVersionCharacteristic(boolean value) {
1836             this.mEnableFirmwareVersionCharacteristic = value;
1837             return this;
1838         }
1839 
1840         /**
1841          * Set whether it is retroactive pairing.
1842          */
setIsRetroactivePairing(boolean value)1843         public Builder setIsRetroactivePairing(boolean value) {
1844             this.mIsRetroactivePairing = value;
1845             return this;
1846         }
1847 
1848         /**
1849          * Set number of allowed sdp attempts after bonded.
1850          */
setNumSdpAttemptsAfterBonded(int value)1851         public Builder setNumSdpAttemptsAfterBonded(int value) {
1852             this.mNumSdpAttemptsAfterBonded = value;
1853             return this;
1854         }
1855 
1856         /**
1857          * Set whether to support Hid device.
1858          */
setSupportHidDevice(boolean value)1859         public Builder setSupportHidDevice(boolean value) {
1860             this.mSupportHidDevice = value;
1861             return this;
1862         }
1863 
1864         /**
1865          * Set wehther to enable the pairing behavior to handle the state transition from
1866          * BOND_BONDED to BOND_BONDING when directly connecting profiles.
1867          */
setEnablePairingWhileDirectlyConnecting(boolean value)1868         public Builder setEnablePairingWhileDirectlyConnecting(boolean value) {
1869             this.mEnablePairingWhileDirectlyConnecting = value;
1870             return this;
1871         }
1872 
1873         /**
1874          * Set whether to accept consent for fast pair one.
1875          */
setAcceptConsentForFastPairOne(boolean value)1876         public Builder setAcceptConsentForFastPairOne(boolean value) {
1877             this.mAcceptConsentForFastPairOne = value;
1878             return this;
1879         }
1880 
1881         /**
1882          * Set Gatt connect retry timeout.
1883          */
setGattConnectRetryTimeoutMillis(int value)1884         public Builder setGattConnectRetryTimeoutMillis(int value) {
1885             this.mGattConnectRetryTimeoutMillis = value;
1886             return this;
1887         }
1888 
1889         /**
1890          * Set whether to enable 128 bit custom gatt characteristic Id.
1891          */
setEnable128BitCustomGattCharacteristicsId(boolean value)1892         public Builder setEnable128BitCustomGattCharacteristicsId(boolean value) {
1893             this.mEnable128BitCustomGattCharacteristicsId = value;
1894             return this;
1895         }
1896 
1897         /**
1898          * Set whether to send exception step to validator.
1899          */
setEnableSendExceptionStepToValidator(boolean value)1900         public Builder setEnableSendExceptionStepToValidator(boolean value) {
1901             this.mEnableSendExceptionStepToValidator = value;
1902             return this;
1903         }
1904 
1905         /**
1906          * Set wehther to add the additional data type in the handshake when action over BLE.
1907          */
setEnableAdditionalDataTypeWhenActionOverBle(boolean value)1908         public Builder setEnableAdditionalDataTypeWhenActionOverBle(boolean value) {
1909             this.mEnableAdditionalDataTypeWhenActionOverBle = value;
1910             return this;
1911         }
1912 
1913         /**
1914          * Set whether to check bond state when skip connecting profiles.
1915          */
setCheckBondStateWhenSkipConnectingProfiles(boolean value)1916         public Builder setCheckBondStateWhenSkipConnectingProfiles(boolean value) {
1917             this.mCheckBondStateWhenSkipConnectingProfiles = value;
1918             return this;
1919         }
1920 
1921         /**
1922          * Set whether to handle passkey confirmation by UI.
1923          */
setHandlePasskeyConfirmationByUi(boolean value)1924         public Builder setHandlePasskeyConfirmationByUi(boolean value) {
1925             this.mHandlePasskeyConfirmationByUi = value;
1926             return this;
1927         }
1928 
1929         /**
1930          * Set wehther to retry gatt connection and secret handshake.
1931          */
setRetryGattConnectionAndSecretHandshake(boolean value)1932         public Builder setRetryGattConnectionAndSecretHandshake(boolean value) {
1933             this.mRetryGattConnectionAndSecretHandshake = value;
1934             return this;
1935         }
1936 
1937         /**
1938          * Set gatt connect short timeout.
1939          */
setGattConnectShortTimeoutMs(long value)1940         public Builder setGattConnectShortTimeoutMs(long value) {
1941             this.mGattConnectShortTimeoutMs = value;
1942             return this;
1943         }
1944 
1945         /**
1946          * Set gatt connect long timeout.
1947          */
setGattConnectLongTimeoutMs(long value)1948         public Builder setGattConnectLongTimeoutMs(long value) {
1949             this.mGattConnectLongTimeoutMs = value;
1950             return this;
1951         }
1952 
1953         /**
1954          * Set gatt connection short timoutout, including retry.
1955          */
setGattConnectShortTimeoutRetryMaxSpentTimeMs(long value)1956         public Builder setGattConnectShortTimeoutRetryMaxSpentTimeMs(long value) {
1957             this.mGattConnectShortTimeoutRetryMaxSpentTimeMs = value;
1958             return this;
1959         }
1960 
1961         /**
1962          * Set address rotate timeout, including retry.
1963          */
setAddressRotateRetryMaxSpentTimeMs(long value)1964         public Builder setAddressRotateRetryMaxSpentTimeMs(long value) {
1965             this.mAddressRotateRetryMaxSpentTimeMs = value;
1966             return this;
1967         }
1968 
1969         /**
1970          * Set pairing retry delay time.
1971          */
setPairingRetryDelayMs(long value)1972         public Builder setPairingRetryDelayMs(long value) {
1973             this.mPairingRetryDelayMs = value;
1974             return this;
1975         }
1976 
1977         /**
1978          * Set secret handshake short timeout.
1979          */
setSecretHandshakeShortTimeoutMs(long value)1980         public Builder setSecretHandshakeShortTimeoutMs(long value) {
1981             this.mSecretHandshakeShortTimeoutMs = value;
1982             return this;
1983         }
1984 
1985         /**
1986          * Set secret handshake long timeout.
1987          */
setSecretHandshakeLongTimeoutMs(long value)1988         public Builder setSecretHandshakeLongTimeoutMs(long value) {
1989             this.mSecretHandshakeLongTimeoutMs = value;
1990             return this;
1991         }
1992 
1993         /**
1994          * Set secret handshake short timeout retry max spent time.
1995          */
setSecretHandshakeShortTimeoutRetryMaxSpentTimeMs(long value)1996         public Builder setSecretHandshakeShortTimeoutRetryMaxSpentTimeMs(long value) {
1997             this.mSecretHandshakeShortTimeoutRetryMaxSpentTimeMs = value;
1998             return this;
1999         }
2000 
2001         /**
2002          * Set secret handshake long timeout retry max spent time.
2003          */
setSecretHandshakeLongTimeoutRetryMaxSpentTimeMs(long value)2004         public Builder setSecretHandshakeLongTimeoutRetryMaxSpentTimeMs(long value) {
2005             this.mSecretHandshakeLongTimeoutRetryMaxSpentTimeMs = value;
2006             return this;
2007         }
2008 
2009         /**
2010          * Set secret handshake retry attempts allowed.
2011          */
setSecretHandshakeRetryAttempts(long value)2012         public Builder setSecretHandshakeRetryAttempts(long value) {
2013             this.mSecretHandshakeRetryAttempts = value;
2014             return this;
2015         }
2016 
2017         /**
2018          * Set secret handshake retry gatt connection max spent time.
2019          */
setSecretHandshakeRetryGattConnectionMaxSpentTimeMs(long value)2020         public Builder setSecretHandshakeRetryGattConnectionMaxSpentTimeMs(long value) {
2021             this.mSecretHandshakeRetryGattConnectionMaxSpentTimeMs = value;
2022             return this;
2023         }
2024 
2025         /**
2026          * Set signal loss retry max spent time.
2027          */
setSignalLostRetryMaxSpentTimeMs(long value)2028         public Builder setSignalLostRetryMaxSpentTimeMs(long value) {
2029             this.mSignalLostRetryMaxSpentTimeMs = value;
2030             return this;
2031         }
2032 
2033         /**
2034          * Set gatt connection and secret handshake no retry gatt error.
2035          */
setGattConnectionAndSecretHandshakeNoRetryGattError( ImmutableSet<Integer> value)2036         public Builder setGattConnectionAndSecretHandshakeNoRetryGattError(
2037                 ImmutableSet<Integer> value) {
2038             this.mGattConnectionAndSecretHandshakeNoRetryGattError = value;
2039             return this;
2040         }
2041 
2042         /**
2043          * Set retry secret handshake timeout.
2044          */
setRetrySecretHandshakeTimeout(boolean value)2045         public Builder setRetrySecretHandshakeTimeout(boolean value) {
2046             this.mRetrySecretHandshakeTimeout = value;
2047             return this;
2048         }
2049 
2050         /**
2051          * Set whether to log user manual retry.
2052          */
setLogUserManualRetry(boolean value)2053         public Builder setLogUserManualRetry(boolean value) {
2054             this.mLogUserManualRetry = value;
2055             return this;
2056         }
2057 
2058         /**
2059          * Set pair falure counts.
2060          */
setPairFailureCounts(int counts)2061         public Builder setPairFailureCounts(int counts) {
2062             this.mPairFailureCounts = counts;
2063             return this;
2064         }
2065 
2066         /**
2067          * Set whether to use pair flow to show ui when pairing is finished without connecting
2068          * profile..
2069          */
setEnablePairFlowShowUiWithoutProfileConnection(boolean value)2070         public Builder setEnablePairFlowShowUiWithoutProfileConnection(boolean value) {
2071             this.mEnablePairFlowShowUiWithoutProfileConnection = value;
2072             return this;
2073         }
2074 
2075         /**
2076          * Set whether to log pairing with cached module Id.
2077          */
setLogPairWithCachedModelId(boolean value)2078         public Builder setLogPairWithCachedModelId(boolean value) {
2079             this.mLogPairWithCachedModelId = value;
2080             return this;
2081         }
2082 
2083         /**
2084          * Set possible cached device address.
2085          */
setPossibleCachedDeviceAddress(String value)2086         public Builder setPossibleCachedDeviceAddress(String value) {
2087             this.mPossibleCachedDeviceAddress = value;
2088             return this;
2089         }
2090 
2091         /**
2092          * Set paired device count from the same module Id.
2093          */
setSameModelIdPairedDeviceCount(int value)2094         public Builder setSameModelIdPairedDeviceCount(int value) {
2095             this.mSameModelIdPairedDeviceCount = value;
2096             return this;
2097         }
2098 
2099         /**
2100          * Set whether the bonded device address is from cache.
2101          */
setIsDeviceFinishCheckAddressFromCache(boolean value)2102         public Builder setIsDeviceFinishCheckAddressFromCache(boolean value) {
2103             this.mIsDeviceFinishCheckAddressFromCache = value;
2104             return this;
2105         }
2106 
2107         /**
2108          * Set whether to directly connect profile if modelId is in cache.
2109          */
setDirectConnectProfileIfModelIdInCache(boolean value)2110         public Builder setDirectConnectProfileIfModelIdInCache(boolean value) {
2111             this.mDirectConnectProfileIfModelIdInCache = value;
2112             return this;
2113         }
2114 
2115         /**
2116          * Set cached device address.
2117          */
setCachedDeviceAddress(String value)2118         public Builder setCachedDeviceAddress(String value) {
2119             this.mCachedDeviceAddress = value;
2120             return this;
2121         }
2122 
2123         /**
2124          * Builds a Preferences instance.
2125          */
build()2126         public Preferences build() {
2127             return new Preferences(
2128                     this.mGattOperationTimeoutSeconds,
2129                     this.mGattConnectionTimeoutSeconds,
2130                     this.mBluetoothToggleTimeoutSeconds,
2131                     this.mBluetoothToggleSleepSeconds,
2132                     this.mClassicDiscoveryTimeoutSeconds,
2133                     this.mNumDiscoverAttempts,
2134                     this.mDiscoveryRetrySleepSeconds,
2135                     this.mIgnoreDiscoveryError,
2136                     this.mSdpTimeoutSeconds,
2137                     this.mNumSdpAttempts,
2138                     this.mNumCreateBondAttempts,
2139                     this.mNumConnectAttempts,
2140                     this.mNumWriteAccountKeyAttempts,
2141                     this.mToggleBluetoothOnFailure,
2142                     this.mBluetoothStateUsesPolling,
2143                     this.mBluetoothStatePollingMillis,
2144                     this.mNumAttempts,
2145                     this.mEnableBrEdrHandover,
2146                     this.mBrHandoverDataCharacteristicId,
2147                     this.mBluetoothSigDataCharacteristicId,
2148                     this.mFirmwareVersionCharacteristicId,
2149                     this.mBrTransportBlockDataDescriptorId,
2150                     this.mWaitForUuidsAfterBonding,
2151                     this.mReceiveUuidsAndBondedEventBeforeClose,
2152                     this.mRemoveBondTimeoutSeconds,
2153                     this.mRemoveBondSleepMillis,
2154                     this.mCreateBondTimeoutSeconds,
2155                     this.mHidCreateBondTimeoutSeconds,
2156                     this.mProxyTimeoutSeconds,
2157                     this.mRejectPhonebookAccess,
2158                     this.mRejectMessageAccess,
2159                     this.mRejectSimAccess,
2160                     this.mWriteAccountKeySleepMillis,
2161                     this.mSkipDisconnectingGattBeforeWritingAccountKey,
2162                     this.mMoreEventLogForQuality,
2163                     this.mRetryGattConnectionAndSecretHandshake,
2164                     this.mGattConnectShortTimeoutMs,
2165                     this.mGattConnectLongTimeoutMs,
2166                     this.mGattConnectShortTimeoutRetryMaxSpentTimeMs,
2167                     this.mAddressRotateRetryMaxSpentTimeMs,
2168                     this.mPairingRetryDelayMs,
2169                     this.mSecretHandshakeShortTimeoutMs,
2170                     this.mSecretHandshakeLongTimeoutMs,
2171                     this.mSecretHandshakeShortTimeoutRetryMaxSpentTimeMs,
2172                     this.mSecretHandshakeLongTimeoutRetryMaxSpentTimeMs,
2173                     this.mSecretHandshakeRetryAttempts,
2174                     this.mSecretHandshakeRetryGattConnectionMaxSpentTimeMs,
2175                     this.mSignalLostRetryMaxSpentTimeMs,
2176                     this.mGattConnectionAndSecretHandshakeNoRetryGattError,
2177                     this.mRetrySecretHandshakeTimeout,
2178                     this.mLogUserManualRetry,
2179                     this.mPairFailureCounts,
2180                     this.mCachedDeviceAddress,
2181                     this.mPossibleCachedDeviceAddress,
2182                     this.mSameModelIdPairedDeviceCount,
2183                     this.mIsDeviceFinishCheckAddressFromCache,
2184                     this.mLogPairWithCachedModelId,
2185                     this.mDirectConnectProfileIfModelIdInCache,
2186                     this.mAcceptPasskey,
2187                     this.mSupportedProfileUuids,
2188                     this.mProviderInitiatesBondingIfSupported,
2189                     this.mAttemptDirectConnectionWhenPreviouslyBonded,
2190                     this.mAutomaticallyReconnectGattWhenNeeded,
2191                     this.mSkipConnectingProfiles,
2192                     this.mIgnoreUuidTimeoutAfterBonded,
2193                     this.mSpecifyCreateBondTransportType,
2194                     this.mCreateBondTransportType,
2195                     this.mIncreaseIntentFilterPriority,
2196                     this.mEvaluatePerformance,
2197                     this.mExtraLoggingInformation,
2198                     this.mEnableNamingCharacteristic,
2199                     this.mEnableFirmwareVersionCharacteristic,
2200                     this.mKeepSameAccountKeyWrite,
2201                     this.mIsRetroactivePairing,
2202                     this.mNumSdpAttemptsAfterBonded,
2203                     this.mSupportHidDevice,
2204                     this.mEnablePairingWhileDirectlyConnecting,
2205                     this.mAcceptConsentForFastPairOne,
2206                     this.mGattConnectRetryTimeoutMillis,
2207                     this.mEnable128BitCustomGattCharacteristicsId,
2208                     this.mEnableSendExceptionStepToValidator,
2209                     this.mEnableAdditionalDataTypeWhenActionOverBle,
2210                     this.mCheckBondStateWhenSkipConnectingProfiles,
2211                     this.mHandlePasskeyConfirmationByUi,
2212                     this.mEnablePairFlowShowUiWithoutProfileConnection);
2213         }
2214     }
2215 
2216     /**
2217      * Whether a given Uuid is supported.
2218      */
isSupportedProfile(short profileUuid)2219     public boolean isSupportedProfile(short profileUuid) {
2220         return Constants.PROFILES.containsKey(profileUuid)
2221                 && Shorts.contains(
2222                 Bytes.toShorts(ByteOrder.BIG_ENDIAN, getSupportedProfileUuids()), profileUuid);
2223     }
2224 
2225     /**
2226      * Information that will be used for logging.
2227      */
2228     public static class ExtraLoggingInformation {
2229 
2230         private final String mModelId;
2231 
ExtraLoggingInformation(String modelId)2232         private ExtraLoggingInformation(String modelId) {
2233             this.mModelId = modelId;
2234         }
2235 
2236         /**
2237          * Returns model Id.
2238          */
getModelId()2239         public String getModelId() {
2240             return mModelId;
2241         }
2242 
2243         /**
2244          * Converts an instance to a builder.
2245          */
toBuilder()2246         public Builder toBuilder() {
2247             return new Builder(this);
2248         }
2249 
2250         /**
2251          * Creates a builder for ExtraLoggingInformation.
2252          */
builder()2253         public static Builder builder() {
2254             return new ExtraLoggingInformation.Builder();
2255         }
2256 
2257         @Override
toString()2258         public String toString() {
2259             return "ExtraLoggingInformation{" + "modelId=" + mModelId + "}";
2260         }
2261 
2262         @Override
equals(@ullable Object o)2263         public boolean equals(@Nullable Object o) {
2264             if (o == this) {
2265                 return true;
2266             }
2267             if (o instanceof ExtraLoggingInformation) {
2268                 Preferences.ExtraLoggingInformation that = (Preferences.ExtraLoggingInformation) o;
2269                 return this.mModelId.equals(that.getModelId());
2270             }
2271             return false;
2272         }
2273 
2274         @Override
hashCode()2275         public int hashCode() {
2276             return Objects.hash(mModelId);
2277         }
2278 
2279         /**
2280          * Extra logging information builder.
2281          */
2282         public static class Builder {
2283 
2284             private String mModelId;
2285 
Builder()2286             private Builder() {
2287             }
2288 
Builder(ExtraLoggingInformation source)2289             private Builder(ExtraLoggingInformation source) {
2290                 this.mModelId = source.getModelId();
2291             }
2292 
2293             /**
2294              * Set model ID.
2295              */
setModelId(String modelId)2296             public Builder setModelId(String modelId) {
2297                 this.mModelId = modelId;
2298                 return this;
2299             }
2300 
2301             /**
2302              * Builds extra logging information.
2303              */
build()2304             public ExtraLoggingInformation build() {
2305                 return new ExtraLoggingInformation(mModelId);
2306             }
2307         }
2308     }
2309 }
2310