2 * Copyright (C) 2017 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package android.bluetooth.le;
19 import android.annotation.Nullable;
20 import android.os.Parcel;
21 import android.os.Parcelable;
23 import java.util.Objects;
26 * PeriodicAdvertisingReport for Bluetooth LE synchronized advertising.
29 public final class PeriodicAdvertisingReport implements Parcelable {
32 * The data returned is complete
34 public static final int DATA_COMPLETE = 0;
37 * The data returned is incomplete. The controller was unsuccessfull to
38 * receive all chained packets, returning only partial data.
40 public static final int DATA_INCOMPLETE_TRUNCATED = 2;
42 private int syncHandle;
45 private int dataStatus;
47 // periodic advertising data.
49 private ScanRecord data;
51 // Device timestamp when the result was last seen.
52 private long timestampNanos;
55 * Constructor of periodic advertising result.
58 public PeriodicAdvertisingReport(int syncHandle, int txPower, int rssi,
59 int dataStatus, ScanRecord data) {
60 this.syncHandle = syncHandle;
61 this.txPower = txPower;
63 this.dataStatus = dataStatus;
67 private PeriodicAdvertisingReport(Parcel in) {
72 public void writeToParcel(Parcel dest, int flags) {
73 dest.writeInt(syncHandle);
74 dest.writeLong(txPower);
76 dest.writeInt(dataStatus);
79 dest.writeByteArray(data.getBytes());
85 private void readFromParcel(Parcel in) {
86 syncHandle = in.readInt();
87 txPower = in.readInt();
89 dataStatus = in.readInt();
90 if (in.readInt() == 1) {
91 data = ScanRecord.parseFromBytes(in.createByteArray());
96 public int describeContents() {
101 * Returns the synchronization handle.
103 public int getSyncHandle() {
108 * Returns the transmit power in dBm. The valid range is [-127, 126]. Value
109 * of 127 means information was not available.
111 public int getTxPower() {
116 * Returns the received signal strength in dBm. The valid range is [-127, 20].
118 public int getRssi() {
123 * Returns the data status. Can be one of {@link PeriodicAdvertisingReport#DATA_COMPLETE}
124 * or {@link PeriodicAdvertisingReport#DATA_INCOMPLETE_TRUNCATED}.
126 public int getDataStatus() {
131 * Returns the data contained in this periodic advertising report.
134 public ScanRecord getData() {
139 * Returns timestamp since boot when the scan record was observed.
141 public long getTimestampNanos() {
142 return timestampNanos;
146 public int hashCode() {
147 return Objects.hash(syncHandle, txPower, rssi, dataStatus, data, timestampNanos);
151 public boolean equals(Object obj) {
155 if (obj == null || getClass() != obj.getClass()) {
158 PeriodicAdvertisingReport other = (PeriodicAdvertisingReport) obj;
159 return (syncHandle == other.syncHandle) &&
160 (txPower == other.txPower) &&
161 (rssi == other.rssi) &&
162 (dataStatus == other.dataStatus) &&
163 Objects.equals(data, other.data) &&
164 (timestampNanos == other.timestampNanos);
168 public String toString() {
169 return "PeriodicAdvertisingReport{syncHandle=" + syncHandle +
170 ", txPower=" + txPower + ", rssi=" + rssi + ", dataStatus=" + dataStatus +
171 ", data=" + Objects.toString(data) + ", timestampNanos=" + timestampNanos + '}';
174 public static final Parcelable.Creator<PeriodicAdvertisingReport> CREATOR = new Creator<PeriodicAdvertisingReport>() {
176 public PeriodicAdvertisingReport createFromParcel(Parcel source) {
177 return new PeriodicAdvertisingReport(source);
181 public PeriodicAdvertisingReport[] newArray(int size) {
182 return new PeriodicAdvertisingReport[size];