17fd46a30f30c8a4ada30777e94e80e788e45dd0byinxu/*
27fd46a30f30c8a4ada30777e94e80e788e45dd0byinxu * Copyright (C) 2018 The Android Open Source Project
37fd46a30f30c8a4ada30777e94e80e788e45dd0byinxu *
47fd46a30f30c8a4ada30777e94e80e788e45dd0byinxu * Licensed under the Apache License, Version 2.0 (the "License");
57fd46a30f30c8a4ada30777e94e80e788e45dd0byinxu * you may not use this file except in compliance with the License.
67fd46a30f30c8a4ada30777e94e80e788e45dd0byinxu * You may obtain a copy of the License at
77fd46a30f30c8a4ada30777e94e80e788e45dd0byinxu *
87fd46a30f30c8a4ada30777e94e80e788e45dd0byinxu *      http://www.apache.org/licenses/LICENSE-2.0
97fd46a30f30c8a4ada30777e94e80e788e45dd0byinxu *
107fd46a30f30c8a4ada30777e94e80e788e45dd0byinxu * Unless required by applicable law or agreed to in writing, software
117fd46a30f30c8a4ada30777e94e80e788e45dd0byinxu * distributed under the License is distributed on an "AS IS" BASIS,
127fd46a30f30c8a4ada30777e94e80e788e45dd0byinxu * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
137fd46a30f30c8a4ada30777e94e80e788e45dd0byinxu * See the License for the specific language governing permissions and
147fd46a30f30c8a4ada30777e94e80e788e45dd0byinxu * limitations under the License.
157fd46a30f30c8a4ada30777e94e80e788e45dd0byinxu */
167fd46a30f30c8a4ada30777e94e80e788e45dd0byinxu
177fd46a30f30c8a4ada30777e94e80e788e45dd0byinxu#include <android-base/logging.h>
187fd46a30f30c8a4ada30777e94e80e788e45dd0byinxu
197fd46a30f30c8a4ada30777e94e80e788e45dd0byinxu#include <VtsHalHidlTargetTestBase.h>
2021b0a0ad2555d3cf5231864a474399fdb00992b2Zhuoyao Zhang#include <VtsHalHidlTargetTestEnvBase.h>
217fd46a30f30c8a4ada30777e94e80e788e45dd0byinxu#include <chrono>
227fd46a30f30c8a4ada30777e94e80e788e45dd0byinxu#include <condition_variable>
237fd46a30f30c8a4ada30777e94e80e788e45dd0byinxu#include <mutex>
247fd46a30f30c8a4ada30777e94e80e788e45dd0byinxu
257fd46a30f30c8a4ada30777e94e80e788e45dd0byinxu#include <android/hardware/radio/config/1.0/IRadioConfig.h>
267fd46a30f30c8a4ada30777e94e80e788e45dd0byinxu#include <android/hardware/radio/config/1.0/IRadioConfigIndication.h>
277fd46a30f30c8a4ada30777e94e80e788e45dd0byinxu#include <android/hardware/radio/config/1.0/IRadioConfigResponse.h>
287fd46a30f30c8a4ada30777e94e80e788e45dd0byinxu#include <android/hardware/radio/config/1.0/types.h>
297fd46a30f30c8a4ada30777e94e80e788e45dd0byinxu
307fd46a30f30c8a4ada30777e94e80e788e45dd0byinxu#include "vts_test_util.h"
317fd46a30f30c8a4ada30777e94e80e788e45dd0byinxu
327fd46a30f30c8a4ada30777e94e80e788e45dd0byinxuusing namespace ::android::hardware::radio::config::V1_0;
337fd46a30f30c8a4ada30777e94e80e788e45dd0byinxu
347fd46a30f30c8a4ada30777e94e80e788e45dd0byinxuusing ::android::hardware::Return;
357fd46a30f30c8a4ada30777e94e80e788e45dd0byinxuusing ::android::hardware::Void;
367fd46a30f30c8a4ada30777e94e80e788e45dd0byinxuusing ::android::hardware::hidl_string;
377fd46a30f30c8a4ada30777e94e80e788e45dd0byinxuusing ::android::hardware::hidl_vec;
387fd46a30f30c8a4ada30777e94e80e788e45dd0byinxuusing ::android::hardware::radio::V1_0::RadioIndicationType;
397fd46a30f30c8a4ada30777e94e80e788e45dd0byinxuusing ::android::hardware::radio::V1_0::RadioResponseInfo;
407fd46a30f30c8a4ada30777e94e80e788e45dd0byinxuusing ::android::hardware::radio::V1_0::RadioResponseType;
417fd46a30f30c8a4ada30777e94e80e788e45dd0byinxuusing ::android::sp;
427fd46a30f30c8a4ada30777e94e80e788e45dd0byinxu
437fd46a30f30c8a4ada30777e94e80e788e45dd0byinxu#define TIMEOUT_PERIOD 75
447fd46a30f30c8a4ada30777e94e80e788e45dd0byinxu#define RADIO_SERVICE_NAME "slot1"
457fd46a30f30c8a4ada30777e94e80e788e45dd0byinxu
467fd46a30f30c8a4ada30777e94e80e788e45dd0byinxuclass RadioConfigHidlTest;
477fd46a30f30c8a4ada30777e94e80e788e45dd0byinxu
487fd46a30f30c8a4ada30777e94e80e788e45dd0byinxu/* Callback class for radio config response */
497fd46a30f30c8a4ada30777e94e80e788e45dd0byinxuclass RadioConfigResponse : public IRadioConfigResponse {
507fd46a30f30c8a4ada30777e94e80e788e45dd0byinxu   protected:
517fd46a30f30c8a4ada30777e94e80e788e45dd0byinxu    RadioConfigHidlTest& parent;
527fd46a30f30c8a4ada30777e94e80e788e45dd0byinxu
537fd46a30f30c8a4ada30777e94e80e788e45dd0byinxu   public:
547fd46a30f30c8a4ada30777e94e80e788e45dd0byinxu    RadioResponseInfo rspInfo;
557fd46a30f30c8a4ada30777e94e80e788e45dd0byinxu
567fd46a30f30c8a4ada30777e94e80e788e45dd0byinxu    RadioConfigResponse(RadioConfigHidlTest& parent);
577fd46a30f30c8a4ada30777e94e80e788e45dd0byinxu    virtual ~RadioConfigResponse() = default;
587fd46a30f30c8a4ada30777e94e80e788e45dd0byinxu
597fd46a30f30c8a4ada30777e94e80e788e45dd0byinxu    Return<void> getSimSlotsStatusResponse(
607fd46a30f30c8a4ada30777e94e80e788e45dd0byinxu        const RadioResponseInfo& info,
617fd46a30f30c8a4ada30777e94e80e788e45dd0byinxu        const ::android::hardware::hidl_vec<SimSlotStatus>& slotStatus);
627fd46a30f30c8a4ada30777e94e80e788e45dd0byinxu
637fd46a30f30c8a4ada30777e94e80e788e45dd0byinxu    Return<void> setSimSlotsMappingResponse(const RadioResponseInfo& info);
647fd46a30f30c8a4ada30777e94e80e788e45dd0byinxu};
657fd46a30f30c8a4ada30777e94e80e788e45dd0byinxu
667fd46a30f30c8a4ada30777e94e80e788e45dd0byinxu/* Callback class for radio config indication */
677fd46a30f30c8a4ada30777e94e80e788e45dd0byinxuclass RadioConfigIndication : public IRadioConfigIndication {
687fd46a30f30c8a4ada30777e94e80e788e45dd0byinxu   protected:
697fd46a30f30c8a4ada30777e94e80e788e45dd0byinxu    RadioConfigHidlTest& parent;
707fd46a30f30c8a4ada30777e94e80e788e45dd0byinxu
717fd46a30f30c8a4ada30777e94e80e788e45dd0byinxu   public:
727fd46a30f30c8a4ada30777e94e80e788e45dd0byinxu    RadioConfigIndication(RadioConfigHidlTest& parent);
737fd46a30f30c8a4ada30777e94e80e788e45dd0byinxu    virtual ~RadioConfigIndication() = default;
747fd46a30f30c8a4ada30777e94e80e788e45dd0byinxu
757fd46a30f30c8a4ada30777e94e80e788e45dd0byinxu    Return<void> simSlotsStatusChanged(
767fd46a30f30c8a4ada30777e94e80e788e45dd0byinxu        RadioIndicationType type, const ::android::hardware::hidl_vec<SimSlotStatus>& slotStatus);
777fd46a30f30c8a4ada30777e94e80e788e45dd0byinxu};
787fd46a30f30c8a4ada30777e94e80e788e45dd0byinxu
7921b0a0ad2555d3cf5231864a474399fdb00992b2Zhuoyao Zhang// Test environment for Radio HIDL HAL.
8021b0a0ad2555d3cf5231864a474399fdb00992b2Zhuoyao Zhangclass RadioConfigHidlEnvironment : public ::testing::VtsHalHidlTargetTestEnvBase {
8121b0a0ad2555d3cf5231864a474399fdb00992b2Zhuoyao Zhang   public:
8221b0a0ad2555d3cf5231864a474399fdb00992b2Zhuoyao Zhang    // get the test environment singleton
8321b0a0ad2555d3cf5231864a474399fdb00992b2Zhuoyao Zhang    static RadioConfigHidlEnvironment* Instance() {
8421b0a0ad2555d3cf5231864a474399fdb00992b2Zhuoyao Zhang        static RadioConfigHidlEnvironment* instance = new RadioConfigHidlEnvironment;
8521b0a0ad2555d3cf5231864a474399fdb00992b2Zhuoyao Zhang        return instance;
8621b0a0ad2555d3cf5231864a474399fdb00992b2Zhuoyao Zhang    }
8721b0a0ad2555d3cf5231864a474399fdb00992b2Zhuoyao Zhang    virtual void registerTestServices() override { registerTestService<IRadioConfig>(); }
8821b0a0ad2555d3cf5231864a474399fdb00992b2Zhuoyao Zhang
8921b0a0ad2555d3cf5231864a474399fdb00992b2Zhuoyao Zhang   private:
9021b0a0ad2555d3cf5231864a474399fdb00992b2Zhuoyao Zhang    RadioConfigHidlEnvironment() {}
9121b0a0ad2555d3cf5231864a474399fdb00992b2Zhuoyao Zhang};
9221b0a0ad2555d3cf5231864a474399fdb00992b2Zhuoyao Zhang
937fd46a30f30c8a4ada30777e94e80e788e45dd0byinxu// The main test class for Radio config HIDL.
947fd46a30f30c8a4ada30777e94e80e788e45dd0byinxuclass RadioConfigHidlTest : public ::testing::VtsHalHidlTargetTestBase {
957fd46a30f30c8a4ada30777e94e80e788e45dd0byinxu   protected:
967fd46a30f30c8a4ada30777e94e80e788e45dd0byinxu    std::mutex mtx_;
977fd46a30f30c8a4ada30777e94e80e788e45dd0byinxu    std::condition_variable cv_;
987fd46a30f30c8a4ada30777e94e80e788e45dd0byinxu    int count_;
997fd46a30f30c8a4ada30777e94e80e788e45dd0byinxu
1007fd46a30f30c8a4ada30777e94e80e788e45dd0byinxu   public:
1017fd46a30f30c8a4ada30777e94e80e788e45dd0byinxu    virtual void SetUp() override;
1027fd46a30f30c8a4ada30777e94e80e788e45dd0byinxu
1037fd46a30f30c8a4ada30777e94e80e788e45dd0byinxu    /* Used as a mechanism to inform the test about data/event callback */
1047fd46a30f30c8a4ada30777e94e80e788e45dd0byinxu    void notify();
1057fd46a30f30c8a4ada30777e94e80e788e45dd0byinxu
1067fd46a30f30c8a4ada30777e94e80e788e45dd0byinxu    /* Test code calls this function to wait for response */
1077fd46a30f30c8a4ada30777e94e80e788e45dd0byinxu    std::cv_status wait();
1087fd46a30f30c8a4ada30777e94e80e788e45dd0byinxu
1097fd46a30f30c8a4ada30777e94e80e788e45dd0byinxu    /* radio config service handle */
1107fd46a30f30c8a4ada30777e94e80e788e45dd0byinxu    sp<IRadioConfig> radioConfig;
1117fd46a30f30c8a4ada30777e94e80e788e45dd0byinxu
1127fd46a30f30c8a4ada30777e94e80e788e45dd0byinxu    /* radio config response handle */
1137fd46a30f30c8a4ada30777e94e80e788e45dd0byinxu    sp<RadioConfigResponse> radioConfigRsp;
1147fd46a30f30c8a4ada30777e94e80e788e45dd0byinxu
1157fd46a30f30c8a4ada30777e94e80e788e45dd0byinxu    /* radio config indication handle */
1167fd46a30f30c8a4ada30777e94e80e788e45dd0byinxu    sp<RadioConfigIndication> radioConfigInd;
1177fd46a30f30c8a4ada30777e94e80e788e45dd0byinxu};
118