1a29583553957a19755bfba26f48b6ebe977879cbPeng Xu/* 2a29583553957a19755bfba26f48b6ebe977879cbPeng Xu * Copyright (C) 2016 The Android Open Source Project 3a29583553957a19755bfba26f48b6ebe977879cbPeng Xu * 4a29583553957a19755bfba26f48b6ebe977879cbPeng Xu * Licensed under the Apache License, Version 2.0 (the "License"); 5a29583553957a19755bfba26f48b6ebe977879cbPeng Xu * you may not use this file except in compliance with the License. 6a29583553957a19755bfba26f48b6ebe977879cbPeng Xu * You may obtain a copy of the License at 7a29583553957a19755bfba26f48b6ebe977879cbPeng Xu * 8a29583553957a19755bfba26f48b6ebe977879cbPeng Xu * http://www.apache.org/licenses/LICENSE-2.0 9a29583553957a19755bfba26f48b6ebe977879cbPeng Xu * 10a29583553957a19755bfba26f48b6ebe977879cbPeng Xu * Unless required by applicable law or agreed to in writing, software 11a29583553957a19755bfba26f48b6ebe977879cbPeng Xu * distributed under the License is distributed on an "AS IS" BASIS, 12a29583553957a19755bfba26f48b6ebe977879cbPeng Xu * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13a29583553957a19755bfba26f48b6ebe977879cbPeng Xu * See the License for the specific language governing permissions and 14a29583553957a19755bfba26f48b6ebe977879cbPeng Xu * limitations under the License. 15a29583553957a19755bfba26f48b6ebe977879cbPeng Xu */ 16a29583553957a19755bfba26f48b6ebe977879cbPeng Xu 17a29583553957a19755bfba26f48b6ebe977879cbPeng Xupackage android.hardware; 18a29583553957a19755bfba26f48b6ebe977879cbPeng Xu 19a29583553957a19755bfba26f48b6ebe977879cbPeng Xuimport android.annotation.IntDef; 20a29583553957a19755bfba26f48b6ebe977879cbPeng Xu 21a29583553957a19755bfba26f48b6ebe977879cbPeng Xuimport java.lang.annotation.Retention; 22a29583553957a19755bfba26f48b6ebe977879cbPeng Xuimport java.lang.annotation.RetentionPolicy; 23a29583553957a19755bfba26f48b6ebe977879cbPeng Xu 24a29583553957a19755bfba26f48b6ebe977879cbPeng Xu/** 25a29583553957a19755bfba26f48b6ebe977879cbPeng Xu * This class represents a {@link android.hardware.Sensor Sensor} additional information frame, 26a29583553957a19755bfba26f48b6ebe977879cbPeng Xu * which is reported through listener callback {@link 27a29583553957a19755bfba26f48b6ebe977879cbPeng Xu * android.hardware.SensorEventCallback#onSensorAdditionalInfo onSensorAdditionalInfo}. 28a29583553957a19755bfba26f48b6ebe977879cbPeng Xu * 29a29583553957a19755bfba26f48b6ebe977879cbPeng Xu * @see SensorManager 30fb1c94133b0cddd5550522b476f4ab69cc0ec73bPeng Xu * @see SensorEventCallback 31a29583553957a19755bfba26f48b6ebe977879cbPeng Xu * @see Sensor 32a29583553957a19755bfba26f48b6ebe977879cbPeng Xu * 33a29583553957a19755bfba26f48b6ebe977879cbPeng Xu */ 34a29583553957a19755bfba26f48b6ebe977879cbPeng Xu 35a29583553957a19755bfba26f48b6ebe977879cbPeng Xupublic class SensorAdditionalInfo { 36a29583553957a19755bfba26f48b6ebe977879cbPeng Xu 37a29583553957a19755bfba26f48b6ebe977879cbPeng Xu /** 38a29583553957a19755bfba26f48b6ebe977879cbPeng Xu * The sensor that generated this event. See 39a29583553957a19755bfba26f48b6ebe977879cbPeng Xu * {@link android.hardware.SensorManager SensorManager} for details. 40a29583553957a19755bfba26f48b6ebe977879cbPeng Xu */ 41a29583553957a19755bfba26f48b6ebe977879cbPeng Xu public final Sensor sensor; 42a29583553957a19755bfba26f48b6ebe977879cbPeng Xu 43a29583553957a19755bfba26f48b6ebe977879cbPeng Xu /** 44a29583553957a19755bfba26f48b6ebe977879cbPeng Xu * Type of this additional info frame. 45a29583553957a19755bfba26f48b6ebe977879cbPeng Xu */ 46a29583553957a19755bfba26f48b6ebe977879cbPeng Xu public final int type; 47a29583553957a19755bfba26f48b6ebe977879cbPeng Xu 48a29583553957a19755bfba26f48b6ebe977879cbPeng Xu /** 49a29583553957a19755bfba26f48b6ebe977879cbPeng Xu * Sequence number of frame for a certain type. 50a29583553957a19755bfba26f48b6ebe977879cbPeng Xu */ 51a29583553957a19755bfba26f48b6ebe977879cbPeng Xu public final int serial; 52a29583553957a19755bfba26f48b6ebe977879cbPeng Xu 53a29583553957a19755bfba26f48b6ebe977879cbPeng Xu /** 54a29583553957a19755bfba26f48b6ebe977879cbPeng Xu * Additional info payload data represented in float values. Depending on the type of 55a29583553957a19755bfba26f48b6ebe977879cbPeng Xu * information, this may be null. 56a29583553957a19755bfba26f48b6ebe977879cbPeng Xu */ 57a29583553957a19755bfba26f48b6ebe977879cbPeng Xu public final float[] floatValues; 58a29583553957a19755bfba26f48b6ebe977879cbPeng Xu 59a29583553957a19755bfba26f48b6ebe977879cbPeng Xu /** 60a29583553957a19755bfba26f48b6ebe977879cbPeng Xu * Additional info payload data represented in int values. Depending on the type of information, 61a29583553957a19755bfba26f48b6ebe977879cbPeng Xu * this may be null. 62a29583553957a19755bfba26f48b6ebe977879cbPeng Xu */ 63a29583553957a19755bfba26f48b6ebe977879cbPeng Xu public final int[] intValues; 64a29583553957a19755bfba26f48b6ebe977879cbPeng Xu 65a29583553957a19755bfba26f48b6ebe977879cbPeng Xu /** 66a29583553957a19755bfba26f48b6ebe977879cbPeng Xu * Typical values of additional infomation type. The set of values is subject to extension in 67a29583553957a19755bfba26f48b6ebe977879cbPeng Xu * newer versions and vendors have the freedom of define their own custom values. 68a29583553957a19755bfba26f48b6ebe977879cbPeng Xu * 69a29583553957a19755bfba26f48b6ebe977879cbPeng Xu * @hide 70a29583553957a19755bfba26f48b6ebe977879cbPeng Xu */ 71a29583553957a19755bfba26f48b6ebe977879cbPeng Xu @IntDef({TYPE_FRAME_BEGIN, TYPE_FRAME_END, TYPE_UNTRACKED_DELAY, TYPE_INTERNAL_TEMPERATURE, 72a29583553957a19755bfba26f48b6ebe977879cbPeng Xu TYPE_VEC3_CALIBRATION, TYPE_SENSOR_PLACEMENT, TYPE_SAMPLING}) 73a29583553957a19755bfba26f48b6ebe977879cbPeng Xu @Retention(RetentionPolicy.SOURCE) 74a29583553957a19755bfba26f48b6ebe977879cbPeng Xu public @interface AdditionalInfoType {} 75a29583553957a19755bfba26f48b6ebe977879cbPeng Xu 76a29583553957a19755bfba26f48b6ebe977879cbPeng Xu /** 77a29583553957a19755bfba26f48b6ebe977879cbPeng Xu * Mark the beginning of a set of additional info frames. 78a29583553957a19755bfba26f48b6ebe977879cbPeng Xu */ 79a29583553957a19755bfba26f48b6ebe977879cbPeng Xu public static final int TYPE_FRAME_BEGIN = 0; 80a29583553957a19755bfba26f48b6ebe977879cbPeng Xu 81a29583553957a19755bfba26f48b6ebe977879cbPeng Xu /** 82a29583553957a19755bfba26f48b6ebe977879cbPeng Xu * Mark the end of a set of additional info frames. 83a29583553957a19755bfba26f48b6ebe977879cbPeng Xu */ 84a29583553957a19755bfba26f48b6ebe977879cbPeng Xu public static final int TYPE_FRAME_END = 1; 85a29583553957a19755bfba26f48b6ebe977879cbPeng Xu 86a29583553957a19755bfba26f48b6ebe977879cbPeng Xu /** 87a29583553957a19755bfba26f48b6ebe977879cbPeng Xu * Untracked delay. Delays that are introduced by data processing, such as filtering, which is 88a29583553957a19755bfba26f48b6ebe977879cbPeng Xu * not taken into account by sensor timestamps. 89a29583553957a19755bfba26f48b6ebe977879cbPeng Xu * 90a29583553957a19755bfba26f48b6ebe977879cbPeng Xu * Payload: 91a29583553957a19755bfba26f48b6ebe977879cbPeng Xu * floatValues[0]: delay estimation in seconds 92a29583553957a19755bfba26f48b6ebe977879cbPeng Xu * floatValues[1]: delay estimation standard deviation 93a29583553957a19755bfba26f48b6ebe977879cbPeng Xu */ 94a29583553957a19755bfba26f48b6ebe977879cbPeng Xu public static final int TYPE_UNTRACKED_DELAY = 0x10000; 95a29583553957a19755bfba26f48b6ebe977879cbPeng Xu 96a29583553957a19755bfba26f48b6ebe977879cbPeng Xu /** 97a29583553957a19755bfba26f48b6ebe977879cbPeng Xu * Internal temperature. Sensor hardware device internal temperature. 98a29583553957a19755bfba26f48b6ebe977879cbPeng Xu * 99a29583553957a19755bfba26f48b6ebe977879cbPeng Xu * Payload: 100a29583553957a19755bfba26f48b6ebe977879cbPeng Xu * floatValues[0]: internal temperature in Celsius. 101a29583553957a19755bfba26f48b6ebe977879cbPeng Xu */ 102a29583553957a19755bfba26f48b6ebe977879cbPeng Xu public static final int TYPE_INTERNAL_TEMPERATURE = 0x10001; 103a29583553957a19755bfba26f48b6ebe977879cbPeng Xu 104a29583553957a19755bfba26f48b6ebe977879cbPeng Xu /** 105a29583553957a19755bfba26f48b6ebe977879cbPeng Xu * Vector calibration parameter. Calibration applied to a sensor with 3 elements vector output, 106a29583553957a19755bfba26f48b6ebe977879cbPeng Xu * such as accelerometer, gyro, etc. 107a29583553957a19755bfba26f48b6ebe977879cbPeng Xu * 108a29583553957a19755bfba26f48b6ebe977879cbPeng Xu * Payload: 109fb1c94133b0cddd5550522b476f4ab69cc0ec73bPeng Xu * floatValues[0..11]: First 3 rows of a homogeneous matrix in row major order that captures 110a29583553957a19755bfba26f48b6ebe977879cbPeng Xu * any linear transformation, including rotation, scaling, shear, shift. 111a29583553957a19755bfba26f48b6ebe977879cbPeng Xu */ 112a29583553957a19755bfba26f48b6ebe977879cbPeng Xu public static final int TYPE_VEC3_CALIBRATION = 0x10002; 113a29583553957a19755bfba26f48b6ebe977879cbPeng Xu 114a29583553957a19755bfba26f48b6ebe977879cbPeng Xu /** 115a29583553957a19755bfba26f48b6ebe977879cbPeng Xu * Sensor placement. Describes location and installation angle of the sensor device. 116a29583553957a19755bfba26f48b6ebe977879cbPeng Xu * 117a29583553957a19755bfba26f48b6ebe977879cbPeng Xu * Payload: 118a29583553957a19755bfba26f48b6ebe977879cbPeng Xu * floatValues[0..11]: First 3 rows of homogeneous matrix in row major order that describes 119a29583553957a19755bfba26f48b6ebe977879cbPeng Xu * the location and orientation of the sensor. Origin of reference will be the mobile device 120a29583553957a19755bfba26f48b6ebe977879cbPeng Xu * geometric sensor. Reference frame is defined as the same as Android sensor frame. 121a29583553957a19755bfba26f48b6ebe977879cbPeng Xu */ 122a29583553957a19755bfba26f48b6ebe977879cbPeng Xu public static final int TYPE_SENSOR_PLACEMENT = 0x10003; 123a29583553957a19755bfba26f48b6ebe977879cbPeng Xu 124a29583553957a19755bfba26f48b6ebe977879cbPeng Xu /** 125a29583553957a19755bfba26f48b6ebe977879cbPeng Xu * Sampling parameter. Describes the raw sample period and estimated jitter of sample time in 126a29583553957a19755bfba26f48b6ebe977879cbPeng Xu * terms of standard deviation. 127a29583553957a19755bfba26f48b6ebe977879cbPeng Xu * 128a29583553957a19755bfba26f48b6ebe977879cbPeng Xu * Payload: 129a29583553957a19755bfba26f48b6ebe977879cbPeng Xu * floatValues[0]: raw sample period in seconds. 130a29583553957a19755bfba26f48b6ebe977879cbPeng Xu * floatValues[1]: standard deviation of sampling period. 131a29583553957a19755bfba26f48b6ebe977879cbPeng Xu */ 132a29583553957a19755bfba26f48b6ebe977879cbPeng Xu public static final int TYPE_SAMPLING = 0x10004; 133a29583553957a19755bfba26f48b6ebe977879cbPeng Xu 1341cfde25e4019bc050c7f030896825fd90d69baf5Peng Xu /** 1351cfde25e4019bc050c7f030896825fd90d69baf5Peng Xu * Local geo-magnetic Field. 1361cfde25e4019bc050c7f030896825fd90d69baf5Peng Xu * 1371cfde25e4019bc050c7f030896825fd90d69baf5Peng Xu * Additional into to sensor hardware. Local geomagnetic field information based on 1381cfde25e4019bc050c7f030896825fd90d69baf5Peng Xu * device geo location. This type is primarily for for magnetic field calibration and rotation 1391cfde25e4019bc050c7f030896825fd90d69baf5Peng Xu * vector sensor fusion. 1401cfde25e4019bc050c7f030896825fd90d69baf5Peng Xu * 1411cfde25e4019bc050c7f030896825fd90d69baf5Peng Xu * float[3]: strength (uT), declination and inclination angle (rad). 1421cfde25e4019bc050c7f030896825fd90d69baf5Peng Xu * @hide 1431cfde25e4019bc050c7f030896825fd90d69baf5Peng Xu */ 1441cfde25e4019bc050c7f030896825fd90d69baf5Peng Xu public static final int TYPE_LOCAL_GEOMAGNETIC_FIELD = 0x30000; 1451cfde25e4019bc050c7f030896825fd90d69baf5Peng Xu 1461cfde25e4019bc050c7f030896825fd90d69baf5Peng Xu /** 1471cfde25e4019bc050c7f030896825fd90d69baf5Peng Xu * Local gravity acceleration strength. 1481cfde25e4019bc050c7f030896825fd90d69baf5Peng Xu * 1491cfde25e4019bc050c7f030896825fd90d69baf5Peng Xu * Additional info to sensor hardware for accelerometer calibration. 1501cfde25e4019bc050c7f030896825fd90d69baf5Peng Xu * 1511cfde25e4019bc050c7f030896825fd90d69baf5Peng Xu * float: gravitational acceleration norm in m/s^2. 1521cfde25e4019bc050c7f030896825fd90d69baf5Peng Xu * @hide 1531cfde25e4019bc050c7f030896825fd90d69baf5Peng Xu */ 1541cfde25e4019bc050c7f030896825fd90d69baf5Peng Xu public static final int TYPE_LOCAL_GRAVITY = 0x30001; 1551cfde25e4019bc050c7f030896825fd90d69baf5Peng Xu 1561cfde25e4019bc050c7f030896825fd90d69baf5Peng Xu /** 1571cfde25e4019bc050c7f030896825fd90d69baf5Peng Xu * Device dock state. 1581cfde25e4019bc050c7f030896825fd90d69baf5Peng Xu * 1591cfde25e4019bc050c7f030896825fd90d69baf5Peng Xu * Additional info to sensor hardware indicating dock states of device. 1601cfde25e4019bc050c7f030896825fd90d69baf5Peng Xu * 1611cfde25e4019bc050c7f030896825fd90d69baf5Peng Xu * int32_t: dock state following definition of {@link android.content.Intent#EXTRA_DOCK_STATE}. 1621cfde25e4019bc050c7f030896825fd90d69baf5Peng Xu * Undefined values are ignored. 1631cfde25e4019bc050c7f030896825fd90d69baf5Peng Xu * @hide 1641cfde25e4019bc050c7f030896825fd90d69baf5Peng Xu */ 1651cfde25e4019bc050c7f030896825fd90d69baf5Peng Xu public static final int TYPE_DOCK_STATE = 0x30002; 1661cfde25e4019bc050c7f030896825fd90d69baf5Peng Xu 1671cfde25e4019bc050c7f030896825fd90d69baf5Peng Xu /** 1681cfde25e4019bc050c7f030896825fd90d69baf5Peng Xu * High performance mode. 1691cfde25e4019bc050c7f030896825fd90d69baf5Peng Xu * 1701cfde25e4019bc050c7f030896825fd90d69baf5Peng Xu * Additional info to sensor hardware. Device is able to use up more power and take more 1711cfde25e4019bc050c7f030896825fd90d69baf5Peng Xu * resources to improve throughput and latency in high performance mode. One possible use case 1721cfde25e4019bc050c7f030896825fd90d69baf5Peng Xu * is virtual reality, when sensor latency need to be carefully controlled. 1731cfde25e4019bc050c7f030896825fd90d69baf5Peng Xu * 1741cfde25e4019bc050c7f030896825fd90d69baf5Peng Xu * int32_t: 1 or 0, denoting device is in or out of high performance mode, respectively. 1751cfde25e4019bc050c7f030896825fd90d69baf5Peng Xu * Other values are ignored. 1761cfde25e4019bc050c7f030896825fd90d69baf5Peng Xu * @hide 1771cfde25e4019bc050c7f030896825fd90d69baf5Peng Xu */ 1781cfde25e4019bc050c7f030896825fd90d69baf5Peng Xu public static final int TYPE_HIGH_PERFORMANCE_MODE = 0x30003; 1791cfde25e4019bc050c7f030896825fd90d69baf5Peng Xu 1801cfde25e4019bc050c7f030896825fd90d69baf5Peng Xu /** 1811cfde25e4019bc050c7f030896825fd90d69baf5Peng Xu * Magnetic field calibration hint. 1821cfde25e4019bc050c7f030896825fd90d69baf5Peng Xu * 1831cfde25e4019bc050c7f030896825fd90d69baf5Peng Xu * Additional info to sensor hardware. Device is notified when manually triggered magnetic field 1841cfde25e4019bc050c7f030896825fd90d69baf5Peng Xu * calibration procedure is started or stopped. The calibration procedure is assumed timed out 1851cfde25e4019bc050c7f030896825fd90d69baf5Peng Xu * after 1 minute from start, even if an explicit stop is not received. 1861cfde25e4019bc050c7f030896825fd90d69baf5Peng Xu * 1871cfde25e4019bc050c7f030896825fd90d69baf5Peng Xu * int32_t: 1 for calibration start, 0 for stop, other values are ignored. 1881cfde25e4019bc050c7f030896825fd90d69baf5Peng Xu * @hide 1891cfde25e4019bc050c7f030896825fd90d69baf5Peng Xu */ 1901cfde25e4019bc050c7f030896825fd90d69baf5Peng Xu public static final int TYPE_MAGNETIC_FIELD_CALIBRATION = 0x30004; 1911cfde25e4019bc050c7f030896825fd90d69baf5Peng Xu 192a29583553957a19755bfba26f48b6ebe977879cbPeng Xu SensorAdditionalInfo( 193a29583553957a19755bfba26f48b6ebe977879cbPeng Xu Sensor aSensor, int aType, int aSerial, int [] aIntValues, float [] aFloatValues) { 194a29583553957a19755bfba26f48b6ebe977879cbPeng Xu sensor = aSensor; 195a29583553957a19755bfba26f48b6ebe977879cbPeng Xu type = aType; 196a29583553957a19755bfba26f48b6ebe977879cbPeng Xu serial = aSerial; 197a29583553957a19755bfba26f48b6ebe977879cbPeng Xu intValues = aIntValues; 198a29583553957a19755bfba26f48b6ebe977879cbPeng Xu floatValues = aFloatValues; 199a29583553957a19755bfba26f48b6ebe977879cbPeng Xu } 2001cfde25e4019bc050c7f030896825fd90d69baf5Peng Xu 2011cfde25e4019bc050c7f030896825fd90d69baf5Peng Xu /** @hide */ 2021cfde25e4019bc050c7f030896825fd90d69baf5Peng Xu public static SensorAdditionalInfo createLocalGeomagneticField( 2031cfde25e4019bc050c7f030896825fd90d69baf5Peng Xu float strength, float declination, float inclination) { 2041cfde25e4019bc050c7f030896825fd90d69baf5Peng Xu if (strength < 10 || strength > 100 // much beyond extreme values on earth 2051cfde25e4019bc050c7f030896825fd90d69baf5Peng Xu || declination < 0 || declination > Math.PI 2061cfde25e4019bc050c7f030896825fd90d69baf5Peng Xu || inclination < -Math.PI / 2 || inclination > Math.PI / 2) { 2071cfde25e4019bc050c7f030896825fd90d69baf5Peng Xu throw new IllegalArgumentException("Geomagnetic field info out of range"); 2081cfde25e4019bc050c7f030896825fd90d69baf5Peng Xu } 2091cfde25e4019bc050c7f030896825fd90d69baf5Peng Xu 2101cfde25e4019bc050c7f030896825fd90d69baf5Peng Xu return new SensorAdditionalInfo( 2111cfde25e4019bc050c7f030896825fd90d69baf5Peng Xu null, TYPE_LOCAL_GEOMAGNETIC_FIELD, 0, 2121cfde25e4019bc050c7f030896825fd90d69baf5Peng Xu null, new float[] { strength, declination, inclination}); 2131cfde25e4019bc050c7f030896825fd90d69baf5Peng Xu } 214a29583553957a19755bfba26f48b6ebe977879cbPeng Xu} 215