aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbkhurshi <kbeenish@hotmail.com>2013-07-18 15:28:36 -0700
committerbkhurshi <kbeenish@hotmail.com>2013-07-18 15:28:36 -0700
commit63128e138febee1238b106bcc43e06b7a3fe2854 (patch)
tree4f454d3ba0a84390e896e9fde58eacf8e6af48e4
parent517112d059f36a7e5604ee1dba77feac2dd5d244 (diff)
parentff82ea455806f6a7eea8f02050662ecb87253d08 (diff)
downloadandroid_external_ant-wireless_ant_service-63128e138febee1238b106bcc43e06b7a3fe2854.tar.gz
android_external_ant-wireless_ant_service-63128e138febee1238b106bcc43e06b7a3fe2854.tar.bz2
android_external_ant-wireless_ant_service-63128e138febee1238b106bcc43e06b7a3fe2854.zip
Merge pull request #3 from bkhurshi/master
Enable Bluetooth when ANT is enabled if required by chip. Only reads first HCI packet if multiple concatenated on read from file. Process flow control message while rx callback is not set. Don't send flow control packet to rx callback.
-rw-r--r--Android.mk13
-rw-r--r--AndroidManifest.xml11
-rw-r--r--project.properties2
-rw-r--r--src/com/dsi/ant/server/AntService.java93
-rw-r--r--src/com/dsi/ant/server/StateChangedReceiver.java43
5 files changed, 160 insertions, 2 deletions
diff --git a/Android.mk b/Android.mk
index 2169f06..92d7751 100644
--- a/Android.mk
+++ b/Android.mk
@@ -20,6 +20,9 @@ ifneq ($(BOARD_ANT_WIRELESS_DEVICE),)
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
+BT_ON_SRC_FILES := \
+ src/com/dsi/ant/server/StateChangedReceiver.java
+
#
# ANT java system service
#
@@ -29,6 +32,16 @@ LOCAL_SRC_FILES := \
src/com/dsi/ant/server/IAntHal.aidl \
src/com/dsi/ant/server/IAntHalCallback.aidl
+#
+# If target board is not one that requires Bluetooth to be enabled for ANT to enable,
+# filter out files that are only needed for Bluetooth to enable when ANT is enabled.
+#
+
+ifeq ($(filter msm8610 msm8226 msm8974, $(TARGET_BOARD_PLATFORM)),)
+LOCAL_SRC_FILES := \
+ $(filter-out $(BT_ON_SRC_FILES), $(LOCAL_SRC_FILES))
+endif
+
LOCAL_REQUIRED_MODULES := libantradio
LOCAL_PROGUARD_FLAG_FILES := proguard.flags
LOCAL_CERTIFICATE := platform
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 9336b82..7284179 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -50,6 +50,15 @@ limitations under the License.
</intent-filter>
</receiver>
+ <receiver android:name="com.dsi.ant.server.StateChangedReceiver"
+ android:enabled="true"
+ android:exported="false"
+ android:label="StateChangedReceiver">
+ <intent-filter>
+ <action android:name="android.bluetooth.adapter.action.STATE_CHANGED" />
+ </intent-filter>
+ </receiver>
+
</application>
<!-- These permissions should be defined in the system -->
@@ -71,5 +80,7 @@ limitations under the License.
android:description="@string/permdesc_antradio"
android:label="@string/permlab_antradio"/>
+ <uses-permission android:name="android.permission.BLUETOOTH" />
+ <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
</manifest>
diff --git a/project.properties b/project.properties
index 5a70945..c4f09d2 100644
--- a/project.properties
+++ b/project.properties
@@ -8,4 +8,4 @@
# project structure.
# Project target.
-target=android-7
+target=android-17
diff --git a/src/com/dsi/ant/server/AntService.java b/src/com/dsi/ant/server/AntService.java
index 1619c0b..388a311 100644
--- a/src/com/dsi/ant/server/AntService.java
+++ b/src/com/dsi/ant/server/AntService.java
@@ -18,12 +18,18 @@
package com.dsi.ant.server;
+import android.bluetooth.BluetoothAdapter;
+import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
+import android.content.IntentFilter;
import android.app.Service;
+import android.os.Binder;
import android.os.IBinder;
import android.os.RemoteException;
+import android.provider.Settings;
import android.util.Log;
+import android.os.SystemProperties;
import com.dsi.ant.core.*;
@@ -40,15 +46,57 @@ public class AntService extends Service
public static final String ANT_SERVICE = "AntService";
+ public static final String ANT_ADMIN_PERMISSION = "com.dsi.ant.permission.ANT_ADMIN";
+
+ public static final String ACTION_REQUEST_ENABLE = "com.dsi.ant.server.action.REQUEST_ENABLE";
+
+ public static final String ACTION_REQUEST_DISABLE = "com.dsi.ant.server.action.REQUEST_DISABLE";
+
private JAntJava mJAnt = null;
private boolean mInitialized = false;
+ private boolean mRequiresBluetoothOn = false;
+
+ private boolean mEnablePending = false;
+
private Object mChangeAntPowerState_LOCK = new Object();
private static Object sAntHalServiceDestroy_LOCK = new Object();
IAntHalCallback mCallback;
+ private boolean isQcomPlatform()
+ {
+ if ((SystemProperties.get("ro.board.platform").equals("msm8974"))
+ || (SystemProperties.get("ro.board.platform").equals("msm8610"))
+ || (SystemProperties.get("ro.board.platform").equals("msm8226"))) {
+
+ return true;
+ }
+ return false;
+ }
+
+ private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ if (mRequiresBluetoothOn) {
+ String action = intent.getAction();
+ if (ACTION_REQUEST_ENABLE.equals(action)) {
+ if (mEnablePending) {
+ asyncSetAntPowerState(true);
+ mEnablePending = false;
+ }
+ } else if (ACTION_REQUEST_DISABLE.equals(action)) {
+ if (mEnablePending) {
+ mEnablePending = false;
+ } else {
+ asyncSetAntPowerState(false);
+ }
+ }
+ }
+ }
+ };
+
public static boolean startService(Context context)
{
return ( null != context.startService(new Intent(IAntHal.class.getName())) );
@@ -99,7 +147,42 @@ public class AntService extends Service
{
case AntHalDefine.ANT_HAL_STATE_ENABLED:
{
- result = asyncSetAntPowerState(true);
+ result = AntHalDefine.ANT_HAL_RESULT_FAIL_NOT_ENABLED;
+
+ boolean waitForBluetoothToEnable = false;
+
+ if (mRequiresBluetoothOn) {
+
+ // Try to turn on BT if it is not enabled.
+ BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
+
+ if (bluetoothAdapter != null) {
+ long callingPid = Binder.clearCallingIdentity();
+
+ if (!bluetoothAdapter.isEnabled()) {
+
+ waitForBluetoothToEnable = true;
+
+ // check permissions of ANTHALService
+ boolean isEnabling = bluetoothAdapter.enable();
+
+ // if enabling adapter has begun, return
+ // success.
+ if (isEnabling) {
+ mEnablePending = true;
+ result = AntHalDefine.ANT_HAL_RESULT_SUCCESS;
+ // StateChangedReceiver will receive
+ // enabled status and then enable ANT
+ }
+ }
+
+ Binder.restoreCallingIdentity(callingPid);
+ }
+ }
+
+ if (!waitForBluetoothToEnable) {
+ result = asyncSetAntPowerState(true);
+ }
break;
}
case AntHalDefine.ANT_HAL_STATE_DISABLED:
@@ -430,6 +513,7 @@ public class AntService extends Service
}
// create a single new JAnt HCI Interface instance
mJAnt = new JAntJava();
+ mRequiresBluetoothOn = isQcomPlatform();
JAntStatus createResult = mJAnt.create(mJAntCallback);
if (createResult == JAntStatus.SUCCESS)
@@ -444,6 +528,11 @@ public class AntService extends Service
if (DEBUG) Log.e(TAG, "JAntJava create failed: " + createResult);
}
+
+ IntentFilter filter = new IntentFilter();
+ filter.addAction(ACTION_REQUEST_ENABLE);
+ filter.addAction(ACTION_REQUEST_DISABLE);
+ registerReceiver(mReceiver, filter);
}
@Override
@@ -471,6 +560,8 @@ public class AntService extends Service
{
super.onDestroy();
}
+
+ unregisterReceiver(mReceiver);
}
@Override
diff --git a/src/com/dsi/ant/server/StateChangedReceiver.java b/src/com/dsi/ant/server/StateChangedReceiver.java
new file mode 100644
index 0000000..4479003
--- /dev/null
+++ b/src/com/dsi/ant/server/StateChangedReceiver.java
@@ -0,0 +1,43 @@
+/*
+ Copyright 2013 Dynastream Innovations
+
+ 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 the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+
+package com.dsi.ant.server;
+
+import android.bluetooth.BluetoothAdapter;
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+
+public class StateChangedReceiver extends BroadcastReceiver {
+
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ // Bluetooth State Changed
+ if (BluetoothAdapter.ACTION_STATE_CHANGED.equals(intent.getAction())) {
+
+ int bluetoothState = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, 0);
+
+ if (BluetoothAdapter.STATE_OFF == bluetoothState) {
+ Intent antIntent = new Intent(AntService.ACTION_REQUEST_DISABLE);
+ context.sendBroadcast(antIntent, AntService.ANT_ADMIN_PERMISSION);
+ } else if (BluetoothAdapter.STATE_ON == bluetoothState) {
+ Intent antIntent = new Intent(AntService.ACTION_REQUEST_ENABLE);
+ context.sendBroadcast(antIntent, AntService.ANT_ADMIN_PERMISSION);
+ }
+ } // else if <<Another device dependency>> state change
+
+ }
+}