Pull in Android_System_Package_3-0-0
(Android_System_ANTHALService_3-0-0)
This commit is contained in:
@@ -16,8 +16,8 @@ limitations under the License.
|
|||||||
-->
|
-->
|
||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
package="com.dsi.ant.server"
|
package="com.dsi.ant.server"
|
||||||
android:versionName="2.1.0"
|
android:versionName="3.0.0"
|
||||||
android:versionCode="020100"
|
android:versionCode="030000"
|
||||||
android:sharedUserId="android.uid.system">
|
android:sharedUserId="android.uid.system">
|
||||||
|
|
||||||
<uses-sdk
|
<uses-sdk
|
||||||
|
|||||||
@@ -18,19 +18,11 @@
|
|||||||
|
|
||||||
package com.dsi.ant.server;
|
package com.dsi.ant.server;
|
||||||
|
|
||||||
import java.lang.reflect.InvocationTargetException;
|
|
||||||
import java.lang.reflect.Method;
|
|
||||||
|
|
||||||
import android.bluetooth.BluetoothAdapter;
|
|
||||||
import android.bluetooth.IBluetooth;
|
|
||||||
import android.bluetooth.IBluetoothStateChangeCallback;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.app.Service;
|
import android.app.Service;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
import android.os.ServiceManager;
|
|
||||||
import android.server.BluetoothService;
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import com.dsi.ant.core.*;
|
import com.dsi.ant.core.*;
|
||||||
@@ -57,13 +49,6 @@ public class AntService extends Service
|
|||||||
|
|
||||||
IAntHalCallback mCallback;
|
IAntHalCallback mCallback;
|
||||||
|
|
||||||
private BluetoothService mBluetoothService;
|
|
||||||
|
|
||||||
/** We requested an ANT enable in the BT service, and are waiting for it to complete */
|
|
||||||
private boolean mBluetoothServiceAntEnabling;
|
|
||||||
/** We requested an ANT disable in the BT service, and are waiting for it to complete */
|
|
||||||
private boolean mBluetoothServiceAntDisabling;
|
|
||||||
|
|
||||||
public static boolean startService(Context context)
|
public static boolean startService(Context context)
|
||||||
{
|
{
|
||||||
return ( null != context.startService(new Intent(IAntHal.class.getName())) );
|
return ( null != context.startService(new Intent(IAntHal.class.getName())) );
|
||||||
@@ -141,66 +126,13 @@ public class AntService extends Service
|
|||||||
{
|
{
|
||||||
if(DEBUG) Log.v(TAG, "doGetAntState start");
|
if(DEBUG) Log.v(TAG, "doGetAntState start");
|
||||||
|
|
||||||
int retState;
|
int retState = mJAnt.getRadioEnabledStatus(); // ANT state is native state
|
||||||
if (mBluetoothServiceAntEnabling)
|
|
||||||
{
|
|
||||||
if(DEBUG) Log.d(TAG, "Bluetooth Service ANT Enabling");
|
|
||||||
|
|
||||||
retState = AntHalDefine.ANT_HAL_STATE_ENABLING;
|
|
||||||
}
|
|
||||||
else if(mBluetoothServiceAntDisabling)
|
|
||||||
{
|
|
||||||
if(DEBUG) Log.d(TAG, "Bluetooth Service ANT Disabling");
|
|
||||||
|
|
||||||
retState = AntHalDefine.ANT_HAL_STATE_DISABLING;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
retState = mJAnt.getRadioEnabledStatus(); // ANT state is native state
|
|
||||||
}
|
|
||||||
|
|
||||||
if(DEBUG) Log.i(TAG, "Get ANT State = "+ retState +" / "+ AntHalDefine.getAntHalStateString(retState));
|
if(DEBUG) Log.i(TAG, "Get ANT State = "+ retState +" / "+ AntHalDefine.getAntHalStateString(retState));
|
||||||
|
|
||||||
return retState;
|
return retState;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* The callback that the BluetoothAdapterStateMachine will call back on when power is on / off.
|
|
||||||
* When called back, this function will call the native enable() or disable()
|
|
||||||
*/
|
|
||||||
private final IBluetoothStateChangeCallback.Stub mBluetoothStateChangeCallback = new IBluetoothStateChangeCallback.Stub()
|
|
||||||
{
|
|
||||||
@Override
|
|
||||||
public void onBluetoothStateChange(boolean on) throws RemoteException
|
|
||||||
{
|
|
||||||
synchronized(mChangeAntPowerState_LOCK) {
|
|
||||||
if (DEBUG) Log.i(TAG, "bluetooth state change callback: " + on);
|
|
||||||
|
|
||||||
if (on) {
|
|
||||||
mBluetoothServiceAntEnabling = false;
|
|
||||||
|
|
||||||
if (enableBlocking() == AntHalDefine.ANT_HAL_RESULT_SUCCESS) {
|
|
||||||
if(DEBUG) Log.v(TAG, "ANT native enable: Success");
|
|
||||||
setState(AntHalDefine.ANT_HAL_STATE_ENABLED);
|
|
||||||
} else {
|
|
||||||
Log.e(TAG, "ANT native enable failed");
|
|
||||||
setState(AntHalDefine.ANT_HAL_STATE_DISABLED);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
mBluetoothServiceAntDisabling = false;
|
|
||||||
|
|
||||||
if (disableBlocking() == AntHalDefine.ANT_HAL_RESULT_SUCCESS) {
|
|
||||||
if(DEBUG) Log.v(TAG, "ANT native disable: Success");
|
|
||||||
setState(AntHalDefine.ANT_HAL_STATE_DISABLED);
|
|
||||||
} else {
|
|
||||||
Log.e(TAG, "ANT native disable failed");
|
|
||||||
setState(doGetAntState());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Perform a power change if required.
|
* Perform a power change if required.
|
||||||
* Tries to use changeAntWirelessState() in {@link BluetoothService}. If it does not exist then
|
* Tries to use changeAntWirelessState() in {@link BluetoothService}. If it does not exist then
|
||||||
@@ -211,93 +143,44 @@ public class AntService extends Service
|
|||||||
*/
|
*/
|
||||||
private int asyncSetAntPowerState(final boolean state)
|
private int asyncSetAntPowerState(final boolean state)
|
||||||
{
|
{
|
||||||
synchronized(mChangeAntPowerState_LOCK) {
|
int result = AntHalDefine.ANT_HAL_RESULT_FAIL_UNKNOWN;
|
||||||
// Check we are not already in/transitioning to the state we want
|
|
||||||
int currentState = doGetAntState();
|
|
||||||
boolean doNativePower = false;
|
|
||||||
|
|
||||||
if(state) {
|
synchronized(mChangeAntPowerState_LOCK) {
|
||||||
if((AntHalDefine.ANT_HAL_STATE_ENABLED == currentState)
|
// Check we are not already in/transitioning to the state we want
|
||||||
|| (AntHalDefine.ANT_HAL_STATE_ENABLING == currentState)) {
|
int currentState = doGetAntState();
|
||||||
if(DEBUG) Log.d(TAG, "Enable request ignored as already enabled/enabling");
|
|
||||||
|
|
||||||
return AntHalDefine.ANT_HAL_RESULT_SUCCESS;
|
if(state) {
|
||||||
} else if(AntHalDefine.ANT_HAL_STATE_DISABLING == currentState) {
|
if((AntHalDefine.ANT_HAL_STATE_ENABLED == currentState)
|
||||||
Log.w(TAG, "Enable request ignored as already disabling");
|
|| (AntHalDefine.ANT_HAL_STATE_ENABLING == currentState)) {
|
||||||
|
if(DEBUG) Log.d(TAG, "Enable request ignored as already enabled/enabling");
|
||||||
|
|
||||||
return AntHalDefine.ANT_HAL_RESULT_FAIL_UNKNOWN;
|
return AntHalDefine.ANT_HAL_RESULT_SUCCESS;
|
||||||
}
|
} else if(AntHalDefine.ANT_HAL_STATE_DISABLING == currentState) {
|
||||||
} else {
|
Log.w(TAG, "Enable request ignored as already disabling");
|
||||||
if((AntHalDefine.ANT_HAL_STATE_DISABLED == currentState)
|
|
||||||
|| (AntHalDefine.ANT_HAL_STATE_DISABLING == currentState)) {
|
|
||||||
if(DEBUG)Log.d(TAG, "Disable request ignored as already disabled/disabling");
|
|
||||||
|
|
||||||
return AntHalDefine.ANT_HAL_RESULT_SUCCESS;
|
return AntHalDefine.ANT_HAL_RESULT_FAIL_UNKNOWN;
|
||||||
} else if(AntHalDefine.ANT_HAL_STATE_ENABLING == currentState) {
|
}
|
||||||
Log.w(TAG, "Disable request ignored as already enabling");
|
} else {
|
||||||
|
if((AntHalDefine.ANT_HAL_STATE_DISABLED == currentState)
|
||||||
|
|| (AntHalDefine.ANT_HAL_STATE_DISABLING == currentState)) {
|
||||||
|
if(DEBUG)Log.d(TAG, "Disable request ignored as already disabled/disabling");
|
||||||
|
|
||||||
return AntHalDefine.ANT_HAL_RESULT_FAIL_UNKNOWN;
|
return AntHalDefine.ANT_HAL_RESULT_SUCCESS;
|
||||||
}
|
} else if(AntHalDefine.ANT_HAL_STATE_ENABLING == currentState) {
|
||||||
}
|
Log.w(TAG, "Disable request ignored as already enabling");
|
||||||
|
|
||||||
if (mBluetoothService != null) {
|
return AntHalDefine.ANT_HAL_RESULT_FAIL_UNKNOWN;
|
||||||
try {
|
}
|
||||||
Method method_changeAntWirelessState = BluetoothService.class.getMethod(
|
}
|
||||||
"changeAntWirelessState", boolean.class,
|
|
||||||
IBluetoothStateChangeCallback.class);
|
|
||||||
|
|
||||||
boolean result = (Boolean) method_changeAntWirelessState.invoke(mBluetoothService,
|
if (state) {
|
||||||
state, mBluetoothStateChangeCallback);
|
result = enableBackground();
|
||||||
if (result) {
|
} else {
|
||||||
if (state) {
|
result = disableBackground();
|
||||||
if (DEBUG) Log.d(TAG, "enable request successful");
|
}
|
||||||
mBluetoothServiceAntEnabling = true;
|
|
||||||
setState(AntHalDefine.ANT_HAL_STATE_ENABLING);
|
|
||||||
} else {
|
|
||||||
if (DEBUG) Log.d(TAG, "disable request successful");
|
|
||||||
mBluetoothServiceAntDisabling = true;
|
|
||||||
setState(AntHalDefine.ANT_HAL_STATE_DISABLING);
|
|
||||||
}
|
|
||||||
return AntHalDefine.ANT_HAL_RESULT_SUCCESS;
|
|
||||||
} else {
|
|
||||||
Log.e(TAG, "power " + state + " request failed");
|
|
||||||
return AntHalDefine.ANT_HAL_RESULT_FAIL_UNKNOWN;
|
|
||||||
}
|
|
||||||
} catch (NoSuchMethodException e) {
|
|
||||||
// BluetoothService does not contain the ANT frameworks power function, which means
|
|
||||||
// the native code will do the chip power.
|
|
||||||
doNativePower = true;
|
|
||||||
} catch (IllegalAccessException e) {
|
|
||||||
// This exception should never happen, but if it does it is something we need to fix.
|
|
||||||
// This call is made on a Binder Thread, so rather than crash it and have it silently
|
|
||||||
// fail, we re-throw a supported IPC exception so that the higher level will know
|
|
||||||
// about the error.
|
|
||||||
throw new SecurityException("BluetoothService.changeAntWirelessState() function should be public\n" + e.getMessage());
|
|
||||||
} catch (InvocationTargetException e) {
|
|
||||||
// This exception should never happen, but if it does it is something we need to fix.
|
|
||||||
// This call is made on a Binder Thread, so rather than crash it and have it silently
|
|
||||||
// fail, we re-throw a supported IPC exception so that the higher level will know
|
|
||||||
// about the error.
|
|
||||||
throw new IllegalArgumentException("BluetoothService.changeAntWirelessState() should not throw exceptions\n" + e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Log.w(TAG, "in disable: No BluetoothService");
|
|
||||||
doNativePower = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(doNativePower) {
|
|
||||||
if (state) {
|
|
||||||
enableBackground();
|
|
||||||
} else {
|
|
||||||
disableBackground();
|
|
||||||
}
|
|
||||||
return AntHalDefine.ANT_HAL_RESULT_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
return AntHalDefine.ANT_HAL_RESULT_FAIL_UNKNOWN;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -540,9 +423,6 @@ public class AntService extends Service
|
|||||||
|
|
||||||
super.onCreate();
|
super.onCreate();
|
||||||
|
|
||||||
mBluetoothServiceAntEnabling = false;
|
|
||||||
mBluetoothServiceAntDisabling = false;
|
|
||||||
|
|
||||||
if(null != mJAnt)
|
if(null != mJAnt)
|
||||||
{
|
{
|
||||||
// This somehow happens when quickly starting/stopping an application.
|
// This somehow happens when quickly starting/stopping an application.
|
||||||
@@ -554,19 +434,9 @@ public class AntService extends Service
|
|||||||
|
|
||||||
if (createResult == JAntStatus.SUCCESS)
|
if (createResult == JAntStatus.SUCCESS)
|
||||||
{
|
{
|
||||||
mBluetoothService = (BluetoothService) IBluetooth.Stub.asInterface(ServiceManager.getService(BluetoothAdapter.BLUETOOTH_SERVICE));
|
mInitialized = true;
|
||||||
|
|
||||||
if (mBluetoothService == null)
|
if (DEBUG) Log.d(TAG, "JAntJava create success");
|
||||||
{
|
|
||||||
Log.e(TAG, "mBluetoothService == null");
|
|
||||||
mInitialized = false;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
mInitialized = true;
|
|
||||||
|
|
||||||
if (DEBUG) Log.d(TAG, "JAntJava create success");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -583,16 +453,13 @@ public class AntService extends Service
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if(null != mJAnt)
|
synchronized(sAntHalServiceDestroy_LOCK)
|
||||||
{
|
{
|
||||||
synchronized(sAntHalServiceDestroy_LOCK)
|
if(null != mJAnt)
|
||||||
{
|
{
|
||||||
if (asyncSetAntPowerState(false) != AntHalDefine.ANT_HAL_RESULT_SUCCESS)
|
|
||||||
{
|
|
||||||
Log.w(TAG, "onDestroy disable failed");
|
|
||||||
}
|
|
||||||
int result = disableBlocking();
|
int result = disableBlocking();
|
||||||
if (DEBUG) Log.d(TAG, "onDestroy: disable result is: " + AntHalDefine.getAntHalResultString(result));
|
if (DEBUG) Log.d(TAG, "onDestroy: disable result is: " + AntHalDefine.getAntHalResultString(result));
|
||||||
|
|
||||||
mJAnt.destroy();
|
mJAnt.destroy();
|
||||||
mJAnt = null;
|
mJAnt = null;
|
||||||
}
|
}
|
||||||
@@ -681,16 +548,6 @@ public class AntService extends Service
|
|||||||
{
|
{
|
||||||
if (DEBUG) Log.i(TAG, "ANTStateChange callback to " + NewState);
|
if (DEBUG) Log.i(TAG, "ANTStateChange callback to " + NewState);
|
||||||
|
|
||||||
if(mBluetoothServiceAntEnabling) {
|
|
||||||
Log.w(TAG, "Native state change ignored while waiting for BluetoothService ANT enable");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(mBluetoothServiceAntDisabling) {
|
|
||||||
Log.w(TAG, "Native state change ignored while waiting for BluetoothService ANT disable");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
setState(NewState);
|
setState(NewState);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user