summaryrefslogtreecommitdiffstats
path: root/location
diff options
context:
space:
mode:
authordestradaa <destradaa@google.com>2015-02-09 14:24:39 -0800
committerdestradaa <destradaa@google.com>2015-02-11 13:16:28 -0800
commitc91ac688295e3d64ad1dd7539a713f5de60fea05 (patch)
treefe3c54f40fd2b8798b7303a6659b86f718375af9 /location
parent5b179afb19a00e03f1bed0f7eb6af9b0462f2f02 (diff)
downloadframeworks_base-c91ac688295e3d64ad1dd7539a713f5de60fea05.zip
frameworks_base-c91ac688295e3d64ad1dd7539a713f5de60fea05.tar.gz
frameworks_base-c91ac688295e3d64ad1dd7539a713f5de60fea05.tar.bz2
Update handling of enum/flag fields in GPS data structures.
It fixes cases when flags where filtered in the platform, because they were checked as enums. It also simplies handling of future values in enums/flags. Change-Id: I83a0f82cc4562749081bf7e279ea52e2d5ba1f7c
Diffstat (limited to 'location')
-rw-r--r--location/java/android/location/GpsClock.java16
-rw-r--r--location/java/android/location/GpsMeasurement.java136
-rw-r--r--location/java/android/location/GpsNavigationMessage.java19
3 files changed, 65 insertions, 106 deletions
diff --git a/location/java/android/location/GpsClock.java b/location/java/android/location/GpsClock.java
index 22ac1a9..4135a1c 100644
--- a/location/java/android/location/GpsClock.java
+++ b/location/java/android/location/GpsClock.java
@@ -19,7 +19,6 @@ package android.location;
import android.annotation.SystemApi;
import android.os.Parcel;
import android.os.Parcelable;
-import android.util.Log;
/**
* A class containing a GPS clock timestamp.
@@ -29,7 +28,6 @@ import android.util.Log;
*/
@SystemApi
public class GpsClock implements Parcelable {
- private static final String TAG = "GpsClock";
// The following enumerations must be in sync with the values declared in gps.h
@@ -109,17 +107,7 @@ public class GpsClock implements Parcelable {
* Sets the type of time reported.
*/
public void setType(byte value) {
- switch (value) {
- case TYPE_UNKNOWN:
- case TYPE_GPS_TIME:
- case TYPE_LOCAL_HW_TIME:
- mType = value;
- break;
- default:
- Log.d(TAG, "Sanitizing invalid 'type': " + value);
- mType = TYPE_UNKNOWN;
- break;
- }
+ mType = value;
}
/**
@@ -135,7 +123,7 @@ public class GpsClock implements Parcelable {
case TYPE_LOCAL_HW_TIME:
return "LocalHwClock";
default:
- return "<Invalid>";
+ return "<Invalid:" + mType + ">";
}
}
diff --git a/location/java/android/location/GpsMeasurement.java b/location/java/android/location/GpsMeasurement.java
index 1c50181..05bcf79 100644
--- a/location/java/android/location/GpsMeasurement.java
+++ b/location/java/android/location/GpsMeasurement.java
@@ -19,7 +19,6 @@ package android.location;
import android.annotation.SystemApi;
import android.os.Parcel;
import android.os.Parcelable;
-import android.util.Log;
/**
* A class representing a GPS satellite measurement, containing raw and computed information.
@@ -28,8 +27,6 @@ import android.util.Log;
*/
@SystemApi
public class GpsMeasurement implements Parcelable {
- private static final String TAG = "GpsMeasurement";
-
private int mFlags;
private byte mPrn;
private double mTimeOffsetInNs;
@@ -140,6 +137,12 @@ public class GpsMeasurement implements Parcelable {
public static final short STATE_TOW_DECODED = (1<<3);
/**
+ * All the GPS receiver state flags.
+ */
+ private static final short STATE_ALL =
+ STATE_CODE_LOCK | STATE_BIT_SYNC | STATE_SUBFRAME_SYNC | STATE_TOW_DECODED;
+
+ /**
* The state of the 'Accumulated Delta Range' is invalid or unknown.
*/
public static final short ADR_STATE_UNKNOWN = 0;
@@ -159,6 +162,11 @@ public class GpsMeasurement implements Parcelable {
*/
public static final short ADR_STATE_CYCLE_SLIP = (1<<2);
+ /**
+ * All the 'Accumulated Delta Range' flags.
+ */
+ private static final short ADR_ALL = ADR_STATE_VALID | ADR_STATE_RESET | ADR_STATE_CYCLE_SLIP;
+
// End enumerations in sync with gps.h
GpsMeasurement() {
@@ -263,19 +271,7 @@ public class GpsMeasurement implements Parcelable {
* Sets the sync state.
*/
public void setState(short value) {
- switch (value) {
- case STATE_UNKNOWN:
- case STATE_BIT_SYNC:
- case STATE_CODE_LOCK:
- case STATE_SUBFRAME_SYNC:
- case STATE_TOW_DECODED:
- mState = value;
- break;
- default:
- Log.d(TAG, "Sanitizing invalid 'sync state': " + value);
- mState = STATE_UNKNOWN;
- break;
- }
+ mState = value;
}
/**
@@ -283,20 +279,30 @@ public class GpsMeasurement implements Parcelable {
* For internal and logging use only.
*/
private String getStateString() {
- switch (mState) {
- case STATE_UNKNOWN:
- return "Unknown";
- case STATE_BIT_SYNC:
- return "BitSync";
- case STATE_CODE_LOCK:
- return "CodeLock";
- case STATE_SUBFRAME_SYNC:
- return "SubframeSync";
- case STATE_TOW_DECODED:
- return "TowDecoded";
- default:
- return "<Invalid>";
+ if (mState == STATE_UNKNOWN) {
+ return "Unknown";
+ }
+ StringBuilder builder = new StringBuilder();
+ if ((mState & STATE_CODE_LOCK) == STATE_CODE_LOCK) {
+ builder.append("CodeLock|");
+ }
+ if ((mState & STATE_BIT_SYNC) == STATE_BIT_SYNC) {
+ builder.append("BitSync|");
+ }
+ if ((mState & STATE_SUBFRAME_SYNC) == STATE_SUBFRAME_SYNC) {
+ builder.append("SubframeSync|");
+ }
+ if ((mState & STATE_TOW_DECODED) == STATE_TOW_DECODED) {
+ builder.append("TowDecoded|");
}
+ int remainingStates = mState & ~STATE_ALL;
+ if (remainingStates > 0) {
+ builder.append("Other(");
+ builder.append(Integer.toBinaryString(remainingStates));
+ builder.append(")|");
+ }
+ builder.deleteCharAt(builder.length() - 1);
+ return builder.toString();
}
/**
@@ -395,18 +401,7 @@ public class GpsMeasurement implements Parcelable {
* Sets the 'Accumulated Delta Range' state.
*/
public void setAccumulatedDeltaRangeState(short value) {
- switch (value) {
- case ADR_STATE_UNKNOWN:
- case ADR_STATE_VALID:
- case ADR_STATE_RESET:
- case ADR_STATE_CYCLE_SLIP:
- mAccumulatedDeltaRangeState = value;
- break;
- default:
- Log.d(TAG, "Sanitizing invalid 'Accumulated Delta Range state': " + value);
- mAccumulatedDeltaRangeState = ADR_STATE_UNKNOWN;
- break;
- }
+ mAccumulatedDeltaRangeState = value;
}
/**
@@ -414,18 +409,27 @@ public class GpsMeasurement implements Parcelable {
* For internal and logging use only.
*/
private String getAccumulatedDeltaRangeStateString() {
- switch (mAccumulatedDeltaRangeState) {
- case ADR_STATE_UNKNOWN:
- return "Unknown";
- case ADR_STATE_VALID:
- return "Valid";
- case ADR_STATE_RESET:
- return "Reset";
- case ADR_STATE_CYCLE_SLIP:
- return "CycleSlip";
- default:
- return "<Invalid>";
+ if (mAccumulatedDeltaRangeState == ADR_STATE_UNKNOWN) {
+ return "Unknown";
+ }
+ StringBuilder builder = new StringBuilder();
+ if ((mAccumulatedDeltaRangeState & ADR_STATE_VALID) == ADR_STATE_VALID) {
+ builder.append("Valid|");
+ }
+ if ((mAccumulatedDeltaRangeState & ADR_STATE_RESET) == ADR_STATE_RESET) {
+ builder.append("Reset|");
}
+ if ((mAccumulatedDeltaRangeState & ADR_STATE_CYCLE_SLIP) == ADR_STATE_CYCLE_SLIP) {
+ builder.append("CycleSlip|");
+ }
+ int remainingStates = mAccumulatedDeltaRangeState & ~ADR_ALL;
+ if (remainingStates > 0) {
+ builder.append("Other(");
+ builder.append(Integer.toBinaryString(remainingStates));
+ builder.append(")|");
+ }
+ builder.deleteCharAt(builder.length() - 1);
+ return builder.toString();
}
/**
@@ -744,17 +748,7 @@ public class GpsMeasurement implements Parcelable {
* Sets the 'loss of lock' status.
*/
public void setLossOfLock(byte value) {
- switch (value) {
- case LOSS_OF_LOCK_UNKNOWN:
- case LOSS_OF_LOCK_OK:
- case LOSS_OF_LOCK_CYCLE_SLIP:
- mLossOfLock = value;
- break;
- default:
- Log.d(TAG, "Sanitizing invalid 'loss of lock': " + value);
- mLossOfLock = LOSS_OF_LOCK_UNKNOWN;
- break;
- }
+ mLossOfLock = value;
}
/**
@@ -770,7 +764,7 @@ public class GpsMeasurement implements Parcelable {
case LOSS_OF_LOCK_CYCLE_SLIP:
return "CycleSlip";
default:
- return "<Invalid>";
+ return "<Invalid:" + mLossOfLock + ">";
}
}
@@ -919,17 +913,7 @@ public class GpsMeasurement implements Parcelable {
* Sets the 'multi-path' indicator.
*/
public void setMultipathIndicator(byte value) {
- switch (value) {
- case MULTIPATH_INDICATOR_UNKNOWN:
- case MULTIPATH_INDICATOR_DETECTED:
- case MULTIPATH_INDICATOR_NOT_USED:
- mMultipathIndicator = value;
- break;
- default:
- Log.d(TAG, "Sanitizing invalid 'muti-path indicator': " + value);
- mMultipathIndicator = MULTIPATH_INDICATOR_UNKNOWN;
- break;
- }
+ mMultipathIndicator = value;
}
/**
@@ -945,7 +929,7 @@ public class GpsMeasurement implements Parcelable {
case MULTIPATH_INDICATOR_NOT_USED:
return "NotUsed";
default:
- return "<Invalid>";
+ return "<Invalid:" + mMultipathIndicator + ">";
}
}
diff --git a/location/java/android/location/GpsNavigationMessage.java b/location/java/android/location/GpsNavigationMessage.java
index 42f8ee4..b893f3f 100644
--- a/location/java/android/location/GpsNavigationMessage.java
+++ b/location/java/android/location/GpsNavigationMessage.java
@@ -20,7 +20,6 @@ import android.annotation.NonNull;
import android.annotation.SystemApi;
import android.os.Parcel;
import android.os.Parcelable;
-import android.util.Log;
import java.security.InvalidParameterException;
@@ -31,7 +30,7 @@ import java.security.InvalidParameterException;
*/
@SystemApi
public class GpsNavigationMessage implements Parcelable {
- private static final String TAG = "GpsNavigationMessage";
+
private static final byte[] EMPTY_ARRAY = new byte[0];
// The following enumerations must be in sync with the values declared in gps.h
@@ -102,19 +101,7 @@ public class GpsNavigationMessage implements Parcelable {
* Sets the type of the navigation message.
*/
public void setType(byte value) {
- switch (value) {
- case TYPE_UNKNOWN:
- case TYPE_L1CA:
- case TYPE_L2CNAV:
- case TYPE_L5CNAV:
- case TYPE_CNAV2:
- mType = value;
- break;
- default:
- Log.d(TAG, "Sanitizing invalid 'type': " + value);
- mType = TYPE_UNKNOWN;
- break;
- }
+ mType = value;
}
/**
@@ -134,7 +121,7 @@ public class GpsNavigationMessage implements Parcelable {
case TYPE_CNAV2:
return "CNAV-2";
default:
- return "<Invalid>";
+ return "<Invalid:" + mType + ">";
}
}