mirror of
https://codeberg.org/OpenTracksApp/OpenTracks.git
synced 2026-10-02 17:43:06 +02:00
- fix bluetooth connection manager when creating an insecure connection
- in ControlRecordingService, unbind right after handling an intent to prevent leaking ServiceConnection before handling the next intent. - update comment in TrackRecordingService
This commit is contained in:
@@ -106,6 +106,8 @@ public class ControlRecordingService extends IntentService implements ServiceCon
|
||||
Log.d(TAG, "ControlRecordingService onHandleIntent RemoteException", e);
|
||||
}
|
||||
}
|
||||
unbindService(this);
|
||||
connected = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -231,6 +231,13 @@ public class TrackRecordingService extends Service {
|
||||
* Application lifetime events:
|
||||
*/
|
||||
|
||||
/*
|
||||
* Note that this service, through the AndroidManifest.xml, is configured to
|
||||
* allow both MyTracks and third party apps to invoke it. For the onCreate
|
||||
* callback, we cannot tell whether the caller is MyTracks or a third party
|
||||
* app, thus it cannot start/stop a recording or write/update MyTracks
|
||||
* database. However, it can resume a recording.
|
||||
*/
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
@@ -270,24 +277,31 @@ public class TrackRecordingService extends Service {
|
||||
showNotification();
|
||||
}
|
||||
|
||||
/*
|
||||
* Note that this service, through the AndroidManifest.xml, is configured to
|
||||
* allow both MyTracks and third party apps to invoke it. For the onStart
|
||||
* callback, we cannot tell whether the caller is MyTracks or a third party
|
||||
* app, thus it cannot start/stop a recording or write/update MyTracks
|
||||
* database. However, it can resume a recording.
|
||||
*/
|
||||
@Override
|
||||
public void onStart(Intent intent, int startId) {
|
||||
handleStartCommand(intent, startId);
|
||||
}
|
||||
|
||||
/*
|
||||
* Note that this service, through the AndroidManifest.xml, is configured to
|
||||
* allow both MyTracks and third party apps to invoke it. For the
|
||||
* onStartCommand callback, we cannot tell whether the caller is MyTracks or a
|
||||
* third party app, thus it cannot start/stop a recording or write/update
|
||||
* MyTracks database. However, it can resume a recording.
|
||||
*/
|
||||
@Override
|
||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||
handleStartCommand(intent, startId);
|
||||
return START_STICKY;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles onStart and onStartCommand. This service, through the
|
||||
* AndroidManifest.xml, is configured to allow both MyTracks and other
|
||||
* applications to invoke it. With only the intent, we cannot tell whether the
|
||||
* caller is MyTracks or another app. Thus when starting the service through
|
||||
* this method, we cannot read/write MyTracks data or start/stop a recording.
|
||||
*/
|
||||
private void handleStartCommand(Intent intent, int startId) {
|
||||
Log.d(TAG, "TrackRecordingService.handleStartCommand: " + startId);
|
||||
|
||||
@@ -550,7 +564,7 @@ public class TrackRecordingService extends Service {
|
||||
* Recording lifecycle.
|
||||
*/
|
||||
|
||||
public long startNewTrack() {
|
||||
private long startNewTrack() {
|
||||
Log.d(TAG, "TrackRecordingService.startNewTrack");
|
||||
if (isTrackInProgress()) {
|
||||
return -1L;
|
||||
|
||||
+2
-3
@@ -263,10 +263,9 @@ public class BluetoothConnectionManager {
|
||||
private BluetoothSocket getSocket() throws IOException {
|
||||
try {
|
||||
Class<? extends BluetoothDevice> c = device.getClass();
|
||||
Method insecure = c.getMethod("createInsecureRfcommSocket",
|
||||
Integer.class);
|
||||
Method insecure = c.getMethod("createInsecureRfcommSocketToServiceRecord", UUID.class);
|
||||
insecure.setAccessible(true);
|
||||
return (BluetoothSocket) insecure.invoke(device, 1);
|
||||
return (BluetoothSocket) insecure.invoke(device, SPP_UUID);
|
||||
} catch (SecurityException e) {
|
||||
Log.e(Constants.TAG, "Unable to get insecure connect.", e);
|
||||
} catch (NoSuchMethodException e) {
|
||||
|
||||
Reference in New Issue
Block a user