Loading Android.mk +0 −1 Original line number Diff line number Diff line Loading @@ -113,7 +113,6 @@ LOCAL_SRC_FILES += \ core/java/android/content/pm/IPackageMoveObserver.aidl \ core/java/android/content/pm/IPackageStatsObserver.aidl \ core/java/android/database/IContentObserver.aidl \ core/java/android/hardware/ISensorService.aidl \ core/java/android/net/IConnectivityManager.aidl \ core/java/android/net/INetworkManagementEventObserver.aidl \ core/java/android/net/IThrottleManager.aidl \ Loading cmds/system_server/library/Android.mk +2 −0 Original line number Diff line number Diff line Loading @@ -10,11 +10,13 @@ LOCAL_C_INCLUDES := \ $(base)/services/camera/libcameraservice \ $(base)/services/audioflinger \ $(base)/services/surfaceflinger \ $(base)/services/sensorservice \ $(base)/media/libmediaplayerservice \ $(JNI_H_INCLUDE) LOCAL_SHARED_LIBRARIES := \ libandroid_runtime \ libsensorservice \ libsurfaceflinger \ libaudioflinger \ libcameraservice \ Loading cmds/system_server/library/system_init.cpp +4 −0 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ #include <CameraService.h> #include <AudioPolicyService.h> #include <MediaPlayerService.h> #include <SensorService.h> #include <android_runtime/AndroidRuntime.h> Loading Loading @@ -69,6 +70,9 @@ extern "C" status_t system_init() SurfaceFlinger::instantiate(); } // Start the sensor service SensorService::instantiate(); // On the simulator, audioflinger et al don't get started the // same way as on the device, and we need to start them here if (!proc->supportsProcesses()) { Loading core/java/android/hardware/ISensorService.aidldeleted 100644 → 0 +0 −29 Original line number Diff line number Diff line /* //device/java/android/android/hardware/ISensorService.aidl ** ** Copyright 2008, The Android Open Source Project ** ** 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 android.hardware; import android.os.Bundle; /** * {@hide} */ interface ISensorService { Bundle getDataChannel(); boolean enableSensor(IBinder listener, String name, int sensor, int enable); } core/java/android/hardware/SensorManager.java +71 −132 Original line number Diff line number Diff line Loading @@ -16,12 +16,7 @@ package android.hardware; import android.content.Context; import android.os.Binder; import android.os.Bundle; import android.os.Looper; import android.os.Parcelable; import android.os.ParcelFileDescriptor; import android.os.Process; import android.os.RemoteException; import android.os.Handler; Loading @@ -33,8 +28,6 @@ import android.view.IRotationWatcher; import android.view.IWindowManager; import android.view.Surface; import java.io.FileDescriptor; import java.io.IOException; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; Loading Loading @@ -339,7 +332,6 @@ public class SensorManager /*-----------------------------------------------------------------------*/ private ISensorService mSensorService; Looper mMainLooper; @SuppressWarnings("deprecation") private HashMap<SensorListener, LegacyListener> mLegacyListenersMap = Loading @@ -356,6 +348,7 @@ public class SensorManager /* The thread and the sensor list are global to the process * but the actual thread is spawned on demand */ private static SensorThread sSensorThread; private static int sQueue; // Used within this module from outside SensorManager, don't make private static SparseArray<Sensor> sHandleToSensor = new SparseArray<Sensor>(); Loading @@ -370,23 +363,18 @@ public class SensorManager boolean mSensorsReady; SensorThread() { // this gets to the sensor module. We can have only one per process. sensors_data_init(); } @Override protected void finalize() { sensors_data_uninit(); } // must be called with sListeners lock boolean startLocked(ISensorService service) { boolean startLocked() { try { if (mThread == null) { Bundle dataChannel = service.getDataChannel(); if (dataChannel != null) { mSensorsReady = false; SensorThreadRunnable runnable = new SensorThreadRunnable(dataChannel); SensorThreadRunnable runnable = new SensorThreadRunnable(); Thread thread = new Thread(runnable, SensorThread.class.getName()); thread.start(); synchronized (runnable) { Loading @@ -396,54 +384,20 @@ public class SensorManager } mThread = thread; } } } catch (RemoteException e) { Log.e(TAG, "RemoteException in startLocked: ", e); } catch (InterruptedException e) { } return mThread == null ? false : true; } private class SensorThreadRunnable implements Runnable { private Bundle mDataChannel; SensorThreadRunnable(Bundle dataChannel) { mDataChannel = dataChannel; SensorThreadRunnable() { } private boolean open() { // NOTE: this cannot synchronize on sListeners, since // it's held in the main thread at least until we // return from here. // this thread is guaranteed to be unique Parcelable[] pfds = mDataChannel.getParcelableArray("fds"); FileDescriptor[] fds; if (pfds != null) { int length = pfds.length; fds = new FileDescriptor[length]; for (int i = 0; i < length; i++) { ParcelFileDescriptor pfd = (ParcelFileDescriptor)pfds[i]; fds[i] = pfd.getFileDescriptor(); } } else { fds = null; } int[] ints = mDataChannel.getIntArray("ints"); sensors_data_open(fds, ints); if (pfds != null) { try { // close our copies of the file descriptors, // since we are just passing these to the JNI code and not using them here. for (int i = pfds.length - 1; i >= 0; i--) { ParcelFileDescriptor pfd = (ParcelFileDescriptor)pfds[i]; pfd.close(); } } catch (IOException e) { // *shrug* Log.e(TAG, "IOException: ", e); } } mDataChannel = null; sQueue = sensors_create_queue(); return true; } Loading @@ -466,7 +420,7 @@ public class SensorManager while (true) { // wait for an event final int sensor = sensors_data_poll(values, status, timestamp); final int sensor = sensors_data_poll(sQueue, values, status, timestamp); int accuracy = status[0]; synchronized (sListeners) { Loading @@ -478,7 +432,8 @@ public class SensorManager } // we have no more listeners or polling failed, terminate the thread sensors_data_close(); sensors_destroy_queue(sQueue); sQueue = 0; mThread = null; break; } Loading Loading @@ -506,7 +461,7 @@ public class SensorManager /*-----------------------------------------------------------------------*/ private class ListenerDelegate extends Binder { private class ListenerDelegate { final SensorEventListener mSensorEventListener; private final ArrayList<Sensor> mSensorList = new ArrayList<Sensor>(); private final Handler mHandler; Loading Loading @@ -602,8 +557,6 @@ public class SensorManager * {@hide} */ public SensorManager(Looper mainLooper) { mSensorService = ISensorService.Stub.asInterface( ServiceManager.getService(Context.SENSOR_SERVICE)); mMainLooper = mainLooper; Loading Loading @@ -1051,7 +1004,6 @@ public class SensorManager return false; } try { synchronized (sListeners) { ListenerDelegate l = null; for (ListenerDelegate i : sListeners) { Loading @@ -1068,9 +1020,9 @@ public class SensorManager l = new ListenerDelegate(listener, sensor, handler); sListeners.add(l); if (!sListeners.isEmpty()) { result = sSensorThread.startLocked(mSensorService); result = sSensorThread.startLocked(); if (result) { result = mSensorService.enableSensor(l, name, handle, delay); result = sensors_enable_sensor(sQueue, name, handle, delay); if (!result) { // there was an error, remove the listeners sListeners.remove(l); Loading @@ -1078,16 +1030,12 @@ public class SensorManager } } } else { result = mSensorService.enableSensor(l, name, handle, delay); result = sensors_enable_sensor(sQueue, name, handle, delay); if (result) { l.addSensor(sensor); } } } } catch (RemoteException e) { Log.e(TAG, "RemoteException in registerListener: ", e); result = false; } return result; } Loading @@ -1095,7 +1043,6 @@ public class SensorManager if (listener == null || sensor == null) { return; } try { synchronized (sListeners) { final int size = sListeners.size(); for (int i=0 ; i<size ; i++) { Loading @@ -1104,7 +1051,7 @@ public class SensorManager // disable these sensors String name = sensor.getName(); int handle = sensor.getHandle(); mSensorService.enableSensor(l, name, handle, SENSOR_DISABLE); sensors_enable_sensor(sQueue, name, handle, SENSOR_DISABLE); // if we have no more sensors enabled on this listener, // take it off the list. if (l.removeSensor(sensor) == 0) { Loading @@ -1114,16 +1061,12 @@ public class SensorManager } } } } catch (RemoteException e) { Log.e(TAG, "RemoteException in unregisterListener: ", e); } } private void unregisterListener(Object listener) { if (listener == null) { return; } try { synchronized (sListeners) { final int size = sListeners.size(); for (int i=0 ; i<size ; i++) { Loading @@ -1133,16 +1076,13 @@ public class SensorManager for (Sensor sensor : l.getSensors()) { String name = sensor.getName(); int handle = sensor.getHandle(); mSensorService.enableSensor(l, name, handle, SENSOR_DISABLE); sensors_enable_sensor(sQueue, name, handle, SENSOR_DISABLE); } sListeners.remove(i); break; } } } } catch (RemoteException e) { Log.e(TAG, "RemoteException in unregisterListener: ", e); } } /** Loading Loading @@ -1794,9 +1734,8 @@ public class SensorManager private static native int sensors_module_get_next_sensor(Sensor sensor, int next); // Used within this module from outside SensorManager, don't make private static native int sensors_data_init(); static native int sensors_data_uninit(); static native int sensors_data_open(FileDescriptor[] fds, int[] ints); static native int sensors_data_close(); static native int sensors_data_poll(float[] values, int[] status, long[] timestamp); static native int sensors_create_queue(); static native void sensors_destroy_queue(int queue); static native boolean sensors_enable_sensor(int queue, String name, int sensor, int enable); static native int sensors_data_poll(int queue, float[] values, int[] status, long[] timestamp); } Loading
Android.mk +0 −1 Original line number Diff line number Diff line Loading @@ -113,7 +113,6 @@ LOCAL_SRC_FILES += \ core/java/android/content/pm/IPackageMoveObserver.aidl \ core/java/android/content/pm/IPackageStatsObserver.aidl \ core/java/android/database/IContentObserver.aidl \ core/java/android/hardware/ISensorService.aidl \ core/java/android/net/IConnectivityManager.aidl \ core/java/android/net/INetworkManagementEventObserver.aidl \ core/java/android/net/IThrottleManager.aidl \ Loading
cmds/system_server/library/Android.mk +2 −0 Original line number Diff line number Diff line Loading @@ -10,11 +10,13 @@ LOCAL_C_INCLUDES := \ $(base)/services/camera/libcameraservice \ $(base)/services/audioflinger \ $(base)/services/surfaceflinger \ $(base)/services/sensorservice \ $(base)/media/libmediaplayerservice \ $(JNI_H_INCLUDE) LOCAL_SHARED_LIBRARIES := \ libandroid_runtime \ libsensorservice \ libsurfaceflinger \ libaudioflinger \ libcameraservice \ Loading
cmds/system_server/library/system_init.cpp +4 −0 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ #include <CameraService.h> #include <AudioPolicyService.h> #include <MediaPlayerService.h> #include <SensorService.h> #include <android_runtime/AndroidRuntime.h> Loading Loading @@ -69,6 +70,9 @@ extern "C" status_t system_init() SurfaceFlinger::instantiate(); } // Start the sensor service SensorService::instantiate(); // On the simulator, audioflinger et al don't get started the // same way as on the device, and we need to start them here if (!proc->supportsProcesses()) { Loading
core/java/android/hardware/ISensorService.aidldeleted 100644 → 0 +0 −29 Original line number Diff line number Diff line /* //device/java/android/android/hardware/ISensorService.aidl ** ** Copyright 2008, The Android Open Source Project ** ** 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 android.hardware; import android.os.Bundle; /** * {@hide} */ interface ISensorService { Bundle getDataChannel(); boolean enableSensor(IBinder listener, String name, int sensor, int enable); }
core/java/android/hardware/SensorManager.java +71 −132 Original line number Diff line number Diff line Loading @@ -16,12 +16,7 @@ package android.hardware; import android.content.Context; import android.os.Binder; import android.os.Bundle; import android.os.Looper; import android.os.Parcelable; import android.os.ParcelFileDescriptor; import android.os.Process; import android.os.RemoteException; import android.os.Handler; Loading @@ -33,8 +28,6 @@ import android.view.IRotationWatcher; import android.view.IWindowManager; import android.view.Surface; import java.io.FileDescriptor; import java.io.IOException; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; Loading Loading @@ -339,7 +332,6 @@ public class SensorManager /*-----------------------------------------------------------------------*/ private ISensorService mSensorService; Looper mMainLooper; @SuppressWarnings("deprecation") private HashMap<SensorListener, LegacyListener> mLegacyListenersMap = Loading @@ -356,6 +348,7 @@ public class SensorManager /* The thread and the sensor list are global to the process * but the actual thread is spawned on demand */ private static SensorThread sSensorThread; private static int sQueue; // Used within this module from outside SensorManager, don't make private static SparseArray<Sensor> sHandleToSensor = new SparseArray<Sensor>(); Loading @@ -370,23 +363,18 @@ public class SensorManager boolean mSensorsReady; SensorThread() { // this gets to the sensor module. We can have only one per process. sensors_data_init(); } @Override protected void finalize() { sensors_data_uninit(); } // must be called with sListeners lock boolean startLocked(ISensorService service) { boolean startLocked() { try { if (mThread == null) { Bundle dataChannel = service.getDataChannel(); if (dataChannel != null) { mSensorsReady = false; SensorThreadRunnable runnable = new SensorThreadRunnable(dataChannel); SensorThreadRunnable runnable = new SensorThreadRunnable(); Thread thread = new Thread(runnable, SensorThread.class.getName()); thread.start(); synchronized (runnable) { Loading @@ -396,54 +384,20 @@ public class SensorManager } mThread = thread; } } } catch (RemoteException e) { Log.e(TAG, "RemoteException in startLocked: ", e); } catch (InterruptedException e) { } return mThread == null ? false : true; } private class SensorThreadRunnable implements Runnable { private Bundle mDataChannel; SensorThreadRunnable(Bundle dataChannel) { mDataChannel = dataChannel; SensorThreadRunnable() { } private boolean open() { // NOTE: this cannot synchronize on sListeners, since // it's held in the main thread at least until we // return from here. // this thread is guaranteed to be unique Parcelable[] pfds = mDataChannel.getParcelableArray("fds"); FileDescriptor[] fds; if (pfds != null) { int length = pfds.length; fds = new FileDescriptor[length]; for (int i = 0; i < length; i++) { ParcelFileDescriptor pfd = (ParcelFileDescriptor)pfds[i]; fds[i] = pfd.getFileDescriptor(); } } else { fds = null; } int[] ints = mDataChannel.getIntArray("ints"); sensors_data_open(fds, ints); if (pfds != null) { try { // close our copies of the file descriptors, // since we are just passing these to the JNI code and not using them here. for (int i = pfds.length - 1; i >= 0; i--) { ParcelFileDescriptor pfd = (ParcelFileDescriptor)pfds[i]; pfd.close(); } } catch (IOException e) { // *shrug* Log.e(TAG, "IOException: ", e); } } mDataChannel = null; sQueue = sensors_create_queue(); return true; } Loading @@ -466,7 +420,7 @@ public class SensorManager while (true) { // wait for an event final int sensor = sensors_data_poll(values, status, timestamp); final int sensor = sensors_data_poll(sQueue, values, status, timestamp); int accuracy = status[0]; synchronized (sListeners) { Loading @@ -478,7 +432,8 @@ public class SensorManager } // we have no more listeners or polling failed, terminate the thread sensors_data_close(); sensors_destroy_queue(sQueue); sQueue = 0; mThread = null; break; } Loading Loading @@ -506,7 +461,7 @@ public class SensorManager /*-----------------------------------------------------------------------*/ private class ListenerDelegate extends Binder { private class ListenerDelegate { final SensorEventListener mSensorEventListener; private final ArrayList<Sensor> mSensorList = new ArrayList<Sensor>(); private final Handler mHandler; Loading Loading @@ -602,8 +557,6 @@ public class SensorManager * {@hide} */ public SensorManager(Looper mainLooper) { mSensorService = ISensorService.Stub.asInterface( ServiceManager.getService(Context.SENSOR_SERVICE)); mMainLooper = mainLooper; Loading Loading @@ -1051,7 +1004,6 @@ public class SensorManager return false; } try { synchronized (sListeners) { ListenerDelegate l = null; for (ListenerDelegate i : sListeners) { Loading @@ -1068,9 +1020,9 @@ public class SensorManager l = new ListenerDelegate(listener, sensor, handler); sListeners.add(l); if (!sListeners.isEmpty()) { result = sSensorThread.startLocked(mSensorService); result = sSensorThread.startLocked(); if (result) { result = mSensorService.enableSensor(l, name, handle, delay); result = sensors_enable_sensor(sQueue, name, handle, delay); if (!result) { // there was an error, remove the listeners sListeners.remove(l); Loading @@ -1078,16 +1030,12 @@ public class SensorManager } } } else { result = mSensorService.enableSensor(l, name, handle, delay); result = sensors_enable_sensor(sQueue, name, handle, delay); if (result) { l.addSensor(sensor); } } } } catch (RemoteException e) { Log.e(TAG, "RemoteException in registerListener: ", e); result = false; } return result; } Loading @@ -1095,7 +1043,6 @@ public class SensorManager if (listener == null || sensor == null) { return; } try { synchronized (sListeners) { final int size = sListeners.size(); for (int i=0 ; i<size ; i++) { Loading @@ -1104,7 +1051,7 @@ public class SensorManager // disable these sensors String name = sensor.getName(); int handle = sensor.getHandle(); mSensorService.enableSensor(l, name, handle, SENSOR_DISABLE); sensors_enable_sensor(sQueue, name, handle, SENSOR_DISABLE); // if we have no more sensors enabled on this listener, // take it off the list. if (l.removeSensor(sensor) == 0) { Loading @@ -1114,16 +1061,12 @@ public class SensorManager } } } } catch (RemoteException e) { Log.e(TAG, "RemoteException in unregisterListener: ", e); } } private void unregisterListener(Object listener) { if (listener == null) { return; } try { synchronized (sListeners) { final int size = sListeners.size(); for (int i=0 ; i<size ; i++) { Loading @@ -1133,16 +1076,13 @@ public class SensorManager for (Sensor sensor : l.getSensors()) { String name = sensor.getName(); int handle = sensor.getHandle(); mSensorService.enableSensor(l, name, handle, SENSOR_DISABLE); sensors_enable_sensor(sQueue, name, handle, SENSOR_DISABLE); } sListeners.remove(i); break; } } } } catch (RemoteException e) { Log.e(TAG, "RemoteException in unregisterListener: ", e); } } /** Loading Loading @@ -1794,9 +1734,8 @@ public class SensorManager private static native int sensors_module_get_next_sensor(Sensor sensor, int next); // Used within this module from outside SensorManager, don't make private static native int sensors_data_init(); static native int sensors_data_uninit(); static native int sensors_data_open(FileDescriptor[] fds, int[] ints); static native int sensors_data_close(); static native int sensors_data_poll(float[] values, int[] status, long[] timestamp); static native int sensors_create_queue(); static native void sensors_destroy_queue(int queue); static native boolean sensors_enable_sensor(int queue, String name, int sensor, int enable); static native int sensors_data_poll(int queue, float[] values, int[] status, long[] timestamp); }