2020-01-09 10:44:32 +01:00
|
|
|
/* Copyright (C) 2015-2020 Andreas Shimokawa, Carsten Pfeiffer, Daniele
|
2018-06-25 18:35:46 +02:00
|
|
|
Gobbetti
|
2017-03-10 14:53:19 +01:00
|
|
|
|
|
|
|
This file is part of Gadgetbridge.
|
|
|
|
|
|
|
|
Gadgetbridge is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU Affero General Public License as published
|
|
|
|
by the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
Gadgetbridge is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU Affero General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Affero General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
2015-05-04 01:03:56 +02:00
|
|
|
package nodomain.freeyourgadget.gadgetbridge.externalevents;
|
|
|
|
|
|
|
|
import android.content.BroadcastReceiver;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.os.PowerManager;
|
2015-05-12 06:28:11 +02:00
|
|
|
|
2015-05-04 01:03:56 +02:00
|
|
|
import org.json.JSONArray;
|
|
|
|
import org.json.JSONException;
|
2015-05-18 20:56:19 +02:00
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
2015-05-04 01:03:56 +02:00
|
|
|
|
2015-08-21 00:58:18 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
2015-09-24 14:45:21 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.model.NotificationSpec;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.model.NotificationType;
|
2016-04-25 23:18:55 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.util.Prefs;
|
2015-05-04 01:03:56 +02:00
|
|
|
|
|
|
|
public class PebbleReceiver extends BroadcastReceiver {
|
|
|
|
|
2015-05-12 06:28:11 +02:00
|
|
|
private static final Logger LOG = LoggerFactory.getLogger(PebbleReceiver.class);
|
2015-05-04 01:03:56 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onReceive(Context context, Intent intent) {
|
|
|
|
|
2016-04-25 23:18:55 +02:00
|
|
|
Prefs prefs = GBApplication.getPrefs();
|
|
|
|
if ("never".equals(prefs.getString("notification_mode_pebblemsg", "when_screen_off"))) {
|
2015-05-04 01:03:56 +02:00
|
|
|
return;
|
|
|
|
}
|
2016-04-25 23:18:55 +02:00
|
|
|
if ("when_screen_off".equals(prefs.getString("notification_mode_pebblemsg", "when_screen_off"))) {
|
2015-05-04 01:03:56 +02:00
|
|
|
PowerManager powermanager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
|
|
|
|
if (powermanager.isScreenOn()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
String messageType = intent.getStringExtra("messageType");
|
|
|
|
if (!messageType.equals("PEBBLE_ALERT")) {
|
2015-05-12 06:28:11 +02:00
|
|
|
LOG.info("non PEBBLE_ALERT message type not supported");
|
2015-05-04 01:03:56 +02:00
|
|
|
return;
|
|
|
|
}
|
2015-08-31 17:31:32 +02:00
|
|
|
|
|
|
|
if (!intent.hasExtra("notificationData")) {
|
|
|
|
LOG.info("missing notificationData extra");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-09-24 14:45:21 +02:00
|
|
|
NotificationSpec notificationSpec = new NotificationSpec();
|
2015-09-17 23:08:05 +02:00
|
|
|
|
2015-05-04 01:03:56 +02:00
|
|
|
String notificationData = intent.getStringExtra("notificationData");
|
|
|
|
try {
|
|
|
|
JSONArray notificationJSON = new JSONArray(notificationData);
|
2015-09-24 14:45:21 +02:00
|
|
|
notificationSpec.title = notificationJSON.getJSONObject(0).getString("title");
|
|
|
|
notificationSpec.body = notificationJSON.getJSONObject(0).getString("body");
|
2015-05-04 01:03:56 +02:00
|
|
|
} catch (JSONException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-09-24 14:45:21 +02:00
|
|
|
if (notificationSpec.title != null) {
|
2016-10-10 23:06:44 +02:00
|
|
|
notificationSpec.type = NotificationType.UNKNOWN;
|
2015-09-17 23:08:05 +02:00
|
|
|
String sender = intent.getStringExtra("sender");
|
2021-09-26 21:59:11 +02:00
|
|
|
if (GBApplication.getPrefs().getString("notification_list_is_blacklist", "true").equals("true")) {
|
|
|
|
if (GBApplication.appIsPebbleBlacklisted(sender)) {
|
|
|
|
LOG.info("Ignoring Pebble message, application " + sender + " is blacklisted");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (!GBApplication.appIsPebbleBlacklisted(sender)) {
|
|
|
|
LOG.info("Ignoring Pebble message, application " + sender + " is not whitelisted");
|
|
|
|
return;
|
|
|
|
}
|
2018-06-18 20:38:37 +02:00
|
|
|
}
|
|
|
|
|
2015-09-17 23:08:05 +02:00
|
|
|
if ("Conversations".equals(sender)) {
|
2016-10-11 11:54:52 +02:00
|
|
|
notificationSpec.type = NotificationType.CONVERSATIONS;
|
|
|
|
}
|
|
|
|
else if ("OsmAnd".equals(sender)) {
|
|
|
|
notificationSpec.type = NotificationType.GENERIC_NAVIGATION;
|
2015-09-17 23:08:05 +02:00
|
|
|
}
|
2015-09-24 14:45:21 +02:00
|
|
|
GBApplication.deviceService().onNotification(notificationSpec);
|
2015-05-04 01:03:56 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|