mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-07-23 23:32:23 +02:00
a1cb246e27
Previously, the DeviceCommunicationService was invoked directly, via Intent intent = new Intent(foo, bar); intent.setExtra(EXTRA_BAZ, baz); startService(...); and this was scattered throughout GadgetBridge. Now there is a "frontend" available, so that you can call the service more easily, like GBApplication.deviceService().connect(); For a start, this client interface (DeviceService) actually implements the same interface (EventHandler) as the receiving side (DeviceSupport). This may change in the future. This will also make testing much easier, because we can use this client interface to invoke the test service as well.
45 lines
1.6 KiB
Java
45 lines
1.6 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.GBApplication;
|
|
|
|
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) {
|
|
GBApplication.deviceService().onSMS(sender, body);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|