forked from upstream-mirrors/OpenTracks
Introduce an interface to decouple platform specific API from the classes that require it. Also:
1) Put the service into foreground to prevent from being killed by the system 2) Fix a bug the prevented MyTracks from running on pre-Eclair devices
This commit is contained in:
+19
@@ -23,6 +23,7 @@ import com.google.android.apps.mytracks.content.MyTracksProviderUtils;
|
||||
import com.google.android.apps.mytracks.content.Track;
|
||||
import com.google.android.apps.mytracks.content.Waypoint;
|
||||
import com.google.android.apps.mytracks.stats.TripStatistics;
|
||||
import com.google.android.apps.mytracks.util.ApiFeatures;
|
||||
import com.google.android.maps.mytracks.R;
|
||||
|
||||
import android.content.ContentResolver;
|
||||
@@ -57,6 +58,9 @@ public class TrackRecordingServiceTest
|
||||
super(TrackRecordingService.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* A context wrapper with the user provided {@link ContentResolver}.
|
||||
*/
|
||||
private static class MockContext extends ContextWrapper {
|
||||
private final ContentResolver contentResolver;
|
||||
|
||||
@@ -70,11 +74,26 @@ public class TrackRecordingServiceTest
|
||||
return contentResolver;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A mock class that forces API level < 5 to make sure we can workaround a bug
|
||||
* in ServiceTestCase (throwing a NPE).
|
||||
* See http://code.google.com/p/android/issues/detail?id=12122 for more
|
||||
* details.
|
||||
*/
|
||||
private static class MockApiFeatures extends ApiFeatures {
|
||||
@Override
|
||||
protected int getApiLevel() {
|
||||
return 4;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
|
||||
ApiFeatures.injectInstance(new MockApiFeatures());
|
||||
|
||||
MockContentResolver mockContentResolver = new MockContentResolver();
|
||||
RenamingDelegatingContext targetContext = new RenamingDelegatingContext(
|
||||
getContext(), getContext(), "test.");
|
||||
|
||||
@@ -75,4 +75,8 @@ public class ApiFeaturesTest extends TestCase {
|
||||
features.setApiLevel(8);
|
||||
assertTrue(features.hasModernSignalStrength());
|
||||
}
|
||||
|
||||
public void testGetApiPlatformAdapter() {
|
||||
assertNotNull(features.getApiPlatformAdapter());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user