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