diff options
author | ANT-Shane <shane.gallup@thisisant.com> | 2014-01-24 15:04:56 -0700 |
---|---|---|
committer | ANT-Shane <shane.gallup@thisisant.com> | 2014-01-24 15:04:56 -0700 |
commit | 8d63c29ff7b134711822d910e3a7412e58424645 (patch) | |
tree | 2e6c15f84c45d772956bd79b9cc8511707dfe2c6 | |
parent | bbb2473bc8aa871c5d82bcc1dba1359adabaf7a8 (diff) | |
download | android_external_ant-wireless_ant_service-8d63c29ff7b134711822d910e3a7412e58424645.tar.gz android_external_ant-wireless_ant_service-8d63c29ff7b134711822d910e3a7412e58424645.tar.bz2 android_external_ant-wireless_ant_service-8d63c29ff7b134711822d910e3a7412e58424645.zip |
Release v3.2.0
-FIXED Unsynchronized access to mCallback in AntHalService causing
NullPointerException in some situations
-UPDATE Application Launcher icon to grey version for visibility on dark
and light backgrounds
-UPDATE gitignore file
-rw-r--r-- | .gitignore | 33 | ||||
-rw-r--r-- | AndroidManifest.xml | 6 | ||||
-rw-r--r-- | res/drawable-xxhdpi/ic_launcher.png | bin | 0 -> 85882 bytes | |||
-rw-r--r-- | res/drawable/icon.png | bin | 6093 -> 0 bytes | |||
-rw-r--r-- | src/com/dsi/ant/server/AntService.java | 74 |
5 files changed, 62 insertions, 51 deletions
@@ -1,21 +1,12 @@ -# built application files -*.apk -*.ap_ - -# files for the dex VM -*.dex - -# Java class files -*.class - -# generated files -bin/ -gen/ - -# Local configuration file (sdk path, etc) -local.properties -# and the not safe to be released part -secure.properties - -# CVS files -CVS/ +# Ignores for Eclipse +/.settings/ + +# Ignores for Android Projects +/bin/ +/gen/ +/publish/ +/local.properties +/secure.properties + +# Ignores for Mac machines +.DS_Store
\ No newline at end of file diff --git a/AndroidManifest.xml b/AndroidManifest.xml index dd9cfc2..cfec40f 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -16,8 +16,8 @@ limitations under the License. --> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.dsi.ant.server" - android:versionName="3.1.1" - android:versionCode="030101" + android:versionName="3.2.0" + android:versionCode="030200" android:sharedUserId="android.uid.system"> <uses-sdk @@ -25,7 +25,7 @@ limitations under the License. android:targetSdkVersion="10" /> - <application android:icon="@drawable/icon" + <application android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:process="system" android:permission="com.dsi.ant.permission.ANTRADIO" > diff --git a/res/drawable-xxhdpi/ic_launcher.png b/res/drawable-xxhdpi/ic_launcher.png Binary files differnew file mode 100644 index 0000000..50efac8 --- /dev/null +++ b/res/drawable-xxhdpi/ic_launcher.png diff --git a/res/drawable/icon.png b/res/drawable/icon.png Binary files differdeleted file mode 100644 index 4bd12b3..0000000 --- a/res/drawable/icon.png +++ /dev/null diff --git a/src/com/dsi/ant/server/AntService.java b/src/com/dsi/ant/server/AntService.java index 92e4e67..4e6f891 100644 --- a/src/com/dsi/ant/server/AntService.java +++ b/src/com/dsi/ant/server/AntService.java @@ -80,7 +80,11 @@ public class AntService extends Service private Object mChangeAntPowerState_LOCK = new Object(); private static Object sAntHalServiceDestroy_LOCK = new Object(); - IAntHalCallback mCallback; + /** Callback object for sending events to the upper layers */ + private volatile IAntHalCallback mCallback; + /** Used for synchronizing changes to {@link #mCallback} + * The synchronization is needed because of how {@link #doUnregisterAntHalCallback(IAntHalCallback)} works */ + private final Object mCallback_LOCK = new Object(); /** * Receives Bluetooth State Changed intent and sends {@link ACTION_REQUEST_ENABLE} @@ -126,7 +130,7 @@ public class AntService extends Service } /** - * Calls back the registered callback with the change to the new state + * Calls back the registered callback with the change to the new state * @param state the {@link AntHalDefine} state */ private void setState(int state) @@ -134,13 +138,16 @@ public class AntService extends Service synchronized(mChangeAntPowerState_LOCK) { if(DEBUG) Log.i(TAG, "Setting ANT State = "+ state +" / "+ AntHalDefine.getAntHalStateString(state)); - if (mCallback != null) + // Use caching instead of synchronization so that we do not have to hold a lock during a callback. + // It is safe to not hold the lock because we are not doing any write accesses. + IAntHalCallback callback = mCallback; + if (callback != null) { try { - if(DEBUG) Log.d(TAG, "Calling status changed callback "+ mCallback.toString()); + if(DEBUG) Log.d(TAG, "Calling status changed callback "+ callback.toString()); - mCallback.antHalStateChanged(state); + callback.antHalStateChanged(state); } catch (RemoteException e) { @@ -188,7 +195,7 @@ public class AntService extends Service waitForBluetoothToEnable = true; mEnablePending = true; - + boolean isEnabling = bluetoothAdapter.enable(); // if enabling adapter has begun, return @@ -222,7 +229,7 @@ public class AntService extends Service break; } } - + return result; } } @@ -236,7 +243,7 @@ public class AntService extends Service if(DEBUG) Log.v(TAG, "doGetAntState start"); int retState = mJAnt.getRadioEnabledStatus(); // ANT state is native state - + if(DEBUG) Log.i(TAG, "Get ANT State = "+ retState +" / "+ AntHalDefine.getAntHalStateString(retState)); return retState; @@ -244,11 +251,9 @@ public class AntService extends Service /** * Perform a power change if required. - * Tries to use changeAntWirelessState() in {@link BluetoothService}. If it does not exist then - * it defaults to a native enable() or disable() call * @param state true for enable, false for disable - * @return {@link AntHalDefine#ANT_HAL_RESULT_SUCCESS} when the request is successfully sent, - * false otherwise + * @return {@link AntHalDefine#ANT_HAL_RESULT_SUCCESS} when the request has + * been posted, false otherwise */ private int asyncSetAntPowerState(final boolean state) { @@ -435,7 +440,10 @@ public class AntService extends Service { if(DEBUG) Log.i(TAG, "Registering callback: "+ callback.toString()); - mCallback = callback; + synchronized(mCallback_LOCK) + { + mCallback = callback; + } return AntHalDefine.ANT_HAL_RESULT_SUCCESS; } @@ -446,10 +454,13 @@ public class AntService extends Service int result = AntHalDefine.ANT_HAL_RESULT_FAIL_UNKNOWN; - if(mCallback.asBinder() == callback.asBinder()) + synchronized (mCallback_LOCK) { - mCallback = null; - result = AntHalDefine.ANT_HAL_RESULT_SUCCESS; + if(mCallback.asBinder() == callback.asBinder()) + { + mCallback = null; + result = AntHalDefine.ANT_HAL_RESULT_SUCCESS; + } } return result; @@ -535,7 +546,7 @@ public class AntService extends Service if (DEBUG) Log.d(TAG, "onCreate() entered"); super.onCreate(); - + if(null != mJAnt) { // This somehow happens when quickly starting/stopping an application. @@ -548,9 +559,9 @@ public class AntService extends Service if (createResult == JAntStatus.SUCCESS) { - mInitialized = true; + mInitialized = true; - if (DEBUG) Log.d(TAG, "JAntJava create success"); + if (DEBUG) Log.d(TAG, "JAntJava create success"); } else { @@ -563,7 +574,7 @@ public class AntService extends Service filter.addAction(ACTION_REQUEST_ENABLE); filter.addAction(ACTION_REQUEST_DISABLE); registerReceiver(mReceiver, filter); - + if (mRequiresBluetoothOn) { IntentFilter stateChangedFilter = new IntentFilter(); stateChangedFilter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED); @@ -578,19 +589,22 @@ public class AntService extends Service try { - synchronized(sAntHalServiceDestroy_LOCK) + synchronized(sAntHalServiceDestroy_LOCK) { if(null != mJAnt) { int result = disableBlocking(); if (DEBUG) Log.d(TAG, "onDestroy: disable result is: " + AntHalDefine.getAntHalResultString(result)); - + mJAnt.destroy(); mJAnt = null; } } - mCallback = null; + synchronized (mCallback_LOCK) + { + mCallback = null; + } } finally { @@ -633,7 +647,10 @@ public class AntService extends Service { if (DEBUG) Log.d(TAG, "onUnbind() entered"); - mCallback = null; + synchronized (mCallback_LOCK) + { + mCallback = null; + } return super.onUnbind(intent); } @@ -657,11 +674,14 @@ public class AntService extends Service { public synchronized void ANTRxMessage( byte[] message) { - if(null != mCallback) + // Use caching instead of synchronization so that we do not have to hold a lock during a callback. + // It is safe to not hold the lock because we are not doing any write accesses. + IAntHalCallback callback = mCallback; + if(null != callback) { try { - mCallback.antHalRxMessage(message); + callback.antHalRxMessage(message); } catch (RemoteException e) { @@ -678,7 +698,7 @@ public class AntService extends Service public synchronized void ANTStateChange(int NewState) { if (DEBUG) Log.i(TAG, "ANTStateChange callback to " + NewState); - + setState(NewState); } }; |