Huawei: Fix notifications handling without key

This commit is contained in:
Me7c7 2025-01-05 14:41:27 +02:00
parent 87871a46e7
commit 4ccf68af0a
3 changed files with 13 additions and 10 deletions

View File

@ -55,7 +55,6 @@ import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

View File

@ -42,6 +42,12 @@ public class HuaweiNotificationsManager {
notificationSpecCache.offer(notificationSpec);
}
public static String getNotificationKey(NotificationSpec notificationSpec) {
if(!TextUtils.isEmpty(notificationSpec.key)) {
return notificationSpec.key;
}
return "0|" + notificationSpec.sourceAppId + "|" + notificationSpec.getId() + "||0";
}
public void onNotification(NotificationSpec notificationSpec) {
@ -79,7 +85,7 @@ public class HuaweiNotificationsManager {
SendNotificationRemoveRequest sendNotificationReq = new SendNotificationRemoveRequest(this.support,
SendNotificationRequest.getNotificationType(notificationSpec.type), // notificationType
notificationSpec.sourceAppId,
notificationSpec.key,
getNotificationKey(notificationSpec),
id,
notificationSpec.channelId,
notificationSpec.category);
@ -105,8 +111,8 @@ public class HuaweiNotificationsManager {
}
NotificationSpec notificationSpec = null;
for (NotificationSpec spec : notificationSpecCache) {
notificationSpec = spec;
if (notificationSpec.key.equals(response.key)) {
if (getNotificationKey(spec).equals(response.key)) {
notificationSpec = spec;
break;
}
}

View File

@ -16,7 +16,7 @@
along with this program. If not, see <https://www.gnu.org/licenses/>. */
package nodomain.freeyourgadget.gadgetbridge.service.devices.huawei.requests;
import android.text.TextUtils;
import static nodomain.freeyourgadget.gadgetbridge.service.devices.huawei.HuaweiNotificationsManager.getNotificationKey;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -31,7 +31,6 @@ import nodomain.freeyourgadget.gadgetbridge.model.NotificationType;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huawei.HuaweiSupportProvider;
public class SendNotificationRequest extends Request {
private static final Logger LOG = LoggerFactory.getLogger(SendNotificationRequest.class);
private HuaweiPacket packet;
@ -54,8 +53,7 @@ public class SendNotificationRequest extends Request {
return Notifications.NotificationType.sms;
}
}
public void buildNotificationTLVFromNotificationSpec(NotificationSpec notificationSpec) {
String title;
if (notificationSpec.title != null)
@ -76,7 +74,7 @@ public class SendNotificationRequest extends Request {
final NotificationSpec.Action action = notificationSpec.attachedActions.get(i);
if (action.type == NotificationSpec.Action.TYPE_WEARABLE_REPLY || action.type == NotificationSpec.Action.TYPE_SYNTECTIC_REPLY_PHONENR) {
//NOTE: store notification key instead action key. The watch returns this key so it is more easier to find action by notification key
replyKey = notificationSpec.key;
replyKey = getNotificationKey(notificationSpec);
break;
}
}
@ -91,7 +89,7 @@ public class SendNotificationRequest extends Request {
params.supportsTimestamp = supportProvider.getHuaweiCoordinator().supportsNotificationsTimestamp();
params.notificationId = notificationSpec.getId();
params.notificationKey = notificationSpec.key;
params.notificationKey = getNotificationKey(notificationSpec);
params.replyKey = replyKey;
params.channelId = notificationSpec.channelId;
params.category = notificationSpec.category;