1462eae34ce11e8e6bf5e28dc252d2d11052694e3Aravind Akella/*
2462eae34ce11e8e6bf5e28dc252d2d11052694e3Aravind Akella * Copyright (C) 2014 The Android Open Source Project
3462eae34ce11e8e6bf5e28dc252d2d11052694e3Aravind Akella *
4462eae34ce11e8e6bf5e28dc252d2d11052694e3Aravind Akella * Licensed under the Apache License, Version 2.0 (the "License");
5462eae34ce11e8e6bf5e28dc252d2d11052694e3Aravind Akella * you may not use this file except in compliance with the License.
6462eae34ce11e8e6bf5e28dc252d2d11052694e3Aravind Akella * You may obtain a copy of the License at
7462eae34ce11e8e6bf5e28dc252d2d11052694e3Aravind Akella *
8462eae34ce11e8e6bf5e28dc252d2d11052694e3Aravind Akella *      http://www.apache.org/licenses/LICENSE-2.0
9462eae34ce11e8e6bf5e28dc252d2d11052694e3Aravind Akella *
10462eae34ce11e8e6bf5e28dc252d2d11052694e3Aravind Akella * Unless required by applicable law or agreed to in writing, software
11462eae34ce11e8e6bf5e28dc252d2d11052694e3Aravind Akella * distributed under the License is distributed on an "AS IS" BASIS,
12462eae34ce11e8e6bf5e28dc252d2d11052694e3Aravind Akella * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13462eae34ce11e8e6bf5e28dc252d2d11052694e3Aravind Akella * See the License for the specific language governing permissions and
14462eae34ce11e8e6bf5e28dc252d2d11052694e3Aravind Akella * limitations under the License.
15462eae34ce11e8e6bf5e28dc252d2d11052694e3Aravind Akella */
16462eae34ce11e8e6bf5e28dc252d2d11052694e3Aravind Akella
17462eae34ce11e8e6bf5e28dc252d2d11052694e3Aravind Akella/*
18462eae34ce11e8e6bf5e28dc252d2d11052694e3Aravind Akella * Activity Recognition HAL. The goal is to provide low power, low latency, always-on activity
19462eae34ce11e8e6bf5e28dc252d2d11052694e3Aravind Akella * recognition implemented in hardware (i.e. these activity recognition algorithms/classifers
20462eae34ce11e8e6bf5e28dc252d2d11052694e3Aravind Akella * should NOT be run on the AP). By low power we mean that this may be activated 24/7 without
21462eae34ce11e8e6bf5e28dc252d2d11052694e3Aravind Akella * impacting the battery drain speed (goal in order of 1mW including the power for sensors).
22462eae34ce11e8e6bf5e28dc252d2d11052694e3Aravind Akella * This HAL does not specify the input sources that are used towards detecting these activities.
23462eae34ce11e8e6bf5e28dc252d2d11052694e3Aravind Akella * It has one monitor interface which can be used to batch activities for always-on
24462eae34ce11e8e6bf5e28dc252d2d11052694e3Aravind Akella * activity_recognition and if the latency is zero, the same interface can be used for low latency
25462eae34ce11e8e6bf5e28dc252d2d11052694e3Aravind Akella * detection.
26462eae34ce11e8e6bf5e28dc252d2d11052694e3Aravind Akella */
27462eae34ce11e8e6bf5e28dc252d2d11052694e3Aravind Akella
28462eae34ce11e8e6bf5e28dc252d2d11052694e3Aravind Akella#ifndef ANDROID_ACTIVITY_RECOGNITION_INTERFACE_H
29462eae34ce11e8e6bf5e28dc252d2d11052694e3Aravind Akella#define ANDROID_ACTIVITY_RECOGNITION_INTERFACE_H
30462eae34ce11e8e6bf5e28dc252d2d11052694e3Aravind Akella
31462eae34ce11e8e6bf5e28dc252d2d11052694e3Aravind Akella#include <hardware/hardware.h>
32462eae34ce11e8e6bf5e28dc252d2d11052694e3Aravind Akella
33462eae34ce11e8e6bf5e28dc252d2d11052694e3Aravind Akella__BEGIN_DECLS
34462eae34ce11e8e6bf5e28dc252d2d11052694e3Aravind Akella
35462eae34ce11e8e6bf5e28dc252d2d11052694e3Aravind Akella#define ACTIVITY_RECOGNITION_HEADER_VERSION   1
36462eae34ce11e8e6bf5e28dc252d2d11052694e3Aravind Akella#define ACTIVITY_RECOGNITION_API_VERSION_0_1  HARDWARE_DEVICE_API_VERSION_2(0, 1, ACTIVITY_RECOGNITION_HEADER_VERSION)
37462eae34ce11e8e6bf5e28dc252d2d11052694e3Aravind Akella
38462eae34ce11e8e6bf5e28dc252d2d11052694e3Aravind Akella#define ACTIVITY_RECOGNITION_HARDWARE_MODULE_ID "activity_recognition"
39462eae34ce11e8e6bf5e28dc252d2d11052694e3Aravind Akella#define ACTIVITY_RECOGNITION_HARDWARE_INTERFACE "activity_recognition_hw_if"
40462eae34ce11e8e6bf5e28dc252d2d11052694e3Aravind Akella
41462eae34ce11e8e6bf5e28dc252d2d11052694e3Aravind Akella/*
42871b74873329f414ec8db3febadebf45e2003572Aravind Akella * Define types for various activities. Multiple activities may be active at the same time and
43871b74873329f414ec8db3febadebf45e2003572Aravind Akella * sometimes none of these activities may be active.
44871b74873329f414ec8db3febadebf45e2003572Aravind Akella *
45871b74873329f414ec8db3febadebf45e2003572Aravind Akella * Each activity has a corresponding type. Only activities that are defined here should use
46871b74873329f414ec8db3febadebf45e2003572Aravind Akella * android.activity_recognition.* prefix. OEM defined activities should not use this prefix.
47871b74873329f414ec8db3febadebf45e2003572Aravind Akella * Activity type of OEM-defined activities should start with the reverse domain name of the entity
48871b74873329f414ec8db3febadebf45e2003572Aravind Akella * defining the activity.
49871b74873329f414ec8db3febadebf45e2003572Aravind Akella *
50871b74873329f414ec8db3febadebf45e2003572Aravind Akella * When android introduces a new activity type that can potentially replace an OEM-defined activity
51871b74873329f414ec8db3febadebf45e2003572Aravind Akella * type, the OEM must use the official activity type on versions of the HAL that support this new
52871b74873329f414ec8db3febadebf45e2003572Aravind Akella * official activity type.
53871b74873329f414ec8db3febadebf45e2003572Aravind Akella *
54871b74873329f414ec8db3febadebf45e2003572Aravind Akella * Example (made up): Suppose Google's Glass team wants to detect nodding activity.
55871b74873329f414ec8db3febadebf45e2003572Aravind Akella *  - Such an activity is not officially supported in android L
56871b74873329f414ec8db3febadebf45e2003572Aravind Akella *  - Glass devices launching on L can implement a custom activity with
57871b74873329f414ec8db3febadebf45e2003572Aravind Akella *    type = "com.google.glass.nodding"
58871b74873329f414ec8db3febadebf45e2003572Aravind Akella *  - In M android release, if android decides to define ACITIVITY_TYPE_NODDING, those types
59871b74873329f414ec8db3febadebf45e2003572Aravind Akella *    should replace the Glass-team-specific types in all future launches.
60871b74873329f414ec8db3febadebf45e2003572Aravind Akella *  - When launching glass on the M release, Google should now use the official activity type
61871b74873329f414ec8db3febadebf45e2003572Aravind Akella *  - This way, other applications can use this activity.
62462eae34ce11e8e6bf5e28dc252d2d11052694e3Aravind Akella */
63462eae34ce11e8e6bf5e28dc252d2d11052694e3Aravind Akella
64871b74873329f414ec8db3febadebf45e2003572Aravind Akella#define ACTIVITY_TYPE_IN_VEHICLE       "android.activity_recognition.in_vehicle"
65462eae34ce11e8e6bf5e28dc252d2d11052694e3Aravind Akella
66871b74873329f414ec8db3febadebf45e2003572Aravind Akella#define ACTIVITY_TYPE_ON_BICYCLE       "android.activity_recognition.on_bicycle"
67462eae34ce11e8e6bf5e28dc252d2d11052694e3Aravind Akella
68871b74873329f414ec8db3febadebf45e2003572Aravind Akella#define ACTIVITY_TYPE_WALKING          "android.activity_recognition.walking"
69462eae34ce11e8e6bf5e28dc252d2d11052694e3Aravind Akella
70871b74873329f414ec8db3febadebf45e2003572Aravind Akella#define ACTIVITY_TYPE_RUNNING          "android.activity_recognition.running"
71462eae34ce11e8e6bf5e28dc252d2d11052694e3Aravind Akella
72871b74873329f414ec8db3febadebf45e2003572Aravind Akella#define ACTIVITY_TYPE_STILL            "android.activity_recognition.still"
73462eae34ce11e8e6bf5e28dc252d2d11052694e3Aravind Akella
74871b74873329f414ec8db3febadebf45e2003572Aravind Akella#define ACTIVITY_TYPE_TILTING          "android.activity_recognition.tilting"
75462eae34ce11e8e6bf5e28dc252d2d11052694e3Aravind Akella
76462eae34ce11e8e6bf5e28dc252d2d11052694e3Aravind Akella/* Values for activity_event.event_types. */
77462eae34ce11e8e6bf5e28dc252d2d11052694e3Aravind Akellaenum {
78462eae34ce11e8e6bf5e28dc252d2d11052694e3Aravind Akella    /*
79462eae34ce11e8e6bf5e28dc252d2d11052694e3Aravind Akella     * A flush_complete event which indicates that a flush() has been successfully completed. This
80462eae34ce11e8e6bf5e28dc252d2d11052694e3Aravind Akella     * does not correspond to any activity/event. An event of this type should be added to the end
81462eae34ce11e8e6bf5e28dc252d2d11052694e3Aravind Akella     * of a batch FIFO and it indicates that all the events in the batch FIFO have been successfully
82462eae34ce11e8e6bf5e28dc252d2d11052694e3Aravind Akella     * reported to the framework. An event of this type should be generated only if flush() has been
83462eae34ce11e8e6bf5e28dc252d2d11052694e3Aravind Akella     * explicitly called and if the FIFO is empty at the time flush() is called it should trivially
84462eae34ce11e8e6bf5e28dc252d2d11052694e3Aravind Akella     * return a flush_complete_event to indicate that the FIFO is empty.
85462eae34ce11e8e6bf5e28dc252d2d11052694e3Aravind Akella     *
86462eae34ce11e8e6bf5e28dc252d2d11052694e3Aravind Akella     * A flush complete event should have the following parameters set.
87871b74873329f414ec8db3febadebf45e2003572Aravind Akella     * activity_event_t.event_type = ACTIVITY_EVENT_FLUSH_COMPLETE
88871b74873329f414ec8db3febadebf45e2003572Aravind Akella     * activity_event_t.activity = 0
89462eae34ce11e8e6bf5e28dc252d2d11052694e3Aravind Akella     * activity_event_t.timestamp = 0
90462eae34ce11e8e6bf5e28dc252d2d11052694e3Aravind Akella     * activity_event_t.reserved = 0
91462eae34ce11e8e6bf5e28dc252d2d11052694e3Aravind Akella     * See (*flush)() for more details.
92462eae34ce11e8e6bf5e28dc252d2d11052694e3Aravind Akella     */
93871b74873329f414ec8db3febadebf45e2003572Aravind Akella    ACTIVITY_EVENT_FLUSH_COMPLETE = 0,
94462eae34ce11e8e6bf5e28dc252d2d11052694e3Aravind Akella
95462eae34ce11e8e6bf5e28dc252d2d11052694e3Aravind Akella    /* Signifies entering an activity. */
96871b74873329f414ec8db3febadebf45e2003572Aravind Akella    ACTIVITY_EVENT_ENTER = 1,
97462eae34ce11e8e6bf5e28dc252d2d11052694e3Aravind Akella
98462eae34ce11e8e6bf5e28dc252d2d11052694e3Aravind Akella    /* Signifies exiting an activity. */
99871b74873329f414ec8db3febadebf45e2003572Aravind Akella    ACTIVITY_EVENT_EXIT  = 2
100462eae34ce11e8e6bf5e28dc252d2d11052694e3Aravind Akella};
101462eae34ce11e8e6bf5e28dc252d2d11052694e3Aravind Akella
102462eae34ce11e8e6bf5e28dc252d2d11052694e3Aravind Akella/*
103462eae34ce11e8e6bf5e28dc252d2d11052694e3Aravind Akella * Each event is a separate activity with event_type indicating whether this activity has started
104153c40ce8bceb6674f605a10f98b84179cf7f204Aravind Akella * or ended. Eg event: (event_type="enter", activity="ON_FOOT", timestamp)
105462eae34ce11e8e6bf5e28dc252d2d11052694e3Aravind Akella */
106462eae34ce11e8e6bf5e28dc252d2d11052694e3Aravind Akellatypedef struct activity_event {
107871b74873329f414ec8db3febadebf45e2003572Aravind Akella    /* One of the ACTIVITY_EVENT_* constants defined above. */
108462eae34ce11e8e6bf5e28dc252d2d11052694e3Aravind Akella    uint32_t event_type;
109462eae34ce11e8e6bf5e28dc252d2d11052694e3Aravind Akella
110871b74873329f414ec8db3febadebf45e2003572Aravind Akella    /*
111871b74873329f414ec8db3febadebf45e2003572Aravind Akella     * Index of the activity in the list returned by get_supported_activities_list. If this event
112871b74873329f414ec8db3febadebf45e2003572Aravind Akella     * is a flush complete event, this should be set to zero.
113871b74873329f414ec8db3febadebf45e2003572Aravind Akella     */
114153c40ce8bceb6674f605a10f98b84179cf7f204Aravind Akella    uint32_t activity;
115462eae34ce11e8e6bf5e28dc252d2d11052694e3Aravind Akella
116462eae34ce11e8e6bf5e28dc252d2d11052694e3Aravind Akella    /* Time at which the transition/event has occurred in nanoseconds using elapsedRealTimeNano. */
117462eae34ce11e8e6bf5e28dc252d2d11052694e3Aravind Akella    int64_t timestamp;
118462eae34ce11e8e6bf5e28dc252d2d11052694e3Aravind Akella
119462eae34ce11e8e6bf5e28dc252d2d11052694e3Aravind Akella    /* Set to zero. */
120462eae34ce11e8e6bf5e28dc252d2d11052694e3Aravind Akella    int32_t reserved[4];
121462eae34ce11e8e6bf5e28dc252d2d11052694e3Aravind Akella} activity_event_t;
122462eae34ce11e8e6bf5e28dc252d2d11052694e3Aravind Akella
123462eae34ce11e8e6bf5e28dc252d2d11052694e3Aravind Akellatypedef struct activity_recognition_module {
12484d35492b145cebc000f8fd72818eb25b8e65c04Stewart Miles    /**
12584d35492b145cebc000f8fd72818eb25b8e65c04Stewart Miles     * Common methods of the activity recognition module.  This *must* be the first member of
12684d35492b145cebc000f8fd72818eb25b8e65c04Stewart Miles     * activity_recognition_module as users of this structure will cast a hw_module_t to
12784d35492b145cebc000f8fd72818eb25b8e65c04Stewart Miles     * activity_recognition_module pointer in contexts where it's known the hw_module_t
12884d35492b145cebc000f8fd72818eb25b8e65c04Stewart Miles     * references an activity_recognition_module.
12984d35492b145cebc000f8fd72818eb25b8e65c04Stewart Miles     */
130462eae34ce11e8e6bf5e28dc252d2d11052694e3Aravind Akella    hw_module_t common;
131462eae34ce11e8e6bf5e28dc252d2d11052694e3Aravind Akella
132462eae34ce11e8e6bf5e28dc252d2d11052694e3Aravind Akella    /*
133871b74873329f414ec8db3febadebf45e2003572Aravind Akella     * List of all activities supported by this module including OEM defined activities. Each
134871b74873329f414ec8db3febadebf45e2003572Aravind Akella     * activity is represented using a string defined above. Each string should be null terminated.
135871b74873329f414ec8db3febadebf45e2003572Aravind Akella     * The index of the activity in this array is used as a "handle" for enabling/disabling and
136871b74873329f414ec8db3febadebf45e2003572Aravind Akella     * event delivery.
137871b74873329f414ec8db3febadebf45e2003572Aravind Akella     * Return value is the size of this list.
138462eae34ce11e8e6bf5e28dc252d2d11052694e3Aravind Akella     */
139462eae34ce11e8e6bf5e28dc252d2d11052694e3Aravind Akella    int (*get_supported_activities_list)(struct activity_recognition_module* module,
140871b74873329f414ec8db3febadebf45e2003572Aravind Akella            char const* const* *activity_list);
141462eae34ce11e8e6bf5e28dc252d2d11052694e3Aravind Akella} activity_recognition_module_t;
142462eae34ce11e8e6bf5e28dc252d2d11052694e3Aravind Akella
143462eae34ce11e8e6bf5e28dc252d2d11052694e3Aravind Akellastruct activity_recognition_device;
144462eae34ce11e8e6bf5e28dc252d2d11052694e3Aravind Akella
145462eae34ce11e8e6bf5e28dc252d2d11052694e3Aravind Akellatypedef struct activity_recognition_callback_procs {
146462eae34ce11e8e6bf5e28dc252d2d11052694e3Aravind Akella    // Callback for activity_data. This is guaranteed to not invoke any HAL methods.
147462eae34ce11e8e6bf5e28dc252d2d11052694e3Aravind Akella    // Memory allocated for the events can be reused after this method returns.
148462eae34ce11e8e6bf5e28dc252d2d11052694e3Aravind Akella    //    events - Array of activity_event_t s that are reported.
149462eae34ce11e8e6bf5e28dc252d2d11052694e3Aravind Akella    //    count  - size of the array.
150153c40ce8bceb6674f605a10f98b84179cf7f204Aravind Akella    void (*activity_callback)(const struct activity_recognition_callback_procs* procs,
151462eae34ce11e8e6bf5e28dc252d2d11052694e3Aravind Akella            const activity_event_t* events, int count);
152462eae34ce11e8e6bf5e28dc252d2d11052694e3Aravind Akella} activity_recognition_callback_procs_t;
153462eae34ce11e8e6bf5e28dc252d2d11052694e3Aravind Akella
154462eae34ce11e8e6bf5e28dc252d2d11052694e3Aravind Akellatypedef struct activity_recognition_device {
15584d35492b145cebc000f8fd72818eb25b8e65c04Stewart Miles    /**
15684d35492b145cebc000f8fd72818eb25b8e65c04Stewart Miles     * Common methods of the activity recognition device.  This *must* be the first member of
15784d35492b145cebc000f8fd72818eb25b8e65c04Stewart Miles     * activity_recognition_device as users of this structure will cast a hw_device_t to
15884d35492b145cebc000f8fd72818eb25b8e65c04Stewart Miles     * activity_recognition_device pointer in contexts where it's known the hw_device_t
15984d35492b145cebc000f8fd72818eb25b8e65c04Stewart Miles     * references an activity_recognition_device.
16084d35492b145cebc000f8fd72818eb25b8e65c04Stewart Miles     */
161462eae34ce11e8e6bf5e28dc252d2d11052694e3Aravind Akella    hw_device_t common;
162462eae34ce11e8e6bf5e28dc252d2d11052694e3Aravind Akella
163462eae34ce11e8e6bf5e28dc252d2d11052694e3Aravind Akella    /*
164462eae34ce11e8e6bf5e28dc252d2d11052694e3Aravind Akella     * Sets the callback to invoke when there are events to report. This call overwrites the
165462eae34ce11e8e6bf5e28dc252d2d11052694e3Aravind Akella     * previously registered callback (if any).
166462eae34ce11e8e6bf5e28dc252d2d11052694e3Aravind Akella     */
167462eae34ce11e8e6bf5e28dc252d2d11052694e3Aravind Akella    void (*register_activity_callback)(const struct activity_recognition_device* dev,
168462eae34ce11e8e6bf5e28dc252d2d11052694e3Aravind Akella            const activity_recognition_callback_procs_t* callback);
169462eae34ce11e8e6bf5e28dc252d2d11052694e3Aravind Akella
170462eae34ce11e8e6bf5e28dc252d2d11052694e3Aravind Akella    /*
171153c40ce8bceb6674f605a10f98b84179cf7f204Aravind Akella     * Activates monitoring of activity transitions. Activities need not be reported as soon as they
172153c40ce8bceb6674f605a10f98b84179cf7f204Aravind Akella     * are detected. The detected activities are stored in a FIFO and reported in batches when the
173153c40ce8bceb6674f605a10f98b84179cf7f204Aravind Akella     * "max_batch_report_latency" expires or when the batch FIFO is full. The implementation should
174153c40ce8bceb6674f605a10f98b84179cf7f204Aravind Akella     * allow the AP to go into suspend mode while the activities are detected and stored in the
175153c40ce8bceb6674f605a10f98b84179cf7f204Aravind Akella     * batch FIFO. Whenever events need to be reported (like when the FIFO is full or when the
176153c40ce8bceb6674f605a10f98b84179cf7f204Aravind Akella     * max_batch_report_latency has expired for an activity, event pair), it should wake_up the AP
177153c40ce8bceb6674f605a10f98b84179cf7f204Aravind Akella     * so that no events are lost. Activities are stored as transitions and they are allowed to
178153c40ce8bceb6674f605a10f98b84179cf7f204Aravind Akella     * overlap with each other. Each (activity, event_type) pair can be activated or deactivated
179153c40ce8bceb6674f605a10f98b84179cf7f204Aravind Akella     * independently of the other. The HAL implementation needs to keep track of which pairs are
180153c40ce8bceb6674f605a10f98b84179cf7f204Aravind Akella     * currently active and needs to detect only those pairs.
181153c40ce8bceb6674f605a10f98b84179cf7f204Aravind Akella     *
182eb1bd05175bb6020b365e90f4c32eb6d68003129Chengu Wang     * At the first detection after this function gets called, the hardware should know whether the
183eb1bd05175bb6020b365e90f4c32eb6d68003129Chengu Wang     * user is in the activity.
184eb1bd05175bb6020b365e90f4c32eb6d68003129Chengu Wang     * - If event_type is ACTIVITY_EVENT_ENTER and the user is in the activity, then an
185eb1bd05175bb6020b365e90f4c32eb6d68003129Chengu Wang     *   (ACTIVITY_EVENT_ENTER, activity) event should be added to the FIFO.
186eb1bd05175bb6020b365e90f4c32eb6d68003129Chengu Wang     * - If event_type is ACTIVITY_EVENT_EXIT and the user is not in the activity, then an
187eb1bd05175bb6020b365e90f4c32eb6d68003129Chengu Wang     *   (ACTIVITY_EVENT_EXIT, activity) event should be added to the FIFO.
188eb1bd05175bb6020b365e90f4c32eb6d68003129Chengu Wang     * For example, suppose get_supported_activities_list contains on_bicyle and running, and the
189eb1bd05175bb6020b365e90f4c32eb6d68003129Chengu Wang     * user is biking. Consider the following four calls that could happen in any order.
190eb1bd05175bb6020b365e90f4c32eb6d68003129Chengu Wang     * - When enable_activity_event(on_bicycle, ACTIVITY_EVENT_ENTER) is called,
191eb1bd05175bb6020b365e90f4c32eb6d68003129Chengu Wang     *   (ACTIVITY_EVENT_ENTER, on_bicycle) should be added to the FIFO.
192eb1bd05175bb6020b365e90f4c32eb6d68003129Chengu Wang     * - When enable_activity_event(on_bicycle, ACTIVITY_EVENT_EXIT) is called, nothing should be
193eb1bd05175bb6020b365e90f4c32eb6d68003129Chengu Wang     *   added to the FIFO.
194eb1bd05175bb6020b365e90f4c32eb6d68003129Chengu Wang     * - When enable_activity_event(running, ACTIVITY_EVENT_ENTER) is called, nothing should be
195eb1bd05175bb6020b365e90f4c32eb6d68003129Chengu Wang     *   added to the FIFO.
196eb1bd05175bb6020b365e90f4c32eb6d68003129Chengu Wang     * - When enable_activity_event(running, ACTIVITY_EVENT_EXIT) is called,
197eb1bd05175bb6020b365e90f4c32eb6d68003129Chengu Wang     *   (ACTIVITY_EVENT_EXIT, running) should be added to the FIFO.
198eb1bd05175bb6020b365e90f4c32eb6d68003129Chengu Wang     *
199871b74873329f414ec8db3febadebf45e2003572Aravind Akella     * activity_handle - Index of the specific activity that needs to be detected in the list
200871b74873329f414ec8db3febadebf45e2003572Aravind Akella     *                   returned by get_supported_activities_list.
201eb1bd05175bb6020b365e90f4c32eb6d68003129Chengu Wang     * event_type - Specific transition of the activity that needs to be detected. It should be
202eb1bd05175bb6020b365e90f4c32eb6d68003129Chengu Wang     *              either ACTIVITY_EVENT_ENTER or ACTIVITY_EVENT_EXIT.
203153c40ce8bceb6674f605a10f98b84179cf7f204Aravind Akella     * max_batch_report_latency_ns - a transition can be delayed by at most
204153c40ce8bceb6674f605a10f98b84179cf7f204Aravind Akella     *                               “max_batch_report_latency” nanoseconds.
205462eae34ce11e8e6bf5e28dc252d2d11052694e3Aravind Akella     * Return 0 on success, negative errno code otherwise.
206462eae34ce11e8e6bf5e28dc252d2d11052694e3Aravind Akella     */
207153c40ce8bceb6674f605a10f98b84179cf7f204Aravind Akella    int (*enable_activity_event)(const struct activity_recognition_device* dev,
208871b74873329f414ec8db3febadebf45e2003572Aravind Akella            uint32_t activity_handle, uint32_t event_type, int64_t max_batch_report_latency_ns);
209153c40ce8bceb6674f605a10f98b84179cf7f204Aravind Akella
210153c40ce8bceb6674f605a10f98b84179cf7f204Aravind Akella    /*
211eb1bd05175bb6020b365e90f4c32eb6d68003129Chengu Wang     * Disables detection of a specific (activity, event_type) pair. All the (activity, event_type)
212eb1bd05175bb6020b365e90f4c32eb6d68003129Chengu Wang     * events in the FIFO are discarded.
213153c40ce8bceb6674f605a10f98b84179cf7f204Aravind Akella     */
214153c40ce8bceb6674f605a10f98b84179cf7f204Aravind Akella    int (*disable_activity_event)(const struct activity_recognition_device* dev,
215871b74873329f414ec8db3febadebf45e2003572Aravind Akella            uint32_t activity_handle, uint32_t event_type);
216462eae34ce11e8e6bf5e28dc252d2d11052694e3Aravind Akella
217462eae34ce11e8e6bf5e28dc252d2d11052694e3Aravind Akella    /*
218462eae34ce11e8e6bf5e28dc252d2d11052694e3Aravind Akella     * Flush all the batch FIFOs. Report all the activities that were stored in the FIFO so far as
219462eae34ce11e8e6bf5e28dc252d2d11052694e3Aravind Akella     * if max_batch_report_latency had expired. This shouldn't change the latency in any way. Add
220462eae34ce11e8e6bf5e28dc252d2d11052694e3Aravind Akella     * a flush_complete_event to indicate the end of the FIFO after all events are delivered.
221eb1bd05175bb6020b365e90f4c32eb6d68003129Chengu Wang     * activity_callback should be called before this function returns successfully.
222871b74873329f414ec8db3febadebf45e2003572Aravind Akella     * See ACTIVITY_EVENT_FLUSH_COMPLETE for more details.
223462eae34ce11e8e6bf5e28dc252d2d11052694e3Aravind Akella     * Return 0 on success, negative errno code otherwise.
224462eae34ce11e8e6bf5e28dc252d2d11052694e3Aravind Akella     */
225462eae34ce11e8e6bf5e28dc252d2d11052694e3Aravind Akella    int (*flush)(const struct activity_recognition_device* dev);
226462eae34ce11e8e6bf5e28dc252d2d11052694e3Aravind Akella
227462eae34ce11e8e6bf5e28dc252d2d11052694e3Aravind Akella    // Must be set to NULL.
228153c40ce8bceb6674f605a10f98b84179cf7f204Aravind Akella    void (*reserved_procs[16 - 4])(void);
229462eae34ce11e8e6bf5e28dc252d2d11052694e3Aravind Akella} activity_recognition_device_t;
230462eae34ce11e8e6bf5e28dc252d2d11052694e3Aravind Akella
231462eae34ce11e8e6bf5e28dc252d2d11052694e3Aravind Akellastatic inline int activity_recognition_open(const hw_module_t* module,
232462eae34ce11e8e6bf5e28dc252d2d11052694e3Aravind Akella        activity_recognition_device_t** device) {
233462eae34ce11e8e6bf5e28dc252d2d11052694e3Aravind Akella    return module->methods->open(module,
234462eae34ce11e8e6bf5e28dc252d2d11052694e3Aravind Akella            ACTIVITY_RECOGNITION_HARDWARE_INTERFACE, (hw_device_t**)device);
235462eae34ce11e8e6bf5e28dc252d2d11052694e3Aravind Akella}
236462eae34ce11e8e6bf5e28dc252d2d11052694e3Aravind Akella
237462eae34ce11e8e6bf5e28dc252d2d11052694e3Aravind Akellastatic inline int activity_recognition_close(activity_recognition_device_t* device) {
238462eae34ce11e8e6bf5e28dc252d2d11052694e3Aravind Akella    return device->common.close(&device->common);
239462eae34ce11e8e6bf5e28dc252d2d11052694e3Aravind Akella}
240462eae34ce11e8e6bf5e28dc252d2d11052694e3Aravind Akella
241462eae34ce11e8e6bf5e28dc252d2d11052694e3Aravind Akella__END_DECLS
242462eae34ce11e8e6bf5e28dc252d2d11052694e3Aravind Akella
243462eae34ce11e8e6bf5e28dc252d2d11052694e3Aravind Akella#endif // ANDROID_ACTIVITY_RECOGNITION_INTERFACE_H
244