Framework Sensor Support

122 views
Skip to first unread message

dani maoz

unread,
Oct 7, 2011, 5:50:48 AM10/7/11
to android-...@googlegroups.com, android-d...@googlegroups.com
Hi
How the framework decide from which sensor to read the relevant data,
For example if i have two accelometer sensor attach how can i configure the framekwork to receive information to read from the second one
Thanks
 

CVS

unread,
Oct 7, 2011, 9:45:40 AM10/7/11
to android-...@googlegroups.com, android-d...@googlegroups.com
Hi Dani,

Android assumes (and rightly so far) that ONLY one sensor of each "type" is present on the device.
Mulitiple sensors of same "type" are not supported in the framework.

If ur device has multiple sensors of same type onboard and you *really* want to enable both, then
1. Enable the kernel drivers for both sensors.
2. Add additonal "switch-sensor"functionality in the sensor-HAL.
(the code that generates your /system/lib/sensor.so)
3. Use the "switch-sensor" function interface u added in step2 in your programs.

Note that other programs (using standard Android API) will NOT be aware of the 2 sensors of the same type.
They will continue using the default sensor exposed by the sensor-HAL.

regards
CVS

dani maoz

unread,
Oct 7, 2011, 11:16:37 AM10/7/11
to android-...@googlegroups.com
Thanks you for the reply,
Can you post example, or point to the code where i have to change in order to support to configure
sensor support.
Where  can find additional information to  "switch sensor" functionality
Here is  a link i found
 


 

--
You received this message because you are subscribed to the Google Groups "android-platform" group.
To view this discussion on the web visit https://groups.google.com/d/msg/android-platform/-/_-KMStklJkMJ.
To post to this group, send email to android-...@googlegroups.com.
To unsubscribe from this group, send email to android-platfo...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/android-platform?hl=en.

Chinmay V S

unread,
Oct 8, 2011, 3:09:49 AM10/8/11
to android-...@googlegroups.com
AFAIK, No commercial devices support multiple sensors of the same "type".
So any "reference" code for multiple sensors is not readily available.
That said, it certainly seems odd that you have such a multiple sensor configuration in ur device.

If you are trying experimenting with android, then you will most certainly have to hack
into the framework to add such a functionality.

And the Sensor "HAL" or sensor middleware library is the easiest place to do so.
The link you shared above is slightly outdated (for android FroYo & previous versions)

You might want to switch to the newer implementation of libsensors (sensorHAL) for Nexus S crespo.

A very interesting project though. I am half-tempted to try it out myself.
I might just end-up doing it and post it on TheCodeArtist

regards
CVS

dani maoz

unread,
Oct 8, 2011, 9:26:40 AM10/8/11
to android-...@googlegroups.com
Thanks for the reply, i changed the Framework to support my sensor
i will post the code after i will finish testing


 


regards
CVS

--
You received this message because you are subscribed to the Google Groups "android-platform" group.

Atul Raut

unread,
Oct 10, 2011, 6:53:02 AM10/10/11
to cvs...@gmail.com, android-...@googlegroups.com
HI CVS,

We have below CTS test case it is getting failed with error given below.

CTS test Case : android.app.cts.SystemFeaturesTest#testSensorFeatures
Error : android.hardware.sensor.accelerometer) returns true but SensorManager#getSensorList(1) shows sensors [] expected:<true> but was:<false>

Does it failing because of  getting  sensor of each "type" present on the device ?
And I need to give framework support to enable this e.g. the steps you have given.
 
Thanks,
----------------------------------------------------------------------------------------------------------------------------------
Atul Raut

http://rautatul.weebly.com/



--
You received this message because you are subscribed to the Google Groups "android-platform" group.
To view this discussion on the web visit https://groups.google.com/d/msg/android-platform/-/_-KMStklJkMJ.

Chinmay V S

unread,
Oct 10, 2011, 7:20:28 AM10/10/11
to android-...@googlegroups.com
Hi Atul,

