diff options
| author | The Android Open Source Project <initial-contribution@android.com> | 2009-03-03 18:28:45 -0800 | 
|---|---|---|
| committer | The Android Open Source Project <initial-contribution@android.com> | 2009-03-03 18:28:45 -0800 | 
| commit | d83a98f4ce9cfa908f5c54bbd70f03eec07e7553 (patch) | |
| tree | 4b825dc642cb6eb9a060e54bf8d69288fbee4904 /core/java/android/hardware | |
| parent | 076357b8567458d4b6dfdcf839ef751634cd2bfb (diff) | |
| download | frameworks_base-d83a98f4ce9cfa908f5c54bbd70f03eec07e7553.zip frameworks_base-d83a98f4ce9cfa908f5c54bbd70f03eec07e7553.tar.gz frameworks_base-d83a98f4ce9cfa908f5c54bbd70f03eec07e7553.tar.bz2 | |
auto import from //depot/cupcake/@135843
Diffstat (limited to 'core/java/android/hardware')
| -rw-r--r-- | core/java/android/hardware/Camera.java | 782 | ||||
| -rw-r--r-- | core/java/android/hardware/GeomagneticField.java | 409 | ||||
| -rw-r--r-- | core/java/android/hardware/ISensorService.aidl | 29 | ||||
| -rw-r--r-- | core/java/android/hardware/Sensor.java | 146 | ||||
| -rw-r--r-- | core/java/android/hardware/SensorEvent.java | 146 | ||||
| -rw-r--r-- | core/java/android/hardware/SensorEventListener.java | 49 | ||||
| -rw-r--r-- | core/java/android/hardware/SensorListener.java | 102 | ||||
| -rw-r--r-- | core/java/android/hardware/SensorManager.java | 1462 | ||||
| -rw-r--r-- | core/java/android/hardware/package.html | 5 | 
9 files changed, 0 insertions, 3130 deletions
| diff --git a/core/java/android/hardware/Camera.java b/core/java/android/hardware/Camera.java deleted file mode 100644 index 40a5b47..0000000 --- a/core/java/android/hardware/Camera.java +++ /dev/null @@ -1,782 +0,0 @@ -/* - * Copyright (C) 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 java.lang.ref.WeakReference; -import java.util.HashMap; -import java.util.StringTokenizer; -import java.io.IOException; - -import android.util.Log; -import android.view.Surface; -import android.view.SurfaceHolder; -import android.graphics.PixelFormat; -import android.os.Handler; -import android.os.Looper; -import android.os.Message; - -/** - * The Camera class is used to connect/disconnect with the camera service, - * set capture settings, start/stop preview, snap a picture, and retrieve - * frames for encoding for video. - * <p>There is no default constructor for this class. Use {@link #open()} to - * get a Camera object.</p> - */ -public class Camera { -    private static final String TAG = "Camera"; -     -    // These match the enum in libs/android_runtime/android_hardware_Camera.cpp -    private static final int SHUTTER_CALLBACK = 0; -    private static final int RAW_PICTURE_CALLBACK = 1; -    private static final int JPEG_PICTURE_CALLBACK = 2; -    private static final int PREVIEW_CALLBACK = 3; -    private static final int AUTOFOCUS_CALLBACK = 4; -    private static final int ERROR_CALLBACK = 5; - -    private int mNativeContext; // accessed by native methods -    private int mListenerContext; -    private EventHandler mEventHandler; -    private ShutterCallback mShutterCallback; -    private PictureCallback mRawImageCallback; -    private PictureCallback mJpegCallback; -    private PreviewCallback mPreviewCallback; -    private AutoFocusCallback mAutoFocusCallback; -    private ErrorCallback mErrorCallback; -    private boolean mOneShot; -     -    /** -     * Returns a new Camera object. -     */ -    public static Camera open() {  -        return new Camera();  -    } - -    Camera() { -        mShutterCallback = null; -        mRawImageCallback = null; -        mJpegCallback = null; -        mPreviewCallback = null; - -        Looper looper; -        if ((looper = Looper.myLooper()) != null) { -            mEventHandler = new EventHandler(this, looper); -        } else if ((looper = Looper.getMainLooper()) != null) { -            mEventHandler = new EventHandler(this, looper); -        } else { -            mEventHandler = null; -        } - -        native_setup(new WeakReference<Camera>(this)); -    } -     -    protected void finalize() {  -        native_release();  -    } -     -    private native final void native_setup(Object camera_this); -    private native final void native_release(); -     - -    /** -     * Disconnects and releases the Camera object resources. -     * <p>It is recommended that you call this as soon as you're done with the  -     * Camera object.</p> -     */ -    public final void release() {  -        native_release(); -    } - -    /** -     * Reconnect to the camera after passing it to MediaRecorder. To save -     * setup/teardown time, a client of Camera can pass an initialized Camera -     * object to a MediaRecorder to use for video recording. Once the  -     * MediaRecorder is done with the Camera, this method can be used to -     * re-establish a connection with the camera hardware. NOTE: The Camera -     * object must first be unlocked by the process that owns it before it -     * can be connected to another proces. -     * -     * @throws IOException if the method fails. -     * -     * FIXME: Unhide after approval -     * @hide -     */ -    public native final void reconnect() throws IOException; -     -    /** -     * Lock the camera to prevent other processes from accessing it. To save -     * setup/teardown time, a client of Camera can pass an initialized Camera -     * object to another process. This method is used to re-lock the Camera -     * object prevent other processes from accessing it. By default, the -     * Camera object is locked. Locking it again from the same process will -     * have no effect. Attempting to lock it from another process if it has -     * not been unlocked will fail. -     * Returns 0 if lock was successful. -     * -     * FIXME: Unhide after approval -     * @hide -     */ -    public native final int lock(); -     -    /** -     * Unlock the camera to allow aother process to access it. To save -     * setup/teardown time, a client of Camera can pass an initialized Camera -     * object to another process. This method is used to unlock the Camera -     * object before handing off the Camera object to the other process. - -     * Returns 0 if unlock was successful. -     * -     * FIXME: Unhide after approval -     * @hide -     */ -    public native final int unlock(); -     -    /** -     * Sets the SurfaceHolder to be used for a picture preview. If the surface -     * changed since the last call, the screen will blank. Nothing happens -     * if the same surface is re-set. -     *  -     * @param holder the SurfaceHolder upon which to place the picture preview -     * @throws IOException if the method fails. -     */ -    public final void setPreviewDisplay(SurfaceHolder holder) throws IOException { -        setPreviewDisplay(holder.getSurface()); -    } - -    private native final void setPreviewDisplay(Surface surface); - -    /** -     * Used to get a copy of each preview frame. -     */ -    public interface PreviewCallback -    { -        /** -         * The callback that delivers the preview frames. -         * -         * @param data The contents of the preview frame in getPreviewFormat() -         *             format. -         * @param camera The Camera service object. -         */ -        void onPreviewFrame(byte[] data, Camera camera); -    }; -     -    /** -     * Start drawing preview frames to the surface. -     */ -    public native final void startPreview(); -     -    /** -     * Stop drawing preview frames to the surface. -     */ -    public native final void stopPreview(); -     -    /** -     * Return current preview state. -     * -     * FIXME: Unhide before release -     * @hide -     */ -    public native final boolean previewEnabled(); -     -    /** -     * Can be called at any time to instruct the camera to use a callback for -     * each preview frame in addition to displaying it. -     * -     * @param cb A callback object that receives a copy of each preview frame. -     *           Pass null to stop receiving callbacks at any time. -     */ -    public final void setPreviewCallback(PreviewCallback cb) { -        mPreviewCallback = cb; -        mOneShot = false; -        setHasPreviewCallback(cb != null, false); -    } - -    /** -     * Installs a callback to retrieve a single preview frame, after which the -     * callback is cleared. -     * -     * @param cb A callback object that receives a copy of the preview frame. -     */ -    public final void setOneShotPreviewCallback(PreviewCallback cb) { -        if (cb != null) { -            mPreviewCallback = cb; -            mOneShot = true; -            setHasPreviewCallback(true, true); -        } -    } - -    private native final void setHasPreviewCallback(boolean installed, boolean oneshot); - -    private class EventHandler extends Handler -    { -        private Camera mCamera; - -        public EventHandler(Camera c, Looper looper) { -            super(looper); -            mCamera = c; -        } - -        @Override -        public void handleMessage(Message msg) { -            switch(msg.what) { -            case SHUTTER_CALLBACK: -                if (mShutterCallback != null) { -                    mShutterCallback.onShutter(); -                } -                return; -            case RAW_PICTURE_CALLBACK: -                if (mRawImageCallback != null) -                    mRawImageCallback.onPictureTaken((byte[])msg.obj, mCamera); -                return; - -            case JPEG_PICTURE_CALLBACK: -                if (mJpegCallback != null) -                    mJpegCallback.onPictureTaken((byte[])msg.obj, mCamera); -                return; -             -            case PREVIEW_CALLBACK: -                if (mPreviewCallback != null) { -                    mPreviewCallback.onPreviewFrame((byte[])msg.obj, mCamera); -                    if (mOneShot) { -                        mPreviewCallback = null; -                    } -                } -                return; - -            case AUTOFOCUS_CALLBACK: -                if (mAutoFocusCallback != null) -                    mAutoFocusCallback.onAutoFocus(msg.arg1 == 0 ? false : true, mCamera); -                return; - -            case ERROR_CALLBACK: -                Log.e(TAG, "Error " + msg.arg1); -                if (mErrorCallback != null) -                    mErrorCallback.onError(msg.arg1, mCamera); -                return; - -            default: -                Log.e(TAG, "Unknown message type " + msg.what); -                return; -            } -        } -    } - -    private static void postEventFromNative(Object camera_ref, -                                            int what, int arg1, int arg2, Object obj) -    { -        Camera c = (Camera)((WeakReference)camera_ref).get(); -        if (c == null) -            return; - -        if (c.mEventHandler != null) { -            Message m = c.mEventHandler.obtainMessage(what, arg1, arg2, obj); -            c.mEventHandler.sendMessage(m); -        } -    } - -    /** -     * Handles the callback for the camera auto focus. -     */ -    public interface AutoFocusCallback -    { -        /** -         * Callback for the camera auto focus. -         *  -         * @param success true if focus was successful, false if otherwise -         * @param camera  the Camera service object -         */ -        void onAutoFocus(boolean success, Camera camera); -    }; - -    /** -     * Starts auto-focus function and registers a callback function to -     * run when camera is focused. Only valid after startPreview() has -     * been called. -     *  -     * @param cb the callback to run -     */ -    public final void autoFocus(AutoFocusCallback cb) -    { -        mAutoFocusCallback = cb; -        native_autoFocus(); -    } -    private native final void native_autoFocus(); - -    /** -     * An interface which contains a callback for the shutter closing after taking a picture. -     */ -    public interface ShutterCallback -    { -        /** -         * Can be used to play a shutter sound as soon as the image has been captured, but before -         * the data is available. -         */ -        void onShutter(); -    } - -    /** -     * Handles the callback for when a picture is taken. -     */ -    public interface PictureCallback { -        /** -         * Callback for when a picture is taken. -         *  -         * @param data   a byte array of the picture data -         * @param camera the Camera service object -         */ -        void onPictureTaken(byte[] data, Camera camera); -    }; - -    /** -     * Triggers an asynchronous image capture. The camera service -     * will initiate a series of callbacks to the application as the -     * image capture progresses. The shutter callback occurs after -     * the image is captured. This can be used to trigger a sound -     * to let the user know that image has been captured. The raw -     * callback occurs when the raw image data is available. The jpeg -     * callback occurs when the compressed image is available. If the -     * application does not need a particular callback, a null can be -     * passed instead of a callback method. -     *  -     * @param shutter   callback after the image is captured, may be null -     * @param raw       callback with raw image data, may be null -     * @param jpeg      callback with jpeg image data, may be null -     */ -    public final void takePicture(ShutterCallback shutter, PictureCallback raw, -            PictureCallback jpeg) { -        mShutterCallback = shutter; -        mRawImageCallback = raw; -        mJpegCallback = jpeg; -        native_takePicture(); -    } -    private native final void native_takePicture(); - -    // These match the enum in libs/android_runtime/android_hardware_Camera.cpp -    /** Unspecified camerar error.  @see #ErrorCallback */ -    public static final int CAMERA_ERROR_UNKNOWN = 1; -    /** Media server died. In this case, the application must release the -     * Camera object and instantiate a new one. @see #ErrorCallback */ -    public static final int CAMERA_ERROR_SERVER_DIED = 100; -     -    /** -     * Handles the camera error callback. -     */ -    public interface ErrorCallback -    { -        /** -         * Callback for camera errors. -         * @param error   error code: -         * <ul> -         * <li>{@link #CAMERA_ERROR_UNKNOWN} -         * <li>{@link #CAMERA_ERROR_SERVER_DIED} -         * </ul> -         * @param camera  the Camera service object -         */ -        void onError(int error, Camera camera); -    }; - -    /** -     * Registers a callback to be invoked when an error occurs. -     * @param cb the callback to run -     */ -    public final void setErrorCallback(ErrorCallback cb) -    { -        mErrorCallback = cb; -    } -     -    private native final void native_setParameters(String params); -    private native final String native_getParameters(); - -    /** -     * Sets the Parameters for pictures from this Camera service. -     *  -     * @param params the Parameters to use for this Camera service -     */ -    public void setParameters(Parameters params) { -        Log.e(TAG, "setParameters()"); -        //params.dump(); -        native_setParameters(params.flatten()); -    } - -    /** -     * Returns the picture Parameters for this Camera service. -     */ -    public Parameters getParameters() { -        Parameters p = new Parameters(); -        String s = native_getParameters(); -        Log.e(TAG, "_getParameters: " + s); -        p.unflatten(s); -        return p; -    } - -    /** -     * Handles the picture size (dimensions). -     */ -    public class Size { -        /** -         * Sets the dimensions for pictures. -         *  -         * @param w the photo width (pixels) -         * @param h the photo height (pixels) -         */ -        public Size(int w, int h) { -            width = w; -            height = h; -        } -        /** width of the picture */ -        public int width; -        /** height of the picture */ -        public int height; -    }; - -    /** -     * Handles the parameters for pictures created by a Camera service. -     */ -    public class Parameters { -        private HashMap<String, String> mMap; - -        private Parameters() { -            mMap = new HashMap<String, String>(); -        } - -        /** -         * Writes the current Parameters to the log. -         * @hide -         * @deprecated -         */ -        public void dump() { -            Log.e(TAG, "dump: size=" + mMap.size()); -            for (String k : mMap.keySet()) { -                Log.e(TAG, "dump: " + k + "=" + mMap.get(k)); -            } -        } - -        /** -         * Creates a single string with all the parameters set in -         * this Parameters object. -         * <p>The {@link #unflatten(String)} method does the reverse.</p> -         *  -         * @return a String with all values from this Parameters object, in -         *         semi-colon delimited key-value pairs -         */ -        public String flatten() { -            StringBuilder flattened = new StringBuilder(); -            for (String k : mMap.keySet()) { -                flattened.append(k); -                flattened.append("="); -                flattened.append(mMap.get(k)); -                flattened.append(";"); -            } -            // chop off the extra semicolon at the end -            flattened.deleteCharAt(flattened.length()-1); -            return flattened.toString(); -        } - -        /** -         * Takes a flattened string of parameters and adds each one to  -         * this Parameters object. -         * <p>The {@link #flatten()} method does the reverse.</p> -         *  -         * @param flattened a String of parameters (key-value paired) that  -         *                  are semi-colon delimited -         */ -        public void unflatten(String flattened) { -            mMap.clear(); -             -            StringTokenizer tokenizer = new StringTokenizer(flattened, ";"); -            while (tokenizer.hasMoreElements()) { -                String kv = tokenizer.nextToken(); -                int pos = kv.indexOf('='); -                if (pos == -1) { -                    continue; -                } -                String k = kv.substring(0, pos); -                String v = kv.substring(pos + 1); -                mMap.put(k, v); -            } -        } -         -        public void remove(String key) { -            mMap.remove(key); -        } - -        /** -         * Sets a String parameter. -         *  -         * @param key   the key name for the parameter -         * @param value the String value of the parameter -         */ -        public void set(String key, String value) { -            if (key.indexOf('=') != -1 || key.indexOf(';') != -1) { -                Log.e(TAG, "Key \"" + key + "\" contains invalid character (= or ;)"); -                return; -            } -            if (value.indexOf('=') != -1 || value.indexOf(';') != -1) { -                Log.e(TAG, "Value \"" + value + "\" contains invalid character (= or ;)"); -                return; -            } - -            mMap.put(key, value); -        } - -        /** -         * Sets an integer parameter. -         *  -         * @param key   the key name for the parameter -         * @param value the int value of the parameter -         */ -        public void set(String key, int value) { -            mMap.put(key, Integer.toString(value)); -        } - -        /** -         * Returns the value of a String parameter. -         *  -         * @param key the key name for the parameter -         * @return the String value of the parameter -         */ -        public String get(String key) { -            return mMap.get(key); -        } - -        /** -         * Returns the value of an integer parameter. -         *  -         * @param key the key name for the parameter -         * @return the int value of the parameter -         */ -        public int getInt(String key) { -            return Integer.parseInt(mMap.get(key)); -        } - -        /** -         * Sets the dimensions for preview pictures. -         *  -         * @param width  the width of the pictures, in pixels -         * @param height the height of the pictures, in pixels -         */ -        public void setPreviewSize(int width, int height) { -            String v = Integer.toString(width) + "x" + Integer.toString(height); -            set("preview-size", v); -        } - -        /** -         * Returns the dimensions setting for preview pictures. -         *  -         * @return a Size object with the height and width setting  -         *          for the preview picture -         */ -        public Size getPreviewSize() { -            String pair = get("preview-size"); -            if (pair == null) -                return null; -            String[] dims = pair.split("x"); -            if (dims.length != 2) -                return null; - -            return new Size(Integer.parseInt(dims[0]), -                            Integer.parseInt(dims[1])); - -        } - -        /** -         * Sets the dimensions for EXIF thumbnails. -         *  -         * @param width  the width of the thumbnail, in pixels -         * @param height the height of the thumbnail, in pixels -         * -         * FIXME: unhide before release -         * @hide -         */ -        public void setThumbnailSize(int width, int height) { -            set("jpeg-thumbnail-width", width); -            set("jpeg-thumbnail-height", height); -        } - -        /** -         * Returns the dimensions for EXIF thumbnail -         *  -         * @return a Size object with the height and width setting  -         *          for the EXIF thumbnails -         * -         * FIXME: unhide before release -         * @hide -         */ -        public Size getThumbnailSize() { -            return new Size(getInt("jpeg-thumbnail-width"), -                            getInt("jpeg-thumbnail-height")); -        } - -        /** -         * Sets the quality of the EXIF thumbnail -         *  -         * @param quality the JPEG quality of the EXIT thumbnail -         * -         * FIXME: unhide before release -         * @hide -         */ -        public void setThumbnailQuality(int quality) { -            set("jpeg-thumbnail-quality", quality); -        } - -        /** -         * Returns the quality setting for the EXIF thumbnail -         *  -         * @return the JPEG quality setting of the EXIF thumbnail -         * -         * FIXME: unhide before release -         * @hide -         */ -        public int getThumbnailQuality() { -            return getInt("jpeg-thumbnail-quality"); -        } - -        /** -         * Sets the rate at which preview frames are received. -         *  -         * @param fps the frame rate (frames per second) -         */ -        public void setPreviewFrameRate(int fps) { -            set("preview-frame-rate", fps); -        } - -        /** -         * Returns the setting for the rate at which preview frames -         * are received. -         *  -         * @return the frame rate setting (frames per second) -         */ -        public int getPreviewFrameRate() { -            return getInt("preview-frame-rate"); -        } - -        /** -         * Sets the image format for preview pictures. -         *  -         * @param pixel_format the desired preview picture format  -         *                     (<var>PixelFormat.YCbCr_420_SP</var>, -         *                      <var>PixelFormat.RGB_565</var>, or -         *                      <var>PixelFormat.JPEG</var>) -         * @see android.graphics.PixelFormat -         */ -        public void setPreviewFormat(int pixel_format) { -            String s = cameraFormatForPixelFormat(pixel_format); -            if (s == null) { -                throw new IllegalArgumentException(); -            } - -            set("preview-format", s); -        } - -        /** -         * Returns the image format for preview pictures. -         *  -         * @return the PixelFormat int representing the preview picture format -         */ -        public int getPreviewFormat() { -            return pixelFormatForCameraFormat(get("preview-format")); -        } - -        /** -         * Sets the dimensions for pictures. -         *  -         * @param width  the width for pictures, in pixels -         * @param height the height for pictures, in pixels -         */ -        public void setPictureSize(int width, int height) { -            String v = Integer.toString(width) + "x" + Integer.toString(height); -            set("picture-size", v); -        } - -        /** -         * Returns the dimension setting for pictures. -         *  -         * @return a Size object with the height and width setting  -         *          for pictures -         */ -        public Size getPictureSize() { -            String pair = get("picture-size"); -            if (pair == null) -                return null; -            String[] dims = pair.split("x"); -            if (dims.length != 2) -                return null; - -            return new Size(Integer.parseInt(dims[0]), -                            Integer.parseInt(dims[1])); - -        } - -        /** -         * Sets the image format for pictures. -         *  -         * @param pixel_format the desired picture format  -         *                     (<var>PixelFormat.YCbCr_420_SP</var>, -         *                      <var>PixelFormat.RGB_565</var>, or -         *                      <var>PixelFormat.JPEG</var>) -         * @see android.graphics.PixelFormat -         */ -        public void setPictureFormat(int pixel_format) { -            String s = cameraFormatForPixelFormat(pixel_format); -            if (s == null) { -                throw new IllegalArgumentException(); -            } - -            set("picture-format", s); -        } - -        /** -         * Returns the image format for pictures. -         *  -         * @return the PixelFormat int representing the picture format -         */ -        public int getPictureFormat() { -            return pixelFormatForCameraFormat(get("picture-format")); -        } - -        private String cameraFormatForPixelFormat(int pixel_format) { -            switch(pixel_format) { -            case PixelFormat.YCbCr_422_SP: return "yuv422sp"; -            case PixelFormat.YCbCr_420_SP: return "yuv420sp"; -            case PixelFormat.RGB_565:      return "rgb565"; -            case PixelFormat.JPEG:         return "jpeg"; -            default:                       return null; -            } -        } - -        private int pixelFormatForCameraFormat(String format) { -            if (format == null) -                return PixelFormat.UNKNOWN; - -            if (format.equals("yuv422sp")) -                return PixelFormat.YCbCr_422_SP; - -            if (format.equals("yuv420sp")) -                return PixelFormat.YCbCr_420_SP; - -            if (format.equals("rgb565")) -                return PixelFormat.RGB_565; - -            if (format.equals("jpeg")) -                return PixelFormat.JPEG; - -            return PixelFormat.UNKNOWN; -        } - -    }; -} - - diff --git a/core/java/android/hardware/GeomagneticField.java b/core/java/android/hardware/GeomagneticField.java deleted file mode 100644 index b4c04b1..0000000 --- a/core/java/android/hardware/GeomagneticField.java +++ /dev/null @@ -1,409 +0,0 @@ -/* - * Copyright (C) 2009 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 java.util.GregorianCalendar; - -/** - * This class is used to estimated estimate magnetic field at a given point on - * Earth, and in particular, to compute the magnetic declination from true - * north. - * - * <p>This uses the World Magnetic Model produced by the United States National - * Geospatial-Intelligence Agency.  More details about the model can be found at - * <a href="http://www.ngdc.noaa.gov/geomag/WMM/DoDWMM.shtml">http://www.ngdc.noaa.gov/geomag/WMM/DoDWMM.shtml</a>. - * This class currently uses WMM-2005 which is valid until 2010, but should - * produce acceptable results for several years after that. - */ -public class GeomagneticField { -    // The magnetic field at a given point, in nonoteslas in geodetic -    // coordinates. -    private float mX; -    private float mY; -    private float mZ; - -    // Geocentric coordinates -- set by computeGeocentricCoordinates. -    private float mGcLatitudeRad; -    private float mGcLongitudeRad; -    private float mGcRadiusKm; - -    // Constants from WGS84 (the coordinate system used by GPS) -    static private final float EARTH_SEMI_MAJOR_AXIS_KM = 6378.137f; -    static private final float EARTH_SEMI_MINOR_AXIS_KM = 6356.7523f; -    static private final float EARTH_REFERENCE_RADIUS_KM = 6371.2f; - -    // These coefficients and the formulae used below are from: -    // NOAA Technical Report: The US/UK World Magnetic Model for 2005-2010 -    static private final float[][] G_COEFF = new float[][] { -        { 0f }, -        { -29556.8f, -1671.7f }, -        { -2340.6f, 3046.9f, 1657.0f }, -        { 1335.4f, -2305.1f, 1246.7f, 674.0f }, -        { 919.8f, 798.1f, 211.3f, -379.4f, 100.0f }, -        { -227.4f, 354.6f, 208.7f, -136.5f, -168.3f, -14.1f }, -        { 73.2f, 69.7f, 76.7f, -151.2f, -14.9f, 14.6f, -86.3f }, -        { 80.1f, -74.5f, -1.4f, 38.5f, 12.4f, 9.5f, 5.7f, 1.8f }, -        { 24.9f, 7.7f, -11.6f, -6.9f, -18.2f, 10.0f, 9.2f, -11.6f, -5.2f }, -        { 5.6f, 9.9f, 3.5f, -7.0f, 5.1f, -10.8f, -1.3f, 8.8f, -6.7f, -9.1f }, -        { -2.3f, -6.3f, 1.6f, -2.6f, 0.0f, 3.1f, 0.4f, 2.1f, 3.9f, -0.1f, -2.3f }, -        { 2.8f, -1.6f, -1.7f, 1.7f, -0.1f, 0.1f, -0.7f, 0.7f, 1.8f, 0.0f, 1.1f, 4.1f }, -        { -2.4f, -0.4f, 0.2f, 0.8f, -0.3f, 1.1f, -0.5f, 0.4f, -0.3f, -0.3f, -0.1f, -          -0.3f, -0.1f } }; - -    static private final float[][] H_COEFF = new float[][] { -        { 0f }, -        { 0.0f, 5079.8f }, -        { 0.0f, -2594.7f, -516.7f }, -        { 0.0f, -199.9f, 269.3f, -524.2f }, -        { 0.0f, 281.5f, -226.0f, 145.8f, -304.7f }, -        { 0.0f, 42.4f, 179.8f, -123.0f, -19.5f, 103.6f }, -        { 0.0f, -20.3f, 54.7f, 63.6f, -63.4f, -0.1f, 50.4f }, -        { 0.0f, -61.5f, -22.4f, 7.2f, 25.4f, 11.0f, -26.4f, -5.1f }, -        { 0.0f, 11.2f, -21.0f, 9.6f, -19.8f, 16.1f, 7.7f, -12.9f, -0.2f }, -        { 0.0f, -20.1f, 12.9f, 12.6f, -6.7f, -8.1f, 8.0f, 2.9f, -7.9f, 6.0f }, -        { 0.0f, 2.4f, 0.2f, 4.4f, 4.8f, -6.5f, -1.1f, -3.4f, -0.8f, -2.3f, -7.9f }, -        { 0.0f, 0.3f, 1.2f, -0.8f, -2.5f, 0.9f, -0.6f, -2.7f, -0.9f, -1.3f, -2.0f, -1.2f }, -        { 0.0f, -0.4f, 0.3f, 2.4f, -2.6f, 0.6f, 0.3f, 0.0f, 0.0f, 0.3f, -0.9f, -0.4f, -          0.8f } }; - -    static private final float[][] DELTA_G = new float[][] { -        { 0f }, -        { 8.0f, 10.6f }, -        { -15.1f, -7.8f, -0.8f }, -        { 0.4f, -2.6f, -1.2f, -6.5f }, -        { -2.5f, 2.8f, -7.0f, 6.2f, -3.8f }, -        { -2.8f, 0.7f, -3.2f, -1.1f, 0.1f, -0.8f }, -        { -0.7f, 0.4f, -0.3f, 2.3f, -2.1f, -0.6f, 1.4f }, -        { 0.2f, -0.1f, -0.3f, 1.1f, 0.6f, 0.5f, -0.4f, 0.6f }, -        { 0.1f, 0.3f, -0.4f, 0.3f, -0.3f, 0.2f, 0.4f, -0.7f, 0.4f }, -        { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f }, -        { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f }, -        { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f }, -        { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f } }; - -    static private final float[][] DELTA_H = new float[][] { -        { 0f }, -        { 0.0f, -20.9f }, -        { 0.0f, -23.2f, -14.6f }, -        { 0.0f, 5.0f, -7.0f, -0.6f }, -        { 0.0f, 2.2f, 1.6f, 5.8f, 0.1f }, -        { 0.0f, 0.0f, 1.7f, 2.1f, 4.8f, -1.1f }, -        { 0.0f, -0.6f, -1.9f, -0.4f, -0.5f, -0.3f, 0.7f }, -        { 0.0f, 0.6f, 0.4f, 0.2f, 0.3f, -0.8f, -0.2f, 0.1f }, -        { 0.0f, -0.2f, 0.1f, 0.3f, 0.4f, 0.1f, -0.2f, 0.4f, 0.4f }, -        { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f }, -        { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f }, -        { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f }, -        { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f } }; - -    static private final long BASE_TIME = -        new GregorianCalendar(2005, 1, 1).getTimeInMillis(); - -    // The ratio between the Gauss-normalized associated Legendre functions and -    // the Schmid quasi-normalized ones. Compute these once staticly since they -    // don't depend on input variables at all. -    static private final float[][] SCHMIDT_QUASI_NORM_FACTORS = -        computeSchmidtQuasiNormFactors(G_COEFF.length); - -    /** -     * Estimate the magnetic field at a given point and time. -     * -     * @param gdLatitudeDeg -     *            Latitude in WGS84 geodetic coordinates -- positive is east. -     * @param gdLongitudeDeg -     *            Longitude in WGS84 geodetic coordinates -- positive is north. -     * @param altitudeMeters -     *            Altitude in WGS84 geodetic coordinates, in meters. -     * @param timeMillis -     *            Time at which to evaluate the declination, in milliseconds -     *            since January 1, 1970. (approximate is fine -- the declination -     *            changes very slowly). -     */ -    public GeomagneticField(float gdLatitudeDeg, -                            float gdLongitudeDeg, -                            float altitudeMeters, -                            long timeMillis) { -        final int MAX_N = G_COEFF.length; // Maximum degree of the coefficients. - -        // We don't handle the north and south poles correctly -- pretend that -        // we're not quite at them to avoid crashing. -        gdLatitudeDeg = Math.min(90.0f - 1e-5f, -                                 Math.max(-90.0f + 1e-5f, gdLatitudeDeg)); -        computeGeocentricCoordinates(gdLatitudeDeg, -                                     gdLongitudeDeg, -                                     altitudeMeters); - -        assert G_COEFF.length == H_COEFF.length; - -        // Note: LegendreTable computes associated Legendre functions for -        // cos(theta).  We want the associated Legendre functions for -        // sin(latitude), which is the same as cos(PI/2 - latitude), except the -        // derivate will be negated. -        LegendreTable legendre = -            new LegendreTable(MAX_N - 1, -                              (float) (Math.PI / 2.0 - mGcLatitudeRad)); - -        // Compute a table of (EARTH_REFERENCE_RADIUS_KM / radius)^n for i in -        // 0..MAX_N-2 (this is much faster than calling Math.pow MAX_N+1 times). -        float[] relativeRadiusPower = new float[MAX_N + 2]; -        relativeRadiusPower[0] = 1.0f; -        relativeRadiusPower[1] = EARTH_REFERENCE_RADIUS_KM / mGcRadiusKm; -        for (int i = 2; i < relativeRadiusPower.length; ++i) { -            relativeRadiusPower[i] = relativeRadiusPower[i - 1] * -                relativeRadiusPower[1]; -        } - -        // Compute tables of sin(lon * m) and cos(lon * m) for m = 0..MAX_N -- -        // this is much faster than calling Math.sin and Math.com MAX_N+1 times. -        float[] sinMLon = new float[MAX_N]; -        float[] cosMLon = new float[MAX_N]; -        sinMLon[0] = 0.0f; -        cosMLon[0] = 1.0f; -        sinMLon[1] = (float) Math.sin(mGcLongitudeRad); -        cosMLon[1] = (float) Math.cos(mGcLongitudeRad); - -        for (int m = 2; m < MAX_N; ++m) { -            // Standard expansions for sin((m-x)*theta + x*theta) and -            // cos((m-x)*theta + x*theta). -            int x = m >> 1; -            sinMLon[m] = sinMLon[m-x] * cosMLon[x] + cosMLon[m-x] * sinMLon[x]; -            cosMLon[m] = cosMLon[m-x] * cosMLon[x] - sinMLon[m-x] * sinMLon[x]; -        } - -        float inverseCosLatitude = 1.0f / (float) Math.cos(mGcLatitudeRad); -        float yearsSinceBase = -            (timeMillis - BASE_TIME) / (365f * 24f * 60f * 60f * 1000f); - -        // We now compute the magnetic field strength given the geocentric -        // location. The magnetic field is the derivative of the potential -        // function defined by the model. See NOAA Technical Report: The US/UK -        // World Magnetic Model for 2005-2010 for the derivation. -        float gcX = 0.0f;  // Geocentric northwards component. -        float gcY = 0.0f;  // Geocentric eastwards component. -        float gcZ = 0.0f;  // Geocentric downwards component. - -        for (int n = 1; n < MAX_N; n++) { -            for (int m = 0; m <= n; m++) { -                // Adjust the coefficients for the current date. -                float g = G_COEFF[n][m] + yearsSinceBase * DELTA_G[n][m]; -                float h = H_COEFF[n][m] + yearsSinceBase * DELTA_H[n][m]; - -                // Negative derivative with respect to latitude, divided by -                // radius.  This looks like the negation of the version in the -                // NOAA Techincal report because that report used -                // P_n^m(sin(theta)) and we use P_n^m(cos(90 - theta)), so the -                // derivative with respect to theta is negated. -                gcX += relativeRadiusPower[n+2] -                    * (g * cosMLon[m] + h * sinMLon[m]) -                    * legendre.mPDeriv[n][m] -                    * SCHMIDT_QUASI_NORM_FACTORS[n][m]; - -                // Negative derivative with respect to longitude, divided by -                // radius. -                gcY += relativeRadiusPower[n+2] * m -                    * (g * sinMLon[m] - h * cosMLon[m]) -                    * legendre.mP[n][m] -                    * SCHMIDT_QUASI_NORM_FACTORS[n][m] -                    * inverseCosLatitude; - -                // Negative derivative with respect to radius. -                gcZ -= (n + 1) * relativeRadiusPower[n+2] -                    * (g * cosMLon[m] + h * sinMLon[m]) -                    * legendre.mP[n][m] -                    * SCHMIDT_QUASI_NORM_FACTORS[n][m]; -            } -        } - -        // Convert back to geodetic coordinates.  This is basically just a -        // rotation around the Y-axis by the difference in latitudes between the -        // geocentric frame and the geodetic frame. -        double latDiffRad = Math.toRadians(gdLatitudeDeg) - mGcLatitudeRad; -        mX = (float) (gcX * Math.cos(latDiffRad) -                      + gcZ * Math.sin(latDiffRad)); -        mY = gcY; -        mZ = (float) (- gcX * Math.sin(latDiffRad) -                      + gcZ * Math.cos(latDiffRad)); -    } - -    /** -     * @return The X (northward) component of the magnetic field in nanoteslas. -     */ -    public float getX() { -        return mX; -    } - -    /** -     * @return The Y (eastward) component of the magnetic field in nanoteslas. -     */ -    public float getY() { -        return mY; -    } - -    /** -     * @return The Z (downward) component of the magnetic field in nanoteslas. -     */ -    public float getZ() { -        return mZ; -    } - -    /** -     * @return The declination of the horizontal component of the magnetic -     *         field from true north, in degrees (i.e. positive means the -     *         magnetic field is rotated east that much from true north). -     */ -    public float getDeclination() { -        return (float) Math.toDegrees(Math.atan2(mY, mX)); -    } - -    /** -     * @return The inclination of the magnetic field in degrees -- positive -     *         means the magnetic field is rotated downwards. -     */ -    public float getInclination() { -        return (float) Math.toDegrees(Math.atan2(mZ, -                                                 getHorizontalStrength())); -    } - -    /** -     * @return  Horizontal component of the field strength in nonoteslas. -     */ -    public float getHorizontalStrength() { -        return (float) Math.sqrt(mX * mX + mY * mY); -    } - -    /** -     * @return  Total field strength in nanoteslas. -     */ -    public float getFieldStrength() { -        return (float) Math.sqrt(mX * mX + mY * mY + mZ * mZ); -    } - -    /** -     * @param gdLatitudeDeg -     *            Latitude in WGS84 geodetic coordinates. -     * @param gdLongitudeDeg -     *            Longitude in WGS84 geodetic coordinates. -     * @param altitudeMeters -     *            Altitude above sea level in WGS84 geodetic coordinates. -     * @return Geocentric latitude (i.e. angle between closest point on the -     *         equator and this point, at the center of the earth. -     */ -    private void computeGeocentricCoordinates(float gdLatitudeDeg, -                                              float gdLongitudeDeg, -                                              float altitudeMeters) { -        float altitudeKm = altitudeMeters / 1000.0f; -        float a2 = EARTH_SEMI_MAJOR_AXIS_KM * EARTH_SEMI_MAJOR_AXIS_KM; -        float b2 = EARTH_SEMI_MINOR_AXIS_KM * EARTH_SEMI_MINOR_AXIS_KM; -        double gdLatRad = Math.toRadians(gdLatitudeDeg); -        float clat = (float) Math.cos(gdLatRad); -        float slat = (float) Math.sin(gdLatRad); -        float tlat = slat / clat; -        float latRad = -            (float) Math.sqrt(a2 * clat * clat + b2 * slat * slat); - -        mGcLatitudeRad = (float) Math.atan(tlat * (latRad * altitudeKm + b2) -                                           / (latRad * altitudeKm + a2)); - -        mGcLongitudeRad = (float) Math.toRadians(gdLongitudeDeg); - -        float radSq = altitudeKm * altitudeKm -            + 2 * altitudeKm * (float) Math.sqrt(a2 * clat * clat + -                                                 b2 * slat * slat) -            + (a2 * a2 * clat * clat + b2 * b2 * slat * slat) -            / (a2 * clat * clat + b2 * slat * slat); -        mGcRadiusKm = (float) Math.sqrt(radSq); -    } - - -    /** -     * Utility class to compute a table of Gauss-normalized associated Legendre -     * functions P_n^m(cos(theta)) -     */ -    static private class LegendreTable { -        // These are the Gauss-normalized associated Legendre functions -- that -        // is, they are normal Legendre functions multiplied by -        // (n-m)!/(2n-1)!! (where (2n-1)!! = 1*3*5*...*2n-1) -        public final float[][] mP; - -        // Derivative of mP, with respect to theta. -        public final float[][] mPDeriv; - -        /** -         * @param maxN -         *            The maximum n- and m-values to support -         * @param thetaRad -         *            Returned functions will be Gauss-normalized -         *            P_n^m(cos(thetaRad)), with thetaRad in radians. -         */ -        public LegendreTable(int maxN, float thetaRad) { -            // Compute the table of Gauss-normalized associated Legendre -            // functions using standard recursion relations. Also compute the -            // table of derivatives using the derivative of the recursion -            // relations. -            float cos = (float) Math.cos(thetaRad); -            float sin = (float) Math.sin(thetaRad); - -            mP = new float[maxN + 1][]; -            mPDeriv = new float[maxN + 1][]; -            mP[0] = new float[] { 1.0f }; -            mPDeriv[0] = new float[] { 0.0f }; -            for (int n = 1; n <= maxN; n++) { -            	mP[n] = new float[n + 1]; -                mPDeriv[n] = new float[n + 1]; -                for (int m = 0; m <= n; m++) { -                    if (n == m) { -                        mP[n][m] = sin * mP[n - 1][m - 1]; -                        mPDeriv[n][m] = cos * mP[n - 1][m - 1] -                            + sin * mPDeriv[n - 1][m - 1]; -                    } else if (n == 1 || m == n - 1) { -                        mP[n][m] = cos * mP[n - 1][m]; -                        mPDeriv[n][m] = -sin * mP[n - 1][m] -                            + cos * mPDeriv[n - 1][m]; -                    } else { -                        assert n > 1 && m < n - 1; -                        float k = ((n - 1) * (n - 1) - m * m) -                            / (float) ((2 * n - 1) * (2 * n - 3)); -                        mP[n][m] = cos * mP[n - 1][m] - k * mP[n - 2][m]; -                        mPDeriv[n][m] = -sin * mP[n - 1][m] -                            + cos * mPDeriv[n - 1][m] - k * mPDeriv[n - 2][m]; -                    } -                } -            } -        } -    } - -    /** -     * Compute the ration between the Gauss-normalized associated Legendre -     * functions and the Schmidt quasi-normalized version. This is equivalent to -     * sqrt((m==0?1:2)*(n-m)!/(n+m!))*(2n-1)!!/(n-m)! -     */ -    private static float[][] computeSchmidtQuasiNormFactors(int maxN) { -        float[][] schmidtQuasiNorm = new float[maxN + 1][]; -        schmidtQuasiNorm[0] = new float[] { 1.0f }; -        for (int n = 1; n <= maxN; n++) { -            schmidtQuasiNorm[n] = new float[n + 1]; -            schmidtQuasiNorm[n][0] = -                schmidtQuasiNorm[n - 1][0] * (2 * n - 1) / (float) n; -            for (int m = 1; m <= n; m++) { -                schmidtQuasiNorm[n][m] = schmidtQuasiNorm[n][m - 1] -                    * (float) Math.sqrt((n - m + 1) * (m == 1 ? 2 : 1) -                                / (float) (n + m)); -            } -        } -        return schmidtQuasiNorm; -    } -}
\ No newline at end of file diff --git a/core/java/android/hardware/ISensorService.aidl b/core/java/android/hardware/ISensorService.aidl deleted file mode 100644 index 04af2ae..0000000 --- a/core/java/android/hardware/ISensorService.aidl +++ /dev/null @@ -1,29 +0,0 @@ -/* //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.ParcelFileDescriptor; - -/** - * {@hide} - */ -interface ISensorService -{ -    ParcelFileDescriptor getDataChanel(); -    boolean enableSensor(IBinder listener, String name, int sensor, int enable); -} diff --git a/core/java/android/hardware/Sensor.java b/core/java/android/hardware/Sensor.java deleted file mode 100644 index 0ce2f7b..0000000 --- a/core/java/android/hardware/Sensor.java +++ /dev/null @@ -1,146 +0,0 @@ -/* - * Copyright (C) 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; - -/**  - * Class representing a sensor. Use {@link SensorManager#getSensorList} - * to get the list of available Sensors. - */ -public class Sensor { - -    /**  -     * A constant describing an accelerometer sensor type. -     * See {@link android.hardware.SensorEvent SensorEvent} -     * for more details. -     */ -    public static final int TYPE_ACCELEROMETER  = 1; - -    /**  -     * A constant describing a magnetic field sensor type. -     * See {@link android.hardware.SensorEvent SensorEvent} -     * for more details. -     */ -    public static final int TYPE_MAGNETIC_FIELD = 2; -     -    /**  -     * A constant describing an orientation sensor type. -     * See {@link android.hardware.SensorEvent SensorEvent} -     * for more details. -     */ -    public static final int TYPE_ORIENTATION    = 3; - -    /** A constant describing a gyroscope sensor type */ -    public static final int TYPE_GYROSCOPE      = 4; -    /** A constant describing a light sensor type */ -    public static final int TYPE_LIGHT          = 5; -    /** A constant describing a pressure sensor type */ -    public static final int TYPE_PRESSURE       = 6; -    /** A constant describing a temperature sensor type */ -    public static final int TYPE_TEMPERATURE    = 7; -    /** A constant describing a proximity sensor type */ -    public static final int TYPE_PROXIMITY      = 8; - -     -    /**  -     * A constant describing all sensor types. -     */ -    public static final int TYPE_ALL             = -1; - -    /* Some of these fields are set only by the native bindings in  -     * SensorManager. -     */ -    private String  mName; -    private String  mVendor; -    private int     mVersion; -    private int     mHandle; -    private int     mType; -    private float   mMaxRange; -    private float   mResolution; -    private float   mPower; -    private int     mLegacyType; -     -     -    Sensor() { -    } - -    /** -     * @return name string of the sensor. -     */ -    public String getName() { -        return mName; -    } - -    /** -     * @return vendor string of this sensor. -     */ -    public String getVendor() { -        return mVendor; -    } -     -    /** -     * @return generic type of this sensor. -     */ -    public int getType() { -        return mType; -    } -     -    /** -     * @return version of the sensor's module. -     */ -    public int getVersion() { -        return mVersion; -    } -     -    /** -     * @return maximum range of the sensor in the sensor's unit. -     */ -    public float getMaximumRange() { -        return mMaxRange; -    } -     -    /** -     * @return resolution of the sensor in the sensor's unit. -     */ -    public float getResolution() { -        return mResolution; -    } -     -    /** -     * @return the power in mA used by this sensor while in use -     */ -    public float getPower() { -        return mPower; -    } -     -    int getHandle() { -        return mHandle; -    } -     -    void setRange(float max, float res) { -        mMaxRange = max; -        mResolution = res; -    } -     -    void setLegacyType(int legacyType) { -        mLegacyType = legacyType; -    } - -    int getLegacyType() { -        return mLegacyType; -    } -} diff --git a/core/java/android/hardware/SensorEvent.java b/core/java/android/hardware/SensorEvent.java deleted file mode 100644 index cf939c5..0000000 --- a/core/java/android/hardware/SensorEvent.java +++ /dev/null @@ -1,146 +0,0 @@ -/* - * Copyright (C) 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; - -/** - * This class represents a sensor event and holds informations such as the - * sensor type (eg: accelerometer, orientation, etc...), the time-stamp,  - * accuracy and of course the sensor's {@link SensorEvent#values data}. - * - * <p><u>Definition of the coordinate system used by the SensorEvent API.</u><p> - *  - * <pre> - * The coordinate space is defined relative to the screen of the phone  - * in its default orientation. The axes are not swapped when the device's - * screen orientation changes. - *  - * The OpenGL ES coordinate system is used. The origin is in the - * lower-left corner  with respect to the screen, with the X axis horizontal - * and pointing  right, the Y axis vertical and pointing up and the Z axis - * pointing outside the front face of the screen. In this system, coordinates - * behind the screen have negative Z values. - *  - * <b>Note:</b> This coordinate system is different from the one used in the - * Android 2D APIs where the origin is in the top-left corner.  - * - *   x<0         x>0 - *                ^ - *                | - *    +-----------+-->  y>0 - *    |           | - *    |           | - *    |           | - *    |           |   / z<0 - *    |           |  / - *    |           | / - *    O-----------+/ - *    |[]  [ ]  []/ - *    +----------/+     y<0 - *              / - *             / - *           |/ z>0 (toward the sky) - * - *    O: Origin (x=0,y=0,z=0) - * </pre> - */ - -public class SensorEvent { -    /** -     * The length and contents of the values array vary depending on which -     * sensor type is being monitored (see also {@link SensorEvent} for a  -     * definition of the coordinate system used): -     *  -     * <p>{@link android.hardware.Sensor#TYPE_ORIENTATION Sensor.TYPE_ORIENTATION}:<p> -     *  All values are angles in degrees. -     *  -     * <p>values[0]: Azimuth, angle between the magnetic north direction and -     * the Y axis, around the Z axis (0 to 359).  -     * 0=North, 90=East, 180=South, 270=West -     *  -     * <p>values[1]: Pitch, rotation around X axis (-180 to 180),  -     * with positive values when the z-axis moves <b>toward</b> the y-axis. -     * -     * <p>values[2]: Roll, rotation around Y axis (-90 to 90), with  -     * positive values  when the x-axis moves <b>away</b> from the z-axis. -     *  -     * <p><b>Note:</b> This definition is different from <b>yaw, pitch and  -     * roll</b> used in aviation where the X axis is along the long side of -     * the plane (tail to nose). -     *  -     * <p><b>Note:</b> It is preferable to use  -     * {@link android.hardware.SensorManager#getRotationMatrix  -     *      getRotationMatrix()} in conjunction with -     * {@link android.hardware.SensorManager#remapCoordinateSystem  -     *      remapCoordinateSystem()} and -     * {@link android.hardware.SensorManager#getOrientation getOrientation()} -     * to compute these values; while it may be more expensive, it is usually  -     * more accurate. -     * -     * <p>{@link android.hardware.Sensor#TYPE_ACCELEROMETER Sensor.TYPE_ACCELEROMETER}:<p> -     *  All values are in SI units (m/s^2) and measure the acceleration applied -     *  to the phone minus the force of gravity. -     *   -     *  <p>values[0]: Acceleration minus Gx on the x-axis  -     *  <p>values[1]: Acceleration minus Gy on the y-axis  -     *  <p>values[2]: Acceleration minus Gz on the z-axis -     *   -     *  <p><u>Examples</u>: -     *    <li>When the device lies flat on a table and is pushed on its left  -     *    side toward the right, the x acceleration value is positive.</li> -     *     -     *    <li>When the device lies flat on a table, the acceleration value is  -     *    +9.81, which correspond to the acceleration of the device (0 m/s^2)  -     *    minus the force of gravity (-9.81 m/s^2).</li> -     *     -     *    <li>When the device lies flat on a table and is pushed toward the sky -     *    with an acceleration of A m/s^2, the acceleration value is equal to  -     *    A+9.81 which correspond to the acceleration of the  -     *    device (+A m/s^2) minus the force of gravity (-9.81 m/s^2).</li> -     *  -     *  -     * <p>{@link android.hardware.Sensor#TYPE_MAGNETIC_FIELD Sensor.TYPE_MAGNETIC_FIELD}:<p> -     *  All values are in micro-Tesla (uT) and measure the ambient magnetic -     *  field in the X, Y and Z axis. -     *   -     */     -    public final float[] values; - -    /** -     * The sensor that generated this event. -     * See {@link android.hardware.SensorManager SensorManager} -     * for details. -     */ -    public Sensor sensor; -     -    /** -     * The accuracy of this event. -     * See {@link android.hardware.SensorManager SensorManager} -     * for details. -     */ -    public int accuracy; -     -     -    /** -     * The time in nanosecond at which the event happened -     */ -    public long timestamp; - -     -    SensorEvent(int size) { -        values = new float[size]; -    } -} diff --git a/core/java/android/hardware/SensorEventListener.java b/core/java/android/hardware/SensorEventListener.java deleted file mode 100644 index 716d0d4..0000000 --- a/core/java/android/hardware/SensorEventListener.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (C) 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; - -/** - * Used for receiving notifications from the SensorManager when - * sensor values have changed. - */ -public interface SensorEventListener { - -    /** -     * Called when sensor values have changed. -     * <p>See {@link android.hardware.SensorManager SensorManager} -     * for details on possible sensor types. -     * <p>See also {@link android.hardware.SensorEvent SensorEvent}. -     *  -     * <p><b>NOTE:</b> The application doesn't own the -     * {@link android.hardware.SensorEvent event} -     * object passed as a parameter and therefore cannot hold on o it. -     * The object may be part of an internal pool and may be reused by -     * the framework. -     * -     * @param event the {@link android.hardware.SensorEvent SensorEvent}.  -     */ -    public void onSensorChanged(SensorEvent event); - -    /** -     * Called when the accuracy of a sensor has changed. -     * <p>See {@link android.hardware.SensorManager SensorManager} -     * for details. -     * -     * @param accuracy The new accuracy of this sensor -     */ -    public void onAccuracyChanged(Sensor sensor, int accuracy);     -} diff --git a/core/java/android/hardware/SensorListener.java b/core/java/android/hardware/SensorListener.java deleted file mode 100644 index cfa184b..0000000 --- a/core/java/android/hardware/SensorListener.java +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Copyright (C) 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; - -/** - * Used for receiving notifications from the SensorManager when - * sensor values have changed. - *  - * This interface is deprecated, use  - * {@link android.hardware.SensorEventListener SensorEventListener} instead. - *  - */ -@Deprecated -public interface SensorListener { - -    /** -     * <p>Called when sensor values have changed. -     * The length and contents of the values array vary -     * depending on which sensor is being monitored. -     * See {@link android.hardware.SensorManager SensorManager} -     * for details on possible sensor types. -     * -     * <p><u>Definition of the coordinate system used below.</u><p> -     * <p>The X axis refers to the screen's horizontal axis -     * (the small edge in portrait mode, the long edge in landscape mode) and -     * points to the right.  -     * <p>The Y axis refers to the screen's vertical axis and points towards -     * the top of the screen (the origin is in the lower-left corner). -     * <p>The Z axis points toward the sky when the device is lying on its back -     * on a table. -     * <p> <b>IMPORTANT NOTE:</b> The axis <b><u>are swapped</u></b> when the -     * device's screen orientation changes. To access the unswapped values, -     * use indices 3, 4 and 5 in values[]. -     *  -     * <p>{@link android.hardware.SensorManager#SENSOR_ORIENTATION SENSOR_ORIENTATION}, -     * {@link android.hardware.SensorManager#SENSOR_ORIENTATION_RAW SENSOR_ORIENTATION_RAW}:<p> -     *  All values are angles in degrees. -     *  -     * <p>values[0]: Azimuth, rotation around the Z axis (0<=azimuth<360). -     * 0 = North, 90 = East, 180 = South, 270 = West -     *  -     * <p>values[1]: Pitch, rotation around X axis (-180<=pitch<=180), with positive -     * values when the z-axis moves toward the y-axis. -     * -     * <p>values[2]: Roll, rotation around Y axis (-90<=roll<=90), with positive values  -     * when the z-axis moves toward the x-axis. -     * -     * <p>Note that this definition of yaw, pitch and roll is different from the -     * traditional definition used in aviation where the X axis is along the long -     * side of the plane (tail to nose). -     * -     * <p>{@link android.hardware.SensorManager#SENSOR_ACCELEROMETER SENSOR_ACCELEROMETER}:<p> -     *  All values are in SI units (m/s^2) and measure contact forces. -     *   -     *  <p>values[0]: force applied by the device on the x-axis  -     *  <p>values[1]: force applied by the device on the y-axis  -     *  <p>values[2]: force applied by the device on the z-axis -     *   -     *  <p><u>Examples</u>: -     *    <li>When the device is pushed on its left side toward the right, the -     *    x acceleration value is negative (the device applies a reaction force -     *    to the push toward the left)</li> -     *     -     *    <li>When the device lies flat on a table, the acceleration value is  -     *    {@link android.hardware.SensorManager#STANDARD_GRAVITY -STANDARD_GRAVITY}, -     *    which correspond to the force the device applies on the table in reaction -     *    to gravity.</li> -     * -     * <p>{@link android.hardware.SensorManager#SENSOR_MAGNETIC_FIELD SENSOR_MAGNETIC_FIELD}:<p> -     *  All values are in micro-Tesla (uT) and measure the ambient magnetic -     *  field in the X, Y and -Z axis. -     *  <p><b><u>Note:</u></b> the magnetic field's Z axis is inverted. -     *   -     * @param sensor The ID of the sensor being monitored -     * @param values The new values for the sensor. -     */ -    public void onSensorChanged(int sensor, float[] values); - -    /** -     * Called when the accuracy of a sensor has changed. -     * See {@link android.hardware.SensorManager SensorManager} -     * for details. -     * -     * @param sensor The ID of the sensor being monitored -     * @param accuracy The new accuracy of this sensor. -     */ -    public void onAccuracyChanged(int sensor, int accuracy);     -} diff --git a/core/java/android/hardware/SensorManager.java b/core/java/android/hardware/SensorManager.java deleted file mode 100644 index e232c2c..0000000 --- a/core/java/android/hardware/SensorManager.java +++ /dev/null @@ -1,1462 +0,0 @@ -/* - * Copyright (C) 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.content.Context; -import android.os.Binder; -import android.os.Looper; -import android.os.ParcelFileDescriptor; -import android.os.Process; -import android.os.RemoteException; -import android.os.Handler; -import android.os.Message; -import android.os.ServiceManager; -import android.util.Log; -import android.util.SparseArray; -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; -import java.util.List; - -/** - * Class that lets you access the device's sensors. Get an instance of this - * class by calling {@link android.content.Context#getSystemService(java.lang.String) - * Context.getSystemService()} with an argument of {@link android.content.Context#SENSOR_SERVICE}. - */ -public class SensorManager extends IRotationWatcher.Stub -{ -    private static final String TAG = "SensorManager"; -    private static final float[] mTempMatrix = new float[16]; - -    /* NOTE: sensor IDs must be a power of 2 */ - -    /** -     * A constant describing an orientation sensor. -     * See {@link android.hardware.SensorListener SensorListener} for more details. -     * @deprecated use {@link android.hardware.Sensor Sensor} instead. -     */ -    @Deprecated -    public static final int SENSOR_ORIENTATION = 1 << 0; - -    /** -     * A constant describing an accelerometer. -     * See {@link android.hardware.SensorListener SensorListener} for more details. -     * @deprecated use {@link android.hardware.Sensor Sensor} instead. -     */ -    @Deprecated -    public static final int SENSOR_ACCELEROMETER = 1 << 1; - -    /** -     * A constant describing a temperature sensor -     * See {@link android.hardware.SensorListener SensorListener} for more details. -     * @deprecated use {@link android.hardware.Sensor Sensor} instead. -     */ -    @Deprecated -    public static final int SENSOR_TEMPERATURE = 1 << 2; - -    /** -     * A constant describing a magnetic sensor -     * See {@link android.hardware.SensorListener SensorListener} for more details. -     * @deprecated use {@link android.hardware.Sensor Sensor} instead. -     */ -    @Deprecated -    public static final int SENSOR_MAGNETIC_FIELD = 1 << 3; - -    /** -     * A constant describing an ambient light sensor -     * See {@link android.hardware.SensorListener SensorListener} for more details. -     * @deprecated use {@link android.hardware.Sensor Sensor} instead. -     */ -    @Deprecated -    public static final int SENSOR_LIGHT = 1 << 4; - -    /** -     * A constant describing a proximity sensor -     * See {@link android.hardware.SensorListener SensorListener} for more details. -     * @deprecated use {@link android.hardware.Sensor Sensor} instead. -     */ -    @Deprecated -    public static final int SENSOR_PROXIMITY = 1 << 5; - -    /** -     * A constant describing a Tricorder -     * See {@link android.hardware.SensorListener SensorListener} for more details. -     * @deprecated use {@link android.hardware.Sensor Sensor} instead. -     */ -    @Deprecated -    public static final int SENSOR_TRICORDER = 1 << 6; - -    /** -     * A constant describing an orientation sensor. -     * See {@link android.hardware.SensorListener SensorListener} for more details. -     * @deprecated use {@link android.hardware.Sensor Sensor} instead. -     */ -    @Deprecated -    public static final int SENSOR_ORIENTATION_RAW = 1 << 7; - -    /** A constant that includes all sensors */ -    @Deprecated -    public static final int SENSOR_ALL = 0x7F; - -    /** Smallest sensor ID */ -    @Deprecated -    public static final int SENSOR_MIN = SENSOR_ORIENTATION; - -    /** Largest sensor ID */ -    @Deprecated -    public static final int SENSOR_MAX = ((SENSOR_ALL + 1)>>1); - - -    /** Index of the X value in the array returned by -     * {@link android.hardware.SensorListener#onSensorChanged} */ -    @Deprecated -    public static final int DATA_X = 0; -    /** Index of the Y value in the array returned by -     * {@link android.hardware.SensorListener#onSensorChanged} */ -    @Deprecated -    public static final int DATA_Y = 1; -    /** Index of the Z value in the array returned by -     * {@link android.hardware.SensorListener#onSensorChanged} */ -    @Deprecated -    public static final int DATA_Z = 2; - -    /** Offset to the untransformed values in the array returned by -     * {@link android.hardware.SensorListener#onSensorChanged} */ -    @Deprecated -    public static final int RAW_DATA_INDEX = 3; - -    /** Index of the untransformed X value in the array returned by -     * {@link android.hardware.SensorListener#onSensorChanged} */ -    @Deprecated -    public static final int RAW_DATA_X = 3; -    /** Index of the untransformed Y value in the array returned by -     * {@link android.hardware.SensorListener#onSensorChanged} */ -    @Deprecated -    public static final int RAW_DATA_Y = 4; -    /** Index of the untransformed Z value in the array returned by -     * {@link android.hardware.SensorListener#onSensorChanged} */ -    @Deprecated -    public static final int RAW_DATA_Z = 5; - - -    /** Standard gravity (g) on Earth. This value is equivalent to 1G */ -    public static final float STANDARD_GRAVITY = 9.80665f; - -    /** values returned by the accelerometer in various locations in the universe. -     * all values are in SI units (m/s^2) */ -    public static final float GRAVITY_SUN             = 275.0f; -    public static final float GRAVITY_MERCURY         = 3.70f; -    public static final float GRAVITY_VENUS           = 8.87f; -    public static final float GRAVITY_EARTH           = 9.80665f; -    public static final float GRAVITY_MOON            = 1.6f; -    public static final float GRAVITY_MARS            = 3.71f; -    public static final float GRAVITY_JUPITER         = 23.12f; -    public static final float GRAVITY_SATURN          = 8.96f; -    public static final float GRAVITY_URANUS          = 8.69f; -    public static final float GRAVITY_NEPTUNE         = 11.0f; -    public static final float GRAVITY_PLUTO           = 0.6f; -    public static final float GRAVITY_DEATH_STAR_I    = 0.000000353036145f; -    public static final float GRAVITY_THE_ISLAND      = 4.815162342f; - - -    /** Maximum magnetic field on Earth's surface */ -    public static final float MAGNETIC_FIELD_EARTH_MAX = 60.0f; - -    /** Minimum magnetic field on Earth's surface */ -    public static final float MAGNETIC_FIELD_EARTH_MIN = 30.0f; - - -    /** Various luminance values during the day (lux) */ -    public static final float LIGHT_SUNLIGHT_MAX = 120000.0f; -    public static final float LIGHT_SUNLIGHT     = 110000.0f; -    public static final float LIGHT_SHADE        = 20000.0f; -    public static final float LIGHT_OVERCAST     = 10000.0f; -    public static final float LIGHT_SUNRISE      = 400.0f; -    public static final float LIGHT_CLOUDY       = 100.0f; -    /** Various luminance values during the night (lux) */ -    public static final float LIGHT_FULLMOON     = 0.25f; -    public static final float LIGHT_NO_MOON      = 0.001f; - -    /** get sensor data as fast as possible */ -    public static final int SENSOR_DELAY_FASTEST = 0; -    /** rate suitable for games */ -    public static final int SENSOR_DELAY_GAME = 1; -    /** rate suitable for the user interface  */ -    public static final int SENSOR_DELAY_UI = 2; -    /** rate (default) suitable for screen orientation changes */ -    public static final int SENSOR_DELAY_NORMAL = 3; - - -    /** The values returned by this sensor cannot be trusted, calibration -     * is needed or the environment doesn't allow readings */ -    public static final int SENSOR_STATUS_UNRELIABLE = 0; - -    /** This sensor is reporting data with low accuracy, calibration with the -     * environment is needed */ -    public static final int SENSOR_STATUS_ACCURACY_LOW = 1; - -    /** This sensor is reporting data with an average level of accuracy, -     * calibration with the environment may improve the readings */ -    public static final int SENSOR_STATUS_ACCURACY_MEDIUM = 2; - -    /** This sensor is reporting data with maximum accuracy */ -    public static final int SENSOR_STATUS_ACCURACY_HIGH = 3; - -    /** see {@link #remapCoordinateSystem} */ -    public static final int AXIS_X = 1; -    /** see {@link #remapCoordinateSystem} */ -    public static final int AXIS_Y = 2; -    /** see {@link #remapCoordinateSystem} */ -    public static final int AXIS_Z = 3; -    /** see {@link #remapCoordinateSystem} */ -    public static final int AXIS_MINUS_X = AXIS_X | 0x80; -    /** see {@link #remapCoordinateSystem} */ -    public static final int AXIS_MINUS_Y = AXIS_Y | 0x80; -    /** see {@link #remapCoordinateSystem} */ -    public static final int AXIS_MINUS_Z = AXIS_Z | 0x80; - -    /*-----------------------------------------------------------------------*/ - -    private ISensorService mSensorService; -    Looper mMainLooper; -    @SuppressWarnings("deprecation") -    private HashMap<SensorListener, LegacyListener> mLegacyListenersMap = -        new HashMap<SensorListener, LegacyListener>(); - -    /*-----------------------------------------------------------------------*/ - -    private static final int SENSOR_DISABLE = -1; -    private static boolean sSensorModuleInitialized = false; -    private static ArrayList<Sensor> sFullSensorsList = new ArrayList<Sensor>(); -    private static SparseArray<List<Sensor>> sSensorListByType = new SparseArray<List<Sensor>>(); -    private static IWindowManager sWindowManager; -    private static int sRotation = Surface.ROTATION_0; -    /* The thread and the sensor list are global to the process -     * but the actual thread is spawned on demand */ -    private static SensorThread sSensorThread; - -    // Used within this module from outside SensorManager, don't make private -    static SparseArray<Sensor> sHandleToSensor = new SparseArray<Sensor>(); -    static final ArrayList<ListenerDelegate> sListeners = -        new ArrayList<ListenerDelegate>(); - -    /*-----------------------------------------------------------------------*/ - -    static private class SensorThread { - -        Thread mThread; - -        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 -        void startLocked(ISensorService service) { -            try { -                if (mThread == null) { -                    ParcelFileDescriptor fd = service.getDataChanel(); -                    mThread = new Thread(new SensorThreadRunnable(fd), -                            SensorThread.class.getName()); -                    mThread.start(); -                } -            } catch (RemoteException e) { -                Log.e(TAG, "RemoteException in startLocked: ", e); -            } -        } - -        private class SensorThreadRunnable implements Runnable { -            private ParcelFileDescriptor mSensorDataFd; -            SensorThreadRunnable(ParcelFileDescriptor fd) { -                mSensorDataFd = fd; -            } -            public void run() { -                //Log.d(TAG, "entering main sensor thread"); -                final float[] values = new float[3]; -                final int[] status = new int[1]; -                final long timestamp[] = new long[1]; -                Process.setThreadPriority(Process.THREAD_PRIORITY_DISPLAY); - -                if (mSensorDataFd == null) { -                    Log.e(TAG, "mSensorDataFd == NULL, exiting"); -                    return; -                } -                // this thread is guaranteed to be unique -                sensors_data_open(mSensorDataFd.getFileDescriptor()); -                try { -                    mSensorDataFd.close(); -                } catch (IOException e) { -                    // *shrug* -                    Log.e(TAG, "IOException: ", e); -                } -                mSensorDataFd = null; - - -                while (true) { -                    // wait for an event -                    final int sensor = sensors_data_poll(values, status, timestamp); - -                    if (sensor == -1) { -                        // we lost the connection to the event stream. this happens -                        // when the last listener is removed. -                        Log.d(TAG, "_sensors_data_poll() failed, we bail out."); -                        break; -                    } - -                    int accuracy = status[0]; -                    synchronized (sListeners) { -                        if (sListeners.isEmpty()) { -                            // we have no more listeners, terminate the thread -                            sensors_data_close(); -                            mThread = null; -                            break; -                        } -                        final Sensor sensorObject = sHandleToSensor.get(sensor); -                        if (sensorObject != null) { -                            // report the sensor event to all listeners that -                            // care about it. -                            final int size = sListeners.size(); -                            for (int i=0 ; i<size ; i++) { -                                ListenerDelegate listener = sListeners.get(i); -                                if (listener.hasSensor(sensorObject)) { -                                    // this is asynchronous (okay to call -                                    // with sListeners lock held). -                                    listener.onSensorChangedLocked(sensorObject, -                                            values, timestamp, accuracy); -                                } -                            } -                        } -                    } -                } -                //Log.d(TAG, "exiting main sensor thread"); -            } -        } -    } - -    /*-----------------------------------------------------------------------*/ - -    private class ListenerDelegate extends Binder { -        final SensorEventListener mSensorEventListener; -        private final ArrayList<Sensor> mSensorList = new ArrayList<Sensor>(); -        private final Handler mHandler; -        private SensorEvent mValuesPool; -        public int mSensors; - -        ListenerDelegate(SensorEventListener listener, Sensor sensor, Handler handler) { -            mSensorEventListener = listener; -            Looper looper = (handler != null) ? handler.getLooper() : mMainLooper; -            // currently we create one Handler instance per listener, but we could -            // have one per looper (we'd need to pass the ListenerDelegate -            // instance to handleMessage and keep track of them separately). -            mHandler = new Handler(looper) { -                @Override -                public void handleMessage(Message msg) { -                    SensorEvent t = (SensorEvent)msg.obj; -                    if (t.accuracy >= 0) { -                        mSensorEventListener.onAccuracyChanged(t.sensor, t.accuracy); -                    } -                    mSensorEventListener.onSensorChanged(t); -                    returnToPool(t); -                } -            }; -            addSensor(sensor); -        } - -        protected SensorEvent createSensorEvent() { -            // maximal size for all legacy events is 3 -            return new SensorEvent(3); -        } - -        protected SensorEvent getFromPool() { -            SensorEvent t = null; -            synchronized (this) { -                // remove the array from the pool -                t = mValuesPool; -                mValuesPool = null; -            } -            if (t == null) { -                // the pool was empty, we need a new one -                t = createSensorEvent(); -            } -            return t; -        } - -        protected void returnToPool(SensorEvent t) { -            synchronized (this) { -                // put back the array into the pool -                if (mValuesPool == null) { -                    mValuesPool = t; -                } -            } -        } - -        Object getListener() { -            return mSensorEventListener; -        } - -        int addSensor(Sensor sensor) { -            mSensors |= 1<<sensor.getHandle(); -            mSensorList.add(sensor); -            return mSensors; -        } -        int removeSensor(Sensor sensor) { -            mSensors &= ~(1<<sensor.getHandle()); -            mSensorList.remove(sensor); -            return mSensors; -        } -        boolean hasSensor(Sensor sensor) { -            return ((mSensors & (1<<sensor.getHandle())) != 0); -        } -        List<Sensor> getSensors() { -            return mSensorList; -        } - -        void onSensorChangedLocked(Sensor sensor, float[] values, long[] timestamp, int accuracy) { -            SensorEvent t = getFromPool(); -            final float[] v = t.values; -            v[0] = values[0]; -            v[1] = values[1]; -            v[2] = values[2]; -            t.timestamp = timestamp[0]; -            t.accuracy = accuracy; -            t.sensor = sensor; -            Message msg = Message.obtain(); -            msg.what = 0; -            msg.obj = t; -            mHandler.sendMessage(msg); -        } -    } - -    /** -     * {@hide} -     */ -    public SensorManager(Looper mainLooper) { -        mSensorService = ISensorService.Stub.asInterface( -                ServiceManager.getService(Context.SENSOR_SERVICE)); -        mMainLooper = mainLooper; - - -        synchronized(sListeners) { -            if (!sSensorModuleInitialized) { -                sSensorModuleInitialized = true; - -                nativeClassInit(); - -                sWindowManager = IWindowManager.Stub.asInterface( -                        ServiceManager.getService("window")); -                if (sWindowManager != null) { -                    // if it's null we're running in the system process -                    // which won't get the rotated values -                    try { -                        sRotation = sWindowManager.watchRotation(this); -                    } catch (RemoteException e) { -                    } -                } - -                // initialize the sensor list -                sensors_module_init(); -                final ArrayList<Sensor> fullList = sFullSensorsList; -                int i = 0; -                do { -                    Sensor sensor = new Sensor(); -                    i = sensors_module_get_next_sensor(sensor, i); - -                    if (i>=0) { -                        Log.d(TAG, "found sensor: " + sensor.getName() + -                                ", handle=" + sensor.getHandle()); -                        sensor.setLegacyType(getLegacySensorType(sensor.getType())); -                        fullList.add(sensor); -                        sHandleToSensor.append(sensor.getHandle(), sensor); -                    } -                } while (i>0); - -                sSensorThread = new SensorThread(); -            } -        } -    } - -    private int getLegacySensorType(int type) { -        switch (type) { -            case Sensor.TYPE_ACCELEROMETER: -                return SENSOR_ACCELEROMETER; -            case Sensor.TYPE_MAGNETIC_FIELD: -                return SENSOR_MAGNETIC_FIELD; -            case Sensor.TYPE_ORIENTATION: -                return SENSOR_ORIENTATION_RAW; -            case Sensor.TYPE_TEMPERATURE: -                return SENSOR_TEMPERATURE; -        } -        return 0; -    } - -    /** @return available sensors. -     * @deprecated This method is deprecated, use -     * {@link SensorManager#getSensorList(int)} instead -     */ -    @Deprecated -    public int getSensors() { -        int result = 0; -        final ArrayList<Sensor> fullList = sFullSensorsList; -        for (Sensor i : fullList) { -            switch (i.getType()) { -                case Sensor.TYPE_ACCELEROMETER: -                    result |= SensorManager.SENSOR_ACCELEROMETER; -                    break; -                case Sensor.TYPE_MAGNETIC_FIELD: -                    result |= SensorManager.SENSOR_MAGNETIC_FIELD; -                    break; -                case Sensor.TYPE_ORIENTATION: -                    result |= SensorManager.SENSOR_ORIENTATION | -                                    SensorManager.SENSOR_ORIENTATION_RAW; -                    break; -            } -        } -        return result; -    } - -    /** -     * Use this method to get the list of available sensors of a certain -     * type. Make multiple calls to get sensors of different types or use -     * {@link android.hardware.Sensor#TYPE_ALL Sensor.TYPE_ALL} to get all -     * the sensors. -     * -     * @param type of sensors requested -     * @return a list of sensors matching the asked type. -     */ -    public List<Sensor> getSensorList(int type) { -        // cache the returned lists the first time -        List<Sensor> list; -        final ArrayList<Sensor> fullList = sFullSensorsList; -        synchronized(fullList) { -            list = sSensorListByType.get(type); -            if (list == null) { -                if (type == Sensor.TYPE_ALL) { -                    list = fullList; -                } else { -                    list = new ArrayList<Sensor>(); -                    for (Sensor i : fullList) { -                        if (i.getType() == type) -                            list.add(i); -                    } -                } -                list = Collections.unmodifiableList(list); -                sSensorListByType.append(type, list); -            } -        } -        return list; -    } - -    /** -     * Use this method to get the default sensor for a given type. Note that -     * the returned sensor could be a composite sensor, and its data could be -     * averaged or filtered. If you need to access the raw sensors use -     * {@link SensorManager#getSensorList(int) getSensorList}. -     * -     * -     * @param type of sensors requested -     * @return the default sensors matching the asked type. -     */ -    public Sensor getDefaultSensor(int type) { -        // TODO: need to be smarter, for now, just return the 1st sensor -        List<Sensor> l = getSensorList(type); -        return l.isEmpty() ? null : l.get(0); -    } - - -    /** -     * Registers a listener for given sensors. -     * @deprecated This method is deprecated, use -     * {@link SensorManager#registerListener(SensorEventListener, Sensor, int)} -     * instead. -     * -     * @param listener sensor listener object -     * @param sensors a bit masks of the sensors to register to -     * -     * @return true if the sensor is supported and successfully enabled -     */ -    @Deprecated -    public boolean registerListener(SensorListener listener, int sensors) { -        return registerListener(listener, sensors, SENSOR_DELAY_NORMAL); -    } - -    /** -     * Registers a SensorListener for given sensors. -     * @deprecated This method is deprecated, use -     * {@link SensorManager#registerListener(SensorEventListener, Sensor, int)} -     * instead. -     * -     * @param listener sensor listener object -     * @param sensors a bit masks of the sensors to register to -     * @param rate rate of events. This is only a hint to the system. events -     * may be received faster or slower than the specified rate. Usually events -     * are received faster. -     * -     * @return true if the sensor is supported and successfully enabled -     */ -    @Deprecated -    public boolean registerListener(SensorListener listener, int sensors, int rate) { -        if (listener == null) { -            return false; -        } -        boolean result = false; -        result = registerLegacyListener(SENSOR_ACCELEROMETER, Sensor.TYPE_ACCELEROMETER, -                listener, sensors, rate) || result; -        result = registerLegacyListener(SENSOR_MAGNETIC_FIELD, Sensor.TYPE_MAGNETIC_FIELD, -                listener, sensors, rate) || result; -        result = registerLegacyListener(SENSOR_ORIENTATION_RAW, Sensor.TYPE_ORIENTATION, -                listener, sensors, rate) || result; -        result = registerLegacyListener(SENSOR_ORIENTATION, Sensor.TYPE_ORIENTATION, -                listener, sensors, rate) || result; -        result = registerLegacyListener(SENSOR_TEMPERATURE, Sensor.TYPE_TEMPERATURE, -                listener, sensors, rate) || result; -        return result; -    } - -    @SuppressWarnings("deprecation") -    private boolean registerLegacyListener(int legacyType, int type, -            SensorListener listener, int sensors, int rate) -    { -        if (listener == null) { -            return false; -        } -        boolean result = false; -        // Are we activating this legacy sensor? -        if ((sensors & legacyType) != 0) { -            // if so, find a suitable Sensor -            Sensor sensor = getDefaultSensor(type); -            if (sensor != null) { -                // If we don't already have one, create a LegacyListener -                // to wrap this listener and process the events as -                // they are expected by legacy apps. -                LegacyListener legacyListener = null; -                synchronized (mLegacyListenersMap) { -                    legacyListener = mLegacyListenersMap.get(listener); -                    if (legacyListener == null) { -                        // we didn't find a LegacyListener for this client, -                        // create one, and put it in our list. -                        legacyListener = new LegacyListener(listener); -                        mLegacyListenersMap.put(listener, legacyListener); -                    } -                } -                // register this legacy sensor with this legacy listener -                legacyListener.registerSensor(legacyType); -                // and finally, register the legacy listener with the new apis -                result = registerListener(legacyListener, sensor, rate); -            } -        } -        return result; -    } - -    /** -     * Unregisters a listener for the sensors with which it is registered. -     * @deprecated This method is deprecated, use -     * {@link SensorManager#unregisterListener(SensorEventListener, Sensor)} -     * instead. -     * -     * @param listener a SensorListener object -     * @param sensors a bit masks of the sensors to unregister from -     */ -    @Deprecated -    public void unregisterListener(SensorListener listener, int sensors) { -        unregisterLegacyListener(SENSOR_ACCELEROMETER, Sensor.TYPE_ACCELEROMETER, -                listener, sensors); -        unregisterLegacyListener(SENSOR_MAGNETIC_FIELD, Sensor.TYPE_MAGNETIC_FIELD, -                listener, sensors); -        unregisterLegacyListener(SENSOR_ORIENTATION_RAW, Sensor.TYPE_ORIENTATION, -                listener, sensors); -        unregisterLegacyListener(SENSOR_ORIENTATION, Sensor.TYPE_ORIENTATION, -                listener, sensors); -        unregisterLegacyListener(SENSOR_TEMPERATURE, Sensor.TYPE_TEMPERATURE, -                listener, sensors); -    } - -    @SuppressWarnings("deprecation") -    private void unregisterLegacyListener(int legacyType, int type, -            SensorListener listener, int sensors) -    { -        if (listener == null) { -            return; -        } -        // do we know about this listener? -        LegacyListener legacyListener = null; -        synchronized (mLegacyListenersMap) { -            legacyListener = mLegacyListenersMap.get(listener); -        } -        if (legacyListener != null) { -            // Are we deactivating this legacy sensor? -            if ((sensors & legacyType) != 0) { -                // if so, find the corresponding Sensor -                Sensor sensor = getDefaultSensor(type); -                if (sensor != null) { -                    // unregister this legacy sensor and if we don't -                    // need the corresponding Sensor, unregister it too -                    if (legacyListener.unregisterSensor(legacyType)) { -                        // corresponding sensor not needed, unregister -                        unregisterListener(legacyListener, sensor); -                        // finally check if we still need the legacyListener -                        // in our mapping, if not, get rid of it too. -                        synchronized(sListeners) { -                            boolean found = false; -                            for (ListenerDelegate i : sListeners) { -                                if (i.getListener() == legacyListener) { -                                    found = true; -                                    break; -                                } -                            } -                            if (!found) { -                                synchronized (mLegacyListenersMap) { -                                    mLegacyListenersMap.remove(listener); -                                } -                            } -                        } -                    } -                } -            } -        } -    } - -    /** -     * Unregisters a listener for all sensors. -     * @deprecated This method is deprecated, use -     * {@link SensorManager#unregisterListener(SensorEventListener)} -     * instead. -     * -     * @param listener a SensorListener object -     */ -    @Deprecated -    public void unregisterListener(SensorListener listener) { -        unregisterListener(listener, SENSOR_ALL | SENSOR_ORIENTATION_RAW); -    } - -    /** -     * Unregisters a listener for the sensors with which it is registered. -     * -     * @param listener a SensorEventListener object -     * @param sensor the sensor to unregister from -     * -     */ -    public void unregisterListener(SensorEventListener listener, Sensor sensor) { -        unregisterListener((Object)listener, sensor); -    } - -    /** -     * Unregisters a listener for all sensors. -     * -     * @param listener a SensorListener object -     * -     */ -    public void unregisterListener(SensorEventListener listener) { -        unregisterListener((Object)listener); -    } - - -    /** -     * Registers a {@link android.hardware.SensorEventListener SensorEventListener} -     * for the given sensor. -     * -     * @param listener A {@link android.hardware.SensorEventListener SensorEventListener} object. -     * @param sensor The {@link android.hardware.Sensor Sensor} to register to. -     * @param rate The rate {@link android.hardware.SensorEvent sensor events} are delivered at. -     * This is only a hint to the system. Events may be received faster or -     * slower than the specified rate. Usually events are received faster. -     * -     * @return true if the sensor is supported and successfully enabled. -     * -     */ -    public boolean registerListener(SensorEventListener listener, Sensor sensor, int rate) { -        return registerListener(listener, sensor, rate, null); -    } - -    /** -     * Registers a {@link android.hardware.SensorEventListener SensorEventListener} -     * for the given sensor. -     * -     * @param listener A {@link android.hardware.SensorEventListener SensorEventListener} object. -     * @param sensor The {@link android.hardware.Sensor Sensor} to register to. -     * @param rate The rate {@link android.hardware.SensorEvent sensor events} are delivered at. -     * This is only a hint to the system. Events may be received faster or -     * slower than the specified rate. Usually events are received faster. -     * @param handler The {@link android.os.Handler Handler} the -     * {@link android.hardware.SensorEvent sensor events} will be delivered to. -     * -     * @return true if the sensor is supported and successfully enabled. -     * -     */ -    public boolean registerListener(SensorEventListener listener, Sensor sensor, int rate, -            Handler handler) { -        if (listener == null || sensor == null) { -            return false; -        } -        boolean result; -        int delay = -1; -        switch (rate) { -            case SENSOR_DELAY_FASTEST: -                delay = 0; -                break; -            case SENSOR_DELAY_GAME: -                delay = 20; -                break; -            case SENSOR_DELAY_UI: -                delay = 60; -                break; -            case SENSOR_DELAY_NORMAL: -                delay = 200; -                break; -            default: -                return false; -        } - -        try { -            synchronized (sListeners) { -                ListenerDelegate l = null; -                for (ListenerDelegate i : sListeners) { -                    if (i.getListener() == listener) { -                        l = i; -                        break; -                    } -                } - -                String name = sensor.getName(); -                int handle = sensor.getHandle(); -                if (l == null) { -                    l = new ListenerDelegate(listener, sensor, handler); -                    result = mSensorService.enableSensor(l, name, handle, delay); -                    if (result) { -                        sListeners.add(l); -                        sListeners.notify(); -                    } -                    if (!sListeners.isEmpty()) { -                        sSensorThread.startLocked(mSensorService); -                    } -                } else { -                    result = mSensorService.enableSensor(l, name, handle, delay); -                    if (result) { -                        l.addSensor(sensor); -                    } -                } -            } -        } catch (RemoteException e) { -            Log.e(TAG, "RemoteException in registerListener: ", e); -            result = false; -        } -        return result; -    } - -    private void unregisterListener(Object listener, Sensor sensor) { -        if (listener == null || sensor == null) { -            return; -        } -        try { -            synchronized (sListeners) { -                final int size = sListeners.size(); -                for (int i=0 ; i<size ; i++) { -                    ListenerDelegate l = sListeners.get(i); -                    if (l.getListener() == listener) { -                        // disable these sensors -                        String name = sensor.getName(); -                        int handle = sensor.getHandle(); -                        mSensorService.enableSensor(l, name, handle, SENSOR_DISABLE); -                        // if we have no more sensors enabled on this listener, -                        // take it off the list. -                        if (l.removeSensor(sensor) == 0) { -                            sListeners.remove(i); -                        } -                        break; -                    } -                } -            } -        } 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++) { -                    ListenerDelegate l = sListeners.get(i); -                    if (l.getListener() == listener) { -                        // disable all sensors for this listener -                        for (Sensor sensor : l.getSensors()) { -                            String name = sensor.getName(); -                            int handle = sensor.getHandle(); -                            mSensorService.enableSensor(l, name, handle, SENSOR_DISABLE); -                        } -                        sListeners.remove(i); -                        break; -                    } -                } -            } -        } catch (RemoteException e) { -            Log.e(TAG, "RemoteException in unregisterListener: ", e); -        } -    } - -    /** -     * Computes the inclination matrix <b>I</b> as well as the rotation -     * matrix <b>R</b> transforming a vector from the -     * device coordinate system to the world's coordinate system which is -     * defined as a direct orthonormal basis, where: -     *  -     * <li>X is defined as the vector product <b>Y.Z</b> (It is tangential to -     * the ground at the device's current location and roughly points East).</li> -     * <li>Y is tangential to the ground at the device's current location and -     * points towards the magnetic North Pole.</li> -     * <li>Z points towards the sky and is perpendicular to the ground.</li> -     * <p> -     * <hr> -     * <p>By definition: -     * <p>[0 0 g] = <b>R</b> * <b>gravity</b> (g = magnitude of gravity) -     * <p>[0 m 0] = <b>I</b> * <b>R</b> * <b>geomagnetic</b> -     * (m = magnitude of geomagnetic field) -     * <p><b>R</b> is the identity matrix when the device is aligned with the -     * world's coordinate system, that is, when the device's X axis points -     * toward East, the Y axis points to the North Pole and the device is facing -     * the sky. -     * -     * <p><b>I</b> is a rotation matrix transforming the geomagnetic -     * vector into the same coordinate space as gravity (the world's coordinate -     * space). <b>I</b> is a simple rotation around the X axis. -     * The inclination angle in radians can be computed with -     * {@link #getInclination}. -     * <hr> -     *  -     * <p> Each matrix is returned either as a 3x3 or 4x4 row-major matrix -     * depending on the length of the passed array: -     * <p><u>If the array length is 16:</u> -     * <pre> -     *   /  M[ 0]   M[ 1]   M[ 2]   M[ 3]  \ -     *   |  M[ 4]   M[ 5]   M[ 6]   M[ 7]  | -     *   |  M[ 8]   M[ 9]   M[10]   M[11]  | -     *   \  M[12]   M[13]   M[14]   M[15]  / -     *</pre> -     * This matrix is ready to be used by OpenGL ES's  -     * {@link javax.microedition.khronos.opengles.GL10#glLoadMatrixf(float[], int)  -     * glLoadMatrixf(float[], int)}.  -     * <p>Note that because OpenGL matrices are column-major matrices you must -     * transpose the matrix before using it. However, since the matrix is a  -     * rotation matrix, its transpose is also its inverse, conveniently, it is -     * often the inverse of the rotation that is needed for rendering; it can -     * therefore be used with OpenGL ES directly. -     * <p> -     * Also note that the returned matrices always have this form: -     * <pre> -     *   /  M[ 0]   M[ 1]   M[ 2]   0  \ -     *   |  M[ 4]   M[ 5]   M[ 6]   0  | -     *   |  M[ 8]   M[ 9]   M[10]   0  | -     *   \      0       0       0   1  / -     *</pre> -     * <p><u>If the array length is 9:</u> -     * <pre> -     *   /  M[ 0]   M[ 1]   M[ 2]  \ -     *   |  M[ 3]   M[ 4]   M[ 5]  | -     *   \  M[ 6]   M[ 7]   M[ 8]  / -     *</pre> -     * -     * <hr> -     * <p>The inverse of each matrix can be computed easily by taking its -     * transpose. -     * -     * <p>The matrices returned by this function are meaningful only when the -     * device is not free-falling and it is not close to the magnetic north. -     * If the device is accelerating, or placed into a strong magnetic field, -     * the returned matrices may be inaccurate. -     * -     * @param R is an array of 9 floats holding the rotation matrix <b>R</b> -     * when this function returns. R can be null.<p> -     * @param I is an array of 9 floats holding the rotation matrix <b>I</b> -     * when this function returns. I can be null.<p> -     * @param gravity is an array of 3 floats containing the gravity vector -     * expressed in the device's coordinate. You can simply use the -     * {@link android.hardware.SensorEvent#values values} -     * returned by a {@link android.hardware.SensorEvent SensorEvent} of a -     * {@link android.hardware.Sensor Sensor} of type -     * {@link android.hardware.Sensor#TYPE_ACCELEROMETER TYPE_ACCELEROMETER}.<p> -     * @param geomagnetic is an array of 3 floats containing the geomagnetic -     * vector expressed in the device's coordinate. You can simply use the -     * {@link android.hardware.SensorEvent#values values} -     * returned by a {@link android.hardware.SensorEvent SensorEvent} of a -     * {@link android.hardware.Sensor Sensor} of type -     * {@link android.hardware.Sensor#TYPE_MAGNETIC_FIELD TYPE_MAGNETIC_FIELD}. -     * @return -     *   true on success<p> -     *   false on failure (for instance, if the device is in free fall). -     *   On failure the output matrices are not modified. -     */ - -    public static boolean getRotationMatrix(float[] R, float[] I, -            float[] gravity, float[] geomagnetic) { -        // TODO: move this to native code for efficiency -        float Ax = gravity[0]; -        float Ay = gravity[1]; -        float Az = gravity[2]; -        final float Ex = geomagnetic[0]; -        final float Ey = geomagnetic[1]; -        final float Ez = geomagnetic[2]; -        float Hx = Ey*Az - Ez*Ay; -        float Hy = Ez*Ax - Ex*Az; -        float Hz = Ex*Ay - Ey*Ax; -        final float normH = (float)Math.sqrt(Hx*Hx + Hy*Hy + Hz*Hz); -        if (normH < 0.1f) { -            // device is close to free fall (or in space?), or close to -            // magnetic north pole. Typical values are  > 100. -            return false; -        } -        final float invH = 1.0f / normH; -        Hx *= invH; -        Hy *= invH; -        Hz *= invH; -        final float invA = 1.0f / (float)Math.sqrt(Ax*Ax + Ay*Ay + Az*Az); -        Ax *= invA; -        Ay *= invA; -        Az *= invA; -        final float Mx = Ay*Hz - Az*Hy; -        final float My = Az*Hx - Ax*Hz; -        final float Mz = Ax*Hy - Ay*Hx; -        if (R != null) { -            if (R.length == 9) { -                R[0] = Hx;     R[1] = Hy;     R[2] = Hz; -                R[3] = Mx;     R[4] = My;     R[5] = Mz; -                R[6] = Ax;     R[7] = Ay;     R[8] = Az; -            } else if (R.length == 16) { -                R[0]  = Hx;    R[1]  = Hy;    R[2]  = Hz;   R[3]  = 0; -                R[4]  = Mx;    R[5]  = My;    R[6]  = Mz;   R[7]  = 0; -                R[8]  = Ax;    R[9]  = Ay;    R[10] = Az;   R[11] = 0; -                R[12] = 0;     R[13] = 0;     R[14] = 0;    R[15] = 1; -            } -        } -        if (I != null) { -            // compute the inclination matrix by projecting the geomagnetic -            // vector onto the Z (gravity) and X (horizontal component -            // of geomagnetic vector) axes. -            final float invE = 1.0f / (float)Math.sqrt(Ex*Ex + Ey*Ey + Ez*Ez); -            final float c = (Ex*Mx + Ey*My + Ez*Mz) * invE; -            final float s = (Ex*Ax + Ey*Ay + Ez*Az) * invE; -            if (I.length == 9) { -                I[0] = 1;     I[1] = 0;     I[2] = 0; -                I[3] = 0;     I[4] = c;     I[5] = s; -                I[6] = 0;     I[7] =-s;     I[8] = c; -            } else if (I.length == 16) { -                I[0] = 1;     I[1] = 0;     I[2] = 0; -                I[4] = 0;     I[5] = c;     I[6] = s; -                I[8] = 0;     I[9] =-s;     I[10]= c; -                I[3] = I[7] = I[11] = I[12] = I[13] = I[14] = 0; -                I[15] = 1; -            } -        } -        return true; -    } - -    /** -     * Computes the geomagnetic inclination angle in radians from the -     * inclination matrix <b>I</b> returned by {@link #getRotationMatrix}. -     * @param I inclination matrix see {@link #getRotationMatrix}. -     * @return The geomagnetic inclination angle in radians. -     */ -    public static float getInclination(float[] I) { -        if (I.length == 9) { -            return (float)Math.atan2(I[5], I[4]); -        } else { -            return (float)Math.atan2(I[6], I[5]);             -        } -    } - -    /** -     * Rotates the supplied rotation matrix so it is expressed in a -     * different coordinate system. This is typically used when an application -     * needs to compute the three orientation angles of the device (see -     * {@link #getOrientation}) in a different coordinate system. -     *  -     * <p>When the rotation matrix is used for drawing (for instance with  -     * OpenGL ES), it usually <b>doesn't need</b> to be transformed by this  -     * function, unless the screen is physically rotated, such as when used -     * in landscape mode.  -     * -     * <p><u>Examples:</u><p> -     * -     * <li>Using the camera (Y axis along the camera's axis) for an augmented  -     * reality application where the rotation angles are needed :</li><p> -     * -     * <code>remapCoordinateSystem(inR, AXIS_X, AXIS_Z, outR);</code><p> -     * -     * <li>Using the device as a mechanical compass in landscape mode:</li><p> -     * -     * <code>remapCoordinateSystem(inR, AXIS_Y, AXIS_MINUS_X, outR);</code><p> -     * -     * Beware of the above example. This call is needed only if the device is -     * physically used in landscape mode to calculate the rotation angles (see  -     * {@link #getOrientation}). -     * If the rotation matrix is also used for rendering, it may not need to  -     * be transformed, for instance if your {@link android.app.Activity -     * Activity} is running in landscape mode. -     * -     * <p>Since the resulting coordinate system is orthonormal, only two axes -     * need to be specified. -     * -     * @param inR the rotation matrix to be transformed. Usually it is the -     * matrix returned by {@link #getRotationMatrix}. -     * @param X defines on which world axis and direction the X axis of the -     *        device is mapped. -     * @param Y defines on which world axis and direction the Y axis of the -     *        device is mapped. -     * @param outR the transformed rotation matrix. inR and outR can be the same -     *        array, but it is not recommended for performance reason. -     * @return true on success. false if the input parameters are incorrect, for -     * instance if X and Y define the same axis. Or if inR and outR don't have  -     * the same length. -     */ - -    public static boolean remapCoordinateSystem(float[] inR, int X, int Y, -            float[] outR) -    { -        if (inR == outR) { -            final float[] temp = mTempMatrix; -            synchronized(temp) { -                // we don't expect to have a lot of contention -                if (remapCoordinateSystemImpl(inR, X, Y, temp)) { -                    final int size = outR.length; -                    for (int i=0 ; i<size ; i++) -                        outR[i] = temp[i]; -                    return true; -                } -            } -        } -        return remapCoordinateSystemImpl(inR, X, Y, outR); -    } - -    private static boolean remapCoordinateSystemImpl(float[] inR, int X, int Y, -            float[] outR) -    { -        /* -         * X and Y define a rotation matrix 'r': -         * -         *  (X==1)?((X&0x80)?-1:1):0    (X==2)?((X&0x80)?-1:1):0    (X==3)?((X&0x80)?-1:1):0 -         *  (Y==1)?((Y&0x80)?-1:1):0    (Y==2)?((Y&0x80)?-1:1):0    (Y==3)?((X&0x80)?-1:1):0 -         *                              r[0] ^ r[1] -         * -         * where the 3rd line is the vector product of the first 2 lines -         * -         */ - -        final int length = outR.length; -        if (inR.length != length) -            return false;   // invalid parameter -        if ((X & 0x7C)!=0 || (Y & 0x7C)!=0) -            return false;   // invalid parameter -        if (((X & 0x3)==0) || ((Y & 0x3)==0)) -            return false;   // no axis specified -        if ((X & 0x3) == (Y & 0x3)) -            return false;   // same axis specified - -        // Z is "the other" axis, its sign is either +/- sign(X)*sign(Y) -        // this can be calculated by exclusive-or'ing X and Y; except for -        // the sign inversion (+/-) which is calculated below. -        int Z = X ^ Y; - -        // extract the axis (remove the sign), offset in the range 0 to 2. -        final int x = (X & 0x3)-1; -        final int y = (Y & 0x3)-1; -        final int z = (Z & 0x3)-1; - -        // compute the sign of Z (whether it needs to be inverted) -        final int axis_y = (z+1)%3; -        final int axis_z = (z+2)%3; -        if (((x^axis_y)|(y^axis_z)) != 0) -            Z ^= 0x80; - -        final boolean sx = (X>=0x80); -        final boolean sy = (Y>=0x80); -        final boolean sz = (Z>=0x80); - -        // Perform R * r, in avoiding actual muls and adds. -        final int rowLength = ((length==16)?4:3); -        for (int j=0 ; j<3 ; j++) { -            final int offset = j*rowLength; -            for (int i=0 ; i<3 ; i++) { -                if (x==i)   outR[offset+i] = sx ? -inR[offset+0] : inR[offset+0]; -                if (y==i)   outR[offset+i] = sy ? -inR[offset+1] : inR[offset+1]; -                if (z==i)   outR[offset+i] = sz ? -inR[offset+2] : inR[offset+2]; -            } -        } -        if (length == 16) { -            outR[3] = outR[7] = outR[11] = outR[12] = outR[13] = outR[14] = 0; -            outR[15] = 1; -        } -        return true; -    } - -    /** -     * Computes the device's orientation based on the rotation matrix. -     * <p> When it returns, the array values is filled with the result: -     * <li>values[0]: <i>azimuth</i>, rotation around the Z axis.</li> -     * <li>values[1]: <i>pitch</i>, rotation around the X axis.</li> -     * <li>values[2]: <i>roll</i>, rotation around the Y axis.</li> -     * <p> -     * -     * @param R rotation matrix see {@link #getRotationMatrix}. -     * @param values an array of 3 floats to hold the result. -     * @return The array values passed as argument. -     */ -    public static float[] getOrientation(float[] R, float values[]) { -        /* -         * 4x4 (length=16) case: -         *   /  R[ 0]   R[ 1]   R[ 2]   0  \ -         *   |  R[ 4]   R[ 5]   R[ 6]   0  | -         *   |  R[ 8]   R[ 9]   R[10]   0  | -         *   \      0       0       0   1  / -         *    -         * 3x3 (length=9) case: -         *   /  R[ 0]   R[ 1]   R[ 2]  \ -         *   |  R[ 3]   R[ 4]   R[ 5]  | -         *   \  R[ 6]   R[ 7]   R[ 8]  / -         *  -         */ -        if (R.length == 9) { -            values[0] = (float)Math.atan2(R[1], R[4]); -            values[1] = (float)Math.asin(-R[7]); -            values[2] = (float)Math.atan2(-R[6], R[8]); -        } else { -            values[0] = (float)Math.atan2(R[1], R[5]); -            values[1] = (float)Math.asin(-R[9]); -            values[2] = (float)Math.atan2(-R[8], R[10]); -        } -        return values; -    } - - -    /** -     * {@hide} -     */ -    public void onRotationChanged(int rotation) { -        synchronized(sListeners) { -            sRotation  = rotation; -        } -    } - -    static int getRotation() { -        synchronized(sListeners) { -            return sRotation; -        } -    } - -    private class LegacyListener implements SensorEventListener { -        private float mValues[] = new float[6]; -        @SuppressWarnings("deprecation") -        private SensorListener mTarget; -        private int mSensors; -        private final LmsFilter mYawfilter = new LmsFilter(); - -        @SuppressWarnings("deprecation") -        LegacyListener(SensorListener target) { -            mTarget = target; -            mSensors = 0; -        } - -        void registerSensor(int legacyType) { -            mSensors |= legacyType; -        } - -        boolean unregisterSensor(int legacyType) { -            mSensors &= ~legacyType; -            int mask = SENSOR_ORIENTATION|SENSOR_ORIENTATION_RAW; -            if (((legacyType&mask)!=0) && ((mSensors&mask)!=0)) { -                return false; -            } -            return true; -        } - -        @SuppressWarnings("deprecation") -        public void onAccuracyChanged(Sensor sensor, int accuracy) { -            try { -                mTarget.onAccuracyChanged(sensor.getLegacyType(), accuracy); -            } catch (AbstractMethodError e) { -                // old app that doesn't implement this method -                // just ignore it. -            } -        } - -        @SuppressWarnings("deprecation") -        public void onSensorChanged(SensorEvent event) { -            final float v[] = mValues; -            v[0] = event.values[0]; -            v[1] = event.values[1]; -            v[2] = event.values[2]; -            int legacyType = event.sensor.getLegacyType(); -            mapSensorDataToWindow(legacyType, v, SensorManager.getRotation()); -            if (event.sensor.getType() == Sensor.TYPE_ORIENTATION) { -                if ((mSensors & SENSOR_ORIENTATION_RAW)!=0) { -                    mTarget.onSensorChanged(SENSOR_ORIENTATION_RAW, v); -                } -                if ((mSensors & SENSOR_ORIENTATION)!=0) { -                    v[0] = mYawfilter.filter(event.timestamp, v[0]); -                    mTarget.onSensorChanged(SENSOR_ORIENTATION, v); -                } -            } else { -                mTarget.onSensorChanged(legacyType, v); -            } -        } - -        /* -         * Helper function to convert the specified sensor's data to the windows's -         * coordinate space from the device's coordinate space. -         * -         * output: 3,4,5: values in the old API format -         *         0,1,2: transformed values in the old API format -         * -         */ -        private void mapSensorDataToWindow(int sensor, -                float[] values, int orientation) { -            float x = values[0]; -            float y = values[1]; -            float z = values[2]; - -            switch (sensor) { -                case SensorManager.SENSOR_ORIENTATION: -                case SensorManager.SENSOR_ORIENTATION_RAW: -                    z = -z; -                    break; -                case SensorManager.SENSOR_ACCELEROMETER: -                    x = -x; -                    y = -y; -                    z = -z; -                    break; -                case SensorManager.SENSOR_MAGNETIC_FIELD: -                    x = -x; -                    y = -y; -                    break; -            } -            values[0] = x; -            values[1] = y; -            values[2] = z; -            values[3] = x; -            values[4] = y; -            values[5] = z; -            // TODO: add support for 180 and 270 orientations -            if (orientation == Surface.ROTATION_90) { -                switch (sensor) { -                    case SENSOR_ACCELEROMETER: -                    case SENSOR_MAGNETIC_FIELD: -                        values[0] =-y; -                        values[1] = x; -                        values[2] = z; -                        break; -                    case SENSOR_ORIENTATION: -                    case SENSOR_ORIENTATION_RAW: -                        values[0] = x + ((x < 270) ? 90 : -270); -                        values[1] = z; -                        values[2] = y; -                        break; -                } -            } -        } -    } - -    class LmsFilter { -        private static final int SENSORS_RATE_MS = 20; -        private static final int COUNT = 12; -        private static final float PREDICTION_RATIO = 1.0f/3.0f; -        private static final float PREDICTION_TIME = (SENSORS_RATE_MS*COUNT/1000.0f)*PREDICTION_RATIO; -        private float mV[] = new float[COUNT*2]; -        private float mT[] = new float[COUNT*2]; -        private int mIndex; - -        public LmsFilter() { -            mIndex = COUNT; -        } - -        public float filter(long time, float in) { -            float v = in; -            final float ns = 1.0f / 1000000000.0f; -            final float t = time*ns; -            float v1 = mV[mIndex]; -            if ((v-v1) > 180) { -                v -= 360; -            } else if ((v1-v) > 180) { -                v += 360; -            } -            /* Manage the circular buffer, we write the data twice spaced -             * by COUNT values, so that we don't have to copy the array -             * when it's full -             */ -            mIndex++; -            if (mIndex >= COUNT*2) -                mIndex = COUNT; -            mV[mIndex] = v; -            mT[mIndex] = t; -            mV[mIndex-COUNT] = v; -            mT[mIndex-COUNT] = t; - -            float A, B, C, D, E; -            float a, b; -            int i; - -            A = B = C = D = E = 0; -            for (i=0 ; i<COUNT-1 ; i++) { -                final int j = mIndex - 1 - i; -                final float Z = mV[j]; -                final float T = 0.5f*(mT[j] + mT[j+1]) - t; -                float dT = mT[j] - mT[j+1]; -                dT *= dT; -                A += Z*dT; -                B += T*(T*dT); -                C +=   (T*dT); -                D += Z*(T*dT); -                E += dT; -            } -            b = (A*B + C*D) / (E*B + C*C); -            a = (E*b - A) / C; -            float f = b + PREDICTION_TIME*a; - -            // Normalize -            f *= (1.0f / 360.0f); -            if (((f>=0)?f:-f) >= 0.5f) -                f = f - (float)Math.ceil(f + 0.5f) + 1.0f; -            if (f < 0) -                f += 1.0f; -            f *= 360.0f; -            return f; -        } -    } - - -    private static native void nativeClassInit(); - -    private static native int sensors_module_init(); -    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 fd); -    static native int sensors_data_close(); -    static native int sensors_data_poll(float[] values, int[] status, long[] timestamp); -} diff --git a/core/java/android/hardware/package.html b/core/java/android/hardware/package.html deleted file mode 100644 index 06788a6..0000000 --- a/core/java/android/hardware/package.html +++ /dev/null @@ -1,5 +0,0 @@ -<HTML> -<BODY> -Provides support for hardware devices that may not be present on every Android device. -</BODY> -</HTML> | 
