merge heads

This commit is contained in:
Jimmy Shih
2012-03-23 10:46:55 -07:00
4 changed files with 31 additions and 51 deletions
@@ -32,8 +32,8 @@ import com.google.android.apps.mytracks.services.TrackRecordingServiceConnection
import com.google.android.apps.mytracks.util.AnalyticsUtils; import com.google.android.apps.mytracks.util.AnalyticsUtils;
import com.google.android.apps.mytracks.util.ApiAdapterFactory; import com.google.android.apps.mytracks.util.ApiAdapterFactory;
import com.google.android.apps.mytracks.util.EulaUtils; import com.google.android.apps.mytracks.util.EulaUtils;
import com.google.android.apps.mytracks.util.SystemUtils;
import com.google.android.apps.mytracks.util.UriUtils; import com.google.android.apps.mytracks.util.UriUtils;
import com.google.android.maps.mytracks.BuildConfig;
import com.google.android.maps.mytracks.R; import com.google.android.maps.mytracks.R;
import android.app.Activity; import android.app.Activity;
@@ -73,7 +73,7 @@ public class MyTracks extends TabActivity implements OnTouchListener {
private static final int DIALOG_CHECK_UNITS_ID = 1; private static final int DIALOG_CHECK_UNITS_ID = 1;
private static final String CHECK_UNITS_PREFERENCE_FILE = "checkunits"; private static final String CHECK_UNITS_PREFERENCE_FILE = "checkunits";
private static final String CHECK_UNITS_PREFERENCE_KEY = "checkunits.checked"; private static final String CHECK_UNITS_PREFERENCE_KEY = "checkunits.checked";
private TrackDataHub dataHub; private TrackDataHub dataHub;
/** /**
@@ -140,7 +140,7 @@ public class MyTracks extends TabActivity implements OnTouchListener {
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
Log.d(TAG, "MyTracks.onCreate"); Log.d(TAG, "MyTracks.onCreate");
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
if (!SystemUtils.isRelease(this)) { if (BuildConfig.DEBUG) {
ApiAdapterFactory.getApiAdapter().enableStrictMode(); ApiAdapterFactory.getApiAdapter().enableStrictMode();
} }
@@ -153,7 +153,7 @@ public class MyTracks extends TabActivity implements OnTouchListener {
serviceConnection = new TrackRecordingServiceConnection(this, serviceBindCallback); serviceConnection = new TrackRecordingServiceConnection(this, serviceBindCallback);
setVolumeControlStream(TextToSpeech.Engine.DEFAULT_STREAM); setVolumeControlStream(TextToSpeech.Engine.DEFAULT_STREAM);
// Show the action bar (or nothing at all). // Show the action bar (or nothing at all).
ApiAdapterFactory.getApiAdapter().showActionBar(this); ApiAdapterFactory.getApiAdapter().showActionBar(this);
@@ -18,6 +18,7 @@ package com.google.android.apps.mytracks.services;
import static com.google.android.apps.mytracks.Constants.TAG; import static com.google.android.apps.mytracks.Constants.TAG;
import com.google.android.apps.mytracks.util.SystemUtils; import com.google.android.apps.mytracks.util.SystemUtils;
import com.google.android.maps.mytracks.BuildConfig;
import android.content.ComponentName; import android.content.ComponentName;
import android.content.Context; import android.content.Context;
@@ -157,7 +158,7 @@ public class TrackRecordingServiceConnection {
Log.i(TAG, "Binding to the service"); Log.i(TAG, "Binding to the service");
Intent intent = new Intent(context, TrackRecordingService.class); Intent intent = new Intent(context, TrackRecordingService.class);
int flags = SystemUtils.isRelease(context) ? 0 : Context.BIND_DEBUG_UNBIND; int flags = BuildConfig.DEBUG ? Context.BIND_DEBUG_UNBIND : 0;
context.bindService(intent, serviceConnection, flags); context.bindService(intent, serviceConnection, flags);
} }
@@ -23,7 +23,7 @@ import com.dsi.ant.exception.AntInterfaceException;
import com.google.android.apps.mytracks.Constants; import com.google.android.apps.mytracks.Constants;
import com.google.android.apps.mytracks.content.Sensor; import com.google.android.apps.mytracks.content.Sensor;
import com.google.android.apps.mytracks.util.ApiAdapterFactory; import com.google.android.apps.mytracks.util.ApiAdapterFactory;
import com.google.android.apps.mytracks.util.SystemUtils; import com.google.android.maps.mytracks.BuildConfig;
import com.google.android.maps.mytracks.R; import com.google.android.maps.mytracks.R;
import android.content.Context; import android.content.Context;
@@ -32,7 +32,7 @@ import android.util.Log;
/** /**
* A sensor manager to the PC7 SRM ANT+ bridge. * A sensor manager to the PC7 SRM ANT+ bridge.
* *
* @author Sandor Dornbush * @author Sandor Dornbush
* @author Umran Abdulla * @author Umran Abdulla
*/ */
@@ -54,15 +54,15 @@ public class AntSrmBridgeSensorManager extends AntSensorManager {
private static final int INDEX_MESSAGE_SPEED = 5; private static final int INDEX_MESSAGE_SPEED = 5;
private static final int INDEX_MESSAGE_CADENCE = 7; private static final int INDEX_MESSAGE_CADENCE = 7;
private static final int INDEX_MESSAGE_BPM = 8; private static final int INDEX_MESSAGE_BPM = 8;
private static final int MSG_INITIAL = 5; private static final int MSG_INITIAL = 5;
private static final int MSG_DATA = 6; private static final int MSG_DATA = 6;
private short deviceNumber; private short deviceNumber;
public AntSrmBridgeSensorManager(Context context) { public AntSrmBridgeSensorManager(Context context) {
super(context); super(context);
Log.i(TAG, "new ANT SRM Bridge Sensor Manager created"); Log.i(TAG, "new ANT SRM Bridge Sensor Manager created");
deviceNumber = WILDCARD; deviceNumber = WILDCARD;
@@ -77,15 +77,15 @@ public class AntSrmBridgeSensorManager extends AntSensorManager {
} }
Log.i(TAG, "Will pair with device: " + deviceNumber); Log.i(TAG, "Will pair with device: " + deviceNumber);
} }
@Override @Override
protected boolean handleMessage(byte messageId, byte[] messageData) { protected boolean handleMessage(byte messageId, byte[] messageData) {
if (super.handleMessage(messageId, messageData)) { if (super.handleMessage(messageId, messageData)) {
return true; return true;
} }
if (!SystemUtils.isRelease(context)) { if (BuildConfig.DEBUG) {
Log.d(TAG, "Received ANT msg: " + AntUtils.antMessageToString(messageId) + "(" + messageId + ")"); Log.d(TAG, "Received ANT msg: " + AntUtils.antMessageToString(messageId) + "(" + messageId + ")");
} }
@@ -100,7 +100,7 @@ public class AntSrmBridgeSensorManager extends AntSensorManager {
return true; return true;
} }
/** /**
* Decode an ant device message. * Decode an ant device message.
* @param messageData The byte array received from the device. * @param messageData The byte array received from the device.
@@ -132,10 +132,10 @@ public class AntSrmBridgeSensorManager extends AntSensorManager {
} }
setSensorState(Sensor.SensorState.CONNECTED); setSensorState(Sensor.SensorState.CONNECTED);
int messageType = antMessage[INDEX_MESSAGE_TYPE] & 0xFF; int messageType = antMessage[INDEX_MESSAGE_TYPE] & 0xFF;
Log.d(TAG, "Received message-type=" + messageType); Log.d(TAG, "Received message-type=" + messageType);
switch (messageType) { switch (messageType) {
case MSG_INITIAL: case MSG_INITIAL:
break; break;
@@ -149,7 +149,7 @@ public class AntSrmBridgeSensorManager extends AntSensorManager {
{ {
int messageId = msg[INDEX_MESSAGE_ID] & 0xFF; int messageId = msg[INDEX_MESSAGE_ID] & 0xFF;
Log.d(TAG, "Received message-id=" + messageId); Log.d(TAG, "Received message-id=" + messageId);
int powerVal = (((msg[INDEX_MESSAGE_POWER] & 0xFF) << 8) | int powerVal = (((msg[INDEX_MESSAGE_POWER] & 0xFF) << 8) |
(msg[INDEX_MESSAGE_POWER+1] & 0xFF)); (msg[INDEX_MESSAGE_POWER+1] & 0xFF));
@SuppressWarnings("unused") @SuppressWarnings("unused")
@@ -158,12 +158,12 @@ public class AntSrmBridgeSensorManager extends AntSensorManager {
int cadenceVal = (msg[INDEX_MESSAGE_CADENCE] & 0xFF); int cadenceVal = (msg[INDEX_MESSAGE_CADENCE] & 0xFF);
int bpmVal = (msg[INDEX_MESSAGE_BPM] & 0xFF); int bpmVal = (msg[INDEX_MESSAGE_BPM] & 0xFF);
long time = System.currentTimeMillis(); long time = System.currentTimeMillis();
Sensor.SensorData.Builder power = Sensor.SensorData.Builder power =
Sensor.SensorData.newBuilder() Sensor.SensorData.newBuilder()
.setValue(powerVal) .setValue(powerVal)
.setState(Sensor.SensorState.SENDING); .setState(Sensor.SensorState.SENDING);
/* /*
* Although speed is available from the SRM Bridge, MyTracks doesn't use the value, and * Although speed is available from the SRM Bridge, MyTracks doesn't use the value, and
* computes speed from the GPS location data. * computes speed from the GPS location data.
@@ -171,12 +171,12 @@ public class AntSrmBridgeSensorManager extends AntSensorManager {
// Sensor.SensorData.Builder speed = Sensor.SensorData.newBuilder().setValue(speedVal).setState( // Sensor.SensorData.Builder speed = Sensor.SensorData.newBuilder().setValue(speedVal).setState(
// Sensor.SensorState.SENDING); // Sensor.SensorState.SENDING);
Sensor.SensorData.Builder cadence = Sensor.SensorData.Builder cadence =
Sensor.SensorData.newBuilder() Sensor.SensorData.newBuilder()
.setValue(cadenceVal) .setValue(cadenceVal)
.setState(Sensor.SensorState.SENDING); .setState(Sensor.SensorState.SENDING);
Sensor.SensorData.Builder bpm = Sensor.SensorData.Builder bpm =
Sensor.SensorData.newBuilder() Sensor.SensorData.newBuilder()
.setValue(bpmVal) .setValue(bpmVal)
.setState(Sensor.SensorState.SENDING); .setState(Sensor.SensorState.SENDING);
@@ -189,7 +189,7 @@ public class AntSrmBridgeSensorManager extends AntSensorManager {
.setHeartRate(bpm) .setHeartRate(bpm)
.build(); .build();
} }
void handleChannelId(byte[] rawMessage) { void handleChannelId(byte[] rawMessage) {
AntChannelIdMessage message = new AntChannelIdMessage(rawMessage); AntChannelIdMessage message = new AntChannelIdMessage(rawMessage);
deviceNumber = message.getDeviceNumber(); deviceNumber = message.getDeviceNumber();
@@ -203,12 +203,12 @@ public class AntSrmBridgeSensorManager extends AntSensorManager {
} }
private void handleMessageResponse(byte[] rawMessage) { private void handleMessageResponse(byte[] rawMessage) {
AntChannelResponseMessage message = AntChannelResponseMessage message =
new AntChannelResponseMessage(rawMessage); new AntChannelResponseMessage(rawMessage);
if (!SystemUtils.isRelease(context)) { if (BuildConfig.DEBUG) {
Log.d(TAG, "Received ANT Response: " + AntUtils.antMessageToString(message.getMessageId()) + Log.d(TAG, "Received ANT Response: " + AntUtils.antMessageToString(message.getMessageId()) +
"(" + message.getMessageId() + ")" + "(" + message.getMessageId() + ")" +
", Code: " + AntUtils.antEventToStr(message.getMessageCode()) + ", Code: " + AntUtils.antEventToStr(message.getMessageCode()) +
"(" + message.getMessageCode() + ")"); "(" + message.getMessageCode() + ")");
} }
switch (message.getMessageId()) { switch (message.getMessageId()) {
@@ -1,12 +1,12 @@
/* /*
* Copyright 2011 Google Inc. * Copyright 2011 Google Inc.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); you may not * Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of * use this file except in compliance with the License. You may obtain a copy of
* the License at * the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
@@ -22,7 +22,6 @@ import android.content.Context;
import android.content.pm.PackageInfo; import android.content.pm.PackageInfo;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException; import android.content.pm.PackageManager.NameNotFoundException;
import android.content.pm.Signature;
import android.os.PowerManager; import android.os.PowerManager;
import android.os.PowerManager.WakeLock; import android.os.PowerManager.WakeLock;
import android.util.Log; import android.util.Log;
@@ -34,26 +33,6 @@ import android.util.Log;
*/ */
public class SystemUtils { public class SystemUtils {
private static final int RELEASE_SIGNATURE_HASHCODE = -1855564782;
/**
* 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(Constants.TAG, "Unable to get signatures", e);
}
return false;
}
/** /**
* Get the My Tracks version from the manifest. * Get the My Tracks version from the manifest.
* *