forked from upstream-mirrors/OpenTracks
Enabling strict mode in non-release builds
This commit is contained in:
@@ -41,6 +41,7 @@ import com.google.android.apps.mytracks.services.StatusAnnouncerFactory;
|
|||||||
import com.google.android.apps.mytracks.services.TrackRecordingService;
|
import com.google.android.apps.mytracks.services.TrackRecordingService;
|
||||||
import com.google.android.apps.mytracks.util.ApiFeatures;
|
import com.google.android.apps.mytracks.util.ApiFeatures;
|
||||||
import com.google.android.apps.mytracks.util.FileUtils;
|
import com.google.android.apps.mytracks.util.FileUtils;
|
||||||
|
import com.google.android.apps.mytracks.util.MyTracksUtils;
|
||||||
import com.google.android.maps.mytracks.R;
|
import com.google.android.maps.mytracks.R;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
@@ -252,6 +253,11 @@ public class MyTracks extends TabActivity implements OnTouchListener,
|
|||||||
Log.d(MyTracksConstants.TAG, "MyTracks.onCreate");
|
Log.d(MyTracksConstants.TAG, "MyTracks.onCreate");
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
instance = this;
|
instance = this;
|
||||||
|
ApiFeatures apiFeatures = ApiFeatures.getInstance();
|
||||||
|
if (!MyTracksUtils.isRelease(this)) {
|
||||||
|
apiFeatures.getApiPlatformAdapter().enableStrictMode();
|
||||||
|
}
|
||||||
|
|
||||||
providerUtils = MyTracksProviderUtils.Factory.get(this);
|
providerUtils = MyTracksProviderUtils.Factory.get(this);
|
||||||
menuManager = new MenuManager(this);
|
menuManager = new MenuManager(this);
|
||||||
sharedPreferences = getSharedPreferences(MyTracksSettings.SETTINGS_NAME, 0);
|
sharedPreferences = getSharedPreferences(MyTracksSettings.SETTINGS_NAME, 0);
|
||||||
@@ -259,7 +265,7 @@ public class MyTracks extends TabActivity implements OnTouchListener,
|
|||||||
|
|
||||||
// The volume we want to control is the Text-To-Speech volume
|
// The volume we want to control is the Text-To-Speech volume
|
||||||
int volumeStream =
|
int volumeStream =
|
||||||
new StatusAnnouncerFactory(ApiFeatures.getInstance()).getVolumeStream();
|
new StatusAnnouncerFactory(apiFeatures).getVolumeStream();
|
||||||
setVolumeControlStream(volumeStream);
|
setVolumeControlStream(volumeStream);
|
||||||
|
|
||||||
// We don't need a window title bar:
|
// We don't need a window title bar:
|
||||||
|
|||||||
@@ -21,7 +21,12 @@ import com.google.android.apps.mytracks.stats.TripStatistics;
|
|||||||
|
|
||||||
import com.google.android.maps.GeoPoint;
|
import com.google.android.maps.GeoPoint;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.pm.PackageManager;
|
||||||
|
import android.content.pm.PackageManager.NameNotFoundException;
|
||||||
|
import android.content.pm.Signature;
|
||||||
import android.location.Location;
|
import android.location.Location;
|
||||||
|
import android.os.StrictMode;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -34,6 +39,7 @@ import java.util.Stack;
|
|||||||
* @author Leif Hendrik Wilden
|
* @author Leif Hendrik Wilden
|
||||||
*/
|
*/
|
||||||
public class MyTracksUtils {
|
public class MyTracksUtils {
|
||||||
|
private static final int RELEASE_SIGNATURE_HASHCODE = -1855564782;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Computes the distance on the two sphere between the point c0 and the line
|
* Computes the distance on the two sphere between the point c0 and the line
|
||||||
@@ -246,6 +252,25 @@ public class MyTracksUtils {
|
|||||||
(int) (location.getLongitude() * 1E6));
|
(int) (location.getLongitude() * 1E6));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns whether or not this is a release build.
|
||||||
|
*/
|
||||||
|
public static boolean isRelease(Context context) {
|
||||||
|
try {
|
||||||
|
Signature [] sigs = context.getPackageManager().getPackageInfo(
|
||||||
|
context.getPackageName(), PackageManager.GET_SIGNATURES).signatures;
|
||||||
|
for (Signature sig : sigs) {
|
||||||
|
if (sig.hashCode() == RELEASE_SIGNATURE_HASHCODE) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (NameNotFoundException e) {
|
||||||
|
Log.e(MyTracksConstants.TAG, "Unable to get signatures", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is a utility class w/ only static memebers.
|
* This is a utility class w/ only static memebers.
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user