1*4d7e907cSAndroid Build Coastguard Worker/* 2*4d7e907cSAndroid Build Coastguard Worker * Copyright (C) 2020 The Android Open Source Project 3*4d7e907cSAndroid Build Coastguard Worker * 4*4d7e907cSAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License"); 5*4d7e907cSAndroid Build Coastguard Worker * you may not use this file except in compliance with the License. 6*4d7e907cSAndroid Build Coastguard Worker * You may obtain a copy of the License at 7*4d7e907cSAndroid Build Coastguard Worker * 8*4d7e907cSAndroid Build Coastguard Worker * http://www.apache.org/licenses/LICENSE-2.0 9*4d7e907cSAndroid Build Coastguard Worker * 10*4d7e907cSAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software 11*4d7e907cSAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS, 12*4d7e907cSAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13*4d7e907cSAndroid Build Coastguard Worker * See the License for the specific language governing permissions and 14*4d7e907cSAndroid Build Coastguard Worker * limitations under the License. 15*4d7e907cSAndroid Build Coastguard Worker */ 16*4d7e907cSAndroid Build Coastguard Worker 17*4d7e907cSAndroid Build Coastguard Workerpackage [email protected]; 18*4d7e907cSAndroid Build Coastguard Worker 19*4d7e907cSAndroid Build Coastguard Workerimport @1.0::Result; 20*4d7e907cSAndroid Build Coastguard Workerimport @2.0::ISensors; 21*4d7e907cSAndroid Build Coastguard Workerimport @2.1::ISensorsCallback; 22*4d7e907cSAndroid Build Coastguard Worker 23*4d7e907cSAndroid Build Coastguard Workerinterface ISensors extends @2.0::ISensors { 24*4d7e907cSAndroid Build Coastguard Worker /** 25*4d7e907cSAndroid Build Coastguard Worker * Enumerate all available (static) sensors. 26*4d7e907cSAndroid Build Coastguard Worker * 27*4d7e907cSAndroid Build Coastguard Worker * The SensorInfo for each sensor returned by getSensorsList must be stable 28*4d7e907cSAndroid Build Coastguard Worker * from the initial call to getSensorsList after a device boot until the 29*4d7e907cSAndroid Build Coastguard Worker * entire system restarts. The SensorInfo for each sensor must not change 30*4d7e907cSAndroid Build Coastguard Worker * between subsequent calls to getSensorsList, even across restarts of the 31*4d7e907cSAndroid Build Coastguard Worker * HAL and its dependencies (for example, the sensor handle for a given 32*4d7e907cSAndroid Build Coastguard Worker * sensor must not change across HAL restarts). 33*4d7e907cSAndroid Build Coastguard Worker */ 34*4d7e907cSAndroid Build Coastguard Worker getSensorsList_2_1() generates (vec<SensorInfo> list); 35*4d7e907cSAndroid Build Coastguard Worker 36*4d7e907cSAndroid Build Coastguard Worker /** 37*4d7e907cSAndroid Build Coastguard Worker * Initialize the Sensors HAL's Fast Message Queues (FMQ) and callback. 38*4d7e907cSAndroid Build Coastguard Worker * 39*4d7e907cSAndroid Build Coastguard Worker * The Fast Message Queues (FMQ) that are used to send data between the 40*4d7e907cSAndroid Build Coastguard Worker * framework and the HAL. The callback is used by the HAL to notify the 41*4d7e907cSAndroid Build Coastguard Worker * framework of asynchronous events, such as a dynamic sensor connection. 42*4d7e907cSAndroid Build Coastguard Worker * 43*4d7e907cSAndroid Build Coastguard Worker * The Event FMQ is used to transport sensor events from the HAL to the 44*4d7e907cSAndroid Build Coastguard Worker * framework. The Event FMQ is created using the eventQueueDescriptor. 45*4d7e907cSAndroid Build Coastguard Worker * Data may only be written to the Event FMQ. Data must not be read from 46*4d7e907cSAndroid Build Coastguard Worker * the Event FMQ since the framework is the only reader. Upon receiving 47*4d7e907cSAndroid Build Coastguard Worker * sensor events, the HAL writes the sensor events to the Event FMQ. 48*4d7e907cSAndroid Build Coastguard Worker * 49*4d7e907cSAndroid Build Coastguard Worker * Once the HAL is finished writing sensor events to the Event FMQ, the HAL 50*4d7e907cSAndroid Build Coastguard Worker * must notify the framework that sensor events are available to be read and 51*4d7e907cSAndroid Build Coastguard Worker * processed. This is accomplished by either: 52*4d7e907cSAndroid Build Coastguard Worker * 1) Calling the Event FMQ’s EventFlag::wake() function with 53*4d7e907cSAndroid Build Coastguard Worker EventQueueFlagBits::READ_AND_PROCESS 54*4d7e907cSAndroid Build Coastguard Worker * 2) Setting the write notification in the Event FMQ’s writeBlocking() 55*4d7e907cSAndroid Build Coastguard Worker * function to EventQueueFlagBits::READ_AND_PROCESS. 56*4d7e907cSAndroid Build Coastguard Worker * 57*4d7e907cSAndroid Build Coastguard Worker * If the Event FMQ’s writeBlocking() function is used, the read 58*4d7e907cSAndroid Build Coastguard Worker * notification must be set to EventQueueFlagBits::EVENTS_READ in order to 59*4d7e907cSAndroid Build Coastguard Worker * be notified and unblocked when the framework has successfully read events 60*4d7e907cSAndroid Build Coastguard Worker * from the Event FMQ. 61*4d7e907cSAndroid Build Coastguard Worker * 62*4d7e907cSAndroid Build Coastguard Worker * The Wake Lock FMQ is used by the framework to notify the HAL when it is 63*4d7e907cSAndroid Build Coastguard Worker * safe to release its wake_lock. When the framework receives WAKE_UP events 64*4d7e907cSAndroid Build Coastguard Worker * from the Event FMQ and the framework has acquired a wake_lock, the 65*4d7e907cSAndroid Build Coastguard Worker * framework must write the number of WAKE_UP events processed to the Wake 66*4d7e907cSAndroid Build Coastguard Worker * Lock FMQ. When the HAL reads the data from the Wake Lock FMQ, the HAL 67*4d7e907cSAndroid Build Coastguard Worker * decrements its current count of unprocessed WAKE_UP events and releases 68*4d7e907cSAndroid Build Coastguard Worker * its wake_lock if the current count of unprocessed WAKE_UP events is 69*4d7e907cSAndroid Build Coastguard Worker * zero. It is important to note that the HAL must acquire the wake lock and 70*4d7e907cSAndroid Build Coastguard Worker * update its internal state regarding the number of outstanding WAKE_UP 71*4d7e907cSAndroid Build Coastguard Worker * events _before_ posting the event to the Wake Lock FMQ, in order to avoid 72*4d7e907cSAndroid Build Coastguard Worker * a race condition that can lead to loss of wake lock synchronization with 73*4d7e907cSAndroid Build Coastguard Worker * the framework. 74*4d7e907cSAndroid Build Coastguard Worker * 75*4d7e907cSAndroid Build Coastguard Worker * The framework must use the WakeLockQueueFlagBits::DATA_WRITTEN value to 76*4d7e907cSAndroid Build Coastguard Worker * notify the HAL that data has been written to the Wake Lock FMQ and must 77*4d7e907cSAndroid Build Coastguard Worker * be read by HAL. 78*4d7e907cSAndroid Build Coastguard Worker * 79*4d7e907cSAndroid Build Coastguard Worker * The ISensorsCallback is used by the HAL to notify the framework of 80*4d7e907cSAndroid Build Coastguard Worker * asynchronous events, such as a dynamic sensor connection. 81*4d7e907cSAndroid Build Coastguard Worker * 82*4d7e907cSAndroid Build Coastguard Worker * The name of any wake_lock acquired by the Sensors HAL for WAKE_UP events 83*4d7e907cSAndroid Build Coastguard Worker * must begin with "SensorsHAL_WAKEUP". 84*4d7e907cSAndroid Build Coastguard Worker * 85*4d7e907cSAndroid Build Coastguard Worker * If WAKE_LOCK_TIMEOUT_SECONDS has elapsed since the most recent WAKE_UP 86*4d7e907cSAndroid Build Coastguard Worker * event was written to the Event FMQ without receiving a message on the 87*4d7e907cSAndroid Build Coastguard Worker * Wake Lock FMQ, then any held wake_lock for WAKE_UP events must be 88*4d7e907cSAndroid Build Coastguard Worker * released. 89*4d7e907cSAndroid Build Coastguard Worker * 90*4d7e907cSAndroid Build Coastguard Worker * If either the Event FMQ or the Wake Lock FMQ is already initialized when 91*4d7e907cSAndroid Build Coastguard Worker * initialize is invoked, then both existing FMQs must be discarded and the 92*4d7e907cSAndroid Build Coastguard Worker * new descriptors must be used to create new FMQs within the HAL. The 93*4d7e907cSAndroid Build Coastguard Worker * number of outstanding WAKE_UP events should also be reset to zero, and 94*4d7e907cSAndroid Build Coastguard Worker * any outstanding wake_locks held as a result of WAKE_UP events should be 95*4d7e907cSAndroid Build Coastguard Worker * released. 96*4d7e907cSAndroid Build Coastguard Worker * 97*4d7e907cSAndroid Build Coastguard Worker * All active sensor requests and direct channels must be closed and 98*4d7e907cSAndroid Build Coastguard Worker * properly cleaned up when initialize is called in order to ensure that the 99*4d7e907cSAndroid Build Coastguard Worker * HAL and framework's state is consistent (e.g. after a runtime restart). 100*4d7e907cSAndroid Build Coastguard Worker * 101*4d7e907cSAndroid Build Coastguard Worker * initialize must be thread safe and prevent concurrent calls 102*4d7e907cSAndroid Build Coastguard Worker * to initialize from simultaneously modifying state. 103*4d7e907cSAndroid Build Coastguard Worker * 104*4d7e907cSAndroid Build Coastguard Worker * @param eventQueueDescriptor Fast Message Queue descriptor that is used to 105*4d7e907cSAndroid Build Coastguard Worker * create the Event FMQ which is where sensor events are written. The 106*4d7e907cSAndroid Build Coastguard Worker * descriptor is obtained from the framework's FMQ that is used to read 107*4d7e907cSAndroid Build Coastguard Worker * sensor events. 108*4d7e907cSAndroid Build Coastguard Worker * @param wakeLockDescriptor Fast Message Queue descriptor that is used to 109*4d7e907cSAndroid Build Coastguard Worker * create the Wake Lock FMQ which is where wake_lock events are read 110*4d7e907cSAndroid Build Coastguard Worker * from. The descriptor is obtained from the framework's FMQ that is 111*4d7e907cSAndroid Build Coastguard Worker * used to write wake_lock events. 112*4d7e907cSAndroid Build Coastguard Worker * @param sensorsCallback sensors callback that receives asynchronous data 113*4d7e907cSAndroid Build Coastguard Worker * from the Sensors HAL. 114*4d7e907cSAndroid Build Coastguard Worker * @return result OK on success; BAD_VALUE if descriptor is invalid (such 115*4d7e907cSAndroid Build Coastguard Worker * as null) 116*4d7e907cSAndroid Build Coastguard Worker */ 117*4d7e907cSAndroid Build Coastguard Worker @entry 118*4d7e907cSAndroid Build Coastguard Worker @callflow(next = {"getSensorsList"}) 119*4d7e907cSAndroid Build Coastguard Worker initialize_2_1(fmq_sync<Event> eventQueueDescriptor, 120*4d7e907cSAndroid Build Coastguard Worker fmq_sync<uint32_t> wakeLockDescriptor, 121*4d7e907cSAndroid Build Coastguard Worker ISensorsCallback sensorsCallback) 122*4d7e907cSAndroid Build Coastguard Worker generates 123*4d7e907cSAndroid Build Coastguard Worker (Result result); 124*4d7e907cSAndroid Build Coastguard Worker 125*4d7e907cSAndroid Build Coastguard Worker /** 126*4d7e907cSAndroid Build Coastguard Worker * Inject a single sensor event or push operation environment parameters to 127*4d7e907cSAndroid Build Coastguard Worker * device. 128*4d7e907cSAndroid Build Coastguard Worker * 129*4d7e907cSAndroid Build Coastguard Worker * When device is in NORMAL mode, this function is called to push operation 130*4d7e907cSAndroid Build Coastguard Worker * environment data to device. In this operation, Event is always of 131*4d7e907cSAndroid Build Coastguard Worker * SensorType::AdditionalInfo type. See operation evironment parameters 132*4d7e907cSAndroid Build Coastguard Worker * section in AdditionalInfoType. 133*4d7e907cSAndroid Build Coastguard Worker * 134*4d7e907cSAndroid Build Coastguard Worker * When device is in DATA_INJECTION mode, this function is also used for 135*4d7e907cSAndroid Build Coastguard Worker * injecting sensor events. 136*4d7e907cSAndroid Build Coastguard Worker * 137*4d7e907cSAndroid Build Coastguard Worker * Regardless of OperationMode, injected SensorType::ADDITIONAL_INFO 138*4d7e907cSAndroid Build Coastguard Worker * type events should not be routed back to the sensor event queue. 139*4d7e907cSAndroid Build Coastguard Worker * 140*4d7e907cSAndroid Build Coastguard Worker * @see AdditionalInfoType 141*4d7e907cSAndroid Build Coastguard Worker * @see OperationMode 142*4d7e907cSAndroid Build Coastguard Worker * @param event sensor event to be injected 143*4d7e907cSAndroid Build Coastguard Worker * @return result OK on success; PERMISSION_DENIED if operation is not 144*4d7e907cSAndroid Build Coastguard Worker * allowed; INVALID_OPERATION, if this functionality is unsupported; 145*4d7e907cSAndroid Build Coastguard Worker * BAD_VALUE if sensor event cannot be injected. 146*4d7e907cSAndroid Build Coastguard Worker */ 147*4d7e907cSAndroid Build Coastguard Worker injectSensorData_2_1(Event event) generates (Result result); 148*4d7e907cSAndroid Build Coastguard Worker}; 149