forked from upstream-mirrors/OpenTracks
- 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);
|
Log.d(TAG, "ControlRecordingService onHandleIntent RemoteException", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
unbindService(this);
|
||||||
|
connected = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -231,6 +231,13 @@ public class TrackRecordingService extends Service {
|
|||||||
* Application lifetime events:
|
* 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
|
@Override
|
||||||
public void onCreate() {
|
public void onCreate() {
|
||||||
super.onCreate();
|
super.onCreate();
|
||||||
@@ -270,24 +277,31 @@ public class TrackRecordingService extends Service {
|
|||||||
showNotification();
|
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
|
@Override
|
||||||
public void onStart(Intent intent, int startId) {
|
public void onStart(Intent intent, int startId) {
|
||||||
handleStartCommand(intent, 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
|
@Override
|
||||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||||
handleStartCommand(intent, startId);
|
handleStartCommand(intent, startId);
|
||||||
return START_STICKY;
|
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) {
|
private void handleStartCommand(Intent intent, int startId) {
|
||||||
Log.d(TAG, "TrackRecordingService.handleStartCommand: " + startId);
|
Log.d(TAG, "TrackRecordingService.handleStartCommand: " + startId);
|
||||||
|
|
||||||
@@ -550,7 +564,7 @@ public class TrackRecordingService extends Service {
|
|||||||
* Recording lifecycle.
|
* Recording lifecycle.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public long startNewTrack() {
|
private long startNewTrack() {
|
||||||
Log.d(TAG, "TrackRecordingService.startNewTrack");
|
Log.d(TAG, "TrackRecordingService.startNewTrack");
|
||||||
if (isTrackInProgress()) {
|
if (isTrackInProgress()) {
|
||||||
return -1L;
|
return -1L;
|
||||||
|
|||||||
+2
-3
@@ -263,10 +263,9 @@ public class BluetoothConnectionManager {
|
|||||||
private BluetoothSocket getSocket() throws IOException {
|
private BluetoothSocket getSocket() throws IOException {
|
||||||
try {
|
try {
|
||||||
Class<? extends BluetoothDevice> c = device.getClass();
|
Class<? extends BluetoothDevice> c = device.getClass();
|
||||||
Method insecure = c.getMethod("createInsecureRfcommSocket",
|
Method insecure = c.getMethod("createInsecureRfcommSocketToServiceRecord", UUID.class);
|
||||||
Integer.class);
|
|
||||||
insecure.setAccessible(true);
|
insecure.setAccessible(true);
|
||||||
return (BluetoothSocket) insecure.invoke(device, 1);
|
return (BluetoothSocket) insecure.invoke(device, SPP_UUID);
|
||||||
} catch (SecurityException e) {
|
} catch (SecurityException e) {
|
||||||
Log.e(Constants.TAG, "Unable to get insecure connect.", e);
|
Log.e(Constants.TAG, "Unable to get insecure connect.", e);
|
||||||
} catch (NoSuchMethodException e) {
|
} catch (NoSuchMethodException e) {
|
||||||
|
|||||||
Reference in New Issue
Block a user