1 /*
2  * Copyright 2022 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.bluetooth.bass_client;
18 
19 import android.bluetooth.BluetoothDevice;
20 import android.util.Log;
21 
22 /** Periodic Advertisement Result */
23 public class PeriodicAdvertisementResult {
24     private static final String TAG = PeriodicAdvertisementResult.class.getSimpleName();
25 
26     private BluetoothDevice mDevice;
27     private int mAddressType;
28     private int mAdvSid;
29     private int mSyncHandle;
30     private int mPAInterval;
31     private int mBroadcastId;
32     private boolean mIsNotified;
33     private PublicBroadcastData mPbData;
34     private String mBroadcastName;
35 
PeriodicAdvertisementResult( BluetoothDevice device, int addressType, int syncHandle, int advSid, int paInterval, int broadcastId, PublicBroadcastData pbData, String broadcastName)36     PeriodicAdvertisementResult(
37             BluetoothDevice device,
38             int addressType,
39             int syncHandle,
40             int advSid,
41             int paInterval,
42             int broadcastId,
43             PublicBroadcastData pbData,
44             String broadcastName) {
45         mDevice = device;
46         mAddressType = addressType;
47         mAdvSid = advSid;
48         mSyncHandle = syncHandle;
49         mPAInterval = paInterval;
50         mBroadcastId = broadcastId;
51         mIsNotified = false;
52         mPbData = pbData;
53         mBroadcastName = broadcastName;
54     }
55 
56     /** Update Sync handle */
updateSyncHandle(int syncHandle)57     public void updateSyncHandle(int syncHandle) {
58         mSyncHandle = syncHandle;
59     }
60 
61     /** Get Sync handle */
getSyncHandle()62     public int getSyncHandle() {
63         return mSyncHandle;
64     }
65 
66     /** Get mIsNotified flag */
isNotified()67     public boolean isNotified() {
68         synchronized (this) {
69             return mIsNotified;
70         }
71     }
72 
setNotified(boolean isNotified)73     public void setNotified(boolean isNotified) {
74         synchronized (this) {
75             mIsNotified = isNotified;
76         }
77     }
78 
79     /** Update Adv ID */
updateAdvSid(int advSid)80     public void updateAdvSid(int advSid) {
81         mAdvSid = advSid;
82     }
83 
84     /** Get Adv ID */
getAdvSid()85     public int getAdvSid() {
86         return mAdvSid;
87     }
88 
89     /** Update address type */
updateAddressType(int addressType)90     public void updateAddressType(int addressType) {
91         mAddressType = addressType;
92     }
93 
94     /** Get address type */
getAddressType()95     public int getAddressType() {
96         return mAddressType;
97     }
98 
99     /** Update Adv interval */
updateAdvInterval(int advInterval)100     public void updateAdvInterval(int advInterval) {
101         mPAInterval = advInterval;
102     }
103 
104     /** Get Adv interval */
getAdvInterval()105     public int getAdvInterval() {
106         return mPAInterval;
107     }
108 
109     /** Update broadcast ID */
updateBroadcastId(int broadcastId)110     public void updateBroadcastId(int broadcastId) {
111         mBroadcastId = broadcastId;
112     }
113 
114     /** Get broadcast ID */
getBroadcastId()115     public int getBroadcastId() {
116         return mBroadcastId;
117     }
118 
119     /** Update public broadcast data */
updatePublicBroadcastData(PublicBroadcastData pbData)120     public void updatePublicBroadcastData(PublicBroadcastData pbData) {
121         mPbData = pbData;
122     }
123 
124     /** Get public broadcast data */
getPublicBroadcastData()125     public PublicBroadcastData getPublicBroadcastData() {
126         return mPbData;
127     }
128 
129     /** Update broadcast name */
updateBroadcastName(String broadcastName)130     public void updateBroadcastName(String broadcastName) {
131         mBroadcastName = broadcastName;
132     }
133 
134     /** Get broadcast name */
getBroadcastName()135     public String getBroadcastName() {
136         return mBroadcastName;
137     }
138 
139     /** print */
print()140     public void print() {
141         log("-- PeriodicAdvertisementResult --");
142         log("mDevice:" + mDevice);
143         log("mAddressType:" + mAddressType);
144         log("mAdvSid:" + mAdvSid);
145         log("mSyncHandle:" + mSyncHandle);
146         log("mPAInterval:" + mPAInterval);
147         log("mBroadcastId:" + mBroadcastId);
148         log("mIsNotified: " + mIsNotified);
149         log("mBroadcastName: " + mBroadcastName);
150         log("-- END: PeriodicAdvertisementResult --");
151         if (mPbData != null) {
152             mPbData.print();
153         } else {
154             log("no public announcement present");
155         }
156     }
157 
log(String msg)158     static void log(String msg) {
159         Log.d(TAG, msg);
160     }
161 }
162