@@ -46,20 +46,17 @@ bool AppleNotificationCenterClient::OnDiscoveryEvent(uint16_t connectionHandle,
46
46
if (service == nullptr && error->status == BLE_HS_EDONE) {
47
47
if (isDiscovered) {
48
48
NRF_LOG_INFO (" ANCS Discovery found, starting characteristics discovery" );
49
- // DebugNotification("ANCS Discovery found, starting characteristics discovery");
50
-
51
49
ble_gattc_disc_all_chrs (connectionHandle, ancsStartHandle, ancsEndHandle, OnANCSCharacteristicDiscoveredCallback, this );
52
50
} else {
53
51
NRF_LOG_INFO (" ANCS not found" );
54
- // DebugNotification("ANCS not found");
55
52
onServiceDiscovered (connectionHandle);
56
53
}
57
54
return true ;
58
55
}
59
56
60
57
if (service != nullptr && ble_uuid_cmp (&ancsUuid.u , &service->uuid .u ) == 0 ) {
61
58
NRF_LOG_INFO (" ANCS discovered : 0x%x - 0x%x" , service->start_handle , service->end_handle );
62
- // DebugNotification("ANCS discovered");
59
+
63
60
ancsStartHandle = service->start_handle ;
64
61
ancsEndHandle = service->end_handle ;
65
62
isDiscovered = true ;
@@ -72,19 +69,16 @@ int AppleNotificationCenterClient::OnCharacteristicsDiscoveryEvent(uint16_t conn
72
69
const ble_gatt_chr* characteristic) {
73
70
if (error->status != 0 && error->status != BLE_HS_EDONE) {
74
71
NRF_LOG_INFO (" ANCS Characteristic discovery ERROR" );
75
- // DebugNotification("ANCS Characteristic discovery ERROR");
76
72
onServiceDiscovered (connectionHandle);
77
73
return 0 ;
78
74
}
79
75
80
76
if (characteristic == nullptr && error->status == BLE_HS_EDONE) {
81
77
NRF_LOG_INFO (" ANCS Characteristic discovery complete" );
82
- // DebugNotification("ANCS Characteristic discovery complete");
83
78
if (isCharacteristicDiscovered) {
84
79
ble_gattc_disc_all_dscs (connectionHandle, notificationSourceHandle, ancsEndHandle, OnANCSDescriptorDiscoveryEventCallback, this );
85
80
}
86
81
if (isDataCharacteristicDiscovered) {
87
- // DebugNotification("ANCS Characteristic discovery complete: Data Source");
88
82
ble_gattc_disc_all_dscs (connectionHandle, dataSourceHandle, ancsEndHandle, OnANCSDescriptorDiscoveryEventCallback, this );
89
83
}
90
84
if (isCharacteristicDiscovered == isControlCharacteristicDiscovered && isCharacteristicDiscovered == isDataCharacteristicDiscovered) {
@@ -94,19 +88,16 @@ int AppleNotificationCenterClient::OnCharacteristicsDiscoveryEvent(uint16_t conn
94
88
if (characteristic != nullptr ) {
95
89
if (ble_uuid_cmp (¬ificationSourceChar.u , &characteristic->uuid .u ) == 0 ) {
96
90
NRF_LOG_INFO (" ANCS Characteristic discovered: Notification Source" );
97
- // DebugNotification("ANCS Characteristic discovered: Notification Source");
98
91
notificationSourceHandle = characteristic->val_handle ;
99
92
isCharacteristicDiscovered = true ;
100
93
} else if (ble_uuid_cmp (&controlPointChar.u , &characteristic->uuid .u ) == 0 ) {
101
94
NRF_LOG_INFO (" ANCS Characteristic discovered: Control Point" );
102
- // DebugNotification("ANCS Characteristic discovered: Control Point");
103
95
controlPointHandle = characteristic->val_handle ;
104
96
isControlCharacteristicDiscovered = true ;
105
97
} else if (ble_uuid_cmp (&dataSourceChar.u , &characteristic->uuid .u ) == 0 ) {
106
98
char msg[55 ];
107
99
snprintf (msg, sizeof (msg), " ANCS Characteristic discovered: Data Source\n %d" , characteristic->val_handle );
108
100
NRF_LOG_INFO (msg);
109
- // DebugNotification(msg);
110
101
dataSourceHandle = characteristic->val_handle ;
111
102
isDataCharacteristicDiscovered = true ;
112
103
}
@@ -123,7 +114,6 @@ int AppleNotificationCenterClient::OnDescriptorDiscoveryEventCallback(uint16_t c
123
114
if (characteristicValueHandle == notificationSourceHandle && ble_uuid_cmp (¬ificationSourceChar.u , &descriptor->uuid .u )) {
124
115
if (notificationSourceDescriptorHandle == 0 ) {
125
116
NRF_LOG_INFO (" ANCS Descriptor discovered : %d" , descriptor->handle );
126
- // DebugNotification("ANCS Descriptor discovered");
127
117
notificationSourceDescriptorHandle = descriptor->handle ;
128
118
isDescriptorFound = true ;
129
119
uint8_t value[2 ] {1 , 0 };
@@ -133,14 +123,12 @@ int AppleNotificationCenterClient::OnDescriptorDiscoveryEventCallback(uint16_t c
133
123
} else if (characteristicValueHandle == controlPointHandle && ble_uuid_cmp (&controlPointChar.u , &descriptor->uuid .u )) {
134
124
if (controlPointDescriptorHandle == 0 ) {
135
125
NRF_LOG_INFO (" ANCS Descriptor discovered : %d" , descriptor->handle );
136
- // DebugNotification("ANCS Descriptor discovered");
137
126
controlPointDescriptorHandle = descriptor->handle ;
138
127
isControlDescriptorFound = true ;
139
128
}
140
129
} else if (characteristicValueHandle == dataSourceHandle && ble_uuid_cmp (&dataSourceChar.u , &descriptor->uuid .u )) {
141
130
if (dataSourceDescriptorHandle == 0 ) {
142
131
NRF_LOG_INFO (" ANCS Descriptor discovered : %d" , descriptor->handle );
143
- // DebugNotification("ANCS Descriptor discovered: Data Source");
144
132
dataSourceDescriptorHandle = descriptor->handle ;
145
133
isDataDescriptorFound = true ;
146
134
uint8_t value[2 ] {1 , 0 };
@@ -152,7 +140,6 @@ int AppleNotificationCenterClient::OnDescriptorDiscoveryEventCallback(uint16_t c
152
140
char errorStr[55 ];
153
141
snprintf (errorStr, sizeof (errorStr), " ANCS Descriptor discovery ERROR: %d" , error->status );
154
142
NRF_LOG_INFO (errorStr);
155
- // DebugNotification(errorStr);
156
143
}
157
144
if (isDescriptorFound == isDataDescriptorFound)
158
145
onServiceDiscovered (connectionHandle);
@@ -165,10 +152,8 @@ int AppleNotificationCenterClient::OnNewAlertSubcribe(uint16_t connectionHandle,
165
152
ble_gatt_attr* /* attribute*/ ) {
166
153
if (error->status == 0 ) {
167
154
NRF_LOG_INFO (" ANCS New alert subscribe OK" );
168
- // DebugNotification("ANCS New alert subscribe OK");
169
155
} else {
170
156
NRF_LOG_INFO (" ANCS New alert subscribe ERROR" );
171
- // DebugNotification("ANCS New alert subscribe ERROR");
172
157
}
173
158
if (isDescriptorFound == isControlDescriptorFound && isDescriptorFound == isDataDescriptorFound)
174
159
onServiceDiscovered (connectionHandle);
@@ -181,12 +166,10 @@ int AppleNotificationCenterClient::OnControlPointWrite(uint16_t /*connectionHand
181
166
ble_gatt_attr* /* attribute*/ ) {
182
167
if (error->status == 0 ) {
183
168
NRF_LOG_INFO (" ANCS Control Point write OK" );
184
- // DebugNotification("ANCS Control Point write OK");
185
169
} else {
186
170
char errorStr[55 ];
187
171
snprintf (errorStr, sizeof (errorStr), " ANCS Control Point ERROR: %d" , error->status );
188
172
NRF_LOG_INFO (errorStr);
189
- // DebugNotification(errorStr);
190
173
}
191
174
return 0 ;
192
175
}
@@ -212,7 +195,7 @@ void AppleNotificationCenterClient::OnNotification(ble_gap_event* event) {
212
195
// bool positiveAction = eventFlags & static_cast<uint8_t>(EventFlags::PositiveAction);
213
196
// bool negativeAction = eventFlags & static_cast<uint8_t>(EventFlags::NegativeAction);
214
197
215
- AncsNotitfication ancsNotif;
198
+ AncsNotification ancsNotif;
216
199
ancsNotif.eventId = eventId;
217
200
ancsNotif.eventFlags = eventFlags;
218
201
ancsNotif.category = category;
@@ -254,20 +237,6 @@ void AppleNotificationCenterClient::OnNotification(ble_gap_event* event) {
254
237
request[13 ] = ((messageSize >> 8 ) & 0xFF );
255
238
256
239
ble_gattc_write_flat (event->notify_rx .conn_handle , controlPointHandle, request, sizeof (request), OnControlPointWriteCallback, this );
257
-
258
- // NotificationManager::Notification notif;
259
- // char uuidStr[55];
260
- // snprintf(uuidStr, sizeof(uuidStr), "iOS Notif.:%08lx\nEvID: %d\nCat: %d\nFlags: %d", notificationUuid, eventId, category, eventFlags);
261
- // notif.message = std::array<char, 101> {};
262
- // std::strncpy(notif.message.data(), uuidStr, notif.message.size() - 1);
263
- // notif.message[10] = '\0'; // Seperate Title and Message
264
- // notif.message[notif.message.size() - 1] = '\0'; // Ensure null-termination
265
- // notif.size = std::min(std::strlen(uuidStr), notif.message.size());
266
- // notif.category = Pinetime::Controllers::NotificationManager::Categories::SimpleAlert;
267
- // notificationManager.Push(std::move(notif));
268
-
269
- // systemTask.PushMessage(Pinetime::System::Messages::OnNewNotification);
270
- // DebugNotification("ANCS Notification received");
271
240
} else if (event->notify_rx .attr_handle == dataSourceHandle || event->notify_rx .attr_handle == dataSourceDescriptorHandle) {
272
241
uint16_t titleSize;
273
242
uint16_t subTitleSize;
@@ -279,7 +248,7 @@ void AppleNotificationCenterClient::OnNotification(ble_gap_event* event) {
279
248
os_mbuf_copydata (event->notify_rx .om , 8 + titleSize + 1 , 2 , &subTitleSize);
280
249
os_mbuf_copydata (event->notify_rx .om , 8 + titleSize + 1 + 2 + subTitleSize + 1 , 2 , &messageSize);
281
250
282
- AncsNotitfication ancsNotif;
251
+ AncsNotification ancsNotif;
283
252
ancsNotif.uuid = 0 ;
284
253
285
254
if (notifications.contains (notificationUid)) {
@@ -294,8 +263,6 @@ void AppleNotificationCenterClient::OnNotification(ble_gap_event* event) {
294
263
295
264
NRF_LOG_INFO (" Decoded Title: %s" , decodedTitle.c_str ());
296
265
NRF_LOG_INFO (" Decoded SubTitle: %s" , decodedSubTitle.c_str ());
297
- // DebugNotification(decodedTitle.c_str());
298
- // DebugNotification("ANCS Data Source received");
299
266
300
267
bool incomingCall = ancsNotif.uuid != 0 && ancsNotif.category == static_cast <uint8_t >(Categories::IncomingCall);
301
268
@@ -333,7 +300,6 @@ void AppleNotificationCenterClient::OnNotification(ble_gap_event* event) {
333
300
334
301
NotificationManager::Notification notif;
335
302
notif.ancsUid = notificationUid;
336
- // std::string notifStr = "iOS Notif.:" + decodedTitle + "\n" + decodedSubTitle;
337
303
std::string notifStr;
338
304
339
305
if (incomingCall) {
@@ -359,11 +325,11 @@ void AppleNotificationCenterClient::OnNotification(ble_gap_event* event) {
359
325
std::strncpy (notif.message .data (), notifStr.c_str (), notif.message .size () - 1 );
360
326
361
327
if (incomingCall)
362
- notif.message [13 ] = ' \0 ' ; // Seperate Title and Message
328
+ notif.message [13 ] = ' \0 ' ; // Separate Title and Message
363
329
else if (!decodedSubTitle.empty ())
364
- notif.message [titleSize + subTitleSize] = ' \0 ' ; // Seperate Title and Message
330
+ notif.message [titleSize + subTitleSize] = ' \0 ' ; // Separate Title and Message
365
331
else
366
- notif.message [titleSize - 1 ] = ' \0 ' ; // Seperate Title and Message
332
+ notif.message [titleSize - 1 ] = ' \0 ' ; // Separate Title and Message
367
333
368
334
notif.message [notif.message .size () - 1 ] = ' \0 ' ; // Ensure null-termination
369
335
notif.size = std::min (std::strlen (notifStr.c_str ()), notif.message .size ());
@@ -379,7 +345,7 @@ void AppleNotificationCenterClient::OnNotification(ble_gap_event* event) {
379
345
}
380
346
381
347
void AppleNotificationCenterClient::AcceptIncomingCall (uint32_t uuid) {
382
- AncsNotitfication ancsNotif;
348
+ AncsNotification ancsNotif;
383
349
if (notifications.contains (uuid)) {
384
350
ancsNotif = notifications[uuid];
385
351
if (ancsNotif.category != static_cast <uint8_t >(Categories::IncomingCall)) {
@@ -401,7 +367,7 @@ void AppleNotificationCenterClient::AcceptIncomingCall(uint32_t uuid) {
401
367
}
402
368
403
369
void AppleNotificationCenterClient::RejectIncomingCall (uint32_t uuid) {
404
- AncsNotitfication ancsNotif;
370
+ AncsNotification ancsNotif;
405
371
if (notifications.contains (uuid)) {
406
372
ancsNotif = notifications[uuid];
407
373
if (ancsNotif.category != static_cast <uint8_t >(Categories::IncomingCall)) {
@@ -451,7 +417,6 @@ void AppleNotificationCenterClient::Reset() {
451
417
452
418
void AppleNotificationCenterClient::Discover (uint16_t connectionHandle, std::function<void (uint16_t )> onServiceDiscovered) {
453
419
NRF_LOG_INFO (" [ANCS] Starting discovery" );
454
- // DebugNotification("[ANCS] Starting discovery");
455
420
this ->onServiceDiscovered = onServiceDiscovered;
456
421
ble_gattc_disc_svc_by_uuid (connectionHandle, &ancsUuid.u , OnDiscoveryEventCallback, this );
457
422
}
0 commit comments