1 /**
2 * Copyright 2022 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 #include "stats/include/LooperWrapper.h"
18
19 #include <android-base/logging.h>
20
21 namespace aidl::android::automotive::evs::implementation {
22
23 using ::android::Message;
24 using ::android::MessageHandler;
25 using ::android::sp;
26
wake()27 void LooperWrapper::wake() {
28 if (mLooper == nullptr) {
29 LOG(WARNING) << __FUNCTION__ << ": Looper is invalid.";
30 return;
31 }
32
33 return mLooper->wake();
34 }
35
pollAll(int timeoutMillis)36 int LooperWrapper::pollAll(int timeoutMillis) {
37 if (mLooper == nullptr) {
38 LOG(WARNING) << __FUNCTION__ << ": Looper is invalid.";
39 return 0;
40 }
41
42 return mLooper->pollAll(timeoutMillis);
43 }
44
sendMessage(const sp<MessageHandler> & handler,const Message & message)45 void LooperWrapper::sendMessage(const sp<MessageHandler>& handler, const Message& message) {
46 if (mLooper == nullptr) {
47 LOG(WARNING) << __FUNCTION__ << ": Looper is invalid.";
48 return;
49 }
50
51 return mLooper->sendMessage(handler, message);
52 }
53
sendMessageAtTime(nsecs_t uptime,const sp<MessageHandler> & handler,const Message & message)54 void LooperWrapper::sendMessageAtTime(nsecs_t uptime, const sp<MessageHandler>& handler,
55 const Message& message) {
56 if (mLooper == nullptr) {
57 LOG(WARNING) << __FUNCTION__ << ": Looper is invalid.";
58 return;
59 }
60
61 return mLooper->sendMessageAtTime(uptime, handler, message);
62 }
63
removeMessages(const sp<MessageHandler> & handler)64 void LooperWrapper::removeMessages(const sp<MessageHandler>& handler) {
65 if (mLooper == nullptr) {
66 LOG(WARNING) << __FUNCTION__ << ": Looper is invalid.";
67 return;
68 }
69
70 return mLooper->removeMessages(handler);
71 }
72
73 } // namespace aidl::android::automotive::evs::implementation
74