2015-08-21 00:58:18 +02:00
|
|
|
package nodomain.freeyourgadget.gadgetbridge.impl;
|
|
|
|
|
|
|
|
import android.app.Service;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.net.Uri;
|
|
|
|
import android.support.annotation.Nullable;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.UUID;
|
|
|
|
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.model.Alarm;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.model.DeviceService;
|
2015-09-24 14:45:21 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.model.NotificationSpec;
|
2015-08-21 00:58:18 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.model.ServiceCommand;
|
2015-08-22 01:08:46 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.service.DeviceCommunicationService;
|
2015-08-21 00:58:18 +02:00
|
|
|
|
|
|
|
public class GBDeviceService implements DeviceService {
|
|
|
|
protected final Context mContext;
|
|
|
|
protected final Class<? extends Service> mServiceClass;
|
|
|
|
|
2015-08-22 01:08:46 +02:00
|
|
|
public GBDeviceService(Context context) {
|
2015-08-21 00:58:18 +02:00
|
|
|
mContext = context;
|
2015-08-22 01:08:46 +02:00
|
|
|
mServiceClass = DeviceCommunicationService.class;
|
2015-08-21 00:58:18 +02:00
|
|
|
}
|
|
|
|
|
2015-08-22 01:08:46 +02:00
|
|
|
protected Intent createIntent() {
|
2015-08-21 00:58:18 +02:00
|
|
|
Intent startIntent = new Intent(mContext, mServiceClass);
|
|
|
|
return startIntent;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void invokeService(Intent intent) {
|
|
|
|
mContext.startService(intent);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void stopService(Intent intent) {
|
|
|
|
mContext.stopService(intent);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void start() {
|
|
|
|
Intent intent = createIntent().setAction(ACTION_START);
|
|
|
|
invokeService(intent);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void connect() {
|
|
|
|
connect(null, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void connect(@Nullable String deviceAddress) {
|
|
|
|
connect(deviceAddress, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void connect(@Nullable String deviceAddress, boolean performPair) {
|
|
|
|
Intent intent = createIntent().setAction(ACTION_CONNECT)
|
|
|
|
.putExtra(EXTRA_DEVICE_ADDRESS, deviceAddress)
|
|
|
|
.putExtra(EXTRA_PERFORM_PAIR, performPair);
|
|
|
|
invokeService(intent);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void disconnect() {
|
|
|
|
Intent intent = createIntent().setAction(ACTION_DISCONNECT);
|
|
|
|
invokeService(intent);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void quit() {
|
|
|
|
Intent intent = createIntent();
|
|
|
|
stopService(intent);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void requestDeviceInfo() {
|
|
|
|
Intent intent = createIntent().setAction(ACTION_REQUEST_DEVICEINFO);
|
|
|
|
invokeService(intent);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-09-24 14:45:21 +02:00
|
|
|
public void onNotification(NotificationSpec notificationSpec) {
|
|
|
|
Intent intent = createIntent().setAction(ACTION_NOTIFICATION)
|
|
|
|
.putExtra(EXTRA_NOTIFICATION_PHONENUMBER, notificationSpec.phoneNumber)
|
|
|
|
.putExtra(EXTRA_NOTIFICATION_SENDER, notificationSpec.sender)
|
|
|
|
.putExtra(EXTRA_NOTIFICATION_SUBJECT, notificationSpec.subject)
|
|
|
|
.putExtra(EXTRA_NOTIFICATION_TITLE, notificationSpec.title)
|
|
|
|
.putExtra(EXTRA_NOTIFICATION_BODY, notificationSpec.body)
|
|
|
|
.putExtra(EXTRA_NOTIFICATION_ID, notificationSpec.id)
|
|
|
|
.putExtra(EXTRA_NOTIFICATION_TYPE, notificationSpec.type)
|
|
|
|
.putExtra(EXTRA_NOTIFICATION_SOURCENAME, notificationSpec.sourceName);
|
2015-08-21 00:58:18 +02:00
|
|
|
invokeService(intent);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSetTime() {
|
|
|
|
Intent intent = createIntent().setAction(ACTION_SETTIME);
|
|
|
|
invokeService(intent);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSetAlarms(ArrayList<? extends Alarm> alarms) {
|
|
|
|
Intent intent = createIntent().setAction(ACTION_SET_ALARMS)
|
|
|
|
.putParcelableArrayListExtra(EXTRA_ALARMS, alarms);
|
|
|
|
invokeService(intent);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSetCallState(String number, String name, ServiceCommand command) {
|
|
|
|
// name is actually ignored and provided by the service itself...
|
|
|
|
Intent intent = createIntent().setAction(ACTION_CALLSTATE)
|
|
|
|
.putExtra(EXTRA_CALL_PHONENUMBER, number)
|
|
|
|
.putExtra(EXTRA_CALL_COMMAND, command);
|
|
|
|
invokeService(intent);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSetMusicInfo(String artist, String album, String track) {
|
|
|
|
Intent intent = createIntent().setAction(ACTION_SETMUSICINFO)
|
|
|
|
.putExtra(EXTRA_MUSIC_ARTIST, artist)
|
|
|
|
.putExtra(EXTRA_MUSIC_TRACK, track);
|
|
|
|
invokeService(intent);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onInstallApp(Uri uri) {
|
|
|
|
Intent intent = createIntent().setAction(ACTION_INSTALL)
|
|
|
|
.putExtra(EXTRA_URI, uri);
|
|
|
|
invokeService(intent);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onAppInfoReq() {
|
|
|
|
Intent intent = createIntent().setAction(ACTION_REQUEST_APPINFO);
|
|
|
|
invokeService(intent);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-09-13 21:44:26 +02:00
|
|
|
public void onAppStart(UUID uuid, boolean start) {
|
2015-08-21 00:58:18 +02:00
|
|
|
Intent intent = createIntent().setAction(ACTION_STARTAPP)
|
2015-09-13 21:44:26 +02:00
|
|
|
.putExtra(EXTRA_APP_UUID, uuid)
|
|
|
|
.putExtra(EXTRA_APP_START, start);
|
2015-08-21 00:58:18 +02:00
|
|
|
invokeService(intent);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onAppDelete(UUID uuid) {
|
|
|
|
Intent intent = createIntent().setAction(ACTION_DELETEAPP)
|
|
|
|
.putExtra(EXTRA_APP_UUID, uuid);
|
|
|
|
invokeService(intent);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFetchActivityData() {
|
|
|
|
Intent intent = createIntent().setAction(ACTION_FETCH_ACTIVITY_DATA);
|
|
|
|
invokeService(intent);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onReboot() {
|
|
|
|
Intent intent = createIntent().setAction(ACTION_REBOOT);
|
|
|
|
invokeService(intent);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFindDevice(boolean start) {
|
|
|
|
Intent intent = createIntent().setAction(ACTION_FIND_DEVICE)
|
2015-08-22 12:38:35 +02:00
|
|
|
.putExtra(EXTRA_FIND_START, start);
|
2015-08-21 00:58:18 +02:00
|
|
|
invokeService(intent);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onScreenshotReq() {
|
|
|
|
Intent intent = createIntent().setAction(ACTION_REQUEST_SCREENSHOT);
|
|
|
|
invokeService(intent);
|
|
|
|
}
|
2015-09-02 08:00:26 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onEnableRealtimeSteps(boolean enable) {
|
|
|
|
Intent intent = createIntent().setAction(ACTION_ENABLE_REALTIME_STEPS)
|
|
|
|
.putExtra(EXTRA_ENABLE_REALTIME_STEPS, enable);
|
|
|
|
invokeService(intent);
|
|
|
|
}
|
2015-08-21 00:58:18 +02:00
|
|
|
}
|