1 /** 2 * Copyright (c) 2020, 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 17 #pragma once 18 19 #include <utils/Looper.h> 20 #include <utils/RefBase.h> 21 #include <utils/Timers.h> 22 23 namespace android { 24 namespace automotive { 25 namespace watchdog { 26 27 // LooperWrapper is a wrapper around the actual looper implementation so tests can stub this wrapper 28 // to deterministically poll the underlying looper. 29 // Refer to utils/Looper.h for the class and methods descriptions. 30 class LooperWrapper : public RefBase { 31 public: LooperWrapper()32 LooperWrapper() : mLooper(nullptr) {} ~LooperWrapper()33 virtual ~LooperWrapper() {} 34 setLooper(sp<Looper> looper)35 void setLooper(sp<Looper> looper) { mLooper = looper; } 36 void wake(); now()37 virtual nsecs_t now() { return systemTime(SYSTEM_TIME_MONOTONIC); } 38 virtual int pollAll(int timeoutMillis); 39 virtual void sendMessage(const android::sp<MessageHandler>& handler, const Message& message); 40 virtual void sendMessageAtTime(nsecs_t uptime, const android::sp<MessageHandler>& handler, 41 const Message& message); 42 virtual void removeMessages(const android::sp<MessageHandler>& handler); 43 virtual void removeMessages(const android::sp<MessageHandler>& handler, int what); 44 45 protected: 46 android::sp<Looper> mLooper; 47 }; 48 49 } // namespace watchdog 50 } // namespace automotive 51 } // namespace android 52