Skip to content

Commit 3a63df3

Browse files
cyberneelliamcharger
authored andcommitted
removed extra array
1 parent 733935f commit 3a63df3

File tree

2 files changed

+25
-28
lines changed

2 files changed

+25
-28
lines changed

src/components/ble/AppleNotificationCenterClient.cpp

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -190,39 +190,38 @@ void AppleNotificationCenterClient::OnNotification(ble_gap_event* event) {
190190
// bool negativeAction = eventFlags & static_cast<uint8_t>(EventFlags::NegativeAction);
191191

192192
// If notification was removed, we remove it from the notifications map
193-
if (ancsNotif.eventId == static_cast<uint8_t>(EventIds::Removed) && sessionNotificationUids.contains(ancsNotif.uuid)) {
194-
sessionNotificationUids.erase(ancsNotif.uuid);
195-
if (notifications.contains(ancsNotif.uuid)) {
196-
notifications.erase(ancsNotif.uuid);
197-
}
193+
if (ancsNotif.eventId == static_cast<uint8_t>(EventIds::Removed) && notifications.contains(ancsNotif.uuid)) {
194+
notifications.erase(ancsNotif.uuid);
198195
NRF_LOG_INFO("ANCS Notification removed: %d", ancsNotif.uuid);
199196
return;
200197
}
201198

202199
// If the notification is pre-existing, or if it is a silent notification, we do not add it to the list
203-
if (sessionNotificationUids.contains(ancsNotif.uuid)) {
200+
if (notifications.contains(ancsNotif.uuid) ||
201+
(ancsNotif.eventFlags & static_cast<uint8_t>(EventFlags::Silent)) != 0 ||
202+
(ancsNotif.eventFlags & static_cast<uint8_t>(EventFlags::PreExisting)) != 0) {
204203
return;
205204
}
206205

207-
// If new notification, add it to the sessionNotificationUids
206+
// If new notification, add it to the notifications
208207
if (ancsNotif.eventId == static_cast<uint8_t>(EventIds::Added) && (ancsNotif.eventFlags & static_cast<uint8_t>(EventFlags::Silent)) == 0) {
209-
sessionNotificationUids.insert({ancsNotif.uuid, false});
208+
notifications.insert({ancsNotif.uuid, ancsNotif});
210209
} else {
211210
// If the notification is not added, we ignore it
212211
NRF_LOG_INFO("ANCS Notification not added, ignoring: %d", ancsNotif.uuid);
213212
return;
214213
}
215214

216215
// The 6 is from TotalNbNotifications in NotificationManager.h + 1
217-
while (notifications.size() > 6) {
216+
while (notifications.size() > 100) {
218217
notifications.erase(notifications.begin());
219218
}
220219

221-
if (notifications.contains(ancsNotif.uuid)) {
222-
notifications[ancsNotif.uuid] = ancsNotif;
223-
} else {
224-
notifications.insert({ancsNotif.uuid, ancsNotif});
225-
}
220+
// if (notifications.contains(ancsNotif.uuid)) {
221+
// notifications[ancsNotif.uuid] = ancsNotif;
222+
// } else {
223+
// notifications.insert({ancsNotif.uuid, ancsNotif});
224+
// }
226225

227226
// Request ANCS more info
228227
// The +4 is for the "..." at the end of the string
@@ -262,8 +261,8 @@ void AppleNotificationCenterClient::OnNotification(ble_gap_event* event) {
262261
ancsNotif.uuid = 0;
263262

264263
// Check if the notification is in the session
265-
if (sessionNotificationUids.contains(notificationUid)) {
266-
if (sessionNotificationUids[notificationUid]) {
264+
if (notifications.contains(notificationUid)) {
265+
if (notifications[notificationUid].isProcessed) {
267266
// If the notification is already processed, we ignore it
268267
NRF_LOG_INFO("Notification with UID %d already processed, ignoring", notificationUid);
269268
return;
@@ -288,6 +287,9 @@ void AppleNotificationCenterClient::OnNotification(ble_gap_event* event) {
288287

289288
std::string decodedMessage = DecodeUtf8String(event->notify_rx.om, messageSize, 8 + titleSize + 1 + 2 + subTitleSize + 1 + 2);
290289

290+
//Debug event ids ands flags by putting them at front of message (in int format)
291+
//decodedMessage = std::to_string(ancsNotif.uuid) + " " + decodedMessage;
292+
291293
NRF_LOG_INFO("Decoded Title: %s", decodedTitle.c_str());
292294
NRF_LOG_INFO("Decoded SubTitle: %s", decodedSubTitle.c_str());
293295

@@ -363,13 +365,14 @@ void AppleNotificationCenterClient::OnNotification(ble_gap_event* event) {
363365
}
364366
notificationManager.Push(std::move(notif));
365367

366-
// Mark the notification as processed in the session
367-
sessionNotificationUids[notificationUid] = true;
368-
369-
// Only ping the system task if the notification was added
370-
if (ancsNotif.eventId == static_cast<uint8_t>(EventIds::Added) && (ancsNotif.eventFlags & static_cast<uint8_t>(EventFlags::Silent)) == 0) {
368+
// Only ping the system task if the notification was added and ignore pre-existing notifications
369+
if (ancsNotif.isProcessed == false && (ancsNotif.eventFlags & static_cast<uint8_t>(EventFlags::Silent)) == 0 &&
370+
(ancsNotif.eventFlags & static_cast<uint8_t>(EventFlags::PreExisting)) == 0) {
371371
systemTask.PushMessage(Pinetime::System::Messages::OnNewNotification);
372372
}
373+
374+
// Mark the notification as processed in the session
375+
notifications[notificationUid].isProcessed = true;
373376
}
374377
}
375378

@@ -441,7 +444,6 @@ void AppleNotificationCenterClient::Reset() {
441444
isDataDescriptorFound = false;
442445

443446
notifications.clear();
444-
sessionNotificationUids.clear();
445447
}
446448

447449
void AppleNotificationCenterClient::Discover(uint16_t connectionHandle, std::function<void(uint16_t)> onServiceDiscovered) {

src/components/ble/AppleNotificationCenterClient.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,6 @@ namespace Pinetime {
4545
static constexpr uint8_t maxSubtitleSize {15};
4646
static constexpr uint8_t maxMessageSize {120};
4747

48-
// Keep track of the ANCS UUIDs in array for this session to avoid re-pings for old notifications
49-
// Keep track of max notifications UUIDs at most
50-
static constexpr uint8_t maxNotifications {200};
51-
// make this unordered map have a boolean attached to see if data has been received for this notification
52-
std::unordered_map<uint32_t, bool> sessionNotificationUids {};
53-
5448
// The Apple Notification Center Service UUID are from https://developer.apple.com/library/archive/documentation/CoreBluetooth/Reference/AppleNotificationCenterServiceSpecification/Specification/Specification.html
5549

5650
// 7905F431-B5CE-4E99-A40F-4B1E122D00D0
@@ -105,6 +99,7 @@ namespace Pinetime {
10599
uint8_t eventFlags {0};
106100
uint8_t category {0};
107101
uint32_t uuid {0};
102+
bool isProcessed {false};
108103
};
109104

110105
std::unordered_map<uint32_t, AncsNotification> notifications;

0 commit comments

Comments
 (0)