Bangle.js: added missed call notification (#4686)

Add an option to receive missed call notifications. See [https://github.com/orgs/espruino/discussions/7718](https://github.com/orgs/espruino/discussions/7718)

Reviewed-on: https://codeberg.org/Freeyourgadget/Gadgetbridge/pulls/4686
Co-authored-by: umpfel <umpfel@noreply.codeberg.org>
Co-committed-by: umpfel <umpfel@noreply.codeberg.org>
This commit is contained in:
umpfel
2025-03-30 19:23:20 +00:00
committed by José Rebelo
parent c7fa48594a
commit 7af7c471da
5 changed files with 61 additions and 0 deletions
@@ -29,4 +29,6 @@ public final class BangleJSConstants {
public static final String PREF_BANGLEJS_ACTIVITY_FULL_SYNC_STATUS = "pref_banglejs_activity_full_sync_status";
public static final String PREF_BANGLEJS_ACTIVITY_FULL_SYNC_START = "pref_banglejs_activity_full_sync_start";
public static final String PREF_BANGLEJS_ACTIVITY_FULL_SYNC_STOP = "pref_banglejs_activity_full_sync_stop";
public static final String PREF_BANGLEJS_NOTIFICATION_MISSED_CALL_ENABLE = "pref_notification_enable_missed_call";
}
@@ -231,6 +231,7 @@ public class BangleJSCoordinator extends AbstractBLEDeviceCoordinator {
settings.add(R.xml.devicesettings_text_bitmaps);
settings.add(R.xml.devicesettings_transliteration);
settings.add(R.xml.devicesettings_canned_reply_16);
settings.add(R.xml.devicesettings_banglejs_notifications);
settings.add(R.xml.devicesettings_header_calendar);
settings.add(R.xml.devicesettings_sync_calendar);
@@ -31,6 +31,7 @@ import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.Dev
import static nodomain.freeyourgadget.gadgetbridge.database.DBHelper.getUser;
import static nodomain.freeyourgadget.gadgetbridge.devices.banglejs.BangleJSConstants.PREF_BANGLEJS_ACTIVITY_FULL_SYNC_START;
import static nodomain.freeyourgadget.gadgetbridge.devices.banglejs.BangleJSConstants.PREF_BANGLEJS_ACTIVITY_FULL_SYNC_STATUS;
import static nodomain.freeyourgadget.gadgetbridge.devices.banglejs.BangleJSConstants.PREF_BANGLEJS_NOTIFICATION_MISSED_CALL_ENABLE;
import android.bluetooth.BluetoothGatt;
import android.bluetooth.BluetoothGattCharacteristic;
@@ -48,6 +49,7 @@ import android.location.Location;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.util.Base64;
import android.widget.Toast;
@@ -174,6 +176,9 @@ public class BangleJSDeviceSupport extends AbstractBTLEDeviceSupport {
/// Last battery percentage reported (or -1) to help with smoothing reported battery levels
private int lastBatteryPercent = -1;
private boolean isMissedCall = false;
private final Handler handler = new Handler();
private final LimitedQueue<Integer, Long> mNotificationReplyAction = new LimitedQueue<>(16);
private boolean gpsUpdateSetup = false;
@@ -211,6 +216,7 @@ public class BangleJSDeviceSupport extends AbstractBTLEDeviceSupport {
stopGlobalUartReceiver();
stopLocationUpdate();
stopRequestQueue();
handler.removeCallbacksAndMessages(null);
}
private void stopGlobalUartReceiver(){
@@ -1573,6 +1579,46 @@ public class BangleJSDeviceSupport extends AbstractBTLEDeviceSupport {
@Override
public void onSetCallState(CallSpec callSpec) {
try {
final boolean enableMissedCall = GBApplication.getDeviceSpecificSharedPrefs(gbDevice.getAddress()).getBoolean(PREF_BANGLEJS_NOTIFICATION_MISSED_CALL_ENABLE, false);
switch (callSpec.command) {
case CallSpec.CALL_INCOMING:
// possible missed call
isMissedCall = true;
break;
case CallSpec.CALL_END:
if (isMissedCall) {
LOG.info("Missed call");
isMissedCall = false;
if (enableMissedCall) {
NotificationSpec notificationSpec = new NotificationSpec();
notificationSpec.sourceName = getContext().getString(R.string.banglejs_notification_missed_call_source);
notificationSpec.title = getContext().getString(R.string.banglejs_notification_missed_call_title);
notificationSpec.subject = getContext().getString(R.string.banglejs_notification_missed_call_title);
if (callSpec.name == null && callSpec.number == null) {
notificationSpec.body = getContext().getString(R.string.banglejs_notification_missed_call_suppressed_caller_id);
}else if (callSpec.name == null) {
notificationSpec.sender = callSpec.number;
notificationSpec.body = callSpec.number;
notificationSpec.phoneNumber = callSpec.number;
} else {
notificationSpec.sender = callSpec.name;
notificationSpec.body = callSpec.name + "\n" + callSpec.number;
notificationSpec.phoneNumber = callSpec.number;
}
handler.postDelayed(() -> {
onNotification(notificationSpec);
}, 1000L);
} else {
LOG.info("Ignoring missed call");
}
}
break;
default:
isMissedCall = false;
break;
}
JSONObject o = new JSONObject();
o.put("t", "call");
String cmdName = "";
+3
View File
@@ -3768,4 +3768,7 @@
<string name="huawei_stress_calibrate_again">Calibrate again</string>
<string name="huawei_stress_calibrate_adjust_score">Adjust score</string>
<string name="banglejs_notification_missed_call_title">Missed call</string>
<string name="banglejs_notification_missed_call_source">Incoming call</string>
<string name="banglejs_notification_missed_call_suppressed_caller_id">Unknown caller. ID is suppressed</string>
</resources>
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<SwitchPreferenceCompat
android:defaultValue="false"
android:icon="@drawable/ic_phone"
android:key="pref_notification_enable_missed_call"
android:layout="@layout/preference_checkbox"
android:title="@string/pref_notifications_and_calls_enable_misscall" />
</androidx.preference.PreferenceScreen>