mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-12-26 02:25:50 +01:00
Last refactoring for now: BluetoothCommunicationService
- rename to DeviceCommunicationService - move all bluetooth related bits into separate DeviceSupportFactory class
This commit is contained in:
parent
db4261e02b
commit
c407ed1a76
@ -164,7 +164,7 @@
|
||||
<action android:name="android.service.notification.NotificationListenerService" />
|
||||
</intent-filter>
|
||||
</service>
|
||||
<service android:name=".service.BluetoothCommunicationService" />
|
||||
<service android:name=".service.DeviceCommunicationService" />
|
||||
|
||||
<receiver
|
||||
android:name=".externalevents.PhoneCallReceiver"
|
||||
|
@ -24,7 +24,7 @@ import java.util.UUID;
|
||||
import nodomain.freeyourgadget.gadgetbridge.impl.GBDeviceApp;
|
||||
import nodomain.freeyourgadget.gadgetbridge.R;
|
||||
import nodomain.freeyourgadget.gadgetbridge.adapter.GBDeviceAppAdapter;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.BluetoothCommunicationService;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.DeviceCommunicationService;
|
||||
|
||||
|
||||
public class AppManagerActivity extends Activity {
|
||||
@ -71,8 +71,8 @@ public class AppManagerActivity extends Activity {
|
||||
@Override
|
||||
public void onItemClick(AdapterView parent, View v, int position, long id) {
|
||||
UUID uuid = appList.get(position).getUUID();
|
||||
Intent startAppIntent = new Intent(AppManagerActivity.this, BluetoothCommunicationService.class);
|
||||
startAppIntent.setAction(BluetoothCommunicationService.ACTION_STARTAPP);
|
||||
Intent startAppIntent = new Intent(AppManagerActivity.this, DeviceCommunicationService.class);
|
||||
startAppIntent.setAction(DeviceCommunicationService.ACTION_STARTAPP);
|
||||
startAppIntent.putExtra("app_uuid", uuid.toString());
|
||||
startService(startAppIntent);
|
||||
}
|
||||
@ -86,8 +86,8 @@ public class AppManagerActivity extends Activity {
|
||||
|
||||
LocalBroadcastManager.getInstance(this).registerReceiver(mReceiver, filter);
|
||||
|
||||
Intent startIntent = new Intent(this, BluetoothCommunicationService.class);
|
||||
startIntent.setAction(BluetoothCommunicationService.ACTION_REQUEST_APPINFO);
|
||||
Intent startIntent = new Intent(this, DeviceCommunicationService.class);
|
||||
startIntent.setAction(DeviceCommunicationService.ACTION_REQUEST_APPINFO);
|
||||
startService(startIntent);
|
||||
}
|
||||
|
||||
@ -106,8 +106,8 @@ public class AppManagerActivity extends Activity {
|
||||
switch (item.getItemId()) {
|
||||
case R.id.appmanager_app_delete:
|
||||
if (selectedApp != null) {
|
||||
Intent deleteIntent = new Intent(this, BluetoothCommunicationService.class);
|
||||
deleteIntent.setAction(BluetoothCommunicationService.ACTION_DELETEAPP);
|
||||
Intent deleteIntent = new Intent(this, DeviceCommunicationService.class);
|
||||
deleteIntent.setAction(DeviceCommunicationService.ACTION_DELETEAPP);
|
||||
deleteIntent.putExtra("app_uuid", selectedApp.getUUID().toString());
|
||||
startService(deleteIntent);
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.BluetoothCommunicationService;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.DeviceCommunicationService;
|
||||
import nodomain.freeyourgadget.gadgetbridge.impl.GBAlarm;
|
||||
import nodomain.freeyourgadget.gadgetbridge.R;
|
||||
import nodomain.freeyourgadget.gadgetbridge.adapter.GBAlarmListAdapter;
|
||||
@ -78,9 +78,9 @@ public class ConfigureAlarms extends ListActivity {
|
||||
}
|
||||
|
||||
private void sendAlarmsToDevice() {
|
||||
Intent startIntent = new Intent(ConfigureAlarms.this, BluetoothCommunicationService.class);
|
||||
Intent startIntent = new Intent(ConfigureAlarms.this, DeviceCommunicationService.class);
|
||||
startIntent.putParcelableArrayListExtra("alarms", mGBAlarmListAdapter.getAlarmList());
|
||||
startIntent.setAction(BluetoothCommunicationService.ACTION_SET_ALARMS);
|
||||
startIntent.setAction(DeviceCommunicationService.ACTION_SET_ALARMS);
|
||||
startService(startIntent);
|
||||
}
|
||||
}
|
||||
|
@ -30,6 +30,7 @@ import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.devices.DeviceCoordinator;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.DeviceCommunicationService;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.DeviceHelper;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.DeviceType;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.GB;
|
||||
@ -38,7 +39,6 @@ import nodomain.freeyourgadget.gadgetbridge.R;
|
||||
import nodomain.freeyourgadget.gadgetbridge.activities.charts.ChartsActivity;
|
||||
import nodomain.freeyourgadget.gadgetbridge.adapter.GBDeviceAdapter;
|
||||
import nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.BluetoothCommunicationService;
|
||||
|
||||
public class ControlCenter extends Activity {
|
||||
|
||||
@ -117,9 +117,9 @@ public class ControlCenter extends Activity {
|
||||
startActivity(startIntent);
|
||||
}
|
||||
} else {
|
||||
Intent startIntent = new Intent(ControlCenter.this, BluetoothCommunicationService.class);
|
||||
startIntent.setAction(BluetoothCommunicationService.ACTION_CONNECT);
|
||||
startIntent.putExtra(BluetoothCommunicationService.EXTRA_DEVICE_ADDRESS, deviceList.get(position).getAddress());
|
||||
Intent startIntent = new Intent(ControlCenter.this, DeviceCommunicationService.class);
|
||||
startIntent.setAction(DeviceCommunicationService.ACTION_CONNECT);
|
||||
startIntent.putExtra(DeviceCommunicationService.EXTRA_DEVICE_ADDRESS, deviceList.get(position).getAddress());
|
||||
startService(startIntent);
|
||||
}
|
||||
}
|
||||
@ -146,8 +146,8 @@ public class ControlCenter extends Activity {
|
||||
Intent enableIntent = new Intent("android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS");
|
||||
startActivity(enableIntent);
|
||||
}
|
||||
Intent startIntent = new Intent(this, BluetoothCommunicationService.class);
|
||||
startIntent.setAction(BluetoothCommunicationService.ACTION_START);
|
||||
Intent startIntent = new Intent(this, DeviceCommunicationService.class);
|
||||
startIntent.setAction(DeviceCommunicationService.ACTION_START);
|
||||
startService(startIntent);
|
||||
|
||||
|
||||
@ -160,14 +160,14 @@ public class ControlCenter extends Activity {
|
||||
}
|
||||
|
||||
/**
|
||||
* Requests information from the {@link BluetoothCommunicationService} about the connection state,
|
||||
* Requests information from the {@link DeviceCommunicationService} about the connection state,
|
||||
* firmware info, etc.
|
||||
* <p/>
|
||||
* 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);
|
||||
|
@ -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);
|
||||
}
|
||||
});
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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:
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
@ -8,7 +8,7 @@ import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
||||
|
||||
/**
|
||||
* Provides the communication support for a specific device. Instances will <b>only</b>
|
||||
* 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.
|
||||
* <p/>
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
@ -160,4 +160,5 @@
|
||||
<string name="miband_prefs_fitness_goal">Target steps for each day</string>
|
||||
<string name="dbaccess_error_executing">Error executing \'%1$s\'</string>
|
||||
<string name="controlcenter_start_activitymonitor">Your Activity (ALPHA)</string>
|
||||
<string name="cannot_connect">Cannot connect: %1$s</string>
|
||||
</resources>
|
||||
|
Loading…
Reference in New Issue
Block a user