2015-04-14 01:24:03 +02:00
|
|
|
package nodomain.freeyourgadget.gadgetbridge;
|
|
|
|
|
2015-05-18 20:56:19 +02:00
|
|
|
import java.util.UUID;
|
|
|
|
|
2015-04-14 01:24:03 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.protocol.GBDeviceProtocol;
|
|
|
|
|
|
|
|
public abstract class AbstractBTDeviceSupport extends AbstractDeviceSupport {
|
|
|
|
|
|
|
|
private GBDeviceProtocol gbDeviceProtocol;
|
|
|
|
private GBDeviceIoThread gbDeviceIOThread;
|
|
|
|
|
|
|
|
protected abstract GBDeviceProtocol createDeviceProtocol();
|
|
|
|
|
|
|
|
protected abstract GBDeviceIoThread createDeviceIOThread();
|
2015-04-14 10:29:09 +02:00
|
|
|
|
2015-04-14 01:39:00 +02:00
|
|
|
@Override
|
|
|
|
public void dispose() {
|
|
|
|
// currently only one thread allowed
|
|
|
|
if (gbDeviceIOThread != null) {
|
|
|
|
gbDeviceIOThread.quit();
|
|
|
|
try {
|
|
|
|
gbDeviceIOThread.join();
|
|
|
|
} catch (InterruptedException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
gbDeviceIOThread = null;
|
|
|
|
}
|
|
|
|
}
|
2015-04-14 10:29:09 +02:00
|
|
|
|
2015-05-05 00:48:02 +02:00
|
|
|
@Override
|
|
|
|
public void pair() {
|
|
|
|
// Default implementation does no manual pairing, use the Android
|
|
|
|
// pairing dialog instead.
|
|
|
|
}
|
|
|
|
|
2015-04-14 01:24:03 +02:00
|
|
|
public synchronized GBDeviceProtocol getDeviceProtocol() {
|
|
|
|
if (gbDeviceProtocol == null) {
|
|
|
|
gbDeviceProtocol = createDeviceProtocol();
|
|
|
|
}
|
|
|
|
return gbDeviceProtocol;
|
|
|
|
}
|
2015-04-14 10:29:09 +02:00
|
|
|
|
2015-04-14 01:24:03 +02:00
|
|
|
public synchronized GBDeviceIoThread getDeviceIOThread() {
|
|
|
|
if (gbDeviceIOThread == null) {
|
|
|
|
gbDeviceIOThread = createDeviceIOThread();
|
|
|
|
}
|
|
|
|
return gbDeviceIOThread;
|
|
|
|
}
|
2015-04-14 10:29:09 +02:00
|
|
|
|
2015-04-14 01:24:03 +02:00
|
|
|
protected void sendToDevice(byte[] bytes) {
|
2015-04-14 01:39:00 +02:00
|
|
|
if (bytes != null && gbDeviceIOThread != null) {
|
2015-04-14 01:24:03 +02:00
|
|
|
gbDeviceIOThread.write(bytes);
|
|
|
|
}
|
|
|
|
}
|
2015-04-14 10:29:09 +02:00
|
|
|
|
2015-04-14 01:24:03 +02:00
|
|
|
@Override
|
|
|
|
public void onSMS(String from, String body) {
|
|
|
|
byte[] bytes = gbDeviceProtocol.encodeSMS(from, body);
|
|
|
|
sendToDevice(bytes);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onEmail(String from, String subject, String body) {
|
|
|
|
byte[] bytes = gbDeviceProtocol.encodeEmail(from, subject, body);
|
|
|
|
sendToDevice(bytes);
|
|
|
|
}
|
|
|
|
|
2015-05-13 21:55:22 +02:00
|
|
|
@Override
|
|
|
|
public void onGenericNotification(String title, String details) {
|
|
|
|
byte[] bytes = gbDeviceProtocol.encodeGenericNotification(title, details);
|
|
|
|
sendToDevice(bytes);
|
|
|
|
}
|
|
|
|
|
2015-04-14 01:24:03 +02:00
|
|
|
@Override
|
|
|
|
public void onSetTime(long ts) {
|
|
|
|
byte[] bytes = gbDeviceProtocol.encodeSetTime(ts);
|
|
|
|
sendToDevice(bytes);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSetCallState(String number, String name, GBCommand command) {
|
|
|
|
byte[] bytes = gbDeviceProtocol.encodeSetCallState(number, name, command);
|
|
|
|
sendToDevice(bytes);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSetMusicInfo(String artist, String album, String track) {
|
|
|
|
byte[] bytes = gbDeviceProtocol.encodeSetMusicInfo(artist, album, track);
|
|
|
|
sendToDevice(bytes);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFirmwareVersionReq() {
|
|
|
|
byte[] bytes = gbDeviceProtocol.encodeFirmwareVersionReq();
|
|
|
|
sendToDevice(bytes);
|
|
|
|
}
|
|
|
|
|
2015-04-19 22:31:09 +02:00
|
|
|
@Override
|
|
|
|
public void onBatteryInfoReq() {
|
|
|
|
byte[] bytes = gbDeviceProtocol.encodeBatteryInfoReq();
|
|
|
|
sendToDevice(bytes);
|
|
|
|
}
|
|
|
|
|
2015-04-14 01:24:03 +02:00
|
|
|
@Override
|
|
|
|
public void onAppInfoReq() {
|
|
|
|
byte[] bytes = gbDeviceProtocol.encodeAppInfoReq();
|
|
|
|
sendToDevice(bytes);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-05-18 20:56:19 +02:00
|
|
|
public void onAppDelete(UUID uuid) {
|
|
|
|
byte[] bytes = gbDeviceProtocol.encodeAppDelete(uuid);
|
2015-04-14 01:24:03 +02:00
|
|
|
sendToDevice(bytes);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onPhoneVersion(byte os) {
|
|
|
|
byte[] bytes = gbDeviceProtocol.encodePhoneVersion(os);
|
|
|
|
sendToDevice(bytes);
|
|
|
|
}
|
2015-05-17 21:58:08 +02:00
|
|
|
|
|
|
|
public void onReboot() {
|
|
|
|
byte[] bytes = gbDeviceProtocol.encodeReboot();
|
|
|
|
sendToDevice(bytes);
|
|
|
|
}
|
2015-04-14 01:24:03 +02:00
|
|
|
}
|