1a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski/*
2a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski * Copyright (C) 2017 The Android Open Source Project
3a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski *
4a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski * Licensed under the Apache License, Version 2.0 (the "License");
5a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski * you may not use this file except in compliance with the License.
6a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski * You may obtain a copy of the License at
7a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski *
8a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski *      http://www.apache.org/licenses/LICENSE-2.0
9a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski *
10a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski * Unless required by applicable law or agreed to in writing, software
11a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski * distributed under the License is distributed on an "AS IS" BASIS,
12a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski * See the License for the specific language governing permissions and
14a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski * limitations under the License.
15a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski */
16a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski
17a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowskipackage android.bluetooth.le;
18a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski
19f4ed33f5fa6ffa3bda6faff773a3fb90b16a760cJakub Pawlowskiimport android.bluetooth.BluetoothAdapter;
209e377194e35c0fb9ac5771f5658c095ed97e0838Jakub Pawlowskiimport android.bluetooth.BluetoothDevice;
21a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowskiimport android.os.Parcel;
22a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowskiimport android.os.Parcelable;
23a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski
24a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski/**
25a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski * The {@link AdvertisingSetParameters} provide a way to adjust advertising
26a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski * preferences for each
27a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski * Bluetooth LE advertising set. Use {@link AdvertisingSetParameters.Builder} to
28a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski * create an
29a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski * instance of this class.
30a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski */
31a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowskipublic final class AdvertisingSetParameters implements Parcelable {
32a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski
33a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski    /**
34a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski    * Advertise on low frequency, around every 1000ms. This is the default and
35a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski    * preferred advertising mode as it consumes the least power.
36a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski    */
376b1f39502c7d5f71b42d82ac6d511ee0afd1191eJakub Pawlowski    public static final int INTERVAL_HIGH = 1600;
38a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski
39a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski    /**
40a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski     * Advertise on medium frequency, around every 250ms. This is balanced
41a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski     * between advertising frequency and power consumption.
42a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski     */
43a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski    public static final int INTERVAL_MEDIUM = 400;
44a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski
45a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski    /**
46a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski     * Perform high frequency, low latency advertising, around every 100ms. This
47a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski     * has the highest power consumption and should not be used for continuous
48a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski     * background advertising.
49a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski     */
506b1f39502c7d5f71b42d82ac6d511ee0afd1191eJakub Pawlowski    public static final int INTERVAL_LOW = 160;
51a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski
52a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski    /**
53a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski     * Minimum value for advertising interval.
54a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski     */
55a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski    public static final int INTERVAL_MIN = 160;
56a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski
57a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski    /**
58a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski     * Maximum value for advertising interval.
59a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski     */
60a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski    public static final int INTERVAL_MAX = 16777215;
61a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski
62a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski    /**
63a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski     * Advertise using the lowest transmission (TX) power level. Low transmission
64a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski     * power can be used to restrict the visibility range of advertising packets.
65a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski     */
66a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski    public static final int TX_POWER_ULTRA_LOW = -21;
67a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski
68a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski    /**
69a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski     * Advertise using low TX power level.
70a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski     */
71a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski    public static final int TX_POWER_LOW = -15;
72a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski
73a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski    /**
74a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski     * Advertise using medium TX power level.
75a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski     */
76a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski    public static final int TX_POWER_MEDIUM = -7;
77a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski
78a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski    /**
79a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski     * Advertise using high TX power level. This corresponds to largest visibility
80a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski     * range of the advertising packet.
81a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski     */
82a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski    public static final int TX_POWER_HIGH = 1;
83a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski
84a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski    /**
85a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski     * Minimum value for TX power.
86a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski     */
87a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski    public static final int TX_POWER_MIN = -127;
88a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski
89a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski    /**
90a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski     * Maximum value for TX power.
91a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski     */
92a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski    public static final int TX_POWER_MAX = 1;
93a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski
94a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski    /**
95a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski     * The maximum limited advertisement duration as specified by the Bluetooth
96a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski     * SIG
97a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski     */
98a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski    private static final int LIMITED_ADVERTISING_MAX_MILLIS = 180 * 1000;
99a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski
100a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski    private final boolean isLegacy;
101a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski    private final boolean isAnonymous;
102a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski    private final boolean includeTxPower;
103a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski    private final int primaryPhy;
104a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski    private final int secondaryPhy;
105a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski    private final boolean connectable;
106d12b5688f06b0f3428730262cf208713442f6f5bJakub Pawlowski    private final boolean scannable;
107a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski    private final int interval;
108a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski    private final int txPowerLevel;
109a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski
110d12b5688f06b0f3428730262cf208713442f6f5bJakub Pawlowski    private AdvertisingSetParameters(boolean connectable, boolean scannable, boolean isLegacy,
111a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski                                     boolean isAnonymous, boolean includeTxPower,
112a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski                                     int primaryPhy, int secondaryPhy,
113adbf2eef2fda68a5c3acc78a67e5dda00d8a14d7Jakub Pawlowski                                     int interval, int txPowerLevel) {
114a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski        this.connectable = connectable;
115d12b5688f06b0f3428730262cf208713442f6f5bJakub Pawlowski        this.scannable = scannable;
116a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski        this.isLegacy = isLegacy;
117a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski        this.isAnonymous = isAnonymous;
118a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski        this.includeTxPower = includeTxPower;
119a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski        this.primaryPhy = primaryPhy;
120a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski        this.secondaryPhy = secondaryPhy;
121a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski        this.interval = interval;
122a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski        this.txPowerLevel = txPowerLevel;
123a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski    }
124a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski
125a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski    private AdvertisingSetParameters(Parcel in) {
126a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski        connectable = in.readInt() != 0 ? true : false;
127d12b5688f06b0f3428730262cf208713442f6f5bJakub Pawlowski        scannable = in.readInt() != 0 ? true : false;
128a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski        isLegacy = in.readInt() != 0 ? true : false;
129a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski        isAnonymous = in.readInt() != 0 ? true : false;
130a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski        includeTxPower = in.readInt() != 0 ? true : false;
131a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski        primaryPhy = in.readInt();
132a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski        secondaryPhy = in.readInt();
133a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski        interval = in.readInt();
134a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski        txPowerLevel = in.readInt();
135a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski    }
136a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski
137a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski    /**
138a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski     * Returns whether the advertisement will be connectable.
139a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski     */
140a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski    public boolean isConnectable() { return connectable; }
141a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski
142a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski    /**
143d12b5688f06b0f3428730262cf208713442f6f5bJakub Pawlowski     * Returns whether the advertisement will be scannable.
144d12b5688f06b0f3428730262cf208713442f6f5bJakub Pawlowski     */
145d12b5688f06b0f3428730262cf208713442f6f5bJakub Pawlowski    public boolean isScannable() { return scannable; }
146d12b5688f06b0f3428730262cf208713442f6f5bJakub Pawlowski
147d12b5688f06b0f3428730262cf208713442f6f5bJakub Pawlowski    /**
148a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski     * Returns whether the legacy advertisement will be used.
149a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski     */
150a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski    public boolean isLegacy() { return isLegacy; }
151a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski
152a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski    /**
153a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski     * Returns whether the advertisement will be anonymous.
154a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski     */
155a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski    public boolean isAnonymous() { return isAnonymous; }
156a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski
157a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski    /**
158a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski     * Returns whether the TX Power will be included.
159a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski     */
160a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski    public boolean includeTxPower() { return includeTxPower; }
161a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski
162a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski    /**
163a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski     * Returns the primary advertising phy.
164a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski     */
165a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski    public int getPrimaryPhy() { return primaryPhy; }
166a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski
167a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski    /**
168a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski     * Returns the secondary advertising phy.
169a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski     */
170a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski    public int getSecondaryPhy() { return secondaryPhy; }
171a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski
172a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski    /**
173a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski     * Returns the advertising interval.
174a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski     */
175a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski    public int getInterval() { return interval; }
176a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski
177a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski    /**
178a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski     * Returns the TX power level for advertising.
179a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski     */
180a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski    public int getTxPowerLevel() { return txPowerLevel; }
181a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski
182a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski    @Override
183a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski    public String toString() {
184a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski        return "AdvertisingSetParameters [connectable=" + connectable
185a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski             + ", isLegacy=" + isLegacy
186a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski             + ", isAnonymous=" + isAnonymous
187a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski             + ", includeTxPower=" + includeTxPower
188a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski             + ", primaryPhy=" + primaryPhy
189a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski             + ", secondaryPhy=" + secondaryPhy
190a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski             + ", interval=" + interval
191adbf2eef2fda68a5c3acc78a67e5dda00d8a14d7Jakub Pawlowski             + ", txPowerLevel=" + txPowerLevel + "]";
192a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski    }
193a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski
194a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski    @Override
195a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski    public int describeContents() {
196a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski       return 0;
197a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski    }
198a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski
199a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski    @Override
200a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski    public void writeToParcel(Parcel dest, int flags) {
201a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski        dest.writeInt(connectable ? 1 : 0);
202d12b5688f06b0f3428730262cf208713442f6f5bJakub Pawlowski        dest.writeInt(scannable ? 1 : 0);
203a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski        dest.writeInt(isLegacy ? 1 : 0);
204a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski        dest.writeInt(isAnonymous ? 1 : 0);
205a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski        dest.writeInt(includeTxPower ? 1 : 0);
206a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski        dest.writeInt(primaryPhy);
207a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski        dest.writeInt(secondaryPhy);
208a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski        dest.writeInt(interval);
209a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski        dest.writeInt(txPowerLevel);
210a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski    }
211a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski
212a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski    public static final Parcelable.Creator<AdvertisingSetParameters> CREATOR =
213a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski        new Creator<AdvertisingSetParameters>() {
214a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski          @Override
215a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski          public AdvertisingSetParameters[] newArray(int size) {
216a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski            return new AdvertisingSetParameters[size];
217a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski          }
218a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski
219a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski          @Override
220a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski          public AdvertisingSetParameters createFromParcel(Parcel in) {
221a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski            return new AdvertisingSetParameters(in);
222a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski          }
223a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski        };
224a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski
225a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski    /**
226a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski     * Builder class for {@link AdvertisingSetParameters}.
227a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski     */
228a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski    public static final class Builder {
229a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski
230010cc95583d6b93bdcc9cf7959f8470d109f8a3dJakub Pawlowski        private boolean connectable = false;
231010cc95583d6b93bdcc9cf7959f8470d109f8a3dJakub Pawlowski        private boolean scannable = false;
232a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski        private boolean isLegacy = false;
233a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski        private boolean isAnonymous = false;
234a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski        private boolean includeTxPower = false;
2359e377194e35c0fb9ac5771f5658c095ed97e0838Jakub Pawlowski        private int primaryPhy = BluetoothDevice.PHY_LE_1M;
2369e377194e35c0fb9ac5771f5658c095ed97e0838Jakub Pawlowski        private int secondaryPhy = BluetoothDevice.PHY_LE_1M;
237a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski        private int interval = INTERVAL_LOW;
238a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski        private int txPowerLevel = TX_POWER_MEDIUM;
239a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski
240a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski        /**
241a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski         * Set whether the advertisement type should be connectable or
242a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski         * non-connectable.
243010cc95583d6b93bdcc9cf7959f8470d109f8a3dJakub Pawlowski         * Legacy advertisements can be both connectable and scannable. Non-legacy
244e7f89b07e6fa3a99877af3298c2a80db23a591d7Jakub Pawlowski         * advertisements can be only scannable or only connectable.
2459d4abb5631c7719de8d919e0c37c9aee54354266Jakub Pawlowski         * @param connectable Controls whether the advertisement type will be
246010cc95583d6b93bdcc9cf7959f8470d109f8a3dJakub Pawlowski         * connectable (true) or non-connectable (false).
247a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski         */
248a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski        public Builder setConnectable(boolean connectable) {
249a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski            this.connectable = connectable;
250a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski            return this;
251a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski        }
252a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski
253a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski        /**
254e7f89b07e6fa3a99877af3298c2a80db23a591d7Jakub Pawlowski         * Set whether the advertisement type should be scannable.
255010cc95583d6b93bdcc9cf7959f8470d109f8a3dJakub Pawlowski         * Legacy advertisements can be both connectable and scannable. Non-legacy
256e7f89b07e6fa3a99877af3298c2a80db23a591d7Jakub Pawlowski         * advertisements can be only scannable or only connectable.
2579d4abb5631c7719de8d919e0c37c9aee54354266Jakub Pawlowski         * @param scannable Controls whether the advertisement type will be
258010cc95583d6b93bdcc9cf7959f8470d109f8a3dJakub Pawlowski         * scannable (true) or non-scannable (false).
259d12b5688f06b0f3428730262cf208713442f6f5bJakub Pawlowski         */
260d12b5688f06b0f3428730262cf208713442f6f5bJakub Pawlowski        public Builder setScannable(boolean scannable) {
261d12b5688f06b0f3428730262cf208713442f6f5bJakub Pawlowski            this.scannable = scannable;
262d12b5688f06b0f3428730262cf208713442f6f5bJakub Pawlowski            return this;
263d12b5688f06b0f3428730262cf208713442f6f5bJakub Pawlowski        }
264d12b5688f06b0f3428730262cf208713442f6f5bJakub Pawlowski
265d12b5688f06b0f3428730262cf208713442f6f5bJakub Pawlowski        /**
266a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski         * When set to true, advertising set will advertise 4.x Spec compliant
267a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski         * advertisements.
268a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski         *
26908ed924d8922eec0555f6a860d80e6e2770c8a2dJakub Pawlowski         * @param isLegacy whether legacy advertising mode should be used.
270a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski         */
271a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski        public Builder setLegacyMode(boolean isLegacy) {
272a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski            this.isLegacy = isLegacy;
273a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski            return this;
274a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski        }
275a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski
276a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski        /**
27708ed924d8922eec0555f6a860d80e6e2770c8a2dJakub Pawlowski         * Set whether advertiser address should be ommited from all packets. If this
278a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski         * mode is used, periodic advertising can't be enabled for this set.
279a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski         *
280a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski         * This is used only if legacy mode is not used.
281a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski         *
28208ed924d8922eec0555f6a860d80e6e2770c8a2dJakub Pawlowski         * @param isAnonymous whether anonymous advertising should be used.
283a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski         */
284bc2991e8665d2f2484e24b7e9f72b18c3c740ae1Jakub Pawlowski        public Builder setAnonymous(boolean isAnonymous) {
285a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski            this.isAnonymous = isAnonymous;
286a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski            return this;
287a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski        }
288a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski
289a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski        /**
29008ed924d8922eec0555f6a860d80e6e2770c8a2dJakub Pawlowski         * Set whether TX power should be included in the extended header.
291a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski         *
292a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski         * This is used only if legacy mode is not used.
293a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski         *
29408ed924d8922eec0555f6a860d80e6e2770c8a2dJakub Pawlowski         * @param includeTxPower whether TX power should be included in extended
295f4ed33f5fa6ffa3bda6faff773a3fb90b16a760cJakub Pawlowski         *            header
296a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski         */
297a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski        public Builder setIncludeTxPower(boolean includeTxPower) {
298a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski            this.includeTxPower = includeTxPower;
299a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski            return this;
300a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski        }
301a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski
302a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski        /**
303a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski         * Set the primary physical channel used for this advertising set.
304a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski         *
305a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski         * This is used only if legacy mode is not used.
306a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski         *
307f4ed33f5fa6ffa3bda6faff773a3fb90b16a760cJakub Pawlowski         * Use {@link BluetoothAdapter#isLeCodedPhySupported} to determine if LE Coded PHY is
308f4ed33f5fa6ffa3bda6faff773a3fb90b16a760cJakub Pawlowski         * supported on this device.
309a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski         * @param primaryPhy Primary advertising physical channel, can only be
3109e377194e35c0fb9ac5771f5658c095ed97e0838Jakub Pawlowski         *            {@link BluetoothDevice#PHY_LE_1M} or
3119e377194e35c0fb9ac5771f5658c095ed97e0838Jakub Pawlowski         *            {@link BluetoothDevice#PHY_LE_CODED}.
312a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski         * @throws IllegalArgumentException If the primaryPhy is invalid.
313a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski         */
314a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski        public Builder setPrimaryPhy(int primaryPhy) {
3159e377194e35c0fb9ac5771f5658c095ed97e0838Jakub Pawlowski            if (primaryPhy != BluetoothDevice.PHY_LE_1M &&
3169e377194e35c0fb9ac5771f5658c095ed97e0838Jakub Pawlowski                primaryPhy != BluetoothDevice.PHY_LE_CODED) {
317a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski               throw new IllegalArgumentException("bad primaryPhy " + primaryPhy);
318a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski            }
319a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski            this.primaryPhy = primaryPhy;
320a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski            return this;
321a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski        }
322a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski
323a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski        /**
324a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski         * Set the secondary physical channel used for this advertising set.
325a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski         *
326a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski         * This is used only if legacy mode is not used.
327a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski         *
328f4ed33f5fa6ffa3bda6faff773a3fb90b16a760cJakub Pawlowski         * Use {@link BluetoothAdapter#isLeCodedPhySupported} and
329f4ed33f5fa6ffa3bda6faff773a3fb90b16a760cJakub Pawlowski         * {@link BluetoothAdapter#isLe2MPhySupported} to determine if LE Coded PHY or 2M PHY is
330f4ed33f5fa6ffa3bda6faff773a3fb90b16a760cJakub Pawlowski         * supported on this device.
331f4ed33f5fa6ffa3bda6faff773a3fb90b16a760cJakub Pawlowski         *
332a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski         * @param secondaryPhy Secondary advertising physical channel, can only be
3339e377194e35c0fb9ac5771f5658c095ed97e0838Jakub Pawlowski         *            one of {@link BluetoothDevice#PHY_LE_1M},
3349e377194e35c0fb9ac5771f5658c095ed97e0838Jakub Pawlowski         *            {@link BluetoothDevice#PHY_LE_2M} or
3359e377194e35c0fb9ac5771f5658c095ed97e0838Jakub Pawlowski         *            {@link BluetoothDevice#PHY_LE_CODED}.
336a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski         * @throws IllegalArgumentException If the secondaryPhy is invalid.
337a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski         */
338a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski        public Builder setSecondaryPhy(int secondaryPhy) {
3399e377194e35c0fb9ac5771f5658c095ed97e0838Jakub Pawlowski            if (secondaryPhy != BluetoothDevice.PHY_LE_1M &&
3409e377194e35c0fb9ac5771f5658c095ed97e0838Jakub Pawlowski                secondaryPhy != BluetoothDevice.PHY_LE_2M &&
3419e377194e35c0fb9ac5771f5658c095ed97e0838Jakub Pawlowski                secondaryPhy != BluetoothDevice.PHY_LE_CODED) {
342a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski               throw new IllegalArgumentException("bad secondaryPhy " + secondaryPhy);
343a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski            }
344a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski            this.secondaryPhy = secondaryPhy;
345a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski            return this;
346a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski        }
347a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski
348a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski        /**
349a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski         * Set advertising interval.
350a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski         *
351a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski         * @param interval Bluetooth LE Advertising interval, in 0.625ms unit. Valid
352a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski         *            range is from 160 (100ms) to 16777215 (10,485.759375 s).
353a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski         *            Recommended values are:
354a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski         *            {@link AdvertisingSetParameters#INTERVAL_LOW},
355a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski         *            {@link AdvertisingSetParameters#INTERVAL_MEDIUM}, or
356a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski         *            {@link AdvertisingSetParameters#INTERVAL_HIGH}.
357a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski         * @throws IllegalArgumentException If the interval is invalid.
358a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski         */
359a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski        public Builder setInterval(int interval) {
360a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski            if (interval < INTERVAL_MIN || interval > INTERVAL_MAX) {
361a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski               throw new IllegalArgumentException("unknown interval " + interval);
362a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski            }
363a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski            this.interval = interval;
364a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski            return this;
365a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski        }
366a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski
367a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski        /**
368a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski         * Set the transmission power level for the advertising.
369a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski         * @param txPowerLevel Transmission power of Bluetooth LE Advertising, in
370a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski         *             dBm. The valid range is [-127, 1] Recommended values are:
371a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski         *             {@link AdvertisingSetParameters#TX_POWER_ULTRA_LOW},
372a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski         *             {@link AdvertisingSetParameters#TX_POWER_LOW},
373a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski         *             {@link AdvertisingSetParameters#TX_POWER_MEDIUM}, or
374a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski         *             {@link AdvertisingSetParameters#TX_POWER_HIGH}.
375a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski         *
376a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski         * @throws IllegalArgumentException If the {@code txPowerLevel} is invalid.
377a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski         */
378a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski        public Builder setTxPowerLevel(int txPowerLevel) {
379a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski            if (txPowerLevel < TX_POWER_MIN || txPowerLevel > TX_POWER_MAX) {
380a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski                throw new IllegalArgumentException("unknown txPowerLevel " +
381a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski                                                   txPowerLevel);
382a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski            }
383a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski            this.txPowerLevel = txPowerLevel;
384a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski            return this;
385a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski        }
386a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski
387a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski        /**
388a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski         * Build the {@link AdvertisingSetParameters} object.
3899d4abb5631c7719de8d919e0c37c9aee54354266Jakub Pawlowski         * @throws IllegalStateException if invalid combination of parameters is used.
390a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski         */
391a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski        public AdvertisingSetParameters build() {
392f4ed33f5fa6ffa3bda6faff773a3fb90b16a760cJakub Pawlowski            if (isLegacy) {
393f4ed33f5fa6ffa3bda6faff773a3fb90b16a760cJakub Pawlowski                if (isAnonymous) {
394f4ed33f5fa6ffa3bda6faff773a3fb90b16a760cJakub Pawlowski                    throw new IllegalArgumentException("Legacy advertising can't be anonymous");
395f4ed33f5fa6ffa3bda6faff773a3fb90b16a760cJakub Pawlowski                }
396f4ed33f5fa6ffa3bda6faff773a3fb90b16a760cJakub Pawlowski
397f4ed33f5fa6ffa3bda6faff773a3fb90b16a760cJakub Pawlowski                if (connectable == true && scannable == false) {
3989d4abb5631c7719de8d919e0c37c9aee54354266Jakub Pawlowski                    throw new IllegalStateException(
399f4ed33f5fa6ffa3bda6faff773a3fb90b16a760cJakub Pawlowski                        "Legacy advertisement can't be connectable and non-scannable");
400f4ed33f5fa6ffa3bda6faff773a3fb90b16a760cJakub Pawlowski                }
401f4ed33f5fa6ffa3bda6faff773a3fb90b16a760cJakub Pawlowski
402f4ed33f5fa6ffa3bda6faff773a3fb90b16a760cJakub Pawlowski                if (includeTxPower) {
4039d4abb5631c7719de8d919e0c37c9aee54354266Jakub Pawlowski                    throw new IllegalStateException(
404f4ed33f5fa6ffa3bda6faff773a3fb90b16a760cJakub Pawlowski                        "Legacy advertising can't include TX power level in header");
405f4ed33f5fa6ffa3bda6faff773a3fb90b16a760cJakub Pawlowski                }
406f4ed33f5fa6ffa3bda6faff773a3fb90b16a760cJakub Pawlowski            } else {
407f4ed33f5fa6ffa3bda6faff773a3fb90b16a760cJakub Pawlowski                if (connectable && scannable) {
4089d4abb5631c7719de8d919e0c37c9aee54354266Jakub Pawlowski                    throw new IllegalStateException(
409f4ed33f5fa6ffa3bda6faff773a3fb90b16a760cJakub Pawlowski                        "Advertising can't be both connectable and scannable");
410f4ed33f5fa6ffa3bda6faff773a3fb90b16a760cJakub Pawlowski                }
411f4ed33f5fa6ffa3bda6faff773a3fb90b16a760cJakub Pawlowski
412f4ed33f5fa6ffa3bda6faff773a3fb90b16a760cJakub Pawlowski                if (isAnonymous && connectable) {
4139d4abb5631c7719de8d919e0c37c9aee54354266Jakub Pawlowski                    throw new IllegalStateException(
414f4ed33f5fa6ffa3bda6faff773a3fb90b16a760cJakub Pawlowski                        "Advertising can't be both connectable and anonymous");
415f4ed33f5fa6ffa3bda6faff773a3fb90b16a760cJakub Pawlowski                }
416f4ed33f5fa6ffa3bda6faff773a3fb90b16a760cJakub Pawlowski            }
417f4ed33f5fa6ffa3bda6faff773a3fb90b16a760cJakub Pawlowski
418d12b5688f06b0f3428730262cf208713442f6f5bJakub Pawlowski            return new AdvertisingSetParameters(connectable, scannable, isLegacy, isAnonymous,
419a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski                                                includeTxPower, primaryPhy,
420adbf2eef2fda68a5c3acc78a67e5dda00d8a14d7Jakub Pawlowski                                                secondaryPhy, interval, txPowerLevel);
421a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski        }
422a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski    }
423a9d1a32e5e51ebc3c141370c9d5045c6c938aaf9Jakub Pawlowski}