The CTS error is because of the difference in capabilities reported by:
- Package-manager : Reports that the accelerometer IS supported.
- Sensor-HAL: Reports that the accelerometer is NOT supported.

If your device HAS an accelerometer, then U obviously support is missing in the Sensor-HAL
You will need to rebuilt the code for system/lib/hw/sensors.*.so

If your device does NOT have an accelerometer, then correct the package-manager code.

As Tiago mentions in this discussion
https://groups.google.com/d/topic/android-platform/HVmTdDDue0g/discussion

PackageManager derieves it info about capabilities from the following file
android/frameworks/base/data/etc/handheld_core_hardware.xml

Try running the CTS tests after removing the following line from the above file
<feature name="android.hardware.sensor.accelerometer" />


regards
CVS

Kaspter Ju

unread,
Oct 10, 2011, 9:25:13 PM10/10/11
to android-...@googlegroups.com
On Fri, Oct 7, 2011 at 11:16 PM, dani maoz <maoz...@gmail.com> wrote:
> Thanks you for the reply,
> Can you post example, or point to the code where i have to change in order
> to support to configure
> sensor support.
> Where  can find additional information to  "switch sensor" functionality
> Here is  a link i found
> http://processors.wiki.ti.com/index.php/Android_Sensor_PortingGuide
>

see camera sensor HAL, there are two camera sensors support.

--
Kaspter Ju

Atul Raut

unread,
Oct 11, 2011, 6:14:50 AM10/11/11
to android-...@googlegroups.com, cvs...@gmail.com
Hi Chinmay,

As per you says,  
>>PackageManager derieves it info about capabilities from the following file
>>android/frameworks/base/data/etc/handheld_core_hardware.xml


In My case I have two devices one supports  accelerometer
and other dont. I don't no how to handled this situation in current
code base as Google made some changes in CTS latest release. 
e.g. in file handheld_core_hardware.xml I have entry 
for supporting one  device given below in handheld_core_hardware.xml
<permissions>
<feature name="android.hardware.sensor.accelerometer" />
</permissions>
then how to handle if my other device wont support accelerometer ?
in same engineering build. How to differentiate here based on device
capabilities ?

Thanks,
----------------------------------------------------------------------------------------------------------------------------------
Atul Raut

http://rautatul.weebly.com/



--
You received this message because you are subscribed to the Google Groups "android-platform" group.

Atul Raut

unread,
Oct 11, 2011, 6:22:24 AM10/11/11
to android-...@googlegroups.com, cvs...@gmail.com, c...@android.com

c...@android.com

Android CTS team can help, as we dont have access to latest cts 2.3_r9  source code.

Thanks,
Atul 

Chinmay V S

unread,
Oct 11, 2011, 7:04:45 AM10/11/11
to Atul Raut, android-...@googlegroups.com, c...@android.com
Hi Atul,

The handheld_core_hardware.xml gets "pushed" onto the device as follows:
PRODUCT_COPY_FILES += \
    frameworks/base/data/etc/handheld_core_hardware.xml:system/etc/permissions/handheld_core_hardware.xml \
Reference: http://goo.gl/M7V7c, http://goo.gl/ZCeRD

To suport multiple devices, you might want to do the following:
1. Write two separate handheld_core_hardware.xml files with separate device-capability profiles.
2. For each of the devices, override which xml file gets copied to the device in the corresponding Device.mk.

Device.mk for dev1 includes:
PRODUCT_COPY_FILES += \
    frameworks/base/data/etc/handheld_core_hardware_device1.xml:system/etc/permissions/handheld_core_hardware.xml \

Device.mk for dev2 includes:
PRODUCT_COPY_FILES += \
    frameworks/base/data/etc/handheld_core_hardware_device2.xml:system/etc/permissions/handheld_core_hardware.xml \

GoodLUCK!
-CVS

Atul Raut

