1/*
2 * Copyright (C) 2017 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.frameworks.sensorservice@1.0;
18
19import IDirectReportChannel;
20import IEventQueue;
21import IEventQueueCallback;
22
23import android.hardware.sensors@1.0::SensorInfo;
24import android.hardware.sensors@1.0::SensorType;
25
26/**
27 * ISensorManager is an interface to manage sensors
28 *
29 * This file provides a set of functions that uses
30 * ISensorManager to access and list hardware sensors.
31 */
32interface ISensorManager {
33
34    /**
35     * Get the list of available sensors.
36     *
37     * @return list   the list of available sensors, or empty on failure
38     * @return result OK on success or UNKNOWN_ERROR on failure
39     */
40    getSensorList() generates (vec<SensorInfo> list, Result result);
41
42    /**
43     * Get the default sensor of the specified type.
44     *
45     * @return sensor the default sensor for the given type, or undetermined
46     *                value on failure.
47     * @return result OK on success or
48                      NOT_EXIST if no sensor of that type exists.
49     */
50    getDefaultSensor(SensorType type)
51          generates (SensorInfo sensor, Result result);
52
53    /**
54     * Create direct channel based on shared memory
55     *
56     * Create a direct channel of DIRECT_CHANNEL_ASHMEM type to be used
57     * for configuring sensor direct report.
58     *
59     * The memory layout looks as follows. These offsets can be found in
60     * android.hardware.sensors@1.0::SensorsEventFormatOffset.
61     *   offset   type        name
62     *  -----------------------------------
63     *   0x0000  int32_t     size (SensorsEventFormatOffset::TOTAL_LENGTH)
64     *   0x0004  int32_t     sensor report token
65     *   0x0008  int32_t     type (see android.hardware.sensors@1.0::SensorType)
66     *   0x000C  uint32_t    atomic counter
67     *   0x0010  int64_t     timestamp (see android.hardware.sensors@1.0::Event)
68     *   0x0018  float[16]/  data
69     *           int64_t[8]
70     *   0x0058  int32_t[4]  reserved (set to zero)
71     *
72     * @param mem     the shared memory to use, must be ashmem.
73     * @param size    the intended size to be used. The following must be true:
74     *                SensorsEventFormatOffset::TOTAL_LENGTH <= size <= mem.size
75     *
76     * @return chan   The created channel, or NULL if failure.
77     * @return result OK if successful;
78     *                BAD_VALUE if size > mem.size();
79     *                BAD_VALUE if size < TOTAL_LENGTH;
80     *                NO_MEMORY, NO_INIT, BAD_VALUE for underlying errors;
81     *                UNKNOWN_ERROR if the underlying error is not recognized;
82     *                UNKNOWN_ERROR if the underlying call returns channelId = 0
83     */
84    createAshmemDirectChannel(memory mem, uint64_t size)
85                   generates (IDirectReportChannel chan, Result result);
86
87    /**
88     * Create direct channel based on hardware buffer
89     *
90     * Create a direct channel of DIRECT_CHANNEL_GRALLOC type to be used
91     * for configuring sensor direct report.
92     *
93     * @param buffer  file descriptor describing the gralloc buffer.
94     * @param size    the intended size to be used, must be less than or equal
95     *                to the size of the buffer.
96     *
97     * @return chan   The created channel, or NULL if failure.
98     * @return result OK if successful;
99     *                NO_MEMORY, NO_INIT, BAD_VALUE for underlying errors;
100     *                UNKNOWN_ERROR if the underlying error is not recognized;
101     *                UNKNOWN_ERROR if the underlying call returns channelId = 0
102     */
103    createGrallocDirectChannel(handle buffer, uint64_t size)
104                    generates (IDirectReportChannel chan, Result result);
105
106    /**
107     * Create a sensor event queue.
108     *
109     * Create a sensor event queue with an IEventQueueCallback object.
110     * Subsequently, one can enable sensors on the event queue so that sensor
111     * events are passed via the specified callback.
112     *
113     * @param  callback the callback to call on events. Must not be null.
114     * @return queue    the event queue created. null on failure.
115     * @return result   OK if successful, BAD_VALUE if callback is null,
116     *                  or other Result values for any underlying errors.
117     */
118    createEventQueue(IEventQueueCallback callback)
119          generates (IEventQueue queue, Result result);
120};
121
122
123