xref: /aosp_15_r20/frameworks/native/services/inputflinger/InputProcessor.h (revision 38e8c45f13ce32b0dcecb25141ffecaf386fa17f)
1*38e8c45fSAndroid Build Coastguard Worker /*
2*38e8c45fSAndroid Build Coastguard Worker  * Copyright (C) 2019 The Android Open Source Project
3*38e8c45fSAndroid Build Coastguard Worker  *
4*38e8c45fSAndroid Build Coastguard Worker  * Licensed under the Apache License, Version 2.0 (the "License");
5*38e8c45fSAndroid Build Coastguard Worker  * you may not use this file except in compliance with the License.
6*38e8c45fSAndroid Build Coastguard Worker  * You may obtain a copy of the License at
7*38e8c45fSAndroid Build Coastguard Worker  *
8*38e8c45fSAndroid Build Coastguard Worker  *      http://www.apache.org/licenses/LICENSE-2.0
9*38e8c45fSAndroid Build Coastguard Worker  *
10*38e8c45fSAndroid Build Coastguard Worker  * Unless required by applicable law or agreed to in writing, software
11*38e8c45fSAndroid Build Coastguard Worker  * distributed under the License is distributed on an "AS IS" BASIS,
12*38e8c45fSAndroid Build Coastguard Worker  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*38e8c45fSAndroid Build Coastguard Worker  * See the License for the specific language governing permissions and
14*38e8c45fSAndroid Build Coastguard Worker  * limitations under the License.
15*38e8c45fSAndroid Build Coastguard Worker  */
16*38e8c45fSAndroid Build Coastguard Worker 
17*38e8c45fSAndroid Build Coastguard Worker #pragma once
18*38e8c45fSAndroid Build Coastguard Worker 
19*38e8c45fSAndroid Build Coastguard Worker #include <android-base/thread_annotations.h>
20*38e8c45fSAndroid Build Coastguard Worker #include <future>
21*38e8c45fSAndroid Build Coastguard Worker #include <thread>
22*38e8c45fSAndroid Build Coastguard Worker #include <unordered_map>
23*38e8c45fSAndroid Build Coastguard Worker 
24*38e8c45fSAndroid Build Coastguard Worker #include <aidl/android/hardware/input/processor/IInputProcessor.h>
25*38e8c45fSAndroid Build Coastguard Worker #include <input/BlockingQueue.h>
26*38e8c45fSAndroid Build Coastguard Worker #include "InputListener.h"
27*38e8c45fSAndroid Build Coastguard Worker namespace android {
28*38e8c45fSAndroid Build Coastguard Worker 
29*38e8c45fSAndroid Build Coastguard Worker enum class ClassifierEventType : uint8_t {
30*38e8c45fSAndroid Build Coastguard Worker     MOTION = 0,
31*38e8c45fSAndroid Build Coastguard Worker     DEVICE_RESET = 1,
32*38e8c45fSAndroid Build Coastguard Worker     HAL_RESET = 2,
33*38e8c45fSAndroid Build Coastguard Worker     EXIT = 3,
34*38e8c45fSAndroid Build Coastguard Worker };
35*38e8c45fSAndroid Build Coastguard Worker 
36*38e8c45fSAndroid Build Coastguard Worker struct ClassifierEvent {
37*38e8c45fSAndroid Build Coastguard Worker     ClassifierEventType type;
38*38e8c45fSAndroid Build Coastguard Worker     std::optional<NotifyArgs> args;
39*38e8c45fSAndroid Build Coastguard Worker 
40*38e8c45fSAndroid Build Coastguard Worker     ClassifierEvent(ClassifierEventType type, std::optional<NotifyArgs> args);
41*38e8c45fSAndroid Build Coastguard Worker     ClassifierEvent(const NotifyMotionArgs& args);
42*38e8c45fSAndroid Build Coastguard Worker     ClassifierEvent(const NotifyDeviceResetArgs& args);
43*38e8c45fSAndroid Build Coastguard Worker     ClassifierEvent(ClassifierEvent&& other) = default;
44*38e8c45fSAndroid Build Coastguard Worker     ClassifierEvent& operator=(ClassifierEvent&& other);
45*38e8c45fSAndroid Build Coastguard Worker 
46*38e8c45fSAndroid Build Coastguard Worker     // Convenience function to create a HAL_RESET event
47*38e8c45fSAndroid Build Coastguard Worker     static ClassifierEvent createHalResetEvent();
48*38e8c45fSAndroid Build Coastguard Worker     // Convenience function to create an EXIT event
49*38e8c45fSAndroid Build Coastguard Worker     static ClassifierEvent createExitEvent();
50*38e8c45fSAndroid Build Coastguard Worker 
51*38e8c45fSAndroid Build Coastguard Worker     std::optional<int32_t> getDeviceId() const;
52*38e8c45fSAndroid Build Coastguard Worker };
53*38e8c45fSAndroid Build Coastguard Worker 
54*38e8c45fSAndroid Build Coastguard Worker // --- Interfaces ---
55*38e8c45fSAndroid Build Coastguard Worker 
56*38e8c45fSAndroid Build Coastguard Worker /**
57*38e8c45fSAndroid Build Coastguard Worker  * Interface for adding a MotionClassification to NotifyMotionArgs.
58*38e8c45fSAndroid Build Coastguard Worker  *
59*38e8c45fSAndroid Build Coastguard Worker  * To implement, override the classify function.
60*38e8c45fSAndroid Build Coastguard Worker  */
61*38e8c45fSAndroid Build Coastguard Worker class MotionClassifierInterface {
62*38e8c45fSAndroid Build Coastguard Worker public:
MotionClassifierInterface()63*38e8c45fSAndroid Build Coastguard Worker     MotionClassifierInterface() {}
~MotionClassifierInterface()64*38e8c45fSAndroid Build Coastguard Worker     virtual ~MotionClassifierInterface() {}
65*38e8c45fSAndroid Build Coastguard Worker     /**
66*38e8c45fSAndroid Build Coastguard Worker      * Based on the motion event described by NotifyMotionArgs,
67*38e8c45fSAndroid Build Coastguard Worker      * provide a MotionClassification for the current gesture.
68*38e8c45fSAndroid Build Coastguard Worker      */
69*38e8c45fSAndroid Build Coastguard Worker     virtual MotionClassification classify(const NotifyMotionArgs& args) = 0;
70*38e8c45fSAndroid Build Coastguard Worker     /**
71*38e8c45fSAndroid Build Coastguard Worker      * Reset all internal HAL state.
72*38e8c45fSAndroid Build Coastguard Worker      */
73*38e8c45fSAndroid Build Coastguard Worker     virtual void reset() = 0;
74*38e8c45fSAndroid Build Coastguard Worker     /**
75*38e8c45fSAndroid Build Coastguard Worker      * Reset HAL state for a specific device.
76*38e8c45fSAndroid Build Coastguard Worker      */
77*38e8c45fSAndroid Build Coastguard Worker     virtual void reset(const NotifyDeviceResetArgs& args) = 0;
78*38e8c45fSAndroid Build Coastguard Worker 
79*38e8c45fSAndroid Build Coastguard Worker     /**
80*38e8c45fSAndroid Build Coastguard Worker      * Dump the state of the motion classifier.
81*38e8c45fSAndroid Build Coastguard Worker      */
82*38e8c45fSAndroid Build Coastguard Worker     virtual void dump(std::string& dump) = 0;
83*38e8c45fSAndroid Build Coastguard Worker 
84*38e8c45fSAndroid Build Coastguard Worker     /**
85*38e8c45fSAndroid Build Coastguard Worker      * Called by the heartbeat to ensure the HAL is still processing normally.
86*38e8c45fSAndroid Build Coastguard Worker      */
87*38e8c45fSAndroid Build Coastguard Worker     virtual void monitor() = 0;
88*38e8c45fSAndroid Build Coastguard Worker };
89*38e8c45fSAndroid Build Coastguard Worker 
90*38e8c45fSAndroid Build Coastguard Worker /**
91*38e8c45fSAndroid Build Coastguard Worker  * Base interface for an InputListener stage.
92*38e8c45fSAndroid Build Coastguard Worker  * Provides classification to events.
93*38e8c45fSAndroid Build Coastguard Worker  */
94*38e8c45fSAndroid Build Coastguard Worker class InputProcessorInterface : public InputListenerInterface {
95*38e8c45fSAndroid Build Coastguard Worker public:
96*38e8c45fSAndroid Build Coastguard Worker     virtual void setMotionClassifierEnabled(bool enabled) = 0;
97*38e8c45fSAndroid Build Coastguard Worker     /**
98*38e8c45fSAndroid Build Coastguard Worker      * Dump the state of the input classifier.
99*38e8c45fSAndroid Build Coastguard Worker      * This method may be called on any thread (usually by the input manager).
100*38e8c45fSAndroid Build Coastguard Worker      */
101*38e8c45fSAndroid Build Coastguard Worker     virtual void dump(std::string& dump) = 0;
102*38e8c45fSAndroid Build Coastguard Worker 
103*38e8c45fSAndroid Build Coastguard Worker     /** Called by the heartbeat to ensure that the classifier has not deadlocked. */
104*38e8c45fSAndroid Build Coastguard Worker     virtual void monitor() = 0;
105*38e8c45fSAndroid Build Coastguard Worker 
InputProcessorInterface()106*38e8c45fSAndroid Build Coastguard Worker     InputProcessorInterface() {}
~InputProcessorInterface()107*38e8c45fSAndroid Build Coastguard Worker     virtual ~InputProcessorInterface() {}
108*38e8c45fSAndroid Build Coastguard Worker };
109*38e8c45fSAndroid Build Coastguard Worker 
110*38e8c45fSAndroid Build Coastguard Worker // --- Implementations ---
111*38e8c45fSAndroid Build Coastguard Worker 
112*38e8c45fSAndroid Build Coastguard Worker class ScopedDeathRecipient {
113*38e8c45fSAndroid Build Coastguard Worker public:
114*38e8c45fSAndroid Build Coastguard Worker     explicit ScopedDeathRecipient(AIBinder_DeathRecipient_onBinderDied onBinderDied, void* cookie);
115*38e8c45fSAndroid Build Coastguard Worker     ScopedDeathRecipient(const ScopedDeathRecipient&) = delete;
116*38e8c45fSAndroid Build Coastguard Worker     ScopedDeathRecipient& operator=(ScopedDeathRecipient const&) = delete;
117*38e8c45fSAndroid Build Coastguard Worker     void linkToDeath(AIBinder* binder);
118*38e8c45fSAndroid Build Coastguard Worker     ~ScopedDeathRecipient();
119*38e8c45fSAndroid Build Coastguard Worker 
120*38e8c45fSAndroid Build Coastguard Worker private:
121*38e8c45fSAndroid Build Coastguard Worker     AIBinder_DeathRecipient* mRecipient;
122*38e8c45fSAndroid Build Coastguard Worker     void* mCookie;
123*38e8c45fSAndroid Build Coastguard Worker };
124*38e8c45fSAndroid Build Coastguard Worker 
125*38e8c45fSAndroid Build Coastguard Worker /**
126*38e8c45fSAndroid Build Coastguard Worker  * Implementation of MotionClassifierInterface that calls the InputProcessor HAL
127*38e8c45fSAndroid Build Coastguard Worker  * in order to determine the classification for the current gesture.
128*38e8c45fSAndroid Build Coastguard Worker  *
129*38e8c45fSAndroid Build Coastguard Worker  * The InputProcessor HAL may keep track of the entire gesture in order to determine
130*38e8c45fSAndroid Build Coastguard Worker  * the classification, and may be hardware-specific. It may use the data in
131*38e8c45fSAndroid Build Coastguard Worker  * NotifyMotionArgs::videoFrames field to drive the classification decisions.
132*38e8c45fSAndroid Build Coastguard Worker  * The HAL is called from a separate thread.
133*38e8c45fSAndroid Build Coastguard Worker  */
134*38e8c45fSAndroid Build Coastguard Worker class MotionClassifier final : public MotionClassifierInterface {
135*38e8c45fSAndroid Build Coastguard Worker public:
136*38e8c45fSAndroid Build Coastguard Worker     /*
137*38e8c45fSAndroid Build Coastguard Worker      * Create an instance of MotionClassifier.
138*38e8c45fSAndroid Build Coastguard Worker      * The death recipient, if provided, will be subscribed to the HAL death.
139*38e8c45fSAndroid Build Coastguard Worker      * The death recipient could be used to destroy MotionClassifier.
140*38e8c45fSAndroid Build Coastguard Worker      *
141*38e8c45fSAndroid Build Coastguard Worker      * This function should be called asynchronously, because getService takes a long time.
142*38e8c45fSAndroid Build Coastguard Worker      */
143*38e8c45fSAndroid Build Coastguard Worker     static std::unique_ptr<MotionClassifierInterface> create(
144*38e8c45fSAndroid Build Coastguard Worker             std::shared_ptr<aidl::android::hardware::input::processor::IInputProcessor> service);
145*38e8c45fSAndroid Build Coastguard Worker 
146*38e8c45fSAndroid Build Coastguard Worker     ~MotionClassifier();
147*38e8c45fSAndroid Build Coastguard Worker 
148*38e8c45fSAndroid Build Coastguard Worker     /**
149*38e8c45fSAndroid Build Coastguard Worker      * Classifies events asynchronously; that is, it doesn't block events on a classification,
150*38e8c45fSAndroid Build Coastguard Worker      * but instead sends them over to the classifier HAL. After a classification of a specific
151*38e8c45fSAndroid Build Coastguard Worker      * event is determined, MotionClassifier then marks the next event in the stream with this
152*38e8c45fSAndroid Build Coastguard Worker      * classification.
153*38e8c45fSAndroid Build Coastguard Worker      *
154*38e8c45fSAndroid Build Coastguard Worker      * Therefore, it is acceptable to have the classifications be delayed by 1-2 events
155*38e8c45fSAndroid Build Coastguard Worker      * in a particular gesture.
156*38e8c45fSAndroid Build Coastguard Worker      */
157*38e8c45fSAndroid Build Coastguard Worker     virtual MotionClassification classify(const NotifyMotionArgs& args) override;
158*38e8c45fSAndroid Build Coastguard Worker     virtual void reset() override;
159*38e8c45fSAndroid Build Coastguard Worker     virtual void reset(const NotifyDeviceResetArgs& args) override;
160*38e8c45fSAndroid Build Coastguard Worker 
161*38e8c45fSAndroid Build Coastguard Worker     virtual void dump(std::string& dump) override;
162*38e8c45fSAndroid Build Coastguard Worker     virtual void monitor() override;
163*38e8c45fSAndroid Build Coastguard Worker 
164*38e8c45fSAndroid Build Coastguard Worker private:
165*38e8c45fSAndroid Build Coastguard Worker     friend class MotionClassifierTest; // to create MotionClassifier with a test HAL implementation
166*38e8c45fSAndroid Build Coastguard Worker     explicit MotionClassifier(
167*38e8c45fSAndroid Build Coastguard Worker             std::shared_ptr<aidl::android::hardware::input::processor::IInputProcessor> service);
168*38e8c45fSAndroid Build Coastguard Worker 
169*38e8c45fSAndroid Build Coastguard Worker     /** The events that need to be sent to the HAL. */
170*38e8c45fSAndroid Build Coastguard Worker     BlockingQueue<ClassifierEvent> mEvents;
171*38e8c45fSAndroid Build Coastguard Worker     /**
172*38e8c45fSAndroid Build Coastguard Worker      * Add an event to the queue mEvents.
173*38e8c45fSAndroid Build Coastguard Worker      */
174*38e8c45fSAndroid Build Coastguard Worker     void enqueueEvent(ClassifierEvent&& event);
175*38e8c45fSAndroid Build Coastguard Worker     /**
176*38e8c45fSAndroid Build Coastguard Worker      * Thread that will communicate with InputProcessor HAL.
177*38e8c45fSAndroid Build Coastguard Worker      * This should be the only thread that communicates with InputProcessor HAL,
178*38e8c45fSAndroid Build Coastguard Worker      * because this thread is allowed to block on the HAL calls.
179*38e8c45fSAndroid Build Coastguard Worker      */
180*38e8c45fSAndroid Build Coastguard Worker     std::thread mHalThread;
181*38e8c45fSAndroid Build Coastguard Worker     /**
182*38e8c45fSAndroid Build Coastguard Worker      * Process events and call the InputProcessor HAL
183*38e8c45fSAndroid Build Coastguard Worker      */
184*38e8c45fSAndroid Build Coastguard Worker     void processEvents();
185*38e8c45fSAndroid Build Coastguard Worker     /**
186*38e8c45fSAndroid Build Coastguard Worker      * Access to the InputProcessor HAL. May be null if init() hasn't completed yet.
187*38e8c45fSAndroid Build Coastguard Worker      * When init() successfully completes, mService is guaranteed to remain non-null and to not
188*38e8c45fSAndroid Build Coastguard Worker      * change its value until MotionClassifier is destroyed.
189*38e8c45fSAndroid Build Coastguard Worker      * This variable is *not* guarded by mLock in the InputProcessor thread, because
190*38e8c45fSAndroid Build Coastguard Worker      * that thread knows exactly when this variable is initialized.
191*38e8c45fSAndroid Build Coastguard Worker      * When accessed in any other thread, mService is checked for nullness with a lock.
192*38e8c45fSAndroid Build Coastguard Worker      */
193*38e8c45fSAndroid Build Coastguard Worker     std::shared_ptr<aidl::android::hardware::input::processor::IInputProcessor> mService;
194*38e8c45fSAndroid Build Coastguard Worker     std::mutex mLock;
195*38e8c45fSAndroid Build Coastguard Worker     /**
196*38e8c45fSAndroid Build Coastguard Worker      * Per-device input classifications. Should only be accessed using the
197*38e8c45fSAndroid Build Coastguard Worker      * getClassification / setClassification methods.
198*38e8c45fSAndroid Build Coastguard Worker      */
199*38e8c45fSAndroid Build Coastguard Worker     std::unordered_map<int32_t /*deviceId*/, MotionClassification> mClassifications
200*38e8c45fSAndroid Build Coastguard Worker             GUARDED_BY(mLock);
201*38e8c45fSAndroid Build Coastguard Worker     /**
202*38e8c45fSAndroid Build Coastguard Worker      * Set the current classification for a given device.
203*38e8c45fSAndroid Build Coastguard Worker      */
204*38e8c45fSAndroid Build Coastguard Worker     void setClassification(int32_t deviceId, MotionClassification classification);
205*38e8c45fSAndroid Build Coastguard Worker     /**
206*38e8c45fSAndroid Build Coastguard Worker      * Get the current classification for a given device.
207*38e8c45fSAndroid Build Coastguard Worker      */
208*38e8c45fSAndroid Build Coastguard Worker     MotionClassification getClassification(int32_t deviceId);
209*38e8c45fSAndroid Build Coastguard Worker     void updateClassification(int32_t deviceId, nsecs_t eventTime,
210*38e8c45fSAndroid Build Coastguard Worker                               MotionClassification classification);
211*38e8c45fSAndroid Build Coastguard Worker     /**
212*38e8c45fSAndroid Build Coastguard Worker      * Clear all current classifications
213*38e8c45fSAndroid Build Coastguard Worker      */
214*38e8c45fSAndroid Build Coastguard Worker     void clearClassifications();
215*38e8c45fSAndroid Build Coastguard Worker     /**
216*38e8c45fSAndroid Build Coastguard Worker      * Per-device times when the last ACTION_DOWN was received.
217*38e8c45fSAndroid Build Coastguard Worker      * Used to reject late classifications that do not belong to the current gesture.
218*38e8c45fSAndroid Build Coastguard Worker      *
219*38e8c45fSAndroid Build Coastguard Worker      * Accessed indirectly by both InputProcessor thread and the thread that receives notifyMotion.
220*38e8c45fSAndroid Build Coastguard Worker      */
221*38e8c45fSAndroid Build Coastguard Worker     std::unordered_map<int32_t /*deviceId*/, nsecs_t /*downTime*/> mLastDownTimes GUARDED_BY(mLock);
222*38e8c45fSAndroid Build Coastguard Worker 
223*38e8c45fSAndroid Build Coastguard Worker     void updateLastDownTime(int32_t deviceId, nsecs_t downTime);
224*38e8c45fSAndroid Build Coastguard Worker 
225*38e8c45fSAndroid Build Coastguard Worker     void clearDeviceState(int32_t deviceId);
226*38e8c45fSAndroid Build Coastguard Worker 
227*38e8c45fSAndroid Build Coastguard Worker     /**
228*38e8c45fSAndroid Build Coastguard Worker      * Exit the InputProcessor HAL thread.
229*38e8c45fSAndroid Build Coastguard Worker      * Useful for tests to ensure proper cleanup.
230*38e8c45fSAndroid Build Coastguard Worker      */
231*38e8c45fSAndroid Build Coastguard Worker     void requestExit();
232*38e8c45fSAndroid Build Coastguard Worker     /**
233*38e8c45fSAndroid Build Coastguard Worker      * Return string status of mService
234*38e8c45fSAndroid Build Coastguard Worker      */
235*38e8c45fSAndroid Build Coastguard Worker     const char* getServiceStatus() REQUIRES(mLock);
236*38e8c45fSAndroid Build Coastguard Worker };
237*38e8c45fSAndroid Build Coastguard Worker 
238*38e8c45fSAndroid Build Coastguard Worker /**
239*38e8c45fSAndroid Build Coastguard Worker  * Implementation of the InputProcessorInterface.
240*38e8c45fSAndroid Build Coastguard Worker  * Represents a separate stage of input processing. All of the input events go through this stage.
241*38e8c45fSAndroid Build Coastguard Worker  * Acts as a passthrough for all input events except for motion events.
242*38e8c45fSAndroid Build Coastguard Worker  * The events of motion type are sent to MotionClassifier.
243*38e8c45fSAndroid Build Coastguard Worker  */
244*38e8c45fSAndroid Build Coastguard Worker class InputProcessor : public InputProcessorInterface {
245*38e8c45fSAndroid Build Coastguard Worker public:
246*38e8c45fSAndroid Build Coastguard Worker     explicit InputProcessor(InputListenerInterface& listener);
247*38e8c45fSAndroid Build Coastguard Worker 
248*38e8c45fSAndroid Build Coastguard Worker     void notifyInputDevicesChanged(const NotifyInputDevicesChangedArgs& args) override;
249*38e8c45fSAndroid Build Coastguard Worker     void notifyKey(const NotifyKeyArgs& args) override;
250*38e8c45fSAndroid Build Coastguard Worker     void notifyMotion(const NotifyMotionArgs& args) override;
251*38e8c45fSAndroid Build Coastguard Worker     void notifySwitch(const NotifySwitchArgs& args) override;
252*38e8c45fSAndroid Build Coastguard Worker     void notifySensor(const NotifySensorArgs& args) override;
253*38e8c45fSAndroid Build Coastguard Worker     void notifyVibratorState(const NotifyVibratorStateArgs& args) override;
254*38e8c45fSAndroid Build Coastguard Worker     void notifyDeviceReset(const NotifyDeviceResetArgs& args) override;
255*38e8c45fSAndroid Build Coastguard Worker     void notifyPointerCaptureChanged(const NotifyPointerCaptureChangedArgs& args) override;
256*38e8c45fSAndroid Build Coastguard Worker 
257*38e8c45fSAndroid Build Coastguard Worker     void dump(std::string& dump) override;
258*38e8c45fSAndroid Build Coastguard Worker     void monitor() override;
259*38e8c45fSAndroid Build Coastguard Worker 
260*38e8c45fSAndroid Build Coastguard Worker     ~InputProcessor();
261*38e8c45fSAndroid Build Coastguard Worker 
262*38e8c45fSAndroid Build Coastguard Worker     // Called from InputManager
263*38e8c45fSAndroid Build Coastguard Worker     void setMotionClassifierEnabled(bool enabled) override;
264*38e8c45fSAndroid Build Coastguard Worker 
265*38e8c45fSAndroid Build Coastguard Worker private:
266*38e8c45fSAndroid Build Coastguard Worker     // Protect access to mMotionClassifier, since it may become null via a hidl callback
267*38e8c45fSAndroid Build Coastguard Worker     std::mutex mLock;
268*38e8c45fSAndroid Build Coastguard Worker     // The next stage to pass input events to
269*38e8c45fSAndroid Build Coastguard Worker     QueuedInputListener mQueuedListener;
270*38e8c45fSAndroid Build Coastguard Worker 
271*38e8c45fSAndroid Build Coastguard Worker     std::unique_ptr<MotionClassifierInterface> mMotionClassifier GUARDED_BY(mLock);
272*38e8c45fSAndroid Build Coastguard Worker     std::future<void> mInitializeMotionClassifier GUARDED_BY(mLock);
273*38e8c45fSAndroid Build Coastguard Worker 
274*38e8c45fSAndroid Build Coastguard Worker     /**
275*38e8c45fSAndroid Build Coastguard Worker      * Set the value of mMotionClassifier.
276*38e8c45fSAndroid Build Coastguard Worker      * This is called from 2 different threads:
277*38e8c45fSAndroid Build Coastguard Worker      * 1) mInitializeMotionClassifierThread, when we have constructed a MotionClassifier
278*38e8c45fSAndroid Build Coastguard Worker      * 2) A binder thread of the HalDeathRecipient, which is created when HAL dies. This would cause
279*38e8c45fSAndroid Build Coastguard Worker      *    mMotionClassifier to become nullptr.
280*38e8c45fSAndroid Build Coastguard Worker      */
281*38e8c45fSAndroid Build Coastguard Worker     void setMotionClassifierLocked(std::unique_ptr<MotionClassifierInterface> motionClassifier)
282*38e8c45fSAndroid Build Coastguard Worker             REQUIRES(mLock);
283*38e8c45fSAndroid Build Coastguard Worker 
284*38e8c45fSAndroid Build Coastguard Worker     static void onBinderDied(void* cookie);
285*38e8c45fSAndroid Build Coastguard Worker 
286*38e8c45fSAndroid Build Coastguard Worker     std::unique_ptr<ScopedDeathRecipient> mHalDeathRecipient GUARDED_BY(mLock);
287*38e8c45fSAndroid Build Coastguard Worker };
288*38e8c45fSAndroid Build Coastguard Worker 
289*38e8c45fSAndroid Build Coastguard Worker } // namespace android
290