2024-01-10 18:54:00 +01:00
|
|
|
/* Copyright (C) 2015-2024 Andreas Böhler, Andreas Shimokawa, Arjan
|
|
|
|
Schrijver, Avamander, Carsten Pfeiffer, Daniel Dakhno, Daniele Gobbetti,
|
|
|
|
Daniel Hauck, Davis Mosenkovs, Dikay900, Dmitriy Bogdanov, Frank Slezak,
|
|
|
|
Gabriele Monaco, Gordon Williams, ivanovlev, João Paulo Barraca, José
|
|
|
|
Rebelo, Julien Pivotto, Kasha, keeshii, Martin, Matthieu Baerts, mvn23,
|
|
|
|
NekoBox, Nephiel, Petr Vaněk, Sebastian Kranz, Sergey Trofimov, Steffen
|
|
|
|
Liebergeld, Taavi Eomäe, TylerWilliamson, Uwe Hermann, Yoran Vulker
|
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
|
2024-01-10 18:54:00 +01:00
|
|
|
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
2015-08-03 23:09:49 +02:00
|
|
|
package nodomain.freeyourgadget.gadgetbridge.service;
|
2015-01-12 00:35:15 +01:00
|
|
|
|
2023-12-08 13:12:35 +01:00
|
|
|
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.*;
|
|
|
|
|
2017-05-09 12:32:00 +02:00
|
|
|
import android.Manifest;
|
2017-04-21 22:21:24 +02:00
|
|
|
import android.annotation.SuppressLint;
|
2015-01-12 00:35:15 +01:00
|
|
|
import android.app.Service;
|
2016-05-22 01:19:28 +02:00
|
|
|
import android.bluetooth.BluetoothDevice;
|
2015-04-19 14:34:18 +02:00
|
|
|
import android.content.BroadcastReceiver;
|
2015-02-06 13:55:44 +01:00
|
|
|
import android.content.Context;
|
2015-01-12 00:35:15 +01:00
|
|
|
import android.content.Intent;
|
2015-04-19 14:34:18 +02:00
|
|
|
import android.content.IntentFilter;
|
2016-04-28 23:17:13 +02:00
|
|
|
import android.content.SharedPreferences;
|
2017-05-09 12:32:00 +02:00
|
|
|
import android.content.pm.PackageManager;
|
2022-06-04 22:20:28 +02:00
|
|
|
import android.location.Location;
|
2023-12-11 11:50:31 +01:00
|
|
|
import android.media.AudioManager;
|
2015-01-23 11:32:58 +01:00
|
|
|
import android.net.Uri;
|
2022-09-04 23:05:57 +02:00
|
|
|
import android.os.Bundle;
|
2017-12-17 22:35:17 +01:00
|
|
|
import android.os.Handler;
|
2015-01-12 00:35:15 +01:00
|
|
|
import android.os.IBinder;
|
|
|
|
import android.widget.Toast;
|
2015-04-19 15:27:16 +02:00
|
|
|
|
2019-08-22 21:31:08 +02:00
|
|
|
import androidx.annotation.Nullable;
|
|
|
|
import androidx.core.content.ContextCompat;
|
|
|
|
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
|
|
|
|
|
2015-05-12 06:28:11 +02:00
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
2015-06-25 14:34:21 +02:00
|
|
|
import java.util.ArrayList;
|
2024-01-04 17:48:26 +01:00
|
|
|
import java.util.Collections;
|
2023-03-31 21:07:56 +02:00
|
|
|
import java.util.HashMap;
|
2024-01-04 17:48:26 +01:00
|
|
|
import java.util.HashSet;
|
2022-06-15 01:54:44 +02:00
|
|
|
import java.util.List;
|
2024-01-04 17:48:26 +01:00
|
|
|
import java.util.Set;
|
2015-05-18 20:56:19 +02:00
|
|
|
import java.util.UUID;
|
|
|
|
|
2015-12-14 23:31:31 +01:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
2022-06-14 18:05:41 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.GBException;
|
2015-08-04 01:01:14 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.R;
|
2018-08-16 13:13:12 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.activities.HeartRateUtils;
|
2023-07-04 00:19:19 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.capabilities.loyaltycards.LoyaltyCard;
|
2017-04-19 21:51:23 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.devices.DeviceCoordinator;
|
2017-02-07 23:49:10 +01:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.externalevents.AlarmClockReceiver;
|
2016-05-24 11:19:57 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.externalevents.AlarmReceiver;
|
2016-05-22 01:19:28 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.externalevents.BluetoothConnectReceiver;
|
2017-04-18 11:47:28 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.externalevents.BluetoothPairingRequestReceiver;
|
2017-12-11 19:09:37 +01:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.externalevents.CMWeatherReceiver;
|
2017-04-24 12:39:40 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.externalevents.CalendarReceiver;
|
2022-09-17 16:23:10 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.externalevents.DeviceSettingsReceiver;
|
2022-08-22 02:30:13 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.externalevents.GenericWeatherReceiver;
|
2022-10-29 01:28:45 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.externalevents.IntentApiReceiver;
|
2019-08-22 17:57:26 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.externalevents.LineageOsWeatherReceiver;
|
2015-10-15 17:23:16 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.externalevents.MusicPlaybackReceiver;
|
2017-12-17 22:35:17 +01:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.externalevents.OmniJawsObserver;
|
2021-10-19 14:32:20 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.externalevents.OsmandEventReceiver;
|
2015-10-15 17:23:16 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.externalevents.PebbleReceiver;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.externalevents.PhoneCallReceiver;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.externalevents.SMSReceiver;
|
2023-12-11 11:50:31 +01:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.externalevents.SilentModeReceiver;
|
2015-10-15 17:23:16 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.externalevents.TimeChangeReceiver;
|
2020-07-05 21:54:10 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.externalevents.TinyWeatherForecastGermanyReceiver;
|
2015-08-03 23:09:49 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
2021-03-21 19:46:30 +01:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.impl.GBDeviceService;
|
2015-08-03 23:09:49 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.model.Alarm;
|
2016-05-16 17:30:11 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.model.CalendarEventSpec;
|
2016-04-04 20:08:34 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.model.CallSpec;
|
2016-06-24 10:25:08 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.model.CannedMessagesSpec;
|
2023-05-18 00:43:29 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.model.Contact;
|
2016-04-04 20:08:34 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.model.MusicSpec;
|
2016-06-08 20:27:25 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.model.MusicStateSpec;
|
2021-10-20 22:37:23 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.model.NavigationInfoSpec;
|
2015-09-24 14:45:21 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.model.NotificationSpec;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.model.NotificationType;
|
2021-12-04 16:55:09 +01:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.model.Reminder;
|
2016-12-31 15:56:05 +01:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.model.WeatherSpec;
|
2022-05-09 20:47:08 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.model.WorldClock;
|
2019-11-19 14:40:20 +01:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.service.receivers.AutoConnectIntervalReceiver;
|
2018-06-23 11:19:09 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.service.receivers.GBAutoFetchReceiver;
|
2015-12-13 00:43:07 +01:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.util.DeviceHelper;
|
2018-11-25 23:56:52 +01:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.util.EmojiConverter;
|
2015-08-04 01:01:14 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.util.GB;
|
2016-04-28 23:17:13 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.util.GBPrefs;
|
2022-06-15 01:54:44 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.util.language.LanguageUtils;
|
2016-04-25 23:18:55 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.util.Prefs;
|
2022-06-15 01:54:44 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.util.language.Transliterator;
|
2015-08-23 00:54:28 +02:00
|
|
|
|
2016-04-28 23:17:13 +02:00
|
|
|
public class DeviceCommunicationService extends Service implements SharedPreferences.OnSharedPreferenceChangeListener {
|
2022-06-14 18:05:41 +02:00
|
|
|
public static class DeviceStruct{
|
|
|
|
private GBDevice device;
|
|
|
|
private DeviceCoordinator coordinator;
|
|
|
|
private DeviceSupport deviceSupport;
|
|
|
|
|
|
|
|
public GBDevice getDevice() {
|
|
|
|
return device;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setDevice(GBDevice device) {
|
|
|
|
this.device = device;
|
|
|
|
}
|
|
|
|
|
|
|
|
public DeviceCoordinator getCoordinator() {
|
|
|
|
return coordinator;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setCoordinator(DeviceCoordinator coordinator) {
|
|
|
|
this.coordinator = coordinator;
|
|
|
|
}
|
|
|
|
|
|
|
|
public DeviceSupport getDeviceSupport() {
|
|
|
|
return deviceSupport;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setDeviceSupport(DeviceSupport deviceSupport) {
|
|
|
|
this.deviceSupport = deviceSupport;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private class FeatureSet{
|
|
|
|
private boolean supportsWeather = false;
|
|
|
|
private boolean supportsActivityDataFetching = false;
|
|
|
|
private boolean supportsCalendarEvents = false;
|
|
|
|
private boolean supportsMusicInfo = false;
|
2022-08-05 23:43:39 +02:00
|
|
|
private boolean supportsNavigation = false;
|
2022-06-14 18:05:41 +02:00
|
|
|
|
|
|
|
public boolean supportsWeather() {
|
|
|
|
return supportsWeather;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setSupportsWeather(boolean supportsWeather) {
|
|
|
|
this.supportsWeather = supportsWeather;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean supportsActivityDataFetching() {
|
|
|
|
return supportsActivityDataFetching;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setSupportsActivityDataFetching(boolean supportsActivityDataFetching) {
|
|
|
|
this.supportsActivityDataFetching = supportsActivityDataFetching;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean supportsCalendarEvents() {
|
|
|
|
return supportsCalendarEvents;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setSupportsCalendarEvents(boolean supportsCalendarEvents) {
|
|
|
|
this.supportsCalendarEvents = supportsCalendarEvents;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean supportsMusicInfo() {
|
|
|
|
return supportsMusicInfo;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setSupportsMusicInfo(boolean supportsMusicInfo) {
|
|
|
|
this.supportsMusicInfo = supportsMusicInfo;
|
|
|
|
}
|
|
|
|
|
2022-08-05 23:43:39 +02:00
|
|
|
public boolean supportsNavigation() {
|
|
|
|
return supportsNavigation;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setSupportsNavigation(boolean supportsNavigation) {
|
|
|
|
this.supportsNavigation = supportsNavigation;
|
|
|
|
}
|
|
|
|
|
2022-06-14 18:05:41 +02:00
|
|
|
public void logicalOr(DeviceCoordinator operand){
|
|
|
|
if(operand.supportsCalendarEvents()){
|
|
|
|
setSupportsCalendarEvents(true);
|
|
|
|
}
|
|
|
|
if(operand.supportsWeather()){
|
|
|
|
setSupportsWeather(true);
|
|
|
|
}
|
|
|
|
if(operand.supportsActivityDataFetching()){
|
|
|
|
setSupportsActivityDataFetching(true);
|
|
|
|
}
|
|
|
|
if(operand.supportsMusicInfo()){
|
|
|
|
setSupportsMusicInfo(true);
|
|
|
|
}
|
2022-08-05 23:43:39 +02:00
|
|
|
if(operand.supportsNavigation()){
|
|
|
|
setSupportsNavigation(true);
|
|
|
|
}
|
2022-06-14 18:05:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static class DeviceNotFoundException extends GBException{
|
|
|
|
private final String address;
|
|
|
|
|
|
|
|
public DeviceNotFoundException(GBDevice device) {
|
|
|
|
this.address = device.getAddress();
|
|
|
|
}
|
|
|
|
|
|
|
|
public DeviceNotFoundException(String address) {
|
|
|
|
this.address = address;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Nullable
|
|
|
|
@Override
|
|
|
|
public String getMessage() {
|
|
|
|
return String.format("device %s not found cached", address);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-04 01:01:14 +02:00
|
|
|
private static final Logger LOG = LoggerFactory.getLogger(DeviceCommunicationService.class);
|
2017-04-21 22:21:24 +02:00
|
|
|
@SuppressLint("StaticFieldLeak") // only used for test cases
|
2016-09-10 10:52:02 +02:00
|
|
|
private static DeviceSupportFactory DEVICE_SUPPORT_FACTORY = null;
|
2015-02-06 13:55:44 +01:00
|
|
|
|
|
|
|
private boolean mStarted = false;
|
2015-03-22 23:38:51 +01:00
|
|
|
|
2015-08-23 00:54:28 +02:00
|
|
|
private DeviceSupportFactory mFactory;
|
2022-06-14 18:05:41 +02:00
|
|
|
private final ArrayList<DeviceStruct> deviceStructs = new ArrayList<>(1);
|
2023-03-31 21:07:56 +02:00
|
|
|
private final HashMap<String, ArrayList<Intent>> cachedNotifications = new HashMap<>();
|
2015-01-12 00:35:15 +01:00
|
|
|
|
2015-10-15 17:23:16 +02:00
|
|
|
private PhoneCallReceiver mPhoneCallReceiver = null;
|
|
|
|
private SMSReceiver mSMSReceiver = null;
|
|
|
|
private PebbleReceiver mPebbleReceiver = null;
|
|
|
|
private MusicPlaybackReceiver mMusicPlaybackReceiver = null;
|
|
|
|
private TimeChangeReceiver mTimeChangeReceiver = null;
|
2016-05-22 01:19:28 +02:00
|
|
|
private BluetoothConnectReceiver mBlueToothConnectReceiver = null;
|
2017-04-18 11:47:28 +02:00
|
|
|
private BluetoothPairingRequestReceiver mBlueToothPairingRequestReceiver = null;
|
2017-02-07 23:49:10 +01:00
|
|
|
private AlarmClockReceiver mAlarmClockReceiver = null;
|
2023-12-11 11:50:31 +01:00
|
|
|
private SilentModeReceiver mSilentModeReceiver = null;
|
2018-06-23 11:19:09 +02:00
|
|
|
private GBAutoFetchReceiver mGBAutoFetchReceiver = null;
|
2021-10-19 14:32:20 +02:00
|
|
|
private AutoConnectIntervalReceiver mAutoConnectInvervalReceiver = null;
|
2015-10-15 17:23:16 +02:00
|
|
|
|
2017-02-07 23:49:10 +01:00
|
|
|
private AlarmReceiver mAlarmReceiver = null;
|
2022-07-20 17:29:40 +02:00
|
|
|
private List<CalendarReceiver> mCalendarReceiver = new ArrayList<>();
|
2017-12-11 19:09:37 +01:00
|
|
|
private CMWeatherReceiver mCMWeatherReceiver = null;
|
2019-08-22 17:57:26 +02:00
|
|
|
private LineageOsWeatherReceiver mLineageOsWeatherReceiver = null;
|
2020-07-05 21:54:10 +02:00
|
|
|
private TinyWeatherForecastGermanyReceiver mTinyWeatherForecastGermanyReceiver = null;
|
2022-08-22 02:30:13 +02:00
|
|
|
private GenericWeatherReceiver mGenericWeatherReceiver = null;
|
2017-12-17 22:35:17 +01:00
|
|
|
private OmniJawsObserver mOmniJawsObserver = null;
|
2022-09-17 16:23:10 +02:00
|
|
|
private final DeviceSettingsReceiver deviceSettingsReceiver = new DeviceSettingsReceiver();
|
2022-10-29 01:28:45 +02:00
|
|
|
private final IntentApiReceiver intentApiReceiver = new IntentApiReceiver();
|
2015-12-14 23:31:31 +01:00
|
|
|
|
2021-10-19 14:32:20 +02:00
|
|
|
private OsmandEventReceiver mOsmandAidlHelper = null;
|
|
|
|
|
2017-02-11 09:49:01 +01:00
|
|
|
private final String[] mMusicActions = {
|
|
|
|
"com.android.music.metachanged",
|
|
|
|
"com.android.music.playstatechanged",
|
|
|
|
"com.android.music.queuechanged",
|
|
|
|
"com.android.music.playbackcomplete",
|
|
|
|
"net.sourceforge.subsonic.androidapp.EVENT_META_CHANGED",
|
|
|
|
"com.maxmpz.audioplayer.TPOS_SYNC",
|
2017-02-17 09:01:37 +01:00
|
|
|
"com.maxmpz.audioplayer.STATUS_CHANGED",
|
2017-09-01 23:47:03 +02:00
|
|
|
"com.maxmpz.audioplayer.PLAYING_MODE_CHANGED",
|
|
|
|
"com.spotify.music.metadatachanged",
|
|
|
|
"com.spotify.music.playbackstatechanged"
|
|
|
|
};
|
2017-02-11 09:49:01 +01:00
|
|
|
|
2022-09-04 23:05:57 +02:00
|
|
|
private final String COMMAND_BLUETOOTH_CONNECT = "nodomain.freeyourgadget.gadgetbridge.BLUETOOTH_CONNECT";
|
|
|
|
private final String ACTION_DEVICE_CONNECTED = "nodomain.freeyourgadget.gadgetbridge.BLUETOOTH_CONNECTED";
|
2023-03-31 21:07:56 +02:00
|
|
|
private final int NOTIFICATIONS_CACHE_MAX = 10; // maximum amount of notifications to cache per device while disconnected
|
2022-09-04 23:05:57 +02:00
|
|
|
private boolean allowBluetoothIntentApi = false;
|
|
|
|
|
|
|
|
private void sendDeviceConnectedBroadcast(String address){
|
|
|
|
if(!allowBluetoothIntentApi){
|
|
|
|
GB.log("not sending API event due to settings", GB.INFO, null);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Intent intent = new Intent(ACTION_DEVICE_CONNECTED);
|
|
|
|
intent.putExtra("EXTRA_DEVICE_ADDRESS", address);
|
|
|
|
|
|
|
|
sendBroadcast(intent);
|
|
|
|
}
|
|
|
|
|
|
|
|
BroadcastReceiver bluetoothCommandReceiver = new BroadcastReceiver() {
|
|
|
|
@Override
|
|
|
|
public void onReceive(Context context, Intent intent) {
|
|
|
|
switch (intent.getAction()){
|
|
|
|
case COMMAND_BLUETOOTH_CONNECT:
|
|
|
|
if(!allowBluetoothIntentApi){
|
|
|
|
GB.log("Connection API not allowed in settings", GB.ERROR, null);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Bundle extras = intent.getExtras();
|
|
|
|
if(extras == null){
|
|
|
|
GB.log("no extras provided in Intent", GB.ERROR, null);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
String address = extras.getString("EXTRA_DEVICE_ADDRESS", "");
|
|
|
|
if(address.isEmpty()){
|
|
|
|
GB.log("no bluetooth address provided in Intent", GB.ERROR, null);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if(isDeviceConnected(address)){
|
|
|
|
GB.log(String.format("device %s already connected", address), GB.INFO, null);
|
|
|
|
sendDeviceConnectedBroadcast(address);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
List<GBDevice> devices = GBApplication.app().getDeviceManager().getDevices();
|
|
|
|
GBDevice targetDevice = GBApplication
|
|
|
|
.app()
|
|
|
|
.getDeviceManager()
|
|
|
|
.getDeviceByAddress(address);
|
|
|
|
|
|
|
|
if(targetDevice == null){
|
|
|
|
GB.log(String.format("device %s not registered", address), GB.ERROR, null);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
GB.log(String.format("connecting to %s", address), GB.INFO, null);
|
|
|
|
|
|
|
|
GBApplication
|
|
|
|
.deviceService(targetDevice)
|
|
|
|
.connect();
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-09-10 10:52:02 +02:00
|
|
|
/**
|
|
|
|
* For testing!
|
|
|
|
*
|
|
|
|
* @param factory
|
|
|
|
*/
|
2022-06-14 18:05:41 +02:00
|
|
|
@SuppressWarnings("JavaDoc")
|
2016-09-10 10:52:02 +02:00
|
|
|
public static void setDeviceSupportFactory(DeviceSupportFactory factory) {
|
|
|
|
DEVICE_SUPPORT_FACTORY = factory;
|
|
|
|
}
|
|
|
|
|
|
|
|
public DeviceCommunicationService() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-11-23 23:04:46 +01:00
|
|
|
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
|
2015-04-19 14:34:18 +02:00
|
|
|
@Override
|
|
|
|
public void onReceive(Context context, Intent intent) {
|
|
|
|
String action = intent.getAction();
|
2022-06-14 18:05:41 +02:00
|
|
|
if(GBDevice.ACTION_DEVICE_CHANGED.equals(action)){
|
2015-07-10 21:35:28 +02:00
|
|
|
GBDevice device = intent.getParcelableExtra(GBDevice.EXTRA_DEVICE);
|
2022-06-14 18:05:41 +02:00
|
|
|
|
|
|
|
// create a new instance of the changed devices coordinator, in case it's capabilities changed
|
|
|
|
DeviceStruct cachedStruct = getDeviceStructOrNull(device);
|
|
|
|
if(cachedStruct != null) {
|
|
|
|
cachedStruct.setDevice(device);
|
2023-09-27 23:11:02 +02:00
|
|
|
DeviceCoordinator newCoordinator = device.getDeviceCoordinator();
|
2022-06-14 18:05:41 +02:00
|
|
|
cachedStruct.setCoordinator(newCoordinator);
|
2015-04-19 14:34:18 +02:00
|
|
|
}
|
2022-06-14 18:05:41 +02:00
|
|
|
updateReceiversState();
|
2022-09-04 23:05:57 +02:00
|
|
|
|
2022-09-29 00:42:15 +02:00
|
|
|
GBDevice.DeviceUpdateSubject subject = (GBDevice.DeviceUpdateSubject) intent.getSerializableExtra(GBDevice.EXTRA_UPDATE_SUBJECT);
|
2022-09-23 02:57:08 +02:00
|
|
|
|
2022-09-29 00:42:15 +02:00
|
|
|
if(subject == GBDevice.DeviceUpdateSubject.DEVICE_STATE && device.isInitialized()){
|
2022-09-25 01:27:26 +02:00
|
|
|
LOG.debug("device state update reason");
|
2022-09-04 23:05:57 +02:00
|
|
|
sendDeviceConnectedBroadcast(device.getAddress());
|
2023-03-31 21:07:56 +02:00
|
|
|
sendCachedNotifications(device);
|
2022-09-04 23:05:57 +02:00
|
|
|
}
|
2015-04-19 14:34:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2015-04-19 15:27:16 +02:00
|
|
|
|
2022-06-14 18:05:41 +02:00
|
|
|
private void updateReceiversState(){
|
|
|
|
boolean enableReceivers = false;
|
|
|
|
boolean anyDeviceInitialized = false;
|
2022-07-20 17:29:40 +02:00
|
|
|
List <GBDevice> devicesWithCalendar = new ArrayList<>();
|
2022-06-14 18:05:41 +02:00
|
|
|
|
|
|
|
FeatureSet features = new FeatureSet();
|
|
|
|
|
|
|
|
for(DeviceStruct struct: deviceStructs){
|
|
|
|
DeviceSupport deviceSupport = struct.getDeviceSupport();
|
|
|
|
if((deviceSupport != null && deviceSupport.useAutoConnect()) || isDeviceInitialized(struct.getDevice())){
|
|
|
|
enableReceivers = true;
|
|
|
|
}
|
|
|
|
if(isDeviceInitialized(struct.getDevice())){
|
|
|
|
anyDeviceInitialized = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
DeviceCoordinator coordinator = struct.getCoordinator();
|
|
|
|
if(coordinator != null){
|
|
|
|
features.logicalOr(coordinator);
|
2022-07-20 17:29:40 +02:00
|
|
|
if (coordinator.supportsCalendarEvents()){
|
|
|
|
devicesWithCalendar.add(struct.getDevice());
|
|
|
|
}
|
2022-06-14 18:05:41 +02:00
|
|
|
}
|
|
|
|
}
|
2022-07-20 17:29:40 +02:00
|
|
|
setReceiversEnableState(enableReceivers, anyDeviceInitialized, features, devicesWithCalendar);
|
2022-06-14 18:05:41 +02:00
|
|
|
}
|
|
|
|
|
2024-02-12 23:30:32 +01:00
|
|
|
@Override
|
|
|
|
public void onCreate() {
|
|
|
|
LOG.debug("DeviceCommunicationService is being created");
|
|
|
|
super.onCreate();
|
|
|
|
LocalBroadcastManager.getInstance(this).registerReceiver(mReceiver, new IntentFilter(GBDevice.ACTION_DEVICE_CHANGED));
|
|
|
|
mFactory = getDeviceSupportFactory();
|
2016-04-28 23:17:13 +02:00
|
|
|
|
2022-06-14 18:05:41 +02:00
|
|
|
mBlueToothConnectReceiver = new BluetoothConnectReceiver(this);
|
|
|
|
registerReceiver(mBlueToothConnectReceiver, new IntentFilter(BluetoothDevice.ACTION_ACL_CONNECTED));
|
|
|
|
|
2022-08-05 15:22:21 +02:00
|
|
|
mAutoConnectInvervalReceiver= new AutoConnectIntervalReceiver(this);
|
|
|
|
registerReceiver(mAutoConnectInvervalReceiver, new IntentFilter("GB_RECONNECT"));
|
|
|
|
|
2024-02-12 23:30:32 +01:00
|
|
|
if (hasPrefs()) {
|
|
|
|
getPrefs().getPreferences().registerOnSharedPreferenceChangeListener(this);
|
|
|
|
allowBluetoothIntentApi = getPrefs().getBoolean(GBPrefs.PREF_ALLOW_INTENT_API, false);
|
|
|
|
}
|
|
|
|
|
2022-09-04 23:05:57 +02:00
|
|
|
IntentFilter bluetoothCommandFilter = new IntentFilter();
|
|
|
|
bluetoothCommandFilter.addAction(COMMAND_BLUETOOTH_CONNECT);
|
|
|
|
registerReceiver(bluetoothCommandReceiver, bluetoothCommandFilter);
|
2022-09-17 16:23:10 +02:00
|
|
|
|
|
|
|
final IntentFilter deviceSettingsIntentFilter = new IntentFilter();
|
|
|
|
deviceSettingsIntentFilter.addAction(DeviceSettingsReceiver.COMMAND);
|
|
|
|
registerReceiver(deviceSettingsReceiver, deviceSettingsIntentFilter);
|
2022-10-29 01:28:45 +02:00
|
|
|
|
|
|
|
registerReceiver(intentApiReceiver, intentApiReceiver.buildFilter());
|
2015-01-12 00:35:15 +01:00
|
|
|
}
|
|
|
|
|
2016-09-10 10:52:02 +02:00
|
|
|
private DeviceSupportFactory getDeviceSupportFactory() {
|
|
|
|
if (DEVICE_SUPPORT_FACTORY != null) {
|
|
|
|
return DEVICE_SUPPORT_FACTORY;
|
|
|
|
}
|
|
|
|
return new DeviceSupportFactory(this);
|
|
|
|
}
|
|
|
|
|
2015-01-12 00:35:15 +01:00
|
|
|
@Override
|
2015-10-22 00:52:45 +02:00
|
|
|
public synchronized int onStartCommand(Intent intent, int flags, int startId) {
|
2015-01-26 18:52:19 +01:00
|
|
|
|
2015-04-03 22:39:25 +02:00
|
|
|
if (intent == null) {
|
2015-05-12 06:28:11 +02:00
|
|
|
LOG.info("no intent");
|
2015-04-03 22:39:25 +02:00
|
|
|
return START_NOT_STICKY;
|
|
|
|
}
|
|
|
|
|
2015-02-06 13:55:44 +01:00
|
|
|
String action = intent.getAction();
|
2017-04-12 21:33:19 +02:00
|
|
|
boolean firstTime = intent.getBooleanExtra(EXTRA_CONNECT_FIRST_TIME, false);
|
2015-04-03 22:39:25 +02:00
|
|
|
|
2015-03-17 21:41:58 +01:00
|
|
|
if (action == null) {
|
2015-05-12 06:28:11 +02:00
|
|
|
LOG.info("no action");
|
2015-03-17 21:41:58 +01:00
|
|
|
return START_NOT_STICKY;
|
|
|
|
}
|
2015-01-12 00:35:15 +01:00
|
|
|
|
2015-05-12 06:28:11 +02:00
|
|
|
LOG.debug("Service startcommand: " + action);
|
2015-04-22 20:37:07 +02:00
|
|
|
|
2015-04-19 02:37:29 +02:00
|
|
|
if (!action.equals(ACTION_START) && !action.equals(ACTION_CONNECT)) {
|
2015-08-06 23:17:41 +02:00
|
|
|
if (!mStarted) {
|
|
|
|
// using the service before issuing ACTION_START
|
|
|
|
LOG.info("Must start service with " + ACTION_START + " or " + ACTION_CONNECT + " before using it: " + action);
|
|
|
|
return START_NOT_STICKY;
|
|
|
|
}
|
|
|
|
|
2022-06-14 18:05:41 +02:00
|
|
|
// TODO
|
|
|
|
/*if (mDeviceSupport == null || (!isInitialized() && !action.equals(ACTION_DISCONNECT) && (!mDeviceSupport.useAutoConnect() || isConnected()))) {
|
2015-04-19 02:37:29 +02:00
|
|
|
// trying to send notification without valid Bluetooth connection
|
2015-04-24 23:08:47 +02:00
|
|
|
if (mGBDevice != null) {
|
|
|
|
// at least send back the current device state
|
|
|
|
mGBDevice.sendDeviceUpdateIntent(this);
|
|
|
|
}
|
2015-04-19 02:37:29 +02:00
|
|
|
return START_STICKY;
|
2022-06-14 18:05:41 +02:00
|
|
|
}*/
|
2015-02-06 13:55:44 +01:00
|
|
|
}
|
2015-01-12 00:35:15 +01:00
|
|
|
|
2015-08-14 00:23:01 +02:00
|
|
|
// when we get past this, we should have valid mDeviceSupport and mGBDevice instances
|
2015-08-06 23:17:41 +02:00
|
|
|
|
2016-04-29 21:49:17 +02:00
|
|
|
Prefs prefs = getPrefs();
|
2015-05-08 11:18:06 +02:00
|
|
|
switch (action) {
|
2015-08-06 23:17:41 +02:00
|
|
|
case ACTION_START:
|
|
|
|
start();
|
|
|
|
break;
|
2015-05-08 11:18:06 +02:00
|
|
|
case ACTION_CONNECT:
|
2015-08-06 23:17:41 +02:00
|
|
|
start(); // ensure started
|
2023-10-01 22:54:45 +02:00
|
|
|
List<GBDevice> gbDevs = null;
|
|
|
|
boolean fromExtra = false;
|
|
|
|
|
|
|
|
GBDevice extraDevice = intent.getParcelableExtra(GBDevice.EXTRA_DEVICE);
|
|
|
|
if (extraDevice != null) {
|
|
|
|
gbDevs = new ArrayList<>();
|
|
|
|
gbDevs.add(extraDevice);
|
|
|
|
fromExtra = true;
|
2024-01-04 17:48:26 +01:00
|
|
|
} else if (prefs.getBoolean(GBPrefs.RECONNECT_ONLY_TO_CONNECTED, true)) {
|
|
|
|
List<GBDevice> gbAllDevs = GBApplication.app().getDeviceManager().getDevices();
|
|
|
|
Set<String> lastDeviceAddresses = prefs.getStringSet(GBPrefs.LAST_DEVICE_ADDRESSES, Collections.emptySet());
|
|
|
|
if (gbAllDevs != null && !gbAllDevs.isEmpty() && !lastDeviceAddresses.isEmpty()) {
|
|
|
|
gbDevs = new ArrayList<>();
|
|
|
|
for(GBDevice gbDev : gbAllDevs) {
|
|
|
|
if (lastDeviceAddresses.contains(gbDev.getAddress())) {
|
|
|
|
gbDevs.add(gbDev);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-03-20 19:48:54 +01:00
|
|
|
} else {
|
2023-10-01 22:54:45 +02:00
|
|
|
gbDevs = GBApplication.app().getDeviceManager().getDevices();
|
2016-03-20 19:48:54 +01:00
|
|
|
}
|
|
|
|
|
2023-10-01 22:54:45 +02:00
|
|
|
if(gbDevs == null || gbDevs.size() == 0) {
|
2022-06-14 18:05:41 +02:00
|
|
|
return START_NOT_STICKY;
|
|
|
|
}
|
|
|
|
|
2023-10-01 22:54:45 +02:00
|
|
|
for(GBDevice gbDevice : gbDevs) {
|
|
|
|
String btDeviceAddress = gbDevice.getAddress();
|
2015-05-08 11:18:06 +02:00
|
|
|
|
2023-10-01 22:54:45 +02:00
|
|
|
boolean autoReconnect = GBPrefs.AUTO_RECONNECT_DEFAULT;
|
|
|
|
if (prefs != null && prefs.getPreferences() != null) {
|
|
|
|
autoReconnect = getGBPrefs().getAutoReconnect(gbDevice);
|
|
|
|
if(!fromExtra && !autoReconnect) {
|
|
|
|
continue;
|
|
|
|
}
|
2024-01-04 17:48:26 +01:00
|
|
|
Set<String> lastDeviceAddresses = prefs.getStringSet(GBPrefs.LAST_DEVICE_ADDRESSES, Collections.emptySet());
|
|
|
|
if (!lastDeviceAddresses.contains(btDeviceAddress)) {
|
|
|
|
lastDeviceAddresses = new HashSet<String>(lastDeviceAddresses);
|
|
|
|
lastDeviceAddresses.add(btDeviceAddress);
|
|
|
|
prefs.getPreferences().edit().putStringSet(GBPrefs.LAST_DEVICE_ADDRESSES, lastDeviceAddresses).apply();
|
|
|
|
}
|
2022-06-14 18:05:41 +02:00
|
|
|
}
|
2023-10-01 22:54:45 +02:00
|
|
|
|
|
|
|
if(!fromExtra && !autoReconnect) {
|
|
|
|
continue;
|
2022-06-14 18:05:41 +02:00
|
|
|
}
|
|
|
|
|
2023-10-01 22:54:45 +02:00
|
|
|
DeviceStruct registeredStruct = getDeviceStructOrNull(gbDevice);
|
|
|
|
if(registeredStruct != null){
|
|
|
|
boolean deviceAlreadyConnected = isDeviceConnecting(registeredStruct.getDevice()) || isDeviceConnected(registeredStruct.getDevice());
|
|
|
|
if(deviceAlreadyConnected){
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
removeDeviceSupport(gbDevice);
|
|
|
|
} catch (DeviceNotFoundException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
registeredStruct = new DeviceStruct();
|
|
|
|
registeredStruct.setDevice(gbDevice);
|
|
|
|
registeredStruct.setCoordinator(gbDevice.getDeviceCoordinator());
|
|
|
|
deviceStructs.add(registeredStruct);
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
DeviceSupport deviceSupport = mFactory.createDeviceSupport(gbDevice);
|
|
|
|
if (deviceSupport != null) {
|
|
|
|
setDeviceSupport(gbDevice, deviceSupport);
|
|
|
|
if (firstTime) {
|
|
|
|
deviceSupport.connectFirstTime();
|
|
|
|
} else {
|
|
|
|
deviceSupport.setAutoReconnect(autoReconnect);
|
|
|
|
deviceSupport.connect();
|
|
|
|
}
|
2015-10-18 08:34:51 +02:00
|
|
|
} else {
|
2023-10-01 22:54:45 +02:00
|
|
|
GB.toast(this, getString(R.string.cannot_connect, "Can't create device support"), Toast.LENGTH_SHORT, GB.ERROR);
|
2015-04-01 18:34:52 +02:00
|
|
|
}
|
2023-10-01 22:54:45 +02:00
|
|
|
} catch (Exception e) {
|
|
|
|
GB.toast(this, getString(R.string.cannot_connect, e.getMessage()), Toast.LENGTH_SHORT, GB.ERROR, e);
|
2015-01-12 00:35:15 +01:00
|
|
|
}
|
2022-06-14 18:05:41 +02:00
|
|
|
|
2023-10-01 22:54:45 +02:00
|
|
|
for(DeviceStruct struct2 : deviceStructs){
|
|
|
|
struct2.getDevice().sendDeviceUpdateIntent(this);
|
|
|
|
}
|
2015-01-12 00:35:15 +01:00
|
|
|
}
|
2015-05-08 11:18:06 +02:00
|
|
|
break;
|
2018-09-15 23:30:39 +02:00
|
|
|
default:
|
2022-06-14 18:05:41 +02:00
|
|
|
GBDevice targetedDevice = intent.getParcelableExtra(GBDevice.EXTRA_DEVICE);
|
|
|
|
ArrayList<GBDevice> targetedDevices = new ArrayList<>();
|
|
|
|
if(targetedDevice != null){
|
|
|
|
targetedDevices.add(targetedDevice);
|
|
|
|
}else{
|
|
|
|
for(GBDevice device : getGBDevices()){
|
|
|
|
if(isDeviceInitialized(device)){
|
|
|
|
targetedDevices.add(device);
|
2023-03-31 21:07:56 +02:00
|
|
|
} else if (isDeviceReconnecting(device) && action.equals(ACTION_NOTIFICATION) && GBApplication.getPrefs().getBoolean("notification_cache_while_disconnected", false)) {
|
|
|
|
if (!cachedNotifications.containsKey(device.getAddress())) {
|
|
|
|
cachedNotifications.put(device.getAddress(), new ArrayList<>());
|
|
|
|
}
|
|
|
|
ArrayList<Intent> notifCache = cachedNotifications.get(device.getAddress());
|
|
|
|
notifCache.add(intent);
|
|
|
|
if (notifCache.size() > NOTIFICATIONS_CACHE_MAX) {
|
|
|
|
// remove the oldest notification if the maximum is reached
|
|
|
|
notifCache.remove(0);
|
|
|
|
}
|
|
|
|
} else if (action.equals(ACTION_DELETE_NOTIFICATION)) {
|
|
|
|
ArrayList<Intent> notifCache = cachedNotifications.get(device.getAddress());
|
|
|
|
if (notifCache != null) {
|
|
|
|
int notifId = intent.getIntExtra(EXTRA_NOTIFICATION_ID, -1);
|
|
|
|
ArrayList<Intent> toRemove = new ArrayList<>();
|
|
|
|
for (Intent cached : notifCache) {
|
|
|
|
if (notifId == cached.getIntExtra(EXTRA_NOTIFICATION_ID, -1)) {
|
|
|
|
toRemove.add(cached);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
notifCache.removeAll(toRemove);
|
|
|
|
}
|
2024-01-04 19:24:12 +01:00
|
|
|
} else if (action.equals(ACTION_DISCONNECT) && device.getState() != GBDevice.State.NOT_CONNECTED) {
|
|
|
|
targetedDevices.add(device);
|
2022-06-14 18:05:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (GBDevice device1 : targetedDevices) {
|
|
|
|
try {
|
|
|
|
handleAction(intent, action, device1);
|
|
|
|
} catch (DeviceNotFoundException e) {
|
|
|
|
e.printStackTrace();
|
2023-12-05 20:13:13 +01:00
|
|
|
} catch (Exception e) {
|
|
|
|
LOG.error("An exception was raised while handling the action {} for the device {}: ", action, device1, e);
|
2022-06-14 18:05:41 +02:00
|
|
|
}
|
2018-09-15 23:30:39 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return START_STICKY;
|
|
|
|
}
|
|
|
|
|
2018-11-25 23:56:52 +01:00
|
|
|
/**
|
2019-02-28 21:57:45 +01:00
|
|
|
* @param text original text
|
2018-11-25 23:56:52 +01:00
|
|
|
* @return 'text' or a new String without non supported chars like emoticons, etc.
|
|
|
|
*/
|
2022-06-14 18:05:41 +02:00
|
|
|
private String sanitizeNotifText(String text, GBDevice device) throws DeviceNotFoundException {
|
2018-11-25 23:56:52 +01:00
|
|
|
if (text == null || text.length() == 0)
|
|
|
|
return text;
|
|
|
|
|
2022-06-14 18:05:41 +02:00
|
|
|
text = getDeviceSupport(device).customStringFilter(text);
|
2019-07-31 20:22:38 +02:00
|
|
|
|
2022-06-14 18:05:41 +02:00
|
|
|
if (!getDeviceCoordinator(device).supportsUnicodeEmojis()) {
|
2018-12-23 22:58:43 +01:00
|
|
|
return EmojiConverter.convertUnicodeEmojiToAscii(text, getApplicationContext());
|
2019-07-31 20:22:38 +02:00
|
|
|
}
|
2018-11-25 23:56:52 +01:00
|
|
|
|
|
|
|
return text;
|
|
|
|
}
|
|
|
|
|
2022-06-14 18:05:41 +02:00
|
|
|
private DeviceCoordinator getDeviceCoordinator(GBDevice device) throws DeviceNotFoundException {
|
|
|
|
if(device == null){
|
|
|
|
throw new DeviceNotFoundException("null");
|
|
|
|
}
|
|
|
|
for(DeviceStruct struct : deviceStructs){
|
|
|
|
if(struct.getDevice().equals(device)){
|
|
|
|
return struct.getCoordinator();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
throw new DeviceNotFoundException(device);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void handleAction(Intent intent, String action, GBDevice device) throws DeviceNotFoundException {
|
|
|
|
DeviceSupport deviceSupport = getDeviceSupport(device);
|
|
|
|
|
|
|
|
Prefs devicePrefs = new Prefs(GBApplication.getDeviceSpecificSharedPrefs(device.getAddress()));
|
2021-03-21 19:46:30 +01:00
|
|
|
|
2022-06-15 01:54:44 +02:00
|
|
|
final Transliterator transliterator = LanguageUtils.getTransliterator(device);
|
|
|
|
|
2023-07-08 18:13:53 +02:00
|
|
|
for (String extra : GBDeviceService.transliterationExtras) {
|
|
|
|
if (intent.hasExtra(extra)) {
|
|
|
|
// Ensure the text is sanitized (eg. emoji converted to ascii) before applying the transliterators
|
|
|
|
// otherwise the emoji are removed before converting them
|
|
|
|
String sanitizedText = sanitizeNotifText(intent.getStringExtra(extra), device);
|
|
|
|
if (transliterator != null) {
|
|
|
|
sanitizedText = transliterator.transliterate(sanitizedText);
|
2021-03-21 19:46:30 +01:00
|
|
|
}
|
2023-07-08 18:13:53 +02:00
|
|
|
intent.putExtra(extra, sanitizedText);
|
2021-03-21 19:46:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-15 23:30:39 +02:00
|
|
|
switch (action) {
|
2015-08-14 23:37:47 +02:00
|
|
|
case ACTION_REQUEST_DEVICEINFO:
|
2022-09-29 00:42:15 +02:00
|
|
|
device.sendDeviceUpdateIntent(this, GBDevice.DeviceUpdateSubject.NOTHING);
|
2015-08-06 23:17:41 +02:00
|
|
|
break;
|
2015-09-24 14:45:21 +02:00
|
|
|
case ACTION_NOTIFICATION: {
|
2018-10-31 21:47:12 +01:00
|
|
|
int desiredId = intent.getIntExtra(EXTRA_NOTIFICATION_ID, -1);
|
|
|
|
NotificationSpec notificationSpec = new NotificationSpec(desiredId);
|
2017-01-24 19:04:06 +01:00
|
|
|
notificationSpec.phoneNumber = intent.getStringExtra(EXTRA_NOTIFICATION_PHONENUMBER);
|
2023-07-08 18:13:53 +02:00
|
|
|
notificationSpec.sender = intent.getStringExtra(EXTRA_NOTIFICATION_SENDER);
|
|
|
|
notificationSpec.subject = intent.getStringExtra(EXTRA_NOTIFICATION_SUBJECT);
|
|
|
|
notificationSpec.title = intent.getStringExtra(EXTRA_NOTIFICATION_TITLE);
|
2023-12-08 13:12:35 +01:00
|
|
|
notificationSpec.key = intent.getStringExtra(EXTRA_NOTIFICATION_KEY);
|
2023-07-08 18:13:53 +02:00
|
|
|
notificationSpec.body = intent.getStringExtra(EXTRA_NOTIFICATION_BODY);
|
2017-01-24 19:04:06 +01:00
|
|
|
notificationSpec.sourceName = intent.getStringExtra(EXTRA_NOTIFICATION_SOURCENAME);
|
2015-09-24 14:45:21 +02:00
|
|
|
notificationSpec.type = (NotificationType) intent.getSerializableExtra(EXTRA_NOTIFICATION_TYPE);
|
2018-10-31 21:47:12 +01:00
|
|
|
notificationSpec.attachedActions = (ArrayList<NotificationSpec.Action>) intent.getSerializableExtra(EXTRA_NOTIFICATION_ACTIONS);
|
2017-09-19 13:24:31 +02:00
|
|
|
notificationSpec.pebbleColor = (byte) intent.getSerializableExtra(EXTRA_NOTIFICATION_PEBBLE_COLOR);
|
2016-01-09 17:54:17 +01:00
|
|
|
notificationSpec.flags = intent.getIntExtra(EXTRA_NOTIFICATION_FLAGS, 0);
|
2018-07-23 02:24:38 +02:00
|
|
|
notificationSpec.sourceAppId = intent.getStringExtra(EXTRA_NOTIFICATION_SOURCEAPPID);
|
2021-04-20 09:55:27 +02:00
|
|
|
notificationSpec.iconId = intent.getIntExtra(EXTRA_NOTIFICATION_ICONID, 0);
|
2021-11-19 15:09:27 +01:00
|
|
|
notificationSpec.dndSuppressed = intent.getIntExtra(EXTRA_NOTIFICATION_DNDSUPPRESSED, 0);
|
2017-01-17 21:07:12 +01:00
|
|
|
|
2016-10-11 11:54:52 +02:00
|
|
|
if (notificationSpec.type == NotificationType.GENERIC_SMS && notificationSpec.phoneNumber != null) {
|
2018-10-31 21:47:12 +01:00
|
|
|
GBApplication.getIDSenderLookup().add(notificationSpec.getId(), notificationSpec.phoneNumber);
|
2016-01-09 17:54:17 +01:00
|
|
|
}
|
2017-01-17 21:07:12 +01:00
|
|
|
|
2018-10-31 21:47:12 +01:00
|
|
|
//TODO: check if at least one of the attached actions is a reply action instead?
|
2018-11-15 15:53:04 +01:00
|
|
|
if ((notificationSpec.attachedActions != null && notificationSpec.attachedActions.size() > 0)
|
2016-10-11 11:54:52 +02:00
|
|
|
|| (notificationSpec.type == NotificationType.GENERIC_SMS && notificationSpec.phoneNumber != null)) {
|
2015-12-13 12:03:57 +01:00
|
|
|
// NOTE: maybe not where it belongs
|
2018-11-01 17:02:33 +01:00
|
|
|
// I would rather like to save that as an array in SharedPreferences
|
|
|
|
// this would work but I dont know how to do the same in the Settings Activity's xml
|
|
|
|
ArrayList<String> replies = new ArrayList<>();
|
|
|
|
for (int i = 1; i <= 16; i++) {
|
2020-10-13 00:25:43 +02:00
|
|
|
String reply = devicePrefs.getString("canned_reply_" + i, null);
|
2018-11-01 17:02:33 +01:00
|
|
|
if (reply != null && !reply.equals("")) {
|
|
|
|
replies.add(reply);
|
2015-12-13 12:03:57 +01:00
|
|
|
}
|
|
|
|
}
|
2020-10-13 00:25:43 +02:00
|
|
|
notificationSpec.cannedReplies = replies.toArray(new String[0]);
|
2015-09-24 14:45:21 +02:00
|
|
|
}
|
2017-01-17 21:07:12 +01:00
|
|
|
|
2022-06-14 18:05:41 +02:00
|
|
|
deviceSupport.onNotification(notificationSpec);
|
2015-05-08 11:18:06 +02:00
|
|
|
break;
|
2015-04-06 20:58:35 +02:00
|
|
|
}
|
2017-01-09 16:33:00 +01:00
|
|
|
case ACTION_DELETE_NOTIFICATION: {
|
2022-06-14 18:05:41 +02:00
|
|
|
deviceSupport.onDeleteNotification(intent.getIntExtra(EXTRA_NOTIFICATION_ID, -1));
|
2017-01-09 16:33:00 +01:00
|
|
|
break;
|
|
|
|
}
|
2016-05-16 17:30:11 +02:00
|
|
|
case ACTION_ADD_CALENDAREVENT: {
|
|
|
|
CalendarEventSpec calendarEventSpec = new CalendarEventSpec();
|
|
|
|
calendarEventSpec.id = intent.getLongExtra(EXTRA_CALENDAREVENT_ID, -1);
|
2016-05-24 13:11:57 +02:00
|
|
|
calendarEventSpec.type = intent.getByteExtra(EXTRA_CALENDAREVENT_TYPE, (byte) -1);
|
2016-05-16 17:30:11 +02:00
|
|
|
calendarEventSpec.timestamp = intent.getIntExtra(EXTRA_CALENDAREVENT_TIMESTAMP, -1);
|
|
|
|
calendarEventSpec.durationInSeconds = intent.getIntExtra(EXTRA_CALENDAREVENT_DURATION, -1);
|
2022-08-21 15:58:12 +02:00
|
|
|
calendarEventSpec.allDay = intent.getBooleanExtra(EXTRA_CALENDAREVENT_ALLDAY, false);
|
2023-07-08 18:13:53 +02:00
|
|
|
calendarEventSpec.title = intent.getStringExtra(EXTRA_CALENDAREVENT_TITLE);
|
|
|
|
calendarEventSpec.description = intent.getStringExtra(EXTRA_CALENDAREVENT_DESCRIPTION);
|
|
|
|
calendarEventSpec.location = intent.getStringExtra(EXTRA_CALENDAREVENT_LOCATION);
|
|
|
|
calendarEventSpec.calName = intent.getStringExtra(EXTRA_CALENDAREVENT_CALNAME);
|
2022-08-23 17:05:38 +02:00
|
|
|
calendarEventSpec.color = intent.getIntExtra(EXTRA_CALENDAREVENT_COLOR, 0);
|
2022-06-14 18:05:41 +02:00
|
|
|
deviceSupport.onAddCalendarEvent(calendarEventSpec);
|
2016-05-16 17:30:11 +02:00
|
|
|
break;
|
|
|
|
}
|
2016-05-16 23:37:40 +02:00
|
|
|
case ACTION_DELETE_CALENDAREVENT: {
|
|
|
|
long id = intent.getLongExtra(EXTRA_CALENDAREVENT_ID, -1);
|
2016-05-24 13:11:57 +02:00
|
|
|
byte type = intent.getByteExtra(EXTRA_CALENDAREVENT_TYPE, (byte) -1);
|
2022-06-14 18:05:41 +02:00
|
|
|
deviceSupport.onDeleteCalendarEvent(type, id);
|
2016-05-16 23:37:40 +02:00
|
|
|
break;
|
|
|
|
}
|
2018-12-16 16:05:13 +01:00
|
|
|
case ACTION_RESET: {
|
|
|
|
int flags = intent.getIntExtra(EXTRA_RESET_FLAGS, 0);
|
2022-06-14 18:05:41 +02:00
|
|
|
deviceSupport.onReset(flags);
|
2015-05-17 21:58:08 +02:00
|
|
|
break;
|
|
|
|
}
|
2015-12-28 14:38:56 +01:00
|
|
|
case ACTION_HEARTRATE_TEST: {
|
2022-06-14 18:05:41 +02:00
|
|
|
deviceSupport.onHeartRateTest();
|
2015-12-28 14:38:56 +01:00
|
|
|
break;
|
|
|
|
}
|
2018-03-31 16:21:25 +02:00
|
|
|
case ACTION_FETCH_RECORDED_DATA: {
|
|
|
|
int dataTypes = intent.getIntExtra(EXTRA_RECORDED_DATA_TYPES, 0);
|
2022-06-14 18:05:41 +02:00
|
|
|
deviceSupport.onFetchRecordedData(dataTypes);
|
2015-06-06 19:39:04 +02:00
|
|
|
break;
|
|
|
|
}
|
2022-06-14 18:05:41 +02:00
|
|
|
case ACTION_DISCONNECT:
|
|
|
|
try {
|
|
|
|
removeDeviceSupport(device);
|
|
|
|
} catch (DeviceNotFoundException e) {
|
|
|
|
e.printStackTrace();
|
2016-05-22 01:19:28 +02:00
|
|
|
}
|
2022-06-14 18:05:41 +02:00
|
|
|
device.setState(GBDevice.State.NOT_CONNECTED);
|
|
|
|
device.sendDeviceUpdateIntent(this);
|
|
|
|
updateReceiversState();
|
2015-06-07 15:31:42 +02:00
|
|
|
break;
|
2015-06-21 00:34:05 +02:00
|
|
|
case ACTION_FIND_DEVICE: {
|
2015-08-21 00:58:18 +02:00
|
|
|
boolean start = intent.getBooleanExtra(EXTRA_FIND_START, false);
|
2022-06-14 18:05:41 +02:00
|
|
|
deviceSupport.onFindDevice(start);
|
2015-06-21 00:34:05 +02:00
|
|
|
break;
|
2016-09-20 20:28:52 +02:00
|
|
|
}
|
2022-08-18 23:03:28 +02:00
|
|
|
case ACTION_PHONE_FOUND: {
|
2022-10-22 21:53:45 +02:00
|
|
|
final boolean start = intent.getBooleanExtra(EXTRA_FIND_START, false);
|
|
|
|
deviceSupport.onFindPhone(start);
|
2022-08-18 23:03:28 +02:00
|
|
|
break;
|
|
|
|
}
|
2016-09-20 20:28:52 +02:00
|
|
|
case ACTION_SET_CONSTANT_VIBRATION: {
|
|
|
|
int intensity = intent.getIntExtra(EXTRA_VIBRATION_INTENSITY, 0);
|
2022-06-14 18:05:41 +02:00
|
|
|
deviceSupport.onSetConstantVibration(intensity);
|
2016-09-20 20:28:52 +02:00
|
|
|
break;
|
2015-06-21 00:34:05 +02:00
|
|
|
}
|
2015-05-08 11:18:06 +02:00
|
|
|
case ACTION_CALLSTATE:
|
2016-04-04 20:08:34 +02:00
|
|
|
CallSpec callSpec = new CallSpec();
|
2017-01-27 21:16:19 +01:00
|
|
|
callSpec.command = intent.getIntExtra(EXTRA_CALL_COMMAND, CallSpec.CALL_UNDEFINED);
|
|
|
|
callSpec.number = intent.getStringExtra(EXTRA_CALL_PHONENUMBER);
|
2023-07-08 18:13:53 +02:00
|
|
|
callSpec.name = intent.getStringExtra(EXTRA_CALL_DISPLAYNAME);
|
2023-10-08 20:40:17 +02:00
|
|
|
callSpec.sourceName = intent.getStringExtra(EXTRA_CALL_SOURCENAME);
|
|
|
|
callSpec.sourceAppId = intent.getStringExtra(EXTRA_CALL_SOURCEAPPID);
|
2022-05-15 16:51:41 +02:00
|
|
|
callSpec.dndSuppressed = intent.getIntExtra(EXTRA_CALL_DNDSUPPRESSED, 0);
|
2022-06-14 18:05:41 +02:00
|
|
|
deviceSupport.onSetCallState(callSpec);
|
2015-05-08 11:18:06 +02:00
|
|
|
break;
|
2016-06-24 10:25:08 +02:00
|
|
|
case ACTION_SETCANNEDMESSAGES:
|
|
|
|
int type = intent.getIntExtra(EXTRA_CANNEDMESSAGES_TYPE, -1);
|
|
|
|
String[] cannedMessages = intent.getStringArrayExtra(EXTRA_CANNEDMESSAGES);
|
|
|
|
|
|
|
|
CannedMessagesSpec cannedMessagesSpec = new CannedMessagesSpec();
|
|
|
|
cannedMessagesSpec.type = type;
|
|
|
|
cannedMessagesSpec.cannedMessages = cannedMessages;
|
2022-06-14 18:05:41 +02:00
|
|
|
deviceSupport.onSetCannedMessages(cannedMessagesSpec);
|
2016-06-24 10:25:08 +02:00
|
|
|
break;
|
2015-05-08 11:18:06 +02:00
|
|
|
case ACTION_SETTIME:
|
2022-06-14 18:05:41 +02:00
|
|
|
deviceSupport.onSetTime();
|
2015-05-08 11:18:06 +02:00
|
|
|
break;
|
|
|
|
case ACTION_SETMUSICINFO:
|
2016-04-04 20:08:34 +02:00
|
|
|
MusicSpec musicSpec = new MusicSpec();
|
2023-07-08 18:13:53 +02:00
|
|
|
musicSpec.artist = intent.getStringExtra(EXTRA_MUSIC_ARTIST);
|
|
|
|
musicSpec.album = intent.getStringExtra(EXTRA_MUSIC_ALBUM);
|
|
|
|
musicSpec.track = intent.getStringExtra(EXTRA_MUSIC_TRACK);
|
2016-04-04 20:08:34 +02:00
|
|
|
musicSpec.duration = intent.getIntExtra(EXTRA_MUSIC_DURATION, 0);
|
|
|
|
musicSpec.trackCount = intent.getIntExtra(EXTRA_MUSIC_TRACKCOUNT, 0);
|
|
|
|
musicSpec.trackNr = intent.getIntExtra(EXTRA_MUSIC_TRACKNR, 0);
|
2022-06-14 18:05:41 +02:00
|
|
|
deviceSupport.onSetMusicInfo(musicSpec);
|
2015-05-08 11:18:06 +02:00
|
|
|
break;
|
2022-05-05 15:14:15 +02:00
|
|
|
case ACTION_SET_PHONE_VOLUME:
|
|
|
|
float phoneVolume = intent.getFloatExtra(EXTRA_PHONE_VOLUME, 0);
|
2022-06-14 18:05:41 +02:00
|
|
|
deviceSupport.onSetPhoneVolume(phoneVolume);
|
2022-05-05 15:14:15 +02:00
|
|
|
break;
|
2023-12-11 11:50:31 +01:00
|
|
|
case ACTION_SET_PHONE_SILENT_MODE:
|
|
|
|
final int ringerMode = intent.getIntExtra(EXTRA_PHONE_RINGER_MODE, -1);
|
|
|
|
deviceSupport.onChangePhoneSilentMode(ringerMode);
|
|
|
|
break;
|
2016-06-08 20:27:25 +02:00
|
|
|
case ACTION_SETMUSICSTATE:
|
|
|
|
MusicStateSpec stateSpec = new MusicStateSpec();
|
2016-11-27 10:32:56 +01:00
|
|
|
stateSpec.shuffle = intent.getByteExtra(EXTRA_MUSIC_SHUFFLE, (byte) 0);
|
|
|
|
stateSpec.repeat = intent.getByteExtra(EXTRA_MUSIC_REPEAT, (byte) 0);
|
2016-06-08 20:27:25 +02:00
|
|
|
stateSpec.position = intent.getIntExtra(EXTRA_MUSIC_POSITION, 0);
|
|
|
|
stateSpec.playRate = intent.getIntExtra(EXTRA_MUSIC_RATE, 0);
|
2016-11-27 10:32:56 +01:00
|
|
|
stateSpec.state = intent.getByteExtra(EXTRA_MUSIC_STATE, (byte) 0);
|
2022-06-14 18:05:41 +02:00
|
|
|
deviceSupport.onSetMusicState(stateSpec);
|
2016-06-08 20:27:25 +02:00
|
|
|
break;
|
2021-10-20 22:37:23 +02:00
|
|
|
case ACTION_SETNAVIGATIONINFO:
|
|
|
|
NavigationInfoSpec navigationInfoSpec = new NavigationInfoSpec();
|
|
|
|
navigationInfoSpec.instruction = intent.getStringExtra(EXTRA_NAVIGATION_INSTRUCTION);
|
|
|
|
navigationInfoSpec.nextAction = intent.getIntExtra(EXTRA_NAVIGATION_NEXT_ACTION,0);
|
2023-06-12 13:20:43 +02:00
|
|
|
navigationInfoSpec.distanceToTurn = intent.getStringExtra(EXTRA_NAVIGATION_DISTANCE_TO_TURN);
|
2023-06-09 09:47:10 +02:00
|
|
|
navigationInfoSpec.ETA = intent.getStringExtra(EXTRA_NAVIGATION_ETA);
|
2022-08-05 23:43:39 +02:00
|
|
|
deviceSupport.onSetNavigationInfo(navigationInfoSpec);
|
2021-10-20 22:37:23 +02:00
|
|
|
break;
|
2015-05-08 11:18:06 +02:00
|
|
|
case ACTION_REQUEST_APPINFO:
|
2022-06-14 18:05:41 +02:00
|
|
|
deviceSupport.onAppInfoReq();
|
2015-05-08 11:18:06 +02:00
|
|
|
break;
|
2015-06-24 00:23:38 +02:00
|
|
|
case ACTION_REQUEST_SCREENSHOT:
|
2022-06-14 18:05:41 +02:00
|
|
|
deviceSupport.onScreenshotReq();
|
2015-06-24 00:23:38 +02:00
|
|
|
break;
|
2015-08-21 00:58:18 +02:00
|
|
|
case ACTION_STARTAPP: {
|
|
|
|
UUID uuid = (UUID) intent.getSerializableExtra(EXTRA_APP_UUID);
|
2015-09-13 21:44:26 +02:00
|
|
|
boolean start = intent.getBooleanExtra(EXTRA_APP_START, true);
|
2022-06-14 18:05:41 +02:00
|
|
|
deviceSupport.onAppStart(uuid, start);
|
2015-05-18 22:20:01 +02:00
|
|
|
break;
|
2015-08-21 00:58:18 +02:00
|
|
|
}
|
2023-01-04 22:40:38 +01:00
|
|
|
case ACTION_DOWNLOADAPP: {
|
|
|
|
UUID uuid = (UUID) intent.getSerializableExtra(EXTRA_APP_UUID);
|
|
|
|
deviceSupport.onAppDownload(uuid);
|
|
|
|
break;
|
|
|
|
}
|
2015-08-21 00:58:18 +02:00
|
|
|
case ACTION_DELETEAPP: {
|
|
|
|
UUID uuid = (UUID) intent.getSerializableExtra(EXTRA_APP_UUID);
|
2022-06-14 18:05:41 +02:00
|
|
|
deviceSupport.onAppDelete(uuid);
|
2015-05-08 11:18:06 +02:00
|
|
|
break;
|
2015-08-21 00:58:18 +02:00
|
|
|
}
|
2016-03-03 14:23:17 +01:00
|
|
|
case ACTION_APP_CONFIGURE: {
|
|
|
|
UUID uuid = (UUID) intent.getSerializableExtra(EXTRA_APP_UUID);
|
|
|
|
String config = intent.getStringExtra(EXTRA_APP_CONFIG);
|
2017-08-01 00:03:28 +02:00
|
|
|
Integer id = null;
|
|
|
|
if (intent.hasExtra(EXTRA_APP_CONFIG_ID)) {
|
|
|
|
id = intent.getIntExtra(EXTRA_APP_CONFIG_ID, 0);
|
|
|
|
}
|
2022-06-14 18:05:41 +02:00
|
|
|
deviceSupport.onAppConfiguration(uuid, config, id);
|
2016-06-12 01:20:12 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case ACTION_APP_REORDER: {
|
|
|
|
UUID[] uuids = (UUID[]) intent.getSerializableExtra(EXTRA_APP_UUID);
|
2022-06-14 18:05:41 +02:00
|
|
|
deviceSupport.onAppReorder(uuids);
|
2016-06-12 01:20:12 +02:00
|
|
|
break;
|
2016-03-03 14:23:17 +01:00
|
|
|
}
|
2015-07-23 12:09:01 +02:00
|
|
|
case ACTION_INSTALL:
|
2015-08-21 00:58:18 +02:00
|
|
|
Uri uri = intent.getParcelableExtra(EXTRA_URI);
|
2015-08-06 02:17:38 +02:00
|
|
|
if (uri != null) {
|
2015-07-23 12:09:01 +02:00
|
|
|
LOG.info("will try to install app/fw");
|
2022-06-14 18:05:41 +02:00
|
|
|
deviceSupport.onInstallApp(uri);
|
2015-05-08 11:18:06 +02:00
|
|
|
}
|
|
|
|
break;
|
2015-06-24 20:14:08 +02:00
|
|
|
case ACTION_SET_ALARMS:
|
2019-01-07 01:10:57 +01:00
|
|
|
ArrayList<? extends Alarm> alarms = (ArrayList<? extends Alarm>) intent.getSerializableExtra(EXTRA_ALARMS);
|
2022-06-14 18:05:41 +02:00
|
|
|
deviceSupport.onSetAlarms(alarms);
|
2015-06-25 12:42:47 +02:00
|
|
|
break;
|
2021-12-04 16:55:09 +01:00
|
|
|
case ACTION_SET_REMINDERS:
|
|
|
|
ArrayList<? extends Reminder> reminders = (ArrayList<? extends Reminder>) intent.getSerializableExtra(EXTRA_REMINDERS);
|
2022-06-14 18:05:41 +02:00
|
|
|
deviceSupport.onSetReminders(reminders);
|
2021-12-04 16:55:09 +01:00
|
|
|
break;
|
2023-07-04 00:19:19 +02:00
|
|
|
case ACTION_SET_LOYALTY_CARDS:
|
|
|
|
final ArrayList<LoyaltyCard> loyaltyCards = (ArrayList<LoyaltyCard>) intent.getSerializableExtra(EXTRA_LOYALTY_CARDS);
|
|
|
|
deviceSupport.onSetLoyaltyCards(loyaltyCards);
|
|
|
|
break;
|
2022-05-09 20:47:08 +02:00
|
|
|
case ACTION_SET_WORLD_CLOCKS:
|
|
|
|
ArrayList<? extends WorldClock> clocks = (ArrayList<? extends WorldClock>) intent.getSerializableExtra(EXTRA_WORLD_CLOCKS);
|
2022-06-14 18:05:41 +02:00
|
|
|
deviceSupport.onSetWorldClocks(clocks);
|
2022-05-09 20:47:08 +02:00
|
|
|
break;
|
2023-05-18 00:43:29 +02:00
|
|
|
case ACTION_SET_CONTACTS:
|
|
|
|
ArrayList<? extends Contact> contacts = (ArrayList<? extends Contact>) intent.getSerializableExtra(EXTRA_CONTACTS);
|
|
|
|
deviceSupport.onSetContacts(contacts);
|
|
|
|
break;
|
2016-04-03 22:38:06 +02:00
|
|
|
case ACTION_ENABLE_REALTIME_STEPS: {
|
|
|
|
boolean enable = intent.getBooleanExtra(EXTRA_BOOLEAN_ENABLE, false);
|
2022-06-14 18:05:41 +02:00
|
|
|
deviceSupport.onEnableRealtimeSteps(enable);
|
2015-09-02 08:00:26 +02:00
|
|
|
break;
|
2016-04-03 22:38:06 +02:00
|
|
|
}
|
|
|
|
case ACTION_ENABLE_HEARTRATE_SLEEP_SUPPORT: {
|
|
|
|
boolean enable = intent.getBooleanExtra(EXTRA_BOOLEAN_ENABLE, false);
|
2022-06-14 18:05:41 +02:00
|
|
|
deviceSupport.onEnableHeartRateSleepSupport(enable);
|
2016-04-03 22:38:06 +02:00
|
|
|
break;
|
|
|
|
}
|
2017-11-11 00:04:51 +01:00
|
|
|
case ACTION_SET_HEARTRATE_MEASUREMENT_INTERVAL: {
|
2018-09-15 23:56:44 +02:00
|
|
|
int seconds = intent.getIntExtra(EXTRA_INTERVAL_SECONDS, 0);
|
2022-06-14 18:05:41 +02:00
|
|
|
deviceSupport.onSetHeartRateMeasurementInterval(seconds);
|
2017-11-11 00:04:51 +01:00
|
|
|
break;
|
|
|
|
}
|
2016-04-12 23:12:15 +02:00
|
|
|
case ACTION_ENABLE_REALTIME_HEARTRATE_MEASUREMENT: {
|
|
|
|
boolean enable = intent.getBooleanExtra(EXTRA_BOOLEAN_ENABLE, false);
|
2022-06-14 18:05:41 +02:00
|
|
|
deviceSupport.onEnableRealtimeHeartRateMeasurement(enable);
|
2016-04-12 23:12:15 +02:00
|
|
|
break;
|
|
|
|
}
|
2016-11-13 20:47:24 +01:00
|
|
|
case ACTION_SEND_CONFIGURATION: {
|
|
|
|
String config = intent.getStringExtra(EXTRA_CONFIG);
|
2022-06-14 18:05:41 +02:00
|
|
|
deviceSupport.onSendConfiguration(config);
|
2016-11-13 20:47:24 +01:00
|
|
|
break;
|
|
|
|
}
|
2019-02-20 14:09:21 +01:00
|
|
|
case ACTION_READ_CONFIGURATION: {
|
|
|
|
String config = intent.getStringExtra(EXTRA_CONFIG);
|
2022-06-14 18:05:41 +02:00
|
|
|
deviceSupport.onReadConfiguration(config);
|
2019-02-20 14:09:21 +01:00
|
|
|
break;
|
|
|
|
}
|
2016-10-11 23:06:59 +02:00
|
|
|
case ACTION_TEST_NEW_FUNCTION: {
|
2022-06-14 18:05:41 +02:00
|
|
|
deviceSupport.onTestNewFunction();
|
2016-10-11 23:06:59 +02:00
|
|
|
break;
|
|
|
|
}
|
2016-12-31 15:56:05 +01:00
|
|
|
case ACTION_SEND_WEATHER: {
|
2017-11-29 23:57:36 +01:00
|
|
|
WeatherSpec weatherSpec = intent.getParcelableExtra(EXTRA_WEATHER);
|
|
|
|
if (weatherSpec != null) {
|
2022-06-14 18:05:41 +02:00
|
|
|
deviceSupport.onSendWeather(weatherSpec);
|
2017-11-29 23:57:36 +01:00
|
|
|
}
|
2016-12-31 15:56:05 +01:00
|
|
|
break;
|
|
|
|
}
|
2018-07-28 17:23:58 +02:00
|
|
|
case ACTION_SET_LED_COLOR:
|
|
|
|
int color = intent.getIntExtra(EXTRA_LED_COLOR, 0);
|
|
|
|
if (color != 0) {
|
2022-06-14 18:05:41 +02:00
|
|
|
deviceSupport.onSetLedColor(color);
|
2018-07-28 17:23:58 +02:00
|
|
|
}
|
|
|
|
break;
|
2021-12-24 15:20:57 +01:00
|
|
|
case ACTION_POWER_OFF:
|
2022-06-14 18:05:41 +02:00
|
|
|
deviceSupport.onPowerOff();
|
2021-12-24 15:20:57 +01:00
|
|
|
break;
|
2018-07-28 17:23:58 +02:00
|
|
|
case ACTION_SET_FM_FREQUENCY:
|
|
|
|
float frequency = intent.getFloatExtra(EXTRA_FM_FREQUENCY, -1);
|
|
|
|
if (frequency != -1) {
|
2022-06-14 18:05:41 +02:00
|
|
|
deviceSupport.onSetFmFrequency(frequency);
|
2018-07-28 17:23:58 +02:00
|
|
|
}
|
|
|
|
break;
|
2022-06-04 22:20:28 +02:00
|
|
|
case ACTION_SET_GPS_LOCATION:
|
|
|
|
final Location location = intent.getParcelableExtra(EXTRA_GPS_LOCATION);
|
2022-06-14 20:12:26 +02:00
|
|
|
deviceSupport.onSetGpsLocation(location);
|
2022-06-04 22:20:28 +02:00
|
|
|
break;
|
2015-01-12 00:35:15 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-23 00:54:28 +02:00
|
|
|
/**
|
|
|
|
* Disposes the current DeviceSupport instance (if any) and sets a new device support instance
|
|
|
|
* (if not null).
|
2015-09-13 21:44:26 +02:00
|
|
|
*
|
2022-06-14 18:05:41 +02:00
|
|
|
* @param deviceSupport deviceSupport to reokace/add
|
2015-08-23 00:54:28 +02:00
|
|
|
*/
|
2022-06-14 18:05:41 +02:00
|
|
|
private void setDeviceSupport(GBDevice device, DeviceSupport deviceSupport) throws DeviceNotFoundException {
|
|
|
|
DeviceStruct deviceStruct = getDeviceStruct(device);
|
|
|
|
DeviceSupport cachedDeviceSupport = deviceStruct.getDeviceSupport();
|
|
|
|
if (deviceSupport != cachedDeviceSupport && cachedDeviceSupport != null) {
|
|
|
|
cachedDeviceSupport.dispose();
|
|
|
|
}
|
|
|
|
deviceStruct.setDeviceSupport(deviceSupport);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void removeDeviceSupport(GBDevice device) throws DeviceNotFoundException {
|
|
|
|
DeviceStruct struct = getDeviceStruct(device);
|
|
|
|
if(struct.getDeviceSupport() != null){
|
|
|
|
struct.getDeviceSupport().dispose();
|
2015-08-23 00:54:28 +02:00
|
|
|
}
|
2022-06-14 18:05:41 +02:00
|
|
|
struct.setDeviceSupport(null);
|
|
|
|
}
|
|
|
|
|
|
|
|
private DeviceStruct getDeviceStructOrNull(GBDevice device){
|
|
|
|
DeviceStruct deviceStruct = null;
|
|
|
|
try {
|
|
|
|
deviceStruct = getDeviceStruct(device);
|
|
|
|
} catch (DeviceNotFoundException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
return deviceStruct;
|
|
|
|
}
|
|
|
|
|
|
|
|
public DeviceStruct getDeviceStruct(GBDevice device) throws DeviceNotFoundException {
|
|
|
|
if(device == null){
|
|
|
|
throw new DeviceNotFoundException("null");
|
|
|
|
}
|
|
|
|
for(DeviceStruct struct : deviceStructs){
|
|
|
|
if(struct.getDevice().equals(device)){
|
|
|
|
return struct;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
throw new DeviceNotFoundException(device);
|
|
|
|
}
|
|
|
|
|
|
|
|
public GBDevice getDeviceByAddress(String deviceAddress) throws DeviceNotFoundException {
|
|
|
|
if(deviceAddress == null){
|
|
|
|
throw new DeviceNotFoundException(deviceAddress);
|
|
|
|
}
|
|
|
|
for(DeviceStruct struct : deviceStructs){
|
|
|
|
if(struct.getDevice().getAddress().equals(deviceAddress)){
|
|
|
|
return struct.getDevice();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
throw new DeviceNotFoundException(deviceAddress);
|
|
|
|
}
|
|
|
|
|
|
|
|
public GBDevice getDeviceByAddressOrNull(String deviceAddress){
|
|
|
|
GBDevice device = null;
|
|
|
|
try {
|
|
|
|
device = getDeviceByAddress(deviceAddress);
|
|
|
|
} catch (DeviceNotFoundException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
return device;
|
|
|
|
}
|
|
|
|
|
|
|
|
private DeviceSupport getDeviceSupport(GBDevice device) throws DeviceNotFoundException {
|
|
|
|
if(device == null){
|
|
|
|
throw new DeviceNotFoundException("null");
|
|
|
|
}
|
|
|
|
for(DeviceStruct struct : deviceStructs){
|
|
|
|
if(struct.getDevice().equals(device)){
|
2022-08-21 21:53:49 +02:00
|
|
|
if(struct.getDeviceSupport() == null)
|
|
|
|
throw new DeviceNotFoundException(device);
|
|
|
|
|
2022-06-14 18:05:41 +02:00
|
|
|
return struct.getDeviceSupport();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
throw new DeviceNotFoundException(device);
|
2015-08-23 00:54:28 +02:00
|
|
|
}
|
|
|
|
|
2015-08-06 23:17:41 +02:00
|
|
|
private void start() {
|
|
|
|
if (!mStarted) {
|
2021-05-14 18:30:54 +02:00
|
|
|
GB.createNotificationChannels(this);
|
2017-10-30 21:37:31 +01:00
|
|
|
startForeground(GB.NOTIFICATION_ID, GB.createNotification(getString(R.string.gadgetbridge_running), this));
|
2015-08-06 23:17:41 +02:00
|
|
|
mStarted = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-23 00:54:28 +02:00
|
|
|
public boolean isStarted() {
|
|
|
|
return mStarted;
|
|
|
|
}
|
|
|
|
|
2022-06-14 18:05:41 +02:00
|
|
|
private boolean isDeviceConnected(GBDevice device) {
|
2022-09-04 23:05:57 +02:00
|
|
|
return isDeviceConnected(device.getAddress());
|
|
|
|
}
|
|
|
|
|
|
|
|
private boolean isDeviceConnected(String deviceAddress) {
|
2022-06-14 18:05:41 +02:00
|
|
|
for(DeviceStruct struct : deviceStructs){
|
2022-09-04 23:05:57 +02:00
|
|
|
if(struct.getDevice().getAddress().compareToIgnoreCase(deviceAddress) == 0){
|
2022-06-14 18:05:41 +02:00
|
|
|
return struct.getDevice().isConnected();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2015-04-13 11:22:03 +02:00
|
|
|
}
|
2015-04-13 01:01:52 +02:00
|
|
|
|
2022-06-14 18:05:41 +02:00
|
|
|
private boolean isDeviceConnecting(GBDevice device) {
|
2022-09-04 23:05:57 +02:00
|
|
|
return isDeviceConnecting(device.getAddress());
|
|
|
|
}
|
|
|
|
|
|
|
|
private boolean isDeviceConnecting(String deviceAddress) {
|
2022-06-14 18:05:41 +02:00
|
|
|
for(DeviceStruct struct : deviceStructs){
|
2022-09-04 23:05:57 +02:00
|
|
|
if(struct.getDevice().getAddress().compareToIgnoreCase(deviceAddress) == 0){
|
2022-06-14 18:05:41 +02:00
|
|
|
return struct.getDevice().isConnecting();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2015-08-07 13:24:54 +02:00
|
|
|
}
|
|
|
|
|
2022-06-14 18:05:41 +02:00
|
|
|
private boolean isDeviceInitialized(GBDevice device) {
|
2022-09-04 23:05:57 +02:00
|
|
|
return isDeviceInitialized(device.getAddress());
|
|
|
|
}
|
|
|
|
|
|
|
|
private boolean isDeviceInitialized(String deviceAddress) {
|
2022-06-14 18:05:41 +02:00
|
|
|
for(DeviceStruct struct : deviceStructs){
|
2022-09-04 23:05:57 +02:00
|
|
|
if(struct.getDevice().getAddress().compareToIgnoreCase(deviceAddress) == 0){
|
2022-06-14 18:05:41 +02:00
|
|
|
return struct.getDevice().isInitialized();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2015-04-13 13:26:22 +02:00
|
|
|
}
|
|
|
|
|
2023-03-31 21:07:56 +02:00
|
|
|
private boolean isDeviceReconnecting(GBDevice device) {
|
|
|
|
for(DeviceStruct struct : deviceStructs){
|
|
|
|
if(struct.getDevice().getAddress().compareToIgnoreCase(device.getAddress()) == 0){
|
|
|
|
return struct.getDevice().getStateOrdinal() == GBDevice.State.WAITING_FOR_RECONNECT.ordinal();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-07-20 17:29:40 +02:00
|
|
|
private boolean deviceHasCalendarReceiverRegistered(GBDevice device){
|
|
|
|
for (CalendarReceiver receiver: mCalendarReceiver){
|
|
|
|
if(receiver.getGBDevice().equals(device)){
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void setReceiversEnableState(boolean enable, boolean initialized, FeatureSet features, List <GBDevice> devicesWithCalendar) {
|
2015-10-15 17:23:16 +02:00
|
|
|
LOG.info("Setting broadcast receivers to: " + enable);
|
|
|
|
|
2022-06-14 18:05:41 +02:00
|
|
|
if(enable && features == null){
|
|
|
|
throw new RuntimeException("features cannot be null when enabling receivers");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (enable && initialized && features.supportsCalendarEvents()) {
|
2022-07-20 17:29:40 +02:00
|
|
|
for (GBDevice deviceWithCalendar : devicesWithCalendar) {
|
|
|
|
if (!deviceHasCalendarReceiverRegistered(deviceWithCalendar)) {
|
|
|
|
if (!(GBApplication.isRunningMarshmallowOrLater() && ContextCompat.checkSelfPermission(this, Manifest.permission.READ_CALENDAR) == PackageManager.PERMISSION_DENIED)) {
|
|
|
|
IntentFilter calendarIntentFilter = new IntentFilter();
|
|
|
|
calendarIntentFilter.addAction("android.intent.action.PROVIDER_CHANGED");
|
|
|
|
calendarIntentFilter.addDataScheme("content");
|
|
|
|
calendarIntentFilter.addDataAuthority("com.android.calendar", null);
|
|
|
|
CalendarReceiver receiver = new CalendarReceiver(deviceWithCalendar);
|
|
|
|
registerReceiver(receiver, calendarIntentFilter);
|
|
|
|
mCalendarReceiver.add(receiver);
|
2022-11-23 21:10:28 +01:00
|
|
|
// Add a receiver to allow us to quickly force as calendar sync (without having to provide data)
|
|
|
|
registerReceiver(receiver, new IntentFilter("FORCE_CALENDAR_SYNC"));
|
2022-07-20 17:29:40 +02:00
|
|
|
}
|
2017-05-09 12:32:00 +02:00
|
|
|
}
|
2017-04-17 21:09:29 +02:00
|
|
|
}
|
2017-04-19 21:51:23 +02:00
|
|
|
if (mAlarmReceiver == null) {
|
|
|
|
mAlarmReceiver = new AlarmReceiver();
|
|
|
|
registerReceiver(mAlarmReceiver, new IntentFilter("DAILY_ALARM"));
|
|
|
|
}
|
|
|
|
} else {
|
2022-07-20 17:29:40 +02:00
|
|
|
for (CalendarReceiver registeredReceiver: mCalendarReceiver){
|
|
|
|
unregisterReceiver(registeredReceiver);
|
2017-04-19 21:51:23 +02:00
|
|
|
}
|
2022-07-20 17:29:40 +02:00
|
|
|
mCalendarReceiver.clear();
|
2017-04-19 21:51:23 +02:00
|
|
|
if (mAlarmReceiver != null) {
|
|
|
|
unregisterReceiver(mAlarmReceiver);
|
|
|
|
mAlarmReceiver = null;
|
|
|
|
}
|
2017-04-17 21:09:29 +02:00
|
|
|
}
|
|
|
|
|
2015-10-15 17:23:16 +02:00
|
|
|
if (enable) {
|
|
|
|
if (mPhoneCallReceiver == null) {
|
|
|
|
mPhoneCallReceiver = new PhoneCallReceiver();
|
|
|
|
IntentFilter filter = new IntentFilter();
|
|
|
|
filter.addAction("android.intent.action.PHONE_STATE");
|
|
|
|
filter.addAction("android.intent.action.NEW_OUTGOING_CALL");
|
2019-05-25 15:56:21 +02:00
|
|
|
filter.addAction("nodomain.freeyourgadget.gadgetbridge.MUTE_CALL");
|
2015-10-15 17:23:16 +02:00
|
|
|
registerReceiver(mPhoneCallReceiver, filter);
|
|
|
|
}
|
|
|
|
if (mSMSReceiver == null) {
|
|
|
|
mSMSReceiver = new SMSReceiver();
|
|
|
|
registerReceiver(mSMSReceiver, new IntentFilter("android.provider.Telephony.SMS_RECEIVED"));
|
|
|
|
}
|
|
|
|
if (mPebbleReceiver == null) {
|
|
|
|
mPebbleReceiver = new PebbleReceiver();
|
|
|
|
registerReceiver(mPebbleReceiver, new IntentFilter("com.getpebble.action.SEND_NOTIFICATION"));
|
|
|
|
}
|
2022-06-14 18:05:41 +02:00
|
|
|
if (mMusicPlaybackReceiver == null && features.supportsMusicInfo()) {
|
2015-10-15 17:23:16 +02:00
|
|
|
mMusicPlaybackReceiver = new MusicPlaybackReceiver();
|
2016-04-04 20:08:34 +02:00
|
|
|
IntentFilter filter = new IntentFilter();
|
2017-12-17 22:35:17 +01:00
|
|
|
for (String action : mMusicActions) {
|
2017-02-11 09:49:01 +01:00
|
|
|
filter.addAction(action);
|
|
|
|
}
|
2016-04-04 20:08:34 +02:00
|
|
|
registerReceiver(mMusicPlaybackReceiver, filter);
|
2015-10-15 17:23:16 +02:00
|
|
|
}
|
|
|
|
if (mTimeChangeReceiver == null) {
|
|
|
|
mTimeChangeReceiver = new TimeChangeReceiver();
|
|
|
|
IntentFilter filter = new IntentFilter();
|
|
|
|
filter.addAction("android.intent.action.TIME_SET");
|
|
|
|
filter.addAction("android.intent.action.TIMEZONE_CHANGED");
|
2024-02-15 21:07:08 +01:00
|
|
|
filter.addAction(TimeChangeReceiver.ACTION_DST_CHANGED_OR_PERIODIC_SYNC);
|
2015-10-15 17:23:16 +02:00
|
|
|
registerReceiver(mTimeChangeReceiver, filter);
|
2024-02-15 21:32:44 +01:00
|
|
|
// Ensure alarm is scheduled after registering broadcast receiver
|
|
|
|
// (this is important in case receiver was unregistered when the previous alarm arrived).
|
|
|
|
TimeChangeReceiver.ifEnabledScheduleNextDstChangeOrPeriodicSync(this);
|
2015-10-15 17:23:16 +02:00
|
|
|
}
|
2017-04-18 11:47:28 +02:00
|
|
|
if (mBlueToothPairingRequestReceiver == null) {
|
|
|
|
mBlueToothPairingRequestReceiver = new BluetoothPairingRequestReceiver(this);
|
|
|
|
registerReceiver(mBlueToothPairingRequestReceiver, new IntentFilter(BluetoothDevice.ACTION_PAIRING_REQUEST));
|
|
|
|
}
|
2017-02-07 23:49:10 +01:00
|
|
|
if (mAlarmClockReceiver == null) {
|
|
|
|
mAlarmClockReceiver = new AlarmClockReceiver();
|
|
|
|
IntentFilter filter = new IntentFilter();
|
|
|
|
filter.addAction(AlarmClockReceiver.ALARM_ALERT_ACTION);
|
|
|
|
filter.addAction(AlarmClockReceiver.ALARM_DONE_ACTION);
|
2018-08-10 18:36:29 +02:00
|
|
|
filter.addAction(AlarmClockReceiver.GOOGLE_CLOCK_ALARM_ALERT_ACTION);
|
|
|
|
filter.addAction(AlarmClockReceiver.GOOGLE_CLOCK_ALARM_DONE_ACTION);
|
2017-02-07 23:49:10 +01:00
|
|
|
registerReceiver(mAlarmClockReceiver, filter);
|
|
|
|
}
|
2019-08-22 21:31:08 +02:00
|
|
|
|
2023-12-11 11:50:31 +01:00
|
|
|
if (mSilentModeReceiver == null) {
|
|
|
|
mSilentModeReceiver = new SilentModeReceiver();
|
|
|
|
IntentFilter filter = new IntentFilter();
|
|
|
|
filter.addAction(AudioManager.RINGER_MODE_CHANGED_ACTION);
|
|
|
|
registerReceiver(mSilentModeReceiver, filter);
|
|
|
|
}
|
|
|
|
|
2022-08-05 23:43:39 +02:00
|
|
|
if (mOsmandAidlHelper == null && features.supportsNavigation()) {
|
2021-10-21 18:39:01 +02:00
|
|
|
mOsmandAidlHelper = new OsmandEventReceiver(this.getApplication());
|
|
|
|
}
|
|
|
|
|
2020-07-05 21:54:10 +02:00
|
|
|
// Weather receivers
|
2022-06-14 18:05:41 +02:00
|
|
|
if (features.supportsWeather()) {
|
2020-07-05 21:54:10 +02:00
|
|
|
if (GBApplication.isRunningOreoOrLater()) {
|
|
|
|
if (mLineageOsWeatherReceiver == null) {
|
|
|
|
mLineageOsWeatherReceiver = new LineageOsWeatherReceiver();
|
|
|
|
registerReceiver(mLineageOsWeatherReceiver, new IntentFilter("GB_UPDATE_WEATHER"));
|
|
|
|
}
|
2021-10-21 18:39:01 +02:00
|
|
|
} else {
|
2020-07-05 21:54:10 +02:00
|
|
|
if (mCMWeatherReceiver == null) {
|
|
|
|
mCMWeatherReceiver = new CMWeatherReceiver();
|
|
|
|
registerReceiver(mCMWeatherReceiver, new IntentFilter("GB_UPDATE_WEATHER"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (mTinyWeatherForecastGermanyReceiver == null) {
|
|
|
|
mTinyWeatherForecastGermanyReceiver = new TinyWeatherForecastGermanyReceiver();
|
|
|
|
registerReceiver(mTinyWeatherForecastGermanyReceiver, new IntentFilter("de.kaffeemitkoffein.broadcast.WEATHERDATA"));
|
|
|
|
}
|
2022-08-22 02:30:13 +02:00
|
|
|
if (mGenericWeatherReceiver == null) {
|
|
|
|
mGenericWeatherReceiver = new GenericWeatherReceiver();
|
|
|
|
registerReceiver(mGenericWeatherReceiver, new IntentFilter(GenericWeatherReceiver.ACTION_GENERIC_WEATHER));
|
|
|
|
}
|
2020-07-05 21:54:10 +02:00
|
|
|
if (mOmniJawsObserver == null) {
|
|
|
|
try {
|
|
|
|
mOmniJawsObserver = new OmniJawsObserver(new Handler());
|
|
|
|
getContentResolver().registerContentObserver(OmniJawsObserver.WEATHER_URI, true, mOmniJawsObserver);
|
|
|
|
} catch (PackageManager.NameNotFoundException e) {
|
|
|
|
//Nothing wrong, it just means we're not running on omnirom.
|
|
|
|
}
|
2017-12-17 22:35:17 +01:00
|
|
|
}
|
|
|
|
}
|
2020-07-05 21:54:10 +02:00
|
|
|
|
2018-06-23 11:19:09 +02:00
|
|
|
if (GBApplication.getPrefs().getBoolean("auto_fetch_enabled", false) &&
|
2022-06-14 18:05:41 +02:00
|
|
|
features.supportsActivityDataFetching() && mGBAutoFetchReceiver == null) {
|
2018-06-23 11:19:09 +02:00
|
|
|
mGBAutoFetchReceiver = new GBAutoFetchReceiver();
|
|
|
|
registerReceiver(mGBAutoFetchReceiver, new IntentFilter("android.intent.action.USER_PRESENT"));
|
|
|
|
}
|
2015-10-15 17:23:16 +02:00
|
|
|
} else {
|
|
|
|
if (mPhoneCallReceiver != null) {
|
|
|
|
unregisterReceiver(mPhoneCallReceiver);
|
|
|
|
mPhoneCallReceiver = null;
|
|
|
|
}
|
|
|
|
if (mSMSReceiver != null) {
|
|
|
|
unregisterReceiver(mSMSReceiver);
|
|
|
|
mSMSReceiver = null;
|
|
|
|
}
|
|
|
|
if (mPebbleReceiver != null) {
|
|
|
|
unregisterReceiver(mPebbleReceiver);
|
|
|
|
mPebbleReceiver = null;
|
|
|
|
}
|
|
|
|
if (mMusicPlaybackReceiver != null) {
|
|
|
|
unregisterReceiver(mMusicPlaybackReceiver);
|
|
|
|
mMusicPlaybackReceiver = null;
|
|
|
|
}
|
|
|
|
if (mTimeChangeReceiver != null) {
|
|
|
|
unregisterReceiver(mTimeChangeReceiver);
|
|
|
|
mTimeChangeReceiver = null;
|
|
|
|
}
|
2017-04-18 11:47:28 +02:00
|
|
|
|
|
|
|
if (mBlueToothPairingRequestReceiver != null) {
|
|
|
|
unregisterReceiver(mBlueToothPairingRequestReceiver);
|
|
|
|
mBlueToothPairingRequestReceiver = null;
|
|
|
|
}
|
2017-02-07 23:49:10 +01:00
|
|
|
if (mAlarmClockReceiver != null) {
|
|
|
|
unregisterReceiver(mAlarmClockReceiver);
|
|
|
|
mAlarmClockReceiver = null;
|
|
|
|
}
|
2023-12-11 11:50:31 +01:00
|
|
|
if (mSilentModeReceiver != null) {
|
|
|
|
unregisterReceiver(mSilentModeReceiver);
|
|
|
|
mSilentModeReceiver = null;
|
|
|
|
}
|
2017-11-29 23:57:36 +01:00
|
|
|
if (mCMWeatherReceiver != null) {
|
|
|
|
unregisterReceiver(mCMWeatherReceiver);
|
|
|
|
mCMWeatherReceiver = null;
|
2019-08-22 17:57:26 +02:00
|
|
|
}
|
|
|
|
if (mLineageOsWeatherReceiver != null) {
|
|
|
|
unregisterReceiver(mLineageOsWeatherReceiver);
|
|
|
|
mLineageOsWeatherReceiver = null;
|
2017-11-29 23:57:36 +01:00
|
|
|
}
|
2017-12-17 22:35:17 +01:00
|
|
|
if (mOmniJawsObserver != null) {
|
|
|
|
getContentResolver().unregisterContentObserver(mOmniJawsObserver);
|
2020-07-05 21:54:10 +02:00
|
|
|
mOmniJawsObserver = null;
|
|
|
|
}
|
|
|
|
if (mTinyWeatherForecastGermanyReceiver != null) {
|
|
|
|
unregisterReceiver(mTinyWeatherForecastGermanyReceiver);
|
|
|
|
mTinyWeatherForecastGermanyReceiver = null;
|
2017-12-17 22:35:17 +01:00
|
|
|
}
|
2021-10-19 14:32:20 +02:00
|
|
|
if (mOsmandAidlHelper != null) {
|
|
|
|
mOsmandAidlHelper.cleanupResources();
|
|
|
|
mOsmandAidlHelper = null;
|
|
|
|
}
|
2018-06-23 11:19:09 +02:00
|
|
|
if (mGBAutoFetchReceiver != null) {
|
|
|
|
unregisterReceiver(mGBAutoFetchReceiver);
|
|
|
|
mGBAutoFetchReceiver = null;
|
|
|
|
}
|
2022-08-22 02:30:13 +02:00
|
|
|
if (mGenericWeatherReceiver != null) {
|
|
|
|
unregisterReceiver(mGenericWeatherReceiver);
|
|
|
|
mGenericWeatherReceiver = null;
|
|
|
|
}
|
2015-10-15 17:23:16 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-31 21:07:56 +02:00
|
|
|
private void sendCachedNotifications(GBDevice device) {
|
|
|
|
ArrayList<Intent> notifCache = cachedNotifications.get(device.getAddress());
|
|
|
|
if (notifCache == null) return;
|
|
|
|
try {
|
|
|
|
while (notifCache.size() > 0) {
|
|
|
|
handleAction(notifCache.remove(0), ACTION_NOTIFICATION, device);
|
|
|
|
}
|
|
|
|
} catch (DeviceNotFoundException e) {
|
|
|
|
LOG.error("Error while sending cached notifications to "+device.getAliasOrName(), e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-13 11:22:03 +02:00
|
|
|
@Override
|
2015-01-12 00:35:15 +01:00
|
|
|
public void onDestroy() {
|
2016-04-29 21:49:17 +02:00
|
|
|
if (hasPrefs()) {
|
|
|
|
getPrefs().getPreferences().unregisterOnSharedPreferenceChangeListener(this);
|
|
|
|
}
|
2016-04-28 23:17:13 +02:00
|
|
|
|
2015-08-04 01:01:14 +02:00
|
|
|
LOG.debug("DeviceCommunicationService is being destroyed");
|
2015-01-12 00:35:15 +01:00
|
|
|
super.onDestroy();
|
2015-02-02 21:16:42 +01:00
|
|
|
|
2015-04-19 15:11:03 +02:00
|
|
|
LocalBroadcastManager.getInstance(this).unregisterReceiver(mReceiver);
|
2022-07-20 17:29:40 +02:00
|
|
|
setReceiversEnableState(false, false, null, null); // disable BroadcastReceivers
|
2015-02-02 21:16:42 +01:00
|
|
|
|
2022-06-14 18:05:41 +02:00
|
|
|
unregisterReceiver(mBlueToothConnectReceiver);
|
2022-08-05 15:22:21 +02:00
|
|
|
mBlueToothConnectReceiver = null;
|
|
|
|
|
|
|
|
unregisterReceiver(mAutoConnectInvervalReceiver);
|
|
|
|
mAutoConnectInvervalReceiver.destroy();
|
|
|
|
mAutoConnectInvervalReceiver = null;
|
2022-06-14 18:05:41 +02:00
|
|
|
|
|
|
|
for(GBDevice device : getGBDevices()){
|
|
|
|
try {
|
|
|
|
removeDeviceSupport(device);
|
|
|
|
} catch (DeviceNotFoundException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
2021-05-14 18:30:54 +02:00
|
|
|
GB.removeNotification(GB.NOTIFICATION_ID, this); // need to do this because the updated notification won't be cancelled when service stops
|
2022-09-04 23:05:57 +02:00
|
|
|
|
|
|
|
unregisterReceiver(bluetoothCommandReceiver);
|
2022-09-17 16:23:10 +02:00
|
|
|
unregisterReceiver(deviceSettingsReceiver);
|
2022-10-29 01:28:45 +02:00
|
|
|
unregisterReceiver(intentApiReceiver);
|
2015-01-12 00:35:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public IBinder onBind(Intent intent) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2016-04-28 23:17:13 +02:00
|
|
|
@Override
|
|
|
|
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
|
2022-06-14 18:05:41 +02:00
|
|
|
if (GBPrefs.DEVICE_AUTO_RECONNECT.equals(key)) {
|
|
|
|
for(DeviceStruct deviceStruct : deviceStructs){
|
|
|
|
boolean autoReconnect = getGBPrefs().getAutoReconnect(deviceStruct.getDevice());
|
|
|
|
deviceStruct.getDeviceSupport().setAutoReconnect(autoReconnect);
|
2016-04-28 23:17:13 +02:00
|
|
|
}
|
|
|
|
}
|
2018-08-16 13:13:12 +02:00
|
|
|
if (GBPrefs.CHART_MAX_HEART_RATE.equals(key) || GBPrefs.CHART_MIN_HEART_RATE.equals(key)) {
|
|
|
|
HeartRateUtils.getInstance().updateCachedHeartRatePreferences();
|
|
|
|
}
|
2022-09-04 23:05:57 +02:00
|
|
|
if (GBPrefs.PREF_ALLOW_INTENT_API.equals(key)){
|
|
|
|
allowBluetoothIntentApi = sharedPreferences.getBoolean(GBPrefs.PREF_ALLOW_INTENT_API, false);
|
|
|
|
GB.log("allowBluetoothIntentApi changed to " + allowBluetoothIntentApi, GB.INFO, null);
|
|
|
|
}
|
2016-04-28 23:17:13 +02:00
|
|
|
}
|
2016-04-29 21:49:17 +02:00
|
|
|
|
|
|
|
protected boolean hasPrefs() {
|
|
|
|
return getPrefs().getPreferences() != null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Prefs getPrefs() {
|
|
|
|
return GBApplication.getPrefs();
|
|
|
|
}
|
|
|
|
|
|
|
|
public GBPrefs getGBPrefs() {
|
|
|
|
return GBApplication.getGBPrefs();
|
|
|
|
}
|
2016-05-22 01:19:28 +02:00
|
|
|
|
2022-06-14 18:05:41 +02:00
|
|
|
public GBDevice[] getGBDevices() {
|
|
|
|
GBDevice[] devices = new GBDevice[deviceStructs.size()];
|
|
|
|
for(int i = 0; i < devices.length; i++){
|
|
|
|
devices[i] = deviceStructs.get(i).getDevice();
|
|
|
|
}
|
|
|
|
return devices;
|
2016-05-22 01:19:28 +02:00
|
|
|
}
|
2015-01-30 11:59:36 +01:00
|
|
|
}
|