2015-04-20 22:39:35 +02:00
|
|
|
package nodomain.freeyourgadget.gadgetbridge.externalevents;
|
2015-01-24 12:21:15 +01:00
|
|
|
|
|
|
|
import android.content.BroadcastReceiver;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.os.Bundle;
|
2015-03-04 23:47:47 +01:00
|
|
|
import android.os.PowerManager;
|
2015-01-24 12:21:15 +01:00
|
|
|
import android.telephony.SmsMessage;
|
|
|
|
|
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-04-20 22:39:35 +02:00
|
|
|
|
2015-01-24 12:21:15 +01:00
|
|
|
public class SMSReceiver extends BroadcastReceiver {
|
|
|
|
|
|
|
|
@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_sms", "when_screen_off"))) {
|
2015-03-04 23:47:47 +01:00
|
|
|
return;
|
|
|
|
}
|
2016-04-25 23:18:55 +02:00
|
|
|
if ("when_screen_off".equals(prefs.getString("notification_mode_sms", "when_screen_off"))) {
|
2015-05-04 01:03:56 +02:00
|
|
|
PowerManager powermanager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
|
2015-03-06 14:00:56 +01:00
|
|
|
if (powermanager.isScreenOn()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2015-03-04 23:47:47 +01:00
|
|
|
|
2015-09-24 14:45:21 +02:00
|
|
|
NotificationSpec notificationSpec = new NotificationSpec();
|
|
|
|
notificationSpec.id = -1;
|
|
|
|
notificationSpec.type = NotificationType.SMS;
|
|
|
|
|
2015-01-24 12:21:15 +01:00
|
|
|
Bundle bundle = intent.getExtras();
|
|
|
|
if (bundle != null) {
|
|
|
|
Object[] pdus = (Object[]) bundle.get("pdus");
|
2015-11-23 21:59:13 +01:00
|
|
|
if (pdus != null) {
|
|
|
|
for (Object pdu1 : pdus) {
|
|
|
|
byte[] pdu = (byte[]) pdu1;
|
|
|
|
SmsMessage message = SmsMessage.createFromPdu(pdu);
|
|
|
|
notificationSpec.body = message.getDisplayMessageBody();
|
|
|
|
notificationSpec.phoneNumber = message.getOriginatingAddress();
|
|
|
|
if (notificationSpec.phoneNumber != null) {
|
|
|
|
GBApplication.deviceService().onNotification(notificationSpec);
|
|
|
|
}
|
2015-01-24 12:21:15 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|