forked from upstream-mirrors/OpenTracks
Moved myTrackLib into MyTracks: compiles, but recording service is not started correctly.
This commit is contained in:
@@ -55,11 +55,7 @@ public class SensorStateActivity extends AbstractActivity {
|
|||||||
// Check if service is available and recording
|
// Check if service is available and recording
|
||||||
boolean isRecording = false;
|
boolean isRecording = false;
|
||||||
if (trackRecordingService != null) {
|
if (trackRecordingService != null) {
|
||||||
try {
|
|
||||||
isRecording = trackRecordingService.isRecording();
|
isRecording = trackRecordingService.isRecording();
|
||||||
} catch (RemoteException e) {
|
|
||||||
Log.e(TAG, "Unable to determine if the track recording service is recording.", e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isRecording) {
|
if (!isRecording) {
|
||||||
@@ -151,20 +147,13 @@ public class SensorStateActivity extends AbstractActivity {
|
|||||||
if (trackRecordingService == null) {
|
if (trackRecordingService == null) {
|
||||||
Log.d(TAG, "Cannot get the track recording service.");
|
Log.d(TAG, "Cannot get the track recording service.");
|
||||||
} else {
|
} else {
|
||||||
try {
|
|
||||||
sensorState = Sensor.SensorState.valueOf(trackRecordingService.getSensorState());
|
sensorState = Sensor.SensorState.valueOf(trackRecordingService.getSensorState());
|
||||||
} catch (RemoteException e) {
|
|
||||||
Log.e(TAG, "Cannote read sensor state.", e);
|
|
||||||
sensorState = Sensor.SensorState.NONE;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
byte[] buff = trackRecordingService.getSensorData();
|
byte[] buff = trackRecordingService.getSensorData();
|
||||||
if (buff != null) {
|
if (buff != null) {
|
||||||
sensorDataSet = Sensor.SensorDataSet.parseFrom(buff);
|
sensorDataSet = Sensor.SensorDataSet.parseFrom(buff);
|
||||||
}
|
}
|
||||||
} catch (RemoteException e) {
|
|
||||||
Log.e(TAG, "Cannot read sensor data set.", e);
|
|
||||||
} catch (InvalidProtocolBufferException e) {
|
} catch (InvalidProtocolBufferException e) {
|
||||||
Log.e(TAG, "Cannot read sensor data set.", e);
|
Log.e(TAG, "Cannot read sensor data set.", e);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -146,11 +146,6 @@ public class TrackController {
|
|||||||
*/
|
*/
|
||||||
private long getTotalTime() {
|
private long getTotalTime() {
|
||||||
ITrackRecordingService trackRecordingService = trackRecordingServiceConnection.getServiceIfBound();
|
ITrackRecordingService trackRecordingService = trackRecordingServiceConnection.getServiceIfBound();
|
||||||
try {
|
|
||||||
return trackRecordingService != null ? trackRecordingService.getTotalTime() : 0L;
|
return trackRecordingService != null ? trackRecordingService.getTotalTime() : 0L;
|
||||||
} catch (RemoteException e) {
|
|
||||||
Log.e(TAG, "exception", e);
|
|
||||||
return 0L;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -115,7 +115,7 @@ public class TrackListActivity extends AbstractTrackActivity implements FileType
|
|||||||
}
|
}
|
||||||
if (startNewRecording) {
|
if (startNewRecording) {
|
||||||
startGps = false;
|
startGps = false;
|
||||||
try {
|
|
||||||
long trackId = service.startNewTrack();
|
long trackId = service.startNewTrack();
|
||||||
startNewRecording = false;
|
startNewRecording = false;
|
||||||
Intent intent = IntentUtils.newIntent(TrackListActivity.this, TrackDetailActivity.class)
|
Intent intent = IntentUtils.newIntent(TrackListActivity.this, TrackDetailActivity.class)
|
||||||
@@ -124,21 +124,10 @@ public class TrackListActivity extends AbstractTrackActivity implements FileType
|
|||||||
Toast.makeText(
|
Toast.makeText(
|
||||||
TrackListActivity.this, R.string.track_list_record_success, Toast.LENGTH_SHORT)
|
TrackListActivity.this, R.string.track_list_record_success, Toast.LENGTH_SHORT)
|
||||||
.show();
|
.show();
|
||||||
} catch (RemoteException e) {
|
|
||||||
Toast.makeText(
|
|
||||||
TrackListActivity.this, R.string.track_list_record_error, Toast.LENGTH_LONG).show();
|
|
||||||
Log.e(TAG, "Unable to start a new recording.", e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (startGps) {
|
if (startGps) {
|
||||||
try {
|
|
||||||
service.startGps();
|
service.startGps();
|
||||||
startGps = false;
|
startGps = false;
|
||||||
} catch (RemoteException e) {
|
|
||||||
Toast.makeText(TrackListActivity.this, R.string.gps_starting_error, Toast.LENGTH_LONG)
|
|
||||||
.show();
|
|
||||||
Log.e(TAG, "Unable to start gps");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -477,11 +466,7 @@ public class TrackListActivity extends AbstractTrackActivity implements FileType
|
|||||||
} else {
|
} else {
|
||||||
ITrackRecordingService trackRecordingService = trackRecordingServiceConnection.getServiceIfBound();
|
ITrackRecordingService trackRecordingService = trackRecordingServiceConnection.getServiceIfBound();
|
||||||
if (trackRecordingService != null) {
|
if (trackRecordingService != null) {
|
||||||
try {
|
|
||||||
trackRecordingService.stopGps();
|
trackRecordingService.stopGps();
|
||||||
} catch (RemoteException e) {
|
|
||||||
Log.e(TAG, "Unable to stop gps.", e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
trackRecordingServiceConnection.unbindAndStop();
|
trackRecordingServiceConnection.unbindAndStop();
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-5
@@ -60,7 +60,7 @@ public class ControlRecordingService extends IntentService implements ServiceCon
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onServiceConnected(ComponentName name, IBinder service) {
|
public void onServiceConnected(ComponentName name, IBinder service) {
|
||||||
trackRecordingService = ITrackRecordingService.Stub.asInterface(service);
|
trackRecordingService = (ITrackRecordingService)service;
|
||||||
notifyConnected();
|
notifyConnected();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -109,7 +109,6 @@ public class ControlRecordingService extends IntentService implements ServiceCon
|
|||||||
void onHandleIntent(Intent intent, ITrackRecordingService service) {
|
void onHandleIntent(Intent intent, ITrackRecordingService service) {
|
||||||
String action = intent.getAction();
|
String action = intent.getAction();
|
||||||
if (action != null) {
|
if (action != null) {
|
||||||
try {
|
|
||||||
if (action.equals(getString(R.string.track_action_start))) {
|
if (action.equals(getString(R.string.track_action_start))) {
|
||||||
service.startNewTrack();
|
service.startNewTrack();
|
||||||
} else if (action.equals(getString(R.string.track_action_end))) {
|
} else if (action.equals(getString(R.string.track_action_end))) {
|
||||||
@@ -119,9 +118,6 @@ public class ControlRecordingService extends IntentService implements ServiceCon
|
|||||||
} else if (action.equals(getString(R.string.track_action_resume))) {
|
} else if (action.equals(getString(R.string.track_action_resume))) {
|
||||||
service.resumeCurrentTrack();
|
service.resumeCurrentTrack();
|
||||||
}
|
}
|
||||||
} catch (RemoteException e) {
|
|
||||||
Log.d(TAG, "ControlRecordingService onHandleIntent RemoteException", e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
unbindService(this);
|
unbindService(this);
|
||||||
connected = false;
|
connected = false;
|
||||||
|
|||||||
+5
-3
@@ -15,13 +15,15 @@
|
|||||||
*/
|
*/
|
||||||
package com.google.android.apps.mytracks.services;
|
package com.google.android.apps.mytracks.services;
|
||||||
|
|
||||||
|
import android.location.Location;
|
||||||
|
|
||||||
import com.google.android.apps.mytracks.content.WaypointCreationRequest;
|
import com.google.android.apps.mytracks.content.WaypointCreationRequest;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* MyTracks service.
|
* MyTracks service.
|
||||||
* This service is the process that actually records and manages tracks.
|
* This service is the process that actually records and manages tracks.
|
||||||
*/
|
*/
|
||||||
interface ITrackRecordingService {
|
public interface ITrackRecordingService {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Starts gps.
|
* Starts gps.
|
||||||
@@ -81,7 +83,7 @@ interface ITrackRecordingService {
|
|||||||
* @param request the details of the waypoint to be inserted
|
* @param request the details of the waypoint to be inserted
|
||||||
* @return the ID of the inserted waypoint
|
* @return the ID of the inserted waypoint
|
||||||
*/
|
*/
|
||||||
long insertWaypoint(in WaypointCreationRequest request);
|
long insertWaypoint(WaypointCreationRequest request);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Inserts a track point in the current recording track.
|
* Inserts a track point in the current recording track.
|
||||||
@@ -91,7 +93,7 @@ interface ITrackRecordingService {
|
|||||||
*
|
*
|
||||||
* @param location the track point to be inserted
|
* @param location the track point to be inserted
|
||||||
*/
|
*/
|
||||||
void insertTrackPoint(in Location location);
|
void insertTrackPoint(Location location);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the current sensor data. Returns null if there is no data.
|
* Gets the current sensor data. Returns null if there is no data.
|
||||||
+2
-33
@@ -39,7 +39,6 @@ import android.os.PowerManager.WakeLock;
|
|||||||
import android.os.Process;
|
import android.os.Process;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
import androidx.annotation.VisibleForTesting;
|
import androidx.annotation.VisibleForTesting;
|
||||||
import androidx.core.app.NotificationCompat;
|
import androidx.core.app.NotificationCompat;
|
||||||
import androidx.core.app.TaskStackBuilder;
|
import androidx.core.app.TaskStackBuilder;
|
||||||
@@ -305,7 +304,7 @@ public class TrackRecordingService extends Service {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IBinder onBind(Intent intent) {
|
public IBinder onBind(Intent intent) {
|
||||||
return binder;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -1060,38 +1059,13 @@ public class TrackRecordingService extends Service {
|
|||||||
* each service instance. For more details, see the following bug:
|
* each service instance. For more details, see the following bug:
|
||||||
* http://code.google.com/p/android/issues/detail?id=6426.
|
* http://code.google.com/p/android/issues/detail?id=6426.
|
||||||
*/
|
*/
|
||||||
private static class ServiceBinder extends ITrackRecordingService.Stub {
|
private static class ServiceBinder implements ITrackRecordingService {
|
||||||
private TrackRecordingService trackRecordingService;
|
private TrackRecordingService trackRecordingService;
|
||||||
private DeathRecipient deathRecipient;
|
|
||||||
|
|
||||||
public ServiceBinder(TrackRecordingService trackRecordingService) {
|
public ServiceBinder(TrackRecordingService trackRecordingService) {
|
||||||
this.trackRecordingService = trackRecordingService;
|
this.trackRecordingService = trackRecordingService;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isBinderAlive() {
|
|
||||||
return trackRecordingService != null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean pingBinder() {
|
|
||||||
return isBinderAlive();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void linkToDeath(@NonNull DeathRecipient recipient, int flags) {
|
|
||||||
deathRecipient = recipient;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean unlinkToDeath(@NonNull DeathRecipient recipient, int flags) {
|
|
||||||
if (!isBinderAlive()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
deathRecipient = null;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void startGps() {
|
public void startGps() {
|
||||||
if (!canAccess()) {
|
if (!canAccess()) {
|
||||||
@@ -1250,11 +1224,6 @@ public class TrackRecordingService extends Service {
|
|||||||
*/
|
*/
|
||||||
private void detachFromService() {
|
private void detachFromService() {
|
||||||
trackRecordingService = null;
|
trackRecordingService = null;
|
||||||
attachInterface(null, null);
|
|
||||||
|
|
||||||
if (deathRecipient != null) {
|
|
||||||
deathRecipient.binderDied();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -56,7 +56,7 @@ public class TrackRecordingServiceConnection {
|
|||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
Log.e(TAG, "Failed to bind a death recipient.", e);
|
Log.e(TAG, "Failed to bind a death recipient.", e);
|
||||||
}
|
}
|
||||||
setTrackRecordingService(ITrackRecordingService.Stub.asInterface(service));
|
setTrackRecordingService((ITrackRecordingService)service);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -119,7 +119,7 @@ public class TrackRecordingServiceConnection {
|
|||||||
* Gets the track recording service if bound. Returns null otherwise
|
* Gets the track recording service if bound. Returns null otherwise
|
||||||
*/
|
*/
|
||||||
public ITrackRecordingService getServiceIfBound() {
|
public ITrackRecordingService getServiceIfBound() {
|
||||||
if (trackRecordingService != null && !trackRecordingService.asBinder().isBinderAlive()) {
|
if (trackRecordingService != null) {
|
||||||
setTrackRecordingService(null);
|
setTrackRecordingService(null);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
-10
@@ -71,14 +71,10 @@ public class TrackRecordingServiceConnectionUtils {
|
|||||||
* @param trackRecordingServiceConnection the track recording service
|
* @param trackRecordingServiceConnection the track recording service
|
||||||
*/
|
*/
|
||||||
public static void resumeTrack(TrackRecordingServiceConnection trackRecordingServiceConnection) {
|
public static void resumeTrack(TrackRecordingServiceConnection trackRecordingServiceConnection) {
|
||||||
try {
|
|
||||||
ITrackRecordingService service = trackRecordingServiceConnection.getServiceIfBound();
|
ITrackRecordingService service = trackRecordingServiceConnection.getServiceIfBound();
|
||||||
if (service != null) {
|
if (service != null) {
|
||||||
service.resumeCurrentTrack();
|
service.resumeCurrentTrack();
|
||||||
}
|
}
|
||||||
} catch (RemoteException e) {
|
|
||||||
Log.e(TAG, "Unable to resume track.", e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -88,14 +84,10 @@ public class TrackRecordingServiceConnectionUtils {
|
|||||||
* connection
|
* connection
|
||||||
*/
|
*/
|
||||||
public static void pauseTrack(TrackRecordingServiceConnection trackRecordingServiceConnection) {
|
public static void pauseTrack(TrackRecordingServiceConnection trackRecordingServiceConnection) {
|
||||||
try {
|
|
||||||
ITrackRecordingService service = trackRecordingServiceConnection.getServiceIfBound();
|
ITrackRecordingService service = trackRecordingServiceConnection.getServiceIfBound();
|
||||||
if (service != null) {
|
if (service != null) {
|
||||||
service.pauseCurrentTrack();
|
service.pauseCurrentTrack();
|
||||||
}
|
}
|
||||||
} catch (RemoteException e) {
|
|
||||||
Log.e(TAG, "Unable to resume track.", e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -181,8 +173,6 @@ public class TrackRecordingServiceConnectionUtils {
|
|||||||
Toast.makeText(context, R.string.marker_add_success, Toast.LENGTH_SHORT).show();
|
Toast.makeText(context, R.string.marker_add_success, Toast.LENGTH_SHORT).show();
|
||||||
return markerId;
|
return markerId;
|
||||||
}
|
}
|
||||||
} catch (RemoteException e) {
|
|
||||||
Log.e(TAG, "Unable to add marker", e);
|
|
||||||
} catch (IllegalStateException e) {
|
} catch (IllegalStateException e) {
|
||||||
Log.e(TAG, "Unable to add marker.", e);
|
Log.e(TAG, "Unable to add marker.", e);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user