1 // Copyright 2013 The Flutter Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef FLUTTER_FML_PLATFORM_ANDROID_MESSAGE_LOOP_ANDROID_H_ 6 #define FLUTTER_FML_PLATFORM_ANDROID_MESSAGE_LOOP_ANDROID_H_ 7 8 #include <android/looper.h> 9 10 #include <atomic> 11 12 #include "flutter/fml/macros.h" 13 #include "flutter/fml/message_loop_impl.h" 14 #include "flutter/fml/unique_fd.h" 15 16 namespace fml { 17 18 struct UniqueLooperTraits { InvalidValueUniqueLooperTraits19 static ALooper* InvalidValue() { return nullptr; } IsValidUniqueLooperTraits20 static bool IsValid(ALooper* value) { return value != nullptr; } FreeUniqueLooperTraits21 static void Free(ALooper* value) { ::ALooper_release(value); } 22 }; 23 24 class MessageLoopAndroid : public MessageLoopImpl { 25 private: 26 fml::UniqueObject<ALooper*, UniqueLooperTraits> looper_; 27 fml::UniqueFD timer_fd_; 28 bool running_; 29 30 MessageLoopAndroid(); 31 32 ~MessageLoopAndroid() override; 33 34 void Run() override; 35 36 void Terminate() override; 37 38 void WakeUp(fml::TimePoint time_point) override; 39 40 void OnEventFired(); 41 42 FML_FRIEND_MAKE_REF_COUNTED(MessageLoopAndroid); 43 FML_FRIEND_REF_COUNTED_THREAD_SAFE(MessageLoopAndroid); 44 FML_DISALLOW_COPY_AND_ASSIGN(MessageLoopAndroid); 45 }; 46 47 } // namespace fml 48 49 #endif // FLUTTER_FML_PLATFORM_ANDROID_MESSAGE_LOOP_ANDROID_H_ 50