2021-01-10 23:37:09 +01:00
|
|
|
/* Copyright (C) 2015-2021 Andreas Shimokawa, Carsten Pfeiffer, Daniele
|
2019-02-13 20:43:30 +01:00
|
|
|
Gobbetti, José Rebelo, Matthieu Baerts
|
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
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
2015-08-03 23:09:49 +02:00
|
|
|
package nodomain.freeyourgadget.gadgetbridge.devices.pebble;
|
2015-05-05 00:48:02 +02:00
|
|
|
|
|
|
|
import android.app.Activity;
|
2015-08-06 02:17:38 +02:00
|
|
|
import android.content.Context;
|
|
|
|
import android.net.Uri;
|
2015-05-05 00:48:02 +02:00
|
|
|
|
2019-01-26 15:52:40 +01:00
|
|
|
import androidx.annotation.NonNull;
|
2020-10-13 00:25:43 +02:00
|
|
|
|
2021-05-29 16:42:32 +02:00
|
|
|
import java.io.File;
|
|
|
|
import java.io.IOException;
|
2022-06-14 18:05:41 +02:00
|
|
|
import java.util.List;
|
2021-05-29 16:42:32 +02:00
|
|
|
|
2016-10-24 20:02:44 +02:00
|
|
|
import de.greenrobot.dao.query.QueryBuilder;
|
2015-08-11 11:21:10 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
2016-10-24 20:02:44 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.GBException;
|
2020-10-13 00:25:43 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.R;
|
2016-06-14 15:56:38 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.activities.appmanager.AppManagerActivity;
|
2022-07-10 22:01:20 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.devices.AbstractBLClassicDeviceCoordinator;
|
2015-08-06 02:17:38 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.devices.InstallHandler;
|
2015-08-11 11:21:10 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.devices.SampleProvider;
|
2016-06-16 21:54:53 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.entities.AbstractActivitySample;
|
2016-05-08 23:14:58 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.entities.DaoSession;
|
2016-10-24 20:02:44 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.entities.Device;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.entities.PebbleHealthActivityOverlayDao;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.entities.PebbleHealthActivitySampleDao;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.entities.PebbleMisfitSampleDao;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.entities.PebbleMorpheuzSampleDao;
|
2015-08-11 11:21:10 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
2015-08-03 23:09:49 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.impl.GBDeviceCandidate;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.model.DeviceType;
|
2023-08-20 04:14:06 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.service.DeviceSupport;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.service.devices.pebble.PebbleSupport;
|
2016-11-15 23:41:35 +01:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.util.PebbleUtils;
|
2016-04-25 23:18:55 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.util.Prefs;
|
2015-05-05 00:48:02 +02:00
|
|
|
|
2022-07-10 22:01:20 +02:00
|
|
|
public class PebbleCoordinator extends AbstractBLClassicDeviceCoordinator {
|
2015-07-27 23:49:53 +02:00
|
|
|
public PebbleCoordinator() {
|
|
|
|
}
|
|
|
|
|
2017-04-19 21:51:23 +02:00
|
|
|
@NonNull
|
2015-05-05 00:48:02 +02:00
|
|
|
@Override
|
2016-11-27 01:09:20 +01:00
|
|
|
public DeviceType getSupportedType(GBDeviceCandidate candidate) {
|
2016-07-12 00:24:23 +02:00
|
|
|
String name = candidate.getDevice().getName();
|
2016-11-27 01:09:20 +01:00
|
|
|
if (name != null && name.startsWith("Pebble")) {
|
|
|
|
return DeviceType.PEBBLE;
|
|
|
|
}
|
|
|
|
return DeviceType.UNKNOWN;
|
2015-05-05 00:48:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public DeviceType getDeviceType() {
|
|
|
|
return DeviceType.PEBBLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Class<? extends Activity> getPairingActivity() {
|
2016-11-19 22:13:00 +01:00
|
|
|
return PebblePairingActivity.class;
|
2015-05-05 00:48:02 +02:00
|
|
|
}
|
2015-07-20 23:20:24 +02:00
|
|
|
|
2016-10-24 20:02:44 +02:00
|
|
|
@Override
|
2017-04-19 21:51:23 +02:00
|
|
|
protected void deleteDevice(@NonNull GBDevice gbDevice, @NonNull Device device, @NonNull DaoSession session) throws GBException {
|
2016-10-24 20:02:44 +02:00
|
|
|
Long deviceId = device.getId();
|
|
|
|
QueryBuilder<?> qb = session.getPebbleHealthActivitySampleDao().queryBuilder();
|
|
|
|
qb.where(PebbleHealthActivitySampleDao.Properties.DeviceId.eq(deviceId)).buildDelete().executeDeleteWithoutDetachingEntities();
|
|
|
|
qb = session.getPebbleHealthActivityOverlayDao().queryBuilder();
|
|
|
|
qb.where(PebbleHealthActivityOverlayDao.Properties.DeviceId.eq(deviceId)).buildDelete().executeDeleteWithoutDetachingEntities();
|
|
|
|
qb = session.getPebbleMisfitSampleDao().queryBuilder();
|
|
|
|
qb.where(PebbleMisfitSampleDao.Properties.DeviceId.eq(deviceId)).buildDelete().executeDeleteWithoutDetachingEntities();
|
|
|
|
qb = session.getPebbleMorpheuzSampleDao().queryBuilder();
|
|
|
|
qb.where(PebbleMorpheuzSampleDao.Properties.DeviceId.eq(deviceId)).buildDelete().executeDeleteWithoutDetachingEntities();
|
|
|
|
}
|
|
|
|
|
2015-07-27 23:49:53 +02:00
|
|
|
@Override
|
2016-06-27 20:41:20 +02:00
|
|
|
public SampleProvider<? extends AbstractActivitySample> getSampleProvider(GBDevice device, DaoSession session) {
|
2016-04-25 23:18:55 +02:00
|
|
|
Prefs prefs = GBApplication.getPrefs();
|
2016-04-25 23:39:03 +02:00
|
|
|
int activityTracker = prefs.getInt("pebble_activitytracker", SampleProvider.PROVIDER_PEBBLE_HEALTH);
|
2016-02-18 20:41:22 +01:00
|
|
|
switch (activityTracker) {
|
|
|
|
case SampleProvider.PROVIDER_PEBBLE_HEALTH:
|
2016-07-30 23:22:27 +02:00
|
|
|
return new PebbleHealthSampleProvider(device, session);
|
2016-02-18 20:41:22 +01:00
|
|
|
case SampleProvider.PROVIDER_PEBBLE_MISFIT:
|
2016-07-30 23:22:27 +02:00
|
|
|
return new PebbleMisfitSampleProvider(device, session);
|
2016-02-18 20:41:22 +01:00
|
|
|
case SampleProvider.PROVIDER_PEBBLE_MORPHEUZ:
|
2016-07-30 23:22:27 +02:00
|
|
|
return new PebbleMorpheuzSampleProvider(device, session);
|
2016-02-18 20:41:22 +01:00
|
|
|
default:
|
2016-07-30 23:22:27 +02:00
|
|
|
return new PebbleHealthSampleProvider(device, session);
|
2015-08-16 23:30:16 +02:00
|
|
|
}
|
2015-07-27 23:49:53 +02:00
|
|
|
}
|
2015-08-06 02:17:38 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public InstallHandler findInstallHandler(Uri uri, Context context) {
|
|
|
|
PBWInstallHandler installHandler = new PBWInstallHandler(uri, context);
|
|
|
|
return installHandler.isValid() ? installHandler : null;
|
|
|
|
}
|
2015-10-24 23:28:02 +02:00
|
|
|
|
2022-07-06 23:09:36 +02:00
|
|
|
@Override
|
|
|
|
public boolean supportsFlashing() { return true; }
|
|
|
|
|
2015-10-24 23:28:02 +02:00
|
|
|
@Override
|
|
|
|
public boolean supportsActivityDataFetching() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-09-20 22:02:40 +02:00
|
|
|
@Override
|
|
|
|
public boolean supportsActivityTracking() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-10-24 23:28:02 +02:00
|
|
|
@Override
|
|
|
|
public boolean supportsScreenshots() {
|
|
|
|
return true;
|
|
|
|
}
|
2016-03-20 17:53:55 +01:00
|
|
|
|
2018-11-24 12:16:47 +01:00
|
|
|
@Override
|
2023-06-13 23:02:26 +02:00
|
|
|
public int getAlarmSlotCount(GBDevice device) {
|
2018-11-24 12:16:47 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-01-26 20:55:00 +01:00
|
|
|
@Override
|
|
|
|
public boolean supportsSmartWakeup(GBDevice device) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-06-19 23:22:28 +02:00
|
|
|
@Override
|
|
|
|
public boolean supportsHeartRateMeasurement(GBDevice device) {
|
2016-11-15 23:41:35 +01:00
|
|
|
return PebbleUtils.hasHRM(device.getModel());
|
2016-06-19 23:22:28 +02:00
|
|
|
}
|
|
|
|
|
2016-05-13 23:47:47 +02:00
|
|
|
@Override
|
|
|
|
public String getManufacturer() {
|
|
|
|
return "Pebble";
|
|
|
|
}
|
2016-10-25 17:39:11 +02:00
|
|
|
|
|
|
|
@Override
|
2023-06-11 00:31:38 +02:00
|
|
|
public boolean supportsAppsManagement(final GBDevice device) {
|
2016-10-25 17:39:11 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Class<? extends Activity> getAppsManagementActivity() {
|
|
|
|
return AppManagerActivity.class;
|
|
|
|
}
|
2017-02-25 22:02:40 +01:00
|
|
|
|
2021-05-29 16:42:32 +02:00
|
|
|
@Override
|
|
|
|
public File getAppCacheDir() throws IOException {
|
|
|
|
return PebbleUtils.getPbwCacheDir();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getAppCacheSortFilename() {
|
|
|
|
return "pbwcacheorder.txt";
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getAppFileExtension() {
|
|
|
|
return ".pbw";
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean supportsAppListFetching() {
|
2022-06-14 18:05:41 +02:00
|
|
|
List<GBDevice> devices = GBApplication.app().getDeviceManager().getSelectedDevices();
|
|
|
|
for(GBDevice device : devices){
|
|
|
|
if(device.getType() == DeviceType.PEBBLE){
|
|
|
|
if (device.getFirmwareVersion() != null) {
|
|
|
|
return PebbleUtils.getFwMajor(device.getFirmwareVersion()) < 3;
|
|
|
|
}
|
|
|
|
}
|
2021-05-29 16:42:32 +02:00
|
|
|
}
|
2022-06-14 18:05:41 +02:00
|
|
|
|
2021-05-29 16:42:32 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean supportsAppReordering() {
|
2022-06-14 18:05:41 +02:00
|
|
|
List<GBDevice> devices = GBApplication.app().getDeviceManager().getSelectedDevices();
|
|
|
|
for(GBDevice device : devices){
|
|
|
|
if(device.getType() == DeviceType.PEBBLE){
|
|
|
|
if (device.getFirmwareVersion() != null) {
|
|
|
|
return PebbleUtils.getFwMajor(device.getFirmwareVersion()) >= 3;
|
|
|
|
}
|
|
|
|
}
|
2021-05-29 16:42:32 +02:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-04-19 21:51:23 +02:00
|
|
|
@Override
|
|
|
|
public boolean supportsCalendarEvents() {
|
|
|
|
return true;
|
|
|
|
}
|
2017-04-20 14:34:32 +02:00
|
|
|
|
2017-06-02 21:59:46 +02:00
|
|
|
@Override
|
|
|
|
public boolean supportsRealtimeData() {
|
|
|
|
return false;
|
|
|
|
}
|
2017-12-11 19:09:37 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean supportsWeather() {
|
|
|
|
return true;
|
|
|
|
}
|
2018-07-26 21:57:12 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean supportsFindDevice() {
|
|
|
|
return true;
|
|
|
|
}
|
2018-08-07 12:44:00 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean supportsMusicInfo() {
|
|
|
|
return true;
|
|
|
|
}
|
2018-11-25 23:56:52 +01:00
|
|
|
|
|
|
|
@Override
|
2020-10-13 00:25:43 +02:00
|
|
|
public boolean supportsUnicodeEmojis() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int[] getSupportedDeviceSpecificSettings(GBDevice device) {
|
|
|
|
return new int[]{
|
2021-03-08 15:05:33 +01:00
|
|
|
R.xml.devicesettings_autoremove_notifications,
|
2020-10-13 00:25:43 +02:00
|
|
|
R.xml.devicesettings_canned_reply_16,
|
2021-11-03 17:13:22 +01:00
|
|
|
R.xml.devicesettings_canned_dismisscall_16,
|
2022-06-16 23:28:17 +02:00
|
|
|
R.xml.devicesettings_sync_calendar,
|
2021-11-03 17:13:22 +01:00
|
|
|
R.xml.devicesettings_transliteration
|
2020-10-13 00:25:43 +02:00
|
|
|
};
|
|
|
|
}
|
2023-08-20 04:14:06 +02:00
|
|
|
|
|
|
|
@NonNull
|
|
|
|
@Override
|
|
|
|
public Class<? extends DeviceSupport> getDeviceSupportClass() {
|
|
|
|
return PebbleSupport.class;
|
|
|
|
}
|
2015-05-05 00:48:02 +02:00
|
|
|
}
|