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