diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index aad0c2ea7..85bb980a5 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -164,7 +164,7 @@
-
+
* Note that this method may cause an implicit device connection (for auto-connectable devices).
*/
private void requestDeviceInfo() {
- Intent versionInfoIntent = new Intent(ControlCenter.this, BluetoothCommunicationService.class);
- versionInfoIntent.setAction(BluetoothCommunicationService.ACTION_REQUEST_VERSIONINFO);
+ Intent versionInfoIntent = new Intent(ControlCenter.this, DeviceCommunicationService.class);
+ versionInfoIntent.setAction(DeviceCommunicationService.ACTION_REQUEST_VERSIONINFO);
startService(versionInfoIntent);
}
@@ -213,16 +213,16 @@ public class ControlCenter extends Activity {
return true;
case R.id.controlcenter_fetch_activity_data:
if (selectedDevice != null) {
- Intent startIntent = new Intent(this, BluetoothCommunicationService.class);
- startIntent.setAction(BluetoothCommunicationService.ACTION_FETCH_ACTIVITY_DATA);
+ Intent startIntent = new Intent(this, DeviceCommunicationService.class);
+ startIntent.setAction(DeviceCommunicationService.ACTION_FETCH_ACTIVITY_DATA);
startService(startIntent);
}
return true;
case R.id.controlcenter_disconnect:
if (selectedDevice != null) {
selectedDevice = null;
- Intent startIntent = new Intent(this, BluetoothCommunicationService.class);
- startIntent.setAction(BluetoothCommunicationService.ACTION_DISCONNECT);
+ Intent startIntent = new Intent(this, DeviceCommunicationService.class);
+ startIntent.setAction(DeviceCommunicationService.ACTION_DISCONNECT);
startService(startIntent);
}
return true;
@@ -251,8 +251,8 @@ public class ControlCenter extends Activity {
return true;
case R.id.controlcenter_take_screenshot:
if (selectedDevice != null) {
- Intent startIntent = new Intent(this, BluetoothCommunicationService.class);
- startIntent.setAction(BluetoothCommunicationService.ACTION_REQUEST_SCREENSHOT);
+ Intent startIntent = new Intent(this, DeviceCommunicationService.class);
+ startIntent.setAction(DeviceCommunicationService.ACTION_REQUEST_SCREENSHOT);
startService(startIntent);
}
return true;
@@ -262,9 +262,9 @@ public class ControlCenter extends Activity {
}
private void findDevice(boolean start) {
- Intent startIntent = new Intent(this, BluetoothCommunicationService.class);
+ Intent startIntent = new Intent(this, DeviceCommunicationService.class);
startIntent.putExtra("find_start", start);
- startIntent.setAction(BluetoothCommunicationService.ACTION_FIND_DEVICE);
+ startIntent.setAction(DeviceCommunicationService.ACTION_FIND_DEVICE);
startService(startIntent);
}
@@ -288,7 +288,7 @@ public class ControlCenter extends Activity {
startActivity(debugIntent);
return true;
case R.id.action_quit:
- Intent stopIntent = new Intent(this, BluetoothCommunicationService.class);
+ Intent stopIntent = new Intent(this, DeviceCommunicationService.class);
stopService(stopIntent);
Intent quitIntent = new Intent(ControlCenter.ACTION_QUIT);
diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/DebugActivity.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/DebugActivity.java
index 64b9a7508..5f672f45f 100644
--- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/DebugActivity.java
+++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/DebugActivity.java
@@ -21,13 +21,13 @@ import org.slf4j.LoggerFactory;
import java.io.File;
+import nodomain.freeyourgadget.gadgetbridge.service.DeviceCommunicationService;
import nodomain.freeyourgadget.gadgetbridge.util.GB;
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
import nodomain.freeyourgadget.gadgetbridge.model.ServiceCommand;
import nodomain.freeyourgadget.gadgetbridge.R;
import nodomain.freeyourgadget.gadgetbridge.database.DBHandler;
import nodomain.freeyourgadget.gadgetbridge.database.DBHelper;
-import nodomain.freeyourgadget.gadgetbridge.service.BluetoothCommunicationService;
import nodomain.freeyourgadget.gadgetbridge.util.FileUtils;
@@ -70,8 +70,8 @@ public class DebugActivity extends Activity {
sendSMSButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
- Intent startIntent = new Intent(DebugActivity.this, BluetoothCommunicationService.class);
- startIntent.setAction(BluetoothCommunicationService.ACTION_NOTIFICATION_SMS);
+ Intent startIntent = new Intent(DebugActivity.this, DeviceCommunicationService.class);
+ startIntent.setAction(DeviceCommunicationService.ACTION_NOTIFICATION_SMS);
startIntent.putExtra("notification_sender", getResources().getText(R.string.app_name));
startIntent.putExtra("notification_body", editContent.getText().toString());
startService(startIntent);
@@ -81,8 +81,8 @@ public class DebugActivity extends Activity {
sendEmailButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
- Intent startIntent = new Intent(DebugActivity.this, BluetoothCommunicationService.class);
- startIntent.setAction(BluetoothCommunicationService.ACTION_NOTIFICATION_EMAIL);
+ Intent startIntent = new Intent(DebugActivity.this, DeviceCommunicationService.class);
+ startIntent.setAction(DeviceCommunicationService.ACTION_NOTIFICATION_EMAIL);
startIntent.putExtra("notification_sender", getResources().getText(R.string.app_name));
startIntent.putExtra("notification_subject", getResources().getText(R.string.test));
startIntent.putExtra("notification_body", editContent.getText().toString());
@@ -94,8 +94,8 @@ public class DebugActivity extends Activity {
incomingCallButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
- Intent startIntent = new Intent(DebugActivity.this, BluetoothCommunicationService.class);
- startIntent.setAction(BluetoothCommunicationService.ACTION_CALLSTATE);
+ Intent startIntent = new Intent(DebugActivity.this, DeviceCommunicationService.class);
+ startIntent.setAction(DeviceCommunicationService.ACTION_CALLSTATE);
startIntent.putExtra("call_phonenumber", editContent.getText().toString());
startIntent.putExtra("call_command", ServiceCommand.CALL_INCOMING.ordinal());
startService(startIntent);
@@ -105,8 +105,8 @@ public class DebugActivity extends Activity {
outgoingCallButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
- Intent startIntent = new Intent(DebugActivity.this, BluetoothCommunicationService.class);
- startIntent.setAction(BluetoothCommunicationService.ACTION_CALLSTATE);
+ Intent startIntent = new Intent(DebugActivity.this, DeviceCommunicationService.class);
+ startIntent.setAction(DeviceCommunicationService.ACTION_CALLSTATE);
startIntent.putExtra("call_phonenumber", editContent.getText().toString());
startIntent.putExtra("call_command", ServiceCommand.CALL_OUTGOING.ordinal());
startService(startIntent);
@@ -117,8 +117,8 @@ public class DebugActivity extends Activity {
startCallButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
- Intent startIntent = new Intent(DebugActivity.this, BluetoothCommunicationService.class);
- startIntent.setAction(BluetoothCommunicationService.ACTION_CALLSTATE);
+ Intent startIntent = new Intent(DebugActivity.this, DeviceCommunicationService.class);
+ startIntent.setAction(DeviceCommunicationService.ACTION_CALLSTATE);
startIntent.putExtra("call_command", ServiceCommand.CALL_START.ordinal());
startService(startIntent);
}
@@ -127,8 +127,8 @@ public class DebugActivity extends Activity {
endCallButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
- Intent startIntent = new Intent(DebugActivity.this, BluetoothCommunicationService.class);
- startIntent.setAction(BluetoothCommunicationService.ACTION_CALLSTATE);
+ Intent startIntent = new Intent(DebugActivity.this, DeviceCommunicationService.class);
+ startIntent.setAction(DeviceCommunicationService.ACTION_CALLSTATE);
startIntent.putExtra("call_command", ServiceCommand.CALL_END.ordinal());
startService(startIntent);
}
@@ -153,8 +153,8 @@ public class DebugActivity extends Activity {
rebootButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
- Intent startIntent = new Intent(DebugActivity.this, BluetoothCommunicationService.class);
- startIntent.setAction(BluetoothCommunicationService.ACTION_REBOOT);
+ Intent startIntent = new Intent(DebugActivity.this, DeviceCommunicationService.class);
+ startIntent.setAction(DeviceCommunicationService.ACTION_REBOOT);
startService(startIntent);
}
});
@@ -163,8 +163,8 @@ public class DebugActivity extends Activity {
setMusicInfoButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
- Intent startIntent = new Intent(DebugActivity.this, BluetoothCommunicationService.class);
- startIntent.setAction(BluetoothCommunicationService.ACTION_SETMUSICINFO);
+ Intent startIntent = new Intent(DebugActivity.this, DeviceCommunicationService.class);
+ startIntent.setAction(DeviceCommunicationService.ACTION_SETMUSICINFO);
startIntent.putExtra("music_artist", editContent.getText().toString() + "(artist)");
startIntent.putExtra("music_album", editContent.getText().toString() + "(album)");
startIntent.putExtra("music_track", editContent.getText().toString() + "(track)");
@@ -176,8 +176,8 @@ public class DebugActivity extends Activity {
setTimeButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
- Intent startIntent = new Intent(DebugActivity.this, BluetoothCommunicationService.class);
- startIntent.setAction(BluetoothCommunicationService.ACTION_SETTIME);
+ Intent startIntent = new Intent(DebugActivity.this, DeviceCommunicationService.class);
+ startIntent.setAction(DeviceCommunicationService.ACTION_SETTIME);
startService(startIntent);
}
});
diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/FwAppInstallerActivity.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/FwAppInstallerActivity.java
index 799955863..c292fc10e 100644
--- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/FwAppInstallerActivity.java
+++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/FwAppInstallerActivity.java
@@ -17,7 +17,7 @@ import android.widget.TextView;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import nodomain.freeyourgadget.gadgetbridge.service.BluetoothCommunicationService;
+import nodomain.freeyourgadget.gadgetbridge.service.DeviceCommunicationService;
import nodomain.freeyourgadget.gadgetbridge.model.DeviceType;
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
import nodomain.freeyourgadget.gadgetbridge.impl.GBDeviceApp;
@@ -104,14 +104,14 @@ public class FwAppInstallerActivity extends Activity {
installButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
- Intent startIntent = new Intent(FwAppInstallerActivity.this, BluetoothCommunicationService.class);
- startIntent.setAction(BluetoothCommunicationService.ACTION_INSTALL);
+ Intent startIntent = new Intent(FwAppInstallerActivity.this, DeviceCommunicationService.class);
+ startIntent.setAction(DeviceCommunicationService.ACTION_INSTALL);
startIntent.putExtra("uri", uri.toString());
startService(startIntent);
}
});
- Intent versionInfoIntent = new Intent(this, BluetoothCommunicationService.class);
- versionInfoIntent.setAction(BluetoothCommunicationService.ACTION_REQUEST_VERSIONINFO);
+ Intent versionInfoIntent = new Intent(this, DeviceCommunicationService.class);
+ versionInfoIntent.setAction(DeviceCommunicationService.ACTION_REQUEST_VERSIONINFO);
startService(versionInfoIntent);
}
diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/ChartsActivity.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/ChartsActivity.java
index 0f2736fcf..301c1012e 100644
--- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/ChartsActivity.java
+++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/ChartsActivity.java
@@ -23,7 +23,7 @@ import org.slf4j.LoggerFactory;
import java.util.Locale;
import nodomain.freeyourgadget.gadgetbridge.activities.ControlCenter;
-import nodomain.freeyourgadget.gadgetbridge.service.BluetoothCommunicationService;
+import nodomain.freeyourgadget.gadgetbridge.service.DeviceCommunicationService;
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
import nodomain.freeyourgadget.gadgetbridge.R;
@@ -117,8 +117,8 @@ public class ChartsActivity extends FragmentActivity {
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.charts_fetch_activity_data:
- Intent startIntent = new Intent(this, BluetoothCommunicationService.class);
- startIntent.setAction(BluetoothCommunicationService.ACTION_FETCH_ACTIVITY_DATA);
+ Intent startIntent = new Intent(this, DeviceCommunicationService.class);
+ startIntent.setAction(DeviceCommunicationService.ACTION_FETCH_ACTIVITY_DATA);
startService(startIntent);
return true;
default:
diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/miband/MiBandPairingActivity.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/miband/MiBandPairingActivity.java
index b8e7d2505..dbb5814ce 100644
--- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/miband/MiBandPairingActivity.java
+++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/miband/MiBandPairingActivity.java
@@ -12,7 +12,7 @@ import android.support.v4.content.LocalBroadcastManager;
import android.widget.TextView;
import android.widget.Toast;
-import nodomain.freeyourgadget.gadgetbridge.service.BluetoothCommunicationService;
+import nodomain.freeyourgadget.gadgetbridge.service.DeviceCommunicationService;
import nodomain.freeyourgadget.gadgetbridge.activities.ControlCenter;
import nodomain.freeyourgadget.gadgetbridge.devices.DeviceCoordinator;
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
@@ -105,14 +105,14 @@ public class MiBandPairingActivity extends Activity {
IntentFilter filter = new IntentFilter(GBDevice.ACTION_DEVICE_CHANGED);
LocalBroadcastManager.getInstance(this).registerReceiver(mPairingReceiver, filter);
- Intent serviceIntent = new Intent(this, BluetoothCommunicationService.class);
- serviceIntent.setAction(BluetoothCommunicationService.ACTION_START);
+ Intent serviceIntent = new Intent(this, DeviceCommunicationService.class);
+ serviceIntent.setAction(DeviceCommunicationService.ACTION_START);
startService(serviceIntent);
- serviceIntent = new Intent(this, BluetoothCommunicationService.class);
- serviceIntent.setAction(BluetoothCommunicationService.ACTION_CONNECT);
- serviceIntent.putExtra(BluetoothCommunicationService.EXTRA_PERFORM_PAIR, true);
- serviceIntent.putExtra(BluetoothCommunicationService.EXTRA_DEVICE_ADDRESS, macAddress);
+ serviceIntent = new Intent(this, DeviceCommunicationService.class);
+ serviceIntent.setAction(DeviceCommunicationService.ACTION_CONNECT);
+ serviceIntent.putExtra(DeviceCommunicationService.EXTRA_PERFORM_PAIR, true);
+ serviceIntent.putExtra(DeviceCommunicationService.EXTRA_DEVICE_ADDRESS, macAddress);
startService(serviceIntent);
}
diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/BluetoothStateChangeReceiver.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/BluetoothStateChangeReceiver.java
index cb6cb66ac..ae7f52ad3 100644
--- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/BluetoothStateChangeReceiver.java
+++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/BluetoothStateChangeReceiver.java
@@ -8,7 +8,7 @@ import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.support.v4.content.LocalBroadcastManager;
-import nodomain.freeyourgadget.gadgetbridge.service.BluetoothCommunicationService;
+import nodomain.freeyourgadget.gadgetbridge.service.DeviceCommunicationService;
import nodomain.freeyourgadget.gadgetbridge.activities.ControlCenter;
public class BluetoothStateChangeReceiver extends BroadcastReceiver {
@@ -28,17 +28,17 @@ public class BluetoothStateChangeReceiver extends BroadcastReceiver {
}
String deviceAddress = sharedPrefs.getString("last_device_address", null);
- Intent startIntent = new Intent(context, BluetoothCommunicationService.class);
- startIntent.setAction(BluetoothCommunicationService.ACTION_START);
+ Intent startIntent = new Intent(context, DeviceCommunicationService.class);
+ startIntent.setAction(DeviceCommunicationService.ACTION_START);
context.startService(startIntent);
if (deviceAddress != null) {
- Intent connectIntent = new Intent(context, BluetoothCommunicationService.class);
- connectIntent.setAction(BluetoothCommunicationService.ACTION_CONNECT);
- connectIntent.putExtra(BluetoothCommunicationService.EXTRA_DEVICE_ADDRESS, deviceAddress);
+ Intent connectIntent = new Intent(context, DeviceCommunicationService.class);
+ connectIntent.setAction(DeviceCommunicationService.ACTION_CONNECT);
+ connectIntent.putExtra(DeviceCommunicationService.EXTRA_DEVICE_ADDRESS, deviceAddress);
context.startService(connectIntent);
}
} else if (intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, -1) == BluetoothAdapter.STATE_OFF) {
- Intent stopIntent = new Intent(context, BluetoothCommunicationService.class);
+ Intent stopIntent = new Intent(context, DeviceCommunicationService.class);
context.stopService(stopIntent);
Intent quitIntent = new Intent(ControlCenter.ACTION_QUIT);
diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/K9Receiver.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/K9Receiver.java
index 13b539630..afbe5baa9 100644
--- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/K9Receiver.java
+++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/K9Receiver.java
@@ -12,7 +12,7 @@ import android.preference.PreferenceManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import nodomain.freeyourgadget.gadgetbridge.service.BluetoothCommunicationService;
+import nodomain.freeyourgadget.gadgetbridge.service.DeviceCommunicationService;
public class K9Receiver extends BroadcastReceiver {
@@ -65,8 +65,8 @@ public class K9Receiver extends BroadcastReceiver {
} while (c.moveToNext());
c.close();
- Intent startIntent = new Intent(context, BluetoothCommunicationService.class);
- startIntent.setAction(BluetoothCommunicationService.ACTION_NOTIFICATION_EMAIL);
+ Intent startIntent = new Intent(context, DeviceCommunicationService.class);
+ startIntent.setAction(DeviceCommunicationService.ACTION_NOTIFICATION_EMAIL);
startIntent.putExtra("notification_sender", sender);
startIntent.putExtra("notification_subject", subject);
startIntent.putExtra("notification_body", preview);
diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/MusicPlaybackReceiver.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/MusicPlaybackReceiver.java
index c65cc6206..45d957735 100644
--- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/MusicPlaybackReceiver.java
+++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/MusicPlaybackReceiver.java
@@ -7,7 +7,7 @@ import android.content.Intent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import nodomain.freeyourgadget.gadgetbridge.service.BluetoothCommunicationService;
+import nodomain.freeyourgadget.gadgetbridge.service.DeviceCommunicationService;
public class MusicPlaybackReceiver extends BroadcastReceiver {
private static final Logger LOG = LoggerFactory.getLogger(MusicPlaybackReceiver.class);
@@ -20,8 +20,8 @@ public class MusicPlaybackReceiver extends BroadcastReceiver {
LOG.info("Current track: " + artist + ", " + album + ", " + track);
- Intent startIntent = new Intent(context, BluetoothCommunicationService.class);
- startIntent.setAction(BluetoothCommunicationService.ACTION_SETMUSICINFO);
+ Intent startIntent = new Intent(context, DeviceCommunicationService.class);
+ startIntent.setAction(DeviceCommunicationService.ACTION_SETMUSICINFO);
startIntent.putExtra("music_artist", artist);
startIntent.putExtra("music_album", album);
startIntent.putExtra("music_track", track);
diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/NotificationListener.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/NotificationListener.java
index 4bf6ed21f..6c8e72da3 100644
--- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/NotificationListener.java
+++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/NotificationListener.java
@@ -17,7 +17,7 @@ import android.support.v4.content.LocalBroadcastManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import nodomain.freeyourgadget.gadgetbridge.service.BluetoothCommunicationService;
+import nodomain.freeyourgadget.gadgetbridge.service.DeviceCommunicationService;
public class NotificationListener extends NotificationListenerService {
@@ -53,7 +53,7 @@ public class NotificationListener extends NotificationListenerService {
@Override
public void onNotificationPosted(StatusBarNotification sbn) {
/*
- * return early if BluetoothCommunicationService is not running,
+ * return early if DeviceCommunicationService is not running,
* else the service would get started every time we get a notification.
* unfortunately we cannot enable/disable NotificationListener at runtime like we do with
* broadcast receivers because it seems to invalidate the permissions that are
@@ -62,7 +62,7 @@ public class NotificationListener extends NotificationListenerService {
boolean isServiceRunning = false;
ActivityManager manager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
- if (BluetoothCommunicationService.class.getName().equals(service.service.getClassName())) {
+ if (DeviceCommunicationService.class.getName().equals(service.service.getClassName())) {
isServiceRunning = true;
}
}
@@ -119,8 +119,8 @@ public class NotificationListener extends NotificationListenerService {
}
if (content != null) {
- Intent startIntent = new Intent(NotificationListener.this, BluetoothCommunicationService.class);
- startIntent.setAction(BluetoothCommunicationService.ACTION_NOTIFICATION_GENERIC);
+ Intent startIntent = new Intent(NotificationListener.this, DeviceCommunicationService.class);
+ startIntent.setAction(DeviceCommunicationService.ACTION_NOTIFICATION_GENERIC);
startIntent.putExtra("notification_title", title);
startIntent.putExtra("notification_body", content);
startService(startIntent);
diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/PebbleReceiver.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/PebbleReceiver.java
index 380252331..a74f995c4 100644
--- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/PebbleReceiver.java
+++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/PebbleReceiver.java
@@ -12,7 +12,7 @@ import org.json.JSONException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import nodomain.freeyourgadget.gadgetbridge.service.BluetoothCommunicationService;
+import nodomain.freeyourgadget.gadgetbridge.service.DeviceCommunicationService;
public class PebbleReceiver extends BroadcastReceiver {
@@ -51,8 +51,8 @@ public class PebbleReceiver extends BroadcastReceiver {
}
if (title != null && body != null) {
- Intent startIntent = new Intent(context, BluetoothCommunicationService.class);
- startIntent.setAction(BluetoothCommunicationService.ACTION_NOTIFICATION_SMS);
+ Intent startIntent = new Intent(context, DeviceCommunicationService.class);
+ startIntent.setAction(DeviceCommunicationService.ACTION_NOTIFICATION_SMS);
startIntent.putExtra("notification_sender", title);
startIntent.putExtra("notification_body", body);
context.startService(startIntent);
diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/PhoneCallReceiver.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/PhoneCallReceiver.java
index dab7e2062..c462c94b5 100644
--- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/PhoneCallReceiver.java
+++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/PhoneCallReceiver.java
@@ -5,7 +5,7 @@ import android.content.Context;
import android.content.Intent;
import android.telephony.TelephonyManager;
-import nodomain.freeyourgadget.gadgetbridge.service.BluetoothCommunicationService;
+import nodomain.freeyourgadget.gadgetbridge.service.DeviceCommunicationService;
import nodomain.freeyourgadget.gadgetbridge.model.ServiceCommand;
@@ -62,8 +62,8 @@ public class PhoneCallReceiver extends BroadcastReceiver {
break;
}
if (callCommand != null) {
- Intent startIntent = new Intent(context, BluetoothCommunicationService.class);
- startIntent.setAction(BluetoothCommunicationService.ACTION_CALLSTATE);
+ Intent startIntent = new Intent(context, DeviceCommunicationService.class);
+ startIntent.setAction(DeviceCommunicationService.ACTION_CALLSTATE);
startIntent.putExtra("call_phonenumber", mSavedNumber);
startIntent.putExtra("call_command", callCommand.ordinal());
context.startService(startIntent);
diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/SMSReceiver.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/SMSReceiver.java
index 7bc56100d..599366cd2 100644
--- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/SMSReceiver.java
+++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/SMSReceiver.java
@@ -9,7 +9,7 @@ import android.os.PowerManager;
import android.preference.PreferenceManager;
import android.telephony.SmsMessage;
-import nodomain.freeyourgadget.gadgetbridge.service.BluetoothCommunicationService;
+import nodomain.freeyourgadget.gadgetbridge.service.DeviceCommunicationService;
public class SMSReceiver extends BroadcastReceiver {
@@ -36,8 +36,8 @@ public class SMSReceiver extends BroadcastReceiver {
String body = message.getDisplayMessageBody();
String sender = message.getOriginatingAddress();
if (sender != null && body != null) {
- Intent startIntent = new Intent(context, BluetoothCommunicationService.class);
- startIntent.setAction(BluetoothCommunicationService.ACTION_NOTIFICATION_SMS);
+ Intent startIntent = new Intent(context, DeviceCommunicationService.class);
+ startIntent.setAction(DeviceCommunicationService.ACTION_NOTIFICATION_SMS);
startIntent.putExtra("notification_sender", sender);
startIntent.putExtra("notification_body", body);
context.startService(startIntent);
diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/TimeChangeReceiver.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/TimeChangeReceiver.java
index 5b2946485..3142f24b6 100644
--- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/TimeChangeReceiver.java
+++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/TimeChangeReceiver.java
@@ -9,7 +9,7 @@ import android.preference.PreferenceManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import nodomain.freeyourgadget.gadgetbridge.service.BluetoothCommunicationService;
+import nodomain.freeyourgadget.gadgetbridge.service.DeviceCommunicationService;
public class TimeChangeReceiver extends BroadcastReceiver {
@@ -23,8 +23,8 @@ public class TimeChangeReceiver extends BroadcastReceiver {
if (sharedPrefs.getBoolean("datetime_synconconnect", true) && (action.equals(Intent.ACTION_TIME_CHANGED) || action.equals(Intent.ACTION_TIMEZONE_CHANGED))) {
LOG.info("Time or Timezone changed, syncing with device");
- Intent startIntent = new Intent(context, BluetoothCommunicationService.class);
- startIntent.setAction(BluetoothCommunicationService.ACTION_SETTIME);
+ Intent startIntent = new Intent(context, DeviceCommunicationService.class);
+ startIntent.setAction(DeviceCommunicationService.ACTION_SETTIME);
context.startService(startIntent);
}
}
diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/BluetoothCommunicationService.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/DeviceCommunicationService.java
similarity index 69%
rename from app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/BluetoothCommunicationService.java
rename to app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/DeviceCommunicationService.java
index 195819aec..b0aa94faa 100644
--- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/BluetoothCommunicationService.java
+++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/DeviceCommunicationService.java
@@ -2,8 +2,6 @@ package nodomain.freeyourgadget.gadgetbridge.service;
import android.app.NotificationManager;
import android.app.Service;
-import android.bluetooth.BluetoothAdapter;
-import android.bluetooth.BluetoothDevice;
import android.content.BroadcastReceiver;
import android.content.ContentResolver;
import android.content.Context;
@@ -24,54 +22,51 @@ import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.UUID;
-import nodomain.freeyourgadget.gadgetbridge.model.DeviceType;
-import nodomain.freeyourgadget.gadgetbridge.util.GB;
-import nodomain.freeyourgadget.gadgetbridge.model.ServiceCommand;
+import nodomain.freeyourgadget.gadgetbridge.R;
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice.State;
-import nodomain.freeyourgadget.gadgetbridge.R;
import nodomain.freeyourgadget.gadgetbridge.model.Alarm;
-import nodomain.freeyourgadget.gadgetbridge.service.devices.miband.MiBandSupport;
-import nodomain.freeyourgadget.gadgetbridge.service.devices.pebble.PebbleSupport;
+import nodomain.freeyourgadget.gadgetbridge.model.ServiceCommand;
+import nodomain.freeyourgadget.gadgetbridge.util.GB;
-public class BluetoothCommunicationService extends Service {
+public class DeviceCommunicationService extends Service {
public static final String ACTION_START
- = "nodomain.freeyourgadget.gadgetbridge.bluetoothcommunicationservice.action.start";
+ = "nodomain.freeyourgadget.gadgetbridge.devicecommunicationservice.action.start";
public static final String ACTION_CONNECT
- = "nodomain.freeyourgadget.gadgetbridge.bluetoothcommunicationservice.action.connect";
+ = "nodomain.freeyourgadget.gadgetbridge.devicecommunicationservice.action.connect";
public static final String ACTION_NOTIFICATION_GENERIC
- = "nodomain.freeyourgadget.gadgetbridge.bluetoothcommunicationservice.action.notification_generic";
+ = "nodomain.freeyourgadget.gadgetbridge.devicecommunicationservice.action.notification_generic";
public static final String ACTION_NOTIFICATION_SMS
- = "nodomain.freeyourgadget.gadgetbridge.bluetoothcommunicationservice.action.notification_sms";
+ = "nodomain.freeyourgadget.gadgetbridge.devicecommunicationservice.action.notification_sms";
public static final String ACTION_NOTIFICATION_EMAIL
- = "nodomain.freeyourgadget.gadgetbridge.bluetoothcommunicationservice.action.notification_email";
+ = "nodomain.freeyourgadget.gadgetbridge.devicecommunicationservice.action.notification_email";
public static final String ACTION_CALLSTATE
- = "nodomain.freeyourgadget.gadgetbridge.bluetoothcommunicationservice.action.callstate";
+ = "nodomain.freeyourgadget.gadgetbridge.devicecommunicationservice.action.callstate";
public static final String ACTION_SETTIME
- = "nodomain.freeyourgadget.gadgetbridge.bluetoothcommunicationservice.action.settime";
+ = "nodomain.freeyourgadget.gadgetbridge.devicecommunicationservice.action.settime";
public static final String ACTION_SETMUSICINFO
- = "nodomain.freeyourgadget.gadgetbridge.bluetoothcommunicationservice.action.setmusicinfo";
+ = "nodomain.freeyourgadget.gadgetbridge.devicecommunicationservice.action.setmusicinfo";
public static final String ACTION_REQUEST_VERSIONINFO
- = "nodomain.freeyourgadget.gadgetbridge.bluetoothcommunicationservice.action.request_versioninfo";
+ = "nodomain.freeyourgadget.gadgetbridge.devicecommunicationservice.action.request_versioninfo";
public static final String ACTION_REQUEST_APPINFO
- = "nodomain.freeyourgadget.gadgetbridge.bluetoothcommunicationservice.action.request_appinfo";
+ = "nodomain.freeyourgadget.gadgetbridge.devicecommunicationservice.action.request_appinfo";
public static final String ACTION_REQUEST_SCREENSHOT
- = "nodomain.freeyourgadget.gadgetbridge.bluetoothcommunicationservice.action.request_screenshot";
+ = "nodomain.freeyourgadget.gadgetbridge.devicecommunicationservice.action.request_screenshot";
public static final String ACTION_STARTAPP
- = "nodomain.freeyourgadget.gadgetbridge.bluetoothcommunicationservice.action.startapp";
+ = "nodomain.freeyourgadget.gadgetbridge.devicecommunicationservice.action.startapp";
public static final String ACTION_DELETEAPP
- = "nodomain.freeyourgadget.gadgetbridge.bluetoothcommunicationservice.action.deleteapp";
+ = "nodomain.freeyourgadget.gadgetbridge.devicecommunicationservice.action.deleteapp";
public static final String ACTION_INSTALL
- = "nodomain.freeyourgadget.gadgetbridge.bluetoothcommunicationservice.action.install";
- public static final String ACTION_REBOOT = "nodomain.freeyourgadget.gadgetbridge.bluetoothcommunicationservice.action.reboot";
- public static final String ACTION_FETCH_ACTIVITY_DATA = "nodomain.freeyourgadget.gadgetbridge.bluetoothcommunicationservice.action.fetch_activity_data";
- public static final String ACTION_DISCONNECT = "nodomain.freeyourgadget.gadgetbridge.bluetoothcommunicationservice.action.disconnect";
- public static final String ACTION_FIND_DEVICE = "nodomain.freeyourgadget.gadgetbridge.bluetoothcommunicationservice.action.find_device";
- public static final String ACTION_SET_ALARMS = "nodomain.freeyourgadget.gadgetbridge.bluetoothcommunicationservice.action.set_alarms";
+ = "nodomain.freeyourgadget.gadgetbridge.devicecommunicationservice.action.install";
+ public static final String ACTION_REBOOT = "nodomain.freeyourgadget.gadgetbridge.devicecommunicationservice.action.reboot";
+ public static final String ACTION_FETCH_ACTIVITY_DATA = "nodomain.freeyourgadget.gadgetbridge.devicecommunicationservice.action.fetch_activity_data";
+ public static final String ACTION_DISCONNECT = "nodomain.freeyourgadget.gadgetbridge.devicecommunicationservice.action.disconnect";
+ public static final String ACTION_FIND_DEVICE = "nodomain.freeyourgadget.gadgetbridge.devicecommunicationservice.action.find_device";
+ public static final String ACTION_SET_ALARMS = "nodomain.freeyourgadget.gadgetbridge.devicecommunicationservice.action.set_alarms";
public static final String EXTRA_PERFORM_PAIR = "perform_pair";
- private static final Logger LOG = LoggerFactory.getLogger(BluetoothCommunicationService.class);
+ private static final Logger LOG = LoggerFactory.getLogger(DeviceCommunicationService.class);
public static final String EXTRA_DEVICE_ADDRESS = "device_address";
private boolean mStarted = false;
@@ -99,7 +94,7 @@ public class BluetoothCommunicationService extends Service {
@Override
public void onCreate() {
- LOG.debug("BluetoothCommunicationService is being created");
+ LOG.debug("DeviceCommunicationService is being created");
super.onCreate();
LocalBroadcastManager.getInstance(this).registerReceiver(mReceiver, new IntentFilter(GBDevice.ACTION_DEVICE_CHANGED));
}
@@ -146,43 +141,30 @@ public class BluetoothCommunicationService extends Service {
switch (action) {
case ACTION_CONNECT:
- //Check the system status
- BluetoothAdapter mBtAdapter = BluetoothAdapter.getDefaultAdapter();
- if (mBtAdapter == null) {
- Toast.makeText(this, R.string.bluetooth_is_not_supported_, Toast.LENGTH_SHORT).show();
- } else if (!mBtAdapter.isEnabled()) {
- Toast.makeText(this, R.string.bluetooth_is_disabled_, Toast.LENGTH_SHORT).show();
- } else {
- String btDeviceAddress = intent.getStringExtra(EXTRA_DEVICE_ADDRESS);
- SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);
- sharedPrefs.edit().putString("last_device_address", btDeviceAddress).apply();
+ String btDeviceAddress = intent.getStringExtra(EXTRA_DEVICE_ADDRESS);
+ SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);
+ sharedPrefs.edit().putString("last_device_address", btDeviceAddress).apply();
- if (btDeviceAddress != null && !isConnected() && !isConnecting()) {
+ if (btDeviceAddress != null && !isConnected() && !isConnecting()) {
+ if (mDeviceSupport != null) {
+ mDeviceSupport.dispose();
+ mDeviceSupport = null;
+ }
+ try {
+ DeviceSupportFactory factory = new DeviceSupportFactory(this);
+ mDeviceSupport = factory.createDeviceSupport(btDeviceAddress);
if (mDeviceSupport != null) {
- mDeviceSupport.dispose();
- mDeviceSupport = null;
- }
- try {
- BluetoothDevice btDevice = mBtAdapter.getRemoteDevice(btDeviceAddress);
- if (btDevice.getName() == null || btDevice.getName().equals("MI")) { //FIXME: workaround for Miband not being paired
- mGBDevice = new GBDevice(btDeviceAddress, "MI", DeviceType.MIBAND);
- mDeviceSupport = new ServiceDeviceSupport(new MiBandSupport());
- } else if (btDevice.getName().indexOf("Pebble") == 0) {
- mGBDevice = new GBDevice(btDeviceAddress, btDevice.getName(), DeviceType.PEBBLE);
- mDeviceSupport = new ServiceDeviceSupport(new PebbleSupport());
+ mGBDevice = mDeviceSupport.getDevice();
+ if (pair) {
+ mDeviceSupport.pair();
+ } else {
+ mDeviceSupport.connect();
}
- if (mDeviceSupport != null) {
- mDeviceSupport.setContext(mGBDevice, mBtAdapter, this);
- if (pair) {
- mDeviceSupport.pair();
- } else {
- mDeviceSupport.connect();
- }
- }
- } catch (Exception e) {
- Toast.makeText(this, R.string.cannot_connect_bt_address_invalid_, Toast.LENGTH_SHORT).show();
- e.printStackTrace();
}
+ } catch (Exception e) {
+ GB.toast(this, getString(R.string.cannot_connect, e.getMessage()), Toast.LENGTH_SHORT, GB.ERROR);
+ mDeviceSupport = null;
+ mGBDevice = null;
}
}
break;
@@ -294,7 +276,7 @@ public class BluetoothCommunicationService extends Service {
@Override
public void onDestroy() {
- LOG.debug("BluetoothCommunicationService is being destroyed");
+ LOG.debug("DeviceCommunicationService is being destroyed");
super.onDestroy();
LocalBroadcastManager.getInstance(this).unregisterReceiver(mReceiver);
diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/DeviceSupport.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/DeviceSupport.java
index 41ec6c6ab..a76285c18 100644
--- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/DeviceSupport.java
+++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/DeviceSupport.java
@@ -8,7 +8,7 @@ import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
/**
* Provides the communication support for a specific device. Instances will only
- * be used inside the BluetoothCommunicationService. Has hooks to manage the life cycle
+ * be used inside the DeviceCommunicationService. Has hooks to manage the life cycle
* of a device: instances of this interface will be created, initialized, and disposed
* as needed.
*
diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/DeviceSupportFactory.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/DeviceSupportFactory.java
new file mode 100644
index 000000000..9465c3e24
--- /dev/null
+++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/DeviceSupportFactory.java
@@ -0,0 +1,70 @@
+package nodomain.freeyourgadget.gadgetbridge.service;
+
+import android.bluetooth.BluetoothAdapter;
+import android.bluetooth.BluetoothDevice;
+import android.content.Context;
+import android.widget.Toast;
+
+import nodomain.freeyourgadget.gadgetbridge.GBException;
+import nodomain.freeyourgadget.gadgetbridge.R;
+import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
+import nodomain.freeyourgadget.gadgetbridge.model.DeviceType;
+import nodomain.freeyourgadget.gadgetbridge.service.devices.miband.MiBandSupport;
+import nodomain.freeyourgadget.gadgetbridge.service.devices.pebble.PebbleSupport;
+import nodomain.freeyourgadget.gadgetbridge.util.GB;
+
+public class DeviceSupportFactory {
+ private final BluetoothAdapter mBtAdapter;
+ private Context mContext;
+
+ public DeviceSupportFactory(Context context) {
+ mContext = context;
+ mBtAdapter = BluetoothAdapter.getDefaultAdapter();
+ }
+
+ public synchronized DeviceSupport createDeviceSupport(String deviceAddress) throws GBException {
+ DeviceSupport deviceSupport = createBTDeviceSupport(deviceAddress);
+ if (deviceSupport != null) {
+ return deviceSupport;
+ }
+ // support for other kinds of transports
+
+ // no device found, check transport availability and warn
+ checkBtAvailability();
+ return null;
+ }
+
+ private void checkBtAvailability() {
+ if (mBtAdapter == null) {
+ GB.toast(mContext.getString(R.string.bluetooth_is_not_supported_), Toast.LENGTH_SHORT, GB.WARN);
+ } else if (!mBtAdapter.isEnabled()) {
+ GB.toast(mContext.getString(R.string.bluetooth_is_disabled_), Toast.LENGTH_SHORT, GB.WARN);
+ }
+ }
+
+ private DeviceSupport createBTDeviceSupport(String deviceAddress) throws GBException {
+ if (mBtAdapter != null && mBtAdapter.isEnabled()) {
+ GBDevice gbDevice = null;
+ DeviceSupport deviceSupport = null;
+
+ try {
+ BluetoothDevice btDevice = mBtAdapter.getRemoteDevice(deviceAddress);
+ if (btDevice.getName() == null || btDevice.getName().equals("MI")) { //FIXME: workaround for Miband not being paired
+ gbDevice = new GBDevice(deviceAddress, "MI", DeviceType.MIBAND);
+ deviceSupport = new MiBandSupport();
+ } else if (btDevice.getName().indexOf("Pebble") == 0) {
+ gbDevice = new GBDevice(deviceAddress, btDevice.getName(), DeviceType.PEBBLE);
+ deviceSupport = new PebbleSupport();
+ }
+ if (deviceSupport != null) {
+ deviceSupport = new ServiceDeviceSupport(deviceSupport);
+ deviceSupport.setContext(gbDevice, mBtAdapter, mContext);
+ return deviceSupport;
+ }
+ } catch (Exception e) {
+ throw new GBException(mContext.getString(R.string.cannot_connect_bt_address_invalid_, e));
+ }
+ }
+ return null;
+ }
+}
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 25f2c653b..a97d7613c 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -160,4 +160,5 @@
Target steps for each day
Error executing \'%1$s\'
Your Activity (ALPHA)
+ Cannot connect: %1$s