mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-12-27 11:05:49 +01:00
Cleanup and update AsteroidOS
1. Added icons to the notifications 2. Cleaned up a lot of the DeviceCoordinator code (Since a lot of them have default implementations now)
This commit is contained in:
parent
1165a5d03c
commit
bf762a25a5
@ -23,17 +23,17 @@ import java.util.UUID;
|
|||||||
*/
|
*/
|
||||||
public class AsteroidOSConstants {
|
public class AsteroidOSConstants {
|
||||||
/**
|
/**
|
||||||
* A list of all the supported devices and their codenames
|
* A list of all the known supported codenames
|
||||||
*/
|
*/
|
||||||
public static final String[] SUPPORTED_DEVICE_CODENAMES = {
|
public static final String[] KNOWN_DEVICE_CODENAMES = {
|
||||||
"bass", "sturgeon", "catfish", "catfish_ext",
|
"bass", "sturgeon", "catfish", "catfish_ext",
|
||||||
"catshark", "lenok", "smelt", "carp",
|
"catshark", "lenok", "smelt", "carp",
|
||||||
"sparrow", "wren", "anthias", "beluga",
|
"sparrow", "wren", "anthias", "beluga",
|
||||||
"dory", "firefish", "harmony", "inharmony",
|
"dory", "firefish", "harmony", "inharmony",
|
||||||
"narwhal", "ray", "sawfish", "sawshark",
|
"narwhal", "ray", "sawfish", "sawshark",
|
||||||
"skipjack", "tunny", "mooneye", "swift",
|
"skipjack", "tunny", "mooneye", "swift",
|
||||||
"minnow", "sprat", "tetra", "pike", "hoki",
|
"minnow", "sprat", "tetra", "pike", "hoki",
|
||||||
"koi", "ayu"
|
"koi", "ayu"
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -66,11 +66,11 @@ public class AsteroidOSConstants {
|
|||||||
/**
|
/**
|
||||||
* Screenshot request characteristic
|
* Screenshot request characteristic
|
||||||
*/
|
*/
|
||||||
public static final UUID SCREENSHOT_REQUEST = UUID.fromString("00006001-0000-0000-0000-00A57E401D05");
|
public static final UUID SCREENSHOT_REQUEST_CHAR = UUID.fromString("00006001-0000-0000-0000-00A57E401D05");
|
||||||
/**
|
/**
|
||||||
* Screenshot content characteristic
|
* Screenshot content characteristic
|
||||||
*/
|
*/
|
||||||
public static final UUID SCREENSHOT_CONTENT = UUID.fromString("00006002-0000-0000-0000-00A57E401D05");
|
public static final UUID SCREENSHOT_CONTENT_CHAR = UUID.fromString("00006002-0000-0000-0000-00A57E401D05");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Media service
|
* Media service
|
||||||
|
@ -17,17 +17,10 @@
|
|||||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||||
package nodomain.freeyourgadget.gadgetbridge.devices.asteroidos;
|
package nodomain.freeyourgadget.gadgetbridge.devices.asteroidos;
|
||||||
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.bluetooth.le.ScanFilter;
|
import android.bluetooth.le.ScanFilter;
|
||||||
import android.content.Context;
|
|
||||||
import android.net.Uri;
|
|
||||||
import android.os.ParcelUuid;
|
import android.os.ParcelUuid;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
@ -36,42 +29,27 @@ import java.util.List;
|
|||||||
import nodomain.freeyourgadget.gadgetbridge.GBException;
|
import nodomain.freeyourgadget.gadgetbridge.GBException;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.R;
|
import nodomain.freeyourgadget.gadgetbridge.R;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.devices.AbstractDeviceCoordinator;
|
import nodomain.freeyourgadget.gadgetbridge.devices.AbstractDeviceCoordinator;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.devices.InstallHandler;
|
|
||||||
import nodomain.freeyourgadget.gadgetbridge.devices.SampleProvider;
|
|
||||||
import nodomain.freeyourgadget.gadgetbridge.entities.DaoSession;
|
import nodomain.freeyourgadget.gadgetbridge.entities.DaoSession;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.entities.Device;
|
import nodomain.freeyourgadget.gadgetbridge.entities.Device;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.impl.GBDeviceCandidate;
|
import nodomain.freeyourgadget.gadgetbridge.impl.GBDeviceCandidate;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.model.ActivitySample;
|
|
||||||
import nodomain.freeyourgadget.gadgetbridge.model.DeviceType;
|
|
||||||
import nodomain.freeyourgadget.gadgetbridge.service.DeviceSupport;
|
import nodomain.freeyourgadget.gadgetbridge.service.DeviceSupport;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.asteroidos.AsteroidOSDeviceSupport;
|
import nodomain.freeyourgadget.gadgetbridge.service.devices.asteroidos.AsteroidOSDeviceSupport;
|
||||||
|
|
||||||
public class AsteroidOSDeviceCoordinator extends AbstractDeviceCoordinator {
|
public class AsteroidOSDeviceCoordinator extends AbstractDeviceCoordinator {
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(AsteroidOSDeviceCoordinator.class);
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getManufacturer() {
|
public String getManufacturer() {
|
||||||
return "AsteroidOS";
|
return "AsteroidOS";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean supportsAppsManagement(final GBDevice device) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Class<? extends Activity> getAppsManagementActivity() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public Collection<? extends ScanFilter> createBLEScanFilters() {
|
public Collection<? extends ScanFilter> createBLEScanFilters() {
|
||||||
ParcelUuid asteroidUUID = ParcelUuid.fromString(AsteroidOSConstants.SERVICE_UUID.toString());
|
ParcelUuid asteroidUUID = ParcelUuid.fromString(AsteroidOSConstants.SERVICE_UUID.toString());
|
||||||
ScanFilter serviceFilter = new ScanFilter.Builder().setServiceUuid(asteroidUUID).build();
|
ScanFilter serviceFilter = new ScanFilter.Builder().setServiceUuid(asteroidUUID).build();
|
||||||
|
|
||||||
List<ScanFilter> filters = new ArrayList();
|
List<ScanFilter> filters = new ArrayList<>();
|
||||||
filters.add(serviceFilter);
|
filters.add(serviceFilter);
|
||||||
|
|
||||||
return filters;
|
return filters;
|
||||||
@ -81,61 +59,17 @@ public class AsteroidOSDeviceCoordinator extends AbstractDeviceCoordinator {
|
|||||||
protected void deleteDevice(@NonNull GBDevice gbDevice, @NonNull Device device, @NonNull DaoSession session) throws GBException {
|
protected void deleteDevice(@NonNull GBDevice gbDevice, @NonNull Device device, @NonNull DaoSession session) throws GBException {
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
|
||||||
@Override
|
@Override
|
||||||
public boolean supports(GBDeviceCandidate candidate) {
|
public boolean supports(GBDeviceCandidate candidate) {
|
||||||
if (candidate.supportsService(AsteroidOSConstants.SERVICE_UUID)) {
|
if (candidate.supportsService(AsteroidOSConstants.SERVICE_UUID))
|
||||||
return true;
|
return true;
|
||||||
}
|
// Some devices still can't see the service
|
||||||
for (String name : AsteroidOSConstants.SUPPORTED_DEVICE_CODENAMES) {
|
for (String codename : AsteroidOSConstants.KNOWN_DEVICE_CODENAMES)
|
||||||
if (candidate.getName().equals(name)) {
|
if (candidate.getName().equals(codename))
|
||||||
return true;
|
return true;
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getBondingStyle() {
|
|
||||||
return BONDING_STYLE_ASK;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean supportsCalendarEvents() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean supportsRealtimeData() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
@Override
|
|
||||||
public Class<? extends Activity> getPairingActivity() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean supportsActivityDataFetching() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean supportsActivityTracking() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public SampleProvider<? extends ActivitySample> getSampleProvider(GBDevice device, DaoSession session) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public InstallHandler findInstallHandler(Uri uri, Context context) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean supportsWeather() {
|
public boolean supportsWeather() {
|
||||||
return true;
|
return true;
|
||||||
@ -146,21 +80,6 @@ public class AsteroidOSDeviceCoordinator extends AbstractDeviceCoordinator {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean supportsScreenshots(final GBDevice device) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getAlarmSlotCount(GBDevice device) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean supportsHeartRateMeasurement(GBDevice device) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean supportsMusicInfo() {
|
public boolean supportsMusicInfo() {
|
||||||
return true;
|
return true;
|
||||||
|
@ -24,6 +24,7 @@ import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
|||||||
import nodomain.freeyourgadget.gadgetbridge.R;
|
import nodomain.freeyourgadget.gadgetbridge.R;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.model.CallSpec;
|
import nodomain.freeyourgadget.gadgetbridge.model.CallSpec;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.model.NotificationSpec;
|
import nodomain.freeyourgadget.gadgetbridge.model.NotificationSpec;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.model.NotificationType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An adapter for notifications on AsteroidOS
|
* An adapter for notifications on AsteroidOS
|
||||||
@ -64,6 +65,7 @@ public class AsteroidOSNotification {
|
|||||||
this.summary = spec.subject;
|
this.summary = spec.subject;
|
||||||
this.id = spec.getId();
|
this.id = spec.getId();
|
||||||
this.packageName = spec.sourceAppId;
|
this.packageName = spec.sourceAppId;
|
||||||
|
this.icon = this.gbNotificationTypeToIcon(spec.type);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -78,6 +80,7 @@ public class AsteroidOSNotification {
|
|||||||
this.body = callSpec.number;
|
this.body = callSpec.number;
|
||||||
this.vibrationStrength = VibrationStrength.RINGTONE;
|
this.vibrationStrength = VibrationStrength.RINGTONE;
|
||||||
this.id = (callSpec.name + callSpec.number).hashCode();
|
this.id = (callSpec.name + callSpec.number).hashCode();
|
||||||
|
this.icon = "ios-call-outline";
|
||||||
break;
|
break;
|
||||||
case CallSpec.CALL_OUTGOING:
|
case CallSpec.CALL_OUTGOING:
|
||||||
break;
|
break;
|
||||||
@ -128,4 +131,46 @@ public class AsteroidOSNotification {
|
|||||||
retString += "</insert>";
|
retString += "</insert>";
|
||||||
return retString;
|
return retString;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String gbNotificationTypeToIcon(NotificationType type) {
|
||||||
|
switch (type) {
|
||||||
|
// Logos
|
||||||
|
case FACEBOOK:
|
||||||
|
return "logo-facebook";
|
||||||
|
case INSTAGRAM:
|
||||||
|
return "logo-instagram";
|
||||||
|
case LINKEDIN:
|
||||||
|
return "logo-linkedin";
|
||||||
|
case SIGNAL:
|
||||||
|
return "logo-signal";
|
||||||
|
case SKYPE:
|
||||||
|
return "logo-skype";
|
||||||
|
case SNAPCHAT:
|
||||||
|
return "logo-snapchat";
|
||||||
|
case TWITTER:
|
||||||
|
return "logo-twitter";
|
||||||
|
case WHATSAPP:
|
||||||
|
return "logo-whatsapp";
|
||||||
|
case YAHOO_MAIL:
|
||||||
|
return "logo-yahoo";
|
||||||
|
// Generic
|
||||||
|
default:
|
||||||
|
switch (type.getGenericType()) {
|
||||||
|
case "generic_email":
|
||||||
|
return "ios-mail-outline";
|
||||||
|
case "generic_navigation":
|
||||||
|
return "ios-navigate-outline";
|
||||||
|
case "generic_sms":
|
||||||
|
return "ios-chatboxes-outline";
|
||||||
|
case "generic_alarm_clock":
|
||||||
|
return "ios-alarm-outline";
|
||||||
|
case "generic_social":
|
||||||
|
return "ios-people-outline";
|
||||||
|
case "generic_chat":
|
||||||
|
return "ios-chatbubbles-outline";
|
||||||
|
default:
|
||||||
|
return "ios-notifications-outline";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,15 +18,18 @@ package nodomain.freeyourgadget.gadgetbridge.service.devices.asteroidos;
|
|||||||
|
|
||||||
import android.bluetooth.BluetoothGatt;
|
import android.bluetooth.BluetoothGatt;
|
||||||
import android.bluetooth.BluetoothGattCharacteristic;
|
import android.bluetooth.BluetoothGattCharacteristic;
|
||||||
import android.content.Intent;
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.GregorianCalendar;
|
import java.util.GregorianCalendar;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventBatteryInfo;
|
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventBatteryInfo;
|
||||||
@ -63,14 +66,10 @@ public class AsteroidOSDeviceSupport extends AbstractBTLEDeviceSupport {
|
|||||||
addSupportedService(AsteroidOSConstants.NOTIFICATION_SERVICE_UUID);
|
addSupportedService(AsteroidOSConstants.NOTIFICATION_SERVICE_UUID);
|
||||||
addSupportedService(AsteroidOSConstants.MEDIA_SERVICE_UUID);
|
addSupportedService(AsteroidOSConstants.MEDIA_SERVICE_UUID);
|
||||||
|
|
||||||
IntentListener mListener = new IntentListener() {
|
IntentListener mListener = intent -> {
|
||||||
@Override
|
String action = intent.getAction();
|
||||||
public void notify(Intent intent) {
|
if (BatteryInfoProfile.ACTION_BATTERY_INFO.equals(action)) {
|
||||||
String action = intent.getAction();
|
handleBatteryInfo(Objects.requireNonNull(intent.getParcelableExtra(BatteryInfoProfile.EXTRA_BATTERY_INFO)));
|
||||||
if (BatteryInfoProfile.ACTION_BATTERY_INFO.equals(action)) {
|
|
||||||
handleBatteryInfo((nodomain.freeyourgadget.gadgetbridge.service.btle.profiles.battery.BatteryInfo) intent.getParcelableExtra(BatteryInfoProfile.EXTRA_BATTERY_INFO));
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -79,7 +78,7 @@ public class AsteroidOSDeviceSupport extends AbstractBTLEDeviceSupport {
|
|||||||
addSupportedProfile(batteryInfoProfile);
|
addSupportedProfile(batteryInfoProfile);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleBatteryInfo(nodomain.freeyourgadget.gadgetbridge.service.btle.profiles.battery.BatteryInfo info) {
|
private void handleBatteryInfo(@NonNull nodomain.freeyourgadget.gadgetbridge.service.btle.profiles.battery.BatteryInfo info) {
|
||||||
batteryCmd.level = info.getPercentCharged();
|
batteryCmd.level = info.getPercentCharged();
|
||||||
handleGBDeviceEvent(batteryCmd);
|
handleGBDeviceEvent(batteryCmd);
|
||||||
}
|
}
|
||||||
@ -91,12 +90,12 @@ public class AsteroidOSDeviceSupport extends AbstractBTLEDeviceSupport {
|
|||||||
UUID characteristicUUID = characteristic.getUuid();
|
UUID characteristicUUID = characteristic.getUuid();
|
||||||
|
|
||||||
if (characteristicUUID.equals(AsteroidOSConstants.MEDIA_COMMANDS_CHAR)) {
|
if (characteristicUUID.equals(AsteroidOSConstants.MEDIA_COMMANDS_CHAR)) {
|
||||||
handleMediaCommand(gatt, characteristic);
|
handleMediaCommand(characteristic);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
LOG.info("Characteristic changed UUID: " + characteristicUUID);
|
LOG.info("Characteristic changed UUID: " + characteristicUUID);
|
||||||
LOG.info("Characteristic changed value: " + characteristic.getValue().toString());
|
LOG.info("Characteristic changed value: " + Arrays.toString(characteristic.getValue()));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -266,10 +265,9 @@ public class AsteroidOSDeviceSupport extends AbstractBTLEDeviceSupport {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles a media command sent from the AsteroidOS device
|
* Handles a media command sent from the AsteroidOS device
|
||||||
* @param gatt The bluetooth device's GATT info
|
|
||||||
* @param characteristic The Characteristic information
|
* @param characteristic The Characteristic information
|
||||||
*/
|
*/
|
||||||
public void handleMediaCommand (BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) {
|
public void handleMediaCommand (BluetoothGattCharacteristic characteristic) {
|
||||||
LOG.info("handle media command");
|
LOG.info("handle media command");
|
||||||
AsteroidOSMediaCommand command = new AsteroidOSMediaCommand(characteristic.getValue()[0]);
|
AsteroidOSMediaCommand command = new AsteroidOSMediaCommand(characteristic.getValue()[0]);
|
||||||
GBDeviceEventMusicControl event = command.toMusicControlEvent();
|
GBDeviceEventMusicControl event = command.toMusicControlEvent();
|
||||||
|
Loading…
Reference in New Issue
Block a user