unread,
Oct 18, 2011, 7:46:23 AM10/18/11
to Chinmay V S, android-...@googlegroups.com, c...@android.com
Hi Chinmay,

If I don't want to used two .xml files. And defining all permissions in single file,
will it be doable if then how. I tried many ways but didnt succeeded. 
Single xml file which have all permissions define and same file should used
device supporting the sensors and device which wont supports the sensors. 
 
Thanks,
----------------------------------------------------------------------------------------------------------------------------------
Atul Raut

http://rautatul.weebly.com/



Chinmay V S

unread,
Oct 18, 2011, 7:56:11 AM10/18/11
to Atul Raut, android-...@googlegroups.com, c...@android.com
Why?...
Any errors when you tried using the previous approach of device-specific xml files?...

regards
CVS

Atul Raut

unread,
Oct 18, 2011, 8:01:46 AM10/18/11
to Chinmay V S, android-...@googlegroups.com, c...@android.com
No not seen any others works fine. But I wanted to go with more generic ways so.
And its no good to touch Android code base. .e.g. Creating two handheld_core_hardware.xml 
files. So checking. 

 
Thanks,
----------------------------------------------------------------------------------------------------------------------------------
Atul Raut

http://rautatul.weebly.com/



Chinmay V S

unread,
Oct 18, 2011, 9:02:16 AM10/18/11
to Atul Raut, android-...@googlegroups.com, c...@android.com
Hi Atul,

The approach of multiple  handheld_core_hardware.xml files is specifically  a "hack" applicable to support devices with/without accelerometer sensor ONLY. This is because the accelerometer feature is very common and present in almost 100% of android devices. Hence it is a part of the handheld_core_hardware.xml.

Alternately for a "cleaner" implementation you could TRY the following:
1. Edit handheld_core_hardware.xml to a bare-minimum.
(Remove the accelerometer feature from the permissions tag.)

2. Create a android.hardware.sensor.accelerometer.xml in android/frameworks/base/data/etc/

3. Add the accelerometer feature <permission> tag in the above file.
You might want to look at this for reference:
android/frameworks/base/data/etc/android.hardware.sensor.gyroscope.xml

4. In the device-specific mk file, Add the second line ONLY in the mk file of the device supporting the accelerometer.
# These are the hardware-specific features
PRODUCT_COPY_FILES += \
frameworks/base/data/etc/handheld_core_hardware.xml:system/etc/permissions/handheld_core_hardware.xml \
frameworks/base/data/etc/android.hardware.sensor.accelerometer.xml:system/etc/permissions/android.hardware.sensor.accelerometer..xml \
...


The Android 2.3 Compatibility Definition document section 7.3. specifies the device implementations
Of particular interest is the reference link: Android Hardware Features List

PackageManager has the getSystemAvailableFeatures() and hasSystemFeature(String) APIs to check for the device capabilities.

You might want to poke around in the android frameworks code here to see how it does it:
android/frameworks/base/core/java/android/content/pm/PackageManager.java


GoodLUCK!
CVS

Chinmay V S

unread,
Nov 17, 2011, 12:43:55 PM11/17/11
to android-...@googlegroups.com
Hi Dani,

Did you get the multiple-sensors setup up and running?...

A clarification about what i said in my earlier reply,

Mulitiple sensors of same "type" are not supported in the framework.


I was wrong. Support for multiple sensors DOES exist in the framework.
Its just that the most applications assume single sensor of each type.

Presently, multiple sensors of same-type can be enumerated by querying SensorManager.getSensorList(type). This will flow down to the sensor-HAL which reports the elements listed in the sSensorList[]

Is this what you have implemented and got running?

Most applications do NOT seem to go through the extra pain of querying all the sensors and rely on SensorManager.getDefaultSensor(type) to obtain the sensor of a desired type. Hence the switch-functionality "hack" i was describing.

When you said, you changed the Framework to support your sensor, which approach did you try?

regards
CVS
Reply all
Reply to author
Forward
0 new messages