1 /*
2  * Copyright (C) 2019 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 // A fake ECOServiceInfoListener for testing ECOService and ECOSession.
18 
19 #include <android-base/unique_fd.h>
20 #include <android/media/eco/BnECOServiceInfoListener.h>
21 #include <android/media/eco/IECOSession.h>
22 #include <binder/BinderService.h>
23 #include <binder/Parcel.h>
24 #include <binder/Parcelable.h>
25 #include <cutils/ashmem.h>
26 #include <gtest/gtest.h>
27 #include <math.h>
28 #include <stdlib.h>
29 #include <sys/mman.h>
30 #include <utils/Log.h>
31 
32 #include "eco/ECOData.h"
33 #include "eco/ECODataKey.h"
34 
35 namespace android {
36 namespace media {
37 namespace eco {
38 
39 using ::android::sp;
40 using ::android::binder::Status;
41 
42 /**
43  * A fake ECOServiceInfoListener.
44  *
45  * FakeECOServiceInfoListener is a fake ECOServiceInfoListener that used for testing.
46  */
47 class FakeECOServiceInfoListener : public BnECOServiceInfoListener {
48 public:
49     // Method called by the FakeECOServiceInfoListener when there is new info from ECOService.
50     // This is used by the test to verify the information is sent by the ECOService correctly.
51     using InfoAvailableCallback =
52             std::function<void(const ::android::media::eco::ECOData& newInfo)>;
53 
54     FakeECOServiceInfoListener(int32_t width, int32_t height, bool isCameraRecording,
55                                sp<IECOSession> session);
56 
57     FakeECOServiceInfoListener(int32_t width, int32_t height, bool isCameraRecording);
58 
setECOSession(android::sp<IECOSession> session)59     void setECOSession(android::sp<IECOSession> session) { mECOSession = session; }
60 
61     virtual ~FakeECOServiceInfoListener();
62 
63     virtual Status getType(int32_t* _aidl_return);
64     virtual Status getName(::android::String16* _aidl_return);
65     virtual Status getECOSession(::android::sp<::android::IBinder>* _aidl_return);
66     virtual Status onNewInfo(const ::android::media::eco::ECOData& newInfo);
67 
68     // Helper callback to send the info to the test.
setInfoAvailableCallback(InfoAvailableCallback callback)69     void setInfoAvailableCallback(InfoAvailableCallback callback) {
70         mInfoAvaiableCallback = callback;
71     }
72 
73     // IBinder::DeathRecipient implementation
74     virtual void binderDied(const wp<IBinder>& who);
75 
76 private:
77     int32_t mWidth;
78     int32_t mHeight;
79     bool mIsCameraRecording;
80     android::sp<IECOSession> mECOSession;
81     InfoAvailableCallback mInfoAvaiableCallback;
82 };
83 
84 }  // namespace eco
85 }  // namespace media
86 }  // namespace android
87