mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-07-08 22:51:37 +02:00
7c597b325a
- model package contains mostly shared interfaces (UI+service), not named GB* - impl package contains implementations of those interfaces, named GB* the impl classes should not be used by the service (not completely done) - the service classes should mostly use classes inside the service and deviceevents packages (tbd) Every device now has two packages: - devices/[device name] for UI related functionality - service[device name] for lowlevel communication
49 lines
2.0 KiB
Java
49 lines
2.0 KiB
Java
package nodomain.freeyourgadget.gadgetbridge.externalevents;
|
|
|
|
import android.content.BroadcastReceiver;
|
|
import android.content.Context;
|
|
import android.content.Intent;
|
|
import android.content.SharedPreferences;
|
|
import android.os.Bundle;
|
|
import android.os.PowerManager;
|
|
import android.preference.PreferenceManager;
|
|
import android.telephony.SmsMessage;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.service.BluetoothCommunicationService;
|
|
|
|
public class SMSReceiver extends BroadcastReceiver {
|
|
|
|
@Override
|
|
public void onReceive(Context context, Intent intent) {
|
|
|
|
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context);
|
|
if ("never".equals(sharedPrefs.getString("notification_mode_sms", "when_screen_off"))) {
|
|
return;
|
|
}
|
|
if ("when_screen_off".equals(sharedPrefs.getString("notification_mode_sms", "when_screen_off"))) {
|
|
PowerManager powermanager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
|
|
if (powermanager.isScreenOn()) {
|
|
return;
|
|
}
|
|
}
|
|
|
|
Bundle bundle = intent.getExtras();
|
|
if (bundle != null) {
|
|
Object[] pdus = (Object[]) bundle.get("pdus");
|
|
for (Object pdu1 : pdus) {
|
|
byte[] pdu = (byte[]) pdu1;
|
|
SmsMessage message = SmsMessage.createFromPdu(pdu);
|
|
String body = message.getDisplayMessageBody();
|
|
String sender = message.getOriginatingAddress();
|
|
if (sender != null && body != null) {
|
|
Intent startIntent = new Intent(context, BluetoothCommunicationService.class);
|
|
startIntent.setAction(BluetoothCommunicationService.ACTION_NOTIFICATION_SMS);
|
|
startIntent.putExtra("notification_sender", sender);
|
|
startIntent.putExtra("notification_body", body);
|
|
context.startService(startIntent);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|