forked from upstream-mirrors/OpenTracks
Removed external access check to now internal service.
This commit is contained in:
+1
-62
@@ -1044,8 +1044,7 @@ public class TrackRecordingService extends Service {
|
||||
Intent intent = new Intent().setAction(getString(actionId))
|
||||
.putExtra(getString(R.string.track_id_broadcast_extra), trackId);
|
||||
sendBroadcast(intent, getString(R.string.permission_notification_value));
|
||||
if (PreferencesUtils.getBoolean(
|
||||
this, R.string.allow_access_key, PreferencesUtils.ALLOW_ACCESS_DEFAULT)) {
|
||||
if (PreferencesUtils.getBoolean(this, R.string.allow_access_key, PreferencesUtils.ALLOW_ACCESS_DEFAULT)) {
|
||||
sendBroadcast(intent, getString(R.string.broadcast_notifications_permission));
|
||||
}
|
||||
}
|
||||
@@ -1068,18 +1067,12 @@ public class TrackRecordingService extends Service {
|
||||
|
||||
@Override
|
||||
public void startGps() {
|
||||
if (!canAccess()) {
|
||||
return;
|
||||
}
|
||||
if (!trackRecordingService.isRecording()) {
|
||||
trackRecordingService.startGps();
|
||||
}
|
||||
}
|
||||
|
||||
public void stopGps() {
|
||||
if (!canAccess()) {
|
||||
return;
|
||||
}
|
||||
if (!trackRecordingService.isRecording()) {
|
||||
trackRecordingService.stopGps(true);
|
||||
}
|
||||
@@ -1087,65 +1080,41 @@ public class TrackRecordingService extends Service {
|
||||
|
||||
@Override
|
||||
public long startNewTrack() {
|
||||
if (!canAccess()) {
|
||||
return -1L;
|
||||
}
|
||||
return trackRecordingService.startNewTrack();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void pauseCurrentTrack() {
|
||||
if (!canAccess()) {
|
||||
return;
|
||||
}
|
||||
trackRecordingService.pauseCurrentTrack();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resumeCurrentTrack() {
|
||||
if (!canAccess()) {
|
||||
return;
|
||||
}
|
||||
trackRecordingService.resumeCurrentTrack();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endCurrentTrack() {
|
||||
if (!canAccess()) {
|
||||
return;
|
||||
}
|
||||
trackRecordingService.endCurrentTrack();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRecording() {
|
||||
if (!canAccess()) {
|
||||
return false;
|
||||
}
|
||||
return trackRecordingService.isRecording();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPaused() {
|
||||
if (!canAccess()) {
|
||||
return false;
|
||||
}
|
||||
return trackRecordingService.isPaused();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getRecordingTrackId() {
|
||||
if (!canAccess()) {
|
||||
return -1L;
|
||||
}
|
||||
return trackRecordingService.recordingTrackId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getTotalTime() {
|
||||
if (!canAccess()) {
|
||||
return 0;
|
||||
}
|
||||
TripStatisticsUpdater updater = trackRecordingService.trackTripStatisticsUpdater;
|
||||
if (updater == null) {
|
||||
return 0;
|
||||
@@ -1158,25 +1127,16 @@ public class TrackRecordingService extends Service {
|
||||
|
||||
@Override
|
||||
public long insertWaypoint(WaypointCreationRequest waypointCreationRequest) {
|
||||
if (!canAccess()) {
|
||||
return -1L;
|
||||
}
|
||||
return trackRecordingService.insertWaypoint(waypointCreationRequest);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void insertTrackPoint(Location location) {
|
||||
if (!canAccess()) {
|
||||
return;
|
||||
}
|
||||
//TODO trackRecordingService.locationListener.onLocationChanged(location);
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] getSensorData() {
|
||||
if (!canAccess()) {
|
||||
return null;
|
||||
}
|
||||
if (trackRecordingService.sensorManager == null) {
|
||||
Log.d(TAG, "sensorManager is null.");
|
||||
return null;
|
||||
@@ -1190,9 +1150,6 @@ public class TrackRecordingService extends Service {
|
||||
|
||||
@Override
|
||||
public int getSensorState() {
|
||||
if (!canAccess()) {
|
||||
return Sensor.SensorState.NONE.getNumber();
|
||||
}
|
||||
if (trackRecordingService.sensorManager == null) {
|
||||
Log.d(TAG, "sensorManager is null.");
|
||||
return Sensor.SensorState.NONE.getNumber();
|
||||
@@ -1200,24 +1157,6 @@ public class TrackRecordingService extends Service {
|
||||
return trackRecordingService.sensorManager.getSensorState().getNumber();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the RPC caller is from the same application or if the
|
||||
* "Allow access" setting indicates that another app can invoke this
|
||||
* service's RPCs.
|
||||
*/
|
||||
private boolean canAccess() {
|
||||
// As a precondition for access, must check if the service is available.
|
||||
if (trackRecordingService == null) {
|
||||
throw new IllegalStateException("The track recording service has been detached!");
|
||||
}
|
||||
if (Process.myPid() == Binder.getCallingPid()) {
|
||||
return true;
|
||||
} else {
|
||||
return PreferencesUtils.getBoolean(trackRecordingService, R.string.allow_access_key,
|
||||
PreferencesUtils.ALLOW_ACCESS_DEFAULT);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Detaches from the track recording service. Clears the reference to the
|
||||
* outer class to minimize the leak.
|
||||
|
||||
@@ -43,14 +43,14 @@ import java.util.List;
|
||||
*/
|
||||
public class TrackIconUtils {
|
||||
|
||||
public static final String AIRPLANE = "AIRPLANE";
|
||||
public static final String BIKE = "BIKE";
|
||||
public static final String BOAT = "BOAT";
|
||||
public static final String DRIVE = "DRIVE";
|
||||
public static final String RUN = "RUN";
|
||||
public static final String SKI = "SKI";
|
||||
public static final String SNOW_BOARDING = "SNOW_BOARDING";
|
||||
public static final String WALK = "WALK";
|
||||
private static final String AIRPLANE = "AIRPLANE";
|
||||
private static final String BIKE = "BIKE";
|
||||
private static final String BOAT = "BOAT";
|
||||
private static final String DRIVE = "DRIVE";
|
||||
private static final String RUN = "RUN";
|
||||
private static final String SKI = "SKI";
|
||||
private static final String SNOW_BOARDING = "SNOW_BOARDING";
|
||||
private static final String WALK = "WALK";
|
||||
|
||||
private static final int[] AIRPLANE_LIST = new int[] { R.string.activity_type_airplane,
|
||||
R.string.activity_type_commercial_airplane, R.string.activity_type_rc_airplane };
|
||||
@@ -79,25 +79,18 @@ public class TrackIconUtils {
|
||||
MAP = new LinkedHashMap<>();
|
||||
|
||||
static {
|
||||
MAP.put(
|
||||
RUN, new Pair<>(R.string.activity_type_running, R.drawable.ic_track_run));
|
||||
MAP.put(
|
||||
WALK, new Pair<>(R.string.activity_type_walking, R.drawable.ic_track_walk));
|
||||
MAP.put(
|
||||
BIKE, new Pair<>(R.string.activity_type_biking, R.drawable.ic_track_bike));
|
||||
MAP.put(DRIVE,
|
||||
new Pair<>(R.string.activity_type_driving, R.drawable.ic_track_drive));
|
||||
MAP.put(
|
||||
SKI, new Pair<>(R.string.activity_type_skiing, R.drawable.ic_track_ski));
|
||||
MAP.put(SNOW_BOARDING, new Pair<>(
|
||||
R.string.activity_type_snow_boarding, R.drawable.ic_track_snow_boarding));
|
||||
MAP.put(AIRPLANE,
|
||||
new Pair<>(R.string.activity_type_airplane, R.drawable.ic_track_airplane));
|
||||
MAP.put(
|
||||
BOAT, new Pair<>(R.string.activity_type_boat, R.drawable.ic_track_boat));
|
||||
MAP.put(RUN, new Pair<>(R.string.activity_type_running, R.drawable.ic_track_run));
|
||||
MAP.put(WALK, new Pair<>(R.string.activity_type_walking, R.drawable.ic_track_walk));
|
||||
MAP.put(BIKE, new Pair<>(R.string.activity_type_biking, R.drawable.ic_track_bike));
|
||||
MAP.put(DRIVE, new Pair<>(R.string.activity_type_driving, R.drawable.ic_track_drive));
|
||||
MAP.put(SKI, new Pair<>(R.string.activity_type_skiing, R.drawable.ic_track_ski));
|
||||
MAP.put(SNOW_BOARDING, new Pair<>(R.string.activity_type_snow_boarding, R.drawable.ic_track_snow_boarding));
|
||||
MAP.put(AIRPLANE,new Pair<>(R.string.activity_type_airplane, R.drawable.ic_track_airplane));
|
||||
MAP.put(BOAT, new Pair<>(R.string.activity_type_boat, R.drawable.ic_track_boat));
|
||||
}
|
||||
|
||||
private static final float[] REVERT_COLOR_MATRIX = { -1.0f, 0, 0, 0, 255, // red
|
||||
private static final float[] REVERT_COLOR_MATRIX = {
|
||||
-1.0f, 0, 0, 0, 255, // red
|
||||
0, -1.0f, 0, 0, 255, // green
|
||||
0, 0, -1.0f, 0, 255, // blue
|
||||
0, 0, 0, 1.0f, 0 // alpha
|
||||
@@ -191,8 +184,7 @@ public class TrackIconUtils {
|
||||
@Override
|
||||
public View getView(int position, View convertView, @NonNull android.view.ViewGroup parent) {
|
||||
ImageView imageView = convertView != null ? (ImageView) convertView : new ImageView(getContext());
|
||||
Bitmap source = BitmapFactory.decodeResource(
|
||||
context.getResources(), TrackIconUtils.getIconDrawable(getItem(position).toString()));
|
||||
Bitmap source = BitmapFactory.decodeResource(context.getResources(), TrackIconUtils.getIconDrawable(getItem(position).toString()));
|
||||
imageView.setImageBitmap(source);
|
||||
imageView.setPadding(4, 4, -4, -4);
|
||||
return imageView;
|
||||
|
||||
Reference in New Issue
Block a user